1import n,{getHeaderHeight as o}from"woody_library_header_utils";import{createActiveItemObserver as p}from"woody_lib_active_item_observer";class h{constructor(t){this.ctrl=t}get el(){return this.ctrl.el}get config(){return this.ctrl.config}get grid(){return this.ctrl.grid}init(){this.mapSlot=this.el.querySelector('[data-cpl-slot="map"]'),this.mapSwitchWrapper=this.el.querySelector("[data-cpl-map-switch-wrapper]"),this.mapSwitch=this.el.querySelector("[data-cpl-map-switch]"),this.mapStatus=this.el.querySelector("[data-cpl-map-status]"),!(!this.mapSlot||!this.mapSwitch)&&(this.mapEl=this.mapSlot.querySelector("woody-map"),this.mapReady=null,this.mapMarkersAbort=null,this.mapCardAbort=null,this.mapObserver=p({getTargets:()=>this.grid?this.grid.querySelectorAll("[data-cpl-item][data-location-lat]"):[],getKey:t=>t.getAttribute("data-postid"),onActiveChange:t=>this.selectPinFor(t)}),this.mapSwitchWrapper&&(this.mapSwitchWrapper.hidden=!1),this.mapSwitch.addEventListener("change",()=>{this.toggleMap(this.mapSwitch.checked,{push:!0})}),this.mapSwitch.addEventListener("keydown",t=>{t.key==="Enter"&&(t.preventDefault(),this.mapSwitch.click())}),this.setupMapHandle(),this.setupMobileOffset(),this.mapSwitch.checked&&this.toggleMap(!0,{push:!1}))}setupMapHandle(){const t=this.mapSlot.querySelector("[data-cpl-map-handle]");t&&t.addEventListener("click",()=>{const e=this.el.classList.toggle("cpl-map-expanded");t.setAttribute("aria-expanded",e?"true":"false")})}setupMobileOffset(){this.updateMobileOffset();let t=!1;window.addEventListener("resize",()=>{t||(t=!0,window.requestAnimationFrame(()=>{t=!1,this.updateMobileOffset()}))})}updateMobileOffset(){let t=this.topHeaderHeight();const e=document.getElementById("wpadminbar");e&&window.getComputedStyle(e).position==="fixed"&&(t+=e.offsetHeight),this.el.style.setProperty("--cpl-map-mobile-offset-top",t+"px")}async toggleMap(t,e){if(e=e||{},this.el.classList.toggle("cpl-has-map",t),this.mapSlot.hidden=!t,e.push!==!1&&this.pushMapState(),!t){this.detachedPopup()&&this.detachedPopup().clear(),this.mapObserver.stop(),this.announceMap(this.i18nMapHidden());return}this.mapObserver.start(),await this.ensureMap()}ensureMap(){return this.mapReady?this.mapReady:(this.mapReady=(async()=>{if(!this.mapEl||!window.customElements)return!1;try{await customElements.whenDefined("woody-map");const{default:t}=await import("woody_contentplaylist_map_manager");await this.mapEl.init({manager:new t})}catch(t){return console.warn("[contentplaylist] map init failed",t),this.el.classList.remove("cpl-has-map"),this.mapSlot.hidden=!0,this.mapSwitchWrapper&&(this.mapSwitchWrapper.hidden=!0),!1}return this.mapEl.addEventListener("pinclick",t=>this.onPinClick(t)),await this.refreshMarkers(this.ctrl.formSearch()),!0})(),this.mapReady)}async refreshMarkers(t){if(!this.mapEl||!this.mapEl.loaded)return;this.mapMarkersAbort&&this.mapMarkersAbort.abort(),this.mapMarkersAbort=new AbortController;const e=this.config.rest_base+"/map/"+this.config.post_id+(t?"?"+t:"");let i=[];try{i=await(await fetch(e,{headers:{Accept:"application/json"},signal:this.mapMarkersAbort.signal})).json()}catch(s){if(s.name==="AbortError")return;console.warn("[contentplaylist] map markers failed",s);return}i=Array.isArray(i)?i:[];const a=Object.assign({},this.mapModel(),{pins:i.map((s,r)=>this.normalizePin(s,r))});this.mapEl.setMarkersModel(a,null),this.mapEl.fitBounds(!this.prefersReducedMotion()),this.announceMap(this.i18nMapShown(i.length))}mapModel(){if(this.mapModelCache)return this.mapModelCache;const t=this.mapSlot.querySelector("[data-cpl-map-model]");try{this.mapModelCache=t?JSON.parse(t.textContent):{}}catch(e){console.warn("[contentplaylist] invalid map model",e),this.mapModelCache={}}return this.mapModelCache}normalizePin(t,e){const i=t.properties&&t.properties.post_id!==void 0?t.properties.post_id:t.post_id;return{lat:parseFloat(t.lat),lon:parseFloat(t.lon!==void 0?t.lon:t.lng),name:t.name||this.titleFromList(i)||"",properties:{post_id:parseInt(i,10),index:t.properties&&t.properties.index!==void 0?t.properties.index:e}}}titleFromList(t){const e=this.cellFor(t),i=e&&e.querySelector("h1, h2, h3, h4, .card-title");return i?i.textContent.trim():""}detachedPopup(){return this.mapEl&&this.mapEl.manager&&this.mapEl.manager.getDetachedPopup?this.mapEl.manager.getDetachedPopup():null}onPinClick(t){const e=this.detachedPopup();e&&e.clear();const i=t.detail&&t.detail.properties?t.detail.properties.post_id:null;if(!i)return;const a=this.cellFor(i);if(a){this.focusCard(a);return}this.openCardPopup(i,e)}cellFor(t){return!this.grid||!t?null:this.grid.querySelector('[data-cpl-item][data-postid="'+t+'"]')||this.grid.querySelector('[data-postid="'+t+'"]')}async focusCard(t){await this.mapObserver.runExclusive(async()=>{const e=n()+this.reservedHeaderHeight();if(!this.isInViewport(t,e)){const a=t.getBoundingClientRect().top+window.scrollY-e;window.scrollTo({top:Math.max(0,a),behavior:this.prefersReducedMotion()?"auto":"smooth"})}const i=t.querySelector("a[href]");i?i.focus({preventScroll:!0}
1):(t.setAttribute("tabindex","-1"),t.focus({preventScroll:!0})),await new Promise(a=>setTimeout(a,800))})}async openCardPopup(t,e){if(!e)return;e.open(),this.mapCardAbort&&this.mapCardAbort.abort(),this.mapCardAbort=new AbortController;const i=this.config.rest_base+"/card/"+t+"?page_id="+this.config.post_id;try{const s=await(await fetch(i,{headers:{Accept:"application/json"},signal:this.mapCardAbort.signal})).json();e.setContent(s)}catch(a){if(a.name==="AbortError")return;console.warn("[contentplaylist] map card failed",a),e.close()}}selectPinFor(t){if(!this.mapEl||!this.mapEl.loaded||!this.mapEl.manager||!this.mapEl.manager.getMappedPinIndex)return;const e=this.mapEl.manager.getMappedPinIndex(t);e!==void 0&&this.mapEl.setSelectedPinIndex(e,!this.prefersReducedMotion(),!1)}onGridUpdated(t){if(this.mapObserver&&(this.mapObserver.refresh(),!t.append)){const e=this.detachedPopup();e&&e.clear(),this.mapEl&&this.mapEl.loaded&&this.refreshMarkers(t.search)}}searchWithMapState(t){if(!this.mapSwitch)return t;const e=new URLSearchParams(t||"");return e.delete("cpl_map"),this.mapSwitch&&this.mapSwitch.checked!==this.mapDefaultOpen()&&e.set("cpl_map",this.mapSwitch.checked?"1":"0"),e.toString()}mapDefaultOpen(){return this.config.default_view==="map"}syncMapFromSearch(t){if(!this.mapSwitch)return;const e=new URLSearchParams(t||"").get("cpl_map"),i=e===null?this.mapDefaultOpen():e!=="0"&&e!=="";i!==this.mapSwitch.checked&&(this.mapSwitch.checked=i,this.toggleMap(i,{push:!1}))}pushMapState(){if(!this.config.permalink)return;const t=this.searchWithMapState(window.location.search.replace(/^\?/,""));window.history.pushState({},"",this.config.permalink+(t?"?"+t:""))}announceMap(t){this.mapStatus&&(this.mapStatus.textContent=t)}i18nMapShown(t){return"Carte affich\xE9e, "+t+(t>1?" points":" point")+" sur la carte."}i18nMapHidden(){return"Carte masqu\xE9e."}reservedHeaderHeight(){return o()>0?0:this.topHeaderHeight()}topHeaderHeight(){let t=0;return document.querySelectorAll(".woody-component-headnavs, .woody-component-mobilenavs").forEach(e=>{const i=window.getComputedStyle(e);i.display==="none"||i.position!=="fixed"&&i.position!=="sticky"||e.getBoundingClientRect().top>=window.innerHeight/2||(t=Math.max(t,e.offsetHeight))}),t}isInViewport(t,e=0){const i=t.getBoundingClientRect();return i.top>=e&&i.bottom<=(window.innerHeight||document.documentElement.clientHeight)}prefersReducedMotion(){return window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}}export{h as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.