@archilogic/floor-plan-sdk 0.0.0-20240716133754

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.
@@ -0,0 +1,10 @@
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),s);
2
+ /*!
3
+ Archilogic Floor Plan Engine SDK v5.0.0-rc.1 webgl build nightly-240716-133233-16e7b6
4
+
5
+ Copyright (c) 2024 Archilogic AG. All rights reserved.
6
+
7
+ License: According to your license agreement with Archilogic AG
8
+ */
9
+ 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},g=(t,e)=>{const i=`.${e}`;return(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 E=["info","warnings","errors"];let P=class{constructor(t){this.levels=E.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)}};function T(t,e=4){const i=Math.pow(10,e);return Math.round((t+Number.EPSILON)*i)/i}var I,A=new Uint8Array(16);function S(){if(!I&&!(I="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return I(A)}const C=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var M=[],N=0;N<256;++N)M.push((N+256).toString(16).substr(1));function O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=(M[t[e+0]]+M[t[e+1]]+M[t[e+2]]+M[t[e+3]]+"-"+M[t[e+4]]+M[t[e+5]]+"-"+M[t[e+6]]+M[t[e+7]]+"-"+M[t[e+8]]+M[t[e+9]]+"-"+M[t[e+10]]+M[t[e+11]]+M[t[e+12]]+M[t[e+13]]+M[t[e+14]]+M[t[e+15]]).toLowerCase();if(!function(t){return"string"==typeof t&&C.test(t)}(i))throw TypeError("Stringified UUID is invalid");return i}function R(t,e,i){var s=(t=t||{}).random||(t.rng||S)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,O(s)}const L=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 k 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 F="https://api.archilogic.com";function D(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 k("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 k(i,t.status,void 0));case"object":return Promise.reject(new k(i.message,t.status,i.data));default:return Promise.reject(new k(null,null,e))}}))}async function U(t,e,i={},s){const r=new URL(F+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 k("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 G{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),i(this,"getTemporaryAccessToken",(async()=>{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 k(`Temporary access token expired at ${t.toString()}`,void 0,void 0))}else e(new k("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)}})),this.config=D(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 callSpaceAPI(t,e,i={},s=this.config){switch(s.type){case"secret":case"publishable":return U(t,e,i,s);case"temporary":{const r=await this.getTemporaryAccessToken();return U(t,e,i,{...s,temporaryAccessToken:r})}}}}class X{constructor(t,e={}){i(this,"connection"),this.connection=new G(t);for(const[i,s]of Object.entries(e))this[i]=s}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=L({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=L(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=await this.queryFloors({geometry:t,includeArchived:e,includeRelations:i,includeCustomAttributes:r,teamId:s});let o=n.features;for(;null==o?void 0:o.length;)o=(await this.queryFloors({geometry:t,includeArchived:e,includeRelations:i,includeCustomAttributes:r,teamId:s,offset:n.features.length})).features,n.features.push(...o);return n}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=await this.querySpaces({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s});let n=r.features;for(;null==n?void 0:n.length;)n=(await this.querySpaces({floorId:t,geometry:e,includeRelations:i,includeCustomAttributes:s,offset:r.features.length})).features,r.features.push(...n);return r}getAssetById(t,e=!1,i=!0,s=!1){const r=L({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 e=await this.queryAssets(t);let i=e.features;for(;null==i?void 0:i.length;)i=(await this.queryAssets({...t,offset:(t.offset||0)+e.features.length})).features,e.features.push(...i);return e}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})}getLayout(t,e){const i=L(e?{filter:e}:{});return this.connection.callSpaceAPI("GET",`/v2/layout/${t}${i}`)}getLayouts(t,e){const i=L({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=L({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)}}var H,W=Object.defineProperty,Y=(t,e,i)=>(((t,e,i)=>{e in t?W(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);(t=>{t.version="6.4.2.2",t.use_lines=!0;class e{constructor(){Y(this,"m_Parent",null),Y(this,"m_polygon",[]),Y(this,"m_Index",0),Y(this,"m_jointype",0),Y(this,"m_endtype",0),Y(this,"m_Children",[]),Y(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(),Y(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){Y(this,"X",0),Y(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){Y(this,"left"),Y(this,"top"),Y(this,"right"),Y(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(){Y(this,"Bot",new t.FPoint),Y(this,"Curr",new t.FPoint),Y(this,"Top",new t.FPoint),Y(this,"Delta",new t.FPoint),Y(this,"Dx",0),Y(this,"PolyTyp",0),Y(this,"Side",0),Y(this,"WindDelta",0),Y(this,"WindCnt",0),Y(this,"WindCnt2",0),Y(this,"OutIdx",0),Y(this,"Next",null),Y(this,"Prev",null),Y(this,"NextInLML",null),Y(this,"NextInAEL",null),Y(this,"PrevInAEL",null),Y(this,"NextInSEL",null),Y(this,"PrevInSEL",null)}};t.IntersectNode=class{constructor(){Y(this,"Edge1",null),Y(this,"Edge2",null),Y(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(){Y(this,"Y",0),Y(this,"LeftBound",null),Y(this,"RightBound",null),Y(this,"Next",null)}};t.Scanbeam=class{constructor(){Y(this,"Y",0),Y(this,"Next",null)}};t.Maxima=class{constructor(){Y(this,"X",0),Y(this,"Next",null),Y(this,"Prev",null)}};t.OutRec=class{constructor(){Y(this,"Idx",0),Y(this,"IsHole",!1),Y(this,"IsOpen",!1),Y(this,"FirstLeft",null),Y(this,"Pts",null),Y(this,"BottomPt",null),Y(this,"PolyNode",null)}};t.OutPt=class{constructor(){Y(this,"Idx",0),Y(this,"Pt",new t.FPoint),Y(this,"Next",null),Y(this,"Prev",null)}};t.Join=class{constructor(){Y(this,"OutPt1",null),Y(this,"OutPt2",null),Y(this,"OffPt",new t.FPoint)}};class u{constructor(){Y(this,"m_MinimaList",null),Y(this,"m_CurrentLM",null),Y(this,"m_edges",new Array),Y(this,"m_HasOpenPaths",!1),Y(this,"PreserveCollinear",!1),Y(this,"m_Scanbeam",null),Y(this,"m_PolyOuts",null),Y(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)}}Y(u,"horizontal",-34e37),Y(u,"Skip",-2),Y(u,"Unassigned",-1),Y(u,"tolerance",1e-20),Y(u,"maxValue",Math.sqrt(Number.MAX_VALUE)),Y(u,"minValue",Math.sqrt(Number.MIN_VALUE)),t.ClipperBase=u;class c extends u{constructor(e){super(),Y(this,"m_SortedEdges",null),Y(this,"m_IntersectList",null),Y(this,"m_IntersectNodeComparer",null),Y(this,"m_ExecuteLocked",!1),Y(this,"m_ClipFillType",0),Y(this,"m_SubjFillType",0),Y(this,"m_Joins",null),Y(this,"m_GhostJoins",null),Y(this,"m_UsingPolyTree",!1),Y(this,"ReverseSolution",!1),Y(this,"StrictlySimple",!1),Y(this,"m_ClipType",0),Y(this,"m_Maxima",null),Y(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}}Y(c,"ioReverseSolution",1),Y(c,"ioStrictlySimple",2),Y(c,"ioPreserveCollinear",4),t.Clipper=c;class d{constructor(e,i){Y(this,"m_destPolys",[]),Y(this,"m_srcPoly",[]),Y(this,"m_destPoly",[]),Y(this,"m_normals",new Array),Y(this,"m_delta",0),Y(this,"m_sinA",0),Y(this,"m_sin",0),Y(this,"m_cos",0),Y(this,"m_miterLim",0),Y(this,"m_StepsPerRad",0),Y(this,"m_lowest",new t.FPoint),Y(this,"m_polyNodes",new t.PolyNode),Y(this,"MiterLimit"),Y(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))}}Y(d,"two_pi",6.28318530717959),Y(d,"def_arc_tolerance",.25),t.ClipperOffset=d,t.Error=function(e){throw new t.Error(e)}})(H||(H={}));const $=H;function z(t){let e=tt(t),i=$.Clipper.GetBounds(e);return{min:[i.left,-i.bottom],max:[i.right,-i.top]}}function V(t){if(!t.length||!t[0])return[];let e=tt(t);if(!e.length)return[];let i=[e[0]],s=e.slice(1),r=new $.Clipper;r.AddPaths(i,$.PolyType.ptSubject,!0),r.AddPaths(s,$.PolyType.ptClip,!0);let n=[];return r.Execute($.ClipType.ctUnion,n,$.PolyFillType.pftNonZero,$.PolyFillType.pftNonZero),et(n)}function j(t,e,i){if(!t.length||!t[0])return[];let s=tt(t),r=tt(e),n=new $.Clipper;n.AddPaths(s,$.PolyType.ptSubject,!i),n.AddPaths(r,$.PolyType.ptClip,!0);let o=[];return new $.PolyTree,n.Execute($.ClipType.ctDifference,o,$.PolyFillType.pftNonZero,$.PolyFillType.pftNonZero),et(o)}function q(t,e,i=[]){let s=new $.FPoint(t[0],-t[1]),r=tt([e])[0],n=$.Clipper.PointInPolygon(s,r);for(let o of i){let e=q(t,o);1===e?n=0:-1===e&&(n=-1)}return n}function J(t){let e=tt([t]);return $.Clipper.Area(e[0])}function Z(t){return Math.abs(J(t))}function K(t,e=.01){let i=tt(t);return et($.Clipper.CleanPolygons(i,e))}function Q(t,e=.01){return K([t],e)[0]}function tt(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 et(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 it=1e-6,st="undefined"!=typeof Float32Array?Float32Array:Array;function rt(){var t=new st(16);return st!=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 nt(t,e){var i=new st(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 ot(){var t=new st(3);return st!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function at(t,e,i){var s=new st(3);return s[0]=t,s[1]=e,s[2]=i,s}function lt(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)});function ht(){var t=new st(4);return st!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function ut(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}ot(),function(){var t,e=(t=new st(4),st!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var ct;function dt(){var t=new st(2);return st!=Float32Array&&(t[0]=0,t[1]=0),t}function pt(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}ot(),at(1,0,0),at(0,1,0),ht(),ht(),ct=new st(9),st!=Float32Array&&(ct[1]=0,ct[2]=0,ct[3]=0,ct[5]=0,ct[6]=0,ct[7]=0),ct[0]=1,ct[4]=1,ct[8]=1,function(){var t=dt()}();var ft=Object.defineProperty,mt=(t,e,i)=>(((t,e,i)=>{e in t?ft(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);class gt{constructor(){mt(this,"polygons",[])}clone(){var t=new gt;return t.polygons=this.polygons.map((function(t){return t.clone()})),t}toPolygons(){return this.polygons}union(t){var e=new gt.Node(this.clone().polygons),i=new gt.Node(t.clone().polygons);return e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),gt.fromPolygons(e.allPolygons())}subtract(t){var e=new gt.Node(this.clone().polygons),i=new gt.Node(t.clone().polygons);return e.invert(),e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),e.invert(),gt.fromPolygons(e.allPolygons())}intersect(t){var e=new gt.Node(this.clone().polygons),i=new gt.Node(t.clone().polygons);return e.invert(),i.clipTo(e),i.invert(),e.clipTo(i),i.clipTo(e),e.build(i.allPolygons()),e.invert(),gt.fromPolygons(e.allPolygons())}inverse(){var t=this.clone();return t.polygons.map((function(t){t.flip()})),t}}(t=>{t.fromPolygons=function(e){var i=new t;return i.polygons=e,i},t.cube=function(e){e=e||{};var i=new t.Vector(e.center||[0,0,0]),s=e.radius?e.radius.length?e.radius:[e.radius,e.radius,e.radius]:[1,1,1];return t.fromPolygons([[[0,4,6,2],[-1,0,0]],[[1,3,7,5],[1,0,0]],[[0,1,5,4],[0,-1,0]],[[2,6,7,3],[0,1,0]],[[0,2,3,1],[0,0,-1]],[[4,5,7,6],[0,0,1]]].map((function(e){return new t.Polygon(e[0].map((function(r){let n=1&r?s[0]:-s[0],o=2&r?s[1]:-s[1],a=4&r?s[2]:-s[2],l=new t.Vector(i.x+n,i.y+o,i.z+a);return new t.Vertex(l,new t.Vector(e[1]))})))})))},t.sphere=function(e){e=e||{};var i,s=new t.Vector(e.center||[0,0,0]),r=e.radius||1,n=e.slices||16,o=e.stacks||8,a=[];function l(e,n){e*=2*Math.PI,n*=Math.PI;var o=new t.Vector(Math.cos(e)*Math.sin(n),Math.cos(n),Math.sin(e)*Math.sin(n));i.push(new t.Vertex(s.plus(o.times(r)),o))}for(var h=0;h<n;h++)for(var u=0;u<o;u++)i=[],l(h/n,u/o),u>0&&l((h+1)/n,u/o),u<o-1&&l((h+1)/n,(u+1)/o),l(h/n,(u+1)/o),a.push(new t.Polygon(i));return t.fromPolygons(a)},t.cylinder=function(e){e=e||{};var i=new t.Vector(e.start||[0,-1,0]),s=new t.Vector(e.end||[0,1,0]),r=s.minus(i),n=e.radius||1,o=e.slices||16,a=r.unit(),l=Math.abs(a.y)>.5,h=new t.Vector(l,!l,0).cross(a).unit(),u=h.cross(a).unit(),c=new t.Vertex(i,a.negated()),d=new t.Vertex(s,a.unit()),p=[];function f(e,s,o){var l=s*Math.PI*2,c=h.times(Math.cos(l)).plus(u.times(Math.sin(l))),d=i.plus(r.times(e)).plus(c.times(n)),p=c.times(1-Math.abs(o)).plus(a.times(o));return new t.Vertex(d,p)}for(var m=0;m<o;m++){var g=m/o,y=(m+1)/o;p.push(new t.Polygon([c,f(0,g,-1),f(0,y,-1)])),p.push(new t.Polygon([f(0,y,0),f(0,g,0),f(1,g,0),f(1,y,0)])),p.push(new t.Polygon([d,f(1,y,1),f(1,g,1)]))}return t.fromPolygons(p)};t.Vector=class{constructor(t,e,i){mt(this,"x"),mt(this,"y"),mt(this,"z"),3==arguments.length?(this.x=t,this.y=e,this.z=i):"x"in t?(this.x=t.x,this.y=t.y,this.z=t.z):(this.x=t[0],this.y=t[1],this.z=t[2])}clone(){return new t.Vector(this.x,this.y,this.z)}negated(){return new t.Vector(-this.x,-this.y,-this.z)}plus(e){return new t.Vector(this.x+e.x,this.y+e.y,this.z+e.z)}minus(e){return new t.Vector(this.x-e.x,this.y-e.y,this.z-e.z)}times(e){return new t.Vector(this.x*e,this.y*e,this.z*e)}dividedBy(e){return new t.Vector(this.x/e,this.y/e,this.z/e)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lerp(t,e){return this.plus(t.minus(this).times(e))}length(){return Math.sqrt(this.dot(this))}unit(){return this.dividedBy(this.length())}cross(e){return new t.Vector(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)}};t.Vertex=class{constructor(e,i){mt(this,"pos"),mt(this,"normal"),this.pos=new t.Vector(e),this.normal=new t.Vector(i)}clone(){return new t.Vertex(this.pos.clone(),this.normal.clone())}flip(){this.normal=this.normal.negated()}interpolate(e,i){return new t.Vertex(this.pos.lerp(e.pos,i),this.normal.lerp(e.normal,i))}};class e{constructor(t,e){mt(this,"normal"),mt(this,"w"),this.normal=t,this.w=e}clone(){return new t.Plane(this.normal.clone(),this.w)}flip(){this.normal=this.normal.negated(),this.w=-this.w}splitPolygon(e,i,s,r,n){for(var o=0,a=[],l=0;l<e.vertices.length;l++){var h=(y=this.normal.dot(e.vertices[l].pos)-this.w)<-t.Plane.EPSILON?2:y>t.Plane.EPSILON?1:0;o|=h,a.push(h)}switch(o){case 0:(this.normal.dot(e.plane.normal)>0?i:s).push(e);break;case 1:r.push(e);break;case 2:n.push(e);break;case 3:var u=[],c=[];for(l=0;l<e.vertices.length;l++){var d=(l+1)%e.vertices.length,p=a[l],f=a[d],m=e.vertices[l],g=e.vertices[d];if(2!=p&&u.push(m),1!=p&&c.push(2!=p?m.clone():m),3==(p|f)){var y=(this.w-this.normal.dot(m.pos))/this.normal.dot(g.pos.minus(m.pos)),v=m.interpolate(g,y);u.push(v),c.push(v.clone())}}u.length>=3&&r.push(new t.Polygon(u,e.shared)),c.length>=3&&n.push(new t.Polygon(c,e.shared))}}}mt(e,"EPSILON",1e-5),mt(e,"fromPoints",(function(e,i,s){var r=i.minus(e).cross(s.minus(e)).unit();return new t.Plane(r,r.dot(e))})),t.Plane=e;t.Polygon=class{constructor(e,i){mt(this,"vertices"),mt(this,"shared"),mt(this,"plane"),this.vertices=e,this.shared=i,this.plane=t.Plane.fromPoints(e[0].pos,e[1].pos,e[2].pos)}clone(){var e=this.vertices.map((function(t){return t.clone()}));return new t.Polygon(e,this.shared)}flip(){this.vertices.reverse().map((function(t){t.flip()})),this.plane.flip()}};t.Node=class{constructor(t){mt(this,"plane",null),mt(this,"front",null),mt(this,"back",null),mt(this,"polygons",[]),t&&this.build(t)}clone(){var e=new t.Node;return e.plane=this.plane&&this.plane.clone(),e.front=this.front&&this.front.clone(),e.back=this.back&&this.back.clone(),e.polygons=this.polygons.map((function(t){return t.clone()})),e}invert(){for(var t,e=0;e<this.polygons.length;e++)this.polygons[e].flip();null==(t=this.plane)||t.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var i=this.front;this.front=this.back,this.back=i}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);return this.front&&(e=this.front.clipPolygons(e)),i=this.back?this.back.clipPolygons(i):[],e.concat(i)}clipTo(t){this.polygons=t.clipPolygons(this.polygons),this.front&&this.front.clipTo(t),this.back&&this.back.clipTo(t)}allPolygons(){var t=this.polygons.slice();return this.front&&(t=t.concat(this.front.allPolygons())),this.back&&(t=t.concat(this.back.allPolygons())),t}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))}}}})(gt||(gt={}));var yt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function vt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function xt(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 bt={exports:{}};function _t(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=wt(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=wt(t,e[r]*s,r<n-1?e[r+1]*s:t.length,s,!1))===o.next&&(o.steiner=!0),a.push(Rt(o));for(a.sort(Ct),r=0;r<a.length;r++)i=Mt(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 Pt(d,p,i,s,r,h,0),p}function wt(t,e,i,s,r){var n,o;if(r===zt(t,e,i,s)>0)for(n=e;n<i;n+=s)o=Wt(n,t[n],t[n+1],o);else for(n=i-s;n>=e;n-=s)o=Wt(n,t[n],t[n+1],o);return o&&Dt(o,o.next)&&(Yt(o),o=o.next),o}function Et(t,e){if(!t)return t;e||(e=t);var i,s=t;do{if(i=!1,s.steiner||!Dt(s,s.next)&&0!==Ft(s.prev,s,s.next))s=s.next;else{if(Yt(s),(s=e=s.prev)===s.next)break;i=!0}}while(i||s!==e);return e}function Pt(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=Ot(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?It(t,s,r,n):Tt(t))e.push(a.i/i|0),e.push(t.i/i|0),e.push(l.i/i|0),Yt(t),t=l.next,h=l.next;else if((t=l)===h){o?1===o?Pt(t=At(Et(t),e,i),e,i,s,r,n,2):2===o&&St(t,e,i,s,r,n):Pt(Et(t),e,i,s,r,n,1);break}}}function Tt(t){var e=t.prev,i=t,s=t.next;if(Ft(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&&Lt(r,a,n,l,o,h,f.x,f.y)&&Ft(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function It(t,e,i,s){var r=t.prev,n=t,o=t.next;if(Ft(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=Ot(p,f,e,i,s),v=Ot(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&&Lt(a,u,l,c,h,d,x.x,x.y)&&Ft(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&&Lt(a,u,l,c,h,d,b.x,b.y)&&Ft(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&&Lt(a,u,l,c,h,d,x.x,x.y)&&Ft(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&&Lt(a,u,l,c,h,d,b.x,b.y)&&Ft(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function At(t,e,i){var s=t;do{var r=s.prev,n=s.next.next;!Dt(r,n)&&Bt(r,s,s.next,n)&&Xt(r,n)&&Xt(n,r)&&(e.push(r.i/i|0),e.push(s.i/i|0),e.push(n.i/i|0),Yt(s),Yt(s.next),s=t=n),s=s.next}while(s!==t);return Et(s)}function St(t,e,i,s,r,n){var o=t;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&kt(o,a)){var l=Ht(o,a);return o=Et(o,o.next),l=Et(l,l.next),Pt(o,e,i,s,r,n,0),void Pt(l,e,i,s,r,n,0)}a=a.next}o=o.next}while(o!==t)}function Ct(t,e){return t.x-e.x}function Mt(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&&Lt(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),Xt(s,t)&&(l<d||l===d&&(s.x>i.x||s.x===i.x&&Nt(i,s)))&&(i=s,d=l)),s=s.next}while(s!==h);return i}(t,e);if(!i)return e;var s=Ht(i,t);return Et(s,s.next),Et(i,i.next)}function Nt(t,e){return Ft(t.prev,t,e.prev)<0&&Ft(e.next,t,t.next)<0}function Ot(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 Rt(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 Lt(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 kt(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&&Bt(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(Xt(t,e)&&Xt(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)&&(Ft(t.prev,t,e.prev)||Ft(t,e.prev,e))||Dt(t,e)&&Ft(t.prev,t,t.next)>0&&Ft(e.prev,e,e.next)>0)}function Ft(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function Dt(t,e){return t.x===e.x&&t.y===e.y}function Bt(t,e,i,s){var r=Gt(Ft(t,e,i)),n=Gt(Ft(t,e,s)),o=Gt(Ft(i,s,t)),a=Gt(Ft(i,s,e));return r!==n&&o!==a||(!(0!==r||!Ut(t,i,e))||(!(0!==n||!Ut(t,s,e))||(!(0!==o||!Ut(i,t,s))||!(0!==a||!Ut(i,e,s)))))}function Ut(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 Gt(t){return t>0?1:t<0?-1:0}function Xt(t,e){return Ft(t.prev,t,t.next)<0?Ft(t,e,t.next)>=0&&Ft(t,t.prev,e)>=0:Ft(t,e,t.prev)<0||Ft(t,t.next,e)<0}function Ht(t,e){var i=new $t(t.i,t.x,t.y),s=new $t(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 Wt(t,e,i,s){var r=new $t(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 Yt(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 $t(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 zt(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}bt.exports=_t,bt.exports.default=_t,_t.deviation=function(t,e,i,s){var r=e&&e.length,n=r?e[0]*i:t.length,o=Math.abs(zt(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(zt(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)},_t.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 Vt=vt(bt.exports);let jt=new class extends P{error(...t){this.levels.includes("errors")&&(t.length>0&&(t[0]="Internal error: "+t[0]),console.error(...t))}}(["info","warnings","errors"]);class qt{constructor(t){this.spaceGraph=null,this.type=t}}class Jt extends qt{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)}}const Zt="material:color";class Kt extends Jt{constructor(t,e=[1,1,1],i=1){super(t,Zt),this.color=[...e],this.opacity=i}}const Qt="material:standard";class te extends Jt{constructor(t,e){super(t,Qt),this.reference=e}}class ee extends Jt{constructor(t,e,i){super(t,ie),this.reference=e,this.format=i}}const ie="material:basic";class se extends Jt{constructor(t){super(t,ie),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}}const re=[1,1,1,1];function ne(t,e){return Number.isFinite(t)?!(t<0||t>1)||(jt.warn(`Value out of range (0 to 1) in color literal: '${e}'.`),!1):(jt.warn(`Invalid float value in color literal: '${e}'.`),!1)}function oe(t,e){return Number.isInteger(t)?!(t<0||t>255)||(jt.warn(`Value out of range (0 to 255) in color literal: '${e}'.`),!1):(jt.warn(`Invalid byte value in color literal: '${e}'.`),!1)}function ae(t,e){if(!t.endsWith(")"))return jt.warn(`Missing closing parenthesis: '${t}'.`),re;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 jt.warn(`Invalid number of components in color literal: '${t}'.`),re;let r=[0,0,0,0];for(let n=0;n<3;n++){let e=s[n],i=parseFloat(e);if(!oe(i,t))return re;r[n]=i/255}if(4===s.length){let e=parseFloat(s[3]);if(!ne(e,t))return re;r[3]=e}else r[3]=re[3];return r}function le(t){let[e,i,s,r]=[1,1,1,1];return Array.isArray(t)?[e,i,s,r]=function(t){if(t.length<3||t.length>4)return jt.warn(`Invalid number of components in color literal: '${t}'.`),re;let e=t.toString(),i=[0,0,0,0];for(let s=0;s<t.length;s++){let r=t[s];if(!ne(r,e))return re;i[s]=r}return 3===t.length&&(i[3]=re[3]),i}(t):"string"==typeof t&&([e,i,s,r]=[1,1,1,1],""===t?jt.warn("Empty string not a valid color literal."):t.startsWith("#")?[e,i,s,r]=function(t){let e,i,s,r,n=t.substring(1),o=parseInt(n,16);if(isNaN(o))return jt.warn(`Invalid hexadecimal color literal: '${t}'.`),re;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 jt.warn(`Invalid hexademical color literal length: '${t}'.`),re;e=(o>>24&255)/255,i=(o>>16&255)/255,s=(o>>8&255)/255,r=(255&o)/255}return[e,i,s,r]}(t):t.startsWith("rgb(")?[e,i,s,r]=ae(t,!1):t.startsWith("rgba(")?[e,i,s,r]=ae(t,!0):jt.warn(`String ${t} not a valid color literal.`)),[e,i,s,r]}function he(t,e){return[t[0]+e[0],t[1]+e[1]]}function ue(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 ce(t,e){return t[0]*e[1]-t[1]*e[0]}function de(t){return Math.sqrt(function(t){return t[0]*t[0]+t[1]*t[1]}(t))}function pe(t,e){return de(ve(e,t))}function fe(t,e,i){return[t[0]+i*(e[0]-t[0]),t[1]+i*(e[1]-t[1])]}function me(t){let e=de(t);return[t[0]/e,t[1]/e]}function ge(t){return[-t[1],t[0]]}function ye(t,e){return[t[0]*e,t[1]*e]}function ve(t,e){return[t[0]-e[0],t[1]-e[1]]}function xe(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function be(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function _e(t,e,i){let s=ce(ve(e,t),ve(i,t));return s>1e-7?1:s<-1e-7?-1:0}function we(t,e){return ue([e[0]-t[0],e[1]-t[1]])}function Ee(t,e,i,s){let r=ve(e,t),n=ve(s,i),o=function(t,e){return t[0]*e[0]+t[1]*e[1]}(r,n),a=ce(r,n);return Math.atan2(Math.abs(a),o)}function Pe(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 Te(t,e){if(!Pe(t,e[0]))return!1;for(let i=1;i<e.length;i++){if(Pe(t,e[i]))return!1}return!0}function Ie(t,e,i){return function(t,e,i){const s=ve(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:fe(e,i,o)}const o=ve(n,t);return o[0]*o[0]+o[1]*o[1]}(t,e,i)**.5}function Ae(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 Se(t){return Math.abs(Ae(t))}function Ce(t,e){return(t%e+e)%e}function Me(t,e,i){if(0!==t[0]||0!==t[1]||0!==t[2]||0!==e){let s=rt(),r=at(t[0],t[1],t[2]),n=function(t=0,e=[0,1,0]){let i=t*Math.PI/180,s=ht();return ut(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 rt()}function Ne(t){let e=ot(),i=ht();!function(t,e){t[0]=e[12],t[1]=e[13],t[2]=e[14]}(e,t),nt(i,t);let s=ot(),r=(n=s,o=i,a=2*Math.acos(o[3]),(l=Math.sin(a/2))>it?(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 Oe(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 st(6);return st!=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 Re(t,e){return function(t,e){let i=pt(dt(),t.position,e),s=t.rotation+Math.atan2(-e[1],e[0])*(180/Math.PI);return{position:[i[0],i[1]],rotation:Ce(s,360)}}(t,Oe(e))}function Le(t){let e=Oe(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=pt(dt(),dt(),t),i=Math.atan2(-t[1],t[0])*(180/Math.PI);return{position:[e[0],e[1]],rotation:Ce(i,360)}}(e)}function ke(t,e){return t.map((t=>{let{position:i}=Re({position:t,rotation:0},e);return i}))}class Fe{constructor(){this.vertices=[],this.edges=[],this.geometryProfile=[]}}var De,Be=new Uint8Array(16);function Ue(){if(!De&&!(De="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return De(Be)}const Ge=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var Xe=[],He=0;He<256;++He)Xe.push((He+256).toString(16).substr(1));function We(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=(Xe[t[e+0]]+Xe[t[e+1]]+Xe[t[e+2]]+Xe[t[e+3]]+"-"+Xe[t[e+4]]+Xe[t[e+5]]+"-"+Xe[t[e+6]]+Xe[t[e+7]]+"-"+Xe[t[e+8]]+Xe[t[e+9]]+"-"+Xe[t[e+10]]+Xe[t[e+11]]+Xe[t[e+12]]+Xe[t[e+13]]+Xe[t[e+14]]+Xe[t[e+15]]).toLowerCase();if(!function(t){return"string"==typeof t&&Ge.test(t)}(i))throw TypeError("Stringified UUID is invalid");return i}function Ye(t,e,i){var s=(t=t||{}).random||(t.rng||Ue)();return s[6]=15&s[6]|64,s[8]=63&s[8]|128,We(s)}class $e extends Jt{constructor(t,e){super(t,e),this.layout=null}}class ze extends $e{}class Ve extends ze{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=ue([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 jt.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)}}function je(t,e,i,s,r=!1){if(e.layout)return jt.warn(`${s} ${e.id} already part of layout ${e.layout.id}.`),!1;if(i[e.id])return jt.error(`${s} ${e.id} already registered in layout.`),!1;let n=t.spaceGraph;if(n&&n.nodesById[e.id])return jt.error(`${s} ${e.id} already registered in space graph.`),!1;if(e.type.startsWith("space:")){let t=e;if(t.slabs.length>0)return jt.warn(`Detached space ${t.id} references boundary slab elements.`),!1}else if(e.type.startsWith("element:")){let n=e;if(r&&n.parent)return jt.warn(`${s} ${n.id} already a child of ${s} ${n.parent.id}.`),!1;for(let e of n.elements)if(!je(t,e,i,s,!1))return!1}return!0}function qe(t,e){if(e.layout=t,t.elementsById[e.id])return void jt.error(`Element ${e.id} already registered.`);t.elementsById[e.id]=e,t.elementsByType[e.type]||(t.elementsByType[e.type]=[]),t.elementsByType[e.type].push(e);let i=t.spaceGraph;i&&("element:asset"===e.type&&e.product&&!i.productsById[e.product.id]&&i.insertProduct(e.product),i.registerNode(e),i.emit("element-create",e));for(let s of e.elements)qe(t,s)}function Je(t,e){for(let n of e.elements)Je(t,n);if(t.elementsById[e.id]!==e)return void jt.error(`Entry ${e.id} in 'elements stored by ID' record does not contain this object.`);delete t.elementsById[e.id];let i=t.elementsByType[e.type],s=null==i?void 0:i.indexOf(e);if(!i||-1===s)return void jt.error(`element ${e.id} not found in 'elements stored by type' record.`);t.elementsByType[e.type].splice(s,1);let r=t.spaceGraph;r&&(r.unregisterNode(e),r.emit("element-delete",e)),e.layout=null}function Ze(t){return"object"==typeof t&&null!==t}function Ke(t){return Ze(t)&&!function(t){return Array.isArray(t)||ArrayBuffer.isView(t)}(t)}function Qe(t,e,i,s){Ke(t)&&Ke(e)||jt.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)){jt.warn(`Key '${l}' not found in scope ${i}, skipped.`);continue}}let a=e[l],h=t[l];if(Ze(a)){let e=`${i}.${l}`;!(null==n?void 0:n.includes(e))&&Ke(h)?Qe(h,a,e,s):t[l]=o?JSON.parse(JSON.stringify(a)):a}else t[l]=a}}function ti(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:[]},Qe(t,e,"",{onNewKeys:s,copyScopes:i.copyScopes??[],cloneObjects:i.cloneObjects??!0})}const ei=["element:ceiling","element:floor","element:boundaryWall","element:curtainWall","element:spaceDivider","element:wall","element:opening","element:asset","element:beam","element:casework","element:column","element:door","element:generic","element:kitchen","element:railing","element:ramp","element:roof","element:slab","element:stairs","element:stairFlight","element:window"];class ii extends $e{constructor(){super(...arguments),this.parent=null,this.elements=[],this.geometries=[]}insertElement(t){let e=this.layout;e&&!je(e,t,e.elementsById,"Element",!0)||(t.parent=this,this.elements.push(t),e&&qe(e,t))}getTransform(){return{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}getBoundingBox(t=!1){return{min:[0,0,0],max:[0,0,0],transform:{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]}}}removeElement(t){if(t.parent!==this)return void jt.warn(`Element ${t.id} not a child of element ${this.id}.`);let e=this.elements.indexOf(t);-1!==e?(t.parent=null,this.elements.splice(e,1),t.layout&&Je(t.layout,t)):jt.error(`Element ${t.id} not found in parent ${this.id}.`)}copyForClone(t){super.copyForClone(t),this.parameters=JSON.parse(JSON.stringify(t.parameters)),this.geometries=JSON.parse(JSON.stringify(t.geometries))}setParameters(t){ti(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("element-parameters-change",this)}getSpaces(){return this.parent?this.parent.getSpaces():[]}}function si(t,e,i){let s=t.edge,r=s.vertices[0],n=s.vertices[1],o=r.position,a=de(ve(n.position,o)),l=[];for(let h of t.elements)if("element:opening"===h.type){let t=h.parameters.position[0],s=t/a,r=(t+h.parameters.dimensions[0])/a;i?e>=s&&e<r&&l.push(h):e>s&&e<r&&l.push(h)}return l}class ri extends ii{constructor(t,e,i){super(t,e),this.edge=i}getVertices(){return[this.edge.vertices[0],this.edge.vertices[1]]}getEdges(){return[this.edge]}getAdjacentElementsByVertex(){let t=[[],[]];for(let e=0;e<2;e++){let i=this.edge.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.edge].filter((t=>t.spaces[e])).map((t=>t.spaces[e]));t[e]=i}return t}getSpaces(){let t=[],e=this.edge;return e.spaces[0]&&t.push(e.spaces[0]),e.spaces[1]&&t.push(e.spaces[1]),t}getElementsAtLinearPosition(t){return si(this,t,!0)}}function ni(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 oi extends ze{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]}setVertices(t,e){if(t===e)return void jt.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,(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 jt.error(`Cannot find vertex ${t}.`);let r=i.verticesById[e];r?this.setVertices(s,r):jt.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=this.vertices[0],s=this.vertices[1],r=e.position,n=s.position,o=fe(r,n,t),a=de(ve(o,r)),l=de(ve(o,n));if(a<i||l<i)return!1}else if(t<=0||t>=1)return!1;if(this.element){return 0===si(this.element,t,!1).length}return!0}split(t,e={},i=!1){let s=this.layout.spatialGraph,r=this.vertices[0],n=this.vertices[1],o=r.position,a=n.position,l=fe(o,a,t),h=e.vertexId??(this.layout.debugIds?s.debugVertexCount.toString():Ye()),u=s.verticesById[h]??s.createVertex(h,l[0],l[1]);this.setVertices(r,u);let c=e.edgeId??s.getEdgeId(),d=s.createEdge(c,u,n);if(d.spaces[0]=this.spaces[0],d.spaces[1]=this.spaces[1],d.boundaryWalls[0]=this.boundaryWalls[0],d.boundaryWalls[1]=this.boundaryWalls[1],this.element){let i=e.elementId??this.layout.getElementId(this.element),s=this.layout.createElement(this.element.type,i,d);s.parameters=JSON.parse(JSON.stringify(this.element.parameters));let r=de(ve(a,o)),n=de(ve(a,l)),h=[...this.element.elements];for(let e of h)if("element:opening"===e.type){let i=e.parameters.position[0],o=i/r,a=(i+e.parameters.dimensions[0])/r;if(t<=o){let i=(o-t)/(1-t);e.parameters.position[0]=i*n,this.element.removeElement(e),s.insertElement(e)}else t<a&&jt.warn(`Opening ${e.id} overlaps split position.`)}}if(i)for(let p of d.spaces){if(!p)continue;let{boundary:t}=p.getBoundaryFromEdge(this);if(t){let e,i=t.vertices.indexOf(r),o=t.vertices.indexOf(n);e=0===i&&o===t.vertices.length-1?o:0===o&&i===t.vertices.length-1||i<o?i:o,t.vertices.splice(e+1,0,u),t.edges=[];for(let r=0;r<t.vertices.length;r++){let e=r,i=r<t.vertices.length-1?r+1:0,n=t.vertices[e],o=t.vertices[i],a=s.getEdgeFromVertices(n,o);a?t.edges.push(a):jt.error(`Cannot find edge with vertices ${n.id} and ${o.id}.`)}}else jt.error(`Edge ${this.id} not found in space boundary.`)}for(let p of d.boundaryWalls){if(!p)continue;let t,e=p.boundaries[0],i=e.vertices.indexOf(r),o=e.vertices.indexOf(n);t=0===i&&o===e.vertices.length-1?o:0===o&&i===e.vertices.length-1||i<o?i:o,e.vertices.splice(t+1,0,u),e.edges=[];for(let r=0;r<e.vertices.length;r++){let t=r,i=r<e.vertices.length-1?r+1:0,n=e.vertices[t],o=e.vertices[i],a=s.getEdgeFromVertices(n,o);a?e.edges.push(a):jt.error(`Cannot find edge with vertices ${n.id} and ${o.id}.`)}}return{vertex:u,edge:d,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!==_e(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){if(this.element&&!t.element||!this.element&&t.element)return void jt.warn("Either none or both edges must have an element, cannot merge.");let i,s,r=this.layout.spatialGraph,n=this.vertices[0],o=this.vertices[1],a=t.vertices[0],l=t.vertices[1];if(n===a)i=[l,n,o],s=!0;else if(n===l)i=[a,n,o],s=!1;else if(o===a)i=[n,o,l],s=!1;else{if(o!==l)return void jt.warn(`Edge ${this.id} does not share a vertex with edge ${t.id}, cannot merge.`);i=[n,o,a],s=!0}let h=i[0].position,u=i[1].position;if(0!==_e(h,u,i[2].position))return void jt.warn(`Edges ${this.id} and ${t.id} are not collinear, cannot merge.`);let c=i[1];if(c.edges.includes(this)&&c.edges.includes(t)||jt.error(`Common vertex ${c.id} edge list does not contain either one or both edges, cannot merge.`),t.element&&s&&function(t){let e=t.edge,[i,s]=e.getPoints(),r=de(ve(s,i));for(let n of t.elements){if("element:opening"!==n.type)continue;let t=n.parameters;t.position[0]=r-(t.position[0]+t.dimensions[0]),ni(n)}}(t.element),this.element&&t.element){let e=de(ve(u,h)),i=[...t.element.elements];for(let s of i){if("element:opening"!==s.type)continue;t.element.removeElement(s),this.element.insertElement(s),s.parameters.position[0]+=e}}if(this.setVertices(i[0],i[2]),e)for(let d of t.spaces){if(!d)continue;let{boundary:e,edgeIndex:s}=d.getBoundaryFromEdge(t);if(e){e.edges.splice(s,1);let t=e.vertices.indexOf(i[1]);t>-1?e.vertices.splice(t,1):jt.error(`Cannot find vertex ${i[1].id} in space ${d.id}`)}else jt.error(`Cannot find edge ${t.id} in space ${d.id}.`)}for(let d of t.boundaryWalls){if(!d)continue;let e=d.boundaries[0],s=e.edges.indexOf(t);if(s>-1){e.edges.splice(s,1);let t=e.vertices.indexOf(i[1]);t>-1?e.vertices.splice(t,1):jt.error(`Cannot find vertex ${i[1].id} in boundary wall ${d.id}`)}else jt.error(`Cannot find edge ${t.id} in boundary wall ${d.id}.`)}t.spaces[0]=null,t.spaces[1]=null,t.boundaryWalls[0]=null,t.boundaryWalls[1]=null,r.removeEdge(t),0===c.edges.length&&r.removeVertex(c)}}const ai={usage:"generic",program:"none"};class li extends $e{constructor(t,e){super(t,"layout:space"),this.boundaries=[],this.slabs=[],this.attributes={...ai},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 jt.error(`ID ${t} already in use in layout ${e.id}.`);if(e&&e.spacesById[this.id]!==this)return void jt.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 jt.error(`ID ${t} already in use in space graph object.`);if(i&&i.nodesById[this.id]!==this)return void jt.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)}getArea(){let t=this.geometry.polygons;if(0===t.length)return jt.error(`Geometry has not been computed for space ${this.id}.`),0;let e=Se(t[0]);for(let i=1;i<t.length;i++){e-=Se(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=>{let e=t.parent.edge;return e.spaces[0]===this||e.spaces[1]===this},i=t&&(Array.isArray(t)?t:[t]),s=[],r=this.layout.getElementList();for(let n of r){if(i&&!i.includes(n.type))continue;let t;switch(n.type){case"element:ceiling":case"element:floor":t=n.space===this;break;case"element:boundaryWall":break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":let i=n.edge;t=i.spaces[0]===this||i.spaces[1]===this;break;case"element:opening":t=e(n);break;case"element:door":case"element:window":t=e(n.parent);break;default:let s=n;t=Te([s.position[0],s.position[2]],this.geometry.polygons)}t&&s.push(n)}return s}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=z([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]}}}attachSlab(t){if(null!==t.space)return void jt.warn(`Boundary slab ${t.id} already attached to space ${t.space.id}.`);this.slabs.indexOf(t)>-1?jt.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 jt.warn(`Boundary slab ${t.id} not attached to space ${this.id}.`);let e=this.slabs.indexOf(t);-1!==e?(t.space=null,t.boundaries=ki(this.boundaries),this.slabs.splice(e,1)):jt.warn(`Boundary slab ${t.id} not referenced by space ${this.id}.`)}}class hi extends ii{constructor(t,e,i){super(t,e),this.boundaries=ki(i)}getBoundingBox(){const t=[0,0,0],e=[0,0,0],i=z([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 ui={top:"#202020",bottom:"#000000",side1:"asm:basic-wall",side2:"asm:basic-wall",join1:"asm:basic-wall",join2:"asm:basic-wall"},ci={width:.15,height:3,offset:0,elevation:0,materials:{...ui}};class di extends ri{constructor(t,e){super(t,"element:wall",e),e.element=this,this.parameters=JSON.parse(JSON.stringify(ci)),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.edge.getPoints(),r={position:i,rotation:-(we(i,s)/Math.PI*180)},n={position:[i[0],0,i[1]],rotation:r.rotation,rotationAxis:[0,1,0]},o=z([ke(this.geometryProfile.points,Le(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 pi={"element:ceiling":{height:.2,elevation:ci.elevation+ci.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 fi extends hi{constructor(t,e,i){super(t,e,i);let s=pi[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 mi(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=j([r],V(n))}else s=V([r,...n]);return s=s.filter((t=>Z(t)>1e-7)),0===s.length?(jt.warn("No valid polygons, returning boundary polygon."),r):(s=K(s,.001),s=s.filter((t=>t.length>0)),0===s.length?(jt.warn("No valid polygons after filtering, returning boundary polygon."),r):(s.length>1&&(jt.warn(`Result has ${s.length} polygons, returning largest one.`),s=s.sort(((t,e)=>Z(e)-Z(t)))),s[0]))}function gi(t,e){var i;let s=[mi(e.boundaries[0],!0)];for(let o=1;o<e.boundaries.length;o++){s=j(s,[mi(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(Te(fe(t,r,.5),s)){let t=o.element.geometryProfile.points;n.push(t)}}n.length>0&&(s=j(s,n)),s.sort(((t,e)=>{let i=Z(t);return Z(e)-i})),e.geometry.polygons=s}function yi(t,e){return new Array(e-t).fill(void 0).map(((e,i)=>t+i))}function vi(t){return`${t.type.split(":")[1]}Geometry-${t.id.substring(0,8)}`}function xi(t){let e;switch(t.type){case"curve:rectangle":e=4;break;case"curve:polygon":e=t.points.length;break;case"curve:composite":e=t.segments.reduce(((t,e)=>t+xi(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 bi(){let t=Math.random(),e=Math.random(),i=Math.random();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 _i(t,e=!1){let i,s=t.parameters.materials,r="element:floor"===t.type?-t.parameters.height:0,n=t.parameters.elevation+r;for(let o=0;o<t.boundaries.length;o++){let r=t.boundaries[o].geometryProfile.slice(),a=0===o?"boundary":"hole-"+o,l={id:`boundarySlabGeometry-${t.id}-${a}`,type:"geometry:extrusion",position:[0,n,0],height:t.parameters.height,profile:{type:"curve:polygon",points:r},geometries:[]},h={top:[0],bottom:[1],sides:yi(2,2+r.length)},u={top:e?bi():s.top,bottom:s.bottom,sides:s.sides};l.surfaces=h,l.materials=u,0===o?(i=l,t.geometries=[{type:"reference:geometry",geometry:l}]):i.geometries.push({type:"csg:subtract",geometry:l})}t.emit("geometry-update",t)}function wi(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";jt.error(`Edge ${s.id} already references a space on its ${t} side.`)}}}}function Ei(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]?jt.error(`Edge ${i.id} referenced by more than two adjacent nodes.`):i.boundaryWalls[1]=t:i.boundaryWalls[0]=t}function Pi(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)}Ni(e)}function Ti(t,e){if(0!==e.boundaries.length){for(let i of e.boundaries)Pi(t,i);switch(e.type){case"element:boundaryWall":Ei(e);break;case"element:ceiling":case"element:floor":{let i=function(t,e,i){for(const s of t.spaces){if(s.boundaries.length!==e.length)continue;let t=0;for(;t<s.boundaries.length;){if(!Oi(s.boundaries[t],e[t]))break;t++}if(t===s.boundaries.length)return s}return}(t,e.boundaries);i?i.attachSlab(e):jt.warn(`Matching space not found for boundary slab element ${e.id}.`);break}}}else jt.warn(`Boundary slab element ${e.id} does not specify boundaries.`)}function Ii(t,e){let i=t.spatialGraph,s=i.edgesById[e.edge.id];s?e.edge=s:i.insertEdge(e.edge),function(t){null===t.edge.element?t.edge.element=t:t.edge.element!==t&&jt.error(`Edge ${t.edge.id} referenced by more than one edge element.`)}(e)}function Ai(t){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):jt.warn(`Boundary slab element ${t.id} not attached to a space.`);break}}}(t);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":t.edge.element=null}}function Si(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 Ci(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 jt.warn(`Could not add edge ${s.id} to current path.`);e.push(n)}}return e}function Mi(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 Ni(t){let e=Ci(t.edges);if(!e)return!1;if(t.vertices=e,t.geometryProfile=t.vertices.map((t=>t.position)),!(Ae(t.geometryProfile)>0)){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 Oi(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 Ri(t,e,i){if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++){if(!Oi(t[s],e[s]))return!1}return!0}function Li(t){let e=new Fe;return e.vertices=[...t.vertices],e.edges=[...t.edges],e.geometryProfile=JSON.parse(JSON.stringify(t.geometryProfile)),e}function ki(t){let e=[];for(let i of t){let t=Li(i);e.push(t)}return e}function Fi(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:jt.warn(`Edge ${s.id} not in space ${e.id} boundary.`)}function Di(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 jt.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=Mi(c).concat(s),f=Mi(d).concat(s),m=c.map((t=>t.position)),g=d.map((t=>t.position)),y=new Fe;y.vertices=c,y.edges=p,y.geometryProfile=m;let v=new Fe;return v.vertices=d,v.edges=f,v.geometryProfile=g,[y,v]}(t.boundaries[0],e,i,s);if(!r)return void jt.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(Pe(i,r[0].geometryProfile))n.push(e);else{if(!Pe(i,r[1].geometryProfile)){jt.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=Ye(),l=Ye());let u=new li(a,n),c=new li(l,o);for(let f of n)Fi(f,t,u);for(let f of o)Fi(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);gi(h,u),gi(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=Ye(),i=Ye();let r=new fi(e,s.type,n),u=new fi(i,s.type,o);_i(r,!0),_i(u,!0),d.push(r),p.push(u)}return{spaces:[u,c],slabs:[d,p]}}function Bi(t,e){let{position:i,rotation:s,rotationAxis:r}=t.getTransform(),n=Me(i,s,r);return e&&function(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];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}(n,e,n),n}function Ui(t){let e;return t.parent&&(e=Ui(t.parent)),Bi(t,e)}function Gi(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 Xi{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;jt.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;jt.error(`Entry ${i.id} in 'edges by id' record does not contain this object.`)}insertVertex(t){if(!je(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 jt.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 jt.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);jt.error(`Entry ${t} in 'vertices by id' record does not contain this object.`)}insertEdge(t,e=!1){if(!je(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=Di(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 jt.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 jt.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 jt.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);jt.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:Ye()}getEdgeId(t){return this.layout.debugIds?(t??"edge-")+this.debugEdgeCount:Ye()}createVertex(t,e,i){let s=new Ve(t,e,i);return this.insertVertex(s),s}createEdge(t,e,i,s=!1){let r=new oi(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)}}const Hi={height:3,elevation:0,surfaces:{top:[0],bottom:[1],sides:"..."},materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class Wi extends hi{constructor(t,e){super(t,"element:boundaryWall",e),this.parameters=JSON.parse(JSON.stringify(Hi))}setParameters(t){super.setParameters(t)}}const Yi={materials:{}};class $i extends ri{constructor(t,e){super(t,"element:curtainWall",e),e.element=this,this.parameters=JSON.parse(JSON.stringify(Yi))}setParameters(t){super.setParameters(t)}}const zi={materials:{}};class Vi extends ri{constructor(t,e){super(t,"element:spaceDivider",e),e.element=this,this.parameters=JSON.parse(JSON.stringify(zi))}setParameters(t){super.setParameters(t)}getBoundingBox(){const[t,e]=this.edge.getPoints(),i=pe(t,e),s=we(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 ji extends ii{constructor(t,e){super(t,e)}}function qi(t,e){let i=t.parameters.width,s=t.parameters.offset,r=t.edge.vertices[0],n=t.edge.vertices[1],o=r.position,a=n.position,l=ve(a,o),h=de(l),u=fe(o,a,e.parameters.position[0]/h);u=he(u,ye(ge(me(l)),-.5*i+s));let c=e.parameters.position[1];return{position:[u[0],c,u[1]],rotation:180*-ue(ve(a,o))/Math.PI}}function Ji(t,e,i,s){let r=s.parameters.dimensions[0],n=s.parameters.dimensions[1],o=e.parameters.width,{position:a,rotation:l}=qi(e,s),h=s.parameters.materials,u={id:i,type:"geometry:cuboid",position:a,rotation:l,dimensions:[r,n,o],surfaces:{top:[0],bottom:[1],frontBack:[2,4],sides:[3,5]}},c={top:h.top,bottom:h.bottom,frontBack:"#FFFFFF",sides:h.sides};u.materials=c;let d=e.geometries[0].geometry;d.geometries??(d.geometries=[]),d.geometries.push({type:"csg:subtract",geometry:u}),s.emit("geometry-update",s)}function Zi(t,e){let i,s={},r=yi(0,e);for(let[n,o]of Object.entries(t))if("string"==typeof o)"..."===o?i=n:jt.warn("Invalid surface definition string.");else if(Array.isArray(o)){s[n]=[];for(let t of o){if(t<0||t>=e){jt.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)):jt.warn(`Face index ${t} already assigned when defining surface ${n}.`)}}else jt.warn("Invalid surface definition.");return i&&r.length>0&&(s[i]=r),s}function Ki(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=Ci(n.edges);if(!a)return void jt.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=Zi(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 Qi(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=vi(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 ts(t,e,i){let s=vi(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),E=[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],P=[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<P.length;T+=3){let t=P[T+1];P[T+1]=P[T+2],P[T+2]=t}return{id:t,type:"geometry:mesh",vertices:E,indices:P,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 es(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}}}(vi(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=ts(t,s,{...n,radius:e,angle:i,circulation:r})}t.geometries=[o],t.emit("geometry-update",t)}function is(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?bi():h.top??ui.top,bottom:h.bottom??ui.bottom,side1:h.side1??ui.side1,side2:h.side2??ui.side2},[d,p]=function(t){let e=[!1,!1];for(let i=0;i<t.edge.vertices.length;i++){let s=t.edge.vertices[i],r=s.edges.filter((t=>{var e;return"element:wall"===(null==(e=t.element)?void 0:e.type)})).map((t=>t.element));if(1===r.length)e[i]=!0;else if(r.length>0){let n=t.parameters.height,o=t.parameters.elevation;for(let a of r){if(a===t)continue;if(a.parameters.height!==n||a.parameters.elevation!==o){e[i]=!0;break}let r=t.edge.vertices[1]===s?1:-1,l=a.edge.vertices[0]===s?1:-1;if(r*(t.parameters.offset/t.parameters.width)!=l*(a.parameters.offset/a.parameters.width)){e[i]=!0;break}}}else jt.error(`Vertex ${s.id} not referencing edge that references it.`)}return e}(t);d&&(u.join1=[3],c.join1=h.join1??ui.join1),p&&(u.join2=[5],c.join2=h.join2??ui.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);Ji(t.layout,t,i,e)}t.emit("geometry-update",t)}function ss(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=vi(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=be(t,[0,.01,0]),s=be(e,i),r=xe(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=vi(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=xi(e);o.surfaces={top:[0],bottom:[1],sides:yi(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":_i(t);break;case"element:boundaryWall":Ki(t);break;case"element:door":!function(t){let{height:e,length:i,frameThickness:s,frameDepth:r,materials:n}=t.parameters,o=vi(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},...Qi(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=xi(e),n={id:vi(t),type:"geometry:extrusion",position:[0,0,0],profile:e,height:i,surfaces:{top:[0],bottom:[1],sides:yi(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=vi(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:vi(t),type:"geometry:extrusion",position:[0,0,0],profile:e,height:i},n=xi(e);r.surfaces={top:[0],bottom:[1],sides:yi(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":es(t);break;case"element:wall":is(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=vi(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)ss(e)}const rs={position:[0,0],dimensions:[1,2],materials:{top:"#FFFFFF",bottom:"#FFFFFF",sides:"#FFFFFF"}};class ns extends ji{constructor(t){super(t,"element:opening"),this.parameters=JSON.parse(JSON.stringify(rs))}getTransform(){if(!this.parent)return jt.error(`Element ${this.id} does not have a parent.`),{position:[0,0,0],rotation:0,rotationAxis:[0,1,0]};let{position:t,rotation:e}=qi(this.parent,this);return{position:t,rotation:e,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&&ss(t),i)for(let e of this.elements)ss(e)}}getSpaces(){return this.parent?this.parent.getSpaces():(jt.error(`Element ${this.id} does not have a parent.`),[])}}class os extends ii{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(Te(t,e.geometry.polygons))return[e];return[]}getTransform(){let{position:t,rotation:e,rotationAxis:i}=this;return{position:[...t],rotation:e,rotationAxis:[...i]}}getWorldTransform(){let t=Ui(this),{position:e,rotation:i,rotationAxis:s}=Ne(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),"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=z([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),ss(this)}}const as={materials:{}};class ls extends os{constructor(t){super(t,"element:asset"),this.product=null,this.parameters=JSON.parse(JSON.stringify(as))}setParameters(t){super.setParameters(t)}setProduct(t){this.product=t,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 hs={length:2,width:.1,height:.2,materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class us extends os{constructor(t){super(t,"element:beam"),this.parameters=JSON.parse(JSON.stringify(hs))}setParameters(t){super.setParameters(t)}}const cs={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 ds extends os{constructor(t){super(t,"element:casework"),this.parameters=JSON.parse(JSON.stringify(cs))}setParameters(t){super.setParameters(t)}}const ps={type:"curve:circle",radius:.1},fs={"curve:circle":{...ps},"curve:rectangle":{type:"curve:rectangle",dimensions:[.1,.1]},"curve:polygon":{type:"curve:polygon",points:[[0,0],[.1,0],[.1,.1],[0,.1]]}},ms={profile:{...ps},height:3,materials:{top:"#202020",bottom:"#000000",sides:"asm:basic-wall"}};class gs extends os{constructor(t){super(t,"element:column"),this.parameters=JSON.parse(JSON.stringify(ms))}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(fs[t.profile.type]))),super.setParameters(t)}}const ys={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 vs extends os{constructor(t){super(t,"element:door"),this.parameters=JSON.parse(JSON.stringify(ys))}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 xs={"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]]}},bs={profile:"none",height:0,materials:{top:"#F0F0F0",bottom:"#F0F0F0",sides:"#F0F0F0"}};class _s extends os{constructor(t){super(t,"element:generic"),this.parameters=JSON.parse(JSON.stringify(bs))}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(xs[t.profile.type]))),super.setParameters(t)}}class ws extends Jt{constructor(t){super(t,"product:static"),this.geometries=[],this.attributes={manufacturer:"",categories:[],subCategories:[],thumbnail:"",boundingBox:{min:[1,0,0],max:[-1,0,0]},seatCapacity:0,updatedAt:""}}copyForClone(t){super.copyForClone(t),this.attributes=JSON.parse(JSON.stringify(t.attributes)),this.geometries=JSON.parse(JSON.stringify(t.geometries))}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}}function Es(t){for(let e=t.elements.length-1;e>=0;e--)t.removeElement(t.elements[e])}function Ps(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=Ye();s[r]="element:casework"===e?new ds(i):new ls(i),t.insertElement(s[r])}return s}function Ts(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=Ps(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=Ps(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 ws(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=xe(n,(v=be(o,n),x=.5,[v[0]*x,v[1]*x,v[2]*x]));l[1]=0;let u=xe([a*h-c,.9,0],[h/2,0,i/2]);r&&(e.setProduct(r),e.setPosition(be(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&&(Es(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&&(Es(b),b.setParameters({length:c,width:i,height:s,counterHeight:0,materials:{...y}}),b.setTransform([0,0,0],0));let _=d>0&&g.shift();_&&(Es(_),_.setParameters({length:d,width:i,height:s,counterHeight:0,materials:{...y}}),_.setTransform([c+p,0,0],0))}const Is={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 As extends os{constructor(t){super(t,"element:kitchen"),this.parameters=JSON.parse(JSON.stringify(Is))}setParameters(t,e=!1){super.setParameters(t),e||Ts(this),this.emit("element-parameters-change",this)}}const Ss={length:2,width:.05,height:1,segmentCount:0,segmentLength:.12,materials:{surface:"#CCCCCC"}};class Cs extends os{constructor(t){super(t,"element:railing"),this.parameters=JSON.parse(JSON.stringify(Ss))}setParameters(t){super.setParameters(t)}}const Ms={length:2,width:1,height:.5,materials:{top:"asm:basic-floor",bottom:"asm:basic-wall",sides:"asm:basic-wall"}};class Ns extends os{constructor(t){super(t,"element:ramp"),this.parameters=JSON.parse(JSON.stringify(Ms))}}const Os={materials:{}};class Rs extends os{constructor(t){super(t,"element:roof"),this.parameters=JSON.parse(JSON.stringify(Os))}}const Ls={type:"curve:rectangle",dimensions:[1,1]},ks={"curve:circle":{type:"curve:circle",radius:1},"curve:rectangle":{...Ls},"curve:polygon":{type:"curve:polygon",points:[[0,0],[1,0],[1,1],[0,1]]}},Fs={profile:{...Ls},height:.1,materials:{top:"asm:basic-floor",bottom:"asm:basic-floor",sides:"asm:basic-wall"}};class Ds extends os{constructor(t){super(t,"element:slab"),this.parameters=JSON.parse(JSON.stringify(Fs))}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(ks[t.profile.type]))),super.setParameters(t)}}const Bs={height:3,width:1.2,materials:{steps:"asm:basic-wall",tread:"asm:basic-floor"}},Us={straight:{stairFlightType:"straight",length:3,...Bs},spiral:{stairFlightType:"spiral",angle:270,radius:1.5,circulation:"right",...Bs}};class Gs extends os{constructor(t){super(t,"element:stairFlight"),this.parameters=JSON.parse(JSON.stringify(Us.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(Us[t.stairFlightType])),height:e,materials:i,width:s}}super.setParameters(t)}}function Xs(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=Ye();s[r]="element:stairFlight"===e?new Gs(i):new Ds(i),t.insertElement(s[r])}return s}const Hs=.1;const Ws={height:3,railing:"right",materials:{steps:"asm:basic-wall",tread:"asm:basic-floor",railing:"#CCCCCC"}},Ys={straight:{stairsType:"straight",length:4,width:1.2,...Ws},straightLanding:{stairsType:"straightLanding",length:4,width:1.2,...Ws},halfLanding:{stairsType:"halfLanding",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Ws},quarterLanding:{stairsType:"quarterLanding",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Ws},twoQuarterLanding:{stairsType:"twoQuarterLanding",length:3,width:4,stepWidth:1.2,circulation:"right",...Ws},winder:{stairsType:"winder",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Ws},doubleWinder:{stairsType:"doubleWinder",length:4,width:2.5,stepWidth:1.2,circulation:"right",...Ws},spiral:{stairsType:"spiral",radius:1.5,angle:270,stepWidth:1.2,circulation:"right",...Ws},custom:{stairsType:"custom",stepWidth:1.2,...Ws}},$s=Ys.straight;class zs extends os{constructor(t){super(t,"element:stairs"),this.parameters=JSON.parse(JSON.stringify($s))}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(Ys[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]=Xs(t,"element:stairFlight",1);Xs(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]=Xs(t,"element:stairFlight",2),[l]=Xs(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:Hs,materials:{top:r.tread,bottom:r.steps,sides:r.steps}}),l.setTransform([n,s/2-Hs,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]=Xs(t,"element:stairFlight",2),[u]=Xs(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:Hs,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),u.setPosition([e-r,s/2-Hs,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]=Xs(t,"element:stairFlight",2),[f]=Xs(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:Hs,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),f.setPosition([e-r,u-Hs,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]=Xs(t,"element:stairFlight",3),[m,g]=Xs(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:Hs,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),m.setPosition([e-r,u-Hs,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:Hs,materials:{top:o.tread,bottom:o.steps,sides:o.steps}}),g.setPosition([e-r,u+c-Hs,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]=Xs(t,"element:stairFlight",1);Xs(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 Vs={length:1,height:1.2,frameThickness:.05,frameDepth:.1,panelLength:0,panelCount:1,materials:{frame:"#CCCCCC",panel:"asm:glass"}};class js extends os{constructor(t){super(t,"element:window"),this.parameters=JSON.parse(JSON.stringify(Vs))}setParameters(t){super.setParameters(t)}}class qs extends $e{copyForClone(t){super.copyForClone(t),this.parameters=JSON.parse(JSON.stringify(t.parameters))}setParameters(t){ti(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("view-parameters-change",this)}}const Js={style:{background:{fill:"#f7f8fa"},units:"metric",byId:{},byType:{},byAttribute:{program:{},usage:{}}},hidden:[]};class Zs extends qs{constructor(t){super(t,"view:2d"),this.parameters=JSON.parse(JSON.stringify(Js))}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={}),ti(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 Ks={position:[0,0,0],normal:[0,0,1],fov:"default",scale:1,lensShiftX:0,lensShiftY:0,projection:"perspective"};class Qs extends qs{constructor(t){super(t,"view:3d"),this.parameters=JSON.parse(JSON.stringify(Ks))}setParameters(t){super.setParameters(t)}}const tr="relation:group";class er extends Jt{constructor(t){super(t,tr),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)}}class ir extends Jt{constructor(t,e){super(t,e)}}function sr(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 rr(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 nr(t,e){e.registerNode(t);for(let i of t.layouts)sr(i,e);e.emit("spatial-structure-create",t)}function or(t,e){e.unregisterNode(t);for(let i of t.layouts)rr(i,e);e.emit("spatial-structure-delete",t)}function ar(t,e,...i){let s;switch(t){case"element:ceiling":case"element:floor":s=new fi(e,t,i[0]);break;case"element:boundaryWall":s=new Wi(e,i[0]);break;case"element:curtainWall":s=new $i(e,i[0]);break;case"element:spaceDivider":s=new Vi(e,i[0]);break;case"element:wall":s=new di(e,i[0]);break;case"element:opening":s=new ns(e);break;case"element:asset":s=new ls(e);break;case"element:beam":s=new us(e);break;case"element:casework":s=new ds(e);break;case"element:column":s=new gs(e);break;case"element:door":s=new vs(e);break;case"element:generic":s=new _s(e);break;case"element:kitchen":s=new As(e);break;case"element:ramp":s=new Ns(e);break;case"element:roof":s=new Rs(e);break;case"element:railing":s=new Cs(e);break;case"element:slab":s=new Ds(e);break;case"element:stairs":s=new zs(e);break;case"element:stairFlight":s=new Gs(e);break;case"element:window":s=new js(e)}return s}class lr extends $e{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){ti(this.parameters,t,{onNewKeys:{allow:!1},cloneObjects:!0}),this.emit("annotation-parameters-change",this)}}const hr={uri:"",length:1,width:1};class ur extends lr{constructor(t){super(t,"annotation:floorPlanImage"),this.parameters=JSON.parse(JSON.stringify(hr))}setParameters(t){super.setParameters(t)}}const cr={uri:"",drawingOrigin:[0,0],hiddenLayers:[]};class dr extends lr{constructor(t){super(t,"annotation:floorPlanDxf"),this.parameters=JSON.parse(JSON.stringify(cr))}setParameters(t){super.setParameters(t)}}function pr(t,e){let i;switch(t){case"annotation:floorPlanDxf":i=new dr(e);break;case"annotation:floorPlanImage":i=new ur(e)}return i}function fr(t,e){let i;switch(t){case"view:2d":i=new Zs(e);break;case"view:3d":i=new Qs(e)}return i}class mr{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}}const gr="spatialStructure:layout";class yr extends ir{constructor(t){super(t,gr),this.parent=null,this.spaces=[],this.spacesById={},this.elements=[],this.elementsById={},this.elementsByType={},this.annotations=[],this.annotationsById={},this.annotationsByType={},this.views=[],this.viewsById={},this.viewsByType={},this.debugIds=!1,this.suggestedIds={};for(let e of ei)this.elementsByType[e]=[];this.spatialGraph=new Xi(this)}copyForClone(t){super.copyForClone(t),this.debugIds=t.debugIds,this.suggestedIds={...t.suggestedIds}}insertSpace(t){je(this,t,this.spacesById,"Space")&&(!function(t,e){for(let i of t.elements)"element:ceiling"!==i.type&&"element:floor"!==i.type||Ri(e.boundaries,i.boundaries)&&e.attachSlab(i)}(this,t),t.layout=this,this.spaces.push(t),this.spacesById[t.id]=t,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;jt.error(`Entry ${t.id} in 'spaces stored by ID' record does not contain this object.`)}else jt.warn(`Space ${t.id} not found.`)}createSpace(t,e){let i=new li(t,e);return this.insertSpace(i),i}insertElement(t){je(this,t,this.elementsById,"Element",!0)&&(!function(t,e){switch(e.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":Ti(t,e);break;case"element:curtainWall":case"element:spaceDivider":case"element:wall":Ii(t,e)}}(this,t),this.elements.push(t),qe(this,t))}removeElement(t){if(t.layout!==this)return void jt.warn(`Element ${t.id} not part of layout ${this.id}.`);if(t.parent)return void jt.warn(`Element ${t.id} not a root element, cannot remove from layout.`);Ai(t);let e=this.elements.indexOf(t);if(-1!==e)return this.elements.splice(e,1),Je(this,t),t;jt.warn(`Element ${t.id} not found.`)}createElement(t,e,...i){let s=ar(t,e,...i);return this.insertElement(s),s}insertNode(t){let{nodes:e,nodesById:i,nodesByType:s}=Gi(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}=Gi(this,t),n=i.indexOf(t);if(-1===n)return void jt.warn(`Node ${t.id} not found in '${e}' list.`);if(i.splice(n,1),s[t.id]!==t)return void jt.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):jt.error(`Node ${t.id} not found in '${e} stored by type' record.`)}insertAnnotation(t){je(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=pr(t,e);return this.insertAnnotation(i),i}insertView(t){je(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=fr(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 jt.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 mr,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):Ye(),e}getElementId(t,e){let i;return e=e??t.type.split(":")[1]+"-",i=this.debugIds?this.getUniqueId(e,this.elementsById):Ye(),i}}const vr="spatialStructure:floor";class xr extends ir{constructor(t){super(t,vr),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?jt.warn(`SpaceGraphLayout ${t.id} already part of floor ${t.parent.id}.`):(t.parent=this,this.layouts.push(t),this.spaceGraph&&sr(t,this.spaceGraph))}removeLayout(t){-1!==this.layouts.indexOf(t)?(this.spaceGraph&&rr(t,this.spaceGraph),t.parent=null):jt.warn(`Floor ${t.id} not found.`)}createLayout(t){let e=new yr(t);return this.insertLayout(e),e}}const br="spatialStructure:building";class _r extends ir{constructor(t){super(t,br),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?jt.warn(`Floor ${t.id} already part of building ${t.parent.id}.`):(t.parent=this,this.floors.push(t),this.spaceGraph&&nr(t,this.spaceGraph))}removeFloor(t){-1!==this.floors.indexOf(t)?(this.spaceGraph&&or(t,this.spaceGraph),t.parent=null):jt.warn(`Floor ${t.id} not found.`)}createFloor(t){let e=new xr(t);return this.insertFloor(e),e}}var wr={exports:{}};function Er(){}Er.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}},wr.exports=Er;var Pr=wr.exports.TinyEmitter=Er;class Tr{constructor(){this.products=[],this.productsById={},this.productsByType={},this.geometries=[],this.geometriesById={},this.geometriesByType={},this.materials=[],this.materialsById={},this.materialsByType={},this.relations=[],this.relationsById={},this.relationsByType={},this.nodes=[],this.nodesById={},this.nodesByType={},this.spatialStructure=null,this.emitter=new Pr}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 jt.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 jt.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;jt.error(`Node ${r.id} not found in 'nodes stored by type' record.`)}insertNode(t,e,i,s){i[t.id]?jt.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;jt.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)jt.warn(`Space graph object already has spatial structure ${this.spatialStructure.id} attached.`);else if(t.spaceGraph)jt.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)nr(i,e);e.emit("spatial-structure-create",t)}(t,this);break;case"spatialStructure:floor":nr(t,this);break;case"spatialStructure:layout":sr(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)or(i,e);e.emit("spatial-structure-delete",t)}(t,this);break;case"spatialStructure:floor":or(t,this);break;case"spatialStructure:layout":rr(t,this)}return this.emit("spatial-structure-delete",t),t}jt.warn("No spatial structure attached to space graph object.")}createSpatialStructure(t,e){let i;switch(t){case"spatialStructure:building":i=new _r(e);break;case"spatialStructure:floor":i=new xr(e);break;case"spatialStructure:layout":i=new yr(e)}return this.insertSpatialStructure(i),i}insertProduct(t){t.spaceGraph?jt.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)):jt.warn(`Product ${t.id} already in a detached state.`)}createProduct(t){let e=new ws(t);return this.insertProduct(e),e}insertGeometry(t){let{geometries:e,geometriesById:i,geometriesByType:s}=this;e.push(t),i[t.id]=t,s[t.type]||(s[t.type]=[]),s[t.type].push(t)}removeGeometry(t){let{geometries:e,geometriesById:i,geometriesByType:s}=this,r=e.indexOf(t);if(-1===r)return void jt.warn(`Geometry ${t.id} not found.`);if(e.splice(r,1),i[t.id]!==t)return void jt.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 jt.error(`Geometry ${t.id} not found in 'geometries stored by type' record.`);let o=n.indexOf(t);-1!==o?n.splice(o,1):jt.error(`Node ${t.id} not found in 'nodes stored by type' record.`)}insertMaterial(t){t.spaceGraph?jt.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)):jt.warn(`Material ${t.id} already in a detached state.`)}createMaterial(t,e,...i){let s;switch(t){case Zt:s=new Kt(e,i[0],i[1]);break;case Qt:s=new te(e,i[0]);break;case"material:embedded":s=new ee(e,i[0],i[1]);break;case ie:s=new se(e)}return this.insertMaterial(s),s}insertRelation(t){t.spaceGraph?jt.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)):jt.warn(`Relation ${t.id} already in a detached state.`)}createRelation(t,e){let i;if(t===tr)i=new er(e);return this.insertRelation(i),i}getId(){return Ye()}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)}}function Ir(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 Ar(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 Sr(t,e){t.name=e.name??t.name,t.customId=e.customId??t.customId}function Cr(t,e){t.name=e.name??t.name,t.customId=e.customId??t.customId}function Mr(t,e){let i=t.spatialGraph,s=new Fe;for(let r of e.edges){let t=i.edgesById[r];if(!t)return void jt.warn(`Edge ${r} not found, skipping boundary.`);s.edges.push(t)}if(Ni(s))return s}function Nr(t,e){let i=[];for(let s of e){let e=Mr(t,s);if(!e)return;i.push(e)}return i}function Or(t,e){let{id:i,position:s}=e,r=new Ve(i,s[0],s[1]);return Sr(r,e),r}function Rr(t,e){let i=t.spatialGraph,s=e.vertices[0],r=e.vertices[1];if(s===r)return void jt.warn(`Same vertex referenced twice, skipping edge ${e.id}.`);let n=i.verticesById[s],o=i.verticesById[r];if(!n||!o)return void jt.warn(`One or both vertices not found, skipping edge ${e.id}.`);let a=new oi(e.id,n,o);return Sr(a,e),a}function Lr(t,e){let i=Nr(t,e.boundaries);if(!i)return void jt.warn(`Invalid boundaries, skipping space ${e.id}.`);let s=new li(e.id,i);return Sr(s,e),e.attributes&&s.setAttributes(e.attributes),s}function kr(t,e){let i=pr(e.type,e.id);return Sr(i,e),i.setTransform(e.position,e.rotation??0),e.parameters&&i.setParameters(e.parameters),i}function Fr(t,e){let i=fr(e.type,e.id);return Sr(i,e),e.parameters&&i.setParameters(e.parameters),i}function Dr(t){if(t.id.includes(":")){let e=JSON.parse(JSON.stringify(t));return e.id=Ye(),e}return t}function Br(t){let e;switch(t.type){case"element:floor":case"element:ceiling":e=function(t){if(t.id.includes(":")){let e=JSON.parse(JSON.stringify(t));return e.id=Ye(),e}return t}(t);break;case"element:window":e=function(t){if(t.parameters&&"framePosition"in t.parameters){let e=JSON.parse(JSON.stringify(t));return delete e.parameters.framePosition,e}return t}(t);break;default:e=t}return e}function Ur(t,e){var i;let{position:s,rotation:r,rotationAxis:n}=e;if(t.setTransform(s,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 Gr(t,e,i){let s,r=Br(e);switch(r.type){case"element:boundaryWall":case"element:ceiling":case"element:floor":s=function(t,e){let i=Nr(t,e.boundaries);if(!i)return void jt.warn(`Invalid boundaries, skipping boundary wall ${e.id}.`);let s=ar(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=t.spatialGraph.edgesById[e.edge];if(!i)return void jt.warn(`Edge ${e.edge} not found, skipping edge element ${e.id}.`);let s=ar(e.type,e.id,i);return e.parameters&&s.setParameters(e.parameters),s}(t,r);break;case"element:opening":s=function(t,e){let i=ar("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=ar(e.type,e.id);if(Ur(s,e),!e.product)return e.geometries||jt.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 jt.warn(`Product ${e.product} not found, skipping element ${e.id}.`);s.setProduct(t)}else jt.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=ar(e.type,e.id);return Ur(i,e),i}(0,r);break;default:return void jt.warn(`Unknown element type '${r.type}', skipping element.`)}if(!s)return;Sr(s,r);let n=r.elements??[];for(let o of n){let e=Gr(t,o,i);e&&s.insertElement(e)}return s}function Xr(t,e,i){Sr(t,e),function(t,e){let i=t.spatialGraph,s=e.spatialGraph;for(let r of s.vertices){let t=Or(0,r);i.insertVertex(t)}for(let r of s.edges){let e=Rr(t,r);e&&i.insertEdge(e)}}(t,e),function(t,e){for(let i of e.spaces){let e=Lr(t,Dr(i));e&&t.insertSpace(e)}}(t,e),function(t,e,i){for(let s of e.elements){let e=Gr(t,s,i);e&&t.insertElement(e)}}(t,e,i),function(t,e){let i=e.annotations??[];for(let s of i){let e=kr(0,s);t.insertAnnotation(e)}}(t,e),function(t,e){let i=e.views??[];for(let s of i){let e=Fr(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)wi(s),i.push(Si(s));for(const s of e){if(null!==s.spaces[0]||null!==s.spaces[1])continue;const[e,r]=s.getPoints(),n=fe(e,r,.5);for(let o=0;o<t.spaces.length;o++)if(Te(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&&Ei(s)}(t)}function Hr(t){let e=new ws(t.id);return t.attributes&&e.setAttributes(t.attributes),Cr(e,t),e.geometries=JSON.parse(JSON.stringify(t.geometries)),e}function Wr(t){return JSON.parse(JSON.stringify(t))}function Yr(t){let e;if(Array.isArray(t)||"string"==typeof t)jt.warn("Color literal or standard material reference not allowed in shared resources section.");else if("object"==typeof t)switch(t.type){case Zt:let[i,s,r,n]=le(t.value);e=new Kt(t.id,[i,s,r],n);break;case Qt:e=new te(t.id,t.reference);break;case ie:e=new se(t.id),Cr(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 Kt(t.id,[1,1,1],1),jt.warn(`Unknown material type ${t.type}, creating default material.`)}else jt.warn("Material not an array, string or object.");return e}function $r(t,e){let i;if(e.type===tr){i=new er(e.id);let s=[];for(let r of e.elements)t.nodesById[r]?s.push(t.nodesById[r]):jt.error(`Element ${r} not found, referenced by relation ${i.id}.`);i.insertElements(s)}return Cr(i,e),i}function zr(t,e){let i=new xr(e.id);Cr(i,e),i.position=[...e.position],i.rotation=e.rotation;for(let s of e.layouts){let e=Vr(t,s);i.insertLayout(e)}return i}function Vr(t,e){let i=new yr(e.id);return Xr(i,e,t),i}function jr(t,e){let i;switch(e.type){case br:i=function(t,e){let i=new _r(e.id);Cr(i,e),e.location&&(i.location=JSON.parse(JSON.stringify(i.location)));for(let s of e.floors){let e=zr(t,s);i.insertFloor(e)}return i}(t,e);break;case vr:i=zr(t,e);break;case gr:i=Vr(t,e)}return i}function qr(t,e){!function(t,e){for(let i of e){let e=Hr(i);t.insertProduct(e)}}(t,e.products),function(t,e){for(let i of e){let e=Wr(i);t.insertGeometry(e)}}(t,e.geometries),function(t,e){for(let i of e){let e=Yr(i);e&&t.insertMaterial(e)}}(t,e.materials)}function Jr(t,e){qr(t,e.sharedResources),function(t,e){let i=jr(t,e);t.insertSpatialStructure(i)}(t,e.spatialStructure),function(t,e){for(let i of e){let e=$r(t,i);e&&t.insertRelation(e)}}(t,e.sharedResources.relations||[])}function Zr(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(Ie(a,r,n)<1e-7)return i?t[0]=a:t[1]=a,void(s?e.splice(0,o):e.splice(o+1))}}function Kr(t){let e=0;for(;e<t.length-2;){let i=t[e],s=t[e+2];Ie(t[e+1],i,s)<1e-7?t.splice(e+1,1):e++}}function Qr(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=Ar(t,s,e[r],e[r+1]);if(1===n.tag&&n.u>i&&n.u<1-i)return!0}}return!1}const tn="miter",en=.05,sn=.15,rn=2.5,nn=0;function on(t,e){let i={indices:[t,e],faces:[-1,-1],geometry:{tangible:!0,skipped:!1,parameters:{width:sn,height:rn,offset:nn},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 an="intersectCap",ln="intersectCap";function hn(t){let e=t.toFixed(3),i=parseFloat(e);return e+=t>i?"+":t<i?"-":" ",t>=0&&(e=" "+e),e}function un(t){if(t.length>0)for(let e=0;e<t.length;e++){let i=t[e];i[0],i[1]}}function cn(t,e){for(let i of e)if(t.length>0){let e=t[0],s=t[t.length-1],r=de(ve(i,e)),n=de(ve(i,s));r>1e-7&&n>1e-7&&t.push(i)}else t.push(i)}function dn(t,e,i,s,r){0===t.joinPoints.length?(cn(t.joinPoints,[...s,i]),cn(t.sidePoints[0],r)):(cn(t.joinPoints,s),cn(t.sidePoints[1],r.slice().reverse())),un(t.joinPoints),un(t.sidePoints[0]),un(t.sidePoints[1])}function pn(t,e,i,s,r){dn(t,0,i,[s],[s]),dn(e,0,i,[r],[r]),t.edge.geometry.computed.skipped=!0,e.edge.geometry.computed.skipped=!0}function fn(t,e,i,s){dn(t,0,i,[s],[s]),dn(e,0,i,[s],[s])}function mn(t,e,i,s,r){dn(t,0,i,[s],[s]),dn(e,0,i,[r],[r])}function gn(t,e,i,s,r,n,o,a,l,h,u){if("ignore"===u)pn(t,e,i,r,a);else{let u;if(u=h?Ir(s,r,l,a):Ir(n,r,o,a),2!==u.tag)return jt.warn("Edge side line does not intersect edge cap line, ignoring result."),void pn(t,e,i,r,a);let c=u.p;h?(dn(t,0,i,[c],[c]),dn(e,0,i,[a,c],[a])):(dn(t,0,i,[r,c],[r]),dn(e,0,i,[c],[c]))}}function yn(t,e,i,s,r,n,o,a,l,h,u,c){t.edge.id,e.edge.id;let d=Ir(s,r,a,l);if(2!==d.tag)return jt.warn("Edge side lines do not intersect, ignoring result.",d),void pn(t,e,i,r,l);let p=de(ve(r,s)),f=de(ve(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(de(ve(y,i))>s){let s,n=Ir(y,i,r,l);2!==n.tag?(jt.warn("Bevel construction failed, using center point.",n),s=fe(r,l,.5)):s=n.p,dn(t,0,i,[s],[r,s]),dn(e,0,i,[s],[l,s])}else fn(t,e,i,y)}else if(x>=g)fn(t,e,i,y);else{let c=o&&u?an:"ignore";gn(t,e,i,s,r,n,a,l,h,!0,c),_="ignore"===c?"* (ignore)":"* (intersectCap)"}else pn(t,e,i,r,l);else if(x>=.9999999)if(u)if(v>=m)fn(t,e,i,y);else{let c=o&&u?an:"ignore";gn(t,e,i,s,r,n,a,l,h,!1,c),b="ignore"===c?"* (ignore)":"* (intersectCap)"}else pn(t,e,i,r,l);else jt.warn("Edge side line segments cross, ignoring result."),pn(t,e,i,r,l);hn(v),m.toFixed(3),hn(x),g.toFixed(3)}function vn(t,e,i,s,r,n,o,a,l,h,u,c){t.edge.id,e.edge.id;let d=Ir(s,r,a,l);if(2!==d.tag)return jt.warn("Edge side lines do not intersect, ignoring result.",d),void pn(t,e,i,r,l);let p=de(ve(r,s)),f=de(ve(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)fn(t,e,i,y);else if(v>1&&x>1)jt.warn("Edge side line segments do not cross, ignoring result."),pn(t,e,i,r,l);else if(v>1)if(x>=g)fn(t,e,i,y);else{let c=o&&u?ln:"ignore";gn(t,e,i,s,r,n,a,l,h,!1,c),_="ignore"===c?"* (ignore)":"* (intersectCap)"}else if(x>1)if(v>=m)fn(t,e,i,y);else{let c=o&&u?ln:"ignore";gn(t,e,i,s,r,n,a,l,h,!0,c),b="ignore"===c?"* (ignore)":"* (intersectCap)"}else pn(t,e,i,r,l);hn(v),m.toFixed(3),hn(x),g.toFixed(3)}function xn(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 bn(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=Ee(o,a,d,p);if(w<_||w>Math.PI-_)mn(r,u,b,a,p);else{1===_e(h,b,m)?yn(r,u,b,o,a,l,v,d,p,f,x):vn(r,u,b,o,a,l,v,d,p,f,x)}}}function _n(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 wn(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,_n(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?xn(n,t):bn(n,t,r)}}function En(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 Pn(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:tn,parameters:{distance:en}}}}});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=on(s[t.id],s[e.id]);En(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:ue([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 Tn(t,e){gi(t,e),e.emit("geometry-profile-update",e);for(let i of e.slabs)i.emit("geometry-profile-update",i)}function In(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)Ki(i)}function An(t){let e=t.spatialGraph.edges,i=Pn(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=ve(l,a);if(t.skipped=de(h)<1e-7,!t.skipped){let e=ge(me(h)),i=ye(e,.5*n+o),s=ye(e,-.5*n+o),r=he(a,i),u=he(a,s),c=he(l,i),d=he(l,s);t.fragments[0].points=[r,u],t.fragments[1].points=[c,d]}}}(i),wn(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=Ir(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&&(Zr(c,r,!1,!0),Zr(c,n,!0,!1),Zr(d,r,!0,!1),Zr(d,n,!1,!0)),Kr(c),Kr(r),Kr(d),Kr(n),1===_e(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=Q(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=Qr(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){for(let e of t.edges){let t=e.reference.element;if("element:wall"===(null==t?void 0:t.type)){let i=e.geometry.computed;t.geometryProfile={valid:i.valid,skipped:i.skipped,selfIntersecting:i.selfIntersecting,sidePoints1:i.sidePoints1.slice(),sidePoints2:i.sidePoints2.slice(),joinPoints1:i.joinPoints1.slice(),joinPoints2:i.joinPoints2.slice(),points:i.points.slice()},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)&&is(i.element)}(e),In(e)}function Sn(t){An(t),function(t){let e=t.spaces;for(let i of e){Tn(t,i);for(let t of i.slabs)_i(t)}}(t)}function Cn(t){return new Promise(((e,i)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>i(t.error)}))}function Mn(t,e){const i=indexedDB.open(t);i.onupgradeneeded=()=>i.result.createObjectStore(e);const s=Cn(i);return(t,i)=>s.then((s=>i(s.transaction(e,t).objectStore(e))))}let Nn;function On(){return Nn||(Nn=Mn("keyval-store","keyval")),Nn}var Rn={exports:{}};function Ln(){}Ln.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}},Rn.exports=Ln;for(var kn=Rn.exports.TinyEmitter=Ln,Fn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Dn="undefined"==typeof Uint8Array?[]:new Uint8Array(256),Bn=0;Bn<64;Bn++)Dn[Fn.charCodeAt(Bn)]=Bn;var Un={exports:{}};function Gn(t,e){return t<e?-1:t>e?1:0}var Xn=xt(Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=Gn){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 Hn(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 Xn(void 0,Wn),m=s;m<n;m+=c)for(var g=r;g<o;g+=c)f.push(new Yn(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 Yn(r[0][0],r[0][1],0,t):new Yn(i/e,s/e,0,t)}(t),v=new Yn(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 Yn(b.x-d,b.y-d,d,t)),f.push(new Yn(b.x+d,b.y-d,d,t)),f.push(new Yn(b.x-d,b.y+d,d,t)),f.push(new Yn(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 Wn(t,e){return e.max-t.max}function Yn(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,$n(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 $n(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}Xn.default&&(Xn=Xn.default),Un.exports=Hn,Un.exports.default=Hn;const zn=vt(Un.exports);var Vn,jn,qn={exports:{}};Vn=qn,jn=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}(),Vn.exports=jn;const Jn=vt(qn.exports),Zn={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}}}},Kn={};Object.keys(Zn).forEach((t=>{const e=Zn[t];Kn[t]={name:e.name,type:"program",category:[]},e.isHidden&&(Kn[t].isHidden=e.isHidden);const i={};Object.keys(Zn[t].spaceUsage).forEach((e=>{const s=Zn[t].spaceUsage[e];Kn[e]={...s,type:"space",program:t},s.category.forEach((t=>{i[t]=!0}))})),Kn[t].category=Object.keys(i)})),new Jn({size:256});var Qn=typeof Float32Array<"u"?Float32Array:Array;function to(){var t=new Qn(16);return Qn!=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 eo(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 io(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 so(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,E=r*h-n*l,P=u*m-c*f,T=u*g-d*f,I=u*y-p*f,A=c*g-d*m,S=c*y-p*m,C=d*y-p*g,M=v*C-x*S+b*A+_*I-w*T+E*P;return M?(M=1/M,t[0]=(a*C-l*S+h*A)*M,t[1]=(r*S-s*C-n*A)*M,t[2]=(m*E-g*w+y*_)*M,t[3]=(d*w-c*E-p*_)*M,t[4]=(l*I-o*C-h*T)*M,t[5]=(i*C-r*I+n*T)*M,t[6]=(g*b-f*E-y*x)*M,t[7]=(u*E-d*b+p*x)*M,t[8]=(o*S-a*I+h*P)*M,t[9]=(s*I-i*S-n*P)*M,t[10]=(f*w-m*b+y*v)*M,t[11]=(c*b-u*w-p*v)*M,t[12]=(a*T-o*A-l*P)*M,t[13]=(i*A-s*T+r*P)*M,t[14]=(m*x-f*_-g*v)*M,t[15]=(u*_-c*x+d*v)*M,t):null}function ro(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 no(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function oo(t,e){var i=new Qn(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 ao(){var t=new Qn(3);return Qn!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function lo(t){var e=new Qn(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function ho(t,e,i){var s=new Qn(3);return s[0]=t,s[1]=e,s[2]=i,s}function uo(t,e,i,s){return t[0]=e,t[1]=i,t[2]=s,t}function co(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t}function po(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t}function fo(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 mo(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 go(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 yo=po;function vo(){var t=new Qn(4);return Qn!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function xo(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}ao(),function(){var t=function(){var t=new Qn(4);return Qn!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}()}();!function(){var t=ao(),e=ho(1,0,0),i=ho(0,1,0)}(),function(){var t=vo(),e=vo()}(),function(){var t=function(){var t=new Qn(9);return Qn!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}()}(),function(){var t=function(){var t=new Qn(2);return Qn!=Float32Array&&(t[0]=0,t[1]=0),t}()}();var bo=Object.defineProperty,_o=(t,e,i)=>(((t,e,i)=>{e in t?bo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);let wo=class t{constructor(){_o(this,"polygons",[])}clone(){var e=new t;return e.polygons=this.polygons.map((function(t){return t.clone()})),e}toPolygons(){return this.polygons}union(e){var i=new t.Node(this.clone().polygons),s=new t.Node(e.clone().polygons);return i.clipTo(s),s.clipTo(i),s.invert(),s.clipTo(i),s.invert(),i.build(s.allPolygons()),t.fromPolygons(i.allPolygons())}subtract(e){var i=new t.Node(this.clone().polygons),s=new t.Node(e.clone().polygons);return i.invert(),i.clipTo(s),s.clipTo(i),s.invert(),s.clipTo(i),s.invert(),i.build(s.allPolygons()),i.invert(),t.fromPolygons(i.allPolygons())}intersect(e){var i=new t.Node(this.clone().polygons),s=new t.Node(e.clone().polygons);return i.invert(),s.clipTo(i),s.invert(),i.clipTo(s),s.clipTo(i),i.build(s.allPolygons()),i.invert(),t.fromPolygons(i.allPolygons())}inverse(){var t=this.clone();return t.polygons.map((function(t){t.flip()})),t}};(t=>{t.fromPolygons=function(e){var i=new t;return i.polygons=e,i},t.cube=function(e){e=e||{};var i=new t.Vector(e.center||[0,0,0]),s=e.radius?e.radius.length?e.radius:[e.radius,e.radius,e.radius]:[1,1,1];return t.fromPolygons([[[0,4,6,2],[-1,0,0]],[[1,3,7,5],[1,0,0]],[[0,1,5,4],[0,-1,0]],[[2,6,7,3],[0,1,0]],[[0,2,3,1],[0,0,-1]],[[4,5,7,6],[0,0,1]]].map((function(e){return new t.Polygon(e[0].map((function(r){let n=1&r?s[0]:-s[0],o=2&r?s[1]:-s[1],a=4&r?s[2]:-s[2],l=new t.Vector(i.x+n,i.y+o,i.z+a);return new t.Vertex(l,new t.Vector(e[1]))})))})))},t.sphere=function(e){e=e||{};var i,s=new t.Vector(e.center||[0,0,0]),r=e.radius||1,n=e.slices||16,o=e.stacks||8,a=[];function l(e,n){e*=2*Math.PI,n*=Math.PI;var o=new t.Vector(Math.cos(e)*Math.sin(n),Math.cos(n),Math.sin(e)*Math.sin(n));i.push(new t.Vertex(s.plus(o.times(r)),o))}for(var h=0;h<n;h++)for(var u=0;u<o;u++)i=[],l(h/n,u/o),u>0&&l((h+1)/n,u/o),u<o-1&&l((h+1)/n,(u+1)/o),l(h/n,(u+1)/o),a.push(new t.Polygon(i));return t.fromPolygons(a)},t.cylinder=function(e){e=e||{};var i=new t.Vector(e.start||[0,-1,0]),s=new t.Vector(e.end||[0,1,0]),r=s.minus(i),n=e.radius||1,o=e.slices||16,a=r.unit(),l=Math.abs(a.y)>.5,h=new t.Vector(l,!l,0).cross(a).unit(),u=h.cross(a).unit(),c=new t.Vertex(i,a.negated()),d=new t.Vertex(s,a.unit()),p=[];function f(e,s,o){var l=s*Math.PI*2,c=h.times(Math.cos(l)).plus(u.times(Math.sin(l))),d=i.plus(r.times(e)).plus(c.times(n)),p=c.times(1-Math.abs(o)).plus(a.times(o));return new t.Vertex(d,p)}for(var m=0;m<o;m++){var g=m/o,y=(m+1)/o;p.push(new t.Polygon([c,f(0,g,-1),f(0,y,-1)])),p.push(new t.Polygon([f(0,y,0),f(0,g,0),f(1,g,0),f(1,y,0)])),p.push(new t.Polygon([d,f(1,y,1),f(1,g,1)]))}return t.fromPolygons(p)};t.Vector=class{constructor(t,e,i){_o(this,"x"),_o(this,"y"),_o(this,"z"),3==arguments.length?(this.x=t,this.y=e,this.z=i):"x"in t?(this.x=t.x,this.y=t.y,this.z=t.z):(this.x=t[0],this.y=t[1],this.z=t[2])}clone(){return new t.Vector(this.x,this.y,this.z)}negated(){return new t.Vector(-this.x,-this.y,-this.z)}plus(e){return new t.Vector(this.x+e.x,this.y+e.y,this.z+e.z)}minus(e){return new t.Vector(this.x-e.x,this.y-e.y,this.z-e.z)}times(e){return new t.Vector(this.x*e,this.y*e,this.z*e)}dividedBy(e){return new t.Vector(this.x/e,this.y/e,this.z/e)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lerp(t,e){return this.plus(t.minus(this).times(e))}length(){return Math.sqrt(this.dot(this))}unit(){return this.dividedBy(this.length())}cross(e){return new t.Vector(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)}};t.Vertex=class{constructor(e,i){_o(this,"pos"),_o(this,"normal"),this.pos=new t.Vector(e),this.normal=new t.Vector(i)}clone(){return new t.Vertex(this.pos.clone(),this.normal.clone())}flip(){this.normal=this.normal.negated()}interpolate(e,i){return new t.Vertex(this.pos.lerp(e.pos,i),this.normal.lerp(e.normal,i))}};class e{constructor(t,e){_o(this,"normal"),_o(this,"w"),this.normal=t,this.w=e}clone(){return new t.Plane(this.normal.clone(),this.w)}flip(){this.normal=this.normal.negated(),this.w=-this.w}splitPolygon(e,i,s,r,n){for(var o=0,a=[],l=0;l<e.vertices.length;l++){var h=(y=this.normal.dot(e.vertices[l].pos)-this.w)<-t.Plane.EPSILON?2:y>t.Plane.EPSILON?1:0;o|=h,a.push(h)}switch(o){case 0:(this.normal.dot(e.plane.normal)>0?i:s).push(e);break;case 1:r.push(e);break;case 2:n.push(e);break;case 3:var u=[],c=[];for(l=0;l<e.vertices.length;l++){var d=(l+1)%e.vertices.length,p=a[l],f=a[d],m=e.vertices[l],g=e.vertices[d];if(2!=p&&u.push(m),1!=p&&c.push(2!=p?m.clone():m),3==(p|f)){var y=(this.w-this.normal.dot(m.pos))/this.normal.dot(g.pos.minus(m.pos)),v=m.interpolate(g,y);u.push(v),c.push(v.clone())}}u.length>=3&&r.push(new t.Polygon(u,e.shared)),c.length>=3&&n.push(new t.Polygon(c,e.shared))}}}_o(e,"EPSILON",1e-5),_o(e,"fromPoints",(function(e,i,s){var r=i.minus(e).cross(s.minus(e)).unit();return new t.Plane(r,r.dot(e))})),t.Plane=e;t.Polygon=class{constructor(e,i){_o(this,"vertices"),_o(this,"shared"),_o(this,"plane"),this.vertices=e,this.shared=i,this.plane=t.Plane.fromPoints(e[0].pos,e[1].pos,e[2].pos)}clone(){var e=this.vertices.map((function(t){return t.clone()}));return new t.Polygon(e,this.shared)}flip(){this.vertices.reverse().map((function(t){t.flip()})),this.plane.flip()}};t.Node=class{constructor(t){_o(this,"plane",null),_o(this,"front",null),_o(this,"back",null),_o(this,"polygons",[]),t&&this.build(t)}clone(){var e=new t.Node;return e.plane=this.plane&&this.plane.clone(),e.front=this.front&&this.front.clone(),e.back=this.back&&this.back.clone(),e.polygons=this.polygons.map((function(t){return t.clone()})),e}invert(){for(var t,e=0;e<this.polygons.length;e++)this.polygons[e].flip();null==(t=this.plane)||t.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var i=this.front;this.front=this.back,this.back=i}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);return this.front&&(e=this.front.clipPolygons(e)),i=this.back?this.back.clipPolygons(i):[],e.concat(i)}clipTo(t){this.polygons=t.clipPolygons(this.polygons),this.front&&this.front.clipTo(t),this.back&&this.back.clipTo(t)}allPolygons(){var t=this.polygons.slice();return this.front&&(t=t.concat(this.front.allPolygons())),this.back&&(t=t.concat(this.back.allPolygons())),t}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))}}}})(wo||(wo={}));const Eo=wo;function Po(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var To={exports:{}};function Io(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=Ao(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,l,h=[];for(r=0,n=e.length;r<n;r++)o=e[r]*s,a=r<n-1?e[r+1]*s:t.length,(l=Ao(t,o,a,s,!1))===l.next&&(l.steiner=!0),h.push(Bo(l));for(h.sort(Lo),r=0;r<h.length;r++)i=ko(h[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 Co(d,p,i,s,r,h,0),p}function Ao(t,e,i,s,r){var n,o;if(r===Zo(t,e,i,s)>0)for(n=e;n<i;n+=s)o=jo(n,t[n],t[n+1],o);else for(n=i-s;n>=e;n-=s)o=jo(n,t[n],t[n+1],o);return o&&Ho(o,o.next)&&(qo(o),o=o.next),o}function So(t,e){if(!t)return t;e||(e=t);var i,s=t;do{if(i=!1,s.steiner||!Ho(s,s.next)&&0!==Xo(s.prev,s,s.next))s=s.next;else{if(qo(s),(s=e=s.prev)===s.next)break;i=!0}}while(i||s!==e);return e}function Co(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=Do(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?No(t,s,r,n):Mo(t))e.push(a.i/i|0),e.push(t.i/i|0),e.push(l.i/i|0),qo(t),t=l.next,h=l.next;else if((t=l)===h){o?1===o?Co(t=Oo(So(t),e,i),e,i,s,r,n,2):2===o&&Ro(t,e,i,s,r,n):Co(So(t),e,i,s,r,n,1);break}}}function Mo(t){var e=t.prev,i=t,s=t.next;if(Xo(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&&Uo(r,a,n,l,o,h,f.x,f.y)&&Xo(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function No(t,e,i,s){var r=t.prev,n=t,o=t.next;if(Xo(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=Do(p,f,e,i,s),v=Do(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&&Uo(a,u,l,c,h,d,x.x,x.y)&&Xo(x.prev,x,x.next)>=0||(x=x.prevZ,b.x>=p&&b.x<=m&&b.y>=f&&b.y<=g&&b!==r&&b!==o&&Uo(a,u,l,c,h,d,b.x,b.y)&&Xo(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&&Uo(a,u,l,c,h,d,x.x,x.y)&&Xo(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&&Uo(a,u,l,c,h,d,b.x,b.y)&&Xo(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Oo(t,e,i){var s=t;do{var r=s.prev,n=s.next.next;!Ho(r,n)&&Wo(r,s,s.next,n)&&zo(r,n)&&zo(n,r)&&(e.push(r.i/i|0),e.push(s.i/i|0),e.push(n.i/i|0),qo(s),qo(s.next),s=t=n),s=s.next}while(s!==t);return So(s)}function Ro(t,e,i,s,r,n){var o=t;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Go(o,a)){var l=Vo(o,a);return o=So(o,o.next),l=So(l,l.next),Co(o,e,i,s,r,n,0),void Co(l,e,i,s,r,n,0)}a=a.next}o=o.next}while(o!==t)}function Lo(t,e){return t.x-e.x}function ko(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&&Uo(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),zo(s,t)&&(l<d||l===d&&(s.x>i.x||s.x===i.x&&Fo(i,s)))&&(i=s,d=l)),s=s.next}while(s!==h);return i}(t,e);if(!i)return e;var s=Vo(i,t);return So(s,s.next),So(i,i.next)}function Fo(t,e){return Xo(t.prev,t,e.prev)<0&&Xo(e.next,t,t.next)<0}function Do(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 Bo(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 Uo(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 Go(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&&Wo(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(zo(t,e)&&zo(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)&&(Xo(t.prev,t,e.prev)||Xo(t,e.prev,e))||Ho(t,e)&&Xo(t.prev,t,t.next)>0&&Xo(e.prev,e,e.next)>0)}function Xo(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function Ho(t,e){return t.x===e.x&&t.y===e.y}function Wo(t,e,i,s){var r=$o(Xo(t,e,i)),n=$o(Xo(t,e,s)),o=$o(Xo(i,s,t)),a=$o(Xo(i,s,e));return!!(r!==n&&o!==a||0===r&&Yo(t,i,e)||0===n&&Yo(t,s,e)||0===o&&Yo(i,t,s)||0===a&&Yo(i,e,s))}function Yo(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 $o(t){return t>0?1:t<0?-1:0}function zo(t,e){return Xo(t.prev,t,t.next)<0?Xo(t,e,t.next)>=0&&Xo(t,t.prev,e)>=0:Xo(t,e,t.prev)<0||Xo(t,t.next,e)<0}function Vo(t,e){var i=new Jo(t.i,t.x,t.y),s=new Jo(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 jo(t,e,i,s){var r=new Jo(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 qo(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 Jo(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 Zo(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}To.exports=Io,To.exports.default=Io,Io.deviation=function(t,e,i,s){var r=e&&e.length,n=r?e[0]*i:t.length,o=Math.abs(Zo(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(Zo(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)},Io.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 Ko=Po(To.exports);let Qo=new class extends P{error(...t){this.levels.includes("errors")&&(t.length>0&&(t[0]="Internal error: "+t[0]),console.error(...t))}}(["info","warnings","errors"]);const ta="material:color",ea="material:standard",ia="material:embedded",sa="material:basic",ra="default",na=[1,1,1],oa=[1,1,1],aa=1,la=1,ha=[...na,la];function ua(t,e){return Number.isFinite(t)?!(t<0||t>1)||(Qo.warn(`Value out of range (0 to 1) in color literal: '${e}'.`),!1):(Qo.warn(`Invalid float value in color literal: '${e}'.`),!1)}function ca(t,e){return Number.isInteger(t)?!(t<0||t>255)||(Qo.warn(`Value out of range (0 to 255) in color literal: '${e}'.`),!1):(Qo.warn(`Invalid byte value in color literal: '${e}'.`),!1)}function da(t,e){if(!t.endsWith(")"))return Qo.warn(`Missing closing parenthesis: '${t}'.`),ha;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 Qo.warn(`Invalid number of components in color literal: '${t}'.`),ha;let r=[0,0,0,0];for(let n=0;n<3;n++){let e=s[n],i=parseFloat(e);if(!ca(i,t))return ha;r[n]=i/255}if(4===s.length){let e=parseFloat(s[3]);if(!ua(e,t))return ha;r[3]=e}else r[3]=ha[3];return r}function pa({name:t=ra,color:e=na,specularColor:i=oa,specularCoefficient:s=aa,opacity:r=la,reference:n}={}){return n?{name:t,reference:n}:{name:t,color:[...e],specularColor:[...i],specularCoefficient:s,opacity:r}}function fa(t,e={}){if(Array.isArray(t)){let[e,i,s,r]=function(t){if(t.length<3||t.length>4)return Qo.warn(`Invalid number of components in color literal: '${t}'.`),ha;let e=t.toString(),i=[0,0,0,0];for(let s=0;s<t.length;s++){let r=t[s];if(!ua(r,e))return ha;i[s]=r}return 3===t.length&&(i[3]=ha[3]),i}(t);return pa({name:t.toString(),color:[e,i,s],opacity:r})}if("string"==typeof t){let i,s,r,n;if(""===t)return Qo.warn("Empty string not a valid color value."),pa({name:t});if(t===ra)return pa();if("#"===t.charAt(0))[i,s,r,n]=function(t){let e,i,s,r,n=t.substring(1),o=parseInt(n,16);if(isNaN(o))return Qo.warn(`Invalid hexadecimal color literal: '${t}'.`),ha;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 Qo.warn(`Invalid hexademical color literal length: '${t}'.`),ha;e=(o>>24&255)/255,i=(o>>16&255)/255,s=(o>>8&255)/255,r=(255&o)/255}return[e,i,s,r]}(t);else if(t.startsWith("rgb("))[i,s,r,n]=da(t,!1);else{if(!t.startsWith("rgba(")){if(t.startsWith("asm:")){let e=t.substring(4,t.length);return pa({name:t,reference:e})}if(t.startsWith("data3d:")){let e=t.substring(7,t.length);return pa({name:t,reference:e})}{let i=e[t];if(typeof i>"u")return Qo.warn(`Unknown material: '${t}'.`),pa();{let e;switch(i.type){case ta:e=pa({name:t,color:i.color,specularColor:i.color});break;case ea:e=pa({name:t,reference:i.reference});break;case ia:Qo.warn("Embedded material not supported in materials section."),e=pa();break;case sa:e=pa({name:t,color:i.colorDiffuse,specularColor:i.colorSpecular,specularCoefficient:i.specularCoefficient,opacity:i.opacity});break;default:Qo.warn(`Unknown material type ${i.type}.`),e=pa()}return e}}}[i,s,r,n]=da(t,!0)}return pa({name:t,color:[i,s,r],opacity:n})}return Qo.warn(`Material can only be an array or a string: '${t}'.`),pa()}const ma="default";function ga(t,e){return new Array(e-t).fill(void 0).map(((e,i)=>t+i))}function ya(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 va(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 xa(t,e,i){let s=[],r=e.faces,{surfaces:n,materials:o}=function(t){let e=t.surfaces??{[ma]:"all"},i=t.materials??{[ma]:"default"};if(e&&0===Object.keys(e).length)Qo.warn("Empty 'surfaces' field not allowed.");else if(i&&0===Object.keys(i).length)Qo.warn("Empty 'materials' field not allowed.");else if(t.material)t.materials?Qo.warn("Cannot use 'material' and 'materials' at the same time."):i={[ma]:t.material};else if(i[ma])Object.keys(i).length>1&&Qo.warn("Extraneous material assignments ignored.");else{let t=Object.keys(e);for(let e of t)i[e]||Qo.warn(`Surface '${e}' not assigned a material, using default.`);let s=Object.keys(i);for(let i of s)e[i]||Qo.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){Qo.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(...ga(0,t))}else if(Array.isArray(l))n.push(...l);else{let{start:t,end:e}=l;n.push(...ga(t,e))}else if("all"===l)for(let t of r){let{index:e,count:i}=t;n.push(...ga(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(...ga(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(...ga(e,e+s))}}let h,{vertices:u,indices:c,normals:d,uvs:p}=e;h=o[ma]?o[ma]:o[a]??"default";let f=fa(h,i),m={name:a,vertices:u,indices:ya(c,n),material:f};d&&(m.normals=va(d,3,n)),p&&(m.uvs=va(p,2,n)),s.push(m)}return s}function ba(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 Qo.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 Qo.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 _a(t,e,i){return Math.abs(t[0]-e[0])<i&&Math.abs(t[1]-e[1])<i}function wa(t){return function(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}(t)>0}function Ea(t,e,i){if(0!==t[0]||0!==t[1]||0!==t[2]||0!==e){let s=to(),r=ho(t[0],t[1],t[2]),n=function(t=0,e=[0,1,0]){let i=t*Math.PI/180,s=vo();return xo(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 to()}function Pa(t,e){let i=ao();for(let s=0;s<t.length;s+=3)i[0]=t[s],i[1]=t[s+1],i[2]=t[s+2],go(i,i,e),t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2]}function Ta({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=ba(t,e),u=[],c=[],d=[],p=[],f=to();for(let g=0;g<h.length;g++){let t=h[g],{position:e,rotation:s}=t,l=Ea(e,s,i),m=r.slice();Pa(m,l);let y=u.length/3;if(u.push(...m),c.push(...n.map((t=>y+t))),Array.isArray(o)){eo(f,l),f[12]=0,f[13]=0,f[14]=0,io(f,f),so(f,f);let t=o.slice();Pa(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}function Ia(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 fo(r,t),mo(i,Math.abs(r[1])<e?ho(0,1,0):ho(1,0,0),t),mo(s,t,i),fo(i,i),fo(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 Qn(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)go(u,u,h);return r}function Aa(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function Sa(t,e){let i=[],s=t.nextId++,{name:r,vertices:n,indices:o,material:a}=e,l=[0,0,0],h=[0,0,0],u=[0,0,0];for(let c=0;c<o.length;c+=3){let t=o[c],e=o[c+1],d=o[c+2];Aa(n,l,3*t),Aa(n,h,3*e),Aa(n,u,3*d);let p=[new Eo.Vertex(l,{}),new Eo.Vertex(h,{}),new Eo.Vertex(u,{})];i.push(new Eo.Polygon(p,{id:s,name:r,material:a}))}return i}function Ca(){let t=Math.random(),e=Math.random(),i=Math.random();return pa({name:"#"+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"),color:[t,e,i],opacity:1})}function Ma(t,e,{precision:i}={}){let s=[],r=[],n={};for(let o=0;o<e.length;o++){let a=3*e[o],l=t[a],h=t[a+1],u=t[a+2];void 0!==i&&(l=T(l,i),h=T(h,i),u=T(u,i));let c=l+"_"+h+"_"+u,d=n[c];void 0===d&&(d=s.push(l,h,u)/3-1,n[c]=d),r.push(d)}return{vertices:s,indices:r}}function Na(t,e){let i=[];for(let s of e){let e=Sa(t,s);i.push(...e)}return Eo.fromPolygons(i)}function Oa(t,{debugMode:e=!1,sharedVertices:i=!0}={}){let s={},{polygons:r}=t;for(let n=0;n<r.length;n++){let t=r[n],i=t.vertices.length;if(i<3){Qo.warn(`Skipping CSG polygon with '${i}' '${1===i?"vertex":"vertices"}.`);continue}let o,a=[];for(let e=0;e<i;e++){let i=t.vertices[e];a.push(i.pos.x,i.pos.y,i.pos.z)}if(3===i)o=[0,1,2];else{o=[];for(let t=1;t<i-1;t++)o.push(0,t,t+1)}if(e){let t=Ca();s[n]={name:t.name,vertices:a,indices:o,material:t}}else{let{id:e,name:i,material:r}=t.shared,n=s[e];if(n){let t=n.vertices.length/3;n.vertices.push(...a),n.indices.push(...o.map((e=>t+e)))}else s[e]={name:i,vertices:a,indices:o,material:r}}}if(i)for(let n of Object.values(s)){let{vertices:t,indices:e}=n,i=Ma(t,e);n.vertices=i.vertices,n.indices=i.indices}return Object.values(s)}function Ra(t,e,i,s){let r,n,o,a,l;if("string"==typeof t){if(r=t,l=e[r],!l)return Qo.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 Qo.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 Qo.warn(`Cycle detected while resolving geometry '${l.id}'.`),[];let h=Ka(l,e,i,s);"string"!=typeof t&&"csg:clip"!==t.type&&function(t,e,i,s){let r;if(t.material?t.materials?Qo.warn("Cannot use 'material' and 'materials' at the same time."):r={[ma]:t.material}:t.materials&&(0===Object.keys(t.materials).length?Qo.warn("Empty 'materials' field not allowed."):r=t.materials),r)if(r[ma]){let t=fa(r[ma],i);for(let i of e)i.material=t;Object.keys(r).length>1&&Qo.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=fa(o,i);t.material=e}else Qo.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=Ta({position:n,rotation:o,rotationAxis:a,name:t,vertices:e,indices:i,normals:s,uvs:r,material:l});u.push(h)}return u}function La(t,e,i,s,r){return[...t,...Ra(e,i,s,r)]}function ka(t,e,i,s){let{plane:r,material:n}=i,o=Na(t,e);{let e=function(t,e,i,s,r=100){let n=t.nextId++,{position:o,normal:a}=e,l=fa(i,s),h=[0,0,0],u=[0,0,0];fo(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=Ia(o,h,r),d=Ia(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 Eo.Vertex(p[i],{}));let e=new Eo.Polygon(t,{id:n,name:"",material:l});m.push(e)}return Eo.fromPolygons(m)}(t,r,n,s);o.polygons.length>0&&(o=o.subtract(e))}return Oa(o,{debugMode:!1})}function Fa(t,e,i,s,r,n){let o=Ra(i,s,r,n),a=Na(t,e),l=Na(t,o),h=[];if(a.polygons.length&&l.polygons.length){switch(i.type){case"csg:subtract":a=a.subtract(l);break;case"csg:union":a=a.union(l);break;case"csg:intersect":a=a.intersect(l)}h=Oa(a,{debugMode:!1})}return h}function Da(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function Ba(t,e,i){t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2]}function Ua(t,e){let i=new Array(3*e.length),s=ao(),r=ao(),n=ao(),o=ao(),a=ao(),l=ao(),h=0;for(let u=0;u<e.length;u+=3){let c=e[u],d=e[u+1],p=e[u+2];Da(t,s,3*c),Da(t,r,3*d),Da(t,n,3*p),yo(o,r,s),yo(a,n,s),mo(l,o,a),fo(l,l),Ba(i,l,h+0),Ba(i,l,h+3),Ba(i,l,h+6),h+=9}return i}function Ga(t,e){let i=new Array(3*e.length),s=ao(),r=ao(),n=ao(),o=ao(),a=ao(),l=ao(),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];Da(t,s,3*i),Da(t,r,3*h),Da(t,n,3*d),yo(o,r,s),yo(a,n,s),mo(l,o,a),fo(l,l),u[c++]={index1:i,index2:h,index3:d,normal1:lo(l),normal2:lo(l),normal3:lo(l)}}let d=[];for(let f=0;f<t.length;f++)d[f]={normals:[],normal:ao()};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;uo(i,0,0,0);for(let s=0;s<e;s++)co(i,i,t.normals[s]);fo(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;Ba(i,n,p+0),Ba(i,o,p+3),Ba(i,a,p+6),p+=9}return i}function Xa(t,e,i){e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2]}function Ha(t,e){let i=new Array(2*e.length),s=ao(),r=ao(),n=ao(),o=ao(),a=ao(),l=ao(),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];Xa(t,s,3*p),Xa(t,r,3*f),Xa(t,n,3*m),yo(o,r,s),yo(a,n,s),mo(l,o,a),fo(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 Wa(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 Ya(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 $a=48,za=12;function Va(t,e){return[e*Math.cos(t),-e*Math.sin(t)]}function ja(t,e,i,s=!0){let r=[],n=e-t,o=function(t,e){let i=Math.ceil($a/(2*Math.PI)*t*e);const s=Math.ceil(za/(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=Va(t+l*a,i);r.push(e)}if(s){let t=Va(e,i);r.push(t)}return r}function qa(t){let e=[];switch(t.type){case"curve:line":e.push(t.start,t.end);break;case"curve:arc":e=ja(Math.PI*t.startAngle/180,Math.PI*t.endAngle/180,t.radius);break;case"curve:polyline":e=t.points}return e}function Ja(t,e,i){let s,r=i.holes??[],n=i.y??0,o=i.flipSide??!1,a=t,l=[],h=0;for(let u=0;u<a.length;u+=2)l[h++]=a[u],l[h++]=n,l[h++]=a[u+1];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=Ko(a,t)}else s=Ko(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}}return{vertices:l,indices:s}}function Za(t){let{profile:e,height:i}=t,s=function(t){let e=[],i=[];switch(t.type){case"curve:circle":e=ja(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:rectangle":let{dimensions:s}=t,r=s[0],n=s[1];e=[[0,0],[0,n],[r,n],[r,0]];for(let t=0;t<e.length;t++)i.push({index:t,count:1});break;case"curve:composite":const o=1e-7;let a,l,h=t.segments;for(let t=0;t<h.length;t++){let s=qa(h[t]),r=s[0],n=s[s.length-1];0===t||_a(r,l,o)||Qo.warn(`Composite curve segments ${t} and ${t+1} are not continuous.`),0===t&&(a=r),l=n,i.push({index:e.length,count:s.length-1}),e.push(...s.slice(0,s.length-1))}h.length>0&&!_a(l,a,o)&&Qo.warn("Composite curve not closed.")}return{points:e,segmentRanges:i}}(e),{points:r,segmentRanges:n}=s,o=r.flat(),a=wa(r),l=Ja(o,a,{y:i,flipSide:!1}),h=Ja(o,a,{y:0,flipSide:!0}),u=[];u.push(...l.vertices),u.push(...h.vertices);let c=l.indices,d=h.indices.map((t=>t+r.length)),p=function(t,e=!1){let i=t.length/6,s=new Array(2*i*3),r=0;for(let n=0;n<i;n++)n===i-1?e?(s[r++]=n,s[r++]=0,s[r++]=i,s[r++]=n,s[r++]=i,s[r++]=n+i):(s[r++]=i,s[r++]=0,s[r++]=n,s[r++]=n+i,s[r++]=i,s[r++]=n):e?(s[r++]=n,s[r++]=n+1,s[r++]=n+i+1,s[r++]=n,s[r++]=n+i+1,s[r++]=n+i):(s[r++]=n+i+1,s[r++]=n+1,s[r++]=n,s[r++]=n+i,s[r++]=n+i+1,s[r++]=n);return s}(u,a),f=[];f.push(...c),f.push(...d),f.push(...p);let m=c.length/3,g=[];g[0]={index:0,count:m},g[1]={index:m,count:m};let y=2*m;for(let v of n){let t=y+2*v.index,e=2*v.count;g.push({index:t,count:e})}return{vertices:u,indices:f,faces:g}}function Ka(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=Ia([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){let e,i,s=t.radius,r=[],n=[],o="generator"===t.uvs?[]:void 0;r.push(0,s,0);for(let l=1;l<16;l++){let t=Math.PI*l/16;for(let e=0;e<16;e++){let i=Ya(s,t,2*Math.PI*e/16);r.push(i[0],i[1],i[2])}}let a=r.push(0,-s,0)/3-1;e=1,i=.9375;for(let l=0;l<16;l++){let t=1+l,s=1+(l+1)%16;if(n.push(0,s,t),o){let t=1-l/16,s=1-(l+1)/16,r=.5*(t+s);o.push(r,e,s,i,t,i)}}for(let l=0;l<14;l++)for(let t=0;t<16;t++){let e=1+16*l+t,i=1+16*l+(t+1)%16,s=1+16*(l+1)+(t+1)%16,r=1+16*(l+1)+t;if(n.push(e,i,s),n.push(e,s,r),o){let e=1-t/16,i=1-(l+1)/16,s=1-(t+1)/16,r=1-(l+2)/16;o.push(e,i,s,i,s,r),o.push(e,i,s,r,e,r)}}e=.0625,i=0;for(let l=0;l<16;l++){let t=225+l,s=225+(l+1)%16;if(n.push(t,s,a),o){let t=1-l/16,s=1-(l+1)/16,r=.5*(t+s);o.push(t,e,s,e,r,i)}}return{vertices:r,indices:n,uvs:o,faces:[{index:0,count:n.length/3}]}}(t);break;case"geometry:extrusion":n=Za(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 Qo.warn(`Invalid geometry type ${t.type}.`),o}o=xa(t,n,i),("geometry:plane"===t.type||"geometry:cuboid"===t.type||"geometry:sphere"===t.type||"geometry:extrusion"===t.type)&&null!=(r=t.geometries)&&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?La(e,a,i,s,r):"csg:clip"===a.type?ka(n,e,a,s):Fa(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=Ta({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?Ua(t,e):Ga(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?Ha(t,e):Wa(t,e)}return o}for(var Qa=[],tl=0;tl<256;++tl)Qa.push((tl+256).toString(16).substr(1));var el={exports:{}};function il(){}il.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}},el.exports=il,el.exports.TinyEmitter=il;const sl=["ABSORBEDDOSEUNIT","AMOUNTOFSUBSTANCEUNIT","AREAUNIT","DOSEEQUIVALENTUNIT","ELECTRICCAPACITANCEUNIT","ELECTRICCHARGEUNIT","ELECTRICCONDUCTANCEUNIT","ELECTRICCURRENTUNIT","ELECTRICRESISTANCEUNIT","ELECTRICVOLTAGEUNIT","ENERGYUNIT","FORCEUNIT","FREQUENCYUNIT","ILLUMINANCEUNIT","INDUCTANCEUNIT","LENGTHUNIT","LUMINOUSFLUXUNIT","LUMINOUSINTENSITYUNIT","MAGNETICFLUXDENSITYUNIT","MAGNETICFLUXUNIT","MASSUNIT","PLANEANGLEUNIT","POWERUNIT","PRESSUREUNIT","RADIOACTIVITYUNIT","SOLIDANGLEUNIT","THERMODYNAMICTEMPERATUREUNIT","TIMEUNIT","VOLUMEUNIT","USERDEFINED"],rl={IFCAPPLICATION:[{name:"ApplicationDeveloper",type:"ref"},{name:"Version",type:"string"},{name:"ApplicationFullName",type:"string"},{name:"ApplicationIdentifier",type:"string"}],IFCARBITRARYCLOSEDPROFILEDEF:["IfcProfileDef",{name:"OuterCurve",type:"ref"}],IFCARBITRARYPROFILEDEFWITHVOIDS:["IfcProfileDef",{name:"OuterCurve",type:"ref"},{name:"InnerCurves",type:"list",listType:"ref"}],IFCAXIS2PLACEMENT2D:[{name:"Location",type:"ref"},{name:"RefDirection",type:"ref",optional:!0}],IFCAXIS2PLACEMENT3D:[{name:"Location",type:"ref"},{name:"Axis",type:"ref",optional:!0},{name:"RefDirection",type:"ref",optional:!0}],IFCBOOLEANCLIPPINGRESULT:null,IFCBUILDING:["IfcRoot","IfcObject","IfcProduct","IfcSpatialStructureElement",{name:"ElevationOfRefHeight",type:"real",optional:!0},{name:"ElevationOfTerrain",type:"real",optional:!0},{name:"BuildingAddress",type:"ref",optional:!0}],IFCBUILDINGSTOREY:["IfcRoot","IfcObject","IfcProduct","IfcSpatialStructureElement",{name:"Elevation",type:"real",optional:!0}],IFCCARTESIANPOINT:[{name:"DirectionRatios",type:"list",listType:"real"}],IFCCLOSEDSHELL:[{name:"CfsFaces",type:"list",listType:"ref"}],IFCCIRCLEHOLLOWPROFILEDEF:null,IFCCIRCLEPROFILEDEF:["IfcProfileDef",{name:"Position",type:"ref"},{name:"Radius",type:"real+"}],IFCCOLOURRGB:[{name:"Name",type:"string",optional:!0},{name:"Red",type:"real"},{name:"Green",type:"real"},{name:"Blue",type:"real"}],IFCCOLUMN:["IfcRoot","IfcObject","IfcProduct","IfcElement"],IFCCOMPOSITECURVE:null,IFCCONVERSIONBASEDUNIT:["IfcNamedUnit",{name:"Name",type:"string"},{name:"ConversionFactor",type:"ref"}],IFCDERIVEDPROFILEDEF:null,IFCDIMENSIONALEXPONENTS:[{name:"LengthExponent",type:"int"},{name:"MassExponent",type:"int"},{name:"TimeExponent",type:"int"},{name:"ElectricCurrentExponent",type:"int"},{name:"ThermodynamicTemperatureExponent",type:"int"},{name:"AmountOfSubstanceExponent",type:"int"},{name:"LuminousIntensityExponent",type:"int"}],IFCDIRECTION:[{name:"DirectionRatios",type:"list",listType:"real"}],IFCDOOR:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"OverallHeight",type:"real+",optional:!0},{name:"OverallWidth",type:"real+",optional:!0}],IFCDOORLININGPROPERTIES:["IfcRoot",{name:"LiningDepth",type:"real+",optional:!0},{name:"LiningThickness",type:"real+",optional:!0},{name:"ThresholdDepth",type:"real+",optional:!0},{name:"ThresholdThickness",type:"real+",optional:!0},{name:"TransomThickness",type:"real+",optional:!0},{name:"TransomOffset",type:"real",optional:!0},{name:"LiningOffset",type:"real",optional:!0},{name:"ThresholdOffset",type:"real",optional:!0},{name:"CasingThickness",type:"real+",optional:!0},{name:"CasingDepth",type:"real+",optional:!0},{name:"ShapeAspectStyle",type:"real",optional:!0}],IFCDOORSTYLE:["IfcRoot","IfcTypeObject","IfcTypeProduct",{name:"OperationType",type:"enum",oneOf:["SINGLE_SWING_LEFT","SINGLE_SWING_RIGHT","DOUBLE_DOOR_SINGLE_SWING","DOUBLE_DOOR_SINGLE_SWING_OPPOSITE_LEFT","DOUBLE_DOOR_SINGLE_SWING_OPPOSITE_RIGHT","DOUBLE_SWING_LEFT","DOUBLE_SWING_RIGHT","DOUBLE_DOOR_DOUBLE_SWING","SLIDING_TO_LEFT","SLIDING_TO_RIGHT","DOUBLE_DOOR_SLIDING","FOLDING_TO_LEFT","FOLDING_TO_RIGHT","DOUBLE_DOOR_FOLDING","REVOLVING","ROLLINGUP","USERDEFINED","NOTDEFINED"]},{name:"ConstructionType",type:"enum",oneOf:["ALUMINIUM","HIGH_GRADE_STEEL","STEEL","WOOD","ALUMINIUM_WOOD","ALUMINIUM_PLASTIC","PLASTIC","USERDEFINED","NOTDEFINED"]},{name:"ParameterTakesPrecedence",type:"boolean"},{name:"Sizeable",type:"boolean"}],IfcElement:[{name:"Tag",type:"string",optional:!0}],IFCELEMENTASSEMBLY:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"AssemblyPlace",optional:!0,type:"enum",oneOf:["SITE","FACTORY","NOTDEFINED"]},{name:"PredefinedType",optional:!0,type:"enum",oneOf:["ACCESSORY_ASSEMBLY","ARCH","BEAM_GRID","BRACED_FRAME","GIRDER","REINFORCEMENT_UNIT","RIGID_FRAME","SLAB_FIELD","TRUSS","USERDEFINED","NOTDEFINED"]}],IFCEXTRUDEDAREASOLID:[{name:"SweptArea",type:"ref"},{name:"Position",type:"ref"},{name:"ExtrudedDirection",type:"ref"},{name:"Depth",type:"real+"}],IFCFACE:[{name:"Bounds",type:"list",listType:"ref"}],IFCFACEBASEDSURFACEMODEL:[{name:"FbsmFaces",type:"list",listType:"ref"}],IFCFACEOUTERBOUND:[{name:"Bound",type:"ref"},{name:"Orientation",type:"boolean"}],IFCFACETEDBREP:[{name:"IfcGeometricRepresentationItem",type:"ref"}],IFCFURNISHINGELEMENT:["IfcRoot","IfcObject","IfcProduct","IfcElement"],IFCGEOMETRICREPRESENTATIONCONTEXT:[{name:"ContextIdentifier",type:"string",optional:!0},{name:"ContextType",type:"string",optional:!0},{name:"CoordinateSpaceDimension",type:"int"},{name:"Precision",type:"real",optional:!0},{name:"WorldCoordinateSystem",type:"ref"},{name:"TrueNorth",type:"ref",optional:!0}],IFCISHAPEPROFILEDEF:null,IFCLENGTHMEASURE:[{name:"Measure",type:"real"}],IFCLOCALPLACEMENT:[{name:"PlacementRelTo",type:"ref",optional:!0},{name:"RelativePlacement",type:"ref"}],IFCLSHAPEPROFILEDEF:null,IFCMATERIAL:[{name:"Name",type:"string"}],IFCMATERIALDEFINITIONREPRESENTATION:null,IFCMATERIALLAYER:[{name:"Material",type:"ref",optional:!0},{name:"LayerThickness",type:"real+"},{name:"IsVentilated",type:"boolean",optional:!0}],IFCMATERIALLAYERSET:[{name:"MaterialLayers",type:"list",listType:"ref"},{name:"LayerSetName",type:"string",optional:!0}],IFCMATERIALLAYERSETUSAGE:[{name:"ForLayerSet",type:"ref"},{name:"LayerSetDirection",type:"enum",oneOf:["AXIS1","AXIS2","AXIS3"]},{name:"DirectionSense",type:"enum",oneOf:["POSITIVE","NEGATIVE"]},{name:"OffsetFromReferenceLine",type:"real"}],IfcObject:[{name:"ObjectType",type:"string",optional:!0}],IFCMEASUREWITHUNIT:[{name:"ValueComponent",type:"ifcValue"},{name:"UnitComponent",type:"ref"}],IfcNamedUnit:[{name:"Dimensions",type:"ref"},{name:"UnitType",type:"enum",oneOf:sl}],IFCOPENINGELEMENT:["IfcRoot","IfcObject","IfcProduct","IfcElement"],IFCOPENSHELL:[{name:"CfsFaces",type:"list",listType:"ref"}],IFCORGANIZATION:[{name:"Id",type:"string",optional:!0},{name:"Name",type:"string"},{name:"Description",type:"string",optional:!0},{name:"Roles",type:"list",optional:!0,listType:"ref"},{name:"Addresses",type:"list",optional:!0,listType:"ref"}],IFCOWNERHISTORY:[{name:"OwningUser",type:"ref"},{name:"OwningApplication",type:"ref"},{name:"State",type:"enum",optional:!0,oneOf:["READWRITE","READONLY","LOCKED","READWRITELOCKED","READONLYLOCKED"]},{name:"ChangeAction",type:"enum",oneOf:["NOCHANGE","MODIFIED","ADDED","DELETED","MODIFIEDADDED","MODIFIEDDELETED"]},{name:"LastModifiedDate",type:"int",optional:!0},{name:"LastModifyingUser",type:"ref",optional:!0},{name:"LastModifyingApplication",type:"ref",optional:!0},{name:"CreationDate",type:"int"}],IFCPERSON:[{name:"Id",type:"string",optional:!0},{name:"FamilyName",type:"string",optional:!0},{name:"GivenName",type:"string",optional:!0},{name:"MiddleNames",type:"list",optional:!0,listType:"string"},{name:"PrefixTitles",type:"list",optional:!0,listType:"string"},{name:"SuffixTitles",type:"list",optional:!0,listType:"string"},{name:"Roles",type:"list",optional:!0,listType:"string"},{name:"Addresses",type:"list",optional:!0,listType:"string"}],IFCPERSONANDORGANIZATION:[{name:"ThePerson",type:"ref"},{name:"TheOrganization",type:"ref"},{name:"Roles",type:"list",listType:"ref",optional:!0}],IFCPLANEANGLEMEASURE:[{name:"Measure",type:"real"}],IFCPOLYLINE:[{name:"Points",type:"list",listType:"ref"}],IFCPOLYLOOP:[{name:"Polygon",type:"list",listType:"ref"}],IFCPOSITIVELENGTHMEASURE:[{name:"Measure",type:"real+"}],IFCPRESENTATIONSTYLEASSIGNMENT:[{name:"Styles",type:"list",listType:"ref"}],IfcProduct:[{name:"ObjectPlacement",type:"ref",optional:!0},{name:"Representation",type:"ref",optional:!0}],IFCPRODUCTDEFINITIONSHAPE:["IfcProductRepresentation"],IfcProductRepresentation:[{name:"Name",type:"string",optional:!0},{name:"Description",type:"string",optional:!0},{name:"Representations",type:"list",listType:"ref"}],IfcProfileDef:[{name:"ProfileType",type:"enum",oneOf:["CURVE","AREA"]},{name:"ProfileName",type:"string",optional:!0}],IFCPROJECT:["IfcRoot","IfcObject",{name:"LongName",type:"string",optional:!0},{name:"Phase",type:"string",optional:!0},{name:"RepresentationContexts",type:"list",listType:"ref"},{name:"UnitsInContext",type:"ref"}],IFCRAILING:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"PredefinedType",type:"enum",oneOf:["HANDRAIL","GUARDRAIL","BALUSTRADE","USERDEFINED","NOTDEFINED"]}],IFCRATIOMEASURE:[{name:"Measure",type:"real"}],IFCRECTANGLEPROFILEDEF:["IfcProfileDef",{name:"Position",type:"ref"},{name:"XDim",type:"real+"},{name:"YDim",type:"real+"}],IFCRECTANGLEHOLLOWPROFILEDEF:null,IFCRELAGGREGATES:["IfcRoot",{name:"RelatingObject",type:"ref"},{name:"RelatedObjects",type:"list",listType:"ref"}],IFCRELASSOCIATESMATERIAL:["IfcRoot",{name:"RelatedObjects",type:"list",listType:"ref"},{name:"RelatingMaterial",type:"ref"}],IFCRELCONTAINEDINSPATIALSTRUCTURE:["IfcRoot",{name:"RelatedElements",type:"list",listType:"ref"},{name:"RelatingStructure",type:"ref"}],IFCRELDEFINESBYTYPE:["IfcRoot",{name:"RelatedObjects",type:"list",listType:"ref"},{name:"RelatingType",type:"ref"}],IFCRELFILLSELEMENT:["IfcRoot",{name:"RelatingOpeningElement",type:"ref"},{name:"RelatedBuildingElement",type:"ref"}],IFCRELVOIDSELEMENT:["IfcRoot",{name:"RelatingBuildingElement",type:"ref"},{name:"RelatedOpeningElement",type:"ref"}],IFCROUNDEDRECTANGLEPROFILEDEF:null,IfcRepresentation:[{name:"ContextOfItems",type:"ref",optional:!0},{name:"RepresentationIdentifier",type:"string",optional:!0},{name:"RepresentationType",type:"string",optional:!0},{name:"Items",type:"list",listType:"ref"}],IfcRoot:[{name:"GlobalId",type:"guid"},{name:"OwnerHistory",type:"ref"},{name:"Name",type:"string",optional:!0},{name:"Description",type:"string",optional:!0}],IFCSHAPEREPRESENTATION:["IfcRepresentation"],IFCSHELLBASEDSURFACEMODEL:null,IFCSITE:["IfcRoot","IfcObject","IfcProduct","IfcSpatialStructureElement",{name:"RefLatitude",type:"real",optional:!0},{name:"RefLongitude",type:"real",optional:!0},{name:"RefElevation",type:"real",optional:!0},{name:"LandTitleNumber",type:"string",optional:!0},{name:"SiteAddress",type:"ref",optional:!0}],IFCSIUNIT:[{name:"asterisk",type:"value"},{name:"UnitType",type:"enum",oneOf:sl},{name:"Prefix",type:"enum",optional:!0,oneOf:["EXA","PETA","TERA","GIGA","MEGA","KILO","HECTO","DECA","DECI","CENTI","MILLI","MICRO","NANO","PICO","FEMTO","ATTO"]},{name:"Name",type:"enum",optional:!0,oneOf:["AMPERE","BECQUEREL","CANDELA","COULOMB","CUBIC_METRE","DEGREE_CELSIUS","FARAD","GRAM","GRAY","HENRY","HERTZ","JOULE","KELVIN","LUMEN","LUX","METRE","MOLE","NEWTON","OHM","PASCAL","RADIAN","SECOND","SIEMENS","SIEVERT","SQUARE_METRE","STERADIAN","TESLA","VOLT","WATT","WEBER"]}],IFCSLAB:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"PredefinedType",type:"enum",oneOf:["FLOOR","ROOF","LANDING","BASESLAB","USERDEFINED","NOTDEFINED"]}],IFCSPACE:["IfcRoot","IfcObject","IfcProduct","IfcSpatialStructureElement",{name:"InteriorOrExteriorSpace",type:"enum",oneOf:["INTERNAL","EXTERNAL","NOTDEFINED"]},{name:"ElevationWithFlooring",type:"real",optional:!0}],IFCSTAIR:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"ShapeType",type:"enum",oneOf:["STRAIGHT_RUN_STAIR","TWO_STRAIGHT_RUN_STAIR","QUARTER_WINDING_STAIR","QUARTER_TURN_STAIR","HALF_WINDING_STAIR","HALF_TURN_STAIR","TWO_QUARTER_WINDING_STAIR","TWO_QUARTER_TURN_STAIR","THREE_QUARTER_WINDING_STAIR","THREE_QUARTER_TURN_STAIR","SPIRAL_STAIR","DOUBLE_RETURN_STAIR","CURVED_RUN_STAIR","TWO_CURVED_RUN_STAIR","USERDEFINED","NOTDEFINED"]}],IFCSTAIRFLIGHT:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"NumberOfRiser",type:"int",optional:!0},{name:"NumberOfTreads",type:"int",optional:!0},{name:"RiserHeight",type:"real+",optional:!0},{name:"TreadLength",type:"real+",optional:!0}],IFCSTYLEDITEM:[{name:"Item",type:"ref",optional:!0},{name:"Styles",type:"list",listType:"ref"},{name:"Name",type:"string",optional:!0}],IFCSURFACESTYLE:[{name:"Name",type:"string",optional:!0},{name:"Side",type:"enum",oneOf:["POSITIVE","NEGATIVE","BOTH"]},{name:"Styles",type:"list",listType:"ref"}],IFCSURFACESTYLERENDERING:[{name:"SurfaceColour",type:"ref"},{name:"Transparency",type:"real",optional:!0},{name:"DiffuseColour",type:"real+",optional:!0},{name:"TransmissionColour",type:"real+",optional:!0},{name:"DiffuseTransmissionColour",type:"real+",optional:!0},{name:"ReflectionColour",type:"real+",optional:!0},{name:"SpecularColour",type:"real+",optional:!0},{name:"SpecularHighlight",type:"real+",optional:!0},{name:"ReflectanceMethod",type:"enum",oneOf:["PHONG","NOTDEFINED"]}],IFCTSHAPEPROFILEDEF:null,IfcSpatialStructureElement:[{name:"LongName",type:"string",optional:!0},{name:"CompositionType",type:"enum",oneOf:["COMPLEX","ELEMENT","PARTIAL"]}],IfcTypeObject:[{name:"ApplicableOccurrence",type:"string",optional:!0},{name:"HasPropertySets",type:"list",listType:"ref",optional:!0}],IfcTypeProduct:[{name:"RepresentationMaps",type:"list",listType:"ref",optional:!0},{name:"Tag",type:"string",optional:!0}],IFCUNITASSIGNMENT:[{name:"Units",type:"list",listType:"ref"}],IFCUSHAPEPROFILEDEF:null,IFCWALL:["IfcRoot","IfcObject","IfcProduct","IfcElement"],IFCWALLSTANDARDCASE:["IfcRoot","IfcObject","IfcProduct","IfcElement"],IFCWINDOW:["IfcRoot","IfcObject","IfcProduct","IfcElement",{name:"OverallHeight",type:"real+",optional:!0},{name:"OverallWidth",type:"real+",optional:!0}]};function nl(t){const e=["boolean","enum","guid","int","ifcValue","list","real","real+","ref","string","value"];if(!e.includes(t.type))throw new Error("Invalid type "+t.type);if(!("list"!==t.type||t.listType&&e.includes(t.listType)))throw new Error("Invalid listType "+t.listType);if(!t.name||"string"!=typeof t.name)throw new Error("Invalid name "+t.name);return!0}!function t(e){var i;let s=e?[e]:Object.keys(rl),r={};for(let n of s)rl[n]&&(r[n]=[],null==(i=rl[n])||i.forEach((e=>{if("string"==typeof e){if(!rl[e])throw new Error("Invalid type inheritance");let i=t(e)[e];r[n].push(...i)}else nl(e)&&r[n].push(e)})));return r}();for(var ol=[],al=0;al<256;++al)ol.push((al+256).toString(16).substr(1));function ll(t,e,i){let s=ho(...t),r=ho(...e),n=ho(...i),o=ao(),a=ao(),l=ao();return po(o,s,n),po(a,r,n),mo(l,o,a),fo(l,l),[...l]}function hl(t){let{indices:e,vertices:i}=t,s=[],r=[],n=[],o=function(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}(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];ll(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=K(V(n),.0015);h=h.filter((t=>t&&t.length&&Z(t)>5e-4));for(let u of h)wa(u)?l[0].push(u):a.push(u);return{outlines:a,holes:l,boundingBox:o}}function ul(t,e,i=new Map){let s=function(t,e){let{position:i,rotation:s,rotationAxis:r}=t.getTransform(),n=Ea(i,s,r);return e&&ro(n,e,n),n}(t,e),r=function(t,e=to(),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){Qo.warn(`Geometry ${o} not found.`);continue}a=[0,0,0],l=0,h=[0,1,0]}else{if("reference:geometry"!==o.type){Qo.warn(`Operation ${o.type} not supported.`);continue}let e=o.geometry;if("string"==typeof e){if(t=n.geometriesById[e],!t){Qo.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=ba(a,l);for(let o of u){let a=Ea(o.position,o.rotation,h);s&&(a=ro(to(),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(...Ka(e,n.geometriesById,n.materialsById,[]))}}else l=Ka(t,n.geometriesById,n.materialsById,[]);let u=vo(),c=ao();oo(u,a),no(c,a);for(let t of l)Pa(t.vertices,a);r.push({meshes:l,rotation:u,position:c})}}return r}(t,s,i),n=[];for(let o of r)for(let t of o.meshes)n.push(hl(t));return n}const cl={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"]}]}},dl={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"},pl={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:"Avenir, Verdana, sans-serif",background:{color:dl.whisper,showGrid:!1},wallContours:!1,showAssetTextures:!1,elements:{floorPlan:{grayscale:!1},roomStamp:{showArea:!0,showUsage:!0}}},units:{system:"metric",areaDecimals:0,lengthDecimals:3,roomDimensions:"area"},zoomRange:[3,300]};let fl="archilogic/product",ml="https://storage.archilogic.com";function gl(t,e="Floor plan engine couldn't load properly on this page. For technical details check the browser console."){const i=document.getElementById(t),s=i.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}(i);s.querySelector(".fpe-err__msg").textContent=e}let yl=new P(["info","warnings","errors"]);function vl(t,e){let i,s=e.product.geometries[0];if("string"==typeof s){let t=s;i=e.spaceGraph.geometriesById[t]}else"reference:geometry"===(null==s?void 0:s.type)&&"string"!=typeof s.geometry&&(i=s.geometry);return"geometry:uri"===(null==i?void 0:i.type)?t.loader.loadResources(e.product.id,e,["productJson","productContour"]).catch((t=>yl.error(t))):Promise.reject("Unsupported product geometry: "+e.product.id)}const xl=t=>{const e=[];return t.layout.elementsByType["element:asset"].forEach((t=>{"product"in t&&t.product&&e.push(t)})),Promise.allSettled(e.map((e=>vl(t,e))))};function bl(t){return fetch(`${ml}/${fl}/outline/${t}.json`).then((t=>{if(t.ok)return t.json();throw Error(t.statusText)}))}const _l="undefined"==typeof window||"undefined"!=typeof process;let wl;try{wl=!_l&&Mn("al-kvs","al-keyval")}catch(Vx){yl.warn("indexedDb initialization failed")}let El=!0;async function Pl(t,e,i){if(!wl)return Promise.resolve();i=i||2592e6;try{const s={timeStamp:(new Date).getTime(),content:e,maxAge:i};return El&&await function(t,e,i=On()){return i("readwrite",(i=>(i.put(e,t),Cn(i.transaction))))}(t,s,wl),t}catch(s){return}}async function Tl(t,e){if(!wl)return Promise.resolve();const i=e||2592e6,s=(new Date).getTime();let r;try{El&&(r=await function(t,e=On()){return e("readonly",(e=>Cn(e.get(t))))}(t,wl));const e=s-r.timeStamp;if(e>Math.min(r.maxAge,i))return;if(r.content)return r.content}catch(n){return}}const Il="fpe-dc2-";var Al=(t=>(t[t.None=0]="None",t[t.Default=1]="Default",t[t.Grayscale=2]="Grayscale",t))(Al||{});class Sl extends kn{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=Cl(t,this,e.product);break;case"productContour":this.loadStages.productTexture&&this._requestCounter++,s=Ml(t,this).then((()=>{if(this.loadStages.productTexture&&!this.resources.texture.has(t)){if(!this.resources.productJson.has(t))return void yl.warn("texture loading failed, no product info yet");const e=`${ml}/${fl}/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 Cl=(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])||(yl.warn("invalid product bounding box"),delete n.boundingBox),e.resources.productJson.set(t,n),Promise.resolve().then((()=>{e.emit("resource-loaded",{resourceId:t})}))},Ml=async(t,e)=>{const i=Il+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=Il+t,n=e.promiseCache.get(r);if(n)return n;const o=Tl(r,i).then((e=>e||bl(t).then((t=>(Pl(r,t,s),t))))).catch((t=>{yl.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){yl.warn("product boundingbox missing - creating from contour");let t=z(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 Nl(t){return t.max.map(((e,i)=>e-t.min[i]))}function Ol(t){let e=function(t){return[t.vertices[0].position,t.vertices[1].position]}(t);return 180*we(e[0],e[1])/Math.PI}function Rl(t){switch(t.type){case"element:ceiling":case"element:floor":case"element:curtainWall":case"element:beam":case"element:ramp":case"element:roof":case"element:slab":case"element:stairFlight":default:return;case"element:boundaryWall":return function(t){return{objectAlignedBoundingBox:t.boundaries[0].vertices.map((t=>t.position)),elementIsAxisAligned:!1}}(t);case"element:spaceDivider":return Ll(t.edge);case"element:wall":return function(t){const{points:e}=t.geometryProfile;return{objectAlignedBoundingBox:e,elementIsAxisAligned:Ol(t.edge)%90==0}}(t);case"element:opening":return function(t){const e=t.parent;let i=[[0,0],[t.parameters.dimensions[0],0],[t.parameters.dimensions[0],e.parameters.width],[0,e.parameters.width]];const s=t.getTransform();let r=s.position[0],n=s.position[2],o=s.rotation;return{objectAlignedBoundingBox:ke(i,{position:[r,n],rotation:o}),elementIsAxisAligned:o%90==0}}(t);case"element:asset":return kl(t);case"element:casework":case"element:column":case"element:door":case"element:generic":case"element:kitchen":case"element:railing":case"element:stairs":case"element:window":return function(t){let e=[],i=t.position[0],s=t.position[2],r=t.rotation;switch(t.type){case"element:casework":case"element:kitchen":e=[[0,0],[t.parameters.length,0],[t.parameters.length,t.parameters.width],[0,t.parameters.width]];break;case"element:railing":e=[[0,-t.parameters.width/2],[t.parameters.length,-t.parameters.width/2],[t.parameters.length,t.parameters.width/2],[0,t.parameters.width/2]];break;case"element:stairs":switch(t.parameters.stairsType){case"straight":case"straightLanding":e=[[0,0],[t.parameters.length,0],[t.parameters.length,t.parameters.width],[0,t.parameters.width]];break;case"halfLanding":case"quarterLanding":case"twoQuarterLanding":{const i="right"===t.parameters.circulation?1:-1;e=[[0,0],[t.parameters.length,0],[t.parameters.length,i*t.parameters.width],[0,i*t.parameters.width]]}break;case"spiral":{const i="right"===t.parameters.circulation?1:-1;e=[[-t.parameters.radius,0],[t.parameters.radius,0],[t.parameters.radius,2*i*t.parameters.radius],[-t.parameters.radius,2*i*t.parameters.radius]]}}break;case"element:column":switch(t.parameters.profile.type){case"curve:rectangle":e=[[-t.parameters.profile.dimensions[0]/2,-t.parameters.profile.dimensions[1]/2],[t.parameters.profile.dimensions[0]/2,-t.parameters.profile.dimensions[1]/2],[t.parameters.profile.dimensions[0]/2,t.parameters.profile.dimensions[1]/2],[-t.parameters.profile.dimensions[0]/2,t.parameters.profile.dimensions[1]/2]];break;case"curve:circle":e=[[-t.parameters.profile.radius,-t.parameters.profile.radius],[t.parameters.profile.radius,-t.parameters.profile.radius],[t.parameters.profile.radius,t.parameters.profile.radius],[-t.parameters.profile.radius,t.parameters.profile.radius]]}break;case"element:window":case"element:door":{const n=t.parent.parent;e=[[0,0],[t.parameters.length,0],[t.parameters.length,n.parameters.width],[0,n.parameters.width]];const o=t.getWorldTransform();i=o.position[0],s=o.position[2],r=o.rotation}break;case"element:generic":if("none"!==t.parameters.profile&&"curve:polygon"===t.parameters.profile.type){const{min:i,max:s}=z([t.parameters.profile.points]);e=[[i[0],i[1]],[i[0],s[1]],[s[0],s[1]],[s[0],i[1]]]}}return{objectAlignedBoundingBox:ke(e,{position:[i,s],rotation:r}),elementIsAxisAligned:r%90==0}}(t);case"spatialGraph:edge":return Ll(t);case"layout:space":return{objectAlignedBoundingBox:t.geometry.polygons[0],elementIsAxisAligned:!1}}}function Ll(t){var e;return"element:wall"===(null==(e=t.element)?void 0:e.type)||t.boundaryWalls.some((t=>null!==t))?{objectAlignedBoundingBox:[],elementIsAxisAligned:!1}:{objectAlignedBoundingBox:[t.vertices[0].position,t.vertices[1].position],elementIsAxisAligned:Ol(t)%90==0}}function kl(t){const e=t.product.attributes.boundingBox,i=[[e.min[0],e.min[2]],[e.max[0],e.min[2]],[e.max[0],e.max[2]],[e.min[0],e.max[2]]],s=t.getWorldTransform();return{objectAlignedBoundingBox:ke(i,{position:[s.position[0],s.position[2]],rotation:s.rotation}),elementIsAxisAligned:s.rotation%90==0}}const Fl=class t{constructor({options:t={}}={}){this.settings=b(pl),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 kn,jt.setLevels("errors"),this.set(t),this.loader=new Sl(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||(Sn(this.layout),function(t){for(let e of t.elements)ss(e)}(this.layout)),setTimeout((()=>{this.loader.emit("spaces-loaded")}),0),xl(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=>yl.warn(t))),this.loader.initialLoading=!1):yl.warn("No layout to load")}loadSpaceGraphJson(t){this.loadSpaceGraph(function(t){let e=new Tr;return Jr(e,t),e}(t))}async loadFloorById(e,i=this.settings.api){return new Promise((async(s,r)=>{var n;e&&"string"==typeof e||r(`Expected non-empty string floorId parameter; instead got: "${e}"`);try{const r=D({...i,sdkVersion:t.version}),a=new X(r);this.loader.once("assets-loaded",s);const l=await a.getFloorById(e,!1,!1,!0),h=null==(n=l.properties)?void 0:n.address;if(o(null==h?void 0:h.latitude,90)&&(this.location.latitude=h.latitude),function(t){return o(t,180)}(null==h?void 0:h.longitude)&&(this.location.longitude=h.longitude),function(t){return o(t,180)}(null==h?void 0:h.bearing)&&(this.location.bearing=h.bearing),!l.properties.defaultLayoutId)throw new Error(`The floor ${e} has no space graph layout`);const u=await a.getLayout(l.properties.defaultLayoutId);!function(t){var e;null==(e=document.querySelector(`#${t} .fpe-err`))||e.remove()}(this.fpeId),this.loadSpaceGraphJson(u.layout)}catch(Vx){r(Vx)}})).catch((t=>{throw gl(this.fpeId,t),t}))}set(t={}){var e,i,s,r,n;const o=null==(e=this.settings.hideElements)?void 0:e.includes("element:asset");let a=b(t);a.theme&&(a.theme=_(pl.theme,a.theme)),a.ui&&(a.ui={...pl.ui,...a.ui}),a.api&&(a.api={...pl.api,...a.api}),a.units&&(a.units={...pl.units,...a.units});const l=!(null==(i=a.hideElements)?void 0:i.includes("element:asset"));for(let h in a)this.settings[h]=a[h];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&&o&&l&&xl(this),this.emit("update-settings",this.settings)}getResourcesFromPosition(t){const e=this.layout.spaces.filter((e=>Te(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=kl(e).objectAlignedBoundingBox;return(null==i?void 0:i.length)?q(t,i):void 0}));i.push(...s)})),{spaces:e,assets:i}}destroy(){delete this.layout,delete this.settings,delete this.utils}};Fl.version="5.0.0-rc.1";let Dl=Fl;function Bl(t){let e=[];switch(t.type){case"element:door":e=function(t){let{length:e,hingeSide:i,doorSide:s,doorAngle:r,doorType:n,frameThickness:o,frameDepth:a}=t.parameters,{position:l,rotation:h}=t.getWorldTransform(),u=[],c="right"===i,d="side1"===s,p=d?0:a;if(0===r)return u;if("singleSwing"===n){let t,i,s,n=e-2*o;d?c?(t=0,i=r,s=[o,p]):(t=180-r,i=180,s=[e-o,p]):c?(t=-180,i=-180+r,s=[e-o,p]):(t=360-r,i=360,s=[o,p]),u.push({type:"curve:arc",radius:n,position:s,startAngle:t,endAngle:i})}else if("doubleSwing"===n){let t,i,s,n,a,l,h=e/2-o;d?(t=0,i=r,s=[o,p],l=[e-o,p],n=180-r,a=180):(t=360-r,i=360,s=[o,p],l=[e-o,p],n=180,a=180+r),u.push({type:"curve:arc",radius:h,position:s,startAngle:t,endAngle:i}),u.push({type:"curve:arc",radius:h,position:l,startAngle:n,endAngle:a})}return[{type:"group",position:[l[0],l[2]],rotation:h,children:u}]}(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,{position:o,rotation:a}=t.getWorldTransform(),l=r/Math.round(n/.17),h=[[l/2-.06,s/2+.12],[l/2+.06,s/2],[l/2-.06,s/2-.12]];return[{type:"group",position:[o[0],o[2]],rotation:a,children:[{type:"curve:polyline",points:h}]}]}(t)}return e}const Ul=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Gl(t){return"string"==typeof t&&Ul.test(t)}function Xl(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=Gl(t.id)?t.id.substring(0,4):t.id;t.element&&(e=Gl(t.element.id)?t.element.id.substring(0,4):t.element.id);let o=t.element?`${r} (${e})`:r;n.push({type:"text",position:he(i.position,ye(ve(s.position,i.position),.5)),text:o,fontSize:10})}if(null===t.element||"element:spaceDivider"===t.element.type){let t=me(ge(ve(s.position,i.position))),e=.02,o=he(i.position,ye(t,-e)),a=he(i.position,ye(t,e)),l=he(s.position,ye(t,e)),h=he(s.position,ye(t,-e));n.unshift({type:"curve:polygon",points:[o,a,l,h],style:{stroke:null,fill:r?dl.blue_ribbon:dl.whisper,fillOpacity:.1}})}return n}function Hl(t){let{dimensions:e}=t.parameters,i=t.parent;if(!i)return[];let s=i.parameters.width,r=[[0,0],[e[0],0],[e[0],s],[0,s]];return function(t,e){let i=ot();for(let s of t)i[0]=s[0],i[1]=0,i[2]=s[1],lt(i,i,e),s[0]=i[0],s[1]=i[2]}(r,Me(t.position,t.rotation,[0,1,0])),[{type:"curve:polygon",points:r}]}var Wl,Yl={grad:.9,turn:360,rad:360/(2*Math.PI)},$l=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},zl=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},Vl=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},jl=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},ql=function(t){return{r:Vl(t.r,0,255),g:Vl(t.g,0,255),b:Vl(t.b,0,255),a:Vl(t.a)}},Jl=function(t){return{r:zl(t.r),g:zl(t.g),b:zl(t.b),a:zl(t.a,3)}},Zl=/^#([0-9a-f]{3,8})$/i,Kl=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Ql=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}},th=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}},eh=function(t){return{h:jl(t.h),s:Vl(t.s,0,100),l:Vl(t.l,0,100),a:Vl(t.a)}},ih=function(t){return{h:zl(t.h),s:zl(t.s),l:zl(t.l),a:zl(t.a,3)}},sh=function(t){return th((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},rh=function(t){return{h:(e=Ql(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},nh=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,oh=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ah=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,lh=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,hh={string:[[function(t){var e=Zl.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?zl(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?zl(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=ah.exec(t)||lh.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:ql({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=nh.exec(t)||oh.exec(t);if(!e)return null;var i,s,r=eh({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(Yl[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return sh(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 $l(e)&&$l(i)&&$l(s)?ql({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(!$l(e)||!$l(i)||!$l(s))return null;var o=eh({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return sh(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!$l(e)||!$l(i)||!$l(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:jl(o.h),s:Vl(o.s,0,100),v:Vl(o.v,0,100),a:Vl(o.a)});return th(a)},"hsv"]]},uh=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]},ch=function(t,e){var i=rh(t);return{h:i.h,s:Vl(i.s+100*e,0,100),l:i.l,a:i.a}},dh=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},ph=function(t,e){var i=rh(t);return{h:i.h,s:i.s,l:Vl(i.l+100*e,0,100),a:i.a}},fh=function(){function t(t){this.parsed=function(t){return"string"==typeof t?uh(t.trim(),hh.string):"object"==typeof t&&null!==t?uh(t,hh.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 zl(dh(this.rgba),2)},t.prototype.isDark=function(){return dh(this.rgba)<.5},t.prototype.isLight=function(){return dh(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=Jl(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?Kl(zl(255*r)):"","#"+Kl(e)+Kl(i)+Kl(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return Jl(this.rgba)},t.prototype.toRgbString=function(){return e=(t=Jl(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 ih(rh(this.rgba))},t.prototype.toHslString=function(){return e=(t=ih(rh(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=Ql(this.rgba),{h:zl(t.h),s:zl(t.s),v:zl(t.v),a:zl(t.a,3)};var t},t.prototype.invert=function(){return mh({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),mh(ch(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),mh(ch(this.rgba,-t))},t.prototype.grayscale=function(){return mh(ch(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),mh(ph(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),mh(ph(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?mh({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):zl(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=rh(this.rgba);return"number"==typeof t?mh({h:t,s:e.s,l:e.l,a:e.a}):zl(e.h)},t.prototype.isEqual=function(t){return this.toHex()===mh(t).toHex()},t}(),mh=function(t){return t instanceof fh?t:new fh(t)},gh=[];Wl=[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"])}],Wl.forEach((function(t){gh.indexOf(t)<0&&(t(fh,hh),gh.push(t))}));const yh=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=mh(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)}};yh.shared=new yh,yh.temp=new yh,yh.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let vh=yh;function xh(t){for(const e of Object.keys(cl.programs)){if(cl.programs[e].find((e=>e.name===t)))return e}return""}function bh(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 _h={default:{fill:dl.white,stroke:dl.warsaw,strokeWidth:"native",fillOpacity:1},selected:{fill:dl.zurich_48,stroke:dl.warsaw,strokeWidth:1}};function wh(t){return"number"==typeof t?t:"string"==typeof t?new vh(t).toNumber():Array.isArray(t)?new vh(t.map((t=>t/255))).toNumber():void 0}const Eh=({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=xh(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=wh(e)),s&&(n.stroke=wh(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||{})},Ph=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{}},Th=({style:t,settings:e,element:i,elementType:s})=>{const r="selected"===t?"selected":"default",n=s||(null==i?void 0:i.type),o=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:dl.stone,stroke:dl.stone},selected:{fill:dl.oslo,stroke:dl.blue_ribbon,strokeWidth:"native"}},"element:boundaryWall":{default:{fill:dl.stone,stroke:dl.new_york},selected:{fill:dl.oslo,stroke:dl.blue_ribbon}},"element:curtainWall":{default:{fill:dl.stone_08},selected:{strokeWidth:"native"}},"element:column":{default:{fill:dl.stone,stroke:dl.stone},selected:{fill:dl.oslo,stroke:dl.blue_ribbon,strokeWidth:"native"}},"element:asset":{default:{fill:n?null:dl.stone_08},selected:{fill:dl.zurich_48,stroke:dl.blue_ribbon,strokeWidth:2.5}},"element:stairs":{default:{fill:dl.whisper},selected:{strokeWidth:"native"}},"element:stairFlight":{default:{fill:dl.whisper}},"element:slab":{default:{fill:dl.whisper}},"layout:space":(()=>{const e={default:{fill:dl.white,stroke:dl.gray},selected:{fill:dl.zurich_48,stroke:dl.gray,strokeWidth:"native"}};if(t&&"layout:space"===t.type){const i="kitchen"!==t.attributes.usage&&xh(t.attributes.usage),s={care:dl.gray,circulate:dl.whisper};i&&s[i]&&(e.default.fill=s[i]),"void"===i&&(e.default.fillOpacity=.05)}return e})(),"spatialGraph:edge":{default:{fill:dl.gray,stroke:dl.new_york,strokeOpacity:.8,strokeWidth:.5},selected:{stroke:dl.blue_ribbon,strokeWidth:.5}},"element:spaceDivider":{default:{fill:dl.gray,stroke:dl.new_york,strokeOpacity:.8,strokeWidth:.5},selected:{stroke:dl.blue_ribbon,strokeWidth:.5}}}[i]||_h;return"selected"===s?{..._h.default,...o.default,..._h.selected,...o.selected}:{..._h.default,...o.default}}({element:i,elementType:n,settings:e,state:r});return{...o,...Eh({element:i,elementType:n,settings:e}),...t?{}:Ph(i),..."object"==typeof t?t:{}}};function Ih(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 Ah(t,e,i,s=5){const r=[];let n,o,a,l=0;for(let h=0;h<=s;++h)l=h/s,n=Ih(t,e,l),o=Ih(e,i,l),a=Ih(n,o,l),r.push(a);return r}const Sh=(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))},Ch=t=>{const e={type:"curve:polygon",points:[]};switch(t.type){case"curve:circle":const i=t.radius,s=Sh(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;e.points=[[0,0],[0,a[1]],[a[0],a[1]],[a[0],0]];break;case"curve:composite":for(const l of t.segments){let t=Mh(l);e.points.push(...t.points)}}return e},Mh=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=Sh(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=Ah(0===h?i:Ih(i,s),s,h===t.points.length-3?r:Ih(s,r));e.points.push(...n.slice(1))}}return e},Nh=(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};var Oh=(t=>(t[t.WEBGL_LEGACY=0]="WEBGL_LEGACY",t[t.WEBGL=1]="WEBGL",t[t.WEBGL2=2]="WEBGL2",t))(Oh||{}),Rh=(t=>(t[t.UNKNOWN=0]="UNKNOWN",t[t.WEBGL=1]="WEBGL",t[t.CANVAS=2]="CANVAS",t))(Rh||{}),Lh=(t=>(t[t.COLOR=16384]="COLOR",t[t.DEPTH=256]="DEPTH",t[t.STENCIL=1024]="STENCIL",t))(Lh||{}),kh=(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))(kh||{}),Fh=(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))(Fh||{}),Dh=(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))(Dh||{}),Bh=(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))(Bh||{}),Uh=(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))(Uh||{}),Gh=(t=>(t[t.FLOAT=0]="FLOAT",t[t.INT=1]="INT",t[t.UINT=2]="UINT",t))(Gh||{}),Xh=(t=>(t[t.NEAREST=0]="NEAREST",t[t.LINEAR=1]="LINEAR",t))(Xh||{}),Hh=(t=>(t[t.CLAMP=33071]="CLAMP",t[t.REPEAT=10497]="REPEAT",t[t.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",t))(Hh||{}),Wh=(t=>(t[t.OFF=0]="OFF",t[t.POW2=1]="POW2",t[t.ON=2]="ON",t[t.ON_MANUAL=3]="ON_MANUAL",t))(Wh||{}),Yh=(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))(Yh||{}),$h=(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))($h||{}),zh=(t=>(t[t.AUTO=0]="AUTO",t[t.MANUAL=1]="MANUAL",t))(zh||{}),Vh=(t=>(t.LOW="lowp",t.MEDIUM="mediump",t.HIGH="highp",t))(Vh||{}),jh=(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))(jh||{}),qh=(t=>(t[t.NONE=0]="NONE",t[t.LOW=2]="LOW",t[t.MEDIUM=4]="MEDIUM",t[t.HIGH=8]="HIGH",t))(qh||{}),Jh=(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))(Jh||{});const Zh={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 Kh=/iPhone/i,Qh=/iPod/i,tu=/iPad/i,eu=/\biOS-universal(?:.+)Mac\b/i,iu=/\bAndroid(?:.+)Mobile\b/i,su=/Android/i,ru=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,nu=/Silk/i,ou=/Windows Phone/i,au=/\bWindows(?:.+)ARM\b/i,lu=/BlackBerry/i,hu=/BB10/i,uu=/Opera Mini/i,cu=/\b(CriOS|Chrome)(?:.+)Mobile/i,du=/Mobile(?:.+)Firefox\b/i,pu=function(t){return void 0!==t&&"MacIntel"===t.platform&&"number"==typeof t.maxTouchPoints&&t.maxTouchPoints>1&&"undefined"==typeof MSStream};function fu(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(Kh)&&!r(ou),ipod:r(Qh),tablet:!r(Kh)&&(r(tu)||pu(e))&&!r(ou),universal:r(eu),device:(r(Kh)||r(Qh)||r(tu)||r(eu)||pu(e))&&!r(ou)},amazon:{phone:r(ru),tablet:!r(ru)&&r(nu),device:r(ru)||r(nu)},android:{phone:!r(ou)&&r(ru)||!r(ou)&&r(iu),tablet:!r(ou)&&!r(ru)&&!r(iu)&&(r(nu)||r(su)),device:!r(ou)&&(r(ru)||r(nu)||r(iu)||r(su))||r(/\bokhttp\b/i)},windows:{phone:r(ou),tablet:r(au),device:r(ou)||r(au)},other:{blackberry:r(lu),blackberry10:r(hu),opera:r(uu),firefox:r(du),chrome:r(cu),device:r(lu)||r(hu)||r(uu)||r(du)||r(cu)},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 mu=(fu.default??fu)(globalThis.navigator);Zh.RETINA_PREFIX=/@([0-9\.]+)x/,Zh.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var gu={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}(gu);const yu=vt(gu.exports);var vu={exports:{}};
10
+ /*! https://mths.be/punycode v1.3.2 by @mathias */!function(t,e){!function(i){var s=e&&!e.nodeType&&e,r=t&&!t.nodeType&&t,n="object"==typeof yt&&yt;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,E=String.fromCharCode;function P(t){throw RangeError(b[t])}function T(t,e){for(var i=t.length,s=[];i--;)s[i]=e(t[i]);return s}function I(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 A(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+=E((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=E(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 N(t){var e,i,s,r,n,o,a,d,p,y,v,x=[],b=t.length,_=0,E=m,T=f;for((i=t.lastIndexOf(g))<0&&(i=0),s=0;s<i;++s)t.charCodeAt(s)>=128&&P("not-basic"),x.push(t.charCodeAt(s));for(r=i>0?i+1:0;r<b;){for(n=_,o=1,a=h;r>=b&&P("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))&&P("overflow"),_+=d*o,!(d<(p=a<=T?u:a>=T+c?c:a-T));a+=h)o>w(l/(y=h-p))&&P("overflow"),o*=y;T=M(_-n,e=x.length+1,0==n),w(_/e)>l-E&&P("overflow"),E+=w(_/e),_%=e,x.splice(_++,0,E)}return S(x)}function O(t){var e,i,s,r,n,o,a,d,p,y,v,x,b,_,T,I=[];for(x=(t=A(t)).length,e=m,i=0,n=f,o=0;o<x;++o)(v=t[o])<128&&I.push(E(v));for(s=r=I.length,r&&I.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))&&P("overflow"),i+=(a-e)*b,e=a,o=0;o<x;++o)if((v=t[o])<e&&++i>l&&P("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,I.push(E(C(y+T%_,0))),d=w(T/_);I.push(E(C(d,0))),n=M(i,b,s==r),i=0,++s}++i,++e}return I.join("")}if(o={version:"1.3.2",ucs2:{decode:A,encode:S},decode:N,encode:O,toASCII:function(t){return I(t,(function(t){return v.test(t)?"xn--"+O(t):t}))},toUnicode:function(t){return I(t,(function(t){return y.test(t)?N(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}(yt)}(vu,vu.exports);var xu=vu.exports,bu={};function _u(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var wu=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};bu.decode=bu.parse=function(t,e,i,s){e=e||"&",i=i||"=";var r={};if("string"!=typeof t||0===t.length)return r;var n=/\+/g;t=t.split(e);var o=1e3;s&&"number"==typeof s.maxKeys&&(o=s.maxKeys);var a=t.length;o>0&&a>o&&(a=o);for(var l=0;l<a;++l){var h,u,c,d,p=t[l].replace(n,"%20"),f=p.indexOf(i);f>=0?(h=p.substr(0,f),u=p.substr(f+1)):(h=p,u=""),c=decodeURIComponent(h),d=decodeURIComponent(u),_u(r,c)?Array.isArray(r[c])?r[c].push(d):r[c]=[r[c],d]:r[c]=d}return r},bu.encode=bu.stringify=function(t,e,i,s){return e=e||"&",i=i||"=",null===t&&(t=void 0),"object"==typeof t?Object.keys(t).map((function(s){var r=encodeURIComponent(wu(s))+i;return Array.isArray(t[s])?t[s].map((function(t){return r+encodeURIComponent(wu(t))})).join(e):r+encodeURIComponent(wu(t[s]))})).join(e):s?encodeURIComponent(wu(s))+i+encodeURIComponent(wu(t)):""};var Eu=xu,Pu=Gu,Tu=function(t,e){return Gu(t,!1,!0).resolve(e)},Iu=function(t){Xu(t)&&(t=Gu(t));return t instanceof Au?t.format():Au.prototype.format.call(t)};function Au(){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 Su=/^([a-z0-9.+-]+:)/i,Cu=/:[0-9]*$/,Mu=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),Nu=["'"].concat(Mu),Ou=["%","/","?",";","#"].concat(Nu),Ru=["/","?","#"],Lu=/^[a-z0-9A-Z_-]{0,63}$/,ku=/^([a-z0-9A-Z_-]{0,63})(.*)$/,Fu={javascript:!0,"javascript:":!0},Du={javascript:!0,"javascript:":!0},Bu={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},Uu=bu;function Gu(t,e,i){if(t&&Hu(t)&&t instanceof Au)return t;var s=new Au;return s.parse(t,e,i),s}function Xu(t){return"string"==typeof t}function Hu(t){return"object"==typeof t&&null!==t}function Wu(t){return null===t}Au.prototype.parse=function(t,e,i){if(!Xu(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var s=t;s=s.trim();var r=Su.exec(s);if(r){var n=(r=r[0]).toLowerCase();this.protocol=n,s=s.substr(r.length)}if(i||r||s.match(/^\/\/[^@\/]+@[^@\/]+/)){var o="//"===s.substr(0,2);!o||r&&Du[r]||(s=s.substr(2),this.slashes=!0)}if(!Du[r]&&(o||r&&!Bu[r])){for(var a,l,h=-1,u=0;u<Ru.length;u++){-1!==(c=s.indexOf(Ru[u]))&&(-1===h||c<h)&&(h=c)}-1!==(l=-1===h?s.lastIndexOf("@"):s.lastIndexOf("@",h))&&(a=s.slice(0,l),s=s.slice(l+1),this.auth=decodeURIComponent(a)),h=-1;for(u=0;u<Ou.length;u++){var c;-1!==(c=s.indexOf(Ou[u]))&&(-1===h||c<h)&&(h=c)}-1===h&&(h=s.length),this.host=s.slice(0,h),s=s.slice(h),this.parseHost(),this.hostname=this.hostname||"";var d="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!d)for(var p=this.hostname.split(/\./),f=(u=0,p.length);u<f;u++){var m=p[u];if(m&&!m.match(Lu)){for(var g="",y=0,v=m.length;y<v;y++)m.charCodeAt(y)>127?g+="x":g+=m[y];if(!g.match(Lu)){var x=p.slice(0,u),b=p.slice(u+1),_=m.match(ku);_&&(x.push(_[1]),b.unshift(_[2])),b.length&&(s="/"+b.join(".")+s),this.hostname=x.join(".");break}}}if(this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),!d){var w=this.hostname.split("."),E=[];for(u=0;u<w.length;++u){var P=w[u];E.push(P.match(/[^A-Za-z0-9_-]/)?"xn--"+Eu.encode(P):P)}this.hostname=E.join(".")}var T=this.port?":"+this.port:"",I=this.hostname||"";this.host=I+T,this.href+=this.host,d&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==s[0]&&(s="/"+s))}if(!Fu[n])for(u=0,f=Nu.length;u<f;u++){var A=Nu[u],S=encodeURIComponent(A);S===A&&(S=escape(A)),s=s.split(A).join(S)}var C=s.indexOf("#");-1!==C&&(this.hash=s.substr(C),s=s.slice(0,C));var M=s.indexOf("?");if(-1!==M?(this.search=s.substr(M),this.query=s.substr(M+1),e&&(this.query=Uu.parse(this.query)),s=s.slice(0,M)):e&&(this.search="",this.query={}),s&&(this.pathname=s),Bu[n]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){T=this.pathname||"",P=this.search||"";this.path=T+P}return this.href=this.format(),this},Au.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&&Hu(this.query)&&Object.keys(this.query).length&&(n=Uu.stringify(this.query));var o=this.search||n&&"?"+n||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||Bu[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},Au.prototype.resolve=function(t){return this.resolveObject(Gu(t,!1,!0)).format()},Au.prototype.resolveObject=function(t){if(Xu(t)){var e=new Au;e.parse(t,!1,!0),t=e}var i=new Au;if(Object.keys(this).forEach((function(t){i[t]=this[t]}),this),i.hash=t.hash,""===t.href)return i.href=i.format(),i;if(t.slashes&&!t.protocol)return Object.keys(t).forEach((function(e){"protocol"!==e&&(i[e]=t[e])})),Bu[i.protocol]&&i.hostname&&!i.pathname&&(i.path=i.pathname="/"),i.href=i.format(),i;if(t.protocol&&t.protocol!==i.protocol){if(!Bu[t.protocol])return Object.keys(t).forEach((function(e){i[e]=t[e]})),i.href=i.format(),i;if(i.protocol=t.protocol,t.host||Du[t.protocol])i.pathname=t.pathname;else{for(var s=(t.pathname||"").split("/");s.length&&!(t.host=s.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==s[0]&&s.unshift(""),s.length<2&&s.unshift(""),i.pathname=s.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 r=i.pathname||"",n=i.search||"";i.path=r+n}return i.slashes=i.slashes||t.slashes,i.href=i.format(),i}var o=i.pathname&&"/"===i.pathname.charAt(0),a=t.host||t.pathname&&"/"===t.pathname.charAt(0),l=a||o||i.host&&t.pathname,h=l,u=i.pathname&&i.pathname.split("/")||[],c=(s=t.pathname&&t.pathname.split("/")||[],i.protocol&&!Bu[i.protocol]);if(c&&(i.hostname="",i.port=null,i.host&&(""===u[0]?u[0]=i.host:u.unshift(i.host)),i.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===s[0]?s[0]=t.host:s.unshift(t.host)),t.host=null),l=l&&(""===s[0]||""===u[0])),a)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,u=s;else if(s.length)u||(u=[]),u.pop(),u=u.concat(s),i.search=t.search,i.query=t.query;else if(null!=t.search){if(c)i.hostname=i.host=u.shift(),(g=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=g.shift(),i.host=i.hostname=g.shift());return i.search=t.search,i.query=t.query,Wu(i.pathname)&&Wu(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i}if(!u.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var d=u.slice(-1)[0],p=(i.host||t.host)&&("."===d||".."===d)||""===d,f=0,m=u.length;m>=0;m--)"."==(d=u[m])?u.splice(m,1):".."===d?(u.splice(m,1),f++):f&&(u.splice(m,1),f--);if(!l&&!h)for(;f--;f)u.unshift("..");!l||""===u[0]||u[0]&&"/"===u[0].charAt(0)||u.unshift(""),p&&"/"!==u.join("/").substr(-1)&&u.push("");var g,y=""===u[0]||u[0]&&"/"===u[0].charAt(0);c&&(i.hostname=i.host=y?"":u.length?u.shift():"",(g=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=g.shift(),i.host=i.hostname=g.shift()));return(l=l||i.host&&u.length)&&!y&&u.unshift(""),u.length?i.pathname=u.join("/"):(i.pathname=null,i.path=null),Wu(i.pathname)&&Wu(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},Au.prototype.parseHost=function(){var t=this.host,e=Cu.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)};const Yu={};function $u(t,e,i=3){if(Yu[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))),Yu[e]=!0}const zu={get parse(){return $u("7.3.0","utils.url.parse is deprecated, use native URL API instead."),Pu},get format(){return $u("7.3.0","utils.url.format is deprecated, use native URL API instead."),Iu},get resolve(){return $u("7.3.0","utils.url.resolve is deprecated, use native URL API instead."),Tu}};function Vu(t){if("string"!=typeof t)throw new TypeError(`Path must be a string. Received ${JSON.stringify(t)}`)}function ju(t){return t.split("?")[0].split("#")[0]}const qu={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){Vu(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(Vu(t),this.isDataUrl(t)||this.isBlobUrl(t))return t;const s=ju(this.toPosix(e??Zh.ADAPTER.getBaseUrl())),r=ju(this.toPosix(i??this.rootname(s)));return(t=this.toPosix(t)).startsWith("/")?qu.join(r,t.slice(1)):this.isAbsolute(t)?t:this.join(s,t)},normalize(t){if(Vu(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,e){let i="",s=0,r=-1,n=0,o=-1;for(let a=0;a<=t.length;++a){if(a<t.length)o=t.charCodeAt(a);else{if(47===o)break;o=47}if(47===o){if(r!==a-1&&1!==n)if(r!==a-1&&2===n){if(i.length<2||2!==s||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2))if(i.length>2){const t=i.lastIndexOf("/");if(t!==i.length-1){-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.lastIndexOf("/")),r=a,n=0;continue}}else if(2===i.length||1===i.length){i="",s=0,r=a,n=0;continue}}else i.length>0?i+=`/${t.slice(r+1,a)}`:i=t.slice(r+1,a),s=a-r-1;r=a,n=0}else 46===o&&-1!==n?++n:n=-1}return i}(t)).length>0&&s&&(t+="/"),i?`/${t}`:e+t},isAbsolute(t){return Vu(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(Vu(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(Vu(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){Vu(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){Vu(t),e&&Vu(e),t=ju(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){Vu(t);let e=-1,i=0,s=-1,r=!0,n=0;for(let o=(t=ju(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){Vu(t);const e={root:"",dir:"",base:"",ext:"",name:""};if(0===t.length)return e;let i=(t=ju(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 Ju,Zu;function Ku(){return typeof Zu>"u"&&(Zu=function(){var t;const e={stencil:!0,failIfMajorPerformanceCaveat:Zh.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!Zh.ADAPTER.getWebGLRenderingContext())return!1;const i=Zh.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}}()),Zu}var Qu={grad:.9,turn:360,rad:360/(2*Math.PI)},tc=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},ec=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},ic=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},sc=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},rc=function(t){return{r:ic(t.r,0,255),g:ic(t.g,0,255),b:ic(t.b,0,255),a:ic(t.a)}},nc=function(t){return{r:ec(t.r),g:ec(t.g),b:ec(t.b),a:ec(t.a,3)}},oc=/^#([0-9a-f]{3,8})$/i,ac=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},lc=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}},hc=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}},uc=function(t){return{h:sc(t.h),s:ic(t.s,0,100),l:ic(t.l,0,100),a:ic(t.a)}},cc=function(t){return{h:ec(t.h),s:ec(t.s),l:ec(t.l),a:ec(t.a,3)}},dc=function(t){return hc((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},pc=function(t){return{h:(e=lc(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},fc=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,mc=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,gc=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,yc=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,vc={string:[[function(t){var e=oc.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?ec(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?ec(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=gc.exec(t)||yc.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:rc({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=fc.exec(t)||mc.exec(t);if(!e)return null;var i,s,r=uc({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(Qu[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return dc(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 tc(e)&&tc(i)&&tc(s)?rc({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(!tc(e)||!tc(i)||!tc(s))return null;var o=uc({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return dc(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!tc(e)||!tc(i)||!tc(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:sc(o.h),s:ic(o.s,0,100),v:ic(o.v,0,100),a:ic(o.a)});return hc(a)},"hsv"]]},xc=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]},bc=function(t,e){var i=pc(t);return{h:i.h,s:ic(i.s+100*e,0,100),l:i.l,a:i.a}},_c=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},wc=function(t,e){var i=pc(t);return{h:i.h,s:i.s,l:ic(i.l+100*e,0,100),a:i.a}},Ec=function(){function t(t){this.parsed=function(t){return"string"==typeof t?xc(t.trim(),vc.string):"object"==typeof t&&null!==t?xc(t,vc.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 ec(_c(this.rgba),2)},t.prototype.isDark=function(){return _c(this.rgba)<.5},t.prototype.isLight=function(){return _c(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=nc(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?ac(ec(255*r)):"","#"+ac(e)+ac(i)+ac(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return nc(this.rgba)},t.prototype.toRgbString=function(){return e=(t=nc(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 cc(pc(this.rgba))},t.prototype.toHslString=function(){return e=(t=cc(pc(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=lc(this.rgba),{h:ec(t.h),s:ec(t.s),v:ec(t.v),a:ec(t.a,3)};var t},t.prototype.invert=function(){return Pc({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),Pc(bc(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),Pc(bc(this.rgba,-t))},t.prototype.grayscale=function(){return Pc(bc(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),Pc(wc(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),Pc(wc(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?Pc({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):ec(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=pc(this.rgba);return"number"==typeof t?Pc({h:t,s:e.s,l:e.l,a:e.a}):ec(e.h)},t.prototype.isEqual=function(t){return this.toHex()===Pc(t).toHex()},t}(),Pc=function(t){return t instanceof Ec?t:new Ec(t)},Tc=[];!function(t){t.forEach((function(t){Tc.indexOf(t)<0&&(t(Ec,vc),Tc.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 Ic=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=Pc(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)}};Ic.shared=new Ic,Ic.temp=new Ic,Ic.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let Ac=Ic;const Sc=function(){const t=[],e=[];for(let s=0;s<32;s++)t[s]=s,e[s]=s;t[kh.NORMAL_NPM]=kh.NORMAL,t[kh.ADD_NPM]=kh.ADD,t[kh.SCREEN_NPM]=kh.SCREEN,e[kh.NORMAL]=kh.NORMAL_NPM,e[kh.ADD]=kh.ADD_NPM,e[kh.SCREEN]=kh.SCREEN_NPM;const i=[];return i.push(e),i.push(t),i}();const Cc=/^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;charset=([\w-]+))?(?:;(base64))?,(.*)/i;function Mc(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 Nc={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array};function Oc(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 Rc(t){return!(t&t-1||!t)}function Lc(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 kc(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 Fc(t){return 0===t?0:t<0?-1:1}let Dc=0;function Bc(){return++Dc}const Uc=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}};Uc.EMPTY=new Uc(0,0,0,0);let Gc=Uc;const Xc={},Hc=Object.create(null),Wc=Object.create(null);function Yc(){let t;for(t in Hc)delete Hc[t];for(t in Wc)delete Wc[t]}class $c{constructor(t,e,i){this._canvas=Zh.ADAPTER.createCanvas(),this._context=this._canvas.getContext("2d"),this.resolution=i||Zh.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 zc(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 Vc(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 jc(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&&zc(r,e,o);)++o;if(o===i)return Gc.EMPTY;for(;zc(r,e,l);)--l;for(;Vc(r,e,n,o,l);)++n;for(;Vc(r,e,a,o,l);)--a;return++a,++l,new Gc(n,o,a,l)}function qc(t){const e=jc(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 Jc(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 Zc(t,e=1){var i;const s=null==(i=Zh.RETINA_PREFIX)?void 0:i.exec(t);return s?parseFloat(s[1]):e}const Kc=Object.freeze(Object.defineProperty({__proto__:null,BaseTextureCache:Wc,BoundingBox:Gc,CanvasRenderTarget:$c,DATA_URI:Cc,EventEmitter:yu,ProgramCache:Xc,TextureCache:Hc,clearTextureCache:Yc,correctBlendMode:function(t,e){return Sc[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=Cc.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:$u,destroyTextureCache:function(){let t;for(t in Hc)Hc[t].destroy();for(t in Wc)Wc[t].destroy()},detectVideoAlphaMode:async function(){return Ju??(Ju=(async()=>{var t;const e=document.createElement("canvas").getContext("webgl");if(!e)return Yh.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 Yh.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]?Yh.PMA:Yh.UNPACK})()),Ju},determineCrossOrigin:Jc,earcut:Vt,getBufferType:Mc,getCanvasBoundingBox:jc,getResolutionOfUrl:Zc,hex2rgb:function(t,e=[]){return $u("7.2.0","utils.hex2rgb is deprecated, use Color#toRgbArray instead"),Ac.shared.setValue(t).toRgbArray(e)},hex2string:function(t){return $u("7.2.0","utils.hex2string is deprecated, use Color#toHex instead"),Ac.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=Mc(h);r[u]||(r[u]=new Nc[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:mu,isPow2:Rc,isWebGLSupported:Ku,log2:Lc,nextPow2:Oc,path:qu,premultiplyBlendMode:Sc,premultiplyRgba:function(t,e,i,s=!0){return $u("7.2.0","utils.premultiplyRgba has moved to Color.premultiply"),Ac.shared.setValue(t).premultiply(e,s).toArray(i??new Float32Array(4))},premultiplyTint:function(t,e){return $u("7.2.0","utils.premultiplyTint has moved to Color.toPremultiplied"),Ac.shared.setValue(t).toPremultiplied(e)},premultiplyTintToRgba:function(t,e,i,s=!0){return $u("7.2.0","utils.premultiplyTintToRgba has moved to Color.premultiply"),Ac.shared.setValue(t).premultiply(e,s).toArray(i??new Float32Array(4))},removeItems:kc,rgb2hex:function(t){return $u("7.2.0","utils.rgb2hex is deprecated, use Color#toNumber instead"),Ac.shared.setValue(t).toNumber()},sayHello:function(){$u("7.0.0",'sayHello is deprecated, please use Renderer\'s "hello" option')},sign:Fc,skipHello:function(){$u("7.0.0","skipHello is deprecated, please use settings.RENDER_OPTIONS.hello")},string2hex:function(t){return $u("7.2.0","utils.string2hex is deprecated, use Color#toNumber instead"),Ac.shared.setValue(t).toNumber()},trimCanvas:qc,uid:Bc,url:zu},Symbol.toStringTag,{value:"Module"}));var Qc=(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))(Qc||{});const td=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},ed=(t,e)=>td(t).priority??e,id={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...t){return t.map(td).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(td).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)=>ed(e,i)-ed(t,i))))}),(t=>{const i=e.indexOf(t.ref);-1!==i&&e.splice(i,1)}))}};class sd{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 rd=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join("\n");function nd(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 od{constructor(){this.data=0,this.blendMode=kh.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!==kh.NONE,this._blendMode=t}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}static for2d(){const t=new od;return t.depthTest=!1,t.blend=!0,t}}od.prototype.toString=function(){return`[@pixi/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`};const ad=[];function ld(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=ad.length-1;s>=0;--s){const r=ad[s];if(r.test&&r.test(t,i))return new r(t,e)}throw new Error("Unrecognized source type to auto-detect Resource")}class hd{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(hd.prototype,{dispatch:{value:hd.prototype.emit},run:{value:hd.prototype.emit}});class ud{constructor(t=0,e=0){this._width=t,this._height=e,this.destroyed=!1,this.internal=!1,this.onResize=new hd("setRealSize"),this.onUpdate=new hd("update"),this.onError=new hd("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 cd extends ud{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===Yh.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 dd={scaleMode:Xh.NEAREST,alphaMode:Yh.NPM},pd=class t extends yu{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 ud)&&((e=ld(e,f)).internal=!0),this.resolution=p||Zh.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=Bc(),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=Rc(this.realWidth)&&Rc(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 Wc[this.cacheId],delete Hc[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=Zh.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}_${Bc()}`}n=e._pixiId}let o=Wc[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 cd(e,{width:i,height:s,...null==r?void 0:r.resourceOptions});let o,a;return e instanceof Float32Array?(o=Dh.RGBA,a=Uh.FLOAT):e instanceof Int32Array?(o=Dh.RGBA_INTEGER,a=Uh.INT):e instanceof Uint32Array?(o=Dh.RGBA_INTEGER,a=Uh.UNSIGNED_INT):e instanceof Int16Array?(o=Dh.RGBA_INTEGER,a=Uh.SHORT):e instanceof Uint16Array?(o=Dh.RGBA_INTEGER,a=Uh.UNSIGNED_SHORT):e instanceof Int8Array?(o=Dh.RGBA,a=Uh.BYTE):(o=Dh.RGBA,a=Uh.UNSIGNED_BYTE),n.internal=!0,new t(n,Object.assign({},dd,{type:a,format:o},r))}static addToCache(t,e){e&&(t.textureCacheIds.includes(e)||t.textureCacheIds.push(e),Wc[e]&&Wc[e]!==t&&console.warn(`BaseTexture added to the cache with an id [${e}] that already had an entry`),Wc[e]=t)}static removeFromCache(t){if("string"==typeof t){const e=Wc[t];if(e){const i=e.textureCacheIds.indexOf(t);return i>-1&&e.textureCacheIds.splice(i,1),delete Wc[t],e}}else if(null==t?void 0:t.textureCacheIds){for(let e=0;e<t.textureCacheIds.length;++e)delete Wc[t.textureCacheIds[e]];return t.textureCacheIds.length=0,t}return null}};pd.defaultOptions={mipmap:Wh.POW2,anisotropicLevel:0,scaleMode:Xh.LINEAR,wrapMode:Hh.CLAMP,alphaMode:Yh.UNPACK,target:Bh.TEXTURE_2D,format:Dh.RGBA,type:Uh.UNSIGNED_BYTE},pd._globalBatch=0;let fd=pd;class md{constructor(){this.texArray=null,this.blend=0,this.type=Fh.TRIANGLES,this.start=0,this.size=0,this.data=null}}let gd=0;class yd{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=gd++,this.disposeRunner=new hd("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?Jh.ELEMENT_ARRAY_BUFFER:Jh.ARRAY_BUFFER}get index(){return this.type===Jh.ELEMENT_ARRAY_BUFFER}static from(t){return t instanceof Array&&(t=new Float32Array(t)),new yd(t)}}class vd{constructor(t,e=0,i=!1,s=Uh.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 vd(t,e,i,s,r)}}const xd={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array};const bd={5126:4,5123:2,5121:1};let _d=0;const wd={Float32Array:Float32Array,Uint32Array:Uint32Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array};class Ed{constructor(t=[],e={}){this.buffers=t,this.indexBuffer=null,this.attributes=e,this.glVertexArrayObjects={},this.id=_d++,this.instanced=!1,this.instanceCount=1,this.disposeRunner=new hd("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 yd||(e instanceof Array&&(e=new Float32Array(e)),e=new yd(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 vd(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 yd||(t instanceof Array&&(t=new Uint16Array(t)),t=new yd(t)),t.type=Jh.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 yd;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*bd[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=Mc(h);r[u]||(r[u]=new xd[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 Ed;for(let e=0;e<this.buffers.length;e++)t.buffers[e]=new yd(this.buffers[e].data.slice(0));for(const e in this.attributes){const i=this.attributes[e];t.attributes[e]=new vd(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=Jh.ELEMENT_ARRAY_BUFFER),t}static merge(t){const e=new Ed,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(wd[Mc(n.buffers[o].data)])(s[o]),e.buffers[o]=new yd(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=Jh.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*bd[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 Pd extends Ed{constructor(t=!1){super(),this._buffer=new yd(null,t,!1),this._indexBuffer=new yd(null,t,!0),this.addAttribute("aVertexPosition",this._buffer,2,!1,Uh.FLOAT).addAttribute("aTextureCoord",this._buffer,2,!1,Uh.FLOAT).addAttribute("aColor",this._buffer,4,!0,Uh.UNSIGNED_BYTE).addAttribute("aTextureId",this._buffer,1,!0,Uh.FLOAT).addIndex(this._indexBuffer)}}const Td=2*Math.PI,Id=180/Math.PI,Ad=Math.PI/180;var Sd=(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))(Sd||{});class Cd{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new Cd(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}}Cd.prototype.toString=function(){return`[@pixi/math:Point x=${this.x} y=${this.y}]`};const Md=[new Cd,new Cd,new Cd,new Cd];class Nd{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=Sd.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 Nd(0,0,0,0)}clone(){return new Nd(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=Md[0].set(t.left,t.top),a=Md[1].set(t.left,t.bottom),l=Md[2].set(t.right,t.top),h=Md[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}}Nd.prototype.toString=function(){return`[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class Od{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.radius=i,this.type=Sd.CIRC}clone(){return new Od(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 Nd(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius)}}Od.prototype.toString=function(){return`[@pixi/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`};class Rd{constructor(t=0,e=0,i=0,s=0){this.x=t,this.y=e,this.width=i,this.height=s,this.type=Sd.ELIP}clone(){return new Rd(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 Nd(this.x-this.width,this.y-this.height,this.width,this.height)}}Rd.prototype.toString=function(){return`[@pixi/math:Ellipse x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class Ld{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=Sd.POLY,this.closeStroke=!0}clone(){const t=this.points.slice(),e=new Ld(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}}Ld.prototype.toString=function(){return`[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce(((t,e)=>`${t}, ${e}`),"")}]`};class kd{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=Sd.RREC}clone(){return new kd(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}}kd.prototype.toString=function(){return`[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`};class Fd{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 Cd;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 Cd;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(Td-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 Fd;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 Fd}static get TEMP_MATRIX(){return new Fd}}Fd.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 Dd=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Bd=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Ud=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Gd=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Xd=[],Hd=[],Wd=Math.sign;!function(){for(let t=0;t<16;t++){const e=[];Xd.push(e);for(let i=0;i<16;i++){const s=Wd(Dd[t]*Dd[i]+Ud[t]*Bd[i]),r=Wd(Bd[t]*Dd[i]+Gd[t]*Bd[i]),n=Wd(Dd[t]*Ud[i]+Ud[t]*Gd[i]),o=Wd(Bd[t]*Ud[i]+Gd[t]*Gd[i]);for(let t=0;t<16;t++)if(Dd[t]===s&&Bd[t]===r&&Ud[t]===n&&Gd[t]===o){e.push(t);break}}}for(let t=0;t<16;t++){const e=new Fd;e.set(Dd[t],Bd[t],Ud[t],Gd[t],0,0),Hd.push(e)}}();const Yd={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=>Dd[t],uY:t=>Bd[t],vX:t=>Ud[t],vY:t=>Gd[t],inv:t=>8&t?15&t:7&-t,add:(t,e)=>Xd[t][e],sub:(t,e)=>Xd[t][Yd.inv(e)],rotate180:t=>4^t,isVertical:t=>2==(3&t),byDirection:(t,e)=>2*Math.abs(t)<=Math.abs(e)?e>=0?Yd.S:Yd.N:2*Math.abs(e)<=Math.abs(t)?t>0?Yd.E:Yd.W:e>0?t>0?Yd.SE:Yd.SW:t>0?Yd.NE:Yd.NW,matrixAppendRotationInv:(t,e,i=0,s=0)=>{const r=Hd[Yd.inv(e)];r.tx=i,r.ty=s,t.append(r)}};class $d{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 $d(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))}}$d.prototype.toString=function(){return`[@pixi/math:ObservablePoint x=${this.x} y=${this.y} scope=${this.scope}]`};const zd=class{constructor(){this.worldTransform=new Fd,this.localTransform=new Fd,this.position=new $d(this.onChange,this,0,0),this.scale=new $d(this.onChange,this,1,1),this.pivot=new $d(this.onChange,this,0,0),this.skew=new $d(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())}};zd.IDENTITY=new zd;let Vd=zd;Vd.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 jd(t,e,i){const s=t.createShader(e);return t.shaderSource(s,i),t.compileShader(s),s}function qd(t){const e=new Array(t);for(let i=0;i<e.length;i++)e[i]=!1;return e}function Jd(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 qd(2*e);case"bvec3":return qd(3*e);case"bvec4":return qd(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 Zd=[{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 }`}],Kd={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 }"},Qd={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 tp={};let ep,ip=tp;function sp(){if(!ep){ep=Vh.MEDIUM;const t=function(){if(ip===tp||(null==ip?void 0:ip.isContextLost())){const t=Zh.ADAPTER.createCanvas();let e;Zh.PREFER_ENV>=Oh.WEBGL2&&(e=t.getContext("webgl2",{})),e||(e=t.getContext("webgl",{})||t.getContext("experimental-webgl",{}),e?e.getExtension("WEBGL_draw_buffers"):e=null),ip=e}return ip}();if(t&&t.getShaderPrecisionFormat){const e=t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT);e&&(ep=e.precision?Vh.HIGH:Vh.MEDIUM)}}return ep}function rp(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 np={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 op(t){return np[t]}let ap=null;const lp={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 hp(t,e){if(!ap){const e=Object.keys(lp);ap={};for(let i=0;i<e.length;++i){const s=e[i];ap[t[s]]=lp[s]}}return ap[e]}function up(t,e,i){if("precision"!==t.substring(0,9)){let s=e;return e===Vh.HIGH&&i!==Vh.HIGH&&(s=Vh.MEDIUM),`precision ${s} float;\n${t}`}return i!==Vh.HIGH&&"precision highp"===t.substring(0,15)?t.replace("precision highp","precision mediump"):t}let cp;let dp=0;const pp={},fp=class t{constructor(e,i,s="pixi-shader",r={}){this.extra={},this.id=dp++,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,"-"),pp[s]?(pp[s]++,s+=`-${pp[s]}`):pp[s]=1,this.vertexSrc=`#define SHADER_NAME ${s}\n${this.vertexSrc}`,this.fragmentSrc=`#define SHADER_NAME ${s}\n${this.fragmentSrc}`,this.vertexSrc=up(this.vertexSrc,t.defaultVertexPrecision,Vh.HIGH),this.fragmentSrc=up(this.fragmentSrc,t.defaultFragmentPrecision,sp())),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=Xc[r];return n||(Xc[r]=n=new t(e,i,s)),n}};fp.defaultVertexPrecision=Vh.HIGH,fp.defaultFragmentPrecision=mu.apple.device?Vh.HIGH:Vh.MEDIUM;let mp=fp,gp=0;class yp{constructor(t,e,i){this.group=!0,this.syncUniforms={},this.dirtyId=0,this.id=gp++,this.static=!!e,this.ubo=!!i,t instanceof yd?(this.buffer=t,this.buffer.type=Jh.UNIFORM_BUFFER,this.autoManage=!1,this.ubo=!0):(this.uniforms=t,this.ubo&&(this.buffer=new yd(new Float32Array(1)),this.buffer.type=Jh.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 yp(e,i)}static from(t,e,i){return new yp(t,e,i)}static uboFrom(t,e){return new yp(t,e??!0,!0)}}class vp{constructor(t,e){this.uniformBindCount=0,this.program=t,this.uniformGroup=e?e instanceof yp?e:new yp(e):new yp({}),this.disposeRunner=new hd("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=mp.from(t,e);return new vp(s,i)}}class xp{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]=yp.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 mp(this.vertexSrc,i)}const e={tint:new Float32Array([1,1,1,1]),translationMatrix:new Fd,default:this.defaultGroupCache[t]};return new vp(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 bp{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 _p{constructor(t){this.renderer=t}flush(){}destroy(){this.renderer=null}start(){}stop(){this.flush()}render(t){}}const wp=class t extends _p{constructor(e){super(e),this.setShaderGenerator(),this.geometryClass=Pd,this.vertexSize=6,this.state=od.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=Zh.ADAPTER.getNavigator();if(mu.tablet||mu.phone){if(mu.apple.device){const t=i.userAgent.match(/OS (\d+)_(\d+)?/);t&&parseInt(t[1],10)<11&&(e=!1)}if(mu.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??!mu.apple.device,this._canUploadSameBuffer}static set canUploadSameBuffer(t){this._canUploadSameBuffer=t}get MAX_TEXTURES(){return $u("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 xp(e,i)}contextChange(){const e=this.renderer.gl;Zh.PREFER_ENV===Oh.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=rd.replace(/%forloop%/gi,nd(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 md);for(;i.length<r;)i.push(new bp);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=++fd._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;fd._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=Sc[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=Oc(Math.ceil(t/8)),i=Lc(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 sd(s*this.vertexSize*4)),r}getIndexBuffer(t){const e=Oc(Math.ceil(t/12)),i=Lc(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=Ac.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]}};wp.defaultBatchSize=4096,wp.extension={name:"batch",type:Qc.RendererPlugin},wp._drawCallPool=[],wp._textureArrayPool=[];let Ep=wp;id.add(Ep);const Pp=class t extends vp{constructor(e,i,s){super(mp.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 od}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"}};Pp.defaultResolution=1,Pp.defaultMultisample=qh.NONE;let Tp=Pp;class Ip{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new Ac(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(){}}Ip.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0},Ip.extension={type:[Qc.RendererSystem,Qc.CanvasRendererSystem],name:"background"},id.add(Ip);class Ap{constructor(t){this.renderer=t,this.emptyRenderer=new _p(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}}Ap.extension={type:Qc.RendererSystem,name:"batch"},id.add(Ap);let Sp=0;class Cp{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=Sp++}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=Sp++,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(Zh.PREFER_ENV>=Oh.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")}}Cp.defaultOptions={context:null,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"},Cp.extension={type:Qc.RendererSystem,name:"context"},id.add(Cp);class Mp{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 hd("disposeFramebuffer"),this.multisample=qh.NONE}get colorTexture(){return this.colorTextures[0]}addColorTexture(t=0,e){return this.colorTextures[t]=e||new fd(null,{scaleMode:Xh.NEAREST,resolution:1,mipmap:Wh.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this}addDepthTexture(t){return this.depthTexture=t||new fd(null,{scaleMode:Xh.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:Wh.OFF,format:Dh.DEPTH_COMPONENT,type:Uh.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 Np extends fd{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=qh.NONE),super(null,t),this.mipmap=Wh.OFF,this.valid=!0,this._clear=new Ac([0,0,0,0]),this.framebuffer=new Mp(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 Op extends ud{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=Jc(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===Yh.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 Rp extends Op{constructor(t,e){if(e=e||{},"string"==typeof t){const i=new Image;Op.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??Zh.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===Yh.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 Lp{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=Yd.add(i,Yd.NW),this.x0=o+e*Yd.uX(i),this.y0=a+n*Yd.uY(i),i=Yd.add(i,2),this.x1=o+e*Yd.uX(i),this.y1=a+n*Yd.uY(i),i=Yd.add(i,2),this.x2=o+e*Yd.uX(i),this.y2=a+n*Yd.uY(i),i=Yd.add(i,2),this.x3=o+e*Yd.uX(i),this.y3=a+n*Yd.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}}Lp.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 kp=new Lp;function Fp(t){t.destroy=function(){},t.on=function(){},t.once=function(){},t.emit=function(){}}class Dp extends yu{constructor(t,e,i,s,r,n,o){if(super(),this.noFrame=!1,e||(this.noFrame=!0,e=new Nd(0,0,1,1)),t instanceof Dp&&(t=t.baseTexture),this.baseTexture=t,this._frame=e,this.trim=s,this.valid=!1,this.destroyed=!1,this._uvs=kp,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 Cd(n.x,n.y):new Cd(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)&&Hc[t.url]&&Dp.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,Dp.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 Dp(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===kp&&(this._uvs=new Lp),this._uvs.set(this._frame,this.baseTexture,this.rotate),this._updateID++}static from(t,e={},i=Zh.STRICT_TEXTURE_CACHE){const s="string"==typeof t;let r=null;if(s)r=t;else if(t instanceof fd){if(!t.cacheId){const i=(null==e?void 0:e.pixiIdPrefix)||"pixiid";t.cacheId=`${i}-${Bc()}`,fd.addToCache(t,t.cacheId)}r=t.cacheId}else{if(!t._pixiId){const i=(null==e?void 0:e.pixiIdPrefix)||"pixiid";t._pixiId=`${i}_${Bc()}`}r=t._pixiId}let n=Hc[r];if(s&&i&&!n)throw new Error(`The cacheId "${r}" does not exist in TextureCache.`);return n||t instanceof fd?!n&&t instanceof fd&&(n=new Dp(t),Dp.addToCache(n,r)):(e.resolution||(e.resolution=Zc(t)),n=new Dp(new fd(t,e)),n.baseTexture.cacheId=r,fd.addToCache(n.baseTexture,r),Dp.addToCache(n,r)),n}static fromURL(t,e){const i=Object.assign({autoLoad:!1},null==e?void 0:e.resourceOptions),s=Dp.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 Dp(fd.fromBuffer(t,e,i,s))}static fromLoader(t,e,i,s){const r=new fd(t,Object.assign({scaleMode:fd.defaultOptions.scaleMode,resolution:Zc(e)},s)),{resource:n}=r;n instanceof Rp&&(n.url=e);const o=new Dp(r);return i||(i=e),fd.addToCache(o.baseTexture,i),Dp.addToCache(o,i),i!==e&&(fd.addToCache(o.baseTexture,e),Dp.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),Hc[e]&&Hc[e]!==t&&console.warn(`Texture added to the cache with an id [${e}] that already had an entry`),Hc[e]=t)}static removeFromCache(t){if("string"==typeof t){const e=Hc[t];if(e){const i=e.textureCacheIds.indexOf(t);return i>-1&&e.textureCacheIds.splice(i,1),delete Hc[t],e}}else if(null==t?void 0:t.textureCacheIds){for(let e=0;e<t.textureCacheIds.length;++e)Hc[t.textureCacheIds[e]]===t&&delete Hc[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 Dp._EMPTY||(Dp._EMPTY=new Dp(new fd),Fp(Dp._EMPTY),Fp(Dp._EMPTY.baseTexture)),Dp._EMPTY}static get WHITE(){if(!Dp._WHITE){const t=Zh.ADAPTER.createCanvas(16,16),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="white",e.fillRect(0,0,16,16),Dp._WHITE=new Dp(fd.from(t)),Fp(Dp._WHITE),Fp(Dp._WHITE.baseTexture)}return Dp._WHITE}}class Bp extends Dp{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 Bp(new Np(t))}}class Up{constructor(t){this.texturePool={},this.textureOptions=t||{},this.enableFullScreen=!1,this._pixelsWidth=0,this._pixelsHeight=0}createTexture(t,e,i=qh.NONE){const s=new Np(Object.assign({width:t,height:e,resolution:1,multisample:i},this.textureOptions));return new Bp(s)}getOptimalTexture(t,e,i=1,s=qh.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=Oc(t)))<<16|65535&(e=Oc(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||qh.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}}}Up.SCREEN_KEY=-1;class Gp extends Ed{constructor(){super(),this.addAttribute("aVertexPosition",new Float32Array([0,0,1,0,1,1,0,1])).addIndex([0,1,3,2])}}class Xp extends Ed{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 yd(this.vertices),this.uvBuffer=new yd(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 Hp{constructor(){this.renderTexture=null,this.target=null,this.legacy=!1,this.resolution=1,this.multisample=qh.NONE,this.sourceFrame=new Nd,this.destinationFrame=new Nd,this.bindingSourceFrame=new Nd,this.bindingDestinationFrame=new Nd,this.filters=[],this.transform=null}clear(){this.target=null,this.filters=null,this.renderTexture=null}}const Wp=[new Cd,new Cd,new Cd,new Cd],Yp=new Fd;class $p{constructor(t){this.renderer=t,this.defaultFilterStack=[{}],this.texturePool=new Up,this.statePool=[],this.quad=new Gp,this.quadUv=new Xp,this.tempRect=new Nd,this.activeState={},this.globalUniforms=new yp({outputFrame:new Nd,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 Hp,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(Yp.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,$h.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,$h.CLEAR,e);const n=t;t=s,s=n}i[r].apply(this,t,a.renderTexture,$h.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=$h.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===$h.CLEAR||e===$h.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(Fh.TRIANGLES)):(r.geometry.bind(this.quad),r.geometry.draw(Fh.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(Fd.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=qh.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||qh.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=Wp[0],s=Wp[1],r=Wp[2],n=Wp[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?Yp.copyFrom(r):Yp.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)}}}$p.extension={type:Qc.RendererSystem,name:"filter"},id.add($p);class zp{constructor(t){this.framebuffer=t,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=qh.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}}const Vp=new Nd;class jp{constructor(t){this.renderer=t,this.managedFramebuffers=[],this.unknownFramebuffer=new Mp(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 Nd,this.hasMRT=!0,this.writeDepthTexture=!0,1===this.renderer.context.webGLVersion){let e=this.renderer.context.extensions.drawBuffers,i=this.renderer.context.extensions.depthTexture;Zh.PREFER_ENV===Oh.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=Lh.COLOR|Lh.DEPTH){const{gl:n}=this;n.clearColor(t,e,i,s),n.clear(r)}initFramebuffer(t){const{gl:e}=this,i=new zp(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=qh.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=qh.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 Mp(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=Vp).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 Nd}destroy(){this.renderer=null}}jp.extension={type:Qc.RendererSystem,name:"framebuffer"},id.add(jp);const qp={5126:4,5123:2,5121:1};class Jp{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;Zh.PREFER_ENV===Oh.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*qp[c[f].type];for(const f in c){const t=c[f],e=t.size;void 0===t.stride&&(d[t.buffer]===e*qp[t.type]?t.stride=0:t.stride=d[t.buffer]),void 0===t.start&&(t.start=p[t.buffer],p[t.buffer]+=e*qp[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(Jh.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}}Jp.extension={type:Qc.RendererSystem,name:"geometry"},id.add(Jp);const Zp=new Fd;class Kp{constructor(t,e){this._texture=t,this.mapCoord=new Fd,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&&(Zp.set(s.width/r.width,0,0,s.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(Zp));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 Qp extends Tp{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 Fd}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 Kp(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 tf{constructor(t=null){this.type=jh.NONE,this.autoDetect=!0,this.maskObject=t||null,this.pooled=!1,this.isMaskData=!0,this.resolution=null,this.multisample=Tp.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=jh.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 ef{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 tf;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!==jh.SPRITE&&this.maskStack.push(i),i.enabled)switch(i.type){case jh.SCISSOR:this.renderer.scissor.push(i);break;case jh.STENCIL:this.renderer.stencil.push(i);break;case jh.SPRITE:i.copyCountersOrReset(null),this.pushSpriteMask(i);break;case jh.COLOR:this.pushColorMask(i)}i.type===jh.SPRITE&&this.maskStack.push(i)}pop(t){const e=this.maskStack.pop();if(e&&e._target===t){if(e.enabled)switch(e.type){case jh.SCISSOR:this.renderer.scissor.pop(e);break;case jh.STENCIL:this.renderer.stencil.pop(e.maskObject);break;case jh.SPRITE:this.popSpriteMask(e);break;case jh.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===jh.SPRITE&&t._filters&&(t._filters[0].maskSprite=t.maskObject)}}}detect(t){const e=t.maskObject;e?e.isSprite?t.type=jh.SPRITE:this.enableScissor&&this.renderer.scissor.testScissor(t)?t.type=jh.SCISSOR:t.type=jh.STENCIL:t.type=jh.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 Qp])),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}}ef.extension={type:Qc.RendererSystem,name:"mask"},id.add(ef);class sf{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 rf=new Fd,nf=[],of=class t extends sf{constructor(t){super(t),this.glConst=Zh.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,nf.pop()??new Nd);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?rf.copyFrom(n):rf.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&&nf.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)}};of.extension={type:Qc.RendererSystem,name:"scissor"};let af=of;id.add(af);class lf extends sf{constructor(t){super(t),this.glConst=Zh.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)}}lf.extension={type:Qc.RendererSystem,name:"stencil"},id.add(lf);class hf{constructor(t){this.renderer=t,this.plugins={},Object.defineProperties(this.plugins,{extract:{enumerable:!1,get:()=>($u("7.0.0","renderer.plugins.extract has moved to renderer.extract"),t.extract)},prepare:{enumerable:!1,get:()=>($u("7.0.0","renderer.plugins.prepare has moved to renderer.prepare"),t.prepare)},interaction:{enumerable:!1,get:()=>($u("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}}hf.extension={type:[Qc.RendererSystem,Qc.CanvasRendererSystem],name:"_plugin"},id.add(hf);class uf{constructor(t){this.renderer=t,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new Fd,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}}uf.extension={type:Qc.RendererSystem,name:"projection"},id.add(uf);const cf=new Vd,df=new Nd;class pf{constructor(t){this.renderer=t,this._tempMatrix=new Fd}generateTexture(t,e){const{region:i,...s}=e||{},r=(null==i?void 0:i.copyTo(df))||t.getLocalBounds(df,!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=Bp.create(s);this._tempMatrix.tx=-r.x,this._tempMatrix.ty=-r.y;const a=t.transform;return t.transform=cf,this.renderer.render(t,{renderTexture:o,transform:this._tempMatrix,skipUpdateTransform:!!t.parent,blit:!0}),t.transform=a,o}destroy(){}}pf.extension={type:[Qc.RendererSystem,Qc.CanvasRendererSystem],name:"textureGenerator"},id.add(pf);const ff=new Nd,mf=new Nd;class gf{constructor(t){this.renderer=t,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new Nd,this.destinationFrame=new Nd,this.viewportFrame=new Nd}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||(ff.width=t.frame.width,ff.height=t.frame.height,e=ff),i||(mf.x=t.frame.x,mf.y=t.frame.y,mf.width=e.width,mf.height=e.height,i=mf),n=r.framebuffer):(o=s.resolution,e||(ff.width=s._view.screen.width,ff.height=s._view.screen.height,e=ff),i||((i=ff).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=Ac.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}}gf.extension={type:Qc.RendererSystem,name:"renderTexture"},id.add(gf);class yf{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 vf(t,e){var i;const s=jd(t,t.VERTEX_SHADER,e.vertexSrc),r=jd(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)||rp(t,i),t.getShaderParameter(s,t.COMPILE_STATUS)||rp(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=hp(e,s.type),o={type:n,name:s.name,size:op(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=hp(e,s.type);i[n]={name:n,index:r,type:a,size:s.size,isArray:o,value:Jd(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:Jd(i.type,i.size)}}return new yf(n,a)}function xf(t,e,i,s,r){i.buffer.update(r)}const bf={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 "},_f={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 wf(t,e){if(!t.autoManage)return{size:0,syncFunc:xf};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=_f[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<Zd.length;t++){const s=Zd[t];if(s.codeUbo&&s.test(e.data,i)){n.push(`offset = ${e.offset/4};`,Zd[t].codeUbo(e.data.name,i)),a=!0;break}}if(!a)if(e.data.size>1){const t=op(e.data.type),i=Math.max(_f[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=bf[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 Ef=0;const Pf={textureCount:0,uboCount:0};class Tf{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=Ef++}systemCheck(){if(!function(){if("boolean"==typeof cp)return cp;try{cp=!0===new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")}catch{cp=!1}return cp}())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||(Pf.textureCount=0,Pf.uboCount=0,this.syncUniformGroup(t.uniformGroup,Pf)),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<Zd.length;t++)if(Zd[t].test(n,o)){s.push(Zd[t].code(r,o)),a=!0;break}if(!a){const t=(1!==n.size||n.isArray?Qd:Kd)[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,Pf,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]=wf(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=vf(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}}Tf.extension={type:Qc.RendererSystem,name:"shader"},id.add(Tf);class If{constructor(t){this.renderer=t}run(t){const{renderer:e}=this;e.runners.init.emit(e.options),t.hello&&console.log(`PixiJS 7.4.0 - ${e.rendererLogId} - https://pixijs.com`),e.resize(e.screen.width,e.screen.height)}destroy(){}}If.defaultOptions={hello:!1},If.extension={type:[Qc.RendererSystem,Qc.CanvasRendererSystem],name:"startup"},id.add(If);const Af=class t{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode=kh.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 od,this.defaultState.blend=!0}contextChange(t){this.gl=t,this.blendModes=function(t,e=[]){return e[kh.NORMAL]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.ADD]=[t.ONE,t.ONE],e[kh.MULTIPLY]=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.SCREEN]=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.OVERLAY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.DARKEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.LIGHTEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.COLOR_DODGE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.COLOR_BURN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.HARD_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.SOFT_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.DIFFERENCE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.EXCLUSION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.HUE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.SATURATION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.COLOR]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.LUMINOSITY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.NONE]=[0,0],e[kh.NORMAL_NPM]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.ADD_NPM]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e[kh.SCREEN_NPM]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e[kh.SRC_IN]=[t.DST_ALPHA,t.ZERO],e[kh.SRC_OUT]=[t.ONE_MINUS_DST_ALPHA,t.ZERO],e[kh.SRC_ATOP]=[t.DST_ALPHA,t.ONE_MINUS_SRC_ALPHA],e[kh.DST_OVER]=[t.ONE_MINUS_DST_ALPHA,t.ONE],e[kh.DST_IN]=[t.ZERO,t.SRC_ALPHA],e[kh.DST_OUT]=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],e[kh.DST_ATOP]=[t.ONE_MINUS_DST_ALPHA,t.SRC_ALPHA],e[kh.XOR]=[t.ONE_MINUS_DST_ALPHA,t.ONE_MINUS_SRC_ALPHA],e[kh.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}};Af.extension={type:Qc.RendererSystem,name:"state"};let Sf=Af;id.add(Sf);class Cf extends yu{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 hd(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 Mf=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!==zh.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}};Mf.defaultMode=zh.AUTO,Mf.defaultMaxIdle=3600,Mf.defaultCheckCountMax=600,Mf.extension={type:Qc.RendererSystem,name:"textureGC"};let Nf=Mf;id.add(Nf);class Of{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=Uh.UNSIGNED_BYTE,this.internalFormat=Dh.RGBA,this.samplerType=0}}class Rf{constructor(t){this.renderer=t,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new fd,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?{[Uh.UNSIGNED_BYTE]:{[Dh.RGBA]:t.RGBA8,[Dh.RGB]:t.RGB8,[Dh.RG]:t.RG8,[Dh.RED]:t.R8,[Dh.RGBA_INTEGER]:t.RGBA8UI,[Dh.RGB_INTEGER]:t.RGB8UI,[Dh.RG_INTEGER]:t.RG8UI,[Dh.RED_INTEGER]:t.R8UI,[Dh.ALPHA]:t.ALPHA,[Dh.LUMINANCE]:t.LUMINANCE,[Dh.LUMINANCE_ALPHA]:t.LUMINANCE_ALPHA},[Uh.BYTE]:{[Dh.RGBA]:t.RGBA8_SNORM,[Dh.RGB]:t.RGB8_SNORM,[Dh.RG]:t.RG8_SNORM,[Dh.RED]:t.R8_SNORM,[Dh.RGBA_INTEGER]:t.RGBA8I,[Dh.RGB_INTEGER]:t.RGB8I,[Dh.RG_INTEGER]:t.RG8I,[Dh.RED_INTEGER]:t.R8I},[Uh.UNSIGNED_SHORT]:{[Dh.RGBA_INTEGER]:t.RGBA16UI,[Dh.RGB_INTEGER]:t.RGB16UI,[Dh.RG_INTEGER]:t.RG16UI,[Dh.RED_INTEGER]:t.R16UI,[Dh.DEPTH_COMPONENT]:t.DEPTH_COMPONENT16},[Uh.SHORT]:{[Dh.RGBA_INTEGER]:t.RGBA16I,[Dh.RGB_INTEGER]:t.RGB16I,[Dh.RG_INTEGER]:t.RG16I,[Dh.RED_INTEGER]:t.R16I},[Uh.UNSIGNED_INT]:{[Dh.RGBA_INTEGER]:t.RGBA32UI,[Dh.RGB_INTEGER]:t.RGB32UI,[Dh.RG_INTEGER]:t.RG32UI,[Dh.RED_INTEGER]:t.R32UI,[Dh.DEPTH_COMPONENT]:t.DEPTH_COMPONENT24},[Uh.INT]:{[Dh.RGBA_INTEGER]:t.RGBA32I,[Dh.RGB_INTEGER]:t.RGB32I,[Dh.RG_INTEGER]:t.RG32I,[Dh.RED_INTEGER]:t.R32I},[Uh.FLOAT]:{[Dh.RGBA]:t.RGBA32F,[Dh.RGB]:t.RGB32F,[Dh.RG]:t.RG32F,[Dh.RED]:t.R32F,[Dh.DEPTH_COMPONENT]:t.DEPTH_COMPONENT32F},[Uh.HALF_FLOAT]:{[Dh.RGBA]:t.RGBA16F,[Dh.RGB]:t.RGB16F,[Dh.RG]:t.RG16F,[Dh.RED]:t.R16F},[Uh.UNSIGNED_SHORT_5_6_5]:{[Dh.RGB]:t.RGB565},[Uh.UNSIGNED_SHORT_4_4_4_4]:{[Dh.RGBA]:t.RGBA4},[Uh.UNSIGNED_SHORT_5_5_5_1]:{[Dh.RGBA]:t.RGB5_A1},[Uh.UNSIGNED_INT_2_10_10_10_REV]:{[Dh.RGBA]:t.RGB10_A2,[Dh.RGBA_INTEGER]:t.RGB10_A2UI},[Uh.UNSIGNED_INT_10F_11F_11F_REV]:{[Dh.RGB]:t.R11F_G11F_B10F},[Uh.UNSIGNED_INT_5_9_9_9_REV]:{[Dh.RGB]:t.RGB9_E5},[Uh.UNSIGNED_INT_24_8]:{[Dh.DEPTH_STENCIL]:t.DEPTH24_STENCIL8},[Uh.FLOAT_32_UNSIGNED_INT_24_8_REV]:{[Dh.DEPTH_STENCIL]:t.DEPTH32F_STENCIL8}}:{[Uh.UNSIGNED_BYTE]:{[Dh.RGBA]:t.RGBA,[Dh.RGB]:t.RGB,[Dh.ALPHA]:t.ALPHA,[Dh.LUMINANCE]:t.LUMINANCE,[Dh.LUMINANCE_ALPHA]:t.LUMINANCE_ALPHA},[Uh.UNSIGNED_SHORT_5_6_5]:{[Dh.RGB]:t.RGB},[Uh.UNSIGNED_SHORT_4_4_4_4]:{[Dh.RGBA]:t.RGBA},[Uh.UNSIGNED_SHORT_5_5_5_1]:{[Dh.RGBA]:t.RGBA}},e}(t),this.samplerTypes=function(t){let e;return e="WebGL2RenderingContext"in globalThis&&t instanceof globalThis.WebGL2RenderingContext?{[t.RGB]:Gh.FLOAT,[t.RGBA]:Gh.FLOAT,[t.ALPHA]:Gh.FLOAT,[t.LUMINANCE]:Gh.FLOAT,[t.LUMINANCE_ALPHA]:Gh.FLOAT,[t.R8]:Gh.FLOAT,[t.R8_SNORM]:Gh.FLOAT,[t.RG8]:Gh.FLOAT,[t.RG8_SNORM]:Gh.FLOAT,[t.RGB8]:Gh.FLOAT,[t.RGB8_SNORM]:Gh.FLOAT,[t.RGB565]:Gh.FLOAT,[t.RGBA4]:Gh.FLOAT,[t.RGB5_A1]:Gh.FLOAT,[t.RGBA8]:Gh.FLOAT,[t.RGBA8_SNORM]:Gh.FLOAT,[t.RGB10_A2]:Gh.FLOAT,[t.RGB10_A2UI]:Gh.FLOAT,[t.SRGB8]:Gh.FLOAT,[t.SRGB8_ALPHA8]:Gh.FLOAT,[t.R16F]:Gh.FLOAT,[t.RG16F]:Gh.FLOAT,[t.RGB16F]:Gh.FLOAT,[t.RGBA16F]:Gh.FLOAT,[t.R32F]:Gh.FLOAT,[t.RG32F]:Gh.FLOAT,[t.RGB32F]:Gh.FLOAT,[t.RGBA32F]:Gh.FLOAT,[t.R11F_G11F_B10F]:Gh.FLOAT,[t.RGB9_E5]:Gh.FLOAT,[t.R8I]:Gh.INT,[t.R8UI]:Gh.UINT,[t.R16I]:Gh.INT,[t.R16UI]:Gh.UINT,[t.R32I]:Gh.INT,[t.R32UI]:Gh.UINT,[t.RG8I]:Gh.INT,[t.RG8UI]:Gh.UINT,[t.RG16I]:Gh.INT,[t.RG16UI]:Gh.UINT,[t.RG32I]:Gh.INT,[t.RG32UI]:Gh.UINT,[t.RGB8I]:Gh.INT,[t.RGB8UI]:Gh.UINT,[t.RGB16I]:Gh.INT,[t.RGB16UI]:Gh.UINT,[t.RGB32I]:Gh.INT,[t.RGB32UI]:Gh.UINT,[t.RGBA8I]:Gh.INT,[t.RGBA8UI]:Gh.UINT,[t.RGBA16I]:Gh.INT,[t.RGBA16UI]:Gh.UINT,[t.RGBA32I]:Gh.INT,[t.RGBA32UI]:Gh.UINT,[t.DEPTH_COMPONENT16]:Gh.FLOAT,[t.DEPTH_COMPONENT24]:Gh.FLOAT,[t.DEPTH_COMPONENT32F]:Gh.FLOAT,[t.DEPTH_STENCIL]:Gh.FLOAT,[t.DEPTH24_STENCIL8]:Gh.FLOAT,[t.DEPTH32F_STENCIL8]:Gh.FLOAT}:{[t.RGB]:Gh.FLOAT,[t.RGBA]:Gh.FLOAT,[t.ALPHA]:Gh.FLOAT,[t.LUMINANCE]:Gh.FLOAT,[t.LUMINANCE_ALPHA]:Gh.FLOAT,[t.DEPTH_STENCIL]:Gh.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 Of(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 Of(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!==Gh.FLOAT&&this.renderer.texture.unbind(t)}}initTexture(t){const e=new Of(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]??Gh.FLOAT,2===this.webGLVersion&&t.type===Uh.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!==Gh.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&&kc(this.managedTextures,e,1)}}updateTextureStyle(t){var e;const i=t._glTextures[this.CONTEXT_UID];i&&(t.mipmap!==Wh.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=Hh.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!==Wh.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===Xh.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);const e=this.renderer.context.extensions.anisotropicFiltering;if(e&&t.anisotropicLevel>0&&t.scaleMode===Xh.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===Xh.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(t.target,i.TEXTURE_MAG_FILTER,t.scaleMode===Xh.LINEAR?i.LINEAR:i.NEAREST)}destroy(){this.renderer=null}}Rf.extension={type:Qc.RendererSystem,name:"texture"},id.add(Rf);class Lf{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}}Lf.extension={type:Qc.RendererSystem,name:"transformFeedback"},id.add(Lf);class kf{constructor(t){this.renderer=t}init(t){this.screen=new Nd(0,0,t.width,t.height),this.element=t.view||Zh.ADAPTER.createCanvas(),this.resolution=t.resolution||Zh.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}}kf.defaultOptions={width:800,height:600,resolution:void 0,autoDensity:!1},kf.extension={type:[Qc.RendererSystem,Qc.CanvasRendererSystem],name:"_view"},id.add(kf),Zh.PREFER_ENV=Oh.WEBGL2,Zh.STRICT_TEXTURE_CACHE=!1,Zh.RENDER_OPTIONS={...Cp.defaultOptions,...Ip.defaultOptions,...kf.defaultOptions,...If.defaultOptions},Object.defineProperties(Zh,{WRAP_MODE:{get:()=>fd.defaultOptions.wrapMode,set(t){$u("7.1.0","settings.WRAP_MODE is deprecated, use BaseTexture.defaultOptions.wrapMode"),fd.defaultOptions.wrapMode=t}},SCALE_MODE:{get:()=>fd.defaultOptions.scaleMode,set(t){$u("7.1.0","settings.SCALE_MODE is deprecated, use BaseTexture.defaultOptions.scaleMode"),fd.defaultOptions.scaleMode=t}},MIPMAP_TEXTURES:{get:()=>fd.defaultOptions.mipmap,set(t){$u("7.1.0","settings.MIPMAP_TEXTURES is deprecated, use BaseTexture.defaultOptions.mipmap"),fd.defaultOptions.mipmap=t}},ANISOTROPIC_LEVEL:{get:()=>fd.defaultOptions.anisotropicLevel,set(t){$u("7.1.0","settings.ANISOTROPIC_LEVEL is deprecated, use BaseTexture.defaultOptions.anisotropicLevel"),fd.defaultOptions.anisotropicLevel=t}},FILTER_RESOLUTION:{get:()=>($u("7.1.0","settings.FILTER_RESOLUTION is deprecated, use Filter.defaultResolution"),Tp.defaultResolution),set(t){Tp.defaultResolution=t}},FILTER_MULTISAMPLE:{get:()=>($u("7.1.0","settings.FILTER_MULTISAMPLE is deprecated, use Filter.defaultMultisample"),Tp.defaultMultisample),set(t){Tp.defaultMultisample=t}},SPRITE_MAX_TEXTURES:{get:()=>Ep.defaultMaxTextures,set(t){$u("7.1.0","settings.SPRITE_MAX_TEXTURES is deprecated, use BatchRenderer.defaultMaxTextures"),Ep.defaultMaxTextures=t}},SPRITE_BATCH_SIZE:{get:()=>Ep.defaultBatchSize,set(t){$u("7.1.0","settings.SPRITE_BATCH_SIZE is deprecated, use BatchRenderer.defaultBatchSize"),Ep.defaultBatchSize=t}},CAN_UPLOAD_SAME_BUFFER:{get:()=>Ep.canUploadSameBuffer,set(t){$u("7.1.0","settings.CAN_UPLOAD_SAME_BUFFER is deprecated, use BatchRenderer.canUploadSameBuffer"),Ep.canUploadSameBuffer=t}},GC_MODE:{get:()=>Nf.defaultMode,set(t){$u("7.1.0","settings.GC_MODE is deprecated, use TextureGCSystem.defaultMode"),Nf.defaultMode=t}},GC_MAX_IDLE:{get:()=>Nf.defaultMaxIdle,set(t){$u("7.1.0","settings.GC_MAX_IDLE is deprecated, use TextureGCSystem.defaultMaxIdle"),Nf.defaultMaxIdle=t}},GC_MAX_CHECK_COUNT:{get:()=>Nf.defaultCheckCountMax,set(t){$u("7.1.0","settings.GC_MAX_CHECK_COUNT is deprecated, use TextureGCSystem.defaultCheckCountMax"),Nf.defaultCheckCountMax=t}},PRECISION_VERTEX:{get:()=>mp.defaultVertexPrecision,set(t){$u("7.1.0","settings.PRECISION_VERTEX is deprecated, use Program.defaultVertexPrecision"),mp.defaultVertexPrecision=t}},PRECISION_FRAGMENT:{get:()=>mp.defaultFragmentPrecision,set(t){$u("7.1.0","settings.PRECISION_FRAGMENT is deprecated, use Program.defaultFragmentPrecision"),mp.defaultFragmentPrecision=t}}});var Ff=(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))(Ff||{});class Df{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 Bf=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 Df(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=Ff.NORMAL){return this._addListener(new Df(t,e,i))}addOnce(t,e,i=Ff.NORMAL){return this._addListener(new Df(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}};Bf.targetFPMS=.06;let Uf=Bf;Object.defineProperties(Zh,{TARGET_FPMS:{get:()=>Uf.targetFPMS,set(t){$u("7.1.0","settings.TARGET_FPMS is deprecated, use Ticker.targetFPMS"),Uf.targetFPMS=t}}});class Gf{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,Ff.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?Uf.shared:new Uf,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}Gf.extension=Qc.Application,id.add(Gf);const Xf=[];id.handleByList(Qc.Renderer,Xf);class Hf{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>=qh.HIGH?this.multisample=qh.HIGH:e>=qh.MEDIUM?this.multisample=qh.MEDIUM:e>=qh.LOW?this.multisample=qh.LOW:this.multisample=qh.NONE}destroy(){}}Hf.extension={type:Qc.RendererSystem,name:"_multisample"},id.add(Hf);class Wf{constructor(t){this.buffer=t||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}}class Yf{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 Wf(i.createBuffer()),this.managedBuffers[t.id]=t,t.disposeRunner.add(this),t._glBuffers[e]}}Yf.extension={type:Qc.RendererSystem,name:"buffer"},id.add(Yf);class $f{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}}$f.extension={type:Qc.RendererSystem,name:"objectRenderer"},id.add($f);const zf=class t extends Cf{constructor(e){super(),this.type=Rh.WEBGL,e=Object.assign({},Zh.RENDER_OPTIONS,e),this.gl=null,this.CONTEXT_UID=0,this.globalUniforms=new yp({projectionMatrix:new Fd},!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&&($u("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)&&Ku()}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 $u("7.0.0","renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."),this.background.clearBeforeRender}get useContextAlpha(){return $u("7.0.0","renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."),this.context.useContextAlpha}get preserveDrawingBuffer(){return $u("7.0.0","renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"),this.context.preserveDrawingBuffer}get backgroundColor(){return $u("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){$u("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return $u("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){$u("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get powerPreference(){return $u("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)}};zf.extension={type:Qc.Renderer,priority:1},zf.__plugins={},zf.__systems={};let Vf=zf;id.handleByMap(Qc.RendererPlugin,Vf.__plugins),id.handleByMap(Qc.RendererSystem,Vf.__systems),id.add(Vf);class jf extends ud{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 fd;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 ud?this.addResourceAt(t[i],i):this.addResourceAt(ld(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 qf extends Op{constructor(t){super(t)}static test(t){const{OffscreenCanvas:e}=globalThis;return!!(e&&t instanceof e)||globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement}}const Jf=class t extends jf{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=Bh.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=Bh.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=Bh.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}};Jf.SIDES=6;let Zf=Jf;class Kf extends Op{constructor(t,e){let i,s,r;e=e||{},"string"==typeof t?(i=Kf.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 Zh.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===Yh.UNPACK?"premultiply":"none"});if(this.destroyed)return void s.close();this.source=s,this.update(),t(this)}catch(i){if(this.destroyed)return;e(i),this.onError.emit(i)}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 Kf._EMPTY=Kf._EMPTY??Zh.ADAPTER.createCanvas(0,0),Kf._EMPTY}}const Qf=class t extends Op{constructor(t,e){e=e||{},super(Zh.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;Op.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_${Bc()}`,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)}};Qf.SVG_XML=/^(<\?xml[^?]+\?>)?\s*(<!--[^(-->)]*-->)?\s*\<svg/m,Qf.SVG_SIZE=/<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i;let tm=Qf;const em=class t extends Op{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];Op.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=Uf.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&&(Uf.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||(Uf.shared.add(this.update,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(null!==this._videoFrameRequestCallbackHandle&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(Uf.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)}};em.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],em.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let im=em;ad.push(Kf,Rp,qf,im,class extends Op{constructor(t){super(t)}static test(t){return!!globalThis.VideoFrame&&t instanceof globalThis.VideoFrame}},tm,cd,Zf,class extends jf{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=Bh.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 sm{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?Nd.EMPTY:((t=t||new Nd(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 rm extends yu{constructor(){super(),this.tempDisplayObjectParent=null,this.transform=new Vd,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 sm,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(rm.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 Nd),e=this._boundsRect),this._bounds.getRectangle(e)}getLocalBounds(t){t||(this._localBoundsRect||(this._localBoundsRect=new Nd),t=this._localBoundsRect),this._localBounds||(this._localBounds=new sm);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 nm),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*Id}set angle(t){this.transform.rotation=t*Ad}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 nm extends rm{constructor(){super(...arguments),this.sortDirty=null}}rm.prototype.displayObjectUpdateTransform=rm.prototype.updateTransform;const om=new Fd;function am(t,e){return t.zIndex===e.zIndex?t._lastSortedIndex-e._lastSortedIndex:t.zIndex-e.zIndex}const lm=class t extends rm{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);kc(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,kc(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,kc(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(am),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=om.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!==jh.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}};lm.defaultSortableChildren=!1;let hm=lm;hm.prototype.containerUpdateTransform=hm.prototype.updateTransform,Object.defineProperties(Zh,{SORTABLE_CHILDREN:{get:()=>hm.defaultSortableChildren,set(t){$u("7.1.0","settings.SORTABLE_CHILDREN is deprecated, use Container.defaultSortableChildren"),hm.defaultSortableChildren=t}}});const um=new Cd,cm=new Uint16Array([0,1,2,0,2,3]);class dm extends hm{constructor(t){super(),this._anchor=new $d(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 Ac(16777215),this._tintRGB=null,this.tint=16777215,this.blendMode=kh.NORMAL,this._cachedTint=16777215,this.uvs=null,this.texture=t||Dp.EMPTY,this.vertexData=new Float32Array(8),this.vertexTrimmedData=null,this._transformID=-1,this._textureID=-1,this._transformTrimmedID=-1,this._textureTrimmedID=-1,this.indices=cm,this.pluginName="batch",this.isSprite=!0,this._roundPixels=Zh.ROUND_PIXELS}_onTextureUpdate(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=Fc(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=Fc(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=Zh.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=Zh.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 sm),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 Nd),t=this._localBoundsRect),this._localBounds.getRectangle(t)):super.getLocalBounds.call(this,t)}containsPoint(t){this.worldTransform.applyInverse(t,um);const e=this._texture.orig.width,i=this._texture.orig.height,s=-e*this.anchor.x;let r=0;return um.x>=s&&um.x<s+e&&(r=-i*this.anchor.y,um.y>=r&&um.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 Dp?t:Dp.from(t,e);return new dm(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=Fc(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=Fc(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||Dp.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))}}const pm={build(t){const e=t.points;let i,s,r,n,o,a;if(t.type===Sd.CIRC){const e=t.shape;i=e.x,s=e.y,o=a=e.radius,r=n=0}else if(t.type===Sd.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!==Sd.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 fm(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 mm={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){fm(i,!1);const t=[];for(let r=0;r<s.length;r++){const e=s[r];fm(e.points,!0),t.push(i.length/2),i=i.concat(e.points)}const e=Vt(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])}}},gm={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)}},ym={build(t){pm.build(t)},triangulate(t,e){pm.triangulate(t,e)}};var vm=(t=>(t.MITER="miter",t.BEVEL="bevel",t.ROUND="round",t))(vm||{}),xm=(t=>(t.BUTT="butt",t.ROUND="round",t.SQUARE="square",t))(xm||{});const bm={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 _m{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),E=u*(m+v),P=h*(m+v);return{cx:x+t,cy:b+e,radius:r,startAngle:Math.atan2(w-b,_-x),endAngle:Math.atan2(P-b,E-x),anticlockwise:l*h>u*a}}static arc(t,e,i,s,r,n,o,a,l){const h=o-n,u=bm._segmentsCount(Math.abs(h)*r,40*Math.ceil(Math.abs(h)/Td)),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 wm{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 Em{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=bm._segmentsCount(Em.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 Pm(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 Tm(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 Im(t,e){t.lineStyle.native?function(t,e){let i=0;const s=t.shape,r=t.points||s.points,n=s.type!==Sd.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 Cd(s[0],s[1]),a=new Cd(s[s.length-2],s[s.length-1]),l=i.type!==Sd.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,E=-(v-b),P=y-x,T=0,I=0,A=Math.sqrt(E*E+P*P);E/=A,P/=A,E*=f,P*=f;const S=n.alignment,C=2*(1-S),M=2*S;l||(n.cap===xm.ROUND?d+=Tm(y-E*(C-M)*.5,v-P*(C-M)*.5,y-E*C,v-P*C,y+E*M,v+P*M,u,!0)+2:n.cap===xm.SQUARE&&(d+=Pm(y,v,E,P,C,M,!0,u))),u.push(y-E*C,v-P*C,y+E*M,v+P*M);for(let R=1;R<c-1;++R){y=s[2*(R-1)],v=s[2*(R-1)+1],x=s[2*R],b=s[2*R+1],_=s[2*(R+1)],w=s[2*(R+1)+1],E=-(v-b),P=y-x,A=Math.sqrt(E*E+P*P),E/=A,P/=A,E*=f,P*=f,T=-(b-w),I=x-_,A=Math.sqrt(T*T+I*I),T/=A,I/=A,T*=f,I*=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-E*C,b-P*C,x+E*M,b+P*M),o>=0&&(n.join===vm.ROUND?d+=Tm(x,b,x-E*C,b-P*C,x-T*C,b-I*C,u,!1)+4:d+=2,u.push(x-T*M,b-I*M,x+T*C,b+I*C));continue}const h=(-E+y)*(-P+b)-(-E+x)*(-P+v),c=(-T+_)*(-I+b)-(-T+x)*(-I+w),p=(t*c-i*h)/a,S=(r*h-e*c)/a,N=(p-x)*(p-x)+(S-b)*(S-b),O=x+(p-x)*C,L=b+(S-b)*C,k=x-(p-x)*M,F=b-(S-b)*M,D=l?C:M,B=N<=Math.min(t*t+e*e,i*i+r*r)+D*D*m;let U=n.join;if(U===vm.MITER&&N/m>g&&(U=vm.BEVEL),B)switch(U){case vm.MITER:u.push(O,L,k,F);break;case vm.BEVEL:l?u.push(O,L,x+E*M,b+P*M,O,L,x+T*M,b+I*M):u.push(x-E*C,b-P*C,k,F,x-T*C,b-I*C,k,F),d+=2;break;case vm.ROUND:l?(u.push(O,L,x+E*M,b+P*M),d+=Tm(x,b,x+E*M,b+P*M,x+T*M,b+I*M,u,!0)+4,u.push(O,L,x+T*M,b+I*M)):(u.push(x-E*C,b-P*C,k,F),d+=Tm(x,b,x-E*C,b-P*C,x-T*C,b-I*C,u,!1)+4,u.push(x-T*C,b-I*C,k,F))}else{switch(u.push(x-E*C,b-P*C,x+E*M,b+P*M),U){case vm.MITER:l?u.push(k,F,k,F):u.push(O,L,O,L),d+=2;break;case vm.ROUND:d+=l?Tm(x,b,x+E*M,b+P*M,x+T*M,b+I*M,u,!0)+2:Tm(x,b,x-E*C,b-P*C,x-T*C,b-I*C,u,!1)+2}u.push(x-T*C,b-I*C,x+T*M,b+I*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],E=-(v-b),P=y-x,A=Math.sqrt(E*E+P*P),E/=A,P/=A,E*=f,P*=f,u.push(x-E*C,b-P*C,x+E*M,b+P*M),l||(n.cap===xm.ROUND?d+=Tm(x-E*(C-M)*.5,b-P*(C-M)*.5,x-E*C,b-P*C,x+E*M,b+P*M,u,!1)+2:n.cap===xm.SQUARE&&(d+=Pm(x,b,E,P,C,M,!1,u)));const N=e.indices,O=bm.epsilon*bm.epsilon;for(let R=p;R<d+p-2;++R)y=u[2*R],v=u[2*R+1],x=u[2*(R+1)],b=u[2*(R+1)+1],_=u[2*(R+2)],w=u[2*(R+2)+1],!(Math.abs(y*(b-w)+x*(w-v)+_*(v-b))<O)&&N.push(R,R+1,R+2)}(t,e)}class Am{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=bm._segmentsCount(Am.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 Sm={[Sd.POLY]:mm,[Sd.CIRC]:pm,[Sd.ELIP]:pm,[Sd.RECT]:gm,[Sd.RREC]:ym},Cm=[],Mm=[];class Nm{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 Nm(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 Om=new Cd,Rm=class t extends Pd{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 sm,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(),Mm.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),Cm.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 Nm(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 Nm(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,Om):Om.copyFrom(t),s.shape.contains(Om.x,Om.y))){let t=!1;if(s.holes)for(let e=0;e<s.holes.length;e++)if(s.holes[e].shape.contains(Om.x,Om.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;Sm[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=Hh.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=Cm.pop()||new wm,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=++fd._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),Mm.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let s=Mm.pop();s||(s=new md,s.texArray=new bp),s.texArray.count=0,s.start=0,s.size=0,s.type=Fh.TRIANGLES;let r=0,n=null,o=0,a=!1,l=Fh.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?Fh.LINES:Fh.TRIANGLES,n=null,r=d,t++),n!==f&&(n=f,f._batchEnabled!==t&&(r===d&&(t++,r=0,s.size>0&&(s=Mm.pop(),s||(s=new md,s.texArray=new bp),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=Hh.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)}fd._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?mm.triangulate(t,this):Sm[t.type].triangulate(t,this)}processLine(t){Im(t,this);for(let e=0;e<t.holes.length;e++)Im(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];Sm[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=Ac.shared.setValue(e).toLittleEndianNumber(),o=Ac.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}};Rm.BATCHABLE_SIZE=100;let Lm=Rm;class km{constructor(){this.color=16777215,this.alpha=1,this.texture=Dp.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new km;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=Dp.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class Fm extends km{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=xm.BUTT,this.join=vm.MITER,this.miterLimit=10}clone(){const t=new Fm;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=xm.BUTT,this.join=vm.MITER,this.miterLimit=10}}const Dm={},Bm=class t extends hm{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 km,this._lineStyle=new Fm,this._matrix=null,this._holeMode=!1,this.state=od.for2d(),this._geometry=t||new Lm,this._geometry.refCount++,this._transformID=-1,this._tintColor=new Ac(16777215),this.blendMode=kh.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:Dp.WHITE,color:(null==t?void 0:t.texture)?16777215:0,matrix:null,alignment:.5,native:!1,cap:xm.BUTT,join:vm.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 Ld,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new Ld,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),Am.curveTo(t,e,i,s,r),this}bezierCurveTo(t,e,i,s,r,n){return this._initCurve(),Em.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=_m.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+=Td:n&&s<=r&&(s+=Td),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 _m.arc(o,a,t,e,i,s,r,n,h),this}beginFill(t=0,e){return this.beginTextureFill({texture:Dp.WHITE,color:t,alpha:e})}normalizeColor(t){const e=Ac.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:Dp.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 Nd(t,e,i,s))}drawRoundedRect(t,e,i,s,r){return this.drawShape(new kd(t,e,i,s,r))}drawCircle(t,e,i){return this.drawShape(new Od(t,e,i))}drawEllipse(t,e,i,s){return this.drawShape(new Rd(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 Ld(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!==Sd.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:Ac.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,Ac.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(!Dm[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 Fd,default:yp.from({uSamplers:s},!0)},n=t.plugins[i]._shader.program;Dm[i]=new vp(n,r)}e=Dm[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=Ac.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)}};Bm.curves=bm,Bm._TEMP_POINT=new Cd;let Um=Bm;var Gm=(t=>(t[t.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",t[t.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",t))(Gm||{});const Xm={willReadFrequently:!0},Hm=class t{static get experimentalLetterSpacingSupported(){let e=t._experimentalLetterSpacingSupported;if(void 0!==e){const i=Zh.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",Xm);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",Xm);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",Xm))?void 0:e.measureText)return t.__canvas=s,s;i=Zh.ADAPTER.createCanvas()}catch{i=Zh.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",Xm)),t.__context}};Hm.METRICS_STRING="|ÉqÅ",Hm.BASELINE_SYMBOL="M",Hm.BASELINE_MULTIPLIER=1.4,Hm.HEIGHT_MULTIPLIER=2,Hm.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]})(),Hm.experimentalLetterSpacing=!1,Hm._fonts={},Hm._newlines=[10,13],Hm._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let Wm=Hm;const Ym=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],$m=class t{constructor(t){this.styleID=0,this.reset(),jm(this,t,t)}clone(){const e={};return jm(e,this,t.defaultStyle),new t(e)}reset(){jm(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=Vm(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=Vm(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=Vm(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)&&!Ym.includes(t)&&(t=`"${t}"`),e[i]=t}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};$m.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Gm.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 zm=$m;function Vm(t){const e=Ac.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 jm(t,e,i){for(const s in i)Array.isArray(e[s])?t[s]=e[s].slice():t[s]=e[s]}const qm={texture:!0,children:!1,baseTexture:!0},Jm=class t extends dm{constructor(e,i,s){let r=!1;s||(s=Zh.ADAPTER.createCanvas(),r=!0),s.width=3,s.height=3;const n=Dp.from(s);n.orig=new Nd,n.trim=new Nd,super(n),this._ownCanvas=r,this.canvas=s,this.context=s.getContext("2d",{willReadFrequently:!0}),this._resolution=t.defaultResolution??Zh.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 Wm.experimentalLetterSpacing}static set experimentalLetterSpacing(t){$u("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),Wm.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=Wm.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=Ac.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(Wm.experimentalLetterSpacingSupported&&(Wm.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=Wm.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=qc(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===Gm.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({},qm,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=Fc(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=Fc(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 zm?t:new zm(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)}};Jm.defaultAutoResolution=!0;let Zm=Jm;class Km extends Tp{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]=Ac.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=Ac.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}}Km.prototype.grayscale=Km.prototype.greyscale;var Qm={exports:{}};!function(t,e){(function(){var 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}},function(e){t.exports=e}(e)}).call(yt)}(Qm);const tg=vt(Qm.exports);hm.prototype._renderCanvas=function(t){},hm.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)}},rm.prototype.renderCanvas=function(t){},Zm.prototype._renderCanvas=function(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),dm.prototype._renderCanvas.call(this,t)},rm.prototype.name=null,hm.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 eg={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)}},ig={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(Tf.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?ig:eg)[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 sg=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||(Uf.system.add(this.tickerUpdate,this,Ff.INTERACTION),this.tickerAdded=!0)}removeTickerListener(){this.tickerAdded&&(Uf.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 rg{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=rg.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new Cd,this.page=new Cd,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 ng extends rg{constructor(){super(...arguments),this.client=new Cd,this.movement=new Cd,this.offset=new Cd,this.global=new Cd,this.screen=new Cd}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 og extends ng{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 ag extends ng{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}ag.DOM_DELTA_PIXEL=0,ag.DOM_DELTA_LINE=1,ag.DOM_DELTA_PAGE=2;const lg=new Cd,hg=new Cd;class ug{constructor(t){this.dispatch=new yu,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){sg.pauseUpdate=!0;const i=this[this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive"](this.rootTarget,this.rootTarget.eventMode,lg.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)&&(sg.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)&&(sg.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,hg),!t.hitArea.contains(hg.x,hg.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 og))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 og))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 og))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 og))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 og))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 og))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 ag))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(og);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(ag);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(og);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 og&&e instanceof og&&(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 ng&&e instanceof ng&&(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 cg={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},dg=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 ug(null),sg.init(this),this.autoPreventDefault=!0,this.eventsAdded=!1,this.rootPointerEvent=new og(null),this.rootWheelEvent=new ag(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,sg.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,sg.domElement=t,this.addEvents()}addEvents(){if(this.eventsAdded||!this.domElement)return;sg.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;sg.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=cg[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}};dg.extension={name:"events",type:[Qc.RendererSystem,Qc.CanvasRendererSystem]},dg.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let pg=dg;function fg(t){return"dynamic"===t||"static"===t}id.add(pg);const mg={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??fg(pg.defaultEventMode)},set interactive(t){$u("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??pg.defaultEventMode},set eventMode(t){this._internalInteractive=fg(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 rg))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}};rm.mixin(mg);const gg=new Nd;class yg{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 Bp?n=t:(n=i.generateTexture(t,{region:e,resolution:i.resolution}),e&&(gg.width=e.width,gg.height=e.height,e=gg))),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=gg).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 $c(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 Bp?n=t:(n=i.generateTexture(t,{region:e,resolution:i.resolution}),e&&(gg.width=e.width,gg.height=e.height,e=gg))),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=i.canvasContext.rootContext,r=i.resolution,e||((e=gg).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 vg;function xg(t){const e=Zh.ADAPTER.createCanvas(6,1),i=e.getContext("2d");return i.fillStyle=t,i.fillRect(0,0,6,1),e}function bg(){if(typeof document>"u")return!1;if(void 0!==vg)return vg;const t=xg("#ff00ff"),e=xg("#ffff00"),i=Zh.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;vg=255===t[0]&&0===t[1]&&0===t[2]}else vg=!1;return vg}yg.extension={name:"extract",type:Qc.CanvasRendererSystem},id.add(yg),fd.prototype.getDrawableSource=function(){const t=this.resource;return t?t.bitmap||t.source:null},Np.prototype._canvasRenderTarget=null,Dp.prototype.patternCache=null,Dp.prototype.tintCache=null;const _g=new Fd;class wg{constructor(t){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=function(t=[]){return bg()?(t[kh.NORMAL]="source-over",t[kh.ADD]="lighter",t[kh.MULTIPLY]="multiply",t[kh.SCREEN]="screen",t[kh.OVERLAY]="overlay",t[kh.DARKEN]="darken",t[kh.LIGHTEN]="lighten",t[kh.COLOR_DODGE]="color-dodge",t[kh.COLOR_BURN]="color-burn",t[kh.HARD_LIGHT]="hard-light",t[kh.SOFT_LIGHT]="soft-light",t[kh.DIFFERENCE]="difference",t[kh.EXCLUSION]="exclusion",t[kh.HUE]="hue",t[kh.SATURATION]="saturation",t[kh.COLOR]="color",t[kh.LUMINOSITY]="luminosity"):(t[kh.NORMAL]="source-over",t[kh.ADD]="lighter",t[kh.MULTIPLY]="source-over",t[kh.SCREEN]="source-over",t[kh.OVERLAY]="source-over",t[kh.DARKEN]="source-over",t[kh.LIGHTEN]="source-over",t[kh.COLOR_DODGE]="source-over",t[kh.COLOR_BURN]="source-over",t[kh.HARD_LIGHT]="source-over",t[kh.SOFT_LIGHT]="source-over",t[kh.DIFFERENCE]="source-over",t[kh.EXCLUSION]="source-over",t[kh.HUE]="source-over",t[kh.SATURATION]="source-over",t[kh.COLOR]="source-over",t[kh.LUMINOSITY]="source-over"),t[kh.NORMAL_NPM]=t[kh.NORMAL],t[kh.ADD_NPM]=t[kh.ADD],t[kh.SCREEN_NPM]=t[kh.SCREEN],t[kh.SRC_IN]="source-in",t[kh.SRC_OUT]="source-out",t[kh.SRC_ATOP]="source-atop",t[kh.DST_OVER]="destination-over",t[kh.DST_IN]="destination-in",t[kh.DST_OUT]="destination-out",t[kh.DST_ATOP]="destination-atop",t[kh.XOR]="xor",t[kh.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=_g,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?Ac.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===kh.SRC_IN||t===kh.SRC_OUT||t===kh.DST_IN||t===kh.DST_ATOP;!e&&i&&(t=kh.NORMAL),this._activeBlendMode!==t&&(this._activeBlendMode=t,this._outerBlend=i,this.activeContext.globalCompositeOperation=this.blendModes[t])}resize(){this.smoothProperty&&(this.rootContext[this.smoothProperty]=fd.defaultOptions.scaleMode===Xh.LINEAR)}invalidateBlendMode(){this._activeBlendMode=this.blendModes.indexOf(this.activeContext.globalCompositeOperation)}destroy(){this.renderer=null,this.rootContext=null,this.activeContext=null,this.smoothProperty=null}}wg.extension={type:Qc.CanvasRendererSystem,name:"canvasContext"},id.add(wg);class Eg{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===Sd.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===Sd.RECT)e.rect(s.x,s.y,s.width,s.height),e.closePath();else if(s.type===Sd.CIRC)e.arc(s.x,s.y,s.radius,0,2*Math.PI),e.closePath();else if(s.type===Sd.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===Sd.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(){}}Eg.extension={type:Qc.CanvasRendererSystem,name:"mask"},id.add(Eg);class Pg{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 $c(r.width,r.height,r.resolution),r.resource=new qf(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=kh.NORMAL,s._outerBlend=!1,h.globalCompositeOperation=s.blendModes[kh.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}}Pg.extension={type:Qc.CanvasRendererSystem,name:"objectRenderer"},id.add(Pg);const{deprecation:Tg}=Kc,Ig=class t extends Cf{constructor(e){super(),this.type=Rh.CANVAS,this.rendererLogId="Canvas",e=Object.assign({},Zh.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&&(Tg("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 Tg("7.0.0","renderer.blendModes has been deprecated, please use renderer.canvasContext.blendModes instead"),this.canvasContext.blendModes}get maskManager(){return Tg("7.0.0","renderer.maskManager has been deprecated, please use renderer.mask instead"),this.mask}get refresh(){return Tg("7.0.0","renderer.refresh has been deprecated"),!0}get rootContext(){return Tg("7.0.0","renderer.rootContext has been deprecated, please use renderer.canvasContext.rootContext instead"),this.canvasContext.rootContext}get context(){return Tg("7.0.0","renderer.context has been deprecated, please use renderer.canvasContext.activeContext instead"),this.canvasContext.activeContext}get smoothProperty(){return Tg("7.0.0","renderer.smoothProperty has been deprecated, please use renderer.canvasContext.smoothProperty instead"),this.canvasContext.smoothProperty}setBlendMode(t,e){Tg("7.0.0","renderer.setBlendMode has been deprecated, use renderer.canvasContext.setBlendMode instead"),this.canvasContext.setBlendMode(t,e)}invalidateBlendMode(){Tg("7.0.0","renderer.invalidateBlendMode has been deprecated, use renderer.canvasContext.invalidateBlendMode instead"),this.canvasContext.invalidateBlendMode()}setContextTransform(t,e,i){Tg("7.0.0","renderer.setContextTransform has been deprecated, use renderer.canvasContext.setContextTransform instead"),this.canvasContext.setContextTransform(t,e,i)}get backgroundColor(){return Tg("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){Tg("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return Tg("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){Tg("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get preserveDrawingBuffer(){return Tg("7.0.0","renderer.preserveDrawingBuffer has been deprecated"),!1}get useContextAlpha(){return Tg("7.0.0","renderer.useContextAlpha has been deprecated"),!1}};Ig.extension={type:Qc.Renderer,priority:0},Ig.__plugins={},Ig.__systems={};let Ag=Ig;id.handleByMap(Qc.CanvasRendererPlugin,Ag.__plugins),id.handleByMap(Qc.CanvasRendererSystem,Ag.__systems),id.add(Ag);const Sg={canvas:null,getTintedCanvas:(t,e)=>{const i=t.texture,s=Ac.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=Zh.ADAPTER.createCanvas();return Sg.tintMethod(i,e,n),n.tintId=i._updateID,Sg.convertTintToImage||(i.tintCache[s]=n),n},getTintedPattern:(t,e)=>{const i=Ac.shared.setValue(e).toHex();t.patternCache=t.patternCache||{};let s=t.patternCache[i];return(null==s?void 0:s.tintId)===t._updateID||(Sg.canvas||(Sg.canvas=Zh.ADAPTER.createCanvas()),Sg.tintMethod(t,e,Sg.canvas),s=Sg.canvas.getContext("2d").createPattern(Sg.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=Ac.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]=Ac.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=>($u("7.3.0","PIXI.canvasUtils.roundColor is deprecated"),Ac.shared.setValue(t).round(Sg.cacheStepsPerColorChannel).toNumber()),cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:bg(),tintMethod:null};let Cg;Sg.tintMethod=Sg.canUseMultiply?Sg.tintWithMultiply:Sg.tintWithPerPixel;const Mg=new Fd;Um.prototype.generateCanvasTexture=function(t,e=1){const i=this.getLocalBounds(new Nd);i.width=Math.max(i.width,1/e),i.height=Math.max(i.height,1/e);const s=Bp.create({width:i.width,height:i.height,scaleMode:t,resolution:e});Cg||(Cg=new Ag),this.transform.updateLocalTransform(),this.transform.localTransform.copyTo(Mg),Mg.invert(),Mg.tx-=i.x,Mg.ty-=i.y,Cg.render(this,{renderTexture:s,clear:!0,transform:Mg});const r=Dp.from(s.baseTexture._canvasRenderTarget.canvas,{scaleMode:t});return r.baseTexture.setResolution(e),r},Um.prototype.cachedGraphicsData=[],Um.prototype._renderCanvas=function(t){!0!==this.isMask&&(this.finishPoly(),t.plugins.graphics.render(this))};class Ng{static offsetPolygon(t,e){const i=[],s=t.length;e=Ng.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=Ng.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 Og{constructor(t){this._svgMatrix=null,this._tempMatrix=new Fd,this.renderer=t}_calcCanvasStyle(t,e){let i;return t.texture&&t.texture.baseTexture!==Dp.WHITE.baseTexture?t.texture.valid?(i=Sg.getTintedPattern(t.texture,e),this.setPatternTransform(i,t.matrix||Fd.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=Ac.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,Ac.shared.setValue(p).multiply(l).toNumber())),d.visible&&(a=this._calcCanvasStyle(d,Ac.shared.setValue(f).multiply(l).toNumber())),i.lineWidth=d.width,i.lineCap=d.cap,i.lineJoin=d.join,i.miterLimit=d.miterLimit,t.type===Sd.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===Sd.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===Sd.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===Sd.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===Sd.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=Ng.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=Ng.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}}Og.extension={name:"graphics",type:Qc.CanvasRendererPlugin},id.add(Og);class Rg{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function Lg(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 Dp){const i=t._textures[r].baseTexture;e.includes(i)||(e.push(i),s=!0)}return s}function kg(t,e){if(t.baseTexture instanceof fd){const i=t.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function Fg(t,e){if(t._texture&&t._texture instanceof Dp){const i=t._texture.baseTexture;return e.includes(i)||e.push(i),!0}return!1}function Dg(t,e){return e instanceof Zm&&(e.updateText(!0),!0)}function Bg(t,e){if(e instanceof zm){const t=e.toFontString();return Wm.measureFont(t),!0}return!1}function Ug(t,e){if(t instanceof Zm){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 Gg(t,e){return t instanceof zm&&(e.includes(t)||e.push(t),!0)}const Xg=class t{constructor(e){this.limiter=new Rg(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(Ug),this.registerFindHook(Gg),this.registerFindHook(Lg),this.registerFindHook(kg),this.registerFindHook(Fg),this.registerUploadHook(Dg),this.registerUploadHook(Bg)}upload(t){return new Promise((e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,Uf.system.addOnce(this.tick,this,Ff.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)Uf.system.addOnce(this.tick,this,Ff.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 hm)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&Uf.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}};Xg.uploadsPerFrame=4;let Hg=Xg;function Wg(t,e){return e instanceof fd&&(e._glTextures[t.CONTEXT_UID]||t.texture.bind(e),!0)}function Yg(t,e){if(!(e instanceof Um))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&&Wg(t,e.baseTexture)}return i.batchable||t.geometry.bind(i,e._resolveDirectShader(t)),!0}function $g(t,e){return t instanceof Um&&(e.push(t),!0)}Object.defineProperties(Zh,{UPLOADS_PER_FRAME:{get:()=>Hg.uploadsPerFrame,set(t){$u("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),Hg.uploadsPerFrame=t}}});class zg extends Hg{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook($g),this.registerUploadHook(Wg),this.registerUploadHook(Yg)}}zg.extension={name:"prepare",type:Qc.RendererSystem},id.add(zg);function Vg(t,e){const i=t;if(e instanceof fd){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 jg extends Hg{constructor(t){super(t),this.uploadHookHelper=this,this.canvas=Zh.ADAPTER.createCanvas(16,16),this.ctx=this.canvas.getContext("2d"),this.registerUploadHook(Vg)}destroy(){super.destroy(),this.ctx=null,this.canvas=null}}jg.extension={name:"prepare",type:Qc.CanvasRendererSystem},id.add(jg),dm.prototype._tintedCanvas=null,dm.prototype._renderCanvas=function(t){t.plugins.sprite.render(this)};const qg=new Fd;class Jg{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===Xh.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(qg),h=qg,Yd.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=Sg.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(kh.NORMAL)}destroy(){this.renderer=null}}Jg.extension={name:"sprite",type:Qc.CanvasRendererPlugin},id.add(Jg);var Zg=Object.defineProperty,Kg=(t,e,i)=>(((t,e,i)=>{e in t?Zg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);let Qg=class{constructor(t){Kg(this,"parent"),Kg(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 ty,ey=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},iy={exports:{}};ty=iy,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}},ty.exports=e}.call(ey);const sy=iy.exports;function ry(t,e){return t?"function"==typeof t?t:"string"==typeof t?sy[t]:void 0:sy[e]}const ny={removeOnInterrupt:!1,ease:"linear",time:1e3};let oy=class extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"startX"),Kg(this,"startY"),Kg(this,"deltaX"),Kg(this,"deltaY"),Kg(this,"keepCenter"),Kg(this,"startWidth",null),Kg(this,"startHeight",null),Kg(this,"deltaWidth",null),Kg(this,"deltaHeight",null),Kg(this,"width",null),Kg(this,"height",null),Kg(this,"time",0),this.options=Object.assign({},ny,e),this.options.ease=ry(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 Cd(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 Cd(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 ay={sides:"all",friction:.5,time:150,ease:"easeInOutSine",underflow:"center",bounceBox:null};class ly extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"left"),Kg(this,"top"),Kg(this,"right"),Kg(this,"bottom"),Kg(this,"underflowX"),Kg(this,"underflowY"),Kg(this,"ease"),Kg(this,"toX"),Kg(this,"toY"),this.options=Object.assign({},ay,e),this.ease=ry(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 Cd(e*this.parent.scale.x,i*this.parent.scale.y),bottomRight:new Cd(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 Cd(0,0),bottomRight:new Cd(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 hy={left:!1,right:!1,top:!1,bottom:!1,direction:null,underflow:"center"};class uy extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"last"),Kg(this,"noUnderflow"),Kg(this,"underflowX"),Kg(this,"underflowY"),this.options=Object.assign({},hy,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 Cd(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 cy={minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,minScale:null,maxScale:null};class dy extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),this.options=Object.assign({},cy,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 py={friction:.98,bounce:.8,minSpeed:.01},fy=16;let my=class extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"x"),Kg(this,"y"),Kg(this,"percentChangeX"),Kg(this,"percentChangeY"),Kg(this,"saved"),Kg(this,"timeSinceRelease"),this.options=Object.assign({},py,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*fy/r*(Math.pow(e,s/fy)-Math.pow(e,i/fy)),this.x*=Math.pow(this.percentChangeX,t/fy)}if(this.y){const e=this.percentChangeY,r=Math.log(e);this.parent.y+=this.y*fy/r*(Math.pow(e,s/fy)-Math.pow(e,i/fy)),this.y*=Math.pow(this.percentChangeY,t/fy)}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 gy={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 yy extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"moved"),Kg(this,"reverse"),Kg(this,"xDirection"),Kg(this,"yDirection"),Kg(this,"keyIsPressed"),Kg(this,"mouse"),Kg(this,"underflowX"),Kg(this,"underflowY"),Kg(this,"last"),Kg(this,"current"),Kg(this,"windowEventHandlers",[]),this.options=Object.assign({},gy,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 Cd(this.last.x,this.last.y),world:this.parent.toWorld(new Cd(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 Cd(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 vy={speed:0,acceleration:null,radius:null};class xy extends Qg{constructor(t,e,i={}){super(t),Kg(this,"options"),Kg(this,"target"),Kg(this,"velocity"),this.target=e,this.options=Object.assign({},vy,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 by={radius:null,distance:null,top:null,bottom:null,left:null,right:null,speed:8,reverse:!1,noDecelerate:!1,linear:!1,allowButtons:!1};let _y=class extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"reverse"),Kg(this,"radiusSquared"),Kg(this,"left"),Kg(this,"top"),Kg(this,"right"),Kg(this,"bottom"),Kg(this,"horizontal"),Kg(this,"vertical"),this.options=Object.assign({},by,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 wy={noDrag:!1,percent:1,center:null,factor:1,axis:"all"};class Ey extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"active",!1),Kg(this,"pinching",!1),Kg(this,"moved",!1),Kg(this,"lastCenter"),this.options=Object.assign({},wy,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 Cd(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 Py={topLeft:!1,friction:.8,time:1e3,ease:"easeInOutSine",interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1};class Ty extends Qg{constructor(t,e,i,s={}){super(t),Kg(this,"options"),Kg(this,"ease"),Kg(this,"x"),Kg(this,"y"),Kg(this,"percent"),Kg(this,"snapping"),Kg(this,"deltaX"),Kg(this,"deltaY"),Kg(this,"startX"),Kg(this,"startY"),this.options=Object.assign({},Py,s),this.ease=ry(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 Iy={width:0,height:0,time:1e3,ease:"easeInOutSine",center:null,interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1,noMove:!1};class Ay extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"ease"),Kg(this,"xScale"),Kg(this,"yScale"),Kg(this,"xIndependent"),Kg(this,"yIndependent"),Kg(this,"snapping"),this.options=Object.assign({},Iy,e),this.ease=ry(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 Sy={percent:.1,smooth:!1,interrupt:!0,reverse:!1,center:null,lineHeight:20,axis:"all",keyToPress:null,trackpadPinch:!1,wheelZoom:!0};class Cy extends Qg{constructor(t,e={}){super(t),Kg(this,"options"),Kg(this,"smoothing"),Kg(this,"smoothingCenter"),Kg(this,"smoothingCount"),Kg(this,"keyIsPressed"),this.options=Object.assign({},Sy,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 My=class{constructor(t){Kg(this,"viewport"),Kg(this,"clickedAvailable"),Kg(this,"isMouseDown"),Kg(this,"last"),Kg(this,"wheelFunction"),Kg(this,"touches"),this.viewport=t,this.touches=[],this.addListeners()}addListeners(){this.viewport.eventMode="static",this.viewport.forceHitArea||(this.viewport.hitArea=new Nd(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 Cd;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 Ny=["drag","pinch","wheel","follow","mouse-edges","decelerate","animate","bounce","snap-zoom","clamp-zoom","snap","clamp"];class Oy{constructor(t){Kg(this,"plugins"),Kg(this,"list"),Kg(this,"viewport"),this.viewport=t,this.list=[],this.plugins={}}add(t,e,i=Ny.length){const s=this.plugins[t];s&&s.destroy(),this.plugins[t]=e;const r=Ny.indexOf(t);-1!==r&&Ny.splice(r,1),Ny.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 Ny)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 Ry={screenWidth:window.innerWidth,screenHeight:window.innerHeight,worldWidth:null,worldHeight:null,threshold:5,passiveWheel:!0,stopPropagation:!1,forceHitArea:null,noTicker:!1,disableOnContextMenu:!1,ticker:Uf.shared,allowPreserveDragOutside:!1};class Ly extends hm{constructor(t){super(),Kg(this,"moving"),Kg(this,"screenWidth"),Kg(this,"screenHeight"),Kg(this,"threshold"),Kg(this,"input"),Kg(this,"plugins"),Kg(this,"zooming"),Kg(this,"lastViewport"),Kg(this,"options"),Kg(this,"_dirty"),Kg(this,"_forceHitArea"),Kg(this,"_hitAreaDefault"),Kg(this,"_pause"),Kg(this,"tickerFunction"),Kg(this,"_worldWidth"),Kg(this,"_worldHeight"),Kg(this,"_disableOnContextMenu",(t=>t.preventDefault())),this.options={...Ry,...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 My(this),this.plugins=new Oy(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 Nd(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 Nd(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight)}toWorld(t,e){return 2===arguments.length?this.toLocal(new Cd(t,e)):this.toLocal(t)}toScreen(t,e){return 2===arguments.length?this.toGlobal(new Cd(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 Cd(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 Cd(-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 Ay(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 Cd(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 Nd(0,0,this.worldWidth,this.worldHeight))}drag(t){return this.plugins.add("drag",new yy(this,t)),this}clamp(t){return this.plugins.add("clamp",new uy(this,t)),this}decelerate(t){return this.plugins.add("decelerate",new my(this,t)),this}bounce(t){return this.plugins.add("bounce",new ly(this,t)),this}pinch(t){return this.plugins.add("pinch",new Ey(this,t)),this}snap(t,e,i){return this.plugins.add("snap",new Ty(this,t,e,i)),this}follow(t,e){return this.plugins.add("follow",new xy(this,t,e)),this}wheel(t){return this.plugins.add("wheel",new Cy(this,t)),this}animate(t){return this.plugins.add("animate",new oy(this,t)),this}clampZoom(t){return this.plugins.add("clamp-zoom",new dy(this,t)),this}mouseEdges(t){return this.plugins.add("mouse-edges",new _y(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"})}}const ky=100;var Fy={exports:{}};function Dy(){}Dy.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}},Fy.exports=Dy;var By=Fy.exports.TinyEmitter=Dy;class Uy extends By{constructor({floorPlan:t,helperId:e}){super(),this.floorPlan=t,this.helperId=e}destroy(){delete this.floorPlan.helper[this.helperId],this.floorPlan=null}}class Gy extends Uy{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 Xy extends Uy{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 Hy=100,Wy=80;class Yy{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||Hy;this.width=Math.max(100,o);let a=e||Wy;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 $y{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 yl.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=R(),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 zy={grad:.9,turn:360,rad:360/(2*Math.PI)},Vy=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},jy=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},qy=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},Jy=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},Zy=function(t){return{r:qy(t.r,0,255),g:qy(t.g,0,255),b:qy(t.b,0,255),a:qy(t.a)}},Ky=function(t){return{r:jy(t.r),g:jy(t.g),b:jy(t.b),a:jy(t.a,3)}},Qy=/^#([0-9a-f]{3,8})$/i,tv=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},ev=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}},iv=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}},sv=function(t){return{h:Jy(t.h),s:qy(t.s,0,100),l:qy(t.l,0,100),a:qy(t.a)}},rv=function(t){return{h:jy(t.h),s:jy(t.s),l:jy(t.l),a:jy(t.a,3)}},nv=function(t){return iv((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},ov=function(t){return{h:(e=ev(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},av=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,lv=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,hv=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,uv=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,cv={string:[[function(t){var e=Qy.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?jy(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?jy(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=hv.exec(t)||uv.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:Zy({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=av.exec(t)||lv.exec(t);if(!e)return null;var i,s,r=sv({h:(i=e[1],s=e[2],void 0===s&&(s="deg"),Number(i)*(zy[s]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return nv(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 Vy(e)&&Vy(i)&&Vy(s)?Zy({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(!Vy(e)||!Vy(i)||!Vy(s))return null;var o=sv({h:Number(e),s:Number(i),l:Number(s),a:Number(n)});return nv(o)},"hsl"],[function(t){var e=t.h,i=t.s,s=t.v,r=t.a,n=void 0===r?1:r;if(!Vy(e)||!Vy(i)||!Vy(s))return null;var o,a=(o={h:Number(e),s:Number(i),v:Number(s),a:Number(n)},{h:Jy(o.h),s:qy(o.s,0,100),v:qy(o.v,0,100),a:qy(o.a)});return iv(a)},"hsv"]]},dv=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]},pv=function(t,e){var i=ov(t);return{h:i.h,s:qy(i.s+100*e,0,100),l:i.l,a:i.a}},fv=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},mv=function(t,e){var i=ov(t);return{h:i.h,s:i.s,l:qy(i.l+100*e,0,100),a:i.a}},gv=function(){function t(t){this.parsed=function(t){return"string"==typeof t?dv(t.trim(),cv.string):"object"==typeof t&&null!==t?dv(t,cv.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 jy(fv(this.rgba),2)},t.prototype.isDark=function(){return fv(this.rgba)<.5},t.prototype.isLight=function(){return fv(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=Ky(this.rgba)).r,i=t.g,s=t.b,n=(r=t.a)<1?tv(jy(255*r)):"","#"+tv(e)+tv(i)+tv(s)+n;var t,e,i,s,r,n},t.prototype.toRgb=function(){return Ky(this.rgba)},t.prototype.toRgbString=function(){return e=(t=Ky(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 rv(ov(this.rgba))},t.prototype.toHslString=function(){return e=(t=rv(ov(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=ev(this.rgba),{h:jy(t.h),s:jy(t.s),v:jy(t.v),a:jy(t.a,3)};var t},t.prototype.invert=function(){return yv({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),yv(pv(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),yv(pv(this.rgba,-t))},t.prototype.grayscale=function(){return yv(pv(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),yv(mv(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),yv(mv(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?yv({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):jy(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=ov(this.rgba);return"number"==typeof t?yv({h:t,s:e.s,l:e.l,a:e.a}):jy(e.h)},t.prototype.isEqual=function(t){return this.toHex()===yv(t).toHex()},t}(),yv=function(t){return t instanceof gv?t:new gv(t)},vv=[];!function(t){t.forEach((function(t){vv.indexOf(t)<0&&(t(gv,cv),vv.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 xv=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=yv(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)}};xv.shared=new xv,xv.temp=new xv,xv.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let bv=xv;class _v{constructor({position:t,color:e,size:i,floorPlan:s}){this.position=t,this.color=e,this.size=i,this.floorPlan=s,this.id=R(),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 bv(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 wv=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 Ev(t,e,i){const s=new dm(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 Pv(t=[]){return(t=t.sort(((t,e)=>Z(t)>Z(e)?-1:1)))&&t.length?[{type:"curve:polygonWithHoles",polygons:t}]:[]}function Tv(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 Iv(t){return t.stroke?{alpha:t.strokeOpacity||1,color:wh(t.stroke),native:"native"===t.strokeWidth,width:"number"==typeof t.strokeWidth?t.strokeWidth:1}:{}}function Av({shape:t,settings:e,gfx:i,style:s={}}){var r,n,o;if(!i||!i.lineStyle)return;let a={...s,...t.style||{}};const l=ky,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(fd.defaultOptions.scaleMode=Xh.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=dm.from(l);if("curve:polygon"===t.type){let{min:i,max:r}=z([t.points]);n=r[0]-i[0],o=r[1]-i[1],a=i;let l=new Um;Av({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*ky,h.height=o*ky,h.x=a[0]*ky,h.y=a[1]*ky,h.anchor.set(0),s.addChild(h)}({shape:t,settings:e,style:a,gfx:i});else{if(h&&a.fill&&i.beginFill(wh(a.fill),a.fillOpacity),i.lineStyle(Iv(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){Sv(Ch(t).points,[],a,l,i,h)}else if("curve:arc"===t.type||"curve:quadraticBezier"===t.type){Mh(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)Sv(t.points,[],a,l,i,h);else if("curve:polygonWithHoles"===t.type){let{polygons:e}=t;Sv(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?Tv(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 Um;o.x=r[0]*l,o.y=r[1]*l,o.rotation=-Math.PI/180*n,t.children.forEach((t=>Av({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)?wh(t.style.fill):0,a=(null==(n=t.style)?void 0:n.stroke)?wh(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 zm({fontFamily:(null==(o=null==e?void 0:e.theme)?void 0:o.fontFamily)||pl.theme.fontFamily,fontSize:f,fill:s,align:d,stroke:a,strokeThickness:3});let g=new Zm(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 Sv(t=[],e=[],i={},s=100,r,n){if(!t||!Array.isArray(t)||!t.length)return r;r.lineStyle(Iv(i));let o=t.flat().map((t=>t*s));if(i.dash?(Tv(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 Cv(t,e){e.on("product-load-texture",(({resourceId:i})=>{!function(t,e){let i=t.resources.productJson.get(e);if(!i.boundingBox)return void yl.warn("product boundingBox missing");const{boundingBox:s}=i,r=Nl(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),Mv({view:t,resourceId:i,loader:e})}));const i=new Um;i.lineStyle({native:!0,color:3355443}),i.drawCircle(0,0,1),t._dummyTexture=t._renderer.generateTexture(i)}function Mv({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 Yc(),function(t){return new Promise(((e,i)=>{var s=new Image;s.addEventListener("load",(()=>{URL.revokeObjectURL(s.src),e(new Dp(new fd(s)))})),s.addEventListener("error",(()=>{URL.revokeObjectURL(s.src),i("image loading failed: "+t)}));const r=t.includes("/storage/get/"),n=t.startsWith("https://")?t:ml+t;s.src=n,s.crossOrigin=r?"use-credentials":"anonymous"}))}(r).then((r=>{s.imageData=r,Rv(t,i,e)})).catch((r=>{yl.warn(r),s.error=r,Rv(t,i,e)}))}function Nv(t,e){let i,s=new Um;for(const r of t)Av({shape:r,gfx:s,style:e});return i=s.generateCanvasTexture(Xh.LINEAR,2),s.destroy(),i}function Ov(t,e){switch(e){case Al.Default:{const e=new Km;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 Al.Grayscale:{const e=new Km;e.blackAndWhite(!0),t.filters=[e];break}case Al.None:}return t}function Rv(t,e,i){const s=null==e?void 0:e._renderer,r=i.resources.texture.get(t),n=r.error;if(Yc(),!r.texture){const e=i.resources.productJson.get(t),o=new hm;let a,l;n||(a=new dm(r.imageData),a=Ov(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=Th({settings:{theme:{showAssetTextures:!0,elements:{}}},elementType:"element:asset"}),t.stroke=dl.stone),l=Nv(u,t);const i=new dm(l);i.anchor.x=r.anchor.x,i.anchor.y=r.anchor.y;const s=Nl(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:Xh.LINEAR,resolution:1.5}),o.destroy(!0),l&&l.destroy(!0)}i.emit("resource-loaded",{resourceId:t})}function Lv(t,e,i,s){var r;!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)))vl(e,t).catch(yl.warn)}(t,i);const{view:n,settings:o,loader:a}=i,{theme:l,showCeilingLamps:h}=o,u=ky;let c,d,p=[],{position:f,rotation:m}=t.getWorldTransform();const g=null==(r=t.product)?void 0:r.id,y=a.resources.productJson.get(g)||{subCategories:[]},v=a.resources.productContour.get(g),x=a.resources.texture.get(g),b=Pv(v);if((null==y?void 0:y.subCategories.includes("ceilingLight"))&&!h)return[];const _=bh(t.type,function(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}(y));e.zIndex=_||0;const w=Th({element:t,settings:o,style:s});if(!v&&y.boundingBox){p=Pv(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[]}(y.boundingBox)),c=new Um}else if(l.showAssetTextures&&!(null==x?void 0:x.error)||!v)if(l.showAssetTextures&&(null==x?void 0:x.texture)){const t=Nl(y.boundingBox);c=Ev(x.texture,t[0]*u,t[2]*u),c.anchor.x=x.anchor.x,c.anchor.y=x.anchor.y,c.zIndex=1,x&&"selected"===s?(x.contourTexture||(x.contourTexture=Nv(b,{stroke:w.stroke,strokeWidth:w.strokeWidth||1})),d=new dm(x.contourTexture),d.anchor.x=x.anchor.x,d.anchor.y=x.anchor.y,d.zIndex=5,w.fill&&(c.tint=wh(w.fill))):s&&(d=new Um,p=b||[],d.zIndex=5)}else c=new dm(n._dummyTexture);else p=b,c=new Um;c&&(c.x=f[0]*u,c.y=f[2]*u,c.rotation=-Math.PI/180*m||0),d&&(d.x=f[0]*u,d.y=f[2]*u,d.rotation=-Math.PI/180*m||0);for(const E of p)Av({shape:E,settings:o,gfx:d||c,style:w});return[c,d]}function kv(t,e,i,s,r){let n,o,a=[];const{view:l,settings:h}=i;if("element:asset"===t.type){let r=Lv(t,e,i,s);n=r[0],o=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=ky;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)?Al.Grayscale:Al.None,g=a.resources.texture.get(f);return(null==g?void 0:g.texture)?(h=Ev(g.texture,d*l,p*l),h=Ov(h,m),u=new Um,h.zIndex=1,u.zIndex=5):(a.resources.nodes.set(f,new Set([t])),a.resources.texture.set(f,{textureUrl:c,applyFilter:m}),Mv({loader:a,view:n,resourceId:f}),h=new Um),[h,u]}(t,e,i);n=s[0],o=s[1]}else{if("element:wall"===t.type)a=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=Th({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)a=Hl(t);else if("element:spaceDivider"===t.type)a=Xl(t.edge);else if("spatialGraph:edge"===t.type)a=Xl(t);else if("layout:space"===t.type){const e=t.geometry.polygons;e.length>0&&a.push({type:"curve:polygonWithHoles",polygons:e})}else if("geometries"in t&&t.geometries.length){const{shapes:i,maxY:s}=function(t){let e;"parent"in t&&t.parent&&(e=Bi(t.parent));const i=ul(t,e).sort(((t,e)=>t.boundingBox.max[1]<e.boundingBox.max[1]?-1:1));"element:door"!==t.type&&"element:window"!==t.type||i.pop();let s=i.length?i[i.length-1].boundingBox.max[1]:0,r=[];for(let n of i)for(let t=0;t<n.outlines.length;t++)r.push({type:"curve:polygonWithHoles",polygons:[n.outlines[t],...n.holes[t]||[]]});return{shapes:r,maxY:s}}(t);a=i,e.zIndex=e.zIndex+s}let i=Bl(t);a.push(...i),n=new Um;const r=Th({element:t,settings:h,style:s});for(const t of a)Av({shape:t,settings:h,gfx:n,style:r})}!r&&n&&(l.gfxNodes[t.id]=e,n.eventMode="static",n._nodeId=t.id),n&&e.addChild(n),o&&e.addChild(o)}const Fv={};function Dv(t,e,{ctx:i,style:s,container:r,preview:n}){var o;const{view:a,settings:l}=e;if(!(null==t?void 0:t.spaceGraph))return;let h;n||(s?Fv[t.id]=s:!1===s?delete Fv[t.id]:s=Fv[t.id]),r?(h=r,wv(h)):h=new hm;const u=l.hideElements.includes(t.type)||"spatialGraph:edge"===t.type&&!l.showSpaceDividers||"spatialGraph:edge"===t.type&&"element:spaceDivider"===(null==(o=t.element)?void 0:o.type)||"element:spaceDivider"===t.type&&!l.showSpaceDividers||"annotation:floorPlanImage"===t.type&&!l.showFloorPlan||"space"in t||("element:window"===t.type||"element:door"===t.type)&&!t.parent,c=bh(t.type);if(h.zIndex=c||0,u||kv(t,h,e,s,n),t&&"elements"in t)for(const d of t.elements)Dv(d,e,{ctx:h,style:s,preview:n});r||i.addChild(h),a.viewportNeedsUpdate=!0}function Bv(t,e){const i=e.getChildByName(t);null==i||i.destroy(!0)}function Uv(t,e,i,s){var r;if(Bv(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 zm({fontFamily:s.theme.fontFamily||pl.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=zn(d),f=function(t,e){var i,s;let r=t.getArea(),n=t.attributes.usage;if("void"===xh(n))return[];let{showUsage:o,showArea:a,roomStampDisplay:l}=(null==(i=e.theme.elements)?void 0:i.roomStamp)||{};const h=e.spaceLabelMapping||{};let u,c;void 0!==h[n]&&(u=h[n]),void 0!==h[t.id]&&(u=h[t.id]),c="area"===e.units.roomDimensions?m(r,e.units.system,e.units.areaDecimals):"";let d="";if(d||"undefined"===n||(d=(n||"").replace(/([A-Z])/g,(t=>` ${t}`)).replace(/^./,(t=>t.toUpperCase())).trim()),void 0!==u&&("string"!=typeof u?yl.warn("space label mapping has to be a string"):u.length>50?yl.warn("space label mapping has to be less than 50 characters"):d=u),!l){const i=void 0!==o||void 0!==a;l=[],!1!==(null==(s=e.theme.elements)?void 0:s.roomStamp)&&(t.layout.debugIds?l.push("id"):i?(o&&l.push("usage"),a&&l.push("area")):l.push("usage","area"))}const p=[];return l.forEach((e=>{switch(e){case"id":let e=Gl(t.id)?t.id.substring(0,4):t.id;p.push(e);break;case"name":t.name&&p.push(t.name);break;case"customId":t.customId&&p.push(t.customId);break;case"usage":p.push(d);break;case"area":p.push(c)}})),p}(t,s),g=f.join("\n");const y=new Zm(g,c);y.x=p[0]*ky,y.y=p[1]*ky,y.anchor.x=.5,y.anchor.y=.5,Gv(y,i,t),y.name=t.id,y.eventMode="none",e.addChild(y)}function Gv(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 Xv(t="linear"){return tg[t]}function Hv({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*=ky,h*=ky,u*=ky,c*=ky;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:Xv("easeInOutQuad"),updateViewport:Yv.bind(i)},i.ticker.add("animateView",Wv,i)}else s.fit(!1,p.width,p.height).moveCenter(p.x,p.y),Yv.bind(i)({type:"animation"}),i.viewportNeedsUpdate=!0,r(!0)}))}function Wv(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 Yv(t){this.viewportNeedsUpdate=!0,this.viewportPaused&&this.startAnimationLoop();const e=this._viewport;"animation"!==t.type&&this._zoomTarget&&this._zoomTarget.destroy();const i=ky,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 $v({position:t,nodeId:e}){zv(this.interaction,{cursor:t,cursorTarget:e&&this.layout&&(this.layout.elementsById[e]||this.layout.spacesById[e])})}function zv(t,e){for(const i in e)t[i]=e[i],"cursorAction"===i&&Vv(e[i])}function Vv(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 jv(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]);zv(this.interaction,{cursor:[m[0],m[1]]});let g={sourceEvent:t,nodeId:d,position:m,isDoubleClick:!!h};this.emit(c,g)}function qv(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 Jv(t){t.drag().pinch({percent:4}).wheel()}function Zv(t){const{settings:e,view:i}=t;e.panZoom&&Jv(i._viewport),i._viewport.on("pointerdown",Kv,t).on("pointerup",Qv,t).on("pointerup",jv,t).on("rightup",qv,t).on("pointerupoutside",Qv,t).on("pointermove",tx,t).on("moved",Yv,i).on("zoomed",Yv,i),ex(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",$v,t)}function Kv(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 Qv(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 tx(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/ky,s.y/ky];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 ex=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 ix({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 bv(a).toNumber();const l=s.gfxLayers.scene;wv(l);let h={ctx:l};e&&(h.style=!1);for(let u of i.spaces)Dv(u,t,h);for(let u of i.elements)Dv(u,t,h);for(let u of i.annotations)Dv(u,t,h);for(let u of i.spatialGraph.edges)Dv(u,t,h);sx(t,!0),s.emit("scene-rendered",{update:e}),s.viewportNeedsUpdate=!0,e&&(r.panZoom?Jv(o):function(t){t.plugins.remove("wheel"),t.plugins.remove("pinch"),t.plugins.remove("drag")}(o)),s.viewportPaused&&s.startAnimationLoop()}function sx(t,e=!1){const{view:i,layout:s,settings:r}=t,n=t.addLayer({id:"fpe-room-stamp",baseLayer:"annotation"});e?(wv(n.container),s.spaces.forEach((t=>Uv(t,n.container,i.zoom,r)))):n.container.children.forEach((t=>{let e=s.spaces.find((e=>e.id===t.name));Gv(t,i.zoom,e)}))}function rx(t){const{shapeLayers:e}=t.settings;for(const i in e){const s=e[i];t.addLayer({id:i}).addGraphic({shapes:s})}}id.add(Ep),id.add(yg),id.add(Og),id.add(jg),id.add(Jg);class nx extends Ly{}const ox=(t,e,i)=>{const s=t.getChildByName(e);if(s)return wv(s),s;{const s=new hm;return s.sortableChildren=!0,s.zIndex=i,s.name=e,t.addChild(s),s}},ax={top:0,left:0,center:.5,right:1,bottom:1};class lx{constructor(){this.methods={},this.add=(t,e,i)=>{this.methods[t]={fn:e,ctx:i}},this.remove=t=>{delete this.methods[t]}}}class hx extends By{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.viewportNeedsUpdate=!1,this.viewportPaused=!1,this.viewportInFocus=!1,this.wallNodesToUpdate=[],this.wallNodeUpdateInProgress=!1,this.gfxNodes={},this._canvasMargin={x:0,y:0},this.ticker=new lx,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 Xf)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 bv(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 bv(l).toNumber()),this._stage=new hm,this._stage.sortableChildren=!0,this._viewport=new nx({screenWidth:n,screenHeight:o,worldWidth:n,worldHeight:o,events:this._renderer.events,noTicker:!0,passiveWheel:!1}),(null==(s=Uf)?void 0:s.system)&&Uf.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=ux(this._viewport),Cv(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=ky,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=>ax[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.gfxNodes={},this.gfxLayers=ux(this._viewport)}pause(t="drag"){this._viewport.plugins.pause(t)}resume(t="drag"){this._viewport.plugins.resume(t)}}const ux=t=>{t.sortableChildren=!0;return{base:ox(t,"base",0),scene:ox(t,"scene",1),preview:ox(t,"preview",2),annotation:ox(t,"annotation",3),helper:ox(t,"helper",4)}};function cx(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&&Uv(t,e.container,s.zoom,r)}Dv(t,e,{ctx:n.parent,container:n,...i}),s.viewportNeedsUpdate=!0,s.viewportPaused&&s.startAnimationLoop()}}class dx{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&&wv(this.container);let p=new Um;this.gfx=p,p.alpha=i;const f=Math.min(1/this.floorPlan.view.zoom)*this.gfxScale;e&&(p.x=e[0]*ky,p.y=e[1]*ky),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=>Av({shape:t,settings:this.floorPlan.settings,gfx:p}))),this.floorPlan.view.viewportNeedsUpdate=!0,this.floorPlan.view.viewportPaused&&this.floorPlan.view.startAnimationLoop()}set({position:t,style:e,shapes:i}={}){const s=Math.min(1/this.floorPlan.view.zoom)*this.gfxScale,r=this.gfx;if(t&&(r.x=t[0]*ky,r.y=t[1]*ky),i&&(this.shapes=i,r.clear(),wv(r),i.forEach((t=>Av({shape:t,settings:this.floorPlan.settings,gfx:r})))),s&&this.scaleOnZoom&&(r.scale.x=r.scale.y=s),e){const t=Iv(e);e.fill&&(r.geometry.graphicsData[0].fillStyle.color=wh(e.fill)),r.geometry.graphicsData[0].lineStyle.color=Number(t.color),r.geometry.graphicsData[0].lineStyle.width=t.width,r.geometry.graphicsData[0].lineStyle.native=t.native,r.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 px{constructor(t,e,i){this.graphics=new Set,this.container=new hm,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 dx({...t,floorPlan:this.floorPlan,baseLayer:this.baseLayer,container:this.container});return this.graphics.add(e),e}deleteGraphic(t){this.graphics.delete(t),t.destroy()}clear(){wv(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 fx(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 mx=dl.blue_ribbon,gx=dl.zurich,yx=dl.white,vx=mx,xx=mx,bx=gx,_x=mx,wx=mx,Ex=yx;class Px extends Uy{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=Nh(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:_x,fillOpacity:.1}},{type:"curve:circle",position:[0,0],radius:.05,style:{stroke:wx,fill:Ex,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&&Nh(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+=pe(t[e],t[s])}return i}(i,t.isClosed),t.lengthDisplay=this.getLengthText(t.length);const s=i.length<2?0:180*we(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?zn([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(J(i)),t.areaDisplay=this.getAreaText(t.area);const o=this.isInAreaMode||t.isClosed?"curve:polygon":"curve:polyline",a={stroke:bx,dash:!0,strokeWidth:"native"};let l=t.lengthDisplay,h=s;this.isInAreaMode&&(a.fill=xx,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:vx}}],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 Tx extends Uy{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.layer||(this.layer=this.floorPlan.addLayer({id:"fpe-snap-cursor"})),this.cursor){let t=dl.stone;this.isError?t=dl.error:this.isSnapping&&(t=dl.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:dl.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(){this.floorPlan.off("mousemove",this.draw),this.layer&&this.layer.destroy(),this.layer=void 0,this.cursor=null,super.destroy()}}function Ix(t,e){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: node ID change, type ${t.type}, previous ID ${e}`),this.drawNodeUpdate(t.id))}function Ax(t,e){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: node property change, type ${t.type}, property name ${e}`),this.drawNodeUpdate(t.id))}function Sx(t){this.preventUpdateOnSpaceGraphEvent||yl.debug(`${t.id}: vertex create`)}function Cx(t){this.preventUpdateOnSpaceGraphEvent||yl.debug(`${t.id}: vertex delete`)}function Mx(t){if(!this.preventUpdateOnSpaceGraphEvent){yl.debug(`${t.id}: vertex set position`);for(let e of t.edges)this.drawNodeUpdate(e.id)}}function Nx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: edge create`),this.drawNodeUpdate(t.id))}function Ox(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: edge delete`),this.drawNodeUpdate(t.id))}function Rx(t,e){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: edge set vertices`),this.drawNodeUpdate(t.id))}function Lx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: space create`),this.drawNodeUpdate(t.id))}function kx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: space delete`),this.drawNodeUpdate(t.id))}function Fx(t,e){this.preventUpdateOnSpaceGraphEvent||yl.debug(`${t.id}: space split into ${e[0].id} and ${e[1].id}`)}function Dx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: space attributes change`),this.drawNodeUpdate(t.id))}function Bx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: element create, type ${t.type}`),this.drawNodeUpdate(t.id))}function Ux(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: element delete, type ${t.type}`),this.drawNodeUpdate(t.id))}function Gx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: element transform change, type ${t.type}`),this.drawNodeUpdate(t.id))}function Xx(t){if(!this.preventUpdateOnSpaceGraphEvent)if(yl.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);Sn(this.layout);for(const e of t)this.drawNodeUpdate(e);this.view.wallNodeUpdateInProgress=!1,this.view.wallNodesToUpdate=[]}))}else ss(t),this.drawNodeUpdate(t.id)}function Hx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: annotation change, type ${t.type}`),this.drawNodeUpdate(t.id))}function Wx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: geometry profile update`),this.drawNodeUpdate(t.id))}function Yx(t){this.preventUpdateOnSpaceGraphEvent||(yl.debug(`${t.id}: geometry update`),["element:boundaryWall","element:generic"].includes(t.type)&&this.drawNodeUpdate(t.id))}function $x(t){const e=t.addLayer({id:"fpe-grid-lines",baseLayer:"base"});let i;function s(t,e,s=!1){const r=ky;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(wv(t),!e.settings.theme.background.showGrid)return;const o=new Um;let a=wh(dl.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)}}const zx={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};t.FloorPlanEngine=class extends Dl{constructor({container:t,options:e={}}={}){let i;super({options:e}),this.interaction=zx,this.availableHelpers={cursorCoordinates:Gy,scaleBar:Xy},this.helper={},this.preventUpdateOnSpaceGraphEvent=!1,i=t instanceof Element?t:document.body,this.mountFloorPlan(i),this.availableHelpers.polygonHelper=Px,this.availableHelpers.snapCursor=Tx}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&&(ix({floorPlan:this,update:!0}),rx(this),$x(this))}drawNodePreview(t,e,i,s){Dv((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,a,l;if(!this.layout)return;let h=(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(h)if(this.view.gfxNodes[t])cx(h,this,{style:e}),"element"in h&&"element:spaceDivider"===(null==(o=h.element)?void 0:o.type)&&cx(h.element,this,{style:e});else{let t=this.view.gfxLayers.scene;"parent"in h&&this.view.gfxNodes[null==(a=h.parent)?void 0:a.id]&&(t=this.view.gfxNodes[h.parent.id]),Dv(h,this,{ctx:t,style:e}),"edge"in h&&cx(h.edge,this,{style:e}),"element"in h&&"element:spaceDivider"===(null==(l=h.element)?void 0:l.type)&&cx(h.element,this,{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 Fv[t],Bv(t,e.getLayer("fpe-room-stamp").container),e.view.viewportNeedsUpdate=!0,e.view.viewportPaused&&e.view.startAnimationLoop()}(t,this)}drawResourceUpdate({resourceId:t}){let e=this.loader.resources.nodes.get(t);for(let i of e)cx(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.classList.add("fpe__canvas"),i.appendChild(s),s.appendChild(r),this.fpeNode=i,this.view=new hx(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())),Zv(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()}))})),sx(this),$x(this)})),this.view&&$x(this),this.generateUi()}initDrawing(){this.loader.initialLoading||wv(this.view.gfxLayers.scene),ix({floorPlan:this}),rx(this),this.initDrawingEvents()}initDrawingEvents(){this.spaceGraph.on("node-id-change",Ix,this),this.spaceGraph.on("node-property-change",Ax,this),this.spaceGraph.on("vertex-create",Sx,this),this.spaceGraph.on("vertex-delete",Cx,this),this.spaceGraph.on("vertex-set-position",Mx,this),this.spaceGraph.on("edge-create",Nx,this),this.spaceGraph.on("edge-delete",Ox,this),this.spaceGraph.on("edge-set-vertices",Rx,this),this.spaceGraph.on("space-create",Lx,this),this.spaceGraph.on("space-delete",kx,this),this.spaceGraph.on("space-split",Fx,this),this.spaceGraph.on("space-attributes-change",Dx,this),this.spaceGraph.on("element-create",Bx,this),this.spaceGraph.on("element-delete",Ux,this),this.spaceGraph.on("element-transform-change",Gx,this),this.spaceGraph.on("element-parameters-change",Xx,this),this.spaceGraph.on("geometry-profile-update",Wx,this),this.spaceGraph.on("geometry-update",Yx,this),this.spaceGraph.on("annotation-transform-change",Hx,this),this.spaceGraph.on("annotation-parameters-change",Hx,this)}freeDrawingEvents(){this.spaceGraph.off("node-id-change",Ix),this.spaceGraph.off("node-property-change",Ax),this.spaceGraph.off("vertex-create",Sx),this.spaceGraph.off("vertex-delete",Cx),this.spaceGraph.off("vertex-set-position",Mx),this.spaceGraph.off("edge-create",Nx),this.spaceGraph.off("edge-delete",Ox),this.spaceGraph.off("edge-set-vertices",Rx),this.spaceGraph.off("space-create",Lx),this.spaceGraph.off("space-delete",kx),this.spaceGraph.off("space-split",Fx),this.spaceGraph.off("space-attributes-change",Dx),this.spaceGraph.off("element-create",Bx),this.spaceGraph.off("element-delete",Ux),this.spaceGraph.off("element-transform-change",Gx),this.spaceGraph.off("element-parameters-change",Xx),this.spaceGraph.off("geometry-profile-update",Wx),this.spaceGraph.off("geometry-update",Yx),this.spaceGraph.off("annotation-transform-change",Hx),this.spaceGraph.off("annotation-parameters-change",Hx)}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")}getBoundingBox(t=0){var e;if(!(null==(e=this.view)?void 0:e._viewport))return;let i=this.view.gfxLayers.scene;if(!i)return;let{x:s,y:r,width:n,height:o}=i.getLocalBounds(),a=s/ky-t,l=r/ky-t;return{min:[a,l],max:[a+(n/ky+2*t),l+(o/ky+2*t)]}}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}){if(!i.view.gfxLayers.scene)return Promise.resolve(!1);if(s)return Hv({bb:s,animate:e,view:i.view});let{min:r,max:n}=i.getBoundingBox(),o=r[0],a=r[1],l=n[0]-o,h=n[1]-a;return o-=t,a-=t,l+=2*t,h+=2*t,Hv({bb:{min:[o,a],max:[o+l,a+h]},animate:e,view:i.view})}({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 r=Rl(s);if(!r||0===r.objectAlignedBoundingBox.length)return Promise.resolve(!0);const{min:n,max:o}=z([r.objectAlignedBoundingBox]);return Hv({bb:{min:[n[0]-e,n[1]-e],max:[o[0]+e,o[1]+e]},animate:i,view:this.view})}setZoom(t,e=!0){return Hv({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 Yy({...t,floorPlan:this})}addHtmlMarker(t={}){return new $y({...t,floorPlan:this})}addMarker({position:t=[0,0],color:e="#669cff",size:i=40}={}){return new _v({position:t,color:e,size:i,floorPlan:this})}getPlanPosition(t){const e=this.view._viewport.toWorld(t[0],t[1]);return[e.x/ky,e.y/ky]}getScreenPosition(t){const e=t.map((t=>t*ky)),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=R()),this.view.layers.has(t)){const e=this.view.layers.get(t);if(null==e?void 0:e.container)return e}const s=new px(this,e,t);return this.view.layers.set(t,s),s}getLayer(t){return this.view.layers.get(t)}addPlanGraphic(){return new px(this)}addHelper(t,e={}){let i=null==e?void 0:e.helperId;return i||(i="string"==typeof t?t:R()),this.helper[i]&&this.removeHelper(i),"string"==typeof t?this.availableHelpers[t]?this.helper[i]=new this.availableHelpers[t]({floorPlan:this,helperId:i,...e}):yl.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;fx(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&&(ml=t),"string"==typeof i&&(fl=i),"string"==typeof e&&(F=e)},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));