@archilogic/floor-plan-sdk 5.1.10 → 5.1.12
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.
- package/dist/fpe.d.ts +1 -1
- package/dist/fpe.js +1095 -915
- package/dist/fpe.umd.cjs +3 -3
- package/package.json +1 -1
package/dist/fpe.umd.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FloorPlanSdk={})}(this,(function(t){"use strict";var e=Object.defineProperty,i=(t,i,s)=>((t,i,s)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s)(t,"symbol"!=typeof i?i+"":i,s)
|
|
2
2
|
/*!
|
|
3
|
-
Archilogic Floor Plan Engine SDK v5.1.
|
|
3
|
+
Archilogic Floor Plan Engine SDK v5.1.12 webgl build 251008-143854-d58f25
|
|
4
4
|
|
|
5
5
|
Copyright (c) 2025 Archilogic AG. All rights reserved.
|
|
6
6
|
|
|
7
7
|
License: According to your license agreement with Archilogic AG
|
|
8
|
-
*/;const s=3.28084,r=(t,e=1/64)=>{const i=1/e;return Math.round(t*i)/i};function n(t){return Math.sign(t)*Math.floor(Math.abs(t))}function o(t,e){return typeof t<"u"&&null!==t&&Number.isFinite(t)&&t>=-e&&t<=e}const a=" ",l="m",h="′",u="″",c="m²",d="ft²";function p(t,e=.5,i=1/64){return!(t%e)||e<=i?[t/e,1/e]:p(t,e/2)}const f=(t=0,e="metric",i=3)=>{if("imperial"===e){const{feet:e,inches:i,fraction:o,isNegative:l}=function(t){const e=t*s,i=Math.abs(e),o=r(i%1*12);return{feet:n(i),inches:n(o),fraction:r(o%1),isNegative:Math.sign(t)<0}}(t);let c="";if(o>0){const[t,e]=p(r(o));c=`${a}${t}/${e}`}return`${l?"-":""}${e}${h}${a}${i}${c}${u}`}const o=Math.pow(10,i);return`${Math.round(t*o)/o}${a}${l}`},m=(t=0,e="metric",i=0,r=!0)=>{let n="",o="";const l=Math.pow(10,i);if("imperial"===e){const e=function(t){return t*s*s}(t);n=""+Math.round(e*l)/l,o=`${a}${d}`}else n=""+Math.round(t*l)/l,o=`${a}${c}`;return r&&(n+=o),n};["US","USA","United States","U.S","U.S.A","England","UK","U.K","United Kingdom","Liberia","Myanmar"].map((t=>t.toLowerCase()));const g=(t,e)=>{const i=`.${e}`;return(t=>t.replace(/[/\\]/g,"_"))((t=>t.replace(/[.,\s]/g,"_"))(t.endsWith(i)?t.split(i)[0]:t))+i};function y(t){const e=function(t){return"#"===t.slice(0,1)&&(t=t.slice(1)),t}(t);return 3===e.length?`#${e.split("").map((t=>t+t)).join("")}`:t}function v(t){return t>=0&&t<=255}function x(t){const e=y(t),i={r:parseInt(e.substring(1,3),16),g:parseInt(e.substring(3,5),16),b:parseInt(e.substring(5,7),16)};if(function({r:t,g:e,b:i}){return v(t)&&v(e)&&v(i)}(i))return i;throw"invalid hex color input"}function b(t){return JSON.parse(JSON.stringify(t))}function _(...t){let e={};for(const i of t)if(i instanceof Array)e instanceof Array||(e=[]),e=[...e,...i];else if(i instanceof Object)for(const t of Object.entries(i)){const i=t[0];let s=t[1];s instanceof Object&&i in e&&(s=_(e[i],s)),e={...e,[i]:s}}return e}function w(){return typeof window<"u"&&typeof navigator<"u"&&typeof document<"u"}!w()||window.self===window.top||window.location.ancestorOrigins&&window.location.ancestorOrigins[0]||document.referrer,w()&&navigator.platform.toUpperCase().indexOf("MAC");const P=["info","warnings","errors"];class E{constructor(t){this.levels=P.slice(),this.info=this.log,t&&this.setLevels(t),this.levelStack=[]}setLevels(t){const e=this.levels.slice();if("string"==typeof t)switch(t){case"none":this.levels=[];break;case"all":this.levels=["debug","info","warnings","errors"];break;case"debug":this.levels=["debug"];break;case"info":this.levels=["info"];break;case"warnings":this.levels=["warnings"];break;case"errors":this.levels=["errors"];break;default:console.error(`Unknown setting '${t}'.`)}else this.levels=t.slice();return e}push(){this.levelStack.push(this.levels)}pushAndSetLevels(t){return this.push(),this.setLevels(t)}pop(){if(this.levelStack.length>0){const t=this.levelStack.pop();this.setLevels(t)}}debug(...t){this.levels.includes("debug")&&console.debug(...t)}log(...t){this.levels.includes("info")&&console.log(...t)}warn(...t){this.levels.includes("warnings")&&console.warn(...t)}error(...t){this.levels.includes("errors")&&console.error(...t)}}for(var T,A=[],I=0;I<256;++I)A.push((I+256).toString(16).slice(1));var S=new Uint8Array(16);function C(){if(!T&&!(T="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return T(S)}const M={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function O(t,e,i){if(M.randomUUID&&!e&&!t)return M.randomUUID();var s=(t=t||{}).random||(t.rng||C)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,function(t,e=0){return(A[t[e+0]]+A[t[e+1]]+A[t[e+2]]+A[t[e+3]]+"-"+A[t[e+4]]+A[t[e+5]]+"-"+A[t[e+6]]+A[t[e+7]]+"-"+A[t[e+8]]+A[t[e+9]]+"-"+A[t[e+10]]+A[t[e+11]]+A[t[e+12]]+A[t[e+13]]+A[t[e+14]]+A[t[e+15]]).toLowerCase()}(s)}const N=t=>{const e=[];for(const[i,s]of Object.entries(t))void 0!==s&&e.push(`${i}=${String(s)}`);return e.length?`?${e.join("&")}`:""};class L extends Error{constructor(t,e,s){super(t||"There was a problem. Please check your internet connection and try again."),i(this,"code"),i(this,"data"),this.name="SpaceApiError",this.stack=(new Error).stack,this.code=e,this.data=s}}let R="https://api.archilogic.com";function k(t){let e;if(t.secretAccessToken)e={type:"secret",secretAccessToken:t.secretAccessToken};else if(t.temporaryAccessToken||t.temporaryAccessTokenFunction)e={type:"temporary",temporaryAccessToken:t.temporaryAccessToken};else{if(!t.publishableAccessToken)throw new L("Programming error: token is not provided.",void 0,void 0);e={type:"publishable",publishableAccessToken:t.publishableAccessToken}}return t.sdkVersion&&(e.sdkVersion=t.sdkVersion),e}function B(t){return t.status>=200&&t.status<400?t:t.json().then((e=>{const i=(null==e?void 0:e.message)||(null==e?void 0:e.error)||e;switch(typeof i){case"string":return Promise.reject(new L(i,t.status,void 0));case"object":return Promise.reject(new L(i.message,t.status,i.data));default:return Promise.reject(new L(null,null,e))}}))}async function F(t,e,i={},s){const r=new URL(R+e),n=function(t){var e;const i=new Headers;switch(t.type){case"secret":i.set("authorization",`AL-Secret-Token ${t.secretAccessToken}`);break;case"temporary":i.set("authorization",`${null==(e=t.temporaryAccessToken)?void 0:e.authorization}`)}return t.sdkVersion&&i.set("x-sdk-version",t.sdkVersion),i}(s);let o=!1;switch("publishable"===s.type&&r.searchParams.set("pubtoken",s.publishableAccessToken),t){case"GET":i&&"object"==typeof i&&Object.entries(i).forEach((([t,e])=>{void 0!==e&&r.searchParams.set(t,e.toString())}));break;case"POST":case"PUT":case"PATCH":n.set("content-type","application/json"),o=!0;break;case"DELETE":break;default:return Promise.reject(new L("Programming error, unsupported method: "+t,void 0,void 0))}return fetch(r.toString(),{method:t,headers:n,body:o?JSON.stringify(i):void 0}).then(B,(t=>{throw t})).then((t=>t.json())).catch((t=>Promise.reject(t)))}class D{constructor(t){i(this,"config"),i(this,"temporaryAccessTokenFunction"),i(this,"tempScopes",[{resource:"floor",action:"readPublic"},{resource:"floor",action:"readPrivate"},{resource:"floor",action:"queryPublic"},{resource:"floor",action:"queryPrivate"},{resource:"floor",action:"archive"},{resource:"customFields",action:"readPublic"},{resource:"customFields",action:"readPrivate"},{resource:"customFields",action:"write"}]),i(this,"temporaryAccessToken"),i(this,"temporaryAccessTokenPromise"),i(this,"durationSeconds",3600),this.config=k(t),(t.temporaryAccessToken||t.temporaryAccessTokenFunction)&&(this.temporaryAccessTokenFunction=t.temporaryAccessTokenFunction,this.temporaryAccessToken=t.temporaryAccessToken),t.temporaryAccessTokenScopes&&(this.tempScopes=t.temporaryAccessTokenScopes)}get isAccessTokenActive(){const t=(new Date).getTime()/1e3;return!!this.temporaryAccessToken&&this.temporaryAccessToken.expiresAt>t}async getTemporaryAccessToken(){if(this.isAccessTokenActive&&this.temporaryAccessToken)return this.temporaryAccessToken;this.temporaryAccessTokenPromise||(this.temporaryAccessTokenPromise=new Promise((async(t,e)=>{if(this.temporaryAccessTokenFunction&&(this.temporaryAccessToken=await this.temporaryAccessTokenFunction({scopes:this.tempScopes,durationSeconds:this.durationSeconds}),this.isAccessTokenActive&&t(this.temporaryAccessToken)),this.temporaryAccessToken){const t=new Date;t.setTime(1e3*this.temporaryAccessToken.expiresAt),e(new L(`Temporary access token expired at ${t.toString()}`,void 0,void 0))}else e(new L("Temporary access token not defined",void 0,void 0))})));try{return await this.temporaryAccessTokenPromise}catch(t){throw this.temporaryAccessTokenPromise=void 0,t}finally{this.isAccessTokenActive&&(this.temporaryAccessTokenPromise=void 0)}}async callSpaceAPI(t,e,i={},s=this.config){switch(s.type){case"secret":case"publishable":return F(t,e,i,s);case"temporary":{const r=await this.getTemporaryAccessToken();return F(t,e,i,{...s,temporaryAccessToken:r})}}}}class U{constructor(t,e={}){i(this,"connection"),this.connection=new D(t);for(const[i,s]of Object.entries(e))this[i]=s}async getTemporaryAccessToken(){return this.connection.getTemporaryAccessToken()}async createFloor(t){return this.connection.callSpaceAPI("POST","/v2/floor",t)}async duplicateFloor(t,e){const i=e.revisionId?`?revisionId=${e.revisionId}`:"";return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/duplicate${i}`)}async updateFloor(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/floor/${t}`,e)}async archiveFloor(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/archive`)}async unarchiveFloor(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/unarchive`)}async searchFloorsBasic(t){const{name:e,id:i,paginationInput:s,teamId:r}=t,n=((t,e,i,s)=>{const r={};return t&&(r.name={contains:`${t}`}),e&&(r.ids=[e]),s&&(r.team={id:{eq:s}}),{query:"query ($floorFilter: FloorFilter!, $paginationInput: PaginationInput) { getFloors(where: $floorFilter, paginationInput: $paginationInput) { floors { id name area createdAt updatedAt labels { name color } }, paginationInfo { currentPage limit offset totalCount totalPageCount} } }",variables:{floorFilter:r,paginationInput:i}}})(e,i,s,r);return this.connection.callSpaceAPI("POST","/graphql",n)}async searchFloorsAdvanced(t,e){const i=((t,e)=>({query:t,variables:{paginationInput:e}}))(t,e);return this.connection.callSpaceAPI("POST","/graphql",i)}async getFloorById(t,e=!1,i=!0,s=!1,r,n=!1){var o;const a=N({includeAddress:s,includeRelations:i,includeCustomAttributes:n}),l=await this.connection.callSpaceAPI("GET",`/v2/floor/${t}${e?"/geo-json":""}${a}`);let h={};if(null==(o=l.properties)?void 0:o.defaultLayoutId){const{layout:t,id:e,lastRevision:i,categories:s}=await this.getLayout(l.properties.defaultLayoutId,r);h={layout:{id:e,layout:t,lastRevision:i,categories:s}}}return{...l,...h}}async getFloorGeoJson(t,e){const i=N(e??{}),s=await this.connection.callSpaceAPI("GET",`/v2/floor/${t}/geo-json${i}`);let r;if(null==e?void 0:e.includeAllElements){const t=s.features.find((t=>"Floor"===t.properties.resourceType));r=null==t?void 0:t.properties.defaultLayoutId}else{r=s.properties.defaultLayoutId}if(r){const{layout:t,id:e,lastRevision:i,categories:n}=await this.getLayout(r);return{...s,layout:{id:e,layout:t,lastRevision:i,categories:n}}}return s}getFloorStatistics(t){return this.connection.callSpaceAPI("GET",`/v2/floor/${t}/statistics`)}queryFloors(t){return this.connection.callSpaceAPI("GET","/v2/floor",t)}async getAllFloors(t=!1,e=!1,i=!1,s,r){const n=t||i?1e3:1e4,o=await this.queryFloors({geometry:t,includeArchived:e,includeRelations:i,includeCustomAttributes:r,teamId:s,limit:n});let a=o.features||[];if(a.length<n)return o;for(;null==a?void 0:a.length;)a=(await this.queryFloors({geometry:t,includeArchived:e,includeRelations:i,includeCustomAttributes:r,teamId:s,offset:o.features.length,limit:n})).features||[],o.features.push(...a);return o}getFloorplanImage(t,e){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/2d-image`,e)}getSceneStructure(t,e=!1){return this.connection.callSpaceAPI("GET",`/v2/floor/${t}/scene-structure`,{includeMetadata:e})}assignLabel(t,e){return this.connection.callSpaceAPI("PUT",`/v2/floor/${t}/label/${e}`)}removeLabel(t,e){return this.connection.callSpaceAPI("DELETE",`/v2/floor/${t}/label/${e}`)}getSpaceById(t,e=!1,i=!0){const s=`?includeRelations=${i}`;return this.connection.callSpaceAPI("GET",`/v2/space/${t}/${e?"geo-json":""}${s}`)}querySpaces(t){return this.connection.callSpaceAPI("GET","/v2/space",t)}async getAllSpacesByFloorId(t,e=!1,i,s){const r=1e3,n=await this.querySpaces({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s,limit:r});let o=n.features||[];if(o.length<r)return n;for(;null==o?void 0:o.length;)o=(await this.querySpaces({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s,offset:n.features.length,limit:r})).features||[],n.features.push(...o);return n}getAssetById(t,e=!1,i=!0,s=!1){const r=N({includeRelations:i,includeCustomAttributes:s});return this.connection.callSpaceAPI("GET",`/v2/asset/${t}/${e?"geo-json":""}${r}`)}queryAssets(t){return this.connection.callSpaceAPI("GET","/v2/asset",t)}async getAllAssets(t){const{limit:e=1e4,...i}=t,s=await this.queryAssets({...i,limit:e});let r=s.features||[];if(r.length<e)return s;for(;null==r?void 0:r.length;)r=(await this.queryAssets({...t,offset:(t.offset||0)+s.features.length,limit:e})).features||[],s.features.push(...r);return s}getAllAssetsByFloorId(t,e=!1,i,s){return this.getAllAssets({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s})}getAllAssetsBySpaceId(t,e=!1,i,s){return this.getAllAssets({spaceId:t,geometry:e,includeRelations:i,includeCustomAttributes:s})}getCustomField(t,e,i){return this.connection.callSpaceAPI("GET",`/v2/${t}/${e}/custom-field/${i}`)}getAllCustomFields(t,e){return this.connection.callSpaceAPI("GET",`/v2/${t}/${e}/custom-field`)}setCustomField(t,e,i,s){return this.connection.callSpaceAPI("PUT",`/v2/${t}/${e}/custom-field/${i}`,s)}deleteCustomField(t,e,i){return this.connection.callSpaceAPI("DELETE",`/v2/${t}/${e}/custom-field/${i}`)}getLabel(t){return this.connection.callSpaceAPI("GET",`/v2/label/${t}`)}listLabels(){return this.connection.callSpaceAPI("GET","/v2/label/")}createOrUpdateLabel(t,e){return this.connection.callSpaceAPI("PUT",`/v2/label/${t}`,e)}deleteLabel(t){return this.connection.callSpaceAPI("DELETE",`/v2/label/${t}`)}getCustomAttributes(){return this.connection.callSpaceAPI("GET","/v2/custom-attributes")}getCustomAttribute(t,e){return this.connection.callSpaceAPI("GET",`/v2/${t.toLowerCase()}/custom-attributes/${e}`)}getCustomAttributesForResourceType(t){return this.connection.callSpaceAPI("GET",`/v2/${t.toLowerCase()}/custom-attributes`)}createCustomAttribute(t){const{resourceType:e,...i}=t;return this.connection.callSpaceAPI("POST",`/v2/${e.toLowerCase()}/custom-attributes`,i)}updateCustomAttribute(t){const{apiFieldName:e,resourceType:i,...s}=t;return this.connection.callSpaceAPI("PATCH",`/v2/${i.toLowerCase()}/custom-attributes/${e}`,s)}deleteCustomAttribute(t,e){return this.connection.callSpaceAPI("DELETE",`/v2/${t.toLowerCase()}/custom-attributes/${e}`)}getCustomAttributeValues(t,e){return this.connection.callSpaceAPI("GET",`/v2/${t.toLowerCase()}/${e}/custom-attributes`)}createCustomAttributeValue(t){const{apiFieldName:e,resourceId:i,resourceType:s,...r}=t;return this.connection.callSpaceAPI("POST",`/v2/${s.toLowerCase()}/${i}/custom-attributes/${e}`,r)}updateCustomAttributeValue(t){const{apiFieldName:e,resourceId:i,resourceType:s,...r}=t;return this.connection.callSpaceAPI("PATCH",`/v2/${s.toLowerCase()}/${i}/custom-attributes/${e}`,r)}deleteCustomAttributeValue(t,e,i){return this.connection.callSpaceAPI("DELETE",`/v2/${e.toLowerCase()}/${t}/custom-attributes/${i}`)}createLayout(t,e,i){return this.connection.callSpaceAPI("POST","/v2/layout",{floorId:t,layout:e,isDefault:i})}duplicateLayout(t,e){const i=N({revisionId:e});return this.connection.callSpaceAPI("POST",`/v2/layout/${t}/duplicate${i}`,{layoutId:t,revisionId:e})}getLayout(t,e){const i=N(e?{filter:e}:{});return this.connection.callSpaceAPI("GET",`/v2/layout/${t}${i}`)}getLayouts(t,e){const i=N({floorId:t,isDefault:e});return this.connection.callSpaceAPI("GET",`/v2/layout/${i}`)}updateLayout(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/layout/${t}`,e)}deleteLayout(t){return this.connection.callSpaceAPI("DELETE",`/v2/layout/${t}`)}createLayoutRevision(t,e){return this.connection.callSpaceAPI("POST",`/v2/layout/${t}/revisions`,{layout:e})}updateLayoutRevision(t,e,i){return this.connection.callSpaceAPI("PATCH",`/v2/layout/${t}/revisions/${e}`,i)}getLayoutRevisions(t,e){const i=N(e?{filter:e}:{});return this.connection.callSpaceAPI("GET",`/v2/layout/${t}/revisions${i}`)}getLayoutRevision(t,e){return this.connection.callSpaceAPI("GET",`/v2/layout/${t}/revisions/${e}`)}convertLanguageToQuery(t){return this.connection.callSpaceAPI("POST","/v2/language/graphql",t)}getDxf(t){return this.connection.callSpaceAPI("GET",`/v2/floor/${t}/dxf`)}getIfc(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/ifc`)}getGltf(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/gltf`)}getImdf(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/imdf`)}getImdfs(t){return this.connection.callSpaceAPI("POST","/v2/floor/imdf",t)}listExtensions(){return this.connection.callSpaceAPI("GET","/v2/extensions")}createExtension(t){return this.connection.callSpaceAPI("POST","/v2/extensions",t)}updateExtension(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/extensions/${t}`,e)}deleteExtension(t){return this.connection.callSpaceAPI("DELETE",`/v2/extensions/${t}`)}listBuildings(){return this.connection.callSpaceAPI("GET","/v2/buildings")}createBuilding(t){return this.connection.callSpaceAPI("POST","/v2/buildings",t)}getBuildingById(t){return this.connection.callSpaceAPI("GET",`/v2/buildings/${t}`)}updateBuilding(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/buildings/${t}`,e)}deleteBuilding(t){return this.connection.callSpaceAPI("DELETE",`/v2/buildings/${t}`)}}var G,X=Object.defineProperty,W=(t,e,i)=>((t,e,i)=>e in t?X(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i)(t,"symbol"!=typeof e?e+"":e,i);(t=>{t.version="6.4.2.2",t.use_lines=!0;class e{constructor(){W(this,"m_Parent",null),W(this,"m_polygon",[]),W(this,"m_Index",0),W(this,"m_jointype",0),W(this,"m_endtype",0),W(this,"m_Children",[]),W(this,"IsOpen",!1)}IsHoleNode(){for(var t=!0,e=this.m_Parent;null!==e;)t=!t,e=e.m_Parent;return t}ChildCount(){return this.m_Children.length}Contour(){return this.m_polygon}AddChild(t){var e=this.m_Children.length;this.m_Children.push(t),t.m_Parent=this,t.m_Index=e}GetNext(){return this.m_Children.length>0?this.m_Children[0]:this.GetNextSiblingUp()}GetNextSiblingUp(){return null===this.m_Parent?null:this.m_Index===this.m_Parent.m_Children.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Children[this.m_Index+1]}Children(){return this.m_Children}Parent(){return this.m_Parent}IsHole(){return this.IsHoleNode()}}t.PolyNode=e;t.PolyTree=class extends e{constructor(){super(),W(this,"m_AllPolys",[])}Clear(){for(var t=0,e=this.m_AllPolys.length;t<e;t++)this.m_AllPolys[t]=null;this.m_AllPolys.length=0,this.m_Children.length=0}GetFirst(){return this.m_Children.length>0?this.m_Children[0]:null}Total(){var t=this.m_AllPolys.length;return t>0&&this.m_Children[0]!==this.m_AllPolys[0]&&t--,t}},t.Clear=function(t){t.length=0},t.PI=3.141592653589793,t.PI2=6.283185307179586;t.FPoint=class{constructor(...e){W(this,"X",0),W(this,"Y",0);var i=e,s=e.length;if(this.X=0,this.Y=0,2===s)this.X=i[0],this.Y=i[1];else if(1===s)if(i[0]instanceof t.FPoint){var r=i[0];this.X=r.X,this.Y=r.Y}else{var n=i[0];this.X=n.X,this.Y=n.Y}else this.X=0,this.Y=0}static op_Equality(t,e){return t.X===e.X&&t.Y===e.Y}static op_Inequality(t,e){return t.X!==e.X||t.Y!==e.Y}};var i,s,r,n,o,a,l,h;t.FRect=class{constructor(...t){W(this,"left"),W(this,"top"),W(this,"right"),W(this,"bottom");var e=t,i=t.length;if(4===i)this.left=e[0],this.top=e[1],this.right=e[2],this.bottom=e[3];else if(1===i){var s=e[0];this.left=s.left,this.top=s.top,this.right=s.right,this.bottom=s.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0}},(i=t.ClipType||(t.ClipType={}))[i.ctIntersection=0]="ctIntersection",i[i.ctUnion=1]="ctUnion",i[i.ctDifference=2]="ctDifference",i[i.ctXor=3]="ctXor",(s=t.PolyType||(t.PolyType={}))[s.ptSubject=0]="ptSubject",s[s.ptClip=1]="ptClip",(r=t.PolyFillType||(t.PolyFillType={}))[r.pftEvenOdd=0]="pftEvenOdd",r[r.pftNonZero=1]="pftNonZero",r[r.pftPositive=2]="pftPositive",r[r.pftNegative=3]="pftNegative",(n=t.JoinType||(t.JoinType={}))[n.jtSquare=0]="jtSquare",n[n.jtRound=1]="jtRound",n[n.jtMiter=2]="jtMiter",(o=t.EndType||(t.EndType={}))[o.etOpenSquare=0]="etOpenSquare",o[o.etOpenRound=1]="etOpenRound",o[o.etOpenButt=2]="etOpenButt",o[o.etClosedLine=3]="etClosedLine",o[o.etClosedPolygon=4]="etClosedPolygon",(a=t.EdgeSide||(t.EdgeSide={}))[a.esLeft=0]="esLeft",a[a.esRight=1]="esRight",(l=t.Direction||(t.Direction={}))[l.dRightToLeft=0]="dRightToLeft",l[l.dLeftToRight=1]="dLeftToRight",(h=t.NodeType||(t.NodeType={}))[h.ntAny=0]="ntAny",h[h.ntOpen=1]="ntOpen",h[h.ntClosed=2]="ntClosed";t.TEdge=class{constructor(){W(this,"Bot",new t.FPoint),W(this,"Curr",new t.FPoint),W(this,"Top",new t.FPoint),W(this,"Delta",new t.FPoint),W(this,"Dx",0),W(this,"PolyTyp",0),W(this,"Side",0),W(this,"WindDelta",0),W(this,"WindCnt",0),W(this,"WindCnt2",0),W(this,"OutIdx",0),W(this,"Next",null),W(this,"Prev",null),W(this,"NextInLML",null),W(this,"NextInAEL",null),W(this,"PrevInAEL",null),W(this,"NextInSEL",null),W(this,"PrevInSEL",null)}};t.IntersectNode=class{constructor(){W(this,"Edge1",null),W(this,"Edge2",null),W(this,"Pt",new t.FPoint)}},t.Compare=function(t,e){var i=e.Pt.Y-t.Pt.Y;return i>0?1:i<0?-1:0};t.LocalMinima=class{constructor(){W(this,"Y",0),W(this,"LeftBound",null),W(this,"RightBound",null),W(this,"Next",null)}};t.Scanbeam=class{constructor(){W(this,"Y",0),W(this,"Next",null)}};t.Maxima=class{constructor(){W(this,"X",0),W(this,"Next",null),W(this,"Prev",null)}};t.OutRec=class{constructor(){W(this,"Idx",0),W(this,"IsHole",!1),W(this,"IsOpen",!1),W(this,"FirstLeft",null),W(this,"Pts",null),W(this,"BottomPt",null),W(this,"PolyNode",null)}};t.OutPt=class{constructor(){W(this,"Idx",0),W(this,"Pt",new t.FPoint),W(this,"Next",null),W(this,"Prev",null)}};t.Join=class{constructor(){W(this,"OutPt1",null),W(this,"OutPt2",null),W(this,"OffPt",new t.FPoint)}};class u{constructor(){W(this,"m_MinimaList",null),W(this,"m_CurrentLM",null),W(this,"m_edges",new Array),W(this,"m_HasOpenPaths",!1),W(this,"PreserveCollinear",!1),W(this,"m_Scanbeam",null),W(this,"m_PolyOuts",null),W(this,"m_ActiveEdges",null)}static near_zero(e){return e>-t.ClipperBase.tolerance&&e<t.ClipperBase.tolerance}static IsHorizontal(t){return 0===t.Delta.Y}PointIsVertex(e,i){var s=i;do{if(t.FPoint.op_Equality(s.Pt,e))return!0;s=s.Next}while(s!==i);return!1}PointOnLineSegment(t,e,i){return t.X===e.X&&t.Y===e.Y||t.X===i.X&&t.Y===i.Y||t.X>e.X==t.X<i.X&&t.Y>e.Y==t.Y<i.Y&&(t.X-e.X)*(i.Y-e.Y)==(i.X-e.X)*(t.Y-e.Y)}PointOnPolygon(t,e){for(var i=e;;){if(this.PointOnLineSegment(t,i.Pt,i.Next.Pt))return!0;if((i=i.Next)===e)break}return!1}static SlopesEqual(){var t,e,i,s,r,n,o=arguments,a=o.length;return 2===a?(e=o[1],(t=o[0]).Delta.Y*e.Delta.X==t.Delta.X*e.Delta.Y):3===a?(s=o[1],r=o[2],((i=o[0]).Y-s.Y)*(s.X-r.X)-(i.X-s.X)*(s.Y-r.Y)==0):(s=o[1],r=o[2],n=o[3],((i=o[0]).Y-s.Y)*(r.X-n.X)-(i.X-s.X)*(r.Y-n.Y)==0)}static SlopesEqual3(t,e){return t.Delta.Y*e.Delta.X==t.Delta.X*e.Delta.Y}static SlopesEqual4(t,e,i){return(t.Y-e.Y)*(e.X-i.X)-(t.X-e.X)*(e.Y-i.Y)==0}static SlopesEqual5(t,e,i,s){return(t.Y-e.Y)*(i.X-s.X)-(t.X-e.X)*(i.Y-s.Y)==0}Clear(){this.DisposeLocalMinimaList();for(var e=0,i=this.m_edges.length;e<i;++e){for(var s=0,r=this.m_edges[e].length;s<r;++s)this.m_edges[e][s]=null;t.Clear(this.m_edges[e])}t.Clear(this.m_edges),this.m_HasOpenPaths=!1}DisposeLocalMinimaList(){for(;null!==this.m_MinimaList;){var t=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=t}this.m_CurrentLM=null}RangeTest(e){(e.X>t.ClipperBase.maxValue||e.X<-t.ClipperBase.maxValue||e.Y>t.ClipperBase.maxValue||e.Y<-t.ClipperBase.maxValue||e.X>0&&e.X<t.ClipperBase.minValue||e.Y>0&&e.Y<t.ClipperBase.minValue||e.X<0&&e.X>-t.ClipperBase.minValue||e.Y<0&&e.Y>-t.ClipperBase.minValue)&&t.Error("Coordinate outside allowed range in RangeTest().")}InitEdge(t,e,i,s){t.Next=e,t.Prev=i,t.Curr.X=s.X,t.Curr.Y=s.Y,t.OutIdx=-1}InitEdge2(t,e){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y),this.SetDx(t),t.PolyTyp=e}FindNextLocMin(e){for(var i;;){for(;t.FPoint.op_Inequality(e.Bot,e.Prev.Bot)||t.FPoint.op_Equality(e.Curr,e.Top);)e=e.Next;if(e.Dx!==t.ClipperBase.horizontal&&e.Prev.Dx!==t.ClipperBase.horizontal)break;for(;e.Prev.Dx===t.ClipperBase.horizontal;)e=e.Prev;for(i=e;e.Dx===t.ClipperBase.horizontal;)e=e.Next;if(e.Top.Y!==e.Prev.Bot.Y){i.Prev.Bot.X<e.Bot.X&&(e=i);break}}return e}ProcessBound(e,i){var s,r,n=e;if(n.OutIdx===t.ClipperBase.Skip){if(e=n,i){for(;e.Top.Y===e.Next.Bot.Y;)e=e.Next;for(;e!==n&&e.Dx===t.ClipperBase.horizontal;)e=e.Prev}else{for(;e.Top.Y===e.Prev.Bot.Y;)e=e.Prev;for(;e!==n&&e.Dx===t.ClipperBase.horizontal;)e=e.Next}if(e===n)n=i?e.Next:e.Prev;else{e=i?n.Next:n.Prev;var o=new t.LocalMinima;o.Next=null,o.Y=e.Bot.Y,o.LeftBound=null,o.RightBound=e,e.WindDelta=0,n=this.ProcessBound(e,i),this.InsertLocalMinima(o)}return n}if(e.Dx===t.ClipperBase.horizontal&&((s=i?e.Prev:e.Next).Dx===t.ClipperBase.horizontal?s.Bot.X!==e.Bot.X&&s.Top.X!==e.Bot.X&&this.ReverseHorizontal(e):s.Bot.X!==e.Bot.X&&this.ReverseHorizontal(e)),s=e,i){for(;n.Top.Y===n.Next.Bot.Y&&n.Next.OutIdx!==t.ClipperBase.Skip;)n=n.Next;if(n.Dx===t.ClipperBase.horizontal&&n.Next.OutIdx!==t.ClipperBase.Skip){for(r=n;r.Prev.Dx===t.ClipperBase.horizontal;)r=r.Prev;r.Prev.Top.X>n.Next.Top.X&&(n=r.Prev)}for(;e!==n;)e.NextInLML=e.Next,e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Prev.Top.X&&this.ReverseHorizontal(e),e=e.Next;e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Prev.Top.X&&this.ReverseHorizontal(e),n=n.Next}else{for(;n.Top.Y===n.Prev.Bot.Y&&n.Prev.OutIdx!==t.ClipperBase.Skip;)n=n.Prev;if(n.Dx===t.ClipperBase.horizontal&&n.Prev.OutIdx!==t.ClipperBase.Skip){for(r=n;r.Next.Dx===t.ClipperBase.horizontal;)r=r.Next;(r.Next.Top.X===n.Prev.Top.X||r.Next.Top.X>n.Prev.Top.X)&&(n=r.Next)}for(;e!==n;)e.NextInLML=e.Prev,e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Next.Top.X&&this.ReverseHorizontal(e),e=e.Prev;e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Next.Top.X&&this.ReverseHorizontal(e),n=n.Prev}return n}AddPath(e,i,s){t.use_lines?s||1!==i||t.Error("AddPath: Open paths must be subject."):s||t.Error("AddPath: Open paths have been disabled.");var r=e.length-1;if(s)for(;r>0&&t.FPoint.op_Equality(e[r],e[0]);)--r;for(;r>0&&t.FPoint.op_Equality(e[r],e[r-1]);)--r;if(s&&r<2||!s&&r<1)return!1;for(var n=new Array,o=0;o<=r;o++)n.push(new t.TEdge);var a=!0;n[1].Curr.X=e[1].X,n[1].Curr.Y=e[1].Y,this.RangeTest(e[0]),this.RangeTest(e[r]),this.InitEdge(n[0],n[1],n[r],e[0]),this.InitEdge(n[r],n[0],n[r-1],e[r]);for(o=r-1;o>=1;--o)this.RangeTest(e[o]),this.InitEdge(n[o],n[o+1],n[o-1],e[o]);for(var l,h=n[0],u=h,c=h;;)if(u.Curr!==u.Next.Curr||!s&&u.Next===h){if(u.Prev===u.Next)break;if(!s||!t.ClipperBase.SlopesEqual4(u.Prev.Curr,u.Curr,u.Next.Curr)||this.PreserveCollinear&&this.Pt2IsBetweenPt1AndPt3(u.Prev.Curr,u.Curr,u.Next.Curr)){if((u=u.Next)===c||!s&&u.Next===h)break}else u===h&&(h=u.Next),c=u=(u=this.RemoveEdge(u)).Prev}else{if(u===u.Next)break;u===h&&(h=u.Next),c=u=this.RemoveEdge(u)}if(!s&&u===u.Next||s&&u.Prev===u.Next)return!1;s||(this.m_HasOpenPaths=!0,h.Prev.OutIdx=t.ClipperBase.Skip),u=h;do{this.InitEdge2(u,i),u=u.Next,a&&u.Curr.Y!==h.Curr.Y&&(a=!1)}while(u!==h);if(a){if(s)return!1;for(u.Prev.OutIdx=t.ClipperBase.Skip,(p=new t.LocalMinima).Next=null,p.Y=u.Bot.Y,p.LeftBound=null,p.RightBound=u,p.RightBound.Side=1,p.RightBound.WindDelta=0;u.Bot.X!==u.Prev.Top.X&&this.ReverseHorizontal(u),u.Next.OutIdx!==t.ClipperBase.Skip;)u.NextInLML=u.Next,u=u.Next;return this.InsertLocalMinima(p),this.m_edges.push(n),!0}this.m_edges.push(n);var d=null;for(t.FPoint.op_Equality(u.Prev.Bot,u.Prev.Top)&&(u=u.Next);(u=this.FindNextLocMin(u))!==d;){var p;null===d&&(d=u),(p=new t.LocalMinima).Next=null,p.Y=u.Bot.Y,u.Dx<u.Prev.Dx?(p.LeftBound=u.Prev,p.RightBound=u,l=!1):(p.LeftBound=u,p.RightBound=u.Prev,l=!0),p.LeftBound.Side=0,p.RightBound.Side=1,s?p.LeftBound.Next===p.RightBound?p.LeftBound.WindDelta=-1:p.LeftBound.WindDelta=1:p.LeftBound.WindDelta=0,p.RightBound.WindDelta=-p.LeftBound.WindDelta,(u=this.ProcessBound(p.LeftBound,l)).OutIdx===t.ClipperBase.Skip&&(u=this.ProcessBound(u,l));var f=this.ProcessBound(p.RightBound,!l);f.OutIdx===t.ClipperBase.Skip&&(f=this.ProcessBound(f,!l)),p.LeftBound.OutIdx===t.ClipperBase.Skip?p.LeftBound=null:p.RightBound.OutIdx===t.ClipperBase.Skip&&(p.RightBound=null),this.InsertLocalMinima(p),l||(u=f)}return!0}AddPaths(t,e,i){for(var s=!1,r=0,n=t.length;r<n;++r)this.AddPath(t[r],e,i)&&(s=!0);return s}Pt2IsBetweenPt1AndPt3(e,i,s){return!(t.FPoint.op_Equality(e,s)||t.FPoint.op_Equality(e,i)||t.FPoint.op_Equality(s,i))&&(e.X!==s.X?i.X>e.X==i.X<s.X:i.Y>e.Y==i.Y<s.Y)}RemoveEdge(t){t.Prev.Next=t.Next,t.Next.Prev=t.Prev;var e=t.Next;return t.Prev=null,e}SetDx(e){e.Delta.X=e.Top.X-e.Bot.X,e.Delta.Y=e.Top.Y-e.Bot.Y,0===e.Delta.Y?e.Dx=t.ClipperBase.horizontal:e.Dx=e.Delta.X/e.Delta.Y}InsertLocalMinima(t){if(null===this.m_MinimaList)this.m_MinimaList=t;else if(t.Y>=this.m_MinimaList.Y)t.Next=this.m_MinimaList,this.m_MinimaList=t;else{for(var e=this.m_MinimaList;null!==e.Next&&t.Y<e.Next.Y;)e=e.Next;t.Next=e.Next,e.Next=t}}PopLocalMinima(t,e){return e.v=this.m_CurrentLM,null!==this.m_CurrentLM&&this.m_CurrentLM.Y===t&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)}ReverseHorizontal(t){var e=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=e}Reset(){if(this.m_CurrentLM=this.m_MinimaList,null!==this.m_CurrentLM){this.m_Scanbeam=null;for(var e=this.m_MinimaList;null!==e;){this.InsertScanbeam(e.Y);var i=e.LeftBound;null!==i&&(i.Curr.X=i.Bot.X,i.Curr.Y=i.Bot.Y,i.OutIdx=t.ClipperBase.Unassigned),null!==(i=e.RightBound)&&(i.Curr.X=i.Bot.X,i.Curr.Y=i.Bot.Y,i.OutIdx=t.ClipperBase.Unassigned),e=e.Next}this.m_ActiveEdges=null}}InsertScanbeam(e){if(null===this.m_Scanbeam)this.m_Scanbeam=new t.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=e;else if(e>this.m_Scanbeam.Y){var i=new t.Scanbeam;i.Y=e,i.Next=this.m_Scanbeam,this.m_Scanbeam=i}else{for(var s=this.m_Scanbeam;null!==s.Next&&e<=s.Next.Y;)s=s.Next;if(e===s.Y)return;var r=new t.Scanbeam;r.Y=e,r.Next=s.Next,s.Next=r}}PopScanbeam(t){return null===this.m_Scanbeam?(t.v=0,!1):(t.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)}LocalMinimaPending(){return null!==this.m_CurrentLM}CreateOutRec(){var e=new t.OutRec;return e.Idx=t.ClipperBase.Unassigned,e.IsHole=!1,e.IsOpen=!1,e.FirstLeft=null,e.Pts=null,e.BottomPt=null,e.PolyNode=null,this.m_PolyOuts.push(e),e.Idx=this.m_PolyOuts.length-1,e}DisposeOutRec(t){var e=this.m_PolyOuts[t];e.Pts=null,e=null,this.m_PolyOuts[t]=null}UpdateEdgeIntoAEL(e){null===e.NextInLML&&t.Error("UpdateEdgeIntoAEL: invalid call");var i=e.PrevInAEL,s=e.NextInAEL;return e.NextInLML.OutIdx=e.OutIdx,null!==i?i.NextInAEL=e.NextInLML:this.m_ActiveEdges=e.NextInLML,null!==s&&(s.PrevInAEL=e.NextInLML),e.NextInLML.Side=e.Side,e.NextInLML.WindDelta=e.WindDelta,e.NextInLML.WindCnt=e.WindCnt,e.NextInLML.WindCnt2=e.WindCnt2,(e=e.NextInLML).Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,e.PrevInAEL=i,e.NextInAEL=s,t.ClipperBase.IsHorizontal(e)||this.InsertScanbeam(e.Top.Y),e}SwapPositionsInAEL(t,e){if(t.NextInAEL!==t.PrevInAEL&&e.NextInAEL!==e.PrevInAEL){if(t.NextInAEL===e){var i=e.NextInAEL;null!==i&&(i.PrevInAEL=t);var s=t.PrevInAEL;null!==s&&(s.NextInAEL=e),e.PrevInAEL=s,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=i}else if(e.NextInAEL===t){var r=t.NextInAEL;null!==r&&(r.PrevInAEL=e);var n=e.PrevInAEL;null!==n&&(n.NextInAEL=t),t.PrevInAEL=n,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=r}else{var o=t.NextInAEL,a=t.PrevInAEL;t.NextInAEL=e.NextInAEL,null!==t.NextInAEL&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=e.PrevInAEL,null!==t.PrevInAEL&&(t.PrevInAEL.NextInAEL=t),e.NextInAEL=o,null!==e.NextInAEL&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=a,null!==e.PrevInAEL&&(e.PrevInAEL.NextInAEL=e)}null===t.PrevInAEL?this.m_ActiveEdges=t:null===e.PrevInAEL&&(this.m_ActiveEdges=e)}}DeleteFromAEL(t){var e=t.PrevInAEL,i=t.NextInAEL;null===e&&null===i&&t!==this.m_ActiveEdges||(null!==e?e.NextInAEL=i:this.m_ActiveEdges=i,null!==i&&(i.PrevInAEL=e),t.NextInAEL=null,t.PrevInAEL=null)}}W(u,"horizontal",-34e37),W(u,"Skip",-2),W(u,"Unassigned",-1),W(u,"tolerance",1e-20),W(u,"maxValue",Math.sqrt(Number.MAX_VALUE)),W(u,"minValue",Math.sqrt(Number.MIN_VALUE)),t.ClipperBase=u;class c extends u{constructor(e){super(),W(this,"m_SortedEdges",null),W(this,"m_IntersectList",null),W(this,"m_IntersectNodeComparer",null),W(this,"m_ExecuteLocked",!1),W(this,"m_ClipFillType",0),W(this,"m_SubjFillType",0),W(this,"m_Joins",null),W(this,"m_GhostJoins",null),W(this,"m_UsingPolyTree",!1),W(this,"ReverseSolution",!1),W(this,"StrictlySimple",!1),W(this,"m_ClipType",0),W(this,"m_Maxima",null),W(this,"ZFillFunction"),void 0===e&&(e=0),this.m_PolyOuts=null,this.m_Scanbeam=null,this.m_ActiveEdges=null,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=new Array,this.m_IntersectNodeComparer=t.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=new Array,this.m_Joins=new Array,this.m_GhostJoins=new Array,this.ReverseSolution=!!(1&e),this.StrictlySimple=!!(2&e),this.PreserveCollinear=!!(4&e)}Clear(){0!==this.m_edges.length&&(this.DisposeAllPolyPts(),super.Clear())}InsertMaxima(e){var i=new t.Maxima;if(i.X=e,null===this.m_Maxima)this.m_Maxima=i,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(e<this.m_Maxima.X)i.Next=this.m_Maxima,i.Prev=null,this.m_Maxima=i;else{for(var s=this.m_Maxima;null!==s.Next&&e>=s.Next.X;)s=s.Next;if(e===s.X)return;i.Next=s.Next,i.Prev=s,null!==s.Next&&(s.Next.Prev=i),s.Next=i}}Execute(...e){var i=e,s=i.length,r=i[1]instanceof t.PolyTree;if(4===s&&!r){var n=i[0],o=i[1],a=i[2],l=i[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&t.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,t.Clear(o),this.m_SubjFillType=a,this.m_ClipFillType=l,this.m_ClipType=n,this.m_UsingPolyTree=!1;try{(u=this.ExecuteInternal())&&this.BuildResult(o)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return u}if(4===s&&r){n=i[0];var h=i[1];a=i[2],l=i[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=a,this.m_ClipFillType=l,this.m_ClipType=n,this.m_UsingPolyTree=!0;try{var u;(u=this.ExecuteInternal())&&this.BuildResult2(h)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return u}if(2===s&&!r){n=i[0],o=i[1];return this.Execute(n,o,0,0)}if(2===s&&r){n=i[0],h=i[1];return this.Execute(n,h,0,0)}}FixHoleLinkage(t){if(null!==t.FirstLeft&&(t.IsHole===t.FirstLeft.IsHole||null===t.FirstLeft.Pts)){for(var e=t.FirstLeft;null!==e&&(e.IsHole===t.IsHole||null===e.Pts);)e=e.FirstLeft;t.FirstLeft=e}}ExecuteInternal(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var t,e,i,s={},r={};if(!this.PopScanbeam(s))return!1;for(this.InsertLocalMinimaIntoAEL(s.v);this.PopScanbeam(r)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(r.v))return!1;this.ProcessEdgesAtTopOfScanbeam(r.v),s.v=r.v,this.InsertLocalMinimaIntoAEL(s.v)}for(e=0,i=this.m_PolyOuts.length;e<i;e++)null===(t=this.m_PolyOuts[e]).Pts||t.IsOpen||(t.IsHole^this.ReverseSolution)==this.Area$1(t)>0&&this.ReversePolyPtLinks(t.Pts);for(this.JoinCommonEdges(),e=0,i=this.m_PolyOuts.length;e<i;e++)null!==(t=this.m_PolyOuts[e]).Pts&&(t.IsOpen?this.FixupOutPolyline(t):this.FixupOutPolygon(t));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}}DisposeAllPolyPts(){for(var e=0,i=this.m_PolyOuts.length;e<i;++e)this.DisposeOutRec(e);t.Clear(this.m_PolyOuts)}AddJoin(e,i,s){var r=new t.Join;r.OutPt1=e,r.OutPt2=i,r.OffPt.X=s.X,r.OffPt.Y=s.Y,this.m_Joins.push(r)}AddGhostJoin(e,i){var s=new t.Join;s.OutPt1=e,s.OffPt.X=i.X,s.OffPt.Y=i.Y,this.m_GhostJoins.push(s)}InsertLocalMinimaIntoAEL(e){for(var i,s,r={};this.PopLocalMinima(e,r);){i=r.v.LeftBound,s=r.v.RightBound;var n=null;if(null===i?(this.InsertEdgeIntoAEL(s,null),this.SetWindingCount(s),this.IsContributing(s)&&(n=this.AddOutPt(s,s.Bot))):null===s?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(n=this.AddOutPt(i,i.Bot)),this.InsertScanbeam(i.Top.Y)):(this.InsertEdgeIntoAEL(i,null),this.InsertEdgeIntoAEL(s,i),this.SetWindingCount(i),s.WindCnt=i.WindCnt,s.WindCnt2=i.WindCnt2,this.IsContributing(i)&&(n=this.AddLocalMinPoly(i,s,i.Bot)),this.InsertScanbeam(i.Top.Y)),null!==s&&(t.ClipperBase.IsHorizontal(s)?(null!==s.NextInLML&&this.InsertScanbeam(s.NextInLML.Top.Y),this.AddEdgeToSEL(s)):this.InsertScanbeam(s.Top.Y)),null!==i&&null!==s){if(null!==n&&t.ClipperBase.IsHorizontal(s)&&this.m_GhostJoins.length>0&&0!==s.WindDelta)for(var o=0,a=this.m_GhostJoins.length;o<a;o++){var l=this.m_GhostJoins[o];this.HorzSegmentsOverlap(l.OutPt1.Pt.X,l.OffPt.X,s.Bot.X,s.Top.X)&&this.AddJoin(l.OutPt1,n,l.OffPt)}if(i.OutIdx>=0&&null!==i.PrevInAEL&&i.PrevInAEL.Curr.X===i.Bot.X&&i.PrevInAEL.OutIdx>=0&&t.ClipperBase.SlopesEqual5(i.PrevInAEL.Curr,i.PrevInAEL.Top,i.Curr,i.Top)&&0!==i.WindDelta&&0!==i.PrevInAEL.WindDelta){var h=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(n,h,i.Top)}if(i.NextInAEL!==s){if(s.OutIdx>=0&&s.PrevInAEL.OutIdx>=0&&t.ClipperBase.SlopesEqual5(s.PrevInAEL.Curr,s.PrevInAEL.Top,s.Curr,s.Top)&&0!==s.WindDelta&&0!==s.PrevInAEL.WindDelta){h=this.AddOutPt(s.PrevInAEL,s.Bot);this.AddJoin(n,h,s.Top)}var u=i.NextInAEL;if(null!==u)for(;u!==s;)this.IntersectEdges(s,u,i.Curr),u=u.NextInAEL}}}}InsertEdgeIntoAEL(t,e){if(null===this.m_ActiveEdges)t.PrevInAEL=null,t.NextInAEL=null,this.m_ActiveEdges=t;else if(null===e&&this.E2InsertsBeforeE1(this.m_ActiveEdges,t))t.PrevInAEL=null,t.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=t,this.m_ActiveEdges=t;else{for(null===e&&(e=this.m_ActiveEdges);null!==e.NextInAEL&&!this.E2InsertsBeforeE1(e.NextInAEL,t);)e=e.NextInAEL;t.NextInAEL=e.NextInAEL,null!==e.NextInAEL&&(e.NextInAEL.PrevInAEL=t),t.PrevInAEL=e,e.NextInAEL=t}}E2InsertsBeforeE1(e,i){return i.Curr.X===e.Curr.X?i.Top.Y>e.Top.Y?i.Top.X<t.Clipper.TopX(e,i.Top.Y):e.Top.X>t.Clipper.TopX(i,e.Top.Y):i.Curr.X<e.Curr.X}IsEvenOddFillType(t){return 0===t.PolyTyp?0===this.m_SubjFillType:0===this.m_ClipFillType}IsEvenOddAltFillType(t){return 0===t.PolyTyp?0===this.m_ClipFillType:0===this.m_SubjFillType}IsContributing(t){var e,i;switch(0===t.PolyTyp?(e=this.m_SubjFillType,i=this.m_ClipFillType):(e=this.m_ClipFillType,i=this.m_SubjFillType),e){case 0:if(0===t.WindDelta&&1!==t.WindCnt)return!1;break;case 1:if(1!==Math.abs(t.WindCnt))return!1;break;case 2:if(1!==t.WindCnt)return!1;break;default:if(-1!==t.WindCnt)return!1}switch(this.m_ClipType){case 0:switch(i){case 0:case 1:return 0!==t.WindCnt2;case 2:return t.WindCnt2>0;default:return t.WindCnt2<0}case 1:switch(i){case 0:case 1:return 0===t.WindCnt2;case 2:return t.WindCnt2<=0;default:return t.WindCnt2>=0}case 2:if(0===t.PolyTyp)switch(i){case 0:case 1:return 0===t.WindCnt2;case 2:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(i){case 0:case 1:return 0!==t.WindCnt2;case 2:return t.WindCnt2>0;default:return t.WindCnt2<0}case 3:if(0!==t.WindDelta)return!0;switch(i){case 0:case 1:return 0===t.WindCnt2;case 2:return t.WindCnt2<=0;default:return t.WindCnt2>=0}}return!0}SetWindingCount(t){for(var e=t.PrevInAEL;null!==e&&(e.PolyTyp!==t.PolyTyp||0===e.WindDelta);)e=e.PrevInAEL;if(null===e){var i=0===t.PolyTyp?this.m_SubjFillType:this.m_ClipFillType;0===t.WindDelta?t.WindCnt=3===i?-1:1:t.WindCnt=t.WindDelta,t.WindCnt2=0,e=this.m_ActiveEdges}else if(0===t.WindDelta&&1!==this.m_ClipType)t.WindCnt=1,t.WindCnt2=e.WindCnt2,e=e.NextInAEL;else if(this.IsEvenOddFillType(t)){if(0===t.WindDelta){for(var s=!0,r=e.PrevInAEL;null!==r;)r.PolyTyp===e.PolyTyp&&0!==r.WindDelta&&(s=!s),r=r.PrevInAEL;t.WindCnt=s?0:1}else t.WindCnt=t.WindDelta;t.WindCnt2=e.WindCnt2,e=e.NextInAEL}else e.WindCnt*e.WindDelta<0?Math.abs(e.WindCnt)>1?e.WindDelta*t.WindDelta<0?t.WindCnt=e.WindCnt:t.WindCnt=e.WindCnt+t.WindDelta:t.WindCnt=0===t.WindDelta?1:t.WindDelta:0===t.WindDelta?t.WindCnt=e.WindCnt<0?e.WindCnt-1:e.WindCnt+1:e.WindDelta*t.WindDelta<0?t.WindCnt=e.WindCnt:t.WindCnt=e.WindCnt+t.WindDelta,t.WindCnt2=e.WindCnt2,e=e.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;e!==t;)0!==e.WindDelta&&(t.WindCnt2=0===t.WindCnt2?1:0),e=e.NextInAEL;else for(;e!==t;)t.WindCnt2+=e.WindDelta,e=e.NextInAEL}AddEdgeToSEL(t){null===this.m_SortedEdges?(this.m_SortedEdges=t,t.PrevInSEL=null,t.NextInSEL=null):(t.NextInSEL=this.m_SortedEdges,t.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=t,this.m_SortedEdges=t)}PopEdgeFromSEL(t){if(t.v=this.m_SortedEdges,null===t.v)return!1;var e=t.v;return this.m_SortedEdges=t.v.NextInSEL,null!==this.m_SortedEdges&&(this.m_SortedEdges.PrevInSEL=null),e.NextInSEL=null,e.PrevInSEL=null,!0}CopyAELToSEL(){var t=this.m_ActiveEdges;for(this.m_SortedEdges=t;null!==t;)t.PrevInSEL=t.PrevInAEL,t.NextInSEL=t.NextInAEL,t=t.NextInAEL}SwapPositionsInSEL(t,e){if(!(null===t.NextInSEL&&null===t.PrevInSEL||null===e.NextInSEL&&null===e.PrevInSEL)){if(t.NextInSEL===e)null!==(i=e.NextInSEL)&&(i.PrevInSEL=t),null!==(s=t.PrevInSEL)&&(s.NextInSEL=e),e.PrevInSEL=s,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=i;else if(e.NextInSEL===t){null!==(i=t.NextInSEL)&&(i.PrevInSEL=e),null!==(s=e.PrevInSEL)&&(s.NextInSEL=t),t.PrevInSEL=s,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=i}else{var i=t.NextInSEL,s=t.PrevInSEL;t.NextInSEL=e.NextInSEL,null!==t.NextInSEL&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=e.PrevInSEL,null!==t.PrevInSEL&&(t.PrevInSEL.NextInSEL=t),e.NextInSEL=i,null!==e.NextInSEL&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=s,null!==e.PrevInSEL&&(e.PrevInSEL.NextInSEL=e)}null===t.PrevInSEL?this.m_SortedEdges=t:null===e.PrevInSEL&&(this.m_SortedEdges=e)}}AddLocalMaxPoly(t,e,i){this.AddOutPt(t,i),0===e.WindDelta&&this.AddOutPt(e,i),t.OutIdx===e.OutIdx?(t.OutIdx=-1,e.OutIdx=-1):t.OutIdx<e.OutIdx?this.AppendPolygon(t,e):this.AppendPolygon(e,t)}AddLocalMinPoly(e,i,s){var r,n,o;if(t.ClipperBase.IsHorizontal(i)||e.Dx>i.Dx?(r=this.AddOutPt(e,s),i.OutIdx=e.OutIdx,e.Side=0,i.Side=1,o=(n=e).PrevInAEL===i?i.PrevInAEL:n.PrevInAEL):(r=this.AddOutPt(i,s),e.OutIdx=i.OutIdx,e.Side=1,i.Side=0,o=(n=i).PrevInAEL===e?e.PrevInAEL:n.PrevInAEL),null!==o&&o.OutIdx>=0&&o.Top.Y<s.Y&&n.Top.Y<s.Y){var a=t.Clipper.TopX(o,s.Y),l=t.Clipper.TopX(n,s.Y);if(a===l&&0!==n.WindDelta&&0!==o.WindDelta&&t.ClipperBase.SlopesEqual5(new t.FPoint(a,s.Y),o.Top,new t.FPoint(l,s.Y),n.Top)){var h=this.AddOutPt(o,s);this.AddJoin(r,h,n.Top)}}return r}AddOutPt(e,i){if(e.OutIdx<0){let r=this.CreateOutRec();r.IsOpen=0===e.WindDelta;var s=new t.OutPt;return r.Pts=s,s.Idx=r.Idx,s.Pt.X=i.X,s.Pt.Y=i.Y,s.Next=s,s.Prev=s,r.IsOpen||this.SetHoleState(e,r),e.OutIdx=r.Idx,s}{let o=this.m_PolyOuts[e.OutIdx];var r=o.Pts,n=0===e.Side;return n&&t.FPoint.op_Equality(i,r.Pt)?r:!n&&t.FPoint.op_Equality(i,r.Prev.Pt)?r.Prev:((s=new t.OutPt).Idx=o.Idx,s.Pt.X=i.X,s.Pt.Y=i.Y,s.Next=r,s.Prev=r.Prev,s.Prev.Next=s,r.Prev=s,n&&(o.Pts=s),s)}}GetLastOutPt(t){var e=this.m_PolyOuts[t.OutIdx];return 0===t.Side?e.Pts:e.Pts.Prev}SwapPoints(e,i){var s=new t.FPoint(e.Value);e.Value.X=i.Value.X,e.Value.Y=i.Value.Y,i.Value.X=s.X,i.Value.Y=s.Y}HorzSegmentsOverlap(t,e,i,s){var r;return t>e&&(r=t,t=e,e=r),i>s&&(r=i,i=s,s=r),t<s&&i<e}SetHoleState(t,e){for(var i=t.PrevInAEL,s=null;null!==i;)i.OutIdx>=0&&0!==i.WindDelta&&(null===s?s=i:s.OutIdx===i.OutIdx&&(s=null)),i=i.PrevInAEL;null===s?(e.FirstLeft=null,e.IsHole=!1):(e.FirstLeft=this.m_PolyOuts[s.OutIdx],e.IsHole=!e.FirstLeft.IsHole)}GetDx(e,i){return e.Y===i.Y?t.ClipperBase.horizontal:(i.X-e.X)/(i.Y-e.Y)}FirstIsBottomPt(e,i){for(var s=e.Prev;t.FPoint.op_Equality(s.Pt,e.Pt)&&s!==e;)s=s.Prev;var r=Math.abs(this.GetDx(e.Pt,s.Pt));for(s=e.Next;t.FPoint.op_Equality(s.Pt,e.Pt)&&s!==e;)s=s.Next;var n=Math.abs(this.GetDx(e.Pt,s.Pt));for(s=i.Prev;t.FPoint.op_Equality(s.Pt,i.Pt)&&s!==i;)s=s.Prev;var o=Math.abs(this.GetDx(i.Pt,s.Pt));for(s=i.Next;t.FPoint.op_Equality(s.Pt,i.Pt)&&s!==i;)s=s.Next;var a=Math.abs(this.GetDx(i.Pt,s.Pt));return Math.max(r,n)===Math.max(o,a)&&Math.min(r,n)===Math.min(o,a)?this.Area(e)>0:r>=o&&r>=a||n>=o&&n>=a}GetBottomPt(e){for(var i=null,s=e.Next;s!==e;)s.Pt.Y>e.Pt.Y?(e=s,i=null):s.Pt.Y===e.Pt.Y&&s.Pt.X<=e.Pt.X&&(s.Pt.X<e.Pt.X?(i=null,e=s):s.Next!==e&&s.Prev!==e&&(i=s)),s=s.Next;if(null!==i)for(;i!==s;)for(this.FirstIsBottomPt(s,i)||(e=i),i=i.Next;t.FPoint.op_Inequality(i.Pt,e.Pt);)i=i.Next;return e}GetLowermostRec(t,e){null===t.BottomPt&&(t.BottomPt=this.GetBottomPt(t.Pts)),null===e.BottomPt&&(e.BottomPt=this.GetBottomPt(e.Pts));var i=t.BottomPt,s=e.BottomPt;return i.Pt.Y>s.Pt.Y?t:i.Pt.Y<s.Pt.Y?e:i.Pt.X<s.Pt.X?t:i.Pt.X>s.Pt.X||i.Next===i?e:s.Next===s||this.FirstIsBottomPt(i,s)?t:e}OutRec1RightOfOutRec2(t,e){do{if((t=t.FirstLeft)===e)return!0}while(null!==t);return!1}GetOutRec(t){for(var e=this.m_PolyOuts[t];e!==this.m_PolyOuts[e.Idx];)e=this.m_PolyOuts[e.Idx];return e}AppendPolygon(t,e){var i,s=this.m_PolyOuts[t.OutIdx],r=this.m_PolyOuts[e.OutIdx];i=this.OutRec1RightOfOutRec2(s,r)?r:this.OutRec1RightOfOutRec2(r,s)?s:this.GetLowermostRec(s,r);var n=s.Pts,o=n.Prev,a=r.Pts,l=a.Prev;0===t.Side?0===e.Side?(this.ReversePolyPtLinks(a),a.Next=n,n.Prev=a,o.Next=l,l.Prev=o,s.Pts=l):(l.Next=n,n.Prev=l,a.Prev=o,o.Next=a,s.Pts=a):1===e.Side?(this.ReversePolyPtLinks(a),o.Next=l,l.Prev=o,a.Next=n,n.Prev=a):(o.Next=a,a.Prev=o,n.Prev=l,l.Next=n),s.BottomPt=null,i===r&&(r.FirstLeft!==s&&(s.FirstLeft=r.FirstLeft),s.IsHole=r.IsHole),r.Pts=null,r.BottomPt=null,r.FirstLeft=s;var h=t.OutIdx,u=e.OutIdx;t.OutIdx=-1,e.OutIdx=-1;for(var c=this.m_ActiveEdges;null!==c;){if(c.OutIdx===u){c.OutIdx=h,c.Side=t.Side;break}c=c.NextInAEL}r.Idx=s.Idx}ReversePolyPtLinks(t){if(null!==t){var e,i;e=t;do{i=e.Next,e.Next=e.Prev,e.Prev=i,e=i}while(e!==t)}}static SwapSides(t,e){var i=t.Side;t.Side=e.Side,e.Side=i}static SwapPolyIndexes(t,e){var i=t.OutIdx;t.OutIdx=e.OutIdx,e.OutIdx=i}IntersectEdges(e,i,s){var r=e.OutIdx>=0,n=i.OutIdx>=0;if(!t.use_lines||0!==e.WindDelta&&0!==i.WindDelta){if(e.PolyTyp===i.PolyTyp)if(this.IsEvenOddFillType(e)){var o=e.WindCnt;e.WindCnt=i.WindCnt,i.WindCnt=o}else e.WindCnt+i.WindDelta===0?e.WindCnt=-e.WindCnt:e.WindCnt+=i.WindDelta,i.WindCnt-e.WindDelta==0?i.WindCnt=-i.WindCnt:i.WindCnt-=e.WindDelta;else this.IsEvenOddFillType(i)?e.WindCnt2=0===e.WindCnt2?1:0:e.WindCnt2+=i.WindDelta,this.IsEvenOddFillType(e)?i.WindCnt2=0===i.WindCnt2?1:0:i.WindCnt2-=e.WindDelta;var a,l,h,u,c,d;switch(0===e.PolyTyp?(a=this.m_SubjFillType,h=this.m_ClipFillType):(a=this.m_ClipFillType,h=this.m_SubjFillType),0===i.PolyTyp?(l=this.m_SubjFillType,u=this.m_ClipFillType):(l=this.m_ClipFillType,u=this.m_SubjFillType),a){case 2:c=e.WindCnt;break;case 3:c=-e.WindCnt;break;default:c=Math.abs(e.WindCnt)}switch(l){case 2:d=i.WindCnt;break;case 3:d=-i.WindCnt;break;default:d=Math.abs(i.WindCnt)}if(r&&n)0!==c&&1!==c||0!==d&&1!==d||e.PolyTyp!==i.PolyTyp&&3!==this.m_ClipType?this.AddLocalMaxPoly(e,i,s):(this.AddOutPt(e,s),this.AddOutPt(i,s),t.Clipper.SwapSides(e,i),t.Clipper.SwapPolyIndexes(e,i));else if(r)0!==d&&1!==d||(this.AddOutPt(e,s),t.Clipper.SwapSides(e,i),t.Clipper.SwapPolyIndexes(e,i));else if(n)0!==c&&1!==c||(this.AddOutPt(i,s),t.Clipper.SwapSides(e,i),t.Clipper.SwapPolyIndexes(e,i));else if(!(0!==c&&1!==c||0!==d&&1!==d)){var p,f;switch(h){case 2:p=e.WindCnt2;break;case 3:p=-e.WindCnt2;break;default:p=Math.abs(e.WindCnt2)}switch(u){case 2:f=i.WindCnt2;break;case 3:f=-i.WindCnt2;break;default:f=Math.abs(i.WindCnt2)}if(e.PolyTyp!==i.PolyTyp)this.AddLocalMinPoly(e,i,s);else if(1===c&&1===d)switch(this.m_ClipType){case 0:p>0&&f>0&&this.AddLocalMinPoly(e,i,s);break;case 1:p<=0&&f<=0&&this.AddLocalMinPoly(e,i,s);break;case 2:(1===e.PolyTyp&&p>0&&f>0||0===e.PolyTyp&&p<=0&&f<=0)&&this.AddLocalMinPoly(e,i,s);break;case 3:this.AddLocalMinPoly(e,i,s)}else t.Clipper.SwapSides(e,i)}}else{if(0===e.WindDelta&&0===i.WindDelta)return;e.PolyTyp===i.PolyTyp&&e.WindDelta!==i.WindDelta&&1===this.m_ClipType?0===e.WindDelta?n&&(this.AddOutPt(e,s),r&&(e.OutIdx=-1)):r&&(this.AddOutPt(i,s),n&&(i.OutIdx=-1)):e.PolyTyp!==i.PolyTyp&&(0!==e.WindDelta||1!==Math.abs(i.WindCnt)||1===this.m_ClipType&&0!==i.WindCnt2?0!==i.WindDelta||1!==Math.abs(e.WindCnt)||1===this.m_ClipType&&0!==e.WindCnt2||(this.AddOutPt(i,s),n&&(i.OutIdx=-1)):(this.AddOutPt(e,s),r&&(e.OutIdx=-1)))}}DeleteFromSEL(t){var e=t.PrevInSEL,i=t.NextInSEL;null===e&&null===i&&t!==this.m_SortedEdges||(null!==e?e.NextInSEL=i:this.m_SortedEdges=i,null!==i&&(i.PrevInSEL=e),t.NextInSEL=null,t.PrevInSEL=null)}ProcessHorizontals(){for(var t={};this.PopEdgeFromSEL(t);)this.ProcessHorizontal(t.v)}GetHorzDirection(t,e){t.Bot.X<t.Top.X?(e.Left=t.Bot.X,e.Right=t.Top.X,e.Dir=1):(e.Left=t.Top.X,e.Right=t.Bot.X,e.Dir=0)}ProcessHorizontal(e){var i={Dir:null,Left:null,Right:null};this.GetHorzDirection(e,i);for(var s=i.Dir,r=i.Left,n=i.Right,o=0===e.WindDelta,a=e,l=null;null!==a.NextInLML&&t.ClipperBase.IsHorizontal(a.NextInLML);)a=a.NextInLML;null===a.NextInLML&&(l=this.GetMaximaPair(a));var h=this.m_Maxima;if(null!==h)if(1===s){for(;null!==h&&h.X<=e.Bot.X;)h=h.Next;null!==h&&h.X>=a.Top.X&&(h=null)}else{for(;null!==h.Next&&h.Next.X<e.Bot.X;)h=h.Next;h.X<=a.Top.X&&(h=null)}for(var u=null;;){for(var c=e===a,d=this.GetNextInAEL(e,s);null!==d;){if(null!==h)if(1===s)for(;null!==h&&h.X<d.Curr.X;)e.OutIdx>=0&&!o&&this.AddOutPt(e,new t.FPoint(h.X,e.Bot.Y)),h=h.Next;else for(;null!==h&&h.X>d.Curr.X;)e.OutIdx>=0&&!o&&this.AddOutPt(e,new t.FPoint(h.X,e.Bot.Y)),h=h.Prev;if(1===s&&d.Curr.X>n||0===s&&d.Curr.X<r)break;if(d.Curr.X===e.Top.X&&null!==e.NextInLML&&d.Dx<e.NextInLML.Dx)break;if(e.OutIdx>=0&&!o){u=this.AddOutPt(e,d.Curr);for(var p=this.m_SortedEdges;null!==p;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(e.Bot.X,e.Top.X,p.Bot.X,p.Top.X)){var f=this.GetLastOutPt(p);this.AddJoin(f,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,e.Bot)}if(d===l&&c)return e.OutIdx>=0&&this.AddLocalMaxPoly(e,l,e.Top),this.DeleteFromAEL(e),void this.DeleteFromAEL(l);if(1===s){var m=new t.FPoint(d.Curr.X,e.Curr.Y);this.IntersectEdges(e,d,m)}else{m=new t.FPoint(d.Curr.X,e.Curr.Y);this.IntersectEdges(d,e,m)}var g=this.GetNextInAEL(d,s);this.SwapPositionsInAEL(e,d),d=g}if(null===e.NextInLML||!t.ClipperBase.IsHorizontal(e.NextInLML))break;(e=this.UpdateEdgeIntoAEL(e)).OutIdx>=0&&this.AddOutPt(e,e.Bot),i={Dir:s,Left:r,Right:n},this.GetHorzDirection(e,i),s=i.Dir,r=i.Left,n=i.Right}if(e.OutIdx>=0&&null===u){u=this.GetLastOutPt(e);for(p=this.m_SortedEdges;null!==p;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(e.Bot.X,e.Top.X,p.Bot.X,p.Top.X)){f=this.GetLastOutPt(p);this.AddJoin(f,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,e.Top)}if(null!==e.NextInLML)if(e.OutIdx>=0){if(u=this.AddOutPt(e,e.Top),0===(e=this.UpdateEdgeIntoAEL(e)).WindDelta)return;var y=e.PrevInAEL;g=e.NextInAEL;if(null!==y&&y.Curr.X===e.Bot.X&&y.Curr.Y===e.Bot.Y&&0===y.WindDelta&&y.OutIdx>=0&&y.Curr.Y>y.Top.Y&&t.ClipperBase.SlopesEqual3(e,y)){let t=this.AddOutPt(y,e.Bot);this.AddJoin(u,t,e.Top)}else if(null!==g&&g.Curr.X===e.Bot.X&&g.Curr.Y===e.Bot.Y&&0!==g.WindDelta&&g.OutIdx>=0&&g.Curr.Y>g.Top.Y&&t.ClipperBase.SlopesEqual3(e,g)){let t=this.AddOutPt(g,e.Bot);this.AddJoin(u,t,e.Top)}}else e=this.UpdateEdgeIntoAEL(e);else e.OutIdx>=0&&this.AddOutPt(e,e.Top),this.DeleteFromAEL(e)}GetNextInAEL(t,e){return 1===e?t.NextInAEL:t.PrevInAEL}IsMinima(t){return null!==t&&t.Prev.NextInLML!==t&&t.Next.NextInLML!==t}IsMaxima(t,e){return null!==t&&t.Top.Y===e&&null===t.NextInLML}IsIntermediate(t,e){return t.Top.Y===e&&null!==t.NextInLML}GetMaximaPair(e){return t.FPoint.op_Equality(e.Next.Top,e.Top)&&null===e.Next.NextInLML?e.Next:t.FPoint.op_Equality(e.Prev.Top,e.Top)&&null===e.Prev.NextInLML?e.Prev:null}GetMaximaPairEx(e){var i=this.GetMaximaPair(e);return null===i||i.OutIdx===t.ClipperBase.Skip||i.NextInAEL===i.PrevInAEL&&!t.ClipperBase.IsHorizontal(i)?null:i}ProcessIntersections(e){if(null===this.m_ActiveEdges)return!0;try{if(this.BuildIntersectList(e),0===this.m_IntersectList.length)return!0;if(1!==this.m_IntersectList.length&&!this.FixupIntersectionOrder())return!1;this.ProcessIntersectList()}catch(i){this.m_SortedEdges=null,this.m_IntersectList.length=0,t.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0}BuildIntersectList(e){if(null!==this.m_ActiveEdges){var i=this.m_ActiveEdges;for(this.m_SortedEdges=i;null!==i;)i.PrevInSEL=i.PrevInAEL,i.NextInSEL=i.NextInAEL,i.Curr.X=t.Clipper.TopX(i,e),i=i.NextInAEL;for(var s=!0;s&&null!==this.m_SortedEdges;){for(s=!1,i=this.m_SortedEdges;null!==i.NextInSEL;){var r=i.NextInSEL,n=new t.FPoint;if(i.Curr.X>r.Curr.X){this.IntersectPoint(i,r,n),n.Y<e&&(n=new t.FPoint(t.Clipper.TopX(i,e),e));var o=new t.IntersectNode;o.Edge1=i,o.Edge2=r,o.Pt.X=n.X,o.Pt.Y=n.Y,this.m_IntersectList.push(o),this.SwapPositionsInSEL(i,r),s=!0}else i=r}if(null===i.PrevInSEL)break;i.PrevInSEL.NextInSEL=null}this.m_SortedEdges=null}}EdgesAdjacent(t){return t.Edge1.NextInSEL===t.Edge2||t.Edge1.PrevInSEL===t.Edge2}static IntersectNodeSort(t,e){return e.Pt.Y-t.Pt.Y}FixupIntersectionOrder(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var t=this.m_IntersectList.length,e=0;e<t;e++){if(!this.EdgesAdjacent(this.m_IntersectList[e])){for(var i=e+1;i<t&&!this.EdgesAdjacent(this.m_IntersectList[i]);)i++;if(i===t)return!1;var s=this.m_IntersectList[e];this.m_IntersectList[e]=this.m_IntersectList[i],this.m_IntersectList[i]=s}this.SwapPositionsInSEL(this.m_IntersectList[e].Edge1,this.m_IntersectList[e].Edge2)}return!0}ProcessIntersectList(){for(var t=0,e=this.m_IntersectList.length;t<e;t++){var i=this.m_IntersectList[t];this.IntersectEdges(i.Edge1,i.Edge2,i.Pt),this.SwapPositionsInAEL(i.Edge1,i.Edge2)}this.m_IntersectList.length=0}static TopX(t,e){return e===t.Top.Y?t.Top.X:t.Bot.X+t.Dx*(e-t.Bot.Y)}IntersectPoint(e,i,s){var r,n;if(s.X=0,s.Y=0,e.Dx===i.Dx)return s.Y=e.Curr.Y,void(s.X=t.Clipper.TopX(e,s.Y));if(0===e.Delta.X)s.X=e.Bot.X,t.ClipperBase.IsHorizontal(i)?s.Y=i.Bot.Y:(n=i.Bot.Y-i.Bot.X/i.Dx,s.Y=s.X/i.Dx+n);else if(0===i.Delta.X)s.X=i.Bot.X,t.ClipperBase.IsHorizontal(e)?s.Y=e.Bot.Y:(r=e.Bot.Y-e.Bot.X/e.Dx,s.Y=s.X/e.Dx+r);else{r=e.Bot.X-e.Bot.Y*e.Dx;var o=((n=i.Bot.X-i.Bot.Y*i.Dx)-r)/(e.Dx-i.Dx);s.Y=o,Math.abs(e.Dx)<Math.abs(i.Dx)?s.X=e.Dx*o+r:s.X=i.Dx*o+n}if(s.Y<e.Top.Y||s.Y<i.Top.Y){if(e.Top.Y>i.Top.Y)return s.Y=e.Top.Y,s.X=t.Clipper.TopX(i,e.Top.Y),s.X<e.Top.X;s.Y=i.Top.Y,Math.abs(e.Dx)<Math.abs(i.Dx)?s.X=t.Clipper.TopX(e,s.Y):s.X=t.Clipper.TopX(i,s.Y)}s.Y>e.Curr.Y&&(s.Y=e.Curr.Y,Math.abs(e.Dx)>Math.abs(i.Dx)?s.X=t.Clipper.TopX(i,s.Y):s.X=t.Clipper.TopX(e,s.Y))}ProcessEdgesAtTopOfScanbeam(e){for(var i=this.m_ActiveEdges;null!==i;){var s=this.IsMaxima(i,e);if(s){var r=this.GetMaximaPairEx(i);s=null===r||!t.ClipperBase.IsHorizontal(r)}if(s){this.StrictlySimple&&this.InsertMaxima(i.Top.X);var n=i.PrevInAEL;this.DoMaxima(i),i=null===n?this.m_ActiveEdges:n.NextInAEL}else{if(this.IsIntermediate(i,e)&&t.ClipperBase.IsHorizontal(i.NextInLML)?((i=this.UpdateEdgeIntoAEL(i)).OutIdx>=0&&this.AddOutPt(i,i.Bot),this.AddEdgeToSEL(i)):(i.Curr.X=t.Clipper.TopX(i,e),i.Curr.Y=e),this.StrictlySimple){n=i.PrevInAEL;if(i.OutIdx>=0&&0!==i.WindDelta&&null!==n&&n.OutIdx>=0&&n.Curr.X===i.Curr.X&&0!==n.WindDelta){var o=new t.FPoint(i.Curr),a=this.AddOutPt(n,o),l=this.AddOutPt(i,o);this.AddJoin(a,l,o)}}i=i.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,i=this.m_ActiveEdges;null!==i;){if(this.IsIntermediate(i,e)){a=null;i.OutIdx>=0&&(a=this.AddOutPt(i,i.Top));n=(i=this.UpdateEdgeIntoAEL(i)).PrevInAEL;var h=i.NextInAEL;if(null!==n&&n.Curr.X===i.Bot.X&&n.Curr.Y===i.Bot.Y&&null!==a&&n.OutIdx>=0&&n.Curr.Y===n.Top.Y&&t.ClipperBase.SlopesEqual5(i.Curr,i.Top,n.Curr,n.Top)&&0!==i.WindDelta&&0!==n.WindDelta){l=this.AddOutPt(n,i.Bot);this.AddJoin(a,l,i.Top)}else if(null!==h&&h.Curr.X===i.Bot.X&&h.Curr.Y===i.Bot.Y&&null!==a&&h.OutIdx>=0&&h.Curr.Y===h.Top.Y&&t.ClipperBase.SlopesEqual5(i.Curr,i.Top,h.Curr,h.Top)&&0!==i.WindDelta&&0!==h.WindDelta){l=this.AddOutPt(h,i.Bot);this.AddJoin(a,l,i.Top)}}i=i.NextInAEL}}DoMaxima(e){var i=this.GetMaximaPairEx(e);if(null===i)return e.OutIdx>=0&&this.AddOutPt(e,e.Top),void this.DeleteFromAEL(e);for(var s=e.NextInAEL;null!==s&&s!==i;)this.IntersectEdges(e,s,e.Top),this.SwapPositionsInAEL(e,s),s=e.NextInAEL;-1===e.OutIdx&&-1===i.OutIdx?(this.DeleteFromAEL(e),this.DeleteFromAEL(i)):e.OutIdx>=0&&i.OutIdx>=0?(e.OutIdx>=0&&this.AddLocalMaxPoly(e,i,e.Top),this.DeleteFromAEL(e),this.DeleteFromAEL(i)):t.use_lines&&0===e.WindDelta?(e.OutIdx>=0&&(this.AddOutPt(e,e.Top),e.OutIdx=t.ClipperBase.Unassigned),this.DeleteFromAEL(e),i.OutIdx>=0&&(this.AddOutPt(i,e.Top),i.OutIdx=t.ClipperBase.Unassigned),this.DeleteFromAEL(i)):t.Error("DoMaxima error")}static ReversePaths(t){for(var e=0,i=t.length;e<i;e++)t[e].reverse()}static Orientation(e){return t.Clipper.Area(e)>=0}PointCount(t){if(null===t)return 0;var e=0,i=t;do{e++,i=i.Next}while(i!==t);return e}BuildResult(e){t.Clear(e);for(var i=0,s=this.m_PolyOuts.length;i<s;i++){var r=this.m_PolyOuts[i];if(null!==r.Pts){var n=r.Pts.Prev,o=this.PointCount(n);if(!(o<2)){for(var a=new Array(o),l=0;l<o;l++)a[l]=n.Pt,n=n.Prev;e.push(a)}}}}BuildResult2(e){e.Clear();for(var i=0,s=this.m_PolyOuts.length;i<s;i++){var r=this.m_PolyOuts[i],n=this.PointCount(r.Pts);if(!(r.IsOpen&&n<2||!r.IsOpen&&n<3)){this.FixHoleLinkage(r);var o=new t.PolyNode;e.m_AllPolys.push(o),r.PolyNode=o,o.m_polygon.length=n;for(var a=r.Pts.Prev,l=0;l<n;l++)o.m_polygon[l]=a.Pt,a=a.Prev}}for(i=0,s=this.m_PolyOuts.length;i<s;i++){null!==(r=this.m_PolyOuts[i]).PolyNode&&(r.IsOpen?(r.PolyNode.IsOpen=!0,e.AddChild(r.PolyNode)):null!==r.FirstLeft&&null!==r.FirstLeft.PolyNode?r.FirstLeft.PolyNode.AddChild(r.PolyNode):e.AddChild(r.PolyNode))}}FixupOutPolyline(e){for(var i=e.Pts,s=i.Prev;i!==s;)if(i=i.Next,t.FPoint.op_Equality(i.Pt,i.Prev.Pt)){i===s&&(s=i.Prev);var r=i.Prev;r.Next=i.Next,i.Next.Prev=r,i=r}i===i.Prev&&(e.Pts=null)}FixupOutPolygon(e){var i=null;e.BottomPt=null;for(var s=e.Pts,r=this.PreserveCollinear||this.StrictlySimple;;){if(s.Prev===s||s.Prev===s.Next)return void(e.Pts=null);if(t.FPoint.op_Equality(s.Pt,s.Next.Pt)||t.FPoint.op_Equality(s.Pt,s.Prev.Pt)||t.ClipperBase.SlopesEqual4(s.Prev.Pt,s.Pt,s.Next.Pt)&&(!r||!this.Pt2IsBetweenPt1AndPt3(s.Prev.Pt,s.Pt,s.Next.Pt)))i=null,s.Prev.Next=s.Next,s.Next.Prev=s.Prev,s=s.Prev;else{if(s===i)break;null===i&&(i=s),s=s.Next}}e.Pts=s}DupOutPt(e,i){var s=new t.OutPt;return s.Pt.X=e.Pt.X,s.Pt.Y=e.Pt.Y,s.Idx=e.Idx,i?(s.Next=e.Next,s.Prev=e,e.Next.Prev=s,e.Next=s):(s.Prev=e.Prev,s.Next=e,e.Prev.Next=s,e.Prev=s),s}GetOverlap(t,e,i,s,r){return t<e?i<s?(r.Left=Math.max(t,i),r.Right=Math.min(e,s)):(r.Left=Math.max(t,s),r.Right=Math.min(e,i)):i<s?(r.Left=Math.max(e,i),r.Right=Math.min(t,s)):(r.Left=Math.max(e,s),r.Right=Math.min(t,i)),r.Left<r.Right}JoinHorz(e,i,s,r,n,o){var a=e.Pt.X>i.Pt.X?0:1,l=s.Pt.X>r.Pt.X?0:1;if(a===l)return!1;if(1===a){for(;e.Next.Pt.X<=n.X&&e.Next.Pt.X>=e.Pt.X&&e.Next.Pt.Y===n.Y;)e=e.Next;o&&e.Pt.X!==n.X&&(e=e.Next),i=this.DupOutPt(e,!o),t.FPoint.op_Inequality(i.Pt,n)&&((e=i).Pt.X=n.X,e.Pt.Y=n.Y,i=this.DupOutPt(e,!o))}else{for(;e.Next.Pt.X>=n.X&&e.Next.Pt.X<=e.Pt.X&&e.Next.Pt.Y===n.Y;)e=e.Next;o||e.Pt.X===n.X||(e=e.Next),i=this.DupOutPt(e,o),t.FPoint.op_Inequality(i.Pt,n)&&((e=i).Pt.X=n.X,e.Pt.Y=n.Y,i=this.DupOutPt(e,o))}if(1===l){for(;s.Next.Pt.X<=n.X&&s.Next.Pt.X>=s.Pt.X&&s.Next.Pt.Y===n.Y;)s=s.Next;o&&s.Pt.X!==n.X&&(s=s.Next),r=this.DupOutPt(s,!o),t.FPoint.op_Inequality(r.Pt,n)&&((s=r).Pt.X=n.X,s.Pt.Y=n.Y,r=this.DupOutPt(s,!o))}else{for(;s.Next.Pt.X>=n.X&&s.Next.Pt.X<=s.Pt.X&&s.Next.Pt.Y===n.Y;)s=s.Next;o||s.Pt.X===n.X||(s=s.Next),r=this.DupOutPt(s,o),t.FPoint.op_Inequality(r.Pt,n)&&((s=r).Pt.X=n.X,s.Pt.Y=n.Y,r=this.DupOutPt(s,o))}return 1===a===o?(e.Prev=s,s.Next=e,i.Next=r,r.Prev=i):(e.Next=s,s.Prev=e,i.Prev=r,r.Next=i),!0}JoinPoints(e,i,s){var r=e.OutPt1,n=new t.OutPt,o=e.OutPt2,a=new t.OutPt,l=e.OutPt1.Pt.Y===e.OffPt.Y;if(l&&t.FPoint.op_Equality(e.OffPt,e.OutPt1.Pt)&&t.FPoint.op_Equality(e.OffPt,e.OutPt2.Pt)){if(i!==s)return!1;for(n=e.OutPt1.Next;n!==r&&t.FPoint.op_Equality(n.Pt,e.OffPt);)n=n.Next;var h=n.Pt.Y>e.OffPt.Y;for(a=e.OutPt2.Next;a!==o&&t.FPoint.op_Equality(a.Pt,e.OffPt);)a=a.Next;return h!==a.Pt.Y>e.OffPt.Y&&(h?(n=this.DupOutPt(r,!1),a=this.DupOutPt(o,!0),r.Prev=o,o.Next=r,n.Next=a,a.Prev=n,e.OutPt1=r,e.OutPt2=n,!0):(n=this.DupOutPt(r,!0),a=this.DupOutPt(o,!1),r.Next=o,o.Prev=r,n.Prev=a,a.Next=n,e.OutPt1=r,e.OutPt2=n,!0))}if(l){for(n=r;r.Prev.Pt.Y===r.Pt.Y&&r.Prev!==n&&r.Prev!==o;)r=r.Prev;for(;n.Next.Pt.Y===n.Pt.Y&&n.Next!==r&&n.Next!==o;)n=n.Next;if(n.Next===r||n.Next===o)return!1;for(a=o;o.Prev.Pt.Y===o.Pt.Y&&o.Prev!==a&&o.Prev!==n;)o=o.Prev;for(;a.Next.Pt.Y===a.Pt.Y&&a.Next!==o&&a.Next!==r;)a=a.Next;if(a.Next===o||a.Next===r)return!1;var u={Left:null,Right:null};if(!this.GetOverlap(r.Pt.X,n.Pt.X,o.Pt.X,a.Pt.X,u))return!1;var c,d=u.Left,p=u.Right,f=new t.FPoint;return r.Pt.X>=d&&r.Pt.X<=p?(f.X=r.Pt.X,f.Y=r.Pt.Y,c=r.Pt.X>n.Pt.X):o.Pt.X>=d&&o.Pt.X<=p?(f.X=o.Pt.X,f.Y=o.Pt.Y,c=o.Pt.X>a.Pt.X):n.Pt.X>=d&&n.Pt.X<=p?(f.X=n.Pt.X,f.Y=n.Pt.Y,c=n.Pt.X>r.Pt.X):(f.X=a.Pt.X,f.Y=a.Pt.Y,c=a.Pt.X>o.Pt.X),e.OutPt1=r,e.OutPt2=o,this.JoinHorz(r,n,o,a,f,c)}for(n=r.Next;t.FPoint.op_Equality(n.Pt,r.Pt)&&n!==r;)n=n.Next;var m=n.Pt.Y>r.Pt.Y||!t.ClipperBase.SlopesEqual4(r.Pt,n.Pt,e.OffPt);if(m){for(n=r.Prev;t.FPoint.op_Equality(n.Pt,r.Pt)&&n!==r;)n=n.Prev;if(n.Pt.Y>r.Pt.Y||!t.ClipperBase.SlopesEqual4(r.Pt,n.Pt,e.OffPt))return!1}for(a=o.Next;t.FPoint.op_Equality(a.Pt,o.Pt)&&a!==o;)a=a.Next;var g=a.Pt.Y>o.Pt.Y||!t.ClipperBase.SlopesEqual4(o.Pt,a.Pt,e.OffPt);if(g){for(a=o.Prev;t.FPoint.op_Equality(a.Pt,o.Pt)&&a!==o;)a=a.Prev;if(a.Pt.Y>o.Pt.Y||!t.ClipperBase.SlopesEqual4(o.Pt,a.Pt,e.OffPt))return!1}return n!==r&&a!==o&&n!==a&&(i!==s||m!==g)&&(m?(n=this.DupOutPt(r,!1),a=this.DupOutPt(o,!0),r.Prev=o,o.Next=r,n.Next=a,a.Prev=n,e.OutPt1=r,e.OutPt2=n,!0):(n=this.DupOutPt(r,!0),a=this.DupOutPt(o,!1),r.Next=o,o.Prev=r,n.Prev=a,a.Next=n,e.OutPt1=r,e.OutPt2=n,!0))}static GetBounds(e){for(var i=0,s=e.length;i<s&&0===e[i].length;)i++;if(i===s)return new t.FRect(0,0,0,0);var r=new t.FRect;for(r.left=e[i][0].X,r.right=r.left,r.top=e[i][0].Y,r.bottom=r.top;i<s;i++)for(var n=0,o=e[i].length;n<o;n++)e[i][n].X<r.left?r.left=e[i][n].X:e[i][n].X>r.right&&(r.right=e[i][n].X),e[i][n].Y<r.top?r.top=e[i][n].Y:e[i][n].Y>r.bottom&&(r.bottom=e[i][n].Y);return r}GetBounds2(e){var i=e,s=new t.FRect;for(s.left=e.Pt.X,s.right=e.Pt.X,s.top=e.Pt.Y,s.bottom=e.Pt.Y,e=e.Next;e!==i;)e.Pt.X<s.left&&(s.left=e.Pt.X),e.Pt.X>s.right&&(s.right=e.Pt.X),e.Pt.Y<s.top&&(s.top=e.Pt.Y),e.Pt.Y>s.bottom&&(s.bottom=e.Pt.Y),e=e.Next;return s}static PointInPolygon(t,e){var i=0,s=e.length;if(s<3)return 0;for(var r=e[0],n=1;n<=s;++n){var o=n===s?e[0]:e[n];if(o.Y===t.Y&&(o.X===t.X||r.Y===t.Y&&o.X>t.X==r.X<t.X))return-1;if(r.Y<t.Y!=o.Y<t.Y)if(r.X>=t.X)if(o.X>t.X)i=1-i;else{if(0===(a=(r.X-t.X)*(o.Y-t.Y)-(o.X-t.X)*(r.Y-t.Y)))return-1;a>0==o.Y>r.Y&&(i=1-i)}else if(o.X>t.X){var a;if(0===(a=(r.X-t.X)*(o.Y-t.Y)-(o.X-t.X)*(r.Y-t.Y)))return-1;a>0==o.Y>r.Y&&(i=1-i)}r=o}return i}PointInPolygon(t,e){var i=0,s=e,r=t.X,n=t.Y,o=e.Pt.X,a=e.Pt.Y;do{var l=(e=e.Next).Pt.X,h=e.Pt.Y;if(h===n&&(l===r||a===n&&l>r==o<r))return-1;if(a<n!=h<n)if(o>=r)if(l>r)i=1-i;else{if(0===(u=(o-r)*(h-n)-(l-r)*(a-n)))return-1;u>0==h>a&&(i=1-i)}else if(l>r){var u;if(0===(u=(o-r)*(h-n)-(l-r)*(a-n)))return-1;u>0==h>a&&(i=1-i)}o=l,a=h}while(s!==e);return i}Poly2ContainsPoly1(t,e){var i=t;do{var s=this.PointInPolygon(i.Pt,e);if(s>=0)return s>0;i=i.Next}while(i!==t);return!0}FixupFirstLefts1(e,i){for(var s,r,n=0,o=this.m_PolyOuts.length;n<o;n++)s=this.m_PolyOuts[n],r=t.Clipper.ParseFirstLeft(s.FirstLeft),null!==s.Pts&&r===e&&this.Poly2ContainsPoly1(s.Pts,i.Pts)&&(s.FirstLeft=i)}FixupFirstLefts2(e,i){for(var s,r,n=i.FirstLeft,o=0,a=this.m_PolyOuts.length;o<a;o++)null!==(s=this.m_PolyOuts[o]).Pts&&s!==i&&s!==e&&((r=t.Clipper.ParseFirstLeft(s.FirstLeft))!==n&&r!==e&&r!==i||(this.Poly2ContainsPoly1(s.Pts,e.Pts)?s.FirstLeft=e:this.Poly2ContainsPoly1(s.Pts,i.Pts)?s.FirstLeft=i:s.FirstLeft!==e&&s.FirstLeft!==i||(s.FirstLeft=n)))}FixupFirstLefts3(e,i){for(var s,r,n=0,o=this.m_PolyOuts.length;n<o;n++)s=this.m_PolyOuts[n],r=t.Clipper.ParseFirstLeft(s.FirstLeft),null!==s.Pts&&r===e&&(s.FirstLeft=i)}static ParseFirstLeft(t){for(;null!==t&&null===t.Pts;)t=t.FirstLeft;return t}JoinCommonEdges(){for(var t=0,e=this.m_Joins.length;t<e;t++){var i,s=this.m_Joins[t],r=this.GetOutRec(s.OutPt1.Idx),n=this.GetOutRec(s.OutPt2.Idx);if(null!==r.Pts&&null!==n.Pts)if(!r.IsOpen&&!n.IsOpen)i=r===n?r:this.OutRec1RightOfOutRec2(r,n)?n:this.OutRec1RightOfOutRec2(n,r)?r:this.GetLowermostRec(r,n),this.JoinPoints(s,r,n)&&(r===n?(r.Pts=s.OutPt1,r.BottomPt=null,(n=this.CreateOutRec()).Pts=s.OutPt2,this.UpdateOutPtIdxs(n),this.Poly2ContainsPoly1(n.Pts,r.Pts)?(n.IsHole=!r.IsHole,n.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(n,r),(n.IsHole^this.ReverseSolution)==this.Area$1(n)>0&&this.ReversePolyPtLinks(n.Pts)):this.Poly2ContainsPoly1(r.Pts,n.Pts)?(n.IsHole=r.IsHole,r.IsHole=!n.IsHole,n.FirstLeft=r.FirstLeft,r.FirstLeft=n,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,n),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(n.IsHole=r.IsHole,n.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,n))):(n.Pts=null,n.BottomPt=null,n.Idx=r.Idx,r.IsHole=i.IsHole,i===n&&(r.FirstLeft=n.FirstLeft),n.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(n,r)))}}UpdateOutPtIdxs(t){var e=t.Pts;do{e.Idx=t.Idx,e=e.Prev}while(e!==t.Pts)}DoSimplePolygons(){for(var e=0;e<this.m_PolyOuts.length;){var i=this.m_PolyOuts[e++],s=i.Pts;if(null!==s&&!i.IsOpen)do{for(var r=s.Next;r!==i.Pts;){if(t.FPoint.op_Equality(s.Pt,r.Pt)&&r.Next!==s&&r.Prev!==s){var n=s.Prev,o=r.Prev;s.Prev=o,o.Next=s,r.Prev=n,n.Next=r,i.Pts=s;var a=this.CreateOutRec();a.Pts=r,this.UpdateOutPtIdxs(a),this.Poly2ContainsPoly1(a.Pts,i.Pts)?(a.IsHole=!i.IsHole,a.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(a,i)):this.Poly2ContainsPoly1(i.Pts,a.Pts)?(a.IsHole=i.IsHole,i.IsHole=!a.IsHole,a.FirstLeft=i.FirstLeft,i.FirstLeft=a,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,a)):(a.IsHole=i.IsHole,a.FirstLeft=i.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(i,a)),r=s}r=r.Next}s=s.Next}while(s!==i.Pts)}}static Area(t){if(!Array.isArray(t))return 0;var e=t.length;if(e<3)return 0;for(var i=0,s=0,r=e-1;s<e;++s)i+=(t[r].X+t[s].X)*(t[r].Y-t[s].Y),r=s;return.5*-i}Area(t){var e=t;if(null===t)return 0;var i=0;do{i+=(t.Prev.Pt.X+t.Pt.X)*(t.Prev.Pt.Y-t.Pt.Y),t=t.Next}while(t!==e);return.5*i}Area$1(t){return this.Area(t.Pts)}static SimplifyPolygon(e,i){var s=new Array,r=new t.Clipper(0);return r.StrictlySimple=!0,r.AddPath(e,0,!0),r.Execute(1,s,i,i),s}static SimplifyPolygons(e,i){void 0===i&&(i=0);var s=new Array,r=new t.Clipper(0);return r.StrictlySimple=!0,r.AddPaths(e,0,!0),r.Execute(1,s,i,i),s}static DistanceSqrd(t,e){var i=t.X-e.X,s=t.Y-e.Y;return i*i+s*s}static DistanceFromLineSqrd(t,e,i){var s=e.Y-i.Y,r=i.X-e.X,n=s*e.X+r*e.Y;return(n=s*t.X+r*t.Y-n)*n/(s*s+r*r)}static SlopesNearCollinear(e,i,s,r){return Math.abs(e.X-i.X)>Math.abs(e.Y-i.Y)?e.X>i.X==e.X<s.X?t.Clipper.DistanceFromLineSqrd(e,i,s)<r:i.X>e.X==i.X<s.X?t.Clipper.DistanceFromLineSqrd(i,e,s)<r:t.Clipper.DistanceFromLineSqrd(s,e,i)<r:e.Y>i.Y==e.Y<s.Y?t.Clipper.DistanceFromLineSqrd(e,i,s)<r:i.Y>e.Y==i.Y<s.Y?t.Clipper.DistanceFromLineSqrd(i,e,s)<r:t.Clipper.DistanceFromLineSqrd(s,e,i)<r}static PointsAreClose(t,e,i){var s=t.X-e.X,r=t.Y-e.Y;return s*s+r*r<=i}static ExcludeOp(t){var e=t.Prev;return e.Next=t.Next,t.Next.Prev=e,e.Idx=0,e}static CleanPolygon(e,i){void 0===i&&(i=1.415);var s=e.length;if(0===s)return new Array;for(var r=new Array(s),n=0;n<s;++n)r[n]=new t.OutPt;for(n=0;n<s;++n)r[n].Pt=e[n],r[n].Next=r[(n+1)%s],r[n].Next.Prev=r[n],r[n].Idx=0;for(var o=i*i,a=r[0];0===a.Idx&&a.Next!==a.Prev;)t.Clipper.PointsAreClose(a.Pt,a.Prev.Pt,o)?(a=t.Clipper.ExcludeOp(a),s--):t.Clipper.PointsAreClose(a.Prev.Pt,a.Next.Pt,o)?(t.Clipper.ExcludeOp(a.Next),a=t.Clipper.ExcludeOp(a),s-=2):t.Clipper.SlopesNearCollinear(a.Prev.Pt,a.Pt,a.Next.Pt,o)?(a=t.Clipper.ExcludeOp(a),s--):(a.Idx=1,a=a.Next);s<3&&(s=0);var l=new Array(s);for(n=0;n<s;++n)l[n]=new t.FPoint(a.Pt),a=a.Next;return r=null,l}static CleanPolygons(e,i){for(var s=new Array(e.length),r=0,n=e.length;r<n;r++)s[r]=t.Clipper.CleanPolygon(e[r],i);return s}static Minkowski(e,i,s,r){var n=r?1:0,o=e.length,a=i.length,l=new Array;if(s)for(var h=0;h<a;h++){for(var u=new Array(o),c=0,d=e.length,p=e[c];c<d;p=e[++c])u[c]=new t.FPoint(i[h].X+p.X,i[h].Y+p.Y);l.push(u)}else for(h=0;h<a;h++){for(u=new Array(o),c=0,d=e.length,p=e[c];c<d;p=e[++c])u[c]=new t.FPoint(i[h].X-p.X,i[h].Y-p.Y);l.push(u)}var f=new Array;for(h=0;h<a-1+n;h++)for(c=0;c<o;c++){var m=new Array;m.push(l[h%a][c%o]),m.push(l[(h+1)%a][c%o]),m.push(l[(h+1)%a][(c+1)%o]),m.push(l[h%a][(c+1)%o]),t.Clipper.Orientation(m)||m.reverse(),f.push(m)}return f}static MinkowskiSum(e,i,s){if(i[0]instanceof Array){let l=i;for(var r=[],n=(a=new t.Clipper,0);n<l.length;++n){var o=t.Clipper.Minkowski(e,l[n],!0,s);if(a.AddPaths(o,0,!0),s){let i=t.Clipper.TranslatePath(l[n],e[0]);a.AddPath(i,1,!0)}}return a.Execute(1,r,1,1),r}{let r=i,n=t.Clipper.Minkowski(e,r,!0,s);var a;return(a=new t.Clipper).AddPaths(n,0,!0),a.Execute(1,n,1,1),n}}static TranslatePath(e,i){for(var s=[],r=0;r<e.length;r++)s.push(new t.FPoint(e[r].X+i.X,e[r].Y+i.Y));return s}static MinkowskiDiff(e,i){var s=t.Clipper.Minkowski(e,i,!1,!0),r=new t.Clipper;return r.AddPaths(s,0,!0),r.Execute(1,s,1,1),s}static PolyTreeToPaths(e){var i=new Array;return t.Clipper.AddPolyNodeToPaths(e,0,i),i}static AddPolyNodeToPaths(e,i,s){var r=!0;switch(i){case 1:return;case 2:r=!e.IsOpen}e.m_polygon.length>0&&r&&s.push(e.m_polygon);for(var n=0,o=e.Children(),a=o.length,l=o[n];n<a;l=o[++n])t.Clipper.AddPolyNodeToPaths(l,i,s)}static OpenPathsFromPolyTree(t){for(var e=[],i=0,s=t.ChildCount();i<s;i++)t.Children()[i].IsOpen&&e.push(t.Children()[i].m_polygon);return e}static ClosedPathsFromPolyTree(e){var i=[];return t.Clipper.AddPolyNodeToPaths(e,2,i),i}}W(c,"ioReverseSolution",1),W(c,"ioStrictlySimple",2),W(c,"ioPreserveCollinear",4),t.Clipper=c;class d{constructor(e,i){W(this,"m_destPolys",[]),W(this,"m_srcPoly",[]),W(this,"m_destPoly",[]),W(this,"m_normals",new Array),W(this,"m_delta",0),W(this,"m_sinA",0),W(this,"m_sin",0),W(this,"m_cos",0),W(this,"m_miterLim",0),W(this,"m_StepsPerRad",0),W(this,"m_lowest",new t.FPoint),W(this,"m_polyNodes",new t.PolyNode),W(this,"MiterLimit"),W(this,"ArcTolerance"),void 0===e&&(e=2),void 0===i&&(i=t.ClipperOffset.def_arc_tolerance),this.MiterLimit=e,this.ArcTolerance=i,this.m_lowest.X=-1}Clear(){t.Clear(this.m_polyNodes.Children()),this.m_lowest.X=-1}AddPath(e,i,s){var r=e.length-1;if(!(r<0)){var n=new t.PolyNode;if(n.m_jointype=i,n.m_endtype=s,3===s||4===s)for(;r>0&&t.FPoint.op_Equality(e[0],e[r]);)r--;n.m_polygon.push(e[0]);for(var o=0,a=0,l=1;l<=r;l++)t.FPoint.op_Inequality(n.m_polygon[o],e[l])&&(o++,n.m_polygon.push(e[l]),(e[l].Y>n.m_polygon[a].Y||e[l].Y===n.m_polygon[a].Y&&e[l].X<n.m_polygon[a].X)&&(a=o));if(!(4===s&&o<2)&&(this.m_polyNodes.AddChild(n),4===s))if(this.m_lowest.X<0)this.m_lowest=new t.FPoint(this.m_polyNodes.ChildCount()-1,a);else{var h=this.m_polyNodes.Children()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(n.m_polygon[a].Y>h.Y||n.m_polygon[a].Y===h.Y&&n.m_polygon[a].X<h.X)&&(this.m_lowest=new t.FPoint(this.m_polyNodes.ChildCount()-1,a))}}}AddPaths(t,e,i){for(var s=0,r=t.length;s<r;s++)this.AddPath(t[s],e,i)}FixOrientations(){if(this.m_lowest.X>=0&&!t.Clipper.Orientation(this.m_polyNodes.Children()[this.m_lowest.X].m_polygon))for(var e=0;e<this.m_polyNodes.ChildCount();e++){(4===(i=this.m_polyNodes.Children()[e]).m_endtype||3===i.m_endtype&&t.Clipper.Orientation(i.m_polygon))&&i.m_polygon.reverse()}else for(e=0;e<this.m_polyNodes.ChildCount();e++){var i;3!==(i=this.m_polyNodes.Children()[e]).m_endtype||t.Clipper.Orientation(i.m_polygon)||i.m_polygon.reverse()}}static GetUnitNormal(e,i){var s=i.X-e.X,r=i.Y-e.Y;if(0===s&&0===r)return new t.FPoint(0,0);var n=1/Math.sqrt(s*s+r*r);return s*=n,r*=n,new t.FPoint(r,-s)}DoOffset(e){if(this.m_destPolys=new Array,this.m_delta=e,t.ClipperBase.near_zero(e))for(var i=0;i<this.m_polyNodes.ChildCount();i++){4===(n=this.m_polyNodes.Children()[i]).m_endtype&&this.m_destPolys.push(n.m_polygon)}else{var s;this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5,s=this.ArcTolerance<=0?t.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(e)*t.ClipperOffset.def_arc_tolerance?Math.abs(e)*t.ClipperOffset.def_arc_tolerance:this.ArcTolerance;var r=3.14159265358979/Math.acos(1-s/Math.abs(e));this.m_sin=Math.sin(t.ClipperOffset.two_pi/r),this.m_cos=Math.cos(t.ClipperOffset.two_pi/r),this.m_StepsPerRad=r/t.ClipperOffset.two_pi,e<0&&(this.m_sin=-this.m_sin);for(i=0;i<this.m_polyNodes.ChildCount();i++){var n=this.m_polyNodes.Children()[i];this.m_srcPoly=n.m_polygon;var o=this.m_srcPoly.length;if(!(0===o||e<=0&&(o<3||4!==n.m_endtype)))if(this.m_destPoly=new Array,1!==o){this.m_normals.length=0;for(d=0;d<o-1;d++)this.m_normals.push(t.ClipperOffset.GetUnitNormal(this.m_srcPoly[d],this.m_srcPoly[d+1]));if(3===n.m_endtype||4===n.m_endtype?this.m_normals.push(t.ClipperOffset.GetUnitNormal(this.m_srcPoly[o-1],this.m_srcPoly[0])):this.m_normals.push(new t.FPoint(this.m_normals[o-2])),4===n.m_endtype){var a=o-1;for(d=0;d<o;d++)a=this.OffsetPoint(d,a,n.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(3===n.m_endtype){for(a=o-1,d=0;d<o;d++)a=this.OffsetPoint(d,a,n.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;var l=this.m_normals[o-1];for(d=o-1;d>0;d--)this.m_normals[d]=new t.FPoint(-this.m_normals[d-1].X,-this.m_normals[d-1].Y);this.m_normals[0]=new t.FPoint(-l.X,-l.Y),a=0;for(d=o-1;d>=0;d--)a=this.OffsetPoint(d,a,n.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{var h;for(a=0,d=1;d<o-1;++d)a=this.OffsetPoint(d,a,n.m_jointype);if(2===n.m_endtype){d=o-1;h=new t.FPoint(this.m_srcPoly[d].X+this.m_normals[d].X*e,this.m_srcPoly[d].Y+this.m_normals[d].Y*e),this.m_destPoly.push(h),h=new t.FPoint(this.m_srcPoly[d].X-this.m_normals[d].X*e,this.m_srcPoly[d].Y-this.m_normals[d].Y*e),this.m_destPoly.push(h)}else{d=o-1;a=o-2,this.m_sinA=0,this.m_normals[d]=new t.FPoint(-this.m_normals[d].X,-this.m_normals[d].Y),0===n.m_endtype?this.DoSquare(d,a):this.DoRound(d,a)}for(d=o-1;d>0;d--)this.m_normals[d]=new t.FPoint(-this.m_normals[d-1].X,-this.m_normals[d-1].Y);this.m_normals[0]=new t.FPoint(-this.m_normals[1].X,-this.m_normals[1].Y);for(d=(a=o-1)-1;d>0;--d)a=this.OffsetPoint(d,a,n.m_jointype);2===n.m_endtype?(h=new t.FPoint(this.m_srcPoly[0].X-this.m_normals[0].X*e,this.m_srcPoly[0].Y-this.m_normals[0].Y*e),this.m_destPoly.push(h),h=new t.FPoint(this.m_srcPoly[0].X+this.m_normals[0].X*e,this.m_srcPoly[0].Y+this.m_normals[0].Y*e),this.m_destPoly.push(h)):(a=1,this.m_sinA=0,0===n.m_endtype?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}else{if(1===n.m_jointype)for(var u=1,c=0,d=1;d<=r;d++){this.m_destPoly.push(new t.FPoint(this.m_srcPoly[0].X+u*e,this.m_srcPoly[0].Y+c*e));var p=u;u=u*this.m_cos-this.m_sin*c,c=p*this.m_sin+c*this.m_cos}else{u=-1,c=-1;for(var d=0;d<4;++d)this.m_destPoly.push(new t.FPoint(this.m_srcPoly[0].X+u*e,this.m_srcPoly[0].Y+c*e)),u<0?u=1:c<0?c=1:u=-1}this.m_destPolys.push(this.m_destPoly)}}}}Execute(...e){var i=e;if(i[0]instanceof t.PolyTree){o=i[0],a=i[1];if(o.Clear(),this.FixOrientations(),this.DoOffset(a),(n=new t.Clipper(0)).AddPaths(this.m_destPolys,0,!0),a>0)n.Execute(1,o,2,2);else{h=t.Clipper.GetBounds(this.m_destPolys);if((l=[]).push(new t.FPoint(h.left-10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.top-10)),l.push(new t.FPoint(h.left-10,h.top-10)),n.AddPath(l,0,!0),n.ReverseSolution=!0,n.Execute(1,o,3,3),1===o.ChildCount()&&o.Children()[0].ChildCount()>0){var s=o.Children()[0];o.Children()[0]=s.Children()[0],o.Children()[0].m_Parent=o;for(var r=1;r<s.ChildCount();r++)o.AddChild(s.Children()[r])}else o.Clear()}}else{var n,o=i[0],a=i[1];if(t.Clear(o),this.FixOrientations(),this.DoOffset(a),(n=new t.Clipper(0)).AddPaths(this.m_destPolys,0,!0),a>0)n.Execute(1,o,2,2);else{var l,h=t.Clipper.GetBounds(this.m_destPolys);(l=[]).push(new t.FPoint(h.left-10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.top-10)),l.push(new t.FPoint(h.left-10,h.top-10)),n.AddPath(l,0,!0),n.ReverseSolution=!0,n.Execute(1,o,3,3),o.length>0&&o.splice(0,1)}}}OffsetPoint(e,i,s){if(this.m_sinA=this.m_normals[i].X*this.m_normals[e].Y-this.m_normals[e].X*this.m_normals[i].Y,0===this.m_sinA)return i;if(this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1),this.m_sinA*this.m_delta<0)this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_normals[i].X*this.m_delta,this.m_srcPoly[e].Y+this.m_normals[i].Y*this.m_delta)),this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e])),this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_normals[e].X*this.m_delta,this.m_srcPoly[e].Y+this.m_normals[e].Y*this.m_delta));else switch(s){case 2:var r=this.m_normals[e].X*this.m_normals[i].X+this.m_normals[e].Y*this.m_normals[i].Y+1;r>=this.m_miterLim?this.DoMiter(e,i,r):this.DoSquare(e,i);break;case 0:this.DoSquare(e,i);break;case 1:this.DoRound(e,i)}return i=e}DoSquare(e,i){var s=Math.tan(Math.atan2(this.m_sinA,this.m_normals[i].X*this.m_normals[e].X+this.m_normals[i].Y*this.m_normals[e].Y)/4);this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_delta*(this.m_normals[i].X-this.m_normals[i].Y*s),this.m_srcPoly[e].Y+this.m_delta*(this.m_normals[i].Y+this.m_normals[i].X*s))),this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_delta*(this.m_normals[e].X+this.m_normals[e].Y*s),this.m_srcPoly[e].Y+this.m_delta*(this.m_normals[e].Y-this.m_normals[e].X*s)))}DoMiter(e,i,s){var r=this.m_delta/s;this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+(this.m_normals[i].X+this.m_normals[e].X)*r,this.m_srcPoly[e].Y+(this.m_normals[i].Y+this.m_normals[e].Y)*r))}DoRound(e,i){for(var s,r=Math.atan2(this.m_sinA,this.m_normals[i].X*this.m_normals[e].X+this.m_normals[i].Y*this.m_normals[e].Y),n=Math.max(Math.round(this.m_StepsPerRad*Math.abs(r)),1),o=this.m_normals[i].X,a=this.m_normals[i].Y,l=0;l<n;++l)this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+o*this.m_delta,this.m_srcPoly[e].Y+a*this.m_delta)),s=o,o=o*this.m_cos-this.m_sin*a,a=s*this.m_sin+a*this.m_cos;this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_normals[e].X*this.m_delta,this.m_srcPoly[e].Y+this.m_normals[e].Y*this.m_delta))}}W(d,"two_pi",6.28318530717959),W(d,"def_arc_tolerance",.25),t.ClipperOffset=d,t.Error=function(e){throw new t.Error(e)}})(G||(G={}));const H=G;function Y(t){let e=st(t),i=H.Clipper.GetBounds(e);return{min:[i.left,-i.bottom],max:[i.right,-i.top]}}function $(t){if(!t.length||!t[0])return[];let e=st(t);if(!e.length)return[];let i=[e[0]],s=e.slice(1),r=new H.Clipper;r.AddPaths(i,H.PolyType.ptSubject,!0),r.AddPaths(s,H.PolyType.ptClip,!0);let n=[];return r.Execute(H.ClipType.ctUnion,n,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),rt(n)}function j(t,e=0,i=[],s=[],r=[]){for(let n of t.m_Children){if(!n.m_polygon.length)continue;let t=e%2!=0,o=rt([n.m_polygon])[0],a={polygon:o,children:[]};i.push(a),t?r.push(o):(r=[o],s.push(r)),j(n,e+1,a.children,s,r)}return s.sort(((t,e)=>Q(t[0])>Q(e[0])?-1:1)),{polyTree:i,polygons:s}}function z(t,e=.1,i,s){if(!t.length||!t[0])return[];void 0===i&&(i=H.EndType.etClosedPolygon),e=e&&"number"==typeof e?e:.1;let r=st(t=s?t:et(t)),n=new H.ClipperOffset(2),o=[];return n.AddPaths(r,H.JoinType.jtMiter,i),n.Execute(o,e),rt(o)}function V(t,e=.1,i=H.EndType.etClosedPolygon){if(!t.length||!t[0])return{polygons:[],polyTree:[]};let s=t.flatMap(st),r=new H.ClipperOffset(2);r.AddPaths(s,H.JoinType.jtMiter,i);let n=new H.PolyTree;return r.Execute(n,e),j(n)}function q(t,e,i){if(!t.length||!t[0])return[];let s=st(t),r=st(e),n=new H.Clipper;n.AddPaths(s,H.PolyType.ptSubject,!i),n.AddPaths(r,H.PolyType.ptClip,!0);let o=[];return new H.PolyTree,n.Execute(H.ClipType.ctDifference,o,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),rt(o)}function J(t,e){if(!t.length||!t[0])return{polygons:[],polyTree:[]};let i=t.flatMap(st),s=e.flatMap(st),r=new H.Clipper;r.AddPaths(i,H.PolyType.ptSubject,!0),r.AddPaths(s,H.PolyType.ptClip,!0);let n=new H.PolyTree;return r.Execute(H.ClipType.ctDifference,n,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),j(n)}function K(t,e,i=[]){let s=new H.FPoint(t[0],-t[1]),r=st([e])[0],n=H.Clipper.PointInPolygon(s,r);for(let o of i){let e=K(t,o);1===e?n=0:-1===e&&(n=-1)}return n}function Z(t){let e=st([t]);return H.Clipper.Area(e[0])}function Q(t){return Math.abs(Z(t))}function tt(t){let e=Math.abs(Z(t[0]));for(let i of t.slice(1))e-=Math.abs(Z(i));return e}function et(t,e=.01){let i=st(t);return rt(H.Clipper.CleanPolygons(i,e))}function it(t,e=.01){return et([t],e)[0]}function st(t=[]){let e=[],i=0;for(let s of t)if(null==s?void 0:s.length){e[i]=[];for(let t=0;t<s.length;t++)e[i][t]={X:s[t][0],Y:-s[t][1]};i++}return e}function rt(t){let e=[];for(let i=0;i<t.length;i++){let s=t[i]||[];e[i]=[];for(let t=0;t<s.length;t++)e[i][t]=[s[t].X,-s[t].Y]}return e}var nt=1e-6,ot="undefined"!=typeof Float32Array?Float32Array:Array;function at(){var t=new ot(16);return ot!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function lt(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function ht(t,e){if(t===e){var i=e[1],s=e[2],r=e[3],n=e[6],o=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=i,t[6]=e[9],t[7]=e[13],t[8]=s,t[9]=n,t[11]=e[14],t[12]=r,t[13]=o,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function ut(t,e){var i=e[0],s=e[1],r=e[2],n=e[3],o=e[4],a=e[5],l=e[6],h=e[7],u=e[8],c=e[9],d=e[10],p=e[11],f=e[12],m=e[13],g=e[14],y=e[15],v=i*a-s*o,x=i*l-r*o,b=i*h-n*o,_=s*l-r*a,w=s*h-n*a,P=r*h-n*l,E=u*m-c*f,T=u*g-d*f,A=u*y-p*f,I=c*g-d*m,S=c*y-p*m,C=d*y-p*g,M=v*C-x*S+b*I+_*A-w*T+P*E;return M?(M=1/M,t[0]=(a*C-l*S+h*I)*M,t[1]=(r*S-s*C-n*I)*M,t[2]=(m*P-g*w+y*_)*M,t[3]=(d*w-c*P-p*_)*M,t[4]=(l*A-o*C-h*T)*M,t[5]=(i*C-r*A+n*T)*M,t[6]=(g*b-f*P-y*x)*M,t[7]=(u*P-d*b+p*x)*M,t[8]=(o*S-a*A+h*E)*M,t[9]=(s*A-i*S-n*E)*M,t[10]=(f*w-m*b+y*v)*M,t[11]=(c*b-u*w-p*v)*M,t[12]=(a*T-o*I-l*E)*M,t[13]=(i*I-s*T+r*E)*M,t[14]=(m*x-f*_-g*v)*M,t[15]=(u*_-c*x+d*v)*M,t):null}function ct(t,e,i){var s=e[0],r=e[1],n=e[2],o=e[3],a=e[4],l=e[5],h=e[6],u=e[7],c=e[8],d=e[9],p=e[10],f=e[11],m=e[12],g=e[13],y=e[14],v=e[15],x=i[0],b=i[1],_=i[2],w=i[3];return t[0]=x*s+b*a+_*c+w*m,t[1]=x*r+b*l+_*d+w*g,t[2]=x*n+b*h+_*p+w*y,t[3]=x*o+b*u+_*f+w*v,x=i[4],b=i[5],_=i[6],w=i[7],t[4]=x*s+b*a+_*c+w*m,t[5]=x*r+b*l+_*d+w*g,t[6]=x*n+b*h+_*p+w*y,t[7]=x*o+b*u+_*f+w*v,x=i[8],b=i[9],_=i[10],w=i[11],t[8]=x*s+b*a+_*c+w*m,t[9]=x*r+b*l+_*d+w*g,t[10]=x*n+b*h+_*p+w*y,t[11]=x*o+b*u+_*f+w*v,x=i[12],b=i[13],_=i[14],w=i[15],t[12]=x*s+b*a+_*c+w*m,t[13]=x*r+b*l+_*d+w*g,t[14]=x*n+b*h+_*p+w*y,t[15]=x*o+b*u+_*f+w*v,t}function dt(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function pt(t,e){var i=new ot(3);!function(t,e){var i=e[0],s=e[1],r=e[2],n=e[4],o=e[5],a=e[6],l=e[8],h=e[9],u=e[10];t[0]=Math.hypot(i,s,r),t[1]=Math.hypot(n,o,a),t[2]=Math.hypot(l,h,u)}(i,e);var s=1/i[0],r=1/i[1],n=1/i[2],o=e[0]*s,a=e[1]*r,l=e[2]*n,h=e[4]*s,u=e[5]*r,c=e[6]*n,d=e[8]*s,p=e[9]*r,f=e[10]*n,m=o+u+f,g=0;return m>0?(g=2*Math.sqrt(m+1),t[3]=.25*g,t[0]=(c-p)/g,t[1]=(d-l)/g,t[2]=(a-h)/g):o>u&&o>f?(g=2*Math.sqrt(1+o-u-f),t[3]=(c-p)/g,t[0]=.25*g,t[1]=(a+h)/g,t[2]=(d+l)/g):u>f?(g=2*Math.sqrt(1+u-o-f),t[3]=(d-l)/g,t[0]=(a+h)/g,t[1]=.25*g,t[2]=(c+p)/g):(g=2*Math.sqrt(1+f-o-u),t[3]=(a-h)/g,t[0]=(d+l)/g,t[1]=(c+p)/g,t[2]=.25*g),t}function ft(){var t=new ot(3);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function mt(t){var e=new ot(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function gt(t,e,i){var s=new ot(3);return s[0]=t,s[1]=e,s[2]=i,s}function yt(t,e,i,s){return t[0]=e,t[1]=i,t[2]=s,t}function vt(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t}function xt(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t}function bt(t,e){var i=e[0],s=e[1],r=e[2],n=i*i+s*s+r*r;return n>0&&(n=1/Math.sqrt(n)),t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function _t(t,e,i){var s=e[0],r=e[1],n=e[2],o=i[0],a=i[1],l=i[2];return t[0]=r*l-n*a,t[1]=n*o-s*l,t[2]=s*a-r*o,t}function wt(t,e,i){var s=e[0],r=e[1],n=e[2],o=i[3]*s+i[7]*r+i[11]*n+i[15];return o=o||1,t[0]=(i[0]*s+i[4]*r+i[8]*n+i[12])/o,t[1]=(i[1]*s+i[5]*r+i[9]*n+i[13])/o,t[2]=(i[2]*s+i[6]*r+i[10]*n+i[14])/o,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var Pt=xt;function Et(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function Tt(t,e,i){i*=.5;var s=Math.sin(i);return t[0]=s*e[0],t[1]=s*e[1],t[2]=s*e[2],t[3]=Math.cos(i),t}ft(),function(){var t,e=(t=new ot(4),ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var At;function It(){var t=new ot(2);return ot!=Float32Array&&(t[0]=0,t[1]=0),t}function St(t,e,i){var s=e[0],r=e[1];return t[0]=i[0]*s+i[2]*r+i[4],t[1]=i[1]*s+i[3]*r+i[5],t}ft(),gt(1,0,0),gt(0,1,0),Et(),Et(),At=new ot(9),ot!=Float32Array&&(At[1]=0,At[2]=0,At[3]=0,At[5]=0,At[6]=0,At[7]=0),At[0]=1,At[4]=1,At[8]=1,function(){var t=It()}();var Ct="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Mt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Ot(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})})),i}var Nt={exports:{}};function Lt(t,e,i){i=i||2;var s,r,n,o,a,l,h,u=e&&e.length,c=u?e[0]*i:t.length,d=Rt(t,0,c,i,!0),p=[];if(!d||d.next===d.prev)return p;if(u&&(d=function(t,e,i,s){var r,n,o,a=[];for(r=0,n=e.length;r<n;r++)(o=Rt(t,e[r]*s,r<n-1?e[r+1]*s:t.length,s,!1))===o.next&&(o.steiner=!0),a.push($t(o));for(a.sort(Xt),r=0;r<a.length;r++)i=Wt(a[r],i);return i}(t,e,d,i)),t.length>80*i){s=n=t[0],r=o=t[1];for(var f=i;f<c;f+=i)(a=t[f])<s&&(s=a),(l=t[f+1])<r&&(r=l),a>n&&(n=a),l>o&&(o=l);h=0!==(h=Math.max(n-s,o-r))?32767/h:0}return Bt(d,p,i,s,r,h,0),p}function Rt(t,e,i,s,r){var n,o;if(r===re(t,e,i,s)>0)for(n=e;n<i;n+=s)o=ee(n,t[n],t[n+1],o);else for(n=i-s;n>=e;n-=s)o=ee(n,t[n],t[n+1],o);return o&&qt(o,o.next)&&(ie(o),o=o.next),o}function kt(t,e){if(!t)return t;e||(e=t);var i,s=t;do{if(i=!1,s.steiner||!qt(s,s.next)&&0!==Vt(s.prev,s,s.next))s=s.next;else{if(ie(s),(s=e=s.prev)===s.next)break;i=!0}}while(i||s!==e);return e}function Bt(t,e,i,s,r,n,o){if(t){!o&&n&&function(t,e,i,s){var r=t;do{0===r.z&&(r.z=Yt(r.x,r.y,e,i,s)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){var e,i,s,r,n,o,a,l,h=1;do{for(i=t,t=null,n=null,o=0;i;){for(o++,s=i,a=0,e=0;e<h&&(a++,s=s.nextZ);e++);for(l=h;a>0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(r=i,i=i.nextZ,a--):(r=s,s=s.nextZ,l--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;i=s}n.nextZ=null,h*=2}while(o>1)}(r)}(t,s,r,n);for(var a,l,h=t;t.prev!==t.next;)if(a=t.prev,l=t.next,n?Dt(t,s,r,n):Ft(t))e.push(a.i/i|0),e.push(t.i/i|0),e.push(l.i/i|0),ie(t),t=l.next,h=l.next;else if((t=l)===h){o?1===o?Bt(t=Ut(kt(t),e,i),e,i,s,r,n,2):2===o&&Gt(t,e,i,s,r,n):Bt(kt(t),e,i,s,r,n,1);break}}}function Ft(t){var e=t.prev,i=t,s=t.next;if(Vt(e,i,s)>=0)return!1;for(var r=e.x,n=i.x,o=s.x,a=e.y,l=i.y,h=s.y,u=r<n?r<o?r:o:n<o?n:o,c=a<l?a<h?a:h:l<h?l:h,d=r>n?r>o?r:o:n>o?n:o,p=a>l?a>h?a:h:l>h?l:h,f=s.next;f!==e;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&jt(r,a,n,l,o,h,f.x,f.y)&&Vt(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Dt(t,e,i,s){var r=t.prev,n=t,o=t.next;if(Vt(r,n,o)>=0)return!1;for(var a=r.x,l=n.x,h=o.x,u=r.y,c=n.y,d=o.y,p=a<l?a<h?a:h:l<h?l:h,f=u<c?u<d?u:d:c<d?c:d,m=a>l?a>h?a:h:l>h?l:h,g=u>c?u>d?u:d:c>d?c:d,y=Yt(p,f,e,i,s),v=Yt(m,g,e,i,s),x=t.prevZ,b=t.nextZ;x&&x.z>=y&&b&&b.z<=v;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=g&&x!==r&&x!==o&&jt(a,u,l,c,h,d,x.x,x.y)&&Vt(x.prev,x,x.next)>=0)return!1;if(x=x.prevZ,b.x>=p&&b.x<=m&&b.y>=f&&b.y<=g&&b!==r&&b!==o&&jt(a,u,l,c,h,d,b.x,b.y)&&Vt(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;x&&x.z>=y;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=g&&x!==r&&x!==o&&jt(a,u,l,c,h,d,x.x,x.y)&&Vt(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;b&&b.z<=v;){if(b.x>=p&&b.x<=m&&b.y>=f&&b.y<=g&&b!==r&&b!==o&&jt(a,u,l,c,h,d,b.x,b.y)&&Vt(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Ut(t,e,i){var s=t;do{var r=s.prev,n=s.next.next;!qt(r,n)&&Jt(r,s,s.next,n)&&Qt(r,n)&&Qt(n,r)&&(e.push(r.i/i|0),e.push(s.i/i|0),e.push(n.i/i|0),ie(s),ie(s.next),s=t=n),s=s.next}while(s!==t);return kt(s)}function Gt(t,e,i,s,r,n){var o=t;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&zt(o,a)){var l=te(o,a);return o=kt(o,o.next),l=kt(l,l.next),Bt(o,e,i,s,r,n,0),void Bt(l,e,i,s,r,n,0)}a=a.next}o=o.next}while(o!==t)}function Xt(t,e){return t.x-e.x}function Wt(t,e){var i=function(t,e){var i,s=e,r=t.x,n=t.y,o=-1/0;do{if(n<=s.y&&n>=s.next.y&&s.next.y!==s.y){var a=s.x+(n-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=r&&a>o&&(o=a,i=s.x<s.next.x?s:s.next,a===r))return i}s=s.next}while(s!==e);if(!i)return null;var l,h=i,u=i.x,c=i.y,d=1/0;s=i;do{r>=s.x&&s.x>=u&&r!==s.x&&jt(n<c?r:o,n,u,c,n<c?o:r,n,s.x,s.y)&&(l=Math.abs(n-s.y)/(r-s.x),Qt(s,t)&&(l<d||l===d&&(s.x>i.x||s.x===i.x&&Ht(i,s)))&&(i=s,d=l)),s=s.next}while(s!==h);return i}(t,e);if(!i)return e;var s=te(i,t);return kt(s,s.next),kt(i,i.next)}function Ht(t,e){return Vt(t.prev,t,e.prev)<0&&Vt(e.next,t,t.next)<0}function Yt(t,e,i,s,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-i)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-s)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function $t(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function jt(t,e,i,s,r,n,o,a){return(r-o)*(e-a)>=(t-o)*(n-a)&&(t-o)*(s-a)>=(i-o)*(e-a)&&(i-o)*(n-a)>=(r-o)*(s-a)}function zt(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&Jt(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(Qt(t,e)&&Qt(e,t)&&function(t,e){var i=t,s=!1,r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==t);return s}(t,e)&&(Vt(t.prev,t,e.prev)||Vt(t,e.prev,e))||qt(t,e)&&Vt(t.prev,t,t.next)>0&&Vt(e.prev,e,e.next)>0)}function Vt(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function qt(t,e){return t.x===e.x&&t.y===e.y}function Jt(t,e,i,s){var r=Zt(Vt(t,e,i)),n=Zt(Vt(t,e,s)),o=Zt(Vt(i,s,t)),a=Zt(Vt(i,s,e));return r!==n&&o!==a||(!(0!==r||!Kt(t,i,e))||(!(0!==n||!Kt(t,s,e))||(!(0!==o||!Kt(i,t,s))||!(0!==a||!Kt(i,e,s)))))}function Kt(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function Zt(t){return t>0?1:t<0?-1:0}function Qt(t,e){return Vt(t.prev,t,t.next)<0?Vt(t,e,t.next)>=0&&Vt(t,t.prev,e)>=0:Vt(t,e,t.prev)<0||Vt(t,t.next,e)<0}function te(t,e){var i=new se(t.i,t.x,t.y),s=new se(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function ee(t,e,i,s){var r=new se(t,e,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function ie(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function se(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function re(t,e,i,s){for(var r=0,n=e,o=i-s;n<i;n+=s)r+=(t[o]-t[n])*(t[n+1]+t[o+1]),o=n;return r}Nt.exports=Lt,Nt.exports.default=Lt,Lt.deviation=function(t,e,i,s){var r=e&&e.length,n=r?e[0]*i:t.length,o=Math.abs(re(t,0,n,i));if(r)for(var a=0,l=e.length;a<l;a++){var h=e[a]*i,u=a<l-1?e[a+1]*i:t.length;o-=Math.abs(re(t,h,u,i))}var c=0;for(a=0;a<s.length;a+=3){var d=s[a]*i,p=s[a+1]*i,f=s[a+2]*i;c+=Math.abs((t[d]-t[f])*(t[p+1]-t[d+1])-(t[d]-t[p])*(t[f+1]-t[d+1]))}return 0===o&&0===c?0:Math.abs((c-o)/o)},Lt.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},s=0,r=0;r<t.length;r++){for(var n=0;n<t[r].length;n++)for(var o=0;o<e;o++)i.vertices.push(t[r][n][o]);r>0&&(s+=t[r-1].length,i.holes.push(s))}return i};const ne=Mt(Nt.exports);for(var oe,ae=[],le=0;le<256;++le)ae.push((le+256).toString(16).slice(1));var he=new Uint8Array(16);function ue(){if(!oe&&!(oe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oe(he)}const ce={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function de(t,e,i){if(ce.randomUUID&&!e&&!t)return ce.randomUUID();var s=(t=t||{}).random||(t.rng||ue)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,function(t,e=0){return(ae[t[e+0]]+ae[t[e+1]]+ae[t[e+2]]+ae[t[e+3]]+"-"+ae[t[e+4]]+ae[t[e+5]]+"-"+ae[t[e+6]]+ae[t[e+7]]+"-"+ae[t[e+8]]+ae[t[e+9]]+"-"+ae[t[e+10]]+ae[t[e+11]]+ae[t[e+12]]+ae[t[e+13]]+ae[t[e+14]]+ae[t[e+15]]).toLowerCase()}(s)}var pe={exports:{}};function fe(){}fe.prototype={on:function(t,e,i){var s=this.e||(this.e={});return(s[t]||(s[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){var s=this;function r(){s.off(t,r),e.apply(i,arguments)}return r._=e,this.on(t,r,i)},emit:function(t){for(var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),s=0,r=i.length;s<r;s++)i[s].fn.apply(i[s].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),s=i[t],r=[];if(s&&e)for(var n=0,o=s.length;n<o;n++)s[n].fn!==e&&s[n].fn._!==e&&r.push(s[n]);return r.length?i[t]=r:delete i[t],this}},pe.exports=fe;var me,ge,ye=pe.exports.TinyEmitter=fe,ve=t=>{throw TypeError(t)},xe=(t,e,i)=>(((t,e,i)=>{e.has(t)||ve("Cannot "+i)})(t,e,"access private method"),i);let be=new class extends E{error(...t){this.levels.includes("errors")&&(t.length>0&&(t[0]="Internal error: "+t[0]),console.error(...t),this.emit("error",...t))}}(["info","warnings","errors"]);class _e{constructor(t){this.spaceGraph=null,this.type=t}}class we extends _e{constructor(t,e){super(e),this.name="",this.customId="",this.id=t}copyForClone(t){this.name=t.name,this.customId=t.customId}setName(t){this.name=t,this.emit("node-property-change",this,"name")}setCustomId(t){this.customId=t,this.emit("node-property-change",this,"customId")}emit(t,...e){this.spaceGraph&&this.spaceGraph.emit(t,...e)}toJSON(){return{type:this.type,id:this.id,name:""===this.name?void 0:this.name,customId:""===this.customId?void 0:this.customId}}}const Pe="material:color";class Ee extends we{constructor(t,e=[1,1,1],i=1){super(t,Pe),this.color=[...e],this.opacity=i}toJSON(){let t;return t=1===this.opacity?[...this.color]:[this.color[0],this.color[1],this.color[2],this.opacity],{...super.toJSON(),value:t}}}const Te="material:standard";class Ae extends we{constructor(t,e){super(t,Te),this.reference=e}toJSON(){return{...super.toJSON(),reference:this.reference}}}const Ie="material:embedded";class Se extends we{constructor(t,e,i){super(t,Ce),this.reference=e,this.format=i}toJSON(){return be.warn("Embedded material not supported in materials section."),{...super.toJSON(),type:"material:color",value:[1,1,1,1]}}}const Ce="material:basic";class Me extends we{constructor(t){super(t,Ce),this.colorDiffuse=[1,1,1],this.colorSpecular=[1,1,1],this.specularCoefficient=1,this.opacity=1}copyForClone(t){super.copyForClone(t),this.colorDiffuse=[...t.colorDiffuse],this.colorSpecular=[...t.colorSpecular],this.specularCoefficient=t.specularCoefficient,this.opacity=t.opacity}toJSON(){return{...super.toJSON(),colorDiffuse:[...this.colorDiffuse],colorSpecular:[...this.colorSpecular],specularCoefficient:this.specularCoefficient,opacity:this.opacity}}}const Oe="default",Ne=[1,1,1],Le=[1,1,1],Re=1,ke=1,Be=[...Ne,ke];function Fe(t,e){return Number.isFinite(t)?!(t<0||t>1)||(be.warn(`Value out of range (0 to 1) in color literal: '${e}'.`),!1):(be.warn(`Invalid float value in color literal: '${e}'.`),!1)}function De(t,e){return Number.isInteger(t)?!(t<0||t>255)||(be.warn(`Value out of range (0 to 255) in color literal: '${e}'.`),!1):(be.warn(`Invalid byte value in color literal: '${e}'.`),!1)}function Ue(t){if(t.length<3||t.length>4)return be.warn(`Invalid number of components in color literal: '${t}'.`),Be;let e=t.toString(),i=[0,0,0,0];for(let s=0;s<t.length;s++){let r=t[s];if(!Fe(r,e))return Be;i[s]=r}return 3===t.length&&(i[3]=Be[3]),i}function Ge(t){let e,i,s,r,n=t.substring(1),o=parseInt(n,16);if(isNaN(o))return be.warn(`Invalid hexadecimal color literal: '${t}'.`),Be;if(3===n.length?o=o<<4|15:6===n.length&&(o=o<<8|255),3===n.length||4===n.length)e=(o>>12&15)/15,i=(o>>8&15)/15,s=(o>>4&15)/15,r=(15&o)/15;else{if(6!==n.length&&8!==n.length)return be.warn(`Invalid hexademical color literal length: '${t}'.`),Be;e=(o>>24&255)/255,i=(o>>16&255)/255,s=(o>>8&255)/255,r=(255&o)/255}return[e,i,s,r]}function Xe(t,e){if(!t.endsWith(")"))return be.warn(`Missing closing parenthesis: '${t}'.`),Be;let i=e?5:4,s=t.substring(i,t.length-1).split(",");if(s.length<3||s.length>4||3===s.length&&e||4===s.length&&!e)return be.warn(`Invalid number of components in color literal: '${t}'.`),Be;let r=[0,0,0,0];for(let n=0;n<3;n++){let e=s[n],i=parseFloat(e);if(!De(i,t))return Be;r[n]=i/255}if(4===s.length){let e=parseFloat(s[3]);if(!Fe(e,t))return Be;r[3]=e}else r[3]=Be[3];return r}function We([t,e,i]){return"#"+Math.round(255*t).toString(16).padStart(2,"0")+Math.round(255*e).toString(16).padStart(2,"0")+Math.round(255*i).toString(16).padStart(2,"0")}function He({name:t=Oe,color:e=Ne,specularColor:i=Le,specularCoefficient:s=Re,opacity:r=ke,reference:n}={}){return n?{name:t,reference:n}:{name:t,color:[...e],specularColor:[...i],specularCoefficient:s,opacity:r}}function Ye(t,e={}){if(Array.isArray(t)){let[e,i,s,r]=Ue(t);return He({name:t.toString(),color:[e,i,s],opacity:r})}if("string"==typeof t){let i,s,r,n;if(""===t)return be.warn("Empty string not a valid color value."),He({name:t});if(t===Oe)return He();if("#"===t.charAt(0))[i,s,r,n]=Ge(t);else if(t.startsWith("rgb("))[i,s,r,n]=Xe(t,!1);else{if(!t.startsWith("rgba(")){if(t.startsWith("asm:")){let e=t.substring(4,t.length);return He({name:t,reference:e})}if(t.startsWith("data3d:")){let e=t.substring(7,t.length);return He({name:t,reference:e})}{let i=e[t];if(void 0===i)return be.warn(`Unknown material: '${t}'.`),He();{let e;switch(i.type){case Pe:e=He({name:t,color:i.color,specularColor:i.color});break;case Te:e=He({name:t,reference:i.reference});break;case Ie:be.warn("Embedded material not supported in materials section."),e=He();break;case Ce:e=He({name:t,color:i.colorDiffuse,specularColor:i.colorSpecular,specularCoefficient:i.specularCoefficient,opacity:i.opacity});break;default:be.warn(`Unknown material type ${i.type}.`),e=He()}return e}}}[i,s,r,n]=Xe(t,!0)}return He({name:t,color:[i,s,r],opacity:n})}return be.warn(`Material can only be an array or a string: '${t}'.`),He()}const $e="default";function je(t,e){return new Array(e-t).fill(void 0).map(((e,i)=>t+i))}function ze(t,e){let i=new Array(3*e.length),s=0;for(let r=0;r<e.length;r++){let n=3*e[r];i[s++]=t[n],i[s++]=t[n+1],i[s++]=t[n+2]}return i}function Ve(t,e,i){let s=3*e,r=new Array(s*i.length),n=0;for(let o=0;o<i.length;o++){let e=s*i[o];for(let i=0;i<s;i++)r[n++]=t[e++]}return r}function qe(t,e,i){let s=[],r=e.faces,{surfaces:n,materials:o}=function(t){let e=t.surfaces??{[$e]:"all"},i=t.materials??{[$e]:"default"};if(e&&0===Object.keys(e).length)be.warn("Empty 'surfaces' field not allowed.");else if(i&&0===Object.keys(i).length)be.warn("Empty 'materials' field not allowed.");else if(t.material)t.materials?be.warn("Cannot use 'material' and 'materials' at the same time."):i={[$e]:t.material};else if(i[$e])Object.keys(i).length>1&&be.warn("Extraneous material assignments ignored.");else{let t=Object.keys(e);for(let e of t)i[e]||be.warn(`Surface '${e}' not assigned a material, using default.`);let s=Object.keys(i);for(let i of s)e[i]||be.warn(`Surface '${i}' not found.`)}return{surfaces:e,materials:i}}(t);for(let[a,l]of Object.entries(n)){if("all"!==l&&!Array.isArray(l)&&"object"!=typeof l){be.warn(`Unknown face indices type, skipping surface '${a}'.`);continue}let n=[];if("geometry:mesh"===t.type)if("all"===l){let t=e.indices.length/3;n.push(...je(0,t))}else if(Array.isArray(l))n.push(...l);else{let{start:t,end:e}=l;n.push(...je(t,e))}else if("all"===l)for(let t of r){let{index:e,count:i}=t;n.push(...je(e,e+i))}else if(Array.isArray(l))for(let t=0;t<l.length;t++){let e=r[l[t]],{index:i,count:s}=e;n.push(...je(i,i+s))}else{let{start:t,end:e}=l;for(let i=t;i<e;i++){let t=r[i],{index:e,count:s}=t;n.push(...je(e,e+s))}}let h,{vertices:u,indices:c,normals:d,uvs:p}=e;h=o[$e]?o[$e]:o[a]??"default";let f=Ye(h,i),m={name:a,vertices:u,indices:ze(c,n),material:f};d&&(m.normals=Ve(d,3,n)),p&&(m.uvs=Ve(p,2,n)),s.push(m)}return s}function Je(t,e){let i=function(t){if(Array.isArray(t))return[t];if("vector3:list"===t.type)return t.list;if("vector3:range"===t.type){let{start:e,step:i,count:s}=t.range;return function(t,e,i){let s=[];for(let r=0;r<i;r++){let i=t[0]+r*e[0],n=t[1]+r*e[1],o=t[2]+r*e[2];s.push([i,n,o])}return s}(e,i,s)}return be.warn(`Unknown position type: ${t}`),[[0,0,0]]}(t),s=function(t){if("number"==typeof t)return[t];if("number:list"===t.type)return t.list;if("number:range"===t.type){let{start:e,step:i,count:s}=t.range;return function(t,e,i){let s=[];for(let r=0;r<i;r++){let i=t+r*e;s.push(i)}return s}(e,i,s)}return be.warn(`Unknown rotation type: ${t}`),[0]}(e),r=Math.max(i.length,s.length),n=[];for(let o=0;o<r;o++){let t=i[Math.min(o,i.length-1)],e=s[Math.min(o,s.length-1)];n.push({position:t,rotation:e})}return n}function Ke(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Ze(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})})),i}var Qe={exports:{}};function ti(t,e){return t<e?-1:t>e?1:0}const ei=Ze(Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=ti){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:i}=this,s=e[t];for(;t>0;){const r=t-1>>1,n=e[r];if(i(s,n)>=0)break;e[t]=n,t=r}e[t]=s}_down(t){const{data:e,compare:i}=this,s=this.length>>1,r=e[t];for(;t<s;){let s=1+(t<<1),n=e[s];const o=s+1;if(o<this.length&&i(e[o],n)<0&&(s=o,n=e[o]),i(n,r)>=0)break;e[t]=n,t=s}e[t]=r}}},Symbol.toStringTag,{value:"Module"})));var ii;const si=Ke(function(){if(ii)return Qe.exports;ii=1;var t=ei;function e(e,r,n){var o,a,l,h;r=r||1;for(var u=0;u<e[0].length;u++){var c=e[0][u];(!u||c[0]<o)&&(o=c[0]),(!u||c[1]<a)&&(a=c[1]),(!u||c[0]>l)&&(l=c[0]),(!u||c[1]>h)&&(h=c[1])}var d=l-o,p=h-a,f=Math.min(d,p),m=f/2;if(0===f){var g=[o,a];return g.distance=0,g}for(var y=new t(void 0,i),v=o;v<l;v+=f)for(var x=a;x<h;x+=f)y.push(new s(v+m,x+m,m,e));var b=function(t){for(var e=0,i=0,r=0,n=t[0],o=0,a=n.length,l=a-1;o<a;l=o++){var h=n[o],u=n[l],c=h[0]*u[1]-u[0]*h[1];i+=(h[0]+u[0])*c,r+=(h[1]+u[1])*c,e+=3*c}return 0===e?new s(n[0][0],n[0][1],0,t):new s(i/e,r/e,0,t)}(e),_=new s(o+d/2,a+p/2,0,e);_.d>b.d&&(b=_);for(var w=y.length;y.length;){var P=y.pop();P.d>b.d&&(b=P,n&&console.log("found best %d after %d probes",Math.round(1e4*P.d)/1e4,w)),P.max-b.d<=r||(m=P.h/2,y.push(new s(P.x-m,P.y-m,m,e)),y.push(new s(P.x+m,P.y-m,m,e)),y.push(new s(P.x-m,P.y+m,m,e)),y.push(new s(P.x+m,P.y+m,m,e)),w+=4)}n&&(console.log("num probes: "+w),console.log("best distance: "+b.d));var E=[b.x,b.y];return E.distance=b.d,E}function i(t,e){return e.max-t.max}function s(t,e,i,s){this.x=t,this.y=e,this.h=i,this.d=function(t,e,i){for(var s=!1,n=1/0,o=0;o<i.length;o++)for(var a=i[o],l=0,h=a.length,u=h-1;l<h;u=l++){var c=a[l],d=a[u];c[1]>e!=d[1]>e&&t<(d[0]-c[0])*(e-c[1])/(d[1]-c[1])+c[0]&&(s=!s),n=Math.min(n,r(t,e,c,d))}return 0===n?0:(s?1:-1)*Math.sqrt(n)}(t,e,s),this.max=this.d+this.h*Math.SQRT2}function r(t,e,i,s){var r=i[0],n=i[1],o=s[0]-r,a=s[1]-n;if(0!==o||0!==a){var l=((t-r)*o+(e-n)*a)/(o*o+a*a);l>1?(r=s[0],n=s[1]):l>0&&(r+=o*l,n+=a*l)}return(o=t-r)*o+(a=e-n)*a}return t.default&&(t=t.default),Qe.exports=e,Qe.exports.default=e,Qe.exports}());function ri(t,e){return[t[0]+e[0],t[1]+e[1]]}function ni(t){let e;return 0===t[0]?e=t[1]>0?Math.PI/2:t[1]<0?3*Math.PI/2:0:(e=Math.atan2(t[1],t[0]),e<0&&(e+=2*Math.PI)),e}function oi(t,e){return t[0]*e[1]-t[1]*e[0]}function ai(t,e,i){return Math.abs(t[0]-e[0])<i&&Math.abs(t[1]-e[1])<i}function li(t){return Math.sqrt(function(t){return t[0]*t[0]+t[1]*t[1]}(t))}function hi(t,e){return li(fi(e,t))}function ui(t,e,i){return[t[0]+i*(e[0]-t[0]),t[1]+i*(e[1]-t[1])]}function ci(t){let e=li(t);return[t[0]/e,t[1]/e]}function di(t){return[-t[1],t[0]]}function pi(t,e){return[t[0]*e,t[1]*e]}function fi(t,e){return[t[0]-e[0],t[1]-e[1]]}function mi(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function gi(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function yi(t,e,i){return[t[0]+i*(e[0]-t[0]),t[1]+i*(e[1]-t[1]),t[2]+i*(e[2]-t[2])]}function vi(t,e,i){let s=oi(fi(e,t),fi(i,t));return s>1e-7?1:s<-1e-7?-1:0}function xi(t,e){return ni([e[0]-t[0],e[1]-t[1]])}function bi(t,e,i,s){let r=fi(e,t),n=fi(s,i),o=function(t,e){return t[0]*e[0]+t[1]*e[1]}(r,n),a=oi(r,n);return Math.atan2(Math.abs(a),o)}function _i(t,e){let i=!1;const s=t[0],r=t[1];for(let n=0;n<e.length;n++){const t=e[n],o=n===e.length-1?e[0]:e[n+1];if(t[1]<r&&o[1]>=r||o[1]<r&&t[1]>=r){const e=o[0]-t[0],n=o[1]-t[1];Math.abs(n)>=1e-9&&t[0]+(r-t[1])/n*e<s&&(i=!i)}}return i}function wi(t,e){if(!_i(t,e[0]))return!1;for(let i=1;i<e.length;i++){if(_i(t,e[i]))return!1}return!0}function Pi(t,e,i){return function(t,e,i){const s=fi(i,e),r=s[0]*s[0]+s[1]*s[1];let n;if(r<1e-9)n=e;else{const o=((t[0]-e[0])*s[0]+(t[1]-e[1])*s[1])/r;n=o<0?e:o>1?i:ui(e,i,o)}const o=fi(n,t);return o[0]*o[0]+o[1]*o[1]}(t,e,i)**.5}function Ei(t){let e=0;for(let i=0;i<t.length;i++){let s=i,r=i<t.length-1?i+1:0,n=t[s],o=t[r];e+=n[0]*o[1]-o[0]*n[1]}return.5*e}function Ti(t){return Math.abs(Ei(t))}function Ai(t,e=.1){let i;if(function(t){if(0===t.length)return 0;let e=Ti(t[0]);for(let i=1;i<t.length;i++)e-=Ti(t[i]);return e}(t)<.1)i=function(t){const{min:e,max:i}=Y([t]);return[e[0]+(i[0]-e[0])/2,e[1]+(i[1]-e[1])/2]}(t[0]);else{const s=si(t,e);i=[s[0],s[1]]}return i}function Ii(t){return Ei(t)>0}function Si(t,e){return(t%e+e)%e}function Ci(t,e,i){if(0!==t[0]||0!==t[1]||0!==t[2]||0!==e){let s=at(),r=gt(t[0],t[1],t[2]),n=function(t=0,e=[0,1,0]){let i=t*Math.PI/180,s=Et();return Tt(s,e,i),s}(e,i);return function(t,e,i){var s=e[0],r=e[1],n=e[2],o=e[3],a=s+s,l=r+r,h=n+n,u=s*a,c=s*l,d=s*h,p=r*l,f=r*h,m=n*h,g=o*a,y=o*l,v=o*h;t[0]=1-(p+m),t[1]=c+v,t[2]=d-y,t[3]=0,t[4]=c-v,t[5]=1-(u+m),t[6]=f+g,t[7]=0,t[8]=d+y,t[9]=f-g,t[10]=1-(u+p),t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1}(s,n,r),s}return at()}function Mi(t){let e=ft(),i=Et();dt(e,t),pt(i,t);let s=ft(),r=(n=s,o=i,a=2*Math.acos(o[3]),(l=Math.sin(a/2))>nt?(n[0]=o[0]/l,n[1]=o[1]/l,n[2]=o[2]/l):(n[0]=1,n[1]=0,n[2]=0),a);var n,o,a,l;return 0===r&&(s=[0,1,0]),{position:[e[0],e[1],e[2]],rotation:180*r/Math.PI,rotationAxis:[s[0],s[1],s[2]]}}function Oi(t,e){let i=ft();for(let s=0;s<t.length;s+=3)i[0]=t[s],i[1]=t[s+1],i[2]=t[s+2],wt(i,i,e),t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2]}function Ni(t){let e=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=e[0],t[5]=e[1],t}(function(){var t=new ot(6);return ot!=Float32Array&&(t[1]=0,t[2]=0,t[4]=0,t[5]=0),t[0]=1,t[3]=1,t}(),t.position);return function(t,e,i){var s=e[0],r=e[1],n=e[2],o=e[3],a=e[4],l=e[5],h=Math.sin(i),u=Math.cos(i);t[0]=s*u+n*h,t[1]=r*u+o*h,t[2]=s*-h+n*u,t[3]=r*-h+o*u,t[4]=a,t[5]=l}(e,e,-t.rotation*Math.PI/180),e}function Li(t,e){return function(t,e){let i=St(It(),t.position,e),s=t.rotation+Math.atan2(-e[1],e[0])*(180/Math.PI);return{position:[i[0],i[1]],rotation:Si(s,360)}}(t,Ni(e))}function Ri(t){let e=Ni(t);return function(t,e){var i=e[0],s=e[1],r=e[2],n=e[3],o=e[4],a=e[5],l=i*n-s*r;l&&(l=1/l,t[0]=n*l,t[1]=-s*l,t[2]=-r*l,t[3]=i*l,t[4]=(r*a-n*o)*l,t[5]=(s*o-i*a)*l)}(e,e),function(t){let e=St(It(),It(),t),i=Math.atan2(-t[1],t[0])*(180/Math.PI);return{position:[e[0],e[1]],rotation:Si(i,360)}}(e)}function ki(t,e){return t.map((t=>{let{position:i}=Li({position:t,rotation:0},e);return i}))}function Bi({position:t=[0,0,0],rotation:e=0,rotationAxis:i=[0,1,0],name:s,vertices:r,indices:n,normals:o,uvs:a,material:l}){let h=Je(t,e),u=[],c=[],d=[],p=[],f=at();for(let g=0;g<h.length;g++){let t=h[g],{position:e,rotation:s}=t,l=Ci(e,s,i),m=r.slice();Oi(m,l);let y=u.length/3;for(const i of m)u.push(i);for(const i of n)c.push(y+i);if(Array.isArray(o)){lt(f,l),f[12]=0,f[13]=0,f[14]=0,ht(f,f),ut(f,f);let t=o.slice();Oi(t,f),d.push(...t)}Array.isArray(a)&&p.push(...a)}let m={name:s,vertices:u,indices:c,material:l};return Array.isArray(o)&&(m.normals=d),Array.isArray(a)&&(m.uvs=p),m}class Fi{constructor(){this.polygons=[]}clone(){const t=new Fi;for(const e of this.polygons)t.polygons.push(e.clone());return t}toPolygons(){return this.polygons}union(t){var e=new Fi.Node(this.clone().polygons),i=new Fi.Node(t.clone().polygons);return e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),Fi.fromPolygons(e.allPolygons())}subtract(t){var e=new Fi.Node(this.polygons),i=new Fi.Node(t.polygons);return e.invert(),e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),e.invert(),Fi.fromPolygons(e.allPolygons())}intersect(t){var e=new Fi.Node(this.clone().polygons),i=new Fi.Node(t.clone().polygons);return e.invert(),i.clipTo(e),i.invert(),e.clipTo(i),i.clipTo(e),e.build(i.allPolygons()),e.invert(),Fi.fromPolygons(e.allPolygons())}inverse(){var t=this.clone();return t.polygons.forEach((function(t){t.flip()})),t}}(t=>{function e(t){return[-t[0],-t[1],-t[2]]}function i(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function s(t){const e=function(t){return Math.sqrt(i(t,t))}(t);return[t[0]/e,t[1]/e,t[2]/e]}t.fromPolygons=function(e){var i=new t;return i.polygons=e,i};t.Vertex=class{constructor(t,e){this.pos=t,this.normal=e}clone(){return new t.Vertex([...this.pos],this.normal?[...this.normal]:void 0)}flip(){this.normal&&(this.normal=e(this.normal))}interpolate(e,i){return new t.Vertex(yi(this.pos,e.pos,i),this.normal&&e.normal?yi(this.normal,e.normal,i):void 0)}};const r=class{constructor(t,e){this.normal=t,this.w=e}clone(){return new t.Plane([...this.normal],this.w)}flip(){this.normal=e(this.normal),this.w=-this.w}splitPolygon(e,s,r,n,o){for(var a=0,l=[],h=0;h<e.vertices.length;h++){var u=(v=i(this.normal,e.vertices[h].pos)-this.w)<-t.Plane.EPSILON?2:v>t.Plane.EPSILON?1:0;a|=u,l.push(u)}switch(a){case 0:(i(this.normal,e.plane.normal)>0?s:r).push(e);break;case 1:n.push(e);break;case 2:o.push(e);break;case 3:var c=[],d=[];for(h=0;h<e.vertices.length;h++){var p=(h+1)%e.vertices.length,f=l[h],m=l[p],g=e.vertices[h],y=e.vertices[p];if(2!=f&&c.push(g),1!=f&&d.push(2!=f?g.clone():g),3==(f|m)){var v=(this.w-i(this.normal,g.pos))/i(this.normal,gi(y.pos,g.pos)),x=g.interpolate(y,v);c.push(x),d.push(x.clone())}}c.length>=3&&n.push(new t.Polygon(c,e.shared)),d.length>=3&&o.push(new t.Polygon(d,e.shared))}}};r.EPSILON=1e-5,r.fromPoints=function(e,r,n){var o,a,l=s((o=gi(r,e),a=gi(n,e),[o[1]*a[2]-o[2]*a[1],o[2]*a[0]-o[0]*a[2],o[0]*a[1]-o[1]*a[0]]));return new t.Plane(l,i(l,e))};let n=r;t.Plane=n;t.Polygon=class{constructor(e,i){this.vertices=e,this.shared=i,this.plane=t.Plane.fromPoints(e[0].pos,e[1].pos,e[2].pos)}clone(){const e=[];for(const t of this.vertices)e.push(t.clone());return new t.Polygon(e,this.shared)}flip(){this.vertices.reverse();for(const t of this.vertices)t.flip();this.plane.flip()}};t.Node=class{constructor(t){this.plane=null,this.front=null,this.back=null,this.polygons=[],t&&this.build(t)}clone(){var e=new t.Node;e.plane=this.plane&&this.plane.clone(),e.front=this.front&&this.front.clone(),e.back=this.back&&this.back.clone();for(const t of this.polygons)e.polygons.push(t.clone());return e}invert(){var t;for(let i=0;i<this.polygons.length;i++)this.polygons[i].flip();null==(t=this.plane)||t.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();const e=this.front;this.front=this.back,this.back=e}clipPolygons(t){if(!this.plane)return t.slice();for(var e=[],i=[],s=0;s<t.length;s++)this.plane.splitPolygon(t[s],e,i,e,i);this.front&&(e=this.front.clipPolygons(e)),i=this.back?this.back.clipPolygons(i):[];const r=new Array(e.length+i.length);for(let n=0;n<e.length;n++)r[n]=e[n];for(let n=0;n<i.length;n++)r[e.length+n]=i[n];return r}clipTo(t){this.polygons=t.clipPolygons(this.polygons),this.front&&this.front.clipTo(t),this.back&&this.back.clipTo(t)}allPolygons(t=!0){var e=t?this.polygons.slice():this.polygons;return this.front&&(e=e.concat(this.front.allPolygons(!1))),this.back&&(e=e.concat(this.back.allPolygons(!1))),e}build(e){if(e.length){this.plane||(this.plane=e[0].plane.clone());for(var i=[],s=[],r=0;r<e.length;r++)this.plane.splitPolygon(e[r],this.polygons,this.polygons,i,s);i.length&&(this.front||(this.front=new t.Node),this.front.build(i)),s.length&&(this.back||(this.back=new t.Node),this.back.build(s))}}}})(Fi||(Fi={}));const Di=Fi;function Ui(t,e,i){let s=.5*i,r=[[-s,-s,0],[s,-s,0],[s,s,0],[-s,s,0]],{u:n,v:o,n:a}=function(t){const e=1/Math.sqrt(2);let i=[0,0,0],s=[0,0,0],r=[0,0,0];return bt(r,t),_t(i,Math.abs(r[1])<e?gt(0,1,0):gt(1,0,0),t),_t(s,t,i),bt(i,i),bt(s,s),{u:i,v:s,n:r}}(e),l=t,h=function(t,e,i,s,r,n,o,a,l,h,u,c,d,p,f,m){var g=new ot(16);return g[0]=t,g[1]=e,g[2]=i,g[3]=s,g[4]=r,g[5]=n,g[6]=o,g[7]=a,g[8]=l,g[9]=h,g[10]=u,g[11]=c,g[12]=d,g[13]=p,g[14]=f,g[15]=m,g}(n[0],n[1],n[2],0,o[0],o[1],o[2],0,a[0],a[1],a[2],0,l[0],l[1],l[2],1);for(let u of r)wt(u,u,h);return r}function Gi(t,e){const i=[],s=t.nextId++,{name:r,vertices:n,indices:o,material:a}=e;for(let l=0;l<o.length;l+=3){const t=3*o[l],e=3*o[l+1],h=3*o[l+2],u=[n[t],n[t+1],n[t+2]],c=[n[e],n[e+1],n[e+2]],d=[n[h],n[h+1],n[h+2]],p=[new Di.Vertex(u),new Di.Vertex(c),new Di.Vertex(d)];i.push(new Di.Polygon(p,{id:s,name:r,material:a}))}return i}function Xi(){let t=Math.random(),e=Math.random(),i=Math.random();return He({name:We([t,e,i]),color:[t,e,i],opacity:1})}function Wi(t,e){const i=[],s=[],r={};for(let n=0;n<e.length;n++){const o=3*e[n],a=t[o],l=t[o+1],h=t[o+2],u=73856093*a^19349663*l^83492791*h;let c=r[u];void 0===c&&(c=i.push(a,l,h)/3-1,r[u]=c),s.push(c)}return{vertices:i,indices:s}}function Hi(t,e){const i=[];for(const s of e){const e=Gi(t,s);for(const t of e)i.push(t)}return Di.fromPolygons(i)}function Yi(t,{debugMode:e=!1,sharedVertices:i=!0}={}){const s={},{polygons:r}=t;for(let n=0;n<r.length;n++){const t=r[n],i=t.vertices.length;if(i<3){be.warn(`Skipping CSG polygon with '${i}' '${1===i?"vertex":"vertices"}.`);continue}const o=[];o.length=3*i;for(let e=0;e<i;e++){const i=t.vertices[e];o[3*e]=i.pos[0],o[3*e+1]=i.pos[1],o[3*e+2]=i.pos[2]}let a;if(3===i)a=[0,1,2];else{a=[];for(let t=1;t<i-1;t++)a.push(0,t,t+1)}if(e){const t=Xi();s[n]={name:t.name,vertices:o,indices:a,material:t}}else{const{id:e,name:i,material:r}=t.shared,n=s[e];if(n){const t=n.vertices.length;n.vertices.length=t+o.length;for(let s=0;s<o.length;s++)n.vertices[t+s]=o[s];const e=n.indices.length;n.indices.length=e+a.length;const i=t/3;for(let s=0;s<a.length;s++)n.indices[e+s]=a[s]+i}else s[e]={name:i,vertices:o,indices:a,material:r}}}if(i)for(const n of Object.values(s)){const{vertices:t,indices:e}=n,i=Wi(t,e);n.vertices=i.vertices,n.indices=i.indices}return Object.values(s)}function $i(t,e,i,s){let r,n,o,a,l;if("string"==typeof t){if(r=t,l=e[r],!l)return be.warn(`Geometry '${r}' not found.`),[];n=[0,0,0],o=0,a=[0,1,0]}else{let i=t;if("string"==typeof i.geometry){if(r=i.geometry,l=e[r],!l)return be.warn(`Geometry '${r}' not found.`),[]}else l=i.geometry;n=i.position??[0,0,0],o=i.rotation??0,a=i.rotationAxis??[0,1,0]}if(s.indexOf(l)>-1)return be.warn(`Cycle detected while resolving geometry '${l.id}'.`),[];let h=cs(l,e,i,s);"string"!=typeof t&&"csg:clip"!==t.type&&function(t,e,i,s){let r;if(t.material?t.materials?be.warn("Cannot use 'material' and 'materials' at the same time."):r={[$e]:t.material}:t.materials&&(0===Object.keys(t.materials).length?be.warn("Empty 'materials' field not allowed."):r=t.materials),r)if(r[$e]){let t=Ye(r[$e],i);for(let i of e)i.material=t;Object.keys(r).length>1&&be.warn(`Extraneous material assignments to '${s}' ignored.`)}else for(let[n,o]of Object.entries(r)){let t=e.find((t=>t.name===n));if(t){let e=Ye(o,i);t.material=e}else be.warn(`Surface '${n}' not found in geometry '${s}', skipping material assignment.`)}}(t,h,i,l.id);let u=[];for(let c of h){let{name:t,vertices:e,indices:i,normals:s,uvs:r,material:l}=c,h=Bi({position:n,rotation:o,rotationAxis:a,name:t,vertices:e,indices:i,normals:s,uvs:r,material:l});u.push(h)}return u}function ji(t,e,i,s,r){return[...t,...$i(e,i,s,r)]}function zi(t,e,i,s){let{plane:r,material:n}=i,o=Hi(t,e);{let e=function(t,e,i,s,r=100){let n=t.nextId++,{position:o,normal:a}=e,l=Ye(i,s),h=[0,0,0],u=[0,0,0];bt(h,a),function(t,e,i,s){t[0]=e[0]+i[0]*s,t[1]=e[1]+i[1]*s,t[2]=e[2]+i[2]*s}(u,o,h,r);let c=Ui(o,h,r),d=Ui(u,h,r),p=c.concat(d),f=[[0,1,2,3],[4,5,6,7],[0,4,5,1],[1,5,6,2],[2,6,7,3],[3,7,4,0]],m=[];for(let g of f){let t=[];for(let i of g)t.push(new Di.Vertex(p[i]));let e=new Di.Polygon(t,{id:n,name:"",material:l});m.push(e)}return Di.fromPolygons(m)}(t,r,n,s);o.polygons.length>0&&(o=o.subtract(e))}return Yi(o,{debugMode:!1})}function Vi(t,e,i,s,r,n){const o=$i(i,s,r,n),a=Hi(t,e),l=Hi(t,o);let h=[];if(a.polygons.length&&l.polygons.length){let t;switch(i.type){case"csg:subtract":t=a.subtract(l);break;case"csg:union":t=a.union(l);break;case"csg:intersect":t=a.intersect(l);break;default:t=a}h=Yi(t,{debugMode:!1})}return h}function qi(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function Ji(t,e,i){t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2]}function Ki(t,e){let i=new Array(3*e.length),s=ft(),r=ft(),n=ft(),o=ft(),a=ft(),l=ft(),h=0;for(let u=0;u<e.length;u+=3){let c=e[u],d=e[u+1],p=e[u+2];qi(t,s,3*c),qi(t,r,3*d),qi(t,n,3*p),Pt(o,r,s),Pt(a,n,s),_t(l,o,a),bt(l,l),Ji(i,l,h+0),Ji(i,l,h+3),Ji(i,l,h+6),h+=9}return i}function Zi(t,e){let i=new Array(3*e.length),s=ft(),r=ft(),n=ft(),o=ft(),a=ft(),l=ft(),h=e.length/3,u=new Array(h),c=0;for(let f=0;f<e.length;f+=3){let i=e[f],h=e[f+1],d=e[f+2];qi(t,s,3*i),qi(t,r,3*h),qi(t,n,3*d),Pt(o,r,s),Pt(a,n,s),_t(l,o,a),bt(l,l),u[c++]={index1:i,index2:h,index3:d,normal1:mt(l),normal2:mt(l),normal3:mt(l)}}let d=[];for(let f=0;f<t.length;f++)d[f]={normals:[],normal:ft()};for(let f=0;f<u.length;f++){let t=u[f],{index1:e,index2:i,index3:s}=t;d[e].normals.push(t.normal1),d[i].normals.push(t.normal2),d[s].normals.push(t.normal3)}for(let f=0;f<d.length;f++){let t=d[f],e=t.normals.length;if(e>0){let i=t.normal;yt(i,0,0,0);for(let s=0;s<e;s++)vt(i,i,t.normals[s]);bt(i,i)}}let p=0;for(let f=0;f<e.length;f+=3){let t=e[f],s=e[f+1],r=e[f+2],n=d[t].normal,o=d[s].normal,a=d[r].normal;Ji(i,n,p+0),Ji(i,o,p+3),Ji(i,a,p+6),p+=9}return i}function Qi(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function ts(t,e){let i=new Array(2*e.length),s=ft(),r=ft(),n=ft(),o=ft(),a=ft(),l=ft(),h=0;for(let u=0;u<e.length;u+=3){let c,d,p=e[u],f=e[u+1],m=e[u+2];Qi(t,s,3*p),Qi(t,r,3*f),Qi(t,n,3*m),Pt(o,r,s),Pt(a,n,s),_t(l,o,a),bt(l,l),l[0]=Math.abs(l[0]),l[1]=Math.abs(l[1]),l[2]=Math.abs(l[2]),l[0]>=l[1]&&l[0]>=l[2]?(c=2,d=1):l[1]>=l[0]&&l[1]>=l[2]?(c=0,d=2):(c=0,d=1),i[h++]=s[c],i[h++]=s[d],i[h++]=r[c],i[h++]=r[d],i[h++]=n[c],i[h++]=n[d]}return i}function es(t,e){let i=new Array(2*e.length),s=0;for(let r=0;r<e.length;r++){let n=3*e[r],o=t[n],a=t[n+1],l=t[n+2],h=.5+Math.atan2(o,l)/(2*Math.PI),u=.5+Math.asin(a)/Math.PI;i[s++]=h,i[s++]=u}return i}function is(t,e,i){let s=Math.cos(e),r=Math.sin(e);return[t*r*Math.cos(i),t*s,t*r*Math.sin(i)]}const ss=48,rs=12;function ns(t,e){return[e*Math.cos(t),-e*Math.sin(t)]}function os(t,e,i,s=!0){let r=[],n=e-t,o=function(t,e){let i=Math.ceil(ss/(2*Math.PI)*t*e);const s=Math.ceil(rs/(2*Math.PI)*t);return Math.max(s,i)}(Math.abs(n),i),a=n/o;for(let l=0;l<o;l++){let e=ns(t+l*a,i);r.push(e)}if(s){let t=ns(e,i);r.push(t)}return r}function as(t){let e=[];switch(t.type){case"curve:line":e.push(t.start,t.end);break;case"curve:arc":e=os(Math.PI*t.startAngle/180,Math.PI*t.endAngle/180,t.radius);break;case"curve:polyline":e=t.points}return e}function ls(t){let e=[],i=[],s=[];switch(t.type){case"curve:circle":e=os(0,2*Math.PI,t.radius,!1),i.push({index:0,count:e.length});break;case"curve:polygon":e=t.points;for(let t=0;t<e.length;t++)i.push({index:t,count:1});break;case"curve:polygonWithHoles":e=t.polygons[0];for(let t=0;t<e.length;t++)i.push({index:t,count:1});const r=t.polygons.slice(1);if(r.length>=1){const t=r.length>1?$(r):r;for(let e of t)s.push(ls({type:"curve:polygon",points:e}))}break;case"curve:rectangle":let{dimensions:n}=t,o=n[0],a=n[1];e=[[0,0],[0,a],[o,a],[o,0]];for(let t=0;t<e.length;t++)i.push({index:t,count:1});break;case"curve:composite":const l=1e-7;let h,u,c=t.segments;for(let t=0;t<c.length;t++){let s=as(c[t]),r=s[0],n=s[s.length-1];0===t||ai(r,u,l)||be.warn(`Composite curve segments ${t} and ${t+1} are not continuous.`),0===t&&(h=r),u=n,i.push({index:e.length,count:s.length-1}),e.push(...s.slice(0,s.length-1))}c.length>0&&!ai(u,h,l)&&be.warn("Composite curve not closed.")}return{points:e,segmentRanges:i,holes:s}}function hs(t,e,i){let s,r=i.holes??[],n=i.y??0,o=i.flipSide??!1,a=t,l=[];if(8===a.length&&0===r.length){s=(e?o:!o)?[3,0,1,1,2,3]:[1,0,3,3,2,1]}else{if(r.length>0){let t=new Array(r.length);for(let e=0;e<r.length;e++)t[e]=a.length/2,a=a.concat(r[e]);s=ne(a,t)}else s=ne(a);if(!o)for(let t=0;t<s.length;t+=3){let e=s[t];s[t]=s[t+2],s[t+2]=e}}let h=0;for(let u=0;u<a.length;u+=2)l[h++]=a[u],l[h++]=n,l[h++]=a[u+1];return{vertices:l,indices:s}}function us(t,e,i=0,s=!1){let r=new Array(2*t*3),n=0;for(let o=0;o<t;o++){o===t-1?s?(r[n++]=o+i,r[n++]=i,r[n++]=e+i,r[n++]=o+i,r[n++]=e+i,r[n++]=o+e+i):(r[n++]=e+i,r[n++]=i,r[n++]=o+i,r[n++]=o+e+i,r[n++]=e+i,r[n++]=o+i):s?(r[n++]=o+i,r[n++]=o+1+i,r[n++]=o+e+1+i,r[n++]=o+i,r[n++]=o+e+1+i,r[n++]=o+e+i):(r[n++]=o+e+1+i,r[n++]=o+1+i,r[n++]=o+i,r[n++]=o+e+i,r[n++]=o+e+1+i,r[n++]=o+i)}return r}function cs(t,e,i,s=[]){var r;let n,o=[];switch(t.type){case"geometry:plane":n=function(t){let{normal:e,size:i,doubleSided:s}=t,r=Ui([0,0,0],e,i).flat(),n=[0,1,2,0,2,3],o=[{index:0,count:2}];return s&&(n=n.concat([0,2,1,0,3,2]),o.push({index:2,count:2})),{vertices:r,indices:n,faces:o}}(t);break;case"geometry:cuboid":n=function(t){let{dimensions:e}=t,i=e[0],s=e[1],r=e[2],n=[0,s,r,i,s,r,i,s,0,0,s,0,0,0,r,i,0,r,i,0,0,0,0,0],o=[];for(let a=0;a<6;a++)o.push({index:2*a,count:2});return{vertices:n,indices:[0,1,2,0,2,3,4,7,6,4,6,5,0,4,5,0,5,1,1,5,6,1,6,2,2,6,7,2,7,3,3,7,4,3,4,0],faces:o}}(t);break;case"geometry:sphere":n=function(t){const e=16,i=16;let s,r,n=t.radius,o=[],a=[],l="generator"===t.uvs?[]:void 0;o.push(0,n,0);for(let u=1;u<i;u++){let t=Math.PI*u/i;for(let i=0;i<e;i++){let s=is(n,t,2*Math.PI*i/e);o.push(s[0],s[1],s[2])}}let h=o.push(0,-n,0)/3-1;s=1,r=.9375;for(let u=0;u<e;u++){let t=1+u,i=1+(u+1)%e;if(a.push(0,i,t),l){let t=1-u/e,i=1-(u+1)/e,n=.5*(t+i);l.push(n,s,i,r,t,r)}}for(let u=0;u<14;u++)for(let t=0;t<e;t++){let s=1+u*e+t,r=1+u*e+(t+1)%e,n=1+(u+1)*e+(t+1)%e,o=1+(u+1)*e+t;if(a.push(s,r,n),a.push(s,n,o),l){let s=1-t/e,r=1-(u+1)/i,n=1-(t+1)/e,o=1-(u+2)/i;l.push(s,r,n,r,n,o),l.push(s,r,n,o,s,o)}}s=.0625,r=0;for(let u=0;u<e;u++){let t=225+u,i=225+(u+1)%e;if(a.push(t,i,h),l){let t=1-u/e,i=1-(u+1)/e,n=.5*(t+i);l.push(t,s,i,s,n,r)}}return{vertices:o,indices:a,uvs:l,faces:[{index:0,count:a.length/3}]}}(t);break;case"geometry:extrusion":n=function(t){let{profile:e,height:i}=t,s=ls(e),{points:r,segmentRanges:n,holes:o}=s,a=r.flat(),l=[],h=r.length,u=[{points:r,segmentRanges:n}];for(let w of o)l.push(w.points.flat()),u.push(w),h+=w.points.length;let c=Ii(r),d=hs(a,c,{y:i,flipSide:!1,holes:l}),p=hs(a,c,{y:0,flipSide:!0,holes:l}),f=[];f.push(...d.vertices),f.push(...p.vertices);let m=d.indices,g=p.indices.map((t=>t+h)),y=[];y.push(...m),y.push(...g);let v=m.length/3,x=[];x[0]={index:0,count:v},x[1]={index:v,count:v};let b=2*v,_=0;for(let w=0;w<u.length;w++){let{points:t,segmentRanges:e}=u[w],i=0===w?Ii(t):!Ii(t),s=us(t.length,d.vertices.length/3,_,i);_=t.length,y.push(...s);for(let r of e){let t=b+2*r.index,e=2*r.count;x.push({index:t,count:e})}b+=2*t.length}return{vertices:f,indices:y,faces:x}}(t);break;case"geometry:mesh":n=function(t){let{vertices:e,indices:i,normals:s,uvs:r}=t,n={vertices:e,indices:i,faces:[]};return Array.isArray(s)&&(n.normals=s),Array.isArray(r)&&(n.uvs=r),n}(t);break;default:return be.warn(`Invalid geometry type ${t.type}.`),o}o=qe(t,n,i),"geometry:plane"!==t.type&&"geometry:cuboid"!==t.type&&"geometry:sphere"!==t.type&&"geometry:extrusion"!==t.type||(null==(r=t.geometries)?void 0:r.length)&&(s.push(t),o=function(t,e,i,s,r){let n={nextId:0},o=t.geometries??[];for(let a of o)e="string"==typeof a||"reference:geometry"===a.type?ji(e,a,i,s,r):"csg:clip"===a.type?zi(n,e,a,s):Vi(n,e,a,i,s,r);return e}(t,o,e,i,s),s.pop());let a=[];for(let u of o){let{name:e,vertices:i,indices:s,normals:r,uvs:n,material:o}=u,{position:l,rotation:h,rotationAxis:c}=t,d=Bi({position:l,rotation:h,rotationAxis:c,name:e,vertices:i,indices:s,normals:r,uvs:n,material:o});a.push(d)}o=a;let l=t.normals??"flat";if("flat"===l||"smooth"===l)for(let u of o){let{vertices:t,indices:e}=u;u.normals="flat"===l?Ki(t,e):Zi(t,e)}let h=t.uvs??"automatic";if("automatic"==h||"spherical"===h)for(let u of o){let{vertices:t,indices:e}=u;u.uvs="automatic"===h?ts(t,e):es(t,e)}return o}function ds(t){let e,i,s,r={min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]};for(let n=0;n<t.length;n+=3)e=t[n],i=t[n+1],s=t[n+2],r.min[0]=Math.min(r.min[0],e),r.max[0]=Math.max(r.max[0],e),r.min[1]=Math.min(r.min[1],i),r.max[1]=Math.max(r.max[1],i),r.min[2]=Math.min(r.min[2],s),r.max[2]=Math.max(r.max[2],s);return r}class ps{constructor(){this.vertices=[],this.edges=[],this.geometryProfile=[]}toJSON(){return{edges:this.edges.map((t=>t.id))}}}function fs(t,e){return"integer"===e.type?"number"==typeof t&&Number.isInteger(t):typeof t===e.type&&(!("enum"in e)||e.enum.includes(t))}const ms={"spatialStructure:layout":"layout","layout:space":"space","product:static":"product","product:component":"product","spatialStructure:building":"building","spatialStructure:floor":"floor","element:asset":"element","element:beam":"element","element:casework":"element","element:column":"element","element:door":"element","element:kitchen":"element","element:railing":"element","element:ramp":"element","element:roof":"element","element:slab":"element","element:stairs":"element","element:stairFlight":"element","element:window":"element","element:generic":"element","element:floor":"element","element:ceiling":"element","element:boundaryWall":"element","element:curtainWall":"element","element:opening":"element","element:spaceDivider":"element","element:wall":"element"},gs=(t,e)=>{const i=ms[e];return i||be.error(`Missing custom attribute resource type for node type: "${e}"`),`${t}:${i}`};function ys(t,e){if("boolean"===e.type&&"string"==typeof t){if("true"===t.toLowerCase())return!0;if("false"===t.toLowerCase())return!1}if("number"===e.type&&"string"==typeof t){const e=Number(t);if(!isNaN(e))return e}return null}class vs extends we{constructor(t,e){super(t,"customAttribute:definition"),this.attributes={resourceType:"space",schema:{type:"string"}},e&&this.setAttributes(e)}getInputType(){return function(t){switch(t.type){case"integer":return"Integer";case"boolean":return"Boolean";case"number":return"Number";case"string":return"enum"in t?"Select":"Text"}}(this.attributes.schema)}setAttributes(t){let e=this.attributes;e.resourceType=t.resourceType??e.resourceType,e.updatedAt=t.updatedAt??e.updatedAt,e.description=t.description??e.description,e.schema=function(t){return t.schema?JSON.parse(JSON.stringify(t.schema)):"Text"===t.valueType?{type:"string"}:"Number"===t.valueType?{type:"number"}:"Boolean"===t.valueType?{type:"boolean"}:void 0}(t)}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes))}toJSON(){const t=super.toJSON();let e={resourceType:this.attributes.resourceType,schema:JSON.parse(JSON.stringify(this.attributes.schema))};return void 0!==this.attributes.updatedAt&&(e.updatedAt=this.attributes.updatedAt),void 0!==this.attributes.description&&(e.description=this.attributes.description),t.attributes=e,t}}const xs={"customAttribute:definition":vs};class bs extends we{constructor(t,e){super(t,e),this.customAttributes={}}setCustomAttributes(t,e){let i=null,s=!1;if(null===t&&(this.customAttributes={},s=!0),t&&e)for(const r in t){let n=t[r];if(null===n){delete this.customAttributes[r],s=!0;continue}const o=gs(r,this.type),a=e[o];if(a){if(!fs(n,a.attributes.schema)){let t=ys(n,a.attributes.schema);if(null===t){be.error(`Value type mismatch for custom attribute. Received value: "${n}". Expected type: ${a.attributes.schema.type}`),i=`Value type mismatch for custom attribute. Received value: "${n}". Expected type: ${a.attributes.schema.type}`;continue}n=t}this.customAttributes[r]!==n&&(this.customAttributes[r]=n,s=!0)}else i=`Missing custom attribute definition for node key: "${r}", node type: "${this.type}" and definition id: ${o}`}s&&this.emit("node-custom-attributes-change",this),i&&be.error(i)}toJSON(){const t=super.toJSON();return Object.keys(this.customAttributes).length>0&&(t.customAttributes=JSON.parse(JSON.stringify(this.customAttributes))),t}copyForClone(t){super.copyForClone(t),this.customAttributes=JSON.parse(JSON.stringify(t.customAttributes))}}class _s extends bs{constructor(t,e){super(t,e),this.layout=null}}class ws extends _s{}class Ps extends ws{constructor(t,e,i){super(t,"spatialGraph:vertex"),this.position=[0,0],this.edges=[],this.position[0]=e,this.position[1]=i}sortVertexEdges(){let t=[];for(let e of this.edges){let i=this===e.vertices[0]?e.vertices[1]:e.vertices[0],s=ni([i.position[0]-this.position[0],i.position[1]-this.position[1]]);t.push({edge:e,edgeAngle:s})}t.sort(((t,e)=>t.edgeAngle-e.edgeAngle)),this.edges=t.map((t=>t.edge))}addEdge(t){this.edges.push(t),this.sortVertexEdges(),this.emit("vertex-add-edge",this,t)}removeEdge(t){let e=this.edges.indexOf(t);if(e>-1){let t=this.edges.splice(e,1)[0];this.emit("vertex-remove-edge",this,t)}else be.error(`Vertex does not reference edge ${t.id}.`)}setPosition(t,e){this.position[0]=t,this.position[1]=e,this.edges.length>0&&(this.layout.spatialGraph.graphChanged=!0),this.emit("vertex-set-position",this)}toJSON(){return{...super.toJSON(),position:[...this.position]}}}function Es(t,e,i,s,r=!1){if(e.layout)return be.warn(`${s} ${e.id} already part of layout ${e.layout.id}.`),!1;if(i[e.id])return be.error(`${s} ${e.id} already registered in layout.`),!1;let n=t.spaceGraph;if(n&&n.nodesById[e.id])return be.error(`${s} ${e.id} already registered in space graph.`),!1;if(e.type.startsWith("space:")){let t=e;if(t.slabs.length>0)return be.warn(`Detached space ${t.id} references boundary slab elements.`),!1}else if(e.type.startsWith("element:")){let n=e;if(r&&n.parent)return be.warn(`${s} ${n.id} already a child of ${s} ${n.parent.id}.`),!1;for(let e of n.elements)if(!Es(t,e,i,s,!1))return!1}return!0}function Ts(t,e){if(e.layout=t,t.elementsById[e.id])return void be.error(`Element ${e.id} already registered.`);t.elementsById[e.id]=e;const i=t.elementsByType[e.type];i||(be.warn(`unrecognized layout element type: ${e.type}`),t.elementsByType[e.type]=[]),i.push(e);let s=t.spaceGraph;s&&("element:asset"===e.type&&e.product&&!s.productsById[e.product.id]&&s.insertProduct(e.product),s.registerNode(e),s.emit("element-create",e));for(let r of e.elements)Ts(t,r)}function As(t,e,i){for(let o of e.elements)As(t,o,e);if(t.elementsById[e.id]!==e)return void be.error(`Entry ${e.id} in 'elements stored by ID' record does not contain this object.`);delete t.elementsById[e.id];const s=t.elementsByType[e.type],r=null==s?void 0:s.indexOf(e);if(!s||-1===r)return void be.error(`element ${e.id} not found in 'elements stored by type' record.`);s.splice(r,1);let n=t.spaceGraph;n&&(n.unregisterNode(e),n.emit("element-delete",e,i)),e.layout=null}function Is(t){return"object"==typeof t&&null!==t}function Ss(t){return Is(t)&&!function(t){return Array.isArray(t)||ArrayBuffer.isView(t)}(t)}function Cs(t,e,i,s){Ss(t)&&Ss(e)||be.error("Both arguments must be objects.");let{onNewKeys:r,copyScopes:n,cloneObjects:o}=s,a=Object.keys(e);for(let l of a){if(r){let{allow:e,excludedScopes:s}=r;if(e===(!!s&&s.includes(i))&&!(l in t)){be.warn(`Key '${l}' not found in scope ${i}, skipped.`);continue}}let a=e[l],h=t[l];if(Is(a)){let e=`${i}.${l}`;!(null==n?void 0:n.includes(e))&&Ss(h)?Cs(h,a,e,s):t[l]=o?JSON.parse(JSON.stringify(a)):a}else t[l]=a}}function Ms(t,e,i={onNewKeys:{allow:!1,excludedScopes:[]},copyScopes:[],cloneObjects:!0}){let s;i.onNewKeys?(s=i.onNewKeys,s.allow=i.onNewKeys.allow??!1,s.excludedScopes=i.onNewKeys.excludedScopes??[]):s={allow:!1,excludedScopes:[]},Cs(t,e,"",{onNewKeys:s,copyScopes:i.copyScopes??[],cloneObjects:i.cloneObjects??!0})}function Os(t,e){t.name=e.name??t.name,t.customId=e.customId??t.customId}function Ns(t,e,i){t.setCustomAttributes(e.customAttributes,i)}function Ls(t){let e=t.getEdges();return 1===e.length?e[0].id:e.map((t=>t.id))}function Rs(t){let e;switch(t.type){case"element:ceiling":case"element:floor":e=function(t){let e=[];for(let i of t.boundaries){let t=i.toJSON();e.push(t)}return{id:t.id,type:t.type,boundaries:e,parameters:{height:t.parameters.height,elevation:t.parameters.elevation,materials:{...t.parameters.materials}}}}(t);break;case"element:boundaryWall":e=function(t){let e=[];for(let s of t.boundaries){let t=s.toJSON();e.push(t)}let i=JSON.parse(JSON.stringify(t.parameters.surfaces));return{id:t.id,type:t.type,boundaries:e,parameters:{height:t.parameters.height,elevation:t.parameters.elevation,surfaces:i,materials:{...t.parameters.materials}}}}(t);break;case"element:curtainWall":e={id:(n=t).id,type:n.type,edge:Ls(n)};break;case"element:spaceDivider":e={id:(r=t).id,type:r.type,edge:Ls(r)};break;case"element:wall":e=function(t){let{width:e,height:i,offset:s,elevation:r,materials:n}=t.parameters;return{id:t.id,type:t.type,parameters:{width:e,height:i,offset:s,elevation:r,materials:{...n}},edge:Ls(t)}}(t);break;case"element:opening":e=function(t){let{position:e,dimensions:i,materials:s}=t.parameters;return{id:t.id,type:t.type,parameters:{position:[...e],dimensions:[...i],materials:{...s}}}}(t);break;case"element:asset":e={id:(i=t).id,type:i.type,position:[...i.position],rotation:i.rotation,rotationAxis:i.rotationAxis,product:null==(s=i.product)?void 0:s.id,geometries:JSON.parse(JSON.stringify(i.geometries))};break;case"element:beam":case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:kitchen":case"element:railing":case"element:ramp":case"element:roof":case"element:slab":case"element:stairs":case"element:stairFlight":case"element:window":e=function(t){let e={id:t.id,type:t.type,position:[...t.position],parameters:JSON.parse(JSON.stringify(t.parameters)),rotation:t.rotation,rotationAxis:t.rotationAxis};return"element:generic"!==t.type&&"element:asset"!==t.type||(e.geometries=JSON.parse(JSON.stringify(t.geometries))),e}(t);break;default:return void be.warn(`Unknown element type '${t.type}, skipping element.`)}var i,s,r,n,o,a;if(o=e,""!==(a=t).name&&(o.name=a.name),""!==a.customId&&(o.customId=a.customId),function(t,e){e.customAttributes===Object(e.customAttributes)&&Object.keys(e.customAttributes).length>0&&(t.customAttributes=e.customAttributes)}(e,t),t.elements.length){e.elements=[];for(let i of t.elements){let t=Rs(i);t&&e.elements.push(t)}}return e}class ks extends _s{constructor(){super(...arguments),this.parent=null,this.elements=[],this.geometries=[]}insertElement(t){let e=this.layout;e&&!Es(e,t,e.elementsById,"Element",!0)||(t.parent=this,this.elements.push(t),e&&Ts(e,t))}getTransform(){return{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}getWorldTransform(){return this.getTransform()}getBoundingBox(t=!1){return{min:[0,0,0],max:[0,0,0],transform:{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}}getAxisAlignedBoundingBox(t=!1){return function({min:t,max:e,transform:i}){if(0===i.rotation)return{min:mi(t,i.position),max:mi(e,i.position)};{let s=Ci(i.position,i.rotation,i.rotationAxis);const r=[[...t],[...e],[t[0],t[1],e[2]],[e[0],e[1],t[2]]];for(const t of r)wt(t,t,s);return ds(r.flat())}}(this.getBoundingBox(t))}getBoundingBoxContour(t=!1){const{min:[e,,i],max:[s,,r],transform:n}=this.getBoundingBox(t),{position:[o,,a],rotation:l}=n;return ki([[e,i],[s,i],[s,r],[e,r]],{position:[o,a],rotation:l})}get isExternal(){if(this.parent)return this.parent.isExternal;const t=this.getSpaces().flatMap((t=>t?[t]:[]));return!t.length||t[0].isExternal}removeElement(t){if(t.parent!==this)return void be.warn(`Element ${t.id} not a child of element ${this.id}.`);let e=this.elements.indexOf(t);if(-1===e)return void be.error(`Element ${t.id} not found in parent ${this.id}.`);let i=t.parent;t.parent=null,this.elements.splice(e,1),t.layout&&As(t.layout,t,i)}copyForClone(t){super.copyForClone(t),this.parameters=JSON.parse(JSON.stringify(t.parameters)),this.geometries=JSON.parse(JSON.stringify(t.geometries))}setParameters(t){Ms(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("element-parameters-change",this)}getSpaces(){return this.parent?this.parent.getSpaces():[]}toJSON(){return Rs(this)}}function Bs(t,e,i){let s=t.getAxisLength(),r=[];for(let n of t.elements)if("element:opening"===n.type){let t=n.parameters.position[0],o=t/s,a=(t+n.parameters.dimensions[0])/s;i?e>=o&&e<a&&r.push(n):e>o&&e<a&&r.push(n)}return r}class Fs extends ks{constructor(t,e,i){super(t,e),this.edges=[],this.vertices=[],this.edgesChanged=!1,this.setEdges(i)}setEdges(t){var e,i;if(!t.length)return this.edges=[],void(this.vertices=[]);if(1===t.length)return this.edges=[t[0]],void(this.vertices=[t[0].vertices[0],t[0].vertices[1]]);const s=function(t){var e;const i=new Map;for(const s of t)for(const t of s.vertices)i.has(t)||i.set(t,[]),null==(e=i.get(t))||e.push(s);return i}(t),r=[];let n,o;for(const[h,u]of s.entries())if(1===u.length){n=u[0];const t=n.vertices.find((t=>t!==h));if(2!==(null==(e=s.get(t))?void 0:e.length))return void be.error("Edge sequence is not continuous");r.push(h,t),o=t;break}if(!n||!o)return void be.error("Unable to find start of edge sequence");const a=[n];let l=n;for(;a.length<t.length;){const t=o&&(null==(i=s.get(o))?void 0:i.find((t=>t!==l)));if(!t)return void be.error("Edge sequence is not continuous");if(a.includes(t))return void be.error("Duplicate Edge in sequence",t.id,l.id);const e=t.vertices.find((t=>t!==o));r.push(e),a.push(t),o=e,l=t}this.edges=a,this.vertices=r,this.edgesChanged=!1,this.emit("element-edges-change",this)}verifyEdges(){this.edgesChanged&&this.edges.length&&this.setEdges(this.edges)}getEdges(){return[...this.edges]}getVertices(){return this.verifyEdges(),[...this.vertices]}getStartVertex(){return this.verifyEdges(),this.vertices.at(0)}getEndVertex(){return this.verifyEdges(),this.vertices.at(-1)}getAxisPoints(){const t=this.getStartVertex(),e=this.getEndVertex();return t&&e?[t.position,e.position]:[]}getAxisLength(){const[t,e]=this.getAxisPoints();return t&&e?li(fi(t,e)):0}getEdgeAtLinearPosition(t){if(t<0||t>1)return;if(1===this.edges.length)return this.edges[0];let e=this.getAxisLength();if(!e)return;let i=this.vertices[0].position;for(let s=0;s<this.vertices.length-1;s++){if(hi(i,this.vertices[s+1].position)/e>=t)return this.edges[s]}}getEdgesAtLinearSegment(t,e){if(t>e)return[];if(1===this.edges.length)return[this.edges[0]];let i=this.getAxisLength();if(!i)return[];let s=[],r=this.vertices[0].position,n=r;for(let o=0;o<this.vertices.length-1;o++){let a=this.vertices[o+1].position,l=hi(r,n)/i,h=hi(r,a)/i;(t<=l&&e>=h||t>=l&&t<h||e>l&&e<=h)&&s.push(this.edges[o]),n=a}return s}get edge(){return be.warn("Use getEdges() instead of edge"),this.edges[0]||null}getAdjacentElementsByVertex(){let t=[[],[]];for(let e=0;e<this.vertices.length;e++){let i=this.vertices[e].edges.filter((t=>t.element&&t.element.id!==this.id)).map((t=>t.element));t[e]=i}return t}getAdjacentSpacesBySide(){let t=[[],[]];for(let e=0;e<2;e++){let i=this.edges.filter((t=>t.spaces[e])).map((t=>t.spaces[e]));t[e]=i}return t}getSpaces(){let t=[];for(let e of this.edges)e.spaces[0]&&t.push(e.spaces[0]),e.spaces[1]&&t.push(e.spaces[1]);return t}getElementsAtLinearPosition(t){return Bs(this,t,!0)}get isExternal(){let t=0,e=0;for(const i of this.getEdges())i.isExternal?t+=i.getLength():e+=i.getLength();return t>=e}}function Ds(t){for(let e of t.elements)if("element:door"===e.type){let t=e.parameters;t.hingeSide="right"===t.hingeSide?"left":"right",t.doorSide="side1"===t.doorSide?"side2":"side1"}}class Us extends ws{constructor(t,e,i){super(t,"spatialGraph:edge"),this.spaces=[void 0,void 0],this.boundaryWalls=[null,null],this.element=null,this.vertices=[e,i]}getPoints(){return[this.vertices[0].position,this.vertices[1].position]}getLength(){return hi(...this.getPoints())}get isExternal(){return this.spaces.some((t=>!t||t.isExternal))}setVertices(t,e){if(t===e)return void be.warn("Cannot set both edge vertices to the same vertex.");let i,s,r=this.vertices[0],n=this.vertices[1];this.vertices[0]=t,this.vertices[1]=e,r!==t?(r.removeEdge(this),t.addEdge(this),i=!0):i=!1,n!==e?(n.removeEdge(this),e.addEdge(this),s=!0):s=!1,this.layout.spatialGraph.graphChanged=!0,this.element&&(this.element.edgesChanged=!0),(i||s)&&this.emit("edge-set-vertices",this,{previousVertices:[r,n]})}setVerticesByIds(t,e){let i=this.layout.spatialGraph,s=i.verticesById[t];if(!s)return void be.error(`Cannot find vertex ${t}.`);let r=i.verticesById[e];r?this.setVertices(s,r):be.error(`Cannot find vertex ${e}.`)}canSplit(t,e={}){let{minimumLength:i}=e;if(void 0!==i){if(t<0||t>1)return!1;let[e,s]=this.getPoints(),r=ui(e,s,t),n=li(fi(r,e)),o=li(fi(r,s));if(n<i||o<i)return!1}else if(t<=0||t>=1)return!1;if(this.element){let[e,i]=this.getPoints(),s=ui(e,i,t),[r]=this.element.getAxisPoints();if(!r)return!1;let n=this.element.getAxisLength(),o=hi(r,s)/n;return 0===Bs(this.element,o,!1).length}return!0}split(t,e={},i=!1){var s,r,n;let o=this.layout.spatialGraph,a=this.vertices[0],l=this.vertices[1],h=null==(s=this.element)?void 0:s.getAxisLength(),u=null==(n=null==(r=this.element)?void 0:r.getStartVertex())?void 0:n.position,[c,d]=this.getPoints(),p=ui(c,d,t),f=e.vertexId??(this.layout.debugIds?o.debugVertexCount.toString():de()),m=o.verticesById[f]??o.createVertex(f,p[0],p[1]);this.setVertices(a,m);let g=e.edgeId??o.getEdgeId(),y=o.createEdge(g,m,l);if(y.spaces[0]=this.spaces[0],y.spaces[1]=this.spaces[1],y.boundaryWalls[0]=this.boundaryWalls[0],y.boundaryWalls[1]=this.boundaryWalls[1],this.element&&e.elementId&&h&&u){let i=hi(u,p)/h,s=this.element.getEdges(),r=s.indexOf(this)+1,n=[y,...s.splice(r)];this.element.setEdges(s);let o=e.elementId??this.layout.getElementId(this.element),a=this.layout.createElement(this.element.type,o,n);a.parameters=JSON.parse(JSON.stringify(this.element.parameters));let l=hi(u,p),c=[...this.element.elements];for(let e of c)if("element:opening"===e.type){let s=e.parameters.position[0],r=s/h,n=(s+e.parameters.dimensions[0])/h;i<=r?(e.parameters.position[0]=r*h-l,this.element.removeElement(e),a.insertElement(e)):t<n&&be.warn(`Opening ${e.id} overlaps split position.`)}}else if(this.element){const t=this.element.getEdges();this.element.setEdges([...t,y]),y.element=this.element}if(i)for(let v of y.spaces){if(!v)continue;let{boundary:t}=v.getBoundaryFromEdge(this);if(t){let e,i=t.vertices.indexOf(a),s=t.vertices.indexOf(l);e=0===i&&s===t.vertices.length-1?s:0===s&&i===t.vertices.length-1||i<s?i:s,t.vertices.splice(e+1,0,m),t.edges=[];for(let r=0;r<t.vertices.length;r++){let e=r,i=r<t.vertices.length-1?r+1:0,s=t.vertices[e],n=t.vertices[i],a=o.getEdgeFromVertices(s,n);a?t.edges.push(a):be.error(`Cannot find edge with vertices ${s.id} and ${n.id}.`)}}else be.error(`Edge ${this.id} not found in space boundary.`)}for(let v of y.boundaryWalls){if(!v)continue;let t,e=v.boundaries[0],i=e.vertices.indexOf(a),s=e.vertices.indexOf(l);t=0===i&&s===e.vertices.length-1?s:0===s&&i===e.vertices.length-1||i<s?i:s,e.vertices.splice(t+1,0,m),e.edges=[];for(let r=0;r<e.vertices.length;r++){let t=r,i=r<e.vertices.length-1?r+1:0,s=e.vertices[t],n=e.vertices[i],a=o.getEdgeFromVertices(s,n);a?e.edges.push(a):be.error(`Cannot find edge with vertices ${s.id} and ${n.id}.`)}}return{vertex:m,edge:y,element:undefined}}canMerge(t){if(this.element&&!t.element||!this.element&&t.element)return!1;let e,i=this.vertices[0],s=this.vertices[1],r=t.vertices[0],n=t.vertices[1];if(i===r)e=[s,i,n];else if(i===n)e=[s,i,r];else if(s===r)e=[i,s,n];else{if(s!==n)return!1;e=[i,s,r]}if(0!==vi(e[0].position,e[1].position,e[2].position))return!1;let o=e[1];return!(!o.edges.includes(this)||!o.edges.includes(t))}merge(t,e=!1){var i;if(this.element&&!t.element||!this.element&&t.element)return void be.warn("Either none or both edges must have an element, cannot merge.");let s,r,n=this.layout.spatialGraph,o=this.vertices[0],a=this.vertices[1],l=t.vertices[0],h=t.vertices[1];if(o===l)s=[h,o,a],r=!0;else if(o===h)s=[l,o,a],r=!1;else if(a===l)s=[o,a,h],r=!1;else{if(a!==h)return void be.warn(`Edge ${this.id} does not share a vertex with edge ${t.id}, cannot merge.`);s=[o,a,l],r=!0}let u=s[0].position,c=s[1].position;if(0!==vi(u,c,s[2].position))return void be.warn(`Edges ${this.id} and ${t.id} are not collinear, cannot merge.`);let d=s[1];if(d.edges.includes(this)&&d.edges.includes(t)||be.error(`Common vertex ${d.id} edge list does not contain either one or both edges, cannot merge.`),t.element&&r&&function(t){let e=t.getAxisLength();for(let i of t.elements){if("element:opening"!==i.type)continue;let t=i.parameters;t.position[0]=e-(t.position[0]+t.dimensions[0]),Ds(i)}}(t.element),this.setVertices(s[0],s[2]),this.element&&this.element===t.element){const e=this.element.getEdges(),i=e.indexOf(t);e.splice(i,1),this.element.setEdges(e),t.element=null}else if(this.element&&t.element){const e=t.element.getEdges(),s=e.indexOf(t);e.splice(s,1);let r=[...this.element.getEdges(),...e];this.element.setEdges(r),t.element.setEdges([t]);for(const t of r)t.element=this.element;let n=null==(i=this.element.getStartVertex())?void 0:i.position;if(!n)return;let o=hi(c,n),a=[...t.element.elements];for(let i of a){if("element:opening"!==i.type)continue;t.element.removeElement(i),this.element.insertElement(i),i.parameters.position[0]+=o}}if(e)for(let p of t.spaces){if(!p)continue;let{boundary:e,edgeIndex:i}=p.getBoundaryFromEdge(t);if(e){e.edges.splice(i,1);let t=e.vertices.indexOf(s[1]);t>-1?e.vertices.splice(t,1):be.error(`Cannot find vertex ${s[1].id} in space ${p.id}`)}else be.error(`Cannot find edge ${t.id} in space ${p.id}.`)}for(let p of t.boundaryWalls){if(!p)continue;let e=p.boundaries[0],i=e.edges.indexOf(t);if(i>-1){e.edges.splice(i,1);let t=e.vertices.indexOf(s[1]);t>-1?e.vertices.splice(t,1):be.error(`Cannot find vertex ${s[1].id} in boundary wall ${p.id}`)}else be.error(`Cannot find edge ${t.id} in boundary wall ${p.id}.`)}t.spaces[0]=null,t.spaces[1]=null,t.boundaryWalls[0]=null,t.boundaryWalls[1]=null,n.removeEdge(t),0===d.edges.length&&n.removeVertex(d)}toJSON(){const t=this.vertices[0],e=this.vertices[1];return{...super.toJSON(),vertices:[t.id,e.id]}}}const Gs={usage:"generic",program:"none"};function Xs(t,e){const i=e.parent,s=i.getAxisLength(),{position:r,dimensions:n}=e.parameters,o=r[0]/s,a=(r[0]+n[0])/s;return i.getEdgesAtLinearSegment(o,a).some((e=>e.spaces[0]===t||e.spaces[1]===t))}class Ws extends _s{constructor(t,e){super(t,"layout:space"),this.boundaries=[],this.slabs=[],this.attributes={...Gs},this.boundaries=e,this.geometry={polygons:[]}}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes)),this.geometry=JSON.parse(JSON.stringify(t.geometry))}setId(t){if(t===this.id)return;let e=this.layout;if((null==e?void 0:e.spacesById[t])||(null==e?void 0:e.elementsById[t])||(null==e?void 0:e.annotationsById[t]))return void be.error(`ID ${t} already in use in layout ${e.id}.`);if(e&&e.spacesById[this.id]!==this)return void be.error(`Entry ${this.id} in 'spaces stored by ID' record does not contain space ${this.id}.`);let i=this.spaceGraph;if(null==i?void 0:i.nodesById[t])return void be.error(`ID ${t} already in use in space graph object.`);if(i&&i.nodesById[this.id]!==this)return void be.error(`Entry ${this.id} in 'nodes stored by ID' record does not contain space ${this.id}.`);let s=this.id;this.id=t,e&&(delete e.spacesById[s],e.spacesById[this.id]=this),i&&(delete i.nodesById[s],i.nodesById[this.id]=this),this.emit("node-id-change",this,s)}setAttributes(t){this.attributes.usage=t.usage??this.attributes.usage,this.attributes.program=t.program??this.attributes.program,this.emit("space-attributes-change",this)}get isExternal(){return["balcony","terrace","buildingOpening"].includes(this.attributes.usage)}getArea(){let t=this.geometry.polygons;if(0===t.length)return be.error(`Geometry has not been computed for space ${this.id}.`),0;let e=Ti(t[0]);for(let i=1;i<t.length;i++){e-=Ti(t[i])}return e}getAdjacentSpaces(t,{connectivity:e}={}){var i;let s=null==(i=t.nodeMap.get(this))?void 0:i.get("graph:adjacentTo");if(!s)return[];if(void 0===e)return Array.from(s);{let i=0===e?2:2*e;return Array.from(s).filter((s=>{let r=t.findShortestPath("graph:connectedTo",s,this,{depthLimit:i});return!!(null==r?void 0:r.length)&&(0!==e||"element:spaceDivider"===r[1].type)}))}}getElements(t){let e=t&&(Array.isArray(t)?t:[t]),i=[],s=this.layout.getElementList();for(let r of s){if(e&&!e.includes(r.type))continue;let t;switch(r.type){case"element:ceiling":case"element:floor":t=r.space===this;break;case"element:boundaryWall":break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":t=r.getEdges().some((t=>t.spaces[0]===this||t.spaces[1]===this));break;case"element:opening":t=Xs(this,r);break;case"element:door":case"element:window":t=Xs(this,r.parent);break;default:{let e,i=r;if(i.parent){let t=i.parent;for(;t.parent;)t=t.parent;e=t.getTransform().position}else e=i.position;t=wi([e[0],e[2]],this.geometry.polygons);break}}t&&i.push(r)}return i}getBoundaryFromVertex(t){for(let e of this.boundaries){let i=e.vertices.indexOf(t);if(i>-1)return{boundary:e,itemIndex:i}}return{boundary:void 0,itemIndex:-1}}getBoundaryFromEdge(t){for(let e of this.boundaries){let i=e.edges.indexOf(t);if(i>-1)return{boundary:e,edgeIndex:i}}return{boundary:void 0,edgeIndex:-1}}getBoundingBox(){const t=Y([this.geometry.polygons[0]]);let e=0,i=0;for(const s of this.slabs)"element:floor"===s.type&&(e=s.parameters.elevation),"element:ceiling"===s.type&&(i=s.parameters.elevation);return{min:[t.min[0],e,t.min[1]],max:[t.max[0],i,t.max[1]],transform:{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}}getAxisAlignedBoundingBox(){const{min:t,max:e}=this.getBoundingBox();return{min:t,max:e}}getBoundingBoxContour(){const{min:[t,,e],max:[i,,s]}=this.getBoundingBox();return[[t,e],[i,e],[i,s],[t,s]]}attachSlab(t){if(null!==t.space)return void be.warn(`Boundary slab ${t.id} already attached to space ${t.space.id}.`);this.slabs.indexOf(t)>-1?be.warn(`Boundary slab ${t.id} already referenced by space ${this.id}.`):(t.boundaries=this.boundaries,t.space=this,this.slabs.push(t))}detachSlab(t){if(t.space!==this)return void be.warn(`Boundary slab ${t.id} not attached to space ${this.id}.`);let e=this.slabs.indexOf(t);-1!==e?(t.space=null,t.boundaries=gr(this.boundaries),this.slabs.splice(e,1)):be.warn(`Boundary slab ${t.id} not referenced by space ${this.id}.`)}toJSON(){const{program:t,usage:e}=this.attributes,i={...super.toJSON(),boundaries:[],attributes:{program:t,usage:e}};for(const s of this.boundaries)i.boundaries.push(s.toJSON());return i}}class Hs extends ks{constructor(t,e,i){super(t,e),this.boundaries=gr(i)}getBoundingBox(){const t=[0,0,0],e=[0,0,0],i=Y([this.boundaries[0].geometryProfile]);return t[0]=i.min[0],e[0]=i.max[0],t[2]=i.min[1],e[2]=i.max[1],"element:floor"===this.type?(t[1]=this.parameters.elevation-this.parameters.height,e[1]=this.parameters.elevation):(t[1]=this.parameters.elevation,e[1]=this.parameters.elevation+this.parameters.height),{min:t,max:e,transform:this.getTransform()}}}const Ys={top:"#202020",bottom:"#000000",side1:"asm:basic-wall",side2:"asm:basic-wall",join1:"asm:basic-wall",join2:"asm:basic-wall"},$s={width:.15,height:3,offset:0,elevation:0,materials:{...Ys}};class js extends Fs{constructor(t,e){super(t,"element:wall",e);for(const i of e)i.element=this;this.parameters=JSON.parse(JSON.stringify($s)),this.geometryProfile={valid:!0,skipped:!1,selfIntersecting:!1,sidePoints1:[],sidePoints2:[],joinPoints1:[],joinPoints2:[],points:[]}}copyForClone(t){super.copyForClone(t),this.geometryProfile=JSON.parse(JSON.stringify(t.geometryProfile))}setParameters(t){super.setParameters(t)}getBoundingBox(){const t=[0,0,0],e=[0,0,0],[i,s]=this.getAxisPoints();if(!i||!s)return super.getBoundingBox();const r={position:i,rotation:-(xi(i,s)/Math.PI*180)},n={position:[i[0],0,i[1]],rotation:r.rotation,rotationAxis:[0,1,0]},o=Y([ki(this.geometryProfile.points,Ri(r))]);return t[0]=o.min[0],e[0]=o.max[0],t[2]=o.min[1],e[2]=o.max[1],t[1]=this.parameters.elevation,e[1]=this.parameters.elevation+this.parameters.height,{min:t,max:e,transform:n}}}const zs={"element:ceiling":{height:.2,elevation:$s.elevation+$s.height,materials:{top:"#808080",bottom:"asm:basic-ceiling",sides:"asm:basic-wall"}},"element:floor":{height:.2,elevation:0,materials:{top:"asm:basic-floor",bottom:"#808080",sides:"asm:basic-wall"}}};class Vs extends Hs{constructor(t,e,i){super(t,e,i);let s=zs[this.type];this.parameters=JSON.parse(JSON.stringify(s)),this.space=null}setParameters(t){super.setParameters(t)}getSpaces(){return null===this.space?[]:[this.space]}}function qs(t,e){var i;let s,r=t.vertices.map((t=>t.position)),n=[];for(let o of t.edges){if("element:wall"!==(null==(i=o.element)?void 0:i.type))continue;let t=o.element.geometryProfile.points;n.push(t)}if(0===n.length)s=[r];else if(e){s=q([r],$(n))}else s=$([r,...n]);return s=s.filter((t=>Q(t)>1e-7)),0===s.length?(be.warn("No valid polygons, returning boundary polygon."),r):(s=et(s,.001),s=s.filter((t=>t.length>0)),0===s.length?(be.warn("No valid polygons after filtering, returning boundary polygon."),r):(s.length>1&&(be.warn(`Result has ${s.length} polygons, returning largest one.`),s=s.sort(((t,e)=>Q(e)-Q(t)))),s[0]))}function Js(t,e){var i;let s=[qs(e.boundaries[0],!0)];for(let o=1;o<e.boundaries.length;o++){s=q(s,[qs(e.boundaries[o],!1)])}let{edges:r}=t.spatialGraph,n=[];for(let o of r){if(o.spaces[0]!==e||o.spaces[1]!==e||"element:wall"!==(null==(i=o.element)?void 0:i.type))continue;let[t,r]=o.getPoints();if(wi(ui(t,r,.5),s)){let t=o.element.geometryProfile.points;n.push(t)}}n.length>0&&(s=q(s,n)),s.sort(((t,e)=>{let i=Q(t);return Q(e)-i})),e.geometry.polygons=s}function Ks(t,e){return new Array(e-t).fill(void 0).map(((e,i)=>t+i))}function Zs(t){return`${t.type.split(":")[1]}Geometry-${t.id.substring(0,8)}`}function Qs(t){let e;switch(t.type){case"curve:rectangle":e=4;break;case"curve:polygon":e=t.points.length;break;case"curve:polygonWithHoles":e=t.polygons.reduce(((t,e)=>t+Qs({type:"curve:polygon",points:e})),0);break;case"curve:composite":e=t.segments.reduce(((t,e)=>t+Qs(e)),0);break;case"curve:polyline":e=t.points.length-1;break;case"curve:circle":case"curve:arc":case"curve:line":e=1}return e}function tr(){return We([Math.random(),Math.random(),Math.random()])}function er(t,e=!1){let{materials:i,height:s,elevation:r}=t.parameters,n="element:floor"===t.type?-s:0,o=[];for(let d=1;d<t.boundaries.length;d++){let e=t.boundaries[d].geometryProfile.slice();o.push(e)}o=$(o);let a=t.boundaries[0].geometryProfile.slice(),l=r+n,h={id:`boundarySlabGeometry-${t.id}-boundary`,type:"geometry:extrusion",position:[0,l,0],height:s,profile:{type:"curve:polygonWithHoles",polygons:[a,...o]},geometries:[]},u={top:[0],bottom:[1],sides:Ks(2,2+a.length)},c={top:e?tr():i.top,bottom:i.bottom,sides:i.sides};h.surfaces=u,h.materials=c,t.geometries=[{type:"reference:geometry",geometry:h}],t.emit("geometry-update",t)}function ir(t){for(let e=0;e<t.boundaries.length;e++){const i=t.boundaries[e];for(const s of i.edges){const r=s.vertices[0],n=s.vertices[1],o=i.vertices.indexOf(r),a=i.vertices.indexOf(n);let l,h;if(l=0===o?1===a:o===i.vertices.length-1?0===a:a-o==1,h=0===e?l?1:0:l?0:1,null===s.spaces[h])s.spaces[h]=t;else{const t=0===h?"left":"right";be.error(`Edge ${s.id} already references a space on its ${t} side.`)}}}}function sr(t){for(const e of t.boundaries)for(const i of e.edges)i.spaces[0]||null!==i.boundaryWalls[0]?i.spaces[1]||null!==i.boundaryWalls[1]?be.error(`Edge ${i.id} referenced by more than two adjacent nodes.`):i.boundaryWalls[1]=t:i.boundaryWalls[0]=t}function rr(t,e){let i=t.spatialGraph;for(let s=0;s<e.edges.length;s++){let t=e.edges[s],r=i.edgesById[t.id];r?e.edges[s]=r:i.insertEdge(t)}cr(e)}function nr(t,e){if(0!==e.boundaries.length){for(let i of e.boundaries)rr(t,i);switch(e.type){case"element:boundaryWall":sr(e);break;case"element:ceiling":case"element:floor":{let i=function(t,e){for(const i of t.spaces){if(i.boundaries.length!==e.length)continue;let t=0;for(;t<i.boundaries.length;){if(!dr(i.boundaries[t],e[t]))break;t++}if(t===i.boundaries.length)return fr(i,[{boundaries:e}])?i:void 0}return}(t,e.boundaries);i?i.attachSlab(e):be.warn(`Matching space not found for boundary slab element ${e.id}.`);break}}}else be.warn(`Boundary slab element ${e.id} does not specify boundaries.`)}function or(t,e){let i=t.spatialGraph;const s=e.getEdges(),r=new Set(s);let n=!1;for(let o of s){let t=i.edgesById[o.id];t?(n=!0,r.delete(o),r.add(t)):i.insertEdge(o)}n&&e.setEdges(Array.from(r)),function(t){for(const e of t.getEdges())null===e.element?e.element=t:e.element!==t&&be.error(`Edge ${e.id} referenced by more than one edge element.`)}(e)}function ar(t){var e;switch(t.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":!function(t){switch(t.type){case"element:boundaryWall":for(let e of t.boundaries)for(let i of e.edges)i.boundaryWalls[0]===t&&(i.boundaryWalls[0]=null),i.boundaryWalls[1]===t&&(i.boundaryWalls[1]=null);break;case"element:ceiling":case"element:floor":{let e=t.space;e?e.detachSlab(t):be.warn(`Boundary slab element ${t.id} not attached to a space.`);break}}}(t);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":!function(t){for(const e of t.getEdges())e.element=null}(t);break;case"element:asset":null==(e=t.product)||e.instances.delete(t)}}function lr(t){const e=[];for(const i of t.boundaries){const t=[];for(const e of i.vertices)t.push(e.position);e.push(t)}return e}function hr(t){let e=[];if(0===t.length)return e;if(1===t.length){let i=t[0];return e.push(i.vertices[0]),e.push(i.vertices[1]),e}for(let i=0;i<t.length;i++){let s=t[i],r=t[(i+1)%t.length],n=s.vertices[0],o=s.vertices[1],a=r.vertices[0],l=r.vertices[1];if(n===a||n===l)e.push(o);else{if(o!==a&&o!==l)return void be.warn(`Could not add edge ${s.id} to current path.`);e.push(n)}}return e}function ur(t){let e=[];for(let i=0;i<t.length-1;i++){let s=t[i],r=t[i+1];for(let t of s.edges)if(r.edges.indexOf(t)>-1){e.push(t);break}}return e}function cr(t){let e=hr(t.edges);if(!e)return!1;if(t.vertices=e,t.geometryProfile=t.vertices.map((t=>t.position)),!Ii(t.geometryProfile)){let{vertices:e,edges:i,geometryProfile:s}=t;e.reverse(),s.reverse();{i.reverse();let t=e[e.length-1],s=i[0];s.vertices[0]!==t&&s.vertices[1]!==t||(e.pop(),e.unshift(t))}}return!0}function dr(t,e,i){if(t.edges.length!==e.edges.length)return!1;const s=function(t,e){let i=0;for(const s of t.edges)for(const t of e.edges)if(s.id===t.id){i++;break}return i}(t,e);let r;return r=s===t.edges.length,r}function pr(t,e,i){if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++){if(!dr(t[s],e[s]))return!1}return!0}function fr(t,e){const i=e.map((t=>[t.boundaries[0].geometryProfile])),{polygons:s}=V(i,.01),{polygons:r}=V(s,-.01);if(0===r.length)return be.warn(`No union polygon, cannot match space ${t.id}.`),!1;if(r.length>1)return be.warn(` Disjoint union area, cannot match space ${t.id}.`),!1;const n=r[0][0],o=t.boundaries[0].geometryProfile,a=J([[o]],[[n]]).polygons,l=J([[n]],[[o]]).polygons,h=a.length?tt(a[0]):0,u=l.length?tt(l[0]):0;return h<.01&&u<.01}function mr(t){let e=new ps;return e.vertices=[...t.vertices],e.edges=[...t.edges],e.geometryProfile=JSON.parse(JSON.stringify(t.geometryProfile)),e}function gr(t){let e=[];for(let i of t){let t=mr(i);e.push(t)}return e}function yr(t,e,i){for(let s of t.edges)s.spaces[0]===e?s.spaces[0]=i:s.spaces[1]===e?s.spaces[1]=i:be.warn(`Edge ${s.id} not in space ${e.id} boundary.`)}function vr(t,e,i,s){let r=function(t,e,i,s){let r=t.vertices,n=Math.min(e,i),o=Math.max(e,i),a=o-n+1,l=r.length-a+2;if(a<3||l<3)return be.warn("Cannot split boundary, both fragments should have three or more vertices."),[];let h=r.slice(0,n+1),u=r.slice(n,o+1),c=r.slice(o,r.length).concat(h),d=u,p=ur(c).concat(s),f=ur(d).concat(s),m=c.map((t=>t.position)),g=d.map((t=>t.position)),y=new ps;y.vertices=c,y.edges=p,y.geometryProfile=m;let v=new ps;return v.vertices=d,v.edges=f,v.geometryProfile=g,[y,v]}(t.boundaries[0],e,i,s);if(!r)return void be.warn(`Could not split outer boundary of space ${t.id}.`);let n=[r[0]],o=[r[1]];for(let f=1;f<t.boundaries.length;f++){let e=t.boundaries[f],i=e.vertices[0].position;if(_i(i,r[0].geometryProfile))n.push(e);else{if(!_i(i,r[1].geometryProfile)){be.warn("Inner boundary is not contained by either of the two split boundaries.");continue}o.push(e)}}let a,l,h=t.layout;(null==h?void 0:h.debugIds)?(a=h.getSpaceId(),l=h.getSpaceId()):(a=de(),l=de());let u=new Ws(a,n),c=new Ws(l,o);for(let f of n)yr(f,t,u);for(let f of o)yr(f,t,c);for(let f of n)u.geometry.polygons.push(f.geometryProfile);for(let f of o)c.geometry.polygons.push(f.geometryProfile);Js(h,u),Js(h,c);let d=[],p=[];for(let f=0;f<t.slabs.length;f++){let e,i,s=t.slabs[f];if(null==h?void 0:h.debugIds){let t="element:ceiling"===s.type?"ceiling":"floor";e=`${t}-${f+1}-in-${a}`,i=`${t}-${f+1}-in-${l}`}else e=de(),i=de();let r=new Vs(e,s.type,n),u=new Vs(i,s.type,o);er(r,!0),er(u,!0),d.push(r),p.push(u)}return{spaces:[u,c],slabs:[d,p]}}function xr(t,e){let{position:i,rotation:s,rotationAxis:r}=t.getTransform(),n=Ci(i,s,r);return e&&ct(n,e,n),n}function br(t){let e;return t.parent&&(e=br(t.parent)),xr(t,e)}function _r(t,e){switch(e.type){case"annotation:floorPlanDxf":case"annotation:floorPlanImage":return{name:"annotation",nodes:t.annotations,nodesById:t.annotationsById,nodesByType:t.annotationsByType};case"view:2d":case"view:3d":return{name:"view",nodes:t.views,nodesById:t.viewsById,nodesByType:t.viewsByType}}}class wr{constructor(t){this.vertices=[],this.verticesById={},this.edges=[],this.edgesById={},this.graphChanged=!1,this.debugVertexCount=0,this.debugEdgeCount=0,this.layout=t}emit(t,...e){let i=this.layout.spaceGraph;i&&i.emit(t,...e)}copyForClone(t){this.debugVertexCount=t.debugVertexCount,this.debugEdgeCount=t.debugEdgeCount}deleteVertexAtIndex(t,e){let i=this.vertices[t];if(e){let t=i.edges.slice();for(let s of t){let t=s.vertices[0],r=s.vertices[1];t!==i&&r!==i||this.removeEdge(s,e)}}if(this.vertices.splice(t,1),this.verticesById[i.id]===i)return delete this.verticesById[i.id],i;be.error(`Entry ${i.id} in 'vertices by ID' record does not contain this object.`)}deleteEdgeAtIndex(t,e){let i=this.edges[t];if(i.element&&this.layout.removeElement(i.element),i.vertices[0].removeEdge(i),i.vertices[1].removeEdge(i),e){if(i.spaces[0]!==i.spaces[1]){if(i.spaces[0]){let t=i.spaces[0].slabs;for(let e of t)this.layout.removeElement(e);this.layout.removeSpace(i.spaces[0])}if(i.spaces[1]){let t=i.spaces[1].slabs;for(let e of t)this.layout.removeElement(e);this.layout.removeSpace(i.spaces[1])}}i.boundaryWalls[0]&&this.layout.removeElement(i.boundaryWalls[0]),i.boundaryWalls[1]&&this.layout.removeElement(i.boundaryWalls[1])}if(this.edges.splice(t,1),this.edgesById[i.id]===i)return delete this.edgesById[i.id],this.graphChanged=!0,i;be.error(`Entry ${i.id} in 'edges by id' record does not contain this object.`)}insertVertex(t){if(!Es(this.layout,t,this.edgesById,"Edge"))return;t.layout=this.layout,this.vertices.push(t),this.verticesById[t.id]=t;let e=this.layout.spaceGraph;e&&(e.registerNode(t),e.emit("vertex-create",t))}removeVertex(t,e=!1){let i=this.vertices.indexOf(t);if(-1===i)return void be.warn(`Vertex ${t.id} not found.`);this.deleteVertexAtIndex(i,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(t),s.emit("vertex-delete",t)),t.layout=null,t}removeVertexAtIndex(t,e=!1){let i=this.vertices[t];if(!i)return void be.warn(`Vertex not found at index ${t}.`);this.deleteVertexAtIndex(t,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(i),s.emit("vertex-delete",i)),i.layout=null,i}removeVertexById(t,e=!1){let i=this.verticesById[t];if(i&&i.id===t)return this.removeVertex(i,e);be.error(`Entry ${t} in 'vertices by id' record does not contain this object.`)}insertEdge(t,e=!1){if(!Es(this.layout,t,this.edgesById,"Edge"))return;let i=this.verticesById[t.vertices[0].id],s=this.verticesById[t.vertices[1].id];i?t.vertices[0]=i:this.insertVertex(t.vertices[0]),s?t.vertices[1]=s:this.insertVertex(t.vertices[1]),t.layout=this.layout,this.edges.push(t),this.edgesById[t.id]=t,t.vertices[0].addEdge(t),t.vertices[1].addEdge(t);let r=this.layout.spaceGraph;r&&(r.registerNode(t),r.emit("edge-create",t)),e&&function(t){let e=t.layout,i=t.vertices[0],s=t.vertices[1];for(let r of e.spaces){let n=r.boundaries[0],o=n.vertices.indexOf(i),a=n.vertices.indexOf(s);if(o>-1&&a>-1){t.spaces[0]=r,t.spaces[1]=r;let i=vr(r,o,a,t);if(i){let s=r.slabs.slice();for(let t of s)e.removeElement(t);e.removeSpace(r);let[n,o]=i.spaces,[a,l]=i.slabs;e.insertSpace(n);for(let t of a)e.insertElement(t);e.insertSpace(o);for(let t of l)e.insertElement(t);t.emit("space-split",r,[n,o]),n.emit("geometry-profile-update",n),o.emit("geometry-profile-update",o);for(let t of n.slabs)t.emit("geometry-profile-update",t);for(let t of o.slabs)t.emit("geometry-profile-update",t)}else be.warn(`Failed to split space ${r.id}.`);break}}}(t),this.graphChanged=!0}removeEdge(t,e=!1){let i=this.edges.indexOf(t);if(-1===i)return void be.warn(`Edge ${t.id} not found.`);this.deleteEdgeAtIndex(i,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(t),s.emit("edge-delete",t)),t.layout=null,t}removeEdgeAtIndex(t,e=!1){let i=this.edges[t];if(!i)return void be.warn(`Edge not found at index ${t}.`);this.deleteEdgeAtIndex(t,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(i),s.emit("edge-delete",i)),i.layout=null,i}removeEdgeById(t,e=!1){let i=this.edgesById[t];if(i&&i.id===t)return this.removeEdge(i,e);be.error(`Entry ${t} in 'edges by id' record does not contain this object.`)}getEdgeFromVertices(t,e){let i=t.edges,s=e.edges;for(let r of i)for(let t of s)if(r===t)return r}getVertexId(t){return this.layout.debugIds?(t??"vertex-")+this.debugVertexCount:de()}getEdgeId(t){return this.layout.debugIds?(t??"edge-")+this.debugEdgeCount:de()}createVertex(t,e,i){let s=new Ps(t,e,i);return this.insertVertex(s),s}createEdge(t,e,i,s=!1){let r=new Us(t,e,i);return this.insertEdge(r,s),r}createEdgeByVertexIds(t,e,i,s=!1){let r=this.verticesById[e],n=this.verticesById[i];return this.createEdge(t,r,n,s)}toJSON(){let t=[];for(let i of this.vertices){let e=i.toJSON();t.push(e)}let e=[];for(let i of this.edges){let t=i.toJSON();e.push(t)}return{vertices:t,edges:e}}}const Pr={height:3,elevation:0,surfaces:{top:[0],bottom:[1],sides:"..."},materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class Er extends Hs{constructor(t,e){super(t,"element:boundaryWall",e),this.parameters=JSON.parse(JSON.stringify(Pr))}setParameters(t){super.setParameters(t)}}const Tr={materials:{}};class Ar extends Fs{constructor(t,e){super(t,"element:curtainWall",e);for(const i of e)i.element=this;this.parameters=JSON.parse(JSON.stringify(Tr))}setParameters(t){super.setParameters(t)}}const Ir={materials:{}};class Sr extends Fs{constructor(t,e){super(t,"element:spaceDivider",e);for(const i of e)i.element=this;this.parameters=JSON.parse(JSON.stringify(Ir))}setParameters(t){super.setParameters(t)}getBoundingBox(){const[t,e]=this.getAxisPoints();if(!t||!e)return super.getBoundingBox();const i=hi(t,e),s=xi(t,e)/Math.PI*180;return{min:[0,0,-.01],max:[i,0,.01],transform:{position:[t[0],0,t[1]],rotation:-s,rotationAxis:[0,1,0]}}}}class Cr extends ks{constructor(t,e){super(t,e)}}function Mr(t,e,i=0){let{width:s,offset:r,elevation:n}=t.parameters,[o,a]=t.getAxisPoints();if(!o||!a)return{position:[0,0,0],rotation:0};let l=fi(a,o),h=li(l),u=ui(o,a,e.parameters.position[0]/h);u=ri(u,pi(di(ci(l)),-.5*s+r-i));let c=e.parameters.position[1]+n;return{position:[u[0],c,u[1]],rotation:180*-ni(fi(a,o))/Math.PI}}function Or(t,e,i,s){const r=.001;let n=s.parameters.dimensions[0],o=s.parameters.dimensions[1],{width:a,elevation:l}=e.parameters,{position:[h,u,c],rotation:d}=Mr(e,s,r),p=s.parameters.materials,f={id:i,type:"geometry:cuboid",position:[h,u-r-l,c],rotation:d,dimensions:[n,o+r,a+.002],surfaces:{top:[0],bottom:[1],frontBack:[2,4],sides:[3,5]}},m={top:p.top,bottom:p.bottom,frontBack:"#FFFFFF",sides:p.sides};f.materials=m;let g=e.geometries[0].geometry;g.geometries??(g.geometries=[]),g.geometries.push({type:"csg:subtract",geometry:f}),s.emit("geometry-update",s)}function Nr(t,e){let i,s={},r=Ks(0,e);for(let[n,o]of Object.entries(t))if("string"==typeof o)"..."===o?i=n:be.warn("Invalid surface definition string.");else if(Array.isArray(o)){s[n]=[];for(let t of o){if(t<0||t>=e){be.warn(`Face index ${t} out of range when defining surface ${n}.`);continue}let i=r.indexOf(t);-1!==i?(s[n].push(t),r.splice(i,1)):be.warn(`Face index ${t} already assigned when defining surface ${n}.`)}}else be.warn("Invalid surface definition.");return i&&r.length>0&&(s[i]=r),s}function Lr(t){let e,{surfaces:i,materials:s}=t.parameters;for(let r=0;r<t.boundaries.length;r++){let n=t.boundaries[r],o=t.parameters.elevation,a=hr(n.edges);if(!a)return void be.warn(`Could not create geometry for boundary wall ${t.id}.`);let l=a.map((t=>t.position)),h=0===r?"boundary":"hole-"+r,u={id:`boundaryWallGeometry-${t.id}-${h}`,type:"geometry:extrusion",position:[0,o,0],height:t.parameters.height,profile:{type:"curve:polygon",points:l},geometries:[]};u.surfaces=Nr(i,2+l.length),u.materials=JSON.parse(JSON.stringify(s)),0===r?(e=u,t.geometries=[{type:"reference:geometry",geometry:u}]):e.geometries.push({type:"csg:subtract",geometry:u})}t.emit("geometry-update",t)}function Rr(t){let{length:e,height:i,frameThickness:s,frameDepth:r,doorAngle:n,hingeSide:o,doorSide:a,doorType:l,materials:h}=t.parameters,u="right"===o,c=[e/2,r/2],d=Zs(t),p=.05,f=[],m=(180-Math.min(180,Math.max(0,n)))/180,g=(r-p)/2,y=e-2*s,v=i-s;switch(l){case"singleSwing":u?f.push({position:[s-c[0],0,-c[1]],rotation:n,dimensions:[y,v,p]}):f.push({position:[c[0]-s,0,-c[1]],dimensions:[p,v,y],rotation:270-n});break;case"doubleSwing":y=e/2-s,f.push({position:[s-c[0],0,-c[1]],rotation:n,dimensions:[y,v,p]}),f.push({position:[c[0]-s,0,-c[1]],rotation:270-n,dimensions:[p,v,y]});break;case"slidingDoor":y=(e-2*s)*m;let t=u?s-c[0]:c[0]-y-s;f.push({position:[t,0,-c[1]+g],rotation:0,dimensions:[y,v,p]});break;case"garageDoor":f.push({position:[s-c[0],v*(1-m),-c[1]+g],rotation:0,dimensions:[y,v*m,p]});break;case"elevatorDoor":y=(e-2*s)/2-.005,f.push({position:[s-c[0],0,-c[1]+g],rotation:0,dimensions:[y,v,p]}),f.push({position:[0,0,-c[1]+g],rotation:0,dimensions:[y,v,p]})}let x=[];for(let b=0;b<f.length;b++){let{position:t,rotation:e,dimensions:i}=f[b],s={id:d+"-leaf-"+b,type:"geometry:cuboid",position:t,rotation:e,dimensions:i,material:h.leaf};x.push({type:"reference:geometry",position:[c[0],0,c[1]],rotation:"side2"===a?180:0,geometry:s})}return x}function kr(t,e,i){let s=Zs(t),{stepCount:r,stepHeight:n,angle:o,radius:a,width:l,circulation:h}=i,u=a-l,c=a-l/2,d=Math.PI*o/180*c/r/(u+l/2),p=[0,n,0],f=180/Math.PI*d,m=0;"right"===h&&(f=-f,m=180);let g=function(t,e,i){let{stepThickness:s,stepHeight:r,angle:n,width:o,stepCount:a,radius:l,circulation:h}=i,u=l-o/2,c=l-o,d=Math.PI*n/180*u/a/(c+o/2),p="right"===h,f=r,m=c,g=(p?-1:1)*Math.sin(d)*c,y=r-s,v=Math.cos(d)*c,x=-s,b=c+o,_=(p?-1:1)*Math.sin(d)*(c+o),w=Math.cos(d)*(c+o),P=[0,f,m,0,0,m,g,y,v,g,f,v,0,x,m,0,f,b,0,0,b,_,y,w,_,f,w,0,x,b],E=[0,8,3,0,5,8,0,3,2,0,2,1,1,2,4,0,6,5,0,1,6,5,7,8,5,6,7,6,9,7,2,7,4,4,7,9,8,7,3,7,2,3];if(p)for(let T=0;T<E.length;T+=3){let t=E[T+1];E[T+1]=E[T+2],E[T+2]=t}return{id:t,type:"geometry:mesh",vertices:P,indices:E,rotation:0,surfaces:{top:[0,1],base:[2,3,4,5,6,7,8,9,10,11,12,13]},materials:{top:e.tread,base:e.steps}}}(s,e,i);return{type:"reference:geometry",position:{type:"vector3:range",range:{start:[0,0,0],step:p,count:r}},rotation:{type:"number:range",range:{start:m,step:f,count:r}},geometry:g}}function Br(t){let{width:e,height:i,materials:s}=t.parameters;const r=Math.round(i/.17),n={height:i,width:e,stepCount:r,stepHeight:i/r,stepThickness:.1};let o;if("straight"===t.parameters.stairFlightType){let{length:e}=t.parameters;o=function(t,e,i){let{stepCount:s,width:r,stepHeight:n,length:o,stepThickness:a}=i,l=o/s,h=[l,n,0],u=function(t,e,i){let{riser:s,tread:r,width:n,thickness:o}=i;return{id:t,type:"geometry:extrusion",rotation:90,rotationAxis:[1,0,0],height:n,profile:{type:"curve:polygon",points:[[0,0],[0,o],[r,o-s],[r,-s],[0,-s]]},surfaces:{top:[5],base:[0,1,2,3,4,6]},materials:{top:e.tread,base:e.steps}}}(Zs(t),e,{tread:l,riser:n,width:r,thickness:a});return{type:"reference:geometry",position:{type:"vector3:range",range:{start:[0,0,0],step:h,count:s}},geometry:u}}(t,s,{...n,length:e})}else{let{radius:e,angle:i,circulation:r}=t.parameters;o=kr(t,s,{...n,radius:e,angle:i,circulation:r})}t.geometries=[o],t.emit("geometry-update",t)}function Fr(t,e=!1){let{sidePoints1:i,sidePoints2:s,joinPoints1:r,joinPoints2:n,points:o}=t.geometryProfile;if(0===o.length)return;let a="wallGeometry-"+t.id,l={id:a,type:"geometry:extrusion",position:[0,t.parameters.elevation,0],height:t.parameters.height,profile:{type:"curve:composite",segments:[{type:"curve:polyline",points:i},{type:"curve:polyline",points:r},{type:"curve:polyline",points:s},{type:"curve:polyline",points:n}]}},h=t.parameters.materials,u={top:[0],bottom:[1],side1:[2],side2:[4]},c={top:e?tr():h.top??Ys.top,bottom:h.bottom??Ys.bottom,side1:h.side1??Ys.side1,side2:h.side2??Ys.side2},[d,p]=function(t){let e=[!1,!1],i=[t.getStartVertex(),t.getEndVertex()];for(let s=0;s<i.length;s++){let t=i[s];t&&(t.edges.filter((t=>{var e;return"element:wall"===(null==(e=t.element)?void 0:e.type)})).map((t=>t.element)).length>0?e[s]=!0:be.error(`Vertex ${t.id} not referencing edge that references it.`))}return e}(t);d&&(u.join1=[3],c.join1=h.join1??Ys.join1),p&&(u.join2=[5],c.join2=h.join2??Ys.join2),l.surfaces=u,l.materials=c,t.geometries=[{type:"reference:geometry",geometry:l}];for(let f=0;f<t.elements.length;f++){let e=t.elements[f];if("element:opening"!==e.type)continue;let i=a+"-opening-"+(f+1);Or(t.layout,t,i,e)}t.emit("geometry-update",t)}function Dr(t){switch(t.type){case"element:asset":case"element:beam":case"element:curtainWall":case"element:opening":case"element:ramp":case"element:roof":case"element:spaceDivider":case"element:stairs":break;case"element:casework":!function(t){let{length:e,width:i,height:s,counterHeight:r,materials:n}=t.parameters,o=Math.min(.6,e),a=Math.floor(e/o),l=e%o,h=i-.02,u=s-r,c=.02,d=Zs(t),p=[],f=t.elements;for(let y of f)if("product"in y&&y.product){let{min:t,max:e}=y.product.attributes.boundingBox,i=gi(t,[0,.01,0]),s=gi(e,i),r=mi(i,y.position);p.push({id:d+"-subtraction-"+y.id.substring(0,8),type:"geometry:cuboid",position:[...r],dimensions:s})}let m=[];r>0&&m.push({id:d+"-counter",type:"geometry:cuboid",position:[0,u,0],dimensions:[e,r,i],material:n.counter}),m.push({id:d+"-doors",type:"geometry:cuboid",position:{type:"vector3:range",range:{start:[c,c,h],step:[o,0,0],count:a}},dimensions:[o-.04,u-.04,c],material:n.cabinetDoors}),l>.04&&m.push({id:d+"-doors+2",type:"geometry:cuboid",position:[a*o+c,c,h],dimensions:[l-.04,u-.04,c],material:n.cabinet});let g={id:d+"-cabinet",type:"geometry:cuboid",position:[0,0,0],dimensions:[e,u,h],geometries:[...m.map((t=>({type:"reference:geometry",geometry:t}))),...p.map((t=>({type:"csg:subtract",geometry:t})))],material:n.cabinet};t.geometries=[{type:"reference:geometry",geometry:g}],t.emit("geometry-update",t)}(t);break;case"element:column":!function(t){let{profile:e,height:i,materials:s}=t.parameters,r=Zs(t),n=[0,0,0];"curve:rectangle"===e.type&&(n=[-e.dimensions[0]/2,0,-e.dimensions[1]/2]);let o={id:r,type:"geometry:extrusion",position:n,profile:e,height:i},a=Qs(e);o.surfaces={top:[0],bottom:[1],sides:Ks(2,2+a)},o.materials={top:s.top,bottom:s.bottom,sides:s.sides},t.geometries=[{type:"reference:geometry",geometry:o}],t.emit("geometry-update",t)}(t);break;case"element:ceiling":case"element:floor":er(t);break;case"element:boundaryWall":Lr(t);break;case"element:door":!function(t){let{height:e,length:i,frameThickness:s,frameDepth:r,materials:n}=t.parameters,o=Zs(t),a={id:o+"-frame-top",type:"geometry:cuboid",position:[0,e-s,0],rotation:0,dimensions:[i,s,r],material:n.frame},l={id:o+"-frame-side",type:"geometry:cuboid",position:{type:"vector3:list",list:[[0,0,0],[i-s,0,0]]},rotation:0,dimensions:[s,e-s,r],material:n.frame};t.geometries=[{type:"reference:geometry",geometry:a},{type:"reference:geometry",geometry:l},...Rr(t)],t.emit("geometry-update",t)}(t);break;case"element:generic":!function(t){let{profile:e,height:i,materials:s}=t.parameters;if("none"===e)return;let r=Qs(e),n={id:Zs(t),type:"geometry:extrusion",position:[0,0,0],profile:e,height:i,surfaces:{top:[0],bottom:[1],sides:Ks(2,2+r)},materials:{top:s.top,bottom:s.bottom,sides:s.sides}};t.geometries=[{type:"reference:geometry",geometry:n}],t.emit("geometry-update",t)}(t);break;case"element:railing":!function(t){let e,{height:i,length:s,width:r,segmentCount:n,segmentLength:o,materials:a}=t.parameters,l=.01;e=o&&o>0?Math.max(Math.round(s/o),1):n&&n>0?n:Math.max(Math.round(s/.12),1);let h=(s-l)/e,u=Zs(t),c={id:u+"-horizontal",type:"geometry:cuboid",position:{type:"vector3:list",list:[[0,i-l,-r/2],[0,0,-r/2]]},rotation:0,dimensions:[s,l,r],material:a.surface},d={id:u+"-vertical",type:"geometry:cuboid",position:{type:"vector3:range",range:{start:[0,l,-r/2],step:[h,0,0],count:e+1}},rotation:0,dimensions:[l,i-.02,r],material:a.surface};t.geometries=[{type:"reference:geometry",geometry:c},{type:"reference:geometry",geometry:d}],t.emit("geometry-update",t)}(t);break;case"element:slab":!function(t){let{profile:e,height:i,materials:s}=t.parameters,r={id:Zs(t),type:"geometry:extrusion",position:[0,0,0],profile:e,height:i},n=Qs(e);r.surfaces={top:[0],bottom:[1],sides:Ks(2,2+n)},r.materials={top:s.top,bottom:s.bottom,sides:s.sides},t.geometries=[{type:"reference:geometry",geometry:r}],t.emit("geometry-update",t)}(t);break;case"element:stairFlight":Br(t);break;case"element:wall":Fr(t);break;case"element:window":!function(t){let{panelCount:e,panelLength:i,height:s,length:r,frameThickness:n,frameDepth:o,materials:a}=t.parameters,l=Zs(t),h={id:l,type:"geometry:cuboid",position:{type:"vector3:list",list:[[0,s-n,0],[0,0,0]]},rotation:0,dimensions:[r,n,o],material:a.frame},u=[[0,n,0]],c=r-n;if(e&&(i=c/e),i&&i>n){let t=i;for(;t<c;)u.push([t,n,0]),t+=i}u.push([r-n,n,0]);let d={id:l+"-vertical",type:"geometry:cuboid",position:{type:"vector3:list",list:u},rotation:0,dimensions:[n,s-2*n,o],material:a.frame},p={id:l+"-glass",type:"geometry:extrusion",position:[n,n,o/2],rotation:0,height:s-2*n,profile:{type:"curve:rectangle",dimensions:[r-2*n,.01]},material:a.panel};t.geometries=[{type:"reference:geometry",geometry:h},{type:"reference:geometry",geometry:d},{type:"reference:geometry",geometry:p}],t.emit("geometry-update",t)}(t)}for(let e of t.elements)Dr(e)}const Ur={position:[0,0],dimensions:[1,2],materials:{top:"#FFFFFF",bottom:"#FFFFFF",sides:"#FFFFFF"}};class Gr extends Cr{constructor(t){super(t,"element:opening"),this.parameters=JSON.parse(JSON.stringify(Ur))}getTransform(){var t;if("element:wall"!==(null==(t=this.parent)?void 0:t.type)){const t=this.parent?`Parent of element ${this.id} is not a wall.`:`Element ${this.id} does not have a parent.`;return be.error(t),{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}let{position:e,rotation:i}=Mr(this.parent,this);return{position:e,rotation:i,rotationAxis:[0,1,0]}}get position(){return this.getTransform().position}get rotation(){return this.getTransform().rotation}setParameters(t){let e=!!t.position,i=!!t.dimensions;if(super.setParameters(t),this.emit("element-parameters-change",this),e||i){let t=this.parent;if(t&&Dr(t),i)for(let e of this.elements)Dr(e)}}getBoundingBox(t=!1){const{dimensions:e}=this.parameters,i=this.parent,s=(null==i?void 0:i.parameters.width)||0;return{min:[0,0,0],max:[e[0],e[1],s],transform:t?this.getTransform():this.getWorldTransform()}}getSpaces(){if(this.parent){return this.parent.getSpaces().filter((t=>Xs(t,this)))}return be.error(`Element ${this.id} does not have a parent.`),[]}get isExternal(){const t=this.parent;if(!t)return super.isExternal;const[e]=t.getAxisPoints();if(!e)return super.isExternal;const i=t.getAxisLength(),{position:s,dimensions:r}=this.parameters,n=s[0]/i,o=(s[0]+r[0])/i,a=t.getEdgesAtLinearSegment(n,o);if(1===a.length)return a[0].isExternal;let l=0,h=0;for(const u of a){const[t,s]=u.getPoints().map((t=>hi(e,t)/i)).sort(((t,e)=>t-e)),r=(o>s?s:o)-(n>t?n:t);u.isExternal?l+=r:h+=r}return l>=h}}class Xr extends ks{constructor(t,e){super(t,e),this.position=[0,0,0],this.rotation=0,this.rotationAxis=[0,1,0]}copyForClone(t){super.copyForClone(t),this.position=[...t.position],this.rotation=t.rotation,this.rotationAxis=[...t.rotationAxis]}setPosition(t){this.position=[...t],this.emit("element-transform-change",this)}setRotation(t,e){this.rotation=t,e&&(this.rotationAxis=[...e]),this.emit("element-transform-change",this)}setTransform(t,e,i){this.position=[...t],this.rotation=e,i&&(this.rotationAxis=[...i]),this.emit("element-transform-change",this)}getSpaces(){if(this.parent)return this.parent.getSpaces();let t=[this.position[0],this.position[2]];for(let e of this.layout.spaces)if(wi(t,e.geometry.polygons))return[e];return[]}getTransform(){return{position:[...this.position],rotation:this.rotation,rotationAxis:[...this.rotationAxis]}}getWorldTransform(){if(!this.parent)return this.getTransform();let t=br(this),{position:e,rotation:i,rotationAxis:s}=Mi(t);return 0===s[0]&&s[1]<0&&0===s[2]&&(s=[0,1,0],i=-i),{position:e,rotation:i,rotationAxis:s}}getBoundingBox(t=!1){const e=[0,0,0],i=[0,0,0];if("length"in this.parameters&&(i[0]=this.parameters.length),"height"in this.parameters&&(i[1]=this.parameters.height),"width"in this.parameters?i[2]=this.parameters.width:"frameDepth"in this.parameters&&(i[2]=this.parameters.frameDepth),"radius"in this.parameters&&(e[0]=e[2]=-this.parameters.radius,i[0]=i[2]=this.parameters.radius),"profile"in this.parameters&&"none"!==this.parameters.profile)switch(this.parameters.profile.type){case"curve:rectangle":{let[t,s]=this.parameters.profile.dimensions;i[0]=t,i[2]=s,"element:column"===this.type&&(e[0]=-t/2,i[0]=t/2,e[2]=-s/2,i[2]=s/2);break}case"curve:circle":e[0]=e[2]=-this.parameters.profile.radius,i[0]=i[2]=this.parameters.profile.radius;break;case"curve:polygon":let t=Y([this.parameters.profile.points]);e[0]=t.min[0],i[0]=t.max[0],e[2]=t.min[1],i[2]=t.max[1]}return{min:e,max:i,transform:t?this.getTransform():this.getWorldTransform()}}setParameters(t){super.setParameters(t),Dr(this)}}const Wr={materials:{}};class Hr extends Xr{constructor(t){super(t,"element:asset"),this.product=null,this.parameters=JSON.parse(JSON.stringify(Wr))}get isComponentInstance(){var t;return"product:component"===(null==(t=this.product)?void 0:t.type)}get isComponentInstanceChild(){var t;return"element:asset"===(null==(t=this.parent)?void 0:t.type)&&this.parent.isComponentInstance}setParameters(t){super.setParameters(t)}setProduct(t){this.product=t,this.product.instances.add(this),this.emit("node-property-change",this,"product"),this.emit("geometry-update",this)}getBoundingBox(t=!1){if(!this.product)return super.getBoundingBox();const{min:e,max:i}=this.product.attributes.boundingBox;return{min:e,max:i,transform:t?this.getTransform():this.getWorldTransform()}}}const Yr={length:2,width:.1,height:.2,materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class $r extends Xr{constructor(t){super(t,"element:beam"),this.parameters=JSON.parse(JSON.stringify(Yr))}setParameters(t){super.setParameters(t)}}const jr={length:2,height:.7,width:.6,counterHeight:.03,materials:{cabinet:"asm:cabinet_paint_white",cabinetDoors:"asm:cabinet_paint_white",counter:"asm:cabinet_paint_white"}};class zr extends Xr{constructor(t){super(t,"element:casework"),this.parameters=JSON.parse(JSON.stringify(jr))}setParameters(t){super.setParameters(t)}}const Vr={type:"curve:circle",radius:.1},qr={"curve:circle":{...Vr},"curve:rectangle":{type:"curve:rectangle",dimensions:[.1,.1]},"curve:polygon":{type:"curve:polygon",points:[[0,0],[.1,0],[.1,.1],[0,.1]]},"curve:polygonWithHoles":{type:"curve:polygonWithHoles",polygons:[[[0,0],[.1,0],[.1,.1],[0,.1]],[[.02,.02],[.02,.08],[.08,.08],[.08,.02]]]}},Jr={profile:{...Vr},height:3,materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class Kr extends Xr{constructor(t){super(t,"element:column"),this.parameters=JSON.parse(JSON.stringify(Jr))}setParameters(t){var e;(null==(e=t.profile)?void 0:e.type)&&t.profile.type!==this.parameters.profile.type&&(this.parameters.profile=JSON.parse(JSON.stringify(qr[t.profile.type]))),super.setParameters(t)}}const Zr={length:1,height:2,frameThickness:.05,frameDepth:.1,doorType:"singleSwing",doorAngle:90,hardware:!0,hingeSide:"right",doorSide:"side1",materials:{frame:"asm:doorLeaf-flush-white",leaf:"asm:doorLeaf-flush-white"}};class Qr extends Xr{constructor(t){super(t,"element:door"),this.parameters=JSON.parse(JSON.stringify(Zr))}setParameters(t){super.setParameters(t)}getBoundingBox(t=!1){const e=super.getBoundingBox(t),{doorType:i,frameThickness:s,frameDepth:r,doorSide:n,length:o}=this.parameters;if("singleSwing"===i||"doubleSwing"===i){const t="singleSwing"===i?o-2*s:o/2-s;"side1"===n?e.min[2]=-t:e.max[2]=r+t}return e}}const tn={"curve:circle":{type:"curve:circle",radius:.5},"curve:rectangle":{type:"curve:rectangle",dimensions:[1,1]},"curve:polygon":{type:"curve:polygon",points:[[0,0],[1,0],[1,1],[0,1]]},"curve:polygonWithHoles":{type:"curve:polygonWithHoles",polygons:[[[0,0],[1,0],[1,1],[0,1]],[[.25,.25],[.25,.75],[.75,.75],[.75,.25]]]}},en={profile:"none",height:0,materials:{top:"#F0F0F0",bottom:"#F0F0F0",sides:"#F0F0F0"}};class sn extends Xr{constructor(t){super(t,"element:generic"),this.parameters=JSON.parse(JSON.stringify(en))}setParameters(t){t.profile&&"none"!==t.profile&&t.profile.type&&"none"!==this.parameters.profile&&this.parameters.profile.type!==t.profile.type&&(this.parameters.profile=JSON.parse(JSON.stringify(tn[t.profile.type]))),super.setParameters(t)}}const rn="product:static",nn={manufacturer:"",categories:[],subCategories:[],thumbnail:"",boundingBox:{min:[0,0,0],max:[0,0,0]},seatCapacity:0,updatedAt:""};class on extends bs{constructor(t,e){var i,s,r;super(t,e),i=this,(s=me).has(i)?ve("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(i):s.set(i,r),this.instances=new Set,this.attributes=JSON.parse(JSON.stringify(nn))}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes))}setAttributes(t){var e,i;let s=this.attributes;s.manufacturer=t.manufacturer??s.manufacturer,s.categories=(null==(e=t.categories)?void 0:e.slice())??s.categories,s.subCategories=(null==(i=t.subCategories)?void 0:i.slice())??s.subCategories,s.thumbnail=t.thumbnail??s.thumbnail,t.boundingBox&&(s.boundingBox.min=[...t.boundingBox.min],s.boundingBox.max=[...t.boundingBox.max]),s.seatCapacity=t.seatCapacity??s.seatCapacity,s.updatedAt=t.updatedAt??s.updatedAt}toJSON(){const t=super.toJSON();return t.attributes=xe(this,me,ge).call(this),t}}me=new WeakSet,ge=function(){const t={},e=this.attributes;""!==e.manufacturer&&(t.manufacturer=e.manufacturer),e.categories.length>0&&(t.categories=[...e.categories]),e.subCategories.length>0&&(t.subCategories=[...e.subCategories]),""!==e.thumbnail&&(t.thumbnail=e.thumbnail);let{min:i,max:s}=e.boundingBox;return 1!==i[0]&&-1!==s[0]&&(t.boundingBox={min:[...e.boundingBox.min],max:[...e.boundingBox.max]}),e.seatCapacity>0&&(t.seatCapacity=e.seatCapacity),void 0!==e.updatedAt&&(t.updatedAt=e.updatedAt),t};class an extends on{constructor(t){super(t,rn),this.geometries=[]}copyForClone(t){super.copyForClone(t),this.geometries=JSON.parse(JSON.stringify(t.geometries))}toJSON(){return{...super.toJSON(),type:rn,geometries:JSON.parse(JSON.stringify(this.geometries))}}}const ln="product:component";class hn extends on{constructor(t){super(t,ln),this.products=[],this.geometries=[],this.attributes=JSON.parse(JSON.stringify(nn))}copyForClone(t){super.copyForClone(t),this.products=JSON.parse(JSON.stringify(t.products))}toJSON(){return{...super.toJSON(),type:ln,products:JSON.parse(JSON.stringify(this.products)),geometries:[]}}setProducts(t){this.products=JSON.parse(JSON.stringify(t))}setInstances(){var t;for(const e of this.instances)if(this.products.length===e.elements.length)for(let i=0;i<this.products.length;i++){const s=this.products[i];if("type"in s.position)continue;if("number"!=typeof s.rotation)continue;const r=e.elements[i];"element:asset"===r.type&&(null==(t=r.product)?void 0:t.id)===s.product&&r.setTransform(s.position,s.rotation)}}}function un(t){for(let e=t.elements.length-1;e>=0;e--)t.removeElement(t.elements[e])}function cn(t,e,i){let s=t.elements.filter((t=>t.type===e));for(let r=s.length-1;r>=i;r--)t.removeElement(s[r]);for(let r=0;r<i;r++)if(!s[r]){let i=de();s[r]="element:casework"===e?new zr(i):new Hr(i),t.insertElement(s[r])}return s}function dn(t){let{length:e,width:i,height:s,wallCabinet:r,leftHighCabinetCount:n,rightHighCabinetCount:o,sinkElementSlot:a,materials:l}=t.parameters,h=Math.min(.6,e),u=s-1.5,c=Math.min(e,h*Math.max(n,0)),d=e>c?h*o:0,p=Math.max(e-c-d,0);d=Math.max(e-c-p,0);let f=0;p>0&&(f++,r&&f++),c>0&&f++,d>0&&f++;let m=p>0&&a*h>=c&&a*h<=c+p,g=cn(t,"element:casework",f),y={cabinet:l.cabinet,cabinetDoors:l.cabinetDoors,counter:l.counter};if(p>0){let e=g.shift();if(e){let s=cn(e,"element:asset",m?1:0);if(m){let e=s[0],r=function(t){const e="7f24bd1c-1ebc-4724-8cd4-ca78c7d4a1e5";if(null==t?void 0:t.productsById[e])return null==t?void 0:t.productsById[e];let i=new an(e);return i.setAttributes({categories:["appliances"],subCategories:["kitchen"],boundingBox:{max:[.54,.21,0],min:[0,-.17,-.47]}}),i.geometries=[{type:"reference:geometry",geometry:{id:"sinkGeometry",type:"geometry:uri",format:"data3d",uri:"015f8f8e-e588-4f51-a342-2930559834ee/201208-0355-60hukz/bf4e4a56-ed95-4b58-a214-4b1a0a84ae0e.gz.data3d.buffer"}}],i}(t.spaceGraph),{min:n,max:o}=r.attributes.boundingBox,l=mi(n,(v=gi(o,n),x=.5,[v[0]*x,v[1]*x,v[2]*x]));l[1]=0;let u=mi([a*h-c,.9,0],[h/2,0,i/2]);r&&(e.setProduct(r),e.setPosition(gi(u,l)))}e.setParameters({length:p,width:i,height:.9,counterHeight:.03,materials:{...y}}),e.setTransform([c,0,0],0)}let s=r&&g.shift();s&&(un(s),s.setParameters({length:p,width:.45,height:u,counterHeight:0,materials:{...y}}),s.setTransform([c,1.5,0],0))}var v,x;let b=c>0&&g.shift();b&&(un(b),b.setParameters({length:c,width:i,height:s,counterHeight:0,materials:{...y}}),b.setTransform([0,0,0],0));let _=d>0&&g.shift();_&&(un(_),_.setParameters({length:d,width:i,height:s,counterHeight:0,materials:{...y}}),_.setTransform([c+p,0,0],0))}const pn={length:3,width:.6,height:2.2,wallCabinet:!0,leftHighCabinetCount:1,rightHighCabinetCount:0,sinkElementSlot:-1,cooktopElementSlot:-1,ovenElementSlot:-1,materials:{cabinet:"asm:cabinet_paint_white",cabinetDoors:"asm:cabinet_paint_white",counter:"asm:cabinet_paint_white"}};class fn extends Xr{constructor(t){super(t,"element:kitchen"),this.parameters=JSON.parse(JSON.stringify(pn))}setParameters(t,e=!1){super.setParameters(t),e||dn(this),this.emit("element-parameters-change",this)}}const mn={length:2,width:.05,height:1,segmentCount:0,segmentLength:.12,materials:{surface:"#CCCCCC"}};class gn extends Xr{constructor(t){super(t,"element:railing"),this.parameters=JSON.parse(JSON.stringify(mn))}setParameters(t){super.setParameters(t)}}const yn={length:2,width:1,height:.5,materials:{top:"asm:basic-floor",bottom:"asm:basic-wall",sides:"asm:basic-wall"}};class vn extends Xr{constructor(t){super(t,"element:ramp"),this.parameters=JSON.parse(JSON.stringify(yn))}}const xn={materials:{}};class bn extends Xr{constructor(t){super(t,"element:roof"),this.parameters=JSON.parse(JSON.stringify(xn))}}const _n={type:"curve:rectangle",dimensions:[1,1]},wn={"curve:circle":{type:"curve:circle",radius:1},"curve:rectangle":{..._n},"curve:polygon":{type:"curve:polygon",points:[[0,0],[1,0],[1,1],[0,1]]},"curve:polygonWithHoles":{type:"curve:polygonWithHoles",polygons:[[[0,0],[1,0],[1,1],[0,1]],[[.25,.25],[.25,.75],[.75,.75],[.75,.25]]]}},Pn={profile:{..._n},height:.1,materials:{top:"asm:basic-floor",bottom:"asm:basic-floor",sides:"asm:basic-wall"}};class En extends Xr{constructor(t){super(t,"element:slab"),this.parameters=JSON.parse(JSON.stringify(Pn))}setParameters(t){var e;(null==(e=t.profile)?void 0:e.type)&&t.profile.type!==this.parameters.profile.type&&(this.parameters.profile=JSON.parse(JSON.stringify(wn[t.profile.type]))),super.setParameters(t)}}const Tn={height:3,width:1.2,materials:{steps:"asm:basic-wall",tread:"asm:basic-floor"}},An={straight:{stairFlightType:"straight",length:3,...Tn},spiral:{stairFlightType:"spiral",angle:270,radius:1.5,circulation:"right",...Tn}};class In extends Xr{constructor(t){super(t,"element:stairFlight"),this.parameters=JSON.parse(JSON.stringify(An.straight))}setParameters(t){if(t.stairFlightType&&this.parameters.stairFlightType!==t.stairFlightType){let{height:e,materials:i,width:s}=this.parameters;this.parameters={...JSON.parse(JSON.stringify(An[t.stairFlightType])),height:e,materials:i,width:s}}super.setParameters(t)}}function Sn(t,e,i){let s=t.elements.filter((t=>t.type===e));for(let r=s.length-1;r>=i;r--)t.removeElement(s[r]);for(let r=0;r<i;r++)if(!s[r]){let i=de();s[r]="element:stairFlight"===e?new In(i):new En(i),t.insertElement(s[r])}return s}const Cn=.1;const Mn={height:3,railing:"right",materials:{steps:"asm:basic-wall",tread:"asm:basic-floor",railing:"#CCCCCC"}},On={straight:{stairsType:"straight",length:4,width:1.2,...Mn},straightLanding:{stairsType:"straightLanding",length:4,width:1.2,...Mn},halfLanding:{stairsType:"halfLanding",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},quarterLanding:{stairsType:"quarterLanding",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},twoQuarterLanding:{stairsType:"twoQuarterLanding",length:3,width:4,stepWidth:1.2,circulation:"right",...Mn},winder:{stairsType:"winder",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},doubleWinder:{stairsType:"doubleWinder",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},spiral:{stairsType:"spiral",radius:1.5,angle:270,stepWidth:1.2,circulation:"right",...Mn},custom:{stairsType:"custom",stepWidth:1.2,...Mn}},Nn=On.straight;class Ln extends Xr{constructor(t){super(t,"element:stairs"),this.parameters=JSON.parse(JSON.stringify(Nn))}setParameters(t,e=!1){if(t.stairsType&&this.parameters.stairsType!==t.stairsType){let{height:e,railing:i,materials:s}=this.parameters;this.parameters={...JSON.parse(JSON.stringify(On[t.stairsType])),height:e,railing:i,materials:s}}super.setParameters(t),e||function(t){switch(t.parameters.stairsType){case"straight":{let{length:e,width:i,height:s,materials:r}=t.parameters,[n]=Sn(t,"element:stairFlight",1);Sn(t,"element:slab",0),n.setParameters({stairFlightType:"straight",length:e,width:i,height:s,materials:{steps:r.steps,tread:r.tread}}),n.setTransform([0,0,0],0);break}case"straightLanding":{let{length:e,width:i,height:s,materials:r}=t.parameters,n=(e-i)/2,[o,a]=Sn(t,"element:stairFlight",2),[l]=Sn(t,"element:slab",1);o.setParameters({stairFlightType:"straight",length:n,width:i,height:s/2,materials:{steps:r.steps,tread:r.tread}}),o.setTransform([0,0,0],0),l.setParameters({profile:{type:"curve:rectangle",dimensions:[i,i]},height:Cn,materials:{top:r.tread,bottom:r.steps,sides:r.steps}}),l.setTransform([n,s/2-Cn,0],0),a.setParameters({stairFlightType:"straight",length:n,width:i,height:s/2}),a.setTransform([e-n,s/2,0],0);break}case"halfLanding":{let{length:e,width:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,[l,h]=Sn(t,"element:stairFlight",2),[u]=Sn(t,"element:slab",1);l.setParameters({stairFlightType:"straight",length:e-r,width:r,height:s/2,materials:{steps:o.steps,tread:o.tread}}),l.setTransform([0,0,a?0:-r],0),u.setParameters({profile:{type:"curve:rectangle",dimensions:[r,i]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),u.setPosition([e-r,s/2-Cn,a?0:-i]),h.setParameters({stairFlightType:"straight",length:e-r,width:r,height:s/2,materials:{steps:o.steps,tread:o.tread}}),h.setTransform([e-r,s/2,a?i:-i+r],-180);break}case"quarterLanding":{let{length:e,width:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,l=e-r,h=i-r,u=l/(l+h)*s,c=h/(l+h)*s,[d,p]=Sn(t,"element:stairFlight",2),[f]=Sn(t,"element:slab",1);d.setParameters({stairFlightType:"straight",length:l,width:r,height:u,materials:{steps:o.steps,tread:o.tread}}),d.setTransform([0,0,a?0:-r],0),f.setParameters({profile:{type:"curve:rectangle",dimensions:[r,r]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),f.setPosition([e-r,u-Cn,a?0:-r]),p.setParameters({stairFlightType:"straight",length:h,width:r,height:c,materials:{steps:o.steps,tread:o.tread}}),a?p.setTransform([e,u,r],-90):p.setTransform([e-r,u,-r],90);break}case"twoQuarterLanding":{let{length:e,width:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,l=e-r,h=i-2*r,u=l/(2*l+h)*s,c=h/(2*l+h)*s,[d,p,f]=Sn(t,"element:stairFlight",3),[m,g]=Sn(t,"element:slab",2);d.setParameters({stairFlightType:"straight",length:l,width:r,height:u,materials:{steps:o.steps,tread:o.tread}}),d.setTransform([0,0,a?0:-r],0),m.setParameters({profile:{type:"curve:rectangle",dimensions:[r,r]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),m.setPosition([e-r,u-Cn,a?0:-r]),p.setParameters({stairFlightType:"straight",length:h,width:r,height:c,materials:{steps:o.steps,tread:o.tread}}),a?p.setTransform([e,u,r],-90):p.setTransform([e-r,u,-r],90),g.setParameters({profile:{type:"curve:rectangle",dimensions:[r,r]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),g.setPosition([e-r,u+c-Cn,a?i-r:-i]),f.setParameters({stairFlightType:"straight",length:l,width:r,height:u,materials:{steps:o.steps,tread:o.tread}}),f.setTransform([e-r,u+c,a?i:-i+r],-180);break}case"spiral":{let{radius:e,angle:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,[l]=Sn(t,"element:stairFlight",1);Sn(t,"element:slab",0),l.setParameters({stairFlightType:"spiral",radius:e,angle:i,height:s,width:r,circulation:n,materials:{steps:o.steps,tread:o.tread}}),l.setTransform([0,0,a?e:-e],0);break}}}(this),this.emit("element-parameters-change",this)}getBoundingBox(t=!1){const e=super.getBoundingBox(t);return"radius"in this.parameters&&(e.min[2]=0,e.max[2]=2*this.parameters.radius,e.min[0]=-this.parameters.radius,e.max[0]=this.parameters.radius),"circulation"in this.parameters&&"left"===this.parameters.circulation&&(e.min[2]=-e.max[2],e.max[2]=0),e}}const Rn={length:1,height:1.2,frameThickness:.05,frameDepth:.1,panelLength:0,panelCount:1,materials:{frame:"#CCCCCC",panel:"asm:glass"}};class kn extends Xr{constructor(t){super(t,"element:window"),this.parameters=JSON.parse(JSON.stringify(Rn))}setParameters(t){super.setParameters(t)}}class Bn extends _s{constructor(){super(...arguments),this.position=[0,0,0],this.rotation=0}copyForClone(t){super.copyForClone(t),this.position=[...t.position],this.rotation=t.rotation,this.parameters=JSON.parse(JSON.stringify(t.parameters))}setTransform(t,e){this.position=[...t],this.rotation=e,this.emit("annotation-transform-change",this)}setParameters(t){Ms(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("annotation-parameters-change",this)}toJSON(){return{...super.toJSON(),position:[...this.position],parameters:JSON.parse(JSON.stringify(this.parameters)),rotation:this.rotation}}}const Fn={uri:"",drawingOrigin:[0,0],drawingUnits:"unitLess",hiddenLayers:[]};class Dn extends Bn{constructor(t){super(t,"annotation:floorPlanDxf"),this.parameters=JSON.parse(JSON.stringify(Fn))}setParameters(t){super.setParameters(t)}}class Un extends _s{copyForClone(t){super.copyForClone(t),this.parameters=JSON.parse(JSON.stringify(t.parameters))}setParameters(t){Ms(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("view-parameters-change",this)}toJSON(){return{...super.toJSON(),parameters:JSON.parse(JSON.stringify(this.parameters))}}}const Gn={style:{background:{fill:"#f7f8fa"},units:"metric",byId:{},byType:{},byAttribute:{program:{},usage:{}}},hidden:[]};class Xn extends Un{constructor(t){super(t,"view:2d"),this.parameters=JSON.parse(JSON.stringify(Gn))}setParameters(t){var e,i;let{style:s}=t;void 0===(null==s?void 0:s.byId)&&(this.parameters.style.byId={}),void 0===(null==s?void 0:s.byType)&&(this.parameters.style.byType={}),void 0===(null==(e=null==s?void 0:s.byAttribute)?void 0:e.program)&&(this.parameters.style.byAttribute.program={}),void 0===(null==(i=null==s?void 0:s.byAttribute)?void 0:i.usage)&&(this.parameters.style.byAttribute.usage={}),Ms(this.parameters,t,{onNewKeys:{allow:!1},copyScopes:[".style.byId",".style.byType",".style.byAttribute.program",".style.byAttribute.usage"],cloneObjects:!0}),this.emit("view-parameters-change",this)}}const Wn={position:[0,0,0],normal:[0,0,1],fov:"default",scale:1,lensShiftX:0,lensShiftY:0,projection:"perspective"};class Hn extends Un{constructor(t){super(t,"view:3d"),this.parameters=JSON.parse(JSON.stringify(Wn))}setParameters(t){super.setParameters(t)}}const Yn="relation:group";class $n extends we{constructor(t){super(t,Yn),this.elements=new Set}insertElements(t){for(let e of t)this.elements.add(e)}removeElements(t){for(let e of t)this.elements.delete(e)}copyForClone(t){super.copyForClone(t)}toJSON(){const t=super.toJSON();return t.elements=Array.from(this.elements).map((t=>t.id)),t}}class jn extends bs{constructor(t,e){super(t,e)}}function zn(t,e){e.registerNode(t),function(t,e){let{vertices:i,edges:s}=t.spatialGraph;for(let r of i)e.registerNode(r),e.emit("vertex-create",r);for(let r of s)e.registerNode(r),e.emit("edge-create",r)}(t,e);for(let s of t.spaces)e.registerNode(s);let i=t.getElementList();for(let s of i)e.registerNode(s);for(let s of t.annotations)e.registerNode(s);for(let s of t.views)e.registerNode(s);e.emit("spatial-structure-create",t)}function Vn(t,e){e.unregisterNode(t),function(t,e){let{vertices:i,edges:s}=t.spatialGraph;for(let r of i)e.unregisterNode(r),e.emit("vertex-delete",r);for(let r of s)e.unregisterNode(r),e.emit("edge-delete",r)}(t,e);for(let s of t.spaces)e.unregisterNode(s);let i=t.getElementList();for(let s of i)e.unregisterNode(s);for(let s of t.annotations)e.unregisterNode(s);e.emit("spatial-structure-delete",t)}function qn(t,e){e.registerNode(t);for(let i of t.layouts)zn(i,e);e.emit("spatial-structure-create",t)}function Jn(t,e){e.unregisterNode(t);for(let i of t.layouts)Vn(i,e);e.emit("spatial-structure-delete",t)}function Kn(t,e,...i){let s;switch(t){case"element:ceiling":case"element:floor":s=new Vs(e,t,i[0]);break;case"element:boundaryWall":s=new Er(e,i[0]);break;case"element:curtainWall":s=new Ar(e,i[0]);break;case"element:spaceDivider":s=new Sr(e,i[0]);break;case"element:wall":s=new js(e,i[0]);break;case"element:opening":s=new Gr(e);break;case"element:asset":s=new Hr(e);break;case"element:beam":s=new $r(e);break;case"element:casework":s=new zr(e);break;case"element:column":s=new Kr(e);break;case"element:door":s=new Qr(e);break;case"element:generic":s=new sn(e);break;case"element:kitchen":s=new fn(e);break;case"element:ramp":s=new vn(e);break;case"element:roof":s=new bn(e);break;case"element:railing":s=new gn(e);break;case"element:slab":s=new En(e);break;case"element:stairs":s=new Ln(e);break;case"element:stairFlight":s=new In(e);break;case"element:window":s=new kn(e)}return s}const Zn={uri:"",length:1,width:1};class Qn extends Bn{constructor(t){super(t,"annotation:floorPlanImage"),this.parameters=JSON.parse(JSON.stringify(Zn))}setParameters(t){super.setParameters(t)}}function to(t,e){let i;switch(t){case"annotation:floorPlanDxf":i=new Dn(e);break;case"annotation:floorPlanImage":i=new Qn(e)}return i}function eo(t,e){let i;switch(t){case"view:2d":i=new Xn(e);break;case"view:3d":i=new Hn(e)}return i}class io{constructor(){this.nodeMap=new Map}addNode(t){return this.nodeMap.has(t)||this.nodeMap.set(t,new Map),this.nodeMap.get(t)}addEdge(t,e,i){var s,r;let n=this.addNode(e),o=this.addNode(i);n.has(t)||n.set(t,new Set),o.has(t)||o.set(t,new Set),null==(s=n.get(t))||s.add(i),null==(r=o.get(t))||r.add(e)}removeNode(t){if(this.nodeMap.has(t)){for(let e of this.nodeMap.get(t))for(let i of e[1])this.removeEdge(e[0],t,i);this.nodeMap.delete(t)}}removeEdge(t,e,i){var s,r,n,o;null==(r=null==(s=this.nodeMap.get(e))?void 0:s.get(t))||r.delete(i),null==(o=null==(n=this.nodeMap.get(i))?void 0:n.get(t))||o.delete(e)}findShortestPath(t,e,i,s={}){var r;let n=[[e]],o=new Set;for(;n.length>0;){let e=n.shift();if(!e)return null;if(s.depthLimit&&e.length-1>s.depthLimit)return null;let a=e[e.length-1];if(a===i)return e;if(!o.has(a)&&this.nodeMap.has(a)&&(null==(r=this.nodeMap.get(a))?void 0:r.has(t))){o.add(a);for(let i of this.nodeMap.get(a).get(t))n.push([...e,i])}}return null}toJSON(){const t=[],e=[];for(const[i,s]of this.nodeMap.entries()){t.push({id:i.id,type:i.type});for(const[t,r]of s.entries())for(const s of r)i.id<s.id&&e.push({type:String(t),nodes:[i.id,s.id]})}return{nodes:t,edges:e}}}const so=t=>{const e={};for(const i in t)e[i]=[];return e},ro={"element:ceiling":Vs,"element:floor":Vs,"element:boundaryWall":Er,"element:curtainWall":Ar,"element:spaceDivider":Sr,"element:wall":js,"element:opening":Gr,"element:asset":Hr,"element:beam":$r,"element:casework":zr,"element:column":Kr,"element:door":Qr,"element:generic":sn,"element:kitchen":fn,"element:railing":gn,"element:ramp":vn,"element:roof":bn,"element:slab":En,"element:stairs":Ln,"element:stairFlight":In,"element:window":kn},no={"annotation:floorPlanDxf":Dn,"annotation:floorPlanImage":Qn},oo={"view:2d":Xn,"view:3d":Hn};const ao="spatialStructure:layout";class lo extends jn{constructor(t){super(t,ao),this.parent=null,this.spaces=[],this.spacesById={},this.elements=[],this.elementsById={},this.elementsByType=so(ro),this.annotations=[],this.annotationsById={},this.annotationsByType=so(no),this.views=[],this.viewsById={},this.viewsByType=so(oo),this.debugIds=!1,this.suggestedIds={},this.spatialGraph=new wr(this)}copyForClone(t){super.copyForClone(t),this.debugIds=t.debugIds,this.suggestedIds={...t.suggestedIds}}insertSpace(t){Es(this,t,this.spacesById,"Space")&&(!function(t,e){for(let i of t.elements)"element:ceiling"!==i.type&&"element:floor"!==i.type||pr(e.boundaries,i.boundaries)&&e.attachSlab(i)}(this,t),t.layout=this,this.spaces.push(t),this.spacesById[t.id]=t,t.boundaries.length&&(this.spatialGraph.graphChanged=!0),this.spaceGraph&&(this.spaceGraph.registerNode(t),this.spaceGraph.emit("space-create",t)))}removeSpace(t){let e=this.spaces.indexOf(t);if(-1!==e){if(function(t){let e=t.slabs.slice();for(let i of e)t.detachSlab(i);for(let i of t.boundaries)for(let e of i.edges)e.spaces[0]===t&&(e.spaces[0]=null),e.spaces[1]===t&&(e.spaces[1]=null)}(t),this.spaces.splice(e,1),this.spacesById[t.id]===t)return delete this.spacesById[t.id],this.spaceGraph&&(this.spaceGraph.unregisterNode(t),this.spaceGraph.emit("space-delete",t)),t.layout=null,t;be.error(`Entry ${t.id} in 'spaces stored by ID' record does not contain this object.`)}else be.warn(`Space ${t.id} not found.`)}createSpace(t,e){let i=new Ws(t,e);return this.insertSpace(i),i}insertElement(t){Es(this,t,this.elementsById,"Element",!0)&&(!function(t,e){switch(e.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":nr(t,e);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":or(t,e)}}(this,t),this.elements.push(t),Ts(this,t))}removeElement(t){if(t.layout!==this)return void be.warn(`Element ${t.id} not part of layout ${this.id}.`);if(t.parent)return void be.warn(`Element ${t.id} not a root element, cannot remove from layout.`);ar(t);let e=this.elements.indexOf(t);if(-1!==e)return this.elements.splice(e,1),As(this,t,null),t;be.warn(`Element ${t.id} not found.`)}createElement(t,e,...i){let s=Kn(t,e,...i);return this.insertElement(s),s}insertNode(t){let{nodes:e,nodesById:i,nodesByType:s}=_r(this,t);t.layout=this,e.push(t),i[t.id]=t,s[t.type]||(s[t.type]=[]),s[t.type].push(t)}removeNode(t){let{name:e,nodes:i,nodesById:s,nodesByType:r}=_r(this,t),n=i.indexOf(t);if(-1===n)return void be.warn(`Node ${t.id} not found in '${e}' list.`);if(i.splice(n,1),s[t.id]!==t)return void be.error(`Entry ${t.id} in '${e} stored by ID' record does not contain this object.`);delete s[t.id];let o=r[t.type],a=null==o?void 0:o.indexOf(t);o&&-1!==a?r[t.type].splice(a,1):be.error(`Node ${t.id} not found in '${e} stored by type' record.`)}insertAnnotation(t){Es(this,t,this.annotationsById,"Annotation")&&(this.insertNode(t),this.spaceGraph&&(this.spaceGraph.registerNode(t),this.spaceGraph.emit("annotation-create",t)))}removeAnnotation(t){return this.removeNode(t),this.spaceGraph&&(this.spaceGraph.unregisterNode(t),this.spaceGraph.emit("annotation-delete",t)),t.layout=null,t}createAnnotation(t,e){let i=to(t,e);return this.insertAnnotation(i),i}insertView(t){Es(this,t,this.viewsById,"View")&&(this.insertNode(t),this.spaceGraph&&(this.spaceGraph.registerNode(t),this.spaceGraph.emit("view-create",t)))}removeView(t){return this.removeNode(t),this.spaceGraph&&(this.spaceGraph.unregisterNode(t),this.spaceGraph.emit("view-delete",t)),t.layout=null,t}createView(t,e){let i=eo(t,e);return this.insertView(i),i}clearSpaces(){let t=[...this.spaces];for(let e of t)this.removeSpace(e)}getElementList(){return Object.values(this.elementsById)}getArea(t={program:{exclude:["void"]}}){var e,i;let s=(null==(e=null==t?void 0:t.program)?void 0:e.include)??[],r=(null==(i=null==t?void 0:t.program)?void 0:i.exclude)??[];if(s.length&&r.length)return be.warn("Cannot use 'include' and 'exclude' filters at the same time, skipping area calculation."),0;let n=0;for(let o of this.spaces){let t=!1;s.length&&(t=s.includes(o.attributes.program)),r.length&&(t=r.includes(o.attributes.program)),t||(n+=o.getArea())}return n}getLayoutGraph(){var t;let e=new io,i=this.elementsByType["element:spaceDivider"].slice();for(let s of this.elementsByType["element:opening"])"element:window"!==(null==(t=s.elements[0])?void 0:t.type)&&i.push(s);for(let s of i)for(let t of s.getSpaces())t&&e.addEdge("graph:connectedTo",t,s);for(let s of this.spatialGraph.edges)s.spaces[0]&&s.spaces[1]&&e.addEdge("graph:adjacentTo",s.spaces[0],s.spaces[1]);return e}getUniqueId(t,e){let i=0,s=t+i++;for(;this.suggestedIds[s]||e[s];)s=t+i++;return this.suggestedIds[s]=!0,s}getSpaceId(t){let e;return t=t??"space-",e=this.debugIds?this.getUniqueId(t,this.spacesById):de(),e}getElementId(t,e){let i;return e=e??t.type.split(":")[1]+"-",i=this.debugIds?this.getUniqueId(e,this.elementsById):de(),i}getBoundingBox(){const t={position:[0,0,0],rotation:0,rotationAxis:[0,1,0]};if(0===this.spaces.length)return{min:[0,0,0],max:[0,0,0],transform:t};const e=[];for(const r of this.spaces){const{min:t,max:i}=r.getAxisAlignedBoundingBox();e.push(t,i)}for(const r of this.getElementList()){const{min:t,max:i}=r.getAxisAlignedBoundingBox();e.push(t,i)}const{min:i,max:s}=ds(e.flat());return{min:i,max:s,transform:t}}toJSON(){let t=this.spatialGraph.toJSON(),e=function(t){let e=[];for(let i of t.spaces){let t=i.toJSON();e.push(t)}return e}(this),i=function(t){let e=[];for(let i of t.elements){let t=i.toJSON();t&&e.push(t)}return e}(this),s=function(t){let e=[];for(let i of t.annotations){let t=i.toJSON();e.push(t)}return e}(this),r=function(t){let e=[];for(let i of t.views){let t=i.toJSON();e.push(t)}return e}(this);return{...super.toJSON(),spatialGraph:t,spaces:e,elements:i,annotations:s,views:r}}}const ho="spatialStructure:floor";class uo extends jn{constructor(t){super(t,ho),this.parent=null,this.position=[0,0,0],this.rotation=0,this.layouts=[]}copyForClone(t){super.copyForClone(t),this.position=[...t.position],this.rotation=t.rotation}insertLayout(t){t.parent?be.warn(`SpaceGraphLayout ${t.id} already part of floor ${t.parent.id}.`):(t.parent=this,this.layouts.push(t),this.spaceGraph&&zn(t,this.spaceGraph))}removeLayout(t){-1!==this.layouts.indexOf(t)?(this.spaceGraph&&Vn(t,this.spaceGraph),t.parent=null):be.warn(`Floor ${t.id} not found.`)}createLayout(t){let e=new lo(t);return this.insertLayout(e),e}toJSON(){const t={...super.toJSON(),position:[...this.position],rotation:this.rotation,layouts:[]};for(let e of this.layouts){let i=e.toJSON();t.layouts.push(i)}return t}}const co="spatialStructure:building";class po extends jn{constructor(t){super(t,co),this.floors=[],this.location={latLong:[0,0],rotation:0}}copyForClone(t){super.copyForClone(t),this.location=JSON.parse(JSON.stringify(t.location))}insertFloor(t){t.parent?be.warn(`Floor ${t.id} already part of building ${t.parent.id}.`):(t.parent=this,this.floors.push(t),this.spaceGraph&&qn(t,this.spaceGraph))}removeFloor(t){-1!==this.floors.indexOf(t)?(this.spaceGraph&&Jn(t,this.spaceGraph),t.parent=null):be.warn(`Floor ${t.id} not found.`)}createFloor(t){let e=new uo(t);return this.insertFloor(e),e}toJSON(){let t={...super.toJSON(),floors:[]},e=this.location;e.latLong[0]&&e.latLong[1]&&e.rotation&&(t.location={latLong:[...e.latLong],rotation:e.rotation});for(let i of this.floors){let e=i.toJSON();t.floors.push(e)}return t}}const fo={...ro,"spatialGraph:edge":Us,"spatialGraph:vertex":Ps,"layout:space":Ws,"view:2d":Xn,"view:3d":Hn,"annotation:floorPlanDxf":Dn,"annotation:floorPlanImage":Qn};class mo extends we{constructor(t,e){super(t,e),this.position=[0,0,0],this.rotation=0,this.rotationAxis=[0,1,0],this.surfaces={},this.materials={},this.boundingBox={min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]}}}class go extends mo{constructor(t,e){super(t,e),this.normals="generator",this.uvs="generator",this.geometries=[]}}const yo={"geometry:plane":class extends go{constructor(t){super(t,"geometry:plane"),this.normal=[0,1,0],this.size=1,this.doubleSided=!1}},"geometry:cuboid":class extends go{constructor(t){super(t,"geometry:cuboid"),this.dimensions=[1,1,1]}},"geometry:sphere":class extends go{constructor(t){super(t,"geometry:sphere"),this.radius=1}},"geometry:extrusion":class extends go{constructor(t,e){super(t,"geometry:extrusion"),this.height=1,this.profile=e}},"geometry:mesh":class extends mo{constructor(t){super(t,"geometry:mesh"),this.vertices=[],this.indices=[],this.normals=[],this.uvs=[]}},"geometry:uri":class extends mo{constructor(t){super(t,"geometry:uri"),this.format="data3d",this.uri="",this.normals="smooth"}}},vo={"material:embedded":Se,"material:basic":Me,"material:color":Ee,"material:standard":Ae},xo={"product:static":an,"product:component":hn},bo={"relation:group":$n},_o={...fo,...yo,...vo,...xo,...bo,"spatialStructure:building":po,"spatialStructure:floor":uo,"spatialStructure:layout":lo};class wo{constructor(t){this.products=[],this.productsById={},this.productsByType=so(xo),this.customAttributes=[],this.customAttributesById={},this.customAttributesByType=so(xs),this.geometries=[],this.geometriesById={},this.geometriesByType=so(yo),this.materials=[],this.materialsById={},this.materialsByType=so(vo),this.relations=[],this.relationsById={},this.relationsByType=so(bo),this.nodes=[],this.nodesById={},this.nodesByType=so(_o),this.spatialStructure=null,this.emitter=new ye,this.sourceSchemaVersion=t}getEvents(){return this.emitter.e??{}}copyEvents(t){let e=t.getEvents();for(let[i,s]of Object.entries(e))this.emitter.on(i,s)}deleteNodeAtIndex(t,e,i,s){let r=e[t];if(e.splice(t,1),i[r.id]!==r)return void be.error(`Entry ${r.id} in 'nodes stored by ID' record does not contain this object.`);delete i[r.id];let n=s[r.type];if(!n)return void be.error(`Node ${r.id} not found in 'nodes stored by type' record.`);let o=n.indexOf(r);if(-1!==o)return n.splice(o,1),r;be.error(`Node ${r.id} not found in 'nodes stored by type' record.`)}insertNode(t,e,i,s){i[t.id]?be.error(`Node ${t.id} already registered.`):(e.push(t),i[t.id]=t,s[t.type]||(s[t.type]=[]),s[t.type].push(t))}removeNode(t,e,i,s){let r=e.indexOf(t);if(-1!==r)return this.deleteNodeAtIndex(r,e,i,s),t;be.warn(`Node ${t.id} not found.`)}registerNode(t){t.spaceGraph=this;let{nodes:e,nodesById:i,nodesByType:s}=this;this.insertNode(t,e,i,s)}unregisterNode(t){t.spaceGraph=null;let{nodes:e,nodesById:i,nodesByType:s}=this;this.removeNode(t,e,i,s)}insertSpatialStructure(t){if(this.spatialStructure)be.warn(`Space graph object already has spatial structure ${this.spatialStructure.id} attached.`);else if(t.spaceGraph)be.warn(`Spatial structure ${t.id} already part of a space graph object.`);else{switch(t.spaceGraph=this,this.spatialStructure=t,t.type){case"spatialStructure:building":!function(t,e){e.registerNode(t);for(let i of t.floors)qn(i,e);e.emit("spatial-structure-create",t)}(t,this);break;case"spatialStructure:floor":qn(t,this);break;case"spatialStructure:layout":zn(t,this)}this.emit("spatial-structure-create",t)}}removeSpatialStructure(){let t=this.spatialStructure;if(t){switch(t.spaceGraph=null,this.spatialStructure=null,t.type){case"spatialStructure:building":!function(t,e){e.unregisterNode(t);for(let i of t.floors)Jn(i,e);e.emit("spatial-structure-delete",t)}(t,this);break;case"spatialStructure:floor":Jn(t,this);break;case"spatialStructure:layout":Vn(t,this)}return this.emit("spatial-structure-delete",t),t}be.warn("No spatial structure attached to space graph object.")}createSpatialStructure(t,e){let i;switch(t){case"spatialStructure:building":i=new po(e);break;case"spatialStructure:floor":i=new uo(e);break;case"spatialStructure:layout":i=new lo(e)}return this.insertSpatialStructure(i),i}insertProduct(t){t.spaceGraph?be.warn(`Product ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.products,this.productsById,this.productsByType),this.registerNode(t),this.emit("product-create",t))}removeProduct(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.products,this.productsById,this.productsByType),this.unregisterNode(t),this.emit("product-delete",t)):be.warn(`Product ${t.id} already in a detached state.`)}createProduct(t,e){let i;return i=e===ln?new hn(t):new an(t),this.insertProduct(i),i}insertGeometry(t){let{geometries:e,geometriesById:i,geometriesByType:s}=this;e.push(t),i[t.id]=t,s[t.type].push(t)}removeGeometry(t){let{geometries:e,geometriesById:i,geometriesByType:s}=this,r=e.indexOf(t);if(-1===r)return void be.warn(`Geometry ${t.id} not found.`);if(e.splice(r,1),i[t.id]!==t)return void be.error(`Entry ${t.id} in 'geometries stored by ID' record does not contain this object.`);delete this.geometriesById[t.id];let n=s[t.type];if(!n)return void be.error(`Geometry ${t.id} not found in 'geometries stored by type' record.`);let o=n.indexOf(t);-1!==o?n.splice(o,1):be.error(`Node ${t.id} not found in 'nodes stored by type' record.`)}insertMaterial(t){t.spaceGraph?be.warn(`Material ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.materials,this.materialsById,this.materialsByType),this.registerNode(t),this.emit("material-create",t))}removeMaterial(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.materials,this.materialsById,this.materialsByType),this.unregisterNode(t),this.emit("material-delete",t)):be.warn(`Material ${t.id} already in a detached state.`)}createMaterial(t,e,...i){let s;switch(t){case Pe:s=new Ee(e,i[0],i[1]);break;case Te:s=new Ae(e,i[0]);break;case Ie:s=new Se(e,i[0],i[1]);break;case Ce:s=new Me(e)}return this.insertMaterial(s),s}insertRelation(t){t.spaceGraph?be.warn(`Relation ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.relations,this.relationsById,this.relationsByType),this.registerNode(t),this.emit("relation-create",t))}removeRelation(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.relations,this.relationsById,this.relationsByType),this.unregisterNode(t),this.emit("relation-delete",t)):be.warn(`Relation ${t.id} already in a detached state.`)}createRelation(t,e){let i;if(t===Yn)i=new $n(e);return this.insertRelation(i),i}insertCustomAttribute(t){t.spaceGraph?be.warn(`Custom attribute ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.customAttributes,this.customAttributesById,this.customAttributesByType),this.registerNode(t),this.emit("custom-attribute-create",t))}removeCustomAttribute(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.customAttributes,this.customAttributesById,this.customAttributesByType),this.unregisterNode(t),this.emit("custom-attribute-delete",t)):be.warn(`Custom attribute ${t.id} already in a detached state.`)}getId(){return de()}emit(t,...e){this.emitter.emit(t,...e)}on(t,e,i){this.emitter.on(t,e,i)}once(t,e,i){this.emitter.once(t,e,i)}off(t,e){this.emitter.off(t,e)}toJSON(){let t=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.products),e=function(t){let e=[];for(let i of t){let t=b(i);e.push(t)}return e}(this.geometries),i=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.materials),s=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.relations),r=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.customAttributes);return{schemaVersion:"0.22.1",spatialStructure:this.spatialStructure.toJSON(),sharedResources:{products:t,geometries:e,materials:i,relations:s,customAttributes:r}}}}function Po(t,e,i,s){const r=1e-7*1e-7;let n=[e[0]-t[0],e[1]-t[1]],o=[s[0]-i[0],s[1]-i[1]],a=i[0]-t[0],l=i[1]-t[1],h=n[0]*o[1]-n[1]*o[0],u=h*h,c=n[0]*n[0]+n[1]*n[1];if(u>r*c*(o[0]*o[0]+o[1]*o[1])){let e=(a*o[1]-l*o[0])/h,i=(a*n[1]-l*n[0])/h;return{tag:2,intersect:!0,p:[t[0]+e*n[0],t[1]+e*n[1]],u:e,v:i}}return h=a*n[1]-l*n[0],u=h*h,u>r*c*(a*a+l*l)?{tag:0,intersect:!1}:{tag:1,intersect:!0}}function Eo(t,e,i,s){const r=[e[0]-t[0],e[1]-t[1]],n=[s[0]-i[0],s[1]-i[1]],o=i[0]-t[0],a=i[1]-t[1];let l=r[0]*n[1]-r[1]*n[0],h=l*l;const u=r[0]*r[0]+r[1]*r[1];let c,d,p,f;if(h>1e-14*u*(n[0]*n[0]+n[1]*n[1])){const e=(o*n[1]-a*n[0])/l;if(e<0||e>1)return{tag:0,intersect:!1};{const i=(o*r[1]-a*r[0])/l;return i<0||i>1?{tag:0,intersect:!1}:(c=t[0]+e*r[0],d=t[1]+e*r[1],{tag:1,intersect:!0,p:[c,d],u:e,v:i})}}if(l=o*r[1]-a*r[0],h=l*l,h>1e-14*u*(o*o+a*a))return{tag:2,intersect:!1};{const e=(r[0]*o+r[1]*a)/u,i=e+(r[0]*n[0]+r[1]*n[1])/u;let s,l;e<i?(s=e,l=i):(s=i,l=e);const h=function(t,e,i,s){if(e<i||t>s)return{tag:0,intersect:!1};if(t===i&&e===s)return{tag:1,intersect:!0};if(e>i)return e<s?{tag:3,intersect:!0,w0:t<i?i:t,w1:e>s?s:e}:{tag:2,intersect:!0,w:t};return{tag:2,intersect:!0,w:e}}(0,1,s,l);switch(h.tag){case 0:return{tag:3,intersect:!1};case 1:return{tag:4,intersect:!0};case 2:{const e=h.w;return c=t[0]+e*r[0],d=t[1]+e*r[1],{tag:5,intersect:!0,p:[c,d],u:e}}case 3:{const e=h.w0,i=h.w1;return c=t[0]+e*r[0],d=t[1]+e*r[1],p=t[0]+i*r[0],f=t[1]+i*r[1],{tag:6,intersect:!0,p:[c,d],q:[p,f],u0:e,u1:i}}default:throw new Error("Unknown tag value.")}}}function To(t,e){let i=t.spatialGraph,s=new ps;for(let r of e.edges){let t=i.edgesById[r];if(!t)return void be.warn(`Edge ${r} not found, skipping boundary.`);s.edges.push(t)}if(cr(s))return s}function Ao(t,e){let i=[];for(let s of e){let e=To(t,s);if(!e)return;i.push(e)}return i}function Io(t,e){let{id:i,position:s}=e,r=new Ps(i,s[0],s[1]);return Os(r,e),r}function So(t,e){let i=t.spatialGraph,s=e.vertices[0],r=e.vertices[1];if(s===r)return void be.warn(`Same vertex referenced twice, skipping edge ${e.id}.`);let n=i.verticesById[s],o=i.verticesById[r];if(!n||!o)return void be.warn(`One or both vertices not found, skipping edge ${e.id}.`);let a=new Us(e.id,n,o);return Os(a,e),a}function Co(t,e,i){let s=Ao(t,e.boundaries);if(!s)return void be.warn(`Invalid boundaries, skipping space ${e.id}.`);let r=new Ws(e.id,s);return Os(r,e),Ns(r,e,i),e.attributes&&r.setAttributes(e.attributes),r}function Mo(t,e){let i=to(e.type,e.id);return Os(i,e),i.setTransform(e.position,e.rotation??0),e.parameters&&i.setParameters(e.parameters),i}function Oo(t,e){let i=eo(e.type,e.id);return Os(i,e),e.parameters&&i.setParameters(e.parameters),i}const No={};function Lo(t,e,i){return No[t]||(No[t]={}),No[t][e]=i,i}const Ro={.15:t=>{if(("layout:space"===t.type||"element:floor"===t.type||"element:ceiling"===t.type)&&t.id.includes(":")){const e=JSON.parse(JSON.stringify(t));return e.id=de(),e}return t},.16:t=>{if("element:window"===t.type&&t.parameters&&"framePosition"in t.parameters){const e=JSON.parse(JSON.stringify(t));return delete e.parameters.framePosition,e}return t},"0.20.3":t=>{if("layout:space"===t.type||!t.parameters)return t;let e=!1;const i=JSON.parse(JSON.stringify(t.parameters));if("height"in i&&i.height<.01&&(i.height=.01,e=!0),"width"in i&&i.width<.01&&(i.width=.01,e=!0),"length"in i&&i.length<.01&&(i.length=.01,e=!0),e){const e=JSON.parse(JSON.stringify(t));return e.parameters=i,e}return t}};function ko(t,e){return!e||function(t,e){var i;if(void 0!==(null==(i=No[t])?void 0:i[e]))return No[t][e];const s=t.split(".").map((t=>parseInt(t))),r=e.split(".").map((t=>parseInt(t)));for(let n=0;n<Math.max(s.length,r.length);n++){const i=s[n]||0,o=r[n]||0;if(i>o)return Lo(t,e,1);if(i<o)return Lo(t,e,-1)}return Lo(t,e,0)}(e,t)<0}function Bo(t,e){let i=t;for(const s in Ro)ko(s,e)&&(i=Ro[s](i));return i}function Fo(t,e){var i;let{position:s,rotation:r,rotationAxis:n}=e;if(t.setTransform(s??[0,0,0],r??0,n),e.parameters){let s=!!(null==(i=e.elements)?void 0:i.length);!function(t,e,i=!1){switch(t.type){case"element:ceiling":case"element:floor":case"element:boundaryWall":case"element:curtainWall":case"element:spaceDivider":case"element:wall":case"element:opening":case"element:asset":case"element:beam":case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:ramp":case"element:roof":case"element:railing":case"element:slab":case"element:stairFlight":case"element:window":t.setParameters(e);break;case"element:kitchen":case"element:stairs":t.setParameters(e,i)}}(t,e.parameters,s)}"element:generic"!==e.type&&"element:asset"!==e.type||(t.geometries=e.geometries?JSON.parse(JSON.stringify(e.geometries)):[])}function Do(t,e,i){let s,r=Bo(e,null==i?void 0:i.sourceSchemaVersion);switch(r.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":s=function(t,e){let i=Ao(t,e.boundaries);if(!i)return void be.warn(`Invalid boundaries, skipping boundary wall ${e.id}.`);let s=Kn(e.type,e.id,i);return e.parameters&&s.setParameters(e.parameters),s}(t,r);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":s=function(t,e){let i=[];if(i=Array.isArray(e.edge)?e.edge:[e.edge],!i.length)return void be.warn(`Element ${e.id} references no edges and is skipped.`);let s=[];for(let n of i){let i=t.spatialGraph.edgesById[n];if(!i)return void be.warn(`Edge ${e.edge} not found, skipping edge element ${e.id}.`);s.push(i)}let r=Kn(e.type,e.id,s);return e.parameters&&r.setParameters(e.parameters),r}(t,r);break;case"element:opening":s=function(t,e){let i=Kn("element:opening",e.id);return e.parameters&&i.setParameters(e.parameters),i}(0,r);break;case"element:asset":s=function(t,e,i){let s=Kn(e.type,e.id);if(Fo(s,e),!e.product)return e.geometries||be.warn(`Element ${s.id} does not specify a 'geometries' field and does not reference a product.`),s;let r=t.spaceGraph??i;if(r){let t=r.nodesById[e.product];if(!t)return void be.warn(`Product ${e.product} not found, skipping element ${e.id}.`);s.setProduct(t)}else be.warn(`Layout not attached and space graph not passed as an argument, cannot find product ${e.product}.`);return s}(t,r,i);break;case"element:beam":case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:kitchen":case"element:railing":case"element:ramp":case"element:roof":case"element:slab":case"element:stairFlight":case"element:stairs":case"element:window":s=function(t,e){let i=Kn(e.type,e.id);return Fo(i,e),i}(0,r);break;default:return void be.warn(`Unknown element type '${r.type}', skipping element.`)}if(!s)return;Os(s,r),Ns(s,r,null==i?void 0:i.customAttributesById);let n=r.elements??[];for(let o of n){let e=Do(t,o,i);e&&s.insertElement(e)}return s}function Uo(t,e,i){Ns(t,e,i.customAttributesById),Os(t,e),function(t,e){let i=t.spatialGraph,s=e.spatialGraph;for(let r of s.vertices){let t=Io(0,r);i.insertVertex(t)}for(let r of s.edges){let e=So(t,r);e&&i.insertEdge(e)}}(t,e),function(t,e,i){for(let s of e.spaces){let e=Co(t,Bo(s),i.customAttributesById);e&&t.insertSpace(e)}}(t,e,i),function(t,e,i){for(let s of e.elements){let e=Do(t,s,i);e&&t.insertElement(e)}}(t,e,i),function(t,e){let i=e.annotations??[];for(let s of i){let e=Mo(0,s);t.insertAnnotation(e)}}(t,e),function(t,e){let i=e.views??[];for(let s of i){let e=Oo(0,s);t.insertView(e)}}(t,e),function(t){const e=t.spatialGraph.edges;for(const s of e)s.spaces=[null,null],s.boundaryWalls=[null,null];const i=[];for(const s of t.spaces)ir(s),i.push(lr(s));for(const s of e){if(null!==s.spaces[0]||null!==s.spaces[1])continue;const[e,r]=s.getPoints(),n=ui(e,r,.5);for(let o=0;o<t.spaces.length;o++)if(wi(n,i[o])){s.spaces[0]=t.spaces[o],s.spaces[1]=t.spaces[o];break}}for(const s of t.elements)"element:boundaryWall"===s.type&&sr(s)}(t)}function Go(t,e){t.name=e.name??t.name,t.customId=e.customId??t.customId}function Xo(t,e){let i;return t.type===ln?(i=new hn(t.id),i.products=JSON.parse(JSON.stringify(t.products))):(i=new an(t.id),i.geometries=JSON.parse(JSON.stringify(t.geometries))),t.attributes&&i.setAttributes(t.attributes),t.customAttributes&&i.setCustomAttributes(t.customAttributes,e),Go(i,t),i}function Wo(t){return JSON.parse(JSON.stringify(t))}function Ho(t){let e;if(Array.isArray(t)||"string"==typeof t)be.warn("Color literal or standard material reference not allowed in shared resources section.");else if("object"==typeof t)switch(t.type){case Pe:let[i,s,r,n]=function(t){let[e,i,s,r]=[1,1,1,1];return Array.isArray(t)?[e,i,s,r]=Ue(t):"string"==typeof t&&([e,i,s,r]=[1,1,1,1],""===t?be.warn("Empty string not a valid color literal."):t.startsWith("#")?[e,i,s,r]=Ge(t):t.startsWith("rgb(")?[e,i,s,r]=Xe(t,!1):t.startsWith("rgba(")?[e,i,s,r]=Xe(t,!0):be.warn(`String ${t} not a valid color literal.`)),[e,i,s,r]}(t.value);e=new Ee(t.id,[i,s,r],n);break;case Te:e=new Ae(t.id,t.reference);break;case Ce:e=new Me(t.id),Go(e,t),e.colorDiffuse=[...t.colorDiffuse],t.colorSpecular&&(e.colorSpecular=[...t.colorSpecular]),e.specularCoefficient=t.specularCoefficient??e.specularCoefficient,e.opacity=t.opacity??e.opacity;break;default:e=new Ee(t.id,[1,1,1],1),be.warn(`Unknown material type ${t.type}, creating default material.`)}else be.warn("Material not an array, string or object.");return e}function Yo(t,e){let i;if(e.type===Yn){i=new $n(e.id);let s=[];for(let r of e.elements)t.nodesById[r]?s.push(t.nodesById[r]):be.error(`Element ${r} not found, referenced by relation ${i.id}.`);i.insertElements(s)}return Go(i,e),i}function $o(t,e){let i=new uo(e.id);Go(i,e),Ns(i,e,t.customAttributesById),i.position=[...e.position],i.rotation=e.rotation;for(let s of e.layouts){let e=zo(t,s);i.insertLayout(e)}return i}function jo(t){const e=function(t){const{id:e,attributes:{resourceType:i}}=t;return e.endsWith(`:${i}`)?e:`${e}:${i}`}(t),i=new vs(e,t.attributes);return Go(i,t),i}function zo(t,e){let i=new lo(e.id);return Uo(i,e,t),i}function Vo(t,e){let i;switch(e.type){case co:i=function(t,e){let i=new po(e.id);Go(i,e),Ns(i,e,t.customAttributesById),e.location&&(i.location=JSON.parse(JSON.stringify(i.location)));for(let s of e.floors){let e=$o(t,s);i.insertFloor(e)}return i}(t,e);break;case ho:i=$o(t,e);break;case ao:i=zo(t,e)}return i}function qo(t,e){!function(t,e){for(let i of e){let e=jo(i);e&&t.insertCustomAttribute(e)}}(t,e.customAttributes||[]),function(t,e){for(let i of e){let e=Xo(i,t.customAttributesById);t.insertProduct(e)}}(t,e.products),function(t,e){for(let i of e){let e=Wo(i);t.insertGeometry(e)}}(t,e.geometries),function(t,e){for(let i of e){let e=Ho(i);e&&t.insertMaterial(e)}}(t,e.materials)}function Jo(t,e){qo(t,e.sharedResources),function(t,e){let i=Vo(t,e);t.insertSpatialStructure(i)}(t,e.spatialStructure),function(t,e){for(let i of e){let e=Yo(t,i);e&&t.insertRelation(e)}}(t,e.sharedResources.relations||[])}function Ko(t,e,i,s){let r=t[0],n=t[1];for(let o=1;o<e.length-1;o++){let a=e[o];if(Pi(a,r,n)<1e-7)return i?t[0]=a:t[1]=a,void(s?e.splice(0,o):e.splice(o+1))}}function Zo(t){let e=0;for(;e<t.length-2;){let i=t[e],s=t[e+2];Pi(t[e+1],i,s)<1e-7?t.splice(e+1,1):e++}}function Qo(t){if(t.length<3)return!1;let e=t.slice();e.push(t[0]);for(let i=0;i<e.length-2;i++){let t=e[i],s=e[i+1];for(let r=i+1;r<e.length-1;r++){const i=1e-7;let n=Eo(t,s,e[r],e[r+1]);if(1===n.tag&&n.u>i&&n.u<1-i)return!0}}return!1}const ta="miter",ea=.05,ia=.15,sa=2.5,ra=0;function na(t,e){let i={indices:[t,e],faces:[-1,-1],geometry:{tangible:!0,skipped:!1,parameters:{width:ia,height:sa,offset:ra},fragments:[],computed:{valid:!0,skipped:!1,selfIntersecting:!1,sidePoints1:[],sidePoints2:[],joinPoints1:[],joinPoints2:[],points:[]}},openings:[]};return i.geometry.fragments=[{edge:i,angle:0,points:[],joinPoints:[],sidePoints:[]},{edge:i,angle:0,points:[],joinPoints:[],sidePoints:[]}],i}const oa="intersectCap",aa="intersectCap";function la(t){let e=t.toFixed(3),i=parseFloat(e);return e+=t>i?"+":t<i?"-":" ",t>=0&&(e=" "+e),e}function ha(t){if(t.length>0)for(let e=0;e<t.length;e++){let i=t[e];i[0],i[1]}}function ua(t,e){for(let i of e)if(t.length>0){let e=t[0],s=t[t.length-1],r=li(fi(i,e)),n=li(fi(i,s));r>1e-7&&n>1e-7&&t.push(i)}else t.push(i)}function ca(t,e,i,s,r){0===t.joinPoints.length?(ua(t.joinPoints,[...s,i]),ua(t.sidePoints[0],r)):(ua(t.joinPoints,s),ua(t.sidePoints[1],r.slice().reverse())),ha(t.joinPoints),ha(t.sidePoints[0]),ha(t.sidePoints[1])}function da(t,e,i,s,r){ca(t,0,i,[s],[s]),ca(e,0,i,[r],[r]),t.edge.geometry.computed.skipped=!0,e.edge.geometry.computed.skipped=!0}function pa(t,e,i,s){ca(t,0,i,[s],[s]),ca(e,0,i,[s],[s])}function fa(t,e,i,s,r){ca(t,0,i,[s],[s]),ca(e,0,i,[r],[r])}function ma(t,e,i,s,r,n,o,a,l,h,u){if("ignore"===u)da(t,e,i,r,a);else{let u;if(u=h?Po(s,r,l,a):Po(n,r,o,a),2!==u.tag)return be.warn("Edge side line does not intersect edge cap line, ignoring result."),void da(t,e,i,r,a);let c=u.p;h?(ca(t,0,i,[c],[c]),ca(e,0,i,[a,c],[a])):(ca(t,0,i,[r,c],[r]),ca(e,0,i,[c],[c]))}}function ga(t,e,i,s,r,n,o,a,l,h,u,c){t.edge.id,e.edge.id;let d=Po(s,r,a,l);if(2!==d.tag)return be.warn("Edge side lines do not intersect, ignoring result.",d),void da(t,e,i,r,l);let p=li(fi(r,s)),f=li(fi(l,a)),m=Math.max(0,1-.2/p),g=Math.max(0,1-.2/f),{p:y,u:v,v:x}=d,b="",_="";if(v>=.9999999)if(o)if(x>=.9999999){const s=1;if(li(fi(y,i))>s){let s,n=Po(y,i,r,l);2!==n.tag?(be.warn("Bevel construction failed, using center point.",n),s=ui(r,l,.5)):s=n.p,ca(t,0,i,[s],[r,s]),ca(e,0,i,[s],[l,s])}else pa(t,e,i,y)}else if(x>=g)pa(t,e,i,y);else{let c=o&&u?oa:"ignore";ma(t,e,i,s,r,n,a,l,h,!0,c),_="ignore"===c?"* (ignore)":"* (intersectCap)"}else da(t,e,i,r,l);else if(x>=.9999999)if(u)if(v>=m)pa(t,e,i,y);else{let c=o&&u?oa:"ignore";ma(t,e,i,s,r,n,a,l,h,!1,c),b="ignore"===c?"* (ignore)":"* (intersectCap)"}else da(t,e,i,r,l);else be.warn("Edge side line segments cross, ignoring result."),da(t,e,i,r,l);la(v),m.toFixed(3),la(x),g.toFixed(3)}function ya(t,e,i,s,r,n,o,a,l,h,u,c){t.edge.id,e.edge.id;let d=Po(s,r,a,l);if(2!==d.tag)return be.warn("Edge side lines do not intersect, ignoring result.",d),void da(t,e,i,r,l);let p=li(fi(r,s)),f=li(fi(l,a)),m=Math.max(0,1-1/p),g=Math.max(0,1-1/f),{p:y,u:v,v:x}=d,b="",_="";if(v>=0&&v<=1+1e-7&&x>=0&&x<=1+1e-7)pa(t,e,i,y);else if(v>1&&x>1)be.warn("Edge side line segments do not cross, ignoring result."),da(t,e,i,r,l);else if(v>1)if(x>=g)pa(t,e,i,y);else{let c=o&&u?aa:"ignore";ma(t,e,i,s,r,n,a,l,h,!1,c),_="ignore"===c?"* (ignore)":"* (intersectCap)"}else if(x>1)if(v>=m)pa(t,e,i,y);else{let c=o&&u?aa:"ignore";ma(t,e,i,s,r,n,a,l,h,!0,c),b="ignore"===c?"* (ignore)":"* (intersectCap)"}else da(t,e,i,r,l);la(v),m.toFixed(3),la(x),g.toFixed(3)}function va(t,e){let i,s,r,n=e[0];n.indices[0]===t?(i=n.geometry.fragments[0],s=i.points[0],r=i.points[1]):(i=n.geometry.fragments[1],s=i.points[1],r=i.points[0]),i.joinPoints.push(s,r),i.sidePoints[0].push(s),i.sidePoints[1].push(r)}function xa(t,e,i){for(let s=0;s<e.length;s++){let r,n,o,a,l,h,u,c,d,p,f,m,g=e[s],y=s<e.length-1?e[s+1]:e[0],v=!g.geometry.skipped&&0!==g.geometry.parameters.width,x=!y.geometry.skipped&&0!==y.geometry.parameters.width;if(!v&&!x)continue;g.indices[0]===t?(r=g.geometry.fragments[0],n=g.geometry.fragments[1],o=n.points[0],a=r.points[0],l=r.points[1],h=i[g.indices[1]].position):(r=g.geometry.fragments[1],n=g.geometry.fragments[0],o=n.points[1],a=r.points[1],l=r.points[0],h=i[g.indices[0]].position),y.indices[0]===t?(u=y.geometry.fragments[0],c=y.geometry.fragments[1],d=c.points[1],p=u.points[1],f=u.points[0],m=i[y.indices[1]].position):(u=y.geometry.fragments[1],c=y.geometry.fragments[0],d=c.points[0],p=u.points[0],f=u.points[1],m=i[y.indices[0]].position);let b=i[t].position;const _=.01;let w=bi(o,a,d,p);if(w<_||w>Math.PI-_)fa(r,u,b,a,p);else{1===vi(h,b,m)?ga(r,u,b,o,a,l,v,d,p,f,x):ya(r,u,b,o,a,l,v,d,p,f,x)}}}function ba(t){let e=t.geometry;e.fragments[0].joinPoints=[],e.fragments[0].sidePoints[0]=[],e.fragments[0].sidePoints[1]=[],e.fragments[1].joinPoints=[],e.fragments[1].sidePoints[0]=[],e.fragments[1].sidePoints[1]=[],e.computed={valid:!0,skipped:!1,selfIntersecting:!1,sidePoints1:[],sidePoints2:[],joinPoints1:[],joinPoints2:[],points:[]}}function _a(t,e){let i=function(t){let e={};for(let i of t){let t=i.indices[0],s=i.indices[1],r=Math.min(t,s),n=Math.max(t,s);e[r.toString()+"_"+n.toString()]=i}return e}(e),s=[];for(let n of e){if(!n.geometry.tangible||n.geometry.skipped)continue;let t=n.indices[0],e=n.indices[1];s[t]=!0,s[e]=!0,ba(n)}let{vertices:r}=t;for(let n=0;n<r.length;n++){if(!s[n])continue;let t=[],e=r[n];for(let s of e.edges){if(!s.geometry.tangible||s.geometry.skipped)continue;let e=s.indices[0],r=s.indices[1],n=Math.min(e,r),o=Math.max(e,r);i[n.toString()+"_"+o.toString()]&&t.push(s)}t.length,1===t.length?va(n,t):xa(n,t,r)}}function wa(t,e){let i=e.element;if(i?t.geometry.tangible="element:spaceDivider"!==i.type:e.boundaryWalls[0]||e.boundaryWalls[1]?t.geometry.tangible=!0:t.geometry.tangible=!1,i&&"element:wall"===i.type){let{width:e,height:s,offset:r}=i.parameters;t.geometry.parameters={width:e,height:s,offset:r}}else t.geometry.parameters={width:0,height:0,offset:0}}function Pa(t,e){let i=[],s={};for(let h of e)for(let t of h.vertices)if(void 0===s[t.id]){let e=(r=t.position[0],n=t.position[1],{position:[r,n],edges:[],geometry:{parameters:{joinStyle:{type:ta,parameters:{distance:ea}}}}});e.reference=t,s[t.id]=i.push(e)-1}var r,n;let o=[],a={};for(let h of e){let t=h.vertices[0],e=h.vertices[1],i=na(s[t.id],s[e.id]);wa(i,h),i.id=h.id,i.reference=h,o.push(i),a[h.id]=!0}let l=function(t,e){return{vertices:t,edges:e,cycles:[],faces:[]}}(i,o);return function(t){let{vertices:e,edges:i}=t;for(let s of e)s.edges=[];for(let s of i){let t=s.indices[0],i=s.indices[1];e[t].edges.push(s),e[i].edges.push(s)}}(l),function(t){let{vertices:e}=t;for(let i=0;i<e.length;i++){let t=e[i],s=t.edges,r=[];for(let n of s){let s=e[i===n.indices[0]?n.indices[1]:n.indices[0]],o={edge:n,angle:ni([s.position[0]-t.position[0],s.position[1]-t.position[1]]),points:[],joinPoints:[],sidePoints:[[],[]]},a={edge:n,fragment:o};i===n.indices[0]?n.geometry.fragments[0]=o:n.geometry.fragments[1]=o,r.push(a)}r.sort(((t,e)=>t.fragment.angle-e.fragment.angle)),t.edges=r.map((t=>t.edge))}}(l),l}function Ea(t){const e=t.map((t=>t.geometry.computed)),i=function(t){var e;if(0===t.length)return[];const i={};for(const l of t)for(const t of l.indices)i[t]??(i[t]=[]),i[t].push(l);let s=(null==(e=Object.entries(i).find((([,t])=>1===t.length)))?void 0:e[0])||Object.keys(i)[0];const r=[],n=new Set;let o=parseInt(s),a=i[o][0];for(;r.length<t.length;){if(n.has(a)){if(a=t.find((t=>!n.has(t))),!a)break;o=a.indices[0];continue}const e=a.indices[0]!==o;r.push({edge:a,reverse:e}),n.add(a);const s=e?a.indices[0]:a.indices[1],l=i[s].find((t=>!n.has(t)));if(l)o=s,a=l;else{if(a=t.find((t=>!n.has(t))),!a)break;o=a.indices[0]}}return r}(t),s=t[0].geometry.computed;let r=s.valid;const n=i[0].reverse,o=i[0].edge.geometry.computed,a=i[i.length-1].reverse,l=i[i.length-1].edge.geometry.computed,h=n?o.joinPoints2:o.joinPoints1,u=a?l.joinPoints1:l.joinPoints2,c=[],d=[];for(const{edge:m,reverse:g}of i){const{computed:t}=m.geometry;g?(c.unshift(...t.sidePoints2),d.push(...t.sidePoints1)):(c.unshift(...t.sidePoints1),d.push(...t.sidePoints2))}const p=$(e.map((t=>t.points)));let f=[];if(1===p.length)f=p[0];else if(p.length>1){const t=z(p,.001,void 0,!0);t.length>0&&(f=t[0])}return 0===f.length&&(be.warn(`Empty wall geometry after merging edge profiles: ${t.map((t=>t.id)).join(", ")}`),r=!1),{valid:r,skipped:s.skipped,selfIntersecting:s.selfIntersecting,sidePoints1:c.slice(),sidePoints2:d.slice(),joinPoints1:h.slice(),joinPoints2:u.slice(),points:f}}function Ta(t,e){Js(t,e),e.emit("geometry-profile-update",e);for(let i of e.slabs)i.emit("geometry-profile-update",i)}function Aa(t){let e=function(t){let e=new Map;for(let i of t)for(let t of i.boundaryWalls)t&&e.set(t.id,t);return[...e.values()]}(t);for(let i of e)Lr(i)}function Ia(t){let e=t.spatialGraph.edges,i=Pa(0,e);!function(t){let{vertices:e,edges:i}=t;for(let s of i){let{geometry:t}=s,i=s.indices[0],r=s.indices[1],n=t.parameters.width,o=t.parameters.offset,a=e[i].position,l=e[r].position,h=fi(l,a);if(t.skipped=li(h)<1e-7,!t.skipped){let e=di(ci(h)),i=pi(e,.5*n+o),s=pi(e,-.5*n+o),r=ri(a,i),u=ri(a,s),c=ri(l,i),d=ri(l,s);t.fragments[0].points=[r,u],t.fragments[1].points=[c,d]}}}(i),_a(i,i.edges),function(t,e){for(let i of e){let{geometry:t}=i;if(!t.tangible||t.skipped||0===t.parameters.width)continue;let e=t.fragments[0],s=t.fragments[1],r=[...e.joinPoints],n=[...s.joinPoints],o=[...e.sidePoints[0]],a=[...e.sidePoints[1]],l=[...s.sidePoints[0]],h=[...s.sidePoints[1]],u=Po(r[0],n[n.length-1],r[r.length-1],n[0]);2===u.tag&&u.u>0&&u.u<1&&u.v>0&&u.v<1&&(n.reverse(),l.reverse(),h.reverse(),[l,h]=[h,l]);let c=h.concat(o),d=a.concat(l);2===c.length&&2===d.length&&(Ko(c,r,!1,!0),Ko(c,n,!0,!1),Ko(d,r,!0,!1),Ko(d,n,!1,!0)),Zo(c),Zo(r),Zo(d),Zo(n),1===vi(c[0],c[c.length-1],d[0])&&(c.reverse(),d.reverse(),r.reverse(),n.reverse(),[c,d]=[d,c]);let p=c.slice(0,c.length-1),f=r.slice(0,r.length-1),m=d.slice(0,d.length-1),g=n.slice(0,n.length-1),y=it(p.concat(f).concat(m).concat(g),.001),v=i.geometry.computed;v.sidePoints1=c,v.sidePoints2=d,v.joinPoints1=r,v.joinPoints2=n,v.points=y,v.selfIntersecting=Qo(v.points),v.valid=v.points.length>=3&&!v.skipped&&!v.selfIntersecting,i.id,v.valid,v.skipped,v.selfIntersecting}}(0,i.edges),function(t){var e;let i={};for(let s of t.edges){let t=s.reference.element;if("element:wall"===(null==t?void 0:t.type)){let r=s.geometry.computed;1===t.getEdges().length?(t.geometryProfile={valid:r.valid,skipped:r.skipped,selfIntersecting:r.selfIntersecting,sidePoints1:r.sidePoints1.slice(),sidePoints2:r.sidePoints2.slice(),joinPoints1:r.joinPoints1.slice(),joinPoints2:r.joinPoints2.slice(),points:r.points.slice()},t.emit("geometry-profile-update",t)):(i[e=t.id]??(i[e]=[]),i[t.id].push(s),i[t.id].length===t.getEdges().length&&(t.geometryProfile=Ea(i[t.id]),t.emit("geometry-profile-update",t)))}}}(i),function(t){var e;for(let i of t)"element:wall"===(null==(e=i.element)?void 0:e.type)&&Fr(i.element)}(e),Aa(e)}function Sa(t){Ia(t),function(t){let e=t.spaces;for(let i of e){Ta(t,i);for(let t of i.slabs)er(t)}}(t)}function Ca(t){return new Promise(((e,i)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>i(t.error)}))}function Ma(t,e){const i=indexedDB.open(t);i.onupgradeneeded=()=>i.result.createObjectStore(e);const s=Ca(i);return(t,i)=>s.then((s=>i(s.transaction(e,t).objectStore(e))))}let Oa;function Na(){return Oa||(Oa=Ma("keyval-store","keyval")),Oa}for(var La="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ra="undefined"==typeof Uint8Array?[]:new Uint8Array(256),ka=0;ka<64;ka++)Ra[La.charCodeAt(ka)]=ka;var Ba={exports:{}};function Fa(t,e){return t<e?-1:t>e?1:0}var Da=Ot(Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=Fa){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:i}=this,s=e[t];for(;t>0;){const r=t-1>>1,n=e[r];if(i(s,n)>=0)break;e[t]=n,t=r}e[t]=s}_down(t){const{data:e,compare:i}=this,s=this.length>>1,r=e[t];for(;t<s;){let s=1+(t<<1),n=e[s];const o=s+1;if(o<this.length&&i(e[o],n)<0&&(s=o,n=e[o]),i(n,r)>=0)break;e[t]=n,t=s}e[t]=r}}},Symbol.toStringTag,{value:"Module"})));function Ua(t,e,i){var s,r,n,o;e=e||1;for(var a=0;a<t[0].length;a++){var l=t[0][a];(!a||l[0]<s)&&(s=l[0]),(!a||l[1]<r)&&(r=l[1]),(!a||l[0]>n)&&(n=l[0]),(!a||l[1]>o)&&(o=l[1])}var h=n-s,u=o-r,c=Math.min(h,u),d=c/2;if(0===c){var p=[s,r];return p.distance=0,p}for(var f=new Da(void 0,Ga),m=s;m<n;m+=c)for(var g=r;g<o;g+=c)f.push(new Xa(m+d,g+d,d,t));var y=function(t){for(var e=0,i=0,s=0,r=t[0],n=0,o=r.length,a=o-1;n<o;a=n++){var l=r[n],h=r[a],u=l[0]*h[1]-h[0]*l[1];i+=(l[0]+h[0])*u,s+=(l[1]+h[1])*u,e+=3*u}return 0===e?new Xa(r[0][0],r[0][1],0,t):new Xa(i/e,s/e,0,t)}(t),v=new Xa(s+h/2,r+u/2,0,t);v.d>y.d&&(y=v);for(var x=f.length;f.length;){var b=f.pop();b.d>y.d&&(y=b,i&&console.log("found best %d after %d probes",Math.round(1e4*b.d)/1e4,x)),b.max-y.d<=e||(d=b.h/2,f.push(new Xa(b.x-d,b.y-d,d,t)),f.push(new Xa(b.x+d,b.y-d,d,t)),f.push(new Xa(b.x-d,b.y+d,d,t)),f.push(new Xa(b.x+d,b.y+d,d,t)),x+=4)}i&&(console.log("num probes: "+x),console.log("best distance: "+y.d));var _=[y.x,y.y];return _.distance=y.d,_}function Ga(t,e){return e.max-t.max}function Xa(t,e,i,s){this.x=t,this.y=e,this.h=i,this.d=function(t,e,i){for(var s=!1,r=1/0,n=0;n<i.length;n++)for(var o=i[n],a=0,l=o.length,h=l-1;a<l;h=a++){var u=o[a],c=o[h];u[1]>e!=c[1]>e&&t<(c[0]-u[0])*(e-u[1])/(c[1]-u[1])+u[0]&&(s=!s),r=Math.min(r,Wa(t,e,u,c))}return 0===r?0:(s?1:-1)*Math.sqrt(r)}(t,e,s),this.max=this.d+this.h*Math.SQRT2}function Wa(t,e,i,s){var r=i[0],n=i[1],o=s[0]-r,a=s[1]-n;if(0!==o||0!==a){var l=((t-r)*o+(e-n)*a)/(o*o+a*a);l>1?(r=s[0],n=s[1]):l>0&&(r+=o*l,n+=a*l)}return(o=t-r)*o+(a=e-n)*a}Da.default&&(Da=Da.default),Ba.exports=Ua,Ba.exports.default=Ua;var Ha,Ya,$a={exports:{}};Ha=$a,Ya=function(){var t={},e=Math.PI/180,i=180/Math.PI,s=6378137,r=20037508.342789244;function n(t){return Number(t)===t&&t%1!=0}function o(e){if(e=e||{},this.size=e.size||256,this.expansion=!0===e.antimeridian?2:1,!t[this.size]){var i=this.size,s=t[this.size]={};s.Bc=[],s.Cc=[],s.zc=[],s.Ac=[];for(var r=0;r<30;r++)s.Bc.push(i/360),s.Cc.push(i/(2*Math.PI)),s.zc.push(i/2),s.Ac.push(i),i*=2}this.Bc=t[this.size].Bc,this.Cc=t[this.size].Cc,this.zc=t[this.size].zc,this.Ac=t[this.size].Ac}return o.prototype.px=function(t,i){if(n(i)){var s=this.size*Math.pow(2,i),r=s/2,o=s/360,a=s/(2*Math.PI),l=s,h=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),u=r+t[0]*o,c=r+.5*Math.log((1+h)/(1-h))*-a;return u>l*this.expansion&&(u=l*this.expansion),c>l&&(c=l),[u,c]}return r=this.zc[i],h=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),u=Math.round(r+t[0]*this.Bc[i]),c=Math.round(r+.5*Math.log((1+h)/(1-h))*-this.Cc[i]),u>this.Ac[i]*this.expansion&&(u=this.Ac[i]*this.expansion),c>this.Ac[i]&&(c=this.Ac[i]),[u,c]},o.prototype.ll=function(t,e){if(n(e)){var s=this.size*Math.pow(2,e),r=s/360,o=s/(2*Math.PI),a=s/2,l=(t[1]-a)/-o;return[(t[0]-a)/r,i*(2*Math.atan(Math.exp(l))-.5*Math.PI)]}return l=(t[1]-this.zc[e])/-this.Cc[e],[(t[0]-this.zc[e])/this.Bc[e],i*(2*Math.atan(Math.exp(l))-.5*Math.PI)]},o.prototype.bbox=function(t,e,i,s,r){s&&(e=Math.pow(2,i)-1-e);var n=[t*this.size,(+e+1)*this.size],o=[(+t+1)*this.size,e*this.size],a=this.ll(n,i).concat(this.ll(o,i));return"900913"===r?this.convert(a,"900913"):a},o.prototype.xyz=function(t,e,i,s){"900913"===s&&(t=this.convert(t,"WGS84"));var r=[t[0],t[1]],n=[t[2],t[3]],o=this.px(r,e),a=this.px(n,e),l=[Math.floor(o[0]/this.size),Math.floor((a[0]-1)/this.size)],h=[Math.floor(a[1]/this.size),Math.floor((o[1]-1)/this.size)],u={minX:Math.min.apply(Math,l)<0?0:Math.min.apply(Math,l),minY:Math.min.apply(Math,h)<0?0:Math.min.apply(Math,h),maxX:Math.max.apply(Math,l),maxY:Math.max.apply(Math,h)};if(i){var c={minY:Math.pow(2,e)-1-u.maxY,maxY:Math.pow(2,e)-1-u.minY};u.minY=c.minY,u.maxY=c.maxY}return u},o.prototype.convert=function(t,e){return"900913"===e?this.forward(t.slice(0,2)).concat(this.forward(t.slice(2,4))):this.inverse(t.slice(0,2)).concat(this.inverse(t.slice(2,4)))},o.prototype.forward=function(t){var i=[s*t[0]*e,s*Math.log(Math.tan(.25*Math.PI+.5*t[1]*e))];return i[0]>r&&(i[0]=r),i[0]<-r&&(i[0]=-r),i[1]>r&&(i[1]=r),i[1]<-r&&(i[1]=-r),i},o.prototype.inverse=function(t){return[t[0]*i/s,(.5*Math.PI-2*Math.atan(Math.exp(-t[1]/s)))*i]},o}(),Ha.exports=Ya;const ja=Mt($a.exports),za={work:{name:"Work",isHidden:!0,description:"space for individual head-down work",spaceUsage:{privateOffice:{name:"Private office",category:["office"]},focusRoom:{name:"Focus room",category:["office"]},openWorkspace:{name:"Open workspace",category:["office"]},enclosedWorkspace:{name:"Enclosed workspace",category:["office"]},closedWorkspace:{name:"Closed workspace",isDeprecated:!0,category:["office"]},executiveOffice:{name:"Executive office",isDeprecated:!0,category:["office"]}}},meet:{name:"Meet",isHidden:!0,spaceUsage:{meetingRoom:{name:"Meeting room",category:["office"]},hub:{name:"Hub",category:["office"]},assembly:{name:"Assembly",category:["office"]},boardRoom:{name:"Board room",category:["office"]},trainingRoom:{name:"Training room",category:["office"]},collaboration:{name:"Collaboration",isDeprecated:!0,category:["office"]}}},live:{name:"live",isHidden:!0,spaceUsage:{living:{name:"Living",category:["residential"]},dining:{name:"Dining",category:["residential"]},dining_living:{name:"Living & Dining",category:["residential"]},homeOffice:{name:"Home office",category:["residential"]},bedroom:{name:"Bedroom",category:["residential"]}}},socialize:{name:"Socialize",isHidden:!0,spaceUsage:{lobby:{name:"Lobby",category:["office","residential"]},reception:{name:"Reception",category:["office"]},lounge:{name:"Lounge",category:["office"]},cafe:{name:"Cafe",category:["office"]},canteen:{name:"Canteen",category:["office"]},pantry:{name:"Pantry",category:["office"]},terrace:{name:"Terrace",isOutdoor:!0,category:["office","residential"]},balcony:{name:"Balcony",isOutdoor:!0,category:["office","residential"]},rooftop:{name:"Rooftop",isOutdoor:!0,category:["office","residential"]},courtyard:{name:"Courtyard",isOutdoor:!0,category:["office","residential"]},garden:{name:"Garden",isOutdoor:!0,category:["residential"]},common:{name:"Common",isDeprecated:!0,category:["office"]}}},support:{name:"Support",isHidden:!0,spaceUsage:{serviceKitchen:{name:"Service kitchen",category:["office"]},printStation:{name:"Print station",category:["office"]},storage:{name:"Storage",category:["lightIndustrial","residential","office","parking"]},mailRoom:{name:"Mail room",category:["office"]},operationalRoom:{name:"Operational room",category:["lightIndustrial","office","parking"]},serviceRoom:{name:"Service room",category:["office"]},laundryRoom:{name:"Laundry room",category:["residential"]},loadingDock:{name:"Loading dock",category:["lightIndustrial"]},operate:{name:"Operate",isDeprecated:!0,category:["office"]},services:{name:"Services",isDeprecated:!0,category:["office","residential"]}}},care:{name:"Care",isHidden:!0,spaceUsage:{kitchen:{name:"Kitchen",category:["residential"]},wellnessRoom:{name:"Wellness room",category:["lightIndustrial","office"]},restroom:{name:"Restroom",category:["lightIndustrial","office","parking"]},bathroom:{name:"Bathroom",category:["residential"]},shower:{name:"Shower",category:["lightIndustrial","office","residential"]},toilet:{name:"Toilet",category:["residential"]}}},circulate:{name:"Circulate",isHidden:!0,spaceUsage:{corridor:{name:"Corridor",category:["lightIndustrial","residential","office","parking"]},foyer:{name:"Foyer",category:["lightIndustrial","residential","office","parking"]},staircase:{name:"Staircase",isVertical:!0,category:["lightIndustrial","residential","office","parking"]},elevator:{name:"Elevator",isVertical:!0,category:["lightIndustrial","residential","office","parking"]}}},drive:{name:"Drive",isHidden:!0,spaceUsage:{parkingSpot:{name:"Parking spot",category:["parking"]},driveway:{name:"Driveway",category:["parking"]},garage:{name:"Garage",category:["residential"]}}},produce:{name:"Produce",isHidden:!0,spaceUsage:{productionArea:{name:"Production area",category:["lightIndustrial"]}}},void:{isHidden:!0,name:"Void",spaceUsage:{shaft:{name:"Shaft",isVertical:!0,category:["lightIndustrial","residential","office","parking"]},buildingOpening:{name:"Building opening",isVertical:!0,category:["lightIndustrial","residential","office","parking"]},floorOpening:{name:"Floor opening",isVertical:!0,category:["lightIndustrial","residential","office","parking"]}}},undefined:{isHidden:!0,spaceUsage:{undefined:{name:"Undefined",category:["residential","office"],isHidden:!0}}}},Va={};function qa(t,e,i){let s=gt(...t),r=gt(...e),n=gt(...i),o=ft(),a=ft(),l=ft();return xt(o,s,n),xt(a,r,n),_t(l,o,a),bt(l,l),[...l]}function Ja(t){let{indices:e,vertices:i}=t,s=[],r=[],n=[],o=ds(i);for(let u=0;u<i.length;u+=3){let t=i[u],e=i[u+1],n=i[u+2];s.push([t,e,n]),r.push([t,n])}for(let u=0;u<e.length;u+=3){let t=e[u],i=e[u+1],o=e[u+2];qa(s[t],s[i],s[o])[1]<.01||n.push([r[t],r[i],r[o]])}let a=[],l=[[]];if(!n.length)return{outlines:a,holes:l,boundingBox:o};let h=et($(n),.0015);h=h.filter((t=>t&&t.length&&Q(t)>5e-4));for(let u of h)Ii(u)?l[0].push(u):a.push(u);return{outlines:a,holes:l,boundingBox:o}}function Ka(t,e={}){let i=function(t,e=at(),i=new Map,s=!0){let r=[],n=t.spaceGraph;if("geometries"in t&&t.geometries)for(let o of t.geometries){let t,a,l,h;if("string"==typeof o){if(t=n.geometriesById[o],!t){be.warn(`Geometry ${o} not found.`);continue}a=[0,0,0],l=0,h=[0,1,0]}else{if("reference:geometry"!==o.type){be.warn(`Operation ${o.type} not supported.`);continue}let e=o.geometry;if("string"==typeof e){if(t=n.geometriesById[e],!t){be.warn(`Geometry ${e} not found.`);continue}}else t=e;a=o.position??[0,0,0],l=o.rotation??0,h=o.rotationAxis??[0,1,0]}let u=Je(a,l);for(let o of u){let a=Ci(o.position,o.rotation,h);s&&(a=ct(at(),e,a));let l=[];if("geometry:uri"===t.type&&"data3d"===t.format){let e=i.get(t.uri),s=(null==e?void 0:e.meshGeometries)||{};for(let t in s){let e=s[t];l.push(...cs(e,n.geometriesById,n.materialsById,[]))}}else l=cs(t,n.geometriesById,n.materialsById,[]);let u=Et(),c=ft();pt(u,a),dt(c,a);for(let t of l)Oi(t.vertices,a);r.push({meshes:l,rotation:u,position:c})}}return r}(t,e.applyElementMatrix?xr(t,e.parentMatrix):void 0,e.resources),s=[];for(let r of i)for(let t of r.meshes)s.push(Ja(t));return s}Object.keys(za).forEach((t=>{const e=za[t];Va[t]={name:e.name,type:"program",category:[]},e.isHidden&&(Va[t].isHidden=e.isHidden);const i={};Object.keys(za[t].spaceUsage).forEach((e=>{const s=za[t].spaceUsage[e];Va[e]={...s,type:"space",program:t},s.category.forEach((t=>{i[t]=!0}))})),Va[t].category=Object.keys(i)})),new ja({size:256});const Za=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Qa(t){return"string"==typeof t&&Za.test(t)}const tl={categories:["lightIndustrial","office","parking","residential","laboratory"],programs:{care:[{name:"bathroom",tags:[],categories:["residential"]},{name:"kitchen",tags:[],categories:["residential"]},{name:"restroom",tags:[],categories:["lightIndustrial","office","parking","laboratory"]},{name:"shower",tags:[],categories:["lightIndustrial","office","residential","laboratory"]},{name:"toilet",tags:[],categories:["residential"]},{name:"wellnessRoom",tags:[],categories:["lightIndustrial","office","laboratory"]}],circulate:[{name:"corridor",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"elevator",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"foyer",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"staircase",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]}],drive:[{name:"driveway",tags:[],categories:["parking"]},{name:"garage",tags:[],categories:["residential"]},{name:"parkingSpot",tags:[],categories:["parking"]}],live:[{name:"bedroom",tags:[],categories:["residential"]},{name:"dining",tags:[],categories:["residential"]},{name:"dining_living",tags:[],categories:["residential"]},{name:"homeOffice",tags:[],categories:["residential"]},{name:"living",tags:[],categories:["residential"]}],meet:[{name:"assembly",tags:[],categories:["office"]},{name:"boardRoom",tags:[],categories:["office"]},{name:"hub",tags:[],categories:["office"]},{name:"meetingRoom",tags:[],categories:["office"]},{name:"trainingRoom",tags:[],categories:["office"]}],none:[{name:"generic",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]}],produce:[{name:"productionArea",tags:[],categories:["lightIndustrial"]}],research:[{name:"lab",tags:[],categories:["lightIndustrial","laboratory"]}],socialize:[{name:"balcony",tags:["outdoor"],categories:["office","residential"]},{name:"cafe",tags:[],categories:["office","laboratory"]},{name:"canteen",tags:[],categories:["office"]},{name:"courtyard",tags:["outdoor"],categories:["office","residential"]},{name:"garden",tags:["outdoor"],categories:["residential"]},{name:"lobby",tags:[],categories:["office","residential","laboratory"]},{name:"lounge",tags:[],categories:["office","laboratory"]},{name:"pantry",tags:[],categories:["office"]},{name:"reception",tags:[],categories:["office","laboratory"]},{name:"rooftop",tags:["outdoor"],categories:["office","residential"]},{name:"terrace",tags:["outdoor"],categories:["office","residential"]}],support:[{name:"chemicalStore",tags:[],categories:["laboratory"]},{name:"cleanRoom",tags:[],categories:["laboratory"]},{name:"coldRoom",tags:[],categories:["laboratory"]},{name:"laundryRoom",tags:[],categories:["residential"]},{name:"loadingDock",tags:[],categories:["lightIndustrial"]},{name:"mailRoom",tags:[],categories:["office"]},{name:"operationalRoom",tags:[],categories:["lightIndustrial","office","parking","laboratory"]},{name:"printStation",tags:[],categories:["office"]},{name:"serviceKitchen",tags:[],categories:["office"]},{name:"serviceRoom",tags:[],categories:["office"]},{name:"storage",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]}],void:[{name:"buildingOpening",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"floorOpening",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"shaft",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]}],work:[{name:"enclosedWorkspace",tags:[],categories:["office"]},{name:"focusRoom",tags:[],categories:["office"]},{name:"openWorkspace",tags:[],categories:["office"]},{name:"privateOffice",tags:[],categories:["office"]}]}},el={medium_blue:"#1414c1",navy:"#172c4d",white:"#ffffff",new_york:"#0c1829",stone:"#4d586b",warsaw:"#929baa",oslo:"#72849e",stone_08:"#f1f2f3",gray:"#cfd5de",athens:"#e8ebef",whisper:"#f7f8fa",zurich:"#bdd7ff",blue_ribbon:"#3355ff",dark_blue:"#000099",zurich_48:"#dfecff",error:"#ab220a",warning:"#ffc400",san_fran:"#54c072",orange:"#ffab00",purple:"#6700ab",fandango:"#c40096",dodger:"#007aff",flamingo:"#ef5533",aqua:"#00b5ce",palegreen:"#ffeae6",palered:"#e6ffed"},il={api:{productDataCacheAge:864e5,productContourCacheAge:864e6},hideElements:[],panZoom:!0,preserveViewbox:"center-center",roomStampSize:null,showCeilingLamps:!1,destroyOnDomRemove:!1,ui:{scale:!0,coordinates:!1},spaceLabelMapping:{},theme:{fontFamily:"Inter, Avenir, Verdana, sans-serif",background:{color:el.whisper,showGrid:!1},wallContours:!1,showAssetTextures:!1,elements:{floorPlan:{grayscale:!1},roomStamp:{}}},units:{system:"metric",areaDecimals:0,lengthDecimals:3,roomDimensions:"area"},zoomRange:[3,300]};let sl="archilogic/product",rl="https://storage.archilogic.com";let nl=new E(["info","warnings","errors"]);function ol(t,e){var i;let s,r=e.product.geometries[0];const n="product:component"===(null==(i=e.product)?void 0:i.type);if("string"==typeof r){let t=r;s=e.spaceGraph.geometriesById[t]}else"reference:geometry"===(null==r?void 0:r.type)&&"string"!=typeof r.geometry&&(s=r.geometry);let o="geometry:uri"===(null==s?void 0:s.type);if(!n&&!o)return Promise.reject("Unsupported product geometry: "+e.product.id);const a=n?["productJson"]:["productJson","productContour"];return t.loadResources(e.product.id,e,a).catch((t=>nl.error(t)))}const al=t=>{const e=[];return t.layout.elementsByType["element:asset"].forEach((t=>{var i;"product"in t&&"product:static"===(null==(i=t.product)?void 0:i.type)&&e.push(t)})),Promise.allSettled(e.map((e=>ol(t.loader,e))))};function ll(t){return fetch(`${rl}/${sl}/outline/${t}.json`).then((t=>{if(t.ok)return t.json();throw Error(t.statusText)}))}const hl="undefined"==typeof window||"undefined"!=typeof process;let ul;try{ul=!hl&&Ma("al-kvs","al-keyval")}catch(vw){nl.warn("indexedDb initialization failed")}let cl=!0;async function dl(t,e,i){if(!ul)return Promise.resolve();i=i||2592e6;try{const s={timeStamp:(new Date).getTime(),content:e,maxAge:i};return cl&&await function(t,e,i=Na()){return i("readwrite",(i=>(i.put(e,t),Ca(i.transaction))))}(t,s,ul),t}catch(s){return}}async function pl(t,e){if(!ul)return Promise.resolve();const i=e||2592e6,s=(new Date).getTime();let r;try{cl&&(r=await function(t,e=Na()){return e("readonly",(e=>Ca(e.get(t))))}(t,ul));const e=s-r.timeStamp;if(e>Math.min(r.maxAge,i))return;if(r.content)return r.content}catch(n){return}}const fl="fpe-dc2-";var ml=(t=>(t[t.None=0]="None",t[t.Default=1]="Default",t[t.Grayscale=2]="Grayscale",t))(ml||{});class gl extends ye{constructor(t){var e,i,s;super(),this.promiseCache=new Map,this.loadStages={product:!0,productContour:!0,productTexture:!1},this.queue={productJson:new Map,productContour:new Map,texture:new Map},this.resources={nodes:new Map,productJson:new Map,productContour:new Map,texture:new Map},this.initialLoading=!0,this._requestCounter=0,this._loadCounter=0;const{settings:r}=t;this.floorPlan=t,this.productContourCacheAge=null==(e=r.api)?void 0:e.productContourCacheAge,this.productDataCacheAge=null==(i=r.api)?void 0:i.productDataCacheAge,this.loadStages.productTexture=!!(null==(s=r.theme)?void 0:s.showAssetTextures)&&!1!==r.loadTextures,this.on("resource-loaded",this.loadStatus,this)}loadStatus(){const t=this._requestCounter;this._loadCounter++,this.emit("loading-status",{totalCount:t,doneCount:this._loadCounter}),t===this._loadCounter&&this.emit("loading-done",{totalCount:t})}loadResources(t,e,i){return Promise.all(i.map((i=>this.loadResource(t,e,i))))}loadResource(t,e,i){if(this.resources.nodes.has(t)||this.resources.nodes.set(t,new Set),this.resources.nodes.get(t).add(e),this.queue[i].has(t))return this.queue[i].get(t);let s;switch(this._requestCounter++,i){case"productJson":s=yl(t,this,e.product);break;case"productContour":this.loadStages.productTexture&&this._requestCounter++,s=vl(t,this).then((()=>{if(this.loadStages.productTexture&&!this.resources.texture.has(t)){if(!this.resources.productJson.has(t))return void nl.warn("texture loading failed, no product info yet");const e=`${rl}/${sl}/thumb/${t}.png`;this.resources.texture.set(t,{textureUrl:e,applyFilter:1}),this.emit("product-load-texture",{resourceId:t})}}))}return this.queue[i].set(t,s),s}reset(){this.resources={nodes:new Map,productContour:new Map,productJson:new Map,texture:new Map},this.queue={productContour:new Map,productJson:new Map,texture:new Map},this._loadCounter=0,this._requestCounter=0,this.promiseCache=new Map,this.initialLoading=!0}}const yl=(t,e,i)=>{var s;const r=e.floorPlan.spaceGraph;t!==(null==i?void 0:i.id)||r.productsById[t]||r.insertProduct(i);const n=JSON.parse(JSON.stringify((null==i?void 0:i.attributes)||{}));return Number.isFinite(null==(s=n.boundingBox)?void 0:s.min[0])||(nl.warn("invalid product bounding box"),delete n.boundingBox),e.resources.productJson.set(t,n),Promise.resolve().then((()=>{e.emit("resource-loaded",{resourceId:t})}))},vl=async(t,e)=>{const i=fl+t,s=e.promiseCache.get(i);if(s)return s;const r=function(t,e){const i=e.productContourCacheAge,s=i||864e6;if(!t)return Promise.reject("product id missing");const r=fl+t,n=e.promiseCache.get(r);if(n)return n;const o=pl(r,i).then((e=>e||ll(t).then((t=>(dl(r,t,s),t))))).catch((t=>{nl.warn(t)}));return e.promiseCache.set(r,o),o}(t,e).then((i=>{const s=i,r=e.resources.productJson.get(t);if(!r.boundingBox){nl.warn("product boundingbox missing - creating from contour");let t=Y(s);r.boundingBox={min:[t.min[0],0,t.min[1]],max:[t.max[0],0,t.max[1]]}}e.resources.productContour.set(t,s),e.emit("resource-loaded",{resourceId:t})})).catch((()=>{}));return e.promiseCache.set(i,r),r};function xl(t){return t.max.map(((e,i)=>e-t.min[i]))}function bl(t,e=[0,0]){const{dimensions:i}=t.parameters,s=t.parent;let r=[];if("element:wall"===(null==s?void 0:s.type)){let t=s.parameters.width;r=[[-e[0],-e[1]],[i[0]+e[0],-e[1]],[i[0]+e[0],t+e[1]],[-e[0],t+e[1]]]}return[{type:"curve:polygon",points:r}]}function _l(t){const e=.01,i=t.elementsByType["element:wall"],s=t.elementsByType["element:boundaryWall"],r=t.elementsByType["element:column"],n=t.elementsByType["element:opening"],o=[];for(const u of n){const t=bl(u,[0,e]),{position:i,rotation:s}=u,r={position:[i[0],i[2]],rotation:s},n=ki(t[0].points,r);o.push([n])}const a=[];for(const u of i){let{points:t}=u.geometryProfile;t=z([t],e)[0],a.push([t])}for(const u of r){const{profile:t}=u.parameters;let{points:i}=ls(t);if("curve:rectangle"===t.type){const[e,s]=t.dimensions;i=[[-e/2,-s/2],[e/2,-s/2],[e/2,s/2],[-e/2,s/2]]}i=ki(i,{position:[u.position[0],u.position[2]],rotation:u.rotation}),i=z([i],e)[0],a.push([i])}for(const u of s){let t=u.boundaries[0].geometryProfile;t=z([t],e)[0],a.push([t])}let{polygons:l}=function(t){if(!t.length||!t[0])return{polygons:[],polyTree:[]};let e=st(t[0]),i=t.slice(1).flatMap(st),s=new H.Clipper;s.AddPaths(e,H.PolyType.ptSubject,!0),s.AddPaths(i,H.PolyType.ptClip,!0);let r=new H.PolyTree;return s.Execute(H.ClipType.ctUnion,r,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),j(r)}(a);l=V(l,-.01).polygons,o.length&&(l=J(l,o).polygons);const h=[];for(const u of l){const t=[];for(const e of u){let i=it(e,.001);i.length&&t.push(i)}t.length&&h.push(t)}return h}const wl=class t{constructor({options:t={}}={}){this.settings=b(il),this.fpeId="fpe-"+Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,3),this.computed={wallContours:[],snapPoints:[],snapMargin:0},this.isBrowser="object"!=typeof process&&"undefined"!=typeof window,this.location={latitude:0,longitude:0,bearing:0},this._emitter=new ye,be.setLevels("errors"),this.set(t),this.loader=new gl(this)}on(t,e,i){return this._emitter.on(t,e,i),this}once(t,e,i){return this._emitter.once(t,e,i),this}off(t,e){return this._emitter.off(t,e),this}emit(t,...e){return this._emitter.emit(t,...e),this}loadLayout(t,{skipGeometryCompute:e=!1}={}){this.loadSpaceGraph(t.spaceGraph,{skipGeometryCompute:e,layoutId:t.id})}loadSpaceGraph(t,{skipGeometryCompute:e=!1,layoutId:i}={}){this.loader.initialLoading||this.loader.reset(),this.spaceGraph=t,this.layout=i?t.nodesById[i]:t.nodesByType["spatialStructure:layout"][0],this.layout&&"spatialStructure:layout"===this.layout.type?(e||(Sa(this.layout),function(t){for(let e of t.elements)Dr(e)}(this.layout)),this.settings.theme.wallContours&&(this.computed.wallContours=_l(this.layout)),setTimeout((()=>{this.loader.emit("spaces-loaded")}),0),al(this).then((()=>{const t=this.settings.hideElements.includes("element:asset"),e=0===Object.keys(this.spaceGraph.products).length;this.loader.emit("assets-loaded",!0),(t||e)&&this.loader.emit("loading-done",{totalCount:0})})).catch((t=>nl.warn(t))),this.loader.initialLoading=!1):nl.warn("No layout to load")}loadSpaceGraphJson(t){this.loadSpaceGraph(function(t){let e=new wo(t.schemaVersion);return Jo(e,t),e}(t))}async loadFloorById(e,i=this.settings.api){return new Promise((async(s,r)=>{var n,a;e&&"string"==typeof e||r(`Expected non-empty string floorId parameter; instead got: "${e}"`);try{const r=k({...i,sdkVersion:t.version}),l=new U(r);this.loader.once("assets-loaded",s);const h=await l.getFloorById(e,!1,!1,!0),u=null==(n=h.properties)?void 0:n.address;if(o(null==u?void 0:u.latitude,90)&&(this.location.latitude=u.latitude),function(t){return o(t,180)}(null==u?void 0:u.longitude)&&(this.location.longitude=u.longitude),function(t){return o(t,180)}(null==u?void 0:u.bearing)&&(this.location.bearing=u.bearing),!(null==(a=h.layout)?void 0:a.layout))throw new Error(`The floor ${e} has no space graph layout`);this.emit("space-api-floor-loaded",e),this.loadSpaceGraphJson(h.layout.layout)}catch(vw){r(vw)}})).catch((t=>{throw this.emit("space-api-floor-error",e,t),t}))}set(t={}){var e,i,s,r,n,o,a,l,h;const u=null==(e=this.settings.hideElements)?void 0:e.includes("element:asset");let c=b(t);c.theme&&(c.theme=_(il.theme,c.theme)),c.ui&&(c.ui={...il.ui,...c.ui}),c.api&&(c.api={...il.api,...c.api}),c.units&&(c.units={...il.units,...c.units});const d=!(null==(i=c.hideElements)?void 0:i.includes("element:asset"));for(let p in c)this.settings[p]=c[p];if(null==(n=null==(r=null==(s=this.settings.theme)?void 0:s.elements)?void 0:r["layout:space"])?void 0:n.program){const t=this.settings.theme.elements["layout:space"].program,e={wash:"care",operate:"support",common:"socialize"};Object.keys(t).forEach((i=>{Object.keys(e).includes(i)&&(t[e[i]]=t[i],delete t[i])}))}this.layout&&(u&&d&&al(this),(null==(o=c.theme)?void 0:o.wallContours)&&!(null==(a=this.computed.wallContours)?void 0:a.length)?this.computed.wallContours=_l(this.layout):!(null==(l=c.theme)?void 0:l.wallContours)&&(null==(h=this.computed.wallContours)?void 0:h.length)&&(this.computed.wallContours=[])),this.emit("update-settings",this.settings)}getBoundingBox(t=0){const{min:[e,,i],max:[s,,r]}=this.layout.getBoundingBox();return{min:[e-t,i-t],max:[s+t,r+t]}}getResourcesFromPosition(t){const e=this.layout.spaces.filter((e=>wi(t,e.geometry.polygons))),i=[];return e.forEach((e=>{const s=e.getElements("element:asset").filter((e=>{if(e.product.attributes.subCategories.includes("ceilingLight")&&!this.settings.showCeilingLamps)return;const i=e.getBoundingBoxContour();return(null==i?void 0:i.length)?K(t,i):void 0}));i.push(...s)})),{spaces:e,assets:i}}destroy(){delete this.layout,delete this.settings,delete this.utils}};wl.version="5.0.0-rc.2";let Pl=wl;function El(t){let{length:e,hingeSide:i,doorSide:s,doorAngle:r,doorType:n,frameThickness:o,frameDepth:a}=t.parameters,l=[],h="right"===i,u="side1"===s,c=u?0:a,d=!1,p=0,f=0;if(r<5&&r>-5){r=20;const t=r/180*Math.PI;p=Math.sin(t),f=Math.cos(t),d=!0}if("singleSwing"===n){let t,i,s,n,a=e-2*o;u?h?(t=0,i=r,s=[o,c],n=[s[0]+f*a,s[1]-p*a]):(t=180-r,i=180,s=[e-o,c],n=[s[0]-f*a,s[1]-p*a]):h?(t=-180,i=-180+r,s=[e-o,c],n=[s[0]-f*a,s[1]+p*a]):(t=360-r,i=360,s=[o,c],n=[s[0]+f*a,s[1]+p*a]),l.push({type:"curve:arc",radius:a,position:s,startAngle:t,endAngle:i}),d&&l.push({type:"curve:line",start:s,end:n})}else if("doubleSwing"===n){let t,i,s,n,a,h,m,g,y=e/2-o;u?(t=0,i=r,s=[o,c],m=[e-o,c],a=180-r,h=180,n=[s[0]+f*y,s[1]-p*y],g=[m[0]-f*y,m[1]-p*y]):(t=360-r,i=360,s=[o,c],m=[e-o,c],a=180,h=180+r,n=[s[0]+f*y,s[1]+p*y],g=[m[0]-f*y,m[1]+p*y]),l.push({type:"curve:arc",radius:y,position:s,startAngle:t,endAngle:i}),l.push({type:"curve:arc",radius:y,position:m,startAngle:a,endAngle:h}),d&&(l.push({type:"curve:line",start:s,end:n}),l.push({type:"curve:line",start:m,end:g}))}return l}function Tl(t){let e=[];switch(t.type){case"element:door":e=El(t);break;case"element:stairFlight":e=function(t){var e;let i=null==(e=t.parent)?void 0:e.elements.find((t=>"element:stairFlight"===t.type));if((null==i?void 0:i.id)!==t.id||"spiral"===t.parameters.stairFlightType)return[];let{width:s,length:r,height:n}=t.parameters,o=r/Math.round(n/.17);return[{type:"curve:polyline",points:[[o/2-.06,s/2+.12],[o/2+.06,s/2],[o/2-.06,s/2-.12]]}]}(t)}return e}function Al(t){for(const e of Object.keys(tl.programs)){if(tl.programs[e].find((e=>e.name===t)))return e}return""}function Il(t,e=0){return({"element:door":40,"element:window":40,"element:opening":40,"element:spaceDivider":35,"spatialGraph:edge":35,"element:column":30,"element:wall":30,"element:boundaryWall":30,"element:casework":20,"element:kitchen":20,"element:railing":20,"element:generic":11,"element:asset":10,"element:stairs":5,"element:stairFlight":5,"element:slab":5,"layout:space":1,"annotation:floorPlanDxf":0,"annotation:floorPlanImage":0}[t]||0)+e}const Sl={default:{fill:el.white,stroke:el.warsaw,strokeWidth:"native",fillOpacity:1},selected:{fill:el.zurich_48,stroke:el.warsaw,strokeWidth:1}},Cl=t=>{const e=t.toString(16);return 1===e.length?"0"+e:e},Ml=(t,e,i)=>"#"+[t,e,i].map(Cl).join(""),Ol=t=>Number(parseInt(t.slice(1),16));function Nl(t){return"number"==typeof t?t:"string"==typeof t&&t.startsWith("#")?Ol(t):Array.isArray(t)?Ol(Ml(...t)):void 0}const Ll=({settings:t,element:e,elementType:i})=>{var s,r,n,o,a,l;const h=null==(s=null==t?void 0:t.theme)?void 0:s.elements;if(!h)return{};let u=(null==(r=h.byId)?void 0:r[null==e?void 0:e.id])||h[i]||h[null==e?void 0:e.type]||null;if(e){const t=h["layout:space"];if("layout:space"===e.type){const i=Al(e.attributes.usage);(null==(n=null==t?void 0:t.usage)?void 0:n[e.attributes.usage])?u=t.usage[e.attributes.usage]:(null==(o=null==t?void 0:t.program)?void 0:o[i])&&(u=t.program[i])}else"element:stairs"!==e.type||u||((null==(a=null==t?void 0:t.usage)?void 0:a.staircase)?u=t.usage.staircase:(null==(l=null==t?void 0:t.program)?void 0:l.circulate)&&(u=t.program.circulate))}return(t=>{const{fill:e,fillOpacity:i,stroke:s,strokeWidth:r}=t,n={};return e&&(n.fill=Nl(e)),s&&(n.stroke=Nl(s)),i&&Number.isFinite(i)&&(n.fillOpacity=Math.max(Math.min(i,1),0)),"string"==typeof r?"native"===r&&(n.strokeWidth=r):Number.isFinite(r)&&r>=0&&(n.strokeWidth=r),n})(u||{})},Rl=t=>{var e,i,s;if(null==(e=null==t?void 0:t.layout)?void 0:e.debugIds){let e=(null==(i=/\d+/.exec(t.id))?void 0:i[0])||"0",r=(s=parseInt(e),function(){let t=s+=1831565813;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296});return{fill:Math.round(5*r()*16777215)%16777215,fillOpacity:.5}}return{}},kl=({style:t,settings:e,element:i,elementType:s})=>{const r="selected"===t?"selected":"default",n=function({element:t,settings:e,elementType:i,state:s="default"}){var r;const n=null==(r=null==e?void 0:e.theme)?void 0:r.showAssetTextures,o={"element:wall":{default:{fill:el.stone,stroke:el.stone},selected:{fill:el.oslo,stroke:el.blue_ribbon,strokeWidth:"native"}},"element:boundaryWall":{default:{fill:el.stone,stroke:el.new_york},selected:{fill:el.oslo,stroke:el.blue_ribbon}},"element:curtainWall":{default:{fill:el.stone_08},selected:{strokeWidth:"native"}},"element:column":{default:{fill:el.stone,stroke:el.stone},selected:{fill:el.oslo,stroke:el.blue_ribbon,strokeWidth:"native"}},"element:asset":{default:{fill:n?null:el.stone_08},selected:{fill:el.zurich_48,stroke:el.blue_ribbon,strokeWidth:.5,alignment:0}},"element:stairs":{default:{fill:el.whisper},selected:{strokeWidth:"native"}},"element:stairFlight":{default:{fill:el.whisper}},"element:slab":{default:{fill:el.whisper}},"layout:space":(()=>{const e={default:{fill:el.white,stroke:el.gray},selected:{fill:el.zurich_48,stroke:el.gray,strokeWidth:"native"}};if(t&&"layout:space"===t.type){const i="kitchen"!==t.attributes.usage&&Al(t.attributes.usage),s={care:el.gray,circulate:el.whisper};i&&s[i]&&(e.default.fill=s[i]),"void"===i&&(e.default.fillOpacity=.05)}return e})(),"spatialGraph:edge":{default:{fill:el.gray,stroke:el.new_york,strokeOpacity:.8,strokeWidth:.5},selected:{stroke:el.blue_ribbon,strokeWidth:.5}},"element:spaceDivider":{default:{fill:el.gray,stroke:el.new_york,strokeOpacity:.8,strokeWidth:.5},selected:{stroke:el.blue_ribbon,strokeWidth:.5}}}[i]||Sl,a=Ll({settings:e,element:t,elementType:i});return"selected"===s?{...Sl.default,...o.default,...a,...Sl.selected,...o.selected}:{...Sl.default,...o.default,...a}}({element:i,elementType:s||(null==i?void 0:i.type),settings:e,state:r});return{...n,...t?{}:Rl(i),..."object"==typeof t?t:{}}};function Bl(t,e,i=.5){let s=[e[0]-t[0],e[1]-t[1]];return[t[0]+s[0]*i,t[1]+s[1]*i]}function Fl(t,e,i,s=5){const r=[];let n,o,a,l=0;for(let h=0;h<=s;++h)l=h/s,n=Bl(t,e,l),o=Bl(e,i,l),a=Bl(n,o,l),r.push(a);return r}const Dl=(t,e)=>{const i=Math.ceil(48/(2*Math.PI)*t*e),s=Math.ceil(12/(2*Math.PI)*t);return Math.min(100,Math.max(s,i))},Ul=t=>{const e={type:"curve:polygon",points:[]};switch(t.type){case"curve:circle":const i=t.radius,s=Dl(2*Math.PI,i),r=t.position,n=2*Math.PI/s;let o=0;for(let t=0;t<s;t++)e.points.push([i*Math.cos(o)+r[0],-i*Math.sin(o)+r[1]]),o+=n;break;case"curve:polygon":e.points=t.points;break;case"curve:rectangle":const a=t.dimensions,[l,h]=t.position||[0,0];e.points=[[l,h],[l,h+a[1]],[l+a[0],h+a[1]],[l+a[0],h]];break;case"curve:composite":for(const u of t.segments){let t=Gl(u);e.points.push(...t.points)}}return e},Gl=t=>{const e={type:"curve:polyline",points:[]};switch(t.type){case"curve:line":e.points=[t.start,t.end];break;case"curve:arc":const i=t.startAngle/180*Math.PI,s=t.endAngle/180*Math.PI-i,r=t.radius,n=Dl(Math.abs(s),r),o=t.position,a=s/n;let l=i;for(let t=0;t<n+1;t++)e.points.push([r*Math.cos(l)+o[0],-r*Math.sin(l)+o[1]]),l+=a;break;case"curve:polyline":e.points=t.points;break;case"curve:quadraticBezier":e.points.push(t.points[0]);for(let h=0;h<=t.points.length-3;h++){let i=t.points[h],s=t.points[h+1],r=t.points[h+2],n=Fl(0===h?i:Bl(i,s),s,h===t.points.length-3?r:Bl(s,r));e.points.push(...n.slice(1))}}return e},Xl=(t,e,i=.15)=>{let s,r,n;for(const o of e)if(s=Math.abs(t[0]-o[0]),!(s>i)&&(r=Math.abs(t[1]-o[1]),s<i&&r<i)){n=o;break}return n};function Wl(t){const e={10:["ceilingLight","wallLight"],9:["modularMeetingRoom","phoneBooth"],8:["floorLamp","tableLamp","deskDivider","cushion","plant","officeSupply","tableware","decoration","laundry","electronics","kitchen","car"],7:["shelf","cabinet","wardrobe","storageCombination","outdoor","bicycle","people","sink"],6:["highTable","diningTable","conferenceTable","desk"],5:["sofa","armchair","loungeChair","ottoman","sideboard","pedestal"],4:["taskChair","diningChair","conferenceChair","stool","barStool","bench"],3:["shower"],2:["singleBed","doubleBed","daybed","toilet","bathtub"],1:["sideTable","coffeeTable","radiator","nightstand"],0:["rug"]};let i=0;return t.subCategories.forEach((t=>{Object.keys(e).forEach((s=>{let r=parseInt(s);e[s].includes(t)&&r>i&&(i=r)}))})),1===i&&t.categories.includes("tables")&&t.boundingBox.max[1]-t.boundingBox.min[1]>.6&&(i=6),i}var Hl=(t=>(t[t.WEBGL_LEGACY=0]="WEBGL_LEGACY",t[t.WEBGL=1]="WEBGL",t[t.WEBGL2=2]="WEBGL2",t))(Hl||{}),Yl=(t=>(t[t.UNKNOWN=0]="UNKNOWN",t[t.WEBGL=1]="WEBGL",t[t.CANVAS=2]="CANVAS",t))(Yl||{}),$l=(t=>(t[t.COLOR=16384]="COLOR",t[t.DEPTH=256]="DEPTH",t[t.STENCIL=1024]="STENCIL",t))($l||{}),jl=(t=>(t[t.NORMAL=0]="NORMAL",t[t.ADD=1]="ADD",t[t.MULTIPLY=2]="MULTIPLY",t[t.SCREEN=3]="SCREEN",t[t.OVERLAY=4]="OVERLAY",t[t.DARKEN=5]="DARKEN",t[t.LIGHTEN=6]="LIGHTEN",t[t.COLOR_DODGE=7]="COLOR_DODGE",t[t.COLOR_BURN=8]="COLOR_BURN",t[t.HARD_LIGHT=9]="HARD_LIGHT",t[t.SOFT_LIGHT=10]="SOFT_LIGHT",t[t.DIFFERENCE=11]="DIFFERENCE",t[t.EXCLUSION=12]="EXCLUSION",t[t.HUE=13]="HUE",t[t.SATURATION=14]="SATURATION",t[t.COLOR=15]="COLOR",t[t.LUMINOSITY=16]="LUMINOSITY",t[t.NORMAL_NPM=17]="NORMAL_NPM",t[t.ADD_NPM=18]="ADD_NPM",t[t.SCREEN_NPM=19]="SCREEN_NPM",t[t.NONE=20]="NONE",t[t.SRC_OVER=0]="SRC_OVER",t[t.SRC_IN=21]="SRC_IN",t[t.SRC_OUT=22]="SRC_OUT",t[t.SRC_ATOP=23]="SRC_ATOP",t[t.DST_OVER=24]="DST_OVER",t[t.DST_IN=25]="DST_IN",t[t.DST_OUT=26]="DST_OUT",t[t.DST_ATOP=27]="DST_ATOP",t[t.ERASE=26]="ERASE",t[t.SUBTRACT=28]="SUBTRACT",t[t.XOR=29]="XOR",t))(jl||{}),zl=(t=>(t[t.POINTS=0]="POINTS",t[t.LINES=1]="LINES",t[t.LINE_LOOP=2]="LINE_LOOP",t[t.LINE_STRIP=3]="LINE_STRIP",t[t.TRIANGLES=4]="TRIANGLES",t[t.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",t[t.TRIANGLE_FAN=6]="TRIANGLE_FAN",t))(zl||{}),Vl=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(Vl||{}),ql=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(ql||{}),Jl=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(Jl||{}),Kl=(t=>(t[t.FLOAT=0]="FLOAT",t[t.INT=1]="INT",t[t.UINT=2]="UINT",t))(Kl||{}),Zl=(t=>(t[t.NEAREST=0]="NEAREST",t[t.LINEAR=1]="LINEAR",t))(Zl||{}),Ql=(t=>(t[t.CLAMP=33071]="CLAMP",t[t.REPEAT=10497]="REPEAT",t[t.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",t))(Ql||{}),th=(t=>(t[t.OFF=0]="OFF",t[t.POW2=1]="POW2",t[t.ON=2]="ON",t[t.ON_MANUAL=3]="ON_MANUAL",t))(th||{}),eh=(t=>(t[t.NPM=0]="NPM",t[t.UNPACK=1]="UNPACK",t[t.PMA=2]="PMA",t[t.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",t[t.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",t[t.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",t))(eh||{}),ih=(t=>(t[t.NO=0]="NO",t[t.YES=1]="YES",t[t.AUTO=2]="AUTO",t[t.BLEND=0]="BLEND",t[t.CLEAR=1]="CLEAR",t[t.BLIT=2]="BLIT",t))(ih||{}),sh=(t=>(t[t.AUTO=0]="AUTO",t[t.MANUAL=1]="MANUAL",t))(sh||{}),rh=(t=>(t.LOW="lowp",t.MEDIUM="mediump",t.HIGH="highp",t))(rh||{}),nh=(t=>(t[t.NONE=0]="NONE",t[t.SCISSOR=1]="SCISSOR",t[t.STENCIL=2]="STENCIL",t[t.SPRITE=3]="SPRITE",t[t.COLOR=4]="COLOR",t))(nh||{}),oh=(t=>(t[t.NONE=0]="NONE",t[t.LOW=2]="LOW",t[t.MEDIUM=4]="MEDIUM",t[t.HIGH=8]="HIGH",t))(oh||{}),ah=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(ah||{});const lh={ADAPTER:{createCanvas:(t,e)=>{const i=document.createElement("canvas");return i.width=t,i.height=e,i},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(t,e)=>fetch(t,e),parseXML:t=>(new DOMParser).parseFromString(t,"text/xml")},RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var hh=/iPhone/i,uh=/iPod/i,ch=/iPad/i,dh=/\biOS-universal(?:.+)Mac\b/i,ph=/\bAndroid(?:.+)Mobile\b/i,fh=/Android/i,mh=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,gh=/Silk/i,yh=/Windows Phone/i,vh=/\bWindows(?:.+)ARM\b/i,xh=/BlackBerry/i,bh=/BB10/i,_h=/Opera Mini/i,wh=/\b(CriOS|Chrome)(?:.+)Mobile/i,Ph=/Mobile(?:.+)Firefox\b/i,Eh=function(t){return void 0!==t&&"MacIntel"===t.platform&&"number"==typeof t.maxTouchPoints&&t.maxTouchPoints>1&&"undefined"==typeof MSStream};function Th(t){var e={userAgent:"",platform:"",maxTouchPoints:0};t||"undefined"==typeof navigator?"string"==typeof t?e.userAgent=t:t&&t.userAgent&&(e={userAgent:t.userAgent,platform:t.platform,maxTouchPoints:t.maxTouchPoints||0}):e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0};var i=e.userAgent,s=i.split("[FBAN");void 0!==s[1]&&(i=s[0]),void 0!==(s=i.split("Twitter"))[1]&&(i=s[0]);var r=function(t){return function(e){return e.test(t)}}(i),n={apple:{phone:r(hh)&&!r(yh),ipod:r(uh),tablet:!r(hh)&&(r(ch)||Eh(e))&&!r(yh),universal:r(dh),device:(r(hh)||r(uh)||r(ch)||r(dh)||Eh(e))&&!r(yh)},amazon:{phone:r(mh),tablet:!r(mh)&&r(gh),device:r(mh)||r(gh)},android:{phone:!r(yh)&&r(mh)||!r(yh)&&r(ph),tablet:!r(yh)&&!r(mh)&&!r(ph)&&(r(gh)||r(fh)),device:!r(yh)&&(r(mh)||r(gh)||r(ph)||r(fh))||r(/\bokhttp\b/i)},windows:{phone:r(yh),tablet:r(vh),device:r(yh)||r(vh)},other:{blackberry:r(xh),blackberry10:r(bh),opera:r(_h),firefox:r(Ph),chrome:r(wh),device:r(xh)||r(bh)||r(_h)||r(Ph)||r(wh)},any:!1,phone:!1,tablet:!1};return n.any=n.apple.device||n.android.device||n.windows.device||n.other.device,n.phone=n.apple.phone||n.android.phone||n.windows.phone,n.tablet=n.apple.tablet||n.android.tablet||n.windows.tablet,n}const Ah=(Th.default??Th)(globalThis.navigator);lh.RETINA_PREFIX=/@([0-9\.]+)x/,lh.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ih={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function r(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,s,n,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new r(s,n||t,o),l=i?i+e:e;return t._events[l]?t._events[l].fn?t._events[l]=[t._events[l],a]:t._events[l].push(a):(t._events[l]=a,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),a.prototype.eventNames=function(){var t,s,r=[];if(0===this._eventsCount)return r;for(s in t=this._events)e.call(t,s)&&r.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,n=s.length,o=new Array(n);r<n;r++)o[r]=s[r].fn;return o},a.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},a.prototype.emit=function(t,e,s,r,n,o){var a=i?i+t:t;if(!this._events[a])return!1;var l,h,u=this._events[a],c=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),c){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,e),!0;case 3:return u.fn.call(u.context,e,s),!0;case 4:return u.fn.call(u.context,e,s,r),!0;case 5:return u.fn.call(u.context,e,s,r,n),!0;case 6:return u.fn.call(u.context,e,s,r,n,o),!0}for(h=1,l=new Array(c-1);h<c;h++)l[h-1]=arguments[h];u.fn.apply(u.context,l)}else{var d,p=u.length;for(h=0;h<p;h++)switch(u[h].once&&this.removeListener(t,u[h].fn,void 0,!0),c){case 1:u[h].fn.call(u[h].context);break;case 2:u[h].fn.call(u[h].context,e);break;case 3:u[h].fn.call(u[h].context,e,s);break;case 4:u[h].fn.call(u[h].context,e,s,r);break;default:if(!l)for(d=1,l=new Array(c-1);d<c;d++)l[d-1]=arguments[d];u[h].fn.apply(u[h].context,l)}}return!0},a.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},a.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},a.prototype.removeListener=function(t,e,s,r){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return o(this,n),this;var a=this._events[n];if(a.fn)a.fn!==e||r&&!a.once||s&&a.context!==s||o(this,n);else{for(var l=0,h=[],u=a.length;l<u;l++)(a[l].fn!==e||r&&!a[l].once||s&&a[l].context!==s)&&h.push(a[l]);h.length?this._events[n]=1===h.length?h[0]:h:o(this,n)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&o(this,e)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=i,a.EventEmitter=a,t.exports=a}(Ih);const Sh=Mt(Ih.exports);var Ch={exports:{}};
|
|
9
|
-
/*! https://mths.be/punycode v1.4.1 by @mathias */!function(t,e){!function(i){var s=e&&!e.nodeType&&e,r=t&&!t.nodeType&&t,n="object"==typeof Ct&&Ct;n.global!==n&&n.window!==n&&n.self!==n||(i=n);var o,a,l=2147483647,h=36,u=1,c=26,d=38,p=700,f=72,m=128,g="-",y=/^xn--/,v=/[^\x20-\x7E]/,x=/[\x2E\u3002\uFF0E\uFF61]/g,b={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},_=h-u,w=Math.floor,P=String.fromCharCode;function E(t){throw new RangeError(b[t])}function T(t,e){for(var i=t.length,s=[];i--;)s[i]=e(t[i]);return s}function A(t,e){var i=t.split("@"),s="";return i.length>1&&(s=i[0]+"@",t=i[1]),s+T((t=t.replace(x,".")).split("."),e).join(".")}function I(t){for(var e,i,s=[],r=0,n=t.length;r<n;)(e=t.charCodeAt(r++))>=55296&&e<=56319&&r<n?56320==(64512&(i=t.charCodeAt(r++)))?s.push(((1023&e)<<10)+(1023&i)+65536):(s.push(e),r--):s.push(e);return s}function S(t){return T(t,(function(t){var e="";return t>65535&&(e+=P((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=P(t)})).join("")}function C(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function M(t,e,i){var s=0;for(t=i?w(t/p):t>>1,t+=w(t/e);t>_*c>>1;s+=h)t=w(t/_);return w(s+(_+1)*t/(t+d))}function O(t){var e,i,s,r,n,o,a,d,p,y,v,x=[],b=t.length,_=0,P=m,T=f;for((i=t.lastIndexOf(g))<0&&(i=0),s=0;s<i;++s)t.charCodeAt(s)>=128&&E("not-basic"),x.push(t.charCodeAt(s));for(r=i>0?i+1:0;r<b;){for(n=_,o=1,a=h;r>=b&&E("invalid-input"),((d=(v=t.charCodeAt(r++))-48<10?v-22:v-65<26?v-65:v-97<26?v-97:h)>=h||d>w((l-_)/o))&&E("overflow"),_+=d*o,!(d<(p=a<=T?u:a>=T+c?c:a-T));a+=h)o>w(l/(y=h-p))&&E("overflow"),o*=y;T=M(_-n,e=x.length+1,0==n),w(_/e)>l-P&&E("overflow"),P+=w(_/e),_%=e,x.splice(_++,0,P)}return S(x)}function N(t){var e,i,s,r,n,o,a,d,p,y,v,x,b,_,T,A=[];for(x=(t=I(t)).length,e=m,i=0,n=f,o=0;o<x;++o)(v=t[o])<128&&A.push(P(v));for(s=r=A.length,r&&A.push(g);s<x;){for(a=l,o=0;o<x;++o)(v=t[o])>=e&&v<a&&(a=v);for(a-e>w((l-i)/(b=s+1))&&E("overflow"),i+=(a-e)*b,e=a,o=0;o<x;++o)if((v=t[o])<e&&++i>l&&E("overflow"),v==e){for(d=i,p=h;!(d<(y=p<=n?u:p>=n+c?c:p-n));p+=h)T=d-y,_=h-y,A.push(P(C(y+T%_,0))),d=w(T/_);A.push(P(C(d,0))),n=M(i,b,s==r),i=0,++s}++i,++e}return A.join("")}if(o={version:"1.4.1",ucs2:{decode:I,encode:S},decode:O,encode:N,toASCII:function(t){return A(t,(function(t){return v.test(t)?"xn--"+N(t):t}))},toUnicode:function(t){return A(t,(function(t){return y.test(t)?O(t.slice(4).toLowerCase()):t}))}},s&&r)if(t.exports==s)r.exports=o;else for(a in o)o.hasOwnProperty(a)&&(s[a]=o[a]);else i.punycode=o}(Ct)}(Ch,Ch.exports);var Mh,Oh=Ch.exports,Nh=Error,Lh=EvalError,Rh=RangeError,kh=ReferenceError,Bh=SyntaxError,Fh=TypeError,Dh=URIError,Uh="undefined"!=typeof Symbol&&Symbol,Gh=function(){if("function"!=typeof Symbol||"function"!=typeof Object.getOwnPropertySymbols)return!1;if("symbol"==typeof Symbol.iterator)return!0;var t={},e=Symbol("test"),i=Object(e);if("string"==typeof e)return!1;if("[object Symbol]"!==Object.prototype.toString.call(e))return!1;if("[object Symbol]"!==Object.prototype.toString.call(i))return!1;for(e in t[e]=42,t)return!1;if("function"==typeof Object.keys&&0!==Object.keys(t).length)return!1;if("function"==typeof Object.getOwnPropertyNames&&0!==Object.getOwnPropertyNames(t).length)return!1;var s=Object.getOwnPropertySymbols(t);if(1!==s.length||s[0]!==e)return!1;if(!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if("function"==typeof Object.getOwnPropertyDescriptor){var r=Object.getOwnPropertyDescriptor(t,e);if(42!==r.value||!0!==r.enumerable)return!1}return!0},Xh={__proto__:null,foo:{}},Wh=Object,Hh=Object.prototype.toString,Yh=Math.max,$h=function(t,e){for(var i=[],s=0;s<t.length;s+=1)i[s]=t[s];for(var r=0;r<e.length;r+=1)i[r+t.length]=e[r];return i},jh=function(t){var e=this;if("function"!=typeof e||"[object Function]"!==Hh.apply(e))throw new TypeError("Function.prototype.bind called on incompatible "+e);for(var i,s=function(t,e){for(var i=[],s=e,r=0;s<t.length;s+=1,r+=1)i[r]=t[s];return i}(arguments,1),r=Yh(0,e.length-s.length),n=[],o=0;o<r;o++)n[o]="$"+o;if(i=Function("binder","return function ("+function(t,e){for(var i="",s=0;s<t.length;s+=1)i+=t[s],s+1<t.length&&(i+=e);return i}(n,",")+"){ return binder.apply(this,arguments); }")((function(){if(this instanceof i){var r=e.apply(this,$h(s,arguments));return Object(r)===r?r:this}return e.apply(t,$h(s,arguments))})),e.prototype){var a=function(){};a.prototype=e.prototype,i.prototype=new a,a.prototype=null}return i},zh=Function.prototype.bind||jh,Vh=Function.prototype.call,qh=Object.prototype.hasOwnProperty,Jh=zh.call(Vh,qh),Kh=Nh,Zh=Lh,Qh=Rh,tu=kh,eu=Bh,iu=Fh,su=Dh,ru=Function,nu=function(t){try{return ru('"use strict"; return ('+t+").constructor;")()}catch(e){}},ou=Object.getOwnPropertyDescriptor;if(ou)try{ou({},"")}catch(xw){ou=null}var au=function(){throw new iu},lu=ou?function(){try{return au}catch(t){try{return ou(arguments,"callee").get}catch(e){return au}}}():au,hu="function"==typeof Uh&&"function"==typeof Symbol&&"symbol"==typeof Uh("foo")&&"symbol"==typeof Symbol("bar")&&Gh(),uu={__proto__:Xh}.foo===Xh.foo&&!(Xh instanceof Wh),cu=Object.getPrototypeOf||(uu?function(t){return t.__proto__}:null),du={},pu="undefined"!=typeof Uint8Array&&cu?cu(Uint8Array):Mh,fu={__proto__:null,"%AggregateError%":"undefined"==typeof AggregateError?Mh:AggregateError,"%Array%":Array,"%ArrayBuffer%":"undefined"==typeof ArrayBuffer?Mh:ArrayBuffer,"%ArrayIteratorPrototype%":hu&&cu?cu([][Symbol.iterator]()):Mh,"%AsyncFromSyncIteratorPrototype%":Mh,"%AsyncFunction%":du,"%AsyncGenerator%":du,"%AsyncGeneratorFunction%":du,"%AsyncIteratorPrototype%":du,"%Atomics%":"undefined"==typeof Atomics?Mh:Atomics,"%BigInt%":"undefined"==typeof BigInt?Mh:BigInt,"%BigInt64Array%":"undefined"==typeof BigInt64Array?Mh:BigInt64Array,"%BigUint64Array%":"undefined"==typeof BigUint64Array?Mh:BigUint64Array,"%Boolean%":Boolean,"%DataView%":"undefined"==typeof DataView?Mh:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Kh,"%eval%":eval,"%EvalError%":Zh,"%Float32Array%":"undefined"==typeof Float32Array?Mh:Float32Array,"%Float64Array%":"undefined"==typeof Float64Array?Mh:Float64Array,"%FinalizationRegistry%":"undefined"==typeof FinalizationRegistry?Mh:FinalizationRegistry,"%Function%":ru,"%GeneratorFunction%":du,"%Int8Array%":"undefined"==typeof Int8Array?Mh:Int8Array,"%Int16Array%":"undefined"==typeof Int16Array?Mh:Int16Array,"%Int32Array%":"undefined"==typeof Int32Array?Mh:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":hu&&cu?cu(cu([][Symbol.iterator]())):Mh,"%JSON%":"object"==typeof JSON?JSON:Mh,"%Map%":"undefined"==typeof Map?Mh:Map,"%MapIteratorPrototype%":"undefined"!=typeof Map&&hu&&cu?cu((new Map)[Symbol.iterator]()):Mh,"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":"undefined"==typeof Promise?Mh:Promise,"%Proxy%":"undefined"==typeof Proxy?Mh:Proxy,"%RangeError%":Qh,"%ReferenceError%":tu,"%Reflect%":"undefined"==typeof Reflect?Mh:Reflect,"%RegExp%":RegExp,"%Set%":"undefined"==typeof Set?Mh:Set,"%SetIteratorPrototype%":"undefined"!=typeof Set&&hu&&cu?cu((new Set)[Symbol.iterator]()):Mh,"%SharedArrayBuffer%":"undefined"==typeof SharedArrayBuffer?Mh:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":hu&&cu?cu(""[Symbol.iterator]()):Mh,"%Symbol%":hu?Symbol:Mh,"%SyntaxError%":eu,"%ThrowTypeError%":lu,"%TypedArray%":pu,"%TypeError%":iu,"%Uint8Array%":"undefined"==typeof Uint8Array?Mh:Uint8Array,"%Uint8ClampedArray%":"undefined"==typeof Uint8ClampedArray?Mh:Uint8ClampedArray,"%Uint16Array%":"undefined"==typeof Uint16Array?Mh:Uint16Array,"%Uint32Array%":"undefined"==typeof Uint32Array?Mh:Uint32Array,"%URIError%":su,"%WeakMap%":"undefined"==typeof WeakMap?Mh:WeakMap,"%WeakRef%":"undefined"==typeof WeakRef?Mh:WeakRef,"%WeakSet%":"undefined"==typeof WeakSet?Mh:WeakSet};if(cu)try{null.error}catch(xw){var mu=cu(cu(xw));fu["%Error.prototype%"]=mu}var gu,yu,vu=function t(e){var i;if("%AsyncFunction%"===e)i=nu("async function () {}");else if("%GeneratorFunction%"===e)i=nu("function* () {}");else if("%AsyncGeneratorFunction%"===e)i=nu("async function* () {}");else if("%AsyncGenerator%"===e){var s=t("%AsyncGeneratorFunction%");s&&(i=s.prototype)}else if("%AsyncIteratorPrototype%"===e){var r=t("%AsyncGenerator%");r&&cu&&(i=cu(r.prototype))}return fu[e]=i,i},xu={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},bu=zh,_u=Jh,wu=bu.call(Function.call,Array.prototype.concat),Pu=bu.call(Function.apply,Array.prototype.splice),Eu=bu.call(Function.call,String.prototype.replace),Tu=bu.call(Function.call,String.prototype.slice),Au=bu.call(Function.call,RegExp.prototype.exec),Iu=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Su=/\\(\\)?/g,Cu=function(t,e){var i,s=t;if(_u(xu,s)&&(s="%"+(i=xu[s])[0]+"%"),_u(fu,s)){var r=fu[s];if(r===du&&(r=vu(s)),void 0===r&&!e)throw new iu("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:i,name:s,value:r}}throw new eu("intrinsic "+t+" does not exist!")},Mu=function(t,e){if("string"!=typeof t||0===t.length)throw new iu("intrinsic name must be a non-empty string");if(arguments.length>1&&"boolean"!=typeof e)throw new iu('"allowMissing" argument must be a boolean');if(null===Au(/^%?[^%]*%?$/,t))throw new eu("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=function(t){var e=Tu(t,0,1),i=Tu(t,-1);if("%"===e&&"%"!==i)throw new eu("invalid intrinsic syntax, expected closing `%`");if("%"===i&&"%"!==e)throw new eu("invalid intrinsic syntax, expected opening `%`");var s=[];return Eu(t,Iu,(function(t,e,i,r){s[s.length]=i?Eu(r,Su,"$1"):e||t})),s}(t),s=i.length>0?i[0]:"",r=Cu("%"+s+"%",e),n=r.name,o=r.value,a=!1,l=r.alias;l&&(s=l[0],Pu(i,wu([0,1],l)));for(var h=1,u=!0;h<i.length;h+=1){var c=i[h],d=Tu(c,0,1),p=Tu(c,-1);if(('"'===d||"'"===d||"`"===d||'"'===p||"'"===p||"`"===p)&&d!==p)throw new eu("property names with quotes must have matching quotes");if("constructor"!==c&&u||(a=!0),_u(fu,n="%"+(s+="."+c)+"%"))o=fu[n];else if(null!=o){if(!(c in o)){if(!e)throw new iu("base intrinsic for "+t+" exists, but the property is not available.");return}if(ou&&h+1>=i.length){var f=ou(o,c);o=(u=!!f)&&"get"in f&&!("originalValue"in f.get)?f.get:o[c]}else u=_u(o,c),o=o[c];u&&!a&&(fu[n]=o)}}return o},Ou={exports:{}};function Nu(){if(yu)return gu;yu=1;var t=Mu("%Object.defineProperty%",!0)||!1;if(t)try{t({},"a",{value:1})}catch(xw){t=!1}return gu=t}var Lu=Mu("%Object.getOwnPropertyDescriptor%",!0);if(Lu)try{Lu([],"length")}catch(xw){Lu=null}var Ru=Lu,ku=Nu(),Bu=Bh,Fu=Fh,Du=Ru,Uu=Nu(),Gu=function(){return!!Uu};Gu.hasArrayLengthDefineBug=function(){if(!Uu)return null;try{return 1!==Uu([],"length",{value:1}).length}catch(xw){return!0}};var Xu=Mu,Wu=function(t,e,i){if(!t||"object"!=typeof t&&"function"!=typeof t)throw new Fu("`obj` must be an object or a function`");if("string"!=typeof e&&"symbol"!=typeof e)throw new Fu("`property` must be a string or a symbol`");if(arguments.length>3&&"boolean"!=typeof arguments[3]&&null!==arguments[3])throw new Fu("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&"boolean"!=typeof arguments[4]&&null!==arguments[4])throw new Fu("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&"boolean"!=typeof arguments[5]&&null!==arguments[5])throw new Fu("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&"boolean"!=typeof arguments[6])throw new Fu("`loose`, if provided, must be a boolean");var s=arguments.length>3?arguments[3]:null,r=arguments.length>4?arguments[4]:null,n=arguments.length>5?arguments[5]:null,o=arguments.length>6&&arguments[6],a=!!Du&&Du(t,e);if(ku)ku(t,e,{configurable:null===n&&a?a.configurable:!n,enumerable:null===s&&a?a.enumerable:!s,value:i,writable:null===r&&a?a.writable:!r});else{if(!o&&(s||r||n))throw new Bu("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.");t[e]=i}},Hu=Gu(),Yu=Ru,$u=Fh,ju=Xu("%Math.floor%"),zu=function(t,e){if("function"!=typeof t)throw new $u("`fn` is not a function");if("number"!=typeof e||e<0||e>4294967295||ju(e)!==e)throw new $u("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],s=!0,r=!0;if("length"in t&&Yu){var n=Yu(t,"length");n&&!n.configurable&&(s=!1),n&&!n.writable&&(r=!1)}return(s||r||!i)&&(Hu?Wu(t,"length",e,!0,!0):Wu(t,"length",e)),t};!function(t){var e=zh,i=Mu,s=zu,r=Fh,n=i("%Function.prototype.apply%"),o=i("%Function.prototype.call%"),a=i("%Reflect.apply%",!0)||e.call(o,n),l=Nu(),h=i("%Math.max%");t.exports=function(t){if("function"!=typeof t)throw new r("a function is required");var i=a(e,o,arguments);return s(i,1+h(0,t.length-(arguments.length-1)),!0)};var u=function(){return a(e,n,arguments)};l?l(t.exports,"apply",{value:u}):t.exports.apply=u}(Ou);var Vu=Mu,qu=Ou.exports,Ju=qu(Vu("String.prototype.indexOf"));const Ku=Ot(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Zu="function"==typeof Map&&Map.prototype,Qu=Object.getOwnPropertyDescriptor&&Zu?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,tc=Zu&&Qu&&"function"==typeof Qu.get?Qu.get:null,ec=Zu&&Map.prototype.forEach,ic="function"==typeof Set&&Set.prototype,sc=Object.getOwnPropertyDescriptor&&ic?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,rc=ic&&sc&&"function"==typeof sc.get?sc.get:null,nc=ic&&Set.prototype.forEach,oc="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,ac="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,lc="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,hc=Boolean.prototype.valueOf,uc=Object.prototype.toString,cc=Function.prototype.toString,dc=String.prototype.match,pc=String.prototype.slice,fc=String.prototype.replace,mc=String.prototype.toUpperCase,gc=String.prototype.toLowerCase,yc=RegExp.prototype.test,vc=Array.prototype.concat,xc=Array.prototype.join,bc=Array.prototype.slice,_c=Math.floor,wc="function"==typeof BigInt?BigInt.prototype.valueOf:null,Pc=Object.getOwnPropertySymbols,Ec="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Tc="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Ac="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Tc||"symbol")?Symbol.toStringTag:null,Ic=Object.prototype.propertyIsEnumerable,Sc=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(t){return t.__proto__}:null);function Cc(t,e){if(t===1/0||t===-1/0||t!=t||t&&t>-1e3&&t<1e3||yc.call(/e/,e))return e;var i=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof t){var s=t<0?-_c(-t):_c(t);if(s!==t){var r=String(s),n=pc.call(e,r.length+1);return fc.call(r,i,"$&_")+"."+fc.call(fc.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return fc.call(e,i,"$&_")}var Mc=Ku,Oc=Mc.custom,Nc=Fc(Oc)?Oc:null;function Lc(t,e,i){var s="double"===(i.quoteStyle||e)?'"':"'";return s+t+s}function Rc(t){return fc.call(String(t),/"/g,""")}function kc(t){return!("[object Array]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}function Bc(t){return!("[object RegExp]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}function Fc(t){if(Tc)return t&&"object"==typeof t&&t instanceof Symbol;if("symbol"==typeof t)return!0;if(!t||"object"!=typeof t||!Ec)return!1;try{return Ec.call(t),!0}catch(xw){}return!1}var Dc=Object.prototype.hasOwnProperty||function(t){return t in this};function Uc(t,e){return Dc.call(t,e)}function Gc(t){return uc.call(t)}function Xc(t,e){if(t.indexOf)return t.indexOf(e);for(var i=0,s=t.length;i<s;i++)if(t[i]===e)return i;return-1}function Wc(t,e){if(t.length>e.maxStringLength){var i=t.length-e.maxStringLength,s="... "+i+" more character"+(i>1?"s":"");return Wc(pc.call(t,0,e.maxStringLength),e)+s}return Lc(fc.call(fc.call(t,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,Hc),"single",e)}function Hc(t){var e=t.charCodeAt(0),i={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return i?"\\"+i:"\\x"+(e<16?"0":"")+mc.call(e.toString(16))}function Yc(t){return"Object("+t+")"}function $c(t){return t+" { ? }"}function jc(t,e,i,s){return t+" ("+e+") {"+(s?zc(i,s):xc.call(i,", "))+"}"}function zc(t,e){if(0===t.length)return"";var i="\n"+e.prev+e.base;return i+xc.call(t,","+i)+"\n"+e.prev}function Vc(t,e){var i=kc(t),s=[];if(i){s.length=t.length;for(var r=0;r<t.length;r++)s[r]=Uc(t,r)?e(t[r],t):""}var n,o="function"==typeof Pc?Pc(t):[];if(Tc){n={};for(var a=0;a<o.length;a++)n["$"+o[a]]=o[a]}for(var l in t)Uc(t,l)&&(i&&String(Number(l))===l&&l<t.length||Tc&&n["$"+l]instanceof Symbol||(yc.call(/[^\w$]/,l)?s.push(e(l,t)+": "+e(t[l],t)):s.push(l+": "+e(t[l],t))));if("function"==typeof Pc)for(var h=0;h<o.length;h++)Ic.call(t,o[h])&&s.push("["+e(o[h])+"]: "+e(t[o[h]],t));return s}var qc=Mu,Jc=function(t,e){var i=Vu(t,!!e);return"function"==typeof i&&Ju(t,".prototype.")>-1?qu(i):i},Kc=function t(e,i,s,r){var n=i||{};if(Uc(n,"quoteStyle")&&"single"!==n.quoteStyle&&"double"!==n.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Uc(n,"maxStringLength")&&("number"==typeof n.maxStringLength?n.maxStringLength<0&&n.maxStringLength!==1/0:null!==n.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=!Uc(n,"customInspect")||n.customInspect;if("boolean"!=typeof o&&"symbol"!==o)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Uc(n,"indent")&&null!==n.indent&&"\t"!==n.indent&&!(parseInt(n.indent,10)===n.indent&&n.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Uc(n,"numericSeparator")&&"boolean"!=typeof n.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=n.numericSeparator;if(void 0===e)return"undefined";if(null===e)return"null";if("boolean"==typeof e)return e?"true":"false";if("string"==typeof e)return Wc(e,n);if("number"==typeof e){if(0===e)return 1/0/e>0?"0":"-0";var l=String(e);return a?Cc(e,l):l}if("bigint"==typeof e){var h=String(e)+"n";return a?Cc(e,h):h}var u=void 0===n.depth?5:n.depth;if(void 0===s&&(s=0),s>=u&&u>0&&"object"==typeof e)return kc(e)?"[Array]":"[Object]";var c=function(t,e){var i;if("\t"===t.indent)i="\t";else{if(!("number"==typeof t.indent&&t.indent>0))return null;i=xc.call(Array(t.indent+1)," ")}return{base:i,prev:xc.call(Array(e+1),i)}}(n,s);if(void 0===r)r=[];else if(Xc(r,e)>=0)return"[Circular]";function d(e,i,o){if(i&&(r=bc.call(r)).push(i),o){var a={depth:n.depth};return Uc(n,"quoteStyle")&&(a.quoteStyle=n.quoteStyle),t(e,a,s+1,r)}return t(e,n,s+1,r)}if("function"==typeof e&&!Bc(e)){var p=function(t){if(t.name)return t.name;var e=dc.call(cc.call(t),/^function\s*([\w$]+)/);if(e)return e[1];return null}(e),f=Vc(e,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+xc.call(f,", ")+" }":"")}if(Fc(e)){var m=Tc?fc.call(String(e),/^(Symbol\(.*\))_[^)]*$/,"$1"):Ec.call(e);return"object"!=typeof e||Tc?m:Yc(m)}if(function(t){if(!t||"object"!=typeof t)return!1;if("undefined"!=typeof HTMLElement&&t instanceof HTMLElement)return!0;return"string"==typeof t.nodeName&&"function"==typeof t.getAttribute}(e)){for(var g="<"+gc.call(String(e.nodeName)),y=e.attributes||[],v=0;v<y.length;v++)g+=" "+y[v].name+"="+Lc(Rc(y[v].value),"double",n);return g+=">",e.childNodes&&e.childNodes.length&&(g+="..."),g+="</"+gc.call(String(e.nodeName))+">"}if(kc(e)){if(0===e.length)return"[]";var x=Vc(e,d);return c&&!function(t){for(var e=0;e<t.length;e++)if(Xc(t[e],"\n")>=0)return!1;return!0}(x)?"["+zc(x,c)+"]":"[ "+xc.call(x,", ")+" ]"}if(function(t){return!("[object Error]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}(e)){var b=Vc(e,d);return"cause"in Error.prototype||!("cause"in e)||Ic.call(e,"cause")?0===b.length?"["+String(e)+"]":"{ ["+String(e)+"] "+xc.call(b,", ")+" }":"{ ["+String(e)+"] "+xc.call(vc.call("[cause]: "+d(e.cause),b),", ")+" }"}if("object"==typeof e&&o){if(Nc&&"function"==typeof e[Nc]&&Mc)return Mc(e,{depth:u-s});if("symbol"!==o&&"function"==typeof e.inspect)return e.inspect()}if(function(t){if(!tc||!t||"object"!=typeof t)return!1;try{tc.call(t);try{rc.call(t)}catch(g){return!0}return t instanceof Map}catch(xw){}return!1}(e)){var _=[];return ec&&ec.call(e,(function(t,i){_.push(d(i,e,!0)+" => "+d(t,e))})),jc("Map",tc.call(e),_,c)}if(function(t){if(!rc||!t||"object"!=typeof t)return!1;try{rc.call(t);try{tc.call(t)}catch(e){return!0}return t instanceof Set}catch(xw){}return!1}(e)){var w=[];return nc&&nc.call(e,(function(t){w.push(d(t,e))})),jc("Set",rc.call(e),w,c)}if(function(t){if(!oc||!t||"object"!=typeof t)return!1;try{oc.call(t,oc);try{ac.call(t,ac)}catch(g){return!0}return t instanceof WeakMap}catch(xw){}return!1}(e))return $c("WeakMap");if(function(t){if(!ac||!t||"object"!=typeof t)return!1;try{ac.call(t,ac);try{oc.call(t,oc)}catch(g){return!0}return t instanceof WeakSet}catch(xw){}return!1}(e))return $c("WeakSet");if(function(t){if(!lc||!t||"object"!=typeof t)return!1;try{return lc.call(t),!0}catch(xw){}return!1}(e))return $c("WeakRef");if(function(t){return!("[object Number]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}(e))return Yc(d(Number(e)));if(function(t){if(!t||"object"!=typeof t||!wc)return!1;try{return wc.call(t),!0}catch(xw){}return!1}(e))return Yc(d(wc.call(e)));if(function(t){return!("[object Boolean]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}(e))return Yc(hc.call(e));if(function(t){return!("[object String]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}(e))return Yc(d(String(e)));if("undefined"!=typeof window&&e===window)return"{ [object Window] }";if("undefined"!=typeof globalThis&&e===globalThis||void 0!==Ct&&e===Ct)return"{ [object globalThis] }";if(!function(t){return!("[object Date]"!==Gc(t)||Ac&&"object"==typeof t&&Ac in t)}(e)&&!Bc(e)){var P=Vc(e,d),E=Sc?Sc(e)===Object.prototype:e instanceof Object||e.constructor===Object,T=e instanceof Object?"":"null prototype",A=!E&&Ac&&Object(e)===e&&Ac in e?pc.call(Gc(e),8,-1):T?"Object":"",I=(E||"function"!=typeof e.constructor?"":e.constructor.name?e.constructor.name+" ":"")+(A||T?"["+xc.call(vc.call([],A||[],T||[]),": ")+"] ":"");return 0===P.length?I+"{}":c?I+"{"+zc(P,c)+"}":I+"{ "+xc.call(P,", ")+" }"}return String(e)},Zc=Fh,Qc=qc("%WeakMap%",!0),td=qc("%Map%",!0),ed=Jc("WeakMap.prototype.get",!0),id=Jc("WeakMap.prototype.set",!0),sd=Jc("WeakMap.prototype.has",!0),rd=Jc("Map.prototype.get",!0),nd=Jc("Map.prototype.set",!0),od=Jc("Map.prototype.has",!0),ad=function(t,e){for(var i,s=t;null!==(i=s.next);s=i)if(i.key===e)return s.next=i.next,i.next=t.next,t.next=i,i},ld=String.prototype.replace,hd=/%20/g,ud="RFC3986",cd={default:ud,formatters:{RFC1738:function(t){return ld.call(t,hd,"+")},RFC3986:function(t){return String(t)}},RFC1738:"RFC1738",RFC3986:ud},dd=cd,pd=Object.prototype.hasOwnProperty,fd=Array.isArray,md=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),gd=function(t,e){for(var i=e&&e.plainObjects?Object.create(null):{},s=0;s<t.length;++s)void 0!==t[s]&&(i[s]=t[s]);return i},yd=1024,vd={arrayToObject:gd,assign:function(t,e){return Object.keys(e).reduce((function(t,i){return t[i]=e[i],t}),t)},combine:function(t,e){return[].concat(t,e)},compact:function(t){for(var e=[{obj:{o:t},prop:"o"}],i=[],s=0;s<e.length;++s)for(var r=e[s],n=r.obj[r.prop],o=Object.keys(n),a=0;a<o.length;++a){var l=o[a],h=n[l];"object"==typeof h&&null!==h&&-1===i.indexOf(h)&&(e.push({obj:n,prop:l}),i.push(h))}return function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(fd(i)){for(var s=[],r=0;r<i.length;++r)void 0!==i[r]&&s.push(i[r]);e.obj[e.prop]=s}}}(e),t},decode:function(t,e,i){var s=t.replace(/\+/g," ");if("iso-8859-1"===i)return s.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(s)}catch(xw){return s}},encode:function(t,e,i,s,r){if(0===t.length)return t;var n=t;if("symbol"==typeof t?n=Symbol.prototype.toString.call(t):"string"!=typeof t&&(n=String(t)),"iso-8859-1"===i)return escape(n).replace(/%u[0-9a-f]{4}/gi,(function(t){return"%26%23"+parseInt(t.slice(2),16)+"%3B"}));for(var o="",a=0;a<n.length;a+=yd){for(var l=n.length>=yd?n.slice(a,a+yd):n,h=[],u=0;u<l.length;++u){var c=l.charCodeAt(u);45===c||46===c||95===c||126===c||c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||r===dd.RFC1738&&(40===c||41===c)?h[h.length]=l.charAt(u):c<128?h[h.length]=md[c]:c<2048?h[h.length]=md[192|c>>6]+md[128|63&c]:c<55296||c>=57344?h[h.length]=md[224|c>>12]+md[128|c>>6&63]+md[128|63&c]:(u+=1,c=65536+((1023&c)<<10|1023&l.charCodeAt(u)),h[h.length]=md[240|c>>18]+md[128|c>>12&63]+md[128|c>>6&63]+md[128|63&c])}o+=h.join("")}return o},isBuffer:function(t){return!(!t||"object"!=typeof t)&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(fd(t)){for(var i=[],s=0;s<t.length;s+=1)i.push(e(t[s]));return i}return e(t)},merge:function t(e,i,s){if(!i)return e;if("object"!=typeof i){if(fd(e))e.push(i);else{if(!e||"object"!=typeof e)return[e,i];(s&&(s.plainObjects||s.allowPrototypes)||!pd.call(Object.prototype,i))&&(e[i]=!0)}return e}if(!e||"object"!=typeof e)return[e].concat(i);var r=e;return fd(e)&&!fd(i)&&(r=gd(e,s)),fd(e)&&fd(i)?(i.forEach((function(i,r){if(pd.call(e,r)){var n=e[r];n&&"object"==typeof n&&i&&"object"==typeof i?e[r]=t(n,i,s):e.push(i)}else e[r]=i})),e):Object.keys(i).reduce((function(e,r){var n=i[r];return pd.call(e,r)?e[r]=t(e[r],n,s):e[r]=n,e}),r)}},xd=function(){var t,e,i,s={assert:function(t){if(!s.has(t))throw new Zc("Side channel does not contain "+Kc(t))},get:function(s){if(Qc&&s&&("object"==typeof s||"function"==typeof s)){if(t)return ed(t,s)}else if(td){if(e)return rd(e,s)}else if(i)return function(t,e){var i=ad(t,e);return i&&i.value}(i,s)},has:function(s){if(Qc&&s&&("object"==typeof s||"function"==typeof s)){if(t)return sd(t,s)}else if(td){if(e)return od(e,s)}else if(i)return function(t,e){return!!ad(t,e)}(i,s);return!1},set:function(s,r){Qc&&s&&("object"==typeof s||"function"==typeof s)?(t||(t=new Qc),id(t,s,r)):td?(e||(e=new td),nd(e,s,r)):(i||(i={key:{},next:null}),function(t,e,i){var s=ad(t,e);s?s.value=i:t.next={key:e,next:t.next,value:i}}(i,s,r))}};return s},bd=vd,_d=cd,wd=Object.prototype.hasOwnProperty,Pd={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},Ed=Array.isArray,Td=Array.prototype.push,Ad=function(t,e){Td.apply(t,Ed(e)?e:[e])},Id=Date.prototype.toISOString,Sd=_d.default,Cd={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:bd.encode,encodeValuesOnly:!1,format:Sd,formatter:_d.formatters[Sd],indices:!1,serializeDate:function(t){return Id.call(t)},skipNulls:!1,strictNullHandling:!1},Md={},Od=function t(e,i,s,r,n,o,a,l,h,u,c,d,p,f,m,g,y,v){for(var x,b=e,_=v,w=0,P=!1;void 0!==(_=_.get(Md))&&!P;){var E=_.get(e);if(w+=1,void 0!==E){if(E===w)throw new RangeError("Cyclic object value");P=!0}void 0===_.get(Md)&&(w=0)}if("function"==typeof u?b=u(i,b):b instanceof Date?b=p(b):"comma"===s&&Ed(b)&&(b=bd.maybeMap(b,(function(t){return t instanceof Date?p(t):t}))),null===b){if(o)return h&&!g?h(i,Cd.encoder,y,"key",f):i;b=""}if("string"==typeof(x=b)||"number"==typeof x||"boolean"==typeof x||"symbol"==typeof x||"bigint"==typeof x||bd.isBuffer(b))return h?[m(g?i:h(i,Cd.encoder,y,"key",f))+"="+m(h(b,Cd.encoder,y,"value",f))]:[m(i)+"="+m(String(b))];var T,A=[];if(void 0===b)return A;if("comma"===s&&Ed(b))g&&h&&(b=bd.maybeMap(b,h)),T=[{value:b.length>0?b.join(",")||null:void 0}];else if(Ed(u))T=u;else{var I=Object.keys(b);T=c?I.sort(c):I}var S=l?i.replace(/\./g,"%2E"):i,C=r&&Ed(b)&&1===b.length?S+"[]":S;if(n&&Ed(b)&&0===b.length)return C+"[]";for(var M=0;M<T.length;++M){var O=T[M],N="object"==typeof O&&void 0!==O.value?O.value:b[O];if(!a||null!==N){var L=d&&l?O.replace(/\./g,"%2E"):O,R=Ed(b)?"function"==typeof s?s(C,L):C:C+(d?"."+L:"["+L+"]");v.set(e,w);var k=xd();k.set(Md,v),Ad(A,t(N,R,s,r,n,o,a,l,"comma"===s&&g&&Ed(b)?null:h,u,c,d,p,f,m,g,y,k))}}return A},Nd=vd,Ld=Object.prototype.hasOwnProperty,Rd=Array.isArray,kd={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:Nd.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},Bd=function(t){return t.replace(/&#(\d+);/g,(function(t,e){return String.fromCharCode(parseInt(e,10))}))},Fd=function(t,e){return t&&"string"==typeof t&&e.comma&&t.indexOf(",")>-1?t.split(","):t},Dd=function(t,e,i,s){if(t){var r=i.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,n=/(\[[^[\]]*])/g,o=i.depth>0&&/(\[[^[\]]*])/.exec(r),a=o?r.slice(0,o.index):r,l=[];if(a){if(!i.plainObjects&&Ld.call(Object.prototype,a)&&!i.allowPrototypes)return;l.push(a)}for(var h=0;i.depth>0&&null!==(o=n.exec(r))&&h<i.depth;){if(h+=1,!i.plainObjects&&Ld.call(Object.prototype,o[1].slice(1,-1))&&!i.allowPrototypes)return;l.push(o[1])}return o&&l.push("["+r.slice(o.index)+"]"),function(t,e,i,s){for(var r=s?e:Fd(e,i),n=t.length-1;n>=0;--n){var o,a=t[n];if("[]"===a&&i.parseArrays)o=i.allowEmptyArrays&&(""===r||i.strictNullHandling&&null===r)?[]:[].concat(r);else{o=i.plainObjects?Object.create(null):{};var l="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,h=i.decodeDotInKeys?l.replace(/%2E/g,"."):l,u=parseInt(h,10);i.parseArrays||""!==h?!isNaN(u)&&a!==h&&String(u)===h&&u>=0&&i.parseArrays&&u<=i.arrayLimit?(o=[])[u]=r:"__proto__"!==h&&(o[h]=r):o={0:r}}r=o}return r}(l,e,i,s)}},Ud={formats:cd,parse:function(t,e){var i=function(t){if(!t)return kd;if(void 0!==t.allowEmptyArrays&&"boolean"!=typeof t.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==t.decodeDotInKeys&&"boolean"!=typeof t.decodeDotInKeys)throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=void 0===t.charset?kd.charset:t.charset,i=void 0===t.duplicates?kd.duplicates:t.duplicates;if("combine"!==i&&"first"!==i&&"last"!==i)throw new TypeError("The duplicates option must be either combine, first, or last");return{allowDots:void 0===t.allowDots?!0===t.decodeDotInKeys||kd.allowDots:!!t.allowDots,allowEmptyArrays:"boolean"==typeof t.allowEmptyArrays?!!t.allowEmptyArrays:kd.allowEmptyArrays,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:kd.allowPrototypes,allowSparse:"boolean"==typeof t.allowSparse?t.allowSparse:kd.allowSparse,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:kd.arrayLimit,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:kd.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:kd.comma,decodeDotInKeys:"boolean"==typeof t.decodeDotInKeys?t.decodeDotInKeys:kd.decodeDotInKeys,decoder:"function"==typeof t.decoder?t.decoder:kd.decoder,delimiter:"string"==typeof t.delimiter||Nd.isRegExp(t.delimiter)?t.delimiter:kd.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:kd.depth,duplicates:i,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:kd.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:kd.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:kd.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:kd.strictNullHandling}}(e);if(""===t||null==t)return i.plainObjects?Object.create(null):{};for(var s="string"==typeof t?function(t,e){var i={__proto__:null},s=e.ignoreQueryPrefix?t.replace(/^\?/,""):t;s=s.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var r,n=e.parameterLimit===1/0?void 0:e.parameterLimit,o=s.split(e.delimiter,n),a=-1,l=e.charset;if(e.charsetSentinel)for(r=0;r<o.length;++r)0===o[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===o[r]?l="utf-8":"utf8=%26%2310003%3B"===o[r]&&(l="iso-8859-1"),a=r,r=o.length);for(r=0;r<o.length;++r)if(r!==a){var h,u,c=o[r],d=c.indexOf("]="),p=-1===d?c.indexOf("="):d+1;-1===p?(h=e.decoder(c,kd.decoder,l,"key"),u=e.strictNullHandling?null:""):(h=e.decoder(c.slice(0,p),kd.decoder,l,"key"),u=Nd.maybeMap(Fd(c.slice(p+1),e),(function(t){return e.decoder(t,kd.decoder,l,"value")}))),u&&e.interpretNumericEntities&&"iso-8859-1"===l&&(u=Bd(u)),c.indexOf("[]=")>-1&&(u=Rd(u)?[u]:u);var f=Ld.call(i,h);f&&"combine"===e.duplicates?i[h]=Nd.combine(i[h],u):f&&"last"!==e.duplicates||(i[h]=u)}return i}(t,i):t,r=i.plainObjects?Object.create(null):{},n=Object.keys(s),o=0;o<n.length;++o){var a=n[o],l=Dd(a,s[a],i,"string"==typeof t);r=Nd.merge(r,l,i)}return!0===i.allowSparse?r:Nd.compact(r)},stringify:function(t,e){var i,s=t,r=function(t){if(!t)return Cd;if(void 0!==t.allowEmptyArrays&&"boolean"!=typeof t.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==t.encodeDotInKeys&&"boolean"!=typeof t.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==t.encoder&&void 0!==t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||Cd.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var i=_d.default;if(void 0!==t.format){if(!wd.call(_d.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var s,r=_d.formatters[i],n=Cd.filter;if(("function"==typeof t.filter||Ed(t.filter))&&(n=t.filter),s=t.arrayFormat in Pd?t.arrayFormat:"indices"in t?t.indices?"indices":"repeat":Cd.arrayFormat,"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var o=void 0===t.allowDots?!0===t.encodeDotInKeys||Cd.allowDots:!!t.allowDots;return{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:Cd.addQueryPrefix,allowDots:o,allowEmptyArrays:"boolean"==typeof t.allowEmptyArrays?!!t.allowEmptyArrays:Cd.allowEmptyArrays,arrayFormat:s,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:Cd.charsetSentinel,commaRoundTrip:t.commaRoundTrip,delimiter:void 0===t.delimiter?Cd.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:Cd.encode,encodeDotInKeys:"boolean"==typeof t.encodeDotInKeys?t.encodeDotInKeys:Cd.encodeDotInKeys,encoder:"function"==typeof t.encoder?t.encoder:Cd.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:Cd.encodeValuesOnly,filter:n,format:i,formatter:r,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:Cd.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:Cd.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:Cd.strictNullHandling}}(e);"function"==typeof r.filter?s=(0,r.filter)("",s):Ed(r.filter)&&(i=r.filter);var n=[];if("object"!=typeof s||null===s)return"";var o=Pd[r.arrayFormat],a="comma"===o&&r.commaRoundTrip;i||(i=Object.keys(s)),r.sort&&i.sort(r.sort);for(var l=xd(),h=0;h<i.length;++h){var u=i[h];r.skipNulls&&null===s[u]||Ad(n,Od(s[u],u,o,a,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset,l))}var c=n.join(r.delimiter),d=!0===r.addQueryPrefix?"?":"";return r.charsetSentinel&&("iso-8859-1"===r.charset?d+="utf8=%26%2310003%3B&":d+="utf8=%E2%9C%93&"),c.length>0?d+c:""}},Gd=Oh;function Xd(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var Wd=/^([a-z0-9.+-]+:)/i,Hd=/:[0-9]*$/,Yd=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,$d=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),jd=["'"].concat($d),zd=["%","/","?",";","#"].concat(jd),Vd=["/","?","#"],qd=/^[+a-z0-9A-Z_-]{0,63}$/,Jd=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,Kd={javascript:!0,"javascript:":!0},Zd={javascript:!0,"javascript:":!0},Qd={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},tp=Ud;function ep(t,e,i){if(t&&"object"==typeof t&&t instanceof Xd)return t;var s=new Xd;return s.parse(t,e,i),s}Xd.prototype.parse=function(t,e,i){if("string"!=typeof t)throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var s=t.indexOf("?"),r=-1!==s&&s<t.indexOf("#")?"?":"#",n=t.split(r);n[0]=n[0].replace(/\\/g,"/");var o=t=n.join(r);if(o=o.trim(),!i&&1===t.split("#").length){var a=Yd.exec(o);if(a)return this.path=o,this.href=o,this.pathname=a[1],a[2]?(this.search=a[2],this.query=e?tp.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var l=Wd.exec(o);if(l){var h=(l=l[0]).toLowerCase();this.protocol=h,o=o.substr(l.length)}if(i||l||o.match(/^\/\/[^@/]+@[^@/]+/)){var u="//"===o.substr(0,2);!u||l&&Zd[l]||(o=o.substr(2),this.slashes=!0)}if(!Zd[l]&&(u||l&&!Qd[l])){for(var c,d,p=-1,f=0;f<Vd.length;f++){-1!==(m=o.indexOf(Vd[f]))&&(-1===p||m<p)&&(p=m)}-1!==(d=-1===p?o.lastIndexOf("@"):o.lastIndexOf("@",p))&&(c=o.slice(0,d),o=o.slice(d+1),this.auth=decodeURIComponent(c)),p=-1;for(f=0;f<zd.length;f++){var m;-1!==(m=o.indexOf(zd[f]))&&(-1===p||m<p)&&(p=m)}-1===p&&(p=o.length),this.host=o.slice(0,p),o=o.slice(p),this.parseHost(),this.hostname=this.hostname||"";var g="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!g)for(var y=this.hostname.split(/\./),v=(f=0,y.length);f<v;f++){var x=y[f];if(x&&!x.match(qd)){for(var b="",_=0,w=x.length;_<w;_++)x.charCodeAt(_)>127?b+="x":b+=x[_];if(!b.match(qd)){var P=y.slice(0,f),E=y.slice(f+1),T=x.match(Jd);T&&(P.push(T[1]),E.unshift(T[2])),E.length&&(o="/"+E.join(".")+o),this.hostname=P.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),g||(this.hostname=Gd.toASCII(this.hostname));var A=this.port?":"+this.port:"",I=this.hostname||"";this.host=I+A,this.href+=this.host,g&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==o[0]&&(o="/"+o))}if(!Kd[h])for(f=0,v=jd.length;f<v;f++){var S=jd[f];if(-1!==o.indexOf(S)){var C=encodeURIComponent(S);C===S&&(C=escape(S)),o=o.split(S).join(C)}}var M=o.indexOf("#");-1!==M&&(this.hash=o.substr(M),o=o.slice(0,M));var O=o.indexOf("?");if(-1!==O?(this.search=o.substr(O),this.query=o.substr(O+1),e&&(this.query=tp.parse(this.query)),o=o.slice(0,O)):e&&(this.search="",this.query={}),o&&(this.pathname=o),Qd[h]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){A=this.pathname||"";var N=this.search||"";this.path=A+N}return this.href=this.format(),this},Xd.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",i=this.pathname||"",s=this.hash||"",r=!1,n="";this.host?r=t+this.host:this.hostname&&(r=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(r+=":"+this.port)),this.query&&"object"==typeof this.query&&Object.keys(this.query).length&&(n=tp.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var o=this.search||n&&"?"+n||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||Qd[e])&&!1!==r?(r="//"+(r||""),i&&"/"!==i.charAt(0)&&(i="/"+i)):r||(r=""),s&&"#"!==s.charAt(0)&&(s="#"+s),o&&"?"!==o.charAt(0)&&(o="?"+o),e+r+(i=i.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(o=o.replace("#","%23"))+s},Xd.prototype.resolve=function(t){return this.resolveObject(ep(t,!1,!0)).format()},Xd.prototype.resolveObject=function(t){if("string"==typeof t){var e=new Xd;e.parse(t,!1,!0),t=e}for(var i=new Xd,s=Object.keys(this),r=0;r<s.length;r++){var n=s[r];i[n]=this[n]}if(i.hash=t.hash,""===t.href)return i.href=i.format(),i;if(t.slashes&&!t.protocol){for(var o=Object.keys(t),a=0;a<o.length;a++){var l=o[a];"protocol"!==l&&(i[l]=t[l])}return Qd[i.protocol]&&i.hostname&&!i.pathname&&(i.pathname="/",i.path=i.pathname),i.href=i.format(),i}if(t.protocol&&t.protocol!==i.protocol){if(!Qd[t.protocol]){for(var h=Object.keys(t),u=0;u<h.length;u++){var c=h[u];i[c]=t[c]}return i.href=i.format(),i}if(i.protocol=t.protocol,t.host||Zd[t.protocol])i.pathname=t.pathname;else{for(var d=(t.pathname||"").split("/");d.length&&!(t.host=d.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),i.pathname=d.join("/")}if(i.search=t.search,i.query=t.query,i.host=t.host||"",i.auth=t.auth,i.hostname=t.hostname||t.host,i.port=t.port,i.pathname||i.search){var p=i.pathname||"",f=i.search||"";i.path=p+f}return i.slashes=i.slashes||t.slashes,i.href=i.format(),i}var m=i.pathname&&"/"===i.pathname.charAt(0),g=t.host||t.pathname&&"/"===t.pathname.charAt(0),y=g||m||i.host&&t.pathname,v=y,x=i.pathname&&i.pathname.split("/")||[],b=(d=t.pathname&&t.pathname.split("/")||[],i.protocol&&!Qd[i.protocol]);if(b&&(i.hostname="",i.port=null,i.host&&(""===x[0]?x[0]=i.host:x.unshift(i.host)),i.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===d[0]?d[0]=t.host:d.unshift(t.host)),t.host=null),y=y&&(""===d[0]||""===x[0])),g)i.host=t.host||""===t.host?t.host:i.host,i.hostname=t.hostname||""===t.hostname?t.hostname:i.hostname,i.search=t.search,i.query=t.query,x=d;else if(d.length)x||(x=[]),x.pop(),x=x.concat(d),i.search=t.search,i.query=t.query;else if(null!=t.search){if(b)i.host=x.shift(),i.hostname=i.host,(T=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=T.shift(),i.hostname=T.shift(),i.host=i.hostname);return i.search=t.search,i.query=t.query,null===i.pathname&&null===i.search||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i}if(!x.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var _=x.slice(-1)[0],w=(i.host||t.host||x.length>1)&&("."===_||".."===_)||""===_,P=0,E=x.length;E>=0;E--)"."===(_=x[E])?x.splice(E,1):".."===_?(x.splice(E,1),P++):P&&(x.splice(E,1),P--);if(!y&&!v)for(;P--;P)x.unshift("..");!y||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),w&&"/"!==x.join("/").substr(-1)&&x.push("");var T,A=""===x[0]||x[0]&&"/"===x[0].charAt(0);b&&(i.hostname=A?"":x.length?x.shift():"",i.host=i.hostname,(T=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=T.shift(),i.hostname=T.shift(),i.host=i.hostname));return(y=y||i.host&&x.length)&&!A&&x.unshift(""),x.length>0?i.pathname=x.join("/"):(i.pathname=null,i.path=null),null===i.pathname&&null===i.search||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.auth=t.auth||i.auth,i.slashes=i.slashes||t.slashes,i.href=i.format(),i},Xd.prototype.parseHost=function(){var t=this.host,e=Hd.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)};var ip=ep,sp=function(t,e){return ep(t,!1,!0).resolve(e)},rp=function(t){return"string"==typeof t&&(t=ep(t)),t instanceof Xd?t.format():Xd.prototype.format.call(t)};const np={};function op(t,e,i=3){if(np[e])return;let s=(new Error).stack;typeof s>"u"?console.warn("PixiJS Deprecation Warning: ",`${e}\nDeprecated since v${t}`):(s=s.split("\n").splice(i).join("\n"),console.groupCollapsed?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",`${e}\nDeprecated since v${t}`),console.warn(s),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",`${e}\nDeprecated since v${t}`),console.warn(s))),np[e]=!0}const ap={get parse(){return op("7.3.0","utils.url.parse is deprecated, use native URL API instead."),ip},get format(){return op("7.3.0","utils.url.format is deprecated, use native URL API instead."),rp},get resolve(){return op("7.3.0","utils.url.resolve is deprecated, use native URL API instead."),sp}};function lp(t){if("string"!=typeof t)throw new TypeError(`Path must be a string. Received ${JSON.stringify(t)}`)}function hp(t){return t.split("?")[0].split("#")[0]}const up={toPosix(t){return e="\\",i="/",t.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),i);var e,i},isUrl(t){return/^https?:/.test(this.toPosix(t))},isDataUrl:t=>/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(t),isBlobUrl:t=>t.startsWith("blob:"),hasProtocol(t){return/^[^/:]+:/.test(this.toPosix(t))},getProtocol(t){lp(t),t=this.toPosix(t);const e=/^file:\/\/\//.exec(t);if(e)return e[0];const i=/^[^/:]+:\/{0,2}/.exec(t);return i?i[0]:""},toAbsolute(t,e,i){if(lp(t),this.isDataUrl(t)||this.isBlobUrl(t))return t;const s=hp(this.toPosix(e??lh.ADAPTER.getBaseUrl())),r=hp(this.toPosix(i??this.rootname(s)));return(t=this.toPosix(t)).startsWith("/")?up.join(r,t.slice(1)):this.isAbsolute(t)?t:this.join(s,t)},normalize(t){if(lp(t),0===t.length)return".";if(this.isDataUrl(t)||this.isBlobUrl(t))return t;let e="";const i=(t=this.toPosix(t)).startsWith("/");this.hasProtocol(t)&&(e=this.rootname(t),t=t.slice(e.length));const s=t.endsWith("/");return(t=function(t){let e="",i=0,s=-1,r=0,n=-1;for(let o=0;o<=t.length;++o){if(o<t.length)n=t.charCodeAt(o);else{if(47===n)break;n=47}if(47===n){if(s!==o-1&&1!==r)if(s!==o-1&&2===r){if(e.length<2||2!==i||46!==e.charCodeAt(e.length-1)||46!==e.charCodeAt(e.length-2))if(e.length>2){const t=e.lastIndexOf("/");if(t!==e.length-1){-1===t?(e="",i=0):(e=e.slice(0,t),i=e.length-1-e.lastIndexOf("/")),s=o,r=0;continue}}else if(2===e.length||1===e.length){e="",i=0,s=o,r=0;continue}}else e.length>0?e+=`/${t.slice(s+1,o)}`:e=t.slice(s+1,o),i=o-s-1;s=o,r=0}else 46===n&&-1!==r?++r:r=-1}return e}(t)).length>0&&s&&(t+="/"),i?`/${t}`:e+t},isAbsolute(t){return lp(t),t=this.toPosix(t),!!this.hasProtocol(t)||t.startsWith("/")},join(...t){if(0===t.length)return".";let e;for(let i=0;i<t.length;++i){const s=t[i];if(lp(s),s.length>0)if(void 0===e)e=s;else{const r=t[i-1]??"";this.joinExtensions.includes(this.extname(r).toLowerCase())?e+=`/../${s}`:e+=`/${s}`}}return void 0===e?".":this.normalize(e)},dirname(t){if(lp(t),0===t.length)return".";let e=(t=this.toPosix(t)).charCodeAt(0);const i=47===e;let s=-1,r=!0;const n=this.getProtocol(t),o=t;for(let a=(t=t.slice(n.length)).length-1;a>=1;--a)if(e=t.charCodeAt(a),47===e){if(!r){s=a;break}}else r=!1;return-1===s?i?"/":this.isUrl(o)?n+t:n:i&&1===s?"//":n+t.slice(0,s)},rootname(t){lp(t);let e="";if(e=(t=this.toPosix(t)).startsWith("/")?"/":this.getProtocol(t),this.isUrl(t)){const i=t.indexOf("/",e.length);e=-1!==i?t.slice(0,i):t,e.endsWith("/")||(e+="/")}return e},basename(t,e){lp(t),e&&lp(e),t=hp(this.toPosix(t));let i,s=0,r=-1,n=!0;if(void 0!==e&&e.length>0&&e.length<=t.length){if(e.length===t.length&&e===t)return"";let o=e.length-1,a=-1;for(i=t.length-1;i>=0;--i){const l=t.charCodeAt(i);if(47===l){if(!n){s=i+1;break}}else-1===a&&(n=!1,a=i+1),o>=0&&(l===e.charCodeAt(o)?-1==--o&&(r=i):(o=-1,r=a))}return s===r?r=a:-1===r&&(r=t.length),t.slice(s,r)}for(i=t.length-1;i>=0;--i)if(47===t.charCodeAt(i)){if(!n){s=i+1;break}}else-1===r&&(n=!1,r=i+1);return-1===r?"":t.slice(s,r)},extname(t){lp(t);let e=-1,i=0,s=-1,r=!0,n=0;for(let o=(t=hp(this.toPosix(t))).length-1;o>=0;--o){const a=t.charCodeAt(o);if(47!==a)-1===s&&(r=!1,s=o+1),46===a?-1===e?e=o:1!==n&&(n=1):-1!==e&&(n=-1);else if(!r){i=o+1;break}}return-1===e||-1===s||0===n||1===n&&e===s-1&&e===i+1?"":t.slice(e,s)},parse(t){lp(t);const e={root:"",dir:"",base:"",ext:"",name:""};if(0===t.length)return e;let i=(t=hp(this.toPosix(t))).charCodeAt(0);const s=this.isAbsolute(t);let r;e.root=this.rootname(t),r=s||this.hasProtocol(t)?1:0;let n=-1,o=0,a=-1,l=!0,h=t.length-1,u=0;for(;h>=r;--h)if(i=t.charCodeAt(h),47!==i)-1===a&&(l=!1,a=h+1),46===i?-1===n?n=h:1!==u&&(u=1):-1!==n&&(u=-1);else if(!l){o=h+1;break}return-1===n||-1===a||0===u||1===u&&n===a-1&&n===o+1?-1!==a&&(e.base=e.name=0===o&&s?t.slice(1,a):t.slice(o,a)):(0===o&&s?(e.name=t.slice(1,n),e.base=t.slice(1,a)):(e.name=t.slice(o,n),e.base=t.slice(o,a)),e.ext=t.slice(n,a)),e.dir=this.dirname(t),e},sep:"/",delimiter:":",joinExtensions:[".html"]};let cp,dp;function pp(){return typeof dp>"u"&&(dp=function(){var t;const e={stencil:!0,failIfMajorPerformanceCaveat:lh.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!lh.ADAPTER.getWebGLRenderingContext())return!1;const i=lh.ADAPTER.createCanvas();let s=i.getContext("webgl",e)||i.getContext("experimental-webgl",e);const r=!!(null==(t=null==s?void 0:s.getContextAttributes())?void 0:t.stencil);if(s){const t=s.getExtension("WEBGL_lose_context");t&&t.loseContext()}return s=null,r}catch{return!1}}()),dp}var fp,mp={grad:.9,turn:360,rad:360/(2*Math.PI)},gp=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},yp=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},vp=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},xp=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},bp=function(t){return{r:vp(t.r,0,255),g:vp(t.g,0,255),b:vp(t.b,0,255),a:vp(t.a)}},_p=function(t){return{r:yp(t.r),g:yp(t.g),b:yp(t.b),a:yp(t.a,3)}},wp=/^#([0-9a-f]{3,8})$/i,Pp=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Ep=function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=Math.max(e,i,s),o=n-Math.min(e,i,s),a=o?n===e?(i-s)/o:n===i?2+(s-e)/o:4+(e-i)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},Tp=function(t){var e=t.h,i=t.s,s=t.v,r=t.a;e=e/360*6,i/=100,s/=100;var n=Math.floor(e),o=s*(1-i),a=s*(1-(e-n)*i),l=s*(1-(1-e+n)*i),h=n%6;return{r:255*[s,a,o,o,l,s][h],g:255*[l,s,s,a,o,o][h],b:255*[o,o,l,s,s,a][h],a:r}},Ap=function(t){return{h:xp(t.h),s:vp(t.s,0,100),l:vp(t.l,0,100),a:vp(t.a)}},Ip=function(t){return{h:yp(t.h),s:yp(t.s),l:yp(t.l),a:yp(t.a,3)}},Sp=function(t){return Tp((i=(e=t).s,{h:e.h,s:(i*=((s=e.l)<50?s:100-s)/100)>0?2*i/(s+i)*100:0,v:s+i,a:e.a}));var e,i,s},Cp=function(t){return{h:(e=Ep(t)).h,s:(r=(200-(i=e.s))*(s=e.v)/100)>0&&r<200?i*s/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,i,s,r},Mp=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Op=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Np=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lp=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Rp={string:[[function(t){var e=wp.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?yp(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?yp(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Np.exec(t)||Lp.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:bp({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Mp.exec(t)||Op.exec(t);if(!e)return null;var i,s,r=Ap({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(mp[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return Sp(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=void 0===r?1:r;return gp(e)&&gp(i)&&gp(s)?bp({r:Number(e),g:Number(i),b:Number(s),a:Number(n)}):null},"rgb"],[function(t){var e=t.h,i=t.s,s=t.l,r=t.a,n=void 0===r?1:r;if(!gp(e)||!gp(i)||!gp(s))return null;var o=Ap({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return Sp(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!gp(e)||!gp(i)||!gp(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:xp(o.h),s:vp(o.s,0,100),v:vp(o.v,0,100),a:vp(o.a)});return Tp(a)},"hsv"]]},kp=function(t,e){for(var i=0;i<e.length;i++){var s=e[i][0](t);if(s)return[s,e[i][1]]}return[null,void 0]},Bp=function(t,e){var i=Cp(t);return{h:i.h,s:vp(i.s+100*e,0,100),l:i.l,a:i.a}},Fp=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Dp=function(t,e){var i=Cp(t);return{h:i.h,s:i.s,l:vp(i.l+100*e,0,100),a:i.a}},Up=function(){function t(t){this.parsed=function(t){return"string"==typeof t?kp(t.trim(),Rp.string):"object"==typeof t&&null!==t?kp(t,Rp.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return yp(Fp(this.rgba),2)},t.prototype.isDark=function(){return Fp(this.rgba)<.5},t.prototype.isLight=function(){return Fp(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=_p(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?Pp(yp(255*r)):"","#"+Pp(e)+Pp(i)+Pp(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return _p(this.rgba)},t.prototype.toRgbString=function(){return e=(t=_p(this.rgba)).r,i=t.g,s=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+s+", "+r+")":"rgb("+e+", "+i+", "+s+")";var t,e,i,s,r},t.prototype.toHsl=function(){return Ip(Cp(this.rgba))},t.prototype.toHslString=function(){return e=(t=Ip(Cp(this.rgba))).h,i=t.s,s=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+s+"%, "+r+")":"hsl("+e+", "+i+"%, "+s+"%)";var t,e,i,s,r},t.prototype.toHsv=function(){return t=Ep(this.rgba),{h:yp(t.h),s:yp(t.s),v:yp(t.v),a:yp(t.a,3)};var t},t.prototype.invert=function(){return Gp({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),Gp(Bp(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),Gp(Bp(this.rgba,-t))},t.prototype.grayscale=function(){return Gp(Bp(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),Gp(Dp(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),Gp(Dp(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?Gp({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):yp(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Cp(this.rgba);return"number"==typeof t?Gp({h:t,s:e.s,l:e.l,a:e.a}):yp(e.h)},t.prototype.isEqual=function(t){return this.toHex()===Gp(t).toHex()},t}(),Gp=function(t){return t instanceof Up?t:new Up(t)},Xp=[];fp=[function(t,e){var i={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},s={};for(var r in i)s[i[r]]=r;var n={};t.prototype.toName=function(e){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var r,o,a=s[this.toHex()];if(a)return a;if(null==e?void 0:e.closest){var l=this.toRgb(),h=1/0,u="black";if(!n.length)for(var c in i)n[c]=new t(i[c]).toRgb();for(var d in i){var p=(r=l,o=n[d],Math.pow(r.r-o.r,2)+Math.pow(r.g-o.g,2)+Math.pow(r.b-o.b,2));p<h&&(h=p,u=d)}return u}},e.string.push([function(e){var s=e.toLowerCase(),r="transparent"===s?"#0000":i[s];return r?new t(r).toRgb():null},"name"])}],fp.forEach((function(t){Xp.indexOf(t)<0&&(t(Up,Rp),Xp.push(t))}));const Wp=class t{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(e){if(e instanceof t)this._value=this.cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(null===e)throw new Error("Cannot set PIXI.Color#value to null");(null===this._value||!this.isSourceEqual(this._value,e))&&(this.normalize(e),this._value=this.cloneSource(e))}}get value(){return this._value}cloneSource(t){return"string"==typeof t||"number"==typeof t||t instanceof Number||null===t?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):"object"==typeof t&&null!==t?{...t}:t}isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if("number"===i||"string"===i||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length===e.length&&t.every(((t,i)=>t===e[i]));if(null!==t&&null!==e){const i=Object.keys(t),s=Object.keys(e);return i.length===s.length&&i.every((i=>t[i]===e[i]))}return t===e}toRgba(){const[t,e,i,s]=this._components;return{r:t,g:e,b:i,a:s}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,s]=this._components;return(t=t??[])[0]=Math.round(255*e),t[1]=Math.round(255*i),t[2]=Math.round(255*s),t}toRgbArray(t){t=t??[];const[e,i,s]=this._components;return t[0]=e,t[1]=i,t[2]=s,t}toNumber(){return this._int}toLittleEndianNumber(){const t=this._int;return(t>>16)+(65280&t)+((255&t)<<16)}multiply(e){const[i,s,r,n]=t.temp.setValue(e)._components;return this._components[0]*=i,this._components[1]*=s,this._components[2]*=r,this._components[3]*=n,this.refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this.refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(1===t)return(255<<24)+this._int;if(0===t)return e?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,r=255&this._int;return e&&(i=i*t+.5|0,s=s*t+.5|0,r=r*t+.5|0),(255*t<<24)+(i<<16)+(s<<8)+r}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const t=Math.round(255*this._components[3]).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(t){return this._components[3]=this._clamp(t),this}round(t){const[e,i,s]=this._components;return this._components[0]=Math.round(e*t)/t,this._components[1]=Math.round(i*t)/t,this._components[2]=Math.round(s*t)/t,this.refreshInt(),this._value=null,this}toArray(t){t=t??[];const[e,i,s,r]=this._components;return t[0]=e,t[1]=i,t[2]=s,t[3]=r,t}normalize(e){let i,s,r,n;if(("number"==typeof e||e instanceof Number)&&e>=0&&e<=16777215){i=(e>>16&255)/255,s=(e>>8&255)/255,r=(255&e)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[i,s,r,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[i,s,r,n=255]=e,i/=255,s/=255,r/=255,n/=255;else if("string"==typeof e||"object"==typeof e){if("string"==typeof e){const i=t.HEX_PATTERN.exec(e);i&&(e=`#${i[2]}`)}const o=Gp(e);o.isValid()&&(({r:i,g:s,b:r,a:n}=o.rgba),i/=255,s/=255,r/=255)}if(void 0===i)throw new Error(`Unable to convert color ${e}`);this._components[0]=i,this._components[1]=s,this._components[2]=r,this._components[3]=n,this.refreshInt()}refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(255*t<<16)+(255*e<<8)+(255*i|0)}_clamp(t,e=0,i=1){return"number"==typeof t?Math.min(Math.max(t,e),i):(t.forEach(((s,r)=>{t[r]=Math.min(Math.max(s,e),i)})),t)}};Wp.shared=new Wp,Wp.temp=new Wp,Wp.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let Hp=Wp;const Yp=function(){const t=[],e=[];for(let s=0;s<32;s++)t[s]=s,e[s]=s;t[jl.NORMAL_NPM]=jl.NORMAL,t[jl.ADD_NPM]=jl.ADD,t[jl.SCREEN_NPM]=jl.SCREEN,e[jl.NORMAL]=jl.NORMAL_NPM,e[jl.ADD]=jl.ADD_NPM,e[jl.SCREEN]=jl.SCREEN_NPM;const i=[];return i.push(e),i.push(t),i}();const $p=/^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;charset=([\w-]+))?(?:;(base64))?,(.*)/i;function jp(t){if(4===t.BYTES_PER_ELEMENT)return t instanceof Float32Array?"Float32Array":t instanceof Uint32Array?"Uint32Array":"Int32Array";if(2===t.BYTES_PER_ELEMENT){if(t instanceof Uint16Array)return"Uint16Array"}else if(1===t.BYTES_PER_ELEMENT&&t instanceof Uint8Array)return"Uint8Array";return null}const zp={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array};function Vp(t){return t+=0===t?1:0,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)+1}function qp(t){return!(t&t-1||!t)}function Jp(t){let e=(t>65535?1:0)<<4,i=((t>>>=e)>255?1:0)<<3;return e|=i,i=((t>>>=i)>15?1:0)<<2,e|=i,i=((t>>>=i)>3?1:0)<<1,e|=i,e|(t>>>=i)>>1}function Kp(t,e,i){const s=t.length;let r;if(e>=s||0===i)return;const n=s-(i=e+i>s?s-e:i);for(r=e;r<n;++r)t[r]=t[r+i];t.length=n}function Zp(t){return 0===t?0:t<0?-1:1}let Qp=0;function tf(){return++Qp}const ef=class{constructor(t,e,i,s){this.left=t,this.top=e,this.right=i,this.bottom=s}get width(){return this.right-this.left}get height(){return this.bottom-this.top}isEmpty(){return this.left===this.right||this.top===this.bottom}};ef.EMPTY=new ef(0,0,0,0);let sf=ef;const rf={},nf=Object.create(null),of=Object.create(null);function af(){let t;for(t in nf)delete nf[t];for(t in of)delete of[t]}class lf{constructor(t,e,i){this._canvas=lh.ADAPTER.createCanvas(),this._context=this._canvas.getContext("2d"),this.resolution=i||lh.RESOLUTION,this.resize(t,e)}clear(){this._checkDestroyed(),this._context.setTransform(1,0,0,1,0,0),this._context.clearRect(0,0,this._canvas.width,this._canvas.height)}resize(t,e){this._checkDestroyed(),this._canvas.width=Math.round(t*this.resolution),this._canvas.height=Math.round(e*this.resolution)}destroy(){this._context=null,this._canvas=null}get width(){return this._checkDestroyed(),this._canvas.width}set width(t){this._checkDestroyed(),this._canvas.width=Math.round(t)}get height(){return this._checkDestroyed(),this._canvas.height}set height(t){this._checkDestroyed(),this._canvas.height=Math.round(t)}get canvas(){return this._checkDestroyed(),this._canvas}get context(){return this._checkDestroyed(),this._context}_checkDestroyed(){if(null===this._canvas)throw new TypeError("The CanvasRenderTarget has already been destroyed")}}function hf(t,e,i){for(let s=0,r=4*i*e;s<e;++s,r+=4)if(0!==t[r+3])return!1;return!0}function uf(t,e,i,s,r){const n=4*e;for(let o=s,a=s*n+4*i;o<=r;++o,a+=n)if(0!==t[a+3])return!1;return!0}function cf(t){const{width:e,height:i}=t,s=t.getContext("2d",{willReadFrequently:!0});if(null===s)throw new TypeError("Failed to get canvas 2D context");const r=s.getImageData(0,0,e,i).data;let n=0,o=0,a=e-1,l=i-1;for(;o<i&&hf(r,e,o);)++o;if(o===i)return sf.EMPTY;for(;hf(r,e,l);)--l;for(;uf(r,e,n,o,l);)++n;for(;uf(r,e,a,o,l);)--a;return++a,++l,new sf(n,o,a,l)}function df(t){const e=cf(t),{width:i,height:s}=e;let r=null;if(!e.isEmpty()){const n=t.getContext("2d");if(null===n)throw new TypeError("Failed to get canvas 2D context");r=n.getImageData(e.left,e.top,i,s)}return{width:i,height:s,data:r}}function pf(t,e=globalThis.location){if(t.startsWith("data:"))return"";e=e||globalThis.location;const i=new URL(t,document.baseURI);return i.hostname!==e.hostname||i.port!==e.port||i.protocol!==e.protocol?"anonymous":""}function ff(t,e=1){var i;const s=null==(i=lh.RETINA_PREFIX)?void 0:i.exec(t);return s?parseFloat(s[1]):e}const mf=Object.freeze(Object.defineProperty({__proto__:null,BaseTextureCache:of,BoundingBox:sf,CanvasRenderTarget:lf,DATA_URI:$p,EventEmitter:Sh,ProgramCache:rf,TextureCache:nf,clearTextureCache:af,correctBlendMode:function(t,e){return Yp[e?1:0][t]},createIndicesForQuads:function(t,e=null){const i=6*t;if((e=e||new Uint16Array(i)).length!==i)throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${i}`);for(let s=0,r=0;s<i;s+=6,r+=4)e[s+0]=r+0,e[s+1]=r+1,e[s+2]=r+2,e[s+3]=r+0,e[s+4]=r+2,e[s+5]=r+3;return e},decomposeDataUri:function(t){const e=$p.exec(t);if(e)return{mediaType:e[1]?e[1].toLowerCase():void 0,subType:e[2]?e[2].toLowerCase():void 0,charset:e[3]?e[3].toLowerCase():void 0,encoding:e[4]?e[4].toLowerCase():void 0,data:e[5]}},deprecation:op,destroyTextureCache:function(){let t;for(t in nf)nf[t].destroy();for(t in of)of[t].destroy()},detectVideoAlphaMode:async function(){return cp??(cp=(async()=>{var t;const e=document.createElement("canvas").getContext("webgl");if(!e)return eh.UNPACK;const i=await new Promise((t=>{const e=document.createElement("video");e.onloadeddata=()=>t(e),e.onerror=()=>t(null),e.autoplay=!1,e.crossOrigin="anonymous",e.preload="auto",e.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",e.load()}));if(!i)return eh.UNPACK;const s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s);const r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i);const n=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,n),e.deleteFramebuffer(r),e.deleteTexture(s),null==(t=e.getExtension("WEBGL_lose_context"))||t.loseContext(),n[0]<=n[3]?eh.PMA:eh.UNPACK})()),cp},determineCrossOrigin:pf,earcut:ne,getBufferType:jp,getCanvasBoundingBox:cf,getResolutionOfUrl:ff,hex2rgb:function(t,e=[]){return op("7.2.0","utils.hex2rgb is deprecated, use Color#toRgbArray instead"),Hp.shared.setValue(t).toRgbArray(e)},hex2string:function(t){return op("7.2.0","utils.hex2string is deprecated, use Color#toHex instead"),Hp.shared.setValue(t).toHex()},interleaveTypedArrays:function(t,e){let i=0,s=0;const r={};for(let l=0;l<t.length;l++)s+=e[l],i+=t[l].length;const n=new ArrayBuffer(4*i);let o=null,a=0;for(let l=0;l<t.length;l++){const i=e[l],h=t[l],u=jp(h);r[u]||(r[u]=new zp[u](n)),o=r[u];for(let t=0;t<h.length;t++){o[(t/i|0)*s+a+t%i]=h[t]}a+=i}return new Float32Array(n)},isMobile:Ah,isPow2:qp,isWebGLSupported:pp,log2:Jp,nextPow2:Vp,path:up,premultiplyBlendMode:Yp,premultiplyRgba:function(t,e,i,s=!0){return op("7.2.0","utils.premultiplyRgba has moved to Color.premultiply"),Hp.shared.setValue(t).premultiply(e,s).toArray(i??new Float32Array(4))},premultiplyTint:function(t,e){return op("7.2.0","utils.premultiplyTint has moved to Color.toPremultiplied"),Hp.shared.setValue(t).toPremultiplied(e)},premultiplyTintToRgba:function(t,e,i,s=!0){return op("7.2.0","utils.premultiplyTintToRgba has moved to Color.premultiply"),Hp.shared.setValue(t).premultiply(e,s).toArray(i??new Float32Array(4))},removeItems:Kp,rgb2hex:function(t){return op("7.2.0","utils.rgb2hex is deprecated, use Color#toNumber instead"),Hp.shared.setValue(t).toNumber()},sayHello:function(){op("7.0.0",'sayHello is deprecated, please use Renderer\'s "hello" option')},sign:Zp,skipHello:function(){op("7.0.0","skipHello is deprecated, please use settings.RENDER_OPTIONS.hello")},string2hex:function(t){return op("7.2.0","utils.string2hex is deprecated, use Color#toNumber instead"),Hp.shared.setValue(t).toNumber()},trimCanvas:df,uid:tf,url:ap},Symbol.toStringTag,{value:"Module"}));var gf=(t=>(t.Renderer="renderer",t.Application="application",t.RendererSystem="renderer-webgl-system",t.RendererPlugin="renderer-webgl-plugin",t.CanvasRendererSystem="renderer-canvas-system",t.CanvasRendererPlugin="renderer-canvas-plugin",t.Asset="asset",t.LoadParser="load-parser",t.ResolveParser="resolve-parser",t.CacheParser="cache-parser",t.DetectionParser="detection-parser",t))(gf||{});const yf=t=>{if("function"==typeof t||"object"==typeof t&&t.extension){if(!t.extension)throw new Error("Extension class must have an extension object");t={..."object"!=typeof t.extension?{type:t.extension}:t.extension,ref:t}}if("object"!=typeof t)throw new Error("Invalid extension type");return"string"==typeof(t={...t}).type&&(t.type=[t.type]),t},vf=(t,e)=>yf(t).priority??e,xf={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...t){return t.map(yf).forEach((t=>{t.type.forEach((e=>{var i,s;return null==(s=(i=this._removeHandlers)[e])?void 0:s.call(i,t)}))})),this},add(...t){return t.map(yf).forEach((t=>{t.type.forEach((e=>{var i,s;const r=this._addHandlers,n=this._queue;r[e]?null==(i=r[e])||i.call(r,t):(n[e]=n[e]||[],null==(s=n[e])||s.push(t))}))})),this},handle(t,e,i){var s;const r=this._addHandlers,n=this._removeHandlers;if(r[t]||n[t])throw new Error(`Extension type ${t} already has a handler`);r[t]=e,n[t]=i;const o=this._queue;return o[t]&&(null==(s=o[t])||s.forEach((t=>e(t))),delete o[t]),this},handleByMap(t,e){return this.handle(t,(t=>{t.name&&(e[t.name]=t.ref)}),(t=>{t.name&&delete e[t.name]}))},handleByList(t,e,i=-1){return this.handle(t,(t=>{e.includes(t.ref)||(e.push(t.ref),e.sort(((t,e)=>vf(e,i)-vf(t,i))))}),(t=>{const i=e.indexOf(t.ref);-1!==i&&e.splice(i,1)}))}};class bf{constructor(t){"number"==typeof t?this.rawBinaryData=new ArrayBuffer(t):t instanceof Uint8Array?this.rawBinaryData=t.buffer:this.rawBinaryData=t,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData)}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get uint16View(){return this._uint16View||(this._uint16View=new Uint16Array(this.rawBinaryData)),this._uint16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}view(t){return this[`${t}View`]}destroy(){this.rawBinaryData=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._uint16View=null,this._int32View=null,this.uint32View=null,this.float32View=null}static sizeOf(t){switch(t){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${t} isn't a valid view type`)}}}const _f=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join("\n");function wf(t){let e="";for(let i=0;i<t;++i)i>0&&(e+="\nelse "),i<t-1&&(e+=`if(test == ${i}.0){}`);return e}class Pf{constructor(){this.data=0,this.blendMode=jl.NORMAL,this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(1&this.data)}set blend(t){!!(1&this.data)!==t&&(this.data^=1)}get offsets(){return!!(2&this.data)}set offsets(t){!!(2&this.data)!==t&&(this.data^=2)}get culling(){return!!(4&this.data)}set culling(t){!!(4&this.data)!==t&&(this.data^=4)}get depthTest(){return!!(8&this.data)}set depthTest(t){!!(8&this.data)!==t&&(this.data^=8)}get depthMask(){return!!(32&this.data)}set depthMask(t){!!(32&this.data)!==t&&(this.data^=32)}get clockwiseFrontFace(){return!!(16&this.data)}set clockwiseFrontFace(t){!!(16&this.data)!==t&&(this.data^=16)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!==jl.NONE,this._blendMode=t}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}static for2d(){const t=new Pf;return t.depthTest=!1,t.blend=!0,t}}Pf.prototype.toString=function(){return`[@pixi/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`};const Ef=[];function Tf(t,e){if(!t)return null;let i="";if("string"==typeof t){const e=/\.(\w{3,4})(?:$|\?|#)/i.exec(t);e&&(i=e[1].toLowerCase())}for(let s=Ef.length-1;s>=0;--s){const r=Ef[s];if(r.test&&r.test(t,i))return new r(t,e)}throw new Error("Unrecognized source type to auto-detect Resource")}class Af{constructor(t){this.items=[],this._name=t,this._aliasCount=0}emit(t,e,i,s,r,n,o,a){if(arguments.length>8)throw new Error("max arguments reached");const{name:l,items:h}=this;this._aliasCount++;for(let u=0,c=h.length;u<c;u++)h[u][l](t,e,i,s,r,n,o,a);return h===this.items&&this._aliasCount--,this}ensureNonAliasedItems(){this._aliasCount>0&&this.items.length>1&&(this._aliasCount=0,this.items=this.items.slice(0))}add(t){return t[this._name]&&(this.ensureNonAliasedItems(),this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return-1!==e&&(this.ensureNonAliasedItems(),this.items.splice(e,1)),this}contains(t){return this.items.includes(t)}removeAll(){return this.ensureNonAliasedItems(),this.items.length=0,this}destroy(){this.removeAll(),this.items.length=0,this._name=""}get empty(){return 0===this.items.length}get name(){return this._name}}Object.defineProperties(Af.prototype,{dispatch:{value:Af.prototype.emit},run:{value:Af.prototype.emit}});class If{constructor(t=0,e=0){this._width=t,this._height=e,this.destroyed=!1,this.internal=!1,this.onResize=new Af("setRealSize"),this.onUpdate=new Af("update"),this.onError=new Af("onError")}bind(t){this.onResize.add(t),this.onUpdate.add(t),this.onError.add(t),(this._width||this._height)&&this.onResize.emit(this._width,this._height)}unbind(t){this.onResize.remove(t),this.onUpdate.remove(t),this.onError.remove(t)}resize(t,e){(t!==this._width||e!==this._height)&&(this._width=t,this._height=e,this.onResize.emit(t,e))}get valid(){return!!this._width&&!!this._height}update(){this.destroyed||this.onUpdate.emit()}load(){return Promise.resolve(this)}get width(){return this._width}get height(){return this._height}style(t,e,i){return!1}dispose(){}destroy(){this.destroyed||(this.destroyed=!0,this.dispose(),this.onError.removeAll(),this.onError=null,this.onResize.removeAll(),this.onResize=null,this.onUpdate.removeAll(),this.onUpdate=null)}static test(t,e){return!1}}class Sf extends If{constructor(t,e){const{width:i,height:s}=e||{};if(!i||!s)throw new Error("BufferResource width or height invalid");super(i,s),this.data=t,this.unpackAlignment=e.unpackAlignment??4}upload(t,e,i){const s=t.gl;s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.alphaMode===eh.UNPACK);const r=e.realWidth,n=e.realHeight;return i.width===r&&i.height===n?s.texSubImage2D(e.target,0,0,0,r,n,e.format,i.type,this.data):(i.width=r,i.height=n,s.texImage2D(e.target,0,i.internalFormat,r,n,0,e.format,i.type,this.data)),!0}dispose(){this.data=null}static test(t){return null===t||t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array}}const Cf={scaleMode:Zl.NEAREST,alphaMode:eh.NPM},Mf=class t extends Sh{constructor(e=null,i=null){super(),i=Object.assign({},t.defaultOptions,i);const{alphaMode:s,mipmap:r,anisotropicLevel:n,scaleMode:o,width:a,height:l,wrapMode:h,format:u,type:c,target:d,resolution:p,resourceOptions:f}=i;e&&!(e instanceof If)&&((e=Tf(e,f)).internal=!0),this.resolution=p||lh.RESOLUTION,this.width=Math.round((a||0)*this.resolution)/this.resolution,this.height=Math.round((l||0)*this.resolution)/this.resolution,this._mipmap=r,this.anisotropicLevel=n,this._wrapMode=h,this._scaleMode=o,this.format=u,this.type=c,this.target=d,this.alphaMode=s,this.uid=tf(),this.touched=0,this.isPowerOfTwo=!1,this._refreshPOT(),this._glTextures={},this.dirtyId=0,this.dirtyStyleId=0,this.cacheId=null,this.valid=a>0&&l>0,this.textureCacheIds=[],this.destroyed=!1,this.resource=null,this._batchEnabled=0,this._batchLocation=0,this.parentTextureArray=null,this.setResource(e)}get realWidth(){return Math.round(this.width*this.resolution)}get realHeight(){return Math.round(this.height*this.resolution)}get mipmap(){return this._mipmap}set mipmap(t){this._mipmap!==t&&(this._mipmap=t,this.dirtyStyleId++)}get scaleMode(){return this._scaleMode}set scaleMode(t){this._scaleMode!==t&&(this._scaleMode=t,this.dirtyStyleId++)}get wrapMode(){return this._wrapMode}set wrapMode(t){this._wrapMode!==t&&(this._wrapMode=t,this.dirtyStyleId++)}setStyle(t,e){let i;return void 0!==t&&t!==this.scaleMode&&(this.scaleMode=t,i=!0),void 0!==e&&e!==this.mipmap&&(this.mipmap=e,i=!0),i&&this.dirtyStyleId++,this}setSize(t,e,i){return i=i||this.resolution,this.setRealSize(t*i,e*i,i)}setRealSize(t,e,i){return this.resolution=i||this.resolution,this.width=Math.round(t)/this.resolution,this.height=Math.round(e)/this.resolution,this._refreshPOT(),this.update(),this}_refreshPOT(){this.isPowerOfTwo=qp(this.realWidth)&&qp(this.realHeight)}setResolution(t){const e=this.resolution;return e===t||(this.resolution=t,this.valid&&(this.width=Math.round(this.width*e)/t,this.height=Math.round(this.height*e)/t,this.emit("update",this)),this._refreshPOT()),this}setResource(t){if(this.resource===t)return this;if(this.resource)throw new Error("Resource can be set only once");return t.bind(this),this.resource=t,this}update(){this.valid?(this.dirtyId++,this.dirtyStyleId++,this.emit("update",this)):this.width>0&&this.height>0&&(this.valid=!0,this.emit("loaded",this),this.emit("update",this))}onError(t){this.emit("error",this,t)}destroy(){this.resource&&(this.resource.unbind(this),this.resource.internal&&this.resource.destroy(),this.resource=null),this.cacheId&&(delete of[this.cacheId],delete nf[this.cacheId],this.cacheId=null),this.valid=!1,this.dispose(),t.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0,this.emit("destroyed",this),this.removeAllListeners()}dispose(){this.emit("dispose",this)}castToBaseTexture(){return this}static from(e,i,s=lh.STRICT_TEXTURE_CACHE){const r="string"==typeof e;let n=null;if(r)n=e;else{if(!e._pixiId){const t=(null==i?void 0:i.pixiIdPrefix)||"pixiid";e._pixiId=`${t}_${tf()}`}n=e._pixiId}let o=of[n];if(r&&s&&!o)throw new Error(`The cacheId "${n}" does not exist in BaseTextureCache.`);return o||(o=new t(e,i),o.cacheId=n,t.addToCache(o,n)),o}static fromBuffer(e,i,s,r){e=e||new Float32Array(i*s*4);const n=new Sf(e,{width:i,height:s,...null==r?void 0:r.resourceOptions});let o,a;return e instanceof Float32Array?(o=Vl.RGBA,a=Jl.FLOAT):e instanceof Int32Array?(o=Vl.RGBA_INTEGER,a=Jl.INT):e instanceof Uint32Array?(o=Vl.RGBA_INTEGER,a=Jl.UNSIGNED_INT):e instanceof Int16Array?(o=Vl.RGBA_INTEGER,a=Jl.SHORT):e instanceof Uint16Array?(o=Vl.RGBA_INTEGER,a=Jl.UNSIGNED_SHORT):e instanceof Int8Array?(o=Vl.RGBA,a=Jl.BYTE):(o=Vl.RGBA,a=Jl.UNSIGNED_BYTE),n.internal=!0,new t(n,Object.assign({},Cf,{type:a,format:o},r))}static addToCache(t,e){e&&(t.textureCacheIds.includes(e)||t.textureCacheIds.push(e),of[e]&&of[e]!==t&&console.warn(`BaseTexture added to the cache with an id [${e}] that already had an entry`),of[e]=t)}static removeFromCache(t){if("string"==typeof t){const e=of[t];if(e){const i=e.textureCacheIds.indexOf(t);return i>-1&&e.textureCacheIds.splice(i,1),delete of[t],e}}else if(null==t?void 0:t.textureCacheIds){for(let e=0;e<t.textureCacheIds.length;++e)delete of[t.textureCacheIds[e]];return t.textureCacheIds.length=0,t}return null}};Mf.defaultOptions={mipmap:th.POW2,anisotropicLevel:0,scaleMode:Zl.LINEAR,wrapMode:Ql.CLAMP,alphaMode:eh.UNPACK,target:ql.TEXTURE_2D,format:Vl.RGBA,type:Jl.UNSIGNED_BYTE},Mf._globalBatch=0;let Of=Mf;class Nf{constructor(){this.texArray=null,this.blend=0,this.type=zl.TRIANGLES,this.start=0,this.size=0,this.data=null}}let Lf=0;class Rf{constructor(t,e=!0,i=!1){this.data=t||new Float32Array(1),this._glBuffers={},this._updateID=0,this.index=i,this.static=e,this.id=Lf++,this.disposeRunner=new Af("disposeBuffer")}update(t){t instanceof Array&&(t=new Float32Array(t)),this.data=t||this.data,this._updateID++}dispose(){this.disposeRunner.emit(this,!1)}destroy(){this.dispose(),this.data=null}set index(t){this.type=t?ah.ELEMENT_ARRAY_BUFFER:ah.ARRAY_BUFFER}get index(){return this.type===ah.ELEMENT_ARRAY_BUFFER}static from(t){return t instanceof Array&&(t=new Float32Array(t)),new Rf(t)}}class kf{constructor(t,e=0,i=!1,s=Jl.FLOAT,r,n,o,a=1){this.buffer=t,this.size=e,this.normalized=i,this.type=s,this.stride=r,this.start=n,this.instance=o,this.divisor=a}destroy(){this.buffer=null}static from(t,e,i,s,r){return new kf(t,e,i,s,r)}}const Bf={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array};const Ff={5126:4,5123:2,5121:1};let Df=0;const Uf={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array};class Gf{constructor(t=[],e={}){this.buffers=t,this.indexBuffer=null,this.attributes=e,this.glVertexArrayObjects={},this.id=Df++,this.instanced=!1,this.instanceCount=1,this.disposeRunner=new Af("disposeGeometry"),this.refCount=0}addAttribute(t,e,i=0,s=!1,r,n,o,a=!1){if(!e)throw new Error("You must pass a buffer when creating an attribute");e instanceof Rf||(e instanceof Array&&(e=new Float32Array(e)),e=new Rf(e));const l=t.split("|");if(l.length>1){for(let t=0;t<l.length;t++)this.addAttribute(l[t],e,i,s,r);return this}let h=this.buffers.indexOf(e);return-1===h&&(this.buffers.push(e),h=this.buffers.length-1),this.attributes[t]=new kf(h,i,s,r,n,o,a),this.instanced=this.instanced||a,this}getAttribute(t){return this.attributes[t]}getBuffer(t){return this.buffers[this.getAttribute(t).buffer]}addIndex(t){return t instanceof Rf||(t instanceof Array&&(t=new Uint16Array(t)),t=new Rf(t)),t.type=ah.ELEMENT_ARRAY_BUFFER,this.indexBuffer=t,this.buffers.includes(t)||this.buffers.push(t),this}getIndex(){return this.indexBuffer}interleave(){if(1===this.buffers.length||2===this.buffers.length&&this.indexBuffer)return this;const t=[],e=[],i=new Rf;let s;for(s in this.attributes){const i=this.attributes[s],r=this.buffers[i.buffer];t.push(r.data),e.push(i.size*Ff[i.type]/4),i.buffer=0}for(i.data=function(t,e){let i=0,s=0;const r={};for(let l=0;l<t.length;l++)s+=e[l],i+=t[l].length;const n=new ArrayBuffer(4*i);let o=null,a=0;for(let l=0;l<t.length;l++){const i=e[l],h=t[l],u=jp(h);r[u]||(r[u]=new Bf[u](n)),o=r[u];for(let t=0;t<h.length;t++)o[(t/i|0)*s+a+t%i]=h[t];a+=i}return new Float32Array(n)}(t,e),s=0;s<this.buffers.length;s++)this.buffers[s]!==this.indexBuffer&&this.buffers[s].destroy();return this.buffers=[i],this.indexBuffer&&this.buffers.push(this.indexBuffer),this}getSize(){for(const t in this.attributes){const e=this.attributes[t];return this.buffers[e.buffer].data.length/(e.stride/4||e.size)}return 0}dispose(){this.disposeRunner.emit(this,!1)}destroy(){this.dispose(),this.buffers=null,this.indexBuffer=null,this.attributes=null}clone(){const t=new Gf;for(let e=0;e<this.buffers.length;e++)t.buffers[e]=new Rf(this.buffers[e].data.slice(0));for(const e in this.attributes){const i=this.attributes[e];t.attributes[e]=new kf(i.buffer,i.size,i.normalized,i.type,i.stride,i.start,i.instance)}return this.indexBuffer&&(t.indexBuffer=t.buffers[this.buffers.indexOf(this.indexBuffer)],t.indexBuffer.type=ah.ELEMENT_ARRAY_BUFFER),t}static merge(t){const e=new Gf,i=[],s=[],r=[];let n;for(let o=0;o<t.length;o++){n=t[o];for(let t=0;t<n.buffers.length;t++)s[t]=s[t]||0,s[t]+=n.buffers[t].data.length,r[t]=0}for(let o=0;o<n.buffers.length;o++)i[o]=new(Uf[jp(n.buffers[o].data)])(s[o]),e.buffers[o]=new Rf(i[o]);for(let o=0;o<t.length;o++){n=t[o];for(let t=0;t<n.buffers.length;t++)i[t].set(n.buffers[t].data,r[t]),r[t]+=n.buffers[t].data.length}if(e.attributes=n.attributes,n.indexBuffer){e.indexBuffer=e.buffers[n.buffers.indexOf(n.indexBuffer)],e.indexBuffer.type=ah.ELEMENT_ARRAY_BUFFER;let i=0,s=0,r=0,o=0;for(let t=0;t<n.buffers.length;t++)if(n.buffers[t]!==n.indexBuffer){o=t;break}for(const t in n.attributes){const e=n.attributes[t];(0|e.buffer)===o&&(s+=e.size*Ff[e.type]/4)}for(let n=0;n<t.length;n++){const a=t[n].indexBuffer.data;for(let t=0;t<a.length;t++)e.indexBuffer.data[t+r]+=i;i+=t[n].buffers[o].data.length/s,r+=a.length}}return e}}class Xf extends Gf{constructor(t=!1){super(),this._buffer=new Rf(null,t,!1),this._indexBuffer=new Rf(null,t,!0),this.addAttribute("aVertexPosition",this._buffer,2,!1,Jl.FLOAT).addAttribute("aTextureCoord",this._buffer,2,!1,Jl.FLOAT).addAttribute("aColor",this._buffer,4,!0,Jl.UNSIGNED_BYTE).addAttribute("aTextureId",this._buffer,1,!0,Jl.FLOAT).addIndex(this._indexBuffer)}}const Wf=2*Math.PI,Hf=180/Math.PI,Yf=Math.PI/180;var $f=(t=>(t[t.POLY=0]="POLY",t[t.RECT=1]="RECT",t[t.CIRC=2]="CIRC",t[t.ELIP=3]="ELIP",t[t.RREC=4]="RREC",t))($f||{});class jf{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new jf(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}}jf.prototype.toString=function(){return`[@pixi/math:Point x=${this.x} y=${this.y}]`};const zf=[new jf,new jf,new jf,new jf];class Vf{constructor(t=0,e=0,i=0,s=0){this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(s),this.type=$f.RECT}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}static get EMPTY(){return new Vf(0,0,0,0)}clone(){return new Vf(this.x,this.y,this.width,this.height)}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t}contains(t,e){return!(this.width<=0||this.height<=0)&&(t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height)}intersects(t,e){if(!e){const e=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=e)return!1;const i=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>i}const i=this.left,s=this.right,r=this.top,n=this.bottom;if(s<=i||n<=r)return!1;const o=zf[0].set(t.left,t.top),a=zf[1].set(t.left,t.bottom),l=zf[2].set(t.right,t.top),h=zf[3].set(t.right,t.bottom);if(l.x<=o.x||a.y<=o.y)return!1;const u=Math.sign(e.a*e.d-e.b*e.c);if(0===u||(e.apply(o,o),e.apply(a,a),e.apply(l,l),e.apply(h,h),Math.max(o.x,a.x,l.x,h.x)<=i||Math.min(o.x,a.x,l.x,h.x)>=s||Math.max(o.y,a.y,l.y,h.y)<=r||Math.min(o.y,a.y,l.y,h.y)>=n))return!1;const c=u*(a.y-o.y),d=u*(o.x-a.x),p=c*i+d*r,f=c*s+d*r,m=c*i+d*n,g=c*s+d*n;if(Math.max(p,f,m,g)<=c*o.x+d*o.y||Math.min(p,f,m,g)>=c*h.x+d*h.y)return!1;const y=u*(o.y-l.y),v=u*(l.x-o.x),x=y*i+v*r,b=y*s+v*r,_=y*i+v*n,w=y*s+v*n;return!(Math.max(x,b,_,w)<=y*o.x+v*o.y||Math.min(x,b,_,w)>=y*h.x+v*h.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),r=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=s,this.height=Math.max(r-s,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,s=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=s-this.y,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),r=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=s,this.height=r-s,this}}Vf.prototype.toString=function(){return`[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class qf{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.radius=i,this.type=$f.CIRC}clone(){return new qf(this.x,this.y,this.radius)}contains(t,e){if(this.radius<=0)return!1;const i=this.radius*this.radius;let s=this.x-t,r=this.y-e;return s*=s,r*=r,s+r<=i}getBounds(){return new Vf(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius)}}qf.prototype.toString=function(){return`[@pixi/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`};class Jf{constructor(t=0,e=0,i=0,s=0){this.x=t,this.y=e,this.width=i,this.height=s,this.type=$f.ELIP}clone(){return new Jf(this.x,this.y,this.width,this.height)}contains(t,e){if(this.width<=0||this.height<=0)return!1;let i=(t-this.x)/this.width,s=(e-this.y)/this.height;return i*=i,s*=s,i+s<=1}getBounds(){return new Vf(this.x-this.width,this.y-this.height,this.width,this.height)}}Jf.prototype.toString=function(){return`[@pixi/math:Ellipse x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class Kf{constructor(...t){let e=Array.isArray(t[0])?t[0]:t;if("number"!=typeof e[0]){const t=[];for(let i=0,s=e.length;i<s;i++)t.push(e[i].x,e[i].y);e=t}this.points=e,this.type=$f.POLY,this.closeStroke=!0}clone(){const t=this.points.slice(),e=new Kf(t);return e.closeStroke=this.closeStroke,e}contains(t,e){let i=!1;const s=this.points.length/2;for(let r=0,n=s-1;r<s;n=r++){const s=this.points[2*r],o=this.points[2*r+1],a=this.points[2*n],l=this.points[2*n+1];o>e!=l>e&&t<(e-o)/(l-o)*(a-s)+s&&(i=!i)}return i}}Kf.prototype.toString=function(){return`[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce(((t,e)=>`${t}, ${e}`),"")}]`};class Zf{constructor(t=0,e=0,i=0,s=0,r=20){this.x=t,this.y=e,this.width=i,this.height=s,this.radius=r,this.type=$f.RREC}clone(){return new Zf(this.x,this.y,this.width,this.height,this.radius)}contains(t,e){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(e>=this.y+i&&e<=this.y+this.height-i||t>=this.x+i&&t<=this.x+this.width-i)return!0;let s=t-(this.x+i),r=e-(this.y+i);const n=i*i;if(s*s+r*r<=n||(s=t-(this.x+this.width-i),s*s+r*r<=n)||(r=e-(this.y+this.height-i),s*s+r*r<=n)||(s=t-(this.x+i),s*s+r*r<=n))return!0}return!1}}Zf.prototype.toString=function(){return`[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`};class Qf{constructor(t=1,e=0,i=0,s=1,r=0,n=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=n}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,s,r,n){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=n,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new jf;const i=t.x,s=t.y;return e.x=this.a*i+this.c*s+this.tx,e.y=this.b*i+this.d*s+this.ty,e}applyInverse(t,e){e=e||new jf;const i=1/(this.a*this.d+this.c*-this.b),s=t.x,r=t.y;return e.x=this.d*i*s+-this.c*i*r+(this.ty*this.c-this.tx*this.d)*i,e.y=this.a*i*r+-this.b*i*s+(-this.ty*this.a+this.tx*this.b)*i,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.a,r=this.c,n=this.tx;return this.a=s*e-this.b*i,this.b=s*i+this.b*e,this.c=r*e-this.d*i,this.d=r*i+this.d*e,this.tx=n*e-this.ty*i,this.ty=n*i+this.ty*e,this}append(t){const e=this.a,i=this.b,s=this.c,r=this.d;return this.a=t.a*e+t.b*s,this.b=t.a*i+t.b*r,this.c=t.c*e+t.d*s,this.d=t.c*i+t.d*r,this.tx=t.tx*e+t.ty*s+this.tx,this.ty=t.tx*i+t.ty*r+this.ty,this}setTransform(t,e,i,s,r,n,o,a,l){return this.a=Math.cos(o+l)*r,this.b=Math.sin(o+l)*r,this.c=-Math.sin(o-a)*n,this.d=Math.cos(o-a)*n,this.tx=t-(i*this.a+s*this.c),this.ty=e-(i*this.b+s*this.d),this}prepend(t){const e=this.tx;if(1!==t.a||0!==t.b||0!==t.c||1!==t.d){const e=this.a,i=this.c;this.a=e*t.a+this.b*t.c,this.b=e*t.b+this.b*t.d,this.c=i*t.a+this.d*t.c,this.d=i*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,s=this.c,r=this.d,n=t.pivot,o=-Math.atan2(-s,r),a=Math.atan2(i,e),l=Math.abs(o+a);return l<1e-5||Math.abs(Wf-l)<1e-5?(t.rotation=a,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=o,t.skew.y=a),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(s*s+r*r),t.position.x=this.tx+(n.x*e+n.y*s),t.position.y=this.ty+(n.x*i+n.y*r),t}invert(){const t=this.a,e=this.b,i=this.c,s=this.d,r=this.tx,n=t*s-e*i;return this.a=s/n,this.b=-e/n,this.c=-i/n,this.d=t/n,this.tx=(i*this.ty-s*r)/n,this.ty=-(t*this.ty-e*r)/n,this}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const t=new Qf;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}static get IDENTITY(){return new Qf}static get TEMP_MATRIX(){return new Qf}}Qf.prototype.toString=function(){return`[@pixi/math:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`};const tm=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],em=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],im=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],sm=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],rm=[],nm=[],om=Math.sign;!function(){for(let t=0;t<16;t++){const e=[];rm.push(e);for(let i=0;i<16;i++){const s=om(tm[t]*tm[i]+im[t]*em[i]),r=om(em[t]*tm[i]+sm[t]*em[i]),n=om(tm[t]*im[i]+im[t]*sm[i]),o=om(em[t]*im[i]+sm[t]*sm[i]);for(let t=0;t<16;t++)if(tm[t]===s&&em[t]===r&&im[t]===n&&sm[t]===o){e.push(t);break}}}for(let t=0;t<16;t++){const e=new Qf;e.set(tm[t],em[t],im[t],sm[t],0,0),nm.push(e)}}();const am={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:t=>tm[t],uY:t=>em[t],vX:t=>im[t],vY:t=>sm[t],inv:t=>8&t?15&t:7&-t,add:(t,e)=>rm[t][e],sub:(t,e)=>rm[t][am.inv(e)],rotate180:t=>4^t,isVertical:t=>2==(3&t),byDirection:(t,e)=>2*Math.abs(t)<=Math.abs(e)?e>=0?am.S:am.N:2*Math.abs(e)<=Math.abs(t)?t>0?am.E:am.W:e>0?t>0?am.SE:am.SW:t>0?am.NE:am.NW,matrixAppendRotationInv:(t,e,i=0,s=0)=>{const r=nm[am.inv(e)];r.tx=i,r.ty=s,t.append(r)}};class lm{constructor(t,e,i=0,s=0){this._x=i,this._y=s,this.cb=t,this.scope=e}clone(t=this.cb,e=this.scope){return new lm(t,e,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this.cb.call(this.scope)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this.cb.call(this.scope)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this.cb.call(this.scope))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this.cb.call(this.scope))}}lm.prototype.toString=function(){return`[@pixi/math:ObservablePoint x=${this.x} y=${this.y} scope=${this.scope}]`};const hm=class{constructor(){this.worldTransform=new Qf,this.localTransform=new Qf,this.position=new lm(this.onChange,this,0,0),this.scale=new lm(this.onChange,this,1,1),this.pivot=new lm(this.onChange,this,0,0),this.skew=new lm(this.updateSkew,this,0,0),this._rotation=0,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._localID=0,this._currentLocalID=0,this._worldID=0,this._parentID=0}onChange(){this._localID++}updateSkew(){this._cx=Math.cos(this._rotation+this.skew.y),this._sx=Math.sin(this._rotation+this.skew.y),this._cy=-Math.sin(this._rotation-this.skew.x),this._sy=Math.cos(this._rotation-this.skew.x),this._localID++}updateLocalTransform(){const t=this.localTransform;this._localID!==this._currentLocalID&&(t.a=this._cx*this.scale.x,t.b=this._sx*this.scale.x,t.c=this._cy*this.scale.y,t.d=this._sy*this.scale.y,t.tx=this.position.x-(this.pivot.x*t.a+this.pivot.y*t.c),t.ty=this.position.y-(this.pivot.x*t.b+this.pivot.y*t.d),this._currentLocalID=this._localID,this._parentID=-1)}updateTransform(t){const e=this.localTransform;if(this._localID!==this._currentLocalID&&(e.a=this._cx*this.scale.x,e.b=this._sx*this.scale.x,e.c=this._cy*this.scale.y,e.d=this._sy*this.scale.y,e.tx=this.position.x-(this.pivot.x*e.a+this.pivot.y*e.c),e.ty=this.position.y-(this.pivot.x*e.b+this.pivot.y*e.d),this._currentLocalID=this._localID,this._parentID=-1),this._parentID!==t._worldID){const i=t.worldTransform,s=this.worldTransform;s.a=e.a*i.a+e.b*i.c,s.b=e.a*i.b+e.b*i.d,s.c=e.c*i.a+e.d*i.c,s.d=e.c*i.b+e.d*i.d,s.tx=e.tx*i.a+e.ty*i.c+i.tx,s.ty=e.tx*i.b+e.ty*i.d+i.ty,this._parentID=t._worldID,this._worldID++}}setFromMatrix(t){t.decompose(this),this._localID++}get rotation(){return this._rotation}set rotation(t){this._rotation!==t&&(this._rotation=t,this.updateSkew())}};hm.IDENTITY=new hm;let um=hm;um.prototype.toString=function(){return`[@pixi/math:Transform position=(${this.position.x}, ${this.position.y}) rotation=${this.rotation} scale=(${this.scale.x}, ${this.scale.y}) skew=(${this.skew.x}, ${this.skew.y}) ]`};function cm(t,e,i){const s=t.createShader(e);return t.shaderSource(s,i),t.compileShader(s),s}function dm(t){const e=new Array(t);for(let i=0;i<e.length;i++)e[i]=!1;return e}function pm(t,e){switch(t){case"float":case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return dm(2*e);case"bvec3":return dm(3*e);case"bvec4":return dm(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const fm=[{test:t=>"float"===t.type&&1===t.size&&!t.isArray,code:t=>`\n if(uv["${t}"] !== ud["${t}"].value)\n {\n ud["${t}"].value = uv["${t}"]\n gl.uniform1f(ud["${t}"].location, uv["${t}"])\n }\n `},{test:(t,e)=>!("sampler2D"!==t.type&&"samplerCube"!==t.type&&"sampler2DArray"!==t.type||1!==t.size||t.isArray||null!=e&&void 0===e.castToBaseTexture),code:t=>`t = syncData.textureCount++;\n\n renderer.texture.bind(uv["${t}"], t);\n\n if(ud["${t}"].value !== t)\n {\n ud["${t}"].value = t;\n gl.uniform1i(ud["${t}"].location, t);\n; // eslint-disable-line max-len\n }`},{test:(t,e)=>"mat3"===t.type&&1===t.size&&!t.isArray&&void 0!==e.a,code:t=>`\n gl.uniformMatrix3fv(ud["${t}"].location, false, uv["${t}"].toArray(true));\n `,codeUbo:t=>`\n var ${t}_matrix = uv.${t}.toArray(true);\n\n data[offset] = ${t}_matrix[0];\n data[offset+1] = ${t}_matrix[1];\n data[offset+2] = ${t}_matrix[2];\n \n data[offset + 4] = ${t}_matrix[3];\n data[offset + 5] = ${t}_matrix[4];\n data[offset + 6] = ${t}_matrix[5];\n \n data[offset + 8] = ${t}_matrix[6];\n data[offset + 9] = ${t}_matrix[7];\n data[offset + 10] = ${t}_matrix[8];\n `},{test:(t,e)=>"vec2"===t.type&&1===t.size&&!t.isArray&&void 0!==e.x,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.x || cv[1] !== v.y)\n {\n cv[0] = v.x;\n cv[1] = v.y;\n gl.uniform2f(ud["${t}"].location, v.x, v.y);\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.x;\n data[offset+1] = v.y;\n `},{test:t=>"vec2"===t.type&&1===t.size&&!t.isArray,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n gl.uniform2f(ud["${t}"].location, v[0], v[1]);\n }\n `},{test:(t,e)=>"vec4"===t.type&&1===t.size&&!t.isArray&&void 0!==e.width,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height)\n {\n cv[0] = v.x;\n cv[1] = v.y;\n cv[2] = v.width;\n cv[3] = v.height;\n gl.uniform4f(ud["${t}"].location, v.x, v.y, v.width, v.height)\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.x;\n data[offset+1] = v.y;\n data[offset+2] = v.width;\n data[offset+3] = v.height;\n `},{test:(t,e)=>"vec4"===t.type&&1===t.size&&!t.isArray&&void 0!==e.red,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha)\n {\n cv[0] = v.red;\n cv[1] = v.green;\n cv[2] = v.blue;\n cv[3] = v.alpha;\n gl.uniform4f(ud["${t}"].location, v.red, v.green, v.blue, v.alpha)\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.red;\n data[offset+1] = v.green;\n data[offset+2] = v.blue;\n data[offset+3] = v.alpha;\n `},{test:(t,e)=>"vec3"===t.type&&1===t.size&&!t.isArray&&void 0!==e.red,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.a)\n {\n cv[0] = v.red;\n cv[1] = v.green;\n cv[2] = v.blue;\n \n gl.uniform3f(ud["${t}"].location, v.red, v.green, v.blue)\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.red;\n data[offset+1] = v.green;\n data[offset+2] = v.blue;\n `},{test:t=>"vec4"===t.type&&1===t.size&&!t.isArray,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4f(ud["${t}"].location, v[0], v[1], v[2], v[3])\n }`}],mm={float:"\n if (cv !== v)\n {\n cu.value = v;\n gl.uniform1f(location, v);\n }",vec2:"\n if (cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2f(location, v[0], v[1])\n }",vec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3f(location, v[0], v[1], v[2])\n }",vec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4f(location, v[0], v[1], v[2], v[3]);\n }",int:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }",ivec2:"\n if (cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2i(location, v[0], v[1]);\n }",ivec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3i(location, v[0], v[1], v[2]);\n }",ivec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4i(location, v[0], v[1], v[2], v[3]);\n }",uint:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1ui(location, v);\n }",uvec2:"\n if (cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2ui(location, v[0], v[1]);\n }",uvec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3ui(location, v[0], v[1], v[2]);\n }",uvec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4ui(location, v[0], v[1], v[2], v[3]);\n }",bool:"\n if (cv !== v)\n {\n cu.value = v;\n gl.uniform1i(location, v);\n }",bvec2:"\n if (cv[0] != v[0] || cv[1] != v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2i(location, v[0], v[1]);\n }",bvec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3i(location, v[0], v[1], v[2]);\n }",bvec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4i(location, v[0], v[1], v[2], v[3]);\n }",mat2:"gl.uniformMatrix2fv(location, false, v)",mat3:"gl.uniformMatrix3fv(location, false, v)",mat4:"gl.uniformMatrix4fv(location, false, v)",sampler2D:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }",samplerCube:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }",sampler2DArray:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }"},gm={float:"gl.uniform1fv(location, v)",vec2:"gl.uniform2fv(location, v)",vec3:"gl.uniform3fv(location, v)",vec4:"gl.uniform4fv(location, v)",mat4:"gl.uniformMatrix4fv(location, false, v)",mat3:"gl.uniformMatrix3fv(location, false, v)",mat2:"gl.uniformMatrix2fv(location, false, v)",int:"gl.uniform1iv(location, v)",ivec2:"gl.uniform2iv(location, v)",ivec3:"gl.uniform3iv(location, v)",ivec4:"gl.uniform4iv(location, v)",uint:"gl.uniform1uiv(location, v)",uvec2:"gl.uniform2uiv(location, v)",uvec3:"gl.uniform3uiv(location, v)",uvec4:"gl.uniform4uiv(location, v)",bool:"gl.uniform1iv(location, v)",bvec2:"gl.uniform2iv(location, v)",bvec3:"gl.uniform3iv(location, v)",bvec4:"gl.uniform4iv(location, v)",sampler2D:"gl.uniform1iv(location, v)",samplerCube:"gl.uniform1iv(location, v)",sampler2DArray:"gl.uniform1iv(location, v)"};const ym={};let vm,xm=ym;function bm(){if(!vm){vm=rh.MEDIUM;const t=function(){if(xm===ym||(null==xm?void 0:xm.isContextLost())){const t=lh.ADAPTER.createCanvas();let e;lh.PREFER_ENV>=Hl.WEBGL2&&(e=t.getContext("webgl2",{})),e||(e=t.getContext("webgl",{})||t.getContext("experimental-webgl",{}),e?e.getExtension("WEBGL_draw_buffers"):e=null),xm=e}return xm}();if(t&&t.getShaderPrecisionFormat){const e=t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT);e&&(vm=e.precision?rh.HIGH:rh.MEDIUM)}}return vm}function _m(t,e){const i=t.getShaderSource(e).split("\n").map(((t,e)=>`${e}: ${t}`)),s=t.getShaderInfoLog(e),r=s.split("\n"),n={},o=r.map((t=>parseFloat(t.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1")))).filter((t=>!(!t||n[t])&&(n[t]=!0,!0))),a=[""];o.forEach((t=>{i[t-1]=`%c${i[t-1]}%c`,a.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")}));const l=i.join("\n");a[0]=l,console.error(s),console.groupCollapsed("click to view full shader code"),console.warn(...a),console.groupEnd()}const wm={float:1,vec2:2,vec3:3,vec4:4,int:1,ivec2:2,ivec3:3,ivec4:4,uint:1,uvec2:2,uvec3:3,uvec4:4,bool:1,bvec2:2,bvec3:3,bvec4:4,mat2:4,mat3:9,mat4:16,sampler2D:1};function Pm(t){return wm[t]}let Em=null;const Tm={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"};function Am(t,e){if(!Em){const e=Object.keys(Tm);Em={};for(let i=0;i<e.length;++i){const s=e[i];Em[t[s]]=Tm[s]}}return Em[e]}function Im(t,e,i){if("precision"!==t.substring(0,9)){let s=e;return e===rh.HIGH&&i!==rh.HIGH&&(s=rh.MEDIUM),`precision ${s} float;\n${t}`}return i!==rh.HIGH&&"precision highp"===t.substring(0,15)?t.replace("precision highp","precision mediump"):t}let Sm;let Cm=0;const Mm={},Om=class t{constructor(e,i,s="pixi-shader",r={}){this.extra={},this.id=Cm++,this.vertexSrc=e||t.defaultVertexSrc,this.fragmentSrc=i||t.defaultFragmentSrc,this.vertexSrc=this.vertexSrc.trim(),this.fragmentSrc=this.fragmentSrc.trim(),this.extra=r,"#version"!==this.vertexSrc.substring(0,8)&&(s=s.replace(/\s+/g,"-"),Mm[s]?(Mm[s]++,s+=`-${Mm[s]}`):Mm[s]=1,this.vertexSrc=`#define SHADER_NAME ${s}\n${this.vertexSrc}`,this.fragmentSrc=`#define SHADER_NAME ${s}\n${this.fragmentSrc}`,this.vertexSrc=Im(this.vertexSrc,t.defaultVertexPrecision,rh.HIGH),this.fragmentSrc=Im(this.fragmentSrc,t.defaultFragmentPrecision,bm())),this.glPrograms={},this.syncUniforms=null}static get defaultVertexSrc(){return"attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}\n"}static get defaultFragmentSrc(){return"varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n gl_FragColor *= texture2D(uSampler, vTextureCoord);\n}"}static from(e,i,s){const r=e+i;let n=rf[r];return n||(rf[r]=n=new t(e,i,s)),n}};Om.defaultVertexPrecision=rh.HIGH,Om.defaultFragmentPrecision=Ah.apple.device?rh.HIGH:rh.MEDIUM;let Nm=Om,Lm=0;class Rm{constructor(t,e,i){this.group=!0,this.syncUniforms={},this.dirtyId=0,this.id=Lm++,this.static=!!e,this.ubo=!!i,t instanceof Rf?(this.buffer=t,this.buffer.type=ah.UNIFORM_BUFFER,this.autoManage=!1,this.ubo=!0):(this.uniforms=t,this.ubo&&(this.buffer=new Rf(new Float32Array(1)),this.buffer.type=ah.UNIFORM_BUFFER,this.autoManage=!0))}update(){this.dirtyId++,!this.autoManage&&this.buffer&&this.buffer.update()}add(t,e,i){if(this.ubo)throw new Error("[UniformGroup] uniform groups in ubo mode cannot be modified, or have uniform groups nested in them");this.uniforms[t]=new Rm(e,i)}static from(t,e,i){return new Rm(t,e,i)}static uboFrom(t,e){return new Rm(t,e??!0,!0)}}class km{constructor(t,e){this.uniformBindCount=0,this.program=t,this.uniformGroup=e?e instanceof Rm?e:new Rm(e):new Rm({}),this.disposeRunner=new Af("disposeShader")}checkUniformExists(t,e){if(e.uniforms[t])return!0;for(const i in e.uniforms){const s=e.uniforms[i];if(!0===s.group&&this.checkUniformExists(t,s))return!0}return!1}destroy(){this.uniformGroup=null,this.disposeRunner.emit(this),this.disposeRunner.destroy()}get uniforms(){return this.uniformGroup.uniforms}static from(t,e,i){const s=Nm.from(t,e);return new km(s,i)}}class Bm{constructor(t,e){if(this.vertexSrc=t,this.fragTemplate=e,this.programCache={},this.defaultGroupCache={},!e.includes("%count%"))throw new Error('Fragment template must contain "%count%".');if(!e.includes("%forloop%"))throw new Error('Fragment template must contain "%forloop%".')}generateShader(t){if(!this.programCache[t]){const e=new Int32Array(t);for(let s=0;s<t;s++)e[s]=s;this.defaultGroupCache[t]=Rm.from({uSamplers:e},!0);let i=this.fragTemplate;i=i.replace(/%count%/gi,`${t}`),i=i.replace(/%forloop%/gi,this.generateSampleSrc(t)),this.programCache[t]=new Nm(this.vertexSrc,i)}const e={tint:new Float32Array([1,1,1,1]),translationMatrix:new Qf,default:this.defaultGroupCache[t]};return new km(this.programCache[t],e)}generateSampleSrc(t){let e="";e+="\n",e+="\n";for(let i=0;i<t;i++)i>0&&(e+="\nelse "),i<t-1&&(e+=`if(vTextureId < ${i}.5)`),e+="\n{",e+=`\n\tcolor = texture2D(uSamplers[${i}], vTextureCoord);`,e+="\n}";return e+="\n",e+="\n",e}}class Fm{constructor(){this.elements=[],this.ids=[],this.count=0}clear(){for(let t=0;t<this.count;t++)this.elements[t]=null;this.count=0}}class Dm{constructor(t){this.renderer=t}flush(){}destroy(){this.renderer=null}start(){}stop(){this.flush()}render(t){}}const Um=class t extends Dm{constructor(e){super(e),this.setShaderGenerator(),this.geometryClass=Xf,this.vertexSize=6,this.state=Pf.for2d(),this.size=4*t.defaultBatchSize,this._vertexCount=0,this._indexCount=0,this._bufferedElements=[],this._bufferedTextures=[],this._bufferSize=0,this._shader=null,this._packedGeometries=[],this._packedGeometryPoolSize=2,this._flushId=0,this._aBuffers={},this._iBuffers={},this.maxTextures=1,this.renderer.on("prerender",this.onPrerender,this),e.runners.contextChange.add(this),this._dcIndex=0,this._aIndex=0,this._iIndex=0,this._attributeBuffer=null,this._indexBuffer=null,this._tempBoundTextures=[]}static get defaultMaxTextures(){return this._defaultMaxTextures=this._defaultMaxTextures??function(t){let e=!0;const i=lh.ADAPTER.getNavigator();if(Ah.tablet||Ah.phone){if(Ah.apple.device){const t=i.userAgent.match(/OS (\d+)_(\d+)?/);t&&parseInt(t[1],10)<11&&(e=!1)}if(Ah.android.device){const t=i.userAgent.match(/Android\s([0-9.]*)/);t&&parseInt(t[1],10)<7&&(e=!1)}}return e?t:4}(32),this._defaultMaxTextures}static set defaultMaxTextures(t){this._defaultMaxTextures=t}static get canUploadSameBuffer(){return this._canUploadSameBuffer=this._canUploadSameBuffer??!Ah.apple.device,this._canUploadSameBuffer}static set canUploadSameBuffer(t){this._canUploadSameBuffer=t}get MAX_TEXTURES(){return op("7.1.0","BatchRenderer#MAX_TEXTURES renamed to BatchRenderer#maxTextures"),this.maxTextures}static get defaultVertexSrc(){return"precision highp float;\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform vec4 tint;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vTextureId = aTextureId;\n vColor = aColor * tint;\n}\n"}static get defaultFragmentTemplate(){return"varying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\nuniform sampler2D uSamplers[%count%];\n\nvoid main(void){\n vec4 color;\n %forloop%\n gl_FragColor = color * vColor;\n}\n"}setShaderGenerator({vertex:e=t.defaultVertexSrc,fragment:i=t.defaultFragmentTemplate}={}){this.shaderGenerator=new Bm(e,i)}contextChange(){const e=this.renderer.gl;lh.PREFER_ENV===Hl.WEBGL_LEGACY?this.maxTextures=1:(this.maxTextures=Math.min(e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),t.defaultMaxTextures),this.maxTextures=function(t,e){if(0===t)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const i=e.createShader(e.FRAGMENT_SHADER);for(;;){const s=_f.replace(/%forloop%/gi,wf(t));if(e.shaderSource(i,s),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS))break;t=t/2|0}return t}(this.maxTextures,e)),this._shader=this.shaderGenerator.generateShader(this.maxTextures);for(let t=0;t<this._packedGeometryPoolSize;t++)this._packedGeometries[t]=new this.geometryClass;this.initFlushBuffers()}initFlushBuffers(){const{_drawCallPool:e,_textureArrayPool:i}=t,s=this.size/4,r=Math.floor(s/this.maxTextures)+1;for(;e.length<s;)e.push(new Nf);for(;i.length<r;)i.push(new Fm);for(let t=0;t<this.maxTextures;t++)this._tempBoundTextures[t]=null}onPrerender(){this._flushId=0}render(t){t._texture.valid&&(this._vertexCount+t.vertexData.length/2>this.size&&this.flush(),this._vertexCount+=t.vertexData.length/2,this._indexCount+=t.indices.length,this._bufferedTextures[this._bufferSize]=t._texture.baseTexture,this._bufferedElements[this._bufferSize++]=t)}buildTexturesAndDrawCalls(){const{_bufferedTextures:e,maxTextures:i}=this,s=t._textureArrayPool,r=this.renderer.batch,n=this._tempBoundTextures,o=this.renderer.textureGC.count;let a=++Of._globalBatch,l=0,h=s[0],u=0;r.copyBoundTextures(n,i);for(let t=0;t<this._bufferSize;++t){const c=e[t];e[t]=null,c._batchEnabled!==a&&(h.count>=i&&(r.boundArray(h,n,a,i),this.buildDrawCalls(h,u,t),u=t,h=s[++l],++a),c._batchEnabled=a,c.touched=o,h.elements[h.count++]=c)}h.count>0&&(r.boundArray(h,n,a,i),this.buildDrawCalls(h,u,this._bufferSize),++l,++a);for(let t=0;t<n.length;t++)n[t]=null;Of._globalBatch=a}buildDrawCalls(e,i,s){const{_bufferedElements:r,_attributeBuffer:n,_indexBuffer:o,vertexSize:a}=this,l=t._drawCallPool;let h=this._dcIndex,u=this._aIndex,c=this._iIndex,d=l[h];d.start=this._iIndex,d.texArray=e;for(let t=i;t<s;++t){const s=r[t],p=s._texture.baseTexture,f=Yp[p.alphaMode?1:0][s.blendMode];r[t]=null,i<t&&d.blend!==f&&(d.size=c-d.start,i=t,d=l[++h],d.texArray=e,d.start=c),this.packInterleavedGeometry(s,n,o,u,c),u+=s.vertexData.length/2*a,c+=s.indices.length,d.blend=f}i<s&&(d.size=c-d.start,++h),this._dcIndex=h,this._aIndex=u,this._iIndex=c}bindAndClearTexArray(t){const e=this.renderer.texture;for(let i=0;i<t.count;i++)e.bind(t.elements[i],t.ids[i]),t.elements[i]=null;t.count=0}updateGeometry(){const{_packedGeometries:e,_attributeBuffer:i,_indexBuffer:s}=this;t.canUploadSameBuffer?(e[this._flushId]._buffer.update(i.rawBinaryData),e[this._flushId]._indexBuffer.update(s),this.renderer.geometry.updateBuffers()):(this._packedGeometryPoolSize<=this._flushId&&(this._packedGeometryPoolSize++,e[this._flushId]=new this.geometryClass),e[this._flushId]._buffer.update(i.rawBinaryData),e[this._flushId]._indexBuffer.update(s),this.renderer.geometry.bind(e[this._flushId]),this.renderer.geometry.updateBuffers(),this._flushId++)}drawBatches(){const e=this._dcIndex,{gl:i,state:s}=this.renderer,r=t._drawCallPool;let n=null;for(let t=0;t<e;t++){const{texArray:e,type:o,size:a,start:l,blend:h}=r[t];n!==e&&(n=e,this.bindAndClearTexArray(e)),this.state.blendMode=h,s.set(this.state),i.drawElements(o,a,i.UNSIGNED_SHORT,2*l)}}flush(){0!==this._vertexCount&&(this._attributeBuffer=this.getAttributeBuffer(this._vertexCount),this._indexBuffer=this.getIndexBuffer(this._indexCount),this._aIndex=0,this._iIndex=0,this._dcIndex=0,this.buildTexturesAndDrawCalls(),this.updateGeometry(),this.drawBatches(),this._bufferSize=0,this._vertexCount=0,this._indexCount=0)}start(){this.renderer.state.set(this.state),this.renderer.texture.ensureSamplerType(this.maxTextures),this.renderer.shader.bind(this._shader),t.canUploadSameBuffer&&this.renderer.geometry.bind(this._packedGeometries[this._flushId])}stop(){this.flush()}destroy(){for(let t=0;t<this._packedGeometryPoolSize;t++)this._packedGeometries[t]&&this._packedGeometries[t].destroy();this.renderer.off("prerender",this.onPrerender,this),this._aBuffers=null,this._iBuffers=null,this._packedGeometries=null,this._attributeBuffer=null,this._indexBuffer=null,this._shader&&(this._shader.destroy(),this._shader=null),super.destroy()}getAttributeBuffer(t){const e=Vp(Math.ceil(t/8)),i=Jp(e),s=8*e;this._aBuffers.length<=i&&(this._iBuffers.length=i+1);let r=this._aBuffers[s];return r||(this._aBuffers[s]=r=new bf(s*this.vertexSize*4)),r}getIndexBuffer(t){const e=Vp(Math.ceil(t/12)),i=Jp(e),s=12*e;this._iBuffers.length<=i&&(this._iBuffers.length=i+1);let r=this._iBuffers[i];return r||(this._iBuffers[i]=r=new Uint16Array(s)),r}packInterleavedGeometry(t,e,i,s,r){const{uint32View:n,float32View:o}=e,a=s/this.vertexSize,l=t.uvs,h=t.indices,u=t.vertexData,c=t._texture.baseTexture._batchLocation,d=Math.min(t.worldAlpha,1),p=Hp.shared.setValue(t._tintRGB).toPremultiplied(d,t._texture.baseTexture.alphaMode>0);for(let f=0;f<u.length;f+=2)o[s++]=u[f],o[s++]=u[f+1],o[s++]=l[f],o[s++]=l[f+1],n[s++]=p,o[s++]=c;for(let f=0;f<h.length;f++)i[r++]=a+h[f]}};Um.defaultBatchSize=4096,Um.extension={name:"batch",type:gf.RendererPlugin},Um._drawCallPool=[],Um._textureArrayPool=[];let Gm=Um;xf.add(Gm);const Xm=class t extends km{constructor(e,i,s){super(Nm.from(e||t.defaultVertexSrc,i||t.defaultFragmentSrc),s),this.padding=0,this.resolution=t.defaultResolution,this.multisample=t.defaultMultisample,this.enabled=!0,this.autoFit=!0,this.state=new Pf}apply(t,e,i,s,r){t.applyFilter(this,e,i,s)}get blendMode(){return this.state.blendMode}set blendMode(t){this.state.blendMode=t}get resolution(){return this._resolution}set resolution(t){this._resolution=t}static get defaultVertexSrc(){return"attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n gl_Position = filterVertexPosition();\n vTextureCoord = filterTextureCoord();\n}\n"}static get defaultFragmentSrc(){return"varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n}\n"}};Xm.defaultResolution=1,Xm.defaultMultisample=oh.NONE;let Wm=Xm;class Hm{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new Hp(0),this.alpha=1}init(t){this.clearBeforeRender=t.clearBeforeRender;const{backgroundColor:e,background:i,backgroundAlpha:s}=t,r=i??e;void 0!==r&&(this.color=r),this.alpha=s}get color(){return this._backgroundColor.value}set color(t){this._backgroundColor.setValue(t)}get alpha(){return this._backgroundColor.alpha}set alpha(t){this._backgroundColor.setAlpha(t)}get backgroundColor(){return this._backgroundColor}destroy(){}}Hm.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0},Hm.extension={type:[gf.RendererSystem,gf.CanvasRendererSystem],name:"background"},xf.add(Hm);class Ym{constructor(t){this.renderer=t,this.emptyRenderer=new Dm(t),this.currentRenderer=this.emptyRenderer}setObjectRenderer(t){this.currentRenderer!==t&&(this.currentRenderer.stop(),this.currentRenderer=t,this.currentRenderer.start())}flush(){this.setObjectRenderer(this.emptyRenderer)}reset(){this.setObjectRenderer(this.emptyRenderer)}copyBoundTextures(t,e){const{boundTextures:i}=this.renderer.texture;for(let s=e-1;s>=0;--s)t[s]=i[s]||null,t[s]&&(t[s]._batchLocation=s)}boundArray(t,e,i,s){const{elements:r,ids:n,count:o}=t;let a=0;for(let l=0;l<o;l++){const t=r[l],o=t._batchLocation;if(o>=0&&o<s&&e[o]===t)n[l]=o;else for(;a<s;){const s=e[a];if(!s||s._batchEnabled!==i||s._batchLocation!==a){n[l]=a,t._batchLocation=a,e[a]=t;break}a++}}}destroy(){this.renderer=null}}Ym.extension={type:gf.RendererSystem,name:"batch"},xf.add(Ym);let $m=0;class jm{constructor(t){this.renderer=t,this.webGLVersion=1,this.extensions={},this.supports={uint32Indices:!1},this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(t){this.gl=t,this.renderer.gl=t,this.renderer.CONTEXT_UID=$m++}init(t){if(t.context)this.initFromContext(t.context);else{const e=this.renderer.background.alpha<1,i=t.premultipliedAlpha;this.preserveDrawingBuffer=t.preserveDrawingBuffer,this.useContextAlpha=t.useContextAlpha,this.powerPreference=t.powerPreference,this.initFromOptions({alpha:e,premultipliedAlpha:i,antialias:t.antialias,stencil:!0,preserveDrawingBuffer:t.preserveDrawingBuffer,powerPreference:t.powerPreference})}}initFromContext(t){this.gl=t,this.validateContext(t),this.renderer.gl=t,this.renderer.CONTEXT_UID=$m++,this.renderer.runners.contextChange.emit(t);const e=this.renderer.view;void 0!==e.addEventListener&&(e.addEventListener("webglcontextlost",this.handleContextLost,!1),e.addEventListener("webglcontextrestored",this.handleContextRestored,!1))}initFromOptions(t){const e=this.createContext(this.renderer.view,t);this.initFromContext(e)}createContext(t,e){let i;if(lh.PREFER_ENV>=Hl.WEBGL2&&(i=t.getContext("webgl2",e)),i)this.webGLVersion=2;else if(this.webGLVersion=1,i=t.getContext("webgl",e)||t.getContext("experimental-webgl",e),!i)throw new Error("This browser does not support WebGL. Try using the canvas renderer");return this.gl=i,this.getExtensions(),this.gl}getExtensions(){const{gl:t}=this,e={loseContext:t.getExtension("WEBGL_lose_context"),anisotropicFiltering:t.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:t.getExtension("OES_texture_float_linear"),s3tc:t.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:t.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:t.getExtension("WEBGL_compressed_texture_etc"),etc1:t.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:t.getExtension("WEBGL_compressed_texture_atc"),astc:t.getExtension("WEBGL_compressed_texture_astc"),bptc:t.getExtension("EXT_texture_compression_bptc")};1===this.webGLVersion?Object.assign(this.extensions,e,{drawBuffers:t.getExtension("WEBGL_draw_buffers"),depthTexture:t.getExtension("WEBGL_depth_texture"),vertexArrayObject:t.getExtension("OES_vertex_array_object")||t.getExtension("MOZ_OES_vertex_array_object")||t.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:t.getExtension("OES_element_index_uint"),floatTexture:t.getExtension("OES_texture_float"),floatTextureLinear:t.getExtension("OES_texture_float_linear"),textureHalfFloat:t.getExtension("OES_texture_half_float"),textureHalfFloatLinear:t.getExtension("OES_texture_half_float_linear")}):2===this.webGLVersion&&Object.assign(this.extensions,e,{colorBufferFloat:t.getExtension("EXT_color_buffer_float")})}handleContextLost(t){t.preventDefault(),setTimeout((()=>{this.gl.isContextLost()&&this.extensions.loseContext&&this.extensions.loseContext.restoreContext()}),0)}handleContextRestored(){this.renderer.runners.contextChange.emit(this.gl)}destroy(){const t=this.renderer.view;this.renderer=null,void 0!==t.removeEventListener&&(t.removeEventListener("webglcontextlost",this.handleContextLost),t.removeEventListener("webglcontextrestored",this.handleContextRestored)),this.gl.useProgram(null),this.extensions.loseContext&&this.extensions.loseContext.loseContext()}postrender(){this.renderer.objectRenderer.renderingToScreen&&this.gl.flush()}validateContext(t){const e=t.getContextAttributes(),i="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext;i&&(this.webGLVersion=2),e&&!e.stencil&&console.warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const s=i||!!t.getExtension("OES_element_index_uint");this.supports.uint32Indices=s,s||console.warn("Provided WebGL context does not support 32 index buffer, complex graphics may not render correctly")}}jm.defaultOptions={context:null,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"},jm.extension={type:gf.RendererSystem,name:"context"},xf.add(jm);class zm{constructor(t,e){if(this.width=Math.round(t),this.height=Math.round(e),!this.width||!this.height)throw new Error("Framebuffer width or height is zero");this.stencil=!1,this.depth=!1,this.dirtyId=0,this.dirtyFormat=0,this.dirtySize=0,this.depthTexture=null,this.colorTextures=[],this.glFramebuffers={},this.disposeRunner=new Af("disposeFramebuffer"),this.multisample=oh.NONE}get colorTexture(){return this.colorTextures[0]}addColorTexture(t=0,e){return this.colorTextures[t]=e||new Of(null,{scaleMode:Zl.NEAREST,resolution:1,mipmap:th.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this}addDepthTexture(t){return this.depthTexture=t||new Of(null,{scaleMode:Zl.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:th.OFF,format:Vl.DEPTH_COMPONENT,type:Jl.UNSIGNED_SHORT}),this.dirtyId++,this.dirtyFormat++,this}enableDepth(){return this.depth=!0,this.dirtyId++,this.dirtyFormat++,this}enableStencil(){return this.stencil=!0,this.dirtyId++,this.dirtyFormat++,this}resize(t,e){if(t=Math.round(t),e=Math.round(e),!t||!e)throw new Error("Framebuffer width and height must not be zero");if(t!==this.width||e!==this.height){this.width=t,this.height=e,this.dirtyId++,this.dirtySize++;for(let i=0;i<this.colorTextures.length;i++){const s=this.colorTextures[i],r=s.resolution;s.setSize(t/r,e/r)}if(this.depthTexture){const i=this.depthTexture.resolution;this.depthTexture.setSize(t/i,e/i)}}}dispose(){this.disposeRunner.emit(this,!1)}destroyDepthTexture(){this.depthTexture&&(this.depthTexture.destroy(),this.depthTexture=null,++this.dirtyId,++this.dirtyFormat)}}class Vm extends Of{constructor(t={}){if("number"==typeof t){t={width:arguments[0],height:arguments[1],scaleMode:arguments[2],resolution:arguments[3]}}t.width=t.width??100,t.height=t.height??100,t.multisample??(t.multisample=oh.NONE),super(null,t),this.mipmap=th.OFF,this.valid=!0,this._clear=new Hp([0,0,0,0]),this.framebuffer=new zm(this.realWidth,this.realHeight).addColorTexture(0,this),this.framebuffer.multisample=t.multisample,this.maskStack=[],this.filterStack=[{}]}set clearColor(t){this._clear.setValue(t)}get clearColor(){return this._clear.value}get clear(){return this._clear}get multisample(){return this.framebuffer.multisample}set multisample(t){this.framebuffer.multisample=t}resize(t,e){this.framebuffer.resize(t*this.resolution,e*this.resolution),this.setRealSize(this.framebuffer.width,this.framebuffer.height)}dispose(){this.framebuffer.dispose(),super.dispose()}destroy(){super.destroy(),this.framebuffer.destroyDepthTexture(),this.framebuffer=null}}class qm extends If{constructor(t){const e=t;super(e.naturalWidth||e.videoWidth||e.displayWidth||e.width,e.naturalHeight||e.videoHeight||e.displayHeight||e.height),this.source=t,this.noSubImage=!1}static crossOrigin(t,e,i){void 0!==i||e.startsWith("data:")?!1!==i&&(t.crossOrigin="string"==typeof i?i:"anonymous"):t.crossOrigin=pf(e)}upload(t,e,i,s){const r=t.gl,n=e.realWidth,o=e.realHeight;if(s=s||this.source,typeof HTMLImageElement<"u"&&s instanceof HTMLImageElement){if(!s.complete||0===s.naturalWidth)return!1}else if(typeof HTMLVideoElement<"u"&&s instanceof HTMLVideoElement&&s.readyState<=1)return!1;return r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.alphaMode===eh.UNPACK),this.noSubImage||e.target!==r.TEXTURE_2D||i.width!==n||i.height!==o?(i.width=n,i.height=o,r.texImage2D(e.target,0,i.internalFormat,e.format,i.type,s)):r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.format,i.type,s),!0}update(){if(this.destroyed)return;const t=this.source,e=t.naturalWidth||t.videoWidth||t.width,i=t.naturalHeight||t.videoHeight||t.height;this.resize(e,i),super.update()}dispose(){this.source=null}}class Jm extends qm{constructor(t,e){if(e=e||{},"string"==typeof t){const i=new Image;qm.crossOrigin(i,t,e.crossorigin),i.src=t,t=i}super(t),!t.complete&&this._width&&this._height&&(this._width=0,this._height=0),this.url=t.src,this._process=null,this.preserveBitmap=!1,this.createBitmap=(e.createBitmap??lh.CREATE_IMAGE_BITMAP)&&!!globalThis.createImageBitmap,this.alphaMode="number"==typeof e.alphaMode?e.alphaMode:null,this.bitmap=null,this._load=null,!1!==e.autoLoad&&this.load()}load(t){return this._load||(void 0!==t&&(this.createBitmap=t),this._load=new Promise(((t,e)=>{const i=this.source;this.url=i.src;const s=()=>{this.destroyed||(i.onload=null,i.onerror=null,this.update(),this._load=null,this.createBitmap?t(this.process()):t(this))};i.complete&&i.src?s():(i.onload=s,i.onerror=t=>{e(t),this.onError.emit(t)})}))),this._load}process(){const t=this.source;if(null!==this._process)return this._process;if(null!==this.bitmap||!globalThis.createImageBitmap)return Promise.resolve(this);const e=globalThis.createImageBitmap,i=!t.crossOrigin||"anonymous"===t.crossOrigin;return this._process=fetch(t.src,{mode:i?"cors":"no-cors"}).then((t=>t.blob())).then((i=>e(i,0,0,t.width,t.height,{premultiplyAlpha:null===this.alphaMode||this.alphaMode===eh.UNPACK?"premultiply":"none"}))).then((t=>this.destroyed?Promise.reject():(this.bitmap=t,this.update(),this._process=null,Promise.resolve(this)))),this._process}upload(t,e,i){if("number"==typeof this.alphaMode&&(e.alphaMode=this.alphaMode),!this.createBitmap)return super.upload(t,e,i);if(!this.bitmap&&(this.process(),!this.bitmap))return!1;if(super.upload(t,e,i,this.bitmap),!this.preserveBitmap){let t=!0;const s=e._glTextures;for(const r in s){const n=s[r];if(n!==i&&n.dirtyId!==e.dirtyId){t=!1;break}}t&&(this.bitmap.close&&this.bitmap.close(),this.bitmap=null)}return!0}dispose(){this.source.onload=null,this.source.onerror=null,super.dispose(),this.bitmap&&(this.bitmap.close(),this.bitmap=null),this._process=null,this._load=null}static test(t){return typeof HTMLImageElement<"u"&&("string"==typeof t||t instanceof HTMLImageElement)}}class Km{constructor(){this.x0=0,this.y0=0,this.x1=1,this.y1=0,this.x2=1,this.y2=1,this.x3=0,this.y3=1,this.uvsFloat32=new Float32Array(8)}set(t,e,i){const s=e.width,r=e.height;if(i){const e=t.width/2/s,n=t.height/2/r,o=t.x/s+e,a=t.y/r+n;i=am.add(i,am.NW),this.x0=o+e*am.uX(i),this.y0=a+n*am.uY(i),i=am.add(i,2),this.x1=o+e*am.uX(i),this.y1=a+n*am.uY(i),i=am.add(i,2),this.x2=o+e*am.uX(i),this.y2=a+n*am.uY(i),i=am.add(i,2),this.x3=o+e*am.uX(i),this.y3=a+n*am.uY(i)}else this.x0=t.x/s,this.y0=t.y/r,this.x1=(t.x+t.width)/s,this.y1=t.y/r,this.x2=(t.x+t.width)/s,this.y2=(t.y+t.height)/r,this.x3=t.x/s,this.y3=(t.y+t.height)/r;this.uvsFloat32[0]=this.x0,this.uvsFloat32[1]=this.y0,this.uvsFloat32[2]=this.x1,this.uvsFloat32[3]=this.y1,this.uvsFloat32[4]=this.x2,this.uvsFloat32[5]=this.y2,this.uvsFloat32[6]=this.x3,this.uvsFloat32[7]=this.y3}}Km.prototype.toString=function(){return`[@pixi/core:TextureUvs x0=${this.x0} y0=${this.y0} x1=${this.x1} y1=${this.y1} x2=${this.x2} y2=${this.y2} x3=${this.x3} y3=${this.y3}]`};const Zm=new Km;function Qm(t){t.destroy=function(){},t.on=function(){},t.once=function(){},t.emit=function(){}}class tg extends Sh{constructor(t,e,i,s,r,n,o){if(super(),this.noFrame=!1,e||(this.noFrame=!0,e=new Vf(0,0,1,1)),t instanceof tg&&(t=t.baseTexture),this.baseTexture=t,this._frame=e,this.trim=s,this.valid=!1,this.destroyed=!1,this._uvs=Zm,this.uvMatrix=null,this.orig=i||e,this._rotate=Number(r||0),!0===r)this._rotate=2;else if(this._rotate%2!=0)throw new Error("attempt to use diamond-shaped UVs. If you are sure, set rotation manually");this.defaultAnchor=n?new jf(n.x,n.y):new jf(0,0),this.defaultBorders=o,this._updateID=0,this.textureCacheIds=[],t.valid?this.noFrame?t.valid&&this.onBaseTextureUpdated(t):this.frame=e:t.once("loaded",this.onBaseTextureUpdated,this),this.noFrame&&t.on("update",this.onBaseTextureUpdated,this)}update(){this.baseTexture.resource&&this.baseTexture.resource.update()}onBaseTextureUpdated(t){if(this.noFrame){if(!this.baseTexture.valid)return;this._frame.width=t.width,this._frame.height=t.height,this.valid=!0,this.updateUvs()}else this.frame=this._frame;this.emit("update",this)}destroy(t){if(this.baseTexture){if(t){const{resource:t}=this.baseTexture;(null==t?void 0:t.url)&&nf[t.url]&&tg.removeFromCache(t.url),this.baseTexture.destroy()}this.baseTexture.off("loaded",this.onBaseTextureUpdated,this),this.baseTexture.off("update",this.onBaseTextureUpdated,this),this.baseTexture=null}this._frame=null,this._uvs=null,this.trim=null,this.orig=null,this.valid=!1,tg.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0,this.emit("destroyed",this),this.removeAllListeners()}clone(){var t;const e=this._frame.clone(),i=this._frame===this.orig?e:this.orig.clone(),s=new tg(this.baseTexture,!this.noFrame&&e,i,null==(t=this.trim)?void 0:t.clone(),this.rotate,this.defaultAnchor,this.defaultBorders);return this.noFrame&&(s._frame=e),s}updateUvs(){this._uvs===Zm&&(this._uvs=new Km),this._uvs.set(this._frame,this.baseTexture,this.rotate),this._updateID++}static from(t,e={},i=lh.STRICT_TEXTURE_CACHE){const s="string"==typeof t;let r=null;if(s)r=t;else if(t instanceof Of){if(!t.cacheId){const i=(null==e?void 0:e.pixiIdPrefix)||"pixiid";t.cacheId=`${i}-${tf()}`,Of.addToCache(t,t.cacheId)}r=t.cacheId}else{if(!t._pixiId){const i=(null==e?void 0:e.pixiIdPrefix)||"pixiid";t._pixiId=`${i}_${tf()}`}r=t._pixiId}let n=nf[r];if(s&&i&&!n)throw new Error(`The cacheId "${r}" does not exist in TextureCache.`);return n||t instanceof Of?!n&&t instanceof Of&&(n=new tg(t),tg.addToCache(n,r)):(e.resolution||(e.resolution=ff(t)),n=new tg(new Of(t,e)),n.baseTexture.cacheId=r,Of.addToCache(n.baseTexture,r),tg.addToCache(n,r)),n}static fromURL(t,e){const i=Object.assign({autoLoad:!1},null==e?void 0:e.resourceOptions),s=tg.from(t,Object.assign({resourceOptions:i},e),!1),r=s.baseTexture.resource;return s.baseTexture.valid?Promise.resolve(s):r.load().then((()=>Promise.resolve(s)))}static fromBuffer(t,e,i,s){return new tg(Of.fromBuffer(t,e,i,s))}static fromLoader(t,e,i,s){const r=new Of(t,Object.assign({scaleMode:Of.defaultOptions.scaleMode,resolution:ff(e)},s)),{resource:n}=r;n instanceof Jm&&(n.url=e);const o=new tg(r);return i||(i=e),Of.addToCache(o.baseTexture,i),tg.addToCache(o,i),i!==e&&(Of.addToCache(o.baseTexture,e),tg.addToCache(o,e)),o.baseTexture.valid?Promise.resolve(o):new Promise((t=>{o.baseTexture.once("loaded",(()=>t(o)))}))}static addToCache(t,e){e&&(t.textureCacheIds.includes(e)||t.textureCacheIds.push(e),nf[e]&&nf[e]!==t&&console.warn(`Texture added to the cache with an id [${e}] that already had an entry`),nf[e]=t)}static removeFromCache(t){if("string"==typeof t){const e=nf[t];if(e){const i=e.textureCacheIds.indexOf(t);return i>-1&&e.textureCacheIds.splice(i,1),delete nf[t],e}}else if(null==t?void 0:t.textureCacheIds){for(let e=0;e<t.textureCacheIds.length;++e)nf[t.textureCacheIds[e]]===t&&delete nf[t.textureCacheIds[e]];return t.textureCacheIds.length=0,t}return null}get resolution(){return this.baseTexture.resolution}get frame(){return this._frame}set frame(t){this._frame=t,this.noFrame=!1;const{x:e,y:i,width:s,height:r}=t,n=e+s>this.baseTexture.width,o=i+r>this.baseTexture.height;if(n||o){const t=n&&o?"and":"or",a=`X: ${e} + ${s} = ${e+s} > ${this.baseTexture.width}`,l=`Y: ${i} + ${r} = ${i+r} > ${this.baseTexture.height}`;throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions: ${a} ${t} ${l}`)}this.valid=s&&r&&this.baseTexture.valid,!this.trim&&!this.rotate&&(this.orig=t),this.valid&&this.updateUvs()}get rotate(){return this._rotate}set rotate(t){this._rotate=t,this.valid&&this.updateUvs()}get width(){return this.orig.width}get height(){return this.orig.height}castToBaseTexture(){return this.baseTexture}static get EMPTY(){return tg._EMPTY||(tg._EMPTY=new tg(new Of),Qm(tg._EMPTY),Qm(tg._EMPTY.baseTexture)),tg._EMPTY}static get WHITE(){if(!tg._WHITE){const t=lh.ADAPTER.createCanvas(16,16),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="white",e.fillRect(0,0,16,16),tg._WHITE=new tg(Of.from(t)),Qm(tg._WHITE),Qm(tg._WHITE.baseTexture)}return tg._WHITE}}class eg extends tg{constructor(t,e){super(t,e),this.valid=!0,this.filterFrame=null,this.filterPoolKey=null,this.updateUvs()}get framebuffer(){return this.baseTexture.framebuffer}get multisample(){return this.framebuffer.multisample}set multisample(t){this.framebuffer.multisample=t}resize(t,e,i=!0){const s=this.baseTexture.resolution,r=Math.round(t*s)/s,n=Math.round(e*s)/s;this.valid=r>0&&n>0,this._frame.width=this.orig.width=r,this._frame.height=this.orig.height=n,i&&this.baseTexture.resize(r,n),this.updateUvs()}setResolution(t){const{baseTexture:e}=this;e.resolution!==t&&(e.setResolution(t),this.resize(e.width,e.height,!1))}static create(t){return new eg(new Vm(t))}}class ig{constructor(t){this.texturePool={},this.textureOptions=t||{},this.enableFullScreen=!1,this._pixelsWidth=0,this._pixelsHeight=0}createTexture(t,e,i=oh.NONE){const s=new Vm(Object.assign({width:t,height:e,resolution:1,multisample:i},this.textureOptions));return new eg(s)}getOptimalTexture(t,e,i=1,s=oh.NONE){let r;t=Math.max(Math.ceil(t*i-1e-6),1),e=Math.max(Math.ceil(e*i-1e-6),1),this.enableFullScreen&&t===this._pixelsWidth&&e===this._pixelsHeight?r=s>1?-s:-1:(r=((65535&(t=Vp(t)))<<16|65535&(e=Vp(e)))>>>0,s>1&&(r+=4294967296*s)),this.texturePool[r]||(this.texturePool[r]=[]);let n=this.texturePool[r].pop();return n||(n=this.createTexture(t,e,s)),n.filterPoolKey=r,n.setResolution(i),n}getFilterTexture(t,e,i){const s=this.getOptimalTexture(t.width,t.height,e||t.resolution,i||oh.NONE);return s.filterFrame=t.filterFrame,s}returnTexture(t){const e=t.filterPoolKey;t.filterFrame=null,this.texturePool[e].push(t)}returnFilterTexture(t){this.returnTexture(t)}clear(t){if(t=!1!==t)for(const e in this.texturePool){const t=this.texturePool[e];if(t)for(let e=0;e<t.length;e++)t[e].destroy(!0)}this.texturePool={}}setScreenSize(t){if(t.width!==this._pixelsWidth||t.height!==this._pixelsHeight){this.enableFullScreen=t.width>0&&t.height>0;for(const t in this.texturePool){if(!(Number(t)<0))continue;const e=this.texturePool[t];if(e)for(let t=0;t<e.length;t++)e[t].destroy(!0);this.texturePool[t]=[]}this._pixelsWidth=t.width,this._pixelsHeight=t.height}}}ig.SCREEN_KEY=-1;class sg extends Gf{constructor(){super(),this.addAttribute("aVertexPosition",new Float32Array([0,0,1,0,1,1,0,1])).addIndex([0,1,3,2])}}class rg extends Gf{constructor(){super(),this.vertices=new Float32Array([-1,-1,1,-1,1,1,-1,1]),this.uvs=new Float32Array([0,0,1,0,1,1,0,1]),this.vertexBuffer=new Rf(this.vertices),this.uvBuffer=new Rf(this.uvs),this.addAttribute("aVertexPosition",this.vertexBuffer).addAttribute("aTextureCoord",this.uvBuffer).addIndex([0,1,2,0,2,3])}map(t,e){let i=0,s=0;return this.uvs[0]=i,this.uvs[1]=s,this.uvs[2]=i+e.width/t.width,this.uvs[3]=s,this.uvs[4]=i+e.width/t.width,this.uvs[5]=s+e.height/t.height,this.uvs[6]=i,this.uvs[7]=s+e.height/t.height,i=e.x,s=e.y,this.vertices[0]=i,this.vertices[1]=s,this.vertices[2]=i+e.width,this.vertices[3]=s,this.vertices[4]=i+e.width,this.vertices[5]=s+e.height,this.vertices[6]=i,this.vertices[7]=s+e.height,this.invalidate(),this}invalidate(){return this.vertexBuffer._updateID++,this.uvBuffer._updateID++,this}}class ng{constructor(){this.renderTexture=null,this.target=null,this.legacy=!1,this.resolution=1,this.multisample=oh.NONE,this.sourceFrame=new Vf,this.destinationFrame=new Vf,this.bindingSourceFrame=new Vf,this.bindingDestinationFrame=new Vf,this.filters=[],this.transform=null}clear(){this.target=null,this.filters=null,this.renderTexture=null}}const og=[new jf,new jf,new jf,new jf],ag=new Qf;class lg{constructor(t){this.renderer=t,this.defaultFilterStack=[{}],this.texturePool=new ig,this.statePool=[],this.quad=new sg,this.quadUv=new rg,this.tempRect=new Vf,this.activeState={},this.globalUniforms=new Rm({outputFrame:new Vf,inputSize:new Float32Array(4),inputPixel:new Float32Array(4),inputClamp:new Float32Array(4),resolution:1,filterArea:new Float32Array(4),filterClamp:new Float32Array(4)},!0),this.forceClear=!1,this.useMaxPadding=!1}init(){this.texturePool.setScreenSize(this.renderer.view)}push(t,e){const i=this.renderer,s=this.defaultFilterStack,r=this.statePool.pop()||new ng,n=i.renderTexture;let o,a;if(n.current){const t=n.current;o=t.resolution,a=t.multisample}else o=i.resolution,a=i.multisample;let l=e[0].resolution||o,h=e[0].multisample??a,u=e[0].padding,c=e[0].autoFit,d=e[0].legacy??!0;for(let m=1;m<e.length;m++){const t=e[m];l=Math.min(l,t.resolution||o),h=Math.min(h,t.multisample??a),u=this.useMaxPadding?Math.max(u,t.padding):u+t.padding,c=c&&t.autoFit,d=d||(t.legacy??!0)}1===s.length&&(this.defaultFilterStack[0].renderTexture=n.current),s.push(r),r.resolution=l,r.multisample=h,r.legacy=d,r.target=t,r.sourceFrame.copyFrom(t.filterArea||t.getBounds(!0)),r.sourceFrame.pad(u);const p=this.tempRect.copyFrom(n.sourceFrame);i.projection.transform&&this.transformAABB(ag.copyFrom(i.projection.transform).invert(),p),c?(r.sourceFrame.fit(p),(r.sourceFrame.width<=0||r.sourceFrame.height<=0)&&(r.sourceFrame.width=0,r.sourceFrame.height=0)):r.sourceFrame.intersects(p)||(r.sourceFrame.width=0,r.sourceFrame.height=0),this.roundFrame(r.sourceFrame,n.current?n.current.resolution:i.resolution,n.sourceFrame,n.destinationFrame,i.projection.transform),r.renderTexture=this.getOptimalFilterTexture(r.sourceFrame.width,r.sourceFrame.height,l,h),r.filters=e,r.destinationFrame.width=r.renderTexture.width,r.destinationFrame.height=r.renderTexture.height;const f=this.tempRect;f.x=0,f.y=0,f.width=r.sourceFrame.width,f.height=r.sourceFrame.height,r.renderTexture.filterFrame=r.sourceFrame,r.bindingSourceFrame.copyFrom(n.sourceFrame),r.bindingDestinationFrame.copyFrom(n.destinationFrame),r.transform=i.projection.transform,i.projection.transform=null,n.bind(r.renderTexture,r.sourceFrame,f),i.framebuffer.clear(0,0,0,0)}pop(){const t=this.defaultFilterStack,e=t.pop(),i=e.filters;this.activeState=e;const s=this.globalUniforms.uniforms;s.outputFrame=e.sourceFrame,s.resolution=e.resolution;const r=s.inputSize,n=s.inputPixel,o=s.inputClamp;if(r[0]=e.destinationFrame.width,r[1]=e.destinationFrame.height,r[2]=1/r[0],r[3]=1/r[1],n[0]=Math.round(r[0]*e.resolution),n[1]=Math.round(r[1]*e.resolution),n[2]=1/n[0],n[3]=1/n[1],o[0]=.5*n[2],o[1]=.5*n[3],o[2]=e.sourceFrame.width*r[2]-.5*n[2],o[3]=e.sourceFrame.height*r[3]-.5*n[3],e.legacy){const t=s.filterArea;t[0]=e.destinationFrame.width,t[1]=e.destinationFrame.height,t[2]=e.sourceFrame.x,t[3]=e.sourceFrame.y,s.filterClamp=s.inputClamp}this.globalUniforms.update();const a=t[t.length-1];if(this.renderer.framebuffer.blit(),1===i.length)i[0].apply(this,e.renderTexture,a.renderTexture,ih.BLEND,e),this.returnFilterTexture(e.renderTexture);else{let t=e.renderTexture,s=this.getOptimalFilterTexture(t.width,t.height,e.resolution);s.filterFrame=t.filterFrame;let r=0;for(r=0;r<i.length-1;++r){1===r&&e.multisample>1&&(s=this.getOptimalFilterTexture(t.width,t.height,e.resolution),s.filterFrame=t.filterFrame),i[r].apply(this,t,s,ih.CLEAR,e);const n=t;t=s,s=n}i[r].apply(this,t,a.renderTexture,ih.BLEND,e),r>1&&e.multisample>1&&this.returnFilterTexture(e.renderTexture),this.returnFilterTexture(t),this.returnFilterTexture(s)}e.clear(),this.statePool.push(e)}bindAndClear(t,e=ih.CLEAR){const{renderTexture:i,state:s}=this.renderer;if(t===this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?this.renderer.projection.transform=this.activeState.transform:this.renderer.projection.transform=null,null==t?void 0:t.filterFrame){const e=this.tempRect;e.x=0,e.y=0,e.width=t.filterFrame.width,e.height=t.filterFrame.height,i.bind(t,t.filterFrame,e)}else t!==this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?i.bind(t):this.renderer.renderTexture.bind(t,this.activeState.bindingSourceFrame,this.activeState.bindingDestinationFrame);const r=1&s.stateId||this.forceClear;(e===ih.CLEAR||e===ih.BLIT&&r)&&this.renderer.framebuffer.clear(0,0,0,0)}applyFilter(t,e,i,s){const r=this.renderer;r.state.set(t.state),this.bindAndClear(i,s),t.uniforms.uSampler=e,t.uniforms.filterGlobals=this.globalUniforms,r.shader.bind(t),t.legacy=!!t.program.attributeData.aTextureCoord,t.legacy?(this.quadUv.map(e._frame,e.filterFrame),r.geometry.bind(this.quadUv),r.geometry.draw(zl.TRIANGLES)):(r.geometry.bind(this.quad),r.geometry.draw(zl.TRIANGLE_STRIP))}calculateSpriteMatrix(t,e){const{sourceFrame:i,destinationFrame:s}=this.activeState,{orig:r}=e._texture,n=t.set(s.width,0,0,s.height,i.x,i.y),o=e.worldTransform.copyTo(Qf.TEMP_MATRIX);return o.invert(),n.prepend(o),n.scale(1/r.width,1/r.height),n.translate(e.anchor.x,e.anchor.y),n}destroy(){this.renderer=null,this.texturePool.clear(!1)}getOptimalFilterTexture(t,e,i=1,s=oh.NONE){return this.texturePool.getOptimalTexture(t,e,i,s)}getFilterTexture(t,e,i){if("number"==typeof t){const i=t;t=e,e=i}t=t||this.activeState.renderTexture;const s=this.texturePool.getOptimalTexture(t.width,t.height,e||t.resolution,i||oh.NONE);return s.filterFrame=t.filterFrame,s}returnFilterTexture(t){this.texturePool.returnTexture(t)}emptyPool(){this.texturePool.clear(!0)}resize(){this.texturePool.setScreenSize(this.renderer.view)}transformAABB(t,e){const i=og[0],s=og[1],r=og[2],n=og[3];i.set(e.left,e.top),s.set(e.left,e.bottom),r.set(e.right,e.top),n.set(e.right,e.bottom),t.apply(i,i),t.apply(s,s),t.apply(r,r),t.apply(n,n);const o=Math.min(i.x,s.x,r.x,n.x),a=Math.min(i.y,s.y,r.y,n.y),l=Math.max(i.x,s.x,r.x,n.x),h=Math.max(i.y,s.y,r.y,n.y);e.x=o,e.y=a,e.width=l-o,e.height=h-a}roundFrame(t,e,i,s,r){if(!(t.width<=0||t.height<=0||i.width<=0||i.height<=0)){if(r){const{a:t,b:e,c:i,d:s}=r;if((Math.abs(e)>1e-4||Math.abs(i)>1e-4)&&(Math.abs(t)>1e-4||Math.abs(s)>1e-4))return}(r=r?ag.copyFrom(r):ag.identity()).translate(-i.x,-i.y).scale(s.width/i.width,s.height/i.height).translate(s.x,s.y),this.transformAABB(r,t),t.ceil(e),this.transformAABB(r.invert(),t)}}}lg.extension={type:gf.RendererSystem,name:"filter"},xf.add(lg);class hg{constructor(t){this.framebuffer=t,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=oh.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}}const ug=new Vf;class cg{constructor(t){this.renderer=t,this.managedFramebuffers=[],this.unknownFramebuffer=new zm(10,10),this.msaaSamples=null}contextChange(){this.disposeAll(!0);const t=this.gl=this.renderer.gl;if(this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.current=this.unknownFramebuffer,this.viewport=new Vf,this.hasMRT=!0,this.writeDepthTexture=!0,1===this.renderer.context.webGLVersion){let e=this.renderer.context.extensions.drawBuffers,i=this.renderer.context.extensions.depthTexture;lh.PREFER_ENV===Hl.WEBGL_LEGACY&&(e=null,i=null),e?t.drawBuffers=t=>e.drawBuffersWEBGL(t):(this.hasMRT=!1,t.drawBuffers=()=>{}),i||(this.writeDepthTexture=!1)}else this.msaaSamples=t.getInternalformatParameter(t.RENDERBUFFER,t.RGBA8,t.SAMPLES)}bind(t,e,i=0){const{gl:s}=this;if(t){const r=t.glFramebuffers[this.CONTEXT_UID]||this.initFramebuffer(t);this.current!==t&&(this.current=t,s.bindFramebuffer(s.FRAMEBUFFER,r.framebuffer)),r.mipLevel!==i&&(t.dirtyId++,t.dirtyFormat++,r.mipLevel=i),r.dirtyId!==t.dirtyId&&(r.dirtyId=t.dirtyId,r.dirtyFormat!==t.dirtyFormat?(r.dirtyFormat=t.dirtyFormat,r.dirtySize=t.dirtySize,this.updateFramebuffer(t,i)):r.dirtySize!==t.dirtySize&&(r.dirtySize=t.dirtySize,this.resizeFramebuffer(t)));for(let e=0;e<t.colorTextures.length;e++){const i=t.colorTextures[e];this.renderer.texture.unbind(i.parentTextureArray||i)}if(t.depthTexture&&this.renderer.texture.unbind(t.depthTexture),e){const t=e.width>>i,s=e.height>>i,r=t/e.width;this.setViewport(e.x*r,e.y*r,t,s)}else{const e=t.width>>i,s=t.height>>i;this.setViewport(0,0,e,s)}}else this.current&&(this.current=null,s.bindFramebuffer(s.FRAMEBUFFER,null)),e?this.setViewport(e.x,e.y,e.width,e.height):this.setViewport(0,0,this.renderer.width,this.renderer.height)}setViewport(t,e,i,s){const r=this.viewport;t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s),(r.width!==i||r.height!==s||r.x!==t||r.y!==e)&&(r.x=t,r.y=e,r.width=i,r.height=s,this.gl.viewport(t,e,i,s))}get size(){return this.current?{x:0,y:0,width:this.current.width,height:this.current.height}:{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}clear(t,e,i,s,r=$l.COLOR|$l.DEPTH){const{gl:n}=this;n.clearColor(t,e,i,s),n.clear(r)}initFramebuffer(t){const{gl:e}=this,i=new hg(e.createFramebuffer());return i.multisample=this.detectSamples(t.multisample),t.glFramebuffers[this.CONTEXT_UID]=i,this.managedFramebuffers.push(t),t.disposeRunner.add(this),i}resizeFramebuffer(t){const{gl:e}=this,i=t.glFramebuffers[this.CONTEXT_UID];if(i.stencil){let s;e.bindRenderbuffer(e.RENDERBUFFER,i.stencil),s=1===this.renderer.context.webGLVersion?e.DEPTH_STENCIL:t.depth&&t.stencil?e.DEPTH24_STENCIL8:t.depth?e.DEPTH_COMPONENT24:e.STENCIL_INDEX8,i.msaaBuffer?e.renderbufferStorageMultisample(e.RENDERBUFFER,i.multisample,s,t.width,t.height):e.renderbufferStorage(e.RENDERBUFFER,s,t.width,t.height)}const s=t.colorTextures;let r=s.length;e.drawBuffers||(r=Math.min(r,1));for(let n=0;n<r;n++){const r=s[n],o=r.parentTextureArray||r;this.renderer.texture.bind(o,0),0===n&&i.msaaBuffer&&(e.bindRenderbuffer(e.RENDERBUFFER,i.msaaBuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,i.multisample,o._glTextures[this.CONTEXT_UID].internalFormat,t.width,t.height))}t.depthTexture&&this.writeDepthTexture&&this.renderer.texture.bind(t.depthTexture,0)}updateFramebuffer(t,e){const{gl:i}=this,s=t.glFramebuffers[this.CONTEXT_UID],r=t.colorTextures;let n=r.length;i.drawBuffers||(n=Math.min(n,1)),s.multisample>1&&this.canMultisampleFramebuffer(t)?s.msaaBuffer=s.msaaBuffer||i.createRenderbuffer():s.msaaBuffer&&(i.deleteRenderbuffer(s.msaaBuffer),s.msaaBuffer=null,s.blitFramebuffer&&(s.blitFramebuffer.dispose(),s.blitFramebuffer=null));const o=[];for(let a=0;a<n;a++){const n=r[a],l=n.parentTextureArray||n;this.renderer.texture.bind(l,0),0===a&&s.msaaBuffer?(i.bindRenderbuffer(i.RENDERBUFFER,s.msaaBuffer),i.renderbufferStorageMultisample(i.RENDERBUFFER,s.multisample,l._glTextures[this.CONTEXT_UID].internalFormat,t.width,t.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,s.msaaBuffer)):(i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+a,n.target,l._glTextures[this.CONTEXT_UID].texture,e),o.push(i.COLOR_ATTACHMENT0+a))}if(o.length>1&&i.drawBuffers(o),t.depthTexture&&this.writeDepthTexture){const s=t.depthTexture;this.renderer.texture.bind(s,0),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,s._glTextures[this.CONTEXT_UID].texture,e)}if(!t.stencil&&!t.depth||t.depthTexture&&this.writeDepthTexture)s.stencil&&(i.deleteRenderbuffer(s.stencil),s.stencil=null);else{let e,r;s.stencil=s.stencil||i.createRenderbuffer(),1===this.renderer.context.webGLVersion?(e=i.DEPTH_STENCIL_ATTACHMENT,r=i.DEPTH_STENCIL):t.depth&&t.stencil?(e=i.DEPTH_STENCIL_ATTACHMENT,r=i.DEPTH24_STENCIL8):t.depth?(e=i.DEPTH_ATTACHMENT,r=i.DEPTH_COMPONENT24):(e=i.STENCIL_ATTACHMENT,r=i.STENCIL_INDEX8),i.bindRenderbuffer(i.RENDERBUFFER,s.stencil),s.msaaBuffer?i.renderbufferStorageMultisample(i.RENDERBUFFER,s.multisample,r,t.width,t.height):i.renderbufferStorage(i.RENDERBUFFER,r,t.width,t.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,e,i.RENDERBUFFER,s.stencil)}}canMultisampleFramebuffer(t){return 1!==this.renderer.context.webGLVersion&&t.colorTextures.length<=1&&!t.depthTexture}detectSamples(t){const{msaaSamples:e}=this;let i=oh.NONE;if(t<=1||null===e)return i;for(let s=0;s<e.length;s++)if(e[s]<=t){i=e[s];break}return 1===i&&(i=oh.NONE),i}blit(t,e,i){const{current:s,renderer:r,gl:n,CONTEXT_UID:o}=this;if(2!==r.context.webGLVersion||!s)return;const a=s.glFramebuffers[o];if(!a)return;if(!t){if(!a.msaaBuffer)return;const e=s.colorTextures[0];if(!e)return;a.blitFramebuffer||(a.blitFramebuffer=new zm(s.width,s.height),a.blitFramebuffer.addColorTexture(0,e)),(t=a.blitFramebuffer).colorTextures[0]!==e&&(t.colorTextures[0]=e,t.dirtyId++,t.dirtyFormat++),(t.width!==s.width||t.height!==s.height)&&(t.width=s.width,t.height=s.height,t.dirtyId++,t.dirtySize++)}e||((e=ug).width=s.width,e.height=s.height),i||(i=e);const l=e.width===i.width&&e.height===i.height;this.bind(t),n.bindFramebuffer(n.READ_FRAMEBUFFER,a.framebuffer),n.blitFramebuffer(e.left,e.top,e.right,e.bottom,i.left,i.top,i.right,i.bottom,n.COLOR_BUFFER_BIT,l?n.NEAREST:n.LINEAR),n.bindFramebuffer(n.READ_FRAMEBUFFER,t.glFramebuffers[this.CONTEXT_UID].framebuffer)}disposeFramebuffer(t,e){const i=t.glFramebuffers[this.CONTEXT_UID],s=this.gl;if(!i)return;delete t.glFramebuffers[this.CONTEXT_UID];const r=this.managedFramebuffers.indexOf(t);r>=0&&this.managedFramebuffers.splice(r,1),t.disposeRunner.remove(this),e||(s.deleteFramebuffer(i.framebuffer),i.msaaBuffer&&s.deleteRenderbuffer(i.msaaBuffer),i.stencil&&s.deleteRenderbuffer(i.stencil)),i.blitFramebuffer&&this.disposeFramebuffer(i.blitFramebuffer,e)}disposeAll(t){const e=this.managedFramebuffers;this.managedFramebuffers=[];for(let i=0;i<e.length;i++)this.disposeFramebuffer(e[i],t)}forceStencil(){const t=this.current;if(!t)return;const e=t.glFramebuffers[this.CONTEXT_UID];if(!e||e.stencil&&t.stencil)return;t.stencil=!0;const i=t.width,s=t.height,r=this.gl,n=e.stencil=r.createRenderbuffer();let o,a;r.bindRenderbuffer(r.RENDERBUFFER,n),1===this.renderer.context.webGLVersion?(o=r.DEPTH_STENCIL_ATTACHMENT,a=r.DEPTH_STENCIL):t.depth?(o=r.DEPTH_STENCIL_ATTACHMENT,a=r.DEPTH24_STENCIL8):(o=r.STENCIL_ATTACHMENT,a=r.STENCIL_INDEX8),e.msaaBuffer?r.renderbufferStorageMultisample(r.RENDERBUFFER,e.multisample,a,i,s):r.renderbufferStorage(r.RENDERBUFFER,a,i,s),r.framebufferRenderbuffer(r.FRAMEBUFFER,o,r.RENDERBUFFER,n)}reset(){this.current=this.unknownFramebuffer,this.viewport=new Vf}destroy(){this.renderer=null}}cg.extension={type:gf.RendererSystem,name:"framebuffer"},xf.add(cg);const dg={5126:4,5123:2,5121:1};class pg{constructor(t){this.renderer=t,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this.canUseUInt32ElementIndex=!1,this.managedGeometries={}}contextChange(){this.disposeAll(!0);const t=this.gl=this.renderer.gl,e=this.renderer.context;if(this.CONTEXT_UID=this.renderer.CONTEXT_UID,2!==e.webGLVersion){let e=this.renderer.context.extensions.vertexArrayObject;lh.PREFER_ENV===Hl.WEBGL_LEGACY&&(e=null),e?(t.createVertexArray=()=>e.createVertexArrayOES(),t.bindVertexArray=t=>e.bindVertexArrayOES(t),t.deleteVertexArray=t=>e.deleteVertexArrayOES(t)):(this.hasVao=!1,t.createVertexArray=()=>null,t.bindVertexArray=()=>null,t.deleteVertexArray=()=>null)}if(2!==e.webGLVersion){const e=t.getExtension("ANGLE_instanced_arrays");e?(t.vertexAttribDivisor=(t,i)=>e.vertexAttribDivisorANGLE(t,i),t.drawElementsInstanced=(t,i,s,r,n)=>e.drawElementsInstancedANGLE(t,i,s,r,n),t.drawArraysInstanced=(t,i,s,r)=>e.drawArraysInstancedANGLE(t,i,s,r)):this.hasInstance=!1}this.canUseUInt32ElementIndex=2===e.webGLVersion||!!e.extensions.uint32ElementIndex}bind(t,e){e=e||this.renderer.shader.shader;const{gl:i}=this;let s=t.glVertexArrayObjects[this.CONTEXT_UID],r=!1;s||(this.managedGeometries[t.id]=t,t.disposeRunner.add(this),t.glVertexArrayObjects[this.CONTEXT_UID]=s={},r=!0);const n=s[e.program.id]||this.initGeometryVao(t,e,r);this._activeGeometry=t,this._activeVao!==n&&(this._activeVao=n,this.hasVao?i.bindVertexArray(n):this.activateVao(t,e.program)),this.updateBuffers()}reset(){this.unbind()}updateBuffers(){const t=this._activeGeometry,e=this.renderer.buffer;for(let i=0;i<t.buffers.length;i++){const s=t.buffers[i];e.update(s)}}checkCompatibility(t,e){const i=t.attributes,s=e.attributeData;for(const r in s)if(!i[r])throw new Error(`shader and geometry incompatible, geometry missing the "${r}" attribute`)}getSignature(t,e){const i=t.attributes,s=e.attributeData,r=["g",t.id];for(const n in i)s[n]&&r.push(n,s[n].location);return r.join("-")}initGeometryVao(t,e,i=!0){const s=this.gl,r=this.CONTEXT_UID,n=this.renderer.buffer,o=e.program;o.glPrograms[r]||this.renderer.shader.generateProgram(e),this.checkCompatibility(t,o);const a=this.getSignature(t,o),l=t.glVertexArrayObjects[this.CONTEXT_UID];let h=l[a];if(h)return l[o.id]=h,h;const u=t.buffers,c=t.attributes,d={},p={};for(const f in u)d[f]=0,p[f]=0;for(const f in c)!c[f].size&&o.attributeData[f]?c[f].size=o.attributeData[f].size:c[f].size||console.warn(`PIXI Geometry attribute '${f}' size cannot be determined (likely the bound shader does not have the attribute)`),d[c[f].buffer]+=c[f].size*dg[c[f].type];for(const f in c){const t=c[f],e=t.size;void 0===t.stride&&(d[t.buffer]===e*dg[t.type]?t.stride=0:t.stride=d[t.buffer]),void 0===t.start&&(t.start=p[t.buffer],p[t.buffer]+=e*dg[t.type])}h=s.createVertexArray(),s.bindVertexArray(h);for(let f=0;f<u.length;f++){const t=u[f];n.bind(t),i&&t._glBuffers[r].refCount++}return this.activateVao(t,o),l[o.id]=h,l[a]=h,s.bindVertexArray(null),n.unbind(ah.ARRAY_BUFFER),h}disposeGeometry(t,e){var i;if(!this.managedGeometries[t.id])return;delete this.managedGeometries[t.id];const s=t.glVertexArrayObjects[this.CONTEXT_UID],r=this.gl,n=t.buffers,o=null==(i=this.renderer)?void 0:i.buffer;if(t.disposeRunner.remove(this),s){if(o)for(let t=0;t<n.length;t++){const i=n[t]._glBuffers[this.CONTEXT_UID];i&&(i.refCount--,0===i.refCount&&!e&&o.dispose(n[t],e))}if(!e)for(const t in s)if("g"===t[0]){const e=s[t];this._activeVao===e&&this.unbind(),r.deleteVertexArray(e)}delete t.glVertexArrayObjects[this.CONTEXT_UID]}}disposeAll(t){const e=Object.keys(this.managedGeometries);for(let i=0;i<e.length;i++)this.disposeGeometry(this.managedGeometries[e[i]],t)}activateVao(t,e){const i=this.gl,s=this.CONTEXT_UID,r=this.renderer.buffer,n=t.buffers,o=t.attributes;t.indexBuffer&&r.bind(t.indexBuffer);let a=null;for(const l in o){const t=o[l],h=n[t.buffer],u=h._glBuffers[s];if(e.attributeData[l]){a!==u&&(r.bind(h),a=u);const s=e.attributeData[l].location;if(i.enableVertexAttribArray(s),i.vertexAttribPointer(s,t.size,t.type||i.FLOAT,t.normalized,t.stride,t.start),t.instance){if(!this.hasInstance)throw new Error("geometry error, GPU Instancing is not supported on this device");i.vertexAttribDivisor(s,t.divisor)}}}}draw(t,e,i,s){const{gl:r}=this,n=this._activeGeometry;if(n.indexBuffer){const o=n.indexBuffer.data.BYTES_PER_ELEMENT,a=2===o?r.UNSIGNED_SHORT:r.UNSIGNED_INT;2===o||4===o&&this.canUseUInt32ElementIndex?n.instanced?r.drawElementsInstanced(t,e||n.indexBuffer.data.length,a,(i||0)*o,s||1):r.drawElements(t,e||n.indexBuffer.data.length,a,(i||0)*o):console.warn("unsupported index buffer type: uint32")}else n.instanced?r.drawArraysInstanced(t,i,e||n.getSize(),s||1):r.drawArrays(t,i,e||n.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this.renderer=null}}pg.extension={type:gf.RendererSystem,name:"geometry"},xf.add(pg);const fg=new Qf;class mg{constructor(t,e){this._texture=t,this.mapCoord=new Qf,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,this.clampMargin=typeof e>"u"?.5:e,this.isSimple=!1}get texture(){return this._texture}set texture(t){this._texture=t,this._textureID=-1}multiplyUvs(t,e){void 0===e&&(e=t);const i=this.mapCoord;for(let s=0;s<t.length;s+=2){const r=t[s],n=t[s+1];e[s]=r*i.a+n*i.c+i.tx,e[s+1]=r*i.b+n*i.d+i.ty}return e}update(t){const e=this._texture;if(!e||!e.valid||!t&&this._textureID===e._updateID)return!1;this._textureID=e._updateID,this._updateID++;const i=e._uvs;this.mapCoord.set(i.x1-i.x0,i.y1-i.y0,i.x3-i.x0,i.y3-i.y0,i.x0,i.y0);const s=e.orig,r=e.trim;r&&(fg.set(s.width/r.width,0,0,s.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(fg));const n=e.baseTexture,o=this.uClampFrame,a=this.clampMargin/n.resolution,l=this.clampOffset;return o[0]=(e._frame.x+a+l)/n.width,o[1]=(e._frame.y+a+l)/n.height,o[2]=(e._frame.x+e._frame.width-a+l)/n.width,o[3]=(e._frame.y+e._frame.height-a+l)/n.height,this.uClampOffset[0]=l/n.realWidth,this.uClampOffset[1]=l/n.realHeight,this.isSimple=e._frame.width===n.width&&e._frame.height===n.height&&0===e.rotate,!0}}class gg extends Wm{constructor(t,e,i){let s=null;"string"!=typeof t&&void 0===e&&void 0===i&&(s=t,t=void 0,e=void 0,i=void 0),super(t||"attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 otherMatrix;\n\nvarying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vMaskCoord = ( otherMatrix * vec3( aTextureCoord, 1.0) ).xy;\n}\n",e||"varying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform sampler2D mask;\nuniform float alpha;\nuniform float npmAlpha;\nuniform vec4 maskClamp;\n\nvoid main(void)\n{\n float clip = step(3.5,\n step(maskClamp.x, vMaskCoord.x) +\n step(maskClamp.y, vMaskCoord.y) +\n step(vMaskCoord.x, maskClamp.z) +\n step(vMaskCoord.y, maskClamp.w));\n\n vec4 original = texture2D(uSampler, vTextureCoord);\n vec4 masky = texture2D(mask, vMaskCoord);\n float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);\n\n original *= (alphaMul * masky.r * alpha * clip);\n\n gl_FragColor = original;\n}\n",i),this.maskSprite=s,this.maskMatrix=new Qf}get maskSprite(){return this._maskSprite}set maskSprite(t){this._maskSprite=t,this._maskSprite&&(this._maskSprite.renderable=!1)}apply(t,e,i,s){const r=this._maskSprite,n=r._texture;n.valid&&(n.uvMatrix||(n.uvMatrix=new mg(n,0)),n.uvMatrix.update(),this.uniforms.npmAlpha=n.baseTexture.alphaMode?0:1,this.uniforms.mask=n,this.uniforms.otherMatrix=t.calculateSpriteMatrix(this.maskMatrix,r).prepend(n.uvMatrix.mapCoord),this.uniforms.alpha=r.worldAlpha,this.uniforms.maskClamp=n.uvMatrix.uClampFrame,t.applyFilter(this,e,i,s))}}class yg{constructor(t=null){this.type=nh.NONE,this.autoDetect=!0,this.maskObject=t||null,this.pooled=!1,this.isMaskData=!0,this.resolution=null,this.multisample=Wm.defaultMultisample,this.enabled=!0,this.colorMask=15,this._filters=null,this._stencilCounter=0,this._scissorCounter=0,this._scissorRect=null,this._scissorRectLocal=null,this._colorMask=15,this._target=null}get filter(){return this._filters?this._filters[0]:null}set filter(t){t?this._filters?this._filters[0]=t:this._filters=[t]:this._filters=null}reset(){this.pooled&&(this.maskObject=null,this.type=nh.NONE,this.autoDetect=!0),this._target=null,this._scissorRectLocal=null}copyCountersOrReset(t){t?(this._stencilCounter=t._stencilCounter,this._scissorCounter=t._scissorCounter,this._scissorRect=t._scissorRect):(this._stencilCounter=0,this._scissorCounter=0,this._scissorRect=null)}}class vg{constructor(t){this.renderer=t,this.enableScissor=!0,this.alphaMaskPool=[],this.maskDataPool=[],this.maskStack=[],this.alphaMaskIndex=0}setMaskStack(t){this.maskStack=t,this.renderer.scissor.setMaskStack(t),this.renderer.stencil.setMaskStack(t)}push(t,e){let i=e;if(!i.isMaskData){const t=this.maskDataPool.pop()||new yg;t.pooled=!0,t.maskObject=e,i=t}const s=0!==this.maskStack.length?this.maskStack[this.maskStack.length-1]:null;if(i.copyCountersOrReset(s),i._colorMask=s?s._colorMask:15,i.autoDetect&&this.detect(i),i._target=t,i.type!==nh.SPRITE&&this.maskStack.push(i),i.enabled)switch(i.type){case nh.SCISSOR:this.renderer.scissor.push(i);break;case nh.STENCIL:this.renderer.stencil.push(i);break;case nh.SPRITE:i.copyCountersOrReset(null),this.pushSpriteMask(i);break;case nh.COLOR:this.pushColorMask(i)}i.type===nh.SPRITE&&this.maskStack.push(i)}pop(t){const e=this.maskStack.pop();if(e&&e._target===t){if(e.enabled)switch(e.type){case nh.SCISSOR:this.renderer.scissor.pop(e);break;case nh.STENCIL:this.renderer.stencil.pop(e.maskObject);break;case nh.SPRITE:this.popSpriteMask(e);break;case nh.COLOR:this.popColorMask(e)}if(e.reset(),e.pooled&&this.maskDataPool.push(e),0!==this.maskStack.length){const t=this.maskStack[this.maskStack.length-1];t.type===nh.SPRITE&&t._filters&&(t._filters[0].maskSprite=t.maskObject)}}}detect(t){const e=t.maskObject;e?e.isSprite?t.type=nh.SPRITE:this.enableScissor&&this.renderer.scissor.testScissor(t)?t.type=nh.SCISSOR:t.type=nh.STENCIL:t.type=nh.COLOR}pushSpriteMask(t){const{maskObject:e}=t,i=t._target;let s=t._filters;s||(s=this.alphaMaskPool[this.alphaMaskIndex],s||(s=this.alphaMaskPool[this.alphaMaskIndex]=[new gg])),s[0].resolution=t.resolution,s[0].multisample=t.multisample,s[0].maskSprite=e;const r=i.filterArea;i.filterArea=e.getBounds(!0),this.renderer.filter.push(i,s),i.filterArea=r,t._filters||this.alphaMaskIndex++}popSpriteMask(t){this.renderer.filter.pop(),t._filters?t._filters[0].maskSprite=null:(this.alphaMaskIndex--,this.alphaMaskPool[this.alphaMaskIndex][0].maskSprite=null)}pushColorMask(t){const e=t._colorMask,i=t._colorMask=e&t.colorMask;i!==e&&this.renderer.gl.colorMask(!!(1&i),!!(2&i),!!(4&i),!!(8&i))}popColorMask(t){const e=t._colorMask,i=this.maskStack.length>0?this.maskStack[this.maskStack.length-1]._colorMask:15;i!==e&&this.renderer.gl.colorMask(!!(1&i),!!(2&i),!!(4&i),!!(8&i))}destroy(){this.renderer=null}}vg.extension={type:gf.RendererSystem,name:"mask"},xf.add(vg);class xg{constructor(t){this.renderer=t,this.maskStack=[],this.glConst=0}getStackLength(){return this.maskStack.length}setMaskStack(t){const{gl:e}=this.renderer,i=this.getStackLength();this.maskStack=t;const s=this.getStackLength();s!==i&&(0===s?e.disable(this.glConst):(e.enable(this.glConst),this._useCurrent()))}_useCurrent(){}destroy(){this.renderer=null,this.maskStack=null}}const bg=new Qf,_g=[],wg=class t extends xg{constructor(t){super(t),this.glConst=lh.ADAPTER.getWebGLRenderingContext().SCISSOR_TEST}getStackLength(){const t=this.maskStack[this.maskStack.length-1];return t?t._scissorCounter:0}calcScissorRect(t){if(t._scissorRectLocal)return;const e=t._scissorRect,{maskObject:i}=t,{renderer:s}=this,r=s.renderTexture,n=i.getBounds(!0,_g.pop()??new Vf);this.roundFrameToPixels(n,r.current?r.current.resolution:s.resolution,r.sourceFrame,r.destinationFrame,s.projection.transform),e&&n.fit(e),t._scissorRectLocal=n}static isMatrixRotated(t){if(!t)return!1;const{a:e,b:i,c:s,d:r}=t;return(Math.abs(i)>1e-4||Math.abs(s)>1e-4)&&(Math.abs(e)>1e-4||Math.abs(r)>1e-4)}testScissor(e){const{maskObject:i}=e;if(!i.isFastRect||!i.isFastRect()||t.isMatrixRotated(i.worldTransform)||t.isMatrixRotated(this.renderer.projection.transform))return!1;this.calcScissorRect(e);const s=e._scissorRectLocal;return s.width>0&&s.height>0}roundFrameToPixels(e,i,s,r,n){t.isMatrixRotated(n)||((n=n?bg.copyFrom(n):bg.identity()).translate(-s.x,-s.y).scale(r.width/s.width,r.height/s.height).translate(r.x,r.y),this.renderer.filter.transformAABB(n,e),e.fit(r),e.x=Math.round(e.x*i),e.y=Math.round(e.y*i),e.width=Math.round(e.width*i),e.height=Math.round(e.height*i))}push(t){t._scissorRectLocal||this.calcScissorRect(t);const{gl:e}=this.renderer;t._scissorRect||e.enable(e.SCISSOR_TEST),t._scissorCounter++,t._scissorRect=t._scissorRectLocal,this._useCurrent()}pop(t){const{gl:e}=this.renderer;t&&_g.push(t._scissorRectLocal),this.getStackLength()>0?this._useCurrent():e.disable(e.SCISSOR_TEST)}_useCurrent(){const t=this.maskStack[this.maskStack.length-1]._scissorRect;let e;e=this.renderer.renderTexture.current?t.y:this.renderer.height-t.height-t.y,this.renderer.gl.scissor(t.x,e,t.width,t.height)}};wg.extension={type:gf.RendererSystem,name:"scissor"};let Pg=wg;xf.add(Pg);class Eg extends xg{constructor(t){super(t),this.glConst=lh.ADAPTER.getWebGLRenderingContext().STENCIL_TEST}getStackLength(){const t=this.maskStack[this.maskStack.length-1];return t?t._stencilCounter:0}push(t){const e=t.maskObject,{gl:i}=this.renderer,s=t._stencilCounter;0===s&&(this.renderer.framebuffer.forceStencil(),i.clearStencil(0),i.clear(i.STENCIL_BUFFER_BIT),i.enable(i.STENCIL_TEST)),t._stencilCounter++;const r=t._colorMask;0!==r&&(t._colorMask=0,i.colorMask(!1,!1,!1,!1)),i.stencilFunc(i.EQUAL,s,4294967295),i.stencilOp(i.KEEP,i.KEEP,i.INCR),e.renderable=!0,e.render(this.renderer),this.renderer.batch.flush(),e.renderable=!1,0!==r&&(t._colorMask=r,i.colorMask(!!(1&r),!!(2&r),!!(4&r),!!(8&r))),this._useCurrent()}pop(t){const e=this.renderer.gl;if(0===this.getStackLength())e.disable(e.STENCIL_TEST);else{const i=0!==this.maskStack.length?this.maskStack[this.maskStack.length-1]:null,s=i?i._colorMask:15;0!==s&&(i._colorMask=0,e.colorMask(!1,!1,!1,!1)),e.stencilOp(e.KEEP,e.KEEP,e.DECR),t.renderable=!0,t.render(this.renderer),this.renderer.batch.flush(),t.renderable=!1,0!==s&&(i._colorMask=s,e.colorMask(!!(1&s),!!(2&s),!!(4&s),!!(8&s))),this._useCurrent()}}_useCurrent(){const t=this.renderer.gl;t.stencilFunc(t.EQUAL,this.getStackLength(),4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP)}}Eg.extension={type:gf.RendererSystem,name:"stencil"},xf.add(Eg);class Tg{constructor(t){this.renderer=t,this.plugins={},Object.defineProperties(this.plugins,{extract:{enumerable:!1,get:()=>(op("7.0.0","renderer.plugins.extract has moved to renderer.extract"),t.extract)},prepare:{enumerable:!1,get:()=>(op("7.0.0","renderer.plugins.prepare has moved to renderer.prepare"),t.prepare)},interaction:{enumerable:!1,get:()=>(op("7.0.0","renderer.plugins.interaction has been deprecated, use renderer.events"),t.events)}})}init(){const t=this.rendererPlugins;for(const e in t)this.plugins[e]=new t[e](this.renderer)}destroy(){for(const t in this.plugins)this.plugins[t].destroy(),this.plugins[t]=null}}Tg.extension={type:[gf.RendererSystem,gf.CanvasRendererSystem],name:"_plugin"},xf.add(Tg);class Ag{constructor(t){this.renderer=t,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new Qf,this.transform=null}update(t,e,i,s){this.destinationFrame=t||this.destinationFrame||this.defaultFrame,this.sourceFrame=e||this.sourceFrame||t,this.calculateProjection(this.destinationFrame,this.sourceFrame,i,s),this.transform&&this.projectionMatrix.append(this.transform);const r=this.renderer;r.globalUniforms.uniforms.projectionMatrix=this.projectionMatrix,r.globalUniforms.update(),r.shader.shader&&r.shader.syncUniformGroup(r.shader.shader.uniforms.globals)}calculateProjection(t,e,i,s){const r=this.projectionMatrix,n=s?-1:1;r.identity(),r.a=1/e.width*2,r.d=n*(1/e.height*2),r.tx=-1-e.x*r.a,r.ty=-n-e.y*r.d}setTransform(t){}destroy(){this.renderer=null}}Ag.extension={type:gf.RendererSystem,name:"projection"},xf.add(Ag);const Ig=new um,Sg=new Vf;class Cg{constructor(t){this.renderer=t,this._tempMatrix=new Qf}generateTexture(t,e){const{region:i,...s}=e||{},r=(null==i?void 0:i.copyTo(Sg))||t.getLocalBounds(Sg,!0),n=s.resolution||this.renderer.resolution;r.width=Math.max(r.width,1/n),r.height=Math.max(r.height,1/n),s.width=r.width,s.height=r.height,s.resolution=n,s.multisample??(s.multisample=this.renderer.multisample);const o=eg.create(s);this._tempMatrix.tx=-r.x,this._tempMatrix.ty=-r.y;const a=t.transform;return t.transform=Ig,this.renderer.render(t,{renderTexture:o,transform:this._tempMatrix,skipUpdateTransform:!!t.parent,blit:!0}),t.transform=a,o}destroy(){}}Cg.extension={type:[gf.RendererSystem,gf.CanvasRendererSystem],name:"textureGenerator"},xf.add(Cg);const Mg=new Vf,Og=new Vf;class Ng{constructor(t){this.renderer=t,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new Vf,this.destinationFrame=new Vf,this.viewportFrame=new Vf}contextChange(){var t;const e=null==(t=this.renderer)?void 0:t.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(e&&e.alpha&&e.premultipliedAlpha)}bind(t=null,e,i){const s=this.renderer;let r,n,o;this.current=t,t?(r=t.baseTexture,o=r.resolution,e||(Mg.width=t.frame.width,Mg.height=t.frame.height,e=Mg),i||(Og.x=t.frame.x,Og.y=t.frame.y,Og.width=e.width,Og.height=e.height,i=Og),n=r.framebuffer):(o=s.resolution,e||(Mg.width=s._view.screen.width,Mg.height=s._view.screen.height,e=Mg),i||((i=Mg).width=e.width,i.height=e.height));const a=this.viewportFrame;a.x=i.x*o,a.y=i.y*o,a.width=i.width*o,a.height=i.height*o,t||(a.y=s.view.height-(a.y+a.height)),a.ceil(),this.renderer.framebuffer.bind(n,a),this.renderer.projection.update(i,e,o,!n),t?this.renderer.mask.setMaskStack(r.maskStack):this.renderer.mask.setMaskStack(this.defaultMaskStack),this.sourceFrame.copyFrom(e),this.destinationFrame.copyFrom(i)}clear(t,e){const i=this.current?this.current.baseTexture.clear:this.renderer.background.backgroundColor,s=Hp.shared.setValue(t||i);(this.current&&this.current.baseTexture.alphaMode>0||!this.current&&this._rendererPremultipliedAlpha)&&s.premultiply(s.alpha);const r=this.destinationFrame,n=this.current?this.current.baseTexture:this.renderer._view.screen,o=r.width!==n.width||r.height!==n.height;if(o){let{x:t,y:e,width:i,height:s}=this.viewportFrame;t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s),this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST),this.renderer.gl.scissor(t,e,i,s)}this.renderer.framebuffer.clear(s.red,s.green,s.blue,s.alpha,e),o&&this.renderer.scissor.pop()}resize(){this.bind(null)}reset(){this.bind(null)}destroy(){this.renderer=null}}Ng.extension={type:gf.RendererSystem,name:"renderTexture"},xf.add(Ng);class Lg{constructor(t,e){this.program=t,this.uniformData=e,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBufferBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBufferBindings=null,this.program=null}}function Rg(t,e){var i;const s=cm(t,t.VERTEX_SHADER,e.vertexSrc),r=cm(t,t.FRAGMENT_SHADER,e.fragmentSrc),n=t.createProgram();t.attachShader(n,s),t.attachShader(n,r);const o=null==(i=e.extra)?void 0:i.transformFeedbackVaryings;if(o&&("function"!=typeof t.transformFeedbackVaryings?console.warn("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(n,o.names,"separate"===o.bufferMode?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(n),t.getProgramParameter(n,t.LINK_STATUS)||function(t,e,i,s){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(i,t.COMPILE_STATUS)||_m(t,i),t.getShaderParameter(s,t.COMPILE_STATUS)||_m(t,s),console.error("PixiJS Error: Could not initialize shader."),""!==t.getProgramInfoLog(e)&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}(t,n,s,r),e.attributeData=function(t,e){const i={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r<s;r++){const s=e.getActiveAttrib(t,r);if(s.name.startsWith("gl_"))continue;const n=Am(e,s.type),o={type:n,name:s.name,size:Pm(n),location:e.getAttribLocation(t,s.name)};i[s.name]=o}return i}(n,t),e.uniformData=function(t,e){const i={},s=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){const s=e.getActiveUniform(t,r),n=s.name.replace(/\[.*?\]$/,""),o=!!s.name.match(/\[.*?\]$/),a=Am(e,s.type);i[n]={name:n,index:r,type:a,size:s.size,isArray:o,value:pm(a,s.size)}}return i}(n,t),!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertexSrc)){const i=Object.keys(e.attributeData);i.sort(((t,e)=>t>e?1:-1));for(let s=0;s<i.length;s++)e.attributeData[i[s]].location=s,t.bindAttribLocation(n,s,i[s]);t.linkProgram(n)}t.deleteShader(s),t.deleteShader(r);const a={};for(const l in e.uniformData){const i=e.uniformData[l];a[l]={location:t.getUniformLocation(n,l),value:pm(i.type,i.size)}}return new Lg(n,a)}function kg(t,e,i,s,r){i.buffer.update(r)}const Bg={float:"\n data[offset] = v;\n ",vec2:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n ",vec3:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n\n ",vec4:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n data[offset+3] = v[3];\n ",mat2:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n\n data[offset+4] = v[2];\n data[offset+5] = v[3];\n ",mat3:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n\n data[offset + 4] = v[3];\n data[offset + 5] = v[4];\n data[offset + 6] = v[5];\n\n data[offset + 8] = v[6];\n data[offset + 9] = v[7];\n data[offset + 10] = v[8];\n ",mat4:"\n for(var i = 0; i < 16; i++)\n {\n data[offset + i] = v[i];\n }\n "},Fg={float:4,vec2:8,vec3:12,vec4:16,int:4,ivec2:8,ivec3:12,ivec4:16,uint:4,uvec2:8,uvec3:12,uvec4:16,bool:4,bvec2:8,bvec3:12,bvec4:16,mat2:32,mat3:48,mat4:64};function Dg(t,e){if(!t.autoManage)return{size:0,syncFunc:kg};const i=function(t,e){const i=[];for(const s in t)e[s]&&i.push(e[s]);return i.sort(((t,e)=>t.index-e.index)),i}(t.uniforms,e),{uboElements:s,size:r}=function(t){const e=t.map((t=>({data:t,offset:0,dataLen:0,dirty:0})));let i=0,s=0,r=0;for(let n=0;n<e.length;n++){const t=e[n];if(i=Fg[t.data.type],t.data.size>1&&(i=Math.max(i,16)*t.data.size),t.dataLen=i,s%i!=0&&s<16){const t=s%i%16;s+=t,r+=t}s+i>16?(r=16*Math.ceil(r/16),t.offset=r,r+=i,s=i):(t.offset=r,s+=i,r+=i)}return r=16*Math.ceil(r/16),{uboElements:e,size:r}}(i),n=["\n var v = null;\n var v2 = null;\n var cv = null;\n var t = 0;\n var gl = renderer.gl\n var index = 0;\n var data = buffer.data;\n "];for(let o=0;o<s.length;o++){const e=s[o],i=t.uniforms[e.data.name],r=e.data.name;let a=!1;for(let t=0;t<fm.length;t++){const s=fm[t];if(s.codeUbo&&s.test(e.data,i)){n.push(`offset = ${e.offset/4};`,fm[t].codeUbo(e.data.name,i)),a=!0;break}}if(!a)if(e.data.size>1){const t=Pm(e.data.type),i=Math.max(Fg[e.data.type]/16,1),s=t/i,o=(4-s%4)%4;n.push(`\n cv = ud.${r}.value;\n v = uv.${r};\n offset = ${e.offset/4};\n\n t = 0;\n\n for(var i=0; i < ${e.data.size*i}; i++)\n {\n for(var j = 0; j < ${s}; j++)\n {\n data[offset++] = v[t++];\n }\n offset += ${o};\n }\n\n `)}else{const t=Bg[e.data.type];n.push(`\n cv = ud.${r}.value;\n v = uv.${r};\n offset = ${e.offset/4};\n ${t};\n `)}}return n.push("\n renderer.buffer.update(buffer);\n "),{size:r,syncFunc:new Function("ud","uv","renderer","syncData","buffer",n.join("\n"))}}let Ug=0;const Gg={textureCount:0,uboCount:0};class Xg{constructor(t){this.destroyed=!1,this.renderer=t,this.systemCheck(),this.gl=null,this.shader=null,this.program=null,this.cache={},this._uboCache={},this.id=Ug++}systemCheck(){if(!function(){if("boolean"==typeof Sm)return Sm;try{Sm=!0===new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")}catch{Sm=!1}return Sm}())throw new Error("Current environment does not allow unsafe-eval, please use @pixi/unsafe-eval module to enable support.")}contextChange(t){this.gl=t,this.reset()}bind(t,e){t.disposeRunner.add(this),t.uniforms.globals=this.renderer.globalUniforms;const i=t.program,s=i.glPrograms[this.renderer.CONTEXT_UID]||this.generateProgram(t);return this.shader=t,this.program!==i&&(this.program=i,this.gl.useProgram(s.program)),e||(Gg.textureCount=0,Gg.uboCount=0,this.syncUniformGroup(t.uniformGroup,Gg)),s}setUniforms(t){const e=this.shader.program,i=e.glPrograms[this.renderer.CONTEXT_UID];e.syncUniforms(i.uniformData,t,this.renderer)}syncUniformGroup(t,e){const i=this.getGlProgram();(!t.static||t.dirtyId!==i.uniformDirtyGroups[t.id])&&(i.uniformDirtyGroups[t.id]=t.dirtyId,this.syncUniforms(t,i,e))}syncUniforms(t,e,i){(t.syncUniforms[this.shader.program.id]||this.createSyncGroups(t))(e.uniformData,t.uniforms,this.renderer,i)}createSyncGroups(t){const e=this.getSignature(t,this.shader.program.uniformData,"u");return this.cache[e]||(this.cache[e]=function(t,e){var i;const s=["\n var v = null;\n var cv = null;\n var cu = null;\n var t = 0;\n var gl = renderer.gl;\n "];for(const r in t.uniforms){const n=e[r];if(!n){!0===(null==(i=t.uniforms[r])?void 0:i.group)&&(t.uniforms[r].ubo?s.push(`\n renderer.shader.syncUniformBufferGroup(uv.${r}, '${r}');\n `):s.push(`\n renderer.shader.syncUniformGroup(uv.${r}, syncData);\n `));continue}const o=t.uniforms[r];let a=!1;for(let t=0;t<fm.length;t++)if(fm[t].test(n,o)){s.push(fm[t].code(r,o)),a=!0;break}if(!a){const t=(1!==n.size||n.isArray?gm:mm)[n.type].replace("location",`ud["${r}"].location`);s.push(`\n cu = ud["${r}"];\n cv = cu.value;\n v = uv["${r}"];\n ${t};`)}}return new Function("ud","uv","renderer","syncData",s.join("\n"))}(t,this.shader.program.uniformData)),t.syncUniforms[this.shader.program.id]=this.cache[e],t.syncUniforms[this.shader.program.id]}syncUniformBufferGroup(t,e){const i=this.getGlProgram();if(!t.static||0!==t.dirtyId||!i.uniformGroups[t.id]){t.dirtyId=0;const s=i.uniformGroups[t.id]||this.createSyncBufferGroup(t,i,e);t.buffer.update(),s(i.uniformData,t.uniforms,this.renderer,Gg,t.buffer)}this.renderer.buffer.bindBufferBase(t.buffer,i.uniformBufferBindings[e])}createSyncBufferGroup(t,e,i){const{gl:s}=this.renderer;this.renderer.buffer.bind(t.buffer);const r=this.gl.getUniformBlockIndex(e.program,i);e.uniformBufferBindings[i]=this.shader.uniformBindCount,s.uniformBlockBinding(e.program,r,this.shader.uniformBindCount),this.shader.uniformBindCount++;const n=this.getSignature(t,this.shader.program.uniformData,"ubo");let o=this._uboCache[n];if(o||(o=this._uboCache[n]=Dg(t,this.shader.program.uniformData)),t.autoManage){const e=new Float32Array(o.size/4);t.buffer.update(e)}return e.uniformGroups[t.id]=o.syncFunc,e.uniformGroups[t.id]}getSignature(t,e,i){const s=t.uniforms,r=[`${i}-`];for(const n in s)r.push(n),e[n]&&r.push(e[n].type);return r.join("-")}getGlProgram(){return this.shader?this.shader.program.glPrograms[this.renderer.CONTEXT_UID]:null}generateProgram(t){const e=this.gl,i=t.program,s=Rg(e,i);return i.glPrograms[this.renderer.CONTEXT_UID]=s,s}reset(){this.program=null,this.shader=null}disposeShader(t){this.shader===t&&(this.shader=null)}destroy(){this.renderer=null,this.destroyed=!0}}Xg.extension={type:gf.RendererSystem,name:"shader"},xf.add(Xg);class Wg{constructor(t){this.renderer=t}run(t){const{renderer:e}=this;e.runners.init.emit(e.options),t.hello&&console.log(`PixiJS 7.4.2 - ${e.rendererLogId} - https://pixijs.com`),e.resize(e.screen.width,e.screen.height)}destroy(){}}Wg.defaultOptions={hello:!1},Wg.extension={type:[gf.RendererSystem,gf.CanvasRendererSystem],name:"startup"},xf.add(Wg);const Hg=class t{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode=jl.NONE,this._blendEq=!1,this.map=[],this.map[0]=this.setBlend,this.map[1]=this.setOffset,this.map[2]=this.setCullFace,this.map[3]=this.setDepthTest,this.map[4]=this.setFrontFace,this.map[5]=this.setDepthMask,this.checks=[],this.defaultState=new Pf,this.defaultState.blend=!0}contextChange(t){this.gl=t,this.blendModes=function(t,e=[]){return e[jl.NORMAL]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.ADD]=[t.ONE,t.ONE],e[jl.MULTIPLY]=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SCREEN]=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.OVERLAY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.DARKEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.LIGHTEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.COLOR_DODGE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.COLOR_BURN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.HARD_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SOFT_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.DIFFERENCE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.EXCLUSION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.HUE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SATURATION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.COLOR]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.LUMINOSITY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.NONE]=[0,0],e[jl.NORMAL_NPM]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.ADD_NPM]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e[jl.SCREEN_NPM]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SRC_IN]=[t.DST_ALPHA,t.ZERO],e[jl.SRC_OUT]=[t.ONE_MINUS_DST_ALPHA,t.ZERO],e[jl.SRC_ATOP]=[t.DST_ALPHA,t.ONE_MINUS_SRC_ALPHA],e[jl.DST_OVER]=[t.ONE_MINUS_DST_ALPHA,t.ONE],e[jl.DST_IN]=[t.ZERO,t.SRC_ALPHA],e[jl.DST_OUT]=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],e[jl.DST_ATOP]=[t.ONE_MINUS_DST_ALPHA,t.SRC_ALPHA],e[jl.XOR]=[t.ONE_MINUS_DST_ALPHA,t.ONE_MINUS_SRC_ALPHA],e[jl.SUBTRACT]=[t.ONE,t.ONE,t.ONE,t.ONE,t.FUNC_REVERSE_SUBTRACT,t.FUNC_ADD],e}(t),this.set(this.defaultState),this.reset()}set(t){if(t=t||this.defaultState,this.stateId!==t.data){let e=this.stateId^t.data,i=0;for(;e;)1&e&&this.map[i].call(this,!!(t.data&1<<i)),e>>=1,i++;this.stateId=t.data}for(let e=0;e<this.checks.length;e++)this.checks[e](this,t)}forceState(t){t=t||this.defaultState;for(let e=0;e<this.map.length;e++)this.map[e].call(this,!!(t.data&1<<e));for(let e=0;e<this.checks.length;e++)this.checks[e](this,t);this.stateId=t.data}setBlend(e){this.updateCheck(t.checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this.updateCheck(t.checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(t){this.gl[t?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(t){this.gl.depthMask(t)}setCullFace(t){this.gl[t?"enable":"disable"](this.gl.CULL_FACE)}setFrontFace(t){this.gl.frontFace(this.gl[t?"CW":"CCW"])}setBlendMode(t){if(t===this.blendMode)return;this.blendMode=t;const e=this.blendModes[t],i=this.gl;2===e.length?i.blendFunc(e[0],e[1]):i.blendFuncSeparate(e[0],e[1],e[2],e[3]),6===e.length?(this._blendEq=!0,i.blendEquationSeparate(e[4],e[5])):this._blendEq&&(this._blendEq=!1,i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD))}setPolygonOffset(t,e){this.gl.polygonOffset(t,e)}reset(){this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode=-1,this.setBlendMode(0)}updateCheck(t,e){const i=this.checks.indexOf(t);e&&-1===i?this.checks.push(t):!e&&-1!==i&&this.checks.splice(i,1)}static checkBlendMode(t,e){t.setBlendMode(e.blendMode)}static checkPolygonOffset(t,e){t.setPolygonOffset(1,e.polygonOffset)}destroy(){this.gl=null}};Hg.extension={type:gf.RendererSystem,name:"state"};let Yg=Hg;xf.add(Yg);class $g extends Sh{constructor(){super(...arguments),this.runners={},this._systemsHash={}}setup(t){this.addRunners(...t.runners);const e=(t.priority??[]).filter((e=>t.systems[e])),i=[...e,...Object.keys(t.systems).filter((t=>!e.includes(t)))];for(const s of i)this.addSystem(t.systems[s],s)}addRunners(...t){t.forEach((t=>{this.runners[t]=new Af(t)}))}addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const s in this.runners)this.runners[s].add(i);return this}emitWithCustomOptions(t,e){const i=Object.keys(this._systemsHash);t.items.forEach((s=>{const r=i.find((t=>this._systemsHash[t]===s));s[t.name](e[r])}))}destroy(){Object.values(this.runners).forEach((t=>{t.destroy()})),this._systemsHash={}}}const jg=class t{constructor(e){this.renderer=e,this.count=0,this.checkCount=0,this.maxIdle=t.defaultMaxIdle,this.checkCountMax=t.defaultCheckCountMax,this.mode=t.defaultMode}postrender(){this.renderer.objectRenderer.renderingToScreen&&(this.count++,this.mode!==sh.MANUAL&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const t=this.renderer.texture,e=t.managedTextures;let i=!1;for(let s=0;s<e.length;s++){const r=e[s];r.resource&&this.count-r.touched>this.maxIdle&&(t.destroyTexture(r,!0),e[s]=null,i=!0)}if(i){let t=0;for(let i=0;i<e.length;i++)null!==e[i]&&(e[t++]=e[i]);e.length=t}}unload(t){const e=this.renderer.texture,i=t._texture;i&&!i.framebuffer&&e.destroyTexture(i);for(let s=t.children.length-1;s>=0;s--)this.unload(t.children[s])}destroy(){this.renderer=null}};jg.defaultMode=sh.AUTO,jg.defaultMaxIdle=3600,jg.defaultCheckCountMax=600,jg.extension={type:gf.RendererSystem,name:"textureGC"};let zg=jg;xf.add(zg);class Vg{constructor(t){this.texture=t,this.width=-1,this.height=-1,this.dirtyId=-1,this.dirtyStyleId=-1,this.mipmap=!1,this.wrapMode=33071,this.type=Jl.UNSIGNED_BYTE,this.internalFormat=Vl.RGBA,this.samplerType=0}}class qg{constructor(t){this.renderer=t,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new Of,this.hasIntegerTextures=!1}contextChange(){const t=this.gl=this.renderer.gl;this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.webGLVersion=this.renderer.context.webGLVersion,this.internalFormats=function(t){let e;return e="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext?{[Jl.UNSIGNED_BYTE]:{[Vl.RGBA]:t.RGBA8,[Vl.RGB]:t.RGB8,[Vl.RG]:t.RG8,[Vl.RED]:t.R8,[Vl.RGBA_INTEGER]:t.RGBA8UI,[Vl.RGB_INTEGER]:t.RGB8UI,[Vl.RG_INTEGER]:t.RG8UI,[Vl.RED_INTEGER]:t.R8UI,[Vl.ALPHA]:t.ALPHA,[Vl.LUMINANCE]:t.LUMINANCE,[Vl.LUMINANCE_ALPHA]:t.LUMINANCE_ALPHA},[Jl.BYTE]:{[Vl.RGBA]:t.RGBA8_SNORM,[Vl.RGB]:t.RGB8_SNORM,[Vl.RG]:t.RG8_SNORM,[Vl.RED]:t.R8_SNORM,[Vl.RGBA_INTEGER]:t.RGBA8I,[Vl.RGB_INTEGER]:t.RGB8I,[Vl.RG_INTEGER]:t.RG8I,[Vl.RED_INTEGER]:t.R8I},[Jl.UNSIGNED_SHORT]:{[Vl.RGBA_INTEGER]:t.RGBA16UI,[Vl.RGB_INTEGER]:t.RGB16UI,[Vl.RG_INTEGER]:t.RG16UI,[Vl.RED_INTEGER]:t.R16UI,[Vl.DEPTH_COMPONENT]:t.DEPTH_COMPONENT16},[Jl.SHORT]:{[Vl.RGBA_INTEGER]:t.RGBA16I,[Vl.RGB_INTEGER]:t.RGB16I,[Vl.RG_INTEGER]:t.RG16I,[Vl.RED_INTEGER]:t.R16I},[Jl.UNSIGNED_INT]:{[Vl.RGBA_INTEGER]:t.RGBA32UI,[Vl.RGB_INTEGER]:t.RGB32UI,[Vl.RG_INTEGER]:t.RG32UI,[Vl.RED_INTEGER]:t.R32UI,[Vl.DEPTH_COMPONENT]:t.DEPTH_COMPONENT24},[Jl.INT]:{[Vl.RGBA_INTEGER]:t.RGBA32I,[Vl.RGB_INTEGER]:t.RGB32I,[Vl.RG_INTEGER]:t.RG32I,[Vl.RED_INTEGER]:t.R32I},[Jl.FLOAT]:{[Vl.RGBA]:t.RGBA32F,[Vl.RGB]:t.RGB32F,[Vl.RG]:t.RG32F,[Vl.RED]:t.R32F,[Vl.DEPTH_COMPONENT]:t.DEPTH_COMPONENT32F},[Jl.HALF_FLOAT]:{[Vl.RGBA]:t.RGBA16F,[Vl.RGB]:t.RGB16F,[Vl.RG]:t.RG16F,[Vl.RED]:t.R16F},[Jl.UNSIGNED_SHORT_5_6_5]:{[Vl.RGB]:t.RGB565},[Jl.UNSIGNED_SHORT_4_4_4_4]:{[Vl.RGBA]:t.RGBA4},[Jl.UNSIGNED_SHORT_5_5_5_1]:{[Vl.RGBA]:t.RGB5_A1},[Jl.UNSIGNED_INT_2_10_10_10_REV]:{[Vl.RGBA]:t.RGB10_A2,[Vl.RGBA_INTEGER]:t.RGB10_A2UI},[Jl.UNSIGNED_INT_10F_11F_11F_REV]:{[Vl.RGB]:t.R11F_G11F_B10F},[Jl.UNSIGNED_INT_5_9_9_9_REV]:{[Vl.RGB]:t.RGB9_E5},[Jl.UNSIGNED_INT_24_8]:{[Vl.DEPTH_STENCIL]:t.DEPTH24_STENCIL8},[Jl.FLOAT_32_UNSIGNED_INT_24_8_REV]:{[Vl.DEPTH_STENCIL]:t.DEPTH32F_STENCIL8}}:{[Jl.UNSIGNED_BYTE]:{[Vl.RGBA]:t.RGBA,[Vl.RGB]:t.RGB,[Vl.ALPHA]:t.ALPHA,[Vl.LUMINANCE]:t.LUMINANCE,[Vl.LUMINANCE_ALPHA]:t.LUMINANCE_ALPHA},[Jl.UNSIGNED_SHORT_5_6_5]:{[Vl.RGB]:t.RGB},[Jl.UNSIGNED_SHORT_4_4_4_4]:{[Vl.RGBA]:t.RGBA},[Jl.UNSIGNED_SHORT_5_5_5_1]:{[Vl.RGBA]:t.RGBA}},e}(t),this.samplerTypes=function(t){let e;return e="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext?{[t.RGB]:Kl.FLOAT,[t.RGBA]:Kl.FLOAT,[t.ALPHA]:Kl.FLOAT,[t.LUMINANCE]:Kl.FLOAT,[t.LUMINANCE_ALPHA]:Kl.FLOAT,[t.R8]:Kl.FLOAT,[t.R8_SNORM]:Kl.FLOAT,[t.RG8]:Kl.FLOAT,[t.RG8_SNORM]:Kl.FLOAT,[t.RGB8]:Kl.FLOAT,[t.RGB8_SNORM]:Kl.FLOAT,[t.RGB565]:Kl.FLOAT,[t.RGBA4]:Kl.FLOAT,[t.RGB5_A1]:Kl.FLOAT,[t.RGBA8]:Kl.FLOAT,[t.RGBA8_SNORM]:Kl.FLOAT,[t.RGB10_A2]:Kl.FLOAT,[t.RGB10_A2UI]:Kl.FLOAT,[t.SRGB8]:Kl.FLOAT,[t.SRGB8_ALPHA8]:Kl.FLOAT,[t.R16F]:Kl.FLOAT,[t.RG16F]:Kl.FLOAT,[t.RGB16F]:Kl.FLOAT,[t.RGBA16F]:Kl.FLOAT,[t.R32F]:Kl.FLOAT,[t.RG32F]:Kl.FLOAT,[t.RGB32F]:Kl.FLOAT,[t.RGBA32F]:Kl.FLOAT,[t.R11F_G11F_B10F]:Kl.FLOAT,[t.RGB9_E5]:Kl.FLOAT,[t.R8I]:Kl.INT,[t.R8UI]:Kl.UINT,[t.R16I]:Kl.INT,[t.R16UI]:Kl.UINT,[t.R32I]:Kl.INT,[t.R32UI]:Kl.UINT,[t.RG8I]:Kl.INT,[t.RG8UI]:Kl.UINT,[t.RG16I]:Kl.INT,[t.RG16UI]:Kl.UINT,[t.RG32I]:Kl.INT,[t.RG32UI]:Kl.UINT,[t.RGB8I]:Kl.INT,[t.RGB8UI]:Kl.UINT,[t.RGB16I]:Kl.INT,[t.RGB16UI]:Kl.UINT,[t.RGB32I]:Kl.INT,[t.RGB32UI]:Kl.UINT,[t.RGBA8I]:Kl.INT,[t.RGBA8UI]:Kl.UINT,[t.RGBA16I]:Kl.INT,[t.RGBA16UI]:Kl.UINT,[t.RGBA32I]:Kl.INT,[t.RGBA32UI]:Kl.UINT,[t.DEPTH_COMPONENT16]:Kl.FLOAT,[t.DEPTH_COMPONENT24]:Kl.FLOAT,[t.DEPTH_COMPONENT32F]:Kl.FLOAT,[t.DEPTH_STENCIL]:Kl.FLOAT,[t.DEPTH24_STENCIL8]:Kl.FLOAT,[t.DEPTH32F_STENCIL8]:Kl.FLOAT}:{[t.RGB]:Kl.FLOAT,[t.RGBA]:Kl.FLOAT,[t.ALPHA]:Kl.FLOAT,[t.LUMINANCE]:Kl.FLOAT,[t.LUMINANCE_ALPHA]:Kl.FLOAT,[t.DEPTH_STENCIL]:Kl.FLOAT},e}(t);const e=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=e;for(let s=0;s<e;s++)this.boundTextures[s]=null;this.emptyTextures={};const i=new Vg(t.createTexture());t.bindTexture(t.TEXTURE_2D,i.texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array(4)),this.emptyTextures[t.TEXTURE_2D]=i,this.emptyTextures[t.TEXTURE_CUBE_MAP]=new Vg(t.createTexture()),t.bindTexture(t.TEXTURE_CUBE_MAP,this.emptyTextures[t.TEXTURE_CUBE_MAP].texture);for(let s=0;s<6;s++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+s,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,null);t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR);for(let s=0;s<this.boundTextures.length;s++)this.bind(null,s)}bind(t,e=0){const{gl:i}=this;if((null==(t=null==t?void 0:t.castToBaseTexture())?void 0:t.valid)&&!t.parentTextureArray){t.touched=this.renderer.textureGC.count;const s=t._glTextures[this.CONTEXT_UID]||this.initTexture(t);this.boundTextures[e]!==t&&(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(t.target,s.texture)),s.dirtyId!==t.dirtyId?(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),this.updateTexture(t)):s.dirtyStyleId!==t.dirtyStyleId&&this.updateTextureStyle(t),this.boundTextures[e]=t}else this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,this.emptyTextures[i.TEXTURE_2D].texture),this.boundTextures[e]=null}reset(){this._unknownBoundTextures=!0,this.hasIntegerTextures=!1,this.currentLocation=-1;for(let t=0;t<this.boundTextures.length;t++)this.boundTextures[t]=this.unknownTexture}unbind(t){const{gl:e,boundTextures:i}=this;if(this._unknownBoundTextures){this._unknownBoundTextures=!1;for(let t=0;t<i.length;t++)i[t]===this.unknownTexture&&this.bind(null,t)}for(let s=0;s<i.length;s++)i[s]===t&&(this.currentLocation!==s&&(e.activeTexture(e.TEXTURE0+s),this.currentLocation=s),e.bindTexture(t.target,this.emptyTextures[t.target].texture),i[s]=null)}ensureSamplerType(t){const{boundTextures:e,hasIntegerTextures:i,CONTEXT_UID:s}=this;if(i)for(let r=t-1;r>=0;--r){const t=e[r];t&&t._glTextures[s].samplerType!==Kl.FLOAT&&this.renderer.texture.unbind(t)}}initTexture(t){const e=new Vg(this.gl.createTexture());return e.dirtyId=-1,t._glTextures[this.CONTEXT_UID]=e,this.managedTextures.push(t),t.on("dispose",this.destroyTexture,this),e}initTextureType(t,e){var i;e.internalFormat=(null==(i=this.internalFormats[t.type])?void 0:i[t.format])??t.format,e.samplerType=this.samplerTypes[e.internalFormat]??Kl.FLOAT,2===this.webGLVersion&&t.type===Jl.HALF_FLOAT?e.type=this.gl.HALF_FLOAT:e.type=t.type}updateTexture(t){var e;const i=t._glTextures[this.CONTEXT_UID];if(!i)return;const s=this.renderer;if(this.initTextureType(t,i),null==(e=t.resource)?void 0:e.upload(s,t,i))i.samplerType!==Kl.FLOAT&&(this.hasIntegerTextures=!0);else{const e=t.realWidth,r=t.realHeight,n=s.gl;(i.width!==e||i.height!==r||i.dirtyId<0)&&(i.width=e,i.height=r,n.texImage2D(t.target,0,i.internalFormat,e,r,0,t.format,i.type,null))}t.dirtyStyleId!==i.dirtyStyleId&&this.updateTextureStyle(t),i.dirtyId=t.dirtyId}destroyTexture(t,e){const{gl:i}=this;if((t=t.castToBaseTexture())._glTextures[this.CONTEXT_UID]&&(this.unbind(t),i.deleteTexture(t._glTextures[this.CONTEXT_UID].texture),t.off("dispose",this.destroyTexture,this),delete t._glTextures[this.CONTEXT_UID],!e)){const e=this.managedTextures.indexOf(t);-1!==e&&Kp(this.managedTextures,e,1)}}updateTextureStyle(t){var e;const i=t._glTextures[this.CONTEXT_UID];i&&(t.mipmap!==th.POW2&&2===this.webGLVersion||t.isPowerOfTwo?i.mipmap=t.mipmap>=1:i.mipmap=!1,2===this.webGLVersion||t.isPowerOfTwo?i.wrapMode=t.wrapMode:i.wrapMode=Ql.CLAMP,(null==(e=t.resource)?void 0:e.style(this.renderer,t,i))||this.setStyle(t,i),i.dirtyStyleId=t.dirtyStyleId)}setStyle(t,e){const i=this.gl;if(e.mipmap&&t.mipmap!==th.ON_MANUAL&&i.generateMipmap(t.target),i.texParameteri(t.target,i.TEXTURE_WRAP_S,e.wrapMode),i.texParameteri(t.target,i.TEXTURE_WRAP_T,e.wrapMode),e.mipmap){i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===Zl.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);const e=this.renderer.context.extensions.anisotropicFiltering;if(e&&t.anisotropicLevel>0&&t.scaleMode===Zl.LINEAR){const s=Math.min(t.anisotropicLevel,i.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT));i.texParameterf(t.target,e.TEXTURE_MAX_ANISOTROPY_EXT,s)}}else i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===Zl.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(t.target,i.TEXTURE_MAG_FILTER,t.scaleMode===Zl.LINEAR?i.LINEAR:i.NEAREST)}destroy(){this.renderer=null}}qg.extension={type:gf.RendererSystem,name:"texture"},xf.add(qg);class Jg{constructor(t){this.renderer=t}contextChange(){this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,s=t._glTransformFeedbacks[i]||this.createGLTransformFeedback(t);e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,s)}unbind(){const{gl:t}=this;t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null)}beginTransformFeedback(t,e){const{gl:i,renderer:s}=this;e&&s.shader.bind(e),i.beginTransformFeedback(t)}endTransformFeedback(){const{gl:t}=this;t.endTransformFeedback()}createGLTransformFeedback(t){const{gl:e,renderer:i,CONTEXT_UID:s}=this,r=e.createTransformFeedback();t._glTransformFeedbacks[s]=r,e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,r);for(let n=0;n<t.buffers.length;n++){const r=t.buffers[n];r&&(i.buffer.update(r),r._glBuffers[s].refCount++,e.bindBufferBase(e.TRANSFORM_FEEDBACK_BUFFER,n,r._glBuffers[s].buffer||null))}return e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,null),t.disposeRunner.add(this),r}disposeTransformFeedback(t,e){const i=t._glTransformFeedbacks[this.CONTEXT_UID],s=this.gl;t.disposeRunner.remove(this);const r=this.renderer.buffer;if(r)for(let n=0;n<t.buffers.length;n++){const i=t.buffers[n];if(!i)continue;const s=i._glBuffers[this.CONTEXT_UID];s&&(s.refCount--,0===s.refCount&&!e&&r.dispose(i,e))}i&&(e||s.deleteTransformFeedback(i),delete t._glTransformFeedbacks[this.CONTEXT_UID])}destroy(){this.renderer=null}}Jg.extension={type:gf.RendererSystem,name:"transformFeedback"},xf.add(Jg);class Kg{constructor(t){this.renderer=t}init(t){this.screen=new Vf(0,0,t.width,t.height),this.element=t.view||lh.ADAPTER.createCanvas(),this.resolution=t.resolution||lh.RESOLUTION,this.autoDensity=!!t.autoDensity}resizeView(t,e){this.element.width=Math.round(t*this.resolution),this.element.height=Math.round(e*this.resolution);const i=this.element.width/this.resolution,s=this.element.height/this.resolution;this.screen.width=i,this.screen.height=s,this.autoDensity&&(this.element.style.width=`${i}px`,this.element.style.height=`${s}px`),this.renderer.emit("resize",i,s),this.renderer.runners.resize.emit(this.screen.width,this.screen.height)}destroy(t){var e;t&&(null==(e=this.element.parentNode)||e.removeChild(this.element)),this.renderer=null,this.element=null,this.screen=null}}Kg.defaultOptions={width:800,height:600,resolution:void 0,autoDensity:!1},Kg.extension={type:[gf.RendererSystem,gf.CanvasRendererSystem],name:"_view"},xf.add(Kg),lh.PREFER_ENV=Hl.WEBGL2,lh.STRICT_TEXTURE_CACHE=!1,lh.RENDER_OPTIONS={...jm.defaultOptions,...Hm.defaultOptions,...Kg.defaultOptions,...Wg.defaultOptions},Object.defineProperties(lh,{WRAP_MODE:{get:()=>Of.defaultOptions.wrapMode,set(t){op("7.1.0","settings.WRAP_MODE is deprecated, use BaseTexture.defaultOptions.wrapMode"),Of.defaultOptions.wrapMode=t}},SCALE_MODE:{get:()=>Of.defaultOptions.scaleMode,set(t){op("7.1.0","settings.SCALE_MODE is deprecated, use BaseTexture.defaultOptions.scaleMode"),Of.defaultOptions.scaleMode=t}},MIPMAP_TEXTURES:{get:()=>Of.defaultOptions.mipmap,set(t){op("7.1.0","settings.MIPMAP_TEXTURES is deprecated, use BaseTexture.defaultOptions.mipmap"),Of.defaultOptions.mipmap=t}},ANISOTROPIC_LEVEL:{get:()=>Of.defaultOptions.anisotropicLevel,set(t){op("7.1.0","settings.ANISOTROPIC_LEVEL is deprecated, use BaseTexture.defaultOptions.anisotropicLevel"),Of.defaultOptions.anisotropicLevel=t}},FILTER_RESOLUTION:{get:()=>(op("7.1.0","settings.FILTER_RESOLUTION is deprecated, use Filter.defaultResolution"),Wm.defaultResolution),set(t){Wm.defaultResolution=t}},FILTER_MULTISAMPLE:{get:()=>(op("7.1.0","settings.FILTER_MULTISAMPLE is deprecated, use Filter.defaultMultisample"),Wm.defaultMultisample),set(t){Wm.defaultMultisample=t}},SPRITE_MAX_TEXTURES:{get:()=>Gm.defaultMaxTextures,set(t){op("7.1.0","settings.SPRITE_MAX_TEXTURES is deprecated, use BatchRenderer.defaultMaxTextures"),Gm.defaultMaxTextures=t}},SPRITE_BATCH_SIZE:{get:()=>Gm.defaultBatchSize,set(t){op("7.1.0","settings.SPRITE_BATCH_SIZE is deprecated, use BatchRenderer.defaultBatchSize"),Gm.defaultBatchSize=t}},CAN_UPLOAD_SAME_BUFFER:{get:()=>Gm.canUploadSameBuffer,set(t){op("7.1.0","settings.CAN_UPLOAD_SAME_BUFFER is deprecated, use BatchRenderer.canUploadSameBuffer"),Gm.canUploadSameBuffer=t}},GC_MODE:{get:()=>zg.defaultMode,set(t){op("7.1.0","settings.GC_MODE is deprecated, use TextureGCSystem.defaultMode"),zg.defaultMode=t}},GC_MAX_IDLE:{get:()=>zg.defaultMaxIdle,set(t){op("7.1.0","settings.GC_MAX_IDLE is deprecated, use TextureGCSystem.defaultMaxIdle"),zg.defaultMaxIdle=t}},GC_MAX_CHECK_COUNT:{get:()=>zg.defaultCheckCountMax,set(t){op("7.1.0","settings.GC_MAX_CHECK_COUNT is deprecated, use TextureGCSystem.defaultCheckCountMax"),zg.defaultCheckCountMax=t}},PRECISION_VERTEX:{get:()=>Nm.defaultVertexPrecision,set(t){op("7.1.0","settings.PRECISION_VERTEX is deprecated, use Program.defaultVertexPrecision"),Nm.defaultVertexPrecision=t}},PRECISION_FRAGMENT:{get:()=>Nm.defaultFragmentPrecision,set(t){op("7.1.0","settings.PRECISION_FRAGMENT is deprecated, use Program.defaultFragmentPrecision"),Nm.defaultFragmentPrecision=t}}});var Zg=(t=>(t[t.INTERACTION=50]="INTERACTION",t[t.HIGH=25]="HIGH",t[t.NORMAL=0]="NORMAL",t[t.LOW=-25]="LOW",t[t.UTILITY=-50]="UTILITY",t))(Zg||{});class Qg{constructor(t,e=null,i=0,s=!1){this.next=null,this.previous=null,this._destroyed=!1,this.fn=t,this.context=e,this.priority=i,this.once=s}match(t,e=null){return this.fn===t&&this.context===e}emit(t){this.fn&&(this.context?this.fn.call(this.context,t):this.fn(t));const e=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const ty=class t{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new Qg(null,null,1/0),this.deltaMS=1/t.targetFPMS,this.elapsedMS=1/t.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&null===this._requestId&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){null===this._requestId&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=Zg.NORMAL){return this._addListener(new Qg(t,e,i))}addOnce(t,e,i=Zg.NORMAL){return this._addListener(new Qg(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(e){for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}else t.connect(i);return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i=i.match(t,e)?i.destroy():i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(e=performance.now()){let i;if(e>this.lastTime){if(i=this.elapsedMS=e-this.lastTime,i>this._maxElapsedMS&&(i=this._maxElapsedMS),i*=this.speed,this._minElapsedMS){const t=e-this._lastFrame|0;if(t<this._minElapsedMS)return;this._lastFrame=e-t%this._minElapsedMS}this.deltaMS=i,this.deltaTime=this.deltaMS*t.targetFPMS;const s=this._head;let r=s.next;for(;r;)r=r.emit(this.deltaTime);s.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const i=Math.min(this.maxFPS,e),s=Math.min(Math.max(0,i)/1e3,t.targetFPMS);this._maxElapsedMS=1/s}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(0===t)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!t._shared){const e=t._shared=new t;e.autoStart=!0,e._protected=!0}return t._shared}static get system(){if(!t._system){const e=t._system=new t;e.autoStart=!0,e._protected=!0}return t._system}};ty.targetFPMS=.06;let ey=ty;Object.defineProperties(lh,{TARGET_FPMS:{get:()=>ey.targetFPMS,set(t){op("7.1.0","settings.TARGET_FPMS is deprecated, use Ticker.targetFPMS"),ey.targetFPMS=t}}});class iy{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,Zg.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?ey.shared:new ey,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}iy.extension=gf.Application,xf.add(iy);const sy=[];xf.handleByList(gf.Renderer,sy);class ry{constructor(t){this.renderer=t}contextChange(t){let e;if(1===this.renderer.context.webGLVersion){const i=t.getParameter(t.FRAMEBUFFER_BINDING);t.bindFramebuffer(t.FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.FRAMEBUFFER,i)}else{const i=t.getParameter(t.DRAW_FRAMEBUFFER_BINDING);t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,i)}e>=oh.HIGH?this.multisample=oh.HIGH:e>=oh.MEDIUM?this.multisample=oh.MEDIUM:e>=oh.LOW?this.multisample=oh.LOW:this.multisample=oh.NONE}destroy(){}}ry.extension={type:gf.RendererSystem,name:"_multisample"},xf.add(ry);class ny{constructor(t){this.buffer=t||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}}class oy{constructor(t){this.renderer=t,this.managedBuffers={},this.boundBufferBases={}}destroy(){this.renderer=null}contextChange(){this.disposeAll(!0),this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,s=t._glBuffers[i]||this.createGLBuffer(t);e.bindBuffer(t.type,s.buffer)}unbind(t){const{gl:e}=this;e.bindBuffer(t,null)}bindBufferBase(t,e){const{gl:i,CONTEXT_UID:s}=this;if(this.boundBufferBases[e]!==t){const r=t._glBuffers[s]||this.createGLBuffer(t);this.boundBufferBases[e]=t,i.bindBufferBase(i.UNIFORM_BUFFER,e,r.buffer)}}bindBufferRange(t,e,i){const{gl:s,CONTEXT_UID:r}=this;i=i||0;const n=t._glBuffers[r]||this.createGLBuffer(t);s.bindBufferRange(s.UNIFORM_BUFFER,e||0,n.buffer,256*i,256)}update(t){const{gl:e,CONTEXT_UID:i}=this,s=t._glBuffers[i]||this.createGLBuffer(t);if(t._updateID!==s.updateID)if(s.updateID=t._updateID,e.bindBuffer(t.type,s.buffer),s.byteLength>=t.data.byteLength)e.bufferSubData(t.type,0,t.data);else{const i=t.static?e.STATIC_DRAW:e.DYNAMIC_DRAW;s.byteLength=t.data.byteLength,e.bufferData(t.type,t.data,i)}}dispose(t,e){if(!this.managedBuffers[t.id])return;delete this.managedBuffers[t.id];const i=t._glBuffers[this.CONTEXT_UID],s=this.gl;t.disposeRunner.remove(this),i&&(e||s.deleteBuffer(i.buffer),delete t._glBuffers[this.CONTEXT_UID])}disposeAll(t){const e=Object.keys(this.managedBuffers);for(let i=0;i<e.length;i++)this.dispose(this.managedBuffers[e[i]],t)}createGLBuffer(t){const{CONTEXT_UID:e,gl:i}=this;return t._glBuffers[e]=new ny(i.createBuffer()),this.managedBuffers[t.id]=t,t.disposeRunner.add(this),t._glBuffers[e]}}oy.extension={type:gf.RendererSystem,name:"buffer"},xf.add(oy);class ay{constructor(t){this.renderer=t}render(t,e){const i=this.renderer;let s,r,n,o;if(e&&(s=e.renderTexture,r=e.clear,n=e.transform,o=e.skipUpdateTransform),this.renderingToScreen=!s,i.runners.prerender.emit(),i.emit("prerender"),i.projection.transform=n,!i.context.isLost){if(s||(this.lastObjectRendered=t),!o){const e=t.enableTempParent();t.updateTransform(),t.disableTempParent(e)}i.renderTexture.bind(s),i.batch.currentRenderer.start(),(r??i.background.clearBeforeRender)&&i.renderTexture.clear(),t.render(i),i.batch.currentRenderer.flush(),s&&(e.blit&&i.framebuffer.blit(),s.baseTexture.update()),i.runners.postrender.emit(),i.projection.transform=null,i.emit("postrender")}}destroy(){this.renderer=null,this.lastObjectRendered=null}}ay.extension={type:gf.RendererSystem,name:"objectRenderer"},xf.add(ay);const ly=class t extends $g{constructor(e){super(),this.type=Yl.WEBGL,e=Object.assign({},lh.RENDER_OPTIONS,e),this.gl=null,this.CONTEXT_UID=0,this.globalUniforms=new Rm({projectionMatrix:new Qf},!0);const i={runners:["init","destroy","contextChange","resolutionChange","reset","update","postrender","prerender","resize"],systems:t.__systems,priority:["_view","textureGenerator","background","_plugin","startup","context","state","texture","buffer","geometry","framebuffer","transformFeedback","mask","scissor","stencil","projection","textureGC","filter","renderTexture","batch","objectRenderer","_multisample"]};this.setup(i),"useContextAlpha"in e&&(op("7.0.0","options.useContextAlpha is deprecated, use options.premultipliedAlpha and options.backgroundAlpha instead"),e.premultipliedAlpha=e.useContextAlpha&&"notMultiplied"!==e.useContextAlpha,e.backgroundAlpha=!1===e.useContextAlpha?1:e.backgroundAlpha),this._plugin.rendererPlugins=t.__plugins,this.options=e,this.startup.run(this.options)}static test(t){return!(null==t?void 0:t.forceCanvas)&&pp()}render(t,e){this.objectRenderer.render(t,e)}resize(t,e){this._view.resizeView(t,e)}reset(){return this.runners.reset.emit(),this}clear(){this.renderTexture.bind(),this.renderTexture.clear()}destroy(t=!1){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:t}),super.destroy()}get plugins(){return this._plugin.plugins}get multisample(){return this._multisample.multisample}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}set resolution(t){this._view.resolution=t,this.runners.resolutionChange.emit(t)}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get rendererLogId(){return`WebGL ${this.context.webGLVersion}`}get clearBeforeRender(){return op("7.0.0","renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."),this.background.clearBeforeRender}get useContextAlpha(){return op("7.0.0","renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."),this.context.useContextAlpha}get preserveDrawingBuffer(){return op("7.0.0","renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"),this.context.preserveDrawingBuffer}get backgroundColor(){return op("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){op("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return op("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){op("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get powerPreference(){return op("7.0.0","renderer.powerPreference has been deprecated, we can only know this if pixi creates the context"),this.context.powerPreference}generateTexture(t,e){return this.textureGenerator.generateTexture(t,e)}};ly.extension={type:gf.Renderer,priority:1},ly.__plugins={},ly.__systems={};let hy=ly;xf.handleByMap(gf.RendererPlugin,hy.__plugins),xf.handleByMap(gf.RendererSystem,hy.__systems),xf.add(hy);class uy extends If{constructor(t,e){const{width:i,height:s}=e||{};super(i,s),this.items=[],this.itemDirtyIds=[];for(let r=0;r<t;r++){const t=new Of;this.items.push(t),this.itemDirtyIds.push(-2)}this.length=t,this._load=null,this.baseTexture=null}initFromArray(t,e){for(let i=0;i<this.length;i++)t[i]&&(t[i].castToBaseTexture?this.addBaseTextureAt(t[i].castToBaseTexture(),i):t[i]instanceof If?this.addResourceAt(t[i],i):this.addResourceAt(Tf(t[i],e),i))}dispose(){for(let t=0,e=this.length;t<e;t++)this.items[t].destroy();this.items=null,this.itemDirtyIds=null,this._load=null}addResourceAt(t,e){if(!this.items[e])throw new Error(`Index ${e} is out of bounds`);return t.valid&&!this.valid&&this.resize(t.width,t.height),this.items[e].setResource(t),this}bind(t){if(null!==this.baseTexture)throw new Error("Only one base texture per TextureArray is allowed");super.bind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=t,this.items[e].on("update",t.update,t)}unbind(t){super.unbind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=null,this.items[e].off("update",t.update,t)}load(){if(this._load)return this._load;const t=this.items.map((t=>t.resource)).filter((t=>t)).map((t=>t.load()));return this._load=Promise.all(t).then((()=>{const{realWidth:t,realHeight:e}=this.items[0];return this.resize(t,e),this.update(),Promise.resolve(this)})),this._load}}class cy extends qm{constructor(t){super(t)}static test(t){const{OffscreenCanvas:e}=globalThis;return!!(e&&t instanceof e)||globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement}}const dy=class t extends uy{constructor(e,i){const{width:s,height:r,autoLoad:n,linkBaseTexture:o}=i||{};if(e&&e.length!==t.SIDES)throw new Error(`Invalid length. Got ${e.length}, expected 6`);super(6,{width:s,height:r});for(let a=0;a<t.SIDES;a++)this.items[a].target=ql.TEXTURE_CUBE_MAP_POSITIVE_X+a;this.linkBaseTexture=!1!==o,e&&this.initFromArray(e,i),!1!==n&&this.load()}bind(t){super.bind(t),t.target=ql.TEXTURE_CUBE_MAP}addBaseTextureAt(t,e,i){if(void 0===i&&(i=this.linkBaseTexture),!this.items[e])throw new Error(`Index ${e} is out of bounds`);if(!this.linkBaseTexture||t.parentTextureArray||Object.keys(t._glTextures).length>0){if(!t.resource)throw new Error("CubeResource does not support copying of renderTexture.");this.addResourceAt(t.resource,e)}else t.target=ql.TEXTURE_CUBE_MAP_POSITIVE_X+e,t.parentTextureArray=this.baseTexture,this.items[e]=t;return t.valid&&!this.valid&&this.resize(t.realWidth,t.realHeight),this.items[e]=t,this}upload(e,i,s){const r=this.itemDirtyIds;for(let n=0;n<t.SIDES;n++){const t=this.items[n];(r[n]<t.dirtyId||s.dirtyId<i.dirtyId)&&(t.valid&&t.resource?(t.resource.upload(e,t,s),r[n]=t.dirtyId):r[n]<-1&&(e.gl.texImage2D(t.target,0,s.internalFormat,i.realWidth,i.realHeight,0,i.format,s.type,null),r[n]=-1))}return!0}static test(e){return Array.isArray(e)&&e.length===t.SIDES}};dy.SIDES=6;let py=dy;class fy extends qm{constructor(t,e){let i,s,r;e=e||{},"string"==typeof t?(i=fy.EMPTY,s=t,r=!0):(i=t,s=null,r=!1),super(i),this.url=s,this.crossOrigin=e.crossOrigin??!0,this.alphaMode="number"==typeof e.alphaMode?e.alphaMode:null,this.ownsImageBitmap=e.ownsImageBitmap??r,this._load=null,!1!==e.autoLoad&&this.load()}load(){return this._load||(this._load=new Promise((async(t,e)=>{if(null!==this.url)try{const e=await lh.ADAPTER.fetch(this.url,{mode:this.crossOrigin?"cors":"no-cors"});if(this.destroyed)return;const i=await e.blob();if(this.destroyed)return;const s=await createImageBitmap(i,{premultiplyAlpha:null===this.alphaMode||this.alphaMode===eh.UNPACK?"premultiply":"none"});if(this.destroyed)return void s.close();this.source=s,this.update(),t(this)}catch(xw){if(this.destroyed)return;e(xw),this.onError.emit(xw)}else t(this)}))),this._load}upload(t,e,i){return this.source instanceof ImageBitmap?("number"==typeof this.alphaMode&&(e.alphaMode=this.alphaMode),super.upload(t,e,i)):(this.load(),!1)}dispose(){this.ownsImageBitmap&&this.source instanceof ImageBitmap&&this.source.close(),super.dispose(),this._load=null}static test(t){return!!globalThis.createImageBitmap&&typeof ImageBitmap<"u"&&("string"==typeof t||t instanceof ImageBitmap)}static get EMPTY(){return fy._EMPTY=fy._EMPTY??lh.ADAPTER.createCanvas(0,0),fy._EMPTY}}const my=class t extends qm{constructor(t,e){e=e||{},super(lh.ADAPTER.createCanvas()),this._width=0,this._height=0,this.svg=t,this.scale=e.scale||1,this._overrideWidth=e.width,this._overrideHeight=e.height,this._resolve=null,this._crossorigin=e.crossorigin,this._load=null,!1!==e.autoLoad&&this.load()}load(){return this._load||(this._load=new Promise((e=>{if(this._resolve=()=>{this.update(),e(this)},t.SVG_XML.test(this.svg.trim())){if(!btoa)throw new Error("Your browser doesn't support base64 conversions.");this.svg=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.svg)))}`}this._loadSvg()}))),this._load}_loadSvg(){const t=new Image;qm.crossOrigin(t,this.svg,this._crossorigin),t.src=this.svg,t.onerror=e=>{this._resolve&&(t.onerror=null,this.onError.emit(e))},t.onload=()=>{if(!this._resolve)return;const e=t.width,i=t.height;if(!e||!i)throw new Error("The SVG image must have width and height defined (in pixels), canvas API needs them.");let s=e*this.scale,r=i*this.scale;(this._overrideWidth||this._overrideHeight)&&(s=this._overrideWidth||this._overrideHeight/i*e,r=this._overrideHeight||this._overrideWidth/e*i),s=Math.round(s),r=Math.round(r);const n=this.source;n.width=s,n.height=r,n._pixiId=`canvas_${tf()}`,n.getContext("2d").drawImage(t,0,0,e,i,0,0,s,r),this._resolve(),this._resolve=null}}static getSize(e){const i=t.SVG_SIZE.exec(e),s={};return i&&(s[i[1]]=Math.round(parseFloat(i[3])),s[i[5]]=Math.round(parseFloat(i[7]))),s}dispose(){super.dispose(),this._resolve=null,this._crossorigin=null}static test(e,i){return"svg"===i||"string"==typeof e&&e.startsWith("data:image/svg+xml")||"string"==typeof e&&t.SVG_XML.test(e)}};my.SVG_XML=/^(<\?xml[^?]+\?>)?\s*(<!--[^(-->)]*-->)?\s*\<svg/m,my.SVG_SIZE=/<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i;let gy=my;const yy=class t extends qm{constructor(e,i){if(i=i||{},!(e instanceof HTMLVideoElement)){const s=document.createElement("video");!1!==i.autoLoad&&s.setAttribute("preload","auto"),!1!==i.playsinline&&(s.setAttribute("webkit-playsinline",""),s.setAttribute("playsinline","")),!0===i.muted&&(s.setAttribute("muted",""),s.muted=!0),!0===i.loop&&s.setAttribute("loop",""),!1!==i.autoPlay&&s.setAttribute("autoplay",""),"string"==typeof e&&(e=[e]);const r=e[0].src||e[0];qm.crossOrigin(s,r,i.crossorigin);for(let i=0;i<e.length;++i){const r=document.createElement("source");let{src:n,mime:o}=e[i];if(n=n||e[i],n.startsWith("data:"))o=n.slice(5,n.indexOf(";"));else if(!n.startsWith("blob:")){const e=n.split("?").shift().toLowerCase(),i=e.slice(e.lastIndexOf(".")+1);o=o||t.MIME_TYPES[i]||`video/${i}`}r.src=n,o&&(r.type=o),s.appendChild(r)}e=s}super(e),this.noSubImage=!0,this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=i.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=!1!==i.autoPlay,this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),!1!==i.autoLoad&&this.load()}update(t=0){if(!this.destroyed){if(this._updateFPS){const t=ey.shared.elapsedMS*this.source.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-t)}(!this._updateFPS||this._msToNextUpdate<=0)&&(super.update(),this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0)}}_videoFrameRequestCallback(){this.update(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback)}load(){if(this._load)return this._load;const t=this.source;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._onCanPlay():(t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlay),t.addEventListener("error",this._onError,!0)),this._load=new Promise(((e,i)=>{this.valid?e(this):(this._resolve=e,this._reject=i,t.load())})),this._load}_onError(t){this.source.removeEventListener("error",this._onError,!0),this.onError.emit(t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.source;return!t.paused&&!t.ended}_isSourceReady(){return this.source.readyState>2}_onPlayStart(){this.valid||this._onCanPlay(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0)}_onCanPlay(){const t=this.source;t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay);const e=this.valid;this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0,!e&&this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&t.play()}dispose(){this._configureAutoUpdate();const t=this.source;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.dispose()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.source.requestVideoFrameCallback?(this._isConnectedToTicker&&(ey.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),null===this._videoFrameRequestCallbackHandle&&(this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(null!==this._videoFrameRequestCallbackHandle&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(ey.shared.add(this.update,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(null!==this._videoFrameRequestCallbackHandle&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(ey.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e,i){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement||t.TYPES.includes(i)}};yy.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],yy.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let vy=yy;Ef.push(fy,Jm,cy,vy,class extends qm{constructor(t){super(t)}static test(t){return!!globalThis.VideoFrame&&t instanceof globalThis.VideoFrame}},gy,Sf,py,class extends uy{constructor(t,e){const{width:i,height:s}=e||{};let r,n;Array.isArray(t)?(r=t,n=t.length):n=t,super(n,{width:i,height:s}),r&&this.initFromArray(r,e)}addBaseTextureAt(t,e){if(!t.resource)throw new Error("ArrayResource does not support RenderTexture");return this.addResourceAt(t.resource,e),this}bind(t){super.bind(t),t.target=ql.TEXTURE_2D_ARRAY}upload(t,e,i){const{length:s,itemDirtyIds:r,items:n}=this,{gl:o}=t;i.dirtyId<0&&o.texImage3D(o.TEXTURE_2D_ARRAY,0,i.internalFormat,this._width,this._height,s,0,e.format,i.type,null);for(let a=0;a<s;a++){const t=n[a];r[a]<t.dirtyId&&(r[a]=t.dirtyId,t.valid&&o.texSubImage3D(o.TEXTURE_2D_ARRAY,0,0,0,a,t.resource.width,t.resource.height,1,e.format,i.type,t.resource.source))}return!0}});class xy{constructor(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.rect=null,this.updateID=-1}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}clear(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}getRectangle(t){return this.minX>this.maxX||this.minY>this.maxY?Vf.EMPTY:((t=t||new Vf(0,0,1,1)).x=this.minX,t.y=this.minY,t.width=this.maxX-this.minX,t.height=this.maxY-this.minY,t)}addPoint(t){this.minX=Math.min(this.minX,t.x),this.maxX=Math.max(this.maxX,t.x),this.minY=Math.min(this.minY,t.y),this.maxY=Math.max(this.maxY,t.y)}addPointMatrix(t,e){const{a:i,b:s,c:r,d:n,tx:o,ty:a}=t,l=i*e.x+r*e.y+o,h=s*e.x+n*e.y+a;this.minX=Math.min(this.minX,l),this.maxX=Math.max(this.maxX,l),this.minY=Math.min(this.minY,h),this.maxY=Math.max(this.maxY,h)}addQuad(t){let e=this.minX,i=this.minY,s=this.maxX,r=this.maxY,n=t[0],o=t[1];e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,n=t[2],o=t[3],e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,n=t[4],o=t[5],e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,n=t[6],o=t[7],e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,this.minX=e,this.minY=i,this.maxX=s,this.maxY=r}addFrame(t,e,i,s,r){this.addFrameMatrix(t.worldTransform,e,i,s,r)}addFrameMatrix(t,e,i,s,r){const n=t.a,o=t.b,a=t.c,l=t.d,h=t.tx,u=t.ty;let c=this.minX,d=this.minY,p=this.maxX,f=this.maxY,m=n*e+a*i+h,g=o*e+l*i+u;c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,m=n*s+a*i+h,g=o*s+l*i+u,c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,m=n*e+a*r+h,g=o*e+l*r+u,c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,m=n*s+a*r+h,g=o*s+l*r+u,c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,this.minX=c,this.minY=d,this.maxX=p,this.maxY=f}addVertexData(t,e,i){let s=this.minX,r=this.minY,n=this.maxX,o=this.maxY;for(let a=e;a<i;a+=2){const e=t[a],i=t[a+1];s=e<s?e:s,r=i<r?i:r,n=e>n?e:n,o=i>o?i:o}this.minX=s,this.minY=r,this.maxX=n,this.maxY=o}addVertices(t,e,i,s){this.addVerticesMatrix(t.worldTransform,e,i,s)}addVerticesMatrix(t,e,i,s,r=0,n=r){const o=t.a,a=t.b,l=t.c,h=t.d,u=t.tx,c=t.ty;let d=this.minX,p=this.minY,f=this.maxX,m=this.maxY;for(let g=i;g<s;g+=2){const t=e[g],i=e[g+1],s=o*t+l*i+u,y=h*i+a*t+c;d=Math.min(d,s-r),f=Math.max(f,s+r),p=Math.min(p,y-n),m=Math.max(m,y+n)}this.minX=d,this.minY=p,this.maxX=f,this.maxY=m}addBounds(t){const e=this.minX,i=this.minY,s=this.maxX,r=this.maxY;this.minX=t.minX<e?t.minX:e,this.minY=t.minY<i?t.minY:i,this.maxX=t.maxX>s?t.maxX:s,this.maxY=t.maxY>r?t.maxY:r}addBoundsMask(t,e){const i=t.minX>e.minX?t.minX:e.minX,s=t.minY>e.minY?t.minY:e.minY,r=t.maxX<e.maxX?t.maxX:e.maxX,n=t.maxY<e.maxY?t.maxY:e.maxY;if(i<=r&&s<=n){const t=this.minX,e=this.minY,o=this.maxX,a=this.maxY;this.minX=i<t?i:t,this.minY=s<e?s:e,this.maxX=r>o?r:o,this.maxY=n>a?n:a}}addBoundsMatrix(t,e){this.addFrameMatrix(e,t.minX,t.minY,t.maxX,t.maxY)}addBoundsArea(t,e){const i=t.minX>e.x?t.minX:e.x,s=t.minY>e.y?t.minY:e.y,r=t.maxX<e.x+e.width?t.maxX:e.x+e.width,n=t.maxY<e.y+e.height?t.maxY:e.y+e.height;if(i<=r&&s<=n){const t=this.minX,e=this.minY,o=this.maxX,a=this.maxY;this.minX=i<t?i:t,this.minY=s<e?s:e,this.maxX=r>o?r:o,this.maxY=n>a?n:a}}pad(t=0,e=t){this.isEmpty()||(this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e)}addFramePad(t,e,i,s,r,n){t-=r,e-=n,i+=r,s+=n,this.minX=this.minX<t?this.minX:t,this.maxX=this.maxX>i?this.maxX:i,this.minY=this.minY<e?this.minY:e,this.maxY=this.maxY>s?this.maxY:s}}class by extends Sh{constructor(){super(),this.tempDisplayObjectParent=null,this.transform=new um,this.alpha=1,this.visible=!0,this.renderable=!0,this.cullable=!1,this.cullArea=null,this.parent=null,this.worldAlpha=1,this._lastSortedIndex=0,this._zIndex=0,this.filterArea=null,this.filters=null,this._enabledFilters=null,this._bounds=new xy,this._localBounds=null,this._boundsID=0,this._boundsRect=null,this._localBoundsRect=null,this._mask=null,this._maskRefCount=0,this._destroyed=!1,this.isSprite=!1,this.isMask=!1}static mixin(t){const e=Object.keys(t);for(let i=0;i<e.length;++i){const s=e[i];Object.defineProperty(by.prototype,s,Object.getOwnPropertyDescriptor(t,s))}}get destroyed(){return this._destroyed}_recursivePostUpdateTransform(){this.parent?(this.parent._recursivePostUpdateTransform(),this.transform.updateTransform(this.parent.transform)):this.transform.updateTransform(this._tempDisplayObjectParent.transform)}updateTransform(){this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha}getBounds(t,e){return t||(this.parent?(this._recursivePostUpdateTransform(),this.updateTransform()):(this.parent=this._tempDisplayObjectParent,this.updateTransform(),this.parent=null)),this._bounds.updateID!==this._boundsID&&(this.calculateBounds(),this._bounds.updateID=this._boundsID),e||(this._boundsRect||(this._boundsRect=new Vf),e=this._boundsRect),this._bounds.getRectangle(e)}getLocalBounds(t){t||(this._localBoundsRect||(this._localBoundsRect=new Vf),t=this._localBoundsRect),this._localBounds||(this._localBounds=new xy);const e=this.transform,i=this.parent;this.parent=null,this._tempDisplayObjectParent.worldAlpha=(null==i?void 0:i.worldAlpha)??1,this.transform=this._tempDisplayObjectParent.transform;const s=this._bounds,r=this._boundsID;this._bounds=this._localBounds;const n=this.getBounds(!1,t);return this.parent=i,this.transform=e,this._bounds=s,this._bounds.updateID+=this._boundsID-r,n}toGlobal(t,e,i=!1){return i||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.apply(t,e)}toLocal(t,e,i,s){return e&&(t=e.toGlobal(t,i,s)),s||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.applyInverse(t,i)}setParent(t){if(!t||!t.addChild)throw new Error("setParent: Argument must be a Container");return t.addChild(this),t}removeFromParent(){var t;null==(t=this.parent)||t.removeChild(this)}setTransform(t=0,e=0,i=1,s=1,r=0,n=0,o=0,a=0,l=0){return this.position.x=t,this.position.y=e,this.scale.x=i||1,this.scale.y=s||1,this.rotation=r,this.skew.x=n,this.skew.y=o,this.pivot.x=a,this.pivot.y=l,this}destroy(t){this.removeFromParent(),this._destroyed=!0,this.transform=null,this.parent=null,this._bounds=null,this.mask=null,this.cullArea=null,this.filters=null,this.filterArea=null,this.hitArea=null,this.eventMode="auto",this.interactiveChildren=!1,this.emit("destroyed"),this.removeAllListeners()}get _tempDisplayObjectParent(){return null===this.tempDisplayObjectParent&&(this.tempDisplayObjectParent=new _y),this.tempDisplayObjectParent}enableTempParent(){const t=this.parent;return this.parent=this._tempDisplayObjectParent,t}disableTempParent(t){this.parent=t}get x(){return this.position.x}set x(t){this.transform.position.x=t}get y(){return this.position.y}set y(t){this.transform.position.y=t}get worldTransform(){return this.transform.worldTransform}get localTransform(){return this.transform.localTransform}get position(){return this.transform.position}set position(t){this.transform.position.copyFrom(t)}get scale(){return this.transform.scale}set scale(t){this.transform.scale.copyFrom(t)}get pivot(){return this.transform.pivot}set pivot(t){this.transform.pivot.copyFrom(t)}get skew(){return this.transform.skew}set skew(t){this.transform.skew.copyFrom(t)}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angle(){return this.transform.rotation*Hf}set angle(t){this.transform.rotation=t*Yf}get zIndex(){return this._zIndex}set zIndex(t){this._zIndex!==t&&(this._zIndex=t,this.parent&&(this.parent.sortDirty=!0))}get worldVisible(){let t=this;do{if(!t.visible)return!1;t=t.parent}while(t);return!0}get mask(){return this._mask}set mask(t){if(this._mask!==t){if(this._mask){const t=this._mask.isMaskData?this._mask.maskObject:this._mask;t&&(t._maskRefCount--,0===t._maskRefCount&&(t.renderable=!0,t.isMask=!1))}if(this._mask=t,this._mask){const t=this._mask.isMaskData?this._mask.maskObject:this._mask;t&&(0===t._maskRefCount&&(t.renderable=!1,t.isMask=!0),t._maskRefCount++)}}}}class _y extends by{constructor(){super(...arguments),this.sortDirty=null}}by.prototype.displayObjectUpdateTransform=by.prototype.updateTransform;const wy=new Qf;function Py(t,e){return t.zIndex===e.zIndex?t._lastSortedIndex-e._lastSortedIndex:t.zIndex-e.zIndex}const Ey=class t extends by{constructor(){super(),this.children=[],this.sortableChildren=t.defaultSortableChildren,this.sortDirty=!1}onChildrenChange(t){}addChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.addChild(t[e]);else{const e=t[0];e.parent&&e.parent.removeChild(e),e.parent=this,this.sortDirty=!0,e.transform._parentID=-1,this.children.push(e),this._boundsID++,this.onChildrenChange(this.children.length-1),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this)}return t[0]}addChildAt(t,e){if(e<0||e>this.children.length)throw new Error(`${t}addChildAt: The index ${e} supplied is out of bounds ${this.children.length}`);return t.parent&&t.parent.removeChild(t),t.parent=this,this.sortDirty=!0,t.transform._parentID=-1,this.children.splice(e,0,t),this._boundsID++,this.onChildrenChange(e),t.emit("added",this),this.emit("childAdded",t,this,e),t}swapChildren(t,e){if(t===e)return;const i=this.getChildIndex(t),s=this.getChildIndex(e);this.children[i]=e,this.children[s]=t,this.onChildrenChange(i<s?i:s)}getChildIndex(t){const e=this.children.indexOf(t);if(-1===e)throw new Error("The supplied DisplayObject must be a child of the caller");return e}setChildIndex(t,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);const i=this.getChildIndex(t);Kp(this.children,i,1),this.children.splice(e,0,t),this.onChildrenChange(e)}getChildAt(t){if(t<0||t>=this.children.length)throw new Error(`getChildAt: Index (${t}) does not exist.`);return this.children[t]}removeChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.removeChild(t[e]);else{const e=t[0],i=this.children.indexOf(e);if(-1===i)return null;e.parent=null,e.transform._parentID=-1,Kp(this.children,i,1),this._boundsID++,this.onChildrenChange(i),e.emit("removed",this),this.emit("childRemoved",e,this,i)}return t[0]}removeChildAt(t){const e=this.getChildAt(t);return e.parent=null,e.transform._parentID=-1,Kp(this.children,t,1),this._boundsID++,this.onChildrenChange(t),e.emit("removed",this),this.emit("childRemoved",e,this,t),e}removeChildren(t=0,e=this.children.length){const i=t,s=e-i;let r;if(s>0&&s<=e){r=this.children.splice(i,s);for(let t=0;t<r.length;++t)r[t].parent=null,r[t].transform&&(r[t].transform._parentID=-1);this._boundsID++,this.onChildrenChange(t);for(let t=0;t<r.length;++t)r[t].emit("removed",this),this.emit("childRemoved",r[t],this,t);return r}if(0===s&&0===this.children.length)return[];throw new RangeError("removeChildren: numeric values are outside the acceptable range.")}sortChildren(){let t=!1;for(let e=0,i=this.children.length;e<i;++e){const i=this.children[e];i._lastSortedIndex=e,!t&&0!==i.zIndex&&(t=!0)}t&&this.children.length>1&&this.children.sort(Py),this.sortDirty=!1}updateTransform(){this.sortableChildren&&this.sortDirty&&this.sortChildren(),this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha;for(let t=0,e=this.children.length;t<e;++t){const e=this.children[t];e.visible&&e.updateTransform()}}calculateBounds(){this._bounds.clear(),this._calculateBounds();for(let t=0;t<this.children.length;t++){const e=this.children[t];if(e.visible&&e.renderable)if(e.calculateBounds(),e._mask){const t=e._mask.isMaskData?e._mask.maskObject:e._mask;t?(t.calculateBounds(),this._bounds.addBoundsMask(e._bounds,t._bounds)):this._bounds.addBounds(e._bounds)}else e.filterArea?this._bounds.addBoundsArea(e._bounds,e.filterArea):this._bounds.addBounds(e._bounds)}this._bounds.updateID=this._boundsID}getLocalBounds(t,e=!1){const i=super.getLocalBounds(t);if(!e)for(let s=0,r=this.children.length;s<r;++s){const t=this.children[s];t.visible&&t.updateTransform()}return i}_calculateBounds(){}_renderWithCulling(e){const i=e.renderTexture.sourceFrame;if(!(i.width>0&&i.height>0))return;let s,r;this.cullArea?(s=this.cullArea,r=this.worldTransform):this._render!==t.prototype._render&&(s=this.getBounds(!0));const n=e.projection.transform;if(n&&(r?(r=wy.copyFrom(r),r.prepend(n)):r=n),s&&i.intersects(s,r))this._render(e);else if(this.cullArea)return;for(let t=0,o=this.children.length;t<o;++t){const i=this.children[t],s=i.cullable;i.cullable=s||!this.cullArea,i.render(e),i.cullable=s}}render(t){var e;if(this.visible&&!(this.worldAlpha<=0)&&this.renderable)if(this._mask||(null==(e=this.filters)?void 0:e.length))this.renderAdvanced(t);else if(this.cullable)this._renderWithCulling(t);else{this._render(t);for(let e=0,i=this.children.length;e<i;++e)this.children[e].render(t)}}renderAdvanced(t){var e,i,s;const r=this.filters,n=this._mask;if(r){this._enabledFilters||(this._enabledFilters=[]),this._enabledFilters.length=0;for(let t=0;t<r.length;t++)r[t].enabled&&this._enabledFilters.push(r[t])}const o=r&&(null==(e=this._enabledFilters)?void 0:e.length)||n&&(!n.isMaskData||n.enabled&&(n.autoDetect||n.type!==nh.NONE));if(o&&t.batch.flush(),r&&(null==(i=this._enabledFilters)?void 0:i.length)&&t.filter.push(this,this._enabledFilters),n&&t.mask.push(this,this._mask),this.cullable)this._renderWithCulling(t);else{this._render(t);for(let e=0,i=this.children.length;e<i;++e)this.children[e].render(t)}o&&t.batch.flush(),n&&t.mask.pop(this),r&&(null==(s=this._enabledFilters)?void 0:s.length)&&t.filter.pop()}_render(t){}destroy(t){super.destroy(),this.sortDirty=!1;const e="boolean"==typeof t?t:null==t?void 0:t.children,i=this.removeChildren(0,this.children.length);if(e)for(let s=0;s<i.length;++s)i[s].destroy(t)}get width(){return this.scale.x*this.getLocalBounds().width}set width(t){const e=this.getLocalBounds().width;this.scale.x=0!==e?t/e:1,this._width=t}get height(){return this.scale.y*this.getLocalBounds().height}set height(t){const e=this.getLocalBounds().height;this.scale.y=0!==e?t/e:1,this._height=t}};Ey.defaultSortableChildren=!1;let Ty=Ey;Ty.prototype.containerUpdateTransform=Ty.prototype.updateTransform,Object.defineProperties(lh,{SORTABLE_CHILDREN:{get:()=>Ty.defaultSortableChildren,set(t){op("7.1.0","settings.SORTABLE_CHILDREN is deprecated, use Container.defaultSortableChildren"),Ty.defaultSortableChildren=t}}});const Ay=new jf,Iy=new Uint16Array([0,1,2,0,2,3]);class Sy extends Ty{constructor(t){super(),this._anchor=new lm(this._onAnchorUpdate,this,t?t.defaultAnchor.x:0,t?t.defaultAnchor.y:0),this._texture=null,this._width=0,this._height=0,this._tintColor=new Hp(16777215),this._tintRGB=null,this.tint=16777215,this.blendMode=jl.NORMAL,this._cachedTint=16777215,this.uvs=null,this.texture=t||tg.EMPTY,this.vertexData=new Float32Array(8),this.vertexTrimmedData=null,this._transformID=-1,this._textureID=-1,this._transformTrimmedID=-1,this._textureTrimmedID=-1,this.indices=Iy,this.pluginName="batch",this.isSprite=!0,this._roundPixels=lh.ROUND_PIXELS}_onTextureUpdate(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=Zp(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=Zp(this.scale.y)*this._height/this._texture.orig.height)}_onAnchorUpdate(){this._transformID=-1,this._transformTrimmedID=-1}calculateVertices(){const t=this._texture;if(this._transformID===this.transform._worldID&&this._textureID===t._updateID)return;this._textureID!==t._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=t._updateID;const e=this.transform.worldTransform,i=e.a,s=e.b,r=e.c,n=e.d,o=e.tx,a=e.ty,l=this.vertexData,h=t.trim,u=t.orig,c=this._anchor;let d=0,p=0,f=0,m=0;if(h?(p=h.x-c._x*u.width,d=p+h.width,m=h.y-c._y*u.height,f=m+h.height):(p=-c._x*u.width,d=p+u.width,m=-c._y*u.height,f=m+u.height),l[0]=i*p+r*m+o,l[1]=n*m+s*p+a,l[2]=i*d+r*m+o,l[3]=n*m+s*d+a,l[4]=i*d+r*f+o,l[5]=n*f+s*d+a,l[6]=i*p+r*f+o,l[7]=n*f+s*p+a,this._roundPixels){const t=lh.RESOLUTION;for(let e=0;e<l.length;++e)l[e]=Math.round(l[e]*t)/t}}calculateTrimmedVertices(){if(this.vertexTrimmedData){if(this._transformTrimmedID===this.transform._worldID&&this._textureTrimmedID===this._texture._updateID)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=this.transform._worldID,this._textureTrimmedID=this._texture._updateID;const t=this._texture,e=this.vertexTrimmedData,i=t.orig,s=this._anchor,r=this.transform.worldTransform,n=r.a,o=r.b,a=r.c,l=r.d,h=r.tx,u=r.ty,c=-s._x*i.width,d=c+i.width,p=-s._y*i.height,f=p+i.height;if(e[0]=n*c+a*p+h,e[1]=l*p+o*c+u,e[2]=n*d+a*p+h,e[3]=l*p+o*d+u,e[4]=n*d+a*f+h,e[5]=l*f+o*d+u,e[6]=n*c+a*f+h,e[7]=l*f+o*c+u,this._roundPixels){const t=lh.RESOLUTION;for(let i=0;i<e.length;++i)e[i]=Math.round(e[i]*t)/t}}_render(t){this.calculateVertices(),t.batch.setObjectRenderer(t.plugins[this.pluginName]),t.plugins[this.pluginName].render(this)}_calculateBounds(){const t=this._texture.trim,e=this._texture.orig;!t||t.width===e.width&&t.height===e.height?(this.calculateVertices(),this._bounds.addQuad(this.vertexData)):(this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData))}getLocalBounds(t){return 0===this.children.length?(this._localBounds||(this._localBounds=new xy),this._localBounds.minX=this._texture.orig.width*-this._anchor._x,this._localBounds.minY=this._texture.orig.height*-this._anchor._y,this._localBounds.maxX=this._texture.orig.width*(1-this._anchor._x),this._localBounds.maxY=this._texture.orig.height*(1-this._anchor._y),t||(this._localBoundsRect||(this._localBoundsRect=new Vf),t=this._localBoundsRect),this._localBounds.getRectangle(t)):super.getLocalBounds.call(this,t)}containsPoint(t){this.worldTransform.applyInverse(t,Ay);const e=this._texture.orig.width,i=this._texture.orig.height,s=-e*this.anchor.x;let r=0;return Ay.x>=s&&Ay.x<s+e&&(r=-i*this.anchor.y,Ay.y>=r&&Ay.y<r+i)}destroy(t){if(super.destroy(t),this._texture.off("update",this._onTextureUpdate,this),this._anchor=null,"boolean"==typeof t?t:null==t?void 0:t.texture){const e="boolean"==typeof t?t:null==t?void 0:t.baseTexture;this._texture.destroy(!!e)}this._texture=null}static from(t,e){const i=t instanceof tg?t:tg.from(t,e);return new Sy(i)}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1,this._transformTrimmedID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){const e=Zp(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){const e=Zp(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get anchor(){return this._anchor}set anchor(t){this._anchor.copyFrom(t)}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t),this._tintRGB=this._tintColor.toLittleEndianNumber()}get tintValue(){return this._tintColor.toNumber()}get texture(){return this._texture}set texture(t){this._texture!==t&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=t||tg.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))}}const Cy={build(t){const e=t.points;let i,s,r,n,o,a;if(t.type===$f.CIRC){const e=t.shape;i=e.x,s=e.y,o=a=e.radius,r=n=0}else if(t.type===$f.ELIP){const e=t.shape;i=e.x,s=e.y,o=e.width,a=e.height,r=n=0}else{const e=t.shape,l=e.width/2,h=e.height/2;i=e.x+l,s=e.y+h,o=a=Math.max(0,Math.min(e.radius,Math.min(l,h))),r=l-o,n=h-a}if(!(o>=0&&a>=0&&r>=0&&n>=0))return void(e.length=0);const l=Math.ceil(2.3*Math.sqrt(o+a)),h=8*l+(r?4:0)+(n?4:0);if(e.length=h,0===h)return;if(0===l)return e.length=8,e[0]=e[6]=i+r,e[1]=e[3]=s+n,e[2]=e[4]=i-r,void(e[5]=e[7]=s-n);let u=0,c=4*l+(r?2:0)+2,d=c,p=h;{const t=r+o,a=n,l=i+t,h=i-t,f=s+a;if(e[u++]=l,e[u++]=f,e[--c]=f,e[--c]=h,n){const t=s-a;e[d++]=h,e[d++]=t,e[--p]=t,e[--p]=l}}for(let f=1;f<l;f++){const t=Math.PI/2*(f/l),h=r+Math.cos(t)*o,m=n+Math.sin(t)*a,g=i+h,y=i-h,v=s+m,x=s-m;e[u++]=g,e[u++]=v,e[--c]=v,e[--c]=y,e[d++]=y,e[d++]=x,e[--p]=x,e[--p]=g}{const t=n+a,o=i+r,l=i-r,h=s+t,c=s-t;e[u++]=o,e[u++]=h,e[--p]=c,e[--p]=o,r&&(e[u++]=l,e[u++]=h,e[--p]=c,e[--p]=l)}},triangulate(t,e){const i=t.points,s=e.points,r=e.indices;if(0===i.length)return;let n=s.length/2;const o=n;let a,l;if(t.type!==$f.RREC){const e=t.shape;a=e.x,l=e.y}else{const e=t.shape;a=e.x+e.width/2,l=e.y+e.height/2}const h=t.matrix;s.push(t.matrix?h.a*a+h.c*l+h.tx:a,t.matrix?h.b*a+h.d*l+h.ty:l),n++,s.push(i[0],i[1]);for(let u=2;u<i.length;u+=2)s.push(i[u],i[u+1]),r.push(n++,o,n);r.push(o+1,o,n)}};function My(t,e=!1){const i=t.length;if(i<6)return;let s=0;for(let r=0,n=t[i-2],o=t[i-1];r<i;r+=2){const e=t[r],i=t[r+1];s+=(e-n)*(i+o),n=e,o=i}if(!e&&s>0||e&&s<=0){const e=i/2;for(let s=e+e%2;s<i;s+=2){const e=i-s-2,r=i-s-1,n=s,o=s+1;[t[e],t[n]]=[t[n],t[e]],[t[r],t[o]]=[t[o],t[r]]}}}const Oy={build(t){t.points=t.shape.points.slice()},triangulate(t,e){let i=t.points;const s=t.holes,r=e.points,n=e.indices;if(i.length>=6){My(i,!1);const t=[];for(let r=0;r<s.length;r++){const e=s[r];My(e.points,!0),t.push(i.length/2),i=i.concat(e.points)}const e=ne(i,t,2);if(!e)return;const o=r.length/2;for(let i=0;i<e.length;i+=3)n.push(e[i]+o),n.push(e[i+1]+o),n.push(e[i+2]+o);for(let s=0;s<i.length;s++)r.push(i[s])}}},Ny={build(t){const e=t.shape,i=e.x,s=e.y,r=e.width,n=e.height,o=t.points;o.length=0,r>=0&&n>=0&&o.push(i,s,i+r,s,i+r,s+n,i,s+n)},triangulate(t,e){const i=t.points,s=e.points;if(0===i.length)return;const r=s.length/2;s.push(i[0],i[1],i[2],i[3],i[6],i[7],i[4],i[5]),e.indices.push(r,r+1,r+2,r+1,r+2,r+3)}},Ly={build(t){Cy.build(t)},triangulate(t,e){Cy.triangulate(t,e)}};var Ry=(t=>(t.MITER="miter",t.BEVEL="bevel",t.ROUND="round",t))(Ry||{}),ky=(t=>(t.BUTT="butt",t.ROUND="round",t.SQUARE="square",t))(ky||{});const By={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(t,e=20){if(!this.adaptive||!t||isNaN(t))return e;let i=Math.ceil(t/this.maxLength);return i<this.minSegments?i=this.minSegments:i>this.maxSegments&&(i=this.maxSegments),i}};class Fy{static curveTo(t,e,i,s,r,n){const o=n[n.length-2],a=n[n.length-1]-e,l=o-t,h=s-e,u=i-t,c=Math.abs(a*u-l*h);if(c<1e-8||0===r)return(n[n.length-2]!==t||n[n.length-1]!==e)&&n.push(t,e),null;const d=a*a+l*l,p=h*h+u*u,f=a*h+l*u,m=r*Math.sqrt(d)/c,g=r*Math.sqrt(p)/c,y=m*f/d,v=g*f/p,x=m*u+g*l,b=m*h+g*a,_=l*(g+y),w=a*(g+y),P=u*(m+v),E=h*(m+v);return{cx:x+t,cy:b+e,radius:r,startAngle:Math.atan2(w-b,_-x),endAngle:Math.atan2(E-b,P-x),anticlockwise:l*h>u*a}}static arc(t,e,i,s,r,n,o,a,l){const h=o-n,u=By._segmentsCount(Math.abs(h)*r,40*Math.ceil(Math.abs(h)/Wf)),c=h/(2*u),d=2*c,p=Math.cos(c),f=Math.sin(c),m=u-1,g=m%1/m;for(let y=0;y<=m;++y){const t=c+n+d*(y+g*y),e=Math.cos(t),o=-Math.sin(t);l.push((p*e+f*o)*r+i,(p*-o+f*e)*r+s)}}}class Dy{constructor(){this.reset()}begin(t,e,i){this.reset(),this.style=t,this.start=e,this.attribStart=i}end(t,e){this.attribSize=e-this.attribStart,this.size=t-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class Uy{static curveLength(t,e,i,s,r,n,o,a){let l=0,h=0,u=0,c=0,d=0,p=0,f=0,m=0,g=0,y=0,v=0,x=t,b=e;for(let _=1;_<=10;++_)h=_/10,u=h*h,c=u*h,d=1-h,p=d*d,f=p*d,m=f*t+3*p*h*i+3*d*u*r+c*o,g=f*e+3*p*h*s+3*d*u*n+c*a,y=x-m,v=b-g,x=m,b=g,l+=Math.sqrt(y*y+v*v);return l}static curveTo(t,e,i,s,r,n,o){const a=o[o.length-2],l=o[o.length-1];o.length-=2;const h=By._segmentsCount(Uy.curveLength(a,l,t,e,i,s,r,n));let u=0,c=0,d=0,p=0,f=0;o.push(a,l);for(let m=1,g=0;m<=h;++m)g=m/h,u=1-g,c=u*u,d=c*u,p=g*g,f=p*g,o.push(d*a+3*c*g*t+3*u*p*i+f*r,d*l+3*c*g*e+3*u*p*s+f*n)}}function Gy(t,e,i,s,r,n,o,a){let l,h;o?(l=s,h=-i):(l=-s,h=i);const u=t-i*r+l,c=e-s*r+h,d=t+i*n+l,p=e+s*n+h;return a.push(u,c,d,p),2}function Xy(t,e,i,s,r,n,o,a){const l=i-t,h=s-e;let u=Math.atan2(l,h),c=Math.atan2(r-t,n-e);a&&u<c?u+=2*Math.PI:!a&&u>c&&(c+=2*Math.PI);let d=u;const p=c-u,f=Math.abs(p),m=Math.sqrt(l*l+h*h),g=1+(15*f*Math.sqrt(m)/Math.PI|0),y=p/g;if(d+=y,a){o.push(t,e,i,s);for(let i=1,s=d;i<g;i++,s+=y)o.push(t,e,t+Math.sin(s)*m,e+Math.cos(s)*m);o.push(t,e,r,n)}else{o.push(i,s,t,e);for(let i=1,s=d;i<g;i++,s+=y)o.push(t+Math.sin(s)*m,e+Math.cos(s)*m,t,e);o.push(r,n,t,e)}return 2*g}function Wy(t,e){t.lineStyle.native?function(t,e){let i=0;const s=t.shape,r=t.points||s.points,n=s.type!==$f.POLY||s.closeStroke;if(0===r.length)return;const o=e.points,a=e.indices,l=r.length/2,h=o.length/2;let u=h;for(o.push(r[0],r[1]),i=1;i<l;i++)o.push(r[2*i],r[2*i+1]),a.push(u,u+1),u++;n&&a.push(u,h)}(t,e):function(t,e){const i=t.shape;let s=t.points||i.points.slice();const r=e.closePointEps;if(0===s.length)return;const n=t.lineStyle,o=new jf(s[0],s[1]),a=new jf(s[s.length-2],s[s.length-1]),l=i.type!==$f.POLY||i.closeStroke,h=Math.abs(o.x-a.x)<r&&Math.abs(o.y-a.y)<r;if(l){s=s.slice(),h&&(s.pop(),s.pop(),a.set(s[s.length-2],s[s.length-1]));const t=.5*(o.x+a.x),e=.5*(a.y+o.y);s.unshift(t,e),s.push(t,e)}const u=e.points,c=s.length/2;let d=s.length;const p=u.length/2,f=n.width/2,m=f*f,g=n.miterLimit*n.miterLimit;let y=s[0],v=s[1],x=s[2],b=s[3],_=0,w=0,P=-(v-b),E=y-x,T=0,A=0,I=Math.sqrt(P*P+E*E);P/=I,E/=I,P*=f,E*=f;const S=n.alignment,C=2*(1-S),M=2*S;l||(n.cap===ky.ROUND?d+=Xy(y-P*(C-M)*.5,v-E*(C-M)*.5,y-P*C,v-E*C,y+P*M,v+E*M,u,!0)+2:n.cap===ky.SQUARE&&(d+=Gy(y,v,P,E,C,M,!0,u))),u.push(y-P*C,v-E*C,y+P*M,v+E*M);for(let L=1;L<c-1;++L){y=s[2*(L-1)],v=s[2*(L-1)+1],x=s[2*L],b=s[2*L+1],_=s[2*(L+1)],w=s[2*(L+1)+1],P=-(v-b),E=y-x,I=Math.sqrt(P*P+E*E),P/=I,E/=I,P*=f,E*=f,T=-(b-w),A=x-_,I=Math.sqrt(T*T+A*A),T/=I,A/=I,T*=f,A*=f;const t=x-y,e=v-b,i=x-_,r=w-b,o=t*i+e*r,a=e*i-r*t,l=a<0;if(Math.abs(a)<.001*Math.abs(o)){u.push(x-P*C,b-E*C,x+P*M,b+E*M),o>=0&&(n.join===Ry.ROUND?d+=Xy(x,b,x-P*C,b-E*C,x-T*C,b-A*C,u,!1)+4:d+=2,u.push(x-T*M,b-A*M,x+T*C,b+A*C));continue}const h=(-P+y)*(-E+b)-(-P+x)*(-E+v),c=(-T+_)*(-A+b)-(-T+x)*(-A+w),p=(t*c-i*h)/a,S=(r*h-e*c)/a,O=(p-x)*(p-x)+(S-b)*(S-b),N=x+(p-x)*C,R=b+(S-b)*C,k=x-(p-x)*M,B=b-(S-b)*M,F=l?C:M,D=O<=Math.min(t*t+e*e,i*i+r*r)+F*F*m;let U=n.join;if(U===Ry.MITER&&O/m>g&&(U=Ry.BEVEL),D)switch(U){case Ry.MITER:u.push(N,R,k,B);break;case Ry.BEVEL:l?u.push(N,R,x+P*M,b+E*M,N,R,x+T*M,b+A*M):u.push(x-P*C,b-E*C,k,B,x-T*C,b-A*C,k,B),d+=2;break;case Ry.ROUND:l?(u.push(N,R,x+P*M,b+E*M),d+=Xy(x,b,x+P*M,b+E*M,x+T*M,b+A*M,u,!0)+4,u.push(N,R,x+T*M,b+A*M)):(u.push(x-P*C,b-E*C,k,B),d+=Xy(x,b,x-P*C,b-E*C,x-T*C,b-A*C,u,!1)+4,u.push(x-T*C,b-A*C,k,B))}else{switch(u.push(x-P*C,b-E*C,x+P*M,b+E*M),U){case Ry.MITER:l?u.push(k,B,k,B):u.push(N,R,N,R),d+=2;break;case Ry.ROUND:d+=l?Xy(x,b,x+P*M,b+E*M,x+T*M,b+A*M,u,!0)+2:Xy(x,b,x-P*C,b-E*C,x-T*C,b-A*C,u,!1)+2}u.push(x-T*C,b-A*C,x+T*M,b+A*M),d+=2}}y=s[2*(c-2)],v=s[2*(c-2)+1],x=s[2*(c-1)],b=s[2*(c-1)+1],P=-(v-b),E=y-x,I=Math.sqrt(P*P+E*E),P/=I,E/=I,P*=f,E*=f,u.push(x-P*C,b-E*C,x+P*M,b+E*M),l||(n.cap===ky.ROUND?d+=Xy(x-P*(C-M)*.5,b-E*(C-M)*.5,x-P*C,b-E*C,x+P*M,b+E*M,u,!1)+2:n.cap===ky.SQUARE&&(d+=Gy(x,b,P,E,C,M,!1,u)));const O=e.indices,N=By.epsilon*By.epsilon;for(let L=p;L<d+p-2;++L)y=u[2*L],v=u[2*L+1],x=u[2*(L+1)],b=u[2*(L+1)+1],_=u[2*(L+2)],w=u[2*(L+2)+1],!(Math.abs(y*(b-w)+x*(w-v)+_*(v-b))<N)&&O.push(L,L+1,L+2)}(t,e)}class Hy{static curveLength(t,e,i,s,r,n){const o=t-2*i+r,a=e-2*s+n,l=2*i-2*t,h=2*s-2*e,u=4*(o*o+a*a),c=4*(o*l+a*h),d=l*l+h*h,p=2*Math.sqrt(u+c+d),f=Math.sqrt(u),m=2*u*f,g=2*Math.sqrt(d),y=c/f;return(m*p+f*c*(p-g)+(4*d*u-c*c)*Math.log((2*f+y+p)/(y+g)))/(4*m)}static curveTo(t,e,i,s,r){const n=r[r.length-2],o=r[r.length-1],a=By._segmentsCount(Hy.curveLength(n,o,t,e,i,s));let l=0,h=0;for(let u=1;u<=a;++u){const c=u/a;l=n+(t-n)*c,h=o+(e-o)*c,r.push(l+(t+(i-t)*c-l)*c,h+(e+(s-e)*c-h)*c)}}}const Yy={[$f.POLY]:Oy,[$f.CIRC]:Cy,[$f.ELIP]:Cy,[$f.RECT]:Ny,[$f.RREC]:Ly},$y=[],jy=[];class zy{constructor(t,e=null,i=null,s=null){this.points=[],this.holes=[],this.shape=t,this.lineStyle=i,this.fillStyle=e,this.matrix=s,this.type=t.type}clone(){return new zy(this.shape,this.fillStyle,this.lineStyle,this.matrix)}destroy(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null}}const Vy=new jf,qy=class t extends Xf{constructor(){super(),this.closePointEps=1e-4,this.boundsPadding=0,this.uvsFloat32=null,this.indicesUint16=null,this.batchable=!1,this.points=[],this.colors=[],this.uvs=[],this.indices=[],this.textureIds=[],this.graphicsData=[],this.drawCalls=[],this.batchDirty=-1,this.batches=[],this.dirty=0,this.cacheDirty=-1,this.clearDirty=0,this.shapeIndex=0,this._bounds=new xy,this.boundsDirty=-1}get bounds(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds}invalidate(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(let t=0;t<this.drawCalls.length;t++)this.drawCalls[t].texArray.clear(),jy.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),$y.push(e)}this.batches.length=0}clear(){return this.graphicsData.length>0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(t,e=null,i=null,s=null){const r=new zy(t,e,i,s);return this.graphicsData.push(r),this.dirty++,this}drawHole(t,e=null){if(!this.graphicsData.length)return null;const i=new zy(t,null,null,e),s=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=s.lineStyle,s.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let t=0;t<this.graphicsData.length;++t)this.graphicsData[t].destroy();this.points.length=0,this.points=null,this.colors.length=0,this.colors=null,this.uvs.length=0,this.uvs=null,this.indices.length=0,this.indices=null,this.indexBuffer.destroy(),this.indexBuffer=null,this.graphicsData.length=0,this.graphicsData=null,this.drawCalls.length=0,this.drawCalls=null,this.batches.length=0,this.batches=null,this._bounds=null}containsPoint(t){const e=this.graphicsData;for(let i=0;i<e.length;++i){const s=e[i];if(s.fillStyle.visible&&s.shape&&(s.matrix?s.matrix.applyInverse(t,Vy):Vy.copyFrom(t),s.shape.contains(Vy.x,Vy.y))){let t=!1;if(s.holes)for(let e=0;e<s.holes.length;e++)if(s.holes[e].shape.contains(Vy.x,Vy.y)){t=!0;break}if(!t)return!0}}return!1}updateBatches(){if(!this.graphicsData.length)return void(this.batchable=!0);if(!this.validateBatching())return;this.cacheDirty=this.dirty;const t=this.uvs,e=this.graphicsData;let i=null,s=null;this.batches.length>0&&(i=this.batches[this.batches.length-1],s=i.style);for(let a=this.shapeIndex;a<e.length;a++){this.shapeIndex++;const r=e[a],n=r.fillStyle,o=r.lineStyle;Yy[r.type].build(r),r.matrix&&this.transformPoints(r.points,r.matrix),(n.visible||o.visible)&&this.processHoles(r.holes);for(let e=0;e<2;e++){const a=0===e?n:o;if(!a.visible)continue;const l=a.texture.baseTexture,h=this.indices.length,u=this.points.length/2;l.wrapMode=Ql.REPEAT,0===e?this.processFill(r):this.processLine(r);const c=this.points.length/2-u;0!==c&&(i&&!this._compareStyles(s,a)&&(i.end(h,u),i=null),i||(i=$y.pop()||new Dy,i.begin(a,h,u),this.batches.push(i),s=a),this.addUvs(this.points,t,a.texture,u,c,a.matrix))}}const r=this.indices.length,n=this.points.length/2;if(i&&i.end(r,n),0===this.batches.length)return void(this.batchable=!0);const o=n>65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&o===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=o?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(t,e){return!(!t||!e||t.texture.baseTexture!==e.texture.baseTexture||t.color+t.alpha!==e.color+e.alpha||!!t.native!=!!e.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let t=0,e=this.graphicsData.length;t<e;t++){const e=this.graphicsData[t],i=e.fillStyle,s=e.lineStyle;if(i&&!i.texture.baseTexture.valid||s&&!s.texture.baseTexture.valid)return!1}return!0}packBatches(){this.batchDirty++,this.uvsFloat32=new Float32Array(this.uvs);const t=this.batches;for(let e=0,i=t.length;e<i;e++){const i=t[e];for(let t=0;t<i.size;t++){const e=i.start+t;this.indicesUint16[e]=this.indicesUint16[e]-i.attribStart}}}isBatchable(){if(this.points.length>131070)return!1;const e=this.batches;for(let t=0;t<e.length;t++)if(e[t].style.native)return!1;return this.points.length<2*t.BATCHABLE_SIZE}buildDrawCalls(){let t=++Of._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),jy.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let s=jy.pop();s||(s=new Nf,s.texArray=new Fm),s.texArray.count=0,s.start=0,s.size=0,s.type=zl.TRIANGLES;let r=0,n=null,o=0,a=!1,l=zl.TRIANGLES,h=0;this.drawCalls.push(s);for(let u=0;u<this.batches.length;u++){const c=this.batches[u],d=8,p=c.style,f=p.texture.baseTexture;a!==!!p.native&&(a=!!p.native,l=a?zl.LINES:zl.TRIANGLES,n=null,r=d,t++),n!==f&&(n=f,f._batchEnabled!==t&&(r===d&&(t++,r=0,s.size>0&&(s=jy.pop(),s||(s=new Nf,s.texArray=new Fm),this.drawCalls.push(s)),s.start=h,s.size=0,s.texArray.count=0,s.type=l),f.touched=1,f._batchEnabled=t,f._batchLocation=r,f.wrapMode=Ql.REPEAT,s.texArray.elements[s.texArray.count++]=f,r++)),s.size+=c.size,h+=c.size,o=f._batchLocation,this.addColors(e,p.color,p.alpha,c.attribSize,c.attribStart),this.addTextureIds(i,o,c.attribSize,c.attribStart)}Of._globalBatch=t,this.packAttributes()}packAttributes(){const t=this.points,e=this.uvs,i=this.colors,s=this.textureIds,r=new ArrayBuffer(3*t.length*4),n=new Float32Array(r),o=new Uint32Array(r);let a=0;for(let l=0;l<t.length/2;l++)n[a++]=t[2*l],n[a++]=t[2*l+1],n[a++]=e[2*l],n[a++]=e[2*l+1],o[a++]=i[l],n[a++]=s[l];this._buffer.update(r),this._indexBuffer.update(this.indicesUint16)}processFill(t){t.holes.length?Oy.triangulate(t,this):Yy[t.type].triangulate(t,this)}processLine(t){Wy(t,this);for(let e=0;e<t.holes.length;e++)Wy(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];Yy[i.type].build(i),i.matrix&&this.transformPoints(i.points,i.matrix)}}calculateBounds(){const t=this._bounds;t.clear(),t.addVertexData(this.points,0,this.points.length),t.pad(this.boundsPadding,this.boundsPadding)}transformPoints(t,e){for(let i=0;i<t.length/2;i++){const s=t[2*i],r=t[2*i+1];t[2*i]=e.a*s+e.c*r+e.tx,t[2*i+1]=e.b*s+e.d*r+e.ty}}addColors(t,e,i,s,r=0){const n=Hp.shared.setValue(e).toLittleEndianNumber(),o=Hp.shared.setValue(n).toPremultiplied(i);t.length=Math.max(t.length,r+s);for(let a=0;a<s;a++)t[r+a]=o}addTextureIds(t,e,i,s=0){t.length=Math.max(t.length,s+i);for(let r=0;r<i;r++)t[s+r]=e}addUvs(t,e,i,s,r,n=null){let o=0;const a=e.length,l=i.frame;for(;o<r;){let i=t[2*(s+o)],r=t[2*(s+o)+1];if(n){const t=n.a*i+n.c*r+n.tx;r=n.b*i+n.d*r+n.ty,i=t}o++,e.push(i/l.width,r/l.height)}const h=i.baseTexture;(l.width<h.width||l.height<h.height)&&this.adjustUvs(e,i,a,r)}adjustUvs(t,e,i,s){const r=e.baseTexture,n=1e-6,o=i+2*s,a=e.frame,l=a.width/r.width,h=a.height/r.height;let u=a.x/a.width,c=a.y/a.height,d=Math.floor(t[i]+n),p=Math.floor(t[i+1]+n);for(let f=i+2;f<o;f+=2)d=Math.min(d,Math.floor(t[f]+n)),p=Math.min(p,Math.floor(t[f+1]+n));u-=d,c-=p;for(let f=i;f<o;f+=2)t[f]=(t[f]+u)*l,t[f+1]=(t[f+1]+c)*h}};qy.BATCHABLE_SIZE=100;let Jy=qy;class Ky{constructor(){this.color=16777215,this.alpha=1,this.texture=tg.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new Ky;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t}reset(){this.color=16777215,this.alpha=1,this.texture=tg.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class Zy extends Ky{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=ky.BUTT,this.join=Ry.MITER,this.miterLimit=10}clone(){const t=new Zy;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t.width=this.width,t.alignment=this.alignment,t.native=this.native,t.cap=this.cap,t.join=this.join,t.miterLimit=this.miterLimit,t}reset(){super.reset(),this.color=0,this.alignment=.5,this.width=0,this.native=!1,this.cap=ky.BUTT,this.join=Ry.MITER,this.miterLimit=10}}const Qy={},tv=class t extends Ty{constructor(t=null){super(),this.shader=null,this.pluginName="batch",this.currentPath=null,this.batches=[],this.batchTint=-1,this.batchDirty=-1,this.vertexData=null,this._fillStyle=new Ky,this._lineStyle=new Zy,this._matrix=null,this._holeMode=!1,this.state=Pf.for2d(),this._geometry=t||new Jy,this._geometry.refCount++,this._transformID=-1,this._tintColor=new Hp(16777215),this.blendMode=jl.NORMAL}get geometry(){return this._geometry}clone(){return this.finishPoly(),new t(this._geometry)}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t)}get fill(){return this._fillStyle}get line(){return this._lineStyle}lineStyle(t=null,e=0,i,s=.5,r=!1){return"number"==typeof t&&(t={width:t,color:e,alpha:i,alignment:s,native:r}),this.lineTextureStyle(t)}lineTextureStyle(t){const e={width:0,texture:tg.WHITE,color:(null==t?void 0:t.texture)?16777215:0,matrix:null,alignment:.5,native:!1,cap:ky.BUTT,join:Ry.MITER,miterLimit:10};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.width>0&&t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._lineStyle,{visible:i},t)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const t=this.currentPath.points,e=this.currentPath.points.length;e>2&&(this.drawShape(this.currentPath),this.currentPath=new Kf,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new Kf,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(t,e){return this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this}lineTo(t,e){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,s=i[i.length-2],r=i[i.length-1];return(s!==t||r!==e)&&i.push(t,e),this}_initCurve(t=0,e=0){this.currentPath?0===this.currentPath.points.length&&(this.currentPath.points=[t,e]):this.moveTo(t,e)}quadraticCurveTo(t,e,i,s){this._initCurve();const r=this.currentPath.points;return 0===r.length&&this.moveTo(0,0),Hy.curveTo(t,e,i,s,r),this}bezierCurveTo(t,e,i,s,r,n){return this._initCurve(),Uy.curveTo(t,e,i,s,r,n,this.currentPath.points),this}arcTo(t,e,i,s,r){this._initCurve(t,e);const n=this.currentPath.points,o=Fy.curveTo(t,e,i,s,r,n);if(o){const{cx:t,cy:e,radius:i,startAngle:s,endAngle:r,anticlockwise:n}=o;this.arc(t,e,i,s,r,n)}return this}arc(t,e,i,s,r,n=!1){if(s===r)return this;if(!n&&r<=s?r+=Wf:n&&s<=r&&(s+=Wf),r-s==0)return this;const o=t+Math.cos(s)*i,a=e+Math.sin(s)*i,l=this._geometry.closePointEps;let h=this.currentPath?this.currentPath.points:null;if(h){const t=Math.abs(h[h.length-2]-o),e=Math.abs(h[h.length-1]-a);t<l&&e<l||h.push(o,a)}else this.moveTo(o,a),h=this.currentPath.points;return Fy.arc(o,a,t,e,i,s,r,n,h),this}beginFill(t=0,e){return this.beginTextureFill({texture:tg.WHITE,color:t,alpha:e})}normalizeColor(t){const e=Hp.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:tg.WHITE,color:16777215,matrix:null};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._fillStyle,{visible:i},t)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(t,e,i,s){return this.drawShape(new Vf(t,e,i,s))}drawRoundedRect(t,e,i,s,r){return this.drawShape(new Zf(t,e,i,s,r))}drawCircle(t,e,i){return this.drawShape(new qf(t,e,i))}drawEllipse(t,e,i,s){return this.drawShape(new Jf(t,e,i,s))}drawPolygon(...t){let e,i=!0;const s=t[0];s.points?(i=s.closeStroke,e=s.points):e=Array.isArray(t[0])?t[0]:t;const r=new Kf(e);return r.closeStroke=i,this.drawShape(r),this}drawShape(t){return this._holeMode?this._geometry.drawHole(t,this._matrix):this._geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const t=this._geometry.graphicsData;return!(1!==t.length||t[0].shape.type!==$f.RECT||t[0].matrix||t[0].holes.length||t[0].lineStyle.visible&&t[0].lineStyle.width)}_render(t){this.finishPoly();const e=this._geometry;e.updateBatches(),e.batchable?(this.batchDirty!==e.batchDirty&&this._populateBatches(),this._renderBatched(t)):(t.batch.flush(),this._renderDirect(t))}_populateBatches(){const t=this._geometry,e=this.blendMode,i=t.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=t.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(t.points);for(let s=0;s<i;s++){const i=t.batches[s],r=i.style.color,n=new Float32Array(this.vertexData.buffer,4*i.attribStart*2,2*i.attribSize),o=new Float32Array(t.uvsFloat32.buffer,4*i.attribStart*2,2*i.attribSize),a={vertexData:n,blendMode:e,indices:new Uint16Array(t.indicesUint16.buffer,2*i.start,i.size),uvs:o,_batchRGB:Hp.shared.setValue(r).toRgbArray(),_tintRGB:r,_texture:i.style.texture,alpha:i.style.alpha,worldAlpha:1};this.batches[s]=a}}_renderBatched(t){if(this.batches.length){t.batch.setObjectRenderer(t.plugins[this.pluginName]),this.calculateVertices(),this.calculateTints();for(let e=0,i=this.batches.length;e<i;e++){const i=this.batches[e];i.worldAlpha=this.worldAlpha*i.alpha,t.plugins[this.pluginName].render(i)}}}_renderDirect(t){const e=this._resolveDirectShader(t),i=this._geometry,s=this.worldAlpha,r=e.uniforms,n=i.drawCalls;r.translationMatrix=this.transform.worldTransform,Hp.shared.setValue(this._tintColor).premultiply(s).toArray(r.tint),t.shader.bind(e),t.geometry.bind(i,e),t.state.set(this.state);for(let o=0,a=n.length;o<a;o++)this._renderDrawCallDirect(t,i.drawCalls[o])}_renderDrawCallDirect(t,e){const{texArray:i,type:s,size:r,start:n}=e,o=i.count;for(let a=0;a<o;a++)t.texture.bind(i.elements[a],a);t.geometry.draw(s,r,n)}_resolveDirectShader(t){let e=this.shader;const i=this.pluginName;if(!e){if(!Qy[i]){const{maxTextures:e}=t.plugins[i],s=new Int32Array(e);for(let t=0;t<e;t++)s[t]=t;const r={tint:new Float32Array([1,1,1,1]),translationMatrix:new Qf,default:Rm.from({uSamplers:s},!0)},n=t.plugins[i]._shader.program;Qy[i]=new km(n,r)}e=Qy[i]}return e}_calculateBounds(){this.finishPoly();const t=this._geometry;if(!t.graphicsData.length)return;const{minX:e,minY:i,maxX:s,maxY:r}=t.bounds;this._bounds.addFrame(this.transform,e,i,s,r)}containsPoint(e){return this.worldTransform.applyInverse(e,t._TEMP_POINT),this._geometry.containsPoint(t._TEMP_POINT)}calculateTints(){if(this.batchTint!==this.tint){this.batchTint=this._tintColor.toNumber();for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e._tintRGB=Hp.shared.setValue(this._tintColor).multiply(e._batchRGB).toLittleEndianNumber()}}}calculateVertices(){const t=this.transform._worldID;if(this._transformID===t)return;this._transformID=t;const e=this.transform.worldTransform,i=e.a,s=e.b,r=e.c,n=e.d,o=e.tx,a=e.ty,l=this._geometry.points,h=this.vertexData;let u=0;for(let c=0;c<l.length;c+=2){const t=l[c],e=l[c+1];h[u++]=i*t+r*e+o,h[u++]=n*e+s*t+a}}closePath(){const t=this.currentPath;return t&&(t.closeStroke=!0,this.finishPoly()),this}setMatrix(t){return this._matrix=t,this}beginHole(){return this.finishPoly(),this._holeMode=!0,this}endHole(){return this.finishPoly(),this._holeMode=!1,this}destroy(t){this._geometry.refCount--,0===this._geometry.refCount&&this._geometry.dispose(),this._matrix=null,this.currentPath=null,this._lineStyle.destroy(),this._lineStyle=null,this._fillStyle.destroy(),this._fillStyle=null,this._geometry=null,this.shader=null,this.vertexData=null,this.batches.length=0,this.batches=null,super.destroy(t)}};tv.curves=By,tv._TEMP_POINT=new jf;let ev=tv;var iv=(t=>(t[t.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",t[t.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",t))(iv||{});const sv={willReadFrequently:!0},rv=class t{static get experimentalLetterSpacingSupported(){let e=t._experimentalLetterSpacingSupported;if(void 0!==e){const i=lh.ADAPTER.getCanvasRenderingContext2D().prototype;e=t._experimentalLetterSpacingSupported="letterSpacing"in i||"textLetterSpacing"in i}return e}constructor(t,e,i,s,r,n,o,a,l){this.text=t,this.style=e,this.width=i,this.height=s,this.lines=r,this.lineWidths=n,this.lineHeight=o,this.maxLineWidth=a,this.fontProperties=l}static measureText(e,i,s,r=t._canvas){s=s??i.wordWrap;const n=i.toFontString(),o=t.measureFont(n);0===o.fontSize&&(o.fontSize=i.fontSize,o.ascent=i.fontSize);const a=r.getContext("2d",sv);a.font=n;const l=(s?t.wordWrap(e,i,r):e).split(/(?:\r\n|\r|\n)/),h=new Array(l.length);let u=0;for(let f=0;f<l.length;f++){const e=t._measureText(l[f],i.letterSpacing,a);h[f]=e,u=Math.max(u,e)}let c=u+i.strokeThickness;i.dropShadow&&(c+=i.dropShadowDistance);const d=i.lineHeight||o.fontSize+i.strokeThickness;let p=Math.max(d,o.fontSize+2*i.strokeThickness)+i.leading+(l.length-1)*(d+i.leading);return i.dropShadow&&(p+=i.dropShadowDistance),new t(e,i,c,p,l,h,d+i.leading,u,o)}static _measureText(e,i,s){let r=!1;t.experimentalLetterSpacingSupported&&(t.experimentalLetterSpacing?(s.letterSpacing=`${i}px`,s.textLetterSpacing=`${i}px`,r=!0):(s.letterSpacing="0px",s.textLetterSpacing="0px"));let n=s.measureText(e).width;return n>0&&(r?n-=i:n+=(t.graphemeSegmenter(e).length-1)*i),n}static wordWrap(e,i,s=t._canvas){const r=s.getContext("2d",sv);let n=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:u}=i,c=t.collapseSpaces(u),d=t.collapseNewlines(u);let p=!c;const f=i.wordWrapWidth+h,m=t.tokenize(e);for(let g=0;g<m.length;g++){let e=m[g];if(t.isNewline(e)){if(!d){a+=t.addLine(o),p=!c,o="",n=0;continue}e=" "}if(c){const i=t.isBreakingSpace(e),s=t.isBreakingSpace(o[o.length-1]);if(i&&s)continue}const s=t.getFromCache(e,h,l,r);if(s>f)if(""!==o&&(a+=t.addLine(o),o="",n=0),t.canBreakWords(e,i.breakWords)){const s=t.wordWrapSplit(e);for(let u=0;u<s.length;u++){let c=s[u],d=c,m=1;for(;s[u+m];){const r=s[u+m];if(t.canBreakChars(d,r,e,u,i.breakWords))break;c+=r,d=r,m++}u+=m-1;const g=t.getFromCache(c,h,l,r);g+n>f&&(a+=t.addLine(o),p=!1,o="",n=0),o+=c,n+=g}}else{o.length>0&&(a+=t.addLine(o),o="",n=0);const i=g===m.length-1;a+=t.addLine(e,!i),p=!1,o="",n=0}else s+n>f&&(p=!1,a+=t.addLine(o),o="",n=0),(o.length>0||!t.isBreakingSpace(e)||p)&&(o+=e,n+=s)}return a+=t.addLine(o,!1),a}static addLine(e,i=!0){return e=t.trimRight(e),e=i?`${e}\n`:e}static getFromCache(e,i,s,r){let n=s[e];return"number"!=typeof n&&(n=t._measureText(e,i,r)+i,s[e]=n),n}static collapseSpaces(t){return"normal"===t||"pre-line"===t}static collapseNewlines(t){return"normal"===t}static trimRight(e){if("string"!=typeof e)return"";for(let i=e.length-1;i>=0;i--){const s=e[i];if(!t.isBreakingSpace(s))break;e=e.slice(0,-1)}return e}static isNewline(e){return"string"==typeof e&&t._newlines.includes(e.charCodeAt(0))}static isBreakingSpace(e,i){return"string"==typeof e&&t._breakingSpaces.includes(e.charCodeAt(0))}static tokenize(e){const i=[];let s="";if("string"!=typeof e)return i;for(let r=0;r<e.length;r++){const n=e[r],o=e[r+1];t.isBreakingSpace(n,o)||t.isNewline(n)?(""!==s&&(i.push(s),s=""),i.push(n)):s+=n}return""!==s&&i.push(s),i}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,s,r){return!0}static wordWrapSplit(e){return t.graphemeSegmenter(e)}static measureFont(e){if(t._fonts[e])return t._fonts[e];const i={ascent:0,descent:0,fontSize:0},s=t._canvas,r=t._context;r.font=e;const n=t.METRICS_STRING+t.BASELINE_SYMBOL,o=Math.ceil(r.measureText(n).width);let a=Math.ceil(r.measureText(t.BASELINE_SYMBOL).width);const l=Math.ceil(t.HEIGHT_MULTIPLIER*a);if(a=a*t.BASELINE_MULTIPLIER|0,0===o||0===l)return t._fonts[e]=i,i;s.width=o,s.height=l,r.fillStyle="#f00",r.fillRect(0,0,o,l),r.font=e,r.textBaseline="alphabetic",r.fillStyle="#000",r.fillText(n,0,a);const h=r.getImageData(0,0,o,l).data,u=h.length,c=4*o;let d=0,p=0,f=!1;for(d=0;d<a;++d){for(let t=0;t<c;t+=4)if(255!==h[p+t]){f=!0;break}if(f)break;p+=c}for(i.ascent=a-d,p=u-c,f=!1,d=l;d>a;--d){for(let t=0;t<c;t+=4)if(255!==h[p+t]){f=!0;break}if(f)break;p-=c}return i.descent=d-a,i.fontSize=i.ascent+i.descent,t._fonts[e]=i,i}static clearMetrics(e=""){e?delete t._fonts[e]:t._fonts={}}static get _canvas(){var e;if(!t.__canvas){let i;try{const s=new OffscreenCanvas(0,0);if(null==(e=s.getContext("2d",sv))?void 0:e.measureText)return t.__canvas=s,s;i=lh.ADAPTER.createCanvas()}catch{i=lh.ADAPTER.createCanvas()}i.width=i.height=10,t.__canvas=i}return t.__canvas}static get _context(){return t.__context||(t.__context=t._canvas.getContext("2d",sv)),t.__context}};rv.METRICS_STRING="|ÉqÅ",rv.BASELINE_SYMBOL="M",rv.BASELINE_MULTIPLIER=1.4,rv.HEIGHT_MULTIPLIER=2,rv.graphemeSegmenter=(()=>{if("function"==typeof(null==Intl?void 0:Intl.Segmenter)){const t=new Intl.Segmenter;return e=>[...t.segment(e)].map((t=>t.segment))}return t=>[...t]})(),rv.experimentalLetterSpacing=!1,rv._fonts={},rv._newlines=[10,13],rv._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let nv=rv;const ov=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],av=class t{constructor(t){this.styleID=0,this.reset(),uv(this,t,t)}clone(){const e={};return uv(e,this,t.defaultStyle),new t(e)}reset(){uv(this,t.defaultStyle,t.defaultStyle)}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(this._dropShadow=t,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(t){this._dropShadowAlpha!==t&&(this._dropShadowAlpha=t,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(t){this._dropShadowAngle!==t&&(this._dropShadowAngle=t,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(t){this._dropShadowBlur!==t&&(this._dropShadowBlur=t,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(t){const e=hv(t);this._dropShadowColor!==e&&(this._dropShadowColor=e,this.styleID++)}get dropShadowDistance(){return this._dropShadowDistance}set dropShadowDistance(t){this._dropShadowDistance!==t&&(this._dropShadowDistance=t,this.styleID++)}get fill(){return this._fill}set fill(t){const e=hv(t);this._fill!==e&&(this._fill=e,this.styleID++)}get fillGradientType(){return this._fillGradientType}set fillGradientType(t){this._fillGradientType!==t&&(this._fillGradientType=t,this.styleID++)}get fillGradientStops(){return this._fillGradientStops}set fillGradientStops(t){(function(t,e){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(t[i]!==e[i])return!1;return!0})(this._fillGradientStops,t)||(this._fillGradientStops=t,this.styleID++)}get fontFamily(){return this._fontFamily}set fontFamily(t){this.fontFamily!==t&&(this._fontFamily=t,this.styleID++)}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.styleID++)}get fontStyle(){return this._fontStyle}set fontStyle(t){this._fontStyle!==t&&(this._fontStyle=t,this.styleID++)}get fontVariant(){return this._fontVariant}set fontVariant(t){this._fontVariant!==t&&(this._fontVariant=t,this.styleID++)}get fontWeight(){return this._fontWeight}set fontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.styleID++)}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.styleID++)}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight!==t&&(this._lineHeight=t,this.styleID++)}get leading(){return this._leading}set leading(t){this._leading!==t&&(this._leading=t,this.styleID++)}get lineJoin(){return this._lineJoin}set lineJoin(t){this._lineJoin!==t&&(this._lineJoin=t,this.styleID++)}get miterLimit(){return this._miterLimit}set miterLimit(t){this._miterLimit!==t&&(this._miterLimit=t,this.styleID++)}get padding(){return this._padding}set padding(t){this._padding!==t&&(this._padding=t,this.styleID++)}get stroke(){return this._stroke}set stroke(t){const e=hv(t);this._stroke!==e&&(this._stroke=e,this.styleID++)}get strokeThickness(){return this._strokeThickness}set strokeThickness(t){this._strokeThickness!==t&&(this._strokeThickness=t,this.styleID++)}get textBaseline(){return this._textBaseline}set textBaseline(t){this._textBaseline!==t&&(this._textBaseline=t,this.styleID++)}get trim(){return this._trim}set trim(t){this._trim!==t&&(this._trim=t,this.styleID++)}get whiteSpace(){return this._whiteSpace}set whiteSpace(t){this._whiteSpace!==t&&(this._whiteSpace=t,this.styleID++)}get wordWrap(){return this._wordWrap}set wordWrap(t){this._wordWrap!==t&&(this._wordWrap=t,this.styleID++)}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(t){this._wordWrapWidth!==t&&(this._wordWrapWidth=t,this.styleID++)}toFontString(){const t="number"==typeof this.fontSize?`${this.fontSize}px`:this.fontSize;let e=this.fontFamily;Array.isArray(this.fontFamily)||(e=this.fontFamily.split(","));for(let i=e.length-1;i>=0;i--){let t=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(t)&&!ov.includes(t)&&(t=`"${t}"`),e[i]=t}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};av.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:iv.LINEAR_VERTICAL,fillGradientStops:[],fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,lineJoin:"miter",miterLimit:10,padding:0,stroke:"black",strokeThickness:0,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let lv=av;function hv(t){const e=Hp.shared,i=t=>{const i=e.setValue(t);return 1===i.alpha?i.toHex():i.toRgbaString()};return Array.isArray(t)?t.map(i):i(t)}function uv(t,e,i){for(const s in i)Array.isArray(e[s])?t[s]=e[s].slice():t[s]=e[s]}const cv={texture:!0,children:!1,baseTexture:!0},dv=class t extends Sy{constructor(e,i,s){let r=!1;s||(s=lh.ADAPTER.createCanvas(),r=!0),s.width=3,s.height=3;const n=tg.from(s);n.orig=new Vf,n.trim=new Vf,super(n),this._ownCanvas=r,this.canvas=s,this.context=s.getContext("2d",{willReadFrequently:!0}),this._resolution=t.defaultResolution??lh.RESOLUTION,this._autoResolution=t.defaultAutoResolution,this._text=null,this._style=null,this._styleListener=null,this._font="",this.text=e,this.style=i,this.localStyleID=-1}static get experimentalLetterSpacing(){return nv.experimentalLetterSpacing}static set experimentalLetterSpacing(t){op("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),nv.experimentalLetterSpacing=t}updateText(t){const e=this._style;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;this._font=this._style.toFontString();const i=this.context,s=nv.measureText(this._text||" ",this._style,this._style.wordWrap,this.canvas),r=s.width,n=s.height,o=s.lines,a=s.lineHeight,l=s.lineWidths,h=s.maxLineWidth,u=s.fontProperties;let c,d;this.canvas.width=Math.ceil(Math.ceil(Math.max(1,r)+2*e.padding)*this._resolution),this.canvas.height=Math.ceil(Math.ceil(Math.max(1,n)+2*e.padding)*this._resolution),i.scale(this._resolution,this._resolution),i.clearRect(0,0,this.canvas.width,this.canvas.height),i.font=this._font,i.lineWidth=e.strokeThickness,i.textBaseline=e.textBaseline,i.lineJoin=e.lineJoin,i.miterLimit=e.miterLimit;const p=e.dropShadow?2:1;for(let f=0;f<p;++f){const t=e.dropShadow&&0===f,r=t?Math.ceil(Math.max(1,n)+2*e.padding):0,p=r*this._resolution;if(t){i.fillStyle="black",i.strokeStyle="black";const t=e.dropShadowColor,s=e.dropShadowBlur*this._resolution,r=e.dropShadowDistance*this._resolution;i.shadowColor=Hp.shared.setValue(t).setAlpha(e.dropShadowAlpha).toRgbaString(),i.shadowBlur=s,i.shadowOffsetX=Math.cos(e.dropShadowAngle)*r,i.shadowOffsetY=Math.sin(e.dropShadowAngle)*r+p}else i.fillStyle=this._generateFillStyle(e,o,s),i.strokeStyle=e.stroke,i.shadowColor="black",i.shadowBlur=0,i.shadowOffsetX=0,i.shadowOffsetY=0;let m=(a-u.fontSize)/2;a-u.fontSize<0&&(m=0);for(let i=0;i<o.length;i++)c=e.strokeThickness/2,d=e.strokeThickness/2+i*a+u.ascent+m,"right"===e.align?c+=h-l[i]:"center"===e.align&&(c+=(h-l[i])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(o[i],c+e.padding,d+e.padding-r,!0),e.fill&&this.drawLetterSpacing(o[i],c+e.padding,d+e.padding-r)}this.updateTexture()}drawLetterSpacing(t,e,i,s=!1){const r=this._style.letterSpacing;let n=!1;if(nv.experimentalLetterSpacingSupported&&(nv.experimentalLetterSpacing?(this.context.letterSpacing=`${r}px`,this.context.textLetterSpacing=`${r}px`,n=!0):(this.context.letterSpacing="0px",this.context.textLetterSpacing="0px")),0===r||n)return void(s?this.context.strokeText(t,e,i):this.context.fillText(t,e,i));let o=e;const a=nv.graphemeSegmenter(t);let l=this.context.measureText(t).width,h=0;for(let u=0;u<a.length;++u){const t=a[u];s?this.context.strokeText(t,o,i):this.context.fillText(t,o,i);let e="";for(let i=u+1;i<a.length;++i)e+=a[i];h=this.context.measureText(e).width,o+=l-h+r,l=h}}updateTexture(){const t=this.canvas;if(this._style.trim){const e=df(t);e.data&&(t.width=e.width,t.height=e.height,this.context.putImageData(e.data,0,0))}const e=this._texture,i=this._style,s=i.trim?0:i.padding,r=e.baseTexture;e.trim.width=e._frame.width=t.width/this._resolution,e.trim.height=e._frame.height=t.height/this._resolution,e.trim.x=-s,e.trim.y=-s,e.orig.width=e._frame.width-2*s,e.orig.height=e._frame.height-2*s,this._onTextureUpdate(),r.setRealSize(t.width,t.height,this._resolution),e.updateUvs(),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}updateTransform(){this.updateText(!0),super.updateTransform()}getBounds(t,e){return this.updateText(!0),-1===this._textureID&&(t=!1),super.getBounds(t,e)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds.call(this,t)}_calculateBounds(){this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_generateFillStyle(t,e,i){const s=t.fill;if(!Array.isArray(s))return s;if(1===s.length)return s[0];let r;const n=t.dropShadow?t.dropShadowDistance:0,o=t.padding||0,a=this.canvas.width/this._resolution-n-2*o,l=this.canvas.height/this._resolution-n-2*o,h=s.slice(),u=t.fillGradientStops.slice();if(!u.length){const t=h.length+1;for(let e=1;e<t;++e)u.push(e/t)}if(h.unshift(s[0]),u.unshift(0),h.push(s[s.length-1]),u.push(1),t.fillGradientType===iv.LINEAR_VERTICAL){r=this.context.createLinearGradient(a/2,o,a/2,l+o);const s=i.fontProperties.fontSize+t.strokeThickness;for(let t=0;t<e.length;t++){const n=i.lineHeight*(t-1)+s,o=i.lineHeight*t;let a=o;t>0&&n>o&&(a=(o+n)/2);const c=o+s,d=i.lineHeight*(t+1);let p=c;t+1<e.length&&d<c&&(p=(c+d)/2);const f=(p-a)/l;for(let t=0;t<h.length;t++){let e=0;e="number"==typeof u[t]?u[t]:t/h.length;let i=Math.min(1,Math.max(0,a/l+e*f));i=Number(i.toFixed(5)),r.addColorStop(i,h[t])}}}else{r=this.context.createLinearGradient(o,l/2,a+o,l/2);const t=h.length+1;let e=1;for(let i=0;i<h.length;i++){let s;s="number"==typeof u[i]?u[i]:e/t,r.addColorStop(s,h[i]),e++}}return r}destroy(t){"boolean"==typeof t&&(t={children:t}),t=Object.assign({},cv,t),super.destroy(t),this._ownCanvas&&(this.canvas.height=this.canvas.width=0),this.context=null,this.canvas=null,this._style=null}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this.updateText(!0);const e=Zp(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this.updateText(!0);const e=Zp(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get style(){return this._style}set style(t){t=t||{},this._style=t instanceof lv?t:new lv(t),this.localStyleID=-1,this.dirty=!0}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}};dv.defaultAutoResolution=!0;let pv=dv;class fv extends Wm{constructor(){super("attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n gl_Position = filterVertexPosition();\n vTextureCoord = filterTextureCoord();\n}\n","varying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float m[20];\nuniform float uAlpha;\n\nvoid main(void)\n{\n vec4 c = texture2D(uSampler, vTextureCoord);\n\n if (uAlpha == 0.0) {\n gl_FragColor = c;\n return;\n }\n\n // Un-premultiply alpha before applying the color matrix. See issue #3539.\n if (c.a > 0.0) {\n c.rgb /= c.a;\n }\n\n vec4 result;\n\n result.r = (m[0] * c.r);\n result.r += (m[1] * c.g);\n result.r += (m[2] * c.b);\n result.r += (m[3] * c.a);\n result.r += m[4];\n\n result.g = (m[5] * c.r);\n result.g += (m[6] * c.g);\n result.g += (m[7] * c.b);\n result.g += (m[8] * c.a);\n result.g += m[9];\n\n result.b = (m[10] * c.r);\n result.b += (m[11] * c.g);\n result.b += (m[12] * c.b);\n result.b += (m[13] * c.a);\n result.b += m[14];\n\n result.a = (m[15] * c.r);\n result.a += (m[16] * c.g);\n result.a += (m[17] * c.b);\n result.a += (m[18] * c.a);\n result.a += m[19];\n\n vec3 rgb = mix(c.rgb, result.rgb, uAlpha);\n\n // Premultiply alpha again.\n rgb *= result.a;\n\n gl_FragColor = vec4(rgb, result.a);\n}\n",{m:new Float32Array([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0]),uAlpha:1}),this.alpha=1}_loadMatrix(t,e=!1){let i=t;e&&(this._multiply(i,this.uniforms.m,t),i=this._colorMatrix(i)),this.uniforms.m=i}_multiply(t,e,i){return t[0]=e[0]*i[0]+e[1]*i[5]+e[2]*i[10]+e[3]*i[15],t[1]=e[0]*i[1]+e[1]*i[6]+e[2]*i[11]+e[3]*i[16],t[2]=e[0]*i[2]+e[1]*i[7]+e[2]*i[12]+e[3]*i[17],t[3]=e[0]*i[3]+e[1]*i[8]+e[2]*i[13]+e[3]*i[18],t[4]=e[0]*i[4]+e[1]*i[9]+e[2]*i[14]+e[3]*i[19]+e[4],t[5]=e[5]*i[0]+e[6]*i[5]+e[7]*i[10]+e[8]*i[15],t[6]=e[5]*i[1]+e[6]*i[6]+e[7]*i[11]+e[8]*i[16],t[7]=e[5]*i[2]+e[6]*i[7]+e[7]*i[12]+e[8]*i[17],t[8]=e[5]*i[3]+e[6]*i[8]+e[7]*i[13]+e[8]*i[18],t[9]=e[5]*i[4]+e[6]*i[9]+e[7]*i[14]+e[8]*i[19]+e[9],t[10]=e[10]*i[0]+e[11]*i[5]+e[12]*i[10]+e[13]*i[15],t[11]=e[10]*i[1]+e[11]*i[6]+e[12]*i[11]+e[13]*i[16],t[12]=e[10]*i[2]+e[11]*i[7]+e[12]*i[12]+e[13]*i[17],t[13]=e[10]*i[3]+e[11]*i[8]+e[12]*i[13]+e[13]*i[18],t[14]=e[10]*i[4]+e[11]*i[9]+e[12]*i[14]+e[13]*i[19]+e[14],t[15]=e[15]*i[0]+e[16]*i[5]+e[17]*i[10]+e[18]*i[15],t[16]=e[15]*i[1]+e[16]*i[6]+e[17]*i[11]+e[18]*i[16],t[17]=e[15]*i[2]+e[16]*i[7]+e[17]*i[12]+e[18]*i[17],t[18]=e[15]*i[3]+e[16]*i[8]+e[17]*i[13]+e[18]*i[18],t[19]=e[15]*i[4]+e[16]*i[9]+e[17]*i[14]+e[18]*i[19]+e[19],t}_colorMatrix(t){const e=new Float32Array(t);return e[4]/=255,e[9]/=255,e[14]/=255,e[19]/=255,e}brightness(t,e){const i=[t,0,0,0,0,0,t,0,0,0,0,0,t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}tint(t,e){const[i,s,r]=Hp.shared.setValue(t).toArray(),n=[i,0,0,0,0,0,s,0,0,0,0,0,r,0,0,0,0,0,1,0];this._loadMatrix(n,e)}greyscale(t,e){const i=[t,t,t,0,0,t,t,t,0,0,t,t,t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}blackAndWhite(t){this._loadMatrix([.3,.6,.1,0,0,.3,.6,.1,0,0,.3,.6,.1,0,0,0,0,0,1,0],t)}hue(t,e){t=(t||0)/180*Math.PI;const i=Math.cos(t),s=Math.sin(t),r=1/3,n=(0,Math.sqrt)(r),o=[i+(1-i)*r,r*(1-i)-n*s,r*(1-i)+n*s,0,0,r*(1-i)+n*s,i+r*(1-i),r*(1-i)-n*s,0,0,r*(1-i)-n*s,r*(1-i)+n*s,i+r*(1-i),0,0,0,0,0,1,0];this._loadMatrix(o,e)}contrast(t,e){const i=(t||0)+1,s=-.5*(i-1),r=[i,0,0,0,s,0,i,0,0,s,0,0,i,0,s,0,0,0,1,0];this._loadMatrix(r,e)}saturate(t=0,e){const i=2*t/3+1,s=-.5*(i-1),r=[i,s,s,0,0,s,i,s,0,0,s,s,i,0,0,0,0,0,1,0];this._loadMatrix(r,e)}desaturate(){this.saturate(-1)}negative(t){this._loadMatrix([-1,0,0,1,0,0,-1,0,1,0,0,0,-1,1,0,0,0,0,1,0],t)}sepia(t){this._loadMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0],t)}technicolor(t){this._loadMatrix([1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0],t)}polaroid(t){this._loadMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0],t)}toBGR(t){this._loadMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0],t)}kodachrome(t){this._loadMatrix([1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0],t)}browni(t){this._loadMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0],t)}vintage(t){this._loadMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0],t)}colorTone(t,e,i,s,r){t=t||.2,e=e||.15,i=i||16770432,s=s||3375104;const n=Hp.shared,[o,a,l]=n.setValue(i).toArray(),[h,u,c]=n.setValue(s).toArray(),d=[.3,.59,.11,0,0,o,a,l,t,0,h,u,c,e,0,o-h,a-u,l-c,0,0];this._loadMatrix(d,r)}night(t,e){const i=[-2*(t=t||.1),-t,0,0,0,-t,0,t,0,0,0,t,2*t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}predator(t,e){const i=[11.224130630493164*t,-4.794486999511719*t,-2.8746118545532227*t,0*t,.40342438220977783*t,-3.6330697536468506*t,9.193157196044922*t,-2.951810836791992*t,0*t,-1.316135048866272*t,-3.2184197902679443*t,-4.2375030517578125*t,7.476448059082031*t,0*t,.8044459223747253*t,0,0,0,1,0];this._loadMatrix(i,e)}lsd(t){this._loadMatrix([2,-.4,.5,0,0,-.5,2,-.4,0,0,-.4,-.5,3,0,0,0,0,0,1,0],t)}reset(){this._loadMatrix([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],!1)}get matrix(){return this.uniforms.m}set matrix(t){this.uniforms.m=t}get alpha(){return this.uniforms.uAlpha}set alpha(t){this.uniforms.uAlpha=t}}fv.prototype.grayscale=fv.prototype.greyscale;var mv={exports:{}};!function(t){(function(){var e;(function(e){t.exports=e})(e={linear:function(t,e,i,s){return i*t/s+e},easeInQuad:function(t,e,i,s){return i*(t/=s)*t+e},easeOutQuad:function(t,e,i,s){return-i*(t/=s)*(t-2)+e},easeInOutQuad:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e},easeInCubic:function(t,e,i,s){return i*(t/=s)*t*t+e},easeOutCubic:function(t,e,i,s){return i*((t=t/s-1)*t*t+1)+e},easeInOutCubic:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e},easeInQuart:function(t,e,i,s){return i*(t/=s)*t*t*t+e},easeOutQuart:function(t,e,i,s){return-i*((t=t/s-1)*t*t*t-1)+e},easeInOutQuart:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e},easeInQuint:function(t,e,i,s){return i*(t/=s)*t*t*t*t+e},easeOutQuint:function(t,e,i,s){return i*((t=t/s-1)*t*t*t*t+1)+e},easeInOutQuint:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e},easeInSine:function(t,e,i,s){return-i*Math.cos(t/s*(Math.PI/2))+i+e},easeOutSine:function(t,e,i,s){return i*Math.sin(t/s*(Math.PI/2))+e},easeInOutSine:function(t,e,i,s){return-i/2*(Math.cos(Math.PI*t/s)-1)+e},easeInExpo:function(t,e,i,s){return 0===t?e:i*Math.pow(2,10*(t/s-1))+e},easeOutExpo:function(t,e,i,s){return t===s?e+i:i*(1-Math.pow(2,-10*t/s))+e},easeInOutExpo:function(t,e,i,s){return(t/=s/2)<1?i/2*Math.pow(2,10*(t-1))+e:i/2*(2-Math.pow(2,-10*--t))+e},easeInCirc:function(t,e,i,s){return-i*(Math.sqrt(1-(t/=s)*t)-1)+e},easeOutCirc:function(t,e,i,s){return i*Math.sqrt(1-(t=t/s-1)*t)+e},easeInOutCirc:function(t,e,i,s){return(t/=s/2)<1?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e},easeInElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)+e},easeOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/n)+i+e},easeInOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s/2),(n=0)||(n=s*(.3*1.5)),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*.5+i+e},easeInBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*(t/=s)*t*((r+1)*t-r)+e},easeOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeInOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInBounce:function(t,i,s,r){return s-e.easeOutBounce(r-t,0,s,r)+i},easeOutBounce:function(t,e,i,s){return(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e},easeInOutBounce:function(t,i,s,r){return t<r/2?.5*e.easeInBounce(2*t,0,s,r)+i:.5*e.easeOutBounce(2*t-r,0,s,r)+.5*s+i}})}).call(Ct)}(mv);const gv=Mt(mv.exports);Ty.prototype._renderCanvas=function(t){},Ty.prototype.renderCanvas=function(t){if(this.visible&&!(this.worldAlpha<=0)&&this.renderable){this._mask&&t.mask.pushMask(this._mask),this._renderCanvas(t);for(let e=0,i=this.children.length;e<i;++e)this.children[e].renderCanvas(t);this._mask&&t.mask.popMask(t)}},by.prototype.renderCanvas=function(t){},pv.prototype._renderCanvas=function(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),Sy.prototype._renderCanvas.call(this,t)},by.prototype.name=null,Ty.prototype.getChildByName=function(t,e){for(let i=0,s=this.children.length;i<s;i++)if(this.children[i].name===t)return this.children[i];if(e)for(let i=0,s=this.children.length;i<s;i++){const e=this.children[i];if(!e.getChildByName)continue;const s=e.getChildByName(t,!0);if(s)return s}return null};const yv={vec3(t,e,i,s){(i[0]!==s[0]||i[1]!==s[1]||i[2]!==s[2])&&(i[0]=s[0],i[1]=s[1],i[2]=s[2],t.uniform3f(e,s[0],s[1],s[2]))},int(t,e,i,s){t.uniform1i(e,s)},ivec2(t,e,i,s){t.uniform2i(e,s[0],s[1])},ivec3(t,e,i,s){t.uniform3i(e,s[0],s[1],s[2])},ivec4(t,e,i,s){t.uniform4i(e,s[0],s[1],s[2],s[3])},uint(t,e,i,s){t.uniform1ui(e,s)},uvec2(t,e,i,s){t.uniform2ui(e,s[0],s[1])},uvec3(t,e,i,s){t.uniform3ui(e,s[0],s[1],s[2])},uvec4(t,e,i,s){t.uniform4ui(e,s[0],s[1],s[2],s[3])},bvec2(t,e,i,s){t.uniform2i(e,s[0],s[1])},bvec3(t,e,i,s){t.uniform3i(e,s[0],s[1],s[2])},bvec4(t,e,i,s){t.uniform4i(e,s[0],s[1],s[2],s[3])},mat2(t,e,i,s){t.uniformMatrix2fv(e,!1,s)},mat4(t,e,i,s){t.uniformMatrix4fv(e,!1,s)}},vv={float(t,e,i,s){t.uniform1fv(e,s)},vec2(t,e,i,s){t.uniform2fv(e,s)},vec3(t,e,i,s){t.uniform3fv(e,s)},vec4(t,e,i,s){t.uniform4fv(e,s)},int(t,e,i,s){t.uniform1iv(e,s)},ivec2(t,e,i,s){t.uniform2iv(e,s)},ivec3(t,e,i,s){t.uniform3iv(e,s)},ivec4(t,e,i,s){t.uniform4iv(e,s)},uint(t,e,i,s){t.uniform1uiv(e,s)},uvec2(t,e,i,s){t.uniform2uiv(e,s)},uvec3(t,e,i,s){t.uniform3uiv(e,s)},uvec4(t,e,i,s){t.uniform4uiv(e,s)},bool(t,e,i,s){t.uniform1iv(e,s)},bvec2(t,e,i,s){t.uniform2iv(e,s)},bvec3(t,e,i,s){t.uniform3iv(e,s)},bvec4(t,e,i,s){t.uniform4iv(e,s)},sampler2D(t,e,i,s){t.uniform1iv(e,s)},samplerCube(t,e,i,s){t.uniform1iv(e,s)},sampler2DArray(t,e,i,s){t.uniform1iv(e,s)}};Object.assign(Xg.prototype,{systemCheck(){},syncUniforms(t,e){const{shader:i,renderer:s}=this;!function(t,e,i,s,r){let n=0,o=null,a=null;const l=r.gl;for(const h in t.uniforms){const u=e[h],c=s[h],d=i[h],p=t.uniforms[h];u?"float"!==u.type||1!==u.size||u.isArray?"bool"!==u.type||1!==u.size||u.isArray?"sampler2D"!==u.type&&"samplerCube"!==u.type&&"sampler2DArray"!==u.type||1!==u.size||u.isArray?"mat3"!==u.type||1!==u.size||u.isArray?"vec2"!==u.type||1!==u.size||u.isArray?"vec4"!==u.type||1!==u.size||u.isArray?(1!==u.size||u.isArray?vv:yv)[u.type].call(null,l,d.location,d.value,c):void 0!==p.width?(a=d.value,o=c,(a[0]!==o.x||a[1]!==o.y||a[2]!==o.width||a[3]!==o.height)&&(a[0]=o.x,a[1]=o.y,a[2]=o.width,a[3]=o.height,l.uniform4f(d.location,o.x,o.y,o.width,o.height))):(a=d.value,o=c,(a[0]!==o[0]||a[1]!==o[1]||a[2]!==o[2]||a[3]!==o[3])&&(a[0]=o[0],a[1]=o[1],a[2]=o[2],a[3]=o[3],l.uniform4f(d.location,o[0],o[1],o[2],o[3]))):void 0!==p.x?(a=d.value,o=c,(a[0]!==o.x||a[1]!==o.y)&&(a[0]=o.x,a[1]=o.y,l.uniform2f(d.location,o.x,o.y))):(a=d.value,o=c,(a[0]!==o[0]||a[1]!==o[1])&&(a[0]=o[0],a[1]=o[1],l.uniform2f(d.location,o[0],o[1]))):void 0!==p.a?l.uniformMatrix3fv(d.location,!1,c.toArray(!0)):l.uniformMatrix3fv(d.location,!1,c):(r.texture.bind(c,n),d.value!==n&&(d.value=n,l.uniform1i(d.location,n)),n++):c!==d.value&&(d.value=c,l.uniform1i(d.location,Number(c))):c!==d.value&&(d.value=c,l.uniform1f(d.location,c)):!0===p.group&&r.shader.syncUniformGroup(c)}}(t,i.program.uniformData,e.uniformData,t.uniforms,s)}});const xv=new class{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}init(t){this.removeTickerListener(),this.events=t,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(t){this._pauseUpdate=t}addTickerListener(){this.tickerAdded||!this.domElement||(ey.system.add(this.tickerUpdate,this,Zg.INTERACTION),this.tickerAdded=!0)}removeTickerListener(){this.tickerAdded&&(ey.system.remove(this.tickerUpdate,this),this.tickerAdded=!1)}pointerMoved(){this._didMove=!0}update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove)return void(this._didMove=!1);const t=this.events.rootPointerEvent;this.events.supportsTouchEvents&&"touch"===t.pointerType||globalThis.document.dispatchEvent(new PointerEvent("pointermove",{clientX:t.clientX,clientY:t.clientY}))}tickerUpdate(t){this._deltaTime+=t,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this.update())}};class bv{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=bv.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new jf,this.page=new jf,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=t}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(t,e,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(t,e,i,s,r){throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}preventDefault(){this.nativeEvent instanceof Event&&this.nativeEvent.cancelable&&this.nativeEvent.preventDefault(),this.defaultPrevented=!0}stopImmediatePropagation(){this.propagationImmediatelyStopped=!0}stopPropagation(){this.propagationStopped=!0}}class _v extends bv{constructor(){super(...arguments),this.client=new jf,this.movement=new jf,this.offset=new jf,this.global=new jf,this.screen=new jf}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(t,e,i){return t.worldTransform.applyInverse(i||this.global,e)}getModifierState(t){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(t)}initMouseEvent(t,e,i,s,r,n,o,a,l,h,u,c,d,p,f){throw new Error("Method not implemented.")}}class wv extends _v{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return"pointermove"===this.type||"mousemove"===this.type||"touchmove"===this.type?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class Pv extends _v{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}Pv.DOM_DELTA_PIXEL=0,Pv.DOM_DELTA_LINE=1,Pv.DOM_DELTA_PAGE=2;const Ev=new jf,Tv=new jf;class Av{constructor(t){this.dispatch=new Sh,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=t,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel)}addEventMapping(t,e){this.mappingTable[t]||(this.mappingTable[t]=[]),this.mappingTable[t].push({fn:e,priority:0}),this.mappingTable[t].sort(((t,e)=>t.priority-e.priority))}dispatchEvent(t,e){t.propagationStopped=!1,t.propagationImmediatelyStopped=!1,this.propagate(t,e),this.dispatch.emit(e||t.type,t)}mapEvent(t){if(!this.rootTarget)return;const e=this.mappingTable[t.type];if(e)for(let i=0,s=e.length;i<s;i++)e[i].fn(t);else console.warn(`[EventBoundary]: Event mapping not defined for ${t.type}`)}hitTest(t,e){xv.pauseUpdate=!0;const i=this[this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive"](this.rootTarget,this.rootTarget.eventMode,Ev.set(t,e),this.hitTestFn,this.hitPruneFn);return i&&i[0]}propagate(t,e){if(!t.target)return;const i=t.composedPath();t.eventPhase=t.CAPTURING_PHASE;for(let s=0,r=i.length-1;s<r;s++)if(t.currentTarget=i[s],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return;if(t.eventPhase=t.AT_TARGET,t.currentTarget=t.target,this.notifyTarget(t,e),!t.propagationStopped&&!t.propagationImmediatelyStopped){t.eventPhase=t.BUBBLING_PHASE;for(let s=i.length-2;s>=0;s--)if(t.currentTarget=i[s],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return}}all(t,e,i=this._allInteractiveElements){if(0===i.length)return;t.eventPhase=t.BUBBLING_PHASE;const s=Array.isArray(e)?e:[e];for(let r=i.length-1;r>=0;r--)s.forEach((e=>{t.currentTarget=i[r],this.notifyTarget(t,e)}))}propagationPath(t){const e=[t];for(let i=0;i<2048&&t!==this.rootTarget;i++){if(!t.parent)throw new Error("Cannot find propagation path to disconnected target");e.push(t.parent),t=t.parent}return e.reverse(),e}hitTestMoveRecursive(t,e,i,s,r,n=!1){let o=!1;if(this._interactivePrune(t))return null;if(("dynamic"===t.eventMode||"dynamic"===e)&&(xv.pauseUpdate=!1),t.interactiveChildren&&t.children){const a=t.children;for(let l=a.length-1;l>=0;l--){const h=a[l],u=this.hitTestMoveRecursive(h,this._isInteractive(e)?e:h.eventMode,i,s,r,n||r(t,i));if(u){if(u.length>0&&!u[u.length-1].parent)continue;const e=t.isInteractive();(u.length>0||e)&&(e&&this._allInteractiveElements.push(t),u.push(t)),0===this._hitElements.length&&(this._hitElements=u),o=!0}}}const a=this._isInteractive(e),l=t.isInteractive();return a&&l&&this._allInteractiveElements.push(t),n||this._hitElements.length>0?null:o?this._hitElements:a&&!r(t,i)&&s(t,i)?l?[t]:[]:null}hitTestRecursive(t,e,i,s,r){if(this._interactivePrune(t)||r(t,i))return null;if(("dynamic"===t.eventMode||"dynamic"===e)&&(xv.pauseUpdate=!1),t.interactiveChildren&&t.children){const n=t.children;for(let o=n.length-1;o>=0;o--){const a=n[o],l=this.hitTestRecursive(a,this._isInteractive(e)?e:a.eventMode,i,s,r);if(l){if(l.length>0&&!l[l.length-1].parent)continue;const e=t.isInteractive();return(l.length>0||e)&&l.push(t),l}}}const n=this._isInteractive(e),o=t.isInteractive();return n&&s(t,i)?o?[t]:[]:null}_isInteractive(t){return"static"===t||"dynamic"===t}_interactivePrune(t){return!(t&&!t.isMask&&t.visible&&t.renderable&&"none"!==t.eventMode&&("passive"!==t.eventMode||t.interactiveChildren)&&!t.isMask)}hitPruneFn(t,e){var i;if(t.hitArea&&(t.worldTransform.applyInverse(e,Tv),!t.hitArea.contains(Tv.x,Tv.y)))return!0;if(t._mask){const s=t._mask.isMaskData?t._mask.maskObject:t._mask;if(s&&!(null==(i=s.containsPoint)?void 0:i.call(s,e)))return!0}return!1}hitTestFn(t,e){return"passive"!==t.eventMode&&(!!t.hitArea||!!t.containsPoint&&t.containsPoint(e))}notifyTarget(t,e){var i,s;const r=`on${e=e??t.type}`;null==(s=(i=t.currentTarget)[r])||s.call(i,t);const n=t.eventPhase===t.CAPTURING_PHASE||t.eventPhase===t.AT_TARGET?`${e}capture`:e;this.notifyListeners(t,n),t.eventPhase===t.AT_TARGET&&this.notifyListeners(t,e)}mapPointerDown(t){if(!(t instanceof wv))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=this.createPointerEvent(t);if(this.dispatchEvent(e,"pointerdown"),"touch"===e.pointerType)this.dispatchEvent(e,"touchstart");else if("mouse"===e.pointerType||"pen"===e.pointerType){const t=2===e.button;this.dispatchEvent(e,t?"rightdown":"mousedown")}this.trackingData(t.pointerId).pressTargetsByButton[t.button]=e.composedPath(),this.freeEvent(e)}mapPointerMove(t){var e,i;if(!(t instanceof wv))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const s=this.createPointerEvent(t);this._isPointerMoveEvent=!1;const r="mouse"===s.pointerType||"pen"===s.pointerType,n=this.trackingData(t.pointerId),o=this.findMountedTarget(n.overTargets);if((null==(e=n.overTargets)?void 0:e.length)>0&&o!==s.target){const e="mousemove"===t.type?"mouseout":"pointerout",i=this.createPointerEvent(t,e,o);if(this.dispatchEvent(i,"pointerout"),r&&this.dispatchEvent(i,"mouseout"),!s.composedPath().includes(o)){const e=this.createPointerEvent(t,"pointerleave",o);for(e.eventPhase=e.AT_TARGET;e.target&&!s.composedPath().includes(e.target);)e.currentTarget=e.target,this.notifyTarget(e),r&&this.notifyTarget(e,"mouseleave"),e.target=e.target.parent;this.freeEvent(e)}this.freeEvent(i)}if(o!==s.target){const e="mousemove"===t.type?"mouseover":"pointerover",i=this.clonePointerEvent(s,e);this.dispatchEvent(i,"pointerover"),r&&this.dispatchEvent(i,"mouseover");let n=null==o?void 0:o.parent;for(;n&&n!==this.rootTarget.parent&&n!==s.target;)n=n.parent;if(!n||n===this.rootTarget.parent){const t=this.clonePointerEvent(s,"pointerenter");for(t.eventPhase=t.AT_TARGET;t.target&&t.target!==o&&t.target!==this.rootTarget.parent;)t.currentTarget=t.target,this.notifyTarget(t),r&&this.notifyTarget(t,"mouseenter"),t.target=t.target.parent;this.freeEvent(t)}this.freeEvent(i)}const a=[],l=this.enableGlobalMoveEvents??!0;this.moveOnAll?a.push("pointermove"):this.dispatchEvent(s,"pointermove"),l&&a.push("globalpointermove"),"touch"===s.pointerType&&(this.moveOnAll?a.splice(1,0,"touchmove"):this.dispatchEvent(s,"touchmove"),l&&a.push("globaltouchmove")),r&&(this.moveOnAll?a.splice(1,0,"mousemove"):this.dispatchEvent(s,"mousemove"),l&&a.push("globalmousemove"),this.cursor=null==(i=s.target)?void 0:i.cursor),a.length>0&&this.all(s,a),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=s.composedPath(),this.freeEvent(s)}mapPointerOver(t){var e;if(!(t instanceof wv))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const i=this.trackingData(t.pointerId),s=this.createPointerEvent(t),r="mouse"===s.pointerType||"pen"===s.pointerType;this.dispatchEvent(s,"pointerover"),r&&this.dispatchEvent(s,"mouseover"),"mouse"===s.pointerType&&(this.cursor=null==(e=s.target)?void 0:e.cursor);const n=this.clonePointerEvent(s,"pointerenter");for(n.eventPhase=n.AT_TARGET;n.target&&n.target!==this.rootTarget.parent;)n.currentTarget=n.target,this.notifyTarget(n),r&&this.notifyTarget(n,"mouseenter"),n.target=n.target.parent;i.overTargets=s.composedPath(),this.freeEvent(s),this.freeEvent(n)}mapPointerOut(t){if(!(t instanceof wv))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=this.trackingData(t.pointerId);if(e.overTargets){const i="mouse"===t.pointerType||"pen"===t.pointerType,s=this.findMountedTarget(e.overTargets),r=this.createPointerEvent(t,"pointerout",s);this.dispatchEvent(r),i&&this.dispatchEvent(r,"mouseout");const n=this.createPointerEvent(t,"pointerleave",s);for(n.eventPhase=n.AT_TARGET;n.target&&n.target!==this.rootTarget.parent;)n.currentTarget=n.target,this.notifyTarget(n),i&&this.notifyTarget(n,"mouseleave"),n.target=n.target.parent;e.overTargets=null,this.freeEvent(r),this.freeEvent(n)}this.cursor=null}mapPointerUp(t){if(!(t instanceof wv))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=performance.now(),i=this.createPointerEvent(t);if(this.dispatchEvent(i,"pointerup"),"touch"===i.pointerType)this.dispatchEvent(i,"touchend");else if("mouse"===i.pointerType||"pen"===i.pointerType){const t=2===i.button;this.dispatchEvent(i,t?"rightup":"mouseup")}const s=this.trackingData(t.pointerId),r=this.findMountedTarget(s.pressTargetsByButton[t.button]);let n=r;if(r&&!i.composedPath().includes(r)){let e=r;for(;e&&!i.composedPath().includes(e);){if(i.currentTarget=e,this.notifyTarget(i,"pointerupoutside"),"touch"===i.pointerType)this.notifyTarget(i,"touchendoutside");else if("mouse"===i.pointerType||"pen"===i.pointerType){const t=2===i.button;this.notifyTarget(i,t?"rightupoutside":"mouseupoutside")}e=e.parent}delete s.pressTargetsByButton[t.button],n=e}if(n){const r=this.clonePointerEvent(i,"click");r.target=n,r.path=null,s.clicksByButton[t.button]||(s.clicksByButton[t.button]={clickCount:0,target:r.target,timeStamp:e});const o=s.clicksByButton[t.button];if(o.target===r.target&&e-o.timeStamp<200?++o.clickCount:o.clickCount=1,o.target=r.target,o.timeStamp=e,r.detail=o.clickCount,"mouse"===r.pointerType){const t=2===r.button;this.dispatchEvent(r,t?"rightclick":"click")}else"touch"===r.pointerType&&this.dispatchEvent(r,"tap");this.dispatchEvent(r,"pointertap"),this.freeEvent(r)}this.freeEvent(i)}mapPointerUpOutside(t){if(!(t instanceof wv))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=this.trackingData(t.pointerId),i=this.findMountedTarget(e.pressTargetsByButton[t.button]),s=this.createPointerEvent(t);if(i){let r=i;for(;r;)s.currentTarget=r,this.notifyTarget(s,"pointerupoutside"),"touch"===s.pointerType?this.notifyTarget(s,"touchendoutside"):("mouse"===s.pointerType||"pen"===s.pointerType)&&this.notifyTarget(s,2===s.button?"rightupoutside":"mouseupoutside"),r=r.parent;delete e.pressTargetsByButton[t.button]}this.freeEvent(s)}mapWheel(t){if(!(t instanceof Pv))return void console.warn("EventBoundary cannot map a non-wheel event as a wheel event");const e=this.createWheelEvent(t);this.dispatchEvent(e),this.freeEvent(e)}findMountedTarget(t){if(!t)return null;let e=t[0];for(let i=1;i<t.length&&t[i].parent===e;i++)e=t[i];return e}createPointerEvent(t,e,i){const s=this.allocateEvent(wv);return this.copyPointerData(t,s),this.copyMouseData(t,s),this.copyData(t,s),s.nativeEvent=t.nativeEvent,s.originalEvent=t,s.target=i??this.hitTest(s.global.x,s.global.y)??this._hitElements[0],"string"==typeof e&&(s.type=e),s}createWheelEvent(t){const e=this.allocateEvent(Pv);return this.copyWheelData(t,e),this.copyMouseData(t,e),this.copyData(t,e),e.nativeEvent=t.nativeEvent,e.originalEvent=t,e.target=this.hitTest(e.global.x,e.global.y),e}clonePointerEvent(t,e){const i=this.allocateEvent(wv);return i.nativeEvent=t.nativeEvent,i.originalEvent=t.originalEvent,this.copyPointerData(t,i),this.copyMouseData(t,i),this.copyData(t,i),i.target=t.target,i.path=t.composedPath().slice(),i.type=e??i.type,i}copyWheelData(t,e){e.deltaMode=t.deltaMode,e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ}copyPointerData(t,e){t instanceof wv&&e instanceof wv&&(e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist)}copyMouseData(t,e){t instanceof _v&&e instanceof _v&&(e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.copyFrom(t.client),e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.copyFrom(t.movement),e.screen.copyFrom(t.screen),e.shiftKey=t.shiftKey,e.global.copyFrom(t.global))}copyData(t,e){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.detail=t.detail,e.view=t.view,e.which=t.which,e.layer.copyFrom(t.layer),e.page.copyFrom(t.page)}trackingData(t){return this.mappingState.trackingData[t]||(this.mappingState.trackingData[t]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[t]}allocateEvent(t){this.eventPool.has(t)||this.eventPool.set(t,[]);const e=this.eventPool.get(t).pop()||new t(this);return e.eventPhase=e.NONE,e.currentTarget=null,e.path=null,e.target=null,e}freeEvent(t){if(t.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const e=t.constructor;this.eventPool.has(e)||this.eventPool.set(e,[]),this.eventPool.get(e).push(t)}notifyListeners(t,e){const i=t.currentTarget._events[e];if(i&&t.currentTarget.isInteractive())if("fn"in i)i.once&&t.currentTarget.removeListener(e,i.fn,void 0,!0),i.fn.call(i.context,t);else for(let s=0,r=i.length;s<r&&!t.propagationImmediatelyStopped;s++)i[s].once&&t.currentTarget.removeListener(e,i[s].fn,void 0,!0),i[s].fn.call(i[s].context,t)}}const Iv={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},Sv=class t{constructor(e){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=e,this.rootBoundary=new Av(null),xv.init(this),this.autoPreventDefault=!0,this.eventsAdded=!1,this.rootPointerEvent=new wv(null),this.rootWheelEvent=new Pv(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...t.defaultEventFeatures},{set:(t,e,i)=>("globalMove"===e&&(this.rootBoundary.enableGlobalMoveEvents=i),t[e]=i,!0)}),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this),this.onPointerOverOut=this.onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{view:i,resolution:s}=this.renderer;this.setTargetElement(i),this.resolution=s,t._defaultEventMode=e.eventMode??"auto",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(t){this.resolution=t}destroy(){this.setTargetElement(null),this.renderer=null}setCursor(t){t=t||"default";let e=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(e=!1),this.currentCursor===t)return;this.currentCursor=t;const i=this.cursorStyles[t];if(i)switch(typeof i){case"string":e&&(this.domElement.style.cursor=i);break;case"function":i(t);break;case"object":e&&Object.assign(this.domElement.style,i)}else e&&"string"==typeof t&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,t)&&(this.domElement.style.cursor=t)}get pointer(){return this.rootPointerEvent}onPointerDown(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);this.autoPreventDefault&&e[0].isNormalized&&(t.cancelable||!("cancelable"in t))&&t.preventDefault();for(let i=0,s=e.length;i<s;i++){const t=e[i],s=this.bootstrapEvent(this.rootPointerEvent,t);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onPointerMove(t){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,xv.pointerMoved();const e=this.normalizeToPointerData(t);for(let i=0,s=e.length;i<s;i++){const t=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(t)}this.setCursor(this.rootBoundary.cursor)}onPointerUp(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let e=t.target;t.composedPath&&t.composedPath().length>0&&(e=t.composedPath()[0]);const i=e!==this.domElement?"outside":"",s=this.normalizeToPointerData(t);for(let r=0,n=s.length;r<n;r++){const t=this.bootstrapEvent(this.rootPointerEvent,s[r]);t.type+=i,this.rootBoundary.mapEvent(t)}this.setCursor(this.rootBoundary.cursor)}onPointerOverOut(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);for(let i=0,s=e.length;i<s;i++){const t=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(t)}this.setCursor(this.rootBoundary.cursor)}onWheel(t){if(!this.features.wheel)return;const e=this.normalizeWheelEvent(t);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(e)}setTargetElement(t){this.removeEvents(),this.domElement=t,xv.domElement=t,this.addEvents()}addEvents(){if(this.eventsAdded||!this.domElement)return;xv.addTickerListener();const t=this.domElement.style;t&&(globalThis.navigator.msPointerEnabled?(t.msContentZooming="none",t.msTouchAction="none"):this.supportsPointerEvents&&(t.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this.onPointerMove,!0),this.domElement.addEventListener("pointerdown",this.onPointerDown,!0),this.domElement.addEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this.onPointerOverOut,!0),globalThis.addEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this.onPointerMove,!0),this.domElement.addEventListener("mousedown",this.onPointerDown,!0),this.domElement.addEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this.onPointerOverOut,!0),globalThis.addEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this.onPointerDown,!0),this.domElement.addEventListener("touchend",this.onPointerUp,!0),this.domElement.addEventListener("touchmove",this.onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this.eventsAdded=!0}removeEvents(){if(!this.eventsAdded||!this.domElement)return;xv.removeTickerListener();const t=this.domElement.style;globalThis.navigator.msPointerEnabled?(t.msContentZooming="",t.msTouchAction=""):this.supportsPointerEvents&&(t.touchAction=""),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this.onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this.onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this.onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this.onPointerMove,!0),this.domElement.removeEventListener("mousedown",this.onPointerDown,!0),this.domElement.removeEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this.onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this.onPointerDown,!0),this.domElement.removeEventListener("touchend",this.onPointerUp,!0),this.domElement.removeEventListener("touchmove",this.onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement=null,this.eventsAdded=!1}mapPositionToPoint(t,e,i){const s=this.domElement.isConnected?this.domElement.getBoundingClientRect():{x:0,y:0,width:this.domElement.width,height:this.domElement.height,left:0,top:0},r=1/this.resolution;t.x=(e-s.left)*(this.domElement.width/s.width)*r,t.y=(i-s.top)*(this.domElement.height/s.height)*r}normalizeToPointerData(t){const e=[];if(this.supportsTouchEvents&&t instanceof TouchEvent)for(let i=0,s=t.changedTouches.length;i<s;i++){const s=t.changedTouches[i];typeof s.button>"u"&&(s.button=0),typeof s.buttons>"u"&&(s.buttons=1),typeof s.isPrimary>"u"&&(s.isPrimary=1===t.touches.length&&"touchstart"===t.type),typeof s.width>"u"&&(s.width=s.radiusX||1),typeof s.height>"u"&&(s.height=s.radiusY||1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="touch"),typeof s.pointerId>"u"&&(s.pointerId=s.identifier||0),typeof s.pressure>"u"&&(s.pressure=s.force||.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),typeof s.layerX>"u"&&(s.layerX=s.offsetX=s.clientX),typeof s.layerY>"u"&&(s.layerY=s.offsetY=s.clientY),s.isNormalized=!0,s.type=t.type,e.push(s)}else if(globalThis.MouseEvent&&(!(t instanceof MouseEvent)||this.supportsPointerEvents&&t instanceof globalThis.PointerEvent))e.push(t);else{const i=t;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=1),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,e.push(i)}return e}normalizeWheelEvent(t){const e=this.rootWheelEvent;return this.transferMouseData(e,t),e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ,e.deltaMode=t.deltaMode,this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.nativeEvent=t,e.type=t.type,e}bootstrapEvent(t,e){return t.originalEvent=null,t.nativeEvent=e,t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist,this.transferMouseData(t,e),this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.isTrusted=e.isTrusted,"pointerleave"===t.type&&(t.type="pointerout"),t.type.startsWith("mouse")&&(t.type=t.type.replace("mouse","pointer")),t.type.startsWith("touch")&&(t.type=Iv[t.type]||t.type),t}transferMouseData(t,e){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.x=e.clientX,t.client.y=e.clientY,t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.x=e.movementX,t.movement.y=e.movementY,t.page.x=e.pageX,t.page.y=e.pageY,t.relatedTarget=null,t.shiftKey=e.shiftKey}};Sv.extension={name:"events",type:[gf.RendererSystem,gf.CanvasRendererSystem]},Sv.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let Cv=Sv;function Mv(t){return"dynamic"===t||"static"===t}xf.add(Cv);const Ov={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,_internalInteractive:void 0,get interactive(){return this._internalInteractive??Mv(Cv.defaultEventMode)},set interactive(t){op("7.2.0","Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."),this._internalInteractive=t,this.eventMode=t?"static":"auto"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??Cv.defaultEventMode},set eventMode(t){this._internalInteractive=Mv(t),this._internalEventMode=t},isInteractive(){return"static"===this.eventMode||"dynamic"===this.eventMode},interactiveChildren:!0,hitArea:null,addEventListener(t,e,i){const s="boolean"==typeof i&&i||"object"==typeof i&&i.capture,r="object"==typeof i?i.signal:void 0,n="object"==typeof i&&!0===i.once,o="function"==typeof e?void 0:e;t=s?`${t}capture`:t;const a="function"==typeof e?e:e.handleEvent,l=this;r&&r.addEventListener("abort",(()=>{l.off(t,a,o)})),n?l.once(t,a,o):l.on(t,a,o)},removeEventListener(t,e,i){const s="function"==typeof e?void 0:e;t="boolean"==typeof i&&i||"object"==typeof i&&i.capture?`${t}capture`:t,e="function"==typeof e?e:e.handleEvent,this.off(t,e,s)},dispatchEvent(t){if(!(t instanceof bv))throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");return t.defaultPrevented=!1,t.path=null,t.target=this,t.manager.dispatchEvent(t),!t.defaultPrevented}};by.mixin(Ov);const Nv=new Vf;class Lv{constructor(t){this.renderer=t}async image(t,e,i,s){const r=new Image;return r.src=await this.base64(t,e,i,s),r}async base64(t,e,i,s){const r=this.canvas(t,s);if(void 0!==r.toBlob)return new Promise(((t,s)=>{r.toBlob((e=>{if(!e)return void s(new Error("ICanvas.toBlob failed!"));const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s,i.readAsDataURL(e)}),e,i)}));if(void 0!==r.toDataURL)return r.toDataURL(e,i);if(void 0!==r.convertToBlob){const t=await r.convertToBlob({type:e,quality:i});return new Promise(((e,i)=>{const s=new FileReader;s.onload=()=>e(s.result),s.onerror=i,s.readAsDataURL(t)}))}throw new Error("CanvasExtract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(t,e){const i=this.renderer;if(!i)throw new Error("The CanvasExtract has already been destroyed");let s,r,n;t&&(t instanceof eg?n=t:(n=i.generateTexture(t,{region:e,resolution:i.resolution}),e&&(Nv.width=e.width,Nv.height=e.height,e=Nv))),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=i.canvasContext.rootContext,r=i._view.resolution,e||((e=Nv).width=i.width/r,e.height=i.height/r));const o=Math.round(e.x*r),a=Math.round(e.y*r),l=Math.max(Math.round(e.width*r),1),h=Math.max(Math.round(e.height*r),1),u=new lf(l,h,1),c=s.getImageData(o,a,l,h);return u.context.putImageData(c,0,0),u.canvas}pixels(t,e){const i=this.renderer;if(!i)throw new Error("The CanvasExtract has already been destroyed");let s,r,n;t&&(t instanceof eg?n=t:(n=i.generateTexture(t,{region:e,resolution:i.resolution}),e&&(Nv.width=e.width,Nv.height=e.height,e=Nv))),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=i.canvasContext.rootContext,r=i.resolution,e||((e=Nv).width=i.width/r,e.height=i.height/r));const o=Math.round(e.x*r),a=Math.round(e.y*r),l=Math.max(Math.round(e.width*r),1),h=Math.max(Math.round(e.height*r),1);return s.getImageData(o,a,l,h).data}destroy(){this.renderer=null}}let Rv;function kv(t){const e=lh.ADAPTER.createCanvas(6,1),i=e.getContext("2d");return i.fillStyle=t,i.fillRect(0,0,6,1),e}function Bv(){if(typeof document>"u")return!1;if(void 0!==Rv)return Rv;const t=kv("#ff00ff"),e=kv("#ffff00"),i=lh.ADAPTER.createCanvas(6,1).getContext("2d");i.globalCompositeOperation="multiply",i.drawImage(t,0,0),i.drawImage(e,2,0);const s=i.getImageData(2,0,1,1);if(s){const t=s.data;Rv=255===t[0]&&0===t[1]&&0===t[2]}else Rv=!1;return Rv}Lv.extension={name:"extract",type:gf.CanvasRendererSystem},xf.add(Lv),Of.prototype.getDrawableSource=function(){const t=this.resource;return t?t.bitmap||t.source:null},Vm.prototype._canvasRenderTarget=null,tg.prototype.patternCache=null,tg.prototype.tintCache=null;const Fv=new Qf;class Dv{constructor(t){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=function(t=[]){return Bv()?(t[jl.NORMAL]="source-over",t[jl.ADD]="lighter",t[jl.MULTIPLY]="multiply",t[jl.SCREEN]="screen",t[jl.OVERLAY]="overlay",t[jl.DARKEN]="darken",t[jl.LIGHTEN]="lighten",t[jl.COLOR_DODGE]="color-dodge",t[jl.COLOR_BURN]="color-burn",t[jl.HARD_LIGHT]="hard-light",t[jl.SOFT_LIGHT]="soft-light",t[jl.DIFFERENCE]="difference",t[jl.EXCLUSION]="exclusion",t[jl.HUE]="hue",t[jl.SATURATION]="saturation",t[jl.COLOR]="color",t[jl.LUMINOSITY]="luminosity"):(t[jl.NORMAL]="source-over",t[jl.ADD]="lighter",t[jl.MULTIPLY]="source-over",t[jl.SCREEN]="source-over",t[jl.OVERLAY]="source-over",t[jl.DARKEN]="source-over",t[jl.LIGHTEN]="source-over",t[jl.COLOR_DODGE]="source-over",t[jl.COLOR_BURN]="source-over",t[jl.HARD_LIGHT]="source-over",t[jl.SOFT_LIGHT]="source-over",t[jl.DIFFERENCE]="source-over",t[jl.EXCLUSION]="source-over",t[jl.HUE]="source-over",t[jl.SATURATION]="source-over",t[jl.COLOR]="source-over",t[jl.LUMINOSITY]="source-over"),t[jl.NORMAL_NPM]=t[jl.NORMAL],t[jl.ADD_NPM]=t[jl.ADD],t[jl.SCREEN_NPM]=t[jl.SCREEN],t[jl.SRC_IN]="source-in",t[jl.SRC_OUT]="source-out",t[jl.SRC_ATOP]="source-atop",t[jl.DST_OVER]="destination-over",t[jl.DST_IN]="destination-in",t[jl.DST_OUT]="destination-out",t[jl.DST_ATOP]="destination-atop",t[jl.XOR]="xor",t[jl.SUBTRACT]="source-over",t}(),this._activeBlendMode=null,this._projTransform=null,this._outerBlend=!1,this.renderer=t}init(){const t=this.renderer.background.alpha<1;if(this.rootContext=this.renderer.view.getContext("2d",{alpha:t}),this.activeContext=this.rootContext,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(t,e,i){let s=t;const r=this._projTransform,n=this.activeResolution;i=i||n,r&&(s=Fv,s.copyFrom(t),s.prepend(r)),e?this.activeContext.setTransform(s.a*i,s.b*i,s.c*i,s.d*i,s.tx*n|0,s.ty*n|0):this.activeContext.setTransform(s.a*i,s.b*i,s.c*i,s.d*i,s.tx*n,s.ty*n)}clear(t,e){const{activeContext:i,renderer:s}=this,r=t?Hp.shared.setValue(t):this.renderer.background.backgroundColor;i.clearRect(0,0,s.width,s.height),t&&(i.globalAlpha=e??this.renderer.background.alpha,i.fillStyle=r.toHex(),i.fillRect(0,0,s.width,s.height),i.globalAlpha=1)}setBlendMode(t,e){const i=t===jl.SRC_IN||t===jl.SRC_OUT||t===jl.DST_IN||t===jl.DST_ATOP;!e&&i&&(t=jl.NORMAL),this._activeBlendMode!==t&&(this._activeBlendMode=t,this._outerBlend=i,this.activeContext.globalCompositeOperation=this.blendModes[t])}resize(){this.smoothProperty&&(this.rootContext[this.smoothProperty]=Of.defaultOptions.scaleMode===Zl.LINEAR)}invalidateBlendMode(){this._activeBlendMode=this.blendModes.indexOf(this.activeContext.globalCompositeOperation)}destroy(){this.renderer=null,this.rootContext=null,this.activeContext=null,this.smoothProperty=null}}Dv.extension={type:gf.CanvasRendererSystem,name:"canvasContext"},xf.add(Dv);class Uv{constructor(t){this._foundShapes=[],this.renderer=t}pushMask(t){const e=this.renderer,i=t.maskObject||t;e.canvasContext.activeContext.save();const s=this._foundShapes;if(this.recursiveFindShapes(i,s),s.length>0){const t=e.canvasContext.activeContext;t.beginPath();for(let e=0;e<s.length;e++){const t=s[e],i=t.transform.worldTransform;this.renderer.canvasContext.setContextTransform(i),this.renderGraphicsShape(t)}s.length=0,t.clip()}}recursiveFindShapes(t,e){t.geometry&&t.geometry.graphicsData&&e.push(t);const{children:i}=t;if(i)for(let s=0;s<i.length;s++)this.recursiveFindShapes(i[s],e)}renderGraphicsShape(t){t.finishPoly();const e=this.renderer.canvasContext.activeContext,i=t.geometry.graphicsData,s=i.length;if(0!==s)for(let r=0;r<s;r++){const t=i[r],s=t.shape;if(s.type===$f.POLY){let i=s.points;const r=t.holes;let n,o,a,l;e.moveTo(i[0],i[1]);for(let t=1;t<i.length/2;t++)e.lineTo(i[2*t],i[2*t+1]);if(r.length>0){n=0,a=i[0],l=i[1];for(let t=2;t+2<i.length;t+=2)n+=(i[t]-a)*(i[t+3]-l)-(i[t+2]-a)*(i[t+1]-l);for(let t=0;t<r.length;t++)if(i=r[t].shape.points,i){o=0,a=i[0],l=i[1];for(let t=2;t+2<i.length;t+=2)o+=(i[t]-a)*(i[t+3]-l)-(i[t+2]-a)*(i[t+1]-l);if(o*n<0){e.moveTo(i[0],i[1]);for(let t=2;t<i.length;t+=2)e.lineTo(i[t],i[t+1])}else{e.moveTo(i[i.length-2],i[i.length-1]);for(let t=i.length-4;t>=0;t-=2)e.lineTo(i[t],i[t+1])}r[t].shape.closeStroke&&e.closePath()}}i[0]===i[i.length-2]&&i[1]===i[i.length-1]&&e.closePath()}else if(s.type===$f.RECT)e.rect(s.x,s.y,s.width,s.height),e.closePath();else if(s.type===$f.CIRC)e.arc(s.x,s.y,s.radius,0,2*Math.PI),e.closePath();else if(s.type===$f.ELIP){const t=2*s.width,i=2*s.height,r=s.x-t/2,n=s.y-i/2,o=.5522848,a=t/2*o,l=i/2*o,h=r+t,u=n+i,c=r+t/2,d=n+i/2;e.moveTo(r,d),e.bezierCurveTo(r,d-l,c-a,n,c,n),e.bezierCurveTo(c+a,n,h,d-l,h,d),e.bezierCurveTo(h,d+l,c+a,u,c,u),e.bezierCurveTo(c-a,u,r,d+l,r,d),e.closePath()}else if(s.type===$f.RREC){const t=s.x,i=s.y,r=s.width,n=s.height;let o=s.radius;const a=Math.min(r,n)/2;o=o>a?a:o,e.moveTo(t,i+o),e.lineTo(t,i+n-o),e.quadraticCurveTo(t,i+n,t+o,i+n),e.lineTo(t+r-o,i+n),e.quadraticCurveTo(t+r,i+n,t+r,i+n-o),e.lineTo(t+r,i+o),e.quadraticCurveTo(t+r,i,t+r-o,i),e.lineTo(t+o,i),e.quadraticCurveTo(t,i,t,i+o),e.closePath()}}}popMask(t){t.canvasContext.activeContext.restore(),t.canvasContext.invalidateBlendMode()}destroy(){}}Uv.extension={type:gf.CanvasRendererSystem,name:"mask"},xf.add(Uv);class Gv{constructor(t){this.renderer=t}render(t,e){const i=this.renderer;if(!i.view)return;const s=i.canvasContext;let r,n,o,a;e&&(r=e.renderTexture,n=e.clear,o=e.transform,a=e.skipUpdateTransform),this.renderingToScreen=!r,i.emit("prerender");const l=i.resolution;r?(r=r.castToBaseTexture(),r._canvasRenderTarget||(r._canvasRenderTarget=new lf(r.width,r.height,r.resolution),r.resource=new cy(r._canvasRenderTarget.canvas),r.valid=!0),s.activeContext=r._canvasRenderTarget.context,i.canvasContext.activeResolution=r._canvasRenderTarget.resolution):(s.activeContext=s.rootContext,s.activeResolution=l);const h=s.activeContext;if(s._projTransform=o||null,r||(this.lastObjectRendered=t),!a){const e=t.enableTempParent();t.updateTransform(),t.disableTempParent(e)}if(h.save(),h.setTransform(1,0,0,1,0,0),h.globalAlpha=1,s._activeBlendMode=jl.NORMAL,s._outerBlend=!1,h.globalCompositeOperation=s.blendModes[jl.NORMAL],n??i.background.clearBeforeRender)if(this.renderingToScreen){h.clearRect(0,0,i.width,i.height);const t=i.background;t.alpha>0&&(h.globalAlpha=t.backgroundColor.alpha,h.fillStyle=t.backgroundColor.toHex(),h.fillRect(0,0,i.width,i.height),h.globalAlpha=1)}else r._canvasRenderTarget.clear(),r.clear.alpha>0&&(h.globalAlpha=r.clear.alpha,h.fillStyle=r.clear.toHex(),h.fillRect(0,0,r.realWidth,r.realHeight),h.globalAlpha=1);const u=s.activeContext;s.activeContext=h,t.renderCanvas(i),s.activeContext=u,h.restore(),s.activeResolution=l,s._projTransform=null,i.emit("postrender")}destroy(){this.lastObjectRendered=null,this.render=null}}Gv.extension={type:gf.CanvasRendererSystem,name:"objectRenderer"},xf.add(Gv);const{deprecation:Xv}=mf,Wv=class t extends $g{constructor(e){super(),this.type=Yl.CANVAS,this.rendererLogId="Canvas",e=Object.assign({},lh.RENDER_OPTIONS,e);const i={runners:["init","destroy","contextChange","resolutionChange","reset","update","postrender","prerender","resize"],systems:t.__systems,priority:["textureGenerator","background","_view","_plugin","startup","mask","canvasContext","objectRenderer"]};this.setup(i),"useContextAlpha"in e&&(Xv("7.0.0","options.useContextAlpha is deprecated, use options.backgroundAlpha instead"),e.backgroundAlpha=!1===e.useContextAlpha?1:e.backgroundAlpha),this._plugin.rendererPlugins=t.__plugins,this.options=e,this.startup.run(this.options)}static test(){return!0}generateTexture(t,e){return this.textureGenerator.generateTexture(t,e)}reset(){}render(t,e){this.objectRenderer.render(t,e)}clear(){this.canvasContext.clear()}destroy(t){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:t}),super.destroy()}get plugins(){return this._plugin.plugins}resize(t,e){this._view.resizeView(t,e)}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}set resolution(t){this._view.resolution=t,this.runners.resolutionChange.emit(t)}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get clearBeforeRender(){return this.background.clearBeforeRender}get blendModes(){return Xv("7.0.0","renderer.blendModes has been deprecated, please use renderer.canvasContext.blendModes instead"),this.canvasContext.blendModes}get maskManager(){return Xv("7.0.0","renderer.maskManager has been deprecated, please use renderer.mask instead"),this.mask}get refresh(){return Xv("7.0.0","renderer.refresh has been deprecated"),!0}get rootContext(){return Xv("7.0.0","renderer.rootContext has been deprecated, please use renderer.canvasContext.rootContext instead"),this.canvasContext.rootContext}get context(){return Xv("7.0.0","renderer.context has been deprecated, please use renderer.canvasContext.activeContext instead"),this.canvasContext.activeContext}get smoothProperty(){return Xv("7.0.0","renderer.smoothProperty has been deprecated, please use renderer.canvasContext.smoothProperty instead"),this.canvasContext.smoothProperty}setBlendMode(t,e){Xv("7.0.0","renderer.setBlendMode has been deprecated, use renderer.canvasContext.setBlendMode instead"),this.canvasContext.setBlendMode(t,e)}invalidateBlendMode(){Xv("7.0.0","renderer.invalidateBlendMode has been deprecated, use renderer.canvasContext.invalidateBlendMode instead"),this.canvasContext.invalidateBlendMode()}setContextTransform(t,e,i){Xv("7.0.0","renderer.setContextTransform has been deprecated, use renderer.canvasContext.setContextTransform instead"),this.canvasContext.setContextTransform(t,e,i)}get backgroundColor(){return Xv("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){Xv("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return Xv("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){Xv("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get preserveDrawingBuffer(){return Xv("7.0.0","renderer.preserveDrawingBuffer has been deprecated"),!1}get useContextAlpha(){return Xv("7.0.0","renderer.useContextAlpha has been deprecated"),!1}};Wv.extension={type:gf.Renderer,priority:0},Wv.__plugins={},Wv.__systems={};let Hv=Wv;xf.handleByMap(gf.CanvasRendererPlugin,Hv.__plugins),xf.handleByMap(gf.CanvasRendererSystem,Hv.__systems),xf.add(Hv);const Yv={canvas:null,getTintedCanvas:(t,e)=>{const i=t.texture,s=Hp.shared.setValue(e).toHex();i.tintCache=i.tintCache||{};const r=i.tintCache[s];let n;if(r){if(r.tintId===i._updateID)return i.tintCache[s];n=i.tintCache[s]}else n=lh.ADAPTER.createCanvas();return Yv.tintMethod(i,e,n),n.tintId=i._updateID,Yv.convertTintToImage||(i.tintCache[s]=n),n},getTintedPattern:(t,e)=>{const i=Hp.shared.setValue(e).toHex();t.patternCache=t.patternCache||{};let s=t.patternCache[i];return(null==s?void 0:s.tintId)===t._updateID||(Yv.canvas||(Yv.canvas=lh.ADAPTER.createCanvas()),Yv.tintMethod(t,e,Yv.canvas),s=Yv.canvas.getContext("2d").createPattern(Yv.canvas,"repeat"),s.tintId=t._updateID,t.patternCache[i]=s),s},tintWithMultiply:(t,e,i)=>{const s=i.getContext("2d"),r=t._frame.clone(),n=t.baseTexture.resolution;r.x*=n,r.y*=n,r.width*=n,r.height*=n,i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),s.save(),s.fillStyle=Hp.shared.setValue(e).toHex(),s.fillRect(0,0,r.width,r.height),s.globalCompositeOperation="multiply";const o=t.baseTexture.getDrawableSource();s.drawImage(o,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.globalCompositeOperation="destination-atop",s.drawImage(o,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore()},tintWithOverlay:(t,e,i)=>{const s=i.getContext("2d"),r=t._frame.clone(),n=t.baseTexture.resolution;r.x*=n,r.y*=n,r.width*=n,r.height*=n,i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),s.save(),s.globalCompositeOperation="copy",s.fillStyle=`#${`00000${(0|e).toString(16)}`.slice(-6)}`,s.fillRect(0,0,r.width,r.height),s.globalCompositeOperation="destination-atop",s.drawImage(t.baseTexture.getDrawableSource(),r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore()},tintWithPerPixel:(t,e,i)=>{const s=i.getContext("2d"),r=t._frame.clone(),n=t.baseTexture.resolution;r.x*=n,r.y*=n,r.width*=n,r.height*=n,i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),s.save(),s.globalCompositeOperation="copy",s.drawImage(t.baseTexture.getDrawableSource(),r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore();const[o,a,l]=Hp.shared.setValue(e).toArray(),h=s.getImageData(0,0,r.width,r.height),u=h.data;for(let c=0;c<u.length;c+=4)u[c+0]*=o,u[c+1]*=a,u[c+2]*=l;s.putImageData(h,0,0)},roundColor:t=>(op("7.3.0","PIXI.canvasUtils.roundColor is deprecated"),Hp.shared.setValue(t).round(Yv.cacheStepsPerColorChannel).toNumber()),cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:Bv(),tintMethod:null};let $v;Yv.tintMethod=Yv.canUseMultiply?Yv.tintWithMultiply:Yv.tintWithPerPixel;const jv=new Qf;ev.prototype.generateCanvasTexture=function(t,e=1){const i=this.getLocalBounds(new Vf);i.width=Math.max(i.width,1/e),i.height=Math.max(i.height,1/e);const s=eg.create({width:i.width,height:i.height,scaleMode:t,resolution:e});$v||($v=new Hv),this.transform.updateLocalTransform(),this.transform.localTransform.copyTo(jv),jv.invert(),jv.tx-=i.x,jv.ty-=i.y,$v.render(this,{renderTexture:s,clear:!0,transform:jv});const r=tg.from(s.baseTexture._canvasRenderTarget.canvas,{scaleMode:t});return r.baseTexture.setResolution(e),r},ev.prototype.cachedGraphicsData=[],ev.prototype._renderCanvas=function(t){!0!==this.isMask&&(this.finishPoly(),t.plugins.graphics.render(this))};class zv{static offsetPolygon(t,e){const i=[],s=t.length;e=zv.isPolygonClockwise(t)?e:-1*e;for(let r=0;r<s;r+=2){let n=r-2;n<0&&(n+=s);const o=(r+2)%s;let a=t[r]-t[n],l=t[r+1]-t[n+1],h=Math.sqrt(a*a+l*l);a/=h,l/=h,a*=e,l*=e;const u=-l,c=a,d=[t[n]+u,t[n+1]+c],p=[t[r]+u,t[r+1]+c];let f=t[o]-t[r],m=t[o+1]-t[r+1];h=Math.sqrt(f*f+m*m),f/=h,m/=h,f*=e,m*=e;const g=-m,y=f,v=[t[r]+g,t[r+1]+y],x=[t[o]+g,t[o+1]+y],b=zv.findIntersection(d[0],d[1],p[0],p[1],v[0],v[1],x[0],x[1]);b&&i.push(...b)}return i}static findIntersection(t,e,i,s,r,n,o,a){const l=(a-n)*(i-t)-(o-r)*(s-e),h=(o-r)*(e-n)-(a-n)*(t-r);if(0===l)return 0===h&&0===(i-t)*(e-n)-(s-e)*(t-r)?[(t+i)/2,(e+s)/2]:null;const u=h/l;return[t+u*(i-t),e+u*(s-e)]}static isPolygonClockwise(t){let e=0;for(let i=0,s=t.length-2;i<t.length;s=i,i+=2)e+=(t[i]-t[s])*(t[i+1]+t[s+1]);return e>0}}class Vv{constructor(t){this._svgMatrix=null,this._tempMatrix=new Qf,this.renderer=t}_calcCanvasStyle(t,e){let i;return t.texture&&t.texture.baseTexture!==tg.WHITE.baseTexture?t.texture.valid?(i=Yv.getTintedPattern(t.texture,e),this.setPatternTransform(i,t.matrix||Qf.IDENTITY)):i="#808080":i=`#${`00000${(0|e).toString(16)}`.slice(-6)}`,i}render(t){const e=this.renderer,i=e.canvasContext.activeContext,s=t.worldAlpha,r=t.transform.worldTransform;e.canvasContext.setContextTransform(r),e.canvasContext.setBlendMode(t.blendMode);const n=t.geometry.graphicsData;let o,a;const l=Hp.shared.setValue(t.tint).toArray();for(let h=0;h<n.length;h++){const t=n[h],u=t.shape,c=t.fillStyle,d=t.lineStyle,p=0|t.fillStyle.color,f=0|t.lineStyle.color;if(t.matrix&&e.canvasContext.setContextTransform(r.copyTo(this._tempMatrix).append(t.matrix)),c.visible&&(o=this._calcCanvasStyle(c,Hp.shared.setValue(p).multiply(l).toNumber())),d.visible&&(a=this._calcCanvasStyle(d,Hp.shared.setValue(f).multiply(l).toNumber())),i.lineWidth=d.width,i.lineCap=d.cap,i.lineJoin=d.join,i.miterLimit=d.miterLimit,t.type===$f.POLY){i.beginPath();const e=u;let r=e.points;const n=t.holes;let l,h,p,f,m;i.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)i.lineTo(r[t],r[t+1]);if(e.closeStroke&&i.closePath(),n.length>0){m=[],l=0,p=r[0],f=r[1];for(let t=2;t+2<r.length;t+=2)l+=(r[t]-p)*(r[t+3]-f)-(r[t+2]-p)*(r[t+1]-f);for(let t=0;t<n.length;t++)if(r=n[t].shape.points,r){h=0,p=r[0],f=r[1];for(let t=2;t+2<r.length;t+=2)h+=(r[t]-p)*(r[t+3]-f)-(r[t+2]-p)*(r[t+1]-f);if(h*l<0){i.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)i.lineTo(r[t],r[t+1])}else{i.moveTo(r[r.length-2],r[r.length-1]);for(let t=r.length-4;t>=0;t-=2)i.lineTo(r[t],r[t+1])}n[t].shape.closeStroke&&i.closePath(),m[t]=h*l<0}}c.visible&&(i.globalAlpha=c.alpha*s,i.fillStyle=o,i.fill()),d.visible&&this.paintPolygonStroke(e,d,a,n,m,s,i)}else if(t.type===$f.RECT){const t=u;if(c.visible&&(i.globalAlpha=c.alpha*s,i.fillStyle=o,i.fillRect(t.x,t.y,t.width,t.height)),d.visible){const e=d.width*(.5-(1-d.alignment)),r=t.width+2*e,n=t.height+2*e;i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.strokeRect(t.x-e,t.y-e,r,n)}}else if(t.type===$f.CIRC){const t=u;if(i.beginPath(),i.arc(t.x,t.y,t.radius,0,2*Math.PI),i.closePath(),c.visible&&(i.globalAlpha=c.alpha*s,i.fillStyle=o,i.fill()),d.visible){if(.5!==d.alignment){const e=d.width*(.5-(1-d.alignment));i.beginPath(),i.arc(t.x,t.y,t.radius+e,0,2*Math.PI),i.closePath()}i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.stroke()}}else if(t.type===$f.ELIP){const t=u,e=1===d.alignment;if(e||this.paintEllipse(t,c,d,o,s,i),d.visible){if(.5!==d.alignment){const e=.5522848,s=d.width*(.5-(1-d.alignment)),r=2*(t.width+s),n=2*(t.height+s),o=t.x-r/2,a=t.y-n/2,l=r/2*e,h=n/2*e,u=o+r,c=a+n,p=o+r/2,f=a+n/2;i.beginPath(),i.moveTo(o,f),i.bezierCurveTo(o,f-h,p-l,a,p,a),i.bezierCurveTo(p+l,a,u,f-h,u,f),i.bezierCurveTo(u,f+h,p+l,c,p,c),i.bezierCurveTo(p-l,c,o,f+h,o,f),i.closePath()}i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.stroke()}e&&this.paintEllipse(t,c,d,o,s,i)}else if(t.type===$f.RREC){const t=u,e=1===d.alignment;if(e||this.paintRoundedRectangle(t,c,d,o,s,i),d.visible){if(.5!==d.alignment){const e=t.width,s=t.height,r=d.width*(.5-(1-d.alignment)),n=t.x-r,o=t.y-r,a=t.width+2*r,l=t.height+2*r,h=r*(d.alignment>=1?Math.min(a/e,l/s):Math.min(e/a,s/l));let u=t.radius+h;const c=Math.min(a,l)/2;u=u>c?c:u,i.beginPath(),i.moveTo(n,o+u),i.lineTo(n,o+l-u),i.quadraticCurveTo(n,o+l,n+u,o+l),i.lineTo(n+a-u,o+l),i.quadraticCurveTo(n+a,o+l,n+a,o+l-u),i.lineTo(n+a,o+u),i.quadraticCurveTo(n+a,o,n+a-u,o),i.lineTo(n+u,o),i.quadraticCurveTo(n,o,n,o+u),i.closePath()}i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.stroke()}e&&this.paintRoundedRectangle(t,c,d,o,s,i)}}}paintPolygonStroke(t,e,i,s,r,n,o){if(.5!==e.alignment){const i=e.width*(.5-(1-e.alignment));let n,a=zv.offsetPolygon(t.points,i);o.beginPath(),o.moveTo(a[0],a[1]);for(let t=2;t<a.length;t+=2)o.lineTo(a[t],a[t+1]);t.closeStroke&&o.closePath();for(let t=0;t<s.length;t++){if(n=s[t].shape.points,a=zv.offsetPolygon(n,i),r[t]){o.moveTo(a[0],a[1]);for(let t=2;t<a.length;t+=2)o.lineTo(a[t],a[t+1])}else{o.moveTo(a[a.length-2],a[a.length-1]);for(let t=a.length-4;t>=0;t-=2)o.lineTo(a[t],a[t+1])}s[t].shape.closeStroke&&o.closePath()}}o.globalAlpha=e.alpha*n,o.strokeStyle=i,o.stroke()}paintEllipse(t,e,i,s,r,n){const o=2*t.width,a=2*t.height,l=t.x-o/2,h=t.y-a/2,u=.5522848,c=o/2*u,d=a/2*u,p=l+o,f=h+a,m=l+o/2,g=h+a/2;0===i.alignment&&n.save(),n.beginPath(),n.moveTo(l,g),n.bezierCurveTo(l,g-d,m-c,h,m,h),n.bezierCurveTo(m+c,h,p,g-d,p,g),n.bezierCurveTo(p,g+d,m+c,f,m,f),n.bezierCurveTo(m-c,f,l,g+d,l,g),n.closePath(),0===i.alignment&&n.clip(),e.visible&&(n.globalAlpha=e.alpha*r,n.fillStyle=s,n.fill()),0===i.alignment&&n.restore()}paintRoundedRectangle(t,e,i,s,r,n){const o=t.x,a=t.y,l=t.width,h=t.height;let u=t.radius;const c=Math.min(l,h)/2;u=u>c?c:u,0===i.alignment&&n.save(),n.beginPath(),n.moveTo(o,a+u),n.lineTo(o,a+h-u),n.quadraticCurveTo(o,a+h,o+u,a+h),n.lineTo(o+l-u,a+h),n.quadraticCurveTo(o+l,a+h,o+l,a+h-u),n.lineTo(o+l,a+u),n.quadraticCurveTo(o+l,a,o+l-u,a),n.lineTo(o+u,a),n.quadraticCurveTo(o,a,o,a+u),n.closePath(),0===i.alignment&&n.clip(),e.visible&&(n.globalAlpha=e.alpha*r,n.fillStyle=s,n.fill()),0===i.alignment&&n.restore()}setPatternTransform(t,e){if(!1!==this._svgMatrix){if(!this._svgMatrix){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");if((null==e?void 0:e.createSVGMatrix)&&(this._svgMatrix=e.createSVGMatrix()),!this._svgMatrix||!t.setTransform)return void(this._svgMatrix=!1)}this._svgMatrix.a=e.a,this._svgMatrix.b=e.b,this._svgMatrix.c=e.c,this._svgMatrix.d=e.d,this._svgMatrix.e=e.tx,this._svgMatrix.f=e.ty,t.setTransform(this._svgMatrix.inverse())}}destroy(){this.renderer=null,this._svgMatrix=null,this._tempMatrix=null}}Vv.extension={name:"graphics",type:gf.CanvasRendererPlugin},xf.add(Vv);class qv{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function Jv(t,e){var i;let s=!1;if(null==(i=null==t?void 0:t._textures)?void 0:i.length)for(let r=0;r<t._textures.length;r++)if(t._textures[r]instanceof tg){const i=t._textures[r].baseTexture;e.includes(i)||(e.push(i),s=!0)}return s}function Kv(t,e){if(t.baseTexture instanceof Of){const i=t.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function Zv(t,e){if(t._texture&&t._texture instanceof tg){const i=t._texture.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function Qv(t,e){return e instanceof pv&&(e.updateText(!0),!0)}function tx(t,e){if(e instanceof lv){const t=e.toFontString();return nv.measureFont(t),!0}return!1}function ex(t,e){if(t instanceof pv){e.includes(t.style)||e.push(t.style),e.includes(t)||e.push(t);const i=t._texture.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function ix(t,e){return t instanceof lv&&(e.includes(t)||e.push(t),!0)}const sx=class t{constructor(e){this.limiter=new qv(t.uploadsPerFrame),this.renderer=e,this.uploadHookHelper=null,this.queue=[],this.addHooks=[],this.uploadHooks=[],this.completes=[],this.ticking=!1,this.delayedTick=()=>{this.queue&&this.prepareItems()},this.registerFindHook(ex),this.registerFindHook(ix),this.registerFindHook(Jv),this.registerFindHook(Kv),this.registerFindHook(Zv),this.registerUploadHook(Qv),this.registerUploadHook(tx)}upload(t){return new Promise((e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,ey.system.addOnce(this.tick,this,Zg.UTILITY))):e()}))}tick(){setTimeout(this.delayedTick,0)}prepareItems(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){const t=this.queue[0];let e=!1;if(t&&!t._destroyed)for(let i=0,s=this.uploadHooks.length;i<s;i++)if(this.uploadHooks[i](this.uploadHookHelper,t)){this.queue.shift(),e=!0;break}e||this.queue.shift()}if(this.queue.length)ey.system.addOnce(this.tick,this,Zg.UTILITY);else{this.ticking=!1;const t=this.completes.slice(0);this.completes.length=0;for(let e=0,i=t.length;e<i;e++)t[e]()}}registerFindHook(t){return t&&this.addHooks.push(t),this}registerUploadHook(t){return t&&this.uploadHooks.push(t),this}add(t){for(let e=0,i=this.addHooks.length;e<i&&!this.addHooks[e](t,this.queue);e++);if(t instanceof Ty)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&ey.system.remove(this.tick,this),this.ticking=!1,this.addHooks=null,this.uploadHooks=null,this.renderer=null,this.completes=null,this.queue=null,this.limiter=null,this.uploadHookHelper=null}};sx.uploadsPerFrame=4;let rx=sx;function nx(t,e){return e instanceof Of&&(e._glTextures[t.CONTEXT_UID]||t.texture.bind(e),!0)}function ox(t,e){if(!(e instanceof ev))return!1;const{geometry:i}=e;e.finishPoly(),i.updateBatches();const{batches:s}=i;for(let r=0;r<s.length;r++){const{texture:e}=s[r].style;e&&nx(t,e.baseTexture)}return i.batchable||t.geometry.bind(i,e._resolveDirectShader(t)),!0}function ax(t,e){return t instanceof ev&&(e.push(t),!0)}Object.defineProperties(lh,{UPLOADS_PER_FRAME:{get:()=>rx.uploadsPerFrame,set(t){op("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),rx.uploadsPerFrame=t}}});class lx extends rx{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(ax),this.registerUploadHook(nx),this.registerUploadHook(ox)}}lx.extension={name:"prepare",type:gf.RendererSystem},xf.add(lx);function hx(t,e){const i=t;if(e instanceof Of){const t=e.source,s=0===t.width?i.canvas.width:Math.min(i.canvas.width,t.width),r=0===t.height?i.canvas.height:Math.min(i.canvas.height,t.height);return i.ctx.drawImage(t,0,0,s,r,0,0,i.canvas.width,i.canvas.height),!0}return!1}class ux extends rx{constructor(t){super(t),this.uploadHookHelper=this,this.canvas=lh.ADAPTER.createCanvas(16,16),this.ctx=this.canvas.getContext("2d"),this.registerUploadHook(hx)}destroy(){super.destroy(),this.ctx=null,this.canvas=null}}ux.extension={name:"prepare",type:gf.CanvasRendererSystem},xf.add(ux),Sy.prototype._tintedCanvas=null,Sy.prototype._renderCanvas=function(t){t.plugins.sprite.render(this)};const cx=new Qf;class dx{constructor(t){this.renderer=t}render(t){const e=t._texture,i=this.renderer,s=i.canvasContext.activeContext,r=i.canvasContext.activeResolution;if(!e.valid)return;const n=e._frame.width,o=e._frame.height;let a=e._frame.width,l=e._frame.height;e.trim&&(a=e.trim.width,l=e.trim.height);let h=t.transform.worldTransform,u=0,c=0;const d=e.baseTexture.getDrawableSource();if(e.orig.width<=0||e.orig.height<=0||!e.valid||!d)return;i.canvasContext.setBlendMode(t.blendMode,!0),s.globalAlpha=t.worldAlpha;const p=e.baseTexture.scaleMode===Zl.LINEAR,f=i.canvasContext.smoothProperty;f&&s[f]!==p&&(s[f]=p),e.trim?(u=e.trim.width/2+e.trim.x-t.anchor.x*e.orig.width,c=e.trim.height/2+e.trim.y-t.anchor.y*e.orig.height):(u=(.5-t.anchor.x)*e.orig.width,c=(.5-t.anchor.y)*e.orig.height),e.rotate&&(h.copyTo(cx),h=cx,am.matrixAppendRotationInv(h,e.rotate,u,c),u=0,c=0),u-=a/2,c-=l/2,i.canvasContext.setContextTransform(h,t.roundPixels,1),t.roundPixels&&(u|=0,c|=0);const m=e.baseTexture.resolution,g=i.canvasContext._outerBlend;g&&(s.save(),s.beginPath(),s.rect(u*r,c*r,a*r,l*r),s.clip()),16777215!==t.tint?((t._cachedTint!==t.tintValue||t._tintedCanvas.tintId!==t._texture._updateID)&&(t._cachedTint=t.tintValue,t._tintedCanvas=Yv.getTintedCanvas(t,t.tintValue)),s.drawImage(t._tintedCanvas,0,0,Math.floor(n*m),Math.floor(o*m),Math.floor(u*r),Math.floor(c*r),Math.floor(a*r),Math.floor(l*r))):s.drawImage(d,e._frame.x*m,e._frame.y*m,Math.floor(n*m),Math.floor(o*m),Math.floor(u*r),Math.floor(c*r),Math.floor(a*r),Math.floor(l*r)),g&&s.restore(),i.canvasContext.setBlendMode(jl.NORMAL)}destroy(){this.renderer=null}}dx.extension={name:"sprite",type:gf.CanvasRendererPlugin},xf.add(dx);var px=Object.defineProperty,fx=(t,e,i)=>(((t,e,i)=>{e in t?px(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);let mx=class{constructor(t){fx(this,"parent"),fx(this,"paused"),this.parent=t,this.paused=!1}destroy(){}down(t){return!1}move(t){return!1}up(t){return!1}wheel(t){return!1}update(t){}resize(){}reset(){}pause(){this.paused=!0}resume(){this.paused=!1}};var gx,yx=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},vx={exports:{}};gx=vx,function(){var t,e;e=t={linear:function(t,e,i,s){return i*t/s+e},easeInQuad:function(t,e,i,s){return i*(t/=s)*t+e},easeOutQuad:function(t,e,i,s){return-i*(t/=s)*(t-2)+e},easeInOutQuad:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e},easeInCubic:function(t,e,i,s){return i*(t/=s)*t*t+e},easeOutCubic:function(t,e,i,s){return i*((t=t/s-1)*t*t+1)+e},easeInOutCubic:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e},easeInQuart:function(t,e,i,s){return i*(t/=s)*t*t*t+e},easeOutQuart:function(t,e,i,s){return-i*((t=t/s-1)*t*t*t-1)+e},easeInOutQuart:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e},easeInQuint:function(t,e,i,s){return i*(t/=s)*t*t*t*t+e},easeOutQuint:function(t,e,i,s){return i*((t=t/s-1)*t*t*t*t+1)+e},easeInOutQuint:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e},easeInSine:function(t,e,i,s){return-i*Math.cos(t/s*(Math.PI/2))+i+e},easeOutSine:function(t,e,i,s){return i*Math.sin(t/s*(Math.PI/2))+e},easeInOutSine:function(t,e,i,s){return-i/2*(Math.cos(Math.PI*t/s)-1)+e},easeInExpo:function(t,e,i,s){return 0===t?e:i*Math.pow(2,10*(t/s-1))+e},easeOutExpo:function(t,e,i,s){return t===s?e+i:i*(1-Math.pow(2,-10*t/s))+e},easeInOutExpo:function(t,e,i,s){return(t/=s/2)<1?i/2*Math.pow(2,10*(t-1))+e:i/2*(2-Math.pow(2,-10*--t))+e},easeInCirc:function(t,e,i,s){return-i*(Math.sqrt(1-(t/=s)*t)-1)+e},easeOutCirc:function(t,e,i,s){return i*Math.sqrt(1-(t=t/s-1)*t)+e},easeInOutCirc:function(t,e,i,s){return(t/=s/2)<1?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e},easeInElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)+e},easeOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/n)+i+e},easeInOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s/2),(n=0)||(n=s*(.3*1.5)),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*.5+i+e},easeInBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*(t/=s)*t*((r+1)*t-r)+e},easeOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeInOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInBounce:function(e,i,s,r){return s-t.easeOutBounce(r-e,0,s,r)+i},easeOutBounce:function(t,e,i,s){return(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e},easeInOutBounce:function(e,i,s,r){return e<r/2?.5*t.easeInBounce(2*e,0,s,r)+i:.5*t.easeOutBounce(2*e-r,0,s,r)+.5*s+i}},gx.exports=e}.call(yx);const xx=vx.exports;function bx(t,e){return t?"function"==typeof t?t:"string"==typeof t?xx[t]:void 0:xx[e]}const _x={removeOnInterrupt:!1,ease:"linear",time:1e3};let wx=class extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"startX"),fx(this,"startY"),fx(this,"deltaX"),fx(this,"deltaY"),fx(this,"keepCenter"),fx(this,"startWidth",null),fx(this,"startHeight",null),fx(this,"deltaWidth",null),fx(this,"deltaHeight",null),fx(this,"width",null),fx(this,"height",null),fx(this,"time",0),this.options=Object.assign({},_x,e),this.options.ease=bx(this.options.ease),this.setupPosition(),this.setupZoom(),this.time=0}setupPosition(){typeof this.options.position<"u"?(this.startX=this.parent.center.x,this.startY=this.parent.center.y,this.deltaX=this.options.position.x-this.parent.center.x,this.deltaY=this.options.position.y-this.parent.center.y,this.keepCenter=!1):this.keepCenter=!0}setupZoom(){this.width=null,this.height=null,typeof this.options.scale<"u"?this.width=this.parent.screenWidth/this.options.scale:typeof this.options.scaleX<"u"||typeof this.options.scaleY<"u"?(typeof this.options.scaleX<"u"&&(this.width=this.parent.screenWidth/this.options.scaleX),typeof this.options.scaleY<"u"&&(this.height=this.parent.screenHeight/this.options.scaleY)):(typeof this.options.width<"u"&&(this.width=this.options.width),typeof this.options.height<"u"&&(this.height=this.options.height)),null!==this.width&&(this.startWidth=this.parent.screenWidthInWorldPixels,this.deltaWidth=this.width-this.startWidth),null!==this.height&&(this.startHeight=this.parent.screenHeightInWorldPixels,this.deltaHeight=this.height-this.startHeight)}down(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("animate"),!1}complete(){this.parent.plugins.remove("animate"),null!==this.width&&this.parent.fitWidth(this.width,this.keepCenter,null===this.height),null!==this.height&&this.parent.fitHeight(this.height,this.keepCenter,null===this.width),!this.keepCenter&&this.options.position&&this.parent.moveCenter(this.options.position),this.parent.emit("animate-end",this.parent),this.options.callbackOnComplete&&this.options.callbackOnComplete(this.parent)}update(t){if(this.paused)return;this.time+=t;const e=new jf(this.parent.scale.x,this.parent.scale.y);if(this.time>=this.options.time){const t=this.parent.width,i=this.parent.height;this.complete(),(t!==this.parent.width||i!==this.parent.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:e,type:"animate"})}else{const t=this.options.ease(this.time,0,1,this.options.time);if(null!==this.width){const e=this.startWidth,i=this.deltaWidth;this.parent.fitWidth(e+i*t,this.keepCenter,null===this.height)}if(null!==this.height){const e=this.startHeight,i=this.deltaHeight;this.parent.fitHeight(e+i*t,this.keepCenter,null===this.width)}if(null===this.width?this.parent.scale.x=this.parent.scale.y:null===this.height&&(this.parent.scale.y=this.parent.scale.x),!this.keepCenter){const e=this.startX,i=this.startY,s=this.deltaX,r=this.deltaY,n=new jf(this.parent.x,this.parent.y);this.parent.moveCenter(e+s*t,i+r*t),this.parent.emit("moved",{viewport:this.parent,original:n,type:"animate"})}(this.width||this.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:e,type:"animate"})}}};const Px={sides:"all",friction:.5,time:150,ease:"easeInOutSine",underflow:"center",bounceBox:null};class Ex extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"left"),fx(this,"top"),fx(this,"right"),fx(this,"bottom"),fx(this,"underflowX"),fx(this,"underflowY"),fx(this,"ease"),fx(this,"toX"),fx(this,"toY"),this.options=Object.assign({},Px,e),this.ease=bx(this.options.ease,"easeInOutSine"),this.options.sides?"all"===this.options.sides?this.top=this.bottom=this.left=this.right=!0:"horizontal"===this.options.sides?(this.right=this.left=!0,this.top=this.bottom=!1):"vertical"===this.options.sides?(this.left=this.right=!1,this.top=this.bottom=!0):(this.top=-1!==this.options.sides.indexOf("top"),this.bottom=-1!==this.options.sides.indexOf("bottom"),this.left=-1!==this.options.sides.indexOf("left"),this.right=-1!==this.options.sides.indexOf("right")):this.left=this.top=this.right=this.bottom=!1;const i=this.options.underflow.toLowerCase();"center"===i?(this.underflowX=0,this.underflowY=0):(this.underflowX=-1!==i.indexOf("left")?-1:-1!==i.indexOf("right")?1:0,this.underflowY=-1!==i.indexOf("top")?-1:-1!==i.indexOf("bottom")?1:0),this.reset()}isActive(){return null!==this.toX||null!==this.toY}down(){return this.toX=this.toY=null,!1}up(){return this.bounce(),!1}update(t){if(!this.paused){if(this.bounce(),this.toX){const e=this.toX;e.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-x"}),e.time>=this.options.time?(this.parent.x=e.end,this.toX=null,this.parent.emit("bounce-x-end",this.parent)):this.parent.x=this.ease(e.time,e.start,e.delta,this.options.time)}if(this.toY){const e=this.toY;e.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-y"}),e.time>=this.options.time?(this.parent.y=e.end,this.toY=null,this.parent.emit("bounce-y-end",this.parent)):this.parent.y=this.ease(e.time,e.start,e.delta,this.options.time)}}}calcUnderflowX(){let t;switch(this.underflowX){case-1:t=0;break;case 1:t=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:t=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}return t}calcUnderflowY(){let t;switch(this.underflowY){case-1:t=0;break;case 1:t=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:t=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}return t}oob(){const t=this.options.bounceBox;if(t){const e=typeof t.x>"u"?0:t.x,i=typeof t.y>"u"?0:t.y,s=typeof t.width>"u"?this.parent.worldWidth:t.width,r=typeof t.height>"u"?this.parent.worldHeight:t.height;return{left:this.parent.left<e,right:this.parent.right>s,top:this.parent.top<i,bottom:this.parent.bottom>r,topLeft:new jf(e*this.parent.scale.x,i*this.parent.scale.y),bottomRight:new jf(s*this.parent.scale.x-this.parent.screenWidth,r*this.parent.scale.y-this.parent.screenHeight)}}return{left:this.parent.left<0,right:this.parent.right>this.parent.worldWidth,top:this.parent.top<0,bottom:this.parent.bottom>this.parent.worldHeight,topLeft:new jf(0,0),bottomRight:new jf(this.parent.worldWidth*this.parent.scale.x-this.parent.screenWidth,this.parent.worldHeight*this.parent.scale.y-this.parent.screenHeight)}}bounce(){var t,e;if(this.paused)return;let i,s=this.parent.plugins.get("decelerate",!0);s&&(s.x||s.y)&&(s.x&&s.percentChangeX===(null==(t=s.options)?void 0:t.friction)||s.y&&s.percentChangeY===(null==(e=s.options)?void 0:e.friction))&&(i=this.oob(),(i.left&&this.left||i.right&&this.right)&&(s.percentChangeX=this.options.friction),(i.top&&this.top||i.bottom&&this.bottom)&&(s.percentChangeY=this.options.friction));const r=this.parent.plugins.get("drag",!0)||{},n=this.parent.plugins.get("pinch",!0)||{};if(s=s||{},!(null!=r&&r.active||null!=n&&n.active||this.toX&&this.toY||s.x&&s.y)){i=i||this.oob();const t=i.topLeft,e=i.bottomRight;if(!this.toX&&!s.x){let s=null;i.left&&this.left?s=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-t.x:i.right&&this.right&&(s=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-e.x),null!==s&&this.parent.x!==s&&(this.toX={time:0,start:this.parent.x,delta:s-this.parent.x,end:s},this.parent.emit("bounce-x-start",this.parent))}if(!this.toY&&!s.y){let s=null;i.top&&this.top?s=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-t.y:i.bottom&&this.bottom&&(s=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-e.y),null!==s&&this.parent.y!==s&&(this.toY={time:0,start:this.parent.y,delta:s-this.parent.y,end:s},this.parent.emit("bounce-y-start",this.parent))}}}reset(){this.toX=this.toY=null,this.bounce()}}const Tx={left:!1,right:!1,top:!1,bottom:!1,direction:null,underflow:"center"};class Ax extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"last"),fx(this,"noUnderflow"),fx(this,"underflowX"),fx(this,"underflowY"),this.options=Object.assign({},Tx,e),this.options.direction&&(this.options.left="x"===this.options.direction||"all"===this.options.direction||null,this.options.right="x"===this.options.direction||"all"===this.options.direction||null,this.options.top="y"===this.options.direction||"all"===this.options.direction||null,this.options.bottom="y"===this.options.direction||"all"===this.options.direction||null),this.parseUnderflow(),this.last={x:null,y:null,scaleX:null,scaleY:null},this.update()}parseUnderflow(){const t=this.options.underflow.toLowerCase();"none"===t?this.noUnderflow=!0:"center"===t?(this.underflowX=this.underflowY=0,this.noUnderflow=!1):(this.underflowX=-1!==t.indexOf("left")?-1:-1!==t.indexOf("right")?1:0,this.underflowY=-1!==t.indexOf("top")?-1:-1!==t.indexOf("bottom")?1:0,this.noUnderflow=!1)}move(){return this.update(),!1}update(){if(this.paused||this.parent.x===this.last.x&&this.parent.y===this.last.y&&this.parent.scale.x===this.last.scaleX&&this.parent.scale.y===this.last.scaleY)return;const t=new jf(this.parent.x,this.parent.y),e=this.parent.plugins.decelerate||{};if(null!==this.options.left||null!==this.options.right){let i=!1;if(!this.noUnderflow&&this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:0!==this.parent.x&&(this.parent.x=0,i=!0);break;case 1:this.parent.x!==this.parent.screenWidth-this.parent.screenWorldWidth&&(this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth,i=!0);break;default:this.parent.x!==(this.parent.screenWidth-this.parent.screenWorldWidth)/2&&(this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2,i=!0)}else null!==this.options.left&&this.parent.left<(!0===this.options.left?0:this.options.left)&&(this.parent.x=-(!0===this.options.left?0:this.options.left)*this.parent.scale.x,e.x=0,i=!0),null!==this.options.right&&this.parent.right>(!0===this.options.right?this.parent.worldWidth:this.options.right)&&(this.parent.x=-(!0===this.options.right?this.parent.worldWidth:this.options.right)*this.parent.scale.x+this.parent.screenWidth,e.x=0,i=!0);i&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-x"})}if(null!==this.options.top||null!==this.options.bottom){let i=!1;if(!this.noUnderflow&&this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:0!==this.parent.y&&(this.parent.y=0,i=!0);break;case 1:this.parent.y!==this.parent.screenHeight-this.parent.screenWorldHeight&&(this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight,i=!0);break;default:this.parent.y!==(this.parent.screenHeight-this.parent.screenWorldHeight)/2&&(this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2,i=!0)}else null!==this.options.top&&this.parent.top<(!0===this.options.top?0:this.options.top)&&(this.parent.y=-(!0===this.options.top?0:this.options.top)*this.parent.scale.y,e.y=0,i=!0),null!==this.options.bottom&&this.parent.bottom>(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)&&(this.parent.y=-(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)*this.parent.scale.y+this.parent.screenHeight,e.y=0,i=!0);i&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-y"})}this.last.x=this.parent.x,this.last.y=this.parent.y,this.last.scaleX=this.parent.scale.x,this.last.scaleY=this.parent.scale.y}reset(){this.update()}}const Ix={minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,minScale:null,maxScale:null};class Sx extends mx{constructor(t,e={}){super(t),fx(this,"options"),this.options=Object.assign({},Ix,e),this.clamp()}resize(){this.clamp()}clamp(){if(!this.paused)if(this.options.minWidth||this.options.minHeight||this.options.maxWidth||this.options.maxHeight){let t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight;if(null!==this.options.minWidth&&t<this.options.minWidth){const i=this.parent.scale.x;this.parent.fitWidth(this.options.minWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/i,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxWidth&&t>this.options.maxWidth){const i=this.parent.scale.x;this.parent.fitWidth(this.options.maxWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/i,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.minHeight&&e<this.options.minHeight){const i=this.parent.scale.y;this.parent.fitHeight(this.options.minHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/i,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxHeight&&e>this.options.maxHeight){const t=this.parent.scale.y;this.parent.fitHeight(this.options.maxHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/t,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}}else if(this.options.minScale||this.options.maxScale){const t={x:null,y:null},e={x:null,y:null};if("number"==typeof this.options.minScale)t.x=this.options.minScale,t.y=this.options.minScale;else if(null!==this.options.minScale){const e=this.options.minScale;t.x=typeof e.x>"u"?null:e.x,t.y=typeof e.y>"u"?null:e.y}if("number"==typeof this.options.maxScale)e.x=this.options.maxScale,e.y=this.options.maxScale;else if(null!==this.options.maxScale){const t=this.options.maxScale;e.x=typeof t.x>"u"?null:t.x,e.y=typeof t.y>"u"?null:t.y}let i=this.parent.scale.x,s=this.parent.scale.y;null!==t.x&&i<t.x&&(i=t.x),null!==e.x&&i>e.x&&(i=e.x),null!==t.y&&s<t.y&&(s=t.y),null!==e.y&&s>e.y&&(s=e.y),(i!==this.parent.scale.x||s!==this.parent.scale.y)&&(this.parent.scale.set(i,s),this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"}))}}reset(){this.clamp()}}const Cx={friction:.98,bounce:.8,minSpeed:.01},Mx=16;let Ox=class extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"x"),fx(this,"y"),fx(this,"percentChangeX"),fx(this,"percentChangeY"),fx(this,"saved"),fx(this,"timeSinceRelease"),this.options=Object.assign({},Cx,e),this.saved=[],this.timeSinceRelease=0,this.reset(),this.parent.on("moved",(t=>this.handleMoved(t)))}down(){return this.saved=[],this.x=this.y=null,!1}isActive(){return!(!this.x&&!this.y)}move(){if(this.paused)return!1;const t=this.parent.input.count();return(1===t||t>1&&!this.parent.plugins.get("pinch",!0))&&(this.saved.push({x:this.parent.x,y:this.parent.y,time:performance.now()}),this.saved.length>60&&this.saved.splice(0,30)),!1}handleMoved(t){if(this.saved.length){const e=this.saved[this.saved.length-1];"clamp-x"===t.type&&t.original?e.x===t.original.x&&(e.x=this.parent.x):"clamp-y"===t.type&&t.original&&e.y===t.original.y&&(e.y=this.parent.y)}}up(){if(0===this.parent.input.count()&&this.saved.length){const t=performance.now();for(const e of this.saved)if(e.time>=t-100){const i=t-e.time;this.x=(this.parent.x-e.x)/i,this.y=(this.parent.y-e.y)/i,this.percentChangeX=this.percentChangeY=this.options.friction,this.timeSinceRelease=0;break}}return!1}activate(t){typeof(t=t||{}).x<"u"&&(this.x=t.x,this.percentChangeX=this.options.friction),typeof t.y<"u"&&(this.y=t.y,this.percentChangeY=this.options.friction)}update(t){if(this.paused)return;const e=this.x||this.y,i=this.timeSinceRelease,s=this.timeSinceRelease+t;if(this.x){const e=this.percentChangeX,r=Math.log(e);this.parent.x+=this.x*Mx/r*(Math.pow(e,s/Mx)-Math.pow(e,i/Mx)),this.x*=Math.pow(this.percentChangeX,t/Mx)}if(this.y){const e=this.percentChangeY,r=Math.log(e);this.parent.y+=this.y*Mx/r*(Math.pow(e,s/Mx)-Math.pow(e,i/Mx)),this.y*=Math.pow(this.percentChangeY,t/Mx)}this.timeSinceRelease+=t,this.x&&this.y?Math.abs(this.x)<this.options.minSpeed&&Math.abs(this.y)<this.options.minSpeed&&(this.x=0,this.y=0):(Math.abs(this.x||0)<this.options.minSpeed&&(this.x=0),Math.abs(this.y||0)<this.options.minSpeed&&(this.y=0)),e&&this.parent.emit("moved",{viewport:this.parent,type:"decelerate"})}reset(){this.x=this.y=null}};const Nx={direction:"all",pressDrag:!0,wheel:!0,wheelScroll:1,reverse:!1,clampWheel:!1,underflow:"center",factor:1,mouseButtons:"all",keyToPress:null,ignoreKeyToPressOnTouch:!1,lineHeight:20,wheelSwapAxes:!1};class Lx extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"moved"),fx(this,"reverse"),fx(this,"xDirection"),fx(this,"yDirection"),fx(this,"keyIsPressed"),fx(this,"mouse"),fx(this,"underflowX"),fx(this,"underflowY"),fx(this,"last"),fx(this,"current"),fx(this,"windowEventHandlers",[]),this.options=Object.assign({},Nx,e),this.moved=!1,this.reverse=this.options.reverse?1:-1,this.xDirection=!this.options.direction||"all"===this.options.direction||"x"===this.options.direction,this.yDirection=!this.options.direction||"all"===this.options.direction||"y"===this.options.direction,this.keyIsPressed=!1,this.parseUnderflow(),this.mouseButtons(this.options.mouseButtons),this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){this.addWindowEventHandler("keyup",(e=>{t.includes(e.code)&&(this.keyIsPressed=!1)})),this.addWindowEventHandler("keydown",(e=>{t.includes(e.code)&&(this.keyIsPressed=!0)}))}addWindowEventHandler(t,e){window.addEventListener(t,e),this.windowEventHandlers.push({event:t,handler:e})}destroy(){this.windowEventHandlers.forEach((({event:t,handler:e})=>{window.removeEventListener(t,e)}))}mouseButtons(t){this.mouse=t&&"all"!==t?[-1!==t.indexOf("left"),-1!==t.indexOf("middle"),-1!==t.indexOf("right")]:[!0,!0,!0]}parseUnderflow(){const t=this.options.underflow.toLowerCase();"center"===t?(this.underflowX=0,this.underflowY=0):(t.includes("left")?this.underflowX=-1:t.includes("right")?this.underflowX=1:this.underflowX=0,t.includes("top")?this.underflowY=-1:t.includes("bottom")?this.underflowY=1:this.underflowY=0)}checkButtons(t){const e="mouse"===t.pointerType,i=this.parent.input.count();return!(!(1===i||i>1&&!this.parent.plugins.get("pinch",!0))||e&&!this.mouse[t.button])}checkKeyPress(t){return!this.options.keyToPress||this.keyIsPressed||this.options.ignoreKeyToPressOnTouch&&"touch"===t.data.pointerType}down(t){return!(this.paused||!this.options.pressDrag)&&(this.checkButtons(t)&&this.checkKeyPress(t)?(this.last={x:t.global.x,y:t.global.y},this.current=t.pointerId,!0):(this.last=null,!1))}get active(){return this.moved}move(t){if(this.paused||!this.options.pressDrag)return!1;if(this.last&&this.current===t.data.pointerId){const e=t.global.x,i=t.global.y,s=this.parent.input.count();if(1===s||s>1&&!this.parent.plugins.get("pinch",!0)){const s=e-this.last.x,r=i-this.last.y;if(this.moved||this.xDirection&&this.parent.input.checkThreshold(s)||this.yDirection&&this.parent.input.checkThreshold(r)){const s={x:e,y:i};return this.xDirection&&(this.parent.x+=(s.x-this.last.x)*this.options.factor),this.yDirection&&(this.parent.y+=(s.y-this.last.y)*this.options.factor),this.last=s,this.moved||this.parent.emit("drag-start",{event:t,screen:new jf(this.last.x,this.last.y),world:this.parent.toWorld(new jf(this.last.x,this.last.y)),viewport:this.parent}),this.moved=!0,this.parent.emit("moved",{viewport:this.parent,type:"drag"}),!0}}else this.moved=!1}return!1}up(t){if(this.paused)return!1;const e=this.parent.input.touches;if(1===e.length){const t=e[0];return t.last&&(this.last={x:t.last.x,y:t.last.y},this.current=t.id),this.moved=!1,!0}if(this.last&&this.moved){const e=new jf(this.last.x,this.last.y);return this.parent.emit("drag-end",{event:t,screen:e,world:this.parent.toWorld(e),viewport:this.parent}),this.last=null,this.moved=!1,!0}return!1}wheel(t){if(this.paused)return!1;if(this.options.wheel){const e=this.parent.plugins.get("wheel",!0);if(!e||!e.options.wheelZoom&&!t.ctrlKey){const e=t.deltaMode?this.options.lineHeight:1,i=[t.deltaX,t.deltaY],[s,r]=this.options.wheelSwapAxes?i.reverse():i;return this.xDirection&&(this.parent.x+=s*e*this.options.wheelScroll*this.reverse),this.yDirection&&(this.parent.y+=r*e*this.options.wheelScroll*this.reverse),this.options.clampWheel&&this.clamp(),this.parent.emit("wheel-scroll",this.parent),this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.options.passiveWheel||t.preventDefault(),this.parent.options.stopPropagation&&t.stopPropagation(),!0}}return!1}resume(){this.last=null,this.paused=!1}clamp(){const t=this.parent.plugins.get("decelerate",!0)||{};if("y"!==this.options.clampWheel)if(this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:this.parent.x=0;break;case 1:this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}else this.parent.left<0?(this.parent.x=0,t.x=0):this.parent.right>this.parent.worldWidth&&(this.parent.x=-this.parent.worldWidth*this.parent.scale.x+this.parent.screenWidth,t.x=0);if("x"!==this.options.clampWheel)if(this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:this.parent.y=0;break;case 1:this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}else this.parent.top<0&&(this.parent.y=0,t.y=0),this.parent.bottom>this.parent.worldHeight&&(this.parent.y=-this.parent.worldHeight*this.parent.scale.y+this.parent.screenHeight,t.y=0)}}const Rx={speed:0,acceleration:null,radius:null};class kx extends mx{constructor(t,e,i={}){super(t),fx(this,"options"),fx(this,"target"),fx(this,"velocity"),this.target=e,this.options=Object.assign({},Rx,i),this.velocity={x:0,y:0}}update(t){if(this.paused)return;const e=this.parent.center;let i=this.target.x,s=this.target.y;if(this.options.radius){if(!(Math.sqrt(Math.pow(this.target.y-e.y,2)+Math.pow(this.target.x-e.x,2))>this.options.radius))return;{const t=Math.atan2(this.target.y-e.y,this.target.x-e.x);i=this.target.x-Math.cos(t)*this.options.radius,s=this.target.y-Math.sin(t)*this.options.radius}}const r=i-e.x,n=s-e.y;if(r||n)if(this.options.speed)if(this.options.acceleration){const t=Math.atan2(s-e.y,i-e.x),o=Math.sqrt(Math.pow(r,2)+Math.pow(n,2));if(o){const a=(Math.pow(this.velocity.x,2)+Math.pow(this.velocity.y,2))/(2*this.options.acceleration);this.velocity=o>a?{x:Math.min(this.velocity.x+(this.options.acceleration,this.options.speed)),y:Math.min(this.velocity.y+(this.options.acceleration,this.options.speed))}:{x:Math.max(this.velocity.x-this.options.acceleration*this.options.speed,0),y:Math.max(this.velocity.y-this.options.acceleration*this.options.speed,0)};const l=Math.cos(t)*this.velocity.x,h=Math.sin(t)*this.velocity.y,u=Math.abs(l)>Math.abs(r)?i:e.x+l,c=Math.abs(h)>Math.abs(n)?s:e.y+h;this.parent.moveCenter(u,c),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}else{const t=Math.atan2(s-e.y,i-e.x),o=Math.cos(t)*this.options.speed,a=Math.sin(t)*this.options.speed,l=Math.abs(o)>Math.abs(r)?i:e.x+o,h=Math.abs(a)>Math.abs(n)?s:e.y+a;this.parent.moveCenter(l,h),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}else this.parent.moveCenter(i,s),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}const Bx={radius:null,distance:null,top:null,bottom:null,left:null,right:null,speed:8,reverse:!1,noDecelerate:!1,linear:!1,allowButtons:!1};let Fx=class extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"reverse"),fx(this,"radiusSquared"),fx(this,"left"),fx(this,"top"),fx(this,"right"),fx(this,"bottom"),fx(this,"horizontal"),fx(this,"vertical"),this.options=Object.assign({},Bx,e),this.reverse=this.options.reverse?1:-1,this.radiusSquared="number"==typeof this.options.radius?Math.pow(this.options.radius,2):null,this.resize()}resize(){const t=this.options.distance;null!==t?(this.left=t,this.top=t,this.right=this.parent.screenWidth-t,this.bottom=this.parent.screenHeight-t):this.options.radius||(this.left=this.options.left,this.top=this.options.top,this.right=null===this.options.right?null:this.parent.screenWidth-this.options.right,this.bottom=null===this.options.bottom?null:this.parent.screenHeight-this.options.bottom)}down(){return this.paused||this.options.allowButtons||(this.horizontal=this.vertical=null),!1}move(t){if(this.paused||"mouse"!==t.pointerType&&1!==t.pointerId||!this.options.allowButtons&&0!==t.buttons)return!1;const e=t.global.x,i=t.global.y;if(this.radiusSquared){const t=this.parent.toScreen(this.parent.center);if(Math.pow(t.x-e,2)+Math.pow(t.y-i,2)>=this.radiusSquared){const s=Math.atan2(t.y-i,t.x-e);this.options.linear?(this.horizontal=Math.round(Math.cos(s))*this.options.speed*this.reverse*.06,this.vertical=Math.round(Math.sin(s))*this.options.speed*this.reverse*.06):(this.horizontal=Math.cos(s)*this.options.speed*this.reverse*.06,this.vertical=Math.sin(s)*this.options.speed*this.reverse*.06)}else this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=0}else null!==this.left&&e<this.left?this.horizontal=Number(this.reverse)*this.options.speed*.06:null!==this.right&&e>this.right?this.horizontal=-1*this.reverse*this.options.speed*.06:(this.decelerateHorizontal(),this.horizontal=0),null!==this.top&&i<this.top?this.vertical=Number(this.reverse)*this.options.speed*.06:null!==this.bottom&&i>this.bottom?this.vertical=-1*this.reverse*this.options.speed*.06:(this.decelerateVertical(),this.vertical=0);return!1}decelerateHorizontal(){const t=this.parent.plugins.get("decelerate",!0);this.horizontal&&t&&!this.options.noDecelerate&&t.activate({x:this.horizontal*this.options.speed*this.reverse/(1e3/60)})}decelerateVertical(){const t=this.parent.plugins.get("decelerate",!0);this.vertical&&t&&!this.options.noDecelerate&&t.activate({y:this.vertical*this.options.speed*this.reverse/(1e3/60)})}up(){return this.paused||(this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=null),!1}update(){if(!this.paused&&(this.horizontal||this.vertical)){const t=this.parent.center;this.horizontal&&(t.x+=this.horizontal*this.options.speed),this.vertical&&(t.y+=this.vertical*this.options.speed),this.parent.moveCenter(t),this.parent.emit("moved",{viewport:this.parent,type:"mouse-edges"})}}};const Dx={noDrag:!1,percent:1,center:null,factor:1,axis:"all"};class Ux extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"active",!1),fx(this,"pinching",!1),fx(this,"moved",!1),fx(this,"lastCenter"),this.options=Object.assign({},Dx,e)}down(){return this.parent.input.count()>=2&&(this.active=!0,!0)}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}move(t){if(this.paused||!this.active)return!1;const e=t.global.x,i=t.global.y,s=this.parent.input.touches;if(s.length>=2){const r=s[0],n=s[1],o=r.last&&n.last?Math.sqrt(Math.pow(n.last.x-r.last.x,2)+Math.pow(n.last.y-r.last.y,2)):null;if(r.id===t.pointerId?r.last={x:e,y:i,data:t}:n.id===t.pointerId&&(n.last={x:e,y:i,data:t}),o){let t;const e=new jf(r.last.x+(n.last.x-r.last.x)/2,r.last.y+(n.last.y-r.last.y)/2);this.options.center||(t=this.parent.toLocal(e));let i=Math.sqrt(Math.pow(n.last.x-r.last.x,2)+Math.pow(n.last.y-r.last.y,2));i=0===i?i=1e-10:i;const s=(1-o/i)*this.options.percent*(this.isAxisX()?this.parent.scale.x:this.parent.scale.y);this.isAxisX()&&(this.parent.scale.x+=s),this.isAxisY()&&(this.parent.scale.y+=s),this.parent.emit("zoomed",{viewport:this.parent,type:"pinch",center:e});const a=this.parent.plugins.get("clamp-zoom",!0);if(a&&a.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const i=this.parent.toGlobal(t);this.parent.x+=(e.x-i.x)*this.options.factor,this.parent.y+=(e.y-i.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})}!this.options.noDrag&&this.lastCenter&&(this.parent.x+=(e.x-this.lastCenter.x)*this.options.factor,this.parent.y+=(e.y-this.lastCenter.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})),this.lastCenter=e,this.moved=!0}else this.pinching||(this.parent.emit("pinch-start",this.parent),this.pinching=!0);return!0}return!1}up(){return!!(this.pinching&&this.parent.input.touches.length<=1)&&(this.active=!1,this.lastCenter=null,this.pinching=!1,this.moved=!1,this.parent.emit("pinch-end",this.parent),!0)}}const Gx={topLeft:!1,friction:.8,time:1e3,ease:"easeInOutSine",interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1};class Xx extends mx{constructor(t,e,i,s={}){super(t),fx(this,"options"),fx(this,"ease"),fx(this,"x"),fx(this,"y"),fx(this,"percent"),fx(this,"snapping"),fx(this,"deltaX"),fx(this,"deltaY"),fx(this,"startX"),fx(this,"startY"),this.options=Object.assign({},Gx,s),this.ease=bx(s.ease,"easeInOutSine"),this.x=e,this.y=i,this.options.forceStart&&this.snapStart()}snapStart(){this.percent=0,this.snapping={time:0};const t=this.options.topLeft?this.parent.corner:this.parent.center;this.deltaX=this.x-t.x,this.deltaY=this.y-t.y,this.startX=t.x,this.startY=t.y,this.parent.emit("snap-start",this.parent)}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap"):this.options.interrupt&&(this.snapping=null),!1}up(){if(0===this.parent.input.count()){const t=this.parent.plugins.get("decelerate",!0);t&&(t.x||t.y)&&(t.percentChangeX=t.percentChangeY=this.options.friction)}return!1}update(t){if(!(this.paused||this.options.interrupt&&0!==this.parent.input.count()))if(this.snapping){const e=this.snapping;let i,s,r;e.time+=t;const n=this.startX,o=this.startY,a=this.deltaX,l=this.deltaY;if(e.time>this.options.time)i=!0,s=n+a,r=o+l;else{const t=this.ease(e.time,0,1,this.options.time);s=n+a*t,r=o+l*t}this.options.topLeft?this.parent.moveCorner(s,r):this.parent.moveCenter(s,r),this.parent.emit("moved",{viewport:this.parent,type:"snap"}),i&&(this.options.removeOnComplete&&this.parent.plugins.remove("snap"),this.parent.emit("snap-end",this.parent),this.snapping=null)}else{const t=this.options.topLeft?this.parent.corner:this.parent.center;(t.x!==this.x||t.y!==this.y)&&this.snapStart()}}}const Wx={width:0,height:0,time:1e3,ease:"easeInOutSine",center:null,interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1,noMove:!1};class Hx extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"ease"),fx(this,"xScale"),fx(this,"yScale"),fx(this,"xIndependent"),fx(this,"yIndependent"),fx(this,"snapping"),this.options=Object.assign({},Wx,e),this.ease=bx(this.options.ease),this.xIndependent=!1,this.yIndependent=!1,this.xScale=0,this.yScale=0,this.options.width>0&&(this.xScale=t.screenWidth/this.options.width,this.xIndependent=!0),this.options.height>0&&(this.yScale=t.screenHeight/this.options.height,this.yIndependent=!0),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale,0===this.options.time?(t.container.scale.x=this.xScale,t.container.scale.y=this.yScale,this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom")):e.forceStart&&this.createSnapping()}createSnapping(){const t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,i=this.parent.screenWidth/this.xScale,s=this.parent.screenHeight/this.yScale;this.snapping={time:0,startX:t,startY:e,deltaX:i-t,deltaY:s-e},this.parent.emit("snap-zoom-start",this.parent)}resize(){this.snapping=null,this.options.width>0&&(this.xScale=this.parent.screenWidth/this.options.width),this.options.height>0&&(this.yScale=this.parent.screenHeight/this.options.height),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap-zoom"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap-zoom"):this.options.interrupt&&(this.snapping=null),!1}update(t){if(this.paused||this.options.interrupt&&0!==this.parent.input.count())return;let e;if(!this.options.center&&!this.options.noMove&&(e=this.parent.center),this.snapping){if(this.snapping){const i=this.snapping;if(i.time+=t,i.time>=this.options.time)this.parent.scale.set(this.xScale,this.yScale),this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom"),this.parent.emit("snap-zoom-end",this.parent),this.snapping=null;else{const t=this.snapping,e=this.ease(t.time,t.startX,t.deltaX,this.options.time),i=this.ease(t.time,t.startY,t.deltaY,this.options.time);this.parent.scale.x=this.parent.screenWidth/e,this.parent.scale.y=this.parent.screenHeight/i}const s=this.parent.plugins.get("clamp-zoom",!0);s&&s.clamp(),this.options.noMove||(this.options.center?this.parent.moveCenter(this.options.center):this.parent.moveCenter(e))}}else(this.parent.scale.x!==this.xScale||this.parent.scale.y!==this.yScale)&&this.createSnapping()}resume(){this.snapping=null,super.resume()}}const Yx={percent:.1,smooth:!1,interrupt:!0,reverse:!1,center:null,lineHeight:20,axis:"all",keyToPress:null,trackpadPinch:!1,wheelZoom:!0};class $x extends mx{constructor(t,e={}){super(t),fx(this,"options"),fx(this,"smoothing"),fx(this,"smoothingCenter"),fx(this,"smoothingCount"),fx(this,"keyIsPressed"),this.options=Object.assign({},Yx,e),this.keyIsPressed=!1,this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){window.addEventListener("keydown",(e=>{t.includes(e.code)&&(this.keyIsPressed=!0)})),window.addEventListener("keyup",(e=>{t.includes(e.code)&&(this.keyIsPressed=!1)}))}checkKeyPress(){return!this.options.keyToPress||this.keyIsPressed}down(){return this.options.interrupt&&(this.smoothing=null),!1}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}update(){if(this.smoothing){const t=this.smoothingCenter,e=this.smoothing;let i;this.options.center||(i=this.parent.toLocal(t)),this.isAxisX()&&(this.parent.scale.x+=e.x),this.isAxisY()&&(this.parent.scale.y+=e.y),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const s=this.parent.plugins.get("clamp-zoom",!0);if(s&&s.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const e=this.parent.toGlobal(i);this.parent.x+=t.x-e.x,this.parent.y+=t.y-e.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.smoothingCount++,this.smoothingCount>=this.options.smooth&&(this.smoothing=null)}}pinch(t){if(this.paused)return;const e=this.parent.input.getPointerPosition(t),i=-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/200,s=Math.pow(2,(1+this.options.percent)*i);let r;this.options.center||(r=this.parent.toLocal(e)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const n=this.parent.plugins.get("clamp-zoom",!0);if(n&&n.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const t=this.parent.toGlobal(r);this.parent.x+=e.x-t.x,this.parent.y+=e.y-t.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel-start",{event:t,viewport:this.parent})}wheel(t){if(this.paused||!this.checkKeyPress())return!1;if(t.ctrlKey&&this.options.trackpadPinch)this.pinch(t);else if(this.options.wheelZoom){const e=this.parent.input.getPointerPosition(t),i=(this.options.reverse?-1:1)*-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/500,s=Math.pow(2,(1+this.options.percent)*i);if(this.options.smooth){const t={x:this.smoothing?this.smoothing.x*(this.options.smooth-this.smoothingCount):0,y:this.smoothing?this.smoothing.y*(this.options.smooth-this.smoothingCount):0};this.smoothing={x:((this.parent.scale.x+t.x)*s-this.parent.scale.x)/this.options.smooth,y:((this.parent.scale.y+t.y)*s-this.parent.scale.y)/this.options.smooth},this.smoothingCount=0,this.smoothingCenter=e}else{let t;this.options.center||(t=this.parent.toLocal(e)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const i=this.parent.plugins.get("clamp-zoom",!0);if(i&&i.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const i=this.parent.toGlobal(t);this.parent.x+=e.x-i.x,this.parent.y+=e.y-i.y}}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel-start",{event:t,viewport:this.parent})}return!this.parent.options.passiveWheel}}let jx=class{constructor(t){fx(this,"viewport"),fx(this,"clickedAvailable"),fx(this,"isMouseDown"),fx(this,"last"),fx(this,"wheelFunction"),fx(this,"touches"),this.viewport=t,this.touches=[],this.addListeners()}addListeners(){this.viewport.eventMode="static",this.viewport.forceHitArea||(this.viewport.hitArea=new Vf(0,0,this.viewport.worldWidth,this.viewport.worldHeight)),this.viewport.on("pointerdown",this.down,this),this.viewport.options.allowPreserveDragOutside?this.viewport.on("globalpointermove",this.move,this):this.viewport.on("pointermove",this.move,this),this.viewport.on("pointerup",this.up,this),this.viewport.on("pointerupoutside",this.up,this),this.viewport.on("pointercancel",this.up,this),this.viewport.options.allowPreserveDragOutside||this.viewport.on("pointerleave",this.up,this),this.wheelFunction=t=>this.handleWheel(t),this.viewport.options.events.domElement.addEventListener("wheel",this.wheelFunction,{passive:this.viewport.options.passiveWheel}),this.isMouseDown=!1}destroy(){this.viewport.options.events.domElement.removeEventListener("wheel",this.wheelFunction)}down(t){if(!this.viewport.pause&&this.viewport.worldVisible){if("mouse"===t.pointerType?this.isMouseDown=!0:this.get(t.pointerId)||this.touches.push({id:t.pointerId,last:null}),1===this.count()){this.last=t.global.clone();const e=this.viewport.plugins.get("decelerate",!0),i=this.viewport.plugins.get("bounce",!0);e&&e.isActive()||i&&i.isActive()?this.clickedAvailable=!1:this.clickedAvailable=!0}else this.clickedAvailable=!1;this.viewport.plugins.down(t)&&this.viewport.options.stopPropagation&&t.stopPropagation()}}clear(){this.isMouseDown=!1,this.touches=[],this.last=null}checkThreshold(t){return Math.abs(t)>=this.viewport.threshold}move(t){if(this.viewport.pause||!this.viewport.worldVisible)return;const e=this.viewport.plugins.move(t);if(this.clickedAvailable&&this.last){const e=t.global.x-this.last.x,i=t.global.y-this.last.y;(this.checkThreshold(e)||this.checkThreshold(i))&&(this.clickedAvailable=!1)}e&&this.viewport.options.stopPropagation&&t.stopPropagation()}up(t){if(this.viewport.pause||!this.viewport.worldVisible)return;"mouse"===t.pointerType&&(this.isMouseDown=!1),"mouse"!==t.pointerType&&this.remove(t.pointerId);const e=this.viewport.plugins.up(t);this.clickedAvailable&&0===this.count()&&this.last&&(this.viewport.emit("clicked",{event:t,screen:this.last,world:this.viewport.toWorld(this.last),viewport:this.viewport}),this.clickedAvailable=!1),e&&this.viewport.options.stopPropagation&&t.stopPropagation()}getPointerPosition(t){const e=new jf;return this.viewport.options.events.mapPositionToPoint(e,t.clientX,t.clientY),e}handleWheel(t){if(this.viewport.pause||!this.viewport.worldVisible)return;const e=this.viewport.toLocal(this.getPointerPosition(t));this.viewport.left<=e.x&&e.x<=this.viewport.right&&this.viewport.top<=e.y&&e.y<=this.viewport.bottom&&this.viewport.plugins.wheel(t)&&!this.viewport.options.passiveWheel&&t.preventDefault()}pause(){this.touches=[],this.isMouseDown=!1}get(t){for(const e of this.touches)if(e.id===t)return e;return null}remove(t){for(let e=0;e<this.touches.length;e++)if(this.touches[e].id===t)return void this.touches.splice(e,1)}count(){return(this.isMouseDown?1:0)+this.touches.length}};const zx=["drag","pinch","wheel","follow","mouse-edges","decelerate","animate","bounce","snap-zoom","clamp-zoom","snap","clamp"];class Vx{constructor(t){fx(this,"plugins"),fx(this,"list"),fx(this,"viewport"),this.viewport=t,this.list=[],this.plugins={}}add(t,e,i=zx.length){const s=this.plugins[t];s&&s.destroy(),this.plugins[t]=e;const r=zx.indexOf(t);-1!==r&&zx.splice(r,1),zx.splice(i,0,t),this.sort()}get(t,e){var i;return e&&null!=(i=this.plugins[t])&&i.paused?null:this.plugins[t]}update(t){for(const e of this.list)e.update(t)}resize(){for(const t of this.list)t.resize()}reset(){for(const t of this.list)t.reset()}removeAll(){this.list.forEach((t=>{t.destroy()})),this.plugins={},this.sort()}remove(t){var e;this.plugins[t]&&(null==(e=this.plugins[t])||e.destroy(),delete this.plugins[t],this.viewport.emit("plugin-remove",t),this.sort())}pause(t){var e;null==(e=this.plugins[t])||e.pause()}resume(t){var e;null==(e=this.plugins[t])||e.resume()}sort(){this.list=[];for(const t of zx)this.plugins[t]&&this.list.push(this.plugins[t])}down(t){let e=!1;for(const i of this.list)i.down(t)&&(e=!0);return e}move(t){let e=!1;for(const i of this.viewport.plugins.list)i.move(t)&&(e=!0);return e}up(t){let e=!1;for(const i of this.list)i.up(t)&&(e=!0);return e}wheel(t){let e=!1;for(const i of this.list)i.wheel(t)&&(e=!0);return e}}const qx={screenWidth:window.innerWidth,screenHeight:window.innerHeight,worldWidth:null,worldHeight:null,threshold:5,passiveWheel:!0,stopPropagation:!1,forceHitArea:null,noTicker:!1,disableOnContextMenu:!1,ticker:ey.shared,allowPreserveDragOutside:!1};class Jx extends Ty{constructor(t){super(),fx(this,"moving"),fx(this,"screenWidth"),fx(this,"screenHeight"),fx(this,"threshold"),fx(this,"input"),fx(this,"plugins"),fx(this,"zooming"),fx(this,"lastViewport"),fx(this,"options"),fx(this,"_dirty"),fx(this,"_forceHitArea"),fx(this,"_hitAreaDefault"),fx(this,"_pause"),fx(this,"tickerFunction"),fx(this,"_worldWidth"),fx(this,"_worldHeight"),fx(this,"_disableOnContextMenu",(t=>t.preventDefault())),this.options={...qx,...t},this.screenWidth=this.options.screenWidth,this.screenHeight=this.options.screenHeight,this._worldWidth=this.options.worldWidth,this._worldHeight=this.options.worldHeight,this.forceHitArea=this.options.forceHitArea,this.threshold=this.options.threshold,this.options.disableOnContextMenu&&this.options.events.domElement.addEventListener("contextmenu",this._disableOnContextMenu),this.options.noTicker||(this.tickerFunction=()=>this.update(this.options.ticker.elapsedMS),this.options.ticker.add(this.tickerFunction)),this.input=new jx(this),this.plugins=new Vx(this)}destroy(t){!this.options.noTicker&&this.tickerFunction&&this.options.ticker.remove(this.tickerFunction),this.options.disableOnContextMenu&&this.options.events.domElement.removeEventListener("contextmenu",this._disableOnContextMenu),this.input.destroy(),super.destroy(t)}update(t){this.pause||(this.plugins.update(t),this.lastViewport&&(this.lastViewport.x!==this.x||this.lastViewport.y!==this.y?this.moving=!0:this.moving&&(this.emit("moved-end",this),this.moving=!1),this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y?this.zooming=!0:this.zooming&&(this.emit("zoomed-end",this),this.zooming=!1)),this.forceHitArea||(this._hitAreaDefault=new Vf(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight),this.hitArea=this._hitAreaDefault),this._dirty=this._dirty||!this.lastViewport||this.lastViewport.x!==this.x||this.lastViewport.y!==this.y||this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y,this.lastViewport={x:this.x,y:this.y,scaleX:this.scale.x,scaleY:this.scale.y},this.emit("frame-end",this))}resize(t=window.innerWidth,e=window.innerHeight,i,s){this.screenWidth=t,this.screenHeight=e,typeof i<"u"&&(this._worldWidth=i),typeof s<"u"&&(this._worldHeight=s),this.plugins.resize(),this.dirty=!0}get worldWidth(){return this._worldWidth?this._worldWidth:this.width/this.scale.x}set worldWidth(t){this._worldWidth=t,this.plugins.resize()}get worldHeight(){return this._worldHeight?this._worldHeight:this.height/this.scale.y}set worldHeight(t){this._worldHeight=t,this.plugins.resize()}getVisibleBounds(){return new Vf(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight)}toWorld(t,e){return 2===arguments.length?this.toLocal(new jf(t,e)):this.toLocal(t)}toScreen(t,e){return 2===arguments.length?this.toGlobal(new jf(t,e)):this.toGlobal(t)}get worldScreenWidth(){return this.screenWidth/this.scale.x}get worldScreenHeight(){return this.screenHeight/this.scale.y}get screenWorldWidth(){return this.worldWidth*this.scale.x}get screenWorldHeight(){return this.worldHeight*this.scale.y}get center(){return new jf(this.worldScreenWidth/2-this.x/this.scale.x,this.worldScreenHeight/2-this.y/this.scale.y)}set center(t){this.moveCenter(t)}moveCenter(...t){let e,i;"number"==typeof t[0]?(e=t[0],i=t[1]):(e=t[0].x,i=t[0].y);const s=(this.worldScreenWidth/2-e)*this.scale.x,r=(this.worldScreenHeight/2-i)*this.scale.y;return(this.x!==s||this.y!==r)&&(this.position.set(s,r),this.plugins.reset(),this.dirty=!0),this}get corner(){return new jf(-this.x/this.scale.x,-this.y/this.scale.y)}set corner(t){this.moveCorner(t)}moveCorner(...t){let e,i;return 1===t.length?(e=-t[0].x*this.scale.x,i=-t[0].y*this.scale.y):(e=-t[0]*this.scale.x,i=-t[1]*this.scale.y),(e!==this.x||i!==this.y)&&(this.position.set(e,i),this.plugins.reset(),this.dirty=!0),this}get screenWidthInWorldPixels(){return this.screenWidth/this.scale.x}get screenHeightInWorldPixels(){return this.screenHeight/this.scale.y}findFitWidth(t){return this.screenWidth/t}findFitHeight(t){return this.screenHeight/t}findFit(t,e){const i=this.screenWidth/t,s=this.screenHeight/e;return Math.min(i,s)}findCover(t,e){const i=this.screenWidth/t,s=this.screenHeight/e;return Math.max(i,s)}fitWidth(t=this.worldWidth,e,i=!0,s){let r;e&&(r=this.center),this.scale.x=this.screenWidth/t,i&&(this.scale.y=this.scale.x);const n=this.plugins.get("clamp-zoom",!0);return!s&&n&&n.clamp(),e&&r&&this.moveCenter(r),this}fitHeight(t=this.worldHeight,e,i=!0,s){let r;e&&(r=this.center),this.scale.y=this.screenHeight/t,i&&(this.scale.x=this.scale.y);const n=this.plugins.get("clamp-zoom",!0);return!s&&n&&n.clamp(),e&&r&&this.moveCenter(r),this}fitWorld(t){let e;t&&(e=this.center),this.scale.x=this.screenWidth/this.worldWidth,this.scale.y=this.screenHeight/this.worldHeight,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const i=this.plugins.get("clamp-zoom",!0);return i&&i.clamp(),t&&e&&this.moveCenter(e),this}fit(t,e=this.worldWidth,i=this.worldHeight){let s;t&&(s=this.center),this.scale.x=this.screenWidth/e,this.scale.y=this.screenHeight/i,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const r=this.plugins.get("clamp-zoom",!0);return r&&r.clamp(),t&&s&&this.moveCenter(s),this}setZoom(t,e){let i;e&&(i=this.center),this.scale.set(t);const s=this.plugins.get("clamp-zoom",!0);return s&&s.clamp(),e&&i&&this.moveCenter(i),this}zoomPercent(t,e){return this.setZoom(this.scale.x+this.scale.x*t,e)}zoom(t,e){return this.fitWidth(t+this.worldScreenWidth,e),this}get scaled(){return this.scale.x}set scaled(t){this.setZoom(t,!0)}snapZoom(t){return this.plugins.add("snap-zoom",new Hx(this,t)),this}OOB(){return{left:this.left<0,right:this.right>this.worldWidth,top:this.top<0,bottom:this.bottom>this.worldHeight,cornerPoint:new jf(this.worldWidth*this.scale.x-this.screenWidth,this.worldHeight*this.scale.y-this.screenHeight)}}get right(){return-this.x/this.scale.x+this.worldScreenWidth}set right(t){this.x=-t*this.scale.x+this.screenWidth,this.plugins.reset()}get left(){return-this.x/this.scale.x}set left(t){this.x=-t*this.scale.x,this.plugins.reset()}get top(){return-this.y/this.scale.y}set top(t){this.y=-t*this.scale.y,this.plugins.reset()}get bottom(){return-this.y/this.scale.y+this.worldScreenHeight}set bottom(t){this.y=-t*this.scale.y+this.screenHeight,this.plugins.reset()}get dirty(){return!!this._dirty}set dirty(t){this._dirty=t}get forceHitArea(){return this._forceHitArea}set forceHitArea(t){t?(this._forceHitArea=t,this.hitArea=t):(this._forceHitArea=null,this.hitArea=new Vf(0,0,this.worldWidth,this.worldHeight))}drag(t){return this.plugins.add("drag",new Lx(this,t)),this}clamp(t){return this.plugins.add("clamp",new Ax(this,t)),this}decelerate(t){return this.plugins.add("decelerate",new Ox(this,t)),this}bounce(t){return this.plugins.add("bounce",new Ex(this,t)),this}pinch(t){return this.plugins.add("pinch",new Ux(this,t)),this}snap(t,e,i){return this.plugins.add("snap",new Xx(this,t,e,i)),this}follow(t,e){return this.plugins.add("follow",new kx(this,t,e)),this}wheel(t){return this.plugins.add("wheel",new $x(this,t)),this}animate(t){return this.plugins.add("animate",new wx(this,t)),this}clampZoom(t){return this.plugins.add("clamp-zoom",new Sx(this,t)),this}mouseEdges(t){return this.plugins.add("mouse-edges",new Fx(this,t)),this}get pause(){return!!this._pause}set pause(t){this._pause=t,this.lastViewport=null,this.moving=!1,this.zooming=!1,t&&this.input.pause()}ensureVisible(t,e,i,s,r){r&&(i>this.worldScreenWidth||s>this.worldScreenHeight)&&(this.fit(!0,i,s),this.emit("zoomed",{viewport:this,type:"ensureVisible"}));let n=!1;t<this.left?(this.left=t,n=!0):t+i>this.right&&(this.right=t+i,n=!0),e<this.top?(this.top=e,n=!0):e+s>this.bottom&&(this.bottom=e+s,n=!0),n&&this.emit("moved",{viewport:this,type:"ensureVisible"})}}var Kx,Zx,Qx,tb=t=>{throw TypeError(t)},eb=(t,e,i)=>e.has(t)||tb("Cannot "+i),ib=(t,e,i)=>e.has(t)?tb("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),sb=(t,e,i,s)=>(eb(t,e,"write to private field"),e.set(t,i),i),rb=(t,e,i)=>(eb(t,e,"access private method"),i);const nb=100;var ob={exports:{}};function ab(){}ab.prototype={on:function(t,e,i){var s=this.e||(this.e={});return(s[t]||(s[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){var s=this;function r(){s.off(t,r),e.apply(i,arguments)}return r._=e,this.on(t,r,i)},emit:function(t){for(var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),s=0,r=i.length;s<r;s++)i[s].fn.apply(i[s].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),s=i[t],r=[];if(s&&e)for(var n=0,o=s.length;n<o;n++)s[n].fn!==e&&s[n].fn._!==e&&r.push(s[n]);return r.length?i[t]=r:delete i[t],this}},ob.exports=ab;var lb=ob.exports.TinyEmitter=ab;class hb extends lb{constructor({floorPlan:t,helperId:e}){super(),this.floorPlan=t,this.helperId=e}destroy(){delete this.floorPlan.helper[this.helperId],this.floorPlan=null}}class ub extends hb{constructor({floorPlan:t,parentEl:e,helperId:i}){super({floorPlan:t,helperId:i}),e&&t&&(this.data={cursor:["0","0"]},this.floorPlan.on("mousemove",this.update,this),this.mount(e),this.update())}update(){this.rootEl&&this.setData({cursor:[f(this.floorPlan.interaction.cursor[0],this.floorPlan.settings.units.system,this.floorPlan.settings.units.lengthDecimals),f(this.floorPlan.interaction.cursor[1],this.floorPlan.settings.units.system,this.floorPlan.settings.units.lengthDecimals)]})}setData(t={}){for(let e in t)this.data[e]=t[e];this.rootEl.innerHTML=this.template(this.data)}template(t={}){return`<span class="fpe-coordinates__unit">x:${t.cursor[0]}</span>\n <span class="fpe-coordinates__unit">z:${t.cursor[1]}</span>`}mount(t){this.rootEl||(this.rootEl=document.createElement("div"),this.rootEl.classList.add("fpe-coordinates"),t.appendChild(this.rootEl))}destroy(){this.floorPlan.off("mousemove",this.update),this.rootEl.remove(),delete this.floorPlan,delete this.data}}class cb extends hb{constructor({floorPlan:t,parentEl:e,helperId:i}){super({floorPlan:t,helperId:i}),e&&t&&(this.data={width:100,height:4,margin:2,style:"lines",box:{},scaleStep:null,scaleDisplay:null,steps:[],leftHanded:!1,isImperial:"imperial"===t.settings.units.system},this.floorPlan.view.on("zoom",this.update,this),this.floorPlan.on("update-settings",this.update,this),this.mount(e),this.update())}update(){this.data.isImperial="imperial"===this.floorPlan.settings.units.system;const t=this.data.isImperial?3.28084:1;if(!this.floorPlan.view.viewbox)return;this.data.box.length=this.floorPlan.view.viewbox.max[0]-this.floorPlan.view.viewbox.min[0],this.data.box.width=this.floorPlan.view.viewbox.max[1]-this.floorPlan.view.viewbox.min[1];const e=Math.min(this.floorPlan.view.client[0],this.floorPlan.view.client[1]),i=Math.min(this.data.box.length,this.data.box.width),s=e/i;if(!s)return;const r=200/s;this.data.scaleStep=i<=.5/t?.01/t:i<=1/t?.05/t:i<=2.5/t?.1/t:i<=5.4/t?.2/t:i<=12/t?.5/t:i<=25/t?1/t:i<=50/t?2/t:i<=100/t?5/t:i<=200/t?10/t:i<=550/t?20/t:50/t,this.data.scaleDisplay=this.data.scaleStep*t;const n=this.data.width,o=n*this.data.scaleStep/r,a=this.leftHanded?0:n;let l=0,h=[];if(this.data.leftHanded)for(;l<n-o;){let t=o<n-l?o:n-l;h.push([l+a,t]),l+=o}else for(;l>-n+o;){let t=o;h.push([l+a,-t]),l-=o}this.data.steps=h,this.setData()}setData(t={}){for(let e in t)this.data[e]=t[e];this.rootEl.setAttribute("viewBox",`-${this.data.margin} -${3*this.data.margin} ${this.data.width+2*this.data.margin} ${this.data.height+2*this.data.margin}`),this.rootEl.innerHTML=this.template(this.data)}template(t={}){let e="";return t.steps[0]&&(e+=`<rect\n class="fpe-scale-bar__background"\n style="fill:${this.backgroundClr()}"\n y="${2.5*-t.height}"\n x="${t.width+t.steps[0][1]-t.margin}"\n width="${-t.steps[0][1]+2*t.margin}"\n height="${4*t.height}"\n />`),e+=`<text x="${t.leftHanded?0:t.width}" text-anchor="${t.leftHanded?"start":"end"}" y="-3">\n ${t.scaleDisplay} ${t.isImperial?"ft":"m"}\n </text>`,"lines"===t.style&&(e+=`<path d="${this.stepStr(t.steps)}" />`),"solid"===t.style&&(e+="<g>",t.steps.forEach(((t,i)=>{e+=`<rect\n class="${i%2!=0?"white":""}"\n x="${t[0]}"\n y="0"\n width="${t[1]}"\n height="0.5"\n />`})),e+="</g>"),e}backgroundClr(){let t=this.floorPlan.settings&&function(t,e=1){if(null!==y(t).match(/^#[a-f0-9]{6}$/i)){const{r:i,g:s,b:r}=x(t);return`rgba(${i},${s},${r},${e})`}}(this.floorPlan.settings.theme.background.color);return t||(t="rgba(255, 255, 255, 0.8)"),t+"!important"}stepStr(t){if(!t)return"";let e="",i=this.data.height;return t.forEach(((t,s)=>{if(s>=1&&!this.data.leftHanded)return;t=t.map((t=>Math.round(1e3*t)/1e3));let r=s%2==0?0:i,n=s%2==0?i:0;0===s&&(e+=`M ${t[0]} ${i} L ${t[0]} 0`),e+=`L ${t[0]+t[1]} ${r} `,e+=`L ${t[0]+t[1]} ${n} `})),e}mount(t){this.rootEl||(this.rootEl=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.rootEl.classList.add("fpe-scale-bar"),t.appendChild(this.rootEl))}destroy(){this.floorPlan.view.off("viewbox",this.update),this.floorPlan.off("update-settings",this.update),this.rootEl.remove(),delete this.floorPlan.helper.scaleBar,delete this.floorPlan,delete this.data}}const db=100,pb=80;class fb{constructor({width:t,height:e,position:i=[0,0],html:s="",closeButton:r=!0,floorPlan:n}={}){this._floorPlan=n,this.position=i,this.html=s,this.closeButton=r,this._anchorPos=null;let o=t||db;this.width=Math.max(100,o);let a=e||pb;this.height=Math.max(50,a),this._getPosition=()=>{this._anchorPos=this._floorPlan.getScreenPosition(this.position),this._updateInfoWindow()},this._getPosition(),this._createInfoWindow(),this._floorPlan.view.on("viewbox",this._getPosition,this),this._floorPlan.view.on("resize-canvas",this._getPosition,this)}_createInfoWindow(){const t=document.querySelector(`#${this._floorPlan.fpeId}.fpe`),e=t.querySelector("canvas");this.el||(this.el=document.createElement("div"),this.el.classList.add("fpe-info-window"),t.appendChild(this.el),this.el.addEventListener("wheel",(t=>{let i=new WheelEvent(t.type,t);e.dispatchEvent(i)}))),this._setContent(),this._updateInfoWindow()}_setContent(){let t=`<div class="fpe-info-window__content">${this.html}</div>`;this.closeButton&&(t+='<div class="fpe-info-window__close" @click="infoWindow.remove"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">\n <g fill="none" stroke="#000" stroke-width="1.2" stroke-miterlimit="10">\n <path d="M11.8 11.8l16.4 16.4M11.8 28.2l16.3-16.4" />\n </g>\n</svg></div>'),this.el.innerHTML=t;const e=this.el.querySelector(".fpe-info-window__close");e&&e.addEventListener("click",this.remove.bind(this))}_updateInfoWindow(){if(!this.el)return;const t=this._floorPlan.interaction.isPanning?"pointer-events: none;":"",e=this._anchorPos[0]-47,i=this._anchorPos[1]-this.height-15,s=1e3+2*this.position[1],r=this.height,n=this.width;this.el.setAttribute("style",`transform: translate(${e}px, ${i}px);${t} height:${r}px; width:${n}px; z-index:${s}`)}set({width:t,height:e,position:i,html:s,closeButton:r}){void 0!==i&&(this.position=i),void 0!==t&&(this.width=Math.max(100,t)),void 0!==e&&(this.height=Math.max(50,e)),void 0!==s&&(this.html=s),void 0!==r&&(this.closeButton=r),void 0===s&&void 0===r||this._setContent(),this._getPosition()}remove(){this._floorPlan.view.off("viewbox",this._getPosition),this._floorPlan.view.off("resize-canvas",this._getPosition),this.el.remove(),this._floorPlan=null}}class mb{constructor({position:t=[0,0],offset:e=[0,0],el:i,floorPlan:s}){if(this._updateHtmlMarker=()=>{this.el&&(this.isHidden=!(([t,e],i,s=0)=>i.min[0]-s<t&&i.max[0]+s>t&&i.min[1]-s<e&&i.max[1]+s>e)(this.position,this._floorPlan.view.viewbox,5),this.el.classList.toggle("fpe-marker--hidden",this.isHidden),this.isHidden||(this._anchorPos=this._floorPlan.getScreenPosition(this.position),this._updateHtmlMarkerStyle()))},!s)return;if(i instanceof HTMLElement==!1)return void nl.warn("no Element provided");this.el=i;const r=document.querySelector(`#${s.fpeId}.fpe`),n=r.querySelector("canvas");r.appendChild(this.el),this.el.classList.add("fpe-marker");const{width:o,height:a}=i.getBoundingClientRect();this.el.addEventListener("wheel",(t=>{let e=new WheelEvent(t.type,t);n.dispatchEvent(e)})),this.id=O(),this._floorPlan=s,this.position=t,this.size=[o,a],this.offset=e,this._updateHtmlMarker(),this._floorPlan.view.on("viewbox",this._updateHtmlMarker),this._floorPlan.on("drag-end",this._updateHtmlMarker),this._floorPlan.view.on("resize-canvas",this._updateHtmlMarker)}_updateHtmlMarkerStyle(){const t=this._floorPlan.interaction.isPanning,e=this.offset?this.offset:[0,0],i=this._anchorPos[0]-this.size[0]/2+e[0],s=this._anchorPos[1]-this.size[1]/2+e[1];this.el.style.pointerEvents=t?"none":"",this.el.style.transform=`translate(${i}px, ${s}px)`}set({position:t,offset:e}){void 0!==t&&(this.position=t),void 0!==e&&(this.offset=e),this._updateHtmlMarker()}remove(){this._floorPlan.view.off("viewbox",this._updateHtmlMarker),this._floorPlan.view.off("resize-canvas",this._updateHtmlMarker),this._floorPlan.off("drag-end",this._updateHtmlMarker),this.el.remove(),this._floorPlan=null}}var gb={grad:.9,turn:360,rad:360/(2*Math.PI)},yb=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},vb=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},xb=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},bb=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_b=function(t){return{r:xb(t.r,0,255),g:xb(t.g,0,255),b:xb(t.b,0,255),a:xb(t.a)}},wb=function(t){return{r:vb(t.r),g:vb(t.g),b:vb(t.b),a:vb(t.a,3)}},Pb=/^#([0-9a-f]{3,8})$/i,Eb=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Tb=function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=Math.max(e,i,s),o=n-Math.min(e,i,s),a=o?n===e?(i-s)/o:n===i?2+(s-e)/o:4+(e-i)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},Ab=function(t){var e=t.h,i=t.s,s=t.v,r=t.a;e=e/360*6,i/=100,s/=100;var n=Math.floor(e),o=s*(1-i),a=s*(1-(e-n)*i),l=s*(1-(1-e+n)*i),h=n%6;return{r:255*[s,a,o,o,l,s][h],g:255*[l,s,s,a,o,o][h],b:255*[o,o,l,s,s,a][h],a:r}},Ib=function(t){return{h:bb(t.h),s:xb(t.s,0,100),l:xb(t.l,0,100),a:xb(t.a)}},Sb=function(t){return{h:vb(t.h),s:vb(t.s),l:vb(t.l),a:vb(t.a,3)}},Cb=function(t){return Ab((i=(e=t).s,{h:e.h,s:(i*=((s=e.l)<50?s:100-s)/100)>0?2*i/(s+i)*100:0,v:s+i,a:e.a}));var e,i,s},Mb=function(t){return{h:(e=Tb(t)).h,s:(r=(200-(i=e.s))*(s=e.v)/100)>0&&r<200?i*s/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,i,s,r},Ob=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Nb=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lb=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Rb=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,kb={string:[[function(t){var e=Pb.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?vb(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?vb(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Lb.exec(t)||Rb.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:_b({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Ob.exec(t)||Nb.exec(t);if(!e)return null;var i,s,r=Ib({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(gb[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return Cb(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=void 0===r?1:r;return yb(e)&&yb(i)&&yb(s)?_b({r:Number(e),g:Number(i),b:Number(s),a:Number(n)}):null},"rgb"],[function(t){var e=t.h,i=t.s,s=t.l,r=t.a,n=void 0===r?1:r;if(!yb(e)||!yb(i)||!yb(s))return null;var o=Ib({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return Cb(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!yb(e)||!yb(i)||!yb(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:bb(o.h),s:xb(o.s,0,100),v:xb(o.v,0,100),a:xb(o.a)});return Ab(a)},"hsv"]]},Bb=function(t,e){for(var i=0;i<e.length;i++){var s=e[i][0](t);if(s)return[s,e[i][1]]}return[null,void 0]},Fb=function(t,e){var i=Mb(t);return{h:i.h,s:xb(i.s+100*e,0,100),l:i.l,a:i.a}},Db=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Ub=function(t,e){var i=Mb(t);return{h:i.h,s:i.s,l:xb(i.l+100*e,0,100),a:i.a}},Gb=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Bb(t.trim(),kb.string):"object"==typeof t&&null!==t?Bb(t,kb.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return vb(Db(this.rgba),2)},t.prototype.isDark=function(){return Db(this.rgba)<.5},t.prototype.isLight=function(){return Db(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=wb(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?Eb(vb(255*r)):"","#"+Eb(e)+Eb(i)+Eb(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return wb(this.rgba)},t.prototype.toRgbString=function(){return e=(t=wb(this.rgba)).r,i=t.g,s=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+s+", "+r+")":"rgb("+e+", "+i+", "+s+")";var t,e,i,s,r},t.prototype.toHsl=function(){return Sb(Mb(this.rgba))},t.prototype.toHslString=function(){return e=(t=Sb(Mb(this.rgba))).h,i=t.s,s=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+s+"%, "+r+")":"hsl("+e+", "+i+"%, "+s+"%)";var t,e,i,s,r},t.prototype.toHsv=function(){return t=Tb(this.rgba),{h:vb(t.h),s:vb(t.s),v:vb(t.v),a:vb(t.a,3)};var t},t.prototype.invert=function(){return Xb({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),Xb(Fb(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),Xb(Fb(this.rgba,-t))},t.prototype.grayscale=function(){return Xb(Fb(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),Xb(Ub(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),Xb(Ub(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?Xb({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):vb(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Mb(this.rgba);return"number"==typeof t?Xb({h:t,s:e.s,l:e.l,a:e.a}):vb(e.h)},t.prototype.isEqual=function(t){return this.toHex()===Xb(t).toHex()},t}(),Xb=function(t){return t instanceof Gb?t:new Gb(t)},Wb=[];!function(t){t.forEach((function(t){Wb.indexOf(t)<0&&(t(Gb,kb),Wb.push(t))}))}([function(t,e){var i={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},s={};for(var r in i)s[i[r]]=r;var n={};t.prototype.toName=function(e){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var r,o,a=s[this.toHex()];if(a)return a;if(null==e?void 0:e.closest){var l=this.toRgb(),h=1/0,u="black";if(!n.length)for(var c in i)n[c]=new t(i[c]).toRgb();for(var d in i){var p=(r=l,o=n[d],Math.pow(r.r-o.r,2)+Math.pow(r.g-o.g,2)+Math.pow(r.b-o.b,2));p<h&&(h=p,u=d)}return u}},e.string.push([function(e){var s=e.toLowerCase(),r="transparent"===s?"#0000":i[s];return r?new t(r).toRgb():null},"name"])}]);const Hb=class t{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(e){if(e instanceof t)this._value=this.cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(null===e)throw new Error("Cannot set PIXI.Color#value to null");(null===this._value||!this.isSourceEqual(this._value,e))&&(this.normalize(e),this._value=this.cloneSource(e))}}get value(){return this._value}cloneSource(t){return"string"==typeof t||"number"==typeof t||t instanceof Number||null===t?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):"object"==typeof t&&null!==t?{...t}:t}isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if("number"===i||"string"===i||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length===e.length&&t.every(((t,i)=>t===e[i]));if(null!==t&&null!==e){const i=Object.keys(t),s=Object.keys(e);return i.length===s.length&&i.every((i=>t[i]===e[i]))}return t===e}toRgba(){const[t,e,i,s]=this._components;return{r:t,g:e,b:i,a:s}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,s]=this._components;return(t=t??[])[0]=Math.round(255*e),t[1]=Math.round(255*i),t[2]=Math.round(255*s),t}toRgbArray(t){t=t??[];const[e,i,s]=this._components;return t[0]=e,t[1]=i,t[2]=s,t}toNumber(){return this._int}toLittleEndianNumber(){const t=this._int;return(t>>16)+(65280&t)+((255&t)<<16)}multiply(e){const[i,s,r,n]=t.temp.setValue(e)._components;return this._components[0]*=i,this._components[1]*=s,this._components[2]*=r,this._components[3]*=n,this.refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this.refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(1===t)return(255<<24)+this._int;if(0===t)return e?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,r=255&this._int;return e&&(i=i*t+.5|0,s=s*t+.5|0,r=r*t+.5|0),(255*t<<24)+(i<<16)+(s<<8)+r}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const t=Math.round(255*this._components[3]).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(t){return this._components[3]=this._clamp(t),this}round(t){const[e,i,s]=this._components;return this._components[0]=Math.round(e*t)/t,this._components[1]=Math.round(i*t)/t,this._components[2]=Math.round(s*t)/t,this.refreshInt(),this._value=null,this}toArray(t){t=t??[];const[e,i,s,r]=this._components;return t[0]=e,t[1]=i,t[2]=s,t[3]=r,t}normalize(e){let i,s,r,n;if(("number"==typeof e||e instanceof Number)&&e>=0&&e<=16777215){i=(e>>16&255)/255,s=(e>>8&255)/255,r=(255&e)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[i,s,r,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[i,s,r,n=255]=e,i/=255,s/=255,r/=255,n/=255;else if("string"==typeof e||"object"==typeof e){if("string"==typeof e){const i=t.HEX_PATTERN.exec(e);i&&(e=`#${i[2]}`)}const o=Xb(e);o.isValid()&&(({r:i,g:s,b:r,a:n}=o.rgba),i/=255,s/=255,r/=255)}if(void 0===i)throw new Error(`Unable to convert color ${e}`);this._components[0]=i,this._components[1]=s,this._components[2]=r,this._components[3]=n,this.refreshInt()}refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(255*t<<16)+(255*e<<8)+(255*i|0)}_clamp(t,e=0,i=1){return"number"==typeof t?Math.min(Math.max(t,e),i):(t.forEach(((s,r)=>{t[r]=Math.min(Math.max(s,e),i)})),t)}};Hb.shared=new Hb,Hb.temp=new Hb,Hb.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let Yb=Hb;class $b{constructor({position:t,color:e,size:i,floorPlan:s}){this.position=t,this.color=e,this.size=i,this.floorPlan=s,this.id=O(),this.draw()}draw(){const t=this.size/4e3;this.layer=this.floorPlan.addLayer({id:"fpe-markers"});let e=[{type:"curve:composite",segments:[{type:"curve:arc",position:[0,-27.8],radius:12.4,startAngle:-25,endAngle:205},{type:"curve:line",end:[0,0],start:[-11.2,-22.5]}],style:{fill:new Yb(this.color).toNumber(),stroke:6710886,strokeWidth:.5/t}},{type:"curve:circle",position:[0,-28],radius:5,style:{fill:1,fillOpacity:.2}}];this.graphic=this.layer.addGraphic({shapes:e,position:this.position,id:"marker_"+this.id,scale:t,scaleOnZoom:!0})}remove(){this.off("click"),this.layer.deleteGraphic(this.graphic),delete this.floorPlan,0===this.layer.graphics.size&&this.layer.destroy()}on(t="click",e,i){this.graphic.gfx.eventMode="static",this.graphic.gfx.on(t,e,i)}off(t="click",e){this.graphic.gfx.off(t,e)}set(t){let e=["position","color","size"];Object.keys(t).forEach((i=>{e.includes(i)&&(this[i]=t[i])})),this.draw()}}const jb=t=>{if(null==t?void 0:t.children)for(var e=t.children.length-1;e>=0;e--)t.children[e].destroy({children:!0}),t.removeChild(t.children[e])};function zb(t,e,i){const s=new Sy(t);return s.x=0,s.y=0,s.anchor.x=.5,s.anchor.y=.5,s.rotation=0,e&&(s.width=e),i&&(s.height=i),s}function Vb(t=[]){return(t=t.sort(((t,e)=>Q(t)>Q(e)?-1:1)))&&t.length?[{type:"curve:polygonWithHoles",polygons:t}]:[]}function qb(t,e,i=!1,s=16,r=8){let n=[];for(let m=0;m<e.length-1;m+=2)n.push({x:e[m],y:e[m+1]});let o,a,l,h=0,u=0,c=i?1:0;for(o=0;o<n.length-c;o++){a=n[o],l=o==n.length-1?n[0]:n[o+1];let e=l.x-a.x,i=l.y-a.y;var d=Math.sqrt(e*e+i*i),p={x:e/d,y:i/d},f=0;for(t.moveTo(a.x+u*p.x,a.y+u*p.y);f<=d;)f+=u,(f+=h>0?h:s)>d?(h=f-d,f=d):h=0,t.lineTo(a.x+f*p.x,a.y+f*p.y),(f+=r)>d&&0==h?u=f-d:(u=0,t.moveTo(a.x+f*p.x,a.y+f*p.y))}}function Jb(t){return t.stroke?{alpha:t.strokeOpacity||1,color:Nl(t.stroke),native:"native"===t.strokeWidth,width:"number"==typeof t.strokeWidth?t.strokeWidth:1,alignment:"number"==typeof t.alignment?t.alignment:.5}:{}}function Kb({shape:t,settings:e,gfx:i,style:s={}}){var r,n,o;if(!i||!i.lineStyle)return;let a={...s,...t.style||{}};const l=nb,h=!["curve:line","curve:polyline","curve:arc"].includes(t.type)&&!!a.fill;if("string"==typeof(null==a?void 0:a.fill)&&a.fill.startsWith("url("))!function({shape:t,settings:e,style:i,gfx:s}){var r;if(Of.defaultOptions.scaleMode=Zl.NEAREST,"string"!=typeof i.fill||"curve:rectangle"!==t.type&&"curve:polygon"!==t.type)return;let n,o,a=[0,0],l=null==(r=i.fill.match(/url\((.*?)\)/))?void 0:r[1];if(!l||!l.startsWith("data:image")&&!l.startsWith("https://"))return;let h=Sy.from(l);if("curve:polygon"===t.type){let{min:i,max:r}=Y([t.points]);n=r[0]-i[0],o=r[1]-i[1],a=i;let l=new ev;Kb({shape:{type:"curve:polygon",points:t.points,style:{fill:16777215}},settings:e,gfx:l}),s.addChild(l),h.mask=l}else n=t.dimensions[0],o=t.dimensions[1],a=t.position;h.width=n*nb,h.height=o*nb,h.x=a[0]*nb,h.y=a[1]*nb,h.anchor.set(0),s.addChild(h)}({shape:t,settings:e,style:a,gfx:i});else{if(h&&a.fill&&i.beginFill(Nl(a.fill),a.fillOpacity),i.lineStyle(Jb(a)),"curve:rectangle"===t.type){let{position:e,dimensions:s}=t;i.drawRect(e[0]*l,e[1]*l,s[0]*l,s[1]*l)}else if("curve:circle"===t.type||"curve:composite"===t.type){Zb(Ul(t).points,[],a,l,i,h)}else if("curve:arc"===t.type||"curve:quadraticBezier"===t.type){Gl(t).points.forEach(((t,e)=>{0===e?i.moveTo(t[0]*l,t[1]*l):i.lineTo(t[0]*l,t[1]*l)}))}else if("curve:polygon"===t.type)Zb(t.points,[],a,l,i,h);else if("curve:polygonWithHoles"===t.type){let{polygons:e}=t;Zb(e[0],e.slice(1),a,l,i,h)}else if("curve:line"===t.type){let{start:e=[],end:s=[]}=t;i.moveTo(e[0]*l,e[1]*l),i.lineTo(s[0]*l,s[1]*l)}else if("curve:polyline"===t.type){let{points:e}=t;a.dash?qb(i,e.flat().map((t=>t*l)),!0):e.forEach(((t,e)=>{0===e?i.moveTo(t[0]*l,t[1]*l):i.lineTo(t[0]*l,t[1]*l)}))}else if("group"===t.type){let{position:r=[0,0],rotation:n=0}=t,o=new ev;o.x=r[0]*l,o.y=r[1]*l,o.rotation=-Math.PI/180*n,t.children.forEach((t=>Kb({shape:t,settings:e,gfx:o,style:s}))),i.addChild(o)}else if("text"===t.type){let s=(null==(r=t.style)?void 0:r.fill)?Nl(t.style.fill):0,a=(null==(n=t.style)?void 0:n.stroke)?Nl(t.style.stroke):16777215,{position:h=[0,0],rotation:u=0,text:c,alignH:d="center",alignV:p="center",fontSize:f=16}=t;const m=new lv({fontFamily:(null==(o=null==e?void 0:e.theme)?void 0:o.fontFamily)||il.theme.fontFamily,fontSize:f,fill:s,align:d,stroke:a,strokeThickness:3});let g=new pv(c,m);g.x=h[0]*l,g.y=h[1]*l,g.rotation=-Math.PI/180*u,g.anchor.x=.5,g.anchor.y="center"===p?.5:"bottom"===p?1:0,i.addChild(g)}h&&i.endFill()}}function Zb(t=[],e=[],i={},s=100,r,n){if(!t||!Array.isArray(t)||!t.length)return r;r.lineStyle(Jb(i));let o=t.flat().map((t=>t*s));if(i.dash?(qb(r,o),n&&(r.lineStyle(0),r.drawPolygon(o))):r.drawPolygon(o),e.length){n&&r.beginHole();for(const t of e){let e=t.flat().map((t=>t*s));r.drawPolygon(e)}n&&r.endHole()}return r}function Qb(t,e){e.on("product-load-texture",(({resourceId:i})=>{!function(t,e){let i=t.resources.productJson.get(e);if(!i.boundingBox)return void nl.warn("product boundingBox missing");const{boundingBox:s}=i,r=xl(s);let n={x:s.min[0],y:s.min[2]},o={x:Math.abs(s.min[0]/r[0]),y:Math.abs(s.min[2]/r[2])},a={x:s.max[0]-r[0]/2,y:s.max[2]-r[2]/2},l=t.resources.texture.get(e);l.offset=a,l.anchor=o,l.position=n}(e,i),t_({view:t,resourceId:i,loader:e})}));const i=new ev;i.lineStyle({native:!0,color:3355443}),i.drawCircle(0,0,1),t._dummyTexture=t._renderer.generateTexture(i)}function t_({resourceId:t,loader:e,view:i}){if(!e.resources.texture.has(t))return Promise.reject(`no texture data to load ${t}`);const s=e.resources.texture.get(t);if(s.texture)return Promise.resolve();let{textureUrl:r}=s;return af(),function(t){return new Promise(((e,i)=>{var s=new Image;s.addEventListener("load",(()=>{URL.revokeObjectURL(s.src),e(new tg(new Of(s)))})),s.addEventListener("error",(()=>{URL.revokeObjectURL(s.src),i("image loading failed: "+t)}));const r=t.includes("/storage/get/"),n=t.startsWith("https://")?t:rl+t;s.src=n,s.crossOrigin=r?"use-credentials":"anonymous"}))}(r).then((r=>{s.imageData=r,function(t,e,i){const s=null==e?void 0:e._renderer,r=i.resources.texture.get(t),n=r.error;if(af(),!r.texture){const e=i.resources.productJson.get(t),o=new Ty;let a,l;n||(a=new Sy(r.imageData),a=i_(a,r.applyFilter),o.addChild(a));const h=i.resources.productContour.get(t),u=(null==h?void 0:h.length)?[{type:"curve:polygon",points:h[0],holes:h.slice(1)}]:[];if(u.length&&(null==e?void 0:e.boundingBox)){let t;n?t={strokeWidth:.5,stroke:1,fill:16316664}:(t=kl({settings:{theme:{showAssetTextures:!0,elements:{}}},elementType:"element:asset"}),t.stroke=el.stone),l=e_(u,t);const i=new Sy(l);i.anchor.x=r.anchor.x,i.anchor.y=r.anchor.y;const s=xl(e.boundingBox);if(!n){let t=a.width/s[0],e=(null==r?void 0:r.offset)||{x:0,y:0};i.scale.x=a.width/i.width,i.scale.y=a.height/i.height,i.x=a.width/2-e.x*t,i.y=a.height/2-e.y*t}o.addChild(i)}r.texture=s.generateTexture(o,{scaleMode:Zl.LINEAR,resolution:1.5}),o.destroy(!0),l&&l.destroy(!0)}i.emit("resource-loaded",{resourceId:t})}(t,i,e)})).catch((i=>{nl.warn(i),s.error={message:i},e.emit("resource-loaded",{resourceId:t})}))}function e_(t,e){let i,s=new ev;for(const r of t)Kb({shape:r,gfx:s,style:e});return i=s.generateCanvasTexture(Zl.LINEAR,2),s.destroy(),i}function i_(t,e){switch(e){case ml.Default:{const e=new fv;e.matrix=[.7,0,0,0,.25,0,.7,0,0,.25,0,0,.7,0,.25,0,0,0,1,0],t.filters=[e];break}case ml.Grayscale:{const e=new fv;e.blackAndWhite(!0),t.filters=[e];break}case ml.None:}return t}function s_(t,e,i,s){var r,n,o,a;!function(t,e){var i;const s=null==(i=t.product)?void 0:i.id,{loader:r}=e,n=r.resources.nodes.get(s);if(s&&!(null==n?void 0:n.has(t)))ol(e.loader,t).catch((t=>nl.warn(t)))}(t,i);const{view:l,settings:h,loader:u}=i,{theme:c,showCeilingLamps:d}=h,p=nb;let f,m,g=[];const y=null==(r=t.product)?void 0:r.id,v=u.resources.productJson.get(y)||{subCategories:[]},x="product:component"===(null==(n=t.product)?void 0:n.type),b=u.resources.productContour.get(y),_=u.resources.texture.get(y),w=Vb(b);if((null==v?void 0:v.subCategories.includes("ceilingLight"))&&!d)return[];let P=0;if(x)for(const A of t.elements){if("element:asset"!==A.type||!A.product)continue;const t=Wl(A.product.attributes);t>P&&(P=t)}else P=Wl(v);const E=Il(t.type,P);e.zIndex=E||0;let T=kl({element:t,settings:h,style:s});if(b||x||!v.boundingBox)if(c.showAssetTextures&&!(null==_?void 0:_.error)||!b)if(c.showAssetTextures&&(null==_?void 0:_.texture)){const t=xl(v.boundingBox);if(f=zb(_.texture,t[0]*p,t[2]*p),f.anchor.x=_.anchor.x,f.anchor.y=_.anchor.y,f.zIndex=1,(null==(o=v.categories)?void 0:o.includes("tables"))||(null==(a=v.categories)?void 0:a.includes("seating"))){const t=new Kf(w[0].polygons[0].flatMap((t=>[t[0]*p/f.scale.x,t[1]*p/f.scale.y])));f.hitArea=t,f.interactive=!0}"selected"===s?(_.contourTexture||(_.contourTexture=e_(w,{stroke:T.stroke,strokeWidth:T.strokeWidth||1})),m=new Sy(_.contourTexture),m.anchor.x=_.anchor.x,m.anchor.y=_.anchor.y,m.zIndex=5,T.fill&&(f.tint=Nl(T.fill))):s&&(m=new ev,g=w||[],m.zIndex=5)}else f=new Sy(l._dummyTexture);else{const e={...c,showAssetTextures:!1};T=kl({element:t,settings:{...h,theme:e},style:s}),g=w,f=new ev}else{g=Vb(function(t){const e=t;if(e){let t;return t=[[e.min[0],e.min[2]],[e.min[0],e.max[2]],[e.max[0],e.max[2]],[e.max[0],e.min[2]]],[t]}return[]}(v.boundingBox)),f=new ev}m&&(m.eventMode="none");for(const A of g)Kb({shape:A,settings:h,gfx:m||f,style:T});return[f,m]}function r_(t,e,i,s,r,n){let o,a,l=[];const{view:h,settings:u}=i;if("element:asset"===t.type){let r=s_(t,e,i,s);o=r[0],a=r[1]}else if("annotation:floorPlanImage"===t.type){let s=function(t,e,i){var s,r;const{view:n,settings:o,loader:a}=i,l=nb;let h,u;e.x=t.position[0]*l,e.y=t.position[2]*l,e.rotation=-Math.PI/180*t.rotation||0;const{uri:c,length:d,width:p}=t.parameters,f=t.id,m=(null==(r=null==(s=o.theme.elements)?void 0:s.floorPlan)?void 0:r.grayscale)?ml.Grayscale:ml.None,g=a.resources.texture.get(f);return(null==g?void 0:g.texture)?(h=zb(g.texture,d*l,p*l),h=i_(h,m),u=new ev,h.zIndex=1,u.zIndex=5):(a.resources.nodes.set(f,new Set([t])),a.resources.texture.set(f,{textureUrl:c,applyFilter:m}),t_({loader:a,view:n,resourceId:f}),h=new ev),[h,u]}(t,e,i);o=s[0],a=s[1]}else{if("element:wall"===t.type)l=function(t){var e;let{valid:i,points:s}=t.geometryProfile,r=[];if(null==(e=t.layout)?void 0:e.debugIds){for(let t of s)r.push({type:"curve:circle",radius:.02,position:t,style:{stroke:0,fill:i?32768:16711680,fillOpacity:.2}});let e=kl({element:t});i||(e.stroke=16711680),r.push({type:"curve:polygon",points:s,style:e})}else r.push({type:"curve:polygon",points:s});return r}(t);else if("element:opening"===t.type)l=bl(t);else if("spatialGraph:edge"===t.type)l=function(t,e={}){let[i,s]=t.vertices,r="selected"===e,n=[{type:"curve:line",start:i.position,end:s.position}];if(t.layout.debugIds){let e,r=Qa(t.id)?t.id.substring(0,4):t.id;t.element&&(e=Qa(t.element.id)?t.element.id.substring(0,4):t.element.id);let o=t.element?`${r} (${e})`:r;n.push({type:"text",position:ri(i.position,pi(fi(s.position,i.position),.5)),text:o,fontSize:10})}if(null===t.element||"element:spaceDivider"===t.element.type){let t=ci(di(fi(s.position,i.position))),e=.02,o=ri(i.position,pi(t,-e)),a=ri(i.position,pi(t,e)),l=ri(s.position,pi(t,e)),h=ri(s.position,pi(t,-e));n.unshift({type:"curve:polygon",points:[o,a,l,h],style:{stroke:null,fill:r?el.blue_ribbon:el.whisper,fillOpacity:.1}})}return n}(t);else if("layout:space"===t.type){const e=t.geometry.polygons;e.length>0&&l.push({type:"curve:polygonWithHoles",polygons:e})}else if("geometries"in t&&t.geometries.length){const{shapes:i,maxY:s}=function(t){const e=Ka(t).sort(((t,e)=>t.boundingBox.max[1]<e.boundingBox.max[1]?-1:1));"element:door"!==t.type&&"element:window"!==t.type||e.pop();let i=e.length?e[e.length-1].boundingBox.max[1]:0,s=[];for(let r of e)for(let t=0;t<r.outlines.length;t++)s.push({type:"curve:polygonWithHoles",polygons:[r.outlines[t],...r.holes[t]||[]]});return{shapes:s,maxY:i}}(t);l=i,e.zIndex=e.zIndex+s}let i=Tl(t);l.push(...i),o=new ev;const r=kl({element:t,settings:u,style:s});for(const t of l)Kb({shape:t,settings:u,gfx:o,style:r})}if("getTransform"in t){const i=t.parent&&t.parent.id!==(null==n?void 0:n.name)?t.getWorldTransform():t.getTransform();e.x=i.position[0]*nb,e.y=i.position[2]*nb,e.rotation=-Math.PI/180*i.rotation||0}if(!r&&o){h.gfxNodes[t.id]=e,o.eventMode="static";let i=t.id;"element"in t&&t.element&&(i=t.element.id),o._nodeId=i}o&&e.addChild(o),a&&e.addChild(a)}function n_(t,e,{ctx:i,style:s,container:r,preview:n}){const{view:o,settings:a}=e;if(!(null==t?void 0:t.spaceGraph))return;let l;n||(s?o.styleCache[t.id]=s:!1===s?delete o.styleCache[t.id]:s=o.styleCache[t.id]),r?(l=r,jb(l)):l=new Ty;const h=a.hideElements.includes(t.type)||"spatialGraph:edge"===t.type&&!a.showSpaceDividers||"element:spaceDivider"===t.type||"annotation:floorPlanImage"===t.type&&!a.showFloorPlan||"space"in t||("element:window"===t.type||"element:door"===t.type)&&!t.parent||e.computed.wallContours.length&&["element:wall","element:boundaryWall","element:column","spatialGraph:edge"].includes(t.type),u=Il(t.type);if(l.zIndex=u||0,l.name=t.id,h||r_(t,l,e,s,n,i),t&&"elements"in t){t.elements.length&&(l.sortableChildren=!0);for(const i of t.elements)n_(i,e,{ctx:l,style:s,preview:n})}r||i.addChild(l),o.viewportNeedsUpdate=!0}function o_(t,e){const i=e.getChildByName(t);null==i||i.destroy(!0)}function a_(t,e,i,s){var r;if(o_(t.id,e),s.hideElements.includes("roomStamp"))return;const{text:n,textOutline:o=!0}=(null==(r=s.theme.elements)?void 0:r.roomStamp)||{},a=s.theme.background.color,l="transparent"!==a?a:"#eee",h=n?(u=n.map((t=>t/255)),"#"+((255*u[0]<<16)+(255*u[1]<<8)+(255*u[2]|0)).toString(16).padStart(6,"0")):"#333333";var u;const c=new lv({fontFamily:s.theme.fontFamily||il.theme.fontFamily,fontSize:16,align:"center",fill:h,stroke:l,strokeThickness:o?3:0});let d=t.geometry.polygons;if(0===d.length)return;let p=Ai(d),f=function(t,e){var i,s;let r=t.getArea(),n=t.attributes.usage;if("void"===Al(n))return[];let{roomStampDisplay:o}=(null==(i=e.theme.elements)?void 0:i.roomStamp)||{};const a=e.spaceLabelMapping||{};let l,h;void 0!==a[n]&&(l=a[n]),void 0!==a[t.id]&&(l=a[t.id]),h="area"===e.units.roomDimensions?m(r,e.units.system,e.units.areaDecimals):"";let u="";u||"undefined"===n||(u=(n||"").replace(/([A-Z])/g,(t=>` ${t}`)).replace(/^./,(t=>t.toUpperCase())).trim()),void 0!==l&&("string"!=typeof l?nl.warn("space label mapping has to be a string"):l.length>50?nl.warn("space label mapping has to be less than 50 characters"):u=l),o||(o=[],!1!==(null==(s=e.theme.elements)?void 0:s.roomStamp)&&(t.layout.debugIds?o.push("id"):o.push("usage","area")));const c=[];return o.forEach((e=>{switch(e){case"id":let i=Qa(t.id)?t.id.substring(0,4):t.id;c.push(i);break;case"name":t.name&&c.push(t.name);break;case"customId":t.customId&&c.push(t.customId);break;case"usage":c.push(u);break;case"area":c.push(h);break;default:Array.isArray(e)&&"customAttribute"===e[0]&&t.customAttributes[e[1]]&&c.push(String(t.customAttributes[e[1]]))}})),c}(t,s),g=f.join("\n");const y=new pv(g,c);y.x=p[0]*nb,y.y=p[1]*nb,y.anchor.x=.5,y.anchor.y=.5,l_(y,i,t),y.name=t.id,y.eventMode="none",e.addChild(y)}function l_(t,e,i){let s=Math.min(1/e,2);t.scale.x=s,t.scale.y=s,t.visible=i.getArea()>1.5*s}function h_(t="linear"){return gv[t]}function u_({bb:t,animate:e=!1,view:i}){const s=i._viewport;if(!s)throw new Error("no viewport");return i.viewportPaused&&i.startAnimationLoop(),new Promise((r=>{var n;Number.isFinite(null==(n=t.min)?void 0:n[0])||r(!1);const{min:o,max:a}=t;let l=o[0],h=o[1];let u=a[0]-l,c=a[1]-h;l*=nb,h*=nb,u*=nb,c*=nb;let d=0;"number"==typeof e&&Number.isFinite(e)?d=e:!0===e&&(d=500);let p={x:l+u/2,y:h+c/2,width:u,height:c};if(d){let t={x:s.center.x,y:s.center.y,width:s.worldScreenWidth,height:s.worldScreenHeight},e={x:t.x-p.x,y:t.y-p.y,width:t.width-p.width,height:t.height-p.height};i._zoomTarget={delta:e,start:t,target:p,time:0,duration:d,destroy:()=>{i.ticker.remove("animateView"),delete i._zoomTarget,r(!0)},ease:h_("easeInOutQuad"),updateViewport:d_.bind(i)},i.ticker.add("animateView",c_,i)}else s.fit(!1,p.width,p.height).moveCenter(p.x,p.y),d_.bind(i)({type:"animation"}),i.viewportNeedsUpdate=!0,r(!0)}))}function c_(t){let e=this._zoomTarget,i=!1;e.time+=t;let s=e.ease(e.time,0,1,e.duration),r={x:e.start.x-e.delta.x*s,y:e.start.y-e.delta.y*s,width:e.start.width-e.delta.width*s,height:e.start.height-e.delta.height*s};e.time>e.duration&&(r=e.target,i=!0),this._viewport.fit(!1,r.width,r.height).moveCenter(r.x,r.y),this.viewportNeedsUpdate=!0,e.updateViewport({type:"animation"});const n=0!==this._viewport.input.count();(i||n)&&e.destroy()}function d_(t){this.viewportNeedsUpdate=!0,this.viewportPaused&&this.startAnimationLoop();const e=this._viewport;"animation"!==t.type&&this._zoomTarget&&this._zoomTarget.destroy();const i=nb,s=e.scale._x,r=e.left,n=e.top,o=e.worldScreenWidth,a=e.worldScreenHeight;this.viewbox={min:[r/i,n/i],max:[(r+o)/i,(n+a)/i]},this.client=[e.screenWidth,e.screenHeight];const l=this.zoom!==s;this.zoom=s;const h={sourceEvent:{type:t.type},viewbox:this.viewbox,zoom:this.zoom};l?this.emit("zoom",h):this.emit("pan",h),this.emit("viewbox",h)}function p_({position:t,nodeId:e}){f_(this.interaction,{cursor:t,cursorTarget:e&&this.layout&&(this.layout.elementsById[e]||this.layout.spacesById[e])})}function f_(t,e){for(const i in e)t[i]=e[i],"cursorAction"===i&&m_(e[i])}function m_(t){let e="";switch(t){case"split-wall":e="var(--fpe-split-cursor) 16 16, pointer";break;case"duplicate":e="var(--fpe-duplicate-cursor) 16 16, pointer";break;case"move":e="move";break;default:e="default"}document.body.style.cursor=e}function g_(t){var e,i,s,r;if(2===(null==(i=null==(e=null==t?void 0:t.data)?void 0:e.originalEvent)?void 0:i.button))return;if(!this||!this.view)throw new Error("Viewport context is missing");let n=this.interaction._dragStart||{x:0,y:0},o=t.data.global||{x:0,y:0},a=Math.abs(o.x-n.x),l=Math.abs(o.y-n.y);if(!(a<5&&l<5))return;let h,u=(new Date).getTime();if(this.interaction.lastClick){let t=u-this.interaction.lastClick.time,e=this.interaction.lastClick.position&&Math.max(Math.abs(o.x-this.interaction.lastClick.position.x),Math.abs(o.y-this.interaction.lastClick.position.y));h=t<400&&e<10}this.interaction.lastClick={time:u,position:{...o}};const c=h?"dblclick":"click",d=null==(s=t.target)?void 0:s._nodeId,{x:p,y:f}=(null==(r=t.data)?void 0:r.global)||{},m=this.getPlanPosition([p,f]);f_(this.interaction,{cursor:[m[0],m[1]]});let g={sourceEvent:t,nodeId:d,position:m,isDoubleClick:!!h};this.emit(c,g)}function y_(t){var e;const{x:i,y:s}=t.data.global;this.view.windowPos=[i,s];const r=this.getPlanPosition(this.view.windowPos);this.interaction.lastSceneClick=r;const n=null==(e=t.target)?void 0:e._nodeId;this.emit("context-menu",{sourceEvent:t,nodeId:n,position:r})}function v_(t){t.drag().pinch({percent:4}).wheel()}function x_(t){const{settings:e,view:i}=t;e.panZoom&&v_(i._viewport),i._viewport.on("pointerdown",b_,t).on("pointerup",__,t).on("pointerup",g_,t).on("rightup",y_,t).on("pointerupoutside",__,t).on("pointermove",w_,t).on("moved",d_,i).on("zoomed",d_,i),P_(t),(t=>{const{view:e,interaction:i}=t,s=(s,r)=>{e.viewportInFocus&&("Alt"===s.key&&"keyup"===r&&i.preventFocusoutOnAltKeyup&&s.preventDefault(),i.shiftKey=s.shiftKey,i.ctrlKey=s.ctrlKey,i.altKey=s.altKey,i.metaKey=s.metaKey,t.emit(r,{key:s.key,lowerCaseKey:s.key&&s.key.toLowerCase(),sourceEvent:s}))};document.addEventListener("keydown",(t=>s(t,"key"))),document.addEventListener("keyup",(t=>s(t,"keyup")))})(t),t.on("mousemove",p_,t)}function b_(t){this.interaction._dragStart={x:t.data.global.x,y:t.data.global.y};const e=t.data.getLocalPosition(this.view._viewport);this.emit("drag-start",{position:this.interaction.cursor,sourceEvent:t,screenPos:[e.x,e.y]})}function __(t){this.view.resume("drag");const e=t.data.getLocalPosition(this.view._viewport);this.emit("drag-end",{position:this.interaction.cursor,sourceEvent:t,screenPos:[e.x,e.y]}),this.interaction.isDragging=!1,this.interaction.dragOffset=null}function w_(t){var e;const{srcElement:i}=(null==(e=null==t?void 0:t.data)?void 0:e.originalEvent)||{};if(!i)return;if(!(i===this.view._renderer.view))return;const s=t.data.getLocalPosition(this.view._viewport);let r=[s.x/nb,s.y/nb];const n=t.target&&t.target._nodeId;if(this.interaction.cursor=r,this.interaction.isDragging){const e=[s.x,s.y];this.emit("drag-move",{position:this.interaction.cursor,screenPos:e,sourceEvent:t})}this.emit("mousemove",{sourceEvent:t,nodeId:n,position:r})}const P_=t=>{const e=document.querySelector(`#${t.fpeId} .fpe__plan`);e&&(e.addEventListener("mouseleave",(()=>t.view.emit("focus",!1,t.view))),e.addEventListener("mouseenter",(()=>t.view.emit("focus",!0,t.view))),document.addEventListener("visibilitychange",(()=>t.view.emit("focus","visible"===document.visibilityState,t.view))),e.addEventListener("contextmenu",(function(t){return t.preventDefault(),!1}),!1))};function E_({floorPlan:t,update:e=!1}){const{layout:i,view:s,settings:r}=t,{_renderer:n,_viewport:o}=s;let a=r.theme.background.color;4===a.length&&(a=a[0]+a[1]+a[1]+a[2]+a[2]+a[3]+a[3]),n.background.color=new Yb(a).toNumber();const l=s.gfxLayers.scene;jb(l);let h={ctx:l};e||(s.styleCache={});for(let u of i.spaces)n_(u,t,h);for(let u of i.elements)n_(u,t,h);for(let u of i.annotations)n_(u,t,h);for(let u of i.spatialGraph.edges)n_(u,t,h);t.computed.wallContours.length&&function(t,e){const{ctx:i,style:s}=e,{wallContours:r}=t.computed,n="wallContours",o=r.map((t=>({type:"curve:polygonWithHoles",polygons:t})));let a=i.getChildByName(n);a?jb(a):(a=new Ty,a.name=n);const l=Il("element:wall");a.zIndex=l||0;const h=kl({style:s,settings:t.settings,elementType:"element:wall"}),u=new ev;for(const c of o)Kb({shape:c,gfx:u,style:h});a.addChild(u),i.addChild(a)}(t,h),T_(t,!0),s.emit("scene-rendered",{update:e}),s.viewportNeedsUpdate=!0,e&&(r.panZoom?v_(o):function(t){t.plugins.remove("wheel"),t.plugins.remove("pinch"),t.plugins.remove("drag")}(o)),s.viewportPaused&&s.startAnimationLoop()}function T_(t,e=!1){const{view:i,layout:s,settings:r}=t,n=t.addLayer({id:"fpe-room-stamp",baseLayer:"annotation"});e?(jb(n.container),s.spaces.forEach((t=>a_(t,n.container,i.zoom,r)))):n.container.children.forEach((t=>{let e=s.spaces.find((e=>e.id===t.name));l_(t,i.zoom,e)}))}function A_(t){const{shapeLayers:e}=t.settings;for(const i in e){const s=e[i];t.addLayer({id:i}).addGraphic({shapes:s})}}xf.add(Gm),xf.add(Lv),xf.add(Vv),xf.add(ux),xf.add(dx);class I_ extends Jx{}const S_=(t,e,i)=>{const s=t.getChildByName(e);if(s)return jb(s),s;{const s=new Ty;return s.sortableChildren=!0,s.zIndex=i,s.name=e,t.addChild(s),s}},C_={top:0,left:0,center:.5,right:1,bottom:1};class M_{constructor(){this.methods={},this.add=(t,e,i)=>{this.methods[t]={fn:e,ctx:i}},this.remove=t=>{delete this.methods[t]}}}class O_ extends lb{constructor(t,e,i){var s;super(),this.windowPos=[0,0],this.zoom=1,this.client=[0,0],this.layers=new Map,this.viewbox={min:[0,0],max:[0,0]},this.styleCache={},this.viewportNeedsUpdate=!1,this.viewportPaused=!1,this.viewportInFocus=!1,this.wallNodesToUpdate=[],this.wallNodeUpdateInProgress=!1,this.gfxNodes={},this._canvasMargin={x:0,y:0},this.ticker=new M_,this._oldTime=Date.now(),this.parentEl=i;const r=this.parentEl.querySelector(".fpe__canvas");let n=this.parentEl.clientWidth,o=this.parentEl.clientHeight;this._settings=e;const a=window.devicePixelRatio||1;let l=e.theme.background.color;const h="transparent"===l;4===l.length&&(l=l[0]+l[1]+l[1]+l[2]+l[2]+l[3]+l[3]),this._renderer=function(t){for(const e of sy)if(e.test(t))return new e(t);throw new Error("Unable to auto-detect a suitable renderer.")}({width:n,height:o,view:r,antialias:!0,hello:!1,backgroundAlpha:h?0:1,autoDensity:!0,resolution:a,powerPreference:"high-performance",preserveDrawingBuffer:!0,backgroundColor:h?new Yb(l).toNumber():void 0}),this.parentEl.appendChild(this._renderer.view),4===l.length&&(l=l[0]+l[1]+l[1]+l[2]+l[2]+l[3]+l[3]),h||(this._renderer.background.color=new Yb(l).toNumber()),this._stage=new Ty,this._stage.sortableChildren=!0,this._viewport=new I_({screenWidth:n,screenHeight:o,worldWidth:n,worldHeight:o,events:this._renderer.events,noTicker:!0,passiveWheel:!1}),(null==(s=ey)?void 0:s.system)&&ey.system.stop(),this.startAnimationLoop(),this.watchResize(),this._stage.addChild(this._viewport),this.on("focus",(t=>{t&&this.viewportPaused?this.startAnimationLoop():t||this.stopAnimationLoop(),this.viewportInFocus=t})),this.gfxLayers=N_(this._viewport),Qb(this,t)}draw(){var t;const e=Date.now();let i=e-this._oldTime;this._oldTime=e,i<0&&(i=0),i>1e3&&(i=1e3);let s=Object.keys(this.ticker.methods).length;(this.viewportNeedsUpdate||s)&&((null==(t=this.ticker)?void 0:t.methods)&&Object.values(this.ticker.methods).forEach((({fn:t,ctx:e})=>{"function"==typeof t&&(e?t.call(e,i):t(i))})),this._viewport.update(i),this._renderer.render(this._stage)),this.viewportPaused||requestAnimationFrame((()=>this.draw())),this.viewportNeedsUpdate=!1}startAnimationLoop(){this._oldTime=Date.now(),this.viewportNeedsUpdate=!0,this.viewportPaused=!1,requestAnimationFrame((()=>this.draw()))}stopAnimationLoop(){this.viewportPaused=!0}updateView(){if(!this.parentEl.clientWidth||!this.parentEl.clientHeight)return;const t=this._viewport,e=this._renderer,i=nb,s=t.screenWidth,r=t.screenHeight,n=this.parentEl.clientWidth-this._canvasMargin.x,o=this.parentEl.clientHeight-this._canvasMargin.y;e.resize(n,o),t.resize(n,o);const a=s-n,l=r-o,h=this._settings.preserveViewbox,[u=.5,c=.5]=h.split("-").map((t=>C_[t])),d=u*a,p=c*l;t.position.set(t.x-d,t.y-p),t.plugins.get("clamp-zoom")||t.clampZoom({minHeight:this._settings.zoomRange[0]*i,maxHeight:this._settings.zoomRange[1]*i}),e.render(this._stage);let f=t.left,m=t.top,g=t.worldScreenWidth,y=t.worldScreenHeight;this.viewbox={min:[f/i,m/i],max:[(f+g)/i,(m+y)/i]},this.client=[t.screenWidth,t.screenHeight]}async watchResize(){this._canvasMargin.x=this.parentEl.clientWidth-this._viewport.screenWidth,this._canvasMargin.y=this.parentEl.clientHeight-this._viewport.screenHeight;new ResizeObserver((()=>{this.updateView(),this.emit("resize-canvas",this.viewbox)})).observe(this.parentEl)}get gfxNodeCount(){return Object.keys(this.gfxNodes).length}reset(){this.styleCache={},this.gfxNodes={},this.gfxLayers=N_(this._viewport)}pause(t="drag"){this._viewport.plugins.pause(t)}resume(t="drag"){this._viewport.plugins.resume(t)}}const N_=t=>{t.sortableChildren=!0;return{base:S_(t,"base",0),scene:S_(t,"scene",1),preview:S_(t,"preview",2),annotation:S_(t,"annotation",3),helper:S_(t,"helper",4)}};function L_(t,e,i){e=e||this;const{view:s,settings:r}=e,n=s.gfxNodes[t.id];if(n){if("layout:space"===t.type){const e=s.layers.get("fpe-room-stamp");e&&a_(t,e.container,s.zoom,r)}n_(t,e,{ctx:n.parent,container:n,...i}),s.viewportNeedsUpdate=!0,s.viewportPaused&&s.startAnimationLoop()}}class R_{constructor({shapes:t=[],position:e=[0,0],alpha:i=1,scale:s=1,clearLayer:r=!1,interactive:n=!1,id:o,isHandler:a=!1,scaleOnZoom:l=!1,updatePositionOnDrag:h=!1,baseLayer:u,container:c,floorPlan:d}){if(this.shapes=t,this.gfxScale=s,this.scaleOnZoom=l,this.container=c,this.floorPlan=d,!this.container)return;r&&jb(this.container);let p=new ev;this.gfx=p,p.alpha=i;const f=Math.min(1/this.floorPlan.view.zoom)*this.gfxScale;e&&(p.x=e[0]*nb,p.y=e[1]*nb),p.eventMode=n?"static":"none",p._nodeId=o,a&&(p._isHandler=!0),h&&this.on("drag",this.doUpdatePositionOnDrag,this),f&&l&&(p.scale.x=p.scale.y=f),u.addChild(this.container),this.container.addChild(p),t.forEach((t=>Kb({shape:t,settings:this.floorPlan.settings,gfx:p}))),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}set({position:t,rotation:e,style:i,shapes:s}={}){const r=Math.min(1/this.floorPlan.view.zoom)*this.gfxScale,n=this.gfx;if(function(t,{position:e,rotation:i}){e&&(t.x=e[0]*nb,t.y=e[1]*nb),i&&(t.rotation=-Math.PI/180*i)}(n,{position:t,rotation:e}),s&&(this.shapes=s,n.clear(),jb(n),s.forEach((t=>Kb({shape:t,settings:this.floorPlan.settings,gfx:n})))),r&&this.scaleOnZoom&&(n.scale.x=n.scale.y=r),i){const t=Jb(i);i.fill&&(n.geometry.graphicsData[0].fillStyle.color=Nl(i.fill)),n.geometry.graphicsData[0].lineStyle.color=Number(t.color),n.geometry.graphicsData[0].lineStyle.width=t.width,n.geometry.graphicsData[0].lineStyle.native=t.native,n.geometry.invalidate()}this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}doUpdatePositionOnDrag({position:t}){this.set({position:t})}on(t,e,i){return this.gfx.eventMode="static","drag"===t?this.addDragEvent(e,i):this.gfx.on(t,e,i),this}off(t,e){return"drag"===t?this.removeDragEvent():this.gfx.off(t,e),this}destroy(){this.off("drag"),this.gfx.destroy(),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}addDragEvent(t,e){function i(){this.floorPlan.interaction.isDragging=!1,this.floorPlan.view.resume("drag"),this.floorPlan.off("mousemove",t)}this.on("pointerdown",(function(){this.floorPlan.interaction.isDragging=!0,this.floorPlan.view.pause("drag"),this.floorPlan.on("mousemove",t,e)}),this),this.on("pointerup",i,this),this.on("pointerupoutside",i,this),this.on("pointercancel",i,this)}removeDragEvent(){this.off("pointerdown"),this.off("pointerup"),this.off("pointerupoutside"),this.off("pointercancel")}}class k_{constructor(t,e,i){this.graphics=new Set,this.container=new Ty,this.id=i,this.baseLayer=t.view.gfxLayers[e]||t.view.gfxLayers.helper,this.floorPlan=t,this.baseLayer.addChild(this.container)}addGraphic(t){const e=new R_({...t,floorPlan:this.floorPlan,baseLayer:this.baseLayer,container:this.container});return this.graphics.add(e),e}findGraphic(t){return this.container.getChildByName(t)}deleteGraphic(t){this.graphics.delete(t),t.destroy()}clear(){jb(this.container),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}destroy(){this.container&&(this.floorPlan.view.layers.delete(this.id),this.container.destroy({children:!0,texture:!0,baseTexture:!0}),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop(),delete this.container,delete this.floorPlan)}}function B_(t,{format:e,fileName:i,quality:s}={}){if("svg"===e)return;const r=new Image;r.src=t,r.onload=function(){const t=document.createElement("canvas");t.width=r.naturalWidth,t.height=r.naturalHeight;const n=t.getContext("2d");n.imageSmoothingEnabled=!1,n.drawImage(r,0,0),function(t,{format:e="png",fileName:i="floorplan",quality:s=.95}){let r="png"===e?"image/png":"image/jpeg";t.toBlob((function(t){!function({fileName:t,href:e,ext:i}){const s=document.createElement("a");Object.assign(s,{href:e,download:g(t,i),target:"_blank",rel:"noopener",style:"display:none;"}),document.body.appendChild(s),s.click(),document.body.removeChild(s)}({fileName:i,href:URL.createObjectURL(t),ext:e})}),r,s)}(t,{format:e,fileName:i,quality:s})}}const F_=el.blue_ribbon,D_=el.zurich,U_=el.white,G_=F_,X_=F_,W_=D_,H_=F_,Y_=F_,$_=U_;class j_ extends hb{constructor({floorPlan:t,helperId:e,mode:i="distance"}){super({floorPlan:t,helperId:e}),this.drawing=!1,this.polygonsOrPolylines=[],this.floorPlan=t,this.mode=i,this.floorPlan.on("mousemove",this.handlePointerMove,this),this.floorPlan.on("click",this.handlePointerDown,this),this.floorPlan.on("dblclick",this.handlePointerDown,this),this.floorPlan.on("update-settings",this.draw,this),this.startDrawing()}get isInAreaMode(){return"area"===this.mode}get isDrawing(){return this.drawing}set({mode:t}){this.mode=t,this.draw()}handlePointerMove(t){this.setSnapCursor(t)}handlePointerDown(t){this.setSnapCursor(t),this.drawPoint(t)}setSnapCursor({position:t}){this._snapCursor??(this._snapCursor=this.floorPlan.addHelper("snapCursor",{position:t}));const{snapPoints:e,snapMargin:i}=this.floorPlan.computed;if(!e.length)return this._snapCursor.set({position:t}),void this.draw();const s=Xl(t,e,i);this._snapCursor.isSnapping=!!s,this._snapCursor.set({position:s||t}),this.draw()}stopDrawing(){this.polygonsOrPolylines[this.polygonsOrPolylines.length-1].points.length>1&&this.drawing&&this.polygonDone()}cancelDrawing(){this.destroy()}startDrawing(){this.drawing=!0,this.polygonsOrPolylines.push({points:[],isClosed:!1,length:0,area:0,areaDisplay:"",lengthDisplay:"",contour:null,label:null,pointGraphics:[]})}removeLastPoint(){var t,e;const i=this.polygonsOrPolylines[this.polygonsOrPolylines.length-1];if((null==i?void 0:i.points.length)>0){i.points.pop();const s=i.pointGraphics.pop();s&&this.layer.deleteGraphic(s),i.points.length<=1&&(i.contour&&(null==(t=this.layer)||t.deleteGraphic(i.contour),i.contour=null),i.label&&(null==(e=this.layer)||e.deleteGraphic(i.label),i.label=null)),0===i.points.length?(this.polygonsOrPolylines.pop(),this.drawing=!1):this.draw()}}polygonDone(){this.drawing=!1,this.emit("polygon-done",{}),this.draw()}drawPoint(t){var e;this.drawing||this.startDrawing();const i=this.polygonsOrPolylines.length-1,s=this.polygonsOrPolylines[i];if((null==(e=t.nodeId)?void 0:e.startsWith(`point/${i}/`))||t.isDoubleClick){const e=t.nodeId===`point/${i}/0`;return"distance"===this.mode&&e&&(s.isClosed=!0),void this.polygonDone()}const{position:r}=this._snapCursor;s.points.push([...r]);const n=s.points.length-1,o=`point/${i}/${n}`;this.layer||(this.layer=this.floorPlan.addLayer());const a=this.layer.addGraphic({shapes:[{type:"curve:circle",position:[0,0],radius:.15,style:{fill:H_,fillOpacity:.1}},{type:"curve:circle",position:[0,0],radius:.05,style:{stroke:Y_,fill:$_,strokeWidth:1.5}}],position:r,scaleOnZoom:!0,id:o,isHandler:!0});s.pointGraphics[n]=a,a.on("drag",(function(){this.updatePolygon(i,n,this.floorPlan.interaction.cursor),a.set({position:s.points[n]})}),this)}updatePolygon(t,e,i){const s=i,{snapPoints:r,snapMargin:n}=this.floorPlan.computed,o=r.length&&Xl(s,r,n);this.polygonsOrPolylines[t].points[e]=o||s,this.draw()}getLengthText(t){const{units:e}=this.floorPlan.settings;return f(t,e.system,e.lengthDecimals)}getAreaText(t){const{units:e}=this.floorPlan.settings;return m(t,e.system,e.areaDecimals)}reset(){this.drawing=!1,this.polygonsOrPolylines=[],this.floorPlan.removeHelper("snapCursor"),this._snapCursor=null,this.layer&&(this.layer.destroy(),this.layer=null)}draw(){this.polygonsOrPolylines.length&&(this.layer||(this.layer=this.floorPlan.addLayer()),this.polygonsOrPolylines.forEach(((t,e)=>{if(!t.points.length)return;const i=this.drawing&&this._snapCursor&&e===this.polygonsOrPolylines.length-1?[...t.points,this._snapCursor.position]:t.points;if(i.length<2)return;t.length=function(t,e=!0){let i=0,s=e?t.length:t.length-1;for(var r=0;r<s;r++){let e=r,s=r<t.length-1?r+1:0;i+=hi(t[e],t[s])}return i}(i,t.isClosed),t.lengthDisplay=this.getLengthText(t.length);const s=i.length<2?0:180*xi(i[0],i[1])/Math.PI,r=i.map((t=>t.map((t=>Number(t.toFixed(10)))))).slice(0,this.isInAreaMode?void 0:2),n=this.isInAreaMode?Ai([r]):[r[0][0]+(r[1][0]-r[0][0])/2,r[0][1]+(r[1][1]-r[0][1])/2];t.area=Math.abs(Z(i)),t.areaDisplay=this.getAreaText(t.area);const o=this.isInAreaMode||t.isClosed?"curve:polygon":"curve:polyline",a={stroke:W_,dash:!0,strokeWidth:"native"};let l=t.lengthDisplay,h=s;this.isInAreaMode&&(a.fill=X_,a.fillOpacity=.04,l=t.areaDisplay,h=0);const u=[{type:o,points:i,style:a}],c={shapes:[{type:"text",text:l,position:[0,0],rotation:h,alignV:"bottom",fontSize:15,style:{fill:G_}}],id:"text",position:n,scaleOnZoom:!0};t.contour?t.contour.set({shapes:u}):t.contour=this.layer.addGraphic({shapes:u}),t.label?t.label.set(c):t.label=this.layer.addGraphic(c);const d=this.isInAreaMode?{area:t.area}:{distance:t.length};this.emit("polygon-draw",d)})))}destroy(){this.reset(),this.floorPlan.off("mousemove",this.handlePointerMove),this.floorPlan.off("click",this.handlePointerDown),this.floorPlan.off("dblclick",this.handlePointerDown),this.floorPlan.off("update-settings",this.draw),super.destroy()}}class z_ extends hb{constructor({floorPlan:t,helperId:e,position:i}){super({floorPlan:t,helperId:e}),this.position=[0,0],this.floorPlan.on("mousemove",this.draw,this),this.isSnapping=!1,this.isEdge=!1,this.isError=!1,i&&(this.position=i)}draw(){if(this.floorPlan)if(this.layer||(this.layer=this.floorPlan.addLayer({id:"fpe-snap-cursor"})),this.cursor){let t=el.stone;this.isError?t=el.error:this.isSnapping&&(t=el.blue_ribbon);const e=this.isSnapping?2:1.5;this.cursor.set({position:this.position,style:{stroke:t,strokeWidth:e}})}else this.cursor=this.layer.addGraphic({shapes:[{type:"curve:circle",position:[0,0],radius:.06,style:{stroke:el.blue_ribbon,strokeWidth:1.5}}],position:this.position,scaleOnZoom:!0})}set({position:t,isSnapping:e,isEdge:i,isError:s}){this.position=t,this.isSnapping=e,this.isEdge=i,this.isError=s,this.draw()}snapState(){return this.isSnapping?this.isEdge?"edge":"point":""}destroy(){var t;null==(t=this.floorPlan)||t.off("mousemove",this.draw),this.layer&&this.layer.destroy(),this.layer=void 0,this.cursor=null,super.destroy()}}function V_(t,e){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: node ID change, type ${t.type}, previous ID ${e}`),this.drawNodeUpdate(t.id))}function q_(t,e){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: node property change, type ${t.type}, property name ${e}`),this.drawNodeUpdate(t.id))}function J_(t){this.preventUpdateOnSpaceGraphEvent||nl.debug(`${t.id}: vertex create`)}function K_(t){this.preventUpdateOnSpaceGraphEvent||nl.debug(`${t.id}: vertex delete`)}function Z_(t){if(!this.preventUpdateOnSpaceGraphEvent){nl.debug(`${t.id}: vertex set position`);for(let e of t.edges)this.drawNodeUpdate(e.id)}}function Q_(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: edge create`),this.drawNodeUpdate(t.id))}function tw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: edge delete`),this.drawNodeUpdate(t.id))}function ew(t,e){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: edge set vertices`),this.drawNodeUpdate(t.id))}function iw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: space create`),this.drawNodeUpdate(t.id))}function sw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: space delete`),this.drawNodeUpdate(t.id))}function rw(t,e){this.preventUpdateOnSpaceGraphEvent||nl.debug(`${t.id}: space split into ${e[0].id} and ${e[1].id}`)}function nw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: space attributes change`),this.drawNodeUpdate(t.id))}function ow(t){this.preventUpdateOnSpaceGraphEvent||"layout:space"!==t.type||(nl.debug(`${t.id}: custom attributes change`),this.drawNodeUpdate(t.id))}function aw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: element create, type ${t.type}`),this.drawNodeUpdate(t.id))}function lw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: element delete, type ${t.type}`),this.drawNodeUpdate(t.id))}function hw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: element transform change, type ${t.type}`),this.drawNodeUpdate(t.id))}function uw(t){if(!this.preventUpdateOnSpaceGraphEvent)if(nl.debug(`${t.id}: element parameters change, type ${t.type}`),"element:wall"===t.type){let e=t.getAdjacentElementsByVertex().flat();if(this.view.wallNodesToUpdate.push(t.id,...e.map((t=>t.id))),this.view.wallNodeUpdateInProgress)return;this.view.wallNodeUpdateInProgress=!0,setTimeout((()=>{const t=new Set(this.view.wallNodesToUpdate);Sa(this.layout);for(const e of t)this.drawNodeUpdate(e);this.view.wallNodeUpdateInProgress=!1,this.view.wallNodesToUpdate=[]}))}else Dr(t),this.drawNodeUpdate(t.id)}function cw(t){this.preventUpdateOnSpaceGraphEvent||queueMicrotask((()=>this.drawNodeUpdate(t.id)))}function dw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: annotation change, type ${t.type}`),this.drawNodeUpdate(t.id))}function pw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: geometry profile update`),this.drawNodeUpdate(t.id))}function fw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: geometry update`),["element:boundaryWall","element:generic"].includes(t.type)&&this.drawNodeUpdate(t.id))}function mw(t){const e=t.addLayer({id:"fpe-grid-lines",baseLayer:"base"});let i;function s(t,e,s=!1){const r=nb;if(!t)return;let n;if(n=e.view.zoom>2?.1:e.view.zoom>.25?1:(e.view.zoom,10),!s&&n===i)return;if(jb(t),!e.settings.theme.background.showGrid)return;const o=new ev;let a=Nl(el.athens);o.lineStyle({width:1,color:a,native:!0});for(let i=-100;i<100;i+=n)Math.round(100*i)/100==0?o.lineStyle({width:2,color:a,native:!0}):(Math.round(100*i)/100%10==0||Math.round(100*i),o.lineStyle({width:1,color:a,native:!0})),o.moveTo(-100*r,i*r),o.lineTo(100*r,i*r),o.moveTo(i*r,-100*r),o.lineTo(i*r,100*r);t.addChild(o),i=n}return s(null==e?void 0:e.container,t),{update:i=>s(e.container,t,i)}}function gw(t,e="Floor plan engine couldn't load properly on this page. For technical details check the browser console."){const i=t.querySelector(".fpe-err")??function(t){const e=document.createElement("div"),i=document.createElement("div"),s=document.createElement("div"),r=document.createElement("div");return e.classList.add("fpe-err"),i.classList.add("fpe-err__box"),s.classList.add("fpe-err__title"),r.classList.add("fpe-err__msg"),t.append(e),e.append(i),i.append(s),i.append(r),s.textContent="Something went wrong",t.append(e),t}(t);i.querySelector(".fpe-err__msg").textContent=e}const yw={lastSceneClick:[0,0],cursor:[0,0],cursorTarget:null,isDragging:!1,altKey:!1,shiftKey:!1,metaKey:!1,ctrlKey:!1,dragOffset:null,cursorAction:"none",isPanning:!1,lastClick:{time:null,position:{x:0,y:0}},_dragStart:{x:0,y:0},preventFocusoutOnAltKeyup:!1};Kx=new WeakMap,Zx=new WeakSet,Qx=function(t){if(t!==(eb(e=this,i=Kx,"read from private field"),s?s.call(e):i.get(e))){var e,i,s;sb(this,Kx,t);try{this.fpeNode.style.setProperty("--fpe-font-family",t)}catch(xw){console.warn("Failed to set font-family",xw)}}},t.FloorPlanEngine=class extends Pl{constructor({container:t,options:e={}}={}){let i;super({options:e}),ib(this,Zx),ib(this,Kx),this.interaction=yw,this.availableHelpers={cursorCoordinates:ub,scaleBar:cb},this.helper={},this.preventUpdateOnSpaceGraphEvent=!1,sb(this,Kx,il.theme.fontFamily),i=t instanceof Element?t:document.body,this.mountFloorPlan(i),this.availableHelpers.polygonHelper=j_,this.availableHelpers.snapCursor=z_,this.on("space-api-floor-error",((t,e)=>{gw(this.fpeNode,e)})),this.on("space-api-floor-loaded",(()=>{!function(t){var e;null==(e=t.querySelector(".fpe-err"))||e.remove()}(this.fpeNode)}))}prevent(t){t.preventDefault()}on(t,e,i){return this._emitter.on(t,e,i),this}once(t,e,i){return this._emitter.once(t,e,i),this}off(t,e,i){return this._emitter.off(t,e),this}emit(t,...e){return this._emitter.emit(t,...e),this}handleDrop(t){var e;t.preventDefault(),t.stopPropagation();const i=[t.offsetX,t.offsetY],s=this.getPlanPosition(i);this.interaction.cursor=[...s];const{spaces:r}=this.getResourcesFromPosition(s),n=null==(e=r[0])?void 0:e.slabs.find((t=>"element:floor"===t.type)),o=(null==n?void 0:n.parameters.elevation)||0;this.emit("drop",{position:s,sourceEvent:t,verticalPos:o,screenPos:i})}set(t){super.set(t),this.view&&(E_({floorPlan:this,update:!0}),A_(this),mw(this))}drawNodePreview(t,e,i,s){n_((null==e?void 0:e.elementsById[t])||(null==e?void 0:e.spacesById[t])||(null==e?void 0:e.spatialGraph.edgesById[t]),this,{preview:!0,style:s,ctx:i.container})}drawNodeUpdate(t,e){var i,s,r,n,o;if(!this.layout)return;let a=(null==(i=this.layout)?void 0:i.elementsById[t])||(null==(s=this.layout)?void 0:s.spacesById[t])||(null==(r=this.layout)?void 0:r.annotationsById[t])||(null==(n=this.layout)?void 0:n.spatialGraph.edgesById[t]);if(a)if(this.view.gfxNodes[t])L_(a,this,{style:e});else{let t=this.view.gfxLayers.scene;"parent"in a&&this.view.gfxNodes[null==(o=a.parent)?void 0:o.id]&&(t=this.view.gfxNodes[a.parent.id]),n_(a,this,{ctx:t,style:e})}else!function(t,e){const i=e.view.gfxNodes[t];i&&(i.parent.removeChild(i),i.destroy({children:!0})),delete e.view.gfxNodes[t],delete e.view.styleCache[t],o_(t,e.getLayer("fpe-room-stamp").container),e.view.viewportNeedsUpdate=!0,e.view.viewportPaused&&e.view.startAnimationLoop()}(t,this);if(a&&"getEdges"in a)for(const l of a.getEdges())this.drawNodeUpdate(l.id,e)}drawResourceUpdate({resourceId:t}){let e=this.loader.resources.nodes.get(t);for(let i of e)L_(i,this,{})}mountFloorPlan(t){const e=t.querySelector(".fpe");e&&e.remove();const i=document.createElement("div");i.id=this.fpeId,i.classList.add("fpe"),t.appendChild(i);const s=document.createElement("div");s.classList.add("fpe__plan");const r=document.createElement("canvas");r.title="fpe-canvas",r.classList.add("fpe__canvas"),i.appendChild(s),s.appendChild(r),this.fpeNode=i;try{i.style.setProperty("--fpe-font-family",this.settings.theme.fontFamily)}catch(xw){console.warn("Failed to set font-family",xw)}this.view=new O_(this.loader,this.settings,s),this.loader.on("resource-loaded",this.drawResourceUpdate,this),this.loader.on("spaces-loaded",this.initDrawing,this),r.addEventListener("drop",this.handleDrop.bind(this)),r.addEventListener("gesturestart",this.prevent),r.addEventListener("gesturechange",this.prevent),r.addEventListener("gestureend",this.prevent),r.addEventListener("dragover",this.prevent),this.settings.destroyOnDomRemove&&function(t,e,i){const s=new MutationObserver((()=>{(function t(i){return i.parentNode!==e&&(null===i.parentNode||t(i.parentNode))})(t)&&(s.disconnect(),i())}));s.observe(e,{childList:!0,subtree:!0})}(i,t,(()=>this.destroy())),x_(this),this.view.on("scene-rendered",(({update:t})=>{t||this.zoomExtents(1,0)})),this.view.on("zoom",(()=>{this.view.layers.forEach((t=>{t.graphics.forEach((t=>{t.scaleOnZoom&&!t.gfx.destroyed&&t.set()}))})),T_(this),mw(this)})),this.view&&mw(this),rb(this,Zx,Qx).call(this,this.settings.theme.fontFamily),this.on("update-settings",(t=>{rb(this,Zx,Qx).call(this,t.theme.fontFamily)})),this.generateUi()}initDrawing(){var t;!this.loader.initialLoading&&(null==(t=this.view.gfxLayers)?void 0:t.scene)&&jb(this.view.gfxLayers.scene),E_({floorPlan:this}),A_(this),this.initDrawingEvents()}initDrawingEvents(){this.spaceGraph.on("node-id-change",V_,this),this.spaceGraph.on("node-property-change",q_,this),this.spaceGraph.on("node-custom-attributes-change",ow,this),this.spaceGraph.on("vertex-create",J_,this),this.spaceGraph.on("vertex-delete",K_,this),this.spaceGraph.on("vertex-set-position",Z_,this),this.spaceGraph.on("edge-create",Q_,this),this.spaceGraph.on("edge-delete",tw,this),this.spaceGraph.on("edge-set-vertices",ew,this),this.spaceGraph.on("space-create",iw,this),this.spaceGraph.on("space-delete",sw,this),this.spaceGraph.on("space-split",rw,this),this.spaceGraph.on("space-attributes-change",nw,this),this.spaceGraph.on("element-create",aw,this),this.spaceGraph.on("element-delete",lw,this),this.spaceGraph.on("element-transform-change",hw,this),this.spaceGraph.on("element-parameters-change",uw,this),this.spaceGraph.on("element-edges-change",cw,this),this.spaceGraph.on("geometry-profile-update",pw,this),this.spaceGraph.on("geometry-update",fw,this),this.spaceGraph.on("annotation-transform-change",dw,this),this.spaceGraph.on("annotation-parameters-change",dw,this)}freeDrawingEvents(){this.spaceGraph.off("node-id-change",V_),this.spaceGraph.off("node-property-change",q_),this.spaceGraph.off("vertex-create",J_),this.spaceGraph.off("vertex-delete",K_),this.spaceGraph.off("vertex-set-position",Z_),this.spaceGraph.off("edge-create",Q_),this.spaceGraph.off("edge-delete",tw),this.spaceGraph.off("edge-set-vertices",ew),this.spaceGraph.off("space-create",iw),this.spaceGraph.off("space-delete",sw),this.spaceGraph.off("space-split",rw),this.spaceGraph.off("space-attributes-change",nw),this.spaceGraph.off("element-create",aw),this.spaceGraph.off("element-delete",lw),this.spaceGraph.off("element-transform-change",hw),this.spaceGraph.off("element-parameters-change",uw),this.spaceGraph.off("geometry-profile-update",pw),this.spaceGraph.off("geometry-update",fw),this.spaceGraph.off("annotation-transform-change",dw),this.spaceGraph.off("annotation-parameters-change",dw)}generateUi(){this.settings.ui.coordinates?this.addHelper("cursorCoordinates",{parentEl:this.fpeNode}):this.helper.cursorCoordinates&&this.removeHelper("cursorCoordinates"),this.settings.ui.scale?this.addHelper("scaleBar",{parentEl:this.fpeNode}):this.helper.scaleBar&&this.removeHelper("scaleBar")}getZoomExtentsBoundingBox(t,e,i,s,r,n,o){return function({layoutBoundingBox:t,rectLeft:e,rectTop:i,rectRight:s,rectBottom:r,viewportWidth:n,viewportHeight:o}){if([e,i,s,r].some((t=>t>0))&&n&&o){const a=s-e,l=r-i,h=function(t,e,i){const{min:s,max:r}=t;let n=s[0],o=s[1],a=r[0],l=r[1],h=a-n,u=l-o;const c=e/i;if(h/u>c){const t=u;u=h/c;const e=(t-u)/2;o+=e,l-=e}else{const t=h;h=u*c;const e=(t-h)/2;n+=e,a-=e}return{min:[n,o],max:[a,l]}}(t,a,l);let{min:u,max:c}=h,d=u[0],p=u[1],f=c[0]-d,m=c[1]-p;return f*=n/a,m*=o/l,d-=e/n*f,p-=i/o*m,{min:[d,p],max:[d+f,p+m]}}return t}({layoutBoundingBox:t,rectLeft:e,rectTop:i,rectRight:s,rectBottom:r,viewportWidth:n,viewportHeight:o})}zoomExtents(t=1,e=!1,i=null){return function({margin:t=0,animate:e,floorPlan:i,boundingBox:s}){return i.view.gfxLayers.scene?u_(s?{bb:s,animate:e,view:i.view}:{bb:i.getBoundingBox(t),animate:e,view:i.view}):Promise.resolve(!1)}({margin:t,animate:e,floorPlan:this,boundingBox:i})}zoomToElement(t,e=1,i){let s;if("string"==typeof t){const e=t;s=this.layout.elementsById[e]||this.layout.spacesById[e]||this.layout.spatialGraph.edgesById[e]||null}else s=t;if(!s)return Promise.resolve(!0);const{min:[r,n,o],max:[a,l,h]}=s.getAxisAlignedBoundingBox();return u_({bb:{min:[r-e,o-e],max:[a+e,h+e]},animate:i,view:this.view})}setZoom(t,e=!0){return u_({bb:t,animate:e,view:this.view})}zoomByFactor(t,e=!0){if(!Number.isFinite(t)||t<=0)return Promise.reject("factor is not a positive number");let{min:i,max:s}=this.view.viewbox,r=i[0],n=i[1],o=s[0]-r,a=s[1]-n;r-=(o/t-o)/2,n-=(a/t-a)/2;const l=r+o,h=n+a;return this.setZoom({min:[r,n],max:[l,h]},e)}addInfoWindow(t={}){return new fb({...t,floorPlan:this})}addHtmlMarker(t={}){return new mb({...t,floorPlan:this})}addMarker({position:t=[0,0],color:e="#669cff",size:i=40}={}){return new $b({position:t,color:e,size:i,floorPlan:this})}getPlanPosition(t){const e=this.view._viewport.toWorld(t[0],t[1]);return[e.x/nb,e.y/nb]}getScreenPosition(t){const e=t.map((t=>t*nb)),i=this.view._viewport.toScreen(e[0],e[1]);return[i.x,i.y]}addLayer({id:t,baseLayer:e}={}){var i;if(!(null==(i=this.view)?void 0:i.layers))return;if(t||(t=O()),this.view.layers.has(t)){const e=this.view.layers.get(t);if(null==e?void 0:e.container)return e}const s=new k_(this,e,t);return this.view.layers.set(t,s),s}getLayer(t){return this.view.layers.get(t)}addPlanGraphic(){return new k_(this)}addHelper(t,e={}){let i=null==e?void 0:e.helperId;return i||(i="string"==typeof t?t:O()),this.helper[i]&&this.removeHelper(i),"string"==typeof t?this.availableHelpers[t]?this.helper[i]=new this.availableHelpers[t]({floorPlan:this,helperId:i,...e}):nl.warn(`No helper registered for: ${t}`):this.helper[i]=new t({floorPlan:this,helperId:i,...e}),this.helper[i]}removeHelper(t){var e,i;null==(i=null==(e=this.helper[t])?void 0:e.destroy)||i.call(e),delete this.helper[t]}async exportImage({format:t="png",fileName:e,quality:i=90,output:s="base64",maxWidth:r,download:n=!1}={}){let o={format:t,quality:i,output:s,maxWidth:r};n&&(o.format="png");const a=document.querySelector("#"+this.fpeId+" canvas"),l=await function(t,{format:e="png",quality:i=.95}){return new Promise((s=>{let r;r="jpg"===e?t.toDataURL("image/jpeg",i):t.toDataURL(),s(r)}))}(a,o).catch((t=>t));if(!n)return l;B_(l,{format:t,fileName:e,quality:i})}destroy(){var t;null==(t=this.view._viewport)||t.destroy(),this.view.reset(),this.loader.reset(),this.freeDrawingEvents(),delete this.layout,delete this.utils,this.fpeNode&&this.fpeNode.remove(),delete this.fpeNode}},t.setApiUrls=({apiStorageUrl:t,spaceApiUrl:e,apiProductDataPath:i}={})=>{"string"==typeof t&&(rl=t),"string"==typeof i&&(sl=i),"string"==typeof e&&(R=e)},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
8
|
+
*/;const s=3.28084,r=(t,e=1/64)=>{const i=1/e;return Math.round(t*i)/i};function n(t){return Math.sign(t)*Math.floor(Math.abs(t))}function o(t,e){return typeof t<"u"&&null!==t&&Number.isFinite(t)&&t>=-e&&t<=e}const a=" ",l="m",h="′",u="″",c="m²",d="ft²";function p(t,e=.5,i=1/64){return!(t%e)||e<=i?[t/e,1/e]:p(t,e/2)}const f=(t=0,e="metric",i=3)=>{if("imperial"===e){const{feet:e,inches:i,fraction:o,isNegative:l}=function(t){const e=t*s,i=Math.abs(e),o=r(i%1*12);return{feet:n(i),inches:n(o),fraction:r(o%1),isNegative:Math.sign(t)<0}}(t);let c="";if(o>0){const[t,e]=p(r(o));c=`${a}${t}/${e}`}return`${l?"-":""}${e}${h}${a}${i}${c}${u}`}const o=Math.pow(10,i);return`${Math.round(t*o)/o}${a}${l}`},m=(t=0,e="metric",i=0,r=!0)=>{let n="",o="";const l=Math.pow(10,i);if("imperial"===e){const e=function(t){return t*s*s}(t);n=""+Math.round(e*l)/l,o=`${a}${d}`}else n=""+Math.round(t*l)/l,o=`${a}${c}`;return r&&(n+=o),n};["US","USA","United States","U.S","U.S.A","England","UK","U.K","United Kingdom","Liberia","Myanmar"].map((t=>t.toLowerCase()));const g=(t,e)=>{const i=`.${e}`;return(t=>t.replace(/[/\\]/g,"_"))((t=>t.replace(/[.,\s]/g,"_"))(t.endsWith(i)?t.split(i)[0]:t))+i};function y(t){const e=function(t){return"#"===t.slice(0,1)&&(t=t.slice(1)),t}(t);return 3===e.length?`#${e.split("").map((t=>t+t)).join("")}`:t}function v(t){return t>=0&&t<=255}function x(t){const e=y(t),i={r:parseInt(e.substring(1,3),16),g:parseInt(e.substring(3,5),16),b:parseInt(e.substring(5,7),16)};if(function({r:t,g:e,b:i}){return v(t)&&v(e)&&v(i)}(i))return i;throw"invalid hex color input"}function b(t){return JSON.parse(JSON.stringify(t))}function _(...t){let e={};for(const i of t)if(i instanceof Array)e instanceof Array||(e=[]),e=[...e,...i];else if(i instanceof Object)for(const t of Object.entries(i)){const i=t[0];let s=t[1];s instanceof Object&&i in e&&(s=_(e[i],s)),e={...e,[i]:s}}return e}function w(){return typeof window<"u"&&typeof navigator<"u"&&typeof document<"u"}!w()||window.self===window.top||window.location.ancestorOrigins&&window.location.ancestorOrigins[0]||document.referrer,w()&&navigator.platform.toUpperCase().indexOf("MAC");const P=["info","warnings","errors"];class E{constructor(t){this.levels=P.slice(),this.info=this.log,t&&this.setLevels(t),this.levelStack=[]}setLevels(t){const e=this.levels.slice();if("string"==typeof t)switch(t){case"none":this.levels=[];break;case"all":this.levels=["debug","info","warnings","errors"];break;case"debug":this.levels=["debug"];break;case"info":this.levels=["info"];break;case"warnings":this.levels=["warnings"];break;case"errors":this.levels=["errors"];break;default:console.error(`Unknown setting '${t}'.`)}else this.levels=t.slice();return e}push(){this.levelStack.push(this.levels)}pushAndSetLevels(t){return this.push(),this.setLevels(t)}pop(){if(this.levelStack.length>0){const t=this.levelStack.pop();this.setLevels(t)}}debug(...t){this.levels.includes("debug")&&console.debug(...t)}log(...t){this.levels.includes("info")&&console.log(...t)}warn(...t){this.levels.includes("warnings")&&console.warn(...t)}error(...t){this.levels.includes("errors")&&console.error(...t)}}for(var T,A=[],I=0;I<256;++I)A.push((I+256).toString(16).slice(1));var S=new Uint8Array(16);function C(){if(!T&&!(T="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return T(S)}const M={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function O(t,e,i){if(M.randomUUID&&!t)return M.randomUUID();var s=(t=t||{}).random||(t.rng||C)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,function(t,e=0){return(A[t[e+0]]+A[t[e+1]]+A[t[e+2]]+A[t[e+3]]+"-"+A[t[e+4]]+A[t[e+5]]+"-"+A[t[e+6]]+A[t[e+7]]+"-"+A[t[e+8]]+A[t[e+9]]+"-"+A[t[e+10]]+A[t[e+11]]+A[t[e+12]]+A[t[e+13]]+A[t[e+14]]+A[t[e+15]]).toLowerCase()}(s)}const N=t=>{const e=[];for(const[i,s]of Object.entries(t))void 0!==s&&e.push(`${i}=${String(s)}`);return e.length?`?${e.join("&")}`:""};class L extends Error{constructor(t,e,s){super(t||"There was a problem. Please check your internet connection and try again."),i(this,"code"),i(this,"data"),this.name="SpaceApiError",this.stack=(new Error).stack,this.code=e,this.data=s}}let R="https://api.archilogic.com";function k(t){let e;if(t.secretAccessToken)e={type:"secret",secretAccessToken:t.secretAccessToken};else if(t.temporaryAccessToken||t.temporaryAccessTokenFunction)e={type:"temporary",temporaryAccessToken:t.temporaryAccessToken};else{if(!t.publishableAccessToken)throw new L("Programming error: token is not provided.",void 0,void 0);e={type:"publishable",publishableAccessToken:t.publishableAccessToken}}return t.sdkVersion&&(e.sdkVersion=t.sdkVersion),e}function B(t){return t.status>=200&&t.status<400?t:t.json().then((e=>{const i=(null==e?void 0:e.message)||(null==e?void 0:e.error)||e;switch(typeof i){case"string":return Promise.reject(new L(i,t.status,void 0));case"object":return Promise.reject(new L(i.message,t.status,i.data));default:return Promise.reject(new L(null,null,e))}}))}async function F(t,e,i={},s){const r=new URL(R+e),n=function(t){var e;const i=new Headers;switch(t.type){case"secret":i.set("authorization",`AL-Secret-Token ${t.secretAccessToken}`);break;case"temporary":i.set("authorization",`${null==(e=t.temporaryAccessToken)?void 0:e.authorization}`)}return t.sdkVersion&&i.set("x-sdk-version",t.sdkVersion),i}(s);let o=!1;switch("publishable"===s.type&&r.searchParams.set("pubtoken",s.publishableAccessToken),t){case"GET":i&&"object"==typeof i&&Object.entries(i).forEach((([t,e])=>{void 0!==e&&r.searchParams.set(t,e.toString())}));break;case"POST":case"PUT":case"PATCH":n.set("content-type","application/json"),o=!0;break;case"DELETE":break;default:return Promise.reject(new L("Programming error, unsupported method: "+t,void 0,void 0))}return fetch(r.toString(),{method:t,headers:n,body:o?JSON.stringify(i):void 0}).then(B,(t=>{throw t})).then((t=>t.json())).catch((t=>Promise.reject(t)))}class D{constructor(t){i(this,"config"),i(this,"temporaryAccessTokenFunction"),i(this,"tempScopes",[{resource:"floor",action:"readPublic"},{resource:"floor",action:"readPrivate"},{resource:"floor",action:"queryPublic"},{resource:"floor",action:"queryPrivate"},{resource:"floor",action:"archive"},{resource:"customFields",action:"readPublic"},{resource:"customFields",action:"readPrivate"},{resource:"customFields",action:"write"}]),i(this,"temporaryAccessToken"),i(this,"temporaryAccessTokenPromise"),i(this,"durationSeconds",3600),this.config=k(t),(t.temporaryAccessToken||t.temporaryAccessTokenFunction)&&(this.temporaryAccessTokenFunction=t.temporaryAccessTokenFunction,this.temporaryAccessToken=t.temporaryAccessToken),t.temporaryAccessTokenScopes&&(this.tempScopes=t.temporaryAccessTokenScopes)}get isAccessTokenActive(){const t=(new Date).getTime()/1e3;return!!this.temporaryAccessToken&&this.temporaryAccessToken.expiresAt>t}async getTemporaryAccessToken(){if(this.isAccessTokenActive&&this.temporaryAccessToken)return this.temporaryAccessToken;this.temporaryAccessTokenPromise||(this.temporaryAccessTokenPromise=new Promise((async(t,e)=>{if(this.temporaryAccessTokenFunction&&(this.temporaryAccessToken=await this.temporaryAccessTokenFunction({scopes:this.tempScopes,durationSeconds:this.durationSeconds}),this.isAccessTokenActive&&t(this.temporaryAccessToken)),this.temporaryAccessToken){const t=new Date;t.setTime(1e3*this.temporaryAccessToken.expiresAt),e(new L(`Temporary access token expired at ${t.toString()}`,void 0,void 0))}else e(new L("Temporary access token not defined",void 0,void 0))})));try{return await this.temporaryAccessTokenPromise}catch(t){throw this.temporaryAccessTokenPromise=void 0,t}finally{this.isAccessTokenActive&&(this.temporaryAccessTokenPromise=void 0)}}async callSpaceAPI(t,e,i={},s=this.config){switch(s.type){case"secret":case"publishable":return F(t,e,i,s);case"temporary":{const r=await this.getTemporaryAccessToken();return F(t,e,i,{...s,temporaryAccessToken:r})}}}}class U{constructor(t,e={}){i(this,"connection"),this.connection=new D(t);for(const[i,s]of Object.entries(e))this[i]=s}async getTemporaryAccessToken(){return this.connection.getTemporaryAccessToken()}async createFloor(t){return this.connection.callSpaceAPI("POST","/v2/floor",t)}async duplicateFloor(t,e){const i=e.revisionId?`?revisionId=${e.revisionId}`:"";return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/duplicate${i}`)}async updateFloor(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/floor/${t}`,e)}async archiveFloor(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/archive`)}async unarchiveFloor(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/unarchive`)}async searchFloorsBasic(t){const{name:e,id:i,paginationInput:s,teamId:r}=t,n=((t,e,i,s)=>{const r={};return t&&(r.name={contains:`${t}`}),e&&(r.ids=[e]),s&&(r.team={id:{eq:s}}),{query:"query ($floorFilter: FloorFilter!, $paginationInput: PaginationInput) { getFloors(where: $floorFilter, paginationInput: $paginationInput) { floors { id name area createdAt updatedAt labels { name color } }, paginationInfo { currentPage limit offset totalCount totalPageCount} } }",variables:{floorFilter:r,paginationInput:i}}})(e,i,s,r);return this.connection.callSpaceAPI("POST","/graphql",n)}async searchFloorsAdvanced(t,e){const i=((t,e)=>({query:t,variables:{paginationInput:e}}))(t,e);return this.connection.callSpaceAPI("POST","/graphql",i)}async getFloorById(t,e=!1,i=!0,s=!1,r,n=!1){var o;const a=N({includeAddress:s,includeRelations:i,includeCustomAttributes:n}),l=await this.connection.callSpaceAPI("GET",`/v2/floor/${t}${e?"/geo-json":""}${a}`);let h={};if(null==(o=l.properties)?void 0:o.defaultLayoutId){const{layout:t,id:e,lastRevision:i,categories:s}=await this.getLayout(l.properties.defaultLayoutId,r);h={layout:{id:e,layout:t,lastRevision:i,categories:s}}}return{...l,...h}}async getFloorGeoJson(t,e){const i=N(e??{}),s=await this.connection.callSpaceAPI("GET",`/v2/floor/${t}/geo-json${i}`);let r;if(null==e?void 0:e.includeAllElements){const t=s.features.find((t=>"Floor"===t.properties.resourceType));r=null==t?void 0:t.properties.defaultLayoutId}else{r=s.properties.defaultLayoutId}if(r){const{layout:t,id:e,lastRevision:i,categories:n}=await this.getLayout(r);return{...s,layout:{id:e,layout:t,lastRevision:i,categories:n}}}return s}getFloorStatistics(t){return this.connection.callSpaceAPI("GET",`/v2/floor/${t}/statistics`)}queryFloors(t){return this.connection.callSpaceAPI("GET","/v2/floor",t)}async getAllFloors(t=!1,e=!1,i=!1,s,r){const n=t||i?1e3:1e4,o=await this.queryFloors({geometry:t,includeArchived:e,includeRelations:i,includeCustomAttributes:r,teamId:s,limit:n});let a=o.features||[];if(a.length<n)return o;for(;null==a?void 0:a.length;)a=(await this.queryFloors({geometry:t,includeArchived:e,includeRelations:i,includeCustomAttributes:r,teamId:s,offset:o.features.length,limit:n})).features||[],o.features.push(...a);return o}getFloorplanImage(t,e){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/2d-image`,e)}getSceneStructure(t,e=!1){return this.connection.callSpaceAPI("GET",`/v2/floor/${t}/scene-structure`,{includeMetadata:e})}assignLabel(t,e){return this.connection.callSpaceAPI("PUT",`/v2/floor/${t}/label/${e}`)}removeLabel(t,e){return this.connection.callSpaceAPI("DELETE",`/v2/floor/${t}/label/${e}`)}getSpaceById(t,e=!1,i=!0){const s=`?includeRelations=${i}`;return this.connection.callSpaceAPI("GET",`/v2/space/${t}/${e?"geo-json":""}${s}`)}querySpaces(t){return this.connection.callSpaceAPI("GET","/v2/space",t)}async getAllSpacesByFloorId(t,e=!1,i,s){const r=1e3,n=await this.querySpaces({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s,limit:r});let o=n.features||[];if(o.length<r)return n;for(;null==o?void 0:o.length;)o=(await this.querySpaces({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s,offset:n.features.length,limit:r})).features||[],n.features.push(...o);return n}getAssetById(t,e=!1,i=!0,s=!1){const r=N({includeRelations:i,includeCustomAttributes:s});return this.connection.callSpaceAPI("GET",`/v2/asset/${t}/${e?"geo-json":""}${r}`)}queryAssets(t){return this.connection.callSpaceAPI("GET","/v2/asset",t)}async getAllAssets(t){const{limit:e=1e4,...i}=t,s=await this.queryAssets({...i,limit:e});let r=s.features||[];if(r.length<e)return s;for(;null==r?void 0:r.length;)r=(await this.queryAssets({...t,offset:(t.offset||0)+s.features.length,limit:e})).features||[],s.features.push(...r);return s}getAllAssetsByFloorId(t,e=!1,i,s){return this.getAllAssets({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s})}getAllAssetsBySpaceId(t,e=!1,i,s){return this.getAllAssets({spaceId:t,geometry:e,includeRelations:i,includeCustomAttributes:s})}getCustomField(t,e,i){return this.connection.callSpaceAPI("GET",`/v2/${t}/${e}/custom-field/${i}`)}getAllCustomFields(t,e){return this.connection.callSpaceAPI("GET",`/v2/${t}/${e}/custom-field`)}setCustomField(t,e,i,s){return this.connection.callSpaceAPI("PUT",`/v2/${t}/${e}/custom-field/${i}`,s)}deleteCustomField(t,e,i){return this.connection.callSpaceAPI("DELETE",`/v2/${t}/${e}/custom-field/${i}`)}getLabel(t){return this.connection.callSpaceAPI("GET",`/v2/label/${t}`)}listLabels(){return this.connection.callSpaceAPI("GET","/v2/label/")}createOrUpdateLabel(t,e){return this.connection.callSpaceAPI("PUT",`/v2/label/${t}`,e)}deleteLabel(t){return this.connection.callSpaceAPI("DELETE",`/v2/label/${t}`)}getCustomAttributes(){return this.connection.callSpaceAPI("GET","/v2/custom-attributes")}getCustomAttribute(t,e){return this.connection.callSpaceAPI("GET",`/v2/${t.toLowerCase()}/custom-attributes/${e}`)}getCustomAttributesForResourceType(t){return this.connection.callSpaceAPI("GET",`/v2/${t.toLowerCase()}/custom-attributes`)}createCustomAttribute(t){const{resourceType:e,...i}=t;return this.connection.callSpaceAPI("POST",`/v2/${e.toLowerCase()}/custom-attributes`,i)}updateCustomAttribute(t){const{apiFieldName:e,resourceType:i,...s}=t;return this.connection.callSpaceAPI("PATCH",`/v2/${i.toLowerCase()}/custom-attributes/${e}`,s)}deleteCustomAttribute(t,e){return this.connection.callSpaceAPI("DELETE",`/v2/${t.toLowerCase()}/custom-attributes/${e}`)}getCustomAttributeValues(t,e){return this.connection.callSpaceAPI("GET",`/v2/${t.toLowerCase()}/${e}/custom-attributes`)}createCustomAttributeValue(t){const{apiFieldName:e,resourceId:i,resourceType:s,...r}=t;return this.connection.callSpaceAPI("POST",`/v2/${s.toLowerCase()}/${i}/custom-attributes/${e}`,r)}updateCustomAttributeValue(t){const{apiFieldName:e,resourceId:i,resourceType:s,...r}=t;return this.connection.callSpaceAPI("PATCH",`/v2/${s.toLowerCase()}/${i}/custom-attributes/${e}`,r)}deleteCustomAttributeValue(t,e,i){return this.connection.callSpaceAPI("DELETE",`/v2/${e.toLowerCase()}/${t}/custom-attributes/${i}`)}createLayout(t,e,i){return this.connection.callSpaceAPI("POST","/v2/layout",{floorId:t,layout:e,isDefault:i})}duplicateLayout(t,e){const i=N({revisionId:e});return this.connection.callSpaceAPI("POST",`/v2/layout/${t}/duplicate${i}`,{layoutId:t,revisionId:e})}getLayout(t,e){const i=N(e?{filter:e}:{});return this.connection.callSpaceAPI("GET",`/v2/layout/${t}${i}`)}getLayouts(t,e){const i=N({floorId:t,isDefault:e});return this.connection.callSpaceAPI("GET",`/v2/layout/${i}`)}updateLayout(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/layout/${t}`,e)}deleteLayout(t){return this.connection.callSpaceAPI("DELETE",`/v2/layout/${t}`)}createLayoutRevision(t,e){return this.connection.callSpaceAPI("POST",`/v2/layout/${t}/revisions`,{layout:e})}updateLayoutRevision(t,e,i){return this.connection.callSpaceAPI("PATCH",`/v2/layout/${t}/revisions/${e}`,i)}getLayoutRevisions(t,e){const i=N(e?{filter:e}:{});return this.connection.callSpaceAPI("GET",`/v2/layout/${t}/revisions${i}`)}getLayoutRevision(t,e){return this.connection.callSpaceAPI("GET",`/v2/layout/${t}/revisions/${e}`)}convertLanguageToQuery(t){return this.connection.callSpaceAPI("POST","/v2/language/graphql",t)}getDxf(t){return this.connection.callSpaceAPI("GET",`/v2/floor/${t}/dxf`)}getIfc(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/ifc`)}getGltf(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/gltf`)}getImdf(t){return this.connection.callSpaceAPI("POST",`/v2/floor/${t}/imdf`)}getImdfs(t){return this.connection.callSpaceAPI("POST","/v2/floor/imdf",t)}listExtensions(){return this.connection.callSpaceAPI("GET","/v2/extensions")}createExtension(t){return this.connection.callSpaceAPI("POST","/v2/extensions",t)}updateExtension(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/extensions/${t}`,e)}deleteExtension(t){return this.connection.callSpaceAPI("DELETE",`/v2/extensions/${t}`)}listBuildings(){return this.connection.callSpaceAPI("GET","/v2/buildings")}createBuilding(t){return this.connection.callSpaceAPI("POST","/v2/buildings",t)}getBuildingById(t){return this.connection.callSpaceAPI("GET",`/v2/buildings/${t}`)}updateBuilding(t,e){return this.connection.callSpaceAPI("PATCH",`/v2/buildings/${t}`,e)}deleteBuilding(t){return this.connection.callSpaceAPI("DELETE",`/v2/buildings/${t}`)}}var G,X=Object.defineProperty,W=(t,e,i)=>((t,e,i)=>e in t?X(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i)(t,"symbol"!=typeof e?e+"":e,i);(t=>{t.version="6.4.2.2",t.use_lines=!0;class e{constructor(){W(this,"m_Parent",null),W(this,"m_polygon",[]),W(this,"m_Index",0),W(this,"m_jointype",0),W(this,"m_endtype",0),W(this,"m_Children",[]),W(this,"IsOpen",!1)}IsHoleNode(){for(var t=!0,e=this.m_Parent;null!==e;)t=!t,e=e.m_Parent;return t}ChildCount(){return this.m_Children.length}Contour(){return this.m_polygon}AddChild(t){var e=this.m_Children.length;this.m_Children.push(t),t.m_Parent=this,t.m_Index=e}GetNext(){return this.m_Children.length>0?this.m_Children[0]:this.GetNextSiblingUp()}GetNextSiblingUp(){return null===this.m_Parent?null:this.m_Index===this.m_Parent.m_Children.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Children[this.m_Index+1]}Children(){return this.m_Children}Parent(){return this.m_Parent}IsHole(){return this.IsHoleNode()}}t.PolyNode=e;t.PolyTree=class extends e{constructor(){super(),W(this,"m_AllPolys",[])}Clear(){for(var t=0,e=this.m_AllPolys.length;t<e;t++)this.m_AllPolys[t]=null;this.m_AllPolys.length=0,this.m_Children.length=0}GetFirst(){return this.m_Children.length>0?this.m_Children[0]:null}Total(){var t=this.m_AllPolys.length;return t>0&&this.m_Children[0]!==this.m_AllPolys[0]&&t--,t}},t.Clear=function(t){t.length=0},t.PI=3.141592653589793,t.PI2=6.283185307179586;t.FPoint=class{constructor(...e){W(this,"X",0),W(this,"Y",0);var i=e,s=e.length;if(this.X=0,this.Y=0,2===s)this.X=i[0],this.Y=i[1];else if(1===s)if(i[0]instanceof t.FPoint){var r=i[0];this.X=r.X,this.Y=r.Y}else{var n=i[0];this.X=n.X,this.Y=n.Y}else this.X=0,this.Y=0}static op_Equality(t,e){return t.X===e.X&&t.Y===e.Y}static op_Inequality(t,e){return t.X!==e.X||t.Y!==e.Y}};var i,s,r,n,o,a,l,h;t.FRect=class{constructor(...t){W(this,"left"),W(this,"top"),W(this,"right"),W(this,"bottom");var e=t,i=t.length;if(4===i)this.left=e[0],this.top=e[1],this.right=e[2],this.bottom=e[3];else if(1===i){var s=e[0];this.left=s.left,this.top=s.top,this.right=s.right,this.bottom=s.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0}},(i=t.ClipType||(t.ClipType={}))[i.ctIntersection=0]="ctIntersection",i[i.ctUnion=1]="ctUnion",i[i.ctDifference=2]="ctDifference",i[i.ctXor=3]="ctXor",(s=t.PolyType||(t.PolyType={}))[s.ptSubject=0]="ptSubject",s[s.ptClip=1]="ptClip",(r=t.PolyFillType||(t.PolyFillType={}))[r.pftEvenOdd=0]="pftEvenOdd",r[r.pftNonZero=1]="pftNonZero",r[r.pftPositive=2]="pftPositive",r[r.pftNegative=3]="pftNegative",(n=t.JoinType||(t.JoinType={}))[n.jtSquare=0]="jtSquare",n[n.jtRound=1]="jtRound",n[n.jtMiter=2]="jtMiter",(o=t.EndType||(t.EndType={}))[o.etOpenSquare=0]="etOpenSquare",o[o.etOpenRound=1]="etOpenRound",o[o.etOpenButt=2]="etOpenButt",o[o.etClosedLine=3]="etClosedLine",o[o.etClosedPolygon=4]="etClosedPolygon",(a=t.EdgeSide||(t.EdgeSide={}))[a.esLeft=0]="esLeft",a[a.esRight=1]="esRight",(l=t.Direction||(t.Direction={}))[l.dRightToLeft=0]="dRightToLeft",l[l.dLeftToRight=1]="dLeftToRight",(h=t.NodeType||(t.NodeType={}))[h.ntAny=0]="ntAny",h[h.ntOpen=1]="ntOpen",h[h.ntClosed=2]="ntClosed";t.TEdge=class{constructor(){W(this,"Bot",new t.FPoint),W(this,"Curr",new t.FPoint),W(this,"Top",new t.FPoint),W(this,"Delta",new t.FPoint),W(this,"Dx",0),W(this,"PolyTyp",0),W(this,"Side",0),W(this,"WindDelta",0),W(this,"WindCnt",0),W(this,"WindCnt2",0),W(this,"OutIdx",0),W(this,"Next",null),W(this,"Prev",null),W(this,"NextInLML",null),W(this,"NextInAEL",null),W(this,"PrevInAEL",null),W(this,"NextInSEL",null),W(this,"PrevInSEL",null)}};t.IntersectNode=class{constructor(){W(this,"Edge1",null),W(this,"Edge2",null),W(this,"Pt",new t.FPoint)}},t.Compare=function(t,e){var i=e.Pt.Y-t.Pt.Y;return i>0?1:i<0?-1:0};t.LocalMinima=class{constructor(){W(this,"Y",0),W(this,"LeftBound",null),W(this,"RightBound",null),W(this,"Next",null)}};t.Scanbeam=class{constructor(){W(this,"Y",0),W(this,"Next",null)}};t.Maxima=class{constructor(){W(this,"X",0),W(this,"Next",null),W(this,"Prev",null)}};t.OutRec=class{constructor(){W(this,"Idx",0),W(this,"IsHole",!1),W(this,"IsOpen",!1),W(this,"FirstLeft",null),W(this,"Pts",null),W(this,"BottomPt",null),W(this,"PolyNode",null)}};t.OutPt=class{constructor(){W(this,"Idx",0),W(this,"Pt",new t.FPoint),W(this,"Next",null),W(this,"Prev",null)}};t.Join=class{constructor(){W(this,"OutPt1",null),W(this,"OutPt2",null),W(this,"OffPt",new t.FPoint)}};class u{constructor(){W(this,"m_MinimaList",null),W(this,"m_CurrentLM",null),W(this,"m_edges",new Array),W(this,"m_HasOpenPaths",!1),W(this,"PreserveCollinear",!1),W(this,"m_Scanbeam",null),W(this,"m_PolyOuts",null),W(this,"m_ActiveEdges",null)}static near_zero(e){return e>-t.ClipperBase.tolerance&&e<t.ClipperBase.tolerance}static IsHorizontal(t){return 0===t.Delta.Y}PointIsVertex(e,i){var s=i;do{if(t.FPoint.op_Equality(s.Pt,e))return!0;s=s.Next}while(s!==i);return!1}PointOnLineSegment(t,e,i){return t.X===e.X&&t.Y===e.Y||t.X===i.X&&t.Y===i.Y||t.X>e.X==t.X<i.X&&t.Y>e.Y==t.Y<i.Y&&(t.X-e.X)*(i.Y-e.Y)==(i.X-e.X)*(t.Y-e.Y)}PointOnPolygon(t,e){for(var i=e;;){if(this.PointOnLineSegment(t,i.Pt,i.Next.Pt))return!0;if((i=i.Next)===e)break}return!1}static SlopesEqual(){var t,e,i,s,r,n,o=arguments,a=o.length;return 2===a?(e=o[1],(t=o[0]).Delta.Y*e.Delta.X==t.Delta.X*e.Delta.Y):3===a?(s=o[1],r=o[2],((i=o[0]).Y-s.Y)*(s.X-r.X)-(i.X-s.X)*(s.Y-r.Y)==0):(s=o[1],r=o[2],n=o[3],((i=o[0]).Y-s.Y)*(r.X-n.X)-(i.X-s.X)*(r.Y-n.Y)==0)}static SlopesEqual3(t,e){return t.Delta.Y*e.Delta.X==t.Delta.X*e.Delta.Y}static SlopesEqual4(t,e,i){return(t.Y-e.Y)*(e.X-i.X)-(t.X-e.X)*(e.Y-i.Y)==0}static SlopesEqual5(t,e,i,s){return(t.Y-e.Y)*(i.X-s.X)-(t.X-e.X)*(i.Y-s.Y)==0}Clear(){this.DisposeLocalMinimaList();for(var e=0,i=this.m_edges.length;e<i;++e){for(var s=0,r=this.m_edges[e].length;s<r;++s)this.m_edges[e][s]=null;t.Clear(this.m_edges[e])}t.Clear(this.m_edges),this.m_HasOpenPaths=!1}DisposeLocalMinimaList(){for(;null!==this.m_MinimaList;){var t=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=t}this.m_CurrentLM=null}RangeTest(e){(e.X>t.ClipperBase.maxValue||e.X<-t.ClipperBase.maxValue||e.Y>t.ClipperBase.maxValue||e.Y<-t.ClipperBase.maxValue||e.X>0&&e.X<t.ClipperBase.minValue||e.Y>0&&e.Y<t.ClipperBase.minValue||e.X<0&&e.X>-t.ClipperBase.minValue||e.Y<0&&e.Y>-t.ClipperBase.minValue)&&t.Error("Coordinate outside allowed range in RangeTest().")}InitEdge(t,e,i,s){t.Next=e,t.Prev=i,t.Curr.X=s.X,t.Curr.Y=s.Y,t.OutIdx=-1}InitEdge2(t,e){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y),this.SetDx(t),t.PolyTyp=e}FindNextLocMin(e){for(var i;;){for(;t.FPoint.op_Inequality(e.Bot,e.Prev.Bot)||t.FPoint.op_Equality(e.Curr,e.Top);)e=e.Next;if(e.Dx!==t.ClipperBase.horizontal&&e.Prev.Dx!==t.ClipperBase.horizontal)break;for(;e.Prev.Dx===t.ClipperBase.horizontal;)e=e.Prev;for(i=e;e.Dx===t.ClipperBase.horizontal;)e=e.Next;if(e.Top.Y!==e.Prev.Bot.Y){i.Prev.Bot.X<e.Bot.X&&(e=i);break}}return e}ProcessBound(e,i){var s,r,n=e;if(n.OutIdx===t.ClipperBase.Skip){if(e=n,i){for(;e.Top.Y===e.Next.Bot.Y;)e=e.Next;for(;e!==n&&e.Dx===t.ClipperBase.horizontal;)e=e.Prev}else{for(;e.Top.Y===e.Prev.Bot.Y;)e=e.Prev;for(;e!==n&&e.Dx===t.ClipperBase.horizontal;)e=e.Next}if(e===n)n=i?e.Next:e.Prev;else{e=i?n.Next:n.Prev;var o=new t.LocalMinima;o.Next=null,o.Y=e.Bot.Y,o.LeftBound=null,o.RightBound=e,e.WindDelta=0,n=this.ProcessBound(e,i),this.InsertLocalMinima(o)}return n}if(e.Dx===t.ClipperBase.horizontal&&((s=i?e.Prev:e.Next).Dx===t.ClipperBase.horizontal?s.Bot.X!==e.Bot.X&&s.Top.X!==e.Bot.X&&this.ReverseHorizontal(e):s.Bot.X!==e.Bot.X&&this.ReverseHorizontal(e)),s=e,i){for(;n.Top.Y===n.Next.Bot.Y&&n.Next.OutIdx!==t.ClipperBase.Skip;)n=n.Next;if(n.Dx===t.ClipperBase.horizontal&&n.Next.OutIdx!==t.ClipperBase.Skip){for(r=n;r.Prev.Dx===t.ClipperBase.horizontal;)r=r.Prev;r.Prev.Top.X>n.Next.Top.X&&(n=r.Prev)}for(;e!==n;)e.NextInLML=e.Next,e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Prev.Top.X&&this.ReverseHorizontal(e),e=e.Next;e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Prev.Top.X&&this.ReverseHorizontal(e),n=n.Next}else{for(;n.Top.Y===n.Prev.Bot.Y&&n.Prev.OutIdx!==t.ClipperBase.Skip;)n=n.Prev;if(n.Dx===t.ClipperBase.horizontal&&n.Prev.OutIdx!==t.ClipperBase.Skip){for(r=n;r.Next.Dx===t.ClipperBase.horizontal;)r=r.Next;(r.Next.Top.X===n.Prev.Top.X||r.Next.Top.X>n.Prev.Top.X)&&(n=r.Next)}for(;e!==n;)e.NextInLML=e.Prev,e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Next.Top.X&&this.ReverseHorizontal(e),e=e.Prev;e.Dx===t.ClipperBase.horizontal&&e!==s&&e.Bot.X!==e.Next.Top.X&&this.ReverseHorizontal(e),n=n.Prev}return n}AddPath(e,i,s){t.use_lines?s||1!==i||t.Error("AddPath: Open paths must be subject."):s||t.Error("AddPath: Open paths have been disabled.");var r=e.length-1;if(s)for(;r>0&&t.FPoint.op_Equality(e[r],e[0]);)--r;for(;r>0&&t.FPoint.op_Equality(e[r],e[r-1]);)--r;if(s&&r<2||!s&&r<1)return!1;for(var n=new Array,o=0;o<=r;o++)n.push(new t.TEdge);var a=!0;n[1].Curr.X=e[1].X,n[1].Curr.Y=e[1].Y,this.RangeTest(e[0]),this.RangeTest(e[r]),this.InitEdge(n[0],n[1],n[r],e[0]),this.InitEdge(n[r],n[0],n[r-1],e[r]);for(o=r-1;o>=1;--o)this.RangeTest(e[o]),this.InitEdge(n[o],n[o+1],n[o-1],e[o]);for(var l,h=n[0],u=h,c=h;;)if(u.Curr!==u.Next.Curr||!s&&u.Next===h){if(u.Prev===u.Next)break;if(!s||!t.ClipperBase.SlopesEqual4(u.Prev.Curr,u.Curr,u.Next.Curr)||this.PreserveCollinear&&this.Pt2IsBetweenPt1AndPt3(u.Prev.Curr,u.Curr,u.Next.Curr)){if((u=u.Next)===c||!s&&u.Next===h)break}else u===h&&(h=u.Next),c=u=(u=this.RemoveEdge(u)).Prev}else{if(u===u.Next)break;u===h&&(h=u.Next),c=u=this.RemoveEdge(u)}if(!s&&u===u.Next||s&&u.Prev===u.Next)return!1;s||(this.m_HasOpenPaths=!0,h.Prev.OutIdx=t.ClipperBase.Skip),u=h;do{this.InitEdge2(u,i),u=u.Next,a&&u.Curr.Y!==h.Curr.Y&&(a=!1)}while(u!==h);if(a){if(s)return!1;for(u.Prev.OutIdx=t.ClipperBase.Skip,(p=new t.LocalMinima).Next=null,p.Y=u.Bot.Y,p.LeftBound=null,p.RightBound=u,p.RightBound.Side=1,p.RightBound.WindDelta=0;u.Bot.X!==u.Prev.Top.X&&this.ReverseHorizontal(u),u.Next.OutIdx!==t.ClipperBase.Skip;)u.NextInLML=u.Next,u=u.Next;return this.InsertLocalMinima(p),this.m_edges.push(n),!0}this.m_edges.push(n);var d=null;for(t.FPoint.op_Equality(u.Prev.Bot,u.Prev.Top)&&(u=u.Next);(u=this.FindNextLocMin(u))!==d;){var p;null===d&&(d=u),(p=new t.LocalMinima).Next=null,p.Y=u.Bot.Y,u.Dx<u.Prev.Dx?(p.LeftBound=u.Prev,p.RightBound=u,l=!1):(p.LeftBound=u,p.RightBound=u.Prev,l=!0),p.LeftBound.Side=0,p.RightBound.Side=1,s?p.LeftBound.Next===p.RightBound?p.LeftBound.WindDelta=-1:p.LeftBound.WindDelta=1:p.LeftBound.WindDelta=0,p.RightBound.WindDelta=-p.LeftBound.WindDelta,(u=this.ProcessBound(p.LeftBound,l)).OutIdx===t.ClipperBase.Skip&&(u=this.ProcessBound(u,l));var f=this.ProcessBound(p.RightBound,!l);f.OutIdx===t.ClipperBase.Skip&&(f=this.ProcessBound(f,!l)),p.LeftBound.OutIdx===t.ClipperBase.Skip?p.LeftBound=null:p.RightBound.OutIdx===t.ClipperBase.Skip&&(p.RightBound=null),this.InsertLocalMinima(p),l||(u=f)}return!0}AddPaths(t,e,i){for(var s=!1,r=0,n=t.length;r<n;++r)this.AddPath(t[r],e,i)&&(s=!0);return s}Pt2IsBetweenPt1AndPt3(e,i,s){return!(t.FPoint.op_Equality(e,s)||t.FPoint.op_Equality(e,i)||t.FPoint.op_Equality(s,i))&&(e.X!==s.X?i.X>e.X==i.X<s.X:i.Y>e.Y==i.Y<s.Y)}RemoveEdge(t){t.Prev.Next=t.Next,t.Next.Prev=t.Prev;var e=t.Next;return t.Prev=null,e}SetDx(e){e.Delta.X=e.Top.X-e.Bot.X,e.Delta.Y=e.Top.Y-e.Bot.Y,0===e.Delta.Y?e.Dx=t.ClipperBase.horizontal:e.Dx=e.Delta.X/e.Delta.Y}InsertLocalMinima(t){if(null===this.m_MinimaList)this.m_MinimaList=t;else if(t.Y>=this.m_MinimaList.Y)t.Next=this.m_MinimaList,this.m_MinimaList=t;else{for(var e=this.m_MinimaList;null!==e.Next&&t.Y<e.Next.Y;)e=e.Next;t.Next=e.Next,e.Next=t}}PopLocalMinima(t,e){return e.v=this.m_CurrentLM,null!==this.m_CurrentLM&&this.m_CurrentLM.Y===t&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)}ReverseHorizontal(t){var e=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=e}Reset(){if(this.m_CurrentLM=this.m_MinimaList,null!==this.m_CurrentLM){this.m_Scanbeam=null;for(var e=this.m_MinimaList;null!==e;){this.InsertScanbeam(e.Y);var i=e.LeftBound;null!==i&&(i.Curr.X=i.Bot.X,i.Curr.Y=i.Bot.Y,i.OutIdx=t.ClipperBase.Unassigned),null!==(i=e.RightBound)&&(i.Curr.X=i.Bot.X,i.Curr.Y=i.Bot.Y,i.OutIdx=t.ClipperBase.Unassigned),e=e.Next}this.m_ActiveEdges=null}}InsertScanbeam(e){if(null===this.m_Scanbeam)this.m_Scanbeam=new t.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=e;else if(e>this.m_Scanbeam.Y){var i=new t.Scanbeam;i.Y=e,i.Next=this.m_Scanbeam,this.m_Scanbeam=i}else{for(var s=this.m_Scanbeam;null!==s.Next&&e<=s.Next.Y;)s=s.Next;if(e===s.Y)return;var r=new t.Scanbeam;r.Y=e,r.Next=s.Next,s.Next=r}}PopScanbeam(t){return null===this.m_Scanbeam?(t.v=0,!1):(t.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)}LocalMinimaPending(){return null!==this.m_CurrentLM}CreateOutRec(){var e=new t.OutRec;return e.Idx=t.ClipperBase.Unassigned,e.IsHole=!1,e.IsOpen=!1,e.FirstLeft=null,e.Pts=null,e.BottomPt=null,e.PolyNode=null,this.m_PolyOuts.push(e),e.Idx=this.m_PolyOuts.length-1,e}DisposeOutRec(t){var e=this.m_PolyOuts[t];e.Pts=null,e=null,this.m_PolyOuts[t]=null}UpdateEdgeIntoAEL(e){null===e.NextInLML&&t.Error("UpdateEdgeIntoAEL: invalid call");var i=e.PrevInAEL,s=e.NextInAEL;return e.NextInLML.OutIdx=e.OutIdx,null!==i?i.NextInAEL=e.NextInLML:this.m_ActiveEdges=e.NextInLML,null!==s&&(s.PrevInAEL=e.NextInLML),e.NextInLML.Side=e.Side,e.NextInLML.WindDelta=e.WindDelta,e.NextInLML.WindCnt=e.WindCnt,e.NextInLML.WindCnt2=e.WindCnt2,(e=e.NextInLML).Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,e.PrevInAEL=i,e.NextInAEL=s,t.ClipperBase.IsHorizontal(e)||this.InsertScanbeam(e.Top.Y),e}SwapPositionsInAEL(t,e){if(t.NextInAEL!==t.PrevInAEL&&e.NextInAEL!==e.PrevInAEL){if(t.NextInAEL===e){var i=e.NextInAEL;null!==i&&(i.PrevInAEL=t);var s=t.PrevInAEL;null!==s&&(s.NextInAEL=e),e.PrevInAEL=s,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=i}else if(e.NextInAEL===t){var r=t.NextInAEL;null!==r&&(r.PrevInAEL=e);var n=e.PrevInAEL;null!==n&&(n.NextInAEL=t),t.PrevInAEL=n,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=r}else{var o=t.NextInAEL,a=t.PrevInAEL;t.NextInAEL=e.NextInAEL,null!==t.NextInAEL&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=e.PrevInAEL,null!==t.PrevInAEL&&(t.PrevInAEL.NextInAEL=t),e.NextInAEL=o,null!==e.NextInAEL&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=a,null!==e.PrevInAEL&&(e.PrevInAEL.NextInAEL=e)}null===t.PrevInAEL?this.m_ActiveEdges=t:null===e.PrevInAEL&&(this.m_ActiveEdges=e)}}DeleteFromAEL(t){var e=t.PrevInAEL,i=t.NextInAEL;null===e&&null===i&&t!==this.m_ActiveEdges||(null!==e?e.NextInAEL=i:this.m_ActiveEdges=i,null!==i&&(i.PrevInAEL=e),t.NextInAEL=null,t.PrevInAEL=null)}}W(u,"horizontal",-34e37),W(u,"Skip",-2),W(u,"Unassigned",-1),W(u,"tolerance",1e-20),W(u,"maxValue",Math.sqrt(Number.MAX_VALUE)),W(u,"minValue",Math.sqrt(Number.MIN_VALUE)),t.ClipperBase=u;class c extends u{constructor(e){super(),W(this,"m_SortedEdges",null),W(this,"m_IntersectList",null),W(this,"m_IntersectNodeComparer",null),W(this,"m_ExecuteLocked",!1),W(this,"m_ClipFillType",0),W(this,"m_SubjFillType",0),W(this,"m_Joins",null),W(this,"m_GhostJoins",null),W(this,"m_UsingPolyTree",!1),W(this,"ReverseSolution",!1),W(this,"StrictlySimple",!1),W(this,"m_ClipType",0),W(this,"m_Maxima",null),W(this,"ZFillFunction"),void 0===e&&(e=0),this.m_PolyOuts=null,this.m_Scanbeam=null,this.m_ActiveEdges=null,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=new Array,this.m_IntersectNodeComparer=t.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=new Array,this.m_Joins=new Array,this.m_GhostJoins=new Array,this.ReverseSolution=!!(1&e),this.StrictlySimple=!!(2&e),this.PreserveCollinear=!!(4&e)}Clear(){0!==this.m_edges.length&&(this.DisposeAllPolyPts(),super.Clear())}InsertMaxima(e){var i=new t.Maxima;if(i.X=e,null===this.m_Maxima)this.m_Maxima=i,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(e<this.m_Maxima.X)i.Next=this.m_Maxima,i.Prev=null,this.m_Maxima=i;else{for(var s=this.m_Maxima;null!==s.Next&&e>=s.Next.X;)s=s.Next;if(e===s.X)return;i.Next=s.Next,i.Prev=s,null!==s.Next&&(s.Next.Prev=i),s.Next=i}}Execute(...e){var i=e,s=i.length,r=i[1]instanceof t.PolyTree;if(4===s&&!r){var n=i[0],o=i[1],a=i[2],l=i[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&t.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,t.Clear(o),this.m_SubjFillType=a,this.m_ClipFillType=l,this.m_ClipType=n,this.m_UsingPolyTree=!1;try{(u=this.ExecuteInternal())&&this.BuildResult(o)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return u}if(4===s&&r){n=i[0];var h=i[1];a=i[2],l=i[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=a,this.m_ClipFillType=l,this.m_ClipType=n,this.m_UsingPolyTree=!0;try{var u;(u=this.ExecuteInternal())&&this.BuildResult2(h)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return u}if(2===s&&!r){n=i[0],o=i[1];return this.Execute(n,o,0,0)}if(2===s&&r){n=i[0],h=i[1];return this.Execute(n,h,0,0)}}FixHoleLinkage(t){if(null!==t.FirstLeft&&(t.IsHole===t.FirstLeft.IsHole||null===t.FirstLeft.Pts)){for(var e=t.FirstLeft;null!==e&&(e.IsHole===t.IsHole||null===e.Pts);)e=e.FirstLeft;t.FirstLeft=e}}ExecuteInternal(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var t,e,i,s={},r={};if(!this.PopScanbeam(s))return!1;for(this.InsertLocalMinimaIntoAEL(s.v);this.PopScanbeam(r)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(r.v))return!1;this.ProcessEdgesAtTopOfScanbeam(r.v),s.v=r.v,this.InsertLocalMinimaIntoAEL(s.v)}for(e=0,i=this.m_PolyOuts.length;e<i;e++)null===(t=this.m_PolyOuts[e]).Pts||t.IsOpen||(t.IsHole^this.ReverseSolution)==this.Area$1(t)>0&&this.ReversePolyPtLinks(t.Pts);for(this.JoinCommonEdges(),e=0,i=this.m_PolyOuts.length;e<i;e++)null!==(t=this.m_PolyOuts[e]).Pts&&(t.IsOpen?this.FixupOutPolyline(t):this.FixupOutPolygon(t));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}}DisposeAllPolyPts(){for(var e=0,i=this.m_PolyOuts.length;e<i;++e)this.DisposeOutRec(e);t.Clear(this.m_PolyOuts)}AddJoin(e,i,s){var r=new t.Join;r.OutPt1=e,r.OutPt2=i,r.OffPt.X=s.X,r.OffPt.Y=s.Y,this.m_Joins.push(r)}AddGhostJoin(e,i){var s=new t.Join;s.OutPt1=e,s.OffPt.X=i.X,s.OffPt.Y=i.Y,this.m_GhostJoins.push(s)}InsertLocalMinimaIntoAEL(e){for(var i,s,r={};this.PopLocalMinima(e,r);){i=r.v.LeftBound,s=r.v.RightBound;var n=null;if(null===i?(this.InsertEdgeIntoAEL(s,null),this.SetWindingCount(s),this.IsContributing(s)&&(n=this.AddOutPt(s,s.Bot))):null===s?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(n=this.AddOutPt(i,i.Bot)),this.InsertScanbeam(i.Top.Y)):(this.InsertEdgeIntoAEL(i,null),this.InsertEdgeIntoAEL(s,i),this.SetWindingCount(i),s.WindCnt=i.WindCnt,s.WindCnt2=i.WindCnt2,this.IsContributing(i)&&(n=this.AddLocalMinPoly(i,s,i.Bot)),this.InsertScanbeam(i.Top.Y)),null!==s&&(t.ClipperBase.IsHorizontal(s)?(null!==s.NextInLML&&this.InsertScanbeam(s.NextInLML.Top.Y),this.AddEdgeToSEL(s)):this.InsertScanbeam(s.Top.Y)),null!==i&&null!==s){if(null!==n&&t.ClipperBase.IsHorizontal(s)&&this.m_GhostJoins.length>0&&0!==s.WindDelta)for(var o=0,a=this.m_GhostJoins.length;o<a;o++){var l=this.m_GhostJoins[o];this.HorzSegmentsOverlap(l.OutPt1.Pt.X,l.OffPt.X,s.Bot.X,s.Top.X)&&this.AddJoin(l.OutPt1,n,l.OffPt)}if(i.OutIdx>=0&&null!==i.PrevInAEL&&i.PrevInAEL.Curr.X===i.Bot.X&&i.PrevInAEL.OutIdx>=0&&t.ClipperBase.SlopesEqual5(i.PrevInAEL.Curr,i.PrevInAEL.Top,i.Curr,i.Top)&&0!==i.WindDelta&&0!==i.PrevInAEL.WindDelta){var h=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(n,h,i.Top)}if(i.NextInAEL!==s){if(s.OutIdx>=0&&s.PrevInAEL.OutIdx>=0&&t.ClipperBase.SlopesEqual5(s.PrevInAEL.Curr,s.PrevInAEL.Top,s.Curr,s.Top)&&0!==s.WindDelta&&0!==s.PrevInAEL.WindDelta){h=this.AddOutPt(s.PrevInAEL,s.Bot);this.AddJoin(n,h,s.Top)}var u=i.NextInAEL;if(null!==u)for(;u!==s;)this.IntersectEdges(s,u,i.Curr),u=u.NextInAEL}}}}InsertEdgeIntoAEL(t,e){if(null===this.m_ActiveEdges)t.PrevInAEL=null,t.NextInAEL=null,this.m_ActiveEdges=t;else if(null===e&&this.E2InsertsBeforeE1(this.m_ActiveEdges,t))t.PrevInAEL=null,t.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=t,this.m_ActiveEdges=t;else{for(null===e&&(e=this.m_ActiveEdges);null!==e.NextInAEL&&!this.E2InsertsBeforeE1(e.NextInAEL,t);)e=e.NextInAEL;t.NextInAEL=e.NextInAEL,null!==e.NextInAEL&&(e.NextInAEL.PrevInAEL=t),t.PrevInAEL=e,e.NextInAEL=t}}E2InsertsBeforeE1(e,i){return i.Curr.X===e.Curr.X?i.Top.Y>e.Top.Y?i.Top.X<t.Clipper.TopX(e,i.Top.Y):e.Top.X>t.Clipper.TopX(i,e.Top.Y):i.Curr.X<e.Curr.X}IsEvenOddFillType(t){return 0===t.PolyTyp?0===this.m_SubjFillType:0===this.m_ClipFillType}IsEvenOddAltFillType(t){return 0===t.PolyTyp?0===this.m_ClipFillType:0===this.m_SubjFillType}IsContributing(t){var e,i;switch(0===t.PolyTyp?(e=this.m_SubjFillType,i=this.m_ClipFillType):(e=this.m_ClipFillType,i=this.m_SubjFillType),e){case 0:if(0===t.WindDelta&&1!==t.WindCnt)return!1;break;case 1:if(1!==Math.abs(t.WindCnt))return!1;break;case 2:if(1!==t.WindCnt)return!1;break;default:if(-1!==t.WindCnt)return!1}switch(this.m_ClipType){case 0:switch(i){case 0:case 1:return 0!==t.WindCnt2;case 2:return t.WindCnt2>0;default:return t.WindCnt2<0}case 1:switch(i){case 0:case 1:return 0===t.WindCnt2;case 2:return t.WindCnt2<=0;default:return t.WindCnt2>=0}case 2:if(0===t.PolyTyp)switch(i){case 0:case 1:return 0===t.WindCnt2;case 2:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(i){case 0:case 1:return 0!==t.WindCnt2;case 2:return t.WindCnt2>0;default:return t.WindCnt2<0}case 3:if(0!==t.WindDelta)return!0;switch(i){case 0:case 1:return 0===t.WindCnt2;case 2:return t.WindCnt2<=0;default:return t.WindCnt2>=0}}return!0}SetWindingCount(t){for(var e=t.PrevInAEL;null!==e&&(e.PolyTyp!==t.PolyTyp||0===e.WindDelta);)e=e.PrevInAEL;if(null===e){var i=0===t.PolyTyp?this.m_SubjFillType:this.m_ClipFillType;0===t.WindDelta?t.WindCnt=3===i?-1:1:t.WindCnt=t.WindDelta,t.WindCnt2=0,e=this.m_ActiveEdges}else if(0===t.WindDelta&&1!==this.m_ClipType)t.WindCnt=1,t.WindCnt2=e.WindCnt2,e=e.NextInAEL;else if(this.IsEvenOddFillType(t)){if(0===t.WindDelta){for(var s=!0,r=e.PrevInAEL;null!==r;)r.PolyTyp===e.PolyTyp&&0!==r.WindDelta&&(s=!s),r=r.PrevInAEL;t.WindCnt=s?0:1}else t.WindCnt=t.WindDelta;t.WindCnt2=e.WindCnt2,e=e.NextInAEL}else e.WindCnt*e.WindDelta<0?Math.abs(e.WindCnt)>1?e.WindDelta*t.WindDelta<0?t.WindCnt=e.WindCnt:t.WindCnt=e.WindCnt+t.WindDelta:t.WindCnt=0===t.WindDelta?1:t.WindDelta:0===t.WindDelta?t.WindCnt=e.WindCnt<0?e.WindCnt-1:e.WindCnt+1:e.WindDelta*t.WindDelta<0?t.WindCnt=e.WindCnt:t.WindCnt=e.WindCnt+t.WindDelta,t.WindCnt2=e.WindCnt2,e=e.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;e!==t;)0!==e.WindDelta&&(t.WindCnt2=0===t.WindCnt2?1:0),e=e.NextInAEL;else for(;e!==t;)t.WindCnt2+=e.WindDelta,e=e.NextInAEL}AddEdgeToSEL(t){null===this.m_SortedEdges?(this.m_SortedEdges=t,t.PrevInSEL=null,t.NextInSEL=null):(t.NextInSEL=this.m_SortedEdges,t.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=t,this.m_SortedEdges=t)}PopEdgeFromSEL(t){if(t.v=this.m_SortedEdges,null===t.v)return!1;var e=t.v;return this.m_SortedEdges=t.v.NextInSEL,null!==this.m_SortedEdges&&(this.m_SortedEdges.PrevInSEL=null),e.NextInSEL=null,e.PrevInSEL=null,!0}CopyAELToSEL(){var t=this.m_ActiveEdges;for(this.m_SortedEdges=t;null!==t;)t.PrevInSEL=t.PrevInAEL,t.NextInSEL=t.NextInAEL,t=t.NextInAEL}SwapPositionsInSEL(t,e){if(!(null===t.NextInSEL&&null===t.PrevInSEL||null===e.NextInSEL&&null===e.PrevInSEL)){if(t.NextInSEL===e)null!==(i=e.NextInSEL)&&(i.PrevInSEL=t),null!==(s=t.PrevInSEL)&&(s.NextInSEL=e),e.PrevInSEL=s,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=i;else if(e.NextInSEL===t){null!==(i=t.NextInSEL)&&(i.PrevInSEL=e),null!==(s=e.PrevInSEL)&&(s.NextInSEL=t),t.PrevInSEL=s,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=i}else{var i=t.NextInSEL,s=t.PrevInSEL;t.NextInSEL=e.NextInSEL,null!==t.NextInSEL&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=e.PrevInSEL,null!==t.PrevInSEL&&(t.PrevInSEL.NextInSEL=t),e.NextInSEL=i,null!==e.NextInSEL&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=s,null!==e.PrevInSEL&&(e.PrevInSEL.NextInSEL=e)}null===t.PrevInSEL?this.m_SortedEdges=t:null===e.PrevInSEL&&(this.m_SortedEdges=e)}}AddLocalMaxPoly(t,e,i){this.AddOutPt(t,i),0===e.WindDelta&&this.AddOutPt(e,i),t.OutIdx===e.OutIdx?(t.OutIdx=-1,e.OutIdx=-1):t.OutIdx<e.OutIdx?this.AppendPolygon(t,e):this.AppendPolygon(e,t)}AddLocalMinPoly(e,i,s){var r,n,o;if(t.ClipperBase.IsHorizontal(i)||e.Dx>i.Dx?(r=this.AddOutPt(e,s),i.OutIdx=e.OutIdx,e.Side=0,i.Side=1,o=(n=e).PrevInAEL===i?i.PrevInAEL:n.PrevInAEL):(r=this.AddOutPt(i,s),e.OutIdx=i.OutIdx,e.Side=1,i.Side=0,o=(n=i).PrevInAEL===e?e.PrevInAEL:n.PrevInAEL),null!==o&&o.OutIdx>=0&&o.Top.Y<s.Y&&n.Top.Y<s.Y){var a=t.Clipper.TopX(o,s.Y),l=t.Clipper.TopX(n,s.Y);if(a===l&&0!==n.WindDelta&&0!==o.WindDelta&&t.ClipperBase.SlopesEqual5(new t.FPoint(a,s.Y),o.Top,new t.FPoint(l,s.Y),n.Top)){var h=this.AddOutPt(o,s);this.AddJoin(r,h,n.Top)}}return r}AddOutPt(e,i){if(e.OutIdx<0){let r=this.CreateOutRec();r.IsOpen=0===e.WindDelta;var s=new t.OutPt;return r.Pts=s,s.Idx=r.Idx,s.Pt.X=i.X,s.Pt.Y=i.Y,s.Next=s,s.Prev=s,r.IsOpen||this.SetHoleState(e,r),e.OutIdx=r.Idx,s}{let o=this.m_PolyOuts[e.OutIdx];var r=o.Pts,n=0===e.Side;return n&&t.FPoint.op_Equality(i,r.Pt)?r:!n&&t.FPoint.op_Equality(i,r.Prev.Pt)?r.Prev:((s=new t.OutPt).Idx=o.Idx,s.Pt.X=i.X,s.Pt.Y=i.Y,s.Next=r,s.Prev=r.Prev,s.Prev.Next=s,r.Prev=s,n&&(o.Pts=s),s)}}GetLastOutPt(t){var e=this.m_PolyOuts[t.OutIdx];return 0===t.Side?e.Pts:e.Pts.Prev}SwapPoints(e,i){var s=new t.FPoint(e.Value);e.Value.X=i.Value.X,e.Value.Y=i.Value.Y,i.Value.X=s.X,i.Value.Y=s.Y}HorzSegmentsOverlap(t,e,i,s){var r;return t>e&&(r=t,t=e,e=r),i>s&&(r=i,i=s,s=r),t<s&&i<e}SetHoleState(t,e){for(var i=t.PrevInAEL,s=null;null!==i;)i.OutIdx>=0&&0!==i.WindDelta&&(null===s?s=i:s.OutIdx===i.OutIdx&&(s=null)),i=i.PrevInAEL;null===s?(e.FirstLeft=null,e.IsHole=!1):(e.FirstLeft=this.m_PolyOuts[s.OutIdx],e.IsHole=!e.FirstLeft.IsHole)}GetDx(e,i){return e.Y===i.Y?t.ClipperBase.horizontal:(i.X-e.X)/(i.Y-e.Y)}FirstIsBottomPt(e,i){for(var s=e.Prev;t.FPoint.op_Equality(s.Pt,e.Pt)&&s!==e;)s=s.Prev;var r=Math.abs(this.GetDx(e.Pt,s.Pt));for(s=e.Next;t.FPoint.op_Equality(s.Pt,e.Pt)&&s!==e;)s=s.Next;var n=Math.abs(this.GetDx(e.Pt,s.Pt));for(s=i.Prev;t.FPoint.op_Equality(s.Pt,i.Pt)&&s!==i;)s=s.Prev;var o=Math.abs(this.GetDx(i.Pt,s.Pt));for(s=i.Next;t.FPoint.op_Equality(s.Pt,i.Pt)&&s!==i;)s=s.Next;var a=Math.abs(this.GetDx(i.Pt,s.Pt));return Math.max(r,n)===Math.max(o,a)&&Math.min(r,n)===Math.min(o,a)?this.Area(e)>0:r>=o&&r>=a||n>=o&&n>=a}GetBottomPt(e){for(var i=null,s=e.Next;s!==e;)s.Pt.Y>e.Pt.Y?(e=s,i=null):s.Pt.Y===e.Pt.Y&&s.Pt.X<=e.Pt.X&&(s.Pt.X<e.Pt.X?(i=null,e=s):s.Next!==e&&s.Prev!==e&&(i=s)),s=s.Next;if(null!==i)for(;i!==s;)for(this.FirstIsBottomPt(s,i)||(e=i),i=i.Next;t.FPoint.op_Inequality(i.Pt,e.Pt);)i=i.Next;return e}GetLowermostRec(t,e){null===t.BottomPt&&(t.BottomPt=this.GetBottomPt(t.Pts)),null===e.BottomPt&&(e.BottomPt=this.GetBottomPt(e.Pts));var i=t.BottomPt,s=e.BottomPt;return i.Pt.Y>s.Pt.Y?t:i.Pt.Y<s.Pt.Y?e:i.Pt.X<s.Pt.X?t:i.Pt.X>s.Pt.X||i.Next===i?e:s.Next===s||this.FirstIsBottomPt(i,s)?t:e}OutRec1RightOfOutRec2(t,e){do{if((t=t.FirstLeft)===e)return!0}while(null!==t);return!1}GetOutRec(t){for(var e=this.m_PolyOuts[t];e!==this.m_PolyOuts[e.Idx];)e=this.m_PolyOuts[e.Idx];return e}AppendPolygon(t,e){var i,s=this.m_PolyOuts[t.OutIdx],r=this.m_PolyOuts[e.OutIdx];i=this.OutRec1RightOfOutRec2(s,r)?r:this.OutRec1RightOfOutRec2(r,s)?s:this.GetLowermostRec(s,r);var n=s.Pts,o=n.Prev,a=r.Pts,l=a.Prev;0===t.Side?0===e.Side?(this.ReversePolyPtLinks(a),a.Next=n,n.Prev=a,o.Next=l,l.Prev=o,s.Pts=l):(l.Next=n,n.Prev=l,a.Prev=o,o.Next=a,s.Pts=a):1===e.Side?(this.ReversePolyPtLinks(a),o.Next=l,l.Prev=o,a.Next=n,n.Prev=a):(o.Next=a,a.Prev=o,n.Prev=l,l.Next=n),s.BottomPt=null,i===r&&(r.FirstLeft!==s&&(s.FirstLeft=r.FirstLeft),s.IsHole=r.IsHole),r.Pts=null,r.BottomPt=null,r.FirstLeft=s;var h=t.OutIdx,u=e.OutIdx;t.OutIdx=-1,e.OutIdx=-1;for(var c=this.m_ActiveEdges;null!==c;){if(c.OutIdx===u){c.OutIdx=h,c.Side=t.Side;break}c=c.NextInAEL}r.Idx=s.Idx}ReversePolyPtLinks(t){if(null!==t){var e,i;e=t;do{i=e.Next,e.Next=e.Prev,e.Prev=i,e=i}while(e!==t)}}static SwapSides(t,e){var i=t.Side;t.Side=e.Side,e.Side=i}static SwapPolyIndexes(t,e){var i=t.OutIdx;t.OutIdx=e.OutIdx,e.OutIdx=i}IntersectEdges(e,i,s){var r=e.OutIdx>=0,n=i.OutIdx>=0;if(!t.use_lines||0!==e.WindDelta&&0!==i.WindDelta){if(e.PolyTyp===i.PolyTyp)if(this.IsEvenOddFillType(e)){var o=e.WindCnt;e.WindCnt=i.WindCnt,i.WindCnt=o}else e.WindCnt+i.WindDelta===0?e.WindCnt=-e.WindCnt:e.WindCnt+=i.WindDelta,i.WindCnt-e.WindDelta==0?i.WindCnt=-i.WindCnt:i.WindCnt-=e.WindDelta;else this.IsEvenOddFillType(i)?e.WindCnt2=0===e.WindCnt2?1:0:e.WindCnt2+=i.WindDelta,this.IsEvenOddFillType(e)?i.WindCnt2=0===i.WindCnt2?1:0:i.WindCnt2-=e.WindDelta;var a,l,h,u,c,d;switch(0===e.PolyTyp?(a=this.m_SubjFillType,h=this.m_ClipFillType):(a=this.m_ClipFillType,h=this.m_SubjFillType),0===i.PolyTyp?(l=this.m_SubjFillType,u=this.m_ClipFillType):(l=this.m_ClipFillType,u=this.m_SubjFillType),a){case 2:c=e.WindCnt;break;case 3:c=-e.WindCnt;break;default:c=Math.abs(e.WindCnt)}switch(l){case 2:d=i.WindCnt;break;case 3:d=-i.WindCnt;break;default:d=Math.abs(i.WindCnt)}if(r&&n)0!==c&&1!==c||0!==d&&1!==d||e.PolyTyp!==i.PolyTyp&&3!==this.m_ClipType?this.AddLocalMaxPoly(e,i,s):(this.AddOutPt(e,s),this.AddOutPt(i,s),t.Clipper.SwapSides(e,i),t.Clipper.SwapPolyIndexes(e,i));else if(r)0!==d&&1!==d||(this.AddOutPt(e,s),t.Clipper.SwapSides(e,i),t.Clipper.SwapPolyIndexes(e,i));else if(n)0!==c&&1!==c||(this.AddOutPt(i,s),t.Clipper.SwapSides(e,i),t.Clipper.SwapPolyIndexes(e,i));else if(!(0!==c&&1!==c||0!==d&&1!==d)){var p,f;switch(h){case 2:p=e.WindCnt2;break;case 3:p=-e.WindCnt2;break;default:p=Math.abs(e.WindCnt2)}switch(u){case 2:f=i.WindCnt2;break;case 3:f=-i.WindCnt2;break;default:f=Math.abs(i.WindCnt2)}if(e.PolyTyp!==i.PolyTyp)this.AddLocalMinPoly(e,i,s);else if(1===c&&1===d)switch(this.m_ClipType){case 0:p>0&&f>0&&this.AddLocalMinPoly(e,i,s);break;case 1:p<=0&&f<=0&&this.AddLocalMinPoly(e,i,s);break;case 2:(1===e.PolyTyp&&p>0&&f>0||0===e.PolyTyp&&p<=0&&f<=0)&&this.AddLocalMinPoly(e,i,s);break;case 3:this.AddLocalMinPoly(e,i,s)}else t.Clipper.SwapSides(e,i)}}else{if(0===e.WindDelta&&0===i.WindDelta)return;e.PolyTyp===i.PolyTyp&&e.WindDelta!==i.WindDelta&&1===this.m_ClipType?0===e.WindDelta?n&&(this.AddOutPt(e,s),r&&(e.OutIdx=-1)):r&&(this.AddOutPt(i,s),n&&(i.OutIdx=-1)):e.PolyTyp!==i.PolyTyp&&(0!==e.WindDelta||1!==Math.abs(i.WindCnt)||1===this.m_ClipType&&0!==i.WindCnt2?0!==i.WindDelta||1!==Math.abs(e.WindCnt)||1===this.m_ClipType&&0!==e.WindCnt2||(this.AddOutPt(i,s),n&&(i.OutIdx=-1)):(this.AddOutPt(e,s),r&&(e.OutIdx=-1)))}}DeleteFromSEL(t){var e=t.PrevInSEL,i=t.NextInSEL;null===e&&null===i&&t!==this.m_SortedEdges||(null!==e?e.NextInSEL=i:this.m_SortedEdges=i,null!==i&&(i.PrevInSEL=e),t.NextInSEL=null,t.PrevInSEL=null)}ProcessHorizontals(){for(var t={};this.PopEdgeFromSEL(t);)this.ProcessHorizontal(t.v)}GetHorzDirection(t,e){t.Bot.X<t.Top.X?(e.Left=t.Bot.X,e.Right=t.Top.X,e.Dir=1):(e.Left=t.Top.X,e.Right=t.Bot.X,e.Dir=0)}ProcessHorizontal(e){var i={Dir:null,Left:null,Right:null};this.GetHorzDirection(e,i);for(var s=i.Dir,r=i.Left,n=i.Right,o=0===e.WindDelta,a=e,l=null;null!==a.NextInLML&&t.ClipperBase.IsHorizontal(a.NextInLML);)a=a.NextInLML;null===a.NextInLML&&(l=this.GetMaximaPair(a));var h=this.m_Maxima;if(null!==h)if(1===s){for(;null!==h&&h.X<=e.Bot.X;)h=h.Next;null!==h&&h.X>=a.Top.X&&(h=null)}else{for(;null!==h.Next&&h.Next.X<e.Bot.X;)h=h.Next;h.X<=a.Top.X&&(h=null)}for(var u=null;;){for(var c=e===a,d=this.GetNextInAEL(e,s);null!==d;){if(null!==h)if(1===s)for(;null!==h&&h.X<d.Curr.X;)e.OutIdx>=0&&!o&&this.AddOutPt(e,new t.FPoint(h.X,e.Bot.Y)),h=h.Next;else for(;null!==h&&h.X>d.Curr.X;)e.OutIdx>=0&&!o&&this.AddOutPt(e,new t.FPoint(h.X,e.Bot.Y)),h=h.Prev;if(1===s&&d.Curr.X>n||0===s&&d.Curr.X<r)break;if(d.Curr.X===e.Top.X&&null!==e.NextInLML&&d.Dx<e.NextInLML.Dx)break;if(e.OutIdx>=0&&!o){u=this.AddOutPt(e,d.Curr);for(var p=this.m_SortedEdges;null!==p;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(e.Bot.X,e.Top.X,p.Bot.X,p.Top.X)){var f=this.GetLastOutPt(p);this.AddJoin(f,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,e.Bot)}if(d===l&&c)return e.OutIdx>=0&&this.AddLocalMaxPoly(e,l,e.Top),this.DeleteFromAEL(e),void this.DeleteFromAEL(l);if(1===s){var m=new t.FPoint(d.Curr.X,e.Curr.Y);this.IntersectEdges(e,d,m)}else{m=new t.FPoint(d.Curr.X,e.Curr.Y);this.IntersectEdges(d,e,m)}var g=this.GetNextInAEL(d,s);this.SwapPositionsInAEL(e,d),d=g}if(null===e.NextInLML||!t.ClipperBase.IsHorizontal(e.NextInLML))break;(e=this.UpdateEdgeIntoAEL(e)).OutIdx>=0&&this.AddOutPt(e,e.Bot),i={Dir:s,Left:r,Right:n},this.GetHorzDirection(e,i),s=i.Dir,r=i.Left,n=i.Right}if(e.OutIdx>=0&&null===u){u=this.GetLastOutPt(e);for(p=this.m_SortedEdges;null!==p;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(e.Bot.X,e.Top.X,p.Bot.X,p.Top.X)){f=this.GetLastOutPt(p);this.AddJoin(f,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,e.Top)}if(null!==e.NextInLML)if(e.OutIdx>=0){if(u=this.AddOutPt(e,e.Top),0===(e=this.UpdateEdgeIntoAEL(e)).WindDelta)return;var y=e.PrevInAEL;g=e.NextInAEL;if(null!==y&&y.Curr.X===e.Bot.X&&y.Curr.Y===e.Bot.Y&&0===y.WindDelta&&y.OutIdx>=0&&y.Curr.Y>y.Top.Y&&t.ClipperBase.SlopesEqual3(e,y)){let t=this.AddOutPt(y,e.Bot);this.AddJoin(u,t,e.Top)}else if(null!==g&&g.Curr.X===e.Bot.X&&g.Curr.Y===e.Bot.Y&&0!==g.WindDelta&&g.OutIdx>=0&&g.Curr.Y>g.Top.Y&&t.ClipperBase.SlopesEqual3(e,g)){let t=this.AddOutPt(g,e.Bot);this.AddJoin(u,t,e.Top)}}else e=this.UpdateEdgeIntoAEL(e);else e.OutIdx>=0&&this.AddOutPt(e,e.Top),this.DeleteFromAEL(e)}GetNextInAEL(t,e){return 1===e?t.NextInAEL:t.PrevInAEL}IsMinima(t){return null!==t&&t.Prev.NextInLML!==t&&t.Next.NextInLML!==t}IsMaxima(t,e){return null!==t&&t.Top.Y===e&&null===t.NextInLML}IsIntermediate(t,e){return t.Top.Y===e&&null!==t.NextInLML}GetMaximaPair(e){return t.FPoint.op_Equality(e.Next.Top,e.Top)&&null===e.Next.NextInLML?e.Next:t.FPoint.op_Equality(e.Prev.Top,e.Top)&&null===e.Prev.NextInLML?e.Prev:null}GetMaximaPairEx(e){var i=this.GetMaximaPair(e);return null===i||i.OutIdx===t.ClipperBase.Skip||i.NextInAEL===i.PrevInAEL&&!t.ClipperBase.IsHorizontal(i)?null:i}ProcessIntersections(e){if(null===this.m_ActiveEdges)return!0;try{if(this.BuildIntersectList(e),0===this.m_IntersectList.length)return!0;if(1!==this.m_IntersectList.length&&!this.FixupIntersectionOrder())return!1;this.ProcessIntersectList()}catch(i){this.m_SortedEdges=null,this.m_IntersectList.length=0,t.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0}BuildIntersectList(e){if(null!==this.m_ActiveEdges){var i=this.m_ActiveEdges;for(this.m_SortedEdges=i;null!==i;)i.PrevInSEL=i.PrevInAEL,i.NextInSEL=i.NextInAEL,i.Curr.X=t.Clipper.TopX(i,e),i=i.NextInAEL;for(var s=!0;s&&null!==this.m_SortedEdges;){for(s=!1,i=this.m_SortedEdges;null!==i.NextInSEL;){var r=i.NextInSEL,n=new t.FPoint;if(i.Curr.X>r.Curr.X){this.IntersectPoint(i,r,n),n.Y<e&&(n=new t.FPoint(t.Clipper.TopX(i,e),e));var o=new t.IntersectNode;o.Edge1=i,o.Edge2=r,o.Pt.X=n.X,o.Pt.Y=n.Y,this.m_IntersectList.push(o),this.SwapPositionsInSEL(i,r),s=!0}else i=r}if(null===i.PrevInSEL)break;i.PrevInSEL.NextInSEL=null}this.m_SortedEdges=null}}EdgesAdjacent(t){return t.Edge1.NextInSEL===t.Edge2||t.Edge1.PrevInSEL===t.Edge2}static IntersectNodeSort(t,e){return e.Pt.Y-t.Pt.Y}FixupIntersectionOrder(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var t=this.m_IntersectList.length,e=0;e<t;e++){if(!this.EdgesAdjacent(this.m_IntersectList[e])){for(var i=e+1;i<t&&!this.EdgesAdjacent(this.m_IntersectList[i]);)i++;if(i===t)return!1;var s=this.m_IntersectList[e];this.m_IntersectList[e]=this.m_IntersectList[i],this.m_IntersectList[i]=s}this.SwapPositionsInSEL(this.m_IntersectList[e].Edge1,this.m_IntersectList[e].Edge2)}return!0}ProcessIntersectList(){for(var t=0,e=this.m_IntersectList.length;t<e;t++){var i=this.m_IntersectList[t];this.IntersectEdges(i.Edge1,i.Edge2,i.Pt),this.SwapPositionsInAEL(i.Edge1,i.Edge2)}this.m_IntersectList.length=0}static TopX(t,e){return e===t.Top.Y?t.Top.X:t.Bot.X+t.Dx*(e-t.Bot.Y)}IntersectPoint(e,i,s){var r,n;if(s.X=0,s.Y=0,e.Dx===i.Dx)return s.Y=e.Curr.Y,void(s.X=t.Clipper.TopX(e,s.Y));if(0===e.Delta.X)s.X=e.Bot.X,t.ClipperBase.IsHorizontal(i)?s.Y=i.Bot.Y:(n=i.Bot.Y-i.Bot.X/i.Dx,s.Y=s.X/i.Dx+n);else if(0===i.Delta.X)s.X=i.Bot.X,t.ClipperBase.IsHorizontal(e)?s.Y=e.Bot.Y:(r=e.Bot.Y-e.Bot.X/e.Dx,s.Y=s.X/e.Dx+r);else{r=e.Bot.X-e.Bot.Y*e.Dx;var o=((n=i.Bot.X-i.Bot.Y*i.Dx)-r)/(e.Dx-i.Dx);s.Y=o,Math.abs(e.Dx)<Math.abs(i.Dx)?s.X=e.Dx*o+r:s.X=i.Dx*o+n}if(s.Y<e.Top.Y||s.Y<i.Top.Y){if(e.Top.Y>i.Top.Y)return s.Y=e.Top.Y,s.X=t.Clipper.TopX(i,e.Top.Y),s.X<e.Top.X;s.Y=i.Top.Y,Math.abs(e.Dx)<Math.abs(i.Dx)?s.X=t.Clipper.TopX(e,s.Y):s.X=t.Clipper.TopX(i,s.Y)}s.Y>e.Curr.Y&&(s.Y=e.Curr.Y,Math.abs(e.Dx)>Math.abs(i.Dx)?s.X=t.Clipper.TopX(i,s.Y):s.X=t.Clipper.TopX(e,s.Y))}ProcessEdgesAtTopOfScanbeam(e){for(var i=this.m_ActiveEdges;null!==i;){var s=this.IsMaxima(i,e);if(s){var r=this.GetMaximaPairEx(i);s=null===r||!t.ClipperBase.IsHorizontal(r)}if(s){this.StrictlySimple&&this.InsertMaxima(i.Top.X);var n=i.PrevInAEL;this.DoMaxima(i),i=null===n?this.m_ActiveEdges:n.NextInAEL}else{if(this.IsIntermediate(i,e)&&t.ClipperBase.IsHorizontal(i.NextInLML)?((i=this.UpdateEdgeIntoAEL(i)).OutIdx>=0&&this.AddOutPt(i,i.Bot),this.AddEdgeToSEL(i)):(i.Curr.X=t.Clipper.TopX(i,e),i.Curr.Y=e),this.StrictlySimple){n=i.PrevInAEL;if(i.OutIdx>=0&&0!==i.WindDelta&&null!==n&&n.OutIdx>=0&&n.Curr.X===i.Curr.X&&0!==n.WindDelta){var o=new t.FPoint(i.Curr),a=this.AddOutPt(n,o),l=this.AddOutPt(i,o);this.AddJoin(a,l,o)}}i=i.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,i=this.m_ActiveEdges;null!==i;){if(this.IsIntermediate(i,e)){a=null;i.OutIdx>=0&&(a=this.AddOutPt(i,i.Top));n=(i=this.UpdateEdgeIntoAEL(i)).PrevInAEL;var h=i.NextInAEL;if(null!==n&&n.Curr.X===i.Bot.X&&n.Curr.Y===i.Bot.Y&&null!==a&&n.OutIdx>=0&&n.Curr.Y===n.Top.Y&&t.ClipperBase.SlopesEqual5(i.Curr,i.Top,n.Curr,n.Top)&&0!==i.WindDelta&&0!==n.WindDelta){l=this.AddOutPt(n,i.Bot);this.AddJoin(a,l,i.Top)}else if(null!==h&&h.Curr.X===i.Bot.X&&h.Curr.Y===i.Bot.Y&&null!==a&&h.OutIdx>=0&&h.Curr.Y===h.Top.Y&&t.ClipperBase.SlopesEqual5(i.Curr,i.Top,h.Curr,h.Top)&&0!==i.WindDelta&&0!==h.WindDelta){l=this.AddOutPt(h,i.Bot);this.AddJoin(a,l,i.Top)}}i=i.NextInAEL}}DoMaxima(e){var i=this.GetMaximaPairEx(e);if(null===i)return e.OutIdx>=0&&this.AddOutPt(e,e.Top),void this.DeleteFromAEL(e);for(var s=e.NextInAEL;null!==s&&s!==i;)this.IntersectEdges(e,s,e.Top),this.SwapPositionsInAEL(e,s),s=e.NextInAEL;-1===e.OutIdx&&-1===i.OutIdx?(this.DeleteFromAEL(e),this.DeleteFromAEL(i)):e.OutIdx>=0&&i.OutIdx>=0?(e.OutIdx>=0&&this.AddLocalMaxPoly(e,i,e.Top),this.DeleteFromAEL(e),this.DeleteFromAEL(i)):t.use_lines&&0===e.WindDelta?(e.OutIdx>=0&&(this.AddOutPt(e,e.Top),e.OutIdx=t.ClipperBase.Unassigned),this.DeleteFromAEL(e),i.OutIdx>=0&&(this.AddOutPt(i,e.Top),i.OutIdx=t.ClipperBase.Unassigned),this.DeleteFromAEL(i)):t.Error("DoMaxima error")}static ReversePaths(t){for(var e=0,i=t.length;e<i;e++)t[e].reverse()}static Orientation(e){return t.Clipper.Area(e)>=0}PointCount(t){if(null===t)return 0;var e=0,i=t;do{e++,i=i.Next}while(i!==t);return e}BuildResult(e){t.Clear(e);for(var i=0,s=this.m_PolyOuts.length;i<s;i++){var r=this.m_PolyOuts[i];if(null!==r.Pts){var n=r.Pts.Prev,o=this.PointCount(n);if(!(o<2)){for(var a=new Array(o),l=0;l<o;l++)a[l]=n.Pt,n=n.Prev;e.push(a)}}}}BuildResult2(e){e.Clear();for(var i=0,s=this.m_PolyOuts.length;i<s;i++){var r=this.m_PolyOuts[i],n=this.PointCount(r.Pts);if(!(r.IsOpen&&n<2||!r.IsOpen&&n<3)){this.FixHoleLinkage(r);var o=new t.PolyNode;e.m_AllPolys.push(o),r.PolyNode=o,o.m_polygon.length=n;for(var a=r.Pts.Prev,l=0;l<n;l++)o.m_polygon[l]=a.Pt,a=a.Prev}}for(i=0,s=this.m_PolyOuts.length;i<s;i++){null!==(r=this.m_PolyOuts[i]).PolyNode&&(r.IsOpen?(r.PolyNode.IsOpen=!0,e.AddChild(r.PolyNode)):null!==r.FirstLeft&&null!==r.FirstLeft.PolyNode?r.FirstLeft.PolyNode.AddChild(r.PolyNode):e.AddChild(r.PolyNode))}}FixupOutPolyline(e){for(var i=e.Pts,s=i.Prev;i!==s;)if(i=i.Next,t.FPoint.op_Equality(i.Pt,i.Prev.Pt)){i===s&&(s=i.Prev);var r=i.Prev;r.Next=i.Next,i.Next.Prev=r,i=r}i===i.Prev&&(e.Pts=null)}FixupOutPolygon(e){var i=null;e.BottomPt=null;for(var s=e.Pts,r=this.PreserveCollinear||this.StrictlySimple;;){if(s.Prev===s||s.Prev===s.Next)return void(e.Pts=null);if(t.FPoint.op_Equality(s.Pt,s.Next.Pt)||t.FPoint.op_Equality(s.Pt,s.Prev.Pt)||t.ClipperBase.SlopesEqual4(s.Prev.Pt,s.Pt,s.Next.Pt)&&(!r||!this.Pt2IsBetweenPt1AndPt3(s.Prev.Pt,s.Pt,s.Next.Pt)))i=null,s.Prev.Next=s.Next,s.Next.Prev=s.Prev,s=s.Prev;else{if(s===i)break;null===i&&(i=s),s=s.Next}}e.Pts=s}DupOutPt(e,i){var s=new t.OutPt;return s.Pt.X=e.Pt.X,s.Pt.Y=e.Pt.Y,s.Idx=e.Idx,i?(s.Next=e.Next,s.Prev=e,e.Next.Prev=s,e.Next=s):(s.Prev=e.Prev,s.Next=e,e.Prev.Next=s,e.Prev=s),s}GetOverlap(t,e,i,s,r){return t<e?i<s?(r.Left=Math.max(t,i),r.Right=Math.min(e,s)):(r.Left=Math.max(t,s),r.Right=Math.min(e,i)):i<s?(r.Left=Math.max(e,i),r.Right=Math.min(t,s)):(r.Left=Math.max(e,s),r.Right=Math.min(t,i)),r.Left<r.Right}JoinHorz(e,i,s,r,n,o){var a=e.Pt.X>i.Pt.X?0:1,l=s.Pt.X>r.Pt.X?0:1;if(a===l)return!1;if(1===a){for(;e.Next.Pt.X<=n.X&&e.Next.Pt.X>=e.Pt.X&&e.Next.Pt.Y===n.Y;)e=e.Next;o&&e.Pt.X!==n.X&&(e=e.Next),i=this.DupOutPt(e,!o),t.FPoint.op_Inequality(i.Pt,n)&&((e=i).Pt.X=n.X,e.Pt.Y=n.Y,i=this.DupOutPt(e,!o))}else{for(;e.Next.Pt.X>=n.X&&e.Next.Pt.X<=e.Pt.X&&e.Next.Pt.Y===n.Y;)e=e.Next;o||e.Pt.X===n.X||(e=e.Next),i=this.DupOutPt(e,o),t.FPoint.op_Inequality(i.Pt,n)&&((e=i).Pt.X=n.X,e.Pt.Y=n.Y,i=this.DupOutPt(e,o))}if(1===l){for(;s.Next.Pt.X<=n.X&&s.Next.Pt.X>=s.Pt.X&&s.Next.Pt.Y===n.Y;)s=s.Next;o&&s.Pt.X!==n.X&&(s=s.Next),r=this.DupOutPt(s,!o),t.FPoint.op_Inequality(r.Pt,n)&&((s=r).Pt.X=n.X,s.Pt.Y=n.Y,r=this.DupOutPt(s,!o))}else{for(;s.Next.Pt.X>=n.X&&s.Next.Pt.X<=s.Pt.X&&s.Next.Pt.Y===n.Y;)s=s.Next;o||s.Pt.X===n.X||(s=s.Next),r=this.DupOutPt(s,o),t.FPoint.op_Inequality(r.Pt,n)&&((s=r).Pt.X=n.X,s.Pt.Y=n.Y,r=this.DupOutPt(s,o))}return 1===a===o?(e.Prev=s,s.Next=e,i.Next=r,r.Prev=i):(e.Next=s,s.Prev=e,i.Prev=r,r.Next=i),!0}JoinPoints(e,i,s){var r=e.OutPt1,n=new t.OutPt,o=e.OutPt2,a=new t.OutPt,l=e.OutPt1.Pt.Y===e.OffPt.Y;if(l&&t.FPoint.op_Equality(e.OffPt,e.OutPt1.Pt)&&t.FPoint.op_Equality(e.OffPt,e.OutPt2.Pt)){if(i!==s)return!1;for(n=e.OutPt1.Next;n!==r&&t.FPoint.op_Equality(n.Pt,e.OffPt);)n=n.Next;var h=n.Pt.Y>e.OffPt.Y;for(a=e.OutPt2.Next;a!==o&&t.FPoint.op_Equality(a.Pt,e.OffPt);)a=a.Next;return h!==a.Pt.Y>e.OffPt.Y&&(h?(n=this.DupOutPt(r,!1),a=this.DupOutPt(o,!0),r.Prev=o,o.Next=r,n.Next=a,a.Prev=n,e.OutPt1=r,e.OutPt2=n,!0):(n=this.DupOutPt(r,!0),a=this.DupOutPt(o,!1),r.Next=o,o.Prev=r,n.Prev=a,a.Next=n,e.OutPt1=r,e.OutPt2=n,!0))}if(l){for(n=r;r.Prev.Pt.Y===r.Pt.Y&&r.Prev!==n&&r.Prev!==o;)r=r.Prev;for(;n.Next.Pt.Y===n.Pt.Y&&n.Next!==r&&n.Next!==o;)n=n.Next;if(n.Next===r||n.Next===o)return!1;for(a=o;o.Prev.Pt.Y===o.Pt.Y&&o.Prev!==a&&o.Prev!==n;)o=o.Prev;for(;a.Next.Pt.Y===a.Pt.Y&&a.Next!==o&&a.Next!==r;)a=a.Next;if(a.Next===o||a.Next===r)return!1;var u={Left:null,Right:null};if(!this.GetOverlap(r.Pt.X,n.Pt.X,o.Pt.X,a.Pt.X,u))return!1;var c,d=u.Left,p=u.Right,f=new t.FPoint;return r.Pt.X>=d&&r.Pt.X<=p?(f.X=r.Pt.X,f.Y=r.Pt.Y,c=r.Pt.X>n.Pt.X):o.Pt.X>=d&&o.Pt.X<=p?(f.X=o.Pt.X,f.Y=o.Pt.Y,c=o.Pt.X>a.Pt.X):n.Pt.X>=d&&n.Pt.X<=p?(f.X=n.Pt.X,f.Y=n.Pt.Y,c=n.Pt.X>r.Pt.X):(f.X=a.Pt.X,f.Y=a.Pt.Y,c=a.Pt.X>o.Pt.X),e.OutPt1=r,e.OutPt2=o,this.JoinHorz(r,n,o,a,f,c)}for(n=r.Next;t.FPoint.op_Equality(n.Pt,r.Pt)&&n!==r;)n=n.Next;var m=n.Pt.Y>r.Pt.Y||!t.ClipperBase.SlopesEqual4(r.Pt,n.Pt,e.OffPt);if(m){for(n=r.Prev;t.FPoint.op_Equality(n.Pt,r.Pt)&&n!==r;)n=n.Prev;if(n.Pt.Y>r.Pt.Y||!t.ClipperBase.SlopesEqual4(r.Pt,n.Pt,e.OffPt))return!1}for(a=o.Next;t.FPoint.op_Equality(a.Pt,o.Pt)&&a!==o;)a=a.Next;var g=a.Pt.Y>o.Pt.Y||!t.ClipperBase.SlopesEqual4(o.Pt,a.Pt,e.OffPt);if(g){for(a=o.Prev;t.FPoint.op_Equality(a.Pt,o.Pt)&&a!==o;)a=a.Prev;if(a.Pt.Y>o.Pt.Y||!t.ClipperBase.SlopesEqual4(o.Pt,a.Pt,e.OffPt))return!1}return n!==r&&a!==o&&n!==a&&(i!==s||m!==g)&&(m?(n=this.DupOutPt(r,!1),a=this.DupOutPt(o,!0),r.Prev=o,o.Next=r,n.Next=a,a.Prev=n,e.OutPt1=r,e.OutPt2=n,!0):(n=this.DupOutPt(r,!0),a=this.DupOutPt(o,!1),r.Next=o,o.Prev=r,n.Prev=a,a.Next=n,e.OutPt1=r,e.OutPt2=n,!0))}static GetBounds(e){for(var i=0,s=e.length;i<s&&0===e[i].length;)i++;if(i===s)return new t.FRect(0,0,0,0);var r=new t.FRect;for(r.left=e[i][0].X,r.right=r.left,r.top=e[i][0].Y,r.bottom=r.top;i<s;i++)for(var n=0,o=e[i].length;n<o;n++)e[i][n].X<r.left?r.left=e[i][n].X:e[i][n].X>r.right&&(r.right=e[i][n].X),e[i][n].Y<r.top?r.top=e[i][n].Y:e[i][n].Y>r.bottom&&(r.bottom=e[i][n].Y);return r}GetBounds2(e){var i=e,s=new t.FRect;for(s.left=e.Pt.X,s.right=e.Pt.X,s.top=e.Pt.Y,s.bottom=e.Pt.Y,e=e.Next;e!==i;)e.Pt.X<s.left&&(s.left=e.Pt.X),e.Pt.X>s.right&&(s.right=e.Pt.X),e.Pt.Y<s.top&&(s.top=e.Pt.Y),e.Pt.Y>s.bottom&&(s.bottom=e.Pt.Y),e=e.Next;return s}static PointInPolygon(t,e){var i=0,s=e.length;if(s<3)return 0;for(var r=e[0],n=1;n<=s;++n){var o=n===s?e[0]:e[n];if(o.Y===t.Y&&(o.X===t.X||r.Y===t.Y&&o.X>t.X==r.X<t.X))return-1;if(r.Y<t.Y!=o.Y<t.Y)if(r.X>=t.X)if(o.X>t.X)i=1-i;else{if(0===(a=(r.X-t.X)*(o.Y-t.Y)-(o.X-t.X)*(r.Y-t.Y)))return-1;a>0==o.Y>r.Y&&(i=1-i)}else if(o.X>t.X){var a;if(0===(a=(r.X-t.X)*(o.Y-t.Y)-(o.X-t.X)*(r.Y-t.Y)))return-1;a>0==o.Y>r.Y&&(i=1-i)}r=o}return i}PointInPolygon(t,e){var i=0,s=e,r=t.X,n=t.Y,o=e.Pt.X,a=e.Pt.Y;do{var l=(e=e.Next).Pt.X,h=e.Pt.Y;if(h===n&&(l===r||a===n&&l>r==o<r))return-1;if(a<n!=h<n)if(o>=r)if(l>r)i=1-i;else{if(0===(u=(o-r)*(h-n)-(l-r)*(a-n)))return-1;u>0==h>a&&(i=1-i)}else if(l>r){var u;if(0===(u=(o-r)*(h-n)-(l-r)*(a-n)))return-1;u>0==h>a&&(i=1-i)}o=l,a=h}while(s!==e);return i}Poly2ContainsPoly1(t,e){var i=t;do{var s=this.PointInPolygon(i.Pt,e);if(s>=0)return s>0;i=i.Next}while(i!==t);return!0}FixupFirstLefts1(e,i){for(var s,r,n=0,o=this.m_PolyOuts.length;n<o;n++)s=this.m_PolyOuts[n],r=t.Clipper.ParseFirstLeft(s.FirstLeft),null!==s.Pts&&r===e&&this.Poly2ContainsPoly1(s.Pts,i.Pts)&&(s.FirstLeft=i)}FixupFirstLefts2(e,i){for(var s,r,n=i.FirstLeft,o=0,a=this.m_PolyOuts.length;o<a;o++)null!==(s=this.m_PolyOuts[o]).Pts&&s!==i&&s!==e&&((r=t.Clipper.ParseFirstLeft(s.FirstLeft))!==n&&r!==e&&r!==i||(this.Poly2ContainsPoly1(s.Pts,e.Pts)?s.FirstLeft=e:this.Poly2ContainsPoly1(s.Pts,i.Pts)?s.FirstLeft=i:s.FirstLeft!==e&&s.FirstLeft!==i||(s.FirstLeft=n)))}FixupFirstLefts3(e,i){for(var s,r,n=0,o=this.m_PolyOuts.length;n<o;n++)s=this.m_PolyOuts[n],r=t.Clipper.ParseFirstLeft(s.FirstLeft),null!==s.Pts&&r===e&&(s.FirstLeft=i)}static ParseFirstLeft(t){for(;null!==t&&null===t.Pts;)t=t.FirstLeft;return t}JoinCommonEdges(){for(var t=0,e=this.m_Joins.length;t<e;t++){var i,s=this.m_Joins[t],r=this.GetOutRec(s.OutPt1.Idx),n=this.GetOutRec(s.OutPt2.Idx);if(null!==r.Pts&&null!==n.Pts)if(!r.IsOpen&&!n.IsOpen)i=r===n?r:this.OutRec1RightOfOutRec2(r,n)?n:this.OutRec1RightOfOutRec2(n,r)?r:this.GetLowermostRec(r,n),this.JoinPoints(s,r,n)&&(r===n?(r.Pts=s.OutPt1,r.BottomPt=null,(n=this.CreateOutRec()).Pts=s.OutPt2,this.UpdateOutPtIdxs(n),this.Poly2ContainsPoly1(n.Pts,r.Pts)?(n.IsHole=!r.IsHole,n.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(n,r),(n.IsHole^this.ReverseSolution)==this.Area$1(n)>0&&this.ReversePolyPtLinks(n.Pts)):this.Poly2ContainsPoly1(r.Pts,n.Pts)?(n.IsHole=r.IsHole,r.IsHole=!n.IsHole,n.FirstLeft=r.FirstLeft,r.FirstLeft=n,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,n),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(n.IsHole=r.IsHole,n.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,n))):(n.Pts=null,n.BottomPt=null,n.Idx=r.Idx,r.IsHole=i.IsHole,i===n&&(r.FirstLeft=n.FirstLeft),n.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(n,r)))}}UpdateOutPtIdxs(t){var e=t.Pts;do{e.Idx=t.Idx,e=e.Prev}while(e!==t.Pts)}DoSimplePolygons(){for(var e=0;e<this.m_PolyOuts.length;){var i=this.m_PolyOuts[e++],s=i.Pts;if(null!==s&&!i.IsOpen)do{for(var r=s.Next;r!==i.Pts;){if(t.FPoint.op_Equality(s.Pt,r.Pt)&&r.Next!==s&&r.Prev!==s){var n=s.Prev,o=r.Prev;s.Prev=o,o.Next=s,r.Prev=n,n.Next=r,i.Pts=s;var a=this.CreateOutRec();a.Pts=r,this.UpdateOutPtIdxs(a),this.Poly2ContainsPoly1(a.Pts,i.Pts)?(a.IsHole=!i.IsHole,a.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(a,i)):this.Poly2ContainsPoly1(i.Pts,a.Pts)?(a.IsHole=i.IsHole,i.IsHole=!a.IsHole,a.FirstLeft=i.FirstLeft,i.FirstLeft=a,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,a)):(a.IsHole=i.IsHole,a.FirstLeft=i.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(i,a)),r=s}r=r.Next}s=s.Next}while(s!==i.Pts)}}static Area(t){if(!Array.isArray(t))return 0;var e=t.length;if(e<3)return 0;for(var i=0,s=0,r=e-1;s<e;++s)i+=(t[r].X+t[s].X)*(t[r].Y-t[s].Y),r=s;return.5*-i}Area(t){var e=t;if(null===t)return 0;var i=0;do{i+=(t.Prev.Pt.X+t.Pt.X)*(t.Prev.Pt.Y-t.Pt.Y),t=t.Next}while(t!==e);return.5*i}Area$1(t){return this.Area(t.Pts)}static SimplifyPolygon(e,i){var s=new Array,r=new t.Clipper(0);return r.StrictlySimple=!0,r.AddPath(e,0,!0),r.Execute(1,s,i,i),s}static SimplifyPolygons(e,i){void 0===i&&(i=0);var s=new Array,r=new t.Clipper(0);return r.StrictlySimple=!0,r.AddPaths(e,0,!0),r.Execute(1,s,i,i),s}static DistanceSqrd(t,e){var i=t.X-e.X,s=t.Y-e.Y;return i*i+s*s}static DistanceFromLineSqrd(t,e,i){var s=e.Y-i.Y,r=i.X-e.X,n=s*e.X+r*e.Y;return(n=s*t.X+r*t.Y-n)*n/(s*s+r*r)}static SlopesNearCollinear(e,i,s,r){return Math.abs(e.X-i.X)>Math.abs(e.Y-i.Y)?e.X>i.X==e.X<s.X?t.Clipper.DistanceFromLineSqrd(e,i,s)<r:i.X>e.X==i.X<s.X?t.Clipper.DistanceFromLineSqrd(i,e,s)<r:t.Clipper.DistanceFromLineSqrd(s,e,i)<r:e.Y>i.Y==e.Y<s.Y?t.Clipper.DistanceFromLineSqrd(e,i,s)<r:i.Y>e.Y==i.Y<s.Y?t.Clipper.DistanceFromLineSqrd(i,e,s)<r:t.Clipper.DistanceFromLineSqrd(s,e,i)<r}static PointsAreClose(t,e,i){var s=t.X-e.X,r=t.Y-e.Y;return s*s+r*r<=i}static ExcludeOp(t){var e=t.Prev;return e.Next=t.Next,t.Next.Prev=e,e.Idx=0,e}static CleanPolygon(e,i){void 0===i&&(i=1.415);var s=e.length;if(0===s)return new Array;for(var r=new Array(s),n=0;n<s;++n)r[n]=new t.OutPt;for(n=0;n<s;++n)r[n].Pt=e[n],r[n].Next=r[(n+1)%s],r[n].Next.Prev=r[n],r[n].Idx=0;for(var o=i*i,a=r[0];0===a.Idx&&a.Next!==a.Prev;)t.Clipper.PointsAreClose(a.Pt,a.Prev.Pt,o)?(a=t.Clipper.ExcludeOp(a),s--):t.Clipper.PointsAreClose(a.Prev.Pt,a.Next.Pt,o)?(t.Clipper.ExcludeOp(a.Next),a=t.Clipper.ExcludeOp(a),s-=2):t.Clipper.SlopesNearCollinear(a.Prev.Pt,a.Pt,a.Next.Pt,o)?(a=t.Clipper.ExcludeOp(a),s--):(a.Idx=1,a=a.Next);s<3&&(s=0);var l=new Array(s);for(n=0;n<s;++n)l[n]=new t.FPoint(a.Pt),a=a.Next;return r=null,l}static CleanPolygons(e,i){for(var s=new Array(e.length),r=0,n=e.length;r<n;r++)s[r]=t.Clipper.CleanPolygon(e[r],i);return s}static Minkowski(e,i,s,r){var n=r?1:0,o=e.length,a=i.length,l=new Array;if(s)for(var h=0;h<a;h++){for(var u=new Array(o),c=0,d=e.length,p=e[c];c<d;p=e[++c])u[c]=new t.FPoint(i[h].X+p.X,i[h].Y+p.Y);l.push(u)}else for(h=0;h<a;h++){for(u=new Array(o),c=0,d=e.length,p=e[c];c<d;p=e[++c])u[c]=new t.FPoint(i[h].X-p.X,i[h].Y-p.Y);l.push(u)}var f=new Array;for(h=0;h<a-1+n;h++)for(c=0;c<o;c++){var m=new Array;m.push(l[h%a][c%o]),m.push(l[(h+1)%a][c%o]),m.push(l[(h+1)%a][(c+1)%o]),m.push(l[h%a][(c+1)%o]),t.Clipper.Orientation(m)||m.reverse(),f.push(m)}return f}static MinkowskiSum(e,i,s){if(i[0]instanceof Array){let l=i;for(var r=[],n=(a=new t.Clipper,0);n<l.length;++n){var o=t.Clipper.Minkowski(e,l[n],!0,s);if(a.AddPaths(o,0,!0),s){let i=t.Clipper.TranslatePath(l[n],e[0]);a.AddPath(i,1,!0)}}return a.Execute(1,r,1,1),r}{let r=i,n=t.Clipper.Minkowski(e,r,!0,s);var a;return(a=new t.Clipper).AddPaths(n,0,!0),a.Execute(1,n,1,1),n}}static TranslatePath(e,i){for(var s=[],r=0;r<e.length;r++)s.push(new t.FPoint(e[r].X+i.X,e[r].Y+i.Y));return s}static MinkowskiDiff(e,i){var s=t.Clipper.Minkowski(e,i,!1,!0),r=new t.Clipper;return r.AddPaths(s,0,!0),r.Execute(1,s,1,1),s}static PolyTreeToPaths(e){var i=new Array;return t.Clipper.AddPolyNodeToPaths(e,0,i),i}static AddPolyNodeToPaths(e,i,s){var r=!0;switch(i){case 1:return;case 2:r=!e.IsOpen}e.m_polygon.length>0&&r&&s.push(e.m_polygon);for(var n=0,o=e.Children(),a=o.length,l=o[n];n<a;l=o[++n])t.Clipper.AddPolyNodeToPaths(l,i,s)}static OpenPathsFromPolyTree(t){for(var e=[],i=0,s=t.ChildCount();i<s;i++)t.Children()[i].IsOpen&&e.push(t.Children()[i].m_polygon);return e}static ClosedPathsFromPolyTree(e){var i=[];return t.Clipper.AddPolyNodeToPaths(e,2,i),i}}W(c,"ioReverseSolution",1),W(c,"ioStrictlySimple",2),W(c,"ioPreserveCollinear",4),t.Clipper=c;class d{constructor(e,i){W(this,"m_destPolys",[]),W(this,"m_srcPoly",[]),W(this,"m_destPoly",[]),W(this,"m_normals",new Array),W(this,"m_delta",0),W(this,"m_sinA",0),W(this,"m_sin",0),W(this,"m_cos",0),W(this,"m_miterLim",0),W(this,"m_StepsPerRad",0),W(this,"m_lowest",new t.FPoint),W(this,"m_polyNodes",new t.PolyNode),W(this,"MiterLimit"),W(this,"ArcTolerance"),void 0===e&&(e=2),void 0===i&&(i=t.ClipperOffset.def_arc_tolerance),this.MiterLimit=e,this.ArcTolerance=i,this.m_lowest.X=-1}Clear(){t.Clear(this.m_polyNodes.Children()),this.m_lowest.X=-1}AddPath(e,i,s){var r=e.length-1;if(!(r<0)){var n=new t.PolyNode;if(n.m_jointype=i,n.m_endtype=s,3===s||4===s)for(;r>0&&t.FPoint.op_Equality(e[0],e[r]);)r--;n.m_polygon.push(e[0]);for(var o=0,a=0,l=1;l<=r;l++)t.FPoint.op_Inequality(n.m_polygon[o],e[l])&&(o++,n.m_polygon.push(e[l]),(e[l].Y>n.m_polygon[a].Y||e[l].Y===n.m_polygon[a].Y&&e[l].X<n.m_polygon[a].X)&&(a=o));if(!(4===s&&o<2)&&(this.m_polyNodes.AddChild(n),4===s))if(this.m_lowest.X<0)this.m_lowest=new t.FPoint(this.m_polyNodes.ChildCount()-1,a);else{var h=this.m_polyNodes.Children()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(n.m_polygon[a].Y>h.Y||n.m_polygon[a].Y===h.Y&&n.m_polygon[a].X<h.X)&&(this.m_lowest=new t.FPoint(this.m_polyNodes.ChildCount()-1,a))}}}AddPaths(t,e,i){for(var s=0,r=t.length;s<r;s++)this.AddPath(t[s],e,i)}FixOrientations(){if(this.m_lowest.X>=0&&!t.Clipper.Orientation(this.m_polyNodes.Children()[this.m_lowest.X].m_polygon))for(var e=0;e<this.m_polyNodes.ChildCount();e++){(4===(i=this.m_polyNodes.Children()[e]).m_endtype||3===i.m_endtype&&t.Clipper.Orientation(i.m_polygon))&&i.m_polygon.reverse()}else for(e=0;e<this.m_polyNodes.ChildCount();e++){var i;3!==(i=this.m_polyNodes.Children()[e]).m_endtype||t.Clipper.Orientation(i.m_polygon)||i.m_polygon.reverse()}}static GetUnitNormal(e,i){var s=i.X-e.X,r=i.Y-e.Y;if(0===s&&0===r)return new t.FPoint(0,0);var n=1/Math.sqrt(s*s+r*r);return s*=n,r*=n,new t.FPoint(r,-s)}DoOffset(e){if(this.m_destPolys=new Array,this.m_delta=e,t.ClipperBase.near_zero(e))for(var i=0;i<this.m_polyNodes.ChildCount();i++){4===(n=this.m_polyNodes.Children()[i]).m_endtype&&this.m_destPolys.push(n.m_polygon)}else{var s;this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5,s=this.ArcTolerance<=0?t.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(e)*t.ClipperOffset.def_arc_tolerance?Math.abs(e)*t.ClipperOffset.def_arc_tolerance:this.ArcTolerance;var r=3.14159265358979/Math.acos(1-s/Math.abs(e));this.m_sin=Math.sin(t.ClipperOffset.two_pi/r),this.m_cos=Math.cos(t.ClipperOffset.two_pi/r),this.m_StepsPerRad=r/t.ClipperOffset.two_pi,e<0&&(this.m_sin=-this.m_sin);for(i=0;i<this.m_polyNodes.ChildCount();i++){var n=this.m_polyNodes.Children()[i];this.m_srcPoly=n.m_polygon;var o=this.m_srcPoly.length;if(!(0===o||e<=0&&(o<3||4!==n.m_endtype)))if(this.m_destPoly=new Array,1!==o){this.m_normals.length=0;for(d=0;d<o-1;d++)this.m_normals.push(t.ClipperOffset.GetUnitNormal(this.m_srcPoly[d],this.m_srcPoly[d+1]));if(3===n.m_endtype||4===n.m_endtype?this.m_normals.push(t.ClipperOffset.GetUnitNormal(this.m_srcPoly[o-1],this.m_srcPoly[0])):this.m_normals.push(new t.FPoint(this.m_normals[o-2])),4===n.m_endtype){var a=o-1;for(d=0;d<o;d++)a=this.OffsetPoint(d,a,n.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(3===n.m_endtype){for(a=o-1,d=0;d<o;d++)a=this.OffsetPoint(d,a,n.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;var l=this.m_normals[o-1];for(d=o-1;d>0;d--)this.m_normals[d]=new t.FPoint(-this.m_normals[d-1].X,-this.m_normals[d-1].Y);this.m_normals[0]=new t.FPoint(-l.X,-l.Y),a=0;for(d=o-1;d>=0;d--)a=this.OffsetPoint(d,a,n.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{var h;for(a=0,d=1;d<o-1;++d)a=this.OffsetPoint(d,a,n.m_jointype);if(2===n.m_endtype){d=o-1;h=new t.FPoint(this.m_srcPoly[d].X+this.m_normals[d].X*e,this.m_srcPoly[d].Y+this.m_normals[d].Y*e),this.m_destPoly.push(h),h=new t.FPoint(this.m_srcPoly[d].X-this.m_normals[d].X*e,this.m_srcPoly[d].Y-this.m_normals[d].Y*e),this.m_destPoly.push(h)}else{d=o-1;a=o-2,this.m_sinA=0,this.m_normals[d]=new t.FPoint(-this.m_normals[d].X,-this.m_normals[d].Y),0===n.m_endtype?this.DoSquare(d,a):this.DoRound(d,a)}for(d=o-1;d>0;d--)this.m_normals[d]=new t.FPoint(-this.m_normals[d-1].X,-this.m_normals[d-1].Y);this.m_normals[0]=new t.FPoint(-this.m_normals[1].X,-this.m_normals[1].Y);for(d=(a=o-1)-1;d>0;--d)a=this.OffsetPoint(d,a,n.m_jointype);2===n.m_endtype?(h=new t.FPoint(this.m_srcPoly[0].X-this.m_normals[0].X*e,this.m_srcPoly[0].Y-this.m_normals[0].Y*e),this.m_destPoly.push(h),h=new t.FPoint(this.m_srcPoly[0].X+this.m_normals[0].X*e,this.m_srcPoly[0].Y+this.m_normals[0].Y*e),this.m_destPoly.push(h)):(a=1,this.m_sinA=0,0===n.m_endtype?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}else{if(1===n.m_jointype)for(var u=1,c=0,d=1;d<=r;d++){this.m_destPoly.push(new t.FPoint(this.m_srcPoly[0].X+u*e,this.m_srcPoly[0].Y+c*e));var p=u;u=u*this.m_cos-this.m_sin*c,c=p*this.m_sin+c*this.m_cos}else{u=-1,c=-1;for(var d=0;d<4;++d)this.m_destPoly.push(new t.FPoint(this.m_srcPoly[0].X+u*e,this.m_srcPoly[0].Y+c*e)),u<0?u=1:c<0?c=1:u=-1}this.m_destPolys.push(this.m_destPoly)}}}}Execute(...e){var i=e;if(i[0]instanceof t.PolyTree){o=i[0],a=i[1];if(o.Clear(),this.FixOrientations(),this.DoOffset(a),(n=new t.Clipper(0)).AddPaths(this.m_destPolys,0,!0),a>0)n.Execute(1,o,2,2);else{h=t.Clipper.GetBounds(this.m_destPolys);if((l=[]).push(new t.FPoint(h.left-10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.top-10)),l.push(new t.FPoint(h.left-10,h.top-10)),n.AddPath(l,0,!0),n.ReverseSolution=!0,n.Execute(1,o,3,3),1===o.ChildCount()&&o.Children()[0].ChildCount()>0){var s=o.Children()[0];o.Children()[0]=s.Children()[0],o.Children()[0].m_Parent=o;for(var r=1;r<s.ChildCount();r++)o.AddChild(s.Children()[r])}else o.Clear()}}else{var n,o=i[0],a=i[1];if(t.Clear(o),this.FixOrientations(),this.DoOffset(a),(n=new t.Clipper(0)).AddPaths(this.m_destPolys,0,!0),a>0)n.Execute(1,o,2,2);else{var l,h=t.Clipper.GetBounds(this.m_destPolys);(l=[]).push(new t.FPoint(h.left-10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.bottom+10)),l.push(new t.FPoint(h.right+10,h.top-10)),l.push(new t.FPoint(h.left-10,h.top-10)),n.AddPath(l,0,!0),n.ReverseSolution=!0,n.Execute(1,o,3,3),o.length>0&&o.splice(0,1)}}}OffsetPoint(e,i,s){if(this.m_sinA=this.m_normals[i].X*this.m_normals[e].Y-this.m_normals[e].X*this.m_normals[i].Y,0===this.m_sinA)return i;if(this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1),this.m_sinA*this.m_delta<0)this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_normals[i].X*this.m_delta,this.m_srcPoly[e].Y+this.m_normals[i].Y*this.m_delta)),this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e])),this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_normals[e].X*this.m_delta,this.m_srcPoly[e].Y+this.m_normals[e].Y*this.m_delta));else switch(s){case 2:var r=this.m_normals[e].X*this.m_normals[i].X+this.m_normals[e].Y*this.m_normals[i].Y+1;r>=this.m_miterLim?this.DoMiter(e,i,r):this.DoSquare(e,i);break;case 0:this.DoSquare(e,i);break;case 1:this.DoRound(e,i)}return i=e}DoSquare(e,i){var s=Math.tan(Math.atan2(this.m_sinA,this.m_normals[i].X*this.m_normals[e].X+this.m_normals[i].Y*this.m_normals[e].Y)/4);this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_delta*(this.m_normals[i].X-this.m_normals[i].Y*s),this.m_srcPoly[e].Y+this.m_delta*(this.m_normals[i].Y+this.m_normals[i].X*s))),this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_delta*(this.m_normals[e].X+this.m_normals[e].Y*s),this.m_srcPoly[e].Y+this.m_delta*(this.m_normals[e].Y-this.m_normals[e].X*s)))}DoMiter(e,i,s){var r=this.m_delta/s;this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+(this.m_normals[i].X+this.m_normals[e].X)*r,this.m_srcPoly[e].Y+(this.m_normals[i].Y+this.m_normals[e].Y)*r))}DoRound(e,i){for(var s,r=Math.atan2(this.m_sinA,this.m_normals[i].X*this.m_normals[e].X+this.m_normals[i].Y*this.m_normals[e].Y),n=Math.max(Math.round(this.m_StepsPerRad*Math.abs(r)),1),o=this.m_normals[i].X,a=this.m_normals[i].Y,l=0;l<n;++l)this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+o*this.m_delta,this.m_srcPoly[e].Y+a*this.m_delta)),s=o,o=o*this.m_cos-this.m_sin*a,a=s*this.m_sin+a*this.m_cos;this.m_destPoly.push(new t.FPoint(this.m_srcPoly[e].X+this.m_normals[e].X*this.m_delta,this.m_srcPoly[e].Y+this.m_normals[e].Y*this.m_delta))}}W(d,"two_pi",6.28318530717959),W(d,"def_arc_tolerance",.25),t.ClipperOffset=d,t.Error=function(e){throw new t.Error(e)}})(G||(G={}));const H=G;function Y(t){let e=st(t),i=H.Clipper.GetBounds(e);return{min:[i.left,-i.bottom],max:[i.right,-i.top]}}function $(t){if(!t.length||!t[0])return[];let e=st(t);if(!e.length)return[];let i=[e[0]],s=e.slice(1),r=new H.Clipper;r.AddPaths(i,H.PolyType.ptSubject,!0),r.AddPaths(s,H.PolyType.ptClip,!0);let n=[];return r.Execute(H.ClipType.ctUnion,n,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),rt(n)}function j(t,e=0,i=[],s=[],r=[]){for(let n of t.m_Children){if(!n.m_polygon.length)continue;let t=e%2!=0,o=rt([n.m_polygon])[0],a={polygon:o,children:[]};i.push(a),t?r.push(o):(r=[o],s.push(r)),j(n,e+1,a.children,s,r)}return s.sort(((t,e)=>Q(t[0])>Q(e[0])?-1:1)),{polyTree:i,polygons:s}}function z(t,e=.1,i,s){if(!t.length||!t[0])return[];void 0===i&&(i=H.EndType.etClosedPolygon),e=e&&"number"==typeof e?e:.1;let r=st(t=s?t:et(t)),n=new H.ClipperOffset(2),o=[];return n.AddPaths(r,H.JoinType.jtMiter,i),n.Execute(o,e),rt(o)}function V(t,e=.1,i=H.EndType.etClosedPolygon){if(!t.length||!t[0])return{polygons:[],polyTree:[]};let s=t.flatMap(st),r=new H.ClipperOffset(2);r.AddPaths(s,H.JoinType.jtMiter,i);let n=new H.PolyTree;return r.Execute(n,e),j(n)}function q(t,e,i){if(!t.length||!t[0])return[];let s=st(t),r=st(e),n=new H.Clipper;n.AddPaths(s,H.PolyType.ptSubject,!0),n.AddPaths(r,H.PolyType.ptClip,!0);let o=[];return new H.PolyTree,n.Execute(H.ClipType.ctDifference,o,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),rt(o)}function J(t,e){if(!t.length||!t[0])return{polygons:[],polyTree:[]};let i=t.flatMap(st),s=e.flatMap(st),r=new H.Clipper;r.AddPaths(i,H.PolyType.ptSubject,!0),r.AddPaths(s,H.PolyType.ptClip,!0);let n=new H.PolyTree;return r.Execute(H.ClipType.ctDifference,n,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),j(n)}function K(t,e,i=[]){let s=new H.FPoint(t[0],-t[1]),r=st([e])[0],n=H.Clipper.PointInPolygon(s,r);for(let o of i){let e=K(t,o);1===e?n=0:-1===e&&(n=-1)}return n}function Z(t){let e=st([t]);return H.Clipper.Area(e[0])}function Q(t){return Math.abs(Z(t))}function tt(t){let e=Math.abs(Z(t[0]));for(let i of t.slice(1))e-=Math.abs(Z(i));return e}function et(t,e=.01){let i=st(t);return rt(H.Clipper.CleanPolygons(i,e))}function it(t,e=.01){return et([t],e)[0]}function st(t=[]){let e=[],i=0;for(let s of t)if(null==s?void 0:s.length){e[i]=[];for(let t=0;t<s.length;t++)e[i][t]={X:s[t][0],Y:-s[t][1]};i++}return e}function rt(t){let e=[];for(let i=0;i<t.length;i++){let s=t[i]||[];e[i]=[];for(let t=0;t<s.length;t++)e[i][t]=[s[t].X,-s[t].Y]}return e}var nt=1e-6,ot="undefined"!=typeof Float32Array?Float32Array:Array;function at(){var t=new ot(16);return ot!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function lt(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function ht(t,e){if(t===e){var i=e[1],s=e[2],r=e[3],n=e[6],o=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=i,t[6]=e[9],t[7]=e[13],t[8]=s,t[9]=n,t[11]=e[14],t[12]=r,t[13]=o,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function ut(t,e){var i=e[0],s=e[1],r=e[2],n=e[3],o=e[4],a=e[5],l=e[6],h=e[7],u=e[8],c=e[9],d=e[10],p=e[11],f=e[12],m=e[13],g=e[14],y=e[15],v=i*a-s*o,x=i*l-r*o,b=i*h-n*o,_=s*l-r*a,w=s*h-n*a,P=r*h-n*l,E=u*m-c*f,T=u*g-d*f,A=u*y-p*f,I=c*g-d*m,S=c*y-p*m,C=d*y-p*g,M=v*C-x*S+b*I+_*A-w*T+P*E;return M?(M=1/M,t[0]=(a*C-l*S+h*I)*M,t[1]=(r*S-s*C-n*I)*M,t[2]=(m*P-g*w+y*_)*M,t[3]=(d*w-c*P-p*_)*M,t[4]=(l*A-o*C-h*T)*M,t[5]=(i*C-r*A+n*T)*M,t[6]=(g*b-f*P-y*x)*M,t[7]=(u*P-d*b+p*x)*M,t[8]=(o*S-a*A+h*E)*M,t[9]=(s*A-i*S-n*E)*M,t[10]=(f*w-m*b+y*v)*M,t[11]=(c*b-u*w-p*v)*M,t[12]=(a*T-o*I-l*E)*M,t[13]=(i*I-s*T+r*E)*M,t[14]=(m*x-f*_-g*v)*M,t[15]=(u*_-c*x+d*v)*M,t):null}function ct(t,e,i){var s=e[0],r=e[1],n=e[2],o=e[3],a=e[4],l=e[5],h=e[6],u=e[7],c=e[8],d=e[9],p=e[10],f=e[11],m=e[12],g=e[13],y=e[14],v=e[15],x=i[0],b=i[1],_=i[2],w=i[3];return t[0]=x*s+b*a+_*c+w*m,t[1]=x*r+b*l+_*d+w*g,t[2]=x*n+b*h+_*p+w*y,t[3]=x*o+b*u+_*f+w*v,x=i[4],b=i[5],_=i[6],w=i[7],t[4]=x*s+b*a+_*c+w*m,t[5]=x*r+b*l+_*d+w*g,t[6]=x*n+b*h+_*p+w*y,t[7]=x*o+b*u+_*f+w*v,x=i[8],b=i[9],_=i[10],w=i[11],t[8]=x*s+b*a+_*c+w*m,t[9]=x*r+b*l+_*d+w*g,t[10]=x*n+b*h+_*p+w*y,t[11]=x*o+b*u+_*f+w*v,x=i[12],b=i[13],_=i[14],w=i[15],t[12]=x*s+b*a+_*c+w*m,t[13]=x*r+b*l+_*d+w*g,t[14]=x*n+b*h+_*p+w*y,t[15]=x*o+b*u+_*f+w*v,t}function dt(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function pt(t,e){var i=new ot(3);!function(t,e){var i=e[0],s=e[1],r=e[2],n=e[4],o=e[5],a=e[6],l=e[8],h=e[9],u=e[10];t[0]=Math.hypot(i,s,r),t[1]=Math.hypot(n,o,a),t[2]=Math.hypot(l,h,u)}(i,e);var s=1/i[0],r=1/i[1],n=1/i[2],o=e[0]*s,a=e[1]*r,l=e[2]*n,h=e[4]*s,u=e[5]*r,c=e[6]*n,d=e[8]*s,p=e[9]*r,f=e[10]*n,m=o+u+f,g=0;return m>0?(g=2*Math.sqrt(m+1),t[3]=.25*g,t[0]=(c-p)/g,t[1]=(d-l)/g,t[2]=(a-h)/g):o>u&&o>f?(g=2*Math.sqrt(1+o-u-f),t[3]=(c-p)/g,t[0]=.25*g,t[1]=(a+h)/g,t[2]=(d+l)/g):u>f?(g=2*Math.sqrt(1+u-o-f),t[3]=(d-l)/g,t[0]=(a+h)/g,t[1]=.25*g,t[2]=(c+p)/g):(g=2*Math.sqrt(1+f-o-u),t[3]=(a-h)/g,t[0]=(d+l)/g,t[1]=(c+p)/g,t[2]=.25*g),t}function ft(){var t=new ot(3);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function mt(t){var e=new ot(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function gt(t,e,i){var s=new ot(3);return s[0]=t,s[1]=e,s[2]=i,s}function yt(t,e,i,s){return t[0]=e,t[1]=i,t[2]=s,t}function vt(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t}function xt(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t}function bt(t,e){var i=e[0],s=e[1],r=e[2],n=i*i+s*s+r*r;return n>0&&(n=1/Math.sqrt(n)),t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function _t(t,e,i){var s=e[0],r=e[1],n=e[2],o=i[0],a=i[1],l=i[2];return t[0]=r*l-n*a,t[1]=n*o-s*l,t[2]=s*a-r*o,t}function wt(t,e,i){var s=e[0],r=e[1],n=e[2],o=i[3]*s+i[7]*r+i[11]*n+i[15];return o=o||1,t[0]=(i[0]*s+i[4]*r+i[8]*n+i[12])/o,t[1]=(i[1]*s+i[5]*r+i[9]*n+i[13])/o,t[2]=(i[2]*s+i[6]*r+i[10]*n+i[14])/o,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var Pt=xt;function Et(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function Tt(t,e,i){i*=.5;var s=Math.sin(i);return t[0]=s*e[0],t[1]=s*e[1],t[2]=s*e[2],t[3]=Math.cos(i),t}ft(),function(){var t,e=(t=new ot(4),ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var At;function It(){var t=new ot(2);return ot!=Float32Array&&(t[0]=0,t[1]=0),t}function St(t,e,i){var s=e[0],r=e[1];return t[0]=i[0]*s+i[2]*r+i[4],t[1]=i[1]*s+i[3]*r+i[5],t}ft(),gt(1,0,0),gt(0,1,0),Et(),Et(),At=new ot(9),ot!=Float32Array&&(At[1]=0,At[2]=0,At[3]=0,At[5]=0,At[6]=0,At[7]=0),At[0]=1,At[4]=1,At[8]=1,function(){var t=It()}();var Ct="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Mt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Ot(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})})),i}var Nt={exports:{}};function Lt(t,e,i){i=i||2;var s,r,n,o,a,l,h,u=e&&e.length,c=u?e[0]*i:t.length,d=Rt(t,0,c,i,!0),p=[];if(!d||d.next===d.prev)return p;if(u&&(d=function(t,e,i,s){var r,n,o,a=[];for(r=0,n=e.length;r<n;r++)(o=Rt(t,e[r]*s,r<n-1?e[r+1]*s:t.length,s,!1))===o.next&&(o.steiner=!0),a.push($t(o));for(a.sort(Xt),r=0;r<a.length;r++)i=Wt(a[r],i);return i}(t,e,d,i)),t.length>80*i){s=n=t[0],r=o=t[1];for(var f=i;f<c;f+=i)(a=t[f])<s&&(s=a),(l=t[f+1])<r&&(r=l),a>n&&(n=a),l>o&&(o=l);h=0!==(h=Math.max(n-s,o-r))?32767/h:0}return Bt(d,p,i,s,r,h,0),p}function Rt(t,e,i,s,r){var n,o;if(r===re(t,e,i,s)>0)for(n=e;n<i;n+=s)o=ee(n,t[n],t[n+1],o);else for(n=i-s;n>=e;n-=s)o=ee(n,t[n],t[n+1],o);return o&&qt(o,o.next)&&(ie(o),o=o.next),o}function kt(t,e){if(!t)return t;e||(e=t);var i,s=t;do{if(i=!1,s.steiner||!qt(s,s.next)&&0!==Vt(s.prev,s,s.next))s=s.next;else{if(ie(s),(s=e=s.prev)===s.next)break;i=!0}}while(i||s!==e);return e}function Bt(t,e,i,s,r,n,o){if(t){!o&&n&&function(t,e,i,s){var r=t;do{0===r.z&&(r.z=Yt(r.x,r.y,e,i,s)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){var e,i,s,r,n,o,a,l,h=1;do{for(i=t,t=null,n=null,o=0;i;){for(o++,s=i,a=0,e=0;e<h&&(a++,s=s.nextZ);e++);for(l=h;a>0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(r=i,i=i.nextZ,a--):(r=s,s=s.nextZ,l--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;i=s}n.nextZ=null,h*=2}while(o>1)}(r)}(t,s,r,n);for(var a,l,h=t;t.prev!==t.next;)if(a=t.prev,l=t.next,n?Dt(t,s,r,n):Ft(t))e.push(a.i/i|0),e.push(t.i/i|0),e.push(l.i/i|0),ie(t),t=l.next,h=l.next;else if((t=l)===h){o?1===o?Bt(t=Ut(kt(t),e,i),e,i,s,r,n,2):2===o&&Gt(t,e,i,s,r,n):Bt(kt(t),e,i,s,r,n,1);break}}}function Ft(t){var e=t.prev,i=t,s=t.next;if(Vt(e,i,s)>=0)return!1;for(var r=e.x,n=i.x,o=s.x,a=e.y,l=i.y,h=s.y,u=r<n?r<o?r:o:n<o?n:o,c=a<l?a<h?a:h:l<h?l:h,d=r>n?r>o?r:o:n>o?n:o,p=a>l?a>h?a:h:l>h?l:h,f=s.next;f!==e;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&jt(r,a,n,l,o,h,f.x,f.y)&&Vt(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Dt(t,e,i,s){var r=t.prev,n=t,o=t.next;if(Vt(r,n,o)>=0)return!1;for(var a=r.x,l=n.x,h=o.x,u=r.y,c=n.y,d=o.y,p=a<l?a<h?a:h:l<h?l:h,f=u<c?u<d?u:d:c<d?c:d,m=a>l?a>h?a:h:l>h?l:h,g=u>c?u>d?u:d:c>d?c:d,y=Yt(p,f,e,i,s),v=Yt(m,g,e,i,s),x=t.prevZ,b=t.nextZ;x&&x.z>=y&&b&&b.z<=v;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=g&&x!==r&&x!==o&&jt(a,u,l,c,h,d,x.x,x.y)&&Vt(x.prev,x,x.next)>=0)return!1;if(x=x.prevZ,b.x>=p&&b.x<=m&&b.y>=f&&b.y<=g&&b!==r&&b!==o&&jt(a,u,l,c,h,d,b.x,b.y)&&Vt(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;x&&x.z>=y;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=g&&x!==r&&x!==o&&jt(a,u,l,c,h,d,x.x,x.y)&&Vt(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;b&&b.z<=v;){if(b.x>=p&&b.x<=m&&b.y>=f&&b.y<=g&&b!==r&&b!==o&&jt(a,u,l,c,h,d,b.x,b.y)&&Vt(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Ut(t,e,i){var s=t;do{var r=s.prev,n=s.next.next;!qt(r,n)&&Jt(r,s,s.next,n)&&Qt(r,n)&&Qt(n,r)&&(e.push(r.i/i|0),e.push(s.i/i|0),e.push(n.i/i|0),ie(s),ie(s.next),s=t=n),s=s.next}while(s!==t);return kt(s)}function Gt(t,e,i,s,r,n){var o=t;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&zt(o,a)){var l=te(o,a);return o=kt(o,o.next),l=kt(l,l.next),Bt(o,e,i,s,r,n,0),void Bt(l,e,i,s,r,n,0)}a=a.next}o=o.next}while(o!==t)}function Xt(t,e){return t.x-e.x}function Wt(t,e){var i=function(t,e){var i,s=e,r=t.x,n=t.y,o=-1/0;do{if(n<=s.y&&n>=s.next.y&&s.next.y!==s.y){var a=s.x+(n-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=r&&a>o&&(o=a,i=s.x<s.next.x?s:s.next,a===r))return i}s=s.next}while(s!==e);if(!i)return null;var l,h=i,u=i.x,c=i.y,d=1/0;s=i;do{r>=s.x&&s.x>=u&&r!==s.x&&jt(n<c?r:o,n,u,c,n<c?o:r,n,s.x,s.y)&&(l=Math.abs(n-s.y)/(r-s.x),Qt(s,t)&&(l<d||l===d&&(s.x>i.x||s.x===i.x&&Ht(i,s)))&&(i=s,d=l)),s=s.next}while(s!==h);return i}(t,e);if(!i)return e;var s=te(i,t);return kt(s,s.next),kt(i,i.next)}function Ht(t,e){return Vt(t.prev,t,e.prev)<0&&Vt(e.next,t,t.next)<0}function Yt(t,e,i,s,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-i)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-s)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function $t(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function jt(t,e,i,s,r,n,o,a){return(r-o)*(e-a)>=(t-o)*(n-a)&&(t-o)*(s-a)>=(i-o)*(e-a)&&(i-o)*(n-a)>=(r-o)*(s-a)}function zt(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&Jt(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(Qt(t,e)&&Qt(e,t)&&function(t,e){var i=t,s=!1,r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==t);return s}(t,e)&&(Vt(t.prev,t,e.prev)||Vt(t,e.prev,e))||qt(t,e)&&Vt(t.prev,t,t.next)>0&&Vt(e.prev,e,e.next)>0)}function Vt(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function qt(t,e){return t.x===e.x&&t.y===e.y}function Jt(t,e,i,s){var r=Zt(Vt(t,e,i)),n=Zt(Vt(t,e,s)),o=Zt(Vt(i,s,t)),a=Zt(Vt(i,s,e));return r!==n&&o!==a||(!(0!==r||!Kt(t,i,e))||(!(0!==n||!Kt(t,s,e))||(!(0!==o||!Kt(i,t,s))||!(0!==a||!Kt(i,e,s)))))}function Kt(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function Zt(t){return t>0?1:t<0?-1:0}function Qt(t,e){return Vt(t.prev,t,t.next)<0?Vt(t,e,t.next)>=0&&Vt(t,t.prev,e)>=0:Vt(t,e,t.prev)<0||Vt(t,t.next,e)<0}function te(t,e){var i=new se(t.i,t.x,t.y),s=new se(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function ee(t,e,i,s){var r=new se(t,e,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function ie(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function se(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function re(t,e,i,s){for(var r=0,n=e,o=i-s;n<i;n+=s)r+=(t[o]-t[n])*(t[n+1]+t[o+1]),o=n;return r}Nt.exports=Lt,Nt.exports.default=Lt,Lt.deviation=function(t,e,i,s){var r=e&&e.length,n=r?e[0]*i:t.length,o=Math.abs(re(t,0,n,i));if(r)for(var a=0,l=e.length;a<l;a++){var h=e[a]*i,u=a<l-1?e[a+1]*i:t.length;o-=Math.abs(re(t,h,u,i))}var c=0;for(a=0;a<s.length;a+=3){var d=s[a]*i,p=s[a+1]*i,f=s[a+2]*i;c+=Math.abs((t[d]-t[f])*(t[p+1]-t[d+1])-(t[d]-t[p])*(t[f+1]-t[d+1]))}return 0===o&&0===c?0:Math.abs((c-o)/o)},Lt.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},s=0,r=0;r<t.length;r++){for(var n=0;n<t[r].length;n++)for(var o=0;o<e;o++)i.vertices.push(t[r][n][o]);r>0&&(s+=t[r-1].length,i.holes.push(s))}return i};const ne=Mt(Nt.exports);for(var oe,ae=[],le=0;le<256;++le)ae.push((le+256).toString(16).slice(1));var he=new Uint8Array(16);function ue(){if(!oe&&!(oe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oe(he)}const ce={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function de(t,e,i){if(ce.randomUUID&&!t)return ce.randomUUID();var s=(t=t||{}).random||(t.rng||ue)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,function(t,e=0){return(ae[t[e+0]]+ae[t[e+1]]+ae[t[e+2]]+ae[t[e+3]]+"-"+ae[t[e+4]]+ae[t[e+5]]+"-"+ae[t[e+6]]+ae[t[e+7]]+"-"+ae[t[e+8]]+ae[t[e+9]]+"-"+ae[t[e+10]]+ae[t[e+11]]+ae[t[e+12]]+ae[t[e+13]]+ae[t[e+14]]+ae[t[e+15]]).toLowerCase()}(s)}var pe={exports:{}};function fe(){}fe.prototype={on:function(t,e,i){var s=this.e||(this.e={});return(s[t]||(s[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){var s=this;function r(){s.off(t,r),e.apply(i,arguments)}return r._=e,this.on(t,r,i)},emit:function(t){for(var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),s=0,r=i.length;s<r;s++)i[s].fn.apply(i[s].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),s=i[t],r=[];if(s&&e)for(var n=0,o=s.length;n<o;n++)s[n].fn!==e&&s[n].fn._!==e&&r.push(s[n]);return r.length?i[t]=r:delete i[t],this}},pe.exports=fe;var me,ge,ye=pe.exports.TinyEmitter=fe,ve=t=>{throw TypeError(t)},xe=(t,e,i)=>(((t,e,i)=>{e.has(t)||ve("Cannot "+i)})(t,e,"access private method"),i);let be=new class extends E{error(...t){this.levels.includes("errors")&&(t.length>0&&(t[0]="Internal error: "+t[0]),console.error(...t),this.emit("error",...t))}}(["info","warnings","errors"]);class _e{constructor(t){this.spaceGraph=null,this.type=t}}class we extends _e{constructor(t,e){super(e),this.name="",this.customId="",this.id=t}copyForClone(t){this.name=t.name,this.customId=t.customId}setName(t){this.name=t,this.emit("node-property-change",this,"name")}setCustomId(t){this.customId=t,this.emit("node-property-change",this,"customId")}emit(t,...e){this.spaceGraph&&this.spaceGraph.emit(t,...e)}toJSON(){return{type:this.type,id:this.id,name:""===this.name?void 0:this.name,customId:""===this.customId?void 0:this.customId}}}const Pe="material:color";class Ee extends we{constructor(t,e=[1,1,1],i=1){super(t,Pe),this.color=[...e],this.opacity=i}toJSON(){let t;return t=1===this.opacity?[...this.color]:[this.color[0],this.color[1],this.color[2],this.opacity],{...super.toJSON(),value:t}}}const Te="material:standard";class Ae extends we{constructor(t,e){super(t,Te),this.reference=e}toJSON(){return{...super.toJSON(),reference:this.reference}}}const Ie="material:embedded";class Se extends we{constructor(t,e,i){super(t,Ce),this.reference=e,this.format=i}toJSON(){return be.warn("Embedded material not supported in materials section."),{...super.toJSON(),type:"material:color",value:[1,1,1,1]}}}const Ce="material:basic";class Me extends we{constructor(t){super(t,Ce),this.colorDiffuse=[1,1,1],this.colorSpecular=[1,1,1],this.specularCoefficient=1,this.opacity=1}copyForClone(t){super.copyForClone(t),this.colorDiffuse=[...t.colorDiffuse],this.colorSpecular=[...t.colorSpecular],this.specularCoefficient=t.specularCoefficient,this.opacity=t.opacity}toJSON(){return{...super.toJSON(),colorDiffuse:[...this.colorDiffuse],colorSpecular:[...this.colorSpecular],specularCoefficient:this.specularCoefficient,opacity:this.opacity}}}const Oe="default",Ne=[1,1,1],Le=[1,1,1],Re=1,ke=1,Be=[...Ne,ke];function Fe(t,e){return Number.isFinite(t)?!(t<0||t>1)||(be.warn(`Value out of range (0 to 1) in color literal: '${e}'.`),!1):(be.warn(`Invalid float value in color literal: '${e}'.`),!1)}function De(t,e){return Number.isInteger(t)?!(t<0||t>255)||(be.warn(`Value out of range (0 to 255) in color literal: '${e}'.`),!1):(be.warn(`Invalid byte value in color literal: '${e}'.`),!1)}function Ue(t){if(t.length<3||t.length>4)return be.warn(`Invalid number of components in color literal: '${t}'.`),Be;let e=t.toString(),i=[0,0,0,0];for(let s=0;s<t.length;s++){let r=t[s];if(!Fe(r,e))return Be;i[s]=r}return 3===t.length&&(i[3]=Be[3]),i}function Ge(t){let e,i,s,r,n=t.substring(1),o=parseInt(n,16);if(isNaN(o))return be.warn(`Invalid hexadecimal color literal: '${t}'.`),Be;if(3===n.length?o=o<<4|15:6===n.length&&(o=o<<8|255),3===n.length||4===n.length)e=(o>>12&15)/15,i=(o>>8&15)/15,s=(o>>4&15)/15,r=(15&o)/15;else{if(6!==n.length&&8!==n.length)return be.warn(`Invalid hexademical color literal length: '${t}'.`),Be;e=(o>>24&255)/255,i=(o>>16&255)/255,s=(o>>8&255)/255,r=(255&o)/255}return[e,i,s,r]}function Xe(t,e){if(!t.endsWith(")"))return be.warn(`Missing closing parenthesis: '${t}'.`),Be;let i=e?5:4,s=t.substring(i,t.length-1).split(",");if(s.length<3||s.length>4||3===s.length&&e||4===s.length&&!e)return be.warn(`Invalid number of components in color literal: '${t}'.`),Be;let r=[0,0,0,0];for(let n=0;n<3;n++){let e=s[n],i=parseFloat(e);if(!De(i,t))return Be;r[n]=i/255}if(4===s.length){let e=parseFloat(s[3]);if(!Fe(e,t))return Be;r[3]=e}else r[3]=Be[3];return r}function We([t,e,i]){return"#"+Math.round(255*t).toString(16).padStart(2,"0")+Math.round(255*e).toString(16).padStart(2,"0")+Math.round(255*i).toString(16).padStart(2,"0")}function He({name:t=Oe,color:e=Ne,specularColor:i=Le,specularCoefficient:s=Re,opacity:r=ke,reference:n}={}){return n?{name:t,reference:n}:{name:t,color:[...e],specularColor:[...i],specularCoefficient:s,opacity:r}}function Ye(t,e={}){if(Array.isArray(t)){let[e,i,s,r]=Ue(t);return He({name:t.toString(),color:[e,i,s],opacity:r})}if("string"==typeof t){let i,s,r,n;if(""===t)return be.warn("Empty string not a valid color value."),He({name:t});if(t===Oe)return He();if("#"===t.charAt(0))[i,s,r,n]=Ge(t);else if(t.startsWith("rgb("))[i,s,r,n]=Xe(t,!1);else{if(!t.startsWith("rgba(")){if(t.startsWith("asm:")){let e=t.substring(4,t.length);return He({name:t,reference:e})}if(t.startsWith("data3d:")){let e=t.substring(7,t.length);return He({name:t,reference:e})}{let i=e[t];if(void 0===i)return be.warn(`Unknown material: '${t}'.`),He();{let e;switch(i.type){case Pe:e=He({name:t,color:i.color,specularColor:i.color});break;case Te:e=He({name:t,reference:i.reference});break;case Ie:be.warn("Embedded material not supported in materials section."),e=He();break;case Ce:e=He({name:t,color:i.colorDiffuse,specularColor:i.colorSpecular,specularCoefficient:i.specularCoefficient,opacity:i.opacity});break;default:be.warn(`Unknown material type ${i.type}.`),e=He()}return e}}}[i,s,r,n]=Xe(t,!0)}return He({name:t,color:[i,s,r],opacity:n})}return be.warn(`Material can only be an array or a string: '${t}'.`),He()}const $e="default";function je(t,e){return new Array(e-t).fill(void 0).map(((e,i)=>t+i))}function ze(t,e){let i=new Array(3*e.length),s=0;for(let r=0;r<e.length;r++){let n=3*e[r];i[s++]=t[n],i[s++]=t[n+1],i[s++]=t[n+2]}return i}function Ve(t,e,i){let s=3*e,r=new Array(s*i.length),n=0;for(let o=0;o<i.length;o++){let e=s*i[o];for(let i=0;i<s;i++)r[n++]=t[e++]}return r}function qe(t,e,i){let s=[],r=e.faces,{surfaces:n,materials:o}=function(t){let e=t.surfaces??{[$e]:"all"},i=t.materials??{[$e]:"default"};if(e&&0===Object.keys(e).length)be.warn("Empty 'surfaces' field not allowed.");else if(i&&0===Object.keys(i).length)be.warn("Empty 'materials' field not allowed.");else if(t.material)t.materials?be.warn("Cannot use 'material' and 'materials' at the same time."):i={[$e]:t.material};else if(i[$e])Object.keys(i).length>1&&be.warn("Extraneous material assignments ignored.");else{let t=Object.keys(e);for(let e of t)i[e]||be.warn(`Surface '${e}' not assigned a material, using default.`);let s=Object.keys(i);for(let i of s)e[i]||be.warn(`Surface '${i}' not found.`)}return{surfaces:e,materials:i}}(t);for(let[a,l]of Object.entries(n)){if("all"!==l&&!Array.isArray(l)&&"object"!=typeof l){be.warn(`Unknown face indices type, skipping surface '${a}'.`);continue}let n=[];if("geometry:mesh"===t.type)if("all"===l){let t=e.indices.length/3;n.push(...je(0,t))}else if(Array.isArray(l))n.push(...l);else{let{start:t,end:e}=l;n.push(...je(t,e))}else if("all"===l)for(let t of r){let{index:e,count:i}=t;n.push(...je(e,e+i))}else if(Array.isArray(l))for(let t=0;t<l.length;t++){let e=r[l[t]],{index:i,count:s}=e;n.push(...je(i,i+s))}else{let{start:t,end:e}=l;for(let i=t;i<e;i++){let t=r[i],{index:e,count:s}=t;n.push(...je(e,e+s))}}let h,{vertices:u,indices:c,normals:d,uvs:p}=e;h=o[$e]?o[$e]:o[a]??"default";let f=Ye(h,i),m={name:a,vertices:u,indices:ze(c,n),material:f};d&&(m.normals=Ve(d,3,n)),p&&(m.uvs=Ve(p,2,n)),s.push(m)}return s}function Je(t,e){let i=function(t){if(Array.isArray(t))return[t];if("vector3:list"===t.type)return t.list;if("vector3:range"===t.type){let{start:e,step:i,count:s}=t.range;return function(t,e,i){let s=[];for(let r=0;r<i;r++){let i=t[0]+r*e[0],n=t[1]+r*e[1],o=t[2]+r*e[2];s.push([i,n,o])}return s}(e,i,s)}return be.warn(`Unknown position type: ${t}`),[[0,0,0]]}(t),s=function(t){if("number"==typeof t)return[t];if("number:list"===t.type)return t.list;if("number:range"===t.type){let{start:e,step:i,count:s}=t.range;return function(t,e,i){let s=[];for(let r=0;r<i;r++){let i=t+r*e;s.push(i)}return s}(e,i,s)}return be.warn(`Unknown rotation type: ${t}`),[0]}(e),r=Math.max(i.length,s.length),n=[];for(let o=0;o<r;o++){let t=i[Math.min(o,i.length-1)],e=s[Math.min(o,s.length-1)];n.push({position:t,rotation:e})}return n}function Ke(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Ze(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})})),i}var Qe={exports:{}};function ti(t,e){return t<e?-1:t>e?1:0}const ei=Ze(Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=ti){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:i}=this,s=e[t];for(;t>0;){const r=t-1>>1,n=e[r];if(i(s,n)>=0)break;e[t]=n,t=r}e[t]=s}_down(t){const{data:e,compare:i}=this,s=this.length>>1,r=e[t];for(;t<s;){let s=1+(t<<1),n=e[s];const o=s+1;if(o<this.length&&i(e[o],n)<0&&(s=o,n=e[o]),i(n,r)>=0)break;e[t]=n,t=s}e[t]=r}}},Symbol.toStringTag,{value:"Module"})));var ii;const si=Ke(function(){if(ii)return Qe.exports;ii=1;var t=ei;function e(e,r,n){var o,a,l,h;r=r||1;for(var u=0;u<e[0].length;u++){var c=e[0][u];(!u||c[0]<o)&&(o=c[0]),(!u||c[1]<a)&&(a=c[1]),(!u||c[0]>l)&&(l=c[0]),(!u||c[1]>h)&&(h=c[1])}var d=l-o,p=h-a,f=Math.min(d,p),m=f/2;if(0===f){var g=[o,a];return g.distance=0,g}for(var y=new t(void 0,i),v=o;v<l;v+=f)for(var x=a;x<h;x+=f)y.push(new s(v+m,x+m,m,e));var b=function(t){for(var e=0,i=0,r=0,n=t[0],o=0,a=n.length,l=a-1;o<a;l=o++){var h=n[o],u=n[l],c=h[0]*u[1]-u[0]*h[1];i+=(h[0]+u[0])*c,r+=(h[1]+u[1])*c,e+=3*c}return 0===e?new s(n[0][0],n[0][1],0,t):new s(i/e,r/e,0,t)}(e),_=new s(o+d/2,a+p/2,0,e);_.d>b.d&&(b=_);for(var w=y.length;y.length;){var P=y.pop();P.d>b.d&&(b=P,n&&console.log("found best %d after %d probes",Math.round(1e4*P.d)/1e4,w)),P.max-b.d<=r||(m=P.h/2,y.push(new s(P.x-m,P.y-m,m,e)),y.push(new s(P.x+m,P.y-m,m,e)),y.push(new s(P.x-m,P.y+m,m,e)),y.push(new s(P.x+m,P.y+m,m,e)),w+=4)}n&&(console.log("num probes: "+w),console.log("best distance: "+b.d));var E=[b.x,b.y];return E.distance=b.d,E}function i(t,e){return e.max-t.max}function s(t,e,i,s){this.x=t,this.y=e,this.h=i,this.d=function(t,e,i){for(var s=!1,n=1/0,o=0;o<i.length;o++)for(var a=i[o],l=0,h=a.length,u=h-1;l<h;u=l++){var c=a[l],d=a[u];c[1]>e!=d[1]>e&&t<(d[0]-c[0])*(e-c[1])/(d[1]-c[1])+c[0]&&(s=!s),n=Math.min(n,r(t,e,c,d))}return 0===n?0:(s?1:-1)*Math.sqrt(n)}(t,e,s),this.max=this.d+this.h*Math.SQRT2}function r(t,e,i,s){var r=i[0],n=i[1],o=s[0]-r,a=s[1]-n;if(0!==o||0!==a){var l=((t-r)*o+(e-n)*a)/(o*o+a*a);l>1?(r=s[0],n=s[1]):l>0&&(r+=o*l,n+=a*l)}return(o=t-r)*o+(a=e-n)*a}return t.default&&(t=t.default),Qe.exports=e,Qe.exports.default=e,Qe.exports}());function ri(t,e){return[t[0]+e[0],t[1]+e[1]]}function ni(t){let e;return 0===t[0]?e=t[1]>0?Math.PI/2:t[1]<0?3*Math.PI/2:0:(e=Math.atan2(t[1],t[0]),e<0&&(e+=2*Math.PI)),e}function oi(t,e){return t[0]*e[1]-t[1]*e[0]}function ai(t,e,i){return Math.abs(t[0]-e[0])<i&&Math.abs(t[1]-e[1])<i}function li(t){return Math.sqrt(function(t){return t[0]*t[0]+t[1]*t[1]}(t))}function hi(t,e){return li(fi(e,t))}function ui(t,e,i){return[t[0]+i*(e[0]-t[0]),t[1]+i*(e[1]-t[1])]}function ci(t){let e=li(t);return[t[0]/e,t[1]/e]}function di(t){return[-t[1],t[0]]}function pi(t,e){return[t[0]*e,t[1]*e]}function fi(t,e){return[t[0]-e[0],t[1]-e[1]]}function mi(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function gi(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function yi(t,e,i){return[t[0]+i*(e[0]-t[0]),t[1]+i*(e[1]-t[1]),t[2]+i*(e[2]-t[2])]}function vi(t,e,i){let s=oi(fi(e,t),fi(i,t));return s>1e-7?1:s<-1e-7?-1:0}function xi(t,e){return ni([e[0]-t[0],e[1]-t[1]])}function bi(t,e,i,s){let r=fi(e,t),n=fi(s,i),o=function(t,e){return t[0]*e[0]+t[1]*e[1]}(r,n),a=oi(r,n);return Math.atan2(Math.abs(a),o)}function _i(t,e){let i=!1;const s=t[0],r=t[1];for(let n=0;n<e.length;n++){const t=e[n],o=n===e.length-1?e[0]:e[n+1];if(t[1]<r&&o[1]>=r||o[1]<r&&t[1]>=r){const e=o[0]-t[0],n=o[1]-t[1];Math.abs(n)>=1e-9&&t[0]+(r-t[1])/n*e<s&&(i=!i)}}return i}function wi(t,e){if(!_i(t,e[0]))return!1;for(let i=1;i<e.length;i++){if(_i(t,e[i]))return!1}return!0}function Pi(t,e,i){return function(t,e,i){const s=fi(i,e),r=s[0]*s[0]+s[1]*s[1];let n;if(r<1e-9)n=e;else{const o=((t[0]-e[0])*s[0]+(t[1]-e[1])*s[1])/r;n=o<0?e:o>1?i:ui(e,i,o)}const o=fi(n,t);return o[0]*o[0]+o[1]*o[1]}(t,e,i)**.5}function Ei(t){let e=0;for(let i=0;i<t.length;i++){let s=i,r=i<t.length-1?i+1:0,n=t[s],o=t[r];e+=n[0]*o[1]-o[0]*n[1]}return.5*e}function Ti(t){return Math.abs(Ei(t))}function Ai(t,e=.1){let i;if(function(t){if(0===t.length)return 0;let e=Ti(t[0]);for(let i=1;i<t.length;i++)e-=Ti(t[i]);return e}(t)<.1)i=function(t){const{min:e,max:i}=Y([t]);return[e[0]+(i[0]-e[0])/2,e[1]+(i[1]-e[1])/2]}(t[0]);else{const s=si(t,e);i=[s[0],s[1]]}return i}function Ii(t){return Ei(t)>0}function Si(t,e){return(t%e+e)%e}function Ci(t,e,i){if(0!==t[0]||0!==t[1]||0!==t[2]||0!==e){let s=at(),r=gt(t[0],t[1],t[2]),n=function(t=0,e=[0,1,0]){let i=t*Math.PI/180,s=Et();return Tt(s,e,i),s}(e,i);return function(t,e,i){var s=e[0],r=e[1],n=e[2],o=e[3],a=s+s,l=r+r,h=n+n,u=s*a,c=s*l,d=s*h,p=r*l,f=r*h,m=n*h,g=o*a,y=o*l,v=o*h;t[0]=1-(p+m),t[1]=c+v,t[2]=d-y,t[3]=0,t[4]=c-v,t[5]=1-(u+m),t[6]=f+g,t[7]=0,t[8]=d+y,t[9]=f-g,t[10]=1-(u+p),t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1}(s,n,r),s}return at()}function Mi(t){let e=ft(),i=Et();dt(e,t),pt(i,t);let s=ft(),r=(n=s,o=i,a=2*Math.acos(o[3]),(l=Math.sin(a/2))>nt?(n[0]=o[0]/l,n[1]=o[1]/l,n[2]=o[2]/l):(n[0]=1,n[1]=0,n[2]=0),a);var n,o,a,l;return 0===r&&(s=[0,1,0]),{position:[e[0],e[1],e[2]],rotation:180*r/Math.PI,rotationAxis:[s[0],s[1],s[2]]}}function Oi(t,e){let i=ft();for(let s=0;s<t.length;s+=3)i[0]=t[s],i[1]=t[s+1],i[2]=t[s+2],wt(i,i,e),t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2]}function Ni(t){let e=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=e[0],t[5]=e[1],t}(function(){var t=new ot(6);return ot!=Float32Array&&(t[1]=0,t[2]=0,t[4]=0,t[5]=0),t[0]=1,t[3]=1,t}(),t.position);return function(t,e,i){var s=e[0],r=e[1],n=e[2],o=e[3],a=e[4],l=e[5],h=Math.sin(i),u=Math.cos(i);t[0]=s*u+n*h,t[1]=r*u+o*h,t[2]=s*-h+n*u,t[3]=r*-h+o*u,t[4]=a,t[5]=l}(e,e,-t.rotation*Math.PI/180),e}function Li(t,e){return function(t,e){let i=St(It(),t.position,e),s=t.rotation+Math.atan2(-e[1],e[0])*(180/Math.PI);return{position:[i[0],i[1]],rotation:Si(s,360)}}(t,Ni(e))}function Ri(t){let e=Ni(t);return function(t,e){var i=e[0],s=e[1],r=e[2],n=e[3],o=e[4],a=e[5],l=i*n-s*r;l&&(l=1/l,t[0]=n*l,t[1]=-s*l,t[2]=-r*l,t[3]=i*l,t[4]=(r*a-n*o)*l,t[5]=(s*o-i*a)*l)}(e,e),function(t){let e=St(It(),It(),t),i=Math.atan2(-t[1],t[0])*(180/Math.PI);return{position:[e[0],e[1]],rotation:Si(i,360)}}(e)}function ki(t,e){return t.map((t=>{let{position:i}=Li({position:t,rotation:0},e);return i}))}function Bi({position:t=[0,0,0],rotation:e=0,rotationAxis:i=[0,1,0],name:s,vertices:r,indices:n,normals:o,uvs:a,material:l}){let h=Je(t,e),u=[],c=[],d=[],p=[],f=at();for(let g=0;g<h.length;g++){let t=h[g],{position:e,rotation:s}=t,l=Ci(e,s,i),m=r.slice();Oi(m,l);let y=u.length/3;for(const i of m)u.push(i);for(const i of n)c.push(y+i);if(Array.isArray(o)){lt(f,l),f[12]=0,f[13]=0,f[14]=0,ht(f,f),ut(f,f);let t=o.slice();Oi(t,f),d.push(...t)}Array.isArray(a)&&p.push(...a)}let m={name:s,vertices:u,indices:c,material:l};return Array.isArray(o)&&(m.normals=d),Array.isArray(a)&&(m.uvs=p),m}class Fi{constructor(){this.polygons=[]}clone(){const t=new Fi;for(const e of this.polygons)t.polygons.push(e.clone());return t}toPolygons(){return this.polygons}union(t){var e=new Fi.Node(this.clone().polygons),i=new Fi.Node(t.clone().polygons);return e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),Fi.fromPolygons(e.allPolygons())}subtract(t){var e=new Fi.Node(this.polygons),i=new Fi.Node(t.polygons);return e.invert(),e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),e.invert(),Fi.fromPolygons(e.allPolygons())}intersect(t){var e=new Fi.Node(this.clone().polygons),i=new Fi.Node(t.clone().polygons);return e.invert(),i.clipTo(e),i.invert(),e.clipTo(i),i.clipTo(e),e.build(i.allPolygons()),e.invert(),Fi.fromPolygons(e.allPolygons())}inverse(){var t=this.clone();return t.polygons.forEach((function(t){t.flip()})),t}}(t=>{function e(t){return[-t[0],-t[1],-t[2]]}function i(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function s(t){const e=function(t){return Math.sqrt(i(t,t))}(t);return[t[0]/e,t[1]/e,t[2]/e]}t.fromPolygons=function(e){var i=new t;return i.polygons=e,i};t.Vertex=class{constructor(t,e){this.pos=t,this.normal=e}clone(){return new t.Vertex([...this.pos],this.normal?[...this.normal]:void 0)}flip(){this.normal&&(this.normal=e(this.normal))}interpolate(e,i){return new t.Vertex(yi(this.pos,e.pos,i),this.normal&&e.normal?yi(this.normal,e.normal,i):void 0)}};const r=class{constructor(t,e){this.normal=t,this.w=e}clone(){return new t.Plane([...this.normal],this.w)}flip(){this.normal=e(this.normal),this.w=-this.w}splitPolygon(e,s,r,n,o){for(var a=0,l=[],h=0;h<e.vertices.length;h++){var u=(v=i(this.normal,e.vertices[h].pos)-this.w)<-t.Plane.EPSILON?2:v>t.Plane.EPSILON?1:0;a|=u,l.push(u)}switch(a){case 0:(i(this.normal,e.plane.normal)>0?s:r).push(e);break;case 1:n.push(e);break;case 2:o.push(e);break;case 3:var c=[],d=[];for(h=0;h<e.vertices.length;h++){var p=(h+1)%e.vertices.length,f=l[h],m=l[p],g=e.vertices[h],y=e.vertices[p];if(2!=f&&c.push(g),1!=f&&d.push(2!=f?g.clone():g),3==(f|m)){var v=(this.w-i(this.normal,g.pos))/i(this.normal,gi(y.pos,g.pos)),x=g.interpolate(y,v);c.push(x),d.push(x.clone())}}c.length>=3&&n.push(new t.Polygon(c,e.shared)),d.length>=3&&o.push(new t.Polygon(d,e.shared))}}};r.EPSILON=1e-5,r.fromPoints=function(e,r,n){var o,a,l=s((o=gi(r,e),a=gi(n,e),[o[1]*a[2]-o[2]*a[1],o[2]*a[0]-o[0]*a[2],o[0]*a[1]-o[1]*a[0]]));return new t.Plane(l,i(l,e))};let n=r;t.Plane=n;t.Polygon=class{constructor(e,i){this.vertices=e,this.shared=i,this.plane=t.Plane.fromPoints(e[0].pos,e[1].pos,e[2].pos)}clone(){const e=[];for(const t of this.vertices)e.push(t.clone());return new t.Polygon(e,this.shared)}flip(){this.vertices.reverse();for(const t of this.vertices)t.flip();this.plane.flip()}};t.Node=class{constructor(t){this.plane=null,this.front=null,this.back=null,this.polygons=[],t&&this.build(t)}clone(){var e=new t.Node;e.plane=this.plane&&this.plane.clone(),e.front=this.front&&this.front.clone(),e.back=this.back&&this.back.clone();for(const t of this.polygons)e.polygons.push(t.clone());return e}invert(){var t;for(let i=0;i<this.polygons.length;i++)this.polygons[i].flip();null==(t=this.plane)||t.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();const e=this.front;this.front=this.back,this.back=e}clipPolygons(t){if(!this.plane)return t.slice();for(var e=[],i=[],s=0;s<t.length;s++)this.plane.splitPolygon(t[s],e,i,e,i);this.front&&(e=this.front.clipPolygons(e)),i=this.back?this.back.clipPolygons(i):[];const r=new Array(e.length+i.length);for(let n=0;n<e.length;n++)r[n]=e[n];for(let n=0;n<i.length;n++)r[e.length+n]=i[n];return r}clipTo(t){this.polygons=t.clipPolygons(this.polygons),this.front&&this.front.clipTo(t),this.back&&this.back.clipTo(t)}allPolygons(t=!0){var e=t?this.polygons.slice():this.polygons;return this.front&&(e=e.concat(this.front.allPolygons(!1))),this.back&&(e=e.concat(this.back.allPolygons(!1))),e}build(e){if(e.length){this.plane||(this.plane=e[0].plane.clone());for(var i=[],s=[],r=0;r<e.length;r++)this.plane.splitPolygon(e[r],this.polygons,this.polygons,i,s);i.length&&(this.front||(this.front=new t.Node),this.front.build(i)),s.length&&(this.back||(this.back=new t.Node),this.back.build(s))}}}})(Fi||(Fi={}));const Di=Fi;function Ui(t,e,i){let s=.5*i,r=[[-s,-s,0],[s,-s,0],[s,s,0],[-s,s,0]],{u:n,v:o,n:a}=function(t){const e=1/Math.sqrt(2);let i=[0,0,0],s=[0,0,0],r=[0,0,0];return bt(r,t),_t(i,Math.abs(r[1])<e?gt(0,1,0):gt(1,0,0),t),_t(s,t,i),bt(i,i),bt(s,s),{u:i,v:s,n:r}}(e),l=t,h=function(t,e,i,s,r,n,o,a,l,h,u,c,d,p,f,m){var g=new ot(16);return g[0]=t,g[1]=e,g[2]=i,g[3]=s,g[4]=r,g[5]=n,g[6]=o,g[7]=a,g[8]=l,g[9]=h,g[10]=u,g[11]=c,g[12]=d,g[13]=p,g[14]=f,g[15]=m,g}(n[0],n[1],n[2],0,o[0],o[1],o[2],0,a[0],a[1],a[2],0,l[0],l[1],l[2],1);for(let u of r)wt(u,u,h);return r}function Gi(t,e){const i=[],s=t.nextId++,{name:r,vertices:n,indices:o,material:a}=e;for(let l=0;l<o.length;l+=3){const t=3*o[l],e=3*o[l+1],h=3*o[l+2],u=[n[t],n[t+1],n[t+2]],c=[n[e],n[e+1],n[e+2]],d=[n[h],n[h+1],n[h+2]],p=[new Di.Vertex(u),new Di.Vertex(c),new Di.Vertex(d)];i.push(new Di.Polygon(p,{id:s,name:r,material:a}))}return i}function Xi(){let t=Math.random(),e=Math.random(),i=Math.random();return He({name:We([t,e,i]),color:[t,e,i],opacity:1})}function Wi(t,e){const i=[],s=[],r={};for(let n=0;n<e.length;n++){const o=3*e[n],a=t[o],l=t[o+1],h=t[o+2],u=73856093*a^19349663*l^83492791*h;let c=r[u];void 0===c&&(c=i.push(a,l,h)/3-1,r[u]=c),s.push(c)}return{vertices:i,indices:s}}function Hi(t,e){const i=[];for(const s of e){const e=Gi(t,s);for(const t of e)i.push(t)}return Di.fromPolygons(i)}function Yi(t,{debugMode:e=!1,sharedVertices:i=!0}={}){const s={},{polygons:r}=t;for(let n=0;n<r.length;n++){const t=r[n],i=t.vertices.length;if(i<3){be.warn(`Skipping CSG polygon with '${i}' '${1===i?"vertex":"vertices"}.`);continue}const o=[];o.length=3*i;for(let e=0;e<i;e++){const i=t.vertices[e];o[3*e]=i.pos[0],o[3*e+1]=i.pos[1],o[3*e+2]=i.pos[2]}let a;if(3===i)a=[0,1,2];else{a=[];for(let t=1;t<i-1;t++)a.push(0,t,t+1)}if(e){const t=Xi();s[n]={name:t.name,vertices:o,indices:a,material:t}}else{const{id:e,name:i,material:r}=t.shared,n=s[e];if(n){const t=n.vertices.length;n.vertices.length=t+o.length;for(let s=0;s<o.length;s++)n.vertices[t+s]=o[s];const e=n.indices.length;n.indices.length=e+a.length;const i=t/3;for(let s=0;s<a.length;s++)n.indices[e+s]=a[s]+i}else s[e]={name:i,vertices:o,indices:a,material:r}}}if(i)for(const n of Object.values(s)){const{vertices:t,indices:e}=n,i=Wi(t,e);n.vertices=i.vertices,n.indices=i.indices}return Object.values(s)}function $i(t,e,i,s){let r,n,o,a,l;if("string"==typeof t){if(r=t,l=e[r],!l)return be.warn(`Geometry '${r}' not found.`),[];n=[0,0,0],o=0,a=[0,1,0]}else{let i=t;if("string"==typeof i.geometry){if(r=i.geometry,l=e[r],!l)return be.warn(`Geometry '${r}' not found.`),[]}else l=i.geometry;n=i.position??[0,0,0],o=i.rotation??0,a=i.rotationAxis??[0,1,0]}if(s.indexOf(l)>-1)return be.warn(`Cycle detected while resolving geometry '${l.id}'.`),[];let h=cs(l,e,i,s);"string"!=typeof t&&"csg:clip"!==t.type&&function(t,e,i,s){let r;if(t.material?t.materials?be.warn("Cannot use 'material' and 'materials' at the same time."):r={[$e]:t.material}:t.materials&&(0===Object.keys(t.materials).length?be.warn("Empty 'materials' field not allowed."):r=t.materials),r)if(r[$e]){let t=Ye(r[$e],i);for(let i of e)i.material=t;Object.keys(r).length>1&&be.warn(`Extraneous material assignments to '${s}' ignored.`)}else for(let[n,o]of Object.entries(r)){let t=e.find((t=>t.name===n));if(t){let e=Ye(o,i);t.material=e}else be.warn(`Surface '${n}' not found in geometry '${s}', skipping material assignment.`)}}(t,h,i,l.id);let u=[];for(let c of h){let{name:t,vertices:e,indices:i,normals:s,uvs:r,material:l}=c,h=Bi({position:n,rotation:o,rotationAxis:a,name:t,vertices:e,indices:i,normals:s,uvs:r,material:l});u.push(h)}return u}function ji(t,e,i,s,r){return[...t,...$i(e,i,s,r)]}function zi(t,e,i,s){let{plane:r,material:n}=i,o=Hi(t,e);{let e=function(t,e,i,s,r=100){let n=t.nextId++,{position:o,normal:a}=e,l=Ye(i,s),h=[0,0,0],u=[0,0,0];bt(h,a),function(t,e,i,s){t[0]=e[0]+i[0]*s,t[1]=e[1]+i[1]*s,t[2]=e[2]+i[2]*s}(u,o,h,r);let c=Ui(o,h,r),d=Ui(u,h,r),p=c.concat(d),f=[[0,1,2,3],[4,5,6,7],[0,4,5,1],[1,5,6,2],[2,6,7,3],[3,7,4,0]],m=[];for(let g of f){let t=[];for(let i of g)t.push(new Di.Vertex(p[i]));let e=new Di.Polygon(t,{id:n,name:"",material:l});m.push(e)}return Di.fromPolygons(m)}(t,r,n,s);o.polygons.length>0&&(o=o.subtract(e))}return Yi(o,{debugMode:!1})}function Vi(t,e,i,s,r,n){const o=$i(i,s,r,n),a=Hi(t,e),l=Hi(t,o);let h=[];if(a.polygons.length&&l.polygons.length){let t;switch(i.type){case"csg:subtract":t=a.subtract(l);break;case"csg:union":t=a.union(l);break;case"csg:intersect":t=a.intersect(l);break;default:t=a}h=Yi(t,{debugMode:!1})}return h}function qi(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function Ji(t,e,i){t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2]}function Ki(t,e){let i=new Array(3*e.length),s=ft(),r=ft(),n=ft(),o=ft(),a=ft(),l=ft(),h=0;for(let u=0;u<e.length;u+=3){let c=e[u],d=e[u+1],p=e[u+2];qi(t,s,3*c),qi(t,r,3*d),qi(t,n,3*p),Pt(o,r,s),Pt(a,n,s),_t(l,o,a),bt(l,l),Ji(i,l,h+0),Ji(i,l,h+3),Ji(i,l,h+6),h+=9}return i}function Zi(t,e){let i=new Array(3*e.length),s=ft(),r=ft(),n=ft(),o=ft(),a=ft(),l=ft(),h=e.length/3,u=new Array(h),c=0;for(let f=0;f<e.length;f+=3){let i=e[f],h=e[f+1],d=e[f+2];qi(t,s,3*i),qi(t,r,3*h),qi(t,n,3*d),Pt(o,r,s),Pt(a,n,s),_t(l,o,a),bt(l,l),u[c++]={index1:i,index2:h,index3:d,normal1:mt(l),normal2:mt(l),normal3:mt(l)}}let d=[];for(let f=0;f<t.length;f++)d[f]={normals:[],normal:ft()};for(let f=0;f<u.length;f++){let t=u[f],{index1:e,index2:i,index3:s}=t;d[e].normals.push(t.normal1),d[i].normals.push(t.normal2),d[s].normals.push(t.normal3)}for(let f=0;f<d.length;f++){let t=d[f],e=t.normals.length;if(e>0){let i=t.normal;yt(i,0,0,0);for(let s=0;s<e;s++)vt(i,i,t.normals[s]);bt(i,i)}}let p=0;for(let f=0;f<e.length;f+=3){let t=e[f],s=e[f+1],r=e[f+2],n=d[t].normal,o=d[s].normal,a=d[r].normal;Ji(i,n,p+0),Ji(i,o,p+3),Ji(i,a,p+6),p+=9}return i}function Qi(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function ts(t,e){let i=new Array(2*e.length),s=ft(),r=ft(),n=ft(),o=ft(),a=ft(),l=ft(),h=0;for(let u=0;u<e.length;u+=3){let c,d,p=e[u],f=e[u+1],m=e[u+2];Qi(t,s,3*p),Qi(t,r,3*f),Qi(t,n,3*m),Pt(o,r,s),Pt(a,n,s),_t(l,o,a),bt(l,l),l[0]=Math.abs(l[0]),l[1]=Math.abs(l[1]),l[2]=Math.abs(l[2]),l[0]>=l[1]&&l[0]>=l[2]?(c=2,d=1):l[1]>=l[0]&&l[1]>=l[2]?(c=0,d=2):(c=0,d=1),i[h++]=s[c],i[h++]=s[d],i[h++]=r[c],i[h++]=r[d],i[h++]=n[c],i[h++]=n[d]}return i}function es(t,e){let i=new Array(2*e.length),s=0;for(let r=0;r<e.length;r++){let n=3*e[r],o=t[n],a=t[n+1],l=t[n+2],h=.5+Math.atan2(o,l)/(2*Math.PI),u=.5+Math.asin(a)/Math.PI;i[s++]=h,i[s++]=u}return i}function is(t,e,i){let s=Math.cos(e),r=Math.sin(e);return[t*r*Math.cos(i),t*s,t*r*Math.sin(i)]}const ss=48,rs=12;function ns(t,e){return[e*Math.cos(t),-e*Math.sin(t)]}function os(t,e,i,s=!0){let r=[],n=e-t,o=function(t,e){let i=Math.ceil(ss/(2*Math.PI)*t*e);const s=Math.ceil(rs/(2*Math.PI)*t);return Math.max(s,i)}(Math.abs(n),i),a=n/o;for(let l=0;l<o;l++){let e=ns(t+l*a,i);r.push(e)}if(s){let t=ns(e,i);r.push(t)}return r}function as(t){let e=[];switch(t.type){case"curve:line":e.push(t.start,t.end);break;case"curve:arc":e=os(Math.PI*t.startAngle/180,Math.PI*t.endAngle/180,t.radius);break;case"curve:polyline":e=t.points}return e}function ls(t){let e=[],i=[],s=[];switch(t.type){case"curve:circle":e=os(0,2*Math.PI,t.radius,!1),i.push({index:0,count:e.length});break;case"curve:polygon":e=t.points;for(let t=0;t<e.length;t++)i.push({index:t,count:1});break;case"curve:polygonWithHoles":e=t.polygons[0];for(let t=0;t<e.length;t++)i.push({index:t,count:1});const r=t.polygons.slice(1);if(r.length>=1){const t=r.length>1?$(r):r;for(let e of t)s.push(ls({type:"curve:polygon",points:e}))}break;case"curve:rectangle":let{dimensions:n}=t,o=n[0],a=n[1];e=[[0,0],[0,a],[o,a],[o,0]];for(let t=0;t<e.length;t++)i.push({index:t,count:1});break;case"curve:composite":const l=1e-7;let h,u,c=t.segments;for(let t=0;t<c.length;t++){let s=as(c[t]),r=s[0],n=s[s.length-1];0===t||ai(r,u,l)||be.warn(`Composite curve segments ${t} and ${t+1} are not continuous.`),0===t&&(h=r),u=n,i.push({index:e.length,count:s.length-1}),e.push(...s.slice(0,s.length-1))}c.length>0&&!ai(u,h,l)&&be.warn("Composite curve not closed.")}return{points:e,segmentRanges:i,holes:s}}function hs(t,e,i){let s,r=i.holes??[],n=i.y??0,o=i.flipSide??!1,a=t,l=[];if(8===a.length&&0===r.length){s=(e?o:!o)?[3,0,1,1,2,3]:[1,0,3,3,2,1]}else{if(r.length>0){let t=new Array(r.length);for(let e=0;e<r.length;e++)t[e]=a.length/2,a=a.concat(r[e]);s=ne(a,t)}else s=ne(a);if(!o)for(let t=0;t<s.length;t+=3){let e=s[t];s[t]=s[t+2],s[t+2]=e}}let h=0;for(let u=0;u<a.length;u+=2)l[h++]=a[u],l[h++]=n,l[h++]=a[u+1];return{vertices:l,indices:s}}function us(t,e,i=0,s=!1){let r=new Array(2*t*3),n=0;for(let o=0;o<t;o++){o===t-1?s?(r[n++]=o+i,r[n++]=i,r[n++]=e+i,r[n++]=o+i,r[n++]=e+i,r[n++]=o+e+i):(r[n++]=e+i,r[n++]=i,r[n++]=o+i,r[n++]=o+e+i,r[n++]=e+i,r[n++]=o+i):s?(r[n++]=o+i,r[n++]=o+1+i,r[n++]=o+e+1+i,r[n++]=o+i,r[n++]=o+e+1+i,r[n++]=o+e+i):(r[n++]=o+e+1+i,r[n++]=o+1+i,r[n++]=o+i,r[n++]=o+e+i,r[n++]=o+e+1+i,r[n++]=o+i)}return r}function cs(t,e,i,s=[]){var r;let n,o=[];switch(t.type){case"geometry:plane":n=function(t){let{normal:e,size:i,doubleSided:s}=t,r=Ui([0,0,0],e,i).flat(),n=[0,1,2,0,2,3],o=[{index:0,count:2}];return s&&(n=n.concat([0,2,1,0,3,2]),o.push({index:2,count:2})),{vertices:r,indices:n,faces:o}}(t);break;case"geometry:cuboid":n=function(t){let{dimensions:e}=t,i=e[0],s=e[1],r=e[2],n=[0,s,r,i,s,r,i,s,0,0,s,0,0,0,r,i,0,r,i,0,0,0,0,0],o=[];for(let a=0;a<6;a++)o.push({index:2*a,count:2});return{vertices:n,indices:[0,1,2,0,2,3,4,7,6,4,6,5,0,4,5,0,5,1,1,5,6,1,6,2,2,6,7,2,7,3,3,7,4,3,4,0],faces:o}}(t);break;case"geometry:sphere":n=function(t){const e=16,i=16;let s,r,n=t.radius,o=[],a=[],l="generator"===t.uvs?[]:void 0;o.push(0,n,0);for(let u=1;u<i;u++){let t=Math.PI*u/i;for(let i=0;i<e;i++){let s=is(n,t,2*Math.PI*i/e);o.push(s[0],s[1],s[2])}}let h=o.push(0,-n,0)/3-1;s=1,r=.9375;for(let u=0;u<e;u++){let t=1+u,i=1+(u+1)%e;if(a.push(0,i,t),l){let t=1-u/e,i=1-(u+1)/e,n=.5*(t+i);l.push(n,s,i,r,t,r)}}for(let u=0;u<14;u++)for(let t=0;t<e;t++){let s=1+u*e+t,r=1+u*e+(t+1)%e,n=1+(u+1)*e+(t+1)%e,o=1+(u+1)*e+t;if(a.push(s,r,n),a.push(s,n,o),l){let s=1-t/e,r=1-(u+1)/i,n=1-(t+1)/e,o=1-(u+2)/i;l.push(s,r,n,r,n,o),l.push(s,r,n,o,s,o)}}s=.0625,r=0;for(let u=0;u<e;u++){let t=225+u,i=225+(u+1)%e;if(a.push(t,i,h),l){let t=1-u/e,i=1-(u+1)/e,n=.5*(t+i);l.push(t,s,i,s,n,r)}}return{vertices:o,indices:a,uvs:l,faces:[{index:0,count:a.length/3}]}}(t);break;case"geometry:extrusion":n=function(t){let{profile:e,height:i}=t,s=ls(e),{points:r,segmentRanges:n,holes:o}=s,a=r.flat(),l=[],h=r.length,u=[{points:r,segmentRanges:n}];for(let w of o)l.push(w.points.flat()),u.push(w),h+=w.points.length;let c=Ii(r),d=hs(a,c,{y:i,flipSide:!1,holes:l}),p=hs(a,c,{y:0,flipSide:!0,holes:l}),f=[];f.push(...d.vertices),f.push(...p.vertices);let m=d.indices,g=p.indices.map((t=>t+h)),y=[];y.push(...m),y.push(...g);let v=m.length/3,x=[];x[0]={index:0,count:v},x[1]={index:v,count:v};let b=2*v,_=0;for(let w=0;w<u.length;w++){let{points:t,segmentRanges:e}=u[w],i=0===w?Ii(t):!Ii(t),s=us(t.length,d.vertices.length/3,_,i);_=t.length,y.push(...s);for(let r of e){let t=b+2*r.index,e=2*r.count;x.push({index:t,count:e})}b+=2*t.length}return{vertices:f,indices:y,faces:x}}(t);break;case"geometry:mesh":n=function(t){let{vertices:e,indices:i,normals:s,uvs:r}=t,n={vertices:e,indices:i,faces:[]};return Array.isArray(s)&&(n.normals=s),Array.isArray(r)&&(n.uvs=r),n}(t);break;default:return be.warn(`Invalid geometry type ${t.type}.`),o}o=qe(t,n,i),"geometry:plane"!==t.type&&"geometry:cuboid"!==t.type&&"geometry:sphere"!==t.type&&"geometry:extrusion"!==t.type||(null==(r=t.geometries)?void 0:r.length)&&(s.push(t),o=function(t,e,i,s,r){let n={nextId:0},o=t.geometries??[];for(let a of o)e="string"==typeof a||"reference:geometry"===a.type?ji(e,a,i,s,r):"csg:clip"===a.type?zi(n,e,a,s):Vi(n,e,a,i,s,r);return e}(t,o,e,i,s),s.pop());let a=[];for(let u of o){let{name:e,vertices:i,indices:s,normals:r,uvs:n,material:o}=u,{position:l,rotation:h,rotationAxis:c}=t,d=Bi({position:l,rotation:h,rotationAxis:c,name:e,vertices:i,indices:s,normals:r,uvs:n,material:o});a.push(d)}o=a;let l=t.normals??"flat";if("flat"===l||"smooth"===l)for(let u of o){let{vertices:t,indices:e}=u;u.normals="flat"===l?Ki(t,e):Zi(t,e)}let h=t.uvs??"automatic";if("automatic"==h||"spherical"===h)for(let u of o){let{vertices:t,indices:e}=u;u.uvs="automatic"===h?ts(t,e):es(t,e)}return o}function ds(t){let e,i,s,r={min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]};for(let n=0;n<t.length;n+=3)e=t[n],i=t[n+1],s=t[n+2],r.min[0]=Math.min(r.min[0],e),r.max[0]=Math.max(r.max[0],e),r.min[1]=Math.min(r.min[1],i),r.max[1]=Math.max(r.max[1],i),r.min[2]=Math.min(r.min[2],s),r.max[2]=Math.max(r.max[2],s);return r}class ps{constructor(){this.vertices=[],this.edges=[],this.geometryProfile=[]}toJSON(){return{edges:this.edges.map((t=>t.id))}}}function fs(t,e){return"integer"===e.type?"number"==typeof t&&Number.isInteger(t):typeof t===e.type&&(!("enum"in e)||e.enum.includes(t))}const ms={"spatialStructure:layout":"layout","layout:space":"space","product:static":"product","product:component":"product","spatialStructure:building":"building","spatialStructure:floor":"floor","element:asset":"element","element:beam":"element","element:casework":"element","element:column":"element","element:door":"element","element:kitchen":"element","element:railing":"element","element:ramp":"element","element:roof":"element","element:slab":"element","element:stairs":"element","element:stairFlight":"element","element:window":"element","element:generic":"element","element:floor":"element","element:ceiling":"element","element:boundaryWall":"element","element:curtainWall":"element","element:opening":"element","element:spaceDivider":"element","element:wall":"element"},gs=(t,e)=>{const i=ms[e];return i||be.error(`Missing custom attribute resource type for node type: "${e}"`),`${t}:${i}`};function ys(t,e){if("boolean"===e.type&&"string"==typeof t){if("true"===t.toLowerCase())return!0;if("false"===t.toLowerCase())return!1}if("number"===e.type&&"string"==typeof t){const e=Number(t);if(!isNaN(e))return e}return null}class vs extends we{constructor(t,e){super(t,"customAttribute:definition"),this.attributes={resourceType:"space",schema:{type:"string"}},e&&this.setAttributes(e)}getInputType(){return function(t){switch(t.type){case"integer":return"Integer";case"boolean":return"Boolean";case"number":return"Number";case"string":return"enum"in t?"Select":"Text"}}(this.attributes.schema)}setAttributes(t){let e=this.attributes;e.resourceType=t.resourceType??e.resourceType,e.updatedAt=t.updatedAt??e.updatedAt,e.description=t.description??e.description,e.schema=function(t){return t.schema?JSON.parse(JSON.stringify(t.schema)):"Text"===t.valueType?{type:"string"}:"Number"===t.valueType?{type:"number"}:"Boolean"===t.valueType?{type:"boolean"}:void 0}(t)}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes))}toJSON(){const t=super.toJSON();let e={resourceType:this.attributes.resourceType,schema:JSON.parse(JSON.stringify(this.attributes.schema))};return void 0!==this.attributes.updatedAt&&(e.updatedAt=this.attributes.updatedAt),void 0!==this.attributes.description&&(e.description=this.attributes.description),t.attributes=e,t}}const xs={"customAttribute:definition":vs};class bs extends we{constructor(t,e){super(t,e),this.customAttributes={}}setCustomAttributes(t,e){let i=null,s=!1;if(null===t&&(this.customAttributes={},s=!0),t&&e)for(const r in t){let n=t[r];if(null===n){delete this.customAttributes[r],s=!0;continue}const o=gs(r,this.type),a=e[o];if(a){if(!fs(n,a.attributes.schema)){let t=ys(n,a.attributes.schema);if(null===t){be.error(`Value type mismatch for custom attribute. Received value: "${n}". Expected type: ${a.attributes.schema.type}`),i=`Value type mismatch for custom attribute. Received value: "${n}". Expected type: ${a.attributes.schema.type}`;continue}n=t}this.customAttributes[r]!==n&&(this.customAttributes[r]=n,s=!0)}else i=`Missing custom attribute definition for node key: "${r}", node type: "${this.type}" and definition id: ${o}`}s&&this.emit("node-custom-attributes-change",this),i&&be.error(i)}toJSON(){const t=super.toJSON();return Object.keys(this.customAttributes).length>0&&(t.customAttributes=JSON.parse(JSON.stringify(this.customAttributes))),t}copyForClone(t){super.copyForClone(t),this.customAttributes=JSON.parse(JSON.stringify(t.customAttributes))}}class _s extends bs{constructor(t,e){super(t,e),this.layout=null}}class ws extends _s{}class Ps extends ws{constructor(t,e,i){super(t,"spatialGraph:vertex"),this.position=[0,0],this.edges=[],this.position[0]=e,this.position[1]=i}sortVertexEdges(){let t=[];for(let e of this.edges){let i=this===e.vertices[0]?e.vertices[1]:e.vertices[0],s=ni([i.position[0]-this.position[0],i.position[1]-this.position[1]]);t.push({edge:e,edgeAngle:s})}t.sort(((t,e)=>t.edgeAngle-e.edgeAngle)),this.edges=t.map((t=>t.edge))}addEdge(t){this.edges.push(t),this.sortVertexEdges(),this.emit("vertex-add-edge",this,t)}removeEdge(t){let e=this.edges.indexOf(t);if(e>-1){let t=this.edges.splice(e,1)[0];this.emit("vertex-remove-edge",this,t)}else be.error(`Vertex does not reference edge ${t.id}.`)}setPosition(t,e){this.position[0]=t,this.position[1]=e,this.edges.length>0&&(this.layout.spatialGraph.graphChanged=!0),this.emit("vertex-set-position",this)}toJSON(){return{...super.toJSON(),position:[...this.position]}}}function Es(t,e,i,s,r=!1){if(e.layout)return be.warn(`${s} ${e.id} already part of layout ${e.layout.id}.`),!1;if(i[e.id])return be.error(`${s} ${e.id} already registered in layout.`),!1;let n=t.spaceGraph;if(n&&n.nodesById[e.id])return be.error(`${s} ${e.id} already registered in space graph.`),!1;if(e.type.startsWith("space:")){let t=e;if(t.slabs.length>0)return be.warn(`Detached space ${t.id} references boundary slab elements.`),!1}else if(e.type.startsWith("element:")){let n=e;if(r&&n.parent)return be.warn(`${s} ${n.id} already a child of ${s} ${n.parent.id}.`),!1;for(let e of n.elements)if(!Es(t,e,i,s,!1))return!1}return!0}function Ts(t,e){if(e.layout=t,t.elementsById[e.id])return void be.error(`Element ${e.id} already registered.`);t.elementsById[e.id]=e;const i=t.elementsByType[e.type];i||(be.warn(`unrecognized layout element type: ${e.type}`),t.elementsByType[e.type]=[]),i.push(e);let s=t.spaceGraph;s&&("element:asset"===e.type&&e.product&&!s.productsById[e.product.id]&&s.insertProduct(e.product),s.registerNode(e),s.emit("element-create",e));for(let r of e.elements)Ts(t,r)}function As(t,e,i){for(let o of e.elements)As(t,o,e);if(t.elementsById[e.id]!==e)return void be.error(`Entry ${e.id} in 'elements stored by ID' record does not contain this object.`);delete t.elementsById[e.id];const s=t.elementsByType[e.type],r=null==s?void 0:s.indexOf(e);if(!s||-1===r)return void be.error(`element ${e.id} not found in 'elements stored by type' record.`);s.splice(r,1);let n=t.spaceGraph;n&&(n.unregisterNode(e),n.emit("element-delete",e,i)),e.layout=null}function Is(t){return"object"==typeof t&&null!==t}function Ss(t){return Is(t)&&!function(t){return Array.isArray(t)||ArrayBuffer.isView(t)}(t)}function Cs(t,e,i,s){Ss(t)&&Ss(e)||be.error("Both arguments must be objects.");let{onNewKeys:r,copyScopes:n,cloneObjects:o}=s,a=Object.keys(e);for(let l of a){if(r){let{allow:e,excludedScopes:s}=r;if(e===(!!s&&s.includes(i))&&!(l in t)){be.warn(`Key '${l}' not found in scope ${i}, skipped.`);continue}}let a=e[l],h=t[l];if(Is(a)){let e=`${i}.${l}`;!(null==n?void 0:n.includes(e))&&Ss(h)?Cs(h,a,e,s):t[l]=o?JSON.parse(JSON.stringify(a)):a}else t[l]=a}}function Ms(t,e,i={onNewKeys:{allow:!1,excludedScopes:[]},copyScopes:[],cloneObjects:!0}){let s;i.onNewKeys?(s=i.onNewKeys,s.allow=i.onNewKeys.allow??!1,s.excludedScopes=i.onNewKeys.excludedScopes??[]):s={allow:!1,excludedScopes:[]},Cs(t,e,"",{onNewKeys:s,copyScopes:i.copyScopes??[],cloneObjects:i.cloneObjects??!0})}function Os(t,e){t.name=e.name??t.name,t.customId=e.customId??t.customId}function Ns(t,e,i){t.setCustomAttributes(e.customAttributes,i)}function Ls(t){let e=t.getEdges();return 1===e.length?e[0].id:e.map((t=>t.id))}function Rs(t){let e;switch(t.type){case"element:ceiling":case"element:floor":e=function(t){let e=[];for(let i of t.boundaries){let t=i.toJSON();e.push(t)}return{id:t.id,type:t.type,boundaries:e,parameters:{height:t.parameters.height,elevation:t.parameters.elevation,materials:{...t.parameters.materials}}}}(t);break;case"element:boundaryWall":e=function(t){let e=[];for(let s of t.boundaries){let t=s.toJSON();e.push(t)}let i=JSON.parse(JSON.stringify(t.parameters.surfaces));return{id:t.id,type:t.type,boundaries:e,parameters:{height:t.parameters.height,elevation:t.parameters.elevation,surfaces:i,materials:{...t.parameters.materials}}}}(t);break;case"element:curtainWall":e={id:(n=t).id,type:n.type,edge:Ls(n)};break;case"element:spaceDivider":e={id:(r=t).id,type:r.type,edge:Ls(r)};break;case"element:wall":e=function(t){let{width:e,height:i,offset:s,elevation:r,materials:n}=t.parameters;return{id:t.id,type:t.type,parameters:{width:e,height:i,offset:s,elevation:r,materials:{...n}},edge:Ls(t)}}(t);break;case"element:opening":e=function(t){let{position:e,dimensions:i,materials:s}=t.parameters;return{id:t.id,type:t.type,parameters:{position:[...e],dimensions:[...i],materials:{...s}}}}(t);break;case"element:asset":e={id:(i=t).id,type:i.type,position:[...i.position],rotation:i.rotation,rotationAxis:i.rotationAxis,product:null==(s=i.product)?void 0:s.id,geometries:JSON.parse(JSON.stringify(i.geometries))};break;case"element:beam":case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:kitchen":case"element:railing":case"element:ramp":case"element:roof":case"element:slab":case"element:stairs":case"element:stairFlight":case"element:window":e=function(t){let e={id:t.id,type:t.type,position:[...t.position],parameters:JSON.parse(JSON.stringify(t.parameters)),rotation:t.rotation,rotationAxis:t.rotationAxis};return"element:generic"!==t.type&&"element:asset"!==t.type||(e.geometries=JSON.parse(JSON.stringify(t.geometries))),e}(t);break;default:return void be.warn(`Unknown element type '${t.type}, skipping element.`)}var i,s,r,n,o,a;if(o=e,""!==(a=t).name&&(o.name=a.name),""!==a.customId&&(o.customId=a.customId),function(t,e){e.customAttributes===Object(e.customAttributes)&&Object.keys(e.customAttributes).length>0&&(t.customAttributes=e.customAttributes)}(e,t),t.elements.length){e.elements=[];for(let i of t.elements){let t=Rs(i);t&&e.elements.push(t)}}return e}class ks extends _s{constructor(){super(...arguments),this.parent=null,this.elements=[],this.geometries=[]}insertElement(t){let e=this.layout;e&&!Es(e,t,e.elementsById,"Element",!0)||(t.parent=this,this.elements.push(t),e&&Ts(e,t))}getTransform(){return{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}getWorldTransform(){return this.getTransform()}getBoundingBox(t=!1){return{min:[0,0,0],max:[0,0,0],transform:{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}}getAxisAlignedBoundingBox(t=!1){return function({min:t,max:e,transform:i}){if(0===i.rotation)return{min:mi(t,i.position),max:mi(e,i.position)};{let s=Ci(i.position,i.rotation,i.rotationAxis);const r=[[...t],[...e],[t[0],t[1],e[2]],[e[0],e[1],t[2]]];for(const t of r)wt(t,t,s);return ds(r.flat())}}(this.getBoundingBox(t))}getBoundingBoxContour(t=!1){const{min:[e,,i],max:[s,,r],transform:n}=this.getBoundingBox(t),{position:[o,,a],rotation:l}=n;return ki([[e,i],[s,i],[s,r],[e,r]],{position:[o,a],rotation:l})}get isExternal(){if(this.parent)return this.parent.isExternal;const t=this.getSpaces().flatMap((t=>t?[t]:[]));return!t.length||t[0].isExternal}removeElement(t){if(t.parent!==this)return void be.warn(`Element ${t.id} not a child of element ${this.id}.`);let e=this.elements.indexOf(t);if(-1===e)return void be.error(`Element ${t.id} not found in parent ${this.id}.`);let i=t.parent;t.parent=null,this.elements.splice(e,1),t.layout&&As(t.layout,t,i)}copyForClone(t){super.copyForClone(t),this.parameters=JSON.parse(JSON.stringify(t.parameters)),this.geometries=JSON.parse(JSON.stringify(t.geometries))}setParameters(t){Ms(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("element-parameters-change",this)}getSpaces(){return this.parent?this.parent.getSpaces():[]}toJSON(){return Rs(this)}}function Bs(t,e,i){let s=t.getAxisLength(),r=[];for(let n of t.elements)if("element:opening"===n.type){let t=n.parameters.position[0],o=t/s,a=(t+n.parameters.dimensions[0])/s;i?e>=o&&e<a&&r.push(n):e>o&&e<a&&r.push(n)}return r}class Fs extends ks{constructor(t,e,i){super(t,e),this.edges=[],this.vertices=[],this.edgesChanged=!1,this.setEdges(i)}setEdges(t){var e,i;if(!t.length)return this.edges=[],void(this.vertices=[]);if(1===t.length)return this.edges=[t[0]],void(this.vertices=[t[0].vertices[0],t[0].vertices[1]]);const s=function(t){var e;const i=new Map;for(const s of t)for(const t of s.vertices)i.has(t)||i.set(t,[]),null==(e=i.get(t))||e.push(s);return i}(t),r=[];let n,o;for(const[h,u]of s.entries())if(1===u.length){n=u[0];const t=n.vertices.find((t=>t!==h));if(2!==(null==(e=s.get(t))?void 0:e.length))return void be.error("Edge sequence is not continuous");r.push(h,t),o=t;break}if(!n||!o)return void be.error("Unable to find start of edge sequence");const a=[n];let l=n;for(;a.length<t.length;){const t=o&&(null==(i=s.get(o))?void 0:i.find((t=>t!==l)));if(!t)return void be.error("Edge sequence is not continuous");if(a.includes(t))return void be.error("Duplicate Edge in sequence",t.id,l.id);const e=t.vertices.find((t=>t!==o));r.push(e),a.push(t),o=e,l=t}this.edges=a,this.vertices=r,this.edgesChanged=!1,this.emit("element-edges-change",this)}verifyEdges(){this.edgesChanged&&this.edges.length&&this.setEdges(this.edges)}getEdges(){return[...this.edges]}getVertices(){return this.verifyEdges(),[...this.vertices]}getStartVertex(){return this.verifyEdges(),this.vertices.at(0)}getEndVertex(){return this.verifyEdges(),this.vertices.at(-1)}getAxisPoints(){const t=this.getStartVertex(),e=this.getEndVertex();return t&&e?[t.position,e.position]:[]}getAxisLength(){const[t,e]=this.getAxisPoints();return t&&e?li(fi(t,e)):0}getEdgeAtLinearPosition(t){if(t<0||t>1)return;if(1===this.edges.length)return this.edges[0];let e=this.getAxisLength();if(!e)return;let i=this.vertices[0].position;for(let s=0;s<this.vertices.length-1;s++){if(hi(i,this.vertices[s+1].position)/e>=t)return this.edges[s]}}getEdgesAtLinearSegment(t,e){if(t>e)return[];if(1===this.edges.length)return[this.edges[0]];let i=this.getAxisLength();if(!i)return[];let s=[],r=this.vertices[0].position,n=r;for(let o=0;o<this.vertices.length-1;o++){let a=this.vertices[o+1].position,l=hi(r,n)/i,h=hi(r,a)/i;(t<=l&&e>=h||t>=l&&t<h||e>l&&e<=h)&&s.push(this.edges[o]),n=a}return s}get edge(){return be.warn("Use getEdges() instead of edge"),this.edges[0]||null}getAdjacentElementsByVertex(){let t=[[],[]];for(let e=0;e<this.vertices.length;e++){let i=this.vertices[e].edges.filter((t=>t.element&&t.element.id!==this.id)).map((t=>t.element));t[e]=i}return t}getAdjacentSpacesBySide(){let t=[[],[]];for(let e=0;e<2;e++){let i=this.edges.filter((t=>t.spaces[e])).map((t=>t.spaces[e]));t[e]=i}return t}getSpaces(){let t=[];for(let e of this.edges)e.spaces[0]&&t.push(e.spaces[0]),e.spaces[1]&&t.push(e.spaces[1]);return t}getElementsAtLinearPosition(t){return Bs(this,t,!0)}get isExternal(){let t=0,e=0;for(const i of this.getEdges())i.isExternal?t+=i.getLength():e+=i.getLength();return t>=e}}function Ds(t){for(let e of t.elements)if("element:door"===e.type){let t=e.parameters;t.hingeSide="right"===t.hingeSide?"left":"right",t.doorSide="side1"===t.doorSide?"side2":"side1"}}class Us extends ws{constructor(t,e,i){super(t,"spatialGraph:edge"),this.spaces=[void 0,void 0],this.boundaryWalls=[null,null],this.element=null,this.vertices=[e,i]}getPoints(){return[this.vertices[0].position,this.vertices[1].position]}getLength(){return hi(...this.getPoints())}get isExternal(){return this.spaces.some((t=>!t||t.isExternal))}setVertices(t,e){if(t===e)return void be.warn("Cannot set both edge vertices to the same vertex.");let i,s,r=this.vertices[0],n=this.vertices[1];this.vertices[0]=t,this.vertices[1]=e,r!==t?(r.removeEdge(this),t.addEdge(this),i=!0):i=!1,n!==e?(n.removeEdge(this),e.addEdge(this),s=!0):s=!1,this.layout.spatialGraph.graphChanged=!0,this.element&&(this.element.edgesChanged=!0),(i||s)&&this.emit("edge-set-vertices",this,{previousVertices:[r,n]})}setVerticesByIds(t,e){let i=this.layout.spatialGraph,s=i.verticesById[t];if(!s)return void be.error(`Cannot find vertex ${t}.`);let r=i.verticesById[e];r?this.setVertices(s,r):be.error(`Cannot find vertex ${e}.`)}canSplit(t,e={}){let{minimumLength:i}=e;if(void 0!==i){if(t<0||t>1)return!1;let[e,s]=this.getPoints(),r=ui(e,s,t),n=li(fi(r,e)),o=li(fi(r,s));if(n<i||o<i)return!1}else if(t<=0||t>=1)return!1;if(this.element){let[e,i]=this.getPoints(),s=ui(e,i,t),[r]=this.element.getAxisPoints();if(!r)return!1;let n=this.element.getAxisLength(),o=hi(r,s)/n;return 0===Bs(this.element,o,!1).length}return!0}split(t,e={},i=!1){var s,r,n;let o=this.layout.spatialGraph,a=this.vertices[0],l=this.vertices[1],h=null==(s=this.element)?void 0:s.getAxisLength(),u=null==(n=null==(r=this.element)?void 0:r.getStartVertex())?void 0:n.position,[c,d]=this.getPoints(),p=ui(c,d,t),f=e.vertexId??(this.layout.debugIds?o.debugVertexCount.toString():de()),m=o.verticesById[f]??o.createVertex(f,p[0],p[1]);this.setVertices(a,m);let g=e.edgeId??o.getEdgeId(),y=o.createEdge(g,m,l);if(y.spaces[0]=this.spaces[0],y.spaces[1]=this.spaces[1],y.boundaryWalls[0]=this.boundaryWalls[0],y.boundaryWalls[1]=this.boundaryWalls[1],this.element&&e.elementId&&h&&u){let i=hi(u,p)/h,s=this.element.getEdges(),r=s.indexOf(this)+1,n=[y,...s.splice(r)];this.element.setEdges(s);let o=e.elementId??this.layout.getElementId(this.element),a=this.layout.createElement(this.element.type,o,n);a.parameters=JSON.parse(JSON.stringify(this.element.parameters));let l=hi(u,p),c=[...this.element.elements];for(let e of c)if("element:opening"===e.type){let s=e.parameters.position[0],r=s/h,n=(s+e.parameters.dimensions[0])/h;i<=r?(e.parameters.position[0]=r*h-l,this.element.removeElement(e),a.insertElement(e)):t<n&&be.warn(`Opening ${e.id} overlaps split position.`)}}else if(this.element){const t=this.element.getEdges();this.element.setEdges([...t,y]),y.element=this.element}if(i)for(let v of y.spaces){if(!v)continue;let{boundary:t}=v.getBoundaryFromEdge(this);if(t){let e,i=t.vertices.indexOf(a),s=t.vertices.indexOf(l);e=0===i&&s===t.vertices.length-1?s:0===s&&i===t.vertices.length-1||i<s?i:s,t.vertices.splice(e+1,0,m),t.edges=[];for(let r=0;r<t.vertices.length;r++){let e=r,i=r<t.vertices.length-1?r+1:0,s=t.vertices[e],n=t.vertices[i],a=o.getEdgeFromVertices(s,n);a?t.edges.push(a):be.error(`Cannot find edge with vertices ${s.id} and ${n.id}.`)}}else be.error(`Edge ${this.id} not found in space boundary.`)}for(let v of y.boundaryWalls){if(!v)continue;let t,e=v.boundaries[0],i=e.vertices.indexOf(a),s=e.vertices.indexOf(l);t=0===i&&s===e.vertices.length-1?s:0===s&&i===e.vertices.length-1||i<s?i:s,e.vertices.splice(t+1,0,m),e.edges=[];for(let r=0;r<e.vertices.length;r++){let t=r,i=r<e.vertices.length-1?r+1:0,s=e.vertices[t],n=e.vertices[i],a=o.getEdgeFromVertices(s,n);a?e.edges.push(a):be.error(`Cannot find edge with vertices ${s.id} and ${n.id}.`)}}return{vertex:m,edge:y,element:undefined}}canMerge(t){if(this.element&&!t.element||!this.element&&t.element)return!1;let e,i=this.vertices[0],s=this.vertices[1],r=t.vertices[0],n=t.vertices[1];if(i===r)e=[s,i,n];else if(i===n)e=[s,i,r];else if(s===r)e=[i,s,n];else{if(s!==n)return!1;e=[i,s,r]}if(0!==vi(e[0].position,e[1].position,e[2].position))return!1;let o=e[1];return!(!o.edges.includes(this)||!o.edges.includes(t))}merge(t,e=!1){var i;if(this.element&&!t.element||!this.element&&t.element)return void be.warn("Either none or both edges must have an element, cannot merge.");let s,r,n=this.layout.spatialGraph,o=this.vertices[0],a=this.vertices[1],l=t.vertices[0],h=t.vertices[1];if(o===l)s=[h,o,a],r=!0;else if(o===h)s=[l,o,a],r=!1;else if(a===l)s=[o,a,h],r=!1;else{if(a!==h)return void be.warn(`Edge ${this.id} does not share a vertex with edge ${t.id}, cannot merge.`);s=[o,a,l],r=!0}let u=s[0].position,c=s[1].position;if(0!==vi(u,c,s[2].position))return void be.warn(`Edges ${this.id} and ${t.id} are not collinear, cannot merge.`);let d=s[1];if(d.edges.includes(this)&&d.edges.includes(t)||be.error(`Common vertex ${d.id} edge list does not contain either one or both edges, cannot merge.`),t.element&&r&&function(t){let e=t.getAxisLength();for(let i of t.elements){if("element:opening"!==i.type)continue;let t=i.parameters;t.position[0]=e-(t.position[0]+t.dimensions[0]),Ds(i)}}(t.element),this.setVertices(s[0],s[2]),this.element&&this.element===t.element){const e=this.element.getEdges(),i=e.indexOf(t);e.splice(i,1),this.element.setEdges(e),t.element=null}else if(this.element&&t.element){const e=t.element.getEdges(),s=e.indexOf(t);e.splice(s,1);let r=[...this.element.getEdges(),...e];this.element.setEdges(r),t.element.setEdges([t]);for(const t of r)t.element=this.element;let n=null==(i=this.element.getStartVertex())?void 0:i.position;if(!n)return;let o=hi(c,n),a=[...t.element.elements];for(let i of a){if("element:opening"!==i.type)continue;t.element.removeElement(i),this.element.insertElement(i),i.parameters.position[0]+=o}}if(e)for(let p of t.spaces){if(!p)continue;let{boundary:e,edgeIndex:i}=p.getBoundaryFromEdge(t);if(e){e.edges.splice(i,1);let t=e.vertices.indexOf(s[1]);t>-1?e.vertices.splice(t,1):be.error(`Cannot find vertex ${s[1].id} in space ${p.id}`)}else be.error(`Cannot find edge ${t.id} in space ${p.id}.`)}for(let p of t.boundaryWalls){if(!p)continue;let e=p.boundaries[0],i=e.edges.indexOf(t);if(i>-1){e.edges.splice(i,1);let t=e.vertices.indexOf(s[1]);t>-1?e.vertices.splice(t,1):be.error(`Cannot find vertex ${s[1].id} in boundary wall ${p.id}`)}else be.error(`Cannot find edge ${t.id} in boundary wall ${p.id}.`)}t.spaces[0]=null,t.spaces[1]=null,t.boundaryWalls[0]=null,t.boundaryWalls[1]=null,n.removeEdge(t),0===d.edges.length&&n.removeVertex(d)}toJSON(){const t=this.vertices[0],e=this.vertices[1];return{...super.toJSON(),vertices:[t.id,e.id]}}}const Gs={usage:"generic",program:"none"};function Xs(t,e){const i=e.parent,s=i.getAxisLength(),{position:r,dimensions:n}=e.parameters,o=r[0]/s,a=(r[0]+n[0])/s;return i.getEdgesAtLinearSegment(o,a).some((e=>e.spaces[0]===t||e.spaces[1]===t))}class Ws extends _s{constructor(t,e){super(t,"layout:space"),this.boundaries=[],this.slabs=[],this.attributes={...Gs},this.boundaries=e,this.geometry={polygons:[]}}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes)),this.geometry=JSON.parse(JSON.stringify(t.geometry))}setId(t){if(t===this.id)return;let e=this.layout;if((null==e?void 0:e.spacesById[t])||(null==e?void 0:e.elementsById[t])||(null==e?void 0:e.annotationsById[t]))return void be.error(`ID ${t} already in use in layout ${e.id}.`);if(e&&e.spacesById[this.id]!==this)return void be.error(`Entry ${this.id} in 'spaces stored by ID' record does not contain space ${this.id}.`);let i=this.spaceGraph;if(null==i?void 0:i.nodesById[t])return void be.error(`ID ${t} already in use in space graph object.`);if(i&&i.nodesById[this.id]!==this)return void be.error(`Entry ${this.id} in 'nodes stored by ID' record does not contain space ${this.id}.`);let s=this.id;this.id=t,e&&(delete e.spacesById[s],e.spacesById[this.id]=this),i&&(delete i.nodesById[s],i.nodesById[this.id]=this),this.emit("node-id-change",this,s)}setAttributes(t){this.attributes.usage=t.usage??this.attributes.usage,this.attributes.program=t.program??this.attributes.program,this.emit("space-attributes-change",this)}get isExternal(){return["balcony","terrace","buildingOpening"].includes(this.attributes.usage)}getArea(){let t=this.geometry.polygons;if(0===t.length)return be.error(`Geometry has not been computed for space ${this.id}.`),0;let e=Ti(t[0]);for(let i=1;i<t.length;i++){e-=Ti(t[i])}return e}getAdjacentSpaces(t,{connectivity:e}={}){var i;let s=null==(i=t.nodeMap.get(this))?void 0:i.get("graph:adjacentTo");if(!s)return[];if(void 0===e)return Array.from(s);{let i=0===e?2:2*e;return Array.from(s).filter((s=>{let r=t.findShortestPath("graph:connectedTo",s,this,{depthLimit:i});return!!(null==r?void 0:r.length)&&(0!==e||"element:spaceDivider"===r[1].type)}))}}getElements(t){let e=t&&(Array.isArray(t)?t:[t]),i=[],s=this.layout.getElementList();for(let r of s){if(e&&!e.includes(r.type))continue;let t;switch(r.type){case"element:ceiling":case"element:floor":t=r.space===this;break;case"element:boundaryWall":break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":t=r.getEdges().some((t=>t.spaces[0]===this||t.spaces[1]===this));break;case"element:opening":t=Xs(this,r);break;case"element:door":case"element:window":t=Xs(this,r.parent);break;default:{let e,i=r;if(i.parent){let t=i.parent;for(;t.parent;)t=t.parent;e=t.getTransform().position}else e=i.position;t=wi([e[0],e[2]],this.geometry.polygons);break}}t&&i.push(r)}return i}getBoundaryFromVertex(t){for(let e of this.boundaries){let i=e.vertices.indexOf(t);if(i>-1)return{boundary:e,itemIndex:i}}return{boundary:void 0,itemIndex:-1}}getBoundaryFromEdge(t){for(let e of this.boundaries){let i=e.edges.indexOf(t);if(i>-1)return{boundary:e,edgeIndex:i}}return{boundary:void 0,edgeIndex:-1}}getBoundingBox(){const t=Y([this.geometry.polygons[0]]);let e=0,i=0;for(const s of this.slabs)"element:floor"===s.type&&(e=s.parameters.elevation),"element:ceiling"===s.type&&(i=s.parameters.elevation);return{min:[t.min[0],e,t.min[1]],max:[t.max[0],i,t.max[1]],transform:{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}}getAxisAlignedBoundingBox(){const{min:t,max:e}=this.getBoundingBox();return{min:t,max:e}}getBoundingBoxContour(){const{min:[t,,e],max:[i,,s]}=this.getBoundingBox();return[[t,e],[i,e],[i,s],[t,s]]}attachSlab(t){if(null!==t.space)return void be.warn(`Boundary slab ${t.id} already attached to space ${t.space.id}.`);this.slabs.indexOf(t)>-1?be.warn(`Boundary slab ${t.id} already referenced by space ${this.id}.`):(t.boundaries=this.boundaries,t.space=this,this.slabs.push(t))}detachSlab(t){if(t.space!==this)return void be.warn(`Boundary slab ${t.id} not attached to space ${this.id}.`);let e=this.slabs.indexOf(t);-1!==e?(t.space=null,t.boundaries=gr(this.boundaries),this.slabs.splice(e,1)):be.warn(`Boundary slab ${t.id} not referenced by space ${this.id}.`)}toJSON(){const{program:t,usage:e}=this.attributes,i={...super.toJSON(),boundaries:[],attributes:{program:t,usage:e}};for(const s of this.boundaries)i.boundaries.push(s.toJSON());return i}}class Hs extends ks{constructor(t,e,i){super(t,e),this.boundaries=gr(i)}getBoundingBox(){const t=[0,0,0],e=[0,0,0],i=Y([this.boundaries[0].geometryProfile]);return t[0]=i.min[0],e[0]=i.max[0],t[2]=i.min[1],e[2]=i.max[1],"element:floor"===this.type?(t[1]=this.parameters.elevation-this.parameters.height,e[1]=this.parameters.elevation):(t[1]=this.parameters.elevation,e[1]=this.parameters.elevation+this.parameters.height),{min:t,max:e,transform:this.getTransform()}}}const Ys={top:"#202020",bottom:"#000000",side1:"asm:basic-wall",side2:"asm:basic-wall",join1:"asm:basic-wall",join2:"asm:basic-wall"},$s={width:.15,height:3,offset:0,elevation:0,materials:{...Ys}};class js extends Fs{constructor(t,e){super(t,"element:wall",e);for(const i of e)i.element=this;this.parameters=JSON.parse(JSON.stringify($s)),this.geometryProfile={valid:!0,skipped:!1,selfIntersecting:!1,sidePoints1:[],sidePoints2:[],joinPoints1:[],joinPoints2:[],points:[]}}copyForClone(t){super.copyForClone(t),this.geometryProfile=JSON.parse(JSON.stringify(t.geometryProfile))}setParameters(t){super.setParameters(t)}getBoundingBox(){const t=[0,0,0],e=[0,0,0],[i,s]=this.getAxisPoints();if(!i||!s)return super.getBoundingBox();const r={position:i,rotation:-(xi(i,s)/Math.PI*180)},n={position:[i[0],0,i[1]],rotation:r.rotation,rotationAxis:[0,1,0]},o=Y([ki(this.geometryProfile.points,Ri(r))]);return t[0]=o.min[0],e[0]=o.max[0],t[2]=o.min[1],e[2]=o.max[1],t[1]=this.parameters.elevation,e[1]=this.parameters.elevation+this.parameters.height,{min:t,max:e,transform:n}}}const zs={"element:ceiling":{height:.2,elevation:$s.elevation+$s.height,materials:{top:"#808080",bottom:"asm:basic-ceiling",sides:"asm:basic-wall"}},"element:floor":{height:.2,elevation:0,materials:{top:"asm:basic-floor",bottom:"#808080",sides:"asm:basic-wall"}}};class Vs extends Hs{constructor(t,e,i){super(t,e,i);let s=zs[this.type];this.parameters=JSON.parse(JSON.stringify(s)),this.space=null}setParameters(t){super.setParameters(t)}getSpaces(){return null===this.space?[]:[this.space]}}function qs(t,e){var i;let s,r=t.vertices.map((t=>t.position)),n=[];for(let o of t.edges){if("element:wall"!==(null==(i=o.element)?void 0:i.type))continue;let t=o.element.geometryProfile.points;n.push(t)}if(0===n.length)s=[r];else if(e){s=q([r],$(n))}else s=$([r,...n]);return s=s.filter((t=>Q(t)>1e-7)),0===s.length?(be.warn("No valid polygons, returning boundary polygon."),r):(s=et(s,.001),s=s.filter((t=>t.length>0)),0===s.length?(be.warn("No valid polygons after filtering, returning boundary polygon."),r):(s.length>1&&(be.warn(`Result has ${s.length} polygons, returning largest one.`),s=s.sort(((t,e)=>Q(e)-Q(t)))),s[0]))}function Js(t,e){var i;let s=[qs(e.boundaries[0],!0)];for(let o=1;o<e.boundaries.length;o++){s=q(s,[qs(e.boundaries[o],!1)])}let{edges:r}=t.spatialGraph,n=[];for(let o of r){if(o.spaces[0]!==e||o.spaces[1]!==e||"element:wall"!==(null==(i=o.element)?void 0:i.type))continue;let[t,r]=o.getPoints();if(wi(ui(t,r,.5),s)){let t=o.element.geometryProfile.points;n.push(t)}}n.length>0&&(s=q(s,n)),s.sort(((t,e)=>{let i=Q(t);return Q(e)-i})),e.geometry.polygons=s}function Ks(t,e){return new Array(e-t).fill(void 0).map(((e,i)=>t+i))}function Zs(t){return`${t.type.split(":")[1]}Geometry-${t.id.substring(0,8)}`}function Qs(t){let e;switch(t.type){case"curve:rectangle":e=4;break;case"curve:polygon":e=t.points.length;break;case"curve:polygonWithHoles":e=t.polygons.reduce(((t,e)=>t+Qs({type:"curve:polygon",points:e})),0);break;case"curve:composite":e=t.segments.reduce(((t,e)=>t+Qs(e)),0);break;case"curve:polyline":e=t.points.length-1;break;case"curve:circle":case"curve:arc":case"curve:line":e=1}return e}function tr(){return We([Math.random(),Math.random(),Math.random()])}function er(t,e=!1){let{materials:i,height:s,elevation:r}=t.parameters,n="element:floor"===t.type?-s:0,o=[];for(let d=1;d<t.boundaries.length;d++){let e=t.boundaries[d].geometryProfile.slice();o.push(e)}o=$(o);let a=t.boundaries[0].geometryProfile.slice(),l=r+n,h={id:`boundarySlabGeometry-${t.id}-boundary`,type:"geometry:extrusion",position:[0,l,0],height:s,profile:{type:"curve:polygonWithHoles",polygons:[a,...o]},geometries:[]},u={top:[0],bottom:[1],sides:Ks(2,2+a.length)},c={top:e?tr():i.top,bottom:i.bottom,sides:i.sides};h.surfaces=u,h.materials=c,t.geometries=[{type:"reference:geometry",geometry:h}],t.emit("geometry-update",t)}function ir(t){for(let e=0;e<t.boundaries.length;e++){const i=t.boundaries[e];for(const s of i.edges){const r=s.vertices[0],n=s.vertices[1],o=i.vertices.indexOf(r),a=i.vertices.indexOf(n);let l,h;if(l=0===o?1===a:o===i.vertices.length-1?0===a:a-o==1,h=0===e?l?1:0:l?0:1,null===s.spaces[h])s.spaces[h]=t;else{const t=0===h?"left":"right";be.error(`Edge ${s.id} already references a space on its ${t} side.`)}}}}function sr(t){for(const e of t.boundaries)for(const i of e.edges)i.spaces[0]||null!==i.boundaryWalls[0]?i.spaces[1]||null!==i.boundaryWalls[1]?be.error(`Edge ${i.id} referenced by more than two adjacent nodes.`):i.boundaryWalls[1]=t:i.boundaryWalls[0]=t}function rr(t,e){let i=t.spatialGraph;for(let s=0;s<e.edges.length;s++){let t=e.edges[s],r=i.edgesById[t.id];r?e.edges[s]=r:i.insertEdge(t)}cr(e)}function nr(t,e){if(0!==e.boundaries.length){for(let i of e.boundaries)rr(t,i);switch(e.type){case"element:boundaryWall":sr(e);break;case"element:ceiling":case"element:floor":{let i=function(t,e){for(const i of t.spaces){if(i.boundaries.length!==e.length)continue;let t=0;for(;t<i.boundaries.length;){if(!dr(i.boundaries[t],e[t]))break;t++}if(t===i.boundaries.length)return fr(i,[{boundaries:e}])?i:void 0}return}(t,e.boundaries);i?i.attachSlab(e):be.warn(`Matching space not found for boundary slab element ${e.id}.`);break}}}else be.warn(`Boundary slab element ${e.id} does not specify boundaries.`)}function or(t,e){let i=t.spatialGraph;const s=e.getEdges(),r=new Set(s);let n=!1;for(let o of s){let t=i.edgesById[o.id];t?(n=!0,r.delete(o),r.add(t)):i.insertEdge(o)}n&&e.setEdges(Array.from(r)),function(t){for(const e of t.getEdges())null===e.element?e.element=t:e.element!==t&&be.error(`Edge ${e.id} referenced by more than one edge element.`)}(e)}function ar(t){var e;switch(t.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":!function(t){switch(t.type){case"element:boundaryWall":for(let e of t.boundaries)for(let i of e.edges)i.boundaryWalls[0]===t&&(i.boundaryWalls[0]=null),i.boundaryWalls[1]===t&&(i.boundaryWalls[1]=null);break;case"element:ceiling":case"element:floor":{let e=t.space;e?e.detachSlab(t):be.warn(`Boundary slab element ${t.id} not attached to a space.`);break}}}(t);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":!function(t){for(const e of t.getEdges())e.element=null}(t);break;case"element:asset":null==(e=t.product)||e.instances.delete(t)}}function lr(t){const e=[];for(const i of t.boundaries){const t=[];for(const e of i.vertices)t.push(e.position);e.push(t)}return e}function hr(t){let e=[];if(0===t.length)return e;if(1===t.length){let i=t[0];return e.push(i.vertices[0]),e.push(i.vertices[1]),e}for(let i=0;i<t.length;i++){let s=t[i],r=t[(i+1)%t.length],n=s.vertices[0],o=s.vertices[1],a=r.vertices[0],l=r.vertices[1];if(n===a||n===l)e.push(o);else{if(o!==a&&o!==l)return void be.warn(`Could not add edge ${s.id} to current path.`);e.push(n)}}return e}function ur(t){let e=[];for(let i=0;i<t.length-1;i++){let s=t[i],r=t[i+1];for(let t of s.edges)if(r.edges.indexOf(t)>-1){e.push(t);break}}return e}function cr(t){let e=hr(t.edges);if(!e)return!1;if(t.vertices=e,t.geometryProfile=t.vertices.map((t=>t.position)),!Ii(t.geometryProfile)){let{vertices:e,edges:i,geometryProfile:s}=t;e.reverse(),s.reverse();{i.reverse();let t=e[e.length-1],s=i[0];s.vertices[0]!==t&&s.vertices[1]!==t||(e.pop(),e.unshift(t))}}return!0}function dr(t,e,i){if(t.edges.length!==e.edges.length)return!1;const s=function(t,e){let i=0;for(const s of t.edges)for(const t of e.edges)if(s.id===t.id){i++;break}return i}(t,e);let r;return r=s===t.edges.length,r}function pr(t,e,i){if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++){if(!dr(t[s],e[s]))return!1}return!0}function fr(t,e){const i=e.map((t=>[t.boundaries[0].geometryProfile])),{polygons:s}=V(i,.01),{polygons:r}=V(s,-.01);if(0===r.length)return be.warn(`No union polygon, cannot match space ${t.id}.`),!1;if(r.length>1)return be.warn(` Disjoint union area, cannot match space ${t.id}.`),!1;const n=r[0][0],o=t.boundaries[0].geometryProfile,a=J([[o]],[[n]]).polygons,l=J([[n]],[[o]]).polygons,h=a.length?tt(a[0]):0,u=l.length?tt(l[0]):0;return h<.01&&u<.01}function mr(t){let e=new ps;return e.vertices=[...t.vertices],e.edges=[...t.edges],e.geometryProfile=JSON.parse(JSON.stringify(t.geometryProfile)),e}function gr(t){let e=[];for(let i of t){let t=mr(i);e.push(t)}return e}function yr(t,e,i){for(let s of t.edges)s.spaces[0]===e?s.spaces[0]=i:s.spaces[1]===e?s.spaces[1]=i:be.warn(`Edge ${s.id} not in space ${e.id} boundary.`)}function vr(t,e,i,s){let r=function(t,e,i,s){let r=t.vertices,n=Math.min(e,i),o=Math.max(e,i),a=o-n+1,l=r.length-a+2;if(a<3||l<3)return be.warn("Cannot split boundary, both fragments should have three or more vertices."),[];let h=r.slice(0,n+1),u=r.slice(n,o+1),c=r.slice(o,r.length).concat(h),d=u,p=ur(c).concat(s),f=ur(d).concat(s),m=c.map((t=>t.position)),g=d.map((t=>t.position)),y=new ps;y.vertices=c,y.edges=p,y.geometryProfile=m;let v=new ps;return v.vertices=d,v.edges=f,v.geometryProfile=g,[y,v]}(t.boundaries[0],e,i,s);if(!r)return void be.warn(`Could not split outer boundary of space ${t.id}.`);let n=[r[0]],o=[r[1]];for(let f=1;f<t.boundaries.length;f++){let e=t.boundaries[f],i=e.vertices[0].position;if(_i(i,r[0].geometryProfile))n.push(e);else{if(!_i(i,r[1].geometryProfile)){be.warn("Inner boundary is not contained by either of the two split boundaries.");continue}o.push(e)}}let a,l,h=t.layout;(null==h?void 0:h.debugIds)?(a=h.getSpaceId(),l=h.getSpaceId()):(a=de(),l=de());let u=new Ws(a,n),c=new Ws(l,o);for(let f of n)yr(f,t,u);for(let f of o)yr(f,t,c);for(let f of n)u.geometry.polygons.push(f.geometryProfile);for(let f of o)c.geometry.polygons.push(f.geometryProfile);Js(h,u),Js(h,c);let d=[],p=[];for(let f=0;f<t.slabs.length;f++){let e,i,s=t.slabs[f];if(null==h?void 0:h.debugIds){let t="element:ceiling"===s.type?"ceiling":"floor";e=`${t}-${f+1}-in-${a}`,i=`${t}-${f+1}-in-${l}`}else e=de(),i=de();let r=new Vs(e,s.type,n),u=new Vs(i,s.type,o);er(r,!0),er(u,!0),d.push(r),p.push(u)}return{spaces:[u,c],slabs:[d,p]}}function xr(t,e){let{position:i,rotation:s,rotationAxis:r}=t.getTransform(),n=Ci(i,s,r);return e&&ct(n,e,n),n}function br(t){let e;return t.parent&&(e=br(t.parent)),xr(t,e)}function _r(t,e){switch(e.type){case"annotation:floorPlanDxf":case"annotation:floorPlanImage":return{name:"annotation",nodes:t.annotations,nodesById:t.annotationsById,nodesByType:t.annotationsByType};case"view:2d":case"view:3d":return{name:"view",nodes:t.views,nodesById:t.viewsById,nodesByType:t.viewsByType}}}class wr{constructor(t){this.vertices=[],this.verticesById={},this.edges=[],this.edgesById={},this.graphChanged=!1,this.debugVertexCount=0,this.debugEdgeCount=0,this.layout=t}emit(t,...e){let i=this.layout.spaceGraph;i&&i.emit(t,...e)}copyForClone(t){this.debugVertexCount=t.debugVertexCount,this.debugEdgeCount=t.debugEdgeCount}deleteVertexAtIndex(t,e){let i=this.vertices[t];if(e){let t=i.edges.slice();for(let s of t){let t=s.vertices[0],r=s.vertices[1];t!==i&&r!==i||this.removeEdge(s,e)}}if(this.vertices.splice(t,1),this.verticesById[i.id]===i)return delete this.verticesById[i.id],i;be.error(`Entry ${i.id} in 'vertices by ID' record does not contain this object.`)}deleteEdgeAtIndex(t,e){let i=this.edges[t];if(i.element&&this.layout.removeElement(i.element),i.vertices[0].removeEdge(i),i.vertices[1].removeEdge(i),e){if(i.spaces[0]!==i.spaces[1]){if(i.spaces[0]){let t=i.spaces[0].slabs;for(let e of t)this.layout.removeElement(e);this.layout.removeSpace(i.spaces[0])}if(i.spaces[1]){let t=i.spaces[1].slabs;for(let e of t)this.layout.removeElement(e);this.layout.removeSpace(i.spaces[1])}}i.boundaryWalls[0]&&this.layout.removeElement(i.boundaryWalls[0]),i.boundaryWalls[1]&&this.layout.removeElement(i.boundaryWalls[1])}if(this.edges.splice(t,1),this.edgesById[i.id]===i)return delete this.edgesById[i.id],this.graphChanged=!0,i;be.error(`Entry ${i.id} in 'edges by id' record does not contain this object.`)}insertVertex(t){if(!Es(this.layout,t,this.edgesById,"Edge"))return;t.layout=this.layout,this.vertices.push(t),this.verticesById[t.id]=t;let e=this.layout.spaceGraph;e&&(e.registerNode(t),e.emit("vertex-create",t))}removeVertex(t,e=!1){let i=this.vertices.indexOf(t);if(-1===i)return void be.warn(`Vertex ${t.id} not found.`);this.deleteVertexAtIndex(i,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(t),s.emit("vertex-delete",t)),t.layout=null,t}removeVertexAtIndex(t,e=!1){let i=this.vertices[t];if(!i)return void be.warn(`Vertex not found at index ${t}.`);this.deleteVertexAtIndex(t,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(i),s.emit("vertex-delete",i)),i.layout=null,i}removeVertexById(t,e=!1){let i=this.verticesById[t];if(i&&i.id===t)return this.removeVertex(i,e);be.error(`Entry ${t} in 'vertices by id' record does not contain this object.`)}insertEdge(t,e=!1){if(!Es(this.layout,t,this.edgesById,"Edge"))return;let i=this.verticesById[t.vertices[0].id],s=this.verticesById[t.vertices[1].id];i?t.vertices[0]=i:this.insertVertex(t.vertices[0]),s?t.vertices[1]=s:this.insertVertex(t.vertices[1]),t.layout=this.layout,this.edges.push(t),this.edgesById[t.id]=t,t.vertices[0].addEdge(t),t.vertices[1].addEdge(t);let r=this.layout.spaceGraph;r&&(r.registerNode(t),r.emit("edge-create",t)),e&&function(t){let e=t.layout,i=t.vertices[0],s=t.vertices[1];for(let r of e.spaces){let n=r.boundaries[0],o=n.vertices.indexOf(i),a=n.vertices.indexOf(s);if(o>-1&&a>-1){t.spaces[0]=r,t.spaces[1]=r;let i=vr(r,o,a,t);if(i){let s=r.slabs.slice();for(let t of s)e.removeElement(t);e.removeSpace(r);let[n,o]=i.spaces,[a,l]=i.slabs;e.insertSpace(n);for(let t of a)e.insertElement(t);e.insertSpace(o);for(let t of l)e.insertElement(t);t.emit("space-split",r,[n,o]),n.emit("geometry-profile-update",n),o.emit("geometry-profile-update",o);for(let t of n.slabs)t.emit("geometry-profile-update",t);for(let t of o.slabs)t.emit("geometry-profile-update",t)}else be.warn(`Failed to split space ${r.id}.`);break}}}(t),this.graphChanged=!0}removeEdge(t,e=!1){let i=this.edges.indexOf(t);if(-1===i)return void be.warn(`Edge ${t.id} not found.`);this.deleteEdgeAtIndex(i,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(t),s.emit("edge-delete",t)),t.layout=null,t}removeEdgeAtIndex(t,e=!1){let i=this.edges[t];if(!i)return void be.warn(`Edge not found at index ${t}.`);this.deleteEdgeAtIndex(t,e);let s=this.layout.spaceGraph;return s&&(s.unregisterNode(i),s.emit("edge-delete",i)),i.layout=null,i}removeEdgeById(t,e=!1){let i=this.edgesById[t];if(i&&i.id===t)return this.removeEdge(i,e);be.error(`Entry ${t} in 'edges by id' record does not contain this object.`)}getEdgeFromVertices(t,e){let i=t.edges,s=e.edges;for(let r of i)for(let t of s)if(r===t)return r}getVertexId(t){return this.layout.debugIds?(t??"vertex-")+this.debugVertexCount:de()}getEdgeId(t){return this.layout.debugIds?(t??"edge-")+this.debugEdgeCount:de()}createVertex(t,e,i){let s=new Ps(t,e,i);return this.insertVertex(s),s}createEdge(t,e,i,s=!1){let r=new Us(t,e,i);return this.insertEdge(r,s),r}createEdgeByVertexIds(t,e,i,s=!1){let r=this.verticesById[e],n=this.verticesById[i];return this.createEdge(t,r,n,s)}toJSON(){let t=[];for(let i of this.vertices){let e=i.toJSON();t.push(e)}let e=[];for(let i of this.edges){let t=i.toJSON();e.push(t)}return{vertices:t,edges:e}}}const Pr={height:3,elevation:0,surfaces:{top:[0],bottom:[1],sides:"..."},materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class Er extends Hs{constructor(t,e){super(t,"element:boundaryWall",e),this.parameters=JSON.parse(JSON.stringify(Pr))}setParameters(t){super.setParameters(t)}}const Tr={materials:{}};class Ar extends Fs{constructor(t,e){super(t,"element:curtainWall",e);for(const i of e)i.element=this;this.parameters=JSON.parse(JSON.stringify(Tr))}setParameters(t){super.setParameters(t)}}const Ir={materials:{}};class Sr extends Fs{constructor(t,e){super(t,"element:spaceDivider",e);for(const i of e)i.element=this;this.parameters=JSON.parse(JSON.stringify(Ir))}setParameters(t){super.setParameters(t)}getBoundingBox(){const[t,e]=this.getAxisPoints();if(!t||!e)return super.getBoundingBox();const i=hi(t,e),s=xi(t,e)/Math.PI*180;return{min:[0,0,-.01],max:[i,0,.01],transform:{position:[t[0],0,t[1]],rotation:-s,rotationAxis:[0,1,0]}}}}class Cr extends ks{constructor(t,e){super(t,e)}}function Mr(t,e,i=0){let{width:s,offset:r,elevation:n}=t.parameters,[o,a]=t.getAxisPoints();if(!o||!a)return{position:[0,0,0],rotation:0};let l=fi(a,o),h=li(l),u=ui(o,a,e.parameters.position[0]/h);u=ri(u,pi(di(ci(l)),-.5*s+r-i));let c=e.parameters.position[1]+n;return{position:[u[0],c,u[1]],rotation:180*-ni(fi(a,o))/Math.PI}}function Or(t,e,i,s){const r=.001;let n=s.parameters.dimensions[0],o=s.parameters.dimensions[1],{width:a,elevation:l}=e.parameters,{position:[h,u,c],rotation:d}=Mr(e,s,r),p=s.parameters.materials,f={id:i,type:"geometry:cuboid",position:[h,u-r-l,c],rotation:d,dimensions:[n,o+r,a+.002],surfaces:{top:[0],bottom:[1],frontBack:[2,4],sides:[3,5]}},m={top:p.top,bottom:p.bottom,frontBack:"#FFFFFF",sides:p.sides};f.materials=m;let g=e.geometries[0].geometry;g.geometries??(g.geometries=[]),g.geometries.push({type:"csg:subtract",geometry:f}),s.emit("geometry-update",s)}function Nr(t,e){let i,s={},r=Ks(0,e);for(let[n,o]of Object.entries(t))if("string"==typeof o)"..."===o?i=n:be.warn("Invalid surface definition string.");else if(Array.isArray(o)){s[n]=[];for(let t of o){if(t<0||t>=e){be.warn(`Face index ${t} out of range when defining surface ${n}.`);continue}let i=r.indexOf(t);-1!==i?(s[n].push(t),r.splice(i,1)):be.warn(`Face index ${t} already assigned when defining surface ${n}.`)}}else be.warn("Invalid surface definition.");return i&&r.length>0&&(s[i]=r),s}function Lr(t){let e,{surfaces:i,materials:s}=t.parameters;for(let r=0;r<t.boundaries.length;r++){let n=t.boundaries[r],o=t.parameters.elevation,a=hr(n.edges);if(!a)return void be.warn(`Could not create geometry for boundary wall ${t.id}.`);let l=a.map((t=>t.position)),h=0===r?"boundary":"hole-"+r,u={id:`boundaryWallGeometry-${t.id}-${h}`,type:"geometry:extrusion",position:[0,o,0],height:t.parameters.height,profile:{type:"curve:polygon",points:l},geometries:[]};u.surfaces=Nr(i,2+l.length),u.materials=JSON.parse(JSON.stringify(s)),0===r?(e=u,t.geometries=[{type:"reference:geometry",geometry:u}]):e.geometries.push({type:"csg:subtract",geometry:u})}t.emit("geometry-update",t)}function Rr(t){let{length:e,height:i,frameThickness:s,frameDepth:r,doorAngle:n,hingeSide:o,doorSide:a,doorType:l,materials:h}=t.parameters,u="right"===o,c=[e/2,r/2],d=Zs(t),p=.05,f=[],m=(180-Math.min(180,Math.max(0,n)))/180,g=(r-p)/2,y=e-2*s,v=i-s;switch(l){case"singleSwing":u?f.push({position:[s-c[0],0,-c[1]],rotation:n,dimensions:[y,v,p]}):f.push({position:[c[0]-s,0,-c[1]],dimensions:[p,v,y],rotation:270-n});break;case"doubleSwing":y=e/2-s,f.push({position:[s-c[0],0,-c[1]],rotation:n,dimensions:[y,v,p]}),f.push({position:[c[0]-s,0,-c[1]],rotation:270-n,dimensions:[p,v,y]});break;case"slidingDoor":y=(e-2*s)*m;let t=u?s-c[0]:c[0]-y-s;f.push({position:[t,0,-c[1]+g],rotation:0,dimensions:[y,v,p]});break;case"garageDoor":f.push({position:[s-c[0],v*(1-m),-c[1]+g],rotation:0,dimensions:[y,v*m,p]});break;case"elevatorDoor":y=(e-2*s)/2-.005,f.push({position:[s-c[0],0,-c[1]+g],rotation:0,dimensions:[y,v,p]}),f.push({position:[0,0,-c[1]+g],rotation:0,dimensions:[y,v,p]})}let x=[];for(let b=0;b<f.length;b++){let{position:t,rotation:e,dimensions:i}=f[b],s={id:d+"-leaf-"+b,type:"geometry:cuboid",position:t,rotation:e,dimensions:i,material:h.leaf};x.push({type:"reference:geometry",position:[c[0],0,c[1]],rotation:"side2"===a?180:0,geometry:s})}return x}function kr(t,e,i){let s=Zs(t),{stepCount:r,stepHeight:n,angle:o,radius:a,width:l,circulation:h}=i,u=a-l,c=a-l/2,d=Math.PI*o/180*c/r/(u+l/2),p=[0,n,0],f=180/Math.PI*d,m=0;"right"===h&&(f=-f,m=180);let g=function(t,e,i){let{stepThickness:s,stepHeight:r,angle:n,width:o,stepCount:a,radius:l,circulation:h}=i,u=l-o/2,c=l-o,d=Math.PI*n/180*u/a/(c+o/2),p="right"===h,f=r,m=c,g=(p?-1:1)*Math.sin(d)*c,y=r-s,v=Math.cos(d)*c,x=-s,b=c+o,_=(p?-1:1)*Math.sin(d)*(c+o),w=Math.cos(d)*(c+o),P=[0,f,m,0,0,m,g,y,v,g,f,v,0,x,m,0,f,b,0,0,b,_,y,w,_,f,w,0,x,b],E=[0,8,3,0,5,8,0,3,2,0,2,1,1,2,4,0,6,5,0,1,6,5,7,8,5,6,7,6,9,7,2,7,4,4,7,9,8,7,3,7,2,3];if(p)for(let T=0;T<E.length;T+=3){let t=E[T+1];E[T+1]=E[T+2],E[T+2]=t}return{id:t,type:"geometry:mesh",vertices:P,indices:E,rotation:0,surfaces:{top:[0,1],base:[2,3,4,5,6,7,8,9,10,11,12,13]},materials:{top:e.tread,base:e.steps}}}(s,e,i);return{type:"reference:geometry",position:{type:"vector3:range",range:{start:[0,0,0],step:p,count:r}},rotation:{type:"number:range",range:{start:m,step:f,count:r}},geometry:g}}function Br(t){let{width:e,height:i,materials:s}=t.parameters;const r=Math.round(i/.17),n={height:i,width:e,stepCount:r,stepHeight:i/r,stepThickness:.1};let o;if("straight"===t.parameters.stairFlightType){let{length:e}=t.parameters;o=function(t,e,i){let{stepCount:s,width:r,stepHeight:n,length:o,stepThickness:a}=i,l=o/s,h=[l,n,0],u=function(t,e,i){let{riser:s,tread:r,width:n,thickness:o}=i;return{id:t,type:"geometry:extrusion",rotation:90,rotationAxis:[1,0,0],height:n,profile:{type:"curve:polygon",points:[[0,0],[0,o],[r,o-s],[r,-s],[0,-s]]},surfaces:{top:[5],base:[0,1,2,3,4,6]},materials:{top:e.tread,base:e.steps}}}(Zs(t),e,{tread:l,riser:n,width:r,thickness:a});return{type:"reference:geometry",position:{type:"vector3:range",range:{start:[0,0,0],step:h,count:s}},geometry:u}}(t,s,{...n,length:e})}else{let{radius:e,angle:i,circulation:r}=t.parameters;o=kr(t,s,{...n,radius:e,angle:i,circulation:r})}t.geometries=[o],t.emit("geometry-update",t)}function Fr(t,e=!1){let{sidePoints1:i,sidePoints2:s,joinPoints1:r,joinPoints2:n,points:o}=t.geometryProfile;if(0===o.length)return;let a="wallGeometry-"+t.id,l={id:a,type:"geometry:extrusion",position:[0,t.parameters.elevation,0],height:t.parameters.height,profile:{type:"curve:composite",segments:[{type:"curve:polyline",points:i},{type:"curve:polyline",points:r},{type:"curve:polyline",points:s},{type:"curve:polyline",points:n}]}},h=t.parameters.materials,u={top:[0],bottom:[1],side1:[2],side2:[4]},c={top:e?tr():h.top??Ys.top,bottom:h.bottom??Ys.bottom,side1:h.side1??Ys.side1,side2:h.side2??Ys.side2},[d,p]=function(t){let e=[!1,!1],i=[t.getStartVertex(),t.getEndVertex()];for(let s=0;s<i.length;s++){let t=i[s];t&&(t.edges.filter((t=>{var e;return"element:wall"===(null==(e=t.element)?void 0:e.type)})).map((t=>t.element)).length>0?e[s]=!0:be.error(`Vertex ${t.id} not referencing edge that references it.`))}return e}(t);d&&(u.join1=[3],c.join1=h.join1??Ys.join1),p&&(u.join2=[5],c.join2=h.join2??Ys.join2),l.surfaces=u,l.materials=c,t.geometries=[{type:"reference:geometry",geometry:l}];for(let f=0;f<t.elements.length;f++){let e=t.elements[f];if("element:opening"!==e.type)continue;let i=a+"-opening-"+(f+1);Or(t.layout,t,i,e)}t.emit("geometry-update",t)}function Dr(t){switch(t.type){case"element:asset":case"element:beam":case"element:curtainWall":case"element:opening":case"element:ramp":case"element:roof":case"element:spaceDivider":case"element:stairs":break;case"element:casework":!function(t){let{length:e,width:i,height:s,counterHeight:r,materials:n}=t.parameters,o=Math.min(.6,e),a=Math.floor(e/o),l=e%o,h=i-.02,u=s-r,c=.02,d=Zs(t),p=[],f=t.elements;for(let y of f)if("product"in y&&y.product){let{min:t,max:e}=y.product.attributes.boundingBox,i=gi(t,[0,.01,0]),s=gi(e,i),r=mi(i,y.position);p.push({id:d+"-subtraction-"+y.id.substring(0,8),type:"geometry:cuboid",position:[...r],dimensions:s})}let m=[];r>0&&m.push({id:d+"-counter",type:"geometry:cuboid",position:[0,u,0],dimensions:[e,r,i],material:n.counter}),m.push({id:d+"-doors",type:"geometry:cuboid",position:{type:"vector3:range",range:{start:[c,c,h],step:[o,0,0],count:a}},dimensions:[o-.04,u-.04,c],material:n.cabinetDoors}),l>.04&&m.push({id:d+"-doors+2",type:"geometry:cuboid",position:[a*o+c,c,h],dimensions:[l-.04,u-.04,c],material:n.cabinet});let g={id:d+"-cabinet",type:"geometry:cuboid",position:[0,0,0],dimensions:[e,u,h],geometries:[...m.map((t=>({type:"reference:geometry",geometry:t}))),...p.map((t=>({type:"csg:subtract",geometry:t})))],material:n.cabinet};t.geometries=[{type:"reference:geometry",geometry:g}],t.emit("geometry-update",t)}(t);break;case"element:column":!function(t){let{profile:e,height:i,materials:s}=t.parameters,r=Zs(t),n=[0,0,0];"curve:rectangle"===e.type&&(n=[-e.dimensions[0]/2,0,-e.dimensions[1]/2]);let o={id:r,type:"geometry:extrusion",position:n,profile:e,height:i},a=Qs(e);o.surfaces={top:[0],bottom:[1],sides:Ks(2,2+a)},o.materials={top:s.top,bottom:s.bottom,sides:s.sides},t.geometries=[{type:"reference:geometry",geometry:o}],t.emit("geometry-update",t)}(t);break;case"element:ceiling":case"element:floor":er(t);break;case"element:boundaryWall":Lr(t);break;case"element:door":!function(t){let{height:e,length:i,frameThickness:s,frameDepth:r,materials:n}=t.parameters,o=Zs(t),a={id:o+"-frame-top",type:"geometry:cuboid",position:[0,e-s,0],rotation:0,dimensions:[i,s,r],material:n.frame},l={id:o+"-frame-side",type:"geometry:cuboid",position:{type:"vector3:list",list:[[0,0,0],[i-s,0,0]]},rotation:0,dimensions:[s,e-s,r],material:n.frame};t.geometries=[{type:"reference:geometry",geometry:a},{type:"reference:geometry",geometry:l},...Rr(t)],t.emit("geometry-update",t)}(t);break;case"element:generic":!function(t){let{profile:e,height:i,materials:s}=t.parameters;if("none"===e)return;let r=Qs(e),n={id:Zs(t),type:"geometry:extrusion",position:[0,0,0],profile:e,height:i,surfaces:{top:[0],bottom:[1],sides:Ks(2,2+r)},materials:{top:s.top,bottom:s.bottom,sides:s.sides}};t.geometries=[{type:"reference:geometry",geometry:n}],t.emit("geometry-update",t)}(t);break;case"element:railing":!function(t){let e,{height:i,length:s,width:r,segmentCount:n,segmentLength:o,materials:a}=t.parameters,l=.01;e=o&&o>0?Math.max(Math.round(s/o),1):n&&n>0?n:Math.max(Math.round(s/.12),1);let h=(s-l)/e,u=Zs(t),c={id:u+"-horizontal",type:"geometry:cuboid",position:{type:"vector3:list",list:[[0,i-l,-r/2],[0,0,-r/2]]},rotation:0,dimensions:[s,l,r],material:a.surface},d={id:u+"-vertical",type:"geometry:cuboid",position:{type:"vector3:range",range:{start:[0,l,-r/2],step:[h,0,0],count:e+1}},rotation:0,dimensions:[l,i-.02,r],material:a.surface};t.geometries=[{type:"reference:geometry",geometry:c},{type:"reference:geometry",geometry:d}],t.emit("geometry-update",t)}(t);break;case"element:slab":!function(t){let{profile:e,height:i,materials:s}=t.parameters,r={id:Zs(t),type:"geometry:extrusion",position:[0,0,0],profile:e,height:i},n=Qs(e);r.surfaces={top:[0],bottom:[1],sides:Ks(2,2+n)},r.materials={top:s.top,bottom:s.bottom,sides:s.sides},t.geometries=[{type:"reference:geometry",geometry:r}],t.emit("geometry-update",t)}(t);break;case"element:stairFlight":Br(t);break;case"element:wall":Fr(t);break;case"element:window":!function(t){let{panelCount:e,panelLength:i,height:s,length:r,frameThickness:n,frameDepth:o,materials:a}=t.parameters,l=Zs(t),h={id:l,type:"geometry:cuboid",position:{type:"vector3:list",list:[[0,s-n,0],[0,0,0]]},rotation:0,dimensions:[r,n,o],material:a.frame},u=[[0,n,0]],c=r-n;if(e&&(i=c/e),i&&i>n){let t=i;for(;t<c;)u.push([t,n,0]),t+=i}u.push([r-n,n,0]);let d={id:l+"-vertical",type:"geometry:cuboid",position:{type:"vector3:list",list:u},rotation:0,dimensions:[n,s-2*n,o],material:a.frame},p={id:l+"-glass",type:"geometry:extrusion",position:[n,n,o/2],rotation:0,height:s-2*n,profile:{type:"curve:rectangle",dimensions:[r-2*n,.01]},material:a.panel};t.geometries=[{type:"reference:geometry",geometry:h},{type:"reference:geometry",geometry:d},{type:"reference:geometry",geometry:p}],t.emit("geometry-update",t)}(t)}for(let e of t.elements)Dr(e)}const Ur={position:[0,0],dimensions:[1,2],materials:{top:"#FFFFFF",bottom:"#FFFFFF",sides:"#FFFFFF"}};class Gr extends Cr{constructor(t){super(t,"element:opening"),this.parameters=JSON.parse(JSON.stringify(Ur))}getTransform(){var t;if("element:wall"!==(null==(t=this.parent)?void 0:t.type)){const t=this.parent?`Parent of element ${this.id} is not a wall.`:`Element ${this.id} does not have a parent.`;return be.error(t),{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}let{position:e,rotation:i}=Mr(this.parent,this);return{position:e,rotation:i,rotationAxis:[0,1,0]}}get position(){return this.getTransform().position}get rotation(){return this.getTransform().rotation}setParameters(t){let e=!!t.position,i=!!t.dimensions;if(super.setParameters(t),this.emit("element-parameters-change",this),e||i){let t=this.parent;if(t&&Dr(t),i)for(let e of this.elements)Dr(e)}}getBoundingBox(t=!1){const{dimensions:e}=this.parameters,i=this.parent,s=(null==i?void 0:i.parameters.width)||0;return{min:[0,0,0],max:[e[0],e[1],s],transform:t?this.getTransform():this.getWorldTransform()}}getSpaces(){if(this.parent){return this.parent.getSpaces().filter((t=>Xs(t,this)))}return be.error(`Element ${this.id} does not have a parent.`),[]}get isExternal(){const t=this.parent;if(!t)return super.isExternal;const[e]=t.getAxisPoints();if(!e)return super.isExternal;const i=t.getAxisLength(),{position:s,dimensions:r}=this.parameters,n=s[0]/i,o=(s[0]+r[0])/i,a=t.getEdgesAtLinearSegment(n,o);if(1===a.length)return a[0].isExternal;let l=0,h=0;for(const u of a){const[t,s]=u.getPoints().map((t=>hi(e,t)/i)).sort(((t,e)=>t-e)),r=(o>s?s:o)-(n>t?n:t);u.isExternal?l+=r:h+=r}return l>=h}}class Xr extends ks{constructor(t,e){super(t,e),this.position=[0,0,0],this.rotation=0,this.rotationAxis=[0,1,0]}copyForClone(t){super.copyForClone(t),this.position=[...t.position],this.rotation=t.rotation,this.rotationAxis=[...t.rotationAxis]}setPosition(t){this.position=[...t],this.emit("element-transform-change",this)}setRotation(t,e){this.rotation=t,e&&(this.rotationAxis=[...e]),this.emit("element-transform-change",this)}setTransform(t,e,i){this.position=[...t],this.rotation=e,i&&(this.rotationAxis=[...i]),this.emit("element-transform-change",this)}getSpaces(){if(this.parent)return this.parent.getSpaces();let t=[this.position[0],this.position[2]];for(let e of this.layout.spaces)if(wi(t,e.geometry.polygons))return[e];return[]}getTransform(){return{position:[...this.position],rotation:this.rotation,rotationAxis:[...this.rotationAxis]}}getWorldTransform(){if(!this.parent)return this.getTransform();let t=br(this),{position:e,rotation:i,rotationAxis:s}=Mi(t);return 0===s[0]&&s[1]<0&&0===s[2]&&(s=[0,1,0],i=-i),{position:e,rotation:i,rotationAxis:s}}getBoundingBox(t=!1){const e=[0,0,0],i=[0,0,0];if("length"in this.parameters&&(i[0]=this.parameters.length),"height"in this.parameters&&(i[1]=this.parameters.height),"width"in this.parameters?i[2]=this.parameters.width:"frameDepth"in this.parameters&&(i[2]=this.parameters.frameDepth),"radius"in this.parameters&&(e[0]=e[2]=-this.parameters.radius,i[0]=i[2]=this.parameters.radius),"profile"in this.parameters&&"none"!==this.parameters.profile)switch(this.parameters.profile.type){case"curve:rectangle":{let[t,s]=this.parameters.profile.dimensions;i[0]=t,i[2]=s,"element:column"===this.type&&(e[0]=-t/2,i[0]=t/2,e[2]=-s/2,i[2]=s/2);break}case"curve:circle":e[0]=e[2]=-this.parameters.profile.radius,i[0]=i[2]=this.parameters.profile.radius;break;case"curve:polygon":let t=Y([this.parameters.profile.points]);e[0]=t.min[0],i[0]=t.max[0],e[2]=t.min[1],i[2]=t.max[1]}return{min:e,max:i,transform:t?this.getTransform():this.getWorldTransform()}}setParameters(t){super.setParameters(t),Dr(this)}}const Wr={materials:{}};class Hr extends Xr{constructor(t){super(t,"element:asset"),this.product=null,this.parameters=JSON.parse(JSON.stringify(Wr))}get isComponentInstance(){var t;return"product:component"===(null==(t=this.product)?void 0:t.type)}get isComponentInstanceChild(){var t;return"element:asset"===(null==(t=this.parent)?void 0:t.type)&&this.parent.isComponentInstance}setParameters(t){super.setParameters(t)}setProduct(t){this.product=t,this.product.instances.add(this),this.emit("node-property-change",this,"product"),this.emit("geometry-update",this)}getBoundingBox(t=!1){if(!this.product)return super.getBoundingBox();const{min:e,max:i}=this.product.attributes.boundingBox;return{min:e,max:i,transform:t?this.getTransform():this.getWorldTransform()}}}const Yr={length:2,width:.1,height:.2,materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class $r extends Xr{constructor(t){super(t,"element:beam"),this.parameters=JSON.parse(JSON.stringify(Yr))}setParameters(t){super.setParameters(t)}}const jr={length:2,height:.7,width:.6,counterHeight:.03,materials:{cabinet:"asm:cabinet_paint_white",cabinetDoors:"asm:cabinet_paint_white",counter:"asm:cabinet_paint_white"}};class zr extends Xr{constructor(t){super(t,"element:casework"),this.parameters=JSON.parse(JSON.stringify(jr))}setParameters(t){super.setParameters(t)}}const Vr={type:"curve:circle",radius:.1},qr={"curve:circle":{...Vr},"curve:rectangle":{type:"curve:rectangle",dimensions:[.1,.1]},"curve:polygon":{type:"curve:polygon",points:[[0,0],[.1,0],[.1,.1],[0,.1]]},"curve:polygonWithHoles":{type:"curve:polygonWithHoles",polygons:[[[0,0],[.1,0],[.1,.1],[0,.1]],[[.02,.02],[.02,.08],[.08,.08],[.08,.02]]]}},Jr={profile:{...Vr},height:3,materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class Kr extends Xr{constructor(t){super(t,"element:column"),this.parameters=JSON.parse(JSON.stringify(Jr))}setParameters(t){var e;(null==(e=t.profile)?void 0:e.type)&&t.profile.type!==this.parameters.profile.type&&(this.parameters.profile=JSON.parse(JSON.stringify(qr[t.profile.type]))),super.setParameters(t)}}const Zr={length:1,height:2,frameThickness:.05,frameDepth:.1,doorType:"singleSwing",doorAngle:90,hardware:!0,hingeSide:"right",doorSide:"side1",materials:{frame:"asm:doorLeaf-flush-white",leaf:"asm:doorLeaf-flush-white"}};class Qr extends Xr{constructor(t){super(t,"element:door"),this.parameters=JSON.parse(JSON.stringify(Zr))}setParameters(t){super.setParameters(t)}getBoundingBox(t=!1){const e=super.getBoundingBox(t),{doorType:i,frameThickness:s,frameDepth:r,doorSide:n,length:o}=this.parameters;if("singleSwing"===i||"doubleSwing"===i){const t="singleSwing"===i?o-2*s:o/2-s;"side1"===n?e.min[2]=-t:e.max[2]=r+t}return e}}const tn={"curve:circle":{type:"curve:circle",radius:.5},"curve:rectangle":{type:"curve:rectangle",dimensions:[1,1]},"curve:polygon":{type:"curve:polygon",points:[[0,0],[1,0],[1,1],[0,1]]},"curve:polygonWithHoles":{type:"curve:polygonWithHoles",polygons:[[[0,0],[1,0],[1,1],[0,1]],[[.25,.25],[.25,.75],[.75,.75],[.75,.25]]]}},en={profile:"none",height:0,materials:{top:"#F0F0F0",bottom:"#F0F0F0",sides:"#F0F0F0"}};class sn extends Xr{constructor(t){super(t,"element:generic"),this.parameters=JSON.parse(JSON.stringify(en))}setParameters(t){t.profile&&"none"!==t.profile&&t.profile.type&&"none"!==this.parameters.profile&&this.parameters.profile.type!==t.profile.type&&(this.parameters.profile=JSON.parse(JSON.stringify(tn[t.profile.type]))),super.setParameters(t)}}const rn="product:static",nn={manufacturer:"",categories:[],subCategories:[],thumbnail:"",boundingBox:{min:[0,0,0],max:[0,0,0]},seatCapacity:0,updatedAt:""};class on extends bs{constructor(t,e){var i,s,r;super(t,e),i=this,(s=me).has(i)?ve("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(i):s.set(i,r),this.instances=new Set,this.attributes=JSON.parse(JSON.stringify(nn))}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes))}setAttributes(t){var e,i;let s=this.attributes;s.manufacturer=t.manufacturer??s.manufacturer,s.categories=(null==(e=t.categories)?void 0:e.slice())??s.categories,s.subCategories=(null==(i=t.subCategories)?void 0:i.slice())??s.subCategories,s.thumbnail=t.thumbnail??s.thumbnail,t.boundingBox&&(s.boundingBox.min=[...t.boundingBox.min],s.boundingBox.max=[...t.boundingBox.max]),s.seatCapacity=t.seatCapacity??s.seatCapacity,s.updatedAt=t.updatedAt??s.updatedAt}toJSON(){const t=super.toJSON();return t.attributes=xe(this,me,ge).call(this),t}}me=new WeakSet,ge=function(){const t={},e=this.attributes;""!==e.manufacturer&&(t.manufacturer=e.manufacturer),e.categories.length>0&&(t.categories=[...e.categories]),e.subCategories.length>0&&(t.subCategories=[...e.subCategories]),""!==e.thumbnail&&(t.thumbnail=e.thumbnail);let{min:i,max:s}=e.boundingBox;return 1!==i[0]&&-1!==s[0]&&(t.boundingBox={min:[...e.boundingBox.min],max:[...e.boundingBox.max]}),e.seatCapacity>0&&(t.seatCapacity=e.seatCapacity),void 0!==e.updatedAt&&(t.updatedAt=e.updatedAt),t};class an extends on{constructor(t){super(t,rn),this.geometries=[]}copyForClone(t){super.copyForClone(t),this.geometries=JSON.parse(JSON.stringify(t.geometries))}toJSON(){return{...super.toJSON(),type:rn,geometries:JSON.parse(JSON.stringify(this.geometries))}}}const ln="product:component";class hn extends on{constructor(t){super(t,ln),this.products=[],this.geometries=[],this.attributes=JSON.parse(JSON.stringify(nn))}copyForClone(t){super.copyForClone(t),this.products=JSON.parse(JSON.stringify(t.products))}toJSON(){return{...super.toJSON(),type:ln,products:JSON.parse(JSON.stringify(this.products)),geometries:[]}}setProducts(t){this.products=JSON.parse(JSON.stringify(t))}setInstances(){var t;for(const e of this.instances)if(this.products.length===e.elements.length)for(let i=0;i<this.products.length;i++){const s=this.products[i];if("type"in s.position)continue;if("number"!=typeof s.rotation)continue;const r=e.elements[i];"element:asset"===r.type&&(null==(t=r.product)?void 0:t.id)===s.product&&r.setTransform(s.position,s.rotation)}}}function un(t){for(let e=t.elements.length-1;e>=0;e--)t.removeElement(t.elements[e])}function cn(t,e,i){let s=t.elements.filter((t=>t.type===e));for(let r=s.length-1;r>=i;r--)t.removeElement(s[r]);for(let r=0;r<i;r++)if(!s[r]){let i=de();s[r]="element:casework"===e?new zr(i):new Hr(i),t.insertElement(s[r])}return s}function dn(t){let{length:e,width:i,height:s,wallCabinet:r,leftHighCabinetCount:n,rightHighCabinetCount:o,sinkElementSlot:a,materials:l}=t.parameters,h=Math.min(.6,e),u=s-1.5,c=Math.min(e,h*Math.max(n,0)),d=e>c?h*o:0,p=Math.max(e-c-d,0);d=Math.max(e-c-p,0);let f=0;p>0&&(f++,r&&f++),c>0&&f++,d>0&&f++;let m=p>0&&a*h>=c&&a*h<=c+p,g=cn(t,"element:casework",f),y={cabinet:l.cabinet,cabinetDoors:l.cabinetDoors,counter:l.counter};if(p>0){let e=g.shift();if(e){let s=cn(e,"element:asset",m?1:0);if(m){let e=s[0],r=function(t){const e="7f24bd1c-1ebc-4724-8cd4-ca78c7d4a1e5";if(null==t?void 0:t.productsById[e])return null==t?void 0:t.productsById[e];let i=new an(e);return i.setAttributes({categories:["appliances"],subCategories:["kitchen"],boundingBox:{max:[.54,.21,0],min:[0,-.17,-.47]}}),i.geometries=[{type:"reference:geometry",geometry:{id:"sinkGeometry",type:"geometry:uri",format:"data3d",uri:"015f8f8e-e588-4f51-a342-2930559834ee/201208-0355-60hukz/bf4e4a56-ed95-4b58-a214-4b1a0a84ae0e.gz.data3d.buffer"}}],i}(t.spaceGraph),{min:n,max:o}=r.attributes.boundingBox,l=mi(n,(v=gi(o,n),x=.5,[v[0]*x,v[1]*x,v[2]*x]));l[1]=0;let u=mi([a*h-c,.9,0],[h/2,0,i/2]);r&&(e.setProduct(r),e.setPosition(gi(u,l)))}e.setParameters({length:p,width:i,height:.9,counterHeight:.03,materials:{...y}}),e.setTransform([c,0,0],0)}let s=r&&g.shift();s&&(un(s),s.setParameters({length:p,width:.45,height:u,counterHeight:0,materials:{...y}}),s.setTransform([c,1.5,0],0))}var v,x;let b=c>0&&g.shift();b&&(un(b),b.setParameters({length:c,width:i,height:s,counterHeight:0,materials:{...y}}),b.setTransform([0,0,0],0));let _=d>0&&g.shift();_&&(un(_),_.setParameters({length:d,width:i,height:s,counterHeight:0,materials:{...y}}),_.setTransform([c+p,0,0],0))}const pn={length:3,width:.6,height:2.2,wallCabinet:!0,leftHighCabinetCount:1,rightHighCabinetCount:0,sinkElementSlot:-1,cooktopElementSlot:-1,ovenElementSlot:-1,materials:{cabinet:"asm:cabinet_paint_white",cabinetDoors:"asm:cabinet_paint_white",counter:"asm:cabinet_paint_white"}};class fn extends Xr{constructor(t){super(t,"element:kitchen"),this.parameters=JSON.parse(JSON.stringify(pn))}setParameters(t,e=!1){super.setParameters(t),e||dn(this),this.emit("element-parameters-change",this)}}const mn={length:2,width:.05,height:1,segmentCount:0,segmentLength:.12,materials:{surface:"#CCCCCC"}};class gn extends Xr{constructor(t){super(t,"element:railing"),this.parameters=JSON.parse(JSON.stringify(mn))}setParameters(t){super.setParameters(t)}}const yn={length:2,width:1,height:.5,materials:{top:"asm:basic-floor",bottom:"asm:basic-wall",sides:"asm:basic-wall"}};class vn extends Xr{constructor(t){super(t,"element:ramp"),this.parameters=JSON.parse(JSON.stringify(yn))}}const xn={materials:{}};class bn extends Xr{constructor(t){super(t,"element:roof"),this.parameters=JSON.parse(JSON.stringify(xn))}}const _n={type:"curve:rectangle",dimensions:[1,1]},wn={"curve:circle":{type:"curve:circle",radius:1},"curve:rectangle":{..._n},"curve:polygon":{type:"curve:polygon",points:[[0,0],[1,0],[1,1],[0,1]]},"curve:polygonWithHoles":{type:"curve:polygonWithHoles",polygons:[[[0,0],[1,0],[1,1],[0,1]],[[.25,.25],[.25,.75],[.75,.75],[.75,.25]]]}},Pn={profile:{..._n},height:.1,materials:{top:"asm:basic-floor",bottom:"asm:basic-floor",sides:"asm:basic-wall"}};class En extends Xr{constructor(t){super(t,"element:slab"),this.parameters=JSON.parse(JSON.stringify(Pn))}setParameters(t){var e;(null==(e=t.profile)?void 0:e.type)&&t.profile.type!==this.parameters.profile.type&&(this.parameters.profile=JSON.parse(JSON.stringify(wn[t.profile.type]))),super.setParameters(t)}}const Tn={height:3,width:1.2,materials:{steps:"asm:basic-wall",tread:"asm:basic-floor"}},An={straight:{stairFlightType:"straight",length:3,...Tn},spiral:{stairFlightType:"spiral",angle:270,radius:1.5,circulation:"right",...Tn}};class In extends Xr{constructor(t){super(t,"element:stairFlight"),this.parameters=JSON.parse(JSON.stringify(An.straight))}setParameters(t){if(t.stairFlightType&&this.parameters.stairFlightType!==t.stairFlightType){let{height:e,materials:i,width:s}=this.parameters;this.parameters={...JSON.parse(JSON.stringify(An[t.stairFlightType])),height:e,materials:i,width:s}}super.setParameters(t)}}function Sn(t,e,i){let s=t.elements.filter((t=>t.type===e));for(let r=s.length-1;r>=i;r--)t.removeElement(s[r]);for(let r=0;r<i;r++)if(!s[r]){let i=de();s[r]="element:stairFlight"===e?new In(i):new En(i),t.insertElement(s[r])}return s}const Cn=.1;const Mn={height:3,railing:"right",materials:{steps:"asm:basic-wall",tread:"asm:basic-floor",railing:"#CCCCCC"}},On={straight:{stairsType:"straight",length:4,width:1.2,...Mn},straightLanding:{stairsType:"straightLanding",length:4,width:1.2,...Mn},halfLanding:{stairsType:"halfLanding",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},quarterLanding:{stairsType:"quarterLanding",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},twoQuarterLanding:{stairsType:"twoQuarterLanding",length:3,width:4,stepWidth:1.2,circulation:"right",...Mn},winder:{stairsType:"winder",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},doubleWinder:{stairsType:"doubleWinder",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Mn},spiral:{stairsType:"spiral",radius:1.5,angle:270,stepWidth:1.2,circulation:"right",...Mn},custom:{stairsType:"custom",stepWidth:1.2,...Mn}},Nn=On.straight;class Ln extends Xr{constructor(t){super(t,"element:stairs"),this.parameters=JSON.parse(JSON.stringify(Nn))}setParameters(t,e=!1){if(t.stairsType&&this.parameters.stairsType!==t.stairsType){let{height:e,railing:i,materials:s}=this.parameters;this.parameters={...JSON.parse(JSON.stringify(On[t.stairsType])),height:e,railing:i,materials:s}}super.setParameters(t),e||function(t){switch(t.parameters.stairsType){case"straight":{let{length:e,width:i,height:s,materials:r}=t.parameters,[n]=Sn(t,"element:stairFlight",1);Sn(t,"element:slab",0),n.setParameters({stairFlightType:"straight",length:e,width:i,height:s,materials:{steps:r.steps,tread:r.tread}}),n.setTransform([0,0,0],0);break}case"straightLanding":{let{length:e,width:i,height:s,materials:r}=t.parameters,n=(e-i)/2,[o,a]=Sn(t,"element:stairFlight",2),[l]=Sn(t,"element:slab",1);o.setParameters({stairFlightType:"straight",length:n,width:i,height:s/2,materials:{steps:r.steps,tread:r.tread}}),o.setTransform([0,0,0],0),l.setParameters({profile:{type:"curve:rectangle",dimensions:[i,i]},height:Cn,materials:{top:r.tread,bottom:r.steps,sides:r.steps}}),l.setTransform([n,s/2-Cn,0],0),a.setParameters({stairFlightType:"straight",length:n,width:i,height:s/2}),a.setTransform([e-n,s/2,0],0);break}case"halfLanding":{let{length:e,width:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,[l,h]=Sn(t,"element:stairFlight",2),[u]=Sn(t,"element:slab",1);l.setParameters({stairFlightType:"straight",length:e-r,width:r,height:s/2,materials:{steps:o.steps,tread:o.tread}}),l.setTransform([0,0,a?0:-r],0),u.setParameters({profile:{type:"curve:rectangle",dimensions:[r,i]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),u.setPosition([e-r,s/2-Cn,a?0:-i]),h.setParameters({stairFlightType:"straight",length:e-r,width:r,height:s/2,materials:{steps:o.steps,tread:o.tread}}),h.setTransform([e-r,s/2,a?i:-i+r],-180);break}case"quarterLanding":{let{length:e,width:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,l=e-r,h=i-r,u=l/(l+h)*s,c=h/(l+h)*s,[d,p]=Sn(t,"element:stairFlight",2),[f]=Sn(t,"element:slab",1);d.setParameters({stairFlightType:"straight",length:l,width:r,height:u,materials:{steps:o.steps,tread:o.tread}}),d.setTransform([0,0,a?0:-r],0),f.setParameters({profile:{type:"curve:rectangle",dimensions:[r,r]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),f.setPosition([e-r,u-Cn,a?0:-r]),p.setParameters({stairFlightType:"straight",length:h,width:r,height:c,materials:{steps:o.steps,tread:o.tread}}),a?p.setTransform([e,u,r],-90):p.setTransform([e-r,u,-r],90);break}case"twoQuarterLanding":{let{length:e,width:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,l=e-r,h=i-2*r,u=l/(2*l+h)*s,c=h/(2*l+h)*s,[d,p,f]=Sn(t,"element:stairFlight",3),[m,g]=Sn(t,"element:slab",2);d.setParameters({stairFlightType:"straight",length:l,width:r,height:u,materials:{steps:o.steps,tread:o.tread}}),d.setTransform([0,0,a?0:-r],0),m.setParameters({profile:{type:"curve:rectangle",dimensions:[r,r]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),m.setPosition([e-r,u-Cn,a?0:-r]),p.setParameters({stairFlightType:"straight",length:h,width:r,height:c,materials:{steps:o.steps,tread:o.tread}}),a?p.setTransform([e,u,r],-90):p.setTransform([e-r,u,-r],90),g.setParameters({profile:{type:"curve:rectangle",dimensions:[r,r]},height:Cn,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),g.setPosition([e-r,u+c-Cn,a?i-r:-i]),f.setParameters({stairFlightType:"straight",length:l,width:r,height:u,materials:{steps:o.steps,tread:o.tread}}),f.setTransform([e-r,u+c,a?i:-i+r],-180);break}case"spiral":{let{radius:e,angle:i,height:s,stepWidth:r,circulation:n,materials:o}=t.parameters,a="right"===n,[l]=Sn(t,"element:stairFlight",1);Sn(t,"element:slab",0),l.setParameters({stairFlightType:"spiral",radius:e,angle:i,height:s,width:r,circulation:n,materials:{steps:o.steps,tread:o.tread}}),l.setTransform([0,0,a?e:-e],0);break}}}(this),this.emit("element-parameters-change",this)}getBoundingBox(t=!1){const e=super.getBoundingBox(t);return"radius"in this.parameters&&(e.min[2]=0,e.max[2]=2*this.parameters.radius,e.min[0]=-this.parameters.radius,e.max[0]=this.parameters.radius),"circulation"in this.parameters&&"left"===this.parameters.circulation&&(e.min[2]=-e.max[2],e.max[2]=0),e}}const Rn={length:1,height:1.2,frameThickness:.05,frameDepth:.1,panelLength:0,panelCount:1,materials:{frame:"#CCCCCC",panel:"asm:glass"}};class kn extends Xr{constructor(t){super(t,"element:window"),this.parameters=JSON.parse(JSON.stringify(Rn))}setParameters(t){super.setParameters(t)}}class Bn extends _s{constructor(){super(...arguments),this.position=[0,0,0],this.rotation=0}copyForClone(t){super.copyForClone(t),this.position=[...t.position],this.rotation=t.rotation,this.parameters=JSON.parse(JSON.stringify(t.parameters))}setTransform(t,e){this.position=[...t],this.rotation=e,this.emit("annotation-transform-change",this)}setParameters(t){Ms(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("annotation-parameters-change",this)}toJSON(){return{...super.toJSON(),position:[...this.position],parameters:JSON.parse(JSON.stringify(this.parameters)),rotation:this.rotation}}}const Fn={uri:"",drawingOrigin:[0,0],drawingUnits:"unitLess",hiddenLayers:[]};class Dn extends Bn{constructor(t){super(t,"annotation:floorPlanDxf"),this.parameters=JSON.parse(JSON.stringify(Fn))}setParameters(t){super.setParameters(t)}}class Un extends _s{copyForClone(t){super.copyForClone(t),this.parameters=JSON.parse(JSON.stringify(t.parameters))}setParameters(t){Ms(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("view-parameters-change",this)}toJSON(){return{...super.toJSON(),parameters:JSON.parse(JSON.stringify(this.parameters))}}}const Gn={style:{background:{fill:"#f7f8fa"},units:"metric",byId:{},byType:{},byAttribute:{program:{},usage:{}}},hidden:[]};class Xn extends Un{constructor(t){super(t,"view:2d"),this.parameters=JSON.parse(JSON.stringify(Gn))}setParameters(t){var e,i;let{style:s}=t;void 0===(null==s?void 0:s.byId)&&(this.parameters.style.byId={}),void 0===(null==s?void 0:s.byType)&&(this.parameters.style.byType={}),void 0===(null==(e=null==s?void 0:s.byAttribute)?void 0:e.program)&&(this.parameters.style.byAttribute.program={}),void 0===(null==(i=null==s?void 0:s.byAttribute)?void 0:i.usage)&&(this.parameters.style.byAttribute.usage={}),Ms(this.parameters,t,{onNewKeys:{allow:!1},copyScopes:[".style.byId",".style.byType",".style.byAttribute.program",".style.byAttribute.usage"],cloneObjects:!0}),this.emit("view-parameters-change",this)}}const Wn={position:[0,0,0],normal:[0,0,1],fov:"default",scale:1,lensShiftX:0,lensShiftY:0,projection:"perspective"};class Hn extends Un{constructor(t){super(t,"view:3d"),this.parameters=JSON.parse(JSON.stringify(Wn))}setParameters(t){super.setParameters(t)}}const Yn="relation:group";class $n extends we{constructor(t){super(t,Yn),this.elements=new Set}insertElements(t){for(let e of t)this.elements.add(e)}removeElements(t){for(let e of t)this.elements.delete(e)}copyForClone(t){super.copyForClone(t)}toJSON(){const t=super.toJSON();return t.elements=Array.from(this.elements).map((t=>t.id)),t}}class jn extends bs{constructor(t,e){super(t,e)}}function zn(t,e){e.registerNode(t),function(t,e){let{vertices:i,edges:s}=t.spatialGraph;for(let r of i)e.registerNode(r),e.emit("vertex-create",r);for(let r of s)e.registerNode(r),e.emit("edge-create",r)}(t,e);for(let s of t.spaces)e.registerNode(s);let i=t.getElementList();for(let s of i)e.registerNode(s);for(let s of t.annotations)e.registerNode(s);for(let s of t.views)e.registerNode(s);e.emit("spatial-structure-create",t)}function Vn(t,e){e.unregisterNode(t),function(t,e){let{vertices:i,edges:s}=t.spatialGraph;for(let r of i)e.unregisterNode(r),e.emit("vertex-delete",r);for(let r of s)e.unregisterNode(r),e.emit("edge-delete",r)}(t,e);for(let s of t.spaces)e.unregisterNode(s);let i=t.getElementList();for(let s of i)e.unregisterNode(s);for(let s of t.annotations)e.unregisterNode(s);e.emit("spatial-structure-delete",t)}function qn(t,e){e.registerNode(t);for(let i of t.layouts)zn(i,e);e.emit("spatial-structure-create",t)}function Jn(t,e){e.unregisterNode(t);for(let i of t.layouts)Vn(i,e);e.emit("spatial-structure-delete",t)}function Kn(t,e,...i){let s;switch(t){case"element:ceiling":case"element:floor":s=new Vs(e,t,i[0]);break;case"element:boundaryWall":s=new Er(e,i[0]);break;case"element:curtainWall":s=new Ar(e,i[0]);break;case"element:spaceDivider":s=new Sr(e,i[0]);break;case"element:wall":s=new js(e,i[0]);break;case"element:opening":s=new Gr(e);break;case"element:asset":s=new Hr(e);break;case"element:beam":s=new $r(e);break;case"element:casework":s=new zr(e);break;case"element:column":s=new Kr(e);break;case"element:door":s=new Qr(e);break;case"element:generic":s=new sn(e);break;case"element:kitchen":s=new fn(e);break;case"element:ramp":s=new vn(e);break;case"element:roof":s=new bn(e);break;case"element:railing":s=new gn(e);break;case"element:slab":s=new En(e);break;case"element:stairs":s=new Ln(e);break;case"element:stairFlight":s=new In(e);break;case"element:window":s=new kn(e)}return s}const Zn={uri:"",length:1,width:1};class Qn extends Bn{constructor(t){super(t,"annotation:floorPlanImage"),this.parameters=JSON.parse(JSON.stringify(Zn))}setParameters(t){super.setParameters(t)}}function to(t,e){let i;switch(t){case"annotation:floorPlanDxf":i=new Dn(e);break;case"annotation:floorPlanImage":i=new Qn(e)}return i}function eo(t,e){let i;switch(t){case"view:2d":i=new Xn(e);break;case"view:3d":i=new Hn(e)}return i}class io{constructor(){this.nodeMap=new Map}addNode(t){return this.nodeMap.has(t)||this.nodeMap.set(t,new Map),this.nodeMap.get(t)}addEdge(t,e,i){var s,r;let n=this.addNode(e),o=this.addNode(i);n.has(t)||n.set(t,new Set),o.has(t)||o.set(t,new Set),null==(s=n.get(t))||s.add(i),null==(r=o.get(t))||r.add(e)}removeNode(t){if(this.nodeMap.has(t)){for(let e of this.nodeMap.get(t))for(let i of e[1])this.removeEdge(e[0],t,i);this.nodeMap.delete(t)}}removeEdge(t,e,i){var s,r,n,o;null==(r=null==(s=this.nodeMap.get(e))?void 0:s.get(t))||r.delete(i),null==(o=null==(n=this.nodeMap.get(i))?void 0:n.get(t))||o.delete(e)}findShortestPath(t,e,i,s={}){var r;let n=[[e]],o=new Set;for(;n.length>0;){let e=n.shift();if(!e)return null;if(s.depthLimit&&e.length-1>s.depthLimit)return null;let a=e[e.length-1];if(a===i)return e;if(!o.has(a)&&this.nodeMap.has(a)&&(null==(r=this.nodeMap.get(a))?void 0:r.has(t))){o.add(a);for(let i of this.nodeMap.get(a).get(t))n.push([...e,i])}}return null}toJSON(){const t=[],e=[];for(const[i,s]of this.nodeMap.entries()){t.push({id:i.id,type:i.type});for(const[t,r]of s.entries())for(const s of r)i.id<s.id&&e.push({type:String(t),nodes:[i.id,s.id]})}return{nodes:t,edges:e}}}const so=t=>{const e={};for(const i in t)e[i]=[];return e},ro={"element:ceiling":Vs,"element:floor":Vs,"element:boundaryWall":Er,"element:curtainWall":Ar,"element:spaceDivider":Sr,"element:wall":js,"element:opening":Gr,"element:asset":Hr,"element:beam":$r,"element:casework":zr,"element:column":Kr,"element:door":Qr,"element:generic":sn,"element:kitchen":fn,"element:railing":gn,"element:ramp":vn,"element:roof":bn,"element:slab":En,"element:stairs":Ln,"element:stairFlight":In,"element:window":kn},no={"annotation:floorPlanDxf":Dn,"annotation:floorPlanImage":Qn},oo={"view:2d":Xn,"view:3d":Hn};const ao="spatialStructure:layout";class lo extends jn{constructor(t){super(t,ao),this.parent=null,this.spaces=[],this.spacesById={},this.elements=[],this.elementsById={},this.elementsByType=so(ro),this.annotations=[],this.annotationsById={},this.annotationsByType=so(no),this.views=[],this.viewsById={},this.viewsByType=so(oo),this.debugIds=!1,this.suggestedIds={},this.spatialGraph=new wr(this)}copyForClone(t){super.copyForClone(t),this.debugIds=t.debugIds,this.suggestedIds={...t.suggestedIds}}insertSpace(t){Es(this,t,this.spacesById,"Space")&&(!function(t,e){for(let i of t.elements)"element:ceiling"!==i.type&&"element:floor"!==i.type||pr(e.boundaries,i.boundaries)&&e.attachSlab(i)}(this,t),t.layout=this,this.spaces.push(t),this.spacesById[t.id]=t,t.boundaries.length&&(this.spatialGraph.graphChanged=!0),this.spaceGraph&&(this.spaceGraph.registerNode(t),this.spaceGraph.emit("space-create",t)))}removeSpace(t){let e=this.spaces.indexOf(t);if(-1!==e){if(function(t){let e=t.slabs.slice();for(let i of e)t.detachSlab(i);for(let i of t.boundaries)for(let e of i.edges)e.spaces[0]===t&&(e.spaces[0]=null),e.spaces[1]===t&&(e.spaces[1]=null)}(t),this.spaces.splice(e,1),this.spacesById[t.id]===t)return delete this.spacesById[t.id],this.spaceGraph&&(this.spaceGraph.unregisterNode(t),this.spaceGraph.emit("space-delete",t)),t.layout=null,t;be.error(`Entry ${t.id} in 'spaces stored by ID' record does not contain this object.`)}else be.warn(`Space ${t.id} not found.`)}createSpace(t,e){let i=new Ws(t,e);return this.insertSpace(i),i}insertElement(t){Es(this,t,this.elementsById,"Element",!0)&&(!function(t,e){switch(e.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":nr(t,e);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":or(t,e)}}(this,t),this.elements.push(t),Ts(this,t))}removeElement(t){if(t.layout!==this)return void be.warn(`Element ${t.id} not part of layout ${this.id}.`);if(t.parent)return void be.warn(`Element ${t.id} not a root element, cannot remove from layout.`);ar(t);let e=this.elements.indexOf(t);if(-1!==e)return this.elements.splice(e,1),As(this,t,null),t;be.warn(`Element ${t.id} not found.`)}createElement(t,e,...i){let s=Kn(t,e,...i);return this.insertElement(s),s}insertNode(t){let{nodes:e,nodesById:i,nodesByType:s}=_r(this,t);t.layout=this,e.push(t),i[t.id]=t,s[t.type]||(s[t.type]=[]),s[t.type].push(t)}removeNode(t){let{name:e,nodes:i,nodesById:s,nodesByType:r}=_r(this,t),n=i.indexOf(t);if(-1===n)return void be.warn(`Node ${t.id} not found in '${e}' list.`);if(i.splice(n,1),s[t.id]!==t)return void be.error(`Entry ${t.id} in '${e} stored by ID' record does not contain this object.`);delete s[t.id];let o=r[t.type],a=null==o?void 0:o.indexOf(t);o&&-1!==a?r[t.type].splice(a,1):be.error(`Node ${t.id} not found in '${e} stored by type' record.`)}insertAnnotation(t){Es(this,t,this.annotationsById,"Annotation")&&(this.insertNode(t),this.spaceGraph&&(this.spaceGraph.registerNode(t),this.spaceGraph.emit("annotation-create",t)))}removeAnnotation(t){return this.removeNode(t),this.spaceGraph&&(this.spaceGraph.unregisterNode(t),this.spaceGraph.emit("annotation-delete",t)),t.layout=null,t}createAnnotation(t,e){let i=to(t,e);return this.insertAnnotation(i),i}insertView(t){Es(this,t,this.viewsById,"View")&&(this.insertNode(t),this.spaceGraph&&(this.spaceGraph.registerNode(t),this.spaceGraph.emit("view-create",t)))}removeView(t){return this.removeNode(t),this.spaceGraph&&(this.spaceGraph.unregisterNode(t),this.spaceGraph.emit("view-delete",t)),t.layout=null,t}createView(t,e){let i=eo(t,e);return this.insertView(i),i}clearSpaces(){let t=[...this.spaces];for(let e of t)this.removeSpace(e)}getElementList(){return Object.values(this.elementsById)}getArea(t={program:{exclude:["void"]}}){var e,i;let s=(null==(e=null==t?void 0:t.program)?void 0:e.include)??[],r=(null==(i=null==t?void 0:t.program)?void 0:i.exclude)??[];if(s.length&&r.length)return be.warn("Cannot use 'include' and 'exclude' filters at the same time, skipping area calculation."),0;let n=0;for(let o of this.spaces){let t=!1;s.length&&(t=s.includes(o.attributes.program)),r.length&&(t=r.includes(o.attributes.program)),t||(n+=o.getArea())}return n}getLayoutGraph(){var t;let e=new io,i=this.elementsByType["element:spaceDivider"].slice();for(let s of this.elementsByType["element:opening"])"element:window"!==(null==(t=s.elements[0])?void 0:t.type)&&i.push(s);for(let s of i)for(let t of s.getSpaces())t&&e.addEdge("graph:connectedTo",t,s);for(let s of this.spatialGraph.edges)s.spaces[0]&&s.spaces[1]&&e.addEdge("graph:adjacentTo",s.spaces[0],s.spaces[1]);return e}getUniqueId(t,e){let i=0,s=t+i++;for(;this.suggestedIds[s]||e[s];)s=t+i++;return this.suggestedIds[s]=!0,s}getSpaceId(t){let e;return t=t??"space-",e=this.debugIds?this.getUniqueId(t,this.spacesById):de(),e}getElementId(t,e){let i;return e=e??t.type.split(":")[1]+"-",i=this.debugIds?this.getUniqueId(e,this.elementsById):de(),i}getBoundingBox(){const t={position:[0,0,0],rotation:0,rotationAxis:[0,1,0]};if(0===this.spaces.length)return{min:[0,0,0],max:[0,0,0],transform:t};const e=[];for(const r of this.spaces){const{min:t,max:i}=r.getAxisAlignedBoundingBox();e.push(t,i)}for(const r of this.getElementList()){const{min:t,max:i}=r.getAxisAlignedBoundingBox();e.push(t,i)}const{min:i,max:s}=ds(e.flat());return{min:i,max:s,transform:t}}toJSON(){let t=this.spatialGraph.toJSON(),e=function(t){let e=[];for(let i of t.spaces){let t=i.toJSON();e.push(t)}return e}(this),i=function(t){let e=[];for(let i of t.elements){let t=i.toJSON();t&&e.push(t)}return e}(this),s=function(t){let e=[];for(let i of t.annotations){let t=i.toJSON();e.push(t)}return e}(this),r=function(t){let e=[];for(let i of t.views){let t=i.toJSON();e.push(t)}return e}(this);return{...super.toJSON(),spatialGraph:t,spaces:e,elements:i,annotations:s,views:r}}}const ho="spatialStructure:floor";class uo extends jn{constructor(t){super(t,ho),this.parent=null,this.position=[0,0,0],this.rotation=0,this.layouts=[]}copyForClone(t){super.copyForClone(t),this.position=[...t.position],this.rotation=t.rotation}insertLayout(t){t.parent?be.warn(`SpaceGraphLayout ${t.id} already part of floor ${t.parent.id}.`):(t.parent=this,this.layouts.push(t),this.spaceGraph&&zn(t,this.spaceGraph))}removeLayout(t){-1!==this.layouts.indexOf(t)?(this.spaceGraph&&Vn(t,this.spaceGraph),t.parent=null):be.warn(`Floor ${t.id} not found.`)}createLayout(t){let e=new lo(t);return this.insertLayout(e),e}toJSON(){const t={...super.toJSON(),position:[...this.position],rotation:this.rotation,layouts:[]};for(let e of this.layouts){let i=e.toJSON();t.layouts.push(i)}return t}}const co="spatialStructure:building";class po extends jn{constructor(t){super(t,co),this.floors=[],this.location={latLong:[0,0],rotation:0}}copyForClone(t){super.copyForClone(t),this.location=JSON.parse(JSON.stringify(t.location))}insertFloor(t){t.parent?be.warn(`Floor ${t.id} already part of building ${t.parent.id}.`):(t.parent=this,this.floors.push(t),this.spaceGraph&&qn(t,this.spaceGraph))}removeFloor(t){-1!==this.floors.indexOf(t)?(this.spaceGraph&&Jn(t,this.spaceGraph),t.parent=null):be.warn(`Floor ${t.id} not found.`)}createFloor(t){let e=new uo(t);return this.insertFloor(e),e}toJSON(){let t={...super.toJSON(),floors:[]},e=this.location;e.latLong[0]&&e.latLong[1]&&e.rotation&&(t.location={latLong:[...e.latLong],rotation:e.rotation});for(let i of this.floors){let e=i.toJSON();t.floors.push(e)}return t}}const fo={...ro,"spatialGraph:edge":Us,"spatialGraph:vertex":Ps,"layout:space":Ws,"view:2d":Xn,"view:3d":Hn,"annotation:floorPlanDxf":Dn,"annotation:floorPlanImage":Qn};class mo extends we{constructor(t,e){super(t,e),this.position=[0,0,0],this.rotation=0,this.rotationAxis=[0,1,0],this.surfaces={},this.materials={},this.boundingBox={min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]}}}class go extends mo{constructor(t,e){super(t,e),this.normals="generator",this.uvs="generator",this.geometries=[]}}const yo={"geometry:plane":class extends go{constructor(t){super(t,"geometry:plane"),this.normal=[0,1,0],this.size=1,this.doubleSided=!1}},"geometry:cuboid":class extends go{constructor(t){super(t,"geometry:cuboid"),this.dimensions=[1,1,1]}},"geometry:sphere":class extends go{constructor(t){super(t,"geometry:sphere"),this.radius=1}},"geometry:extrusion":class extends go{constructor(t,e){super(t,"geometry:extrusion"),this.height=1,this.profile=e}},"geometry:mesh":class extends mo{constructor(t){super(t,"geometry:mesh"),this.vertices=[],this.indices=[],this.normals=[],this.uvs=[]}},"geometry:uri":class extends mo{constructor(t){super(t,"geometry:uri"),this.format="data3d",this.uri="",this.normals="smooth"}}},vo={"material:embedded":Se,"material:basic":Me,"material:color":Ee,"material:standard":Ae},xo={"product:static":an,"product:component":hn},bo={"relation:group":$n},_o={...fo,...yo,...vo,...xo,...bo,"spatialStructure:building":po,"spatialStructure:floor":uo,"spatialStructure:layout":lo};class wo{constructor(t){this.products=[],this.productsById={},this.productsByType=so(xo),this.customAttributes=[],this.customAttributesById={},this.customAttributesByType=so(xs),this.geometries=[],this.geometriesById={},this.geometriesByType=so(yo),this.materials=[],this.materialsById={},this.materialsByType=so(vo),this.relations=[],this.relationsById={},this.relationsByType=so(bo),this.nodes=[],this.nodesById={},this.nodesByType=so(_o),this.spatialStructure=null,this.emitter=new ye,this.sourceSchemaVersion=t}getEvents(){return this.emitter.e??{}}copyEvents(t){let e=t.getEvents();for(let[i,s]of Object.entries(e))this.emitter.on(i,s)}deleteNodeAtIndex(t,e,i,s){let r=e[t];if(e.splice(t,1),i[r.id]!==r)return void be.error(`Entry ${r.id} in 'nodes stored by ID' record does not contain this object.`);delete i[r.id];let n=s[r.type];if(!n)return void be.error(`Node ${r.id} not found in 'nodes stored by type' record.`);let o=n.indexOf(r);if(-1!==o)return n.splice(o,1),r;be.error(`Node ${r.id} not found in 'nodes stored by type' record.`)}insertNode(t,e,i,s){i[t.id]?be.error(`Node ${t.id} already registered.`):(e.push(t),i[t.id]=t,s[t.type]||(s[t.type]=[]),s[t.type].push(t))}removeNode(t,e,i,s){let r=e.indexOf(t);if(-1!==r)return this.deleteNodeAtIndex(r,e,i,s),t;be.warn(`Node ${t.id} not found.`)}registerNode(t){t.spaceGraph=this;let{nodes:e,nodesById:i,nodesByType:s}=this;this.insertNode(t,e,i,s)}unregisterNode(t){t.spaceGraph=null;let{nodes:e,nodesById:i,nodesByType:s}=this;this.removeNode(t,e,i,s)}insertSpatialStructure(t){if(this.spatialStructure)be.warn(`Space graph object already has spatial structure ${this.spatialStructure.id} attached.`);else if(t.spaceGraph)be.warn(`Spatial structure ${t.id} already part of a space graph object.`);else{switch(t.spaceGraph=this,this.spatialStructure=t,t.type){case"spatialStructure:building":!function(t,e){e.registerNode(t);for(let i of t.floors)qn(i,e);e.emit("spatial-structure-create",t)}(t,this);break;case"spatialStructure:floor":qn(t,this);break;case"spatialStructure:layout":zn(t,this)}this.emit("spatial-structure-create",t)}}removeSpatialStructure(){let t=this.spatialStructure;if(t){switch(t.spaceGraph=null,this.spatialStructure=null,t.type){case"spatialStructure:building":!function(t,e){e.unregisterNode(t);for(let i of t.floors)Jn(i,e);e.emit("spatial-structure-delete",t)}(t,this);break;case"spatialStructure:floor":Jn(t,this);break;case"spatialStructure:layout":Vn(t,this)}return this.emit("spatial-structure-delete",t),t}be.warn("No spatial structure attached to space graph object.")}createSpatialStructure(t,e){let i;switch(t){case"spatialStructure:building":i=new po(e);break;case"spatialStructure:floor":i=new uo(e);break;case"spatialStructure:layout":i=new lo(e)}return this.insertSpatialStructure(i),i}insertProduct(t){t.spaceGraph?be.warn(`Product ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.products,this.productsById,this.productsByType),this.registerNode(t),this.emit("product-create",t))}removeProduct(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.products,this.productsById,this.productsByType),this.unregisterNode(t),this.emit("product-delete",t)):be.warn(`Product ${t.id} already in a detached state.`)}createProduct(t,e){let i;return i=e===ln?new hn(t):new an(t),this.insertProduct(i),i}insertGeometry(t){let{geometries:e,geometriesById:i,geometriesByType:s}=this;e.push(t),i[t.id]=t,s[t.type].push(t)}removeGeometry(t){let{geometries:e,geometriesById:i,geometriesByType:s}=this,r=e.indexOf(t);if(-1===r)return void be.warn(`Geometry ${t.id} not found.`);if(e.splice(r,1),i[t.id]!==t)return void be.error(`Entry ${t.id} in 'geometries stored by ID' record does not contain this object.`);delete this.geometriesById[t.id];let n=s[t.type];if(!n)return void be.error(`Geometry ${t.id} not found in 'geometries stored by type' record.`);let o=n.indexOf(t);-1!==o?n.splice(o,1):be.error(`Node ${t.id} not found in 'nodes stored by type' record.`)}insertMaterial(t){t.spaceGraph?be.warn(`Material ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.materials,this.materialsById,this.materialsByType),this.registerNode(t),this.emit("material-create",t))}removeMaterial(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.materials,this.materialsById,this.materialsByType),this.unregisterNode(t),this.emit("material-delete",t)):be.warn(`Material ${t.id} already in a detached state.`)}createMaterial(t,e,...i){let s;switch(t){case Pe:s=new Ee(e,i[0],i[1]);break;case Te:s=new Ae(e,i[0]);break;case Ie:s=new Se(e,i[0],i[1]);break;case Ce:s=new Me(e)}return this.insertMaterial(s),s}insertRelation(t){t.spaceGraph?be.warn(`Relation ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.relations,this.relationsById,this.relationsByType),this.registerNode(t),this.emit("relation-create",t))}removeRelation(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.relations,this.relationsById,this.relationsByType),this.unregisterNode(t),this.emit("relation-delete",t)):be.warn(`Relation ${t.id} already in a detached state.`)}createRelation(t,e){let i;if(t===Yn)i=new $n(e);return this.insertRelation(i),i}insertCustomAttribute(t){t.spaceGraph?be.warn(`Custom attribute ${t.id} already part of a space graph object.`):(t.spaceGraph=this,this.insertNode(t,this.customAttributes,this.customAttributesById,this.customAttributesByType),this.registerNode(t),this.emit("custom-attribute-create",t))}removeCustomAttribute(t){t.spaceGraph?(t.spaceGraph=null,this.removeNode(t,this.customAttributes,this.customAttributesById,this.customAttributesByType),this.unregisterNode(t),this.emit("custom-attribute-delete",t)):be.warn(`Custom attribute ${t.id} already in a detached state.`)}getId(){return de()}emit(t,...e){this.emitter.emit(t,...e)}on(t,e,i){this.emitter.on(t,e,i)}once(t,e,i){this.emitter.once(t,e,i)}off(t,e){this.emitter.off(t,e)}toJSON(){let t=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.products),e=function(t){let e=[];for(let i of t){let t=b(i);e.push(t)}return e}(this.geometries),i=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.materials),s=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.relations),r=function(t){let e=[];for(let i of t){let t=i.toJSON();e.push(t)}return e}(this.customAttributes);return{schemaVersion:"0.22.1",spatialStructure:this.spatialStructure.toJSON(),sharedResources:{products:t,geometries:e,materials:i,relations:s,customAttributes:r}}}}function Po(t,e,i,s){const r=1e-7*1e-7;let n=[e[0]-t[0],e[1]-t[1]],o=[s[0]-i[0],s[1]-i[1]],a=i[0]-t[0],l=i[1]-t[1],h=n[0]*o[1]-n[1]*o[0],u=h*h,c=n[0]*n[0]+n[1]*n[1];if(u>r*c*(o[0]*o[0]+o[1]*o[1])){let e=(a*o[1]-l*o[0])/h,i=(a*n[1]-l*n[0])/h;return{tag:2,intersect:!0,p:[t[0]+e*n[0],t[1]+e*n[1]],u:e,v:i}}return h=a*n[1]-l*n[0],u=h*h,u>r*c*(a*a+l*l)?{tag:0,intersect:!1}:{tag:1,intersect:!0}}function Eo(t,e,i,s){const r=[e[0]-t[0],e[1]-t[1]],n=[s[0]-i[0],s[1]-i[1]],o=i[0]-t[0],a=i[1]-t[1];let l=r[0]*n[1]-r[1]*n[0],h=l*l;const u=r[0]*r[0]+r[1]*r[1];let c,d,p,f;if(h>1e-14*u*(n[0]*n[0]+n[1]*n[1])){const e=(o*n[1]-a*n[0])/l;if(e<0||e>1)return{tag:0,intersect:!1};{const i=(o*r[1]-a*r[0])/l;return i<0||i>1?{tag:0,intersect:!1}:(c=t[0]+e*r[0],d=t[1]+e*r[1],{tag:1,intersect:!0,p:[c,d],u:e,v:i})}}if(l=o*r[1]-a*r[0],h=l*l,h>1e-14*u*(o*o+a*a))return{tag:2,intersect:!1};{const e=(r[0]*o+r[1]*a)/u,i=e+(r[0]*n[0]+r[1]*n[1])/u;let s,l;e<i?(s=e,l=i):(s=i,l=e);const h=function(t,e,i,s){if(e<i||t>s)return{tag:0,intersect:!1};if(t===i&&e===s)return{tag:1,intersect:!0};if(e>i)return e<s?{tag:3,intersect:!0,w0:t<i?i:t,w1:e>s?s:e}:{tag:2,intersect:!0,w:t};return{tag:2,intersect:!0,w:e}}(0,1,s,l);switch(h.tag){case 0:return{tag:3,intersect:!1};case 1:return{tag:4,intersect:!0};case 2:{const e=h.w;return c=t[0]+e*r[0],d=t[1]+e*r[1],{tag:5,intersect:!0,p:[c,d],u:e}}case 3:{const e=h.w0,i=h.w1;return c=t[0]+e*r[0],d=t[1]+e*r[1],p=t[0]+i*r[0],f=t[1]+i*r[1],{tag:6,intersect:!0,p:[c,d],q:[p,f],u0:e,u1:i}}default:throw new Error("Unknown tag value.")}}}function To(t,e){let i=t.spatialGraph,s=new ps;for(let r of e.edges){let t=i.edgesById[r];if(!t)return void be.warn(`Edge ${r} not found, skipping boundary.`);s.edges.push(t)}if(cr(s))return s}function Ao(t,e){let i=[];for(let s of e){let e=To(t,s);if(!e)return;i.push(e)}return i}function Io(t,e){let{id:i,position:s}=e,r=new Ps(i,s[0],s[1]);return Os(r,e),r}function So(t,e){let i=t.spatialGraph,s=e.vertices[0],r=e.vertices[1];if(s===r)return void be.warn(`Same vertex referenced twice, skipping edge ${e.id}.`);let n=i.verticesById[s],o=i.verticesById[r];if(!n||!o)return void be.warn(`One or both vertices not found, skipping edge ${e.id}.`);let a=new Us(e.id,n,o);return Os(a,e),a}function Co(t,e,i){let s=Ao(t,e.boundaries);if(!s)return void be.warn(`Invalid boundaries, skipping space ${e.id}.`);let r=new Ws(e.id,s);return Os(r,e),Ns(r,e,i),e.attributes&&r.setAttributes(e.attributes),r}function Mo(t,e){let i=to(e.type,e.id);return Os(i,e),i.setTransform(e.position,e.rotation??0),e.parameters&&i.setParameters(e.parameters),i}function Oo(t,e){let i=eo(e.type,e.id);return Os(i,e),e.parameters&&i.setParameters(e.parameters),i}const No={};function Lo(t,e,i){return No[t]||(No[t]={}),No[t][e]=i,i}const Ro={.15:t=>{if(("layout:space"===t.type||"element:floor"===t.type||"element:ceiling"===t.type)&&t.id.includes(":")){const e=JSON.parse(JSON.stringify(t));return e.id=de(),e}return t},.16:t=>{if("element:window"===t.type&&t.parameters&&"framePosition"in t.parameters){const e=JSON.parse(JSON.stringify(t));return delete e.parameters.framePosition,e}return t},"0.20.3":t=>{if("layout:space"===t.type||!t.parameters)return t;let e=!1;const i=JSON.parse(JSON.stringify(t.parameters));if("height"in i&&i.height<.01&&(i.height=.01,e=!0),"width"in i&&i.width<.01&&(i.width=.01,e=!0),"length"in i&&i.length<.01&&(i.length=.01,e=!0),e){const e=JSON.parse(JSON.stringify(t));return e.parameters=i,e}return t}};function ko(t,e){return!e||function(t,e){var i;if(void 0!==(null==(i=No[t])?void 0:i[e]))return No[t][e];const s=t.split(".").map((t=>parseInt(t))),r=e.split(".").map((t=>parseInt(t)));for(let n=0;n<Math.max(s.length,r.length);n++){const i=s[n]||0,o=r[n]||0;if(i>o)return Lo(t,e,1);if(i<o)return Lo(t,e,-1)}return Lo(t,e,0)}(e,t)<0}function Bo(t,e){let i=t;for(const s in Ro)ko(s,e)&&(i=Ro[s](i));return i}function Fo(t,e){var i;let{position:s,rotation:r,rotationAxis:n}=e;if(t.setTransform(s??[0,0,0],r??0,n),e.parameters){let s=!!(null==(i=e.elements)?void 0:i.length);!function(t,e,i=!1){switch(t.type){case"element:ceiling":case"element:floor":case"element:boundaryWall":case"element:curtainWall":case"element:spaceDivider":case"element:wall":case"element:opening":case"element:asset":case"element:beam":case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:ramp":case"element:roof":case"element:railing":case"element:slab":case"element:stairFlight":case"element:window":t.setParameters(e);break;case"element:kitchen":case"element:stairs":t.setParameters(e,i)}}(t,e.parameters,s)}"element:generic"!==e.type&&"element:asset"!==e.type||(t.geometries=e.geometries?JSON.parse(JSON.stringify(e.geometries)):[])}function Do(t,e,i){let s,r=Bo(e,null==i?void 0:i.sourceSchemaVersion);switch(r.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":s=function(t,e){let i=Ao(t,e.boundaries);if(!i)return void be.warn(`Invalid boundaries, skipping boundary wall ${e.id}.`);let s=Kn(e.type,e.id,i);return e.parameters&&s.setParameters(e.parameters),s}(t,r);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":s=function(t,e){let i=[];if(i=Array.isArray(e.edge)?e.edge:[e.edge],!i.length)return void be.warn(`Element ${e.id} references no edges and is skipped.`);let s=[];for(let n of i){let i=t.spatialGraph.edgesById[n];if(!i)return void be.warn(`Edge ${e.edge} not found, skipping edge element ${e.id}.`);s.push(i)}let r=Kn(e.type,e.id,s);return e.parameters&&r.setParameters(e.parameters),r}(t,r);break;case"element:opening":s=function(t,e){let i=Kn("element:opening",e.id);return e.parameters&&i.setParameters(e.parameters),i}(0,r);break;case"element:asset":s=function(t,e,i){let s=Kn(e.type,e.id);if(Fo(s,e),!e.product)return e.geometries||be.warn(`Element ${s.id} does not specify a 'geometries' field and does not reference a product.`),s;let r=t.spaceGraph??i;if(r){let t=r.nodesById[e.product];if(!t)return void be.warn(`Product ${e.product} not found, skipping element ${e.id}.`);s.setProduct(t)}else be.warn(`Layout not attached and space graph not passed as an argument, cannot find product ${e.product}.`);return s}(t,r,i);break;case"element:beam":case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:kitchen":case"element:railing":case"element:ramp":case"element:roof":case"element:slab":case"element:stairFlight":case"element:stairs":case"element:window":s=function(t,e){let i=Kn(e.type,e.id);return Fo(i,e),i}(0,r);break;default:return void be.warn(`Unknown element type '${r.type}', skipping element.`)}if(!s)return;Os(s,r),Ns(s,r,null==i?void 0:i.customAttributesById);let n=r.elements??[];for(let o of n){let e=Do(t,o,i);e&&s.insertElement(e)}return s}function Uo(t,e,i){Ns(t,e,i.customAttributesById),Os(t,e),function(t,e){let i=t.spatialGraph,s=e.spatialGraph;for(let r of s.vertices){let t=Io(0,r);i.insertVertex(t)}for(let r of s.edges){let e=So(t,r);e&&i.insertEdge(e)}}(t,e),function(t,e,i){for(let s of e.spaces){let e=Co(t,Bo(s),i.customAttributesById);e&&t.insertSpace(e)}}(t,e,i),function(t,e,i){for(let s of e.elements){let e=Do(t,s,i);e&&t.insertElement(e)}}(t,e,i),function(t,e){let i=e.annotations??[];for(let s of i){let e=Mo(0,s);t.insertAnnotation(e)}}(t,e),function(t,e){let i=e.views??[];for(let s of i){let e=Oo(0,s);t.insertView(e)}}(t,e),function(t){const e=t.spatialGraph.edges;for(const s of e)s.spaces=[null,null],s.boundaryWalls=[null,null];const i=[];for(const s of t.spaces)ir(s),i.push(lr(s));for(const s of e){if(null!==s.spaces[0]||null!==s.spaces[1])continue;const[e,r]=s.getPoints(),n=ui(e,r,.5);for(let o=0;o<t.spaces.length;o++)if(wi(n,i[o])){s.spaces[0]=t.spaces[o],s.spaces[1]=t.spaces[o];break}}for(const s of t.elements)"element:boundaryWall"===s.type&&sr(s)}(t)}function Go(t,e){t.name=e.name??t.name,t.customId=e.customId??t.customId}function Xo(t,e){let i;return t.type===ln?(i=new hn(t.id),i.products=JSON.parse(JSON.stringify(t.products))):(i=new an(t.id),i.geometries=JSON.parse(JSON.stringify(t.geometries))),t.attributes&&i.setAttributes(t.attributes),t.customAttributes&&i.setCustomAttributes(t.customAttributes,e),Go(i,t),i}function Wo(t){return JSON.parse(JSON.stringify(t))}function Ho(t){let e;if(Array.isArray(t)||"string"==typeof t)be.warn("Color literal or standard material reference not allowed in shared resources section.");else if("object"==typeof t)switch(t.type){case Pe:let[i,s,r,n]=function(t){let[e,i,s,r]=[1,1,1,1];return Array.isArray(t)?[e,i,s,r]=Ue(t):"string"==typeof t&&([e,i,s,r]=[1,1,1,1],""===t?be.warn("Empty string not a valid color literal."):t.startsWith("#")?[e,i,s,r]=Ge(t):t.startsWith("rgb(")?[e,i,s,r]=Xe(t,!1):t.startsWith("rgba(")?[e,i,s,r]=Xe(t,!0):be.warn(`String ${t} not a valid color literal.`)),[e,i,s,r]}(t.value);e=new Ee(t.id,[i,s,r],n);break;case Te:e=new Ae(t.id,t.reference);break;case Ce:e=new Me(t.id),Go(e,t),e.colorDiffuse=[...t.colorDiffuse],t.colorSpecular&&(e.colorSpecular=[...t.colorSpecular]),e.specularCoefficient=t.specularCoefficient??e.specularCoefficient,e.opacity=t.opacity??e.opacity;break;default:e=new Ee(t.id,[1,1,1],1),be.warn(`Unknown material type ${t.type}, creating default material.`)}else be.warn("Material not an array, string or object.");return e}function Yo(t,e){let i;if(e.type===Yn){i=new $n(e.id);let s=[];for(let r of e.elements)t.nodesById[r]?s.push(t.nodesById[r]):be.error(`Element ${r} not found, referenced by relation ${i.id}.`);i.insertElements(s)}return Go(i,e),i}function $o(t,e){let i=new uo(e.id);Go(i,e),Ns(i,e,t.customAttributesById),i.position=[...e.position],i.rotation=e.rotation;for(let s of e.layouts){let e=zo(t,s);i.insertLayout(e)}return i}function jo(t){const e=function(t){const{id:e,attributes:{resourceType:i}}=t;return e.endsWith(`:${i}`)?e:`${e}:${i}`}(t),i=new vs(e,t.attributes);return Go(i,t),i}function zo(t,e){let i=new lo(e.id);return Uo(i,e,t),i}function Vo(t,e){let i;switch(e.type){case co:i=function(t,e){let i=new po(e.id);Go(i,e),Ns(i,e,t.customAttributesById),e.location&&(i.location=JSON.parse(JSON.stringify(i.location)));for(let s of e.floors){let e=$o(t,s);i.insertFloor(e)}return i}(t,e);break;case ho:i=$o(t,e);break;case ao:i=zo(t,e)}return i}function qo(t,e){!function(t,e){for(let i of e){let e=jo(i);e&&t.insertCustomAttribute(e)}}(t,e.customAttributes||[]),function(t,e){for(let i of e){let e=Xo(i,t.customAttributesById);t.insertProduct(e)}}(t,e.products),function(t,e){for(let i of e){let e=Wo(i);t.insertGeometry(e)}}(t,e.geometries),function(t,e){for(let i of e){let e=Ho(i);e&&t.insertMaterial(e)}}(t,e.materials)}function Jo(t,e){qo(t,e.sharedResources),function(t,e){let i=Vo(t,e);t.insertSpatialStructure(i)}(t,e.spatialStructure),function(t,e){for(let i of e){let e=Yo(t,i);e&&t.insertRelation(e)}}(t,e.sharedResources.relations||[])}function Ko(t,e,i,s){let r=t[0],n=t[1];for(let o=1;o<e.length-1;o++){let a=e[o];if(Pi(a,r,n)<1e-7)return i?t[0]=a:t[1]=a,void(s?e.splice(0,o):e.splice(o+1))}}function Zo(t){let e=0;for(;e<t.length-2;){let i=t[e],s=t[e+2];Pi(t[e+1],i,s)<1e-7?t.splice(e+1,1):e++}}function Qo(t){if(t.length<3)return!1;let e=t.slice();e.push(t[0]);for(let i=0;i<e.length-2;i++){let t=e[i],s=e[i+1];for(let r=i+1;r<e.length-1;r++){const i=1e-7;let n=Eo(t,s,e[r],e[r+1]);if(1===n.tag&&n.u>i&&n.u<1-i)return!0}}return!1}const ta="miter",ea=.05,ia=.15,sa=2.5,ra=0;function na(t,e){let i={indices:[t,e],faces:[-1,-1],geometry:{tangible:!0,skipped:!1,parameters:{width:ia,height:sa,offset:ra},fragments:[],computed:{valid:!0,skipped:!1,selfIntersecting:!1,sidePoints1:[],sidePoints2:[],joinPoints1:[],joinPoints2:[],points:[]}},openings:[]};return i.geometry.fragments=[{edge:i,angle:0,points:[],joinPoints:[],sidePoints:[]},{edge:i,angle:0,points:[],joinPoints:[],sidePoints:[]}],i}const oa="intersectCap",aa="intersectCap";function la(t){let e=t.toFixed(3),i=parseFloat(e);return e+=t>i?"+":t<i?"-":" ",t>=0&&(e=" "+e),e}function ha(t){if(t.length>0)for(let e=0;e<t.length;e++){let i=t[e];i[0],i[1]}}function ua(t,e){for(let i of e)if(t.length>0){let e=t[0],s=t[t.length-1],r=li(fi(i,e)),n=li(fi(i,s));r>1e-7&&n>1e-7&&t.push(i)}else t.push(i)}function ca(t,e,i,s,r){0===t.joinPoints.length?(ua(t.joinPoints,[...s,i]),ua(t.sidePoints[0],r)):(ua(t.joinPoints,s),ua(t.sidePoints[1],r.slice().reverse())),ha(t.joinPoints),ha(t.sidePoints[0]),ha(t.sidePoints[1])}function da(t,e,i,s,r){ca(t,0,i,[s],[s]),ca(e,0,i,[r],[r]),t.edge.geometry.computed.skipped=!0,e.edge.geometry.computed.skipped=!0}function pa(t,e,i,s){ca(t,0,i,[s],[s]),ca(e,0,i,[s],[s])}function fa(t,e,i,s,r){ca(t,0,i,[s],[s]),ca(e,0,i,[r],[r])}function ma(t,e,i,s,r,n,o,a,l,h,u){if("ignore"===u)da(t,e,i,r,a);else{let u;if(u=h?Po(s,r,l,a):Po(n,r,o,a),2!==u.tag)return be.warn("Edge side line does not intersect edge cap line, ignoring result."),void da(t,e,i,r,a);let c=u.p;h?(ca(t,0,i,[c],[c]),ca(e,0,i,[a,c],[a])):(ca(t,0,i,[r,c],[r]),ca(e,0,i,[c],[c]))}}function ga(t,e,i,s,r,n,o,a,l,h,u,c){t.edge.id,e.edge.id;let d=Po(s,r,a,l);if(2!==d.tag)return be.warn("Edge side lines do not intersect, ignoring result.",d),void da(t,e,i,r,l);let p=li(fi(r,s)),f=li(fi(l,a)),m=Math.max(0,1-.2/p),g=Math.max(0,1-.2/f),{p:y,u:v,v:x}=d,b="",_="";if(v>=.9999999)if(o)if(x>=.9999999){const s=1;if(li(fi(y,i))>s){let s,n=Po(y,i,r,l);2!==n.tag?(be.warn("Bevel construction failed, using center point.",n),s=ui(r,l,.5)):s=n.p,ca(t,0,i,[s],[r,s]),ca(e,0,i,[s],[l,s])}else pa(t,e,i,y)}else if(x>=g)pa(t,e,i,y);else{let c=o&&u?oa:"ignore";ma(t,e,i,s,r,n,a,l,h,!0,c),_="ignore"===c?"* (ignore)":"* (intersectCap)"}else da(t,e,i,r,l);else if(x>=.9999999)if(u)if(v>=m)pa(t,e,i,y);else{let c=o&&u?oa:"ignore";ma(t,e,i,s,r,n,a,l,h,!1,c),b="ignore"===c?"* (ignore)":"* (intersectCap)"}else da(t,e,i,r,l);else be.warn("Edge side line segments cross, ignoring result."),da(t,e,i,r,l);la(v),m.toFixed(3),la(x),g.toFixed(3)}function ya(t,e,i,s,r,n,o,a,l,h,u,c){t.edge.id,e.edge.id;let d=Po(s,r,a,l);if(2!==d.tag)return be.warn("Edge side lines do not intersect, ignoring result.",d),void da(t,e,i,r,l);let p=li(fi(r,s)),f=li(fi(l,a)),m=Math.max(0,1-1/p),g=Math.max(0,1-1/f),{p:y,u:v,v:x}=d,b="",_="";if(v>=0&&v<=1+1e-7&&x>=0&&x<=1+1e-7)pa(t,e,i,y);else if(v>1&&x>1)be.warn("Edge side line segments do not cross, ignoring result."),da(t,e,i,r,l);else if(v>1)if(x>=g)pa(t,e,i,y);else{let c=o&&u?aa:"ignore";ma(t,e,i,s,r,n,a,l,h,!1,c),_="ignore"===c?"* (ignore)":"* (intersectCap)"}else if(x>1)if(v>=m)pa(t,e,i,y);else{let c=o&&u?aa:"ignore";ma(t,e,i,s,r,n,a,l,h,!0,c),b="ignore"===c?"* (ignore)":"* (intersectCap)"}else da(t,e,i,r,l);la(v),m.toFixed(3),la(x),g.toFixed(3)}function va(t,e){let i,s,r,n=e[0];n.indices[0]===t?(i=n.geometry.fragments[0],s=i.points[0],r=i.points[1]):(i=n.geometry.fragments[1],s=i.points[1],r=i.points[0]),i.joinPoints.push(s,r),i.sidePoints[0].push(s),i.sidePoints[1].push(r)}function xa(t,e,i){for(let s=0;s<e.length;s++){let r,n,o,a,l,h,u,c,d,p,f,m,g=e[s],y=s<e.length-1?e[s+1]:e[0],v=!g.geometry.skipped&&0!==g.geometry.parameters.width,x=!y.geometry.skipped&&0!==y.geometry.parameters.width;if(!v&&!x)continue;g.indices[0]===t?(r=g.geometry.fragments[0],n=g.geometry.fragments[1],o=n.points[0],a=r.points[0],l=r.points[1],h=i[g.indices[1]].position):(r=g.geometry.fragments[1],n=g.geometry.fragments[0],o=n.points[1],a=r.points[1],l=r.points[0],h=i[g.indices[0]].position),y.indices[0]===t?(u=y.geometry.fragments[0],c=y.geometry.fragments[1],d=c.points[1],p=u.points[1],f=u.points[0],m=i[y.indices[1]].position):(u=y.geometry.fragments[1],c=y.geometry.fragments[0],d=c.points[0],p=u.points[0],f=u.points[1],m=i[y.indices[0]].position);let b=i[t].position;const _=.01;let w=bi(o,a,d,p);if(w<_||w>Math.PI-_)fa(r,u,b,a,p);else{1===vi(h,b,m)?ga(r,u,b,o,a,l,v,d,p,f,x):ya(r,u,b,o,a,l,v,d,p,f,x)}}}function ba(t){let e=t.geometry;e.fragments[0].joinPoints=[],e.fragments[0].sidePoints[0]=[],e.fragments[0].sidePoints[1]=[],e.fragments[1].joinPoints=[],e.fragments[1].sidePoints[0]=[],e.fragments[1].sidePoints[1]=[],e.computed={valid:!0,skipped:!1,selfIntersecting:!1,sidePoints1:[],sidePoints2:[],joinPoints1:[],joinPoints2:[],points:[]}}function _a(t,e){let i=function(t){let e={};for(let i of t){let t=i.indices[0],s=i.indices[1],r=Math.min(t,s),n=Math.max(t,s);e[r.toString()+"_"+n.toString()]=i}return e}(e),s=[];for(let n of e){if(!n.geometry.tangible||n.geometry.skipped)continue;let t=n.indices[0],e=n.indices[1];s[t]=!0,s[e]=!0,ba(n)}let{vertices:r}=t;for(let n=0;n<r.length;n++){if(!s[n])continue;let t=[],e=r[n];for(let s of e.edges){if(!s.geometry.tangible||s.geometry.skipped)continue;let e=s.indices[0],r=s.indices[1],n=Math.min(e,r),o=Math.max(e,r);i[n.toString()+"_"+o.toString()]&&t.push(s)}t.length,1===t.length?va(n,t):xa(n,t,r)}}function wa(t,e){let i=e.element;if(i?t.geometry.tangible="element:spaceDivider"!==i.type:e.boundaryWalls[0]||e.boundaryWalls[1]?t.geometry.tangible=!0:t.geometry.tangible=!1,i&&"element:wall"===i.type){let{width:e,height:s,offset:r}=i.parameters;t.geometry.parameters={width:e,height:s,offset:r}}else t.geometry.parameters={width:0,height:0,offset:0}}function Pa(t,e){let i=[],s={};for(let h of e)for(let t of h.vertices)if(void 0===s[t.id]){let e=(r=t.position[0],n=t.position[1],{position:[r,n],edges:[],geometry:{parameters:{joinStyle:{type:ta,parameters:{distance:ea}}}}});e.reference=t,s[t.id]=i.push(e)-1}var r,n;let o=[],a={};for(let h of e){let t=h.vertices[0],e=h.vertices[1],i=na(s[t.id],s[e.id]);wa(i,h),i.id=h.id,i.reference=h,o.push(i),a[h.id]=!0}let l=function(t,e){return{vertices:t,edges:e,cycles:[],faces:[]}}(i,o);return function(t){let{vertices:e,edges:i}=t;for(let s of e)s.edges=[];for(let s of i){let t=s.indices[0],i=s.indices[1];e[t].edges.push(s),e[i].edges.push(s)}}(l),function(t){let{vertices:e}=t;for(let i=0;i<e.length;i++){let t=e[i],s=t.edges,r=[];for(let n of s){let s=e[i===n.indices[0]?n.indices[1]:n.indices[0]],o={edge:n,angle:ni([s.position[0]-t.position[0],s.position[1]-t.position[1]]),points:[],joinPoints:[],sidePoints:[[],[]]},a={edge:n,fragment:o};i===n.indices[0]?n.geometry.fragments[0]=o:n.geometry.fragments[1]=o,r.push(a)}r.sort(((t,e)=>t.fragment.angle-e.fragment.angle)),t.edges=r.map((t=>t.edge))}}(l),l}function Ea(t){const e=t.map((t=>t.geometry.computed)),i=function(t){var e;if(0===t.length)return[];const i={};for(const l of t)for(const t of l.indices)i[t]??(i[t]=[]),i[t].push(l);let s=(null==(e=Object.entries(i).find((([,t])=>1===t.length)))?void 0:e[0])||Object.keys(i)[0];const r=[],n=new Set;let o=parseInt(s),a=i[o][0];for(;r.length<t.length;){if(n.has(a)){if(a=t.find((t=>!n.has(t))),!a)break;o=a.indices[0];continue}const e=a.indices[0]!==o;r.push({edge:a,reverse:e}),n.add(a);const s=e?a.indices[0]:a.indices[1],l=i[s].find((t=>!n.has(t)));if(l)o=s,a=l;else{if(a=t.find((t=>!n.has(t))),!a)break;o=a.indices[0]}}return r}(t),s=t[0].geometry.computed;let r=s.valid;const n=i[0].reverse,o=i[0].edge.geometry.computed,a=i[i.length-1].reverse,l=i[i.length-1].edge.geometry.computed,h=n?o.joinPoints2:o.joinPoints1,u=a?l.joinPoints1:l.joinPoints2,c=[],d=[];for(const{edge:m,reverse:g}of i){const{computed:t}=m.geometry;g?(c.unshift(...t.sidePoints2),d.push(...t.sidePoints1)):(c.unshift(...t.sidePoints1),d.push(...t.sidePoints2))}const p=$(e.map((t=>t.points)));let f=[];if(1===p.length)f=p[0];else if(p.length>1){const t=z(p,.001,void 0,!0);t.length>0&&(f=t[0])}return 0===f.length&&(be.warn(`Empty wall geometry after merging edge profiles: ${t.map((t=>t.id)).join(", ")}`),r=!1),{valid:r,skipped:s.skipped,selfIntersecting:s.selfIntersecting,sidePoints1:c.slice(),sidePoints2:d.slice(),joinPoints1:h.slice(),joinPoints2:u.slice(),points:f}}function Ta(t,e){Js(t,e),e.emit("geometry-profile-update",e);for(let i of e.slabs)i.emit("geometry-profile-update",i)}function Aa(t){let e=function(t){let e=new Map;for(let i of t)for(let t of i.boundaryWalls)t&&e.set(t.id,t);return[...e.values()]}(t);for(let i of e)Lr(i)}function Ia(t){let e=t.spatialGraph.edges,i=Pa(0,e);!function(t){let{vertices:e,edges:i}=t;for(let s of i){let{geometry:t}=s,i=s.indices[0],r=s.indices[1],n=t.parameters.width,o=t.parameters.offset,a=e[i].position,l=e[r].position,h=fi(l,a);if(t.skipped=li(h)<1e-7,!t.skipped){let e=di(ci(h)),i=pi(e,.5*n+o),s=pi(e,-.5*n+o),r=ri(a,i),u=ri(a,s),c=ri(l,i),d=ri(l,s);t.fragments[0].points=[r,u],t.fragments[1].points=[c,d]}}}(i),_a(i,i.edges),function(t,e){for(let i of e){let{geometry:t}=i;if(!t.tangible||t.skipped||0===t.parameters.width)continue;let e=t.fragments[0],s=t.fragments[1],r=[...e.joinPoints],n=[...s.joinPoints],o=[...e.sidePoints[0]],a=[...e.sidePoints[1]],l=[...s.sidePoints[0]],h=[...s.sidePoints[1]],u=Po(r[0],n[n.length-1],r[r.length-1],n[0]);2===u.tag&&u.u>0&&u.u<1&&u.v>0&&u.v<1&&(n.reverse(),l.reverse(),h.reverse(),[l,h]=[h,l]);let c=h.concat(o),d=a.concat(l);2===c.length&&2===d.length&&(Ko(c,r,!1,!0),Ko(c,n,!0,!1),Ko(d,r,!0,!1),Ko(d,n,!1,!0)),Zo(c),Zo(r),Zo(d),Zo(n),1===vi(c[0],c[c.length-1],d[0])&&(c.reverse(),d.reverse(),r.reverse(),n.reverse(),[c,d]=[d,c]);let p=c.slice(0,c.length-1),f=r.slice(0,r.length-1),m=d.slice(0,d.length-1),g=n.slice(0,n.length-1),y=it(p.concat(f).concat(m).concat(g),.001),v=i.geometry.computed;v.sidePoints1=c,v.sidePoints2=d,v.joinPoints1=r,v.joinPoints2=n,v.points=y,v.selfIntersecting=Qo(v.points),v.valid=v.points.length>=3&&!v.skipped&&!v.selfIntersecting,i.id,v.valid,v.skipped,v.selfIntersecting}}(0,i.edges),function(t){var e;let i={};for(let s of t.edges){let t=s.reference.element;if("element:wall"===(null==t?void 0:t.type)){let r=s.geometry.computed;1===t.getEdges().length?(t.geometryProfile={valid:r.valid,skipped:r.skipped,selfIntersecting:r.selfIntersecting,sidePoints1:r.sidePoints1.slice(),sidePoints2:r.sidePoints2.slice(),joinPoints1:r.joinPoints1.slice(),joinPoints2:r.joinPoints2.slice(),points:r.points.slice()},t.emit("geometry-profile-update",t)):(i[e=t.id]??(i[e]=[]),i[t.id].push(s),i[t.id].length===t.getEdges().length&&(t.geometryProfile=Ea(i[t.id]),t.emit("geometry-profile-update",t)))}}}(i),function(t){var e;for(let i of t)"element:wall"===(null==(e=i.element)?void 0:e.type)&&Fr(i.element)}(e),Aa(e)}function Sa(t){Ia(t),function(t){let e=t.spaces;for(let i of e){Ta(t,i);for(let t of i.slabs)er(t)}}(t)}function Ca(t){return new Promise(((e,i)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>i(t.error)}))}function Ma(t,e){const i=indexedDB.open(t);i.onupgradeneeded=()=>i.result.createObjectStore(e);const s=Ca(i);return(t,i)=>s.then((s=>i(s.transaction(e,t).objectStore(e))))}let Oa;function Na(){return Oa||(Oa=Ma("keyval-store","keyval")),Oa}for(var La="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ra="undefined"==typeof Uint8Array?[]:new Uint8Array(256),ka=0;ka<64;ka++)Ra[La.charCodeAt(ka)]=ka;var Ba={exports:{}};function Fa(t,e){return t<e?-1:t>e?1:0}var Da=Ot(Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=Fa){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:i}=this,s=e[t];for(;t>0;){const r=t-1>>1,n=e[r];if(i(s,n)>=0)break;e[t]=n,t=r}e[t]=s}_down(t){const{data:e,compare:i}=this,s=this.length>>1,r=e[t];for(;t<s;){let s=1+(t<<1),n=e[s];const o=s+1;if(o<this.length&&i(e[o],n)<0&&(s=o,n=e[o]),i(n,r)>=0)break;e[t]=n,t=s}e[t]=r}}},Symbol.toStringTag,{value:"Module"})));function Ua(t,e,i){var s,r,n,o;e=e||1;for(var a=0;a<t[0].length;a++){var l=t[0][a];(!a||l[0]<s)&&(s=l[0]),(!a||l[1]<r)&&(r=l[1]),(!a||l[0]>n)&&(n=l[0]),(!a||l[1]>o)&&(o=l[1])}var h=n-s,u=o-r,c=Math.min(h,u),d=c/2;if(0===c){var p=[s,r];return p.distance=0,p}for(var f=new Da(void 0,Ga),m=s;m<n;m+=c)for(var g=r;g<o;g+=c)f.push(new Xa(m+d,g+d,d,t));var y=function(t){for(var e=0,i=0,s=0,r=t[0],n=0,o=r.length,a=o-1;n<o;a=n++){var l=r[n],h=r[a],u=l[0]*h[1]-h[0]*l[1];i+=(l[0]+h[0])*u,s+=(l[1]+h[1])*u,e+=3*u}return 0===e?new Xa(r[0][0],r[0][1],0,t):new Xa(i/e,s/e,0,t)}(t),v=new Xa(s+h/2,r+u/2,0,t);v.d>y.d&&(y=v);for(var x=f.length;f.length;){var b=f.pop();b.d>y.d&&(y=b,i&&console.log("found best %d after %d probes",Math.round(1e4*b.d)/1e4,x)),b.max-y.d<=e||(d=b.h/2,f.push(new Xa(b.x-d,b.y-d,d,t)),f.push(new Xa(b.x+d,b.y-d,d,t)),f.push(new Xa(b.x-d,b.y+d,d,t)),f.push(new Xa(b.x+d,b.y+d,d,t)),x+=4)}i&&(console.log("num probes: "+x),console.log("best distance: "+y.d));var _=[y.x,y.y];return _.distance=y.d,_}function Ga(t,e){return e.max-t.max}function Xa(t,e,i,s){this.x=t,this.y=e,this.h=i,this.d=function(t,e,i){for(var s=!1,r=1/0,n=0;n<i.length;n++)for(var o=i[n],a=0,l=o.length,h=l-1;a<l;h=a++){var u=o[a],c=o[h];u[1]>e!=c[1]>e&&t<(c[0]-u[0])*(e-u[1])/(c[1]-u[1])+u[0]&&(s=!s),r=Math.min(r,Wa(t,e,u,c))}return 0===r?0:(s?1:-1)*Math.sqrt(r)}(t,e,s),this.max=this.d+this.h*Math.SQRT2}function Wa(t,e,i,s){var r=i[0],n=i[1],o=s[0]-r,a=s[1]-n;if(0!==o||0!==a){var l=((t-r)*o+(e-n)*a)/(o*o+a*a);l>1?(r=s[0],n=s[1]):l>0&&(r+=o*l,n+=a*l)}return(o=t-r)*o+(a=e-n)*a}Da.default&&(Da=Da.default),Ba.exports=Ua,Ba.exports.default=Ua;var Ha,Ya,$a={exports:{}};Ha=$a,Ya=function(){var t={},e=Math.PI/180,i=180/Math.PI,s=6378137,r=20037508.342789244;function n(t){return Number(t)===t&&t%1!=0}function o(e){if(e=e||{},this.size=e.size||256,this.expansion=!0===e.antimeridian?2:1,!t[this.size]){var i=this.size,s=t[this.size]={};s.Bc=[],s.Cc=[],s.zc=[],s.Ac=[];for(var r=0;r<30;r++)s.Bc.push(i/360),s.Cc.push(i/(2*Math.PI)),s.zc.push(i/2),s.Ac.push(i),i*=2}this.Bc=t[this.size].Bc,this.Cc=t[this.size].Cc,this.zc=t[this.size].zc,this.Ac=t[this.size].Ac}return o.prototype.px=function(t,i){if(n(i)){var s=this.size*Math.pow(2,i),r=s/2,o=s/360,a=s/(2*Math.PI),l=s,h=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),u=r+t[0]*o,c=r+.5*Math.log((1+h)/(1-h))*-a;return u>l*this.expansion&&(u=l*this.expansion),c>l&&(c=l),[u,c]}return r=this.zc[i],h=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),u=Math.round(r+t[0]*this.Bc[i]),c=Math.round(r+.5*Math.log((1+h)/(1-h))*-this.Cc[i]),u>this.Ac[i]*this.expansion&&(u=this.Ac[i]*this.expansion),c>this.Ac[i]&&(c=this.Ac[i]),[u,c]},o.prototype.ll=function(t,e){if(n(e)){var s=this.size*Math.pow(2,e),r=s/360,o=s/(2*Math.PI),a=s/2,l=(t[1]-a)/-o;return[(t[0]-a)/r,i*(2*Math.atan(Math.exp(l))-.5*Math.PI)]}return l=(t[1]-this.zc[e])/-this.Cc[e],[(t[0]-this.zc[e])/this.Bc[e],i*(2*Math.atan(Math.exp(l))-.5*Math.PI)]},o.prototype.bbox=function(t,e,i,s,r){s&&(e=Math.pow(2,i)-1-e);var n=[t*this.size,(+e+1)*this.size],o=[(+t+1)*this.size,e*this.size],a=this.ll(n,i).concat(this.ll(o,i));return"900913"===r?this.convert(a,"900913"):a},o.prototype.xyz=function(t,e,i,s){"900913"===s&&(t=this.convert(t,"WGS84"));var r=[t[0],t[1]],n=[t[2],t[3]],o=this.px(r,e),a=this.px(n,e),l=[Math.floor(o[0]/this.size),Math.floor((a[0]-1)/this.size)],h=[Math.floor(a[1]/this.size),Math.floor((o[1]-1)/this.size)],u={minX:Math.min.apply(Math,l)<0?0:Math.min.apply(Math,l),minY:Math.min.apply(Math,h)<0?0:Math.min.apply(Math,h),maxX:Math.max.apply(Math,l),maxY:Math.max.apply(Math,h)};if(i){var c={minY:Math.pow(2,e)-1-u.maxY,maxY:Math.pow(2,e)-1-u.minY};u.minY=c.minY,u.maxY=c.maxY}return u},o.prototype.convert=function(t,e){return"900913"===e?this.forward(t.slice(0,2)).concat(this.forward(t.slice(2,4))):this.inverse(t.slice(0,2)).concat(this.inverse(t.slice(2,4)))},o.prototype.forward=function(t){var i=[s*t[0]*e,s*Math.log(Math.tan(.25*Math.PI+.5*t[1]*e))];return i[0]>r&&(i[0]=r),i[0]<-r&&(i[0]=-r),i[1]>r&&(i[1]=r),i[1]<-r&&(i[1]=-r),i},o.prototype.inverse=function(t){return[t[0]*i/s,(.5*Math.PI-2*Math.atan(Math.exp(-t[1]/s)))*i]},o}(),Ha.exports=Ya;const ja=Mt($a.exports),za={work:{name:"Work",isHidden:!0,description:"space for individual head-down work",spaceUsage:{privateOffice:{name:"Private office",category:["office"]},focusRoom:{name:"Focus room",category:["office"]},openWorkspace:{name:"Open workspace",category:["office"]},enclosedWorkspace:{name:"Enclosed workspace",category:["office"]},closedWorkspace:{name:"Closed workspace",isDeprecated:!0,category:["office"]},executiveOffice:{name:"Executive office",isDeprecated:!0,category:["office"]}}},meet:{name:"Meet",isHidden:!0,spaceUsage:{meetingRoom:{name:"Meeting room",category:["office"]},hub:{name:"Hub",category:["office"]},assembly:{name:"Assembly",category:["office"]},boardRoom:{name:"Board room",category:["office"]},trainingRoom:{name:"Training room",category:["office"]},collaboration:{name:"Collaboration",isDeprecated:!0,category:["office"]}}},live:{name:"live",isHidden:!0,spaceUsage:{living:{name:"Living",category:["residential"]},dining:{name:"Dining",category:["residential"]},dining_living:{name:"Living & Dining",category:["residential"]},homeOffice:{name:"Home office",category:["residential"]},bedroom:{name:"Bedroom",category:["residential"]}}},socialize:{name:"Socialize",isHidden:!0,spaceUsage:{lobby:{name:"Lobby",category:["office","residential"]},reception:{name:"Reception",category:["office"]},lounge:{name:"Lounge",category:["office"]},cafe:{name:"Cafe",category:["office"]},canteen:{name:"Canteen",category:["office"]},pantry:{name:"Pantry",category:["office"]},terrace:{name:"Terrace",isOutdoor:!0,category:["office","residential"]},balcony:{name:"Balcony",isOutdoor:!0,category:["office","residential"]},rooftop:{name:"Rooftop",isOutdoor:!0,category:["office","residential"]},courtyard:{name:"Courtyard",isOutdoor:!0,category:["office","residential"]},garden:{name:"Garden",isOutdoor:!0,category:["residential"]},common:{name:"Common",isDeprecated:!0,category:["office"]}}},support:{name:"Support",isHidden:!0,spaceUsage:{serviceKitchen:{name:"Service kitchen",category:["office"]},printStation:{name:"Print station",category:["office"]},storage:{name:"Storage",category:["lightIndustrial","residential","office","parking"]},mailRoom:{name:"Mail room",category:["office"]},operationalRoom:{name:"Operational room",category:["lightIndustrial","office","parking"]},serviceRoom:{name:"Service room",category:["office"]},laundryRoom:{name:"Laundry room",category:["residential"]},loadingDock:{name:"Loading dock",category:["lightIndustrial"]},operate:{name:"Operate",isDeprecated:!0,category:["office"]},services:{name:"Services",isDeprecated:!0,category:["office","residential"]}}},care:{name:"Care",isHidden:!0,spaceUsage:{kitchen:{name:"Kitchen",category:["residential"]},wellnessRoom:{name:"Wellness room",category:["lightIndustrial","office"]},restroom:{name:"Restroom",category:["lightIndustrial","office","parking"]},bathroom:{name:"Bathroom",category:["residential"]},shower:{name:"Shower",category:["lightIndustrial","office","residential"]},toilet:{name:"Toilet",category:["residential"]}}},circulate:{name:"Circulate",isHidden:!0,spaceUsage:{corridor:{name:"Corridor",category:["lightIndustrial","residential","office","parking"]},foyer:{name:"Foyer",category:["lightIndustrial","residential","office","parking"]},staircase:{name:"Staircase",isVertical:!0,category:["lightIndustrial","residential","office","parking"]},elevator:{name:"Elevator",isVertical:!0,category:["lightIndustrial","residential","office","parking"]}}},drive:{name:"Drive",isHidden:!0,spaceUsage:{parkingSpot:{name:"Parking spot",category:["parking"]},driveway:{name:"Driveway",category:["parking"]},garage:{name:"Garage",category:["residential"]}}},produce:{name:"Produce",isHidden:!0,spaceUsage:{productionArea:{name:"Production area",category:["lightIndustrial"]}}},void:{isHidden:!0,name:"Void",spaceUsage:{shaft:{name:"Shaft",isVertical:!0,category:["lightIndustrial","residential","office","parking"]},buildingOpening:{name:"Building opening",isVertical:!0,category:["lightIndustrial","residential","office","parking"]},floorOpening:{name:"Floor opening",isVertical:!0,category:["lightIndustrial","residential","office","parking"]}}},undefined:{isHidden:!0,spaceUsage:{undefined:{name:"Undefined",category:["residential","office"],isHidden:!0}}}},Va={};function qa(t,e,i){let s=gt(...t),r=gt(...e),n=gt(...i),o=ft(),a=ft(),l=ft();return xt(o,s,n),xt(a,r,n),_t(l,o,a),bt(l,l),[...l]}function Ja(t){let{indices:e,vertices:i}=t,s=[],r=[],n=[],o=ds(i);for(let u=0;u<i.length;u+=3){let t=i[u],e=i[u+1],n=i[u+2];s.push([t,e,n]),r.push([t,n])}for(let u=0;u<e.length;u+=3){let t=e[u],i=e[u+1],o=e[u+2];qa(s[t],s[i],s[o])[1]<.01||n.push([r[t],r[i],r[o]])}let a=[],l=[[]];if(!n.length)return{outlines:a,holes:l,boundingBox:o};let h=et($(n),.0015);h=h.filter((t=>t&&t.length&&Q(t)>5e-4));for(let u of h)Ii(u)?l[0].push(u):a.push(u);return{outlines:a,holes:l,boundingBox:o}}function Ka(t,e={}){let i=function(t,e=at(),i=new Map,s=!0){let r=[],n=t.spaceGraph;if("geometries"in t&&t.geometries)for(let o of t.geometries){let t,a,l,h;if("string"==typeof o){if(t=n.geometriesById[o],!t){be.warn(`Geometry ${o} not found.`);continue}a=[0,0,0],l=0,h=[0,1,0]}else{if("reference:geometry"!==o.type){be.warn(`Operation ${o.type} not supported.`);continue}let e=o.geometry;if("string"==typeof e){if(t=n.geometriesById[e],!t){be.warn(`Geometry ${e} not found.`);continue}}else t=e;a=o.position??[0,0,0],l=o.rotation??0,h=o.rotationAxis??[0,1,0]}let u=Je(a,l);for(let o of u){let a=Ci(o.position,o.rotation,h);s&&(a=ct(at(),e,a));let l=[];if("geometry:uri"===t.type&&"data3d"===t.format){let e=i.get(t.uri),s=(null==e?void 0:e.meshGeometries)||{};for(let t in s){let e=s[t];l.push(...cs(e,n.geometriesById,n.materialsById,[]))}}else l=cs(t,n.geometriesById,n.materialsById,[]);let u=Et(),c=ft();pt(u,a),dt(c,a);for(let t of l)Oi(t.vertices,a);r.push({meshes:l,rotation:u,position:c})}}return r}(t,e.applyElementMatrix?xr(t,e.parentMatrix):void 0,e.resources),s=[];for(let r of i)for(let t of r.meshes)s.push(Ja(t));return s}Object.keys(za).forEach((t=>{const e=za[t];Va[t]={name:e.name,type:"program",category:[]},e.isHidden&&(Va[t].isHidden=e.isHidden);const i={};Object.keys(za[t].spaceUsage).forEach((e=>{const s=za[t].spaceUsage[e];Va[e]={...s,type:"space",program:t},s.category.forEach((t=>{i[t]=!0}))})),Va[t].category=Object.keys(i)})),new ja({size:256});const Za=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Qa(t){return"string"==typeof t&&Za.test(t)}const tl={programs:{care:[{name:"bathroom",tags:[],categories:["residential"]},{name:"kitchen",tags:[],categories:["residential"]},{name:"restroom",tags:[],categories:["lightIndustrial","office","parking","laboratory"]},{name:"shower",tags:[],categories:["lightIndustrial","office","residential","laboratory"]},{name:"toilet",tags:[],categories:["residential"]},{name:"wellnessRoom",tags:[],categories:["lightIndustrial","office","laboratory"]}],circulate:[{name:"corridor",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"elevator",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"foyer",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"staircase",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]}],drive:[{name:"driveway",tags:[],categories:["parking"]},{name:"garage",tags:[],categories:["residential"]},{name:"parkingSpot",tags:[],categories:["parking"]}],live:[{name:"bedroom",tags:[],categories:["residential"]},{name:"dining",tags:[],categories:["residential"]},{name:"dining_living",tags:[],categories:["residential"]},{name:"homeOffice",tags:[],categories:["residential"]},{name:"living",tags:[],categories:["residential"]}],meet:[{name:"assembly",tags:[],categories:["office"]},{name:"boardRoom",tags:[],categories:["office"]},{name:"hub",tags:[],categories:["office"]},{name:"meetingRoom",tags:[],categories:["office"]},{name:"trainingRoom",tags:[],categories:["office"]}],none:[{name:"generic",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]}],produce:[{name:"productionArea",tags:[],categories:["lightIndustrial"]}],research:[{name:"lab",tags:[],categories:["lightIndustrial","laboratory"]}],socialize:[{name:"balcony",tags:["outdoor"],categories:["office","residential"]},{name:"cafe",tags:[],categories:["office","laboratory"]},{name:"canteen",tags:[],categories:["office"]},{name:"courtyard",tags:["outdoor"],categories:["office","residential"]},{name:"garden",tags:["outdoor"],categories:["residential"]},{name:"lobby",tags:[],categories:["office","residential","laboratory"]},{name:"lounge",tags:[],categories:["office","laboratory"]},{name:"pantry",tags:[],categories:["office"]},{name:"reception",tags:[],categories:["office","laboratory"]},{name:"rooftop",tags:["outdoor"],categories:["office","residential"]},{name:"terrace",tags:["outdoor"],categories:["office","residential"]}],support:[{name:"chemicalStore",tags:[],categories:["laboratory"]},{name:"cleanRoom",tags:[],categories:["laboratory"]},{name:"coldRoom",tags:[],categories:["laboratory"]},{name:"laundryRoom",tags:[],categories:["residential"]},{name:"loadingDock",tags:[],categories:["lightIndustrial"]},{name:"mailRoom",tags:[],categories:["office"]},{name:"operationalRoom",tags:[],categories:["lightIndustrial","office","parking","laboratory"]},{name:"printStation",tags:[],categories:["office"]},{name:"serviceKitchen",tags:[],categories:["office"]},{name:"serviceRoom",tags:[],categories:["office"]},{name:"storage",tags:[],categories:["lightIndustrial","office","parking","residential","laboratory"]}],void:[{name:"buildingOpening",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"floorOpening",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]},{name:"shaft",tags:["vertical"],categories:["lightIndustrial","office","parking","residential","laboratory"]}],work:[{name:"enclosedWorkspace",tags:[],categories:["office"]},{name:"focusRoom",tags:[],categories:["office"]},{name:"openWorkspace",tags:[],categories:["office"]},{name:"privateOffice",tags:[],categories:["office"]}]}},el={white:"#ffffff",new_york:"#0c1829",stone:"#4d586b",warsaw:"#929baa",oslo:"#72849e",stone_08:"#f1f2f3",gray:"#cfd5de",athens:"#e8ebef",whisper:"#f7f8fa",zurich:"#bdd7ff",blue_ribbon:"#3355ff",zurich_48:"#dfecff",error:"#ab220a"},il={api:{productDataCacheAge:864e5,productContourCacheAge:864e6},hideElements:[],panZoom:!0,preserveViewbox:"center-center",roomStampSize:null,showCeilingLamps:!1,destroyOnDomRemove:!1,ui:{scale:!0,coordinates:!1},spaceLabelMapping:{},theme:{fontFamily:"Inter, Avenir, Verdana, sans-serif",background:{color:el.whisper,showGrid:!1},wallContours:!1,showAssetTextures:!1,elements:{floorPlan:{grayscale:!1},roomStamp:{}}},units:{system:"metric",areaDecimals:0,lengthDecimals:3,roomDimensions:"area"},zoomRange:[3,300]};let sl="archilogic/product",rl="https://storage.archilogic.com";let nl=new E(["info","warnings","errors"]);function ol(t,e){var i;let s,r=e.product.geometries[0];const n="product:component"===(null==(i=e.product)?void 0:i.type);if("string"==typeof r){let t=r;s=e.spaceGraph.geometriesById[t]}else"reference:geometry"===(null==r?void 0:r.type)&&"string"!=typeof r.geometry&&(s=r.geometry);let o="geometry:uri"===(null==s?void 0:s.type);if(!n&&!o)return Promise.reject("Unsupported product geometry: "+e.product.id);const a=n?["productJson"]:["productJson","productContour"];return t.loadResources(e.product.id,e,a).catch((t=>nl.error(t)))}const al=t=>{const e=[];return t.layout.elementsByType["element:asset"].forEach((t=>{var i;"product"in t&&"product:static"===(null==(i=t.product)?void 0:i.type)&&e.push(t)})),Promise.allSettled(e.map((e=>ol(t.loader,e))))};function ll(t){return fetch(`${rl}/${sl}/outline/${t}.json`).then((t=>{if(t.ok)return t.json();throw Error(t.statusText)}))}const hl="undefined"==typeof window||"undefined"!=typeof process;let ul;try{ul=!hl&&Ma("al-kvs","al-keyval")}catch(cP){nl.warn("indexedDb initialization failed")}let cl=!0;async function dl(t,e,i){if(!ul)return Promise.resolve();i=i||2592e6;try{const s={timeStamp:(new Date).getTime(),content:e,maxAge:i};return cl&&await function(t,e,i=Na()){return i("readwrite",(i=>(i.put(e,t),Ca(i.transaction))))}(t,s,ul),t}catch(s){return}}async function pl(t,e){if(!ul)return Promise.resolve();const i=e||2592e6,s=(new Date).getTime();let r;try{cl&&(r=await function(t,e=Na()){return e("readonly",(e=>Ca(e.get(t))))}(t,ul));const e=s-r.timeStamp;if(e>Math.min(r.maxAge,i))return;if(r.content)return r.content}catch(n){return}}const fl="fpe-dc2-";var ml=(t=>(t[t.None=0]="None",t[t.Default=1]="Default",t[t.Grayscale=2]="Grayscale",t))(ml||{});class gl extends ye{constructor(t){var e,i,s;super(),this.promiseCache=new Map,this.loadStages={product:!0,productContour:!0,productTexture:!1},this.queue={productJson:new Map,productContour:new Map,texture:new Map},this.resources={nodes:new Map,productJson:new Map,productContour:new Map,texture:new Map},this.initialLoading=!0,this._requestCounter=0,this._loadCounter=0;const{settings:r}=t;this.floorPlan=t,this.productContourCacheAge=null==(e=r.api)?void 0:e.productContourCacheAge,this.productDataCacheAge=null==(i=r.api)?void 0:i.productDataCacheAge,this.loadStages.productTexture=!!(null==(s=r.theme)?void 0:s.showAssetTextures)&&!1!==r.loadTextures,this.on("resource-loaded",this.loadStatus,this)}loadStatus(){const t=this._requestCounter;this._loadCounter++,this.emit("loading-status",{totalCount:t,doneCount:this._loadCounter}),t===this._loadCounter&&this.emit("loading-done",{totalCount:t})}loadResources(t,e,i){return Promise.all(i.map((i=>this.loadResource(t,e,i))))}loadResource(t,e,i){if(this.resources.nodes.has(t)||this.resources.nodes.set(t,new Set),this.resources.nodes.get(t).add(e),this.queue[i].has(t))return this.queue[i].get(t);let s;switch(this._requestCounter++,i){case"productJson":s=yl(t,this,e.product);break;case"productContour":this.loadStages.productTexture&&this._requestCounter++,s=vl(t,this).then((()=>{if(this.loadStages.productTexture&&!this.resources.texture.has(t)){if(!this.resources.productJson.has(t))return void nl.warn("texture loading failed, no product info yet");const e=`${rl}/${sl}/thumb/${t}.png`;this.resources.texture.set(t,{textureUrl:e,applyFilter:1}),this.emit("product-load-texture",{resourceId:t})}}))}return this.queue[i].set(t,s),s}reset(){this.resources={nodes:new Map,productContour:new Map,productJson:new Map,texture:new Map},this.queue={productContour:new Map,productJson:new Map,texture:new Map},this._loadCounter=0,this._requestCounter=0,this.promiseCache=new Map,this.initialLoading=!0}}const yl=(t,e,i)=>{var s;const r=e.floorPlan.spaceGraph;t!==(null==i?void 0:i.id)||r.productsById[t]||r.insertProduct(i);const n=JSON.parse(JSON.stringify((null==i?void 0:i.attributes)||{}));return Number.isFinite(null==(s=n.boundingBox)?void 0:s.min[0])||(nl.warn("invalid product bounding box"),delete n.boundingBox),e.resources.productJson.set(t,n),Promise.resolve().then((()=>{e.emit("resource-loaded",{resourceId:t})}))},vl=async(t,e)=>{const i=fl+t,s=e.promiseCache.get(i);if(s)return s;const r=function(t,e){const i=e.productContourCacheAge,s=i||864e6;if(!t)return Promise.reject("product id missing");const r=fl+t,n=e.promiseCache.get(r);if(n)return n;const o=pl(r,i).then((e=>e||ll(t).then((t=>(dl(r,t,s),t))))).catch((t=>{nl.warn(t)}));return e.promiseCache.set(r,o),o}(t,e).then((i=>{const s=i,r=e.resources.productJson.get(t);if(!r.boundingBox){nl.warn("product boundingbox missing - creating from contour");let t=Y(s);r.boundingBox={min:[t.min[0],0,t.min[1]],max:[t.max[0],0,t.max[1]]}}e.resources.productContour.set(t,s),e.emit("resource-loaded",{resourceId:t})})).catch((()=>{}));return e.promiseCache.set(i,r),r};function xl(t){return t.max.map(((e,i)=>e-t.min[i]))}function bl(t,e=[0,0]){const{dimensions:i}=t.parameters,s=t.parent;let r=[];if("element:wall"===(null==s?void 0:s.type)){let t=s.parameters.width;r=[[-e[0],-e[1]],[i[0]+e[0],-e[1]],[i[0]+e[0],t+e[1]],[-e[0],t+e[1]]]}return[{type:"curve:polygon",points:r}]}function _l(t){const e=.01,i=t.elementsByType["element:wall"],s=t.elementsByType["element:boundaryWall"],r=t.elementsByType["element:column"],n=t.elementsByType["element:opening"],o=[];for(const u of n){const t=bl(u,[0,e]),{position:i,rotation:s}=u,r={position:[i[0],i[2]],rotation:s},n=ki(t[0].points,r);o.push([n])}const a=[];for(const u of i){let{points:t}=u.geometryProfile;t=z([t],e)[0],a.push([t])}for(const u of r){const{profile:t}=u.parameters;let{points:i}=ls(t);if("curve:rectangle"===t.type){const[e,s]=t.dimensions;i=[[-e/2,-s/2],[e/2,-s/2],[e/2,s/2],[-e/2,s/2]]}i=ki(i,{position:[u.position[0],u.position[2]],rotation:u.rotation}),i=z([i],e)[0],a.push([i])}for(const u of s){let t=u.boundaries[0].geometryProfile;t=z([t],e)[0],a.push([t])}let{polygons:l}=function(t){if(!t.length||!t[0])return{polygons:[],polyTree:[]};let e=st(t[0]),i=t.slice(1).flatMap(st),s=new H.Clipper;s.AddPaths(e,H.PolyType.ptSubject,!0),s.AddPaths(i,H.PolyType.ptClip,!0);let r=new H.PolyTree;return s.Execute(H.ClipType.ctUnion,r,H.PolyFillType.pftNonZero,H.PolyFillType.pftNonZero),j(r)}(a);l=V(l,-.01).polygons,o.length&&(l=J(l,o).polygons);const h=[];for(const u of l){const t=[];for(const e of u){let i=it(e,.001);i.length&&t.push(i)}t.length&&h.push(t)}return h}const wl=class t{constructor({options:t={}}={}){this.settings=b(il),this.fpeId="fpe-"+Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,3),this.computed={wallContours:[],snapPoints:[],snapMargin:0},this.isBrowser="object"!=typeof process&&"undefined"!=typeof window,this.location={latitude:0,longitude:0,bearing:0},this._emitter=new ye,be.setLevels("errors"),this.set(t),this.loader=new gl(this)}on(t,e,i){return this._emitter.on(t,e,i),this}once(t,e,i){return this._emitter.once(t,e,i),this}off(t,e){return this._emitter.off(t,e),this}emit(t,...e){return this._emitter.emit(t,...e),this}loadLayout(t,{skipGeometryCompute:e=!1}={}){this.loadSpaceGraph(t.spaceGraph,{skipGeometryCompute:e,layoutId:t.id})}loadSpaceGraph(t,{skipGeometryCompute:e=!1,layoutId:i}={}){this.loader.initialLoading||this.loader.reset(),this.spaceGraph=t,this.layout=i?t.nodesById[i]:t.nodesByType["spatialStructure:layout"][0],this.layout&&"spatialStructure:layout"===this.layout.type?(e||(Sa(this.layout),function(t){for(let e of t.elements)Dr(e)}(this.layout)),this.settings.theme.wallContours&&(this.computed.wallContours=_l(this.layout)),setTimeout((()=>{this.loader.emit("spaces-loaded")}),0),al(this).then((()=>{const t=this.settings.hideElements.includes("element:asset"),e=0===Object.keys(this.spaceGraph.products).length;this.loader.emit("assets-loaded",!0),(t||e)&&this.loader.emit("loading-done",{totalCount:0})})).catch((t=>nl.warn(t))),this.loader.initialLoading=!1):nl.warn("No layout to load")}loadSpaceGraphJson(t){this.loadSpaceGraph(function(t){let e=new wo(t.schemaVersion);return Jo(e,t),e}(t))}async loadFloorById(e,i=this.settings.api){return new Promise((async(s,r)=>{var n,a;e&&"string"==typeof e||r(`Expected non-empty string floorId parameter; instead got: "${e}"`);try{const r=k({...i,sdkVersion:t.version}),l=new U(r);this.loader.once("assets-loaded",s);const h=await l.getFloorById(e,!1,!1,!0),u=null==(n=h.properties)?void 0:n.address;if(o(null==u?void 0:u.latitude,90)&&(this.location.latitude=u.latitude),function(t){return o(t,180)}(null==u?void 0:u.longitude)&&(this.location.longitude=u.longitude),function(t){return o(t,180)}(null==u?void 0:u.bearing)&&(this.location.bearing=u.bearing),!(null==(a=h.layout)?void 0:a.layout))throw new Error(`The floor ${e} has no space graph layout`);this.emit("space-api-floor-loaded",e),this.loadSpaceGraphJson(h.layout.layout)}catch(cP){r(cP)}})).catch((t=>{throw this.emit("space-api-floor-error",e,t),t}))}set(t={}){var e,i,s,r,n,o,a,l,h;const u=null==(e=this.settings.hideElements)?void 0:e.includes("element:asset");let c=b(t);c.theme&&(c.theme=_(il.theme,c.theme)),c.ui&&(c.ui={...il.ui,...c.ui}),c.api&&(c.api={...il.api,...c.api}),c.units&&(c.units={...il.units,...c.units});const d=!(null==(i=c.hideElements)?void 0:i.includes("element:asset"));for(let p in c)this.settings[p]=c[p];if(null==(n=null==(r=null==(s=this.settings.theme)?void 0:s.elements)?void 0:r["layout:space"])?void 0:n.program){const t=this.settings.theme.elements["layout:space"].program,e={wash:"care",operate:"support",common:"socialize"};Object.keys(t).forEach((i=>{Object.keys(e).includes(i)&&(t[e[i]]=t[i],delete t[i])}))}this.layout&&(u&&d&&al(this),(null==(o=c.theme)?void 0:o.wallContours)&&!(null==(a=this.computed.wallContours)?void 0:a.length)?this.computed.wallContours=_l(this.layout):!(null==(l=c.theme)?void 0:l.wallContours)&&(null==(h=this.computed.wallContours)?void 0:h.length)&&(this.computed.wallContours=[])),this.emit("update-settings",this.settings)}getBoundingBox(t=0){const{min:[e,,i],max:[s,,r]}=this.layout.getBoundingBox();return{min:[e-t,i-t],max:[s+t,r+t]}}getResourcesFromPosition(t){const e=this.layout.spaces.filter((e=>wi(t,e.geometry.polygons))),i=[];return e.forEach((e=>{const s=e.getElements("element:asset").filter((e=>{if(e.product.attributes.subCategories.includes("ceilingLight")&&!this.settings.showCeilingLamps)return;const i=e.getBoundingBoxContour();return(null==i?void 0:i.length)?K(t,i):void 0}));i.push(...s)})),{spaces:e,assets:i}}destroy(){delete this.layout,delete this.settings,delete this.utils}};wl.version="5.1.12";let Pl=wl;function El(t){let{length:e,hingeSide:i,doorSide:s,doorAngle:r,doorType:n,frameThickness:o,frameDepth:a}=t.parameters,l=[],h="right"===i,u="side1"===s,c=u?0:a,d=!1,p=0,f=0;if(r<5&&r>-5){r=20;const t=r/180*Math.PI;p=Math.sin(t),f=Math.cos(t),d=!0}if("singleSwing"===n){let t,i,s,n,a=e-2*o;u?h?(t=0,i=r,s=[o,c],n=[s[0]+f*a,s[1]-p*a]):(t=180-r,i=180,s=[e-o,c],n=[s[0]-f*a,s[1]-p*a]):h?(t=-180,i=-180+r,s=[e-o,c],n=[s[0]-f*a,s[1]+p*a]):(t=360-r,i=360,s=[o,c],n=[s[0]+f*a,s[1]+p*a]),l.push({type:"curve:arc",radius:a,position:s,startAngle:t,endAngle:i}),d&&l.push({type:"curve:line",start:s,end:n})}else if("doubleSwing"===n){let t,i,s,n,a,h,m,g,y=e/2-o;u?(t=0,i=r,s=[o,c],m=[e-o,c],a=180-r,h=180,n=[s[0]+f*y,s[1]-p*y],g=[m[0]-f*y,m[1]-p*y]):(t=360-r,i=360,s=[o,c],m=[e-o,c],a=180,h=180+r,n=[s[0]+f*y,s[1]+p*y],g=[m[0]-f*y,m[1]+p*y]),l.push({type:"curve:arc",radius:y,position:s,startAngle:t,endAngle:i}),l.push({type:"curve:arc",radius:y,position:m,startAngle:a,endAngle:h}),d&&(l.push({type:"curve:line",start:s,end:n}),l.push({type:"curve:line",start:m,end:g}))}return l}function Tl(t){let e=[];switch(t.type){case"element:door":e=El(t);break;case"element:stairFlight":e=function(t){var e;let i=null==(e=t.parent)?void 0:e.elements.find((t=>"element:stairFlight"===t.type));if((null==i?void 0:i.id)!==t.id||"spiral"===t.parameters.stairFlightType)return[];let{width:s,length:r,height:n}=t.parameters,o=r/Math.round(n/.17);return[{type:"curve:polyline",points:[[o/2-.06,s/2+.12],[o/2+.06,s/2],[o/2-.06,s/2-.12]]}]}(t)}return e}function Al(t){for(const e of Object.keys(tl.programs)){if(tl.programs[e].find((e=>e.name===t)))return e}return""}function Il(t,e=0){return({"element:door":40,"element:window":40,"element:opening":40,"element:spaceDivider":35,"spatialGraph:edge":35,"element:column":30,"element:wall":30,"element:boundaryWall":30,"element:casework":20,"element:kitchen":20,"element:railing":20,"element:generic":11,"element:asset":10,"element:stairs":5,"element:stairFlight":5,"element:slab":5,"layout:space":1,"annotation:floorPlanDxf":0,"annotation:floorPlanImage":0}[t]||0)+e}const Sl={default:{fill:el.white,stroke:el.warsaw,strokeWidth:"native",fillOpacity:1},selected:{fill:el.zurich_48,stroke:el.warsaw,strokeWidth:1}},Cl=t=>{const e=t.toString(16);return 1===e.length?"0"+e:e},Ml=(t,e,i)=>"#"+[t,e,i].map(Cl).join(""),Ol=t=>Number(parseInt(t.slice(1),16));function Nl(t){return"number"==typeof t?t:"string"==typeof t&&t.startsWith("#")?Ol(t):Array.isArray(t)?Ol(Ml(...t)):void 0}const Ll=({settings:t,element:e,elementType:i})=>{var s,r,n,o,a,l;const h=null==(s=null==t?void 0:t.theme)?void 0:s.elements;if(!h)return{};let u=(null==(r=h.byId)?void 0:r[null==e?void 0:e.id])||h[i]||h[null==e?void 0:e.type]||null;if(e){const t=h["layout:space"];if("layout:space"===e.type){const i=Al(e.attributes.usage);(null==(n=null==t?void 0:t.usage)?void 0:n[e.attributes.usage])?u=t.usage[e.attributes.usage]:(null==(o=null==t?void 0:t.program)?void 0:o[i])&&(u=t.program[i])}else"element:stairs"!==e.type||u||((null==(a=null==t?void 0:t.usage)?void 0:a.staircase)?u=t.usage.staircase:(null==(l=null==t?void 0:t.program)?void 0:l.circulate)&&(u=t.program.circulate))}return(t=>{const{fill:e,fillOpacity:i,stroke:s,strokeWidth:r}=t,n={};return e&&(n.fill=Nl(e)),s&&(n.stroke=Nl(s)),i&&Number.isFinite(i)&&(n.fillOpacity=Math.max(Math.min(i,1),0)),"string"==typeof r?"native"===r&&(n.strokeWidth=r):Number.isFinite(r)&&r>=0&&(n.strokeWidth=r),n})(u||{})},Rl=t=>{var e,i,s;if(null==(e=null==t?void 0:t.layout)?void 0:e.debugIds){let e=(null==(i=/\d+/.exec(t.id))?void 0:i[0])||"0",r=(s=parseInt(e),function(){let t=s+=1831565813;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296});return{fill:Math.round(5*r()*16777215)%16777215,fillOpacity:.5}}return{}},kl=({style:t,settings:e,element:i,elementType:s})=>{const r="selected"===t?"selected":"default",n=function({element:t,settings:e,elementType:i,state:s="default"}){var r;const n=null==(r=null==e?void 0:e.theme)?void 0:r.showAssetTextures,o={"element:wall":{default:{fill:el.stone,stroke:el.stone},selected:{fill:el.oslo,stroke:el.blue_ribbon,strokeWidth:"native"}},"element:boundaryWall":{default:{fill:el.stone,stroke:el.new_york},selected:{fill:el.oslo,stroke:el.blue_ribbon}},"element:curtainWall":{default:{fill:el.stone_08},selected:{strokeWidth:"native"}},"element:column":{default:{fill:el.stone,stroke:el.stone},selected:{fill:el.oslo,stroke:el.blue_ribbon,strokeWidth:"native"}},"element:asset":{default:{fill:n?null:el.stone_08},selected:{fill:el.zurich_48,stroke:el.blue_ribbon,strokeWidth:.5,alignment:0}},"element:stairs":{default:{fill:el.whisper},selected:{strokeWidth:"native"}},"element:stairFlight":{default:{fill:el.whisper}},"element:slab":{default:{fill:el.whisper}},"layout:space":(()=>{const e={default:{fill:el.white,stroke:el.gray},selected:{fill:el.zurich_48,stroke:el.gray,strokeWidth:"native"}};if(t&&"layout:space"===t.type){const i="kitchen"!==t.attributes.usage&&Al(t.attributes.usage),s={care:el.gray,circulate:el.whisper};i&&s[i]&&(e.default.fill=s[i]),"void"===i&&(e.default.fillOpacity=.05)}return e})(),"spatialGraph:edge":{default:{fill:el.gray,stroke:el.new_york,strokeOpacity:.8,strokeWidth:.5},selected:{stroke:el.blue_ribbon,strokeWidth:.5}},"element:spaceDivider":{default:{fill:el.gray,stroke:el.new_york,strokeOpacity:.8,strokeWidth:.5},selected:{stroke:el.blue_ribbon,strokeWidth:.5}}}[i]||Sl,a=Ll({settings:e,element:t,elementType:i});return"selected"===s?{...Sl.default,...o.default,...a,...Sl.selected,...o.selected}:{...Sl.default,...o.default,...a}}({element:i,elementType:s||(null==i?void 0:i.type),settings:e,state:r});return{...n,...t?{}:Rl(i),..."object"==typeof t?t:{}}};function Bl(t,e,i=.5){let s=[e[0]-t[0],e[1]-t[1]];return[t[0]+s[0]*i,t[1]+s[1]*i]}function Fl(t,e,i,s=5){const r=[];let n,o,a,l=0;for(let h=0;h<=s;++h)l=h/s,n=Bl(t,e,l),o=Bl(e,i,l),a=Bl(n,o,l),r.push(a);return r}const Dl=(t,e)=>{const i=Math.ceil(48/(2*Math.PI)*t*e),s=Math.ceil(12/(2*Math.PI)*t);return Math.min(100,Math.max(s,i))},Ul=t=>{const e={type:"curve:polygon",points:[]};switch(t.type){case"curve:circle":const i=t.radius,s=Dl(2*Math.PI,i),r=t.position,n=2*Math.PI/s;let o=0;for(let t=0;t<s;t++)e.points.push([i*Math.cos(o)+r[0],-i*Math.sin(o)+r[1]]),o+=n;break;case"curve:polygon":e.points=t.points;break;case"curve:rectangle":const a=t.dimensions,[l,h]=t.position||[0,0];e.points=[[l,h],[l,h+a[1]],[l+a[0],h+a[1]],[l+a[0],h]];break;case"curve:composite":for(const u of t.segments){let t=Gl(u);e.points.push(...t.points)}}return e},Gl=t=>{const e={type:"curve:polyline",points:[]};switch(t.type){case"curve:line":e.points=[t.start,t.end];break;case"curve:arc":const i=t.startAngle/180*Math.PI,s=t.endAngle/180*Math.PI-i,r=t.radius,n=Dl(Math.abs(s),r),o=t.position,a=s/n;let l=i;for(let t=0;t<n+1;t++)e.points.push([r*Math.cos(l)+o[0],-r*Math.sin(l)+o[1]]),l+=a;break;case"curve:polyline":e.points=t.points;break;case"curve:quadraticBezier":e.points.push(t.points[0]);for(let h=0;h<=t.points.length-3;h++){let i=t.points[h],s=t.points[h+1],r=t.points[h+2],n=Fl(0===h?i:Bl(i,s),s,h===t.points.length-3?r:Bl(s,r));e.points.push(...n.slice(1))}}return e},Xl=(t,e,i=.15)=>{let s,r,n;for(const o of e)if(s=Math.abs(t[0]-o[0]),!(s>i)&&(r=Math.abs(t[1]-o[1]),s<i&&r<i)){n=o;break}return n};function Wl(t){const e={10:["ceilingLight","wallLight"],9:["modularMeetingRoom","phoneBooth"],8:["floorLamp","tableLamp","deskDivider","cushion","plant","officeSupply","tableware","decoration","laundry","electronics","kitchen","car"],7:["shelf","cabinet","wardrobe","storageCombination","outdoor","bicycle","people","sink"],6:["highTable","diningTable","conferenceTable","desk"],5:["sofa","armchair","loungeChair","ottoman","sideboard","pedestal"],4:["taskChair","diningChair","conferenceChair","stool","barStool","bench"],3:["shower"],2:["singleBed","doubleBed","daybed","toilet","bathtub"],1:["sideTable","coffeeTable","radiator","nightstand"],0:["rug"]};let i=0;return t.subCategories.forEach((t=>{Object.keys(e).forEach((s=>{let r=parseInt(s);e[s].includes(t)&&r>i&&(i=r)}))})),1===i&&t.categories.includes("tables")&&t.boundingBox.max[1]-t.boundingBox.min[1]>.6&&(i=6),i}var Hl=(t=>(t[t.WEBGL_LEGACY=0]="WEBGL_LEGACY",t[t.WEBGL=1]="WEBGL",t[t.WEBGL2=2]="WEBGL2",t))(Hl||{}),Yl=(t=>(t[t.UNKNOWN=0]="UNKNOWN",t[t.WEBGL=1]="WEBGL",t[t.CANVAS=2]="CANVAS",t))(Yl||{}),$l=(t=>(t[t.COLOR=16384]="COLOR",t[t.DEPTH=256]="DEPTH",t[t.STENCIL=1024]="STENCIL",t))($l||{}),jl=(t=>(t[t.NORMAL=0]="NORMAL",t[t.ADD=1]="ADD",t[t.MULTIPLY=2]="MULTIPLY",t[t.SCREEN=3]="SCREEN",t[t.OVERLAY=4]="OVERLAY",t[t.DARKEN=5]="DARKEN",t[t.LIGHTEN=6]="LIGHTEN",t[t.COLOR_DODGE=7]="COLOR_DODGE",t[t.COLOR_BURN=8]="COLOR_BURN",t[t.HARD_LIGHT=9]="HARD_LIGHT",t[t.SOFT_LIGHT=10]="SOFT_LIGHT",t[t.DIFFERENCE=11]="DIFFERENCE",t[t.EXCLUSION=12]="EXCLUSION",t[t.HUE=13]="HUE",t[t.SATURATION=14]="SATURATION",t[t.COLOR=15]="COLOR",t[t.LUMINOSITY=16]="LUMINOSITY",t[t.NORMAL_NPM=17]="NORMAL_NPM",t[t.ADD_NPM=18]="ADD_NPM",t[t.SCREEN_NPM=19]="SCREEN_NPM",t[t.NONE=20]="NONE",t[t.SRC_OVER=0]="SRC_OVER",t[t.SRC_IN=21]="SRC_IN",t[t.SRC_OUT=22]="SRC_OUT",t[t.SRC_ATOP=23]="SRC_ATOP",t[t.DST_OVER=24]="DST_OVER",t[t.DST_IN=25]="DST_IN",t[t.DST_OUT=26]="DST_OUT",t[t.DST_ATOP=27]="DST_ATOP",t[t.ERASE=26]="ERASE",t[t.SUBTRACT=28]="SUBTRACT",t[t.XOR=29]="XOR",t))(jl||{}),zl=(t=>(t[t.POINTS=0]="POINTS",t[t.LINES=1]="LINES",t[t.LINE_LOOP=2]="LINE_LOOP",t[t.LINE_STRIP=3]="LINE_STRIP",t[t.TRIANGLES=4]="TRIANGLES",t[t.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",t[t.TRIANGLE_FAN=6]="TRIANGLE_FAN",t))(zl||{}),Vl=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(Vl||{}),ql=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(ql||{}),Jl=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(Jl||{}),Kl=(t=>(t[t.FLOAT=0]="FLOAT",t[t.INT=1]="INT",t[t.UINT=2]="UINT",t))(Kl||{}),Zl=(t=>(t[t.NEAREST=0]="NEAREST",t[t.LINEAR=1]="LINEAR",t))(Zl||{}),Ql=(t=>(t[t.CLAMP=33071]="CLAMP",t[t.REPEAT=10497]="REPEAT",t[t.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",t))(Ql||{}),th=(t=>(t[t.OFF=0]="OFF",t[t.POW2=1]="POW2",t[t.ON=2]="ON",t[t.ON_MANUAL=3]="ON_MANUAL",t))(th||{}),eh=(t=>(t[t.NPM=0]="NPM",t[t.UNPACK=1]="UNPACK",t[t.PMA=2]="PMA",t[t.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",t[t.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",t[t.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",t))(eh||{}),ih=(t=>(t[t.NO=0]="NO",t[t.YES=1]="YES",t[t.AUTO=2]="AUTO",t[t.BLEND=0]="BLEND",t[t.CLEAR=1]="CLEAR",t[t.BLIT=2]="BLIT",t))(ih||{}),sh=(t=>(t[t.AUTO=0]="AUTO",t[t.MANUAL=1]="MANUAL",t))(sh||{}),rh=(t=>(t.LOW="lowp",t.MEDIUM="mediump",t.HIGH="highp",t))(rh||{}),nh=(t=>(t[t.NONE=0]="NONE",t[t.SCISSOR=1]="SCISSOR",t[t.STENCIL=2]="STENCIL",t[t.SPRITE=3]="SPRITE",t[t.COLOR=4]="COLOR",t))(nh||{}),oh=(t=>(t[t.NONE=0]="NONE",t[t.LOW=2]="LOW",t[t.MEDIUM=4]="MEDIUM",t[t.HIGH=8]="HIGH",t))(oh||{}),ah=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(ah||{});const lh={ADAPTER:{createCanvas:(t,e)=>{const i=document.createElement("canvas");return i.width=t,i.height=e,i},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(t,e)=>fetch(t,e),parseXML:t=>(new DOMParser).parseFromString(t,"text/xml")},RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var hh=/iPhone/i,uh=/iPod/i,ch=/iPad/i,dh=/\biOS-universal(?:.+)Mac\b/i,ph=/\bAndroid(?:.+)Mobile\b/i,fh=/Android/i,mh=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,gh=/Silk/i,yh=/Windows Phone/i,vh=/\bWindows(?:.+)ARM\b/i,xh=/BlackBerry/i,bh=/BB10/i,_h=/Opera Mini/i,wh=/\b(CriOS|Chrome)(?:.+)Mobile/i,Ph=/Mobile(?:.+)Firefox\b/i,Eh=function(t){return void 0!==t&&"MacIntel"===t.platform&&"number"==typeof t.maxTouchPoints&&t.maxTouchPoints>1&&"undefined"==typeof MSStream};function Th(t){var e={userAgent:"",platform:"",maxTouchPoints:0};t||"undefined"==typeof navigator?"string"==typeof t?e.userAgent=t:t&&t.userAgent&&(e={userAgent:t.userAgent,platform:t.platform,maxTouchPoints:t.maxTouchPoints||0}):e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0};var i=e.userAgent,s=i.split("[FBAN");void 0!==s[1]&&(i=s[0]),void 0!==(s=i.split("Twitter"))[1]&&(i=s[0]);var r=function(t){return function(e){return e.test(t)}}(i),n={apple:{phone:r(hh)&&!r(yh),ipod:r(uh),tablet:!r(hh)&&(r(ch)||Eh(e))&&!r(yh),universal:r(dh),device:(r(hh)||r(uh)||r(ch)||r(dh)||Eh(e))&&!r(yh)},amazon:{phone:r(mh),tablet:!r(mh)&&r(gh),device:r(mh)||r(gh)},android:{phone:!r(yh)&&r(mh)||!r(yh)&&r(ph),tablet:!r(yh)&&!r(mh)&&!r(ph)&&(r(gh)||r(fh)),device:!r(yh)&&(r(mh)||r(gh)||r(ph)||r(fh))||r(/\bokhttp\b/i)},windows:{phone:r(yh),tablet:r(vh),device:r(yh)||r(vh)},other:{blackberry:r(xh),blackberry10:r(bh),opera:r(_h),firefox:r(Ph),chrome:r(wh),device:r(xh)||r(bh)||r(_h)||r(Ph)||r(wh)},any:!1,phone:!1,tablet:!1};return n.any=n.apple.device||n.android.device||n.windows.device||n.other.device,n.phone=n.apple.phone||n.android.phone||n.windows.phone,n.tablet=n.apple.tablet||n.android.tablet||n.windows.tablet,n}const Ah=(Th.default??Th)(globalThis.navigator);lh.RETINA_PREFIX=/@([0-9\.]+)x/,lh.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ih={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function r(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,s,n,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new r(s,n||t,o),l=i?i+e:e;return t._events[l]?t._events[l].fn?t._events[l]=[t._events[l],a]:t._events[l].push(a):(t._events[l]=a,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),a.prototype.eventNames=function(){var t,s,r=[];if(0===this._eventsCount)return r;for(s in t=this._events)e.call(t,s)&&r.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,n=s.length,o=new Array(n);r<n;r++)o[r]=s[r].fn;return o},a.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},a.prototype.emit=function(t,e,s,r,n,o){var a=i?i+t:t;if(!this._events[a])return!1;var l,h,u=this._events[a],c=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),c){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,e),!0;case 3:return u.fn.call(u.context,e,s),!0;case 4:return u.fn.call(u.context,e,s,r),!0;case 5:return u.fn.call(u.context,e,s,r,n),!0;case 6:return u.fn.call(u.context,e,s,r,n,o),!0}for(h=1,l=new Array(c-1);h<c;h++)l[h-1]=arguments[h];u.fn.apply(u.context,l)}else{var d,p=u.length;for(h=0;h<p;h++)switch(u[h].once&&this.removeListener(t,u[h].fn,void 0,!0),c){case 1:u[h].fn.call(u[h].context);break;case 2:u[h].fn.call(u[h].context,e);break;case 3:u[h].fn.call(u[h].context,e,s);break;case 4:u[h].fn.call(u[h].context,e,s,r);break;default:if(!l)for(d=1,l=new Array(c-1);d<c;d++)l[d-1]=arguments[d];u[h].fn.apply(u[h].context,l)}}return!0},a.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},a.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},a.prototype.removeListener=function(t,e,s,r){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return o(this,n),this;var a=this._events[n];if(a.fn)a.fn!==e||r&&!a.once||s&&a.context!==s||o(this,n);else{for(var l=0,h=[],u=a.length;l<u;l++)(a[l].fn!==e||r&&!a[l].once||s&&a[l].context!==s)&&h.push(a[l]);h.length?this._events[n]=1===h.length?h[0]:h:o(this,n)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&o(this,e)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=i,a.EventEmitter=a,t.exports=a}(Ih);const Sh=Mt(Ih.exports);var Ch={exports:{}};
|
|
9
|
+
/*! https://mths.be/punycode v1.4.1 by @mathias */!function(t,e){!function(i){var s=e&&!e.nodeType&&e,r=t&&!t.nodeType&&t,n="object"==typeof Ct&&Ct;n.global!==n&&n.window!==n&&n.self!==n||(i=n);var o,a,l=2147483647,h=36,u=1,c=26,d=38,p=700,f=72,m=128,g="-",y=/^xn--/,v=/[^\x20-\x7E]/,x=/[\x2E\u3002\uFF0E\uFF61]/g,b={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},_=h-u,w=Math.floor,P=String.fromCharCode;function E(t){throw new RangeError(b[t])}function T(t,e){for(var i=t.length,s=[];i--;)s[i]=e(t[i]);return s}function A(t,e){var i=t.split("@"),s="";return i.length>1&&(s=i[0]+"@",t=i[1]),s+T((t=t.replace(x,".")).split("."),e).join(".")}function I(t){for(var e,i,s=[],r=0,n=t.length;r<n;)(e=t.charCodeAt(r++))>=55296&&e<=56319&&r<n?56320==(64512&(i=t.charCodeAt(r++)))?s.push(((1023&e)<<10)+(1023&i)+65536):(s.push(e),r--):s.push(e);return s}function S(t){return T(t,(function(t){var e="";return t>65535&&(e+=P((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=P(t)})).join("")}function C(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function M(t,e,i){var s=0;for(t=i?w(t/p):t>>1,t+=w(t/e);t>_*c>>1;s+=h)t=w(t/_);return w(s+(_+1)*t/(t+d))}function O(t){var e,i,s,r,n,o,a,d,p,y,v,x=[],b=t.length,_=0,P=m,T=f;for((i=t.lastIndexOf(g))<0&&(i=0),s=0;s<i;++s)t.charCodeAt(s)>=128&&E("not-basic"),x.push(t.charCodeAt(s));for(r=i>0?i+1:0;r<b;){for(n=_,o=1,a=h;r>=b&&E("invalid-input"),((d=(v=t.charCodeAt(r++))-48<10?v-22:v-65<26?v-65:v-97<26?v-97:h)>=h||d>w((l-_)/o))&&E("overflow"),_+=d*o,!(d<(p=a<=T?u:a>=T+c?c:a-T));a+=h)o>w(l/(y=h-p))&&E("overflow"),o*=y;T=M(_-n,e=x.length+1,0==n),w(_/e)>l-P&&E("overflow"),P+=w(_/e),_%=e,x.splice(_++,0,P)}return S(x)}function N(t){var e,i,s,r,n,o,a,d,p,y,v,x,b,_,T,A=[];for(x=(t=I(t)).length,e=m,i=0,n=f,o=0;o<x;++o)(v=t[o])<128&&A.push(P(v));for(s=r=A.length,r&&A.push(g);s<x;){for(a=l,o=0;o<x;++o)(v=t[o])>=e&&v<a&&(a=v);for(a-e>w((l-i)/(b=s+1))&&E("overflow"),i+=(a-e)*b,e=a,o=0;o<x;++o)if((v=t[o])<e&&++i>l&&E("overflow"),v==e){for(d=i,p=h;!(d<(y=p<=n?u:p>=n+c?c:p-n));p+=h)T=d-y,_=h-y,A.push(P(C(y+T%_,0))),d=w(T/_);A.push(P(C(d,0))),n=M(i,b,s==r),i=0,++s}++i,++e}return A.join("")}if(o={version:"1.4.1",ucs2:{decode:I,encode:S},decode:O,encode:N,toASCII:function(t){return A(t,(function(t){return v.test(t)?"xn--"+N(t):t}))},toUnicode:function(t){return A(t,(function(t){return y.test(t)?O(t.slice(4).toLowerCase()):t}))}},s&&r)if(t.exports==s)r.exports=o;else for(a in o)o.hasOwnProperty(a)&&(s[a]=o[a]);else i.punycode=o}(Ct)}(Ch,Ch.exports);var Mh=Ch.exports,Oh=TypeError;const Nh=Ot(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Lh="function"==typeof Map&&Map.prototype,Rh=Object.getOwnPropertyDescriptor&&Lh?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,kh=Lh&&Rh&&"function"==typeof Rh.get?Rh.get:null,Bh=Lh&&Map.prototype.forEach,Fh="function"==typeof Set&&Set.prototype,Dh=Object.getOwnPropertyDescriptor&&Fh?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Uh=Fh&&Dh&&"function"==typeof Dh.get?Dh.get:null,Gh=Fh&&Set.prototype.forEach,Xh="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Wh="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,Hh="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Yh=Boolean.prototype.valueOf,$h=Object.prototype.toString,jh=Function.prototype.toString,zh=String.prototype.match,Vh=String.prototype.slice,qh=String.prototype.replace,Jh=String.prototype.toUpperCase,Kh=String.prototype.toLowerCase,Zh=RegExp.prototype.test,Qh=Array.prototype.concat,tu=Array.prototype.join,eu=Array.prototype.slice,iu=Math.floor,su="function"==typeof BigInt?BigInt.prototype.valueOf:null,ru=Object.getOwnPropertySymbols,nu="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,ou="function"==typeof Symbol&&"object"==typeof Symbol.iterator,au="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===ou||"symbol")?Symbol.toStringTag:null,lu=Object.prototype.propertyIsEnumerable,hu=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(t){return t.__proto__}:null);function uu(t,e){if(t===1/0||t===-1/0||t!=t||t&&t>-1e3&&t<1e3||Zh.call(/e/,e))return e;var i=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof t){var s=t<0?-iu(-t):iu(t);if(s!==t){var r=String(s),n=Vh.call(e,r.length+1);return qh.call(r,i,"$&_")+"."+qh.call(qh.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return qh.call(e,i,"$&_")}var cu=Nh,du=cu.custom,pu=wu(du)?du:null,fu={__proto__:null,double:'"',single:"'"},mu={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},gu=function t(e,i,s,r){var n=i||{};if(Eu(n,"quoteStyle")&&!Eu(fu,n.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Eu(n,"maxStringLength")&&("number"==typeof n.maxStringLength?n.maxStringLength<0&&n.maxStringLength!==1/0:null!==n.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=!Eu(n,"customInspect")||n.customInspect;if("boolean"!=typeof o&&"symbol"!==o)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Eu(n,"indent")&&null!==n.indent&&"\t"!==n.indent&&!(parseInt(n.indent,10)===n.indent&&n.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Eu(n,"numericSeparator")&&"boolean"!=typeof n.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=n.numericSeparator;if(void 0===e)return"undefined";if(null===e)return"null";if("boolean"==typeof e)return e?"true":"false";if("string"==typeof e)return Iu(e,n);if("number"==typeof e){if(0===e)return 1/0/e>0?"0":"-0";var l=String(e);return a?uu(e,l):l}if("bigint"==typeof e){var h=String(e)+"n";return a?uu(e,h):h}var u=void 0===n.depth?5:n.depth;if(void 0===s&&(s=0),s>=u&&u>0&&"object"==typeof e)return bu(e)?"[Array]":"[Object]";var c=function(t,e){var i;if("\t"===t.indent)i="\t";else{if(!("number"==typeof t.indent&&t.indent>0))return null;i=tu.call(Array(t.indent+1)," ")}return{base:i,prev:tu.call(Array(e+1),i)}}(n,s);if(void 0===r)r=[];else if(Au(r,e)>=0)return"[Circular]";function d(e,i,o){if(i&&(r=eu.call(r)).push(i),o){var a={depth:n.depth};return Eu(n,"quoteStyle")&&(a.quoteStyle=n.quoteStyle),t(e,a,s+1,r)}return t(e,n,s+1,r)}if("function"==typeof e&&!_u(e)){var p=function(t){if(t.name)return t.name;var e=zh.call(jh.call(t),/^function\s*([\w$]+)/);if(e)return e[1];return null}(e),f=Lu(e,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+tu.call(f,", ")+" }":"")}if(wu(e)){var m=ou?qh.call(String(e),/^(Symbol\(.*\))_[^)]*$/,"$1"):nu.call(e);return"object"!=typeof e||ou?m:Cu(m)}if(function(t){if(!t||"object"!=typeof t)return!1;if("undefined"!=typeof HTMLElement&&t instanceof HTMLElement)return!0;return"string"==typeof t.nodeName&&"function"==typeof t.getAttribute}(e)){for(var g="<"+Kh.call(String(e.nodeName)),y=e.attributes||[],v=0;v<y.length;v++)g+=" "+y[v].name+"="+yu(vu(y[v].value),"double",n);return g+=">",e.childNodes&&e.childNodes.length&&(g+="..."),g+="</"+Kh.call(String(e.nodeName))+">"}if(bu(e)){if(0===e.length)return"[]";var x=Lu(e,d);return c&&!function(t){for(var e=0;e<t.length;e++)if(Au(t[e],"\n")>=0)return!1;return!0}(x)?"["+Nu(x,c)+"]":"[ "+tu.call(x,", ")+" ]"}if(function(t){return"[object Error]"===Tu(t)&&xu(t)}(e)){var b=Lu(e,d);return"cause"in Error.prototype||!("cause"in e)||lu.call(e,"cause")?0===b.length?"["+String(e)+"]":"{ ["+String(e)+"] "+tu.call(b,", ")+" }":"{ ["+String(e)+"] "+tu.call(Qh.call("[cause]: "+d(e.cause),b),", ")+" }"}if("object"==typeof e&&o){if(pu&&"function"==typeof e[pu]&&cu)return cu(e,{depth:u-s});if("symbol"!==o&&"function"==typeof e.inspect)return e.inspect()}if(function(t){if(!kh||!t||"object"!=typeof t)return!1;try{kh.call(t);try{Uh.call(t)}catch(g){return!0}return t instanceof Map}catch(e){}return!1}(e)){var _=[];return Bh&&Bh.call(e,(function(t,i){_.push(d(i,e,!0)+" => "+d(t,e))})),Ou("Map",kh.call(e),_,c)}if(function(t){if(!Uh||!t||"object"!=typeof t)return!1;try{Uh.call(t);try{kh.call(t)}catch(e){return!0}return t instanceof Set}catch(i){}return!1}(e)){var w=[];return Gh&&Gh.call(e,(function(t){w.push(d(t,e))})),Ou("Set",Uh.call(e),w,c)}if(function(t){if(!Xh||!t||"object"!=typeof t)return!1;try{Xh.call(t,Xh);try{Wh.call(t,Wh)}catch(g){return!0}return t instanceof WeakMap}catch(e){}return!1}(e))return Mu("WeakMap");if(function(t){if(!Wh||!t||"object"!=typeof t)return!1;try{Wh.call(t,Wh);try{Xh.call(t,Xh)}catch(g){return!0}return t instanceof WeakSet}catch(e){}return!1}(e))return Mu("WeakSet");if(function(t){if(!Hh||!t||"object"!=typeof t)return!1;try{return Hh.call(t),!0}catch(e){}return!1}(e))return Mu("WeakRef");if(function(t){return"[object Number]"===Tu(t)&&xu(t)}(e))return Cu(d(Number(e)));if(function(t){if(!t||"object"!=typeof t||!su)return!1;try{return su.call(t),!0}catch(e){}return!1}(e))return Cu(d(su.call(e)));if(function(t){return"[object Boolean]"===Tu(t)&&xu(t)}(e))return Cu(Yh.call(e));if(function(t){return"[object String]"===Tu(t)&&xu(t)}(e))return Cu(d(String(e)));if("undefined"!=typeof window&&e===window)return"{ [object Window] }";if("undefined"!=typeof globalThis&&e===globalThis||void 0!==Ct&&e===Ct)return"{ [object globalThis] }";if(!function(t){return"[object Date]"===Tu(t)&&xu(t)}(e)&&!_u(e)){var P=Lu(e,d),E=hu?hu(e)===Object.prototype:e instanceof Object||e.constructor===Object,T=e instanceof Object?"":"null prototype",A=!E&&au&&Object(e)===e&&au in e?Vh.call(Tu(e),8,-1):T?"Object":"",I=(E||"function"!=typeof e.constructor?"":e.constructor.name?e.constructor.name+" ":"")+(A||T?"["+tu.call(Qh.call([],A||[],T||[]),": ")+"] ":"");return 0===P.length?I+"{}":c?I+"{"+Nu(P,c)+"}":I+"{ "+tu.call(P,", ")+" }"}return String(e)};function yu(t,e,i){var s=i.quoteStyle||e,r=fu[s];return r+t+r}function vu(t){return qh.call(String(t),/"/g,""")}function xu(t){return!au||!("object"==typeof t&&(au in t||void 0!==t[au]))}function bu(t){return"[object Array]"===Tu(t)&&xu(t)}function _u(t){return"[object RegExp]"===Tu(t)&&xu(t)}function wu(t){if(ou)return t&&"object"==typeof t&&t instanceof Symbol;if("symbol"==typeof t)return!0;if(!t||"object"!=typeof t||!nu)return!1;try{return nu.call(t),!0}catch(e){}return!1}var Pu=Object.prototype.hasOwnProperty||function(t){return t in this};function Eu(t,e){return Pu.call(t,e)}function Tu(t){return $h.call(t)}function Au(t,e){if(t.indexOf)return t.indexOf(e);for(var i=0,s=t.length;i<s;i++)if(t[i]===e)return i;return-1}function Iu(t,e){if(t.length>e.maxStringLength){var i=t.length-e.maxStringLength,s="... "+i+" more character"+(i>1?"s":"");return Iu(Vh.call(t,0,e.maxStringLength),e)+s}var r=mu[e.quoteStyle||"single"];return r.lastIndex=0,yu(qh.call(qh.call(t,r,"\\$1"),/[\x00-\x1f]/g,Su),"single",e)}function Su(t){var e=t.charCodeAt(0),i={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return i?"\\"+i:"\\x"+(e<16?"0":"")+Jh.call(e.toString(16))}function Cu(t){return"Object("+t+")"}function Mu(t){return t+" { ? }"}function Ou(t,e,i,s){return t+" ("+e+") {"+(s?Nu(i,s):tu.call(i,", "))+"}"}function Nu(t,e){if(0===t.length)return"";var i="\n"+e.prev+e.base;return i+tu.call(t,","+i)+"\n"+e.prev}function Lu(t,e){var i=bu(t),s=[];if(i){s.length=t.length;for(var r=0;r<t.length;r++)s[r]=Eu(t,r)?e(t[r],t):""}var n,o="function"==typeof ru?ru(t):[];if(ou){n={};for(var a=0;a<o.length;a++)n["$"+o[a]]=o[a]}for(var l in t)Eu(t,l)&&(i&&String(Number(l))===l&&l<t.length||ou&&n["$"+l]instanceof Symbol||(Zh.call(/[^\w$]/,l)?s.push(e(l,t)+": "+e(t[l],t)):s.push(l+": "+e(t[l],t))));if("function"==typeof ru)for(var h=0;h<o.length;h++)lu.call(t,o[h])&&s.push("["+e(o[h])+"]: "+e(t[o[h]],t));return s}var Ru=gu,ku=Oh,Bu=function(t,e,i){for(var s,r=t;null!=(s=r.next);r=s)if(s.key===e)return r.next=s.next,i||(s.next=t.next,t.next=s),s},Fu=Object,Du=Error,Uu=EvalError,Gu=RangeError,Xu=ReferenceError,Wu=SyntaxError,Hu=URIError,Yu=Math.abs,$u=Math.floor,ju=Math.max,zu=Math.min,Vu=Math.pow,qu=Math.round,Ju=Number.isNaN||function(t){return t!=t},Ku=Object.getOwnPropertyDescriptor;if(Ku)try{Ku([],"length")}catch(dP){Ku=null}var Zu=Ku,Qu=Object.defineProperty||!1;if(Qu)try{Qu({},"a",{value:1})}catch(dP){Qu=!1}var tc,ec,ic,sc,rc,nc,oc,ac,lc,hc,uc,cc,dc,pc,fc,mc,gc=Qu;function yc(){return nc?rc:(nc=1,rc="undefined"!=typeof Reflect&&Reflect.getPrototypeOf||null)}function vc(){return ac?oc:(ac=1,oc=Fu.getPrototypeOf||null)}function xc(){if(cc)return uc;cc=1;var t=function(){if(hc)return lc;hc=1;var t=Object.prototype.toString,e=Math.max,i=function(t,e){for(var i=[],s=0;s<t.length;s+=1)i[s]=t[s];for(var r=0;r<e.length;r+=1)i[r+t.length]=e[r];return i};return lc=function(s){var r=this;if("function"!=typeof r||"[object Function]"!==t.apply(r))throw new TypeError("Function.prototype.bind called on incompatible "+r);for(var n,o=function(t){for(var e=[],i=1,s=0;i<t.length;i+=1,s+=1)e[s]=t[i];return e}(arguments),a=e(0,r.length-o.length),l=[],h=0;h<a;h++)l[h]="$"+h;if(n=Function("binder","return function ("+function(t,e){for(var i="",s=0;s<t.length;s+=1)i+=t[s],s+1<t.length&&(i+=e);return i}(l,",")+"){ return binder.apply(this,arguments); }")((function(){if(this instanceof n){var t=r.apply(this,i(o,arguments));return Object(t)===t?t:this}return r.apply(s,i(o,arguments))})),r.prototype){var u=function(){};u.prototype=r.prototype,n.prototype=new u,u.prototype=null}return n},lc}();return uc=Function.prototype.bind||t}function bc(){return pc?dc:(pc=1,dc=Function.prototype.call)}function _c(){return mc?fc:(mc=1,fc=Function.prototype.apply)}var wc,Pc,Ec,Tc,Ac,Ic,Sc,Cc="undefined"!=typeof Reflect&&Reflect&&Reflect.apply,Mc=xc(),Oc=_c(),Nc=bc(),Lc=Cc||Mc.call(Nc,Oc),Rc=xc(),kc=Oh,Bc=bc(),Fc=Lc,Dc=function(t){if(t.length<1||"function"!=typeof t[0])throw new kc("a function is required");return Fc(Rc,Bc,t)};var Uc=Fu,Gc=Du,Xc=Uu,Wc=Gu,Hc=Xu,Yc=Wu,$c=Oh,jc=Hu,zc=Yu,Vc=$u,qc=ju,Jc=zu,Kc=Vu,Zc=qu,Qc=function(t){return Ju(t)||0===t?t:t<0?-1:1},td=Function,ed=function(t){try{return td('"use strict"; return ('+t+").constructor;")()}catch(dP){}},id=Zu,sd=gc,rd=function(){throw new $c},nd=id?function(){try{return rd}catch(t){try{return id(arguments,"callee").get}catch(e){return rd}}}():rd,od=function(){if(sc)return ic;sc=1;var t="undefined"!=typeof Symbol&&Symbol,e=ec?tc:(ec=1,tc=function(){if("function"!=typeof Symbol||"function"!=typeof Object.getOwnPropertySymbols)return!1;if("symbol"==typeof Symbol.iterator)return!0;var t={},e=Symbol("test"),i=Object(e);if("string"==typeof e)return!1;if("[object Symbol]"!==Object.prototype.toString.call(e))return!1;if("[object Symbol]"!==Object.prototype.toString.call(i))return!1;for(var s in t[e]=42,t)return!1;if("function"==typeof Object.keys&&0!==Object.keys(t).length)return!1;if("function"==typeof Object.getOwnPropertyNames&&0!==Object.getOwnPropertyNames(t).length)return!1;var r=Object.getOwnPropertySymbols(t);if(1!==r.length||r[0]!==e)return!1;if(!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if("function"==typeof Object.getOwnPropertyDescriptor){var n=Object.getOwnPropertyDescriptor(t,e);if(42!==n.value||!0!==n.enumerable)return!1}return!0});return ic=function(){return"function"==typeof t&&("function"==typeof Symbol&&("symbol"==typeof t("foo")&&("symbol"==typeof Symbol("bar")&&e())))}}()(),ad=function(){if(Tc)return Ec;Tc=1;var t=yc(),e=vc(),i=function(){if(Pc)return wc;Pc=1;var t,e=Dc,i=Zu;try{t=[].__proto__===Array.prototype}catch(dP){if(!dP||"object"!=typeof dP||!("code"in dP)||"ERR_PROTO_ACCESS"!==dP.code)throw dP}var s=!!t&&i&&i(Object.prototype,"__proto__"),r=Object,n=r.getPrototypeOf;return wc=s&&"function"==typeof s.get?e([s.get]):"function"==typeof n&&function(t){return n(null==t?t:r(t))}}();return Ec=t?function(e){return t(e)}:e?function(t){if(!t||"object"!=typeof t&&"function"!=typeof t)throw new TypeError("getProto: not an object");return e(t)}:i?function(t){return i(t)}:null}(),ld=vc(),hd=yc(),ud=_c(),cd=bc(),dd={},pd="undefined"!=typeof Uint8Array&&ad?ad(Uint8Array):Sc,fd={__proto__:null,"%AggregateError%":"undefined"==typeof AggregateError?Sc:AggregateError,"%Array%":Array,"%ArrayBuffer%":"undefined"==typeof ArrayBuffer?Sc:ArrayBuffer,"%ArrayIteratorPrototype%":od&&ad?ad([][Symbol.iterator]()):Sc,"%AsyncFromSyncIteratorPrototype%":Sc,"%AsyncFunction%":dd,"%AsyncGenerator%":dd,"%AsyncGeneratorFunction%":dd,"%AsyncIteratorPrototype%":dd,"%Atomics%":"undefined"==typeof Atomics?Sc:Atomics,"%BigInt%":"undefined"==typeof BigInt?Sc:BigInt,"%BigInt64Array%":"undefined"==typeof BigInt64Array?Sc:BigInt64Array,"%BigUint64Array%":"undefined"==typeof BigUint64Array?Sc:BigUint64Array,"%Boolean%":Boolean,"%DataView%":"undefined"==typeof DataView?Sc:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Gc,"%eval%":eval,"%EvalError%":Xc,"%Float16Array%":"undefined"==typeof Float16Array?Sc:Float16Array,"%Float32Array%":"undefined"==typeof Float32Array?Sc:Float32Array,"%Float64Array%":"undefined"==typeof Float64Array?Sc:Float64Array,"%FinalizationRegistry%":"undefined"==typeof FinalizationRegistry?Sc:FinalizationRegistry,"%Function%":td,"%GeneratorFunction%":dd,"%Int8Array%":"undefined"==typeof Int8Array?Sc:Int8Array,"%Int16Array%":"undefined"==typeof Int16Array?Sc:Int16Array,"%Int32Array%":"undefined"==typeof Int32Array?Sc:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":od&&ad?ad(ad([][Symbol.iterator]())):Sc,"%JSON%":"object"==typeof JSON?JSON:Sc,"%Map%":"undefined"==typeof Map?Sc:Map,"%MapIteratorPrototype%":"undefined"!=typeof Map&&od&&ad?ad((new Map)[Symbol.iterator]()):Sc,"%Math%":Math,"%Number%":Number,"%Object%":Uc,"%Object.getOwnPropertyDescriptor%":id,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":"undefined"==typeof Promise?Sc:Promise,"%Proxy%":"undefined"==typeof Proxy?Sc:Proxy,"%RangeError%":Wc,"%ReferenceError%":Hc,"%Reflect%":"undefined"==typeof Reflect?Sc:Reflect,"%RegExp%":RegExp,"%Set%":"undefined"==typeof Set?Sc:Set,"%SetIteratorPrototype%":"undefined"!=typeof Set&&od&&ad?ad((new Set)[Symbol.iterator]()):Sc,"%SharedArrayBuffer%":"undefined"==typeof SharedArrayBuffer?Sc:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":od&&ad?ad(""[Symbol.iterator]()):Sc,"%Symbol%":od?Symbol:Sc,"%SyntaxError%":Yc,"%ThrowTypeError%":nd,"%TypedArray%":pd,"%TypeError%":$c,"%Uint8Array%":"undefined"==typeof Uint8Array?Sc:Uint8Array,"%Uint8ClampedArray%":"undefined"==typeof Uint8ClampedArray?Sc:Uint8ClampedArray,"%Uint16Array%":"undefined"==typeof Uint16Array?Sc:Uint16Array,"%Uint32Array%":"undefined"==typeof Uint32Array?Sc:Uint32Array,"%URIError%":jc,"%WeakMap%":"undefined"==typeof WeakMap?Sc:WeakMap,"%WeakRef%":"undefined"==typeof WeakRef?Sc:WeakRef,"%WeakSet%":"undefined"==typeof WeakSet?Sc:WeakSet,"%Function.prototype.call%":cd,"%Function.prototype.apply%":ud,"%Object.defineProperty%":sd,"%Object.getPrototypeOf%":ld,"%Math.abs%":zc,"%Math.floor%":Vc,"%Math.max%":qc,"%Math.min%":Jc,"%Math.pow%":Kc,"%Math.round%":Zc,"%Math.sign%":Qc,"%Reflect.getPrototypeOf%":hd};if(ad)try{null.error}catch(dP){var md=ad(ad(dP));fd["%Error.prototype%"]=md}var gd=function t(e){var i;if("%AsyncFunction%"===e)i=ed("async function () {}");else if("%GeneratorFunction%"===e)i=ed("function* () {}");else if("%AsyncGeneratorFunction%"===e)i=ed("async function* () {}");else if("%AsyncGenerator%"===e){var s=t("%AsyncGeneratorFunction%");s&&(i=s.prototype)}else if("%AsyncIteratorPrototype%"===e){var r=t("%AsyncGenerator%");r&&ad&&(i=ad(r.prototype))}return fd[e]=i,i},yd={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},vd=xc(),xd=function(){if(Ic)return Ac;Ic=1;var t=Function.prototype.call,e=Object.prototype.hasOwnProperty,i=xc();return Ac=i.call(t,e)}(),bd=vd.call(cd,Array.prototype.concat),_d=vd.call(ud,Array.prototype.splice),wd=vd.call(cd,String.prototype.replace),Pd=vd.call(cd,String.prototype.slice),Ed=vd.call(cd,RegExp.prototype.exec),Td=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Ad=/\\(\\)?/g,Id=function(t,e){var i,s=t;if(xd(yd,s)&&(s="%"+(i=yd[s])[0]+"%"),xd(fd,s)){var r=fd[s];if(r===dd&&(r=gd(s)),void 0===r&&!e)throw new $c("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:i,name:s,value:r}}throw new Yc("intrinsic "+t+" does not exist!")},Sd=function(t,e){if("string"!=typeof t||0===t.length)throw new $c("intrinsic name must be a non-empty string");if(arguments.length>1&&"boolean"!=typeof e)throw new $c('"allowMissing" argument must be a boolean');if(null===Ed(/^%?[^%]*%?$/,t))throw new Yc("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=function(t){var e=Pd(t,0,1),i=Pd(t,-1);if("%"===e&&"%"!==i)throw new Yc("invalid intrinsic syntax, expected closing `%`");if("%"===i&&"%"!==e)throw new Yc("invalid intrinsic syntax, expected opening `%`");var s=[];return wd(t,Td,(function(t,e,i,r){s[s.length]=i?wd(r,Ad,"$1"):e||t})),s}(t),s=i.length>0?i[0]:"",r=Id("%"+s+"%",e),n=r.name,o=r.value,a=!1,l=r.alias;l&&(s=l[0],_d(i,bd([0,1],l)));for(var h=1,u=!0;h<i.length;h+=1){var c=i[h],d=Pd(c,0,1),p=Pd(c,-1);if(('"'===d||"'"===d||"`"===d||'"'===p||"'"===p||"`"===p)&&d!==p)throw new Yc("property names with quotes must have matching quotes");if("constructor"!==c&&u||(a=!0),xd(fd,n="%"+(s+="."+c)+"%"))o=fd[n];else if(null!=o){if(!(c in o)){if(!e)throw new $c("base intrinsic for "+t+" exists, but the property is not available.");return}if(id&&h+1>=i.length){var f=id(o,c);o=(u=!!f)&&"get"in f&&!("originalValue"in f.get)?f.get:o[c]}else u=xd(o,c),o=o[c];u&&!a&&(fd[n]=o)}}return o},Cd=Sd,Md=Dc,Od=Md([Cd("%String.prototype.indexOf%")]),Nd=function(t,e){var i=Cd(t,!!e);return"function"==typeof i&&Od(t,".prototype.")>-1?Md([i]):i},Ld=Nd,Rd=gu,kd=Oh,Bd=Sd("%Map%",!0),Fd=Ld("Map.prototype.get",!0),Dd=Ld("Map.prototype.set",!0),Ud=Ld("Map.prototype.has",!0),Gd=Ld("Map.prototype.delete",!0),Xd=Ld("Map.prototype.size",!0),Wd=!!Bd&&function(){var t,e={assert:function(t){if(!e.has(t))throw new kd("Side channel does not contain "+Rd(t))},delete:function(e){if(t){var i=Gd(t,e);return 0===Xd(t)&&(t=void 0),i}return!1},get:function(e){if(t)return Fd(t,e)},has:function(e){return!!t&&Ud(t,e)},set:function(e,i){t||(t=new Bd),Dd(t,e,i)}};return e},Hd=Nd,Yd=gu,$d=Wd,jd=Oh,zd=Sd("%WeakMap%",!0),Vd=Hd("WeakMap.prototype.get",!0),qd=Hd("WeakMap.prototype.set",!0),Jd=Hd("WeakMap.prototype.has",!0),Kd=Hd("WeakMap.prototype.delete",!0),Zd=Oh,Qd=gu,tp=(zd?function(){var t,e,i={assert:function(t){if(!i.has(t))throw new jd("Side channel does not contain "+Yd(t))},delete:function(i){if(zd&&i&&("object"==typeof i||"function"==typeof i)){if(t)return Kd(t,i)}else if($d&&e)return e.delete(i);return!1},get:function(i){return zd&&i&&("object"==typeof i||"function"==typeof i)&&t?Vd(t,i):e&&e.get(i)},has:function(i){return zd&&i&&("object"==typeof i||"function"==typeof i)&&t?Jd(t,i):!!e&&e.has(i)},set:function(i,s){zd&&i&&("object"==typeof i||"function"==typeof i)?(t||(t=new zd),qd(t,i,s)):$d&&(e||(e=$d()),e.set(i,s))}};return i}:$d)||Wd||function(){var t,e={assert:function(t){if(!e.has(t))throw new ku("Side channel does not contain "+Ru(t))},delete:function(e){var i=t&&t.next,s=function(t,e){if(t)return Bu(t,e,!0)}(t,e);return s&&i&&i===s&&(t=void 0),!!s},get:function(e){return function(t,e){if(t){var i=Bu(t,e);return i&&i.value}}(t,e)},has:function(e){return function(t,e){return!!t&&!!Bu(t,e)}(t,e)},set:function(e,i){t||(t={next:void 0}),function(t,e,i){var s=Bu(t,e);s?s.value=i:t.next={key:e,next:t.next,value:i}}(t,e,i)}};return e},ep=String.prototype.replace,ip=/%20/g,sp="RFC3986",rp={default:sp,formatters:{RFC1738:function(t){return ep.call(t,ip,"+")},RFC3986:function(t){return String(t)}},RFC1738:"RFC1738",RFC3986:sp},np=rp,op=Object.prototype.hasOwnProperty,ap=Array.isArray,lp=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),hp=function(t,e){for(var i=e&&e.plainObjects?{__proto__:null}:{},s=0;s<t.length;++s)void 0!==t[s]&&(i[s]=t[s]);return i},up=1024,cp={arrayToObject:hp,assign:function(t,e){return Object.keys(e).reduce((function(t,i){return t[i]=e[i],t}),t)},combine:function(t,e){return[].concat(t,e)},compact:function(t){for(var e=[{obj:{o:t},prop:"o"}],i=[],s=0;s<e.length;++s)for(var r=e[s],n=r.obj[r.prop],o=Object.keys(n),a=0;a<o.length;++a){var l=o[a],h=n[l];"object"==typeof h&&null!==h&&-1===i.indexOf(h)&&(e.push({obj:n,prop:l}),i.push(h))}return function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(ap(i)){for(var s=[],r=0;r<i.length;++r)void 0!==i[r]&&s.push(i[r]);e.obj[e.prop]=s}}}(e),t},decode:function(t,e,i){var s=t.replace(/\+/g," ");if("iso-8859-1"===i)return s.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(s)}catch(dP){return s}},encode:function(t,e,i,s,r){if(0===t.length)return t;var n=t;if("symbol"==typeof t?n=Symbol.prototype.toString.call(t):"string"!=typeof t&&(n=String(t)),"iso-8859-1"===i)return escape(n).replace(/%u[0-9a-f]{4}/gi,(function(t){return"%26%23"+parseInt(t.slice(2),16)+"%3B"}));for(var o="",a=0;a<n.length;a+=up){for(var l=n.length>=up?n.slice(a,a+up):n,h=[],u=0;u<l.length;++u){var c=l.charCodeAt(u);45===c||46===c||95===c||126===c||c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||r===np.RFC1738&&(40===c||41===c)?h[h.length]=l.charAt(u):c<128?h[h.length]=lp[c]:c<2048?h[h.length]=lp[192|c>>6]+lp[128|63&c]:c<55296||c>=57344?h[h.length]=lp[224|c>>12]+lp[128|c>>6&63]+lp[128|63&c]:(u+=1,c=65536+((1023&c)<<10|1023&l.charCodeAt(u)),h[h.length]=lp[240|c>>18]+lp[128|c>>12&63]+lp[128|c>>6&63]+lp[128|63&c])}o+=h.join("")}return o},isBuffer:function(t){return!(!t||"object"!=typeof t)&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(ap(t)){for(var i=[],s=0;s<t.length;s+=1)i.push(e(t[s]));return i}return e(t)},merge:function t(e,i,s){if(!i)return e;if("object"!=typeof i&&"function"!=typeof i){if(ap(e))e.push(i);else{if(!e||"object"!=typeof e)return[e,i];(s&&(s.plainObjects||s.allowPrototypes)||!op.call(Object.prototype,i))&&(e[i]=!0)}return e}if(!e||"object"!=typeof e)return[e].concat(i);var r=e;return ap(e)&&!ap(i)&&(r=hp(e,s)),ap(e)&&ap(i)?(i.forEach((function(i,r){if(op.call(e,r)){var n=e[r];n&&"object"==typeof n&&i&&"object"==typeof i?e[r]=t(n,i,s):e.push(i)}else e[r]=i})),e):Object.keys(i).reduce((function(e,r){var n=i[r];return op.call(e,r)?e[r]=t(e[r],n,s):e[r]=n,e}),r)}},dp=function(){var t,e={assert:function(t){if(!e.has(t))throw new Zd("Side channel does not contain "+Qd(t))},delete:function(e){return!!t&&t.delete(e)},get:function(e){return t&&t.get(e)},has:function(e){return!!t&&t.has(e)},set:function(e,i){t||(t=tp()),t.set(e,i)}};return e},pp=cp,fp=rp,mp=Object.prototype.hasOwnProperty,gp={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},yp=Array.isArray,vp=Array.prototype.push,xp=function(t,e){vp.apply(t,yp(e)?e:[e])},bp=Date.prototype.toISOString,_p=fp.default,wp={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:pp.encode,encodeValuesOnly:!1,filter:void 0,format:_p,formatter:fp.formatters[_p],indices:!1,serializeDate:function(t){return bp.call(t)},skipNulls:!1,strictNullHandling:!1},Pp={},Ep=function t(e,i,s,r,n,o,a,l,h,u,c,d,p,f,m,g,y,v){for(var x,b=e,_=v,w=0,P=!1;void 0!==(_=_.get(Pp))&&!P;){var E=_.get(e);if(w+=1,void 0!==E){if(E===w)throw new RangeError("Cyclic object value");P=!0}void 0===_.get(Pp)&&(w=0)}if("function"==typeof u?b=u(i,b):b instanceof Date?b=p(b):"comma"===s&&yp(b)&&(b=pp.maybeMap(b,(function(t){return t instanceof Date?p(t):t}))),null===b){if(o)return h&&!g?h(i,wp.encoder,y,"key",f):i;b=""}if("string"==typeof(x=b)||"number"==typeof x||"boolean"==typeof x||"symbol"==typeof x||"bigint"==typeof x||pp.isBuffer(b))return h?[m(g?i:h(i,wp.encoder,y,"key",f))+"="+m(h(b,wp.encoder,y,"value",f))]:[m(i)+"="+m(String(b))];var T,A=[];if(void 0===b)return A;if("comma"===s&&yp(b))g&&h&&(b=pp.maybeMap(b,h)),T=[{value:b.length>0?b.join(",")||null:void 0}];else if(yp(u))T=u;else{var I=Object.keys(b);T=c?I.sort(c):I}var S=l?String(i).replace(/\./g,"%2E"):String(i),C=r&&yp(b)&&1===b.length?S+"[]":S;if(n&&yp(b)&&0===b.length)return C+"[]";for(var M=0;M<T.length;++M){var O=T[M],N="object"==typeof O&&O&&void 0!==O.value?O.value:b[O];if(!a||null!==N){var L=d&&l?String(O).replace(/\./g,"%2E"):String(O),R=yp(b)?"function"==typeof s?s(C,L):C:C+(d?"."+L:"["+L+"]");v.set(e,w);var k=dp();k.set(Pp,v),xp(A,t(N,R,s,r,n,o,a,l,"comma"===s&&g&&yp(b)?null:h,u,c,d,p,f,m,g,y,k))}}return A},Tp=cp,Ap=Object.prototype.hasOwnProperty,Ip=Array.isArray,Sp={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:Tp.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},Cp=function(t){return t.replace(/&#(\d+);/g,(function(t,e){return String.fromCharCode(parseInt(e,10))}))},Mp=function(t,e,i){if(t&&"string"==typeof t&&e.comma&&t.indexOf(",")>-1)return t.split(",");if(e.throwOnLimitExceeded&&i>=e.arrayLimit)throw new RangeError("Array limit exceeded. Only "+e.arrayLimit+" element"+(1===e.arrayLimit?"":"s")+" allowed in an array.");return t},Op=function(t,e,i,s){if(t){var r=i.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,n=/(\[[^[\]]*])/g,o=i.depth>0&&/(\[[^[\]]*])/.exec(r),a=o?r.slice(0,o.index):r,l=[];if(a){if(!i.plainObjects&&Ap.call(Object.prototype,a)&&!i.allowPrototypes)return;l.push(a)}for(var h=0;i.depth>0&&null!==(o=n.exec(r))&&h<i.depth;){if(h+=1,!i.plainObjects&&Ap.call(Object.prototype,o[1].slice(1,-1))&&!i.allowPrototypes)return;l.push(o[1])}if(o){if(!0===i.strictDepth)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");l.push("["+r.slice(o.index)+"]")}return function(t,e,i,s){var r=0;if(t.length>0&&"[]"===t[t.length-1]){var n=t.slice(0,-1).join("");r=Array.isArray(e)&&e[n]?e[n].length:0}for(var o=s?e:Mp(e,i,r),a=t.length-1;a>=0;--a){var l,h=t[a];if("[]"===h&&i.parseArrays)l=i.allowEmptyArrays&&(""===o||i.strictNullHandling&&null===o)?[]:Tp.combine([],o);else{l=i.plainObjects?{__proto__:null}:{};var u="["===h.charAt(0)&&"]"===h.charAt(h.length-1)?h.slice(1,-1):h,c=i.decodeDotInKeys?u.replace(/%2E/g,"."):u,d=parseInt(c,10);i.parseArrays||""!==c?!isNaN(d)&&h!==c&&String(d)===c&&d>=0&&i.parseArrays&&d<=i.arrayLimit?(l=[])[d]=o:"__proto__"!==c&&(l[c]=o):l={0:o}}o=l}return o}(l,e,i,s)}},Np={formats:rp,parse:function(t,e){var i=function(t){if(!t)return Sp;if(void 0!==t.allowEmptyArrays&&"boolean"!=typeof t.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==t.decodeDotInKeys&&"boolean"!=typeof t.decodeDotInKeys)throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0!==t.throwOnLimitExceeded&&"boolean"!=typeof t.throwOnLimitExceeded)throw new TypeError("`throwOnLimitExceeded` option must be a boolean");var e=void 0===t.charset?Sp.charset:t.charset,i=void 0===t.duplicates?Sp.duplicates:t.duplicates;if("combine"!==i&&"first"!==i&&"last"!==i)throw new TypeError("The duplicates option must be either combine, first, or last");return{allowDots:void 0===t.allowDots?!0===t.decodeDotInKeys||Sp.allowDots:!!t.allowDots,allowEmptyArrays:"boolean"==typeof t.allowEmptyArrays?!!t.allowEmptyArrays:Sp.allowEmptyArrays,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:Sp.allowPrototypes,allowSparse:"boolean"==typeof t.allowSparse?t.allowSparse:Sp.allowSparse,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:Sp.arrayLimit,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:Sp.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:Sp.comma,decodeDotInKeys:"boolean"==typeof t.decodeDotInKeys?t.decodeDotInKeys:Sp.decodeDotInKeys,decoder:"function"==typeof t.decoder?t.decoder:Sp.decoder,delimiter:"string"==typeof t.delimiter||Tp.isRegExp(t.delimiter)?t.delimiter:Sp.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:Sp.depth,duplicates:i,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:Sp.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:Sp.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:Sp.plainObjects,strictDepth:"boolean"==typeof t.strictDepth?!!t.strictDepth:Sp.strictDepth,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:Sp.strictNullHandling,throwOnLimitExceeded:"boolean"==typeof t.throwOnLimitExceeded&&t.throwOnLimitExceeded}}(e);if(""===t||null==t)return i.plainObjects?{__proto__:null}:{};for(var s="string"==typeof t?function(t,e){var i={__proto__:null},s=e.ignoreQueryPrefix?t.replace(/^\?/,""):t;s=s.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var r=e.parameterLimit===1/0?void 0:e.parameterLimit,n=s.split(e.delimiter,e.throwOnLimitExceeded?r+1:r);if(e.throwOnLimitExceeded&&n.length>r)throw new RangeError("Parameter limit exceeded. Only "+r+" parameter"+(1===r?"":"s")+" allowed.");var o,a=-1,l=e.charset;if(e.charsetSentinel)for(o=0;o<n.length;++o)0===n[o].indexOf("utf8=")&&("utf8=%E2%9C%93"===n[o]?l="utf-8":"utf8=%26%2310003%3B"===n[o]&&(l="iso-8859-1"),a=o,o=n.length);for(o=0;o<n.length;++o)if(o!==a){var h,u,c=n[o],d=c.indexOf("]="),p=-1===d?c.indexOf("="):d+1;-1===p?(h=e.decoder(c,Sp.decoder,l,"key"),u=e.strictNullHandling?null:""):(h=e.decoder(c.slice(0,p),Sp.decoder,l,"key"),u=Tp.maybeMap(Mp(c.slice(p+1),e,Ip(i[h])?i[h].length:0),(function(t){return e.decoder(t,Sp.decoder,l,"value")}))),u&&e.interpretNumericEntities&&"iso-8859-1"===l&&(u=Cp(String(u))),c.indexOf("[]=")>-1&&(u=Ip(u)?[u]:u);var f=Ap.call(i,h);f&&"combine"===e.duplicates?i[h]=Tp.combine(i[h],u):f&&"last"!==e.duplicates||(i[h]=u)}return i}(t,i):t,r=i.plainObjects?{__proto__:null}:{},n=Object.keys(s),o=0;o<n.length;++o){var a=n[o],l=Op(a,s[a],i,"string"==typeof t);r=Tp.merge(r,l,i)}return!0===i.allowSparse?r:Tp.compact(r)},stringify:function(t,e){var i,s=t,r=function(t){if(!t)return wp;if(void 0!==t.allowEmptyArrays&&"boolean"!=typeof t.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==t.encodeDotInKeys&&"boolean"!=typeof t.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==t.encoder&&void 0!==t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||wp.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var i=fp.default;if(void 0!==t.format){if(!mp.call(fp.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var s,r=fp.formatters[i],n=wp.filter;if(("function"==typeof t.filter||yp(t.filter))&&(n=t.filter),s=t.arrayFormat in gp?t.arrayFormat:"indices"in t?t.indices?"indices":"repeat":wp.arrayFormat,"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var o=void 0===t.allowDots?!0===t.encodeDotInKeys||wp.allowDots:!!t.allowDots;return{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:wp.addQueryPrefix,allowDots:o,allowEmptyArrays:"boolean"==typeof t.allowEmptyArrays?!!t.allowEmptyArrays:wp.allowEmptyArrays,arrayFormat:s,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:wp.charsetSentinel,commaRoundTrip:!!t.commaRoundTrip,delimiter:void 0===t.delimiter?wp.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:wp.encode,encodeDotInKeys:"boolean"==typeof t.encodeDotInKeys?t.encodeDotInKeys:wp.encodeDotInKeys,encoder:"function"==typeof t.encoder?t.encoder:wp.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:wp.encodeValuesOnly,filter:n,format:i,formatter:r,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:wp.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:wp.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:wp.strictNullHandling}}(e);"function"==typeof r.filter?s=(0,r.filter)("",s):yp(r.filter)&&(i=r.filter);var n=[];if("object"!=typeof s||null===s)return"";var o=gp[r.arrayFormat],a="comma"===o&&r.commaRoundTrip;i||(i=Object.keys(s)),r.sort&&i.sort(r.sort);for(var l=dp(),h=0;h<i.length;++h){var u=i[h],c=s[u];r.skipNulls&&null===c||xp(n,Ep(c,u,o,a,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset,l))}var d=n.join(r.delimiter),p=!0===r.addQueryPrefix?"?":"";return r.charsetSentinel&&("iso-8859-1"===r.charset?p+="utf8=%26%2310003%3B&":p+="utf8=%E2%9C%93&"),d.length>0?p+d:""}},Lp=Mh;function Rp(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var kp=/^([a-z0-9.+-]+:)/i,Bp=/:[0-9]*$/,Fp=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,Dp=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),Up=["'"].concat(Dp),Gp=["%","/","?",";","#"].concat(Up),Xp=["/","?","#"],Wp=/^[+a-z0-9A-Z_-]{0,63}$/,Hp=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,Yp={javascript:!0,"javascript:":!0},$p={javascript:!0,"javascript:":!0},jp={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},zp=Np;function Vp(t,e,i){if(t&&"object"==typeof t&&t instanceof Rp)return t;var s=new Rp;return s.parse(t,e,i),s}Rp.prototype.parse=function(t,e,i){if("string"!=typeof t)throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var s=t.indexOf("?"),r=-1!==s&&s<t.indexOf("#")?"?":"#",n=t.split(r);n[0]=n[0].replace(/\\/g,"/");var o=t=n.join(r);if(o=o.trim(),!i&&1===t.split("#").length){var a=Fp.exec(o);if(a)return this.path=o,this.href=o,this.pathname=a[1],a[2]?(this.search=a[2],this.query=e?zp.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var l=kp.exec(o);if(l){var h=(l=l[0]).toLowerCase();this.protocol=h,o=o.substr(l.length)}if(i||l||o.match(/^\/\/[^@/]+@[^@/]+/)){var u="//"===o.substr(0,2);!u||l&&$p[l]||(o=o.substr(2),this.slashes=!0)}if(!$p[l]&&(u||l&&!jp[l])){for(var c,d,p=-1,f=0;f<Xp.length;f++){-1!==(m=o.indexOf(Xp[f]))&&(-1===p||m<p)&&(p=m)}-1!==(d=-1===p?o.lastIndexOf("@"):o.lastIndexOf("@",p))&&(c=o.slice(0,d),o=o.slice(d+1),this.auth=decodeURIComponent(c)),p=-1;for(f=0;f<Gp.length;f++){var m;-1!==(m=o.indexOf(Gp[f]))&&(-1===p||m<p)&&(p=m)}-1===p&&(p=o.length),this.host=o.slice(0,p),o=o.slice(p),this.parseHost(),this.hostname=this.hostname||"";var g="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!g)for(var y=this.hostname.split(/\./),v=(f=0,y.length);f<v;f++){var x=y[f];if(x&&!x.match(Wp)){for(var b="",_=0,w=x.length;_<w;_++)x.charCodeAt(_)>127?b+="x":b+=x[_];if(!b.match(Wp)){var P=y.slice(0,f),E=y.slice(f+1),T=x.match(Hp);T&&(P.push(T[1]),E.unshift(T[2])),E.length&&(o="/"+E.join(".")+o),this.hostname=P.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),g||(this.hostname=Lp.toASCII(this.hostname));var A=this.port?":"+this.port:"",I=this.hostname||"";this.host=I+A,this.href+=this.host,g&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==o[0]&&(o="/"+o))}if(!Yp[h])for(f=0,v=Up.length;f<v;f++){var S=Up[f];if(-1!==o.indexOf(S)){var C=encodeURIComponent(S);C===S&&(C=escape(S)),o=o.split(S).join(C)}}var M=o.indexOf("#");-1!==M&&(this.hash=o.substr(M),o=o.slice(0,M));var O=o.indexOf("?");if(-1!==O?(this.search=o.substr(O),this.query=o.substr(O+1),e&&(this.query=zp.parse(this.query)),o=o.slice(0,O)):e&&(this.search="",this.query={}),o&&(this.pathname=o),jp[h]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){A=this.pathname||"";var N=this.search||"";this.path=A+N}return this.href=this.format(),this},Rp.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",i=this.pathname||"",s=this.hash||"",r=!1,n="";this.host?r=t+this.host:this.hostname&&(r=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(r+=":"+this.port)),this.query&&"object"==typeof this.query&&Object.keys(this.query).length&&(n=zp.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var o=this.search||n&&"?"+n||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||jp[e])&&!1!==r?(r="//"+(r||""),i&&"/"!==i.charAt(0)&&(i="/"+i)):r||(r=""),s&&"#"!==s.charAt(0)&&(s="#"+s),o&&"?"!==o.charAt(0)&&(o="?"+o),e+r+(i=i.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(o=o.replace("#","%23"))+s},Rp.prototype.resolve=function(t){return this.resolveObject(Vp(t,!1,!0)).format()},Rp.prototype.resolveObject=function(t){if("string"==typeof t){var e=new Rp;e.parse(t,!1,!0),t=e}for(var i=new Rp,s=Object.keys(this),r=0;r<s.length;r++){var n=s[r];i[n]=this[n]}if(i.hash=t.hash,""===t.href)return i.href=i.format(),i;if(t.slashes&&!t.protocol){for(var o=Object.keys(t),a=0;a<o.length;a++){var l=o[a];"protocol"!==l&&(i[l]=t[l])}return jp[i.protocol]&&i.hostname&&!i.pathname&&(i.pathname="/",i.path=i.pathname),i.href=i.format(),i}if(t.protocol&&t.protocol!==i.protocol){if(!jp[t.protocol]){for(var h=Object.keys(t),u=0;u<h.length;u++){var c=h[u];i[c]=t[c]}return i.href=i.format(),i}if(i.protocol=t.protocol,t.host||$p[t.protocol])i.pathname=t.pathname;else{for(var d=(t.pathname||"").split("/");d.length&&!(t.host=d.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),i.pathname=d.join("/")}if(i.search=t.search,i.query=t.query,i.host=t.host||"",i.auth=t.auth,i.hostname=t.hostname||t.host,i.port=t.port,i.pathname||i.search){var p=i.pathname||"",f=i.search||"";i.path=p+f}return i.slashes=i.slashes||t.slashes,i.href=i.format(),i}var m=i.pathname&&"/"===i.pathname.charAt(0),g=t.host||t.pathname&&"/"===t.pathname.charAt(0),y=g||m||i.host&&t.pathname,v=y,x=i.pathname&&i.pathname.split("/")||[],b=(d=t.pathname&&t.pathname.split("/")||[],i.protocol&&!jp[i.protocol]);if(b&&(i.hostname="",i.port=null,i.host&&(""===x[0]?x[0]=i.host:x.unshift(i.host)),i.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===d[0]?d[0]=t.host:d.unshift(t.host)),t.host=null),y=y&&(""===d[0]||""===x[0])),g)i.host=t.host||""===t.host?t.host:i.host,i.hostname=t.hostname||""===t.hostname?t.hostname:i.hostname,i.search=t.search,i.query=t.query,x=d;else if(d.length)x||(x=[]),x.pop(),x=x.concat(d),i.search=t.search,i.query=t.query;else if(null!=t.search){if(b)i.host=x.shift(),i.hostname=i.host,(T=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=T.shift(),i.hostname=T.shift(),i.host=i.hostname);return i.search=t.search,i.query=t.query,null===i.pathname&&null===i.search||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i}if(!x.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var _=x.slice(-1)[0],w=(i.host||t.host||x.length>1)&&("."===_||".."===_)||""===_,P=0,E=x.length;E>=0;E--)"."===(_=x[E])?x.splice(E,1):".."===_?(x.splice(E,1),P++):P&&(x.splice(E,1),P--);if(!y&&!v)for(;P--;P)x.unshift("..");!y||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),w&&"/"!==x.join("/").substr(-1)&&x.push("");var T,A=""===x[0]||x[0]&&"/"===x[0].charAt(0);b&&(i.hostname=A?"":x.length?x.shift():"",i.host=i.hostname,(T=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=T.shift(),i.hostname=T.shift(),i.host=i.hostname));return(y=y||i.host&&x.length)&&!A&&x.unshift(""),x.length>0?i.pathname=x.join("/"):(i.pathname=null,i.path=null),null===i.pathname&&null===i.search||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.auth=t.auth||i.auth,i.slashes=i.slashes||t.slashes,i.href=i.format(),i},Rp.prototype.parseHost=function(){var t=this.host,e=Bp.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)};var qp=Vp,Jp=function(t,e){return Vp(t,!1,!0).resolve(e)},Kp=function(t){return"string"==typeof t&&(t=Vp(t)),t instanceof Rp?t.format():Rp.prototype.format.call(t)};const Zp={};function Qp(t,e,i=3){if(Zp[e])return;let s=(new Error).stack;typeof s>"u"?console.warn("PixiJS Deprecation Warning: ",`${e}\nDeprecated since v${t}`):(s=s.split("\n").splice(i).join("\n"),console.groupCollapsed?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",`${e}\nDeprecated since v${t}`),console.warn(s),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",`${e}\nDeprecated since v${t}`),console.warn(s))),Zp[e]=!0}const tf={get parse(){return Qp("7.3.0","utils.url.parse is deprecated, use native URL API instead."),qp},get format(){return Qp("7.3.0","utils.url.format is deprecated, use native URL API instead."),Kp},get resolve(){return Qp("7.3.0","utils.url.resolve is deprecated, use native URL API instead."),Jp}};function ef(t){if("string"!=typeof t)throw new TypeError(`Path must be a string. Received ${JSON.stringify(t)}`)}function sf(t){return t.split("?")[0].split("#")[0]}const rf={toPosix(t){return e="\\",i="/",t.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),i);var e,i},isUrl(t){return/^https?:/.test(this.toPosix(t))},isDataUrl:t=>/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(t),isBlobUrl:t=>t.startsWith("blob:"),hasProtocol(t){return/^[^/:]+:/.test(this.toPosix(t))},getProtocol(t){ef(t),t=this.toPosix(t);const e=/^file:\/\/\//.exec(t);if(e)return e[0];const i=/^[^/:]+:\/{0,2}/.exec(t);return i?i[0]:""},toAbsolute(t,e,i){if(ef(t),this.isDataUrl(t)||this.isBlobUrl(t))return t;const s=sf(this.toPosix(e??lh.ADAPTER.getBaseUrl())),r=sf(this.toPosix(i??this.rootname(s)));return(t=this.toPosix(t)).startsWith("/")?rf.join(r,t.slice(1)):this.isAbsolute(t)?t:this.join(s,t)},normalize(t){if(ef(t),0===t.length)return".";if(this.isDataUrl(t)||this.isBlobUrl(t))return t;let e="";const i=(t=this.toPosix(t)).startsWith("/");this.hasProtocol(t)&&(e=this.rootname(t),t=t.slice(e.length));const s=t.endsWith("/");return(t=function(t){let e="",i=0,s=-1,r=0,n=-1;for(let o=0;o<=t.length;++o){if(o<t.length)n=t.charCodeAt(o);else{if(47===n)break;n=47}if(47===n){if(s!==o-1&&1!==r)if(s!==o-1&&2===r){if(e.length<2||2!==i||46!==e.charCodeAt(e.length-1)||46!==e.charCodeAt(e.length-2))if(e.length>2){const t=e.lastIndexOf("/");if(t!==e.length-1){-1===t?(e="",i=0):(e=e.slice(0,t),i=e.length-1-e.lastIndexOf("/")),s=o,r=0;continue}}else if(2===e.length||1===e.length){e="",i=0,s=o,r=0;continue}}else e.length>0?e+=`/${t.slice(s+1,o)}`:e=t.slice(s+1,o),i=o-s-1;s=o,r=0}else 46===n&&-1!==r?++r:r=-1}return e}(t)).length>0&&s&&(t+="/"),i?`/${t}`:e+t},isAbsolute(t){return ef(t),t=this.toPosix(t),!!this.hasProtocol(t)||t.startsWith("/")},join(...t){if(0===t.length)return".";let e;for(let i=0;i<t.length;++i){const s=t[i];if(ef(s),s.length>0)if(void 0===e)e=s;else{const r=t[i-1]??"";this.joinExtensions.includes(this.extname(r).toLowerCase())?e+=`/../${s}`:e+=`/${s}`}}return void 0===e?".":this.normalize(e)},dirname(t){if(ef(t),0===t.length)return".";let e=(t=this.toPosix(t)).charCodeAt(0);const i=47===e;let s=-1,r=!0;const n=this.getProtocol(t),o=t;for(let a=(t=t.slice(n.length)).length-1;a>=1;--a)if(e=t.charCodeAt(a),47===e){if(!r){s=a;break}}else r=!1;return-1===s?i?"/":this.isUrl(o)?n+t:n:i&&1===s?"//":n+t.slice(0,s)},rootname(t){ef(t);let e="";if(e=(t=this.toPosix(t)).startsWith("/")?"/":this.getProtocol(t),this.isUrl(t)){const i=t.indexOf("/",e.length);e=-1!==i?t.slice(0,i):t,e.endsWith("/")||(e+="/")}return e},basename(t,e){ef(t),e&&ef(e),t=sf(this.toPosix(t));let i,s=0,r=-1,n=!0;if(void 0!==e&&e.length>0&&e.length<=t.length){if(e.length===t.length&&e===t)return"";let o=e.length-1,a=-1;for(i=t.length-1;i>=0;--i){const l=t.charCodeAt(i);if(47===l){if(!n){s=i+1;break}}else-1===a&&(n=!1,a=i+1),o>=0&&(l===e.charCodeAt(o)?-1==--o&&(r=i):(o=-1,r=a))}return s===r?r=a:-1===r&&(r=t.length),t.slice(s,r)}for(i=t.length-1;i>=0;--i)if(47===t.charCodeAt(i)){if(!n){s=i+1;break}}else-1===r&&(n=!1,r=i+1);return-1===r?"":t.slice(s,r)},extname(t){ef(t);let e=-1,i=0,s=-1,r=!0,n=0;for(let o=(t=sf(this.toPosix(t))).length-1;o>=0;--o){const a=t.charCodeAt(o);if(47!==a)-1===s&&(r=!1,s=o+1),46===a?-1===e?e=o:1!==n&&(n=1):-1!==e&&(n=-1);else if(!r){i=o+1;break}}return-1===e||-1===s||0===n||1===n&&e===s-1&&e===i+1?"":t.slice(e,s)},parse(t){ef(t);const e={root:"",dir:"",base:"",ext:"",name:""};if(0===t.length)return e;let i=(t=sf(this.toPosix(t))).charCodeAt(0);const s=this.isAbsolute(t);let r;e.root=this.rootname(t),r=s||this.hasProtocol(t)?1:0;let n=-1,o=0,a=-1,l=!0,h=t.length-1,u=0;for(;h>=r;--h)if(i=t.charCodeAt(h),47!==i)-1===a&&(l=!1,a=h+1),46===i?-1===n?n=h:1!==u&&(u=1):-1!==n&&(u=-1);else if(!l){o=h+1;break}return-1===n||-1===a||0===u||1===u&&n===a-1&&n===o+1?-1!==a&&(e.base=e.name=0===o&&s?t.slice(1,a):t.slice(o,a)):(0===o&&s?(e.name=t.slice(1,n),e.base=t.slice(1,a)):(e.name=t.slice(o,n),e.base=t.slice(o,a)),e.ext=t.slice(n,a)),e.dir=this.dirname(t),e},sep:"/",delimiter:":",joinExtensions:[".html"]};let nf,of;function af(){return typeof of>"u"&&(of=function(){var t;const e={stencil:!0,failIfMajorPerformanceCaveat:lh.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!lh.ADAPTER.getWebGLRenderingContext())return!1;const i=lh.ADAPTER.createCanvas();let s=i.getContext("webgl",e)||i.getContext("experimental-webgl",e);const r=!!(null==(t=null==s?void 0:s.getContextAttributes())?void 0:t.stencil);if(s){const t=s.getExtension("WEBGL_lose_context");t&&t.loseContext()}return s=null,r}catch{return!1}}()),of}var lf,hf={grad:.9,turn:360,rad:360/(2*Math.PI)},uf=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},cf=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},df=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},pf=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},ff=function(t){return{r:df(t.r,0,255),g:df(t.g,0,255),b:df(t.b,0,255),a:df(t.a)}},mf=function(t){return{r:cf(t.r),g:cf(t.g),b:cf(t.b),a:cf(t.a,3)}},gf=/^#([0-9a-f]{3,8})$/i,yf=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},vf=function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=Math.max(e,i,s),o=n-Math.min(e,i,s),a=o?n===e?(i-s)/o:n===i?2+(s-e)/o:4+(e-i)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},xf=function(t){var e=t.h,i=t.s,s=t.v,r=t.a;e=e/360*6,i/=100,s/=100;var n=Math.floor(e),o=s*(1-i),a=s*(1-(e-n)*i),l=s*(1-(1-e+n)*i),h=n%6;return{r:255*[s,a,o,o,l,s][h],g:255*[l,s,s,a,o,o][h],b:255*[o,o,l,s,s,a][h],a:r}},bf=function(t){return{h:pf(t.h),s:df(t.s,0,100),l:df(t.l,0,100),a:df(t.a)}},_f=function(t){return{h:cf(t.h),s:cf(t.s),l:cf(t.l),a:cf(t.a,3)}},wf=function(t){return xf((i=(e=t).s,{h:e.h,s:(i*=((s=e.l)<50?s:100-s)/100)>0?2*i/(s+i)*100:0,v:s+i,a:e.a}));var e,i,s},Pf=function(t){return{h:(e=vf(t)).h,s:(r=(200-(i=e.s))*(s=e.v)/100)>0&&r<200?i*s/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,i,s,r},Ef=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Tf=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Af=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,If=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Sf={string:[[function(t){var e=gf.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?cf(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?cf(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Af.exec(t)||If.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:ff({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Ef.exec(t)||Tf.exec(t);if(!e)return null;var i,s,r=bf({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(hf[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return wf(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=void 0===r?1:r;return uf(e)&&uf(i)&&uf(s)?ff({r:Number(e),g:Number(i),b:Number(s),a:Number(n)}):null},"rgb"],[function(t){var e=t.h,i=t.s,s=t.l,r=t.a,n=void 0===r?1:r;if(!uf(e)||!uf(i)||!uf(s))return null;var o=bf({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return wf(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!uf(e)||!uf(i)||!uf(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:pf(o.h),s:df(o.s,0,100),v:df(o.v,0,100),a:df(o.a)});return xf(a)},"hsv"]]},Cf=function(t,e){for(var i=0;i<e.length;i++){var s=e[i][0](t);if(s)return[s,e[i][1]]}return[null,void 0]},Mf=function(t,e){var i=Pf(t);return{h:i.h,s:df(i.s+100*e,0,100),l:i.l,a:i.a}},Of=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Nf=function(t,e){var i=Pf(t);return{h:i.h,s:i.s,l:df(i.l+100*e,0,100),a:i.a}},Lf=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Cf(t.trim(),Sf.string):"object"==typeof t&&null!==t?Cf(t,Sf.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return cf(Of(this.rgba),2)},t.prototype.isDark=function(){return Of(this.rgba)<.5},t.prototype.isLight=function(){return Of(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=mf(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?yf(cf(255*r)):"","#"+yf(e)+yf(i)+yf(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return mf(this.rgba)},t.prototype.toRgbString=function(){return e=(t=mf(this.rgba)).r,i=t.g,s=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+s+", "+r+")":"rgb("+e+", "+i+", "+s+")";var t,e,i,s,r},t.prototype.toHsl=function(){return _f(Pf(this.rgba))},t.prototype.toHslString=function(){return e=(t=_f(Pf(this.rgba))).h,i=t.s,s=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+s+"%, "+r+")":"hsl("+e+", "+i+"%, "+s+"%)";var t,e,i,s,r},t.prototype.toHsv=function(){return t=vf(this.rgba),{h:cf(t.h),s:cf(t.s),v:cf(t.v),a:cf(t.a,3)};var t},t.prototype.invert=function(){return Rf({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),Rf(Mf(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),Rf(Mf(this.rgba,-t))},t.prototype.grayscale=function(){return Rf(Mf(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),Rf(Nf(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),Rf(Nf(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?Rf({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):cf(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Pf(this.rgba);return"number"==typeof t?Rf({h:t,s:e.s,l:e.l,a:e.a}):cf(e.h)},t.prototype.isEqual=function(t){return this.toHex()===Rf(t).toHex()},t}(),Rf=function(t){return t instanceof Lf?t:new Lf(t)},kf=[];lf=[function(t,e){var i={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},s={};for(var r in i)s[i[r]]=r;var n={};t.prototype.toName=function(e){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var r,o,a=s[this.toHex()];if(a)return a;if(null==e?void 0:e.closest){var l=this.toRgb(),h=1/0,u="black";if(!n.length)for(var c in i)n[c]=new t(i[c]).toRgb();for(var d in i){var p=(r=l,o=n[d],Math.pow(r.r-o.r,2)+Math.pow(r.g-o.g,2)+Math.pow(r.b-o.b,2));p<h&&(h=p,u=d)}return u}},e.string.push([function(e){var s=e.toLowerCase(),r="transparent"===s?"#0000":i[s];return r?new t(r).toRgb():null},"name"])}],lf.forEach((function(t){kf.indexOf(t)<0&&(t(Lf,Sf),kf.push(t))}));const Bf=class t{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(e){if(e instanceof t)this._value=this.cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(null===e)throw new Error("Cannot set PIXI.Color#value to null");(null===this._value||!this.isSourceEqual(this._value,e))&&(this.normalize(e),this._value=this.cloneSource(e))}}get value(){return this._value}cloneSource(t){return"string"==typeof t||"number"==typeof t||t instanceof Number||null===t?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):"object"==typeof t&&null!==t?{...t}:t}isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if("number"===i||"string"===i||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length===e.length&&t.every(((t,i)=>t===e[i]));if(null!==t&&null!==e){const i=Object.keys(t),s=Object.keys(e);return i.length===s.length&&i.every((i=>t[i]===e[i]))}return t===e}toRgba(){const[t,e,i,s]=this._components;return{r:t,g:e,b:i,a:s}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,s]=this._components;return(t=t??[])[0]=Math.round(255*e),t[1]=Math.round(255*i),t[2]=Math.round(255*s),t}toRgbArray(t){t=t??[];const[e,i,s]=this._components;return t[0]=e,t[1]=i,t[2]=s,t}toNumber(){return this._int}toLittleEndianNumber(){const t=this._int;return(t>>16)+(65280&t)+((255&t)<<16)}multiply(e){const[i,s,r,n]=t.temp.setValue(e)._components;return this._components[0]*=i,this._components[1]*=s,this._components[2]*=r,this._components[3]*=n,this.refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this.refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(1===t)return(255<<24)+this._int;if(0===t)return e?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,r=255&this._int;return e&&(i=i*t+.5|0,s=s*t+.5|0,r=r*t+.5|0),(255*t<<24)+(i<<16)+(s<<8)+r}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const t=Math.round(255*this._components[3]).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(t){return this._components[3]=this._clamp(t),this}round(t){const[e,i,s]=this._components;return this._components[0]=Math.round(e*t)/t,this._components[1]=Math.round(i*t)/t,this._components[2]=Math.round(s*t)/t,this.refreshInt(),this._value=null,this}toArray(t){t=t??[];const[e,i,s,r]=this._components;return t[0]=e,t[1]=i,t[2]=s,t[3]=r,t}normalize(e){let i,s,r,n;if(("number"==typeof e||e instanceof Number)&&e>=0&&e<=16777215){i=(e>>16&255)/255,s=(e>>8&255)/255,r=(255&e)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[i,s,r,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[i,s,r,n=255]=e,i/=255,s/=255,r/=255,n/=255;else if("string"==typeof e||"object"==typeof e){if("string"==typeof e){const i=t.HEX_PATTERN.exec(e);i&&(e=`#${i[2]}`)}const o=Rf(e);o.isValid()&&(({r:i,g:s,b:r,a:n}=o.rgba),i/=255,s/=255,r/=255)}if(void 0===i)throw new Error(`Unable to convert color ${e}`);this._components[0]=i,this._components[1]=s,this._components[2]=r,this._components[3]=n,this.refreshInt()}refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(255*t<<16)+(255*e<<8)+(255*i|0)}_clamp(t,e=0,i=1){return"number"==typeof t?Math.min(Math.max(t,e),i):(t.forEach(((s,r)=>{t[r]=Math.min(Math.max(s,e),i)})),t)}};Bf.shared=new Bf,Bf.temp=new Bf,Bf.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let Ff=Bf;const Df=function(){const t=[],e=[];for(let s=0;s<32;s++)t[s]=s,e[s]=s;t[jl.NORMAL_NPM]=jl.NORMAL,t[jl.ADD_NPM]=jl.ADD,t[jl.SCREEN_NPM]=jl.SCREEN,e[jl.NORMAL]=jl.NORMAL_NPM,e[jl.ADD]=jl.ADD_NPM,e[jl.SCREEN]=jl.SCREEN_NPM;const i=[];return i.push(e),i.push(t),i}();const Uf=/^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;charset=([\w-]+))?(?:;(base64))?,(.*)/i;function Gf(t){if(4===t.BYTES_PER_ELEMENT)return t instanceof Float32Array?"Float32Array":t instanceof Uint32Array?"Uint32Array":"Int32Array";if(2===t.BYTES_PER_ELEMENT){if(t instanceof Uint16Array)return"Uint16Array"}else if(1===t.BYTES_PER_ELEMENT&&t instanceof Uint8Array)return"Uint8Array";return null}const Xf={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array};function Wf(t){return t+=0===t?1:0,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,(t|=t>>>16)+1}function Hf(t){return!(t&t-1||!t)}function Yf(t){let e=(t>65535?1:0)<<4,i=((t>>>=e)>255?1:0)<<3;return e|=i,i=((t>>>=i)>15?1:0)<<2,e|=i,i=((t>>>=i)>3?1:0)<<1,e|=i,e|(t>>>=i)>>1}function $f(t,e,i){const s=t.length;let r;if(e>=s||0===i)return;const n=s-(i=e+i>s?s-e:i);for(r=e;r<n;++r)t[r]=t[r+i];t.length=n}function jf(t){return 0===t?0:t<0?-1:1}let zf=0;function Vf(){return++zf}const qf=class{constructor(t,e,i,s){this.left=t,this.top=e,this.right=i,this.bottom=s}get width(){return this.right-this.left}get height(){return this.bottom-this.top}isEmpty(){return this.left===this.right||this.top===this.bottom}};qf.EMPTY=new qf(0,0,0,0);let Jf=qf;const Kf={},Zf=Object.create(null),Qf=Object.create(null);function tm(){let t;for(t in Zf)delete Zf[t];for(t in Qf)delete Qf[t]}class em{constructor(t,e,i){this._canvas=lh.ADAPTER.createCanvas(),this._context=this._canvas.getContext("2d"),this.resolution=i||lh.RESOLUTION,this.resize(t,e)}clear(){this._checkDestroyed(),this._context.setTransform(1,0,0,1,0,0),this._context.clearRect(0,0,this._canvas.width,this._canvas.height)}resize(t,e){this._checkDestroyed(),this._canvas.width=Math.round(t*this.resolution),this._canvas.height=Math.round(e*this.resolution)}destroy(){this._context=null,this._canvas=null}get width(){return this._checkDestroyed(),this._canvas.width}set width(t){this._checkDestroyed(),this._canvas.width=Math.round(t)}get height(){return this._checkDestroyed(),this._canvas.height}set height(t){this._checkDestroyed(),this._canvas.height=Math.round(t)}get canvas(){return this._checkDestroyed(),this._canvas}get context(){return this._checkDestroyed(),this._context}_checkDestroyed(){if(null===this._canvas)throw new TypeError("The CanvasRenderTarget has already been destroyed")}}function im(t,e,i){for(let s=0,r=4*i*e;s<e;++s,r+=4)if(0!==t[r+3])return!1;return!0}function sm(t,e,i,s,r){const n=4*e;for(let o=s,a=s*n+4*i;o<=r;++o,a+=n)if(0!==t[a+3])return!1;return!0}function rm(t){const{width:e,height:i}=t,s=t.getContext("2d",{willReadFrequently:!0});if(null===s)throw new TypeError("Failed to get canvas 2D context");const r=s.getImageData(0,0,e,i).data;let n=0,o=0,a=e-1,l=i-1;for(;o<i&&im(r,e,o);)++o;if(o===i)return Jf.EMPTY;for(;im(r,e,l);)--l;for(;sm(r,e,n,o,l);)++n;for(;sm(r,e,a,o,l);)--a;return++a,++l,new Jf(n,o,a,l)}function nm(t){const e=rm(t),{width:i,height:s}=e;let r=null;if(!e.isEmpty()){const n=t.getContext("2d");if(null===n)throw new TypeError("Failed to get canvas 2D context");r=n.getImageData(e.left,e.top,i,s)}return{width:i,height:s,data:r}}function om(t,e=globalThis.location){if(t.startsWith("data:"))return"";e=e||globalThis.location;const i=new URL(t,document.baseURI);return i.hostname!==e.hostname||i.port!==e.port||i.protocol!==e.protocol?"anonymous":""}function am(t,e=1){var i;const s=null==(i=lh.RETINA_PREFIX)?void 0:i.exec(t);return s?parseFloat(s[1]):e}const lm=Object.freeze(Object.defineProperty({__proto__:null,BaseTextureCache:Qf,BoundingBox:Jf,CanvasRenderTarget:em,DATA_URI:Uf,EventEmitter:Sh,ProgramCache:Kf,TextureCache:Zf,clearTextureCache:tm,correctBlendMode:function(t,e){return Df[e?1:0][t]},createIndicesForQuads:function(t,e=null){const i=6*t;if((e=e||new Uint16Array(i)).length!==i)throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${i}`);for(let s=0,r=0;s<i;s+=6,r+=4)e[s+0]=r+0,e[s+1]=r+1,e[s+2]=r+2,e[s+3]=r+0,e[s+4]=r+2,e[s+5]=r+3;return e},decomposeDataUri:function(t){const e=Uf.exec(t);if(e)return{mediaType:e[1]?e[1].toLowerCase():void 0,subType:e[2]?e[2].toLowerCase():void 0,charset:e[3]?e[3].toLowerCase():void 0,encoding:e[4]?e[4].toLowerCase():void 0,data:e[5]}},deprecation:Qp,destroyTextureCache:function(){let t;for(t in Zf)Zf[t].destroy();for(t in Qf)Qf[t].destroy()},detectVideoAlphaMode:async function(){return nf??(nf=(async()=>{var t;const e=document.createElement("canvas").getContext("webgl");if(!e)return eh.UNPACK;const i=await new Promise((t=>{const e=document.createElement("video");e.onloadeddata=()=>t(e),e.onerror=()=>t(null),e.autoplay=!1,e.crossOrigin="anonymous",e.preload="auto",e.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",e.load()}));if(!i)return eh.UNPACK;const s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s);const r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i);const n=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,n),e.deleteFramebuffer(r),e.deleteTexture(s),null==(t=e.getExtension("WEBGL_lose_context"))||t.loseContext(),n[0]<=n[3]?eh.PMA:eh.UNPACK})()),nf},determineCrossOrigin:om,earcut:ne,getBufferType:Gf,getCanvasBoundingBox:rm,getResolutionOfUrl:am,hex2rgb:function(t,e=[]){return Qp("7.2.0","utils.hex2rgb is deprecated, use Color#toRgbArray instead"),Ff.shared.setValue(t).toRgbArray(e)},hex2string:function(t){return Qp("7.2.0","utils.hex2string is deprecated, use Color#toHex instead"),Ff.shared.setValue(t).toHex()},interleaveTypedArrays:function(t,e){let i=0,s=0;const r={};for(let l=0;l<t.length;l++)s+=e[l],i+=t[l].length;const n=new ArrayBuffer(4*i);let o=null,a=0;for(let l=0;l<t.length;l++){const i=e[l],h=t[l],u=Gf(h);r[u]||(r[u]=new Xf[u](n)),o=r[u];for(let t=0;t<h.length;t++){o[(t/i|0)*s+a+t%i]=h[t]}a+=i}return new Float32Array(n)},isMobile:Ah,isPow2:Hf,isWebGLSupported:af,log2:Yf,nextPow2:Wf,path:rf,premultiplyBlendMode:Df,premultiplyRgba:function(t,e,i,s=!0){return Qp("7.2.0","utils.premultiplyRgba has moved to Color.premultiply"),Ff.shared.setValue(t).premultiply(e,s).toArray(i??new Float32Array(4))},premultiplyTint:function(t,e){return Qp("7.2.0","utils.premultiplyTint has moved to Color.toPremultiplied"),Ff.shared.setValue(t).toPremultiplied(e)},premultiplyTintToRgba:function(t,e,i,s=!0){return Qp("7.2.0","utils.premultiplyTintToRgba has moved to Color.premultiply"),Ff.shared.setValue(t).premultiply(e,s).toArray(i??new Float32Array(4))},removeItems:$f,rgb2hex:function(t){return Qp("7.2.0","utils.rgb2hex is deprecated, use Color#toNumber instead"),Ff.shared.setValue(t).toNumber()},sayHello:function(){Qp("7.0.0",'sayHello is deprecated, please use Renderer\'s "hello" option')},sign:jf,skipHello:function(){Qp("7.0.0","skipHello is deprecated, please use settings.RENDER_OPTIONS.hello")},string2hex:function(t){return Qp("7.2.0","utils.string2hex is deprecated, use Color#toNumber instead"),Ff.shared.setValue(t).toNumber()},trimCanvas:nm,uid:Vf,url:tf},Symbol.toStringTag,{value:"Module"}));var hm=(t=>(t.Renderer="renderer",t.Application="application",t.RendererSystem="renderer-webgl-system",t.RendererPlugin="renderer-webgl-plugin",t.CanvasRendererSystem="renderer-canvas-system",t.CanvasRendererPlugin="renderer-canvas-plugin",t.Asset="asset",t.LoadParser="load-parser",t.ResolveParser="resolve-parser",t.CacheParser="cache-parser",t.DetectionParser="detection-parser",t))(hm||{});const um=t=>{if("function"==typeof t||"object"==typeof t&&t.extension){if(!t.extension)throw new Error("Extension class must have an extension object");t={..."object"!=typeof t.extension?{type:t.extension}:t.extension,ref:t}}if("object"!=typeof t)throw new Error("Invalid extension type");return"string"==typeof(t={...t}).type&&(t.type=[t.type]),t},cm=(t,e)=>um(t).priority??e,dm={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...t){return t.map(um).forEach((t=>{t.type.forEach((e=>{var i,s;return null==(s=(i=this._removeHandlers)[e])?void 0:s.call(i,t)}))})),this},add(...t){return t.map(um).forEach((t=>{t.type.forEach((e=>{var i,s;const r=this._addHandlers,n=this._queue;r[e]?null==(i=r[e])||i.call(r,t):(n[e]=n[e]||[],null==(s=n[e])||s.push(t))}))})),this},handle(t,e,i){var s;const r=this._addHandlers,n=this._removeHandlers;if(r[t]||n[t])throw new Error(`Extension type ${t} already has a handler`);r[t]=e,n[t]=i;const o=this._queue;return o[t]&&(null==(s=o[t])||s.forEach((t=>e(t))),delete o[t]),this},handleByMap(t,e){return this.handle(t,(t=>{t.name&&(e[t.name]=t.ref)}),(t=>{t.name&&delete e[t.name]}))},handleByList(t,e,i=-1){return this.handle(t,(t=>{e.includes(t.ref)||(e.push(t.ref),e.sort(((t,e)=>cm(e,i)-cm(t,i))))}),(t=>{const i=e.indexOf(t.ref);-1!==i&&e.splice(i,1)}))}};class pm{constructor(t){"number"==typeof t?this.rawBinaryData=new ArrayBuffer(t):t instanceof Uint8Array?this.rawBinaryData=t.buffer:this.rawBinaryData=t,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData)}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get uint16View(){return this._uint16View||(this._uint16View=new Uint16Array(this.rawBinaryData)),this._uint16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}view(t){return this[`${t}View`]}destroy(){this.rawBinaryData=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._uint16View=null,this._int32View=null,this.uint32View=null,this.float32View=null}static sizeOf(t){switch(t){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${t} isn't a valid view type`)}}}const fm=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join("\n");function mm(t){let e="";for(let i=0;i<t;++i)i>0&&(e+="\nelse "),i<t-1&&(e+=`if(test == ${i}.0){}`);return e}class gm{constructor(){this.data=0,this.blendMode=jl.NORMAL,this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(1&this.data)}set blend(t){!!(1&this.data)!==t&&(this.data^=1)}get offsets(){return!!(2&this.data)}set offsets(t){!!(2&this.data)!==t&&(this.data^=2)}get culling(){return!!(4&this.data)}set culling(t){!!(4&this.data)!==t&&(this.data^=4)}get depthTest(){return!!(8&this.data)}set depthTest(t){!!(8&this.data)!==t&&(this.data^=8)}get depthMask(){return!!(32&this.data)}set depthMask(t){!!(32&this.data)!==t&&(this.data^=32)}get clockwiseFrontFace(){return!!(16&this.data)}set clockwiseFrontFace(t){!!(16&this.data)!==t&&(this.data^=16)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!==jl.NONE,this._blendMode=t}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}static for2d(){const t=new gm;return t.depthTest=!1,t.blend=!0,t}}gm.prototype.toString=function(){return`[@pixi/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`};const ym=[];function vm(t,e){if(!t)return null;let i="";if("string"==typeof t){const e=/\.(\w{3,4})(?:$|\?|#)/i.exec(t);e&&(i=e[1].toLowerCase())}for(let s=ym.length-1;s>=0;--s){const r=ym[s];if(r.test&&r.test(t,i))return new r(t,e)}throw new Error("Unrecognized source type to auto-detect Resource")}class xm{constructor(t){this.items=[],this._name=t,this._aliasCount=0}emit(t,e,i,s,r,n,o,a){if(arguments.length>8)throw new Error("max arguments reached");const{name:l,items:h}=this;this._aliasCount++;for(let u=0,c=h.length;u<c;u++)h[u][l](t,e,i,s,r,n,o,a);return h===this.items&&this._aliasCount--,this}ensureNonAliasedItems(){this._aliasCount>0&&this.items.length>1&&(this._aliasCount=0,this.items=this.items.slice(0))}add(t){return t[this._name]&&(this.ensureNonAliasedItems(),this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return-1!==e&&(this.ensureNonAliasedItems(),this.items.splice(e,1)),this}contains(t){return this.items.includes(t)}removeAll(){return this.ensureNonAliasedItems(),this.items.length=0,this}destroy(){this.removeAll(),this.items.length=0,this._name=""}get empty(){return 0===this.items.length}get name(){return this._name}}Object.defineProperties(xm.prototype,{dispatch:{value:xm.prototype.emit},run:{value:xm.prototype.emit}});class bm{constructor(t=0,e=0){this._width=t,this._height=e,this.destroyed=!1,this.internal=!1,this.onResize=new xm("setRealSize"),this.onUpdate=new xm("update"),this.onError=new xm("onError")}bind(t){this.onResize.add(t),this.onUpdate.add(t),this.onError.add(t),(this._width||this._height)&&this.onResize.emit(this._width,this._height)}unbind(t){this.onResize.remove(t),this.onUpdate.remove(t),this.onError.remove(t)}resize(t,e){(t!==this._width||e!==this._height)&&(this._width=t,this._height=e,this.onResize.emit(t,e))}get valid(){return!!this._width&&!!this._height}update(){this.destroyed||this.onUpdate.emit()}load(){return Promise.resolve(this)}get width(){return this._width}get height(){return this._height}style(t,e,i){return!1}dispose(){}destroy(){this.destroyed||(this.destroyed=!0,this.dispose(),this.onError.removeAll(),this.onError=null,this.onResize.removeAll(),this.onResize=null,this.onUpdate.removeAll(),this.onUpdate=null)}static test(t,e){return!1}}class _m extends bm{constructor(t,e){const{width:i,height:s}=e||{};if(!i||!s)throw new Error("BufferResource width or height invalid");super(i,s),this.data=t,this.unpackAlignment=e.unpackAlignment??4}upload(t,e,i){const s=t.gl;s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.alphaMode===eh.UNPACK);const r=e.realWidth,n=e.realHeight;return i.width===r&&i.height===n?s.texSubImage2D(e.target,0,0,0,r,n,e.format,i.type,this.data):(i.width=r,i.height=n,s.texImage2D(e.target,0,i.internalFormat,r,n,0,e.format,i.type,this.data)),!0}dispose(){this.data=null}static test(t){return null===t||t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array}}const wm={scaleMode:Zl.NEAREST,alphaMode:eh.NPM},Pm=class t extends Sh{constructor(e=null,i=null){super(),i=Object.assign({},t.defaultOptions,i);const{alphaMode:s,mipmap:r,anisotropicLevel:n,scaleMode:o,width:a,height:l,wrapMode:h,format:u,type:c,target:d,resolution:p,resourceOptions:f}=i;e&&!(e instanceof bm)&&((e=vm(e,f)).internal=!0),this.resolution=p||lh.RESOLUTION,this.width=Math.round((a||0)*this.resolution)/this.resolution,this.height=Math.round((l||0)*this.resolution)/this.resolution,this._mipmap=r,this.anisotropicLevel=n,this._wrapMode=h,this._scaleMode=o,this.format=u,this.type=c,this.target=d,this.alphaMode=s,this.uid=Vf(),this.touched=0,this.isPowerOfTwo=!1,this._refreshPOT(),this._glTextures={},this.dirtyId=0,this.dirtyStyleId=0,this.cacheId=null,this.valid=a>0&&l>0,this.textureCacheIds=[],this.destroyed=!1,this.resource=null,this._batchEnabled=0,this._batchLocation=0,this.parentTextureArray=null,this.setResource(e)}get realWidth(){return Math.round(this.width*this.resolution)}get realHeight(){return Math.round(this.height*this.resolution)}get mipmap(){return this._mipmap}set mipmap(t){this._mipmap!==t&&(this._mipmap=t,this.dirtyStyleId++)}get scaleMode(){return this._scaleMode}set scaleMode(t){this._scaleMode!==t&&(this._scaleMode=t,this.dirtyStyleId++)}get wrapMode(){return this._wrapMode}set wrapMode(t){this._wrapMode!==t&&(this._wrapMode=t,this.dirtyStyleId++)}setStyle(t,e){let i;return void 0!==t&&t!==this.scaleMode&&(this.scaleMode=t,i=!0),void 0!==e&&e!==this.mipmap&&(this.mipmap=e,i=!0),i&&this.dirtyStyleId++,this}setSize(t,e,i){return i=i||this.resolution,this.setRealSize(t*i,e*i,i)}setRealSize(t,e,i){return this.resolution=i||this.resolution,this.width=Math.round(t)/this.resolution,this.height=Math.round(e)/this.resolution,this._refreshPOT(),this.update(),this}_refreshPOT(){this.isPowerOfTwo=Hf(this.realWidth)&&Hf(this.realHeight)}setResolution(t){const e=this.resolution;return e===t||(this.resolution=t,this.valid&&(this.width=Math.round(this.width*e)/t,this.height=Math.round(this.height*e)/t,this.emit("update",this)),this._refreshPOT()),this}setResource(t){if(this.resource===t)return this;if(this.resource)throw new Error("Resource can be set only once");return t.bind(this),this.resource=t,this}update(){this.valid?(this.dirtyId++,this.dirtyStyleId++,this.emit("update",this)):this.width>0&&this.height>0&&(this.valid=!0,this.emit("loaded",this),this.emit("update",this))}onError(t){this.emit("error",this,t)}destroy(){this.resource&&(this.resource.unbind(this),this.resource.internal&&this.resource.destroy(),this.resource=null),this.cacheId&&(delete Qf[this.cacheId],delete Zf[this.cacheId],this.cacheId=null),this.valid=!1,this.dispose(),t.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0,this.emit("destroyed",this),this.removeAllListeners()}dispose(){this.emit("dispose",this)}castToBaseTexture(){return this}static from(e,i,s=lh.STRICT_TEXTURE_CACHE){const r="string"==typeof e;let n=null;if(r)n=e;else{if(!e._pixiId){const t=(null==i?void 0:i.pixiIdPrefix)||"pixiid";e._pixiId=`${t}_${Vf()}`}n=e._pixiId}let o=Qf[n];if(r&&s&&!o)throw new Error(`The cacheId "${n}" does not exist in BaseTextureCache.`);return o||(o=new t(e,i),o.cacheId=n,t.addToCache(o,n)),o}static fromBuffer(e,i,s,r){e=e||new Float32Array(i*s*4);const n=new _m(e,{width:i,height:s,...null==r?void 0:r.resourceOptions});let o,a;return e instanceof Float32Array?(o=Vl.RGBA,a=Jl.FLOAT):e instanceof Int32Array?(o=Vl.RGBA_INTEGER,a=Jl.INT):e instanceof Uint32Array?(o=Vl.RGBA_INTEGER,a=Jl.UNSIGNED_INT):e instanceof Int16Array?(o=Vl.RGBA_INTEGER,a=Jl.SHORT):e instanceof Uint16Array?(o=Vl.RGBA_INTEGER,a=Jl.UNSIGNED_SHORT):e instanceof Int8Array?(o=Vl.RGBA,a=Jl.BYTE):(o=Vl.RGBA,a=Jl.UNSIGNED_BYTE),n.internal=!0,new t(n,Object.assign({},wm,{type:a,format:o},r))}static addToCache(t,e){e&&(t.textureCacheIds.includes(e)||t.textureCacheIds.push(e),Qf[e]&&Qf[e]!==t&&console.warn(`BaseTexture added to the cache with an id [${e}] that already had an entry`),Qf[e]=t)}static removeFromCache(t){if("string"==typeof t){const e=Qf[t];if(e){const i=e.textureCacheIds.indexOf(t);return i>-1&&e.textureCacheIds.splice(i,1),delete Qf[t],e}}else if(null==t?void 0:t.textureCacheIds){for(let e=0;e<t.textureCacheIds.length;++e)delete Qf[t.textureCacheIds[e]];return t.textureCacheIds.length=0,t}return null}};Pm.defaultOptions={mipmap:th.POW2,anisotropicLevel:0,scaleMode:Zl.LINEAR,wrapMode:Ql.CLAMP,alphaMode:eh.UNPACK,target:ql.TEXTURE_2D,format:Vl.RGBA,type:Jl.UNSIGNED_BYTE},Pm._globalBatch=0;let Em=Pm;class Tm{constructor(){this.texArray=null,this.blend=0,this.type=zl.TRIANGLES,this.start=0,this.size=0,this.data=null}}let Am=0;class Im{constructor(t,e=!0,i=!1){this.data=t||new Float32Array(1),this._glBuffers={},this._updateID=0,this.index=i,this.static=e,this.id=Am++,this.disposeRunner=new xm("disposeBuffer")}update(t){t instanceof Array&&(t=new Float32Array(t)),this.data=t||this.data,this._updateID++}dispose(){this.disposeRunner.emit(this,!1)}destroy(){this.dispose(),this.data=null}set index(t){this.type=t?ah.ELEMENT_ARRAY_BUFFER:ah.ARRAY_BUFFER}get index(){return this.type===ah.ELEMENT_ARRAY_BUFFER}static from(t){return t instanceof Array&&(t=new Float32Array(t)),new Im(t)}}class Sm{constructor(t,e=0,i=!1,s=Jl.FLOAT,r,n,o,a=1){this.buffer=t,this.size=e,this.normalized=i,this.type=s,this.stride=r,this.start=n,this.instance=o,this.divisor=a}destroy(){this.buffer=null}static from(t,e,i,s,r){return new Sm(t,e,i,s,r)}}const Cm={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array};const Mm={5126:4,5123:2,5121:1};let Om=0;const Nm={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array};class Lm{constructor(t=[],e={}){this.buffers=t,this.indexBuffer=null,this.attributes=e,this.glVertexArrayObjects={},this.id=Om++,this.instanced=!1,this.instanceCount=1,this.disposeRunner=new xm("disposeGeometry"),this.refCount=0}addAttribute(t,e,i=0,s=!1,r,n,o,a=!1){if(!e)throw new Error("You must pass a buffer when creating an attribute");e instanceof Im||(e instanceof Array&&(e=new Float32Array(e)),e=new Im(e));const l=t.split("|");if(l.length>1){for(let t=0;t<l.length;t++)this.addAttribute(l[t],e,i,s,r);return this}let h=this.buffers.indexOf(e);return-1===h&&(this.buffers.push(e),h=this.buffers.length-1),this.attributes[t]=new Sm(h,i,s,r,n,o,a),this.instanced=this.instanced||a,this}getAttribute(t){return this.attributes[t]}getBuffer(t){return this.buffers[this.getAttribute(t).buffer]}addIndex(t){return t instanceof Im||(t instanceof Array&&(t=new Uint16Array(t)),t=new Im(t)),t.type=ah.ELEMENT_ARRAY_BUFFER,this.indexBuffer=t,this.buffers.includes(t)||this.buffers.push(t),this}getIndex(){return this.indexBuffer}interleave(){if(1===this.buffers.length||2===this.buffers.length&&this.indexBuffer)return this;const t=[],e=[],i=new Im;let s;for(s in this.attributes){const i=this.attributes[s],r=this.buffers[i.buffer];t.push(r.data),e.push(i.size*Mm[i.type]/4),i.buffer=0}for(i.data=function(t,e){let i=0,s=0;const r={};for(let l=0;l<t.length;l++)s+=e[l],i+=t[l].length;const n=new ArrayBuffer(4*i);let o=null,a=0;for(let l=0;l<t.length;l++){const i=e[l],h=t[l],u=Gf(h);r[u]||(r[u]=new Cm[u](n)),o=r[u];for(let t=0;t<h.length;t++)o[(t/i|0)*s+a+t%i]=h[t];a+=i}return new Float32Array(n)}(t,e),s=0;s<this.buffers.length;s++)this.buffers[s]!==this.indexBuffer&&this.buffers[s].destroy();return this.buffers=[i],this.indexBuffer&&this.buffers.push(this.indexBuffer),this}getSize(){for(const t in this.attributes){const e=this.attributes[t];return this.buffers[e.buffer].data.length/(e.stride/4||e.size)}return 0}dispose(){this.disposeRunner.emit(this,!1)}destroy(){this.dispose(),this.buffers=null,this.indexBuffer=null,this.attributes=null}clone(){const t=new Lm;for(let e=0;e<this.buffers.length;e++)t.buffers[e]=new Im(this.buffers[e].data.slice(0));for(const e in this.attributes){const i=this.attributes[e];t.attributes[e]=new Sm(i.buffer,i.size,i.normalized,i.type,i.stride,i.start,i.instance)}return this.indexBuffer&&(t.indexBuffer=t.buffers[this.buffers.indexOf(this.indexBuffer)],t.indexBuffer.type=ah.ELEMENT_ARRAY_BUFFER),t}static merge(t){const e=new Lm,i=[],s=[],r=[];let n;for(let o=0;o<t.length;o++){n=t[o];for(let t=0;t<n.buffers.length;t++)s[t]=s[t]||0,s[t]+=n.buffers[t].data.length,r[t]=0}for(let o=0;o<n.buffers.length;o++)i[o]=new(Nm[Gf(n.buffers[o].data)])(s[o]),e.buffers[o]=new Im(i[o]);for(let o=0;o<t.length;o++){n=t[o];for(let t=0;t<n.buffers.length;t++)i[t].set(n.buffers[t].data,r[t]),r[t]+=n.buffers[t].data.length}if(e.attributes=n.attributes,n.indexBuffer){e.indexBuffer=e.buffers[n.buffers.indexOf(n.indexBuffer)],e.indexBuffer.type=ah.ELEMENT_ARRAY_BUFFER;let i=0,s=0,r=0,o=0;for(let t=0;t<n.buffers.length;t++)if(n.buffers[t]!==n.indexBuffer){o=t;break}for(const t in n.attributes){const e=n.attributes[t];(0|e.buffer)===o&&(s+=e.size*Mm[e.type]/4)}for(let n=0;n<t.length;n++){const a=t[n].indexBuffer.data;for(let t=0;t<a.length;t++)e.indexBuffer.data[t+r]+=i;i+=t[n].buffers[o].data.length/s,r+=a.length}}return e}}class Rm extends Lm{constructor(t=!1){super(),this._buffer=new Im(null,t,!1),this._indexBuffer=new Im(null,t,!0),this.addAttribute("aVertexPosition",this._buffer,2,!1,Jl.FLOAT).addAttribute("aTextureCoord",this._buffer,2,!1,Jl.FLOAT).addAttribute("aColor",this._buffer,4,!0,Jl.UNSIGNED_BYTE).addAttribute("aTextureId",this._buffer,1,!0,Jl.FLOAT).addIndex(this._indexBuffer)}}const km=2*Math.PI,Bm=180/Math.PI,Fm=Math.PI/180;var Dm=(t=>(t[t.POLY=0]="POLY",t[t.RECT=1]="RECT",t[t.CIRC=2]="CIRC",t[t.ELIP=3]="ELIP",t[t.RREC=4]="RREC",t))(Dm||{});class Um{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new Um(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}}Um.prototype.toString=function(){return`[@pixi/math:Point x=${this.x} y=${this.y}]`};const Gm=[new Um,new Um,new Um,new Um];class Xm{constructor(t=0,e=0,i=0,s=0){this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(s),this.type=Dm.RECT}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}static get EMPTY(){return new Xm(0,0,0,0)}clone(){return new Xm(this.x,this.y,this.width,this.height)}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t}contains(t,e){return!(this.width<=0||this.height<=0)&&(t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height)}intersects(t,e){if(!e){const e=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=e)return!1;const i=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>i}const i=this.left,s=this.right,r=this.top,n=this.bottom;if(s<=i||n<=r)return!1;const o=Gm[0].set(t.left,t.top),a=Gm[1].set(t.left,t.bottom),l=Gm[2].set(t.right,t.top),h=Gm[3].set(t.right,t.bottom);if(l.x<=o.x||a.y<=o.y)return!1;const u=Math.sign(e.a*e.d-e.b*e.c);if(0===u||(e.apply(o,o),e.apply(a,a),e.apply(l,l),e.apply(h,h),Math.max(o.x,a.x,l.x,h.x)<=i||Math.min(o.x,a.x,l.x,h.x)>=s||Math.max(o.y,a.y,l.y,h.y)<=r||Math.min(o.y,a.y,l.y,h.y)>=n))return!1;const c=u*(a.y-o.y),d=u*(o.x-a.x),p=c*i+d*r,f=c*s+d*r,m=c*i+d*n,g=c*s+d*n;if(Math.max(p,f,m,g)<=c*o.x+d*o.y||Math.min(p,f,m,g)>=c*h.x+d*h.y)return!1;const y=u*(o.y-l.y),v=u*(l.x-o.x),x=y*i+v*r,b=y*s+v*r,_=y*i+v*n,w=y*s+v*n;return!(Math.max(x,b,_,w)<=y*o.x+v*o.y||Math.min(x,b,_,w)>=y*h.x+v*h.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),r=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=s,this.height=Math.max(r-s,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,s=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=s-this.y,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),r=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=s,this.height=r-s,this}}Xm.prototype.toString=function(){return`[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class Wm{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.radius=i,this.type=Dm.CIRC}clone(){return new Wm(this.x,this.y,this.radius)}contains(t,e){if(this.radius<=0)return!1;const i=this.radius*this.radius;let s=this.x-t,r=this.y-e;return s*=s,r*=r,s+r<=i}getBounds(){return new Xm(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius)}}Wm.prototype.toString=function(){return`[@pixi/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`};class Hm{constructor(t=0,e=0,i=0,s=0){this.x=t,this.y=e,this.width=i,this.height=s,this.type=Dm.ELIP}clone(){return new Hm(this.x,this.y,this.width,this.height)}contains(t,e){if(this.width<=0||this.height<=0)return!1;let i=(t-this.x)/this.width,s=(e-this.y)/this.height;return i*=i,s*=s,i+s<=1}getBounds(){return new Xm(this.x-this.width,this.y-this.height,this.width,this.height)}}Hm.prototype.toString=function(){return`[@pixi/math:Ellipse x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class Ym{constructor(...t){let e=Array.isArray(t[0])?t[0]:t;if("number"!=typeof e[0]){const t=[];for(let i=0,s=e.length;i<s;i++)t.push(e[i].x,e[i].y);e=t}this.points=e,this.type=Dm.POLY,this.closeStroke=!0}clone(){const t=this.points.slice(),e=new Ym(t);return e.closeStroke=this.closeStroke,e}contains(t,e){let i=!1;const s=this.points.length/2;for(let r=0,n=s-1;r<s;n=r++){const s=this.points[2*r],o=this.points[2*r+1],a=this.points[2*n],l=this.points[2*n+1];o>e!=l>e&&t<(e-o)/(l-o)*(a-s)+s&&(i=!i)}return i}}Ym.prototype.toString=function(){return`[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce(((t,e)=>`${t}, ${e}`),"")}]`};class $m{constructor(t=0,e=0,i=0,s=0,r=20){this.x=t,this.y=e,this.width=i,this.height=s,this.radius=r,this.type=Dm.RREC}clone(){return new $m(this.x,this.y,this.width,this.height,this.radius)}contains(t,e){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(e>=this.y+i&&e<=this.y+this.height-i||t>=this.x+i&&t<=this.x+this.width-i)return!0;let s=t-(this.x+i),r=e-(this.y+i);const n=i*i;if(s*s+r*r<=n||(s=t-(this.x+this.width-i),s*s+r*r<=n)||(r=e-(this.y+this.height-i),s*s+r*r<=n)||(s=t-(this.x+i),s*s+r*r<=n))return!0}return!1}}$m.prototype.toString=function(){return`[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`};class jm{constructor(t=1,e=0,i=0,s=1,r=0,n=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=n}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,s,r,n){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=n,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new Um;const i=t.x,s=t.y;return e.x=this.a*i+this.c*s+this.tx,e.y=this.b*i+this.d*s+this.ty,e}applyInverse(t,e){e=e||new Um;const i=1/(this.a*this.d+this.c*-this.b),s=t.x,r=t.y;return e.x=this.d*i*s+-this.c*i*r+(this.ty*this.c-this.tx*this.d)*i,e.y=this.a*i*r+-this.b*i*s+(-this.ty*this.a+this.tx*this.b)*i,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.a,r=this.c,n=this.tx;return this.a=s*e-this.b*i,this.b=s*i+this.b*e,this.c=r*e-this.d*i,this.d=r*i+this.d*e,this.tx=n*e-this.ty*i,this.ty=n*i+this.ty*e,this}append(t){const e=this.a,i=this.b,s=this.c,r=this.d;return this.a=t.a*e+t.b*s,this.b=t.a*i+t.b*r,this.c=t.c*e+t.d*s,this.d=t.c*i+t.d*r,this.tx=t.tx*e+t.ty*s+this.tx,this.ty=t.tx*i+t.ty*r+this.ty,this}setTransform(t,e,i,s,r,n,o,a,l){return this.a=Math.cos(o+l)*r,this.b=Math.sin(o+l)*r,this.c=-Math.sin(o-a)*n,this.d=Math.cos(o-a)*n,this.tx=t-(i*this.a+s*this.c),this.ty=e-(i*this.b+s*this.d),this}prepend(t){const e=this.tx;if(1!==t.a||0!==t.b||0!==t.c||1!==t.d){const e=this.a,i=this.c;this.a=e*t.a+this.b*t.c,this.b=e*t.b+this.b*t.d,this.c=i*t.a+this.d*t.c,this.d=i*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,s=this.c,r=this.d,n=t.pivot,o=-Math.atan2(-s,r),a=Math.atan2(i,e),l=Math.abs(o+a);return l<1e-5||Math.abs(km-l)<1e-5?(t.rotation=a,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=o,t.skew.y=a),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(s*s+r*r),t.position.x=this.tx+(n.x*e+n.y*s),t.position.y=this.ty+(n.x*i+n.y*r),t}invert(){const t=this.a,e=this.b,i=this.c,s=this.d,r=this.tx,n=t*s-e*i;return this.a=s/n,this.b=-e/n,this.c=-i/n,this.d=t/n,this.tx=(i*this.ty-s*r)/n,this.ty=-(t*this.ty-e*r)/n,this}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const t=new jm;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}static get IDENTITY(){return new jm}static get TEMP_MATRIX(){return new jm}}jm.prototype.toString=function(){return`[@pixi/math:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`};const zm=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Vm=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],qm=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Jm=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Km=[],Zm=[],Qm=Math.sign;!function(){for(let t=0;t<16;t++){const e=[];Km.push(e);for(let i=0;i<16;i++){const s=Qm(zm[t]*zm[i]+qm[t]*Vm[i]),r=Qm(Vm[t]*zm[i]+Jm[t]*Vm[i]),n=Qm(zm[t]*qm[i]+qm[t]*Jm[i]),o=Qm(Vm[t]*qm[i]+Jm[t]*Jm[i]);for(let t=0;t<16;t++)if(zm[t]===s&&Vm[t]===r&&qm[t]===n&&Jm[t]===o){e.push(t);break}}}for(let t=0;t<16;t++){const e=new jm;e.set(zm[t],Vm[t],qm[t],Jm[t],0,0),Zm.push(e)}}();const tg={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:t=>zm[t],uY:t=>Vm[t],vX:t=>qm[t],vY:t=>Jm[t],inv:t=>8&t?15&t:7&-t,add:(t,e)=>Km[t][e],sub:(t,e)=>Km[t][tg.inv(e)],rotate180:t=>4^t,isVertical:t=>2==(3&t),byDirection:(t,e)=>2*Math.abs(t)<=Math.abs(e)?e>=0?tg.S:tg.N:2*Math.abs(e)<=Math.abs(t)?t>0?tg.E:tg.W:e>0?t>0?tg.SE:tg.SW:t>0?tg.NE:tg.NW,matrixAppendRotationInv:(t,e,i=0,s=0)=>{const r=Zm[tg.inv(e)];r.tx=i,r.ty=s,t.append(r)}};class eg{constructor(t,e,i=0,s=0){this._x=i,this._y=s,this.cb=t,this.scope=e}clone(t=this.cb,e=this.scope){return new eg(t,e,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this.cb.call(this.scope)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this.cb.call(this.scope)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this.cb.call(this.scope))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this.cb.call(this.scope))}}eg.prototype.toString=function(){return`[@pixi/math:ObservablePoint x=${this.x} y=${this.y} scope=${this.scope}]`};const ig=class{constructor(){this.worldTransform=new jm,this.localTransform=new jm,this.position=new eg(this.onChange,this,0,0),this.scale=new eg(this.onChange,this,1,1),this.pivot=new eg(this.onChange,this,0,0),this.skew=new eg(this.updateSkew,this,0,0),this._rotation=0,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._localID=0,this._currentLocalID=0,this._worldID=0,this._parentID=0}onChange(){this._localID++}updateSkew(){this._cx=Math.cos(this._rotation+this.skew.y),this._sx=Math.sin(this._rotation+this.skew.y),this._cy=-Math.sin(this._rotation-this.skew.x),this._sy=Math.cos(this._rotation-this.skew.x),this._localID++}updateLocalTransform(){const t=this.localTransform;this._localID!==this._currentLocalID&&(t.a=this._cx*this.scale.x,t.b=this._sx*this.scale.x,t.c=this._cy*this.scale.y,t.d=this._sy*this.scale.y,t.tx=this.position.x-(this.pivot.x*t.a+this.pivot.y*t.c),t.ty=this.position.y-(this.pivot.x*t.b+this.pivot.y*t.d),this._currentLocalID=this._localID,this._parentID=-1)}updateTransform(t){const e=this.localTransform;if(this._localID!==this._currentLocalID&&(e.a=this._cx*this.scale.x,e.b=this._sx*this.scale.x,e.c=this._cy*this.scale.y,e.d=this._sy*this.scale.y,e.tx=this.position.x-(this.pivot.x*e.a+this.pivot.y*e.c),e.ty=this.position.y-(this.pivot.x*e.b+this.pivot.y*e.d),this._currentLocalID=this._localID,this._parentID=-1),this._parentID!==t._worldID){const i=t.worldTransform,s=this.worldTransform;s.a=e.a*i.a+e.b*i.c,s.b=e.a*i.b+e.b*i.d,s.c=e.c*i.a+e.d*i.c,s.d=e.c*i.b+e.d*i.d,s.tx=e.tx*i.a+e.ty*i.c+i.tx,s.ty=e.tx*i.b+e.ty*i.d+i.ty,this._parentID=t._worldID,this._worldID++}}setFromMatrix(t){t.decompose(this),this._localID++}get rotation(){return this._rotation}set rotation(t){this._rotation!==t&&(this._rotation=t,this.updateSkew())}};ig.IDENTITY=new ig;let sg=ig;sg.prototype.toString=function(){return`[@pixi/math:Transform position=(${this.position.x}, ${this.position.y}) rotation=${this.rotation} scale=(${this.scale.x}, ${this.scale.y}) skew=(${this.skew.x}, ${this.skew.y}) ]`};function rg(t,e,i){const s=t.createShader(e);return t.shaderSource(s,i),t.compileShader(s),s}function ng(t){const e=new Array(t);for(let i=0;i<e.length;i++)e[i]=!1;return e}function og(t,e){switch(t){case"float":case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return ng(2*e);case"bvec3":return ng(3*e);case"bvec4":return ng(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const ag=[{test:t=>"float"===t.type&&1===t.size&&!t.isArray,code:t=>`\n if(uv["${t}"] !== ud["${t}"].value)\n {\n ud["${t}"].value = uv["${t}"]\n gl.uniform1f(ud["${t}"].location, uv["${t}"])\n }\n `},{test:(t,e)=>!("sampler2D"!==t.type&&"samplerCube"!==t.type&&"sampler2DArray"!==t.type||1!==t.size||t.isArray||null!=e&&void 0===e.castToBaseTexture),code:t=>`t = syncData.textureCount++;\n\n renderer.texture.bind(uv["${t}"], t);\n\n if(ud["${t}"].value !== t)\n {\n ud["${t}"].value = t;\n gl.uniform1i(ud["${t}"].location, t);\n; // eslint-disable-line max-len\n }`},{test:(t,e)=>"mat3"===t.type&&1===t.size&&!t.isArray&&void 0!==e.a,code:t=>`\n gl.uniformMatrix3fv(ud["${t}"].location, false, uv["${t}"].toArray(true));\n `,codeUbo:t=>`\n var ${t}_matrix = uv.${t}.toArray(true);\n\n data[offset] = ${t}_matrix[0];\n data[offset+1] = ${t}_matrix[1];\n data[offset+2] = ${t}_matrix[2];\n \n data[offset + 4] = ${t}_matrix[3];\n data[offset + 5] = ${t}_matrix[4];\n data[offset + 6] = ${t}_matrix[5];\n \n data[offset + 8] = ${t}_matrix[6];\n data[offset + 9] = ${t}_matrix[7];\n data[offset + 10] = ${t}_matrix[8];\n `},{test:(t,e)=>"vec2"===t.type&&1===t.size&&!t.isArray&&void 0!==e.x,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.x || cv[1] !== v.y)\n {\n cv[0] = v.x;\n cv[1] = v.y;\n gl.uniform2f(ud["${t}"].location, v.x, v.y);\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.x;\n data[offset+1] = v.y;\n `},{test:t=>"vec2"===t.type&&1===t.size&&!t.isArray,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n gl.uniform2f(ud["${t}"].location, v[0], v[1]);\n }\n `},{test:(t,e)=>"vec4"===t.type&&1===t.size&&!t.isArray&&void 0!==e.width,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height)\n {\n cv[0] = v.x;\n cv[1] = v.y;\n cv[2] = v.width;\n cv[3] = v.height;\n gl.uniform4f(ud["${t}"].location, v.x, v.y, v.width, v.height)\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.x;\n data[offset+1] = v.y;\n data[offset+2] = v.width;\n data[offset+3] = v.height;\n `},{test:(t,e)=>"vec4"===t.type&&1===t.size&&!t.isArray&&void 0!==e.red,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha)\n {\n cv[0] = v.red;\n cv[1] = v.green;\n cv[2] = v.blue;\n cv[3] = v.alpha;\n gl.uniform4f(ud["${t}"].location, v.red, v.green, v.blue, v.alpha)\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.red;\n data[offset+1] = v.green;\n data[offset+2] = v.blue;\n data[offset+3] = v.alpha;\n `},{test:(t,e)=>"vec3"===t.type&&1===t.size&&!t.isArray&&void 0!==e.red,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.a)\n {\n cv[0] = v.red;\n cv[1] = v.green;\n cv[2] = v.blue;\n \n gl.uniform3f(ud["${t}"].location, v.red, v.green, v.blue)\n }`,codeUbo:t=>`\n v = uv.${t};\n\n data[offset] = v.red;\n data[offset+1] = v.green;\n data[offset+2] = v.blue;\n `},{test:t=>"vec4"===t.type&&1===t.size&&!t.isArray,code:t=>`\n cv = ud["${t}"].value;\n v = uv["${t}"];\n\n if(cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4f(ud["${t}"].location, v[0], v[1], v[2], v[3])\n }`}],lg={float:"\n if (cv !== v)\n {\n cu.value = v;\n gl.uniform1f(location, v);\n }",vec2:"\n if (cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2f(location, v[0], v[1])\n }",vec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3f(location, v[0], v[1], v[2])\n }",vec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4f(location, v[0], v[1], v[2], v[3]);\n }",int:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }",ivec2:"\n if (cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2i(location, v[0], v[1]);\n }",ivec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3i(location, v[0], v[1], v[2]);\n }",ivec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4i(location, v[0], v[1], v[2], v[3]);\n }",uint:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1ui(location, v);\n }",uvec2:"\n if (cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2ui(location, v[0], v[1]);\n }",uvec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3ui(location, v[0], v[1], v[2]);\n }",uvec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4ui(location, v[0], v[1], v[2], v[3]);\n }",bool:"\n if (cv !== v)\n {\n cu.value = v;\n gl.uniform1i(location, v);\n }",bvec2:"\n if (cv[0] != v[0] || cv[1] != v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n\n gl.uniform2i(location, v[0], v[1]);\n }",bvec3:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3i(location, v[0], v[1], v[2]);\n }",bvec4:"\n if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4i(location, v[0], v[1], v[2], v[3]);\n }",mat2:"gl.uniformMatrix2fv(location, false, v)",mat3:"gl.uniformMatrix3fv(location, false, v)",mat4:"gl.uniformMatrix4fv(location, false, v)",sampler2D:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }",samplerCube:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }",sampler2DArray:"\n if (cv !== v)\n {\n cu.value = v;\n\n gl.uniform1i(location, v);\n }"},hg={float:"gl.uniform1fv(location, v)",vec2:"gl.uniform2fv(location, v)",vec3:"gl.uniform3fv(location, v)",vec4:"gl.uniform4fv(location, v)",mat4:"gl.uniformMatrix4fv(location, false, v)",mat3:"gl.uniformMatrix3fv(location, false, v)",mat2:"gl.uniformMatrix2fv(location, false, v)",int:"gl.uniform1iv(location, v)",ivec2:"gl.uniform2iv(location, v)",ivec3:"gl.uniform3iv(location, v)",ivec4:"gl.uniform4iv(location, v)",uint:"gl.uniform1uiv(location, v)",uvec2:"gl.uniform2uiv(location, v)",uvec3:"gl.uniform3uiv(location, v)",uvec4:"gl.uniform4uiv(location, v)",bool:"gl.uniform1iv(location, v)",bvec2:"gl.uniform2iv(location, v)",bvec3:"gl.uniform3iv(location, v)",bvec4:"gl.uniform4iv(location, v)",sampler2D:"gl.uniform1iv(location, v)",samplerCube:"gl.uniform1iv(location, v)",sampler2DArray:"gl.uniform1iv(location, v)"};const ug={};let cg,dg=ug;function pg(){if(!cg){cg=rh.MEDIUM;const t=function(){if(dg===ug||(null==dg?void 0:dg.isContextLost())){const t=lh.ADAPTER.createCanvas();let e;lh.PREFER_ENV>=Hl.WEBGL2&&(e=t.getContext("webgl2",{})),e||(e=t.getContext("webgl",{})||t.getContext("experimental-webgl",{}),e?e.getExtension("WEBGL_draw_buffers"):e=null),dg=e}return dg}();if(t&&t.getShaderPrecisionFormat){const e=t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT);e&&(cg=e.precision?rh.HIGH:rh.MEDIUM)}}return cg}function fg(t,e){const i=t.getShaderSource(e).split("\n").map(((t,e)=>`${e}: ${t}`)),s=t.getShaderInfoLog(e),r=s.split("\n"),n={},o=r.map((t=>parseFloat(t.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1")))).filter((t=>!(!t||n[t])&&(n[t]=!0,!0))),a=[""];o.forEach((t=>{i[t-1]=`%c${i[t-1]}%c`,a.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")}));const l=i.join("\n");a[0]=l,console.error(s),console.groupCollapsed("click to view full shader code"),console.warn(...a),console.groupEnd()}const mg={float:1,vec2:2,vec3:3,vec4:4,int:1,ivec2:2,ivec3:3,ivec4:4,uint:1,uvec2:2,uvec3:3,uvec4:4,bool:1,bvec2:2,bvec3:3,bvec4:4,mat2:4,mat3:9,mat4:16,sampler2D:1};function gg(t){return mg[t]}let yg=null;const vg={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"};function xg(t,e){if(!yg){const e=Object.keys(vg);yg={};for(let i=0;i<e.length;++i){const s=e[i];yg[t[s]]=vg[s]}}return yg[e]}function bg(t,e,i){if("precision"!==t.substring(0,9)){let s=e;return e===rh.HIGH&&i!==rh.HIGH&&(s=rh.MEDIUM),`precision ${s} float;\n${t}`}return i!==rh.HIGH&&"precision highp"===t.substring(0,15)?t.replace("precision highp","precision mediump"):t}let _g;let wg=0;const Pg={},Eg=class t{constructor(e,i,s="pixi-shader",r={}){this.extra={},this.id=wg++,this.vertexSrc=e||t.defaultVertexSrc,this.fragmentSrc=i||t.defaultFragmentSrc,this.vertexSrc=this.vertexSrc.trim(),this.fragmentSrc=this.fragmentSrc.trim(),this.extra=r,"#version"!==this.vertexSrc.substring(0,8)&&(s=s.replace(/\s+/g,"-"),Pg[s]?(Pg[s]++,s+=`-${Pg[s]}`):Pg[s]=1,this.vertexSrc=`#define SHADER_NAME ${s}\n${this.vertexSrc}`,this.fragmentSrc=`#define SHADER_NAME ${s}\n${this.fragmentSrc}`,this.vertexSrc=bg(this.vertexSrc,t.defaultVertexPrecision,rh.HIGH),this.fragmentSrc=bg(this.fragmentSrc,t.defaultFragmentPrecision,pg())),this.glPrograms={},this.syncUniforms=null}static get defaultVertexSrc(){return"attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}\n"}static get defaultFragmentSrc(){return"varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n gl_FragColor *= texture2D(uSampler, vTextureCoord);\n}"}static from(e,i,s){const r=e+i;let n=Kf[r];return n||(Kf[r]=n=new t(e,i,s)),n}};Eg.defaultVertexPrecision=rh.HIGH,Eg.defaultFragmentPrecision=Ah.apple.device?rh.HIGH:rh.MEDIUM;let Tg=Eg,Ag=0;class Ig{constructor(t,e,i){this.group=!0,this.syncUniforms={},this.dirtyId=0,this.id=Ag++,this.static=!!e,this.ubo=!!i,t instanceof Im?(this.buffer=t,this.buffer.type=ah.UNIFORM_BUFFER,this.autoManage=!1,this.ubo=!0):(this.uniforms=t,this.ubo&&(this.buffer=new Im(new Float32Array(1)),this.buffer.type=ah.UNIFORM_BUFFER,this.autoManage=!0))}update(){this.dirtyId++,!this.autoManage&&this.buffer&&this.buffer.update()}add(t,e,i){if(this.ubo)throw new Error("[UniformGroup] uniform groups in ubo mode cannot be modified, or have uniform groups nested in them");this.uniforms[t]=new Ig(e,i)}static from(t,e,i){return new Ig(t,e,i)}static uboFrom(t,e){return new Ig(t,e??!0,!0)}}class Sg{constructor(t,e){this.uniformBindCount=0,this.program=t,this.uniformGroup=e?e instanceof Ig?e:new Ig(e):new Ig({}),this.disposeRunner=new xm("disposeShader")}checkUniformExists(t,e){if(e.uniforms[t])return!0;for(const i in e.uniforms){const s=e.uniforms[i];if(!0===s.group&&this.checkUniformExists(t,s))return!0}return!1}destroy(){this.uniformGroup=null,this.disposeRunner.emit(this),this.disposeRunner.destroy()}get uniforms(){return this.uniformGroup.uniforms}static from(t,e,i){const s=Tg.from(t,e);return new Sg(s,i)}}class Cg{constructor(t,e){if(this.vertexSrc=t,this.fragTemplate=e,this.programCache={},this.defaultGroupCache={},!e.includes("%count%"))throw new Error('Fragment template must contain "%count%".');if(!e.includes("%forloop%"))throw new Error('Fragment template must contain "%forloop%".')}generateShader(t){if(!this.programCache[t]){const e=new Int32Array(t);for(let s=0;s<t;s++)e[s]=s;this.defaultGroupCache[t]=Ig.from({uSamplers:e},!0);let i=this.fragTemplate;i=i.replace(/%count%/gi,`${t}`),i=i.replace(/%forloop%/gi,this.generateSampleSrc(t)),this.programCache[t]=new Tg(this.vertexSrc,i)}const e={tint:new Float32Array([1,1,1,1]),translationMatrix:new jm,default:this.defaultGroupCache[t]};return new Sg(this.programCache[t],e)}generateSampleSrc(t){let e="";e+="\n",e+="\n";for(let i=0;i<t;i++)i>0&&(e+="\nelse "),i<t-1&&(e+=`if(vTextureId < ${i}.5)`),e+="\n{",e+=`\n\tcolor = texture2D(uSamplers[${i}], vTextureCoord);`,e+="\n}";return e+="\n",e+="\n",e}}class Mg{constructor(){this.elements=[],this.ids=[],this.count=0}clear(){for(let t=0;t<this.count;t++)this.elements[t]=null;this.count=0}}class Og{constructor(t){this.renderer=t}flush(){}destroy(){this.renderer=null}start(){}stop(){this.flush()}render(t){}}const Ng=class t extends Og{constructor(e){super(e),this.setShaderGenerator(),this.geometryClass=Rm,this.vertexSize=6,this.state=gm.for2d(),this.size=4*t.defaultBatchSize,this._vertexCount=0,this._indexCount=0,this._bufferedElements=[],this._bufferedTextures=[],this._bufferSize=0,this._shader=null,this._packedGeometries=[],this._packedGeometryPoolSize=2,this._flushId=0,this._aBuffers={},this._iBuffers={},this.maxTextures=1,this.renderer.on("prerender",this.onPrerender,this),e.runners.contextChange.add(this),this._dcIndex=0,this._aIndex=0,this._iIndex=0,this._attributeBuffer=null,this._indexBuffer=null,this._tempBoundTextures=[]}static get defaultMaxTextures(){return this._defaultMaxTextures=this._defaultMaxTextures??function(t){let e=!0;const i=lh.ADAPTER.getNavigator();if(Ah.tablet||Ah.phone){if(Ah.apple.device){const t=i.userAgent.match(/OS (\d+)_(\d+)?/);t&&parseInt(t[1],10)<11&&(e=!1)}if(Ah.android.device){const t=i.userAgent.match(/Android\s([0-9.]*)/);t&&parseInt(t[1],10)<7&&(e=!1)}}return e?t:4}(32),this._defaultMaxTextures}static set defaultMaxTextures(t){this._defaultMaxTextures=t}static get canUploadSameBuffer(){return this._canUploadSameBuffer=this._canUploadSameBuffer??!Ah.apple.device,this._canUploadSameBuffer}static set canUploadSameBuffer(t){this._canUploadSameBuffer=t}get MAX_TEXTURES(){return Qp("7.1.0","BatchRenderer#MAX_TEXTURES renamed to BatchRenderer#maxTextures"),this.maxTextures}static get defaultVertexSrc(){return"precision highp float;\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform vec4 tint;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vTextureId = aTextureId;\n vColor = aColor * tint;\n}\n"}static get defaultFragmentTemplate(){return"varying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\nuniform sampler2D uSamplers[%count%];\n\nvoid main(void){\n vec4 color;\n %forloop%\n gl_FragColor = color * vColor;\n}\n"}setShaderGenerator({vertex:e=t.defaultVertexSrc,fragment:i=t.defaultFragmentTemplate}={}){this.shaderGenerator=new Cg(e,i)}contextChange(){const e=this.renderer.gl;lh.PREFER_ENV===Hl.WEBGL_LEGACY?this.maxTextures=1:(this.maxTextures=Math.min(e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),t.defaultMaxTextures),this.maxTextures=function(t,e){if(0===t)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const i=e.createShader(e.FRAGMENT_SHADER);for(;;){const s=fm.replace(/%forloop%/gi,mm(t));if(e.shaderSource(i,s),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS))break;t=t/2|0}return t}(this.maxTextures,e)),this._shader=this.shaderGenerator.generateShader(this.maxTextures);for(let t=0;t<this._packedGeometryPoolSize;t++)this._packedGeometries[t]=new this.geometryClass;this.initFlushBuffers()}initFlushBuffers(){const{_drawCallPool:e,_textureArrayPool:i}=t,s=this.size/4,r=Math.floor(s/this.maxTextures)+1;for(;e.length<s;)e.push(new Tm);for(;i.length<r;)i.push(new Mg);for(let t=0;t<this.maxTextures;t++)this._tempBoundTextures[t]=null}onPrerender(){this._flushId=0}render(t){t._texture.valid&&(this._vertexCount+t.vertexData.length/2>this.size&&this.flush(),this._vertexCount+=t.vertexData.length/2,this._indexCount+=t.indices.length,this._bufferedTextures[this._bufferSize]=t._texture.baseTexture,this._bufferedElements[this._bufferSize++]=t)}buildTexturesAndDrawCalls(){const{_bufferedTextures:e,maxTextures:i}=this,s=t._textureArrayPool,r=this.renderer.batch,n=this._tempBoundTextures,o=this.renderer.textureGC.count;let a=++Em._globalBatch,l=0,h=s[0],u=0;r.copyBoundTextures(n,i);for(let t=0;t<this._bufferSize;++t){const c=e[t];e[t]=null,c._batchEnabled!==a&&(h.count>=i&&(r.boundArray(h,n,a,i),this.buildDrawCalls(h,u,t),u=t,h=s[++l],++a),c._batchEnabled=a,c.touched=o,h.elements[h.count++]=c)}h.count>0&&(r.boundArray(h,n,a,i),this.buildDrawCalls(h,u,this._bufferSize),++l,++a);for(let t=0;t<n.length;t++)n[t]=null;Em._globalBatch=a}buildDrawCalls(e,i,s){const{_bufferedElements:r,_attributeBuffer:n,_indexBuffer:o,vertexSize:a}=this,l=t._drawCallPool;let h=this._dcIndex,u=this._aIndex,c=this._iIndex,d=l[h];d.start=this._iIndex,d.texArray=e;for(let t=i;t<s;++t){const s=r[t],p=s._texture.baseTexture,f=Df[p.alphaMode?1:0][s.blendMode];r[t]=null,i<t&&d.blend!==f&&(d.size=c-d.start,i=t,d=l[++h],d.texArray=e,d.start=c),this.packInterleavedGeometry(s,n,o,u,c),u+=s.vertexData.length/2*a,c+=s.indices.length,d.blend=f}i<s&&(d.size=c-d.start,++h),this._dcIndex=h,this._aIndex=u,this._iIndex=c}bindAndClearTexArray(t){const e=this.renderer.texture;for(let i=0;i<t.count;i++)e.bind(t.elements[i],t.ids[i]),t.elements[i]=null;t.count=0}updateGeometry(){const{_packedGeometries:e,_attributeBuffer:i,_indexBuffer:s}=this;t.canUploadSameBuffer?(e[this._flushId]._buffer.update(i.rawBinaryData),e[this._flushId]._indexBuffer.update(s),this.renderer.geometry.updateBuffers()):(this._packedGeometryPoolSize<=this._flushId&&(this._packedGeometryPoolSize++,e[this._flushId]=new this.geometryClass),e[this._flushId]._buffer.update(i.rawBinaryData),e[this._flushId]._indexBuffer.update(s),this.renderer.geometry.bind(e[this._flushId]),this.renderer.geometry.updateBuffers(),this._flushId++)}drawBatches(){const e=this._dcIndex,{gl:i,state:s}=this.renderer,r=t._drawCallPool;let n=null;for(let t=0;t<e;t++){const{texArray:e,type:o,size:a,start:l,blend:h}=r[t];n!==e&&(n=e,this.bindAndClearTexArray(e)),this.state.blendMode=h,s.set(this.state),i.drawElements(o,a,i.UNSIGNED_SHORT,2*l)}}flush(){0!==this._vertexCount&&(this._attributeBuffer=this.getAttributeBuffer(this._vertexCount),this._indexBuffer=this.getIndexBuffer(this._indexCount),this._aIndex=0,this._iIndex=0,this._dcIndex=0,this.buildTexturesAndDrawCalls(),this.updateGeometry(),this.drawBatches(),this._bufferSize=0,this._vertexCount=0,this._indexCount=0)}start(){this.renderer.state.set(this.state),this.renderer.texture.ensureSamplerType(this.maxTextures),this.renderer.shader.bind(this._shader),t.canUploadSameBuffer&&this.renderer.geometry.bind(this._packedGeometries[this._flushId])}stop(){this.flush()}destroy(){for(let t=0;t<this._packedGeometryPoolSize;t++)this._packedGeometries[t]&&this._packedGeometries[t].destroy();this.renderer.off("prerender",this.onPrerender,this),this._aBuffers=null,this._iBuffers=null,this._packedGeometries=null,this._attributeBuffer=null,this._indexBuffer=null,this._shader&&(this._shader.destroy(),this._shader=null),super.destroy()}getAttributeBuffer(t){const e=Wf(Math.ceil(t/8)),i=Yf(e),s=8*e;this._aBuffers.length<=i&&(this._iBuffers.length=i+1);let r=this._aBuffers[s];return r||(this._aBuffers[s]=r=new pm(s*this.vertexSize*4)),r}getIndexBuffer(t){const e=Wf(Math.ceil(t/12)),i=Yf(e),s=12*e;this._iBuffers.length<=i&&(this._iBuffers.length=i+1);let r=this._iBuffers[i];return r||(this._iBuffers[i]=r=new Uint16Array(s)),r}packInterleavedGeometry(t,e,i,s,r){const{uint32View:n,float32View:o}=e,a=s/this.vertexSize,l=t.uvs,h=t.indices,u=t.vertexData,c=t._texture.baseTexture._batchLocation,d=Math.min(t.worldAlpha,1),p=Ff.shared.setValue(t._tintRGB).toPremultiplied(d,t._texture.baseTexture.alphaMode>0);for(let f=0;f<u.length;f+=2)o[s++]=u[f],o[s++]=u[f+1],o[s++]=l[f],o[s++]=l[f+1],n[s++]=p,o[s++]=c;for(let f=0;f<h.length;f++)i[r++]=a+h[f]}};Ng.defaultBatchSize=4096,Ng.extension={name:"batch",type:hm.RendererPlugin},Ng._drawCallPool=[],Ng._textureArrayPool=[];let Lg=Ng;dm.add(Lg);const Rg=class t extends Sg{constructor(e,i,s){super(Tg.from(e||t.defaultVertexSrc,i||t.defaultFragmentSrc),s),this.padding=0,this.resolution=t.defaultResolution,this.multisample=t.defaultMultisample,this.enabled=!0,this.autoFit=!0,this.state=new gm}apply(t,e,i,s,r){t.applyFilter(this,e,i,s)}get blendMode(){return this.state.blendMode}set blendMode(t){this.state.blendMode=t}get resolution(){return this._resolution}set resolution(t){this._resolution=t}static get defaultVertexSrc(){return"attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n gl_Position = filterVertexPosition();\n vTextureCoord = filterTextureCoord();\n}\n"}static get defaultFragmentSrc(){return"varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n}\n"}};Rg.defaultResolution=1,Rg.defaultMultisample=oh.NONE;let kg=Rg;class Bg{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new Ff(0),this.alpha=1}init(t){this.clearBeforeRender=t.clearBeforeRender;const{backgroundColor:e,background:i,backgroundAlpha:s}=t,r=i??e;void 0!==r&&(this.color=r),this.alpha=s}get color(){return this._backgroundColor.value}set color(t){this._backgroundColor.setValue(t)}get alpha(){return this._backgroundColor.alpha}set alpha(t){this._backgroundColor.setAlpha(t)}get backgroundColor(){return this._backgroundColor}destroy(){}}Bg.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0},Bg.extension={type:[hm.RendererSystem,hm.CanvasRendererSystem],name:"background"},dm.add(Bg);class Fg{constructor(t){this.renderer=t,this.emptyRenderer=new Og(t),this.currentRenderer=this.emptyRenderer}setObjectRenderer(t){this.currentRenderer!==t&&(this.currentRenderer.stop(),this.currentRenderer=t,this.currentRenderer.start())}flush(){this.setObjectRenderer(this.emptyRenderer)}reset(){this.setObjectRenderer(this.emptyRenderer)}copyBoundTextures(t,e){const{boundTextures:i}=this.renderer.texture;for(let s=e-1;s>=0;--s)t[s]=i[s]||null,t[s]&&(t[s]._batchLocation=s)}boundArray(t,e,i,s){const{elements:r,ids:n,count:o}=t;let a=0;for(let l=0;l<o;l++){const t=r[l],o=t._batchLocation;if(o>=0&&o<s&&e[o]===t)n[l]=o;else for(;a<s;){const s=e[a];if(!s||s._batchEnabled!==i||s._batchLocation!==a){n[l]=a,t._batchLocation=a,e[a]=t;break}a++}}}destroy(){this.renderer=null}}Fg.extension={type:hm.RendererSystem,name:"batch"},dm.add(Fg);let Dg=0;class Ug{constructor(t){this.renderer=t,this.webGLVersion=1,this.extensions={},this.supports={uint32Indices:!1},this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(t){this.gl=t,this.renderer.gl=t,this.renderer.CONTEXT_UID=Dg++}init(t){if(t.context)this.initFromContext(t.context);else{const e=this.renderer.background.alpha<1,i=t.premultipliedAlpha;this.preserveDrawingBuffer=t.preserveDrawingBuffer,this.useContextAlpha=t.useContextAlpha,this.powerPreference=t.powerPreference,this.initFromOptions({alpha:e,premultipliedAlpha:i,antialias:t.antialias,stencil:!0,preserveDrawingBuffer:t.preserveDrawingBuffer,powerPreference:t.powerPreference})}}initFromContext(t){this.gl=t,this.validateContext(t),this.renderer.gl=t,this.renderer.CONTEXT_UID=Dg++,this.renderer.runners.contextChange.emit(t);const e=this.renderer.view;void 0!==e.addEventListener&&(e.addEventListener("webglcontextlost",this.handleContextLost,!1),e.addEventListener("webglcontextrestored",this.handleContextRestored,!1))}initFromOptions(t){const e=this.createContext(this.renderer.view,t);this.initFromContext(e)}createContext(t,e){let i;if(lh.PREFER_ENV>=Hl.WEBGL2&&(i=t.getContext("webgl2",e)),i)this.webGLVersion=2;else if(this.webGLVersion=1,i=t.getContext("webgl",e)||t.getContext("experimental-webgl",e),!i)throw new Error("This browser does not support WebGL. Try using the canvas renderer");return this.gl=i,this.getExtensions(),this.gl}getExtensions(){const{gl:t}=this,e={loseContext:t.getExtension("WEBGL_lose_context"),anisotropicFiltering:t.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:t.getExtension("OES_texture_float_linear"),s3tc:t.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:t.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:t.getExtension("WEBGL_compressed_texture_etc"),etc1:t.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:t.getExtension("WEBGL_compressed_texture_atc"),astc:t.getExtension("WEBGL_compressed_texture_astc"),bptc:t.getExtension("EXT_texture_compression_bptc")};1===this.webGLVersion?Object.assign(this.extensions,e,{drawBuffers:t.getExtension("WEBGL_draw_buffers"),depthTexture:t.getExtension("WEBGL_depth_texture"),vertexArrayObject:t.getExtension("OES_vertex_array_object")||t.getExtension("MOZ_OES_vertex_array_object")||t.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:t.getExtension("OES_element_index_uint"),floatTexture:t.getExtension("OES_texture_float"),floatTextureLinear:t.getExtension("OES_texture_float_linear"),textureHalfFloat:t.getExtension("OES_texture_half_float"),textureHalfFloatLinear:t.getExtension("OES_texture_half_float_linear")}):2===this.webGLVersion&&Object.assign(this.extensions,e,{colorBufferFloat:t.getExtension("EXT_color_buffer_float")})}handleContextLost(t){t.preventDefault(),setTimeout((()=>{this.gl.isContextLost()&&this.extensions.loseContext&&this.extensions.loseContext.restoreContext()}),0)}handleContextRestored(){this.renderer.runners.contextChange.emit(this.gl)}destroy(){const t=this.renderer.view;this.renderer=null,void 0!==t.removeEventListener&&(t.removeEventListener("webglcontextlost",this.handleContextLost),t.removeEventListener("webglcontextrestored",this.handleContextRestored)),this.gl.useProgram(null),this.extensions.loseContext&&this.extensions.loseContext.loseContext()}postrender(){this.renderer.objectRenderer.renderingToScreen&&this.gl.flush()}validateContext(t){const e=t.getContextAttributes(),i="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext;i&&(this.webGLVersion=2),e&&!e.stencil&&console.warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const s=i||!!t.getExtension("OES_element_index_uint");this.supports.uint32Indices=s,s||console.warn("Provided WebGL context does not support 32 index buffer, complex graphics may not render correctly")}}Ug.defaultOptions={context:null,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"},Ug.extension={type:hm.RendererSystem,name:"context"},dm.add(Ug);class Gg{constructor(t,e){if(this.width=Math.round(t),this.height=Math.round(e),!this.width||!this.height)throw new Error("Framebuffer width or height is zero");this.stencil=!1,this.depth=!1,this.dirtyId=0,this.dirtyFormat=0,this.dirtySize=0,this.depthTexture=null,this.colorTextures=[],this.glFramebuffers={},this.disposeRunner=new xm("disposeFramebuffer"),this.multisample=oh.NONE}get colorTexture(){return this.colorTextures[0]}addColorTexture(t=0,e){return this.colorTextures[t]=e||new Em(null,{scaleMode:Zl.NEAREST,resolution:1,mipmap:th.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this}addDepthTexture(t){return this.depthTexture=t||new Em(null,{scaleMode:Zl.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:th.OFF,format:Vl.DEPTH_COMPONENT,type:Jl.UNSIGNED_SHORT}),this.dirtyId++,this.dirtyFormat++,this}enableDepth(){return this.depth=!0,this.dirtyId++,this.dirtyFormat++,this}enableStencil(){return this.stencil=!0,this.dirtyId++,this.dirtyFormat++,this}resize(t,e){if(t=Math.round(t),e=Math.round(e),!t||!e)throw new Error("Framebuffer width and height must not be zero");if(t!==this.width||e!==this.height){this.width=t,this.height=e,this.dirtyId++,this.dirtySize++;for(let i=0;i<this.colorTextures.length;i++){const s=this.colorTextures[i],r=s.resolution;s.setSize(t/r,e/r)}if(this.depthTexture){const i=this.depthTexture.resolution;this.depthTexture.setSize(t/i,e/i)}}}dispose(){this.disposeRunner.emit(this,!1)}destroyDepthTexture(){this.depthTexture&&(this.depthTexture.destroy(),this.depthTexture=null,++this.dirtyId,++this.dirtyFormat)}}class Xg extends Em{constructor(t={}){if("number"==typeof t){t={width:arguments[0],height:arguments[1],scaleMode:arguments[2],resolution:arguments[3]}}t.width=t.width??100,t.height=t.height??100,t.multisample??(t.multisample=oh.NONE),super(null,t),this.mipmap=th.OFF,this.valid=!0,this._clear=new Ff([0,0,0,0]),this.framebuffer=new Gg(this.realWidth,this.realHeight).addColorTexture(0,this),this.framebuffer.multisample=t.multisample,this.maskStack=[],this.filterStack=[{}]}set clearColor(t){this._clear.setValue(t)}get clearColor(){return this._clear.value}get clear(){return this._clear}get multisample(){return this.framebuffer.multisample}set multisample(t){this.framebuffer.multisample=t}resize(t,e){this.framebuffer.resize(t*this.resolution,e*this.resolution),this.setRealSize(this.framebuffer.width,this.framebuffer.height)}dispose(){this.framebuffer.dispose(),super.dispose()}destroy(){super.destroy(),this.framebuffer.destroyDepthTexture(),this.framebuffer=null}}class Wg extends bm{constructor(t){const e=t;super(e.naturalWidth||e.videoWidth||e.displayWidth||e.width,e.naturalHeight||e.videoHeight||e.displayHeight||e.height),this.source=t,this.noSubImage=!1}static crossOrigin(t,e,i){void 0!==i||e.startsWith("data:")?!1!==i&&(t.crossOrigin="string"==typeof i?i:"anonymous"):t.crossOrigin=om(e)}upload(t,e,i,s){const r=t.gl,n=e.realWidth,o=e.realHeight;if(s=s||this.source,typeof HTMLImageElement<"u"&&s instanceof HTMLImageElement){if(!s.complete||0===s.naturalWidth)return!1}else if(typeof HTMLVideoElement<"u"&&s instanceof HTMLVideoElement&&s.readyState<=1)return!1;return r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.alphaMode===eh.UNPACK),this.noSubImage||e.target!==r.TEXTURE_2D||i.width!==n||i.height!==o?(i.width=n,i.height=o,r.texImage2D(e.target,0,i.internalFormat,e.format,i.type,s)):r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.format,i.type,s),!0}update(){if(this.destroyed)return;const t=this.source,e=t.naturalWidth||t.videoWidth||t.width,i=t.naturalHeight||t.videoHeight||t.height;this.resize(e,i),super.update()}dispose(){this.source=null}}class Hg extends Wg{constructor(t,e){if(e=e||{},"string"==typeof t){const i=new Image;Wg.crossOrigin(i,t,e.crossorigin),i.src=t,t=i}super(t),!t.complete&&this._width&&this._height&&(this._width=0,this._height=0),this.url=t.src,this._process=null,this.preserveBitmap=!1,this.createBitmap=(e.createBitmap??lh.CREATE_IMAGE_BITMAP)&&!!globalThis.createImageBitmap,this.alphaMode="number"==typeof e.alphaMode?e.alphaMode:null,this.bitmap=null,this._load=null,!1!==e.autoLoad&&this.load()}load(t){return this._load||(void 0!==t&&(this.createBitmap=t),this._load=new Promise(((t,e)=>{const i=this.source;this.url=i.src;const s=()=>{this.destroyed||(i.onload=null,i.onerror=null,this.update(),this._load=null,this.createBitmap?t(this.process()):t(this))};i.complete&&i.src?s():(i.onload=s,i.onerror=t=>{e(t),this.onError.emit(t)})}))),this._load}process(){const t=this.source;if(null!==this._process)return this._process;if(null!==this.bitmap||!globalThis.createImageBitmap)return Promise.resolve(this);const e=globalThis.createImageBitmap,i=!t.crossOrigin||"anonymous"===t.crossOrigin;return this._process=fetch(t.src,{mode:i?"cors":"no-cors"}).then((t=>t.blob())).then((i=>e(i,0,0,t.width,t.height,{premultiplyAlpha:null===this.alphaMode||this.alphaMode===eh.UNPACK?"premultiply":"none"}))).then((t=>this.destroyed?Promise.reject():(this.bitmap=t,this.update(),this._process=null,Promise.resolve(this)))),this._process}upload(t,e,i){if("number"==typeof this.alphaMode&&(e.alphaMode=this.alphaMode),!this.createBitmap)return super.upload(t,e,i);if(!this.bitmap&&(this.process(),!this.bitmap))return!1;if(super.upload(t,e,i,this.bitmap),!this.preserveBitmap){let t=!0;const s=e._glTextures;for(const r in s){const n=s[r];if(n!==i&&n.dirtyId!==e.dirtyId){t=!1;break}}t&&(this.bitmap.close&&this.bitmap.close(),this.bitmap=null)}return!0}dispose(){this.source.onload=null,this.source.onerror=null,super.dispose(),this.bitmap&&(this.bitmap.close(),this.bitmap=null),this._process=null,this._load=null}static test(t){return typeof HTMLImageElement<"u"&&("string"==typeof t||t instanceof HTMLImageElement)}}class Yg{constructor(){this.x0=0,this.y0=0,this.x1=1,this.y1=0,this.x2=1,this.y2=1,this.x3=0,this.y3=1,this.uvsFloat32=new Float32Array(8)}set(t,e,i){const s=e.width,r=e.height;if(i){const e=t.width/2/s,n=t.height/2/r,o=t.x/s+e,a=t.y/r+n;i=tg.add(i,tg.NW),this.x0=o+e*tg.uX(i),this.y0=a+n*tg.uY(i),i=tg.add(i,2),this.x1=o+e*tg.uX(i),this.y1=a+n*tg.uY(i),i=tg.add(i,2),this.x2=o+e*tg.uX(i),this.y2=a+n*tg.uY(i),i=tg.add(i,2),this.x3=o+e*tg.uX(i),this.y3=a+n*tg.uY(i)}else this.x0=t.x/s,this.y0=t.y/r,this.x1=(t.x+t.width)/s,this.y1=t.y/r,this.x2=(t.x+t.width)/s,this.y2=(t.y+t.height)/r,this.x3=t.x/s,this.y3=(t.y+t.height)/r;this.uvsFloat32[0]=this.x0,this.uvsFloat32[1]=this.y0,this.uvsFloat32[2]=this.x1,this.uvsFloat32[3]=this.y1,this.uvsFloat32[4]=this.x2,this.uvsFloat32[5]=this.y2,this.uvsFloat32[6]=this.x3,this.uvsFloat32[7]=this.y3}}Yg.prototype.toString=function(){return`[@pixi/core:TextureUvs x0=${this.x0} y0=${this.y0} x1=${this.x1} y1=${this.y1} x2=${this.x2} y2=${this.y2} x3=${this.x3} y3=${this.y3}]`};const $g=new Yg;function jg(t){t.destroy=function(){},t.on=function(){},t.once=function(){},t.emit=function(){}}class zg extends Sh{constructor(t,e,i,s,r,n,o){if(super(),this.noFrame=!1,e||(this.noFrame=!0,e=new Xm(0,0,1,1)),t instanceof zg&&(t=t.baseTexture),this.baseTexture=t,this._frame=e,this.trim=s,this.valid=!1,this.destroyed=!1,this._uvs=$g,this.uvMatrix=null,this.orig=i||e,this._rotate=Number(r||0),!0===r)this._rotate=2;else if(this._rotate%2!=0)throw new Error("attempt to use diamond-shaped UVs. If you are sure, set rotation manually");this.defaultAnchor=n?new Um(n.x,n.y):new Um(0,0),this.defaultBorders=o,this._updateID=0,this.textureCacheIds=[],t.valid?this.noFrame?t.valid&&this.onBaseTextureUpdated(t):this.frame=e:t.once("loaded",this.onBaseTextureUpdated,this),this.noFrame&&t.on("update",this.onBaseTextureUpdated,this)}update(){this.baseTexture.resource&&this.baseTexture.resource.update()}onBaseTextureUpdated(t){if(this.noFrame){if(!this.baseTexture.valid)return;this._frame.width=t.width,this._frame.height=t.height,this.valid=!0,this.updateUvs()}else this.frame=this._frame;this.emit("update",this)}destroy(t){if(this.baseTexture){if(t){const{resource:t}=this.baseTexture;(null==t?void 0:t.url)&&Zf[t.url]&&zg.removeFromCache(t.url),this.baseTexture.destroy()}this.baseTexture.off("loaded",this.onBaseTextureUpdated,this),this.baseTexture.off("update",this.onBaseTextureUpdated,this),this.baseTexture=null}this._frame=null,this._uvs=null,this.trim=null,this.orig=null,this.valid=!1,zg.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0,this.emit("destroyed",this),this.removeAllListeners()}clone(){var t;const e=this._frame.clone(),i=this._frame===this.orig?e:this.orig.clone(),s=new zg(this.baseTexture,!this.noFrame&&e,i,null==(t=this.trim)?void 0:t.clone(),this.rotate,this.defaultAnchor,this.defaultBorders);return this.noFrame&&(s._frame=e),s}updateUvs(){this._uvs===$g&&(this._uvs=new Yg),this._uvs.set(this._frame,this.baseTexture,this.rotate),this._updateID++}static from(t,e={},i=lh.STRICT_TEXTURE_CACHE){const s="string"==typeof t;let r=null;if(s)r=t;else if(t instanceof Em){if(!t.cacheId){const i=(null==e?void 0:e.pixiIdPrefix)||"pixiid";t.cacheId=`${i}-${Vf()}`,Em.addToCache(t,t.cacheId)}r=t.cacheId}else{if(!t._pixiId){const i=(null==e?void 0:e.pixiIdPrefix)||"pixiid";t._pixiId=`${i}_${Vf()}`}r=t._pixiId}let n=Zf[r];if(s&&i&&!n)throw new Error(`The cacheId "${r}" does not exist in TextureCache.`);return n||t instanceof Em?!n&&t instanceof Em&&(n=new zg(t),zg.addToCache(n,r)):(e.resolution||(e.resolution=am(t)),n=new zg(new Em(t,e)),n.baseTexture.cacheId=r,Em.addToCache(n.baseTexture,r),zg.addToCache(n,r)),n}static fromURL(t,e){const i=Object.assign({autoLoad:!1},null==e?void 0:e.resourceOptions),s=zg.from(t,Object.assign({resourceOptions:i},e),!1),r=s.baseTexture.resource;return s.baseTexture.valid?Promise.resolve(s):r.load().then((()=>Promise.resolve(s)))}static fromBuffer(t,e,i,s){return new zg(Em.fromBuffer(t,e,i,s))}static fromLoader(t,e,i,s){const r=new Em(t,Object.assign({scaleMode:Em.defaultOptions.scaleMode,resolution:am(e)},s)),{resource:n}=r;n instanceof Hg&&(n.url=e);const o=new zg(r);return i||(i=e),Em.addToCache(o.baseTexture,i),zg.addToCache(o,i),i!==e&&(Em.addToCache(o.baseTexture,e),zg.addToCache(o,e)),o.baseTexture.valid?Promise.resolve(o):new Promise((t=>{o.baseTexture.once("loaded",(()=>t(o)))}))}static addToCache(t,e){e&&(t.textureCacheIds.includes(e)||t.textureCacheIds.push(e),Zf[e]&&Zf[e]!==t&&console.warn(`Texture added to the cache with an id [${e}] that already had an entry`),Zf[e]=t)}static removeFromCache(t){if("string"==typeof t){const e=Zf[t];if(e){const i=e.textureCacheIds.indexOf(t);return i>-1&&e.textureCacheIds.splice(i,1),delete Zf[t],e}}else if(null==t?void 0:t.textureCacheIds){for(let e=0;e<t.textureCacheIds.length;++e)Zf[t.textureCacheIds[e]]===t&&delete Zf[t.textureCacheIds[e]];return t.textureCacheIds.length=0,t}return null}get resolution(){return this.baseTexture.resolution}get frame(){return this._frame}set frame(t){this._frame=t,this.noFrame=!1;const{x:e,y:i,width:s,height:r}=t,n=e+s>this.baseTexture.width,o=i+r>this.baseTexture.height;if(n||o){const t=n&&o?"and":"or",a=`X: ${e} + ${s} = ${e+s} > ${this.baseTexture.width}`,l=`Y: ${i} + ${r} = ${i+r} > ${this.baseTexture.height}`;throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions: ${a} ${t} ${l}`)}this.valid=s&&r&&this.baseTexture.valid,!this.trim&&!this.rotate&&(this.orig=t),this.valid&&this.updateUvs()}get rotate(){return this._rotate}set rotate(t){this._rotate=t,this.valid&&this.updateUvs()}get width(){return this.orig.width}get height(){return this.orig.height}castToBaseTexture(){return this.baseTexture}static get EMPTY(){return zg._EMPTY||(zg._EMPTY=new zg(new Em),jg(zg._EMPTY),jg(zg._EMPTY.baseTexture)),zg._EMPTY}static get WHITE(){if(!zg._WHITE){const t=lh.ADAPTER.createCanvas(16,16),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="white",e.fillRect(0,0,16,16),zg._WHITE=new zg(Em.from(t)),jg(zg._WHITE),jg(zg._WHITE.baseTexture)}return zg._WHITE}}class Vg extends zg{constructor(t,e){super(t,e),this.valid=!0,this.filterFrame=null,this.filterPoolKey=null,this.updateUvs()}get framebuffer(){return this.baseTexture.framebuffer}get multisample(){return this.framebuffer.multisample}set multisample(t){this.framebuffer.multisample=t}resize(t,e,i=!0){const s=this.baseTexture.resolution,r=Math.round(t*s)/s,n=Math.round(e*s)/s;this.valid=r>0&&n>0,this._frame.width=this.orig.width=r,this._frame.height=this.orig.height=n,i&&this.baseTexture.resize(r,n),this.updateUvs()}setResolution(t){const{baseTexture:e}=this;e.resolution!==t&&(e.setResolution(t),this.resize(e.width,e.height,!1))}static create(t){return new Vg(new Xg(t))}}class qg{constructor(t){this.texturePool={},this.textureOptions=t||{},this.enableFullScreen=!1,this._pixelsWidth=0,this._pixelsHeight=0}createTexture(t,e,i=oh.NONE){const s=new Xg(Object.assign({width:t,height:e,resolution:1,multisample:i},this.textureOptions));return new Vg(s)}getOptimalTexture(t,e,i=1,s=oh.NONE){let r;t=Math.max(Math.ceil(t*i-1e-6),1),e=Math.max(Math.ceil(e*i-1e-6),1),this.enableFullScreen&&t===this._pixelsWidth&&e===this._pixelsHeight?r=s>1?-s:-1:(r=((65535&(t=Wf(t)))<<16|65535&(e=Wf(e)))>>>0,s>1&&(r+=4294967296*s)),this.texturePool[r]||(this.texturePool[r]=[]);let n=this.texturePool[r].pop();return n||(n=this.createTexture(t,e,s)),n.filterPoolKey=r,n.setResolution(i),n}getFilterTexture(t,e,i){const s=this.getOptimalTexture(t.width,t.height,e||t.resolution,i||oh.NONE);return s.filterFrame=t.filterFrame,s}returnTexture(t){const e=t.filterPoolKey;t.filterFrame=null,this.texturePool[e].push(t)}returnFilterTexture(t){this.returnTexture(t)}clear(t){if(t=!1!==t)for(const e in this.texturePool){const t=this.texturePool[e];if(t)for(let e=0;e<t.length;e++)t[e].destroy(!0)}this.texturePool={}}setScreenSize(t){if(t.width!==this._pixelsWidth||t.height!==this._pixelsHeight){this.enableFullScreen=t.width>0&&t.height>0;for(const t in this.texturePool){if(!(Number(t)<0))continue;const e=this.texturePool[t];if(e)for(let t=0;t<e.length;t++)e[t].destroy(!0);this.texturePool[t]=[]}this._pixelsWidth=t.width,this._pixelsHeight=t.height}}}qg.SCREEN_KEY=-1;class Jg extends Lm{constructor(){super(),this.addAttribute("aVertexPosition",new Float32Array([0,0,1,0,1,1,0,1])).addIndex([0,1,3,2])}}class Kg extends Lm{constructor(){super(),this.vertices=new Float32Array([-1,-1,1,-1,1,1,-1,1]),this.uvs=new Float32Array([0,0,1,0,1,1,0,1]),this.vertexBuffer=new Im(this.vertices),this.uvBuffer=new Im(this.uvs),this.addAttribute("aVertexPosition",this.vertexBuffer).addAttribute("aTextureCoord",this.uvBuffer).addIndex([0,1,2,0,2,3])}map(t,e){let i=0,s=0;return this.uvs[0]=i,this.uvs[1]=s,this.uvs[2]=i+e.width/t.width,this.uvs[3]=s,this.uvs[4]=i+e.width/t.width,this.uvs[5]=s+e.height/t.height,this.uvs[6]=i,this.uvs[7]=s+e.height/t.height,i=e.x,s=e.y,this.vertices[0]=i,this.vertices[1]=s,this.vertices[2]=i+e.width,this.vertices[3]=s,this.vertices[4]=i+e.width,this.vertices[5]=s+e.height,this.vertices[6]=i,this.vertices[7]=s+e.height,this.invalidate(),this}invalidate(){return this.vertexBuffer._updateID++,this.uvBuffer._updateID++,this}}class Zg{constructor(){this.renderTexture=null,this.target=null,this.legacy=!1,this.resolution=1,this.multisample=oh.NONE,this.sourceFrame=new Xm,this.destinationFrame=new Xm,this.bindingSourceFrame=new Xm,this.bindingDestinationFrame=new Xm,this.filters=[],this.transform=null}clear(){this.target=null,this.filters=null,this.renderTexture=null}}const Qg=[new Um,new Um,new Um,new Um],ty=new jm;class ey{constructor(t){this.renderer=t,this.defaultFilterStack=[{}],this.texturePool=new qg,this.statePool=[],this.quad=new Jg,this.quadUv=new Kg,this.tempRect=new Xm,this.activeState={},this.globalUniforms=new Ig({outputFrame:new Xm,inputSize:new Float32Array(4),inputPixel:new Float32Array(4),inputClamp:new Float32Array(4),resolution:1,filterArea:new Float32Array(4),filterClamp:new Float32Array(4)},!0),this.forceClear=!1,this.useMaxPadding=!1}init(){this.texturePool.setScreenSize(this.renderer.view)}push(t,e){const i=this.renderer,s=this.defaultFilterStack,r=this.statePool.pop()||new Zg,n=i.renderTexture;let o,a;if(n.current){const t=n.current;o=t.resolution,a=t.multisample}else o=i.resolution,a=i.multisample;let l=e[0].resolution||o,h=e[0].multisample??a,u=e[0].padding,c=e[0].autoFit,d=e[0].legacy??!0;for(let m=1;m<e.length;m++){const t=e[m];l=Math.min(l,t.resolution||o),h=Math.min(h,t.multisample??a),u=this.useMaxPadding?Math.max(u,t.padding):u+t.padding,c=c&&t.autoFit,d=d||(t.legacy??!0)}1===s.length&&(this.defaultFilterStack[0].renderTexture=n.current),s.push(r),r.resolution=l,r.multisample=h,r.legacy=d,r.target=t,r.sourceFrame.copyFrom(t.filterArea||t.getBounds(!0)),r.sourceFrame.pad(u);const p=this.tempRect.copyFrom(n.sourceFrame);i.projection.transform&&this.transformAABB(ty.copyFrom(i.projection.transform).invert(),p),c?(r.sourceFrame.fit(p),(r.sourceFrame.width<=0||r.sourceFrame.height<=0)&&(r.sourceFrame.width=0,r.sourceFrame.height=0)):r.sourceFrame.intersects(p)||(r.sourceFrame.width=0,r.sourceFrame.height=0),this.roundFrame(r.sourceFrame,n.current?n.current.resolution:i.resolution,n.sourceFrame,n.destinationFrame,i.projection.transform),r.renderTexture=this.getOptimalFilterTexture(r.sourceFrame.width,r.sourceFrame.height,l,h),r.filters=e,r.destinationFrame.width=r.renderTexture.width,r.destinationFrame.height=r.renderTexture.height;const f=this.tempRect;f.x=0,f.y=0,f.width=r.sourceFrame.width,f.height=r.sourceFrame.height,r.renderTexture.filterFrame=r.sourceFrame,r.bindingSourceFrame.copyFrom(n.sourceFrame),r.bindingDestinationFrame.copyFrom(n.destinationFrame),r.transform=i.projection.transform,i.projection.transform=null,n.bind(r.renderTexture,r.sourceFrame,f),i.framebuffer.clear(0,0,0,0)}pop(){const t=this.defaultFilterStack,e=t.pop(),i=e.filters;this.activeState=e;const s=this.globalUniforms.uniforms;s.outputFrame=e.sourceFrame,s.resolution=e.resolution;const r=s.inputSize,n=s.inputPixel,o=s.inputClamp;if(r[0]=e.destinationFrame.width,r[1]=e.destinationFrame.height,r[2]=1/r[0],r[3]=1/r[1],n[0]=Math.round(r[0]*e.resolution),n[1]=Math.round(r[1]*e.resolution),n[2]=1/n[0],n[3]=1/n[1],o[0]=.5*n[2],o[1]=.5*n[3],o[2]=e.sourceFrame.width*r[2]-.5*n[2],o[3]=e.sourceFrame.height*r[3]-.5*n[3],e.legacy){const t=s.filterArea;t[0]=e.destinationFrame.width,t[1]=e.destinationFrame.height,t[2]=e.sourceFrame.x,t[3]=e.sourceFrame.y,s.filterClamp=s.inputClamp}this.globalUniforms.update();const a=t[t.length-1];if(this.renderer.framebuffer.blit(),1===i.length)i[0].apply(this,e.renderTexture,a.renderTexture,ih.BLEND,e),this.returnFilterTexture(e.renderTexture);else{let t=e.renderTexture,s=this.getOptimalFilterTexture(t.width,t.height,e.resolution);s.filterFrame=t.filterFrame;let r=0;for(r=0;r<i.length-1;++r){1===r&&e.multisample>1&&(s=this.getOptimalFilterTexture(t.width,t.height,e.resolution),s.filterFrame=t.filterFrame),i[r].apply(this,t,s,ih.CLEAR,e);const n=t;t=s,s=n}i[r].apply(this,t,a.renderTexture,ih.BLEND,e),r>1&&e.multisample>1&&this.returnFilterTexture(e.renderTexture),this.returnFilterTexture(t),this.returnFilterTexture(s)}e.clear(),this.statePool.push(e)}bindAndClear(t,e=ih.CLEAR){const{renderTexture:i,state:s}=this.renderer;if(t===this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?this.renderer.projection.transform=this.activeState.transform:this.renderer.projection.transform=null,null==t?void 0:t.filterFrame){const e=this.tempRect;e.x=0,e.y=0,e.width=t.filterFrame.width,e.height=t.filterFrame.height,i.bind(t,t.filterFrame,e)}else t!==this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?i.bind(t):this.renderer.renderTexture.bind(t,this.activeState.bindingSourceFrame,this.activeState.bindingDestinationFrame);const r=1&s.stateId||this.forceClear;(e===ih.CLEAR||e===ih.BLIT&&r)&&this.renderer.framebuffer.clear(0,0,0,0)}applyFilter(t,e,i,s){const r=this.renderer;r.state.set(t.state),this.bindAndClear(i,s),t.uniforms.uSampler=e,t.uniforms.filterGlobals=this.globalUniforms,r.shader.bind(t),t.legacy=!!t.program.attributeData.aTextureCoord,t.legacy?(this.quadUv.map(e._frame,e.filterFrame),r.geometry.bind(this.quadUv),r.geometry.draw(zl.TRIANGLES)):(r.geometry.bind(this.quad),r.geometry.draw(zl.TRIANGLE_STRIP))}calculateSpriteMatrix(t,e){const{sourceFrame:i,destinationFrame:s}=this.activeState,{orig:r}=e._texture,n=t.set(s.width,0,0,s.height,i.x,i.y),o=e.worldTransform.copyTo(jm.TEMP_MATRIX);return o.invert(),n.prepend(o),n.scale(1/r.width,1/r.height),n.translate(e.anchor.x,e.anchor.y),n}destroy(){this.renderer=null,this.texturePool.clear(!1)}getOptimalFilterTexture(t,e,i=1,s=oh.NONE){return this.texturePool.getOptimalTexture(t,e,i,s)}getFilterTexture(t,e,i){if("number"==typeof t){const i=t;t=e,e=i}t=t||this.activeState.renderTexture;const s=this.texturePool.getOptimalTexture(t.width,t.height,e||t.resolution,i||oh.NONE);return s.filterFrame=t.filterFrame,s}returnFilterTexture(t){this.texturePool.returnTexture(t)}emptyPool(){this.texturePool.clear(!0)}resize(){this.texturePool.setScreenSize(this.renderer.view)}transformAABB(t,e){const i=Qg[0],s=Qg[1],r=Qg[2],n=Qg[3];i.set(e.left,e.top),s.set(e.left,e.bottom),r.set(e.right,e.top),n.set(e.right,e.bottom),t.apply(i,i),t.apply(s,s),t.apply(r,r),t.apply(n,n);const o=Math.min(i.x,s.x,r.x,n.x),a=Math.min(i.y,s.y,r.y,n.y),l=Math.max(i.x,s.x,r.x,n.x),h=Math.max(i.y,s.y,r.y,n.y);e.x=o,e.y=a,e.width=l-o,e.height=h-a}roundFrame(t,e,i,s,r){if(!(t.width<=0||t.height<=0||i.width<=0||i.height<=0)){if(r){const{a:t,b:e,c:i,d:s}=r;if((Math.abs(e)>1e-4||Math.abs(i)>1e-4)&&(Math.abs(t)>1e-4||Math.abs(s)>1e-4))return}(r=r?ty.copyFrom(r):ty.identity()).translate(-i.x,-i.y).scale(s.width/i.width,s.height/i.height).translate(s.x,s.y),this.transformAABB(r,t),t.ceil(e),this.transformAABB(r.invert(),t)}}}ey.extension={type:hm.RendererSystem,name:"filter"},dm.add(ey);class iy{constructor(t){this.framebuffer=t,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=oh.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}}const sy=new Xm;class ry{constructor(t){this.renderer=t,this.managedFramebuffers=[],this.unknownFramebuffer=new Gg(10,10),this.msaaSamples=null}contextChange(){this.disposeAll(!0);const t=this.gl=this.renderer.gl;if(this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.current=this.unknownFramebuffer,this.viewport=new Xm,this.hasMRT=!0,this.writeDepthTexture=!0,1===this.renderer.context.webGLVersion){let e=this.renderer.context.extensions.drawBuffers,i=this.renderer.context.extensions.depthTexture;lh.PREFER_ENV===Hl.WEBGL_LEGACY&&(e=null,i=null),e?t.drawBuffers=t=>e.drawBuffersWEBGL(t):(this.hasMRT=!1,t.drawBuffers=()=>{}),i||(this.writeDepthTexture=!1)}else this.msaaSamples=t.getInternalformatParameter(t.RENDERBUFFER,t.RGBA8,t.SAMPLES)}bind(t,e,i=0){const{gl:s}=this;if(t){const r=t.glFramebuffers[this.CONTEXT_UID]||this.initFramebuffer(t);this.current!==t&&(this.current=t,s.bindFramebuffer(s.FRAMEBUFFER,r.framebuffer)),r.mipLevel!==i&&(t.dirtyId++,t.dirtyFormat++,r.mipLevel=i),r.dirtyId!==t.dirtyId&&(r.dirtyId=t.dirtyId,r.dirtyFormat!==t.dirtyFormat?(r.dirtyFormat=t.dirtyFormat,r.dirtySize=t.dirtySize,this.updateFramebuffer(t,i)):r.dirtySize!==t.dirtySize&&(r.dirtySize=t.dirtySize,this.resizeFramebuffer(t)));for(let e=0;e<t.colorTextures.length;e++){const i=t.colorTextures[e];this.renderer.texture.unbind(i.parentTextureArray||i)}if(t.depthTexture&&this.renderer.texture.unbind(t.depthTexture),e){const t=e.width>>i,s=e.height>>i,r=t/e.width;this.setViewport(e.x*r,e.y*r,t,s)}else{const e=t.width>>i,s=t.height>>i;this.setViewport(0,0,e,s)}}else this.current&&(this.current=null,s.bindFramebuffer(s.FRAMEBUFFER,null)),e?this.setViewport(e.x,e.y,e.width,e.height):this.setViewport(0,0,this.renderer.width,this.renderer.height)}setViewport(t,e,i,s){const r=this.viewport;t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s),(r.width!==i||r.height!==s||r.x!==t||r.y!==e)&&(r.x=t,r.y=e,r.width=i,r.height=s,this.gl.viewport(t,e,i,s))}get size(){return this.current?{x:0,y:0,width:this.current.width,height:this.current.height}:{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}clear(t,e,i,s,r=$l.COLOR|$l.DEPTH){const{gl:n}=this;n.clearColor(t,e,i,s),n.clear(r)}initFramebuffer(t){const{gl:e}=this,i=new iy(e.createFramebuffer());return i.multisample=this.detectSamples(t.multisample),t.glFramebuffers[this.CONTEXT_UID]=i,this.managedFramebuffers.push(t),t.disposeRunner.add(this),i}resizeFramebuffer(t){const{gl:e}=this,i=t.glFramebuffers[this.CONTEXT_UID];if(i.stencil){let s;e.bindRenderbuffer(e.RENDERBUFFER,i.stencil),s=1===this.renderer.context.webGLVersion?e.DEPTH_STENCIL:t.depth&&t.stencil?e.DEPTH24_STENCIL8:t.depth?e.DEPTH_COMPONENT24:e.STENCIL_INDEX8,i.msaaBuffer?e.renderbufferStorageMultisample(e.RENDERBUFFER,i.multisample,s,t.width,t.height):e.renderbufferStorage(e.RENDERBUFFER,s,t.width,t.height)}const s=t.colorTextures;let r=s.length;e.drawBuffers||(r=Math.min(r,1));for(let n=0;n<r;n++){const r=s[n],o=r.parentTextureArray||r;this.renderer.texture.bind(o,0),0===n&&i.msaaBuffer&&(e.bindRenderbuffer(e.RENDERBUFFER,i.msaaBuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,i.multisample,o._glTextures[this.CONTEXT_UID].internalFormat,t.width,t.height))}t.depthTexture&&this.writeDepthTexture&&this.renderer.texture.bind(t.depthTexture,0)}updateFramebuffer(t,e){const{gl:i}=this,s=t.glFramebuffers[this.CONTEXT_UID],r=t.colorTextures;let n=r.length;i.drawBuffers||(n=Math.min(n,1)),s.multisample>1&&this.canMultisampleFramebuffer(t)?s.msaaBuffer=s.msaaBuffer||i.createRenderbuffer():s.msaaBuffer&&(i.deleteRenderbuffer(s.msaaBuffer),s.msaaBuffer=null,s.blitFramebuffer&&(s.blitFramebuffer.dispose(),s.blitFramebuffer=null));const o=[];for(let a=0;a<n;a++){const n=r[a],l=n.parentTextureArray||n;this.renderer.texture.bind(l,0),0===a&&s.msaaBuffer?(i.bindRenderbuffer(i.RENDERBUFFER,s.msaaBuffer),i.renderbufferStorageMultisample(i.RENDERBUFFER,s.multisample,l._glTextures[this.CONTEXT_UID].internalFormat,t.width,t.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,s.msaaBuffer)):(i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+a,n.target,l._glTextures[this.CONTEXT_UID].texture,e),o.push(i.COLOR_ATTACHMENT0+a))}if(o.length>1&&i.drawBuffers(o),t.depthTexture&&this.writeDepthTexture){const s=t.depthTexture;this.renderer.texture.bind(s,0),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,s._glTextures[this.CONTEXT_UID].texture,e)}if(!t.stencil&&!t.depth||t.depthTexture&&this.writeDepthTexture)s.stencil&&(i.deleteRenderbuffer(s.stencil),s.stencil=null);else{let e,r;s.stencil=s.stencil||i.createRenderbuffer(),1===this.renderer.context.webGLVersion?(e=i.DEPTH_STENCIL_ATTACHMENT,r=i.DEPTH_STENCIL):t.depth&&t.stencil?(e=i.DEPTH_STENCIL_ATTACHMENT,r=i.DEPTH24_STENCIL8):t.depth?(e=i.DEPTH_ATTACHMENT,r=i.DEPTH_COMPONENT24):(e=i.STENCIL_ATTACHMENT,r=i.STENCIL_INDEX8),i.bindRenderbuffer(i.RENDERBUFFER,s.stencil),s.msaaBuffer?i.renderbufferStorageMultisample(i.RENDERBUFFER,s.multisample,r,t.width,t.height):i.renderbufferStorage(i.RENDERBUFFER,r,t.width,t.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,e,i.RENDERBUFFER,s.stencil)}}canMultisampleFramebuffer(t){return 1!==this.renderer.context.webGLVersion&&t.colorTextures.length<=1&&!t.depthTexture}detectSamples(t){const{msaaSamples:e}=this;let i=oh.NONE;if(t<=1||null===e)return i;for(let s=0;s<e.length;s++)if(e[s]<=t){i=e[s];break}return 1===i&&(i=oh.NONE),i}blit(t,e,i){const{current:s,renderer:r,gl:n,CONTEXT_UID:o}=this;if(2!==r.context.webGLVersion||!s)return;const a=s.glFramebuffers[o];if(!a)return;if(!t){if(!a.msaaBuffer)return;const e=s.colorTextures[0];if(!e)return;a.blitFramebuffer||(a.blitFramebuffer=new Gg(s.width,s.height),a.blitFramebuffer.addColorTexture(0,e)),(t=a.blitFramebuffer).colorTextures[0]!==e&&(t.colorTextures[0]=e,t.dirtyId++,t.dirtyFormat++),(t.width!==s.width||t.height!==s.height)&&(t.width=s.width,t.height=s.height,t.dirtyId++,t.dirtySize++)}e||((e=sy).width=s.width,e.height=s.height),i||(i=e);const l=e.width===i.width&&e.height===i.height;this.bind(t),n.bindFramebuffer(n.READ_FRAMEBUFFER,a.framebuffer),n.blitFramebuffer(e.left,e.top,e.right,e.bottom,i.left,i.top,i.right,i.bottom,n.COLOR_BUFFER_BIT,l?n.NEAREST:n.LINEAR),n.bindFramebuffer(n.READ_FRAMEBUFFER,t.glFramebuffers[this.CONTEXT_UID].framebuffer)}disposeFramebuffer(t,e){const i=t.glFramebuffers[this.CONTEXT_UID],s=this.gl;if(!i)return;delete t.glFramebuffers[this.CONTEXT_UID];const r=this.managedFramebuffers.indexOf(t);r>=0&&this.managedFramebuffers.splice(r,1),t.disposeRunner.remove(this),e||(s.deleteFramebuffer(i.framebuffer),i.msaaBuffer&&s.deleteRenderbuffer(i.msaaBuffer),i.stencil&&s.deleteRenderbuffer(i.stencil)),i.blitFramebuffer&&this.disposeFramebuffer(i.blitFramebuffer,e)}disposeAll(t){const e=this.managedFramebuffers;this.managedFramebuffers=[];for(let i=0;i<e.length;i++)this.disposeFramebuffer(e[i],t)}forceStencil(){const t=this.current;if(!t)return;const e=t.glFramebuffers[this.CONTEXT_UID];if(!e||e.stencil&&t.stencil)return;t.stencil=!0;const i=t.width,s=t.height,r=this.gl,n=e.stencil=r.createRenderbuffer();let o,a;r.bindRenderbuffer(r.RENDERBUFFER,n),1===this.renderer.context.webGLVersion?(o=r.DEPTH_STENCIL_ATTACHMENT,a=r.DEPTH_STENCIL):t.depth?(o=r.DEPTH_STENCIL_ATTACHMENT,a=r.DEPTH24_STENCIL8):(o=r.STENCIL_ATTACHMENT,a=r.STENCIL_INDEX8),e.msaaBuffer?r.renderbufferStorageMultisample(r.RENDERBUFFER,e.multisample,a,i,s):r.renderbufferStorage(r.RENDERBUFFER,a,i,s),r.framebufferRenderbuffer(r.FRAMEBUFFER,o,r.RENDERBUFFER,n)}reset(){this.current=this.unknownFramebuffer,this.viewport=new Xm}destroy(){this.renderer=null}}ry.extension={type:hm.RendererSystem,name:"framebuffer"},dm.add(ry);const ny={5126:4,5123:2,5121:1};class oy{constructor(t){this.renderer=t,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this.canUseUInt32ElementIndex=!1,this.managedGeometries={}}contextChange(){this.disposeAll(!0);const t=this.gl=this.renderer.gl,e=this.renderer.context;if(this.CONTEXT_UID=this.renderer.CONTEXT_UID,2!==e.webGLVersion){let e=this.renderer.context.extensions.vertexArrayObject;lh.PREFER_ENV===Hl.WEBGL_LEGACY&&(e=null),e?(t.createVertexArray=()=>e.createVertexArrayOES(),t.bindVertexArray=t=>e.bindVertexArrayOES(t),t.deleteVertexArray=t=>e.deleteVertexArrayOES(t)):(this.hasVao=!1,t.createVertexArray=()=>null,t.bindVertexArray=()=>null,t.deleteVertexArray=()=>null)}if(2!==e.webGLVersion){const e=t.getExtension("ANGLE_instanced_arrays");e?(t.vertexAttribDivisor=(t,i)=>e.vertexAttribDivisorANGLE(t,i),t.drawElementsInstanced=(t,i,s,r,n)=>e.drawElementsInstancedANGLE(t,i,s,r,n),t.drawArraysInstanced=(t,i,s,r)=>e.drawArraysInstancedANGLE(t,i,s,r)):this.hasInstance=!1}this.canUseUInt32ElementIndex=2===e.webGLVersion||!!e.extensions.uint32ElementIndex}bind(t,e){e=e||this.renderer.shader.shader;const{gl:i}=this;let s=t.glVertexArrayObjects[this.CONTEXT_UID],r=!1;s||(this.managedGeometries[t.id]=t,t.disposeRunner.add(this),t.glVertexArrayObjects[this.CONTEXT_UID]=s={},r=!0);const n=s[e.program.id]||this.initGeometryVao(t,e,r);this._activeGeometry=t,this._activeVao!==n&&(this._activeVao=n,this.hasVao?i.bindVertexArray(n):this.activateVao(t,e.program)),this.updateBuffers()}reset(){this.unbind()}updateBuffers(){const t=this._activeGeometry,e=this.renderer.buffer;for(let i=0;i<t.buffers.length;i++){const s=t.buffers[i];e.update(s)}}checkCompatibility(t,e){const i=t.attributes,s=e.attributeData;for(const r in s)if(!i[r])throw new Error(`shader and geometry incompatible, geometry missing the "${r}" attribute`)}getSignature(t,e){const i=t.attributes,s=e.attributeData,r=["g",t.id];for(const n in i)s[n]&&r.push(n,s[n].location);return r.join("-")}initGeometryVao(t,e,i=!0){const s=this.gl,r=this.CONTEXT_UID,n=this.renderer.buffer,o=e.program;o.glPrograms[r]||this.renderer.shader.generateProgram(e),this.checkCompatibility(t,o);const a=this.getSignature(t,o),l=t.glVertexArrayObjects[this.CONTEXT_UID];let h=l[a];if(h)return l[o.id]=h,h;const u=t.buffers,c=t.attributes,d={},p={};for(const f in u)d[f]=0,p[f]=0;for(const f in c)!c[f].size&&o.attributeData[f]?c[f].size=o.attributeData[f].size:c[f].size||console.warn(`PIXI Geometry attribute '${f}' size cannot be determined (likely the bound shader does not have the attribute)`),d[c[f].buffer]+=c[f].size*ny[c[f].type];for(const f in c){const t=c[f],e=t.size;void 0===t.stride&&(d[t.buffer]===e*ny[t.type]?t.stride=0:t.stride=d[t.buffer]),void 0===t.start&&(t.start=p[t.buffer],p[t.buffer]+=e*ny[t.type])}h=s.createVertexArray(),s.bindVertexArray(h);for(let f=0;f<u.length;f++){const t=u[f];n.bind(t),i&&t._glBuffers[r].refCount++}return this.activateVao(t,o),l[o.id]=h,l[a]=h,s.bindVertexArray(null),n.unbind(ah.ARRAY_BUFFER),h}disposeGeometry(t,e){var i;if(!this.managedGeometries[t.id])return;delete this.managedGeometries[t.id];const s=t.glVertexArrayObjects[this.CONTEXT_UID],r=this.gl,n=t.buffers,o=null==(i=this.renderer)?void 0:i.buffer;if(t.disposeRunner.remove(this),s){if(o)for(let t=0;t<n.length;t++){const i=n[t]._glBuffers[this.CONTEXT_UID];i&&(i.refCount--,0===i.refCount&&!e&&o.dispose(n[t],e))}if(!e)for(const t in s)if("g"===t[0]){const e=s[t];this._activeVao===e&&this.unbind(),r.deleteVertexArray(e)}delete t.glVertexArrayObjects[this.CONTEXT_UID]}}disposeAll(t){const e=Object.keys(this.managedGeometries);for(let i=0;i<e.length;i++)this.disposeGeometry(this.managedGeometries[e[i]],t)}activateVao(t,e){const i=this.gl,s=this.CONTEXT_UID,r=this.renderer.buffer,n=t.buffers,o=t.attributes;t.indexBuffer&&r.bind(t.indexBuffer);let a=null;for(const l in o){const t=o[l],h=n[t.buffer],u=h._glBuffers[s];if(e.attributeData[l]){a!==u&&(r.bind(h),a=u);const s=e.attributeData[l].location;if(i.enableVertexAttribArray(s),i.vertexAttribPointer(s,t.size,t.type||i.FLOAT,t.normalized,t.stride,t.start),t.instance){if(!this.hasInstance)throw new Error("geometry error, GPU Instancing is not supported on this device");i.vertexAttribDivisor(s,t.divisor)}}}}draw(t,e,i,s){const{gl:r}=this,n=this._activeGeometry;if(n.indexBuffer){const o=n.indexBuffer.data.BYTES_PER_ELEMENT,a=2===o?r.UNSIGNED_SHORT:r.UNSIGNED_INT;2===o||4===o&&this.canUseUInt32ElementIndex?n.instanced?r.drawElementsInstanced(t,e||n.indexBuffer.data.length,a,(i||0)*o,s||1):r.drawElements(t,e||n.indexBuffer.data.length,a,(i||0)*o):console.warn("unsupported index buffer type: uint32")}else n.instanced?r.drawArraysInstanced(t,i,e||n.getSize(),s||1):r.drawArrays(t,i,e||n.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this.renderer=null}}oy.extension={type:hm.RendererSystem,name:"geometry"},dm.add(oy);const ay=new jm;class ly{constructor(t,e){this._texture=t,this.mapCoord=new jm,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,this.clampMargin=typeof e>"u"?.5:e,this.isSimple=!1}get texture(){return this._texture}set texture(t){this._texture=t,this._textureID=-1}multiplyUvs(t,e){void 0===e&&(e=t);const i=this.mapCoord;for(let s=0;s<t.length;s+=2){const r=t[s],n=t[s+1];e[s]=r*i.a+n*i.c+i.tx,e[s+1]=r*i.b+n*i.d+i.ty}return e}update(t){const e=this._texture;if(!e||!e.valid||!t&&this._textureID===e._updateID)return!1;this._textureID=e._updateID,this._updateID++;const i=e._uvs;this.mapCoord.set(i.x1-i.x0,i.y1-i.y0,i.x3-i.x0,i.y3-i.y0,i.x0,i.y0);const s=e.orig,r=e.trim;r&&(ay.set(s.width/r.width,0,0,s.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(ay));const n=e.baseTexture,o=this.uClampFrame,a=this.clampMargin/n.resolution,l=this.clampOffset;return o[0]=(e._frame.x+a+l)/n.width,o[1]=(e._frame.y+a+l)/n.height,o[2]=(e._frame.x+e._frame.width-a+l)/n.width,o[3]=(e._frame.y+e._frame.height-a+l)/n.height,this.uClampOffset[0]=l/n.realWidth,this.uClampOffset[1]=l/n.realHeight,this.isSimple=e._frame.width===n.width&&e._frame.height===n.height&&0===e.rotate,!0}}class hy extends kg{constructor(t,e,i){let s=null;"string"!=typeof t&&void 0===e&&void 0===i&&(s=t,t=void 0,e=void 0,i=void 0),super(t||"attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 otherMatrix;\n\nvarying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vMaskCoord = ( otherMatrix * vec3( aTextureCoord, 1.0) ).xy;\n}\n",e||"varying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform sampler2D mask;\nuniform float alpha;\nuniform float npmAlpha;\nuniform vec4 maskClamp;\n\nvoid main(void)\n{\n float clip = step(3.5,\n step(maskClamp.x, vMaskCoord.x) +\n step(maskClamp.y, vMaskCoord.y) +\n step(vMaskCoord.x, maskClamp.z) +\n step(vMaskCoord.y, maskClamp.w));\n\n vec4 original = texture2D(uSampler, vTextureCoord);\n vec4 masky = texture2D(mask, vMaskCoord);\n float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);\n\n original *= (alphaMul * masky.r * alpha * clip);\n\n gl_FragColor = original;\n}\n",i),this.maskSprite=s,this.maskMatrix=new jm}get maskSprite(){return this._maskSprite}set maskSprite(t){this._maskSprite=t,this._maskSprite&&(this._maskSprite.renderable=!1)}apply(t,e,i,s){const r=this._maskSprite,n=r._texture;n.valid&&(n.uvMatrix||(n.uvMatrix=new ly(n,0)),n.uvMatrix.update(),this.uniforms.npmAlpha=n.baseTexture.alphaMode?0:1,this.uniforms.mask=n,this.uniforms.otherMatrix=t.calculateSpriteMatrix(this.maskMatrix,r).prepend(n.uvMatrix.mapCoord),this.uniforms.alpha=r.worldAlpha,this.uniforms.maskClamp=n.uvMatrix.uClampFrame,t.applyFilter(this,e,i,s))}}class uy{constructor(t=null){this.type=nh.NONE,this.autoDetect=!0,this.maskObject=t||null,this.pooled=!1,this.isMaskData=!0,this.resolution=null,this.multisample=kg.defaultMultisample,this.enabled=!0,this.colorMask=15,this._filters=null,this._stencilCounter=0,this._scissorCounter=0,this._scissorRect=null,this._scissorRectLocal=null,this._colorMask=15,this._target=null}get filter(){return this._filters?this._filters[0]:null}set filter(t){t?this._filters?this._filters[0]=t:this._filters=[t]:this._filters=null}reset(){this.pooled&&(this.maskObject=null,this.type=nh.NONE,this.autoDetect=!0),this._target=null,this._scissorRectLocal=null}copyCountersOrReset(t){t?(this._stencilCounter=t._stencilCounter,this._scissorCounter=t._scissorCounter,this._scissorRect=t._scissorRect):(this._stencilCounter=0,this._scissorCounter=0,this._scissorRect=null)}}class cy{constructor(t){this.renderer=t,this.enableScissor=!0,this.alphaMaskPool=[],this.maskDataPool=[],this.maskStack=[],this.alphaMaskIndex=0}setMaskStack(t){this.maskStack=t,this.renderer.scissor.setMaskStack(t),this.renderer.stencil.setMaskStack(t)}push(t,e){let i=e;if(!i.isMaskData){const t=this.maskDataPool.pop()||new uy;t.pooled=!0,t.maskObject=e,i=t}const s=0!==this.maskStack.length?this.maskStack[this.maskStack.length-1]:null;if(i.copyCountersOrReset(s),i._colorMask=s?s._colorMask:15,i.autoDetect&&this.detect(i),i._target=t,i.type!==nh.SPRITE&&this.maskStack.push(i),i.enabled)switch(i.type){case nh.SCISSOR:this.renderer.scissor.push(i);break;case nh.STENCIL:this.renderer.stencil.push(i);break;case nh.SPRITE:i.copyCountersOrReset(null),this.pushSpriteMask(i);break;case nh.COLOR:this.pushColorMask(i)}i.type===nh.SPRITE&&this.maskStack.push(i)}pop(t){const e=this.maskStack.pop();if(e&&e._target===t){if(e.enabled)switch(e.type){case nh.SCISSOR:this.renderer.scissor.pop(e);break;case nh.STENCIL:this.renderer.stencil.pop(e.maskObject);break;case nh.SPRITE:this.popSpriteMask(e);break;case nh.COLOR:this.popColorMask(e)}if(e.reset(),e.pooled&&this.maskDataPool.push(e),0!==this.maskStack.length){const t=this.maskStack[this.maskStack.length-1];t.type===nh.SPRITE&&t._filters&&(t._filters[0].maskSprite=t.maskObject)}}}detect(t){const e=t.maskObject;e?e.isSprite?t.type=nh.SPRITE:this.enableScissor&&this.renderer.scissor.testScissor(t)?t.type=nh.SCISSOR:t.type=nh.STENCIL:t.type=nh.COLOR}pushSpriteMask(t){const{maskObject:e}=t,i=t._target;let s=t._filters;s||(s=this.alphaMaskPool[this.alphaMaskIndex],s||(s=this.alphaMaskPool[this.alphaMaskIndex]=[new hy])),s[0].resolution=t.resolution,s[0].multisample=t.multisample,s[0].maskSprite=e;const r=i.filterArea;i.filterArea=e.getBounds(!0),this.renderer.filter.push(i,s),i.filterArea=r,t._filters||this.alphaMaskIndex++}popSpriteMask(t){this.renderer.filter.pop(),t._filters?t._filters[0].maskSprite=null:(this.alphaMaskIndex--,this.alphaMaskPool[this.alphaMaskIndex][0].maskSprite=null)}pushColorMask(t){const e=t._colorMask,i=t._colorMask=e&t.colorMask;i!==e&&this.renderer.gl.colorMask(!!(1&i),!!(2&i),!!(4&i),!!(8&i))}popColorMask(t){const e=t._colorMask,i=this.maskStack.length>0?this.maskStack[this.maskStack.length-1]._colorMask:15;i!==e&&this.renderer.gl.colorMask(!!(1&i),!!(2&i),!!(4&i),!!(8&i))}destroy(){this.renderer=null}}cy.extension={type:hm.RendererSystem,name:"mask"},dm.add(cy);class dy{constructor(t){this.renderer=t,this.maskStack=[],this.glConst=0}getStackLength(){return this.maskStack.length}setMaskStack(t){const{gl:e}=this.renderer,i=this.getStackLength();this.maskStack=t;const s=this.getStackLength();s!==i&&(0===s?e.disable(this.glConst):(e.enable(this.glConst),this._useCurrent()))}_useCurrent(){}destroy(){this.renderer=null,this.maskStack=null}}const py=new jm,fy=[],my=class t extends dy{constructor(t){super(t),this.glConst=lh.ADAPTER.getWebGLRenderingContext().SCISSOR_TEST}getStackLength(){const t=this.maskStack[this.maskStack.length-1];return t?t._scissorCounter:0}calcScissorRect(t){if(t._scissorRectLocal)return;const e=t._scissorRect,{maskObject:i}=t,{renderer:s}=this,r=s.renderTexture,n=i.getBounds(!0,fy.pop()??new Xm);this.roundFrameToPixels(n,r.current?r.current.resolution:s.resolution,r.sourceFrame,r.destinationFrame,s.projection.transform),e&&n.fit(e),t._scissorRectLocal=n}static isMatrixRotated(t){if(!t)return!1;const{a:e,b:i,c:s,d:r}=t;return(Math.abs(i)>1e-4||Math.abs(s)>1e-4)&&(Math.abs(e)>1e-4||Math.abs(r)>1e-4)}testScissor(e){const{maskObject:i}=e;if(!i.isFastRect||!i.isFastRect()||t.isMatrixRotated(i.worldTransform)||t.isMatrixRotated(this.renderer.projection.transform))return!1;this.calcScissorRect(e);const s=e._scissorRectLocal;return s.width>0&&s.height>0}roundFrameToPixels(e,i,s,r,n){t.isMatrixRotated(n)||((n=n?py.copyFrom(n):py.identity()).translate(-s.x,-s.y).scale(r.width/s.width,r.height/s.height).translate(r.x,r.y),this.renderer.filter.transformAABB(n,e),e.fit(r),e.x=Math.round(e.x*i),e.y=Math.round(e.y*i),e.width=Math.round(e.width*i),e.height=Math.round(e.height*i))}push(t){t._scissorRectLocal||this.calcScissorRect(t);const{gl:e}=this.renderer;t._scissorRect||e.enable(e.SCISSOR_TEST),t._scissorCounter++,t._scissorRect=t._scissorRectLocal,this._useCurrent()}pop(t){const{gl:e}=this.renderer;t&&fy.push(t._scissorRectLocal),this.getStackLength()>0?this._useCurrent():e.disable(e.SCISSOR_TEST)}_useCurrent(){const t=this.maskStack[this.maskStack.length-1]._scissorRect;let e;e=this.renderer.renderTexture.current?t.y:this.renderer.height-t.height-t.y,this.renderer.gl.scissor(t.x,e,t.width,t.height)}};my.extension={type:hm.RendererSystem,name:"scissor"};let gy=my;dm.add(gy);class yy extends dy{constructor(t){super(t),this.glConst=lh.ADAPTER.getWebGLRenderingContext().STENCIL_TEST}getStackLength(){const t=this.maskStack[this.maskStack.length-1];return t?t._stencilCounter:0}push(t){const e=t.maskObject,{gl:i}=this.renderer,s=t._stencilCounter;0===s&&(this.renderer.framebuffer.forceStencil(),i.clearStencil(0),i.clear(i.STENCIL_BUFFER_BIT),i.enable(i.STENCIL_TEST)),t._stencilCounter++;const r=t._colorMask;0!==r&&(t._colorMask=0,i.colorMask(!1,!1,!1,!1)),i.stencilFunc(i.EQUAL,s,4294967295),i.stencilOp(i.KEEP,i.KEEP,i.INCR),e.renderable=!0,e.render(this.renderer),this.renderer.batch.flush(),e.renderable=!1,0!==r&&(t._colorMask=r,i.colorMask(!!(1&r),!!(2&r),!!(4&r),!!(8&r))),this._useCurrent()}pop(t){const e=this.renderer.gl;if(0===this.getStackLength())e.disable(e.STENCIL_TEST);else{const i=0!==this.maskStack.length?this.maskStack[this.maskStack.length-1]:null,s=i?i._colorMask:15;0!==s&&(i._colorMask=0,e.colorMask(!1,!1,!1,!1)),e.stencilOp(e.KEEP,e.KEEP,e.DECR),t.renderable=!0,t.render(this.renderer),this.renderer.batch.flush(),t.renderable=!1,0!==s&&(i._colorMask=s,e.colorMask(!!(1&s),!!(2&s),!!(4&s),!!(8&s))),this._useCurrent()}}_useCurrent(){const t=this.renderer.gl;t.stencilFunc(t.EQUAL,this.getStackLength(),4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP)}}yy.extension={type:hm.RendererSystem,name:"stencil"},dm.add(yy);class vy{constructor(t){this.renderer=t,this.plugins={},Object.defineProperties(this.plugins,{extract:{enumerable:!1,get:()=>(Qp("7.0.0","renderer.plugins.extract has moved to renderer.extract"),t.extract)},prepare:{enumerable:!1,get:()=>(Qp("7.0.0","renderer.plugins.prepare has moved to renderer.prepare"),t.prepare)},interaction:{enumerable:!1,get:()=>(Qp("7.0.0","renderer.plugins.interaction has been deprecated, use renderer.events"),t.events)}})}init(){const t=this.rendererPlugins;for(const e in t)this.plugins[e]=new t[e](this.renderer)}destroy(){for(const t in this.plugins)this.plugins[t].destroy(),this.plugins[t]=null}}vy.extension={type:[hm.RendererSystem,hm.CanvasRendererSystem],name:"_plugin"},dm.add(vy);class xy{constructor(t){this.renderer=t,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new jm,this.transform=null}update(t,e,i,s){this.destinationFrame=t||this.destinationFrame||this.defaultFrame,this.sourceFrame=e||this.sourceFrame||t,this.calculateProjection(this.destinationFrame,this.sourceFrame,i,s),this.transform&&this.projectionMatrix.append(this.transform);const r=this.renderer;r.globalUniforms.uniforms.projectionMatrix=this.projectionMatrix,r.globalUniforms.update(),r.shader.shader&&r.shader.syncUniformGroup(r.shader.shader.uniforms.globals)}calculateProjection(t,e,i,s){const r=this.projectionMatrix,n=s?-1:1;r.identity(),r.a=1/e.width*2,r.d=n*(1/e.height*2),r.tx=-1-e.x*r.a,r.ty=-n-e.y*r.d}setTransform(t){}destroy(){this.renderer=null}}xy.extension={type:hm.RendererSystem,name:"projection"},dm.add(xy);const by=new sg,_y=new Xm;class wy{constructor(t){this.renderer=t,this._tempMatrix=new jm}generateTexture(t,e){const{region:i,...s}=e||{},r=(null==i?void 0:i.copyTo(_y))||t.getLocalBounds(_y,!0),n=s.resolution||this.renderer.resolution;r.width=Math.max(r.width,1/n),r.height=Math.max(r.height,1/n),s.width=r.width,s.height=r.height,s.resolution=n,s.multisample??(s.multisample=this.renderer.multisample);const o=Vg.create(s);this._tempMatrix.tx=-r.x,this._tempMatrix.ty=-r.y;const a=t.transform;return t.transform=by,this.renderer.render(t,{renderTexture:o,transform:this._tempMatrix,skipUpdateTransform:!!t.parent,blit:!0}),t.transform=a,o}destroy(){}}wy.extension={type:[hm.RendererSystem,hm.CanvasRendererSystem],name:"textureGenerator"},dm.add(wy);const Py=new Xm,Ey=new Xm;class Ty{constructor(t){this.renderer=t,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new Xm,this.destinationFrame=new Xm,this.viewportFrame=new Xm}contextChange(){var t;const e=null==(t=this.renderer)?void 0:t.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(e&&e.alpha&&e.premultipliedAlpha)}bind(t=null,e,i){const s=this.renderer;let r,n,o;this.current=t,t?(r=t.baseTexture,o=r.resolution,e||(Py.width=t.frame.width,Py.height=t.frame.height,e=Py),i||(Ey.x=t.frame.x,Ey.y=t.frame.y,Ey.width=e.width,Ey.height=e.height,i=Ey),n=r.framebuffer):(o=s.resolution,e||(Py.width=s._view.screen.width,Py.height=s._view.screen.height,e=Py),i||((i=Py).width=e.width,i.height=e.height));const a=this.viewportFrame;a.x=i.x*o,a.y=i.y*o,a.width=i.width*o,a.height=i.height*o,t||(a.y=s.view.height-(a.y+a.height)),a.ceil(),this.renderer.framebuffer.bind(n,a),this.renderer.projection.update(i,e,o,!n),t?this.renderer.mask.setMaskStack(r.maskStack):this.renderer.mask.setMaskStack(this.defaultMaskStack),this.sourceFrame.copyFrom(e),this.destinationFrame.copyFrom(i)}clear(t,e){const i=this.current?this.current.baseTexture.clear:this.renderer.background.backgroundColor,s=Ff.shared.setValue(t||i);(this.current&&this.current.baseTexture.alphaMode>0||!this.current&&this._rendererPremultipliedAlpha)&&s.premultiply(s.alpha);const r=this.destinationFrame,n=this.current?this.current.baseTexture:this.renderer._view.screen,o=r.width!==n.width||r.height!==n.height;if(o){let{x:t,y:e,width:i,height:s}=this.viewportFrame;t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s),this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST),this.renderer.gl.scissor(t,e,i,s)}this.renderer.framebuffer.clear(s.red,s.green,s.blue,s.alpha,e),o&&this.renderer.scissor.pop()}resize(){this.bind(null)}reset(){this.bind(null)}destroy(){this.renderer=null}}Ty.extension={type:hm.RendererSystem,name:"renderTexture"},dm.add(Ty);class Ay{constructor(t,e){this.program=t,this.uniformData=e,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBufferBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBufferBindings=null,this.program=null}}function Iy(t,e){var i;const s=rg(t,t.VERTEX_SHADER,e.vertexSrc),r=rg(t,t.FRAGMENT_SHADER,e.fragmentSrc),n=t.createProgram();t.attachShader(n,s),t.attachShader(n,r);const o=null==(i=e.extra)?void 0:i.transformFeedbackVaryings;if(o&&("function"!=typeof t.transformFeedbackVaryings?console.warn("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(n,o.names,"separate"===o.bufferMode?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(n),t.getProgramParameter(n,t.LINK_STATUS)||function(t,e,i,s){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(i,t.COMPILE_STATUS)||fg(t,i),t.getShaderParameter(s,t.COMPILE_STATUS)||fg(t,s),console.error("PixiJS Error: Could not initialize shader."),""!==t.getProgramInfoLog(e)&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}(t,n,s,r),e.attributeData=function(t,e){const i={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r<s;r++){const s=e.getActiveAttrib(t,r);if(s.name.startsWith("gl_"))continue;const n=xg(e,s.type),o={type:n,name:s.name,size:gg(n),location:e.getAttribLocation(t,s.name)};i[s.name]=o}return i}(n,t),e.uniformData=function(t,e){const i={},s=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){const s=e.getActiveUniform(t,r),n=s.name.replace(/\[.*?\]$/,""),o=!!s.name.match(/\[.*?\]$/),a=xg(e,s.type);i[n]={name:n,index:r,type:a,size:s.size,isArray:o,value:og(a,s.size)}}return i}(n,t),!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertexSrc)){const i=Object.keys(e.attributeData);i.sort(((t,e)=>t>e?1:-1));for(let s=0;s<i.length;s++)e.attributeData[i[s]].location=s,t.bindAttribLocation(n,s,i[s]);t.linkProgram(n)}t.deleteShader(s),t.deleteShader(r);const a={};for(const l in e.uniformData){const i=e.uniformData[l];a[l]={location:t.getUniformLocation(n,l),value:og(i.type,i.size)}}return new Ay(n,a)}function Sy(t,e,i,s,r){i.buffer.update(r)}const Cy={float:"\n data[offset] = v;\n ",vec2:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n ",vec3:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n\n ",vec4:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n data[offset+3] = v[3];\n ",mat2:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n\n data[offset+4] = v[2];\n data[offset+5] = v[3];\n ",mat3:"\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n\n data[offset + 4] = v[3];\n data[offset + 5] = v[4];\n data[offset + 6] = v[5];\n\n data[offset + 8] = v[6];\n data[offset + 9] = v[7];\n data[offset + 10] = v[8];\n ",mat4:"\n for(var i = 0; i < 16; i++)\n {\n data[offset + i] = v[i];\n }\n "},My={float:4,vec2:8,vec3:12,vec4:16,int:4,ivec2:8,ivec3:12,ivec4:16,uint:4,uvec2:8,uvec3:12,uvec4:16,bool:4,bvec2:8,bvec3:12,bvec4:16,mat2:32,mat3:48,mat4:64};function Oy(t,e){if(!t.autoManage)return{size:0,syncFunc:Sy};const i=function(t,e){const i=[];for(const s in t)e[s]&&i.push(e[s]);return i.sort(((t,e)=>t.index-e.index)),i}(t.uniforms,e),{uboElements:s,size:r}=function(t){const e=t.map((t=>({data:t,offset:0,dataLen:0,dirty:0})));let i=0,s=0,r=0;for(let n=0;n<e.length;n++){const t=e[n];if(i=My[t.data.type],t.data.size>1&&(i=Math.max(i,16)*t.data.size),t.dataLen=i,s%i!=0&&s<16){const t=s%i%16;s+=t,r+=t}s+i>16?(r=16*Math.ceil(r/16),t.offset=r,r+=i,s=i):(t.offset=r,s+=i,r+=i)}return r=16*Math.ceil(r/16),{uboElements:e,size:r}}(i),n=["\n var v = null;\n var v2 = null;\n var cv = null;\n var t = 0;\n var gl = renderer.gl\n var index = 0;\n var data = buffer.data;\n "];for(let o=0;o<s.length;o++){const e=s[o],i=t.uniforms[e.data.name],r=e.data.name;let a=!1;for(let t=0;t<ag.length;t++){const s=ag[t];if(s.codeUbo&&s.test(e.data,i)){n.push(`offset = ${e.offset/4};`,ag[t].codeUbo(e.data.name,i)),a=!0;break}}if(!a)if(e.data.size>1){const t=gg(e.data.type),i=Math.max(My[e.data.type]/16,1),s=t/i,o=(4-s%4)%4;n.push(`\n cv = ud.${r}.value;\n v = uv.${r};\n offset = ${e.offset/4};\n\n t = 0;\n\n for(var i=0; i < ${e.data.size*i}; i++)\n {\n for(var j = 0; j < ${s}; j++)\n {\n data[offset++] = v[t++];\n }\n offset += ${o};\n }\n\n `)}else{const t=Cy[e.data.type];n.push(`\n cv = ud.${r}.value;\n v = uv.${r};\n offset = ${e.offset/4};\n ${t};\n `)}}return n.push("\n renderer.buffer.update(buffer);\n "),{size:r,syncFunc:new Function("ud","uv","renderer","syncData","buffer",n.join("\n"))}}let Ny=0;const Ly={textureCount:0,uboCount:0};class Ry{constructor(t){this.destroyed=!1,this.renderer=t,this.systemCheck(),this.gl=null,this.shader=null,this.program=null,this.cache={},this._uboCache={},this.id=Ny++}systemCheck(){if(!function(){if("boolean"==typeof _g)return _g;try{_g=!0===new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")}catch{_g=!1}return _g}())throw new Error("Current environment does not allow unsafe-eval, please use @pixi/unsafe-eval module to enable support.")}contextChange(t){this.gl=t,this.reset()}bind(t,e){t.disposeRunner.add(this),t.uniforms.globals=this.renderer.globalUniforms;const i=t.program,s=i.glPrograms[this.renderer.CONTEXT_UID]||this.generateProgram(t);return this.shader=t,this.program!==i&&(this.program=i,this.gl.useProgram(s.program)),e||(Ly.textureCount=0,Ly.uboCount=0,this.syncUniformGroup(t.uniformGroup,Ly)),s}setUniforms(t){const e=this.shader.program,i=e.glPrograms[this.renderer.CONTEXT_UID];e.syncUniforms(i.uniformData,t,this.renderer)}syncUniformGroup(t,e){const i=this.getGlProgram();(!t.static||t.dirtyId!==i.uniformDirtyGroups[t.id])&&(i.uniformDirtyGroups[t.id]=t.dirtyId,this.syncUniforms(t,i,e))}syncUniforms(t,e,i){(t.syncUniforms[this.shader.program.id]||this.createSyncGroups(t))(e.uniformData,t.uniforms,this.renderer,i)}createSyncGroups(t){const e=this.getSignature(t,this.shader.program.uniformData,"u");return this.cache[e]||(this.cache[e]=function(t,e){var i;const s=["\n var v = null;\n var cv = null;\n var cu = null;\n var t = 0;\n var gl = renderer.gl;\n "];for(const r in t.uniforms){const n=e[r];if(!n){!0===(null==(i=t.uniforms[r])?void 0:i.group)&&(t.uniforms[r].ubo?s.push(`\n renderer.shader.syncUniformBufferGroup(uv.${r}, '${r}');\n `):s.push(`\n renderer.shader.syncUniformGroup(uv.${r}, syncData);\n `));continue}const o=t.uniforms[r];let a=!1;for(let t=0;t<ag.length;t++)if(ag[t].test(n,o)){s.push(ag[t].code(r,o)),a=!0;break}if(!a){const t=(1!==n.size||n.isArray?hg:lg)[n.type].replace("location",`ud["${r}"].location`);s.push(`\n cu = ud["${r}"];\n cv = cu.value;\n v = uv["${r}"];\n ${t};`)}}return new Function("ud","uv","renderer","syncData",s.join("\n"))}(t,this.shader.program.uniformData)),t.syncUniforms[this.shader.program.id]=this.cache[e],t.syncUniforms[this.shader.program.id]}syncUniformBufferGroup(t,e){const i=this.getGlProgram();if(!t.static||0!==t.dirtyId||!i.uniformGroups[t.id]){t.dirtyId=0;const s=i.uniformGroups[t.id]||this.createSyncBufferGroup(t,i,e);t.buffer.update(),s(i.uniformData,t.uniforms,this.renderer,Ly,t.buffer)}this.renderer.buffer.bindBufferBase(t.buffer,i.uniformBufferBindings[e])}createSyncBufferGroup(t,e,i){const{gl:s}=this.renderer;this.renderer.buffer.bind(t.buffer);const r=this.gl.getUniformBlockIndex(e.program,i);e.uniformBufferBindings[i]=this.shader.uniformBindCount,s.uniformBlockBinding(e.program,r,this.shader.uniformBindCount),this.shader.uniformBindCount++;const n=this.getSignature(t,this.shader.program.uniformData,"ubo");let o=this._uboCache[n];if(o||(o=this._uboCache[n]=Oy(t,this.shader.program.uniformData)),t.autoManage){const e=new Float32Array(o.size/4);t.buffer.update(e)}return e.uniformGroups[t.id]=o.syncFunc,e.uniformGroups[t.id]}getSignature(t,e,i){const s=t.uniforms,r=[`${i}-`];for(const n in s)r.push(n),e[n]&&r.push(e[n].type);return r.join("-")}getGlProgram(){return this.shader?this.shader.program.glPrograms[this.renderer.CONTEXT_UID]:null}generateProgram(t){const e=this.gl,i=t.program,s=Iy(e,i);return i.glPrograms[this.renderer.CONTEXT_UID]=s,s}reset(){this.program=null,this.shader=null}disposeShader(t){this.shader===t&&(this.shader=null)}destroy(){this.renderer=null,this.destroyed=!0}}Ry.extension={type:hm.RendererSystem,name:"shader"},dm.add(Ry);class ky{constructor(t){this.renderer=t}run(t){const{renderer:e}=this;e.runners.init.emit(e.options),t.hello&&console.log(`PixiJS 7.4.2 - ${e.rendererLogId} - https://pixijs.com`),e.resize(e.screen.width,e.screen.height)}destroy(){}}ky.defaultOptions={hello:!1},ky.extension={type:[hm.RendererSystem,hm.CanvasRendererSystem],name:"startup"},dm.add(ky);const By=class t{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode=jl.NONE,this._blendEq=!1,this.map=[],this.map[0]=this.setBlend,this.map[1]=this.setOffset,this.map[2]=this.setCullFace,this.map[3]=this.setDepthTest,this.map[4]=this.setFrontFace,this.map[5]=this.setDepthMask,this.checks=[],this.defaultState=new gm,this.defaultState.blend=!0}contextChange(t){this.gl=t,this.blendModes=function(t,e=[]){return e[jl.NORMAL]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.ADD]=[t.ONE,t.ONE],e[jl.MULTIPLY]=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SCREEN]=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.OVERLAY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.DARKEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.LIGHTEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.COLOR_DODGE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.COLOR_BURN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.HARD_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SOFT_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.DIFFERENCE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.EXCLUSION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.HUE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SATURATION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.COLOR]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.LUMINOSITY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.NONE]=[0,0],e[jl.NORMAL_NPM]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.ADD_NPM]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e[jl.SCREEN_NPM]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[jl.SRC_IN]=[t.DST_ALPHA,t.ZERO],e[jl.SRC_OUT]=[t.ONE_MINUS_DST_ALPHA,t.ZERO],e[jl.SRC_ATOP]=[t.DST_ALPHA,t.ONE_MINUS_SRC_ALPHA],e[jl.DST_OVER]=[t.ONE_MINUS_DST_ALPHA,t.ONE],e[jl.DST_IN]=[t.ZERO,t.SRC_ALPHA],e[jl.DST_OUT]=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],e[jl.DST_ATOP]=[t.ONE_MINUS_DST_ALPHA,t.SRC_ALPHA],e[jl.XOR]=[t.ONE_MINUS_DST_ALPHA,t.ONE_MINUS_SRC_ALPHA],e[jl.SUBTRACT]=[t.ONE,t.ONE,t.ONE,t.ONE,t.FUNC_REVERSE_SUBTRACT,t.FUNC_ADD],e}(t),this.set(this.defaultState),this.reset()}set(t){if(t=t||this.defaultState,this.stateId!==t.data){let e=this.stateId^t.data,i=0;for(;e;)1&e&&this.map[i].call(this,!!(t.data&1<<i)),e>>=1,i++;this.stateId=t.data}for(let e=0;e<this.checks.length;e++)this.checks[e](this,t)}forceState(t){t=t||this.defaultState;for(let e=0;e<this.map.length;e++)this.map[e].call(this,!!(t.data&1<<e));for(let e=0;e<this.checks.length;e++)this.checks[e](this,t);this.stateId=t.data}setBlend(e){this.updateCheck(t.checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this.updateCheck(t.checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(t){this.gl[t?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(t){this.gl.depthMask(t)}setCullFace(t){this.gl[t?"enable":"disable"](this.gl.CULL_FACE)}setFrontFace(t){this.gl.frontFace(this.gl[t?"CW":"CCW"])}setBlendMode(t){if(t===this.blendMode)return;this.blendMode=t;const e=this.blendModes[t],i=this.gl;2===e.length?i.blendFunc(e[0],e[1]):i.blendFuncSeparate(e[0],e[1],e[2],e[3]),6===e.length?(this._blendEq=!0,i.blendEquationSeparate(e[4],e[5])):this._blendEq&&(this._blendEq=!1,i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD))}setPolygonOffset(t,e){this.gl.polygonOffset(t,e)}reset(){this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode=-1,this.setBlendMode(0)}updateCheck(t,e){const i=this.checks.indexOf(t);e&&-1===i?this.checks.push(t):!e&&-1!==i&&this.checks.splice(i,1)}static checkBlendMode(t,e){t.setBlendMode(e.blendMode)}static checkPolygonOffset(t,e){t.setPolygonOffset(1,e.polygonOffset)}destroy(){this.gl=null}};By.extension={type:hm.RendererSystem,name:"state"};let Fy=By;dm.add(Fy);class Dy extends Sh{constructor(){super(...arguments),this.runners={},this._systemsHash={}}setup(t){this.addRunners(...t.runners);const e=(t.priority??[]).filter((e=>t.systems[e])),i=[...e,...Object.keys(t.systems).filter((t=>!e.includes(t)))];for(const s of i)this.addSystem(t.systems[s],s)}addRunners(...t){t.forEach((t=>{this.runners[t]=new xm(t)}))}addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const s in this.runners)this.runners[s].add(i);return this}emitWithCustomOptions(t,e){const i=Object.keys(this._systemsHash);t.items.forEach((s=>{const r=i.find((t=>this._systemsHash[t]===s));s[t.name](e[r])}))}destroy(){Object.values(this.runners).forEach((t=>{t.destroy()})),this._systemsHash={}}}const Uy=class t{constructor(e){this.renderer=e,this.count=0,this.checkCount=0,this.maxIdle=t.defaultMaxIdle,this.checkCountMax=t.defaultCheckCountMax,this.mode=t.defaultMode}postrender(){this.renderer.objectRenderer.renderingToScreen&&(this.count++,this.mode!==sh.MANUAL&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const t=this.renderer.texture,e=t.managedTextures;let i=!1;for(let s=0;s<e.length;s++){const r=e[s];r.resource&&this.count-r.touched>this.maxIdle&&(t.destroyTexture(r,!0),e[s]=null,i=!0)}if(i){let t=0;for(let i=0;i<e.length;i++)null!==e[i]&&(e[t++]=e[i]);e.length=t}}unload(t){const e=this.renderer.texture,i=t._texture;i&&!i.framebuffer&&e.destroyTexture(i);for(let s=t.children.length-1;s>=0;s--)this.unload(t.children[s])}destroy(){this.renderer=null}};Uy.defaultMode=sh.AUTO,Uy.defaultMaxIdle=3600,Uy.defaultCheckCountMax=600,Uy.extension={type:hm.RendererSystem,name:"textureGC"};let Gy=Uy;dm.add(Gy);class Xy{constructor(t){this.texture=t,this.width=-1,this.height=-1,this.dirtyId=-1,this.dirtyStyleId=-1,this.mipmap=!1,this.wrapMode=33071,this.type=Jl.UNSIGNED_BYTE,this.internalFormat=Vl.RGBA,this.samplerType=0}}class Wy{constructor(t){this.renderer=t,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new Em,this.hasIntegerTextures=!1}contextChange(){const t=this.gl=this.renderer.gl;this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.webGLVersion=this.renderer.context.webGLVersion,this.internalFormats=function(t){let e;return e="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext?{[Jl.UNSIGNED_BYTE]:{[Vl.RGBA]:t.RGBA8,[Vl.RGB]:t.RGB8,[Vl.RG]:t.RG8,[Vl.RED]:t.R8,[Vl.RGBA_INTEGER]:t.RGBA8UI,[Vl.RGB_INTEGER]:t.RGB8UI,[Vl.RG_INTEGER]:t.RG8UI,[Vl.RED_INTEGER]:t.R8UI,[Vl.ALPHA]:t.ALPHA,[Vl.LUMINANCE]:t.LUMINANCE,[Vl.LUMINANCE_ALPHA]:t.LUMINANCE_ALPHA},[Jl.BYTE]:{[Vl.RGBA]:t.RGBA8_SNORM,[Vl.RGB]:t.RGB8_SNORM,[Vl.RG]:t.RG8_SNORM,[Vl.RED]:t.R8_SNORM,[Vl.RGBA_INTEGER]:t.RGBA8I,[Vl.RGB_INTEGER]:t.RGB8I,[Vl.RG_INTEGER]:t.RG8I,[Vl.RED_INTEGER]:t.R8I},[Jl.UNSIGNED_SHORT]:{[Vl.RGBA_INTEGER]:t.RGBA16UI,[Vl.RGB_INTEGER]:t.RGB16UI,[Vl.RG_INTEGER]:t.RG16UI,[Vl.RED_INTEGER]:t.R16UI,[Vl.DEPTH_COMPONENT]:t.DEPTH_COMPONENT16},[Jl.SHORT]:{[Vl.RGBA_INTEGER]:t.RGBA16I,[Vl.RGB_INTEGER]:t.RGB16I,[Vl.RG_INTEGER]:t.RG16I,[Vl.RED_INTEGER]:t.R16I},[Jl.UNSIGNED_INT]:{[Vl.RGBA_INTEGER]:t.RGBA32UI,[Vl.RGB_INTEGER]:t.RGB32UI,[Vl.RG_INTEGER]:t.RG32UI,[Vl.RED_INTEGER]:t.R32UI,[Vl.DEPTH_COMPONENT]:t.DEPTH_COMPONENT24},[Jl.INT]:{[Vl.RGBA_INTEGER]:t.RGBA32I,[Vl.RGB_INTEGER]:t.RGB32I,[Vl.RG_INTEGER]:t.RG32I,[Vl.RED_INTEGER]:t.R32I},[Jl.FLOAT]:{[Vl.RGBA]:t.RGBA32F,[Vl.RGB]:t.RGB32F,[Vl.RG]:t.RG32F,[Vl.RED]:t.R32F,[Vl.DEPTH_COMPONENT]:t.DEPTH_COMPONENT32F},[Jl.HALF_FLOAT]:{[Vl.RGBA]:t.RGBA16F,[Vl.RGB]:t.RGB16F,[Vl.RG]:t.RG16F,[Vl.RED]:t.R16F},[Jl.UNSIGNED_SHORT_5_6_5]:{[Vl.RGB]:t.RGB565},[Jl.UNSIGNED_SHORT_4_4_4_4]:{[Vl.RGBA]:t.RGBA4},[Jl.UNSIGNED_SHORT_5_5_5_1]:{[Vl.RGBA]:t.RGB5_A1},[Jl.UNSIGNED_INT_2_10_10_10_REV]:{[Vl.RGBA]:t.RGB10_A2,[Vl.RGBA_INTEGER]:t.RGB10_A2UI},[Jl.UNSIGNED_INT_10F_11F_11F_REV]:{[Vl.RGB]:t.R11F_G11F_B10F},[Jl.UNSIGNED_INT_5_9_9_9_REV]:{[Vl.RGB]:t.RGB9_E5},[Jl.UNSIGNED_INT_24_8]:{[Vl.DEPTH_STENCIL]:t.DEPTH24_STENCIL8},[Jl.FLOAT_32_UNSIGNED_INT_24_8_REV]:{[Vl.DEPTH_STENCIL]:t.DEPTH32F_STENCIL8}}:{[Jl.UNSIGNED_BYTE]:{[Vl.RGBA]:t.RGBA,[Vl.RGB]:t.RGB,[Vl.ALPHA]:t.ALPHA,[Vl.LUMINANCE]:t.LUMINANCE,[Vl.LUMINANCE_ALPHA]:t.LUMINANCE_ALPHA},[Jl.UNSIGNED_SHORT_5_6_5]:{[Vl.RGB]:t.RGB},[Jl.UNSIGNED_SHORT_4_4_4_4]:{[Vl.RGBA]:t.RGBA},[Jl.UNSIGNED_SHORT_5_5_5_1]:{[Vl.RGBA]:t.RGBA}},e}(t),this.samplerTypes=function(t){let e;return e="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext?{[t.RGB]:Kl.FLOAT,[t.RGBA]:Kl.FLOAT,[t.ALPHA]:Kl.FLOAT,[t.LUMINANCE]:Kl.FLOAT,[t.LUMINANCE_ALPHA]:Kl.FLOAT,[t.R8]:Kl.FLOAT,[t.R8_SNORM]:Kl.FLOAT,[t.RG8]:Kl.FLOAT,[t.RG8_SNORM]:Kl.FLOAT,[t.RGB8]:Kl.FLOAT,[t.RGB8_SNORM]:Kl.FLOAT,[t.RGB565]:Kl.FLOAT,[t.RGBA4]:Kl.FLOAT,[t.RGB5_A1]:Kl.FLOAT,[t.RGBA8]:Kl.FLOAT,[t.RGBA8_SNORM]:Kl.FLOAT,[t.RGB10_A2]:Kl.FLOAT,[t.RGB10_A2UI]:Kl.FLOAT,[t.SRGB8]:Kl.FLOAT,[t.SRGB8_ALPHA8]:Kl.FLOAT,[t.R16F]:Kl.FLOAT,[t.RG16F]:Kl.FLOAT,[t.RGB16F]:Kl.FLOAT,[t.RGBA16F]:Kl.FLOAT,[t.R32F]:Kl.FLOAT,[t.RG32F]:Kl.FLOAT,[t.RGB32F]:Kl.FLOAT,[t.RGBA32F]:Kl.FLOAT,[t.R11F_G11F_B10F]:Kl.FLOAT,[t.RGB9_E5]:Kl.FLOAT,[t.R8I]:Kl.INT,[t.R8UI]:Kl.UINT,[t.R16I]:Kl.INT,[t.R16UI]:Kl.UINT,[t.R32I]:Kl.INT,[t.R32UI]:Kl.UINT,[t.RG8I]:Kl.INT,[t.RG8UI]:Kl.UINT,[t.RG16I]:Kl.INT,[t.RG16UI]:Kl.UINT,[t.RG32I]:Kl.INT,[t.RG32UI]:Kl.UINT,[t.RGB8I]:Kl.INT,[t.RGB8UI]:Kl.UINT,[t.RGB16I]:Kl.INT,[t.RGB16UI]:Kl.UINT,[t.RGB32I]:Kl.INT,[t.RGB32UI]:Kl.UINT,[t.RGBA8I]:Kl.INT,[t.RGBA8UI]:Kl.UINT,[t.RGBA16I]:Kl.INT,[t.RGBA16UI]:Kl.UINT,[t.RGBA32I]:Kl.INT,[t.RGBA32UI]:Kl.UINT,[t.DEPTH_COMPONENT16]:Kl.FLOAT,[t.DEPTH_COMPONENT24]:Kl.FLOAT,[t.DEPTH_COMPONENT32F]:Kl.FLOAT,[t.DEPTH_STENCIL]:Kl.FLOAT,[t.DEPTH24_STENCIL8]:Kl.FLOAT,[t.DEPTH32F_STENCIL8]:Kl.FLOAT}:{[t.RGB]:Kl.FLOAT,[t.RGBA]:Kl.FLOAT,[t.ALPHA]:Kl.FLOAT,[t.LUMINANCE]:Kl.FLOAT,[t.LUMINANCE_ALPHA]:Kl.FLOAT,[t.DEPTH_STENCIL]:Kl.FLOAT},e}(t);const e=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=e;for(let s=0;s<e;s++)this.boundTextures[s]=null;this.emptyTextures={};const i=new Xy(t.createTexture());t.bindTexture(t.TEXTURE_2D,i.texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array(4)),this.emptyTextures[t.TEXTURE_2D]=i,this.emptyTextures[t.TEXTURE_CUBE_MAP]=new Xy(t.createTexture()),t.bindTexture(t.TEXTURE_CUBE_MAP,this.emptyTextures[t.TEXTURE_CUBE_MAP].texture);for(let s=0;s<6;s++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+s,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,null);t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR);for(let s=0;s<this.boundTextures.length;s++)this.bind(null,s)}bind(t,e=0){const{gl:i}=this;if((null==(t=null==t?void 0:t.castToBaseTexture())?void 0:t.valid)&&!t.parentTextureArray){t.touched=this.renderer.textureGC.count;const s=t._glTextures[this.CONTEXT_UID]||this.initTexture(t);this.boundTextures[e]!==t&&(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(t.target,s.texture)),s.dirtyId!==t.dirtyId?(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),this.updateTexture(t)):s.dirtyStyleId!==t.dirtyStyleId&&this.updateTextureStyle(t),this.boundTextures[e]=t}else this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,this.emptyTextures[i.TEXTURE_2D].texture),this.boundTextures[e]=null}reset(){this._unknownBoundTextures=!0,this.hasIntegerTextures=!1,this.currentLocation=-1;for(let t=0;t<this.boundTextures.length;t++)this.boundTextures[t]=this.unknownTexture}unbind(t){const{gl:e,boundTextures:i}=this;if(this._unknownBoundTextures){this._unknownBoundTextures=!1;for(let t=0;t<i.length;t++)i[t]===this.unknownTexture&&this.bind(null,t)}for(let s=0;s<i.length;s++)i[s]===t&&(this.currentLocation!==s&&(e.activeTexture(e.TEXTURE0+s),this.currentLocation=s),e.bindTexture(t.target,this.emptyTextures[t.target].texture),i[s]=null)}ensureSamplerType(t){const{boundTextures:e,hasIntegerTextures:i,CONTEXT_UID:s}=this;if(i)for(let r=t-1;r>=0;--r){const t=e[r];t&&t._glTextures[s].samplerType!==Kl.FLOAT&&this.renderer.texture.unbind(t)}}initTexture(t){const e=new Xy(this.gl.createTexture());return e.dirtyId=-1,t._glTextures[this.CONTEXT_UID]=e,this.managedTextures.push(t),t.on("dispose",this.destroyTexture,this),e}initTextureType(t,e){var i;e.internalFormat=(null==(i=this.internalFormats[t.type])?void 0:i[t.format])??t.format,e.samplerType=this.samplerTypes[e.internalFormat]??Kl.FLOAT,2===this.webGLVersion&&t.type===Jl.HALF_FLOAT?e.type=this.gl.HALF_FLOAT:e.type=t.type}updateTexture(t){var e;const i=t._glTextures[this.CONTEXT_UID];if(!i)return;const s=this.renderer;if(this.initTextureType(t,i),null==(e=t.resource)?void 0:e.upload(s,t,i))i.samplerType!==Kl.FLOAT&&(this.hasIntegerTextures=!0);else{const e=t.realWidth,r=t.realHeight,n=s.gl;(i.width!==e||i.height!==r||i.dirtyId<0)&&(i.width=e,i.height=r,n.texImage2D(t.target,0,i.internalFormat,e,r,0,t.format,i.type,null))}t.dirtyStyleId!==i.dirtyStyleId&&this.updateTextureStyle(t),i.dirtyId=t.dirtyId}destroyTexture(t,e){const{gl:i}=this;if((t=t.castToBaseTexture())._glTextures[this.CONTEXT_UID]&&(this.unbind(t),i.deleteTexture(t._glTextures[this.CONTEXT_UID].texture),t.off("dispose",this.destroyTexture,this),delete t._glTextures[this.CONTEXT_UID],!e)){const e=this.managedTextures.indexOf(t);-1!==e&&$f(this.managedTextures,e,1)}}updateTextureStyle(t){var e;const i=t._glTextures[this.CONTEXT_UID];i&&(t.mipmap!==th.POW2&&2===this.webGLVersion||t.isPowerOfTwo?i.mipmap=t.mipmap>=1:i.mipmap=!1,2===this.webGLVersion||t.isPowerOfTwo?i.wrapMode=t.wrapMode:i.wrapMode=Ql.CLAMP,(null==(e=t.resource)?void 0:e.style(this.renderer,t,i))||this.setStyle(t,i),i.dirtyStyleId=t.dirtyStyleId)}setStyle(t,e){const i=this.gl;if(e.mipmap&&t.mipmap!==th.ON_MANUAL&&i.generateMipmap(t.target),i.texParameteri(t.target,i.TEXTURE_WRAP_S,e.wrapMode),i.texParameteri(t.target,i.TEXTURE_WRAP_T,e.wrapMode),e.mipmap){i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===Zl.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);const e=this.renderer.context.extensions.anisotropicFiltering;if(e&&t.anisotropicLevel>0&&t.scaleMode===Zl.LINEAR){const s=Math.min(t.anisotropicLevel,i.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT));i.texParameterf(t.target,e.TEXTURE_MAX_ANISOTROPY_EXT,s)}}else i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===Zl.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(t.target,i.TEXTURE_MAG_FILTER,t.scaleMode===Zl.LINEAR?i.LINEAR:i.NEAREST)}destroy(){this.renderer=null}}Wy.extension={type:hm.RendererSystem,name:"texture"},dm.add(Wy);class Hy{constructor(t){this.renderer=t}contextChange(){this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,s=t._glTransformFeedbacks[i]||this.createGLTransformFeedback(t);e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,s)}unbind(){const{gl:t}=this;t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null)}beginTransformFeedback(t,e){const{gl:i,renderer:s}=this;e&&s.shader.bind(e),i.beginTransformFeedback(t)}endTransformFeedback(){const{gl:t}=this;t.endTransformFeedback()}createGLTransformFeedback(t){const{gl:e,renderer:i,CONTEXT_UID:s}=this,r=e.createTransformFeedback();t._glTransformFeedbacks[s]=r,e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,r);for(let n=0;n<t.buffers.length;n++){const r=t.buffers[n];r&&(i.buffer.update(r),r._glBuffers[s].refCount++,e.bindBufferBase(e.TRANSFORM_FEEDBACK_BUFFER,n,r._glBuffers[s].buffer||null))}return e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,null),t.disposeRunner.add(this),r}disposeTransformFeedback(t,e){const i=t._glTransformFeedbacks[this.CONTEXT_UID],s=this.gl;t.disposeRunner.remove(this);const r=this.renderer.buffer;if(r)for(let n=0;n<t.buffers.length;n++){const i=t.buffers[n];if(!i)continue;const s=i._glBuffers[this.CONTEXT_UID];s&&(s.refCount--,0===s.refCount&&!e&&r.dispose(i,e))}i&&(e||s.deleteTransformFeedback(i),delete t._glTransformFeedbacks[this.CONTEXT_UID])}destroy(){this.renderer=null}}Hy.extension={type:hm.RendererSystem,name:"transformFeedback"},dm.add(Hy);class Yy{constructor(t){this.renderer=t}init(t){this.screen=new Xm(0,0,t.width,t.height),this.element=t.view||lh.ADAPTER.createCanvas(),this.resolution=t.resolution||lh.RESOLUTION,this.autoDensity=!!t.autoDensity}resizeView(t,e){this.element.width=Math.round(t*this.resolution),this.element.height=Math.round(e*this.resolution);const i=this.element.width/this.resolution,s=this.element.height/this.resolution;this.screen.width=i,this.screen.height=s,this.autoDensity&&(this.element.style.width=`${i}px`,this.element.style.height=`${s}px`),this.renderer.emit("resize",i,s),this.renderer.runners.resize.emit(this.screen.width,this.screen.height)}destroy(t){var e;t&&(null==(e=this.element.parentNode)||e.removeChild(this.element)),this.renderer=null,this.element=null,this.screen=null}}Yy.defaultOptions={width:800,height:600,resolution:void 0,autoDensity:!1},Yy.extension={type:[hm.RendererSystem,hm.CanvasRendererSystem],name:"_view"},dm.add(Yy),lh.PREFER_ENV=Hl.WEBGL2,lh.STRICT_TEXTURE_CACHE=!1,lh.RENDER_OPTIONS={...Ug.defaultOptions,...Bg.defaultOptions,...Yy.defaultOptions,...ky.defaultOptions},Object.defineProperties(lh,{WRAP_MODE:{get:()=>Em.defaultOptions.wrapMode,set(t){Qp("7.1.0","settings.WRAP_MODE is deprecated, use BaseTexture.defaultOptions.wrapMode"),Em.defaultOptions.wrapMode=t}},SCALE_MODE:{get:()=>Em.defaultOptions.scaleMode,set(t){Qp("7.1.0","settings.SCALE_MODE is deprecated, use BaseTexture.defaultOptions.scaleMode"),Em.defaultOptions.scaleMode=t}},MIPMAP_TEXTURES:{get:()=>Em.defaultOptions.mipmap,set(t){Qp("7.1.0","settings.MIPMAP_TEXTURES is deprecated, use BaseTexture.defaultOptions.mipmap"),Em.defaultOptions.mipmap=t}},ANISOTROPIC_LEVEL:{get:()=>Em.defaultOptions.anisotropicLevel,set(t){Qp("7.1.0","settings.ANISOTROPIC_LEVEL is deprecated, use BaseTexture.defaultOptions.anisotropicLevel"),Em.defaultOptions.anisotropicLevel=t}},FILTER_RESOLUTION:{get:()=>(Qp("7.1.0","settings.FILTER_RESOLUTION is deprecated, use Filter.defaultResolution"),kg.defaultResolution),set(t){kg.defaultResolution=t}},FILTER_MULTISAMPLE:{get:()=>(Qp("7.1.0","settings.FILTER_MULTISAMPLE is deprecated, use Filter.defaultMultisample"),kg.defaultMultisample),set(t){kg.defaultMultisample=t}},SPRITE_MAX_TEXTURES:{get:()=>Lg.defaultMaxTextures,set(t){Qp("7.1.0","settings.SPRITE_MAX_TEXTURES is deprecated, use BatchRenderer.defaultMaxTextures"),Lg.defaultMaxTextures=t}},SPRITE_BATCH_SIZE:{get:()=>Lg.defaultBatchSize,set(t){Qp("7.1.0","settings.SPRITE_BATCH_SIZE is deprecated, use BatchRenderer.defaultBatchSize"),Lg.defaultBatchSize=t}},CAN_UPLOAD_SAME_BUFFER:{get:()=>Lg.canUploadSameBuffer,set(t){Qp("7.1.0","settings.CAN_UPLOAD_SAME_BUFFER is deprecated, use BatchRenderer.canUploadSameBuffer"),Lg.canUploadSameBuffer=t}},GC_MODE:{get:()=>Gy.defaultMode,set(t){Qp("7.1.0","settings.GC_MODE is deprecated, use TextureGCSystem.defaultMode"),Gy.defaultMode=t}},GC_MAX_IDLE:{get:()=>Gy.defaultMaxIdle,set(t){Qp("7.1.0","settings.GC_MAX_IDLE is deprecated, use TextureGCSystem.defaultMaxIdle"),Gy.defaultMaxIdle=t}},GC_MAX_CHECK_COUNT:{get:()=>Gy.defaultCheckCountMax,set(t){Qp("7.1.0","settings.GC_MAX_CHECK_COUNT is deprecated, use TextureGCSystem.defaultCheckCountMax"),Gy.defaultCheckCountMax=t}},PRECISION_VERTEX:{get:()=>Tg.defaultVertexPrecision,set(t){Qp("7.1.0","settings.PRECISION_VERTEX is deprecated, use Program.defaultVertexPrecision"),Tg.defaultVertexPrecision=t}},PRECISION_FRAGMENT:{get:()=>Tg.defaultFragmentPrecision,set(t){Qp("7.1.0","settings.PRECISION_FRAGMENT is deprecated, use Program.defaultFragmentPrecision"),Tg.defaultFragmentPrecision=t}}});var $y=(t=>(t[t.INTERACTION=50]="INTERACTION",t[t.HIGH=25]="HIGH",t[t.NORMAL=0]="NORMAL",t[t.LOW=-25]="LOW",t[t.UTILITY=-50]="UTILITY",t))($y||{});class jy{constructor(t,e=null,i=0,s=!1){this.next=null,this.previous=null,this._destroyed=!1,this.fn=t,this.context=e,this.priority=i,this.once=s}match(t,e=null){return this.fn===t&&this.context===e}emit(t){this.fn&&(this.context?this.fn.call(this.context,t):this.fn(t));const e=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const zy=class t{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new jy(null,null,1/0),this.deltaMS=1/t.targetFPMS,this.elapsedMS=1/t.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&null===this._requestId&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){null===this._requestId&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=$y.NORMAL){return this._addListener(new jy(t,e,i))}addOnce(t,e,i=$y.NORMAL){return this._addListener(new jy(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(e){for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}else t.connect(i);return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i=i.match(t,e)?i.destroy():i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(e=performance.now()){let i;if(e>this.lastTime){if(i=this.elapsedMS=e-this.lastTime,i>this._maxElapsedMS&&(i=this._maxElapsedMS),i*=this.speed,this._minElapsedMS){const t=e-this._lastFrame|0;if(t<this._minElapsedMS)return;this._lastFrame=e-t%this._minElapsedMS}this.deltaMS=i,this.deltaTime=this.deltaMS*t.targetFPMS;const s=this._head;let r=s.next;for(;r;)r=r.emit(this.deltaTime);s.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const i=Math.min(this.maxFPS,e),s=Math.min(Math.max(0,i)/1e3,t.targetFPMS);this._maxElapsedMS=1/s}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(0===t)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!t._shared){const e=t._shared=new t;e.autoStart=!0,e._protected=!0}return t._shared}static get system(){if(!t._system){const e=t._system=new t;e.autoStart=!0,e._protected=!0}return t._system}};zy.targetFPMS=.06;let Vy=zy;Object.defineProperties(lh,{TARGET_FPMS:{get:()=>Vy.targetFPMS,set(t){Qp("7.1.0","settings.TARGET_FPMS is deprecated, use Ticker.targetFPMS"),Vy.targetFPMS=t}}});class qy{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,$y.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?Vy.shared:new Vy,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}qy.extension=hm.Application,dm.add(qy);const Jy=[];dm.handleByList(hm.Renderer,Jy);class Ky{constructor(t){this.renderer=t}contextChange(t){let e;if(1===this.renderer.context.webGLVersion){const i=t.getParameter(t.FRAMEBUFFER_BINDING);t.bindFramebuffer(t.FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.FRAMEBUFFER,i)}else{const i=t.getParameter(t.DRAW_FRAMEBUFFER_BINDING);t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,i)}e>=oh.HIGH?this.multisample=oh.HIGH:e>=oh.MEDIUM?this.multisample=oh.MEDIUM:e>=oh.LOW?this.multisample=oh.LOW:this.multisample=oh.NONE}destroy(){}}Ky.extension={type:hm.RendererSystem,name:"_multisample"},dm.add(Ky);class Zy{constructor(t){this.buffer=t||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}}class Qy{constructor(t){this.renderer=t,this.managedBuffers={},this.boundBufferBases={}}destroy(){this.renderer=null}contextChange(){this.disposeAll(!0),this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,s=t._glBuffers[i]||this.createGLBuffer(t);e.bindBuffer(t.type,s.buffer)}unbind(t){const{gl:e}=this;e.bindBuffer(t,null)}bindBufferBase(t,e){const{gl:i,CONTEXT_UID:s}=this;if(this.boundBufferBases[e]!==t){const r=t._glBuffers[s]||this.createGLBuffer(t);this.boundBufferBases[e]=t,i.bindBufferBase(i.UNIFORM_BUFFER,e,r.buffer)}}bindBufferRange(t,e,i){const{gl:s,CONTEXT_UID:r}=this;i=i||0;const n=t._glBuffers[r]||this.createGLBuffer(t);s.bindBufferRange(s.UNIFORM_BUFFER,e||0,n.buffer,256*i,256)}update(t){const{gl:e,CONTEXT_UID:i}=this,s=t._glBuffers[i]||this.createGLBuffer(t);if(t._updateID!==s.updateID)if(s.updateID=t._updateID,e.bindBuffer(t.type,s.buffer),s.byteLength>=t.data.byteLength)e.bufferSubData(t.type,0,t.data);else{const i=t.static?e.STATIC_DRAW:e.DYNAMIC_DRAW;s.byteLength=t.data.byteLength,e.bufferData(t.type,t.data,i)}}dispose(t,e){if(!this.managedBuffers[t.id])return;delete this.managedBuffers[t.id];const i=t._glBuffers[this.CONTEXT_UID],s=this.gl;t.disposeRunner.remove(this),i&&(e||s.deleteBuffer(i.buffer),delete t._glBuffers[this.CONTEXT_UID])}disposeAll(t){const e=Object.keys(this.managedBuffers);for(let i=0;i<e.length;i++)this.dispose(this.managedBuffers[e[i]],t)}createGLBuffer(t){const{CONTEXT_UID:e,gl:i}=this;return t._glBuffers[e]=new Zy(i.createBuffer()),this.managedBuffers[t.id]=t,t.disposeRunner.add(this),t._glBuffers[e]}}Qy.extension={type:hm.RendererSystem,name:"buffer"},dm.add(Qy);class tv{constructor(t){this.renderer=t}render(t,e){const i=this.renderer;let s,r,n,o;if(e&&(s=e.renderTexture,r=e.clear,n=e.transform,o=e.skipUpdateTransform),this.renderingToScreen=!s,i.runners.prerender.emit(),i.emit("prerender"),i.projection.transform=n,!i.context.isLost){if(s||(this.lastObjectRendered=t),!o){const e=t.enableTempParent();t.updateTransform(),t.disableTempParent(e)}i.renderTexture.bind(s),i.batch.currentRenderer.start(),(r??i.background.clearBeforeRender)&&i.renderTexture.clear(),t.render(i),i.batch.currentRenderer.flush(),s&&(e.blit&&i.framebuffer.blit(),s.baseTexture.update()),i.runners.postrender.emit(),i.projection.transform=null,i.emit("postrender")}}destroy(){this.renderer=null,this.lastObjectRendered=null}}tv.extension={type:hm.RendererSystem,name:"objectRenderer"},dm.add(tv);const ev=class t extends Dy{constructor(e){super(),this.type=Yl.WEBGL,e=Object.assign({},lh.RENDER_OPTIONS,e),this.gl=null,this.CONTEXT_UID=0,this.globalUniforms=new Ig({projectionMatrix:new jm},!0);const i={runners:["init","destroy","contextChange","resolutionChange","reset","update","postrender","prerender","resize"],systems:t.__systems,priority:["_view","textureGenerator","background","_plugin","startup","context","state","texture","buffer","geometry","framebuffer","transformFeedback","mask","scissor","stencil","projection","textureGC","filter","renderTexture","batch","objectRenderer","_multisample"]};this.setup(i),"useContextAlpha"in e&&(Qp("7.0.0","options.useContextAlpha is deprecated, use options.premultipliedAlpha and options.backgroundAlpha instead"),e.premultipliedAlpha=e.useContextAlpha&&"notMultiplied"!==e.useContextAlpha,e.backgroundAlpha=!1===e.useContextAlpha?1:e.backgroundAlpha),this._plugin.rendererPlugins=t.__plugins,this.options=e,this.startup.run(this.options)}static test(t){return!(null==t?void 0:t.forceCanvas)&&af()}render(t,e){this.objectRenderer.render(t,e)}resize(t,e){this._view.resizeView(t,e)}reset(){return this.runners.reset.emit(),this}clear(){this.renderTexture.bind(),this.renderTexture.clear()}destroy(t=!1){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:t}),super.destroy()}get plugins(){return this._plugin.plugins}get multisample(){return this._multisample.multisample}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}set resolution(t){this._view.resolution=t,this.runners.resolutionChange.emit(t)}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get rendererLogId(){return`WebGL ${this.context.webGLVersion}`}get clearBeforeRender(){return Qp("7.0.0","renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."),this.background.clearBeforeRender}get useContextAlpha(){return Qp("7.0.0","renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."),this.context.useContextAlpha}get preserveDrawingBuffer(){return Qp("7.0.0","renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"),this.context.preserveDrawingBuffer}get backgroundColor(){return Qp("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){Qp("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return Qp("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){Qp("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get powerPreference(){return Qp("7.0.0","renderer.powerPreference has been deprecated, we can only know this if pixi creates the context"),this.context.powerPreference}generateTexture(t,e){return this.textureGenerator.generateTexture(t,e)}};ev.extension={type:hm.Renderer,priority:1},ev.__plugins={},ev.__systems={};let iv=ev;dm.handleByMap(hm.RendererPlugin,iv.__plugins),dm.handleByMap(hm.RendererSystem,iv.__systems),dm.add(iv);class sv extends bm{constructor(t,e){const{width:i,height:s}=e||{};super(i,s),this.items=[],this.itemDirtyIds=[];for(let r=0;r<t;r++){const t=new Em;this.items.push(t),this.itemDirtyIds.push(-2)}this.length=t,this._load=null,this.baseTexture=null}initFromArray(t,e){for(let i=0;i<this.length;i++)t[i]&&(t[i].castToBaseTexture?this.addBaseTextureAt(t[i].castToBaseTexture(),i):t[i]instanceof bm?this.addResourceAt(t[i],i):this.addResourceAt(vm(t[i],e),i))}dispose(){for(let t=0,e=this.length;t<e;t++)this.items[t].destroy();this.items=null,this.itemDirtyIds=null,this._load=null}addResourceAt(t,e){if(!this.items[e])throw new Error(`Index ${e} is out of bounds`);return t.valid&&!this.valid&&this.resize(t.width,t.height),this.items[e].setResource(t),this}bind(t){if(null!==this.baseTexture)throw new Error("Only one base texture per TextureArray is allowed");super.bind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=t,this.items[e].on("update",t.update,t)}unbind(t){super.unbind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=null,this.items[e].off("update",t.update,t)}load(){if(this._load)return this._load;const t=this.items.map((t=>t.resource)).filter((t=>t)).map((t=>t.load()));return this._load=Promise.all(t).then((()=>{const{realWidth:t,realHeight:e}=this.items[0];return this.resize(t,e),this.update(),Promise.resolve(this)})),this._load}}class rv extends Wg{constructor(t){super(t)}static test(t){const{OffscreenCanvas:e}=globalThis;return!!(e&&t instanceof e)||globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement}}const nv=class t extends sv{constructor(e,i){const{width:s,height:r,autoLoad:n,linkBaseTexture:o}=i||{};if(e&&e.length!==t.SIDES)throw new Error(`Invalid length. Got ${e.length}, expected 6`);super(6,{width:s,height:r});for(let a=0;a<t.SIDES;a++)this.items[a].target=ql.TEXTURE_CUBE_MAP_POSITIVE_X+a;this.linkBaseTexture=!1!==o,e&&this.initFromArray(e,i),!1!==n&&this.load()}bind(t){super.bind(t),t.target=ql.TEXTURE_CUBE_MAP}addBaseTextureAt(t,e,i){if(void 0===i&&(i=this.linkBaseTexture),!this.items[e])throw new Error(`Index ${e} is out of bounds`);if(!this.linkBaseTexture||t.parentTextureArray||Object.keys(t._glTextures).length>0){if(!t.resource)throw new Error("CubeResource does not support copying of renderTexture.");this.addResourceAt(t.resource,e)}else t.target=ql.TEXTURE_CUBE_MAP_POSITIVE_X+e,t.parentTextureArray=this.baseTexture,this.items[e]=t;return t.valid&&!this.valid&&this.resize(t.realWidth,t.realHeight),this.items[e]=t,this}upload(e,i,s){const r=this.itemDirtyIds;for(let n=0;n<t.SIDES;n++){const t=this.items[n];(r[n]<t.dirtyId||s.dirtyId<i.dirtyId)&&(t.valid&&t.resource?(t.resource.upload(e,t,s),r[n]=t.dirtyId):r[n]<-1&&(e.gl.texImage2D(t.target,0,s.internalFormat,i.realWidth,i.realHeight,0,i.format,s.type,null),r[n]=-1))}return!0}static test(e){return Array.isArray(e)&&e.length===t.SIDES}};nv.SIDES=6;let ov=nv;class av extends Wg{constructor(t,e){let i,s,r;e=e||{},"string"==typeof t?(i=av.EMPTY,s=t,r=!0):(i=t,s=null,r=!1),super(i),this.url=s,this.crossOrigin=e.crossOrigin??!0,this.alphaMode="number"==typeof e.alphaMode?e.alphaMode:null,this.ownsImageBitmap=e.ownsImageBitmap??r,this._load=null,!1!==e.autoLoad&&this.load()}load(){return this._load||(this._load=new Promise((async(t,e)=>{if(null!==this.url)try{const e=await lh.ADAPTER.fetch(this.url,{mode:this.crossOrigin?"cors":"no-cors"});if(this.destroyed)return;const i=await e.blob();if(this.destroyed)return;const s=await createImageBitmap(i,{premultiplyAlpha:null===this.alphaMode||this.alphaMode===eh.UNPACK?"premultiply":"none"});if(this.destroyed)return void s.close();this.source=s,this.update(),t(this)}catch(dP){if(this.destroyed)return;e(dP),this.onError.emit(dP)}else t(this)}))),this._load}upload(t,e,i){return this.source instanceof ImageBitmap?("number"==typeof this.alphaMode&&(e.alphaMode=this.alphaMode),super.upload(t,e,i)):(this.load(),!1)}dispose(){this.ownsImageBitmap&&this.source instanceof ImageBitmap&&this.source.close(),super.dispose(),this._load=null}static test(t){return!!globalThis.createImageBitmap&&typeof ImageBitmap<"u"&&("string"==typeof t||t instanceof ImageBitmap)}static get EMPTY(){return av._EMPTY=av._EMPTY??lh.ADAPTER.createCanvas(0,0),av._EMPTY}}const lv=class t extends Wg{constructor(t,e){e=e||{},super(lh.ADAPTER.createCanvas()),this._width=0,this._height=0,this.svg=t,this.scale=e.scale||1,this._overrideWidth=e.width,this._overrideHeight=e.height,this._resolve=null,this._crossorigin=e.crossorigin,this._load=null,!1!==e.autoLoad&&this.load()}load(){return this._load||(this._load=new Promise((e=>{if(this._resolve=()=>{this.update(),e(this)},t.SVG_XML.test(this.svg.trim())){if(!btoa)throw new Error("Your browser doesn't support base64 conversions.");this.svg=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.svg)))}`}this._loadSvg()}))),this._load}_loadSvg(){const t=new Image;Wg.crossOrigin(t,this.svg,this._crossorigin),t.src=this.svg,t.onerror=e=>{this._resolve&&(t.onerror=null,this.onError.emit(e))},t.onload=()=>{if(!this._resolve)return;const e=t.width,i=t.height;if(!e||!i)throw new Error("The SVG image must have width and height defined (in pixels), canvas API needs them.");let s=e*this.scale,r=i*this.scale;(this._overrideWidth||this._overrideHeight)&&(s=this._overrideWidth||this._overrideHeight/i*e,r=this._overrideHeight||this._overrideWidth/e*i),s=Math.round(s),r=Math.round(r);const n=this.source;n.width=s,n.height=r,n._pixiId=`canvas_${Vf()}`,n.getContext("2d").drawImage(t,0,0,e,i,0,0,s,r),this._resolve(),this._resolve=null}}static getSize(e){const i=t.SVG_SIZE.exec(e),s={};return i&&(s[i[1]]=Math.round(parseFloat(i[3])),s[i[5]]=Math.round(parseFloat(i[7]))),s}dispose(){super.dispose(),this._resolve=null,this._crossorigin=null}static test(e,i){return"svg"===i||"string"==typeof e&&e.startsWith("data:image/svg+xml")||"string"==typeof e&&t.SVG_XML.test(e)}};lv.SVG_XML=/^(<\?xml[^?]+\?>)?\s*(<!--[^(-->)]*-->)?\s*\<svg/m,lv.SVG_SIZE=/<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i;let hv=lv;const uv=class t extends Wg{constructor(e,i){if(i=i||{},!(e instanceof HTMLVideoElement)){const s=document.createElement("video");!1!==i.autoLoad&&s.setAttribute("preload","auto"),!1!==i.playsinline&&(s.setAttribute("webkit-playsinline",""),s.setAttribute("playsinline","")),!0===i.muted&&(s.setAttribute("muted",""),s.muted=!0),!0===i.loop&&s.setAttribute("loop",""),!1!==i.autoPlay&&s.setAttribute("autoplay",""),"string"==typeof e&&(e=[e]);const r=e[0].src||e[0];Wg.crossOrigin(s,r,i.crossorigin);for(let i=0;i<e.length;++i){const r=document.createElement("source");let{src:n,mime:o}=e[i];if(n=n||e[i],n.startsWith("data:"))o=n.slice(5,n.indexOf(";"));else if(!n.startsWith("blob:")){const e=n.split("?").shift().toLowerCase(),i=e.slice(e.lastIndexOf(".")+1);o=o||t.MIME_TYPES[i]||`video/${i}`}r.src=n,o&&(r.type=o),s.appendChild(r)}e=s}super(e),this.noSubImage=!0,this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=i.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=!1!==i.autoPlay,this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),!1!==i.autoLoad&&this.load()}update(t=0){if(!this.destroyed){if(this._updateFPS){const t=Vy.shared.elapsedMS*this.source.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-t)}(!this._updateFPS||this._msToNextUpdate<=0)&&(super.update(),this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0)}}_videoFrameRequestCallback(){this.update(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback)}load(){if(this._load)return this._load;const t=this.source;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._onCanPlay():(t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlay),t.addEventListener("error",this._onError,!0)),this._load=new Promise(((e,i)=>{this.valid?e(this):(this._resolve=e,this._reject=i,t.load())})),this._load}_onError(t){this.source.removeEventListener("error",this._onError,!0),this.onError.emit(t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.source;return!t.paused&&!t.ended}_isSourceReady(){return this.source.readyState>2}_onPlayStart(){this.valid||this._onCanPlay(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0)}_onCanPlay(){const t=this.source;t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay);const e=this.valid;this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0,!e&&this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&t.play()}dispose(){this._configureAutoUpdate();const t=this.source;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.dispose()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.source.requestVideoFrameCallback?(this._isConnectedToTicker&&(Vy.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),null===this._videoFrameRequestCallbackHandle&&(this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(null!==this._videoFrameRequestCallbackHandle&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(Vy.shared.add(this.update,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(null!==this._videoFrameRequestCallbackHandle&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(Vy.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e,i){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement||t.TYPES.includes(i)}};uv.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],uv.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let cv=uv;ym.push(av,Hg,rv,cv,class extends Wg{constructor(t){super(t)}static test(t){return!!globalThis.VideoFrame&&t instanceof globalThis.VideoFrame}},hv,_m,ov,class extends sv{constructor(t,e){const{width:i,height:s}=e||{};let r,n;Array.isArray(t)?(r=t,n=t.length):n=t,super(n,{width:i,height:s}),r&&this.initFromArray(r,e)}addBaseTextureAt(t,e){if(!t.resource)throw new Error("ArrayResource does not support RenderTexture");return this.addResourceAt(t.resource,e),this}bind(t){super.bind(t),t.target=ql.TEXTURE_2D_ARRAY}upload(t,e,i){const{length:s,itemDirtyIds:r,items:n}=this,{gl:o}=t;i.dirtyId<0&&o.texImage3D(o.TEXTURE_2D_ARRAY,0,i.internalFormat,this._width,this._height,s,0,e.format,i.type,null);for(let a=0;a<s;a++){const t=n[a];r[a]<t.dirtyId&&(r[a]=t.dirtyId,t.valid&&o.texSubImage3D(o.TEXTURE_2D_ARRAY,0,0,0,a,t.resource.width,t.resource.height,1,e.format,i.type,t.resource.source))}return!0}});class dv{constructor(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.rect=null,this.updateID=-1}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}clear(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}getRectangle(t){return this.minX>this.maxX||this.minY>this.maxY?Xm.EMPTY:((t=t||new Xm(0,0,1,1)).x=this.minX,t.y=this.minY,t.width=this.maxX-this.minX,t.height=this.maxY-this.minY,t)}addPoint(t){this.minX=Math.min(this.minX,t.x),this.maxX=Math.max(this.maxX,t.x),this.minY=Math.min(this.minY,t.y),this.maxY=Math.max(this.maxY,t.y)}addPointMatrix(t,e){const{a:i,b:s,c:r,d:n,tx:o,ty:a}=t,l=i*e.x+r*e.y+o,h=s*e.x+n*e.y+a;this.minX=Math.min(this.minX,l),this.maxX=Math.max(this.maxX,l),this.minY=Math.min(this.minY,h),this.maxY=Math.max(this.maxY,h)}addQuad(t){let e=this.minX,i=this.minY,s=this.maxX,r=this.maxY,n=t[0],o=t[1];e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,n=t[2],o=t[3],e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,n=t[4],o=t[5],e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,n=t[6],o=t[7],e=n<e?n:e,i=o<i?o:i,s=n>s?n:s,r=o>r?o:r,this.minX=e,this.minY=i,this.maxX=s,this.maxY=r}addFrame(t,e,i,s,r){this.addFrameMatrix(t.worldTransform,e,i,s,r)}addFrameMatrix(t,e,i,s,r){const n=t.a,o=t.b,a=t.c,l=t.d,h=t.tx,u=t.ty;let c=this.minX,d=this.minY,p=this.maxX,f=this.maxY,m=n*e+a*i+h,g=o*e+l*i+u;c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,m=n*s+a*i+h,g=o*s+l*i+u,c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,m=n*e+a*r+h,g=o*e+l*r+u,c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,m=n*s+a*r+h,g=o*s+l*r+u,c=m<c?m:c,d=g<d?g:d,p=m>p?m:p,f=g>f?g:f,this.minX=c,this.minY=d,this.maxX=p,this.maxY=f}addVertexData(t,e,i){let s=this.minX,r=this.minY,n=this.maxX,o=this.maxY;for(let a=e;a<i;a+=2){const e=t[a],i=t[a+1];s=e<s?e:s,r=i<r?i:r,n=e>n?e:n,o=i>o?i:o}this.minX=s,this.minY=r,this.maxX=n,this.maxY=o}addVertices(t,e,i,s){this.addVerticesMatrix(t.worldTransform,e,i,s)}addVerticesMatrix(t,e,i,s,r=0,n=r){const o=t.a,a=t.b,l=t.c,h=t.d,u=t.tx,c=t.ty;let d=this.minX,p=this.minY,f=this.maxX,m=this.maxY;for(let g=i;g<s;g+=2){const t=e[g],i=e[g+1],s=o*t+l*i+u,y=h*i+a*t+c;d=Math.min(d,s-r),f=Math.max(f,s+r),p=Math.min(p,y-n),m=Math.max(m,y+n)}this.minX=d,this.minY=p,this.maxX=f,this.maxY=m}addBounds(t){const e=this.minX,i=this.minY,s=this.maxX,r=this.maxY;this.minX=t.minX<e?t.minX:e,this.minY=t.minY<i?t.minY:i,this.maxX=t.maxX>s?t.maxX:s,this.maxY=t.maxY>r?t.maxY:r}addBoundsMask(t,e){const i=t.minX>e.minX?t.minX:e.minX,s=t.minY>e.minY?t.minY:e.minY,r=t.maxX<e.maxX?t.maxX:e.maxX,n=t.maxY<e.maxY?t.maxY:e.maxY;if(i<=r&&s<=n){const t=this.minX,e=this.minY,o=this.maxX,a=this.maxY;this.minX=i<t?i:t,this.minY=s<e?s:e,this.maxX=r>o?r:o,this.maxY=n>a?n:a}}addBoundsMatrix(t,e){this.addFrameMatrix(e,t.minX,t.minY,t.maxX,t.maxY)}addBoundsArea(t,e){const i=t.minX>e.x?t.minX:e.x,s=t.minY>e.y?t.minY:e.y,r=t.maxX<e.x+e.width?t.maxX:e.x+e.width,n=t.maxY<e.y+e.height?t.maxY:e.y+e.height;if(i<=r&&s<=n){const t=this.minX,e=this.minY,o=this.maxX,a=this.maxY;this.minX=i<t?i:t,this.minY=s<e?s:e,this.maxX=r>o?r:o,this.maxY=n>a?n:a}}pad(t=0,e=t){this.isEmpty()||(this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e)}addFramePad(t,e,i,s,r,n){t-=r,e-=n,i+=r,s+=n,this.minX=this.minX<t?this.minX:t,this.maxX=this.maxX>i?this.maxX:i,this.minY=this.minY<e?this.minY:e,this.maxY=this.maxY>s?this.maxY:s}}class pv extends Sh{constructor(){super(),this.tempDisplayObjectParent=null,this.transform=new sg,this.alpha=1,this.visible=!0,this.renderable=!0,this.cullable=!1,this.cullArea=null,this.parent=null,this.worldAlpha=1,this._lastSortedIndex=0,this._zIndex=0,this.filterArea=null,this.filters=null,this._enabledFilters=null,this._bounds=new dv,this._localBounds=null,this._boundsID=0,this._boundsRect=null,this._localBoundsRect=null,this._mask=null,this._maskRefCount=0,this._destroyed=!1,this.isSprite=!1,this.isMask=!1}static mixin(t){const e=Object.keys(t);for(let i=0;i<e.length;++i){const s=e[i];Object.defineProperty(pv.prototype,s,Object.getOwnPropertyDescriptor(t,s))}}get destroyed(){return this._destroyed}_recursivePostUpdateTransform(){this.parent?(this.parent._recursivePostUpdateTransform(),this.transform.updateTransform(this.parent.transform)):this.transform.updateTransform(this._tempDisplayObjectParent.transform)}updateTransform(){this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha}getBounds(t,e){return t||(this.parent?(this._recursivePostUpdateTransform(),this.updateTransform()):(this.parent=this._tempDisplayObjectParent,this.updateTransform(),this.parent=null)),this._bounds.updateID!==this._boundsID&&(this.calculateBounds(),this._bounds.updateID=this._boundsID),e||(this._boundsRect||(this._boundsRect=new Xm),e=this._boundsRect),this._bounds.getRectangle(e)}getLocalBounds(t){t||(this._localBoundsRect||(this._localBoundsRect=new Xm),t=this._localBoundsRect),this._localBounds||(this._localBounds=new dv);const e=this.transform,i=this.parent;this.parent=null,this._tempDisplayObjectParent.worldAlpha=(null==i?void 0:i.worldAlpha)??1,this.transform=this._tempDisplayObjectParent.transform;const s=this._bounds,r=this._boundsID;this._bounds=this._localBounds;const n=this.getBounds(!1,t);return this.parent=i,this.transform=e,this._bounds=s,this._bounds.updateID+=this._boundsID-r,n}toGlobal(t,e,i=!1){return i||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.apply(t,e)}toLocal(t,e,i,s){return e&&(t=e.toGlobal(t,i,s)),s||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.applyInverse(t,i)}setParent(t){if(!t||!t.addChild)throw new Error("setParent: Argument must be a Container");return t.addChild(this),t}removeFromParent(){var t;null==(t=this.parent)||t.removeChild(this)}setTransform(t=0,e=0,i=1,s=1,r=0,n=0,o=0,a=0,l=0){return this.position.x=t,this.position.y=e,this.scale.x=i||1,this.scale.y=s||1,this.rotation=r,this.skew.x=n,this.skew.y=o,this.pivot.x=a,this.pivot.y=l,this}destroy(t){this.removeFromParent(),this._destroyed=!0,this.transform=null,this.parent=null,this._bounds=null,this.mask=null,this.cullArea=null,this.filters=null,this.filterArea=null,this.hitArea=null,this.eventMode="auto",this.interactiveChildren=!1,this.emit("destroyed"),this.removeAllListeners()}get _tempDisplayObjectParent(){return null===this.tempDisplayObjectParent&&(this.tempDisplayObjectParent=new fv),this.tempDisplayObjectParent}enableTempParent(){const t=this.parent;return this.parent=this._tempDisplayObjectParent,t}disableTempParent(t){this.parent=t}get x(){return this.position.x}set x(t){this.transform.position.x=t}get y(){return this.position.y}set y(t){this.transform.position.y=t}get worldTransform(){return this.transform.worldTransform}get localTransform(){return this.transform.localTransform}get position(){return this.transform.position}set position(t){this.transform.position.copyFrom(t)}get scale(){return this.transform.scale}set scale(t){this.transform.scale.copyFrom(t)}get pivot(){return this.transform.pivot}set pivot(t){this.transform.pivot.copyFrom(t)}get skew(){return this.transform.skew}set skew(t){this.transform.skew.copyFrom(t)}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angle(){return this.transform.rotation*Bm}set angle(t){this.transform.rotation=t*Fm}get zIndex(){return this._zIndex}set zIndex(t){this._zIndex!==t&&(this._zIndex=t,this.parent&&(this.parent.sortDirty=!0))}get worldVisible(){let t=this;do{if(!t.visible)return!1;t=t.parent}while(t);return!0}get mask(){return this._mask}set mask(t){if(this._mask!==t){if(this._mask){const t=this._mask.isMaskData?this._mask.maskObject:this._mask;t&&(t._maskRefCount--,0===t._maskRefCount&&(t.renderable=!0,t.isMask=!1))}if(this._mask=t,this._mask){const t=this._mask.isMaskData?this._mask.maskObject:this._mask;t&&(0===t._maskRefCount&&(t.renderable=!1,t.isMask=!0),t._maskRefCount++)}}}}class fv extends pv{constructor(){super(...arguments),this.sortDirty=null}}pv.prototype.displayObjectUpdateTransform=pv.prototype.updateTransform;const mv=new jm;function gv(t,e){return t.zIndex===e.zIndex?t._lastSortedIndex-e._lastSortedIndex:t.zIndex-e.zIndex}const yv=class t extends pv{constructor(){super(),this.children=[],this.sortableChildren=t.defaultSortableChildren,this.sortDirty=!1}onChildrenChange(t){}addChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.addChild(t[e]);else{const e=t[0];e.parent&&e.parent.removeChild(e),e.parent=this,this.sortDirty=!0,e.transform._parentID=-1,this.children.push(e),this._boundsID++,this.onChildrenChange(this.children.length-1),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this)}return t[0]}addChildAt(t,e){if(e<0||e>this.children.length)throw new Error(`${t}addChildAt: The index ${e} supplied is out of bounds ${this.children.length}`);return t.parent&&t.parent.removeChild(t),t.parent=this,this.sortDirty=!0,t.transform._parentID=-1,this.children.splice(e,0,t),this._boundsID++,this.onChildrenChange(e),t.emit("added",this),this.emit("childAdded",t,this,e),t}swapChildren(t,e){if(t===e)return;const i=this.getChildIndex(t),s=this.getChildIndex(e);this.children[i]=e,this.children[s]=t,this.onChildrenChange(i<s?i:s)}getChildIndex(t){const e=this.children.indexOf(t);if(-1===e)throw new Error("The supplied DisplayObject must be a child of the caller");return e}setChildIndex(t,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);const i=this.getChildIndex(t);$f(this.children,i,1),this.children.splice(e,0,t),this.onChildrenChange(e)}getChildAt(t){if(t<0||t>=this.children.length)throw new Error(`getChildAt: Index (${t}) does not exist.`);return this.children[t]}removeChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.removeChild(t[e]);else{const e=t[0],i=this.children.indexOf(e);if(-1===i)return null;e.parent=null,e.transform._parentID=-1,$f(this.children,i,1),this._boundsID++,this.onChildrenChange(i),e.emit("removed",this),this.emit("childRemoved",e,this,i)}return t[0]}removeChildAt(t){const e=this.getChildAt(t);return e.parent=null,e.transform._parentID=-1,$f(this.children,t,1),this._boundsID++,this.onChildrenChange(t),e.emit("removed",this),this.emit("childRemoved",e,this,t),e}removeChildren(t=0,e=this.children.length){const i=t,s=e-i;let r;if(s>0&&s<=e){r=this.children.splice(i,s);for(let t=0;t<r.length;++t)r[t].parent=null,r[t].transform&&(r[t].transform._parentID=-1);this._boundsID++,this.onChildrenChange(t);for(let t=0;t<r.length;++t)r[t].emit("removed",this),this.emit("childRemoved",r[t],this,t);return r}if(0===s&&0===this.children.length)return[];throw new RangeError("removeChildren: numeric values are outside the acceptable range.")}sortChildren(){let t=!1;for(let e=0,i=this.children.length;e<i;++e){const i=this.children[e];i._lastSortedIndex=e,!t&&0!==i.zIndex&&(t=!0)}t&&this.children.length>1&&this.children.sort(gv),this.sortDirty=!1}updateTransform(){this.sortableChildren&&this.sortDirty&&this.sortChildren(),this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha;for(let t=0,e=this.children.length;t<e;++t){const e=this.children[t];e.visible&&e.updateTransform()}}calculateBounds(){this._bounds.clear(),this._calculateBounds();for(let t=0;t<this.children.length;t++){const e=this.children[t];if(e.visible&&e.renderable)if(e.calculateBounds(),e._mask){const t=e._mask.isMaskData?e._mask.maskObject:e._mask;t?(t.calculateBounds(),this._bounds.addBoundsMask(e._bounds,t._bounds)):this._bounds.addBounds(e._bounds)}else e.filterArea?this._bounds.addBoundsArea(e._bounds,e.filterArea):this._bounds.addBounds(e._bounds)}this._bounds.updateID=this._boundsID}getLocalBounds(t,e=!1){const i=super.getLocalBounds(t);if(!e)for(let s=0,r=this.children.length;s<r;++s){const t=this.children[s];t.visible&&t.updateTransform()}return i}_calculateBounds(){}_renderWithCulling(e){const i=e.renderTexture.sourceFrame;if(!(i.width>0&&i.height>0))return;let s,r;this.cullArea?(s=this.cullArea,r=this.worldTransform):this._render!==t.prototype._render&&(s=this.getBounds(!0));const n=e.projection.transform;if(n&&(r?(r=mv.copyFrom(r),r.prepend(n)):r=n),s&&i.intersects(s,r))this._render(e);else if(this.cullArea)return;for(let t=0,o=this.children.length;t<o;++t){const i=this.children[t],s=i.cullable;i.cullable=s||!this.cullArea,i.render(e),i.cullable=s}}render(t){var e;if(this.visible&&!(this.worldAlpha<=0)&&this.renderable)if(this._mask||(null==(e=this.filters)?void 0:e.length))this.renderAdvanced(t);else if(this.cullable)this._renderWithCulling(t);else{this._render(t);for(let e=0,i=this.children.length;e<i;++e)this.children[e].render(t)}}renderAdvanced(t){var e,i,s;const r=this.filters,n=this._mask;if(r){this._enabledFilters||(this._enabledFilters=[]),this._enabledFilters.length=0;for(let t=0;t<r.length;t++)r[t].enabled&&this._enabledFilters.push(r[t])}const o=r&&(null==(e=this._enabledFilters)?void 0:e.length)||n&&(!n.isMaskData||n.enabled&&(n.autoDetect||n.type!==nh.NONE));if(o&&t.batch.flush(),r&&(null==(i=this._enabledFilters)?void 0:i.length)&&t.filter.push(this,this._enabledFilters),n&&t.mask.push(this,this._mask),this.cullable)this._renderWithCulling(t);else{this._render(t);for(let e=0,i=this.children.length;e<i;++e)this.children[e].render(t)}o&&t.batch.flush(),n&&t.mask.pop(this),r&&(null==(s=this._enabledFilters)?void 0:s.length)&&t.filter.pop()}_render(t){}destroy(t){super.destroy(),this.sortDirty=!1;const e="boolean"==typeof t?t:null==t?void 0:t.children,i=this.removeChildren(0,this.children.length);if(e)for(let s=0;s<i.length;++s)i[s].destroy(t)}get width(){return this.scale.x*this.getLocalBounds().width}set width(t){const e=this.getLocalBounds().width;this.scale.x=0!==e?t/e:1,this._width=t}get height(){return this.scale.y*this.getLocalBounds().height}set height(t){const e=this.getLocalBounds().height;this.scale.y=0!==e?t/e:1,this._height=t}};yv.defaultSortableChildren=!1;let vv=yv;vv.prototype.containerUpdateTransform=vv.prototype.updateTransform,Object.defineProperties(lh,{SORTABLE_CHILDREN:{get:()=>vv.defaultSortableChildren,set(t){Qp("7.1.0","settings.SORTABLE_CHILDREN is deprecated, use Container.defaultSortableChildren"),vv.defaultSortableChildren=t}}});const xv=new Um,bv=new Uint16Array([0,1,2,0,2,3]);class _v extends vv{constructor(t){super(),this._anchor=new eg(this._onAnchorUpdate,this,t?t.defaultAnchor.x:0,t?t.defaultAnchor.y:0),this._texture=null,this._width=0,this._height=0,this._tintColor=new Ff(16777215),this._tintRGB=null,this.tint=16777215,this.blendMode=jl.NORMAL,this._cachedTint=16777215,this.uvs=null,this.texture=t||zg.EMPTY,this.vertexData=new Float32Array(8),this.vertexTrimmedData=null,this._transformID=-1,this._textureID=-1,this._transformTrimmedID=-1,this._textureTrimmedID=-1,this.indices=bv,this.pluginName="batch",this.isSprite=!0,this._roundPixels=lh.ROUND_PIXELS}_onTextureUpdate(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=jf(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=jf(this.scale.y)*this._height/this._texture.orig.height)}_onAnchorUpdate(){this._transformID=-1,this._transformTrimmedID=-1}calculateVertices(){const t=this._texture;if(this._transformID===this.transform._worldID&&this._textureID===t._updateID)return;this._textureID!==t._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=t._updateID;const e=this.transform.worldTransform,i=e.a,s=e.b,r=e.c,n=e.d,o=e.tx,a=e.ty,l=this.vertexData,h=t.trim,u=t.orig,c=this._anchor;let d=0,p=0,f=0,m=0;if(h?(p=h.x-c._x*u.width,d=p+h.width,m=h.y-c._y*u.height,f=m+h.height):(p=-c._x*u.width,d=p+u.width,m=-c._y*u.height,f=m+u.height),l[0]=i*p+r*m+o,l[1]=n*m+s*p+a,l[2]=i*d+r*m+o,l[3]=n*m+s*d+a,l[4]=i*d+r*f+o,l[5]=n*f+s*d+a,l[6]=i*p+r*f+o,l[7]=n*f+s*p+a,this._roundPixels){const t=lh.RESOLUTION;for(let e=0;e<l.length;++e)l[e]=Math.round(l[e]*t)/t}}calculateTrimmedVertices(){if(this.vertexTrimmedData){if(this._transformTrimmedID===this.transform._worldID&&this._textureTrimmedID===this._texture._updateID)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=this.transform._worldID,this._textureTrimmedID=this._texture._updateID;const t=this._texture,e=this.vertexTrimmedData,i=t.orig,s=this._anchor,r=this.transform.worldTransform,n=r.a,o=r.b,a=r.c,l=r.d,h=r.tx,u=r.ty,c=-s._x*i.width,d=c+i.width,p=-s._y*i.height,f=p+i.height;if(e[0]=n*c+a*p+h,e[1]=l*p+o*c+u,e[2]=n*d+a*p+h,e[3]=l*p+o*d+u,e[4]=n*d+a*f+h,e[5]=l*f+o*d+u,e[6]=n*c+a*f+h,e[7]=l*f+o*c+u,this._roundPixels){const t=lh.RESOLUTION;for(let i=0;i<e.length;++i)e[i]=Math.round(e[i]*t)/t}}_render(t){this.calculateVertices(),t.batch.setObjectRenderer(t.plugins[this.pluginName]),t.plugins[this.pluginName].render(this)}_calculateBounds(){const t=this._texture.trim,e=this._texture.orig;!t||t.width===e.width&&t.height===e.height?(this.calculateVertices(),this._bounds.addQuad(this.vertexData)):(this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData))}getLocalBounds(t){return 0===this.children.length?(this._localBounds||(this._localBounds=new dv),this._localBounds.minX=this._texture.orig.width*-this._anchor._x,this._localBounds.minY=this._texture.orig.height*-this._anchor._y,this._localBounds.maxX=this._texture.orig.width*(1-this._anchor._x),this._localBounds.maxY=this._texture.orig.height*(1-this._anchor._y),t||(this._localBoundsRect||(this._localBoundsRect=new Xm),t=this._localBoundsRect),this._localBounds.getRectangle(t)):super.getLocalBounds.call(this,t)}containsPoint(t){this.worldTransform.applyInverse(t,xv);const e=this._texture.orig.width,i=this._texture.orig.height,s=-e*this.anchor.x;let r=0;return xv.x>=s&&xv.x<s+e&&(r=-i*this.anchor.y,xv.y>=r&&xv.y<r+i)}destroy(t){if(super.destroy(t),this._texture.off("update",this._onTextureUpdate,this),this._anchor=null,"boolean"==typeof t?t:null==t?void 0:t.texture){const e="boolean"==typeof t?t:null==t?void 0:t.baseTexture;this._texture.destroy(!!e)}this._texture=null}static from(t,e){const i=t instanceof zg?t:zg.from(t,e);return new _v(i)}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1,this._transformTrimmedID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){const e=jf(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){const e=jf(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get anchor(){return this._anchor}set anchor(t){this._anchor.copyFrom(t)}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t),this._tintRGB=this._tintColor.toLittleEndianNumber()}get tintValue(){return this._tintColor.toNumber()}get texture(){return this._texture}set texture(t){this._texture!==t&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=t||zg.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))}}const wv={build(t){const e=t.points;let i,s,r,n,o,a;if(t.type===Dm.CIRC){const e=t.shape;i=e.x,s=e.y,o=a=e.radius,r=n=0}else if(t.type===Dm.ELIP){const e=t.shape;i=e.x,s=e.y,o=e.width,a=e.height,r=n=0}else{const e=t.shape,l=e.width/2,h=e.height/2;i=e.x+l,s=e.y+h,o=a=Math.max(0,Math.min(e.radius,Math.min(l,h))),r=l-o,n=h-a}if(!(o>=0&&a>=0&&r>=0&&n>=0))return void(e.length=0);const l=Math.ceil(2.3*Math.sqrt(o+a)),h=8*l+(r?4:0)+(n?4:0);if(e.length=h,0===h)return;if(0===l)return e.length=8,e[0]=e[6]=i+r,e[1]=e[3]=s+n,e[2]=e[4]=i-r,void(e[5]=e[7]=s-n);let u=0,c=4*l+(r?2:0)+2,d=c,p=h;{const t=r+o,a=n,l=i+t,h=i-t,f=s+a;if(e[u++]=l,e[u++]=f,e[--c]=f,e[--c]=h,n){const t=s-a;e[d++]=h,e[d++]=t,e[--p]=t,e[--p]=l}}for(let f=1;f<l;f++){const t=Math.PI/2*(f/l),h=r+Math.cos(t)*o,m=n+Math.sin(t)*a,g=i+h,y=i-h,v=s+m,x=s-m;e[u++]=g,e[u++]=v,e[--c]=v,e[--c]=y,e[d++]=y,e[d++]=x,e[--p]=x,e[--p]=g}{const t=n+a,o=i+r,l=i-r,h=s+t,c=s-t;e[u++]=o,e[u++]=h,e[--p]=c,e[--p]=o,r&&(e[u++]=l,e[u++]=h,e[--p]=c,e[--p]=l)}},triangulate(t,e){const i=t.points,s=e.points,r=e.indices;if(0===i.length)return;let n=s.length/2;const o=n;let a,l;if(t.type!==Dm.RREC){const e=t.shape;a=e.x,l=e.y}else{const e=t.shape;a=e.x+e.width/2,l=e.y+e.height/2}const h=t.matrix;s.push(t.matrix?h.a*a+h.c*l+h.tx:a,t.matrix?h.b*a+h.d*l+h.ty:l),n++,s.push(i[0],i[1]);for(let u=2;u<i.length;u+=2)s.push(i[u],i[u+1]),r.push(n++,o,n);r.push(o+1,o,n)}};function Pv(t,e=!1){const i=t.length;if(i<6)return;let s=0;for(let r=0,n=t[i-2],o=t[i-1];r<i;r+=2){const e=t[r],i=t[r+1];s+=(e-n)*(i+o),n=e,o=i}if(!e&&s>0||e&&s<=0){const e=i/2;for(let s=e+e%2;s<i;s+=2){const e=i-s-2,r=i-s-1,n=s,o=s+1;[t[e],t[n]]=[t[n],t[e]],[t[r],t[o]]=[t[o],t[r]]}}}const Ev={build(t){t.points=t.shape.points.slice()},triangulate(t,e){let i=t.points;const s=t.holes,r=e.points,n=e.indices;if(i.length>=6){Pv(i,!1);const t=[];for(let r=0;r<s.length;r++){const e=s[r];Pv(e.points,!0),t.push(i.length/2),i=i.concat(e.points)}const e=ne(i,t,2);if(!e)return;const o=r.length/2;for(let i=0;i<e.length;i+=3)n.push(e[i]+o),n.push(e[i+1]+o),n.push(e[i+2]+o);for(let s=0;s<i.length;s++)r.push(i[s])}}},Tv={build(t){const e=t.shape,i=e.x,s=e.y,r=e.width,n=e.height,o=t.points;o.length=0,r>=0&&n>=0&&o.push(i,s,i+r,s,i+r,s+n,i,s+n)},triangulate(t,e){const i=t.points,s=e.points;if(0===i.length)return;const r=s.length/2;s.push(i[0],i[1],i[2],i[3],i[6],i[7],i[4],i[5]),e.indices.push(r,r+1,r+2,r+1,r+2,r+3)}},Av={build(t){wv.build(t)},triangulate(t,e){wv.triangulate(t,e)}};var Iv=(t=>(t.MITER="miter",t.BEVEL="bevel",t.ROUND="round",t))(Iv||{}),Sv=(t=>(t.BUTT="butt",t.ROUND="round",t.SQUARE="square",t))(Sv||{});const Cv={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(t,e=20){if(!this.adaptive||!t||isNaN(t))return e;let i=Math.ceil(t/this.maxLength);return i<this.minSegments?i=this.minSegments:i>this.maxSegments&&(i=this.maxSegments),i}};class Mv{static curveTo(t,e,i,s,r,n){const o=n[n.length-2],a=n[n.length-1]-e,l=o-t,h=s-e,u=i-t,c=Math.abs(a*u-l*h);if(c<1e-8||0===r)return(n[n.length-2]!==t||n[n.length-1]!==e)&&n.push(t,e),null;const d=a*a+l*l,p=h*h+u*u,f=a*h+l*u,m=r*Math.sqrt(d)/c,g=r*Math.sqrt(p)/c,y=m*f/d,v=g*f/p,x=m*u+g*l,b=m*h+g*a,_=l*(g+y),w=a*(g+y),P=u*(m+v),E=h*(m+v);return{cx:x+t,cy:b+e,radius:r,startAngle:Math.atan2(w-b,_-x),endAngle:Math.atan2(E-b,P-x),anticlockwise:l*h>u*a}}static arc(t,e,i,s,r,n,o,a,l){const h=o-n,u=Cv._segmentsCount(Math.abs(h)*r,40*Math.ceil(Math.abs(h)/km)),c=h/(2*u),d=2*c,p=Math.cos(c),f=Math.sin(c),m=u-1,g=m%1/m;for(let y=0;y<=m;++y){const t=c+n+d*(y+g*y),e=Math.cos(t),o=-Math.sin(t);l.push((p*e+f*o)*r+i,(p*-o+f*e)*r+s)}}}class Ov{constructor(){this.reset()}begin(t,e,i){this.reset(),this.style=t,this.start=e,this.attribStart=i}end(t,e){this.attribSize=e-this.attribStart,this.size=t-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class Nv{static curveLength(t,e,i,s,r,n,o,a){let l=0,h=0,u=0,c=0,d=0,p=0,f=0,m=0,g=0,y=0,v=0,x=t,b=e;for(let _=1;_<=10;++_)h=_/10,u=h*h,c=u*h,d=1-h,p=d*d,f=p*d,m=f*t+3*p*h*i+3*d*u*r+c*o,g=f*e+3*p*h*s+3*d*u*n+c*a,y=x-m,v=b-g,x=m,b=g,l+=Math.sqrt(y*y+v*v);return l}static curveTo(t,e,i,s,r,n,o){const a=o[o.length-2],l=o[o.length-1];o.length-=2;const h=Cv._segmentsCount(Nv.curveLength(a,l,t,e,i,s,r,n));let u=0,c=0,d=0,p=0,f=0;o.push(a,l);for(let m=1,g=0;m<=h;++m)g=m/h,u=1-g,c=u*u,d=c*u,p=g*g,f=p*g,o.push(d*a+3*c*g*t+3*u*p*i+f*r,d*l+3*c*g*e+3*u*p*s+f*n)}}function Lv(t,e,i,s,r,n,o,a){let l,h;o?(l=s,h=-i):(l=-s,h=i);const u=t-i*r+l,c=e-s*r+h,d=t+i*n+l,p=e+s*n+h;return a.push(u,c,d,p),2}function Rv(t,e,i,s,r,n,o,a){const l=i-t,h=s-e;let u=Math.atan2(l,h),c=Math.atan2(r-t,n-e);a&&u<c?u+=2*Math.PI:!a&&u>c&&(c+=2*Math.PI);let d=u;const p=c-u,f=Math.abs(p),m=Math.sqrt(l*l+h*h),g=1+(15*f*Math.sqrt(m)/Math.PI|0),y=p/g;if(d+=y,a){o.push(t,e,i,s);for(let i=1,s=d;i<g;i++,s+=y)o.push(t,e,t+Math.sin(s)*m,e+Math.cos(s)*m);o.push(t,e,r,n)}else{o.push(i,s,t,e);for(let i=1,s=d;i<g;i++,s+=y)o.push(t+Math.sin(s)*m,e+Math.cos(s)*m,t,e);o.push(r,n,t,e)}return 2*g}function kv(t,e){t.lineStyle.native?function(t,e){let i=0;const s=t.shape,r=t.points||s.points,n=s.type!==Dm.POLY||s.closeStroke;if(0===r.length)return;const o=e.points,a=e.indices,l=r.length/2,h=o.length/2;let u=h;for(o.push(r[0],r[1]),i=1;i<l;i++)o.push(r[2*i],r[2*i+1]),a.push(u,u+1),u++;n&&a.push(u,h)}(t,e):function(t,e){const i=t.shape;let s=t.points||i.points.slice();const r=e.closePointEps;if(0===s.length)return;const n=t.lineStyle,o=new Um(s[0],s[1]),a=new Um(s[s.length-2],s[s.length-1]),l=i.type!==Dm.POLY||i.closeStroke,h=Math.abs(o.x-a.x)<r&&Math.abs(o.y-a.y)<r;if(l){s=s.slice(),h&&(s.pop(),s.pop(),a.set(s[s.length-2],s[s.length-1]));const t=.5*(o.x+a.x),e=.5*(a.y+o.y);s.unshift(t,e),s.push(t,e)}const u=e.points,c=s.length/2;let d=s.length;const p=u.length/2,f=n.width/2,m=f*f,g=n.miterLimit*n.miterLimit;let y=s[0],v=s[1],x=s[2],b=s[3],_=0,w=0,P=-(v-b),E=y-x,T=0,A=0,I=Math.sqrt(P*P+E*E);P/=I,E/=I,P*=f,E*=f;const S=n.alignment,C=2*(1-S),M=2*S;l||(n.cap===Sv.ROUND?d+=Rv(y-P*(C-M)*.5,v-E*(C-M)*.5,y-P*C,v-E*C,y+P*M,v+E*M,u,!0)+2:n.cap===Sv.SQUARE&&(d+=Lv(y,v,P,E,C,M,!0,u))),u.push(y-P*C,v-E*C,y+P*M,v+E*M);for(let L=1;L<c-1;++L){y=s[2*(L-1)],v=s[2*(L-1)+1],x=s[2*L],b=s[2*L+1],_=s[2*(L+1)],w=s[2*(L+1)+1],P=-(v-b),E=y-x,I=Math.sqrt(P*P+E*E),P/=I,E/=I,P*=f,E*=f,T=-(b-w),A=x-_,I=Math.sqrt(T*T+A*A),T/=I,A/=I,T*=f,A*=f;const t=x-y,e=v-b,i=x-_,r=w-b,o=t*i+e*r,a=e*i-r*t,l=a<0;if(Math.abs(a)<.001*Math.abs(o)){u.push(x-P*C,b-E*C,x+P*M,b+E*M),o>=0&&(n.join===Iv.ROUND?d+=Rv(x,b,x-P*C,b-E*C,x-T*C,b-A*C,u,!1)+4:d+=2,u.push(x-T*M,b-A*M,x+T*C,b+A*C));continue}const h=(-P+y)*(-E+b)-(-P+x)*(-E+v),c=(-T+_)*(-A+b)-(-T+x)*(-A+w),p=(t*c-i*h)/a,S=(r*h-e*c)/a,O=(p-x)*(p-x)+(S-b)*(S-b),N=x+(p-x)*C,R=b+(S-b)*C,k=x-(p-x)*M,B=b-(S-b)*M,F=l?C:M,D=O<=Math.min(t*t+e*e,i*i+r*r)+F*F*m;let U=n.join;if(U===Iv.MITER&&O/m>g&&(U=Iv.BEVEL),D)switch(U){case Iv.MITER:u.push(N,R,k,B);break;case Iv.BEVEL:l?u.push(N,R,x+P*M,b+E*M,N,R,x+T*M,b+A*M):u.push(x-P*C,b-E*C,k,B,x-T*C,b-A*C,k,B),d+=2;break;case Iv.ROUND:l?(u.push(N,R,x+P*M,b+E*M),d+=Rv(x,b,x+P*M,b+E*M,x+T*M,b+A*M,u,!0)+4,u.push(N,R,x+T*M,b+A*M)):(u.push(x-P*C,b-E*C,k,B),d+=Rv(x,b,x-P*C,b-E*C,x-T*C,b-A*C,u,!1)+4,u.push(x-T*C,b-A*C,k,B))}else{switch(u.push(x-P*C,b-E*C,x+P*M,b+E*M),U){case Iv.MITER:l?u.push(k,B,k,B):u.push(N,R,N,R),d+=2;break;case Iv.ROUND:d+=l?Rv(x,b,x+P*M,b+E*M,x+T*M,b+A*M,u,!0)+2:Rv(x,b,x-P*C,b-E*C,x-T*C,b-A*C,u,!1)+2}u.push(x-T*C,b-A*C,x+T*M,b+A*M),d+=2}}y=s[2*(c-2)],v=s[2*(c-2)+1],x=s[2*(c-1)],b=s[2*(c-1)+1],P=-(v-b),E=y-x,I=Math.sqrt(P*P+E*E),P/=I,E/=I,P*=f,E*=f,u.push(x-P*C,b-E*C,x+P*M,b+E*M),l||(n.cap===Sv.ROUND?d+=Rv(x-P*(C-M)*.5,b-E*(C-M)*.5,x-P*C,b-E*C,x+P*M,b+E*M,u,!1)+2:n.cap===Sv.SQUARE&&(d+=Lv(x,b,P,E,C,M,!1,u)));const O=e.indices,N=Cv.epsilon*Cv.epsilon;for(let L=p;L<d+p-2;++L)y=u[2*L],v=u[2*L+1],x=u[2*(L+1)],b=u[2*(L+1)+1],_=u[2*(L+2)],w=u[2*(L+2)+1],!(Math.abs(y*(b-w)+x*(w-v)+_*(v-b))<N)&&O.push(L,L+1,L+2)}(t,e)}class Bv{static curveLength(t,e,i,s,r,n){const o=t-2*i+r,a=e-2*s+n,l=2*i-2*t,h=2*s-2*e,u=4*(o*o+a*a),c=4*(o*l+a*h),d=l*l+h*h,p=2*Math.sqrt(u+c+d),f=Math.sqrt(u),m=2*u*f,g=2*Math.sqrt(d),y=c/f;return(m*p+f*c*(p-g)+(4*d*u-c*c)*Math.log((2*f+y+p)/(y+g)))/(4*m)}static curveTo(t,e,i,s,r){const n=r[r.length-2],o=r[r.length-1],a=Cv._segmentsCount(Bv.curveLength(n,o,t,e,i,s));let l=0,h=0;for(let u=1;u<=a;++u){const c=u/a;l=n+(t-n)*c,h=o+(e-o)*c,r.push(l+(t+(i-t)*c-l)*c,h+(e+(s-e)*c-h)*c)}}}const Fv={[Dm.POLY]:Ev,[Dm.CIRC]:wv,[Dm.ELIP]:wv,[Dm.RECT]:Tv,[Dm.RREC]:Av},Dv=[],Uv=[];class Gv{constructor(t,e=null,i=null,s=null){this.points=[],this.holes=[],this.shape=t,this.lineStyle=i,this.fillStyle=e,this.matrix=s,this.type=t.type}clone(){return new Gv(this.shape,this.fillStyle,this.lineStyle,this.matrix)}destroy(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null}}const Xv=new Um,Wv=class t extends Rm{constructor(){super(),this.closePointEps=1e-4,this.boundsPadding=0,this.uvsFloat32=null,this.indicesUint16=null,this.batchable=!1,this.points=[],this.colors=[],this.uvs=[],this.indices=[],this.textureIds=[],this.graphicsData=[],this.drawCalls=[],this.batchDirty=-1,this.batches=[],this.dirty=0,this.cacheDirty=-1,this.clearDirty=0,this.shapeIndex=0,this._bounds=new dv,this.boundsDirty=-1}get bounds(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds}invalidate(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(let t=0;t<this.drawCalls.length;t++)this.drawCalls[t].texArray.clear(),Uv.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),Dv.push(e)}this.batches.length=0}clear(){return this.graphicsData.length>0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(t,e=null,i=null,s=null){const r=new Gv(t,e,i,s);return this.graphicsData.push(r),this.dirty++,this}drawHole(t,e=null){if(!this.graphicsData.length)return null;const i=new Gv(t,null,null,e),s=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=s.lineStyle,s.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let t=0;t<this.graphicsData.length;++t)this.graphicsData[t].destroy();this.points.length=0,this.points=null,this.colors.length=0,this.colors=null,this.uvs.length=0,this.uvs=null,this.indices.length=0,this.indices=null,this.indexBuffer.destroy(),this.indexBuffer=null,this.graphicsData.length=0,this.graphicsData=null,this.drawCalls.length=0,this.drawCalls=null,this.batches.length=0,this.batches=null,this._bounds=null}containsPoint(t){const e=this.graphicsData;for(let i=0;i<e.length;++i){const s=e[i];if(s.fillStyle.visible&&s.shape&&(s.matrix?s.matrix.applyInverse(t,Xv):Xv.copyFrom(t),s.shape.contains(Xv.x,Xv.y))){let t=!1;if(s.holes)for(let e=0;e<s.holes.length;e++)if(s.holes[e].shape.contains(Xv.x,Xv.y)){t=!0;break}if(!t)return!0}}return!1}updateBatches(){if(!this.graphicsData.length)return void(this.batchable=!0);if(!this.validateBatching())return;this.cacheDirty=this.dirty;const t=this.uvs,e=this.graphicsData;let i=null,s=null;this.batches.length>0&&(i=this.batches[this.batches.length-1],s=i.style);for(let a=this.shapeIndex;a<e.length;a++){this.shapeIndex++;const r=e[a],n=r.fillStyle,o=r.lineStyle;Fv[r.type].build(r),r.matrix&&this.transformPoints(r.points,r.matrix),(n.visible||o.visible)&&this.processHoles(r.holes);for(let e=0;e<2;e++){const a=0===e?n:o;if(!a.visible)continue;const l=a.texture.baseTexture,h=this.indices.length,u=this.points.length/2;l.wrapMode=Ql.REPEAT,0===e?this.processFill(r):this.processLine(r);const c=this.points.length/2-u;0!==c&&(i&&!this._compareStyles(s,a)&&(i.end(h,u),i=null),i||(i=Dv.pop()||new Ov,i.begin(a,h,u),this.batches.push(i),s=a),this.addUvs(this.points,t,a.texture,u,c,a.matrix))}}const r=this.indices.length,n=this.points.length/2;if(i&&i.end(r,n),0===this.batches.length)return void(this.batchable=!0);const o=n>65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&o===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=o?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(t,e){return!(!t||!e||t.texture.baseTexture!==e.texture.baseTexture||t.color+t.alpha!==e.color+e.alpha||!!t.native!=!!e.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let t=0,e=this.graphicsData.length;t<e;t++){const e=this.graphicsData[t],i=e.fillStyle,s=e.lineStyle;if(i&&!i.texture.baseTexture.valid||s&&!s.texture.baseTexture.valid)return!1}return!0}packBatches(){this.batchDirty++,this.uvsFloat32=new Float32Array(this.uvs);const t=this.batches;for(let e=0,i=t.length;e<i;e++){const i=t[e];for(let t=0;t<i.size;t++){const e=i.start+t;this.indicesUint16[e]=this.indicesUint16[e]-i.attribStart}}}isBatchable(){if(this.points.length>131070)return!1;const e=this.batches;for(let t=0;t<e.length;t++)if(e[t].style.native)return!1;return this.points.length<2*t.BATCHABLE_SIZE}buildDrawCalls(){let t=++Em._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),Uv.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let s=Uv.pop();s||(s=new Tm,s.texArray=new Mg),s.texArray.count=0,s.start=0,s.size=0,s.type=zl.TRIANGLES;let r=0,n=null,o=0,a=!1,l=zl.TRIANGLES,h=0;this.drawCalls.push(s);for(let u=0;u<this.batches.length;u++){const c=this.batches[u],d=8,p=c.style,f=p.texture.baseTexture;a!==!!p.native&&(a=!!p.native,l=a?zl.LINES:zl.TRIANGLES,n=null,r=d,t++),n!==f&&(n=f,f._batchEnabled!==t&&(r===d&&(t++,r=0,s.size>0&&(s=Uv.pop(),s||(s=new Tm,s.texArray=new Mg),this.drawCalls.push(s)),s.start=h,s.size=0,s.texArray.count=0,s.type=l),f.touched=1,f._batchEnabled=t,f._batchLocation=r,f.wrapMode=Ql.REPEAT,s.texArray.elements[s.texArray.count++]=f,r++)),s.size+=c.size,h+=c.size,o=f._batchLocation,this.addColors(e,p.color,p.alpha,c.attribSize,c.attribStart),this.addTextureIds(i,o,c.attribSize,c.attribStart)}Em._globalBatch=t,this.packAttributes()}packAttributes(){const t=this.points,e=this.uvs,i=this.colors,s=this.textureIds,r=new ArrayBuffer(3*t.length*4),n=new Float32Array(r),o=new Uint32Array(r);let a=0;for(let l=0;l<t.length/2;l++)n[a++]=t[2*l],n[a++]=t[2*l+1],n[a++]=e[2*l],n[a++]=e[2*l+1],o[a++]=i[l],n[a++]=s[l];this._buffer.update(r),this._indexBuffer.update(this.indicesUint16)}processFill(t){t.holes.length?Ev.triangulate(t,this):Fv[t.type].triangulate(t,this)}processLine(t){kv(t,this);for(let e=0;e<t.holes.length;e++)kv(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];Fv[i.type].build(i),i.matrix&&this.transformPoints(i.points,i.matrix)}}calculateBounds(){const t=this._bounds;t.clear(),t.addVertexData(this.points,0,this.points.length),t.pad(this.boundsPadding,this.boundsPadding)}transformPoints(t,e){for(let i=0;i<t.length/2;i++){const s=t[2*i],r=t[2*i+1];t[2*i]=e.a*s+e.c*r+e.tx,t[2*i+1]=e.b*s+e.d*r+e.ty}}addColors(t,e,i,s,r=0){const n=Ff.shared.setValue(e).toLittleEndianNumber(),o=Ff.shared.setValue(n).toPremultiplied(i);t.length=Math.max(t.length,r+s);for(let a=0;a<s;a++)t[r+a]=o}addTextureIds(t,e,i,s=0){t.length=Math.max(t.length,s+i);for(let r=0;r<i;r++)t[s+r]=e}addUvs(t,e,i,s,r,n=null){let o=0;const a=e.length,l=i.frame;for(;o<r;){let i=t[2*(s+o)],r=t[2*(s+o)+1];if(n){const t=n.a*i+n.c*r+n.tx;r=n.b*i+n.d*r+n.ty,i=t}o++,e.push(i/l.width,r/l.height)}const h=i.baseTexture;(l.width<h.width||l.height<h.height)&&this.adjustUvs(e,i,a,r)}adjustUvs(t,e,i,s){const r=e.baseTexture,n=1e-6,o=i+2*s,a=e.frame,l=a.width/r.width,h=a.height/r.height;let u=a.x/a.width,c=a.y/a.height,d=Math.floor(t[i]+n),p=Math.floor(t[i+1]+n);for(let f=i+2;f<o;f+=2)d=Math.min(d,Math.floor(t[f]+n)),p=Math.min(p,Math.floor(t[f+1]+n));u-=d,c-=p;for(let f=i;f<o;f+=2)t[f]=(t[f]+u)*l,t[f+1]=(t[f+1]+c)*h}};Wv.BATCHABLE_SIZE=100;let Hv=Wv;class Yv{constructor(){this.color=16777215,this.alpha=1,this.texture=zg.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new Yv;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t}reset(){this.color=16777215,this.alpha=1,this.texture=zg.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class $v extends Yv{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=Sv.BUTT,this.join=Iv.MITER,this.miterLimit=10}clone(){const t=new $v;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t.width=this.width,t.alignment=this.alignment,t.native=this.native,t.cap=this.cap,t.join=this.join,t.miterLimit=this.miterLimit,t}reset(){super.reset(),this.color=0,this.alignment=.5,this.width=0,this.native=!1,this.cap=Sv.BUTT,this.join=Iv.MITER,this.miterLimit=10}}const jv={},zv=class t extends vv{constructor(t=null){super(),this.shader=null,this.pluginName="batch",this.currentPath=null,this.batches=[],this.batchTint=-1,this.batchDirty=-1,this.vertexData=null,this._fillStyle=new Yv,this._lineStyle=new $v,this._matrix=null,this._holeMode=!1,this.state=gm.for2d(),this._geometry=t||new Hv,this._geometry.refCount++,this._transformID=-1,this._tintColor=new Ff(16777215),this.blendMode=jl.NORMAL}get geometry(){return this._geometry}clone(){return this.finishPoly(),new t(this._geometry)}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t)}get fill(){return this._fillStyle}get line(){return this._lineStyle}lineStyle(t=null,e=0,i,s=.5,r=!1){return"number"==typeof t&&(t={width:t,color:e,alpha:i,alignment:s,native:r}),this.lineTextureStyle(t)}lineTextureStyle(t){const e={width:0,texture:zg.WHITE,color:(null==t?void 0:t.texture)?16777215:0,matrix:null,alignment:.5,native:!1,cap:Sv.BUTT,join:Iv.MITER,miterLimit:10};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.width>0&&t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._lineStyle,{visible:i},t)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const t=this.currentPath.points,e=this.currentPath.points.length;e>2&&(this.drawShape(this.currentPath),this.currentPath=new Ym,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new Ym,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(t,e){return this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this}lineTo(t,e){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,s=i[i.length-2],r=i[i.length-1];return(s!==t||r!==e)&&i.push(t,e),this}_initCurve(t=0,e=0){this.currentPath?0===this.currentPath.points.length&&(this.currentPath.points=[t,e]):this.moveTo(t,e)}quadraticCurveTo(t,e,i,s){this._initCurve();const r=this.currentPath.points;return 0===r.length&&this.moveTo(0,0),Bv.curveTo(t,e,i,s,r),this}bezierCurveTo(t,e,i,s,r,n){return this._initCurve(),Nv.curveTo(t,e,i,s,r,n,this.currentPath.points),this}arcTo(t,e,i,s,r){this._initCurve(t,e);const n=this.currentPath.points,o=Mv.curveTo(t,e,i,s,r,n);if(o){const{cx:t,cy:e,radius:i,startAngle:s,endAngle:r,anticlockwise:n}=o;this.arc(t,e,i,s,r,n)}return this}arc(t,e,i,s,r,n=!1){if(s===r)return this;if(!n&&r<=s?r+=km:n&&s<=r&&(s+=km),r-s==0)return this;const o=t+Math.cos(s)*i,a=e+Math.sin(s)*i,l=this._geometry.closePointEps;let h=this.currentPath?this.currentPath.points:null;if(h){const t=Math.abs(h[h.length-2]-o),e=Math.abs(h[h.length-1]-a);t<l&&e<l||h.push(o,a)}else this.moveTo(o,a),h=this.currentPath.points;return Mv.arc(o,a,t,e,i,s,r,n,h),this}beginFill(t=0,e){return this.beginTextureFill({texture:zg.WHITE,color:t,alpha:e})}normalizeColor(t){const e=Ff.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:zg.WHITE,color:16777215,matrix:null};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._fillStyle,{visible:i},t)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(t,e,i,s){return this.drawShape(new Xm(t,e,i,s))}drawRoundedRect(t,e,i,s,r){return this.drawShape(new $m(t,e,i,s,r))}drawCircle(t,e,i){return this.drawShape(new Wm(t,e,i))}drawEllipse(t,e,i,s){return this.drawShape(new Hm(t,e,i,s))}drawPolygon(...t){let e,i=!0;const s=t[0];s.points?(i=s.closeStroke,e=s.points):e=Array.isArray(t[0])?t[0]:t;const r=new Ym(e);return r.closeStroke=i,this.drawShape(r),this}drawShape(t){return this._holeMode?this._geometry.drawHole(t,this._matrix):this._geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const t=this._geometry.graphicsData;return!(1!==t.length||t[0].shape.type!==Dm.RECT||t[0].matrix||t[0].holes.length||t[0].lineStyle.visible&&t[0].lineStyle.width)}_render(t){this.finishPoly();const e=this._geometry;e.updateBatches(),e.batchable?(this.batchDirty!==e.batchDirty&&this._populateBatches(),this._renderBatched(t)):(t.batch.flush(),this._renderDirect(t))}_populateBatches(){const t=this._geometry,e=this.blendMode,i=t.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=t.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(t.points);for(let s=0;s<i;s++){const i=t.batches[s],r=i.style.color,n=new Float32Array(this.vertexData.buffer,4*i.attribStart*2,2*i.attribSize),o=new Float32Array(t.uvsFloat32.buffer,4*i.attribStart*2,2*i.attribSize),a={vertexData:n,blendMode:e,indices:new Uint16Array(t.indicesUint16.buffer,2*i.start,i.size),uvs:o,_batchRGB:Ff.shared.setValue(r).toRgbArray(),_tintRGB:r,_texture:i.style.texture,alpha:i.style.alpha,worldAlpha:1};this.batches[s]=a}}_renderBatched(t){if(this.batches.length){t.batch.setObjectRenderer(t.plugins[this.pluginName]),this.calculateVertices(),this.calculateTints();for(let e=0,i=this.batches.length;e<i;e++){const i=this.batches[e];i.worldAlpha=this.worldAlpha*i.alpha,t.plugins[this.pluginName].render(i)}}}_renderDirect(t){const e=this._resolveDirectShader(t),i=this._geometry,s=this.worldAlpha,r=e.uniforms,n=i.drawCalls;r.translationMatrix=this.transform.worldTransform,Ff.shared.setValue(this._tintColor).premultiply(s).toArray(r.tint),t.shader.bind(e),t.geometry.bind(i,e),t.state.set(this.state);for(let o=0,a=n.length;o<a;o++)this._renderDrawCallDirect(t,i.drawCalls[o])}_renderDrawCallDirect(t,e){const{texArray:i,type:s,size:r,start:n}=e,o=i.count;for(let a=0;a<o;a++)t.texture.bind(i.elements[a],a);t.geometry.draw(s,r,n)}_resolveDirectShader(t){let e=this.shader;const i=this.pluginName;if(!e){if(!jv[i]){const{maxTextures:e}=t.plugins[i],s=new Int32Array(e);for(let t=0;t<e;t++)s[t]=t;const r={tint:new Float32Array([1,1,1,1]),translationMatrix:new jm,default:Ig.from({uSamplers:s},!0)},n=t.plugins[i]._shader.program;jv[i]=new Sg(n,r)}e=jv[i]}return e}_calculateBounds(){this.finishPoly();const t=this._geometry;if(!t.graphicsData.length)return;const{minX:e,minY:i,maxX:s,maxY:r}=t.bounds;this._bounds.addFrame(this.transform,e,i,s,r)}containsPoint(e){return this.worldTransform.applyInverse(e,t._TEMP_POINT),this._geometry.containsPoint(t._TEMP_POINT)}calculateTints(){if(this.batchTint!==this.tint){this.batchTint=this._tintColor.toNumber();for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e._tintRGB=Ff.shared.setValue(this._tintColor).multiply(e._batchRGB).toLittleEndianNumber()}}}calculateVertices(){const t=this.transform._worldID;if(this._transformID===t)return;this._transformID=t;const e=this.transform.worldTransform,i=e.a,s=e.b,r=e.c,n=e.d,o=e.tx,a=e.ty,l=this._geometry.points,h=this.vertexData;let u=0;for(let c=0;c<l.length;c+=2){const t=l[c],e=l[c+1];h[u++]=i*t+r*e+o,h[u++]=n*e+s*t+a}}closePath(){const t=this.currentPath;return t&&(t.closeStroke=!0,this.finishPoly()),this}setMatrix(t){return this._matrix=t,this}beginHole(){return this.finishPoly(),this._holeMode=!0,this}endHole(){return this.finishPoly(),this._holeMode=!1,this}destroy(t){this._geometry.refCount--,0===this._geometry.refCount&&this._geometry.dispose(),this._matrix=null,this.currentPath=null,this._lineStyle.destroy(),this._lineStyle=null,this._fillStyle.destroy(),this._fillStyle=null,this._geometry=null,this.shader=null,this.vertexData=null,this.batches.length=0,this.batches=null,super.destroy(t)}};zv.curves=Cv,zv._TEMP_POINT=new Um;let Vv=zv;var qv=(t=>(t[t.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",t[t.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",t))(qv||{});const Jv={willReadFrequently:!0},Kv=class t{static get experimentalLetterSpacingSupported(){let e=t._experimentalLetterSpacingSupported;if(void 0!==e){const i=lh.ADAPTER.getCanvasRenderingContext2D().prototype;e=t._experimentalLetterSpacingSupported="letterSpacing"in i||"textLetterSpacing"in i}return e}constructor(t,e,i,s,r,n,o,a,l){this.text=t,this.style=e,this.width=i,this.height=s,this.lines=r,this.lineWidths=n,this.lineHeight=o,this.maxLineWidth=a,this.fontProperties=l}static measureText(e,i,s,r=t._canvas){s=s??i.wordWrap;const n=i.toFontString(),o=t.measureFont(n);0===o.fontSize&&(o.fontSize=i.fontSize,o.ascent=i.fontSize);const a=r.getContext("2d",Jv);a.font=n;const l=(s?t.wordWrap(e,i,r):e).split(/(?:\r\n|\r|\n)/),h=new Array(l.length);let u=0;for(let f=0;f<l.length;f++){const e=t._measureText(l[f],i.letterSpacing,a);h[f]=e,u=Math.max(u,e)}let c=u+i.strokeThickness;i.dropShadow&&(c+=i.dropShadowDistance);const d=i.lineHeight||o.fontSize+i.strokeThickness;let p=Math.max(d,o.fontSize+2*i.strokeThickness)+i.leading+(l.length-1)*(d+i.leading);return i.dropShadow&&(p+=i.dropShadowDistance),new t(e,i,c,p,l,h,d+i.leading,u,o)}static _measureText(e,i,s){let r=!1;t.experimentalLetterSpacingSupported&&(t.experimentalLetterSpacing?(s.letterSpacing=`${i}px`,s.textLetterSpacing=`${i}px`,r=!0):(s.letterSpacing="0px",s.textLetterSpacing="0px"));let n=s.measureText(e).width;return n>0&&(r?n-=i:n+=(t.graphemeSegmenter(e).length-1)*i),n}static wordWrap(e,i,s=t._canvas){const r=s.getContext("2d",Jv);let n=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:u}=i,c=t.collapseSpaces(u),d=t.collapseNewlines(u);let p=!c;const f=i.wordWrapWidth+h,m=t.tokenize(e);for(let g=0;g<m.length;g++){let e=m[g];if(t.isNewline(e)){if(!d){a+=t.addLine(o),p=!c,o="",n=0;continue}e=" "}if(c){const i=t.isBreakingSpace(e),s=t.isBreakingSpace(o[o.length-1]);if(i&&s)continue}const s=t.getFromCache(e,h,l,r);if(s>f)if(""!==o&&(a+=t.addLine(o),o="",n=0),t.canBreakWords(e,i.breakWords)){const s=t.wordWrapSplit(e);for(let u=0;u<s.length;u++){let c=s[u],d=c,m=1;for(;s[u+m];){const r=s[u+m];if(t.canBreakChars(d,r,e,u,i.breakWords))break;c+=r,d=r,m++}u+=m-1;const g=t.getFromCache(c,h,l,r);g+n>f&&(a+=t.addLine(o),p=!1,o="",n=0),o+=c,n+=g}}else{o.length>0&&(a+=t.addLine(o),o="",n=0);const i=g===m.length-1;a+=t.addLine(e,!i),p=!1,o="",n=0}else s+n>f&&(p=!1,a+=t.addLine(o),o="",n=0),(o.length>0||!t.isBreakingSpace(e)||p)&&(o+=e,n+=s)}return a+=t.addLine(o,!1),a}static addLine(e,i=!0){return e=t.trimRight(e),e=i?`${e}\n`:e}static getFromCache(e,i,s,r){let n=s[e];return"number"!=typeof n&&(n=t._measureText(e,i,r)+i,s[e]=n),n}static collapseSpaces(t){return"normal"===t||"pre-line"===t}static collapseNewlines(t){return"normal"===t}static trimRight(e){if("string"!=typeof e)return"";for(let i=e.length-1;i>=0;i--){const s=e[i];if(!t.isBreakingSpace(s))break;e=e.slice(0,-1)}return e}static isNewline(e){return"string"==typeof e&&t._newlines.includes(e.charCodeAt(0))}static isBreakingSpace(e,i){return"string"==typeof e&&t._breakingSpaces.includes(e.charCodeAt(0))}static tokenize(e){const i=[];let s="";if("string"!=typeof e)return i;for(let r=0;r<e.length;r++){const n=e[r],o=e[r+1];t.isBreakingSpace(n,o)||t.isNewline(n)?(""!==s&&(i.push(s),s=""),i.push(n)):s+=n}return""!==s&&i.push(s),i}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,s,r){return!0}static wordWrapSplit(e){return t.graphemeSegmenter(e)}static measureFont(e){if(t._fonts[e])return t._fonts[e];const i={ascent:0,descent:0,fontSize:0},s=t._canvas,r=t._context;r.font=e;const n=t.METRICS_STRING+t.BASELINE_SYMBOL,o=Math.ceil(r.measureText(n).width);let a=Math.ceil(r.measureText(t.BASELINE_SYMBOL).width);const l=Math.ceil(t.HEIGHT_MULTIPLIER*a);if(a=a*t.BASELINE_MULTIPLIER|0,0===o||0===l)return t._fonts[e]=i,i;s.width=o,s.height=l,r.fillStyle="#f00",r.fillRect(0,0,o,l),r.font=e,r.textBaseline="alphabetic",r.fillStyle="#000",r.fillText(n,0,a);const h=r.getImageData(0,0,o,l).data,u=h.length,c=4*o;let d=0,p=0,f=!1;for(d=0;d<a;++d){for(let t=0;t<c;t+=4)if(255!==h[p+t]){f=!0;break}if(f)break;p+=c}for(i.ascent=a-d,p=u-c,f=!1,d=l;d>a;--d){for(let t=0;t<c;t+=4)if(255!==h[p+t]){f=!0;break}if(f)break;p-=c}return i.descent=d-a,i.fontSize=i.ascent+i.descent,t._fonts[e]=i,i}static clearMetrics(e=""){e?delete t._fonts[e]:t._fonts={}}static get _canvas(){var e;if(!t.__canvas){let i;try{const s=new OffscreenCanvas(0,0);if(null==(e=s.getContext("2d",Jv))?void 0:e.measureText)return t.__canvas=s,s;i=lh.ADAPTER.createCanvas()}catch{i=lh.ADAPTER.createCanvas()}i.width=i.height=10,t.__canvas=i}return t.__canvas}static get _context(){return t.__context||(t.__context=t._canvas.getContext("2d",Jv)),t.__context}};Kv.METRICS_STRING="|ÉqÅ",Kv.BASELINE_SYMBOL="M",Kv.BASELINE_MULTIPLIER=1.4,Kv.HEIGHT_MULTIPLIER=2,Kv.graphemeSegmenter=(()=>{if("function"==typeof(null==Intl?void 0:Intl.Segmenter)){const t=new Intl.Segmenter;return e=>[...t.segment(e)].map((t=>t.segment))}return t=>[...t]})(),Kv.experimentalLetterSpacing=!1,Kv._fonts={},Kv._newlines=[10,13],Kv._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let Zv=Kv;const Qv=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],tx=class t{constructor(t){this.styleID=0,this.reset(),sx(this,t,t)}clone(){const e={};return sx(e,this,t.defaultStyle),new t(e)}reset(){sx(this,t.defaultStyle,t.defaultStyle)}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(this._dropShadow=t,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(t){this._dropShadowAlpha!==t&&(this._dropShadowAlpha=t,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(t){this._dropShadowAngle!==t&&(this._dropShadowAngle=t,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(t){this._dropShadowBlur!==t&&(this._dropShadowBlur=t,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(t){const e=ix(t);this._dropShadowColor!==e&&(this._dropShadowColor=e,this.styleID++)}get dropShadowDistance(){return this._dropShadowDistance}set dropShadowDistance(t){this._dropShadowDistance!==t&&(this._dropShadowDistance=t,this.styleID++)}get fill(){return this._fill}set fill(t){const e=ix(t);this._fill!==e&&(this._fill=e,this.styleID++)}get fillGradientType(){return this._fillGradientType}set fillGradientType(t){this._fillGradientType!==t&&(this._fillGradientType=t,this.styleID++)}get fillGradientStops(){return this._fillGradientStops}set fillGradientStops(t){(function(t,e){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(t[i]!==e[i])return!1;return!0})(this._fillGradientStops,t)||(this._fillGradientStops=t,this.styleID++)}get fontFamily(){return this._fontFamily}set fontFamily(t){this.fontFamily!==t&&(this._fontFamily=t,this.styleID++)}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.styleID++)}get fontStyle(){return this._fontStyle}set fontStyle(t){this._fontStyle!==t&&(this._fontStyle=t,this.styleID++)}get fontVariant(){return this._fontVariant}set fontVariant(t){this._fontVariant!==t&&(this._fontVariant=t,this.styleID++)}get fontWeight(){return this._fontWeight}set fontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.styleID++)}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.styleID++)}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight!==t&&(this._lineHeight=t,this.styleID++)}get leading(){return this._leading}set leading(t){this._leading!==t&&(this._leading=t,this.styleID++)}get lineJoin(){return this._lineJoin}set lineJoin(t){this._lineJoin!==t&&(this._lineJoin=t,this.styleID++)}get miterLimit(){return this._miterLimit}set miterLimit(t){this._miterLimit!==t&&(this._miterLimit=t,this.styleID++)}get padding(){return this._padding}set padding(t){this._padding!==t&&(this._padding=t,this.styleID++)}get stroke(){return this._stroke}set stroke(t){const e=ix(t);this._stroke!==e&&(this._stroke=e,this.styleID++)}get strokeThickness(){return this._strokeThickness}set strokeThickness(t){this._strokeThickness!==t&&(this._strokeThickness=t,this.styleID++)}get textBaseline(){return this._textBaseline}set textBaseline(t){this._textBaseline!==t&&(this._textBaseline=t,this.styleID++)}get trim(){return this._trim}set trim(t){this._trim!==t&&(this._trim=t,this.styleID++)}get whiteSpace(){return this._whiteSpace}set whiteSpace(t){this._whiteSpace!==t&&(this._whiteSpace=t,this.styleID++)}get wordWrap(){return this._wordWrap}set wordWrap(t){this._wordWrap!==t&&(this._wordWrap=t,this.styleID++)}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(t){this._wordWrapWidth!==t&&(this._wordWrapWidth=t,this.styleID++)}toFontString(){const t="number"==typeof this.fontSize?`${this.fontSize}px`:this.fontSize;let e=this.fontFamily;Array.isArray(this.fontFamily)||(e=this.fontFamily.split(","));for(let i=e.length-1;i>=0;i--){let t=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(t)&&!Qv.includes(t)&&(t=`"${t}"`),e[i]=t}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};tx.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:qv.LINEAR_VERTICAL,fillGradientStops:[],fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,lineJoin:"miter",miterLimit:10,padding:0,stroke:"black",strokeThickness:0,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let ex=tx;function ix(t){const e=Ff.shared,i=t=>{const i=e.setValue(t);return 1===i.alpha?i.toHex():i.toRgbaString()};return Array.isArray(t)?t.map(i):i(t)}function sx(t,e,i){for(const s in i)Array.isArray(e[s])?t[s]=e[s].slice():t[s]=e[s]}const rx={texture:!0,children:!1,baseTexture:!0},nx=class t extends _v{constructor(e,i,s){let r=!1;s||(s=lh.ADAPTER.createCanvas(),r=!0),s.width=3,s.height=3;const n=zg.from(s);n.orig=new Xm,n.trim=new Xm,super(n),this._ownCanvas=r,this.canvas=s,this.context=s.getContext("2d",{willReadFrequently:!0}),this._resolution=t.defaultResolution??lh.RESOLUTION,this._autoResolution=t.defaultAutoResolution,this._text=null,this._style=null,this._styleListener=null,this._font="",this.text=e,this.style=i,this.localStyleID=-1}static get experimentalLetterSpacing(){return Zv.experimentalLetterSpacing}static set experimentalLetterSpacing(t){Qp("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),Zv.experimentalLetterSpacing=t}updateText(t){const e=this._style;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;this._font=this._style.toFontString();const i=this.context,s=Zv.measureText(this._text||" ",this._style,this._style.wordWrap,this.canvas),r=s.width,n=s.height,o=s.lines,a=s.lineHeight,l=s.lineWidths,h=s.maxLineWidth,u=s.fontProperties;let c,d;this.canvas.width=Math.ceil(Math.ceil(Math.max(1,r)+2*e.padding)*this._resolution),this.canvas.height=Math.ceil(Math.ceil(Math.max(1,n)+2*e.padding)*this._resolution),i.scale(this._resolution,this._resolution),i.clearRect(0,0,this.canvas.width,this.canvas.height),i.font=this._font,i.lineWidth=e.strokeThickness,i.textBaseline=e.textBaseline,i.lineJoin=e.lineJoin,i.miterLimit=e.miterLimit;const p=e.dropShadow?2:1;for(let f=0;f<p;++f){const t=e.dropShadow&&0===f,r=t?Math.ceil(Math.max(1,n)+2*e.padding):0,p=r*this._resolution;if(t){i.fillStyle="black",i.strokeStyle="black";const t=e.dropShadowColor,s=e.dropShadowBlur*this._resolution,r=e.dropShadowDistance*this._resolution;i.shadowColor=Ff.shared.setValue(t).setAlpha(e.dropShadowAlpha).toRgbaString(),i.shadowBlur=s,i.shadowOffsetX=Math.cos(e.dropShadowAngle)*r,i.shadowOffsetY=Math.sin(e.dropShadowAngle)*r+p}else i.fillStyle=this._generateFillStyle(e,o,s),i.strokeStyle=e.stroke,i.shadowColor="black",i.shadowBlur=0,i.shadowOffsetX=0,i.shadowOffsetY=0;let m=(a-u.fontSize)/2;a-u.fontSize<0&&(m=0);for(let i=0;i<o.length;i++)c=e.strokeThickness/2,d=e.strokeThickness/2+i*a+u.ascent+m,"right"===e.align?c+=h-l[i]:"center"===e.align&&(c+=(h-l[i])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(o[i],c+e.padding,d+e.padding-r,!0),e.fill&&this.drawLetterSpacing(o[i],c+e.padding,d+e.padding-r)}this.updateTexture()}drawLetterSpacing(t,e,i,s=!1){const r=this._style.letterSpacing;let n=!1;if(Zv.experimentalLetterSpacingSupported&&(Zv.experimentalLetterSpacing?(this.context.letterSpacing=`${r}px`,this.context.textLetterSpacing=`${r}px`,n=!0):(this.context.letterSpacing="0px",this.context.textLetterSpacing="0px")),0===r||n)return void(s?this.context.strokeText(t,e,i):this.context.fillText(t,e,i));let o=e;const a=Zv.graphemeSegmenter(t);let l=this.context.measureText(t).width,h=0;for(let u=0;u<a.length;++u){const t=a[u];s?this.context.strokeText(t,o,i):this.context.fillText(t,o,i);let e="";for(let i=u+1;i<a.length;++i)e+=a[i];h=this.context.measureText(e).width,o+=l-h+r,l=h}}updateTexture(){const t=this.canvas;if(this._style.trim){const e=nm(t);e.data&&(t.width=e.width,t.height=e.height,this.context.putImageData(e.data,0,0))}const e=this._texture,i=this._style,s=i.trim?0:i.padding,r=e.baseTexture;e.trim.width=e._frame.width=t.width/this._resolution,e.trim.height=e._frame.height=t.height/this._resolution,e.trim.x=-s,e.trim.y=-s,e.orig.width=e._frame.width-2*s,e.orig.height=e._frame.height-2*s,this._onTextureUpdate(),r.setRealSize(t.width,t.height,this._resolution),e.updateUvs(),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}updateTransform(){this.updateText(!0),super.updateTransform()}getBounds(t,e){return this.updateText(!0),-1===this._textureID&&(t=!1),super.getBounds(t,e)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds.call(this,t)}_calculateBounds(){this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_generateFillStyle(t,e,i){const s=t.fill;if(!Array.isArray(s))return s;if(1===s.length)return s[0];let r;const n=t.dropShadow?t.dropShadowDistance:0,o=t.padding||0,a=this.canvas.width/this._resolution-n-2*o,l=this.canvas.height/this._resolution-n-2*o,h=s.slice(),u=t.fillGradientStops.slice();if(!u.length){const t=h.length+1;for(let e=1;e<t;++e)u.push(e/t)}if(h.unshift(s[0]),u.unshift(0),h.push(s[s.length-1]),u.push(1),t.fillGradientType===qv.LINEAR_VERTICAL){r=this.context.createLinearGradient(a/2,o,a/2,l+o);const s=i.fontProperties.fontSize+t.strokeThickness;for(let t=0;t<e.length;t++){const n=i.lineHeight*(t-1)+s,o=i.lineHeight*t;let a=o;t>0&&n>o&&(a=(o+n)/2);const c=o+s,d=i.lineHeight*(t+1);let p=c;t+1<e.length&&d<c&&(p=(c+d)/2);const f=(p-a)/l;for(let t=0;t<h.length;t++){let e=0;e="number"==typeof u[t]?u[t]:t/h.length;let i=Math.min(1,Math.max(0,a/l+e*f));i=Number(i.toFixed(5)),r.addColorStop(i,h[t])}}}else{r=this.context.createLinearGradient(o,l/2,a+o,l/2);const t=h.length+1;let e=1;for(let i=0;i<h.length;i++){let s;s="number"==typeof u[i]?u[i]:e/t,r.addColorStop(s,h[i]),e++}}return r}destroy(t){"boolean"==typeof t&&(t={children:t}),t=Object.assign({},rx,t),super.destroy(t),this._ownCanvas&&(this.canvas.height=this.canvas.width=0),this.context=null,this.canvas=null,this._style=null}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this.updateText(!0);const e=jf(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this.updateText(!0);const e=jf(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get style(){return this._style}set style(t){t=t||{},this._style=t instanceof ex?t:new ex(t),this.localStyleID=-1,this.dirty=!0}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}};nx.defaultAutoResolution=!0;let ox=nx;class ax extends kg{constructor(){super("attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n gl_Position = filterVertexPosition();\n vTextureCoord = filterTextureCoord();\n}\n","varying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float m[20];\nuniform float uAlpha;\n\nvoid main(void)\n{\n vec4 c = texture2D(uSampler, vTextureCoord);\n\n if (uAlpha == 0.0) {\n gl_FragColor = c;\n return;\n }\n\n // Un-premultiply alpha before applying the color matrix. See issue #3539.\n if (c.a > 0.0) {\n c.rgb /= c.a;\n }\n\n vec4 result;\n\n result.r = (m[0] * c.r);\n result.r += (m[1] * c.g);\n result.r += (m[2] * c.b);\n result.r += (m[3] * c.a);\n result.r += m[4];\n\n result.g = (m[5] * c.r);\n result.g += (m[6] * c.g);\n result.g += (m[7] * c.b);\n result.g += (m[8] * c.a);\n result.g += m[9];\n\n result.b = (m[10] * c.r);\n result.b += (m[11] * c.g);\n result.b += (m[12] * c.b);\n result.b += (m[13] * c.a);\n result.b += m[14];\n\n result.a = (m[15] * c.r);\n result.a += (m[16] * c.g);\n result.a += (m[17] * c.b);\n result.a += (m[18] * c.a);\n result.a += m[19];\n\n vec3 rgb = mix(c.rgb, result.rgb, uAlpha);\n\n // Premultiply alpha again.\n rgb *= result.a;\n\n gl_FragColor = vec4(rgb, result.a);\n}\n",{m:new Float32Array([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0]),uAlpha:1}),this.alpha=1}_loadMatrix(t,e=!1){let i=t;e&&(this._multiply(i,this.uniforms.m,t),i=this._colorMatrix(i)),this.uniforms.m=i}_multiply(t,e,i){return t[0]=e[0]*i[0]+e[1]*i[5]+e[2]*i[10]+e[3]*i[15],t[1]=e[0]*i[1]+e[1]*i[6]+e[2]*i[11]+e[3]*i[16],t[2]=e[0]*i[2]+e[1]*i[7]+e[2]*i[12]+e[3]*i[17],t[3]=e[0]*i[3]+e[1]*i[8]+e[2]*i[13]+e[3]*i[18],t[4]=e[0]*i[4]+e[1]*i[9]+e[2]*i[14]+e[3]*i[19]+e[4],t[5]=e[5]*i[0]+e[6]*i[5]+e[7]*i[10]+e[8]*i[15],t[6]=e[5]*i[1]+e[6]*i[6]+e[7]*i[11]+e[8]*i[16],t[7]=e[5]*i[2]+e[6]*i[7]+e[7]*i[12]+e[8]*i[17],t[8]=e[5]*i[3]+e[6]*i[8]+e[7]*i[13]+e[8]*i[18],t[9]=e[5]*i[4]+e[6]*i[9]+e[7]*i[14]+e[8]*i[19]+e[9],t[10]=e[10]*i[0]+e[11]*i[5]+e[12]*i[10]+e[13]*i[15],t[11]=e[10]*i[1]+e[11]*i[6]+e[12]*i[11]+e[13]*i[16],t[12]=e[10]*i[2]+e[11]*i[7]+e[12]*i[12]+e[13]*i[17],t[13]=e[10]*i[3]+e[11]*i[8]+e[12]*i[13]+e[13]*i[18],t[14]=e[10]*i[4]+e[11]*i[9]+e[12]*i[14]+e[13]*i[19]+e[14],t[15]=e[15]*i[0]+e[16]*i[5]+e[17]*i[10]+e[18]*i[15],t[16]=e[15]*i[1]+e[16]*i[6]+e[17]*i[11]+e[18]*i[16],t[17]=e[15]*i[2]+e[16]*i[7]+e[17]*i[12]+e[18]*i[17],t[18]=e[15]*i[3]+e[16]*i[8]+e[17]*i[13]+e[18]*i[18],t[19]=e[15]*i[4]+e[16]*i[9]+e[17]*i[14]+e[18]*i[19]+e[19],t}_colorMatrix(t){const e=new Float32Array(t);return e[4]/=255,e[9]/=255,e[14]/=255,e[19]/=255,e}brightness(t,e){const i=[t,0,0,0,0,0,t,0,0,0,0,0,t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}tint(t,e){const[i,s,r]=Ff.shared.setValue(t).toArray(),n=[i,0,0,0,0,0,s,0,0,0,0,0,r,0,0,0,0,0,1,0];this._loadMatrix(n,e)}greyscale(t,e){const i=[t,t,t,0,0,t,t,t,0,0,t,t,t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}blackAndWhite(t){this._loadMatrix([.3,.6,.1,0,0,.3,.6,.1,0,0,.3,.6,.1,0,0,0,0,0,1,0],t)}hue(t,e){t=(t||0)/180*Math.PI;const i=Math.cos(t),s=Math.sin(t),r=1/3,n=(0,Math.sqrt)(r),o=[i+(1-i)*r,r*(1-i)-n*s,r*(1-i)+n*s,0,0,r*(1-i)+n*s,i+r*(1-i),r*(1-i)-n*s,0,0,r*(1-i)-n*s,r*(1-i)+n*s,i+r*(1-i),0,0,0,0,0,1,0];this._loadMatrix(o,e)}contrast(t,e){const i=(t||0)+1,s=-.5*(i-1),r=[i,0,0,0,s,0,i,0,0,s,0,0,i,0,s,0,0,0,1,0];this._loadMatrix(r,e)}saturate(t=0,e){const i=2*t/3+1,s=-.5*(i-1),r=[i,s,s,0,0,s,i,s,0,0,s,s,i,0,0,0,0,0,1,0];this._loadMatrix(r,e)}desaturate(){this.saturate(-1)}negative(t){this._loadMatrix([-1,0,0,1,0,0,-1,0,1,0,0,0,-1,1,0,0,0,0,1,0],t)}sepia(t){this._loadMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0],t)}technicolor(t){this._loadMatrix([1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0],t)}polaroid(t){this._loadMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0],t)}toBGR(t){this._loadMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0],t)}kodachrome(t){this._loadMatrix([1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0],t)}browni(t){this._loadMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0],t)}vintage(t){this._loadMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0],t)}colorTone(t,e,i,s,r){t=t||.2,e=e||.15,i=i||16770432,s=s||3375104;const n=Ff.shared,[o,a,l]=n.setValue(i).toArray(),[h,u,c]=n.setValue(s).toArray(),d=[.3,.59,.11,0,0,o,a,l,t,0,h,u,c,e,0,o-h,a-u,l-c,0,0];this._loadMatrix(d,r)}night(t,e){const i=[-2*(t=t||.1),-t,0,0,0,-t,0,t,0,0,0,t,2*t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}predator(t,e){const i=[11.224130630493164*t,-4.794486999511719*t,-2.8746118545532227*t,0*t,.40342438220977783*t,-3.6330697536468506*t,9.193157196044922*t,-2.951810836791992*t,0*t,-1.316135048866272*t,-3.2184197902679443*t,-4.2375030517578125*t,7.476448059082031*t,0*t,.8044459223747253*t,0,0,0,1,0];this._loadMatrix(i,e)}lsd(t){this._loadMatrix([2,-.4,.5,0,0,-.5,2,-.4,0,0,-.4,-.5,3,0,0,0,0,0,1,0],t)}reset(){this._loadMatrix([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],!1)}get matrix(){return this.uniforms.m}set matrix(t){this.uniforms.m=t}get alpha(){return this.uniforms.uAlpha}set alpha(t){this.uniforms.uAlpha=t}}ax.prototype.grayscale=ax.prototype.greyscale;var lx={exports:{}};!function(t){(function(){var e;(function(e){t.exports=e})(e={linear:function(t,e,i,s){return i*t/s+e},easeInQuad:function(t,e,i,s){return i*(t/=s)*t+e},easeOutQuad:function(t,e,i,s){return-i*(t/=s)*(t-2)+e},easeInOutQuad:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e},easeInCubic:function(t,e,i,s){return i*(t/=s)*t*t+e},easeOutCubic:function(t,e,i,s){return i*((t=t/s-1)*t*t+1)+e},easeInOutCubic:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e},easeInQuart:function(t,e,i,s){return i*(t/=s)*t*t*t+e},easeOutQuart:function(t,e,i,s){return-i*((t=t/s-1)*t*t*t-1)+e},easeInOutQuart:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e},easeInQuint:function(t,e,i,s){return i*(t/=s)*t*t*t*t+e},easeOutQuint:function(t,e,i,s){return i*((t=t/s-1)*t*t*t*t+1)+e},easeInOutQuint:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e},easeInSine:function(t,e,i,s){return-i*Math.cos(t/s*(Math.PI/2))+i+e},easeOutSine:function(t,e,i,s){return i*Math.sin(t/s*(Math.PI/2))+e},easeInOutSine:function(t,e,i,s){return-i/2*(Math.cos(Math.PI*t/s)-1)+e},easeInExpo:function(t,e,i,s){return 0===t?e:i*Math.pow(2,10*(t/s-1))+e},easeOutExpo:function(t,e,i,s){return t===s?e+i:i*(1-Math.pow(2,-10*t/s))+e},easeInOutExpo:function(t,e,i,s){return(t/=s/2)<1?i/2*Math.pow(2,10*(t-1))+e:i/2*(2-Math.pow(2,-10*--t))+e},easeInCirc:function(t,e,i,s){return-i*(Math.sqrt(1-(t/=s)*t)-1)+e},easeOutCirc:function(t,e,i,s){return i*Math.sqrt(1-(t=t/s-1)*t)+e},easeInOutCirc:function(t,e,i,s){return(t/=s/2)<1?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e},easeInElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)+e},easeOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/n)+i+e},easeInOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s/2),(n=0)||(n=s*(.3*1.5)),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*.5+i+e},easeInBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*(t/=s)*t*((r+1)*t-r)+e},easeOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeInOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInBounce:function(t,i,s,r){return s-e.easeOutBounce(r-t,0,s,r)+i},easeOutBounce:function(t,e,i,s){return(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e},easeInOutBounce:function(t,i,s,r){return t<r/2?.5*e.easeInBounce(2*t,0,s,r)+i:.5*e.easeOutBounce(2*t-r,0,s,r)+.5*s+i}})}).call(Ct)}(lx);const hx=Mt(lx.exports);vv.prototype._renderCanvas=function(t){},vv.prototype.renderCanvas=function(t){if(this.visible&&!(this.worldAlpha<=0)&&this.renderable){this._mask&&t.mask.pushMask(this._mask),this._renderCanvas(t);for(let e=0,i=this.children.length;e<i;++e)this.children[e].renderCanvas(t);this._mask&&t.mask.popMask(t)}},pv.prototype.renderCanvas=function(t){},ox.prototype._renderCanvas=function(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),_v.prototype._renderCanvas.call(this,t)},pv.prototype.name=null,vv.prototype.getChildByName=function(t,e){for(let i=0,s=this.children.length;i<s;i++)if(this.children[i].name===t)return this.children[i];if(e)for(let i=0,s=this.children.length;i<s;i++){const e=this.children[i];if(!e.getChildByName)continue;const s=e.getChildByName(t,!0);if(s)return s}return null};const ux={vec3(t,e,i,s){(i[0]!==s[0]||i[1]!==s[1]||i[2]!==s[2])&&(i[0]=s[0],i[1]=s[1],i[2]=s[2],t.uniform3f(e,s[0],s[1],s[2]))},int(t,e,i,s){t.uniform1i(e,s)},ivec2(t,e,i,s){t.uniform2i(e,s[0],s[1])},ivec3(t,e,i,s){t.uniform3i(e,s[0],s[1],s[2])},ivec4(t,e,i,s){t.uniform4i(e,s[0],s[1],s[2],s[3])},uint(t,e,i,s){t.uniform1ui(e,s)},uvec2(t,e,i,s){t.uniform2ui(e,s[0],s[1])},uvec3(t,e,i,s){t.uniform3ui(e,s[0],s[1],s[2])},uvec4(t,e,i,s){t.uniform4ui(e,s[0],s[1],s[2],s[3])},bvec2(t,e,i,s){t.uniform2i(e,s[0],s[1])},bvec3(t,e,i,s){t.uniform3i(e,s[0],s[1],s[2])},bvec4(t,e,i,s){t.uniform4i(e,s[0],s[1],s[2],s[3])},mat2(t,e,i,s){t.uniformMatrix2fv(e,!1,s)},mat4(t,e,i,s){t.uniformMatrix4fv(e,!1,s)}},cx={float(t,e,i,s){t.uniform1fv(e,s)},vec2(t,e,i,s){t.uniform2fv(e,s)},vec3(t,e,i,s){t.uniform3fv(e,s)},vec4(t,e,i,s){t.uniform4fv(e,s)},int(t,e,i,s){t.uniform1iv(e,s)},ivec2(t,e,i,s){t.uniform2iv(e,s)},ivec3(t,e,i,s){t.uniform3iv(e,s)},ivec4(t,e,i,s){t.uniform4iv(e,s)},uint(t,e,i,s){t.uniform1uiv(e,s)},uvec2(t,e,i,s){t.uniform2uiv(e,s)},uvec3(t,e,i,s){t.uniform3uiv(e,s)},uvec4(t,e,i,s){t.uniform4uiv(e,s)},bool(t,e,i,s){t.uniform1iv(e,s)},bvec2(t,e,i,s){t.uniform2iv(e,s)},bvec3(t,e,i,s){t.uniform3iv(e,s)},bvec4(t,e,i,s){t.uniform4iv(e,s)},sampler2D(t,e,i,s){t.uniform1iv(e,s)},samplerCube(t,e,i,s){t.uniform1iv(e,s)},sampler2DArray(t,e,i,s){t.uniform1iv(e,s)}};Object.assign(Ry.prototype,{systemCheck(){},syncUniforms(t,e){const{shader:i,renderer:s}=this;!function(t,e,i,s,r){let n=0,o=null,a=null;const l=r.gl;for(const h in t.uniforms){const u=e[h],c=s[h],d=i[h],p=t.uniforms[h];u?"float"!==u.type||1!==u.size||u.isArray?"bool"!==u.type||1!==u.size||u.isArray?"sampler2D"!==u.type&&"samplerCube"!==u.type&&"sampler2DArray"!==u.type||1!==u.size||u.isArray?"mat3"!==u.type||1!==u.size||u.isArray?"vec2"!==u.type||1!==u.size||u.isArray?"vec4"!==u.type||1!==u.size||u.isArray?(1!==u.size||u.isArray?cx:ux)[u.type].call(null,l,d.location,d.value,c):void 0!==p.width?(a=d.value,o=c,(a[0]!==o.x||a[1]!==o.y||a[2]!==o.width||a[3]!==o.height)&&(a[0]=o.x,a[1]=o.y,a[2]=o.width,a[3]=o.height,l.uniform4f(d.location,o.x,o.y,o.width,o.height))):(a=d.value,o=c,(a[0]!==o[0]||a[1]!==o[1]||a[2]!==o[2]||a[3]!==o[3])&&(a[0]=o[0],a[1]=o[1],a[2]=o[2],a[3]=o[3],l.uniform4f(d.location,o[0],o[1],o[2],o[3]))):void 0!==p.x?(a=d.value,o=c,(a[0]!==o.x||a[1]!==o.y)&&(a[0]=o.x,a[1]=o.y,l.uniform2f(d.location,o.x,o.y))):(a=d.value,o=c,(a[0]!==o[0]||a[1]!==o[1])&&(a[0]=o[0],a[1]=o[1],l.uniform2f(d.location,o[0],o[1]))):void 0!==p.a?l.uniformMatrix3fv(d.location,!1,c.toArray(!0)):l.uniformMatrix3fv(d.location,!1,c):(r.texture.bind(c,n),d.value!==n&&(d.value=n,l.uniform1i(d.location,n)),n++):c!==d.value&&(d.value=c,l.uniform1i(d.location,Number(c))):c!==d.value&&(d.value=c,l.uniform1f(d.location,c)):!0===p.group&&r.shader.syncUniformGroup(c)}}(t,i.program.uniformData,e.uniformData,t.uniforms,s)}});const dx=new class{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}init(t){this.removeTickerListener(),this.events=t,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(t){this._pauseUpdate=t}addTickerListener(){this.tickerAdded||!this.domElement||(Vy.system.add(this.tickerUpdate,this,$y.INTERACTION),this.tickerAdded=!0)}removeTickerListener(){this.tickerAdded&&(Vy.system.remove(this.tickerUpdate,this),this.tickerAdded=!1)}pointerMoved(){this._didMove=!0}update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove)return void(this._didMove=!1);const t=this.events.rootPointerEvent;this.events.supportsTouchEvents&&"touch"===t.pointerType||globalThis.document.dispatchEvent(new PointerEvent("pointermove",{clientX:t.clientX,clientY:t.clientY}))}tickerUpdate(t){this._deltaTime+=t,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this.update())}};class px{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=px.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new Um,this.page=new Um,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=t}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(t,e,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(t,e,i,s,r){throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}preventDefault(){this.nativeEvent instanceof Event&&this.nativeEvent.cancelable&&this.nativeEvent.preventDefault(),this.defaultPrevented=!0}stopImmediatePropagation(){this.propagationImmediatelyStopped=!0}stopPropagation(){this.propagationStopped=!0}}class fx extends px{constructor(){super(...arguments),this.client=new Um,this.movement=new Um,this.offset=new Um,this.global=new Um,this.screen=new Um}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(t,e,i){return t.worldTransform.applyInverse(i||this.global,e)}getModifierState(t){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(t)}initMouseEvent(t,e,i,s,r,n,o,a,l,h,u,c,d,p,f){throw new Error("Method not implemented.")}}class mx extends fx{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return"pointermove"===this.type||"mousemove"===this.type||"touchmove"===this.type?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class gx extends fx{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}gx.DOM_DELTA_PIXEL=0,gx.DOM_DELTA_LINE=1,gx.DOM_DELTA_PAGE=2;const yx=new Um,vx=new Um;class xx{constructor(t){this.dispatch=new Sh,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=t,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel)}addEventMapping(t,e){this.mappingTable[t]||(this.mappingTable[t]=[]),this.mappingTable[t].push({fn:e,priority:0}),this.mappingTable[t].sort(((t,e)=>t.priority-e.priority))}dispatchEvent(t,e){t.propagationStopped=!1,t.propagationImmediatelyStopped=!1,this.propagate(t,e),this.dispatch.emit(e||t.type,t)}mapEvent(t){if(!this.rootTarget)return;const e=this.mappingTable[t.type];if(e)for(let i=0,s=e.length;i<s;i++)e[i].fn(t);else console.warn(`[EventBoundary]: Event mapping not defined for ${t.type}`)}hitTest(t,e){dx.pauseUpdate=!0;const i=this[this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive"](this.rootTarget,this.rootTarget.eventMode,yx.set(t,e),this.hitTestFn,this.hitPruneFn);return i&&i[0]}propagate(t,e){if(!t.target)return;const i=t.composedPath();t.eventPhase=t.CAPTURING_PHASE;for(let s=0,r=i.length-1;s<r;s++)if(t.currentTarget=i[s],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return;if(t.eventPhase=t.AT_TARGET,t.currentTarget=t.target,this.notifyTarget(t,e),!t.propagationStopped&&!t.propagationImmediatelyStopped){t.eventPhase=t.BUBBLING_PHASE;for(let s=i.length-2;s>=0;s--)if(t.currentTarget=i[s],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return}}all(t,e,i=this._allInteractiveElements){if(0===i.length)return;t.eventPhase=t.BUBBLING_PHASE;const s=Array.isArray(e)?e:[e];for(let r=i.length-1;r>=0;r--)s.forEach((e=>{t.currentTarget=i[r],this.notifyTarget(t,e)}))}propagationPath(t){const e=[t];for(let i=0;i<2048&&t!==this.rootTarget;i++){if(!t.parent)throw new Error("Cannot find propagation path to disconnected target");e.push(t.parent),t=t.parent}return e.reverse(),e}hitTestMoveRecursive(t,e,i,s,r,n=!1){let o=!1;if(this._interactivePrune(t))return null;if(("dynamic"===t.eventMode||"dynamic"===e)&&(dx.pauseUpdate=!1),t.interactiveChildren&&t.children){const a=t.children;for(let l=a.length-1;l>=0;l--){const h=a[l],u=this.hitTestMoveRecursive(h,this._isInteractive(e)?e:h.eventMode,i,s,r,n||r(t,i));if(u){if(u.length>0&&!u[u.length-1].parent)continue;const e=t.isInteractive();(u.length>0||e)&&(e&&this._allInteractiveElements.push(t),u.push(t)),0===this._hitElements.length&&(this._hitElements=u),o=!0}}}const a=this._isInteractive(e),l=t.isInteractive();return a&&l&&this._allInteractiveElements.push(t),n||this._hitElements.length>0?null:o?this._hitElements:a&&!r(t,i)&&s(t,i)?l?[t]:[]:null}hitTestRecursive(t,e,i,s,r){if(this._interactivePrune(t)||r(t,i))return null;if(("dynamic"===t.eventMode||"dynamic"===e)&&(dx.pauseUpdate=!1),t.interactiveChildren&&t.children){const n=t.children;for(let o=n.length-1;o>=0;o--){const a=n[o],l=this.hitTestRecursive(a,this._isInteractive(e)?e:a.eventMode,i,s,r);if(l){if(l.length>0&&!l[l.length-1].parent)continue;const e=t.isInteractive();return(l.length>0||e)&&l.push(t),l}}}const n=this._isInteractive(e),o=t.isInteractive();return n&&s(t,i)?o?[t]:[]:null}_isInteractive(t){return"static"===t||"dynamic"===t}_interactivePrune(t){return!(t&&!t.isMask&&t.visible&&t.renderable&&"none"!==t.eventMode&&("passive"!==t.eventMode||t.interactiveChildren)&&!t.isMask)}hitPruneFn(t,e){var i;if(t.hitArea&&(t.worldTransform.applyInverse(e,vx),!t.hitArea.contains(vx.x,vx.y)))return!0;if(t._mask){const s=t._mask.isMaskData?t._mask.maskObject:t._mask;if(s&&!(null==(i=s.containsPoint)?void 0:i.call(s,e)))return!0}return!1}hitTestFn(t,e){return"passive"!==t.eventMode&&(!!t.hitArea||!!t.containsPoint&&t.containsPoint(e))}notifyTarget(t,e){var i,s;const r=`on${e=e??t.type}`;null==(s=(i=t.currentTarget)[r])||s.call(i,t);const n=t.eventPhase===t.CAPTURING_PHASE||t.eventPhase===t.AT_TARGET?`${e}capture`:e;this.notifyListeners(t,n),t.eventPhase===t.AT_TARGET&&this.notifyListeners(t,e)}mapPointerDown(t){if(!(t instanceof mx))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=this.createPointerEvent(t);if(this.dispatchEvent(e,"pointerdown"),"touch"===e.pointerType)this.dispatchEvent(e,"touchstart");else if("mouse"===e.pointerType||"pen"===e.pointerType){const t=2===e.button;this.dispatchEvent(e,t?"rightdown":"mousedown")}this.trackingData(t.pointerId).pressTargetsByButton[t.button]=e.composedPath(),this.freeEvent(e)}mapPointerMove(t){var e,i;if(!(t instanceof mx))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const s=this.createPointerEvent(t);this._isPointerMoveEvent=!1;const r="mouse"===s.pointerType||"pen"===s.pointerType,n=this.trackingData(t.pointerId),o=this.findMountedTarget(n.overTargets);if((null==(e=n.overTargets)?void 0:e.length)>0&&o!==s.target){const e="mousemove"===t.type?"mouseout":"pointerout",i=this.createPointerEvent(t,e,o);if(this.dispatchEvent(i,"pointerout"),r&&this.dispatchEvent(i,"mouseout"),!s.composedPath().includes(o)){const e=this.createPointerEvent(t,"pointerleave",o);for(e.eventPhase=e.AT_TARGET;e.target&&!s.composedPath().includes(e.target);)e.currentTarget=e.target,this.notifyTarget(e),r&&this.notifyTarget(e,"mouseleave"),e.target=e.target.parent;this.freeEvent(e)}this.freeEvent(i)}if(o!==s.target){const e="mousemove"===t.type?"mouseover":"pointerover",i=this.clonePointerEvent(s,e);this.dispatchEvent(i,"pointerover"),r&&this.dispatchEvent(i,"mouseover");let n=null==o?void 0:o.parent;for(;n&&n!==this.rootTarget.parent&&n!==s.target;)n=n.parent;if(!n||n===this.rootTarget.parent){const t=this.clonePointerEvent(s,"pointerenter");for(t.eventPhase=t.AT_TARGET;t.target&&t.target!==o&&t.target!==this.rootTarget.parent;)t.currentTarget=t.target,this.notifyTarget(t),r&&this.notifyTarget(t,"mouseenter"),t.target=t.target.parent;this.freeEvent(t)}this.freeEvent(i)}const a=[],l=this.enableGlobalMoveEvents??!0;this.moveOnAll?a.push("pointermove"):this.dispatchEvent(s,"pointermove"),l&&a.push("globalpointermove"),"touch"===s.pointerType&&(this.moveOnAll?a.splice(1,0,"touchmove"):this.dispatchEvent(s,"touchmove"),l&&a.push("globaltouchmove")),r&&(this.moveOnAll?a.splice(1,0,"mousemove"):this.dispatchEvent(s,"mousemove"),l&&a.push("globalmousemove"),this.cursor=null==(i=s.target)?void 0:i.cursor),a.length>0&&this.all(s,a),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=s.composedPath(),this.freeEvent(s)}mapPointerOver(t){var e;if(!(t instanceof mx))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const i=this.trackingData(t.pointerId),s=this.createPointerEvent(t),r="mouse"===s.pointerType||"pen"===s.pointerType;this.dispatchEvent(s,"pointerover"),r&&this.dispatchEvent(s,"mouseover"),"mouse"===s.pointerType&&(this.cursor=null==(e=s.target)?void 0:e.cursor);const n=this.clonePointerEvent(s,"pointerenter");for(n.eventPhase=n.AT_TARGET;n.target&&n.target!==this.rootTarget.parent;)n.currentTarget=n.target,this.notifyTarget(n),r&&this.notifyTarget(n,"mouseenter"),n.target=n.target.parent;i.overTargets=s.composedPath(),this.freeEvent(s),this.freeEvent(n)}mapPointerOut(t){if(!(t instanceof mx))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=this.trackingData(t.pointerId);if(e.overTargets){const i="mouse"===t.pointerType||"pen"===t.pointerType,s=this.findMountedTarget(e.overTargets),r=this.createPointerEvent(t,"pointerout",s);this.dispatchEvent(r),i&&this.dispatchEvent(r,"mouseout");const n=this.createPointerEvent(t,"pointerleave",s);for(n.eventPhase=n.AT_TARGET;n.target&&n.target!==this.rootTarget.parent;)n.currentTarget=n.target,this.notifyTarget(n),i&&this.notifyTarget(n,"mouseleave"),n.target=n.target.parent;e.overTargets=null,this.freeEvent(r),this.freeEvent(n)}this.cursor=null}mapPointerUp(t){if(!(t instanceof mx))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=performance.now(),i=this.createPointerEvent(t);if(this.dispatchEvent(i,"pointerup"),"touch"===i.pointerType)this.dispatchEvent(i,"touchend");else if("mouse"===i.pointerType||"pen"===i.pointerType){const t=2===i.button;this.dispatchEvent(i,t?"rightup":"mouseup")}const s=this.trackingData(t.pointerId),r=this.findMountedTarget(s.pressTargetsByButton[t.button]);let n=r;if(r&&!i.composedPath().includes(r)){let e=r;for(;e&&!i.composedPath().includes(e);){if(i.currentTarget=e,this.notifyTarget(i,"pointerupoutside"),"touch"===i.pointerType)this.notifyTarget(i,"touchendoutside");else if("mouse"===i.pointerType||"pen"===i.pointerType){const t=2===i.button;this.notifyTarget(i,t?"rightupoutside":"mouseupoutside")}e=e.parent}delete s.pressTargetsByButton[t.button],n=e}if(n){const r=this.clonePointerEvent(i,"click");r.target=n,r.path=null,s.clicksByButton[t.button]||(s.clicksByButton[t.button]={clickCount:0,target:r.target,timeStamp:e});const o=s.clicksByButton[t.button];if(o.target===r.target&&e-o.timeStamp<200?++o.clickCount:o.clickCount=1,o.target=r.target,o.timeStamp=e,r.detail=o.clickCount,"mouse"===r.pointerType){const t=2===r.button;this.dispatchEvent(r,t?"rightclick":"click")}else"touch"===r.pointerType&&this.dispatchEvent(r,"tap");this.dispatchEvent(r,"pointertap"),this.freeEvent(r)}this.freeEvent(i)}mapPointerUpOutside(t){if(!(t instanceof mx))return void console.warn("EventBoundary cannot map a non-pointer event as a pointer event");const e=this.trackingData(t.pointerId),i=this.findMountedTarget(e.pressTargetsByButton[t.button]),s=this.createPointerEvent(t);if(i){let r=i;for(;r;)s.currentTarget=r,this.notifyTarget(s,"pointerupoutside"),"touch"===s.pointerType?this.notifyTarget(s,"touchendoutside"):("mouse"===s.pointerType||"pen"===s.pointerType)&&this.notifyTarget(s,2===s.button?"rightupoutside":"mouseupoutside"),r=r.parent;delete e.pressTargetsByButton[t.button]}this.freeEvent(s)}mapWheel(t){if(!(t instanceof gx))return void console.warn("EventBoundary cannot map a non-wheel event as a wheel event");const e=this.createWheelEvent(t);this.dispatchEvent(e),this.freeEvent(e)}findMountedTarget(t){if(!t)return null;let e=t[0];for(let i=1;i<t.length&&t[i].parent===e;i++)e=t[i];return e}createPointerEvent(t,e,i){const s=this.allocateEvent(mx);return this.copyPointerData(t,s),this.copyMouseData(t,s),this.copyData(t,s),s.nativeEvent=t.nativeEvent,s.originalEvent=t,s.target=i??this.hitTest(s.global.x,s.global.y)??this._hitElements[0],"string"==typeof e&&(s.type=e),s}createWheelEvent(t){const e=this.allocateEvent(gx);return this.copyWheelData(t,e),this.copyMouseData(t,e),this.copyData(t,e),e.nativeEvent=t.nativeEvent,e.originalEvent=t,e.target=this.hitTest(e.global.x,e.global.y),e}clonePointerEvent(t,e){const i=this.allocateEvent(mx);return i.nativeEvent=t.nativeEvent,i.originalEvent=t.originalEvent,this.copyPointerData(t,i),this.copyMouseData(t,i),this.copyData(t,i),i.target=t.target,i.path=t.composedPath().slice(),i.type=e??i.type,i}copyWheelData(t,e){e.deltaMode=t.deltaMode,e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ}copyPointerData(t,e){t instanceof mx&&e instanceof mx&&(e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist)}copyMouseData(t,e){t instanceof fx&&e instanceof fx&&(e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.copyFrom(t.client),e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.copyFrom(t.movement),e.screen.copyFrom(t.screen),e.shiftKey=t.shiftKey,e.global.copyFrom(t.global))}copyData(t,e){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.detail=t.detail,e.view=t.view,e.which=t.which,e.layer.copyFrom(t.layer),e.page.copyFrom(t.page)}trackingData(t){return this.mappingState.trackingData[t]||(this.mappingState.trackingData[t]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[t]}allocateEvent(t){this.eventPool.has(t)||this.eventPool.set(t,[]);const e=this.eventPool.get(t).pop()||new t(this);return e.eventPhase=e.NONE,e.currentTarget=null,e.path=null,e.target=null,e}freeEvent(t){if(t.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const e=t.constructor;this.eventPool.has(e)||this.eventPool.set(e,[]),this.eventPool.get(e).push(t)}notifyListeners(t,e){const i=t.currentTarget._events[e];if(i&&t.currentTarget.isInteractive())if("fn"in i)i.once&&t.currentTarget.removeListener(e,i.fn,void 0,!0),i.fn.call(i.context,t);else for(let s=0,r=i.length;s<r&&!t.propagationImmediatelyStopped;s++)i[s].once&&t.currentTarget.removeListener(e,i[s].fn,void 0,!0),i[s].fn.call(i[s].context,t)}}const bx={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},_x=class t{constructor(e){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=e,this.rootBoundary=new xx(null),dx.init(this),this.autoPreventDefault=!0,this.eventsAdded=!1,this.rootPointerEvent=new mx(null),this.rootWheelEvent=new gx(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...t.defaultEventFeatures},{set:(t,e,i)=>("globalMove"===e&&(this.rootBoundary.enableGlobalMoveEvents=i),t[e]=i,!0)}),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this),this.onPointerOverOut=this.onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{view:i,resolution:s}=this.renderer;this.setTargetElement(i),this.resolution=s,t._defaultEventMode=e.eventMode??"auto",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(t){this.resolution=t}destroy(){this.setTargetElement(null),this.renderer=null}setCursor(t){t=t||"default";let e=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(e=!1),this.currentCursor===t)return;this.currentCursor=t;const i=this.cursorStyles[t];if(i)switch(typeof i){case"string":e&&(this.domElement.style.cursor=i);break;case"function":i(t);break;case"object":e&&Object.assign(this.domElement.style,i)}else e&&"string"==typeof t&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,t)&&(this.domElement.style.cursor=t)}get pointer(){return this.rootPointerEvent}onPointerDown(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);this.autoPreventDefault&&e[0].isNormalized&&(t.cancelable||!("cancelable"in t))&&t.preventDefault();for(let i=0,s=e.length;i<s;i++){const t=e[i],s=this.bootstrapEvent(this.rootPointerEvent,t);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onPointerMove(t){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,dx.pointerMoved();const e=this.normalizeToPointerData(t);for(let i=0,s=e.length;i<s;i++){const t=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(t)}this.setCursor(this.rootBoundary.cursor)}onPointerUp(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let e=t.target;t.composedPath&&t.composedPath().length>0&&(e=t.composedPath()[0]);const i=e!==this.domElement?"outside":"",s=this.normalizeToPointerData(t);for(let r=0,n=s.length;r<n;r++){const t=this.bootstrapEvent(this.rootPointerEvent,s[r]);t.type+=i,this.rootBoundary.mapEvent(t)}this.setCursor(this.rootBoundary.cursor)}onPointerOverOut(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);for(let i=0,s=e.length;i<s;i++){const t=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(t)}this.setCursor(this.rootBoundary.cursor)}onWheel(t){if(!this.features.wheel)return;const e=this.normalizeWheelEvent(t);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(e)}setTargetElement(t){this.removeEvents(),this.domElement=t,dx.domElement=t,this.addEvents()}addEvents(){if(this.eventsAdded||!this.domElement)return;dx.addTickerListener();const t=this.domElement.style;t&&(globalThis.navigator.msPointerEnabled?(t.msContentZooming="none",t.msTouchAction="none"):this.supportsPointerEvents&&(t.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this.onPointerMove,!0),this.domElement.addEventListener("pointerdown",this.onPointerDown,!0),this.domElement.addEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this.onPointerOverOut,!0),globalThis.addEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this.onPointerMove,!0),this.domElement.addEventListener("mousedown",this.onPointerDown,!0),this.domElement.addEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this.onPointerOverOut,!0),globalThis.addEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this.onPointerDown,!0),this.domElement.addEventListener("touchend",this.onPointerUp,!0),this.domElement.addEventListener("touchmove",this.onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this.eventsAdded=!0}removeEvents(){if(!this.eventsAdded||!this.domElement)return;dx.removeTickerListener();const t=this.domElement.style;globalThis.navigator.msPointerEnabled?(t.msContentZooming="",t.msTouchAction=""):this.supportsPointerEvents&&(t.touchAction=""),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this.onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this.onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this.onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this.onPointerMove,!0),this.domElement.removeEventListener("mousedown",this.onPointerDown,!0),this.domElement.removeEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this.onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this.onPointerDown,!0),this.domElement.removeEventListener("touchend",this.onPointerUp,!0),this.domElement.removeEventListener("touchmove",this.onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement=null,this.eventsAdded=!1}mapPositionToPoint(t,e,i){const s=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},r=1/this.resolution;t.x=(e-s.left)*(this.domElement.width/s.width)*r,t.y=(i-s.top)*(this.domElement.height/s.height)*r}normalizeToPointerData(t){const e=[];if(this.supportsTouchEvents&&t instanceof TouchEvent)for(let i=0,s=t.changedTouches.length;i<s;i++){const s=t.changedTouches[i];typeof s.button>"u"&&(s.button=0),typeof s.buttons>"u"&&(s.buttons=1),typeof s.isPrimary>"u"&&(s.isPrimary=1===t.touches.length&&"touchstart"===t.type),typeof s.width>"u"&&(s.width=s.radiusX||1),typeof s.height>"u"&&(s.height=s.radiusY||1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="touch"),typeof s.pointerId>"u"&&(s.pointerId=s.identifier||0),typeof s.pressure>"u"&&(s.pressure=s.force||.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),typeof s.layerX>"u"&&(s.layerX=s.offsetX=s.clientX),typeof s.layerY>"u"&&(s.layerY=s.offsetY=s.clientY),s.isNormalized=!0,s.type=t.type,e.push(s)}else if(globalThis.MouseEvent&&(!(t instanceof MouseEvent)||this.supportsPointerEvents&&t instanceof globalThis.PointerEvent))e.push(t);else{const i=t;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=1),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,e.push(i)}return e}normalizeWheelEvent(t){const e=this.rootWheelEvent;return this.transferMouseData(e,t),e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ,e.deltaMode=t.deltaMode,this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.nativeEvent=t,e.type=t.type,e}bootstrapEvent(t,e){return t.originalEvent=null,t.nativeEvent=e,t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist,this.transferMouseData(t,e),this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.isTrusted=e.isTrusted,"pointerleave"===t.type&&(t.type="pointerout"),t.type.startsWith("mouse")&&(t.type=t.type.replace("mouse","pointer")),t.type.startsWith("touch")&&(t.type=bx[t.type]||t.type),t}transferMouseData(t,e){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.x=e.clientX,t.client.y=e.clientY,t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.x=e.movementX,t.movement.y=e.movementY,t.page.x=e.pageX,t.page.y=e.pageY,t.relatedTarget=null,t.shiftKey=e.shiftKey}};_x.extension={name:"events",type:[hm.RendererSystem,hm.CanvasRendererSystem]},_x.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let wx=_x;function Px(t){return"dynamic"===t||"static"===t}dm.add(wx);const Ex={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,_internalInteractive:void 0,get interactive(){return this._internalInteractive??Px(wx.defaultEventMode)},set interactive(t){Qp("7.2.0","Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."),this._internalInteractive=t,this.eventMode=t?"static":"auto"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??wx.defaultEventMode},set eventMode(t){this._internalInteractive=Px(t),this._internalEventMode=t},isInteractive(){return"static"===this.eventMode||"dynamic"===this.eventMode},interactiveChildren:!0,hitArea:null,addEventListener(t,e,i){const s="boolean"==typeof i&&i||"object"==typeof i&&i.capture,r="object"==typeof i?i.signal:void 0,n="object"==typeof i&&!0===i.once,o="function"==typeof e?void 0:e;t=s?`${t}capture`:t;const a="function"==typeof e?e:e.handleEvent,l=this;r&&r.addEventListener("abort",(()=>{l.off(t,a,o)})),n?l.once(t,a,o):l.on(t,a,o)},removeEventListener(t,e,i){const s="function"==typeof e?void 0:e;t="boolean"==typeof i&&i||"object"==typeof i&&i.capture?`${t}capture`:t,e="function"==typeof e?e:e.handleEvent,this.off(t,e,s)},dispatchEvent(t){if(!(t instanceof px))throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");return t.defaultPrevented=!1,t.path=null,t.target=this,t.manager.dispatchEvent(t),!t.defaultPrevented}};pv.mixin(Ex);const Tx=new Xm;class Ax{constructor(t){this.renderer=t}async image(t,e,i,s){const r=new Image;return r.src=await this.base64(t,e,i,s),r}async base64(t,e,i,s){const r=this.canvas(t,s);if(void 0!==r.toBlob)return new Promise(((t,s)=>{r.toBlob((e=>{if(!e)return void s(new Error("ICanvas.toBlob failed!"));const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s,i.readAsDataURL(e)}),e,i)}));if(void 0!==r.toDataURL)return r.toDataURL(e,i);if(void 0!==r.convertToBlob){const t=await r.convertToBlob({type:e,quality:i});return new Promise(((e,i)=>{const s=new FileReader;s.onload=()=>e(s.result),s.onerror=i,s.readAsDataURL(t)}))}throw new Error("CanvasExtract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(t,e){const i=this.renderer;if(!i)throw new Error("The CanvasExtract has already been destroyed");let s,r,n;t&&(t instanceof Vg?n=t:(n=i.generateTexture(t,{region:e,resolution:i.resolution}),e&&(Tx.width=e.width,Tx.height=e.height,e=Tx))),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=i.canvasContext.rootContext,r=i._view.resolution,e||((e=Tx).width=i.width/r,e.height=i.height/r));const o=Math.round(e.x*r),a=Math.round(e.y*r),l=Math.max(Math.round(e.width*r),1),h=Math.max(Math.round(e.height*r),1),u=new em(l,h,1),c=s.getImageData(o,a,l,h);return u.context.putImageData(c,0,0),u.canvas}pixels(t,e){const i=this.renderer;if(!i)throw new Error("The CanvasExtract has already been destroyed");let s,r,n;t&&(t instanceof Vg?n=t:(n=i.generateTexture(t,{region:e,resolution:i.resolution}),e&&(Tx.width=e.width,Tx.height=e.height,e=Tx))),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=i.canvasContext.rootContext,r=i.resolution,e||((e=Tx).width=i.width/r,e.height=i.height/r));const o=Math.round(e.x*r),a=Math.round(e.y*r),l=Math.max(Math.round(e.width*r),1),h=Math.max(Math.round(e.height*r),1);return s.getImageData(o,a,l,h).data}destroy(){this.renderer=null}}let Ix;function Sx(t){const e=lh.ADAPTER.createCanvas(6,1),i=e.getContext("2d");return i.fillStyle=t,i.fillRect(0,0,6,1),e}function Cx(){if(typeof document>"u")return!1;if(void 0!==Ix)return Ix;const t=Sx("#ff00ff"),e=Sx("#ffff00"),i=lh.ADAPTER.createCanvas(6,1).getContext("2d");i.globalCompositeOperation="multiply",i.drawImage(t,0,0),i.drawImage(e,2,0);const s=i.getImageData(2,0,1,1);if(s){const t=s.data;Ix=255===t[0]&&0===t[1]&&0===t[2]}else Ix=!1;return Ix}Ax.extension={name:"extract",type:hm.CanvasRendererSystem},dm.add(Ax),Em.prototype.getDrawableSource=function(){const t=this.resource;return t?t.bitmap||t.source:null},Xg.prototype._canvasRenderTarget=null,zg.prototype.patternCache=null,zg.prototype.tintCache=null;const Mx=new jm;class Ox{constructor(t){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=function(t=[]){return Cx()?(t[jl.NORMAL]="source-over",t[jl.ADD]="lighter",t[jl.MULTIPLY]="multiply",t[jl.SCREEN]="screen",t[jl.OVERLAY]="overlay",t[jl.DARKEN]="darken",t[jl.LIGHTEN]="lighten",t[jl.COLOR_DODGE]="color-dodge",t[jl.COLOR_BURN]="color-burn",t[jl.HARD_LIGHT]="hard-light",t[jl.SOFT_LIGHT]="soft-light",t[jl.DIFFERENCE]="difference",t[jl.EXCLUSION]="exclusion",t[jl.HUE]="hue",t[jl.SATURATION]="saturation",t[jl.COLOR]="color",t[jl.LUMINOSITY]="luminosity"):(t[jl.NORMAL]="source-over",t[jl.ADD]="lighter",t[jl.MULTIPLY]="source-over",t[jl.SCREEN]="source-over",t[jl.OVERLAY]="source-over",t[jl.DARKEN]="source-over",t[jl.LIGHTEN]="source-over",t[jl.COLOR_DODGE]="source-over",t[jl.COLOR_BURN]="source-over",t[jl.HARD_LIGHT]="source-over",t[jl.SOFT_LIGHT]="source-over",t[jl.DIFFERENCE]="source-over",t[jl.EXCLUSION]="source-over",t[jl.HUE]="source-over",t[jl.SATURATION]="source-over",t[jl.COLOR]="source-over",t[jl.LUMINOSITY]="source-over"),t[jl.NORMAL_NPM]=t[jl.NORMAL],t[jl.ADD_NPM]=t[jl.ADD],t[jl.SCREEN_NPM]=t[jl.SCREEN],t[jl.SRC_IN]="source-in",t[jl.SRC_OUT]="source-out",t[jl.SRC_ATOP]="source-atop",t[jl.DST_OVER]="destination-over",t[jl.DST_IN]="destination-in",t[jl.DST_OUT]="destination-out",t[jl.DST_ATOP]="destination-atop",t[jl.XOR]="xor",t[jl.SUBTRACT]="source-over",t}(),this._activeBlendMode=null,this._projTransform=null,this._outerBlend=!1,this.renderer=t}init(){const t=this.renderer.background.alpha<1;if(this.rootContext=this.renderer.view.getContext("2d",{alpha:t}),this.activeContext=this.rootContext,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(t,e,i){let s=t;const r=this._projTransform,n=this.activeResolution;i=i||n,r&&(s=Mx,s.copyFrom(t),s.prepend(r)),e?this.activeContext.setTransform(s.a*i,s.b*i,s.c*i,s.d*i,s.tx*n|0,s.ty*n|0):this.activeContext.setTransform(s.a*i,s.b*i,s.c*i,s.d*i,s.tx*n,s.ty*n)}clear(t,e){const{activeContext:i,renderer:s}=this,r=t?Ff.shared.setValue(t):this.renderer.background.backgroundColor;i.clearRect(0,0,s.width,s.height),t&&(i.globalAlpha=e??this.renderer.background.alpha,i.fillStyle=r.toHex(),i.fillRect(0,0,s.width,s.height),i.globalAlpha=1)}setBlendMode(t,e){const i=t===jl.SRC_IN||t===jl.SRC_OUT||t===jl.DST_IN||t===jl.DST_ATOP;!e&&i&&(t=jl.NORMAL),this._activeBlendMode!==t&&(this._activeBlendMode=t,this._outerBlend=i,this.activeContext.globalCompositeOperation=this.blendModes[t])}resize(){this.smoothProperty&&(this.rootContext[this.smoothProperty]=Em.defaultOptions.scaleMode===Zl.LINEAR)}invalidateBlendMode(){this._activeBlendMode=this.blendModes.indexOf(this.activeContext.globalCompositeOperation)}destroy(){this.renderer=null,this.rootContext=null,this.activeContext=null,this.smoothProperty=null}}Ox.extension={type:hm.CanvasRendererSystem,name:"canvasContext"},dm.add(Ox);class Nx{constructor(t){this._foundShapes=[],this.renderer=t}pushMask(t){const e=this.renderer,i=t.maskObject||t;e.canvasContext.activeContext.save();const s=this._foundShapes;if(this.recursiveFindShapes(i,s),s.length>0){const t=e.canvasContext.activeContext;t.beginPath();for(let e=0;e<s.length;e++){const t=s[e],i=t.transform.worldTransform;this.renderer.canvasContext.setContextTransform(i),this.renderGraphicsShape(t)}s.length=0,t.clip()}}recursiveFindShapes(t,e){t.geometry&&t.geometry.graphicsData&&e.push(t);const{children:i}=t;if(i)for(let s=0;s<i.length;s++)this.recursiveFindShapes(i[s],e)}renderGraphicsShape(t){t.finishPoly();const e=this.renderer.canvasContext.activeContext,i=t.geometry.graphicsData,s=i.length;if(0!==s)for(let r=0;r<s;r++){const t=i[r],s=t.shape;if(s.type===Dm.POLY){let i=s.points;const r=t.holes;let n,o,a,l;e.moveTo(i[0],i[1]);for(let t=1;t<i.length/2;t++)e.lineTo(i[2*t],i[2*t+1]);if(r.length>0){n=0,a=i[0],l=i[1];for(let t=2;t+2<i.length;t+=2)n+=(i[t]-a)*(i[t+3]-l)-(i[t+2]-a)*(i[t+1]-l);for(let t=0;t<r.length;t++)if(i=r[t].shape.points,i){o=0,a=i[0],l=i[1];for(let t=2;t+2<i.length;t+=2)o+=(i[t]-a)*(i[t+3]-l)-(i[t+2]-a)*(i[t+1]-l);if(o*n<0){e.moveTo(i[0],i[1]);for(let t=2;t<i.length;t+=2)e.lineTo(i[t],i[t+1])}else{e.moveTo(i[i.length-2],i[i.length-1]);for(let t=i.length-4;t>=0;t-=2)e.lineTo(i[t],i[t+1])}r[t].shape.closeStroke&&e.closePath()}}i[0]===i[i.length-2]&&i[1]===i[i.length-1]&&e.closePath()}else if(s.type===Dm.RECT)e.rect(s.x,s.y,s.width,s.height),e.closePath();else if(s.type===Dm.CIRC)e.arc(s.x,s.y,s.radius,0,2*Math.PI),e.closePath();else if(s.type===Dm.ELIP){const t=2*s.width,i=2*s.height,r=s.x-t/2,n=s.y-i/2,o=.5522848,a=t/2*o,l=i/2*o,h=r+t,u=n+i,c=r+t/2,d=n+i/2;e.moveTo(r,d),e.bezierCurveTo(r,d-l,c-a,n,c,n),e.bezierCurveTo(c+a,n,h,d-l,h,d),e.bezierCurveTo(h,d+l,c+a,u,c,u),e.bezierCurveTo(c-a,u,r,d+l,r,d),e.closePath()}else if(s.type===Dm.RREC){const t=s.x,i=s.y,r=s.width,n=s.height;let o=s.radius;const a=Math.min(r,n)/2;o=o>a?a:o,e.moveTo(t,i+o),e.lineTo(t,i+n-o),e.quadraticCurveTo(t,i+n,t+o,i+n),e.lineTo(t+r-o,i+n),e.quadraticCurveTo(t+r,i+n,t+r,i+n-o),e.lineTo(t+r,i+o),e.quadraticCurveTo(t+r,i,t+r-o,i),e.lineTo(t+o,i),e.quadraticCurveTo(t,i,t,i+o),e.closePath()}}}popMask(t){t.canvasContext.activeContext.restore(),t.canvasContext.invalidateBlendMode()}destroy(){}}Nx.extension={type:hm.CanvasRendererSystem,name:"mask"},dm.add(Nx);class Lx{constructor(t){this.renderer=t}render(t,e){const i=this.renderer;if(!i.view)return;const s=i.canvasContext;let r,n,o,a;e&&(r=e.renderTexture,n=e.clear,o=e.transform,a=e.skipUpdateTransform),this.renderingToScreen=!r,i.emit("prerender");const l=i.resolution;r?(r=r.castToBaseTexture(),r._canvasRenderTarget||(r._canvasRenderTarget=new em(r.width,r.height,r.resolution),r.resource=new rv(r._canvasRenderTarget.canvas),r.valid=!0),s.activeContext=r._canvasRenderTarget.context,i.canvasContext.activeResolution=r._canvasRenderTarget.resolution):(s.activeContext=s.rootContext,s.activeResolution=l);const h=s.activeContext;if(s._projTransform=o||null,r||(this.lastObjectRendered=t),!a){const e=t.enableTempParent();t.updateTransform(),t.disableTempParent(e)}if(h.save(),h.setTransform(1,0,0,1,0,0),h.globalAlpha=1,s._activeBlendMode=jl.NORMAL,s._outerBlend=!1,h.globalCompositeOperation=s.blendModes[jl.NORMAL],n??i.background.clearBeforeRender)if(this.renderingToScreen){h.clearRect(0,0,i.width,i.height);const t=i.background;t.alpha>0&&(h.globalAlpha=t.backgroundColor.alpha,h.fillStyle=t.backgroundColor.toHex(),h.fillRect(0,0,i.width,i.height),h.globalAlpha=1)}else r._canvasRenderTarget.clear(),r.clear.alpha>0&&(h.globalAlpha=r.clear.alpha,h.fillStyle=r.clear.toHex(),h.fillRect(0,0,r.realWidth,r.realHeight),h.globalAlpha=1);const u=s.activeContext;s.activeContext=h,t.renderCanvas(i),s.activeContext=u,h.restore(),s.activeResolution=l,s._projTransform=null,i.emit("postrender")}destroy(){this.lastObjectRendered=null,this.render=null}}Lx.extension={type:hm.CanvasRendererSystem,name:"objectRenderer"},dm.add(Lx);const{deprecation:Rx}=lm,kx=class t extends Dy{constructor(e){super(),this.type=Yl.CANVAS,this.rendererLogId="Canvas",e=Object.assign({},lh.RENDER_OPTIONS,e);const i={runners:["init","destroy","contextChange","resolutionChange","reset","update","postrender","prerender","resize"],systems:t.__systems,priority:["textureGenerator","background","_view","_plugin","startup","mask","canvasContext","objectRenderer"]};this.setup(i),"useContextAlpha"in e&&(Rx("7.0.0","options.useContextAlpha is deprecated, use options.backgroundAlpha instead"),e.backgroundAlpha=!1===e.useContextAlpha?1:e.backgroundAlpha),this._plugin.rendererPlugins=t.__plugins,this.options=e,this.startup.run(this.options)}static test(){return!0}generateTexture(t,e){return this.textureGenerator.generateTexture(t,e)}reset(){}render(t,e){this.objectRenderer.render(t,e)}clear(){this.canvasContext.clear()}destroy(t){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:t}),super.destroy()}get plugins(){return this._plugin.plugins}resize(t,e){this._view.resizeView(t,e)}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}set resolution(t){this._view.resolution=t,this.runners.resolutionChange.emit(t)}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get clearBeforeRender(){return this.background.clearBeforeRender}get blendModes(){return Rx("7.0.0","renderer.blendModes has been deprecated, please use renderer.canvasContext.blendModes instead"),this.canvasContext.blendModes}get maskManager(){return Rx("7.0.0","renderer.maskManager has been deprecated, please use renderer.mask instead"),this.mask}get refresh(){return Rx("7.0.0","renderer.refresh has been deprecated"),!0}get rootContext(){return Rx("7.0.0","renderer.rootContext has been deprecated, please use renderer.canvasContext.rootContext instead"),this.canvasContext.rootContext}get context(){return Rx("7.0.0","renderer.context has been deprecated, please use renderer.canvasContext.activeContext instead"),this.canvasContext.activeContext}get smoothProperty(){return Rx("7.0.0","renderer.smoothProperty has been deprecated, please use renderer.canvasContext.smoothProperty instead"),this.canvasContext.smoothProperty}setBlendMode(t,e){Rx("7.0.0","renderer.setBlendMode has been deprecated, use renderer.canvasContext.setBlendMode instead"),this.canvasContext.setBlendMode(t,e)}invalidateBlendMode(){Rx("7.0.0","renderer.invalidateBlendMode has been deprecated, use renderer.canvasContext.invalidateBlendMode instead"),this.canvasContext.invalidateBlendMode()}setContextTransform(t,e,i){Rx("7.0.0","renderer.setContextTransform has been deprecated, use renderer.canvasContext.setContextTransform instead"),this.canvasContext.setContextTransform(t,e,i)}get backgroundColor(){return Rx("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){Rx("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return Rx("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){Rx("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get preserveDrawingBuffer(){return Rx("7.0.0","renderer.preserveDrawingBuffer has been deprecated"),!1}get useContextAlpha(){return Rx("7.0.0","renderer.useContextAlpha has been deprecated"),!1}};kx.extension={type:hm.Renderer,priority:0},kx.__plugins={},kx.__systems={};let Bx=kx;dm.handleByMap(hm.CanvasRendererPlugin,Bx.__plugins),dm.handleByMap(hm.CanvasRendererSystem,Bx.__systems),dm.add(Bx);const Fx={canvas:null,getTintedCanvas:(t,e)=>{const i=t.texture,s=Ff.shared.setValue(e).toHex();i.tintCache=i.tintCache||{};const r=i.tintCache[s];let n;if(r){if(r.tintId===i._updateID)return i.tintCache[s];n=i.tintCache[s]}else n=lh.ADAPTER.createCanvas();if(Fx.tintMethod(i,e,n),n.tintId=i._updateID,Fx.convertTintToImage&&void 0!==n.toDataURL){const t=new Image;t.src=n.toDataURL(),i.tintCache[s]=t}else i.tintCache[s]=n;return n},getTintedPattern:(t,e)=>{const i=Ff.shared.setValue(e).toHex();t.patternCache=t.patternCache||{};let s=t.patternCache[i];return(null==s?void 0:s.tintId)===t._updateID||(Fx.canvas||(Fx.canvas=lh.ADAPTER.createCanvas()),Fx.tintMethod(t,e,Fx.canvas),s=Fx.canvas.getContext("2d").createPattern(Fx.canvas,"repeat"),s.tintId=t._updateID,t.patternCache[i]=s),s},tintWithMultiply:(t,e,i)=>{const s=i.getContext("2d"),r=t._frame.clone(),n=t.baseTexture.resolution;r.x*=n,r.y*=n,r.width*=n,r.height*=n,i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),s.save(),s.fillStyle=Ff.shared.setValue(e).toHex(),s.fillRect(0,0,r.width,r.height),s.globalCompositeOperation="multiply";const o=t.baseTexture.getDrawableSource();s.drawImage(o,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.globalCompositeOperation="destination-atop",s.drawImage(o,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore()},tintWithOverlay:(t,e,i)=>{const s=i.getContext("2d"),r=t._frame.clone(),n=t.baseTexture.resolution;r.x*=n,r.y*=n,r.width*=n,r.height*=n,i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),s.save(),s.globalCompositeOperation="copy",s.fillStyle=`#${`00000${(0|e).toString(16)}`.slice(-6)}`,s.fillRect(0,0,r.width,r.height),s.globalCompositeOperation="destination-atop",s.drawImage(t.baseTexture.getDrawableSource(),r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore()},tintWithPerPixel:(t,e,i)=>{const s=i.getContext("2d"),r=t._frame.clone(),n=t.baseTexture.resolution;r.x*=n,r.y*=n,r.width*=n,r.height*=n,i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),s.save(),s.globalCompositeOperation="copy",s.drawImage(t.baseTexture.getDrawableSource(),r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore();const[o,a,l]=Ff.shared.setValue(e).toArray(),h=s.getImageData(0,0,r.width,r.height),u=h.data;for(let c=0;c<u.length;c+=4)u[c+0]*=o,u[c+1]*=a,u[c+2]*=l;s.putImageData(h,0,0)},roundColor:t=>(Qp("7.3.0","PIXI.canvasUtils.roundColor is deprecated"),Ff.shared.setValue(t).round(Fx.cacheStepsPerColorChannel).toNumber()),cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:Cx(),tintMethod:null};let Dx;Fx.tintMethod=Fx.canUseMultiply?Fx.tintWithMultiply:Fx.tintWithPerPixel;const Ux=new jm;Vv.prototype.generateCanvasTexture=function(t,e=1){const i=this.getLocalBounds(new Xm);i.width=Math.max(i.width,1/e),i.height=Math.max(i.height,1/e);const s=Vg.create({width:i.width,height:i.height,scaleMode:t,resolution:e});Dx||(Dx=new Bx),this.transform.updateLocalTransform(),this.transform.localTransform.copyTo(Ux),Ux.invert(),Ux.tx-=i.x,Ux.ty-=i.y,Dx.render(this,{renderTexture:s,clear:!0,transform:Ux});const r=zg.from(s.baseTexture._canvasRenderTarget.canvas,{scaleMode:t});return r.baseTexture.setResolution(e),r},Vv.prototype.cachedGraphicsData=[],Vv.prototype._renderCanvas=function(t){!0!==this.isMask&&(this.finishPoly(),t.plugins.graphics.render(this))};class Gx{static offsetPolygon(t,e){const i=[],s=t.length;e=Gx.isPolygonClockwise(t)?e:-1*e;for(let r=0;r<s;r+=2){let n=r-2;n<0&&(n+=s);const o=(r+2)%s;let a=t[r]-t[n],l=t[r+1]-t[n+1],h=Math.sqrt(a*a+l*l);a/=h,l/=h,a*=e,l*=e;const u=-l,c=a,d=[t[n]+u,t[n+1]+c],p=[t[r]+u,t[r+1]+c];let f=t[o]-t[r],m=t[o+1]-t[r+1];h=Math.sqrt(f*f+m*m),f/=h,m/=h,f*=e,m*=e;const g=-m,y=f,v=[t[r]+g,t[r+1]+y],x=[t[o]+g,t[o+1]+y],b=Gx.findIntersection(d[0],d[1],p[0],p[1],v[0],v[1],x[0],x[1]);b&&i.push(...b)}return i}static findIntersection(t,e,i,s,r,n,o,a){const l=(a-n)*(i-t)-(o-r)*(s-e),h=(o-r)*(e-n)-(a-n)*(t-r);if(0===l)return 0===h&&0===(i-t)*(e-n)-(s-e)*(t-r)?[(t+i)/2,(e+s)/2]:null;const u=h/l;return[t+u*(i-t),e+u*(s-e)]}static isPolygonClockwise(t){let e=0;for(let i=0,s=t.length-2;i<t.length;s=i,i+=2)e+=(t[i]-t[s])*(t[i+1]+t[s+1]);return e>0}}class Xx{constructor(t){this._svgMatrix=null,this._tempMatrix=new jm,this.renderer=t}_calcCanvasStyle(t,e){let i;return t.texture&&t.texture.baseTexture!==zg.WHITE.baseTexture?t.texture.valid?(i=Fx.getTintedPattern(t.texture,e),this.setPatternTransform(i,t.matrix||jm.IDENTITY)):i="#808080":i=`#${`00000${(0|e).toString(16)}`.slice(-6)}`,i}render(t){const e=this.renderer,i=e.canvasContext.activeContext,s=t.worldAlpha,r=t.transform.worldTransform;e.canvasContext.setContextTransform(r),e.canvasContext.setBlendMode(t.blendMode);const n=t.geometry.graphicsData;let o,a;const l=Ff.shared.setValue(t.tint).toArray();for(let h=0;h<n.length;h++){const t=n[h],u=t.shape,c=t.fillStyle,d=t.lineStyle,p=0|t.fillStyle.color,f=0|t.lineStyle.color;if(t.matrix&&e.canvasContext.setContextTransform(r.copyTo(this._tempMatrix).append(t.matrix)),c.visible&&(o=this._calcCanvasStyle(c,Ff.shared.setValue(p).multiply(l).toNumber())),d.visible&&(a=this._calcCanvasStyle(d,Ff.shared.setValue(f).multiply(l).toNumber())),i.lineWidth=d.width,i.lineCap=d.cap,i.lineJoin=d.join,i.miterLimit=d.miterLimit,t.type===Dm.POLY){i.beginPath();const e=u;let r=e.points;const n=t.holes;let l,h,p,f,m;i.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)i.lineTo(r[t],r[t+1]);if(e.closeStroke&&i.closePath(),n.length>0){m=[],l=0,p=r[0],f=r[1];for(let t=2;t+2<r.length;t+=2)l+=(r[t]-p)*(r[t+3]-f)-(r[t+2]-p)*(r[t+1]-f);for(let t=0;t<n.length;t++)if(r=n[t].shape.points,r){h=0,p=r[0],f=r[1];for(let t=2;t+2<r.length;t+=2)h+=(r[t]-p)*(r[t+3]-f)-(r[t+2]-p)*(r[t+1]-f);if(h*l<0){i.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)i.lineTo(r[t],r[t+1])}else{i.moveTo(r[r.length-2],r[r.length-1]);for(let t=r.length-4;t>=0;t-=2)i.lineTo(r[t],r[t+1])}n[t].shape.closeStroke&&i.closePath(),m[t]=h*l<0}}c.visible&&(i.globalAlpha=c.alpha*s,i.fillStyle=o,i.fill()),d.visible&&this.paintPolygonStroke(e,d,a,n,m,s,i)}else if(t.type===Dm.RECT){const t=u;if(c.visible&&(i.globalAlpha=c.alpha*s,i.fillStyle=o,i.fillRect(t.x,t.y,t.width,t.height)),d.visible){const e=d.width*(.5-(1-d.alignment)),r=t.width+2*e,n=t.height+2*e;i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.strokeRect(t.x-e,t.y-e,r,n)}}else if(t.type===Dm.CIRC){const t=u;if(i.beginPath(),i.arc(t.x,t.y,t.radius,0,2*Math.PI),i.closePath(),c.visible&&(i.globalAlpha=c.alpha*s,i.fillStyle=o,i.fill()),d.visible){if(.5!==d.alignment){const e=d.width*(.5-(1-d.alignment));i.beginPath(),i.arc(t.x,t.y,t.radius+e,0,2*Math.PI),i.closePath()}i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.stroke()}}else if(t.type===Dm.ELIP){const t=u,e=1===d.alignment;if(e||this.paintEllipse(t,c,d,o,s,i),d.visible){if(.5!==d.alignment){const e=.5522848,s=d.width*(.5-(1-d.alignment)),r=2*(t.width+s),n=2*(t.height+s),o=t.x-r/2,a=t.y-n/2,l=r/2*e,h=n/2*e,u=o+r,c=a+n,p=o+r/2,f=a+n/2;i.beginPath(),i.moveTo(o,f),i.bezierCurveTo(o,f-h,p-l,a,p,a),i.bezierCurveTo(p+l,a,u,f-h,u,f),i.bezierCurveTo(u,f+h,p+l,c,p,c),i.bezierCurveTo(p-l,c,o,f+h,o,f),i.closePath()}i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.stroke()}e&&this.paintEllipse(t,c,d,o,s,i)}else if(t.type===Dm.RREC){const t=u,e=1===d.alignment;if(e||this.paintRoundedRectangle(t,c,d,o,s,i),d.visible){if(.5!==d.alignment){const e=t.width,s=t.height,r=d.width*(.5-(1-d.alignment)),n=t.x-r,o=t.y-r,a=t.width+2*r,l=t.height+2*r,h=r*(d.alignment>=1?Math.min(a/e,l/s):Math.min(e/a,s/l));let u=t.radius+h;const c=Math.min(a,l)/2;u=u>c?c:u,i.beginPath(),i.moveTo(n,o+u),i.lineTo(n,o+l-u),i.quadraticCurveTo(n,o+l,n+u,o+l),i.lineTo(n+a-u,o+l),i.quadraticCurveTo(n+a,o+l,n+a,o+l-u),i.lineTo(n+a,o+u),i.quadraticCurveTo(n+a,o,n+a-u,o),i.lineTo(n+u,o),i.quadraticCurveTo(n,o,n,o+u),i.closePath()}i.globalAlpha=d.alpha*s,i.strokeStyle=a,i.stroke()}e&&this.paintRoundedRectangle(t,c,d,o,s,i)}}}paintPolygonStroke(t,e,i,s,r,n,o){if(.5!==e.alignment){const i=e.width*(.5-(1-e.alignment));let n,a=Gx.offsetPolygon(t.points,i);o.beginPath(),o.moveTo(a[0],a[1]);for(let t=2;t<a.length;t+=2)o.lineTo(a[t],a[t+1]);t.closeStroke&&o.closePath();for(let t=0;t<s.length;t++){if(n=s[t].shape.points,a=Gx.offsetPolygon(n,i),r[t]){o.moveTo(a[0],a[1]);for(let t=2;t<a.length;t+=2)o.lineTo(a[t],a[t+1])}else{o.moveTo(a[a.length-2],a[a.length-1]);for(let t=a.length-4;t>=0;t-=2)o.lineTo(a[t],a[t+1])}s[t].shape.closeStroke&&o.closePath()}}o.globalAlpha=e.alpha*n,o.strokeStyle=i,o.stroke()}paintEllipse(t,e,i,s,r,n){const o=2*t.width,a=2*t.height,l=t.x-o/2,h=t.y-a/2,u=.5522848,c=o/2*u,d=a/2*u,p=l+o,f=h+a,m=l+o/2,g=h+a/2;0===i.alignment&&n.save(),n.beginPath(),n.moveTo(l,g),n.bezierCurveTo(l,g-d,m-c,h,m,h),n.bezierCurveTo(m+c,h,p,g-d,p,g),n.bezierCurveTo(p,g+d,m+c,f,m,f),n.bezierCurveTo(m-c,f,l,g+d,l,g),n.closePath(),0===i.alignment&&n.clip(),e.visible&&(n.globalAlpha=e.alpha*r,n.fillStyle=s,n.fill()),0===i.alignment&&n.restore()}paintRoundedRectangle(t,e,i,s,r,n){const o=t.x,a=t.y,l=t.width,h=t.height;let u=t.radius;const c=Math.min(l,h)/2;u=u>c?c:u,0===i.alignment&&n.save(),n.beginPath(),n.moveTo(o,a+u),n.lineTo(o,a+h-u),n.quadraticCurveTo(o,a+h,o+u,a+h),n.lineTo(o+l-u,a+h),n.quadraticCurveTo(o+l,a+h,o+l,a+h-u),n.lineTo(o+l,a+u),n.quadraticCurveTo(o+l,a,o+l-u,a),n.lineTo(o+u,a),n.quadraticCurveTo(o,a,o,a+u),n.closePath(),0===i.alignment&&n.clip(),e.visible&&(n.globalAlpha=e.alpha*r,n.fillStyle=s,n.fill()),0===i.alignment&&n.restore()}setPatternTransform(t,e){if(!1!==this._svgMatrix){if(!this._svgMatrix){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");if((null==e?void 0:e.createSVGMatrix)&&(this._svgMatrix=e.createSVGMatrix()),!this._svgMatrix||!t.setTransform)return void(this._svgMatrix=!1)}this._svgMatrix.a=e.a,this._svgMatrix.b=e.b,this._svgMatrix.c=e.c,this._svgMatrix.d=e.d,this._svgMatrix.e=e.tx,this._svgMatrix.f=e.ty,t.setTransform(this._svgMatrix.inverse())}}destroy(){this.renderer=null,this._svgMatrix=null,this._tempMatrix=null}}Xx.extension={name:"graphics",type:hm.CanvasRendererPlugin},dm.add(Xx);class Wx{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function Hx(t,e){var i;let s=!1;if(null==(i=null==t?void 0:t._textures)?void 0:i.length)for(let r=0;r<t._textures.length;r++)if(t._textures[r]instanceof zg){const i=t._textures[r].baseTexture;e.includes(i)||(e.push(i),s=!0)}return s}function Yx(t,e){if(t.baseTexture instanceof Em){const i=t.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function $x(t,e){if(t._texture&&t._texture instanceof zg){const i=t._texture.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function jx(t,e){return e instanceof ox&&(e.updateText(!0),!0)}function zx(t,e){if(e instanceof ex){const t=e.toFontString();return Zv.measureFont(t),!0}return!1}function Vx(t,e){if(t instanceof ox){e.includes(t.style)||e.push(t.style),e.includes(t)||e.push(t);const i=t._texture.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function qx(t,e){return t instanceof ex&&(e.includes(t)||e.push(t),!0)}const Jx=class t{constructor(e){this.limiter=new Wx(t.uploadsPerFrame),this.renderer=e,this.uploadHookHelper=null,this.queue=[],this.addHooks=[],this.uploadHooks=[],this.completes=[],this.ticking=!1,this.delayedTick=()=>{this.queue&&this.prepareItems()},this.registerFindHook(Vx),this.registerFindHook(qx),this.registerFindHook(Hx),this.registerFindHook(Yx),this.registerFindHook($x),this.registerUploadHook(jx),this.registerUploadHook(zx)}upload(t){return new Promise((e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,Vy.system.addOnce(this.tick,this,$y.UTILITY))):e()}))}tick(){setTimeout(this.delayedTick,0)}prepareItems(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){const t=this.queue[0];let e=!1;if(t&&!t._destroyed)for(let i=0,s=this.uploadHooks.length;i<s;i++)if(this.uploadHooks[i](this.uploadHookHelper,t)){this.queue.shift(),e=!0;break}e||this.queue.shift()}if(this.queue.length)Vy.system.addOnce(this.tick,this,$y.UTILITY);else{this.ticking=!1;const t=this.completes.slice(0);this.completes.length=0;for(let e=0,i=t.length;e<i;e++)t[e]()}}registerFindHook(t){return t&&this.addHooks.push(t),this}registerUploadHook(t){return t&&this.uploadHooks.push(t),this}add(t){for(let e=0,i=this.addHooks.length;e<i&&!this.addHooks[e](t,this.queue);e++);if(t instanceof vv)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&Vy.system.remove(this.tick,this),this.ticking=!1,this.addHooks=null,this.uploadHooks=null,this.renderer=null,this.completes=null,this.queue=null,this.limiter=null,this.uploadHookHelper=null}};Jx.uploadsPerFrame=4;let Kx=Jx;function Zx(t,e){return e instanceof Em&&(e._glTextures[t.CONTEXT_UID]||t.texture.bind(e),!0)}function Qx(t,e){if(!(e instanceof Vv))return!1;const{geometry:i}=e;e.finishPoly(),i.updateBatches();const{batches:s}=i;for(let r=0;r<s.length;r++){const{texture:e}=s[r].style;e&&Zx(t,e.baseTexture)}return i.batchable||t.geometry.bind(i,e._resolveDirectShader(t)),!0}function tb(t,e){return t instanceof Vv&&(e.push(t),!0)}Object.defineProperties(lh,{UPLOADS_PER_FRAME:{get:()=>Kx.uploadsPerFrame,set(t){Qp("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),Kx.uploadsPerFrame=t}}});class eb extends Kx{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(tb),this.registerUploadHook(Zx),this.registerUploadHook(Qx)}}eb.extension={name:"prepare",type:hm.RendererSystem},dm.add(eb);function ib(t,e){const i=t;if(e instanceof Em){const t=e.source,s=0===t.width?i.canvas.width:Math.min(i.canvas.width,t.width),r=0===t.height?i.canvas.height:Math.min(i.canvas.height,t.height);return i.ctx.drawImage(t,0,0,s,r,0,0,i.canvas.width,i.canvas.height),!0}return!1}class sb extends Kx{constructor(t){super(t),this.uploadHookHelper=this,this.canvas=lh.ADAPTER.createCanvas(16,16),this.ctx=this.canvas.getContext("2d"),this.registerUploadHook(ib)}destroy(){super.destroy(),this.ctx=null,this.canvas=null}}sb.extension={name:"prepare",type:hm.CanvasRendererSystem},dm.add(sb),_v.prototype._tintedCanvas=null,_v.prototype._renderCanvas=function(t){t.plugins.sprite.render(this)};const rb=new jm;class nb{constructor(t){this.renderer=t}render(t){const e=t._texture,i=this.renderer,s=i.canvasContext.activeContext,r=i.canvasContext.activeResolution;if(!e.valid)return;const n=e._frame.width,o=e._frame.height;let a=e._frame.width,l=e._frame.height;e.trim&&(a=e.trim.width,l=e.trim.height);let h=t.transform.worldTransform,u=0,c=0;const d=e.baseTexture.getDrawableSource();if(e.orig.width<=0||e.orig.height<=0||!e.valid||!d)return;i.canvasContext.setBlendMode(t.blendMode,!0),s.globalAlpha=t.worldAlpha;const p=e.baseTexture.scaleMode===Zl.LINEAR,f=i.canvasContext.smoothProperty;f&&s[f]!==p&&(s[f]=p),e.trim?(u=e.trim.width/2+e.trim.x-t.anchor.x*e.orig.width,c=e.trim.height/2+e.trim.y-t.anchor.y*e.orig.height):(u=(.5-t.anchor.x)*e.orig.width,c=(.5-t.anchor.y)*e.orig.height),e.rotate&&(h.copyTo(rb),h=rb,tg.matrixAppendRotationInv(h,e.rotate,u,c),u=0,c=0),u-=a/2,c-=l/2,i.canvasContext.setContextTransform(h,t.roundPixels,1),t.roundPixels&&(u|=0,c|=0);const m=e.baseTexture.resolution,g=i.canvasContext._outerBlend;g&&(s.save(),s.beginPath(),s.rect(u*r,c*r,a*r,l*r),s.clip()),16777215!==t.tint?((t._cachedTint!==t.tintValue||t._tintedCanvas.tintId!==t._texture._updateID)&&(t._cachedTint=t.tintValue,t._tintedCanvas=Fx.getTintedCanvas(t,t.tintValue)),s.drawImage(t._tintedCanvas,0,0,Math.floor(n*m),Math.floor(o*m),Math.floor(u*r),Math.floor(c*r),Math.floor(a*r),Math.floor(l*r))):s.drawImage(d,e._frame.x*m,e._frame.y*m,Math.floor(n*m),Math.floor(o*m),Math.floor(u*r),Math.floor(c*r),Math.floor(a*r),Math.floor(l*r)),g&&s.restore(),i.canvasContext.setBlendMode(jl.NORMAL)}destroy(){this.renderer=null}}nb.extension={name:"sprite",type:hm.CanvasRendererPlugin},dm.add(nb);var ob=Object.defineProperty,ab=(t,e,i)=>(((t,e,i)=>{e in t?ob(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);let lb=class{constructor(t){ab(this,"parent"),ab(this,"paused"),this.parent=t,this.paused=!1}destroy(){}down(t){return!1}move(t){return!1}up(t){return!1}wheel(t){return!1}update(t){}resize(){}reset(){}pause(){this.paused=!0}resume(){this.paused=!1}};var hb,ub=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},cb={exports:{}};hb=cb,function(){var t,e;e=t={linear:function(t,e,i,s){return i*t/s+e},easeInQuad:function(t,e,i,s){return i*(t/=s)*t+e},easeOutQuad:function(t,e,i,s){return-i*(t/=s)*(t-2)+e},easeInOutQuad:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e},easeInCubic:function(t,e,i,s){return i*(t/=s)*t*t+e},easeOutCubic:function(t,e,i,s){return i*((t=t/s-1)*t*t+1)+e},easeInOutCubic:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e},easeInQuart:function(t,e,i,s){return i*(t/=s)*t*t*t+e},easeOutQuart:function(t,e,i,s){return-i*((t=t/s-1)*t*t*t-1)+e},easeInOutQuart:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e},easeInQuint:function(t,e,i,s){return i*(t/=s)*t*t*t*t+e},easeOutQuint:function(t,e,i,s){return i*((t=t/s-1)*t*t*t*t+1)+e},easeInOutQuint:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e},easeInSine:function(t,e,i,s){return-i*Math.cos(t/s*(Math.PI/2))+i+e},easeOutSine:function(t,e,i,s){return i*Math.sin(t/s*(Math.PI/2))+e},easeInOutSine:function(t,e,i,s){return-i/2*(Math.cos(Math.PI*t/s)-1)+e},easeInExpo:function(t,e,i,s){return 0===t?e:i*Math.pow(2,10*(t/s-1))+e},easeOutExpo:function(t,e,i,s){return t===s?e+i:i*(1-Math.pow(2,-10*t/s))+e},easeInOutExpo:function(t,e,i,s){return(t/=s/2)<1?i/2*Math.pow(2,10*(t-1))+e:i/2*(2-Math.pow(2,-10*--t))+e},easeInCirc:function(t,e,i,s){return-i*(Math.sqrt(1-(t/=s)*t)-1)+e},easeOutCirc:function(t,e,i,s){return i*Math.sqrt(1-(t=t/s-1)*t)+e},easeInOutCirc:function(t,e,i,s){return(t/=s/2)<1?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e},easeInElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)+e},easeOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s),(n=0)||(n=.3*s),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/n)+i+e},easeInOutElastic:function(t,e,i,s){var r,n,o;return o=1.70158,0===t||(t/=s/2),(n=0)||(n=s*(.3*1.5)),(r=i)<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*.5+i+e},easeInBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*(t/=s)*t*((r+1)*t-r)+e},easeOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeInOutBack:function(t,e,i,s,r){return void 0===r&&(r=1.70158),(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInBounce:function(e,i,s,r){return s-t.easeOutBounce(r-e,0,s,r)+i},easeOutBounce:function(t,e,i,s){return(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e},easeInOutBounce:function(e,i,s,r){return e<r/2?.5*t.easeInBounce(2*e,0,s,r)+i:.5*t.easeOutBounce(2*e-r,0,s,r)+.5*s+i}},hb.exports=e}.call(ub);const db=cb.exports;function pb(t,e){return t?"function"==typeof t?t:"string"==typeof t?db[t]:void 0:db[e]}const fb={removeOnInterrupt:!1,ease:"linear",time:1e3};let mb=class extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"startX"),ab(this,"startY"),ab(this,"deltaX"),ab(this,"deltaY"),ab(this,"keepCenter"),ab(this,"startWidth",null),ab(this,"startHeight",null),ab(this,"deltaWidth",null),ab(this,"deltaHeight",null),ab(this,"width",null),ab(this,"height",null),ab(this,"time",0),this.options=Object.assign({},fb,e),this.options.ease=pb(this.options.ease),this.setupPosition(),this.setupZoom(),this.time=0}setupPosition(){typeof this.options.position<"u"?(this.startX=this.parent.center.x,this.startY=this.parent.center.y,this.deltaX=this.options.position.x-this.parent.center.x,this.deltaY=this.options.position.y-this.parent.center.y,this.keepCenter=!1):this.keepCenter=!0}setupZoom(){this.width=null,this.height=null,typeof this.options.scale<"u"?this.width=this.parent.screenWidth/this.options.scale:typeof this.options.scaleX<"u"||typeof this.options.scaleY<"u"?(typeof this.options.scaleX<"u"&&(this.width=this.parent.screenWidth/this.options.scaleX),typeof this.options.scaleY<"u"&&(this.height=this.parent.screenHeight/this.options.scaleY)):(typeof this.options.width<"u"&&(this.width=this.options.width),typeof this.options.height<"u"&&(this.height=this.options.height)),null!==this.width&&(this.startWidth=this.parent.screenWidthInWorldPixels,this.deltaWidth=this.width-this.startWidth),null!==this.height&&(this.startHeight=this.parent.screenHeightInWorldPixels,this.deltaHeight=this.height-this.startHeight)}down(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("animate"),!1}complete(){this.parent.plugins.remove("animate"),null!==this.width&&this.parent.fitWidth(this.width,this.keepCenter,null===this.height),null!==this.height&&this.parent.fitHeight(this.height,this.keepCenter,null===this.width),!this.keepCenter&&this.options.position&&this.parent.moveCenter(this.options.position),this.parent.emit("animate-end",this.parent),this.options.callbackOnComplete&&this.options.callbackOnComplete(this.parent)}update(t){if(this.paused)return;this.time+=t;const e=new Um(this.parent.scale.x,this.parent.scale.y);if(this.time>=this.options.time){const t=this.parent.width,i=this.parent.height;this.complete(),(t!==this.parent.width||i!==this.parent.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:e,type:"animate"})}else{const t=this.options.ease(this.time,0,1,this.options.time);if(null!==this.width){const e=this.startWidth,i=this.deltaWidth;this.parent.fitWidth(e+i*t,this.keepCenter,null===this.height)}if(null!==this.height){const e=this.startHeight,i=this.deltaHeight;this.parent.fitHeight(e+i*t,this.keepCenter,null===this.width)}if(null===this.width?this.parent.scale.x=this.parent.scale.y:null===this.height&&(this.parent.scale.y=this.parent.scale.x),!this.keepCenter){const e=this.startX,i=this.startY,s=this.deltaX,r=this.deltaY,n=new Um(this.parent.x,this.parent.y);this.parent.moveCenter(e+s*t,i+r*t),this.parent.emit("moved",{viewport:this.parent,original:n,type:"animate"})}(this.width||this.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:e,type:"animate"})}}};const gb={sides:"all",friction:.5,time:150,ease:"easeInOutSine",underflow:"center",bounceBox:null};class yb extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"left"),ab(this,"top"),ab(this,"right"),ab(this,"bottom"),ab(this,"underflowX"),ab(this,"underflowY"),ab(this,"ease"),ab(this,"toX"),ab(this,"toY"),this.options=Object.assign({},gb,e),this.ease=pb(this.options.ease,"easeInOutSine"),this.options.sides?"all"===this.options.sides?this.top=this.bottom=this.left=this.right=!0:"horizontal"===this.options.sides?(this.right=this.left=!0,this.top=this.bottom=!1):"vertical"===this.options.sides?(this.left=this.right=!1,this.top=this.bottom=!0):(this.top=-1!==this.options.sides.indexOf("top"),this.bottom=-1!==this.options.sides.indexOf("bottom"),this.left=-1!==this.options.sides.indexOf("left"),this.right=-1!==this.options.sides.indexOf("right")):this.left=this.top=this.right=this.bottom=!1;const i=this.options.underflow.toLowerCase();"center"===i?(this.underflowX=0,this.underflowY=0):(this.underflowX=-1!==i.indexOf("left")?-1:-1!==i.indexOf("right")?1:0,this.underflowY=-1!==i.indexOf("top")?-1:-1!==i.indexOf("bottom")?1:0),this.reset()}isActive(){return null!==this.toX||null!==this.toY}down(){return this.toX=this.toY=null,!1}up(){return this.bounce(),!1}update(t){if(!this.paused){if(this.bounce(),this.toX){const e=this.toX;e.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-x"}),e.time>=this.options.time?(this.parent.x=e.end,this.toX=null,this.parent.emit("bounce-x-end",this.parent)):this.parent.x=this.ease(e.time,e.start,e.delta,this.options.time)}if(this.toY){const e=this.toY;e.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-y"}),e.time>=this.options.time?(this.parent.y=e.end,this.toY=null,this.parent.emit("bounce-y-end",this.parent)):this.parent.y=this.ease(e.time,e.start,e.delta,this.options.time)}}}calcUnderflowX(){let t;switch(this.underflowX){case-1:t=0;break;case 1:t=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:t=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}return t}calcUnderflowY(){let t;switch(this.underflowY){case-1:t=0;break;case 1:t=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:t=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}return t}oob(){const t=this.options.bounceBox;if(t){const e=typeof t.x>"u"?0:t.x,i=typeof t.y>"u"?0:t.y,s=typeof t.width>"u"?this.parent.worldWidth:t.width,r=typeof t.height>"u"?this.parent.worldHeight:t.height;return{left:this.parent.left<e,right:this.parent.right>s,top:this.parent.top<i,bottom:this.parent.bottom>r,topLeft:new Um(e*this.parent.scale.x,i*this.parent.scale.y),bottomRight:new Um(s*this.parent.scale.x-this.parent.screenWidth,r*this.parent.scale.y-this.parent.screenHeight)}}return{left:this.parent.left<0,right:this.parent.right>this.parent.worldWidth,top:this.parent.top<0,bottom:this.parent.bottom>this.parent.worldHeight,topLeft:new Um(0,0),bottomRight:new Um(this.parent.worldWidth*this.parent.scale.x-this.parent.screenWidth,this.parent.worldHeight*this.parent.scale.y-this.parent.screenHeight)}}bounce(){var t,e;if(this.paused)return;let i,s=this.parent.plugins.get("decelerate",!0);s&&(s.x||s.y)&&(s.x&&s.percentChangeX===(null==(t=s.options)?void 0:t.friction)||s.y&&s.percentChangeY===(null==(e=s.options)?void 0:e.friction))&&(i=this.oob(),(i.left&&this.left||i.right&&this.right)&&(s.percentChangeX=this.options.friction),(i.top&&this.top||i.bottom&&this.bottom)&&(s.percentChangeY=this.options.friction));const r=this.parent.plugins.get("drag",!0)||{},n=this.parent.plugins.get("pinch",!0)||{};if(s=s||{},!(null!=r&&r.active||null!=n&&n.active||this.toX&&this.toY||s.x&&s.y)){i=i||this.oob();const t=i.topLeft,e=i.bottomRight;if(!this.toX&&!s.x){let s=null;i.left&&this.left?s=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-t.x:i.right&&this.right&&(s=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-e.x),null!==s&&this.parent.x!==s&&(this.toX={time:0,start:this.parent.x,delta:s-this.parent.x,end:s},this.parent.emit("bounce-x-start",this.parent))}if(!this.toY&&!s.y){let s=null;i.top&&this.top?s=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-t.y:i.bottom&&this.bottom&&(s=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-e.y),null!==s&&this.parent.y!==s&&(this.toY={time:0,start:this.parent.y,delta:s-this.parent.y,end:s},this.parent.emit("bounce-y-start",this.parent))}}}reset(){this.toX=this.toY=null,this.bounce()}}const vb={left:!1,right:!1,top:!1,bottom:!1,direction:null,underflow:"center"};class xb extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"last"),ab(this,"noUnderflow"),ab(this,"underflowX"),ab(this,"underflowY"),this.options=Object.assign({},vb,e),this.options.direction&&(this.options.left="x"===this.options.direction||"all"===this.options.direction||null,this.options.right="x"===this.options.direction||"all"===this.options.direction||null,this.options.top="y"===this.options.direction||"all"===this.options.direction||null,this.options.bottom="y"===this.options.direction||"all"===this.options.direction||null),this.parseUnderflow(),this.last={x:null,y:null,scaleX:null,scaleY:null},this.update()}parseUnderflow(){const t=this.options.underflow.toLowerCase();"none"===t?this.noUnderflow=!0:"center"===t?(this.underflowX=this.underflowY=0,this.noUnderflow=!1):(this.underflowX=-1!==t.indexOf("left")?-1:-1!==t.indexOf("right")?1:0,this.underflowY=-1!==t.indexOf("top")?-1:-1!==t.indexOf("bottom")?1:0,this.noUnderflow=!1)}move(){return this.update(),!1}update(){if(this.paused||this.parent.x===this.last.x&&this.parent.y===this.last.y&&this.parent.scale.x===this.last.scaleX&&this.parent.scale.y===this.last.scaleY)return;const t=new Um(this.parent.x,this.parent.y),e=this.parent.plugins.decelerate||{};if(null!==this.options.left||null!==this.options.right){let i=!1;if(!this.noUnderflow&&this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:0!==this.parent.x&&(this.parent.x=0,i=!0);break;case 1:this.parent.x!==this.parent.screenWidth-this.parent.screenWorldWidth&&(this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth,i=!0);break;default:this.parent.x!==(this.parent.screenWidth-this.parent.screenWorldWidth)/2&&(this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2,i=!0)}else null!==this.options.left&&this.parent.left<(!0===this.options.left?0:this.options.left)&&(this.parent.x=-(!0===this.options.left?0:this.options.left)*this.parent.scale.x,e.x=0,i=!0),null!==this.options.right&&this.parent.right>(!0===this.options.right?this.parent.worldWidth:this.options.right)&&(this.parent.x=-(!0===this.options.right?this.parent.worldWidth:this.options.right)*this.parent.scale.x+this.parent.screenWidth,e.x=0,i=!0);i&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-x"})}if(null!==this.options.top||null!==this.options.bottom){let i=!1;if(!this.noUnderflow&&this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:0!==this.parent.y&&(this.parent.y=0,i=!0);break;case 1:this.parent.y!==this.parent.screenHeight-this.parent.screenWorldHeight&&(this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight,i=!0);break;default:this.parent.y!==(this.parent.screenHeight-this.parent.screenWorldHeight)/2&&(this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2,i=!0)}else null!==this.options.top&&this.parent.top<(!0===this.options.top?0:this.options.top)&&(this.parent.y=-(!0===this.options.top?0:this.options.top)*this.parent.scale.y,e.y=0,i=!0),null!==this.options.bottom&&this.parent.bottom>(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)&&(this.parent.y=-(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)*this.parent.scale.y+this.parent.screenHeight,e.y=0,i=!0);i&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-y"})}this.last.x=this.parent.x,this.last.y=this.parent.y,this.last.scaleX=this.parent.scale.x,this.last.scaleY=this.parent.scale.y}reset(){this.update()}}const bb={minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,minScale:null,maxScale:null};class _b extends lb{constructor(t,e={}){super(t),ab(this,"options"),this.options=Object.assign({},bb,e),this.clamp()}resize(){this.clamp()}clamp(){if(!this.paused)if(this.options.minWidth||this.options.minHeight||this.options.maxWidth||this.options.maxHeight){let t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight;if(null!==this.options.minWidth&&t<this.options.minWidth){const i=this.parent.scale.x;this.parent.fitWidth(this.options.minWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/i,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxWidth&&t>this.options.maxWidth){const i=this.parent.scale.x;this.parent.fitWidth(this.options.maxWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/i,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.minHeight&&e<this.options.minHeight){const i=this.parent.scale.y;this.parent.fitHeight(this.options.minHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/i,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxHeight&&e>this.options.maxHeight){const t=this.parent.scale.y;this.parent.fitHeight(this.options.maxHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/t,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}}else if(this.options.minScale||this.options.maxScale){const t={x:null,y:null},e={x:null,y:null};if("number"==typeof this.options.minScale)t.x=this.options.minScale,t.y=this.options.minScale;else if(null!==this.options.minScale){const e=this.options.minScale;t.x=typeof e.x>"u"?null:e.x,t.y=typeof e.y>"u"?null:e.y}if("number"==typeof this.options.maxScale)e.x=this.options.maxScale,e.y=this.options.maxScale;else if(null!==this.options.maxScale){const t=this.options.maxScale;e.x=typeof t.x>"u"?null:t.x,e.y=typeof t.y>"u"?null:t.y}let i=this.parent.scale.x,s=this.parent.scale.y;null!==t.x&&i<t.x&&(i=t.x),null!==e.x&&i>e.x&&(i=e.x),null!==t.y&&s<t.y&&(s=t.y),null!==e.y&&s>e.y&&(s=e.y),(i!==this.parent.scale.x||s!==this.parent.scale.y)&&(this.parent.scale.set(i,s),this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"}))}}reset(){this.clamp()}}const wb={friction:.98,bounce:.8,minSpeed:.01},Pb=16;let Eb=class extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"x"),ab(this,"y"),ab(this,"percentChangeX"),ab(this,"percentChangeY"),ab(this,"saved"),ab(this,"timeSinceRelease"),this.options=Object.assign({},wb,e),this.saved=[],this.timeSinceRelease=0,this.reset(),this.parent.on("moved",(t=>this.handleMoved(t)))}down(){return this.saved=[],this.x=this.y=null,!1}isActive(){return!(!this.x&&!this.y)}move(){if(this.paused)return!1;const t=this.parent.input.count();return(1===t||t>1&&!this.parent.plugins.get("pinch",!0))&&(this.saved.push({x:this.parent.x,y:this.parent.y,time:performance.now()}),this.saved.length>60&&this.saved.splice(0,30)),!1}handleMoved(t){if(this.saved.length){const e=this.saved[this.saved.length-1];"clamp-x"===t.type&&t.original?e.x===t.original.x&&(e.x=this.parent.x):"clamp-y"===t.type&&t.original&&e.y===t.original.y&&(e.y=this.parent.y)}}up(){if(0===this.parent.input.count()&&this.saved.length){const t=performance.now();for(const e of this.saved)if(e.time>=t-100){const i=t-e.time;this.x=(this.parent.x-e.x)/i,this.y=(this.parent.y-e.y)/i,this.percentChangeX=this.percentChangeY=this.options.friction,this.timeSinceRelease=0;break}}return!1}activate(t){typeof(t=t||{}).x<"u"&&(this.x=t.x,this.percentChangeX=this.options.friction),typeof t.y<"u"&&(this.y=t.y,this.percentChangeY=this.options.friction)}update(t){if(this.paused)return;const e=this.x||this.y,i=this.timeSinceRelease,s=this.timeSinceRelease+t;if(this.x){const e=this.percentChangeX,r=Math.log(e);this.parent.x+=this.x*Pb/r*(Math.pow(e,s/Pb)-Math.pow(e,i/Pb)),this.x*=Math.pow(this.percentChangeX,t/Pb)}if(this.y){const e=this.percentChangeY,r=Math.log(e);this.parent.y+=this.y*Pb/r*(Math.pow(e,s/Pb)-Math.pow(e,i/Pb)),this.y*=Math.pow(this.percentChangeY,t/Pb)}this.timeSinceRelease+=t,this.x&&this.y?Math.abs(this.x)<this.options.minSpeed&&Math.abs(this.y)<this.options.minSpeed&&(this.x=0,this.y=0):(Math.abs(this.x||0)<this.options.minSpeed&&(this.x=0),Math.abs(this.y||0)<this.options.minSpeed&&(this.y=0)),e&&this.parent.emit("moved",{viewport:this.parent,type:"decelerate"})}reset(){this.x=this.y=null}};const Tb={direction:"all",pressDrag:!0,wheel:!0,wheelScroll:1,reverse:!1,clampWheel:!1,underflow:"center",factor:1,mouseButtons:"all",keyToPress:null,ignoreKeyToPressOnTouch:!1,lineHeight:20,wheelSwapAxes:!1};class Ab extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"moved"),ab(this,"reverse"),ab(this,"xDirection"),ab(this,"yDirection"),ab(this,"keyIsPressed"),ab(this,"mouse"),ab(this,"underflowX"),ab(this,"underflowY"),ab(this,"last"),ab(this,"current"),ab(this,"windowEventHandlers",[]),this.options=Object.assign({},Tb,e),this.moved=!1,this.reverse=this.options.reverse?1:-1,this.xDirection=!this.options.direction||"all"===this.options.direction||"x"===this.options.direction,this.yDirection=!this.options.direction||"all"===this.options.direction||"y"===this.options.direction,this.keyIsPressed=!1,this.parseUnderflow(),this.mouseButtons(this.options.mouseButtons),this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){this.addWindowEventHandler("keyup",(e=>{t.includes(e.code)&&(this.keyIsPressed=!1)})),this.addWindowEventHandler("keydown",(e=>{t.includes(e.code)&&(this.keyIsPressed=!0)}))}addWindowEventHandler(t,e){window.addEventListener(t,e),this.windowEventHandlers.push({event:t,handler:e})}destroy(){this.windowEventHandlers.forEach((({event:t,handler:e})=>{window.removeEventListener(t,e)}))}mouseButtons(t){this.mouse=t&&"all"!==t?[-1!==t.indexOf("left"),-1!==t.indexOf("middle"),-1!==t.indexOf("right")]:[!0,!0,!0]}parseUnderflow(){const t=this.options.underflow.toLowerCase();"center"===t?(this.underflowX=0,this.underflowY=0):(t.includes("left")?this.underflowX=-1:t.includes("right")?this.underflowX=1:this.underflowX=0,t.includes("top")?this.underflowY=-1:t.includes("bottom")?this.underflowY=1:this.underflowY=0)}checkButtons(t){const e="mouse"===t.pointerType,i=this.parent.input.count();return!(!(1===i||i>1&&!this.parent.plugins.get("pinch",!0))||e&&!this.mouse[t.button])}checkKeyPress(t){return!this.options.keyToPress||this.keyIsPressed||this.options.ignoreKeyToPressOnTouch&&"touch"===t.data.pointerType}down(t){return!(this.paused||!this.options.pressDrag)&&(this.checkButtons(t)&&this.checkKeyPress(t)?(this.last={x:t.global.x,y:t.global.y},this.current=t.pointerId,!0):(this.last=null,!1))}get active(){return this.moved}move(t){if(this.paused||!this.options.pressDrag)return!1;if(this.last&&this.current===t.data.pointerId){const e=t.global.x,i=t.global.y,s=this.parent.input.count();if(1===s||s>1&&!this.parent.plugins.get("pinch",!0)){const s=e-this.last.x,r=i-this.last.y;if(this.moved||this.xDirection&&this.parent.input.checkThreshold(s)||this.yDirection&&this.parent.input.checkThreshold(r)){const s={x:e,y:i};return this.xDirection&&(this.parent.x+=(s.x-this.last.x)*this.options.factor),this.yDirection&&(this.parent.y+=(s.y-this.last.y)*this.options.factor),this.last=s,this.moved||this.parent.emit("drag-start",{event:t,screen:new Um(this.last.x,this.last.y),world:this.parent.toWorld(new Um(this.last.x,this.last.y)),viewport:this.parent}),this.moved=!0,this.parent.emit("moved",{viewport:this.parent,type:"drag"}),!0}}else this.moved=!1}return!1}up(t){if(this.paused)return!1;const e=this.parent.input.touches;if(1===e.length){const t=e[0];return t.last&&(this.last={x:t.last.x,y:t.last.y},this.current=t.id),this.moved=!1,!0}if(this.last&&this.moved){const e=new Um(this.last.x,this.last.y);return this.parent.emit("drag-end",{event:t,screen:e,world:this.parent.toWorld(e),viewport:this.parent}),this.last=null,this.moved=!1,!0}return!1}wheel(t){if(this.paused)return!1;if(this.options.wheel){const e=this.parent.plugins.get("wheel",!0);if(!e||!e.options.wheelZoom&&!t.ctrlKey){const e=t.deltaMode?this.options.lineHeight:1,i=[t.deltaX,t.deltaY],[s,r]=this.options.wheelSwapAxes?i.reverse():i;return this.xDirection&&(this.parent.x+=s*e*this.options.wheelScroll*this.reverse),this.yDirection&&(this.parent.y+=r*e*this.options.wheelScroll*this.reverse),this.options.clampWheel&&this.clamp(),this.parent.emit("wheel-scroll",this.parent),this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.options.passiveWheel||t.preventDefault(),this.parent.options.stopPropagation&&t.stopPropagation(),!0}}return!1}resume(){this.last=null,this.paused=!1}clamp(){const t=this.parent.plugins.get("decelerate",!0)||{};if("y"!==this.options.clampWheel)if(this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:this.parent.x=0;break;case 1:this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}else this.parent.left<0?(this.parent.x=0,t.x=0):this.parent.right>this.parent.worldWidth&&(this.parent.x=-this.parent.worldWidth*this.parent.scale.x+this.parent.screenWidth,t.x=0);if("x"!==this.options.clampWheel)if(this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:this.parent.y=0;break;case 1:this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}else this.parent.top<0&&(this.parent.y=0,t.y=0),this.parent.bottom>this.parent.worldHeight&&(this.parent.y=-this.parent.worldHeight*this.parent.scale.y+this.parent.screenHeight,t.y=0)}}const Ib={speed:0,acceleration:null,radius:null};class Sb extends lb{constructor(t,e,i={}){super(t),ab(this,"options"),ab(this,"target"),ab(this,"velocity"),this.target=e,this.options=Object.assign({},Ib,i),this.velocity={x:0,y:0}}update(t){if(this.paused)return;const e=this.parent.center;let i=this.target.x,s=this.target.y;if(this.options.radius){if(!(Math.sqrt(Math.pow(this.target.y-e.y,2)+Math.pow(this.target.x-e.x,2))>this.options.radius))return;{const t=Math.atan2(this.target.y-e.y,this.target.x-e.x);i=this.target.x-Math.cos(t)*this.options.radius,s=this.target.y-Math.sin(t)*this.options.radius}}const r=i-e.x,n=s-e.y;if(r||n)if(this.options.speed)if(this.options.acceleration){const t=Math.atan2(s-e.y,i-e.x),o=Math.sqrt(Math.pow(r,2)+Math.pow(n,2));if(o){const a=(Math.pow(this.velocity.x,2)+Math.pow(this.velocity.y,2))/(2*this.options.acceleration);this.velocity=o>a?{x:Math.min(this.velocity.x+(this.options.acceleration,this.options.speed)),y:Math.min(this.velocity.y+(this.options.acceleration,this.options.speed))}:{x:Math.max(this.velocity.x-this.options.acceleration*this.options.speed,0),y:Math.max(this.velocity.y-this.options.acceleration*this.options.speed,0)};const l=Math.cos(t)*this.velocity.x,h=Math.sin(t)*this.velocity.y,u=Math.abs(l)>Math.abs(r)?i:e.x+l,c=Math.abs(h)>Math.abs(n)?s:e.y+h;this.parent.moveCenter(u,c),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}else{const t=Math.atan2(s-e.y,i-e.x),o=Math.cos(t)*this.options.speed,a=Math.sin(t)*this.options.speed,l=Math.abs(o)>Math.abs(r)?i:e.x+o,h=Math.abs(a)>Math.abs(n)?s:e.y+a;this.parent.moveCenter(l,h),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}else this.parent.moveCenter(i,s),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}const Cb={radius:null,distance:null,top:null,bottom:null,left:null,right:null,speed:8,reverse:!1,noDecelerate:!1,linear:!1,allowButtons:!1};let Mb=class extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"reverse"),ab(this,"radiusSquared"),ab(this,"left"),ab(this,"top"),ab(this,"right"),ab(this,"bottom"),ab(this,"horizontal"),ab(this,"vertical"),this.options=Object.assign({},Cb,e),this.reverse=this.options.reverse?1:-1,this.radiusSquared="number"==typeof this.options.radius?Math.pow(this.options.radius,2):null,this.resize()}resize(){const t=this.options.distance;null!==t?(this.left=t,this.top=t,this.right=this.parent.screenWidth-t,this.bottom=this.parent.screenHeight-t):this.options.radius||(this.left=this.options.left,this.top=this.options.top,this.right=null===this.options.right?null:this.parent.screenWidth-this.options.right,this.bottom=null===this.options.bottom?null:this.parent.screenHeight-this.options.bottom)}down(){return this.paused||this.options.allowButtons||(this.horizontal=this.vertical=null),!1}move(t){if(this.paused||"mouse"!==t.pointerType&&1!==t.pointerId||!this.options.allowButtons&&0!==t.buttons)return!1;const e=t.global.x,i=t.global.y;if(this.radiusSquared){const t=this.parent.toScreen(this.parent.center);if(Math.pow(t.x-e,2)+Math.pow(t.y-i,2)>=this.radiusSquared){const s=Math.atan2(t.y-i,t.x-e);this.options.linear?(this.horizontal=Math.round(Math.cos(s))*this.options.speed*this.reverse*.06,this.vertical=Math.round(Math.sin(s))*this.options.speed*this.reverse*.06):(this.horizontal=Math.cos(s)*this.options.speed*this.reverse*.06,this.vertical=Math.sin(s)*this.options.speed*this.reverse*.06)}else this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=0}else null!==this.left&&e<this.left?this.horizontal=Number(this.reverse)*this.options.speed*.06:null!==this.right&&e>this.right?this.horizontal=-1*this.reverse*this.options.speed*.06:(this.decelerateHorizontal(),this.horizontal=0),null!==this.top&&i<this.top?this.vertical=Number(this.reverse)*this.options.speed*.06:null!==this.bottom&&i>this.bottom?this.vertical=-1*this.reverse*this.options.speed*.06:(this.decelerateVertical(),this.vertical=0);return!1}decelerateHorizontal(){const t=this.parent.plugins.get("decelerate",!0);this.horizontal&&t&&!this.options.noDecelerate&&t.activate({x:this.horizontal*this.options.speed*this.reverse/(1e3/60)})}decelerateVertical(){const t=this.parent.plugins.get("decelerate",!0);this.vertical&&t&&!this.options.noDecelerate&&t.activate({y:this.vertical*this.options.speed*this.reverse/(1e3/60)})}up(){return this.paused||(this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=null),!1}update(){if(!this.paused&&(this.horizontal||this.vertical)){const t=this.parent.center;this.horizontal&&(t.x+=this.horizontal*this.options.speed),this.vertical&&(t.y+=this.vertical*this.options.speed),this.parent.moveCenter(t),this.parent.emit("moved",{viewport:this.parent,type:"mouse-edges"})}}};const Ob={noDrag:!1,percent:1,center:null,factor:1,axis:"all"};class Nb extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"active",!1),ab(this,"pinching",!1),ab(this,"moved",!1),ab(this,"lastCenter"),this.options=Object.assign({},Ob,e)}down(){return this.parent.input.count()>=2&&(this.active=!0,!0)}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}move(t){if(this.paused||!this.active)return!1;const e=t.global.x,i=t.global.y,s=this.parent.input.touches;if(s.length>=2){const r=s[0],n=s[1],o=r.last&&n.last?Math.sqrt(Math.pow(n.last.x-r.last.x,2)+Math.pow(n.last.y-r.last.y,2)):null;if(r.id===t.pointerId?r.last={x:e,y:i,data:t}:n.id===t.pointerId&&(n.last={x:e,y:i,data:t}),o){let t;const e=new Um(r.last.x+(n.last.x-r.last.x)/2,r.last.y+(n.last.y-r.last.y)/2);this.options.center||(t=this.parent.toLocal(e));let i=Math.sqrt(Math.pow(n.last.x-r.last.x,2)+Math.pow(n.last.y-r.last.y,2));i=0===i?i=1e-10:i;const s=(1-o/i)*this.options.percent*(this.isAxisX()?this.parent.scale.x:this.parent.scale.y);this.isAxisX()&&(this.parent.scale.x+=s),this.isAxisY()&&(this.parent.scale.y+=s),this.parent.emit("zoomed",{viewport:this.parent,type:"pinch",center:e});const a=this.parent.plugins.get("clamp-zoom",!0);if(a&&a.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const i=this.parent.toGlobal(t);this.parent.x+=(e.x-i.x)*this.options.factor,this.parent.y+=(e.y-i.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})}!this.options.noDrag&&this.lastCenter&&(this.parent.x+=(e.x-this.lastCenter.x)*this.options.factor,this.parent.y+=(e.y-this.lastCenter.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})),this.lastCenter=e,this.moved=!0}else this.pinching||(this.parent.emit("pinch-start",this.parent),this.pinching=!0);return!0}return!1}up(){return!!(this.pinching&&this.parent.input.touches.length<=1)&&(this.active=!1,this.lastCenter=null,this.pinching=!1,this.moved=!1,this.parent.emit("pinch-end",this.parent),!0)}}const Lb={topLeft:!1,friction:.8,time:1e3,ease:"easeInOutSine",interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1};class Rb extends lb{constructor(t,e,i,s={}){super(t),ab(this,"options"),ab(this,"ease"),ab(this,"x"),ab(this,"y"),ab(this,"percent"),ab(this,"snapping"),ab(this,"deltaX"),ab(this,"deltaY"),ab(this,"startX"),ab(this,"startY"),this.options=Object.assign({},Lb,s),this.ease=pb(s.ease,"easeInOutSine"),this.x=e,this.y=i,this.options.forceStart&&this.snapStart()}snapStart(){this.percent=0,this.snapping={time:0};const t=this.options.topLeft?this.parent.corner:this.parent.center;this.deltaX=this.x-t.x,this.deltaY=this.y-t.y,this.startX=t.x,this.startY=t.y,this.parent.emit("snap-start",this.parent)}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap"):this.options.interrupt&&(this.snapping=null),!1}up(){if(0===this.parent.input.count()){const t=this.parent.plugins.get("decelerate",!0);t&&(t.x||t.y)&&(t.percentChangeX=t.percentChangeY=this.options.friction)}return!1}update(t){if(!(this.paused||this.options.interrupt&&0!==this.parent.input.count()))if(this.snapping){const e=this.snapping;let i,s,r;e.time+=t;const n=this.startX,o=this.startY,a=this.deltaX,l=this.deltaY;if(e.time>this.options.time)i=!0,s=n+a,r=o+l;else{const t=this.ease(e.time,0,1,this.options.time);s=n+a*t,r=o+l*t}this.options.topLeft?this.parent.moveCorner(s,r):this.parent.moveCenter(s,r),this.parent.emit("moved",{viewport:this.parent,type:"snap"}),i&&(this.options.removeOnComplete&&this.parent.plugins.remove("snap"),this.parent.emit("snap-end",this.parent),this.snapping=null)}else{const t=this.options.topLeft?this.parent.corner:this.parent.center;(t.x!==this.x||t.y!==this.y)&&this.snapStart()}}}const kb={width:0,height:0,time:1e3,ease:"easeInOutSine",center:null,interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1,noMove:!1};class Bb extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"ease"),ab(this,"xScale"),ab(this,"yScale"),ab(this,"xIndependent"),ab(this,"yIndependent"),ab(this,"snapping"),this.options=Object.assign({},kb,e),this.ease=pb(this.options.ease),this.xIndependent=!1,this.yIndependent=!1,this.xScale=0,this.yScale=0,this.options.width>0&&(this.xScale=t.screenWidth/this.options.width,this.xIndependent=!0),this.options.height>0&&(this.yScale=t.screenHeight/this.options.height,this.yIndependent=!0),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale,0===this.options.time?(t.container.scale.x=this.xScale,t.container.scale.y=this.yScale,this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom")):e.forceStart&&this.createSnapping()}createSnapping(){const t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,i=this.parent.screenWidth/this.xScale,s=this.parent.screenHeight/this.yScale;this.snapping={time:0,startX:t,startY:e,deltaX:i-t,deltaY:s-e},this.parent.emit("snap-zoom-start",this.parent)}resize(){this.snapping=null,this.options.width>0&&(this.xScale=this.parent.screenWidth/this.options.width),this.options.height>0&&(this.yScale=this.parent.screenHeight/this.options.height),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap-zoom"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap-zoom"):this.options.interrupt&&(this.snapping=null),!1}update(t){if(this.paused||this.options.interrupt&&0!==this.parent.input.count())return;let e;if(!this.options.center&&!this.options.noMove&&(e=this.parent.center),this.snapping){if(this.snapping){const i=this.snapping;if(i.time+=t,i.time>=this.options.time)this.parent.scale.set(this.xScale,this.yScale),this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom"),this.parent.emit("snap-zoom-end",this.parent),this.snapping=null;else{const t=this.snapping,e=this.ease(t.time,t.startX,t.deltaX,this.options.time),i=this.ease(t.time,t.startY,t.deltaY,this.options.time);this.parent.scale.x=this.parent.screenWidth/e,this.parent.scale.y=this.parent.screenHeight/i}const s=this.parent.plugins.get("clamp-zoom",!0);s&&s.clamp(),this.options.noMove||(this.options.center?this.parent.moveCenter(this.options.center):this.parent.moveCenter(e))}}else(this.parent.scale.x!==this.xScale||this.parent.scale.y!==this.yScale)&&this.createSnapping()}resume(){this.snapping=null,super.resume()}}const Fb={percent:.1,smooth:!1,interrupt:!0,reverse:!1,center:null,lineHeight:20,axis:"all",keyToPress:null,trackpadPinch:!1,wheelZoom:!0};class Db extends lb{constructor(t,e={}){super(t),ab(this,"options"),ab(this,"smoothing"),ab(this,"smoothingCenter"),ab(this,"smoothingCount"),ab(this,"keyIsPressed"),this.options=Object.assign({},Fb,e),this.keyIsPressed=!1,this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){window.addEventListener("keydown",(e=>{t.includes(e.code)&&(this.keyIsPressed=!0)})),window.addEventListener("keyup",(e=>{t.includes(e.code)&&(this.keyIsPressed=!1)}))}checkKeyPress(){return!this.options.keyToPress||this.keyIsPressed}down(){return this.options.interrupt&&(this.smoothing=null),!1}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}update(){if(this.smoothing){const t=this.smoothingCenter,e=this.smoothing;let i;this.options.center||(i=this.parent.toLocal(t)),this.isAxisX()&&(this.parent.scale.x+=e.x),this.isAxisY()&&(this.parent.scale.y+=e.y),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const s=this.parent.plugins.get("clamp-zoom",!0);if(s&&s.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const e=this.parent.toGlobal(i);this.parent.x+=t.x-e.x,this.parent.y+=t.y-e.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.smoothingCount++,this.smoothingCount>=this.options.smooth&&(this.smoothing=null)}}pinch(t){if(this.paused)return;const e=this.parent.input.getPointerPosition(t),i=-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/200,s=Math.pow(2,(1+this.options.percent)*i);let r;this.options.center||(r=this.parent.toLocal(e)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const n=this.parent.plugins.get("clamp-zoom",!0);if(n&&n.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const t=this.parent.toGlobal(r);this.parent.x+=e.x-t.x,this.parent.y+=e.y-t.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel-start",{event:t,viewport:this.parent})}wheel(t){if(this.paused||!this.checkKeyPress())return!1;if(t.ctrlKey&&this.options.trackpadPinch)this.pinch(t);else if(this.options.wheelZoom){const e=this.parent.input.getPointerPosition(t),i=(this.options.reverse?-1:1)*-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/500,s=Math.pow(2,(1+this.options.percent)*i);if(this.options.smooth){const t={x:this.smoothing?this.smoothing.x*(this.options.smooth-this.smoothingCount):0,y:this.smoothing?this.smoothing.y*(this.options.smooth-this.smoothingCount):0};this.smoothing={x:((this.parent.scale.x+t.x)*s-this.parent.scale.x)/this.options.smooth,y:((this.parent.scale.y+t.y)*s-this.parent.scale.y)/this.options.smooth},this.smoothingCount=0,this.smoothingCenter=e}else{let t;this.options.center||(t=this.parent.toLocal(e)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const i=this.parent.plugins.get("clamp-zoom",!0);if(i&&i.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const i=this.parent.toGlobal(t);this.parent.x+=e.x-i.x,this.parent.y+=e.y-i.y}}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel-start",{event:t,viewport:this.parent})}return!this.parent.options.passiveWheel}}let Ub=class{constructor(t){ab(this,"viewport"),ab(this,"clickedAvailable"),ab(this,"isMouseDown"),ab(this,"last"),ab(this,"wheelFunction"),ab(this,"touches"),this.viewport=t,this.touches=[],this.addListeners()}addListeners(){this.viewport.eventMode="static",this.viewport.forceHitArea||(this.viewport.hitArea=new Xm(0,0,this.viewport.worldWidth,this.viewport.worldHeight)),this.viewport.on("pointerdown",this.down,this),this.viewport.options.allowPreserveDragOutside?this.viewport.on("globalpointermove",this.move,this):this.viewport.on("pointermove",this.move,this),this.viewport.on("pointerup",this.up,this),this.viewport.on("pointerupoutside",this.up,this),this.viewport.on("pointercancel",this.up,this),this.viewport.options.allowPreserveDragOutside||this.viewport.on("pointerleave",this.up,this),this.wheelFunction=t=>this.handleWheel(t),this.viewport.options.events.domElement.addEventListener("wheel",this.wheelFunction,{passive:this.viewport.options.passiveWheel}),this.isMouseDown=!1}destroy(){this.viewport.options.events.domElement.removeEventListener("wheel",this.wheelFunction)}down(t){if(!this.viewport.pause&&this.viewport.worldVisible){if("mouse"===t.pointerType?this.isMouseDown=!0:this.get(t.pointerId)||this.touches.push({id:t.pointerId,last:null}),1===this.count()){this.last=t.global.clone();const e=this.viewport.plugins.get("decelerate",!0),i=this.viewport.plugins.get("bounce",!0);e&&e.isActive()||i&&i.isActive()?this.clickedAvailable=!1:this.clickedAvailable=!0}else this.clickedAvailable=!1;this.viewport.plugins.down(t)&&this.viewport.options.stopPropagation&&t.stopPropagation()}}clear(){this.isMouseDown=!1,this.touches=[],this.last=null}checkThreshold(t){return Math.abs(t)>=this.viewport.threshold}move(t){if(this.viewport.pause||!this.viewport.worldVisible)return;const e=this.viewport.plugins.move(t);if(this.clickedAvailable&&this.last){const e=t.global.x-this.last.x,i=t.global.y-this.last.y;(this.checkThreshold(e)||this.checkThreshold(i))&&(this.clickedAvailable=!1)}e&&this.viewport.options.stopPropagation&&t.stopPropagation()}up(t){if(this.viewport.pause||!this.viewport.worldVisible)return;"mouse"===t.pointerType&&(this.isMouseDown=!1),"mouse"!==t.pointerType&&this.remove(t.pointerId);const e=this.viewport.plugins.up(t);this.clickedAvailable&&0===this.count()&&this.last&&(this.viewport.emit("clicked",{event:t,screen:this.last,world:this.viewport.toWorld(this.last),viewport:this.viewport}),this.clickedAvailable=!1),e&&this.viewport.options.stopPropagation&&t.stopPropagation()}getPointerPosition(t){const e=new Um;return this.viewport.options.events.mapPositionToPoint(e,t.clientX,t.clientY),e}handleWheel(t){if(this.viewport.pause||!this.viewport.worldVisible)return;const e=this.viewport.toLocal(this.getPointerPosition(t));this.viewport.left<=e.x&&e.x<=this.viewport.right&&this.viewport.top<=e.y&&e.y<=this.viewport.bottom&&this.viewport.plugins.wheel(t)&&!this.viewport.options.passiveWheel&&t.preventDefault()}pause(){this.touches=[],this.isMouseDown=!1}get(t){for(const e of this.touches)if(e.id===t)return e;return null}remove(t){for(let e=0;e<this.touches.length;e++)if(this.touches[e].id===t)return void this.touches.splice(e,1)}count(){return(this.isMouseDown?1:0)+this.touches.length}};const Gb=["drag","pinch","wheel","follow","mouse-edges","decelerate","animate","bounce","snap-zoom","clamp-zoom","snap","clamp"];class Xb{constructor(t){ab(this,"plugins"),ab(this,"list"),ab(this,"viewport"),this.viewport=t,this.list=[],this.plugins={}}add(t,e,i=Gb.length){const s=this.plugins[t];s&&s.destroy(),this.plugins[t]=e;const r=Gb.indexOf(t);-1!==r&&Gb.splice(r,1),Gb.splice(i,0,t),this.sort()}get(t,e){var i;return e&&null!=(i=this.plugins[t])&&i.paused?null:this.plugins[t]}update(t){for(const e of this.list)e.update(t)}resize(){for(const t of this.list)t.resize()}reset(){for(const t of this.list)t.reset()}removeAll(){this.list.forEach((t=>{t.destroy()})),this.plugins={},this.sort()}remove(t){var e;this.plugins[t]&&(null==(e=this.plugins[t])||e.destroy(),delete this.plugins[t],this.viewport.emit("plugin-remove",t),this.sort())}pause(t){var e;null==(e=this.plugins[t])||e.pause()}resume(t){var e;null==(e=this.plugins[t])||e.resume()}sort(){this.list=[];for(const t of Gb)this.plugins[t]&&this.list.push(this.plugins[t])}down(t){let e=!1;for(const i of this.list)i.down(t)&&(e=!0);return e}move(t){let e=!1;for(const i of this.viewport.plugins.list)i.move(t)&&(e=!0);return e}up(t){let e=!1;for(const i of this.list)i.up(t)&&(e=!0);return e}wheel(t){let e=!1;for(const i of this.list)i.wheel(t)&&(e=!0);return e}}const Wb={screenWidth:window.innerWidth,screenHeight:window.innerHeight,worldWidth:null,worldHeight:null,threshold:5,passiveWheel:!0,stopPropagation:!1,forceHitArea:null,noTicker:!1,disableOnContextMenu:!1,ticker:Vy.shared,allowPreserveDragOutside:!1};class Hb extends vv{constructor(t){super(),ab(this,"moving"),ab(this,"screenWidth"),ab(this,"screenHeight"),ab(this,"threshold"),ab(this,"input"),ab(this,"plugins"),ab(this,"zooming"),ab(this,"lastViewport"),ab(this,"options"),ab(this,"_dirty"),ab(this,"_forceHitArea"),ab(this,"_hitAreaDefault"),ab(this,"_pause"),ab(this,"tickerFunction"),ab(this,"_worldWidth"),ab(this,"_worldHeight"),ab(this,"_disableOnContextMenu",(t=>t.preventDefault())),this.options={...Wb,...t},this.screenWidth=this.options.screenWidth,this.screenHeight=this.options.screenHeight,this._worldWidth=this.options.worldWidth,this._worldHeight=this.options.worldHeight,this.forceHitArea=this.options.forceHitArea,this.threshold=this.options.threshold,this.options.disableOnContextMenu&&this.options.events.domElement.addEventListener("contextmenu",this._disableOnContextMenu),this.options.noTicker||(this.tickerFunction=()=>this.update(this.options.ticker.elapsedMS),this.options.ticker.add(this.tickerFunction)),this.input=new Ub(this),this.plugins=new Xb(this)}destroy(t){!this.options.noTicker&&this.tickerFunction&&this.options.ticker.remove(this.tickerFunction),this.options.disableOnContextMenu&&this.options.events.domElement.removeEventListener("contextmenu",this._disableOnContextMenu),this.input.destroy(),super.destroy(t)}update(t){this.pause||(this.plugins.update(t),this.lastViewport&&(this.lastViewport.x!==this.x||this.lastViewport.y!==this.y?this.moving=!0:this.moving&&(this.emit("moved-end",this),this.moving=!1),this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y?this.zooming=!0:this.zooming&&(this.emit("zoomed-end",this),this.zooming=!1)),this.forceHitArea||(this._hitAreaDefault=new Xm(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight),this.hitArea=this._hitAreaDefault),this._dirty=this._dirty||!this.lastViewport||this.lastViewport.x!==this.x||this.lastViewport.y!==this.y||this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y,this.lastViewport={x:this.x,y:this.y,scaleX:this.scale.x,scaleY:this.scale.y},this.emit("frame-end",this))}resize(t=window.innerWidth,e=window.innerHeight,i,s){this.screenWidth=t,this.screenHeight=e,typeof i<"u"&&(this._worldWidth=i),typeof s<"u"&&(this._worldHeight=s),this.plugins.resize(),this.dirty=!0}get worldWidth(){return this._worldWidth?this._worldWidth:this.width/this.scale.x}set worldWidth(t){this._worldWidth=t,this.plugins.resize()}get worldHeight(){return this._worldHeight?this._worldHeight:this.height/this.scale.y}set worldHeight(t){this._worldHeight=t,this.plugins.resize()}getVisibleBounds(){return new Xm(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight)}toWorld(t,e){return 2===arguments.length?this.toLocal(new Um(t,e)):this.toLocal(t)}toScreen(t,e){return 2===arguments.length?this.toGlobal(new Um(t,e)):this.toGlobal(t)}get worldScreenWidth(){return this.screenWidth/this.scale.x}get worldScreenHeight(){return this.screenHeight/this.scale.y}get screenWorldWidth(){return this.worldWidth*this.scale.x}get screenWorldHeight(){return this.worldHeight*this.scale.y}get center(){return new Um(this.worldScreenWidth/2-this.x/this.scale.x,this.worldScreenHeight/2-this.y/this.scale.y)}set center(t){this.moveCenter(t)}moveCenter(...t){let e,i;"number"==typeof t[0]?(e=t[0],i=t[1]):(e=t[0].x,i=t[0].y);const s=(this.worldScreenWidth/2-e)*this.scale.x,r=(this.worldScreenHeight/2-i)*this.scale.y;return(this.x!==s||this.y!==r)&&(this.position.set(s,r),this.plugins.reset(),this.dirty=!0),this}get corner(){return new Um(-this.x/this.scale.x,-this.y/this.scale.y)}set corner(t){this.moveCorner(t)}moveCorner(...t){let e,i;return 1===t.length?(e=-t[0].x*this.scale.x,i=-t[0].y*this.scale.y):(e=-t[0]*this.scale.x,i=-t[1]*this.scale.y),(e!==this.x||i!==this.y)&&(this.position.set(e,i),this.plugins.reset(),this.dirty=!0),this}get screenWidthInWorldPixels(){return this.screenWidth/this.scale.x}get screenHeightInWorldPixels(){return this.screenHeight/this.scale.y}findFitWidth(t){return this.screenWidth/t}findFitHeight(t){return this.screenHeight/t}findFit(t,e){const i=this.screenWidth/t,s=this.screenHeight/e;return Math.min(i,s)}findCover(t,e){const i=this.screenWidth/t,s=this.screenHeight/e;return Math.max(i,s)}fitWidth(t=this.worldWidth,e,i=!0,s){let r;e&&(r=this.center),this.scale.x=this.screenWidth/t,i&&(this.scale.y=this.scale.x);const n=this.plugins.get("clamp-zoom",!0);return!s&&n&&n.clamp(),e&&r&&this.moveCenter(r),this}fitHeight(t=this.worldHeight,e,i=!0,s){let r;e&&(r=this.center),this.scale.y=this.screenHeight/t,i&&(this.scale.x=this.scale.y);const n=this.plugins.get("clamp-zoom",!0);return!s&&n&&n.clamp(),e&&r&&this.moveCenter(r),this}fitWorld(t){let e;t&&(e=this.center),this.scale.x=this.screenWidth/this.worldWidth,this.scale.y=this.screenHeight/this.worldHeight,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const i=this.plugins.get("clamp-zoom",!0);return i&&i.clamp(),t&&e&&this.moveCenter(e),this}fit(t,e=this.worldWidth,i=this.worldHeight){let s;t&&(s=this.center),this.scale.x=this.screenWidth/e,this.scale.y=this.screenHeight/i,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const r=this.plugins.get("clamp-zoom",!0);return r&&r.clamp(),t&&s&&this.moveCenter(s),this}setZoom(t,e){let i;e&&(i=this.center),this.scale.set(t);const s=this.plugins.get("clamp-zoom",!0);return s&&s.clamp(),e&&i&&this.moveCenter(i),this}zoomPercent(t,e){return this.setZoom(this.scale.x+this.scale.x*t,e)}zoom(t,e){return this.fitWidth(t+this.worldScreenWidth,e),this}get scaled(){return this.scale.x}set scaled(t){this.setZoom(t,!0)}snapZoom(t){return this.plugins.add("snap-zoom",new Bb(this,t)),this}OOB(){return{left:this.left<0,right:this.right>this.worldWidth,top:this.top<0,bottom:this.bottom>this.worldHeight,cornerPoint:new Um(this.worldWidth*this.scale.x-this.screenWidth,this.worldHeight*this.scale.y-this.screenHeight)}}get right(){return-this.x/this.scale.x+this.worldScreenWidth}set right(t){this.x=-t*this.scale.x+this.screenWidth,this.plugins.reset()}get left(){return-this.x/this.scale.x}set left(t){this.x=-t*this.scale.x,this.plugins.reset()}get top(){return-this.y/this.scale.y}set top(t){this.y=-t*this.scale.y,this.plugins.reset()}get bottom(){return-this.y/this.scale.y+this.worldScreenHeight}set bottom(t){this.y=-t*this.scale.y+this.screenHeight,this.plugins.reset()}get dirty(){return!!this._dirty}set dirty(t){this._dirty=t}get forceHitArea(){return this._forceHitArea}set forceHitArea(t){t?(this._forceHitArea=t,this.hitArea=t):(this._forceHitArea=null,this.hitArea=new Xm(0,0,this.worldWidth,this.worldHeight))}drag(t){return this.plugins.add("drag",new Ab(this,t)),this}clamp(t){return this.plugins.add("clamp",new xb(this,t)),this}decelerate(t){return this.plugins.add("decelerate",new Eb(this,t)),this}bounce(t){return this.plugins.add("bounce",new yb(this,t)),this}pinch(t){return this.plugins.add("pinch",new Nb(this,t)),this}snap(t,e,i){return this.plugins.add("snap",new Rb(this,t,e,i)),this}follow(t,e){return this.plugins.add("follow",new Sb(this,t,e)),this}wheel(t){return this.plugins.add("wheel",new Db(this,t)),this}animate(t){return this.plugins.add("animate",new mb(this,t)),this}clampZoom(t){return this.plugins.add("clamp-zoom",new _b(this,t)),this}mouseEdges(t){return this.plugins.add("mouse-edges",new Mb(this,t)),this}get pause(){return!!this._pause}set pause(t){this._pause=t,this.lastViewport=null,this.moving=!1,this.zooming=!1,t&&this.input.pause()}ensureVisible(t,e,i,s,r){r&&(i>this.worldScreenWidth||s>this.worldScreenHeight)&&(this.fit(!0,i,s),this.emit("zoomed",{viewport:this,type:"ensureVisible"}));let n=!1;t<this.left?(this.left=t,n=!0):t+i>this.right&&(this.right=t+i,n=!0),e<this.top?(this.top=e,n=!0):e+s>this.bottom&&(this.bottom=e+s,n=!0),n&&this.emit("moved",{viewport:this,type:"ensureVisible"})}}var Yb,$b,jb,zb=t=>{throw TypeError(t)},Vb=(t,e,i)=>e.has(t)||zb("Cannot "+i),qb=(t,e,i)=>e.has(t)?zb("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),Jb=(t,e,i,s)=>(Vb(t,e,"write to private field"),e.set(t,i),i),Kb=(t,e,i)=>(Vb(t,e,"access private method"),i);const Zb=100;var Qb={exports:{}};function t_(){}t_.prototype={on:function(t,e,i){var s=this.e||(this.e={});return(s[t]||(s[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){var s=this;function r(){s.off(t,r),e.apply(i,arguments)}return r._=e,this.on(t,r,i)},emit:function(t){for(var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),s=0,r=i.length;s<r;s++)i[s].fn.apply(i[s].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),s=i[t],r=[];if(s&&e)for(var n=0,o=s.length;n<o;n++)s[n].fn!==e&&s[n].fn._!==e&&r.push(s[n]);return r.length?i[t]=r:delete i[t],this}},Qb.exports=t_;var e_=Qb.exports.TinyEmitter=t_;class i_ extends e_{constructor({floorPlan:t,helperId:e}){super(),this.floorPlan=t,this.helperId=e}destroy(){delete this.floorPlan.helper[this.helperId],this.floorPlan=null}}class s_ extends i_{constructor({floorPlan:t,parentEl:e,helperId:i}){super({floorPlan:t,helperId:i}),e&&t&&(this.data={cursor:["0","0"]},this.floorPlan.on("mousemove",this.update,this),this.mount(e),this.update())}update(){this.rootEl&&this.setData({cursor:[f(this.floorPlan.interaction.cursor[0],this.floorPlan.settings.units.system,this.floorPlan.settings.units.lengthDecimals),f(this.floorPlan.interaction.cursor[1],this.floorPlan.settings.units.system,this.floorPlan.settings.units.lengthDecimals)]})}setData(t={}){for(let e in t)this.data[e]=t[e];this.rootEl.innerHTML=this.template(this.data)}template(t={}){return`<span class="fpe-coordinates__unit">x:${t.cursor[0]}</span>\n <span class="fpe-coordinates__unit">z:${t.cursor[1]}</span>`}mount(t){this.rootEl||(this.rootEl=document.createElement("div"),this.rootEl.classList.add("fpe-coordinates"),t.appendChild(this.rootEl))}destroy(){this.floorPlan.off("mousemove",this.update),this.rootEl.remove(),delete this.floorPlan,delete this.data}}class r_ extends i_{constructor({floorPlan:t,parentEl:e,helperId:i}){super({floorPlan:t,helperId:i}),e&&t&&(this.data={width:100,height:4,margin:2,style:"lines",box:{},scaleStep:null,scaleDisplay:null,steps:[],leftHanded:!1,isImperial:"imperial"===t.settings.units.system},this.floorPlan.view.on("zoom",this.update,this),this.floorPlan.on("update-settings",this.update,this),this.mount(e),this.update())}update(){this.data.isImperial="imperial"===this.floorPlan.settings.units.system;const t=this.data.isImperial?3.28084:1;if(!this.floorPlan.view.viewbox)return;this.data.box.length=this.floorPlan.view.viewbox.max[0]-this.floorPlan.view.viewbox.min[0],this.data.box.width=this.floorPlan.view.viewbox.max[1]-this.floorPlan.view.viewbox.min[1];const e=Math.min(this.floorPlan.view.client[0],this.floorPlan.view.client[1]),i=Math.min(this.data.box.length,this.data.box.width),s=e/i;if(!s)return;const r=200/s;this.data.scaleStep=i<=.5/t?.01/t:i<=1/t?.05/t:i<=2.5/t?.1/t:i<=5.4/t?.2/t:i<=12/t?.5/t:i<=25/t?1/t:i<=50/t?2/t:i<=100/t?5/t:i<=200/t?10/t:i<=550/t?20/t:50/t,this.data.scaleDisplay=this.data.scaleStep*t;const n=this.data.width,o=n*this.data.scaleStep/r,a=this.leftHanded?0:n;let l=0,h=[];if(this.data.leftHanded)for(;l<n-o;){let t=o<n-l?o:n-l;h.push([l+a,t]),l+=o}else for(;l>-n+o;){let t=o;h.push([l+a,-t]),l-=o}this.data.steps=h,this.setData()}setData(t={}){for(let e in t)this.data[e]=t[e];this.rootEl.setAttribute("viewBox",`-${this.data.margin} -${3*this.data.margin} ${this.data.width+2*this.data.margin} ${this.data.height+2*this.data.margin}`),this.rootEl.innerHTML=this.template(this.data)}template(t={}){let e="";return t.steps[0]&&(e+=`<rect\n class="fpe-scale-bar__background"\n style="fill:${this.backgroundClr()}"\n y="${2.5*-t.height}"\n x="${t.width+t.steps[0][1]-t.margin}"\n width="${-t.steps[0][1]+2*t.margin}"\n height="${4*t.height}"\n />`),e+=`<text x="${t.leftHanded?0:t.width}" text-anchor="${t.leftHanded?"start":"end"}" y="-3">\n ${t.scaleDisplay} ${t.isImperial?"ft":"m"}\n </text>`,"lines"===t.style&&(e+=`<path d="${this.stepStr(t.steps)}" />`),"solid"===t.style&&(e+="<g>",t.steps.forEach(((t,i)=>{e+=`<rect\n class="${i%2!=0?"white":""}"\n x="${t[0]}"\n y="0"\n width="${t[1]}"\n height="0.5"\n />`})),e+="</g>"),e}backgroundClr(){let t=this.floorPlan.settings&&function(t,e=1){if(null!==y(t).match(/^#[a-f0-9]{6}$/i)){const{r:i,g:s,b:r}=x(t);return`rgba(${i},${s},${r},${e})`}}(this.floorPlan.settings.theme.background.color);return t||(t="rgba(255, 255, 255, 0.8)"),t+"!important"}stepStr(t){if(!t)return"";let e="",i=this.data.height;return t.forEach(((t,s)=>{if(s>=1&&!this.data.leftHanded)return;t=t.map((t=>Math.round(1e3*t)/1e3));let r=s%2==0?0:i,n=s%2==0?i:0;0===s&&(e+=`M ${t[0]} ${i} L ${t[0]} 0`),e+=`L ${t[0]+t[1]} ${r} `,e+=`L ${t[0]+t[1]} ${n} `})),e}mount(t){this.rootEl||(this.rootEl=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.rootEl.classList.add("fpe-scale-bar"),t.appendChild(this.rootEl))}destroy(){this.floorPlan.view.off("viewbox",this.update),this.floorPlan.off("update-settings",this.update),this.rootEl.remove(),delete this.floorPlan.helper.scaleBar,delete this.floorPlan,delete this.data}}const n_=100,o_=80;class a_{constructor({width:t,height:e,position:i=[0,0],html:s="",closeButton:r=!0,floorPlan:n}={}){this._floorPlan=n,this.position=i,this.html=s,this.closeButton=r,this._anchorPos=null;let o=t||n_;this.width=Math.max(100,o);let a=e||o_;this.height=Math.max(50,a),this._getPosition=()=>{this._anchorPos=this._floorPlan.getScreenPosition(this.position),this._updateInfoWindow()},this._getPosition(),this._createInfoWindow(),this._floorPlan.view.on("viewbox",this._getPosition,this),this._floorPlan.view.on("resize-canvas",this._getPosition,this)}_createInfoWindow(){const t=document.querySelector(`#${this._floorPlan.fpeId}.fpe`),e=t.querySelector("canvas");this.el||(this.el=document.createElement("div"),this.el.classList.add("fpe-info-window"),t.appendChild(this.el),this.el.addEventListener("wheel",(t=>{let i=new WheelEvent(t.type,t);e.dispatchEvent(i)}))),this._setContent(),this._updateInfoWindow()}_setContent(){let t=`<div class="fpe-info-window__content">${this.html}</div>`;this.closeButton&&(t+='<div class="fpe-info-window__close" @click="infoWindow.remove"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">\n <g fill="none" stroke="#000" stroke-width="1.2" stroke-miterlimit="10">\n <path d="M11.8 11.8l16.4 16.4M11.8 28.2l16.3-16.4" />\n </g>\n</svg></div>'),this.el.innerHTML=t;const e=this.el.querySelector(".fpe-info-window__close");e&&e.addEventListener("click",this.remove.bind(this))}_updateInfoWindow(){if(!this.el)return;const t=this._floorPlan.interaction.isPanning?"pointer-events: none;":"",e=this._anchorPos[0]-47,i=this._anchorPos[1]-this.height-15,s=1e3+2*this.position[1],r=this.height,n=this.width;this.el.setAttribute("style",`transform: translate(${e}px, ${i}px);${t} height:${r}px; width:${n}px; z-index:${s}`)}set({width:t,height:e,position:i,html:s,closeButton:r}){void 0!==i&&(this.position=i),void 0!==t&&(this.width=Math.max(100,t)),void 0!==e&&(this.height=Math.max(50,e)),void 0!==s&&(this.html=s),void 0!==r&&(this.closeButton=r),void 0===s&&void 0===r||this._setContent(),this._getPosition()}remove(){this._floorPlan.view.off("viewbox",this._getPosition),this._floorPlan.view.off("resize-canvas",this._getPosition),this.el.remove(),this._floorPlan=null}}class l_{constructor({position:t=[0,0],offset:e=[0,0],el:i,floorPlan:s}){if(this._updateHtmlMarker=()=>{this.el&&(this.isHidden=!(([t,e],i,s=0)=>i.min[0]-s<t&&i.max[0]+s>t&&i.min[1]-s<e&&i.max[1]+s>e)(this.position,this._floorPlan.view.viewbox,5),this.el.classList.toggle("fpe-marker--hidden",this.isHidden),this.isHidden||(this._anchorPos=this._floorPlan.getScreenPosition(this.position),this._updateHtmlMarkerStyle()))},!s)return;if(i instanceof HTMLElement==!1)return void nl.warn("no Element provided");this.el=i;const r=document.querySelector(`#${s.fpeId}.fpe`),n=r.querySelector("canvas");r.appendChild(this.el),this.el.classList.add("fpe-marker");const{width:o,height:a}=i.getBoundingClientRect();this.el.addEventListener("wheel",(t=>{let e=new WheelEvent(t.type,t);n.dispatchEvent(e)})),this.id=O(),this._floorPlan=s,this.position=t,this.size=[o,a],this.offset=e,this._updateHtmlMarker(),this._floorPlan.view.on("viewbox",this._updateHtmlMarker),this._floorPlan.on("drag-end",this._updateHtmlMarker),this._floorPlan.view.on("resize-canvas",this._updateHtmlMarker)}_updateHtmlMarkerStyle(){const t=this._floorPlan.interaction.isPanning,e=this.offset?this.offset:[0,0],i=this._anchorPos[0]-this.size[0]/2+e[0],s=this._anchorPos[1]-this.size[1]/2+e[1];this.el.style.pointerEvents=t?"none":"",this.el.style.transform=`translate(${i}px, ${s}px)`}set({position:t,offset:e}){void 0!==t&&(this.position=t),void 0!==e&&(this.offset=e),this._updateHtmlMarker()}remove(){this._floorPlan.view.off("viewbox",this._updateHtmlMarker),this._floorPlan.view.off("resize-canvas",this._updateHtmlMarker),this._floorPlan.off("drag-end",this._updateHtmlMarker),this.el.remove(),this._floorPlan=null}}var h_={grad:.9,turn:360,rad:360/(2*Math.PI)},u_=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},c_=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},d_=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},p_=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},f_=function(t){return{r:d_(t.r,0,255),g:d_(t.g,0,255),b:d_(t.b,0,255),a:d_(t.a)}},m_=function(t){return{r:c_(t.r),g:c_(t.g),b:c_(t.b),a:c_(t.a,3)}},g_=/^#([0-9a-f]{3,8})$/i,y_=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},v_=function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=Math.max(e,i,s),o=n-Math.min(e,i,s),a=o?n===e?(i-s)/o:n===i?2+(s-e)/o:4+(e-i)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},x_=function(t){var e=t.h,i=t.s,s=t.v,r=t.a;e=e/360*6,i/=100,s/=100;var n=Math.floor(e),o=s*(1-i),a=s*(1-(e-n)*i),l=s*(1-(1-e+n)*i),h=n%6;return{r:255*[s,a,o,o,l,s][h],g:255*[l,s,s,a,o,o][h],b:255*[o,o,l,s,s,a][h],a:r}},b_=function(t){return{h:p_(t.h),s:d_(t.s,0,100),l:d_(t.l,0,100),a:d_(t.a)}},__=function(t){return{h:c_(t.h),s:c_(t.s),l:c_(t.l),a:c_(t.a,3)}},w_=function(t){return x_((i=(e=t).s,{h:e.h,s:(i*=((s=e.l)<50?s:100-s)/100)>0?2*i/(s+i)*100:0,v:s+i,a:e.a}));var e,i,s},P_=function(t){return{h:(e=v_(t)).h,s:(r=(200-(i=e.s))*(s=e.v)/100)>0&&r<200?i*s/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,i,s,r},E_=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,T_=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,A_=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,I_=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,S_={string:[[function(t){var e=g_.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?c_(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?c_(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=A_.exec(t)||I_.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:f_({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=E_.exec(t)||T_.exec(t);if(!e)return null;var i,s,r=b_({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(h_[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return w_(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,s=t.b,r=t.a,n=void 0===r?1:r;return u_(e)&&u_(i)&&u_(s)?f_({r:Number(e),g:Number(i),b:Number(s),a:Number(n)}):null},"rgb"],[function(t){var e=t.h,i=t.s,s=t.l,r=t.a,n=void 0===r?1:r;if(!u_(e)||!u_(i)||!u_(s))return null;var o=b_({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return w_(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!u_(e)||!u_(i)||!u_(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:p_(o.h),s:d_(o.s,0,100),v:d_(o.v,0,100),a:d_(o.a)});return x_(a)},"hsv"]]},C_=function(t,e){for(var i=0;i<e.length;i++){var s=e[i][0](t);if(s)return[s,e[i][1]]}return[null,void 0]},M_=function(t,e){var i=P_(t);return{h:i.h,s:d_(i.s+100*e,0,100),l:i.l,a:i.a}},O_=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},N_=function(t,e){var i=P_(t);return{h:i.h,s:i.s,l:d_(i.l+100*e,0,100),a:i.a}},L_=function(){function t(t){this.parsed=function(t){return"string"==typeof t?C_(t.trim(),S_.string):"object"==typeof t&&null!==t?C_(t,S_.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return c_(O_(this.rgba),2)},t.prototype.isDark=function(){return O_(this.rgba)<.5},t.prototype.isLight=function(){return O_(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=m_(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?y_(c_(255*r)):"","#"+y_(e)+y_(i)+y_(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return m_(this.rgba)},t.prototype.toRgbString=function(){return e=(t=m_(this.rgba)).r,i=t.g,s=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+s+", "+r+")":"rgb("+e+", "+i+", "+s+")";var t,e,i,s,r},t.prototype.toHsl=function(){return __(P_(this.rgba))},t.prototype.toHslString=function(){return e=(t=__(P_(this.rgba))).h,i=t.s,s=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+s+"%, "+r+")":"hsl("+e+", "+i+"%, "+s+"%)";var t,e,i,s,r},t.prototype.toHsv=function(){return t=v_(this.rgba),{h:c_(t.h),s:c_(t.s),v:c_(t.v),a:c_(t.a,3)};var t},t.prototype.invert=function(){return R_({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),R_(M_(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),R_(M_(this.rgba,-t))},t.prototype.grayscale=function(){return R_(M_(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),R_(N_(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),R_(N_(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?R_({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):c_(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=P_(this.rgba);return"number"==typeof t?R_({h:t,s:e.s,l:e.l,a:e.a}):c_(e.h)},t.prototype.isEqual=function(t){return this.toHex()===R_(t).toHex()},t}(),R_=function(t){return t instanceof L_?t:new L_(t)},k_=[];!function(t){t.forEach((function(t){k_.indexOf(t)<0&&(t(L_,S_),k_.push(t))}))}([function(t,e){var i={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},s={};for(var r in i)s[i[r]]=r;var n={};t.prototype.toName=function(e){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var r,o,a=s[this.toHex()];if(a)return a;if(null==e?void 0:e.closest){var l=this.toRgb(),h=1/0,u="black";if(!n.length)for(var c in i)n[c]=new t(i[c]).toRgb();for(var d in i){var p=(r=l,o=n[d],Math.pow(r.r-o.r,2)+Math.pow(r.g-o.g,2)+Math.pow(r.b-o.b,2));p<h&&(h=p,u=d)}return u}},e.string.push([function(e){var s=e.toLowerCase(),r="transparent"===s?"#0000":i[s];return r?new t(r).toRgb():null},"name"])}]);const B_=class t{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(e){if(e instanceof t)this._value=this.cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(null===e)throw new Error("Cannot set PIXI.Color#value to null");(null===this._value||!this.isSourceEqual(this._value,e))&&(this.normalize(e),this._value=this.cloneSource(e))}}get value(){return this._value}cloneSource(t){return"string"==typeof t||"number"==typeof t||t instanceof Number||null===t?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):"object"==typeof t&&null!==t?{...t}:t}isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if("number"===i||"string"===i||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length===e.length&&t.every(((t,i)=>t===e[i]));if(null!==t&&null!==e){const i=Object.keys(t),s=Object.keys(e);return i.length===s.length&&i.every((i=>t[i]===e[i]))}return t===e}toRgba(){const[t,e,i,s]=this._components;return{r:t,g:e,b:i,a:s}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,s]=this._components;return(t=t??[])[0]=Math.round(255*e),t[1]=Math.round(255*i),t[2]=Math.round(255*s),t}toRgbArray(t){t=t??[];const[e,i,s]=this._components;return t[0]=e,t[1]=i,t[2]=s,t}toNumber(){return this._int}toLittleEndianNumber(){const t=this._int;return(t>>16)+(65280&t)+((255&t)<<16)}multiply(e){const[i,s,r,n]=t.temp.setValue(e)._components;return this._components[0]*=i,this._components[1]*=s,this._components[2]*=r,this._components[3]*=n,this.refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this.refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(1===t)return(255<<24)+this._int;if(0===t)return e?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,r=255&this._int;return e&&(i=i*t+.5|0,s=s*t+.5|0,r=r*t+.5|0),(255*t<<24)+(i<<16)+(s<<8)+r}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const t=Math.round(255*this._components[3]).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(t){return this._components[3]=this._clamp(t),this}round(t){const[e,i,s]=this._components;return this._components[0]=Math.round(e*t)/t,this._components[1]=Math.round(i*t)/t,this._components[2]=Math.round(s*t)/t,this.refreshInt(),this._value=null,this}toArray(t){t=t??[];const[e,i,s,r]=this._components;return t[0]=e,t[1]=i,t[2]=s,t[3]=r,t}normalize(e){let i,s,r,n;if(("number"==typeof e||e instanceof Number)&&e>=0&&e<=16777215){i=(e>>16&255)/255,s=(e>>8&255)/255,r=(255&e)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[i,s,r,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[i,s,r,n=255]=e,i/=255,s/=255,r/=255,n/=255;else if("string"==typeof e||"object"==typeof e){if("string"==typeof e){const i=t.HEX_PATTERN.exec(e);i&&(e=`#${i[2]}`)}const o=R_(e);o.isValid()&&(({r:i,g:s,b:r,a:n}=o.rgba),i/=255,s/=255,r/=255)}if(void 0===i)throw new Error(`Unable to convert color ${e}`);this._components[0]=i,this._components[1]=s,this._components[2]=r,this._components[3]=n,this.refreshInt()}refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(255*t<<16)+(255*e<<8)+(255*i|0)}_clamp(t,e=0,i=1){return"number"==typeof t?Math.min(Math.max(t,e),i):(t.forEach(((s,r)=>{t[r]=Math.min(Math.max(s,e),i)})),t)}};B_.shared=new B_,B_.temp=new B_,B_.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let F_=B_;class D_{constructor({position:t,color:e,size:i,floorPlan:s}){this.position=t,this.color=e,this.size=i,this.floorPlan=s,this.id=O(),this.draw()}draw(){const t=this.size/4e3;this.layer=this.floorPlan.addLayer({id:"fpe-markers"});let e=[{type:"curve:composite",segments:[{type:"curve:arc",position:[0,-27.8],radius:12.4,startAngle:-25,endAngle:205},{type:"curve:line",end:[0,0],start:[-11.2,-22.5]}],style:{fill:new F_(this.color).toNumber(),stroke:6710886,strokeWidth:.5/t}},{type:"curve:circle",position:[0,-28],radius:5,style:{fill:1,fillOpacity:.2}}];this.graphic=this.layer.addGraphic({shapes:e,position:this.position,id:"marker_"+this.id,scale:t,scaleOnZoom:!0})}remove(){this.off("click"),this.layer.deleteGraphic(this.graphic),delete this.floorPlan,0===this.layer.graphics.size&&this.layer.destroy()}on(t="click",e,i){this.graphic.gfx.eventMode="static",this.graphic.gfx.on(t,e,i)}off(t="click",e){this.graphic.gfx.off(t,e)}set(t){let e=["position","color","size"];Object.keys(t).forEach((i=>{e.includes(i)&&(this[i]=t[i])})),this.draw()}}const U_=t=>{if(null==t?void 0:t.children)for(var e=t.children.length-1;e>=0;e--)t.children[e].destroy({children:!0}),t.removeChild(t.children[e])};function G_(t,e,i){const s=new _v(t);return s.x=0,s.y=0,s.anchor.x=.5,s.anchor.y=.5,s.rotation=0,e&&(s.width=e),i&&(s.height=i),s}function X_(t=[]){return(t=t.sort(((t,e)=>Q(t)>Q(e)?-1:1)))&&t.length?[{type:"curve:polygonWithHoles",polygons:t}]:[]}function W_(t,e,i=!1,s=16,r=8){let n=[];for(let m=0;m<e.length-1;m+=2)n.push({x:e[m],y:e[m+1]});let o,a,l,h=0,u=0,c=i?1:0;for(o=0;o<n.length-c;o++){a=n[o],l=o==n.length-1?n[0]:n[o+1];let e=l.x-a.x,i=l.y-a.y;var d=Math.sqrt(e*e+i*i),p={x:e/d,y:i/d},f=0;for(t.moveTo(a.x+u*p.x,a.y+u*p.y);f<=d;)f+=u,(f+=h>0?h:s)>d?(h=f-d,f=d):h=0,t.lineTo(a.x+f*p.x,a.y+f*p.y),(f+=r)>d&&0==h?u=f-d:(u=0,t.moveTo(a.x+f*p.x,a.y+f*p.y))}}function H_(t){return t.stroke?{alpha:t.strokeOpacity||1,color:Nl(t.stroke),native:"native"===t.strokeWidth,width:"number"==typeof t.strokeWidth?t.strokeWidth:1,alignment:"number"==typeof t.alignment?t.alignment:.5}:{}}function Y_({shape:t,settings:e,gfx:i,style:s={}}){var r,n,o;if(!i||!i.lineStyle)return;let a={...s,...t.style||{}};const l=Zb,h=!["curve:line","curve:polyline","curve:arc"].includes(t.type)&&!!a.fill;if("string"==typeof(null==a?void 0:a.fill)&&a.fill.startsWith("url("))!function({shape:t,settings:e,style:i,gfx:s}){var r;if(Em.defaultOptions.scaleMode=Zl.NEAREST,"string"!=typeof i.fill||"curve:rectangle"!==t.type&&"curve:polygon"!==t.type)return;let n,o,a=[0,0],l=null==(r=i.fill.match(/url\((.*?)\)/))?void 0:r[1];if(!l||!l.startsWith("data:image")&&!l.startsWith("https://"))return;let h=_v.from(l);if("curve:polygon"===t.type){let{min:i,max:r}=Y([t.points]);n=r[0]-i[0],o=r[1]-i[1],a=i;let l=new Vv;Y_({shape:{type:"curve:polygon",points:t.points,style:{fill:16777215}},settings:e,gfx:l}),s.addChild(l),h.mask=l}else n=t.dimensions[0],o=t.dimensions[1],a=t.position;h.width=n*Zb,h.height=o*Zb,h.x=a[0]*Zb,h.y=a[1]*Zb,h.anchor.set(0),s.addChild(h)}({shape:t,settings:e,style:a,gfx:i});else{if(h&&a.fill&&i.beginFill(Nl(a.fill),a.fillOpacity),i.lineStyle(H_(a)),"curve:rectangle"===t.type){let{position:e,dimensions:s}=t;i.drawRect(e[0]*l,e[1]*l,s[0]*l,s[1]*l)}else if("curve:circle"===t.type||"curve:composite"===t.type){$_(Ul(t).points,[],a,l,i,h)}else if("curve:arc"===t.type||"curve:quadraticBezier"===t.type){Gl(t).points.forEach(((t,e)=>{0===e?i.moveTo(t[0]*l,t[1]*l):i.lineTo(t[0]*l,t[1]*l)}))}else if("curve:polygon"===t.type)$_(t.points,[],a,l,i,h);else if("curve:polygonWithHoles"===t.type){let{polygons:e}=t;$_(e[0],e.slice(1),a,l,i,h)}else if("curve:line"===t.type){let{start:e=[],end:s=[]}=t;i.moveTo(e[0]*l,e[1]*l),i.lineTo(s[0]*l,s[1]*l)}else if("curve:polyline"===t.type){let{points:e}=t;a.dash?W_(i,e.flat().map((t=>t*l)),!0):e.forEach(((t,e)=>{0===e?i.moveTo(t[0]*l,t[1]*l):i.lineTo(t[0]*l,t[1]*l)}))}else if("group"===t.type){let{position:r=[0,0],rotation:n=0}=t,o=new Vv;o.x=r[0]*l,o.y=r[1]*l,o.rotation=-Math.PI/180*n,t.children.forEach((t=>Y_({shape:t,settings:e,gfx:o,style:s}))),i.addChild(o)}else if("text"===t.type){let s=(null==(r=t.style)?void 0:r.fill)?Nl(t.style.fill):0,a=(null==(n=t.style)?void 0:n.stroke)?Nl(t.style.stroke):16777215,{position:h=[0,0],rotation:u=0,text:c,alignH:d="center",alignV:p="center",fontSize:f=16}=t;const m=new ex({fontFamily:(null==(o=null==e?void 0:e.theme)?void 0:o.fontFamily)||il.theme.fontFamily,fontSize:f,fill:s,align:d,stroke:a,strokeThickness:3});let g=new ox(c,m);g.x=h[0]*l,g.y=h[1]*l,g.rotation=-Math.PI/180*u,g.anchor.x=.5,g.anchor.y="center"===p?.5:"bottom"===p?1:0,i.addChild(g)}h&&i.endFill()}}function $_(t=[],e=[],i={},s=100,r,n){if(!t||!Array.isArray(t)||!t.length)return r;r.lineStyle(H_(i));let o=t.flat().map((t=>t*s));if(i.dash?(W_(r,o),n&&(r.lineStyle(0),r.drawPolygon(o))):r.drawPolygon(o),e.length){n&&r.beginHole();for(const t of e){let e=t.flat().map((t=>t*s));r.drawPolygon(e)}n&&r.endHole()}return r}function j_(t,e){e.on("product-load-texture",(({resourceId:i})=>{!function(t,e){let i=t.resources.productJson.get(e);if(!i.boundingBox)return void nl.warn("product boundingBox missing");const{boundingBox:s}=i,r=xl(s);let n={x:s.min[0],y:s.min[2]},o={x:Math.abs(s.min[0]/r[0]),y:Math.abs(s.min[2]/r[2])},a={x:s.max[0]-r[0]/2,y:s.max[2]-r[2]/2},l=t.resources.texture.get(e);l.offset=a,l.anchor=o,l.position=n}(e,i),z_({view:t,resourceId:i,loader:e})}));const i=new Vv;i.lineStyle({native:!0,color:3355443}),i.drawCircle(0,0,1),t._dummyTexture=t._renderer.generateTexture(i)}function z_({resourceId:t,loader:e,view:i}){if(!e.resources.texture.has(t))return Promise.reject(`no texture data to load ${t}`);const s=e.resources.texture.get(t);if(s.texture)return Promise.resolve();let{textureUrl:r}=s;return tm(),function(t){return new Promise(((e,i)=>{var s=new Image;s.addEventListener("load",(()=>{URL.revokeObjectURL(s.src),e(new zg(new Em(s)))})),s.addEventListener("error",(()=>{URL.revokeObjectURL(s.src),i("image loading failed: "+t)}));const r=t.includes("/storage/get/"),n=t.startsWith("https://")?t:rl+t;s.src=n,s.crossOrigin=r?"use-credentials":"anonymous"}))}(r).then((r=>{s.imageData=r,function(t,e,i){const s=null==e?void 0:e._renderer,r=i.resources.texture.get(t),n=r.error;if(tm(),!r.texture){const e=i.resources.productJson.get(t),o=new vv;let a,l;n||(a=new _v(r.imageData),a=q_(a,r.applyFilter),o.addChild(a));const h=i.resources.productContour.get(t),u=(null==h?void 0:h.length)?[{type:"curve:polygon",points:h[0],holes:h.slice(1)}]:[];if(u.length&&(null==e?void 0:e.boundingBox)){let t;n?t={strokeWidth:.5,stroke:1,fill:16316664}:(t=kl({settings:{theme:{showAssetTextures:!0,elements:{}}},elementType:"element:asset"}),t.stroke=el.stone),l=V_(u,t);const i=new _v(l);i.anchor.x=r.anchor.x,i.anchor.y=r.anchor.y;const s=xl(e.boundingBox);if(!n){let t=a.width/s[0],e=(null==r?void 0:r.offset)||{x:0,y:0};i.scale.x=a.width/i.width,i.scale.y=a.height/i.height,i.x=a.width/2-e.x*t,i.y=a.height/2-e.y*t}o.addChild(i)}r.texture=s.generateTexture(o,{scaleMode:Zl.LINEAR,resolution:1.5}),o.destroy(!0),l&&l.destroy(!0)}i.emit("resource-loaded",{resourceId:t})}(t,i,e)})).catch((i=>{nl.warn(i),s.error={message:i},e.emit("resource-loaded",{resourceId:t})}))}function V_(t,e){let i,s=new Vv;for(const r of t)Y_({shape:r,gfx:s,style:e});return i=s.generateCanvasTexture(Zl.LINEAR,2),s.destroy(),i}function q_(t,e){switch(e){case ml.Default:{const e=new ax;e.matrix=[.7,0,0,0,.25,0,.7,0,0,.25,0,0,.7,0,.25,0,0,0,1,0],t.filters=[e];break}case ml.Grayscale:{const e=new ax;e.blackAndWhite(!0),t.filters=[e];break}case ml.None:}return t}function J_(t,e,i,s){var r,n,o,a;!function(t,e){var i;const s=null==(i=t.product)?void 0:i.id,{loader:r}=e,n=r.resources.nodes.get(s);if(s&&!(null==n?void 0:n.has(t)))ol(e.loader,t).catch((t=>nl.warn(t)))}(t,i);const{view:l,settings:h,loader:u}=i,{theme:c,showCeilingLamps:d}=h,p=Zb;let f,m,g=[];const y=null==(r=t.product)?void 0:r.id,v=u.resources.productJson.get(y)||{subCategories:[]},x="product:component"===(null==(n=t.product)?void 0:n.type),b=u.resources.productContour.get(y),_=u.resources.texture.get(y),w=X_(b);if((null==v?void 0:v.subCategories.includes("ceilingLight"))&&!d)return[];let P=0;if(x)for(const A of t.elements){if("element:asset"!==A.type||!A.product)continue;const t=Wl(A.product.attributes);t>P&&(P=t)}else P=Wl(v);const E=Il(t.type,P);e.zIndex=E||0;let T=kl({element:t,settings:h,style:s});if(b||x||!v.boundingBox)if(c.showAssetTextures&&!(null==_?void 0:_.error)||!b)if(c.showAssetTextures&&(null==_?void 0:_.texture)){const t=xl(v.boundingBox);if(f=G_(_.texture,t[0]*p,t[2]*p),f.anchor.x=_.anchor.x,f.anchor.y=_.anchor.y,f.zIndex=1,(null==(o=v.categories)?void 0:o.includes("tables"))||(null==(a=v.categories)?void 0:a.includes("seating"))){const t=new Ym(w[0].polygons[0].flatMap((t=>[t[0]*p/f.scale.x,t[1]*p/f.scale.y])));f.hitArea=t,f.interactive=!0}"selected"===s?(_.contourTexture||(_.contourTexture=V_(w,{stroke:T.stroke,strokeWidth:T.strokeWidth||1})),m=new _v(_.contourTexture),m.anchor.x=_.anchor.x,m.anchor.y=_.anchor.y,m.zIndex=5,T.fill&&(f.tint=Nl(T.fill))):s&&(m=new Vv,g=w||[],m.zIndex=5)}else f=new _v(l._dummyTexture);else{const e={...c,showAssetTextures:!1};T=kl({element:t,settings:{...h,theme:e},style:s}),g=w,f=new Vv}else{g=X_(function(t){const e=t;if(e){let t;return t=[[e.min[0],e.min[2]],[e.min[0],e.max[2]],[e.max[0],e.max[2]],[e.max[0],e.min[2]]],[t]}return[]}(v.boundingBox)),f=new Vv}m&&(m.eventMode="none");for(const A of g)Y_({shape:A,settings:h,gfx:m||f,style:T});return[f,m]}function K_(t,e,i,s,r,n){let o,a,l=[];const{view:h,settings:u}=i;if("element:asset"!==t.type||t.isComponentInstance)if("annotation:floorPlanImage"===t.type){let s=function(t,e,i){var s,r;const{view:n,settings:o,loader:a}=i,l=Zb;let h,u;e.x=t.position[0]*l,e.y=t.position[2]*l,e.rotation=-Math.PI/180*t.rotation||0;const{uri:c,length:d,width:p}=t.parameters,f=t.id,m=(null==(r=null==(s=o.theme.elements)?void 0:s.floorPlan)?void 0:r.grayscale)?ml.Grayscale:ml.None,g=a.resources.texture.get(f);return(null==g?void 0:g.texture)?(h=G_(g.texture,d*l,p*l),h=q_(h,m),u=new Vv,h.zIndex=1,u.zIndex=5):(a.resources.nodes.set(f,new Set([t])),a.resources.texture.set(f,{textureUrl:c,applyFilter:m}),z_({loader:a,view:n,resourceId:f}),h=new Vv),[h,u]}(t,e,i);o=s[0],a=s[1]}else{if("element:wall"===t.type)l=function(t){var e;let{valid:i,points:s}=t.geometryProfile,r=[];if(null==(e=t.layout)?void 0:e.debugIds){for(let t of s)r.push({type:"curve:circle",radius:.02,position:t,style:{stroke:0,fill:i?32768:16711680,fillOpacity:.2}});let e=kl({element:t});i||(e.stroke=16711680),r.push({type:"curve:polygon",points:s,style:e})}else r.push({type:"curve:polygon",points:s});return r}(t);else if("element:opening"===t.type)l=bl(t);else if("spatialGraph:edge"===t.type)l=function(t,e={}){let[i,s]=t.vertices,r="selected"===e,n=[{type:"curve:line",start:i.position,end:s.position}];if(t.layout.debugIds){let e,r=Qa(t.id)?t.id.substring(0,4):t.id;t.element&&(e=Qa(t.element.id)?t.element.id.substring(0,4):t.element.id);let o=t.element?`${r} (${e})`:r;n.push({type:"text",position:ri(i.position,pi(fi(s.position,i.position),.5)),text:o,fontSize:10})}if(null===t.element||"element:spaceDivider"===t.element.type){let t=ci(di(fi(s.position,i.position))),e=.02,o=ri(i.position,pi(t,-e)),a=ri(i.position,pi(t,e)),l=ri(s.position,pi(t,e)),h=ri(s.position,pi(t,-e));n.unshift({type:"curve:polygon",points:[o,a,l,h],style:{stroke:null,fill:r?el.blue_ribbon:el.whisper,fillOpacity:.1}})}return n}(t);else if("layout:space"===t.type){const e=t.geometry.polygons;e.length>0&&l.push({type:"curve:polygonWithHoles",polygons:e})}else if("geometries"in t&&t.geometries.length){const{shapes:i,maxY:s}=function(t){const e=Ka(t).sort(((t,e)=>t.boundingBox.max[1]<e.boundingBox.max[1]?-1:1));"element:door"!==t.type&&"element:window"!==t.type||e.pop();let i=e.length?e[e.length-1].boundingBox.max[1]:0,s=[];for(let r of e)for(let t=0;t<r.outlines.length;t++)s.push({type:"curve:polygonWithHoles",polygons:[r.outlines[t],...r.holes[t]||[]]});return{shapes:s,maxY:i}}(t);l=i,e.zIndex=e.zIndex+s}let i=Tl(t);l.push(...i),o=new Vv;const r=kl({element:t,settings:u,style:s});for(const t of l)Y_({shape:t,settings:u,gfx:o,style:r})}else{let r=J_(t,e,i,s);o=r[0],a=r[1]}if("getTransform"in t){const i=t.parent&&t.parent.id!==(null==n?void 0:n.name)?t.getWorldTransform():t.getTransform();e.x=i.position[0]*Zb,e.y=i.position[2]*Zb,e.rotation=-Math.PI/180*i.rotation||0}if(!r&&o){h.gfxNodes[t.id]=e,o.eventMode="static";let i=t.id;"element"in t&&t.element&&(i=t.element.id),o._nodeId=i}o&&e.addChild(o),a&&e.addChild(a)}function Z_(t,e,{ctx:i,style:s,container:r,preview:n}){var o,a,l;const{view:h,settings:u}=e;if(!(null==t?void 0:t.spaceGraph))return;let c;n||(s?h.styleCache[t.id]=s:!1===s?delete h.styleCache[t.id]:s=h.styleCache[t.id]),r?(c=r,U_(c)):c=new vv;const d=u.hideElements.includes(t.type)||"spatialGraph:edge"===t.type&&!u.showSpaceDividers||"element:spaceDivider"===t.type||"annotation:floorPlanImage"===t.type&&!u.showFloorPlan||"element:asset"===t.type&&"product"in t&&(null==(l=null==(a=null==(o=t.product)?void 0:o.attributes)?void 0:a.subCategories)?void 0:l.includes("ceilingLight"))&&!u.showCeilingLamps||"space"in t||("element:window"===t.type||"element:door"===t.type)&&!t.parent||e.computed.wallContours.length&&["element:wall","element:boundaryWall","element:column","spatialGraph:edge"].includes(t.type),p=Il(t.type);if(c.zIndex=p||0,c.name=t.id,d||K_(t,c,e,s,n,i),t&&"elements"in t){t.elements.length&&(c.sortableChildren=!0);for(const i of t.elements)Z_(i,e,{ctx:c,style:s,preview:n})}r||i.addChild(c),h.viewportNeedsUpdate=!0}function Q_(t,e){const i=e.getChildByName(t);null==i||i.destroy(!0)}function tw(t,e,i,s){var r;if(Q_(t.id,e),s.hideElements.includes("roomStamp"))return;const{text:n,textOutline:o=!0}=(null==(r=s.theme.elements)?void 0:r.roomStamp)||{},a=s.theme.background.color,l="transparent"!==a?a:"#eee",h=n?(u=n.map((t=>t/255)),"#"+((255*u[0]<<16)+(255*u[1]<<8)+(255*u[2]|0)).toString(16).padStart(6,"0")):"#333333";var u;const c=new ex({fontFamily:s.theme.fontFamily||il.theme.fontFamily,fontSize:16,align:"center",fill:h,stroke:l,strokeThickness:o?3:0});let d=t.geometry.polygons;if(0===d.length)return;let p=Ai(d),f=function(t,e){var i,s;let r=t.getArea(),n=t.attributes.usage;if("void"===Al(n))return[];let{roomStampDisplay:o}=(null==(i=e.theme.elements)?void 0:i.roomStamp)||{};const a=e.spaceLabelMapping||{};let l,h;void 0!==a[n]&&(l=a[n]),void 0!==a[t.id]&&(l=a[t.id]),h="area"===e.units.roomDimensions?m(r,e.units.system,e.units.areaDecimals):"";let u="";u||"undefined"===n||(u=(n||"").replace(/([A-Z])/g,(t=>` ${t}`)).replace(/^./,(t=>t.toUpperCase())).trim()),void 0!==l&&("string"!=typeof l?nl.warn("space label mapping has to be a string"):l.length>50?nl.warn("space label mapping has to be less than 50 characters"):u=l),o||(o=[],!1!==(null==(s=e.theme.elements)?void 0:s.roomStamp)&&(t.layout.debugIds?o.push("id"):o.push("usage","area")));const c=[];return o.forEach((e=>{switch(e){case"id":let i=Qa(t.id)?t.id.substring(0,4):t.id;c.push(i);break;case"name":t.name&&c.push(t.name);break;case"customId":t.customId&&c.push(t.customId);break;case"usage":c.push(u);break;case"area":c.push(h);break;default:Array.isArray(e)&&"customAttribute"===e[0]&&t.customAttributes[e[1]]&&c.push(String(t.customAttributes[e[1]]))}})),c}(t,s),g=f.join("\n");const y=new ox(g,c);y.x=p[0]*Zb,y.y=p[1]*Zb,y.anchor.x=.5,y.anchor.y=.5,ew(y,i,t),y.name=t.id,y.eventMode="none",e.addChild(y)}function ew(t,e,i){let s=Math.min(1/e,2);t.scale.x=s,t.scale.y=s,t.visible=i.getArea()>1.5*s}function iw(t="linear"){return hx[t]}function sw({bb:t,animate:e=!1,view:i}){const s=i._viewport;if(!s)throw new Error("no viewport");return i.viewportPaused&&i.startAnimationLoop(),new Promise((r=>{var n;Number.isFinite(null==(n=t.min)?void 0:n[0])||r(!1);const{min:o,max:a}=t;let l=o[0],h=o[1];let u=a[0]-l,c=a[1]-h;l*=Zb,h*=Zb,u*=Zb,c*=Zb;let d=0;"number"==typeof e&&Number.isFinite(e)?d=e:!0===e&&(d=500);let p={x:l+u/2,y:h+c/2,width:u,height:c};if(d){let t={x:s.center.x,y:s.center.y,width:s.worldScreenWidth,height:s.worldScreenHeight},e={x:t.x-p.x,y:t.y-p.y,width:t.width-p.width,height:t.height-p.height};i._zoomTarget={delta:e,start:t,target:p,time:0,duration:d,destroy:()=>{i.ticker.remove("animateView"),delete i._zoomTarget,r(!0)},ease:iw("easeInOutQuad"),updateViewport:nw.bind(i)},i.ticker.add("animateView",rw,i)}else s.fit(!1,p.width,p.height).moveCenter(p.x,p.y),nw.bind(i)({type:"animation"}),i.viewportNeedsUpdate=!0,r(!0)}))}function rw(t){let e=this._zoomTarget,i=!1;e.time+=t;let s=e.ease(e.time,0,1,e.duration),r={x:e.start.x-e.delta.x*s,y:e.start.y-e.delta.y*s,width:e.start.width-e.delta.width*s,height:e.start.height-e.delta.height*s};e.time>e.duration&&(r=e.target,i=!0),this._viewport.fit(!1,r.width,r.height).moveCenter(r.x,r.y),this.viewportNeedsUpdate=!0,e.updateViewport({type:"animation"});const n=0!==this._viewport.input.count();(i||n)&&e.destroy()}function nw(t){this.viewportNeedsUpdate=!0,this.viewportPaused&&this.startAnimationLoop();const e=this._viewport;"animation"!==t.type&&this._zoomTarget&&this._zoomTarget.destroy();const i=Zb,s=e.scale._x,r=e.left,n=e.top,o=e.worldScreenWidth,a=e.worldScreenHeight;this.viewbox={min:[r/i,n/i],max:[(r+o)/i,(n+a)/i]},this.client=[e.screenWidth,e.screenHeight];const l=this.zoom!==s;this.zoom=s;const h={sourceEvent:{type:t.type},viewbox:this.viewbox,zoom:this.zoom};l?this.emit("zoom",h):this.emit("pan",h),this.emit("viewbox",h)}function ow({position:t,nodeId:e}){aw(this.interaction,{cursor:t,cursorTarget:e&&this.layout&&(this.layout.elementsById[e]||this.layout.spacesById[e])})}function aw(t,e){for(const i in e)t[i]=e[i],"cursorAction"===i&&lw(e[i])}function lw(t){let e="";switch(t){case"split-wall":e="var(--fpe-split-cursor) 16 16, pointer";break;case"duplicate":e="var(--fpe-duplicate-cursor) 16 16, pointer";break;case"move":e="move";break;default:e="default"}document.body.style.cursor=e}function hw(t){var e,i,s,r;if(2===(null==(i=null==(e=null==t?void 0:t.data)?void 0:e.originalEvent)?void 0:i.button))return;if(!this||!this.view)throw new Error("Viewport context is missing");let n=this.interaction._dragStart||{x:0,y:0},o=t.data.global||{x:0,y:0},a=Math.abs(o.x-n.x),l=Math.abs(o.y-n.y);if(!(a<5&&l<5))return;let h,u=(new Date).getTime();if(this.interaction.lastClick){let t=u-this.interaction.lastClick.time,e=this.interaction.lastClick.position&&Math.max(Math.abs(o.x-this.interaction.lastClick.position.x),Math.abs(o.y-this.interaction.lastClick.position.y));h=t<400&&e<10}this.interaction.lastClick={time:u,position:{...o}};const c=h?"dblclick":"click",d=null==(s=t.target)?void 0:s._nodeId,{x:p,y:f}=(null==(r=t.data)?void 0:r.global)||{},m=this.getPlanPosition([p,f]);aw(this.interaction,{cursor:[m[0],m[1]]});let g={sourceEvent:t,nodeId:d,position:m,isDoubleClick:!!h};this.emit(c,g)}function uw(t){var e;const{x:i,y:s}=t.data.global;this.view.windowPos=[i,s];const r=this.getPlanPosition(this.view.windowPos);this.interaction.lastSceneClick=r;const n=null==(e=t.target)?void 0:e._nodeId;this.emit("context-menu",{sourceEvent:t,nodeId:n,position:r})}function cw(t){t.drag().pinch({percent:4}).wheel()}function dw(t){const{settings:e,view:i}=t;e.panZoom&&cw(i._viewport),i._viewport.on("pointerdown",pw,t).on("pointerup",fw,t).on("pointerup",hw,t).on("rightup",uw,t).on("pointerupoutside",fw,t).on("pointermove",mw,t).on("moved",nw,i).on("zoomed",nw,i),gw(t),(t=>{const{view:e,interaction:i}=t,s=(s,r)=>{e.viewportInFocus&&("Alt"===s.key&&"keyup"===r&&i.preventFocusoutOnAltKeyup&&s.preventDefault(),i.shiftKey=s.shiftKey,i.ctrlKey=s.ctrlKey,i.altKey=s.altKey,i.metaKey=s.metaKey,t.emit(r,{key:s.key,lowerCaseKey:s.key&&s.key.toLowerCase(),sourceEvent:s}))};document.addEventListener("keydown",(t=>s(t,"key"))),document.addEventListener("keyup",(t=>s(t,"keyup")))})(t),t.on("mousemove",ow,t)}function pw(t){this.interaction._dragStart={x:t.data.global.x,y:t.data.global.y};const e=t.data.getLocalPosition(this.view._viewport);this.emit("drag-start",{position:this.interaction.cursor,sourceEvent:t,screenPos:[e.x,e.y]})}function fw(t){this.view.resume("drag");const e=t.data.getLocalPosition(this.view._viewport);this.emit("drag-end",{position:this.interaction.cursor,sourceEvent:t,screenPos:[e.x,e.y]}),this.interaction.isDragging=!1,this.interaction.dragOffset=null}function mw(t){var e;const{srcElement:i}=(null==(e=null==t?void 0:t.data)?void 0:e.originalEvent)||{};if(!i)return;if(!(i===this.view._renderer.view))return;const s=t.data.getLocalPosition(this.view._viewport);let r=[s.x/Zb,s.y/Zb];const n=t.target&&t.target._nodeId;if(this.interaction.cursor=r,this.interaction.isDragging){const e=[s.x,s.y];this.emit("drag-move",{position:this.interaction.cursor,screenPos:e,sourceEvent:t})}this.emit("mousemove",{sourceEvent:t,nodeId:n,position:r})}const gw=t=>{const e=document.querySelector(`#${t.fpeId} .fpe__plan`);e&&(e.addEventListener("mouseleave",(()=>t.view.emit("focus",!1,t.view))),e.addEventListener("mouseenter",(()=>t.view.emit("focus",!0,t.view))),document.addEventListener("visibilitychange",(()=>t.view.emit("focus","visible"===document.visibilityState,t.view))),e.addEventListener("contextmenu",(function(t){return t.preventDefault(),!1}),!1))};function yw({floorPlan:t,update:e=!1}){const{layout:i,view:s,settings:r}=t,{_renderer:n,_viewport:o}=s;let a=r.theme.background.color;4===a.length&&(a=a[0]+a[1]+a[1]+a[2]+a[2]+a[3]+a[3]),n.background.color=new F_(a).toNumber();const l=s.gfxLayers.scene;U_(l);let h={ctx:l};e||(s.styleCache={});for(let u of i.spaces)Z_(u,t,h);for(let u of i.elements)Z_(u,t,h);for(let u of i.annotations)Z_(u,t,h);for(let u of i.spatialGraph.edges)Z_(u,t,h);t.computed.wallContours.length&&function(t,e){const{ctx:i,style:s}=e,{wallContours:r}=t.computed,n="wallContours",o=r.map((t=>({type:"curve:polygonWithHoles",polygons:t})));let a=i.getChildByName(n);a?U_(a):(a=new vv,a.name=n);const l=Il("element:wall");a.zIndex=l||0;const h=kl({style:s,settings:t.settings,elementType:"element:wall"}),u=new Vv;for(const c of o)Y_({shape:c,gfx:u,style:h});a.addChild(u),i.addChild(a)}(t,h),vw(t,!0),s.emit("scene-rendered",{update:e}),s.viewportNeedsUpdate=!0,e&&(r.panZoom?cw(o):function(t){t.plugins.remove("wheel"),t.plugins.remove("pinch"),t.plugins.remove("drag")}(o)),s.viewportPaused&&s.startAnimationLoop()}function vw(t,e=!1){const{view:i,layout:s,settings:r}=t,n=t.addLayer({id:"fpe-room-stamp",baseLayer:"annotation"});e?(U_(n.container),s.spaces.forEach((t=>tw(t,n.container,i.zoom,r)))):n.container.children.forEach((t=>{let e=s.spaces.find((e=>e.id===t.name));ew(t,i.zoom,e)}))}function xw(t){const{shapeLayers:e}=t.settings;for(const i in e){const s=e[i];t.addLayer({id:i}).addGraphic({shapes:s})}}dm.add(Lg),dm.add(Ax),dm.add(Xx),dm.add(sb),dm.add(nb);class bw extends Hb{}const _w=(t,e,i)=>{const s=t.getChildByName(e);if(s)return U_(s),s;{const s=new vv;return s.sortableChildren=!0,s.zIndex=i,s.name=e,t.addChild(s),s}},ww={top:0,left:0,center:.5,right:1,bottom:1};class Pw{constructor(){this.methods={},this.add=(t,e,i)=>{this.methods[t]={fn:e,ctx:i}},this.remove=t=>{delete this.methods[t]}}}class Ew extends e_{constructor(t,e,i){var s;super(),this.windowPos=[0,0],this.zoom=1,this.client=[0,0],this.layers=new Map,this.viewbox={min:[0,0],max:[0,0]},this.styleCache={},this.viewportNeedsUpdate=!1,this.viewportPaused=!1,this.viewportInFocus=!1,this.wallNodesToUpdate=[],this.wallNodeUpdateInProgress=!1,this.gfxNodes={},this._canvasMargin={x:0,y:0},this.ticker=new Pw,this._oldTime=Date.now(),this.parentEl=i;const r=this.parentEl.querySelector(".fpe__canvas");let n=this.parentEl.clientWidth,o=this.parentEl.clientHeight;this._settings=e;const a=window.devicePixelRatio||1;let l=e.theme.background.color;const h="transparent"===l;4===l.length&&(l=l[0]+l[1]+l[1]+l[2]+l[2]+l[3]+l[3]),this._renderer=function(t){for(const e of Jy)if(e.test(t))return new e(t);throw new Error("Unable to auto-detect a suitable renderer.")}({width:n,height:o,view:r,antialias:!0,hello:!1,backgroundAlpha:h?0:1,autoDensity:!0,resolution:a,powerPreference:"high-performance",preserveDrawingBuffer:!0,backgroundColor:h?new F_(l).toNumber():void 0}),this.parentEl.appendChild(this._renderer.view),4===l.length&&(l=l[0]+l[1]+l[1]+l[2]+l[2]+l[3]+l[3]),h||(this._renderer.background.color=new F_(l).toNumber()),this._stage=new vv,this._stage.sortableChildren=!0,this._viewport=new bw({screenWidth:n,screenHeight:o,worldWidth:n,worldHeight:o,events:this._renderer.events,noTicker:!0,passiveWheel:!1}),(null==(s=Vy)?void 0:s.system)&&Vy.system.stop(),this.startAnimationLoop(),this.watchResize(),this._stage.addChild(this._viewport),this.on("focus",(t=>{t&&this.viewportPaused?this.startAnimationLoop():t||this.stopAnimationLoop(),this.viewportInFocus=t})),this.gfxLayers=Tw(this._viewport),j_(this,t)}draw(){var t;const e=Date.now();let i=e-this._oldTime;this._oldTime=e,i<0&&(i=0),i>1e3&&(i=1e3);let s=Object.keys(this.ticker.methods).length;(this.viewportNeedsUpdate||s)&&((null==(t=this.ticker)?void 0:t.methods)&&Object.values(this.ticker.methods).forEach((({fn:t,ctx:e})=>{"function"==typeof t&&(e?t.call(e,i):t(i))})),this._viewport.update(i),this._renderer.render(this._stage)),this.viewportPaused||requestAnimationFrame((()=>this.draw())),this.viewportNeedsUpdate=!1}startAnimationLoop(){this._oldTime=Date.now(),this.viewportNeedsUpdate=!0,this.viewportPaused=!1,requestAnimationFrame((()=>this.draw()))}stopAnimationLoop(){this.viewportPaused=!0}updateView(){if(!this.parentEl.clientWidth||!this.parentEl.clientHeight)return;const t=this._viewport,e=this._renderer,i=Zb,s=t.screenWidth,r=t.screenHeight,n=this.parentEl.clientWidth-this._canvasMargin.x,o=this.parentEl.clientHeight-this._canvasMargin.y;e.resize(n,o),t.resize(n,o);const a=s-n,l=r-o,h=this._settings.preserveViewbox,[u=.5,c=.5]=h.split("-").map((t=>ww[t])),d=u*a,p=c*l;t.position.set(t.x-d,t.y-p),t.plugins.get("clamp-zoom")||t.clampZoom({minHeight:this._settings.zoomRange[0]*i,maxHeight:this._settings.zoomRange[1]*i}),e.render(this._stage);let f=t.left,m=t.top,g=t.worldScreenWidth,y=t.worldScreenHeight;this.viewbox={min:[f/i,m/i],max:[(f+g)/i,(m+y)/i]},this.client=[t.screenWidth,t.screenHeight]}async watchResize(){this._canvasMargin.x=this.parentEl.clientWidth-this._viewport.screenWidth,this._canvasMargin.y=this.parentEl.clientHeight-this._viewport.screenHeight;new ResizeObserver((()=>{this.updateView(),this.emit("resize-canvas",this.viewbox)})).observe(this.parentEl)}get gfxNodeCount(){return Object.keys(this.gfxNodes).length}reset(){this.styleCache={},this.gfxNodes={},this.gfxLayers=Tw(this._viewport)}pause(t="drag"){this._viewport.plugins.pause(t)}resume(t="drag"){this._viewport.plugins.resume(t)}}const Tw=t=>{t.sortableChildren=!0;return{base:_w(t,"base",0),scene:_w(t,"scene",1),preview:_w(t,"preview",2),annotation:_w(t,"annotation",3),helper:_w(t,"helper",4)}};function Aw(t,e,i){e=e||this;const{view:s,settings:r}=e,n=s.gfxNodes[t.id];if(n){if("layout:space"===t.type){const e=s.layers.get("fpe-room-stamp");e&&tw(t,e.container,s.zoom,r)}Z_(t,e,{ctx:n.parent,container:n,...i}),s.viewportNeedsUpdate=!0,s.viewportPaused&&s.startAnimationLoop()}}class Iw{constructor({shapes:t=[],position:e=[0,0],alpha:i=1,scale:s=1,clearLayer:r=!1,interactive:n=!1,id:o,isHandler:a=!1,scaleOnZoom:l=!1,updatePositionOnDrag:h=!1,baseLayer:u,container:c,floorPlan:d}){if(this.shapes=t,this.gfxScale=s,this.scaleOnZoom=l,this.container=c,this.floorPlan=d,!this.container)return;r&&U_(this.container);let p=new Vv;this.gfx=p,p.alpha=i;const f=Math.min(1/this.floorPlan.view.zoom)*this.gfxScale;e&&(p.x=e[0]*Zb,p.y=e[1]*Zb),p.eventMode=n?"static":"none",p._nodeId=o,a&&(p._isHandler=!0),h&&this.on("drag",this.doUpdatePositionOnDrag,this),f&&l&&(p.scale.x=p.scale.y=f),u.addChild(this.container),this.container.addChild(p),t.forEach((t=>Y_({shape:t,settings:this.floorPlan.settings,gfx:p}))),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}set({position:t,rotation:e,style:i,shapes:s}={}){const r=Math.min(1/this.floorPlan.view.zoom)*this.gfxScale,n=this.gfx;if(function(t,{position:e,rotation:i}){e&&(t.x=e[0]*Zb,t.y=e[1]*Zb),i&&(t.rotation=-Math.PI/180*i)}(n,{position:t,rotation:e}),s&&(this.shapes=s,n.clear(),U_(n),s.forEach((t=>Y_({shape:t,settings:this.floorPlan.settings,gfx:n})))),r&&this.scaleOnZoom&&(n.scale.x=n.scale.y=r),i){const t=H_(i);i.fill&&(n.geometry.graphicsData[0].fillStyle.color=Nl(i.fill)),n.geometry.graphicsData[0].lineStyle.color=Number(t.color),n.geometry.graphicsData[0].lineStyle.width=t.width,n.geometry.graphicsData[0].lineStyle.native=t.native,n.geometry.invalidate()}this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}doUpdatePositionOnDrag({position:t}){this.set({position:t})}on(t,e,i){return this.gfx.eventMode="static","drag"===t?this.addDragEvent(e,i):this.gfx.on(t,e,i),this}off(t,e){return"drag"===t?this.removeDragEvent():this.gfx.off(t,e),this}destroy(){this.off("drag"),this.gfx.destroy(),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}addDragEvent(t,e){function i(){this.floorPlan.interaction.isDragging=!1,this.floorPlan.view.resume("drag"),this.floorPlan.off("mousemove",t)}this.on("pointerdown",(function(){this.floorPlan.interaction.isDragging=!0,this.floorPlan.view.pause("drag"),this.floorPlan.on("mousemove",t,e)}),this),this.on("pointerup",i,this),this.on("pointerupoutside",i,this),this.on("pointercancel",i,this)}removeDragEvent(){this.off("pointerdown"),this.off("pointerup"),this.off("pointerupoutside"),this.off("pointercancel")}}class Sw{constructor(t,e,i){this.graphics=new Set,this.container=new vv,this.id=i,this.baseLayer=t.view.gfxLayers[e]||t.view.gfxLayers.helper,this.floorPlan=t,this.baseLayer.addChild(this.container)}addGraphic(t){const e=new Iw({...t,floorPlan:this.floorPlan,baseLayer:this.baseLayer,container:this.container});return this.graphics.add(e),e}findGraphic(t){return this.container.getChildByName(t)}deleteGraphic(t){this.graphics.delete(t),t.destroy()}clear(){U_(this.container),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}destroy(){this.container&&(this.floorPlan.view.layers.delete(this.id),this.container.destroy({children:!0,texture:!0,baseTexture:!0}),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop(),delete this.container,delete this.floorPlan)}}function Cw(t,{format:e,fileName:i,quality:s}={}){if("svg"===e)return;const r=new Image;r.src=t,r.onload=function(){const t=document.createElement("canvas");t.width=r.naturalWidth,t.height=r.naturalHeight;const n=t.getContext("2d");n.imageSmoothingEnabled=!1,n.drawImage(r,0,0),function(t,{format:e="png",fileName:i="floorplan",quality:s=.95}){let r="png"===e?"image/png":"image/jpeg";t.toBlob((function(t){!function({fileName:t,href:e,ext:i}){const s=document.createElement("a");Object.assign(s,{href:e,download:g(t,i),target:"_blank",rel:"noopener",style:"display:none;"}),document.body.appendChild(s),s.click(),document.body.removeChild(s)}({fileName:i,href:URL.createObjectURL(t),ext:e})}),r,s)}(t,{format:e,fileName:i,quality:s})}}const Mw=el.blue_ribbon,Ow=el.zurich,Nw=el.white,Lw=Mw,Rw=Mw,kw=Ow,Bw=Mw,Fw=Mw,Dw=Nw;class Uw extends i_{constructor({floorPlan:t,helperId:e,mode:i="distance"}){super({floorPlan:t,helperId:e}),this.drawing=!1,this.polygonsOrPolylines=[],this.floorPlan=t,this.mode=i,this.floorPlan.on("mousemove",this.handlePointerMove,this),this.floorPlan.on("click",this.handlePointerDown,this),this.floorPlan.on("dblclick",this.handlePointerDown,this),this.floorPlan.on("update-settings",this.draw,this),this.startDrawing()}get isInAreaMode(){return"area"===this.mode}get isDrawing(){return this.drawing}set({mode:t}){this.mode=t,this.draw()}handlePointerMove(t){this.setSnapCursor(t)}handlePointerDown(t){this.setSnapCursor(t),this.drawPoint(t)}setSnapCursor({position:t}){this._snapCursor??(this._snapCursor=this.floorPlan.addHelper("snapCursor",{position:t}));const{snapPoints:e,snapMargin:i}=this.floorPlan.computed;if(!e.length)return this._snapCursor.set({position:t}),void this.draw();const s=Xl(t,e,i);this._snapCursor.isSnapping=!!s,this._snapCursor.set({position:s||t}),this.draw()}stopDrawing(){this.polygonsOrPolylines[this.polygonsOrPolylines.length-1].points.length>1&&this.drawing&&this.polygonDone()}cancelDrawing(){this.destroy()}startDrawing(){this.drawing=!0,this.polygonsOrPolylines.push({points:[],isClosed:!1,length:0,area:0,areaDisplay:"",lengthDisplay:"",contour:null,label:null,pointGraphics:[]})}removeLastPoint(){var t,e;const i=this.polygonsOrPolylines[this.polygonsOrPolylines.length-1];if((null==i?void 0:i.points.length)>0){i.points.pop();const s=i.pointGraphics.pop();s&&this.layer.deleteGraphic(s),i.points.length<=1&&(i.contour&&(null==(t=this.layer)||t.deleteGraphic(i.contour),i.contour=null),i.label&&(null==(e=this.layer)||e.deleteGraphic(i.label),i.label=null)),0===i.points.length?(this.polygonsOrPolylines.pop(),this.drawing=!1):this.draw()}}polygonDone(){this.drawing=!1,this.emit("polygon-done",{}),this.draw()}drawPoint(t){var e;this.drawing||this.startDrawing();const i=this.polygonsOrPolylines.length-1,s=this.polygonsOrPolylines[i];if((null==(e=t.nodeId)?void 0:e.startsWith(`point/${i}/`))||t.isDoubleClick){const e=t.nodeId===`point/${i}/0`;return"distance"===this.mode&&e&&(s.isClosed=!0),void this.polygonDone()}const{position:r}=this._snapCursor;s.points.push([...r]);const n=s.points.length-1,o=`point/${i}/${n}`;this.layer||(this.layer=this.floorPlan.addLayer());const a=this.layer.addGraphic({shapes:[{type:"curve:circle",position:[0,0],radius:.15,style:{fill:Bw,fillOpacity:.1}},{type:"curve:circle",position:[0,0],radius:.05,style:{stroke:Fw,fill:Dw,strokeWidth:1.5}}],position:r,scaleOnZoom:!0,id:o,isHandler:!0});s.pointGraphics[n]=a,a.on("drag",(function(){this.updatePolygon(i,n,this.floorPlan.interaction.cursor),a.set({position:s.points[n]})}),this)}updatePolygon(t,e,i){const s=i,{snapPoints:r,snapMargin:n}=this.floorPlan.computed,o=r.length&&Xl(s,r,n);this.polygonsOrPolylines[t].points[e]=o||s,this.draw()}getLengthText(t){const{units:e}=this.floorPlan.settings;return f(t,e.system,e.lengthDecimals)}getAreaText(t){const{units:e}=this.floorPlan.settings;return m(t,e.system,e.areaDecimals)}reset(){this.drawing=!1,this.polygonsOrPolylines=[],this.floorPlan.removeHelper("snapCursor"),this._snapCursor=null,this.layer&&(this.layer.destroy(),this.layer=null)}draw(){this.polygonsOrPolylines.length&&(this.layer||(this.layer=this.floorPlan.addLayer()),this.polygonsOrPolylines.forEach(((t,e)=>{if(!t.points.length)return;const i=this.drawing&&this._snapCursor&&e===this.polygonsOrPolylines.length-1?[...t.points,this._snapCursor.position]:t.points;if(i.length<2)return;t.length=function(t,e=!0){let i=0,s=e?t.length:t.length-1;for(var r=0;r<s;r++){let e=r,s=r<t.length-1?r+1:0;i+=hi(t[e],t[s])}return i}(i,t.isClosed),t.lengthDisplay=this.getLengthText(t.length);const s=i.length<2?0:180*xi(i[0],i[1])/Math.PI,r=i.map((t=>t.map((t=>Number(t.toFixed(10)))))).slice(0,this.isInAreaMode?void 0:2),n=this.isInAreaMode?Ai([r]):[r[0][0]+(r[1][0]-r[0][0])/2,r[0][1]+(r[1][1]-r[0][1])/2];t.area=Math.abs(Z(i)),t.areaDisplay=this.getAreaText(t.area);const o=this.isInAreaMode||t.isClosed?"curve:polygon":"curve:polyline",a={stroke:kw,dash:!0,strokeWidth:"native"};let l=t.lengthDisplay,h=s;this.isInAreaMode&&(a.fill=Rw,a.fillOpacity=.04,l=t.areaDisplay,h=0);const u=[{type:o,points:i,style:a}],c={shapes:[{type:"text",text:l,position:[0,0],rotation:h,alignV:"bottom",fontSize:15,style:{fill:Lw}}],id:"text",position:n,scaleOnZoom:!0};t.contour?t.contour.set({shapes:u}):t.contour=this.layer.addGraphic({shapes:u}),t.label?t.label.set(c):t.label=this.layer.addGraphic(c);const d=this.isInAreaMode?{area:t.area}:{distance:t.length};this.emit("polygon-draw",d)})))}destroy(){this.reset(),this.floorPlan.off("mousemove",this.handlePointerMove),this.floorPlan.off("click",this.handlePointerDown),this.floorPlan.off("dblclick",this.handlePointerDown),this.floorPlan.off("update-settings",this.draw),super.destroy()}}class Gw extends i_{constructor({floorPlan:t,helperId:e,position:i}){super({floorPlan:t,helperId:e}),this.position=[0,0],this.floorPlan.on("mousemove",this.draw,this),this.isSnapping=!1,this.isEdge=!1,this.isError=!1,i&&(this.position=i)}draw(){if(this.floorPlan)if(this.layer||(this.layer=this.floorPlan.addLayer({id:"fpe-snap-cursor"})),this.cursor){let t=el.stone;this.isError?t=el.error:this.isSnapping&&(t=el.blue_ribbon);const e=this.isSnapping?2:1.5;this.cursor.set({position:this.position,style:{stroke:t,strokeWidth:e}})}else this.cursor=this.layer.addGraphic({shapes:[{type:"curve:circle",position:[0,0],radius:.06,style:{stroke:el.blue_ribbon,strokeWidth:1.5}}],position:this.position,scaleOnZoom:!0})}set({position:t,isSnapping:e,isEdge:i,isError:s}){this.position=t,this.isSnapping=e,this.isEdge=i,this.isError=s,this.draw()}snapState(){return this.isSnapping?this.isEdge?"edge":"point":""}destroy(){var t;null==(t=this.floorPlan)||t.off("mousemove",this.draw),this.layer&&this.layer.destroy(),this.layer=void 0,this.cursor=null,super.destroy()}}function Xw(t,e){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: node ID change, type ${t.type}, previous ID ${e}`),this.drawNodeUpdate(t.id))}function Ww(t,e){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: node property change, type ${t.type}, property name ${e}`),this.drawNodeUpdate(t.id))}function Hw(t){this.preventUpdateOnSpaceGraphEvent||nl.debug(`${t.id}: vertex create`)}function Yw(t){this.preventUpdateOnSpaceGraphEvent||nl.debug(`${t.id}: vertex delete`)}function $w(t){if(!this.preventUpdateOnSpaceGraphEvent){nl.debug(`${t.id}: vertex set position`);for(let e of t.edges)this.drawNodeUpdate(e.id)}}function jw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: edge create`),this.drawNodeUpdate(t.id))}function zw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: edge delete`),this.drawNodeUpdate(t.id))}function Vw(t,e){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: edge set vertices`),this.drawNodeUpdate(t.id))}function qw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: space create`),this.drawNodeUpdate(t.id))}function Jw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: space delete`),this.drawNodeUpdate(t.id))}function Kw(t,e){this.preventUpdateOnSpaceGraphEvent||nl.debug(`${t.id}: space split into ${e[0].id} and ${e[1].id}`)}function Zw(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: space attributes change`),this.drawNodeUpdate(t.id))}function Qw(t){this.preventUpdateOnSpaceGraphEvent||"layout:space"!==t.type||(nl.debug(`${t.id}: custom attributes change`),this.drawNodeUpdate(t.id))}function tP(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: element create, type ${t.type}`),this.drawNodeUpdate(t.id))}function eP(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: element delete, type ${t.type}`),this.drawNodeUpdate(t.id))}function iP(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: element transform change, type ${t.type}`),this.drawNodeUpdate(t.id))}function sP(t){if(!this.preventUpdateOnSpaceGraphEvent)if(nl.debug(`${t.id}: element parameters change, type ${t.type}`),"element:wall"===t.type){let e=t.getAdjacentElementsByVertex().flat();if(this.view.wallNodesToUpdate.push(t.id,...e.map((t=>t.id))),this.view.wallNodeUpdateInProgress)return;this.view.wallNodeUpdateInProgress=!0,setTimeout((()=>{const t=new Set(this.view.wallNodesToUpdate);Sa(this.layout);for(const e of t)this.drawNodeUpdate(e);this.view.wallNodeUpdateInProgress=!1,this.view.wallNodesToUpdate=[]}))}else Dr(t),this.drawNodeUpdate(t.id)}function rP(t){this.preventUpdateOnSpaceGraphEvent||queueMicrotask((()=>this.drawNodeUpdate(t.id)))}function nP(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: annotation change, type ${t.type}`),this.drawNodeUpdate(t.id))}function oP(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: geometry profile update`),this.drawNodeUpdate(t.id))}function aP(t){this.preventUpdateOnSpaceGraphEvent||(nl.debug(`${t.id}: geometry update`),["element:boundaryWall","element:generic"].includes(t.type)&&this.drawNodeUpdate(t.id))}function lP(t){const e=t.addLayer({id:"fpe-grid-lines",baseLayer:"base"});let i;function s(t,e,s=!1){const r=Zb;if(!t)return;let n;if(n=e.view.zoom>2?.1:e.view.zoom>.25?1:(e.view.zoom,10),!s&&n===i)return;if(U_(t),!e.settings.theme.background.showGrid)return;const o=new Vv;let a=Nl(el.athens);o.lineStyle({width:1,color:a,native:!0});for(let i=-100;i<100;i+=n)Math.round(100*i)/100==0?o.lineStyle({width:2,color:a,native:!0}):(Math.round(100*i)/100%10==0||Math.round(100*i),o.lineStyle({width:1,color:a,native:!0})),o.moveTo(-100*r,i*r),o.lineTo(100*r,i*r),o.moveTo(i*r,-100*r),o.lineTo(i*r,100*r);t.addChild(o),i=n}return s(null==e?void 0:e.container,t),{update:i=>s(e.container,t,i)}}function hP(t,e="Floor plan engine couldn't load properly on this page. For technical details check the browser console."){const i=t.querySelector(".fpe-err")??function(t){const e=document.createElement("div"),i=document.createElement("div"),s=document.createElement("div"),r=document.createElement("div");return e.classList.add("fpe-err"),i.classList.add("fpe-err__box"),s.classList.add("fpe-err__title"),r.classList.add("fpe-err__msg"),t.append(e),e.append(i),i.append(s),i.append(r),s.textContent="Something went wrong",t.append(e),t}(t);i.querySelector(".fpe-err__msg").textContent=e}const uP={lastSceneClick:[0,0],cursor:[0,0],cursorTarget:null,isDragging:!1,altKey:!1,shiftKey:!1,metaKey:!1,ctrlKey:!1,dragOffset:null,cursorAction:"none",isPanning:!1,lastClick:{time:null,position:{x:0,y:0}},_dragStart:{x:0,y:0},preventFocusoutOnAltKeyup:!1};Yb=new WeakMap,$b=new WeakSet,jb=function(t){if(t!==(Vb(e=this,i=Yb,"read from private field"),i.get(e))){var e,i;Jb(this,Yb,t);try{this.fpeNode.style.setProperty("--fpe-font-family",t)}catch(dP){console.warn("Failed to set font-family",dP)}}},t.FloorPlanEngine=class extends Pl{constructor({container:t,options:e={}}={}){let i;super({options:e}),qb(this,$b),qb(this,Yb),this.interaction=uP,this.availableHelpers={cursorCoordinates:s_,scaleBar:r_},this.helper={},this.preventUpdateOnSpaceGraphEvent=!1,Jb(this,Yb,il.theme.fontFamily),i=t instanceof Element?t:document.body,this.mountFloorPlan(i),this.availableHelpers.polygonHelper=Uw,this.availableHelpers.snapCursor=Gw,this.on("space-api-floor-error",((t,e)=>{hP(this.fpeNode,e)})),this.on("space-api-floor-loaded",(()=>{!function(t){var e;null==(e=t.querySelector(".fpe-err"))||e.remove()}(this.fpeNode)}))}prevent(t){t.preventDefault()}on(t,e,i){return this._emitter.on(t,e,i),this}once(t,e,i){return this._emitter.once(t,e,i),this}off(t,e,i){return this._emitter.off(t,e),this}emit(t,...e){return this._emitter.emit(t,...e),this}handleDrop(t){var e;t.preventDefault(),t.stopPropagation();const i=[t.offsetX,t.offsetY],s=this.getPlanPosition(i);this.interaction.cursor=[...s];const{spaces:r}=this.getResourcesFromPosition(s),n=null==(e=r[0])?void 0:e.slabs.find((t=>"element:floor"===t.type)),o=(null==n?void 0:n.parameters.elevation)||0;this.emit("drop",{position:s,sourceEvent:t,verticalPos:o,screenPos:i})}set(t){super.set(t),this.view&&(yw({floorPlan:this,update:!0}),xw(this),lP(this))}drawNodePreview(t,e,i,s){Z_((null==e?void 0:e.elementsById[t])||(null==e?void 0:e.spacesById[t])||(null==e?void 0:e.spatialGraph.edgesById[t]),this,{preview:!0,style:s,ctx:i.container})}drawNodeUpdate(t,e){var i,s,r,n,o;if(!this.layout)return;let a=(null==(i=this.layout)?void 0:i.elementsById[t])||(null==(s=this.layout)?void 0:s.spacesById[t])||(null==(r=this.layout)?void 0:r.annotationsById[t])||(null==(n=this.layout)?void 0:n.spatialGraph.edgesById[t]);if(a)if(this.view.gfxNodes[t])Aw(a,this,{style:e});else{let t=this.view.gfxLayers.scene;"parent"in a&&this.view.gfxNodes[null==(o=a.parent)?void 0:o.id]&&(t=this.view.gfxNodes[a.parent.id]),Z_(a,this,{ctx:t,style:e})}else!function(t,e){const i=e.view.gfxNodes[t];i&&(i.parent.removeChild(i),i.destroy({children:!0})),delete e.view.gfxNodes[t],delete e.view.styleCache[t],Q_(t,e.getLayer("fpe-room-stamp").container),e.view.viewportNeedsUpdate=!0,e.view.viewportPaused&&e.view.startAnimationLoop()}(t,this);if(a&&"getEdges"in a)for(const l of a.getEdges())this.drawNodeUpdate(l.id,e)}drawResourceUpdate({resourceId:t}){let e=this.loader.resources.nodes.get(t);for(let i of e)Aw(i,this,{})}mountFloorPlan(t){const e=t.querySelector(".fpe");e&&e.remove();const i=document.createElement("div");i.id=this.fpeId,i.classList.add("fpe"),t.appendChild(i);const s=document.createElement("div");s.classList.add("fpe__plan");const r=document.createElement("canvas");r.title="fpe-canvas",r.classList.add("fpe__canvas"),i.appendChild(s),s.appendChild(r),this.fpeNode=i;try{i.style.setProperty("--fpe-font-family",this.settings.theme.fontFamily)}catch(dP){console.warn("Failed to set font-family",dP)}this.view=new Ew(this.loader,this.settings,s),this.loader.on("resource-loaded",this.drawResourceUpdate,this),this.loader.on("spaces-loaded",this.initDrawing,this),r.addEventListener("drop",this.handleDrop.bind(this)),r.addEventListener("gesturestart",this.prevent),r.addEventListener("gesturechange",this.prevent),r.addEventListener("gestureend",this.prevent),r.addEventListener("dragover",this.prevent),this.settings.destroyOnDomRemove&&function(t,e,i){const s=new MutationObserver((()=>{(function t(i){return i.parentNode!==e&&(null===i.parentNode||t(i.parentNode))})(t)&&(s.disconnect(),i())}));s.observe(e,{childList:!0,subtree:!0})}(i,t,(()=>this.destroy())),dw(this),this.view.on("scene-rendered",(({update:t})=>{t||this.zoomExtents(1,0)})),this.view.on("zoom",(()=>{this.view.layers.forEach((t=>{t.graphics.forEach((t=>{t.scaleOnZoom&&!t.gfx.destroyed&&t.set()}))})),vw(this),lP(this)})),this.view&&lP(this),Kb(this,$b,jb).call(this,this.settings.theme.fontFamily),this.on("update-settings",(t=>{Kb(this,$b,jb).call(this,t.theme.fontFamily)})),this.generateUi()}initDrawing(){var t;!this.loader.initialLoading&&(null==(t=this.view.gfxLayers)?void 0:t.scene)&&U_(this.view.gfxLayers.scene),yw({floorPlan:this}),xw(this),this.initDrawingEvents()}initDrawingEvents(){this.spaceGraph.on("node-id-change",Xw,this),this.spaceGraph.on("node-property-change",Ww,this),this.spaceGraph.on("node-custom-attributes-change",Qw,this),this.spaceGraph.on("vertex-create",Hw,this),this.spaceGraph.on("vertex-delete",Yw,this),this.spaceGraph.on("vertex-set-position",$w,this),this.spaceGraph.on("edge-create",jw,this),this.spaceGraph.on("edge-delete",zw,this),this.spaceGraph.on("edge-set-vertices",Vw,this),this.spaceGraph.on("space-create",qw,this),this.spaceGraph.on("space-delete",Jw,this),this.spaceGraph.on("space-split",Kw,this),this.spaceGraph.on("space-attributes-change",Zw,this),this.spaceGraph.on("element-create",tP,this),this.spaceGraph.on("element-delete",eP,this),this.spaceGraph.on("element-transform-change",iP,this),this.spaceGraph.on("element-parameters-change",sP,this),this.spaceGraph.on("element-edges-change",rP,this),this.spaceGraph.on("geometry-profile-update",oP,this),this.spaceGraph.on("geometry-update",aP,this),this.spaceGraph.on("annotation-transform-change",nP,this),this.spaceGraph.on("annotation-parameters-change",nP,this)}freeDrawingEvents(){this.spaceGraph.off("node-id-change",Xw),this.spaceGraph.off("node-property-change",Ww),this.spaceGraph.off("vertex-create",Hw),this.spaceGraph.off("vertex-delete",Yw),this.spaceGraph.off("vertex-set-position",$w),this.spaceGraph.off("edge-create",jw),this.spaceGraph.off("edge-delete",zw),this.spaceGraph.off("edge-set-vertices",Vw),this.spaceGraph.off("space-create",qw),this.spaceGraph.off("space-delete",Jw),this.spaceGraph.off("space-split",Kw),this.spaceGraph.off("space-attributes-change",Zw),this.spaceGraph.off("element-create",tP),this.spaceGraph.off("element-delete",eP),this.spaceGraph.off("element-transform-change",iP),this.spaceGraph.off("element-parameters-change",sP),this.spaceGraph.off("geometry-profile-update",oP),this.spaceGraph.off("geometry-update",aP),this.spaceGraph.off("annotation-transform-change",nP),this.spaceGraph.off("annotation-parameters-change",nP)}generateUi(){this.settings.ui.coordinates?this.addHelper("cursorCoordinates",{parentEl:this.fpeNode}):this.helper.cursorCoordinates&&this.removeHelper("cursorCoordinates"),this.settings.ui.scale?this.addHelper("scaleBar",{parentEl:this.fpeNode}):this.helper.scaleBar&&this.removeHelper("scaleBar")}getZoomExtentsBoundingBox(t,e,i,s,r,n,o){return function({layoutBoundingBox:t,rectLeft:e,rectTop:i,rectRight:s,rectBottom:r,viewportWidth:n,viewportHeight:o}){if([e,i,s,r].some((t=>t>0))&&n&&o){const a=s-e,l=r-i,h=function(t,e,i){const{min:s,max:r}=t;let n=s[0],o=s[1],a=r[0],l=r[1],h=a-n,u=l-o;const c=e/i;if(h/u>c){const t=u;u=h/c;const e=(t-u)/2;o+=e,l-=e}else{const t=h;h=u*c;const e=(t-h)/2;n+=e,a-=e}return{min:[n,o],max:[a,l]}}(t,a,l);let{min:u,max:c}=h,d=u[0],p=u[1],f=c[0]-d,m=c[1]-p;return f*=n/a,m*=o/l,d-=e/n*f,p-=i/o*m,{min:[d,p],max:[d+f,p+m]}}return t}({layoutBoundingBox:t,rectLeft:e,rectTop:i,rectRight:s,rectBottom:r,viewportWidth:n,viewportHeight:o})}zoomExtents(t=1,e=!1,i=null){return function({margin:t=0,animate:e,floorPlan:i,boundingBox:s}){return i.view.gfxLayers.scene?sw(s?{bb:s,animate:e,view:i.view}:{bb:i.getBoundingBox(t),animate:e,view:i.view}):Promise.resolve(!1)}({margin:t,animate:e,floorPlan:this,boundingBox:i})}zoomToElement(t,e=1,i){let s;if("string"==typeof t){const e=t;s=this.layout.elementsById[e]||this.layout.spacesById[e]||this.layout.spatialGraph.edgesById[e]||null}else s=t;if(!s)return Promise.resolve(!0);const{min:[r,n,o],max:[a,l,h]}=s.getAxisAlignedBoundingBox();return sw({bb:{min:[r-e,o-e],max:[a+e,h+e]},animate:i,view:this.view})}setZoom(t,e=!0){return sw({bb:t,animate:e,view:this.view})}zoomByFactor(t,e=!0){if(!Number.isFinite(t)||t<=0)return Promise.reject("factor is not a positive number");let{min:i,max:s}=this.view.viewbox,r=i[0],n=i[1],o=s[0]-r,a=s[1]-n;r-=(o/t-o)/2,n-=(a/t-a)/2;const l=r+o,h=n+a;return this.setZoom({min:[r,n],max:[l,h]},e)}addInfoWindow(t={}){return new a_({...t,floorPlan:this})}addHtmlMarker(t={}){return new l_({...t,floorPlan:this})}addMarker({position:t=[0,0],color:e="#669cff",size:i=40}={}){return new D_({position:t,color:e,size:i,floorPlan:this})}getPlanPosition(t){const e=this.view._viewport.toWorld(t[0],t[1]);return[e.x/Zb,e.y/Zb]}getScreenPosition(t){const e=t.map((t=>t*Zb)),i=this.view._viewport.toScreen(e[0],e[1]);return[i.x,i.y]}addLayer({id:t,baseLayer:e}={}){var i;if(!(null==(i=this.view)?void 0:i.layers))return;if(t||(t=O()),this.view.layers.has(t)){const e=this.view.layers.get(t);if(null==e?void 0:e.container)return e}const s=new Sw(this,e,t);return this.view.layers.set(t,s),s}getLayer(t){return this.view.layers.get(t)}addPlanGraphic(){return new Sw(this)}addHelper(t,e={}){let i=null==e?void 0:e.helperId;return i||(i="string"==typeof t?t:O()),this.helper[i]&&this.removeHelper(i),"string"==typeof t?this.availableHelpers[t]?this.helper[i]=new this.availableHelpers[t]({floorPlan:this,helperId:i,...e}):nl.warn(`No helper registered for: ${t}`):this.helper[i]=new t({floorPlan:this,helperId:i,...e}),this.helper[i]}removeHelper(t){var e,i;null==(i=null==(e=this.helper[t])?void 0:e.destroy)||i.call(e),delete this.helper[t]}async exportImage({format:t="png",fileName:e,quality:i=90,output:s="base64",maxWidth:r,download:n=!1}={}){let o={format:t,quality:i};n&&(o.format="png");const a=document.querySelector("#"+this.fpeId+" canvas"),l=await function(t,{format:e="png",quality:i=.95}){return new Promise((s=>{let r;r="jpg"===e?t.toDataURL("image/jpeg",i):t.toDataURL(),s(r)}))}(a,o).catch((t=>t));if(!n)return l;Cw(l,{format:t,fileName:e,quality:i})}destroy(){var t;null==(t=this.view._viewport)||t.destroy(),this.view.reset(),this.loader.reset(),this.freeDrawingEvents(),delete this.layout,delete this.utils,this.fpeNode&&this.fpeNode.remove(),delete this.fpeNode}},t.setApiUrls=({apiStorageUrl:t,spaceApiUrl:e,apiProductDataPath:i}={})=>{"string"==typeof t&&(rl=t),"string"==typeof i&&(sl=i),"string"==typeof e&&(R=e)},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|