/*!
 * Mapbox GL JS Animated Popup v0.4.0
 * https://nagix.github.io/mapbox-gl-animated-popup
 * (c) 2020-2022 Akihiko Kusanagi
 * Released under the MIT license
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("mapbox-gl")):"function"==typeof define&&define.amd?define(["mapbox-gl"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).AnimatedPopup=t(e.mapboxgl)}(this,(function(e){"use strict";const t=e.version.split(".").map((e=>+e)),n={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>-e*(e-2),easeInOutQuad:e=>(e/=.5)<1?.5*e*e:-.5*(--e*(e-2)-1),easeInCubic:e=>e*e*e,easeOutCubic:e=>(e-=1)*e*e+1,easeInOutCubic:e=>(e/=.5)<1?.5*e*e*e:.5*((e-=2)*e*e+2),easeInQuart:e=>e*e*e*e,easeOutQuart:e=>-((e-=1)*e*e*e-1),easeInOutQuart:e=>(e/=.5)<1?.5*e*e*e*e:-.5*((e-=2)*e*e*e-2),easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>(e-=1)*e*e*e*e+1,easeInOutQuint:e=>(e/=.5)<1?.5*e*e*e*e*e:.5*((e-=2)*e*e*e*e+2),easeInSine:e=>1-Math.cos(e*(Math.PI/2)),easeOutSine:e=>Math.sin(e*(Math.PI/2)),easeInOutSine:e=>-.5*(Math.cos(Math.PI*e)-1),easeInExpo:e=>0===e?0:Math.pow(2,10*(e-1)),easeOutExpo:e=>1===e?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>0===e?0:1===e?1:(e/=.5)<1?.5*Math.pow(2,10*(e-1)):.5*(2-Math.pow(2,-10*--e)),easeInCirc:e=>e>=1?e:-(Math.sqrt(1-e*e)-1),easeOutCirc:e=>Math.sqrt(1-(e-=1)*e),easeInOutCirc:e=>(e/=.5)<1?-.5*(Math.sqrt(1-e*e)-1):.5*(Math.sqrt(1-(e-=2)*e)+1),easeInElastic(e){let t=1.70158,n=0;return 0===e?0:1===e?1:(n||(n=.3),t=n/(2*Math.PI)*Math.asin(1),-1*Math.pow(2,10*(e-=1))*Math.sin((e-t)*(2*Math.PI)/n))},easeOutElastic(e){let t=1.70158,n=0;return 0===e?0:1===e?1:(n||(n=.3),t=n/(2*Math.PI)*Math.asin(1),1*Math.pow(2,-10*e)*Math.sin((e-t)*(2*Math.PI)/n)+1)},easeInOutElastic(e){let t=1.70158,n=0;return 0===e?0:2==(e/=.5)?1:(n||(n=.45),t=n/(2*Math.PI)*Math.asin(1),e<1?1*Math.pow(2,10*(e-=1))*Math.sin((e-t)*(2*Math.PI)/n)*-.5:1*Math.pow(2,-10*(e-=1))*Math.sin((e-t)*(2*Math.PI)/n)*.5+1)},easeInBack(e){const t=1.70158;return e*e*((t+1)*e-t)},easeOutBack(e){const t=1.70158;return(e-=1)*e*((t+1)*e+t)+1},easeInOutBack(e){let t=1.70158;return(e/=.5)<1?e*e*((1+(t*=1.525))*e-t)*.5:.5*((e-=2)*e*((1+(t*=1.525))*e+t)+2)},easeInBounce:e=>1-n.easeOutBounce(1-e),easeOutBounce:e=>e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375,easeInOutBounce:e=>e<.5?.5*n.easeInBounce(2*e):.5*n.easeOutBounce(2*e-1)+.5},a={scale:(e,t,n)=>{e.transform=`scale(${n?1-t:t})`},opacity:(e,t,n)=>{e.opacity=n?1-t:t}};function s(e,t,s,o,i,r){let c;const u="string"==typeof r?a[r]||a.scale:r,p=performance.now(),l=()=>{if(c)return;const a=performance.now()-p,r=0===s?1:Math.min(a/s,1),h=n[t](r);u(e,h,o),r<1?requestAnimationFrame(l):i&&i()};return l(),()=>{c=!0}}function o(e,...t){for(const n of t)for(const t in n)"object"==typeof n[t]?(e[t]||(e[t]={}),o(e[t],n[t])):e[t]=n[t];return e}function i(e){for(const t of e.values()){const e=t.match(/mapboxgl-popup-anchor-(.+)/);if(e)return e[1].replace("-"," ")}}const r={openingAnimation:{transform:"scale",duration:1e3,easing:"easeOutElastic"},closingAnimation:{transform:"scale",duration:300,easing:"easeInBack"}};return class extends e.Popup{constructor(e){super(e),o(this.options,o({},r,e))}addTo(...e){return this._map&&this._remove(),super.addTo(...e)}_remove(){const e=this._wrapperContainer;this._cancelAnimation&&this._cancelAnimation(),e&&e.parentNode&&(e.parentNode.removeChild(e),delete this._wrapperContainer),super.remove()}remove(){if(this._wrapperContainer){const{easing:e,duration:t,transform:n}=this.options.closingAnimation;this._cancelAnimation&&this._cancelAnimation(),this._cancelAnimation=s(this._container.style,e,t,!0,(()=>{this._remove()}),n)}else super.remove();return this}_update(...e){if(!this._map||!(this._lngLat||this._trackPointer)||!this._content)return;const n=this._map._requestDomTask;let a,o=this._wrapperContainer,r=this._container;Object.defineProperty(this,"_container",{configurable:!0,get:()=>r,set:e=>{const{easing:t,duration:n,transform:a}=this.options.openingAnimation;o=this._wrapperContainer=document.createElement("div"),o.className="mapboxgl-popup-wrapper",o.style.position="absolute",o.style.willChange="transform",o.style.pointerEvents="none",r=e,r.style.position="relative",this._map.getContainer().appendChild(o),o.appendChild(r),this._cancelAnimation=s(r.style,t,n,!1,null,a)}}),t[0]>=2&&t[1]>=3||t[0]>=3?this._map._requestDomTask=e=>{n.call(this._map,(()=>{a=r?r.style.transform:"scale(0)",e(),o.style.transform=r.style.transform,r.style.transform=a,r.style.transformOrigin=this._anchor?this._anchor.replace("-"," "):i(r.classList)}))}:a=r?r.style.transform:"scale(0)",super._update(...e),delete this._container,this._container=r,t[0]>=2&&t[1]>=3||t[0]>=3?this._map._requestDomTask=n:(o.style.transform=r.style.transform,r.style.transform=a,r.style.transformOrigin=i(r.classList))}}}));
//# sourceMappingURL=mapbox-gl-animated-popup.min.js.map
