@mapcreator/sdk 0.0.0-opacity.0 → 0.0.0-swipe.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1171,8 +1171,8 @@ vec4 finalPos=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matr
1171
1171
  <div>${Vi(`videoAlert`)}</div>
1172
1172
  </div>
1173
1173
  </div>
1174
- `}var Vl=[`area`,`circle`,`dot`,`line`,`marker`,`polygon`],Hl=class{data;customGroupIds;constructor(e){this.data={area:{},circle:{},dot:{},line:{},marker:{},polygon:{}};for(let t of Vl)for(let n of e.registry?.models?.[t]??[]){this.data[t][n.id]={};for(let e of n.models){if(t===`area`){let t=e;t.featureId===void 0&&(t.featureId=Number(t.id),t.id=`${t.vectorUrl}-${t.id}`)}this.data[t][n.id][e.id]=e}}let{beforeWaters:t=[],beforeBoundaries:n=[],beforeNames:r=[],beforeNone:i=[]}=e.registry?.slots??{};this.customGroupIds=[...t,...n,...r,...i].map(e=>e.groupId)}getModel(e){let t=String(e.properties?.id),n=e.layer.metadata,r=n?.[`mc-group-id`],i=n?.[`mc-model-type`],a=n?.[`mc-model-id-prefix`];if(a&&(t=`${a}-${t}`),!(r===void 0||t===void 0||i===void 0))return this.data[i]?.[r]?.[t]}getPopupElements(){let e=[],t=[`circle`,`dot`,`line`,`marker`,`polygon`];for(let n of this.customGroupIds)for(let r of t){let t=this.data[r]?.[n];if(t)for(let[r,i]of Object.entries(t))(i.popup||i.popupMedia)&&e.push({groupId:n,modelId:r,popup:i.popup,popupMedia:i.popupMedia,lngLat:i.lngLat,center:i.center,radius:i.radius,anchorPoints:i.anchorPoints,dataBindings:i.dataBindings})}return e.reverse()}},Ul=class{map;popupElements;markerLayerIds;resizeObserver;constructor(e,t){this.map=e,this.popupElements=t,this.markerLayerIds=this.map.getStyle().layers.filter(e=>e.id.startsWith(`custom-marker`)).filter(e=>!e.id.endsWith(`-cluster`)).map(e=>e.id)}highlight(e){if(this.deselect(),!e)return;let{groupId:t,modelId:n}=e,r=this.popupElements.filter(e=>e.groupId===t);r.length>1&&t.startsWith(`custom-marker`)&&this.highlightGroupedMarker(t,n,r),t.startsWith(`custom-marker`)&&this.fadeOtherMarkers(t),this.repositionMap(e)}deselect(){this.markerLayerIds.forEach(e=>{this.map.setPaintProperty(e,`icon-opacity`,1),this.map.setPaintProperty(e,`text-opacity`,1)}),this.resizeObserver?.disconnect()}highlightGroupedMarker(e,t,n){let r=this.markerLayerIds.find(t=>t.startsWith(e));r&&(this.map.setPaintProperty(r,`icon-opacity`,[`case`,[`boolean`,[`feature-state`,`highlighted`],!1],1,.3]),this.map.setPaintProperty(r,`text-opacity`,[`case`,[`boolean`,[`feature-state`,`highlighted`],!1],1,.3]),n.forEach(n=>{this.map.setFeatureState({source:e,id:w(n.modelId)},{highlighted:n.modelId===t})}))}fadeOtherMarkers(e){this.markerLayerIds.filter(t=>!t.startsWith(e)).forEach(e=>{this.map.setPaintProperty(e,`icon-opacity`,.3),this.map.setPaintProperty(e,`text-opacity`,.3)})}repositionMap(e){let t,n=20;e.lngLat===void 0?e.anchorPoints===void 0?e.center!==void 0&&e.radius!==void 0&&(t=this.getElementBounds(rr(e.center,e.radius))):t=this.getElementBounds(this.flattenCoordinates(e.anchorPoints)):(t=new u.LngLatBounds(e.lngLat,e.lngLat),n=40);let r=document.querySelector(`.popup-container`);if(!r||!t)return;this.resizeObserver?.disconnect();let i=0;this.resizeObserver=new ResizeObserver(e=>{let r=e[0].contentRect.height;r>i&&(i=r,this.panToElement(t,n))}),this.resizeObserver.observe(r)}getElementBounds(e){let t=new u.LngLatBounds(e[0],e[0]);for(let n of e)t.extend(n);return t}flattenCoordinates(e){return Array.isArray(e[0][0])?e.flat():e}panToElement(e,t){let n=this.map;if(n.getProjection()?.type===`globe`&&[e.getSouthWest(),e.getNorthEast(),e.getNorthWest(),e.getSouthEast()].some(e=>!this.visibleOnGlobe(e.lng,e.lat))){n.easeTo({center:e.getCenter(),duration:500});return}let r=n.projectWithScaleCorrection(e.getSouthWest()),i=n.projectWithScaleCorrection(e.getNorthEast()),a=n.getContainer().clientWidth,o=n.getContainer().clientHeight,s=a>600,c=document.querySelector(`.popup-container`)?.getBoundingClientRect(),l=c?.width??0,u=c?.height??0;s||(u=Math.min(u,o/2));let d=o-r.y>u+t,f=r.x>t+(s&&!d?l:0),p=i.x<a-t,m=i.y>t,h=s?r.y<o-t:d;if(!(f&&p&&m&&h))if(i.x-r.x+2*t<a&&r.y-i.y+2*t<o){let t=e.getCenter();n.easeTo({center:t,duration:500,offset:s?[0,0]:[0,-30]})}else n.fitBounds(e,{padding:t,maxZoom:n.getZoom(),duration:500,linear:!0})}visibleOnGlobe(e,t){let{lng:n,lat:r}=this.map.getCenter(),i=this.map.getPitch()*Math.PI/180,a=this.map.getBearing()*Math.PI/180,o=this.lngLatToUnitVector(n,r),s=this.lngLatToUnitVector(e,t),c=this.normalize(this.cross([0,0,1],o)),l=this.rotateAroundZ(c,a),u=this.rotateVectorAroundAxis(o,l,i);return u[0]*s[0]+u[1]*s[1]+u[2]*s[2]>.3}lngLatToUnitVector(e,t){let n=t*Math.PI/180,r=e*Math.PI/180;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}rotateVectorAroundAxis(e,t,n){let[r,i,a]=e,[o,s,c]=t,l=Math.cos(n),u=Math.sin(n),d=r*o+i*s+a*c;return[r*l+(s*a-c*i)*u+o*d*(1-l),i*l+(c*r-o*a)*u+s*d*(1-l),a*l+(o*i-s*r)*u+c*d*(1-l)]}rotateAroundZ(e,t){let[n,r,i]=e,a=Math.cos(t),o=Math.sin(t);return[n*a-r*o,n*o+r*a,i]}cross(e,t){let[n,r,i]=e,[a,o,s]=t;return[r*s-i*o,i*a-n*s,n*o-r*a]}normalize(e){let[t,n,r]=e,i=Math.hypot(t,n,r);return[t/i,n/i,r/i]}},Wl=class{map;popupPosition=`bottomLeft`;mapContainer;popupContainer;feature;currentFeatureId;currentModelId;popupElements=[];language=`en`;promoteIdCache=new Map;publication;floatingPopup;registry;highlightManager;mode;restrictMapMovement;center;constructor(e,t){this.map=e,this.mode=t,this.mapContainer=this.map.getContainer(),this.popupContainer=document.createElement(`div`),this.popupContainer.classList.add(`popup-container`),this.map.on(`mousemove`,e=>this.onMouseMove(e)),this.map.on(`click`,e=>this.onClick(e))}setJobObject(e){this.registry=new Hl(e)}setParams(e,t,n,r){this.popupPosition=e,this.language=t,this.restrictMapMovement=n,this.center=r}setPublication(e){this.publication=e}setpopupElements(){this.popupElements=this.registry.getPopupElements()}setHighlightManager(){this.highlightManager=new Ul(this.map,this.registry.getPopupElements())}onMouseMove(e){this.feature=this.getInteractiveFeature(e),this.feature?this.map.getCanvas().style.cursor=`pointer`:this.map.getCanvas().style.cursor=``}onClick(e){this.feature=this.getInteractiveFeature(e),this.currentModelId=this.feature?.properties?.id,this.feature&&(!this.mapContainer.contains(this.popupContainer)||this.feature?.id!==this.currentFeatureId)?(this.addPopup(e),this.highlightManager?.highlight(this.getPopupElementFromFeature(this.feature))):(this.hidePopup(),this.highlightManager?.highlight(void 0))}getPopupElementFromFeature(e){return this.popupElements.find(t=>t.modelId===e.properties.id)}getInteractiveFeature(e){return this.map.queryRenderedFeatures(e.point).find(e=>{if(Object.keys(e.layer.metadata??{}).some(e=>e.startsWith(`mc-interactivity-template`)))return!0;let t=this.registry.getModel(e);return!!(t?.popup??t?.popupMedia)})}addPopup(e){if(!this.feature)return;this.floatingPopup?.remove();let t=Number(this.feature.id);this.currentFeatureId=isNaN(t)?this.feature.id:t;let n=this.getTemplate(this.feature);if(n){if(this.popupPosition===`mapElement`){if(this.feature.geometry.type===`Point`)this.addFloatingPopup(n,this.feature.geometry.coordinates);else{let{lng:t,lat:r}=this.map.unprojectWithScaleCorrection(e.point);this.addFloatingPopup(n,[t,r])}return}this.popupContainer.innerHTML=n,this.popupElements.find(e=>e.modelId===this.currentModelId)&&this.addPopupControls(),this.mapContainer.appendChild(this.popupContainer)}}addFloatingPopup(e,t){let n=this.restrictMapMovement?this.getAnchor(t):void 0;this.floatingPopup=new u.Popup({maxWidth:`none`,closeButton:!1,offset:20,...n!==void 0&&{anchor:n}}).setLngLat(t).setHTML(e).addTo(this.map)}getAnchor(e){let t=this.map.projectWithScaleCorrection(e),n=this.map.getContainer().clientWidth,r=this.map.getContainer().clientHeight,i,a;return i=t.y<r*.33?`top`:t.y>r*.66?`bottom`:`center`,a=t.x<n*.33?`left`:t.x>n*.66?`right`:`center`,i===`center`&&a===`center`?`bottom`:i===`center`?a:a===`center`?i:`${i}-${a}`}hidePopup(){this.popupContainer&&(this.popupContainer.remove(),this.feature=void 0,this.currentFeatureId=void 0),this.restrictMapMovement&&this.center&&this.map.easeTo({center:this.center})}getTemplate(e){let{layer:t}=e,n,r=this.registry.getModel(e);if(r?.popup||r?.popupMedia)n=Fl(r.popup,r.popupMedia,r.dataBindings??{},this.mode);else{let r=[];this.publication&&(r.push(`:${this.publication}-${this.language}`),r.push(`:${this.publication}-:en`)),r.push(`:${this.language}`),r.push(`:en`),r.push(``);for(let i of r){let r=t.metadata?.[`mc-interactivity-template${i}`];if(r){n=this.fillDatalayerTemplate(e,r,i);break}}n&&=`
1174
+ `}var Vl=[`area`,`circle`,`dot`,`line`,`marker`,`polygon`],Hl=class{data;customGroupIds;constructor(e){this.data={area:{},circle:{},dot:{},line:{},marker:{},polygon:{}};for(let t of Vl)for(let n of e.registry?.models?.[t]??[]){this.data[t][n.id]={};for(let e of n.models){if(t===`area`){let t=e;t.featureId===void 0&&(t.featureId=Number(t.id),t.id=`${t.vectorUrl}-${t.id}`)}this.data[t][n.id][e.id]=e}}let{beforeWaters:t=[],beforeBoundaries:n=[],beforeNames:r=[],beforeNone:i=[]}=e.registry?.slots??{};this.customGroupIds=[...t,...n,...r,...i].map(e=>e.groupId)}getModel(e){let t=String(e.properties?.id),n=e.layer.metadata,r=n?.[`mc-group-id`],i=n?.[`mc-model-type`],a=n?.[`mc-model-id-prefix`];if(a&&(t=`${a}-${t}`),!(r===void 0||t===void 0||i===void 0))return this.data[i]?.[r]?.[t]}getPopupElements(){let e=[],t=[`circle`,`dot`,`line`,`marker`,`polygon`];for(let n of this.customGroupIds)for(let r of t){let t=this.data[r]?.[n];if(t)for(let[r,i]of Object.entries(t))(i.popup||i.popupMedia)&&e.push({groupId:n,modelId:r,popup:i.popup,popupMedia:i.popupMedia,lngLat:i.lngLat,center:i.center,radius:i.radius,anchorPoints:i.anchorPoints,dataBindings:i.dataBindings})}return e.reverse()}},Ul=class{map;popupElements;markerLayerIds;resizeObserver;constructor(e,t){this.map=e,this.popupElements=t,this.markerLayerIds=this.map.getStyle().layers.filter(e=>e.id.startsWith(`custom-marker`)).filter(e=>!e.id.endsWith(`-cluster`)).map(e=>e.id)}highlight(e){if(this.deselect(),!e)return;let{groupId:t,modelId:n}=e,r=this.popupElements.filter(e=>e.groupId===t);r.length>1&&t.startsWith(`custom-marker`)&&this.highlightGroupedMarker(t,n,r),t.startsWith(`custom-marker`)&&this.fadeOtherMarkers(t),this.repositionMap(e)}deselect(){this.markerLayerIds.forEach(e=>{this.map.setPaintProperty(e,`icon-opacity`,1),this.map.setPaintProperty(e,`text-opacity`,1)}),this.resizeObserver?.disconnect()}highlightGroupedMarker(e,t,n){let r=this.markerLayerIds.find(t=>t.startsWith(e));r&&(this.map.setPaintProperty(r,`icon-opacity`,[`case`,[`boolean`,[`feature-state`,`highlighted`],!1],1,.3]),this.map.setPaintProperty(r,`text-opacity`,[`case`,[`boolean`,[`feature-state`,`highlighted`],!1],1,.3]),n.forEach(n=>{this.map.setFeatureState({source:e,id:w(n.modelId)},{highlighted:n.modelId===t})}))}fadeOtherMarkers(e){this.markerLayerIds.filter(t=>!t.startsWith(e)).forEach(e=>{this.map.setPaintProperty(e,`icon-opacity`,.3),this.map.setPaintProperty(e,`text-opacity`,.3)})}repositionMap(e){let t,n=20;e.lngLat===void 0?e.anchorPoints===void 0?e.center!==void 0&&e.radius!==void 0&&(t=this.getElementBounds(rr(e.center,e.radius))):t=this.getElementBounds(this.flattenCoordinates(e.anchorPoints)):(t=new u.LngLatBounds(e.lngLat,e.lngLat),n=40);let r=document.querySelector(`.popup-container`);if(!r||!t)return;this.resizeObserver?.disconnect();let i=0;this.resizeObserver=new ResizeObserver(e=>{let r=e[0].contentRect.height;r>i&&(i=r,this.panToElement(t,n))}),this.resizeObserver.observe(r)}getElementBounds(e){let t=new u.LngLatBounds(e[0],e[0]);for(let n of e)t.extend(n);return t}flattenCoordinates(e){return Array.isArray(e[0][0])?e.flat():e}panToElement(e,t){let n=this.map;if(n.getProjection()?.type===`globe`&&[e.getSouthWest(),e.getNorthEast(),e.getNorthWest(),e.getSouthEast()].some(e=>!this.visibleOnGlobe(e.lng,e.lat))){n.easeTo({center:e.getCenter(),duration:500});return}let r=n.projectWithScaleCorrection(e.getSouthWest()),i=n.projectWithScaleCorrection(e.getNorthEast()),a=n.getContainer().clientWidth,o=n.getContainer().clientHeight,s=a>600,c=document.querySelector(`.popup-container`)?.getBoundingClientRect(),l=c?.width??0,u=c?.height??0;s||(u=Math.min(u,o/2));let d=o-r.y>u+t,f=r.x>t+(s&&!d?l:0),p=i.x<a-t,m=i.y>t,h=s?r.y<o-t:d;if(!(f&&p&&m&&h))if(i.x-r.x+2*t<a&&r.y-i.y+2*t<o){let t=e.getCenter();n.easeTo({center:t,duration:500,offset:s?[0,0]:[0,-30]})}else n.fitBounds(e,{padding:t,maxZoom:n.getZoom(),duration:500,linear:!0})}visibleOnGlobe(e,t){let{lng:n,lat:r}=this.map.getCenter(),i=this.map.getPitch()*Math.PI/180,a=this.map.getBearing()*Math.PI/180,o=this.lngLatToUnitVector(n,r),s=this.lngLatToUnitVector(e,t),c=this.normalize(this.cross([0,0,1],o)),l=this.rotateAroundZ(c,a),u=this.rotateVectorAroundAxis(o,l,i);return u[0]*s[0]+u[1]*s[1]+u[2]*s[2]>.3}lngLatToUnitVector(e,t){let n=t*Math.PI/180,r=e*Math.PI/180;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}rotateVectorAroundAxis(e,t,n){let[r,i,a]=e,[o,s,c]=t,l=Math.cos(n),u=Math.sin(n),d=r*o+i*s+a*c;return[r*l+(s*a-c*i)*u+o*d*(1-l),i*l+(c*r-o*a)*u+s*d*(1-l),a*l+(o*i-s*r)*u+c*d*(1-l)]}rotateAroundZ(e,t){let[n,r,i]=e,a=Math.cos(t),o=Math.sin(t);return[n*a-r*o,n*o+r*a,i]}cross(e,t){let[n,r,i]=e,[a,o,s]=t;return[r*s-i*o,i*a-n*s,n*o-r*a]}normalize(e){let[t,n,r]=e,i=Math.hypot(t,n,r);return[t/i,n/i,r/i]}},Wl=class{map;popupPosition=`bottomLeft`;mapContainer;popupContainer;feature;currentFeatureId;currentModelId;popupElements=[];language=`en`;promoteIdCache=new Map;publication;floatingPopup;registry;highlightManager;mode;restrictMapMovement;center;constructor(e,t){this.map=e,this.mode=t,this.mapContainer=this.map.getContainer(),this.popupContainer=document.createElement(`div`),this.popupContainer.classList.add(`popup-container`),this.addSwipeAction(),this.map.on(`mousemove`,e=>this.onMouseMove(e)),this.map.on(`click`,e=>this.onClick(e))}setJobObject(e){this.registry=new Hl(e)}setParams(e,t,n,r){this.popupPosition=e,this.language=t,this.restrictMapMovement=n,this.center=r}setPublication(e){this.publication=e}setpopupElements(){this.popupElements=this.registry.getPopupElements()}setHighlightManager(){this.highlightManager=new Ul(this.map,this.registry.getPopupElements())}onMouseMove(e){this.feature=this.getInteractiveFeature(e),this.feature?this.map.getCanvas().style.cursor=`pointer`:this.map.getCanvas().style.cursor=``}onClick(e){this.feature=this.getInteractiveFeature(e),this.currentModelId=this.feature?.properties?.id,this.feature&&(!this.mapContainer.contains(this.popupContainer)||this.feature?.id!==this.currentFeatureId)?(this.addPopup(e),this.highlightManager?.highlight(this.getPopupElementFromFeature(this.feature))):(this.hidePopup(),this.highlightManager?.highlight(void 0))}getPopupElementFromFeature(e){return this.popupElements.find(t=>t.modelId===e.properties.id)}getInteractiveFeature(e){return this.map.queryRenderedFeatures(e.point).find(e=>{if(Object.keys(e.layer.metadata??{}).some(e=>e.startsWith(`mc-interactivity-template`)))return!0;let t=this.registry.getModel(e);return!!(t?.popup??t?.popupMedia)})}addPopup(e){if(!this.feature)return;this.floatingPopup?.remove();let t=Number(this.feature.id);this.currentFeatureId=isNaN(t)?this.feature.id:t;let n=this.getTemplate(this.feature);if(n){if(this.popupPosition===`mapElement`){if(this.feature.geometry.type===`Point`)this.addFloatingPopup(n,this.feature.geometry.coordinates);else{let{lng:t,lat:r}=this.map.unprojectWithScaleCorrection(e.point);this.addFloatingPopup(n,[t,r])}return}this.popupContainer.innerHTML=n,this.popupElements.find(e=>e.modelId===this.currentModelId)&&this.addPopupControls(),this.mapContainer.appendChild(this.popupContainer)}}addFloatingPopup(e,t){let n=this.restrictMapMovement?this.getAnchor(t):void 0;this.floatingPopup=new u.Popup({maxWidth:`none`,closeButton:!1,offset:20,...n!==void 0&&{anchor:n}}).setLngLat(t).setHTML(e).addTo(this.map)}getAnchor(e){let t=this.map.projectWithScaleCorrection(e),n=this.map.getContainer().clientWidth,r=this.map.getContainer().clientHeight,i,a;return i=t.y<r*.33?`top`:t.y>r*.66?`bottom`:`center`,a=t.x<n*.33?`left`:t.x>n*.66?`right`:`center`,i===`center`&&a===`center`?`bottom`:i===`center`?a:a===`center`?i:`${i}-${a}`}hidePopup(){this.popupContainer&&(this.popupContainer.remove(),this.feature=void 0,this.currentFeatureId=void 0),this.restrictMapMovement&&this.center&&this.map.easeTo({center:this.center})}getTemplate(e){let{layer:t}=e,n,r=this.registry.getModel(e);if(r?.popup||r?.popupMedia)n=Fl(r.popup,r.popupMedia,r.dataBindings??{},this.mode);else{let r=[];this.publication&&(r.push(`:${this.publication}-${this.language}`),r.push(`:${this.publication}-:en`)),r.push(`:${this.language}`),r.push(`:en`),r.push(``);for(let i of r){let r=t.metadata?.[`mc-interactivity-template${i}`];if(r){n=this.fillDatalayerTemplate(e,r,i);break}}n&&=`
1175
1175
  <div class="popup-scroll-wrapper">
1176
1176
  <div class="mc-popup data-layer text-content">${n}</div>
1177
1177
  </div>
1178
- `}return n}htmlToElement(e){let t=document.createElement(`template`);return t.innerHTML=e.trim(),t.content.firstElementChild}addPopupControls(){let e=this.htmlToElement(Il);if(e&&(e.addEventListener(`click`,()=>{this.hidePopup(),this.highlightManager.highlight(void 0)}),this.popupContainer.appendChild(e)),this.popupElements.length<2)return;let t=this.htmlToElement(Ll);t&&(t.querySelector(`.prev`)?.addEventListener(`click`,()=>this.cyclePopups(!1)),t.querySelector(`.next`)?.addEventListener(`click`,()=>this.cyclePopups()),this.popupContainer.appendChild(t))}fillDatalayerTemplate(e,t,n){let r=`data-mention-id`,i=new DOMParser().parseFromString(t,`text/html`).body;for(let t of i.querySelectorAll(`[${r}]`)){let i=this.getProperty(e,t.getAttribute(r),n);i!==void 0&&(t.innerText=i)}return i.innerHTML}getProperty(e,t,n){if(!t)return;let r=t.endsWith(`:en`)?[t.replace(`:en`,n),t]:[t];for(let t of r){let n=e.properties[t]??this.getVectorProperty(e,t);if(n!==void 0)return n}}getVectorProperty(e,t){let n=this.promoteIdCache.get(e.source);n===void 0&&(n=this.map.getSource(e.source)?.serialize().promoteId||`id`,this.promoteIdCache.set(e.source,n));try{let r=e.properties[n];return e.layer.metadata.properties[t][r]}catch{return}}cyclePopups(e=!0){let t=this.popupElements?.findIndex(e=>e.modelId===this.currentModelId);if(t!==-1){let n=0;n=e?t===this.popupElements.length-1?0:t+1:t===0?this.popupElements.length-1:t-1;let r=this.popupElements?.[n];this.highlightManager.highlight(r);let i=Fl(r.popup,r.popupMedia,r.dataBindings??{},this.mode),a=this.popupContainer;this.popupContainer.remove(),a.innerHTML=i,this.mapContainer.appendChild(a),this.currentModelId=r.modelId,this.addPopupControls(),e?this.popupContainer.querySelector(`.mc-popup-button.next`)?.focus():this.popupContainer.querySelector(`.mc-popup-button.prev`)?.focus(),this.currentFeatureId=void 0}}},Gl=class e{static#e(e){let t=0,n=[t];for(let r=1;r<e.length;++r){let i=e[r-1],a=e[r],o=a.x-i.x,s=a.y-i.y;t+=Math.sqrt(o*o+s*s),n.push(t)}return n}static#t(e,t){return e.x===t.x&&e.y===t.y}#n;#r;#i;#a;constructor(t){this.#n=t.filter((e,n)=>n===0||t[n][0]!==t[n-1][0]||t[n][1]!==t[n-1][1]),this.#r=this.#n.map(e=>u.MercatorCoordinate.fromLngLat(e)),this.#i=e.#e(this.#r),this.#a=this.#i[this.#i.length-1]}sample(e){let t=this.#r,n=this.#i;if(t.length<2)return t[0];e*=this.#a;for(let r=1;r<t.length;++r){let i=t[r-1],a=t[r],o=n[r-1],s=n[r];if(s>=e){let t=(e-o)/(s-o);return new u.MercatorCoordinate(j(i.x,a.x,t),j(i.y,a.y,t))}}return new u.MercatorCoordinate(t[t.length-1].x,t[t.length-1].y)}slice(t,n){if(this.#n.length<2)return this.#n;let r=this.#r.filter((e,r)=>this.#i[r]>=t*this.#a&&this.#i[r]<=n*this.#a);if(t>0){let n=this.sample(t);e.#t(n,r[0])||r.unshift(n)}if(n<1){let t=this.sample(n);e.#t(t,r[r.length-1])||r.push(t)}return r.map(e=>{let{lng:t,lat:n}=e.toLngLat();return[t,n]})}get length(){return this.#a}},Kl={solid:[1,0],dotted:[.7,.3],dashed:[3.5,1.5]};function ql(e,t,n,r){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(n=>Jl(e,t,n,1,r))}}),Object.entries(Kl).forEach(([r,i])=>{t.models.some(e=>(e.lineStyle??`solid`)===r)&&e.addLayer({id:`${t.id}-${r}`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},filter:[`all`,[`==`,[`geometry-type`],`LineString`],[`==`,[`get`,`line-style`],r]],paint:{"line-width":[`get`,`line-width`],"line-color":[`get`,`line-color`],"line-dasharray":i,"line-opacity":[`coalesce`,[`feature-state`,`opacity`],[`global-state`,`opacity-${t.id}`],1]}},n)}),e.addLayer({id:`${t.id}-clickable`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},paint:{"line-width":[`max`,[`get`,`line-width`],15],"line-opacity":0},filter:[`==`,[`geometry-type`],`LineString`]},n),t.models.some(e=>e.svg)&&e.addLayer({id:`${t.id}-icon`,type:`symbol`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},layout:{"icon-allow-overlap":!0,"icon-ignore-placement":!0,"icon-image":[`get`,`mc-image-key`],"icon-anchor":`center`,"icon-size":[`get`,`icon-size`],"icon-rotate":[`get`,`icon-rotate`],"icon-offset":[`get`,`icon-offset`]},paint:{"icon-opacity":[`coalesce`,[`feature-state`,`opacity`],[`global-state`,`opacity-${t.id}`],1]},filter:[`==`,[`geometry-type`],`Point`]},n)}function Jl(e,t,n,r,i){let a=new Gl(n.geometry).slice(0,r),o=n.svg===void 0?void 0:i.getMapLibreImageKey(qr(n.dataBindings??{},n.svg,void 0),window.devicePixelRatio*(n.iconScale??1));return{type:`Feature`,id:w(n.id),properties:{id:n.id,"line-width":n.lineWidth??3,"line-color":t.lineColor||n.lineColor?Gr(n.dataBindings??{},n.lineColor,t.lineColor):`#000000`,"line-style":n.lineStyle??`solid`,"mc-image-key":o,"icon-rotate":Yl(n,a,e),"icon-offset":n.iconOffset,"icon-size":n.iconScale},geometry:{type:`GeometryCollection`,geometries:[{type:`LineString`,coordinates:a},{type:`Point`,coordinates:a[a.length-1]}]}}}function Yl(e,t,n){return e.iconRotation?e.iconAlign?fr(t,n)+e.iconRotation:e.iconRotation:0}function Xl(e,t,n,r,i,a,o){let s=yr(t),c=new Map,l=new Map;for(let e of t.models){let n=e.featureId,a=t.id,o=[],u=ur(e),d=lr(a,e),f=l.get(d)??{model:e,featureIds:o,modelIdToFillColor:{},modelIdToFillPattern:{},modelIdToOutlineColor:{},modelIdToOutlineWidth:{}};if(e.visible??!0){f.featureIds.push(n);let a=e.fillPattern===void 0?null:i.getMapLibreImageKey(r[e.fillPattern],2*window.devicePixelRatio);f.modelIdToFillColor[n]=t.fillColor||e.fillColor?Gr(e.dataBindings??{},e.fillColor,t.fillColor,s,t.choropleth?.unmatchedColor):`#000000`,f.modelIdToFillPattern[n]=a,f.modelIdToOutlineColor[n]=t.outlineColor||e.outlineColor?Gr(e.dataBindings??{},e.outlineColor,t.outlineColor):`#000000`,f.modelIdToOutlineWidth[n]=e.outlineWidth??.5}c.set(u,e),l.set(d,f)}for(let t of c.keys())e.getSource(t)||e.addSource(t,{type:`vector`,url:`${a}${c.get(t).vectorUrl}?access_token=${o}`});for(let r of l.keys()){let{model:i}=l.get(r),{sourceLayerId:a}=i,o=ur(i);e.addLayer({id:r,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-color":`#ffffff`,"fill-outline-color":`#000000`,"fill-antialias":!1}},n),e.addLayer({id:`${r}-pattern`,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-pattern":[`get`,`fill-pattern`]},layout:{visibility:`visible`}},n),e.addLayer({id:`${r}-outline`,type:`line`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"line-color":`#000000`,"line-width":.5}},n)}l.forEach((t,n)=>{let{featureIds:r,modelIdToFillColor:i,modelIdToFillPattern:a,modelIdToOutlineColor:o,modelIdToOutlineWidth:s}=t;e.setFilter(n,[`in`,`id`,...r]),e.setFilter(`${n}-outline`,[`in`,`id`,...r]),e.setPaintProperty(n,`fill-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,i]]),e.setPaintProperty(`${n}-outline`,`line-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,o]]),e.setPaintProperty(`${n}-outline`,`line-width`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,s]]),e.setFilter(`${n}-pattern`,[`to-boolean`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]]]),e.setPaintProperty(`${n}-pattern`,`fill-pattern`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]])})}function Zl(e,t,n){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(e=>Ql(t,e))}}),e.addLayer({id:t.id,type:`circle`,source:t.id,metadata:{"mc-model-type":`dot`,"mc-group-id":t.id},paint:{"circle-color":[`get`,`circle-color`],"circle-radius":[`get`,`circle-radius`],"circle-opacity":[`coalesce`,[`feature-state`,`opacity`],[`global-state`,`opacity-${t.id}`],1]}},n)}function Ql(e,t){return{type:`Feature`,id:t.id,properties:{id:t.id,"circle-radius":t.radius,"circle-color":e.fillColor||t.fillColor?Gr(t.dataBindings??{},t.fillColor,e.fillColor):`#000000`},geometry:{type:`Point`,coordinates:[t.center.lng,t.center.lat]}}}function $l(e,t,n,r){return t+n/r*e}function eu(e,t,n,r){return n*((e=e/r-1)*e*e+1)+t}function tu(e,t,n,r){let i=1.70158,a=0,o=n;return e===0?t:(e/=r)===1?t+n:(a||=r*.3,o<Math.abs(n)?(o=n,i=a/4):i=a/(2*Math.PI)*Math.asin(n/o),o*2**(-10*e)*Math.sin((e*r-i)*(2*Math.PI)/a)+n+t)}function nu(e,t,n,r,i){return i===void 0&&(i=1.70158),n*((e=e/r-1)*e*((i+1)*e+i)+1)+t}function ru(e,t,n,r){return(e/=r)<1/2.75?n*(7.5625*e*e)+t:e<2/2.75?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:e<2.5/2.75?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t}var iu={linear:$l,easeOutCubic:eu,easeOutBack:nu,easeOutBounce:ru,easeOutElastic:tu};function au(e){return e.entryType===`fade`||e.exitType===`fade`||e.entryType===`instant`||e.exitType===`instant`}function ou(e){return e.entryType===`grow`||e.exitType===`grow`}function su(e,t,n){let{entry:r,entryDuration:i,exit:a,exitDuration:o}=e,{entryType:s,entryEasing:c,exitType:l,exitEasing:u}=e;return n<r&&(s===t||s===`instant`&&t===`fade`)||n>a&&(l===t||l===`instant`&&t===`fade`)?0:i>0&&n<r+i&&s===t?iu[c](n-r,0,1,i):o>0&&n>a-o&&l===t?iu[u](n-(a-o),1,-1,o):1}function cu(e){let t=e.length>0?[lu(e[0])]:[],n=0,r=0;for(let i=1;i<e.length;++i){let a=lu(e[i]);n+=uu(e[i-1].center[0],a.center[0]),r+=uu(e[i-1].bearing,a.bearing),a.center[0]+=n*360,a.x+=n,a.bearing+=r*360,t.push(a)}return t}function lu(e){return{...e,center:[e.center[0],e.center[1]]}}function uu(e,t){if(Math.abs(e)+Math.abs(t)>180){if(e>0&&t<0)return 1;if(e<0&&t>0)return-1}return 0}function du(e){return 2**-e}function fu(e){return e.length>0?e[e.length-1].time:0}function pu(e){return te(e,23.976)?24e3/1001:te(e,29.97)?3e4/1001:te(e,59.94)?6e4/1001:e}function mu(e){return e<0?-1:1}function hu(e,t,n){var r=e._x1-e._x0,i=t-e._x1,a=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(mu(a)+mu(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function gu(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function _u(e,t,n){var r=e._x0,i=e._y0,a=e._x1,o=e._y1,s=(a-r)/3;e._context.bezierCurveTo(r+s,i+s*t,a-s,o-s*n,a,o)}function vu(e){this._context=e}vu.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:_u(this,this._t0,gu(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,_u(this,gu(this,n=hu(this,e,t)),n);break;default:_u(this,this._t0,n=hu(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function yu(e){this._context=new bu(e)}(yu.prototype=Object.create(vu.prototype)).point=function(e,t){vu.prototype.point.call(this,t,e)};function bu(e){this._context=e}bu.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,a){this._context.bezierCurveTo(t,e,r,n,a,i)}};function xu(e){return new vu(e)}function Su(e){return e}var{cbrt:Cu,sqrt:wu,PI:Tu}=Math,Eu=(e,t,n,r,i)=>{let a=t+n*e,o=a**2+r;if(o>0){let e=wu(o);return Cu(a+e)+Cu(a-e)-i}let s=Cu(wu(a*a-o)),c=a?Math.atan(wu(-o)/a):-Tu/2,l;return l=n<0?(a>0?2*Tu:Tu)-c:i<0?(a>0?2*Tu:-3*Tu)+c:(a>0?0:Tu)+c,2*s*Math.cos(l/3)-i},Du=(e,t,n,r)=>((t*e+3*n)*e+r)*e;function Ou(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw Error(`bezier x values must be in [0, 1] range`);if(e===t&&n===r)return Su;let i=6*(3*e-3*n+1),a=6*(n-2*e),o=3*e,s=i*i,c=a*a,l=a/i,u=3*a*o/s-c*a/(s*i),d=2*o/i-c/s,f=d*d*d,p=3/i,m=3*t-3*r+1,h=r-2*t,g=3*t,_=i?Eu:Su;return function(e){return e===0||e===1?e:Du(_(e,u,p,f,l),m,h,g)}}var ku=l(s(((e,t)=>{t.exports=n;function n(e,t,n,r){var i,a,o,s,c,l,u,d,f,p,m,h,g,_;for(typeof t!=`function`&&(r=n,n=t,t=null),r||={},s=r.tolerance===void 0?1e-7:r.tolerance,_=r.epsilon===void 0?2220446049250313e-31:r.epsilon,c=r.maxIterations===void 0?20:r.maxIterations,m=r.h===void 0?1e-4:r.h,g=r.verbose===void 0?!1:r.verbose,h=1/m,l=0;l++<c;){if(a=e(n),t?o=t(n):(u=e(n+m),d=e(n-m),f=e(n+2*m),p=e(n-2*m),o=(p-f+8*(u-d))*h/12),Math.abs(o)<=_*Math.abs(a))return g&&console.log(`Newton-Raphson: failed to converged due to nearly zero first derivative`),!1;if(i=n-a/o,Math.abs(i-n)<=s*Math.abs(i))return g&&console.log(`Newton-Raphson: converged to x = `+i+` after `+l+` iterations`),i;n=i}return g&&console.log(`Newton-Raphson: Maximum iterations reached (`+c+`)`),!1}}))(),1),Au=class{segments;constructor(e){this.segments=[];let t=new ju,n=xu(t);n.lineStart();for(let t of e)n.point(t.x,t.y);n.lineEnd(),this.segments=t.segments}sample(e){if(e<=0)return this.segments[0].startY;if(e>=this.segments[this.segments.length-1].endX)return this.segments[this.segments.length-1].endY;let t=this.segments.find(t=>e>=t.startX&&e<t.endX),n=M(t.startX,t.endX,e);return t.startY!==t.endY&&t.easing!==void 0?j(t.startY,t.endY,t.easing(n)):j(t.startY,t.endY,n)}solve(e,t){let n=(0,ku.default)(t=>this.sample(t)-e,t);return n===!1?t:n}},ju=class{previousPoint={x:0,y:0};segments=[];bezierCurveTo(e,t,n,r,i,a){let o=this.previousPoint.x,s=this.previousPoint.y,c=i===o?void 0:Ou((e-o)/(i-o),(t-s)/(a-s),(n-o)/(i-o),(r-s)/(a-s));this.segments.push({startX:o,endX:i,startY:s,endY:a,easing:c}),this.previousPoint={x:i,y:a}}lineTo(e,t){this.segments.push({startX:this.previousPoint.x,endX:e,startY:this.previousPoint.y,endY:t,easing:void 0}),this.previousPoint={x:e,y:t}}moveTo(e,t){this.previousPoint={x:e,y:t}}closePath(){}arc(){}rect(){}arcTo(){}quadraticCurveTo(){}},Mu=class{script;xCurve;yCurve;fovCurve;zoomCurve;pitchCurve;bearingCurve;altitudeCurve;elevationCurve;constructor(e){this.script=cu(e),this.xCurve=this.createMonotonicCurve(this.script,`x`),this.yCurve=this.createMonotonicCurve(this.script,`y`),this.fovCurve=this.createMonotonicCurve(this.script,`fov`),this.zoomCurve=this.createMonotonicCurve(this.script,`zoom`),this.pitchCurve=this.createMonotonicCurve(this.script,`pitch`),this.bearingCurve=this.createMonotonicCurve(this.script,`bearing`),this.altitudeCurve=this.createMonotonicCurve(this.script,`altitude`),this.elevationCurve=this.createMonotonicCurve(this.script,`elevation`)}sample(e){let t=this.zoomCurve.sample(e),n=this.altitudeCurve.solve(du(t),e),r=this.xCurve.sample(n),i=this.yCurve.sample(n),a=this.elevationCurve.sample(n),o=this.bearingCurve.sample(e),s=this.pitchCurve.sample(e),c=this.fovCurve.sample(e);return{center:new u.MercatorCoordinate(r,i).toLngLat(),zoom:t,bearing:o,pitch:s,fov:c,elevation:a}}createMonotonicCurve(e,t){let n=[];for(let r=0;r<e.length;r++){let i=r===0,a=r===e.length-1,o=e[r],s=e[r+1],c=e[r-1],l=this.getKeyframeValue(o,t);if(i&&n.push({x:-1,y:l}),n.push({x:o.time,y:l}),!i&&!a&&c.transition===`instant`&&o.transition===`ease`&&n.push({x:o.time+.1,y:l}),!a)if(o.transition===`linear`){let e=o.time+.1,r=s.time-.1,i=M(o.time,s.time,e),a=M(o.time,s.time,r),c=this.getKeyframeValue(s,t);n.push({x:e,y:j(l,c,i)}),n.push({x:r,y:j(l,c,a)})}else o.transition===`instant`&&(n.push({x:o.time+.1,y:l}),n.push({x:s.time-.1,y:l}));a&&n.push({x:o.time+1,y:l})}return new Au(n)}sampleAutoHideOpacity(e){let t=this.script;if(t.length<2)return 1;let n=this.getKeyframeIndexByTime(e);if(n===-1||n===t.length-1)return 1;let r=t[n],i=t[n+1],a=n>0?t[n-1]:void 0,o;if(r.hideLabels===(a?.hideLabels??!1))o=r.hideLabels?0:1;else{let t=e-r.time,n=Math.min(400,i.time-r.time);o=N(eu(t,r.hideLabels?1:0,r.hideLabels?-1:1,n),0,1)}let s;if(n===t.length-2&&r.hideLabels){let t=Math.max(r.time,i.time-400);s=N(eu(e-t,0,1,i.time-t),0,1)}else s=0;return Math.max(o,s)}getKeyframeIndexByTime(e){let t=this.script;if(t.length!==0){for(let n=0;n<t.length;n++)if(e<t[n].time)return n-1;return t.length-1}}getKeyframeValue(e,t){return t===`altitude`?du(e.zoom):e[t]}},Nu=Pu;function Pu(e,t,n){var r=null,i=null,a=function(){r&&=(clearTimeout(r),i=null,null)},o=function(){var e=i;a(),e&&e()},s=function(){if(!t)return e.apply(this,arguments);var o=this,s=arguments,c=n&&!r;if(a(),i=function(){e.apply(o,s)},r=setTimeout(function(){if(r=null,!c){var e=i;return i=null,e()}},t),c)return i()};return s.cancel=a,s.flush=o,s}var Fu=class{mcMap;cameraCurve;jobObject;svgs;svgCache;duration;mapstyle;overlays;layerInfo;playhead;playbackContext;constructor(e,t,n,r,i,a,o){this.mcMap=e,this.playhead=0,this.playbackContext=void 0;let s=(t.video?.keyframes??[]).map(e=>{let{x:t,y:n}=u.MercatorCoordinate.fromLngLat(e.center);return{...e,x:t,y:n,fov:e.fov??36.87,elevation:e.elevation??0}});this.duration=fu(s),this.cameraCurve=new Mu(s),this.jobObject=t,this.svgs=n,this.svgCache=r,this.mapstyle=i,this.overlays=a,this.layerInfo=o}play(){this.playbackContext===void 0&&this.duration>0&&(this.playhead>=this.duration&&(this.playhead=0),this.playbackContext={startTime:Date.now(),startPlayhead:this.playhead},this.mcMap.fire(`playstart`,{time:this.playhead}),this.playFrame())}pause(){this.playbackContext!==void 0&&(this.playbackContext=void 0,this.mcMap.fire(`playend`,{time:this.playhead}))}seekTo(e){this.duration>0&&(e=N(e,0,this.duration),this.prepareForPlayback(),this.setCamera(e),this.playbackContext!==void 0&&(this.playbackContext={startTime:Date.now(),startPlayhead:e}))}async*frames(){let e=this.mcMap.map,t=pu(this.jobObject.export?.frameRate??60),n=Math.ceil(this.duration*t/1e3);e._fadeDuration=0,e.style.stylesheet.transition={duration:0,delay:0},e.setCenterClampedToGround(!1);let r=e.getCanvas(),{width:i,height:a}=r,o=new OffscreenCanvas(i,a).getContext(`2d`,{desynchronized:!0,willReadFrequently:!0}),s=e.getContainer(),c=s.getBoundingClientRect();for(let e=0;e<n;e++)yield this.captureFrame(e*1e3/t,r,o,i,a,s,c);e._fadeDuration=300,e.style.stylesheet.transition=void 0,e.setCenterClampedToGround(!0)}async captureFrame(e,t,n,r,i,a,o){return this.setCamera(e),await this.mcMap.map.once(`idle`),n.fillStyle=`#ffffff`,n.fillRect(0,0,r,i),n.drawImage(t,0,0),await this.drawAdornments(n,a,o),n.getImageData(0,0,r,i)}async drawAdornments(e,t,n){let r=t.querySelectorAll(`.adornment-svg`),i=await Promise.all(Array.from(r).map(async e=>{let t=e.outerHTML,r=e.getBoundingClientRect(),i=r.left-n.left,a=r.top-n.top,o=r.width,s=r.height;return{image:await Ar(t,o,s),x:i,y:a}}));for(let t of i)e.drawImage(t.image,t.x,t.y)}playFrame(){if(this.playbackContext!==void 0){let e=this.playbackContext.startPlayhead+(Date.now()-this.playbackContext.startTime);this.prepareForPlayback(),e>this.duration?(this.setCamera(this.duration),this.playbackContext=void 0,this.mcMap.fire(`playend`,{time:this.playhead})):(this.setCamera(e),requestAnimationFrame(()=>this.playFrame()))}}setCamera(e){this.playhead=e;let t=this.mcMap.map,n=this.cameraCurve.sample(e),r=t.getCenter(),i=t.getZoom(),a=t.getBearing(),o=t.getPitch(),s=t.getCenterElevation(),c=t.getVerticalFieldOfView();n.center.lat!==r.lat||n.center.lng!==r.lng||n.zoom!==i||n.bearing!==a||n.pitch!==o||n.elevation!==s||n.fov!==c?(t.setVerticalFieldOfView(n.fov),t.jumpTo(n)):t.triggerRepaint(),this.applyAnimations(e),this.mcMap.fire(`play`,{time:e})}applyAnimations(e){let t=this.mcMap.map,{svgs:n,svgCache:r}=this,i=this.jobObject.video?.animations??[];for(let n of i){let{target:r}=n;if(r.type===`model`&&au(n)){let{modelType:i,groupId:a,modelId:o}=r,s=su(n,`fade`,e);(i===`polygon`||i===`circle`||i===`line`||i===`marker`||i===`dot`)&&(o===void 0?t.setGlobalStateProperty(`opacity-${a}`,s===1?null:s):t.setFeatureState({source:a,id:w(o)},{opacity:s}))}}for(let n of this.jobObject.registry?.models?.area??[]){let{groupAnimation:r,modelAnimations:a}=this.getGroupAnimations(i,`area`,n.id,`opacity`);if(!(r===void 0&&a.size===0))if(r!==void 0&&a.size===0){let i=su(r,`fade`,e);n.models.reduce((e,t)=>e.add(lr(n.id,t)),new Set).forEach(e=>{t.setPaintProperty(e,`fill-opacity`,i),t.setPaintProperty(`${e}-outline`,`line-opacity`,i),t.setPaintProperty(`${e}-pattern`,`fill-opacity`,i)})}else{let i=r===void 0?1:su(r,`fade`,e),o={};for(let t of n.models){let r=t.featureId===void 0?t.id:String(t.featureId),s=lr(n.id,t),c=a.get(t.id),l=c===void 0?i:su(c,`fade`,e);o[s]??={},o[s][r]=l}for(let[e,n]of Object.entries(o)){let r=[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,n]];t.setPaintProperty(e,`fill-opacity`,r),t.setPaintProperty(`${e}-outline`,`line-opacity`,r),t.setPaintProperty(`${e}-pattern`,`fill-opacity`,r)}}}for(let a of this.jobObject.registry?.models?.circle??[]){let{groupAnimation:o,modelAnimations:s}=this.getGroupAnimations(i,`circle`,a.id,`scale`),c=o===void 0?1:su(o,`grow`,e);(o!==void 0||s.size>0)&&t.getSource(a.id).setData({type:`FeatureCollection`,features:a.models.filter(e=>e.visible??!0).map(t=>{let i=s.get(t.id);return yl(a,t,i===void 0?c:su(i,`grow`,e),n,r)})})}for(let n of this.jobObject.registry?.models?.line??[]){let{groupAnimation:a,modelAnimations:o}=this.getGroupAnimations(i,`line`,n.id,`scale`),s=a===void 0?1:su(a,`grow`,e);(a!==void 0||o.size>0)&&t.getSource(n.id).setData({type:`FeatureCollection`,features:n.models.filter(e=>e.visible??!0).map(i=>{let a=o.get(i.id);return Jl(t,n,i,a===void 0?s:su(a,`grow`,e),r)})})}for(let a of this.jobObject.registry?.models?.marker??[]){let{groupAnimation:o,modelAnimations:s}=this.getGroupAnimations(i,`marker`,a.id,`scale`),c=o===void 0?1:su(o,`grow`,e);(o!==void 0||s.size>0)&&t.getSource(a.id).setData({type:`FeatureCollection`,features:a.models.filter(e=>e.visible??!0).map(t=>{let i=s.get(t.id);return Cl(a,t,i===void 0?c:su(i,`grow`,e),n,r)})})}let a=this.cameraCurve.sampleAutoHideOpacity(e);for(let t of this.mapstyle.layers){let n=this.getLayerOpacity(i,t,e,void 0);n===void 0?t.type===`symbol`&&this.setLayerOpacity(t,a):this.setLayerOpacity(t,n)}for(let[t,n]of this.overlays)for(let r of n.layers){let n=this.getLayerOpacity(i,r,e,t);n===void 0?this.resetLayerOpacity(r):this.setLayerOpacity(r,n)}}prepareForPlayback(){let e=this.mcMap.map;e.setCenterClampedToGround(!1),e.style?.stylesheet&&(e.style.stylesheet.transition={duration:0,delay:0}),this.restoreAfterPlayback()}restoreAfterPlayback=Nu(()=>{let e=this.mcMap.map;e.setCenterClampedToGround(!0),e.style?.stylesheet&&(e.style.stylesheet.transition=void 0)},300);getGroupAnimations(e,t,n,r){let i,a=new Map;for(let o of e){let{target:e}=o;e.type===`model`&&e.modelType===t&&e.groupId===n&&(r===`opacity`&&au(o)||r===`scale`&&ou(o))&&(e.modelId===void 0?i=o:a.set(e.modelId,o))}return{groupAnimation:i,modelAnimations:a}}getLayerOpacity(e,t,n,r){let i,a,o=1/0;r!==void 0&&(i=e.find(e=>e.target.type===`overlay`&&e.target.id===r));for(let n of e){let{target:e}=n;e.type===`layer`&&e.ids.includes(t.id)&&e.ids.length<o&&(a=n,o=e.ids.length)}let s=this.layerInfo[t.id]?.opacity??1;return a===void 0?i===void 0?void 0:su(i,`fade`,n)*s:su(a,`fade`,n)*s}setLayerOpacity(e,t){let n=this.mcMap.map,r=m[e.type];if(r){for(let i of r.props)n.setPaintProperty(e.id,i,t*r.defaultValue);n.setLayoutProperty(e.id,`visibility`,t===0?`none`:this.layerInfo[e.id]?.visibility?`visible`:`none`)}}resetLayerOpacity(e){let t=this.mcMap.map,n=m[e.type];if(!n)return;let r=this.layerInfo[e.id],i=r?.opacity;if(i!==void 0)for(let r of n.props)t.setPaintProperty(e.id,r,i*n.defaultValue);else for(let r of n.props){let i=e.paint?.[r]??n.defaultValue;t.setPaintProperty(e.id,r,i)}t.setLayoutProperty(e.id,`visibility`,r?.visibility?`visible`:`none`)}},Iu=class extends u.Evented{map;video;constructor(e,t,n,r,i,a,o){super(),this.map=e,this.video=new Fu(this,t,n,r,i,a,o)}on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}off(e,t){return super.off(e,t)}fire(e,t){return super.fire(e,t)}play(){this.video.play()}pause(){this.video.pause()}seekTo(e){this.video.seekTo(e)}frames(){return this.video.frames()}};async function Lu(e){let{accessToken:t,mode:n=`sdk`,env:r=`production`}=e,i=r===`bleeding`?`https://vapi.bleeding.mc-cdn.io`:r===`beta`?`https://vapi.beta.mc-cdn.io`:`https://vapi.mc-cdn.io`,a=r===`bleeding`?`https://cdn.bleeding.mapcreator.io`:r===`beta`?`https://cdn.beta.mapcreator.io`:`https://cdn.mapcreator.io`,o=typeof e.job==`string`?await Ru(e.job,a,t):e.job;await zu();let s=new u.Map({container:e.container,attributionControl:!1,style:null,maxBounds:[-1/0,-90,1/0,90],maxPitch:85,maxZoom:22,locale:{"CooperativeGesturesHandler.WindowsHelpText":Vi(`windowsHelpText`),"CooperativeGesturesHandler.MacHelpText":Vi(`macHelpText`),"CooperativeGesturesHandler.MobileHelpText":Vi(`mobileHelpText`)},canvasContextAttributes:{preserveDrawingBuffer:n===`video`}}),c=s.getContainer();c.classList.add(`mc-map`),c.classList.add(`mc-mode-${n}`);let l=new Br(s),d=new Wl(s,n),{map:{language:p,pitch:m=0,rotation:g=0,center:v,hideBasemap:b,detailLevel:x=0,projection:S=`mercator`,terrain:C=!1,terrainExaggeration:w=1},registry:T={},web:E,positionOffsets:D,title:O}=o,{models:k={},slots:A={},svgs:j={}}=T;Hu(r,i,t),s.resize(),n===`app`&&(document.title=O?`${O} - Mapcreator`:`Mapcreator`),s.setPitch(m),s.setBearing(g);let M=ee(o,c),N,P;if(n===`video`?(P=o.map.zoom-x,N=M):(P=o.map.zoom-x+Math.log2(M),N=1),s.setScale(N),s.setZoom(P),s.setCenter(v),s.setDetailLevel(x),s.setMinZoom(x),s.addControl(new u.AttributionControl({compact:!1})),n===`app`&&s.cooperativeGestures.enable(),dl(o,D??f,s,{center:v,zoom:P,pitch:m,rotation:g},i,a,t,N,n),d.setJobObject(o),E){let{restrictMapMovement:e,popupPosition:t}=E;e&&(s.boxZoom.disable(),s.doubleClickZoom.disable(),s.dragPan.disable(),s.dragRotate.disable(),s.keyboard.disable(),s.scrollZoom.disable(),s.touchPitch.disable(),s.touchZoomRotate.disable()),d.setParams(t,y(p,_.TWO),e,v)}let te=await fetch(`${i}/styles/${o.meta.mapstyleSet}.json?access_token=${t}`).then(e=>e.json());s.setStyle(null),s.setStyle(te),await s.once(`style.load`),n===`app`&&Uu(s.getStyle().metadata?.customCssFilePath,t),h(p,s);let F=await wl(o.map.overlays??[],o.meta.layers??[],s,i,t,te.metadata?.styleOverride),ne=(o.map.overlays??[]).reduce((e,t,n)=>e.set(t,F[n]),new Map);Ku(s,l,k,A,j,i,t),h(p,s),d.setPublication(te.metadata?.publication),d.setpopupElements(),d.setHighlightManager(),s.setProjection({type:S===`globe`?`globe`:`mercator`}),Bu(s,S),C&&Vu(s,i,t,w);let re=Wu(o.map.layerInfo,te,F);return Gu(s,re,!b),new Iu(s,o,j,l,te,ne,re)}function Ru(e,t,n){return fetch(`${t}/jobs/${e}.json?access_token=${n}`).then(e=>e.json())}function zu(){return new Promise(e=>{let t=()=>{window.innerWidth>0&&window.innerHeight>0&&(window.removeEventListener(`resize`,t),e())};window.addEventListener(`resize`,t),t()})}function Bu(e,t){let n=e.getStyle().metadata??{},r=n[`mc:background-color`]??`#f8f8f8`,i=n[`mc:background-color-globe`]??`#000000`;e.getContainer().style.backgroundColor=t===`globe`?i:r,e.setSky(e.getStyle().sky??d),e.setLight({position:[1.15,210,45]})}function Vu(e,t,n,r){e.addSource(`mc-dem`,{type:`raster-dem`,tiles:[`${t}/dataset/jaxa_terrainrgb/{z}/{x}/{y}?access_token=${n}`],attribution:`<a href="https://earth.jaxa.jp/en/data/policy" target="_blank">© AW3D30 (JAXA)</a>`,minzoom:0,maxzoom:12}),e.setTerrain({source:`mc-dem`,exaggeration:r})}function Hu(e,t,n){let r=`${t}/stylesheets/ff-${e===`beta`?`b-`:``}${n}.css?access_token=${n}`,i=document.createElement(`link`);i.setAttribute(`rel`,`stylesheet`),i.setAttribute(`href`,r),i.setAttribute(`type`,`text/css`),document.head.insertBefore(i,document.head.firstChild)}function Uu(e,t){if(document.getElementById(`custom-style`)?.remove(),!e)return;let n;e.startsWith(`http`)?(e=`${e}?access_token=${t}`,n=document.createElement(`link`),n.setAttribute(`rel`,`stylesheet`),n.setAttribute(`href`,e.replace(/https?:/,``))):(n=document.createElement(`style`),n.appendChild(document.createTextNode(e))),n.setAttribute(`id`,`custom-style`),n.setAttribute(`type`,`text/css`),document.head.appendChild(n)}function Wu(e,t,n){let r=e?.reduce((e,t)=>(e[t.id]={visibility:t.visibility,...t.opacity!==void 0&&{opacity:t.opacity}},e),{})??{},i={};for(let e of t.layers)i[e.id]=r[e.id]??{visibility:(e.layout?.visibility??`visible`)===`visible`};for(let e of n)for(let t of e.layers)i[t.id]=r[t.id]??{visibility:!1};return i}function Gu(e,t,n){for(let r in t){let i=e.getLayer(r);if(i!==void 0){let a=t[r];if(e.setLayoutProperty(r,`visibility`,a.visibility&&n?`visible`:`none`),a.opacity===void 0)continue;let o=m[i.type];if(!o)continue;let{props:s,defaultValue:c}=o;for(let t of s)e.setPaintProperty(r,t,a.opacity*c)}}}function Ku(e,t,n,r,i,a,o){let{beforeNone:s=[],beforeNames:c=[],beforeBoundaries:l=[],beforeWaters:u=[]}=r;s.forEach(r=>{qu(e,t,n,r,i,`mc-before-none`,a,o)}),c.forEach(r=>{qu(e,t,n,r,i,`mc-before-names`,a,o)}),l.forEach(r=>{qu(e,t,n,r,i,`mc-before-boundaries`,a,o)}),u.forEach(r=>{qu(e,t,n,r,i,`mc-before-waters`,a,o)})}function qu(e,t,n,r,i,a,o,s){if(r.type===`marker`){let o=n.marker?.find(e=>e.id===r.groupId);o&&xl(e,o,a,i,t)}else if(r.type===`polygon`){let o=n.polygon?.find(e=>e.id===r.groupId);o&&gl(e,o,a,i,t)}else if(r.type===`circle`){let o=n.circle?.find(e=>e.id===r.groupId);o&&vl(e,o,a,i,t)}else if(r.type===`line`){let i=n.line?.find(e=>e.id===r.groupId);i&&ql(e,i,a,t)}else if(r.type===`dot`){let t=n.dot?.find(e=>e.id===r.groupId);t&&Zl(e,t,a)}else if(r.type===`area`){let c=n.area?.find(e=>e.id===r.groupId);c&&Xl(e,c,a,i,t,o,s)}}e.initMap=Lu,e.setRTLTextPlugin=u.setRTLTextPlugin});
1178
+ `}return n}htmlToElement(e){let t=document.createElement(`template`);return t.innerHTML=e.trim(),t.content.firstElementChild}addPopupControls(){let e=this.htmlToElement(Il);if(e&&(e.addEventListener(`click`,()=>{this.hidePopup(),this.highlightManager.highlight(void 0)}),this.popupContainer.appendChild(e)),this.popupElements.length<2)return;let t=this.htmlToElement(Ll);t&&(t.querySelector(`.prev`)?.addEventListener(`click`,()=>this.cyclePopups(!1)),t.querySelector(`.next`)?.addEventListener(`click`,()=>this.cyclePopups()),this.popupContainer.appendChild(t))}addSwipeAction(){let e=0,t=0,n=0,r=0,i=!1,a=!1,o=null,s=this.popupContainer,c=(o,s)=>{e=n=o,t=r=s,i=!0,a=!1},l=(o,c,l)=>{if(!i)return;n=o,r=c;let u=n-e,d=r-t;!a&&Math.hypot(u,d)>5&&l&&(l.preventDefault(),s.setPointerCapture(l.pointerId),a=!0)},u=()=>{if(!i)return;if(a&&o!==null)try{s.releasePointerCapture(o)}catch{}i=!1,a=!1,o=null;let c=n-e,l=r-t;Math.abs(c)<Math.abs(l)||(c>20&&this.cyclePopups(),c<-20&&this.cyclePopups(!1))};s.addEventListener(`pointerdown`,e=>{e.pointerType!==`touch`&&(o=e.pointerId,c(e.clientX,e.clientY))}),s.addEventListener(`pointermove`,e=>{e.pointerType!==`touch`&&l(e.clientX,e.clientY,e)}),s.addEventListener(`pointerup`,e=>{e.pointerType!==`touch`&&u()}),s.addEventListener(`pointercancel`,e=>{e.pointerType!==`touch`&&u()}),s.addEventListener(`touchstart`,e=>{let t=e.touches[0];c(t.clientX,t.clientY)}),s.addEventListener(`touchmove`,n=>{if(!i)return;let r=n.touches[0],o=r.clientX-e,s=r.clientY-t;if(!a){if(Math.hypot(o,s)<5)return;if(Math.abs(s)>Math.abs(o)){i=!1;return}a=!0}n.preventDefault(),l(r.clientX,r.clientY)},{passive:!1}),s.addEventListener(`touchend`,e=>{let t=e.changedTouches[0];l(t.clientX,t.clientY),u()}),s.addEventListener(`touchcancel`,()=>{i=!1,a=!1})}fillDatalayerTemplate(e,t,n){let r=`data-mention-id`,i=new DOMParser().parseFromString(t,`text/html`).body;for(let t of i.querySelectorAll(`[${r}]`)){let i=this.getProperty(e,t.getAttribute(r),n);i!==void 0&&(t.innerText=i)}return i.innerHTML}getProperty(e,t,n){if(!t)return;let r=t.endsWith(`:en`)?[t.replace(`:en`,n),t]:[t];for(let t of r){let n=e.properties[t]??this.getVectorProperty(e,t);if(n!==void 0)return n}}getVectorProperty(e,t){let n=this.promoteIdCache.get(e.source);n===void 0&&(n=this.map.getSource(e.source)?.serialize().promoteId||`id`,this.promoteIdCache.set(e.source,n));try{let r=e.properties[n];return e.layer.metadata.properties[t][r]}catch{return}}cyclePopups(e=!0){let t=this.popupElements?.findIndex(e=>e.modelId===this.currentModelId);if(t!==-1&&(this.popupElements?.length??0)>1){let n=0;n=e?t===this.popupElements.length-1?0:t+1:t===0?this.popupElements.length-1:t-1;let r=this.popupElements?.[n];this.highlightManager.highlight(r);let i=Fl(r.popup,r.popupMedia,r.dataBindings??{},this.mode),a=this.popupContainer;this.popupContainer.remove(),a.innerHTML=i,this.mapContainer.appendChild(a),this.currentModelId=r.modelId,this.addPopupControls(),e?this.popupContainer.querySelector(`.mc-popup-button.next`)?.focus():this.popupContainer.querySelector(`.mc-popup-button.prev`)?.focus(),this.currentFeatureId=void 0}}},Gl=class e{static#e(e){let t=0,n=[t];for(let r=1;r<e.length;++r){let i=e[r-1],a=e[r],o=a.x-i.x,s=a.y-i.y;t+=Math.sqrt(o*o+s*s),n.push(t)}return n}static#t(e,t){return e.x===t.x&&e.y===t.y}#n;#r;#i;#a;constructor(t){this.#n=t.filter((e,n)=>n===0||t[n][0]!==t[n-1][0]||t[n][1]!==t[n-1][1]),this.#r=this.#n.map(e=>u.MercatorCoordinate.fromLngLat(e)),this.#i=e.#e(this.#r),this.#a=this.#i[this.#i.length-1]}sample(e){let t=this.#r,n=this.#i;if(t.length<2)return t[0];e*=this.#a;for(let r=1;r<t.length;++r){let i=t[r-1],a=t[r],o=n[r-1],s=n[r];if(s>=e){let t=(e-o)/(s-o);return new u.MercatorCoordinate(j(i.x,a.x,t),j(i.y,a.y,t))}}return new u.MercatorCoordinate(t[t.length-1].x,t[t.length-1].y)}slice(t,n){if(this.#n.length<2)return this.#n;let r=this.#r.filter((e,r)=>this.#i[r]>=t*this.#a&&this.#i[r]<=n*this.#a);if(t>0){let n=this.sample(t);e.#t(n,r[0])||r.unshift(n)}if(n<1){let t=this.sample(n);e.#t(t,r[r.length-1])||r.push(t)}return r.map(e=>{let{lng:t,lat:n}=e.toLngLat();return[t,n]})}get length(){return this.#a}},Kl={solid:[1,0],dotted:[.7,.3],dashed:[3.5,1.5]};function ql(e,t,n,r){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(n=>Jl(e,t,n,1,r))}}),Object.entries(Kl).forEach(([r,i])=>{t.models.some(e=>(e.lineStyle??`solid`)===r)&&e.addLayer({id:`${t.id}-${r}`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},filter:[`all`,[`==`,[`geometry-type`],`LineString`],[`==`,[`get`,`line-style`],r]],paint:{"line-width":[`get`,`line-width`],"line-color":[`get`,`line-color`],"line-dasharray":i,"line-opacity":[`coalesce`,[`feature-state`,`opacity`],[`global-state`,`opacity-${t.id}`],1]}},n)}),e.addLayer({id:`${t.id}-clickable`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},paint:{"line-width":[`max`,[`get`,`line-width`],15],"line-opacity":0},filter:[`==`,[`geometry-type`],`LineString`]},n),t.models.some(e=>e.svg)&&e.addLayer({id:`${t.id}-icon`,type:`symbol`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},layout:{"icon-allow-overlap":!0,"icon-ignore-placement":!0,"icon-image":[`get`,`mc-image-key`],"icon-anchor":`center`,"icon-size":[`get`,`icon-size`],"icon-rotate":[`get`,`icon-rotate`],"icon-offset":[`get`,`icon-offset`]},paint:{"icon-opacity":[`coalesce`,[`feature-state`,`opacity`],[`global-state`,`opacity-${t.id}`],1]},filter:[`==`,[`geometry-type`],`Point`]},n)}function Jl(e,t,n,r,i){let a=new Gl(n.geometry).slice(0,r),o=n.svg===void 0?void 0:i.getMapLibreImageKey(qr(n.dataBindings??{},n.svg,void 0),window.devicePixelRatio*(n.iconScale??1));return{type:`Feature`,id:w(n.id),properties:{id:n.id,"line-width":n.lineWidth??3,"line-color":t.lineColor||n.lineColor?Gr(n.dataBindings??{},n.lineColor,t.lineColor):`#000000`,"line-style":n.lineStyle??`solid`,"mc-image-key":o,"icon-rotate":Yl(n,a,e),"icon-offset":n.iconOffset,"icon-size":n.iconScale},geometry:{type:`GeometryCollection`,geometries:[{type:`LineString`,coordinates:a},{type:`Point`,coordinates:a[a.length-1]}]}}}function Yl(e,t,n){return e.iconRotation?e.iconAlign?fr(t,n)+e.iconRotation:e.iconRotation:0}function Xl(e,t,n,r,i,a,o){let s=yr(t),c=new Map,l=new Map;for(let e of t.models){let n=e.featureId,a=t.id,o=[],u=ur(e),d=lr(a,e),f=l.get(d)??{model:e,featureIds:o,modelIdToFillColor:{},modelIdToFillPattern:{},modelIdToOutlineColor:{},modelIdToOutlineWidth:{}};if(e.visible??!0){f.featureIds.push(n);let a=e.fillPattern===void 0?null:i.getMapLibreImageKey(r[e.fillPattern],2*window.devicePixelRatio);f.modelIdToFillColor[n]=t.fillColor||e.fillColor?Gr(e.dataBindings??{},e.fillColor,t.fillColor,s,t.choropleth?.unmatchedColor):`#000000`,f.modelIdToFillPattern[n]=a,f.modelIdToOutlineColor[n]=t.outlineColor||e.outlineColor?Gr(e.dataBindings??{},e.outlineColor,t.outlineColor):`#000000`,f.modelIdToOutlineWidth[n]=e.outlineWidth??.5}c.set(u,e),l.set(d,f)}for(let t of c.keys())e.getSource(t)||e.addSource(t,{type:`vector`,url:`${a}${c.get(t).vectorUrl}?access_token=${o}`});for(let r of l.keys()){let{model:i}=l.get(r),{sourceLayerId:a}=i,o=ur(i);e.addLayer({id:r,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-color":`#ffffff`,"fill-outline-color":`#000000`,"fill-antialias":!1}},n),e.addLayer({id:`${r}-pattern`,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-pattern":[`get`,`fill-pattern`]},layout:{visibility:`visible`}},n),e.addLayer({id:`${r}-outline`,type:`line`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"line-color":`#000000`,"line-width":.5}},n)}l.forEach((t,n)=>{let{featureIds:r,modelIdToFillColor:i,modelIdToFillPattern:a,modelIdToOutlineColor:o,modelIdToOutlineWidth:s}=t;e.setFilter(n,[`in`,`id`,...r]),e.setFilter(`${n}-outline`,[`in`,`id`,...r]),e.setPaintProperty(n,`fill-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,i]]),e.setPaintProperty(`${n}-outline`,`line-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,o]]),e.setPaintProperty(`${n}-outline`,`line-width`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,s]]),e.setFilter(`${n}-pattern`,[`to-boolean`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]]]),e.setPaintProperty(`${n}-pattern`,`fill-pattern`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]])})}function Zl(e,t,n){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(e=>Ql(t,e))}}),e.addLayer({id:t.id,type:`circle`,source:t.id,metadata:{"mc-model-type":`dot`,"mc-group-id":t.id},paint:{"circle-color":[`get`,`circle-color`],"circle-radius":[`get`,`circle-radius`],"circle-opacity":[`coalesce`,[`feature-state`,`opacity`],[`global-state`,`opacity-${t.id}`],1]}},n)}function Ql(e,t){return{type:`Feature`,id:t.id,properties:{id:t.id,"circle-radius":t.radius,"circle-color":e.fillColor||t.fillColor?Gr(t.dataBindings??{},t.fillColor,e.fillColor):`#000000`},geometry:{type:`Point`,coordinates:[t.center.lng,t.center.lat]}}}function $l(e,t,n,r){return t+n/r*e}function eu(e,t,n,r){return n*((e=e/r-1)*e*e+1)+t}function tu(e,t,n,r){let i=1.70158,a=0,o=n;return e===0?t:(e/=r)===1?t+n:(a||=r*.3,o<Math.abs(n)?(o=n,i=a/4):i=a/(2*Math.PI)*Math.asin(n/o),o*2**(-10*e)*Math.sin((e*r-i)*(2*Math.PI)/a)+n+t)}function nu(e,t,n,r,i){return i===void 0&&(i=1.70158),n*((e=e/r-1)*e*((i+1)*e+i)+1)+t}function ru(e,t,n,r){return(e/=r)<1/2.75?n*(7.5625*e*e)+t:e<2/2.75?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:e<2.5/2.75?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t}var iu={linear:$l,easeOutCubic:eu,easeOutBack:nu,easeOutBounce:ru,easeOutElastic:tu};function au(e){return e.entryType===`fade`||e.exitType===`fade`||e.entryType===`instant`||e.exitType===`instant`}function ou(e){return e.entryType===`grow`||e.exitType===`grow`}function su(e,t,n){let{entry:r,entryDuration:i,exit:a,exitDuration:o}=e,{entryType:s,entryEasing:c,exitType:l,exitEasing:u}=e;return n<r&&(s===t||s===`instant`&&t===`fade`)||n>a&&(l===t||l===`instant`&&t===`fade`)?0:i>0&&n<r+i&&s===t?iu[c](n-r,0,1,i):o>0&&n>a-o&&l===t?iu[u](n-(a-o),1,-1,o):1}function cu(e){let t=e.length>0?[lu(e[0])]:[],n=0,r=0;for(let i=1;i<e.length;++i){let a=lu(e[i]);n+=uu(e[i-1].center[0],a.center[0]),r+=uu(e[i-1].bearing,a.bearing),a.center[0]+=n*360,a.x+=n,a.bearing+=r*360,t.push(a)}return t}function lu(e){return{...e,center:[e.center[0],e.center[1]]}}function uu(e,t){if(Math.abs(e)+Math.abs(t)>180){if(e>0&&t<0)return 1;if(e<0&&t>0)return-1}return 0}function du(e){return 2**-e}function fu(e){return e.length>0?e[e.length-1].time:0}function pu(e){return te(e,23.976)?24e3/1001:te(e,29.97)?3e4/1001:te(e,59.94)?6e4/1001:e}function mu(e){return e<0?-1:1}function hu(e,t,n){var r=e._x1-e._x0,i=t-e._x1,a=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(mu(a)+mu(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function gu(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function _u(e,t,n){var r=e._x0,i=e._y0,a=e._x1,o=e._y1,s=(a-r)/3;e._context.bezierCurveTo(r+s,i+s*t,a-s,o-s*n,a,o)}function vu(e){this._context=e}vu.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:_u(this,this._t0,gu(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,_u(this,gu(this,n=hu(this,e,t)),n);break;default:_u(this,this._t0,n=hu(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function yu(e){this._context=new bu(e)}(yu.prototype=Object.create(vu.prototype)).point=function(e,t){vu.prototype.point.call(this,t,e)};function bu(e){this._context=e}bu.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,a){this._context.bezierCurveTo(t,e,r,n,a,i)}};function xu(e){return new vu(e)}function Su(e){return e}var{cbrt:Cu,sqrt:wu,PI:Tu}=Math,Eu=(e,t,n,r,i)=>{let a=t+n*e,o=a**2+r;if(o>0){let e=wu(o);return Cu(a+e)+Cu(a-e)-i}let s=Cu(wu(a*a-o)),c=a?Math.atan(wu(-o)/a):-Tu/2,l;return l=n<0?(a>0?2*Tu:Tu)-c:i<0?(a>0?2*Tu:-3*Tu)+c:(a>0?0:Tu)+c,2*s*Math.cos(l/3)-i},Du=(e,t,n,r)=>((t*e+3*n)*e+r)*e;function Ou(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw Error(`bezier x values must be in [0, 1] range`);if(e===t&&n===r)return Su;let i=6*(3*e-3*n+1),a=6*(n-2*e),o=3*e,s=i*i,c=a*a,l=a/i,u=3*a*o/s-c*a/(s*i),d=2*o/i-c/s,f=d*d*d,p=3/i,m=3*t-3*r+1,h=r-2*t,g=3*t,_=i?Eu:Su;return function(e){return e===0||e===1?e:Du(_(e,u,p,f,l),m,h,g)}}var ku=l(s(((e,t)=>{t.exports=n;function n(e,t,n,r){var i,a,o,s,c,l,u,d,f,p,m,h,g,_;for(typeof t!=`function`&&(r=n,n=t,t=null),r||={},s=r.tolerance===void 0?1e-7:r.tolerance,_=r.epsilon===void 0?2220446049250313e-31:r.epsilon,c=r.maxIterations===void 0?20:r.maxIterations,m=r.h===void 0?1e-4:r.h,g=r.verbose===void 0?!1:r.verbose,h=1/m,l=0;l++<c;){if(a=e(n),t?o=t(n):(u=e(n+m),d=e(n-m),f=e(n+2*m),p=e(n-2*m),o=(p-f+8*(u-d))*h/12),Math.abs(o)<=_*Math.abs(a))return g&&console.log(`Newton-Raphson: failed to converged due to nearly zero first derivative`),!1;if(i=n-a/o,Math.abs(i-n)<=s*Math.abs(i))return g&&console.log(`Newton-Raphson: converged to x = `+i+` after `+l+` iterations`),i;n=i}return g&&console.log(`Newton-Raphson: Maximum iterations reached (`+c+`)`),!1}}))(),1),Au=class{segments;constructor(e){this.segments=[];let t=new ju,n=xu(t);n.lineStart();for(let t of e)n.point(t.x,t.y);n.lineEnd(),this.segments=t.segments}sample(e){if(e<=0)return this.segments[0].startY;if(e>=this.segments[this.segments.length-1].endX)return this.segments[this.segments.length-1].endY;let t=this.segments.find(t=>e>=t.startX&&e<t.endX),n=M(t.startX,t.endX,e);return t.startY!==t.endY&&t.easing!==void 0?j(t.startY,t.endY,t.easing(n)):j(t.startY,t.endY,n)}solve(e,t){let n=(0,ku.default)(t=>this.sample(t)-e,t);return n===!1?t:n}},ju=class{previousPoint={x:0,y:0};segments=[];bezierCurveTo(e,t,n,r,i,a){let o=this.previousPoint.x,s=this.previousPoint.y,c=i===o?void 0:Ou((e-o)/(i-o),(t-s)/(a-s),(n-o)/(i-o),(r-s)/(a-s));this.segments.push({startX:o,endX:i,startY:s,endY:a,easing:c}),this.previousPoint={x:i,y:a}}lineTo(e,t){this.segments.push({startX:this.previousPoint.x,endX:e,startY:this.previousPoint.y,endY:t,easing:void 0}),this.previousPoint={x:e,y:t}}moveTo(e,t){this.previousPoint={x:e,y:t}}closePath(){}arc(){}rect(){}arcTo(){}quadraticCurveTo(){}},Mu=class{script;xCurve;yCurve;fovCurve;zoomCurve;pitchCurve;bearingCurve;altitudeCurve;elevationCurve;constructor(e){this.script=cu(e),this.xCurve=this.createMonotonicCurve(this.script,`x`),this.yCurve=this.createMonotonicCurve(this.script,`y`),this.fovCurve=this.createMonotonicCurve(this.script,`fov`),this.zoomCurve=this.createMonotonicCurve(this.script,`zoom`),this.pitchCurve=this.createMonotonicCurve(this.script,`pitch`),this.bearingCurve=this.createMonotonicCurve(this.script,`bearing`),this.altitudeCurve=this.createMonotonicCurve(this.script,`altitude`),this.elevationCurve=this.createMonotonicCurve(this.script,`elevation`)}sample(e){let t=this.zoomCurve.sample(e),n=this.altitudeCurve.solve(du(t),e),r=this.xCurve.sample(n),i=this.yCurve.sample(n),a=this.elevationCurve.sample(n),o=this.bearingCurve.sample(e),s=this.pitchCurve.sample(e),c=this.fovCurve.sample(e);return{center:new u.MercatorCoordinate(r,i).toLngLat(),zoom:t,bearing:o,pitch:s,fov:c,elevation:a}}createMonotonicCurve(e,t){let n=[];for(let r=0;r<e.length;r++){let i=r===0,a=r===e.length-1,o=e[r],s=e[r+1],c=e[r-1],l=this.getKeyframeValue(o,t);if(i&&n.push({x:-1,y:l}),n.push({x:o.time,y:l}),!i&&!a&&c.transition===`instant`&&o.transition===`ease`&&n.push({x:o.time+.1,y:l}),!a)if(o.transition===`linear`){let e=o.time+.1,r=s.time-.1,i=M(o.time,s.time,e),a=M(o.time,s.time,r),c=this.getKeyframeValue(s,t);n.push({x:e,y:j(l,c,i)}),n.push({x:r,y:j(l,c,a)})}else o.transition===`instant`&&(n.push({x:o.time+.1,y:l}),n.push({x:s.time-.1,y:l}));a&&n.push({x:o.time+1,y:l})}return new Au(n)}sampleAutoHideOpacity(e){let t=this.script;if(t.length<2)return 1;let n=this.getKeyframeIndexByTime(e);if(n===-1||n===t.length-1)return 1;let r=t[n],i=t[n+1],a=n>0?t[n-1]:void 0,o;if(r.hideLabels===(a?.hideLabels??!1))o=r.hideLabels?0:1;else{let t=e-r.time,n=Math.min(400,i.time-r.time);o=N(eu(t,r.hideLabels?1:0,r.hideLabels?-1:1,n),0,1)}let s;if(n===t.length-2&&r.hideLabels){let t=Math.max(r.time,i.time-400);s=N(eu(e-t,0,1,i.time-t),0,1)}else s=0;return Math.max(o,s)}getKeyframeIndexByTime(e){let t=this.script;if(t.length!==0){for(let n=0;n<t.length;n++)if(e<t[n].time)return n-1;return t.length-1}}getKeyframeValue(e,t){return t===`altitude`?du(e.zoom):e[t]}},Nu=Pu;function Pu(e,t,n){var r=null,i=null,a=function(){r&&=(clearTimeout(r),i=null,null)},o=function(){var e=i;a(),e&&e()},s=function(){if(!t)return e.apply(this,arguments);var o=this,s=arguments,c=n&&!r;if(a(),i=function(){e.apply(o,s)},r=setTimeout(function(){if(r=null,!c){var e=i;return i=null,e()}},t),c)return i()};return s.cancel=a,s.flush=o,s}var Fu=class{mcMap;cameraCurve;jobObject;svgs;svgCache;duration;mapstyle;overlays;layerInfo;playhead;playbackContext;constructor(e,t,n,r,i,a,o){this.mcMap=e,this.playhead=0,this.playbackContext=void 0;let s=(t.video?.keyframes??[]).map(e=>{let{x:t,y:n}=u.MercatorCoordinate.fromLngLat(e.center);return{...e,x:t,y:n,fov:e.fov??36.87,elevation:e.elevation??0}});this.duration=fu(s),this.cameraCurve=new Mu(s),this.jobObject=t,this.svgs=n,this.svgCache=r,this.mapstyle=i,this.overlays=a,this.layerInfo=o}play(){this.playbackContext===void 0&&this.duration>0&&(this.playhead>=this.duration&&(this.playhead=0),this.playbackContext={startTime:Date.now(),startPlayhead:this.playhead},this.mcMap.fire(`playstart`,{time:this.playhead}),this.playFrame())}pause(){this.playbackContext!==void 0&&(this.playbackContext=void 0,this.mcMap.fire(`playend`,{time:this.playhead}))}seekTo(e){this.duration>0&&(e=N(e,0,this.duration),this.prepareForPlayback(),this.setCamera(e),this.playbackContext!==void 0&&(this.playbackContext={startTime:Date.now(),startPlayhead:e}))}async*frames(){let e=this.mcMap.map,t=pu(this.jobObject.export?.frameRate??60),n=Math.ceil(this.duration*t/1e3);e._fadeDuration=0,e.style.stylesheet.transition={duration:0,delay:0},e.setCenterClampedToGround(!1);let r=e.getCanvas(),{width:i,height:a}=r,o=new OffscreenCanvas(i,a).getContext(`2d`,{desynchronized:!0,willReadFrequently:!0}),s=e.getContainer(),c=s.getBoundingClientRect();for(let e=0;e<n;e++)yield this.captureFrame(e*1e3/t,r,o,i,a,s,c);e._fadeDuration=300,e.style.stylesheet.transition=void 0,e.setCenterClampedToGround(!0)}async captureFrame(e,t,n,r,i,a,o){return this.setCamera(e),await this.mcMap.map.once(`idle`),n.fillStyle=`#ffffff`,n.fillRect(0,0,r,i),n.drawImage(t,0,0),await this.drawAdornments(n,a,o),n.getImageData(0,0,r,i)}async drawAdornments(e,t,n){let r=t.querySelectorAll(`.adornment-svg`),i=await Promise.all(Array.from(r).map(async e=>{let t=e.outerHTML,r=e.getBoundingClientRect(),i=r.left-n.left,a=r.top-n.top,o=r.width,s=r.height;return{image:await Ar(t,o,s),x:i,y:a}}));for(let t of i)e.drawImage(t.image,t.x,t.y)}playFrame(){if(this.playbackContext!==void 0){let e=this.playbackContext.startPlayhead+(Date.now()-this.playbackContext.startTime);this.prepareForPlayback(),e>this.duration?(this.setCamera(this.duration),this.playbackContext=void 0,this.mcMap.fire(`playend`,{time:this.playhead})):(this.setCamera(e),requestAnimationFrame(()=>this.playFrame()))}}setCamera(e){this.playhead=e;let t=this.mcMap.map,n=this.cameraCurve.sample(e),r=t.getCenter(),i=t.getZoom(),a=t.getBearing(),o=t.getPitch(),s=t.getCenterElevation(),c=t.getVerticalFieldOfView();n.center.lat!==r.lat||n.center.lng!==r.lng||n.zoom!==i||n.bearing!==a||n.pitch!==o||n.elevation!==s||n.fov!==c?(t.setVerticalFieldOfView(n.fov),t.jumpTo(n)):t.triggerRepaint(),this.applyAnimations(e),this.mcMap.fire(`play`,{time:e})}applyAnimations(e){let t=this.mcMap.map,{svgs:n,svgCache:r}=this,i=this.jobObject.video?.animations??[];for(let n of i){let{target:r}=n;if(r.type===`model`&&au(n)){let{modelType:i,groupId:a,modelId:o}=r,s=su(n,`fade`,e);(i===`polygon`||i===`circle`||i===`line`||i===`marker`||i===`dot`)&&(o===void 0?t.setGlobalStateProperty(`opacity-${a}`,s===1?null:s):t.setFeatureState({source:a,id:w(o)},{opacity:s}))}}for(let n of this.jobObject.registry?.models?.area??[]){let{groupAnimation:r,modelAnimations:a}=this.getGroupAnimations(i,`area`,n.id,`opacity`);if(!(r===void 0&&a.size===0))if(r!==void 0&&a.size===0){let i=su(r,`fade`,e);n.models.reduce((e,t)=>e.add(lr(n.id,t)),new Set).forEach(e=>{t.setPaintProperty(e,`fill-opacity`,i),t.setPaintProperty(`${e}-outline`,`line-opacity`,i),t.setPaintProperty(`${e}-pattern`,`fill-opacity`,i)})}else{let i=r===void 0?1:su(r,`fade`,e),o={};for(let t of n.models){let r=t.featureId===void 0?t.id:String(t.featureId),s=lr(n.id,t),c=a.get(t.id),l=c===void 0?i:su(c,`fade`,e);o[s]??={},o[s][r]=l}for(let[e,n]of Object.entries(o)){let r=[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,n]];t.setPaintProperty(e,`fill-opacity`,r),t.setPaintProperty(`${e}-outline`,`line-opacity`,r),t.setPaintProperty(`${e}-pattern`,`fill-opacity`,r)}}}for(let a of this.jobObject.registry?.models?.circle??[]){let{groupAnimation:o,modelAnimations:s}=this.getGroupAnimations(i,`circle`,a.id,`scale`),c=o===void 0?1:su(o,`grow`,e);(o!==void 0||s.size>0)&&t.getSource(a.id).setData({type:`FeatureCollection`,features:a.models.filter(e=>e.visible??!0).map(t=>{let i=s.get(t.id);return yl(a,t,i===void 0?c:su(i,`grow`,e),n,r)})})}for(let n of this.jobObject.registry?.models?.line??[]){let{groupAnimation:a,modelAnimations:o}=this.getGroupAnimations(i,`line`,n.id,`scale`),s=a===void 0?1:su(a,`grow`,e);(a!==void 0||o.size>0)&&t.getSource(n.id).setData({type:`FeatureCollection`,features:n.models.filter(e=>e.visible??!0).map(i=>{let a=o.get(i.id);return Jl(t,n,i,a===void 0?s:su(a,`grow`,e),r)})})}for(let a of this.jobObject.registry?.models?.marker??[]){let{groupAnimation:o,modelAnimations:s}=this.getGroupAnimations(i,`marker`,a.id,`scale`),c=o===void 0?1:su(o,`grow`,e);(o!==void 0||s.size>0)&&t.getSource(a.id).setData({type:`FeatureCollection`,features:a.models.filter(e=>e.visible??!0).map(t=>{let i=s.get(t.id);return Cl(a,t,i===void 0?c:su(i,`grow`,e),n,r)})})}let a=this.cameraCurve.sampleAutoHideOpacity(e);for(let t of this.mapstyle.layers){let n=this.getLayerOpacity(i,t,e,void 0);n===void 0?t.type===`symbol`&&this.setLayerOpacity(t,a):this.setLayerOpacity(t,n)}for(let[t,n]of this.overlays)for(let r of n.layers){let n=this.getLayerOpacity(i,r,e,t);n===void 0?this.resetLayerOpacity(r):this.setLayerOpacity(r,n)}}prepareForPlayback(){let e=this.mcMap.map;e.setCenterClampedToGround(!1),e.style?.stylesheet&&(e.style.stylesheet.transition={duration:0,delay:0}),this.restoreAfterPlayback()}restoreAfterPlayback=Nu(()=>{let e=this.mcMap.map;e.setCenterClampedToGround(!0),e.style?.stylesheet&&(e.style.stylesheet.transition=void 0)},300);getGroupAnimations(e,t,n,r){let i,a=new Map;for(let o of e){let{target:e}=o;e.type===`model`&&e.modelType===t&&e.groupId===n&&(r===`opacity`&&au(o)||r===`scale`&&ou(o))&&(e.modelId===void 0?i=o:a.set(e.modelId,o))}return{groupAnimation:i,modelAnimations:a}}getLayerOpacity(e,t,n,r){let i,a,o=1/0;r!==void 0&&(i=e.find(e=>e.target.type===`overlay`&&e.target.id===r));for(let n of e){let{target:e}=n;e.type===`layer`&&e.ids.includes(t.id)&&e.ids.length<o&&(a=n,o=e.ids.length)}let s=this.layerInfo[t.id]?.opacity??1;return a===void 0?i===void 0?void 0:su(i,`fade`,n)*s:su(a,`fade`,n)*s}setLayerOpacity(e,t){let n=this.mcMap.map,r=m[e.type];if(r){for(let i of r.props)n.setPaintProperty(e.id,i,t*r.defaultValue);n.setLayoutProperty(e.id,`visibility`,t===0?`none`:this.layerInfo[e.id]?.visibility?`visible`:`none`)}}resetLayerOpacity(e){let t=this.mcMap.map,n=m[e.type];if(!n)return;let r=this.layerInfo[e.id],i=r?.opacity;if(i!==void 0)for(let r of n.props)t.setPaintProperty(e.id,r,i*n.defaultValue);else for(let r of n.props){let i=e.paint?.[r]??n.defaultValue;t.setPaintProperty(e.id,r,i)}t.setLayoutProperty(e.id,`visibility`,r?.visibility?`visible`:`none`)}},Iu=class extends u.Evented{map;video;constructor(e,t,n,r,i,a,o){super(),this.map=e,this.video=new Fu(this,t,n,r,i,a,o)}on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}off(e,t){return super.off(e,t)}fire(e,t){return super.fire(e,t)}play(){this.video.play()}pause(){this.video.pause()}seekTo(e){this.video.seekTo(e)}frames(){return this.video.frames()}};async function Lu(e){let{accessToken:t,mode:n=`sdk`,env:r=`production`}=e,i=r===`bleeding`?`https://vapi.bleeding.mc-cdn.io`:r===`beta`?`https://vapi.beta.mc-cdn.io`:`https://vapi.mc-cdn.io`,a=r===`bleeding`?`https://cdn.bleeding.mapcreator.io`:r===`beta`?`https://cdn.beta.mapcreator.io`:`https://cdn.mapcreator.io`,o=typeof e.job==`string`?await Ru(e.job,a,t):e.job;await zu();let s=new u.Map({container:e.container,attributionControl:!1,style:null,maxBounds:[-1/0,-90,1/0,90],maxPitch:85,maxZoom:22,locale:{"CooperativeGesturesHandler.WindowsHelpText":Vi(`windowsHelpText`),"CooperativeGesturesHandler.MacHelpText":Vi(`macHelpText`),"CooperativeGesturesHandler.MobileHelpText":Vi(`mobileHelpText`)},canvasContextAttributes:{preserveDrawingBuffer:n===`video`}}),c=s.getContainer();c.classList.add(`mc-map`),c.classList.add(`mc-mode-${n}`);let l=new Br(s),d=new Wl(s,n),{map:{language:p,pitch:m=0,rotation:g=0,center:v,hideBasemap:b,detailLevel:x=0,projection:S=`mercator`,terrain:C=!1,terrainExaggeration:w=1},registry:T={},web:E,positionOffsets:D,title:O}=o,{models:k={},slots:A={},svgs:j={}}=T;Hu(r,i,t),s.resize(),n===`app`&&(document.title=O?`${O} - Mapcreator`:`Mapcreator`),s.setPitch(m),s.setBearing(g);let M=ee(o,c),N,P;if(n===`video`?(P=o.map.zoom-x,N=M):(P=o.map.zoom-x+Math.log2(M),N=1),s.setScale(N),s.setZoom(P),s.setCenter(v),s.setDetailLevel(x),s.setMinZoom(x),s.addControl(new u.AttributionControl({compact:!1})),n===`app`&&s.cooperativeGestures.enable(),dl(o,D??f,s,{center:v,zoom:P,pitch:m,rotation:g},i,a,t,N,n),d.setJobObject(o),E){let{restrictMapMovement:e,popupPosition:t}=E;e&&(s.boxZoom.disable(),s.doubleClickZoom.disable(),s.dragPan.disable(),s.dragRotate.disable(),s.keyboard.disable(),s.scrollZoom.disable(),s.touchPitch.disable(),s.touchZoomRotate.disable()),d.setParams(t,y(p,_.TWO),e,v)}let te=await fetch(`${i}/styles/${o.meta.mapstyleSet}.json?access_token=${t}`).then(e=>e.json());s.setStyle(null),s.setStyle(te),await s.once(`style.load`),n===`app`&&Uu(s.getStyle().metadata?.customCssFilePath,t),h(p,s);let F=await wl(o.map.overlays??[],o.meta.layers??[],s,i,t,te.metadata?.styleOverride),ne=(o.map.overlays??[]).reduce((e,t,n)=>e.set(t,F[n]),new Map);Ku(s,l,k,A,j,i,t),h(p,s),d.setPublication(te.metadata?.publication),d.setpopupElements(),d.setHighlightManager(),s.setProjection({type:S===`globe`?`globe`:`mercator`}),Bu(s,S),C&&Vu(s,i,t,w);let re=Wu(o.map.layerInfo,te,F);return Gu(s,re,!b),new Iu(s,o,j,l,te,ne,re)}function Ru(e,t,n){return fetch(`${t}/jobs/${e}.json?access_token=${n}`).then(e=>e.json())}function zu(){return new Promise(e=>{let t=()=>{window.innerWidth>0&&window.innerHeight>0&&(window.removeEventListener(`resize`,t),e())};window.addEventListener(`resize`,t),t()})}function Bu(e,t){let n=e.getStyle().metadata??{},r=n[`mc:background-color`]??`#f8f8f8`,i=n[`mc:background-color-globe`]??`#000000`;e.getContainer().style.backgroundColor=t===`globe`?i:r,e.setSky(e.getStyle().sky??d),e.setLight({position:[1.15,210,45]})}function Vu(e,t,n,r){e.addSource(`mc-dem`,{type:`raster-dem`,tiles:[`${t}/dataset/jaxa_terrainrgb/{z}/{x}/{y}?access_token=${n}`],attribution:`<a href="https://earth.jaxa.jp/en/data/policy" target="_blank">© AW3D30 (JAXA)</a>`,minzoom:0,maxzoom:12}),e.setTerrain({source:`mc-dem`,exaggeration:r})}function Hu(e,t,n){let r=`${t}/stylesheets/ff-${e===`beta`?`b-`:``}${n}.css?access_token=${n}`,i=document.createElement(`link`);i.setAttribute(`rel`,`stylesheet`),i.setAttribute(`href`,r),i.setAttribute(`type`,`text/css`),document.head.insertBefore(i,document.head.firstChild)}function Uu(e,t){if(document.getElementById(`custom-style`)?.remove(),!e)return;let n;e.startsWith(`http`)?(e=`${e}?access_token=${t}`,n=document.createElement(`link`),n.setAttribute(`rel`,`stylesheet`),n.setAttribute(`href`,e.replace(/https?:/,``))):(n=document.createElement(`style`),n.appendChild(document.createTextNode(e))),n.setAttribute(`id`,`custom-style`),n.setAttribute(`type`,`text/css`),document.head.appendChild(n)}function Wu(e,t,n){let r=e?.reduce((e,t)=>(e[t.id]={visibility:t.visibility,...t.opacity!==void 0&&{opacity:t.opacity}},e),{})??{},i={};for(let e of t.layers)i[e.id]=r[e.id]??{visibility:(e.layout?.visibility??`visible`)===`visible`};for(let e of n)for(let t of e.layers)i[t.id]=r[t.id]??{visibility:!1};return i}function Gu(e,t,n){for(let r in t){let i=e.getLayer(r);if(i!==void 0){let a=t[r];if(e.setLayoutProperty(r,`visibility`,a.visibility&&n?`visible`:`none`),a.opacity===void 0)continue;let o=m[i.type];if(!o)continue;let{props:s,defaultValue:c}=o;for(let t of s)e.setPaintProperty(r,t,a.opacity*c)}}}function Ku(e,t,n,r,i,a,o){let{beforeNone:s=[],beforeNames:c=[],beforeBoundaries:l=[],beforeWaters:u=[]}=r;s.forEach(r=>{qu(e,t,n,r,i,`mc-before-none`,a,o)}),c.forEach(r=>{qu(e,t,n,r,i,`mc-before-names`,a,o)}),l.forEach(r=>{qu(e,t,n,r,i,`mc-before-boundaries`,a,o)}),u.forEach(r=>{qu(e,t,n,r,i,`mc-before-waters`,a,o)})}function qu(e,t,n,r,i,a,o,s){if(r.type===`marker`){let o=n.marker?.find(e=>e.id===r.groupId);o&&xl(e,o,a,i,t)}else if(r.type===`polygon`){let o=n.polygon?.find(e=>e.id===r.groupId);o&&gl(e,o,a,i,t)}else if(r.type===`circle`){let o=n.circle?.find(e=>e.id===r.groupId);o&&vl(e,o,a,i,t)}else if(r.type===`line`){let i=n.line?.find(e=>e.id===r.groupId);i&&ql(e,i,a,t)}else if(r.type===`dot`){let t=n.dot?.find(e=>e.id===r.groupId);t&&Zl(e,t,a)}else if(r.type===`area`){let c=n.area?.find(e=>e.id===r.groupId);c&&Xl(e,c,a,i,t,o,s)}}e.initMap=Lu,e.setRTLTextPlugin=u.setRTLTextPlugin});