@hatiolab/things-scene 10.0.0-beta.77 → 10.0.0-beta.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/things-scene.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import t from"dompurify";import*as e from"three";import{Scene as n,BoxGeometry as i,MeshStandardMaterial as r,BackSide as s,Mesh as o,PointLight as a,MeshLambertMaterial as c,MathUtils as l,Color as h,LinearSRGBColorSpace as d,SRGBColorSpace as u}from"three";import{Line2 as p}from"three/examples/jsm/lines/Line2.js";import{LineMaterial as f}from"three/examples/jsm/lines/LineMaterial.js";import{LineGeometry as g}from"three/examples/jsm/lines/LineGeometry.js";import{CSS3DObject as m,CSS3DRenderer as y}from"three/examples/jsm/renderers/CSS3DRenderer.js";import b from"tinycolor2";import{Sky as v}from"three/examples/jsm/objects/Sky.js";import{EffectComposer as _}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as x}from"three/examples/jsm/postprocessing/RenderPass.js";import{OutlinePass as w}from"three/examples/jsm/postprocessing/OutlinePass.js";import{OutputPass as M}from"three/examples/jsm/postprocessing/OutputPass.js";import{SMAAPass as S}from"three/examples/jsm/postprocessing/SMAAPass.js";import{TransformControls as k}from"three/examples/jsm/controls/TransformControls.js";import{GLTFLoader as A}from"three/examples/jsm/loaders/GLTFLoader.js";import{DRACOLoader as E}from"three/examples/jsm/loaders/DRACOLoader.js";import{KTX2Loader as C}from"three/examples/jsm/loaders/KTX2Loader.js";import{MeshoptDecoder as T}from"three/examples/jsm/libs/meshopt_decoder.module.js";import{clone as P}from"three/examples/jsm/utils/SkeletonUtils.js";import{render as D,nothing as O,html as z}from"lit";import{RoundedBoxGeometry as I}from"three/examples/jsm/geometries/RoundedBoxGeometry.js";function L(t,e){return t===e||t!=t&&e!=e}function j(t,e){for(var n=t.length;n--;)if(L(t[n][0],e))return n;return-1}var R=Array.prototype.splice;function F(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}F.prototype.clear=function(){this.__data__=[],this.size=0},F.prototype.delete=function(t){var e=this.__data__,n=j(e,t);return!(n<0)&&(n==e.length-1?e.pop():R.call(e,n,1),--this.size,!0)},F.prototype.get=function(t){var e=this.__data__,n=j(e,t);return n<0?void 0:e[n][1]},F.prototype.has=function(t){return j(this.__data__,t)>-1},F.prototype.set=function(t,e){var n=this.__data__,i=j(n,t);return i<0?(++this.size,n.push([t,e])):n[i][1]=e,this};var B="object"==typeof global&&global&&global.Object===Object&&global,N="object"==typeof self&&self&&self.Object===Object&&self,H=B||N||Function("return this")(),Y=H.Symbol,V=Object.prototype,G=V.hasOwnProperty,U=V.toString,W=Y?Y.toStringTag:void 0;var X=Object.prototype.toString;var q=Y?Y.toStringTag:void 0;function K(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":q&&q in Object(t)?function(t){var e=G.call(t,W),n=t[W];try{t[W]=void 0;var i=!0}catch(t){}var r=U.call(t);return i&&(e?t[W]=n:delete t[W]),r}(t):function(t){return X.call(t)}(t)}function $(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Q(t){if(!$(t))return!1;var e=K(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var Z,J=H["__core-js_shared__"],tt=(Z=/[^.]+$/.exec(J&&J.keys&&J.keys.IE_PROTO||""))?"Symbol(src)_1."+Z:"";var et=Function.prototype.toString;function nt(t){if(null!=t){try{return et.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var it=/^\[object .+?Constructor\]$/,rt=Function.prototype,st=Object.prototype,ot=rt.toString,at=st.hasOwnProperty,ct=RegExp("^"+ot.call(at).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function lt(t){return!(!$(t)||(e=t,tt&&tt in e))&&(Q(t)?ct:it).test(nt(t));var e}function ht(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return lt(n)?n:void 0}var dt=ht(H,"Map"),ut=ht(Object,"create");var pt=Object.prototype.hasOwnProperty;var ft=Object.prototype.hasOwnProperty;function gt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function mt(t,e){var n=t.__data__;return function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}(e)?n["string"==typeof e?"string":"hash"]:n.map}function yt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}gt.prototype.clear=function(){this.__data__=ut?ut(null):{},this.size=0},gt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},gt.prototype.get=function(t){var e=this.__data__;if(ut){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return pt.call(e,t)?e[t]:void 0},gt.prototype.has=function(t){var e=this.__data__;return ut?void 0!==e[t]:ft.call(e,t)},gt.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=ut&&void 0===e?"__lodash_hash_undefined__":e,this},yt.prototype.clear=function(){this.size=0,this.__data__={hash:new gt,map:new(dt||F),string:new gt}},yt.prototype.delete=function(t){var e=mt(this,t).delete(t);return this.size-=e?1:0,e},yt.prototype.get=function(t){return mt(this,t).get(t)},yt.prototype.has=function(t){return mt(this,t).has(t)},yt.prototype.set=function(t,e){var n=mt(this,t),i=n.size;return n.set(t,e),this.size+=n.size==i?0:1,this};function bt(t){var e=this.__data__=new F(t);this.size=e.size}bt.prototype.clear=function(){this.__data__=new F,this.size=0},bt.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},bt.prototype.get=function(t){return this.__data__.get(t)},bt.prototype.has=function(t){return this.__data__.has(t)},bt.prototype.set=function(t,e){var n=this.__data__;if(n instanceof F){var i=n.__data__;if(!dt||i.length<199)return i.push([t,e]),this.size=++n.size,this;n=this.__data__=new yt(i)}return n.set(t,e),this.size=n.size,this};function vt(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new yt;++e<n;)this.add(t[e])}function _t(t,e){for(var n=-1,i=null==t?0:t.length;++n<i;)if(e(t[n],n,t))return!0;return!1}vt.prototype.add=vt.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vt.prototype.has=function(t){return this.__data__.has(t)};function xt(t,e,n,i,r,s){var o=1&n,a=t.length,c=e.length;if(a!=c&&!(o&&c>a))return!1;var l=s.get(t),h=s.get(e);if(l&&h)return l==e&&h==t;var d=-1,u=!0,p=2&n?new vt:void 0;for(s.set(t,e),s.set(e,t);++d<a;){var f=t[d],g=e[d];if(i)var m=o?i(g,f,d,e,t,s):i(f,g,d,t,e,s);if(void 0!==m){if(m)continue;u=!1;break}if(p){if(!_t(e,function(t,e){if(o=e,!p.has(o)&&(f===t||r(f,t,n,i,s)))return p.push(e);var o})){u=!1;break}}else if(f!==g&&!r(f,g,n,i,s)){u=!1;break}}return s.delete(t),s.delete(e),u}var wt=H.Uint8Array;function Mt(t){var e=-1,n=Array(t.size);return t.forEach(function(t,i){n[++e]=[i,t]}),n}function St(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var kt=Y?Y.prototype:void 0,At=kt?kt.valueOf:void 0;function Et(t,e){for(var n=-1,i=e.length,r=t.length;++n<i;)t[r+n]=e[n];return t}var Ct=Array.isArray;function Tt(){return[]}var Pt=Object.prototype.propertyIsEnumerable,Dt=Object.getOwnPropertySymbols,Ot=Dt?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var n=-1,i=null==t?0:t.length,r=0,s=[];++n<i;){var o=t[n];e(o,n,t)&&(s[r++]=o)}return s}(Dt(t),function(e){return Pt.call(t,e)}))}:Tt;function zt(t){return null!=t&&"object"==typeof t}function It(t){return zt(t)&&"[object Arguments]"==K(t)}var Lt=Object.prototype,jt=Lt.hasOwnProperty,Rt=Lt.propertyIsEnumerable,Ft=It(function(){return arguments}())?It:function(t){return zt(t)&&jt.call(t,"callee")&&!Rt.call(t,"callee")};var Bt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Nt=Bt&&"object"==typeof module&&module&&!module.nodeType&&module,Ht=Nt&&Nt.exports===Bt?H.Buffer:void 0,Yt=(Ht?Ht.isBuffer:void 0)||function(){return!1},Vt=/^(?:0|[1-9]\d*)$/;function Gt(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&Vt.test(t))&&t>-1&&t%1==0&&t<e}function Ut(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var Wt={};function Xt(t){return function(e){return t(e)}}Wt["[object Float32Array]"]=Wt["[object Float64Array]"]=Wt["[object Int8Array]"]=Wt["[object Int16Array]"]=Wt["[object Int32Array]"]=Wt["[object Uint8Array]"]=Wt["[object Uint8ClampedArray]"]=Wt["[object Uint16Array]"]=Wt["[object Uint32Array]"]=!0,Wt["[object Arguments]"]=Wt["[object Array]"]=Wt["[object ArrayBuffer]"]=Wt["[object Boolean]"]=Wt["[object DataView]"]=Wt["[object Date]"]=Wt["[object Error]"]=Wt["[object Function]"]=Wt["[object Map]"]=Wt["[object Number]"]=Wt["[object Object]"]=Wt["[object RegExp]"]=Wt["[object Set]"]=Wt["[object String]"]=Wt["[object WeakMap]"]=!1;var qt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Kt=qt&&"object"==typeof module&&module&&!module.nodeType&&module,$t=Kt&&Kt.exports===qt&&B.process,Qt=function(){try{var t=Kt&&Kt.require&&Kt.require("util").types;return t||$t&&$t.binding&&$t.binding("util")}catch(t){}}(),Zt=Qt&&Qt.isTypedArray,Jt=Zt?Xt(Zt):function(t){return zt(t)&&Ut(t.length)&&!!Wt[K(t)]},te=Object.prototype.hasOwnProperty;function ee(t,e){var n=Ct(t),i=!n&&Ft(t),r=!n&&!i&&Yt(t),s=!n&&!i&&!r&&Jt(t),o=n||i||r||s,a=o?function(t,e){for(var n=-1,i=Array(t);++n<t;)i[n]=e(n);return i}(t.length,String):[],c=a.length;for(var l in t)!e&&!te.call(t,l)||o&&("length"==l||r&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Gt(l,c))||a.push(l);return a}var ne=Object.prototype;function ie(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ne)}function re(t,e){return function(n){return t(e(n))}}var se=re(Object.keys,Object),oe=Object.prototype.hasOwnProperty;function ae(t){if(!ie(t))return se(t);var e=[];for(var n in Object(t))oe.call(t,n)&&"constructor"!=n&&e.push(n);return e}function ce(t){return null!=t&&Ut(t.length)&&!Q(t)}function le(t){return ce(t)?ee(t):ae(t)}function he(t){return function(t,e,n){var i=e(t);return Ct(t)?i:Et(i,n(t))}(t,le,Ot)}var de=Object.prototype.hasOwnProperty;var ue=ht(H,"DataView"),pe=ht(H,"Promise"),fe=ht(H,"Set"),ge=ht(H,"WeakMap"),me="[object Map]",ye="[object Promise]",be="[object Set]",ve="[object WeakMap]",_e="[object DataView]",xe=nt(ue),we=nt(dt),Me=nt(pe),Se=nt(fe),ke=nt(ge),Ae=K;(ue&&Ae(new ue(new ArrayBuffer(1)))!=_e||dt&&Ae(new dt)!=me||pe&&Ae(pe.resolve())!=ye||fe&&Ae(new fe)!=be||ge&&Ae(new ge)!=ve)&&(Ae=function(t){var e=K(t),n="[object Object]"==e?t.constructor:void 0,i=n?nt(n):"";if(i)switch(i){case xe:return _e;case we:return me;case Me:return ye;case Se:return be;case ke:return ve}return e});var Ee="[object Arguments]",Ce="[object Array]",Te="[object Object]",Pe=Object.prototype.hasOwnProperty;function De(t,e,n,i,r,s){var o=Ct(t),a=Ct(e),c=o?Ce:Ae(t),l=a?Ce:Ae(e),h=(c=c==Ee?Te:c)==Te,d=(l=l==Ee?Te:l)==Te,u=c==l;if(u&&Yt(t)){if(!Yt(e))return!1;o=!0,h=!1}if(u&&!h)return s||(s=new bt),o||Jt(t)?xt(t,e,n,i,r,s):function(t,e,n,i,r,s,o){switch(n){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!s(new wt(t),new wt(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return L(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var a=Mt;case"[object Set]":var c=1&i;if(a||(a=St),t.size!=e.size&&!c)return!1;var l=o.get(t);if(l)return l==e;i|=2,o.set(t,e);var h=xt(a(t),a(e),i,r,s,o);return o.delete(t),h;case"[object Symbol]":if(At)return At.call(t)==At.call(e)}return!1}(t,e,c,n,i,r,s);if(!(1&n)){var p=h&&Pe.call(t,"__wrapped__"),f=d&&Pe.call(e,"__wrapped__");if(p||f){var g=p?t.value():t,m=f?e.value():e;return s||(s=new bt),r(g,m,n,i,s)}}return!!u&&(s||(s=new bt),function(t,e,n,i,r,s){var o=1&n,a=he(t),c=a.length;if(c!=he(e).length&&!o)return!1;for(var l=c;l--;){var h=a[l];if(!(o?h in e:de.call(e,h)))return!1}var d=s.get(t),u=s.get(e);if(d&&u)return d==e&&u==t;var p=!0;s.set(t,e),s.set(e,t);for(var f=o;++l<c;){var g=t[h=a[l]],m=e[h];if(i)var y=o?i(m,g,h,e,t,s):i(g,m,h,t,e,s);if(!(void 0===y?g===m||r(g,m,n,i,s):y)){p=!1;break}f||(f="constructor"==h)}if(p&&!f){var b=t.constructor,v=e.constructor;b==v||!("constructor"in t)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof v&&v instanceof v||(p=!1)}return s.delete(t),s.delete(e),p}(t,e,n,i,r,s))}function Oe(t,e,n,i,r){return t===e||(null==t||null==e||!zt(t)&&!zt(e)?t!=t&&e!=e:De(t,e,n,i,Oe,r))}var ze=function(){try{var t=ht(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Ie(t,e,n){"__proto__"==e&&ze?ze(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var Le=Object.prototype.hasOwnProperty;function je(t,e,n){var i=t[e];Le.call(t,e)&&L(i,n)&&(void 0!==n||e in t)||Ie(t,e,n)}function Re(t,e,n,i){var r=!n;n||(n={});for(var s=-1,o=e.length;++s<o;){var a=e[s],c=i?i(n[a],t[a],a,n,t):void 0;void 0===c&&(c=t[a]),r?Ie(n,a,c):je(n,a,c)}return n}function Fe(t){return t}function Be(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}var Ne=Math.max;function He(t){return function(){return t}}var Ye=ze?function(t,e){return ze(t,"toString",{configurable:!0,enumerable:!1,value:He(e),writable:!0})}:Fe,Ve=Date.now;var Ge=function(t){var e=0,n=0;return function(){var i=Ve(),r=16-(i-n);if(n=i,r>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Ye);function Ue(t,e){return Ge(function(t,e,n){return e=Ne(void 0===e?t.length-1:e,0),function(){for(var i=arguments,r=-1,s=Ne(i.length-e,0),o=Array(s);++r<s;)o[r]=i[e+r];r=-1;for(var a=Array(e+1);++r<e;)a[r]=i[r];return a[e]=n(o),Be(t,this,a)}}(t,e,Fe),t+"")}function We(t,e,n){if(!$(n))return!1;var i=typeof e;return!!("number"==i?ce(n)&&Gt(e,n.length):"string"==i&&e in n)&&L(n[e],t)}var Xe=Object.prototype.hasOwnProperty;function qe(t){if(!$(t))return function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}(t);var e=ie(t),n=[];for(var i in t)("constructor"!=i||!e&&Xe.call(t,i))&&n.push(i);return n}function Ke(t){return ce(t)?ee(t,!0):qe(t)}var $e,Qe=($e=function(t,e,n,i){Re(e,Ke(e),t,i)},Ue(function(t,e){var n=-1,i=e.length,r=i>1?e[i-1]:void 0,s=i>2?e[2]:void 0;for(r=$e.length>3&&"function"==typeof r?(i--,r):void 0,s&&We(e[0],e[1],s)&&(r=i<3?void 0:r,i=1),t=Object(t);++n<i;){var o=e[n];o&&$e(t,o,n,r)}return t})),Ze=re(Object.getPrototypeOf,Object),Je=Function.prototype,tn=Object.prototype,en=Je.toString,nn=tn.hasOwnProperty,rn=en.call(Object);function sn(t){if(!zt(t))return!1;var e=K(t);return"[object Error]"==e||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!function(t){if(!zt(t)||"[object Object]"!=K(t))return!1;var e=Ze(t);if(null===e)return!0;var n=nn.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&en.call(n)==rn}(t)}var on=Ue(function(t,e){try{return Be(t,void 0,e)}catch(t){return sn(t)?t:new Error(t)}});function an(t,e){for(var n=-1,i=null==t?0:t.length,r=Array(i);++n<i;)r[n]=e(t[n],n,t);return r}var cn=Object.prototype,ln=cn.hasOwnProperty;function hn(t,e,n,i){return void 0===t||L(t,cn[n])&&!ln.call(i,n)?e:t}var dn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"};function un(t){return"\\"+dn[t]}var pn=/<%=([\s\S]+?)%>/g;var fn,gn=(fn={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},function(t){return null==fn?void 0:fn[t]});function mn(t){return"symbol"==typeof t||zt(t)&&"[object Symbol]"==K(t)}var yn=Y?Y.prototype:void 0,bn=yn?yn.toString:void 0;function vn(t){if("string"==typeof t)return t;if(Ct(t))return an(t,vn)+"";if(mn(t))return bn?bn.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function _n(t){return null==t?"":vn(t)}var xn=/[&<>"']/g,wn=RegExp(xn.source);var Mn={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:pn,variable:"",imports:{_:{escape:function(t){return(t=_n(t))&&wn.test(t)?t.replace(xn,gn):t}}}},Sn=/\b__p \+= '';/g,kn=/\b(__p \+=) '' \+/g,An=/(__e\(.*?\)|\b__t\)) \+\n'';/g,En=/[()=,{}\[\]\/\s]/,Cn=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Tn=/($^)/,Pn=/['\n\r\u2028\u2029\\]/g,Dn=Object.prototype.hasOwnProperty;var On="object"==typeof exports&&exports&&!exports.nodeType&&exports,zn=On&&"object"==typeof module&&module&&!module.nodeType&&module,In=zn&&zn.exports===On?H.Buffer:void 0,Ln=In?In.allocUnsafe:void 0;var jn=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Et(e,Ot(t)),t=Ze(t);return e}:Tt;var Rn=Object.prototype.hasOwnProperty;var Fn=/\w*$/;var Bn=Y?Y.prototype:void 0,Nn=Bn?Bn.valueOf:void 0;function Hn(t,e,n){var i,r,s,o,a,c=t.constructor;switch(e){case"[object ArrayBuffer]":return a=new(o=t).constructor(o.byteLength),new wt(a).set(new wt(o)),a;case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return s=(r=t).buffer,new r.constructor(s,r.byteOffset,r.byteLength);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(t){var e=t.buffer;return new t.constructor(e,t.byteOffset,t.length)}(t);case"[object Map]":case"[object Set]":return new c;case"[object Number]":case"[object String]":return new c(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,Fn.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return i=t,Nn?Object(Nn.call(i)):{}}}var Yn=Object.create,Vn=function(){function t(){}return function(e){if(!$(e))return{};if(Yn)return Yn(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}();var Gn=Qt&&Qt.isMap,Un=Gn?Xt(Gn):function(t){return zt(t)&&"[object Map]"==Ae(t)};var Wn=Qt&&Qt.isSet,Xn=Wn?Xt(Wn):function(t){return zt(t)&&"[object Set]"==Ae(t)},qn="[object Arguments]",Kn="[object Function]",$n="[object Object]",Qn={};function Zn(t,e,n,i,r,s){var o,a=2&e;if(void 0!==o)return o;if(!$(t))return t;var c=Ct(t);if(c)return o=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&Rn.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),function(t,e){var n=-1,i=t.length;for(e||(e=Array(i));++n<i;)e[n]=t[n];return e}(t,o);var l=Ae(t),h=l==Kn||"[object GeneratorFunction]"==l;if(Yt(t))return function(t){var e=t.length,n=Ln?Ln(e):new t.constructor(e);return t.copy(n),n}(t);if(l==$n||l==qn||h&&!r)return o=h?{}:function(t){return"function"!=typeof t.constructor||ie(t)?{}:Vn(Ze(t))}(t),a?function(t,e){return Re(t,jn(t),e)}(t,function(t,e){return t&&Re(e,Ke(e),t)}(o,t)):function(t,e){return Re(t,Ot(t),e)}(t,function(t,e){return t&&Re(e,le(e),t)}(o,t));if(!Qn[l])return r?t:{};o=Hn(t,l),s||(s=new bt);var d=s.get(t);if(d)return d;s.set(t,o),Xn(t)?t.forEach(function(i){o.add(Zn(i,e,n,i,t,s))}):Un(t)&&t.forEach(function(i,r){o.set(r,Zn(i,e,n,r,t,s))});var u=c?void 0:he(t);return function(t,e){for(var n=-1,i=null==t?0:t.length;++n<i&&!1!==e(t[n],n,t););}(u||t,function(i,r){u&&(i=t[r=i]),je(o,r,Zn(i,e,n,r,t,s))}),o}Qn[qn]=Qn["[object Array]"]=Qn["[object ArrayBuffer]"]=Qn["[object DataView]"]=Qn["[object Boolean]"]=Qn["[object Date]"]=Qn["[object Float32Array]"]=Qn["[object Float64Array]"]=Qn["[object Int8Array]"]=Qn["[object Int16Array]"]=Qn["[object Int32Array]"]=Qn["[object Map]"]=Qn["[object Number]"]=Qn[$n]=Qn["[object RegExp]"]=Qn["[object Set]"]=Qn["[object String]"]=Qn["[object Symbol]"]=Qn["[object Uint8Array]"]=Qn["[object Uint8ClampedArray]"]=Qn["[object Uint16Array]"]=Qn["[object Uint32Array]"]=!0,Qn["[object Error]"]=Qn[Kn]=Qn["[object WeakMap]"]=!1;function Jn(t){return Zn(t,4)}var ti=function(){return H.Date.now()},ei=/\s/;var ni=/^\s+/;function ii(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&ei.test(t.charAt(e)););return e}(t)+1).replace(ni,""):t}var ri=/^[-+]0x[0-9a-f]+$/i,si=/^0b[01]+$/i,oi=/^0o[0-7]+$/i,ai=parseInt;function ci(t){if("number"==typeof t)return t;if(mn(t))return NaN;if($(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=$(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=ii(t);var n=si.test(t);return n||oi.test(t)?ai(t.slice(2),n?2:8):ri.test(t)?NaN:+t}var li=Math.max,hi=Math.min;function di(t,e,n){var i,r,s,o,a,c,l=0,h=!1,d=!1,u=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function p(e){var n=i,s=r;return i=r=void 0,l=e,o=t.apply(s,n)}function f(t){var n=t-c;return void 0===c||n>=e||n<0||d&&t-l>=s}function g(){var t=ti();if(f(t))return m(t);a=setTimeout(g,function(t){var n=e-(t-c);return d?hi(n,s-(t-l)):n}(t))}function m(t){return a=void 0,u&&i?p(t):(i=r=void 0,o)}function y(){var t=ti(),n=f(t);if(i=arguments,r=this,c=t,n){if(void 0===a)return function(t){return l=t,a=setTimeout(g,e),h?p(t):o}(c);if(d)return clearTimeout(a),a=setTimeout(g,e),p(c)}return void 0===a&&(a=setTimeout(g,e)),o}return e=ci(e)||0,$(n)&&(h=!!n.leading,s=(d="maxWait"in n)?li(ci(n.maxWait)||0,e):s,u="trailing"in n?!!n.trailing:u),y.cancel=function(){void 0!==a&&clearTimeout(a),l=0,i=c=r=a=void 0},y.flush=function(){return void 0===a?o:m(ti())},y}var ui=1/0;function pi(t){var e=function(t){return t?(t=ci(t))===ui||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}(t),n=e%1;return e==e?n?e-n:e:0}function fi(t){return function(t,e){var n;if("function"!=typeof e)throw new TypeError("Expected a function");return t=pi(t),function(){return--t>0&&(n=e.apply(this,arguments)),t<=1&&(e=void 0),n}}(2,t)}var gi=Object.prototype.hasOwnProperty;function mi(t){if(null==t)return!0;if(ce(t)&&(Ct(t)||"string"==typeof t||"function"==typeof t.splice||Yt(t)||Jt(t)||Ft(t)))return!t.length;var e=Ae(t);if("[object Map]"==e||"[object Set]"==e)return!t.size;if(ie(t))return!ae(t).length;for(var n in t)if(gi.call(t,n))return!1;return!0}let yi=0;function bi(t={},...e){return"object"!=typeof t&&(t={}),e.forEach(e=>{for(const n in e)"object"!=typeof e[n]?t[n]=e[n]:e[n].length>0?t[n]=e[n].map(t=>{let i;return i="object"!=typeof e[n]?t:bi({},t),i}):t[n]=bi(t[n],e[n])}),t}function vi(t){for(;t&&"object"==typeof t;){const e=t;for(const e in t){t=t[e];break}if(t===e){t=void 0;break}}return t}function _i(t,e){if(!this.__collection__)return this;return-1==this.__collection__.indexOf(e)&&this.__collection__.splice(t,0,e),this}function xi(t){return this.__collection__||(this.__collection__=[]),-1==this.__collection__.indexOf(t)&&this.__collection__.push(t),this}function wi(t){return this.__collection__||(this.__collection__=[]),-1==this.__collection__.indexOf(t)&&this.__collection__.unshift(t),this}function Mi(t){if(!this.__collection__)return this;const e=this.__collection__.indexOf(t);return e>=0&&this.__collection__.splice(e,1),this}function Si(t){if(this.__collection__)return this.__collection__[t]}function ki(t,e){this.__collection__&&this.__collection__.forEach(t,e)}function Ai(t){return this.__collection__?this.__collection__.indexOf(t):-1}function Ei(){return this.__collection__?this.__collection__.length:0}function Ci(){this.__collection__=[]}function Ti(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this.__collection__[e]=this.__collection__[e-1],this.__collection__[e-1]=t)}function Pi(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this.__collection__[e]=this.__collection__[e+1],this.__collection__[e+1]=t)}function Di(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this.__collection__.splice(0,e),i=this.__collection__.splice(1);this.__collection__=this.__collection__.concat(n,i)}function Oi(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this.__collection__.splice(0,e),i=this.__collection__.splice(1);this.__collection__=n.concat(i,this.__collection__)}class zi{constructor(){this.__collection__=[],this.insertAt=_i,this.append=xi,this.prepend=wi,this.remove=Mi,this.getAt=Si,this.forEach=ki,this.indexOf=Ai,this.size=Ei,this.clear=Ci,this.moveForward=Ti,this.moveBackward=Pi,this.moveToHead=Di,this.moveToTail=Oi}}const Ii=new class{constructor(){this.drawCount=0,this.drawTimeSum=0,this.drawTimeLast=0,this.invalidateCount=0,this.triggerCount=0,this.cacheHit=0,this.cacheMiss=0,this._lastSnapshotTime=0,this._frameCount=0,this._getResidents=null}registerResidents(t){this._getResidents=t}countFrame(){this._frameCount++}snapshot(){const t=performance.now(),e=this.drawCount,n=this.cacheHit+this.cacheMiss,i=this._getResidents?.()??null;let r=0;if(this._lastSnapshotTime>0){const e=t-this._lastSnapshotTime;e>0&&(r=Math.round(1e3*this._frameCount/e))}this._lastSnapshotTime=t,this._frameCount=0;const s={fps:r,drawCount:e,drawTimeAvg:e>0?Math.round(this.drawTimeSum/e*100)/100:0,drawTimeLast:Math.round(100*this.drawTimeLast)/100,invalidateCount:this.invalidateCount,triggerCount:this.triggerCount,cacheHitRate:n>0?Math.round(this.cacheHit/n*1e3)/10:0,...i??{}};return this.drawCount=0,this.drawTimeSum=0,this.invalidateCount=0,this.triggerCount=0,this.cacheHit=0,this.cacheMiss=0,s}},Li=/\s+/;function ji(t,e,n,i){if(!n)return!0;if("object"==typeof n){for(const i in n){const r=n[i];t[e].apply(t,[i,r])}return!1}if(Li.test(n)){return n.split(Li).forEach(n=>t[e].apply(t,[n].concat(i))),!1}return!0}const Ri=["on","off","once","delegate_on","delegate_off","trigger","listenTo"],Fi={withEvent(){Ri.forEach(t=>this[t]=Fi[t])},on(t,e,n){if(!ji(this,"on",t,[e,n])||!e)return this;this._listeners||(this._listeners={});return(this._listeners[t]||(this._listeners[t]=[])).push({callback:e,context:n,ctx:n||this}),this},once(t,e,n){if(!ji(this,"once",t,[e,n])||!e)return this;const i=this,r=fi(function(){i.off(t,r,n),e.apply(i,arguments)});return r._callback=e,this.on(t,r,n),this},off(t,e,n){if(!this._listeners||!ji(this,"off",t,[e,n]))return this;if(!t&&!e&&!n)return this._listeners=void 0,this;let i;i=t&&"string"==typeof t?[t]:Object.keys(this._listeners||{});for(let t=0;t<i.length;t++){const r=i[t],s=this._listeners?.[r];if(s){const t=[];if(this._listeners[r]=t,e||n)for(let i=0;i<s.length;i++){const r=s[i];(e&&e!==r.callback&&e!==r.callback._callback||n&&n!==r.context)&&t.push(r)}t.length||delete this._listeners[r]}}return this},delegate_on(t){return this._delegators||(this._delegators=new zi),this._delegators.append(t),this},delegate_off(t){return this._delegators?(this._delegators.remove(t),this):this},delegate(){if(this._delegators&&this._delegators.size()>0&&Ni(this._delegators,arguments),!this._listeners)return this;const t=arguments.length-1,e=arguments[t];arguments[t]={origin:e.origin,name:e.name,deliverer:this};const n=this._listeners[e.name],i=this._listeners["(all)"];return n&&Bi(n,arguments),i&&Bi(i,arguments),this},trigger(t){Ii.triggerCount++;const e=[].slice.call(arguments,1);if(e.push({origin:this,name:t,deliverer:this}),this._delegators&&this._delegators.size()>0&&Ni(this._delegators,e),!this._listeners)return this;if(!ji(this,"trigger",t,e))return this;const n=this._listeners[t],i=this._listeners["(all)"];return n&&Bi(n,e),i&&Bi(i,e),this},stopListening(t,e,n){let i=this._listeningTo;if(!i)return this;const r=!e&&!n;n||"object"!=typeof e||(n=this),t&&(i={},i[t._listenId]=t);for(const t in i){const s=i[t];s.off(e,n,this),(r||mi(s._events))&&delete this._listeningTo[t]}return this}};function Bi(t,e){t.forEach(t=>t.callback.apply(t.ctx,e))}function Ni(t,e){t.forEach(t=>Fi.delegate.apply(t,e))}const Hi={listenTo:"on",listenToOnce:"once"};for(const t in Hi){const e=Hi[t];Fi[t]=function(t,n,i){this._listeningTo||(this._listeningTo={});const r=this._listeningTo;t._listenId||(t._listenId=`${"l"}${++yi}`);return r[t._listenId]=t,i||"object"!=typeof n||(i=this),t[e](n,i,this),this}}const Yi=Fi.on,Vi=Fi.off,Gi=Fi.once,Ui=Fi.trigger,Wi=Fi.delegate_on,Xi=Fi.delegate_off;function qi(t,e){if(e instanceof Array)e.forEach(e=>qi(t,e));else{if(t.mixedIn=t.hasOwnProperty("mixedIn")?t.mixedIn:[],t.mixingIn=t.hasOwnProperty("mixingIn")?t.mixingIn:[],t.mixedIn.indexOf(e)>=0)return t;if(t.mixingIn.indexOf(e)>=0)throw new Error(`found cyclic dependencies between ${t.mixingIn}`);t.mixingIn.push(e),e.call(t),t.mixingIn.pop(),t.mixedIn.push(e)}return t}const Ki=(...t)=>{const e=[];t.forEach(t=>t&&t.stack&&e.push(t.stack)),console.error("[ERROR]",...t,e.join(" "))},$i=(...t)=>{const e=[];t.forEach(t=>t&&t.stack&&e.push(t.stack)),console.warn("[WARN]",...t,e.join(" "))},Qi=(...t)=>console.log("[DEBUG]",...t);function Zi(t,e,n){const i=function(t,e){let n=t;for(;n;){const t=Object.getOwnPropertyDescriptor(n,e);if(t?.get)return t;n=Object.getPrototypeOf(n)}}(t,e);if(!i?.get)return void Ki(`${String(e)} is not defined in ${t.constructor.name}`);const r=i.get,s={get:n?function(){return e in this.__cache__?Ii.cacheHit++:(Ii.cacheMiss++,this.__cache__[e]=Object.freeze(r.call(this))),this.__cache__[e]}:function(){return e in this.__cache__?Ii.cacheHit++:(Ii.cacheMiss++,this.__cache__[e]=r.call(this)),this.__cache__[e]},configurable:!0};i.set&&(s.set=i.set),Object.defineProperty(t,e,s)}var Ji="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function tr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function er(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var nr,ir={exports:{}};var rr=(nr||(nr=1,function(t){var e=function(t){var e,n=Object.prototype,i=n.hasOwnProperty,r=Object.defineProperty||function(t,e,n){t[e]=n.value},s="function"==typeof Symbol?Symbol:{},o=s.iterator||"@@iterator",a=s.asyncIterator||"@@asyncIterator",c=s.toStringTag||"@@toStringTag";function l(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,n){return t[e]=n}}function h(t,e,n,i){var s=e&&e.prototype instanceof y?e:y,o=Object.create(s.prototype),a=new P(i||[]);return r(o,"_invoke",{value:A(t,n,a)}),o}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=h;var u="suspendedStart",p="suspendedYield",f="executing",g="completed",m={};function y(){}function b(){}function v(){}var _={};l(_,o,function(){return this});var x=Object.getPrototypeOf,w=x&&x(x(D([])));w&&w!==n&&i.call(w,o)&&(_=w);var M=v.prototype=y.prototype=Object.create(_);function S(t){["next","throw","return"].forEach(function(e){l(t,e,function(t){return this._invoke(e,t)})})}function k(t,e){function n(r,s,o,a){var c=d(t[r],t,s);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==typeof h&&i.call(h,"__await")?e.resolve(h.__await).then(function(t){n("next",t,o,a)},function(t){n("throw",t,o,a)}):e.resolve(h).then(function(t){l.value=t,o(l)},function(t){return n("throw",t,o,a)})}a(c.arg)}var s;r(this,"_invoke",{value:function(t,i){function r(){return new e(function(e,r){n(t,i,e,r)})}return s=s?s.then(r,r):r()}})}function A(t,n,i){var r=u;return function(s,o){if(r===f)throw new Error("Generator is already running");if(r===g){if("throw"===s)throw o;return{value:e,done:!0}}for(i.method=s,i.arg=o;;){var a=i.delegate;if(a){var c=E(a,i);if(c){if(c===m)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===u)throw r=g,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=f;var l=d(t,n,i);if("normal"===l.type){if(r=i.done?g:p,l.arg===m)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(r=g,i.method="throw",i.arg=l.arg)}}}function E(t,n){var i=n.method,r=t.iterator[i];if(r===e)return n.delegate=null,"throw"===i&&t.iterator.return&&(n.method="return",n.arg=e,E(t,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),m;var s=d(r,t.iterator,n.arg);if("throw"===s.type)return n.method="throw",n.arg=s.arg,n.delegate=null,m;var o=s.arg;return o?o.done?(n[t.resultName]=o.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,m):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function C(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(C,this),this.reset(!0)}function D(t){if(null!=t){var n=t[o];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,s=function n(){for(;++r<t.length;)if(i.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=e,n.done=!0,n};return s.next=s}}throw new TypeError(typeof t+" is not iterable")}return b.prototype=v,r(M,"constructor",{value:v,configurable:!0}),r(v,"constructor",{value:b,configurable:!0}),b.displayName=l(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,l(t,c,"GeneratorFunction")),t.prototype=Object.create(M),t},t.awrap=function(t){return{__await:t}},S(k.prototype),l(k.prototype,a,function(){return this}),t.AsyncIterator=k,t.async=function(e,n,i,r,s){void 0===s&&(s=Promise);var o=new k(h(e,n,i,r),s);return t.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},S(M),l(M,c,"Generator"),l(M,o,function(){return this}),l(M,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},t.values=D,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(T),!t)for(var n in this)"t"===n.charAt(0)&&i.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function r(i,r){return a.type="throw",a.arg=t,n.next=i,r&&(n.method="next",n.arg=e),!!r}for(var s=this.tryEntries.length-1;s>=0;--s){var o=this.tryEntries[s],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var c=i.call(o,"catchLoc"),l=i.call(o,"finallyLoc");if(c&&l){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var s=r;break}}s&&("break"===t||"continue"===t)&&s.tryLoc<=e&&e<=s.finallyLoc&&(s=null);var o=s?s.completion:{};return o.type=t,o.arg=e,s?(this.method="next",this.next=s.finallyLoc,m):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var r=i.arg;T(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,i){return this.delegate={iterator:D(t),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=e),m}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}Number.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},String.fromCodePoint||function(t){var e=function(e){for(var n=[],i=0,r="",s=0,o=arguments.length;s!==o;++s){var a=+arguments[s];if(!(a<1114111&&a>>>0===a))throw RangeError("Invalid code point: "+a);a<=65535?i=n.push(a):(a-=65536,i=n.push(55296+(a>>10),a%1024+56320)),i>=16383&&(r+=t.apply(null,n),n.length=0)}return r+t.apply(null,n)};try{Object.defineProperty(String,"fromCodePoint",{value:e,configurable:!0,writable:!0})}catch(t){String.fromCodePoint=e}}(String.fromCharCode),Object.is||(Object.is=function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e})
2
- /*! https://mths.be/codepointat v0.2.0 by @mathias */,String.prototype.codePointAt||function(){var t=function(){try{var t={},e=Object.defineProperty,n=e(t,t,t)&&e}catch(t){}return n}(),e=function(t){if(null==this)throw TypeError();var e=String(this),n=e.length,i=t?Number(t):0;if(i!=i&&(i=0),!(i<0||i>=n)){var r,s=e.charCodeAt(i);return s>=55296&&s<=56319&&n>i+1&&(r=e.charCodeAt(i+1))>=56320&&r<=57343?1024*(s-55296)+r-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e}(),Math.log10=Math.log10||function(t){return Math.log(t)*Math.LOG10E},t.exports=function(){function t(e,n,i){function r(o,a){if(!n[o]){if(!e[o]){if(!a&&er)return er(o);if(s)return s(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[o]={exports:{}};e[o][0].call(l.exports,function(t){return r(e[o][1][t]||t)},l,l.exports,t,e,n,i)}return n[o].exports}for(var s=er,o=0;o<i.length;o++)r(i[o]);return r}return t}()({1:[function(t,e,n){var i=t("./utils"),r=function(){var t=i.stringToArray,e=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],n=["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fifteenth","Sixteenth","Seventeenth","Eighteenth","Nineteenth"],r=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],s=["Thousand","Million","Billion","Trillion"];function o(t,i){var o=function t(i,o,a){var c="";if(i<=19)c=(o?" and ":"")+(a?n[i]:e[i]);else if(i<100){var l=Math.floor(i/10),h=i%10;c=(o?" and ":"")+r[l-2],h>0?c+="-"+t(h,!1,a):a&&(c=c.substring(0,c.length-1)+"ieth")}else if(i<1e3){var d=Math.floor(i/100),u=i%100;c=(o?", ":"")+e[d]+" Hundred",u>0?c+=t(u,!0,a):a&&(c+="th")}else{var p=Math.floor(Math.log10(i)/3);p>s.length&&(p=s.length);var f=Math.pow(10,3*p),g=Math.floor(i/f),m=i-g*f;c=(o?", ":"")+t(g,!1,!1)+" "+s[p-1],m>0?c+=t(m,!0,a):a&&(c+="th")}return c};return o(t,!1,i)}var a={};function c(t){var e=t.split(/,\s|\sand\s|[\s\\-]/).map(function(t){return a[t]}),n=[0];return e.forEach(function(t){if(t<100){var e=n.pop();e>=1e3&&(n.push(e),e=0),n.push(e+t)}else n.push(n.pop()*t)}),n.reduce(function(t,e){return t+e},0)}e.forEach(function(t,e){a[t.toLowerCase()]=e}),n.forEach(function(t,e){a[t.toLowerCase()]=e}),r.forEach(function(t,e){var n=t.toLowerCase();a[n]=10*(e+2),a[n.substring(0,t.length-1)+"ieth"]=a[n]}),a.hundredth=100,s.forEach(function(t,e){var n=t.toLowerCase(),i=Math.pow(10,3*(e+1));a[n]=i,a[n+"th"]=i});var l=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]],h={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};function d(t){for(var e=0;e<l.length;e++){var n=l[e];if(t>=n[0])return n[1]+d(t-n[0])}return""}function u(t){for(var e=0,n=1,i=t.length-1;i>=0;i--){var r=t[i],s=h[r];s<n?e-=s:(n=s,e+=s)}return e}function p(t,e){for(var n=[],i=e.charCodeAt(0);t>0;)n.unshift(String.fromCharCode((t-1)%26+i)),t=Math.floor((t-1)/26);return n.join("")}function f(t,e){for(var n=e.charCodeAt(0),i=0,r=0;r<t.length;r++)i+=(t.charCodeAt(t.length-r-1)-n+1)*Math.pow(26,r);return i}function g(t,e){if(void 0!==t)return b(t=Math.floor(t),_(e))}var m={DECIMAL:"decimal",LETTERS:"letters",ROMAN:"roman",WORDS:"words",SEQUENCE:"sequence"},y={UPPER:"upper",LOWER:"lower",TITLE:"title"};function b(e,n){var i,r=e<0;switch(e=Math.abs(e),n.primary){case m.LETTERS:i=p(e,n.case===y.UPPER?"A":"a");break;case m.ROMAN:i=d(e),n.case===y.UPPER&&(i=i.toUpperCase());break;case m.WORDS:i=o(e,n.ordinal),n.case===y.UPPER?i=i.toUpperCase():n.case===y.LOWER&&(i=i.toLowerCase());break;case m.DECIMAL:i=""+e;var s=n.mandatoryDigits-i.length;if(s>0){var a=new Array(s+1).join("0");i=a+i}if(48!==n.zeroCode&&(i=t(i).map(function(t){return String.fromCodePoint(t.codePointAt(0)+n.zeroCode-48)}).join("")),n.regular)for(var c=Math.floor((i.length-1)/n.groupingSeparators.position);c>0;c--){var l=i.length-c*n.groupingSeparators.position;i=i.substr(0,l)+n.groupingSeparators.character+i.substr(l)}else n.groupingSeparators.reverse().forEach(function(t){var e=i.length-t.position;i=i.substr(0,e)+t.character+i.substr(e)});if(n.ordinal){var h={1:"st",2:"nd",3:"rd"}[i[i.length-1]];(!h||i.length>1&&"1"===i[i.length-2])&&(h="th"),i+=h}break;case m.SEQUENCE:throw{code:"D3130",value:n.token}}return r&&(i="-"+i),i}var v=[48,1632,1776,1984,2406,2534,2662,2790,2918,3046,3174,3302,3430,3558,3664,3792,3872,4160,4240,6112,6160,6470,6608,6784,6800,6992,7088,7232,7248,42528,43216,43264,43472,43504,43600,44016,65296];function _(e){var n,i={type:"integer",primary:m.DECIMAL,case:y.LOWER,ordinal:!1},r=e.lastIndexOf(";");switch(-1===r?n=e:(n=e.substring(0,r),"o"===e.substring(r+1)[0]&&(i.ordinal=!0)),n){case"A":i.case=y.UPPER;case"a":i.primary=m.LETTERS;break;case"I":i.case=y.UPPER;case"i":i.primary=m.ROMAN;break;case"W":i.case=y.UPPER,i.primary=m.WORDS;break;case"Ww":i.case=y.TITLE,i.primary=m.WORDS;break;case"w":i.primary=m.WORDS;break;default:var s=null,o=0,a=0,c=[],l=0;if(t(n).map(function(t){return t.codePointAt(0)}).reverse().forEach(function(t){for(var e=!1,n=0;n<v.length;n++){var i=v[n];if(t>=i&&t<=i+9){if(e=!0,o++,l++,null===s)s=i;else if(i!==s)throw{code:"D3131"};break}}e||(35===t?(l++,a++):c.push({position:l,character:String.fromCodePoint(t)}))}),o>0){i.primary=m.DECIMAL,i.zeroCode=s,i.mandatoryDigits=o,i.optionalDigits=a;var h=function(t){if(0===t.length)return 0;for(var e=t[0].character,n=1;n<t.length;n++)if(t[n].character!==e)return 0;for(var i=t.map(function(t){return t.position}),r=function t(e,n){return 0===n?e:t(n,e%n)},s=i.reduce(r),o=1;o<=i.length;o++)if(-1===i.indexOf(o*s))return 0;return s}(c);h>0?(i.regular=!0,i.groupingSeparators={position:h,character:c[0].character}):(i.regular=!1,i.groupingSeparators=c)}else i.primary=m.SEQUENCE,i.token=n}return i}var x={Y:"1",M:"1",D:"1",d:"1",F:"n",W:"1",w:"1",X:"1",x:"1",H:"1",h:"1",P:"n",m:"01",s:"01",f:"1",Z:"01:01",z:"01:01",C:"n",E:"n"};function w(t){for(var e=[],n={type:"datetime",parts:e},i=function(n,i){if(i>n){var r=t.substring(n,i);r=r.split("]]").join("]"),e.push({type:"literal",value:r})}},r=0,s=0;s<t.length;){if("["===t.charAt(s)){if("["===t.charAt(s+1)){i(r,s),e.push({type:"literal",value:"["}),r=s+=2;continue}if(i(r,s),r=s,-1===(s=t.indexOf("]",r)))throw{code:"D3135"};var o,a=t.substring(r+1,s),c={type:"marker",component:(a=a.split(/\s+/).join("")).charAt(0)},l=a.lastIndexOf(",");if(-1!==l){var h=a.substring(l+1),d=h.indexOf("-"),u=void 0,p=void 0,f=function(t){return void 0===t||"*"===t?void 0:parseInt(t)};-1===d?u=h:(u=h.substring(0,d),p=h.substring(d+1));var g={min:f(u),max:f(p)};c.width=g,o=a.substring(1,l)}else o=a.substring(1);if(1===o.length)c.presentation1=o;else if(o.length>1){var m=o.charAt(o.length-1);-1!=="atco".indexOf(m)?(c.presentation2=m,"o"===m&&(c.ordinal=!0),c.presentation1=o.substring(0,o.length-1)):c.presentation1=o}else c.presentation1=x[c.component];if(void 0===c.presentation1)throw{code:"D3132",value:c.component};if("n"===c.presentation1[0])c.names=y.LOWER;else if("N"===c.presentation1[0])"n"===c.presentation1[1]?c.names=y.TITLE:c.names=y.UPPER;else if(-1!=="YMDdFWwXxHhmsf".indexOf(c.component)){var b=c.presentation1;if(c.presentation2&&(b+=";"+c.presentation2),c.integerFormat=_(b),c.width&&void 0!==c.width.min&&c.integerFormat.mandatoryDigits<c.width.min&&(c.integerFormat.mandatoryDigits=c.width.min),-1!=="YMD".indexOf(c.component))if(c.n=-1,c.width&&void 0!==c.width.max)c.n=c.width.max,c.integerFormat.mandatoryDigits=c.n;else{var v=c.integerFormat.mandatoryDigits+c.integerFormat.optionalDigits;v>=2&&(c.n=v)}}"Z"!==c.component&&"z"!==c.component||(c.integerFormat=_(c.presentation1)),e.push(c),r=s+1}s++}return i(r,s),n}var M=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],S=["January","February","March","April","May","June","July","August","September","October","November","December"],k=864e5,A=function(t){var e=Date.UTC(t.year,t.month),n=new Date(e).getUTCDay();return 0===n&&(n=7),n>4?e+(8-n)*k:e-(n-1)*k},E=function t(e,n){return{year:e,month:n,nextMonth:function(){return 11===n?t(e+1,0):t(e,n+1)},previousMonth:function(){return 0===n?t(e-1,11):t(e,n-1)},nextYear:function(){return t(e+1,n)},previousYear:function(){return t(e-1,n)}}},C=function(t,e){return(e-t)/(7*k)+1},T=function(t,e){var n;switch(e){case"Y":n=t.getUTCFullYear();break;case"M":n=t.getUTCMonth()+1;break;case"D":n=t.getUTCDate();break;case"d":n=(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-Date.UTC(t.getUTCFullYear(),0))/k+1;break;case"F":0===(n=t.getUTCDay())&&(n=7);break;case"W":var i=E(t.getUTCFullYear(),0),r=A(i),s=Date.UTC(i.year,t.getUTCMonth(),t.getUTCDate()),o=C(r,s);if(o>52)s>=A(i.nextYear())&&(o=1);else if(o<1){var a=A(i.previousYear());o=C(a,s)}n=Math.floor(o);break;case"w":var c=E(t.getUTCFullYear(),t.getUTCMonth()),l=A(c),h=Date.UTC(c.year,c.month,t.getUTCDate()),d=C(l,h);if(d>4)h>=A(c.nextMonth())&&(d=1);else if(d<1){var u=A(c.previousMonth());d=C(u,h)}n=Math.floor(d);break;case"X":var p=E(t.getUTCFullYear(),0),f=A(p),g=A(p.nextYear()),m=t.getTime();n=m<f?p.year-1:m>=g?p.year+1:p.year;break;case"x":var y=E(t.getUTCFullYear(),t.getUTCMonth()),b=A(y),v=y.nextMonth(),_=A(v),x=t.getTime();n=x<b?y.previousMonth().month+1:x>=_?v.month+1:y.month+1;break;case"H":n=t.getUTCHours();break;case"h":n=t.getUTCHours(),0==(n%=12)&&(n=12);break;case"P":n=t.getUTCHours()>=12?"pm":"am";break;case"m":n=t.getUTCMinutes();break;case"s":n=t.getUTCSeconds();break;case"f":n=t.getUTCMilliseconds();break;case"Z":case"z":break;case"C":case"E":n="ISO"}return n},P=null;function D(t,e,n){var i=0,r=0;if(void 0!==n){var s=parseInt(n);i=Math.floor(s/100),r=s%100}var o,a=function(t,e){var n=T(t,e.component);if(-1!=="YMDdFWwXxHhms".indexOf(e.component))if("Y"===e.component&&-1!==e.n&&(n%=Math.pow(10,e.n)),e.names){if("M"===e.component||"x"===e.component)n=S[n-1];else{if("F"!==e.component)throw{code:"D3133",value:e.component};n=M[n]}e.names===y.UPPER?n=n.toUpperCase():e.names===y.LOWER&&(n=n.toLowerCase()),e.width&&n.length>e.width.max&&(n=n.substring(0,e.width.max))}else n=b(n,e.integerFormat);else if("f"===e.component)n=b(n,e.integerFormat);else if("Z"===e.component||"z"===e.component){var s=100*i+r;if(e.integerFormat.regular)n=b(s,e.integerFormat);else{var o=e.integerFormat.mandatoryDigits;if(1===o||2===o)n=b(i,e.integerFormat),0!==r&&(n+=":"+g(r,"00"));else{if(3!==o&&4!==o)throw{code:"D3134",value:o};n=b(s,e.integerFormat)}}s>=0&&(n="+"+n),"z"===e.component&&(n="GMT"+n),0===s&&"t"===e.presentation2&&(n="Z")}return n};void 0===e?(null===P&&(P=w("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),o=P):o=w(e);var c=new Date(t+60*(60*i+r)*1e3),l="";return o.parts.forEach(function(t){"literal"===t.type?l+=t.value:l+=a(c,t)}),l}function O(t){var e={};if("datetime"===t.type)e.type="datetime",e.parts=t.parts.map(function(t){var e={};if("literal"===t.type)e.regex=t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if("Z"===t.component||"z"===t.component){var n;Array.isArray(t.integerFormat.groupingSeparators)||(n=t.integerFormat.groupingSeparators),e.regex="","z"===t.component&&(e.regex="GMT"),e.regex+="[-+][0-9]+",n&&(e.regex+=n.character+"[0-9]+"),e.parse=function(e){"z"===t.component&&(e=e.substring(3));var i=0,r=0;return n?(i=Number.parseInt(e.substring(0,e.indexOf(n.character))),r=Number.parseInt(e.substring(e.indexOf(n.character)+1))):e.length-1<=2?i=Number.parseInt(e):(i=Number.parseInt(e.substring(0,3)),r=Number.parseInt(e.substring(3))),60*i+r}}else if(t.integerFormat)t.integerFormat.n=t.n,e=O(t.integerFormat);else{e.regex="[a-zA-Z]+";var i={};if("M"===t.component||"x"===t.component)S.forEach(function(e,n){t.width&&t.width.max?i[e.substring(0,t.width.max)]=n+1:i[e]=n+1});else if("F"===t.component)M.forEach(function(e,n){n>0&&(t.width&&t.width.max?i[e.substring(0,t.width.max)]=n:i[e]=n)});else{if("P"!==t.component)throw{code:"D3133",value:t.component};i={am:0,AM:0,pm:1,PM:1}}e.parse=function(t){return i[t]}}return e.component=t.component,e});else{e.type="integer";var n,i=t.case===y.UPPER;switch(n=t.n&&t.n>0?0===t.optionalDigits?"{".concat(t.n,"}"):"{".concat(t.n-t.optionalDigits,",").concat(t.n,"}"):"+",t.primary){case m.LETTERS:e.regex=i?"[A-Z]+":"[a-z]+",e.parse=function(t){return f(t,i?"A":"a")};break;case m.ROMAN:e.regex=i?"[MDCLXVI]+":"[mdclxvi]+",e.parse=function(t){return u(i?t:t.toUpperCase())};break;case m.WORDS:e.regex="(?:"+Object.keys(a).concat("and","[\\-, ]").join("|")+")+",e.parse=function(t){return c(t.toLowerCase())};break;case m.DECIMAL:e.regex="[0-9]".concat(n),t.ordinal&&(e.regex+="(?:th|st|nd|rd)"),e.parse=function(e){var n=e;return t.ordinal&&(n=e.substring(0,e.length-2)),t.regular?n=n.split(",").join(""):t.groupingSeparators.forEach(function(t){n=n.split(t.character).join("")}),48!==t.zeroCode&&(n=n.split("").map(function(e){return String.fromCodePoint(e.codePointAt(0)-t.zeroCode+48)}).join("")),parseInt(n)};break;case m.SEQUENCE:throw{code:"D3130",value:t.token}}}return e}function z(t,e){if(void 0!==t)return O(_(e)).parse(t)}function I(t,e){var n=O(w(e)),i="^"+n.parts.map(function(t){return"("+t.regex+")"}).join("")+"$",r=new RegExp(i,"i").exec(t);if(null!==r){for(var s=161,o=130,a=84,c=72,l=23,h=47,d={},u=1;u<r.length;u++){var p=n.parts[u-1];p.parse&&(d[p.component]=p.parse(r[u]))}if(0===Object.getOwnPropertyNames(d).length)return;var f=0,g=function(t){f<<=1,f+=t?1:0},m=function(t){return!(~t&f||!(t&f))};"YXMxWwdD".split("").forEach(function(t){return g(d[t])});var y=!m(s)&&m(o),b=m(a),v=!b&&m(c);f=0,"PHhmsf".split("").forEach(function(t){return g(d[t])});var _=!m(l)&&m(h),x=(y?"YD":b?"XxwF":v?"XWF":"YMD")+(_?"Phmsf":"Hmsf"),M=this.environment.timestamp,S=!1,k=!1;if(x.split("").forEach(function(t){if(void 0===d[t])S?(d[t]=-1!=="MDd".indexOf(t)?1:0,k=!0):d[t]=T(M,t);else if(S=!0,k)throw{code:"D3136"}}),d.M>0?d.M-=1:d.M=0,y){var A=Date.UTC(d.Y,0),E=1e3*(d.d-1)*60*60*24,C=new Date(A+E);d.M=C.getUTCMonth(),d.D=C.getUTCDate()}if(b)throw{code:"D3136"};if(v)throw{code:"D3136"};_&&(d.H=12===d.h?0:d.h,1===d.P&&(d.H+=12));var P=Date.UTC(d.Y,d.M,d.D,d.H,d.m,d.s,d.f);return(d.Z||d.z)&&(P-=60*(d.Z||d.z)*1e3),P}}var L=new RegExp("^\\d{4}(-[01]\\d)*(-[0-3]\\d)*(T[0-2]\\d:[0-5]\\d:[0-5]\\d)*(\\.\\d+)?([+-][0-2]\\d:?[0-5]\\d|Z)?$");function j(t,e){if(void 0!==t){if(void 0===e){if(!L.test(t))throw{stack:(new Error).stack,code:"D3110",value:t};return Date.parse(t)}return I.call(this,t,e)}}function R(t,e,n){if(void 0!==t)return D.call(this,t,e,n)}return{formatInteger:g,parseInteger:z,fromMillis:R,toMillis:j}}();e.exports=r},{"./utils":6}],2:[function(t,e,n){(function(n){(function(){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */r=function(){return e};var t,e={},n=Object.prototype,s=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",l=a.asyncIterator||"@@asyncIterator",h=a.toStringTag||"@@toStringTag";function d(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{d({},"")}catch(t){d=function(t,e,n){return t[e]=n}}function u(t,e,n,i){var r=e&&e.prototype instanceof v?e:v,s=Object.create(r.prototype),a=new O(i||[]);return o(s,"_invoke",{value:C(t,n,a)}),s}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=u;var f="suspendedStart",g="suspendedYield",m="executing",y="completed",b={};function v(){}function _(){}function x(){}var w={};d(w,c,function(){return this});var M=Object.getPrototypeOf,S=M&&M(M(z([])));S&&S!==n&&s.call(S,c)&&(w=S);var k=x.prototype=v.prototype=Object.create(w);function A(t){["next","throw","return"].forEach(function(e){d(t,e,function(t){return this._invoke(e,t)})})}function E(t,e){function n(r,o,a,c){var l=p(t[r],t,o);if("throw"!==l.type){var h=l.arg,d=h.value;return d&&"object"==i(d)&&s.call(d,"__await")?e.resolve(d.__await).then(function(t){n("next",t,a,c)},function(t){n("throw",t,a,c)}):e.resolve(d).then(function(t){h.value=t,a(h)},function(t){return n("throw",t,a,c)})}c(l.arg)}var r;o(this,"_invoke",{value:function(t,i){function s(){return new e(function(e,r){n(t,i,e,r)})}return r=r?r.then(s,s):s()}})}function C(e,n,i){var r=f;return function(s,o){if(r===m)throw new Error("Generator is already running");if(r===y){if("throw"===s)throw o;return{value:t,done:!0}}for(i.method=s,i.arg=o;;){var a=i.delegate;if(a){var c=T(a,i);if(c){if(c===b)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===f)throw r=y,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=m;var l=p(e,n,i);if("normal"===l.type){if(r=i.done?y:g,l.arg===b)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(r=y,i.method="throw",i.arg=l.arg)}}}function T(e,n){var i=n.method,r=e.iterator[i];if(r===t)return n.delegate=null,"throw"===i&&e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),b;var s=p(r,e.iterator,n.arg);if("throw"===s.type)return n.method="throw",n.arg=s.arg,n.delegate=null,b;var o=s.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,b):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,b)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function D(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function z(e){if(e||""===e){var n=e[c];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function n(){for(;++r<e.length;)if(s.call(e,r))return n.value=e[r],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(i(e)+" is not iterable")}return _.prototype=x,o(k,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:_,configurable:!0}),_.displayName=d(x,h,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,d(t,h,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},A(E.prototype),d(E.prototype,l,function(){return this}),e.AsyncIterator=E,e.async=function(t,n,i,r,s){void 0===s&&(s=Promise);var o=new E(u(t,n,i,r),s);return e.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},A(k),d(k,h,"Generator"),d(k,c,function(){return this}),d(k,"toString",function(){return"[object Generator]"}),e.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},e.values=z,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(D),!e)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(i,r){return a.type="throw",a.arg=e,n.next=i,r&&(n.method="next",n.arg=t),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),l=s.call(o,"finallyLoc");if(c&&l){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&s.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=t,o.arg=e,r?(this.method="next",this.next=r.finallyLoc,b):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),D(n),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var r=i.arg;D(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,i){return this.delegate={iterator:z(e),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=t),b}},e}var s=t("./utils"),o=function(){var t=r().mark(H),e=r().mark(Y),o=r().mark(V),a=r().mark(G),c=r().mark(Q),l=r().mark(ut),h=r().mark(pt),d=r().mark(ft),u=r().mark(mt),p=r().mark(St),f=r().mark(Ct),g=r().mark(Dt),m=s.isNumeric,y=s.isArrayOfStrings,b=s.isArrayOfNumbers,v=s.createSequence,_=s.isSequence,x=s.isFunction,w=s.isLambda,M=s.isIterable,S=s.getFunctionArity,k=s.isDeepEqual,A=s.stringToArray;function E(t){if(void 0!==t){var e=0;return t.forEach(function(t){e+=t}),e}}function C(t){return void 0===t?0:t.length}function T(t){if(void 0!==t&&0!==t.length)return Math.max.apply(Math,t)}function P(t){if(void 0!==t&&0!==t.length)return Math.min.apply(Math,t)}function D(t){if(void 0!==t&&0!==t.length){var e=0;return t.forEach(function(t){e+=t}),e/t.length}}function O(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(void 0!==t){var n;if("string"==typeof t)n=t;else if(x(t))n="";else{if("number"==typeof t&&!isFinite(t))throw{code:"D3001",value:t,stack:(new Error).stack};var i=e?2:0;Array.isArray(t)&&t.outerWrapper&&(t=t[0]),n=JSON.stringify(t,function(t,e){return null!=e&&e.toPrecision&&m(e)?Number(e.toPrecision(15)):e&&x(e)?"":e},i)}return n}}function z(t,e,n){if(void 0!==t){var i=A(t),r=i.length;if(r+e<0&&(e=0),void 0!==n){if(n<=0)return"";var s=e>=0?e+n:r+e+n;return i.slice(e,s).join("")}return i.slice(e).join("")}}function I(t,e){if(void 0!==t){var n=t.indexOf(e);return n>-1?t.substr(0,n):t}}function L(t,e){if(void 0!==t){var n=t.indexOf(e);return n>-1?t.substr(n+e.length):t}}function j(t){if(void 0!==t)return t.toLowerCase()}function R(t){if(void 0!==t)return t.toUpperCase()}function F(t){if(void 0!==t)return A(t).length}function B(t){if(void 0!==t){var e=t.replace(/[ \t\n\r]+/gm," ");return" "===e.charAt(0)&&(e=e.substring(1))," "===e.charAt(e.length-1)&&(e=e.substring(0,e.length-1)),e}}function N(t,e,n){if(void 0!==t){var i;void 0!==n&&0!==n.length||(n=" ");var r=Math.abs(e)-F(t);if(r>0){var s=new Array(r+1).join(n);n.length>1&&(s=z(s,0,r)),i=e>0?t+s:s+t}else i=t;return i}}function H(e,n){var i;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=e.apply(this,[n]),!M(i)){t.next=4;break}return t.delegateYield(i,"t0",3);case 3:i=t.t0;case 4:if(!i||"number"==typeof i.start||"number"===i.end||Array.isArray(i.groups)||x(i.next)){t.next=6;break}throw{code:"T1010",stack:(new Error).stack};case 6:return t.abrupt("return",i);case 7:case"end":return t.stop()}},t,this)}function Y(t,n){var i,s;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t){e.next=2;break}return e.abrupt("return",void 0);case 2:if("string"!=typeof n){e.next=6;break}i=-1!==t.indexOf(n),e.next=9;break;case 6:return e.delegateYield(H(n,t),"t0",7);case 7:s=e.t0,i=void 0!==s;case 9:return e.abrupt("return",i);case 10:case"end":return e.stop()}},e)}function V(t,e,n){var i,s,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(!(n<0)){r.next=4;break}throw{stack:(new Error).stack,value:n,code:"D3040",index:3};case 4:if(i=v(),!(void 0===n||n>0)){r.next=17;break}return s=0,r.delegateYield(H(e,t),"t0",8);case 8:if(void 0===(a=r.t0)){r.next=17;break}case 10:if(void 0===a||!(void 0===n||s<n)){r.next=17;break}return i.push({match:a.match,index:a.start,groups:a.groups}),r.delegateYield(H(a.next),"t1",13);case 13:a=r.t1,s++,r.next=10;break;case 17:return r.abrupt("return",i);case 18:case"end":return r.stop()}},o)}function G(t,e,n,i){var s,o,c,l,h,d,u,p;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(s=this,""!==e){r.next=5;break}throw{code:"D3010",stack:(new Error).stack,value:e,index:2};case 5:if(!(i<0)){r.next=7;break}throw{code:"D3011",stack:(new Error).stack,value:i,index:4};case 7:if(o="string"==typeof n?function(t){for(var e="",i=0,r=n.indexOf("$",i);-1!==r&&i<n.length;){e+=n.substring(i,r),i=r+1;var s=n.charAt(i);if("$"===s)e+="$",i++;else if("0"===s)e+=t.match,i++;else{var o;if(o=0===t.groups.length?1:Math.floor(Math.log(t.groups.length)*Math.LOG10E)+1,r=parseInt(n.substring(i,i+o),10),o>1&&r>t.groups.length&&(r=parseInt(n.substring(i,i+o-1),10)),isNaN(r))e+="$";else{if(t.groups.length>0){var a=t.groups[r-1];void 0!==a&&(e+=a)}i+=r.toString().length}}r=n.indexOf("$",i)}return e+=n.substring(i)}:n,c="",l=0,!(void 0===i||i>0)){r.next=44;break}if(h=0,"string"!=typeof e){r.next=18;break}for(d=t.indexOf(e,l);-1!==d&&(void 0===i||h<i);)c+=t.substring(l,d),c+=n,l=d+e.length,h++,d=t.indexOf(e,l);c+=t.substring(l),r.next=42;break;case 18:return r.delegateYield(H(e,t),"t0",19);case 19:if(void 0===(u=r.t0)){r.next=41;break}case 21:if(void 0===u||!(void 0===i||h<i)){r.next=38;break}if(c+=t.substring(l,u.start),p=o.apply(s,[u]),!M(p)){r.next=27;break}return r.delegateYield(p,"t1",26);case 26:p=r.t1;case 27:if("string"!=typeof p){r.next=31;break}c+=p,r.next=32;break;case 31:throw{code:"D3012",stack:(new Error).stack,value:p};case 32:return l=u.start+u.match.length,h++,r.delegateYield(H(u.next),"t2",35);case 35:u=r.t2,r.next=21;break;case 38:c+=t.substring(l),r.next=42;break;case 41:c=t;case 42:r.next=45;break;case 44:c=t;case 45:return r.abrupt("return",c);case 46:case"end":return r.stop()}},a,this)}function U(t){if(void 0!==t){var e="undefined"!=typeof window?window.btoa:function(t){return new n.Buffer.from(t,"binary").toString("base64")};return e(t)}}function W(t){if(void 0!==t){var e="undefined"!=typeof window?window.atob:function(t){return new n.Buffer.from(t,"base64").toString("binary")};return e(t)}}function X(t){if(void 0!==t){var e;try{e=encodeURIComponent(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"encodeUrlComponent"}}return e}}function q(t){if(void 0!==t){var e;try{e=encodeURI(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"encodeUrl"}}return e}}function K(t){if(void 0!==t){var e;try{e=decodeURIComponent(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"decodeUrlComponent"}}return e}}function $(t){if(void 0!==t){var e;try{e=decodeURI(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"decodeUrl"}}return e}}function Q(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(!(n<0)){r.next=4;break}throw{code:"D3020",stack:(new Error).stack,value:n,index:3};case 4:if(i=[],!(void 0===n||n>0)){r.next=27;break}if("string"!=typeof e){r.next=10;break}i=t.split(e,n),r.next=27;break;case 10:return s=0,r.delegateYield(H(e,t),"t0",12);case 12:if(void 0===(o=r.t0)){r.next=26;break}a=0;case 15:if(void 0===o||!(void 0===n||s<n)){r.next=23;break}return i.push(t.substring(a,o.start)),a=o.end,r.delegateYield(H(o.next),"t1",19);case 19:o=r.t1,s++,r.next=15;break;case 23:(void 0===n||s<n)&&i.push(t.substring(a)),r.next=27;break;case 26:i.push(t);case 27:return r.abrupt("return",i);case 28:case"end":return r.stop()}},c)}function Z(t,e){if(void 0!==t)return void 0===e&&(e=""),t.join(e)}function J(t,e,n){if(void 0!==t){var i={"decimal-separator":".","grouping-separator":",","exponent-separator":"e",infinity:"Infinity","minus-sign":"-",NaN:"NaN",percent:"%","per-mille":"‰","zero-digit":"0",digit:"#","pattern-separator":";"};void 0!==n&&Object.keys(n).forEach(function(t){i[t]=n[t]});for(var r=[],s=i["zero-digit"].charCodeAt(0),o=s;o<s+10;o++)r.push(String.fromCharCode(o));var a=r.concat([i["decimal-separator"],i["exponent-separator"],i["grouping-separator"],i.digit,i["pattern-separator"]]),c=e.split(i["pattern-separator"]);if(c.length>2)throw{code:"D3080",stack:(new Error).stack};var l=function(t){var e,n,r,s,o=function(){for(var e,n=0;n<t.length;n++)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(0,n)}(),c=function(){for(var e,n=t.length-1;n>=0;n--)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(n+1)}(),l=t.substring(o.length,t.length-c.length),h=t.indexOf(i["exponent-separator"],o.length);-1===h||h>t.length-c.length?(e=l,n=void 0):(e=l.substring(0,h),n=l.substring(h+1));var d=e.indexOf(i["decimal-separator"]);return-1===d?(r=e,s=c):(r=e.substring(0,d),s=e.substring(d+1)),{prefix:o,suffix:c,activePart:l,mantissaPart:e,exponentPart:n,integerPart:r,fractionalPart:s,subpicture:t}},h=function(t){var e,n,s=t.subpicture,o=s.indexOf(i["decimal-separator"]);o!==s.lastIndexOf(i["decimal-separator"])&&(e="D3081"),s.indexOf(i.percent)!==s.lastIndexOf(i.percent)&&(e="D3082"),s.indexOf(i["per-mille"])!==s.lastIndexOf(i["per-mille"])&&(e="D3083"),-1!==s.indexOf(i.percent)&&-1!==s.indexOf(i["per-mille"])&&(e="D3084");var c=!1;for(n=0;n<t.mantissaPart.length;n++){var l=t.mantissaPart.charAt(n);if(-1!==r.indexOf(l)||l===i.digit){c=!0;break}}c||(e="D3085"),-1!==t.activePart.split("").map(function(t){return-1===a.indexOf(t)?"p":"a"}).join("").indexOf("p")&&(e="D3086"),-1!==o?s.charAt(o-1)!==i["grouping-separator"]&&s.charAt(o+1)!==i["grouping-separator"]||(e="D3087"):t.integerPart.charAt(t.integerPart.length-1)===i["grouping-separator"]&&(e="D3088"),-1!==s.indexOf(i["grouping-separator"]+i["grouping-separator"])&&(e="D3089");var h=t.integerPart.indexOf(i.digit);-1!==h&&t.integerPart.substring(0,h).split("").filter(function(t){return r.indexOf(t)>-1}).length>0&&(e="D3090"),-1!==(h=t.fractionalPart.lastIndexOf(i.digit))&&t.fractionalPart.substring(h).split("").filter(function(t){return r.indexOf(t)>-1}).length>0&&(e="D3091");var d="string"==typeof t.exponentPart;if(d&&t.exponentPart.length>0&&(-1!==s.indexOf(i.percent)||-1!==s.indexOf(i["per-mille"]))&&(e="D3092"),d&&(0===t.exponentPart.length||t.exponentPart.split("").filter(function(t){return-1===r.indexOf(t)}).length>0)&&(e="D3093"),e)throw{code:e,stack:(new Error).stack}},d=function(t){var e=function(e,n){for(var s=[],o=e.indexOf(i["grouping-separator"]);-1!==o;){var a=(n?e.substring(0,o):e.substring(o)).split("").filter(function(t){return-1!==r.indexOf(t)||t===i.digit}).length;s.push(a),o=t.integerPart.indexOf(i["grouping-separator"],o+1)}return s},n=e(t.integerPart),s=function(t){if(0===t.length)return 0;for(var e=function t(e,n){return 0===n?e:t(n,e%n)},n=t.reduce(e),i=1;i<=t.length;i++)if(-1===t.indexOf(i*n))return 0;return n}(n),o=e(t.fractionalPart,!0),a=t.integerPart.split("").filter(function(t){return-1!==r.indexOf(t)}).length,c=a,l=t.fractionalPart.split(""),h=l.filter(function(t){return-1!==r.indexOf(t)}).length,d=l.filter(function(t){return-1!==r.indexOf(t)||t===i.digit}).length,u="string"==typeof t.exponentPart;0===a&&0===d&&(u?(h=1,d=1):a=1),u&&0===a&&-1!==t.integerPart.indexOf(i.digit)&&(a=1),0===a&&0===h&&(h=1);var p=0;return u&&(p=t.exponentPart.split("").filter(function(t){return-1!==r.indexOf(t)}).length),{integerPartGroupingPositions:n,regularGrouping:s,minimumIntegerPartSize:a,scalingFactor:c,prefix:t.prefix,fractionalPartGroupingPositions:o,minimumFactionalPartSize:h,maximumFactionalPartSize:d,minimumExponentSize:p,suffix:t.suffix,picture:t.subpicture}},u=c.map(l);u.forEach(h);var p,f,g,m,y=u.map(d),b=i["minus-sign"],v=i["zero-digit"],_=i["decimal-separator"],x=i["grouping-separator"];if(1===y.length&&(y.push(JSON.parse(JSON.stringify(y[0]))),y[1].prefix=b+y[1].prefix),f=-1!==(p=t>=0?y[0]:y[1]).picture.indexOf(i.percent)?100*t:-1!==p.picture.indexOf(i["per-mille"])?1e3*t:t,0===p.minimumExponentSize)g=f;else{var w=Math.pow(10,p.scalingFactor),M=Math.pow(10,p.scalingFactor-1);for(g=f,m=0;g<M;)g*=10,m-=1;for(;g>w;)g/=10,m+=1}var S=function(t,e){var n=Math.abs(t).toFixed(e);return"0"!==v&&(n=n.split("").map(function(t){return t>="0"&&t<="9"?r[t.charCodeAt(0)-48]:t}).join("")),n},k=S(st(g,p.maximumFactionalPartSize),p.maximumFactionalPartSize),A=k.indexOf(".");for(-1===A?k+=_:k=k.replace(".",_);k.charAt(0)===v;)k=k.substring(1);for(;k.charAt(k.length-1)===v;)k=k.substring(0,k.length-1);A=k.indexOf(_);var E=p.minimumIntegerPartSize-A,C=p.minimumFactionalPartSize-(k.length-A-1);if(k=(E>0?new Array(E+1).join(v):"")+k,k+=C>0?new Array(C+1).join(v):"",A=k.indexOf(_),p.regularGrouping>0)for(var T=Math.floor((A-1)/p.regularGrouping),P=1;P<=T;P++)k=[k.slice(0,A-P*p.regularGrouping),x,k.slice(A-P*p.regularGrouping)].join("");else p.integerPartGroupingPositions.forEach(function(t){k=[k.slice(0,A-t),x,k.slice(A-t)].join(""),A++});if(A=k.indexOf(_),p.fractionalPartGroupingPositions.forEach(function(t){k=[k.slice(0,t+A+1),x,k.slice(t+A+1)].join("")}),A=k.indexOf(_),-1!==p.picture.indexOf(_)&&A!==k.length-1||(k=k.substring(0,k.length-1)),void 0!==m){var D=S(m,0);(E=p.minimumExponentSize-D.length)>0&&(D=new Array(E+1).join(v)+D),k=k+i["exponent-separator"]+(m<0?b:"")+D}return k=p.prefix+k+p.suffix}}function tt(t,e){if(void 0!==t){if(t=st(t),(e=void 0===e?10:st(e))<2||e>36)throw{code:"D3100",stack:(new Error).stack,value:e};return t.toString(e)}}function et(t){var e;if(void 0!==t){if("number"==typeof t)e=t;else if("string"==typeof t&&/^-?[0-9]+(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(t)&&!isNaN(parseFloat(t))&&isFinite(t))e=parseFloat(t);else if(!0===t)e=1;else{if(!1!==t)throw{code:"D3030",value:t,stack:(new Error).stack,index:1};e=0}return e}}function nt(t){if(void 0!==t)return Math.abs(t)}function it(t){if(void 0!==t)return Math.floor(t)}function rt(t){if(void 0!==t)return Math.ceil(t)}function st(t,e){var n;if(void 0!==t){if(e){var i=t.toString().split("e");t=+(i[0]+"e"+(i[1]?+i[1]+e:e))}var r=(n=Math.round(t))-t;return.5===Math.abs(r)&&1===Math.abs(n%2)&&(n-=1),e&&(i=n.toString().split("e"),n=+(i[0]+"e"+(i[1]?+i[1]-e:-e))),Object.is(n,-0)&&(n=0),n}}function ot(t){if(void 0!==t){if(t<0)throw{stack:(new Error).stack,code:"D3060",index:1,value:t};return Math.sqrt(t)}}function at(t,e){var n;if(void 0!==t){if(n=Math.pow(t,e),!isFinite(n))throw{stack:(new Error).stack,code:"D3061",index:1,value:t,exp:e};return n}}function ct(){return Math.random()}function lt(t){if(void 0!==t){var e=!1;return Array.isArray(t)?1===t.length?e=lt(t[0]):t.length>1&&(e=t.filter(function(t){return lt(t)}).length>0):"string"==typeof t?t.length>0&&(e=!0):m(t)?0!==t&&(e=!0):null!==t&&"object"===i(t)?Object.keys(t).length>0&&(e=!0):"boolean"==typeof t&&!0===t&&(e=!0),e}}function ht(t){if(void 0!==t)return!lt(t)}function dt(t,e,n,i){var r=[e],s=S(t);return s>=2&&r.push(n),s>=3&&r.push(i),r}function ut(t,e){var n,i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=v(),i=0;case 4:if(!(i<t.length)){r.next=12;break}return s=dt(e,t[i],i,t),r.delegateYield(e.apply(this,s),"t0",7);case 7:void 0!==(o=r.t0)&&n.push(o);case 9:i++,r.next=4;break;case 12:return r.abrupt("return",n);case 13:case"end":return r.stop()}},l,this)}function pt(t,e){var n,i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=v(),i=0;case 4:if(!(i<t.length)){r.next=13;break}return s=t[i],o=dt(e,s,i,t),r.delegateYield(e.apply(this,o),"t0",8);case 8:lt(r.t0)&&n.push(s);case 10:i++,r.next=4;break;case 13:return r.abrupt("return",n);case 14:case"end":return r.stop()}},h,this)}function ft(t,e){var n,i,s,o,a,c,l;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=!1,s=0;case 4:if(!(s<t.length)){r.next=22;break}if(o=t[s],a=!0,void 0===e){r.next=12;break}return c=dt(e,o,s,t),r.delegateYield(e.apply(this,c),"t0",10);case 10:l=r.t0,a=lt(l);case 12:if(!a){r.next=19;break}if(n){r.next=18;break}i=o,n=!0,r.next=19;break;case 18:throw{stack:(new Error).stack,code:"D3138",index:s};case 19:s++,r.next=4;break;case 22:if(n){r.next=24;break}throw{stack:(new Error).stack,code:"D3139"};case 24:return r.abrupt("return",i);case 25:case"end":return r.stop()}},d,this)}function gt(){for(var t=[],e=Array.prototype.slice.call(arguments),n=Math.min.apply(Math,e.map(function(t){return Array.isArray(t)?t.length:0})),i=0;i<n;i++){var r=e.map(function(t){return t[i]});t.push(r)}return t}function mt(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(!((s=S(e))<2)){r.next=5;break}throw{stack:(new Error).stack,code:"D3050",index:1};case 5:void 0===n&&t.length>0?(i=t[0],o=1):(i=n,o=0);case 6:if(!(o<t.length)){r.next=15;break}return a=[i,t[o]],s>=3&&a.push(o),s>=4&&a.push(t),r.delegateYield(e.apply(this,a),"t0",11);case 11:i=r.t0,o++,r.next=6;break;case 15:return r.abrupt("return",i);case 16:case"end":return r.stop()}},u,this)}function yt(t){var e=v();if(Array.isArray(t)){var n={};t.forEach(function(t){yt(t).forEach(function(t){n[t]=!0})}),e=yt(n)}else null===t||"object"!==i(t)||w(t)||Object.keys(t).forEach(function(t){return e.push(t)});return e}function bt(t,e){var n;if(Array.isArray(t)){n=v();for(var r=0;r<t.length;r++){var s=bt(t[r],e);void 0!==s&&(Array.isArray(s)?s.forEach(function(t){return n.push(t)}):n.push(s))}}else null!==t&&"object"===i(t)&&(n=t[e]);return n}function vt(t,e){return void 0===t?e:void 0===e?t:(Array.isArray(t)||(t=v(t)),Array.isArray(e)||(e=[e]),t.concat(e))}function _t(t){return void 0!==t}function xt(t){var e=v();if(Array.isArray(t))t.forEach(function(t){e=vt(e,xt(t))});else if(null===t||"object"!==i(t)||w(t))e=t;else for(var n in t){var r={};r[n]=t[n],e.push(r)}return e}function wt(t){if(void 0!==t){var e={};return t.forEach(function(t){for(var n in t)e[n]=t[n]}),e}}function Mt(t){if(void 0!==t){if(t.length<=1)return t;for(var e=t.length,n=new Array(e),i=0;i<e;i++)n[e-i-1]=t[i];return n}}function St(t,e){var n,i,s,o;return r().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n=v(),a.t0=r().keys(t);case 2:if((a.t1=a.t0()).done){a.next=10;break}return i=a.t1.value,s=dt(e,t[i],i,t),a.delegateYield(e.apply(this,s),"t2",6);case 6:void 0!==(o=a.t2)&&n.push(o),a.next=2;break;case 10:return a.abrupt("return",n);case 11:case"end":return a.stop()}},p,this)}function kt(t){throw{code:"D3137",stack:(new Error).stack,message:t||"$error() function evaluated"}}function At(t,e){if(!t)throw{code:"D3141",stack:(new Error).stack,message:e||"$assert() statement failed"}}function Et(t){if(void 0!==t)return null===t?"null":m(t)?"number":"string"==typeof t?"string":"boolean"==typeof t?"boolean":Array.isArray(t)?"array":x(t)?"function":"object"}function Ct(t,e){var n,i,s,o;return r().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(void 0!==t){a.next=2;break}return a.abrupt("return",void 0);case 2:if(!(t.length<=1)){a.next=4;break}return a.abrupt("return",t);case 4:if(void 0!==e){a.next=10;break}if(b(t)||y(t)){a.next=7;break}throw{stack:(new Error).stack,code:"D3070",index:1};case 7:n=r().mark(function t(e,n){return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e>n);case 1:case"end":return t.stop()}},t)}),a.next=11;break;case 10:n=e;case 11:return i=r().mark(function t(e,i){var s,o;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return s=r().mark(function t(e,i,s){return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(0!==i.length){r.next=4;break}Array.prototype.push.apply(e,s),r.next=16;break;case 4:if(0!==s.length){r.next=8;break}Array.prototype.push.apply(e,i),r.next=16;break;case 8:return r.delegateYield(n(i[0],s[0]),"t0",9);case 9:if(!r.t0){r.next=14;break}return e.push(s[0]),r.delegateYield(t(e,i,s.slice(1)),"t1",12);case 12:r.next=16;break;case 14:return e.push(i[0]),r.delegateYield(t(e,i.slice(1),s),"t2",16);case 16:case"end":return r.stop()}},t)}),o=[],t.delegateYield(s(o,e,i),"t0",3);case 3:return t.abrupt("return",o);case 4:case"end":return t.stop()}},t)}),s=r().mark(function t(e){var n,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(Array.isArray(e)&&!(e.length<=1)){r.next=4;break}return r.abrupt("return",e);case 4:return n=Math.floor(e.length/2),s=e.slice(0,n),o=e.slice(n),r.delegateYield(t(s),"t0",8);case 8:return s=r.t0,r.delegateYield(t(o),"t1",10);case 10:return o=r.t1,r.delegateYield(i(s,o),"t2",12);case 12:return r.abrupt("return",r.t2);case 13:case"end":return r.stop()}},t)}),a.delegateYield(s(t),"t0",14);case 14:return o=a.t0,a.abrupt("return",o);case 16:case"end":return a.stop()}},f)}function Tt(t){if(void 0!==t){if(t.length<=1)return t;for(var e=new Array(t.length),n=0;n<t.length;n++){var i=Math.floor(Math.random()*(n+1));n!==i&&(e[n]=e[i]),e[i]=t[n]}return e}}function Pt(t){if(void 0!==t){if(!Array.isArray(t)||t.length<=1)return t;for(var e=_(t)?v():[],n=0;n<t.length;n++){for(var i=t[n],r=!1,s=0;s<e.length;s++)if(k(i,e[s])){r=!0;break}r||e.push(i)}return e}}function Dt(t,e){var n,i,s,o;return r().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n={},a.t0=r().keys(t);case 2:if((a.t1=a.t0()).done){a.next=11;break}return i=a.t1.value,s=t[i],o=dt(e,s,i,t),a.delegateYield(e.apply(this,o),"t2",7);case 7:lt(a.t2)&&(n[i]=s),a.next=2;break;case 11:return 0===Object.keys(n).length&&(n=void 0),a.abrupt("return",n);case 13:case"end":return a.stop()}},g,this)}return{sum:E,count:C,max:T,min:P,average:D,string:O,substring:z,substringBefore:I,substringAfter:L,lowercase:j,uppercase:R,length:F,trim:B,pad:N,match:V,contains:Y,replace:G,split:Q,join:Z,formatNumber:J,formatBase:tt,number:et,floor:it,ceil:rt,round:st,abs:nt,sqrt:ot,power:at,random:ct,boolean:lt,not:ht,map:ut,zip:gt,filter:pt,single:ft,foldLeft:mt,sift:Dt,keys:yt,lookup:bt,append:vt,exists:_t,spread:xt,merge:wt,reverse:Mt,each:St,error:kt,assert:At,type:Et,sort:Ct,shuffle:Tt,distinct:Pt,base64encode:U,base64decode:W,encodeUrlComponent:X,encodeUrl:q,decodeUrlComponent:K,decodeUrl:$}}();e.exports=o}).call(this)}).call(this,void 0!==Ji?Ji:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils":6}],3:[function(t,e,n){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */r=function(){return e};var t,e={},n=Object.prototype,s=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",l=a.asyncIterator||"@@asyncIterator",h=a.toStringTag||"@@toStringTag";function d(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{d({},"")}catch(t){d=function(t,e,n){return t[e]=n}}function u(t,e,n,i){var r=e&&e.prototype instanceof v?e:v,s=Object.create(r.prototype),a=new O(i||[]);return o(s,"_invoke",{value:C(t,n,a)}),s}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=u;var f="suspendedStart",g="suspendedYield",m="executing",y="completed",b={};function v(){}function _(){}function x(){}var w={};d(w,c,function(){return this});var M=Object.getPrototypeOf,S=M&&M(M(z([])));S&&S!==n&&s.call(S,c)&&(w=S);var k=x.prototype=v.prototype=Object.create(w);function A(t){["next","throw","return"].forEach(function(e){d(t,e,function(t){return this._invoke(e,t)})})}function E(t,e){function n(r,o,a,c){var l=p(t[r],t,o);if("throw"!==l.type){var h=l.arg,d=h.value;return d&&"object"==i(d)&&s.call(d,"__await")?e.resolve(d.__await).then(function(t){n("next",t,a,c)},function(t){n("throw",t,a,c)}):e.resolve(d).then(function(t){h.value=t,a(h)},function(t){return n("throw",t,a,c)})}c(l.arg)}var r;o(this,"_invoke",{value:function(t,i){function s(){return new e(function(e,r){n(t,i,e,r)})}return r=r?r.then(s,s):s()}})}function C(e,n,i){var r=f;return function(s,o){if(r===m)throw new Error("Generator is already running");if(r===y){if("throw"===s)throw o;return{value:t,done:!0}}for(i.method=s,i.arg=o;;){var a=i.delegate;if(a){var c=T(a,i);if(c){if(c===b)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===f)throw r=y,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=m;var l=p(e,n,i);if("normal"===l.type){if(r=i.done?y:g,l.arg===b)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(r=y,i.method="throw",i.arg=l.arg)}}}function T(e,n){var i=n.method,r=e.iterator[i];if(r===t)return n.delegate=null,"throw"===i&&e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),b;var s=p(r,e.iterator,n.arg);if("throw"===s.type)return n.method="throw",n.arg=s.arg,n.delegate=null,b;var o=s.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,b):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,b)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function D(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function z(e){if(e||""===e){var n=e[c];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function n(){for(;++r<e.length;)if(s.call(e,r))return n.value=e[r],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(i(e)+" is not iterable")}return _.prototype=x,o(k,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:_,configurable:!0}),_.displayName=d(x,h,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,d(t,h,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},A(E.prototype),d(E.prototype,l,function(){return this}),e.AsyncIterator=E,e.async=function(t,n,i,r,s){void 0===s&&(s=Promise);var o=new E(u(t,n,i,r),s);return e.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},A(k),d(k,h,"Generator"),d(k,c,function(){return this}),d(k,"toString",function(){return"[object Generator]"}),e.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},e.values=z,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(D),!e)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(i,r){return a.type="throw",a.arg=e,n.next=i,r&&(n.method="next",n.arg=t),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),l=s.call(o,"finallyLoc");if(c&&l){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&s.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=t,o.arg=e,r?(this.method="next",this.next=r.finallyLoc,b):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),D(n),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var r=i.arg;D(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,i){return this.delegate={iterator:z(e),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=t),b}},e}var s=t("./datetime"),o=t("./functions"),a=t("./utils"),c=t("./parser"),l=t("./signature"),h=function(){var t=r().mark(N),e=r().mark(H),n=r().mark(V),h=r().mark(G),d=r().mark(U),u=r().mark(W),p=r().mark(X),f=r().mark(q),g=r().mark(st),m=r().mark(ct),y=r().mark(dt),b=r().mark(ut),v=r().mark(pt),_=r().mark(mt),x=r().mark(vt),w=r().mark(_t),M=r().mark(xt),S=r().mark(wt),k=r().mark(St),A=r().mark(At),E=r().mark(Tt),C=r().mark(Ot),T=a.isNumeric,P=a.isArrayOfStrings,D=a.isArrayOfNumbers,O=a.createSequence,z=a.isSequence,I=a.isFunction,L=a.isLambda,j=a.isIterable,R=a.getFunctionArity,F=a.isDeepEqual,B=It(null);function N(e,n,i){var s,o,a,c;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:(o=i.lookup("__evaluate_entry"))&&o(e,n,i),t.t0=e.type,t.next="path"===t.t0?5:"binary"===t.t0?8:"unary"===t.t0?11:"name"===t.t0?14:"string"===t.t0||"number"===t.t0||"value"===t.t0?16:"wildcard"===t.t0?18:"descendant"===t.t0?20:"parent"===t.t0?22:"condition"===t.t0?24:"block"===t.t0?27:"bind"===t.t0?30:"regex"===t.t0?33:"function"===t.t0?35:"variable"===t.t0?38:"lambda"===t.t0?40:"partial"===t.t0?42:"apply"===t.t0?45:"transform"===t.t0?48:50;break;case 5:return t.delegateYield(H(e,n,i),"t1",6);case 6:return s=t.t1,t.abrupt("break",50);case 8:return t.delegateYield(X(e,n,i),"t2",9);case 9:return s=t.t2,t.abrupt("break",50);case 11:return t.delegateYield(q(e,n,i),"t3",12);case 12:return s=t.t3,t.abrupt("break",50);case 14:return s=K(e,n),t.abrupt("break",50);case 16:return s=$(e),t.abrupt("break",50);case 18:return s=Q(e,n),t.abrupt("break",50);case 20:return s=J(e,n),t.abrupt("break",50);case 22:return s=i.lookup(e.slot.label),t.abrupt("break",50);case 24:return t.delegateYield(ut(e,n,i),"t4",25);case 25:return s=t.t4,t.abrupt("break",50);case 27:return t.delegateYield(pt(e,n,i),"t5",28);case 28:return s=t.t5,t.abrupt("break",50);case 30:return t.delegateYield(dt(e,n,i),"t6",31);case 31:return s=t.t6,t.abrupt("break",50);case 33:return s=ft(e),t.abrupt("break",50);case 35:return t.delegateYield(_t(e,n,i),"t7",36);case 36:return s=t.t7,t.abrupt("break",50);case 38:return s=gt(e,n,i),t.abrupt("break",50);case 40:return s=Mt(e,n,i),t.abrupt("break",50);case 42:return t.delegateYield(St(e,n,i),"t8",43);case 43:return s=t.t8,t.abrupt("break",50);case 45:return t.delegateYield(vt(e,n,i),"t9",46);case 46:return s=t.t9,t.abrupt("break",50);case 48:return s=yt(e,n,i),t.abrupt("break",50);case 50:if(!i.async||null!=s&&"function"==typeof s.then||(s=Promise.resolve(s)),!i.async||"function"!=typeof s.then||!e.nextFunction||"function"!=typeof s[e.nextFunction]){t.next=54;break}t.next=57;break;case 54:return t.next=56,s;case 56:s=t.sent;case 57:if(!Object.prototype.hasOwnProperty.call(e,"predicate")){t.next=65;break}a=0;case 59:if(!(a<e.predicate.length)){t.next=65;break}return t.delegateYield(W(e.predicate[a].expr,s,i),"t10",61);case 61:s=t.t10;case 62:a++,t.next=59;break;case 65:if("path"===e.type||!Object.prototype.hasOwnProperty.call(e,"group")){t.next=68;break}return t.delegateYield(ct(e.group,s,i),"t11",67);case 67:s=t.t11;case 68:return(c=i.lookup("__evaluate_exit"))&&c(e,n,i,s),s&&z(s)&&!s.tupleStream&&(e.keepArray&&(s.keepSingleton=!0),0===s.length?s=void 0:1===s.length&&(s=s.keepSingleton?s:s[0])),t.abrupt("return",s);case 72:case"end":return t.stop()}},t)}function H(t,n,i){var s,o,a,c,l,h;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:s=Array.isArray(n)&&"variable"!==t.steps[0].type?n:O(n),a=!1,c=void 0,l=0;case 4:if(!(l<t.steps.length)){e.next=25;break}if((h=t.steps[l]).tuple&&(a=!0),0!==l||!h.consarray){e.next=12;break}return e.delegateYield(N(h,s,i),"t0",9);case 9:o=e.t0,e.next=19;break;case 12:if(!a){e.next=17;break}return e.delegateYield(U(h,s,c,i),"t1",14);case 14:c=e.t1,e.next=19;break;case 17:return e.delegateYield(V(h,s,i,l===t.steps.length-1),"t2",18);case 18:o=e.t2;case 19:if(a||void 0!==o&&0!==o.length){e.next=21;break}return e.abrupt("break",25);case 21:void 0===h.focus&&(s=o);case 22:l++,e.next=4;break;case 25:if(a)if(t.tuple)o=c;else for(o=O(),l=0;l<c.length;l++)o.push(c[l]["@"]);if(t.keepSingletonArray&&(Array.isArray(o)&&o.cons&&!o.sequence&&(o=O(o)),o.keepSingleton=!0),!t.hasOwnProperty("group")){e.next=30;break}return e.delegateYield(ct(t.group,a?c:o,i),"t3",29);case 29:o=e.t3;case 30:return e.abrupt("return",o);case 31:case"end":return e.stop()}},e)}function Y(t,e){var n=It(t);for(var i in e)n.bind(i,e[i]);return n}function V(t,e,i,s){var o,a,c,l,h;return r().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if("sort"!==t.type){n.next=7;break}return n.delegateYield(mt(t,e,i),"t0",2);case 2:if(o=n.t0,!t.stages){n.next=6;break}return n.delegateYield(G(t.stages,o,i),"t1",5);case 5:o=n.t1;case 6:return n.abrupt("return",o);case 7:o=O(),a=0;case 9:if(!(a<e.length)){n.next=24;break}return n.delegateYield(N(t,e[a],i),"t2",11);case 11:if(c=n.t2,!t.stages){n.next=20;break}l=0;case 14:if(!(l<t.stages.length)){n.next=20;break}return n.delegateYield(W(t.stages[l].expr,c,i),"t3",16);case 16:c=n.t3;case 17:l++,n.next=14;break;case 20:void 0!==c&&o.push(c);case 21:a++,n.next=9;break;case 24:return h=O(),s&&1===o.length&&Array.isArray(o[0])&&!z(o[0])?h=o[0]:o.forEach(function(t){!Array.isArray(t)||t.cons?h.push(t):t.forEach(function(t){return h.push(t)})}),n.abrupt("return",h);case 27:case"end":return n.stop()}},n)}function G(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:i=e,s=0;case 2:if(!(s<t.length)){r.next=15;break}o=t[s],r.t0=o.type,r.next="filter"===r.t0?7:"index"===r.t0?10:12;break;case 7:return r.delegateYield(W(o.expr,i,n),"t1",8);case 8:return i=r.t1,r.abrupt("break",12);case 10:for(a=0;a<i.length;a++)i[a][o.value]=a;return r.abrupt("break",12);case 12:s++,r.next=2;break;case 15:return r.abrupt("return",i);case 16:case"end":return r.stop()}},h)}function U(t,e,n,i){var s,o,a,c,l,h,u,p;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if("sort"!==t.type){r.next=15;break}if(!n){r.next=6;break}return r.delegateYield(mt(t,n,i),"t0",3);case 3:s=r.t0,r.next=11;break;case 6:return r.delegateYield(mt(t,e,i),"t1",7);case 7:for(o=r.t1,(s=O()).tupleStream=!0,a=0;a<o.length;a++)(c={"@":o[a]})[t.index]=a,s.push(c);case 11:if(!t.stages){r.next=14;break}return r.delegateYield(G(t.stages,s,i),"t2",13);case 13:s=r.t2;case 14:return r.abrupt("return",s);case 15:(s=O()).tupleStream=!0,l=i,void 0===n&&(n=e.map(function(t){return{"@":t}})),h=0;case 20:if(!(h<n.length)){r.next=28;break}return l=Y(i,n[h]),r.delegateYield(N(t,n[h]["@"],l),"t3",23);case 23:if(void 0!==(u=r.t3))for(Array.isArray(u)||(u=[u]),p=0;p<u.length;p++)c={},Object.assign(c,n[h]),u.tupleStream?Object.assign(c,u[p]):(t.focus?(c[t.focus]=u[p],c["@"]=n[h]["@"]):c["@"]=u[p],t.index&&(c[t.index]=p),t.ancestor&&(c[t.ancestor.label]=n[h]["@"])),s.push(c);case 25:h++,r.next=20;break;case 28:if(!t.stages){r.next=31;break}return r.delegateYield(G(t.stages,s,i),"t4",30);case 30:s=r.t4;case 31:return r.abrupt("return",s);case 32:case"end":return r.stop()}},d)}function W(t,e,n){var i,s,a,c,l,h;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(i=O(),e&&e.tupleStream&&(i.tupleStream=!0),Array.isArray(e)||(e=O(e)),"number"!==t.type){r.next=10;break}(s=Math.floor(t.value))<0&&(s=e.length+s),void 0!==(a=e[s])&&(Array.isArray(a)?i=a:i.push(a)),r.next=23;break;case 10:s=0;case 11:if(!(s<e.length)){r.next=23;break}return a=e[s],c=a,l=n,e.tupleStream&&(c=a["@"],l=Y(n,a)),r.delegateYield(N(t,c,l),"t0",17);case 17:h=r.t0,T(h)&&(h=[h]),D(h)?h.forEach(function(t){var n=Math.floor(t);n<0&&(n=e.length+n),n===s&&i.push(a)}):o.boolean(h)&&i.push(a);case 20:s++,r.next=11;break;case 23:return r.abrupt("return",i);case 24:case"end":return r.stop()}},u)}function X(t,e,n){var i,s,o,a,c;return r().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:return l.delegateYield(N(t.lhs,e,n),"t0",1);case 1:if(s=l.t0,o=t.value,a=r().mark(function i(){return r().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.rhs,e,n),"t0",1);case 1:return i.abrupt("return",i.t0);case 2:case"end":return i.stop()}},i)}),"and"!==o&&"or"!==o){l.next=15;break}return l.prev=5,l.delegateYield(st(s,a,o),"t1",7);case 7:return l.abrupt("return",l.t1);case 10:throw l.prev=10,l.t2=l.catch(5),l.t2.position=t.position,l.t2.token=o,l.t2;case 15:return l.delegateYield(a(),"t3",16);case 16:c=l.t3,l.prev=17,l.t4=o,l.next="+"===l.t4||"-"===l.t4||"*"===l.t4||"/"===l.t4||"%"===l.t4?21:"="===l.t4||"!="===l.t4?23:"<"===l.t4||"<="===l.t4||">"===l.t4||">="===l.t4?25:"&"===l.t4?27:".."===l.t4?29:"in"===l.t4?31:33;break;case 21:return i=et(s,c,o),l.abrupt("break",33);case 23:return i=nt(s,c,o),l.abrupt("break",33);case 25:return i=it(s,c,o),l.abrupt("break",33);case 27:return i=at(s,c),l.abrupt("break",33);case 29:return i=ht(s,c),l.abrupt("break",33);case 31:return i=rt(s,c),l.abrupt("break",33);case 33:l.next=40;break;case 35:throw l.prev=35,l.t5=l.catch(17),l.t5.position=t.position,l.t5.token=o,l.t5;case 40:return l.abrupt("return",i);case 41:case"end":return l.stop()}},p,null,[[5,10],[17,35]])}function q(t,e,n){var i,s,a,c;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:r.t0=t.value,r.next="-"===r.t0?3:"["===r.t0?15:"{"===r.t0?27:30;break;case 3:return r.delegateYield(N(t.expression,e,n),"t1",4);case 4:if(void 0!==(i=r.t1)){r.next=9;break}i=void 0,r.next=14;break;case 9:if(!T(i)){r.next=13;break}i=-i,r.next=14;break;case 13:throw{code:"D1002",stack:(new Error).stack,position:t.position,token:t.value,value:i};case 14:return r.abrupt("break",30);case 15:i=[],s=0;case 17:if(!(s<t.expressions.length)){r.next=25;break}return a=t.expressions[s],r.delegateYield(N(a,e,n),"t2",20);case 20:void 0!==(c=r.t2)&&("["===a.value?i.push(c):i=o.append(i,c));case 22:s++,r.next=17;break;case 25:return t.consarray&&Object.defineProperty(i,"cons",{enumerable:!1,configurable:!1,value:!0}),r.abrupt("break",30);case 27:return r.delegateYield(ct(t,e,n),"t3",28);case 28:return i=r.t3,r.abrupt("break",30);case 30:return r.abrupt("return",i);case 31:case"end":return r.stop()}},f)}function K(t,e,n){return o.lookup(e,t.value)}function $(t){return t.value}function Q(t,e){var n=O();return Array.isArray(e)&&e.outerWrapper&&e.length>0&&(e=e[0]),null!==e&&"object"===i(e)&&Object.keys(e).forEach(function(t){var i=e[t];Array.isArray(i)?(i=Z(i),n=o.append(n,i)):n.push(i)}),n}function Z(t,e){return void 0===e&&(e=[]),Array.isArray(t)?t.forEach(function(t){Z(t,e)}):e.push(t),e}function J(t,e){var n,i=O();return void 0!==e&&(tt(e,i),n=1===i.length?i[0]:i),n}function tt(t,e){Array.isArray(t)||e.push(t),Array.isArray(t)?t.forEach(function(t){tt(t,e)}):null!==t&&"object"===i(t)&&Object.keys(t).forEach(function(n){tt(t[n],e)})}function et(t,e,n){var i;if(void 0!==t&&!T(t))throw{code:"T2001",stack:(new Error).stack,value:t};if(void 0!==e&&!T(e))throw{code:"T2002",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return i;switch(n){case"+":i=t+e;break;case"-":i=t-e;break;case"*":i=t*e;break;case"/":i=t/e;break;case"%":i=t%e}return i}function nt(t,e,n){var r,s=i(t),o=i(e);if("undefined"===s||"undefined"===o)return!1;switch(n){case"=":r=F(t,e);break;case"!=":r=!F(t,e)}return r}function it(t,e,n){var r,s=i(t),o=i(e);if("undefined"!==s&&"string"!==s&&"number"!==s||"undefined"!==o&&"string"!==o&&"number"!==o)throw{code:"T2010",stack:(new Error).stack,value:"string"!==s&&"number"!==s?t:e};if("undefined"!==s&&"undefined"!==o){if(s!==o)throw{code:"T2009",stack:(new Error).stack,value:t,value2:e};switch(n){case"<":r=t<e;break;case"<=":r=t<=e;break;case">":r=t>e;break;case">=":r=t>=e}return r}}function rt(t,e){var n=!1;if(void 0===t||void 0===e)return!1;Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)if(e[i]===t){n=!0;break}return n}function st(t,e,n){var i,s;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:s=ot(t),r.t0=n,r.next="and"===r.t0?4:"or"===r.t0?12:20;break;case 4:if(r.t1=s,!r.t1){r.next=10;break}return r.t2=ot,r.delegateYield(e(),"t3",8);case 8:r.t4=r.t3,r.t1=(0,r.t2)(r.t4);case 10:return i=r.t1,r.abrupt("break",20);case 12:if(r.t5=s,r.t5){r.next=18;break}return r.t6=ot,r.delegateYield(e(),"t7",16);case 16:r.t8=r.t7,r.t5=(0,r.t6)(r.t8);case 18:return i=r.t5,r.abrupt("break",20);case 20:return r.abrupt("return",i);case 21:case"end":return r.stop()}},g)}function ot(t){var e=o.boolean(t);return void 0!==e&&e}function at(t,e){var n="",i="";return void 0!==t&&(n=o.string(t)),void 0!==e&&(i=o.string(e)),n.concat(i)}function ct(t,e,n){var i,s,a,c,l,h,d,u,p,f,g,y,b;return r().wrap(function(m){for(;;)switch(m.prev=m.next){case 0:i={},s={},a=!(!e||!e.tupleStream),Array.isArray(e)||(e=O(e)),0===e.length&&e.push(void 0),c=0;case 6:if(!(c<e.length)){m.next=31;break}l=e[c],h=a?Y(n,l):n,d=0;case 10:if(!(d<t.lhs.length)){m.next=28;break}return u=t.lhs[d],m.delegateYield(N(u[0],a?l["@"]:l,h),"t0",13);case 13:if("string"==typeof(p=m.t0)||void 0===p){m.next=16;break}throw{code:"T1003",stack:(new Error).stack,position:t.position,value:p};case 16:if(void 0===p){m.next=25;break}if(f={data:l,exprIndex:d},!s.hasOwnProperty(p)){m.next=24;break}if(s[p].exprIndex===d){m.next=21;break}throw{code:"D1009",stack:(new Error).stack,position:t.position,value:p};case 21:s[p].data=o.append(s[p].data,l),m.next=25;break;case 24:s[p]=f;case 25:d++,m.next=10;break;case 28:c++,m.next=6;break;case 31:m.t1=r().keys(s);case 32:if((m.t2=m.t1()).done){m.next=43;break}return p=m.t2.value,f=s[p],g=f.data,h=n,a&&(y=lt(f.data),g=y["@"],delete y["@"],h=Y(n,y)),m.delegateYield(N(t.lhs[f.exprIndex][1],g,h),"t3",39);case 39:void 0!==(b=m.t3)&&(i[p]=b),m.next=32;break;case 43:return m.abrupt("return",i);case 44:case"end":return m.stop()}},m)}function lt(t){if(!Array.isArray(t))return t;var e={};Object.assign(e,t[0]);for(var n=1;n<t.length;n++)for(var i in t[n])e[i]=o.append(e[i],t[n][i]);return e}function ht(t,e){var n;if(void 0!==t&&!Number.isInteger(t))throw{code:"T2003",stack:(new Error).stack,value:t};if(void 0!==e&&!Number.isInteger(e))throw{code:"T2004",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return n;if(t>e)return n;var i=e-t+1;if(i>1e7)throw{code:"D2014",stack:(new Error).stack,value:i};n=new Array(i);for(var r=t,s=0;r<=e;r++,s++)n[s]=r;return n.sequence=!0,n}function dt(t,e,n){var i;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.rhs,e,n),"t0",1);case 1:return i=r.t0,n.bind(t.lhs.value,i),r.abrupt("return",i);case 4:case"end":return r.stop()}},y)}function ut(t,e,n){var i,s;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.condition,e,n),"t0",1);case 1:if(s=r.t0,!o.boolean(s)){r.next=7;break}return r.delegateYield(N(t.then,e,n),"t1",4);case 4:i=r.t1,r.next=10;break;case 7:if(void 0===t.else){r.next=10;break}return r.delegateYield(N(t.else,e,n),"t2",9);case 9:i=r.t2;case 10:return r.abrupt("return",i);case 11:case"end":return r.stop()}},b)}function pt(t,e,n){var i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:s=It(n),o=0;case 2:if(!(o<t.expressions.length)){r.next=8;break}return r.delegateYield(N(t.expressions[o],e,s),"t0",4);case 4:i=r.t0;case 5:o++,r.next=2;break;case 8:return r.abrupt("return",i);case 9:case"end":return r.stop()}},v)}function ft(t){var e=new Rt.RegexEngine(t.value),n=function n(i,r){var s;e.lastIndex=r||0;var o=e.exec(i);if(null!==o){if(s={match:o[0],start:o.index,end:o.index+o[0].length,groups:[]},o.length>1)for(var a=1;a<o.length;a++)s.groups.push(o[a]);s.next=function(){if(!(e.lastIndex>=i.length)){var r=n(i,e.lastIndex);if(r&&""===r.match)throw{code:"D1004",stack:(new Error).stack,position:t.position,value:t.value.source};return r}}}return s};return n}function gt(t,e,n){return""===t.value?e&&e.outerWrapper?e[0]:e:n.lookup(t.value)}function mt(t,e,n){var s,a,c,l,h;return r().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return a=e,c=!!e.tupleStream,l=r().mark(function e(s,o){var a,l,h,d,u,p,f,g,m;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:a=0,l=0;case 2:if(!(0===a&&l<t.terms.length)){e.next=35;break}return h=t.terms[l],d=s,u=n,c&&(d=s["@"],u=Y(n,s)),e.delegateYield(N(h.expression,d,u),"t0",8);case 8:return p=e.t0,d=o,u=n,c&&(d=o["@"],u=Y(n,o)),e.delegateYield(N(h.expression,d,u),"t1",13);case 13:if(f=e.t1,g=i(p),m=i(f),"undefined"!==g){e.next=19;break}return a="undefined"===m?0:1,e.abrupt("continue",32);case 19:if("undefined"!==m){e.next=22;break}return a=-1,e.abrupt("continue",32);case 22:if(!("string"!==g&&"number"!==g||"string"!==m&&"number"!==m)){e.next=24;break}throw{code:"T2008",stack:(new Error).stack,position:t.position,value:"string"!==g&&"number"!==g?p:f};case 24:if(g===m){e.next=26;break}throw{code:"T2007",stack:(new Error).stack,position:t.position,value:p,value2:f};case 26:if(p!==f){e.next=30;break}return e.abrupt("continue",32);case 30:a=p<f?-1:1;case 31:!0===h.descending&&(a=-a);case 32:l++,e.next=2;break;case 35:return e.abrupt("return",1===a);case 36:case"end":return e.stop()}},e)}),h={environment:n,input:e},d.delegateYield(o.sort.apply(h,[a,l]),"t0",5);case 5:return s=d.t0,d.abrupt("return",s);case 7:case"end":return d.stop()}},_)}function yt(t,e,n){var s=r().mark(function e(s){var o,a,c,l,h,d,u,p,f,g,m;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==s){e.next=2;break}return e.abrupt("return",void 0);case 2:if(o=n.lookup("clone"),I(o)){e.next=5;break}throw{code:"T2013",stack:(new Error).stack,position:t.position};case 5:return e.delegateYield(xt(o,[s],null,n),"t0",6);case 6:return a=e.t0,e.delegateYield(N(t.pattern,a,n),"t1",8);case 8:if(void 0===(c=e.t1)){e.next=35;break}Array.isArray(c)||(c=[c]),l=0;case 12:if(!(l<c.length)){e.next=35;break}if(!(h=c[l])||!(h.isPrototypeOf(a)||h instanceof Object.constructor)){e.next=16;break}throw{code:"D1010",stack:(new Error).stack,position:t.position};case 16:return e.delegateYield(N(t.update,h,n),"t2",17);case 17:if(d=e.t2,"undefined"===(u=i(d))){e.next=23;break}if("object"===u&&null!==d&&!Array.isArray(d)){e.next=22;break}throw{code:"T2011",stack:(new Error).stack,position:t.update.position,value:d};case 22:for(p in d)h[p]=d[p];case 23:if(void 0===t.delete){e.next=32;break}return e.delegateYield(N(t.delete,h,n),"t3",25);case 25:if(void 0===(f=e.t3)){e.next=32;break}if(g=f,Array.isArray(f)||(f=[f]),P(f)){e.next=31;break}throw{code:"T2012",stack:(new Error).stack,position:t.delete.position,value:g};case 31:for(m=0;m<f.length;m++)"object"===i(h)&&null!==h&&delete h[f[m]];case 32:l++,e.next=12;break;case 35:return e.abrupt("return",a);case 36:case"end":return e.stop()}},e)});return Dt(s,"<(oa):o>")}var bt=c("function($f, $g) { function($x){ $g($f($x)) } }");function vt(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.lhs,e,n),"t0",1);case 1:if(s=r.t0,"function"!==t.rhs.type){r.next=7;break}return r.delegateYield(_t(t.rhs,e,n,{context:s}),"t1",4);case 4:i=r.t1,r.next=20;break;case 7:return r.delegateYield(N(t.rhs,e,n),"t2",8);case 8:if(o=r.t2,I(o)){r.next=11;break}throw{code:"T2006",stack:(new Error).stack,position:t.position,value:o};case 11:if(!I(s)){r.next=18;break}return r.delegateYield(N(bt,null,n),"t3",13);case 13:return a=r.t3,r.delegateYield(xt(a,[s,o],null,n),"t4",15);case 15:i=r.t4,r.next=20;break;case 18:return r.delegateYield(xt(o,[s],null,n),"t5",19);case 19:i=r.t5;case 20:return r.abrupt("return",i);case 21:case"end":return r.stop()}},x)}function _t(t,e,n,s){var o,a,c,l,h,d;return r().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.delegateYield(N(t.procedure,e,n),"t0",1);case 1:if(void 0!==(a=u.t0)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){u.next=4;break}throw{code:"T1005",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 4:c=[],void 0!==s&&c.push(s.context),l=r().mark(function i(){var s,o;return r().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.arguments[h],e,n),"t0",1);case 1:s=i.t0,I(s)?(o=r().mark(function t(){var e,i,o,a=arguments;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(e=a.length,i=new Array(e),o=0;o<e;o++)i[o]=a[o];return t.delegateYield(xt(s,i,null,n),"t0",2);case 2:return t.abrupt("return",t.t0);case 3:case"end":return t.stop()}},t)}),o.arity=R(s),c.push(o)):c.push(s);case 3:case"end":return i.stop()}},i)}),h=0;case 8:if(!(h<t.arguments.length)){u.next=13;break}return u.delegateYield(l(),"t1",10);case 10:h++,u.next=8;break;case 13:return d="path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value,u.prev=14,"object"===i(a)&&(a.token=d,a.position=t.position),u.delegateYield(xt(a,c,e,n),"t2",17);case 17:o=u.t2,u.next=25;break;case 20:throw u.prev=20,u.t3=u.catch(14),u.t3.position||(u.t3.position=t.position),u.t3.token||(u.t3.token=d),u.t3;case 25:return u.abrupt("return",o);case 26:case"end":return u.stop()}},w,null,[[14,20]])}function xt(t,e,n,i){var s,o,a,c;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(wt(t,e,n,i),"t0",1);case 1:s=r.t0;case 2:if(!L(s)||!0!==s.thunk){r.next=21;break}return r.delegateYield(N(s.body.procedure,s.input,s.environment),"t1",4);case 4:o=r.t1,"variable"===s.body.procedure.type&&(o.token=s.body.procedure.value),o.position=s.body.procedure.position,a=[],c=0;case 9:if(!(c<s.body.arguments.length)){r.next=17;break}return r.t2=a,r.delegateYield(N(s.body.arguments[c],s.input,s.environment),"t3",12);case 12:r.t4=r.t3,r.t2.push.call(r.t2,r.t4);case 14:c++,r.next=9;break;case 17:return r.delegateYield(wt(o,a,n,i),"t5",18);case 18:s=r.t5,r.next=2;break;case 21:return r.abrupt("return",s);case 22:case"end":return r.stop()}},M)}function wt(t,e,n,i){var s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(r.prev=0,o=e,t&&(o=kt(t.signature,e,n)),!L(t)){r.next=8;break}return r.delegateYield(At(t,o),"t0",5);case 5:s=r.t0,r.next=24;break;case 8:if(!t||!0!==t._jsonata_function){r.next=16;break}if(a={environment:i,input:n},s=t.implementation.apply(a,o),!j(s)){r.next=14;break}return r.delegateYield(s,"t1",13);case 13:s=r.t1;case 14:r.next=24;break;case 16:if("function"!=typeof t){r.next=23;break}if(s=t.apply(n,o),!j(s)){r.next=21;break}return r.delegateYield(s,"t2",20);case 20:s=r.t2;case 21:r.next=24;break;case 23:throw{code:"T1006",stack:(new Error).stack};case 24:r.next=30;break;case 26:throw r.prev=26,r.t3=r.catch(0),t&&(void 0===r.t3.token&&void 0!==t.token&&(r.t3.token=t.token),r.t3.position=t.position||r.t3.position),r.t3;case 30:return r.abrupt("return",s);case 31:case"end":return r.stop()}},S,null,[[0,26]])}function Mt(t,e,n){var i={_jsonata_lambda:!0,input:e,environment:n,arguments:t.arguments,signature:t.signature,body:t.body};return!0===t.thunk&&(i.thunk=!0),i.apply=r().mark(function t(n,s){return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(xt(i,s,e,n.environment),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},t)}),i}function St(t,e,n){var i,s,o,a,c;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:s=[],o=0;case 2:if(!(o<t.arguments.length)){r.next=15;break}if("operator"!==(a=t.arguments[o]).type||"?"!==a.value){r.next=8;break}s.push(a),r.next=12;break;case 8:return r.t0=s,r.delegateYield(N(a,e,n),"t1",10);case 10:r.t2=r.t1,r.t0.push.call(r.t0,r.t2);case 12:o++,r.next=2;break;case 15:return r.delegateYield(N(t.procedure,e,n),"t3",16);case 16:if(void 0!==(c=r.t3)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){r.next=19;break}throw{code:"T1007",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 19:if(!L(c)){r.next=23;break}i=Et(c,s),r.next=32;break;case 23:if(!c||!0!==c._jsonata_function){r.next=27;break}i=Ct(c.implementation,s),r.next=32;break;case 27:if("function"!=typeof c){r.next=31;break}i=Ct(c,s),r.next=32;break;case 31:throw{code:"T1008",stack:(new Error).stack,position:t.position,token:"path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value};case 32:return r.abrupt("return",i);case 33:case"end":return r.stop()}},k)}function kt(t,e,n){return void 0===t?e:t.validate(e,n)}function At(t,e){var n,i;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(i=It(t.environment),t.arguments.forEach(function(t,n){i.bind(t.value,e[n])}),"function"!=typeof t.body){r.next=7;break}return r.delegateYield(Tt(t.body,i),"t0",4);case 4:n=r.t0,r.next=9;break;case 7:return r.delegateYield(N(t.body,t.input,i),"t1",8);case 8:n=r.t1;case 9:return r.abrupt("return",n);case 10:case"end":return r.stop()}},A)}function Et(t,e){var n=It(t.environment),i=[];return t.arguments.forEach(function(t,r){var s=e[r];s&&"operator"===s.type&&"?"===s.value?i.push(t):n.bind(t.value,s)}),{_jsonata_lambda:!0,input:t.input,environment:n,arguments:i,body:t.body}}function Ct(t,e){var n=Pt(t),i="function("+(n=n.map(function(t){return"$"+t.trim()})).join(", ")+"){ _ }",r=c(i);return r.body=t,Et(r,e)}function Tt(t,e){var n,i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(n=Pt(t),i=n.map(function(t){return e.lookup(t.trim())}),s={environment:e},o=t.apply(s,i),!j(o)){r.next=7;break}return r.delegateYield(o,"t0",6);case 6:o=r.t0;case 7:return r.abrupt("return",o);case 8:case"end":return r.stop()}},E)}function Pt(t){var e=t.toString();return/\(([^)]*)\)/.exec(e)[1].split(",")}function Dt(t,e){var n={_jsonata_function:!0,implementation:t};return void 0!==e&&(n.signature=l(e)),n}function Ot(t,e){var n,i,s;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=this.input,void 0!==e&&(n=e,Array.isArray(n)&&!z(n)&&((n=O(n)).outerWrapper=!0)),r.prev=4,i=c(t,!1),r.next=12;break;case 8:throw r.prev=8,r.t0=r.catch(4),jt(r.t0),{stack:(new Error).stack,code:"D3120",value:r.t0.message,error:r.t0};case 12:return r.prev=12,r.delegateYield(N(i,n,this.environment),"t1",14);case 14:s=r.t1,r.next=21;break;case 17:throw r.prev=17,r.t2=r.catch(12),jt(r.t2),{stack:(new Error).stack,code:"D3121",value:r.t2.message,error:r.t2};case 21:return r.abrupt("return",s);case 22:case"end":return r.stop()}},C,this,[[4,8],[12,17]])}function zt(t){if(void 0!==t)return JSON.parse(o.string(t))}function It(t){var e={};return{bind:function(t,n){e[t]=n},lookup:function(n){var i;return e.hasOwnProperty(n)?i=e[n]:t&&(i=t.lookup(n)),i},timestamp:t?t.timestamp:null,async:!!t&&t.async,global:t?t.global:{ancestry:[null]}}}B.bind("sum",Dt(o.sum,"<a<n>:n>")),B.bind("count",Dt(o.count,"<a:n>")),B.bind("max",Dt(o.max,"<a<n>:n>")),B.bind("min",Dt(o.min,"<a<n>:n>")),B.bind("average",Dt(o.average,"<a<n>:n>")),B.bind("string",Dt(o.string,"<x-b?:s>")),B.bind("substring",Dt(o.substring,"<s-nn?:s>")),B.bind("substringBefore",Dt(o.substringBefore,"<s-s:s>")),B.bind("substringAfter",Dt(o.substringAfter,"<s-s:s>")),B.bind("lowercase",Dt(o.lowercase,"<s-:s>")),B.bind("uppercase",Dt(o.uppercase,"<s-:s>")),B.bind("length",Dt(o.length,"<s-:n>")),B.bind("trim",Dt(o.trim,"<s-:s>")),B.bind("pad",Dt(o.pad,"<s-ns?:s>")),B.bind("match",Dt(o.match,"<s-f<s:o>n?:a<o>>")),B.bind("contains",Dt(o.contains,"<s-(sf):b>")),B.bind("replace",Dt(o.replace,"<s-(sf)(sf)n?:s>")),B.bind("split",Dt(o.split,"<s-(sf)n?:a<s>>")),B.bind("join",Dt(o.join,"<a<s>s?:s>")),B.bind("formatNumber",Dt(o.formatNumber,"<n-so?:s>")),B.bind("formatBase",Dt(o.formatBase,"<n-n?:s>")),B.bind("formatInteger",Dt(s.formatInteger,"<n-s:s>")),B.bind("parseInteger",Dt(s.parseInteger,"<s-s:n>")),B.bind("number",Dt(o.number,"<(nsb)-:n>")),B.bind("floor",Dt(o.floor,"<n-:n>")),B.bind("ceil",Dt(o.ceil,"<n-:n>")),B.bind("round",Dt(o.round,"<n-n?:n>")),B.bind("abs",Dt(o.abs,"<n-:n>")),B.bind("sqrt",Dt(o.sqrt,"<n-:n>")),B.bind("power",Dt(o.power,"<n-n:n>")),B.bind("random",Dt(o.random,"<:n>")),B.bind("boolean",Dt(o.boolean,"<x-:b>")),B.bind("not",Dt(o.not,"<x-:b>")),B.bind("map",Dt(o.map,"<af>")),B.bind("zip",Dt(o.zip,"<a+>")),B.bind("filter",Dt(o.filter,"<af>")),B.bind("single",Dt(o.single,"<af?>")),B.bind("reduce",Dt(o.foldLeft,"<afj?:j>")),B.bind("sift",Dt(o.sift,"<o-f?:o>")),B.bind("keys",Dt(o.keys,"<x-:a<s>>")),B.bind("lookup",Dt(o.lookup,"<x-s:x>")),B.bind("append",Dt(o.append,"<xx:a>")),B.bind("exists",Dt(o.exists,"<x:b>")),B.bind("spread",Dt(o.spread,"<x-:a<o>>")),B.bind("merge",Dt(o.merge,"<a<o>:o>")),B.bind("reverse",Dt(o.reverse,"<a:a>")),B.bind("each",Dt(o.each,"<o-f:a>")),B.bind("error",Dt(o.error,"<s?:x>")),B.bind("assert",Dt(o.assert,"<bs?:x>")),B.bind("type",Dt(o.type,"<x:s>")),B.bind("sort",Dt(o.sort,"<af?:a>")),B.bind("shuffle",Dt(o.shuffle,"<a:a>")),B.bind("distinct",Dt(o.distinct,"<x:x>")),B.bind("base64encode",Dt(o.base64encode,"<s-:s>")),B.bind("base64decode",Dt(o.base64decode,"<s-:s>")),B.bind("encodeUrlComponent",Dt(o.encodeUrlComponent,"<s-:s>")),B.bind("encodeUrl",Dt(o.encodeUrl,"<s-:s>")),B.bind("decodeUrlComponent",Dt(o.decodeUrlComponent,"<s-:s>")),B.bind("decodeUrl",Dt(o.decodeUrl,"<s-:s>")),B.bind("eval",Dt(Ot,"<sx?:x>")),B.bind("toMillis",Dt(s.toMillis,"<s-s?:n>")),B.bind("fromMillis",Dt(s.fromMillis,"<n-s?s?:s>")),B.bind("clone",Dt(zt,"<(oa)-:o>"));var Lt={S0101:"String literal must be terminated by a matching quote",S0102:"Number out of range: {{token}}",S0103:"Unsupported escape sequence: \\{{token}}",S0104:"The escape sequence \\u must be followed by 4 hex digits",S0105:"Quoted property name must be terminated with a backquote (`)",S0106:"Comment has no closing tag",S0201:"Syntax error: {{token}}",S0202:"Expected {{value}}, got {{token}}",S0203:"Expected {{value}} before end of expression",S0204:"Unknown operator: {{token}}",S0205:"Unexpected token: {{token}}",S0206:"Unknown expression type: {{token}}",S0207:"Unexpected end of expression",S0208:"Parameter {{value}} of function definition must be a variable name (start with $)",S0209:"A predicate cannot follow a grouping expression in a step",S0210:"Each step can only have one grouping expression",S0211:"The symbol {{token}} cannot be used as a unary operator",S0212:"The left side of := must be a variable name (start with $)",S0213:"The literal value {{value}} cannot be used as a step within a path expression",S0214:"The right side of {{token}} must be a variable name (start with $)",S0215:"A context variable binding must precede any predicates on a step",S0216:"A context variable binding must precede the 'order-by' clause on a step",S0217:"The object representing the 'parent' cannot be derived from this expression",S0301:"Empty regular expressions are not allowed",S0302:"No terminating / in regular expression",S0402:"Choice groups containing parameterized types are not supported",S0401:"Type parameters can only be applied to functions and arrays",S0500:"Attempted to evaluate an expression containing syntax error(s)",T0410:"Argument {{index}} of function {{token}} does not match function signature",T0411:"Context value is not a compatible type with argument {{index}} of function {{token}}",T0412:"Argument {{index}} of function {{token}} must be an array of {{type}}",D1001:"Number out of range: {{value}}",D1002:"Cannot negate a non-numeric value: {{value}}",T1003:"Key in object structure must evaluate to a string; got: {{value}}",D1004:"Regular expression matches zero length string",T1005:"Attempted to invoke a non-function. Did you mean ${{{token}}}?",T1006:"Attempted to invoke a non-function",T1007:"Attempted to partially apply a non-function. Did you mean ${{{token}}}?",T1008:"Attempted to partially apply a non-function",D1009:"Multiple key definitions evaluate to same key: {{value}}",D1010:"Attempted to access the Javascript object prototype",T1010:"The matcher function argument passed to function {{token}} does not return the correct object structure",T2001:"The left side of the {{token}} operator must evaluate to a number",T2002:"The right side of the {{token}} operator must evaluate to a number",T2003:"The left side of the range operator (..) must evaluate to an integer",T2004:"The right side of the range operator (..) must evaluate to an integer",D2005:"The left side of := must be a variable name (start with $)",T2006:"The right side of the function application operator ~> must be a function",T2007:"Type mismatch when comparing values {{value}} and {{value2}} in order-by clause",T2008:"The expressions within an order-by clause must evaluate to numeric or string values",T2009:"The values {{value}} and {{value2}} either side of operator {{token}} must be of the same data type",T2010:"The expressions either side of operator {{token}} must evaluate to numeric or string values",T2011:"The insert/update clause of the transform expression must evaluate to an object: {{value}}",T2012:"The delete clause of the transform expression must evaluate to a string or array of strings: {{value}}",T2013:"The transform expression clones the input object using the $clone() function. This has been overridden in the current scope by a non-function.",D2014:"The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate {{value}}.",D3001:"Attempting to invoke string function on Infinity or NaN",D3010:"Second argument of replace function cannot be an empty string",D3011:"Fourth argument of replace function must evaluate to a positive number",D3012:"Attempted to replace a matched string with a non-string value",D3020:"Third argument of split function must evaluate to a positive number",D3030:"Unable to cast value to a number: {{value}}",D3040:"Third argument of match function must evaluate to a positive number",D3050:"The second argument of reduce function must be a function with at least two arguments",D3060:"The sqrt function cannot be applied to a negative number: {{value}}",D3061:"The power function has resulted in a value that cannot be represented as a JSON number: base={{value}}, exponent={{exp}}",D3070:"The single argument form of the sort function can only be applied to an array of strings or an array of numbers. Use the second argument to specify a comparison function",D3080:"The picture string must only contain a maximum of two sub-pictures",D3081:"The sub-picture must not contain more than one instance of the 'decimal-separator' character",D3082:"The sub-picture must not contain more than one instance of the 'percent' character",D3083:"The sub-picture must not contain more than one instance of the 'per-mille' character",D3084:"The sub-picture must not contain both a 'percent' and a 'per-mille' character",D3085:"The mantissa part of a sub-picture must contain at least one character that is either an 'optional digit character' or a member of the 'decimal digit family'",D3086:"The sub-picture must not contain a passive character that is preceded by an active character and that is followed by another active character",D3087:"The sub-picture must not contain a 'grouping-separator' character that appears adjacent to a 'decimal-separator' character",D3088:"The sub-picture must not contain a 'grouping-separator' at the end of the integer part",D3089:"The sub-picture must not contain two adjacent instances of the 'grouping-separator' character",D3090:"The integer part of the sub-picture must not contain a member of the 'decimal digit family' that is followed by an instance of the 'optional digit character'",D3091:"The fractional part of the sub-picture must not contain an instance of the 'optional digit character' that is followed by a member of the 'decimal digit family'",D3092:"A sub-picture that contains a 'percent' or 'per-mille' character must not contain a character treated as an 'exponent-separator'",D3093:"The exponent part of the sub-picture must comprise only of one or more characters that are members of the 'decimal digit family'",D3100:"The radix of the formatBase function must be between 2 and 36. It was given {{value}}",D3110:"The argument of the toMillis function must be an ISO 8601 formatted timestamp. Given {{value}}",D3120:"Syntax error in expression passed to function eval: {{value}}",D3121:"Dynamic error evaluating the expression passed to function eval: {{value}}",D3130:"Formatting or parsing an integer as a sequence starting with {{value}} is not supported by this implementation",D3131:"In a decimal digit pattern, all digits must be from the same decimal group",D3132:"Unknown component specifier {{value}} in date/time picture string",D3133:"The 'name' modifier can only be applied to months and days in the date/time picture string, not {{value}}",D3134:"The timezone integer format specifier cannot have more than four digits",D3135:"No matching closing bracket ']' in date/time picture string",D3136:"The date/time picture string is missing specifiers required to parse the timestamp",D3137:"{{{message}}}",D3138:"The $single() function expected exactly 1 matching result. Instead it matched more.",D3139:"The $single() function expected exactly 1 matching result. Instead it matched 0.",D3140:"Malformed URL passed to ${{{functionName}}}(): {{value}}",D3141:"{{{message}}}"};function jt(t){var e=Lt[t.code];if(void 0!==e){var n=e.replace(/\{\{\{([^}]+)}}}/g,function(){return t[arguments[1]]});n=n.replace(/\{\{([^}]+)}}/g,function(){return JSON.stringify(t[arguments[1]])}),t.message=n}}function Rt(t,e){var n,i;try{n=c(t,e&&e.recover),i=n.errors,delete n.errors}catch(t){throw jt(t),t}var r=It(B),o=new Date;return r.bind("now",Dt(function(t,e){return s.fromMillis(o.getTime(),t,e)},"<s?s?:s>")),r.bind("millis",Dt(function(){return o.getTime()},"<:n>")),e&&e.RegexEngine?Rt.RegexEngine=e.RegexEngine:Rt.RegexEngine=RegExp,{evaluate:function(t,e,s){if(void 0!==i){var a={code:"S0500",position:0};throw jt(a),a}var c,l,h;if(void 0!==e)for(var d in c=It(r),e)c.bind(d,e[d]);else c=r;if(c.bind("$",t),o=new Date,c.timestamp=o,Array.isArray(t)&&!z(t)&&((t=O(t)).outerWrapper=!0),"function"==typeof s){c.async=!0;var u=function(t){jt(t),s(t,null)},p=function t(e){(l=h.next(e)).done?s(null,l.value):l.value.then(t).catch(u)};h=N(n,t,c),(l=h.next()).value.then(p).catch(u)}else try{for(h=N(n,t,c),l=h.next();!l.done;)l=h.next(l.value);return l.value}catch(a){throw jt(a),a}},assign:function(t,e){r.bind(t,e)},registerFunction:function(t,e,n){var i=Dt(e,n);r.bind(t,i)},ast:function(){return n},errors:function(){return i}}}return Rt.parser=c,Rt}();e.exports=h},{"./datetime":1,"./functions":2,"./parser":4,"./signature":5,"./utils":6}],4:[function(t,e,n){var i=t("./signature"),r=function(){var t={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":80,"#":80,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"^":40,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},e={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},n=function(n){var i=0,r=n.length,s=function(t,e){return{type:t,value:e,position:i}},o=function(){for(var t,e,s=i,o=0;i<r;){var a=n.charAt(i);if("/"===a&&"\\"!==n.charAt(i-1)&&0===o){if(""===(t=n.substring(s,i)))throw{code:"S0301",stack:(new Error).stack,position:i};for(i++,a=n.charAt(i),s=i;"i"===a||"m"===a;)i++,a=n.charAt(i);return e=n.substring(s,i)+"g",new RegExp(t,e)}"("!==a&&"["!==a&&"{"!==a||"\\"===n.charAt(i-1)||o++,")"!==a&&"]"!==a&&"}"!==a||"\\"===n.charAt(i-1)||o--,i++}throw{code:"S0302",stack:(new Error).stack,position:i}},a=function a(c){if(i>=r)return null;for(var l=n.charAt(i);i<r&&" \t\n\r\v".indexOf(l)>-1;)i++,l=n.charAt(i);if("/"===l&&"*"===n.charAt(i+1)){var h=i;for(i+=2,l=n.charAt(i);"*"!==l||"/"!==n.charAt(i+1);)if(l=n.charAt(++i),i>=r)throw{code:"S0106",stack:(new Error).stack,position:h};return i+=2,l=n.charAt(i),a(c)}if(!0!==c&&"/"===l)return i++,s("regex",o());if("."===l&&"."===n.charAt(i+1))return i+=2,s("operator","..");if(":"===l&&"="===n.charAt(i+1))return i+=2,s("operator",":=");if("!"===l&&"="===n.charAt(i+1))return i+=2,s("operator","!=");if(">"===l&&"="===n.charAt(i+1))return i+=2,s("operator",">=");if("<"===l&&"="===n.charAt(i+1))return i+=2,s("operator","<=");if("*"===l&&"*"===n.charAt(i+1))return i+=2,s("operator","**");if("~"===l&&">"===n.charAt(i+1))return i+=2,s("operator","~>");if(Object.prototype.hasOwnProperty.call(t,l))return i++,s("operator",l);if('"'===l||"'"===l){var d=l;i++;for(var u="";i<r;){if("\\"===(l=n.charAt(i)))if(i++,l=n.charAt(i),Object.prototype.hasOwnProperty.call(e,l))u+=e[l];else{if("u"!==l)throw{code:"S0103",stack:(new Error).stack,position:i,token:l};var p=n.substr(i+1,4);if(!/^[0-9a-fA-F]+$/.test(p))throw{code:"S0104",stack:(new Error).stack,position:i};var f=parseInt(p,16);u+=String.fromCharCode(f),i+=4}else{if(l===d)return i++,s("string",u);u+=l}i++}throw{code:"S0101",stack:(new Error).stack,position:i}}var g,m=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/.exec(n.substring(i));if(null!==m){var y=parseFloat(m[0]);if(!isNaN(y)&&isFinite(y))return i+=m[0].length,s("number",y);throw{code:"S0102",stack:(new Error).stack,position:i,token:m[0]}}if("`"===l){i++;var b=n.indexOf("`",i);if(-1!==b)return g=n.substring(i,b),i=b+1,s("name",g);throw i=r,{code:"S0105",stack:(new Error).stack,position:i}}for(var v,_=i;;)if(v=n.charAt(_),_===r||" \t\n\r\v".indexOf(v)>-1||Object.prototype.hasOwnProperty.call(t,v)){if("$"===n.charAt(i))return g=n.substring(i+1,_),i=_,s("variable",g);switch(g=n.substring(i,_),i=_,g){case"or":case"in":case"and":return s("operator",g);case"true":return s("value",!0);case"false":return s("value",!1);case"null":return s("value",null);default:return i===r&&""===g?null:s("name",g)}}else _++};return a},r=function(e,r){var s,o,a={},c=[],l=function(){var t=[];"(end)"!==s.id&&t.push({type:s.type,value:s.value,position:s.position});for(var e=o();null!==e;)t.push(e),e=o();return t},h={nud:function(){var t={code:"S0211",token:this.value,position:this.position};if(r)return t.remaining=l(),t.type="error",c.push(t),t;throw t.stack=(new Error).stack,t}},d=function(t,e){var n=a[t];return e=e||0,n?e>=n.lbp&&(n.lbp=e):((n=Object.create(h)).id=n.value=t,n.lbp=e,a[t]=n),n},u=function(t){if(r){t.remaining=l(),c.push(t);var e=a["(error)"];return(s=Object.create(e)).error=t,s.type="(error)",s}throw t.stack=(new Error).stack,t},p=function(t,n){if(t&&s.id!==t){var i={code:"(end)"===s.id?"S0203":"S0202",position:s.position,token:s.value,value:t};return u(i)}var r=o(n);if(null===r)return(s=a["(end)"]).position=e.length,s;var c,l=r.value,h=r.type;switch(h){case"name":case"variable":c=a["(name)"];break;case"operator":if(!(c=a[l]))return u({code:"S0204",stack:(new Error).stack,position:r.position,token:l});break;case"string":case"number":case"value":c=a["(literal)"];break;case"regex":h="regex",c=a["(regex)"];break;default:return u({code:"S0205",stack:(new Error).stack,position:r.position,token:l})}return(s=Object.create(c)).value=l,s.type=h,s.position=r.position,s},f=function(t){var e,n=s;for(p(null,!0),e=n.nud();t<s.lbp;)n=s,p(),e=n.led(e);return e},g=function(t){d(t,0).nud=function(){return this}},m=function(e,n,i){var r=n||t[e],s=d(e,r);return s.led=i||function(t){return this.lhs=t,this.rhs=f(r),this.type="binary",this},s},y=function(t,e,n){var i=d(t,e);return i.led=n,i},b=function(t,e){var n=d(t);return n.nud=e||function(){return this.expression=f(70),this.type="unary",this},n};g("(end)"),g("(name)"),g("(literal)"),g("(regex)"),d(":"),d(";"),d(","),d(")"),d("]"),d("}"),d(".."),m("."),m("+"),m("-"),m("*"),m("/"),m("%"),m("="),m("<"),m(">"),m("!="),m("<="),m(">="),m("&"),m("and"),m("or"),m("in"),g("and"),g("or"),g("in"),b("-"),m("~>"),y("(error)",10,function(t){return this.lhs=t,this.error=s.error,this.remaining=l(),this.type="error",this}),b("*",function(){return this.type="wildcard",this}),b("**",function(){return this.type="descendant",this}),b("%",function(){return this.type="parent",this}),m("(",t["("],function(t){if(this.procedure=t,this.type="function",this.arguments=[],")"!==s.id)for(;"operator"===s.type&&"?"===s.id?(this.type="partial",this.arguments.push(s),p("?")):this.arguments.push(f(0)),","===s.id;)p(",");if(p(")",!0),"name"===t.type&&("function"===t.value||"λ"===t.value)){if(this.arguments.forEach(function(t,e){if("variable"!==t.type)return u({code:"S0208",stack:(new Error).stack,position:t.position,token:t.value,value:e+1})}),this.type="lambda","<"===s.id){for(var e=s.position,n=1,r="<";n>0&&"{"!==s.id&&"(end)"!==s.id;){var o=p();">"===o.id?n--:"<"===o.id&&n++,r+=o.value}p(">");try{this.signature=i(r)}catch(t){return t.position=e+t.offset,u(t)}}p("{"),this.body=f(0),p("}")}return this}),b("(",function(){for(var t=[];")"!==s.id&&(t.push(f(0)),";"===s.id);)p(";");return p(")",!0),this.type="block",this.expressions=t,this}),b("[",function(){var t=[];if("]"!==s.id)for(;;){var e=f(0);if(".."===s.id){var n={type:"binary",value:"..",position:s.position,lhs:e};p(".."),n.rhs=f(0),e=n}if(t.push(e),","!==s.id)break;p(",")}return p("]",!0),this.expressions=t,this.type="unary",this}),m("[",t["["],function(e){if("]"===s.id){for(var n=e;n&&"binary"===n.type&&"["===n.value;)n=n.lhs;return n.keepArray=!0,p("]"),e}return this.lhs=e,this.rhs=f(t["]"]),this.type="binary",p("]",!0),this}),m("^",t["^"],function(t){p("(");for(var e=[];;){var n={descending:!1};if("<"===s.id?p("<"):">"===s.id&&(n.descending=!0,p(">")),n.expression=f(0),e.push(n),","!==s.id)break;p(",")}return p(")"),this.lhs=t,this.rhs=e,this.type="binary",this});var v=function(t){var e=[];if("}"!==s.id)for(;;){var n=f(0);p(":");var i=f(0);if(e.push([n,i]),","!==s.id)break;p(",")}return p("}",!0),void 0===t?(this.lhs=e,this.type="unary"):(this.lhs=t,this.rhs=e,this.type="binary"),this};b("{",v),m("{",t["{"],v),y(":=",t[":="],function(e){return"variable"!==e.type?u({code:"S0212",stack:(new Error).stack,position:e.position,token:e.value}):(this.lhs=e,this.rhs=f(t[":="]-1),this.type="binary",this)}),m("@",t["@"],function(e){return this.lhs=e,this.rhs=f(t["@"]),"variable"!==this.rhs.type?u({code:"S0214",stack:(new Error).stack,position:this.rhs.position,token:"@"}):(this.type="binary",this)}),m("#",t["#"],function(e){return this.lhs=e,this.rhs=f(t["#"]),"variable"!==this.rhs.type?u({code:"S0214",stack:(new Error).stack,position:this.rhs.position,token:"#"}):(this.type="binary",this)}),m("?",t["?"],function(t){return this.type="condition",this.condition=t,this.then=f(0),":"===s.id&&(p(":"),this.else=f(0)),this}),b("|",function(){return this.type="transform",this.pattern=f(0),p("|"),this.update=f(0),","===s.id&&(p(","),this.delete=f(0)),p("|"),this});var _=function t(e){var n;if("function"!==e.type||e.predicate)if("condition"===e.type)e.then=t(e.then),void 0!==e.else&&(e.else=t(e.else)),n=e;else if("block"===e.type){var i=e.expressions.length;i>0&&(e.expressions[i-1]=t(e.expressions[i-1])),n=e}else n=e;else{var r={type:"lambda",thunk:!0,arguments:[],position:e.position};r.body=e,n=r}return n},x=0,w=0,M=[],S=function t(e,n){switch(e.type){case"name":case"wildcard":n.level--,0===n.level&&(void 0===e.ancestor||(M[n.index].slot.label=e.ancestor.label),e.ancestor=n,e.tuple=!0);break;case"parent":n.level++;break;case"block":e.expressions.length>0&&(e.tuple=!0,n=t(e.expressions[e.expressions.length-1],n));break;case"path":e.tuple=!0;var i=e.steps.length-1;for(n=t(e.steps[i--],n);n.level>0&&i>=0;)n=t(e.steps[i--],n);break;default:throw{code:"S0217",token:e.type,position:e.position}}return n},k=function(t,e){if(void 0!==e.seekingParent||"parent"===e.type){var n=void 0!==e.seekingParent?e.seekingParent:[];"parent"===e.type&&n.push(e.slot),void 0===t.seekingParent?t.seekingParent=n:Array.prototype.push.apply(t.seekingParent,n)}},A=function(t){var e=t.steps.length-1,n=t.steps[e],i=void 0!==n.seekingParent?n.seekingParent:[];"parent"===n.type&&i.push(n.slot);for(var r=0;r<i.length;r++){var s=i[r];for(e=t.steps.length-2;s.level>0;){if(e<0){void 0===t.seekingParent?t.seekingParent=[s]:t.seekingParent.push(s);break}for(var o=t.steps[e--];e>=0&&o.focus&&t.steps[e].focus;)o=t.steps[e--];s=S(o,s)}}},E=function t(e){var n;switch(e.type){case"binary":switch(e.value){case".":var i=t(e.lhs);n="path"===i.type?i:{type:"path",steps:[i]},"parent"===i.type&&(n.seekingParent=[i.slot]);var s=t(e.rhs);"function"===s.type&&"path"===s.procedure.type&&1===s.procedure.steps.length&&"name"===s.procedure.steps[0].type&&"function"===n.steps[n.steps.length-1].type&&(n.steps[n.steps.length-1].nextFunction=s.procedure.steps[0].value),"path"===s.type?Array.prototype.push.apply(n.steps,s.steps):(void 0!==s.predicate&&(s.stages=s.predicate,delete s.predicate),n.steps.push(s)),n.steps.filter(function(t){if("number"===t.type||"value"===t.type)throw{code:"S0213",stack:(new Error).stack,position:t.position,value:t.value};return"string"===t.type}).forEach(function(t){t.type="name"}),n.steps.filter(function(t){return!0===t.keepArray}).length>0&&(n.keepSingletonArray=!0);var o=n.steps[0];"unary"===o.type&&"["===o.value&&(o.consarray=!0);var a=n.steps[n.steps.length-1];"unary"===a.type&&"["===a.value&&(a.consarray=!0),A(n);break;case"[":var l=n=t(e.lhs),h="predicate";if("path"===n.type&&(l=n.steps[n.steps.length-1],h="stages"),void 0!==l.group)throw{code:"S0209",stack:(new Error).stack,position:e.position};void 0===l[h]&&(l[h]=[]);var d=t(e.rhs);void 0!==d.seekingParent&&(d.seekingParent.forEach(function(t){1===t.level?S(l,t):t.level--}),k(l,d)),l[h].push({type:"filter",expr:d,position:e.position});break;case"{":if(void 0!==(n=t(e.lhs)).group)throw{code:"S0210",stack:(new Error).stack,position:e.position};n.group={lhs:e.rhs.map(function(e){return[t(e[0]),t(e[1])]}),position:e.position};break;case"^":"path"!==(n=t(e.lhs)).type&&(n={type:"path",steps:[n]});var u={type:"sort",position:e.position};u.terms=e.rhs.map(function(e){var n=t(e.expression);return k(u,n),{descending:e.descending,expression:n}}),n.steps.push(u),A(n);break;case":=":(n={type:"bind",value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs),k(n,n.rhs);break;case"@":if(n=t(e.lhs),l=n,"path"===n.type&&(l=n.steps[n.steps.length-1]),void 0!==l.stages||void 0!==l.predicate)throw{code:"S0215",stack:(new Error).stack,position:e.position};if("sort"===l.type)throw{code:"S0216",stack:(new Error).stack,position:e.position};e.keepArray&&(l.keepArray=!0),l.focus=e.rhs.value,l.tuple=!0;break;case"#":n=t(e.lhs),l=n,"path"===n.type?l=n.steps[n.steps.length-1]:(n={type:"path",steps:[n]},void 0!==l.predicate&&(l.stages=l.predicate,delete l.predicate)),void 0===l.stages?l.index=e.rhs.value:l.stages.push({type:"index",value:e.rhs.value,position:e.position}),l.tuple=!0;break;case"~>":(n={type:"apply",value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs);break;default:(n={type:e.type,value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs),k(n,n.lhs),k(n,n.rhs)}break;case"unary":n={type:e.type,value:e.value,position:e.position},"["===e.value?n.expressions=e.expressions.map(function(e){var i=t(e);return k(n,i),i}):"{"===e.value?n.lhs=e.lhs.map(function(e){var i=t(e[0]);k(n,i);var r=t(e[1]);return k(n,r),[i,r]}):(n.expression=t(e.expression),"-"===e.value&&"number"===n.expression.type?(n=n.expression).value=-n.value:k(n,n.expression));break;case"function":case"partial":(n={type:e.type,name:e.name,value:e.value,position:e.position}).arguments=e.arguments.map(function(e){var i=t(e);return k(n,i),i}),n.procedure=t(e.procedure);break;case"lambda":n={type:e.type,arguments:e.arguments,signature:e.signature,position:e.position};var p=t(e.body);n.body=_(p);break;case"condition":(n={type:e.type,position:e.position}).condition=t(e.condition),k(n,n.condition),n.then=t(e.then),k(n,n.then),void 0!==e.else&&(n.else=t(e.else),k(n,n.else));break;case"transform":(n={type:e.type,position:e.position}).pattern=t(e.pattern),n.update=t(e.update),void 0!==e.delete&&(n.delete=t(e.delete));break;case"block":(n={type:e.type,position:e.position}).expressions=e.expressions.map(function(e){var i=t(e);return k(n,i),(i.consarray||"path"===i.type&&i.steps[0].consarray)&&(n.consarray=!0),i});break;case"name":n={type:"path",steps:[e]},e.keepArray&&(n.keepSingletonArray=!0);break;case"parent":n={type:"parent",slot:{label:"!"+x++,level:1,index:w++}},M.push(n);break;case"string":case"number":case"value":case"wildcard":case"descendant":case"variable":case"regex":n=e;break;case"operator":if("and"===e.value||"or"===e.value||"in"===e.value)e.type="name",n=t(e);else{if("?"!==e.value)throw{code:"S0201",stack:(new Error).stack,position:e.position,token:e.value};n=e}break;case"error":n=e,e.lhs&&(n=t(e.lhs));break;default:var f="S0206";"(end)"===e.id&&(f="S0207");var g={code:f,position:e.position,token:e.value};if(r)return c.push(g),{type:"error",error:g};throw g.stack=(new Error).stack,g}return e.keepArray&&(n.keepArray=!0),n};o=n(e),p();var C=f(0);if("(end)"!==s.id){var T={code:"S0201",position:s.position,token:s.value};u(T)}if("parent"===(C=E(C)).type||void 0!==C.seekingParent)throw{code:"S0217",token:C.type,position:C.position};return c.length>0&&(C.errors=c),C};return r}();e.exports=r},{"./signature":5}],5:[function(t,e,n){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}var r=t("./utils"),s=function(){var t={a:"arrays",b:"booleans",f:"functions",n:"numbers",o:"objects",s:"strings"};function e(e){for(var n=1,s=[],o={},a=o;n<e.length;){var c=e.charAt(n);if(":"===c)break;var l=function(){s.push(o),a=o,o={}},h=function(t,e,n,i){for(var r=1,s=e;s<t.length;)if(s++,(c=t.charAt(s))===i){if(0===--r)break}else c===n&&r++;return s};switch(c){case"s":case"n":case"b":case"l":case"o":o.regex="["+c+"m]",o.type=c,l();break;case"a":o.regex="[asnblfom]",o.type=c,o.array=!0,l();break;case"f":o.regex="f",o.type=c,l();break;case"j":o.regex="[asnblom]",o.type=c,l();break;case"x":o.regex="[asnblfom]",o.type=c,l();break;case"-":a.context=!0,a.contextRegex=new RegExp(a.regex),a.regex+="?";break;case"?":case"+":a.regex+=c;break;case"(":var d=h(e,n,"(",")"),u=e.substring(n+1,d);if(-1!==u.indexOf("<"))throw{code:"S0402",stack:(new Error).stack,value:u,offset:n};o.regex="["+u+"m]",o.type="("+u+")",n=d,l();break;case"<":if("a"!==a.type&&"f"!==a.type)throw{code:"S0401",stack:(new Error).stack,value:a.type,offset:n};var p=h(e,n,"<",">");a.subtype=e.substring(n+1,p),n=p}n++}var f="^"+s.map(function(t){return"("+t.regex+")"}).join("")+"$",g=new RegExp(f),m=function(t){var e;if(r.isFunction(t))e="f";else switch(i(t)){case"string":e="s";break;case"number":e="n";break;case"boolean":e="b";break;case"object":e=null===t?"l":Array.isArray(t)?"a":"o";break;default:e="m"}return e},y=function(t,e){for(var n="^",i=0,r=0;r<s.length;r++){n+=s[r].regex;var o=e.match(n);if(null===o)throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1};i=o[0].length}throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1}};return{definition:e,validate:function(e,n){var i="";e.forEach(function(t){i+=m(t)});var r=g.exec(i);if(r){var o=[],a=0;return s.forEach(function(i,s){var c=e[a],l=r[s+1];if(""===l)if(i.context&&i.contextRegex){var h=m(n);if(!i.contextRegex.test(h))throw{code:"T0411",stack:(new Error).stack,value:n,index:a+1};o.push(n)}else o.push(c),a++;else l.split("").forEach(function(n){if("a"===i.type){if("m"===n)c=void 0;else{c=e[a];var r=!0;if(void 0!==i.subtype)if("a"!==n&&l!==i.subtype)r=!1;else if("a"===n&&c.length>0){var s=m(c[0]);r=s===i.subtype.charAt(0)&&0===c.filter(function(t){return m(t)!==s}).length}if(!r)throw{code:"T0412",stack:(new Error).stack,value:c,index:a+1,type:t[i.subtype]};"a"!==n&&(c=[c])}o.push(c),a++}else o.push(c),a++})}),o}y(e,i)}}}return e}();e.exports=s},{"./utils":6}],6:[function(t,e,n){function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=r(t))||e){n&&(t=n);var i=0,s=function(){};return{s:s,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw o}}}}function r(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}var a=function(){function t(t){var e=!1;if("number"==typeof t&&(e=!isNaN(t))&&!isFinite(t))throw{code:"D1001",value:t,stack:(new Error).stack};return e}function e(t){var e=!1;return Array.isArray(t)&&(e=0===t.filter(function(t){return"string"!=typeof t}).length),e}function n(e){var n=!1;return Array.isArray(e)&&(n=0===e.filter(function(e){return!t(e)}).length),n}function r(){var t=[];return t.sequence=!0,1===arguments.length&&t.push(arguments[0]),t}function s(t){return!0===t.sequence&&Array.isArray(t)}function a(t){return t&&(!0===t._jsonata_function||!0===t._jsonata_lambda)||"function"==typeof t}function c(t){return"number"==typeof t.arity?t.arity:"function"==typeof t.implementation?t.implementation.length:"number"==typeof t.length?t.length:t.arguments.length}function l(t){return t&&!0===t._jsonata_lambda}var h=("function"==typeof Symbol?Symbol:{}).iterator||"@@iterator";function d(t){return"object"===o(t)&&null!==t&&h in t&&"next"in t&&"function"==typeof t.next}function u(t,e){if(t===e)return!0;if("object"===o(t)&&"object"===o(e)&&null!==t&&null!==e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!u(t[n],e[n]))return!1;return!0}var i=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(i.length!==r.length)return!1;for(i=i.sort(),r=r.sort(),n=0;n<i.length;n++)if(i[n]!==r[n])return!1;for(n=0;n<i.length;n++){var s=i[n];if(!u(t[s],e[s]))return!1}return!0}return!1}function p(t){var e,n=[],r=i(t);try{for(r.s();!(e=r.n()).done;){var s=e.value;n.push(s)}}catch(t){r.e(t)}finally{r.f()}return n}return{isNumeric:t,isArrayOfStrings:e,isArrayOfNumbers:n,createSequence:r,isSequence:s,isFunction:a,isLambda:l,isIterable:d,getFunctionArity:c,isDeepEqual:u,stringToArray:p}}();e.exports=a},{}]},{},[3])(3)}(ir)),ir.exports),sr=tr(rr);const or=function(t){return t};function ar(t){if(!t)return or;try{const e=sr(function(t){return t.replace(/(?<=^|\.|\[)([a-zA-Z_][\w]*-[\w-]*)(?=\.|$|\[|])/g,"`$1`")}(t));return function(t){return e.evaluate(t)}}catch(t){return Ki(t),or}}function cr(t){const e=vi(t);return null==e?"":String(e)}function lr(t){return Number(vi(t))}function hr(t){return t}function dr(t){return cr(t)}function ur(t){return lr(t)}function pr(t){if(this.param)return t=cr(t),this.param.hasOwnProperty(t)?this.param[t]:this.param.default}function fr(t){const{param:e}=this;if(e){for(const n in e){let[i,r]=n.split("~");const s=!!i,o=!!r,a=parseFloat(i),c=parseFloat(r);if(t=lr(t),s&&!o&&t>=a)return e[n];if(!s&&o&&t<a)return e[n];if(t>=a&&t<c)return e[n]}return e.default}}function gr(t){return lr(t)*Math.PI/180}function mr(){}const yr=[/\bimport\b/,/\brequire\b/,/\b__proto__\b/,/\bconstructor\s*\[/,/\bprototype\b/];const br=["globalThis","self","top","parent","frames","fetch","XMLHttpRequest","eval","Function","require","importScripts","process"],vr=new Array(br.length).fill(void 0);function _r(t){try{!function(t){for(const e of yr)if(e.test(t))throw new Error(`Blocked pattern detected: ${e}`)}(t);const e=new Function("value","targets","scene",...br,t);return function(t,n){try{return e.call(this,t,n,globalThis.scene,...vr)}catch(t){return void Ki(t)}}}catch(t){return Ki(t),mr}}function xr(t,e,n,i,r){switch(n){case"value":return"text"===r||"string"===r?dr.bind(t):"number"===r?ur.bind(t):hr.bind(e);case"map":return pr.bind(t);case"range":return fr.bind(t);case"radian":return gr.bind(t);case"eval":return _r(i).bind(e);default:return hr.bind(e)}}class wr{constructor(t,e){this.owner=e,this.model=t}dispose(){this._model=null,this.owner=null,this.evaluator=null,this.accessor=null}get model(){return this._model}set model(t){const{target:e,property:n,rule:i,param:r,accessor:s}=t;this._model=t,this.evaluator=xr(this,this.owner,i,r,function(t){switch(t){case"ref":case"fillStyle":case"strokeStyle":return"string";default:return}}(n)),this.accessor=ar(s);const o=e.match(/\[(.*?)\]/);if(o){const[t,e]=o[1].split(":");this.propAccessor=ar(t),this.partAccessor=ar(e)}}get target(){return this.model.target}get property(){return this.model.property}get source(){return this.model.source}get param(){return this.model.param}get ndnsp(){return!!this.model.ndnsp}get partial(){return!!this.model.partial}}function Mr(t,e,n,i){const r=e.split(".");if(1===r.length)return void(t[e]=i?{...t[e],...n}:n);const s=r[0],o=void 0!==t[s]?t[s]:"function"==typeof t.get?t.get(s):void 0,a=o?{...o}:{};let c=a;for(let t=1;t<r.length-1;t++)c[r[t]]=c[r[t]]?{...c[r[t]]}:{},c=c[r[t]];const l=r[r.length-1];c[l]=i?{...c[l],...n}:n,t[s]=a}function Sr(t,e,n,i){t.forEach(t=>Mr(t,e,n,i))}function kr(t=!1){(t||void 0!==this.data)&&this.mappings&&this.mappings.forEach(t=>{try{let e,{source:n,target:i,property:r,accessor:s,propAccessor:o,partAccessor:a,ndnsp:c=!1,partial:l=!1}=t;i=(i||"(self)").trim(),t.rule||(t.rule="value"),n&&"(self)"!=n?(n.startsWith("#")&&(n=n.substring(1)),e=this.root.findById(n)?.data||{}):e=this.data;const h=s(e);if("(root)"==i||"(key)"==i){if(null==h)return;const e=Object.keys(h||{}).map(t=>this.root.findOrCreate(t)).filter(Boolean).flat();e.length>0&&e.forEach(e=>{const n=t.evaluator(h[e.get("id")],[e]);!r||"(action)"===r||c&&!n&&0!==n&&!1!==n||Mr(e,r,n,l)})}else if(i.startsWith("[")){if(null==h)return;if(h instanceof Array)h.forEach(e=>{const n=o(e);if(n){const i=this.root.findOrCreate(n);if(i){const n=t.evaluator(a(e),i);!r||"(action)"===r||c&&!n&&0!==n&&!1!==n||Sr(i,r,n,l)}}});else{if(!(h instanceof Object))throw String("mapping data should be an object to target property-id.("+h+")");{const e=o(h);if(e){const n=this.root.findOrCreate(e);if(n){const e=t.evaluator(a(h),n);!r||"(action)"===r||c&&!e&&0!==e&&!1!==e||Sr(n,r,e,l)}}}}}else{const e=this.root.findAll(i,this);if(e.length>0){const n=t.evaluator(h,e);!r||"(action)"===r||c&&!n&&0!==n&&!1!==n||Sr(e,r,n,l)}}}catch(e){Ki(e,this,t)}})}function Ar(t,e){this.state.persistent&&this.app?.isViewMode&&this.app?.dataStorage.save(this,t.data),this.app?.lagTracker?.recordIfMonitored(this.state.tag,t.data),kr.call(this,!0)}function Er(){if(this._model.mappings)return this._model.mappings instanceof Array?void(this._mappings=(this._model.mappings||[]).filter(t=>t.property).map(t=>new wr({target:"(self)",rule:"value",...t},this))):(Ki("Mappings model is invalid (should be a Array) ..",this._model.mappings),void(this._mappings=[]));this._mappings=[]}function Cr(){this._mappings&&this._mappings.forEach(t=>t.dispose()),delete this._mappings}function Tr(t,e){this.disposeMappings(),kr.call(this)}function Pr(t,e,n,i,r,s){e.complete?t.drawImage(e,n,i,r,s):e.addEventListener("load",()=>{this.invalidate()})}function Dr(t){const{effects:e}=this.state;(e||[]).forEach(e=>{this.effect(t,e)})}const Or={},zr=0,Ir=1,Lr=2,jr=3,Rr=4,Fr=5,Br={VIEW:0,EDIT:1,SHIFT:2,ADD:3},Nr=30,Hr="undefined"==typeof window?1:window.devicePixelRatio||(window.matchMedia&&window.matchMedia("(min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 1.5),(-moz-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5)").matches?2:1),Yr=["mousemove","mouseup","mousedown","mouseout","wheel","touchstart","touchmove","touchend","dblclick"],Vr=["keydown","keyup"],Gr={ALPHA:1,FONT_SIZE:15,FONT_FAMILY:"Roboto, sans-serif",FONT_COLOR:"black",TEXT_ALIGN:"center",TEXT_BASELINE:"middle",TEXT_WRAP:!1,BOLD:!1,ITALIC:!1,STROKE_STYLE:"#999",LINE_DASH:"solid",LETTER_SPACING:0},Ur=()=>{if("undefined"==typeof document||"function"!=typeof getComputedStyle||!document.documentElement)return;const t=getComputedStyle(document.documentElement);if(!t)return;const e=t.getPropertyValue?.("--scene-theme-font-family")?.trim(),n=t.fontFamily||"sans-serif";Gr.FONT_FAMILY=e||n},Wr=()=>{if("undefined"!=typeof window&&"undefined"!=typeof document&&(window.addEventListener("load",()=>{Ur()}),"fonts"in document&&"ready"in document.fonts&&document.fonts.ready.then(Ur),"undefined"!=typeof MutationObserver&&document.documentElement)){new MutationObserver(()=>{Ur()}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}};let Xr;function qr(t,e,n,i,r){const{alpha:s=1}=i,o=r.fillStyle;if(t.globalAlpha*=s,o)if("string"==typeof o)t.fillStyle=o,t.fill();else if("object"==typeof o)if("gradient"==o.type){t.translate(n.x,n.y);let i,{width:r,height:s}=e;if("linear"==o.gradientType){const e=3.141592653589793,n="number"==typeof o.rotation&&Number.isFinite(o.rotation)?o.rotation:0;if(n>=.436332&&n<=1.13446||n>=2.00713&&n<=2.70526||n>=3.57792&&n<=4.27606||n>=5.14872&&n<=5.84685){let o=Math.sqrt(Math.pow((r-4)/2,2)+Math.pow((s-4)/2,2));o-=o-(r+s)/3,i=t.createLinearGradient(o*Math.cos(n+e),o*Math.sin(n+e),o*Math.cos(n),o*Math.sin(n))}else i=t.createLinearGradient((r-4)/2*Math.cos(n+e),(s-4)/2*Math.sin(n+e),(r-4)/2*Math.cos(n),(s-4)/2*Math.sin(n))}else if("radial"==o.gradientType){const e=.95*Math.sqrt(Math.pow((r-4)/2,2)+Math.pow((s-4)/2,2));switch(o.center){case"center":default:i=t.createRadialGradient(0,0,0,0,0,e);break;case"left-top":i=t.createRadialGradient(-r/2,-s/2,0,-r/2,-s/2,2*e);break;case"right-top":i=t.createRadialGradient(r/2,-s/2,0,r/2,-s/2,2*e);break;case"left-bottom":i=t.createRadialGradient(-r/2,s/2,0,-r/2,s/2,2*e);break;case"right-bottom":i=t.createRadialGradient(r/2,s/2,0,r/2,s/2,2*e)}}o.colorStops.forEach(t=>{if(t.position>=0&&t.position<=1)try{i.addColorStop(t.position,t.color)}catch(e){$i("Invalid Color for colorstop : ",t.color),i.addColorStop(t.position,"#fff")}}),t.fillStyle=i,t.fill(),t.translate(-n.x,-n.y)}else if("pattern"==o.type&&o.image)if(o.guideOnly&&1!=r.app.mode)o.color&&(t.fillStyle=o.color,t.fill());else{r.prepareFillIf(!r._pattern_image_origin);const n=r._pattern_image;if(!n||!n.width||!n.height)return;let i=0,s=0,a=0,c=0,l=e.left,h=e.top;if(!o.fitPattern){i=o.offsetX,s=o.offsetY;const t=o.width?o.width:n.width,r=o.height?o.height:n.height;switch(o.align){case"center":a=e.width/2-t/2,c=e.height/2-r/2;break;case"left-top":a=0,c=0;break;case"left-bottom":a=0,c=e.height-r;break;case"right-top":a=e.width-t,c=0;break;case"right-bottom":a=e.width-t,c=e.height-r;break;case"left":a=0,c=e.height/2-r/2;break;case"right":a=e.width-t,c=e.height/2-r/2;break;case"top":a=e.width/2-t/2,c=0;break;case"bottom":a=e.width/2-t/2,c=e.height-r}l+=i+a,h+=s+c}t.translate(l,h),o.color&&(t.fillStyle=o.color,t.fill()),o.fitPattern?Math.abs((n.width-e.width)*(n.height-e.height))>1?(delete r._pattern_image,delete r._pattern_image_origin):t.fillStyle=t.createPattern(n,"no-repeat"):t.fillStyle=t.createPattern(n,o.noRepeat?"no-repeat":"repeat"),t.fill(),t.translate(-l,-h)}}function Kr(t,e){const n=this.fillStyle;if(!n||"pattern"!=n.type||!n.image)return void t(this);if("string"!=typeof n.image)return this._pattern_image_origin=this._pattern_image=n.image,void t(this);this._pattern_image=null,this._pattern_image_origin=new Image;const i=this;this._pattern_image_origin.onload=function(){if(!n.fitPattern&&!n.width&&!n.height)return i._pattern_image=i._pattern_image_origin,void t(this);let e=n.width||this.width,r=n.height||this.height;n.fitPattern&&(e=i.bounds.width,r=i.bounds.height);const s=Xr(e,r);s.getContext("2d").drawImage(this,0,0,this.width,this.height,0,0,e,r),i._pattern_image=s,t(this)},this._pattern_image_origin.onerror=function(t){e(t)};try{"data"!==String(n.image).substring(0,4)?this._pattern_image_origin.crossOrigin="use-credentials":this._pattern_image_origin.crossOrigin=null,this._pattern_image_origin.src=this.app.url(n.image)}catch(t){e(t)}}function $r(t){t&&this.prepareFill(t=>{this.invalidate()},t=>{Ki(t)})}function Qr(t,e){const n=this.fillStyle;n&&"pattern"!==n.type?this._pattern_image&&(this._pattern_image=null,this._pattern_image_origin=null):n?.image&&this.prepareFillIf(n.image)}function Zr(t,e,n){let{strokeStyle:i,lineDash:r,lineWidth:s,lineCap:o,lineJoin:a,alpha:c}=e;if(i&&0!=s){if(o&&(t.lineCap=o),r){const e="round"==o;switch(r){case"solid":r=[0,0];break;case"round-dot":r=e?[0,2*s]:[s,s];break;case"square-dot":r=e?[s,2*s]:[2*s,s];break;case"dash":r=e?[3*s,2.5*s]:[4*s,1.5*s];break;case"dash-dot":r=e?[3*s,3*s,0,3*s]:[4*s,2*s,s,2*s];break;case"long-dash":r=e?[5*s,4*s]:[6*s,3*s];break;case"long-dash-dot":r=e?[5*s,3*s,0,3*s]:[6*s,2*s,s,2*s];break;case"long-dash-dot-dot":r=e?[5*s,2*s,0,2*s,0,2*s]:[6*s,s,s,s,s,s]}t.setLineDash(r)}t.globalAlpha*=c,t.strokeStyle=i,t.lineWidth=s,t.lineJoin=a,t.stroke()}}function Jr(t){const e=/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3|([^\*_]+)/g,n=[];let i;for(;null!==(i=e.exec(t));)i[1]?n.push({text:i[2],bold:!0,italic:!1}):i[3]?n.push({text:i[4],bold:!1,italic:!0}):i[5]&&n.push({text:i[5],bold:!1,italic:!1});return n}function ts(t,e,n,i=0){if(e.text.length<2)return e;let r=2;for(;r<e.text.length;r++){const s=e.text.substring(0,r);if(!(t.measureText(s).width+(r-1)*i<n))break}return{...e,text:e.text.substring(0,r-1)}}function es(t,e,n,i,r,s=0){const o=String(e).split("\n");return i?[].concat(...o.map(e=>function(t,e,n,i=0){const r=[];let s=[],o=0;return e.forEach(e=>{let a=e.text;for(;a.length>0;){const c=n-o,l=t.measureText(a).width+(a.length-1)*i;if(l<=c)s.push({...e,text:a}),o+=l,a="";else{const n=ts(t,{...e,text:a},c,i);s.push(n),r.push(s),s=[],o=0,a=a.substring(n.text.length)}}}),s.length>0&&r.push(s),r}(t,r?Jr(e):[{text:e,bold:!1,italic:!1}],n,s))):o.map(t=>r?Jr(t):[{text:t,bold:!1,italic:!1}])}function ns(t,e,n,i,r,s,o=0){if(!i)return[];t.save(),t.font=n;const a=es(t,i,e,!!r,s,o);return t.restore(),a}function is(t){const{fontFamily:e=Gr.FONT_FAMILY,bold:n=Gr.BOLD,italic:i=Gr.ITALIC,fontSize:r=Gr.FONT_SIZE}=t,s=[];return n&&s.push("bold"),i&&s.push("italic"),s.push(r+"px"),s.push(e),s.join(" ")}function rs(t,e){const n=t.bold||e.bold,i=t.italic||e.italic;return is({...t,bold:n,italic:i})}function ss(t,e,n,i){let{alpha:r,rotation:s,keepTextAngle:o=!1,fontColor:a=Gr.FONT_COLOR,textAlign:c=Gr.TEXT_ALIGN,textBaseline:l=Gr.TEXT_BASELINE,textBackgroundStyle:h,fontSize:d,lineHeight:u,textWrap:p,textOverflow:f,letterSpacing:g=0}=i;r=void 0!==r?r:1,d||=Gr.FONT_SIZE,u||=1.2*d,t.save();const{left:m,top:y,width:b,height:v}=e;if(s&&o&&(t.translate(m+b/2,y+v/2),t.rotate(-s),t.translate(-(m+b/2),-(y+v/2))),t.beginPath(),t.font=is(i),!p&&f){const e=function(t,e,n,i){const r="ellipsis"===t?"…":"",s=e.measureText(r).width,o=[];let a=0;for(const r of n){const n=[];for(const c of r){const r=e.measureText(c.text).width;if(!(a+r<=i-("ellipsis"===t?s:0))){const r=os(e,c,i-a-("ellipsis"===t?s:0),t);return n.push(r),o.push(n),o}n.push(c),a+=r}o.push(n),a=0}return o}(f,t,n,b);n=e}const _=n.length*u;let x;switch(l){case"top":x=y,t.textBaseline="top";break;case"bottom":x=y+v-_+u,t.textBaseline="bottom";break;default:x=y+v/2-_/2+u/2,t.textBaseline="middle"}t.globalAlpha*=r,t.fillStyle=a,n.forEach((e,r)=>{const s=x+r*u,o=function(t,e,n,i=0){return e.reduce((e,r)=>(t.font=rs(n,r),e+t.measureText(r.text).width+i*(r.text.length-1)),0)}(t,e,i,g);let l=m;switch(c){case"left":case"justify":l=m;break;case"right":l=m+b-o;break;case"center":l=m+(b-o)/2}if(h&&(t.fillStyle=h,function(t,e,n,i,r,s=0,o=!1,a=!0){s="number"==typeof s?{tl:s,tr:s,br:s,bl:s}:{tl:0,tr:0,br:0,bl:0,...s},t.beginPath(),t.moveTo(e+s.tl,n),t.lineTo(e+i-s.tr,n),t.quadraticCurveTo(e+i,n,e+i,n+s.tr),t.lineTo(e+i,n+r-s.br),t.quadraticCurveTo(e+i,n+r,e+i-s.br,n+r),t.lineTo(e+s.bl,n+r),t.quadraticCurveTo(e,n+r,e,n+r-s.bl),t.lineTo(e,n+s.tl),t.quadraticCurveTo(e,n,e+s.tl,n),t.closePath(),o&&t.fill(),a&&t.stroke()}(t,l-4,s-d/2-4,o+8,d+8,4,!0,!1),t.fillStyle=a),"justify"===c&&r<n.length-1&&e.length>1){const n=b-o,r=e.length-1,a=n/r;e.forEach((e,n)=>{t.font=rs(i,e),t.fillText(e.text,l,s),l+=t.measureText(e.text).width+(n<r?a:0)})}else e.forEach(e=>{t.font=rs(i,e),[...e.text].forEach(e=>{t.fillText(e,l,s),l+=t.measureText(e).width+g})})}),t.restore()}function os(t,e,n,i){let r="";for(let i=0;i<e.text.length;i++){const s=r+e.text[i];if(t.measureText(s).width>n)break;r=s}return{...e,text:r+("ellipsis"===i?"…":"")}}function as(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("image/"))return void this.set("fillStyle",{type:"pattern",image:e[n],fitPattern:!0})}Wr(),Ur(),Xr="undefined"==typeof document?function(t,e){return new Canvas(t,e)}:function(t,e){const n=document.createElement("canvas");return n.width=t,n.height=e,n};const cs=[];function ls(t,e,n={x:0,y:0},i=0,r={x:1,y:1}){if(1!==r.x||1!==r.y?(t=(t-n.x)/r.x,e=(e-n.y)/r.y):(t-=n.x,e-=n.y),0!==i){const n=Math.cos(-i),r=Math.sin(-i),s=t*r+e*n;t=t*n-e*r,e=s}return{x:t+n.x,y:e+n.y}}function hs(t,e,n={x:0,y:0},i=0,r={x:1,y:1}){if(t-=n.x,e-=n.y,0!==i){const n=Math.cos(i),r=Math.sin(i),s=t*r+e*n;t=t*n-e*r,e=s}return 1!==r.x||1!==r.y?{x:t*r.x+n.x,y:e*r.y+n.y}:{x:t+n.x,y:e+n.y}}function ds(t,e,n){if(!this.parent)return{x:t,y:e};const{rotation:i=0,scale:r={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,s=ls(t,e,n,i,r);return n&&(s.x-=n.x,s.y-=n.y),s}return ls(t,e,n=n||this.rotatePoint,i,r)}function us(t,e,n){if(!this.parent)return{x:t,y:e};let{rotation:i=0,scale:r={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,s=hs(t,e,void 0,i+(this._delta?.theta??0),r);return n&&(s.x+=n.x,s.y+=n.y),s}n=n||this.rotatePoint;const{theta:s=0,tx:o=0,ty:a=0,sx:c=1,sy:l=1}=this._delta||{};if(0===s&&0===o&&0===a&&1===c&&1===l)return hs(t,e,n,i,r);return hs(t+o,e+a,{x:n.x+o,y:n.y+a},i+s,{x:r.x*c,y:r.y*l})}function ps(t,e,n){n=n||this.rootModel;const i=this.transcoordS2T(t,e,n);return hs(i.x,i.y,void 0,(n.get("rotation")||0)+n._delta.theta)}function fs(t,e,n){n=n||this.rootModel,cs.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)cs.push(t);let i=this.transcoordS2P(t,e);for(let t=0;t<cs.length;t++){const e=cs[t],n=e.bounds;i.x+=n.left,i.y+=n.top,i=e.transcoordS2P(i.x,i.y)}return i}function gs(t,e,n){n=n||this.rootModel,cs.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)cs.push(t);let i={x:t,y:e};for(let t=cs.length-1;t>=0;t--){const e=cs[t];i=e.transcoordP2S(i.x,i.y);const n=e.bounds;i.x-=n.left,i.y-=n.top}return i}function ms(t,e,n){const i=this.transcoordT2P(t,e,n);return this.transcoordP2S(i.x,i.y)}function ys(t,e,n){const i=this.rootModel,r=this.transcoordS2T(t,e,i);return n.transcoordT2S(r.x,r.y,i)}function bs(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;const{translate:i={x:0,y:0},scale:r={x:1,y:1},rotation:s=0}=n.model,o=ls(t,e,i,s,r);return i&&(o.x-=i.x,o.y-=i.y),n===this?o:this.transcoordT2S(o.x,o.y,n)}function vs(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;let i;if(i=n!==this?this.transcoordS2T(t,e,n):{x:t,y:e},!this.scalable)return i;const{translate:r={x:0,y:0},rotation:s=0,scale:o={x:1,y:1}}=n.model;return i=hs(i.x,i.y,void 0,s+n._delta.theta,o),r&&(i.x+=r.x,i.y+=r.y),i}function _s(t){let e=0,n=0,i=0,r=0,s=!1;return t.forEach(t=>{s?(e=Math.min(t.left,e),n=Math.min(t.top,n),i=Math.max(t.left+t.width,i),r=Math.max(t.top+t.height,r)):(e=t.left,n=t.top,i=t.left+t.width,r=t.top+t.height,s=!0)}),{left:e,top:n,width:i-e,height:r-n}}function xs(t){const e=t.element,n=t.fillStyle,i=e.style;if(n)if("string"==typeof n)i.backgroundColor=n;else switch(n.type){case"pattern":if(i.backgroundImage="url("+n.image+")",i.backgroundColor="transparent",n.fitPattern?i.backgroundSize="100% 100%":n.width||n.height?i.backgroundSize=`${n.width?n.width+"px":"auto"} ${n.height?n.height+"px":"auto"}`:i.backgroundSize="contain",n.fitPattern)i.backgroundRepeat="no-repeat";else{const{offsetX:t,offsetY:e,noRepeat:r,align:s,color:o}=n;if(r&&(i.backgroundRepeat="no-repeat"),o&&(i.backgroundColor=o),s)switch(s){case"center":i.backgroundPosition="center center";break;case"left-top":i.backgroundPosition="left top";break;case"left-bottom":i.backgroundPosition="left bottom";break;case"right-top":i.backgroundPosition="right top";break;case"right-bottom":i.backgroundPosition="right bottom";break;case"left":i.backgroundPosition="left center";break;case"right":i.backgroundPosition="right center";break;case"top":i.backgroundPosition="center top";break;case"bottom":i.backgroundPosition="center bottom"}else t||e?i.backgroundPosition=`${Number(t)||0}px ${Number(e)||0}px`:delete i.backgroundPosition}break;case"gradient":i.background=function(t,e){const n=e.colorStops,i=e.gradientType;if(n instanceof Array&&n.length>0)switch(i){case"radial":return"radial-gradient(farthest-corner at "+function(t,e){const{width:n,height:i}=t.bounds;switch(e){case"center":return[n/2,i/2];case"left-top":return[0,0];case"right-top":return[n,0];case"left-bottom":return[0,i];default:return[n,i]}}(t,e.center||"center").map(t=>t+"px").join(" ")+","+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")";case"linear":return"linear-gradient("+(180*(e.rotation||0)/3.141592653589793+90+"deg")+", "+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")"}return""}(t,n)}else i.background="transparent"}const ws={x:1,y:1},Ms={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"};function Ss(t){let{id:e,scale:n=ws,bold:i,italic:r,fontFamily:s="",textAlign:o,textBaseline:a,textOverflow:c,paddingTop:l,paddingBottom:h,paddingLeft:d,paddingRight:u,fontSize:p=Gr.FONT_SIZE,lineWidth:f=0,lineHeight:g,lineDash:m}=t.state;h||=0,l||=0,d||=0,u||=0;const y=t.state.class,{strokeStyle:b,rotation:v=0,fontColor:_,hidden:x}=t,{left:w,top:M,width:S,height:k}=t.bounds,A=t.element;if(A.hidden=x,e&&(A.id=e),y&&(A.className=y),Object.assign(A.style,Ms,{fontFamily:s,fontSize:p+"px",width:S+"px",height:k+"px",paddingTop:l+"px",paddingRight:u+"px",paddingBottom:h+"px",paddingLeft:d+"px",border:f+"px",borderColor:b,borderStyle:f>0?m||Gr.LINE_DASH:"",color:_,fontWeight:i?"bold":"",fontStyle:r?"italic":"",textAlign:"end"==o?"right":"start"==o?"left":o,verticalAlign:a,lineHeight:void 0===g?"":g+"px",whiteSpace:c?"nowrap":"",overflow:c?"hidden":"",textOverflow:c||""},t.isIn3DSpace()?{}:{left:w+"px",top:M+"px"}),xs(t),function(t){if(!t.isShadowable()||!t.state.shadow)return;const e=t.element,{left:n=0,top:i=0,blurSize:r=0,color:s="transparent"}=t.state.shadow;e.style.boxShadow=`${n}px ${i}px ${r}px ${s}`}(t),t.isIn3DSpace())return;const E=t.delta(),C=(n&&n.x||1)*E.sx,T=(n&&n.y||1)*E.sy,P=(v||0)+E.theta,D=E.tx||0,O=E.ty||0;A.style.transform=`rotate(${P}rad) translate(${D}px, ${O}px) scale(${C}, ${T}) perspective(1px)`}function ks(t,e){let n=this.bounds,i=this.rotatePoint;const r=this.get("rotation"),s=this.get("scale");if(t){const i=t.call(e,n);i&&(n=i)}const{left:o,top:a,width:c,height:l}=n;let h=[{x:o,y:a},{x:o+c,y:a+l}];h=h.map(t=>hs(t.x,t.y,i,r,s));let d=h[0],u=h[1];i={x:(d.x+u.x)/2,y:(d.y+u.y)/2},h=h.map(t=>ls(t.x,t.y,i,r,s)),d=h[0],u=h[1],this.bounds={left:d.x,top:d.y,width:u.x-d.x,height:u.y-d.y}}function As(t,e,n){let i=this.path,r=this.rotatePoint;this.get("rotation"),this.get("scale"),t&&(i=t.call(n,i));let s=i.map(t=>{const e=this.toParent(t.x,t.y);return void 0!==t.z&&(e.z=t.z),e});if(e){const t=e.call(n,s);t&&(s=t)}const o={x:0,y:0};let a,c,l,h;i=s.map(t=>this.fromParent(t.x,t.y,o)),a=c=i[0].x,l=h=i[0].y;for(let t=1;t<i.length;t++){const e=i[t];e.x<a?a=e.x:e.x>c&&(c=e.x),e.y<l?l=e.y:e.y>h&&(h=e.y)}r={x:(a+c)/2,y:(l+h)/2},r=this.toParent(r.x,r.y,o),this.path=s.map(t=>{const e=this.fromParent(t.x,t.y,r);return void 0!==t.z&&(e.z=t.z),e})}let Es,Cs=[];function Ts(){Es=null;const t=performance.now();Cs=Cs.filter(t=>Ps(t));const e=Cs.reduce((e,n)=>{const i=t-n.updatedAt;return i>=n.retention?e.kills.push(n):e.next=0==e.next?n.retention-i:Math.min(e.next,n.retention-i),e},{next:0,kills:[]});e.kills.forEach(t=>{const e=Cs.indexOf(t);-1!=e?(Cs.splice(e,1),t.removeSelf(!0)):Ki("Should not be here. Maybe reentrance problem.")}),e.next>0&&(Es=setTimeout(Ds,Math.max(e.next,500)))}function Ps(t){return!t.disposed&&t.retention>0&&!t.isTemplate()&&t.app&&t.app.isViewMode}const Ds=function(t,e,n){var i=!0,r=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return $(n)&&(i="leading"in n?!!n.leading:i,r="trailing"in n?!!n.trailing:r),di(t,e,{leading:i,maxWait:e,trailing:r})}(function(){requestAnimationFrame(Ts)},500);var Os=new class{add(t){Ps(t)&&-1==Cs.indexOf(t)&&(Cs.push(t),t.touch()),this.touch()}remove(t){const e=Cs.indexOf(t);e>0&&Cs.splice(e,1),this.touch()}touch(){null!==Es&&(clearTimeout(Es),Es=null),Ds()}dispose(){Ds.cancel(),null!==Es&&(clearTimeout(Es),Es=null),Cs=[]}get length(){return Cs.length}};const zs=function(t){return t};function Is(t){const e=t.indexOf("||");let n="",i="";-1!=e&&(n=t,i=t.substring(e+2,t.length-1).trim(),t=t.replace(t.substring(e,t.length-1),"").trim());const r=t.substr(2,t.length-3).trim().replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".").filter(t=>!!t.trim()),s=r.slice(1);return{defaultValue:i,match:t,originText:n||t,target:r[0],accessor:s.length>0?function(t){return s.reduce((t,e)=>t?t[e]:void 0,t)}:zs}}function Ls(t){if(!t)return;const e=String(t),n=(e.match(/#{(\S*)}/)||[]).map(t=>Is(t))[0];if(n)return n.accessor(this.getState(n.target));const i=(e.match(/\${[^}]*}/)||[]).map(t=>Is(t))[0];if(i){const t=this.root.findById(i.target);return i.accessor(this.getState(t))}return t}function js(t,e){if(!t)return;const n=String(t),i=e||vi,r=(n.match(/#{(\S*)}/gi)||[]).map(t=>Is(t)),s=(n.match(/\${[^}]*}/gi)||[]).map(t=>Is(t));if(0==r.length&&0==s.length)return n;let o=n;return r.forEach(t=>{const e=i(t.accessor(this.getState(t.target)));o=o.replace(t.match,void 0===e?"":e)}),s.forEach(t=>{const e=this.root.findById(t.target),n=i(t.accessor(e&&e.data));o=o.replace(t.match,void 0===n?"":n)}),o}function Rs(t,e,n){if(!t)return;const i=n||vi,r=String(t),s=(r.match(/#{[^}]*}/gi)||[]).map(t=>Is(t)),o=(r.match(/\${[^}]*}/gi)||[]).map(t=>Is(t));return 0!=s.length||0!=o.length?function(){let t=r;return s.forEach(n=>{const r=i(n.accessor(e.getState(n.target)));t=t.replace(n.originText,void 0===r?n.defaultValue||"":r)}),o.forEach(n=>{const r=e.root.findById(n.target),s=i(n.accessor(r&&r.data));t=t.replace(n.originText,void 0===s?n.defaultValue||"":s)}),t}:void 0}class Fs{constructor(){}static registerDecorator(t,e){Fs.constructors.set(t,e)}static create(t,e,n={},i){const r=Fs.constructors.get(t);if(!r)throw new Error(`unknown decorator type: ${t}`);return new r(i,e,n)}}Fs.constructors=new Map;class Bs{constructor(){this.overlays=new WeakMap}static getInstance(){return Bs.instance||(Bs.instance=new Bs),Bs.instance}addOverlay(t){if(this.overlays.has(t))return!1;const e={element:t,registry:new Map};return this.overlays.set(t,e),!0}removeOverlay(t){if(!this.overlays.has(t))return!1;const e=this.overlays.get(t);for(const[n]of e.registry)this.removeFromOverlay(t,n);return this.overlays.delete(t),!0}addToOverlay(t,e,n,i={}){this.overlays.has(t)||this.addOverlay(t);const r=this.overlays.get(t);r.registry.has(e)||r.registry.set(e,new Map);const s=r.registry.get(e);s.has(n)&&s.get(n).stop();const o=Fs.create(n,e,i,t);return s.set(n,o),e?.root?.app?.suppressAnimations||o.start(),o}removeFromOverlay(t,e,n){if(!this.overlays.has(t))return;const i=this.overlays.get(t);if(!i.registry.has(e))return;const r=i.registry.get(e);let s=null;if(n){if(r.has(n))try{const t=r.get(n);s=n,t&&"function"==typeof t.stop&&t.stop(),r.delete(n)}catch(t){Ki(`데코레이터(${n}) 제거 중 오류:`,t)}}else{const t=Array.from(r.keys());for(const e of t)try{const t=r.get(e);t&&"function"==typeof t.stop&&t.stop(),r.delete(e)}catch(t){Ki(`데코레이터(${e}) 제거 중 오류:`,t)}s="_all_"}0===r.size&&i.registry.delete(e),!s||"data-spread"!==s&&"_all_"!==s||this.restartBorderAnimations(t,e)}restartBorderAnimations(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);for(const[t,i]of n.registry.entries()){if(e&&t===e)continue;const n=i.get("border-highlighting");if(n)try{"function"==typeof n.invalidate&&n.invalidate();const t=n;"function"==typeof t.startAnimations&&t.options&&t.options.animation&&t.startAnimations()}catch(t){Ki("애니메이션 재시작 중 오류:",t)}}}removeAllFromOverlay(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);if(e)for(const[i]of n.registry)this.removeFromOverlay(t,i,e);else{for(const[t,e]of n.registry)for(const t of e.values())t.stop();n.registry.clear()}}getDecoratorFromOverlay(t,e,n){const i=this.overlays.get(t);return i?.registry.get(e)?.get(n)}getDecoratorsFromOverlay(t,e){const n=this.overlays.get(t);return n&&n.registry.has(e)?Array.from(n.registry.get(e).values()):[]}getTargetsWithType(t,e){const n=this.overlays.get(t);if(!n)return[];const i=[];for(const[t,r]of n.registry)r.has(e)&&i.push(t);return i}updateInOverlay(t,e,n,i){const r=this.getDecoratorFromOverlay(t,e,n);r&&r.update(i)}invalidateOverlay(t){if(!this.overlays.has(t))return;const e=this.overlays.get(t),n=Array.from(e.registry.entries());for(const[e,i]of n){if(e.disposed){this.removeFromOverlay(t,e);continue}this.getDecoratorsFromOverlay(t,e).forEach(t=>{t.invalidate()})}}}function Ns(t,e){return!1}function Hs({x:t,y:e},...n){const i=this.path,r=t,s=e;this.path=i.map(t=>({x:t.x+r,y:t.y+s}))}function Ys(t){const e=t??this.center.x,{rotation:n}=this.state,i=this.fillStyle;if(this.set("rotation",2*Math.PI-n),i&&"gradient"===i.type&&"linear"===i.gradientType){const t=Jn(i);t.rotation=(Math.PI-parseFloat(i.rotation||0))%(2*Math.PI),this.set("fillStyle",t)}this.path=this.path.map(t=>({x:2*e-t.x,y:t.y}))}function Vs(t){this.symmetryX(),this.set("rotation",(Math.PI+this.model.rotation)%(2*Math.PI)),t&&this.move({x:0,y:2*(t-this.center.y)},!1)}function Gs(t,e,n){if(n){const e=this.bounds,n=e.height/e.width;let i=t.width-e.width,r=t.height-e.height;i*n>r?r=i*n:i=r/n;let s=t.left-e.left,o=t.top-e.top;return 0!=s&&0!=o?(o=-r,s=-i):0!=s?s=-i:0!=o&&(o=-r),{left:e.left+s,top:e.top+o,width:e.width+i,height:e.height+r}}return t}function Us(t,e){if(e||this.app.rotateStepForced){const e=this.app.rotateStep;return Math.floor((t+e/2)/e)*e}return t}function Ws(t){return function(t,e){const n=t.path.slice();if(!n||!n.length)return void Ki("path should not be empty");let i=1;const r=[];if(t.isLine()||n.push(n[0]),e<=0)return t.toScene(n[0].x,n[0].y);if(e>=1)return t.toScene(n[n.length-1].x,n[n.length-1].y);for(;n[i];){const t=n[i-1],e=n[i],s=e.x-t.x,o=e.y-t.y;r.push(Math.sqrt(s*s+o*o)),i++}const s=r.reduce(function(t,e){return t+e},0);i=0;let o=0;do{o+=r[i++]}while(o/s<e);o-=r[--i],e=(e-o/s)*(s/r[i]);const a=n[i%n.length],c=n[(i+1)%n.length],l=a.x+Math.round((c.x-a.x)*e),h=a.y+Math.round((c.y-a.y)*e);return t.toScene(l,h)}(this,t||0)}function Xs(){const t=this.path;let e,n,i,r;e=n=t[0].x,i=r=t[0].y;for(let s=1;s<t.length;s++){const o=t[s];o.x<e?e=o.x:o.x>n&&(n=o.x),o.y<i?i=o.y:o.y>r&&(r=o.y)}return{left:e,top:i,width:n-e,height:r-i}}function qs(t){const e=this.bounds;if(Math.round(100*t.width)/100==Math.round(100*e.width)/100&&Math.round(100*t.height)/100==Math.round(100*e.height)/100&&Math.round(100*t.left)/100==Math.round(100*e.left)/100&&Math.round(100*t.top)/100==Math.round(100*e.top)/100)return;const n=0==e.width?1:t.width/e.width,i=0==e.height?1:t.height/e.height;this.path=this.path.map(r=>({x:t.left+(r.x-e.left)*n,y:t.top+(r.y-e.top)*i}))}function Ks(){const t=this.bounds;return{x:t.left+t.width/2,y:t.top+t.height/2}}function $s(t){if(!t||isNaN(t.x)||isNaN(t.y))return;const e=this.center;if(Math.round(100*t.x)/100==Math.round(100*e.x)/100&&Math.round(100*t.y)/100==Math.round(100*e.y)/100)return;const n=t.x-e.x,i=t.y-e.y;this.path=this.path.map(t=>({x:t.x+n,y:t.y+i}))}function Qs(){const{x:t,y:e}=this.center;return{x:t,y:e,z:this.state.zPos}}function Zs(t){const{x:e,y:n,z:i}=t||{};this.center={x:e,y:n},isNaN(i)||this.setState("zPos",Number(i))}function Js(){const{rotationX:t,rotationY:e,rotation:n}=this.state;return{x:t,y:e,z:-n}}function to(t){const{x:e,y:n,z:i}=t;this.setState({rotationX:e,rotationY:n,rotation:-i})}function eo(){const{width:t,height:e}=this.bounds,{depth:n}=this.state;return{width:t,height:e,depth:n}}function no(t){const{width:e,height:n,depth:i}=t,{top:r,left:s}=this.bounds;this.bounds={top:r,left:s,width:e,height:n},this.setState("depth",i)}function io(){return Ki("이 컴포넌트에 get path 가 구현되어있지 않음.",this),[]}function ro(t){Ki("이 컴포넌트에 get path 가 구현되어있지 않음.",this)}function so(){return this.path}function oo(){return this.center}function ao(){return this.nature.mutable}function co(){return this.nature.resizable&&!this.stuck}function lo(){return this.nature.rotatable&&!this.stuck}const ho={x:1,y:1};function uo(t,e,n){const{left:i=0,top:r=0,blurSize:s=0,color:o="transparent"}=e,a=n.rootModel.get("scale")||ho;t.shadowOffsetX=i*a.x*Hr,t.shadowOffsetY=r*a.y*Hr,t.shadowBlur=s*a.x*Hr,t.shadowColor=o}function po(t){t.save(),this.prerender(t),this.render(t),this.postrender(t),t.restore()}function fo(t){const e=this.rotatePoint,{scale:n,rotation:i,shadow:r,alpha:s}=this.state,o=(n&&n.x||1)*this._delta.sx,a=(n&&n.y||1)*this._delta.sy,c=(i||0)+this._delta.theta,{tx:l=0,ty:h=0}=this._delta,d=(s||1)-this._delta.fade;(l||h)&&t.translate(l,h),(1!=o||1!=a||c)&&(t.translate(e.x,e.y),1==o&&1==a||t.scale(o,a),c&&t.rotate(c),t.translate(-e.x,-e.y)),d&&(t.globalAlpha=d),r&&uo(t,r,this),this.app.isEditMode&&this.hidden&&(t.globalAlpha*=.5)}function go(t){}function mo(t){this.drawText(t)}function yo(t,e){t(this)}function bo(t){t&&this.prepare&&this.prepare(t=>{this.invalidate()},t=>{Ki(t)})}function vo(t){!this.textHidden&&this.text&&this.hasTextProperty&&ss(t,this.textBounds,this.textLines(t),this.state)}function _o(t,e){Zr(t,e?{...this.state,...e}:this.state)}function xo(t,e){this.fillStyle&&"transparent"!=this.fillStyle&&(qr(t,this.bounds,this.center,e?{...this.state,...e}:this.state,this),function(t){t.shadowColor="transparent"}(t))}function wo(){return this.get("strokeStyle")}function Mo(t){this.set("strokeStyle",t)}function So(){return this.getState("fillStyle")}function ko(t){this.setState("fillStyle",t)}function Ao(){return this.get("fontColor")}function Eo(t){this.set("fontColor",String(vi(t)))}function Co(){return this.getState("rotation")}function To(t){this.setState("rotation",Number(vi(t)))}function Po(){return this.app.isEditMode?["decotag","data-spread"]:[]}function Do(){const{id:t,tag:e}=this.state;return(t?`#${t}`:"")+(e?`@${e}`:"")}function Oo(){return this.getState("hidden")||!this.data&&0!==this.data&&this.getState("ndns")||this.isTemplate()}function zo(t){this.setState("hidden",t)}function Io(){return this.state.tag}function Lo(t){this.setState("tag",t)}function jo(){}function Ro(t){this.data instanceof Array?this.data=this.data.concat(t):this.data instanceof Object?this.data={...this.data,...t}:this.data??=t}function Fo(){const t=this.getState("text");return null==t?"":String(t)}function Bo(t){const{textWrap:e,supportMarkdown:n}=this.state;return ns(t||this.getContext(),this.textBounds.width,this.font,this.text,e,n)}function No(){return is(this.model)}function Ho(){const t=this.get("lineHeight");return t||1.2*this.fontSize}function Yo(){return this._text_substitutor||(this._text_substitutor=Rs(this.getState("text"),this,void 0)||this.defaultTextSubstitutor),this._text_substitutor}function Vo(){const t=this.get("textFormat");return t?function(t,e){if(!t||isNaN(+e))return e;let n,i,r,s,o,a,c,l,h,d,u,p=t.length,f=t.search(/[0-9\-\+#]/),g=f>0?t.substring(0,f):"",m=t.split("").reverse().join(""),y=m.search(/[0-9\-\+#]/),b=p-y,v=t.substring(b,b+1),_=b+("."===v||","===v?1:0),x=y>0?t.substring(_,p):"";if(n=(e="-"===(t=t.substring(f,_)).charAt(0)?-e:+e)<0?e=-e:0,i=t.match(/[^\d\-\+#]/g),r=".",s=i&&i[1]&&i[0]||",",t=t.split("."),e=+(e=e.toFixed(t[1]&&t[1].length))+"",a=t[1]&&t[1].lastIndexOf("0"),l=e.split("."),(!l[1]||l[1]&&l[1].length<=a)&&(e=(+e).toFixed(a+1)),h=t[0].split(s),t[0]=h.join(""),o=t[0]&&t[0].indexOf("0"),o>-1)for(;l[0].length<t[0].length-o;)l[0]="0"+l[0];else 0===+l[0]&&(l[0]="");if((e=e.split("."))[0]=l[0],c=h[1]&&h[h.length-1].length,c){for(d=e[0],m="",b=d.length%c,p=d.length,_=0;_<p;_++)m+=d.charAt(_),!((_-b+1)%c)&&_<p-c&&(m+=s);e[0]=m}return e[1]=t[1]&&e[1]?"."+e[1]:"",i=e.join(""),"0"!==i&&""!==i||(n=!1),u="+"==t[0].substring(0,1)?n?"-":"+":n?"-":"",g+(u+i)+x}(t,this.textSubstitutor()):this.textSubstitutor()}function Go(t){delete this._text_substitutor;const e=vi(t);this.setState("text",null==e?"":String(e))}function Uo(){let{paddingTop:t,paddingLeft:e,paddingRight:n,paddingBottom:i}=this.state;i||=0,t||=0,e||=0,n||=0;const{left:r,top:s,width:o,height:a}=this.bounds;return{left:r+e,top:s+t,width:Math.max(o-e-n,0),height:Math.max(a-t-i,0)}}function Wo(){return 0}function Xo(){return!!this._textHidden}function qo(t){this._textHidden=!!t,this.invalidate()}function Ko(){return!0}function $o(t){return t}function Qo(t){return Math.pow(t,2)}function Zo(t){return 1-Math.sin(Math.acos(t))}function Jo(t,e={x:1.5}){return Math.pow(t,2)*((e.x+1)*t-e.x)}function ta(t){for(let e=0,n=1;;e+=n,n/=2)if(t>=(7-4*e)/11)return-Math.pow((11-6*e-11*t)/4,2)+Math.pow(n,2)}function ea(t,e={x:1.5}){return Math.pow(2,10*(t-1))*Math.cos(20*Math.PI*e.x/3*t)}var na={linear:$o,quad:Qo,circ:Zo,back:Jo,bounce:ta,elastic:ea},ia=Object.freeze({__proto__:null,back:Jo,bounce:ta,circ:Zo,default:na,elastic:ea,linear:$o,quad:Qo});function ra(t){const{duration:e=1e3,easing:n,component:i,step:r=()=>{},onStart:s,onProgress:o,onComplete:a,options:c,repeat:l=!1,delta:h}=t;let d;d="string"==typeof h?ia[h]:h||$o,"out"===n?d=function(t,e){return function(n){return 1-t(1-n,e)}}(d,c):"inout"===n&&(d=function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(d,c));let u=!1,p=null;return{start:function(){if(u)return this;if(i?.root?.app?.suppressAnimations)return this;u=!0,s&&s();let t=0;const n=()=>{if(!u)return;if(i?.root?.app?.suppressAnimations)return this.stop(),void(t=0);0===t&&(t=performance.now());const s=(performance.now()-t)/e,a=l?s%1:Math.min(s,1);r(d(a,c)),o&&o(a),!(s>=1)||l&&u||(this.stop(),t=0),u&&(p=requestAnimationFrame(n))};return p=requestAnimationFrame(n),this},stop:function(){return u=!1,null!==p&&(cancelAnimationFrame(p),p=null),a&&a(),this}}}class sa{constructor(t,e){this._started=!1,this._raf=null,this._timeout=null,this.client=t,this.config=e,this._started=!1;const{delta:n="linear",options:i,ease:r}=this.config;let s;s="string"==typeof n?na[n]:n,this.delta="out"===r?function(t,e){return function(n){return 1-t(1-n,e)}}(s,i):"inout"===r?function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(s,i):s,this.init()}dispose(){this.stop(),delete this.client}init(){}start(){if(this._started)return;if(this.client?.root?.app?.suppressAnimations)return;const{duration:t=2e3,delay:e=0,repeat:n=!1,interval:i=0,onComplete:r}=this.config;this._started=!0;let s=0,o=0;const a=()=>{if(this._raf=null,this._timeout=null,!this._started)return;if(this.client?.root?.app?.suppressAnimations)return void this.stop(r);0==s&&(s=performance.now(),this.client?.touch?.());const c=performance.now()-s,l=Math.max((c-e)%(t+i),0)/t,h=i<=0&&o>l;if(o=l,l>=1||h){if(this.step(1),this.client&&this.client.invalidate?.(),!n||!this._started)return this.stop(r),void(s=0);if(i>0)return void(this._timeout=setTimeout(()=>{this.step(0),this.client&&this.client.invalidate?.(),this._timeout=setTimeout(a,i/2)},i/2))}else this.step(this.delta(l)),this.client&&this.client.invalidate?.();this._raf=requestAnimationFrame(a)};this._raf=requestAnimationFrame(a)}stop(t){this._raf&&cancelAnimationFrame(this._raf),this._timeout&&clearTimeout(this._timeout),this._raf=null,this._timeout=null,this._started=!1,t?.()}step(t){}get started(){return this._started}set started(t){this.started!=!!t&&(t?this.start():this.stop())}}const oa={rotation:class extends sa{step(t){const{theta:e=6.28}=this.config;this.client.delta?.("theta",t*e)}},vibration:class extends sa{step(t){const{theta:e=.2617993877991494}=this.config,n=4*e;let i=t*n;t<1/4?i*=-1:t<3/4?i-=2*e:i=n-i,this.client.delta?.("theta",i)}},heartbeat:class extends sa{step(t){const{scale:e=1.3}=this.config,n=2*(e-1);let i;i=t<.5?1+n*t:1+(1-t)*n,this.client.delta?.({sx:i,sy:i,sz:i})}},moving:class extends sa{step(t){const{x:e=0,y:n=0}=this.config;this.client.delta?.({tx:t*e,ty:t*n})}},outline:class extends sa{step(t){const{rideOn:e}=this.config;if(!e||!this.client)return;const n=this.client.root.findById(e);if(!n)return;let i={tx:0,ty:0};const r=this.client.delta("");r&&"object"==typeof r&&"tx"in r&&"ty"in r&&(i=r);const{tx:s,ty:o}=i,a=n.outline(t),{x:c,y:l}=this.client.center,h=this.client.toScene(c,l);this.client.delta({tx:a.x-h.x+s,ty:a.y-h.y+o})}},fade:class extends sa{step(t){const{startAlpha:e=1,endAlpha:n=0}=this.config,i=Math.max(Math.min(e,n,1),0),r=2*(Math.min(Math.max(e,n,1),1)-i);let s;s=t<.5?r*t:(1-t)*r,this.client.delta?.("fade",s)}},waypoint:class extends sa{start(){let{toComponent:t,fromComponent:e}=this.config;e||(e=t);const n=e.center,i=t.center,{x:r,y:s}=e.toScene(n.x,n.y),{x:o,y:a}=t.toScene(i.x,i.y),c=Math.atan2(a-s,o-r)+Math.PI/2;this.client.location={x:r,y:s},this.client.setState("rotation",c),super.start()}stop(){const{toComponent:t}=this.config;super.stop();const e=t.center,n=t.toScene(e.x,e.y);this.client.delta({tx:0,ty:0}),this.client.location=n}step(t){let{toComponent:e,fromComponent:n}=this.config;n||(n=e);const i=n.center,r=e.center,{x:s,y:o}=n.toScene(i.x,i.y),{x:a,y:c}=e.toScene(r.x,r.y),l=(a-s)*t,h=(c-o)*t;this.client.location={x:s+l,y:o+h}}}};function aa(t,e){const n=e.type?oa[e.type]:void 0;return n?new n(t,e):null}const ca={gradation:function(t,e,n){const{subType:i,from:r,to:s,colors:o}=n;let a;switch(i){case"linear":default:a=e.createLinearGradient(r.x,r.y,s.x,s.y);break;case"radial":a=e.createRadialGradient(r.x,r.y,r.r,s.x,s.y,s.r)}o&&(o.forEach(function(t){a.addColorStop(t.endPoint,t.color)}),e.fillStyle=a,e.fill())},shadow:uo};function la(t){return this._animate&&this._animate.stop(),this._animate=ra(t),this._animate}function ha(t,e){return function(t,e,n){const i=ca[n.type];i&&i(t,e,n)}(this,t,e)}const da=100;function ua(t,e){return"number"!=typeof e||Number.isInteger(e)?e:Math.round(e*da)/da}function pa(t){if(null==t||"object"!=typeof t)return t;for(const e in t){const n=t[e];"number"!=typeof n||Number.isInteger(n)?null!=n&&"object"==typeof n&&pa(n):t[e]=Math.round(n*da)/da}return t}function fa(...t){return JSON.stringify(this.hierarchy,ua,...t)}function ga(){delete this._model[""],"chartjs"!==this._model.type&&delete this._model.chart}function ma(t){this.rootModel.closeScene(t)}function ya(t,e){return t?"object"==typeof t?(this._delta={...this._delta,...t},this._delta):void 0!==e?(this._delta[t]=e,this._delta[t]):void 0:this._delta}function ba(){this.parent&&this.parent.invalidate()}function va(){const t=this.nature["value-property"]||"text";return"value"==t?this.getState("value"):this[t]}function _a(t){const e=this.nature["value-property"]||"text";"value"==e?this.setState("value",t):this[e]=t}function xa(){return this.getState("data")}function wa(t){this.setState("data",t),this.touch()}function Ma(t){const e=this.model.event?.tap;if(e){const{x:t,y:n}=this.center;this.rootModel?._doEventAction(e,this,!0,new MouseEvent("click",{clientX:t,clientY:n}))}}function Sa(){return!this._mappings&&this.parent&&this.buildMappings(),this._mappings}function ka(){return Number(this.get("retention"))||0}function Aa(){if(this.app.isViewMode&&!this.isTemplate()){if(!this._animation){const t=this.state.animation;t&&t.oncreate&&(this._animation=aa(this,t.oncreate))}return this._animation}}function Ea(){return!!this.animation?.started}function Ca(t){this.animation&&(this.animation.started=t)}function Ta(){}function Pa(t,e,n,i){const r=e.get("class");if(!r)return!1;return(r.split(" ")||[]).indexOf(t.substr(1))>=0}function Da(t,e,n,i){return t==e.get("type")}function Oa(t,e,n,i){if("(all)"==t)return!0;switch(t.charAt(0)){case"#":return function(t,e){return t.substring(1)==e.get("id")}(t,e);case".":return Pa(t,e);case"(":return function(t,e,n,i){switch(t){case"(all)":return!0;case"(self)":return i===e;case"(root)":return!i.parent&&i===e;case"(descendant)":return i!==e;case"(child)":return i===e.parent;default:return!1}}(t,e,0,i);default:return Da(t,e)}}function za(t,e,n,i,r,s){return t(e,n,i,r)&&s.push(n),n.components&&n.components.forEach(n=>{za(t,e,n,i,r,s)}),s}function Ia(t,e,n,i){switch(t){case"(all)":return!0;case"(parent)":return n&&n.parent===e;case"(child)":case"(children)":return n&&n===e.parent;case"(sibling)":case"(siblings)":return n&&n.parent===e.parent&&n!==e;default:return!1}}function La(t,e,n){if("(root)"==t)return[e];if("(self)"==t)return n?[n]:[];let i;switch(t.charAt(0)){case"#":const n=e.root.findAllById?.(t.substring(1));return n||[];case".":i=Pa;break;case"(":i=Ia;break;default:i=Da}return za(i,t,e,n,e,[])}function ja(t,...e){if(t(this,...e))return this}function Ra(t,...e){return"string"==typeof t?La(t,this,e[0]||this):"function"==typeof t&&t(this,...e)?[this]:void 0}function Fa(t,e,n){if(!this.capturable||n?.(this))return!1;const i=this.fromParent(t,e);return this.contains(i.x,i.y)?this:void 0}function Ba(t){return this.anchors.find(e=>e.name===t)}function Na(t){return!0}function Ha(t){return this._parent.getContext(t??this)}function Ya(){return this.isRoot()?this:this.parent&&this.parent.root}function Va(){return this.isRootModel()?this:this.parent&&this.parent.rootModel}function Ga(){return this._parent}function Ua(t){this._parent=t}function Wa(){return this.nature.anchors||[]}function Xa(){let t=this.position,e=this;for(;"static"===t&&e.parent;)e=e.parent,t=e.position;return"static"==t}function qa(){return!!(this.parent&&this.parent.layout.isStuck(this)||this.get("locked"))}function Ka(){return!1!==this.get("capturable")&&(this.app.isEditMode||!this.hidden)}function $a(){return this.app?.isViewMode&&this.isPositionable()?this.state.position??"static":"static"}function Qa(){return this.app&&this.app.isViewMode&&this.state.origin||""}function Za(){const{offsetX:t=0,offsetY:e=0}=this.state;return{x:t,y:e}}function Ja(){return!this._app&&this.parent&&(this._app=this.parent.app),this._app}const tc={},ec={mutable:!1,resizable:!0,rotatable:!0,properties:[],"value-property":"text"},nc=[],ic=new Set(["data","text","value","source","accessor","mappings","variables","fillStyle","strokeStyle","fontColor","alpha","opacity","hidden","locked","hatched","started","animation","sensitive","event","src","href","url","class","templatePrefix"]),rc={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0};let sc=0;const oc={};const ac=new FinalizationRegistry(t=>{!function(t){sc--;let e=oc[t];e||(e=oc[t]={up:0,down:0}),e.down++}(t)});class cc{static get nature(){return ec}static register(t,e){if(!e)return tc[t];tc[t]=e}static get residents(){return oc}static get residentsCount(){return sc}static registerDecorator(t,e){Fs.registerDecorator(t,e)}constructor(t,e){this._app=e,this._model=t||{},this._state={},this._delta=Jn(rc),e&&this.animation?.config&&(1==this.animation.config.autoplay||(this.animation.config.autoplay??1))&&(this.animation.started=!0),this.clearCache(),Os.add(this),function(t){sc++;let e=oc[t];e||(e=oc[t]={up:0,down:0}),e.up++}(this._model.type),ac.register(this,this._model.type)}created(){}added(t){}removed(t){}async ready(){if(this.state.persistent){const{isViewMode:t,dataStorage:e}=this.app;t&&(this.data=await e.load(this))}}touch(){this.updatedAt=performance.now()}clearCache(...t){this._cachedState=null,function(t,...e){0==e.length?t.__cache__={}:e.forEach(e=>delete t.__cache__[e])}(this,...t)}removeSelf(t){t?this.dispose():this.parent?.removeComponent?.(this)}resetAnimation(){this._animation&&(this._animation.dispose(),this._animation=null,this._delta=Jn(rc))}dispose(){this.resetAnimation(),this.disposeMappings(),this.parent?.removeComponent?.(this),delete this._text_substitutor,delete this._value_substitutor,this._disposed=!0,this._realObject&&(this._realObject.dispose(),this._realObject=void 0),this.retention&&Os.touch(),this.clearCache(),delete this._app}get nature(){return this.constructor.nature}get disposed(){return!!this._disposed}isLayer(){return!1}isGroup(){return!1}isContainer(){return!1}isLine(){return!1}isRoot(){return!1}isRootModel(){return!1}is3dish(){return!0}get is3dMode(){return!1}isIn3DSpace(){return!!this._realObject}isTemplate(){return!!this.get("templatePrefix")}isHTMLElement(){return!1}isConnectable(){return!1}isIdentifiable(){return!0}isPositionable(){return this.parent?.isRootModel()}replaceRefids(t){}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=this;return this._applyProps(this._model,t,{getBeforeVal:function(t){return n._model[t]},clearState:!0,sensitive:!1,beforeFillStyle:function(t,e){t.hasOwnProperty("retention")&&Os.add(n)},afterFillStyle:function(t,e){t.hasOwnProperty("mappings")&&n.onchangeMappings(t,e)}})}getState(t){return this._state.hasOwnProperty(t)?this._state[t]:this.get(t)}setState(t,e){if("string"==typeof t)return this.setState({[t]:e});const n=this;return this._applyProps(this._state,t,{getBeforeVal:function(t){return n.getState(t)},clearState:!1,sensitive:this.getState("sensitive")})}get model(){return this._model}get state(){return this._cachedState||(this._cachedState=Object.freeze(Object.assign({},this._model,this._state))),this._cachedState}get hierarchy(){const t=Jn(this._model);return this.volatile.forEach(e=>{delete t[e]}),pa(t)}get volatile(){return nc}_applyProps(t,e,n){const i={},r={};let s=!1;const o=Jn(e),a=this;if(Object.getOwnPropertyNames(o).forEach(function(e){const c=n.getBeforeVal(e),l=o[e];!n.sensitive&&function(t,e){return Oe(t,e)}(c,l)||(r[e]=c,i[e]=l,t[e]=l,n.clearState&&delete a._state[e],s=!0)}),s){this._cachedState=null;Object.keys(i).some(t=>!ic.has(t))&&this.clearCache(),i.hasOwnProperty("text")&&delete this._text_substitutor,n.beforeFillStyle&&n.beforeFillStyle(i,r),i.hasOwnProperty("fillStyle")&&this.onchangeFill(i,r),n.afterFillStyle&&n.afterFillStyle(i,r),i.hasOwnProperty("data")&&this.onchangeData(i,r),this.onchange&&this.onchange(i,r),this.trigger("change",i,r)}return this}contains(t,e){return Ns.call(this,t,e)}move(t,...e){Hs.call(this,t,...e)}symmetryX(t){Ys.call(this,t)}symmetryY(t){Vs.call(this,t)}adjustResize(t,e,n){return Gs.call(this,t,e,n)}adjustRotation(t,e){return Us.call(this,t,e)}outline(t){return Ws.call(this,t)}get bounds(){return Xs.call(this)}set bounds(t){qs.call(this,t)}get center(){return Ks.call(this)}set center(t){$s.call(this,t)}get location(){return Qs.call(this)}set location(t){Zs.call(this,t)}get rotate(){return Js.call(this)}set rotate(t){to.call(this,t)}get dimension(){return eo.call(this)}set dimension(t){no.call(this,t)}get path(){return io.call(this)}set path(t){ro.call(this,t)}get drawPath(){return so.call(this)}get rotatePoint(){return oo.call(this)}get mutable(){return ao.call(this)}get resizable(){return co.call(this)}get rotatable(){return lo.call(this)}buildRealObject(){}get realObject(){return this.disposed||this._realObject||(this._realObject=this.buildRealObject(),this._realObject&&(this._realObject.update(),this._realObject.updateTransform())),this._realObject}draw(t){t&&po.call(this,t)}prerender(t){fo.call(this,t)}render(t){go.call(this,t)}postrender(t){mo.call(this,t)}prepare(t,e){yo.call(this,t,e)}prepareIf(t){bo.call(this,t)}drawText(t){vo.call(this,t)}drawStroke(t,e){_o.call(this,t,e)}drawFill(t,e){xo.call(this,t,e)}get strokeStyle(){return wo.call(this)}set strokeStyle(t){Mo.call(this,t)}get fillStyle(){return So.call(this)}set fillStyle(t){ko.call(this,t)}get fontColor(){return Ao.call(this)}set fontColor(t){Eo.call(this,t)}get rotation(){return Co.call(this)}set rotation(t){To.call(this,t)}get decorators(){return Po.call(this)}get decotag(){return Do.call(this)}get hidden(){return Oo.call(this)}set hidden(t){zo.call(this,t)}get tag(){return Io.call(this)}set tag(t){Lo.call(this,t)}get appendum(){return jo.call(this)}set appendum(t){Ro.call(this,t)}defaultTextSubstitutor(){return Fo.call(this)}textLines(t){return Bo.call(this,t)}get font(){return No.call(this)}get lineHeight(){return Ho.call(this)}get textSubstitutor(){return Yo.call(this)}get text(){return Vo.call(this)}set text(t){Go.call(this,t)}get textBounds(){return Uo.call(this)}get textRotation(){return Wo.call(this)}get textHidden(){return Xo.call(this)}set textHidden(t){qo.call(this,t)}get hasTextProperty(){return Ko.call(this)}animate(t){return la.call(this,t)}effect(t,e){return ha.call(this,t,e)}serialize(...t){return fa.call(this,...t)}trim(){ga.call(this)}closeScene(t){ma.call(this,t)}delta(t,e){return ya.call(this,t,e)}invalidate(){ba.call(this)}get value(){return va.call(this)}set value(t){_a.call(this,t)}get data(){return xa.call(this)}set data(t){wa.call(this,t)}set tap(t){Ma.call(this,t)}get mappings(){return Sa.call(this)}get retention(){return ka.call(this)}get animation(){return Aa.call(this)}get started(){return Ea.call(this)}set started(t){Ca.call(this,t)}get controls(){return Ta.call(this)}findFirst(t,...e){return ja.call(this,t,...e)}findAll(t,...e){return Ra.call(this,t,...e)}capture(t,e,n){return Fa.call(this,t,e,n)}findAnchor(t){return Ba.call(this,t)}isDescendible(t){return Na.call(this,t)}getContext(t){return Ha.call(this,t)}get root(){return Ya.call(this)}get rootModel(){return Va.call(this)}get parent(){return Ga.call(this)}set parent(t){Ua.call(this,t)}get anchors(){return Wa.call(this)}get scalable(){return Xa.call(this)}get stuck(){return qa.call(this)}get capturable(){return Ka.call(this)}get position(){return $a.call(this)}get origin(){return Qa.call(this)}get offset(){return Za.call(this)}get app(){return Ja.call(this)}drawEffect(t){Dr.call(this,t)}prepareFill(t,e){Kr.call(this,t,e)}prepareFillIf(t){$r.call(this,t)}onchangeFill(t,e){Qr.call(this,t,e)}drawImage(t,e,n,i,r,s){Pr.call(this,t,e,n,i,r,s)}mutateBounds(t,e){ks.call(this,t,e)}mutatePath(t,e,n){As.call(this,t,e,n)}access(t){return Ls.call(this,t)}substitute(t,e){return js.call(this,t,e)}onchangeMappings(t,e){Tr.call(this,t,e)}onchangeData(t,e){Ar.call(this,t,e)}buildMappings(){Er.call(this)}executeMappings(t){kr.call(this,t)}disposeMappings(){Cr.call(this)}ondropfile(t,e){as.call(this,t,e)}transcoordS2P(t,e,n){return us.call(this,t,e,n)}transcoordP2S(t,e,n){return ds.call(this,t,e,n)}transcoordS2T(t,e,n){return fs.call(this,t,e,n)}transcoordT2P(t,e,n){return gs.call(this,t,e,n)}transcoordT2S(t,e,n){return ms.call(this,t,e,n)}transcoordS2TR(t,e,n){return ps.call(this,t,e,n)}transcoordS2O(t,e,n){return ys.call(this,t,e,n)}transcoordC2S(t,e,n){return bs.call(this,t,e,n)}transcoordS2C(t,e,n){return vs.call(this,t,e,n)}toParent(t,e,n){return us.call(this,t,e,n)}fromParent(t,e,n){return ds.call(this,t,e,n)}toScene(t,e,n){return fs.call(this,t,e,n)}fromScene(t,e,n){return ms.call(this,t,e,n)}toLocal(t,e,n){return bs.call(this,t,e,n)}toGlobal(t,e,n){return vs.call(this,t,e,n)}toOther(t,e,n){return ys.call(this,t,e,n)}on(t,e,n){return Yi.call(this,t,e,n)}off(t,e,n){return Vi.call(this,t,e,n)}once(t,e,n){return Gi.call(this,t,e,n)}trigger(t,...e){return Ui.call(this,t,...e)}delegate_on(t){return Wi.call(this,t)}delegate_off(t){return Xi.call(this,t)}onchange(t,e){}removeComponent(t,e){}addComponent(t,e){}insertComponentAt(t,e,n){}getOverlay(t){}findById(t){}findByRefid(t){}findAllById(t){return[]}resize(){}fit(t){}get components(){}get layout(){}get auxOverlay(){}get isReady(){return!1}get unitScale(){return 1}get selected(){return[]}set selected(t){}get focused(){return null}set focused(t){}get hasSameParentForAllSelected(){return!1}set hasSameParentForAllSelected(t){}get fitMode(){}set fitMode(t){}get element(){return null}set element(t){}}cc.union=_s,cc.transcoordR=ls,cc.transcoordRR=hs,cc.createCanvas=Xr,cc.memoize=Zi,cc.mixin=qi,cc.drawText=ss,cc.font=is,cc.textLines=ns,cc.drawStroke=Zr,cc.drawFill=qr,cc.reposition=Ss,cc.RetentionManager=Os,cc.template=function(t,e,n){var i=Mn.imports._.templateSettings||Mn;n&&We(t,e,n)&&(e=void 0),t=_n(t),e=Qe({},e,i,hn);var r,s,o=Qe({},e.imports,i.imports,hn),a=le(o),c=function(t,e){return an(e,function(e){return t[e]})}(o,a),l=0,h=e.interpolate||Tn,d="__p += '",u=RegExp((e.escape||Tn).source+"|"+h.source+"|"+(h===pn?Cn:Tn).source+"|"+(e.evaluate||Tn).source+"|$","g"),p=Dn.call(e,"sourceURL")?"//# sourceURL="+(e.sourceURL+"").replace(/\s/g," ")+"\n":"";t.replace(u,function(e,n,i,o,a,c){return i||(i=o),d+=t.slice(l,c).replace(Pn,un),n&&(r=!0,d+="' +\n__e("+n+") +\n'"),a&&(s=!0,d+="';\n"+a+";\n__p += '"),i&&(d+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),l=c+e.length,e}),d+="';\n";var f=Dn.call(e,"variable")&&e.variable;if(f){if(En.test(f))throw new Error("Invalid `variable` option passed into `_.template`")}else d="with (obj) {\n"+d+"\n}\n";d=(s?d.replace(Sn,""):d).replace(kn,"$1").replace(An,"$1;"),d="function("+(f||"obj")+") {\n"+(f?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(r?", __e = _.escape":"")+(s?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+d+"return __p\n}";var g=on(function(){return Function(a,p+"return "+d).apply(void 0,c)});if(g.source=d,sn(g))throw g;return g},cc.buildSubstitutor=Rs,["rotatePoint","font","lineHeight","retention"].forEach(t=>cc.memoize(cc.prototype,t,!1)),["bounds","center","textBounds"].forEach(t=>cc.memoize(cc.prototype,t,!0));class lc extends cc{set rotationX(t){this.setState("rotationX",t)}get rotationX(){return this.getState("rotationX")}set rotationY(t){this.setState("rotationY",t)}get rotationY(){return this.getState("rotationY")}set rotationZ(t){this.setState("rotation",t)}get rotationZ(){return this.getState("rotation")}set zPos(t){this.setState("zPos",t)}get zPos(){return this.getState("zPos")}set depth(t){this.setState("depth",t)}get depth(){return this.getState("depth")}postrender(t){this.drawFill(t,void 0),this.drawStroke(t,void 0),super.postrender(t)}render(t){const e=this.drawPath,{round:n=0}=this.state;if(!(e.length<=1)){t.beginPath();for(let i=0;i<e.length;i++){const r=e[(i-1+e.length)%e.length],s=e[(i+e.length)%e.length],o=e[(i+1)%e.length];if(r.x===s.x&&r.y===s.y)continue;let a=Math.sqrt((r.x-s.x)*(r.x-s.x)+(r.y-s.y)*(r.y-s.y)),c=0!==a?Math.atan2(r.x-s.x,r.y-s.y):0,l=Math.sin(c)*Math.min(n,a/2)+s.x,h=Math.cos(c)*Math.min(n,a/2)+s.y;const d=n>0||0!==a?{x:l,y:h}:s;a=Math.sqrt((o.x-s.x)*(o.x-s.x)+(o.y-s.y)*(o.y-s.y)),c=0!==a?Math.atan2(o.x-s.x,o.y-s.y):0,l=Math.sin(c)*Math.min(n,a/2)+s.x,h=Math.cos(c)*Math.min(n,a/2)+s.y;const u=n>0||0!==a?{x:l,y:h}:s;0==i?t.moveTo(d.x,d.y):t.lineTo(d.x,d.y),n>0&&t.quadraticCurveTo(s.x,s.y,u.x,u.y)}t.closePath()}}}function hc(t,e,n){return Math.max(0,Math.min(t,Math.min(n,e)/2))}function dc(t){const e=class extends t{contains(t,e){const{left:n,top:i,width:r,height:s,lineWidth:o=0}=this.state,a=o/2;return t<Math.max(n+r,n)+a&&t>Math.min(n+r,n)-a&&e<Math.max(i+s,i)+a&&e>Math.min(i+s,i)-a}set path(t){const e=t[0],n=t[2];this.set({left:e.x,top:e.y,width:n.x-e.x,height:n.y-e.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get anchors(){return function(t){const{left:e,top:n,width:i,height:r}=t.bounds,s=e+i/2,o=n+r/2;return[{name:"TOP",position:{x:s,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:s,y:n+r}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){this.set({left:0,top:0,width:0,height:0,...t})}render(t){let{round:e=0}=this.model;const{left:n,top:i,width:r,height:s}=this.bounds;t.translate(n,i),t.beginPath(),e=hc(e,r,s),e>0?t.roundRect(0,0,r,s,e):t.rect(0,0,r,s),t.translate(-n,-i)}};return Zi(e.prototype,"path",!1),Zi(e.prototype,"bounds",!0),e}const uc={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"textarea",label:"front-side-template",name:"frontSideTemplate",property:{language:"html"}},{type:"textarea",label:"back-side-template",name:"backSideTemplate",property:{language:"html"}},{type:"textarea",label:"style",name:"style",property:{language:"css"}}],help:"scene/component/info-window"};const pc=20;function fc(t,e){const n=t.split(/\s+/),i=n.indexOf(e);return-1!=i?n.splice(i,1):n.splice(-1,0,e),n.join(" ")}class gc extends(dc(lc)){static get image(){return gc._image||(gc._image=new Image,gc._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAY1BMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIAbxiAAAAIHRSTlMA+gPshCwwWFzYCeLRm7QRG6rLeDZI9JOJJDtjb1HAf1sAT80AAAQQSURBVHhe7MCBAAAAAMKw/KkzOMG2BAAAAKeu3lUohIEggO7jQi5qHqpgwML5/6+0F0y02z31FlvMMLKt86QMQ1ined2Evih1hFFjLfRWjgzDOGZ6JSiM00B9EuHALtQxJLiQBmqSBCeSUEuEGzs1BDjSaHxWOKK5Eyz/4SoMV/hp4+vtcPkdwZD/udwevNg7t1xXYRiKmkB7C+ENlPLq8fxHeX+RGjWQ1D45ldcIulBIvCvYJGBEadyTzxAcfY57NBjpLScOO/bzugcTHe7IMwiSLMcdHZhocMcMgTLjjgZM7F1bCJZ2v27ARGzYDwIk2Z+JYGJ/iiwQLMv+JAEThjkmRG64Q0Q+gIiIiIiIiIiIyFy0KRFt0bOJZAWSUigmkQaJaXhENiRnYBEpkZySRSRGcmIWEaQnYhHRSI5mESmQnIJFZIqQmGhiEYEbEnPjGlEGjYTogW/WUkOXENENSqZfEXmDiIiIiIiIiIiIiIiIiIiImq5ETIpRpBpjJCMeKy6Ri0ZS9MQjkmkkJs1YRDokp2MRyZGclkUkQnIiEQltaX3Lzb6yiGTpl2y/avqSAxGgelCOKI+Kc2isL0TUSsZ4EREREREREREREREREREREfnIQzXrNWSRTeNxnlOwIgueIr6AAyE+CpiqMEUK71IDO4E+LluEKYKnKcMUifEsTZgiJZ5lDVNkwJPcqzBFoPF/HplfxL/w6b4EPGv1h18Weya1TL8iIiIeiIiIiIiIiEjkPefxV+5YA9PPHylB+u5aqgZ39H+jKOxrqtu+pkzvr9YbzoZ6w2OFkzcrA3yE4WZlSSyFk54VoA/wR43+FaD+r9w32QdWvgvjp2ty2xq8qHPHmtyPFxfrK3hw1ejERlAlfR/Ame2OTow05d4rOLLSlHtDVhI0uRO01JeZ405op6zgNNXT+bIRfpIgn+AkU4pOxBscohojdCHu4RRzjC5EYwVHqRONDkSnEvK/CB3QSU32IRW3ZPnj9iEVoGCNTLVrh8ia1x+6wq8xvB5mz8pxu7oPwIn9lcR0AiuX1+1KX+BXqdvXzWsAC0NsGjzZsS/2Bd6yRA5RgIHkXNhSD3whASZ8rrB9mItuEAizac0fDlHxDMEwpQfD1tW4y3Hjfy5s9nOHH3uwWA+EqEJBWCjoTL/S5toBB/7hu6zer74NgqSP39zJU+qQX3ix763mHTqvIVRUVprCljlElRkEjBqNYevH8veBJ2xhiyhE8YctmhDFH7ZoQhR/2KIJUfxhiyRE8YctmhDFH7ZoQhR/2OIJUfxhC9Ppf/t1jgJACERRsHGyYRZB0Ujvf0xD8w6kP7y6RZmgf/oTFTtbbzJVxZWo2Nlqw6TVy5GowNl6ssm7v50obamfSxQAAAAAAAsKLM15fb3vpQAAAABJRU5ErkJggg=="),gc._image}static toggle(t,e,n,i){if(!e)return void $i("InfoWindow not defined.");const r=t.root.findById(e);r?r._findInfoWindowByComponent(t)?gc.hide(t,e):gc.show(t,e,n,i):$i("InfoWindow Not Found.",e)}static hide(t,e){if(!e)return;const n=t.root.findById(e);n?n._removeInfoWindow(t):$i("InfoWindow Not Found.",e)}static show(e,n,i,r){if(!n)return void $i("InfoWindow not defined.");const s=e.root.findById(n);if(!s)return void $i("InfoWindow Not Found.",n);if(s._findInfoWindowByComponent(e))return;const{frontSideTemplate:o="",backSideTemplate:a=""}=s.model;let c=[o,a].filter(t=>String(t).trim());if(c=c.map(t=>cc.template(function(t,e,n){return(e||n?['<div class="info-window-btns">',e?'<button class="closable">&#88</button>':"",n?'<button class="flipable">&#8652</button>':"","</div>"]:[]).concat(['<div class="info-window-content">',t,"</div>"]).join("")}(t,!i,2==c.length))),0==c.length)return;const l='\n.flip {\n backface-visibility: hidden;\n border-radius: 7px;\n height: auto;\n font: normal 14px helvetica, arial, san serif;\n position: absolute;\n opacity: 0.9;\n transform-origin: 50% 50% 0px;\n transition: all 2s;\n min-width: 100px;\n min-height: 50px;\n background-color: #3e424e;\n box-shadow: 2px 3px 2px 0px rgba(0,0,0,0.15);\n}\n\n#side-1 {\n transform: rotateY(0deg);\n}\n\n.flip:after {\n content: "";\n display: block;\n position: absolute;\n opacity: 0.9;\n width: 0;\n height: 0;\n}\n\n.flip.arrow-top:after {\n left: 45%;\n top: -17px;\n border-left: 10px solid transparent;\n border-bottom: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-right:after {\n left: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-left: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n.flip.arrow-bottom:after {\n left: 45%;\n top: 100%;\n border-left: 10px solid transparent;\n border-top: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-left:after {\n right: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-right: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n#side-2 {\n transform: rotateY(180deg);\n}\n\n.flip-side-1 {\n transform: rotateY(0deg) !important;\n}\n\n.flip-side-2 {\n transform: rotateY(180deg) !important;\n}\n\n.info-window-btns {\n position: absolute;\n top: -18px;\n right: 5px;\n overflow: hidden;\n}\n\n.info-window-content {\n padding: 10px;\n color: #efefef;\n font-size: 13px;\n line-height: 1.4;\n}\n\n.info-window-btns button {\n width: 40px;\n height: 40px;\n float: right;\n border: 0;\n border-radius: 50%;\n background-color: #2a7da1;\n margin-right: 3px;\n text-align: center;\n cursor: pointer;\n font-size: 35px;\n color: #fff;\n line-height: 0;\n}\n\n.info-window-btns button:hover {\n background-color: #60bb23;\n}\n'+s.get("style");let{left:h,top:d}=e.bounds;const{x:u,y:p}=r?e.rootModel.toLocal(r.x,r.y):e.toScene(h,d);h=u,d=p;const f=document.createElement("span");f.style.position="absolute";const g=document.createElement("style");let m,y;g.type="text/css",g.appendChild(document.createTextNode(l)),f.appendChild(g),c[0]&&(m=document.createElement("div"),m.id="side-1",m.className="flip",m.style.display="inline-block",m.innerHTML=t.sanitize(c[0](e),{ADD_TAGS:["style"],ADD_ATTR:["class","id","style"]})),c[1]&&(y=document.createElement("div"),y.id="side-2",y.className="flip",y.style.display="inline-block",y.innerHTML=t.sanitize(c[1](e),{ADD_TAGS:["style"],ADD_ATTR:["class","id","style"]}));const b=e.rootModel.getOverlay(e);m&&f.appendChild(m),y&&f.appendChild(y),b.appendChild(f);const v=s._addInfoWindow(e,f,g).signal;if(Yr.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),Vr.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),m){const t=m.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=fc(y.className,"flip-side-1"),m.className=fc(m.className,"flip-side-2")},{signal:v});const i=m.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),gc.hide(e,n)},{signal:v})}if(y){const t=y.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=fc(y.className,"flip-side-1"),m.className=fc(m.className,"flip-side-2")},{signal:v});const i=y.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),gc.hide(e,n)},{signal:v})}const _=m.offsetWidth,x=m.offsetHeight,w=e.rootModel.target.getBoundingClientRect(),M=[];m&&M.push(m),y&&M.push(y);const S={x:h,y:d};let k=e.toGlobal(S.x,S.y);if(k.x+_/2+w.left<w.right&&k.x-_/2>w.left){if(x+pc<k.y)return f.style.marginLeft=S.x-_/2+"px",f.style.marginTop=S.y-x-pc+"px",void M.forEach(t=>t.className+=" arrow-bottom");if(k=e.toGlobal(S.x,S.y+x+pc),w.bottom>k.y+w.top)return f.style.marginLeft=S.x-_/2+"px",f.style.marginTop=S.y+pc+"px",void M.forEach(t=>t.className+=" arrow-top")}if(k=e.toGlobal(S.x,S.y),k.x-(_+pc)>w.left)return f.style.marginLeft=S.x-_-pc+"px",f.style.marginTop=S.y-x/2+"px",void M.forEach(t=>t.className+=" arrow-right");f.style.marginLeft=S.x+pc+"px",f.style.marginTop=S.y-x/2+"px",M.forEach(t=>t.className+=" arrow-left")}dispose(){this.infoWindows.map(t=>t.component).forEach(t=>this._removeInfoWindow(t)),super.dispose()}get infoWindows(){return this._windows||(this._windows=[]),this._windows}_findInfoWindowByComponent(t){return this.infoWindows.find(e=>e.component===t)}_addInfoWindow(t,e,n){if(this._findInfoWindowByComponent(t))return;const i=new AbortController;return this._windows.push({component:t,window:e,styleElement:n,abortController:i}),i}_removeInfoWindow(t){const e=this._findInfoWindowByComponent(t);if(!e)return;e.abortController.abort();const n=e.window;n&&n.parentNode.removeChild(n);const i=this.infoWindows.lastIndexOf(e);this.infoWindows.splice(i,1)}render(t){const{left:e,top:n,width:i,height:r}=this.bounds;t.beginPath(),this.drawImage(t,gc.image,e,n,i,r)}get hasTextProperty(){return!1}get nature(){return uc}}cc.register("info-window",gc);const mc={};var yc={list:function(){return{...mc}},register:function(t,e){mc[t]=e},unregister:function(t){delete mc[t]},get:function(t){if(!t)return;const e=mc[t];return e||Ki("Layout Not Found - ",t),e}};const bc=new class{constructor(){this.ABSOLUTE=!0}reflow(t,e){this.drawables(t).filter(t=>t.isHTMLElement()).forEach(t=>t.reposition())}capturables(t){return t.components}drawables(t){return t.app&&!t.app.isViewMode?t.components:t.components.filter(t=>!t.hidden)}isStuck(t){return!1}};yc.register("html-absolute",bc);const vc=new class{constructor(){this.ABSOLUTE=!0}reflow(t,e){}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!1}};function _c(t){const e=t.components.filter(t=>!t.hidden),n=t.getState("layoutConfig")||{},i=e[n&&n.activeIndex||0];return i&&[i]||[]}yc.register("absolute",vc);const xc=new class{reflow(t){const e=t.bounds,n=t.getState("layoutConfig")||{},i={left:0,top:0,width:e.width,height:e.height};t.forEach((t,e)=>{const r=e!=(n.activeIndex||0);t.bounds=i,t.setState("rotation",0),"element"in t&&t.element&&(t.element.style.visibility=r?"hidden":"visible")})}capturables(t){return _c(t)}drawables(t){return _c(t)}isStuck(t){return!0}};function wc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}yc.register("card",xc);const Mc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+wc(e),0),r=t.bounds,s=i>0?(r.width-((n.left||0)+(n.right||0)))/i:r.width,o=r.height-((n.top||0)+(n.bottom||0));let a=0;e.forEach(t=>{const e=wc(t),i=t.getState("margin")||{};t.bounds={left:s*a+(n.left||0)+(i.left||0),top:0+(n.top||0)+(i.top||0),width:e*s-((i.left||0)+(i.right||0)),height:o-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};function Sc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}yc.register("linear-horizontal",Mc);const kc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+Sc(e),0),r=t.bounds,s=i>0?(r.height-((n.top||0)+(n.bottom||0)))/i:r.height,o=r.width-((n.left||0)+(n.right||0));let a=0;e.forEach(t=>{const e=Sc(t),i=t.getState("margin")||{};t.bounds={left:0+(n.left||0)+(i.left||0),top:s*a+(n.top||0)+(i.top||0),width:o-((i.left||0)+(i.right||0)),height:e*s-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};yc.register("linear-vertical",kc);const Ac=new class{constructor(){this.joinType=!0}reflow(t){const e=t.getState("layoutConfig"),n=e&&e.columns||t.getState("columns"),i=e&&e.rows||t.getState("rows"),r=e&&e.widths||t.getState("widths"),s=e&&e.heights||t.getState("heights"),o=r?r.filter((t,e)=>e<n).reduce((t,e)=>t+e,0):n,a=s?s.filter((t,e)=>e<i).reduce((t,e)=>t+e,0):i,c=t.textBounds,l=t.getState("paddingLeft")||0,h=t.getState("paddingTop")||0,d=c.width/o,u=c.height/a;let p=0,f=0;t.components.forEach((t,e)=>{const i=r?r[e%n]:1,o=s?s[Math.floor(e/n)]:1;let a=t.colspan||1,c=0;for(;--a>0;)c+=r?r[(e+a)%n]:1;let g=t.rowspan||1,m=0;for(;--g>0;)m+=s?s[Math.floor(e/n)+g]:1;t.bounds={left:l+p,top:h+f,width:d*(i+c),height:u*(o+m)},t.setState("rotation",0),e%n==n-1?(p=0,f+=o*u):p+=i*d})}capturables(t){return t.components.filter(t=>!t.merged)}drawables(t){return t.components.filter(t=>!t.merged&&!t.hidden)}isStuck(t){return!0}keyNavigate(t,e,n){const i=t.getState("layoutConfig"),r=i&&i.columns||t.getState("columns"),s=i&&i.rows||t.getState("rows"),{row:o,column:a}=t.getRowColumn(e);switch(n.code){case"ArrowUp":if(o>0)return t.getAt?.((o-1)*r+a);break;case"ArrowDown":if(o<s-1)return t.getAt?.((o+1)*r+a);break;case"ArrowRight":if(a<r-1)return t.getAt?.(o*r+a+1);break;case"ArrowLeft":if(a>0)return t.getAt?.(o*r+a-1);break;default:return e}}};yc.register("table",Ac);const Ec=20;function Cc(t,e="static",n,i,r,s,o={}){const{title:a="",gap:c=Ec}=o;if("auto"===n){const{x:e,y:n}=function(t,e,n,i="",r=Ec){const s=Math.max(e.width/4-n.width/2,r),o=Math.min(3*e.width/4+n.width/2,e.width-r)-n.width,a=Math.max(e.height/4-n.height/2,r),c=Math.min(3*e.height/4+n.height/2,e.height-r)-n.height+(i?-30:0);return{x:t.x<e.width/2?Math.min(o,t.x+20):Math.max(s,t.x-(n.width+20)),y:t.y<e.height/2?Math.min(c,t.y+20+(i?30:0)):Math.max(a,t.y-(n.height+20))}}(i,r,s,a,c);Object.assign(t.style,{position:"absolute",left:`${e}px`,top:`${n}px`})}else"static"===e?function(t,e,n,i,r){const s=t.style,o=e.includes("left")?r:e.includes("right")?n.width-i.width-r:n.width/2-i.width/2,a=e.includes("top")?r:e.includes("bottom")?n.height-i.height-r:n.height/2-i.height/2;Object.assign(s,{left:`${o}px`,top:`${a}px`})}(t,n,r,s,c):function(t,e,n=Ec){const i=t.style;switch(Object.assign(i,{position:"absolute",left:"",right:"",top:"",bottom:"",transform:""}),e){case"center-middle":default:Object.assign(i,{left:"50%",top:"50%",transform:"translate(-50%, -50%)"});break;case"center-top":Object.assign(i,{left:"50%",top:`${n}px`,transform:"translateX(-50%)"});break;case"center-bottom":Object.assign(i,{left:"50%",bottom:`${n}px`,transform:"translateX(-50%)"});break;case"left-middle":Object.assign(i,{left:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"right-middle":Object.assign(i,{right:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"left-top":Object.assign(i,{left:`${n}px`,top:`${n}px`});break;case"right-top":Object.assign(i,{right:`${n}px`,top:`${n}px`});break;case"left-bottom":Object.assign(i,{left:`${n}px`,bottom:`${n}px`});break;case"right-bottom":Object.assign(i,{right:`${n}px`,bottom:`${n}px`})}}(t,n,c)}function Tc(t,e,n={sx:1,sy:1}){let i,r,s=0,o=0,a=!1;const c=/translate\(([-\d.]+)px,\s*([-\d.]+)px\)/;function l(){const e=(t.style.transform||"").match(c);return{x:e?parseFloat(e[1]):0,y:e?parseFloat(e[2]):0}}function h(t,e){a=!0;const n=l();s=n.x,o=n.y,i=t,r=e}function d(e,c){if(!a)return;const l=e-i,h=c-r,{sx:d,sy:u}=n;!function(e,n){t.style.transform=`translate(${e}px, ${n}px)`}(s+l/d,o+h/u)}function u(){const t=l();s=t.x,o=t.y,a=!1}e?.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),h(t.clientX,t.clientY);const e=t=>{t.preventDefault(),d(t.clientX,t.clientY)},n=t=>{t.preventDefault(),u(),window.removeEventListener("mousemove",e,!0),window.removeEventListener("mouseup",n,!0)};window.addEventListener("mousemove",e,!0),window.addEventListener("mouseup",n,!0)}),e?.addEventListener("touchstart",t=>{if(1!==t.touches.length)return;t.preventDefault(),t.stopPropagation(),h(t.touches[0].clientX,t.touches[0].clientY);const e=t=>{1===t.touches.length&&(t.preventDefault(),d(t.touches[0].clientX,t.touches[0].clientY))},n=t=>{u(),window.removeEventListener("touchmove",e,!0),window.removeEventListener("touchend",n,!0),window.removeEventListener("touchcancel",n,!0)};window.addEventListener("touchmove",e,!0),window.addEventListener("touchend",n,!0),window.addEventListener("touchcancel",n,!0)})}const Pc=["run","goto","goto-playlist","link-open","link-move","route-page","start-scenario","run-scenario","export-data","import-data"];function Dc(t,e){const n=document.createElement("button");return n.className=t,n.textContent=e,n}const Oc=new WeakMap;function zc(t){const e=t.root,n=Oc.get(e);if(!n)return;if(e===t)return n.forEach(t=>zc(t[0])),void Oc.delete(e);const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const r=n[i][1];cancelAnimationFrame(r.rafId),r.ac.abort(),r.div.parentNode?.removeChild(r.div),r.scene.target=null,r.scene.release?.(),n.splice(i,1)}class Ic{static hideAll(t){(Oc.get(t)||[]).forEach(([t])=>zc(t))}static hide(t){const e=t.root,n=Oc.get(e);if(!n)return;const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const r=n[i][1];r.div.style.backgroundColor="transparent",r.rafId=function(t,e,n){t.style.opacity="1";const i=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();t.style.transform=`${i} scale(1)`;let r=0;const s=Date.now(),o=()=>{if(n?.aborted)return;const a=Math.min((Date.now()-s)/200,1);t.style.opacity=String(1-a),t.style.transform=`${i} scale(${1-a})`.trim(),a<1?r=requestAnimationFrame(o):(t.style.display="none",e&&e())};return r=requestAnimationFrame(o),r}(r.div,()=>{zc(t)},r.ac.signal)}static show(t,e,n={}){const{data:i,modal:r=!1,closable:s=!0,minimizable:o=!1,draggable:a=!1,output:c=!0,popupPosition:l="static",origin:h="center-middle",title:d="",threed:u=!1}=n,p=t.app?.refProvider,f=!l||"static"===l;p?.get(e,!0).then(e=>{const n=document.createElement("div");n.setAttribute("popup",""),"absolute"==l&&(n.style.zIndex="100");const p=n.style;if(r){const{width:e,height:n}=f?t.rootModel.bounds:t.rootModel.auxOverlay.getBoundingClientRect();Object.assign(p,{position:"absolute",zIndex:"100",left:0,top:0,width:f?`${e}px`:"100%",height:f?`${n}px`:"100%",overflow:"hidden",backgroundColor:"transparent"})}else Object.assign(p,{position:"absolute",display:"inline-block"});n.appendChild(function(t){const e=document.createDocumentFragment(),n=document.createElement("div");n.className="popup-wrap";const i=document.createElement("div");if(i.className="popup-translate",t){const t=document.createElement("div");t.className="popup-title-bar";const e=document.createElement("div");e.className="popup-title",t.appendChild(e);const n=document.createElement("div");n.className="popup-buttons-wrap",n.appendChild(Dc("closable","close")),n.appendChild(Dc("minimizable","minimize")),n.appendChild(Dc("draggable","drag_pan")),t.appendChild(n),i.appendChild(t)}else{const t=document.createElement("div");t.className="popup-buttons-wrap float-right",t.appendChild(Dc("closable","close")),t.appendChild(Dc("minimizable","minimize")),t.appendChild(Dc("draggable","drag_pan")),i.appendChild(t)}const r=document.createElement("div");return r.className="popup-content",i.appendChild(r),n.appendChild(i),e.appendChild(n),e}(!!d));const g=n.querySelector(".popup-content"),{width:m,height:y}=e.root.model;Object.assign(g.style,{width:`${m}px`,height:`${y}px`});const b=document.createElement("style");b.appendChild(document.createTextNode("\n\n.popup-wrap .popup-translate {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n min-width: 120px;\n overflow: hidden;\n transition: height 0.5s ease;\n}\n\n.popup-wrap .popup-translate > * {\n pointer-events: auto;\n}\n\n.popup-wrap .popup-content {\n background-color: var(--md-sys-color-surface, white);\n}\n\n.popup-wrap .popup-title-bar {\n display: flex;\n align-items: center;\n top: 0;\n left: 0;\n width: 100%;\n height: 30px;\n background-color: var(--md-sys-color-primary, #f1f1f1);\n color: var(--md-sys-color-on-primary, black);\n padding: 5px;\n box-sizing: border-box;\n border-bottom: 1px solid #ccc;\n}\n\n.popup-wrap .popup-title {\n flex: 1;\n text-align: center;\n}\n\n.popup-wrap .popup-buttons-wrap {\n position: relative;\n display: flex;\n flex-direction: row-reverse;\n gap: 4px;\n min-width: 100px;\n align-items: center;\n justify-items: center;\n margin: 0;\n padding: 0;\n}\n\n.popup-wrap .popup-buttons-wrap.float-right {\n position: absolute;\n right: 0;\n top: 0;\n height: 30px;\n margin-right: 5px;\n}\n\n.popup-wrap button.closable, \n.popup-wrap button.minimizable, \n.popup-wrap button.draggable {\n display: none;\n color: white; \n background-color: black; \n opacity: .3;\n width: 20px;\n height: 20px;\n top: 5px; \n z-index: 1;\n padding: 0;\n margin: 0;\n border: 0px;\n text-align: center;\n cursor: pointer;\n border-radius: 4px;\n font-family: Material Symbols Outlined;\n font-size: 16px;\n}\n\n.popup-wrap button.draggable {\n cursor: move;\n}\n\n.popup-wrap button.closable:hover, \n.popup-wrap button.minimizable:hover, \n.popup-wrap button.draggable:hover {\n opacity: .6; \n}\n")),n.appendChild(b),Pc.forEach(n=>{e.on(n,(...e)=>{t.trigger(n,...e)})});const v=new AbortController,_=v.signal,x=n.querySelector(".draggable");[...Yr,...Vr].forEach(t=>{g.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),[...Yr,...Vr].forEach(t=>{n.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),r&&s&&n.addEventListener("click",e=>{e.target===n&&Ic.hide(t)},{signal:_});const w=t.rootModel.getOverlay?.({...t,scalable:!l||"static"==l});w?.appendChild(n),function(t,e,n,i,r){const s=t.root;if(s===t)return;zc(t);let o=Oc.get(s)||[];o=[...o,[t,{div:e,scene:n,ac:i,rafId:r}]],Oc.set(s,o)}(t,n,e,v,0);const M=Oc.get(t.root)?.find(e=>e[0]===t)?.[1];if(d){const t=n.querySelector(".popup-title-bar .popup-title");t&&(t.textContent=d)}const S=n.querySelector(".popup-translate");if(a&&(Tc(S,d?n.querySelector(".popup-title-bar"):n.querySelector(".draggable"),function(t,e){if(!(e=e||t.position)||"static"===e){const e=(t.rootModel.getOverlay(t).style.transform||"").match(/scale\(([^,\s)]+)(?:,\s*([^)]+))?\)/),n=e?parseFloat(e[1]):1;return{sx:n,sy:e&&e[2]?parseFloat(e[2]):n}}return{sx:1,sy:1}}(t,l)),d?x&&(x.style.display="block"):(S?.addEventListener("mouseenter",()=>{x&&(x.style.display="block")},{signal:_}),S?.addEventListener("mouseleave",()=>{x&&(x.style.display="none")},{signal:_}))),o){const t=n.querySelector(".minimizable");let e=!1;t.addEventListener("click",t=>{t.preventDefault(),e=!e;const i=n.querySelector(".popup-wrap");!function(t,e,n){const i=e.querySelector(".minimizable"),r=e.querySelector(".popup-translate");r&&(n?(i.textContent="crop_square",r.style.height="30px"):(i.textContent="minimize",r.style.height="100%"))}(0,r?i:n,e)},{signal:_}),d?t&&(t.style.display="block"):(S?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:_}),S?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:_}))}if(s){const t=n.querySelector(".closable");d?t&&(t.style.display="block"):(S?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:_}),S?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:_}))}n.querySelector(".closable")?.addEventListener("click",e=>{e.preventDefault(),Ic.hide(t)},{signal:_}),n.addEventListener("close-scene",e=>{e.preventDefault(),e.stopPropagation(),Ic.hide(t),c&&(t.data=e.detail)},{signal:_}),e.target=g,e.data=i||t.data,e.fit("both"),u&&(e.root.threed=!0);const{x:k,y:A}=t.center,E=t.toScene(k,A),C=r?n.querySelector(".popup-wrap"):n;Cc(C,l,h,E,e.root.bounds,{width:m,height:y},{title:d}),r?Object.assign(C.style,{position:"absolute",pointerEvents:"none",width:`${m}px`,height:`${d?y+30:y}px`}):Object.assign(C.style,{pointerEvents:"none",width:`${m}px`,height:`${d?y+30:y}px`});const T=function(t,e,n){t.style.opacity="0";const i=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();t.style.transform=`${i} scale(0)`,t.style.display="block";let r=0;const s=Date.now(),o=()=>{if(n?.aborted)return;const a=Math.min((Date.now()-s)/200,1);t.style.opacity=String(a),t.style.transform=`${i} scale(${a})`.trim(),a<1?r=requestAnimationFrame(o):e&&e()};return r=requestAnimationFrame(o),r}(n,()=>{r&&(n.style.backgroundColor="rgba(0,0,0,0.3)")},_);M&&(M.rafId=T)},t=>{Ki("cannot fetch board: "+e,t)})}}const Lc=new Image;function jc(t){return class extends t{get showMoveHandle(){return!1}postrender(t){super.postrender(t),this.app.isEditMode&&this._focused&&this.showMoveHandle&&this._draw_move_handle(t)}_draw_move_handle(t){const{left:e,top:n,width:i}=this.bounds;t.save(),t.beginPath(),t.globalAlpha=1,t.rect(e+i,n,25,25);t.fillStyle="rgba(235, 235, 235, 1)",t.fill(),t.drawImage(Lc,e+i+3.75,n+3.75,17.5,17.5),t.closePath(),t.restore()}contains(t,e){let n=super.contains(t,e);if(this.app.isViewMode)return n;if(!n){const{left:i,top:r,width:s}=this.bounds,o=i+s,a=25;this.showMoveHandle&&(n=t<Math.max(o+25,o)&&t>Math.min(o+25,o)&&e<Math.max(r+a,r)&&e>Math.min(r+a,r))}return this._focused!==n&&(this._focused=n,this.invalidate()),n}}}Lc.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAclBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0BbqFAAAAJXRSTlMAgAP3VSI6/g9fBk5FavJsMrariSjzPnO1enRRL5SMhmOOWB9keFTE0wAAANxJREFUOMutk9kWgyAMRLFuiLjUtdp9yf//YglVsQXz1HniMPcEMgHGvpX2O0Ypi+EgCL+IAShC+wB7QfubRDT7AFcnUPoLMLiP4PyJbsb55i05AgnR5iaQDsICgtH0cotBWoAP1c7kC6kFxEseCfZfB6gEgbNeBrira2QmH1uVYCXlA3is8UmgUCPIyQJKEmu8QtQJN0e9DPXVpzG2G216c1CqRmcBOdxXk07sWUSPv07zo0amCNQycv+NzmR6cRcwmfbuI7p2nZ/z4be0P83Foz6vIkhfZXr82XgDlZsspIq4peUAAAAASUVORK5CYII=";const Rc=[];class Fc extends(jc(dc(cc))){constructor(t,e){super(t,e),this._components=[]}replaceRefids(t){this.components.forEach(e=>e.replaceRefids(t))}get showMoveHandle(){return!0}get showOverflow(){return!1}dispose(){this.components.slice().forEach(t=>t.dispose()),super.dispose()}isContainer(){return!0}containable(t){return t.isDescendible(this)}get hasTextProperty(){return!1}get components(){return this._components}get focusible(){return!0}get layout(){return yc.get(this.get("layout"))||vc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){if(!t)return;const{animated:n=!1,duration:i=2e3,ease:r="inout"}=e,s=t.parent;if(!s||s===this)return;const o=t=>{let e=0,n=t;for(;n&&!n.isRootModel?.();)e+=n.state?.rotation||0,n=n.parent;return e},a=!(!t._realObject?.object3d||!this._realObject?.object3d);let c=null,l=null,h=null,d=null;if(a){const e=this._realObject.object3d,n=t._realObject.object3d,i=t._realObject.dimension||{width:1,height:1,depth:1};e.updateWorldMatrix(!0,!1),n.updateWorldMatrix(!0,!1),e.attach(n),c={pos:n.position.clone(),quat:n.quaternion.clone(),fromDimW:i.width||1,fromDimH:i.height||1,fromDimD:i.depth||1},t._realObject.suppressTransform=!0}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);h={x:i.x,y:i.y,rotation:o(s),width:e.width,height:e.height}}if(this.addComponent(t,{silent:!0}),a){const e=t._realObject.object3d;t.clearCache();const n=t._realObject.position,i=t._realObject.rotation,r=t._realObject.dimension||{width:1,height:1,depth:1},s=r.width||1,o=r.height||1,a=r.depth||1,h={x:c.fromDimW/s,y:c.fromDimH/o,z:c.fromDimD/a};l={pos:e.position.clone().set(n.x,n.y,n.z),quat:e.quaternion.clone().setFromEuler(e.rotation.clone().set(i.x,i.y,i.z))},c.fromScale=h,c.toScale={x:1,y:1,z:1},e.position.copy(c.pos),e.quaternion.copy(c.quat)}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);d={x:i.x,y:i.y,rotation:o(this),width:e.width,height:e.height}}if(n){const e=this.root?.transitionEffect;e&&e.begin(t,{fromWorld:h,toWorld:d,from3D:c,to3D:l,duration:i,ease:r})}}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,r=t.parent;if(r){if(this===r)return;r.removeComponent(t,n||i)}const s=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,s),t.delegate_on(this),i?(r&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,s),t.trigger("added",this,t,s),delete t._silentAdd):n||t.trigger("added",this,t,s),this.root&&this.root.isReady&&t.ready()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const r=this._components.splice(0,e);this._components=r.concat(t,this._components),e=this._components.indexOf(t),t.parent=this,t.added(this),n||this.trigger("add",this,t,e),t.delegate_on(this),n||t.trigger("added",this,t,e)}add(t,e=!1){return t instanceof Array?(t.forEach(t=>{-1==this._components.indexOf(t)&&this.addComponent(t,e)}),this):this.add.call(this,[t],e)}remove(t,e=!1){return t instanceof Array?this._components?(t.forEach(t=>{this.removeComponent(t,e)}),this):this:this.remove.call(this,[t],e)}getAt(t){if(this._components)return this._components[t]}forEach(t,e){this._components&&this._components.forEach(t,e)}traverse(t,e){t.call(e,this),this._components&&this._components.forEach(n=>{n.isContainer()?n.traverse(t,e):t.call(e,n)})}indexOf(t){return(this._components||Rc).indexOf(t)}size(){return(this._components||Rc).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const r=this._components.splice(1);this._components=i.concat(r),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return La(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const r=this.components[i].findAll(t,...e);r&&(n=n.concat(r))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return La(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}contains(t,e){let n=super.contains(t,e);if(!n){const{left:i,top:r,width:s,height:o}=this.state;n=t<Math.max(i+s,i)&&t>Math.min(i+s,i)&&e<Math.max(r+o,r)&&e>Math.min(r+o,r)}return n}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const r=this.bounds;i.x-=r.left,i.y-=r.top;const s=this.layout.capturables(this);for(let r=s.length-1;r>=0;r--){const o=s[r];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:r,width:s,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+s||a.y<r||a.y>r+o)return!1;a.x-=i,a.y-=r,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const r=i.capturePath(n,e);if(r)return r}return this.focusible&&this}render(t){const{left:e=0,top:n=0,width:i,height:r}=this.bounds;t.beginPath(),t.rect(e,n,i,r),t.closePath(),this.drawFill(t),this.drawStroke(t)}postrender(t){const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:r,height:s}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,r,s),t.clip(),t.closePath()),({top:i,left:n}=this.state),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)?n.renderComponent(e,this.root?.model_layer):e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>cc.memoize(Fc.prototype,t,!1));class Bc extends Fc{constructor(t,e){super(t,e),this._element=null,this._firstDrawReported=!1,t.translate=t.translate||{x:0,y:0},this._draw_reserved=!1,this.__draw__=()=>{this._draw_reserved=!1;const t=performance.now();this.trigger("redraw"),this.reflow(),this.draw();const e=performance.now()-t;Ii.drawCount++,Ii.drawTimeSum+=e,Ii.drawTimeLast=e,Ii.countFrame(),this._firstDrawReported||(this._firstDrawReported=!0,this.app?.loadTracker?.markFirstRender())},this.throttle_render=()=>{this._draw_reserved||requestAnimationFrame(this.__draw__),this._draw_reserved=!0}}get element(){return this._element}set element(t){this._element=t}fitSize(t,e,n,i){if(this.target){if(e){const t=getComputedStyle(this.target);n=n||(t?parseFloat(t.getPropertyValue("width")):this.target.clientWidth),i=i||(t?parseFloat(t.getPropertyValue("height")):this.target.clientHeight)}else n=this.model.width,i=this.model.height;"CANVAS"==t.tagName&&(t.setAttribute("width",n*Hr),t.setAttribute("height",i*Hr)),t.style.width=n+"px",t.style.height=i+"px"}}resize(){this.fitSize(this.element,!0)}isLayer(){return!0}get showOverflow(){return this.app.isEditMode}get anchors(){}createElement(){const t=cc.createCanvas(1,1);return t.setAttribute("scene",this.state.type),t.style.position="absolute",t.style.pointerEvents=this.pointerEvents,t}get pointerEvents(){return"auto"}get target(){return this._target}set target(t){this._target&&this.element&&this._target.removeChild(this.element),this._target=t,this.element||(this.element=this.createElement()),this.resize(),t?.appendChild(this.element)}get canvas(){return this.element}dispose(){super.dispose(),this.target=null,this.element=null}get selected(){return this.root.selected||[]}set selected(t){this.root.selected=t}get hasSameParentForAllSelected(){return this.root.hasSameParentForAllSelected}get focused(){return this.root.focused}set focused(t){this.root.focused=t}get context2D(){if(!this._context2D&&(this._context2D=this.canvas&&this.canvas.getContext("2d"),this._context2D)){const t=getComputedStyle(document.documentElement),e=t.getPropertyValue("--scene-theme-font-family")?.trim()||t.fontFamily||"sans-serif";this._context2D.font=["10px",e].join(" "),this._context2D.save()}return this._context2D}getContext(t){return this._context2D||this.context2D}draw(t){this.canvas&&(t=t||this.getContext(void 0))&&(t.save(),super.draw(t),t.restore())}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:i}=this.model;t.clearRect(0,0,t.canvas.width,t.canvas.height),e&&t.translate(e.x*Hr,e.y*Hr),t.scale(n.x*Hr,n.y*Hr),i&&t.rotate(i)}get rotatePoint(){return{x:0,y:0}}contains(t,e){return!1}invalidate(){Ii.invalidateCount++,this.throttle_render()}move(t){const e=this.get("translate")||{x:0,y:0};this.set({translate:{x:e.x+t.x,y:e.y+t.y}})}centerTo(t,e){const n=t.rootModel.toLocal(this.canvas.clientWidth/2,this.canvas.clientHeight/2),{x:i,y:r}=t.center,{x:s,y:o}=t.fromParent(i,r),{x:a,y:c}=t.toScene(s,o),{x:l,y:h}=t.rootModel.get("translate"),{x:d,y:u}=t.rootModel.get("scale");e?ra({step:function(e){t.rootModel.set({translate:{x:l+(n.x-a)*d*e,y:h+(n.y-c)*u*e}})},duration:1e3,delta:"circ"}).start():t.rootModel.set({translate:{x:l+(n.x-a)*d,y:h+(n.y-c)*u}})}}class Nc extends Bc{dispose(){super.dispose(),delete this._canvas,delete this._auxCanvas}createElement(){const t=document.createElement("div");return t.style.position="absolute",t.setAttribute("scene",`${this.state.type}-anchor`),t.style["user-select"]="none",t.style.overflow="hidden",this._canvas=cc.createCanvas(1,1),this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.setAttribute("scene",`${this.state.type}-canvas`),t.appendChild(this._canvas),this._auxCanvas=cc.createCanvas(1,1),this._auxCanvas.style.position="absolute",this._auxCanvas.style.pointerEvents="none",this._auxCanvas.style.zIndex="100",this._auxCanvas.setAttribute("scene",`${this.state.type}-aux-canvas`),t.appendChild(this._auxCanvas),t}resize(){if(!this.element)return;this.fitSize(this.element,!0);const t=this.element.clientWidth,e=this.element.clientHeight;this.fitSize(this.canvas,!0,t,e),this.fitSize(this.auxCanvas,!0,t,e)}get canvas(){return this._canvas}get auxCanvas(){return this._auxCanvas}get context2D(){if(!this._context2D){this._context2D=this.canvas&&this.canvas.getContext("2d");const t=getComputedStyle(document.documentElement),e=t.getPropertyValue("--scene-theme-font-family")?.trim()||t.fontFamily||"sans-serif";this._context2D.font=["10px",e].join(" "),this._context2D.save()}return this._context2D}get auxContext2D(){if(!this._auxContext2D){this._auxContext2D=this.auxCanvas&&this.auxCanvas.getContext("2d");const t=getComputedStyle(document.documentElement),e=t.getPropertyValue("--scene-theme-font-family")?.trim()||t.fontFamily||"sans-serif";this._auxContext2D.font=["10px",e].join(" "),this._auxContext2D.save()}return this._auxContext2D}getContext(t){return t?t.scalable?this.context2D:this.auxContext2D:this.context2D}draw(t){this.canvas&&this.element&&(t=t||this.getContext(void 0))&&(this.auxContext2D.clearRect(0,0,this.auxCanvas.width,this.auxCanvas.height),this.auxContext2D.save(),this.auxContext2D.scale(Hr,Hr),super.draw(t),this.auxContext2D.restore())}}var Hc,Yc,Vc,Gc;!function(t){t.CANVAS="canvas",t.DOM="dom"}(Hc||(Hc={}));class Uc{get overlay(){return this._overlay}constructor(t,e,n={}){if(this.element=null,this.isActive=!1,this._overlay=null,this.target=e,this.options={animation:!0,repeat:!0,duration:3e3,color:"#ff0000",opacity:1,fadeOut:!1,...n},this.mode=n.mode||this.determineOptimalMode(),t){this._overlay=t;Bs.getInstance().addOverlay(t)}}determineOptimalMode(){return!1!==this.options.animation?Hc.DOM:Hc.CANVAS}start(){if(!this.isActive&&(this.isActive=!0,this.mode===Hc.DOM)){this.overlay?(this.createDOMElements(),this.target.on("change",this.handleTargetChange,this),this.target.on("removed",this.handleTargetRemoved,this)):($i("오버레이가 설정되지 않아 DOM 모드 데코레이터를 시작할 수 없습니다."),this.isActive=!1)}}stop(){this.isActive&&(this.isActive=!1,this.mode===Hc.DOM&&(this.target.off("change",this.handleTargetChange,this),this.target.off("removed",this.handleTargetRemoved,this),this.removeDOMElements()))}update(t){if(t&&(this.options={...this.options,...t},t.mode&&t.mode!==this.mode))return this.stop(),this.mode=t.mode,void this.start();this.mode===Hc.DOM&&this.isActive&&this.updateDOMElements()}render(t,e){return!(this.mode!==Hc.CANVAS||!this.isActive)&&this.renderCanvas(t,e)}removeDOMElements(){this.element&&this.element.parentNode&&(this.element.parentNode.removeChild(this.element),this.element=null)}updateDOMElements(){this.removeDOMElements(),this.createDOMElements()}getComponentPosition(){const{left:t,top:e,width:n,height:i}=this.target.bounds;if("function"==typeof this.target.toGlobal)try{const{x:r,y:s}=this.target.toGlobal(t,e,this.target.rootModel);return{x:r,y:s,width:n,height:i}}catch(t){$i("좌표 변환 실패, 기본값 사용:",t)}return{x:t,y:e,width:n,height:i}}handleTargetChange(t,e){this.target.disposed?this.stop():this.invalidate()}handleTargetRemoved(){this.stop()}invalidate(){}}function Wc(t,n,i){const r=t.rootModel;if(r?.is3dMode){const n=t._realObject?.object3d,i=r.activeCamera3d,s=r.renderer3d;if(n&&i&&s){const t=new e.Vector3;n.getWorldPosition(t);const r=t.clone().project(i),o=s.domElement;return{x:(.5*r.x+.5)*o.clientWidth,y:(.5*-r.y+.5)*o.clientHeight}}return null}const s=t.toGlobal(n,i,r);return isNaN(s.x)||isNaN(s.y)?null:s}class Xc extends Uc{constructor(t,e,n={}){super(t,e,{strokeWidth:2,strokeColor:"#FF0000",strokeOpacity:1,fillColor:"none",fillOpacity:.5,scale:1,rotation:0,x:0,y:0,zIndex:0,mode:Hc.DOM,...n}),this.vectorElement=null,this.animationElements=[],this.svgContainer=null,this.animationElement=null}getDecoratorType(){return this.constructor.DECORATOR_TYPE}dispose(){this.removeDOMElements()}determineOptimalMode(){return Hc.DOM}renderCanvas(t,e){return $i("VectorDecorator는 Canvas 렌더링을 지원하지 않습니다. DOM 모드를 사용하세요."),!1}getSvgContainer(){if(!this.overlay)throw new Error("오버레이 요소가 없습니다.");if(!Xc.svgContainerCache.has(this.overlay)){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("class","vector-decorator-container"),t.setAttribute("pointer-events","none"),t.style.overflow="visible",t.style.position="absolute",t.style.top="0",t.style.left="0",this.overlay.appendChild(t),Xc.svgContainerCache.set(this.overlay,t)}return Xc.svgContainerCache.get(this.overlay)}getOrCreateDecoratorGroup(t=!1){const e=this.getSvgContainer(),n=this.getVectorGroupId(),i=this.getDecoratorType();let r=e.querySelector(`g[data-decorator-type-container="${i}"]`);if(!r){r=document.createElementNS("http://www.w3.org/2000/svg","g"),r.setAttribute("data-decorator-type-container",i),r.setAttribute("class",`${i}-container`),e.appendChild(r);const t=document.createElementNS("http://www.w3.org/2000/svg","defs");t.setAttribute("data-defs-for",i),r.appendChild(t)}let s=r.querySelector(`g[data-decorator-group-id="${n}"]`);if(!s){const{id:t}=this.target.state;return s=document.createElementNS("http://www.w3.org/2000/svg","g"),s.setAttribute("data-decorator-group-id",n),s.setAttribute("data-decorator-type",i),t&&s.setAttribute("data-component-id",t),r.appendChild(s),s}if(t)for(;s.firstChild;)s.removeChild(s.firstChild);return s}getDefsForType(){const t=this.getSvgContainer(),e=this.getDecoratorType();let n=t.querySelector(`g[data-decorator-type-container="${e}"]`);n||(this.getOrCreateDecoratorGroup(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`));let i=n.querySelector(`defs[data-defs-for="${e}"]`);return i||(i=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.setAttribute("data-defs-for",e),n.appendChild(i)),i}getDecoratorGroup(){const t=this.getSvgContainer(),e=this.getVectorGroupId(),n=t.querySelector(`g[data-decorator-group-id="${e}"]`);if(n)return n}createFadeAnimation(t=0,e=1,n=1e3,i={}){const r=document.createElementNS("http://www.w3.org/2000/svg","animate");return r.setAttribute("attributeName","opacity"),r.setAttribute("from",t.toString()),r.setAttribute("to",e.toString()),r.setAttribute("dur",`${n}ms`),i.delay&&r.setAttribute("begin",`${i.delay}ms`),r.setAttribute("fill","freeze"),i.repeat?r.setAttribute("repeatCount","indefinite"):r.setAttribute("repeatCount","1"),r}createTranslateAnimation(t,e=[],n=1e3,i={}){const r=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return r.setAttribute("attributeName","transform"),r.setAttribute("type","translate"),r.setAttribute("values",t.join(";")),e.length>0&&r.setAttribute("keyTimes",e.join(";")),r.setAttribute("dur",`${n}ms`),i.delay&&r.setAttribute("begin",`${i.delay}ms`),i.repeat?r.setAttribute("repeatCount","indefinite"):r.setAttribute("repeatCount","1"),r}createRotateAnimation(t=0,e=360,n=0,i=0,r=1e3,s={}){const o=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return o.setAttribute("attributeName","transform"),o.setAttribute("type","rotate"),o.setAttribute("from",`${t} ${n} ${i}`),o.setAttribute("to",`${e} ${n} ${i}`),o.setAttribute("dur",`${r}ms`),s.delay&&o.setAttribute("begin",`${s.delay}ms`),s.repeat?o.setAttribute("repeatCount","indefinite"):o.setAttribute("repeatCount","1"),o}addAnimations(t,e){e.forEach(e=>{t.appendChild(e),this.animationElements.push(e)})}projectComponentPoint(t,e,n){return Wc(t,e,n)}updatePosition(){if(!this.vectorElement)return;const t=this.options,{left:e,top:n}=this.target.bounds,i=this.projectComponentPoint(this.target,e,n);if(!i)return;const r=i.x+(t.x??0),s=i.y+(t.y??0);this.vectorElement.setAttribute("transform",`translate(${r}, ${s})`)}updateDOMElements(){this.createDOMElements()}getVectorGroupId(){const t=this.getDecoratorType(),{refid:e="unknown"}=this.target.state;return`decorator-${t}-${e}`}removeVectorElements(){if(this.overlay)try{const t=Xc.svgContainerCache.get(this.overlay);if(!t)return;const e=this.getVectorGroupId(),n=this.getDecoratorType(),i=t.querySelector(`g[data-decorator-type-container="${n}"]`);if(i){const t=i.querySelector(`g[data-decorator-group-id="${e}"]`);if(t&&(this.vectorElement&&(this.vectorElement===t||t.contains(this.vectorElement))&&(this.vectorElement=null),this.animationElements=this.animationElements.filter(e=>!t.contains(e)),t.remove()),!i.querySelector("g[data-decorator-group-id]")){const t=i.querySelector(`defs[data-defs-for="${n}"]`);t&&t.remove(),i.remove()}}0===t.children.length&&(t.remove(),Xc.svgContainerCache.delete(this.overlay))}catch(t){Ki("벡터 요소 제거 실패:",t)}}removeDOMElements(){this.removeVectorElements()}delta(t,e){if("string"==typeof t)return"fade"===t?this.applyFadeValue(e):"theta"===t&&this.applyRotationValue(e),{tx:0,ty:0};if("object"==typeof t){const e=t;("tx"in e||"ty"in e)&&this.applyTranslateValues(e.tx||0,e.ty||0),("sx"in e||"sy"in e)&&this.applyScaleValues(e.sx||1,e.sy||1)}return null}invalidate(){this.mode===Hc.DOM&&this.isActive&&this.updateDOMElements()}touch(){}applyFadeValue(t){if(this.vectorElement){const e=t.toFixed(2);this.vectorElement.setAttribute("opacity",e)}}applyRotationValue(t){if(this.vectorElement){const e=this.getComponentBounds(),n=e.width/2,i=e.height/2,r=(180*t/Math.PI).toFixed(1);this.vectorElement.setAttribute("transform",`rotate(${r} ${n} ${i})`)}}applyTranslateValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("translate")){const i=n.replace(/translate\([^)]+\)/,`translate(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} translate(${t}, ${e})`.trim())}}applyScaleValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("scale")){const i=n.replace(/scale\([^)]+\)/,`scale(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} scale(${t}, ${e})`.trim())}}getComponentBounds(){return this.target&&this.target.bounds?this.target.bounds:{top:0,left:0,width:100,height:100}}}Xc.svgContainerCache=new WeakMap,Xc.DECORATOR_TYPE="vector";class qc extends Uc{constructor(t,e,n={}){super(t,e,{scale:1,strokeColor:"#000000",strokeWidth:1,rotation:0,shadow:!1,shadowColor:"rgba(0,0,0,0.5)",shadowBlur:5,shadowOffsetX:2,shadowOffsetY:2,...n}),this.animationId=null,this.canvasElement=null,this.context=null,this.animationFrame=null,this.deltaValue=0}determineOptimalMode(){return Hc.CANVAS}createDOMElements(){$i("RasterDecorator는 DOM 렌더링을 지원하지 않습니다. Canvas 모드를 사용하세요.")}setAnimationState(t=3e3,e=!1){qc.animationStateMap.set(this.target,{startTime:Date.now(),duration:t,repeat:e})}getAnimationState(){const t=qc.animationStateMap.get(this.target);if(!t)return{delta:0,finished:!0};const{startTime:e,duration:n,repeat:i}=t,r=Date.now()-e;let s=Math.min(1,r/n),o=s>=1;return i&&o&&(qc.animationStateMap.set(this.target,{startTime:Date.now(),duration:n,repeat:i}),s=0,o=!1),{delta:s,finished:o}}bounceEffect(t,e=10){const n=Math.min(1,4*t);return Math.sin(n*Math.PI*10)*e*(1-n)}fadeEffect(t,e=!1){return e?t:1-t}pulseEffect(t,e=.8,n=1.2){return e+(.5*Math.sin(t*Math.PI*2)+.5)*(n-e)}rotateEffect(t,e=360){return t*e}applyShadowEffect(t){if(this.options.shadow){const e=this.options;t.shadowColor=e.shadowColor||"rgba(0,0,0,0.5)",t.shadowBlur=e.shadowBlur||5,t.shadowOffsetX=e.shadowOffsetX||2,t.shadowOffsetY=e.shadowOffsetY||2}}removeShadowEffect(t){t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0}start(){super.start(),this.isActive&&this.options.animation&&this.setAnimationState(this.options.duration||3e3,this.options.repeat||!1)}stop(){null!==this.animationFrame&&(cancelAnimationFrame(this.animationFrame),this.animationFrame=null),super.stop(),qc.animationStateMap.delete(this.target)}applyTransform(t,e,n){const i=this.options,r=i.scale||1,s=i.rotation||0;if(1!==r||0!==s){if(t.translate(e,n),0!==s){const e=s*Math.PI/180;t.rotate(e)}1!==r&&t.scale(r,r),t.translate(-e,-n)}}delta(t,e){return"string"==typeof t?("fade"===t?(this.deltaValue=e,this.context&&(this.context.globalAlpha=e)):"theta"===t&&(this.deltaValue=e),{tx:0,ty:0}):null}invalidate(){this.context&&this.isActive&&(this.animationFrame||(this.animationFrame=requestAnimationFrame(()=>{this.animationFrame=null,this.renderCanvas(this.context,this.deltaValue)})))}touch(){this.deltaValue=0}}qc.animationStateMap=new WeakMap;class Kc extends Xc{constructor(t,e,n={}){super(t,e,{size:1,showId:!1,animation:!1,...n}),this.arrowElement=null,this.labelElement=null,this.decoratorGroup=null}createDOMElements(){if(this.overlay)try{const t=this.getOrCreateDecoratorGroup(!0);this.decoratorGroup=t,t.setAttribute("transform","translate(0, 0)");const{size:e=1,showId:n=!1,duration:i=3e3,repeat:r=!0}=this.options,s=this.options.color||"#FF0000",o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.createArrowPath(0,0,e)),o.setAttribute("fill",s),o.setAttribute("stroke",s),o.setAttribute("stroke-width","1"),o.setAttribute("class","bouncing-arrow");const a=[];if(this.options.animation){const t=this.createBounceAnimation(i,r);if(a.push(t),this.options.fadeOut){const t=this.createFadeAnimation(1,0,i,{repeat:r});a.push(t)}}if(this.addAnimations(o,a),t.appendChild(o),this.arrowElement=o,n&&this.target.state?.id){const n=this.createArrowLabel(0,0,s,this.target.state.id,e);if(this.options.animation){const t=[],e=this.createBounceAnimation(i,r);if(t.push(e),this.options.fadeOut){const e=this.createFadeAnimation(1,0,i,{repeat:r});t.push(e)}this.addAnimations(n,t)}t.appendChild(n),this.labelElement=n}this.vectorElement=t,this.updatePosition(),this.options.animation&&this.startAnimations()}catch(t){Ki("화살표 SVG 요소 생성 실패:",t)}}createArrowPath(t,e,n=1){const i=n/this.getScale();return`\n M${t-10*i},${e-16*i} \n L${t+10*i},${e-16*i} \n L${t+10*i},${e-8*i} \n L${t+16*i},${e-8*i} \n L${t},${e} \n L${t-16*i},${e-8*i} \n L${t-10*i},${e-8*i} \n Z\n `}getScale(){try{if(this.target.rootModel&&"number"==typeof this.target.rootModel.scale)return this.target.rootModel.scale||1}catch(t){$i("스케일 계산 실패, 기본값 사용",t)}return 1}createBounceAnimation(t,e){const n=["0,-10"],i=["0"];for(let t=1;t<=20;t++){const e=t/20;let r=Math.pow(e,.5).toFixed(3);parseFloat(i[i.length-1])>=parseFloat(r)&&(r=(parseFloat(i[i.length-1])+.01).toFixed(3)),n.push("0,0"),n.push("0,-10"),i.push(r),i.push((parseFloat(r)+.01).toFixed(3))}return i[i.length-1]="1.000",this.createTranslateAnimation(n,i,t,{repeat:e})}createArrowLabel(t,e,n,i,r=1){const s=document.createElementNS("http://www.w3.org/2000/svg","g");s.setAttribute("class","bouncing-arrow-label");const o=document.createElementNS("http://www.w3.org/2000/svg","rect");o.setAttribute("x",`${t+20*r}`),o.setAttribute("y",""+(e-20*r)),o.setAttribute("width",""+40*r),o.setAttribute("height",""+20*r),o.setAttribute("rx","3"),o.setAttribute("fill",n);const a=document.createElementNS("http://www.w3.org/2000/svg","text");return a.setAttribute("x",`${t+40*r}`),a.setAttribute("y",""+(e-6*r)),a.setAttribute("fill","white"),a.setAttribute("font-size",12*r+"px"),a.setAttribute("text-anchor","middle"),a.textContent=i,s.appendChild(o),s.appendChild(a),s}startAnimations(){setTimeout(()=>{this.animationElements.forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&t.beginElement()}catch(t){Ki("애니메이션 시작 오류:",t)}})},10)}invalidate(){this.updatePosition()}updatePosition(){if(!this.vectorElement)return;const{left:t,top:e,width:n}=this.target.bounds,i=this.projectComponentPoint(this.target,t+n/2,e);if(!i)return;const r=Math.max(i.x,20),s=Math.max(i.y,20);this.vectorElement.setAttribute("transform",`translate(${r}, ${s})`)}}Kc.DECORATOR_TYPE="bouncing-arrow",function(t){t.ROTATE="rotate",t.TRANSLATE_X="translateX",t.TRANSLATE_Y="translateY",t.SCALE="scale",t.FADE="fade"}(Yc||(Yc={})),function(t){t.VIBRATION="vibration",t.ROTATION="rotation",t.HEARTBEAT="heartbeat",t.MOVING="moving",t.OUTLINE="outline",t.FADE="fade",t.WAYPOINT="waypoint"}(Vc||(Vc={})),function(t){t.CENTER="center",t.TOP="top",t.RIGHT="right",t.BOTTOM="bottom",t.LEFT="left",t.TOP_RIGHT="top-right",t.BOTTOM_RIGHT="bottom-right",t.BOTTOM_LEFT="bottom-left",t.TOP_LEFT="top-left",t.TOP_LEFT_CORNER="top-left-corner",t.TOP_RIGHT_CORNER="top-right-corner",t.BOTTOM_LEFT_CORNER="bottom-left-corner",t.BOTTOM_RIGHT_CORNER="bottom-right-corner",t.LEFT_TOP="left-top",t.LEFT_BOTTOM="left-bottom",t.RIGHT_TOP="right-top",t.RIGHT_BOTTOM="right-bottom"}(Gc||(Gc={}));class $c extends Xc{constructor(t,e,n={}){const{animations:i,...r}=n;super(t,e,{icon:"arrow_forward",size:24,color:"#FF0000",deltaX:0,deltaY:0,...r}),this.animations=[],this._location=null,this.element=null,this._delta={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0},this.animations=this.createAnimations(i)}delta(t,e){if(!t)return this._delta;switch(typeof t){case"object":this._delta={...this._delta,...t};break;case"string":if(void 0===e)return this._delta[t];this._delta[t]=e}const{tx:n,ty:i,sx:r,sy:s,theta:o,fade:a}=this._delta;return this.element&&Object.assign(this._getElement().style,{opacity:1-a,transform:`rotate(${o}rad) translate(${n}px, ${i}px) scale(${r}, ${s}) perspective(1px)`}),this._delta}getScaledSize(){const t=this.options.size||24,{x:e}=this.target.rootModel?.state.scale||{x:1},{x:n}=this.target.state.scale||{x:1};return t*e*n}get location(){if(this._location)return this._location;const{location:t,position:e,size:n}=this.options,{bounds:i}=this.target,{left:r,top:s,width:o,height:a}=i,c=n/2;let l;switch(e||t||Gc.CENTER){case Gc.TOP_LEFT:case"top-left":l={x:r,y:s-n};break;case Gc.TOP:case"top":l={x:r+(o-n)/2,y:s-n};break;case Gc.TOP_RIGHT:case"top-right":l={x:r+o-n,y:s-n};break;case Gc.BOTTOM_LEFT:case"bottom-left":l={x:r,y:s+a};break;case Gc.BOTTOM:case"bottom":l={x:r+(o-n)/2,y:s+a};break;case Gc.BOTTOM_RIGHT:case"bottom-right":l={x:r+o-n,y:s+a};break;case Gc.LEFT_TOP:case"left-top":l={x:r-n,y:s};break;case Gc.LEFT:case"left":l={x:r-n,y:s+(a-n)/2};break;case Gc.LEFT_BOTTOM:case"left-bottom":l={x:r-n,y:s+(a-n)};break;case Gc.RIGHT_TOP:case"right-top":l={x:r+o,y:s};break;case Gc.RIGHT:case"right":l={x:r+o,y:s+(a-n)/2};break;case Gc.RIGHT_BOTTOM:case"right-bottom":l={x:r+o,y:s+(a-n)};break;case Gc.TOP_LEFT_CORNER:case"top-left-corner":l={x:r-c,y:s-c};break;case Gc.TOP_RIGHT_CORNER:case"top-right-corner":l={x:r+o-c,y:s-c};break;case Gc.BOTTOM_LEFT_CORNER:case"bottom-left-corner":l={x:r-c,y:s+a-c};break;case Gc.BOTTOM_RIGHT_CORNER:case"bottom-right-corner":l={x:r+o-c,y:s+a-c};break;case Gc.CENTER:default:l={x:r+o/2-n/2,y:s+a/2-n/2}}return this._location=this.toGlobal(l.x,l.y),this._location}_getElement(){return this.element||this._createElementIfNeeded(),this.element}_createElementIfNeeded(){if(this.element)return;const{icon:t="arrow_forward",color:e="#FF0000"}=this.options,n=this.getScaledSize(),{x:i,y:r}=this.location,s=document.createElement("div");s.setAttribute("scene","animated-icon"),Object.assign(s.style,{position:"absolute",fontVariationSettings:"'FILL' 1",fontFamily:"Material Symbols Outlined",fontSize:n+"px",width:n+"px",height:n+"px",lineHeight:n+"px",padding:0,margin:0,color:e,textAlign:"center",verticalAlign:"middle",left:i+"px",top:r+"px",pointerEvents:"none"}),s.textContent=t,this.element=s}updateIconSizeAndPosition(){if(!this.element)return;this._location=null;const t=this.getScaledSize(),{x:e,y:n}=this.location;Object.assign(this.element.style,{fontSize:t+"px",width:t+"px",height:t+"px",lineHeight:t+"px",left:e+"px",top:n+"px"})}touch(){}invalidate(){this.updateIconSizeAndPosition()}start(){if(super.start(),this.isActive){if(this.overlay&&this._getElement().parentNode!==this.overlay&&this.overlay.appendChild(this._getElement()),this.target?.root?.app?.suppressAnimations)return;this.animations.forEach(t=>t.start())}}stop(){this.animations.forEach(t=>t.stop()),this.element&&this._getElement().parentNode&&this._getElement().parentNode.removeChild(this._getElement()),this._location=null,super.stop()}get center(){const t=this.getScaledSize(),{x:e,y:n}=this.location;return{x:e+t/2,y:n+t/2}}toGlobal(t,e){const{tx:n,ty:i}=this._delta;return this.projectComponentPoint(this.target,t+n,e+i)??this.target.toGlobal(t+n,e+i)}get root(){return this.target.root}createDOMElements(){this._getElement()}updateDOMElements(){this.element?this.updateIconSizeAndPosition():this._getElement()}updatePosition(){this.updateIconSizeAndPosition()}createAnimations(t){if(Array.isArray(t))return t.map(t=>("theta"in t&&(t={...t,theta:t.theta*(Math.PI/180)}),aa(this,t)));if(t){const e={...t};return"theta"in e&&(e.theta=e.theta*(Math.PI/180)),[aa(this,e)]}return[]}}$c.DECORATOR_TYPE="animated-icon";class Qc extends Xc{constructor(t,e,n={}){super(t,e,{distance:10,lineWidth:2,fillStyle:"rgba(0, 0, 0, 0.5)",animation:!1,...n}),this.pathElement=null,this.decoratorGroup=null,this.elementId=""}createDOMElements(){if(this.overlay)try{this.getSvgContainer();const t=this.getOrCreateDecoratorGroup(!0);this.decoratorGroup=t;const e=this.getDefsForType(),n=this.getVectorGroupId();this.elementId=`${n}-border`;const{color:i="#FF0000",animation:r=!1}=this.options,{fillStyle:s}=this.target.state||{},o=this.createFilter(this.elementId,this.options.fillStyle||s||"rgba(0, 0, 0, 0.5)");if(e.appendChild(o),r){const t=this.createGradient(this.elementId,i);e.appendChild(t)}const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("fill","none"),a.setAttribute("stroke-width",(this.options.lineWidth||2).toString()),a.setAttribute("stroke-linejoin","round"),a.setAttribute("pointer-events","none"),a.setAttribute("class","border-highlighting-path"),a.setAttribute("filter",`url(#${this.elementId}-filter)`),r?a.setAttribute("stroke",`url(#${this.elementId})`):a.setAttribute("stroke",i),t.appendChild(a),this.pathElement=a,this.vectorElement=t,this.updatePathData(),this.options.animation&&this.startAnimations()}catch(t){Ki("테두리 하이라이팅 요소 생성 실패:",t)}}updatePathData(){if(!this.pathElement)return;this.pathElement.setAttribute("visibility","visible"),this.pathElement.setAttribute("opacity","1"),this.decoratorGroup&&(this.decoratorGroup.setAttribute("visibility","visible"),this.decoratorGroup.setAttribute("opacity","1"));const t=this.getPathPoints(),e=this.createOffsetPath(t,this.options.distance),{round:n=0}=this.target.state||{},i=this.pointsToPathData(e,n);this.pathElement.setAttribute("d",i)}invalidate(){this.updatePathData()}startAnimations(){if(!this.isActive||!this.options.animation||!this.pathElement)return;this.pathElement.setAttribute("visibility","visible"),this.pathElement.setAttribute("opacity","1"),this.decoratorGroup&&(this.decoratorGroup.setAttribute("visibility","visible"),this.decoratorGroup.setAttribute("opacity","1")),this.elementId&&(this.pathElement.setAttribute("stroke",`url(#${this.elementId})`),this.pathElement.setAttribute("filter",`url(#${this.elementId}-filter)`));const t=this.getDefsForType();if(t){const e=t.querySelector(`#${this.elementId}`);if(e){e.querySelectorAll("animate").forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&(t.setAttribute("restart","always"),t.beginElement())}catch(t){Ki("애니메이션 시작 오류:",t)}})}}}createDefsElement(t){const e=document.createElementNS("http://www.w3.org/2000/svg","defs");return t.appendChild(e),e}getPathPoints(){if(!this.target.path||!Array.isArray(this.target.path)){const{left:t,top:e,width:n,height:i}=this.target.bounds;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}return this.target.path.map(t=>this.target.toGlobal(t.x,t.y))}createOffsetPath(t,e){const n=[],i=t.length;for(let r=0;r<i;r++){const s=t[(r-1+i)%i],o=t[r],a=t[(r+1)%i],c=o.x-s.x,l=o.y-s.y,h=a.x-o.x,d=a.y-o.y,u=this.normalize({x:l,y:-c}),p=this.normalize({x:d,y:-h}),f=this.normalize({x:(u.x+p.x)/2,y:(u.y+p.y)/2}),g={x:o.x+f.x*e,y:o.y+f.y*e};n.push(g)}return n}normalize(t){const e=Math.sqrt(t.x*t.x+t.y*t.y);return{x:t.x/e||0,y:t.y/e||0}}pointsToPathData(t,e=0){if(t.length<2)return"";let n="";const i=t.length,r=(t,e,n)=>{const i=e.x-t.x,r=e.y-t.y,s=Math.sqrt(i*i+r*r);return{x:t.x+i/s*n,y:t.y+r/s*n}};for(let s=0;s<i;s++){const o=t[s],a=t[(s+1)%i],c=t[(s-1+i)%i],l=Math.sqrt((o.x-c.x)**2+(o.y-c.y)**2),h=Math.sqrt((o.x-a.x)**2+(o.y-a.y)**2),d=Math.min(e,l/2,h/2),u=r(o,c,d),p=r(o,a,d);n+=0===s?`M${u.x},${u.y}`:` L${u.x},${u.y}`,n+=` Q${o.x},${o.y} ${p.x},${p.y}`}return n+=" Z",n}createFilter(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","filter");n.setAttribute("id",`${t}-filter`);const i=document.createElementNS("http://www.w3.org/2000/svg","feFlood");i.setAttribute("flood-color",e),i.setAttribute("result","flood");const r=document.createElementNS("http://www.w3.org/2000/svg","feComposite");r.setAttribute("in","flood"),r.setAttribute("in2","SourceAlpha"),r.setAttribute("operator","in"),r.setAttribute("result","mask");const s=document.createElementNS("http://www.w3.org/2000/svg","feMerge"),o=document.createElementNS("http://www.w3.org/2000/svg","feMergeNode");o.setAttribute("in","mask");const a=document.createElementNS("http://www.w3.org/2000/svg","feMergeNode");return a.setAttribute("in","SourceGraphic"),s.appendChild(o),s.appendChild(a),n.appendChild(i),n.appendChild(r),n.appendChild(s),n}createGradient(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");n.setAttribute("id",t),n.setAttribute("x1","0%"),n.setAttribute("y1","0%"),n.setAttribute("x2","100%"),n.setAttribute("y2","0%");const i=this.alterColor(e,120),r=this.alterColor(e,240),s=document.createElementNS("http://www.w3.org/2000/svg","stop");s.setAttribute("offset","0%"),s.setAttribute("stop-color",e);const o=document.createElementNS("http://www.w3.org/2000/svg","animate");o.setAttribute("attributeName","stop-color"),o.setAttribute("values",`${e};${i};${r};${e}`),o.setAttribute("dur","5s"),o.setAttribute("repeatCount","indefinite");const a=document.createElementNS("http://www.w3.org/2000/svg","stop");a.setAttribute("offset","100%"),a.setAttribute("stop-color",r);const c=document.createElementNS("http://www.w3.org/2000/svg","animate");return c.setAttribute("attributeName","stop-color"),c.setAttribute("values",`${r};${e};${i};${r}`),c.setAttribute("dur","5s"),c.setAttribute("repeatCount","indefinite"),s.appendChild(o),a.appendChild(c),n.appendChild(s),n.appendChild(a),n}alterColor(t,e){const n=this.convertToHex(t),i=parseInt(n.substring(1,3),16),r=parseInt(n.substring(3,5),16),s=parseInt(n.substring(5,7),16),o=this.rgbToHsl(i,r,s);o[0]=(o[0]+e/360)%1;const a=this.hslToRgb(o[0],o[1],o[2]);return`#${a[0].toString(16).padStart(2,"0")}${a[1].toString(16).padStart(2,"0")}${a[2].toString(16).padStart(2,"0")}`}rgbToHsl(t,e,n){t/=255,e/=255,n/=255;const i=Math.max(t,e,n),r=Math.min(t,e,n);let s=0,o=0;const a=(i+r)/2;if(i!==r){const c=i-r;switch(o=a>.5?c/(2-i-r):c/(i+r),i){case t:s=(e-n)/c+(e<n?6:0);break;case e:s=(n-t)/c+2;break;case n:s=(t-e)/c+4}s/=6}return[s,o,a]}hslToRgb(t,e,n){let i,r,s;if(0===e)i=r=s=n;else{const o=(t,e,n)=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t),a=n<.5?n*(1+e):n+e-n*e,c=2*n-a;i=o(c,a,t+1/3),r=o(c,a,t),s=o(c,a,t-1/3)}return[Math.round(255*i),Math.round(255*r),Math.round(255*s)]}convertToHex(t){if(/^#([0-9A-F]{6})$/i.test(t))return t;const e=document.createElement("canvas");e.width=1,e.height=1;const n=e.getContext("2d");if(!n)return"#FF0000";n.fillStyle=t,n.fillRect(0,0,1,1);const i=n.getImageData(0,0,1,1).data;return`#${i[0].toString(16).padStart(2,"0")}${i[1].toString(16).padStart(2,"0")}${i[2].toString(16).padStart(2,"0")}`}start(){super.start(),this.isActive&&this.options.animation&&this.startAnimations()}removeDOMElements(){try{if(this.pathElement&&this.pathElement.parentNode&&this.pathElement.parentNode.removeChild(this.pathElement),this.pathElement=null,this.overlay){const t=this.getDefsForType();if(t&&this.elementId){const e=t.querySelector(`#${this.elementId}-filter`);e&&e.remove();const n=t.querySelector(`#${this.elementId}`);n&&n.remove()}}super.removeDOMElements()}catch(t){Ki("테두리 하이라이팅 요소 제거 중 오류:",t)}}}Qc.DECORATOR_TYPE="border-highlighting";class Zc extends Xc{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",...n}),this.textElements=[],this.rectElements=[]}updateDOMElements(){if(!this.target.anchors||!this.target.anchors.length)return void this.removeDOMElements();const t=this.options,e=this.target.anchors,n=this.getOrCreateDecoratorGroup(!0);this.textElements=[],this.rectElements=[];const i=this.getComponentBounds();e.forEach(e=>{const{name:r,position:s}=e;let{x:o,y:a}=s||{};if(!r)return;let c=this.calculateOffsetX(o,i),l=this.calculateOffsetY(a,i);const h=this.projectComponentPoint(this.target,o,a);if(!h)return;o=h.x,a=h.y;const d=document.createElementNS("http://www.w3.org/2000/svg","text");d.setAttribute("fill",t.textColor),d.setAttribute("font-family",t.fontFamily),d.setAttribute("font-size",t.fontSize),d.textContent=r,n.appendChild(d);const u=d.getBBox();n.removeChild(d);const p=u.width,f=u.height;c=-1==c?-p-9:3,l=-1==l?-f-9:3,d.setAttribute("x",(o+c+3).toString()),d.setAttribute("y",(a+l+f).toString());const g=document.createElementNS("http://www.w3.org/2000/svg","rect");g.setAttribute("x",(o+c).toString()),g.setAttribute("y",(a+l).toString()),g.setAttribute("width",(p+6).toString()),g.setAttribute("height",(f+6).toString()),g.setAttribute("rx",t.cornerRadius.toString()),g.setAttribute("ry",t.cornerRadius.toString()),g.setAttribute("fill",t.bgColor),n.appendChild(g),n.appendChild(d),this.rectElements.push(g),this.textElements.push(d)})}calculateOffsetX(t,e){return t<e.left+1?-1:1}calculateOffsetY(t,e){return t<e.top+1?-1:1}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}createDOMElements(){this.updateDOMElements()}}Zc.DECORATOR_TYPE="anchors";class Jc extends Xc{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",offsetX:3,offsetY:-8,animation:!1,...n}),this.textElement=null,this.backgroundElement=null,this.currentTag=""}createDOMElements(){const t=this.target.decotag;if(!t)return;this.currentTag=t;const{fontFamily:e,fontSize:n,textColor:i,padding:r,cornerRadius:s,bgColor:o,animation:a,repeat:c,duration:l}=this.options,h=this.getOrCreateDecoratorGroup(!0);h.setAttribute("transform","translate(0, 0)"),this.textElement=document.createElementNS("http://www.w3.org/2000/svg","text"),this.textElement.textContent=t,this.textElement.setAttribute("x",`${r}`),this.textElement.setAttribute("y",`-${n}`),this.textElement.setAttribute("font-family",e),this.textElement.setAttribute("font-size",n),this.textElement.setAttribute("fill",i),this.textElement.setAttribute("dominant-baseline","middle"),h.appendChild(this.textElement);const d=this.textElement.getBBox();if(this.backgroundElement=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.backgroundElement.setAttribute("x",(d.x-r).toString()),this.backgroundElement.setAttribute("y",(d.y-r).toString()),this.backgroundElement.setAttribute("width",(d.width+2*r).toString()),this.backgroundElement.setAttribute("height",(d.height+2*r).toString()),this.backgroundElement.setAttribute("rx",s.toString()),this.backgroundElement.setAttribute("ry",s.toString()),this.backgroundElement.setAttribute("fill",o),h.replaceChildren(),h.appendChild(this.backgroundElement),h.appendChild(this.textElement),a){const t=this.createFadeAnimation(.3,1,l,{repeat:c});this.addAnimations(h,[t])}this.vectorElement=h,this.updatePosition()}updateDOMElements(){const t=this.target.decotag;t&&t===this.currentTag?this.vectorElement&&this.updatePosition():(this.removeDOMElements(),this.createDOMElements())}updatePosition(){super.updatePosition()}invalidate(){this.updatePosition()}}Jc.DECORATOR_TYPE="decotag";class tl extends Xc{constructor(t,e,n={}){super(t,e,{arrowColor:"#FFA500",arrowHeadLength:12,lineWidth:1.5,startAlpha:.6,endAlpha:1,animated:!0,animationDuration:5e3,repeat:!1,...n}),this.currentMappings=null,this.cachedArrows=[],this._incomingTimer=null}findIncomingSources(){const t=this.target.root;if(!t)return[];const e=this.target.state?.id;if(!e)return[];const n=[];return t.traverse(i=>{if(i===this.target)return;const r=i.model?.mappings;if(r)for(const s of r){if(!s.target)continue;if(s.target===`#${e}`){n.push({from:i,to:this.target});break}const r=t.findAll(s.target,i);if(r?.some(t=>t===this.target)){n.push({from:i,to:this.target});break}}}),n}appendArrow(t,e,n,i,r,s){const o=e.center,a=n.center,c=this.projectComponentPoint(e,o.x,o.y),l=this.projectComponentPoint(n,a.x,a.y);if(!c||!l)return;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,s.arrowHeadLength),u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",h),u.setAttribute("stroke",r),u.setAttribute("stroke-width",String(s.lineWidth||2)),u.setAttribute("fill","none"),u.setAttribute("data-source-id",e.state?.id||""),u.setAttribute("data-target-id",n.state?.id||"");const p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d",d),p.setAttribute("fill",i),p.setAttribute("stroke","none"),t.appendChild(u),t.appendChild(p)}createDOMElements(){this.removeDOMElements();const t=this.target.mappings&&this.target.mappings.length>0;this.currentMappings=this.target.mappings;const e=this.options,n=e.arrowColor||"#FFA500",i=this.getOrCreateDecoratorGroup(!0),r=this.getDefsForType(),s=`data-spread-style-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,o=document.createElementNS("http://www.w3.org/2000/svg","style");o.setAttribute("id",s),o.textContent=`\n @keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: ${e.repeat?"0.2":"0"}; }\n }\n .arrow-animated {\n animation: fadeOut ${e.animationDuration||2e3}ms linear ${e.repeat?"infinite":"1"} forwards;\n }\n `,r.appendChild(o);const a=Date.now(),c=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),l=`arrow-gradient-out-${a}-${c}`,h=this.createGradient(l,n,e);r.appendChild(h);const d=tl.INCOMING_ARROW_COLOR,u=`arrow-gradient-in-${a}-${c}`,p=this.createGradient(u,d,e);r.appendChild(p);const f=document.createElementNS("http://www.w3.org/2000/svg","g");if(f.setAttribute("class",e.animated?"arrow-animated":""),i.appendChild(f),this.cachedArrows=[],t){this.target.mappings.forEach(t=>{const i=this.target.root.findAll(t.target,this.target);i?.length&&i.forEach(t=>{t!==this.target&&(this.cachedArrows.push({from:this.target,to:t}),this.appendArrow(f,this.target,t,n,`url(#${l})`,e))})})}this.vectorElement=i,this._incomingTimer=setTimeout(()=>{if(this._incomingTimer=null,!this.vectorElement)return;this.findIncomingSources().forEach(({from:t})=>{this.cachedArrows.push({from:t,to:this.target}),this.appendArrow(f,t,this.target,d,`url(#${u})`,e)})},tl.INCOMING_DEBOUNCE_MS)}createGradient(t,e,n){const i=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");i.setAttribute("id",t),i.setAttribute("gradientUnits","userSpaceOnUse");const r=document.createElementNS("http://www.w3.org/2000/svg","stop");r.setAttribute("offset","0%"),r.setAttribute("stop-color",e),r.setAttribute("stop-opacity",(n.startAlpha||.5).toString());const s=document.createElementNS("http://www.w3.org/2000/svg","stop");return s.setAttribute("offset","100%"),s.setAttribute("stop-color",e),s.setAttribute("stop-opacity",(n.endAlpha||1).toString()),i.appendChild(r),i.appendChild(s),i}createArrowPaths(t,e,n){const i=e.x-t.x,r=e.y-t.y,s=Math.atan2(r,i),o=e.x+n*Math.cos(s+tl.ARROW_ANGLE_1),a=e.y+n*Math.sin(s+tl.ARROW_ANGLE_1),c=e.x+n*Math.cos(s+tl.ARROW_ANGLE_2),l=e.y+n*Math.sin(s+tl.ARROW_ANGLE_2);return{linePath:`M ${t.x} ${t.y} L ${e.x} ${e.y}`,headPath:`M ${e.x} ${e.y} L ${o} ${a} L ${c} ${l} Z`}}updateDOMElements(){if(!this.target.app?.isEditMode)return void this.removeDOMElements();this.target.mappings!==this.currentMappings?(this.removeDOMElements(),requestAnimationFrame(()=>{this.createDOMElements()})):this.vectorElement&&this.updatePosition()}updatePosition(){const t=this.getDecoratorType(),e=this.getSvgContainer().querySelector(`g[data-decorator-type-container="${t}"]`);if(!e)return;const n=this.getVectorGroupId(),i=e.querySelector(`g[data-decorator-group-id="${n}"]`);if(!i)return;const r=this.options,s=i.querySelector("g.arrow-animated")||i,o=Array.from(s.querySelectorAll('path[fill="none"]')),a=Array.from(s.querySelectorAll('path[stroke="none"]'));if(0===o.length)return;const c=Math.min(o.length,a.length,this.cachedArrows.length);for(let t=0;t<c;t++){const{from:e,to:n}=this.cachedArrows[t],i=e.center,s=n.center,c=this.projectComponentPoint(e,i.x,i.y),l=this.projectComponentPoint(n,s.x,s.y);if(!c||!l)continue;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,r.arrowHeadLength);o[t].setAttribute("d",h),a[t].setAttribute("d",d)}}removeDOMElements(){this.currentMappings=null,this.cachedArrows=[],this._incomingTimer&&(clearTimeout(this._incomingTimer),this._incomingTimer=null);try{if(this.overlay){const t=this.getSvgContainer();if(t){const e=this.getDecoratorType(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`);if(n){const t=n.querySelector(`defs[data-defs-for="${e}"]`);if(t){t.querySelectorAll("style").forEach(t=>t.remove());t.querySelectorAll("linearGradient").forEach(t=>t.remove())}}}}this.animationElements=[],super.removeDOMElements()}catch(t){Ki("데이터 스프레드 데코레이터 요소 제거 중 오류:",t)}}invalidate(){this.updatePosition()}}tl.DECORATOR_TYPE="data-spread",tl.ARROW_ANGLE_1=160*Math.PI/180,tl.ARROW_ANGLE_2=200*Math.PI/180,tl.INCOMING_ARROW_COLOR="#4A9EFF",tl.INCOMING_DEBOUNCE_MS=500;class el extends Xc{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:2,padding:2,fontSize:"12px",fontFamily:"Arial",offsetX:4,offsetY:4,...n}),this.textElements=[],this.rectElements=[]}createDOMElements(){this.updateDOMElements()}updateDOMElements(){if(!this.target.isLine||!this.target.isLine())return void this.removeDOMElements();const{offsetX:t,offsetY:e,padding:n,textColor:i,bgColor:r,cornerRadius:s,fontSize:o,fontFamily:a}=this.options,c=this.getOrCreateDecoratorGroup(!0);this.textElements=[],this.rectElements=[];const{fromEnd:l,toEnd:h}=this.target;[l,h].filter(Boolean).forEach(l=>{const{component:h,anchor:d}=l;if(!d)return;const{name:u,position:p}=d||{};if(!h.rootModel||!u||!p)return;const f=this.projectComponentPoint(h,p.x,p.y);if(!f)return;let{x:g,y:m}=f;const y=document.createElementNS("http://www.w3.org/2000/svg","g"),b=document.createElementNS("http://www.w3.org/2000/svg","text");b.setAttribute("text-anchor","middle"),b.setAttribute("dominant-baseline","middle"),b.setAttribute("x","0"),b.setAttribute("y","0"),b.setAttribute("fill",i),b.setAttribute("font-family",a),b.setAttribute("font-size",o),b.textContent=u,c.appendChild(b);const v=b.getBBox();c.removeChild(b);const _=document.createElementNS("http://www.w3.org/2000/svg","rect"),x=v.width+2*(n??0),w=v.height+2*(n??0);g+=(t??0)+x/2,m+=(e??0)+w/2,_.setAttribute("x",(-x/2).toString()),_.setAttribute("y",(-w/2).toString()),_.setAttribute("width",x.toString()),_.setAttribute("height",w.toString()),_.setAttribute("rx",(s??0).toString()),_.setAttribute("ry",(s??0).toString()),_.setAttribute("fill",r),y.appendChild(_),y.appendChild(b),y.setAttribute("transform",`translate(${g}, ${m})`),c.appendChild(y),this.rectElements.push(_),this.textElements.push(b)})}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}}el.DECORATOR_TYPE="link",Fs.registerDecorator("bouncing-arrow",Kc),Fs.registerDecorator("animated-icon",$c),Fs.registerDecorator("border-highlighting",Qc),Fs.registerDecorator("anchors",Zc),Fs.registerDecorator("decotag",Jc),Fs.registerDecorator("data-spread",tl),Fs.registerDecorator("link",el);class nl{constructor(t){this.params=Object.assign({},t)}excute(){}}class il extends nl{execute(){this.params.changes.forEach(t=>t.component.set(t.after))}static before(t){return t.map(t=>({component:t}))}static after(t,e){e.execute(null,!1)}static around(t,e,n){e.call(n),t.execute(null,!1)}}const rl="left",sl="right",ol="center",al="bottom",cl="middle",ll="z-front",hl="z-back",dl="z-middle",ul=[rl,sl,ol,"top",cl,al,ll,hl,dl];function pl(t){if(!this.hasSameParentForAllSelected||-1===ul.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(e.length<=1)return;const n=this.app.commander;il.around(n,function(){!function(t,e){const n=JSON.parse(JSON.stringify(e[0].bounds));let i=n.left+n.width,r=n.top+n.height;for(let t=0;t<e.length;t++){const s=e[t].bounds;n.left=s.left>n.left?n.left:s.left,n.top=s.top>n.top?n.top:s.top,i=s.left+s.width>i?s.left+s.width:i,r=s.top+s.height>r?s.top+s.height:r}switch(n.width=i-n.left,n.height=r-n.top,t){case rl:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left,top:i.top,width:i.width,height:i.height}}break;case ol:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left+n.width/2-i.width/2,top:i.top,width:i.width,height:i.height}}break;case sl:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:i-n.width,top:n.top,width:n.width,height:n.height}}break;case"top":for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top,width:i.width,height:i.height}}break;case cl:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top+n.height/2-i.height/2,width:i.width,height:i.height}}break;case al:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:n.left,top:r-n.height,width:n.width,height:n.height}}break;case ll:{let t=1/0;for(let n=0;n<e.length;n++){const i=e[n].state.zPos||0;i<t&&(t=i)}for(let n=0;n<e.length;n++)e[n].set({zPos:t});break}case hl:{let t=-1/0;for(let n=0;n<e.length;n++){const i=(e[n].state.zPos||0)+(e[n].state.depth||0);i>t&&(t=i)}for(let n=0;n<e.length;n++){const i=e[n].state.depth||0;e[n].set({zPos:t-i})}break}case dl:{let t=1/0,n=-1/0;for(let i=0;i<e.length;i++){const r=e[i].state.zPos||0,s=e[i].state.depth||0;r<t&&(t=r),r+s>n&&(n=r+s)}const i=(t+n)/2;for(let t=0;t<e.length;t++){const n=e[t].state.depth||0;e[t].set({zPos:i-n/2})}break}default:;}}(t,e)})}const fl="VERTICAL",gl=[fl,"HORIZONTAL","Z"];function ml(t){if(!this.hasSameParentForAllSelected||-1===gl.indexOf(t))return;const e=this.selected;if(e.length<=1)return;const n=this.app.commander;il.around(n,function(){!function(t,e){if("Z"===t)return void function(t){const e=t.filter(t=>!t.stuck).slice(0);e.sort((t,e)=>(t.state.zPos||0)+(t.state.depth||0)/2-((e.state.zPos||0)+(e.state.depth||0)/2));const n=e.reduce((t,e)=>t+(e.state.depth||0),0),i=e[0].state.zPos||0,r=((e[e.length-1].state.zPos||0)+(e[e.length-1].state.depth||0)-i-n)/(e.length-1);let s=i+(e[0].state.depth||0);for(let t=1;t<e.length-1;t++){const n=e[t],i=n.state.depth||0;s+=r,n.set({zPos:s}),s+=i}}(e);const n=e.filter(t=>!t.stuck).slice(0);n.sort(function(e,n){const i=e.center,r=n.center;return t===fl?i.y-r.y:i.x-r.x});const i=n.reduce((e,n)=>e+(t===fl?n.bounds.height:n.bounds.width),0),r=n[0].bounds,s=n[n.length-1].bounds,o=((t===fl?s.top+s.height-r.top:s.left+s.width-r.left)-i)/(n.length-1);let a=t===fl?r.top+r.height:r.left+r.width;for(let e=1;e<n.length-1;e++){const i=n[e],r=i.bounds;a+=o,t===fl?(i.bounds={left:r.left,top:a,width:r.width,height:r.height},a+=r.height):(i.bounds={left:a,top:r.top,width:r.width,height:r.height},a+=r.width)}}(t,e)})}function yl(t){let e=0;for(;t&&!t.isRootModel();)e+=t.get("rotation")||0,t=t.parent;return e%(2*Math.PI)}class bl extends nl{execute(){this.params.changes.forEach(t=>{const{component:e,to_container:n,to_index:i,to_left:r,to_top:s}=t,o=function(t){if(t.isRootModel())return t.bounds;const{bounds:e,rotatePoint:n}=t;let i=n;return i=t.toScene(i.x,i.y),{left:i.x-(n.x-e.left),top:i.y-(n.y-e.top),width:e.width,height:e.height}}(e),a=yl(e);if(function(t){const e=t.parent?.model?.zPos;if(null==e)return;const n=t.state.zPos||0;t.set("zPos",n+e)}(e),e.removeSelf(!n),e.bounds=o,e.set("rotation",a),n){e.set("rotation",function(t,e){return((t.get("rotation")||0)-yl(e))%(2*Math.PI)}(e,n));const o=function(t,e){if(e.isRootModel())return t.bounds;const{bounds:n,rotatePoint:i}=t,r=e.fromScene(i.x,i.y),s=e.bounds;return{left:r.x-(i.x-n.left)-s.left,top:r.y-(i.y-n.top)-s.top,width:n.width,height:n.height}}(e,n);t.to_left=void 0!==r?r:o.left,t.to_top=void 0!==s?s:o.top,e.bounds={left:t.to_left,top:t.to_top,width:o.width,height:o.height},void 0===i?n.addComponent(e):n.insertComponentAt(e,i)}})}}function vl(t,e,n){this.app.commander.execute(new bl({changes:[{component:t,to_container:e,to_index:n}]}))}function _l(t){const e=this.selected.filter(t=>!t.stuck);if(0===e.length||e[0].isRootModel())return;if(e.length>1&&("forward"===t||"backward"===t))return;const n=e[0].parent;let i;if("forward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t+1}]}else if("backward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t-1}]}else i=e.filter(t=>t.parent===n).sort((e,i)=>{const r=n.indexOf(e)<n.indexOf(i);return"front"===t?r:!r}).map((e,i)=>(n.indexOf(e),{component:e,to_container:n,to_index:"front"===t?n.components.length-i-1:i}));const r=new bl({changes:i});this.app.commander.execute(r)}function xl(t,e,n,i){const r=cc.register(t.type);if(!r)return $i("Class not found",t.type),null;n&&(t.refid=n(t.refid)),t.id&&i&&i(t.id)&&delete t.id;const s=new r(t,e);return t.components&&s.isContainer()&&(t.components.forEach(t=>{const r=xl(t,e,n,i);r&&s.addComponent(r)}),delete t.components),s.created(),s}function wl(t,e){const n=Jn(t.hierarchy);return delete n.id,xl(n,t.app,e)}function Ml(t,e,n){t instanceof Array||(t=[t]),n||(n=this.model_layer);const i=[],r=new Map;this.selected=t.map(t=>{try{return xl(t,n.app,t=>{const e=this.getNewRefid();return void 0!==t&&r.set(t,e),e},t=>(this.indexMap[t]||[])[0])}catch(t){return $i(t),!1}}).filter(Boolean).map(t=>{const{left:s,top:o,width:a,height:c,x:l,y:h,cx:d,cy:u}=e;return t.replaceRefids(r),isNaN(s)||isNaN(o)||isNaN(a)||isNaN(c)||(t.bounds={left:s,top:o,width:a,height:c}),isNaN(l)||isNaN(h)||t.move({x:l,y:h},!1),isNaN(d)||isNaN(u)||(t.center={x:d,y:u}),i.push({component:t,to_container:n}),t}),this.app.commander.execute(new bl({changes:i}))}function Sl(){const t=[],e=new Map;if(this.selected=this.selected.filter(t=>!t.isRootModel()).map(n=>{const i=wl(n,t=>{const n=this.getNewRefid();return void 0!==t&&e.set(t,n),n});return i.move({x:20,y:20},!1),t.push({component:i,to_container:n.parent}),i}).map(t=>(t.replaceRefids(e),t)),0===t.length)return;const n=new bl({changes:t});this.app.commander.execute(n)}function kl(){const t=this.selected;this.selected=[];let e=null;const n=t.filter(t=>!t.isRootModel()&&(t.parent.focusible||t.parent.isGroup())).map(t=>(e||(e=t.parent),{component:t,to_container:null}));for(;e&&e.isGroup();){const t=[];if(e.components.filter(t=>!n.find(e=>e.component===t)).forEach(e=>t.push(e)),t.length>1)break;const i=e.parent;t.forEach(t=>n.push({component:t,to_container:i})),n.push({component:e,to_container:null}),e=i}n.length>0&&this.app.commander.execute(new bl({changes:n})),e&&e.calculateBounds&&e.calculateBounds()}const Al=new Set(["execute","redo","undo","command-reset"]);function El(t,e,n,i){const r=function(t,e){return Al.has(e)?t.app?.commander:"mode"===e?t.app:t}(this,e);r?.[t](e,n,i)}function Cl(t,e,n){El.call(this,"on",t,e,n)}function Tl(t,e,n){El.call(this,"once",t,e,n)}function Pl(t,e,n){El.call(this,"off",t,e,n)}function Dl(t){const e=this.target_element,n=t||this.fitMode,i=this;function r(){i.fit(n),document.fullscreenElement||document.removeEventListener("fullscreenchange",r)}document.addEventListener("fullscreenchange",r),e.requestFullscreen().catch(()=>{document.removeEventListener("fullscreenchange",r)})}let Ol=0;function zl(){const t=this.selected.filter(t=>!t.isRootModel()).map(t=>t.hierarchy);if(0!==t.length)return Ol=0,JSON.stringify(t,null,2)}function Il(){Ol=0;const t=zl.call(this);return kl.call(this),t}function Ll(t){if(t)try{Ol++,Ml.call(this,JSON.parse(t),{x:15*Ol,y:15*Ol})}catch(e){Ki(e,t)}}const jl=function(){return{escape:function(t){return t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")},parseExtension:t,mimeType:function(e){const n=t(e).toLowerCase();return function(){const t="application/font-woff",e="image/jpeg";return{woff:t,woff2:t,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:e,jpeg:e,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}()[n]||""},dataAsUrl:function(t,e){return"data:"+e+";base64,"+t},isDataUrl:function(t){return-1!==t.search(/^(data:)/)},canvasToBlob:function(t){return t.toBlob?new Promise(function(e){t.toBlob(e)}):function(t){return new Promise(function(e){const n=window.atob(t.toDataURL().split(",")[1]),i=n.length,r=new Uint8Array(i);for(let t=0;t<i;t++)r[t]=n.charCodeAt(t);e(new Blob([r],{type:"image/png"}))})}(t)},resolveUrl:function(t,e){const n=document.implementation.createHTMLDocument(),i=n.createElement("base");n.head.appendChild(i);const r=n.createElement("a");return n.body.appendChild(r),i.href=e,r.href=t,r.href},getAndEncode:function(t){const e=3e4;Gl.impl.options.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());return new Promise(function(n){const i=new XMLHttpRequest;let r;if(i.onreadystatechange=s,i.ontimeout=o,i.responseType="blob",i.timeout=e,i.open("GET",t,!0),i.send(),Gl.impl.options.imagePlaceholder){const t=Gl.impl.options.imagePlaceholder.split(/,/);t&&t[1]&&(r=t[1])}function s(){if(4!==i.readyState)return;if(200!==i.status)return void(r?n(r):a("cannot fetch resource: "+t+", status: "+i.status));const e=new FileReader;e.onloadend=function(){const t=e.result.split(/,/)[1];n(t)},e.readAsDataURL(i.response)}function o(){r?n(r):a("timeout of "+e+"ms occured while fetching resource: "+t)}function a(t){Ki(t),n("")}})},uid:function(){let t=0;return function(){return"u"+e()+t++;function e(){return("0000"+(Math.random()*Math.pow(36,4)|0).toString(36)).slice(-4)}}}(),delay:function(t){return function(e){return new Promise(function(n){setTimeout(function(){n(e)},t)})}},asArray:function(t){const e=[],n=t.length;for(let i=0;i<n;i++)e.push(t[i]);return e},escapeXhtml:function(t){return t.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(t){return new Promise(function(e,n){const i=new Image;i.onload=function(){e(i)},i.onerror=n,i.src=t})},width:function(t){const n=e(t,"border-left-width"),i=e(t,"border-right-width");return t.scrollWidth+n+i},height:function(t){const n=e(t,"border-top-width"),i=e(t,"border-bottom-width");return t.scrollHeight+n+i}};function t(t){const e=/\.([^\.\/]*?)$/g.exec(t);return e?e[1]:""}function e(t,e){const n=window.getComputedStyle(t).getPropertyValue(e);return parseFloat(n.replace("px",""))}}(),Rl=function(){const t=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(t,r,s){return o()?Promise.resolve(t):Promise.resolve(t).then(n).then(function(e){let n=Promise.resolve(t);return e.forEach(function(t){n=n.then(function(e){return i(e,t,r,s)})}),n});function o(){return!e(t)}},shouldProcess:e,impl:{readUrls:n,inline:i}};function e(e){return-1!==e.search(t)}function n(e){const n=[];let i;for(;null!==(i=t.exec(e));)n.push(i[1]);return n.filter(function(t){return!jl.isDataUrl(t)})}function i(t,e,n,i){return Promise.resolve(e).then(function(t){return n?jl.resolveUrl(t,n):t}).then(i||jl.getAndEncode).then(function(t){return jl.dataAsUrl(t,jl.mimeType(e))}).then(function(n){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+jl.escape(t)+")(['\"]?\\))","g")}(e),"$1"+n+"$3")})}}(),Fl=function(){return{resolveAll:function(){return t().then(function(t){return Promise.all(t.map(function(t){return t.resolve()}))}).then(function(t){return t.join("\n")})},impl:{readAll:t}};function t(){return Promise.resolve(jl.asArray(document.styleSheets)).then(function(t){const e=[];return t.forEach(function(t){try{jl.asArray(t.cssRules||[]).forEach(t=>e.push(t))}catch(e){$i("Error while reading CSS rules from "+t.href,e instanceof Error?e.message:String(e))}}),e}).then(function(t){return t.filter(function(t){return t.type===CSSRule.FONT_FACE_RULE}).filter(function(t){return Rl.shouldProcess(t.style.getPropertyValue("src"))})}).then(function(e){return e.map(t)});function t(t){return{resolve:function(){const e=(t.parentStyleSheet||{}).href;return Rl.inlineAll(t.cssText,e)},src:function(){return t.style.getPropertyValue("src")}}}}}(),Bl=function(){return{inlineAll:function e(n){return n instanceof Element?i(n).then(function(){return n instanceof HTMLImageElement?t(n).inline().then(()=>n):Promise.all(jl.asArray(n.childNodes).map(function(t){return e(t)})).then(()=>n)}):Promise.resolve(n);function i(t){const e=t.style.getPropertyValue("background");return e?Rl.inlineAll(e).then(function(e){t.style.setProperty("background",e,t.style.getPropertyPriority("background"))}).then(function(){return t}):Promise.resolve(t)}},impl:{newImage:t}};function t(t){return{inline:function(e){return jl.isDataUrl(t.src)?Promise.resolve():Promise.resolve(t.src).then(e||jl.getAndEncode).then(function(e){return jl.dataAsUrl(e,jl.mimeType(t.src))}).then(function(e){return new Promise(function(n,i){t.onload=n,t.onerror=i,t.src=e})})}}}}(),Nl={imagePlaceholder:void 0,cacheBust:!1};function Hl(t,e){return function(t){void 0===t.imagePlaceholder?Gl.impl.options.imagePlaceholder=Nl.imagePlaceholder:Gl.impl.options.imagePlaceholder=t.imagePlaceholder;void 0===t.cacheBust?Gl.impl.options.cacheBust=Nl.cacheBust:Gl.impl.options.cacheBust=t.cacheBust}(e=e||{}),Promise.resolve(t).then(function(t){return Vl(t,e.filter,!0)}).then(function(t){return function(t){return Bl.inlineAll(t).then(function(){return t})}(t)}).then(function(t){const{bgcolor:n,width:i,height:r,style:s,sx:o=1,sy:a=1}=e||{},c=t.style;n&&(c.backgroundColor=n);i&&(c.width=i+"px");r&&(c.height=r+"px");c["margin-left"]="0px",c["margin-top"]="0px",c.transform=`rotate(0rad) translate(0px, 0px) scale(${o}, ${a}) perspective(1px)`,s&&Object.keys(s).forEach(function(t){c[t]=s[t]});return t}).then(function(n){return function(t,e,n){return Promise.resolve(t).then(function(t){return t.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),(new XMLSerializer).serializeToString(t)}).then(jl.escapeXhtml).then(function(t){return'<foreignObject x="0" y="0" width="100%" height="100%">'+t+"</foreignObject>"}).then(function(t){return'<svg xmlns="http://www.w3.org/2000/svg" width="'+e+'" height="'+n+'">'+t+"</svg>"}).then(function(t){return"data:image/svg+xml;charset=utf-8,"+t})}(n,e.width||jl.width(t),e.height||jl.height(t))})}function Yl(t,e){return Hl(t,e).then(jl.makeImage).then(jl.delay(100)).then(function(n){const i=function(t){const n=document.createElement("canvas");if(n.width=e.width||jl.width(t),n.height=e.height||jl.height(t),e.bgcolor){const t=n.getContext("2d");t.fillStyle=e.bgcolor,t.fillRect(0,0,n.width,n.height)}return n}(t);return i.getContext("2d").drawImage(n,0,0),i})}function Vl(t,e,n){return n||!e||e(t)?Promise.resolve(t).then(function(t){if(t instanceof HTMLCanvasElement)try{return jl.makeImage(t.toDataURL()).then(t=>t)}catch(t){$i(t)}return t.cloneNode(!1)}).then(function(n){return function(t,e,n){const i=t.childNodes;return 0===i.length?Promise.resolve(e):r(e,jl.asArray(i),n).then(function(){return e});function r(t,e,n){let i=Promise.resolve();return e.forEach(function(e){i=i.then(function(){return Vl(e,n,!1)}).then(function(e){e&&t.appendChild(e)})}),i}}(t,n,e)}).then(function(e){return function(t,e){return e instanceof Element?Promise.resolve().then(n).then(i).then(r).then(s).then(function(){return e}):e;function n(){function n(t,e){function n(t,e){jl.asArray(t).forEach(function(n){e.setProperty(n,t.getPropertyValue(n),t.getPropertyPriority(n))})}t.cssText?e.cssText=t.cssText:n(t,e)}n(window.getComputedStyle(t),e.style)}function i(){function n(n){const i=window.getComputedStyle(t,n),r=i.getPropertyValue("content");if(""===r||"none"===r)return;const s=jl.uid(),o=e;o.className=o.className+" "+s;const a=document.createElement("style");function c(t,e,n){const i="."+t+":"+e,r=n.cssText?s(n):o(n);return document.createTextNode(i+"{"+r+"}");function s(t){const e=t.getPropertyValue("content");return t.cssText+" content: "+e+";"}function o(t){return jl.asArray(t).map(e).join("; ")+";";function e(e){return e+": "+t.getPropertyValue(e)+(t.getPropertyPriority(e)?" !important":"")}}}a.appendChild(c(s,n,i)),e.appendChild(a)}[":before",":after"].forEach(function(t){n(t)})}function r(){t instanceof HTMLTextAreaElement&&e instanceof HTMLTextAreaElement&&(e.textContent=t.value),t instanceof HTMLInputElement&&e instanceof HTMLInputElement&&e.setAttribute("value",t.value)}function s(){e instanceof SVGElement&&(e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e instanceof SVGRectElement&&["width","height"].forEach(function(t){const n=e.getAttribute(t);n&&e.style.setProperty(t,n)}))}}(t,e)}):Promise.resolve(void 0)}const Gl={toSvg:Hl,toPng:function(t,e){return Yl(t,e||{}).then(function(t){return t.toDataURL()})},toJpeg:function(t,e){return Yl(t,e=e||{}).then(function(t){return t.toDataURL("image/jpeg",e.quality||1)})},toBlob:function(t,e){return Yl(t,e||{}).then(t=>jl.canvasToBlob(t))},toPixelData:function(t,e){return Yl(t,e||{}).then(function(e){return e.getContext("2d").getImageData(0,0,jl.width(t),jl.height(t)).data})},impl:{fontFaces:Fl,images:Bl,util:jl,inliner:Rl,options:{}}};function Ul(t,e,n,i){const r=this.model_layer,s=r._overlay;return new Promise(function(o,a){if(r){const a=r.get("width"),c=r.get("height");n=n||a,i=i||c;const l=r.get("translate"),h=r.get("scale"),d=Math.min(n/a,i/c);n=a*d,i=c*d,r.set("translate",{x:0,y:0}),r.set("scale",{x:d/Hr,y:d/Hr});let u=cc.createCanvas(n,i);const p=u.getContext("2d");if(r.draw(p),r.set("translate",l),r.set("scale",h),!s)return o(u.toDataURL(t,e)),void(u=null);Gl.toPng(s,{sx:d,sy:d,width:n,height:i}).then(function(r){const s=new Image;s.onload=function(){p.drawImage(s,0,0,n,i),o(u.toDataURL(t,e)),u=null},s.src=r},function(n){Ki(n),o(u.toDataURL(t,e)),u=null})}else a("No target model")})}function Wl(){if(!this.hasSameParentForAllSelected)return;const t=this.selected.filter(t=>!!t.parent&&!t.stuck);if(t.length<2)return;const e=t[0].parent,n=[],i=t.sort((t,n)=>e.components.indexOf(t)-e.components.indexOf(n));i.forEach(t=>{n.push(t.bounds)});const r=cc.union(n);let s=t[0].fromParent(r.left,r.top);s=t[0].toScene(s.x,s.y);const o=new Map,a=xl({type:"group",left:s.x,top:s.y,width:r.width,height:r.height},e.app,t=>{const e=this.getNewRefid();return void 0!==t&&o.set(t,e),e});a.replaceRefids(o);const c=[{component:a,to_container:e}];i.forEach(t=>{c.push({component:t,to_container:a})}),this.app.commander.execute(new bl({changes:c})),this.selected=[a]}function Xl(){if(0===this.selected.length)return;const t=[],e=[];this.selected.forEach(n=>{if(!n.isGroup())return;const i=n.parent;n.components.forEach(n=>{t.push(n),e.push({component:n,to_container:i})}),e.push({component:n,to_container:null})}),this.app.commander.execute(new bl({changes:e})),this.selected=t}function ql(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=cc.union(e),i=n.left+n.width/2;t.map(t=>{t.symmetryX(i)})}function Kl(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=cc.union(e),i=n.top+n.height/2;t.map(t=>{t.symmetryY(i)})}function $l(){il.around(this.app.commander,ql,this)}function Ql(){il.around(this.app.commander,Kl,this)}function Zl(t,e,n){const i=this.findAll(t,n);return i.forEach(t=>{t.set(e)}),i}function Jl(t){il.around(this.app.commander,t)}function th(){return Object.values(this.indexMap).map(t=>t.map(t=>{const{id:e,data:n}=t.model;return{key:e,value:n}})).flat().sort((t,e)=>t.key>e.key?1:-1)}const eh="left",nh="right",ih="center",rh="bottom",sh="middle",oh=[eh,nh,ih,"top",sh,rh];function ah(t){if(!this.hasSameParentForAllSelected||-1===oh.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(0===e.length)return;const n=this.app.commander;il.around(n,function(){!function(t,e){const n=e[0].parent,{width:i,height:r}=n.bounds;switch(t){case eh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:0}}break;case ih:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i/2-n.width/2}}break;case nh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i-n.width}}break;case"top":for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:0}}break;case sh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:r/2-n.height/2}}break;case rh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:r-n.height}}break;default:;}}(t,e)})}function ch(t){t instanceof Array||(t=[t]),this.trigger("addstart",t)}function lh(){this.trigger("stylepastestart")}function hh(){this.trigger("stylepastestop")}function dh(){this.trigger("databindpastestart")}function uh(){this.trigger("databindpastestop")}let ph=0,fh=0,gh=0,mh=null;function yh(){gh++;const t=performance.now(),e=t-fh;e>=1e3&&(ph=Math.round(1e3*gh/e),fh=t,gh=0),mh=requestAnimationFrame(yh)}function bh(){null!==mh&&(cancelAnimationFrame(mh),mh=null)}function vh(){return null===mh&&(fh=performance.now(),gh=0,mh=requestAnimationFrame(yh)),ph}const _h=function(){const t=document.createElement("canvas").getContext("2d");return(window.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)}();function xh(t,e){const n=document.createElement("canvas");return n.width=t,n.height=e,n.style.width=t+"px",n.style.height=e+"px",n}const wh=Math.sqrt(3);function Mh(t,e){const n=1.2*e;switch(t){case"size1":return{X:n,Y:n};case"size2":return{X:1.5*n,Y:n};case"size3":return{X:2*n,Y:n};case"size4":return{X:n,Y:1.5*n};case"size5":default:return{X:1.5*n,Y:1.5*n};case"size6":return{X:2*n,Y:1.5*n};case"size7":return{X:n,Y:2*n};case"size8":return{X:1.5*n,Y:2*n};case"size9":return{X:2*n,Y:2*n}}}function Sh(t,n,i){switch(t){case"none":default:return null;case"arrow":{const t=wh*n.X,i=n.Y,r=new e.ConeGeometry(i,t,16);return r.rotateZ(-Math.PI/2),r.translate(-t/2,0,0),{mesh:new e.Mesh(r,new e.MeshBasicMaterial)}}case"sharp-arrow":{const t=wh*n.X*1.3,i=.65*n.Y,r=new e.ConeGeometry(i,t,16);return r.rotateZ(-Math.PI/2),r.translate(-t/2,0,0),{mesh:new e.Mesh(r,new e.MeshBasicMaterial)}}case"open-arrow":{const t=wh*n.X,i=n.Y,r=new e.ConeGeometry(i,t,6);return r.rotateZ(-Math.PI/2),r.translate(-t/2,0,0),{mesh:new e.Mesh(r,new e.MeshBasicMaterial({wireframe:!0}))}}case"diamond":{const t=new e.OctahedronGeometry(1);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"oval":{const t=new e.SphereGeometry(1,16,12);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"cross":{const t=Math.max(n.X,n.Y),i=.9*t,r=.25*t,s=.15*t,o=new e.Group,a=[new e.Vector3(1,1,1).normalize(),new e.Vector3(1,-1,-1).normalize(),new e.Vector3(-1,1,-1).normalize(),new e.Vector3(-1,-1,1).normalize()];for(const t of a){const n=new e.CylinderGeometry(r,s,i,6),a=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,1,0),t);n.applyQuaternion(a),n.translate(t.x*i/2,t.y*i/2,t.z*i/2),o.add(new e.Mesh(n,new e.MeshBasicMaterial))}return{group:o}}}}function kh(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Ah(t,n,i,r){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,begin:c="none",beginSize:l="size2",end:h="arrow",endSize:d="size2",label:u}=i,m=(new e.Vector3).subVectors(n,t),y=m.length(),b=new e.Group;if(y<.01)return b;const v=m.clone().normalize(),_=kh(c,a),x=kh(h,a),w=t.clone().add(v.clone().multiplyScalar(_)),M=n.clone().sub(v.clone().multiplyScalar(x));let S;if(Array.isArray(s)&&s.length>=2){const t=s[1];S=new e.Color(t.length>7?t.slice(0,7):t)}else S=new e.Color("string"==typeof s?s:"#00B050");const k=function(t,n,i,r){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,lineDash:c="solid"}=i,l=new g;let h;l.setPositions([t.x,t.y,t.z,n.x,n.y,n.z]);let d=!1;if(Array.isArray(s)&&s.length>=2){const t=new e.Color(s[0].length>7?s[0].slice(0,7):s[0]),n=new e.Color(s[1].length>7?s[1].slice(0,7):s[1]);l.setColors([t.r,t.g,t.b,n.r,n.g,n.b]),d=!0,h=n}else h=new e.Color("string"==typeof s?s:"#00B050");const{dashed:u,dashSize:m,gapSize:y}=function(t,e){switch(t){case"solid":default:return{dashed:!1,dashSize:1,gapSize:0};case"round-dot":return{dashed:!0,dashSize:e,gapSize:2*e};case"square-dot":return{dashed:!0,dashSize:2*e,gapSize:e};case"dash":return{dashed:!0,dashSize:4*e,gapSize:1.5*e};case"dash-dot":return{dashed:!0,dashSize:2.5*e,gapSize:1.5*e};case"long-dash":return{dashed:!0,dashSize:6*e,gapSize:3*e};case"long-dash-dot":return{dashed:!0,dashSize:3.5*e,gapSize:2*e};case"long-dash-dot-dot":return{dashed:!0,dashSize:3*e,gapSize:1.5*e}}}(c,a),b=new f({color:d?16777215:h.getHex(),linewidth:a,worldUnits:!0,vertexColors:d,dashed:u,dashSize:m,gapSize:y,transparent:o<1||Array.isArray(s)&&s.some(t=>t.length>7),opacity:o,resolution:r}),v=new p(l,b);return v.computeLineDistances(),v}(w,M,i,r);b.add(k);const A=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),v),E=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),v.clone().negate()),C=(t,e,n)=>{if(!t)return;const i=t.mesh||t.line2||t.group;if(i){if(i.position.copy(e),i.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(S),e.transparent=o<1,e.opacity=o}else if(t.line2){const e=t.line2.material;e.color.copy(S),e.transparent=o<1,e.opacity=o,e.resolution.copy(r)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color.copy(S),e.transparent=o<1,e.opacity=o,e.resolution&&e.resolution.copy(r)}});b.add(i)}};C(Sh(h,Mh(d,a)),n,A);if(C(Sh(c,Mh(l,a)),t,E),u){const i=(new e.Vector3).addVectors(t,n).multiplyScalar(.5);i.y+=3;const r=function(t,n,i){const r="Arial",s=xh(256,64),o=s.getContext("2d");o.font=`bold 28px ${r}`;const a=o.measureText(t).width;o.fillStyle=n,o.fillRect(0,0,a+12,40),o.fillStyle="white",o.font=`bold 28px ${r}`,o.textBaseline="top",o.fillText(t,6,6);const c=new e.CanvasTexture(s);c.needsUpdate=!0,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace;const l=new e.SpriteMaterial({map:c,transparent:!0}),h=new e.Sprite(l);h.position.copy(i);const d=(a+12)/40;return h.scale.set(4*d,4,1),h}(u,"string"==typeof s?s:Array.isArray(s)&&s[1]||"#00B050",i);b.add(r)}return b}const Eh=.001;function Ch(t,e,n){let i=1;if(n&&"none"!=n&&"transparent"!=n){i=e*("string"==typeof n?b(n).getAlpha():1)}else i=0;t.opacity=i,t.transparent=i<1}function Th(t){const e=b(t);return e.isValid()?e.toHexString():t}const Ph={width:1,height:1,depth:1},Dh={x:1,y:1,z:1},Oh={x:0,y:0,z:0},zh={x:0,y:0,z:0},Ih={default:{metalness:0,roughness:.4},metal:{metalness:1,roughness:.3,envMapIntensity:1},glass:{metalness:0,roughness:.1,opacity:.3,envMapIntensity:1.5},plastic:{metalness:0,roughness:.4},wood:{metalness:0,roughness:.8,envMapIntensity:.3},ceramic:{metalness:.1,roughness:.2,envMapIntensity:.3},rubber:{metalness:0,roughness:.9,envMapIntensity:.3}};function Lh(t){if(!t)return{metalness:0,roughness:.4,emissive:"#000000",emissiveIntensity:0,opacity:1,envMapIntensity:.5,side:"double",castShadow:!0,receiveShadow:!1};const e=Ih[t.preset??"default"]??Ih.default;return{metalness:t.metalness??e.metalness,roughness:t.roughness??e.roughness,emissive:t.emissive??"#000000",emissiveIntensity:t.emissiveIntensity??0,opacity:t.opacity??e.opacity??1,envMapIntensity:t.envMapIntensity??e.envMapIntensity??.5,side:t.side??"double",castShadow:t.castShadow??!0,receiveShadow:t.receiveShadow??!1}}const jh={double:e.DoubleSide,front:e.FrontSide,back:e.BackSide};function Rh(t){return jh[t]??e.DoubleSide}function Fh(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.emissive.set(e.emissive),t.emissiveIntensity=e.emissiveIntensity,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity,t.side=Rh(e.side)}const Bh=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap"];function Nh(t){for(const e of Bh){const n=t[e];n?.dispose()}t.dispose()}function Hh(t){t.traverse(t=>{if(t.geometry?.dispose(),t.material){const e=Array.isArray(t.material)?t.material:[t.material];for(const t of e)Nh(t)}})}function Yh(t,e,n){const i=document.createElement("canvas");i.width=e,i.height=n;const r=i.getContext("2d");if(!r)return null;let s;if("radial"===t.gradientType){const i=e/2,o=n/2,a=Math.max(e,n)/2;switch(t.center){case"left-top":s=r.createRadialGradient(0,0,0,0,0,2*a);break;case"right-top":s=r.createRadialGradient(e,0,0,e,0,2*a);break;case"left-bottom":s=r.createRadialGradient(0,n,0,0,n,2*a);break;case"right-bottom":s=r.createRadialGradient(e,n,0,e,n,2*a);break;default:s=r.createRadialGradient(i,o,0,i,o,a)}}else{const i=t.rotation??0,o=e/2,a=n/2,c=Math.cos(i)*o,l=Math.sin(i)*a;s=r.createLinearGradient(o-c,a-l,o+c,a+l)}for(const e of t.colorStops)if(e.position>=0&&e.position<=1)try{s.addColorStop(e.position,e.color)}catch{s.addColorStop(e.position,"#fff")}return r.fillStyle=s,r.fillRect(0,0,e,n),i}function Vh(t){const{fillStyle:n}=t.state;if(n&&"object"==typeof n)return"pattern"===n.type&&n.image?function(t,n){const{width:i,height:r}=t.state,s=Math.abs(i)||1,o=Math.abs(r)||1,a=new e.Texture;a.colorSpace=e.SRGBColorSpace;const c=new Image;"data"!==String(n.image).substring(0,4)&&(c.crossOrigin="anonymous"),c.onload=()=>{const i=2*s,r=2*o,l=document.createElement("canvas");l.width=i,l.height=r;const h=l.getContext("2d");if(h){if(n.color&&(h.fillStyle=n.color,h.fillRect(0,0,i,r)),n.fitPattern)h.drawImage(c,0,0,i,r);else{const t=2*(n.width||c.naturalWidth),e=2*(n.height||c.naturalHeight),s=2*(n.offsetX||0),o=2*(n.offsetY||0);let a=0,l=0;switch(n.align){case"center":a=(i-t)/2,l=(r-e)/2;break;case"left-top":break;case"left-bottom":l=r-e;break;case"right-top":a=i-t;break;case"right-bottom":a=i-t,l=r-e;break;case"left":l=(r-e)/2;break;case"right":a=i-t,l=(r-e)/2;break;case"top":a=(i-t)/2;break;case"bottom":a=(i-t)/2,l=r-e}const d=s+a,u=o+l;if(n.noRepeat)h.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,d,u,t,e);else{h.save(),h.rect(0,0,i,r),h.clip();const n=d>0?d-Math.ceil(d/t)*t:d;for(let s=u>0?u-Math.ceil(u/e)*e:u;s<r;s+=e)for(let r=n;r<i;r+=t)h.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,r,s,t,e);h.restore()}}a.image=l,a.minFilter=e.LinearFilter,a.needsUpdate=!0,t.invalidate()}},c.onerror=t=>{Ki("Pattern texture load error:",t)};const l=n.image;c.src=t.app.url(l);const h=t.root?.app?.loadTracker;if(h){const t=new Promise((t,e)=>{c.addEventListener("load",()=>t(),{once:!0}),c.addEventListener("error",()=>e(),{once:!0})});h.track(`pattern:${l}`,"pattern",l,t)}return a}(t,n):"gradient"===n.type&&n.colorStops?.length?function(t){const n=Yh(t,256,256);if(!n)return;const i=new e.CanvasTexture(n);return i.colorSpace=e.SRGBColorSpace,i.needsUpdate=!0,i}(n):void 0}function Gh(t,e){return-1!==t.findIndex(t=>t in e)}class Uh{static buildFillStyleTexture(t){return Vh(t)}constructor(t){this._focused=!1,this._suppressOnchange=!1,this._onchangeWrapper=(t,e,n)=>{this._suppressOnchange||n&&n.origin&&n.origin!==this._component||this.onchange(t,e)},this.suppressTransform=!1,this._component=t,this.object3d=this.getObject3dInstance(),this.component.on("change",this._onchangeWrapper)}update(){this.clear(),this.build(),this.updateTransform(),this.updateFillStyle(),this.updateStrokeStyle(),this.updateAlpha(),this.updateHidden(),this.updateText()}getObject3dInstance(){return new e.Object3D}build(){this.object3d.userData.context=this;const t=Lh(this.component.state.material3d);this._applyShadow(t.castShadow,t.receiveShadow),this.object3d.name=this.component.state.id}updateMaterial3d(){const t=Lh(this.component.state.material3d);this._applyShadow(t.castShadow,t.receiveShadow)}_applyShadow(t,e){this.object3d.castShadow=t,this.object3d.receiveShadow=e,this.object3d.traverse(n=>{n!==this.object3d&&(n.castShadow=t,n.receiveShadow=e)})}get gizmoTransformable(){return!0}get allowedGizmoModes(){return null}get component(){return this._component}get threeContainer(){let t=this.component;for(;t;){if("is3dContainer"in t&&t.is3dContainer())return t;t=t.parent}}get focused(){return this._focused}set focused(t){this._focused=t,t&&(this._focusedAt=performance.now())}dispose(){this.component.off("change",this._onchangeWrapper),this.clear()}clear(){const t=[];for(const e of this.object3d.children){const n=e.userData?.context;n&&n!==this&&n instanceof Uh?t.push(e):Hh(e)}this._components3D=void 0,this.object3d.userData={},this.object3d.clear();for(const e of t)this.object3d.add(e);return this.object3d}updateTransform(){if(this.suppressTransform)return;if(this.component.state.screenFixed&&this.component.isHTMLElement()){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{};return this.object3d.position.set(t-n/2,-(e-i/2),0),void this.object3d.rotation.set(0,0,0)}const{x:t,y:e,z:n}=this.position,{x:i,y:r,z:s}=this.rotation,{x:o,y:a,z:c}=this.scale;this.object3d.position.set(t,e,n),this.object3d.rotation.set(i,r,s),this.object3d.scale.set(Math.max(o,Eh),Math.max(a,Eh),Math.max(c,Eh))}get position(){const{x:t,y:e,z:n}=this.center;return{x:t,y:n,z:e}}get rotation(){const{rotationX:t=0,rotationY:e=0,rotation:n=0}=this.component.state;return{x:t,y:-n,z:e}}get scale(){const{scale:t}=this.component.state,e="number"==typeof t?t:t?.x??1;return{x:e,y:e,z:e}}get cx(){const{x:t=0}=this.component.center,{width:e=0}=this.component.parent?.bounds??{},{tx:n=0}=this.component.delta();return t+n-e/2}get cy(){const{y:t=0}=this.component.center,{height:e=0}=this.component.parent?.bounds??{},{ty:n=0}=this.component.delta();return t+n-e/2}get cz(){const{zPos:t=0}=this.component.state,{tz:e=0}=this.component.delta(),n=this.component.parent?._realObject,i=n?.geometricOffsetY??0;return t+e+this.syncZPosOffset-i}get geometricOffsetY(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get scenePlacement(){const t=this.component.rootModel??this.component,e=t?.state?.placement;return"space"===e||"inverted"===e?e:"floor"}get components3D(){return this._components3D&&this._components3D.parent===this.object3d||(this._components3D=new e.Group,this.object3d.add(this._components3D)),this._components3D.position.y=-this.geometricOffsetY,this._components3D}get center(){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{},{tx:r=0,ty:s=0}=this.component.delta();return{x:t+r-n/2,y:e+s-i/2,z:this.cz}}freezeDimension(){this._frozenDimension={...this.dimension}}unfreezeDimension(){delete this._frozenDimension}get dimension(){if(this._frozenDimension)return this._frozenDimension;const{width:t,height:e}=this.component.bounds;return{width:Math.abs(t)||1,height:Math.abs(e)||1,depth:this.effectiveDepth}}get effectiveDepth(){return this.component.state.depth||1}updatePosition(){const{x:t=0,y:e=0,z:n=0}=this.position;this.object3d.position.set(t,e,n)}updateRotate(){const{x:t=0,y:e=0,z:n=0}=this.rotation;this.object3d.rotation.set(t,e,n)}updateScale(){const{x:t=1,y:e=1,z:n=1}=this.scale;this.object3d.scale.set(Math.max(t,Eh),Math.max(e,Eh),Math.max(n,Eh))}syncAnimationDelta(){if(this.suppressTransform)return;const t=this.component.delta();this.updatePosition();const{rotationX:e=0,rotationY:n=0,rotation:i=0}=this.component.state,r=t.theta||0,s=t.rx||0,o=t.ry||0,a=t.rz||0;this.object3d.rotation.set(e+s,-(i+r)+o,n+a);const{scale:c}=this.component.state,l="number"==typeof c?c:c?.x??1,h=t.sx??1,d=t.sy??1,u=t.sz??1;this.object3d.scale.set(Math.max(l*h,Eh),Math.max(l*d,Eh),Math.max(l*u,Eh));const p=t.fade||0;if(0!==p){const t=(this.component.state.alpha??1)*(1-p);this.object3d.traverse(e=>{if(e.isMesh&&e.material){const n=Array.isArray(e.material)?e.material:[e.material];for(const e of n)e.opacity=t,e.transparent=e.opacity<1}})}}updateDimension(){this.clear(),this.build()}updateAlpha(){let{alpha:t}=this.component.state;t=null==t?1:t,this.object3d.traverse(e=>{let n=e.material;e.material&&(Array.isArray(n)||(n=[n]),n.forEach(e=>{e.opacity*=t,e.transparent=t<1}))})}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateStrokeStyle(){}updateFillStyle(){}updateText(){}get syncZPosOffset(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get textSurfaceYOffset(){return this.effectiveDepth-this.syncZPosOffset}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},r=e.bounds,{tx:s=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0,e.bounds={left:t.position.x-s+n/2-r.width/2,top:t.position.z-o+i/2-r.height/2,width:r.width,height:r.height};const c=this.component.parent?._realObject,l=c?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+l,rotationX:t.rotation.x,rotation:-t.rotation.y,rotationY:t.rotation.z}),this._suppressOnchange=!1}onGizmoDragEnd(t){}applyDimensionFromGizmo(t){this._suppressOnchange=!0,this._component.set(t),this._suppressOnchange=!1}onchange(t,e){if("screenFixed"in t&&this.updateTransform(),Gh(["cx","cy","cz","zPos","left","top"],t)&&this.updatePosition(),Gh(["width","height","depth","lineWidth","round"],t)&&(this.updateDimension(),"depth"in t)){this.updatePosition();const t=this.component.components;if(t)for(const e of t){const t=e?._realObject;t?.updateTransform&&t.updateTransform()}}if(Gh(["rotationX","rotationY","rotation"],t)&&this.updateRotate(),"scale"in t&&this.updateScale(),"hidden"in t&&this.updateHidden(),"alpha"in t&&this.updateAlpha(),"strokeStyle"in t&&this.updateStrokeStyle(),"fillStyle"in t&&this.updateFillStyle(),Gh(["text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline"],t))this._lastText=this.component.hasTextProperty?this.component.text:"",this.updateText();else if(Gh(["value","data"],t)){const t=this.component.hasTextProperty?this.component.text:"";t!==this._lastText&&(this._lastText=t,this.updateText())}"material3d"in t&&this.updateMaterial3d()}}class Wh extends Uh{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}getObject3dInstance(){return new m(this.component.element)}get rotation(){const{rotationX:t=0,rotationY:e=0,rotation:n=0}=this.component.state;return{x:t-Math.PI/2,y:e,z:-n}}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},r=e.bounds,{tx:s=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0;const c=t.scale.x;e.bounds={left:t.position.x-s+n/2-r.width/2,top:t.position.z-o+i/2-r.height/2,width:r.width,height:r.height};const l=this.component.parent?._realObject,h=l?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+h,rotationX:t.rotation.x+Math.PI/2,rotation:-t.rotation.z,rotationY:t.rotation.y,scale:{x:c,y:c}}),this._suppressOnchange=!1}build(){super.build();const t=this.component.element;if(!t)return;const{width:e,height:n}=this.component.bounds;t.style.width=e+"px",t.style.height=n+"px",t.style.left="",t.style.top=""}updateDimension(){super.updateDimension();const t=this.dimension,e=this.component.element;e&&(e.style.width=t.width+"px",e.style.height=t.height+"px")}updateAlpha(){super.updateAlpha();const{alpha:t=1}=this.component.state,e=this.component.element;e&&(e.style.opacity=String(t))}}const Xh=new Map;let qh;function Kh(t,e){Xh.set(t,e)}function $h(t){qh=t}function Qh(t){const e=t.buildRealObject();if(e)return e;const n=t.model?.type,i=n?Xh.get(n):void 0;if(i)return i(t);if(t.isHTMLElement()){const e=Xh.get("html-overlay-element");if(e)return e(t)}return qh?.(t)}function Zh(t,n,i){if(!t.hasTextProperty||t.textHidden)return;const r=t._realObject;if(!r?.object3d)return;const{text:s="",bold:o=Gr.BOLD,italic:a=Gr.ITALIC,fontFamily:c=Gr.FONT_FAMILY,fontColor:l=Gr.FONT_COLOR,fontSize:h=Gr.FONT_SIZE,textAlign:d=Gr.TEXT_ALIGN,textBaseline:u=Gr.TEXT_BASELINE,width:p,height:f}=t.model,g=Math.abs(p)||1,y=Math.abs(f)||1,b=document.createElement("textarea"),v=new AbortController;Yr.forEach(t=>{b.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:v.signal})}),b.value=s;const _="right"===d||"end"===d?"right":"left"===d||"start"===d?"left":"justify"===d?"justify":"center";let x="0";if("bottom"===u||"alphabetic"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);x=Math.max(0,y-t)+"px"}else if("middle"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);x=Math.max(0,(y-t)/2)+"px"}b.style.cssText=[`width: ${g}px`,`height: ${y}px`,`padding: ${x} 0 0 0`,"margin: 0",`font-family: ${c}`,`font-size: ${h}px`,`line-height: ${1.2*h}px`,"overflow: hidden","resize: none","outline: 1px solid #f26522","border: 0","background-color: rgba(255, 255, 255, 0.85)","display: block",`color: ${l}`,"box-sizing: border-box","font-weight: "+(o?"bold":"normal"),"font-style: "+(a?"italic":"normal"),`text-align: ${_}`].join("; ");const w=new m(b),M=r.object3d;M.updateWorldMatrix(!0,!1);const S=new e.Vector3,k=new e.Quaternion,A=new e.Vector3;M.matrixWorld.decompose(S,k,A);const E=new e.Vector3(0,r.textSurfaceYOffset,0);E.multiply(A),E.applyQuaternion(k),w.position.copy(S).add(E);const C=(new e.Quaternion).setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2);w.quaternion.copy(k).multiply(C),w.scale.copy(A),n.css3DScene.add(w),i();const T=n.css3DRenderer.domElement,P=T.style.getPropertyValue("pointer-events"),D=T.style.getPropertyPriority("pointer-events"),O=[];let z=b;for(;z&&z!==T.parentElement;)O.push({el:z,saved:z.style.pointerEvents}),z.style.setProperty("pointer-events","auto","important"),z=z.parentElement;b.focus(),b.select();let I=!1;const L=t.root?.selected;b.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"!==t.code&&(t.shiftKey||"Enter"!==t.code&&"NumpadEnter"!==t.code)||(I="Escape"===t.code,b.blur())},{signal:v.signal});const j=()=>{n.css3DScene.remove(w);for(const{el:t,saved:e}of O)e?t.style.pointerEvents=e:t.style.removeProperty("pointer-events");D?T.style.setProperty("pointer-events",P,D):P&&T.style.setProperty("pointer-events",P),v.abort(),b.removeEventListener("blur",j),L&&t.root&&(t.root.selected=L),I||b.value===s||t.app.commander.execute(new il({changes:[{component:t,before:{text:s},after:{text:b.value}}]})),i()};b.addEventListener("blur",j)}class Jh extends n{dispose(){const t=new Set;this.traverse(e=>{if(e.isMesh){t.add(e.geometry);const n=e.material;Array.isArray(n)?n.forEach(e=>t.add(e)):t.add(n)}});for(const e of t)e.dispose()}}function td(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity,t.polygonOffset=!0,t.polygonOffsetFactor=1,t.polygonOffsetUnits=1}function ed(t){const{fillStyle:n,floorMaterial3d:i,placement:r}=t.state,s=Lh({...i,preset:i?.preset??"rubber",envMapIntensity:i?.envMapIntensity??0});if("none"===n)return;if("space"===r)return;const o=new e.BoxGeometry(1,1,1);let a;if(n){const i=Uh.buildFillStyleTexture(t);if(i){const t="#424b57",n=[new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({map:i}),new e.MeshStandardMaterial({color:t})];n.forEach(t=>td(t,s)),a=n}else if("string"==typeof n){const t=new e.MeshStandardMaterial({color:n});td(t,s),a=t}}if(!a){const t=new e.MeshStandardMaterial({color:"#e0e0e0"});td(t,s),a=t}const c=new e.Mesh(o,a),{width:l,height:h}=t.state;return c.scale.set(l,h,5),c.rotation.x=-Math.PI/2,c.position.y="inverted"===r?3.5:-3.5,c.name="floor",c.receiveShadow=!1!==i?.receiveShadow,c.castShadow=!0===i?.castShadow,c}const nd={studio:class extends Jh{constructor(){super(),this.name="StudioEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:13421772}),n=new o(t,e);n.position.set(0,13,0),n.scale.set(40,30,35),this.add(n);const l=new r({color:11184810,roughness:.8}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(40,.5,35),this.add(h);const d=new a(16777215,500,40,2);d.position.set(0,24,0),this.add(d);const u=new a(16777215,200,30,2);u.position.set(-10,22,-8),this.add(u);const p=new a(16777215,200,30,2);p.position.set(10,22,8),this.add(p);const f=(e,n,i)=>{const r=new c({color:0,emissive:16777215,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,26,n),s.scale.set(6,.1,6),s};this.add(f(-8,-6,60)),this.add(f(8,-6,60)),this.add(f(-8,6,60)),this.add(f(8,6,60)),this.add(f(0,0,50))}},warehouse:class extends Jh{constructor(){super(),this.name="WarehouseEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:8425632}),n=new o(t,e);n.position.set(0,18,0),n.scale.set(50,40,40),this.add(n);const l=new r({color:9474192,roughness:.9}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(50,.5,40),this.add(h);const d=new a(15266047,600,50,2);d.position.set(-10,30,0),this.add(d);const u=new a(15266047,600,50,2);u.position.set(10,30,0),this.add(u);const p=(e,n,i)=>{const r=new c({color:0,emissive:15266047,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,35,n),s.scale.set(8,.1,2),s};this.add(p(-12,-6,80)),this.add(p(-12,6,80)),this.add(p(0,0,60)),this.add(p(12,-6,80)),this.add(p(12,6,80));const f=new o(t,new c({color:0,emissive:16772829,emissiveIntensity:15}));f.position.set(0,10,-19),f.scale.set(12,8,.1),this.add(f)}},factory:class extends Jh{constructor(){super(),this.name="FactoryEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:6318192,metalness:.1,roughness:.8}),n=new o(t,e);n.position.set(0,20,0),n.scale.set(60,44,45),this.add(n);const l=new r({color:8028272,roughness:.7,metalness:.05}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(60,.5,45),this.add(h);const d=(t,e)=>{const n=new a(15791615,800,55,2);return n.position.set(t,35,e),n};this.add(d(-15,-10)),this.add(d(-15,10)),this.add(d(0,0)),this.add(d(15,-10)),this.add(d(15,10));const u=(e,n,i)=>{const r=new c({color:0,emissive:15791615,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,38,n),s.scale.set(6,.1,3),s};this.add(u(-18,-10,90)),this.add(u(-18,10,90)),this.add(u(0,-10,70)),this.add(u(0,10,70)),this.add(u(18,-10,90)),this.add(u(18,10,90));const p=new o(t,new c({color:0,emissive:11206570,emissiveIntensity:10}));p.position.set(28,14,-21),p.scale.set(1,2,.1),this.add(p);const f=new o(t,new c({color:0,emissive:16772829,emissiveIntensity:25}));f.position.set(0,8,-22),f.scale.set(10,10,.1),this.add(f)}},office:class extends Jh{constructor(){super(),this.name="OfficeEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:14209224}),n=new o(t,e);n.position.set(0,10,0),n.scale.set(35,22,30),this.add(n);const l=new r({color:10524808,roughness:.85}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(35,.5,30),this.add(h);const d=new a(16774374,400,30,2);d.position.set(0,17,0),this.add(d);const u=(e,n,i)=>{const r=new c({color:0,emissive:16775408,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,19.5,n),s.scale.set(4,.1,4),s};this.add(u(-8,-6,60)),this.add(u(-8,6,60)),this.add(u(8,-6,60)),this.add(u(8,6,60)),this.add(u(0,0,50));const p=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:30}));p.position.set(17,10,0),p.scale.set(.1,6,12),this.add(p);const f=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:20}));f.position.set(-17,10,0),f.scale.set(.1,4,8),this.add(f)}},home:class extends Jh{constructor(){super(),this.name="HomeEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:15261136}),n=new o(t,e);n.position.set(0,8,0),n.scale.set(28,18,24),this.add(n);const l=new r({color:11571312,roughness:.7}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(28,.5,24),this.add(h);const d=new a(16770244,300,25,2);d.position.set(0,14,0),this.add(d);const u=new a(16767152,100,20,2);u.position.set(-8,12,-6),this.add(u);const p=(e,n,i)=>{const r=new c({color:0,emissive:16771280,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,15.5,n),s.scale.set(3,.1,3),s};this.add(p(0,0,40)),this.add(p(-6,-4,25)),this.add(p(6,4,25));const f=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:35}));f.position.set(13.5,8,0),f.scale.set(.1,8,10),this.add(f);const g=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:15}));g.position.set(-13.5,9,3),g.scale.set(.1,5,6),this.add(g)}},sunny:class extends Jh{constructor(){super(),this.name="SunnyEnvironment";const t=new v;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=2,e.rayleigh.value=1.5,e.mieCoefficient.value=.005,e.mieDirectionalG.value=.8;const n=l.degToRad(60),i=l.degToRad(135),r=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,r,i),this.add(t)}},cloudy:class extends Jh{constructor(){super(),this.name="CloudyEnvironment";const t=new v;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=10,e.rayleigh.value=.3,e.mieCoefficient.value=.03,e.mieDirectionalG.value=.7;const n=l.degToRad(50),i=l.degToRad(120),r=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,r,i),this.add(t)}},rainy:class extends Jh{constructor(){super(),this.name="RainyEnvironment";const t=new v;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=20,e.rayleigh.value=.1,e.mieCoefficient.value=.05,e.mieDirectionalG.value=.6;const n=l.degToRad(40),i=l.degToRad(110),r=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,r,i),this.add(t)}}};class id{get scene(){return this._scene}get mixer(){return this._mixer}setup(){return this._scene=new e.Scene,this._scene}setupMixer(){return this._timer=new e.Timer,this._timer.connect(document),this._mixer=new e.AnimationMixer(this._scene),this._mixer}setupEnvironment(t){this._renderer=t}_applyEnvironment(t){if(this._envTexture&&(this._envTexture.dispose(),this._envTexture=void 0),!this._renderer||!this._scene)return;const n=new(0,nd[t]),i=new e.PMREMGenerator(this._renderer);this._envTexture=i.fromScene(n).texture,this._scene.environment=this._envTexture,n.dispose(),i.dispose()}_clearEnvironment(){this._envTexture&&(this._envTexture.dispose(),this._envTexture=void 0),this._scene&&(this._scene.environment=null)}setSky(t,n){if(!this._scene||!this._renderer)return;const i=t;i&&i in nd?(this._applyEnvironment(i),this._scene.background=this._envTexture):"color"===t&&n?(this._clearEnvironment(),this._scene.background=new e.Color(n)):(this._clearEnvironment(),this._scene.background=null)}addFloor(t){const e=ed(t);e&&this._scene.add(e)}updateFloor(t){if(!this._scene)return;const e=this._scene.children.find(t=>"floor"===t.name);e&&(Hh(e),this._scene.remove(e)),this.addFloor(t)}addObject(t){this._scene.add(t)}updateAnimation(){this._mixer&&this._timer&&(this._timer.update(),this._mixer.update(this._timer.getDelta()))}destroy(){this._mixer&&(this._mixer.stopAllAction(),this._mixer.uncacheRoot(this._scene)),this._envTexture&&(this._envTexture.dispose(),delete this._envTexture),this._scene&&(this._scene.environment=null,Hh(this._scene),this._scene.clear()),delete this._scene,delete this._mixer,delete this._renderer,this._timer&&this._timer.disconnect(),delete this._timer}}class rd{constructor(){this._activeView="perspective",this._cameraZPos=0}get camera(){return this._perspCamera}get activeCamera(){return"perspective"!==this._activeView&&this._orthoCamera?this._orthoCamera:this._perspCamera}get activeView(){return this._activeView}get cameraZPos(){return this._cameraZPos}setup(t,n,i){const{fov:r,near:s,far:o,cameraX:a,cameraY:c,cameraZ:l}=i,h=t/n;this._perspCamera=new e.PerspectiveCamera(r,h,s,o);const d=Math.sqrt(t*t+n*n),u=(r||45)/2*Math.PI/180,p=d/2/Math.tan(u)*.75,f=25*Math.PI/180,g=30*Math.PI/180,m=p*Math.sin(f),y=p*Math.cos(f);let b=y*Math.sin(g),v=y*Math.cos(g);return this._cameraZPos=Math.floor(m),null!=a&&(b=a*t),null!=c&&(v=c*n),null!=l&&(this._cameraZPos=l*Math.floor(Math.min(t,n))),this._perspCamera.position.set(b,this._cameraZPos,v),this._activeView="perspective",this._perspCamera}addToScene(t){t.add(this._perspCamera),this._perspCamera.lookAt(t.position)}updateAspect(t,e){if(this._perspCamera&&(this._perspCamera.aspect=t/e,this._perspCamera.updateProjectionMatrix()),this._orthoCamera){const n=this._orthoCamera,i=(n.top-n.bottom)/2,r=t/e;n.left=-i*r,n.right=i*r,n.updateProjectionMatrix()}}updateProperties(t){this._perspCamera&&(void 0!==t.fov&&(this._perspCamera.fov=t.fov),void 0!==t.near&&(this._perspCamera.near=t.near),void 0!==t.far&&(this._perspCamera.far=t.far),this._perspCamera.updateProjectionMatrix())}setOrthoView(t,n,i,r,s){this._orthoCamera||(this._orthoCamera=new e.OrthographicCamera(-1,1,1,-1,.1,5e4)),this.updateOrthoFrustum(n,i,r,s);const o=this._orthoCamera;o.zoom=1;const a=2*Math.max(n,i);switch(t){case"top":o.position.set(0,a,0),o.up.set(0,0,-1);break;case"front":o.position.set(0,0,a),o.up.set(0,1,0);break;case"back":o.position.set(0,0,-a),o.up.set(0,1,0);break;case"right":o.position.set(a,0,0),o.up.set(0,1,0);break;case"left":o.position.set(-a,0,0),o.up.set(0,1,0)}return o.lookAt(0,0,0),o.updateProjectionMatrix(),this._activeView=t,o}restorePerspective(){return this._activeView="perspective",this._perspCamera}updateOrthoFrustum(t,e,n,i){if(!this._orthoCamera)return;const r=(n||t)/(i||e),s=Math.max(t,e)/2;r>=1?(this._orthoCamera.left=-s*r,this._orthoCamera.right=s*r,this._orthoCamera.top=s,this._orthoCamera.bottom=-s):(this._orthoCamera.left=-s,this._orthoCamera.right=s,this._orthoCamera.top=s/r,this._orthoCamera.bottom=-s/r),this._orthoCamera.updateProjectionMatrix()}destroy(){delete this._perspCamera,delete this._orthoCamera,this._activeView="perspective"}}class sd{constructor(){this._noSupportWebgl=!1}get renderer(){return this._renderer}setExposure(t){this._renderer&&(this._renderer.toneMappingExposure=t)}get css3DRenderer(){return this._css3DRenderer||(this._css3DRenderer=this.createCSS3DRenderer()),this._css3DRenderer}get css3DScene(){return this._css3DScene||(this._css3DScene=new e.Scene),this._css3DScene}get composer(){return this._composer}get noSupportWebgl(){return this._noSupportWebgl}get domElement(){return this._renderer?.domElement}get hudScene(){return this._hudScene||(this._hudScene=new e.Scene),this._hudScene}get hudCSS3DScene(){return this._hudCSS3DScene||(this._hudCSS3DScene=new e.Scene),this._hudCSS3DScene}get hudCamera(){return this._hudCamera}setupHUD(t,n){this._hudCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCamera.position.set(0,5e3,0),this._hudCamera.lookAt(0,0,0),this._hudCSS3DCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCSS3DCamera.position.set(0,0,1e3),this._hudCSS3DCamera.lookAt(0,0,0),this._hudCSS3DRenderer=new y,this._hudCSS3DRenderer.setSize(t,n);const i=this._hudCSS3DRenderer.domElement;i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.pointerEvents="none",i.setAttribute("scene","model-layer:css3d-hud-renderer");const r=new e.AmbientLight(16777215,3);this.hudScene.add(r);const s=new Float32Array(64).fill(1),o=new e.DataTexture(s,4,4,e.RGBAFormat,e.FloatType);o.mapping=e.EquirectangularReflectionMapping,o.needsUpdate=!0,this.hudScene.environment=o}resizeHUD(t,e){this._hudCamera&&(this._hudCamera.right=t,this._hudCamera.bottom=-e,this._hudCamera.updateProjectionMatrix())}setupWebGL(t,n,i){try{const r=document.createElement("canvas"),s=r.getContext("webgl2");if(!s)return this._noSupportWebgl=!0,!1;const o=new e.WebGLRenderer({canvas:r,context:s,precision:i.precision,alpha:!0,antialias:i.antialias,logarithmicDepthBuffer:i.logarithmicDepthBuffer??!1!==i.postprocessing,premultipliedAlpha:!1});return o.autoClear=!0,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.ACESFilmicToneMapping,o.toneMappingExposure=i.exposure,o.shadowMap.enabled=!1!==i.shadowMap,o.shadowMap.type=e.PCFShadowMap,o.setClearColor(16777215,1),o.setPixelRatio(window.devicePixelRatio),o.setSize(t,n,!1),r.style.width="100%",r.style.height="100%",this._renderer=o,this._noSupportWebgl=!1,!0}catch(t){return this._noSupportWebgl=!0,!1}}setupCSS3D(t,e){const n=this.css3DRenderer.domElement;n.style.position="absolute",n.style.left="0",n.style.top="0",n.style.pointerEvents="none",e&&n.setAttribute("scene",e),n.style.setProperty("pointer-events","none","important")}createCSS3DRenderer(){return new y}setupComposer(t,n,i,r,s){const o=new e.WebGLRenderTarget(i,r,{samples:4});this._composer=new _(this._renderer,o),this._composer.setSize(i,r);const a=new x(t,n);this._composer.addPass(a);const c=new w(new e.Vector2(i,r),t,n);if(c.visibleEdgeColor.set(15885602),c.hiddenEdgeColor.set(15885602),c.edgeStrength=3,c.edgeThickness=1.5,c.edgeGlow=.5,c.pulsePeriod=0,s){const t=c.render.bind(c);c.render=(e,n,i,r,o)=>{const a=s.visible;s.visible=!1,t(e,n,i,r,o),s.visible=a}}return this._outlinePass=c,this._composer.addPass(c),this._composer.addPass(new S),this._composer.addPass(new M),this._composer}setupLightComposer(t,n,i,r){const s=new e.WebGLRenderTarget(i,r);this._composer=new _(this._renderer,s),this._composer.setSize(i,r),this._composer.addPass(new x(t,n));const o=new w(new e.Vector2(i,r),t,n);return o.visibleEdgeColor.set(15885602),o.hiddenEdgeColor.set(15885602),o.edgeStrength=3,o.edgeThickness=1.5,o.edgeGlow=.5,o.pulsePeriod=0,this._outlinePass=o,this._composer.addPass(o),this._composer.addPass(new M),this._composer}get hasOutlinePass(){return!!this._outlinePass}updateRenderPassCamera(t){this._composer&&this._composer.passes.length>0&&(this._composer.passes[0].camera=t),this._outlinePass&&(this._outlinePass.renderCamera=t),this._camera&&(this._camera=t)}setOutlineObjects(t){this._outlinePass&&(this._outlinePass.selectedObjects=t)}resize(t,e){if(this._renderer?.setSize(t,e,!1),this._css3DRenderer?.setSize(t,e),this._composer?.setSize(t,e),this._hudCSS3DRenderer&&this._hudCSS3DCamera){const n=t/(this._hudCSS3DCamera.right-this._hudCSS3DCamera.left),i=e/(this._hudCSS3DCamera.top-this._hudCSS3DCamera.bottom),r=this._hudCSS3DRenderer.domElement;r.style.transformOrigin="0 0",r.style.transform=`scale(${n}, ${i})`}}teardownLightComposer(){this._composer&&(this._outlinePass=void 0,this._composer.dispose(),this._composer=void 0)}setDirectRenderTargets(t,e){this._scene=t,this._camera=e}render(){if(this._composer){if(this._composer.render(),this._renderer){const t=this._renderer.getContext();t.colorMask(!1,!1,!1,!0),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.colorMask(!0,!0,!0,!0)}}else this._renderer&&this._scene&&this._camera&&this._renderer.render(this._scene,this._camera);this.renderHUD()}renderHUD(){if(!this._renderer||!this._hudScene||!this._hudCamera)return;if(0===this._hudScene.children.length)return;const t=this._renderer.autoClear;this._renderer.autoClear=!1,this._renderer.setRenderTarget(null),this._renderer.clearDepth(),this._renderer.render(this._hudScene,this._hudCamera),this._renderer.autoClear=t}renderCSS3D(t){if(this._css3DRenderer?.render(this.css3DScene,t),this._hudCSS3DRenderer&&this._hudCSS3DCamera&&this._hudCSS3DScene){const t=this._hudCSS3DRenderer.domElement;this._hudCSS3DScene.children.length>0?(t.style.display="",this._hudCSS3DRenderer.render(this._hudCSS3DScene,this._hudCSS3DCamera)):t.style.display="none"}}get hudCSS3DRenderer(){return this._hudCSS3DRenderer}getSize(){const t=new e.Vector2;return this._renderer?.getSize(t),{width:t.x,height:t.y}}destroy(){this._outlinePass=void 0,this._composer?.dispose(),this._renderer?.forceContextLoss(),this._renderer?.dispose(),delete this._composer,delete this._renderer,this.disposeHUD()}disposeHUD(){if(this._hudScene){[...this._hudScene.children].forEach(t=>{if(this._hudScene.remove(t),t.geometry&&t.geometry.dispose(),t.material){const e=t.material;e.map&&e.map.dispose(),e.dispose()}}),this._hudScene.environment&&(this._hudScene.environment.dispose(),this._hudScene.environment=null),this._hudScene=void 0}if(this._hudCamera=void 0,this._hudCSS3DScene){[...this._hudCSS3DScene.children].forEach(t=>this._hudCSS3DScene.remove(t)),this._hudCSS3DScene=void 0}this._hudCSS3DRenderer&&(this._hudCSS3DRenderer.domElement.remove(),this._hudCSS3DRenderer=void 0),this._hudCSS3DCamera=void 0}disposeCSS3DScene(){if(this._css3DScene){[...this._css3DScene.children].forEach(t=>this._css3DScene.remove(t))}}}class od{constructor(){this.lights=[]}get hemiLight(){return this._hemiLight}get dirLight(){return this._dirLight}setup(t,n,i){this._scene=t,this._camera=n;const{hemisphere:r,directional:s,point:o}=i;if(this._hemiLight=new e.HemisphereLight(r.skyColor,r.groundColor,r.intensity),t.add(this._hemiLight),this.lights.push(this._hemiLight),s){if(this._dirLight=new e.DirectionalLight(s.color,s.intensity),s.position&&this._dirLight.position.set(...s.position),!1!==s.castShadow){this._dirLight.castShadow=!0;const t=s.shadowMapSize??2048;this._dirLight.shadow.mapSize.set(t,t),this._dirLight.shadow.bias=s.shadowBias??-5e-4;const e=this._dirLight.shadow.camera;e.near=.1,e.far=5e3,e.left=-1500,e.right=1500,e.top=1500,e.bottom=-1500}s.attachToCamera?n.add(this._dirLight):t.add(this._dirLight),this.lights.push(this._dirLight)}if(o){const n=new e.PointLight(o.color,o.intensity,void 0,o.decay);n.power=o.power,n.castShadow=o.castShadow,n.position.set(...o.position),n.shadow.camera.near=o.shadowNear,n.shadow.camera.far=o.shadowFar,t.add(n),this.lights.push(n)}}updateHemisphere(t){this._hemiLight&&(void 0!==t.skyColor&&this._hemiLight.color.set(t.skyColor),void 0!==t.groundColor&&this._hemiLight.groundColor.set(t.groundColor),void 0!==t.intensity&&(this._hemiLight.intensity=t.intensity))}updateDirectional(t){this._dirLight&&(void 0!==t.color&&this._dirLight.color.set(t.color),void 0!==t.intensity&&(this._dirLight.intensity=t.intensity))}setDirectionalFollowCamera(t){this._dirLight&&this._scene&&this._camera&&(this._dirLight.removeFromParent(),t?this._camera.add(this._dirLight):this._scene.add(this._dirLight))}setDirectionalAngle(t,e,n=1e3){if(!this._dirLight)return;const i=t*Math.PI/180,r=e*Math.PI/180,s=n;this._dirLight.position.set(s*Math.cos(r)*Math.sin(i),s*Math.sin(r),s*Math.cos(r)*Math.cos(i)),this._dirLight.target.position.set(0,0,0),!this._dirLight.target.parent&&this._scene&&this._scene.add(this._dirLight.target)}setDirectionalEnabled(t,n){if(t&&!this._dirLight&&this._camera){const t=n?.color??16777215,i=n?.intensity??2;this._dirLight=new e.DirectionalLight(t,i),this._camera.add(this._dirLight),this.lights.push(this._dirLight)}else!t&&this._dirLight&&(this._dirLight.removeFromParent(),this._dirLight.dispose(),this.lights=this.lights.filter(t=>t!==this._dirLight),this._dirLight=void 0)}destroy(){this.lights.forEach(t=>t.dispose()),this.lights=[],this._hemiLight=void 0,this._dirLight=void 0,this._scene=void 0,this._camera=void 0}}const ad=1e-6;class cd{constructor(){this._enabled=!0,this._state=0,this._autoRotate=!1,this._autoRotateSpeed=2,this._dampingFactor=.15,this._rotateSpeed=.1,this._panSpeed=1,this._dollyStart=0,this._lastScale=1,this._floorConstraint=!1,this._spherical=new e.Spherical,this._sphericalDelta=new e.Spherical,this._panOffset=new e.Vector3,this._target=new e.Vector3,this._target0=new e.Vector3,this._position0=new e.Vector3,this._rotateStart=new e.Vector2,this._rotateEnd=new e.Vector2,this._rotateDelta=new e.Vector2,this._panStart=new e.Vector2,this._panEnd=new e.Vector2,this._panDelta=new e.Vector2,this._offset=new e.Vector3,this._lastPosition=new e.Vector3,this._lastQuaternion=new e.Quaternion,this._panLeftV=new e.Vector3,this._panUpV=new e.Vector3,this._panCalcOffset=new e.Vector3}get isActive(){return!!this._camera}get target(){return this._target.clone()}restoreTarget(t){this._target.copy(t),this.update()}get _isOrthoLocked(){return!!this._camera?.isOrthographicCamera}setup(t,n){this._camera=t,this._host=n,this._target.set(0,0,0),this._target0.copy(this._target),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert();const i=n.state;this._autoRotate=!n.app?.isEditMode&&(i.autoRotate||"orbit"===i.cameraAutoPlay)||!1,this._autoRotateSpeed=i.rotationSpeed||2,this._floorConstraint=!n.app?.isEditMode&&!!i.cameraFloorConstraint||!1,this.update()}setEnabled(t){this._enabled=t}setOnUserInteraction(t){this._onUserInteraction=t}onDragStart(t){this._enabled&&(this._onUserInteraction?.(),this._isOrthoLocked?(this._state=2,this._panStart.set(t.offsetX,t.offsetY)):(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,1===this._state?this._rotateStart.set(t.offsetX,t.offsetY):3===this._state?this._dollyStart=t.offsetY:this._panStart.set(t.offsetX,t.offsetY)))}onDragMove(t){if(this._enabled)if(this._isOrthoLocked)this._state=2,this._handlePanMove(t.offsetX,t.offsetY);else if(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,3===this._state){const e=t.offsetY-this._dollyStart;this._dollyStart=t.offsetY;const n=1+.005*e;this.dollyAtCursor(n,0,0)}else 1===this._state?this._handleRotateMove(t.offsetX,t.offsetY):this._handlePanMove(t.offsetX,t.offsetY)}onDragEnd(t){this._state=0,this._host?.invalidate()}onTouchStart(t){this._onUserInteraction?.();const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)return this._panStart.set(n,i),void(this._state=5);switch(t.touches.length){case 1:this._rotateStart.set(n,i),this._state=4;break;case 2:this._lastScale=t.scale||1,this._panStart.set(n,i),this._state=5;break;default:this._state=0}}onTouchMove(t){const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)this._handlePanMove(n,i);else switch(t.touches.length){case 1:if(4!==this._state)return;this._handleRotateMove(n,i);break;case 2:{if(5!==this._state)return;const e=t.scale||1;if(Math.abs(this._lastScale-e)>.01){const t=this._lastScale/e;this._lastScale=e,this.dollyAtCursor(t,0,0)}else this._handlePanMove(n,i);break}default:this._state=0}}onTouchEnd(t){this._lastScale=1,this._state=0}onKeyDown(t){switch(t.code){case"ArrowUp":this._pan(0,7);break;case"ArrowDown":this._pan(0,-7);break;case"ArrowLeft":this._pan(7,0);break;case"ArrowRight":this._pan(-7,0);break;default:return}this.update()}update(){const t=this._camera,e=t.position;if(this._isOrthoLocked)return this._panOffset.lengthSq()>0&&(this._target.add(this._panOffset),e.add(this._panOffset),this._panOffset.set(0,0,0)),(this._lastPosition.distanceToSquared(e)>ad||8*(1-this._lastQuaternion.dot(t.quaternion))>ad)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0);if(this._offset.copy(e).sub(this._target),this._offset.applyQuaternion(this._quat),this._spherical.setFromVector3(this._offset),this._spherical.theta+=this._sphericalDelta.theta,this._autoRotate&&0===this._state){const t=2*Math.PI/60*(this._autoRotateSpeed/60);this._spherical.theta-=t}this._spherical.phi+=this._sphericalDelta.phi,this._spherical.phi=Math.max(0,Math.min(Math.PI,this._spherical.phi)),this._spherical.makeSafe(),this._target.add(this._panOffset),this._offset.setFromSpherical(this._spherical),this._offset.applyQuaternion(this._quatInverse),e.copy(this._target).add(this._offset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),e.y<0&&(e.y=0)),t.lookAt(this._target);const n=1-this._dampingFactor;return this._sphericalDelta.theta*=n,this._sphericalDelta.phi*=n,this._panOffset.set(0,0,0),(this._lastPosition.distanceToSquared(e)>ad||8*(1-this._lastQuaternion.dot(t.quaternion))>ad)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0)}reset(){this._target.copy(this._target0),this._camera.position.copy(this._position0),this._camera.updateProjectionMatrix(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._state=0,this.update()}pinResetPosition(){this._camera&&(this._position0.copy(this._camera.position),this._target0.copy(this._target))}setCamera(t){this._camera=t,this._target.set(0,0,0),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._lastPosition.copy(t.position),this._lastQuaternion.copy(t.quaternion),this._state=0,t.updateMatrixWorld(!0)}isAutoRotating(){return this._autoRotate}setAutoRotate(t){this._autoRotate=t,this._host?.invalidate()}setFloorConstraint(t){this._floorConstraint=t,this.update()}markCameraChanged(){this._host?.invalidate()}dollyAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,r=i.position.distanceTo(this._target),s=Math.max(1,Math.min(5e4,r*t));if(Math.abs(s-r)<ad)return;const o=Math.tan(i.fov/2*Math.PI/180)/i.zoom,a=r-s,c=e*a*o*i.aspect,l=n*a*o;this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(c),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(l),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),this._panCalcOffset.subVectors(i.position,this._target).normalize().multiplyScalar(s),i.position.copy(this._target).add(this._panCalcOffset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),i.position.y<0&&(i.position.y=0)),this._host?.invalidate()}zoomOrthoAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,r=i.zoom,s=Math.max(.1,Math.min(20,r*t)),o=e*(i.right-i.left)/2*(1/r-1/s),a=n*(i.top-i.bottom)/2*(1/r-1/s);this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(o),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(a),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),i.zoom=s,i.updateProjectionMatrix(),this._host?.invalidate()}destroy(){delete this._camera,delete this._host}_getViewportSize(){const t=this._host?.element;if(t){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return{width:e.width,height:e.height}}const{width:e,height:n}=this._host.bounds;return{width:Math.abs(e)||1,height:Math.abs(n)||1}}_handleRotateMove(t,e){this._rotateEnd.set(t,e),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart);const{width:n,height:i}=this._getViewportSize();this._sphericalDelta.theta-=2*Math.PI*this._rotateDelta.x/n*this._rotateSpeed,this._sphericalDelta.phi-=2*Math.PI*this._rotateDelta.y/i*this._rotateSpeed,this._rotateStart.copy(this._rotateEnd),this._host?.invalidate()}_handlePanMove(t,e){this._panEnd.set(t,e),this._panDelta.subVectors(this._panEnd,this._panStart),this._isOrthoLocked?this._panOrtho(this._panDelta.x,this._panDelta.y):this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this._host?.invalidate()}_panOrtho(t,e){const n=this._camera,{width:i,height:r}=this._getViewportSize();this._panLeftV.setFromMatrixColumn(n.matrix,0),this._panLeftV.multiplyScalar(-t*(n.right-n.left)/n.zoom/i),this._panUpV.setFromMatrixColumn(n.matrix,1),this._panUpV.multiplyScalar(e*(n.top-n.bottom)/n.zoom/r),this._target.add(this._panLeftV).add(this._panUpV),n.position.add(this._panLeftV).add(this._panUpV)}panByPixels(t,e){this._onUserInteraction?.(),this._pan(t,e),this._target.add(this._panOffset),this._camera.position.add(this._panOffset),this._panOffset.set(0,0,0),this._host?.invalidate()}_pan(t,e){t*=this._panSpeed,e*=this._panSpeed;const{width:n,height:i}=this._getViewportSize(),r=this._camera;if(r.isPerspectiveCamera){this._panCalcOffset.copy(r.position).sub(this._target);let n=this._panCalcOffset.length();n*=Math.tan(r.fov/2*Math.PI/180),this._panLeftV.setFromMatrixColumn(r.matrix,0),this._panLeftV.multiplyScalar(-2*t*n/i),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(r.matrix,1),this._panUpV.multiplyScalar(2*e*n/i),this._panOffset.add(this._panUpV)}else r.isOrthographicCamera&&(this._panLeftV.setFromMatrixColumn(r.matrix,0),this._panLeftV.multiplyScalar(-t*(r.right-r.left)/r.zoom/n),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(r.matrix,1),this._panUpV.multiplyScalar(e*(r.top-r.bottom)/r.zoom/i),this._panOffset.add(this._panUpV))}}class ld{constructor(){this._mouse=new e.Vector2,this._raycaster=new e.Raycaster}get mouse(){return this._mouse}get lastFocused(){return this._lastFocused}set lastFocused(t){this._lastFocused=t}get lastHovered(){return this._lastHovered}set lastHovered(t){this._lastHovered=t}updateMouseNDC(t,e,n,i,r,s){this._mouse.x=(t-n)/r*2-1,this._mouse.y=-(e-i)/s*2+1}getObjectByRaycast(t,e){const n=this.getObjectsByRaycast(t,e);if(n&&n.length>0)for(const t of n){if(!this._isWorldVisible(t.object))continue;let e=t.object;for(;e;){if(e.userData.context)return e;e=e.parent}}}_isWorldVisible(t){let e=t;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}getObjectsByRaycast(t,e){return this._raycaster.setFromCamera(this._mouse,t),this._raycaster.intersectObjects(e.children,!0)}setHUD(t,e){this._hudScene=t,this._hudCamera=e}handleClick(t,e,n){let i;this._lastFocused&&(this._lastFocused.focused=!1),this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const r=i?.userData.context;return r&&(r.focused=!0,this._lastFocused=r,r.component?.trigger("click",n)),r}handleHover(t,e,n){let i;this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const r=i?.userData.context;r!==this._lastHovered&&(this._lastHovered&&(this._lastHovered.component?.trigger("mouseleave",n),this._lastHovered=void 0),r&&(this._lastHovered=r,this._lastHovered.component?.trigger("mouseenter",n)))}destroy(){this._lastFocused=void 0,this._lastHovered=void 0,this._hudScene=void 0,this._hudCamera=void 0}}const hd=Math.PI/180*15;class dd{constructor(){this._mode="translate",this._isDragging=!1}get controls(){return this._controls}get mode(){return this._mode}get attached(){return this._attached}get isAttached(){return!!this._attached}get isDragging(){return this._isDragging}get isEngaged(){return!!this._controls?.axis}setup(t,e,n){this.destroy(),this._scene=n;const i=document.createElement("div");i.style.cssText="position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none",i.setPointerCapture=()=>{},i.releasePointerCapture=()=>{},e.appendChild(i),this._proxyElement=i,this._controls=new k(t,i),this._controls.setMode(this._mode),n.add(this._controls.getHelper()),this._controls.addEventListener("dragging-changed",t=>{this._isDragging=t.value,this.onDraggingChanged?.(t.value)}),this._controls.addEventListener("change",()=>{this._attached&&this.onObjectChange?.(this._attached)})}forwardEvent(t,e){if(!this._proxyElement||!this._controls)return;"rotate"===this._mode&&this._controls.setRotationSnap(t.shiftKey?hd:null);const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:t.button??0,pointerId:1,pointerType:"mouse",bubbles:!0});this._proxyElement.dispatchEvent(n)}forwardTouch(t,e){if(!this._proxyElement||!this._controls)return;const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:0,pointerId:t.identifier+10,pointerType:"touch",bubbles:!0});this._proxyElement.dispatchEvent(n)}setMode(t){this._mode=t,this._controls?.setMode(t)}attach(t){this._attached=t,this._controls?.attach(t),this._controls?.getHelper().updateMatrixWorld(!0),this.onAttachChanged?.(!0)}detach(){this._controls?.detach(),this._attached=void 0,this.onAttachChanged?.(!1)}setRotationSnap(t){this._controls&&this._controls.setRotationSnap(t?hd:null)}updateCamera(t){this._controls&&(this._controls.camera=t)}destroy(){this._controls&&(this._controls.detach(),this._controls.dispose(),this._scene&&this._scene.remove(this._controls.getHelper()),this._controls=void 0),this._proxyElement?.parentNode&&this._proxyElement.parentNode.removeChild(this._proxyElement),this._proxyElement=void 0,this._attached=void 0,this._isDragging=!1}}const ud=.01;function pd(t){const[e,n,i]=t,r=Math.abs(e-1),s=Math.abs(n-1),o=Math.abs(i-1);return r<ud&&s<ud&&o<ud?null:r>=s&&r>=o?e:s>=r&&s>=o?n:i}class fd{constructor(){this._mouseDownAltKey=!1}captureAltKey(t){this._mouseDownAltKey=t}setupCallbacks(t,e,n,i){t.onDraggingChanged=r=>{e.setEnabled(!r);const s=n();s&&(i?.onDraggingChanged?.(r),r?(this._onDragStart(t,s),s.hostElement&&this._showInfoOverlay(s.hostElement)):(this._hideInfoOverlay(),this._onDragEnd(t,s)),s.app?.commander?.execute(null),s.invalidate())},t.onObjectChange=e=>{if(this._syncFromGizmo(t,e),this._infoOverlay){const n=t.controls?.axis??null;this._updateInfoOverlay(t.mode,e,n)}n()?.invalidate()},t.onAttachChanged=t=>{i?.onAttachChanged?.(t)}}_onDragStart(t,e){this._mouseDownAltKey&&"translate"===t.mode&&this._performAltDragDuplicate(e);const n=e.root?.selected||[];n.length>1&&this._captureMultiSelectState(t,n);const i=t.attached;i&&("rotate"!==t.mode||this._gizmoInitialRotation?"translate"!==t.mode||this._dragStartPosition||(this._dragStartPosition=i.position.clone()):this._gizmoInitialRotation=i.rotation.clone()),"scale"===t.mode&&this._captureScalePreDrag(t)}_performAltDragDuplicate(t){const e=t.root?.selected||[];if(0===e.length||!t.root)return;const n=t.root,i=[];for(const t of e){const e=t.parent,r=new Map,s=wl(t,t=>{const e=n.getNewRefid();return void 0!==t&&r.set(t,e),e});s.replaceRefids(r),e.addComponent(s),i.push({component:s,to_container:e})}this._altDragDuplicates=i}_captureMultiSelectState(t,e){const n=t.attached;if(n)if("translate"===t.mode){const t=new Map,i=n.position;for(let n=1;n<e.length;n++){const r=e[n]._realObject;r?.object3d&&r.gizmoTransformable&&t.set(r,r.object3d.position.clone().sub(i))}this._multiSelectOffsets=t}else if("rotate"===t.mode){this._gizmoInitialRotation=n.rotation.clone();const t=new Map;for(let n=1;n<e.length;n++){const i=e[n]._realObject;i?.object3d&&i.gizmoTransformable&&t.set(i,i.object3d.rotation.clone())}this._multiSelectInitialRotations=t}else if("scale"===t.mode){const t=new Map;for(let n=1;n<e.length;n++){const i=e[n],r=i._realObject;if(r?.object3d&&r.gizmoTransformable){const{left:e,top:n,width:s,height:o}=i.bounds,{zPos:a=0}=i.state,c=i.state.depth;t.set(r,{left:e,top:n,width:s,height:o,depth:c,zPos:a,scaleX:r.object3d.scale.x,scaleY:r.object3d.scale.y,scaleZ:r.object3d.scale.z})}}this._multiSelectPreDragDimensions=t}}_captureScalePreDrag(t){const e=t.attached,n=e?.userData.context;if(!n||!e)return;const{left:i,top:r,width:s,height:o}=n.component.bounds,{zPos:a=0}=n.component.state,c=n.component.state.depth??n.effectiveDepth;this._preDragDimension={left:i,top:r,width:s,height:o,depth:c,zPos:a},this._preDragScale={x:e.scale.x,y:e.scale.y,z:e.scale.z},this._preDragEffectiveDepth=void 0,this._scaleAnchorSign=this._computeAnchorSign(t,e),this._preDragAttachedPosition=e.position.clone()}_computeAnchorSign(t,n){const i=t.controls;if(!i)return{x:0,y:0,z:0};const r=i.axis;if(!r||"XYZE"===r)return{x:0,y:0,z:0};if(r.includes("X")&&r.includes("Y")&&r.includes("Z"))return{x:0,y:0,z:0};const s=new e.Quaternion;n.getWorldQuaternion(s),s.invert();const o=i.pointStart.clone().applyQuaternion(s),a=.001,c={x:0,y:0,z:0};return r.includes("X")&&Math.abs(o.x)>a&&(c.x=Math.sign(o.x)),r.includes("Y")&&Math.abs(o.y)>a&&(c.y=Math.sign(o.y)),r.includes("Z")&&Math.abs(o.z)>a&&(c.z=Math.sign(o.z)),c}_onDragEnd(t,e){if(this._altDragDuplicates&&this._altDragDuplicates.length>0&&(e.app?.commander.execute(new bl({changes:this._altDragDuplicates})),this._altDragDuplicates=void 0),this._multiSelectOffsets=void 0,this._gizmoInitialRotation=void 0,this._multiSelectInitialRotations=void 0,this._dragStartPosition=void 0,this._preDragDimension){const e=t.attached,n=e?.userData.context;if(n&&(void 0!==this._preDragEffectiveDepth&&n.applyDimensionFromGizmo({depth:this._preDragEffectiveDepth}),n.update()),this._multiSelectPreDragDimensions)for(const[t]of this._multiSelectPreDragDimensions)t.update()}const n=e.root?.selected||[];for(const e of n){const n=e._realObject;n?.onGizmoDragEnd(t.mode)}for(const t of n){let e=t.parent;for(;e?.isGroup?.();){const t=[];e._realObject&&t.push(e._realObject);for(const n of e.components||[])n._realObject&&t.push(n._realObject);for(const e of t)e._suppressOnchange=!0;e.calculateBounds();for(const e of t)e._suppressOnchange=!1,e.updateTransform();e=e.parent}}this._preDragDimension=void 0,this._preDragScale=void 0,this._preDragEffectiveDepth=void 0,this._multiSelectPreDragDimensions=void 0,this._scaleAnchorSign=void 0,this._preDragAttachedPosition=void 0}_syncFromGizmo(t,e){const n=e.userData.context;if(n)if("scale"===t.mode&&this._preDragDimension&&this._preDragScale){const{ratioX:t,ratioY:i,ratioZ:r,sign:s}=this._syncDimensionFromGizmo(n,e);if(this._multiSelectPreDragDimensions)for(const[e,n]of this._multiSelectPreDragDimensions)e.applyDimensionFromGizmo(this._computeAnchorProps(n,t,i,r,s))}else{if(n.syncFromObject3D(),"translate"===t.mode&&this._applyGroundSnap(e,n),this._multiSelectOffsets){const n=e.position;for(const[e,i]of this._multiSelectOffsets)e.object3d&&(e.object3d.position.copy(n).add(i),"translate"===t.mode&&this._applyGroundSnap(e.object3d,e),e.syncFromObject3D())}if(this._multiSelectInitialRotations&&this._gizmoInitialRotation){const t=e.rotation.x-this._gizmoInitialRotation.x,n=e.rotation.y-this._gizmoInitialRotation.y,i=e.rotation.z-this._gizmoInitialRotation.z;for(const[e,r]of this._multiSelectInitialRotations)e.object3d&&(e.object3d.rotation.set(r.x+t,r.y+n,r.z+i),e.syncFromObject3D())}}}_applyGroundSnap(t,e){const n=e.effectiveDepth/2,i=t.position.y-n,r=Math.abs(i);if(r<2)t.position.y=n,e.syncFromObject3D();else if(r<10){const s=(r-2)/8,o=1-s*s;t.position.y=n+i*(1-o),e.syncFromObject3D()}}_syncDimensionFromGizmo(t,e){const n=this._preDragDimension,i=this._preDragScale;let r={...this._scaleAnchorSign??{x:0,y:0,z:0}},s=e.scale.x/i.x,o=e.scale.y/i.y,a=e.scale.z/i.z;if(t.component.state.ratioLock){const t=pd([s,o,a]);if(t){s=o=a=t,e.scale.set(t*i.x,t*i.y,t*i.z);const n=r.x||r.y||r.z;n&&(r={x:n,y:n,z:n})}}return t.applyDimensionFromGizmo(this._computeAnchorProps(n,s,o,a,r)),!this._preDragAttachedPosition||0===r.x&&0===r.y&&0===r.z||this._applyAnchorPositionCorrection(e,n,i,r),{ratioX:s,ratioY:o,ratioZ:a,sign:r}}_computeAnchorProps(t,e,n,i,r){const s=t.width*e,o=t.height*i,a=r.x>0?0:r.x<0?t.width-s:(t.width-s)/2,c=r.z>0?0:r.z<0?t.height-o:(t.height-o)/2,l={left:t.left+a,top:t.top+c,width:s,height:o};if(void 0!==t.depth){const e=t.depth*n,i=r.y>0?0:r.y<0?t.depth-e:(t.depth-e)/2;l.depth=e,l.zPos=t.zPos+i}return l}_applyAnchorPositionCorrection(t,n,i,r){const s=new e.Vector3(r.x*(t.scale.x-i.x)*n.width/2,r.y*(t.scale.y-i.y)*(n.depth??0)/2,r.z*(t.scale.z-i.z)*n.height/2),o=new e.Quaternion;t.getWorldQuaternion(o),s.applyQuaternion(o);const a=this._preDragAttachedPosition;t.position.set(a.x+s.x,a.y+s.y,a.z+s.z)}_showInfoOverlay(t){if(this._infoHostElement=t,this._infoOverlay)return;const e=document.createElement("div");e.style.cssText="\n position: absolute; z-index: 10000; pointer-events: none;\n left: 50%; top: 16px; transform: translateX(-50%);\n padding: 6px 16px; border-radius: 6px;\n background: rgba(0,0,0,0.8); color: #fff;\n font: bold 16px/1.4 'Pretendard', system-ui, sans-serif;\n letter-spacing: 0.5px;\n white-space: nowrap; opacity: 0; transition: opacity 0.15s;\n box-shadow: 0 2px 8px rgba(0,0,0,0.3);\n ",t.style.position="relative",t.appendChild(e),this._infoOverlay=e,requestAnimationFrame(()=>{e.style.opacity="1"})}_updateInfoOverlay(t,e,n){if(!this._infoOverlay)return;const i=t=>(t>=0?"+":"")+t.toFixed(1);if("rotate"===t){if(!this._gizmoInitialRotation)return;const t=180/Math.PI,n=(e.rotation.x-this._gizmoInitialRotation.x)*t,r=(e.rotation.y-this._gizmoInitialRotation.y)*t,s=(e.rotation.z-this._gizmoInitialRotation.z)*t,o=[Math.abs(n),Math.abs(r),Math.abs(s)],a=o.indexOf(Math.max(...o)),c=["X","Y","Z"],l=[n,r,s],h=[e.rotation.x*t,e.rotation.y*t,e.rotation.z*t];this._infoOverlay.textContent=`↻ ${c[a]}: ${h[a].toFixed(1)}° (${i(l[a])})`}else if("translate"===t){if(!this._dragStartPosition)return;const t=e.position.clone().sub(this._dragStartPosition),n=e.position,r=(t,e,n)=>Math.abs(n)<.05?`${t}:${e.toFixed(0)}`:`${t}:${e.toFixed(0)}(${i(n)})`;this._infoOverlay.textContent=`↔ ${r("X",n.x,t.x)} ${r("Y",n.y,t.y)} ${r("Z",n.z,t.z)}`}else if("scale"===t){if(!this._preDragScale)return;this._infoOverlay.textContent=this._formatScaleInfo(e,n)}}_formatScaleInfo(t,e){const n=this._preDragScale,i=this._preDragDimension,r=t.scale.x/(n.x||1),s=t.scale.y/(n.y||1),o=t.scale.z/(n.z||1),a=i?i.width*r:t.scale.x,c=null!=i?.depth?i.depth*s:t.scale.y,l=i?i.height*o:t.scale.z,h=i?i.width*(r-1):t.scale.x-n.x,d=null!=i?.depth?i.depth*(s-1):t.scale.y-n.y,u=i?i.height*(o-1):t.scale.z-n.z,p=t=>(t>=0?"+":"")+t.toFixed(0),f=t=>t.toFixed(0);switch(e){case"X":return`⤢ W ${f(a)}px (${p(h)})`;case"Y":return`⤢ D ${f(c)}px (${p(d)})`;case"Z":return`⤢ H ${f(l)}px (${p(u)})`}return Math.abs(r-s)<.01&&Math.abs(s-o)<.01?`⤢ ×${r.toFixed(2)} (${f(a)}×${f(c)}×${f(l)})`:`⤢ W:${f(a)}(${p(h)}) D:${f(c)}(${p(d)}) H:${f(l)}(${p(u)})`}_hideInfoOverlay(){this._infoOverlay&&(this._infoOverlay.remove(),this._infoOverlay=void 0),this._infoHostElement=void 0}}class gd{constructor(){this._mouseIsDown=!1,this._isDragging=!1,this._touchGizmoCaptured=!1,this._mouseDownPos={x:0,y:0}}get hostElement(){return this._hostElement}setup(t,e,n){this.cleanup(),this._hostElement=t,this._gizmo=e.gizmo,this._controls=e.controls,this._camera=e.camera,this._scene=e.scene,this._event=e.event,this._delegate=n,t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.style.outline="none";const i={mousedown:t=>this._onMouseDown(t),mousemove:t=>this._onMouseMove(t),wheel:t=>{t.stopPropagation(),this._delegate.handleWheel(t)},dblclick:t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleDblClick(t)},contextmenu:t=>{t.preventDefault()},touchstart:t=>{if(t.stopPropagation(),1===t.touches?.length&&this._gizmo?.isAttached){const e=t.touches[0];if(this._gizmo.forwardTouch(e,"pointermove"),this._gizmo.isEngaged)return this._gizmo.forwardTouch(e,"pointerdown"),this._touchGizmoCaptured=!0,void t.preventDefault()}this._touchGizmoCaptured=!1,this._delegate.handleTouchStart(t)},touchmove:t=>{if(t.stopPropagation(),this._touchGizmoCaptured&&1===t.touches.length)return this._gizmo.forwardTouch(t.touches[0],"pointermove"),void t.preventDefault();this._delegate.handleTouchMove(t)},touchend:t=>{if(t.stopPropagation(),this._touchGizmoCaptured){const e=t.changedTouches[0];return e&&this._gizmo.forwardTouch(e,"pointerup"),void(this._touchGizmoCaptured=!1)}this._delegate.handleTouchEnd(t)},keydown:t=>{!this._delegate.handleKeyDown(t)||t.ctrlKey||t.metaKey||t.stopPropagation()},keyup:t=>{(this._delegate.handleKeyUp?.(t)??!1)&&t.stopPropagation()}};t.addEventListener("mousedown",i.mousedown),t.addEventListener("mousemove",i.mousemove),t.addEventListener("wheel",i.wheel),t.addEventListener("dblclick",i.dblclick),t.addEventListener("contextmenu",i.contextmenu),t.addEventListener("touchstart",i.touchstart,{passive:!1}),t.addEventListener("touchmove",i.touchmove,{passive:!1}),t.addEventListener("touchend",i.touchend),t.addEventListener("keydown",i.keydown),t.addEventListener("keyup",i.keyup),this._boundHandlers=i}cleanup(){this._removeDocCapture();const t=this._hostElement,e=this._boundHandlers;t&&e&&(t.removeEventListener("mousedown",e.mousedown),t.removeEventListener("mousemove",e.mousemove),t.removeEventListener("wheel",e.wheel),t.removeEventListener("dblclick",e.dblclick),t.removeEventListener("contextmenu",e.contextmenu),t.removeEventListener("touchstart",e.touchstart),t.removeEventListener("touchmove",e.touchmove),t.removeEventListener("touchend",e.touchend),t.removeEventListener("keydown",e.keydown),t.removeEventListener("keyup",e.keyup),t.removeAttribute("tabindex"),t.style.outline=""),this._boundHandlers=void 0,this._hostElement=void 0,this._mouseIsDown=!1,this._isDragging=!1}forceCleanupDragState(){this._removeDocCapture(),this._mouseIsDown=!1,this._isDragging=!1}clientToElementCoords(t,e){const n=this._hostElement;if(!n)return{x:t,y:e};const i=n.getBoundingClientRect();return{x:t-i.left,y:e-i.top}}updateMouseNDCFromClient(t,e){const n=this._hostElement?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const i=t-n.left,r=e-n.top;this._event.updateMouseNDC(i,r,0,0,n.width,n.height)}_onMouseDown(t){if(t.stopPropagation(),this._hostElement.focus(),this._delegate.isPlacementMode())return void this._delegate.handlePlacementClick(t);if(this._delegate.isSpacePanning?.()??!1)return this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation();const e=t.clientX-this._mouseDownPos.x,n=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(e*e+n*n<gd.DRAG_THRESHOLD)return;this._isDragging=!0;const t=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:t.x,offsetY:t.y,altKey:!0})}const i=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:i.x,offsetY:i.y,altKey:!0})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);if(t.shiftKey&&!t.altKey&&!this._gizmo?.isEngaged){const e=this.clientToElementCoords(t.clientX,t.clientY);return this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation();const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<gd.DRAG_THRESHOLD)return;this._isDragging=!0,this._delegate.handleBoxSelectionStart?.(e.x,e.y)}const r=this.clientToElementCoords(t.clientX,t.clientY);this._delegate.handleBoxSelectionUpdate?.(r.x,r.y)},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging)this._delegate.handleBoxSelectionEnd?.(t.shiftKey,t.ctrlKey||t.metaKey);else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0)}if(this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.tryVertexDragStart?.(t))return this._mouseIsDown=!0,this._isDragging=!0,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleVertexDragMove?.(t)},this._docUpHandler=t=>{t.stopPropagation(),this._removeDocCapture(),this._delegate.handleVertexDragEnd?.(t),this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);this._delegate.captureMouseDownAltKey(t.altKey),this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown");let e=this._gizmo.isDragging;!e&&t.altKey&&this._delegate.tryAltClickSelect(t)&&(this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown"),e=this._gizmo.isDragging),this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{if(t.stopPropagation(),e)return void this._gizmo.forwardEvent(t,"pointermove");const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<gd.DRAG_THRESHOLD)return;this._isDragging=!0;const e=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:e.x,offsetY:e.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}const r=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:r.x,offsetY:r.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),e)return this._gizmo.forwardEvent(t,"pointerup"),this._mouseIsDown=!1,void(this._isDragging=!1);if(this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),document.addEventListener("mouseup",this._docUpHandler,!0)}_onMouseMove(t){if(t.stopPropagation(),this._mouseIsDown)return;if(this._delegate.isPlacementMode())return void this._delegate.handlePlacementHover(t);this.updateMouseNDCFromClient(t.clientX,t.clientY);const e=this._camera.activeCamera;e&&this._scene.scene&&this._event.handleHover(e,this._scene.scene,t),this._gizmo.forwardEvent(t,"pointermove")}_removeDocCapture(){this._docMoveHandler&&(document.removeEventListener("mousemove",this._docMoveHandler,!0),this._docMoveHandler=void 0),this._docUpHandler&&(document.removeEventListener("mouseup",this._docUpHandler,!0),this._docUpHandler=void 0)}}gd.DRAG_THRESHOLD=16;class md{constructor(){this._groundPlane=new e.Plane(new e.Vector3(0,1,0),0)}get isActive(){return!!this._pendingModels}get pendingModels(){return this._pendingModels}setup(t,e){this._camera=t.camera,this._event=t.event,this._scene=t.scene,this._delegate=e}start(t){this._pendingModels=t}stop(){this._pendingModels=void 0,this._removeIndicator()}destroy(){this._removeIndicator(),this._pendingModels=void 0}raycastGroundPlane(t){this._delegate.updateMouseNDCFromClient(t.clientX,t.clientY);const n=this._camera.activeCamera;if(!n)return null;n.updateMatrixWorld(!0);const i=new e.Raycaster;i.setFromCamera(this._event.mouse,n);const r=new e.Vector3;return i.ray.intersectPlane(this._groundPlane,r)}updateIndicator(t){if(!t)return void(this._placementIndicator&&(this._placementIndicator.visible=!1));if(!this._placementIndicator){const t=this._scene?.scene;if(!t)return;const n=new e.RingGeometry(.8,1,32);n.rotateX(-Math.PI/2);const i=new e.MeshBasicMaterial({color:48340,opacity:.6,transparent:!0,side:e.DoubleSide,depthTest:!1});this._placementIndicator=new e.Mesh(n,i),this._placementIndicator.renderOrder=999,t.add(this._placementIndicator)}const n=this._pendingModels?.[0],i=n?.rx??n?.width??50,r=n?.ry??n?.height??50;this._placementIndicator.scale.set(i,1,r),this._placementIndicator.position.copy(t),this._placementIndicator.position.y=1,this._placementIndicator.visible=!0}_removeIndicator(){if(this._placementIndicator){const t=this._placementIndicator;this._scene?.scene?.remove(t),t.geometry.dispose(),t.material.dispose(),this._placementIndicator=void 0}}}const yd={linear:t=>t,"ease-in":t=>t*t,"ease-out":t=>1-(1-t)*(1-t),"ease-in-out":t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2};function bd(t,n,i,r,s,o=new e.Vector3){const a=t*t,c=a*t;return o.set(.5*(2*i.x+(-n.x+r.x)*t+(2*n.x-5*i.x+4*r.x-s.x)*a+(-n.x+3*i.x-3*r.x+s.x)*c),.5*(2*i.y+(-n.y+r.y)*t+(2*n.y-5*i.y+4*r.y-s.y)*a+(-n.y+3*i.y-3*r.y+s.y)*c),.5*(2*i.z+(-n.z+r.z)*t+(2*n.z-5*i.z+4*r.z-s.z)*a+(-n.z+3*i.z-3*r.z+s.z)*c))}class vd{constructor(){this._slots=new Array(10),this._animating=!1,this._animationProgress=0,this._playStartOffset=0,this._lastPlayProgress=-1,this._playIndex=-1,this._playing=!1,this._orbitRotating=!1,this._orbitPaused=!1}get isAnimating(){return this._animating}get isPlaying(){return this._playing}get isOrbitRotating(){return this._orbitRotating}get isOrbitPaused(){return this._orbitPaused}get playIndex(){return this._playIndex}get lastPlayProgress(){return this._lastPlayProgress}get playProgress(){if(!this._playing||this._playIndex<0)return 0;const t=this.getPlayableSlots().length;if(t<2)return 0;const e=(this._playIndex-1+t)%t;let n=this._animating?this._animationProgress:1;return this._playStartOffset>0&&(n=this._playStartOffset+n*(1-this._playStartOffset)),(e+n)%t/t}setCallbacks(t,e){this._onInvalidate=t,this._onAnimationComplete=e}saveSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];this._slots[t]={...e,name:"name"in e?e.name:n?.name}}renameSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];n&&(n.name=e||void 0)}clearSlot(t){t<0||t>9||(this._slots[t]=void 0)}getSlot(t){return this._slots[t]}exportSlots(){return this._slots.map(t=>t?{...t}:null)}importSlots(t){if(Array.isArray(t))for(let e=0;e<10;e++){const n=t[e];this._slots[e]=n?{...n}:void 0}}resetAll(){this._slots=new Array(10)}getPlayableSlots(){return this._slots.map((t,e)=>t&&!t.excludeFromPlay?e:-1).filter(t=>t>=0)}swapSlots(t,e){if(t<0||t>9||e<0||e>9||t===e)return;const n=this._slots[t];this._slots[t]=this._slots[e],this._slots[e]=n}moveSlot(t,e){if(t<1||t>9||e<1||e>9||t===e)return;const n=this._slots[t];this._slots.splice(t,1),this._slots.splice(e,0,n)}animateToSlot(t,n,i,r=800,s){const o=this._slots[t];if(!o)return!1;this.stopAnimation(),this._animating=!0,this._animationProgress=0;const a=n.position.clone(),c=i.target.clone(),l=new e.Vector3(o.position.x,o.position.y,o.position.z),h=new e.Vector3(o.target.x,o.target.y,o.target.z),d=.01,u=Math.max(a.distanceTo(c),d),p=Math.max(l.distanceTo(h),d),f=(new e.Vector3).subVectors(c,a),g=(new e.Vector3).subVectors(h,l),m=f.lengthSq()>1e-4?f.normalize():new e.Vector3(0,0,-1).applyQuaternion(n.quaternion),y=g.lengthSq()>1e-4?g.normalize():m.clone(),b=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),m),v=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),y),_=yd[o.easing??"ease-in-out"];return this._runAnimation(r,_,t=>{s?bd(t,s.prevPos,a,l,s.nextPos,n.position):n.position.lerpVectors(a,l,t);const r=b.clone().slerp(v,t),o=new e.Vector3(0,0,-1).applyQuaternion(r),c=u+(p-u)*t,h=n.position.clone().add(o.multiplyScalar(c));i.restoreTarget(h)}),!0}_animatePathSegment(t,e,n,i,r,s){const o=yd[i];this._runAnimation(n,o,n=>{const i=t+(e-t)*n,o=this.evaluatePath(i<=1?i:i-1);o&&(r.position.copy(o.position),s.restoreTarget(o.target))})}_runAnimation(t,e,n){this.stopAnimation(),this._animating=!0,this._animationProgress=0;const i=performance.now(),r=()=>{const s=performance.now()-i,o=Math.min(s/t,1),a=e(o);this._animationProgress=a,n(a),this._onInvalidate?.(),o<1?this._animationId=requestAnimationFrame(r):(this._animating=!1,this._animationId=void 0,this._onAnimationComplete?.())};this._animationId=requestAnimationFrame(r)}_initFromProgress(t,e){const n=t*e,i=Math.min(Math.floor(n),e-1);this._playStartOffset=n-i,this._playIndex=(i+1)%e}startPlay(t,n,i=2e3,r=1200,s=-1,o=!1){if(this._playing)return void this.stopPlay();const a=this.getPlayableSlots();if(a.length<2)return;this._playing=!0;let c=!0,l=-1;const h=s>=0&&s<=1?s:this._lastPlayProgress>0&&this._lastPlayProgress<1?this._lastPlayProgress:-1;o?this._playIndex=0:h>=0?(this._initFromProgress(h,a.length),l=h,c=!1):this._playIndex=0;const d=t=>new e.Vector3(t.x,t.y,t.z),u=t=>{this._onAnimationComplete=()=>{this._playing&&(this._playStartOffset=0,setTimeout(()=>{this._playing&&(this._playIndex=(this._playIndex+1)%a.length,p())},t))}},p=()=>{if(!this._playing)return;const e=a[this._playIndex],s=this._slots[e],o=s?.holdDuration??i,h=s?.transitionDuration??r;if(l>=0){const e=l;let i=this._playIndex/a.length;i<=e&&(i+=1),l=-1;const r=this._playStartOffset,c=Math.max(Math.round(h*(1-r)),100);return u(o),void this._animatePathSegment(e,i,c,s?.easing??"ease-in-out",t,n)}const p=this._buildSplineContext(a,c,t,n,d);c=!1,u(o),this.animateToSlot(e,t,n,h,p)};p()}_buildSplineContext(t,e,n,i,r){if(t.length<3)return;const s=t.length,o=t[(this._playIndex+1)%s],a=this._slots[o];if(!a)return;if(e)return{prevPos:n.position.clone(),nextPos:r(a.position)};const c=t[(this._playIndex-2+s)%s],l=this._slots[c];return l?{prevPos:r(l.position),nextPos:r(a.position)}:void 0}setProgressForSlot(t){const e=this.getPlayableSlots(),n=e.indexOf(t);n<0||e.length<2?this._lastPlayProgress=-1:this._lastPlayProgress=n/e.length}stopPlay(){this._lastPlayProgress=this.playProgress,this._playing=!1,this._playIndex=-1,this._playStartOffset=0,this._onAnimationComplete=void 0,this.stopAnimation()}resetPlay(){this.stopPlay(),this._lastPlayProgress=-1}toggleOrbitRotation(t){const e=t.isAutoRotating();this._orbitRotating=!e,this._orbitPaused=!this._orbitRotating,t.setAutoRotate(this._orbitRotating)}stopOrbitRotation(t){this._orbitRotating=!1,this._orbitPaused=!1,t.setAutoRotate(!1)}evaluatePath(t){const n=this.getPlayableSlots();if(n.length<2)return null;const i=n.length,r=Math.max(0,Math.min(1,t)),s=t=>{const r=this._slots[n[(t%i+i)%i]];return r?new e.Vector3(r.position.x,r.position.y,r.position.z):new e.Vector3},o=t=>{const r=this._slots[n[(t%i+i)%i]];return r?new e.Vector3(r.target.x,r.target.y,r.target.z):new e.Vector3};if(2===i){const t=r<.5?2*r:2*(1-r);return{position:s(0).lerp(s(1),t),target:o(0).lerp(o(1),t)}}const a=r*i,c=Math.min(Math.floor(a),i-1),l=a-c,h=bd(l,s(c-1),s(c),s(c+1),s(c+2)),d=s(c),u=s(c+1),p=o(c),f=o(c+1),g=.01,m=Math.max(d.distanceTo(p),g),y=Math.max(u.distanceTo(f),g),b=(new e.Vector3).subVectors(p,d),v=(new e.Vector3).subVectors(f,u),_=b.lengthSq()>1e-4?b.normalize():new e.Vector3(0,0,-1),x=v.lengthSq()>1e-4?v.normalize():_.clone(),w=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),_),M=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),x),S=w.clone().slerp(M,l),k=new e.Vector3(0,0,-1).applyQuaternion(S),A=m+(y-m)*l,E=h.clone().add(k.multiplyScalar(A));return{position:h,target:E}}stopAnimation(){void 0!==this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=void 0),this._animating=!1}destroy(){this.stopPlay(),this.stopAnimation(),this._orbitPaused=!1,this._slots=new Array(10),this._onInvalidate=void 0,this._onAnimationComplete=void 0}}class _d{constructor(){this._overlay=null,this._hostElement=null,this._startX=0,this._startY=0,this._currentX=0,this._currentY=0,this._active=!1}get isActive(){return this._active}setup(t){this._hostElement=t}startSelection(t,e){this._hostElement&&(this._startX=t,this._startY=e,this._currentX=t,this._currentY=e,this._active=!0,this._overlay=document.createElement("div"),this._overlay.style.cssText="\n position: absolute;\n border: 1px solid #4a9eff;\n background: rgba(74, 158, 255, 0.1);\n pointer-events: none;\n z-index: 1000;\n ",this._hostElement.appendChild(this._overlay),this._updateOverlay())}updateSelection(t,e){this._active&&(this._currentX=t,this._currentY=e,this._updateOverlay())}endSelection(t,n,i){if(!this._active||!this._hostElement)return this.cancelSelection(),[];const r=this._hostElement.getBoundingClientRect(),s=r.width,o=r.height,a=Math.min(this._startX,this._currentX),c=Math.max(this._startX,this._currentX),l=Math.min(this._startY,this._currentY),h=Math.max(this._startY,this._currentY);if(c-a<5&&h-l<5)return this.cancelSelection(),[];const d=a/s*2-1,u=c/s*2-1,p=-h/o*2+1,f=-l/o*2+1,g=[],m=new e.Vector3;for(const e of i){const n=e._realObject;n?.object3d&&(m.copy(n.object3d.position),m.project(t),m.z>1||m.x>=d&&m.x<=u&&m.y>=p&&m.y<=f&&g.push(e))}return this.cancelSelection(),g}cancelSelection(){this._active=!1,this._overlay&&this._hostElement&&this._hostElement.removeChild(this._overlay),this._overlay=null}destroy(){this.cancelSelection(),this._hostElement=null}_updateOverlay(){if(!this._overlay)return;const t=Math.min(this._startX,this._currentX),e=Math.min(this._startY,this._currentY),n=Math.abs(this._currentX-this._startX),i=Math.abs(this._currentY-this._startY);this._overlay.style.left=`${t}px`,this._overlay.style.top=`${e}px`,this._overlay.style.width=`${n}px`,this._overlay.style.height=`${i}px`}}const xd=4890367,wd=16750592;class Md{constructor(){this._componentHandles=[],this._activeVertexHandles=[],this._activeHandleIndex=-1,this._isDragging=!1,this._isExtending=!1,this._dragPlane=new e.Plane,this._dragOffset=new e.Vector3,this._raycaster=new e.Raycaster,this._intersection=new e.Vector3}get isDragging(){return this._isDragging}get isAttached(){return this._componentHandles.length>0}setVisible(t){this._handleGroup&&(this._handleGroup.visible=t)}attachMultiple(t,n,i){this.detach();const r=t.filter(t=>t.mutable&&t.path&&t.path.length>=2);if(0!==r.length){this._scene3d=n,this._commander=i,this._handleGroup=new e.Group,this._handleGroup.name="__vertexHandles__",this._handleGroup.renderOrder=1e4;for(const t of r){const e=this._buildComponentHandles(t);this._componentHandles.push(e)}n.add(this._handleGroup)}}attach(t,e,n){this.attachMultiple([t],e,n)}detach(){this._handleGroup&&this._scene3d&&(this._scene3d.remove(this._handleGroup),Hh(this._handleGroup)),this._componentHandles=[],this._handleGroup=void 0,this._scene3d=void 0,this._commander=void 0,this._activeComponent=void 0,this._activeVertexHandles=[],this._activeHandleIndex=-1,this._isDragging=!1,this._isExtending=!1}_buildComponentHandles(t){const n=[],i=[],r=t.path;if(!r||!this._handleGroup)return{component:t,vertexHandles:n,midpointHandles:i};const{width:s=0,height:o=0}=t.parent?.bounds??{},a=t._realObject,c=a?a.object3d.position.y:0;for(let i=0;i<r.length;i++){const a=r[i],l=new e.Vector3(a.x-s/2,(a.z||0)+c,a.y-o/2),h=this._createVertexHandle(l,i,t);n.push(h),this._handleGroup.add(h)}if(t.pathExtendable)for(let n=0;n<r.length-1;n++){const a=r[n],l=r[n+1],h=new e.Vector3((a.x+l.x)/2-s/2,((a.z||0)+(l.z||0))/2+c,(a.y+l.y)/2-o/2),d=this._createMidpointHandle(h,n,t);i.push(d),this._handleGroup.add(d)}return{component:t,vertexHandles:n,midpointHandles:i}}_rebuildComponentHandles(t){const e=this._componentHandles.findIndex(e=>e.component===t);if(e<0||!this._handleGroup)return;const n=this._componentHandles[e];for(const t of[...n.vertexHandles,...n.midpointHandles])this._handleGroup.remove(t),t.geometry.dispose(),t.material.dispose();this._componentHandles[e]=this._buildComponentHandles(t),this._activeComponent===t&&(this._activeVertexHandles=this._componentHandles[e].vertexHandles)}_createVertexHandle(t,n,i){const r=new e.SphereGeometry(1,16,12),s=new e.MeshBasicMaterial({color:xd,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(r,s);return o.position.copy(t),o.userData.vertexIndex=n,o.userData.handleType="vertex",o.userData.component=i,o.renderOrder=10001,o}_createMidpointHandle(t,n,i){const r=new e.OctahedronGeometry(.7,0),s=new e.MeshBasicMaterial({color:16735602,transparent:!0,opacity:.7,depthTest:!1}),o=new e.Mesh(r,s);return o.position.copy(t),o.userData.segmentIndex=n,o.userData.handleType="midpoint",o.userData.component=i,o.renderOrder=10001,o}_handlePosToPoint(t,e){const{width:n=0,height:i=0}=e.parent?.bounds??{},r=e._realObject,s=r?r.object3d.position.y:0,o={x:t.x+n/2,y:t.z+i/2},a=t.y-s;return Math.abs(a)>.001&&(o.z=a),o}_execMutatePath(t,e){const n=this._commander;n?il.around(n,()=>{t.mutatePath(null,e)}):t.mutatePath(null,e)}_getAllHandles(){const t=[];for(const e of this._componentHandles)t.push(...e.vertexHandles,...e.midpointHandles);return t}_findComponentHandles(t){return this._componentHandles.find(e=>e.component===t)}onPointerDown(t,e,n){if(!this._handleGroup)return!1;const i=this._getAllHandles();if(0===i.length)return!1;this._raycaster.setFromCamera(t,e);const r=this._raycaster.intersectObjects(i,!1);if(0===r.length)return!1;const s=r[0].object,o=s.userData.handleType,a=s.userData.component,c=this._findComponentHandles(a);if(!c)return!1;if(this._activeComponent=a,this._activeVertexHandles=c.vertexHandles,"midpoint"===o)return this._startMidpointDrag(s,a,e);const l=s.userData.vertexIndex,h=a.path;if(!h)return!1;const d=0===l||l===h.length-1;return n.altKey&&d&&a.pathExtendable?this._startEndpointExtend(s,l,a,e):(this._activeHandleIndex=l,this._isDragging=!0,this._isExtending=!1,s.material.color.setHex(wd),this._setupDragPlane(e,s.position),!0)}_startMidpointDrag(t,e,n){const i=t.userData.segmentIndex+1,r=this._handlePosToPoint(t.position,e);this._execMutatePath(e,t=>{t.splice(i,0,r)}),this._rebuildComponentHandles(e);const s=this._activeVertexHandles[i];return!!s&&(this._activeHandleIndex=i,this._isDragging=!0,this._isExtending=!1,s.material.color.setHex(wd),this._setupDragPlane(n,s.position),!0)}_startEndpointExtend(t,e,n,i){const r=n.path;if(!r)return!1;const s=this._handlePosToPoint(t.position,n),o=0===e?0:r.length;this._execMutatePath(n,t=>{t.splice(o,0,s)}),this._rebuildComponentHandles(n);const a=this._activeVertexHandles[o];return!!a&&(this._activeHandleIndex=o,this._isDragging=!0,this._isExtending=!0,a.material.color.setHex(wd),this._setupDragPlane(i,a.position),!0)}_setupDragPlane(t,n){const i=new e.Vector3;t.getWorldDirection(i),this._dragPlane.setFromNormalAndCoplanarPoint(i,n),this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection),this._dragOffset.copy(n).sub(this._intersection)}onPointerMove(t,e,n){if(!this._isDragging||this._activeHandleIndex<0)return!1;this._raycaster.setFromCamera(t,e),this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection);const i=this._intersection.add(this._dragOffset);if(n.shiftKey){const t=this._activeVertexHandles[this._activeHandleIndex];t&&(i.x=t.position.x,i.z=t.position.z)}const r=this._activeVertexHandles[this._activeHandleIndex];return r&&r.position.copy(i),this._updateLinePreview(),!0}_updateLinePreview(){if(!this._activeComponent)return;const t=this._activeComponent._realObject;if(!t?._line2)return;const{width:e=0,height:n=0}=this._activeComponent.parent?.bounds??{},{x:i,y:r}=this._activeComponent.center,s=t.object3d?t.object3d.position.y:0,o=[];for(const t of this._activeVertexHandles){const a=t.position.x+e/2-i,c=t.position.y-s,l=t.position.z+n/2-r;o.push(a,c,l)}if(o.length<6)return;t._line2.geometry.setPositions(o),t._line2.computeLineDistances()}onPointerUp(){if(!this._isDragging||this._activeHandleIndex<0||!this._activeComponent)return!1;const t=this._activeHandleIndex,e=this._activeVertexHandles[t],n=this._activeComponent;if(!e)return this._isDragging=!1,this._activeHandleIndex=-1,this._isExtending=!1,!0;e.material.color.setHex(xd);const i=this._handlePosToPoint(e.position,n);return this._execMutatePath(n,e=>{e[t]=i}),this._isDragging=!1,this._activeHandleIndex=-1,this._isExtending=!1,this._rebuildComponentHandles(n),!0}onDblClick(t,e){if(!this._handleGroup)return!1;const n=[];for(const t of this._componentHandles)n.push(...t.vertexHandles);this._raycaster.setFromCamera(t,e);const i=this._raycaster.intersectObjects(n,!1);if(0===i.length)return!1;const r=i[0].object,s=r.userData.component;if(!s.pathExtendable)return!1;const o=s.path;if(!o||o.length<=2)return!1;const a=r.userData.vertexIndex;return this._execMutatePath(s,t=>{t.splice(a,1)}),this._rebuildComponentHandles(s),!0}syncHandles(){for(const t of this._componentHandles)this._rebuildComponentHandles(t.component)}updateHandleScales(t){const e=this._getAllHandles();if(0!==e.length)for(const n of e){const e=t.position.distanceTo(n.position),i="midpoint"===n.userData.handleType?5:8;let r;if(t.isPerspectiveCamera){const n=t.fov,s=2*Math.tan(n*Math.PI/360)*e;r=i/window.innerHeight*s}else{const e=t,n=(e.top-e.bottom)/e.zoom;r=i/window.innerHeight*n}n.scale.setScalar(Math.max(r,.1))}}destroy(){this.detach()}}class Sd{constructor(){this.sceneManager=new id,this.cameraManager=new rd,this.rendererManager=new sd,this.lightManager=new od,this.controlsManager=new cd,this.eventManager=new ld,this.gizmoManager=new dd,this.interactionManager=new gd,this.placementManager=new md,this.gizmoOperationManager=new fd,this.bookmarkManager=new vd,this.boxSelectionManager=new _d,this.vertexGizmoManager=new Md,this._isSpacePanning=!1,this._initialized=!1,this._decoratorOutlines=new Set,this._selectionOutlineObjects=[],this._highlightedMarkerIndex=-1,this._arrows=new Map,this._pathVisible=!1}get isInitialized(){return this._initialized}get host(){return this._host}get scene3d(){return this.sceneManager.scene}get renderer3d(){return this.rendererManager.renderer}get mixer(){return this.sceneManager.mixer}get camera(){return this.cameraManager.camera}get activeCamera(){return this.cameraManager.activeCamera}get css3DScene(){return this.rendererManager.css3DScene}get css3DRenderer(){return this.rendererManager.css3DRenderer}get noSupportWebgl(){return this.rendererManager.noSupportWebgl}get isActive(){return this.controlsManager.isActive}setGizmoMode(t){if(this.gizmoManager.mode===t&&this.gizmoManager.attached)return this.gizmoManager.detach(),void this._host?.invalidate();this.gizmoManager.setMode(t),this.onGizmoModeChanged?.(t);const e=this._host?.root?.selected,n=e?.filter(t=>t!==this._host&&t._realObject)||[];if(n.length>=1){const e=n[0]._realObject;if(e?.object3d&&e.gizmoTransformable){const n=e.allowedGizmoModes;!n||n.includes(t)?this.gizmoManager.attach(e.object3d):this.gizmoManager.detach()}this._host?.invalidate()}}get gizmoMode(){return this.gizmoManager.mode}init(t,e){this.interactionManager.cleanup(),this._cleanupEventHandlers(),this._host=t,this.sceneManager.scene&&this.destroy(),this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this._initialized=!0,this._setupScene(e),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged)),t.app?.isEditMode&&t.root?.on&&(this._onAddStart=t=>{this.placementManager.start(t),this._host?.element&&(this._host.element.style.cursor="crosshair",this._host.element.focus())},this._onAddStop=()=>{this.placementManager.stop(),this._host?.element&&(this._host.element.style.cursor="")},t.root.on("addstart",this._onAddStart),t.root.on("addstop",this._onAddStop))}_cleanupEventHandlers(){const t=this._host;t&&(this._redrawHandler&&(t.root.off("redraw",this._redrawHandler),this._redrawHandler=void 0),t.off&&(this._onComponentAdd&&(t.off("add",this._onComponentAdd),this._onComponentAdd=void 0),this._onComponentRemove&&(t.off("remove",this._onComponentRemove),this._onComponentRemove=void 0)),this._onSelectionChanged&&t.root?.off&&(t.root.off("selected",this._onSelectionChanged),this._onSelectionChanged=void 0),this._onAddStart&&t.root?.off&&(t.root.off("addstart",this._onAddStart),this._onAddStart=void 0),this._onAddStop&&t.root?.off&&(t.root.off("addstop",this._onAddStop),this._onAddStop=void 0))}_setupScene(t){const e=this._host;let{width:n,height:i}=e.bounds;n=Math.abs(n)||1,i=Math.abs(i)||1;const{fov:r=45,near:s=.1,far:o=2e4,antialias:a=!0,precision:c="highp",cameraX:l,cameraY:h,cameraZ:d,exposure:u=1.2}=e.state,p=e.components||[],f=t?.lightingConfig??{hemisphere:{skyColor:16777215,groundColor:4473924,intensity:.4}},g=t?.css3DSceneAttribute??"three-container:css3d-renderer",m=this.sceneManager.setup(),y=this.cameraManager.setup(n,i,{fov:r,near:s,far:o,cameraX:l,cameraY:h,cameraZ:d});this.cameraManager.addToScene(m);const b=e.app?.postprocessing,v=!t?.skipShadowMap&&void 0,_=!t?.skipPostprocessing&&void 0;if(this.rendererManager.setupWebGL(n,i,{precision:c,antialias:a,exposure:u,postprocessing:b,shadowMap:v,logarithmicDepthBuffer:_})){if(t?.skipEnvironment||this.sceneManager.setupEnvironment(this.rendererManager.renderer),this.controlsManager.setup(y,e),this.controlsManager.setOnUserInteraction(()=>{this.bookmarkManager.isPlaying&&(this.bookmarkManager.stopPlay(),this._pathVisible&&this.showBookmarkPath()),this.bookmarkManager.isOrbitRotating&&this.bookmarkManager.stopOrbitRotation(this.controlsManager)}),e.app?.isEditMode&&e.element&&(this.gizmoManager.setup(y,e.element,m),this._setupGizmoCallbacks()),this.placementManager.setup({camera:this.cameraManager,event:this.eventManager,scene:this.sceneManager},{updateMouseNDCFromClient:(t,e)=>this._updateMouseNDCFromClient(t,e)}),this.lightManager.setup(m,y,f),this.sceneManager.setupMixer(),this.createObjects(p),y.updateProjectionMatrix(),t?.skipFloor||this.sceneManager.addFloor(e),this.sceneManager.setSky(e.state.sky,e.state.skyColor),t?.skipPostprocessing||!1===e.app?.postprocessing)t?.useLightComposer?this.rendererManager.setupLightComposer(m,y,n,i):this.rendererManager.setDirectRenderTargets(m,y);else{const t=this.gizmoManager.controls?.getHelper();this.rendererManager.setupComposer(m,y,n,i,t)}this.rendererManager.setupHUD(n,i),this.rendererManager.hudCamera&&this.eventManager.setHUD(this.rendererManager.hudScene,this.rendererManager.hudCamera),this.rendererManager.setupCSS3D(e.app.isViewMode,g),this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus),e.element&&(this.interactionManager.setup(e.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate()),e.app?.isEditMode&&this.boxSelectionManager.setup(e.element))}}_setupGizmoCallbacks(){this.gizmoOperationManager.setupCallbacks(this.gizmoManager,this.controlsManager,()=>{const t=this._host;if(t)return Object.create(t,{hostElement:{get:()=>t.target??t.element??void 0}})},{onAttachChanged:t=>this.onGizmoAttachChanged?.(t),onDraggingChanged:t=>{t?this.vertexGizmoManager.setVisible(!1):(this.vertexGizmoManager.syncHandles(),this.vertexGizmoManager.setVisible(!0))}})}createObjects(t){for(const e of t)this.addObject(e)}addObject(t){if(t._realObject){const e=t._realObject;if(e.object3d&&!e.object3d.parent){const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}return}if(!t.is3dContainer?.()){try{if(!t.isLine?.()){const{width:e,height:n}=t.bounds;if(!e||!n)return}if(t.isHTMLElement()&&!t.element)return;const e=Qh(t);if(e){if(t._realObject=e,e.update(),e.updateTransform(),t.state.screenFixed)e instanceof Wh?this.rendererManager.hudCSS3DScene.add(e.object3d):this.rendererManager.hudScene.add(e.object3d);else if(e instanceof Wh)this.rendererManager.css3DScene.add(e.object3d);else{const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}const n=this._host?.root?.selected;n&&n.length>0&&n[0]===t&&e.object3d&&e.gizmoTransformable&&this.gizmoManager.attached&&this.gizmoManager.attach(e.object3d)}}catch(t){Ki(t)}if(t.isContainer()){const e=t,n=e.components||[];this.createObjects(n),e.on&&(e.on("add",this._onComponentAdd),e.on("remove",this._onComponentRemove))}}}removeObject(t){if(t.is3dContainer?.())return;if(t.isContainer()){const e=t,n=e.components||[];for(const t of n)this.removeObject(t);e.off&&(e.off("add",this._onComponentAdd),e.off("remove",this._onComponentRemove))}const e=t._realObject;if(e)try{const n=e.object3d;n&&this.gizmoManager.attached===n&&this.gizmoManager.detach(),n&&(e instanceof Wh?this.rendererManager.css3DScene.remove(n):n.removeFromParent()),e.dispose?.(),t._realObject=void 0}catch(t){Ki(t)}}resize(t,e,n=!1){const i=this._host;if(!i)return;if(void 0===t||void 0===e){const n=i.bounds;t=n.width,e=n.height}if(t=Math.abs(t)||1,e=Math.abs(e)||1,n)return void this._applyResize(t,e);this.rendererManager.css3DRenderer?.setSize(t,e);const r=t,s=e;clearTimeout(this._resizeDebouncer),this._resizeDebouncer=window.setTimeout(()=>{this._resizeDebouncer=void 0,this._applyResize(r,s)},100)}_applyResize(t,n){this.cameraManager.updateAspect(t,n),this.rendererManager.resize(t,n);const i=new e.Vector2(t,n);for(const t of this._arrows.values())t.traverse(t=>{t instanceof p&&t.material.resolution.copy(i)});this._initialized&&this.renderThreeD()}animate(){if(!this._initialized||!this.controlsManager.isActive)return;this.sceneManager.updateAnimation();let t=!1;const e=n=>{for(const i of n)i._animation?.started&&i._realObject&&(i._realObject.syncAnimationDelta(),t=!0),i.components&&e(i.components)};e(this._host?.components||[]),this.controlsManager.update(),this.renderThreeD(),t&&this._host?.invalidate()}renderThreeD(){this._initialized&&(this.vertexGizmoManager?.isAttached&&this.vertexGizmoManager.updateHandleScales(this.cameraManager.activeCamera),this.rendererManager.render(),this.renderCSS3D())}setCameraView(t,e){const n=this._host;if(!n)return;const{width:i,height:r}=n.bounds,s=n.element,o=s?.clientWidth||i,a=s?.clientHeight||r;let c;c="perspective"===t?this.cameraManager.restorePerspective():this.cameraManager.setOrthoView(t,i,r,o,a),this.controlsManager.setCamera(c),this.gizmoManager.updateCamera(c),this.rendererManager.updateRenderPassCamera(c),!1!==e?.render&&this.renderThreeD(),this.onCameraViewChanged?.(t)}renderCSS3D(){const t=this.cameraManager.activeCamera;t&&this.rendererManager.renderCSS3D(t)}buildOverlays(){const t=this._host;if(!t?.element)return;t.element.appendChild(this.css3DRenderer.domElement);const e=this.rendererManager.hudCSS3DRenderer?.domElement;e&&t.element.appendChild(e)}destroy(){this.interactionManager.cleanup(),this._resizeDebouncer&&(clearTimeout(this._resizeDebouncer),this._resizeDebouncer=void 0),this._onFocus&&(window.removeEventListener("focus",this._onFocus),this._onFocus=void 0),this.vertexGizmoManager.destroy(),this.boxSelectionManager.destroy(),this.bookmarkManager.destroy(),this.gizmoManager.destroy(),this.controlsManager.destroy(),this.lightManager.destroy(),this.rendererManager.destroy(),this.cameraManager.destroy(),this.sceneManager.destroy(),this.eventManager.destroy(),this._initialized=!1}forceCleanupDragState(){this.interactionManager.forceCleanupDragState(),this.boxSelectionManager.isActive&&(this.boxSelectionManager.cancelSelection(),this.controlsManager.setEnabled(!0)),this._isSpacePanning&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0)),this._host?.element&&(this._host.element.style.cursor="")}clearAllObjects(){this.gizmoManager.detach();const t=this._host?.components||[];for(const e of t)e._realObject&&this.removeObject(e)}rebuildForHost(t,e){this.interactionManager.cleanup();try{this._cleanupEventHandlers()}catch(t){}this._host=t,this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged),this._onAddStart=t=>{this.placementManager.start(t),this._host?.element&&(this._host.element.style.cursor="crosshair",this._host.element.focus())},this._onAddStop=()=>{this.placementManager.stop(),this._host?.element&&(this._host.element.style.cursor="")},t.root.on("addstart",this._onAddStart),t.root.on("addstop",this._onAddStop)),this.createObjects(t.components||[]),t.element&&this.interactionManager.setup(t.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate());const n=this.controlsManager._position0?.clone(),i=this.controlsManager._target0?.clone();this.controlsManager.setup(this.cameraManager.camera,t),n&&this.controlsManager._position0.copy(n),i&&this.controlsManager._target0.copy(i),t.app?.isEditMode&&t.element&&this.boxSelectionManager.setup(t.element),t.app?.isEditMode&&t.element&&this.sceneManager.scene&&(this.gizmoManager.setup(this.cameraManager.camera,t.element,this.sceneManager.scene),this._setupGizmoCallbacks()),this._onFocus||(this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus)),this.renderThreeD()}dispose(){const t=e=>{for(const n of e)if(!n.is3dContainer?.()){if(n.isContainer()){const e=n.components||[];t(e)}n._realObject&&(n._realObject.dispose?.(),n._realObject=void 0)}};t(this._host?.components||[]),this._decoratorOutlines.clear(),this._selectionOutlineObjects=[],this.clearArrows(),this.placementManager.destroy(),this._cleanupEventHandlers(),this.rendererManager.disposeCSS3DScene(),this.destroy(),this._host=void 0}_buildInteractionDelegate(){return{isPlacementMode:()=>this.placementManager.isActive,handlePlacementClick:t=>{if(!this._host?.root)return;const e=this.placementManager.raycastGroundPlane(t);if(e){const t=this._host,n=t.bounds.width||800,i=t.bounds.height||600,r=e.x+n/2,s=e.z+i/2;Ml.call(t.root,this.placementManager.pendingModels,{cx:r,cy:s}),t.root.trigger("addstop")}},handlePlacementHover:t=>{const e=this.placementManager.raycastGroundPlane(t);this.placementManager.updateIndicator(e),this.renderThreeD()},tryAltClickSelect:t=>{if(!this._host?.app?.isEditMode||!this._host.root)return!1;this._updateMouseNDCFromClient(t.clientX,t.clientY);const e=this.cameraManager.activeCamera;if(e&&this.sceneManager.scene){const n=this.eventManager.handleClick(e,this.sceneManager.scene,t);if(n?.component)return this._host.root.selected=[n.component],!0}return!1},captureMouseDownAltKey:t=>{this.gizmoOperationManager.captureAltKey(t)},handleClickAt:(t,e,n)=>{this._handleClickAt(n)},handleWheel:t=>this.onWheel(t),handleDblClick:t=>this.onDblClick(t),handleTouchStart:t=>this.onTouchStart(t),handleTouchMove:t=>this.onPan(t),handleTouchEnd:t=>this.onTouchEnd(t),handleKeyDown:t=>this.onKeyDown(t),handleKeyUp:t=>this._onKeyUp(t),isSpacePanning:()=>this._isSpacePanning,handleBoxSelectionStart:(t,e)=>{this.controlsManager.setEnabled(!1),this._host?.element&&(this._host.element.style.cursor="crosshair"),this.boxSelectionManager.startSelection(t,e)},handleBoxSelectionUpdate:(t,e)=>{this.boxSelectionManager.updateSelection(t,e)},tryVertexDragStart:t=>{if(!this.vertexGizmoManager.isAttached)return!1;const e=this.cameraManager.activeCamera;if(!e)return!1;const n=this.eventManager.mouse,i=this.vertexGizmoManager.onPointerDown(n,e,t);return i&&this.controlsManager.setEnabled(!1),i},handleVertexDragMove:t=>{const e=this.cameraManager.activeCamera;if(!e)return;const n=this.eventManager.mouse;this.vertexGizmoManager.onPointerMove(n,e,t),this._host?.invalidate()},handleVertexDragEnd:t=>{this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),this._host?.invalidate()},handleBoxSelectionEnd:(t,e)=>{this.controlsManager.setEnabled(!0),this._host?.element&&(this._host.element.style.cursor="");const n=this.cameraManager.activeCamera,i=this.sceneManager.scene,r=this._host?.components||[];if(n&&i){let s=this.boxSelectionManager.endSelection(n,i,r);if(e&&t){const t=this._host?.root?.selected||[];if(t.length>0){const e=t[0].state?.type;e&&(s=s.filter(t=>t.state?.type===e))}}if(s.length>0&&this._host?.root)if(t){const t=this._host,e=(this._host.root.selected||[]).filter(e=>e!==t);for(const t of s)e.includes(t)||e.push(t);this._host.root.selected=e}else this._host.root.selected=s}else this.boxSelectionManager.cancelSelection()}}}_handleClickAt(t){const n=this._host,i=this.cameraManager.activeCamera;if(!i||!this.sceneManager.scene)return;if(this._pathMarkers&&this._pathMarkers.children.length>0){const t=new e.Raycaster,n=this.eventManager.mouse;t.setFromCamera(n,i);const r=t.intersectObjects(this._pathMarkers.children,!0);if(r.length>0){let t=r[0].object;for(;t&&void 0===t.userData.bookmarkSlotIndex;)t=t.parent;if(t&&void 0!==t.userData.bookmarkSlotIndex)return void this.animateToSlot(t.userData.bookmarkSlotIndex)}}if(this.vertexGizmoManager?.isDragging)return this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),void this._host?.invalidate();const r=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),r)return;const s=this.eventManager.handleClick(i,this.sceneManager.scene,t);if(n.root){const t=n.app?.mode;if(4===t||5===t){if(!s?.component){const e=4===t?"stylepastestop":"databindpastestop";n.root.trigger(e)}return}}n.app?.isEditMode&&n.root&&this._applySelection(n.root,s?.component,t.shiftKey)}_applySelection(t,e,n){if(e)if(n){const n=(t.selected||[]).slice(),i=n.indexOf(e);-1===i?n.push(e):n.splice(i,1),t.selected=n}else{let n=null,i=e.parent;for(;i?.isGroup?.();)n=i,i=i.parent;if(n){if(!(t.selected||[]).some(t=>{if(t===n)return!0;let e=t.parent;for(;e?.isGroup?.();){if(e===n)return!0;e=e.parent}return!1}))return void(t.selected=[n])}t.selected=[e]}else n||(t.selected=[])}getObjectByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectByRaycast(t,this.sceneManager.scene):void 0}getObjectsByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectsByRaycast(t,this.sceneManager.scene):void 0}_updateMouseNDCFromClient(t,e){const n=this._host?.element;if(n){const i=n.getBoundingClientRect();if(i.width>0&&i.height>0){const n=t-i.left,r=e-i.top;return void this.eventManager.updateMouseNDC(n,r,0,0,i.width,i.height)}}const i=this._host;if(i){const{left:n,top:r,width:s,height:o}=i.bounds;s>0&&o>0&&this.eventManager.updateMouseNDC(t,e,n,r,Math.abs(s),Math.abs(o))}}_eventToNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0)return{ndcX:(t.clientX-n.left)/n.width*2-1,ndcY:-(t.clientY-n.top)/n.height*2+1}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const r=n.transcoordC2S(t.offsetX,t.offsetY);return{ndcX:r.x/Math.abs(e)*2-1,ndcY:-(r.y/Math.abs(i)*2-1)}}}return{ndcX:0,ndcY:0}}_updateMouseNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0){const e=t.clientX-n.left,i=t.clientY-n.top;return void this.eventManager.updateMouseNDC(e,i,0,0,n.width,n.height)}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const r=n.transcoordC2S(t.offsetX,t.offsetY);this.eventManager.updateMouseNDC(r.x,r.y,0,0,Math.abs(e),Math.abs(i))}}}onMouseUp(t){if(this.controlsManager.isActive){const e=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),e)return t.stopPropagation(),!0;const n=this.cameraManager.activeCamera;this._updateMouseNDC(t);const i=this.eventManager.handleClick(n,this.sceneManager.scene,t),r=this._host;return r?.app?.isEditMode&&r.root&&this._applySelection(r.root,i?.component,t.shiftKey),t.stopPropagation(),!0}return!1}onMouseMove(t){if(this.controlsManager.isActive){this.gizmoManager.forwardEvent(t,"pointermove");const e=this.cameraManager.activeCamera;return this._updateMouseNDC(t),this.eventManager.handleHover(e,this.sceneManager.scene,t),t.stopPropagation(),!0}return!1}onMouseDown(t){return!(!this.controlsManager.isActive||(this.gizmoManager.forwardEvent(t,"pointerdown"),!this.gizmoManager.isDragging))&&(t.stopPropagation(),!0)}onMouseLeave(t){return!1}onWheel(t){if(this.controlsManager.isActive){const{ndcX:e,ndcY:n}=this._eventToNDC(t);if("perspective"!==this.cameraManager.activeView){const i=t.deltaY>0?.9:1.1;this.controlsManager.zoomOrthoAtCursor(i,e,n),this.renderThreeD()}else{const i=Math.pow(.999,-t.deltaY);this.controlsManager.dollyAtCursor(i,e,n),this.renderThreeD()}return t.stopPropagation(),!0}return!1}onDblClick(t){if(!this.controlsManager.isActive)return!1;const e=this._host,n=this.cameraManager.activeCamera;if(!n||!this.sceneManager.scene)return this.controlsManager.reset(),!0;if(e?.app?.isEditMode&&e.root){if(this.vertexGizmoManager.isAttached){const t=this.eventManager.mouse;if(this.vertexGizmoManager.onDblClick(t,n))return this._host?.invalidate(),!0}const t=this.eventManager.getObjectByRaycast(n,this.sceneManager.scene),e=t?.userData?.context?.component;if(e?.hasTextProperty)return Zh(e,this.rendererManager,()=>{this.renderThreeD()}),!0}return this.controlsManager.reset(),t.stopPropagation(),!0}pinResetPosition(){this.controlsManager.pinResetPosition()}onDragStart(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(t.stopPropagation(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.bookmarkManager.stopPlay(),this.controlsManager.onDragStart(t),t.stopPropagation(),!0))}onDragMove(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointermove"),t.stopPropagation(),!0):(this.controlsManager.onDragMove(t),t.stopPropagation(),!0))}onDragEnd(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointerup"),t.stopPropagation(),!0):(this.controlsManager.onDragEnd(t),t.stopPropagation(),!0))}onTouchStart(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchStart(t),t.stopPropagation(),!0)}onPan(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchMove(t),t.stopPropagation(),!0)}onTouchEnd(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchEnd(t),t.stopPropagation(),!0)}onKeyDown(t){return!t.isComposing&&229!==t.keyCode&&(!!this.controlsManager.isActive&&(!!this._handleEscapeKey(t)||(!(!this._host?.app?.isEditMode||!this._handleEditModeKey(t))||(!!this._handleCursorHintKey(t)||(!!this._handleCameraAndViewKey(t)||(!!this._handlePlaybackKey(t)||(!t.shiftKey||t.ctrlKey||t.metaKey||t.altKey||"KeyB"!==t.code||!this._host?.app?.isEditMode?(this.controlsManager.onKeyDown(t),t.ctrlKey||t.metaKey||t.stopPropagation(),!0):(this.onBookmarkEditToggle?.(),t.preventDefault(),!0))))))))}_handleEscapeKey(t){if("Escape"!==t.key&&"Escape"!==t.code)return!1;if(this.placementManager.isActive&&this._host?.root)return this._host.root.trigger("addstop"),t.stopPropagation(),!0;const e=this._host?.app,n=this._host?.root;return e&&4===e.mode?(n?.trigger("stylepastestop"),!0):e&&5===e.mode?(n?.trigger("databindpastestop"),!0):!(!e?.isEditMode||!n)&&(this.gizmoManager.detach(),n.selected=[],!0)}_handleEditModeKey(t){const e=this._host.root;if(t.metaKey||t.ctrlKey)switch(t.code){case"KeyZ":{const n=this._host?.app?.commander,i=(e?.selected||[]).filter(t=>t!==this._host).map(t=>t.state?.id).filter(Boolean);if(t.shiftKey?n?.redo():n?.undo(),e&&i.length>0){const t=i.map(t=>e.findById(t)).filter(Boolean);t.length>0&&(e.selected=t)}return t.preventDefault(),!0}case"KeyC":return e&&(this._clipboard=zl.call(e)),t.preventDefault(),!0;case"KeyX":return e&&(this._clipboard=Il.call(e)),t.preventDefault(),!0;case"KeyV":return e&&this._clipboard&&Ll.call(e,this._clipboard),t.preventDefault(),!0;case"KeyD":return e&&(this._clipboard=zl.call(e),this._clipboard&&Ll.call(e,this._clipboard)),t.preventDefault(),!0;default:return!1}if("Enter"===t.code||"NumpadEnter"===t.code){const n=e?.selected;if(1===n?.length&&n[0].hasTextProperty)return Zh(n[0],this.rendererManager,()=>{this.renderThreeD()}),t.preventDefault(),!0}switch(t.code){case"KeyW":return this.setGizmoMode("translate"),!0;case"KeyE":return this.setGizmoMode("rotate"),!0;case"KeyR":return this.setGizmoMode("scale"),!0;case"Delete":case"Backspace":return e&&kl.call(e),!0}return this._handleArrowKeyMove(t,e)}_handleArrowKeyMove(t,e){const n=e?.selected;if(!n||0===n.length)return!1;const i=t.shiftKey?this._host.MPP||10:1;let r;switch(t.code){case"ArrowLeft":r={x:-i,y:0};break;case"ArrowRight":r={x:i,y:0};break;case"ArrowUp":r={x:0,y:-i};break;case"ArrowDown":r={x:0,y:i}}return!!r&&(il.around(this._host.app.commander,()=>{n.forEach(t=>{t.stuck||t.move(r,!1)})}),t.preventDefault(),t.stopPropagation(),!0)}_handleCursorHintKey(t){return!(t.repeat||!this._host?.app?.isEditMode)&&("AltLeft"===t.code||"AltRight"===t.code?(this._host?.element&&(this._host.element.style.cursor="grab"),!0):("ShiftLeft"===t.code||"ShiftRight"===t.code)&&(this._host?.element&&(this._host.element.style.cursor=this.gizmoManager.isEngaged?"grab":"crosshair"),!0))}_handleCameraAndViewKey(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return!1;switch(t.code){case"KeyQ":case"Digit0":return this._host?.toggleThreeD?.(),t.preventDefault(),!0;case"Digit1":return this.setCameraView("perspective"),t.preventDefault(),!0;case"Digit2":return this.setCameraView("top"),t.preventDefault(),!0;case"Digit3":return this.setCameraView("front"),t.preventDefault(),!0;case"Digit4":return this.setCameraView("back"),t.preventDefault(),!0;case"Digit5":return this.setCameraView("right"),t.preventDefault(),!0;case"Digit6":return this.setCameraView("left"),t.preventDefault(),!0;case"KeyH":return this.onHelpToggle?.(),t.preventDefault(),!0;case"KeyB":return this.onBookmarkNavToggle?.(),t.preventDefault(),!0;case"KeyF":return this.onSearchToggle?.(),t.preventDefault(),!0;case"KeyD":return this.onDataBindingToggle?.(),t.preventDefault(),!0;case"KeyM":return this.onMonitorToggle?.(),t.preventDefault(),!0}return!1}_handlePlaybackKey(t){return!(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)&&("KeyP"!==t.code||this._host?.app?.isEditMode?"Space"===t.code&&this._host?.app?.isEditMode?(this._isSpacePanning=!0,this._beforeSpaceMode=this._host.app.mode,this._host.app.mode=2,this._host?.element&&(this._host.element.style.cursor="grab"),t.preventDefault(),!0):"Space"!==t.code||this._host?.app?.isEditMode?"KeyO"===t.code&&!this._host?.app?.isEditMode&&(this.bookmarkManager.resetPlay(),this.bookmarkManager.toggleOrbitRotation(this.controlsManager),t.preventDefault(),!0):(this.bookmarkManager.isOrbitRotating||this.bookmarkManager.isOrbitPaused?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):(this.bookmarkManager.isPlaying||this.bookmarkManager.lastPlayProgress>=0)&&this.togglePlay(),t.preventDefault(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.restartPlay(),t.preventDefault(),!0))}_onKeyUp(t){return"AltLeft"===t.code||"AltRight"===t.code||"ShiftLeft"===t.code||"ShiftRight"===t.code?(this._host?.element&&!this._isSpacePanning&&(this._host.element.style.cursor=""),!0):!("Space"!==t.code||!this._isSpacePanning)&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0),this._host?.element&&(this._host.element.style.cursor=""),t.preventDefault(),!0)}onPinch(t){if(this.controlsManager.isActive){if("perspective"!==this.cameraManager.activeView){const e=this.cameraManager.activeCamera,n=t.scale||1;e.zoom=Math.max(.1,Math.min(20,e.zoom*n)),e.updateProjectionMatrix(),this.controlsManager.markCameraChanged(),this.renderThreeD()}else{const e=t.scale||1;Math.abs(e-1)>.01&&(this.controlsManager.dollyAtCursor(1/e,0,0),this.renderThreeD())}return t.stopPropagation(),!0}return!1}onDoubleTap(){this.controlsManager.reset()}getCameraState(){const t=this._host;if(!t)return null;const e=this.cameraManager.camera;if(!e)return null;const{width:n,height:i}=t.bounds,r=Math.floor(Math.min(n,i))||1;return{view:this.cameraManager.activeView,cameraX:e.position.x/(n||1),cameraY:e.position.z/(i||1),cameraZ:e.position.y/r}}getCameraWorldState(){const t=this.cameraManager.camera;if(!t)return null;const e=this.controlsManager.target;return{position:{x:t.position.x,y:t.position.y,z:t.position.z},target:{x:e.x,y:e.y,z:e.z}}}captureSessionState(){const t=this.cameraManager.activeView,e=this.cameraManager.camera,n=this.controlsManager.target,i={view:t};return e&&(i.perspPosition={x:e.position.x,y:e.position.y,z:e.position.z}),i.orbitTarget={x:n.x,y:n.y,z:n.z},i}captureViewportInfo(){const t=this.cameraManager.activeCamera,e=this.controlsManager.target.clone();let n=0,i=0;if(t?.fov){i=2*t.position.distanceTo(e)*Math.tan(t.fov*Math.PI/180/2),n=i*(t.aspect||1)}return{target:e,visibleWidth:n,visibleHeight:i}}restoreSessionState(t){"perspective"!==t.view&&this.setCameraView(t.view,{render:!1});const n=this.cameraManager.camera;n&&t.perspPosition&&n.position.set(t.perspPosition.x,t.perspPosition.y,t.perspPosition.z),t.orbitTarget&&this.controlsManager.restoreTarget(new e.Vector3(t.orbitTarget.x,t.orbitTarget.y,t.orbitTarget.z))}saveCameraToSlot(t){if(!this._host?.app?.isEditMode)return;const n=this.cameraManager.camera;if(!n)return;if("perspective"!==this.cameraManager.activeView)return;const i=this.controlsManager.target,r=n.position;let s=i.x,o=i.y,a=i.z;if(r.distanceTo(i)<1){const t=new e.Vector3(0,0,-1).applyQuaternion(n.quaternion);s=r.x+1*t.x,o=r.y+1*t.y,a=r.z+1*t.z}const c={position:{x:r.x,y:r.y,z:r.z},target:{x:s,y:o,z:a}};this.bookmarkManager.saveSlot(t,c),this._host?.app?.isEditMode&&this._host?.set?.("cameraBookmarks",this.bookmarkManager.exportSlots()),this.onBookmarkChanged?.()}positionCameraForViewport(t,n,i,r,s){const o=this.cameraManager.activeCamera;if(!o?.position)return;const a=(o.fov||45)*Math.PI/180,c=o.aspect||1,l=r/2/Math.tan(a/2),h=i/2/(c*Math.tan(a/2)),d=Math.max(l,h),u=s?.orbitTarget?.y??0,p=new e.Vector3(t,u,n);let f;if(s?.perspPosition&&s?.orbitTarget){const t=new e.Vector3(s.perspPosition.x,s.perspPosition.y,s.perspPosition.z),n=new e.Vector3(s.orbitTarget.x,s.orbitTarget.y,s.orbitTarget.z);f=t.sub(n).normalize()}else f=o.position.clone().normalize();o.position.copy(p.clone().add(f.multiplyScalar(d)));try{this.controlsManager.restoreTarget(p)}catch{o.lookAt(p)}this._host?.invalidate()}centerToComponent(t,n){const i=this.cameraManager.activeCamera;if(!i)return;const r=new e.Vector3,s=t._realObject;if(s?.object3d)s.object3d.getWorldPosition(r);else{const{x:e=0,y:n=0}=t.center,{width:i=0,height:s=0}=t.parent?.bounds??{};r.set(e-i/2,0,n-s/2)}const o=this.controlsManager.target,a=i.position.clone().sub(o),c=r.clone().add(a);if(!n)return i.position.copy(c),this.controlsManager.restoreTarget(r),void this._host?.invalidate();const l=i.position.clone(),h=o.clone(),d=performance.now(),u=()=>{const t=performance.now()-d,e=Math.min(t/800,1),n=e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2;i.position.lerpVectors(l,c,n);const s=h.clone().lerp(r,n);this.controlsManager.restoreTarget(s),this._host?.invalidate(),e<1&&requestAnimationFrame(u)};requestAnimationFrame(u)}animateToSlot(t){const e=this.cameraManager.camera;e&&(this.bookmarkManager.isPlaying&&this.bookmarkManager.stopPlay(),"perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.animateToSlot(t,e,this.controlsManager),this.bookmarkManager.setProgressForSlot(t))}scrubPath(t){const e=this.cameraManager.camera;if(!e)return;const n=this.bookmarkManager.evaluatePath(t);n&&(e.position.copy(n.position),this.controlsManager.restoreTarget(n.target),this._host?.invalidate())}togglePlay(t=-1){const e=this.cameraManager.camera;if(e){if("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.isPlaying)return this.bookmarkManager.stopPlay(),void(this._pathVisible&&this.showBookmarkPath());this.hideBookmarkPath(),this.bookmarkManager.startPlay(e,this.controlsManager,2e3,1200,t)}}restartPlay(){const t=this.cameraManager.camera;t&&("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.stopPlay(),this.hideBookmarkPath(),this.bookmarkManager.startPlay(t,this.controlsManager,2e3,1200,-1,!0))}startAutoPlay(t){"orbit"===t?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):"play"===t&&this.togglePlay()}showBookmarkPath(){this._pathVisible=!0,this.hideBookmarkPath();const t=this.sceneManager.scene;if(!t)return;const n=this.bookmarkManager.getPlayableSlots();if(0===n.length)return;const i=[];for(const t of n){const n=this.bookmarkManager.getSlot(t);n&&i.push(new e.Vector3(n.position.x,n.position.y,n.position.z))}if(i.length>=2){let n=0;for(let t=1;t<i.length;t++)n+=i[t].distanceTo(i[t-1]);const r=n/(i.length-1),s=i.length>=3?new e.CatmullRomCurve3(i,!0,"centripetal").getPoints(30*i.length):i,o=(new e.BufferGeometry).setFromPoints(s),a=new e.LineDashedMaterial({color:4890367,dashSize:.06*r,gapSize:.03*r,opacity:.5,transparent:!0,depthTest:!1});this._pathLine=new e.Line(o,a),this._pathLine.computeLineDistances(),this._pathLine.renderOrder=9999,t.add(this._pathLine)}let r;if(i.length>=2){let t=0;for(let e=1;e<i.length;e++)t+=i[e].distanceTo(i[e-1]);r=t/(i.length-1)*.08}else{const t=this.bookmarkManager.getSlot(n[0]);r=.08*(t?new e.Vector3(t.position.x,t.position.y,t.position.z).distanceTo(new e.Vector3(t.target.x,t.target.y,t.target.z)):10)}this._pathMarkers=new e.Group,this._pathMarkers.renderOrder=9999;const s=new e.MeshBasicMaterial({color:4890367,opacity:.6,transparent:!0,depthTest:!1}),o=new e.MeshBasicMaterial({color:4890367,opacity:.15,transparent:!0,depthTest:!1,side:e.DoubleSide});for(const t of n){const n=this.bookmarkManager.getSlot(t);if(!n)continue;const i=new e.Vector3(n.position.x,n.position.y,n.position.z),a=new e.Vector3(n.target.x,n.target.y,n.target.z),c=(new e.Vector3).subVectors(a,i).normalize(),l=new e.Group;l.position.copy(i);const h=(new e.Matrix4).lookAt(new e.Vector3(0,0,0),c,new e.Vector3(0,1,0));l.quaternion.setFromRotationMatrix(h);const d=.2*r,u=new e.BoxGeometry(1.2*d,.8*d,d),p=new e.Mesh(u,s);p.renderOrder=9999,l.add(p);const f=Math.max(.06*i.distanceTo(a),.5*d),g=.35*f,m=9*g/16,y=new e.BufferGeometry,b=[0,0,0,-g,m,-f,g,m,-f,g,-m,-f,-g,-m,-f],v=[0,1,2,0,2,3,0,3,4,0,4,1];y.setAttribute("position",new e.Float32BufferAttribute(b,3)),y.setIndex(v),y.computeVertexNormals();const _=new e.Mesh(y,o);_.position.z=.5*-d,_.renderOrder=9999,l.add(_);const x=new Float32Array([0,0,0,-g,m,-f,0,0,0,g,m,-f,0,0,0,g,-m,-f,0,0,0,-g,-m,-f,-g,m,-f,g,m,-f,g,m,-f,g,-m,-f,g,-m,-f,-g,-m,-f,-g,-m,-f,-g,m,-f]),w=new e.BufferGeometry;w.setAttribute("position",new e.BufferAttribute(x,3));const M=new e.LineSegments(w,new e.LineBasicMaterial({color:4890367,opacity:.5,transparent:!0,depthTest:!1}));M.position.z=.5*-d,M.renderOrder=9999,l.add(M),l.userData.bookmarkSlotIndex=t,this._pathMarkers.add(l)}t.add(this._pathMarkers),this._host?.invalidate()}hideBookmarkPath(t=!1){t&&(this._pathVisible=!1);const e=this.sceneManager.scene;if(this._pathLine&&(e?.remove(this._pathLine),this._pathLine.geometry.dispose(),this._pathLine.material.dispose(),this._pathLine=void 0),this._pathMarkers){e?.remove(this._pathMarkers);const t=new Set;this._pathMarkers.traverse(e=>{e.geometry&&e.geometry.dispose();const n=e.material;n&&!t.has(n)&&(n.dispose(),t.add(n))}),this._pathMarkers=void 0}this._host?.invalidate()}initBookmarks(){const t=this._host;if(!t)return;const e=t.state.cameraBookmarks;Array.isArray(e)&&this.bookmarkManager.importSlots(e),this.bookmarkManager.setCallbacks(()=>this._host?.invalidate())}onchange(t){if(t.hasOwnProperty("autoRotate")&&this.controlsManager.setAutoRotate(t.autoRotate),t.hasOwnProperty("cameraFloorConstraint")){const e=!this._host?.app?.isEditMode;this.controlsManager.setFloorConstraint(e&&!!t.cameraFloorConstraint)}if(t.hasOwnProperty("fov")||t.hasOwnProperty("near")||t.hasOwnProperty("far")){const t=this._host;if(t){const{near:e,far:n,fov:i}=t.state;this.cameraManager.updateProperties({near:e,far:n,fov:i}),this.controlsManager.markCameraChanged()}}t.hasOwnProperty("exposure")&&(this.rendererManager.setExposure(Number(t.exposure)||1),this.renderThreeD());let e=!1;if((t.hasOwnProperty("hemiIntensity")||t.hasOwnProperty("hemiSkyColor")||t.hasOwnProperty("hemiGroundColor"))&&(this.lightManager.updateHemisphere({intensity:t.hemiIntensity,skyColor:t.hemiSkyColor,groundColor:t.hemiGroundColor}),e=!0),t.hasOwnProperty("dirLightEnabled")){const n=this._host;n&&this.lightManager.setDirectionalEnabled(t.dirLightEnabled,{color:n.state.dirLightColor,intensity:n.state.dirLightIntensity}),e=!0}if((t.hasOwnProperty("dirLightColor")||t.hasOwnProperty("dirLightIntensity"))&&(this.lightManager.updateDirectional({color:t.dirLightColor,intensity:t.dirLightIntensity}),e=!0),t.hasOwnProperty("dirLightFollowCamera")){if(this.lightManager.setDirectionalFollowCamera(!1!==t.dirLightFollowCamera),!1===t.dirLightFollowCamera){const t=this._host?.state;this.lightManager.setDirectionalAngle(t?.dirLightAzimuth??30,t?.dirLightElevation??45)}e=!0}if(t.hasOwnProperty("dirLightAzimuth")||t.hasOwnProperty("dirLightElevation")){const n=this._host?.state;!1===n?.dirLightFollowCamera&&this.lightManager.setDirectionalAngle(t.dirLightAzimuth??n?.dirLightAzimuth??30,t.dirLightElevation??n?.dirLightElevation??45),e=!0}if(t.hasOwnProperty("dirShadowEnabled")||t.hasOwnProperty("dirShadowBias")){const n=this.lightManager.dirLight;n&&(t.hasOwnProperty("dirShadowEnabled")&&(n.castShadow=!1!==t.dirShadowEnabled),t.hasOwnProperty("dirShadowBias")&&(n.shadow.bias=t.dirShadowBias??-5e-4)),e=!0}e&&this.renderThreeD(),(t.hasOwnProperty("fillStyle")||t.hasOwnProperty("floorMaterial3d"))&&(this.sceneManager.updateFloor(this._host),this.renderThreeD()),(t.hasOwnProperty("sky")||t.hasOwnProperty("skyColor"))&&(this.sceneManager.setSky(this._host.state.sky,this._host.state.skyColor),this.renderThreeD()),t.hasOwnProperty("placement")&&(this.sceneManager.updateFloor(this._host),this._cascadeUpdateTransform(this._host),this.renderThreeD())}_cascadeUpdateTransform(t){const e=t?._realObject;e&&e.updateTransform?.();const n=t?.components;if(n)for(const t of n)this._cascadeUpdateTransform(t)}get domElement(){return this.rendererManager.domElement}getRendererSize(){return this.rendererManager.getSize()}showWebglNoSupportText(t,e,n){t.save(),t.font=e/20+"px Arial",t.textAlign="center",t.fillText("WebGL no support",e/2-e/40,n/2),t.restore()}showDebugFPS(t){t.font="100px Arial",t.textAlign="center",t.fillStyle="black",t.globalAlpha=.5,t.fillText(String(vh()),100,100)}get decoratorOutlines(){return this._decoratorOutlines}addOutline(t){this._decoratorOutlines.add(t),this._syncOutlinePass(),this._host?.invalidate()}removeOutline(t){this._decoratorOutlines.delete(t),this._syncOutlinePass(),this._host?.invalidate()}clearOutlines(){this._decoratorOutlines.clear(),this._syncOutlinePass(),this._host?.invalidate()}addArrow(t,n,i,r={}){this.removeArrow(t);const s=n._realObject,o=i._realObject;if(!s?.object3d||!o?.object3d)return;const a=new e.Vector3,c=new e.Vector3;s.object3d.getWorldPosition(a),o.object3d.getWorldPosition(c),a.y+=1,c.y+=1;const l=this.rendererManager.getSize(),h=Ah(a,c,r,new e.Vector2(l.width,l.height));h.name=`arrow-${t}`,h.userData._arrowStyle=r,this.sceneManager.scene?.add(h),this._arrows.set(t,h),this._host?.invalidate()}removeArrow(t){const n=this._arrows.get(t);n&&(n.traverse(t=>{if(t instanceof p)return t.geometry.dispose(),void t.material.dispose();if(t instanceof e.Sprite){const e=t.material.map;if(e){e.dispose();const t=e.source?.data;t instanceof HTMLCanvasElement&&(t.width=0,t.height=0)}return void t.material.dispose()}(t instanceof e.Mesh||t instanceof e.Line)&&(t.geometry.dispose(),t.material instanceof e.Material&&t.material.dispose())}),n.removeFromParent(),this._arrows.delete(t),this._host?.invalidate())}clearArrows(){for(const t of this._arrows.keys())this.removeArrow(t)}updateArrow(t,e,n){const i=this._getArrowStyle(t);i&&this.addArrow(t,e,n,i)}_getArrowStyle(t){const e=this._arrows.get(t);return e?e.userData._arrowStyle??null:null}highlightBookmarkMarker(t){this._highlightedMarkerIndex!==t&&(this._highlightedMarkerIndex=t,this._syncOutlinePass(),this._host?.invalidate())}clearBookmarkMarkerHighlight(){-1!==this._highlightedMarkerIndex&&(this._highlightedMarkerIndex=-1,this._syncOutlinePass(),this._host?.invalidate())}_syncOutlinePass(){const t=[...this._selectionOutlineObjects];for(const e of this._decoratorOutlines){const n=e._realObject;n?.object3d&&!t.includes(n.object3d)&&t.push(n.object3d)}if(this._highlightedMarkerIndex>=0&&this._pathMarkers)for(const e of this._pathMarkers.children)if(e.userData.bookmarkSlotIndex===this._highlightedMarkerIndex){e.traverse(e=>{e.isMesh&&t.push(e)});break}this.rendererManager.setOutlineObjects(t)}_handleSelectionChanged(t){const e=t.filter(t=>t!==this._host&&t._realObject);if(e.length>=1){const t=e[0]._realObject;t?.object3d&&t.gizmoTransformable?this.gizmoManager.attached&&this.gizmoManager.attach(t.object3d):this.gizmoManager.detach()}else this.gizmoManager.detach();const n=e.filter(t=>t.mutable&&t.path);n.length>0&&this.sceneManager.scene?this.vertexGizmoManager.attachMultiple(n,this.sceneManager.scene,this._host?.app?.commander):this.vertexGizmoManager.detach(),this._updateSelectionOutline(e),this._host?.invalidate()}_updateSelectionOutline(t){this._selectionOutlineObjects=[];for(const e of t){const t=e._realObject;t?.object3d&&this._selectionOutlineObjects.push(t.object3d)}this._syncOutlinePass()}}yc.register("three",{reflow:function(t){},capturables:function(t){return t.state.threed?[]:t.components},drawables:function(t){return t.state.threed?[]:t.components},isStuck:function(t){return!1}});const kd={x:1,y:1},Ad={x:0,y:0},Ed='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M4 5l12-1v12l-12-1z"/>\n <circle cx="10" cy="10" r="1.5"/>\n</svg>',Cd='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <rect x="4" y="4" width="12" height="12" rx="1"/>\n <path d="M10 2v2M10 16v2"/>\n <path d="M10 7v3l2-1.5" opacity="0.5"/>\n</svg>',Td='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M4 14l2-10h8l2 10z"/>\n <path d="M6 4h8" stroke-width="2"/>\n</svg>',Pd='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M4 6l2 10h8l2-10z"/>\n <path d="M6 16h8" stroke-width="2"/>\n</svg>',Dd='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M6 4l10 2v8l-10 2z"/>\n <path d="M16 6v8" stroke-width="2"/>\n</svg>',Od='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M14 4L4 6v8l10 2z"/>\n <path d="M4 6v8" stroke-width="2"/>\n</svg>',zd={mutable:!1,resizable:!0,rotatable:!1,properties:[{type:"number",label:"width",name:"width"},{type:"number",label:"height",name:"height"},{type:"select",label:"fit-mode",name:"fitMode",property:{options:["ratio","both","width","height","center","none"]}}]};class Id extends Nc{constructor(){super(...arguments),this._threeDUserDeactivated=!1}get nature(){return zd}get is3dMode(){return!!this._threeCapability?.isInitialized}is3dContainer(){return this.is3dMode}get gizmoMode(){return this._threeCapability?.gizmoMode}setGizmoMode(t){this._threeCapability?.setGizmoMode(t)}get scene3d(){return this._threeCapability?.scene3d}get renderer3d(){return this._threeCapability?.renderer3d}get activeCamera3d(){return this._threeCapability?.activeCamera}get mixer(){return this._threeCapability?.mixer}addArrow3D(t,e,n,i){this._threeCapability?.addArrow(t,e,n,i)}removeArrow3D(t){this._threeCapability?.removeArrow(t)}clearArrows3D(){this._threeCapability?.clearArrows()}_buildLightingConfig(){const t=this.state,e={hemisphere:{skyColor:t.hemiSkyColor||"#ffffff",groundColor:t.hemiGroundColor||"#444444",intensity:t.hemiIntensity??4}};if(!1!==t.dirLightEnabled){const n=!1!==t.dirLightFollowCamera;if(e.directional={color:t.dirLightColor||"#ffffff",intensity:t.dirLightIntensity??2,attachToCamera:n,castShadow:!1!==t.dirShadowEnabled,shadowMapSize:t.dirShadowMapSize??2048,shadowBias:t.dirShadowBias??-5e-4},!n){const n=(t.dirLightAzimuth??30)*Math.PI/180,i=(t.dirLightElevation??45)*Math.PI/180,r=1e3;e.directional.position=[r*Math.cos(i)*Math.sin(n),r*Math.sin(i),r*Math.cos(i)*Math.cos(n)]}}return e}_hide2DLayers(){this.canvas&&(this.canvas.style.display="none"),this._overlay&&(this._overlay.style.display="none"),this._auxCanvas&&(this._auxCanvas.style.display="none"),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="none");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="none")}get _hasZoomHandler(){return(this.root?.model?.handlers||[]).includes("zoom-handler")}get _needsViewportSync(){return!!this.app?.isEditMode||this._hasZoomHandler}_activateThreeD(t=!1){this._threeCapability&&this._deactivateThreeD(),t&&!this._needsViewportSync&&(this._saved2DViewport={scale:{...this.get("scale")||{x:1,y:1}},translate:{...this.get("translate")||{x:0,y:0}}}),this._threeCapability=new Sd,this._threeCapability.init(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),this._hide2DLayers(),this.root?.transitionEffect?.dispose();const e=Bs.getInstance(),n=[];this.decoratorOverlay&&(n.push(...e.getTargetsWithType(this.decoratorOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorOverlay,"border-highlighting")),this.decoratorAuxOverlay&&(n.push(...e.getTargetsWithType(this.decoratorAuxOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorAuxOverlay,"border-highlighting"));for(const t of n)this._threeCapability.addOutline(t);if(this._threeCapability.domElement&&this.element){const t=this._threeCapability.domElement;t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.pointerEvents="none",t.setAttribute("scene","model-layer-webgl");const e=this._decoratorOverlay||this.element.firstChild;this.element.insertBefore(t,e)}if(this._threeCapability.buildOverlays(),t&&this._needsViewportSync){const t=this.get("scale")||{x:1};this._2dScaleBeforeThreeD=t.x||1,this._initCameraFrom2DViewport();const e=this._threeCapability?.captureViewportInfo();e&&(this._initialVisibleHeight=e.visibleHeight)}else if(this._lastCameraState)this._threeCapability.restoreSessionState(this._lastCameraState);else{const t=this.model.initialCameraView;t&&"perspective"!==t&&this._threeCapability.setCameraView(t,{render:!1})}if(this._pendingCameraView&&(this._threeCapability.setCameraView(this._pendingCameraView,{render:!1}),delete this._pendingCameraView),this._threeCapability.initBookmarks(),!this.app?.isEditMode){const t=this.model?.cameraAutoPlay;"orbit"!==t&&"play"!==t||this._threeCapability.startAutoPlay(t)}this.app?.isEditMode&&this._createToolbar(),this._registerPopupCallbacks();const i=this.root;i?.selected?.length>0&&this._threeCapability._handleSelectionChanged(i.selected),this._resizeThreeD(!0),this.element&&"function"==typeof this.element.focus&&this.element.focus()}_createToolbar(){if(!this.element)return;this._removeToolbar();const t=!!this._threeCapability,e=document.createElement("div");e.setAttribute("scene","threed-toolbar"),e.style.cssText=["position:absolute","top:12px","left:12px","display:flex","flex-direction:column","gap:1px","padding:4px","background:rgba(30,30,30,0.92)","border:1px solid rgba(255,255,255,0.08)","border-radius:8px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 16px rgba(0,0,0,0.4),inset 0 1px 0 rgba(255,255,255,0.05)","user-select:none"].join(";");const n=["width:32px","height:32px","display:flex","align-items:center","justify-content:center","border-radius:5px","cursor:pointer","transition:all 0.12s ease","position:relative"].join(";"),i=(t,e)=>{const i=document.createElement("div");return i.innerHTML=t,i.title=e,i.style.cssText=n,this._applyButtonStyle(i,!1),i.addEventListener("mouseenter",()=>{i.dataset.active||(i.style.background="rgba(255,255,255,0.1)")}),i.addEventListener("mouseleave",()=>{this._applyButtonStyle(i,!!i.dataset.active)}),i},r=()=>{const t=document.createElement("div");return t.style.cssText="height:1px;margin:3px 4px;background:rgba(255,255,255,0.1)",t},s=i(t?'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="14" height="14" rx="1.5"/>\n <line x1="3" y1="10" x2="17" y2="10" opacity="0.4"/>\n <line x1="10" y1="3" x2="10" y2="17" opacity="0.4"/>\n </svg>':'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2l7 4v8l-7 4-7-4V6l7-4z"/>\n <path d="M10 10l7-4M10 10v8M10 10L3 6"/>\n </svg>',t?"2D Mode":"3D Mode");if(this._applyToggleStyle(s,t),s.addEventListener("mouseenter",()=>{s.style.background=t?"rgba(255,160,60,0.35)":"rgba(255,160,60,0.25)"}),s.addEventListener("mouseleave",()=>{this._applyToggleStyle(s,t)}),s.addEventListener("click",()=>{this.toggleThreeD()}),e.appendChild(s),!t)return e.addEventListener("mousedown",t=>t.stopPropagation()),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),void(this._toolbar=e);e.appendChild(r());const o=this._threeCapability,a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:1px";const c=o.getCameraState()?.view??"perspective",l=[{view:"perspective",icon:Ed,title:"Perspective"},{view:"top",icon:Cd,title:"Top"},{view:"front",icon:Td,title:"Front"},{view:"back",icon:Pd,title:"Back"},{view:"right",icon:Dd,title:"Right"},{view:"left",icon:Od,title:"Left"}],h=[];for(const{view:t,icon:e,title:n}of l){const r=i(e,n);r.dataset.view=t,t===c&&(this._applyButtonStyle(r,!0),r.dataset.active="1"),r.addEventListener("click",()=>{this._threeCapability?.setCameraView(t)}),h.push(r),a.appendChild(r)}a.appendChild(r());const d=i('<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2 L13 5 L12 10 L15 13 L5 13 L8 10 L7 5 Z"/>\n <line x1="10" y1="13" x2="10" y2="18"/>\n </svg>',"Pin Camera View");d.addEventListener("click",()=>{const t=this._threeCapability?.getCameraState();t&&(this.set("cameraX",t.cameraX),this.set("cameraY",t.cameraY),this.set("cameraZ",t.cameraZ),this._threeCapability?.pinResetPosition())}),a.appendChild(d),e.appendChild(a),this._cameraButtons=h,o.onGizmoAttachChanged=t=>{this.root?.trigger("gizmoattach",t)},o.onCameraViewChanged=t=>{this._updateCameraButtons(t)},o.onGizmoModeChanged=t=>{this.root?.trigger("gizmomode",t)},e.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),this._toolbar=e}_applyToggleStyle(t,e){e?(t.style.background="rgba(255,140,40,0.3)",t.style.color="#ffaa44",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.5)"):(t.style.background="rgba(255,140,40,0.15)",t.style.color="#cc8833",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.3)")}_applyButtonStyle(t,e){e?(t.style.background="rgba(74,158,255,0.25)",t.style.color="#4a9eff",t.style.boxShadow="inset 0 0 0 1.5px rgba(74,158,255,0.5)",t.dataset.active="1"):(t.style.background="transparent",t.style.color="rgba(255,255,255,0.55)",t.style.boxShadow="none",delete t.dataset.active)}_updateCameraButtons(t){this._cameraButtons?.forEach(e=>{this._applyButtonStyle(e,e.dataset.view===t)})}_registerPopupCallbacks(){const t=this._threeCapability;t&&(t.onHelpToggle=()=>this._toggleHelpPanel(),t.onSearchToggle=()=>this.onSearchToggle?.(),t.onDataBindingToggle=()=>this.onDataBindingToggle?.(),t.onMonitorToggle=()=>this.onMonitorToggle?.(),t.onBookmarkNavToggle=()=>this._toggleBookmarkNav(),t.onBookmarkEditToggle=()=>this._toggleBookmarkEdit())}_closeFloatingPopup(){this._floatingPopupCloseHandler&&(this.target?.removeEventListener("mousedown",this._floatingPopupCloseHandler,!0),this._floatingPopupCloseHandler=void 0),this._floatingPopup?.parentNode&&this._floatingPopup.parentNode.removeChild(this._floatingPopup),this._floatingPopup=void 0}_showFloatingPopup(t,e=!1){this._closeFloatingPopup(),this._floatingPopup=t,e||(this._floatingPopupCloseHandler=e=>{t.contains(e.target)||this._closeFloatingPopup()},setTimeout(()=>{this.target?.addEventListener("mousedown",this._floatingPopupCloseHandler,!0)},0)),t.addEventListener("mousedown",t=>{t.stopPropagation();const e=t.target?.tagName;"INPUT"!==e&&"TEXTAREA"!==e&&"SELECT"!==e&&t.preventDefault()}),t.addEventListener("mouseup",t=>t.stopPropagation()),this._makePopupDraggable(t),this.target.appendChild(t)}_makePopupDraggable(t){let e=0,n=0,i=0,r=0;const s=s=>{const o=s.clientX-e,a=s.clientY-n;t.style.left=i+o+"px",t.style.top=r+a+"px"},o=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",s),t.removeEventListener("pointerup",o),t.style.cursor=""};t.addEventListener("pointerdown",a=>{const c=a.target,l=c.tagName?.toLowerCase();if("button"===l||"input"===l||"select"===l||"pointer"===c.style.cursor)return;if(c.closest("[data-drag-handle]"))return;const h=t.getBoundingClientRect(),d=t.parentElement.getBoundingClientRect();i=h.left-d.left,r=h.top-d.top,t.style.left=i+"px",t.style.top=r+"px",t.style.right="auto",t.style.bottom="auto",t.style.transform="none",e=a.clientX,n=a.clientY,t.style.cursor="grabbing",t.setPointerCapture(a.pointerId),t.addEventListener("pointermove",s),t.addEventListener("pointerup",o)})}_toggleHelpPanel(){if("help"===this._floatingPopup?.dataset.popupType)return void this._closeFloatingPopup();const t=!!this.app?.isEditMode,e=document.createElement("div");e.dataset.popupType="help",e.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","max-width:min(560px, calc(100% - 40px))","max-height:calc(100% - 40px)","overflow-y:auto","padding:16px 20px","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.08)","border-radius:10px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 20px rgba(0,0,0,0.5)","user-select:none","color:rgba(255,255,255,0.85)","font:12px/1.6 -apple-system,BlinkMacSystemFont,sans-serif","z-index:200"].join(";");const n=document.createElement("div");n.textContent="×",n.style.cssText="position:absolute;top:8px;right:12px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",n.addEventListener("click",()=>this._closeFloatingPopup()),n.addEventListener("mouseenter",()=>{n.style.color="#fff"}),n.addEventListener("mouseleave",()=>{n.style.color="rgba(255,255,255,0.4)"}),e.appendChild(n);const i=document.createElement("div");i.textContent="Help",i.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:12px",e.appendChild(i);const r=document.createElement("div");r.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:0 24px",e.appendChild(r);const s=[{label:"Camera",items:[{key:"1",desc:"Perspective",icon:Ed},{key:"2",desc:"Top",icon:Cd},{key:"3",desc:"Front",icon:Td},{key:"4",desc:"Back",icon:Pd},{key:"5",desc:"Right",icon:Dd},{key:"6",desc:"Left",icon:Od},{key:"0 / Q",desc:"Exit 3D"}]},{label:"Bookmarks",items:[{key:"B",desc:"Bookmark navigator"},{key:"Shift+B",desc:"Bookmark editor",editOnly:!0},{key:"P",desc:"Play tour",viewOnly:!0},{key:"O",desc:"Orbit rotation",viewOnly:!0},{key:"Space",desc:"Pan mode (edit) / Pause (view)"}]},{label:"Navigation",items:[{key:"Drag",desc:"Rotate camera"},{key:"Alt+Drag",desc:"Pan camera"},{key:"Space+Drag",desc:"Pan camera (no select)",editOnly:!0},{key:"Shift+Drag",desc:"Box select",editOnly:!0},{key:"Scroll",desc:"Dolly zoom"},{key:"DblClick",desc:"Reset camera"},{key:"Arrows",desc:"Pan camera"}]},{label:"Edit",items:[{key:"W",desc:"Move gizmo",editOnly:!0},{key:"E",desc:"Rotate gizmo",editOnly:!0},{key:"R",desc:"Scale gizmo",editOnly:!0},{key:"Ctrl+Z",desc:"Undo",editOnly:!0},{key:"Ctrl+Shift+Z",desc:"Redo",editOnly:!0},{key:"Ctrl+C/X/V",desc:"Copy / Cut / Paste",editOnly:!0},{key:"Del",desc:"Delete selected",editOnly:!0},{key:"Esc",desc:"Deselect all",editOnly:!0}]},{label:"Misc",items:[{key:"H",desc:"This help"},{key:"F",desc:"Search"}]}].map(e=>({...e,items:e.items.filter(e=>!(e.editOnly&&!t)&&(!e.viewOnly||!t))})).filter(t=>t.items.length>0),o=s.reduce((t,e)=>t+e.items.length+1,0);let a=0,c=s.length;for(let t=0;t<s.length;t++)if(a+=s[t].items.length+1,a>=o/2){c=t+1;break}const l=[s.slice(0,c),s.slice(c)];for(const t of l){const e=document.createElement("div");let n=!0;for(const i of t){if(!n){const t=document.createElement("div");t.style.cssText="height:1px;margin:8px 0;background:rgba(255,255,255,0.08)",e.appendChild(t)}n=!1;const t=document.createElement("div");t.textContent=i.label,t.style.cssText="font-size:10px;font-weight:700;text-transform:uppercase;color:rgba(255,255,255,0.45);margin:0 0 5px;letter-spacing:0.8px",e.appendChild(t);for(const t of i.items){const n=document.createElement("div");n.style.cssText="display:flex;justify-content:space-between;align-items:center;padding:2px 0;gap:12px";const i=document.createElement("span");i.style.cssText="display:inline-flex;gap:2px;flex-shrink:0";for(const e of t.key.split("+")){const n=document.createElement("kbd");if(n.textContent=e.trim(),n.style.cssText="font-size:10px;font-family:monospace;padding:1px 5px;border-radius:3px;background:rgba(255,255,255,0.08);border:1px solid rgba(255,255,255,0.12);color:rgba(255,255,255,0.65);line-height:1.4",i.appendChild(n),e!==t.key.split("+").at(-1)){const t=document.createElement("span");t.textContent="+",t.style.cssText="color:rgba(255,255,255,0.2);font-size:10px;margin:0 1px",i.appendChild(t)}}const r=document.createElement("span");if(r.style.cssText="font-size:11px;color:rgba(255,255,255,0.7);text-align:right;white-space:nowrap;display:inline-flex;align-items:center;gap:4px",r.appendChild(document.createTextNode(t.desc)),t.icon){const e=document.createElement("span");e.innerHTML=t.icon,e.style.cssText="display:inline-flex;opacity:0.6",r.appendChild(e)}n.appendChild(i),n.appendChild(r),e.appendChild(n)}}r.appendChild(e)}this._showFloatingPopup(e)}_toggleBookmarkNav(){"bookmark-nav"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-nav"):this._closeFloatingPopup()}_toggleBookmarkEdit(){"bookmark-edit"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-edit"):this._closeFloatingPopup()}_buildBookmarkPopup(t){const e=this._threeCapability;if(!e)return;const n="bookmark-nav"===t,i=!!this.app?.isEditMode,r=document.createElement("div");r.dataset.popupType=t,r.tabIndex=-1,r.style.cssText=["position:absolute",n?"bottom:12px":"top:12px","right:12px","min-width:"+(n?"140px":"200px"),"padding:10px 12px","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.08)","border-radius:10px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 20px rgba(0,0,0,0.5)","user-select:none","color:rgba(255,255,255,0.85)","font:12px/1.5 -apple-system,BlinkMacSystemFont,sans-serif","z-index:200"].join(";");const s=document.createElement("div");s.textContent="×",s.style.cssText="position:absolute;top:6px;right:10px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",s.addEventListener("click",()=>this._closeFloatingPopup()),s.addEventListener("mouseenter",()=>{s.style.color="#fff"}),s.addEventListener("mouseleave",()=>{s.style.color="rgba(255,255,255,0.4)"}),r.appendChild(s);const o=document.createElement("div");o.textContent="Bookmarks",o.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:8px;cursor:grab",r.appendChild(o);const a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:2px",r.appendChild(a);const c=e.bookmarkManager,l=()=>{i&&this.set?.("cameraBookmarks",c.exportSlots()),e.onBookmarkChanged?.()},h="border:none;background:transparent;color:inherit;cursor:pointer;padding:2px 4px;border-radius:4px;font-size:13px;line-height:1;display:flex;align-items:center;justify-content:center;width:24px;height:24px",d=t=>{const e=28,n=window.devicePixelRatio||1,i=document.createElement("canvas");i.width=e*n,i.height=e*n,i.style.cssText="width:28px;height:28px;flex-shrink:0;border-radius:50%;background:rgba(0,0,0,0.3)";const r=i.getContext("2d");r.scale(n,n);const s=14,o=14,a=12,c=t.position.x-t.target.x,l=t.position.z-t.target.z,h=t.position.y-t.target.y,d=Math.sqrt(c*c+l*l),u=Math.sqrt(c*c+h*h+l*l),p=u>.001?Math.max(0,h/u):0;let f=0,g=0;d>.001&&(f=c/d,g=l/d);const m=1-.6*p,y=s+f*a*.7*m,b=o+g*a*.7*m;r.strokeStyle="rgba(255,255,255,0.12)",r.lineWidth=1,r.beginPath(),r.arc(s,o,a,0,2*Math.PI),r.stroke(),r.strokeStyle="rgba(255,255,255,0.06)",r.beginPath(),r.moveTo(s,2),r.lineTo(s,26),r.moveTo(2,o),r.lineTo(26,o),r.stroke(),r.fillStyle="rgba(255,255,255,0.25)",r.beginPath(),r.arc(s,o,1.5,0,2*Math.PI),r.fill(),r.strokeStyle=`rgba(74,158,255,${.2+.2*p})`,r.lineWidth=1,r.beginPath(),r.moveTo(y,b),r.lineTo(s,o),r.stroke();const v=.6+.4*p;r.fillStyle=`rgba(74,158,255,${v})`,r.beginPath(),r.arc(y,b,3,0,2*Math.PI),r.fill();const _=Math.atan2(g,f),x=Math.PI/8;return r.fillStyle="rgba(74,158,255,0.08)",r.beginPath(),r.moveTo(y,b),r.arc(y,b,.6*a,_+Math.PI-x,_+Math.PI+x),r.closePath(),r.fill(),i},u=()=>{const t=e.getCameraWorldState();if(!t)return-1;const n=.01;for(let e=1;e<=9;e++){const i=c.getSlot(e);if(i&&(Math.abs(t.position.x-i.position.x)<n&&Math.abs(t.position.y-i.position.y)<n&&Math.abs(t.position.z-i.position.z)<n&&Math.abs(t.target.x-i.target.x)<n&&Math.abs(t.target.y-i.target.y)<n&&Math.abs(t.target.z-i.target.z)<n))return e}return-1};let p,f,g=-1;const m=()=>{a.innerHTML="";let t=!1;const i=u(),r=Array.from({length:9},(t,e)=>e+1);for(const s of r){const r=c.getSlot(s),o=!!r,u=s===i;if(n&&!o)continue;t=t||o;const p=document.createElement("div"),f=u?"rgba(74,158,255,0.1)":"transparent";if(p.style.cssText=`display:flex;align-items:center;gap:6px;padding:${n?"6px 8px":"3px 4px"};border-radius:6px;transition:background 0.15s;background:${f}${u?";box-shadow:inset 0 0 0 1px rgba(74,158,255,0.25)":""}`,p.dataset.active=u?"1":"",p.addEventListener("mouseenter",()=>{p.style.background=p.dataset.active?"rgba(74,158,255,0.15)":"rgba(255,255,255,0.06)",!n&&o&&e.highlightBookmarkMarker(s)}),p.addEventListener("mouseleave",()=>{const t=p.dataset.active;p.style.background=t?"rgba(74,158,255,0.1)":"transparent",n||e.clearBookmarkMarkerHighlight()}),n){if(o&&r){const t=d(r);t.style.pointerEvents="none",p.appendChild(t)}const t=document.createElement("span");t.textContent=r?.name||"noname",t.style.cssText=`flex:1;color:${r?.name?"rgba(255,255,255,0.8)":"rgba(255,255,255,0.35)"};font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;pointer-events:none;${r?.name?"":"font-style:italic"}`,p.appendChild(t),p.style.cursor="pointer",p.addEventListener("click",()=>{e.animateToSlot(s)})}else{const t=document.createElement("div");t.textContent="⠿";const n=o,i=o?"color:rgba(255,255,255,0.3)":"color:rgba(255,255,255,0.12)";if(t.style.cssText=`width:16px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;user-select:none;${i}${n?";cursor:grab":""}`,n&&(t.dataset.dragHandle="1",t.addEventListener("mouseenter",()=>{t.style.color="rgba(255,255,255,0.6)"}),t.addEventListener("mouseleave",()=>{t.style.color="rgba(255,255,255,0.3)"})),p.appendChild(t),o&&r){const t=d(r);t.style.pointerEvents="none",p.appendChild(t)}o&&(p.style.cursor="pointer",p.addEventListener("click",t=>{const n=t.target.tagName;"INPUT"!==n&&"BUTTON"!==n&&e.animateToSlot(s)}));const a=document.createElement("input");a.type="text",a.value=r?.name||"",a.placeholder=o?"noname":"Empty",a.style.cssText=`width:80px;font-size:12px;color:${o?"rgba(255,255,255,0.7)":"rgba(255,255,255,0.3)"};background:transparent;border:none;border-bottom:1px solid rgba(255,255,255,0.1);outline:none;padding:2px 0;min-width:0`,a.addEventListener("focus",()=>{a.style.borderBottomColor="rgba(74,158,255,0.5)",a.style.color="rgba(255,255,255,0.9)"}),a.addEventListener("blur",()=>{a.style.borderBottomColor="rgba(255,255,255,0.1)",a.style.color=o?"rgba(255,255,255,0.7)":"rgba(255,255,255,0.3)",o&&(c.renameSlot(s,a.value.trim()),l())}),a.addEventListener("keydown",t=>{t.stopPropagation(),t.isComposing||"Enter"!==t.key||a.blur()}),p.appendChild(a);const u=document.createElement("div");if(u.style.cssText="display:flex;gap:2px;flex-shrink:0",o){const t=document.createElement("button");t.textContent="📌",t.title="Overwrite with current view",t.style.cssText=h+";color:#ffaa44",t.addEventListener("mouseenter",()=>{t.style.background="rgba(255,170,68,0.15)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",()=>{e.saveCameraToSlot(s),m()}),u.appendChild(t);const n=document.createElement("button");n.textContent="🗑",n.title="Delete this slot",n.style.cssText=h+";color:#ff6b6b",n.addEventListener("mouseenter",()=>{n.style.background="rgba(255,107,107,0.15)"}),n.addEventListener("mouseleave",()=>{n.style.background="transparent"}),n.addEventListener("click",()=>{c.clearSlot(s),l(),m()}),u.appendChild(n);const i=document.createElement("button");i.textContent="⋮",i.title="Playlist settings",i.style.cssText=h+";color:rgba(255,255,255,0.35);font-size:14px",i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{i.style.background="transparent"}),u.appendChild(i)}else{const t=document.createElement("button");t.textContent="📌",t.title="Save current view here",t.style.cssText=h+";color:#4ade80",t.addEventListener("mouseenter",()=>{t.style.background="rgba(74,222,128,0.15)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",()=>{e.saveCameraToSlot(s),m()}),u.appendChild(t)}p.appendChild(u)}const y=document.createElement("div");if(y.dataset.slotIndex=String(s),y.dataset.filled=o?"1":"",y.appendChild(p),!n&&o){const t=p.querySelector("[data-drag-handle]");t&&t.addEventListener("pointerdown",e=>{e.preventDefault(),e.stopPropagation(),y.style.opacity="0.3",y.style.pointerEvents="none",y.style.outline="1px dashed rgba(74,158,255,0.4)",y.style.borderRadius="4px",t.style.cursor="grabbing";const n=document.createElement("div");n.style.cssText="height:2px;background:#4a9eff;border-radius:1px;margin:1px 0",t.setPointerCapture(e.pointerId);const i=t=>{const e=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&n.parentNode.removeChild(n);let i=null;for(const n of e){if(n===y)continue;const e=n.getBoundingClientRect();if(t.clientY<e.top+e.height/2){i=n;break}}if(i)a.insertBefore(n,i);else{const t=e[e.length-1];t&&t.after(n)}},r=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",i),t.removeEventListener("pointerup",r),y.style.cssText="",t.style.cursor="grab";const s=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&(a.insertBefore(y,n),n.parentNode.removeChild(n));const o=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]')).map(t=>parseInt(t.dataset.slotIndex)).map(t=>{const e=c.getSlot(t);return e?{...e,name:e.name}:void 0}),h=s.map(t=>parseInt(t.dataset.slotIndex)).sort((t,e)=>t-e);o.forEach((t,e)=>{const n=h[e];t?c.saveSlot(n,t):c.clearSlot(n)}),l(),m()};t.addEventListener("pointermove",i),t.addEventListener("pointerup",r)})}if(!n&&o&&r){const t=document.createElement("div");t.dataset.slotDetail="1";const e=g===s;t.style.cssText=`display:${e?"block":"none"};margin:2px 0 4px 26px;padding:6px 8px;background:rgba(255,255,255,0.03);border-radius:4px;border:1px solid rgba(255,255,255,0.06)`;const n="width:50px;font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none;text-align:right",i="font-size:10px;color:rgba(255,255,255,0.45);white-space:nowrap",o="display:flex;align-items:center;gap:6px;margin-bottom:4px",c=document.createElement("div");c.style.cssText=o;const h=document.createElement("span");h.textContent="Hold",h.style.cssText=i+";width:55px";const d=document.createElement("input");d.type="number",d.min="0",d.step="500",d.value=String(r.holdDuration??2e3),d.style.cssText=n;const u=document.createElement("span");u.textContent="ms",u.style.cssText=i,d.addEventListener("change",()=>{const t=parseInt(d.value);r.holdDuration=isNaN(t)?void 0:Math.max(0,t),l()}),d.addEventListener("keydown",t=>t.stopPropagation()),c.appendChild(h),c.appendChild(d),c.appendChild(u),t.appendChild(c);const f=document.createElement("div");f.style.cssText=o;const m=document.createElement("span");m.textContent="Transition",m.style.cssText=i+";width:55px";const b=document.createElement("input");b.type="number",b.min="0",b.step="200",b.value=String(r.transitionDuration??1200),b.style.cssText=n;const v=document.createElement("span");v.textContent="ms",v.style.cssText=i,b.addEventListener("change",()=>{const t=parseInt(b.value);r.transitionDuration=isNaN(t)?void 0:Math.max(0,t),l()}),b.addEventListener("keydown",t=>t.stopPropagation()),f.appendChild(m),f.appendChild(b),f.appendChild(v),t.appendChild(f);const _=document.createElement("div");_.style.cssText=o;const x=document.createElement("span");x.textContent="Easing",x.style.cssText=i+";width:55px";const w=document.createElement("select");w.style.cssText="font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none";for(const t of["ease-in-out","ease-in","ease-out","linear"]){const e=document.createElement("option");e.value=t,e.textContent=t,e.style.cssText="background:#2a2a2a;color:#ccc",(r.easing??"ease-in-out")===t&&(e.selected=!0),w.appendChild(e)}w.addEventListener("change",()=>{r.easing="ease-in-out"===w.value?void 0:w.value,l()}),_.appendChild(x),_.appendChild(w),t.appendChild(_);const M=document.createElement("div");M.style.cssText=o+";margin-bottom:0";const S=document.createElement("span");S.textContent="Skip in play",S.style.cssText=i+";width:55px";const k=document.createElement("input");k.type="checkbox",k.checked=!!r.excludeFromPlay,k.style.cssText="accent-color:#4a9eff;cursor:pointer",k.addEventListener("change",()=>{r.excludeFromPlay=k.checked||void 0,l()}),M.appendChild(S),M.appendChild(k),t.appendChild(M),y.appendChild(t);const A=p.querySelector("button:last-child");A&&(e&&(A.style.color="#4a9eff"),A.addEventListener("click",()=>{const e="none"!==t.style.display;a.querySelectorAll("[data-slot-detail]").forEach(e=>{if(e!==t&&"none"!==e.style.display){e.style.display="none";const t=e.parentElement?.firstElementChild?.querySelector("button:last-child");t&&(t.style.color="rgba(255,255,255,0.35)")}}),t.style.display=e?"none":"block",A.style.color=e?"rgba(255,255,255,0.35)":"#4a9eff",g=e?-1:s}))}a.appendChild(y)}if(!t){const t=document.createElement("div");if(t.textContent=n?"No bookmarks defined":"No bookmarks saved",t.style.cssText="color:rgba(255,255,255,0.3);font-size:12px;text-align:center;padding:12px 0",a.appendChild(t),!n){const t=document.createElement("div");t.textContent="Use 📌 to save camera positions",t.style.cssText="color:rgba(255,255,255,0.2);font-size:11px;text-align:center;padding:0 0 4px",a.appendChild(t)}}p&&(p.style.display=c.getPlayableSlots().length>=2?"block":"none")};if(m(),!n){p=document.createElement("div"),p.style.cssText="display:none;margin-top:6px;padding:4px 8px;border-top:1px solid rgba(255,255,255,0.06)";const t=document.createElement("div");t.style.cssText="display:flex;align-items:center;gap:6px";const n=document.createElement("input");n.type="range",n.min="0",n.max="1000",n.value="0",n.tabIndex=-1,n.style.cssText="flex:1;min-width:0;margin:0;height:14px;cursor:grab;accent-color:#4a9eff;outline:none";const i=document.createElement("button");i.textContent="▶",i.title="Play / Stop",i.style.cssText="border:none;background:rgba(255,255,255,0.06);color:rgba(255,255,255,0.5);cursor:pointer;font-size:12px;padding:3px 6px;border-radius:4px;line-height:1;flex-shrink:0",i.addEventListener("mouseenter",()=>{i.style.background="rgba(74,158,255,0.15)",i.style.color="#4a9eff"}),i.addEventListener("mouseleave",()=>{i.style.background="rgba(255,255,255,0.06)",i.style.color=c.isPlaying?"#4a9eff":"rgba(255,255,255,0.5)"}),i.addEventListener("click",()=>{const t=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(t),a()}),n.addEventListener("focus",()=>n.blur());let s=!1;n.addEventListener("mousedown",()=>{s=!0,n.style.cursor="grabbing",c.isPlaying&&(e.togglePlay(),a())}),n.addEventListener("input",()=>{const t=parseInt(n.value)/1e3;e.scrubPath(t)});const o=()=>{s&&(s=!1,n.style.cursor="grab")};n.addEventListener("mouseup",o),n.addEventListener("mouseleave",o),r.addEventListener("keydown",t=>{if("Space"===t.code&&"none"!==p.style.display){t.preventDefault(),t.stopPropagation();const i=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(i),a()}}),t.appendChild(n),t.appendChild(i),p.appendChild(t),r.appendChild(p);const a=()=>{const t=c.isPlaying;i.textContent=t?"⏹":"▶",i.style.color=t?"#4a9eff":"rgba(255,255,255,0.5)"};let l=-1;const h=()=>{if(this._floatingPopup===r){if(c.isPlaying){const t=c.playProgress;n.value=String(Math.round(1e3*t)),l=-1}else{"⏹"===i.textContent&&a();const t=c.lastPlayProgress;t>=0&&t!==l&&(n.value=String(Math.round(1e3*t)),l=t)}f=requestAnimationFrame(h)}};f=requestAnimationFrame(h);(()=>{const t=c.getPlayableSlots().length;p.style.display=t>=2?"block":"none"})()}if(!n){const t=document.createElement("button"),e="display:block;width:100%;margin-top:8px;padding:5px 0;border:1px solid rgba(255,255,255,0.12);border-radius:6px;background:transparent;color:rgba(255,255,255,0.45);font-size:11px;cursor:pointer;transition:all 0.15s";i&&(t.textContent="Clear All",t.style.cssText=e,t.addEventListener("mouseenter",()=>{t.style.borderColor="rgba(255,107,107,0.4)",t.style.color="#ff6b6b"}),t.addEventListener("mouseleave",()=>{t.style.borderColor="rgba(255,255,255,0.12)",t.style.color="rgba(255,255,255,0.45)"}),t.addEventListener("click",()=>{c.resetAll(),l(),m()})),r.appendChild(t)}const y=e.onBookmarkChanged;e.onBookmarkChanged=()=>{y?.(),this._floatingPopup===r&&(m(),v=-2,n||e.showBookmarkPath())},this._showFloatingPopup(r,!0),n||e.showBookmarkPath();let b,v=u();const _=()=>{if(this._floatingPopup!==r)return;const t=u();if(t!==v){v=t;a.querySelectorAll("[data-slot-index]").forEach(e=>{const n=parseInt(e.dataset.slotIndex||"-1"),i=e.firstElementChild;if(!i)return;const r=n===t,s=r?"rgba(74,158,255,0.1)":"transparent";i.style.background=s,i.style.boxShadow=r?"inset 0 0 0 1px rgba(74,158,255,0.25)":"none",i.dataset.active=r?"1":""})}b=requestAnimationFrame(_)};b=requestAnimationFrame(_);const x=this._closeFloatingPopup.bind(this);this._closeFloatingPopup=()=>{void 0!==b&&cancelAnimationFrame(b),void 0!==f&&cancelAnimationFrame(f),c.isPlaying&&e.togglePlay(),e.clearBookmarkMarkerHighlight(),e.hideBookmarkPath(!0),this._closeFloatingPopup=x,x()}}_removeToolbar(){this._closeFloatingPopup(),this._threeCapability&&(this._threeCapability.onGizmoModeChanged=void 0,this._threeCapability.onGizmoAttachChanged=void 0,this._threeCapability.onCameraViewChanged=void 0,this._threeCapability.onBookmarkChanged=void 0,this._threeCapability.onHelpToggle=void 0,this._threeCapability.onSearchToggle=void 0,this._threeCapability.onDataBindingToggle=void 0,this._threeCapability.onMonitorToggle=void 0,this._threeCapability.onBookmarkNavToggle=void 0,this._threeCapability.onBookmarkEditToggle=void 0),this._toolbar?.parentNode&&this._toolbar.parentNode.removeChild(this._toolbar),this._toolbar=void 0,this._cameraButtons=void 0}_resizeThreeD(t=!1){if(!this._threeCapability||!this.element)return;const e=this.canvas?.clientWidth??0,n=this.canvas?.clientHeight??0,i=e>0?e:this.element.clientWidth,r=n>0?n:this.element.clientHeight;i>0&&r>0&&this._threeCapability.resize(i,r,t)}detachThreeCapability(){const t=this._threeCapability;if(t)return t.forceCleanupDragState(),t.clearAllObjects(),this._threeCapability=void 0,t}adoptThreeCapability(t){this._threeCapability=t,this._hide2DLayers();const e=t.domElement;if(e&&this.element){e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.pointerEvents="none",e.setAttribute("scene","model-layer-webgl");const t=this._decoratorOverlay||this.element.firstChild;this.element.insertBefore(e,t)}t.buildOverlays(),t.rebuildForHost(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),this.app?.isEditMode&&this._createToolbar(),this._registerPopupCallbacks(),this._resizeThreeD(!0)}_deactivateThreeD(){if(!this._threeCapability)return;this._removeToolbar(),this._lastCameraState=this._threeCapability.captureSessionState();const{target:t,visibleWidth:e,visibleHeight:n}=this._threeCapability.captureViewportInfo();this._threeCapability.forceCleanupDragState();const i=this._threeCapability.domElement,r=this._threeCapability.css3DRenderer?.domElement,s=[...this._threeCapability.decoratorOutlines];this._threeCapability.dispose(),this._threeCapability=void 0,r?.parentNode&&r.parentNode.removeChild(r);for(const t of this.components)if(t.isHTMLElement()&&t.element){const e=t.element,n=this.getOverlay(t);n?.appendChild(e)}i?.parentNode&&i.parentNode.removeChild(i),this.canvas&&(this.canvas.style.display=""),this._overlay&&(this._overlay.style.display=""),this._auxCanvas&&(this._auxCanvas.style.display=""),this._decoratorOverlay&&(this._decoratorOverlay.style.display=""),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="");for(const t of this.components)t.isHTMLElement()&&t.element&&t.reposition();this.app?.isEditMode&&this._createToolbar();for(const t of s)t.disposed||this.applyDecorator(t,"border-highlighting",{distance:8,lineWidth:4,color:"#f007"});this._saved2DViewport?(this.set({scale:this._saved2DViewport.scale,translate:this._saved2DViewport.translate}),this._saved2DViewport=void 0):this._needsViewportSync&&this._init2DViewportFrom3DCamera(t,e,n),this.root.target_element?.focus()}_getViewportSize(){const t=this.target;return{w:t?.clientWidth||this.canvas?.clientWidth||this.state.width||800,h:t?.clientHeight||this.canvas?.clientHeight||this.state.height||600}}_initCameraFrom2DViewport(){if(!this._threeCapability)return;const{w:t,h:e}=this._getViewportSize(),n=this.get("translate")||{x:0,y:0},i=this.get("scale")||{x:1,y:1},r=i.x||1,s=i.y||1,{width:o=800,height:a=600}=this.state,c=(t/2-n.x)/r-o/2,l=(e/2-n.y)/s-a/2,h=t/r,d=e/s;this._threeCapability.positionCameraForViewport(c,l,h,d,this._lastCameraState)}_init2DViewportFrom3DCamera(t,e,n){const{w:i,h:r}=this._getViewportSize(),{width:s=800,height:o=600}=this.state,a=t.x+s/2,c=t.z+o/2;let l;if(this._2dScaleBeforeThreeD&&this._initialVisibleHeight&&n>0){const t=this._initialVisibleHeight/n;l=this._2dScaleBeforeThreeD*t}else if(e>0||n>0){const t=e>0?i/e:1,s=n>0?r/n:1;l=Math.max(t,s)}else l=1;l=Math.max(.1,Math.min(l,10));const h=i/2-a*l,d=r/2-c*l;this.set({translate:{x:h,y:d},scale:{x:l,y:l}}),this._2dScaleBeforeThreeD=void 0,this._initialVisibleHeight=void 0}centerTo(t,e){this.is3dMode&&this._threeCapability?this._threeCapability.centerToComponent(t,e):super.centerTo(t,e)}async ready(){await super.ready(),this.model.threed?this._threeCapability||(await new Promise(t=>setTimeout(t,0)),this._activateThreeD()):this.app?.isEditMode&&this._createToolbar(),this.root?.trigger("dimension",this.model.threed?"3d":"2d")}toggleThreeD(t){const e=t??!this.is3dMode;e?(this._threeDUserDeactivated=!1,this._activateThreeD(!0)):(this._threeDUserDeactivated=!0,this._deactivateThreeD(),this.resize(),this.invalidate()),this.root?.trigger("dimension",e?"3d":"2d")}dispose(){this._deactivateThreeD(),this._removeToolbar(),super.dispose(),this._overlay=null,this._decoratorOverlay&&(Bs.getInstance().removeOverlay(this._decoratorOverlay),this._decoratorOverlay.parentNode&&this._decoratorOverlay.parentNode.removeChild(this._decoratorOverlay),this._decoratorOverlay=null),this._decoratorAuxOverlay&&(Bs.getInstance().removeOverlay(this._decoratorAuxOverlay),this._decoratorAuxOverlay.parentNode&&this._decoratorAuxOverlay.parentNode.removeChild(this._decoratorAuxOverlay),this._decoratorAuxOverlay=null)}contains(t,e){return!0}isRootModel(){return!0}get stuck(){return!0}get layout(){return this.is3dMode?yc.get("three"):bc}get overlay(){if(!this._overlay){const t=document.createElement("div");t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.margin="0",t.style.padding="0",t.style.overflow="initial",t.style["user-select"]="none",t.style["transform-origin"]="top left",t.setAttribute("scene","model-layer-overlay"),this.element.insertBefore(t,this.auxCanvas),this._overlay=t,this._repositionOverlay()}return this._overlay}get auxOverlay(){return this.element??void 0}get decoratorOverlay(){if(!this._decoratorOverlay){const t=document.createElement("div");t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.margin="0",t.style.padding="0",t.style.overflow="initial",t.style["user-select"]="none",t.style["transform-origin"]="top left",t.setAttribute("scene","decorator-overlay"),t.id=`decorator-overlay-${Date.now()}`,this.element.insertBefore(t,this.overlay),this._decoratorOverlay=t,Bs.getInstance().addOverlay(t)}return this._decoratorOverlay}get decoratorAuxOverlay(){if(!this._decoratorAuxOverlay){const t=document.createElement("div");t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.margin="0",t.style.padding="0",t.style.overflow="initial",t.style.zIndex="100",t.style["user-select"]="none",t.style["transform-origin"]="top left",t.setAttribute("scene","decorator-aux-overlay"),t.id=`decorator-overlay-${Date.now()}`,this.element.appendChild(t),this._decoratorAuxOverlay=t,Bs.getInstance().addOverlay(t)}return this._decoratorAuxOverlay}createElement(){const t=super.createElement();return this._overlay&&t.appendChild(this._overlay),t}resize(){if(!this.target||!this.element)return;let{width:t,height:e,fitMode:n}=this.model;this.root.fitMode?n=this.root.fitMode:n||(n="ratio");let i=null;try{i=getComputedStyle(this.target)}catch(t){return void Ki(t,this.target)}let r=i?parseFloat(i.getPropertyValue("width")):this.target.clientWidth,s=i?parseFloat(i.getPropertyValue("height")):this.target.clientHeight;switch(n){case"both":case"ratio":break;case"width":s=e*r/t,this.element.style.overflowX="hidden",this.element.style.overflowY="auto";break;case"height":r=t*s/e,this.element.style.overflowX="auto",this.element.style.overflowY="hidden";break;default:r=Math.max(t,r),s=Math.max(e,s),this.element.style.overflowX=r>t?"hidden":"auto",this.element.style.overflowY=s>e?"hidden":"auto"}this.fitSize(this.element,!0),this.fitSize(this.canvas,!0,r,s),this.fitSize(this.auxCanvas,!0,r,s),this.root?.transitionEffect?.resize(),this.is3dMode&&this._threeCapability.resize(r,s)}draw(t){if(this.is3dMode){if(!this.element)return;return void this._threeCapability.renderCSS3D()}if(this.model.threed&&!this._threeCapability&&!this._threeDUserDeactivated)return;const e=this.root?.transitionEffect;e?.beginDraw(),super.draw(t),e?.endDraw()}get MPP(){const{scale:t={x:1,y:1},unit:e}=this.model;switch(e){case"mm":case"cm":return 1/this.app.PPM/t.x;case"in":return 1/this.app.PPI/t.x;default:return 1/t.x}}capturePath(t,e){const n=this.layout.capturables(this);for(let i=n.length-1;i>=0;i--){const r=n[i];if(!r.isContainer())continue;const s=r.capturePath(t,e);if(s)return s}return!1}getOverlay(t){return t&&!t.scalable?this.auxOverlay:this.overlay}getDecoratorOverlay(t){return t&&!t.scalable?this.decoratorAuxOverlay:this.decoratorOverlay}_onkeydown_root(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;const e=this.rootModel;if(!e)return;if("KeyF"===t.code)return this.onSearchToggle?.(),void t.preventDefault();if("KeyH"===t.code)return this._toggleHelpPanel(),void t.preventDefault();if("KeyD"===t.code)return this.onDataBindingToggle?.(),void t.preventDefault();if("KeyM"===t.code)return this.onMonitorToggle?.(),void t.preventDefault();if("KeyQ"===t.code)return this.toggleThreeD(),void t.preventDefault();if(e.is3dMode)return;const n={Digit1:"perspective",Digit2:"top",Digit3:"front",Digit4:"back",Digit5:"right",Digit6:"left"}[t.code];n&&(e._pendingCameraView=n,this.toggleThreeD(!0),t.preventDefault())}get eventMap(){return{"(self)":{"(all)":{change:this._onchanged_all,mouseenter:this._onmouseenter_all,mouseleave:this._onmouseleave_all,click:this._onclick,mousedown:this._onmousedownup,mouseup:this._onmousedownup,touchstart:this._onmousedownup,touchend:this._onmousedownup,"deco-reset":t=>this.resetDecorator(void 0,t.origin)},"(descendant)":{"deco-anchors":(t,e)=>this.applyDecorator(e.origin,"anchors",t),"deco-anchors-off":t=>this.offdecorator(t.origin,"anchors"),"deco-anchors-reset":t=>this.resetDecorator("anchors"),"deco-dataspread":(t,e)=>this.applyDecorator(e.origin,"data-spread",t),"deco-dataspread-off":t=>this.offdecorator(t.origin,"data-spread"),"deco-dataspread-reset":t=>this.resetDecorator("data-spread"),"deco-link":(t,e)=>this.applyDecorator(e.origin,"link",t),"deco-link-off":t=>this.offdecorator(t.origin,"link"),"deco-link-reset":t=>this.resetDecorator("link"),"deco-arrow":(t,e)=>this.applyDecorator(e.origin,"bouncing-arrow",t),"deco-arrow-off":t=>this.offdecorator(t.origin,"bouncing-arrow"),"deco-arrow-reset":t=>this.resetDecorator("bouncing-arrow"),"deco-icon":(t,e)=>this.applyDecorator(e.origin,"animated-icon",t),"deco-icon-off":t=>this.offdecorator(t.origin,"animated-icon"),"deco-icon-reset":t=>this.resetDecorator("animated-icon"),"deco-border":(t,e)=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.addOutline(e.origin):this.applyDecorator(e.origin,"border-highlighting",t))},"deco-border-off":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.removeOutline(t.origin):this.offdecorator(t.origin,"border-highlighting"))},"deco-border-reset":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.clearOutlines():this.resetDecorator("border-highlighting"))},"deco-tag":(t,e)=>this.applyDecorator(e.origin,"decotag",t),"deco-tag-off":t=>this.offdecorator(t.origin,"decotag"),"deco-tag-reset":t=>this.resetDecorator("decotag",t.origin),"deco-off":t=>{this.offdecorator(t.origin),this._threeCapability?.removeOutline(t.origin)},mouseenter:this.onmouseenterForDecorator,mouseleave:this.onmouseleaveForDecorator},"(self)":{change:this.onChangeForDecorator,redraw:this.onRedrawForDecorator}},"(root)":{"(self)":{selected:this._onRootSelected,keydown:this._onkeydown_root}}}}onRedrawForDecorator(){this.is3dMode||(Bs.getInstance().invalidateOverlay(this.decoratorOverlay),Bs.getInstance().invalidateOverlay(this.decoratorAuxOverlay))}closeScene(t){requestAnimationFrame(()=>this.overlay.dispatchEvent(new CustomEvent("close-scene",{bubbles:!0,composed:!0,detail:t})))}_repositionOverlay(){const t=this._overlay;if(!t)return;const{translate:e=Ad,scale:n=kd,rotation:i=0}=this.model,{left:r,top:s}=this.bounds;t.style.left=r+"px",t.style.top=s+"px",t.style.transform=`rotate(${i}rad) scale(${n.x}, ${n.y}) perspective(1px)`,t.style.marginLeft=`${e.x}px`,t.style.marginTop=`${e.y}px`}onchange(t){const e=this._model;delete e.id,delete e.text,delete e.class,this._repositionOverlay(),t.hasOwnProperty("threed")&&(t.threed?this._activateThreeD(!0):this._deactivateThreeD(),this.root?.trigger("dimension",t.threed?"3d":"2d")),this.is3dMode&&((t.hasOwnProperty("width")||t.hasOwnProperty("height"))&&this._resizeThreeD(),this._threeCapability.onchange(t))}_onRootSelected(t){const e=1===t?.length?t[0]:t&&0!==t.length?null:this;e&&globalThis.dispatchEvent?.(new CustomEvent("clickComponent",{detail:e}))}_onchanged_all(t,e,n){this.invalidate()}_onmouseenter_all(t,e){if(t.stopPropagation(),!this.app||this.app.isEditMode)return;if(!e)return;const n=e.origin;if(n instanceof Id||!n.model.event||!n.model.event.hover)return;if(n.hidden)return;const i=n.model.event.hover;i&&this._doEventAction(i,n,!0,t)}_onmouseleave_all(t,e){if(t.stopPropagation(),!e)return;const n=e.origin;if(!this.app||this.app.isEditMode)return;const i=n.model.event&&n.model.event.hover;i&&this._doEventAction(i,n,!1,t)}_onclick(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,i=n.model.event?.tap;i&&this._doEventAction(i,n,!0,t)}_onmousedownup(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,i=n.model.event?.tap;i&&i.pressed&&this._doMouseDownUpEventAction(i,n,"mousedown"==t.type||"touchstart"==t.type,t)}_doMouseDownUpEventAction(t,e,n,i){const{pressed:r=!1}=t;r&&(n?function(t){if(t.hasOwnProperty("_backupShadow"))return;const e=t.get("shadow");t._backupShadow=e;const{left:n=0,top:i=0}=e||{};t.delta("tx",n),t.delta("ty",i),t.set("shadow",{})}(e):function(t){t.hasOwnProperty("_backupShadow")&&(t.delta("tx",0),t.delta("ty",0),t.set("shadow",t._backupShadow),delete t._backupShadow)}(e))}_doEventAction(t,e,n,i){let{action:r,target:s,value:o,emphasize:a=!1,restore:c=!1,options:l}=t;if(s&&(s=e.access(s)),o&&(o=e.access(o)),a&&(n?function(t){const{hover:e}=t.state.event||{},{emphasize:n}=e||{};if(t.hasOwnProperty("_backupStrokeStyle"))return;if("__backup_emphasize"in t)return;const{strokeStyle:i,lineWidth:r,fillStyle:s}=t.state;t.__backup_emphasize={strokeStyle:i,lineWidth:r,fillStyle:s},t.setState(n)}(e):c&&function(t){"__backup_emphasize"in t&&(t.setState(t.__backup_emphasize),delete t.__backup_emphasize)}(e)),r)switch(r){case"data-toggle":if(!s)return;(n||c)&&this.root.findAll(s,e)?.forEach(t=>{t.data=!t.data});break;case"data-tristate":if(!s)return;(n||c)&&this.root.findAll(s,e)?.forEach(t=>{const e=Math.round(Math.max(Number(t.data)||0,0));t.data=(e+(n?1:2))%3});break;case"data-spreading":if(!s)return;n&&(e.access(o),this.root.findAll(s,e)?.forEach(t=>{t.executeMappings(!0)}));break;case"data-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.data=t})}break;case"partial-data-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.data={...e.data,...t}})}break;case"value-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.value=t})}break;case"partial-value-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.value={...e.value,...t}})}break;case"infoWindow":case"info-window":if(!s)return;"click"==i.type||n?gc.show(e,s,c,{x:i.offsetX,y:i.offsetY}):c&&gc.hide(e,s);break;case"toggle-info-window":if(!s)return;gc.toggle(e,s,!1,{x:i.offsetX,y:i.offsetY});break;case"popup":case"modal-popup":if(!s)return;const t=l&&"input"in l?l.input:"(self)",a=!l||(!("output"in l)||l.output);Ic.show(e,s,{data:t&&this.root.findFirst(t,e)?.data,output:a,modal:"modal-popup"===r,closable:!0,draggable:!0,origin:"auto"});break;case"close-scene":this.closeScene(e.data);break;case"goto":case"goto-playlist":this.trigger(r,s,l,e);break;case"mouse-cursor":n?this.target.style.cursor=s||"auto":c&&(this.target.style.cursor="auto");break;default:this.trigger(r,s,o,e)}}applyDecorator(t,e,n={}){const i=this.getDecoratorOverlay(t);if(i){Bs.getInstance().addToOverlay(i,t,e,n)}}offdecorator(t,e){const n=this.getDecoratorOverlay(t);if(n){Bs.getInstance().removeFromOverlay(n,t,e)}}resetDecorator(t,e){const n=this.getDecoratorOverlay(e);n&&Bs.getInstance().removeAllFromOverlay(n,t)}onChangeForDecorator(t,e,n){const{origin:i}=n,r=this.getDecoratorOverlay(i);Bs.getInstance().invalidateOverlay(r)}onmouseenterForDecorator(t,e){const{origin:n}=e;n.decorators&&n.decorators.forEach(t=>{this.applyDecorator(n,t)})}onmouseleaveForDecorator(t,e){const{origin:n}=e;n.decorators&&n.decorators.forEach(t=>{this.offdecorator(n,t)})}}function Ld(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.from?.component===n&&(!e||t.from.anchor===e))}function jd(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.to?.component===n&&(!e||t.to.anchor===e))}function Rd(t){return class extends t{isConnectable(){return!0}postrender(t){super.postrender(t),this._draw_anchors(t)}_draw_anchors(t){const e=this.anchors||[];t.save(),e.forEach(e=>{const{draw:n}=e;if(n){t.beginPath();try{n.call(e,t,this)}catch(t){Ki(t)}t.closePath()}}),t.restore()}contains(t,e){let n=super.contains(t,e);if(n)return n;const i=this.anchors||[];for(const r of i){const i=r.bounds;if(!i)continue;const{left:s,top:o,width:a,height:c}=i;if(n=t<Math.max(s+a,s)&&t>Math.min(s+a,s)&&e<Math.max(o+c,o)&&e>Math.min(o+c,o),n)return n}return!1}findInOutLines(t){return function(t,e){const n=t.state.refid;return t.root.findAll(t=>!(!t.isLine()||(t.from?.component!==n||e&&t.from.anchor!==e)&&(t.to?.component!==n||e&&t.to.anchor!==e)))}(this,t)}findOutletLines(t){return Ld(this,t)}findOutletEnds(t){return function(t,e){return Ld(t,e).map(t=>t.toEnd?.component).filter(Boolean)}(this,t)}findInletLines(t){return jd(this,t)}findInletEnds(t){return function(t,e){return jd(t,e).map(t=>t.fromEnd?.component).filter(Boolean)}(this,t)}}}Id.Popup=Ic,cc.register("model-layer",Id);const Fd={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0}}],help:"scene/component/rect"},Bd={ondragmove:function(t,e,n){const{left:i,width:r,height:s}=n.model;let o=(n.fromParent(t.x,t.y).x-i)/(r/2)*100;o=hc(o,r,s),n.set({round:o})}};class Nd extends(Rd(dc(lc))){is3dish(){return!0}get controls(){let{left:t,top:e,width:n,round:i,height:r}=this.state;return i=null==i?0:hc(i,n,r),[{x:t+n/2*(i/100),y:e,handler:Bd}]}get nature(){return Fd}}cc.register("rect",Nd);const Hd=[1,2,10,20,50,50,50,50,50,50];class Yd extends(dc(lc)){render(t){const{lineWidth:e=1,fillStyle:n="lightgray",font:i="15px Arial",left:r,top:s,origin:o,width:a,height:c,side:l="bottom",strokeStyle:h="#000000",scale:d=1}=this.state;t.translate(r,s),t.beginPath();const u=Math.round(e/2);t.rect(-u,-u,a+2*u,c+2*u),t.clip(),t.beginPath(),t.rect(0,0,a,c),n&&(t.fillStyle=n,t.fill()),t.lineWidth=e,t.strokeStyle=h,t.stroke(),t.beginPath(),t.font=i;const p="bottom"!==l,f=p?0:c;let g=4*c/5,m=2*c/3,y=1*c/2,b=3*c/5;p&&(g=c-g,m=c-m,y=c-y,b=c-1.5*c/5);const v=d*this.app.PPM/this.root.unitScale;let _=Math.ceil(o/v);const x=this.app.PPM/v,w=x<=1.1?1:Hd[Math.round(x)]||100;1!=w&&(_+=(w-_%w)%w);let M=Math.ceil(_*v);const S=o+a;for(t.fillStyle=h;M<S;){if(_%10==0){t.moveTo(M-o,y),t.lineTo(M-o,f);const e=(_/10).toString(),n=t.measureText(e);t.fillText(e,M-o-n.width-6,b)}else _%5==0?(t.moveTo(M-o,m),t.lineTo(M-o,f)):(t.moveTo(M-o,g),t.lineTo(M-o,f));_+=w,M=Math.ceil(_*v)}}}cc.register("ruler",Yd);const Vd=20,Gd=20,Ud=90*Math.PI/180,Wd="9px Verdana",Xd=20,qd="#f4f4f4",Kd="#999";function $d(t,e,n){return{left:-t.x,top:-t.y,width:Vd,height:Xd}}function Qd(t,e,n,i){return{left:Vd-t.x,top:0-t.y,origin:20-t.x,width:e-Vd,height:Xd}}function Zd(t,e,n,i){const r={x:0-t.x+10,y:-t.y+Gd+(n-Gd)/2},s=cc.transcoordRR(0-t.x,-t.y+Gd,r,Ud);return{left:s.x-(n-Gd),top:s.y,origin:20-t.y,width:n-Gd,height:Xd}}function Jd(t){const e=t.get("translate");return{left:-e.x,top:-e.y,width:t.canvas.width/Hr,height:t.canvas.height/Hr}}cc.register("guide-layer",class extends Bc{constructor(t,e){super(t,e),this.appScale={x:1,y:1},"disabled"!==t.ruler&&(this.hruler=new Yd({left:Vd,top:0,origin:20,margin:0,height:Xd,unit:"m",rotation:0,font:Wd,fillStyle:qd,strokeStyle:Kd,capturable:!1}),this.vruler=new Yd({left:0,top:0,origin:20,margin:0,height:Xd,unit:"m",rotation:Ud,font:Wd,side:"top",fillStyle:qd,strokeStyle:Kd,capturable:!1}),this.origin_rect=new Nd({left:-20,top:-20,width:20,height:20,fillStyle:qd,strokeStyle:Kd,lineWidth:1}),this.addComponent(this.hruler),this.addComponent(this.vruler),this.addComponent(this.origin_rect)),this.invalidate()}get capturable(){return!1}async ready(){if(await super.ready(),!this.hruler)return void(this.screen_coord=Jd(this));const t=this.rootModel,e=Object.assign({},t.get("translate"));e.x<Vd&&(e.x+=Vd),e.y<Gd&&(e.y+=Gd);const n=t.get("scale")||{x:1,y:1};this.appScale=n,this.hruler.set("scale",n.x),this.vruler.set("scale",n.y),t.set("translate",e),this.set("translate",e),this.screen_coord=Jd(this);const{width:i,height:r}=this.screen_coord;this.hruler.set(Qd(e,i)),this.vruler.set(Zd(e,0,r)),this.origin_rect.set($d(e))}resize(){super.resize(),this.screen_coord=Jd(this);const{width:t,height:e}=this.screen_coord;this.hruler&&(this.hruler.set(Qd(this.model.translate,t)),this.vruler.set(Zd(this.model.translate,0,e)),this.origin_rect.set($d(this.model.translate)))}render(t){if(this.rootModel?.is3dMode)return;if(!this.guide)return;t.save();const{x:e,y:n}=this.guide,{top:i,left:r,width:s,height:o}=this.screen_coord;t.beginPath(),t.moveTo(e,i),t.lineTo(e,i+o),t.moveTo(r,n),t.lineTo(r+s,n),t.lineWidth=1,t.strokeStyle="tomato",t.setLineDash([2,3]),t.font="10px tahoma",t.fillStyle="#333";const a=this.toGlobal(e,n,this.rootModel);t.textBaseline=a.y>200?"bottom":"top",t.textAlign=a.x>200?"right":"left";const c=a.y>200?-5:5,l=a.x>200?-5:5,h=Math.round(e/this.appScale.x),d=Math.round(n/this.appScale.y);t.fillText(` ${h}, ${d} `,e+l,n+c),t.stroke(),t.restore()}get guide(){return this._guide}set guide(t){this._guide=t,this.invalidate()}contains(t,e){return!0}get eventMap(){return{"(root)":{"(descendant)":{mousemove:this.onmousemove_child,mouseout:this.onmouseout_child,dragmove:this.onmousemove_child},"model-layer":{change:this.onchange_root_model}},"(self)":{"(descendant)":{mousedown:this.onmousedown_origin}}}}onmousedown_origin(t,e){this.rootModel.set("translate",{x:20,y:20})}onchange_root_model(t,e,n){if(t.scale&&(this.appScale=t.scale,this.hruler&&(this.hruler.set("scale",t.scale.x),this.vruler.set("scale",t.scale.y))),t.translate&&this.set({translate:{x:t.translate.x,y:t.translate.y}}),t.scale||t.translate){if(this.screen_coord=Jd(this),this.hruler){const{translate:t}=this.model,{width:e,height:n}=this.screen_coord;this.hruler.set(Qd(t,e)),this.vruler.set(Zd(t,0,n)),this.origin_rect.set($d(t))}this._guide=null}this.invalidate()}onmouseout_child(t){this._guide=null,this.invalidate()}onmousemove_child(t,e){t.target&&"CANVAS"!==t.target.tagName?this.guide=null:this.guide=this.toLocal(t.offsetX,t.offsetY)}});cc.register("shift-layer",class extends Bc{async ready(){await super.ready();const t=this.rootModel.get("translate");this.set("translate",t)}render(t){}get pointerEvents(){return"none"}contains(t,e){return!(2!=this.app.mode)}get eventMap(){return{"(root)":{"(self)":{keydown:this.onkeydown,keyup:this.onkeyup}}}}onkeydown(t){"Space"===t.code&&void 0===this.before_mode&&(this.before_mode=this.app.mode,this.app.mode=2)}onkeyup(t){"Space"===t.code&&(void 0!==this.before_mode&&(this.app.mode=this.before_mode),delete this.before_mode)}ondragstart(t){this.last_position=this.toLocal(t.offsetX,t.offsetY)}ondragmove(t){const{x:e,y:n}=this.toLocal(t.offsetX,t.offsetY);this.rootModel.move({x:e-this.last_position.x,y:n-this.last_position.y},!1),this.last_position=this.toLocal(t.offsetX,t.offsetY)}});function tu(t,e,n,i,r){const s=t.selected;let o=i?s.slice(0):[];e.isContainer()||(e=e.parent);const a=e.layout.capturables(e),c=!!e.layout.joinType;if(i&&n.selected.forEach(t=>{o.splice(o.indexOf(t),1)}),n.selected=[],a.forEach(t=>{!t.capturable||!function(t,e,n){const{sx:i,sy:r,ex:s,ey:o}=e;let a,c,l,h;if(i>s?(a=s,c=i):(a=i,c=s),r>o?(l=o,h=r):(l=r,h=o),n){const e=t.bounds,n=t.transcoordS2TR(e.left,e.top),i=t.transcoordS2TR(e.left+e.width,e.top+e.height),r=n.x,s=i.x,o=n.y,d=i.y,u=Math.min(a,r,c,s),p=Math.max(a,r,c,s),f=Math.min(l,o,h,d),g=Math.max(l,o,h,d);return!(p-u>Math.abs(c-a)+Math.abs(s-r)||g-f>Math.abs(h-l)+Math.abs(d-o))}{const e=t.path;if(!e)return Ki("컴포넌트에 get path가 잘못 구현되어있음.",t),!1;for(let n=0;n<e.length;n++){const i=t.transcoordS2TR(e[n].x,e[n].y);if(a>i.x||c<i.x||l>i.y||h<i.y)return!1}return!0}}(t,n,c)||-1!=o.indexOf(t)||r&&t.state.type!==r||n.selected.push(t)}),o=o.concat(n.selected),s.length!==o.length)t.selected=o;else for(let e=0;e<o.length;e++)if(s[e]!=o[e]){t.selected=o;break}}function eu(t,e,n,i,r,s){r||tu(t,e,n,i,s)}function nu(t,e){const n=t.components||[];for(const t of n){nu(t,e);const n=e.indexOf(t);-1!=n&&e.splice(n,1)}}cc.register("add-layer",class extends Bc{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}get pointerEvents(){return"none"}render(t){const e=this.addbox;if(e){const{sx:n,sy:i,ex:r,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,r-n,s-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle="black",t.stroke()}}contains(t,e){return!(3!=this.app.mode)}get eventMap(){return{"(root)":{"(self)":{addstart:this.onaddstart,addstop:this.onaddstop,keydown:this.onkeydown,dragstart:this.ondragstart,dragmove:this.ondragmove,dragend:this.ondragend,mousedown:this.onmousedown,mouseup:this.onmouseup}},"model-layer":{"(self)":{change:this.onchange_root_model}}}}onchange_root_model(t,e,n){t.translate&&this.set("translate",t.translate),t.scale&&this.set("scale",t.scale)}onaddstart(t,e){void 0===this.before_mode&&(this.before_mode=this.app.mode,this.models=t,this.app.mode=3,this.root.target_element?.focus())}onaddstop(){void 0!==this.before_mode&&(this.app.mode=this.before_mode),delete this.before_mode,delete this.addbox,this.invalidate()}onkeydown(t){3!==this.app.mode||"Esc"!=t.code&&"Escape"!=t.code||this.root.trigger("addstop")}ondragstart(t){const{x:e,y:n}=this.toLocal(t.offsetX,t.offsetY);this.addbox={sx:e,sy:n}}ondragmove(t){if(3!==this.app.mode)return;const{x:e,y:n}=this.toLocal(t.offsetX,t.offsetY);this.addbox&&(this.addbox.ex=e,this.addbox.ey=n,this.invalidate())}ondragend(t,e){if(3!==this.app.mode)return;const{sx:n,sy:i,ex:r,ey:s}=this.addbox;Ml.call(this.root,this.models,{left:Math.min(n,r),top:Math.min(i,s),width:Math.abs(r-n),height:Math.abs(s-i)}),this.root.trigger("addstop")}onmousedown(t,e){3===this.app.mode&&(this.downpoint={x:t.offsetX,y:t.offsetY})}onmouseup(t,e){if(this.downpoint.x!==t.offsetX||this.downpoint.y!==t.offsetY)return;const{x:n,y:i}=this.toLocal(t.offsetX,t.offsetY);Ml.call(this.root,this.models,{cx:n,cy:i}),this.root.trigger("addstop")}});cc.register("selection-layer",class extends Bc{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n);const i=this.root?.target_element;i?.addEventListener("contextmenu",t=>{t.shiftKey&&t.preventDefault()})}contains(t,e){return!1}render(t){const e=this.selbox;if(e){const{sx:n,sy:i,ex:r,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,r-n,s-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle="black",t.stroke()}}get eventMap(){return{"(root)":{"(self)":{keydown:this.onkeydown}},"model-layer":{"(self)":{change:this.onchange_root_model},"(all)":{dragstart:this.ondragstart_selbox,dragmove:this.ondragmove_selbox,dragend:this.ondragend_selbox,mousedown:this.onmousedown_comp,mouseup:this.onmouseup_comp}}}}onkeydown(t,e){const{deliverer:n}=e,i=n.selected;if(1!==i.length)return!1;let r=i[0];const s=r.parent;if(!s||s===n)return!1;if("Tab"===t.code){const e=s.layout.capturables(s);let n=e.indexOf(r);if(-1==n){if(!s.indexOf(r))return $i("Container not contains [",r,"] as a component"),!1;n=0}const i=e.length;t.shiftKey?n--:n++,r=e[(n+i)%i]}else{if(!s.layout.keyNavigate)return!1;r=s.layout.keyNavigate(s,r,t)||r}n.selected=[r],t.preventDefault()}onchange_root_model(t,e,n){t.translate&&this.set("translate",t.translate),t.scale&&this.set("scale",t.scale)}_pendingDecision(t){this.downpoint={x:t.offsetX,y:t.offsetY}}_selectGroupItem(t,e){const n=this.selected.indexOf(t);let i=t.parent;for(;i.parent.isGroup();)i=i.parent;let r=[],s=!1,o=!1;if(this.selected.forEach(t=>{let e=t.parent;if(t!==i){for(;e.parent&&e.parent.isGroup();)e=e.parent;e===i&&(r.push(t),s=!0)}else o=!0}),s)if(e.shiftKey){if(-1!=n)return void this._pendingDecision(e);r.push(t)}else{if(-1!=n)return void this._pendingDecision(e);r=[t]}else{if(o)return void this._pendingDecision(e);if(e.shiftKey)if(this.selected.length>0){if(-1!=this.selected.indexOf(i))return;r=[...this.selected,i]}else r=[i];else r=[i]}this.selected=r}onmousedown_comp(t,e){const{origin:n}=e;if(this.downpoint=null,t.shiftKey){if(n.stuck)return;if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(-1==this.selected.indexOf(n)){if((t.ctrlKey||t.metaKey)&&this.selected.length>0){const t=this.selected[0].state.type;if(n.state.type!==t)return}this.selected=[...this.selected,n]}else this._pendingDecision(t)}else{if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(n.stuck)this.selected.length>0&&(this.selected=[]);else{if(-1!=this.selected.indexOf(n))return;this.selected=[n],this.sameParent=!0}}}onmouseup_comp(t,e){if(!this.downpoint)return;if(this.downpoint.x!==t.offsetX||this.downpoint.y!==t.offsetY)return;const{origin:n}=e;if(t.shiftKey){let t=this.selected.indexOf(n);if(-1==t&&n.parent.isGroup()&&(t=this.selected.indexOf(n.parent)),-1!==t){const e=this.selected.slice();e.splice(t,1),this.selected=e}else{const t=this.selected.filter(t=>!t.isRootModel()&&!!t.parent),e=t.length>0&&t[0].parent;e&&e!==n.parent&&(!function(t,e){let n=t.parent;for(;n;){const t=e.indexOf(n);-1!=t&&e.splice(t,1),n=n.parent}}(n,t),nu(n,t)),t.push(n),this.selected=t}}else if(n.parent.isGroup())return void(this.selected=[n])}ondragstart_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:i,y:r}=this.toLocal(t.offsetX,t.offsetY);this.selbox={sx:i,sy:r,selected:[]}}ondragmove_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:i,y:r}=this.toLocal(t.offsetX,t.offsetY);if(this.selbox){this.selbox.ex=i,this.selbox.ey=r;const e=t.shiftKey&&(t.ctrlKey||t.metaKey)&&this.selected.length>0?this.selected[0].state.type:null;eu(this,n,this.selbox,t.shiftKey,!1,e),this.invalidate()}}ondragend_selbox(t,e){const{origin:n}=e;n.stuck&&(this.last_pos=null,this.selbox=null,eu(this,null,null,!1,!0),this.invalidate())}});class iu{constructor(t){this.layer=t}draw(t,e,n){const{left:i,top:r,width:s,height:o}=e.bounds;0!=s&&0!=o&&(t.beginPath(),t.rect(i,r,s,o),t.clip(),t.beginPath(),t.strokeStyle="#f26522",t.lineWidth=4,t.shadowBlur=10,t.shadowColor="black",t.shadowOffsetX=0,t.shadowOffsetY=0,t.rect(i,r,s,o),t.stroke(),t.closePath())}}class ru{constructor(t){this.layer=t}draw(t,e,n){const i=e.bounds;t.beginPath(),t.rect(i.left-4/n.x,i.top-4/n.y,i.width+8/n.x,i.height+8/n.y),t.setLineDash([3/n.x,4/n.y]),t.lineWidth=1/n.x,t.strokeStyle="black",t.stroke(),t.setLineDash([]),t.closePath()}}class su{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){const r=n.controls;return!!r&&(r.every((r,s)=>(Math.abs(t-r.x)<=4/i.x&&Math.abs(e-r.y)<=4/i.y&&(this.active={component:n,index:s,handler:r.handler}),!this.active)),!!this.active)}draw(t,e,n){const i=e.controls;i&&i.forEach((e,i)=>{t.beginPath(),t.lineWidth=1/n.x,t.ellipse(e.x,e.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.fillStyle="#ff5d72",t.fill(),t.strokeStyle="#fff",t.stroke()})}onevent(t,e){const{handler:n,component:i,index:r}=this.active;let s=i.toLocal(e.offsetX,e.offsetY);s=i.toParent(s.x,s.y),n&&"function"==typeof n[t]&&n[t](s,r,i)}onmousedown(t){this.onevent("onmousedown",t)}ondragstart(t){const e=this.active;e.changes=il.before([e.component]),this.onevent("ondragstart",t)}ondragmove(t){this.onevent("ondragmove",t)}ondragend(t){this.onevent("ondragend",t);const{component:e,changes:n}=this.active;il.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function ou(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}const au=15*Math.PI/180;class cu{constructor(t){this.layer=t}reset(){this.active=null,this.created=null}get selected(){return this.layer.selected}contains(t,e,n,i){return!!n.mutable&&(n.path.every((r,s)=>(Math.abs(t-r.x)<=4/i.x&&Math.abs(e-r.y)<=4/i.y&&(this.active={component:n,index:s}),!this.active)),!!this.active)}startLinkProcess(t,e,n){try{const i=xl(e,t.app,void 0);return t.rootModel.addComponent(i),this.layer.selected=[i],this.active={component:i,index:1},this.ondragstart(n),i}catch(t){$i(t)}}draw(t,e,n){if(!e.mutable||e.stuck)return;const i=e.path,r=this.active;i.forEach((i,s)=>{t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.fillStyle="#fff",r&&r.component===e&&r.index===s&&(t.strokeStyle="#fa7703",r.toFill&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke()})}ondblclick(t){const e=this.active.component;if(!e.pathExtendable)return;const n=e.path.slice();n.length<3||(n.splice(this.active.index,1),e.path=n)}onmousedown(t){this.active.toFill=!0}ondragstart(t){const{index:e,component:n}=this.active;this.created||(this.active.changes=il.before([n])),0!==e&&e!==n.path.length-1||(this.layer.counterEnd=0===e?n.toEnd||{fromto:"to"}:n.fromEnd||{fromto:"from"})}ondragmove(t){const{component:e,index:n}=this.active||{},{offsetX:i,offsetY:r}=t;let s=e.toLocal(i,r);if(s=e.toParent(s.x,s.y),t.shiftKey){const t=e.path.length;let i=e.isLine()&&0==n?e.path[1]:e.path[(n-1+t)%t];i=e.toParent(i.x,i.y);let r=0;if(t>2){let s;e.isLine()?0==n?s=e.path[2]:1!=n&&(s=e.path[n-2]):s=e.path[(n-2+t)%t],s&&(s=e.toParent(s.x,s.y),r=ou(s,i))}const c=Math.round((ou(i,s)-r)/au)*au+r;s=function(t,e,n){return{x:Math.cos(e)*n+t.x,y:Math.sin(e)*n+t.y}}(i,c,(o=i,a=s,Math.sqrt((a.x-o.x)*(a.x-o.x)+(a.y-o.y)*(a.y-o.y))))}var o,a;if(0===n||n===e.path.length-1){const t=this.layer.anchorTarget=e.rootModel.capture(i,r,t=>!t.isConnectable());if(t){const{x:o,y:a}=t.toLocal(i,r),c=this.layer.get("scale")||{x:1,y:1},l=this.layer.counterEnd,h=(t.anchors||[]).find(n=>{const{name:i,inout:r,multiplicity:s=1/0,position:h,filter:d}=n;if(l){const{anchor:t,fromto:e}=l;if(t&&("out"===t.inout&&"out"===r||"in"===t.inout&&"in"===r))return!1;if("from"===e&&"out"===r||"to"===e&&"in"===r)return!1}else Ki("should not be here.");if(Math.abs(o-h.x)>8/c.x||Math.abs(a-h.y)>8/c.y)return!1;const u=t.findInOutLines(i);return!!u.includes(e)||!(s!==1/0&&u.length>=s)&&(!l||!d||!!d.call(n,l))});h?0==n?e.from={component:t.get("refid"),anchor:h.name,position:s}:e.to={component:t.get("refid"),anchor:h.name,position:s}:0==n?e.from={position:s}:e.to={position:s}}else 0==n?e.from={position:s}:e.to={position:s}}e.mutatePath(null,function(t){const e=t[n]?.z;t[n]=s,void 0!==e&&(s.z=e)})}ondragend(t){const{component:e,index:n,changes:i}=this.active;if(0===n||n===e.path.length-1){const{offsetX:i,offsetY:r}=t,s=e.rootModel.capture(i,r,t=>t===e||t.isLine()),{x:o,y:a}=s.toLocal(i,r),c=this.layer.get("scale")||{x:1,y:1},l=(s.anchors||[]).find(t=>t&&Math.abs(o-t.position.x)<=8/c.x&&Math.abs(a-t.position.y)<=8/c.y);l&&(0==n?e.from={component:s.get("refid"),anchor:l.name}:e.to={component:s.get("refid"),anchor:l.name}),this.layer.endLinkProcess()}if(this.created){const t=new bl({changes:[{component:this.created,to_container:this.created.parent}]});this.created.app.commander.execute(t)}else il.after(i,e.app.commander);e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function lu(t,e,n){return t.filter(t=>{const{name:i,inout:r,multiplicity:s=1/0,filter:o}=t;if(n){const{anchor:t,fromto:e}=n;if(t&&("out"===t.inout&&"out"===r||"in"===t.inout&&"in"===r))return!1;if("from"===e&&"out"===r||"to"===e&&"in"===r)return!1}else if("in"===r)return!1;return!(s!==1/0&&e.findInOutLines(i).length>=s)&&(!o||!n||!!o.call(t,n))})}class hu{constructor(t){this.layer=t}get active(){return this._active?.component.disposed&&(this._active=null),this._active}set active(t){this._active=t}reset(){this.active=null}contains(t,e,n,i){const r=this.active?.component===n&&this.active?.anchor;this.active=null;const s=this.layer.counterEnd;return lu(n.isConnectable()&&!n.disposed&&this.getAnchorHandles(n,i)||[],n,s).every(s=>{const o=r===s.name?2:1;return s&&s.position&&Math.abs(t-s.position.x)<=4*o/i.x&&Math.abs(e-s.position.y)<=4*o/i.y&&(this.active={component:n,anchor:s.name,template:s.template}),!this.active}),!!this.active}getAnchorHandles(t,e){const{width:n,height:i}=t.bounds;return n*e.x<30||i*e.y<30?[]:t.anchors}draw(t,e,n){if(!e.get("refid")||e.isLine())return;const i=this.active,r=this.active?.component===e&&this.active?.anchor,s=this.layer.counterEnd;lu(e.isConnectable()&&!e.disposed&&this.getAnchorHandles(e,n)||[],e,s).forEach(s=>{const{name:o,position:a}=s,c=r===o?2:1;a&&(t.beginPath(),t.ellipse(a.x,a.y,4*c/n.x,4*c/n.y,0,0,2*Math.PI),t.setLineDash([0,0]),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",i&&i.component===e&&i.anchor===o&&(t.strokeStyle="#fa7703",i.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e,anchor:n,template:i}=this.active,r=this.layer.toLocal(t.offsetX,t.offsetY);this.layer.startLinkProcess(e,{type:"ortholine",lineWidth:1,strokeStyle:"black",begin:"oval",beginSize:"size9",end:"arrow",endSize:"size9",lineDash:"solid",lineCap:"butt",round:10,...i,from:{component:e.get("refid"),anchor:n,position:r},to:{position:r}},t)}ondragmove(t){}ondragend(t){}}function du(t,e){const{left:n,top:i,width:r,height:s}=t,o=n+r/2,a=i+s/2,c=n+r,l=i+s,h=r*e.x>50,d=s*e.y>50;return[{x:n,y:i},h?{x:o,y:i}:{x:null,y:null},{x:c,y:i},d?{x:c,y:a}:{x:null,y:null},{x:c,y:l},h?{x:o,y:l}:{x:null,y:null},{x:n,y:l},d?{x:n,y:a}:{x:null,y:null}]}class uu{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.resizable)return!1;const r=du(n.bounds,i);for(let s=0;s<r.length;s++){const o=r[s];if(null!=o.x&&null!=o.y&&Math.abs(t-o.x)<=4/i.x&&Math.abs(e-o.y)<=4/i.y)return this.active={component:n,index:s},!0}return!1}draw(t,e,n){if(e.isLine())return;const{left:i,top:r,width:s,height:o}=e.bounds;if(t.beginPath(),t.rect(i-4/n.x,r-4/n.y,s+8/n.x,o+8/n.y),t.setLineDash([3/n.x,4/n.y]),t.lineWidth=1/n.x,t.strokeStyle="black",t.stroke(),t.setLineDash([]),!e.resizable)return;const a=this.active;du(e.bounds,n).forEach((i,r)=>{null!=i.x&&null!=i.y&&(t.beginPath(),t.rect(i.x-4/n.x,i.y-4/n.y,8/n.x,8/n.y),t.setLineDash([]),t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",a&&a.component===e&&a.index===r&&(t.strokeStyle="#fa7703",a.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e}=this.active;this.active.bounds=e.bounds,this.active.boundsList=this.layer.selected.filter(t=>t.resizable).map(t=>t.bounds)}_resizeAll(t,e){const{component:n,index:i,boundsList:r,bounds:s}=this.active,o=n.scalable?this.layer.toLocal(t.offsetX,t.offsetY):{x:t.offsetX,y:t.offsetY};n.bounds=s;const a=function(t,e,n){const{left:i,top:r,width:s,height:o}=t.bounds;let a,c;switch(e){case 0:a=i,c=r;break;case 1:a=i+s/2,c=r;break;case 2:a=i+s,c=r;break;case 3:a=i+s,c=r+o/2;break;case 4:a=i+s,c=r+o;break;case 5:a=i+s/2,c=r+o;break;case 6:a=i,c=r+o;break;case 7:a=i,c=r+o/2}const l=a,h=c,d=t.fromScene(n.x,n.y);return{dx:d.x-l,dy:d.y-h}}(n,i,o);this.layer.selected.filter(t=>t.resizable).forEach((n,s)=>{n.bounds=r[s],function(t,e,n,i,r,s){let{left:o,top:a,width:c,height:l}=t.bounds;const h={left:o,top:a,width:c,height:l};switch(e){case 0:o+=i,a+=r,c-=i,l-=r;break;case 1:a+=r,l-=r;break;case 2:a+=r,c+=i,l-=r;break;case 3:c+=i;break;case 4:c+=i,l+=r;break;case 5:l+=r;break;case 6:o+=i,c-=i,l+=r;break;case 7:o+=i,c-=i}if(t.mutateBounds(function(e){return Math.abs(c)<=.001&&(c=.001),Math.abs(l)<=.001&&(l=.001),t.adjustResize({left:o,top:a,width:c,height:l},h,n)},this),t.isContainer()&&t.layout.ABSOLUTE&&!t.isGroup()){const e=h.left-o,n=h.top-a;return void(s?t.components.forEach(t=>{t.delta("tx",0),t.delta("ty",0),t.move({x:e,y:n},!1)}):t.components.forEach(t=>{t.delta("tx",e),t.delta("ty",n)}))}const d=s&&t.parent;d&&d.isGroup()&&d.calculateBounds()}(n,i,t.shiftKey,a.dx,a.dy,e)})}ondragmove(t){this._resizeAll(t,!1)}ondragend(t){this._resizeAll(t,!0),this.active.component.app.commander.execute(null,!1)}}const pu=2*Math.PI,fu=Math.PI/2;function gu(t,e){const n=t.bounds;return{x:n.left+n.width/2,y:n.top-20/e.y}}class mu{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.rotatable)return!1;const r=gu(n,i);return Math.abs(t-r.x)<=4/i.x&&Math.abs(e-r.y)<=4/i.y&&(this.active={component:n},!0)}draw(t,e,n){if(!e.rotatable)return;t.beginPath();const i=gu(e,n);t.lineWidth=1.5/n.x,t.moveTo(i.x,i.y+20/n.y),t.lineTo(i.x,i.y),t.strokeStyle="#656565",t.stroke(),t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,pu,!0),t.stroke(),t.fillStyle="#fff",t.fill();const r=this.active;r&&r.component===e&&(t.strokeStyle="#fa7703",t.stroke(),r.toFill&&(t.fillStyle="#ffb80c",t.fill()))}onmousedown(t){this.active.toFill=!0}ondragstart(t){const e=this.active;e.start_rotation=e.component.get("rotation"),e.rotations=this.layer.selected.filter(t=>t.rotatable).map(t=>t.get("rotation"))}ondragmove(t){const{component:e}=this.active;let n;e.scalable?(n=e.toLocal(t.offsetX,t.offsetY),n=e.toParent(n.x,n.y)):(n={x:t.offsetX,y:t.offsetY},e.parent?.isRootModel()||(n=e.toParent(n.x,n.y)));const i=e.rotatePoint,r=e.get("rotation")||0;let s=Math.atan((i.y-n.y)/(i.x-n.x));s=i.x>=n.x?s-fu:fu+s;const o=s-r;this.layer.selected.filter(t=>t.rotatable).forEach((e,n)=>{const i=((e.get("rotation")||0)+o)%pu;e.set("rotation",e.adjustRotation(i,t.shiftKey))})}ondragend(t){const{component:e}=this.active;e.app.commander.execute(null,!1)}}cc.register("modeling-layer",class extends Nc{constructor(t,e){super(t,e),this.pathHandler=new cu(this);const n=this.pathHandler,i=new su(this),r=new uu(this),s=new mu(this);this._modelers=[n,i,r,s],this._control_mode_modelers=[i,n,r,s],this.focusOutline=new iu(this),this.groupOutline=new ru(this),this.anchorHandler=new hu(this),this._reversed_modelers=this._modelers.slice().reverse(),this._control_mode_reverse_modelers=this._control_mode_modelers.slice().reverse(),this.hovered=null,this.hoveredDest=null}get modelers(){return this._control_mode?this._control_mode_modelers:this._modelers}get reversedModelers(){return this._control_mode?this._control_mode_reverse_modelers:this._reversed_modelers}async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}capture(t,e,n){return!!this.contains(t,e)&&this}contains(t,e){let n=this.selected.filter(t=>!!t.parent);const i=this.fromParent(t,e),r=this.get("scale")||{x:1,y:1};let s;if(this._state_dragging){if(this._counter_end){let n=r;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(i.x,i.y):(s=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(s.x,s.y,this.anchorTarget,n))return!0}return!0}this.modelers.forEach(t=>t.reset()),n=this.selected.filter(t=>!!t.parent);for(let o=0;o<n.length;o++){const a=n[o];let c=r;a.scalable?s=a.fromScene(i.x,i.y):(s=a.fromScene(t,e),c={x:1,y:1});for(let t=0;t<this.modelers.length;t++){const e=this.modelers[t];if(e.contains(s.x,s.y,a,c))return this.currentModeler=e,!0}}if(this.anchorTarget){let n=r;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(i.x,i.y):(s=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(s.x,s.y,this.anchorTarget,n))return this.currentModeler=this.anchorHandler,!0}else this.anchorHandler.reset();return this.currentModeler=null,!1}_componentDrawer(t,e,n,i){const r=[];let s=e.parent;if(e.isRootModel())return t.save(),i(t,e,n),void t.restore();for((t=this.getContext(e))==this.auxContext2D&&(n={x:1,y:1});s&&!s.isRootModel();)r.push(s),s=s.parent;t.save(),r.reverse().forEach(function(e){const n=e.rotatePoint;t.translate(n.x,n.y);const i=e.get("scale");i&&t.scale(i.x,i.y),t.rotate(e.get("rotation")),t.translate(-n.x,-n.y);const r=e.bounds;t.translate(r.left,r.top)});const o=e.rotatePoint;t.translate(o.x,o.y);const a=e.get("scale");a&&t.scale(a.x,a.y),t.rotate(e.get("rotation")),t.translate(-o.x,-o.y),i(t,e,n),t.restore()}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:i}=this.model;t.save(),t.beginPath(),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.rect(0,0,t.canvas.width,t.canvas.height),t.fillStyle="black",t.globalAlpha=.5,t.fill(),t.restore(),e&&t.translate(e.x*Hr,e.y*Hr),t.scale(n.x*Hr,n.y*Hr),i&&t.rotate(i),t.clearRect(0,0,this.rootModel.get("width"),this.rootModel.get("height"))}render(t){if(this.rootModel?.is3dMode)return;t.beginPath();const e=this.get("scale")||{x:1,y:1},n=this.selected.filter(t=>!!t.parent);if(this.anchorTarget&&this._componentDrawer(t,this.anchorTarget,e,(t,e,n)=>{this.anchorHandler.draw(t,e,n)}),this.focused&&this._componentDrawer(t,this.focused,e,(t,e,n)=>{this.focusOutline.draw(t,e,n)}),n.length>0&&n[0].parent.isGroup()){let i=n[0].parent;for(;i.parent.isGroup();)i=i.parent;this._componentDrawer(t,i,e,(t,e,n)=>{this.groupOutline.draw(t,e,n)})}n.forEach(n=>{this._componentDrawer(t,n,e,(t,e,n)=>{this.reversedModelers.forEach(i=>i.draw(t,e,n))})})}get anchorTarget(){return this.currentModeler===this.anchorHandler||this.currentModeler===this.pathHandler||this.hovered?.isLine()||(this._anchorTarget=this.hovered),this._anchorTarget}set anchorTarget(t){this._anchorTarget=t}get hovered(){return this._hovered}set hovered(t){this._hovered=t,this.invalidate()}startLinkProcess(t,e,n){this.currentModeler=this.pathHandler,this.processingLink=this.pathHandler.startLinkProcess(t,e,n),this.counterEnd=this.processingLink.fromEnd,this.processingLink.trigger("tag")}set counterEnd(t){this.currentModeler=this.pathHandler,this._counter_end=t}get counterEnd(){return this._counter_end}endLinkProcess(){this.processingLink?.trigger("tagreset"),this.processingLink=null,this._counter_end=null}get eventMap(){return{"model-layer":{"(all)":{change:this.onchange_model,wheel:this.onwheel_scale,drop:this.ondrop},"(descendant)":{mouseenter:this.onmouseenter,mouseleave:this.onmouseleave},"(self)":{dblclick:this.ondblclick_model}},"(root)":{"(self)":{selected:this.onselected,keydown:this.onkeydown,keyup:this.onkeyup}}}}onmouseenter(t,e){this.hovered=e?.origin}onmouseleave(t,e){this.hovered=null}onkeydown(t){"Alt"==t.key&&(this._control_mode=!0,this.invalidate())}onkeyup(t){"Alt"==t.key&&(this._control_mode=!1,this.invalidate())}onselected(t,e){this.invalidate()}onchange_model(t,e,n){const{origin:i,deliverer:r}=n;i===r&&(t.translate&&this.set("translate",t.translate),void 0!==t.rotation&&this.set("rotation",t.rotation),t.scale&&this.set("scale",t.scale)),this.invalidate()}ondblclick_model(t,e){const n=e.origin;n?.root.fit()}ondblclick(t){"function"==typeof this.currentModeler.ondblclick&&this.currentModeler.ondblclick(t),this.invalidate()}onmousedown(t){this.currentModeler.onmousedown(t),this.invalidate()}onmouseup(t){"function"==typeof this.currentModeler.onmouseup&&this.currentModeler.onmouseup(t),this.invalidate()}ondragstart(t){this.currentModeler.ondragstart(t),this._state_dragging=!0}ondragmove(t){this.currentModeler.ondragmove(t),this.invalidate()}ondragend(t){this._state_dragging=!1,this.currentModeler.ondragend(t),this.invalidate()}ondrop(t,e){const{origin:n}=e,i=t.dataTransfer.files;if(i.length<1)return;const r=this.rootModel.toLocal(t.offsetX,t.offsetY),s=this.rootModel;Promise.all(Array.from(i).map(t=>new Promise((e,n)=>{const i=new FileReader;i.addEventListener("loadend",t=>{e(i.result)}),["error","abort"].forEach(t=>i.addEventListener(t,t=>{n(t)})),i.readAsDataURL(t)}))).then(e=>{if(t.altKey)return il.around(this.app.commander,()=>{n.ondropfile(i,e)}),void(this.selected=[n]);const o=[],a=e.map((t,e)=>{let n;const a=i[e].type,c=i[e].name;return a.startsWith("image/")?(n=xl({type:a.startsWith("image/gif")?"gif-view":"image-view",top:0,left:0,width:200,height:200,src:t},s.app),o.push(new Promise((e,i)=>{const r=new Image;r.src=t,r.onload=()=>{n.set({width:r.width,height:r.height}),e()},r.onerror=t=>{i(t)}}))):a.startsWith("audio/")?n=xl({type:"audio",top:0,left:0,width:100,height:100,src:t},s.app):a.startsWith("vnd.ms-excel/")||/\.xlsx?$/.test(c)?n=xl({type:"excel",top:0,left:0,width:100,height:100,src:t},s.app):Qi("dropped file",i[e]),n&&(n.center=r,r.x+=50,r.y+=50),n}).filter(Boolean).map(t=>({component:t,to_container:s}));a.length>0&&Promise.all(o).then(()=>{this.app.commander.execute(new bl({changes:a})),this.selected=a.map(t=>t.component)},t=>{Ki(t)})},t=>{Ki(t)})}onwheel_scale(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer;let i;if(t.shiftKey)i=-1!=navigator.userAgent.indexOf("Win")?t.deltaY<0?1:-1:t.deltaX<0?1:-1,t.altKey?il.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("letterSpacing")||Gr.LETTER_SPACING;e+=i,t.set("letterSpacing",e)})}):il.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("fontSize")||Gr.FONT_SIZE;e<1&&(e=1),e+=i,t.set("fontSize",e)})});else{i=t.deltaY<0?1:-1;const e=n.get("scale")||{x:1,y:1},r=n.get("translate"),s=t.offsetX,o=t.offsetY,a=n.toLocal(s,o),c=.1*i,l={x:e.x+c,y:e.y+c};if(i<0&&e.x<.2||i>0&&e.x>10)return;n.set("scale",l);const h=n.toLocal(s,o);n.set("translate",{x:r.x+(h.x-a.x)*l.x,y:r.y+(h.y-a.y)*l.y})}}});cc.register("scroll-layer",class extends Bc{get capturable(){return!0}get pointerEvents(){return"none"}render(t){const{scrolling:e}=this.state;if(t.save(),t.beginPath(),t.fillStyle="#777",this.vscroller){const{left:n,top:i,width:r,height:s}=this.vscroller;t.globalAlpha="v"==e?1:.3,t.fillRect(n,i,r,s)}if(this.hscroller){const{left:n,top:i,width:r,height:s}=this.hscroller;t.globalAlpha="h"==e?1:.3,t.fillRect(n,i,r,s)}t.stroke(),t.restore()}resize(){super.resize(),this.calcScrollerBounds()}contains(t,e){const n=this.vscroller,i=this.hscroller;return this.setState("scrolling",n&&t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height?"v":i&&t>=i.left&&t<=i.left+i.width&&e>=i.top&&e<=i.top+i.height?"h":null),!!this.getState("scrolling")}get eventMap(){return{"(root)":{"model-layer":{change:this.onchangeModelLayer}}}}onchange(t){"scrolling"in t&&this.invalidate()}ondragstart(t,e){this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragmove(t,e){const n=this.root,{clientWidth:i,clientHeight:r}=this.canvas,{width:s,height:o}=this.rootModel.model,{x:a,y:c}={x:t.offsetX,y:t.offsetY},{x:l,y:h}=this._scale,{scrolling:d}=this.state,u=s/i,p=o/r;d&&n.rootModel.move({x:"h"==d?(-a+this.lastPosition.x)*l*u:0,y:"v"==d?(-c+this.lastPosition.y)*h*p:0},!1),this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragend(){delete this.lastPosition,this.setState({scrolling:null})}calcScrollerBounds(){if(!this.rootModel)return;const{clientWidth:t,clientHeight:e}=this.canvas,{width:n,height:i}=this.rootModel.model,{x:r=1,y:s=1}=this._scale||{},{x:o=0,y:a=0}=this._translate||{},c=n/t,l=i/e;let h={left:-o/r/c,top:e-10,width:t/r/c,height:10};this.hscroller=h.left>1||h.width+h.left<t-1?h:null,h={left:t-10,top:-a/s/l,width:10,height:e/s/l},this.vscroller=h.top>1||h.height+h.top<e-1?h:null,this.invalidate()}onchangeModelLayer(t,e,n){if(t.scale){const{x:e=1,y:n=1}=t?.scale||{};this._scale={x:e,y:n},this.calcScrollerBounds()}if(t.translate){const{x:e=0,y:n=0}=t.translate||{};this._translate={x:e,y:n},this.calcScrollerBounds()}}});const yu="#ff3366",bu=[3,3];function vu(){const t=arguments,e=t[t.length-1],n=this.event_pump;n.listeners.forEach(i=>{!function(t,e,n,i,r){for(const s in n){const o=n[s];if(Oa(s,i.origin,0,t))for(const t in o){const n=o[t];t==i.name&&(i.listener=e,n.apply(e,r))}}}(n.deliverer,i.listener,i.cloned_handlers,e,t)})}cc.register("snap-guide-layer",class extends Bc{constructor(){super(...arguments),this._snapResult=null}get pointerEvents(){return"none"}get capturable(){return!1}contains(t,e){return!1}get snapResult(){return this._snapResult}set snapResult(t){this._snapResult=t,this.invalidate()}clear(){this._snapResult&&(this._snapResult=null,this.invalidate())}get eventMap(){return{"(root)":{"model-layer":{change:this.onchange_root_model}}}}onchange_root_model(t){(t.translate||t.scale)&&this.syncTransform()}syncTransform(){const t=this.rootModel;if(!t)return;const e=t.get("translate")||{x:0,y:0},n=t.get("scale")||{x:1,y:1};this.set({translate:e,scale:n})}async ready(){await super.ready(),this.syncTransform()}render(t){const e=this._snapResult;if(e&&0!==e.guides.length){t.save(),t.strokeStyle=yu,t.fillStyle=yu,t.lineWidth=1,t.setLineDash(bu);for(let n=0,i=e.guides.length;n<i;n++){const i=e.guides[n];t.beginPath(),"x"===i.axis?(t.moveTo(i.position,i.from),t.lineTo(i.position,i.to)):(t.moveTo(i.from,i.position),t.lineTo(i.to,i.position)),t.stroke()}t.restore()}}});class _u{constructor(t){if(void 0===t.on)throw new Error("Deliverer should be a event handlable object.");this.deliverer=t,this.listeners=[]}start(){this.deliverer.on("(all)",vu,{event_pump:this})}stop(){this.deliverer.off("(all)",vu)}on(t,e){const n=Object.assign({},e);Object.keys(n).forEach(e=>{if(0==e.indexOf("?")){const i=n[e],r=e.substr(1),s=t.get(r);delete n[e],s?n[s]=i:$i("EventPump#on","variable #{selector} is not evaluated on listener")}}),this.listeners.push({listener:t,handlers:e,cloned_handlers:n})}off(t,e){for(let n=0;n<this.listeners.length;n++){const i=this.listeners[n];i.listener!==t||e&&i.handlers!==e||this.listeners.splice(n,1)}}clear(){this.listeners=[]}dispose(){this.stop(),this.clear()}}class xu{constructor(t){this.eventMaps=[],this.root=t,t.eventMap&&this.add(t,t.eventMap)}set root(t){this._root=t}get root(){return this._root}stop(){this.eventMaps.forEach(t=>t.eventPump.stop())}add(t,e){if(this.root)for(const n in e){const i=e[n];if("(self)"===n&&void 0===t.on)throw new Error("(self) selector not available when deliverer is not a event handlable object.");La(n,this.root,t).forEach(n=>{const r=new _u(n);r.on(t,i),r.start(),this.eventMaps.push({eventPump:r,listener:t,handlerMap:e,deliverer:n})})}}remove(t,e){const n=this.eventMaps.slice(0);for(let i=0;i<n.length;i++){const r=n[i];r.listener!==t||e&&r.handlerMap!==e||(this.eventMaps.splice(i,1),r.eventPump.dispose())}}clear(){this.eventMaps.slice(0).forEach(t=>t.eventPump.dispose()),this.eventMaps=[]}dispose(){this.stop(),this.clear()}}const wu=0,Mu=1,Su=2,ku=0,Au=1,Eu=2;let Cu={},Tu=0;class Pu{constructor(t,e){this._type=e||t.type,this._ctrlKey=t.ctrlKey,this._altKey=t.altKey,this._shiftKey=t.shiftKey,this._metaKey=t.metaKey;const n=function(t){if(t.touches){const e=t.touches[0];if(!e)return Cu;const n=e.target.getBoundingClientRect();return Cu={x:t.offsetX||e.clientX-n.left,y:t.offsetY||e.clientY-n.top},Cu}return{x:t.offsetX,y:t.offsetY}}(t);if(this._offsetX=n.x,this._offsetY=n.y,t.touches&&t.touches[0]?(this._clientX=t.touches[0].clientX,this._clientY=t.touches[0].clientY):(this._clientX=t.clientX,this._clientY=t.clientY),"wheel"==t.type)this.deltaX=t.deltaX,this.deltaY=t.deltaY,this.deltaZ=t.deltaZ;else if("drop"==t.type)this.dataTransfer=t.dataTransfer;else if(t.type.match(/^touch/)&&(this._scale=t.scale,this._touches=t.touches,this._changedTouches=t.changedTouches,null==this._scale)){const e=function(t){let e,n,i=0,r=0,s=0;if(1===t.touches.length)return s;Array.from(t.touches).forEach(t=>{e=null!=e?Math.min(t.screenX,e):t.screenX,i=Math.max(t.screenX,i),n=null!=n?Math.min(t.screenY,n):t.screenY,r=Math.max(t.screenY,r)});const o=i-e||0,a=r-n||0;return s=Math.sqrt(Math.pow(o,2)+Math.pow(a,2))||0,s}(t);Tu>0&&(this._scale=e/Tu),Tu=e}}get type(){return this._type}set type(t){this._type=t}get offsetX(){return this._offsetX}get offsetY(){return this._offsetY}get altKey(){return this._altKey}get ctrlKey(){return this._ctrlKey}get shiftKey(){return this._shiftKey}get metaKey(){return this._metaKey}get clientX(){return this._clientX}get clientY(){return this._clientY}get touches(){return this._touches}get changedTouches(){return this._changedTouches}get scale(){return this._scale}stopPropagation(){this._stop_=!0,this.originalEvent?.stopPropagation()}isPropagationStopped(){return this._stop_}preventDefault(){this._prevented=!0}isDefaultPrevented(){return this._prevented}}function Du(t,e,n){if(!t||!t.app)return;if(t.app.isViewMode&&t.hidden)return;n instanceof Pu&&e===n.type||(n=new Pu(n,e));const i="on"+e;t[i]&&t[i](n),n.isPropagationStopped()||t.trigger(e,n)}class Ou{constructor(t,e){this.gestureHandlerBuilder=t=>{const e=this[`on${t}`];return t=>{const n=new Pu(t),i=this.getChildScrollOffset();return n._offsetX+=this.html_element.scrollLeft+i.scrollLeft,n._offsetY+=this.html_element.scrollTop+i.scrollTop,e(n),n.isDefaultPrevented()&&t.preventDefault(),!1}},this.keyeventHandlerBuilder=t=>this[`on${t}`],this.ondragover=t=>(Du(this.findTarget(t),t.type,t),!1),this.ondrop=t=>(Du(this.findTarget(t),t.type,t),!1),this.ondblclick=t=>(Du(this.findTarget(t),t.type,t),this.last_target=null,!1),this.onkeydown=t=>(this.container.trigger(t.type,t),!1),this.onkeyup=t=>(this.container.trigger(t.type,t),!1),this.onmousemove=t=>{switch(this.status){case Mu:const e=t.offsetX-this.__dragstart_e.offsetX,n=t.offsetY-this.__dragstart_e.offsetY;if(e*e+n*n<16)break;this.status=Su,Du(this.last_target,"dragstart",this.__dragstart_e),this.__dragmove_e=t,Du(this.last_target,"dragmove",t);break;case Su:this.__dragmove_e=t,Du(this.last_target,"dragmove",t);break;default:{const e=this.findTarget(t);this.last_enter_target!==e&&(this.last_enter_target&&Du(this.last_enter_target,"mouseleave",t),e&&Du(e,"mouseenter",t),this.last_enter_target=e),Du(e,t.type,t),this.last_target=e}}return!1},this.onmousedown=t=>{if(this.status===Su)Du(this.last_target,"dragend",t),this.last_target=null,this.status=wu;else{const e=this.findTarget(t);this.last_target=e,this.status=Mu,this.__dragstart_e=t,Du(e,t.type,t)}return!1},this.onmouseup=t=>{if(this.status===Su)Du(this.last_target,"dragend",t);else{const e=this.findTarget(t);Du(e,t.type,t),this.last_target===e&&Du(e,"click",t)}return this.last_target=null,this.status=wu,!1},this.onmouseout=t=>{const e=this.findTarget(t);if(this.status===Su)Du(this.last_target,"dragend",t);else{if(this.last_target&&this.last_target===e)return;this.last_enter_target&&(Du(this.last_enter_target,"mouseleave",t),delete this.last_enter_target)}return this.last_target=null,this.status=wu,!1},this.ontouchstart=t=>{const e=this.findTarget(t);return this.last_target=e,this.status=Au,this.touchPoints||(this.touchPoints=[]),this.touchPoints.push(t.changedTouches[0]),this.holdTimer=setTimeout(()=>{this.status=ku,Du(this.last_target,"hold",t),delete this.holdTimer},500),Du(e,t.type,t),!1},this.ontouchmove=t=>{if(!t.touches||!t.changedTouches)return Du(this.last_target,"dragstart",t),Du(this.last_target,"dragmove",t),!1;let e=this.findTarget(t);switch(this.status){case Au:Array.from(t.changedTouches).forEach(t=>{const e=this.touchPoints.find(e=>e.identifier===t.identifier);if(!e)return;const n=e.clientX-t.clientX,i=e.clientY-t.clientY;return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))>=16?(this.status=Eu,void(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer))):void 0});break;case Eu:if(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer),2===t.changedTouches.length&&null!=t.scale&&1!==t.scale&&(t.scale<.9||t.scale>1.1))return Du(this.last_target,"pinch",t),!1;Du(this.last_target,"pan",t),e=this.last_target;break;default:this.last_enter_target!==e&&(this.last_enter_target&&Du(this.last_enter_target,"mouseleave",t),e&&Du(e,"mouseenter",t),this.last_enter_target=e),this.last_target=e}return Du(e,"touchmove",t),!1},this.ontouchend=t=>{let e=this.findTarget(t);switch(this.status){case Eu:e=this.last_target;break;case Au:{const n=performance.now(),i=n-this.touchedAt;this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer,Du(e,i<500?"doubletap":"tap",t),this.touchedAt=n);break}}Du(e,"touchend",t);const n=this.touchPoints.findIndex(e=>e.identifier===t.changedTouches[0].identifier);return this.touchPoints.splice(n,1),this.last_target=null,this.status=ku,!1},this.onwheel=t=>(Du(this.findTarget(t),t.type,t),!1),this.container=t,this.html_element=e,this.status=wu,this.last_target=null,this.gesture_handlers=Yr.map(t=>this.gestureHandlerBuilder(t)),this.keyevent_handlers=Vr.map(t=>this.keyeventHandlerBuilder(t)),Yr.forEach((t,n)=>e.addEventListener(t,this.gesture_handlers[n]),{passive:!1}),Vr.forEach((t,n)=>e.addEventListener(t,this.keyevent_handlers[n])),e.ondragover=this.gestureHandlerBuilder("dragover"),e.ondrop=this.gestureHandlerBuilder("drop"),e.tabIndex=1}dispose(){this.last_enter_target&&Du(this.last_enter_target,"mouseleave",new CustomEvent("mouseleave")),Yr.forEach((t,e)=>this.html_element.removeEventListener(t,this.gesture_handlers[e])),Vr.forEach((t,e)=>this.html_element.removeEventListener(t,this.keyevent_handlers[e])),delete this.gesture_handlers,delete this.keyevent_handlers,delete this.last_target}getChildScrollOffset(){for(const t of this.html_element.children)if(t.scrollTop>0||t.scrollLeft>0)return{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop};return{scrollLeft:0,scrollTop:0}}findTarget(t){const e=this.container.rootModel;if(e?.is3dMode)return e;const n=this.html_element.getBoundingClientRect(),i=this.getChildScrollOffset(),r=t.clientX-n.left+this.html_element.scrollLeft+i.scrollLeft,s=t.clientY-n.top+this.html_element.scrollTop+i.scrollTop;return this.container.capture(r,s)}}function zu(t,e,n,i=0){if(e.length<2)return e;let r=2;for(;r<e.length;r++){const s=e.substring(0,r);if(!(t.measureText(s).width+(s.length-1)*i<n))break}return e.substring(0,r-1)}function Iu(t,e,n,i,r=0){const s=String(e).split("\n");return i?[].concat.apply([],s.map(e=>function(t,e,n,i=0){const r=e.split(" "),s=[];let o,a,c=[];for(o=0,a=1;a<=r.length;a++)if(c=r.slice(o,a),t.measureText(c.join(" ")).width+(c.join("").length-1)*i>n){if(a-o==1){const e=zu(t,c[0],n,i);s.push([e]),r.splice(o,1,e,c[0].substring(e.length))}else{for(;""==r[a-1];)a++;s.push(r.slice(o,--a))}o=a}return a-o>1&&s.push(c),0==s.length&&s.push([""]),s}(t,e,n,r))):s.map(t=>t.split(" "))}const Lu={},ju={},Ru=()=>{};var Fu={register:function(t,e,n){Lu[t]=e,n&&(ju[t]=n)},unregister:function(t){delete Lu[t],delete ju[t]},get:function(t){return Lu[t]},getDisposer:function(t){return ju[t]||Ru}};function Bu(t){if(!t.hasTextProperty||t.textHidden)return;let{text:e="",bold:n=Gr.BOLD,italic:i=Gr.ITALIC,textWrap:r=Gr.TEXT_WRAP,letterSpacing:s=0,fontFamily:o=Gr.FONT_FAMILY,fontColor:a=Gr.FONT_COLOR,textAlign:c=Gr.TEXT_ALIGN,textBaseline:l=Gr.TEXT_BASELINE,fontSize:h=Gr.FONT_SIZE,lineHeight:d=1.2*h}=t.model;const{left:u,top:p,width:f,height:g}=t.textBounds;h||=Gr.FONT_SIZE,d||=1.2*h,t.textHidden=!0;const m=document.createElement("textarea"),y=new AbortController;Yr.forEach(function(t){m.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:y.signal})});const b=t.toGlobal(u,p),{rotation:v,scale:_}=function(t){let e=0,n=1,i=t;for(;i;){e+=i.get("rotation")||0;const{x:t,y:r}=i.get("scale")||{x:1,y:1};n*=Math.max(t,r)||1,i=i.parent}return{rotation:e,scale:n}}(t);m.value=e;const x={position:"absolute",width:f+"px",height:g+"px",padding:"0",fontFamily:o,fontSize:h+"px",lineHeight:d+"px",overflow:"hidden",resize:"none",outline:"none",border:"0",backgroundColor:"transparent",display:"inline-block",color:a};switch(n&&(x.fontWeight="bold"),i&&(x.fontStyle="italic"),c){case"right":case"end":x.textAlign="right";break;case"justify":x.textAlign="justify";break;case"left":case"start":x.textAlign="left";break;default:x.textAlign="center"}const w=[n,i,h+"px",o].filter(Boolean).join(" ");function M(e){const n={left:0,top:0},i=d*function(t,e,n,i,r=0){const s=t.getContext();let o;return s.save(),s.font=n,o=Iu(s,e,i,t.get("textWrap"),r).length,s.restore(),o}(t,e,w,f,s);switch(x.height=i+"px",l){case"top":case"hanging":break;case"bottom":case"alphabetic":n.top=g-i;break;default:n.top=g/2-i/2}if(!r){const i=function(t,e,n,i){const r=e.split("\n");let s=i;const o=t.getContext();return o.save(),o.font=n,r.forEach(t=>{const e=o.measureText(t).width;e>s&&(s=e)}),o.restore(),s}(t,e,w,f);switch(x.width=i+"px",c){case"right":case"end":n.left=f-i;break;case"left":case"start":break;default:n.left=(f-i)/2}}x.marginLeft=n.left+"px",x.marginTop=n.top+"px",x.transform=`translate(${b.x}px, ${b.y}px) scale(${_}) rotate(${v}rad)`,x.transformOrigin=`${-n.left}px ${-n.top}px`,Object.assign(m.style,x)}M(e);const S=t.root.target_element;S.appendChild(m),m.select();let k,A=!1;m.addEventListener("keydown",function(t){t.stopPropagation(),"Escape"!=t.code&&(t.shiftKey||"Enter"!=t.code&&"NumpadEnter"!=t.code)?setTimeout(()=>{M(m.value)}):(A=k.skipUpdate="Escape"==t.code,"function"==typeof document.createEvent?m.dispatchEvent(k):m.fireEvent(k.eventType,k))},{signal:y.signal}),document.createEvent?(k=document.createEvent("HTMLEvents"),k.initEvent("blur",!0,!1)):(k=document.createEventObject(),k.eventType="blur");const E=t.root.selected,C=function(n){t.root.selected=E,t.textHidden=!1,y.abort(),m.removeEventListener("blur",C,!1),m.parentElement&&m.parentElement.removeChild(m),S.focus(),n.skipUpdate||A||t.app.commander.execute(new il({changes:[{component:t,before:{text:e},after:{text:m.value}}]}))};m.addEventListener("blur",C,!1)}Fu.register("text-editor",{"(root)":{"(self)":{keydown:function(t,e){const{deliverer:n}=e,i=n.selected;return!(1!==i.length||!i[0].hasTextProperty)&&(("Enter"==t.code||"NumpadEnter"==t.code)&&(Bu(i[0]),t.preventDefault(),!0))}}},"model-layer":{"(descendant)":{dblclick:function(t,e){Bu(e.origin)}}}});class Nu{constructor(t){const e=[],n=[];for(let i=0,r=t.length;i<r;i++){const r=t[i],s=r.left,o=r.left+r.width,a=s+r.width/2,c=r.top,l=r.top+r.height,h=c+r.height/2;e.push({value:s,perpMin:c,perpMax:l},{value:a,perpMin:c,perpMax:l},{value:o,perpMin:c,perpMax:l}),n.push({value:c,perpMin:s,perpMax:o},{value:h,perpMin:s,perpMax:o},{value:l,perpMin:s,perpMax:o})}e.sort((t,e)=>t.value-e.value),n.sort((t,e)=>t.value-e.value),this.xEdges=e,this.yEdges=n}get empty(){return 0===this.xEdges.length&&0===this.yEdges.length}calculateSnap(t,e,n,i){if(0===this.xEdges.length&&0===this.yEdges.length)return{dx:e,dy:n,guides:[]};const r={left:t.left+e,top:t.top+n,width:t.width,height:t.height},s=r.left,o=s+r.width,a=s+r.width/2,c=r.top,l=c+r.height,h=c+r.height/2,d=this.findBestSnap(this.xEdges,[s,a,o],i),u=this.findBestSnap(this.yEdges,[c,h,l],i),p=d?e+d.correction:e,f=u?n+u.correction:n;if(!d&&!u)return{dx:e,dy:n,guides:[]};const g=[];if(d){const e=t.top+f,n=e+t.height;for(const t of d.matches)g.push({axis:"x",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}if(u){const e=t.left+p,n=e+t.width;for(const t of u.matches)g.push({axis:"y",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}return{dx:p,dy:f,guides:g}}findBestSnap(t,e,n){let i=n+1,r=0,s=[];for(let o=0;o<3;o++){const a=e[o],c=this.searchNearest(t,a,n);if(!c)continue;const l=Math.abs(c.correction);if(l<i)i=l,r=c.correction,s=c.matches;else if(l===i&&c.correction===r)for(const t of c.matches)s.push(t)}return i<=n?{correction:r,matches:s}:null}searchNearest(t,e,n){const i=t.length;if(0===i)return null;let r=0,s=i;for(;r<s;){const n=r+s>>1;t[n].value<e?r=n+1:s=n}let o=-1,a=n+1;if(r<i){const i=t[r].value-e;i<=n&&(o=r,a=i)}if(r>0){const n=e-t[r-1].value;n<a&&(o=r-1,a=n)}if(o<0||a>n)return null;const c=t[o].value,l=c-e,h=[t[o]];for(let e=o-1;e>=0&&t[e].value===c;e--)h.push(t[e]);for(let e=o+1;e<i&&t[e].value===c;e++)h.push(t[e]);return{correction:l,matches:h}}}function Hu(t){const e=t.root;if(!e||!e.assist_layers)return null;for(const t of e.assist_layers)if("snap-guide-layer"===t.state?.type)return t;return null}const Yu=di(function(t,e,n){if(!t.hasSameParentForAllSelected||n)return void(t.focused=null);const i=[];e[0].parent.isGroup()?t.focused=e[0].parent:(e.forEach(t=>{t.path.forEach(e=>{i.push(t.toScene(e.x,e.y))})}),t.focused=t.capturePath(i,e))},300);let Vu;Fu.register("move-handler",{"model-layer":{"(descendant)":{dragstart:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;let r=i.selected;const s=i.selected.filter(t=>!t.stuck);if(r.length!==s.length&&(r=i.selected=s),0==r.length)return;let o;if(r[0].scalable?(o=r[0].toLocal(t.offsetX,t.offsetY),o=r[0].toParent(o.x,o.y)):o={x:t.offsetX,y:t.offsetY},this.last_pos=o,this.direction=0,i.focused=r[0].parent,t.altKey){const t=[],e=new Map;i.selected=i.selected.filter(t=>!t.isRootModel()).map(n=>{const r=wl(n,t=>{const n=i.root.getNewRefid();return void 0!==t&&e.set(t,n),n});return t.push({component:r,to_container:n.parent}),r}).map(t=>(t.replaceRefids(e),t)),t.forEach(({component:t,to_container:e})=>{e.addComponent(t)}),this.duplicates=i.selected.map(t=>({component:t}))}else this.changes=il.before(r);this.snapIndex=function(t){if(0===t.length)return null;const e=t[0].parent;if(!e||!e.components)return null;const n=new Set(t),i=[];for(const t of e.components)t.isLayer?.()||t.stuck||n.has(t)||i.push(t.bounds);return 0===i.length?null:new Nu(i)}(r);const a=n.rootModel?.get("scale"),c=a?(Math.abs(a.x)+Math.abs(a.y))/2:1;this.snapThreshold=5/(c||1)},dragmove:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const r=i.selected;if(0==r.length||!this.last_pos)return;let s;r[0].scalable?(s=r[0].toLocal(t.offsetX,t.offsetY),s=r[0].toParent(s.x,s.y)):s={x:t.offsetX,y:t.offsetY},t.shiftKey?2==this.direction&&(this.direction=0):this.direction=2;let o=s.x-this.last_pos.x,a=s.y-this.last_pos.y;if(0==this.direction){if(o*o+a*a<25)return;Math.abs(o)>Math.abs(a)?this.direction=3:this.direction=4}3==this.direction?a=0:4==this.direction&&(o=0);const c=this.snapIndex,l=c&&!t.metaKey&&!t.ctrlKey,h=o,d=a;if(l){const t=function(t){return 0===t.length?null:1===t.length?t[0].bounds:_s(t.map(t=>t.bounds))}(r);if(t){const e=c.calculateSnap(t,o,a,this.snapThreshold);o=e.dx,a=e.dy;const n=Hu(i);n&&(n.snapResult=e.guides.length>0?e:null)}}else{const t=Hu(i);t&&(t.snapResult=null)}r.forEach(t=>{t.move({x:o,y:a},1===r.length)}),this.last_pos={x:s.x-(h-o),y:s.y-(d-a)},Yu(i,r)},dragend:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const r=i.selected;if(0==r.length)return;const s=r[0].parent,o=i.focused||e.deliverer;if(this.changes&&!o.isGroup())if(i.hasSameParentForAllSelected&&o&&o!==s){const t=this.changes.map(t=>{const{component:e}=t;return{component:e,to_container:o}});i.app.commander.execute(new bl({changes:t}))}else il.after(this.changes,i.app.commander);else if(this.duplicates){this.duplicates=this.duplicates.map(t=>(t.to_container=o,t));const t=new bl({changes:this.duplicates});i.app.commander.execute(t)}r.forEach(t=>{t.parent&&t.parent.calculateBounds&&t.parent.calculateBounds()}),this.last_pos=null,this.changes=null,this.duplicates=null,this.snapIndex=null,this.snapThreshold=5;const a=Hu(i);a&&a.clear(),Yu(i,r,!0)}}},"(root)":{"(self)":{keydown:function(t,e){const{origin:n,deliverer:i}=e,r={},s=t.shiftKey?n.rootModel.MPP:1;switch(t.which){case 37:r.x=-s,r.y=0;break;case 38:r.x=0,r.y=-s;break;case 39:r.x=s,r.y=0;break;case 40:r.x=0,r.y=s;break;default:return}const o=i.selected;il.around(i.app.commander,function(){o.forEach(t=>{!t.stuck&&t.move(r,!1)})})}}}}),Fu.register("shift-handler",{"model-layer":{"(all)":{dragstart:function(t,e){Vu={x:t.offsetX,y:t.offsetY}},dragmove:function(t,e){const{deliverer:n}=e,i=t.offsetX,r=t.offsetY;n.rootModel.move({x:i-Vu.x,y:r-Vu.y},!1),Vu={x:i,y:r}}}}}),Fu.register("zoom-handler",{"model-layer":{"(all)":{wheel:function(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer,i=t.deltaY<0?1:-1,r=n.get("scale")||{x:1,y:1},s=n.get("translate"),o=t.offsetX,a=t.offsetY,c=n.toLocal(o,a),l=.1*i,h={x:r.x+l,y:r.y+l};if(i<0&&r.x<.2||i>0&&r.x>10)return;n.set("scale",h);const d=n.toLocal(o,a);n.set("translate",{x:s.x+(d.x-c.x)*h.x,y:s.y+(d.y-c.y)*h.y})}},"(self)":{dblclick:function(t,e){const n=e.origin;n?.root.fit()}}}});let Gu={},Uu={};function Wu(t){const e={};for(const n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}Fu.register("paste-handler",{"(root)":{"(self)":{stylepastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{fillStyle:e,strokeStyle:r,alpha:s,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:g,textBaseline:m,textOverflow:y,paddingTop:b,paddingBottom:v,paddingLeft:_,paddingRight:x}=t.state;Gu=Jn({fillStyle:e,strokeStyle:r,alpha:s,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:g,textBaseline:m,textOverflow:y,paddingTop:b,paddingBottom:v,paddingLeft:_,paddingRight:x}),n.mode=4}},stylepastestop:function(t){const{deliverer:e}=t,n=e.app;Gu={},4==n.mode&&(n.mode=1)},databindpastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{mappings:e}=t.state;Uu=Jn({mappings:e}),n.mode=5}},databindpastestop:function(t){const{deliverer:e}=t,n=e.app;Uu={},5==n.mode&&(n.mode=1)},pasteapply:function(t,e){const{deliverer:n}=e,i=n.app;t&&(4==i.mode?il.around(i.commander,()=>{t.set(Wu({...t.model,...Gu}))}):5==i.mode&&il.around(i.commander,()=>{t.set(Wu({...t.model,...Uu}))}))},keydown:function(t,e){const{deliverer:n}=e;"Esc"!=t.code&&"Escape"!=t.code||(4==n.app.mode?n.trigger("stylepastestop"):5==n.app.mode&&n.trigger("databindpastestop"))}}},"model-layer":{"(all)":{click:function(t,e){const{deliverer:n}=e,i=n.app;if(4!=i.mode&&5!=i.mode)return;const r=e.origin;4==i.mode?r===n?n.root.trigger("stylepastestop"):r&&il.around(i.commander,()=>{const t=Wu({...r.model,...Gu});r?.set(t)}):r===n?n.root.trigger("databindpastestop"):r&&il.around(i.commander,()=>{const t=Wu({...r.model,...Uu});r?.set(t)})}}}});class Xu{constructor(){this.animatorMap=new Map}waypoint(t,e){this.animatorMap.has(t)&&this.off(t);let{from:n,to:i}=e;if("string"==typeof n&&(n=t.root?.findById(n)),"string"==typeof i&&(i=t.root.findById(i)),!i)return void $i("WaypointAnimation: Source or target component not found");const r=aa(t,{type:"waypoint",fromComponent:n,toComponent:i,...e,onComplete:()=>{this.off(t)}});r&&(this.animatorMap.set(t,r),r.start())}off(t){const e=this.animatorMap.get(t);e&&(e.stop(),this.animatorMap.delete(t))}reset(t){if(this.animatorMap.size>0){for(const t of this.animatorMap.values())t.stop();this.animatorMap.clear()}}dispose(){this.reset(null),this.animatorMap=null}}function qu(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?.reset()}Fu.register("waypoint-handler",{"model-layer":{"(descendant)":{waypoint:function(t,e){const{origin:n}=e,i=n.root;let{waypointHandler:r}=i;r||(r=new Xu,i.waypointHandler=r),r.waypoint(n,t)},waypointoff:function(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?i.off(e):$i("waypoint-handler not found")},waypointreset:qu},"(self)":{waypointreset:qu}}},function(t){const{waypointHandler:e}=t;e&&(e.dispose(),delete t.waypointHandler)});class Ku{constructor(){this.animatorMap=new Map}transition(t,e){this.animatorMap.has(t)&&this.off(t);const n=aa(t,{type:"transition",fromComponent:e.from,toComponent:e.to,...e,onComplete:()=>{this.off(t)}});n&&(this.animatorMap.set(t,n),n.start())}off(t){const e=this.animatorMap.get(t);e&&(e.stop(),this.animatorMap.delete(t))}reset(){for(const t of this.animatorMap.values())t.stop();this.animatorMap.clear()}dispose(){this.reset(),this.animatorMap=null}}function $u(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?.reset()}function Qu(t){return t<.5?2*t*t:1-2*(1-t)*(1-t)}Fu.register("transition-handler",{"model-layer":{"(descendant)":{transition:function(t,e){const{origin:n}=e,i=n.root;let{transitionHandler:r}=i;r||(r=new Ku,i.transitionHandler=r),r.transition(n,t)},transitionoff:function(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?i.off(e):$i("transition-handler not found")},transitionreset:$u},"(self)":{transitionreset:$u}}},function(t){const{transitionHandler:e}=t;e&&(e.dispose(),delete t.transitionHandler)});class Zu{constructor(t){this.active=new Map,this.rafId=0,this._canvas=null,this._ctx=null,this.root=t}isReparenting(t){return this.active.has(t)}getState(t){return this.active.get(t)||null}begin(t,e){if(this.cancel(t),this.root?.app?.suppressAnimations)return this.cleanup3D(t),t.clearCache?.(),void t.invalidate?.();const n={fromWorld:e.fromWorld,toWorld:e.toWorld,from3D:e.from3D,to3D:e.to3D,duration:Math.max(e.duration,1),startTime:performance.now(),progress:0};if(this.active.set(t,n),n.fromWorld&&this.ensureCanvas(),n.from3D){const e=t._realObject?.object3d;if(e){e.position.copy(n.from3D.pos),e.quaternion.copy(n.from3D.quat);const t=n.from3D.fromScale;t&&e.scale.set(t.x,t.y,t.z)}}this.startLoop()}cancel(t){this.active.has(t)&&this.complete(t)}renderComponent(t,e){const n=this.active.get(t);if(!n?.fromWorld||!n?.toWorld||!this._ctx)return;const i=this._ctx,r=n.progress,s=n.fromWorld,o=n.toWorld,a=s.x+(o.x-s.x)*r,c=s.y+(o.y-s.y)*r,l=s.rotation+(o.rotation-s.rotation)*r,h=s.width+(o.width-s.width)*r,d=s.height+(o.height-s.height)*r,{translate:u={x:0,y:0},scale:p={x:1,y:1}}=e.model;i.save(),i.translate(u.x,u.y),i.scale(p.x,p.y),i.translate(a,c),i.rotate(l);const f=t.bounds;if(f&&f.width&&f.height){const t=h/f.width,e=d/f.height;i.scale(t,e),i.translate(-(f.left+f.width/2),-(f.top+f.height/2))}t.render(i),i.restore()}beginDraw(){if(!this._canvas||!this._ctx)return;this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._ctx.save();const t=globalThis.devicePixelRatio||1;this._ctx.scale(t,t)}endDraw(){this._ctx&&this._ctx.restore()}resize(){if(!this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element.clientWidth,n=t.element.clientHeight;t.fitSize(this._canvas,!0,e,n)}dispose(){for(const[t]of this.active)this.cleanup3D(t);this.active.clear(),this.stopLoop(),this.removeCanvas()}ensureCanvas(){if(this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element;this._canvas=document.createElement("canvas"),this._canvas.width=1,this._canvas.height=1,this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.style.zIndex="50",this._canvas.setAttribute("scene","transition-canvas"),e.appendChild(this._canvas);const n=e.clientWidth,i=e.clientHeight;t.fitSize(this._canvas,!0,n,i),this._ctx=this._canvas.getContext("2d")}removeCanvas(){this._canvas&&(this._canvas.parentNode?.removeChild(this._canvas),this._canvas=null,this._ctx=null)}startLoop(){if(this.rafId)return;const t=()=>{this.tick(),this.active.size>0?this.rafId=requestAnimationFrame(t):this.rafId=0};this.rafId=requestAnimationFrame(t)}stopLoop(){this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=0)}tick(){if(this.root?.app?.suppressAnimations){const t=[...this.active.keys()];for(const e of t)this.complete(e);return}const t=performance.now(),e=[];for(const[n,i]of this.active){const r=t-i.startTime,s=Math.min(r/i.duration,1),o=Qu(s);if(i.progress=o,i.from3D&&i.to3D){const t=n._realObject?.object3d;if(t){t.position.lerpVectors(i.from3D.pos,i.to3D.pos,o),t.quaternion.copy(i.from3D.quat).slerp(i.to3D.quat,o);const e=i.from3D.fromScale,n=i.from3D.toScale;e&&n&&t.scale.set(e.x+(n.x-e.x)*o,e.y+(n.y-e.y)*o,e.z+(n.z-e.z)*o)}}n.clearCache?.(),n.invalidate?.(),s>=1&&e.push(n)}for(const t of e)this.complete(t)}complete(t){this.active.get(t),this.cleanup3D(t),this.active.delete(t),t.clearCache?.(),t.invalidate?.();let e=!1;for(const[,t]of this.active)if(t.fromWorld){e=!0;break}e||this.removeCanvas()}cleanup3D(t){const e=t._realObject;e&&(e.object3d&&e.object3d.scale.set(1,1,1),e.suppressTransform=!1,e.update?.())}}const Ju=[],tp=di(function(){Ju.forEach(t=>{t.resize()})},100);"undefined"!=typeof window&&window.addEventListener("resize",tp);class ep extends Fc{constructor(t,e){super(Object.assign({type:"root",scale:{x:1,y:1}},t||{}),e),this._hasSameParentForAllSelected=!1,this._maxRefid=e?.isViewMode?1e6:0,t=t||{},this.fitMode=t.model&&t.model.fitMode,this._app=e,this.style=t.style,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={},this._serviceMap=new Map,this.transitionEffect=new Zu(this),this.target_element=t.target_element,this.rebuildContentModel(this.model.model),Ju.push(this)}registerService(t,e){this._serviceMap.set(t,e)}getService(t){return this._serviceMap.get(t)}unregisterService(t){this._serviceMap.delete(t)}dispose(){Ic.hideAll(this),this.transitionEffect?.dispose(),this._app&&this._app.dispose(),super.dispose(),this._disposeAllResources(),this.target_element=null,this._refresh_mapping_debouncer&&"function"==typeof this._refresh_mapping_debouncer.cancel&&this._refresh_mapping_debouncer.cancel(),delete this._refresh_mapping_debouncer;const t=Ju.indexOf(this);t>=0&&Ju.splice(t,1),this.refidIndexMap.clear(),this.indexMap.clear(),this._serviceMap.clear(),this._maxRefid=0}isRoot(){return!0}get app(){return this._app}get target_element(){return this._target_element}set target_element(t){this._ua_event_handler&&(this._ua_event_handler.dispose(),delete this._ua_event_handler),t&&(t.style.position="absolute",t.style.cursor="default",t.style.overflow="hidden",t.setAttribute("scene","root-container"),this._ua_event_handler=new Ou(this,t)),this.forEach(e=>e.target=t),this._target_element=t}get fitMode(){return this._fitMode}set fitMode(t){this._fitMode=t}get hasSameParentForAllSelected(){return this._hasSameParentForAllSelected}set hasSameParentForAllSelected(t){this._hasSameParentForAllSelected=t}get unitScale(){switch(this.model_layer&&this.model_layer.get("unit")){case"mm":case"cm":case"in":return this.app.PPM/10;default:return 1}}addTemplate(t,e){const n=this.templateMap[t];n&&Ki("Template replaced (duplicated)",t,e,n),this.templateMap[t]=e,delete this.templatePrefixes}removeTemplate(t,e){const n=this.templateMap[t];n!==e?$i("Removing template failed (different)",t,e,n):delete this.templateMap[t],delete this.templatePrefixes}findTemplateFor(t){this.templatePrefixes||(this.templatePrefixes=Object.keys(this.templateMap).sort().reverse());const e=this.templatePrefixes.find(e=>t.startsWith(e));if(e)return this.templateMap[e]}addIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);i?i.push(e):this.indexMap.set(n,[e])}removeIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);if(!i)return;const r=i.indexOf(e);-1===r?$i("Removing index failed (not found)",t,e):(i.splice(r,1),0===i.length&&this.indexMap.delete(n))}addRefidIndex(t,e){null==t&&(t=this.getNewRefid(),e.set("refid",t)),this._maxRefid=Math.max(t,this._maxRefid);const n=this.refidIndexMap.get(t);n&&Ki("Refid Index replaced (has not to be)",t,e,n),this.refidIndexMap.set(t,e)}removeRefidIndex(t,e){if(null==t)return;const n=this.refidIndexMap.get(t);n!==e?Ki("Refid Removing index failed (has not to be)",t,e,n):this.refidIndexMap.delete(t)}getNewRefid(){return this._maxRefid=(this._maxRefid||0)+1,this._maxRefid}async subscribe(t,e){this._app.isViewMode&&t&&this._app&&(e._subscription=await this._app.subscribe(t,e))}async unsubscribe(t,e){e._subscription&&(await e._subscription.unsubscribe(),delete e._subscription)}findById(t){if(!t)return null;const e=this.indexMap.get("#"===t[0]?t.substring(1):t);return e?e[0]:null}findAllById(t){return t&&this.indexMap.get("#"===t[0]?t.substring(1):t)||ep.EMPTY_ARRAY}findByRefid(t){return this.refidIndexMap.get(t)}findOrCreate(t){const e=this.findAllById(t);if(!e||0===e.length){if(this.app&&!this.app.isEditMode){const e=this.findTemplateFor(t);if(e){const n=xl(Object.assign(Jn(e.hierarchy),{id:t,templatePrefix:""}),this.app);return this.model_layer.addComponent(n),[n]}}return[]}return e}resize(){this.components.forEach(t=>{t.resize&&t.resize()}),this.invalidate()}fit(t){const{width:e,height:n,fitMode:i}=this.model_layer.model,r=this.target_element,s=this.model_layer;if(this.fitMode=t||this.fitMode||i||"ratio",e&&n&&r&&r.clientWidth&&r.clientHeight){switch(this.fitMode){case"center":!function(t,e,n){const i=t.unitScale,{width:r,height:s}=e.model;e.set("scale",{x:i,y:i}),e.set("translate",{x:Math.max((n.clientWidth-r*i)/2,0),y:Math.max((n.clientHeight-s*i)/2,0)})}(this,s,r);break;case"both":!function(t,e,n){const{width:i,height:r}=e.model,s=n.clientWidth,o=n.clientHeight;e.set("scale",{x:s/i,y:o/r}),e.set("translate",{x:0,y:0})}(0,s,r);break;case"width":!function(t,e,n){const i=n.clientWidth/e.get("width");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,s,r);break;case"height":!function(t,e,n){const i=n.clientHeight/e.get("height");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,s,r);break;case"ratio":!function(t,e,n){const{width:i,height:r}=e.model,s=n.clientWidth,o=n.clientHeight,a=s/i,c=o/r,l=Math.min(a,c);e.set("scale",{x:l,y:l}),e.set("translate",{x:(s-i*l)/2,y:(o-r*l)/2})}(0,s,r);break;default:!function(t,e){const n=t.unitScale;e.set("scale",{x:n,y:n}),e.set("translate",{x:0,y:0})}(this,s)}this.resize()}}_disposeAllResources(){this.selected=[],this._focused=null,this._ready=!1,this.eventEngine&&(this.assist_handlers&&this.assist_handlers.forEach(t=>{this.eventEngine.remove(t)}),this.eventEngine.dispose(),delete this.eventEngine),(this.model.handlers||[]).map(t=>{Fu.getDisposer(t).call(null,this)}),this.assist_layers&&this.assist_layers.forEach(t=>{t.dispose(),this.removeComponent(t)}),delete this.assist_layers,this.model_layer&&this.model_layer.dispose(),this.model_layer&&this.removeComponent(this.model_layer),delete this.model_layer,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={}}rebuildContentModel(t,e){let n,i;if(e?.preserveThreeD&&this.model_layer?.is3dMode){const t=this.model_layer._threeCapability;t&&(i=t.captureSessionState()),n=this.model_layer.detachThreeCapability()}this._disposeAllResources(),this.eventEngine=new xu(this);const r=this._app?.loadTracker;(t=t||{}).type="model-layer",t.dataLagMonitor&&this._app&&this._app.initLagTracker(t.dataLagMonitor),r?.setPhase("compile"),this.model_layer=xl(t,this.app),this.addComponent(this.model_layer),this.model_layer.target=this.target_element,this.assist_layers=(this.model.layers||[]).map(t=>{const e=xl(t,this.app);if(e)return this.addComponent(e),e.target=this.target_element,e;Ki("Layer compile failed",t)}).filter(Boolean),this.assist_handlers=(this.model.handlers||[]).map(t=>{const e={};return this.eventEngine.add(e,Fu.get(t)),e}),n&&(this.model_layer?.model?.threed?(this.model_layer.adoptThreeCapability(n),i&&n.restoreSessionState(i)):n.dispose()),r?.setPhase("assets"),this._ready=!0,this.traverse(t=>t.ready()),r?.checkComplete(),r?.startGlobalTimeout()}get root(){return this}get anchors(){return[]}get isReady(){return this._ready}get rootModel(){return this.model_layer}get threed(){return this.model_layer?.model?.threed||!1}set threed(t){this.model_layer&&this.model_layer.toggleThreeD(t)}get stuck(){return!0}get data(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].data);return t}set data(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.data=t[e])}}get dataByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.data;return t}set dataByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.data=t[e])}}get values(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].value);return t}set values(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.value=t[e])}}get valuesByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.value;return t}set valuesByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.value=t[e])}}get selected(){return(this._selected||[]).filter(t=>t.parent)}set selected(t){const e=this._selected;if(this._selected=t,!t||t.length<=1)this.hasSameParentForAllSelected=!0;else{const e=t[0].parent;this.hasSameParentForAllSelected=!t.find(t=>t.parent!=e)}this.trigger("selected",t,e)}get focused(){return this._focused}set focused(t){this._focused!==t&&(this._focused=t,this.invalidate())}get style(){return this._style}set style(t){this._style=t,this._compiled_style=t}get hasTextProperty(){return!1}render(){this.components.forEach(t=>t.draw())}contains(t,e){return!0}capturePath(t,e){return this.model_layer.capturePath(t,e)}invalidate(){this.components.forEach(t=>t.invalidate())}_areAliasesEqual(t,e){if(!Array.isArray(t)&&!Array.isArray(e))return!0;if(!Array.isArray(t)||!Array.isArray(e))return!1;if(t.length!==e.length)return!1;const n=[...t].sort(),i=[...e].sort();return n.every((t,e)=>t===i[e])}get eventMap(){return{"(root)":{"(descendant)":{added:this.onadded,removed:this.onremoved,change:this.onchanged}}}}refreshMappings(){if(!this._refresh_mapping_debouncer){if(this.disposed)return;this._refresh_mapping_debouncer=di(function t(e){e.executeMappings(),e.components&&e.components.forEach(e=>t(e))},1e3)}this._refresh_mapping_debouncer(this.model_layer)}_addTraverse(t){t.components&&t.components.forEach(t=>this._addTraverse(t));const{id:e,alias:n,refid:i,tag:r,templatePrefix:s}=t.model;this.addRefidIndex(i,t),e&&this.addIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.addIndex(e,t)}),r&&this.subscribe(r,t),s&&this.addTemplate(s,t);const o=bi({},t.eventMap,t.model.eventMap);this.eventEngine.add(t,o)}_removeTraverse(t){t.components&&t.components.forEach(t=>this._removeTraverse(t));const{id:e,alias:n,refid:i,tag:r,templatePrefix:s}=t.model;this.removeRefidIndex(i,t),e&&this.removeIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.removeIndex(e,t)}),r&&this.unsubscribe(r,t),s&&this.removeTemplate(s,t),this.eventEngine.remove(t)}onadded(t,e){this._addTraverse(e),e._silentAdd||this.refreshMappings(),this.invalidate()}onremoved(t,e){this._removeTraverse(e),this.invalidate()}onchanged(t,e,n){e.templatePrefix&&this.removeTemplate(e.templatePrefix,n.origin),t.templatePrefix&&this.addTemplate(t.templatePrefix,n.origin),e.id&&this.removeIndex(e.id,n.origin),t.id&&this.addIndex(t.id,n.origin),Array.isArray(e.alias)&&e.alias.forEach(t=>{t&&this.removeIndex(t,n.origin)}),Array.isArray(t.alias)&&t.alias.forEach(t=>{t&&this.addIndex(t,n.origin)}),e.tag&&this.unsubscribe(e.tag,n.origin),t.tag&&this.subscribe(t.tag,n.origin),e.id==t.id&&e.class==t.class&&this._areAliasesEqual(e.alias,t.alias)||n.origin._silentAdd||this.refreshMappings()}}ep.EMPTY_ARRAY=[],cc.memoize(ep.prototype,"unitScale",!1);const np=60;class ip{constructor(){this._monitors=new Map,this._disposed=!1}configure(t){const e=Array.isArray(t)?t:[t];for(const t of e)this._monitors.set(t.tag,{config:{...t,warnThreshold:t.warnThreshold??5e3,criticalThreshold:t.criticalThreshold??15e3},fieldKeys:t.timestampField.split("."),samples:new Float64Array(np),writeIdx:0,count:0,baseline:0,baselineSet:!1,baselineSum:0,baselineCount:0,lastLevel:"normal"})}isMonitored(t){return this._monitors.has(t)}recordIfMonitored(t,e){if(this._disposed)return;const n=this._monitors.get(t);if(!n||!e)return;const i=this._extractField(e,n.fieldKeys);if("number"!=typeof i||i<=0)return;const r=Date.now()-i;n.samples[n.writeIdx]=r,n.writeIdx=(n.writeIdx+1)%np,n.count<np&&n.count++,n.baselineSet||(n.baselineSum+=r,n.baselineCount++,n.baselineCount>=5&&(n.baseline=n.baselineSum/n.baselineCount,n.baselineSet=!0))}getStats(t){const e=this._monitors.get(t);if(!e)return null;const{count:n,baseline:i,baselineSet:r}=e;if(0===n)return{tag:t,currentDelta:0,baseline:0,drift:0,driftAvg:0,driftMax:0,trend:"stable",sampleCount:0,level:"normal"};const s=(e.writeIdx-1+np)%np,o=e.samples[s],a=r?o-i:0;let c=0,l=0;const h=this._getRecentDrifts(e);for(const t of h)c+=t,Math.abs(t)>Math.abs(l)&&(l=t);return{tag:t,currentDelta:o,baseline:i,drift:a,driftAvg:h.length>0?c/h.length:0,driftMax:l,trend:this._calcTrend(e),sampleCount:n,level:this._calcLevel(Math.abs(a),e.config)}}getAllStats(){const t=[];for(const e of this._monitors.keys()){const n=this.getStats(e);n&&t.push(n)}return t}evaluateAll(){if(!this._disposed)for(const[t,e]of this._monitors.entries()){const n=this.getStats(t);n&&(n.level!==e.lastLevel&&(e.lastLevel=n.level,this.onLevelChange?.(t,n.level,n)))}}dispose(){this._disposed=!0,this._monitors.clear(),this.onLevelChange=void 0}_extractField(t,e){let n=t;for(const t of e){if(null==n)return;n=n[t]}return n}_getRecentDrifts(t){if(!t.baselineSet||0===t.count)return[];const e=Math.min(t.count,10),n=[];for(let i=0;i<e;i++){const e=(t.writeIdx-1-i+np)%np;n.push(t.samples[e]-t.baseline)}return n.reverse()}_calcTrend(t){if(!t.baselineSet)return"stable";const e=this._getRecentDrifts(t),n=e.length;if(n<3)return"stable";let i=0,r=0,s=0,o=0;for(let t=0;t<n;t++)i+=t,r+=e[t],s+=t*e[t],o+=t*t;const a=(n*s-i*r)/(n*o-i*i),c=r/n,l=e.map(Math.abs),h=l.reduce((t,e)=>t+e,0)/n;if(h>0&&l[n-1]>3*h)return"spike";const d=Math.max(.1*Math.abs(c),50);return a>d?"increasing":a<-d?"decreasing":"stable"}_calcLevel(t,e){return t>=(e.criticalThreshold??15e3)?"critical":t>=(e.warnThreshold??5e3)?"warn":"normal"}}const rp=5e3;class sp{constructor(t){this._entries=new Map,this._phase="fetch",this._phaseHistory=[],this._disposed=!1,this.needsOverlay=!1,this._firstRenderDone=!1,this._options=t||{},this._startTime=performance.now(),this._promise=new Promise(t=>{this._promiseResolve=t}),this._phaseHistory.push({phase:"fetch",timestamp:this._startTime,elapsed:0}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},rp)}get phase(){return this._phase}get phaseHistory(){return this._phaseHistory}get progress(){const t=this._entries.size;if(0===t)return 1;let e=0;for(const t of this._entries.values())"pending"!==t.status&&e++;return e/t}get pending(){const t=[],e=performance.now();for(const n of this._entries.values())"pending"===n.status&&t.push(this._toPublicEntry(n,e));return t}get entries(){const t=performance.now(),e=[];for(const n of this._entries.values())e.push(this._toPublicEntry(n,t));return e}get stats(){let t=0,e=0,n=0,i=0,r=0;for(const s of this._entries.values())switch(s.status){case"loaded":t++;break;case"timeout":e++;break;case"error":n++;break;case"cancelled":i++;break;case"pending":r++}return{total:this._entries.size,loaded:t,timeout:e,error:n,cancelled:i,pending:r,elapsed:this._completedElapsed??performance.now()-this._startTime}}get promise(){return this._promise}markFirstRender(){this._firstRenderDone||this._disposed||(this._firstRenderDone=!0,this.setPhase("render"),this.checkComplete())}setPhase(t){if(this._disposed||this._phase===t||"complete"===this._phase)return;const e=performance.now(),n=this._phaseHistory[this._phaseHistory.length-1];n&&void 0===n.duration&&(n.duration=e-n.timestamp),this._phase=t,"complete"!==t?(this._phaseHistory.push({phase:t,timestamp:e,elapsed:e-this._startTime}),this.onPhase?.(t)):this.onPhase?.(t)}track(t,e,n,i){if(this._disposed)return;const r={id:t,type:e,url:n,startTime:performance.now(),status:"pending"};this._entries.set(t,r),this._options.assetTimeout&&this._options.assetTimeout>0&&(r.timerId=setTimeout(()=>{"pending"===r.status&&(r.status="timeout",r.endTime=performance.now(),r.timerId&&(r.timerId=void 0),this.onTimeout?.(this._toPublicEntry(r)),this._onEntryDone())},this._options.assetTimeout)),i.then(()=>{"pending"===r.status&&(r.status="loaded",r.endTime=performance.now(),this._clearEntryTimer(r),this._onEntryDone())},()=>{"pending"===r.status&&(r.status="error",r.endTime=performance.now(),this._clearEntryTimer(r),this._onEntryDone())})}checkComplete(){if(this._disposed||"complete"===this._phase)return;let t=!1;for(const e of this._entries.values())if("pending"===e.status){t=!0;break}!t&&this._firstRenderDone&&this._doComplete()}startGlobalTimeout(){if(this._disposed)return;const t=this._options.timeout;!t||t<=0||(this._globalTimerId=setTimeout(()=>{if("complete"===this._phase||this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="timeout",e.endTime=t,this._clearEntryTimer(e),this.onTimeout?.(this._toPublicEntry(e)));this._doComplete(!0)},t))}abort(){if(this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="cancelled",e.endTime=t,this._clearEntryTimer(e));this._doComplete(!0)}reset(){for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._entries.clear(),this._phase="fetch",this._startTime=performance.now(),this._phaseHistory=[{phase:"fetch",timestamp:this._startTime,elapsed:0}],this._completedElapsed=void 0,this._firstRenderDone=!1,this.needsOverlay=!1,this._disposed=!1,this._promise=new Promise(t=>{this._promiseResolve=t}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},rp)}dispose(){if(!this._disposed){this._disposed=!0;for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._promiseResolve(),this.onPhase=void 0,this.onProgress=void 0,this.onTimeout=void 0,this.onComplete=void 0,this.onNeedsOverlay=void 0}}_onEntryDone(){this._disposed||(this.onProgress?.(this.stats),this.checkComplete())}_doComplete(t=!1){"complete"!==this._phase&&(this._completedElapsed=performance.now()-this._startTime,this._completedElapsed>rp&&(this.needsOverlay=!0),this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this.setPhase("complete"),this.onComplete?.(this.stats),this._promiseResolve())}_clearEntryTimer(t){t.timerId&&(clearTimeout(t.timerId),t.timerId=void 0)}_toPublicEntry(t,e){const n=t.endTime?t.endTime-t.startTime:(e??performance.now())-t.startTime;return{id:t.id,type:t.type,url:t.url,startTime:t.startTime,status:t.status,elapsed:n}}}let op=13.3;var ap=function(t){return void 0!==t&&(op=t),op};const cp="$base_url";const lp=Math.PI/12;class hp{constructor(t,e){this._postprocessing=!0,this._loadTrackerOwned=!1,this._suppressAnimationsFlag=!1,this._suppressScopeCount=0,this._mode=t,this.screen=ap(),this._baseUrl="undefined"!=typeof window?window.location.origin:null,this._refProvider=e,this.isEditMode&&(this._rotateStep=lp,this._rotateStepForced=!1)}initLoadTracker(t){return this._loadTracker=new sp(t),this._loadTrackerOwned=!0,this._loadTracker}get loadTracker(){return this._loadTracker}adoptLoadTracker(t){this._loadTracker=t,this._loadTrackerOwned=!1}initLagTracker(t){return this._lagTracker=new ip,this._lagTracker.configure(t),this._lagTracker}get lagTracker(){return this._lagTracker}dispose(){this._loadTrackerOwned&&this._loadTracker?.dispose(),this._loadTracker=void 0,this._lagTracker?.dispose(),this._lagTracker=void 0,this._dataSubscriptionProvider?.dispose?.(),delete this._dataStorage}_calcScreen(){const t={width:screen.width,height:screen.height};this._PPI=function(t,e,n,i="d"){t<=0&&(t=1),e<=0&&(e=1);const r=("d"===i?Math.sqrt(t*t+e*e):"w"===i?t:e)/n;return r>0?Math.round(r):0}(t.width,t.height,this.screen),this._PPM=this._PPI/25.4}subscribe(t,e){return this._dataSubscriptionProvider?.subscribe?.(t,e)}get refProvider(){return this._refProvider}set dataSubscriptionProvider(t){this._dataSubscriptionProvider=t}get dataSubscriptionProvider(){return this._dataSubscriptionProvider}set commander(t){this._commander=t}get commander(){return this._commander}get screen(){return this._screen}set screen(t){this._screen=t,this._calcScreen()}get DPPX(){return Hr}get PPI(){return this._PPI}get PPM(){return this._PPM}get mode(){return this._mode}set mode(t){const e=this._mode;e!==t&&(this._mode=t,this.trigger("mode",t,e))}get isViewMode(){return 0===this._mode}get isEditMode(){return 1===this._mode}get baseUrl(){return this._baseUrl}set baseUrl(t){t&&this._baseUrl!==t&&(this._baseUrl=t)}url(t){try{let e;return e=t.includes(cp)?new URL(t.replace(cp,this.baseUrl??""),this.baseUrl??void 0):new URL(t,location.origin),e.href}catch(e){$i(e,t)}}get rotateStep(){return this._rotateStep}set rotateStep(t){this._rotateStep=Number(t)||lp}get rotateStepForced(){return this._rotateStepForced}set rotateStepForced(t){this._rotateStepForced=!!t}get dataStorage(){return this._dataStorage}set dataStorage(t){this._dataStorage=t}get postprocessing(){return this._postprocessing}set postprocessing(t){this._postprocessing=t}get suppressAnimations(){return this._suppressAnimationsFlag||this._suppressScopeCount>0}set suppressAnimations(t){this._suppressAnimationsFlag=!!t}withSuppressedAnimations(t){let e;this._suppressScopeCount++;try{e=t()}catch(t){throw this._suppressScopeCount--,t}return e&&"function"==typeof e.then?e.finally(()=>{this._suppressScopeCount--}):(this._suppressScopeCount--,e)}beginSuppressAnimations(){this._suppressScopeCount++;let t=!1;return{end:()=>{t||(t=!0,this._suppressScopeCount--)}}}}qi(hp.prototype,Fi.withEvent);class dp{constructor(t,e){!(t=Number(t))||t<=0?(Ki("TimeCapsule maxsize should be greater than 0.",t),this.maxsize=10):this.maxsize=t,this.reset(),e&&(this.snapshot(e),this.preserve())}preserve(){this.checkPoint=this.pos}hasUnpreservedChanges(){return this.checkPoint!=this.pos}dispose(){this.reset()}snapshot(t){if(this.q.splice(this.pos+1,this.q.length-(this.pos+1),t),this.q.length>this.maxsize){const t=this.q.splice(0,this.q.length-this.maxsize);this.checkPoint=Math.max(-1,this.checkPoint-t.length)}this.pos=this.q.length-1}forward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.forwardable)return this.q[++this.pos];$i("Not forwardable.")}backward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.backwardable)return this.q[--this.pos];$i("Not backwardable.")}get current(){if(-1!==this.pos)return this.q[this.pos];$i("Non state has been recorded.")}get length(){return this.q.length}get forwardable(){return this.pos<this.q.length-1}get backwardable(){return this.pos>0}get snapshot_taker(){return this._snapshot_taker}set snapshot_taker(t){this._snapshot_taker=t}reset(){this.q=[],this.pos=-1,this.checkPoint=-1}}const up=di(t=>{t.brake||t.take()},1e3,{leading:!0,trailing:!1});function pp(t){!t.brake&&t.dirty&&up(t)}class fp{constructor(t,e){this._brake=!1,this.dirty=!1,this.brake=!1,this.dirty=!1,this.state_holder=t,this.timecapsule=e,this.timecapsule.snapshot_taker=this}dispose(){up.cancel(),this.state_holder=null,this.timecapsule=null}touch(){this.dirty=!0,pp(this)}take(t=!1){(this.dirty||t)&&(this.timecapsule.snapshot(this.state_holder.state),this.dirty=!1)}get brake(){return this._brake}set brake(t){this._brake=!!t,pp(this)}}function gp(t,e){const n=e.model_layer.get("scale"),i=e.model_layer.get("translate"),r=e.model_layer.is3dMode;if(t){const s=JSON.parse(t);s.scale=n,s.translate=i,s.threed=r,e.rebuildContentModel(s,{preserveThreeD:!0})}}class mp{constructor(t){this.container=t,this.timecapsule=new dp(20);const e=this;this.snapshot_taker=new fp({get state(){const t=e.container.model_layer.hierarchy;return JSON.stringify(t,ua)}},this.timecapsule),this.snapshot_taker.take(!0),this.timecapsule.preserve()}dispose(){this.reset(),this.timecapsule&&this.timecapsule.dispose(),this.snapshot_taker&&this.snapshot_taker.dispose(),delete this.container,delete this.timecapsule,delete this.snapshot_taker}preserve(){this.timecapsule.preserve()}hasUnpreservedChanges(){return this.timecapsule.hasUnpreservedChanges()}execute(t,e){!1!==e&&t&&t.execute(),this.snapshot_taker.touch(),this.trigger("execute",t,!0,!1)}undo(){this.timecapsule.backwardable&&(gp(this.timecapsule.backward(),this.container),this.trigger("undo",this.undoable(),this.redoable()))}redo(){this.timecapsule.forwardable&&(gp(this.timecapsule.forward(),this.container),this.trigger("redo",this.undoable(),this.redoable()))}undoable(){return this.timecapsule.backwardable}redoable(){return this.timecapsule.forwardable}reset(){this.timecapsule&&this.timecapsule.reset(),this.trigger("command-reset")}}qi(mp.prototype,Fi.withEvent);const yp=new class{constructor(){this._scenes=[],this.onSceneChange=null,this._watchedComponent=null,this._watchedHandler=null,this.onWatchedComponentChange=null}setWatchedComponent(t,e=0){if(this._clearWatched(),null==t)return!0;const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!r||"function"!=typeof r.on)return!1;const s=(e,n)=>{this.onWatchedComponentChange?.(t,e,n)};return r.on("change",s),this._watchedComponent=r,this._watchedHandler=s,!0}_clearWatched(){this._watchedComponent&&this._watchedHandler&&"function"==typeof this._watchedComponent.off&&this._watchedComponent.off("change",this._watchedHandler),this._watchedComponent=null,this._watchedHandler=null}register(t){this._cleanup(),this._scenes.push(new WeakRef(t)),this.onSceneChange?.(this._scenes.length)}unregister(t){this._clearWatched(),this._scenes=this._scenes.filter(e=>{const n=e.deref();return n&&n!==t}),this.onSceneChange?.(this._scenes.length)}getScenes(){return this._cleanup(),this._scenes.map((t,e)=>{const n=t.deref();if(!n)return null;const i=n.root,r=i?.model||{};return{index:e,model:{width:r.width||0,height:r.height||0,type:r.type||"unknown"}}}).filter(Boolean)}getComponentTree(t=0){const e=this._getScene(t);if(!e)return[];const n=e.rootContainer;if(!n)return[];const i=n.model_layer;return i?this._childrenOf(i):[]}getChildTree(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];let r;return r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),r?this._childrenOf(r):[]}getComponentInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const i=n.rootContainer;if(!i)return null;let r;if(r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),!r)return null;const s=this._safeBounds(r),o={model:this._safeClone(r.model),state:this._safeClone(r.state),nature:r.nature||{},data:this._safeValue(r.data),value:this._safeValue(r.value),bounds:s,type:r.model?.type||"unknown",isContainer:!!r.isContainer?.(),hidden:!!r.model?.hidden};return"model-layer"===r.model?.type&&(o.is3dMode=!!r.model?.threed),o}selectComponent(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;if(!t||"root"===t||"__root__"===t)return i.selected=[],!0;const r=this._findComponent(i,t);return!!r&&(i.selected=[r],!0)}setComponentProperty(t,e,n,i=0){const r=this._getScene(i);if(!r)return!1;const s=r.rootContainer;if(!s)return!1;let o;if(o="root"===t||"__root__"===t?s.model_layer:this._findComponent(s,t),!o)return!1;try{return o.set(e,n),!0}catch{return!1}}setCameraView(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const r=i.model_layer;if(!r||!r._threeCapability)return!1;try{return r._threeCapability.setCameraView(t),!0}catch{return!1}}getCameraState(t=0){const e=this._getScene(t);if(!e)return null;const n=e.rootContainer;if(!n)return null;const i=n.model_layer;if(!i||!i._threeCapability)return null;try{return i._threeCapability.getCameraState()}catch{return null}}toggleHidden(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const r=this._findComponent(i,t);if(!r)return!1;try{return r.set("hidden",!r.model?.hidden),!r.model?.hidden}catch{return!1}}evaluateData(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return r?this._safeValue(r.data):void 0}evaluateValue(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return r?this._safeValue(r.value):void 0}searchComponents(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const r=i.model_layer;if(!r)return[];const s=[],o=t.toLowerCase();return this._traverseComponent(r,t=>{const e=t.state||t.model||{};[e.type||"",e.name||"",e.id||"",e.tag||"",e.class||"",String(e.refid||"")].join(" ").toLowerCase().includes(o)&&s.push(this._toTreeNode(t))}),s}getComponentPath(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const r=i.model_layer;if(!r)return[];const s=[];return this._findPath(r,t,s)?s:[]}getThreedInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const i=n.rootContainer;if(!i)return null;let r;if(r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),!r)return null;const s=r.model||{},o=s.type||"unknown",a=s.material3d,c={is3dish:"function"==typeof r.is3dish&&r.is3dish(),type:o};if(a&&(c.material3d=this._safeClone(a)),c.resolved=Lh(a),"gltf-object"===o)try{c.nodeNames=r.nodeNames??[],c.animationNames=r.animationNames??[],c.nodes=this._safeClone(r.nodes),c.animations=this._safeClone(r.animations),c.fillStyleTargets=r.fillStyleTargets}catch{}return c}_getScene(t){this._cleanup();const e=this._scenes[t];return e?.deref()??null}_cleanup(){this._scenes=this._scenes.filter(t=>void 0!==t.deref())}_findComponent(t,e){const n=Number(e);if(!isNaN(n)){const e=t.findByRefid(n);if(e)return e}const i=t.findById(e);return i||null}_childrenOf(t){const e=t.components;return e?e.map(t=>this._toTreeNode(t)):[]}_toTreeNode(t){const e=t.components,n=!!e&&e.length>0,i=t.state||t.model||{};return{id:String(i.refid??i.id??""),type:i.type||"unknown",model_id:i.id,hasChildren:n,childCount:n?e.length:0,refid:i.refid,tag:i.tag,name:i.name,hidden:!!i.hidden,clazz:i.class}}_componentId(t){const e=t.state||t.model||{};return String(e.refid??e.id??"")}_findPath(t,e,n){const i=this._componentId(t);if(i===e)return!0;const r=t.components;if(!r)return!1;for(const s of r)if(this._findPath(s,e,n))return n.unshift("model-layer"===t.model?.type?"__root__":i),!0;return!1}_traverseComponent(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverseComponent(t,e)}_safeBounds(t){try{const e=t.bounds;return e?{left:e.left??0,top:e.top??0,width:e.width??0,height:e.height??0}:null}catch{return null}}_safeClone(t){if(!t||"object"!=typeof t)return t??{};try{return JSON.parse(JSON.stringify(t))}catch{const e={};for(const n of Object.keys(t))try{const i=t[n];if("function"==typeof i)continue;e[n]="object"==typeof i?String(i):i}catch{e[n]="[error]"}return e}}_safeValue(t){if(null==t)return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}},bp={fetch:"Fetching model...",parse:"Parsing model...",init:"Initializing...",compile:"Building components...",assets:"Loading assets...",data:"Waiting for data...",render:"Rendering..."},vp={stable:"─",increasing:"▲",decreasing:"▼",spike:"⚡"},_p={normal:"rgba(100,200,100,0.9)",warn:"rgba(255,180,50,0.9)",critical:"rgba(255,80,80,0.9)"};class xp{constructor(){this._visible=!1,this._manualOpen=!1,this._phaseRenderedCount=0}attach(t,e,n){this._targetElement=t,this._tracker=e,this._lagTracker=n,this._phaseRenderedCount=0,this._visible=!1,this._phaseListEl&&(this._phaseListEl.innerHTML=""),this._pendingListEl&&(this._pendingListEl.innerHTML=""),e&&(e.needsOverlay&&this._show(),e.onNeedsOverlay=()=>{this._visible||this._manualOpen||this._show()},e.onComplete=()=>{this._visible&&(this._update(),this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3))})}toggle(){this._visible?(this._hide(),this._manualOpen=!1):(this._manualOpen=!0,this._show())}show(){this._manualOpen=!0,this._show()}hide(){this._manualOpen=!1,this._hide()}destroy(){this._hide(),this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._targetElement=void 0,this._tracker=void 0,this._lagTracker=void 0,this._phaseListEl=void 0}get isVisible(){return this._visible}get isAttached(){return!!this._targetElement}_show(){this._targetElement&&(this._container||this._buildDOM(),this._container&&!this._container.parentElement&&this._targetElement.appendChild(this._container),this._container.style.display="flex",this._visible=!0,this._update(),this._updateTimer||(this._updateTimer=setInterval(()=>this._update(),500)),"complete"!==this._tracker?.phase||this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3))}_hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._updateTimer&&(clearInterval(this._updateTimer),this._updateTimer=void 0)}_update(){if(!this._visible||!this._tracker)return;const t=this._tracker,e=t.stats,n=t.phase,i="complete"===n;this._headerEl&&(this._headerEl.textContent=i?`Scene Monitor — ${(e.elapsed/1e3).toFixed(1)}s`:`Scene Monitor — ${bp[n]||n}`),this._updateProgress(t,i),this._updatePhaseList(t),this._updateAssetList(t,e,i),this._updateLagDisplay(),this._elapsedEl&&(this._elapsedEl.textContent=`${(e.elapsed/1e3).toFixed(1)}s`)}_updateProgress(t,e){if(!this._progressFillEl&&!this._progressTextEl)return;const n=t.phaseHistory,i=n.length,r=n.filter(t=>void 0!==t.duration).length,s=i>0?Math.round(r/i*100):e?100:0;this._progressFillEl&&(this._progressFillEl.style.width=s+"%"),this._progressTextEl&&(this._progressTextEl.textContent=`${r} / ${i}`)}_updatePhaseList(t){if(!this._phaseListEl)return;const e=t.phaseHistory;for(let t=this._phaseRenderedCount;t<e.length;t++){const n=e[t];if("complete"===n.phase)continue;const i=150*(t-this._phaseRenderedCount),r=document.createElement("div");r.dataset.phase=n.phase,r.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px;opacity:0;transition:opacity 0.3s ease",r.innerHTML='<span data-field="icon" style="flex-shrink:0"></span><span data-field="label" style="flex:1"></span><span data-field="time" style="width:60px;text-align:right"></span>',this._phaseListEl.appendChild(r),setTimeout(()=>{r.style.opacity="1"},i+16)}this._phaseRenderedCount=e.length;const n=performance.now();for(const t of Array.from(this._phaseListEl.querySelectorAll("[data-phase]"))){const i=t,r=e.find(t=>t.phase===i.dataset.phase);if(!r)continue;const s=bp[r.phase]||r.phase,o=i.querySelector('[data-field="icon"]'),a=i.querySelector('[data-field="label"]'),c=i.querySelector('[data-field="time"]');void 0===r.duration?(o.textContent="⏳",o.style.color="rgba(255,200,50,0.8)",a.textContent=s,a.style.color="rgba(255,255,255,0.9)",c.textContent=`${((n-r.timestamp)/1e3).toFixed(1)}s`,c.style.color="rgba(255,200,50,0.8)"):(o.textContent="✓",o.style.color="rgba(100,200,100,0.8)",a.textContent=s,a.style.color="rgba(255,255,255,0.5)",c.textContent=`${(r.duration/1e3).toFixed(1)}s`,c.style.color="rgba(255,255,255,0.4)")}}_updateAssetList(t,e,n){if(this._pendingListEl)if(n&&"complete"!==this._pendingListEl.dataset.mode)this._pendingListEl.innerHTML="",this._pendingListEl.dataset.mode="complete",this._renderHistorySummary(e);else if(!n){this._pendingListEl.dataset.mode="pending";const e=t.pending.sort((t,e)=>e.elapsed-t.elapsed),n=e.slice(0,5);for(let t=0;t<n.length;t++)t<this._pendingListEl.children.length?this._updatePendingRow(this._pendingListEl.children[t],n[t]):this._pendingListEl.appendChild(this._createPendingRow(n[t]));const i=n.length+(e.length>5?1:0);for(;this._pendingListEl.children.length>i;)this._pendingListEl.lastChild?.remove();if(e.length>5){const t=this._pendingListEl.lastElementChild;if(t?.dataset?.more)t.textContent=`... ${e.length-5} more`;else{const t=document.createElement("div");t.dataset.more="1",t.style.cssText="color:rgba(255,255,255,0.4);font-size:11px;padding:2px 0",t.textContent=`... ${e.length-5} more`,this._pendingListEl.appendChild(t)}}}}_updateLagDisplay(){if(!this._lagSectionEl||!this._lagTracker)return;this._lagTracker.evaluateAll();const t=this._lagTracker.getAllStats();0!==t.length&&(this._lagSectionEl.dataset.built?this._updateLagSection(t):(this._lagSectionEl.innerHTML="",this._renderLagSection(t),this._lagSectionEl.dataset.built="1"))}_renderHistorySummary(t){if(!this._pendingListEl)return;const e=document.createElement("div");e.style.cssText="color:rgba(255,255,255,0.7);padding:2px 0;font-size:12px",e.textContent=`Total: ${t.total} assets | Loaded: ${t.loaded} | Timeout: ${t.timeout} | Error: ${t.error}`,this._pendingListEl.appendChild(e);const n=this._tracker.entries.filter(t=>"pending"!==t.status).sort((t,e)=>e.elapsed-t.elapsed).slice(0,5);for(const t of n){const e=document.createElement("div");e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px";const n="loaded"===t.status?"✓":"timeout"===t.status?"⚠":"✗",i="loaded"===t.status?"rgba(100,200,100,0.8)":"timeout"===t.status?"rgba(255,180,50,0.8)":"rgba(255,80,80,0.8)";e.innerHTML=`<span style="color:${i}">${n}</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,this._pendingListEl.appendChild(e)}}_renderLagSection(t){if(!this._lagSectionEl)return;const e=document.createElement("div");e.style.cssText="color:rgba(255,255,255,0.5);font-size:11px;padding:4px 0 2px;border-top:1px solid rgba(255,255,255,0.08);margin-top:4px",e.textContent="Data Lag",this._lagSectionEl.appendChild(e);for(const e of t){const t=document.createElement("div");t.dataset.tag=e.tag,t.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px";const n=_p[e.level],i=vp[e.trend];t.innerHTML=`<span style="color:rgba(255,255,255,0.7);flex:1">${e.tag}</span><span data-field="drift" style="color:rgba(255,255,255,0.6)">drift: ${e.drift>=0?"+":""}${(e.drift/1e3).toFixed(1)}s</span><span style="color:rgba(255,255,255,0.4)">base: ${(e.baseline/1e3).toFixed(1)}s</span><span data-field="trend" style="color:${n}">${i}</span>`,this._lagSectionEl.appendChild(t)}}_createPendingRow(t){const e=document.createElement("div");return e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px",e.dataset.id=t.id,e.innerHTML=`<span style="color:rgba(255,200,50,0.7)">⏳</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span data-field="url" style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span data-field="time" style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,e}_updatePendingRow(t,e){const n=t.querySelector('[data-field="url"]'),i=t.querySelector('[data-field="time"]');n&&(n.textContent=this._shortUrl(e.url)),i&&(i.textContent=`${(e.elapsed/1e3).toFixed(1)}s`)}_updateLagSection(t){if(!this._lagSectionEl)return;const e=this._lagSectionEl.querySelectorAll("[data-tag]");for(const n of t){const t=Array.from(e).find(t=>t.dataset.tag===n.tag);if(t){const e=t.querySelector('[data-field="drift"]'),i=t.querySelector('[data-field="trend"]');e&&(e.textContent=`drift: ${n.drift>=0?"+":""}${(n.drift/1e3).toFixed(1)}s`),i&&(i.textContent=vp[n.trend],i.style.color=_p[n.level])}}}_shortUrl(t){if(!t)return"";const e=t.split("/");return e[e.length-1]||t}_buildDOM(){const t=document.createElement("div");t.setAttribute("scene","loading-overlay"),t.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none","z-index:9999",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:320px","max-width:450px","padding:12px 16px","gap:8px"].join(";");const e=document.createElement("div");e.style.cssText="display:flex;align-items:center;justify-content:space-between";const n=document.createElement("span");n.style.cssText="font-weight:600;font-size:13px",n.textContent="Loading...",this._headerEl=n,e.appendChild(n);const i=document.createElement("button");i.textContent="✕",i.title="Close",i.style.cssText="background:none;border:none;color:rgba(255,255,255,0.6);cursor:pointer;font-size:14px;padding:2px 4px;border-radius:3px;line-height:1",i.addEventListener("mouseenter",()=>{i.style.color="rgba(255,255,255,0.9)"}),i.addEventListener("mouseleave",()=>{i.style.color="rgba(255,255,255,0.6)"}),i.addEventListener("click",()=>this.hide()),e.appendChild(i),t.appendChild(e);const r=document.createElement("div");r.style.cssText="display:flex;align-items:center;gap:8px";const s=document.createElement("div");s.style.cssText="flex:1;height:4px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden";const o=document.createElement("div");o.style.cssText="height:100%;width:0%;background:rgba(74,158,255,0.8);border-radius:2px;transition:width 0.3s ease",this._progressFillEl=o,s.appendChild(o),r.appendChild(s);const a=document.createElement("span");a.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;min-width:80px;text-align:right",this._progressTextEl=a,r.appendChild(a),t.appendChild(r);const c=document.createElement("div");c.style.cssText="border-top:1px solid rgba(255,255,255,0.08);padding-top:4px",this._phaseListEl=c,t.appendChild(c);const l=document.createElement("div");l.style.cssText="max-height:120px;overflow-y:auto",this._pendingListEl=l,t.appendChild(l);const h=document.createElement("div");this._lagSectionEl=h,t.appendChild(h);const d=document.createElement("div");d.style.cssText="display:flex;align-items:center;border-top:1px solid rgba(255,255,255,0.08);padding-top:8px";const u=document.createElement("span");u.style.cssText="font-size:11px;color:rgba(255,255,255,0.4)",this._elapsedEl=u,d.appendChild(u),t.appendChild(d),t.addEventListener("keydown",t=>t.stopPropagation()),this._container=t}}class wp extends Uh{constructor(){super(...arguments),this._loadGen=0,this._objectSize=new e.Vector3}get objectSize(){return this._objectSize}build(){super.build();const{src:t}=this.component.state;if(!t)return this.clear(),this._showEmptyPlaceholder(),void(this.object3d.userData.context=this);const e=++this._loadGen,n=this.component.app.url(t),i=this._loadExternal(n).then(t=>{e===this._loadGen&&this._onLoaded(t)},t=>{e===this._loadGen&&(Ki(`${this._formatLabel}.load`,t),this.clear(),this._showErrorPlaceholder(),this.component.setState({loadError:String(t)}))});this.component.root?.app?.loadTracker?.track(`${this._formatLabel}:${t}`,this._formatLabel,t,i)}updateSource(){this.build()}get _placeholderColor(){return 6770852}_showEmptyPlaceholder(){const{width:t=100,height:n=100,depth:i=100}=this.component.state,r=t||100,s=n||100,o=i||100,a=this._placeholderColor,c=new e.BoxGeometry(r,o,s),l=new e.MeshStandardMaterial({color:a,transparent:!0,opacity:.15,depthWrite:!1}),h=new e.Mesh(c,l);h.name="__empty_placeholder__";const d=new e.EdgesGeometry(c),u=new e.LineBasicMaterial({color:a,transparent:!0,opacity:.4}),p=new e.LineSegments(d,u);p.name="__empty_placeholder_edge__",h.add(p),this.object3d.add(h)}_showErrorPlaceholder(){const t=new e.BoxGeometry(1,1,1),n=new e.MeshStandardMaterial({color:13369344,wireframe:!0}),i=new e.Mesh(t,n);i.name="__error_placeholder__",this.object3d.add(i)}clear(){return this.pivot&&Hh(this.pivot),this.pivot=void 0,this._objectSize=void 0,super.clear()}}const Mp="KHR_materials_pbrSpecularGlossiness";class Sp{constructor(t){this.name=Mp,this.parser=t}extendMaterialParams(t,e){const n=this.parser.json.materials?.[t],i=n?.extensions?.[Mp];if(!i)return Promise.resolve();const r=[];if(Array.isArray(i.diffuseFactor)){const[t,n,r,s]=i.diffuseFactor;e.color||(e.color=new h),e.color.setRGB(t,n,r,d),e.opacity=s}null!=i.diffuseTexture&&r.push(this.parser.assignTexture(e,"map",i.diffuseTexture,u));const s=i.glossinessFactor??1;e.roughness=1-s;const o=i.specularFactor??[1,1,1],a=Math.max(o[0],o[1],o[2]);return e.metalness=a>.5?a:0,Promise.all(r)}}(()=>{const t="__urdfBlobCrossOriginPatched__",n=e.ImageLoader.prototype;if(n[t])return;const i=n.load;n.load=function(t,e,n,r){if("string"==typeof t&&t.startsWith("blob:")){const s=this.crossOrigin;this.crossOrigin=void 0;try{return i.call(this,t,e,n,r)}finally{this.crossOrigin=s}}return i.call(this,t,e,n,r)},n[t]=!0})();const kp={once:e.LoopOnce,repeat:e.LoopRepeat,pingpong:e.LoopPingPong};class Ap extends wp{constructor(){super(...arguments),this._nodeIndex=new Map,this._originals=new Map,this._animationActions=new Map,this._fillStyleOriginals=new Map,this._clonedMaterials=new WeakSet}get _formatLabel(){return"gltf"}static getSharedLoader(t){if(!Ap._sharedLoader){const t=new A;!function(t){t.register(t=>new Sp(t))}(t);const e=new E;e.setDecoderPath("/node_modules/three/examples/jsm/libs/draco/"),t.setDRACOLoader(e);const n=new C;n.setTranscoderPath("/node_modules/three/examples/jsm/libs/basis/"),t.setKTX2Loader(n),t.setMeshoptDecoder(T),t.setCrossOrigin("anonymous"),Ap._sharedLoader=t}return t&&Ap._sharedLoader.ktx2Loader?.detectSupport(t),Ap._sharedLoader}static loadGLTF(t,e){let n=Ap._gltfCache.get(t);if(!n){const i=Ap.getSharedLoader(e);n=new Promise((e,n)=>{i.load(t,e,void 0,n)}).catch(e=>{throw Ap._gltfCache.delete(t),e}),Ap._gltfCache.set(t,n)}return n}_ensureOwnMaterial(t){let e=t.material;return this._clonedMaterials.has(e)||(e=e.clone(),t.material=e,this._clonedMaterials.add(e)),e}_loadExternal(t){return Ap.loadGLTF(t,this.threeContainer?.renderer3d)}_onLoaded(t){this.component.state.loadError&&this.component.setState({loadError:void 0});const n=t.scene,i=t.animations,r=P(n);r.userData.context=this,r.traverse(t=>{t.isMesh&&(t.castShadow=!0)});const s=(new e.Box3).setFromObject(r),o=s.getCenter(r.position),a=s.getSize(new e.Vector3);o.multiplyScalar(-1);const c=this.component.state.src;if(c){const t=Ap._topViewCache.get(c);t?this.component._topViewSnapshot=t:this._renderTopViewSnapshot(c,r)}if(this.clear(),this.object3d.userData.context=this,this._objectSize=a,this.pivot=new e.Object3D,this.component.state.floorAlign?this.components3D.add(this.pivot):this.object3d.add(this.pivot),this.pivot.add(r),this._buildNodeIndex(r),this.component.state.autoFit&&a.x>0&&a.y>0&&a.z>0){const t=(Number(this.component.state.autoFitSize)>0?Number(this.component.state.autoFitSize):200)/Math.max(a.x,a.y,a.z),e=Math.max(1,Math.round(a.x*t)),n=Math.max(1,Math.round(a.y*t)),i=Math.max(1,Math.round(a.z*t)),r=this.component;r._ratioLocking=!0;try{this.component.set({width:e,height:i,depth:n,autoFit:!1})}finally{r._ratioLocking=!1}}if(this.updateDimension(),this.component.state.floorAlign){const t=this.scenePlacement;if("space"!==t){this.components3D.updateMatrixWorld(!0);const n=(new e.Box3).setFromObject(this.pivot);if(isFinite(n.min.y)&&isFinite(n.max.y))if("inverted"===t){const t=this.components3D.worldToLocal(n.max.clone());t.y>0&&(this.pivot.position.y-=t.y)}else{const t=this.components3D.worldToLocal(n.min.clone());t.y<0&&(this.pivot.position.y-=t.y)}}}i&&i.length&&this._setupAnimations(i);const l=this.component.state.nodes;l&&this._applyNodeStates(l),this.updateFillStyle()}_renderTopViewSnapshot(t,e){const n=Ap.renderTopView(e);Ap._topViewCache.set(t,n),this.component._topViewSnapshot=n,this.component.invalidate()}static renderTopView(t){const n=256,i=new e.Scene,r=t.parent;i.add(t);const s=new e.AmbientLight(16777215,.8);i.add(s);const o=new e.DirectionalLight(16777215,1);o.position.set(0,10,0),i.add(o);const a=(new e.Box3).setFromObject(t),c=a.getSize(new e.Vector3),l=a.getCenter(new e.Vector3),h=(c.x||1)/2*1.02,d=(c.z||1)/2*1.02,u=new e.OrthographicCamera(-h,h,d,-d,.01,10*c.y+1);u.position.set(l.x,a.max.y+c.y,l.z),u.lookAt(l.x,l.y,l.z);const p=h/d,f=p>=1?n:Math.round(n*p),g=p>=1?Math.round(n/p):n;let m;try{m=new e.WebGLRenderer({antialias:!0,alpha:!0});const t=m.getContext();t&&!t.isContextLost()||(m.dispose(),m=void 0)}catch{m=void 0}if(!m){r?r.add(t):i.remove(t);const e=document.createElement("canvas");return e.width=f,e.height=g,e}m.setClearColor(0,0),m.setSize(f,g),m.render(i,u),r?r.add(t):i.remove(t);const y=document.createElement("canvas");y.width=f,y.height=g;const b=y.getContext("2d");return b&&b.drawImage(m.domElement,0,0),m.dispose(),y}static getTopViewCache(t){return Ap._topViewCache.get(t)}static setTopViewCache(t,e){Ap._topViewCache.set(t,e)}static flushCache(){Ap._gltfCache.clear(),Ap._topViewCache.clear()}_buildNodeIndex(t){this._nodeIndex.clear(),this._originals.clear(),t.traverse(t=>{if(!t.name)return;this._nodeIndex.set(t.name,t);const e={visible:t.visible,scale:t.scale.clone()};if(t.isMesh){const n=t.material;n&&(e.color=n.color.clone(),e.opacity=n.opacity,e.transparent=n.transparent,e.emissive=n.emissive.clone(),e.emissiveIntensity=n.emissiveIntensity)}this._originals.set(t.name,e)})}getNode(t){return this._nodeIndex.get(t)}get nodeNames(){return Array.from(this._nodeIndex.keys())}_applyNodeStates(t){for(const[e,n]of Object.entries(t)){const t=this._nodeIndex.get(e);if(t&&(void 0!==n.visible&&(t.visible=n.visible),void 0!==n.scale&&t.scale.setScalar(n.scale),t.isMesh)){const e=t;if(!(void 0!==n.color||void 0!==n.opacity||void 0!==n.emissive||void 0!==n.emissiveIntensity))continue;const i=this._ensureOwnMaterial(e);void 0!==n.color&&i.color.set(n.color),void 0!==n.opacity&&(i.opacity=n.opacity,i.transparent=n.opacity<1),void 0!==n.emissive&&i.emissive.set(n.emissive),void 0!==n.emissiveIntensity&&(i.emissiveIntensity=n.emissiveIntensity)}}}_resetNode(t){const e=this._nodeIndex.get(t),n=this._originals.get(t);if(e&&n&&(e.visible=n.visible,e.scale.copy(n.scale),e.isMesh)){const t=e.material;t&&n.color&&(t.color.copy(n.color),t.opacity=n.opacity,t.transparent=n.transparent,t.emissive.copy(n.emissive),t.emissiveIntensity=n.emissiveIntensity)}}_resetAllNodes(){for(const t of this._originals.keys())this._resetNode(t)}_setupAnimations(t){const e=this.threeContainer.mixer;this._animationActions.clear();for(const n of t){const t=e.clipAction(n);this._animationActions.set(n.name,t)}!1!==this.component.state.play&&this._playTargetAnimations();const n=this.component.state.animations;n&&this._applyAnimationStates(n)}_playTargetAnimations(){const t=this.component.state.playTargets;if("*"===t)this._animationActions.forEach(t=>t.play());else if(Array.isArray(t)&&t.length>0)for(const e of t)this._animationActions.get(e)?.play()}_applyAnimationStates(t){for(const[n,i]of Object.entries(t)){const t=this._animationActions.get(n);t&&(void 0!==i.loop&&(t.loop=kp[i.loop]??e.LoopRepeat,"once"===i.loop&&(t.clampWhenFinished=!0)),void 0!==i.speed&&(t.timeScale=i.speed),void 0!==i.weight&&(t.weight=i.weight),void 0!==i.play&&(i.play?t.play():t.stop()))}}get animationNames(){return Array.from(this._animationActions.keys())}updateFillStyle(){const{fillStyle:t}=this.component.state;if(!t)return;const e=this.component.state.fillStyleTargets;let n;if("*"===e)n=[...this._nodeIndex.entries()].filter(([,t])=>t.isMesh).map(([t])=>t);else{if(!(Array.isArray(e)&&e.length>0))return;n=e}if(0===n.length)return;const i=Uh.buildFillStyleTexture(this.component);for(const e of n){const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const r=this._ensureOwnMaterial(n);r&&(this._fillStyleOriginals.has(e)||this._fillStyleOriginals.set(e,{color:r.color.clone(),map:r.map,opacity:r.opacity,transparent:r.transparent}),i?(r.map&&r.map!==this._fillStyleOriginals.get(e)?.map&&r.map.dispose(),i.needsUpdate=!0,r.map=i):"string"==typeof t&&("transparent"!==t?r.color.set(t):(r.opacity=0,r.transparent=!0)))}}_restoreFillStyleTargets(t){for(const e of t){const t=this._fillStyleOriginals.get(e);if(!t)continue;const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const i=n.material;i&&(i.map&&i.map!==t.map&&i.map.dispose(),i.color.copy(t.color),i.map=t.map,i.opacity=t.opacity,i.transparent=t.transparent,this._fillStyleOriginals.delete(e))}}clear(){return this._animationActions.forEach(t=>t.stop()),this._animationActions.clear(),this._nodeIndex.clear(),this._originals.clear(),this._fillStyleOriginals.clear(),super.clear()}updateDimension(){const{width:t=1,height:e=1,depth:n=1}=this.component.state,{x:i=1,y:r=1,z:s=1}=this.objectSize||{};this.pivot&&this.pivot.scale.set(t/i,n/r,e/s),this.component.invalidate()}onchange(t,e){if(super.onchange(t,e),("src"in t||"floorAlign"in t)&&this.updateSource(),"nodes"in t){this._resetAllNodes();const e=t.nodes;e&&Object.keys(e).length>0&&this._applyNodeStates(e)}if("animations"in t){const e=t.animations;e&&this._applyAnimationStates(e)}if("fillStyleTargets"in t){const t=[...this._fillStyleOriginals.keys()];t.length>0&&this._restoreFillStyleTargets(t),this.updateFillStyle()}("play"in t||"playTargets"in t)&&(this._animationActions.forEach(t=>t.stop()),!1!==this.component.state.play&&this._playTargetAnimations())}}Ap._topViewCache=new Map,Ap._gltfCache=new Map,Ap._sharedLoader=null;const Ep=["id","name","tag","type","class","text","data","property"];class Cp{constructor(){this._results=[],this._currentIndex=-1,this._lastQuery=""}get results(){return this._results}get currentIndex(){return this._currentIndex}get currentResult(){return this._results[this._currentIndex]}get resultCount(){return this._results.length}search(t,e,n){if(this._lastQuery=e,this._results=[],this._currentIndex=-1,!e||!t)return this._results;const i=n?.fields||Ep,r=n?.caseSensitive??!1,s=n?.includeHidden??!1,o=n?.maxResults??1/0,a=r?e:e.toLowerCase(),c=new Set;return this._traverse(t,t=>{if(c.has(t))return;if(this._results.length>=o)return;if(!s&&t.state.hidden)return;const e=this._matchComponent(t,a,i,r);e&&(c.add(t),this._results.push(e))}),this._results.length>0&&(this._currentIndex=0),this._results}navigateNext(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex+1)%this._results.length,this._results[this._currentIndex]}navigatePrev(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex-1+this._results.length)%this._results.length,this._results[this._currentIndex]}navigateTo(t){if(!(t<0||t>=this._results.length))return this._currentIndex=t,this._results[this._currentIndex]}clear(){this._results=[],this._currentIndex=-1,this._lastQuery=""}_traverse(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverse(t,e)}_matchComponent(t,e,n,i){const r=t.state,s=t=>{if(!t)return!1;return(i?t:t.toLowerCase()).includes(e)};for(const o of n)switch(o){case"id":if(s(r.id))return{component:t,matchType:"id",matchField:"id",matchValue:r.id};break;case"name":if(s(r.name))return{component:t,matchType:"name",matchField:"name",matchValue:r.name};break;case"tag":if(s(r.tag))return{component:t,matchType:"tag",matchField:"tag",matchValue:r.tag};break;case"type":if(s(r.type))return{component:t,matchType:"type",matchField:"type",matchValue:r.type};break;case"class":if(s(r.class))return{component:t,matchType:"class",matchField:"class",matchValue:r.class};break;case"text":if(s(r.text))return{component:t,matchType:"text",matchField:"text",matchValue:r.text};break;case"data":{const n=this._matchDataBinding(t,e,i);if(n)return n;break}case"property":{const n=this._matchProperties(t,e,i);if(n)return n;break}}return null}_matchDataBinding(t,e,n){const i=t._model,r=i?.mappings;if(!r||!Array.isArray(r))return null;const s=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)};for(const e of r){if(s(e.accessor))return{component:t,matchType:"data",matchField:"accessor",matchValue:e.accessor};if(s(e.target))return{component:t,matchType:"data",matchField:"target",matchValue:e.target};if(s(e.property))return{component:t,matchType:"data",matchField:"property",matchValue:e.property};if(s(e.source))return{component:t,matchType:"data",matchField:"source",matchValue:e.source}}return null}_matchProperties(t,e,n){const i=t.state,r=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)},s=["ref","src","value","action"];for(const e of s){const n=i[e];if("string"==typeof n&&r(n))return{component:t,matchType:"property",matchField:e,matchValue:n}}const o=i.fillStyle;if(o){if("string"==typeof o&&r(o))return{component:t,matchType:"property",matchField:"fillStyle",matchValue:o};if("object"==typeof o&&"pattern"===o.type&&"string"==typeof o.image&&r(o.image))return{component:t,matchType:"property",matchField:"fillStyle.image",matchValue:o.image}}return null}}const Tp={id:"ID",name:"Name",tag:"Tag",type:"Type",class:"Class",text:"Text",data:"Data",property:"Prop"};class Pp{constructor(){this._engine=new Cp,this._visible=!1,this._queryHistory=[],this._historyIndex=-1,this._savedInput="",this._keyboardNav=!1}get isVisible(){return this._visible}get engine(){return this._engine}setup(t){this.destroy(),this._host=t}toggle(){this._visible?this._input&&document.activeElement!==this._input?(this._input.focus(),this._input.select()):this.hide():this.show()}show(){this._host?.element&&(this._container||this._buildDOM(),this._container&&!this._container.parentElement&&this._host.element.appendChild(this._container),this._container.style.display="flex",this._visible=!0,requestAnimationFrame(()=>{this._input?.focus(),this._input?.select()}))}hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._historyIndex=-1,this._clearHighlight(),this._engine.clear(),this._updateStatus(),this._hideResultList()}destroy(){this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._input=void 0,this._statusEl=void 0,this._resultListEl=void 0,this._host=void 0,this._visible=!1,this._engine.clear()}_buildDOM(){const t=this._host,e=document.createElement("div");e.setAttribute("scene","search-overlay"),e.style.cssText=["position:absolute","top:8px","right:8px","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none","z-index:10000",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:280px","max-width:400px"].join(";");const n=document.createElement("div");n.style.cssText="display:flex;align-items:center;padding:6px 8px;gap:6px";const i=document.createElement("span");i.textContent="🔍",i.style.cssText="font-size:14px;flex-shrink:0;opacity:0.6",n.appendChild(i);const r=document.createElement("input");r.type="text",r.placeholder="Search: type, id, tag, text, data...",r.style.cssText=["flex:1","background:rgba(255,255,255,0.08)","border:1px solid rgba(255,255,255,0.15)","border-radius:4px","color:white","padding:4px 8px","font-size:13px","outline:none","min-width:0"].join(";"),r.addEventListener("focus",()=>{r.style.borderColor="rgba(74,158,255,0.6)"}),r.addEventListener("blur",()=>{r.style.borderColor="rgba(255,255,255,0.15)"}),n.appendChild(r);const s=document.createElement("span");s.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;flex-shrink:0",n.appendChild(s);const o=document.createElement("button");o.textContent="✕",o.title="Close (Esc)",o.style.cssText=this._buttonStyle(),o.addEventListener("click",()=>this.hide()),n.appendChild(o),e.appendChild(n);const a=document.createElement("div");a.style.cssText=["max-height:240px","overflow-y:auto","border-top:1px solid rgba(255,255,255,0.08)","display:none"].join(";"),e.appendChild(a),r.addEventListener("input",()=>{this._historyIndex=-1,this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>this._doSearch(r.value),150)}),r.addEventListener("keydown",e=>{if(e.stopPropagation(),"Escape"===e.key)return this.hide(),void t.element?.focus();if("ArrowDown"===e.key||"Tab"===e.key){if("Tab"===e.key&&e.shiftKey)return;return this._isHistoryMode()||!this._input?.value&&"ArrowDown"===e.key?this._navigateHistory(1):this._engine.resultCount>0&&this._focusResult(0),void e.preventDefault()}if("ArrowUp"===e.key)return this._navigateHistory(-1),void e.preventDefault();if("Enter"===e.key){const t=this._engine.currentIndex>=0?this._engine.currentIndex:0;return this._selectResult(t),void e.preventDefault()}}),this._container=e,this._input=r,this._statusEl=s,this._resultListEl=a}_buttonStyle(){return["background:none","border:none","color:rgba(255,255,255,0.6)","cursor:pointer","font-size:12px","padding:2px 4px","border-radius:3px","line-height:1"].join(";")}_doSearch(t){if(!this._host?.root)return;const e=t.trim();if(!e)return this._engine.clear(),this._clearHighlight(),this._updateStatus(),void this._hideResultList();this._engine.search(this._host.root,e),this._updateStatus(),this._renderResultList()}_addToHistory(t){const e=t.trim();if(!e)return;const n=this._queryHistory.indexOf(e);n>=0&&this._queryHistory.splice(n,1),this._queryHistory.unshift(e),this._queryHistory.length>Pp.MAX_HISTORY&&this._queryHistory.pop()}_navigateHistory(t){if(0===this._queryHistory.length)return;if(!this._input)return;-1===this._historyIndex&&-1===t&&(this._savedInput=this._input.value);const e=this._historyIndex+(-1===t?1:-1);e<-1||e>=this._queryHistory.length||(this._historyIndex=e,-1===this._historyIndex?this._input.value=this._savedInput:this._input.value=this._queryHistory[this._historyIndex],this._debounceTimer&&clearTimeout(this._debounceTimer),this._doSearch(this._input.value))}_isHistoryMode(){return this._historyIndex>=0}_focusResult(t){if(t<0||t>=this._engine.resultCount)return;if(t>=50)return;this._engine.navigateTo(t),this._keyboardNav=!0,this._updateStatus(),this._updateResultListSelection();const e=this._resultListEl?.querySelector(`[data-index="${t}"]`);e?.focus()}_selectResult(t){if(!this._host)return;if(0===this._engine.resultCount)return;if(t<0||t>=this._engine.resultCount)return;this._engine.navigateTo(t);const e=this._engine.currentResult;if(!e)return;this._addToHistory(this._input?.value||""),this._host.setSelected([e.component]),this._host.centerTo(e.component,!0);const n=this._engine.results.map(t=>t.component);this._host.highlightSearchResults?.(n),this._host.invalidate?.(),this._updateStatus(),this._updateResultListSelection()}_clearHighlight(){this._host?.highlightSearchResults?.([]),this._host?.invalidate?.()}_updateStatus(){if(!this._statusEl)return;const t=this._engine.resultCount,e=this._engine.currentIndex;0===t&&this._input?.value?.trim()?(this._statusEl.textContent="No results",this._statusEl.style.color="rgba(255,120,120,0.8)"):t>0?(this._statusEl.textContent=`${e+1}/${t}`,this._statusEl.style.color="rgba(255,255,255,0.5)"):this._statusEl.textContent=""}_renderResultList(){if(!this._resultListEl)return;const t=this._engine.results;if(this._resultListEl.innerHTML="",0===t.length)return void(this._resultListEl.style.display="none");const e=t.slice(0,50);for(let t=0;t<e.length;t++){const n=e[t],i=document.createElement("div");i.dataset.index=String(t),i.tabIndex=-1,i.style.cssText=["padding:4px 10px","cursor:pointer","display:flex","align-items:center","gap:6px","font-size:12px","border-bottom:1px solid rgba(255,255,255,0.04)","transition:background 0.1s","outline:none"].join(";"),i.addEventListener("mouseenter",()=>{this._keyboardNav=!1,i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{this._engine.currentIndex!==t?i.style.background="none":i.style.background="rgba(74,158,255,0.15)"}),i.addEventListener("click",()=>{this._selectResult(t)}),i.addEventListener("keydown",e=>{e.stopPropagation(),"ArrowDown"===e.key?(this._focusResult(t+1),e.preventDefault()):"ArrowUp"===e.key?(0===t?(this._input?.focus(),this._input?.select()):this._focusResult(t-1),e.preventDefault()):"Enter"===e.key?(this._selectResult(t),e.preventDefault()):"Escape"===e.key?(this.hide(),this._host?.element?.focus(),e.preventDefault()):e.shiftKey&&"Tab"===e.key?(this._input?.focus(),e.preventDefault()):1!==e.key.length||e.metaKey||e.ctrlKey||e.altKey||this._input?.focus()});const r=document.createElement("span");r.textContent=Tp[n.matchType]||n.matchType,r.style.cssText=["font-size:9px","padding:1px 4px","border-radius:3px","background:rgba(74,158,255,0.2)","color:rgba(74,158,255,0.9)","flex-shrink:0","text-transform:uppercase","letter-spacing:0.5px"].join(";"),i.appendChild(r);const s=document.createElement("span");s.textContent=n.component.state.type||"?",s.style.cssText="color:rgba(255,255,255,0.7);flex-shrink:0",i.appendChild(s);const o=document.createElement("span");if(o.textContent=this._truncate(n.matchValue,30),o.style.cssText="color:rgba(255,200,100,0.8);overflow:hidden;text-overflow:ellipsis;white-space:nowrap",i.appendChild(o),"id"!==n.matchType&&n.component.state.id){const t=document.createElement("span");t.textContent=`#${n.component.state.id}`,t.style.cssText="color:rgba(255,255,255,0.3);font-size:11px;margin-left:auto;flex-shrink:0",i.appendChild(t)}this._resultListEl.appendChild(i)}if(t.length>50){const e=document.createElement("div");e.style.cssText="padding:4px 10px;font-size:11px;color:rgba(255,255,255,0.3);text-align:center",e.textContent=`... and ${t.length-50} more`,this._resultListEl.appendChild(e)}this._resultListEl.style.display="block",this._updateResultListSelection()}_updateResultListSelection(){if(!this._resultListEl)return;const t=this._engine.currentIndex;for(const e of Array.from(this._resultListEl.children)){const n=e,i=parseInt(n.dataset.index||"-1",10);n.style.background=i===t?"rgba(74,158,255,0.15)":"none"}const e=this._resultListEl.querySelector(`[data-index="${t}"]`);e?.scrollIntoView({block:"nearest"})}_hideResultList(){this._resultListEl&&(this._resultListEl.style.display="none",this._resultListEl.innerHTML="")}_truncate(t,e){return t.length>e?t.slice(0,e)+"...":t}}Pp.MAX_HISTORY=20;let Dp=0;const Op=new FinalizationRegistry(t=>{Dp--});class zp{static get residents(){return Dp}static get residentsCount(){return Dp}constructor(t){this._searchOverlay=new Pp,this._loadingOverlay=new xp,this._container=t,this.app=t.app,this._commander=new mp(this._container),this.app.commander=this._commander,Dp++,Op.register(this,Dp),yp.register(this),this._container.target_element&&this._setupSearchOverlay()}add(t,e,n){return Ml.call(this._container,t,e,n)}duplicate(){return Sl.call(this._container)}remove(){return kl.call(this._container)}animate(t){return ra.call(this,t)}fullscreen(t){return Dl.call(this._container,t)}get target(){return this._container.target_element}set target(t){let e;if("string"==typeof t){if(e=document.getElementById(t),!e)throw new Error(`target element '${t}' does not exist`);if(e.firstChild)throw new Error(`target element '${t}' already has children`)}else e=t;e&&e.style&&(e.style.cursor="default"),this._container.target_element=e,this._setupSearchOverlay(),this._container.invalidate()}get scale(){return this.root.get("scale")}set scale(t){this.root.set("scale",t)}get translate(){return this.root.get("translate")}set translate(t){this.root.set("translate",t)}get unit(){return this.root.get("unit")||"px"}get PPM(){return this.app.PPM}get PPI(){return this.app.PPI}get DPPX(){return this.app.DPPX}static get DPPX(){return Hr}get unitScale(){return this._container.unitScale}get screen(){return this.app.screen}set screen(t){this.app.screen=t,this._container.resize()}resize(){this._container.resize()}release(){this.dispose()}dispose(){this._loadingOverlay.destroy(),this._searchOverlay.destroy(),yp.unregister(this),this._commander&&this._commander.dispose(),this._container&&this._container.dispose(),Ap.flushCache()}get selected(){return this._container.selected.slice()}set selected(t){this._container.selected=t}select(t,...e){return this._container.selected=this.root?.findAll(t,...e),this.selected}get commander(){return this._commander}undo(){this.commander.undo()}undoable(){return this.commander.undoable()}redo(){this.commander.redo()}redoable(){return this.commander.redoable()}preserve(){this.commander.preserve()}hasUnpreservedChanges(){return this.commander.hasUnpreservedChanges()}cut(){return Il.call(this._container)}copy(){return zl.call(this._container)}paste(t){return Ll.call(this._container,t)}undoableChange(t){return Jl.call(this._container,t)}change(t,e,n){return Zl.call(this.root,t,e,n)}get model(){return this.root.hierarchy}set model(t){this._container.rebuildContentModel(t)}get rootContainer(){return this._container}get root(){return this._container?.model_layer}findAll(t,...e){return this.root.findAll(t,...e)}findFirst(t,...e){return this.root.findFirst(t,...e)}findById(t){return this._container.findById(t)}findAllById(t){return this._container.findAllById(t)}serialize(){return this.root.trim(),this.root.serialize()}align(t){return pl.call(this._container,t)}place(t){return ah.call(this._container,t)}distribute(t){return ml.call(this._container,t)}move(t,e,n){return vl.call(this._container,t,e,n)}zorder(t){return _l.call(this._container,t)}symmetryX(){return $l.call(this._container)}symmetryY(){return Ql.call(this._container)}on(t,e,n){return Cl.call(this._container,t,e,n)}once(t,e,n){return Tl.call(this._container,t,e,n)}off(t,e,n){return this._container&&Pl.call(this._container,t,e,n)}centerTo(t,e){return this.root.centerTo(t,e)}get mode(){return this.app.mode}set mode(t){void 0!==t&&(this.app.mode=t)}toDataURL(t,e,n,i){return Ul.call(this._container,t,e,n,i)}group(){return Wl.call(this._container)}ungroup(){return Xl.call(this._container)}fit(t){this._container.once("redraw",()=>this._container.fit(t)),this._container.invalidate()}get fitMode(){return this._container.fitMode}get ids(){return th.call(this._container)}get data(){return this._container.data}set data(t){this._container.data=t}get dataByRefid(){return this._container.dataByRefid}set dataByRefid(t){this._container.dataByRefid=t}get values(){return this._container.values}set values(t){this._container.values=t}get valuesByRefid(){return this._container.valuesByRefid}set valuesByRefid(t){this._container.valuesByRefid=t}get baseUrl(){return this.app.baseUrl}set baseUrl(t){this.app.baseUrl=t}get suppressAnimations(){return this.app.suppressAnimations}set suppressAnimations(t){this.app.suppressAnimations=t}withSuppressedAnimations(t){return this.app.withSuppressedAnimations(t)}beginSuppressAnimations(){return this.app.beginSuppressAnimations()}startAddMode(t){return ch.call(this._container,t)}startStylePasteMode(){return lh.call(this._container)}stopStylePasteMode(){return hh.call(this._container)}startDatabindPasteMode(){return dh.call(this._container)}stopDatabindPasteMode(){return uh.call(this._container)}get loading(){return this.app.loadTracker}get loadingOverlay(){return this._loadingOverlay}showLoadingOverlay(){this._loadingOverlay.show()}hideLoadingOverlay(){this._loadingOverlay.hide()}toggleLoadingOverlay(){if(!this._loadingOverlay.isAttached){const t=this._container.target_element;t&&this._loadingOverlay.attach(t,this.app.loadTracker,this.app.lagTracker)}this._loadingOverlay.toggle()}get searchOverlay(){return this._searchOverlay}_setupSearchOverlay(){const t=this;this._searchOverlay.setup({get root(){return t.root},get element(){return t.target},centerTo(e,n){t.centerTo(e,n)},setSelected(e){t.selected=e},invalidate(){t._container?.invalidate()}});const e=this._container.model_layer;e&&(e.onSearchToggle=()=>this._searchOverlay.toggle(),e.onDataBindingToggle=()=>this.onDataBindingToggle?.(),e.onMonitorToggle=()=>this.toggleLoadingOverlay())}_setupLoadingOverlay(){const t=this._container.target_element;t&&this._loadingOverlay.attach(t,this.app.loadTracker,this.app.lagTracker)}}const Ip=new class{async load(t){}async save(t,e){}async clear(t){}};function Lp({target:t,model:e,style:n,layers:i=[],handlers:r=[],mode:s=0,refProvider:o,dataSubscriptionProvider:a,dataStorage:c=Ip,baseUrl:l,fitMode:h,postprocessing:d=!0,loading:u}){let p=null;if("string"==typeof t){if(p=document.getElementById(t),!p)throw new Error(`target element '${t}' does not exist`);if(p.firstChild)throw new Error(`target element '${t}' is not empty`)}else p=t??null;p&&p.style&&(p.style.position="absolute",p.style.cursor="default",p.style.overflow="hidden");const f=new hp(s,o);return l&&(f.baseUrl=l),f.postprocessing=d,f.dataSubscriptionProvider=a,f.dataStorage=c,u?.tracker?f.adoptLoadTracker(u.tracker):f.initLoadTracker(u||{}),f.loadTracker?.setPhase("init"),new zp(new ep({target_element:p,model:e,style:n,layers:i,handlers:r,fitMode:h},f))}function jp(t,e,n,i){var r,s=arguments.length,o=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(s<3?r(o):s>3?r(e,n,o):r(e,n))||o);return s>3&&o&&Object.defineProperty(e,n,o),o}function Rp(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function Fp(t,e,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const Bp=["mousemove","mouseup","mousedown","mouseout","wheel","tap","click","touchstart","touchmove","touchend","mouseenter","mouseleave","dragstart","dragmove","dragend","dblclick"];function Np(t){return class extends t{constructor(){super(...arguments),this.userInputEventHandler=t=>{Du(this,t.type,t),t.stopPropagation()}}isHTMLElement(){return!0}isShadowable(){return!0}get element(){return this._element}set element(t){this._element=t}get tagName(){return this.get("type")}setElementProperties(t){throw new Error("Not Implemented Yet")}createElement(){this.element=document.createElement(this.tagName),this.element&&(this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element),this.scalable||(this.element.style.zIndex="100"),Bp.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),Vr.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),this.oncreate_element&&this.oncreate_element(this.element))}reposition(){this.element&&Ss(this)}disposeElement(){if(!this.element)return;Bp.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)}),Vr.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)});const t=this.element;t&&t.parentElement&&t.parentElement.removeChild(t),this.element=null}async ready(){await super.ready(),!this.element&&this.createElement(),this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element),this.setElementProperties(this.element),this.reposition()}dispose(){this.disposeElement(),super.dispose()}get hasTextProperty(){return!0}get textHidden(){return!0}set textHidden(t){}get hidden(){return super.hidden}set hidden(t){super.hidden=t,this.element.style.display=t?"none":"block"}onchange(t,e){this.element&&this.setElementProperties(this.element),"position"in t&&this.onchangePosition(),this.reposition()}onchangePosition(){this.element&&("static"==this.position&&this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element))}isDescendible(t){return t.isHTMLElement()}}}var Hp;const Yp={x:1,y:1},Vp={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"},Gp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"position-origin",name:"origin",property:{options:[{display:"",value:""},{display:"left-top",value:"left-top"},{display:"center-top",value:"center-top"},{display:"right-top",value:"right-top"},{display:"left-middle",value:"left-middle"},{display:"center-middle",value:"center-middle"},{display:"right-middle",value:"right-middle"},{display:"left-bottom",value:"left-bottom"},{display:"center-bottom",value:"center-bottom"},{display:"right-bottom",value:"right-bottom"}]}},{type:"number",label:"offset-x",name:"offsetX"},{type:"number",label:"offset-y",name:"offsetY"},{type:"layout",label:"layout",name:"layoutOption"},{type:"checkbox",label:"closable",name:"closable"},{type:"checkbox",label:"draggable",name:"draggable"},{type:"checkbox",label:"minimizable",name:"minimizable"},{type:"checkbox",label:"minimized",name:"minimized"}],help:"scene/component/container"};class Up extends(Np(Fc)){constructor(){super(...arguments),Hp.set(this,null),this.startDragging=t=>{if(!this.state.draggable)return;t.preventDefault(),t.stopPropagation();const e=t.clientX,n=t.clientY,{left:i,top:r}=this.bounds,s=this.rootModel.getOverlay?.(this)?.style.transform,o=s?.match(/scale\(([^,]+),\s*([^)]+)\)/),a=o?parseFloat(o[1]):1,c=o?parseFloat(o[2]):a,l=t=>{t.preventDefault(),t.stopPropagation();const s=(t.clientX-e)/a,o=(t.clientY-n)/c;this.setState({left:i+s,top:r+o})},h=t=>{t.preventDefault(),t.stopPropagation(),document.removeEventListener("mousemove",l,!0),document.removeEventListener("mouseup",h,!0)};document.addEventListener("mousemove",l,!0),document.addEventListener("mouseup",h,!0)},this.toggleMinimizable=()=>{const{minimized:t}=this.state;this.setState("minimized",!t)},this.closeContainer=()=>{this.setState("hidden",!0)}}get tagName(){return"div"}get nature(){return Gp}isPositionable(){return!0}setElementProperties(t){}get layout(){return yc.get(this.get("layout"))||bc}reposition(){if(!this.element)return;const t=this,{id:e,class:n,scale:i=Yp}=t.state,{rotation:r=0,hidden:s}=t,{left:o,top:a,width:c,height:l}=t.bounds,h=c/2,d=l/2,u=t.element;u.hidden=s,e&&(u.id=e),n&&(u.className=n),Object.assign(u.style,Vp,{left:o+"px",top:a+"px",width:"0px",height:"0px",backgroundColor:"transparent"});const p=t.delta(),f=(i&&i.x||1)*p.sx,g=(i&&i.y||1)*p.sy,m=(r||0)+p.theta,y=p.tx||0,b=p.ty||0;u.style.transform=`translate(${y+h}px, ${b+d}px) rotate(${m}rad) translate(${-h}px, ${-d}px) scale(${f}, ${g}) perspective(1px)`}set path(t){const{minimized:e}=this.state,n=t[0],i=t[2];e?this.set({left:n.x,top:n.y,width:i.x-n.x}):this.set({left:n.x,top:n.y,width:i.x-n.x,height:i.y-n.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){const{minimized:e}=this.state,{left:n=0,top:i=0,width:r=0,height:s=0}=t,o={left:n,top:i};e?this.set({...o,width:r}):this.set({...o,width:r,height:s})}updatePosition(){if(!this.origin)return void(Rp(this,Hp,"f")&&(Rp(this,Hp,"f").disconnect(),Fp(this,Hp,null,"f")));const t=this.rootModel.auxOverlay;if(!t)return;const e=this.bounds,{width:n,height:i}="static"!==this.position?t.getBoundingClientRect():this.parent.bounds,{x:r,y:s}=function(t,e,n){const{left:i,top:r,width:s,height:o}=e,{width:a,height:c}=n;return t?{x:t.includes("left")?i:t.includes("center")?i+(s-a)/2:i+(s-a),y:t.includes("top")?r:t.includes("middle")?r+(o-c)/2:r+(o-c)}:{x:n.left,y:n.top}}(this.origin,{left:0,top:0,width:n,height:i},e),o=this.offset;this.bounds={left:r+(this.origin.includes("right")?-o.x:+o.x),top:s+(this.origin.includes("bottom")?-o.y:+o.y),width:e.width,height:e.height},Rp(this,Hp,"f")||(Fp(this,Hp,new ResizeObserver(()=>{requestAnimationFrame(()=>this.updatePosition())}),"f"),Rp(this,Hp,"f").observe(t))}onchange(t,e){const n=["draggable","minimizable","closable","minimized","width","height","origin","offsetX","offsetY","hidden"];super.onchange(t,e),Object.keys(t).some(t=>n.includes(t))&&this.onchangeButtons(),"minimized"in t&&this.onchangeMinimized(),("origin"in t||"offsetX"in t||"offsetY"in t)&&this.updatePosition()}async ready(){await super.ready(),this.updatePosition()}dispose(){Rp(this,Hp,"f")&&(Rp(this,Hp,"f").disconnect(),Fp(this,Hp,null,"f")),super.dispose()}createElement(){super.createElement(),this.element&&(this.element.setAttribute("scene","container"),this.onchangeButtons(),this.onchangeMinimized())}onchangeButtons(){if(!this.element)return;const{draggable:t,minimizable:e,closable:n,minimized:i,hidden:r}=this.state,{width:s}=this.bounds;this.element.style.setProperty("--container-width",`${s}px`);try{D(r?O:z`
2
+ /*! https://mths.be/codepointat v0.2.0 by @mathias */,String.prototype.codePointAt||function(){var t=function(){try{var t={},e=Object.defineProperty,n=e(t,t,t)&&e}catch(t){}return n}(),e=function(t){if(null==this)throw TypeError();var e=String(this),n=e.length,i=t?Number(t):0;if(i!=i&&(i=0),!(i<0||i>=n)){var r,s=e.charCodeAt(i);return s>=55296&&s<=56319&&n>i+1&&(r=e.charCodeAt(i+1))>=56320&&r<=57343?1024*(s-55296)+r-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e}(),Math.log10=Math.log10||function(t){return Math.log(t)*Math.LOG10E},t.exports=function(){function t(e,n,i){function r(o,a){if(!n[o]){if(!e[o]){if(!a&&er)return er(o);if(s)return s(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[o]={exports:{}};e[o][0].call(l.exports,function(t){return r(e[o][1][t]||t)},l,l.exports,t,e,n,i)}return n[o].exports}for(var s=er,o=0;o<i.length;o++)r(i[o]);return r}return t}()({1:[function(t,e,n){var i=t("./utils"),r=function(){var t=i.stringToArray,e=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],n=["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fifteenth","Sixteenth","Seventeenth","Eighteenth","Nineteenth"],r=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],s=["Thousand","Million","Billion","Trillion"];function o(t,i){var o=function t(i,o,a){var c="";if(i<=19)c=(o?" and ":"")+(a?n[i]:e[i]);else if(i<100){var l=Math.floor(i/10),h=i%10;c=(o?" and ":"")+r[l-2],h>0?c+="-"+t(h,!1,a):a&&(c=c.substring(0,c.length-1)+"ieth")}else if(i<1e3){var d=Math.floor(i/100),u=i%100;c=(o?", ":"")+e[d]+" Hundred",u>0?c+=t(u,!0,a):a&&(c+="th")}else{var p=Math.floor(Math.log10(i)/3);p>s.length&&(p=s.length);var f=Math.pow(10,3*p),g=Math.floor(i/f),m=i-g*f;c=(o?", ":"")+t(g,!1,!1)+" "+s[p-1],m>0?c+=t(m,!0,a):a&&(c+="th")}return c};return o(t,!1,i)}var a={};function c(t){var e=t.split(/,\s|\sand\s|[\s\\-]/).map(function(t){return a[t]}),n=[0];return e.forEach(function(t){if(t<100){var e=n.pop();e>=1e3&&(n.push(e),e=0),n.push(e+t)}else n.push(n.pop()*t)}),n.reduce(function(t,e){return t+e},0)}e.forEach(function(t,e){a[t.toLowerCase()]=e}),n.forEach(function(t,e){a[t.toLowerCase()]=e}),r.forEach(function(t,e){var n=t.toLowerCase();a[n]=10*(e+2),a[n.substring(0,t.length-1)+"ieth"]=a[n]}),a.hundredth=100,s.forEach(function(t,e){var n=t.toLowerCase(),i=Math.pow(10,3*(e+1));a[n]=i,a[n+"th"]=i});var l=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]],h={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};function d(t){for(var e=0;e<l.length;e++){var n=l[e];if(t>=n[0])return n[1]+d(t-n[0])}return""}function u(t){for(var e=0,n=1,i=t.length-1;i>=0;i--){var r=t[i],s=h[r];s<n?e-=s:(n=s,e+=s)}return e}function p(t,e){for(var n=[],i=e.charCodeAt(0);t>0;)n.unshift(String.fromCharCode((t-1)%26+i)),t=Math.floor((t-1)/26);return n.join("")}function f(t,e){for(var n=e.charCodeAt(0),i=0,r=0;r<t.length;r++)i+=(t.charCodeAt(t.length-r-1)-n+1)*Math.pow(26,r);return i}function g(t,e){if(void 0!==t)return b(t=Math.floor(t),_(e))}var m={DECIMAL:"decimal",LETTERS:"letters",ROMAN:"roman",WORDS:"words",SEQUENCE:"sequence"},y={UPPER:"upper",LOWER:"lower",TITLE:"title"};function b(e,n){var i,r=e<0;switch(e=Math.abs(e),n.primary){case m.LETTERS:i=p(e,n.case===y.UPPER?"A":"a");break;case m.ROMAN:i=d(e),n.case===y.UPPER&&(i=i.toUpperCase());break;case m.WORDS:i=o(e,n.ordinal),n.case===y.UPPER?i=i.toUpperCase():n.case===y.LOWER&&(i=i.toLowerCase());break;case m.DECIMAL:i=""+e;var s=n.mandatoryDigits-i.length;if(s>0){var a=new Array(s+1).join("0");i=a+i}if(48!==n.zeroCode&&(i=t(i).map(function(t){return String.fromCodePoint(t.codePointAt(0)+n.zeroCode-48)}).join("")),n.regular)for(var c=Math.floor((i.length-1)/n.groupingSeparators.position);c>0;c--){var l=i.length-c*n.groupingSeparators.position;i=i.substr(0,l)+n.groupingSeparators.character+i.substr(l)}else n.groupingSeparators.reverse().forEach(function(t){var e=i.length-t.position;i=i.substr(0,e)+t.character+i.substr(e)});if(n.ordinal){var h={1:"st",2:"nd",3:"rd"}[i[i.length-1]];(!h||i.length>1&&"1"===i[i.length-2])&&(h="th"),i+=h}break;case m.SEQUENCE:throw{code:"D3130",value:n.token}}return r&&(i="-"+i),i}var v=[48,1632,1776,1984,2406,2534,2662,2790,2918,3046,3174,3302,3430,3558,3664,3792,3872,4160,4240,6112,6160,6470,6608,6784,6800,6992,7088,7232,7248,42528,43216,43264,43472,43504,43600,44016,65296];function _(e){var n,i={type:"integer",primary:m.DECIMAL,case:y.LOWER,ordinal:!1},r=e.lastIndexOf(";");switch(-1===r?n=e:(n=e.substring(0,r),"o"===e.substring(r+1)[0]&&(i.ordinal=!0)),n){case"A":i.case=y.UPPER;case"a":i.primary=m.LETTERS;break;case"I":i.case=y.UPPER;case"i":i.primary=m.ROMAN;break;case"W":i.case=y.UPPER,i.primary=m.WORDS;break;case"Ww":i.case=y.TITLE,i.primary=m.WORDS;break;case"w":i.primary=m.WORDS;break;default:var s=null,o=0,a=0,c=[],l=0;if(t(n).map(function(t){return t.codePointAt(0)}).reverse().forEach(function(t){for(var e=!1,n=0;n<v.length;n++){var i=v[n];if(t>=i&&t<=i+9){if(e=!0,o++,l++,null===s)s=i;else if(i!==s)throw{code:"D3131"};break}}e||(35===t?(l++,a++):c.push({position:l,character:String.fromCodePoint(t)}))}),o>0){i.primary=m.DECIMAL,i.zeroCode=s,i.mandatoryDigits=o,i.optionalDigits=a;var h=function(t){if(0===t.length)return 0;for(var e=t[0].character,n=1;n<t.length;n++)if(t[n].character!==e)return 0;for(var i=t.map(function(t){return t.position}),r=function t(e,n){return 0===n?e:t(n,e%n)},s=i.reduce(r),o=1;o<=i.length;o++)if(-1===i.indexOf(o*s))return 0;return s}(c);h>0?(i.regular=!0,i.groupingSeparators={position:h,character:c[0].character}):(i.regular=!1,i.groupingSeparators=c)}else i.primary=m.SEQUENCE,i.token=n}return i}var x={Y:"1",M:"1",D:"1",d:"1",F:"n",W:"1",w:"1",X:"1",x:"1",H:"1",h:"1",P:"n",m:"01",s:"01",f:"1",Z:"01:01",z:"01:01",C:"n",E:"n"};function w(t){for(var e=[],n={type:"datetime",parts:e},i=function(n,i){if(i>n){var r=t.substring(n,i);r=r.split("]]").join("]"),e.push({type:"literal",value:r})}},r=0,s=0;s<t.length;){if("["===t.charAt(s)){if("["===t.charAt(s+1)){i(r,s),e.push({type:"literal",value:"["}),r=s+=2;continue}if(i(r,s),r=s,-1===(s=t.indexOf("]",r)))throw{code:"D3135"};var o,a=t.substring(r+1,s),c={type:"marker",component:(a=a.split(/\s+/).join("")).charAt(0)},l=a.lastIndexOf(",");if(-1!==l){var h=a.substring(l+1),d=h.indexOf("-"),u=void 0,p=void 0,f=function(t){return void 0===t||"*"===t?void 0:parseInt(t)};-1===d?u=h:(u=h.substring(0,d),p=h.substring(d+1));var g={min:f(u),max:f(p)};c.width=g,o=a.substring(1,l)}else o=a.substring(1);if(1===o.length)c.presentation1=o;else if(o.length>1){var m=o.charAt(o.length-1);-1!=="atco".indexOf(m)?(c.presentation2=m,"o"===m&&(c.ordinal=!0),c.presentation1=o.substring(0,o.length-1)):c.presentation1=o}else c.presentation1=x[c.component];if(void 0===c.presentation1)throw{code:"D3132",value:c.component};if("n"===c.presentation1[0])c.names=y.LOWER;else if("N"===c.presentation1[0])"n"===c.presentation1[1]?c.names=y.TITLE:c.names=y.UPPER;else if(-1!=="YMDdFWwXxHhmsf".indexOf(c.component)){var b=c.presentation1;if(c.presentation2&&(b+=";"+c.presentation2),c.integerFormat=_(b),c.width&&void 0!==c.width.min&&c.integerFormat.mandatoryDigits<c.width.min&&(c.integerFormat.mandatoryDigits=c.width.min),-1!=="YMD".indexOf(c.component))if(c.n=-1,c.width&&void 0!==c.width.max)c.n=c.width.max,c.integerFormat.mandatoryDigits=c.n;else{var v=c.integerFormat.mandatoryDigits+c.integerFormat.optionalDigits;v>=2&&(c.n=v)}}"Z"!==c.component&&"z"!==c.component||(c.integerFormat=_(c.presentation1)),e.push(c),r=s+1}s++}return i(r,s),n}var M=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],S=["January","February","March","April","May","June","July","August","September","October","November","December"],k=864e5,A=function(t){var e=Date.UTC(t.year,t.month),n=new Date(e).getUTCDay();return 0===n&&(n=7),n>4?e+(8-n)*k:e-(n-1)*k},E=function t(e,n){return{year:e,month:n,nextMonth:function(){return 11===n?t(e+1,0):t(e,n+1)},previousMonth:function(){return 0===n?t(e-1,11):t(e,n-1)},nextYear:function(){return t(e+1,n)},previousYear:function(){return t(e-1,n)}}},C=function(t,e){return(e-t)/(7*k)+1},T=function(t,e){var n;switch(e){case"Y":n=t.getUTCFullYear();break;case"M":n=t.getUTCMonth()+1;break;case"D":n=t.getUTCDate();break;case"d":n=(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-Date.UTC(t.getUTCFullYear(),0))/k+1;break;case"F":0===(n=t.getUTCDay())&&(n=7);break;case"W":var i=E(t.getUTCFullYear(),0),r=A(i),s=Date.UTC(i.year,t.getUTCMonth(),t.getUTCDate()),o=C(r,s);if(o>52)s>=A(i.nextYear())&&(o=1);else if(o<1){var a=A(i.previousYear());o=C(a,s)}n=Math.floor(o);break;case"w":var c=E(t.getUTCFullYear(),t.getUTCMonth()),l=A(c),h=Date.UTC(c.year,c.month,t.getUTCDate()),d=C(l,h);if(d>4)h>=A(c.nextMonth())&&(d=1);else if(d<1){var u=A(c.previousMonth());d=C(u,h)}n=Math.floor(d);break;case"X":var p=E(t.getUTCFullYear(),0),f=A(p),g=A(p.nextYear()),m=t.getTime();n=m<f?p.year-1:m>=g?p.year+1:p.year;break;case"x":var y=E(t.getUTCFullYear(),t.getUTCMonth()),b=A(y),v=y.nextMonth(),_=A(v),x=t.getTime();n=x<b?y.previousMonth().month+1:x>=_?v.month+1:y.month+1;break;case"H":n=t.getUTCHours();break;case"h":n=t.getUTCHours(),0==(n%=12)&&(n=12);break;case"P":n=t.getUTCHours()>=12?"pm":"am";break;case"m":n=t.getUTCMinutes();break;case"s":n=t.getUTCSeconds();break;case"f":n=t.getUTCMilliseconds();break;case"Z":case"z":break;case"C":case"E":n="ISO"}return n},P=null;function D(t,e,n){var i=0,r=0;if(void 0!==n){var s=parseInt(n);i=Math.floor(s/100),r=s%100}var o,a=function(t,e){var n=T(t,e.component);if(-1!=="YMDdFWwXxHhms".indexOf(e.component))if("Y"===e.component&&-1!==e.n&&(n%=Math.pow(10,e.n)),e.names){if("M"===e.component||"x"===e.component)n=S[n-1];else{if("F"!==e.component)throw{code:"D3133",value:e.component};n=M[n]}e.names===y.UPPER?n=n.toUpperCase():e.names===y.LOWER&&(n=n.toLowerCase()),e.width&&n.length>e.width.max&&(n=n.substring(0,e.width.max))}else n=b(n,e.integerFormat);else if("f"===e.component)n=b(n,e.integerFormat);else if("Z"===e.component||"z"===e.component){var s=100*i+r;if(e.integerFormat.regular)n=b(s,e.integerFormat);else{var o=e.integerFormat.mandatoryDigits;if(1===o||2===o)n=b(i,e.integerFormat),0!==r&&(n+=":"+g(r,"00"));else{if(3!==o&&4!==o)throw{code:"D3134",value:o};n=b(s,e.integerFormat)}}s>=0&&(n="+"+n),"z"===e.component&&(n="GMT"+n),0===s&&"t"===e.presentation2&&(n="Z")}return n};void 0===e?(null===P&&(P=w("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),o=P):o=w(e);var c=new Date(t+60*(60*i+r)*1e3),l="";return o.parts.forEach(function(t){"literal"===t.type?l+=t.value:l+=a(c,t)}),l}function O(t){var e={};if("datetime"===t.type)e.type="datetime",e.parts=t.parts.map(function(t){var e={};if("literal"===t.type)e.regex=t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if("Z"===t.component||"z"===t.component){var n;Array.isArray(t.integerFormat.groupingSeparators)||(n=t.integerFormat.groupingSeparators),e.regex="","z"===t.component&&(e.regex="GMT"),e.regex+="[-+][0-9]+",n&&(e.regex+=n.character+"[0-9]+"),e.parse=function(e){"z"===t.component&&(e=e.substring(3));var i=0,r=0;return n?(i=Number.parseInt(e.substring(0,e.indexOf(n.character))),r=Number.parseInt(e.substring(e.indexOf(n.character)+1))):e.length-1<=2?i=Number.parseInt(e):(i=Number.parseInt(e.substring(0,3)),r=Number.parseInt(e.substring(3))),60*i+r}}else if(t.integerFormat)t.integerFormat.n=t.n,e=O(t.integerFormat);else{e.regex="[a-zA-Z]+";var i={};if("M"===t.component||"x"===t.component)S.forEach(function(e,n){t.width&&t.width.max?i[e.substring(0,t.width.max)]=n+1:i[e]=n+1});else if("F"===t.component)M.forEach(function(e,n){n>0&&(t.width&&t.width.max?i[e.substring(0,t.width.max)]=n:i[e]=n)});else{if("P"!==t.component)throw{code:"D3133",value:t.component};i={am:0,AM:0,pm:1,PM:1}}e.parse=function(t){return i[t]}}return e.component=t.component,e});else{e.type="integer";var n,i=t.case===y.UPPER;switch(n=t.n&&t.n>0?0===t.optionalDigits?"{".concat(t.n,"}"):"{".concat(t.n-t.optionalDigits,",").concat(t.n,"}"):"+",t.primary){case m.LETTERS:e.regex=i?"[A-Z]+":"[a-z]+",e.parse=function(t){return f(t,i?"A":"a")};break;case m.ROMAN:e.regex=i?"[MDCLXVI]+":"[mdclxvi]+",e.parse=function(t){return u(i?t:t.toUpperCase())};break;case m.WORDS:e.regex="(?:"+Object.keys(a).concat("and","[\\-, ]").join("|")+")+",e.parse=function(t){return c(t.toLowerCase())};break;case m.DECIMAL:e.regex="[0-9]".concat(n),t.ordinal&&(e.regex+="(?:th|st|nd|rd)"),e.parse=function(e){var n=e;return t.ordinal&&(n=e.substring(0,e.length-2)),t.regular?n=n.split(",").join(""):t.groupingSeparators.forEach(function(t){n=n.split(t.character).join("")}),48!==t.zeroCode&&(n=n.split("").map(function(e){return String.fromCodePoint(e.codePointAt(0)-t.zeroCode+48)}).join("")),parseInt(n)};break;case m.SEQUENCE:throw{code:"D3130",value:t.token}}}return e}function z(t,e){if(void 0!==t)return O(_(e)).parse(t)}function I(t,e){var n=O(w(e)),i="^"+n.parts.map(function(t){return"("+t.regex+")"}).join("")+"$",r=new RegExp(i,"i").exec(t);if(null!==r){for(var s=161,o=130,a=84,c=72,l=23,h=47,d={},u=1;u<r.length;u++){var p=n.parts[u-1];p.parse&&(d[p.component]=p.parse(r[u]))}if(0===Object.getOwnPropertyNames(d).length)return;var f=0,g=function(t){f<<=1,f+=t?1:0},m=function(t){return!(~t&f||!(t&f))};"YXMxWwdD".split("").forEach(function(t){return g(d[t])});var y=!m(s)&&m(o),b=m(a),v=!b&&m(c);f=0,"PHhmsf".split("").forEach(function(t){return g(d[t])});var _=!m(l)&&m(h),x=(y?"YD":b?"XxwF":v?"XWF":"YMD")+(_?"Phmsf":"Hmsf"),M=this.environment.timestamp,S=!1,k=!1;if(x.split("").forEach(function(t){if(void 0===d[t])S?(d[t]=-1!=="MDd".indexOf(t)?1:0,k=!0):d[t]=T(M,t);else if(S=!0,k)throw{code:"D3136"}}),d.M>0?d.M-=1:d.M=0,y){var A=Date.UTC(d.Y,0),E=1e3*(d.d-1)*60*60*24,C=new Date(A+E);d.M=C.getUTCMonth(),d.D=C.getUTCDate()}if(b)throw{code:"D3136"};if(v)throw{code:"D3136"};_&&(d.H=12===d.h?0:d.h,1===d.P&&(d.H+=12));var P=Date.UTC(d.Y,d.M,d.D,d.H,d.m,d.s,d.f);return(d.Z||d.z)&&(P-=60*(d.Z||d.z)*1e3),P}}var L=new RegExp("^\\d{4}(-[01]\\d)*(-[0-3]\\d)*(T[0-2]\\d:[0-5]\\d:[0-5]\\d)*(\\.\\d+)?([+-][0-2]\\d:?[0-5]\\d|Z)?$");function j(t,e){if(void 0!==t){if(void 0===e){if(!L.test(t))throw{stack:(new Error).stack,code:"D3110",value:t};return Date.parse(t)}return I.call(this,t,e)}}function R(t,e,n){if(void 0!==t)return D.call(this,t,e,n)}return{formatInteger:g,parseInteger:z,fromMillis:R,toMillis:j}}();e.exports=r},{"./utils":6}],2:[function(t,e,n){(function(n){(function(){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */r=function(){return e};var t,e={},n=Object.prototype,s=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",l=a.asyncIterator||"@@asyncIterator",h=a.toStringTag||"@@toStringTag";function d(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{d({},"")}catch(t){d=function(t,e,n){return t[e]=n}}function u(t,e,n,i){var r=e&&e.prototype instanceof v?e:v,s=Object.create(r.prototype),a=new O(i||[]);return o(s,"_invoke",{value:C(t,n,a)}),s}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=u;var f="suspendedStart",g="suspendedYield",m="executing",y="completed",b={};function v(){}function _(){}function x(){}var w={};d(w,c,function(){return this});var M=Object.getPrototypeOf,S=M&&M(M(z([])));S&&S!==n&&s.call(S,c)&&(w=S);var k=x.prototype=v.prototype=Object.create(w);function A(t){["next","throw","return"].forEach(function(e){d(t,e,function(t){return this._invoke(e,t)})})}function E(t,e){function n(r,o,a,c){var l=p(t[r],t,o);if("throw"!==l.type){var h=l.arg,d=h.value;return d&&"object"==i(d)&&s.call(d,"__await")?e.resolve(d.__await).then(function(t){n("next",t,a,c)},function(t){n("throw",t,a,c)}):e.resolve(d).then(function(t){h.value=t,a(h)},function(t){return n("throw",t,a,c)})}c(l.arg)}var r;o(this,"_invoke",{value:function(t,i){function s(){return new e(function(e,r){n(t,i,e,r)})}return r=r?r.then(s,s):s()}})}function C(e,n,i){var r=f;return function(s,o){if(r===m)throw new Error("Generator is already running");if(r===y){if("throw"===s)throw o;return{value:t,done:!0}}for(i.method=s,i.arg=o;;){var a=i.delegate;if(a){var c=T(a,i);if(c){if(c===b)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===f)throw r=y,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=m;var l=p(e,n,i);if("normal"===l.type){if(r=i.done?y:g,l.arg===b)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(r=y,i.method="throw",i.arg=l.arg)}}}function T(e,n){var i=n.method,r=e.iterator[i];if(r===t)return n.delegate=null,"throw"===i&&e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),b;var s=p(r,e.iterator,n.arg);if("throw"===s.type)return n.method="throw",n.arg=s.arg,n.delegate=null,b;var o=s.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,b):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,b)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function D(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function z(e){if(e||""===e){var n=e[c];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function n(){for(;++r<e.length;)if(s.call(e,r))return n.value=e[r],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(i(e)+" is not iterable")}return _.prototype=x,o(k,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:_,configurable:!0}),_.displayName=d(x,h,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,d(t,h,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},A(E.prototype),d(E.prototype,l,function(){return this}),e.AsyncIterator=E,e.async=function(t,n,i,r,s){void 0===s&&(s=Promise);var o=new E(u(t,n,i,r),s);return e.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},A(k),d(k,h,"Generator"),d(k,c,function(){return this}),d(k,"toString",function(){return"[object Generator]"}),e.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},e.values=z,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(D),!e)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(i,r){return a.type="throw",a.arg=e,n.next=i,r&&(n.method="next",n.arg=t),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),l=s.call(o,"finallyLoc");if(c&&l){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&s.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=t,o.arg=e,r?(this.method="next",this.next=r.finallyLoc,b):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),D(n),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var r=i.arg;D(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,i){return this.delegate={iterator:z(e),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=t),b}},e}var s=t("./utils"),o=function(){var t=r().mark(H),e=r().mark(Y),o=r().mark(V),a=r().mark(G),c=r().mark(Q),l=r().mark(ut),h=r().mark(pt),d=r().mark(ft),u=r().mark(mt),p=r().mark(St),f=r().mark(Ct),g=r().mark(Dt),m=s.isNumeric,y=s.isArrayOfStrings,b=s.isArrayOfNumbers,v=s.createSequence,_=s.isSequence,x=s.isFunction,w=s.isLambda,M=s.isIterable,S=s.getFunctionArity,k=s.isDeepEqual,A=s.stringToArray;function E(t){if(void 0!==t){var e=0;return t.forEach(function(t){e+=t}),e}}function C(t){return void 0===t?0:t.length}function T(t){if(void 0!==t&&0!==t.length)return Math.max.apply(Math,t)}function P(t){if(void 0!==t&&0!==t.length)return Math.min.apply(Math,t)}function D(t){if(void 0!==t&&0!==t.length){var e=0;return t.forEach(function(t){e+=t}),e/t.length}}function O(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(void 0!==t){var n;if("string"==typeof t)n=t;else if(x(t))n="";else{if("number"==typeof t&&!isFinite(t))throw{code:"D3001",value:t,stack:(new Error).stack};var i=e?2:0;Array.isArray(t)&&t.outerWrapper&&(t=t[0]),n=JSON.stringify(t,function(t,e){return null!=e&&e.toPrecision&&m(e)?Number(e.toPrecision(15)):e&&x(e)?"":e},i)}return n}}function z(t,e,n){if(void 0!==t){var i=A(t),r=i.length;if(r+e<0&&(e=0),void 0!==n){if(n<=0)return"";var s=e>=0?e+n:r+e+n;return i.slice(e,s).join("")}return i.slice(e).join("")}}function I(t,e){if(void 0!==t){var n=t.indexOf(e);return n>-1?t.substr(0,n):t}}function L(t,e){if(void 0!==t){var n=t.indexOf(e);return n>-1?t.substr(n+e.length):t}}function j(t){if(void 0!==t)return t.toLowerCase()}function R(t){if(void 0!==t)return t.toUpperCase()}function F(t){if(void 0!==t)return A(t).length}function B(t){if(void 0!==t){var e=t.replace(/[ \t\n\r]+/gm," ");return" "===e.charAt(0)&&(e=e.substring(1))," "===e.charAt(e.length-1)&&(e=e.substring(0,e.length-1)),e}}function N(t,e,n){if(void 0!==t){var i;void 0!==n&&0!==n.length||(n=" ");var r=Math.abs(e)-F(t);if(r>0){var s=new Array(r+1).join(n);n.length>1&&(s=z(s,0,r)),i=e>0?t+s:s+t}else i=t;return i}}function H(e,n){var i;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=e.apply(this,[n]),!M(i)){t.next=4;break}return t.delegateYield(i,"t0",3);case 3:i=t.t0;case 4:if(!i||"number"==typeof i.start||"number"===i.end||Array.isArray(i.groups)||x(i.next)){t.next=6;break}throw{code:"T1010",stack:(new Error).stack};case 6:return t.abrupt("return",i);case 7:case"end":return t.stop()}},t,this)}function Y(t,n){var i,s;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t){e.next=2;break}return e.abrupt("return",void 0);case 2:if("string"!=typeof n){e.next=6;break}i=-1!==t.indexOf(n),e.next=9;break;case 6:return e.delegateYield(H(n,t),"t0",7);case 7:s=e.t0,i=void 0!==s;case 9:return e.abrupt("return",i);case 10:case"end":return e.stop()}},e)}function V(t,e,n){var i,s,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(!(n<0)){r.next=4;break}throw{stack:(new Error).stack,value:n,code:"D3040",index:3};case 4:if(i=v(),!(void 0===n||n>0)){r.next=17;break}return s=0,r.delegateYield(H(e,t),"t0",8);case 8:if(void 0===(a=r.t0)){r.next=17;break}case 10:if(void 0===a||!(void 0===n||s<n)){r.next=17;break}return i.push({match:a.match,index:a.start,groups:a.groups}),r.delegateYield(H(a.next),"t1",13);case 13:a=r.t1,s++,r.next=10;break;case 17:return r.abrupt("return",i);case 18:case"end":return r.stop()}},o)}function G(t,e,n,i){var s,o,c,l,h,d,u,p;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(s=this,""!==e){r.next=5;break}throw{code:"D3010",stack:(new Error).stack,value:e,index:2};case 5:if(!(i<0)){r.next=7;break}throw{code:"D3011",stack:(new Error).stack,value:i,index:4};case 7:if(o="string"==typeof n?function(t){for(var e="",i=0,r=n.indexOf("$",i);-1!==r&&i<n.length;){e+=n.substring(i,r),i=r+1;var s=n.charAt(i);if("$"===s)e+="$",i++;else if("0"===s)e+=t.match,i++;else{var o;if(o=0===t.groups.length?1:Math.floor(Math.log(t.groups.length)*Math.LOG10E)+1,r=parseInt(n.substring(i,i+o),10),o>1&&r>t.groups.length&&(r=parseInt(n.substring(i,i+o-1),10)),isNaN(r))e+="$";else{if(t.groups.length>0){var a=t.groups[r-1];void 0!==a&&(e+=a)}i+=r.toString().length}}r=n.indexOf("$",i)}return e+=n.substring(i)}:n,c="",l=0,!(void 0===i||i>0)){r.next=44;break}if(h=0,"string"!=typeof e){r.next=18;break}for(d=t.indexOf(e,l);-1!==d&&(void 0===i||h<i);)c+=t.substring(l,d),c+=n,l=d+e.length,h++,d=t.indexOf(e,l);c+=t.substring(l),r.next=42;break;case 18:return r.delegateYield(H(e,t),"t0",19);case 19:if(void 0===(u=r.t0)){r.next=41;break}case 21:if(void 0===u||!(void 0===i||h<i)){r.next=38;break}if(c+=t.substring(l,u.start),p=o.apply(s,[u]),!M(p)){r.next=27;break}return r.delegateYield(p,"t1",26);case 26:p=r.t1;case 27:if("string"!=typeof p){r.next=31;break}c+=p,r.next=32;break;case 31:throw{code:"D3012",stack:(new Error).stack,value:p};case 32:return l=u.start+u.match.length,h++,r.delegateYield(H(u.next),"t2",35);case 35:u=r.t2,r.next=21;break;case 38:c+=t.substring(l),r.next=42;break;case 41:c=t;case 42:r.next=45;break;case 44:c=t;case 45:return r.abrupt("return",c);case 46:case"end":return r.stop()}},a,this)}function U(t){if(void 0!==t){var e="undefined"!=typeof window?window.btoa:function(t){return new n.Buffer.from(t,"binary").toString("base64")};return e(t)}}function W(t){if(void 0!==t){var e="undefined"!=typeof window?window.atob:function(t){return new n.Buffer.from(t,"base64").toString("binary")};return e(t)}}function X(t){if(void 0!==t){var e;try{e=encodeURIComponent(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"encodeUrlComponent"}}return e}}function q(t){if(void 0!==t){var e;try{e=encodeURI(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"encodeUrl"}}return e}}function K(t){if(void 0!==t){var e;try{e=decodeURIComponent(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"decodeUrlComponent"}}return e}}function $(t){if(void 0!==t){var e;try{e=decodeURI(t)}catch(e){throw{code:"D3140",stack:(new Error).stack,value:t,functionName:"decodeUrl"}}return e}}function Q(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(!(n<0)){r.next=4;break}throw{code:"D3020",stack:(new Error).stack,value:n,index:3};case 4:if(i=[],!(void 0===n||n>0)){r.next=27;break}if("string"!=typeof e){r.next=10;break}i=t.split(e,n),r.next=27;break;case 10:return s=0,r.delegateYield(H(e,t),"t0",12);case 12:if(void 0===(o=r.t0)){r.next=26;break}a=0;case 15:if(void 0===o||!(void 0===n||s<n)){r.next=23;break}return i.push(t.substring(a,o.start)),a=o.end,r.delegateYield(H(o.next),"t1",19);case 19:o=r.t1,s++,r.next=15;break;case 23:(void 0===n||s<n)&&i.push(t.substring(a)),r.next=27;break;case 26:i.push(t);case 27:return r.abrupt("return",i);case 28:case"end":return r.stop()}},c)}function Z(t,e){if(void 0!==t)return void 0===e&&(e=""),t.join(e)}function J(t,e,n){if(void 0!==t){var i={"decimal-separator":".","grouping-separator":",","exponent-separator":"e",infinity:"Infinity","minus-sign":"-",NaN:"NaN",percent:"%","per-mille":"‰","zero-digit":"0",digit:"#","pattern-separator":";"};void 0!==n&&Object.keys(n).forEach(function(t){i[t]=n[t]});for(var r=[],s=i["zero-digit"].charCodeAt(0),o=s;o<s+10;o++)r.push(String.fromCharCode(o));var a=r.concat([i["decimal-separator"],i["exponent-separator"],i["grouping-separator"],i.digit,i["pattern-separator"]]),c=e.split(i["pattern-separator"]);if(c.length>2)throw{code:"D3080",stack:(new Error).stack};var l=function(t){var e,n,r,s,o=function(){for(var e,n=0;n<t.length;n++)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(0,n)}(),c=function(){for(var e,n=t.length-1;n>=0;n--)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(n+1)}(),l=t.substring(o.length,t.length-c.length),h=t.indexOf(i["exponent-separator"],o.length);-1===h||h>t.length-c.length?(e=l,n=void 0):(e=l.substring(0,h),n=l.substring(h+1));var d=e.indexOf(i["decimal-separator"]);return-1===d?(r=e,s=c):(r=e.substring(0,d),s=e.substring(d+1)),{prefix:o,suffix:c,activePart:l,mantissaPart:e,exponentPart:n,integerPart:r,fractionalPart:s,subpicture:t}},h=function(t){var e,n,s=t.subpicture,o=s.indexOf(i["decimal-separator"]);o!==s.lastIndexOf(i["decimal-separator"])&&(e="D3081"),s.indexOf(i.percent)!==s.lastIndexOf(i.percent)&&(e="D3082"),s.indexOf(i["per-mille"])!==s.lastIndexOf(i["per-mille"])&&(e="D3083"),-1!==s.indexOf(i.percent)&&-1!==s.indexOf(i["per-mille"])&&(e="D3084");var c=!1;for(n=0;n<t.mantissaPart.length;n++){var l=t.mantissaPart.charAt(n);if(-1!==r.indexOf(l)||l===i.digit){c=!0;break}}c||(e="D3085"),-1!==t.activePart.split("").map(function(t){return-1===a.indexOf(t)?"p":"a"}).join("").indexOf("p")&&(e="D3086"),-1!==o?s.charAt(o-1)!==i["grouping-separator"]&&s.charAt(o+1)!==i["grouping-separator"]||(e="D3087"):t.integerPart.charAt(t.integerPart.length-1)===i["grouping-separator"]&&(e="D3088"),-1!==s.indexOf(i["grouping-separator"]+i["grouping-separator"])&&(e="D3089");var h=t.integerPart.indexOf(i.digit);-1!==h&&t.integerPart.substring(0,h).split("").filter(function(t){return r.indexOf(t)>-1}).length>0&&(e="D3090"),-1!==(h=t.fractionalPart.lastIndexOf(i.digit))&&t.fractionalPart.substring(h).split("").filter(function(t){return r.indexOf(t)>-1}).length>0&&(e="D3091");var d="string"==typeof t.exponentPart;if(d&&t.exponentPart.length>0&&(-1!==s.indexOf(i.percent)||-1!==s.indexOf(i["per-mille"]))&&(e="D3092"),d&&(0===t.exponentPart.length||t.exponentPart.split("").filter(function(t){return-1===r.indexOf(t)}).length>0)&&(e="D3093"),e)throw{code:e,stack:(new Error).stack}},d=function(t){var e=function(e,n){for(var s=[],o=e.indexOf(i["grouping-separator"]);-1!==o;){var a=(n?e.substring(0,o):e.substring(o)).split("").filter(function(t){return-1!==r.indexOf(t)||t===i.digit}).length;s.push(a),o=t.integerPart.indexOf(i["grouping-separator"],o+1)}return s},n=e(t.integerPart),s=function(t){if(0===t.length)return 0;for(var e=function t(e,n){return 0===n?e:t(n,e%n)},n=t.reduce(e),i=1;i<=t.length;i++)if(-1===t.indexOf(i*n))return 0;return n}(n),o=e(t.fractionalPart,!0),a=t.integerPart.split("").filter(function(t){return-1!==r.indexOf(t)}).length,c=a,l=t.fractionalPart.split(""),h=l.filter(function(t){return-1!==r.indexOf(t)}).length,d=l.filter(function(t){return-1!==r.indexOf(t)||t===i.digit}).length,u="string"==typeof t.exponentPart;0===a&&0===d&&(u?(h=1,d=1):a=1),u&&0===a&&-1!==t.integerPart.indexOf(i.digit)&&(a=1),0===a&&0===h&&(h=1);var p=0;return u&&(p=t.exponentPart.split("").filter(function(t){return-1!==r.indexOf(t)}).length),{integerPartGroupingPositions:n,regularGrouping:s,minimumIntegerPartSize:a,scalingFactor:c,prefix:t.prefix,fractionalPartGroupingPositions:o,minimumFactionalPartSize:h,maximumFactionalPartSize:d,minimumExponentSize:p,suffix:t.suffix,picture:t.subpicture}},u=c.map(l);u.forEach(h);var p,f,g,m,y=u.map(d),b=i["minus-sign"],v=i["zero-digit"],_=i["decimal-separator"],x=i["grouping-separator"];if(1===y.length&&(y.push(JSON.parse(JSON.stringify(y[0]))),y[1].prefix=b+y[1].prefix),f=-1!==(p=t>=0?y[0]:y[1]).picture.indexOf(i.percent)?100*t:-1!==p.picture.indexOf(i["per-mille"])?1e3*t:t,0===p.minimumExponentSize)g=f;else{var w=Math.pow(10,p.scalingFactor),M=Math.pow(10,p.scalingFactor-1);for(g=f,m=0;g<M;)g*=10,m-=1;for(;g>w;)g/=10,m+=1}var S=function(t,e){var n=Math.abs(t).toFixed(e);return"0"!==v&&(n=n.split("").map(function(t){return t>="0"&&t<="9"?r[t.charCodeAt(0)-48]:t}).join("")),n},k=S(st(g,p.maximumFactionalPartSize),p.maximumFactionalPartSize),A=k.indexOf(".");for(-1===A?k+=_:k=k.replace(".",_);k.charAt(0)===v;)k=k.substring(1);for(;k.charAt(k.length-1)===v;)k=k.substring(0,k.length-1);A=k.indexOf(_);var E=p.minimumIntegerPartSize-A,C=p.minimumFactionalPartSize-(k.length-A-1);if(k=(E>0?new Array(E+1).join(v):"")+k,k+=C>0?new Array(C+1).join(v):"",A=k.indexOf(_),p.regularGrouping>0)for(var T=Math.floor((A-1)/p.regularGrouping),P=1;P<=T;P++)k=[k.slice(0,A-P*p.regularGrouping),x,k.slice(A-P*p.regularGrouping)].join("");else p.integerPartGroupingPositions.forEach(function(t){k=[k.slice(0,A-t),x,k.slice(A-t)].join(""),A++});if(A=k.indexOf(_),p.fractionalPartGroupingPositions.forEach(function(t){k=[k.slice(0,t+A+1),x,k.slice(t+A+1)].join("")}),A=k.indexOf(_),-1!==p.picture.indexOf(_)&&A!==k.length-1||(k=k.substring(0,k.length-1)),void 0!==m){var D=S(m,0);(E=p.minimumExponentSize-D.length)>0&&(D=new Array(E+1).join(v)+D),k=k+i["exponent-separator"]+(m<0?b:"")+D}return k=p.prefix+k+p.suffix}}function tt(t,e){if(void 0!==t){if(t=st(t),(e=void 0===e?10:st(e))<2||e>36)throw{code:"D3100",stack:(new Error).stack,value:e};return t.toString(e)}}function et(t){var e;if(void 0!==t){if("number"==typeof t)e=t;else if("string"==typeof t&&/^-?[0-9]+(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(t)&&!isNaN(parseFloat(t))&&isFinite(t))e=parseFloat(t);else if(!0===t)e=1;else{if(!1!==t)throw{code:"D3030",value:t,stack:(new Error).stack,index:1};e=0}return e}}function nt(t){if(void 0!==t)return Math.abs(t)}function it(t){if(void 0!==t)return Math.floor(t)}function rt(t){if(void 0!==t)return Math.ceil(t)}function st(t,e){var n;if(void 0!==t){if(e){var i=t.toString().split("e");t=+(i[0]+"e"+(i[1]?+i[1]+e:e))}var r=(n=Math.round(t))-t;return.5===Math.abs(r)&&1===Math.abs(n%2)&&(n-=1),e&&(i=n.toString().split("e"),n=+(i[0]+"e"+(i[1]?+i[1]-e:-e))),Object.is(n,-0)&&(n=0),n}}function ot(t){if(void 0!==t){if(t<0)throw{stack:(new Error).stack,code:"D3060",index:1,value:t};return Math.sqrt(t)}}function at(t,e){var n;if(void 0!==t){if(n=Math.pow(t,e),!isFinite(n))throw{stack:(new Error).stack,code:"D3061",index:1,value:t,exp:e};return n}}function ct(){return Math.random()}function lt(t){if(void 0!==t){var e=!1;return Array.isArray(t)?1===t.length?e=lt(t[0]):t.length>1&&(e=t.filter(function(t){return lt(t)}).length>0):"string"==typeof t?t.length>0&&(e=!0):m(t)?0!==t&&(e=!0):null!==t&&"object"===i(t)?Object.keys(t).length>0&&(e=!0):"boolean"==typeof t&&!0===t&&(e=!0),e}}function ht(t){if(void 0!==t)return!lt(t)}function dt(t,e,n,i){var r=[e],s=S(t);return s>=2&&r.push(n),s>=3&&r.push(i),r}function ut(t,e){var n,i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=v(),i=0;case 4:if(!(i<t.length)){r.next=12;break}return s=dt(e,t[i],i,t),r.delegateYield(e.apply(this,s),"t0",7);case 7:void 0!==(o=r.t0)&&n.push(o);case 9:i++,r.next=4;break;case 12:return r.abrupt("return",n);case 13:case"end":return r.stop()}},l,this)}function pt(t,e){var n,i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=v(),i=0;case 4:if(!(i<t.length)){r.next=13;break}return s=t[i],o=dt(e,s,i,t),r.delegateYield(e.apply(this,o),"t0",8);case 8:lt(r.t0)&&n.push(s);case 10:i++,r.next=4;break;case 13:return r.abrupt("return",n);case 14:case"end":return r.stop()}},h,this)}function ft(t,e){var n,i,s,o,a,c,l;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=!1,s=0;case 4:if(!(s<t.length)){r.next=22;break}if(o=t[s],a=!0,void 0===e){r.next=12;break}return c=dt(e,o,s,t),r.delegateYield(e.apply(this,c),"t0",10);case 10:l=r.t0,a=lt(l);case 12:if(!a){r.next=19;break}if(n){r.next=18;break}i=o,n=!0,r.next=19;break;case 18:throw{stack:(new Error).stack,code:"D3138",index:s};case 19:s++,r.next=4;break;case 22:if(n){r.next=24;break}throw{stack:(new Error).stack,code:"D3139"};case 24:return r.abrupt("return",i);case 25:case"end":return r.stop()}},d,this)}function gt(){for(var t=[],e=Array.prototype.slice.call(arguments),n=Math.min.apply(Math,e.map(function(t){return Array.isArray(t)?t.length:0})),i=0;i<n;i++){var r=e.map(function(t){return t[i]});t.push(r)}return t}function mt(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:if(!((s=S(e))<2)){r.next=5;break}throw{stack:(new Error).stack,code:"D3050",index:1};case 5:void 0===n&&t.length>0?(i=t[0],o=1):(i=n,o=0);case 6:if(!(o<t.length)){r.next=15;break}return a=[i,t[o]],s>=3&&a.push(o),s>=4&&a.push(t),r.delegateYield(e.apply(this,a),"t0",11);case 11:i=r.t0,o++,r.next=6;break;case 15:return r.abrupt("return",i);case 16:case"end":return r.stop()}},u,this)}function yt(t){var e=v();if(Array.isArray(t)){var n={};t.forEach(function(t){yt(t).forEach(function(t){n[t]=!0})}),e=yt(n)}else null===t||"object"!==i(t)||w(t)||Object.keys(t).forEach(function(t){return e.push(t)});return e}function bt(t,e){var n;if(Array.isArray(t)){n=v();for(var r=0;r<t.length;r++){var s=bt(t[r],e);void 0!==s&&(Array.isArray(s)?s.forEach(function(t){return n.push(t)}):n.push(s))}}else null!==t&&"object"===i(t)&&(n=t[e]);return n}function vt(t,e){return void 0===t?e:void 0===e?t:(Array.isArray(t)||(t=v(t)),Array.isArray(e)||(e=[e]),t.concat(e))}function _t(t){return void 0!==t}function xt(t){var e=v();if(Array.isArray(t))t.forEach(function(t){e=vt(e,xt(t))});else if(null===t||"object"!==i(t)||w(t))e=t;else for(var n in t){var r={};r[n]=t[n],e.push(r)}return e}function wt(t){if(void 0!==t){var e={};return t.forEach(function(t){for(var n in t)e[n]=t[n]}),e}}function Mt(t){if(void 0!==t){if(t.length<=1)return t;for(var e=t.length,n=new Array(e),i=0;i<e;i++)n[e-i-1]=t[i];return n}}function St(t,e){var n,i,s,o;return r().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n=v(),a.t0=r().keys(t);case 2:if((a.t1=a.t0()).done){a.next=10;break}return i=a.t1.value,s=dt(e,t[i],i,t),a.delegateYield(e.apply(this,s),"t2",6);case 6:void 0!==(o=a.t2)&&n.push(o),a.next=2;break;case 10:return a.abrupt("return",n);case 11:case"end":return a.stop()}},p,this)}function kt(t){throw{code:"D3137",stack:(new Error).stack,message:t||"$error() function evaluated"}}function At(t,e){if(!t)throw{code:"D3141",stack:(new Error).stack,message:e||"$assert() statement failed"}}function Et(t){if(void 0!==t)return null===t?"null":m(t)?"number":"string"==typeof t?"string":"boolean"==typeof t?"boolean":Array.isArray(t)?"array":x(t)?"function":"object"}function Ct(t,e){var n,i,s,o;return r().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(void 0!==t){a.next=2;break}return a.abrupt("return",void 0);case 2:if(!(t.length<=1)){a.next=4;break}return a.abrupt("return",t);case 4:if(void 0!==e){a.next=10;break}if(b(t)||y(t)){a.next=7;break}throw{stack:(new Error).stack,code:"D3070",index:1};case 7:n=r().mark(function t(e,n){return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e>n);case 1:case"end":return t.stop()}},t)}),a.next=11;break;case 10:n=e;case 11:return i=r().mark(function t(e,i){var s,o;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return s=r().mark(function t(e,i,s){return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(0!==i.length){r.next=4;break}Array.prototype.push.apply(e,s),r.next=16;break;case 4:if(0!==s.length){r.next=8;break}Array.prototype.push.apply(e,i),r.next=16;break;case 8:return r.delegateYield(n(i[0],s[0]),"t0",9);case 9:if(!r.t0){r.next=14;break}return e.push(s[0]),r.delegateYield(t(e,i,s.slice(1)),"t1",12);case 12:r.next=16;break;case 14:return e.push(i[0]),r.delegateYield(t(e,i.slice(1),s),"t2",16);case 16:case"end":return r.stop()}},t)}),o=[],t.delegateYield(s(o,e,i),"t0",3);case 3:return t.abrupt("return",o);case 4:case"end":return t.stop()}},t)}),s=r().mark(function t(e){var n,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(Array.isArray(e)&&!(e.length<=1)){r.next=4;break}return r.abrupt("return",e);case 4:return n=Math.floor(e.length/2),s=e.slice(0,n),o=e.slice(n),r.delegateYield(t(s),"t0",8);case 8:return s=r.t0,r.delegateYield(t(o),"t1",10);case 10:return o=r.t1,r.delegateYield(i(s,o),"t2",12);case 12:return r.abrupt("return",r.t2);case 13:case"end":return r.stop()}},t)}),a.delegateYield(s(t),"t0",14);case 14:return o=a.t0,a.abrupt("return",o);case 16:case"end":return a.stop()}},f)}function Tt(t){if(void 0!==t){if(t.length<=1)return t;for(var e=new Array(t.length),n=0;n<t.length;n++){var i=Math.floor(Math.random()*(n+1));n!==i&&(e[n]=e[i]),e[i]=t[n]}return e}}function Pt(t){if(void 0!==t){if(!Array.isArray(t)||t.length<=1)return t;for(var e=_(t)?v():[],n=0;n<t.length;n++){for(var i=t[n],r=!1,s=0;s<e.length;s++)if(k(i,e[s])){r=!0;break}r||e.push(i)}return e}}function Dt(t,e){var n,i,s,o;return r().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n={},a.t0=r().keys(t);case 2:if((a.t1=a.t0()).done){a.next=11;break}return i=a.t1.value,s=t[i],o=dt(e,s,i,t),a.delegateYield(e.apply(this,o),"t2",7);case 7:lt(a.t2)&&(n[i]=s),a.next=2;break;case 11:return 0===Object.keys(n).length&&(n=void 0),a.abrupt("return",n);case 13:case"end":return a.stop()}},g,this)}return{sum:E,count:C,max:T,min:P,average:D,string:O,substring:z,substringBefore:I,substringAfter:L,lowercase:j,uppercase:R,length:F,trim:B,pad:N,match:V,contains:Y,replace:G,split:Q,join:Z,formatNumber:J,formatBase:tt,number:et,floor:it,ceil:rt,round:st,abs:nt,sqrt:ot,power:at,random:ct,boolean:lt,not:ht,map:ut,zip:gt,filter:pt,single:ft,foldLeft:mt,sift:Dt,keys:yt,lookup:bt,append:vt,exists:_t,spread:xt,merge:wt,reverse:Mt,each:St,error:kt,assert:At,type:Et,sort:Ct,shuffle:Tt,distinct:Pt,base64encode:U,base64decode:W,encodeUrlComponent:X,encodeUrl:q,decodeUrlComponent:K,decodeUrl:$}}();e.exports=o}).call(this)}).call(this,void 0!==Ji?Ji:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils":6}],3:[function(t,e,n){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */r=function(){return e};var t,e={},n=Object.prototype,s=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",l=a.asyncIterator||"@@asyncIterator",h=a.toStringTag||"@@toStringTag";function d(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{d({},"")}catch(t){d=function(t,e,n){return t[e]=n}}function u(t,e,n,i){var r=e&&e.prototype instanceof v?e:v,s=Object.create(r.prototype),a=new O(i||[]);return o(s,"_invoke",{value:C(t,n,a)}),s}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=u;var f="suspendedStart",g="suspendedYield",m="executing",y="completed",b={};function v(){}function _(){}function x(){}var w={};d(w,c,function(){return this});var M=Object.getPrototypeOf,S=M&&M(M(z([])));S&&S!==n&&s.call(S,c)&&(w=S);var k=x.prototype=v.prototype=Object.create(w);function A(t){["next","throw","return"].forEach(function(e){d(t,e,function(t){return this._invoke(e,t)})})}function E(t,e){function n(r,o,a,c){var l=p(t[r],t,o);if("throw"!==l.type){var h=l.arg,d=h.value;return d&&"object"==i(d)&&s.call(d,"__await")?e.resolve(d.__await).then(function(t){n("next",t,a,c)},function(t){n("throw",t,a,c)}):e.resolve(d).then(function(t){h.value=t,a(h)},function(t){return n("throw",t,a,c)})}c(l.arg)}var r;o(this,"_invoke",{value:function(t,i){function s(){return new e(function(e,r){n(t,i,e,r)})}return r=r?r.then(s,s):s()}})}function C(e,n,i){var r=f;return function(s,o){if(r===m)throw new Error("Generator is already running");if(r===y){if("throw"===s)throw o;return{value:t,done:!0}}for(i.method=s,i.arg=o;;){var a=i.delegate;if(a){var c=T(a,i);if(c){if(c===b)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===f)throw r=y,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=m;var l=p(e,n,i);if("normal"===l.type){if(r=i.done?y:g,l.arg===b)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(r=y,i.method="throw",i.arg=l.arg)}}}function T(e,n){var i=n.method,r=e.iterator[i];if(r===t)return n.delegate=null,"throw"===i&&e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),b;var s=p(r,e.iterator,n.arg);if("throw"===s.type)return n.method="throw",n.arg=s.arg,n.delegate=null,b;var o=s.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,b):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,b)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function D(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function z(e){if(e||""===e){var n=e[c];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function n(){for(;++r<e.length;)if(s.call(e,r))return n.value=e[r],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(i(e)+" is not iterable")}return _.prototype=x,o(k,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:_,configurable:!0}),_.displayName=d(x,h,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,d(t,h,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},A(E.prototype),d(E.prototype,l,function(){return this}),e.AsyncIterator=E,e.async=function(t,n,i,r,s){void 0===s&&(s=Promise);var o=new E(u(t,n,i,r),s);return e.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},A(k),d(k,h,"Generator"),d(k,c,function(){return this}),d(k,"toString",function(){return"[object Generator]"}),e.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},e.values=z,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(D),!e)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(i,r){return a.type="throw",a.arg=e,n.next=i,r&&(n.method="next",n.arg=t),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),l=s.call(o,"finallyLoc");if(c&&l){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&s.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=t,o.arg=e,r?(this.method="next",this.next=r.finallyLoc,b):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),D(n),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var r=i.arg;D(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,i){return this.delegate={iterator:z(e),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=t),b}},e}var s=t("./datetime"),o=t("./functions"),a=t("./utils"),c=t("./parser"),l=t("./signature"),h=function(){var t=r().mark(N),e=r().mark(H),n=r().mark(V),h=r().mark(G),d=r().mark(U),u=r().mark(W),p=r().mark(X),f=r().mark(q),g=r().mark(st),m=r().mark(ct),y=r().mark(dt),b=r().mark(ut),v=r().mark(pt),_=r().mark(mt),x=r().mark(vt),w=r().mark(_t),M=r().mark(xt),S=r().mark(wt),k=r().mark(St),A=r().mark(At),E=r().mark(Tt),C=r().mark(Ot),T=a.isNumeric,P=a.isArrayOfStrings,D=a.isArrayOfNumbers,O=a.createSequence,z=a.isSequence,I=a.isFunction,L=a.isLambda,j=a.isIterable,R=a.getFunctionArity,F=a.isDeepEqual,B=It(null);function N(e,n,i){var s,o,a,c;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:(o=i.lookup("__evaluate_entry"))&&o(e,n,i),t.t0=e.type,t.next="path"===t.t0?5:"binary"===t.t0?8:"unary"===t.t0?11:"name"===t.t0?14:"string"===t.t0||"number"===t.t0||"value"===t.t0?16:"wildcard"===t.t0?18:"descendant"===t.t0?20:"parent"===t.t0?22:"condition"===t.t0?24:"block"===t.t0?27:"bind"===t.t0?30:"regex"===t.t0?33:"function"===t.t0?35:"variable"===t.t0?38:"lambda"===t.t0?40:"partial"===t.t0?42:"apply"===t.t0?45:"transform"===t.t0?48:50;break;case 5:return t.delegateYield(H(e,n,i),"t1",6);case 6:return s=t.t1,t.abrupt("break",50);case 8:return t.delegateYield(X(e,n,i),"t2",9);case 9:return s=t.t2,t.abrupt("break",50);case 11:return t.delegateYield(q(e,n,i),"t3",12);case 12:return s=t.t3,t.abrupt("break",50);case 14:return s=K(e,n),t.abrupt("break",50);case 16:return s=$(e),t.abrupt("break",50);case 18:return s=Q(e,n),t.abrupt("break",50);case 20:return s=J(e,n),t.abrupt("break",50);case 22:return s=i.lookup(e.slot.label),t.abrupt("break",50);case 24:return t.delegateYield(ut(e,n,i),"t4",25);case 25:return s=t.t4,t.abrupt("break",50);case 27:return t.delegateYield(pt(e,n,i),"t5",28);case 28:return s=t.t5,t.abrupt("break",50);case 30:return t.delegateYield(dt(e,n,i),"t6",31);case 31:return s=t.t6,t.abrupt("break",50);case 33:return s=ft(e),t.abrupt("break",50);case 35:return t.delegateYield(_t(e,n,i),"t7",36);case 36:return s=t.t7,t.abrupt("break",50);case 38:return s=gt(e,n,i),t.abrupt("break",50);case 40:return s=Mt(e,n,i),t.abrupt("break",50);case 42:return t.delegateYield(St(e,n,i),"t8",43);case 43:return s=t.t8,t.abrupt("break",50);case 45:return t.delegateYield(vt(e,n,i),"t9",46);case 46:return s=t.t9,t.abrupt("break",50);case 48:return s=yt(e,n,i),t.abrupt("break",50);case 50:if(!i.async||null!=s&&"function"==typeof s.then||(s=Promise.resolve(s)),!i.async||"function"!=typeof s.then||!e.nextFunction||"function"!=typeof s[e.nextFunction]){t.next=54;break}t.next=57;break;case 54:return t.next=56,s;case 56:s=t.sent;case 57:if(!Object.prototype.hasOwnProperty.call(e,"predicate")){t.next=65;break}a=0;case 59:if(!(a<e.predicate.length)){t.next=65;break}return t.delegateYield(W(e.predicate[a].expr,s,i),"t10",61);case 61:s=t.t10;case 62:a++,t.next=59;break;case 65:if("path"===e.type||!Object.prototype.hasOwnProperty.call(e,"group")){t.next=68;break}return t.delegateYield(ct(e.group,s,i),"t11",67);case 67:s=t.t11;case 68:return(c=i.lookup("__evaluate_exit"))&&c(e,n,i,s),s&&z(s)&&!s.tupleStream&&(e.keepArray&&(s.keepSingleton=!0),0===s.length?s=void 0:1===s.length&&(s=s.keepSingleton?s:s[0])),t.abrupt("return",s);case 72:case"end":return t.stop()}},t)}function H(t,n,i){var s,o,a,c,l,h;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:s=Array.isArray(n)&&"variable"!==t.steps[0].type?n:O(n),a=!1,c=void 0,l=0;case 4:if(!(l<t.steps.length)){e.next=25;break}if((h=t.steps[l]).tuple&&(a=!0),0!==l||!h.consarray){e.next=12;break}return e.delegateYield(N(h,s,i),"t0",9);case 9:o=e.t0,e.next=19;break;case 12:if(!a){e.next=17;break}return e.delegateYield(U(h,s,c,i),"t1",14);case 14:c=e.t1,e.next=19;break;case 17:return e.delegateYield(V(h,s,i,l===t.steps.length-1),"t2",18);case 18:o=e.t2;case 19:if(a||void 0!==o&&0!==o.length){e.next=21;break}return e.abrupt("break",25);case 21:void 0===h.focus&&(s=o);case 22:l++,e.next=4;break;case 25:if(a)if(t.tuple)o=c;else for(o=O(),l=0;l<c.length;l++)o.push(c[l]["@"]);if(t.keepSingletonArray&&(Array.isArray(o)&&o.cons&&!o.sequence&&(o=O(o)),o.keepSingleton=!0),!t.hasOwnProperty("group")){e.next=30;break}return e.delegateYield(ct(t.group,a?c:o,i),"t3",29);case 29:o=e.t3;case 30:return e.abrupt("return",o);case 31:case"end":return e.stop()}},e)}function Y(t,e){var n=It(t);for(var i in e)n.bind(i,e[i]);return n}function V(t,e,i,s){var o,a,c,l,h;return r().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if("sort"!==t.type){n.next=7;break}return n.delegateYield(mt(t,e,i),"t0",2);case 2:if(o=n.t0,!t.stages){n.next=6;break}return n.delegateYield(G(t.stages,o,i),"t1",5);case 5:o=n.t1;case 6:return n.abrupt("return",o);case 7:o=O(),a=0;case 9:if(!(a<e.length)){n.next=24;break}return n.delegateYield(N(t,e[a],i),"t2",11);case 11:if(c=n.t2,!t.stages){n.next=20;break}l=0;case 14:if(!(l<t.stages.length)){n.next=20;break}return n.delegateYield(W(t.stages[l].expr,c,i),"t3",16);case 16:c=n.t3;case 17:l++,n.next=14;break;case 20:void 0!==c&&o.push(c);case 21:a++,n.next=9;break;case 24:return h=O(),s&&1===o.length&&Array.isArray(o[0])&&!z(o[0])?h=o[0]:o.forEach(function(t){!Array.isArray(t)||t.cons?h.push(t):t.forEach(function(t){return h.push(t)})}),n.abrupt("return",h);case 27:case"end":return n.stop()}},n)}function G(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:i=e,s=0;case 2:if(!(s<t.length)){r.next=15;break}o=t[s],r.t0=o.type,r.next="filter"===r.t0?7:"index"===r.t0?10:12;break;case 7:return r.delegateYield(W(o.expr,i,n),"t1",8);case 8:return i=r.t1,r.abrupt("break",12);case 10:for(a=0;a<i.length;a++)i[a][o.value]=a;return r.abrupt("break",12);case 12:s++,r.next=2;break;case 15:return r.abrupt("return",i);case 16:case"end":return r.stop()}},h)}function U(t,e,n,i){var s,o,a,c,l,h,u,p;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if("sort"!==t.type){r.next=15;break}if(!n){r.next=6;break}return r.delegateYield(mt(t,n,i),"t0",3);case 3:s=r.t0,r.next=11;break;case 6:return r.delegateYield(mt(t,e,i),"t1",7);case 7:for(o=r.t1,(s=O()).tupleStream=!0,a=0;a<o.length;a++)(c={"@":o[a]})[t.index]=a,s.push(c);case 11:if(!t.stages){r.next=14;break}return r.delegateYield(G(t.stages,s,i),"t2",13);case 13:s=r.t2;case 14:return r.abrupt("return",s);case 15:(s=O()).tupleStream=!0,l=i,void 0===n&&(n=e.map(function(t){return{"@":t}})),h=0;case 20:if(!(h<n.length)){r.next=28;break}return l=Y(i,n[h]),r.delegateYield(N(t,n[h]["@"],l),"t3",23);case 23:if(void 0!==(u=r.t3))for(Array.isArray(u)||(u=[u]),p=0;p<u.length;p++)c={},Object.assign(c,n[h]),u.tupleStream?Object.assign(c,u[p]):(t.focus?(c[t.focus]=u[p],c["@"]=n[h]["@"]):c["@"]=u[p],t.index&&(c[t.index]=p),t.ancestor&&(c[t.ancestor.label]=n[h]["@"])),s.push(c);case 25:h++,r.next=20;break;case 28:if(!t.stages){r.next=31;break}return r.delegateYield(G(t.stages,s,i),"t4",30);case 30:s=r.t4;case 31:return r.abrupt("return",s);case 32:case"end":return r.stop()}},d)}function W(t,e,n){var i,s,a,c,l,h;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(i=O(),e&&e.tupleStream&&(i.tupleStream=!0),Array.isArray(e)||(e=O(e)),"number"!==t.type){r.next=10;break}(s=Math.floor(t.value))<0&&(s=e.length+s),void 0!==(a=e[s])&&(Array.isArray(a)?i=a:i.push(a)),r.next=23;break;case 10:s=0;case 11:if(!(s<e.length)){r.next=23;break}return a=e[s],c=a,l=n,e.tupleStream&&(c=a["@"],l=Y(n,a)),r.delegateYield(N(t,c,l),"t0",17);case 17:h=r.t0,T(h)&&(h=[h]),D(h)?h.forEach(function(t){var n=Math.floor(t);n<0&&(n=e.length+n),n===s&&i.push(a)}):o.boolean(h)&&i.push(a);case 20:s++,r.next=11;break;case 23:return r.abrupt("return",i);case 24:case"end":return r.stop()}},u)}function X(t,e,n){var i,s,o,a,c;return r().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:return l.delegateYield(N(t.lhs,e,n),"t0",1);case 1:if(s=l.t0,o=t.value,a=r().mark(function i(){return r().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.rhs,e,n),"t0",1);case 1:return i.abrupt("return",i.t0);case 2:case"end":return i.stop()}},i)}),"and"!==o&&"or"!==o){l.next=15;break}return l.prev=5,l.delegateYield(st(s,a,o),"t1",7);case 7:return l.abrupt("return",l.t1);case 10:throw l.prev=10,l.t2=l.catch(5),l.t2.position=t.position,l.t2.token=o,l.t2;case 15:return l.delegateYield(a(),"t3",16);case 16:c=l.t3,l.prev=17,l.t4=o,l.next="+"===l.t4||"-"===l.t4||"*"===l.t4||"/"===l.t4||"%"===l.t4?21:"="===l.t4||"!="===l.t4?23:"<"===l.t4||"<="===l.t4||">"===l.t4||">="===l.t4?25:"&"===l.t4?27:".."===l.t4?29:"in"===l.t4?31:33;break;case 21:return i=et(s,c,o),l.abrupt("break",33);case 23:return i=nt(s,c,o),l.abrupt("break",33);case 25:return i=it(s,c,o),l.abrupt("break",33);case 27:return i=at(s,c),l.abrupt("break",33);case 29:return i=ht(s,c),l.abrupt("break",33);case 31:return i=rt(s,c),l.abrupt("break",33);case 33:l.next=40;break;case 35:throw l.prev=35,l.t5=l.catch(17),l.t5.position=t.position,l.t5.token=o,l.t5;case 40:return l.abrupt("return",i);case 41:case"end":return l.stop()}},p,null,[[5,10],[17,35]])}function q(t,e,n){var i,s,a,c;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:r.t0=t.value,r.next="-"===r.t0?3:"["===r.t0?15:"{"===r.t0?27:30;break;case 3:return r.delegateYield(N(t.expression,e,n),"t1",4);case 4:if(void 0!==(i=r.t1)){r.next=9;break}i=void 0,r.next=14;break;case 9:if(!T(i)){r.next=13;break}i=-i,r.next=14;break;case 13:throw{code:"D1002",stack:(new Error).stack,position:t.position,token:t.value,value:i};case 14:return r.abrupt("break",30);case 15:i=[],s=0;case 17:if(!(s<t.expressions.length)){r.next=25;break}return a=t.expressions[s],r.delegateYield(N(a,e,n),"t2",20);case 20:void 0!==(c=r.t2)&&("["===a.value?i.push(c):i=o.append(i,c));case 22:s++,r.next=17;break;case 25:return t.consarray&&Object.defineProperty(i,"cons",{enumerable:!1,configurable:!1,value:!0}),r.abrupt("break",30);case 27:return r.delegateYield(ct(t,e,n),"t3",28);case 28:return i=r.t3,r.abrupt("break",30);case 30:return r.abrupt("return",i);case 31:case"end":return r.stop()}},f)}function K(t,e,n){return o.lookup(e,t.value)}function $(t){return t.value}function Q(t,e){var n=O();return Array.isArray(e)&&e.outerWrapper&&e.length>0&&(e=e[0]),null!==e&&"object"===i(e)&&Object.keys(e).forEach(function(t){var i=e[t];Array.isArray(i)?(i=Z(i),n=o.append(n,i)):n.push(i)}),n}function Z(t,e){return void 0===e&&(e=[]),Array.isArray(t)?t.forEach(function(t){Z(t,e)}):e.push(t),e}function J(t,e){var n,i=O();return void 0!==e&&(tt(e,i),n=1===i.length?i[0]:i),n}function tt(t,e){Array.isArray(t)||e.push(t),Array.isArray(t)?t.forEach(function(t){tt(t,e)}):null!==t&&"object"===i(t)&&Object.keys(t).forEach(function(n){tt(t[n],e)})}function et(t,e,n){var i;if(void 0!==t&&!T(t))throw{code:"T2001",stack:(new Error).stack,value:t};if(void 0!==e&&!T(e))throw{code:"T2002",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return i;switch(n){case"+":i=t+e;break;case"-":i=t-e;break;case"*":i=t*e;break;case"/":i=t/e;break;case"%":i=t%e}return i}function nt(t,e,n){var r,s=i(t),o=i(e);if("undefined"===s||"undefined"===o)return!1;switch(n){case"=":r=F(t,e);break;case"!=":r=!F(t,e)}return r}function it(t,e,n){var r,s=i(t),o=i(e);if("undefined"!==s&&"string"!==s&&"number"!==s||"undefined"!==o&&"string"!==o&&"number"!==o)throw{code:"T2010",stack:(new Error).stack,value:"string"!==s&&"number"!==s?t:e};if("undefined"!==s&&"undefined"!==o){if(s!==o)throw{code:"T2009",stack:(new Error).stack,value:t,value2:e};switch(n){case"<":r=t<e;break;case"<=":r=t<=e;break;case">":r=t>e;break;case">=":r=t>=e}return r}}function rt(t,e){var n=!1;if(void 0===t||void 0===e)return!1;Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)if(e[i]===t){n=!0;break}return n}function st(t,e,n){var i,s;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:s=ot(t),r.t0=n,r.next="and"===r.t0?4:"or"===r.t0?12:20;break;case 4:if(r.t1=s,!r.t1){r.next=10;break}return r.t2=ot,r.delegateYield(e(),"t3",8);case 8:r.t4=r.t3,r.t1=(0,r.t2)(r.t4);case 10:return i=r.t1,r.abrupt("break",20);case 12:if(r.t5=s,r.t5){r.next=18;break}return r.t6=ot,r.delegateYield(e(),"t7",16);case 16:r.t8=r.t7,r.t5=(0,r.t6)(r.t8);case 18:return i=r.t5,r.abrupt("break",20);case 20:return r.abrupt("return",i);case 21:case"end":return r.stop()}},g)}function ot(t){var e=o.boolean(t);return void 0!==e&&e}function at(t,e){var n="",i="";return void 0!==t&&(n=o.string(t)),void 0!==e&&(i=o.string(e)),n.concat(i)}function ct(t,e,n){var i,s,a,c,l,h,d,u,p,f,g,y,b;return r().wrap(function(m){for(;;)switch(m.prev=m.next){case 0:i={},s={},a=!(!e||!e.tupleStream),Array.isArray(e)||(e=O(e)),0===e.length&&e.push(void 0),c=0;case 6:if(!(c<e.length)){m.next=31;break}l=e[c],h=a?Y(n,l):n,d=0;case 10:if(!(d<t.lhs.length)){m.next=28;break}return u=t.lhs[d],m.delegateYield(N(u[0],a?l["@"]:l,h),"t0",13);case 13:if("string"==typeof(p=m.t0)||void 0===p){m.next=16;break}throw{code:"T1003",stack:(new Error).stack,position:t.position,value:p};case 16:if(void 0===p){m.next=25;break}if(f={data:l,exprIndex:d},!s.hasOwnProperty(p)){m.next=24;break}if(s[p].exprIndex===d){m.next=21;break}throw{code:"D1009",stack:(new Error).stack,position:t.position,value:p};case 21:s[p].data=o.append(s[p].data,l),m.next=25;break;case 24:s[p]=f;case 25:d++,m.next=10;break;case 28:c++,m.next=6;break;case 31:m.t1=r().keys(s);case 32:if((m.t2=m.t1()).done){m.next=43;break}return p=m.t2.value,f=s[p],g=f.data,h=n,a&&(y=lt(f.data),g=y["@"],delete y["@"],h=Y(n,y)),m.delegateYield(N(t.lhs[f.exprIndex][1],g,h),"t3",39);case 39:void 0!==(b=m.t3)&&(i[p]=b),m.next=32;break;case 43:return m.abrupt("return",i);case 44:case"end":return m.stop()}},m)}function lt(t){if(!Array.isArray(t))return t;var e={};Object.assign(e,t[0]);for(var n=1;n<t.length;n++)for(var i in t[n])e[i]=o.append(e[i],t[n][i]);return e}function ht(t,e){var n;if(void 0!==t&&!Number.isInteger(t))throw{code:"T2003",stack:(new Error).stack,value:t};if(void 0!==e&&!Number.isInteger(e))throw{code:"T2004",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return n;if(t>e)return n;var i=e-t+1;if(i>1e7)throw{code:"D2014",stack:(new Error).stack,value:i};n=new Array(i);for(var r=t,s=0;r<=e;r++,s++)n[s]=r;return n.sequence=!0,n}function dt(t,e,n){var i;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.rhs,e,n),"t0",1);case 1:return i=r.t0,n.bind(t.lhs.value,i),r.abrupt("return",i);case 4:case"end":return r.stop()}},y)}function ut(t,e,n){var i,s;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.condition,e,n),"t0",1);case 1:if(s=r.t0,!o.boolean(s)){r.next=7;break}return r.delegateYield(N(t.then,e,n),"t1",4);case 4:i=r.t1,r.next=10;break;case 7:if(void 0===t.else){r.next=10;break}return r.delegateYield(N(t.else,e,n),"t2",9);case 9:i=r.t2;case 10:return r.abrupt("return",i);case 11:case"end":return r.stop()}},b)}function pt(t,e,n){var i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:s=It(n),o=0;case 2:if(!(o<t.expressions.length)){r.next=8;break}return r.delegateYield(N(t.expressions[o],e,s),"t0",4);case 4:i=r.t0;case 5:o++,r.next=2;break;case 8:return r.abrupt("return",i);case 9:case"end":return r.stop()}},v)}function ft(t){var e=new Rt.RegexEngine(t.value),n=function n(i,r){var s;e.lastIndex=r||0;var o=e.exec(i);if(null!==o){if(s={match:o[0],start:o.index,end:o.index+o[0].length,groups:[]},o.length>1)for(var a=1;a<o.length;a++)s.groups.push(o[a]);s.next=function(){if(!(e.lastIndex>=i.length)){var r=n(i,e.lastIndex);if(r&&""===r.match)throw{code:"D1004",stack:(new Error).stack,position:t.position,value:t.value.source};return r}}}return s};return n}function gt(t,e,n){return""===t.value?e&&e.outerWrapper?e[0]:e:n.lookup(t.value)}function mt(t,e,n){var s,a,c,l,h;return r().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return a=e,c=!!e.tupleStream,l=r().mark(function e(s,o){var a,l,h,d,u,p,f,g,m;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:a=0,l=0;case 2:if(!(0===a&&l<t.terms.length)){e.next=35;break}return h=t.terms[l],d=s,u=n,c&&(d=s["@"],u=Y(n,s)),e.delegateYield(N(h.expression,d,u),"t0",8);case 8:return p=e.t0,d=o,u=n,c&&(d=o["@"],u=Y(n,o)),e.delegateYield(N(h.expression,d,u),"t1",13);case 13:if(f=e.t1,g=i(p),m=i(f),"undefined"!==g){e.next=19;break}return a="undefined"===m?0:1,e.abrupt("continue",32);case 19:if("undefined"!==m){e.next=22;break}return a=-1,e.abrupt("continue",32);case 22:if(!("string"!==g&&"number"!==g||"string"!==m&&"number"!==m)){e.next=24;break}throw{code:"T2008",stack:(new Error).stack,position:t.position,value:"string"!==g&&"number"!==g?p:f};case 24:if(g===m){e.next=26;break}throw{code:"T2007",stack:(new Error).stack,position:t.position,value:p,value2:f};case 26:if(p!==f){e.next=30;break}return e.abrupt("continue",32);case 30:a=p<f?-1:1;case 31:!0===h.descending&&(a=-a);case 32:l++,e.next=2;break;case 35:return e.abrupt("return",1===a);case 36:case"end":return e.stop()}},e)}),h={environment:n,input:e},d.delegateYield(o.sort.apply(h,[a,l]),"t0",5);case 5:return s=d.t0,d.abrupt("return",s);case 7:case"end":return d.stop()}},_)}function yt(t,e,n){var s=r().mark(function e(s){var o,a,c,l,h,d,u,p,f,g,m;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==s){e.next=2;break}return e.abrupt("return",void 0);case 2:if(o=n.lookup("clone"),I(o)){e.next=5;break}throw{code:"T2013",stack:(new Error).stack,position:t.position};case 5:return e.delegateYield(xt(o,[s],null,n),"t0",6);case 6:return a=e.t0,e.delegateYield(N(t.pattern,a,n),"t1",8);case 8:if(void 0===(c=e.t1)){e.next=35;break}Array.isArray(c)||(c=[c]),l=0;case 12:if(!(l<c.length)){e.next=35;break}if(!(h=c[l])||!(h.isPrototypeOf(a)||h instanceof Object.constructor)){e.next=16;break}throw{code:"D1010",stack:(new Error).stack,position:t.position};case 16:return e.delegateYield(N(t.update,h,n),"t2",17);case 17:if(d=e.t2,"undefined"===(u=i(d))){e.next=23;break}if("object"===u&&null!==d&&!Array.isArray(d)){e.next=22;break}throw{code:"T2011",stack:(new Error).stack,position:t.update.position,value:d};case 22:for(p in d)h[p]=d[p];case 23:if(void 0===t.delete){e.next=32;break}return e.delegateYield(N(t.delete,h,n),"t3",25);case 25:if(void 0===(f=e.t3)){e.next=32;break}if(g=f,Array.isArray(f)||(f=[f]),P(f)){e.next=31;break}throw{code:"T2012",stack:(new Error).stack,position:t.delete.position,value:g};case 31:for(m=0;m<f.length;m++)"object"===i(h)&&null!==h&&delete h[f[m]];case 32:l++,e.next=12;break;case 35:return e.abrupt("return",a);case 36:case"end":return e.stop()}},e)});return Dt(s,"<(oa):o>")}var bt=c("function($f, $g) { function($x){ $g($f($x)) } }");function vt(t,e,n){var i,s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.lhs,e,n),"t0",1);case 1:if(s=r.t0,"function"!==t.rhs.type){r.next=7;break}return r.delegateYield(_t(t.rhs,e,n,{context:s}),"t1",4);case 4:i=r.t1,r.next=20;break;case 7:return r.delegateYield(N(t.rhs,e,n),"t2",8);case 8:if(o=r.t2,I(o)){r.next=11;break}throw{code:"T2006",stack:(new Error).stack,position:t.position,value:o};case 11:if(!I(s)){r.next=18;break}return r.delegateYield(N(bt,null,n),"t3",13);case 13:return a=r.t3,r.delegateYield(xt(a,[s,o],null,n),"t4",15);case 15:i=r.t4,r.next=20;break;case 18:return r.delegateYield(xt(o,[s],null,n),"t5",19);case 19:i=r.t5;case 20:return r.abrupt("return",i);case 21:case"end":return r.stop()}},x)}function _t(t,e,n,s){var o,a,c,l,h,d;return r().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.delegateYield(N(t.procedure,e,n),"t0",1);case 1:if(void 0!==(a=u.t0)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){u.next=4;break}throw{code:"T1005",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 4:c=[],void 0!==s&&c.push(s.context),l=r().mark(function i(){var s,o;return r().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.arguments[h],e,n),"t0",1);case 1:s=i.t0,I(s)?(o=r().mark(function t(){var e,i,o,a=arguments;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(e=a.length,i=new Array(e),o=0;o<e;o++)i[o]=a[o];return t.delegateYield(xt(s,i,null,n),"t0",2);case 2:return t.abrupt("return",t.t0);case 3:case"end":return t.stop()}},t)}),o.arity=R(s),c.push(o)):c.push(s);case 3:case"end":return i.stop()}},i)}),h=0;case 8:if(!(h<t.arguments.length)){u.next=13;break}return u.delegateYield(l(),"t1",10);case 10:h++,u.next=8;break;case 13:return d="path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value,u.prev=14,"object"===i(a)&&(a.token=d,a.position=t.position),u.delegateYield(xt(a,c,e,n),"t2",17);case 17:o=u.t2,u.next=25;break;case 20:throw u.prev=20,u.t3=u.catch(14),u.t3.position||(u.t3.position=t.position),u.t3.token||(u.t3.token=d),u.t3;case 25:return u.abrupt("return",o);case 26:case"end":return u.stop()}},w,null,[[14,20]])}function xt(t,e,n,i){var s,o,a,c;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(wt(t,e,n,i),"t0",1);case 1:s=r.t0;case 2:if(!L(s)||!0!==s.thunk){r.next=21;break}return r.delegateYield(N(s.body.procedure,s.input,s.environment),"t1",4);case 4:o=r.t1,"variable"===s.body.procedure.type&&(o.token=s.body.procedure.value),o.position=s.body.procedure.position,a=[],c=0;case 9:if(!(c<s.body.arguments.length)){r.next=17;break}return r.t2=a,r.delegateYield(N(s.body.arguments[c],s.input,s.environment),"t3",12);case 12:r.t4=r.t3,r.t2.push.call(r.t2,r.t4);case 14:c++,r.next=9;break;case 17:return r.delegateYield(wt(o,a,n,i),"t5",18);case 18:s=r.t5,r.next=2;break;case 21:return r.abrupt("return",s);case 22:case"end":return r.stop()}},M)}function wt(t,e,n,i){var s,o,a;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(r.prev=0,o=e,t&&(o=kt(t.signature,e,n)),!L(t)){r.next=8;break}return r.delegateYield(At(t,o),"t0",5);case 5:s=r.t0,r.next=24;break;case 8:if(!t||!0!==t._jsonata_function){r.next=16;break}if(a={environment:i,input:n},s=t.implementation.apply(a,o),!j(s)){r.next=14;break}return r.delegateYield(s,"t1",13);case 13:s=r.t1;case 14:r.next=24;break;case 16:if("function"!=typeof t){r.next=23;break}if(s=t.apply(n,o),!j(s)){r.next=21;break}return r.delegateYield(s,"t2",20);case 20:s=r.t2;case 21:r.next=24;break;case 23:throw{code:"T1006",stack:(new Error).stack};case 24:r.next=30;break;case 26:throw r.prev=26,r.t3=r.catch(0),t&&(void 0===r.t3.token&&void 0!==t.token&&(r.t3.token=t.token),r.t3.position=t.position||r.t3.position),r.t3;case 30:return r.abrupt("return",s);case 31:case"end":return r.stop()}},S,null,[[0,26]])}function Mt(t,e,n){var i={_jsonata_lambda:!0,input:e,environment:n,arguments:t.arguments,signature:t.signature,body:t.body};return!0===t.thunk&&(i.thunk=!0),i.apply=r().mark(function t(n,s){return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(xt(i,s,e,n.environment),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},t)}),i}function St(t,e,n){var i,s,o,a,c;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:s=[],o=0;case 2:if(!(o<t.arguments.length)){r.next=15;break}if("operator"!==(a=t.arguments[o]).type||"?"!==a.value){r.next=8;break}s.push(a),r.next=12;break;case 8:return r.t0=s,r.delegateYield(N(a,e,n),"t1",10);case 10:r.t2=r.t1,r.t0.push.call(r.t0,r.t2);case 12:o++,r.next=2;break;case 15:return r.delegateYield(N(t.procedure,e,n),"t3",16);case 16:if(void 0!==(c=r.t3)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){r.next=19;break}throw{code:"T1007",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 19:if(!L(c)){r.next=23;break}i=Et(c,s),r.next=32;break;case 23:if(!c||!0!==c._jsonata_function){r.next=27;break}i=Ct(c.implementation,s),r.next=32;break;case 27:if("function"!=typeof c){r.next=31;break}i=Ct(c,s),r.next=32;break;case 31:throw{code:"T1008",stack:(new Error).stack,position:t.position,token:"path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value};case 32:return r.abrupt("return",i);case 33:case"end":return r.stop()}},k)}function kt(t,e,n){return void 0===t?e:t.validate(e,n)}function At(t,e){var n,i;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(i=It(t.environment),t.arguments.forEach(function(t,n){i.bind(t.value,e[n])}),"function"!=typeof t.body){r.next=7;break}return r.delegateYield(Tt(t.body,i),"t0",4);case 4:n=r.t0,r.next=9;break;case 7:return r.delegateYield(N(t.body,t.input,i),"t1",8);case 8:n=r.t1;case 9:return r.abrupt("return",n);case 10:case"end":return r.stop()}},A)}function Et(t,e){var n=It(t.environment),i=[];return t.arguments.forEach(function(t,r){var s=e[r];s&&"operator"===s.type&&"?"===s.value?i.push(t):n.bind(t.value,s)}),{_jsonata_lambda:!0,input:t.input,environment:n,arguments:i,body:t.body}}function Ct(t,e){var n=Pt(t),i="function("+(n=n.map(function(t){return"$"+t.trim()})).join(", ")+"){ _ }",r=c(i);return r.body=t,Et(r,e)}function Tt(t,e){var n,i,s,o;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(n=Pt(t),i=n.map(function(t){return e.lookup(t.trim())}),s={environment:e},o=t.apply(s,i),!j(o)){r.next=7;break}return r.delegateYield(o,"t0",6);case 6:o=r.t0;case 7:return r.abrupt("return",o);case 8:case"end":return r.stop()}},E)}function Pt(t){var e=t.toString();return/\(([^)]*)\)/.exec(e)[1].split(",")}function Dt(t,e){var n={_jsonata_function:!0,implementation:t};return void 0!==e&&(n.signature=l(e)),n}function Ot(t,e){var n,i,s;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==t){r.next=2;break}return r.abrupt("return",void 0);case 2:n=this.input,void 0!==e&&(n=e,Array.isArray(n)&&!z(n)&&((n=O(n)).outerWrapper=!0)),r.prev=4,i=c(t,!1),r.next=12;break;case 8:throw r.prev=8,r.t0=r.catch(4),jt(r.t0),{stack:(new Error).stack,code:"D3120",value:r.t0.message,error:r.t0};case 12:return r.prev=12,r.delegateYield(N(i,n,this.environment),"t1",14);case 14:s=r.t1,r.next=21;break;case 17:throw r.prev=17,r.t2=r.catch(12),jt(r.t2),{stack:(new Error).stack,code:"D3121",value:r.t2.message,error:r.t2};case 21:return r.abrupt("return",s);case 22:case"end":return r.stop()}},C,this,[[4,8],[12,17]])}function zt(t){if(void 0!==t)return JSON.parse(o.string(t))}function It(t){var e={};return{bind:function(t,n){e[t]=n},lookup:function(n){var i;return e.hasOwnProperty(n)?i=e[n]:t&&(i=t.lookup(n)),i},timestamp:t?t.timestamp:null,async:!!t&&t.async,global:t?t.global:{ancestry:[null]}}}B.bind("sum",Dt(o.sum,"<a<n>:n>")),B.bind("count",Dt(o.count,"<a:n>")),B.bind("max",Dt(o.max,"<a<n>:n>")),B.bind("min",Dt(o.min,"<a<n>:n>")),B.bind("average",Dt(o.average,"<a<n>:n>")),B.bind("string",Dt(o.string,"<x-b?:s>")),B.bind("substring",Dt(o.substring,"<s-nn?:s>")),B.bind("substringBefore",Dt(o.substringBefore,"<s-s:s>")),B.bind("substringAfter",Dt(o.substringAfter,"<s-s:s>")),B.bind("lowercase",Dt(o.lowercase,"<s-:s>")),B.bind("uppercase",Dt(o.uppercase,"<s-:s>")),B.bind("length",Dt(o.length,"<s-:n>")),B.bind("trim",Dt(o.trim,"<s-:s>")),B.bind("pad",Dt(o.pad,"<s-ns?:s>")),B.bind("match",Dt(o.match,"<s-f<s:o>n?:a<o>>")),B.bind("contains",Dt(o.contains,"<s-(sf):b>")),B.bind("replace",Dt(o.replace,"<s-(sf)(sf)n?:s>")),B.bind("split",Dt(o.split,"<s-(sf)n?:a<s>>")),B.bind("join",Dt(o.join,"<a<s>s?:s>")),B.bind("formatNumber",Dt(o.formatNumber,"<n-so?:s>")),B.bind("formatBase",Dt(o.formatBase,"<n-n?:s>")),B.bind("formatInteger",Dt(s.formatInteger,"<n-s:s>")),B.bind("parseInteger",Dt(s.parseInteger,"<s-s:n>")),B.bind("number",Dt(o.number,"<(nsb)-:n>")),B.bind("floor",Dt(o.floor,"<n-:n>")),B.bind("ceil",Dt(o.ceil,"<n-:n>")),B.bind("round",Dt(o.round,"<n-n?:n>")),B.bind("abs",Dt(o.abs,"<n-:n>")),B.bind("sqrt",Dt(o.sqrt,"<n-:n>")),B.bind("power",Dt(o.power,"<n-n:n>")),B.bind("random",Dt(o.random,"<:n>")),B.bind("boolean",Dt(o.boolean,"<x-:b>")),B.bind("not",Dt(o.not,"<x-:b>")),B.bind("map",Dt(o.map,"<af>")),B.bind("zip",Dt(o.zip,"<a+>")),B.bind("filter",Dt(o.filter,"<af>")),B.bind("single",Dt(o.single,"<af?>")),B.bind("reduce",Dt(o.foldLeft,"<afj?:j>")),B.bind("sift",Dt(o.sift,"<o-f?:o>")),B.bind("keys",Dt(o.keys,"<x-:a<s>>")),B.bind("lookup",Dt(o.lookup,"<x-s:x>")),B.bind("append",Dt(o.append,"<xx:a>")),B.bind("exists",Dt(o.exists,"<x:b>")),B.bind("spread",Dt(o.spread,"<x-:a<o>>")),B.bind("merge",Dt(o.merge,"<a<o>:o>")),B.bind("reverse",Dt(o.reverse,"<a:a>")),B.bind("each",Dt(o.each,"<o-f:a>")),B.bind("error",Dt(o.error,"<s?:x>")),B.bind("assert",Dt(o.assert,"<bs?:x>")),B.bind("type",Dt(o.type,"<x:s>")),B.bind("sort",Dt(o.sort,"<af?:a>")),B.bind("shuffle",Dt(o.shuffle,"<a:a>")),B.bind("distinct",Dt(o.distinct,"<x:x>")),B.bind("base64encode",Dt(o.base64encode,"<s-:s>")),B.bind("base64decode",Dt(o.base64decode,"<s-:s>")),B.bind("encodeUrlComponent",Dt(o.encodeUrlComponent,"<s-:s>")),B.bind("encodeUrl",Dt(o.encodeUrl,"<s-:s>")),B.bind("decodeUrlComponent",Dt(o.decodeUrlComponent,"<s-:s>")),B.bind("decodeUrl",Dt(o.decodeUrl,"<s-:s>")),B.bind("eval",Dt(Ot,"<sx?:x>")),B.bind("toMillis",Dt(s.toMillis,"<s-s?:n>")),B.bind("fromMillis",Dt(s.fromMillis,"<n-s?s?:s>")),B.bind("clone",Dt(zt,"<(oa)-:o>"));var Lt={S0101:"String literal must be terminated by a matching quote",S0102:"Number out of range: {{token}}",S0103:"Unsupported escape sequence: \\{{token}}",S0104:"The escape sequence \\u must be followed by 4 hex digits",S0105:"Quoted property name must be terminated with a backquote (`)",S0106:"Comment has no closing tag",S0201:"Syntax error: {{token}}",S0202:"Expected {{value}}, got {{token}}",S0203:"Expected {{value}} before end of expression",S0204:"Unknown operator: {{token}}",S0205:"Unexpected token: {{token}}",S0206:"Unknown expression type: {{token}}",S0207:"Unexpected end of expression",S0208:"Parameter {{value}} of function definition must be a variable name (start with $)",S0209:"A predicate cannot follow a grouping expression in a step",S0210:"Each step can only have one grouping expression",S0211:"The symbol {{token}} cannot be used as a unary operator",S0212:"The left side of := must be a variable name (start with $)",S0213:"The literal value {{value}} cannot be used as a step within a path expression",S0214:"The right side of {{token}} must be a variable name (start with $)",S0215:"A context variable binding must precede any predicates on a step",S0216:"A context variable binding must precede the 'order-by' clause on a step",S0217:"The object representing the 'parent' cannot be derived from this expression",S0301:"Empty regular expressions are not allowed",S0302:"No terminating / in regular expression",S0402:"Choice groups containing parameterized types are not supported",S0401:"Type parameters can only be applied to functions and arrays",S0500:"Attempted to evaluate an expression containing syntax error(s)",T0410:"Argument {{index}} of function {{token}} does not match function signature",T0411:"Context value is not a compatible type with argument {{index}} of function {{token}}",T0412:"Argument {{index}} of function {{token}} must be an array of {{type}}",D1001:"Number out of range: {{value}}",D1002:"Cannot negate a non-numeric value: {{value}}",T1003:"Key in object structure must evaluate to a string; got: {{value}}",D1004:"Regular expression matches zero length string",T1005:"Attempted to invoke a non-function. Did you mean ${{{token}}}?",T1006:"Attempted to invoke a non-function",T1007:"Attempted to partially apply a non-function. Did you mean ${{{token}}}?",T1008:"Attempted to partially apply a non-function",D1009:"Multiple key definitions evaluate to same key: {{value}}",D1010:"Attempted to access the Javascript object prototype",T1010:"The matcher function argument passed to function {{token}} does not return the correct object structure",T2001:"The left side of the {{token}} operator must evaluate to a number",T2002:"The right side of the {{token}} operator must evaluate to a number",T2003:"The left side of the range operator (..) must evaluate to an integer",T2004:"The right side of the range operator (..) must evaluate to an integer",D2005:"The left side of := must be a variable name (start with $)",T2006:"The right side of the function application operator ~> must be a function",T2007:"Type mismatch when comparing values {{value}} and {{value2}} in order-by clause",T2008:"The expressions within an order-by clause must evaluate to numeric or string values",T2009:"The values {{value}} and {{value2}} either side of operator {{token}} must be of the same data type",T2010:"The expressions either side of operator {{token}} must evaluate to numeric or string values",T2011:"The insert/update clause of the transform expression must evaluate to an object: {{value}}",T2012:"The delete clause of the transform expression must evaluate to a string or array of strings: {{value}}",T2013:"The transform expression clones the input object using the $clone() function. This has been overridden in the current scope by a non-function.",D2014:"The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate {{value}}.",D3001:"Attempting to invoke string function on Infinity or NaN",D3010:"Second argument of replace function cannot be an empty string",D3011:"Fourth argument of replace function must evaluate to a positive number",D3012:"Attempted to replace a matched string with a non-string value",D3020:"Third argument of split function must evaluate to a positive number",D3030:"Unable to cast value to a number: {{value}}",D3040:"Third argument of match function must evaluate to a positive number",D3050:"The second argument of reduce function must be a function with at least two arguments",D3060:"The sqrt function cannot be applied to a negative number: {{value}}",D3061:"The power function has resulted in a value that cannot be represented as a JSON number: base={{value}}, exponent={{exp}}",D3070:"The single argument form of the sort function can only be applied to an array of strings or an array of numbers. Use the second argument to specify a comparison function",D3080:"The picture string must only contain a maximum of two sub-pictures",D3081:"The sub-picture must not contain more than one instance of the 'decimal-separator' character",D3082:"The sub-picture must not contain more than one instance of the 'percent' character",D3083:"The sub-picture must not contain more than one instance of the 'per-mille' character",D3084:"The sub-picture must not contain both a 'percent' and a 'per-mille' character",D3085:"The mantissa part of a sub-picture must contain at least one character that is either an 'optional digit character' or a member of the 'decimal digit family'",D3086:"The sub-picture must not contain a passive character that is preceded by an active character and that is followed by another active character",D3087:"The sub-picture must not contain a 'grouping-separator' character that appears adjacent to a 'decimal-separator' character",D3088:"The sub-picture must not contain a 'grouping-separator' at the end of the integer part",D3089:"The sub-picture must not contain two adjacent instances of the 'grouping-separator' character",D3090:"The integer part of the sub-picture must not contain a member of the 'decimal digit family' that is followed by an instance of the 'optional digit character'",D3091:"The fractional part of the sub-picture must not contain an instance of the 'optional digit character' that is followed by a member of the 'decimal digit family'",D3092:"A sub-picture that contains a 'percent' or 'per-mille' character must not contain a character treated as an 'exponent-separator'",D3093:"The exponent part of the sub-picture must comprise only of one or more characters that are members of the 'decimal digit family'",D3100:"The radix of the formatBase function must be between 2 and 36. It was given {{value}}",D3110:"The argument of the toMillis function must be an ISO 8601 formatted timestamp. Given {{value}}",D3120:"Syntax error in expression passed to function eval: {{value}}",D3121:"Dynamic error evaluating the expression passed to function eval: {{value}}",D3130:"Formatting or parsing an integer as a sequence starting with {{value}} is not supported by this implementation",D3131:"In a decimal digit pattern, all digits must be from the same decimal group",D3132:"Unknown component specifier {{value}} in date/time picture string",D3133:"The 'name' modifier can only be applied to months and days in the date/time picture string, not {{value}}",D3134:"The timezone integer format specifier cannot have more than four digits",D3135:"No matching closing bracket ']' in date/time picture string",D3136:"The date/time picture string is missing specifiers required to parse the timestamp",D3137:"{{{message}}}",D3138:"The $single() function expected exactly 1 matching result. Instead it matched more.",D3139:"The $single() function expected exactly 1 matching result. Instead it matched 0.",D3140:"Malformed URL passed to ${{{functionName}}}(): {{value}}",D3141:"{{{message}}}"};function jt(t){var e=Lt[t.code];if(void 0!==e){var n=e.replace(/\{\{\{([^}]+)}}}/g,function(){return t[arguments[1]]});n=n.replace(/\{\{([^}]+)}}/g,function(){return JSON.stringify(t[arguments[1]])}),t.message=n}}function Rt(t,e){var n,i;try{n=c(t,e&&e.recover),i=n.errors,delete n.errors}catch(t){throw jt(t),t}var r=It(B),o=new Date;return r.bind("now",Dt(function(t,e){return s.fromMillis(o.getTime(),t,e)},"<s?s?:s>")),r.bind("millis",Dt(function(){return o.getTime()},"<:n>")),e&&e.RegexEngine?Rt.RegexEngine=e.RegexEngine:Rt.RegexEngine=RegExp,{evaluate:function(t,e,s){if(void 0!==i){var a={code:"S0500",position:0};throw jt(a),a}var c,l,h;if(void 0!==e)for(var d in c=It(r),e)c.bind(d,e[d]);else c=r;if(c.bind("$",t),o=new Date,c.timestamp=o,Array.isArray(t)&&!z(t)&&((t=O(t)).outerWrapper=!0),"function"==typeof s){c.async=!0;var u=function(t){jt(t),s(t,null)},p=function t(e){(l=h.next(e)).done?s(null,l.value):l.value.then(t).catch(u)};h=N(n,t,c),(l=h.next()).value.then(p).catch(u)}else try{for(h=N(n,t,c),l=h.next();!l.done;)l=h.next(l.value);return l.value}catch(a){throw jt(a),a}},assign:function(t,e){r.bind(t,e)},registerFunction:function(t,e,n){var i=Dt(e,n);r.bind(t,i)},ast:function(){return n},errors:function(){return i}}}return Rt.parser=c,Rt}();e.exports=h},{"./datetime":1,"./functions":2,"./parser":4,"./signature":5,"./utils":6}],4:[function(t,e,n){var i=t("./signature"),r=function(){var t={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":80,"#":80,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"^":40,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},e={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},n=function(n){var i=0,r=n.length,s=function(t,e){return{type:t,value:e,position:i}},o=function(){for(var t,e,s=i,o=0;i<r;){var a=n.charAt(i);if("/"===a&&"\\"!==n.charAt(i-1)&&0===o){if(""===(t=n.substring(s,i)))throw{code:"S0301",stack:(new Error).stack,position:i};for(i++,a=n.charAt(i),s=i;"i"===a||"m"===a;)i++,a=n.charAt(i);return e=n.substring(s,i)+"g",new RegExp(t,e)}"("!==a&&"["!==a&&"{"!==a||"\\"===n.charAt(i-1)||o++,")"!==a&&"]"!==a&&"}"!==a||"\\"===n.charAt(i-1)||o--,i++}throw{code:"S0302",stack:(new Error).stack,position:i}},a=function a(c){if(i>=r)return null;for(var l=n.charAt(i);i<r&&" \t\n\r\v".indexOf(l)>-1;)i++,l=n.charAt(i);if("/"===l&&"*"===n.charAt(i+1)){var h=i;for(i+=2,l=n.charAt(i);"*"!==l||"/"!==n.charAt(i+1);)if(l=n.charAt(++i),i>=r)throw{code:"S0106",stack:(new Error).stack,position:h};return i+=2,l=n.charAt(i),a(c)}if(!0!==c&&"/"===l)return i++,s("regex",o());if("."===l&&"."===n.charAt(i+1))return i+=2,s("operator","..");if(":"===l&&"="===n.charAt(i+1))return i+=2,s("operator",":=");if("!"===l&&"="===n.charAt(i+1))return i+=2,s("operator","!=");if(">"===l&&"="===n.charAt(i+1))return i+=2,s("operator",">=");if("<"===l&&"="===n.charAt(i+1))return i+=2,s("operator","<=");if("*"===l&&"*"===n.charAt(i+1))return i+=2,s("operator","**");if("~"===l&&">"===n.charAt(i+1))return i+=2,s("operator","~>");if(Object.prototype.hasOwnProperty.call(t,l))return i++,s("operator",l);if('"'===l||"'"===l){var d=l;i++;for(var u="";i<r;){if("\\"===(l=n.charAt(i)))if(i++,l=n.charAt(i),Object.prototype.hasOwnProperty.call(e,l))u+=e[l];else{if("u"!==l)throw{code:"S0103",stack:(new Error).stack,position:i,token:l};var p=n.substr(i+1,4);if(!/^[0-9a-fA-F]+$/.test(p))throw{code:"S0104",stack:(new Error).stack,position:i};var f=parseInt(p,16);u+=String.fromCharCode(f),i+=4}else{if(l===d)return i++,s("string",u);u+=l}i++}throw{code:"S0101",stack:(new Error).stack,position:i}}var g,m=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/.exec(n.substring(i));if(null!==m){var y=parseFloat(m[0]);if(!isNaN(y)&&isFinite(y))return i+=m[0].length,s("number",y);throw{code:"S0102",stack:(new Error).stack,position:i,token:m[0]}}if("`"===l){i++;var b=n.indexOf("`",i);if(-1!==b)return g=n.substring(i,b),i=b+1,s("name",g);throw i=r,{code:"S0105",stack:(new Error).stack,position:i}}for(var v,_=i;;)if(v=n.charAt(_),_===r||" \t\n\r\v".indexOf(v)>-1||Object.prototype.hasOwnProperty.call(t,v)){if("$"===n.charAt(i))return g=n.substring(i+1,_),i=_,s("variable",g);switch(g=n.substring(i,_),i=_,g){case"or":case"in":case"and":return s("operator",g);case"true":return s("value",!0);case"false":return s("value",!1);case"null":return s("value",null);default:return i===r&&""===g?null:s("name",g)}}else _++};return a},r=function(e,r){var s,o,a={},c=[],l=function(){var t=[];"(end)"!==s.id&&t.push({type:s.type,value:s.value,position:s.position});for(var e=o();null!==e;)t.push(e),e=o();return t},h={nud:function(){var t={code:"S0211",token:this.value,position:this.position};if(r)return t.remaining=l(),t.type="error",c.push(t),t;throw t.stack=(new Error).stack,t}},d=function(t,e){var n=a[t];return e=e||0,n?e>=n.lbp&&(n.lbp=e):((n=Object.create(h)).id=n.value=t,n.lbp=e,a[t]=n),n},u=function(t){if(r){t.remaining=l(),c.push(t);var e=a["(error)"];return(s=Object.create(e)).error=t,s.type="(error)",s}throw t.stack=(new Error).stack,t},p=function(t,n){if(t&&s.id!==t){var i={code:"(end)"===s.id?"S0203":"S0202",position:s.position,token:s.value,value:t};return u(i)}var r=o(n);if(null===r)return(s=a["(end)"]).position=e.length,s;var c,l=r.value,h=r.type;switch(h){case"name":case"variable":c=a["(name)"];break;case"operator":if(!(c=a[l]))return u({code:"S0204",stack:(new Error).stack,position:r.position,token:l});break;case"string":case"number":case"value":c=a["(literal)"];break;case"regex":h="regex",c=a["(regex)"];break;default:return u({code:"S0205",stack:(new Error).stack,position:r.position,token:l})}return(s=Object.create(c)).value=l,s.type=h,s.position=r.position,s},f=function(t){var e,n=s;for(p(null,!0),e=n.nud();t<s.lbp;)n=s,p(),e=n.led(e);return e},g=function(t){d(t,0).nud=function(){return this}},m=function(e,n,i){var r=n||t[e],s=d(e,r);return s.led=i||function(t){return this.lhs=t,this.rhs=f(r),this.type="binary",this},s},y=function(t,e,n){var i=d(t,e);return i.led=n,i},b=function(t,e){var n=d(t);return n.nud=e||function(){return this.expression=f(70),this.type="unary",this},n};g("(end)"),g("(name)"),g("(literal)"),g("(regex)"),d(":"),d(";"),d(","),d(")"),d("]"),d("}"),d(".."),m("."),m("+"),m("-"),m("*"),m("/"),m("%"),m("="),m("<"),m(">"),m("!="),m("<="),m(">="),m("&"),m("and"),m("or"),m("in"),g("and"),g("or"),g("in"),b("-"),m("~>"),y("(error)",10,function(t){return this.lhs=t,this.error=s.error,this.remaining=l(),this.type="error",this}),b("*",function(){return this.type="wildcard",this}),b("**",function(){return this.type="descendant",this}),b("%",function(){return this.type="parent",this}),m("(",t["("],function(t){if(this.procedure=t,this.type="function",this.arguments=[],")"!==s.id)for(;"operator"===s.type&&"?"===s.id?(this.type="partial",this.arguments.push(s),p("?")):this.arguments.push(f(0)),","===s.id;)p(",");if(p(")",!0),"name"===t.type&&("function"===t.value||"λ"===t.value)){if(this.arguments.forEach(function(t,e){if("variable"!==t.type)return u({code:"S0208",stack:(new Error).stack,position:t.position,token:t.value,value:e+1})}),this.type="lambda","<"===s.id){for(var e=s.position,n=1,r="<";n>0&&"{"!==s.id&&"(end)"!==s.id;){var o=p();">"===o.id?n--:"<"===o.id&&n++,r+=o.value}p(">");try{this.signature=i(r)}catch(t){return t.position=e+t.offset,u(t)}}p("{"),this.body=f(0),p("}")}return this}),b("(",function(){for(var t=[];")"!==s.id&&(t.push(f(0)),";"===s.id);)p(";");return p(")",!0),this.type="block",this.expressions=t,this}),b("[",function(){var t=[];if("]"!==s.id)for(;;){var e=f(0);if(".."===s.id){var n={type:"binary",value:"..",position:s.position,lhs:e};p(".."),n.rhs=f(0),e=n}if(t.push(e),","!==s.id)break;p(",")}return p("]",!0),this.expressions=t,this.type="unary",this}),m("[",t["["],function(e){if("]"===s.id){for(var n=e;n&&"binary"===n.type&&"["===n.value;)n=n.lhs;return n.keepArray=!0,p("]"),e}return this.lhs=e,this.rhs=f(t["]"]),this.type="binary",p("]",!0),this}),m("^",t["^"],function(t){p("(");for(var e=[];;){var n={descending:!1};if("<"===s.id?p("<"):">"===s.id&&(n.descending=!0,p(">")),n.expression=f(0),e.push(n),","!==s.id)break;p(",")}return p(")"),this.lhs=t,this.rhs=e,this.type="binary",this});var v=function(t){var e=[];if("}"!==s.id)for(;;){var n=f(0);p(":");var i=f(0);if(e.push([n,i]),","!==s.id)break;p(",")}return p("}",!0),void 0===t?(this.lhs=e,this.type="unary"):(this.lhs=t,this.rhs=e,this.type="binary"),this};b("{",v),m("{",t["{"],v),y(":=",t[":="],function(e){return"variable"!==e.type?u({code:"S0212",stack:(new Error).stack,position:e.position,token:e.value}):(this.lhs=e,this.rhs=f(t[":="]-1),this.type="binary",this)}),m("@",t["@"],function(e){return this.lhs=e,this.rhs=f(t["@"]),"variable"!==this.rhs.type?u({code:"S0214",stack:(new Error).stack,position:this.rhs.position,token:"@"}):(this.type="binary",this)}),m("#",t["#"],function(e){return this.lhs=e,this.rhs=f(t["#"]),"variable"!==this.rhs.type?u({code:"S0214",stack:(new Error).stack,position:this.rhs.position,token:"#"}):(this.type="binary",this)}),m("?",t["?"],function(t){return this.type="condition",this.condition=t,this.then=f(0),":"===s.id&&(p(":"),this.else=f(0)),this}),b("|",function(){return this.type="transform",this.pattern=f(0),p("|"),this.update=f(0),","===s.id&&(p(","),this.delete=f(0)),p("|"),this});var _=function t(e){var n;if("function"!==e.type||e.predicate)if("condition"===e.type)e.then=t(e.then),void 0!==e.else&&(e.else=t(e.else)),n=e;else if("block"===e.type){var i=e.expressions.length;i>0&&(e.expressions[i-1]=t(e.expressions[i-1])),n=e}else n=e;else{var r={type:"lambda",thunk:!0,arguments:[],position:e.position};r.body=e,n=r}return n},x=0,w=0,M=[],S=function t(e,n){switch(e.type){case"name":case"wildcard":n.level--,0===n.level&&(void 0===e.ancestor||(M[n.index].slot.label=e.ancestor.label),e.ancestor=n,e.tuple=!0);break;case"parent":n.level++;break;case"block":e.expressions.length>0&&(e.tuple=!0,n=t(e.expressions[e.expressions.length-1],n));break;case"path":e.tuple=!0;var i=e.steps.length-1;for(n=t(e.steps[i--],n);n.level>0&&i>=0;)n=t(e.steps[i--],n);break;default:throw{code:"S0217",token:e.type,position:e.position}}return n},k=function(t,e){if(void 0!==e.seekingParent||"parent"===e.type){var n=void 0!==e.seekingParent?e.seekingParent:[];"parent"===e.type&&n.push(e.slot),void 0===t.seekingParent?t.seekingParent=n:Array.prototype.push.apply(t.seekingParent,n)}},A=function(t){var e=t.steps.length-1,n=t.steps[e],i=void 0!==n.seekingParent?n.seekingParent:[];"parent"===n.type&&i.push(n.slot);for(var r=0;r<i.length;r++){var s=i[r];for(e=t.steps.length-2;s.level>0;){if(e<0){void 0===t.seekingParent?t.seekingParent=[s]:t.seekingParent.push(s);break}for(var o=t.steps[e--];e>=0&&o.focus&&t.steps[e].focus;)o=t.steps[e--];s=S(o,s)}}},E=function t(e){var n;switch(e.type){case"binary":switch(e.value){case".":var i=t(e.lhs);n="path"===i.type?i:{type:"path",steps:[i]},"parent"===i.type&&(n.seekingParent=[i.slot]);var s=t(e.rhs);"function"===s.type&&"path"===s.procedure.type&&1===s.procedure.steps.length&&"name"===s.procedure.steps[0].type&&"function"===n.steps[n.steps.length-1].type&&(n.steps[n.steps.length-1].nextFunction=s.procedure.steps[0].value),"path"===s.type?Array.prototype.push.apply(n.steps,s.steps):(void 0!==s.predicate&&(s.stages=s.predicate,delete s.predicate),n.steps.push(s)),n.steps.filter(function(t){if("number"===t.type||"value"===t.type)throw{code:"S0213",stack:(new Error).stack,position:t.position,value:t.value};return"string"===t.type}).forEach(function(t){t.type="name"}),n.steps.filter(function(t){return!0===t.keepArray}).length>0&&(n.keepSingletonArray=!0);var o=n.steps[0];"unary"===o.type&&"["===o.value&&(o.consarray=!0);var a=n.steps[n.steps.length-1];"unary"===a.type&&"["===a.value&&(a.consarray=!0),A(n);break;case"[":var l=n=t(e.lhs),h="predicate";if("path"===n.type&&(l=n.steps[n.steps.length-1],h="stages"),void 0!==l.group)throw{code:"S0209",stack:(new Error).stack,position:e.position};void 0===l[h]&&(l[h]=[]);var d=t(e.rhs);void 0!==d.seekingParent&&(d.seekingParent.forEach(function(t){1===t.level?S(l,t):t.level--}),k(l,d)),l[h].push({type:"filter",expr:d,position:e.position});break;case"{":if(void 0!==(n=t(e.lhs)).group)throw{code:"S0210",stack:(new Error).stack,position:e.position};n.group={lhs:e.rhs.map(function(e){return[t(e[0]),t(e[1])]}),position:e.position};break;case"^":"path"!==(n=t(e.lhs)).type&&(n={type:"path",steps:[n]});var u={type:"sort",position:e.position};u.terms=e.rhs.map(function(e){var n=t(e.expression);return k(u,n),{descending:e.descending,expression:n}}),n.steps.push(u),A(n);break;case":=":(n={type:"bind",value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs),k(n,n.rhs);break;case"@":if(n=t(e.lhs),l=n,"path"===n.type&&(l=n.steps[n.steps.length-1]),void 0!==l.stages||void 0!==l.predicate)throw{code:"S0215",stack:(new Error).stack,position:e.position};if("sort"===l.type)throw{code:"S0216",stack:(new Error).stack,position:e.position};e.keepArray&&(l.keepArray=!0),l.focus=e.rhs.value,l.tuple=!0;break;case"#":n=t(e.lhs),l=n,"path"===n.type?l=n.steps[n.steps.length-1]:(n={type:"path",steps:[n]},void 0!==l.predicate&&(l.stages=l.predicate,delete l.predicate)),void 0===l.stages?l.index=e.rhs.value:l.stages.push({type:"index",value:e.rhs.value,position:e.position}),l.tuple=!0;break;case"~>":(n={type:"apply",value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs);break;default:(n={type:e.type,value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs),k(n,n.lhs),k(n,n.rhs)}break;case"unary":n={type:e.type,value:e.value,position:e.position},"["===e.value?n.expressions=e.expressions.map(function(e){var i=t(e);return k(n,i),i}):"{"===e.value?n.lhs=e.lhs.map(function(e){var i=t(e[0]);k(n,i);var r=t(e[1]);return k(n,r),[i,r]}):(n.expression=t(e.expression),"-"===e.value&&"number"===n.expression.type?(n=n.expression).value=-n.value:k(n,n.expression));break;case"function":case"partial":(n={type:e.type,name:e.name,value:e.value,position:e.position}).arguments=e.arguments.map(function(e){var i=t(e);return k(n,i),i}),n.procedure=t(e.procedure);break;case"lambda":n={type:e.type,arguments:e.arguments,signature:e.signature,position:e.position};var p=t(e.body);n.body=_(p);break;case"condition":(n={type:e.type,position:e.position}).condition=t(e.condition),k(n,n.condition),n.then=t(e.then),k(n,n.then),void 0!==e.else&&(n.else=t(e.else),k(n,n.else));break;case"transform":(n={type:e.type,position:e.position}).pattern=t(e.pattern),n.update=t(e.update),void 0!==e.delete&&(n.delete=t(e.delete));break;case"block":(n={type:e.type,position:e.position}).expressions=e.expressions.map(function(e){var i=t(e);return k(n,i),(i.consarray||"path"===i.type&&i.steps[0].consarray)&&(n.consarray=!0),i});break;case"name":n={type:"path",steps:[e]},e.keepArray&&(n.keepSingletonArray=!0);break;case"parent":n={type:"parent",slot:{label:"!"+x++,level:1,index:w++}},M.push(n);break;case"string":case"number":case"value":case"wildcard":case"descendant":case"variable":case"regex":n=e;break;case"operator":if("and"===e.value||"or"===e.value||"in"===e.value)e.type="name",n=t(e);else{if("?"!==e.value)throw{code:"S0201",stack:(new Error).stack,position:e.position,token:e.value};n=e}break;case"error":n=e,e.lhs&&(n=t(e.lhs));break;default:var f="S0206";"(end)"===e.id&&(f="S0207");var g={code:f,position:e.position,token:e.value};if(r)return c.push(g),{type:"error",error:g};throw g.stack=(new Error).stack,g}return e.keepArray&&(n.keepArray=!0),n};o=n(e),p();var C=f(0);if("(end)"!==s.id){var T={code:"S0201",position:s.position,token:s.value};u(T)}if("parent"===(C=E(C)).type||void 0!==C.seekingParent)throw{code:"S0217",token:C.type,position:C.position};return c.length>0&&(C.errors=c),C};return r}();e.exports=r},{"./signature":5}],5:[function(t,e,n){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}var r=t("./utils"),s=function(){var t={a:"arrays",b:"booleans",f:"functions",n:"numbers",o:"objects",s:"strings"};function e(e){for(var n=1,s=[],o={},a=o;n<e.length;){var c=e.charAt(n);if(":"===c)break;var l=function(){s.push(o),a=o,o={}},h=function(t,e,n,i){for(var r=1,s=e;s<t.length;)if(s++,(c=t.charAt(s))===i){if(0===--r)break}else c===n&&r++;return s};switch(c){case"s":case"n":case"b":case"l":case"o":o.regex="["+c+"m]",o.type=c,l();break;case"a":o.regex="[asnblfom]",o.type=c,o.array=!0,l();break;case"f":o.regex="f",o.type=c,l();break;case"j":o.regex="[asnblom]",o.type=c,l();break;case"x":o.regex="[asnblfom]",o.type=c,l();break;case"-":a.context=!0,a.contextRegex=new RegExp(a.regex),a.regex+="?";break;case"?":case"+":a.regex+=c;break;case"(":var d=h(e,n,"(",")"),u=e.substring(n+1,d);if(-1!==u.indexOf("<"))throw{code:"S0402",stack:(new Error).stack,value:u,offset:n};o.regex="["+u+"m]",o.type="("+u+")",n=d,l();break;case"<":if("a"!==a.type&&"f"!==a.type)throw{code:"S0401",stack:(new Error).stack,value:a.type,offset:n};var p=h(e,n,"<",">");a.subtype=e.substring(n+1,p),n=p}n++}var f="^"+s.map(function(t){return"("+t.regex+")"}).join("")+"$",g=new RegExp(f),m=function(t){var e;if(r.isFunction(t))e="f";else switch(i(t)){case"string":e="s";break;case"number":e="n";break;case"boolean":e="b";break;case"object":e=null===t?"l":Array.isArray(t)?"a":"o";break;default:e="m"}return e},y=function(t,e){for(var n="^",i=0,r=0;r<s.length;r++){n+=s[r].regex;var o=e.match(n);if(null===o)throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1};i=o[0].length}throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1}};return{definition:e,validate:function(e,n){var i="";e.forEach(function(t){i+=m(t)});var r=g.exec(i);if(r){var o=[],a=0;return s.forEach(function(i,s){var c=e[a],l=r[s+1];if(""===l)if(i.context&&i.contextRegex){var h=m(n);if(!i.contextRegex.test(h))throw{code:"T0411",stack:(new Error).stack,value:n,index:a+1};o.push(n)}else o.push(c),a++;else l.split("").forEach(function(n){if("a"===i.type){if("m"===n)c=void 0;else{c=e[a];var r=!0;if(void 0!==i.subtype)if("a"!==n&&l!==i.subtype)r=!1;else if("a"===n&&c.length>0){var s=m(c[0]);r=s===i.subtype.charAt(0)&&0===c.filter(function(t){return m(t)!==s}).length}if(!r)throw{code:"T0412",stack:(new Error).stack,value:c,index:a+1,type:t[i.subtype]};"a"!==n&&(c=[c])}o.push(c),a++}else o.push(c),a++})}),o}y(e,i)}}}return e}();e.exports=s},{"./utils":6}],6:[function(t,e,n){function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=r(t))||e){n&&(t=n);var i=0,s=function(){};return{s:s,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw o}}}}function r(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}var a=function(){function t(t){var e=!1;if("number"==typeof t&&(e=!isNaN(t))&&!isFinite(t))throw{code:"D1001",value:t,stack:(new Error).stack};return e}function e(t){var e=!1;return Array.isArray(t)&&(e=0===t.filter(function(t){return"string"!=typeof t}).length),e}function n(e){var n=!1;return Array.isArray(e)&&(n=0===e.filter(function(e){return!t(e)}).length),n}function r(){var t=[];return t.sequence=!0,1===arguments.length&&t.push(arguments[0]),t}function s(t){return!0===t.sequence&&Array.isArray(t)}function a(t){return t&&(!0===t._jsonata_function||!0===t._jsonata_lambda)||"function"==typeof t}function c(t){return"number"==typeof t.arity?t.arity:"function"==typeof t.implementation?t.implementation.length:"number"==typeof t.length?t.length:t.arguments.length}function l(t){return t&&!0===t._jsonata_lambda}var h=("function"==typeof Symbol?Symbol:{}).iterator||"@@iterator";function d(t){return"object"===o(t)&&null!==t&&h in t&&"next"in t&&"function"==typeof t.next}function u(t,e){if(t===e)return!0;if("object"===o(t)&&"object"===o(e)&&null!==t&&null!==e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!u(t[n],e[n]))return!1;return!0}var i=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(i.length!==r.length)return!1;for(i=i.sort(),r=r.sort(),n=0;n<i.length;n++)if(i[n]!==r[n])return!1;for(n=0;n<i.length;n++){var s=i[n];if(!u(t[s],e[s]))return!1}return!0}return!1}function p(t){var e,n=[],r=i(t);try{for(r.s();!(e=r.n()).done;){var s=e.value;n.push(s)}}catch(t){r.e(t)}finally{r.f()}return n}return{isNumeric:t,isArrayOfStrings:e,isArrayOfNumbers:n,createSequence:r,isSequence:s,isFunction:a,isLambda:l,isIterable:d,getFunctionArity:c,isDeepEqual:u,stringToArray:p}}();e.exports=a},{}]},{},[3])(3)}(ir)),ir.exports),sr=tr(rr);const or=function(t){return t};function ar(t){if(!t)return or;try{const e=sr(function(t){return t.replace(/(?<=^|\.|\[)([a-zA-Z_][\w]*-[\w-]*)(?=\.|$|\[|])/g,"`$1`")}(t));return function(t){return e.evaluate(t)}}catch(t){return Ki(t),or}}function cr(t){const e=vi(t);return null==e?"":String(e)}function lr(t){return Number(vi(t))}function hr(t){return t}function dr(t){return cr(t)}function ur(t){return lr(t)}function pr(t){if(this.param)return t=cr(t),this.param.hasOwnProperty(t)?this.param[t]:this.param.default}function fr(t){const{param:e}=this;if(e){for(const n in e){let[i,r]=n.split("~");const s=!!i,o=!!r,a=parseFloat(i),c=parseFloat(r);if(t=lr(t),s&&!o&&t>=a)return e[n];if(!s&&o&&t<a)return e[n];if(t>=a&&t<c)return e[n]}return e.default}}function gr(t){return lr(t)*Math.PI/180}function mr(){}const yr=[/\bimport\b/,/\brequire\b/,/\b__proto__\b/,/\bconstructor\s*\[/,/\bprototype\b/];const br=["globalThis","self","top","parent","frames","fetch","XMLHttpRequest","eval","Function","require","importScripts","process"],vr=new Array(br.length).fill(void 0);function _r(t){try{!function(t){for(const e of yr)if(e.test(t))throw new Error(`Blocked pattern detected: ${e}`)}(t);const e=new Function("value","targets","scene",...br,t);return function(t,n){try{return e.call(this,t,n,globalThis.scene,...vr)}catch(t){return void Ki(t)}}}catch(t){return Ki(t),mr}}function xr(t,e,n,i,r){switch(n){case"value":return"text"===r||"string"===r?dr.bind(t):"number"===r?ur.bind(t):hr.bind(e);case"map":return pr.bind(t);case"range":return fr.bind(t);case"radian":return gr.bind(t);case"eval":return _r(i).bind(e);default:return hr.bind(e)}}class wr{constructor(t,e){this.owner=e,this.model=t}dispose(){this._model=null,this.owner=null,this.evaluator=null,this.accessor=null}get model(){return this._model}set model(t){const{target:e,property:n,rule:i,param:r,accessor:s}=t;this._model=t,this.evaluator=xr(this,this.owner,i,r,function(t){switch(t){case"ref":case"fillStyle":case"strokeStyle":return"string";default:return}}(n)),this.accessor=ar(s);const o=e.match(/\[(.*?)\]/);if(o){const[t,e]=o[1].split(":");this.propAccessor=ar(t),this.partAccessor=ar(e)}}get target(){return this.model.target}get property(){return this.model.property}get source(){return this.model.source}get param(){return this.model.param}get ndnsp(){return!!this.model.ndnsp}get partial(){return!!this.model.partial}}function Mr(t,e,n,i){const r=e.split(".");if(1===r.length)return void(t[e]=i?{...t[e],...n}:n);const s=r[0],o=void 0!==t[s]?t[s]:"function"==typeof t.get?t.get(s):void 0,a=o?{...o}:{};let c=a;for(let t=1;t<r.length-1;t++)c[r[t]]=c[r[t]]?{...c[r[t]]}:{},c=c[r[t]];const l=r[r.length-1];c[l]=i?{...c[l],...n}:n,t[s]=a}function Sr(t,e,n,i){t.forEach(t=>Mr(t,e,n,i))}function kr(t=!1){(t||void 0!==this.data)&&this.mappings&&this.mappings.forEach(t=>{try{let e,{source:n,target:i,property:r,accessor:s,propAccessor:o,partAccessor:a,ndnsp:c=!1,partial:l=!1}=t;i=(i||"(self)").trim(),t.rule||(t.rule="value"),n&&"(self)"!=n?(n.startsWith("#")&&(n=n.substring(1)),e=this.root.findById(n)?.data||{}):e=this.data;const h=s(e);if("(root)"==i||"(key)"==i){if(null==h)return;const e=Object.keys(h||{}).map(t=>this.root.findOrCreate(t)).filter(Boolean).flat();e.length>0&&e.forEach(e=>{const n=t.evaluator(h[e.get("id")],[e]);!r||"(action)"===r||c&&!n&&0!==n&&!1!==n||Mr(e,r,n,l)})}else if(i.startsWith("[")){if(null==h)return;if(h instanceof Array)h.forEach(e=>{const n=o(e);if(n){const i=this.root.findOrCreate(n);if(i){const n=t.evaluator(a(e),i);!r||"(action)"===r||c&&!n&&0!==n&&!1!==n||Sr(i,r,n,l)}}});else{if(!(h instanceof Object))throw String("mapping data should be an object to target property-id.("+h+")");{const e=o(h);if(e){const n=this.root.findOrCreate(e);if(n){const e=t.evaluator(a(h),n);!r||"(action)"===r||c&&!e&&0!==e&&!1!==e||Sr(n,r,e,l)}}}}}else{const e=this.root.findAll(i,this);if(e.length>0){const n=t.evaluator(h,e);!r||"(action)"===r||c&&!n&&0!==n&&!1!==n||Sr(e,r,n,l)}}}catch(e){Ki(e,this,t)}})}function Ar(t,e){this.state.persistent&&this.app?.isViewMode&&this.app?.dataStorage.save(this,t.data),this.app?.lagTracker?.recordIfMonitored(this.state.tag,t.data),kr.call(this,!0)}function Er(){if(this._model.mappings)return this._model.mappings instanceof Array?void(this._mappings=(this._model.mappings||[]).filter(t=>t.property).map(t=>new wr({target:"(self)",rule:"value",...t},this))):(Ki("Mappings model is invalid (should be a Array) ..",this._model.mappings),void(this._mappings=[]));this._mappings=[]}function Cr(){this._mappings&&this._mappings.forEach(t=>t.dispose()),delete this._mappings}function Tr(t,e){this.disposeMappings(),kr.call(this)}function Pr(t,e,n,i,r,s){e.complete?t.drawImage(e,n,i,r,s):e.addEventListener("load",()=>{this.invalidate()})}function Dr(t){const{effects:e}=this.state;(e||[]).forEach(e=>{this.effect(t,e)})}const Or={},zr=0,Ir=1,Lr=2,jr=3,Rr=4,Fr=5,Br={VIEW:0,EDIT:1,SHIFT:2,ADD:3},Nr=30,Hr="undefined"==typeof window?1:window.devicePixelRatio||(window.matchMedia&&window.matchMedia("(min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 1.5),(-moz-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5)").matches?2:1),Yr=["mousemove","mouseup","mousedown","mouseout","wheel","touchstart","touchmove","touchend","dblclick"],Vr=["keydown","keyup"],Gr={ALPHA:1,FONT_SIZE:15,FONT_FAMILY:"Roboto, sans-serif",FONT_COLOR:"black",TEXT_ALIGN:"center",TEXT_BASELINE:"middle",TEXT_WRAP:!1,BOLD:!1,ITALIC:!1,STROKE_STYLE:"#999",LINE_DASH:"solid",LETTER_SPACING:0},Ur=()=>{if("undefined"==typeof document||"function"!=typeof getComputedStyle||!document.documentElement)return;const t=getComputedStyle(document.documentElement);if(!t)return;const e=t.getPropertyValue?.("--scene-theme-font-family")?.trim(),n=t.fontFamily||"sans-serif";Gr.FONT_FAMILY=e||n},Wr=()=>{if("undefined"!=typeof window&&"undefined"!=typeof document&&(window.addEventListener("load",()=>{Ur()}),"fonts"in document&&"ready"in document.fonts&&document.fonts.ready.then(Ur),"undefined"!=typeof MutationObserver&&document.documentElement)){new MutationObserver(()=>{Ur()}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}};let Xr;function qr(t,e,n,i,r){const{alpha:s=1}=i,o=r.fillStyle;if(t.globalAlpha*=s,o)if("string"==typeof o)t.fillStyle=o,t.fill();else if("object"==typeof o)if("gradient"==o.type){t.translate(n.x,n.y);let i,{width:r,height:s}=e;if("linear"==o.gradientType){const e=3.141592653589793,n="number"==typeof o.rotation&&Number.isFinite(o.rotation)?o.rotation:0;if(n>=.436332&&n<=1.13446||n>=2.00713&&n<=2.70526||n>=3.57792&&n<=4.27606||n>=5.14872&&n<=5.84685){let o=Math.sqrt(Math.pow((r-4)/2,2)+Math.pow((s-4)/2,2));o-=o-(r+s)/3,i=t.createLinearGradient(o*Math.cos(n+e),o*Math.sin(n+e),o*Math.cos(n),o*Math.sin(n))}else i=t.createLinearGradient((r-4)/2*Math.cos(n+e),(s-4)/2*Math.sin(n+e),(r-4)/2*Math.cos(n),(s-4)/2*Math.sin(n))}else if("radial"==o.gradientType){const e=.95*Math.sqrt(Math.pow((r-4)/2,2)+Math.pow((s-4)/2,2));switch(o.center){case"center":default:i=t.createRadialGradient(0,0,0,0,0,e);break;case"left-top":i=t.createRadialGradient(-r/2,-s/2,0,-r/2,-s/2,2*e);break;case"right-top":i=t.createRadialGradient(r/2,-s/2,0,r/2,-s/2,2*e);break;case"left-bottom":i=t.createRadialGradient(-r/2,s/2,0,-r/2,s/2,2*e);break;case"right-bottom":i=t.createRadialGradient(r/2,s/2,0,r/2,s/2,2*e)}}o.colorStops.forEach(t=>{if(t.position>=0&&t.position<=1)try{i.addColorStop(t.position,t.color)}catch(e){$i("Invalid Color for colorstop : ",t.color),i.addColorStop(t.position,"#fff")}}),t.fillStyle=i,t.fill(),t.translate(-n.x,-n.y)}else if("pattern"==o.type&&o.image)if(o.guideOnly&&1!=r.app.mode)o.color&&(t.fillStyle=o.color,t.fill());else{r.prepareFillIf(!r._pattern_image_origin);const n=r._pattern_image;if(!n||!n.width||!n.height)return;let i=0,s=0,a=0,c=0,l=e.left,h=e.top;if(!o.fitPattern){i=o.offsetX,s=o.offsetY;const t=o.width?o.width:n.width,r=o.height?o.height:n.height;switch(o.align){case"center":a=e.width/2-t/2,c=e.height/2-r/2;break;case"left-top":a=0,c=0;break;case"left-bottom":a=0,c=e.height-r;break;case"right-top":a=e.width-t,c=0;break;case"right-bottom":a=e.width-t,c=e.height-r;break;case"left":a=0,c=e.height/2-r/2;break;case"right":a=e.width-t,c=e.height/2-r/2;break;case"top":a=e.width/2-t/2,c=0;break;case"bottom":a=e.width/2-t/2,c=e.height-r}l+=i+a,h+=s+c}t.translate(l,h),o.color&&(t.fillStyle=o.color,t.fill()),o.fitPattern?Math.abs((n.width-e.width)*(n.height-e.height))>1?(delete r._pattern_image,delete r._pattern_image_origin):t.fillStyle=t.createPattern(n,"no-repeat"):t.fillStyle=t.createPattern(n,o.noRepeat?"no-repeat":"repeat"),t.fill(),t.translate(-l,-h)}}function Kr(t,e){const n=this.fillStyle;if(!n||"pattern"!=n.type||!n.image)return void t(this);if("string"!=typeof n.image)return this._pattern_image_origin=this._pattern_image=n.image,void t(this);this._pattern_image=null,this._pattern_image_origin=new Image;const i=this;this._pattern_image_origin.onload=function(){if(!n.fitPattern&&!n.width&&!n.height)return i._pattern_image=i._pattern_image_origin,void t(this);let e=n.width||this.width,r=n.height||this.height;n.fitPattern&&(e=i.bounds.width,r=i.bounds.height);const s=Xr(e,r);s.getContext("2d").drawImage(this,0,0,this.width,this.height,0,0,e,r),i._pattern_image=s,t(this)},this._pattern_image_origin.onerror=function(t){e(t)};try{"data"!==String(n.image).substring(0,4)?this._pattern_image_origin.crossOrigin="use-credentials":this._pattern_image_origin.crossOrigin=null,this._pattern_image_origin.src=this.app.url(n.image)}catch(t){e(t)}}function $r(t){t&&this.prepareFill(t=>{this.invalidate()},t=>{Ki(t)})}function Qr(t,e){const n=this.fillStyle;n&&"pattern"!==n.type?this._pattern_image&&(this._pattern_image=null,this._pattern_image_origin=null):n?.image&&this.prepareFillIf(n.image)}function Zr(t,e,n){let{strokeStyle:i,lineDash:r,lineWidth:s,lineCap:o,lineJoin:a,alpha:c}=e;if(i&&0!=s){if(o&&(t.lineCap=o),r){const e="round"==o;switch(r){case"solid":r=[0,0];break;case"round-dot":r=e?[0,2*s]:[s,s];break;case"square-dot":r=e?[s,2*s]:[2*s,s];break;case"dash":r=e?[3*s,2.5*s]:[4*s,1.5*s];break;case"dash-dot":r=e?[3*s,3*s,0,3*s]:[4*s,2*s,s,2*s];break;case"long-dash":r=e?[5*s,4*s]:[6*s,3*s];break;case"long-dash-dot":r=e?[5*s,3*s,0,3*s]:[6*s,2*s,s,2*s];break;case"long-dash-dot-dot":r=e?[5*s,2*s,0,2*s,0,2*s]:[6*s,s,s,s,s,s]}t.setLineDash(r)}t.globalAlpha*=c,t.strokeStyle=i,t.lineWidth=s,t.lineJoin=a,t.stroke()}}function Jr(t){const e=/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3|([^\*_]+)/g,n=[];let i;for(;null!==(i=e.exec(t));)i[1]?n.push({text:i[2],bold:!0,italic:!1}):i[3]?n.push({text:i[4],bold:!1,italic:!0}):i[5]&&n.push({text:i[5],bold:!1,italic:!1});return n}function ts(t,e,n,i=0){if(e.text.length<2)return e;let r=2;for(;r<e.text.length;r++){const s=e.text.substring(0,r);if(!(t.measureText(s).width+(r-1)*i<n))break}return{...e,text:e.text.substring(0,r-1)}}function es(t,e,n,i,r,s=0){const o=String(e).split("\n");return i?[].concat(...o.map(e=>function(t,e,n,i=0){const r=[];let s=[],o=0;return e.forEach(e=>{let a=e.text;for(;a.length>0;){const c=n-o,l=t.measureText(a).width+(a.length-1)*i;if(l<=c)s.push({...e,text:a}),o+=l,a="";else{const n=ts(t,{...e,text:a},c,i);s.push(n),r.push(s),s=[],o=0,a=a.substring(n.text.length)}}}),s.length>0&&r.push(s),r}(t,r?Jr(e):[{text:e,bold:!1,italic:!1}],n,s))):o.map(t=>r?Jr(t):[{text:t,bold:!1,italic:!1}])}function ns(t,e,n,i,r,s,o=0){if(!i)return[];t.save(),t.font=n;const a=es(t,i,e,!!r,s,o);return t.restore(),a}function is(t){const{fontFamily:e=Gr.FONT_FAMILY,bold:n=Gr.BOLD,italic:i=Gr.ITALIC,fontSize:r=Gr.FONT_SIZE}=t,s=[];return n&&s.push("bold"),i&&s.push("italic"),s.push(r+"px"),s.push(e),s.join(" ")}function rs(t,e){const n=t.bold||e.bold,i=t.italic||e.italic;return is({...t,bold:n,italic:i})}function ss(t,e,n,i){let{alpha:r,rotation:s,keepTextAngle:o=!1,fontColor:a=Gr.FONT_COLOR,textAlign:c=Gr.TEXT_ALIGN,textBaseline:l=Gr.TEXT_BASELINE,textBackgroundStyle:h,fontSize:d,lineHeight:u,textWrap:p,textOverflow:f,letterSpacing:g=0}=i;r=void 0!==r?r:1,d||=Gr.FONT_SIZE,u||=1.2*d,t.save();const{left:m,top:y,width:b,height:v}=e;if(s&&o&&(t.translate(m+b/2,y+v/2),t.rotate(-s),t.translate(-(m+b/2),-(y+v/2))),t.beginPath(),t.font=is(i),!p&&f){const e=function(t,e,n,i){const r="ellipsis"===t?"…":"",s=e.measureText(r).width,o=[];let a=0;for(const r of n){const n=[];for(const c of r){const r=e.measureText(c.text).width;if(!(a+r<=i-("ellipsis"===t?s:0))){const r=os(e,c,i-a-("ellipsis"===t?s:0),t);return n.push(r),o.push(n),o}n.push(c),a+=r}o.push(n),a=0}return o}(f,t,n,b);n=e}const _=n.length*u;let x;switch(l){case"top":x=y,t.textBaseline="top";break;case"bottom":x=y+v-_+u,t.textBaseline="bottom";break;default:x=y+v/2-_/2+u/2,t.textBaseline="middle"}t.globalAlpha*=r,t.fillStyle=a,n.forEach((e,r)=>{const s=x+r*u,o=function(t,e,n,i=0){return e.reduce((e,r)=>(t.font=rs(n,r),e+t.measureText(r.text).width+i*(r.text.length-1)),0)}(t,e,i,g);let l=m;switch(c){case"left":case"justify":l=m;break;case"right":l=m+b-o;break;case"center":l=m+(b-o)/2}if(h&&(t.fillStyle=h,function(t,e,n,i,r,s=0,o=!1,a=!0){s="number"==typeof s?{tl:s,tr:s,br:s,bl:s}:{tl:0,tr:0,br:0,bl:0,...s},t.beginPath(),t.moveTo(e+s.tl,n),t.lineTo(e+i-s.tr,n),t.quadraticCurveTo(e+i,n,e+i,n+s.tr),t.lineTo(e+i,n+r-s.br),t.quadraticCurveTo(e+i,n+r,e+i-s.br,n+r),t.lineTo(e+s.bl,n+r),t.quadraticCurveTo(e,n+r,e,n+r-s.bl),t.lineTo(e,n+s.tl),t.quadraticCurveTo(e,n,e+s.tl,n),t.closePath(),o&&t.fill(),a&&t.stroke()}(t,l-4,s-d/2-4,o+8,d+8,4,!0,!1),t.fillStyle=a),"justify"===c&&r<n.length-1&&e.length>1){const n=b-o,r=e.length-1,a=n/r;e.forEach((e,n)=>{t.font=rs(i,e),t.fillText(e.text,l,s),l+=t.measureText(e.text).width+(n<r?a:0)})}else e.forEach(e=>{t.font=rs(i,e),[...e.text].forEach(e=>{t.fillText(e,l,s),l+=t.measureText(e).width+g})})}),t.restore()}function os(t,e,n,i){let r="";for(let i=0;i<e.text.length;i++){const s=r+e.text[i];if(t.measureText(s).width>n)break;r=s}return{...e,text:r+("ellipsis"===i?"…":"")}}function as(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("image/"))return void this.set("fillStyle",{type:"pattern",image:e[n],fitPattern:!0})}Wr(),Ur(),Xr="undefined"==typeof document?function(t,e){return new Canvas(t,e)}:function(t,e){const n=document.createElement("canvas");return n.width=t,n.height=e,n};const cs=[];function ls(t,e,n={x:0,y:0},i=0,r={x:1,y:1}){if(1!==r.x||1!==r.y?(t=(t-n.x)/r.x,e=(e-n.y)/r.y):(t-=n.x,e-=n.y),0!==i){const n=Math.cos(-i),r=Math.sin(-i),s=t*r+e*n;t=t*n-e*r,e=s}return{x:t+n.x,y:e+n.y}}function hs(t,e,n={x:0,y:0},i=0,r={x:1,y:1}){if(t-=n.x,e-=n.y,0!==i){const n=Math.cos(i),r=Math.sin(i),s=t*r+e*n;t=t*n-e*r,e=s}return 1!==r.x||1!==r.y?{x:t*r.x+n.x,y:e*r.y+n.y}:{x:t+n.x,y:e+n.y}}function ds(t,e,n){if(!this.parent)return{x:t,y:e};const{rotation:i=0,scale:r={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,s=ls(t,e,n,i,r);return n&&(s.x-=n.x,s.y-=n.y),s}return ls(t,e,n=n||this.rotatePoint,i,r)}function us(t,e,n){if(!this.parent)return{x:t,y:e};let{rotation:i=0,scale:r={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,s=hs(t,e,void 0,i+(this._delta?.theta??0),r);return n&&(s.x+=n.x,s.y+=n.y),s}n=n||this.rotatePoint;const{theta:s=0,tx:o=0,ty:a=0,sx:c=1,sy:l=1}=this._delta||{};if(0===s&&0===o&&0===a&&1===c&&1===l)return hs(t,e,n,i,r);return hs(t+o,e+a,{x:n.x+o,y:n.y+a},i+s,{x:r.x*c,y:r.y*l})}function ps(t,e,n){n=n||this.rootModel;const i=this.transcoordS2T(t,e,n);return hs(i.x,i.y,void 0,(n.get("rotation")||0)+n._delta.theta)}function fs(t,e,n){n=n||this.rootModel,cs.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)cs.push(t);let i=this.transcoordS2P(t,e);for(let t=0;t<cs.length;t++){const e=cs[t],n=e.bounds;i.x+=n.left,i.y+=n.top,i=e.transcoordS2P(i.x,i.y)}return i}function gs(t,e,n){n=n||this.rootModel,cs.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)cs.push(t);let i={x:t,y:e};for(let t=cs.length-1;t>=0;t--){const e=cs[t];i=e.transcoordP2S(i.x,i.y);const n=e.bounds;i.x-=n.left,i.y-=n.top}return i}function ms(t,e,n){const i=this.transcoordT2P(t,e,n);return this.transcoordP2S(i.x,i.y)}function ys(t,e,n){const i=this.rootModel,r=this.transcoordS2T(t,e,i);return n.transcoordT2S(r.x,r.y,i)}function bs(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;const{translate:i={x:0,y:0},scale:r={x:1,y:1},rotation:s=0}=n.model,o=ls(t,e,i,s,r);return i&&(o.x-=i.x,o.y-=i.y),n===this?o:this.transcoordT2S(o.x,o.y,n)}function vs(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;let i;if(i=n!==this?this.transcoordS2T(t,e,n):{x:t,y:e},!this.scalable)return i;const{translate:r={x:0,y:0},rotation:s=0,scale:o={x:1,y:1}}=n.model;return i=hs(i.x,i.y,void 0,s+n._delta.theta,o),r&&(i.x+=r.x,i.y+=r.y),i}function _s(t){let e=0,n=0,i=0,r=0,s=!1;return t.forEach(t=>{s?(e=Math.min(t.left,e),n=Math.min(t.top,n),i=Math.max(t.left+t.width,i),r=Math.max(t.top+t.height,r)):(e=t.left,n=t.top,i=t.left+t.width,r=t.top+t.height,s=!0)}),{left:e,top:n,width:i-e,height:r-n}}function xs(t){const e=t.element,n=t.fillStyle,i=e.style;if(n)if("string"==typeof n)i.backgroundColor=n;else switch(n.type){case"pattern":if(i.backgroundImage="url("+n.image+")",i.backgroundColor="transparent",n.fitPattern?i.backgroundSize="100% 100%":n.width||n.height?i.backgroundSize=`${n.width?n.width+"px":"auto"} ${n.height?n.height+"px":"auto"}`:i.backgroundSize="contain",n.fitPattern)i.backgroundRepeat="no-repeat";else{const{offsetX:t,offsetY:e,noRepeat:r,align:s,color:o}=n;if(r&&(i.backgroundRepeat="no-repeat"),o&&(i.backgroundColor=o),s)switch(s){case"center":i.backgroundPosition="center center";break;case"left-top":i.backgroundPosition="left top";break;case"left-bottom":i.backgroundPosition="left bottom";break;case"right-top":i.backgroundPosition="right top";break;case"right-bottom":i.backgroundPosition="right bottom";break;case"left":i.backgroundPosition="left center";break;case"right":i.backgroundPosition="right center";break;case"top":i.backgroundPosition="center top";break;case"bottom":i.backgroundPosition="center bottom"}else t||e?i.backgroundPosition=`${Number(t)||0}px ${Number(e)||0}px`:delete i.backgroundPosition}break;case"gradient":i.background=function(t,e){const n=e.colorStops,i=e.gradientType;if(n instanceof Array&&n.length>0)switch(i){case"radial":return"radial-gradient(farthest-corner at "+function(t,e){const{width:n,height:i}=t.bounds;switch(e){case"center":return[n/2,i/2];case"left-top":return[0,0];case"right-top":return[n,0];case"left-bottom":return[0,i];default:return[n,i]}}(t,e.center||"center").map(t=>t+"px").join(" ")+","+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")";case"linear":return"linear-gradient("+(180*(e.rotation||0)/3.141592653589793+90+"deg")+", "+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")"}return""}(t,n)}else i.background="transparent"}const ws={x:1,y:1},Ms={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"};function Ss(t){let{id:e,scale:n=ws,bold:i,italic:r,fontFamily:s="",textAlign:o,textBaseline:a,textOverflow:c,paddingTop:l,paddingBottom:h,paddingLeft:d,paddingRight:u,fontSize:p=Gr.FONT_SIZE,lineWidth:f=0,lineHeight:g,lineDash:m}=t.state;h||=0,l||=0,d||=0,u||=0;const y=t.state.class,{strokeStyle:b,rotation:v=0,fontColor:_,hidden:x}=t,{left:w,top:M,width:S,height:k}=t.bounds,A=t.element;if(A.hidden=x,e&&(A.id=e),y&&(A.className=y),Object.assign(A.style,Ms,{fontFamily:s,fontSize:p+"px",width:S+"px",height:k+"px",paddingTop:l+"px",paddingRight:u+"px",paddingBottom:h+"px",paddingLeft:d+"px",border:f+"px",borderColor:b,borderStyle:f>0?m||Gr.LINE_DASH:"",color:_,fontWeight:i?"bold":"",fontStyle:r?"italic":"",textAlign:"end"==o?"right":"start"==o?"left":o,verticalAlign:a,lineHeight:void 0===g?"":g+"px",whiteSpace:c?"nowrap":"",overflow:c?"hidden":"",textOverflow:c||""},t.isIn3DSpace()?{}:{left:w+"px",top:M+"px"}),xs(t),function(t){if(!t.isShadowable()||!t.state.shadow)return;const e=t.state.shadow,n=e.offsetX??e.left??0,i=e.offsetY??e.top??0,r=e.blur??e.blurSize??0,s=e.color??"transparent";t.element.style.boxShadow=`${n}px ${i}px ${r}px ${s}`}(t),t.isIn3DSpace())return;const E=t.delta(),C=(n&&n.x||1)*E.sx,T=(n&&n.y||1)*E.sy,P=(v||0)+E.theta,D=E.tx||0,O=E.ty||0;A.style.transform=`rotate(${P}rad) translate(${D}px, ${O}px) scale(${C}, ${T}) perspective(1px)`}function ks(t,e){let n=this.bounds,i=this.rotatePoint;const r=this.get("rotation"),s=this.get("scale");if(t){const i=t.call(e,n);i&&(n=i)}const{left:o,top:a,width:c,height:l}=n;let h=[{x:o,y:a},{x:o+c,y:a+l}];h=h.map(t=>hs(t.x,t.y,i,r,s));let d=h[0],u=h[1];i={x:(d.x+u.x)/2,y:(d.y+u.y)/2},h=h.map(t=>ls(t.x,t.y,i,r,s)),d=h[0],u=h[1],this.bounds={left:d.x,top:d.y,width:u.x-d.x,height:u.y-d.y}}function As(t,e,n){let i=this.path,r=this.rotatePoint;this.get("rotation"),this.get("scale"),t&&(i=t.call(n,i));let s=i.map(t=>{const e=this.toParent(t.x,t.y);return void 0!==t.z&&(e.z=t.z),e});if(e){const t=e.call(n,s);t&&(s=t)}const o={x:0,y:0};let a,c,l,h;i=s.map(t=>this.fromParent(t.x,t.y,o)),a=c=i[0].x,l=h=i[0].y;for(let t=1;t<i.length;t++){const e=i[t];e.x<a?a=e.x:e.x>c&&(c=e.x),e.y<l?l=e.y:e.y>h&&(h=e.y)}r={x:(a+c)/2,y:(l+h)/2},r=this.toParent(r.x,r.y,o),this.path=s.map(t=>{const e=this.fromParent(t.x,t.y,r);return void 0!==t.z&&(e.z=t.z),e})}let Es,Cs=[];function Ts(){Es=null;const t=performance.now();Cs=Cs.filter(t=>Ps(t));const e=Cs.reduce((e,n)=>{const i=t-n.updatedAt;return i>=n.retention?e.kills.push(n):e.next=0==e.next?n.retention-i:Math.min(e.next,n.retention-i),e},{next:0,kills:[]});e.kills.forEach(t=>{const e=Cs.indexOf(t);-1!=e?(Cs.splice(e,1),t.removeSelf(!0)):Ki("Should not be here. Maybe reentrance problem.")}),e.next>0&&(Es=setTimeout(Ds,Math.max(e.next,500)))}function Ps(t){return!t.disposed&&t.retention>0&&!t.isTemplate()&&t.app&&t.app.isViewMode}const Ds=function(t,e,n){var i=!0,r=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return $(n)&&(i="leading"in n?!!n.leading:i,r="trailing"in n?!!n.trailing:r),di(t,e,{leading:i,maxWait:e,trailing:r})}(function(){requestAnimationFrame(Ts)},500);var Os=new class{add(t){Ps(t)&&-1==Cs.indexOf(t)&&(Cs.push(t),t.touch()),this.touch()}remove(t){const e=Cs.indexOf(t);e>0&&Cs.splice(e,1),this.touch()}touch(){null!==Es&&(clearTimeout(Es),Es=null),Ds()}dispose(){Ds.cancel(),null!==Es&&(clearTimeout(Es),Es=null),Cs=[]}get length(){return Cs.length}};const zs=function(t){return t};function Is(t){const e=t.indexOf("||");let n="",i="";-1!=e&&(n=t,i=t.substring(e+2,t.length-1).trim(),t=t.replace(t.substring(e,t.length-1),"").trim());const r=t.substr(2,t.length-3).trim().replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".").filter(t=>!!t.trim()),s=r.slice(1);return{defaultValue:i,match:t,originText:n||t,target:r[0],accessor:s.length>0?function(t){return s.reduce((t,e)=>t?t[e]:void 0,t)}:zs}}function Ls(t){if(!t)return;const e=String(t),n=(e.match(/#{(\S*)}/)||[]).map(t=>Is(t))[0];if(n)return n.accessor(this.getState(n.target));const i=(e.match(/\${[^}]*}/)||[]).map(t=>Is(t))[0];if(i){const t=this.root.findById(i.target);return i.accessor(this.getState(t))}return t}function js(t,e){if(!t)return;const n=String(t),i=e||vi,r=(n.match(/#{(\S*)}/gi)||[]).map(t=>Is(t)),s=(n.match(/\${[^}]*}/gi)||[]).map(t=>Is(t));if(0==r.length&&0==s.length)return n;let o=n;return r.forEach(t=>{const e=i(t.accessor(this.getState(t.target)));o=o.replace(t.match,void 0===e?"":e)}),s.forEach(t=>{const e=this.root.findById(t.target),n=i(t.accessor(e&&e.data));o=o.replace(t.match,void 0===n?"":n)}),o}function Rs(t,e,n){if(!t)return;const i=n||vi,r=String(t),s=(r.match(/#{[^}]*}/gi)||[]).map(t=>Is(t)),o=(r.match(/\${[^}]*}/gi)||[]).map(t=>Is(t));return 0!=s.length||0!=o.length?function(){let t=r;return s.forEach(n=>{const r=i(n.accessor(e.getState(n.target)));t=t.replace(n.originText,void 0===r?n.defaultValue||"":r)}),o.forEach(n=>{const r=e.root.findById(n.target),s=i(n.accessor(r&&r.data));t=t.replace(n.originText,void 0===s?n.defaultValue||"":s)}),t}:void 0}class Fs{constructor(){}static registerDecorator(t,e){Fs.constructors.set(t,e)}static create(t,e,n={},i){const r=Fs.constructors.get(t);if(!r)throw new Error(`unknown decorator type: ${t}`);return new r(i,e,n)}}Fs.constructors=new Map;class Bs{constructor(){this.overlays=new WeakMap}static getInstance(){return Bs.instance||(Bs.instance=new Bs),Bs.instance}addOverlay(t){if(this.overlays.has(t))return!1;const e={element:t,registry:new Map};return this.overlays.set(t,e),!0}removeOverlay(t){if(!this.overlays.has(t))return!1;const e=this.overlays.get(t);for(const[n]of e.registry)this.removeFromOverlay(t,n);return this.overlays.delete(t),!0}addToOverlay(t,e,n,i={}){this.overlays.has(t)||this.addOverlay(t);const r=this.overlays.get(t);r.registry.has(e)||r.registry.set(e,new Map);const s=r.registry.get(e);s.has(n)&&s.get(n).stop();const o=Fs.create(n,e,i,t);return s.set(n,o),e?.root?.app?.suppressAnimations||o.start(),o}removeFromOverlay(t,e,n){if(!this.overlays.has(t))return;const i=this.overlays.get(t);if(!i.registry.has(e))return;const r=i.registry.get(e);let s=null;if(n){if(r.has(n))try{const t=r.get(n);s=n,t&&"function"==typeof t.stop&&t.stop(),r.delete(n)}catch(t){Ki(`데코레이터(${n}) 제거 중 오류:`,t)}}else{const t=Array.from(r.keys());for(const e of t)try{const t=r.get(e);t&&"function"==typeof t.stop&&t.stop(),r.delete(e)}catch(t){Ki(`데코레이터(${e}) 제거 중 오류:`,t)}s="_all_"}0===r.size&&i.registry.delete(e),!s||"data-spread"!==s&&"_all_"!==s||this.restartBorderAnimations(t,e)}restartBorderAnimations(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);for(const[t,i]of n.registry.entries()){if(e&&t===e)continue;const n=i.get("border-highlighting");if(n)try{"function"==typeof n.invalidate&&n.invalidate();const t=n;"function"==typeof t.startAnimations&&t.options&&t.options.animation&&t.startAnimations()}catch(t){Ki("애니메이션 재시작 중 오류:",t)}}}removeAllFromOverlay(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);if(e)for(const[i]of n.registry)this.removeFromOverlay(t,i,e);else{for(const[t,e]of n.registry)for(const t of e.values())t.stop();n.registry.clear()}}getDecoratorFromOverlay(t,e,n){const i=this.overlays.get(t);return i?.registry.get(e)?.get(n)}getDecoratorsFromOverlay(t,e){const n=this.overlays.get(t);return n&&n.registry.has(e)?Array.from(n.registry.get(e).values()):[]}getTargetsWithType(t,e){const n=this.overlays.get(t);if(!n)return[];const i=[];for(const[t,r]of n.registry)r.has(e)&&i.push(t);return i}updateInOverlay(t,e,n,i){const r=this.getDecoratorFromOverlay(t,e,n);r&&r.update(i)}invalidateOverlay(t){if(!this.overlays.has(t))return;const e=this.overlays.get(t),n=Array.from(e.registry.entries());for(const[e,i]of n){if(e.disposed){this.removeFromOverlay(t,e);continue}this.getDecoratorsFromOverlay(t,e).forEach(t=>{t.invalidate()})}}}function Ns(t,e){return!1}function Hs({x:t,y:e},...n){const i=this.path,r=t,s=e;this.path=i.map(t=>({x:t.x+r,y:t.y+s}))}function Ys(t){const e=t??this.center.x,{rotation:n}=this.state,i=this.fillStyle;if(this.set("rotation",2*Math.PI-n),i&&"gradient"===i.type&&"linear"===i.gradientType){const t=Jn(i);t.rotation=(Math.PI-parseFloat(i.rotation||0))%(2*Math.PI),this.set("fillStyle",t)}this.path=this.path.map(t=>({x:2*e-t.x,y:t.y}))}function Vs(t){this.symmetryX(),this.set("rotation",(Math.PI+this.model.rotation)%(2*Math.PI)),t&&this.move({x:0,y:2*(t-this.center.y)},!1)}function Gs(t,e,n){if(n){const e=this.bounds,n=e.height/e.width;let i=t.width-e.width,r=t.height-e.height;i*n>r?r=i*n:i=r/n;let s=t.left-e.left,o=t.top-e.top;return 0!=s&&0!=o?(o=-r,s=-i):0!=s?s=-i:0!=o&&(o=-r),{left:e.left+s,top:e.top+o,width:e.width+i,height:e.height+r}}return t}function Us(t,e){if(e||this.app.rotateStepForced){const e=this.app.rotateStep;return Math.floor((t+e/2)/e)*e}return t}function Ws(t){return function(t,e){const n=t.path.slice();if(!n||!n.length)return void Ki("path should not be empty");let i=1;const r=[];if(t.isLine()||n.push(n[0]),e<=0)return t.toScene(n[0].x,n[0].y);if(e>=1)return t.toScene(n[n.length-1].x,n[n.length-1].y);for(;n[i];){const t=n[i-1],e=n[i],s=e.x-t.x,o=e.y-t.y;r.push(Math.sqrt(s*s+o*o)),i++}const s=r.reduce(function(t,e){return t+e},0);i=0;let o=0;do{o+=r[i++]}while(o/s<e);o-=r[--i],e=(e-o/s)*(s/r[i]);const a=n[i%n.length],c=n[(i+1)%n.length],l=a.x+Math.round((c.x-a.x)*e),h=a.y+Math.round((c.y-a.y)*e);return t.toScene(l,h)}(this,t||0)}function Xs(){const t=this.path;let e,n,i,r;e=n=t[0].x,i=r=t[0].y;for(let s=1;s<t.length;s++){const o=t[s];o.x<e?e=o.x:o.x>n&&(n=o.x),o.y<i?i=o.y:o.y>r&&(r=o.y)}return{left:e,top:i,width:n-e,height:r-i}}function qs(t){const e=this.bounds;if(Math.round(100*t.width)/100==Math.round(100*e.width)/100&&Math.round(100*t.height)/100==Math.round(100*e.height)/100&&Math.round(100*t.left)/100==Math.round(100*e.left)/100&&Math.round(100*t.top)/100==Math.round(100*e.top)/100)return;const n=0==e.width?1:t.width/e.width,i=0==e.height?1:t.height/e.height;this.path=this.path.map(r=>({x:t.left+(r.x-e.left)*n,y:t.top+(r.y-e.top)*i}))}function Ks(){const t=this.bounds;return{x:t.left+t.width/2,y:t.top+t.height/2}}function $s(t){if(!t||isNaN(t.x)||isNaN(t.y))return;const e=this.center;if(Math.round(100*t.x)/100==Math.round(100*e.x)/100&&Math.round(100*t.y)/100==Math.round(100*e.y)/100)return;const n=t.x-e.x,i=t.y-e.y;this.path=this.path.map(t=>({x:t.x+n,y:t.y+i}))}function Qs(){const{x:t,y:e}=this.center;return{x:t,y:e,z:this.state.zPos}}function Zs(t){const{x:e,y:n,z:i}=t||{};this.center={x:e,y:n},isNaN(i)||this.setState("zPos",Number(i))}function Js(){const{rotationX:t,rotationY:e,rotation:n}=this.state;return{x:t,y:e,z:-n}}function to(t){const{x:e,y:n,z:i}=t;this.setState({rotationX:e,rotationY:n,rotation:-i})}function eo(){const{width:t,height:e}=this.bounds,{depth:n}=this.state;return{width:t,height:e,depth:n}}function no(t){const{width:e,height:n,depth:i}=t,{top:r,left:s}=this.bounds;this.bounds={top:r,left:s,width:e,height:n},this.setState("depth",i)}function io(){return Ki("이 컴포넌트에 get path 가 구현되어있지 않음.",this),[]}function ro(t){Ki("이 컴포넌트에 get path 가 구현되어있지 않음.",this)}function so(){return this.path}function oo(){return this.center}function ao(){return this.nature.mutable}function co(){return this.nature.resizable&&!this.stuck}function lo(){return this.nature.rotatable&&!this.stuck}const ho={x:1,y:1};function uo(t,e,n){const{offsetX:i,offsetY:r,blur:s,color:o}=function(t){return{offsetX:t.offsetX??t.left??0,offsetY:t.offsetY??t.top??0,blur:t.blur??t.blurSize??0,color:t.color??"transparent"}}(e),a=n.rootModel.get("scale")??ho;t.shadowOffsetX=i*a.x*Hr,t.shadowOffsetY=r*a.y*Hr,t.shadowBlur=s*a.x*Hr,t.shadowColor=o}function po(t){t.save(),this.prerender(t),this.render(t),this.postrender(t),t.restore()}function fo(t){const e=this.rotatePoint,{scale:n,rotation:i,shadow:r,alpha:s}=this.state,o=(n&&n.x||1)*this._delta.sx,a=(n&&n.y||1)*this._delta.sy,c=(i||0)+this._delta.theta,{tx:l=0,ty:h=0}=this._delta,d=(s||1)-this._delta.fade;(l||h)&&t.translate(l,h),(1!=o||1!=a||c)&&(t.translate(e.x,e.y),1==o&&1==a||t.scale(o,a),c&&t.rotate(c),t.translate(-e.x,-e.y)),d&&(t.globalAlpha=d),r&&uo(t,r,this),this.app.isEditMode&&this.hidden&&(t.globalAlpha*=.5)}function go(t){}function mo(t){this.drawText(t)}function yo(t,e){t(this)}function bo(t){t&&this.prepare&&this.prepare(t=>{this.invalidate()},t=>{Ki(t)})}function vo(t){!this.textHidden&&this.text&&this.hasTextProperty&&ss(t,this.textBounds,this.textLines(t),this.state)}function _o(t,e){Zr(t,e?{...this.state,...e}:this.state)}function xo(t,e){this.fillStyle&&"transparent"!=this.fillStyle&&(qr(t,this.bounds,this.center,e?{...this.state,...e}:this.state,this),function(t){t.shadowColor="transparent"}(t))}function wo(){return this.get("strokeStyle")}function Mo(t){this.set("strokeStyle",t)}function So(){return this.getState("fillStyle")}function ko(t){this.setState("fillStyle",t)}function Ao(){return this.get("fontColor")}function Eo(t){this.set("fontColor",String(vi(t)))}function Co(){return this.getState("rotation")}function To(t){this.setState("rotation",Number(vi(t)))}function Po(){return this.app.isEditMode?["decotag","data-spread"]:[]}function Do(){const{id:t,tag:e}=this.state;return(t?`#${t}`:"")+(e?`@${e}`:"")}function Oo(){return this.getState("hidden")||!this.data&&0!==this.data&&this.getState("ndns")||this.isTemplate()}function zo(t){this.setState("hidden",t)}function Io(){return this.state.tag}function Lo(t){this.setState("tag",t)}function jo(){}function Ro(t){this.data instanceof Array?this.data=this.data.concat(t):this.data instanceof Object?this.data={...this.data,...t}:this.data??=t}function Fo(){const t=this.getState("text");return null==t?"":String(t)}function Bo(t){const{textWrap:e,supportMarkdown:n}=this.state;return ns(t||this.getContext(),this.textBounds.width,this.font,this.text,e,n)}function No(){return is(this.model)}function Ho(){const t=this.get("lineHeight");return t||1.2*this.fontSize}function Yo(){return this._text_substitutor||(this._text_substitutor=Rs(this.getState("text"),this,void 0)||this.defaultTextSubstitutor),this._text_substitutor}function Vo(){const t=this.get("textFormat");return t?function(t,e){if(!t||isNaN(+e))return e;let n,i,r,s,o,a,c,l,h,d,u,p=t.length,f=t.search(/[0-9\-\+#]/),g=f>0?t.substring(0,f):"",m=t.split("").reverse().join(""),y=m.search(/[0-9\-\+#]/),b=p-y,v=t.substring(b,b+1),_=b+("."===v||","===v?1:0),x=y>0?t.substring(_,p):"";if(n=(e="-"===(t=t.substring(f,_)).charAt(0)?-e:+e)<0?e=-e:0,i=t.match(/[^\d\-\+#]/g),r=".",s=i&&i[1]&&i[0]||",",t=t.split("."),e=+(e=e.toFixed(t[1]&&t[1].length))+"",a=t[1]&&t[1].lastIndexOf("0"),l=e.split("."),(!l[1]||l[1]&&l[1].length<=a)&&(e=(+e).toFixed(a+1)),h=t[0].split(s),t[0]=h.join(""),o=t[0]&&t[0].indexOf("0"),o>-1)for(;l[0].length<t[0].length-o;)l[0]="0"+l[0];else 0===+l[0]&&(l[0]="");if((e=e.split("."))[0]=l[0],c=h[1]&&h[h.length-1].length,c){for(d=e[0],m="",b=d.length%c,p=d.length,_=0;_<p;_++)m+=d.charAt(_),!((_-b+1)%c)&&_<p-c&&(m+=s);e[0]=m}return e[1]=t[1]&&e[1]?"."+e[1]:"",i=e.join(""),"0"!==i&&""!==i||(n=!1),u="+"==t[0].substring(0,1)?n?"-":"+":n?"-":"",g+(u+i)+x}(t,this.textSubstitutor()):this.textSubstitutor()}function Go(t){delete this._text_substitutor;const e=vi(t);this.setState("text",null==e?"":String(e))}function Uo(){let{paddingTop:t,paddingLeft:e,paddingRight:n,paddingBottom:i}=this.state;i||=0,t||=0,e||=0,n||=0;const{left:r,top:s,width:o,height:a}=this.bounds;return{left:r+e,top:s+t,width:Math.max(o-e-n,0),height:Math.max(a-t-i,0)}}function Wo(){return 0}function Xo(){return!!this._textHidden}function qo(t){this._textHidden=!!t,this.invalidate()}function Ko(){return!0}function $o(t){return t}function Qo(t){return Math.pow(t,2)}function Zo(t){return 1-Math.sin(Math.acos(t))}function Jo(t,e={x:1.5}){return Math.pow(t,2)*((e.x+1)*t-e.x)}function ta(t){for(let e=0,n=1;;e+=n,n/=2)if(t>=(7-4*e)/11)return-Math.pow((11-6*e-11*t)/4,2)+Math.pow(n,2)}function ea(t,e={x:1.5}){return Math.pow(2,10*(t-1))*Math.cos(20*Math.PI*e.x/3*t)}var na={linear:$o,quad:Qo,circ:Zo,back:Jo,bounce:ta,elastic:ea},ia=Object.freeze({__proto__:null,back:Jo,bounce:ta,circ:Zo,default:na,elastic:ea,linear:$o,quad:Qo});function ra(t){const{duration:e=1e3,easing:n,component:i,step:r=()=>{},onStart:s,onProgress:o,onComplete:a,options:c,repeat:l=!1,delta:h}=t;let d;d="string"==typeof h?ia[h]:h||$o,"out"===n?d=function(t,e){return function(n){return 1-t(1-n,e)}}(d,c):"inout"===n&&(d=function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(d,c));let u=!1,p=null;return{start:function(){if(u)return this;if(i?.root?.app?.suppressAnimations)return this;u=!0,s&&s();let t=0;const n=()=>{if(!u)return;if(i?.root?.app?.suppressAnimations)return this.stop(),void(t=0);0===t&&(t=performance.now());const s=(performance.now()-t)/e,a=l?s%1:Math.min(s,1);r(d(a,c)),o&&o(a),!(s>=1)||l&&u||(this.stop(),t=0),u&&(p=requestAnimationFrame(n))};return p=requestAnimationFrame(n),this},stop:function(){return u=!1,null!==p&&(cancelAnimationFrame(p),p=null),a&&a(),this}}}class sa{constructor(t,e){this._started=!1,this._raf=null,this._timeout=null,this.client=t,this.config=e,this._started=!1;const{delta:n="linear",options:i,ease:r}=this.config;let s;s="string"==typeof n?na[n]:n,this.delta="out"===r?function(t,e){return function(n){return 1-t(1-n,e)}}(s,i):"inout"===r?function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(s,i):s,this.init()}dispose(){this.stop(),delete this.client}init(){}start(){if(this._started)return;if(this.client?.root?.app?.suppressAnimations)return;const{duration:t=2e3,delay:e=0,repeat:n=!1,interval:i=0,onComplete:r}=this.config;this._started=!0;let s=0,o=0;const a=()=>{if(this._raf=null,this._timeout=null,!this._started)return;if(this.client?.root?.app?.suppressAnimations)return void this.stop(r);0==s&&(s=performance.now(),this.client?.touch?.());const c=performance.now()-s,l=Math.max((c-e)%(t+i),0)/t,h=i<=0&&o>l;if(o=l,l>=1||h){if(this.step(1),this.client&&this.client.invalidate?.(),!n||!this._started)return this.stop(r),void(s=0);if(i>0)return void(this._timeout=setTimeout(()=>{this.step(0),this.client&&this.client.invalidate?.(),this._timeout=setTimeout(a,i/2)},i/2))}else this.step(this.delta(l)),this.client&&this.client.invalidate?.();this._raf=requestAnimationFrame(a)};this._raf=requestAnimationFrame(a)}stop(t){this._raf&&cancelAnimationFrame(this._raf),this._timeout&&clearTimeout(this._timeout),this._raf=null,this._timeout=null,this._started=!1,t?.()}step(t){}get started(){return this._started}set started(t){this.started!=!!t&&(t?this.start():this.stop())}}const oa={rotation:class extends sa{step(t){const{theta:e=6.28}=this.config;this.client.delta?.("theta",t*e)}},vibration:class extends sa{step(t){const{theta:e=.2617993877991494}=this.config,n=4*e;let i=t*n;t<1/4?i*=-1:t<3/4?i-=2*e:i=n-i,this.client.delta?.("theta",i)}},heartbeat:class extends sa{step(t){const{scale:e=1.3}=this.config,n=2*(e-1);let i;i=t<.5?1+n*t:1+(1-t)*n,this.client.delta?.({sx:i,sy:i,sz:i})}},moving:class extends sa{step(t){const{x:e=0,y:n=0}=this.config;this.client.delta?.({tx:t*e,ty:t*n})}},outline:class extends sa{step(t){const{rideOn:e}=this.config;if(!e||!this.client)return;const n=this.client.root.findById(e);if(!n)return;let i={tx:0,ty:0};const r=this.client.delta("");r&&"object"==typeof r&&"tx"in r&&"ty"in r&&(i=r);const{tx:s,ty:o}=i,a=n.outline(t),{x:c,y:l}=this.client.center,h=this.client.toScene(c,l);this.client.delta({tx:a.x-h.x+s,ty:a.y-h.y+o})}},fade:class extends sa{step(t){const{startAlpha:e=1,endAlpha:n=0}=this.config,i=Math.max(Math.min(e,n,1),0),r=2*(Math.min(Math.max(e,n,1),1)-i);let s;s=t<.5?r*t:(1-t)*r,this.client.delta?.("fade",s)}},waypoint:class extends sa{start(){let{toComponent:t,fromComponent:e}=this.config;e||(e=t);const n=e.center,i=t.center,{x:r,y:s}=e.toScene(n.x,n.y),{x:o,y:a}=t.toScene(i.x,i.y),c=Math.atan2(a-s,o-r)+Math.PI/2;this.client.location={x:r,y:s},this.client.setState("rotation",c),super.start()}stop(){const{toComponent:t}=this.config;super.stop();const e=t.center,n=t.toScene(e.x,e.y);this.client.delta({tx:0,ty:0}),this.client.location=n}step(t){let{toComponent:e,fromComponent:n}=this.config;n||(n=e);const i=n.center,r=e.center,{x:s,y:o}=n.toScene(i.x,i.y),{x:a,y:c}=e.toScene(r.x,r.y),l=(a-s)*t,h=(c-o)*t;this.client.location={x:s+l,y:o+h}}}};function aa(t,e){const n=e.type?oa[e.type]:void 0;return n?new n(t,e):null}const ca={gradation:function(t,e,n){const{subType:i,from:r,to:s,colors:o}=n;let a;switch(i){case"linear":default:a=e.createLinearGradient(r.x,r.y,s.x,s.y);break;case"radial":a=e.createRadialGradient(r.x,r.y,r.r,s.x,s.y,s.r)}o&&(o.forEach(function(t){a.addColorStop(t.endPoint,t.color)}),e.fillStyle=a,e.fill())},shadow:uo};function la(t){return this._animate&&this._animate.stop(),this._animate=ra(t),this._animate}function ha(t,e){return function(t,e,n){const i=ca[n.type];i&&i(t,e,n)}(this,t,e)}const da=100;function ua(t,e){return"number"!=typeof e||Number.isInteger(e)?e:Math.round(e*da)/da}function pa(t){if(null==t||"object"!=typeof t)return t;for(const e in t){const n=t[e];"number"!=typeof n||Number.isInteger(n)?null!=n&&"object"==typeof n&&pa(n):t[e]=Math.round(n*da)/da}return t}function fa(...t){return JSON.stringify(this.hierarchy,ua,...t)}function ga(){delete this._model[""],"chartjs"!==this._model.type&&delete this._model.chart}function ma(t){this.rootModel.closeScene(t)}function ya(t,e){return t?"object"==typeof t?(this._delta={...this._delta,...t},this._delta):void 0!==e?(this._delta[t]=e,this._delta[t]):void 0:this._delta}function ba(){this.parent&&this.parent.invalidate()}function va(){const t=this.nature["value-property"]||"text";return"value"==t?this.getState("value"):this[t]}function _a(t){const e=this.nature["value-property"]||"text";"value"==e?this.setState("value",t):this[e]=t}function xa(){return this.getState("data")}function wa(t){this.setState("data",t),this.touch()}function Ma(t){const e=this.model.event?.tap;if(e){const{x:t,y:n}=this.center;this.rootModel?._doEventAction(e,this,!0,new MouseEvent("click",{clientX:t,clientY:n}))}}function Sa(){return!this._mappings&&this.parent&&this.buildMappings(),this._mappings}function ka(){return Number(this.get("retention"))||0}function Aa(){if(this.app.isViewMode&&!this.isTemplate()){if(!this._animation){const t=this.state.animation;t&&t.oncreate&&(this._animation=aa(this,t.oncreate))}return this._animation}}function Ea(){return!!this.animation?.started}function Ca(t){this.animation&&(this.animation.started=t)}function Ta(){}function Pa(t,e,n,i){const r=e.get("class");if(!r)return!1;return(r.split(" ")||[]).indexOf(t.substr(1))>=0}function Da(t,e,n,i){return t==e.get("type")}function Oa(t,e,n,i){if("(all)"==t)return!0;switch(t.charAt(0)){case"#":return function(t,e){return t.substring(1)==e.get("id")}(t,e);case".":return Pa(t,e);case"(":return function(t,e,n,i){switch(t){case"(all)":return!0;case"(self)":return i===e;case"(root)":return!i.parent&&i===e;case"(descendant)":return i!==e;case"(child)":return i===e.parent;default:return!1}}(t,e,0,i);default:return Da(t,e)}}function za(t,e,n,i,r,s){return t(e,n,i,r)&&s.push(n),n.components&&n.components.forEach(n=>{za(t,e,n,i,r,s)}),s}function Ia(t,e,n,i){switch(t){case"(all)":return!0;case"(parent)":return n&&n.parent===e;case"(child)":case"(children)":return n&&n===e.parent;case"(sibling)":case"(siblings)":return n&&n.parent===e.parent&&n!==e;default:return!1}}function La(t,e,n){if("(root)"==t)return[e];if("(self)"==t)return n?[n]:[];let i;switch(t.charAt(0)){case"#":const n=e.root.findAllById?.(t.substring(1));return n||[];case".":i=Pa;break;case"(":i=Ia;break;default:i=Da}return za(i,t,e,n,e,[])}function ja(t,...e){if(t(this,...e))return this}function Ra(t,...e){return"string"==typeof t?La(t,this,e[0]||this):"function"==typeof t&&t(this,...e)?[this]:void 0}function Fa(t,e,n){if(!this.capturable||n?.(this))return!1;const i=this.fromParent(t,e);return this.contains(i.x,i.y)?this:void 0}function Ba(t){return this.anchors.find(e=>e.name===t)}function Na(t){return!0}function Ha(t){return this._parent.getContext(t??this)}function Ya(){return this.isRoot()?this:this.parent&&this.parent.root}function Va(){return this.isRootModel()?this:this.parent&&this.parent.rootModel}function Ga(){return this._parent}function Ua(t){this._parent=t}function Wa(){return this.nature.anchors||[]}function Xa(){let t=this.position,e=this;for(;"static"===t&&e.parent;)e=e.parent,t=e.position;return"static"==t}function qa(){return!!(this.parent&&this.parent.layout.isStuck(this)||this.get("locked"))}function Ka(){return!1!==this.get("capturable")&&(this.app.isEditMode||!this.hidden)}function $a(){return this.app?.isViewMode&&this.isPositionable()?this.state.position??"static":"static"}function Qa(){return this.app&&this.app.isViewMode&&this.state.origin||""}function Za(){const{offsetX:t=0,offsetY:e=0}=this.state;return{x:t,y:e}}function Ja(){return!this._app&&this.parent&&(this._app=this.parent.app),this._app}const tc={},ec={mutable:!1,resizable:!0,rotatable:!0,properties:[],"value-property":"text"},nc=[],ic=new Set(["data","text","value","source","accessor","mappings","variables","fillStyle","strokeStyle","fontColor","alpha","opacity","hidden","locked","hatched","started","animation","sensitive","event","src","href","url","class","templatePrefix"]),rc={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0};let sc=0;const oc={};const ac=new FinalizationRegistry(t=>{!function(t){sc--;let e=oc[t];e||(e=oc[t]={up:0,down:0}),e.down++}(t)});class cc{static get nature(){return ec}static register(t,e){if(!e)return tc[t];tc[t]=e}static get residents(){return oc}static get residentsCount(){return sc}static registerDecorator(t,e){Fs.registerDecorator(t,e)}constructor(t,e){this._app=e,this._model=t||{},this._state={},this._delta=Jn(rc),e&&this.animation?.config&&(1==this.animation.config.autoplay||(this.animation.config.autoplay??1))&&(this.animation.started=!0),this.clearCache(),Os.add(this),function(t){sc++;let e=oc[t];e||(e=oc[t]={up:0,down:0}),e.up++}(this._model.type),ac.register(this,this._model.type)}created(){}added(t){}removed(t){}async ready(){if(this.state.persistent){const{isViewMode:t,dataStorage:e}=this.app;t&&(this.data=await e.load(this))}}touch(){this.updatedAt=performance.now()}clearCache(...t){this._cachedState=null,function(t,...e){0==e.length?t.__cache__={}:e.forEach(e=>delete t.__cache__[e])}(this,...t)}removeSelf(t){t?this.dispose():this.parent?.removeComponent?.(this)}resetAnimation(){this._animation&&(this._animation.dispose(),this._animation=null,this._delta=Jn(rc))}dispose(){this.resetAnimation(),this.disposeMappings(),this.parent?.removeComponent?.(this),delete this._text_substitutor,delete this._value_substitutor,this._disposed=!0,this._realObject&&(this._realObject.dispose(),this._realObject=void 0),this.retention&&Os.touch(),this.clearCache(),delete this._app}get nature(){return this.constructor.nature}get disposed(){return!!this._disposed}isLayer(){return!1}isGroup(){return!1}isContainer(){return!1}isLine(){return!1}isRoot(){return!1}isRootModel(){return!1}is3dish(){return!0}get is3dMode(){return!1}isIn3DSpace(){return!!this._realObject}isTemplate(){return!!this.get("templatePrefix")}isHTMLElement(){return!1}isConnectable(){return!1}isIdentifiable(){return!0}isPositionable(){return this.parent?.isRootModel()}replaceRefids(t){}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=this;return this._applyProps(this._model,t,{getBeforeVal:function(t){return n._model[t]},clearState:!0,sensitive:!1,beforeFillStyle:function(t,e){t.hasOwnProperty("retention")&&Os.add(n)},afterFillStyle:function(t,e){t.hasOwnProperty("mappings")&&n.onchangeMappings(t,e)}})}getState(t){return this._state.hasOwnProperty(t)?this._state[t]:this.get(t)}setState(t,e){if("string"==typeof t)return this.setState({[t]:e});const n=this;return this._applyProps(this._state,t,{getBeforeVal:function(t){return n.getState(t)},clearState:!1,sensitive:this.getState("sensitive")})}get model(){return this._model}get state(){return this._cachedState||(this._cachedState=Object.freeze(Object.assign({},this._model,this._state))),this._cachedState}get hierarchy(){const t=Jn(this._model);return this.volatile.forEach(e=>{delete t[e]}),pa(t)}get volatile(){return nc}_applyProps(t,e,n){const i={},r={};let s=!1;const o=Jn(e),a=this;if(Object.getOwnPropertyNames(o).forEach(function(e){const c=n.getBeforeVal(e),l=o[e];!n.sensitive&&function(t,e){return Oe(t,e)}(c,l)||(r[e]=c,i[e]=l,t[e]=l,n.clearState&&delete a._state[e],s=!0)}),s){this._cachedState=null;Object.keys(i).some(t=>!ic.has(t))&&this.clearCache(),i.hasOwnProperty("text")&&delete this._text_substitutor,n.beforeFillStyle&&n.beforeFillStyle(i,r),i.hasOwnProperty("fillStyle")&&this.onchangeFill(i,r),n.afterFillStyle&&n.afterFillStyle(i,r),i.hasOwnProperty("data")&&this.onchangeData(i,r),this.onchange&&this.onchange(i,r),this.trigger("change",i,r)}return this}contains(t,e){return Ns.call(this,t,e)}move(t,...e){Hs.call(this,t,...e)}symmetryX(t){Ys.call(this,t)}symmetryY(t){Vs.call(this,t)}adjustResize(t,e,n){return Gs.call(this,t,e,n)}adjustRotation(t,e){return Us.call(this,t,e)}outline(t){return Ws.call(this,t)}get bounds(){return Xs.call(this)}set bounds(t){qs.call(this,t)}get center(){return Ks.call(this)}set center(t){$s.call(this,t)}get location(){return Qs.call(this)}set location(t){Zs.call(this,t)}get rotate(){return Js.call(this)}set rotate(t){to.call(this,t)}get dimension(){return eo.call(this)}set dimension(t){no.call(this,t)}get path(){return io.call(this)}set path(t){ro.call(this,t)}get drawPath(){return so.call(this)}get rotatePoint(){return oo.call(this)}get mutable(){return ao.call(this)}get resizable(){return co.call(this)}get rotatable(){return lo.call(this)}buildRealObject(){}get realObject(){return this.disposed||this._realObject||(this._realObject=this.buildRealObject(),this._realObject&&(this._realObject.update(),this._realObject.updateTransform())),this._realObject}draw(t){t&&po.call(this,t)}prerender(t){fo.call(this,t)}render(t){go.call(this,t)}postrender(t){mo.call(this,t)}prepare(t,e){yo.call(this,t,e)}prepareIf(t){bo.call(this,t)}drawText(t){vo.call(this,t)}drawStroke(t,e){_o.call(this,t,e)}drawFill(t,e){xo.call(this,t,e)}get strokeStyle(){return wo.call(this)}set strokeStyle(t){Mo.call(this,t)}get fillStyle(){return So.call(this)}set fillStyle(t){ko.call(this,t)}get fontColor(){return Ao.call(this)}set fontColor(t){Eo.call(this,t)}get rotation(){return Co.call(this)}set rotation(t){To.call(this,t)}get decorators(){return Po.call(this)}get decotag(){return Do.call(this)}get hidden(){return Oo.call(this)}set hidden(t){zo.call(this,t)}get tag(){return Io.call(this)}set tag(t){Lo.call(this,t)}get appendum(){return jo.call(this)}set appendum(t){Ro.call(this,t)}defaultTextSubstitutor(){return Fo.call(this)}textLines(t){return Bo.call(this,t)}get font(){return No.call(this)}get lineHeight(){return Ho.call(this)}get textSubstitutor(){return Yo.call(this)}get text(){return Vo.call(this)}set text(t){Go.call(this,t)}get textBounds(){return Uo.call(this)}get textRotation(){return Wo.call(this)}get textHidden(){return Xo.call(this)}set textHidden(t){qo.call(this,t)}get hasTextProperty(){return Ko.call(this)}animate(t){return la.call(this,t)}effect(t,e){return ha.call(this,t,e)}serialize(...t){return fa.call(this,...t)}trim(){ga.call(this)}closeScene(t){ma.call(this,t)}delta(t,e){return ya.call(this,t,e)}invalidate(){ba.call(this)}get value(){return va.call(this)}set value(t){_a.call(this,t)}get data(){return xa.call(this)}set data(t){wa.call(this,t)}set tap(t){Ma.call(this,t)}get mappings(){return Sa.call(this)}get retention(){return ka.call(this)}get animation(){return Aa.call(this)}get started(){return Ea.call(this)}set started(t){Ca.call(this,t)}get controls(){return Ta.call(this)}findFirst(t,...e){return ja.call(this,t,...e)}findAll(t,...e){return Ra.call(this,t,...e)}capture(t,e,n){return Fa.call(this,t,e,n)}findAnchor(t){return Ba.call(this,t)}isDescendible(t){return Na.call(this,t)}getContext(t){return Ha.call(this,t)}get root(){return Ya.call(this)}get rootModel(){return Va.call(this)}get parent(){return Ga.call(this)}set parent(t){Ua.call(this,t)}get anchors(){return Wa.call(this)}get scalable(){return Xa.call(this)}get stuck(){return qa.call(this)}get capturable(){return Ka.call(this)}get position(){return $a.call(this)}get origin(){return Qa.call(this)}get offset(){return Za.call(this)}get app(){return Ja.call(this)}drawEffect(t){Dr.call(this,t)}prepareFill(t,e){Kr.call(this,t,e)}prepareFillIf(t){$r.call(this,t)}onchangeFill(t,e){Qr.call(this,t,e)}drawImage(t,e,n,i,r,s){Pr.call(this,t,e,n,i,r,s)}mutateBounds(t,e){ks.call(this,t,e)}mutatePath(t,e,n){As.call(this,t,e,n)}access(t){return Ls.call(this,t)}substitute(t,e){return js.call(this,t,e)}onchangeMappings(t,e){Tr.call(this,t,e)}onchangeData(t,e){Ar.call(this,t,e)}buildMappings(){Er.call(this)}executeMappings(t){kr.call(this,t)}disposeMappings(){Cr.call(this)}ondropfile(t,e){as.call(this,t,e)}transcoordS2P(t,e,n){return us.call(this,t,e,n)}transcoordP2S(t,e,n){return ds.call(this,t,e,n)}transcoordS2T(t,e,n){return fs.call(this,t,e,n)}transcoordT2P(t,e,n){return gs.call(this,t,e,n)}transcoordT2S(t,e,n){return ms.call(this,t,e,n)}transcoordS2TR(t,e,n){return ps.call(this,t,e,n)}transcoordS2O(t,e,n){return ys.call(this,t,e,n)}transcoordC2S(t,e,n){return bs.call(this,t,e,n)}transcoordS2C(t,e,n){return vs.call(this,t,e,n)}toParent(t,e,n){return us.call(this,t,e,n)}fromParent(t,e,n){return ds.call(this,t,e,n)}toScene(t,e,n){return fs.call(this,t,e,n)}fromScene(t,e,n){return ms.call(this,t,e,n)}toLocal(t,e,n){return bs.call(this,t,e,n)}toGlobal(t,e,n){return vs.call(this,t,e,n)}toOther(t,e,n){return ys.call(this,t,e,n)}on(t,e,n){return Yi.call(this,t,e,n)}off(t,e,n){return Vi.call(this,t,e,n)}once(t,e,n){return Gi.call(this,t,e,n)}trigger(t,...e){return Ui.call(this,t,...e)}delegate_on(t){return Wi.call(this,t)}delegate_off(t){return Xi.call(this,t)}onchange(t,e){}removeComponent(t,e){}addComponent(t,e){}insertComponentAt(t,e,n){}getOverlay(t){}findById(t){}findByRefid(t){}findAllById(t){return[]}resize(){}fit(t){}get components(){}get layout(){}get auxOverlay(){}get isReady(){return!1}get unitScale(){return 1}get selected(){return[]}set selected(t){}get focused(){return null}set focused(t){}get hasSameParentForAllSelected(){return!1}set hasSameParentForAllSelected(t){}get fitMode(){}set fitMode(t){}get element(){return null}set element(t){}}cc.union=_s,cc.transcoordR=ls,cc.transcoordRR=hs,cc.createCanvas=Xr,cc.memoize=Zi,cc.mixin=qi,cc.drawText=ss,cc.font=is,cc.textLines=ns,cc.drawStroke=Zr,cc.drawFill=qr,cc.reposition=Ss,cc.RetentionManager=Os,cc.template=function(t,e,n){var i=Mn.imports._.templateSettings||Mn;n&&We(t,e,n)&&(e=void 0),t=_n(t),e=Qe({},e,i,hn);var r,s,o=Qe({},e.imports,i.imports,hn),a=le(o),c=function(t,e){return an(e,function(e){return t[e]})}(o,a),l=0,h=e.interpolate||Tn,d="__p += '",u=RegExp((e.escape||Tn).source+"|"+h.source+"|"+(h===pn?Cn:Tn).source+"|"+(e.evaluate||Tn).source+"|$","g"),p=Dn.call(e,"sourceURL")?"//# sourceURL="+(e.sourceURL+"").replace(/\s/g," ")+"\n":"";t.replace(u,function(e,n,i,o,a,c){return i||(i=o),d+=t.slice(l,c).replace(Pn,un),n&&(r=!0,d+="' +\n__e("+n+") +\n'"),a&&(s=!0,d+="';\n"+a+";\n__p += '"),i&&(d+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),l=c+e.length,e}),d+="';\n";var f=Dn.call(e,"variable")&&e.variable;if(f){if(En.test(f))throw new Error("Invalid `variable` option passed into `_.template`")}else d="with (obj) {\n"+d+"\n}\n";d=(s?d.replace(Sn,""):d).replace(kn,"$1").replace(An,"$1;"),d="function("+(f||"obj")+") {\n"+(f?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(r?", __e = _.escape":"")+(s?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+d+"return __p\n}";var g=on(function(){return Function(a,p+"return "+d).apply(void 0,c)});if(g.source=d,sn(g))throw g;return g},cc.buildSubstitutor=Rs,["rotatePoint","font","lineHeight","retention"].forEach(t=>cc.memoize(cc.prototype,t,!1)),["bounds","center","textBounds"].forEach(t=>cc.memoize(cc.prototype,t,!0));class lc extends cc{set rotationX(t){this.setState("rotationX",t)}get rotationX(){return this.getState("rotationX")}set rotationY(t){this.setState("rotationY",t)}get rotationY(){return this.getState("rotationY")}set rotationZ(t){this.setState("rotation",t)}get rotationZ(){return this.getState("rotation")}set zPos(t){this.setState("zPos",t)}get zPos(){return this.getState("zPos")}set depth(t){this.setState("depth",t)}get depth(){return this.getState("depth")}postrender(t){this.drawFill(t,void 0),this.drawStroke(t,void 0),super.postrender(t)}render(t){const e=this.drawPath,{round:n=0}=this.state;if(!(e.length<=1)){t.beginPath();for(let i=0;i<e.length;i++){const r=e[(i-1+e.length)%e.length],s=e[(i+e.length)%e.length],o=e[(i+1)%e.length];if(r.x===s.x&&r.y===s.y)continue;let a=Math.sqrt((r.x-s.x)*(r.x-s.x)+(r.y-s.y)*(r.y-s.y)),c=0!==a?Math.atan2(r.x-s.x,r.y-s.y):0,l=Math.sin(c)*Math.min(n,a/2)+s.x,h=Math.cos(c)*Math.min(n,a/2)+s.y;const d=n>0||0!==a?{x:l,y:h}:s;a=Math.sqrt((o.x-s.x)*(o.x-s.x)+(o.y-s.y)*(o.y-s.y)),c=0!==a?Math.atan2(o.x-s.x,o.y-s.y):0,l=Math.sin(c)*Math.min(n,a/2)+s.x,h=Math.cos(c)*Math.min(n,a/2)+s.y;const u=n>0||0!==a?{x:l,y:h}:s;0==i?t.moveTo(d.x,d.y):t.lineTo(d.x,d.y),n>0&&t.quadraticCurveTo(s.x,s.y,u.x,u.y)}t.closePath()}}}function hc(t,e,n){return Math.max(0,Math.min(t,Math.min(n,e)/2))}function dc(t){const e=class extends t{contains(t,e){const{left:n,top:i,width:r,height:s,lineWidth:o=0}=this.state,a=o/2;return t<Math.max(n+r,n)+a&&t>Math.min(n+r,n)-a&&e<Math.max(i+s,i)+a&&e>Math.min(i+s,i)-a}set path(t){const e=t[0],n=t[2];this.set({left:e.x,top:e.y,width:n.x-e.x,height:n.y-e.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get anchors(){return function(t){const{left:e,top:n,width:i,height:r}=t.bounds,s=e+i/2,o=n+r/2;return[{name:"TOP",position:{x:s,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:s,y:n+r}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){this.set({left:0,top:0,width:0,height:0,...t})}render(t){let{round:e=0}=this.model;const{left:n,top:i,width:r,height:s}=this.bounds;t.translate(n,i),t.beginPath(),e=hc(e,r,s),e>0?t.roundRect(0,0,r,s,e):t.rect(0,0,r,s),t.translate(-n,-i)}};return Zi(e.prototype,"path",!1),Zi(e.prototype,"bounds",!0),e}const uc={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"textarea",label:"front-side-template",name:"frontSideTemplate",property:{language:"html"}},{type:"textarea",label:"back-side-template",name:"backSideTemplate",property:{language:"html"}},{type:"textarea",label:"style",name:"style",property:{language:"css"}}],help:"scene/component/info-window"};const pc=20;function fc(t,e){const n=t.split(/\s+/),i=n.indexOf(e);return-1!=i?n.splice(i,1):n.splice(-1,0,e),n.join(" ")}class gc extends(dc(lc)){static get image(){return gc._image||(gc._image=new Image,gc._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAY1BMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIAbxiAAAAIHRSTlMA+gPshCwwWFzYCeLRm7QRG6rLeDZI9JOJJDtjb1HAf1sAT80AAAQQSURBVHhe7MCBAAAAAMKw/KkzOMG2BAAAAKeu3lUohIEggO7jQi5qHqpgwML5/6+0F0y02z31FlvMMLKt86QMQ1ined2Evih1hFFjLfRWjgzDOGZ6JSiM00B9EuHALtQxJLiQBmqSBCeSUEuEGzs1BDjSaHxWOKK5Eyz/4SoMV/hp4+vtcPkdwZD/udwevNg7t1xXYRiKmkB7C+ENlPLq8fxHeX+RGjWQ1D45ldcIulBIvCvYJGBEadyTzxAcfY57NBjpLScOO/bzugcTHe7IMwiSLMcdHZhocMcMgTLjjgZM7F1bCJZ2v27ARGzYDwIk2Z+JYGJ/iiwQLMv+JAEThjkmRG64Q0Q+gIiIiIiIiIiIyFy0KRFt0bOJZAWSUigmkQaJaXhENiRnYBEpkZySRSRGcmIWEaQnYhHRSI5mESmQnIJFZIqQmGhiEYEbEnPjGlEGjYTogW/WUkOXENENSqZfEXmDiIiIiIiIiIiIiIiIiIiImq5ETIpRpBpjJCMeKy6Ri0ZS9MQjkmkkJs1YRDokp2MRyZGclkUkQnIiEQltaX3Lzb6yiGTpl2y/avqSAxGgelCOKI+Kc2isL0TUSsZ4EREREREREREREREREREREfnIQzXrNWSRTeNxnlOwIgueIr6AAyE+CpiqMEUK71IDO4E+LluEKYKnKcMUifEsTZgiJZ5lDVNkwJPcqzBFoPF/HplfxL/w6b4EPGv1h18Weya1TL8iIiIeiIiIiIiIiEjkPefxV+5YA9PPHylB+u5aqgZ39H+jKOxrqtu+pkzvr9YbzoZ6w2OFkzcrA3yE4WZlSSyFk54VoA/wR43+FaD+r9w32QdWvgvjp2ty2xq8qHPHmtyPFxfrK3hw1ejERlAlfR/Ame2OTow05d4rOLLSlHtDVhI0uRO01JeZ405op6zgNNXT+bIRfpIgn+AkU4pOxBscohojdCHu4RRzjC5EYwVHqRONDkSnEvK/CB3QSU32IRW3ZPnj9iEVoGCNTLVrh8ia1x+6wq8xvB5mz8pxu7oPwIn9lcR0AiuX1+1KX+BXqdvXzWsAC0NsGjzZsS/2Bd6yRA5RgIHkXNhSD3whASZ8rrB9mItuEAizac0fDlHxDMEwpQfD1tW4y3Hjfy5s9nOHH3uwWA+EqEJBWCjoTL/S5toBB/7hu6zer74NgqSP39zJU+qQX3ix763mHTqvIVRUVprCljlElRkEjBqNYevH8veBJ2xhiyhE8YctmhDFH7ZoQhR/2KIJUfxhiyRE8YctmhDFH7ZoQhR/2OIJUfxhC9Ppf/t1jgJACERRsHGyYRZB0Ujvf0xD8w6kP7y6RZmgf/oTFTtbbzJVxZWo2Nlqw6TVy5GowNl6ssm7v50obamfSxQAAAAAAAsKLM15fb3vpQAAAABJRU5ErkJggg=="),gc._image}static toggle(t,e,n,i){if(!e)return void $i("InfoWindow not defined.");const r=t.root.findById(e);r?r._findInfoWindowByComponent(t)?gc.hide(t,e):gc.show(t,e,n,i):$i("InfoWindow Not Found.",e)}static hide(t,e){if(!e)return;const n=t.root.findById(e);n?n._removeInfoWindow(t):$i("InfoWindow Not Found.",e)}static show(e,n,i,r){if(!n)return void $i("InfoWindow not defined.");const s=e.root.findById(n);if(!s)return void $i("InfoWindow Not Found.",n);if(s._findInfoWindowByComponent(e))return;const{frontSideTemplate:o="",backSideTemplate:a=""}=s.model;let c=[o,a].filter(t=>String(t).trim());if(c=c.map(t=>cc.template(function(t,e,n){return(e||n?['<div class="info-window-btns">',e?'<button class="closable">&#88</button>':"",n?'<button class="flipable">&#8652</button>':"","</div>"]:[]).concat(['<div class="info-window-content">',t,"</div>"]).join("")}(t,!i,2==c.length))),0==c.length)return;const l='\n.flip {\n backface-visibility: hidden;\n border-radius: 7px;\n height: auto;\n font: normal 14px helvetica, arial, san serif;\n position: absolute;\n opacity: 0.9;\n transform-origin: 50% 50% 0px;\n transition: all 2s;\n min-width: 100px;\n min-height: 50px;\n background-color: #3e424e;\n box-shadow: 2px 3px 2px 0px rgba(0,0,0,0.15);\n}\n\n#side-1 {\n transform: rotateY(0deg);\n}\n\n.flip:after {\n content: "";\n display: block;\n position: absolute;\n opacity: 0.9;\n width: 0;\n height: 0;\n}\n\n.flip.arrow-top:after {\n left: 45%;\n top: -17px;\n border-left: 10px solid transparent;\n border-bottom: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-right:after {\n left: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-left: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n.flip.arrow-bottom:after {\n left: 45%;\n top: 100%;\n border-left: 10px solid transparent;\n border-top: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-left:after {\n right: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-right: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n#side-2 {\n transform: rotateY(180deg);\n}\n\n.flip-side-1 {\n transform: rotateY(0deg) !important;\n}\n\n.flip-side-2 {\n transform: rotateY(180deg) !important;\n}\n\n.info-window-btns {\n position: absolute;\n top: -18px;\n right: 5px;\n overflow: hidden;\n}\n\n.info-window-content {\n padding: 10px;\n color: #efefef;\n font-size: 13px;\n line-height: 1.4;\n}\n\n.info-window-btns button {\n width: 40px;\n height: 40px;\n float: right;\n border: 0;\n border-radius: 50%;\n background-color: #2a7da1;\n margin-right: 3px;\n text-align: center;\n cursor: pointer;\n font-size: 35px;\n color: #fff;\n line-height: 0;\n}\n\n.info-window-btns button:hover {\n background-color: #60bb23;\n}\n'+s.get("style");let{left:h,top:d}=e.bounds;const{x:u,y:p}=r?e.rootModel.toLocal(r.x,r.y):e.toScene(h,d);h=u,d=p;const f=document.createElement("span");f.style.position="absolute";const g=document.createElement("style");let m,y;g.type="text/css",g.appendChild(document.createTextNode(l)),f.appendChild(g),c[0]&&(m=document.createElement("div"),m.id="side-1",m.className="flip",m.style.display="inline-block",m.innerHTML=t.sanitize(c[0](e),{ADD_TAGS:["style"],ADD_ATTR:["class","id","style"]})),c[1]&&(y=document.createElement("div"),y.id="side-2",y.className="flip",y.style.display="inline-block",y.innerHTML=t.sanitize(c[1](e),{ADD_TAGS:["style"],ADD_ATTR:["class","id","style"]}));const b=e.rootModel.getOverlay(e);m&&f.appendChild(m),y&&f.appendChild(y),b.appendChild(f);const v=s._addInfoWindow(e,f,g).signal;if(Yr.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),Vr.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),m){const t=m.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=fc(y.className,"flip-side-1"),m.className=fc(m.className,"flip-side-2")},{signal:v});const i=m.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),gc.hide(e,n)},{signal:v})}if(y){const t=y.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=fc(y.className,"flip-side-1"),m.className=fc(m.className,"flip-side-2")},{signal:v});const i=y.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),gc.hide(e,n)},{signal:v})}const _=m.offsetWidth,x=m.offsetHeight,w=e.rootModel.target.getBoundingClientRect(),M=[];m&&M.push(m),y&&M.push(y);const S={x:h,y:d};let k=e.toGlobal(S.x,S.y);if(k.x+_/2+w.left<w.right&&k.x-_/2>w.left){if(x+pc<k.y)return f.style.marginLeft=S.x-_/2+"px",f.style.marginTop=S.y-x-pc+"px",void M.forEach(t=>t.className+=" arrow-bottom");if(k=e.toGlobal(S.x,S.y+x+pc),w.bottom>k.y+w.top)return f.style.marginLeft=S.x-_/2+"px",f.style.marginTop=S.y+pc+"px",void M.forEach(t=>t.className+=" arrow-top")}if(k=e.toGlobal(S.x,S.y),k.x-(_+pc)>w.left)return f.style.marginLeft=S.x-_-pc+"px",f.style.marginTop=S.y-x/2+"px",void M.forEach(t=>t.className+=" arrow-right");f.style.marginLeft=S.x+pc+"px",f.style.marginTop=S.y-x/2+"px",M.forEach(t=>t.className+=" arrow-left")}dispose(){this.infoWindows.map(t=>t.component).forEach(t=>this._removeInfoWindow(t)),super.dispose()}get infoWindows(){return this._windows||(this._windows=[]),this._windows}_findInfoWindowByComponent(t){return this.infoWindows.find(e=>e.component===t)}_addInfoWindow(t,e,n){if(this._findInfoWindowByComponent(t))return;const i=new AbortController;return this._windows.push({component:t,window:e,styleElement:n,abortController:i}),i}_removeInfoWindow(t){const e=this._findInfoWindowByComponent(t);if(!e)return;e.abortController.abort();const n=e.window;n&&n.parentNode.removeChild(n);const i=this.infoWindows.lastIndexOf(e);this.infoWindows.splice(i,1)}render(t){const{left:e,top:n,width:i,height:r}=this.bounds;t.beginPath(),this.drawImage(t,gc.image,e,n,i,r)}get hasTextProperty(){return!1}get nature(){return uc}}cc.register("info-window",gc);const mc={};var yc={list:function(){return{...mc}},register:function(t,e){mc[t]=e},unregister:function(t){delete mc[t]},get:function(t){if(!t)return;const e=mc[t];return e||Ki("Layout Not Found - ",t),e}};const bc=new class{constructor(){this.ABSOLUTE=!0}reflow(t,e){this.drawables(t).filter(t=>t.isHTMLElement()).forEach(t=>t.reposition())}capturables(t){return t.components}drawables(t){return t.app&&!t.app.isViewMode?t.components:t.components.filter(t=>!t.hidden)}isStuck(t){return!1}};yc.register("html-absolute",bc);const vc=new class{constructor(){this.ABSOLUTE=!0}reflow(t,e){}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!1}};function _c(t){const e=t.components.filter(t=>!t.hidden),n=t.getState("layoutConfig")||{},i=e[n&&n.activeIndex||0];return i&&[i]||[]}yc.register("absolute",vc);const xc=new class{reflow(t){const e=t.bounds,n=t.getState("layoutConfig")||{},i={left:0,top:0,width:e.width,height:e.height};t.forEach((t,e)=>{const r=e!=(n.activeIndex||0);t.bounds=i,t.setState("rotation",0),"element"in t&&t.element&&(t.element.style.visibility=r?"hidden":"visible")})}capturables(t){return _c(t)}drawables(t){return _c(t)}isStuck(t){return!0}};function wc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}yc.register("card",xc);const Mc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+wc(e),0),r=t.bounds,s=i>0?(r.width-((n.left||0)+(n.right||0)))/i:r.width,o=r.height-((n.top||0)+(n.bottom||0));let a=0;e.forEach(t=>{const e=wc(t),i=t.getState("margin")||{};t.bounds={left:s*a+(n.left||0)+(i.left||0),top:0+(n.top||0)+(i.top||0),width:e*s-((i.left||0)+(i.right||0)),height:o-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};function Sc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}yc.register("linear-horizontal",Mc);const kc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+Sc(e),0),r=t.bounds,s=i>0?(r.height-((n.top||0)+(n.bottom||0)))/i:r.height,o=r.width-((n.left||0)+(n.right||0));let a=0;e.forEach(t=>{const e=Sc(t),i=t.getState("margin")||{};t.bounds={left:0+(n.left||0)+(i.left||0),top:s*a+(n.top||0)+(i.top||0),width:o-((i.left||0)+(i.right||0)),height:e*s-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};yc.register("linear-vertical",kc);const Ac=new class{constructor(){this.joinType=!0}reflow(t){const e=t.getState("layoutConfig"),n=e&&e.columns||t.getState("columns"),i=e&&e.rows||t.getState("rows"),r=e&&e.widths||t.getState("widths"),s=e&&e.heights||t.getState("heights"),o=r?r.filter((t,e)=>e<n).reduce((t,e)=>t+e,0):n,a=s?s.filter((t,e)=>e<i).reduce((t,e)=>t+e,0):i,c=t.textBounds,l=t.getState("paddingLeft")||0,h=t.getState("paddingTop")||0,d=c.width/o,u=c.height/a;let p=0,f=0;t.components.forEach((t,e)=>{const i=r?r[e%n]:1,o=s?s[Math.floor(e/n)]:1;let a=t.colspan||1,c=0;for(;--a>0;)c+=r?r[(e+a)%n]:1;let g=t.rowspan||1,m=0;for(;--g>0;)m+=s?s[Math.floor(e/n)+g]:1;t.bounds={left:l+p,top:h+f,width:d*(i+c),height:u*(o+m)},t.setState("rotation",0),e%n==n-1?(p=0,f+=o*u):p+=i*d})}capturables(t){return t.components.filter(t=>!t.merged)}drawables(t){return t.components.filter(t=>!t.merged&&!t.hidden)}isStuck(t){return!0}keyNavigate(t,e,n){const i=t.getState("layoutConfig"),r=i&&i.columns||t.getState("columns"),s=i&&i.rows||t.getState("rows"),{row:o,column:a}=t.getRowColumn(e);switch(n.code){case"ArrowUp":if(o>0)return t.getAt?.((o-1)*r+a);break;case"ArrowDown":if(o<s-1)return t.getAt?.((o+1)*r+a);break;case"ArrowRight":if(a<r-1)return t.getAt?.(o*r+a+1);break;case"ArrowLeft":if(a>0)return t.getAt?.(o*r+a-1);break;default:return e}}};yc.register("table",Ac);const Ec=20;function Cc(t,e="static",n,i,r,s,o={}){const{title:a="",gap:c=Ec}=o;if("auto"===n){const{x:e,y:n}=function(t,e,n,i="",r=Ec){const s=Math.max(e.width/4-n.width/2,r),o=Math.min(3*e.width/4+n.width/2,e.width-r)-n.width,a=Math.max(e.height/4-n.height/2,r),c=Math.min(3*e.height/4+n.height/2,e.height-r)-n.height+(i?-30:0);return{x:t.x<e.width/2?Math.min(o,t.x+20):Math.max(s,t.x-(n.width+20)),y:t.y<e.height/2?Math.min(c,t.y+20+(i?30:0)):Math.max(a,t.y-(n.height+20))}}(i,r,s,a,c);Object.assign(t.style,{position:"absolute",left:`${e}px`,top:`${n}px`})}else"static"===e?function(t,e,n,i,r){const s=t.style,o=e.includes("left")?r:e.includes("right")?n.width-i.width-r:n.width/2-i.width/2,a=e.includes("top")?r:e.includes("bottom")?n.height-i.height-r:n.height/2-i.height/2;Object.assign(s,{left:`${o}px`,top:`${a}px`})}(t,n,r,s,c):function(t,e,n=Ec){const i=t.style;switch(Object.assign(i,{position:"absolute",left:"",right:"",top:"",bottom:"",transform:""}),e){case"center-middle":default:Object.assign(i,{left:"50%",top:"50%",transform:"translate(-50%, -50%)"});break;case"center-top":Object.assign(i,{left:"50%",top:`${n}px`,transform:"translateX(-50%)"});break;case"center-bottom":Object.assign(i,{left:"50%",bottom:`${n}px`,transform:"translateX(-50%)"});break;case"left-middle":Object.assign(i,{left:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"right-middle":Object.assign(i,{right:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"left-top":Object.assign(i,{left:`${n}px`,top:`${n}px`});break;case"right-top":Object.assign(i,{right:`${n}px`,top:`${n}px`});break;case"left-bottom":Object.assign(i,{left:`${n}px`,bottom:`${n}px`});break;case"right-bottom":Object.assign(i,{right:`${n}px`,bottom:`${n}px`})}}(t,n,c)}function Tc(t,e,n={sx:1,sy:1}){let i,r,s=0,o=0,a=!1;const c=/translate\(([-\d.]+)px,\s*([-\d.]+)px\)/;function l(){const e=(t.style.transform||"").match(c);return{x:e?parseFloat(e[1]):0,y:e?parseFloat(e[2]):0}}function h(t,e){a=!0;const n=l();s=n.x,o=n.y,i=t,r=e}function d(e,c){if(!a)return;const l=e-i,h=c-r,{sx:d,sy:u}=n;!function(e,n){t.style.transform=`translate(${e}px, ${n}px)`}(s+l/d,o+h/u)}function u(){const t=l();s=t.x,o=t.y,a=!1}e?.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),h(t.clientX,t.clientY);const e=t=>{t.preventDefault(),d(t.clientX,t.clientY)},n=t=>{t.preventDefault(),u(),window.removeEventListener("mousemove",e,!0),window.removeEventListener("mouseup",n,!0)};window.addEventListener("mousemove",e,!0),window.addEventListener("mouseup",n,!0)}),e?.addEventListener("touchstart",t=>{if(1!==t.touches.length)return;t.preventDefault(),t.stopPropagation(),h(t.touches[0].clientX,t.touches[0].clientY);const e=t=>{1===t.touches.length&&(t.preventDefault(),d(t.touches[0].clientX,t.touches[0].clientY))},n=t=>{u(),window.removeEventListener("touchmove",e,!0),window.removeEventListener("touchend",n,!0),window.removeEventListener("touchcancel",n,!0)};window.addEventListener("touchmove",e,!0),window.addEventListener("touchend",n,!0),window.addEventListener("touchcancel",n,!0)})}const Pc=["run","goto","goto-playlist","link-open","link-move","route-page","start-scenario","run-scenario","export-data","import-data"];function Dc(t,e){const n=document.createElement("button");return n.className=t,n.textContent=e,n}const Oc=new WeakMap;function zc(t){const e=t.root,n=Oc.get(e);if(!n)return;if(e===t)return n.forEach(t=>zc(t[0])),void Oc.delete(e);const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const r=n[i][1];cancelAnimationFrame(r.rafId),r.ac.abort(),r.div.parentNode?.removeChild(r.div),r.scene.target=null,r.scene.release?.(),n.splice(i,1)}class Ic{static hideAll(t){(Oc.get(t)||[]).forEach(([t])=>zc(t))}static hide(t){const e=t.root,n=Oc.get(e);if(!n)return;const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const r=n[i][1];r.div.style.backgroundColor="transparent",r.rafId=function(t,e,n){t.style.opacity="1";const i=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();t.style.transform=`${i} scale(1)`;let r=0;const s=Date.now(),o=()=>{if(n?.aborted)return;const a=Math.min((Date.now()-s)/200,1);t.style.opacity=String(1-a),t.style.transform=`${i} scale(${1-a})`.trim(),a<1?r=requestAnimationFrame(o):(t.style.display="none",e&&e())};return r=requestAnimationFrame(o),r}(r.div,()=>{zc(t)},r.ac.signal)}static show(t,e,n={}){const{data:i,modal:r=!1,closable:s=!0,minimizable:o=!1,draggable:a=!1,output:c=!0,popupPosition:l="static",origin:h="center-middle",title:d="",threed:u=!1}=n,p=t.app?.refProvider,f=!l||"static"===l;p?.get(e,!0).then(e=>{const n=document.createElement("div");n.setAttribute("popup",""),"absolute"==l&&(n.style.zIndex="100");const p=n.style;if(r){const{width:e,height:n}=f?t.rootModel.bounds:t.rootModel.auxOverlay.getBoundingClientRect();Object.assign(p,{position:"absolute",zIndex:"100",left:0,top:0,width:f?`${e}px`:"100%",height:f?`${n}px`:"100%",overflow:"hidden",backgroundColor:"transparent"})}else Object.assign(p,{position:"absolute",display:"inline-block"});n.appendChild(function(t){const e=document.createDocumentFragment(),n=document.createElement("div");n.className="popup-wrap";const i=document.createElement("div");if(i.className="popup-translate",t){const t=document.createElement("div");t.className="popup-title-bar";const e=document.createElement("div");e.className="popup-title",t.appendChild(e);const n=document.createElement("div");n.className="popup-buttons-wrap",n.appendChild(Dc("closable","close")),n.appendChild(Dc("minimizable","minimize")),n.appendChild(Dc("draggable","drag_pan")),t.appendChild(n),i.appendChild(t)}else{const t=document.createElement("div");t.className="popup-buttons-wrap float-right",t.appendChild(Dc("closable","close")),t.appendChild(Dc("minimizable","minimize")),t.appendChild(Dc("draggable","drag_pan")),i.appendChild(t)}const r=document.createElement("div");return r.className="popup-content",i.appendChild(r),n.appendChild(i),e.appendChild(n),e}(!!d));const g=n.querySelector(".popup-content"),{width:m,height:y}=e.root.model;Object.assign(g.style,{width:`${m}px`,height:`${y}px`});const b=document.createElement("style");b.appendChild(document.createTextNode("\n\n.popup-wrap .popup-translate {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n min-width: 120px;\n overflow: hidden;\n transition: height 0.5s ease;\n}\n\n.popup-wrap .popup-translate > * {\n pointer-events: auto;\n}\n\n.popup-wrap .popup-content {\n background-color: var(--md-sys-color-surface, white);\n}\n\n.popup-wrap .popup-title-bar {\n display: flex;\n align-items: center;\n top: 0;\n left: 0;\n width: 100%;\n height: 30px;\n background-color: var(--md-sys-color-primary, #f1f1f1);\n color: var(--md-sys-color-on-primary, black);\n padding: 5px;\n box-sizing: border-box;\n border-bottom: 1px solid #ccc;\n}\n\n.popup-wrap .popup-title {\n flex: 1;\n text-align: center;\n}\n\n.popup-wrap .popup-buttons-wrap {\n position: relative;\n display: flex;\n flex-direction: row-reverse;\n gap: 4px;\n min-width: 100px;\n align-items: center;\n justify-items: center;\n margin: 0;\n padding: 0;\n}\n\n.popup-wrap .popup-buttons-wrap.float-right {\n position: absolute;\n right: 0;\n top: 0;\n height: 30px;\n margin-right: 5px;\n}\n\n.popup-wrap button.closable, \n.popup-wrap button.minimizable, \n.popup-wrap button.draggable {\n display: none;\n color: white; \n background-color: black; \n opacity: .3;\n width: 20px;\n height: 20px;\n top: 5px; \n z-index: 1;\n padding: 0;\n margin: 0;\n border: 0px;\n text-align: center;\n cursor: pointer;\n border-radius: 4px;\n font-family: Material Symbols Outlined;\n font-size: 16px;\n}\n\n.popup-wrap button.draggable {\n cursor: move;\n}\n\n.popup-wrap button.closable:hover, \n.popup-wrap button.minimizable:hover, \n.popup-wrap button.draggable:hover {\n opacity: .6; \n}\n")),n.appendChild(b),Pc.forEach(n=>{e.on(n,(...e)=>{t.trigger(n,...e)})});const v=new AbortController,_=v.signal,x=n.querySelector(".draggable");[...Yr,...Vr].forEach(t=>{g.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),[...Yr,...Vr].forEach(t=>{n.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),r&&s&&n.addEventListener("click",e=>{e.target===n&&Ic.hide(t)},{signal:_});const w=t.rootModel.getOverlay?.({...t,scalable:!l||"static"==l});w?.appendChild(n),function(t,e,n,i,r){const s=t.root;if(s===t)return;zc(t);let o=Oc.get(s)||[];o=[...o,[t,{div:e,scene:n,ac:i,rafId:r}]],Oc.set(s,o)}(t,n,e,v,0);const M=Oc.get(t.root)?.find(e=>e[0]===t)?.[1];if(d){const t=n.querySelector(".popup-title-bar .popup-title");t&&(t.textContent=d)}const S=n.querySelector(".popup-translate");if(a&&(Tc(S,d?n.querySelector(".popup-title-bar"):n.querySelector(".draggable"),function(t,e){if(!(e=e||t.position)||"static"===e){const e=(t.rootModel.getOverlay(t).style.transform||"").match(/scale\(([^,\s)]+)(?:,\s*([^)]+))?\)/),n=e?parseFloat(e[1]):1;return{sx:n,sy:e&&e[2]?parseFloat(e[2]):n}}return{sx:1,sy:1}}(t,l)),d?x&&(x.style.display="block"):(S?.addEventListener("mouseenter",()=>{x&&(x.style.display="block")},{signal:_}),S?.addEventListener("mouseleave",()=>{x&&(x.style.display="none")},{signal:_}))),o){const t=n.querySelector(".minimizable");let e=!1;t.addEventListener("click",t=>{t.preventDefault(),e=!e;const i=n.querySelector(".popup-wrap");!function(t,e,n){const i=e.querySelector(".minimizable"),r=e.querySelector(".popup-translate");r&&(n?(i.textContent="crop_square",r.style.height="30px"):(i.textContent="minimize",r.style.height="100%"))}(0,r?i:n,e)},{signal:_}),d?t&&(t.style.display="block"):(S?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:_}),S?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:_}))}if(s){const t=n.querySelector(".closable");d?t&&(t.style.display="block"):(S?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:_}),S?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:_}))}n.querySelector(".closable")?.addEventListener("click",e=>{e.preventDefault(),Ic.hide(t)},{signal:_}),n.addEventListener("close-scene",e=>{e.preventDefault(),e.stopPropagation(),Ic.hide(t),c&&(t.data=e.detail)},{signal:_}),e.target=g,e.data=i||t.data,e.fit("both"),u&&(e.root.threed=!0);const{x:k,y:A}=t.center,E=t.toScene(k,A),C=r?n.querySelector(".popup-wrap"):n;Cc(C,l,h,E,e.root.bounds,{width:m,height:y},{title:d}),r?Object.assign(C.style,{position:"absolute",pointerEvents:"none",width:`${m}px`,height:`${d?y+30:y}px`}):Object.assign(C.style,{pointerEvents:"none",width:`${m}px`,height:`${d?y+30:y}px`});const T=function(t,e,n){t.style.opacity="0";const i=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();t.style.transform=`${i} scale(0)`,t.style.display="block";let r=0;const s=Date.now(),o=()=>{if(n?.aborted)return;const a=Math.min((Date.now()-s)/200,1);t.style.opacity=String(a),t.style.transform=`${i} scale(${a})`.trim(),a<1?r=requestAnimationFrame(o):e&&e()};return r=requestAnimationFrame(o),r}(n,()=>{r&&(n.style.backgroundColor="rgba(0,0,0,0.3)")},_);M&&(M.rafId=T)},t=>{Ki("cannot fetch board: "+e,t)})}}const Lc=new Image;function jc(t){return class extends t{get showMoveHandle(){return!1}postrender(t){super.postrender(t),this.app.isEditMode&&this._focused&&this.showMoveHandle&&this._draw_move_handle(t)}_draw_move_handle(t){const{left:e,top:n,width:i}=this.bounds;t.save(),t.beginPath(),t.globalAlpha=1,t.rect(e+i,n,25,25);t.fillStyle="rgba(235, 235, 235, 1)",t.fill(),t.drawImage(Lc,e+i+3.75,n+3.75,17.5,17.5),t.closePath(),t.restore()}contains(t,e){let n=super.contains(t,e);if(this.app.isViewMode)return n;if(!n){const{left:i,top:r,width:s}=this.bounds,o=i+s,a=25;this.showMoveHandle&&(n=t<Math.max(o+25,o)&&t>Math.min(o+25,o)&&e<Math.max(r+a,r)&&e>Math.min(r+a,r))}return this._focused!==n&&(this._focused=n,this.invalidate()),n}}}Lc.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAclBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0BbqFAAAAJXRSTlMAgAP3VSI6/g9fBk5FavJsMrariSjzPnO1enRRL5SMhmOOWB9keFTE0wAAANxJREFUOMutk9kWgyAMRLFuiLjUtdp9yf//YglVsQXz1HniMPcEMgHGvpX2O0Ypi+EgCL+IAShC+wB7QfubRDT7AFcnUPoLMLiP4PyJbsb55i05AgnR5iaQDsICgtH0cotBWoAP1c7kC6kFxEseCfZfB6gEgbNeBrira2QmH1uVYCXlA3is8UmgUCPIyQJKEmu8QtQJN0e9DPXVpzG2G216c1CqRmcBOdxXk07sWUSPv07zo0amCNQycv+NzmR6cRcwmfbuI7p2nZ/z4be0P83Foz6vIkhfZXr82XgDlZsspIq4peUAAAAASUVORK5CYII=";const Rc=[];class Fc extends(jc(dc(cc))){constructor(t,e){super(t,e),this._components=[]}replaceRefids(t){this.components.forEach(e=>e.replaceRefids(t))}get showMoveHandle(){return!0}get showOverflow(){return!1}dispose(){this.components.slice().forEach(t=>t.dispose()),super.dispose()}isContainer(){return!0}containable(t){return t.isDescendible(this)}get hasTextProperty(){return!1}get components(){return this._components}get focusible(){return!0}get layout(){return yc.get(this.get("layout"))||vc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){if(!t)return;const{animated:n=!1,duration:i=2e3,ease:r="inout"}=e,s=t.parent;if(!s||s===this)return;const o=t=>{let e=0,n=t;for(;n&&!n.isRootModel?.();)e+=n.state?.rotation||0,n=n.parent;return e},a=!(!t._realObject?.object3d||!this._realObject?.object3d);let c=null,l=null,h=null,d=null;if(a){const e=this._realObject.object3d,n=t._realObject.object3d,i=t._realObject.dimension||{width:1,height:1,depth:1};e.updateWorldMatrix(!0,!1),n.updateWorldMatrix(!0,!1),e.attach(n),c={pos:n.position.clone(),quat:n.quaternion.clone(),fromDimW:i.width||1,fromDimH:i.height||1,fromDimD:i.depth||1},t._realObject.suppressTransform=!0}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);h={x:i.x,y:i.y,rotation:o(s),width:e.width,height:e.height}}if(this.addComponent(t,{silent:!0}),a){const e=t._realObject.object3d;t.clearCache();const n=t._realObject.position,i=t._realObject.rotation,r=t._realObject.dimension||{width:1,height:1,depth:1},s=r.width||1,o=r.height||1,a=r.depth||1,h={x:c.fromDimW/s,y:c.fromDimH/o,z:c.fromDimD/a};l={pos:e.position.clone().set(n.x,n.y,n.z),quat:e.quaternion.clone().setFromEuler(e.rotation.clone().set(i.x,i.y,i.z))},c.fromScale=h,c.toScale={x:1,y:1,z:1},e.position.copy(c.pos),e.quaternion.copy(c.quat)}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);d={x:i.x,y:i.y,rotation:o(this),width:e.width,height:e.height}}if(n){const e=this.root?.transitionEffect;e&&e.begin(t,{fromWorld:h,toWorld:d,from3D:c,to3D:l,duration:i,ease:r})}}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,r=t.parent;if(r){if(this===r)return;r.removeComponent(t,n||i)}const s=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,s),t.delegate_on(this),i?(r&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,s),t.trigger("added",this,t,s),delete t._silentAdd):n||t.trigger("added",this,t,s),this.root&&this.root.isReady&&t.ready()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const r=this._components.splice(0,e);this._components=r.concat(t,this._components),e=this._components.indexOf(t),t.parent=this,t.added(this),n||this.trigger("add",this,t,e),t.delegate_on(this),n||t.trigger("added",this,t,e)}add(t,e=!1){return t instanceof Array?(t.forEach(t=>{-1==this._components.indexOf(t)&&this.addComponent(t,e)}),this):this.add.call(this,[t],e)}remove(t,e=!1){return t instanceof Array?this._components?(t.forEach(t=>{this.removeComponent(t,e)}),this):this:this.remove.call(this,[t],e)}getAt(t){if(this._components)return this._components[t]}forEach(t,e){this._components&&this._components.forEach(t,e)}traverse(t,e){t.call(e,this),this._components&&this._components.forEach(n=>{n.isContainer()?n.traverse(t,e):t.call(e,n)})}indexOf(t){return(this._components||Rc).indexOf(t)}size(){return(this._components||Rc).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const r=this._components.splice(1);this._components=i.concat(r),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return La(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const r=this.components[i].findAll(t,...e);r&&(n=n.concat(r))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return La(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}contains(t,e){let n=super.contains(t,e);if(!n){const{left:i,top:r,width:s,height:o}=this.state;n=t<Math.max(i+s,i)&&t>Math.min(i+s,i)&&e<Math.max(r+o,r)&&e>Math.min(r+o,r)}return n}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const r=this.bounds;i.x-=r.left,i.y-=r.top;const s=this.layout.capturables(this);for(let r=s.length-1;r>=0;r--){const o=s[r];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:r,width:s,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+s||a.y<r||a.y>r+o)return!1;a.x-=i,a.y-=r,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const r=i.capturePath(n,e);if(r)return r}return this.focusible&&this}render(t){const{left:e=0,top:n=0,width:i,height:r}=this.bounds;t.beginPath(),t.rect(e,n,i,r),t.closePath(),this.drawFill(t),this.drawStroke(t)}postrender(t){const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:r,height:s}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,r,s),t.clip(),t.closePath()),({top:i,left:n}=this.state),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)?n.renderComponent(e,this.root?.model_layer):e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>cc.memoize(Fc.prototype,t,!1));class Bc extends Fc{constructor(t,e){super(t,e),this._element=null,this._firstDrawReported=!1,t.translate=t.translate||{x:0,y:0},this._draw_reserved=!1,this.__draw__=()=>{this._draw_reserved=!1;const t=performance.now();this.trigger("redraw"),this.reflow(),this.draw();const e=performance.now()-t;Ii.drawCount++,Ii.drawTimeSum+=e,Ii.drawTimeLast=e,Ii.countFrame(),this._firstDrawReported||(this._firstDrawReported=!0,this.app?.loadTracker?.markFirstRender())},this.throttle_render=()=>{this._draw_reserved||requestAnimationFrame(this.__draw__),this._draw_reserved=!0}}get element(){return this._element}set element(t){this._element=t}fitSize(t,e,n,i){if(this.target){if(e){const t=getComputedStyle(this.target);n=n||(t?parseFloat(t.getPropertyValue("width")):this.target.clientWidth),i=i||(t?parseFloat(t.getPropertyValue("height")):this.target.clientHeight)}else n=this.model.width,i=this.model.height;"CANVAS"==t.tagName&&(t.setAttribute("width",n*Hr),t.setAttribute("height",i*Hr)),t.style.width=n+"px",t.style.height=i+"px"}}resize(){this.fitSize(this.element,!0)}isLayer(){return!0}get showOverflow(){return this.app.isEditMode}get anchors(){}createElement(){const t=cc.createCanvas(1,1);return t.setAttribute("scene",this.state.type),t.style.position="absolute",t.style.pointerEvents=this.pointerEvents,t}get pointerEvents(){return"auto"}get target(){return this._target}set target(t){this._target&&this.element&&this._target.removeChild(this.element),this._target=t,this.element||(this.element=this.createElement()),this.resize(),t?.appendChild(this.element)}get canvas(){return this.element}dispose(){super.dispose(),this.target=null,this.element=null}get selected(){return this.root.selected||[]}set selected(t){this.root.selected=t}get hasSameParentForAllSelected(){return this.root.hasSameParentForAllSelected}get focused(){return this.root.focused}set focused(t){this.root.focused=t}get context2D(){if(!this._context2D&&(this._context2D=this.canvas&&this.canvas.getContext("2d"),this._context2D)){const t=getComputedStyle(document.documentElement),e=t.getPropertyValue("--scene-theme-font-family")?.trim()||t.fontFamily||"sans-serif";this._context2D.font=["10px",e].join(" "),this._context2D.save()}return this._context2D}getContext(t){return this._context2D||this.context2D}draw(t){this.canvas&&(t=t||this.getContext(void 0))&&(t.save(),super.draw(t),t.restore())}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:i}=this.model;t.clearRect(0,0,t.canvas.width,t.canvas.height),e&&t.translate(e.x*Hr,e.y*Hr),t.scale(n.x*Hr,n.y*Hr),i&&t.rotate(i)}get rotatePoint(){return{x:0,y:0}}contains(t,e){return!1}invalidate(){Ii.invalidateCount++,this.throttle_render()}move(t){const e=this.get("translate")||{x:0,y:0};this.set({translate:{x:e.x+t.x,y:e.y+t.y}})}centerTo(t,e){const n=t.rootModel.toLocal(this.canvas.clientWidth/2,this.canvas.clientHeight/2),{x:i,y:r}=t.center,{x:s,y:o}=t.fromParent(i,r),{x:a,y:c}=t.toScene(s,o),{x:l,y:h}=t.rootModel.get("translate"),{x:d,y:u}=t.rootModel.get("scale");e?ra({step:function(e){t.rootModel.set({translate:{x:l+(n.x-a)*d*e,y:h+(n.y-c)*u*e}})},duration:1e3,delta:"circ"}).start():t.rootModel.set({translate:{x:l+(n.x-a)*d,y:h+(n.y-c)*u}})}}class Nc extends Bc{dispose(){super.dispose(),delete this._canvas,delete this._auxCanvas}createElement(){const t=document.createElement("div");return t.style.position="absolute",t.setAttribute("scene",`${this.state.type}-anchor`),t.style["user-select"]="none",t.style.overflow="hidden",this._canvas=cc.createCanvas(1,1),this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.setAttribute("scene",`${this.state.type}-canvas`),t.appendChild(this._canvas),this._auxCanvas=cc.createCanvas(1,1),this._auxCanvas.style.position="absolute",this._auxCanvas.style.pointerEvents="none",this._auxCanvas.style.zIndex="100",this._auxCanvas.setAttribute("scene",`${this.state.type}-aux-canvas`),t.appendChild(this._auxCanvas),t}resize(){if(!this.element)return;this.fitSize(this.element,!0);const t=this.element.clientWidth,e=this.element.clientHeight;this.fitSize(this.canvas,!0,t,e),this.fitSize(this.auxCanvas,!0,t,e)}get canvas(){return this._canvas}get auxCanvas(){return this._auxCanvas}get context2D(){if(!this._context2D){this._context2D=this.canvas&&this.canvas.getContext("2d");const t=getComputedStyle(document.documentElement),e=t.getPropertyValue("--scene-theme-font-family")?.trim()||t.fontFamily||"sans-serif";this._context2D.font=["10px",e].join(" "),this._context2D.save()}return this._context2D}get auxContext2D(){if(!this._auxContext2D){this._auxContext2D=this.auxCanvas&&this.auxCanvas.getContext("2d");const t=getComputedStyle(document.documentElement),e=t.getPropertyValue("--scene-theme-font-family")?.trim()||t.fontFamily||"sans-serif";this._auxContext2D.font=["10px",e].join(" "),this._auxContext2D.save()}return this._auxContext2D}getContext(t){return t?t.scalable?this.context2D:this.auxContext2D:this.context2D}draw(t){this.canvas&&this.element&&(t=t||this.getContext(void 0))&&(this.auxContext2D.clearRect(0,0,this.auxCanvas.width,this.auxCanvas.height),this.auxContext2D.save(),this.auxContext2D.scale(Hr,Hr),super.draw(t),this.auxContext2D.restore())}}var Hc,Yc,Vc,Gc;!function(t){t.CANVAS="canvas",t.DOM="dom"}(Hc||(Hc={}));class Uc{get overlay(){return this._overlay}constructor(t,e,n={}){if(this.element=null,this.isActive=!1,this._overlay=null,this.target=e,this.options={animation:!0,repeat:!0,duration:3e3,color:"#ff0000",opacity:1,fadeOut:!1,...n},this.mode=n.mode||this.determineOptimalMode(),t){this._overlay=t;Bs.getInstance().addOverlay(t)}}determineOptimalMode(){return!1!==this.options.animation?Hc.DOM:Hc.CANVAS}start(){if(!this.isActive&&(this.isActive=!0,this.mode===Hc.DOM)){this.overlay?(this.createDOMElements(),this.target.on("change",this.handleTargetChange,this),this.target.on("removed",this.handleTargetRemoved,this)):($i("오버레이가 설정되지 않아 DOM 모드 데코레이터를 시작할 수 없습니다."),this.isActive=!1)}}stop(){this.isActive&&(this.isActive=!1,this.mode===Hc.DOM&&(this.target.off("change",this.handleTargetChange,this),this.target.off("removed",this.handleTargetRemoved,this),this.removeDOMElements()))}update(t){if(t&&(this.options={...this.options,...t},t.mode&&t.mode!==this.mode))return this.stop(),this.mode=t.mode,void this.start();this.mode===Hc.DOM&&this.isActive&&this.updateDOMElements()}render(t,e){return!(this.mode!==Hc.CANVAS||!this.isActive)&&this.renderCanvas(t,e)}removeDOMElements(){this.element&&this.element.parentNode&&(this.element.parentNode.removeChild(this.element),this.element=null)}updateDOMElements(){this.removeDOMElements(),this.createDOMElements()}getComponentPosition(){const{left:t,top:e,width:n,height:i}=this.target.bounds;if("function"==typeof this.target.toGlobal)try{const{x:r,y:s}=this.target.toGlobal(t,e,this.target.rootModel);return{x:r,y:s,width:n,height:i}}catch(t){$i("좌표 변환 실패, 기본값 사용:",t)}return{x:t,y:e,width:n,height:i}}handleTargetChange(t,e){this.target.disposed?this.stop():this.invalidate()}handleTargetRemoved(){this.stop()}invalidate(){}}function Wc(t,n,i){const r=t.rootModel;if(r?.is3dMode){const n=t._realObject?.object3d,i=r.activeCamera3d,s=r.renderer3d;if(n&&i&&s){const t=new e.Vector3;n.getWorldPosition(t);const r=t.clone().project(i),o=s.domElement;return{x:(.5*r.x+.5)*o.clientWidth,y:(.5*-r.y+.5)*o.clientHeight}}return null}const s=t.toGlobal(n,i,r);return isNaN(s.x)||isNaN(s.y)?null:s}class Xc extends Uc{constructor(t,e,n={}){super(t,e,{strokeWidth:2,strokeColor:"#FF0000",strokeOpacity:1,fillColor:"none",fillOpacity:.5,scale:1,rotation:0,x:0,y:0,zIndex:0,mode:Hc.DOM,...n}),this.vectorElement=null,this.animationElements=[],this.svgContainer=null,this.animationElement=null}getDecoratorType(){return this.constructor.DECORATOR_TYPE}dispose(){this.removeDOMElements()}determineOptimalMode(){return Hc.DOM}renderCanvas(t,e){return $i("VectorDecorator는 Canvas 렌더링을 지원하지 않습니다. DOM 모드를 사용하세요."),!1}getSvgContainer(){if(!this.overlay)throw new Error("오버레이 요소가 없습니다.");if(!Xc.svgContainerCache.has(this.overlay)){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("class","vector-decorator-container"),t.setAttribute("pointer-events","none"),t.style.overflow="visible",t.style.position="absolute",t.style.top="0",t.style.left="0",this.overlay.appendChild(t),Xc.svgContainerCache.set(this.overlay,t)}return Xc.svgContainerCache.get(this.overlay)}getOrCreateDecoratorGroup(t=!1){const e=this.getSvgContainer(),n=this.getVectorGroupId(),i=this.getDecoratorType();let r=e.querySelector(`g[data-decorator-type-container="${i}"]`);if(!r){r=document.createElementNS("http://www.w3.org/2000/svg","g"),r.setAttribute("data-decorator-type-container",i),r.setAttribute("class",`${i}-container`),e.appendChild(r);const t=document.createElementNS("http://www.w3.org/2000/svg","defs");t.setAttribute("data-defs-for",i),r.appendChild(t)}let s=r.querySelector(`g[data-decorator-group-id="${n}"]`);if(!s){const{id:t}=this.target.state;return s=document.createElementNS("http://www.w3.org/2000/svg","g"),s.setAttribute("data-decorator-group-id",n),s.setAttribute("data-decorator-type",i),t&&s.setAttribute("data-component-id",t),r.appendChild(s),s}if(t)for(;s.firstChild;)s.removeChild(s.firstChild);return s}getDefsForType(){const t=this.getSvgContainer(),e=this.getDecoratorType();let n=t.querySelector(`g[data-decorator-type-container="${e}"]`);n||(this.getOrCreateDecoratorGroup(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`));let i=n.querySelector(`defs[data-defs-for="${e}"]`);return i||(i=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.setAttribute("data-defs-for",e),n.appendChild(i)),i}getDecoratorGroup(){const t=this.getSvgContainer(),e=this.getVectorGroupId(),n=t.querySelector(`g[data-decorator-group-id="${e}"]`);if(n)return n}createFadeAnimation(t=0,e=1,n=1e3,i={}){const r=document.createElementNS("http://www.w3.org/2000/svg","animate");return r.setAttribute("attributeName","opacity"),r.setAttribute("from",t.toString()),r.setAttribute("to",e.toString()),r.setAttribute("dur",`${n}ms`),i.delay&&r.setAttribute("begin",`${i.delay}ms`),r.setAttribute("fill","freeze"),i.repeat?r.setAttribute("repeatCount","indefinite"):r.setAttribute("repeatCount","1"),r}createTranslateAnimation(t,e=[],n=1e3,i={}){const r=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return r.setAttribute("attributeName","transform"),r.setAttribute("type","translate"),r.setAttribute("values",t.join(";")),e.length>0&&r.setAttribute("keyTimes",e.join(";")),r.setAttribute("dur",`${n}ms`),i.delay&&r.setAttribute("begin",`${i.delay}ms`),i.repeat?r.setAttribute("repeatCount","indefinite"):r.setAttribute("repeatCount","1"),r}createRotateAnimation(t=0,e=360,n=0,i=0,r=1e3,s={}){const o=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return o.setAttribute("attributeName","transform"),o.setAttribute("type","rotate"),o.setAttribute("from",`${t} ${n} ${i}`),o.setAttribute("to",`${e} ${n} ${i}`),o.setAttribute("dur",`${r}ms`),s.delay&&o.setAttribute("begin",`${s.delay}ms`),s.repeat?o.setAttribute("repeatCount","indefinite"):o.setAttribute("repeatCount","1"),o}addAnimations(t,e){e.forEach(e=>{t.appendChild(e),this.animationElements.push(e)})}projectComponentPoint(t,e,n){return Wc(t,e,n)}updatePosition(){if(!this.vectorElement)return;const t=this.options,{left:e,top:n}=this.target.bounds,i=this.projectComponentPoint(this.target,e,n);if(!i)return;const r=i.x+(t.x??0),s=i.y+(t.y??0);this.vectorElement.setAttribute("transform",`translate(${r}, ${s})`)}updateDOMElements(){this.createDOMElements()}getVectorGroupId(){const t=this.getDecoratorType(),{refid:e="unknown"}=this.target.state;return`decorator-${t}-${e}`}removeVectorElements(){if(this.overlay)try{const t=Xc.svgContainerCache.get(this.overlay);if(!t)return;const e=this.getVectorGroupId(),n=this.getDecoratorType(),i=t.querySelector(`g[data-decorator-type-container="${n}"]`);if(i){const t=i.querySelector(`g[data-decorator-group-id="${e}"]`);if(t&&(this.vectorElement&&(this.vectorElement===t||t.contains(this.vectorElement))&&(this.vectorElement=null),this.animationElements=this.animationElements.filter(e=>!t.contains(e)),t.remove()),!i.querySelector("g[data-decorator-group-id]")){const t=i.querySelector(`defs[data-defs-for="${n}"]`);t&&t.remove(),i.remove()}}0===t.children.length&&(t.remove(),Xc.svgContainerCache.delete(this.overlay))}catch(t){Ki("벡터 요소 제거 실패:",t)}}removeDOMElements(){this.removeVectorElements()}delta(t,e){if("string"==typeof t)return"fade"===t?this.applyFadeValue(e):"theta"===t&&this.applyRotationValue(e),{tx:0,ty:0};if("object"==typeof t){const e=t;("tx"in e||"ty"in e)&&this.applyTranslateValues(e.tx||0,e.ty||0),("sx"in e||"sy"in e)&&this.applyScaleValues(e.sx||1,e.sy||1)}return null}invalidate(){this.mode===Hc.DOM&&this.isActive&&this.updateDOMElements()}touch(){}applyFadeValue(t){if(this.vectorElement){const e=t.toFixed(2);this.vectorElement.setAttribute("opacity",e)}}applyRotationValue(t){if(this.vectorElement){const e=this.getComponentBounds(),n=e.width/2,i=e.height/2,r=(180*t/Math.PI).toFixed(1);this.vectorElement.setAttribute("transform",`rotate(${r} ${n} ${i})`)}}applyTranslateValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("translate")){const i=n.replace(/translate\([^)]+\)/,`translate(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} translate(${t}, ${e})`.trim())}}applyScaleValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("scale")){const i=n.replace(/scale\([^)]+\)/,`scale(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} scale(${t}, ${e})`.trim())}}getComponentBounds(){return this.target&&this.target.bounds?this.target.bounds:{top:0,left:0,width:100,height:100}}}Xc.svgContainerCache=new WeakMap,Xc.DECORATOR_TYPE="vector";class qc extends Uc{constructor(t,e,n={}){super(t,e,{scale:1,strokeColor:"#000000",strokeWidth:1,rotation:0,shadow:!1,shadowColor:"rgba(0,0,0,0.5)",shadowBlur:5,shadowOffsetX:2,shadowOffsetY:2,...n}),this.animationId=null,this.canvasElement=null,this.context=null,this.animationFrame=null,this.deltaValue=0}determineOptimalMode(){return Hc.CANVAS}createDOMElements(){$i("RasterDecorator는 DOM 렌더링을 지원하지 않습니다. Canvas 모드를 사용하세요.")}setAnimationState(t=3e3,e=!1){qc.animationStateMap.set(this.target,{startTime:Date.now(),duration:t,repeat:e})}getAnimationState(){const t=qc.animationStateMap.get(this.target);if(!t)return{delta:0,finished:!0};const{startTime:e,duration:n,repeat:i}=t,r=Date.now()-e;let s=Math.min(1,r/n),o=s>=1;return i&&o&&(qc.animationStateMap.set(this.target,{startTime:Date.now(),duration:n,repeat:i}),s=0,o=!1),{delta:s,finished:o}}bounceEffect(t,e=10){const n=Math.min(1,4*t);return Math.sin(n*Math.PI*10)*e*(1-n)}fadeEffect(t,e=!1){return e?t:1-t}pulseEffect(t,e=.8,n=1.2){return e+(.5*Math.sin(t*Math.PI*2)+.5)*(n-e)}rotateEffect(t,e=360){return t*e}applyShadowEffect(t){if(this.options.shadow){const e=this.options;t.shadowColor=e.shadowColor||"rgba(0,0,0,0.5)",t.shadowBlur=e.shadowBlur||5,t.shadowOffsetX=e.shadowOffsetX||2,t.shadowOffsetY=e.shadowOffsetY||2}}removeShadowEffect(t){t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0}start(){super.start(),this.isActive&&this.options.animation&&this.setAnimationState(this.options.duration||3e3,this.options.repeat||!1)}stop(){null!==this.animationFrame&&(cancelAnimationFrame(this.animationFrame),this.animationFrame=null),super.stop(),qc.animationStateMap.delete(this.target)}applyTransform(t,e,n){const i=this.options,r=i.scale||1,s=i.rotation||0;if(1!==r||0!==s){if(t.translate(e,n),0!==s){const e=s*Math.PI/180;t.rotate(e)}1!==r&&t.scale(r,r),t.translate(-e,-n)}}delta(t,e){return"string"==typeof t?("fade"===t?(this.deltaValue=e,this.context&&(this.context.globalAlpha=e)):"theta"===t&&(this.deltaValue=e),{tx:0,ty:0}):null}invalidate(){this.context&&this.isActive&&(this.animationFrame||(this.animationFrame=requestAnimationFrame(()=>{this.animationFrame=null,this.renderCanvas(this.context,this.deltaValue)})))}touch(){this.deltaValue=0}}qc.animationStateMap=new WeakMap;class Kc extends Xc{constructor(t,e,n={}){super(t,e,{size:1,showId:!1,animation:!1,...n}),this.arrowElement=null,this.labelElement=null,this.decoratorGroup=null}createDOMElements(){if(this.overlay)try{const t=this.getOrCreateDecoratorGroup(!0);this.decoratorGroup=t,t.setAttribute("transform","translate(0, 0)");const{size:e=1,showId:n=!1,duration:i=3e3,repeat:r=!0}=this.options,s=this.options.color||"#FF0000",o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.createArrowPath(0,0,e)),o.setAttribute("fill",s),o.setAttribute("stroke",s),o.setAttribute("stroke-width","1"),o.setAttribute("class","bouncing-arrow");const a=[];if(this.options.animation){const t=this.createBounceAnimation(i,r);if(a.push(t),this.options.fadeOut){const t=this.createFadeAnimation(1,0,i,{repeat:r});a.push(t)}}if(this.addAnimations(o,a),t.appendChild(o),this.arrowElement=o,n&&this.target.state?.id){const n=this.createArrowLabel(0,0,s,this.target.state.id,e);if(this.options.animation){const t=[],e=this.createBounceAnimation(i,r);if(t.push(e),this.options.fadeOut){const e=this.createFadeAnimation(1,0,i,{repeat:r});t.push(e)}this.addAnimations(n,t)}t.appendChild(n),this.labelElement=n}this.vectorElement=t,this.updatePosition(),this.options.animation&&this.startAnimations()}catch(t){Ki("화살표 SVG 요소 생성 실패:",t)}}createArrowPath(t,e,n=1){const i=n/this.getScale();return`\n M${t-10*i},${e-16*i} \n L${t+10*i},${e-16*i} \n L${t+10*i},${e-8*i} \n L${t+16*i},${e-8*i} \n L${t},${e} \n L${t-16*i},${e-8*i} \n L${t-10*i},${e-8*i} \n Z\n `}getScale(){try{if(this.target.rootModel&&"number"==typeof this.target.rootModel.scale)return this.target.rootModel.scale||1}catch(t){$i("스케일 계산 실패, 기본값 사용",t)}return 1}createBounceAnimation(t,e){const n=["0,-10"],i=["0"];for(let t=1;t<=20;t++){const e=t/20;let r=Math.pow(e,.5).toFixed(3);parseFloat(i[i.length-1])>=parseFloat(r)&&(r=(parseFloat(i[i.length-1])+.01).toFixed(3)),n.push("0,0"),n.push("0,-10"),i.push(r),i.push((parseFloat(r)+.01).toFixed(3))}return i[i.length-1]="1.000",this.createTranslateAnimation(n,i,t,{repeat:e})}createArrowLabel(t,e,n,i,r=1){const s=document.createElementNS("http://www.w3.org/2000/svg","g");s.setAttribute("class","bouncing-arrow-label");const o=document.createElementNS("http://www.w3.org/2000/svg","rect");o.setAttribute("x",`${t+20*r}`),o.setAttribute("y",""+(e-20*r)),o.setAttribute("width",""+40*r),o.setAttribute("height",""+20*r),o.setAttribute("rx","3"),o.setAttribute("fill",n);const a=document.createElementNS("http://www.w3.org/2000/svg","text");return a.setAttribute("x",`${t+40*r}`),a.setAttribute("y",""+(e-6*r)),a.setAttribute("fill","white"),a.setAttribute("font-size",12*r+"px"),a.setAttribute("text-anchor","middle"),a.textContent=i,s.appendChild(o),s.appendChild(a),s}startAnimations(){setTimeout(()=>{this.animationElements.forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&t.beginElement()}catch(t){Ki("애니메이션 시작 오류:",t)}})},10)}invalidate(){this.updatePosition()}updatePosition(){if(!this.vectorElement)return;const{left:t,top:e,width:n}=this.target.bounds,i=this.projectComponentPoint(this.target,t+n/2,e);if(!i)return;const r=Math.max(i.x,20),s=Math.max(i.y,20);this.vectorElement.setAttribute("transform",`translate(${r}, ${s})`)}}Kc.DECORATOR_TYPE="bouncing-arrow",function(t){t.ROTATE="rotate",t.TRANSLATE_X="translateX",t.TRANSLATE_Y="translateY",t.SCALE="scale",t.FADE="fade"}(Yc||(Yc={})),function(t){t.VIBRATION="vibration",t.ROTATION="rotation",t.HEARTBEAT="heartbeat",t.MOVING="moving",t.OUTLINE="outline",t.FADE="fade",t.WAYPOINT="waypoint"}(Vc||(Vc={})),function(t){t.CENTER="center",t.TOP="top",t.RIGHT="right",t.BOTTOM="bottom",t.LEFT="left",t.TOP_RIGHT="top-right",t.BOTTOM_RIGHT="bottom-right",t.BOTTOM_LEFT="bottom-left",t.TOP_LEFT="top-left",t.TOP_LEFT_CORNER="top-left-corner",t.TOP_RIGHT_CORNER="top-right-corner",t.BOTTOM_LEFT_CORNER="bottom-left-corner",t.BOTTOM_RIGHT_CORNER="bottom-right-corner",t.LEFT_TOP="left-top",t.LEFT_BOTTOM="left-bottom",t.RIGHT_TOP="right-top",t.RIGHT_BOTTOM="right-bottom"}(Gc||(Gc={}));class $c extends Xc{constructor(t,e,n={}){const{animations:i,...r}=n;super(t,e,{icon:"arrow_forward",size:24,color:"#FF0000",deltaX:0,deltaY:0,...r}),this.animations=[],this._location=null,this.element=null,this._delta={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0},this.animations=this.createAnimations(i)}delta(t,e){if(!t)return this._delta;switch(typeof t){case"object":this._delta={...this._delta,...t};break;case"string":if(void 0===e)return this._delta[t];this._delta[t]=e}const{tx:n,ty:i,sx:r,sy:s,theta:o,fade:a}=this._delta;return this.element&&Object.assign(this._getElement().style,{opacity:1-a,transform:`rotate(${o}rad) translate(${n}px, ${i}px) scale(${r}, ${s}) perspective(1px)`}),this._delta}getScaledSize(){const t=this.options.size||24,{x:e}=this.target.rootModel?.state.scale||{x:1},{x:n}=this.target.state.scale||{x:1};return t*e*n}get location(){if(this._location)return this._location;const{location:t,position:e,size:n}=this.options,{bounds:i}=this.target,{left:r,top:s,width:o,height:a}=i,c=n/2;let l;switch(e||t||Gc.CENTER){case Gc.TOP_LEFT:case"top-left":l={x:r,y:s-n};break;case Gc.TOP:case"top":l={x:r+(o-n)/2,y:s-n};break;case Gc.TOP_RIGHT:case"top-right":l={x:r+o-n,y:s-n};break;case Gc.BOTTOM_LEFT:case"bottom-left":l={x:r,y:s+a};break;case Gc.BOTTOM:case"bottom":l={x:r+(o-n)/2,y:s+a};break;case Gc.BOTTOM_RIGHT:case"bottom-right":l={x:r+o-n,y:s+a};break;case Gc.LEFT_TOP:case"left-top":l={x:r-n,y:s};break;case Gc.LEFT:case"left":l={x:r-n,y:s+(a-n)/2};break;case Gc.LEFT_BOTTOM:case"left-bottom":l={x:r-n,y:s+(a-n)};break;case Gc.RIGHT_TOP:case"right-top":l={x:r+o,y:s};break;case Gc.RIGHT:case"right":l={x:r+o,y:s+(a-n)/2};break;case Gc.RIGHT_BOTTOM:case"right-bottom":l={x:r+o,y:s+(a-n)};break;case Gc.TOP_LEFT_CORNER:case"top-left-corner":l={x:r-c,y:s-c};break;case Gc.TOP_RIGHT_CORNER:case"top-right-corner":l={x:r+o-c,y:s-c};break;case Gc.BOTTOM_LEFT_CORNER:case"bottom-left-corner":l={x:r-c,y:s+a-c};break;case Gc.BOTTOM_RIGHT_CORNER:case"bottom-right-corner":l={x:r+o-c,y:s+a-c};break;case Gc.CENTER:default:l={x:r+o/2-n/2,y:s+a/2-n/2}}return this._location=this.toGlobal(l.x,l.y),this._location}_getElement(){return this.element||this._createElementIfNeeded(),this.element}_createElementIfNeeded(){if(this.element)return;const{icon:t="arrow_forward",color:e="#FF0000"}=this.options,n=this.getScaledSize(),{x:i,y:r}=this.location,s=document.createElement("div");s.setAttribute("scene","animated-icon"),Object.assign(s.style,{position:"absolute",fontVariationSettings:"'FILL' 1",fontFamily:"Material Symbols Outlined",fontSize:n+"px",width:n+"px",height:n+"px",lineHeight:n+"px",padding:0,margin:0,color:e,textAlign:"center",verticalAlign:"middle",left:i+"px",top:r+"px",pointerEvents:"none"}),s.textContent=t,this.element=s}updateIconSizeAndPosition(){if(!this.element)return;this._location=null;const t=this.getScaledSize(),{x:e,y:n}=this.location;Object.assign(this.element.style,{fontSize:t+"px",width:t+"px",height:t+"px",lineHeight:t+"px",left:e+"px",top:n+"px"})}touch(){}invalidate(){this.updateIconSizeAndPosition()}start(){if(super.start(),this.isActive){if(this.overlay&&this._getElement().parentNode!==this.overlay&&this.overlay.appendChild(this._getElement()),this.target?.root?.app?.suppressAnimations)return;this.animations.forEach(t=>t.start())}}stop(){this.animations.forEach(t=>t.stop()),this.element&&this._getElement().parentNode&&this._getElement().parentNode.removeChild(this._getElement()),this._location=null,super.stop()}get center(){const t=this.getScaledSize(),{x:e,y:n}=this.location;return{x:e+t/2,y:n+t/2}}toGlobal(t,e){const{tx:n,ty:i}=this._delta;return this.projectComponentPoint(this.target,t+n,e+i)??this.target.toGlobal(t+n,e+i)}get root(){return this.target.root}createDOMElements(){this._getElement()}updateDOMElements(){this.element?this.updateIconSizeAndPosition():this._getElement()}updatePosition(){this.updateIconSizeAndPosition()}createAnimations(t){if(Array.isArray(t))return t.map(t=>("theta"in t&&(t={...t,theta:t.theta*(Math.PI/180)}),aa(this,t)));if(t){const e={...t};return"theta"in e&&(e.theta=e.theta*(Math.PI/180)),[aa(this,e)]}return[]}}$c.DECORATOR_TYPE="animated-icon";class Qc extends Xc{constructor(t,e,n={}){super(t,e,{distance:10,lineWidth:2,fillStyle:"rgba(0, 0, 0, 0.5)",animation:!1,...n}),this.pathElement=null,this.decoratorGroup=null,this.elementId=""}createDOMElements(){if(this.overlay)try{this.getSvgContainer();const t=this.getOrCreateDecoratorGroup(!0);this.decoratorGroup=t;const e=this.getDefsForType(),n=this.getVectorGroupId();this.elementId=`${n}-border`;const{color:i="#FF0000",animation:r=!1}=this.options,{fillStyle:s}=this.target.state||{},o=this.createFilter(this.elementId,this.options.fillStyle||s||"rgba(0, 0, 0, 0.5)");if(e.appendChild(o),r){const t=this.createGradient(this.elementId,i);e.appendChild(t)}const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("fill","none"),a.setAttribute("stroke-width",(this.options.lineWidth||2).toString()),a.setAttribute("stroke-linejoin","round"),a.setAttribute("pointer-events","none"),a.setAttribute("class","border-highlighting-path"),a.setAttribute("filter",`url(#${this.elementId}-filter)`),r?a.setAttribute("stroke",`url(#${this.elementId})`):a.setAttribute("stroke",i),t.appendChild(a),this.pathElement=a,this.vectorElement=t,this.updatePathData(),this.options.animation&&this.startAnimations()}catch(t){Ki("테두리 하이라이팅 요소 생성 실패:",t)}}updatePathData(){if(!this.pathElement)return;this.pathElement.setAttribute("visibility","visible"),this.pathElement.setAttribute("opacity","1"),this.decoratorGroup&&(this.decoratorGroup.setAttribute("visibility","visible"),this.decoratorGroup.setAttribute("opacity","1"));const t=this.getPathPoints(),e=this.createOffsetPath(t,this.options.distance),{round:n=0}=this.target.state||{},i=this.pointsToPathData(e,n);this.pathElement.setAttribute("d",i)}invalidate(){this.updatePathData()}startAnimations(){if(!this.isActive||!this.options.animation||!this.pathElement)return;this.pathElement.setAttribute("visibility","visible"),this.pathElement.setAttribute("opacity","1"),this.decoratorGroup&&(this.decoratorGroup.setAttribute("visibility","visible"),this.decoratorGroup.setAttribute("opacity","1")),this.elementId&&(this.pathElement.setAttribute("stroke",`url(#${this.elementId})`),this.pathElement.setAttribute("filter",`url(#${this.elementId}-filter)`));const t=this.getDefsForType();if(t){const e=t.querySelector(`#${this.elementId}`);if(e){e.querySelectorAll("animate").forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&(t.setAttribute("restart","always"),t.beginElement())}catch(t){Ki("애니메이션 시작 오류:",t)}})}}}createDefsElement(t){const e=document.createElementNS("http://www.w3.org/2000/svg","defs");return t.appendChild(e),e}getPathPoints(){if(!this.target.path||!Array.isArray(this.target.path)){const{left:t,top:e,width:n,height:i}=this.target.bounds;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}return this.target.path.map(t=>this.target.toGlobal(t.x,t.y))}createOffsetPath(t,e){const n=[],i=t.length;for(let r=0;r<i;r++){const s=t[(r-1+i)%i],o=t[r],a=t[(r+1)%i],c=o.x-s.x,l=o.y-s.y,h=a.x-o.x,d=a.y-o.y,u=this.normalize({x:l,y:-c}),p=this.normalize({x:d,y:-h}),f=this.normalize({x:(u.x+p.x)/2,y:(u.y+p.y)/2}),g={x:o.x+f.x*e,y:o.y+f.y*e};n.push(g)}return n}normalize(t){const e=Math.sqrt(t.x*t.x+t.y*t.y);return{x:t.x/e||0,y:t.y/e||0}}pointsToPathData(t,e=0){if(t.length<2)return"";let n="";const i=t.length,r=(t,e,n)=>{const i=e.x-t.x,r=e.y-t.y,s=Math.sqrt(i*i+r*r);return{x:t.x+i/s*n,y:t.y+r/s*n}};for(let s=0;s<i;s++){const o=t[s],a=t[(s+1)%i],c=t[(s-1+i)%i],l=Math.sqrt((o.x-c.x)**2+(o.y-c.y)**2),h=Math.sqrt((o.x-a.x)**2+(o.y-a.y)**2),d=Math.min(e,l/2,h/2),u=r(o,c,d),p=r(o,a,d);n+=0===s?`M${u.x},${u.y}`:` L${u.x},${u.y}`,n+=` Q${o.x},${o.y} ${p.x},${p.y}`}return n+=" Z",n}createFilter(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","filter");n.setAttribute("id",`${t}-filter`);const i=document.createElementNS("http://www.w3.org/2000/svg","feFlood");i.setAttribute("flood-color",e),i.setAttribute("result","flood");const r=document.createElementNS("http://www.w3.org/2000/svg","feComposite");r.setAttribute("in","flood"),r.setAttribute("in2","SourceAlpha"),r.setAttribute("operator","in"),r.setAttribute("result","mask");const s=document.createElementNS("http://www.w3.org/2000/svg","feMerge"),o=document.createElementNS("http://www.w3.org/2000/svg","feMergeNode");o.setAttribute("in","mask");const a=document.createElementNS("http://www.w3.org/2000/svg","feMergeNode");return a.setAttribute("in","SourceGraphic"),s.appendChild(o),s.appendChild(a),n.appendChild(i),n.appendChild(r),n.appendChild(s),n}createGradient(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");n.setAttribute("id",t),n.setAttribute("x1","0%"),n.setAttribute("y1","0%"),n.setAttribute("x2","100%"),n.setAttribute("y2","0%");const i=this.alterColor(e,120),r=this.alterColor(e,240),s=document.createElementNS("http://www.w3.org/2000/svg","stop");s.setAttribute("offset","0%"),s.setAttribute("stop-color",e);const o=document.createElementNS("http://www.w3.org/2000/svg","animate");o.setAttribute("attributeName","stop-color"),o.setAttribute("values",`${e};${i};${r};${e}`),o.setAttribute("dur","5s"),o.setAttribute("repeatCount","indefinite");const a=document.createElementNS("http://www.w3.org/2000/svg","stop");a.setAttribute("offset","100%"),a.setAttribute("stop-color",r);const c=document.createElementNS("http://www.w3.org/2000/svg","animate");return c.setAttribute("attributeName","stop-color"),c.setAttribute("values",`${r};${e};${i};${r}`),c.setAttribute("dur","5s"),c.setAttribute("repeatCount","indefinite"),s.appendChild(o),a.appendChild(c),n.appendChild(s),n.appendChild(a),n}alterColor(t,e){const n=this.convertToHex(t),i=parseInt(n.substring(1,3),16),r=parseInt(n.substring(3,5),16),s=parseInt(n.substring(5,7),16),o=this.rgbToHsl(i,r,s);o[0]=(o[0]+e/360)%1;const a=this.hslToRgb(o[0],o[1],o[2]);return`#${a[0].toString(16).padStart(2,"0")}${a[1].toString(16).padStart(2,"0")}${a[2].toString(16).padStart(2,"0")}`}rgbToHsl(t,e,n){t/=255,e/=255,n/=255;const i=Math.max(t,e,n),r=Math.min(t,e,n);let s=0,o=0;const a=(i+r)/2;if(i!==r){const c=i-r;switch(o=a>.5?c/(2-i-r):c/(i+r),i){case t:s=(e-n)/c+(e<n?6:0);break;case e:s=(n-t)/c+2;break;case n:s=(t-e)/c+4}s/=6}return[s,o,a]}hslToRgb(t,e,n){let i,r,s;if(0===e)i=r=s=n;else{const o=(t,e,n)=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t),a=n<.5?n*(1+e):n+e-n*e,c=2*n-a;i=o(c,a,t+1/3),r=o(c,a,t),s=o(c,a,t-1/3)}return[Math.round(255*i),Math.round(255*r),Math.round(255*s)]}convertToHex(t){if(/^#([0-9A-F]{6})$/i.test(t))return t;const e=document.createElement("canvas");e.width=1,e.height=1;const n=e.getContext("2d");if(!n)return"#FF0000";n.fillStyle=t,n.fillRect(0,0,1,1);const i=n.getImageData(0,0,1,1).data;return`#${i[0].toString(16).padStart(2,"0")}${i[1].toString(16).padStart(2,"0")}${i[2].toString(16).padStart(2,"0")}`}start(){super.start(),this.isActive&&this.options.animation&&this.startAnimations()}removeDOMElements(){try{if(this.pathElement&&this.pathElement.parentNode&&this.pathElement.parentNode.removeChild(this.pathElement),this.pathElement=null,this.overlay){const t=this.getDefsForType();if(t&&this.elementId){const e=t.querySelector(`#${this.elementId}-filter`);e&&e.remove();const n=t.querySelector(`#${this.elementId}`);n&&n.remove()}}super.removeDOMElements()}catch(t){Ki("테두리 하이라이팅 요소 제거 중 오류:",t)}}}Qc.DECORATOR_TYPE="border-highlighting";class Zc extends Xc{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",...n}),this.textElements=[],this.rectElements=[]}updateDOMElements(){if(!this.target.anchors||!this.target.anchors.length)return void this.removeDOMElements();const t=this.options,e=this.target.anchors,n=this.getOrCreateDecoratorGroup(!0);this.textElements=[],this.rectElements=[];const i=this.getComponentBounds();e.forEach(e=>{const{name:r,position:s}=e;let{x:o,y:a}=s||{};if(!r)return;let c=this.calculateOffsetX(o,i),l=this.calculateOffsetY(a,i);const h=this.projectComponentPoint(this.target,o,a);if(!h)return;o=h.x,a=h.y;const d=document.createElementNS("http://www.w3.org/2000/svg","text");d.setAttribute("fill",t.textColor),d.setAttribute("font-family",t.fontFamily),d.setAttribute("font-size",t.fontSize),d.textContent=r,n.appendChild(d);const u=d.getBBox();n.removeChild(d);const p=u.width,f=u.height;c=-1==c?-p-9:3,l=-1==l?-f-9:3,d.setAttribute("x",(o+c+3).toString()),d.setAttribute("y",(a+l+f).toString());const g=document.createElementNS("http://www.w3.org/2000/svg","rect");g.setAttribute("x",(o+c).toString()),g.setAttribute("y",(a+l).toString()),g.setAttribute("width",(p+6).toString()),g.setAttribute("height",(f+6).toString()),g.setAttribute("rx",t.cornerRadius.toString()),g.setAttribute("ry",t.cornerRadius.toString()),g.setAttribute("fill",t.bgColor),n.appendChild(g),n.appendChild(d),this.rectElements.push(g),this.textElements.push(d)})}calculateOffsetX(t,e){return t<e.left+1?-1:1}calculateOffsetY(t,e){return t<e.top+1?-1:1}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}createDOMElements(){this.updateDOMElements()}}Zc.DECORATOR_TYPE="anchors";class Jc extends Xc{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",offsetX:3,offsetY:-8,animation:!1,...n}),this.textElement=null,this.backgroundElement=null,this.currentTag=""}createDOMElements(){const t=this.target.decotag;if(!t)return;this.currentTag=t;const{fontFamily:e,fontSize:n,textColor:i,padding:r,cornerRadius:s,bgColor:o,animation:a,repeat:c,duration:l}=this.options,h=this.getOrCreateDecoratorGroup(!0);h.setAttribute("transform","translate(0, 0)"),this.textElement=document.createElementNS("http://www.w3.org/2000/svg","text"),this.textElement.textContent=t,this.textElement.setAttribute("x",`${r}`),this.textElement.setAttribute("y",`-${n}`),this.textElement.setAttribute("font-family",e),this.textElement.setAttribute("font-size",n),this.textElement.setAttribute("fill",i),this.textElement.setAttribute("dominant-baseline","middle"),h.appendChild(this.textElement);const d=this.textElement.getBBox();if(this.backgroundElement=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.backgroundElement.setAttribute("x",(d.x-r).toString()),this.backgroundElement.setAttribute("y",(d.y-r).toString()),this.backgroundElement.setAttribute("width",(d.width+2*r).toString()),this.backgroundElement.setAttribute("height",(d.height+2*r).toString()),this.backgroundElement.setAttribute("rx",s.toString()),this.backgroundElement.setAttribute("ry",s.toString()),this.backgroundElement.setAttribute("fill",o),h.replaceChildren(),h.appendChild(this.backgroundElement),h.appendChild(this.textElement),a){const t=this.createFadeAnimation(.3,1,l,{repeat:c});this.addAnimations(h,[t])}this.vectorElement=h,this.updatePosition()}updateDOMElements(){const t=this.target.decotag;t&&t===this.currentTag?this.vectorElement&&this.updatePosition():(this.removeDOMElements(),this.createDOMElements())}updatePosition(){super.updatePosition()}invalidate(){this.updatePosition()}}Jc.DECORATOR_TYPE="decotag";class tl extends Xc{constructor(t,e,n={}){super(t,e,{arrowColor:"#FFA500",arrowHeadLength:12,lineWidth:1.5,startAlpha:.6,endAlpha:1,animated:!0,animationDuration:5e3,repeat:!1,...n}),this.currentMappings=null,this.cachedArrows=[],this._incomingTimer=null}findIncomingSources(){const t=this.target.root;if(!t)return[];const e=this.target.state?.id;if(!e)return[];const n=[];return t.traverse(i=>{if(i===this.target)return;const r=i.model?.mappings;if(r)for(const s of r){if(!s.target)continue;if(s.target===`#${e}`){n.push({from:i,to:this.target});break}const r=t.findAll(s.target,i);if(r?.some(t=>t===this.target)){n.push({from:i,to:this.target});break}}}),n}appendArrow(t,e,n,i,r,s){const o=e.center,a=n.center,c=this.projectComponentPoint(e,o.x,o.y),l=this.projectComponentPoint(n,a.x,a.y);if(!c||!l)return;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,s.arrowHeadLength),u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",h),u.setAttribute("stroke",r),u.setAttribute("stroke-width",String(s.lineWidth||2)),u.setAttribute("fill","none"),u.setAttribute("data-source-id",e.state?.id||""),u.setAttribute("data-target-id",n.state?.id||"");const p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d",d),p.setAttribute("fill",i),p.setAttribute("stroke","none"),t.appendChild(u),t.appendChild(p)}createDOMElements(){this.removeDOMElements();const t=this.target.mappings&&this.target.mappings.length>0;this.currentMappings=this.target.mappings;const e=this.options,n=e.arrowColor||"#FFA500",i=this.getOrCreateDecoratorGroup(!0),r=this.getDefsForType(),s=`data-spread-style-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,o=document.createElementNS("http://www.w3.org/2000/svg","style");o.setAttribute("id",s),o.textContent=`\n @keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: ${e.repeat?"0.2":"0"}; }\n }\n .arrow-animated {\n animation: fadeOut ${e.animationDuration||2e3}ms linear ${e.repeat?"infinite":"1"} forwards;\n }\n `,r.appendChild(o);const a=Date.now(),c=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),l=`arrow-gradient-out-${a}-${c}`,h=this.createGradient(l,n,e);r.appendChild(h);const d=tl.INCOMING_ARROW_COLOR,u=`arrow-gradient-in-${a}-${c}`,p=this.createGradient(u,d,e);r.appendChild(p);const f=document.createElementNS("http://www.w3.org/2000/svg","g");if(f.setAttribute("class",e.animated?"arrow-animated":""),i.appendChild(f),this.cachedArrows=[],t){this.target.mappings.forEach(t=>{const i=this.target.root.findAll(t.target,this.target);i?.length&&i.forEach(t=>{t!==this.target&&(this.cachedArrows.push({from:this.target,to:t}),this.appendArrow(f,this.target,t,n,`url(#${l})`,e))})})}this.vectorElement=i,this._incomingTimer=setTimeout(()=>{if(this._incomingTimer=null,!this.vectorElement)return;this.findIncomingSources().forEach(({from:t})=>{this.cachedArrows.push({from:t,to:this.target}),this.appendArrow(f,t,this.target,d,`url(#${u})`,e)})},tl.INCOMING_DEBOUNCE_MS)}createGradient(t,e,n){const i=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");i.setAttribute("id",t),i.setAttribute("gradientUnits","userSpaceOnUse");const r=document.createElementNS("http://www.w3.org/2000/svg","stop");r.setAttribute("offset","0%"),r.setAttribute("stop-color",e),r.setAttribute("stop-opacity",(n.startAlpha||.5).toString());const s=document.createElementNS("http://www.w3.org/2000/svg","stop");return s.setAttribute("offset","100%"),s.setAttribute("stop-color",e),s.setAttribute("stop-opacity",(n.endAlpha||1).toString()),i.appendChild(r),i.appendChild(s),i}createArrowPaths(t,e,n){const i=e.x-t.x,r=e.y-t.y,s=Math.atan2(r,i),o=e.x+n*Math.cos(s+tl.ARROW_ANGLE_1),a=e.y+n*Math.sin(s+tl.ARROW_ANGLE_1),c=e.x+n*Math.cos(s+tl.ARROW_ANGLE_2),l=e.y+n*Math.sin(s+tl.ARROW_ANGLE_2);return{linePath:`M ${t.x} ${t.y} L ${e.x} ${e.y}`,headPath:`M ${e.x} ${e.y} L ${o} ${a} L ${c} ${l} Z`}}updateDOMElements(){if(!this.target.app?.isEditMode)return void this.removeDOMElements();this.target.mappings!==this.currentMappings?(this.removeDOMElements(),requestAnimationFrame(()=>{this.createDOMElements()})):this.vectorElement&&this.updatePosition()}updatePosition(){const t=this.getDecoratorType(),e=this.getSvgContainer().querySelector(`g[data-decorator-type-container="${t}"]`);if(!e)return;const n=this.getVectorGroupId(),i=e.querySelector(`g[data-decorator-group-id="${n}"]`);if(!i)return;const r=this.options,s=i.querySelector("g.arrow-animated")||i,o=Array.from(s.querySelectorAll('path[fill="none"]')),a=Array.from(s.querySelectorAll('path[stroke="none"]'));if(0===o.length)return;const c=Math.min(o.length,a.length,this.cachedArrows.length);for(let t=0;t<c;t++){const{from:e,to:n}=this.cachedArrows[t],i=e.center,s=n.center,c=this.projectComponentPoint(e,i.x,i.y),l=this.projectComponentPoint(n,s.x,s.y);if(!c||!l)continue;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,r.arrowHeadLength);o[t].setAttribute("d",h),a[t].setAttribute("d",d)}}removeDOMElements(){this.currentMappings=null,this.cachedArrows=[],this._incomingTimer&&(clearTimeout(this._incomingTimer),this._incomingTimer=null);try{if(this.overlay){const t=this.getSvgContainer();if(t){const e=this.getDecoratorType(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`);if(n){const t=n.querySelector(`defs[data-defs-for="${e}"]`);if(t){t.querySelectorAll("style").forEach(t=>t.remove());t.querySelectorAll("linearGradient").forEach(t=>t.remove())}}}}this.animationElements=[],super.removeDOMElements()}catch(t){Ki("데이터 스프레드 데코레이터 요소 제거 중 오류:",t)}}invalidate(){this.updatePosition()}}tl.DECORATOR_TYPE="data-spread",tl.ARROW_ANGLE_1=160*Math.PI/180,tl.ARROW_ANGLE_2=200*Math.PI/180,tl.INCOMING_ARROW_COLOR="#4A9EFF",tl.INCOMING_DEBOUNCE_MS=500;class el extends Xc{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:2,padding:2,fontSize:"12px",fontFamily:"Arial",offsetX:4,offsetY:4,...n}),this.textElements=[],this.rectElements=[]}createDOMElements(){this.updateDOMElements()}updateDOMElements(){if(!this.target.isLine||!this.target.isLine())return void this.removeDOMElements();const{offsetX:t,offsetY:e,padding:n,textColor:i,bgColor:r,cornerRadius:s,fontSize:o,fontFamily:a}=this.options,c=this.getOrCreateDecoratorGroup(!0);this.textElements=[],this.rectElements=[];const{fromEnd:l,toEnd:h}=this.target;[l,h].filter(Boolean).forEach(l=>{const{component:h,anchor:d}=l;if(!d)return;const{name:u,position:p}=d||{};if(!h.rootModel||!u||!p)return;const f=this.projectComponentPoint(h,p.x,p.y);if(!f)return;let{x:g,y:m}=f;const y=document.createElementNS("http://www.w3.org/2000/svg","g"),b=document.createElementNS("http://www.w3.org/2000/svg","text");b.setAttribute("text-anchor","middle"),b.setAttribute("dominant-baseline","middle"),b.setAttribute("x","0"),b.setAttribute("y","0"),b.setAttribute("fill",i),b.setAttribute("font-family",a),b.setAttribute("font-size",o),b.textContent=u,c.appendChild(b);const v=b.getBBox();c.removeChild(b);const _=document.createElementNS("http://www.w3.org/2000/svg","rect"),x=v.width+2*(n??0),w=v.height+2*(n??0);g+=(t??0)+x/2,m+=(e??0)+w/2,_.setAttribute("x",(-x/2).toString()),_.setAttribute("y",(-w/2).toString()),_.setAttribute("width",x.toString()),_.setAttribute("height",w.toString()),_.setAttribute("rx",(s??0).toString()),_.setAttribute("ry",(s??0).toString()),_.setAttribute("fill",r),y.appendChild(_),y.appendChild(b),y.setAttribute("transform",`translate(${g}, ${m})`),c.appendChild(y),this.rectElements.push(_),this.textElements.push(b)})}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}}el.DECORATOR_TYPE="link",Fs.registerDecorator("bouncing-arrow",Kc),Fs.registerDecorator("animated-icon",$c),Fs.registerDecorator("border-highlighting",Qc),Fs.registerDecorator("anchors",Zc),Fs.registerDecorator("decotag",Jc),Fs.registerDecorator("data-spread",tl),Fs.registerDecorator("link",el);class nl{constructor(t){this.params=Object.assign({},t)}excute(){}}class il extends nl{execute(){this.params.changes.forEach(t=>t.component.set(t.after))}static before(t){return t.map(t=>({component:t}))}static after(t,e){e.execute(null,!1)}static around(t,e,n){e.call(n),t.execute(null,!1)}}const rl="left",sl="right",ol="center",al="bottom",cl="middle",ll="z-front",hl="z-back",dl="z-middle",ul=[rl,sl,ol,"top",cl,al,ll,hl,dl];function pl(t){if(!this.hasSameParentForAllSelected||-1===ul.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(e.length<=1)return;const n=this.app.commander;il.around(n,function(){!function(t,e){const n=JSON.parse(JSON.stringify(e[0].bounds));let i=n.left+n.width,r=n.top+n.height;for(let t=0;t<e.length;t++){const s=e[t].bounds;n.left=s.left>n.left?n.left:s.left,n.top=s.top>n.top?n.top:s.top,i=s.left+s.width>i?s.left+s.width:i,r=s.top+s.height>r?s.top+s.height:r}switch(n.width=i-n.left,n.height=r-n.top,t){case rl:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left,top:i.top,width:i.width,height:i.height}}break;case ol:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left+n.width/2-i.width/2,top:i.top,width:i.width,height:i.height}}break;case sl:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:i-n.width,top:n.top,width:n.width,height:n.height}}break;case"top":for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top,width:i.width,height:i.height}}break;case cl:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top+n.height/2-i.height/2,width:i.width,height:i.height}}break;case al:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:n.left,top:r-n.height,width:n.width,height:n.height}}break;case ll:{let t=1/0;for(let n=0;n<e.length;n++){const i=e[n].state.zPos||0;i<t&&(t=i)}for(let n=0;n<e.length;n++)e[n].set({zPos:t});break}case hl:{let t=-1/0;for(let n=0;n<e.length;n++){const i=(e[n].state.zPos||0)+(e[n].state.depth||0);i>t&&(t=i)}for(let n=0;n<e.length;n++){const i=e[n].state.depth||0;e[n].set({zPos:t-i})}break}case dl:{let t=1/0,n=-1/0;for(let i=0;i<e.length;i++){const r=e[i].state.zPos||0,s=e[i].state.depth||0;r<t&&(t=r),r+s>n&&(n=r+s)}const i=(t+n)/2;for(let t=0;t<e.length;t++){const n=e[t].state.depth||0;e[t].set({zPos:i-n/2})}break}default:;}}(t,e)})}const fl="VERTICAL",gl=[fl,"HORIZONTAL","Z"];function ml(t){if(!this.hasSameParentForAllSelected||-1===gl.indexOf(t))return;const e=this.selected;if(e.length<=1)return;const n=this.app.commander;il.around(n,function(){!function(t,e){if("Z"===t)return void function(t){const e=t.filter(t=>!t.stuck).slice(0);e.sort((t,e)=>(t.state.zPos||0)+(t.state.depth||0)/2-((e.state.zPos||0)+(e.state.depth||0)/2));const n=e.reduce((t,e)=>t+(e.state.depth||0),0),i=e[0].state.zPos||0,r=((e[e.length-1].state.zPos||0)+(e[e.length-1].state.depth||0)-i-n)/(e.length-1);let s=i+(e[0].state.depth||0);for(let t=1;t<e.length-1;t++){const n=e[t],i=n.state.depth||0;s+=r,n.set({zPos:s}),s+=i}}(e);const n=e.filter(t=>!t.stuck).slice(0);n.sort(function(e,n){const i=e.center,r=n.center;return t===fl?i.y-r.y:i.x-r.x});const i=n.reduce((e,n)=>e+(t===fl?n.bounds.height:n.bounds.width),0),r=n[0].bounds,s=n[n.length-1].bounds,o=((t===fl?s.top+s.height-r.top:s.left+s.width-r.left)-i)/(n.length-1);let a=t===fl?r.top+r.height:r.left+r.width;for(let e=1;e<n.length-1;e++){const i=n[e],r=i.bounds;a+=o,t===fl?(i.bounds={left:r.left,top:a,width:r.width,height:r.height},a+=r.height):(i.bounds={left:a,top:r.top,width:r.width,height:r.height},a+=r.width)}}(t,e)})}function yl(t){let e=0;for(;t&&!t.isRootModel();)e+=t.get("rotation")||0,t=t.parent;return e%(2*Math.PI)}class bl extends nl{execute(){this.params.changes.forEach(t=>{const{component:e,to_container:n,to_index:i,to_left:r,to_top:s}=t,o=function(t){if(t.isRootModel())return t.bounds;const{bounds:e,rotatePoint:n}=t;let i=n;return i=t.toScene(i.x,i.y),{left:i.x-(n.x-e.left),top:i.y-(n.y-e.top),width:e.width,height:e.height}}(e),a=yl(e);if(function(t){const e=t.parent?.model?.zPos;if(null==e)return;const n=t.state.zPos||0;t.set("zPos",n+e)}(e),e.removeSelf(!n),e.bounds=o,e.set("rotation",a),n){e.set("rotation",function(t,e){return((t.get("rotation")||0)-yl(e))%(2*Math.PI)}(e,n));const o=function(t,e){if(e.isRootModel())return t.bounds;const{bounds:n,rotatePoint:i}=t,r=e.fromScene(i.x,i.y),s=e.bounds;return{left:r.x-(i.x-n.left)-s.left,top:r.y-(i.y-n.top)-s.top,width:n.width,height:n.height}}(e,n);t.to_left=void 0!==r?r:o.left,t.to_top=void 0!==s?s:o.top,e.bounds={left:t.to_left,top:t.to_top,width:o.width,height:o.height},void 0===i?n.addComponent(e):n.insertComponentAt(e,i)}})}}function vl(t,e,n){this.app.commander.execute(new bl({changes:[{component:t,to_container:e,to_index:n}]}))}function _l(t){const e=this.selected.filter(t=>!t.stuck);if(0===e.length||e[0].isRootModel())return;if(e.length>1&&("forward"===t||"backward"===t))return;const n=e[0].parent;let i;if("forward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t+1}]}else if("backward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t-1}]}else i=e.filter(t=>t.parent===n).sort((e,i)=>{const r=n.indexOf(e)<n.indexOf(i);return"front"===t?r:!r}).map((e,i)=>(n.indexOf(e),{component:e,to_container:n,to_index:"front"===t?n.components.length-i-1:i}));const r=new bl({changes:i});this.app.commander.execute(r)}function xl(t,e,n,i){const r=cc.register(t.type);if(!r)return $i("Class not found",t.type),null;n&&(t.refid=n(t.refid)),t.id&&i&&i(t.id)&&delete t.id;const s=new r(t,e);return t.components&&s.isContainer()&&(t.components.forEach(t=>{const r=xl(t,e,n,i);r&&s.addComponent(r)}),delete t.components),s.created(),s}function wl(t,e){const n=Jn(t.hierarchy);return delete n.id,xl(n,t.app,e)}function Ml(t,e,n){t instanceof Array||(t=[t]),n||(n=this.model_layer);const i=[],r=new Map;this.selected=t.map(t=>{try{return xl(t,n.app,t=>{const e=this.getNewRefid();return void 0!==t&&r.set(t,e),e},t=>(this.indexMap[t]||[])[0])}catch(t){return $i(t),!1}}).filter(Boolean).map(t=>{const{left:s,top:o,width:a,height:c,x:l,y:h,cx:d,cy:u}=e;return t.replaceRefids(r),isNaN(s)||isNaN(o)||isNaN(a)||isNaN(c)||(t.bounds={left:s,top:o,width:a,height:c}),isNaN(l)||isNaN(h)||t.move({x:l,y:h},!1),isNaN(d)||isNaN(u)||(t.center={x:d,y:u}),i.push({component:t,to_container:n}),t}),this.app.commander.execute(new bl({changes:i}))}function Sl(){const t=[],e=new Map;if(this.selected=this.selected.filter(t=>!t.isRootModel()).map(n=>{const i=wl(n,t=>{const n=this.getNewRefid();return void 0!==t&&e.set(t,n),n});return i.move({x:20,y:20},!1),t.push({component:i,to_container:n.parent}),i}).map(t=>(t.replaceRefids(e),t)),0===t.length)return;const n=new bl({changes:t});this.app.commander.execute(n)}function kl(){const t=this.selected;this.selected=[];let e=null;const n=t.filter(t=>!t.isRootModel()&&(t.parent.focusible||t.parent.isGroup())).map(t=>(e||(e=t.parent),{component:t,to_container:null}));for(;e&&e.isGroup();){const t=[];if(e.components.filter(t=>!n.find(e=>e.component===t)).forEach(e=>t.push(e)),t.length>1)break;const i=e.parent;t.forEach(t=>n.push({component:t,to_container:i})),n.push({component:e,to_container:null}),e=i}n.length>0&&this.app.commander.execute(new bl({changes:n})),e&&e.calculateBounds&&e.calculateBounds()}const Al=new Set(["execute","redo","undo","command-reset"]);function El(t,e,n,i){const r=function(t,e){return Al.has(e)?t.app?.commander:"mode"===e?t.app:t}(this,e);r?.[t](e,n,i)}function Cl(t,e,n){El.call(this,"on",t,e,n)}function Tl(t,e,n){El.call(this,"once",t,e,n)}function Pl(t,e,n){El.call(this,"off",t,e,n)}function Dl(t){const e=this.target_element,n=t||this.fitMode,i=this;function r(){i.fit(n),document.fullscreenElement||document.removeEventListener("fullscreenchange",r)}document.addEventListener("fullscreenchange",r),e.requestFullscreen().catch(()=>{document.removeEventListener("fullscreenchange",r)})}let Ol=0;function zl(){const t=this.selected.filter(t=>!t.isRootModel()).map(t=>t.hierarchy);if(0!==t.length)return Ol=0,JSON.stringify(t,null,2)}function Il(){Ol=0;const t=zl.call(this);return kl.call(this),t}function Ll(t){if(t)try{Ol++,Ml.call(this,JSON.parse(t),{x:15*Ol,y:15*Ol})}catch(e){Ki(e,t)}}const jl=function(){return{escape:function(t){return t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")},parseExtension:t,mimeType:function(e){const n=t(e).toLowerCase();return function(){const t="application/font-woff",e="image/jpeg";return{woff:t,woff2:t,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:e,jpeg:e,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}()[n]||""},dataAsUrl:function(t,e){return"data:"+e+";base64,"+t},isDataUrl:function(t){return-1!==t.search(/^(data:)/)},canvasToBlob:function(t){return t.toBlob?new Promise(function(e){t.toBlob(e)}):function(t){return new Promise(function(e){const n=window.atob(t.toDataURL().split(",")[1]),i=n.length,r=new Uint8Array(i);for(let t=0;t<i;t++)r[t]=n.charCodeAt(t);e(new Blob([r],{type:"image/png"}))})}(t)},resolveUrl:function(t,e){const n=document.implementation.createHTMLDocument(),i=n.createElement("base");n.head.appendChild(i);const r=n.createElement("a");return n.body.appendChild(r),i.href=e,r.href=t,r.href},getAndEncode:function(t){const e=3e4;Gl.impl.options.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());return new Promise(function(n){const i=new XMLHttpRequest;let r;if(i.onreadystatechange=s,i.ontimeout=o,i.responseType="blob",i.timeout=e,i.open("GET",t,!0),i.send(),Gl.impl.options.imagePlaceholder){const t=Gl.impl.options.imagePlaceholder.split(/,/);t&&t[1]&&(r=t[1])}function s(){if(4!==i.readyState)return;if(200!==i.status)return void(r?n(r):a("cannot fetch resource: "+t+", status: "+i.status));const e=new FileReader;e.onloadend=function(){const t=e.result.split(/,/)[1];n(t)},e.readAsDataURL(i.response)}function o(){r?n(r):a("timeout of "+e+"ms occured while fetching resource: "+t)}function a(t){Ki(t),n("")}})},uid:function(){let t=0;return function(){return"u"+e()+t++;function e(){return("0000"+(Math.random()*Math.pow(36,4)|0).toString(36)).slice(-4)}}}(),delay:function(t){return function(e){return new Promise(function(n){setTimeout(function(){n(e)},t)})}},asArray:function(t){const e=[],n=t.length;for(let i=0;i<n;i++)e.push(t[i]);return e},escapeXhtml:function(t){return t.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(t){return new Promise(function(e,n){const i=new Image;i.onload=function(){e(i)},i.onerror=n,i.src=t})},width:function(t){const n=e(t,"border-left-width"),i=e(t,"border-right-width");return t.scrollWidth+n+i},height:function(t){const n=e(t,"border-top-width"),i=e(t,"border-bottom-width");return t.scrollHeight+n+i}};function t(t){const e=/\.([^\.\/]*?)$/g.exec(t);return e?e[1]:""}function e(t,e){const n=window.getComputedStyle(t).getPropertyValue(e);return parseFloat(n.replace("px",""))}}(),Rl=function(){const t=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(t,r,s){return o()?Promise.resolve(t):Promise.resolve(t).then(n).then(function(e){let n=Promise.resolve(t);return e.forEach(function(t){n=n.then(function(e){return i(e,t,r,s)})}),n});function o(){return!e(t)}},shouldProcess:e,impl:{readUrls:n,inline:i}};function e(e){return-1!==e.search(t)}function n(e){const n=[];let i;for(;null!==(i=t.exec(e));)n.push(i[1]);return n.filter(function(t){return!jl.isDataUrl(t)})}function i(t,e,n,i){return Promise.resolve(e).then(function(t){return n?jl.resolveUrl(t,n):t}).then(i||jl.getAndEncode).then(function(t){return jl.dataAsUrl(t,jl.mimeType(e))}).then(function(n){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+jl.escape(t)+")(['\"]?\\))","g")}(e),"$1"+n+"$3")})}}(),Fl=function(){return{resolveAll:function(){return t().then(function(t){return Promise.all(t.map(function(t){return t.resolve()}))}).then(function(t){return t.join("\n")})},impl:{readAll:t}};function t(){return Promise.resolve(jl.asArray(document.styleSheets)).then(function(t){const e=[];return t.forEach(function(t){try{jl.asArray(t.cssRules||[]).forEach(t=>e.push(t))}catch(e){$i("Error while reading CSS rules from "+t.href,e instanceof Error?e.message:String(e))}}),e}).then(function(t){return t.filter(function(t){return t.type===CSSRule.FONT_FACE_RULE}).filter(function(t){return Rl.shouldProcess(t.style.getPropertyValue("src"))})}).then(function(e){return e.map(t)});function t(t){return{resolve:function(){const e=(t.parentStyleSheet||{}).href;return Rl.inlineAll(t.cssText,e)},src:function(){return t.style.getPropertyValue("src")}}}}}(),Bl=function(){return{inlineAll:function e(n){return n instanceof Element?i(n).then(function(){return n instanceof HTMLImageElement?t(n).inline().then(()=>n):Promise.all(jl.asArray(n.childNodes).map(function(t){return e(t)})).then(()=>n)}):Promise.resolve(n);function i(t){const e=t.style.getPropertyValue("background");return e?Rl.inlineAll(e).then(function(e){t.style.setProperty("background",e,t.style.getPropertyPriority("background"))}).then(function(){return t}):Promise.resolve(t)}},impl:{newImage:t}};function t(t){return{inline:function(e){return jl.isDataUrl(t.src)?Promise.resolve():Promise.resolve(t.src).then(e||jl.getAndEncode).then(function(e){return jl.dataAsUrl(e,jl.mimeType(t.src))}).then(function(e){return new Promise(function(n,i){t.onload=n,t.onerror=i,t.src=e})})}}}}(),Nl={imagePlaceholder:void 0,cacheBust:!1};function Hl(t,e){return function(t){void 0===t.imagePlaceholder?Gl.impl.options.imagePlaceholder=Nl.imagePlaceholder:Gl.impl.options.imagePlaceholder=t.imagePlaceholder;void 0===t.cacheBust?Gl.impl.options.cacheBust=Nl.cacheBust:Gl.impl.options.cacheBust=t.cacheBust}(e=e||{}),Promise.resolve(t).then(function(t){return Vl(t,e.filter,!0)}).then(function(t){return function(t){return Bl.inlineAll(t).then(function(){return t})}(t)}).then(function(t){const{bgcolor:n,width:i,height:r,style:s,sx:o=1,sy:a=1}=e||{},c=t.style;n&&(c.backgroundColor=n);i&&(c.width=i+"px");r&&(c.height=r+"px");c["margin-left"]="0px",c["margin-top"]="0px",c.transform=`rotate(0rad) translate(0px, 0px) scale(${o}, ${a}) perspective(1px)`,s&&Object.keys(s).forEach(function(t){c[t]=s[t]});return t}).then(function(n){return function(t,e,n){return Promise.resolve(t).then(function(t){return t.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),(new XMLSerializer).serializeToString(t)}).then(jl.escapeXhtml).then(function(t){return'<foreignObject x="0" y="0" width="100%" height="100%">'+t+"</foreignObject>"}).then(function(t){return'<svg xmlns="http://www.w3.org/2000/svg" width="'+e+'" height="'+n+'">'+t+"</svg>"}).then(function(t){return"data:image/svg+xml;charset=utf-8,"+t})}(n,e.width||jl.width(t),e.height||jl.height(t))})}function Yl(t,e){return Hl(t,e).then(jl.makeImage).then(jl.delay(100)).then(function(n){const i=function(t){const n=document.createElement("canvas");if(n.width=e.width||jl.width(t),n.height=e.height||jl.height(t),e.bgcolor){const t=n.getContext("2d");t.fillStyle=e.bgcolor,t.fillRect(0,0,n.width,n.height)}return n}(t);return i.getContext("2d").drawImage(n,0,0),i})}function Vl(t,e,n){return n||!e||e(t)?Promise.resolve(t).then(function(t){if(t instanceof HTMLCanvasElement)try{return jl.makeImage(t.toDataURL()).then(t=>t)}catch(t){$i(t)}return t.cloneNode(!1)}).then(function(n){return function(t,e,n){const i=t.childNodes;return 0===i.length?Promise.resolve(e):r(e,jl.asArray(i),n).then(function(){return e});function r(t,e,n){let i=Promise.resolve();return e.forEach(function(e){i=i.then(function(){return Vl(e,n,!1)}).then(function(e){e&&t.appendChild(e)})}),i}}(t,n,e)}).then(function(e){return function(t,e){return e instanceof Element?Promise.resolve().then(n).then(i).then(r).then(s).then(function(){return e}):e;function n(){function n(t,e){function n(t,e){jl.asArray(t).forEach(function(n){e.setProperty(n,t.getPropertyValue(n),t.getPropertyPriority(n))})}t.cssText?e.cssText=t.cssText:n(t,e)}n(window.getComputedStyle(t),e.style)}function i(){function n(n){const i=window.getComputedStyle(t,n),r=i.getPropertyValue("content");if(""===r||"none"===r)return;const s=jl.uid(),o=e;o.className=o.className+" "+s;const a=document.createElement("style");function c(t,e,n){const i="."+t+":"+e,r=n.cssText?s(n):o(n);return document.createTextNode(i+"{"+r+"}");function s(t){const e=t.getPropertyValue("content");return t.cssText+" content: "+e+";"}function o(t){return jl.asArray(t).map(e).join("; ")+";";function e(e){return e+": "+t.getPropertyValue(e)+(t.getPropertyPriority(e)?" !important":"")}}}a.appendChild(c(s,n,i)),e.appendChild(a)}[":before",":after"].forEach(function(t){n(t)})}function r(){t instanceof HTMLTextAreaElement&&e instanceof HTMLTextAreaElement&&(e.textContent=t.value),t instanceof HTMLInputElement&&e instanceof HTMLInputElement&&e.setAttribute("value",t.value)}function s(){e instanceof SVGElement&&(e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e instanceof SVGRectElement&&["width","height"].forEach(function(t){const n=e.getAttribute(t);n&&e.style.setProperty(t,n)}))}}(t,e)}):Promise.resolve(void 0)}const Gl={toSvg:Hl,toPng:function(t,e){return Yl(t,e||{}).then(function(t){return t.toDataURL()})},toJpeg:function(t,e){return Yl(t,e=e||{}).then(function(t){return t.toDataURL("image/jpeg",e.quality||1)})},toBlob:function(t,e){return Yl(t,e||{}).then(t=>jl.canvasToBlob(t))},toPixelData:function(t,e){return Yl(t,e||{}).then(function(e){return e.getContext("2d").getImageData(0,0,jl.width(t),jl.height(t)).data})},impl:{fontFaces:Fl,images:Bl,util:jl,inliner:Rl,options:{}}};function Ul(t,e,n,i){const r=this.model_layer,s=r._overlay;return new Promise(function(o,a){if(r){const a=r.get("width"),c=r.get("height");n=n||a,i=i||c;const l=r.get("translate"),h=r.get("scale"),d=Math.min(n/a,i/c);n=a*d,i=c*d,r.set("translate",{x:0,y:0}),r.set("scale",{x:d/Hr,y:d/Hr});let u=cc.createCanvas(n,i);const p=u.getContext("2d");if(r.draw(p),r.set("translate",l),r.set("scale",h),!s)return o(u.toDataURL(t,e)),void(u=null);Gl.toPng(s,{sx:d,sy:d,width:n,height:i}).then(function(r){const s=new Image;s.onload=function(){p.drawImage(s,0,0,n,i),o(u.toDataURL(t,e)),u=null},s.src=r},function(n){Ki(n),o(u.toDataURL(t,e)),u=null})}else a("No target model")})}function Wl(){if(!this.hasSameParentForAllSelected)return;const t=this.selected.filter(t=>!!t.parent&&!t.stuck);if(t.length<2)return;const e=t[0].parent,n=[],i=t.sort((t,n)=>e.components.indexOf(t)-e.components.indexOf(n));i.forEach(t=>{n.push(t.bounds)});const r=cc.union(n);let s=t[0].fromParent(r.left,r.top);s=t[0].toScene(s.x,s.y);const o=new Map,a=xl({type:"group",left:s.x,top:s.y,width:r.width,height:r.height},e.app,t=>{const e=this.getNewRefid();return void 0!==t&&o.set(t,e),e});a.replaceRefids(o);const c=[{component:a,to_container:e}];i.forEach(t=>{c.push({component:t,to_container:a})}),this.app.commander.execute(new bl({changes:c})),this.selected=[a]}function Xl(){if(0===this.selected.length)return;const t=[],e=[];this.selected.forEach(n=>{if(!n.isGroup())return;const i=n.parent;n.components.forEach(n=>{t.push(n),e.push({component:n,to_container:i})}),e.push({component:n,to_container:null})}),this.app.commander.execute(new bl({changes:e})),this.selected=t}function ql(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=cc.union(e),i=n.left+n.width/2;t.map(t=>{t.symmetryX(i)})}function Kl(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=cc.union(e),i=n.top+n.height/2;t.map(t=>{t.symmetryY(i)})}function $l(){il.around(this.app.commander,ql,this)}function Ql(){il.around(this.app.commander,Kl,this)}function Zl(t,e,n){const i=this.findAll(t,n);return i.forEach(t=>{t.set(e)}),i}function Jl(t){il.around(this.app.commander,t)}function th(){return Object.values(this.indexMap).map(t=>t.map(t=>{const{id:e,data:n}=t.model;return{key:e,value:n}})).flat().sort((t,e)=>t.key>e.key?1:-1)}const eh="left",nh="right",ih="center",rh="bottom",sh="middle",oh=[eh,nh,ih,"top",sh,rh];function ah(t){if(!this.hasSameParentForAllSelected||-1===oh.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(0===e.length)return;const n=this.app.commander;il.around(n,function(){!function(t,e){const n=e[0].parent,{width:i,height:r}=n.bounds;switch(t){case eh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:0}}break;case ih:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i/2-n.width/2}}break;case nh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i-n.width}}break;case"top":for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:0}}break;case sh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:r/2-n.height/2}}break;case rh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:r-n.height}}break;default:;}}(t,e)})}function ch(t){t instanceof Array||(t=[t]),this.trigger("addstart",t)}function lh(){this.trigger("stylepastestart")}function hh(){this.trigger("stylepastestop")}function dh(){this.trigger("databindpastestart")}function uh(){this.trigger("databindpastestop")}let ph=0,fh=0,gh=0,mh=null;function yh(){gh++;const t=performance.now(),e=t-fh;e>=1e3&&(ph=Math.round(1e3*gh/e),fh=t,gh=0),mh=requestAnimationFrame(yh)}function bh(){null!==mh&&(cancelAnimationFrame(mh),mh=null)}function vh(){return null===mh&&(fh=performance.now(),gh=0,mh=requestAnimationFrame(yh)),ph}const _h=function(){const t=document.createElement("canvas").getContext("2d");return(window.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)}();function xh(t,e){const n=document.createElement("canvas");return n.width=t,n.height=e,n.style.width=t+"px",n.style.height=e+"px",n}const wh=Math.sqrt(3);function Mh(t,e){const n=1.2*e;switch(t){case"size1":return{X:n,Y:n};case"size2":return{X:1.5*n,Y:n};case"size3":return{X:2*n,Y:n};case"size4":return{X:n,Y:1.5*n};case"size5":default:return{X:1.5*n,Y:1.5*n};case"size6":return{X:2*n,Y:1.5*n};case"size7":return{X:n,Y:2*n};case"size8":return{X:1.5*n,Y:2*n};case"size9":return{X:2*n,Y:2*n}}}function Sh(t,n,i){switch(t){case"none":default:return null;case"arrow":{const t=wh*n.X,i=n.Y,r=new e.ConeGeometry(i,t,16);return r.rotateZ(-Math.PI/2),r.translate(-t/2,0,0),{mesh:new e.Mesh(r,new e.MeshBasicMaterial)}}case"sharp-arrow":{const t=wh*n.X*1.3,i=.65*n.Y,r=new e.ConeGeometry(i,t,16);return r.rotateZ(-Math.PI/2),r.translate(-t/2,0,0),{mesh:new e.Mesh(r,new e.MeshBasicMaterial)}}case"open-arrow":{const t=wh*n.X,i=n.Y,r=new e.ConeGeometry(i,t,6);return r.rotateZ(-Math.PI/2),r.translate(-t/2,0,0),{mesh:new e.Mesh(r,new e.MeshBasicMaterial({wireframe:!0}))}}case"diamond":{const t=new e.OctahedronGeometry(1);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"oval":{const t=new e.SphereGeometry(1,16,12);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"cross":{const t=Math.max(n.X,n.Y),i=.9*t,r=.25*t,s=.15*t,o=new e.Group,a=[new e.Vector3(1,1,1).normalize(),new e.Vector3(1,-1,-1).normalize(),new e.Vector3(-1,1,-1).normalize(),new e.Vector3(-1,-1,1).normalize()];for(const t of a){const n=new e.CylinderGeometry(r,s,i,6),a=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,1,0),t);n.applyQuaternion(a),n.translate(t.x*i/2,t.y*i/2,t.z*i/2),o.add(new e.Mesh(n,new e.MeshBasicMaterial))}return{group:o}}}}function kh(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Ah(t,n,i,r){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,begin:c="none",beginSize:l="size2",end:h="arrow",endSize:d="size2",label:u}=i,m=(new e.Vector3).subVectors(n,t),y=m.length(),b=new e.Group;if(y<.01)return b;const v=m.clone().normalize(),_=kh(c,a),x=kh(h,a),w=t.clone().add(v.clone().multiplyScalar(_)),M=n.clone().sub(v.clone().multiplyScalar(x));let S;if(Array.isArray(s)&&s.length>=2){const t=s[1];S=new e.Color(t.length>7?t.slice(0,7):t)}else S=new e.Color("string"==typeof s?s:"#00B050");const k=function(t,n,i,r){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,lineDash:c="solid"}=i,l=new g;let h;l.setPositions([t.x,t.y,t.z,n.x,n.y,n.z]);let d=!1;if(Array.isArray(s)&&s.length>=2){const t=new e.Color(s[0].length>7?s[0].slice(0,7):s[0]),n=new e.Color(s[1].length>7?s[1].slice(0,7):s[1]);l.setColors([t.r,t.g,t.b,n.r,n.g,n.b]),d=!0,h=n}else h=new e.Color("string"==typeof s?s:"#00B050");const{dashed:u,dashSize:m,gapSize:y}=function(t,e){switch(t){case"solid":default:return{dashed:!1,dashSize:1,gapSize:0};case"round-dot":return{dashed:!0,dashSize:e,gapSize:2*e};case"square-dot":return{dashed:!0,dashSize:2*e,gapSize:e};case"dash":return{dashed:!0,dashSize:4*e,gapSize:1.5*e};case"dash-dot":return{dashed:!0,dashSize:2.5*e,gapSize:1.5*e};case"long-dash":return{dashed:!0,dashSize:6*e,gapSize:3*e};case"long-dash-dot":return{dashed:!0,dashSize:3.5*e,gapSize:2*e};case"long-dash-dot-dot":return{dashed:!0,dashSize:3*e,gapSize:1.5*e}}}(c,a),b=new f({color:d?16777215:h.getHex(),linewidth:a,worldUnits:!0,vertexColors:d,dashed:u,dashSize:m,gapSize:y,transparent:o<1||Array.isArray(s)&&s.some(t=>t.length>7),opacity:o,resolution:r}),v=new p(l,b);return v.computeLineDistances(),v}(w,M,i,r);b.add(k);const A=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),v),E=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),v.clone().negate()),C=(t,e,n)=>{if(!t)return;const i=t.mesh||t.line2||t.group;if(i){if(i.position.copy(e),i.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(S),e.transparent=o<1,e.opacity=o}else if(t.line2){const e=t.line2.material;e.color.copy(S),e.transparent=o<1,e.opacity=o,e.resolution.copy(r)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color.copy(S),e.transparent=o<1,e.opacity=o,e.resolution&&e.resolution.copy(r)}});b.add(i)}};C(Sh(h,Mh(d,a)),n,A);if(C(Sh(c,Mh(l,a)),t,E),u){const i=(new e.Vector3).addVectors(t,n).multiplyScalar(.5);i.y+=3;const r=function(t,n,i){const r="Arial",s=xh(256,64),o=s.getContext("2d");o.font=`bold 28px ${r}`;const a=o.measureText(t).width;o.fillStyle=n,o.fillRect(0,0,a+12,40),o.fillStyle="white",o.font=`bold 28px ${r}`,o.textBaseline="top",o.fillText(t,6,6);const c=new e.CanvasTexture(s);c.needsUpdate=!0,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace;const l=new e.SpriteMaterial({map:c,transparent:!0}),h=new e.Sprite(l);h.position.copy(i);const d=(a+12)/40;return h.scale.set(4*d,4,1),h}(u,"string"==typeof s?s:Array.isArray(s)&&s[1]||"#00B050",i);b.add(r)}return b}const Eh=.001;function Ch(t,e,n){let i=1;if(n&&"none"!=n&&"transparent"!=n){i=e*("string"==typeof n?b(n).getAlpha():1)}else i=0;t.opacity=i,t.transparent=i<1}function Th(t){const e=b(t);return e.isValid()?e.toHexString():t}const Ph={width:1,height:1,depth:1},Dh={x:1,y:1,z:1},Oh={x:0,y:0,z:0},zh={x:0,y:0,z:0},Ih={default:{metalness:0,roughness:.4},metal:{metalness:1,roughness:.3,envMapIntensity:1},glass:{metalness:0,roughness:.1,opacity:.3,envMapIntensity:1.5},plastic:{metalness:0,roughness:.4},wood:{metalness:0,roughness:.8,envMapIntensity:.3},ceramic:{metalness:.1,roughness:.2,envMapIntensity:.3},rubber:{metalness:0,roughness:.9,envMapIntensity:.3}};function Lh(t){if(!t)return{metalness:0,roughness:.4,emissive:"#000000",emissiveIntensity:0,opacity:1,envMapIntensity:.5,side:"double",castShadow:!0,receiveShadow:!1};const e=Ih[t.preset??"default"]??Ih.default;return{metalness:t.metalness??e.metalness,roughness:t.roughness??e.roughness,emissive:t.emissive??"#000000",emissiveIntensity:t.emissiveIntensity??0,opacity:t.opacity??e.opacity??1,envMapIntensity:t.envMapIntensity??e.envMapIntensity??.5,side:t.side??"double",castShadow:t.castShadow??!0,receiveShadow:t.receiveShadow??!1}}const jh={double:e.DoubleSide,front:e.FrontSide,back:e.BackSide};function Rh(t){return jh[t]??e.DoubleSide}function Fh(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.emissive.set(e.emissive),t.emissiveIntensity=e.emissiveIntensity,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity,t.side=Rh(e.side)}const Bh=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap"];function Nh(t){for(const e of Bh){const n=t[e];n?.dispose()}t.dispose()}function Hh(t){t.traverse(t=>{if(t.geometry?.dispose(),t.material){const e=Array.isArray(t.material)?t.material:[t.material];for(const t of e)Nh(t)}})}function Yh(t,e,n){const i=document.createElement("canvas");i.width=e,i.height=n;const r=i.getContext("2d");if(!r)return null;let s;if("radial"===t.gradientType){const i=e/2,o=n/2,a=Math.max(e,n)/2;switch(t.center){case"left-top":s=r.createRadialGradient(0,0,0,0,0,2*a);break;case"right-top":s=r.createRadialGradient(e,0,0,e,0,2*a);break;case"left-bottom":s=r.createRadialGradient(0,n,0,0,n,2*a);break;case"right-bottom":s=r.createRadialGradient(e,n,0,e,n,2*a);break;default:s=r.createRadialGradient(i,o,0,i,o,a)}}else{const i=t.rotation??0,o=e/2,a=n/2,c=Math.cos(i)*o,l=Math.sin(i)*a;s=r.createLinearGradient(o-c,a-l,o+c,a+l)}for(const e of t.colorStops)if(e.position>=0&&e.position<=1)try{s.addColorStop(e.position,e.color)}catch{s.addColorStop(e.position,"#fff")}return r.fillStyle=s,r.fillRect(0,0,e,n),i}function Vh(t){const{fillStyle:n}=t.state;if(n&&"object"==typeof n)return"pattern"===n.type&&n.image?function(t,n){const{width:i,height:r}=t.state,s=Math.abs(i)||1,o=Math.abs(r)||1,a=new e.Texture;a.colorSpace=e.SRGBColorSpace;const c=new Image;"data"!==String(n.image).substring(0,4)&&(c.crossOrigin="anonymous"),c.onload=()=>{const i=2*s,r=2*o,l=document.createElement("canvas");l.width=i,l.height=r;const h=l.getContext("2d");if(h){if(n.color&&(h.fillStyle=n.color,h.fillRect(0,0,i,r)),n.fitPattern)h.drawImage(c,0,0,i,r);else{const t=2*(n.width||c.naturalWidth),e=2*(n.height||c.naturalHeight),s=2*(n.offsetX||0),o=2*(n.offsetY||0);let a=0,l=0;switch(n.align){case"center":a=(i-t)/2,l=(r-e)/2;break;case"left-top":break;case"left-bottom":l=r-e;break;case"right-top":a=i-t;break;case"right-bottom":a=i-t,l=r-e;break;case"left":l=(r-e)/2;break;case"right":a=i-t,l=(r-e)/2;break;case"top":a=(i-t)/2;break;case"bottom":a=(i-t)/2,l=r-e}const d=s+a,u=o+l;if(n.noRepeat)h.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,d,u,t,e);else{h.save(),h.rect(0,0,i,r),h.clip();const n=d>0?d-Math.ceil(d/t)*t:d;for(let s=u>0?u-Math.ceil(u/e)*e:u;s<r;s+=e)for(let r=n;r<i;r+=t)h.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,r,s,t,e);h.restore()}}a.image=l,a.minFilter=e.LinearFilter,a.needsUpdate=!0,t.invalidate()}},c.onerror=t=>{Ki("Pattern texture load error:",t)};const l=n.image;c.src=t.app.url(l);const h=t.root?.app?.loadTracker;if(h){const t=new Promise((t,e)=>{c.addEventListener("load",()=>t(),{once:!0}),c.addEventListener("error",()=>e(),{once:!0})});h.track(`pattern:${l}`,"pattern",l,t)}return a}(t,n):"gradient"===n.type&&n.colorStops?.length?function(t){const n=Yh(t,256,256);if(!n)return;const i=new e.CanvasTexture(n);return i.colorSpace=e.SRGBColorSpace,i.needsUpdate=!0,i}(n):void 0}function Gh(t,e){return-1!==t.findIndex(t=>t in e)}class Uh{static buildFillStyleTexture(t){return Vh(t)}constructor(t){this._focused=!1,this._suppressOnchange=!1,this._onchangeWrapper=(t,e,n)=>{this._suppressOnchange||n&&n.origin&&n.origin!==this._component||this.onchange(t,e)},this.suppressTransform=!1,this._component=t,this.object3d=this.getObject3dInstance(),this.component.on("change",this._onchangeWrapper)}update(){this.clear(),this.build(),this.updateTransform(),this.updateFillStyle(),this.updateStrokeStyle(),this.updateAlpha(),this.updateHidden(),this.updateText()}getObject3dInstance(){return new e.Object3D}build(){this.object3d.userData.context=this;const t=Lh(this.component.state.material3d);this._applyShadow(t.castShadow,t.receiveShadow),this.object3d.name=this.component.state.id}updateMaterial3d(){const t=Lh(this.component.state.material3d);this._applyShadow(t.castShadow,t.receiveShadow)}_applyShadow(t,e){this.object3d.castShadow=t,this.object3d.receiveShadow=e,this.object3d.traverse(n=>{n!==this.object3d&&(n.castShadow=t,n.receiveShadow=e)})}get gizmoTransformable(){return!0}get allowedGizmoModes(){return null}get component(){return this._component}get threeContainer(){let t=this.component;for(;t;){if("is3dContainer"in t&&t.is3dContainer())return t;t=t.parent}}get focused(){return this._focused}set focused(t){this._focused=t,t&&(this._focusedAt=performance.now())}dispose(){this.component.off("change",this._onchangeWrapper),this.clear()}clear(){const t=[];for(const e of this.object3d.children){const n=e.userData?.context;n&&n!==this&&n instanceof Uh?t.push(e):Hh(e)}this._components3D=void 0,this.object3d.userData={},this.object3d.clear();for(const e of t)this.object3d.add(e);return this.object3d}updateTransform(){if(this.suppressTransform)return;if(this.component.state.screenFixed&&this.component.isHTMLElement()){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{};return this.object3d.position.set(t-n/2,-(e-i/2),0),void this.object3d.rotation.set(0,0,0)}const{x:t,y:e,z:n}=this.position,{x:i,y:r,z:s}=this.rotation,{x:o,y:a,z:c}=this.scale;this.object3d.position.set(t,e,n),this.object3d.rotation.set(i,r,s),this.object3d.scale.set(Math.max(o,Eh),Math.max(a,Eh),Math.max(c,Eh))}get position(){const{x:t,y:e,z:n}=this.center;return{x:t,y:n,z:e}}get rotation(){const{rotationX:t=0,rotationY:e=0,rotation:n=0}=this.component.state;return{x:t,y:-n,z:e}}get scale(){const{scale:t}=this.component.state,e="number"==typeof t?t:t?.x??1;return{x:e,y:e,z:e}}get cx(){const{x:t=0}=this.component.center,{width:e=0}=this.component.parent?.bounds??{},{tx:n=0}=this.component.delta();return t+n-e/2}get cy(){const{y:t=0}=this.component.center,{height:e=0}=this.component.parent?.bounds??{},{ty:n=0}=this.component.delta();return t+n-e/2}get cz(){const{zPos:t=0}=this.component.state,{tz:e=0}=this.component.delta(),n=this.component.parent?._realObject,i=n?.geometricOffsetY??0;return t+e+this.syncZPosOffset-i}get geometricOffsetY(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get scenePlacement(){const t=this.component.rootModel??this.component,e=t?.state?.placement;return"space"===e||"inverted"===e?e:"floor"}get components3D(){return this._components3D&&this._components3D.parent===this.object3d||(this._components3D=new e.Group,this.object3d.add(this._components3D)),this._components3D.position.y=-this.geometricOffsetY,this._components3D}get center(){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{},{tx:r=0,ty:s=0}=this.component.delta();return{x:t+r-n/2,y:e+s-i/2,z:this.cz}}freezeDimension(){this._frozenDimension={...this.dimension}}unfreezeDimension(){delete this._frozenDimension}get dimension(){if(this._frozenDimension)return this._frozenDimension;const{width:t,height:e}=this.component.bounds;return{width:Math.abs(t)||1,height:Math.abs(e)||1,depth:this.effectiveDepth}}get effectiveDepth(){return this.component.state.depth||1}updatePosition(){const{x:t=0,y:e=0,z:n=0}=this.position;this.object3d.position.set(t,e,n)}updateRotate(){const{x:t=0,y:e=0,z:n=0}=this.rotation;this.object3d.rotation.set(t,e,n)}updateScale(){const{x:t=1,y:e=1,z:n=1}=this.scale;this.object3d.scale.set(Math.max(t,Eh),Math.max(e,Eh),Math.max(n,Eh))}syncAnimationDelta(){if(this.suppressTransform)return;const t=this.component.delta();this.updatePosition();const{rotationX:e=0,rotationY:n=0,rotation:i=0}=this.component.state,r=t.theta||0,s=t.rx||0,o=t.ry||0,a=t.rz||0;this.object3d.rotation.set(e+s,-(i+r)+o,n+a);const{scale:c}=this.component.state,l="number"==typeof c?c:c?.x??1,h=t.sx??1,d=t.sy??1,u=t.sz??1;this.object3d.scale.set(Math.max(l*h,Eh),Math.max(l*d,Eh),Math.max(l*u,Eh));const p=t.fade||0;if(0!==p){const t=(this.component.state.alpha??1)*(1-p);this.object3d.traverse(e=>{if(e.isMesh&&e.material){const n=Array.isArray(e.material)?e.material:[e.material];for(const e of n)e.opacity=t,e.transparent=e.opacity<1}})}}updateDimension(){this.clear(),this.build()}updateAlpha(){let{alpha:t}=this.component.state;t=null==t?1:t,this.object3d.traverse(e=>{let n=e.material;e.material&&(Array.isArray(n)||(n=[n]),n.forEach(e=>{e.opacity*=t,e.transparent=t<1}))})}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateStrokeStyle(){}updateFillStyle(){}updateText(){}get syncZPosOffset(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get textSurfaceYOffset(){return this.effectiveDepth-this.syncZPosOffset}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},r=e.bounds,{tx:s=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0,e.bounds={left:t.position.x-s+n/2-r.width/2,top:t.position.z-o+i/2-r.height/2,width:r.width,height:r.height};const c=this.component.parent?._realObject,l=c?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+l,rotationX:t.rotation.x,rotation:-t.rotation.y,rotationY:t.rotation.z}),this._suppressOnchange=!1}onGizmoDragEnd(t){}applyDimensionFromGizmo(t){this._suppressOnchange=!0,this._component.set(t),this._suppressOnchange=!1}onchange(t,e){if("screenFixed"in t&&this.updateTransform(),Gh(["cx","cy","cz","zPos","left","top"],t)&&this.updatePosition(),Gh(["width","height","depth","lineWidth","round"],t)&&(this.updateDimension(),"depth"in t)){this.updatePosition();const t=this.component.components;if(t)for(const e of t){const t=e?._realObject;t?.updateTransform&&t.updateTransform()}}if(Gh(["rotationX","rotationY","rotation"],t)&&this.updateRotate(),"scale"in t&&this.updateScale(),"hidden"in t&&this.updateHidden(),"alpha"in t&&this.updateAlpha(),"strokeStyle"in t&&this.updateStrokeStyle(),"fillStyle"in t&&this.updateFillStyle(),Gh(["text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline"],t))this._lastText=this.component.hasTextProperty?this.component.text:"",this.updateText();else if(Gh(["value","data"],t)){const t=this.component.hasTextProperty?this.component.text:"";t!==this._lastText&&(this._lastText=t,this.updateText())}"material3d"in t&&this.updateMaterial3d()}}class Wh extends Uh{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}getObject3dInstance(){return new m(this.component.element)}get rotation(){const{rotationX:t=0,rotationY:e=0,rotation:n=0}=this.component.state;return{x:t-Math.PI/2,y:e,z:-n}}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},r=e.bounds,{tx:s=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0;const c=t.scale.x;e.bounds={left:t.position.x-s+n/2-r.width/2,top:t.position.z-o+i/2-r.height/2,width:r.width,height:r.height};const l=this.component.parent?._realObject,h=l?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+h,rotationX:t.rotation.x+Math.PI/2,rotation:-t.rotation.z,rotationY:t.rotation.y,scale:{x:c,y:c}}),this._suppressOnchange=!1}build(){super.build();const t=this.component.element;if(!t)return;const{width:e,height:n}=this.component.bounds;t.style.width=e+"px",t.style.height=n+"px",t.style.left="",t.style.top=""}updateDimension(){super.updateDimension();const t=this.dimension,e=this.component.element;e&&(e.style.width=t.width+"px",e.style.height=t.height+"px")}updateAlpha(){super.updateAlpha();const{alpha:t=1}=this.component.state,e=this.component.element;e&&(e.style.opacity=String(t))}}const Xh=new Map;let qh;function Kh(t,e){Xh.set(t,e)}function $h(t){qh=t}function Qh(t){const e=t.buildRealObject();if(e)return e;const n=t.model?.type,i=n?Xh.get(n):void 0;if(i)return i(t);if(t.isHTMLElement()){const e=Xh.get("html-overlay-element");if(e)return e(t)}return qh?.(t)}function Zh(t,n,i){if(!t.hasTextProperty||t.textHidden)return;const r=t._realObject;if(!r?.object3d)return;const{text:s="",bold:o=Gr.BOLD,italic:a=Gr.ITALIC,fontFamily:c=Gr.FONT_FAMILY,fontColor:l=Gr.FONT_COLOR,fontSize:h=Gr.FONT_SIZE,textAlign:d=Gr.TEXT_ALIGN,textBaseline:u=Gr.TEXT_BASELINE,width:p,height:f}=t.model,g=Math.abs(p)||1,y=Math.abs(f)||1,b=document.createElement("textarea"),v=new AbortController;Yr.forEach(t=>{b.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:v.signal})}),b.value=s;const _="right"===d||"end"===d?"right":"left"===d||"start"===d?"left":"justify"===d?"justify":"center";let x="0";if("bottom"===u||"alphabetic"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);x=Math.max(0,y-t)+"px"}else if("middle"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);x=Math.max(0,(y-t)/2)+"px"}b.style.cssText=[`width: ${g}px`,`height: ${y}px`,`padding: ${x} 0 0 0`,"margin: 0",`font-family: ${c}`,`font-size: ${h}px`,`line-height: ${1.2*h}px`,"overflow: hidden","resize: none","outline: 1px solid #f26522","border: 0","background-color: rgba(255, 255, 255, 0.85)","display: block",`color: ${l}`,"box-sizing: border-box","font-weight: "+(o?"bold":"normal"),"font-style: "+(a?"italic":"normal"),`text-align: ${_}`].join("; ");const w=new m(b),M=r.object3d;M.updateWorldMatrix(!0,!1);const S=new e.Vector3,k=new e.Quaternion,A=new e.Vector3;M.matrixWorld.decompose(S,k,A);const E=new e.Vector3(0,r.textSurfaceYOffset,0);E.multiply(A),E.applyQuaternion(k),w.position.copy(S).add(E);const C=(new e.Quaternion).setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2);w.quaternion.copy(k).multiply(C),w.scale.copy(A),n.css3DScene.add(w),i();const T=n.css3DRenderer.domElement,P=T.style.getPropertyValue("pointer-events"),D=T.style.getPropertyPriority("pointer-events"),O=[];let z=b;for(;z&&z!==T.parentElement;)O.push({el:z,saved:z.style.pointerEvents}),z.style.setProperty("pointer-events","auto","important"),z=z.parentElement;b.focus(),b.select();let I=!1;const L=t.root?.selected;b.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"!==t.code&&(t.shiftKey||"Enter"!==t.code&&"NumpadEnter"!==t.code)||(I="Escape"===t.code,b.blur())},{signal:v.signal});const j=()=>{n.css3DScene.remove(w);for(const{el:t,saved:e}of O)e?t.style.pointerEvents=e:t.style.removeProperty("pointer-events");D?T.style.setProperty("pointer-events",P,D):P&&T.style.setProperty("pointer-events",P),v.abort(),b.removeEventListener("blur",j),L&&t.root&&(t.root.selected=L),I||b.value===s||t.app.commander.execute(new il({changes:[{component:t,before:{text:s},after:{text:b.value}}]})),i()};b.addEventListener("blur",j)}class Jh extends n{dispose(){const t=new Set;this.traverse(e=>{if(e.isMesh){t.add(e.geometry);const n=e.material;Array.isArray(n)?n.forEach(e=>t.add(e)):t.add(n)}});for(const e of t)e.dispose()}}function td(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity,t.polygonOffset=!0,t.polygonOffsetFactor=1,t.polygonOffsetUnits=1}function ed(t){const{fillStyle:n,floorMaterial3d:i,placement:r}=t.state,s=Lh({...i,preset:i?.preset??"rubber",envMapIntensity:i?.envMapIntensity??0});if("none"===n)return;if("space"===r)return;const o=new e.BoxGeometry(1,1,1);let a;if(n){const i=Uh.buildFillStyleTexture(t);if(i){const t="#424b57",n=[new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({map:i}),new e.MeshStandardMaterial({color:t})];n.forEach(t=>td(t,s)),a=n}else if("string"==typeof n){const t=new e.MeshStandardMaterial({color:n});td(t,s),a=t}}if(!a){const t=new e.MeshStandardMaterial({color:"#e0e0e0"});td(t,s),a=t}const c=new e.Mesh(o,a),{width:l,height:h}=t.state;return c.scale.set(l,h,5),c.rotation.x=-Math.PI/2,c.position.y="inverted"===r?3.5:-3.5,c.name="floor",c.receiveShadow=!1!==i?.receiveShadow,c.castShadow=!0===i?.castShadow,c}const nd={studio:class extends Jh{constructor(){super(),this.name="StudioEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:13421772}),n=new o(t,e);n.position.set(0,13,0),n.scale.set(40,30,35),this.add(n);const l=new r({color:11184810,roughness:.8}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(40,.5,35),this.add(h);const d=new a(16777215,500,40,2);d.position.set(0,24,0),this.add(d);const u=new a(16777215,200,30,2);u.position.set(-10,22,-8),this.add(u);const p=new a(16777215,200,30,2);p.position.set(10,22,8),this.add(p);const f=(e,n,i)=>{const r=new c({color:0,emissive:16777215,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,26,n),s.scale.set(6,.1,6),s};this.add(f(-8,-6,60)),this.add(f(8,-6,60)),this.add(f(-8,6,60)),this.add(f(8,6,60)),this.add(f(0,0,50))}},warehouse:class extends Jh{constructor(){super(),this.name="WarehouseEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:8425632}),n=new o(t,e);n.position.set(0,18,0),n.scale.set(50,40,40),this.add(n);const l=new r({color:9474192,roughness:.9}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(50,.5,40),this.add(h);const d=new a(15266047,600,50,2);d.position.set(-10,30,0),this.add(d);const u=new a(15266047,600,50,2);u.position.set(10,30,0),this.add(u);const p=(e,n,i)=>{const r=new c({color:0,emissive:15266047,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,35,n),s.scale.set(8,.1,2),s};this.add(p(-12,-6,80)),this.add(p(-12,6,80)),this.add(p(0,0,60)),this.add(p(12,-6,80)),this.add(p(12,6,80));const f=new o(t,new c({color:0,emissive:16772829,emissiveIntensity:15}));f.position.set(0,10,-19),f.scale.set(12,8,.1),this.add(f)}},factory:class extends Jh{constructor(){super(),this.name="FactoryEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:6318192,metalness:.1,roughness:.8}),n=new o(t,e);n.position.set(0,20,0),n.scale.set(60,44,45),this.add(n);const l=new r({color:8028272,roughness:.7,metalness:.05}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(60,.5,45),this.add(h);const d=(t,e)=>{const n=new a(15791615,800,55,2);return n.position.set(t,35,e),n};this.add(d(-15,-10)),this.add(d(-15,10)),this.add(d(0,0)),this.add(d(15,-10)),this.add(d(15,10));const u=(e,n,i)=>{const r=new c({color:0,emissive:15791615,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,38,n),s.scale.set(6,.1,3),s};this.add(u(-18,-10,90)),this.add(u(-18,10,90)),this.add(u(0,-10,70)),this.add(u(0,10,70)),this.add(u(18,-10,90)),this.add(u(18,10,90));const p=new o(t,new c({color:0,emissive:11206570,emissiveIntensity:10}));p.position.set(28,14,-21),p.scale.set(1,2,.1),this.add(p);const f=new o(t,new c({color:0,emissive:16772829,emissiveIntensity:25}));f.position.set(0,8,-22),f.scale.set(10,10,.1),this.add(f)}},office:class extends Jh{constructor(){super(),this.name="OfficeEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:14209224}),n=new o(t,e);n.position.set(0,10,0),n.scale.set(35,22,30),this.add(n);const l=new r({color:10524808,roughness:.85}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(35,.5,30),this.add(h);const d=new a(16774374,400,30,2);d.position.set(0,17,0),this.add(d);const u=(e,n,i)=>{const r=new c({color:0,emissive:16775408,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,19.5,n),s.scale.set(4,.1,4),s};this.add(u(-8,-6,60)),this.add(u(-8,6,60)),this.add(u(8,-6,60)),this.add(u(8,6,60)),this.add(u(0,0,50));const p=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:30}));p.position.set(17,10,0),p.scale.set(.1,6,12),this.add(p);const f=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:20}));f.position.set(-17,10,0),f.scale.set(.1,4,8),this.add(f)}},home:class extends Jh{constructor(){super(),this.name="HomeEnvironment",this.position.y=-3.5;const t=new i;t.deleteAttribute("uv");const e=new r({side:s,color:15261136}),n=new o(t,e);n.position.set(0,8,0),n.scale.set(28,18,24),this.add(n);const l=new r({color:11571312,roughness:.7}),h=new o(t,l);h.position.set(0,-1.5,0),h.scale.set(28,.5,24),this.add(h);const d=new a(16770244,300,25,2);d.position.set(0,14,0),this.add(d);const u=new a(16767152,100,20,2);u.position.set(-8,12,-6),this.add(u);const p=(e,n,i)=>{const r=new c({color:0,emissive:16771280,emissiveIntensity:i}),s=new o(t,r);return s.position.set(e,15.5,n),s.scale.set(3,.1,3),s};this.add(p(0,0,40)),this.add(p(-6,-4,25)),this.add(p(6,4,25));const f=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:35}));f.position.set(13.5,8,0),f.scale.set(.1,8,10),this.add(f);const g=new o(t,new c({color:0,emissive:14544639,emissiveIntensity:15}));g.position.set(-13.5,9,3),g.scale.set(.1,5,6),this.add(g)}},sunny:class extends Jh{constructor(){super(),this.name="SunnyEnvironment";const t=new v;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=2,e.rayleigh.value=1.5,e.mieCoefficient.value=.005,e.mieDirectionalG.value=.8;const n=l.degToRad(60),i=l.degToRad(135),r=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,r,i),this.add(t)}},cloudy:class extends Jh{constructor(){super(),this.name="CloudyEnvironment";const t=new v;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=10,e.rayleigh.value=.3,e.mieCoefficient.value=.03,e.mieDirectionalG.value=.7;const n=l.degToRad(50),i=l.degToRad(120),r=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,r,i),this.add(t)}},rainy:class extends Jh{constructor(){super(),this.name="RainyEnvironment";const t=new v;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=20,e.rayleigh.value=.1,e.mieCoefficient.value=.05,e.mieDirectionalG.value=.6;const n=l.degToRad(40),i=l.degToRad(110),r=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,r,i),this.add(t)}}};class id{get scene(){return this._scene}get mixer(){return this._mixer}setup(){return this._scene=new e.Scene,this._scene}setupMixer(){return this._timer=new e.Timer,this._timer.connect(document),this._mixer=new e.AnimationMixer(this._scene),this._mixer}setupEnvironment(t){this._renderer=t}_applyEnvironment(t){if(this._envTexture&&(this._envTexture.dispose(),this._envTexture=void 0),!this._renderer||!this._scene)return;const n=new(0,nd[t]),i=new e.PMREMGenerator(this._renderer);this._envTexture=i.fromScene(n).texture,this._scene.environment=this._envTexture,n.dispose(),i.dispose()}_clearEnvironment(){this._envTexture&&(this._envTexture.dispose(),this._envTexture=void 0),this._scene&&(this._scene.environment=null)}setSky(t,n){if(!this._scene||!this._renderer)return;const i=t;i&&i in nd?(this._applyEnvironment(i),this._scene.background=this._envTexture):"color"===t&&n?(this._clearEnvironment(),this._scene.background=new e.Color(n)):(this._clearEnvironment(),this._scene.background=null)}addFloor(t){const e=ed(t);e&&this._scene.add(e)}updateFloor(t){if(!this._scene)return;const e=this._scene.children.find(t=>"floor"===t.name);e&&(Hh(e),this._scene.remove(e)),this.addFloor(t)}addObject(t){this._scene.add(t)}updateAnimation(){this._mixer&&this._timer&&(this._timer.update(),this._mixer.update(this._timer.getDelta()))}destroy(){this._mixer&&(this._mixer.stopAllAction(),this._mixer.uncacheRoot(this._scene)),this._envTexture&&(this._envTexture.dispose(),delete this._envTexture),this._scene&&(this._scene.environment=null,Hh(this._scene),this._scene.clear()),delete this._scene,delete this._mixer,delete this._renderer,this._timer&&this._timer.disconnect(),delete this._timer}}class rd{constructor(){this._activeView="perspective",this._cameraZPos=0}get camera(){return this._perspCamera}get activeCamera(){return"perspective"!==this._activeView&&this._orthoCamera?this._orthoCamera:this._perspCamera}get activeView(){return this._activeView}get cameraZPos(){return this._cameraZPos}setup(t,n,i){const{fov:r,near:s,far:o,cameraX:a,cameraY:c,cameraZ:l}=i,h=t/n;this._perspCamera=new e.PerspectiveCamera(r,h,s,o);const d=Math.sqrt(t*t+n*n),u=(r||45)/2*Math.PI/180,p=d/2/Math.tan(u)*.75,f=25*Math.PI/180,g=30*Math.PI/180,m=p*Math.sin(f),y=p*Math.cos(f);let b=y*Math.sin(g),v=y*Math.cos(g);return this._cameraZPos=Math.floor(m),null!=a&&(b=a*t),null!=c&&(v=c*n),null!=l&&(this._cameraZPos=l*Math.floor(Math.min(t,n))),this._perspCamera.position.set(b,this._cameraZPos,v),this._activeView="perspective",this._perspCamera}addToScene(t){t.add(this._perspCamera),this._perspCamera.lookAt(t.position)}updateAspect(t,e){if(this._perspCamera&&(this._perspCamera.aspect=t/e,this._perspCamera.updateProjectionMatrix()),this._orthoCamera){const n=this._orthoCamera,i=(n.top-n.bottom)/2,r=t/e;n.left=-i*r,n.right=i*r,n.updateProjectionMatrix()}}updateProperties(t){this._perspCamera&&(void 0!==t.fov&&(this._perspCamera.fov=t.fov),void 0!==t.near&&(this._perspCamera.near=t.near),void 0!==t.far&&(this._perspCamera.far=t.far),this._perspCamera.updateProjectionMatrix())}setOrthoView(t,n,i,r,s){this._orthoCamera||(this._orthoCamera=new e.OrthographicCamera(-1,1,1,-1,.1,5e4)),this.updateOrthoFrustum(n,i,r,s);const o=this._orthoCamera;o.zoom=1;const a=2*Math.max(n,i);switch(t){case"top":o.position.set(0,a,0),o.up.set(0,0,-1);break;case"front":o.position.set(0,0,a),o.up.set(0,1,0);break;case"back":o.position.set(0,0,-a),o.up.set(0,1,0);break;case"right":o.position.set(a,0,0),o.up.set(0,1,0);break;case"left":o.position.set(-a,0,0),o.up.set(0,1,0)}return o.lookAt(0,0,0),o.updateProjectionMatrix(),this._activeView=t,o}restorePerspective(){return this._activeView="perspective",this._perspCamera}updateOrthoFrustum(t,e,n,i){if(!this._orthoCamera)return;const r=(n||t)/(i||e),s=Math.max(t,e)/2;r>=1?(this._orthoCamera.left=-s*r,this._orthoCamera.right=s*r,this._orthoCamera.top=s,this._orthoCamera.bottom=-s):(this._orthoCamera.left=-s,this._orthoCamera.right=s,this._orthoCamera.top=s/r,this._orthoCamera.bottom=-s/r),this._orthoCamera.updateProjectionMatrix()}destroy(){delete this._perspCamera,delete this._orthoCamera,this._activeView="perspective"}}class sd{constructor(){this._noSupportWebgl=!1}get renderer(){return this._renderer}setExposure(t){this._renderer&&(this._renderer.toneMappingExposure=t)}get css3DRenderer(){return this._css3DRenderer||(this._css3DRenderer=this.createCSS3DRenderer()),this._css3DRenderer}get css3DScene(){return this._css3DScene||(this._css3DScene=new e.Scene),this._css3DScene}get composer(){return this._composer}get noSupportWebgl(){return this._noSupportWebgl}get domElement(){return this._renderer?.domElement}get hudScene(){return this._hudScene||(this._hudScene=new e.Scene),this._hudScene}get hudCSS3DScene(){return this._hudCSS3DScene||(this._hudCSS3DScene=new e.Scene),this._hudCSS3DScene}get hudCamera(){return this._hudCamera}setupHUD(t,n){this._hudCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCamera.position.set(0,5e3,0),this._hudCamera.lookAt(0,0,0),this._hudCSS3DCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCSS3DCamera.position.set(0,0,1e3),this._hudCSS3DCamera.lookAt(0,0,0),this._hudCSS3DRenderer=new y,this._hudCSS3DRenderer.setSize(t,n);const i=this._hudCSS3DRenderer.domElement;i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.pointerEvents="none",i.setAttribute("scene","model-layer:css3d-hud-renderer");const r=new e.AmbientLight(16777215,3);this.hudScene.add(r);const s=new Float32Array(64).fill(1),o=new e.DataTexture(s,4,4,e.RGBAFormat,e.FloatType);o.mapping=e.EquirectangularReflectionMapping,o.needsUpdate=!0,this.hudScene.environment=o}resizeHUD(t,e){this._hudCamera&&(this._hudCamera.right=t,this._hudCamera.bottom=-e,this._hudCamera.updateProjectionMatrix())}setupWebGL(t,n,i){try{const r=document.createElement("canvas"),s=r.getContext("webgl2");if(!s)return this._noSupportWebgl=!0,!1;const o=new e.WebGLRenderer({canvas:r,context:s,precision:i.precision,alpha:!0,antialias:i.antialias,logarithmicDepthBuffer:i.logarithmicDepthBuffer??!1!==i.postprocessing,premultipliedAlpha:!1});return o.autoClear=!0,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.ACESFilmicToneMapping,o.toneMappingExposure=i.exposure,o.shadowMap.enabled=!1!==i.shadowMap,o.shadowMap.type=e.PCFShadowMap,o.setClearColor(16777215,1),o.setPixelRatio(window.devicePixelRatio),o.setSize(t,n,!1),r.style.width="100%",r.style.height="100%",this._renderer=o,this._noSupportWebgl=!1,!0}catch(t){return this._noSupportWebgl=!0,!1}}setupCSS3D(t,e){const n=this.css3DRenderer.domElement;n.style.position="absolute",n.style.left="0",n.style.top="0",n.style.pointerEvents="none",e&&n.setAttribute("scene",e),n.style.setProperty("pointer-events","none","important")}createCSS3DRenderer(){return new y}setupComposer(t,n,i,r,s){const o=new e.WebGLRenderTarget(i,r,{samples:4});this._composer=new _(this._renderer,o),this._composer.setSize(i,r);const a=new x(t,n);this._composer.addPass(a);const c=new w(new e.Vector2(i,r),t,n);if(c.visibleEdgeColor.set(15885602),c.hiddenEdgeColor.set(15885602),c.edgeStrength=3,c.edgeThickness=1.5,c.edgeGlow=.5,c.pulsePeriod=0,s){const t=c.render.bind(c);c.render=(e,n,i,r,o)=>{const a=s.visible;s.visible=!1,t(e,n,i,r,o),s.visible=a}}return this._outlinePass=c,this._composer.addPass(c),this._composer.addPass(new S),this._composer.addPass(new M),this._composer}setupLightComposer(t,n,i,r){const s=new e.WebGLRenderTarget(i,r);this._composer=new _(this._renderer,s),this._composer.setSize(i,r),this._composer.addPass(new x(t,n));const o=new w(new e.Vector2(i,r),t,n);return o.visibleEdgeColor.set(15885602),o.hiddenEdgeColor.set(15885602),o.edgeStrength=3,o.edgeThickness=1.5,o.edgeGlow=.5,o.pulsePeriod=0,this._outlinePass=o,this._composer.addPass(o),this._composer.addPass(new M),this._composer}get hasOutlinePass(){return!!this._outlinePass}updateRenderPassCamera(t){this._composer&&this._composer.passes.length>0&&(this._composer.passes[0].camera=t),this._outlinePass&&(this._outlinePass.renderCamera=t),this._camera&&(this._camera=t)}setOutlineObjects(t){this._outlinePass&&(this._outlinePass.selectedObjects=t)}resize(t,e){if(this._renderer?.setSize(t,e,!1),this._css3DRenderer?.setSize(t,e),this._composer?.setSize(t,e),this._hudCSS3DRenderer&&this._hudCSS3DCamera){const n=t/(this._hudCSS3DCamera.right-this._hudCSS3DCamera.left),i=e/(this._hudCSS3DCamera.top-this._hudCSS3DCamera.bottom),r=this._hudCSS3DRenderer.domElement;r.style.transformOrigin="0 0",r.style.transform=`scale(${n}, ${i})`}}teardownLightComposer(){this._composer&&(this._outlinePass=void 0,this._composer.dispose(),this._composer=void 0)}setDirectRenderTargets(t,e){this._scene=t,this._camera=e}render(){if(this._composer){if(this._composer.render(),this._renderer){const t=this._renderer.getContext();t.colorMask(!1,!1,!1,!0),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.colorMask(!0,!0,!0,!0)}}else this._renderer&&this._scene&&this._camera&&this._renderer.render(this._scene,this._camera);this.renderHUD()}renderHUD(){if(!this._renderer||!this._hudScene||!this._hudCamera)return;if(0===this._hudScene.children.length)return;const t=this._renderer.autoClear;this._renderer.autoClear=!1,this._renderer.setRenderTarget(null),this._renderer.clearDepth(),this._renderer.render(this._hudScene,this._hudCamera),this._renderer.autoClear=t}renderCSS3D(t){if(this._css3DRenderer?.render(this.css3DScene,t),this._hudCSS3DRenderer&&this._hudCSS3DCamera&&this._hudCSS3DScene){const t=this._hudCSS3DRenderer.domElement;this._hudCSS3DScene.children.length>0?(t.style.display="",this._hudCSS3DRenderer.render(this._hudCSS3DScene,this._hudCSS3DCamera)):t.style.display="none"}}get hudCSS3DRenderer(){return this._hudCSS3DRenderer}getSize(){const t=new e.Vector2;return this._renderer?.getSize(t),{width:t.x,height:t.y}}destroy(){this._outlinePass=void 0,this._composer?.dispose(),this._renderer?.forceContextLoss(),this._renderer?.dispose(),delete this._composer,delete this._renderer,this.disposeHUD()}disposeHUD(){if(this._hudScene){[...this._hudScene.children].forEach(t=>{if(this._hudScene.remove(t),t.geometry&&t.geometry.dispose(),t.material){const e=t.material;e.map&&e.map.dispose(),e.dispose()}}),this._hudScene.environment&&(this._hudScene.environment.dispose(),this._hudScene.environment=null),this._hudScene=void 0}if(this._hudCamera=void 0,this._hudCSS3DScene){[...this._hudCSS3DScene.children].forEach(t=>this._hudCSS3DScene.remove(t)),this._hudCSS3DScene=void 0}this._hudCSS3DRenderer&&(this._hudCSS3DRenderer.domElement.remove(),this._hudCSS3DRenderer=void 0),this._hudCSS3DCamera=void 0}disposeCSS3DScene(){if(this._css3DScene){[...this._css3DScene.children].forEach(t=>this._css3DScene.remove(t))}}}class od{constructor(){this.lights=[]}get hemiLight(){return this._hemiLight}get dirLight(){return this._dirLight}setup(t,n,i){this._scene=t,this._camera=n;const{hemisphere:r,directional:s,point:o}=i;if(this._hemiLight=new e.HemisphereLight(r.skyColor,r.groundColor,r.intensity),t.add(this._hemiLight),this.lights.push(this._hemiLight),s){if(this._dirLight=new e.DirectionalLight(s.color,s.intensity),s.position&&this._dirLight.position.set(...s.position),!1!==s.castShadow){this._dirLight.castShadow=!0;const t=s.shadowMapSize??2048;this._dirLight.shadow.mapSize.set(t,t),this._dirLight.shadow.bias=s.shadowBias??-5e-4;const e=this._dirLight.shadow.camera;e.near=.1,e.far=5e3,e.left=-1500,e.right=1500,e.top=1500,e.bottom=-1500}s.attachToCamera?n.add(this._dirLight):t.add(this._dirLight),this.lights.push(this._dirLight)}if(o){const n=new e.PointLight(o.color,o.intensity,void 0,o.decay);n.power=o.power,n.castShadow=o.castShadow,n.position.set(...o.position),n.shadow.camera.near=o.shadowNear,n.shadow.camera.far=o.shadowFar,t.add(n),this.lights.push(n)}}updateHemisphere(t){this._hemiLight&&(void 0!==t.skyColor&&this._hemiLight.color.set(t.skyColor),void 0!==t.groundColor&&this._hemiLight.groundColor.set(t.groundColor),void 0!==t.intensity&&(this._hemiLight.intensity=t.intensity))}updateDirectional(t){this._dirLight&&(void 0!==t.color&&this._dirLight.color.set(t.color),void 0!==t.intensity&&(this._dirLight.intensity=t.intensity))}setDirectionalFollowCamera(t){this._dirLight&&this._scene&&this._camera&&(this._dirLight.removeFromParent(),t?this._camera.add(this._dirLight):this._scene.add(this._dirLight))}setDirectionalAngle(t,e,n=1e3){if(!this._dirLight)return;const i=t*Math.PI/180,r=e*Math.PI/180,s=n;this._dirLight.position.set(s*Math.cos(r)*Math.sin(i),s*Math.sin(r),s*Math.cos(r)*Math.cos(i)),this._dirLight.target.position.set(0,0,0),!this._dirLight.target.parent&&this._scene&&this._scene.add(this._dirLight.target)}setDirectionalEnabled(t,n){if(t&&!this._dirLight&&this._camera){const t=n?.color??16777215,i=n?.intensity??2;this._dirLight=new e.DirectionalLight(t,i),this._camera.add(this._dirLight),this.lights.push(this._dirLight)}else!t&&this._dirLight&&(this._dirLight.removeFromParent(),this._dirLight.dispose(),this.lights=this.lights.filter(t=>t!==this._dirLight),this._dirLight=void 0)}destroy(){this.lights.forEach(t=>t.dispose()),this.lights=[],this._hemiLight=void 0,this._dirLight=void 0,this._scene=void 0,this._camera=void 0}}const ad=1e-6;class cd{constructor(){this._enabled=!0,this._state=0,this._autoRotate=!1,this._autoRotateSpeed=2,this._dampingFactor=.15,this._rotateSpeed=.1,this._panSpeed=1,this._dollyStart=0,this._lastScale=1,this._floorConstraint=!1,this._spherical=new e.Spherical,this._sphericalDelta=new e.Spherical,this._panOffset=new e.Vector3,this._target=new e.Vector3,this._target0=new e.Vector3,this._position0=new e.Vector3,this._rotateStart=new e.Vector2,this._rotateEnd=new e.Vector2,this._rotateDelta=new e.Vector2,this._panStart=new e.Vector2,this._panEnd=new e.Vector2,this._panDelta=new e.Vector2,this._offset=new e.Vector3,this._lastPosition=new e.Vector3,this._lastQuaternion=new e.Quaternion,this._panLeftV=new e.Vector3,this._panUpV=new e.Vector3,this._panCalcOffset=new e.Vector3}get isActive(){return!!this._camera}get target(){return this._target.clone()}restoreTarget(t){this._target.copy(t),this.update()}get _isOrthoLocked(){return!!this._camera?.isOrthographicCamera}setup(t,n){this._camera=t,this._host=n,this._target.set(0,0,0),this._target0.copy(this._target),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert();const i=n.state;this._autoRotate=!n.app?.isEditMode&&(i.autoRotate||"orbit"===i.cameraAutoPlay)||!1,this._autoRotateSpeed=i.rotationSpeed||2,this._floorConstraint=!n.app?.isEditMode&&!!i.cameraFloorConstraint||!1,this.update()}setEnabled(t){this._enabled=t}setOnUserInteraction(t){this._onUserInteraction=t}onDragStart(t){this._enabled&&(this._onUserInteraction?.(),this._isOrthoLocked?(this._state=2,this._panStart.set(t.offsetX,t.offsetY)):(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,1===this._state?this._rotateStart.set(t.offsetX,t.offsetY):3===this._state?this._dollyStart=t.offsetY:this._panStart.set(t.offsetX,t.offsetY)))}onDragMove(t){if(this._enabled)if(this._isOrthoLocked)this._state=2,this._handlePanMove(t.offsetX,t.offsetY);else if(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,3===this._state){const e=t.offsetY-this._dollyStart;this._dollyStart=t.offsetY;const n=1+.005*e;this.dollyAtCursor(n,0,0)}else 1===this._state?this._handleRotateMove(t.offsetX,t.offsetY):this._handlePanMove(t.offsetX,t.offsetY)}onDragEnd(t){this._state=0,this._host?.invalidate()}onTouchStart(t){this._onUserInteraction?.();const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)return this._panStart.set(n,i),void(this._state=5);switch(t.touches.length){case 1:this._rotateStart.set(n,i),this._state=4;break;case 2:this._lastScale=t.scale||1,this._panStart.set(n,i),this._state=5;break;default:this._state=0}}onTouchMove(t){const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)this._handlePanMove(n,i);else switch(t.touches.length){case 1:if(4!==this._state)return;this._handleRotateMove(n,i);break;case 2:{if(5!==this._state)return;const e=t.scale||1;if(Math.abs(this._lastScale-e)>.01){const t=this._lastScale/e;this._lastScale=e,this.dollyAtCursor(t,0,0)}else this._handlePanMove(n,i);break}default:this._state=0}}onTouchEnd(t){this._lastScale=1,this._state=0}onKeyDown(t){switch(t.code){case"ArrowUp":this._pan(0,7);break;case"ArrowDown":this._pan(0,-7);break;case"ArrowLeft":this._pan(7,0);break;case"ArrowRight":this._pan(-7,0);break;default:return}this.update()}update(){const t=this._camera,e=t.position;if(this._isOrthoLocked)return this._panOffset.lengthSq()>0&&(this._target.add(this._panOffset),e.add(this._panOffset),this._panOffset.set(0,0,0)),(this._lastPosition.distanceToSquared(e)>ad||8*(1-this._lastQuaternion.dot(t.quaternion))>ad)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0);if(this._offset.copy(e).sub(this._target),this._offset.applyQuaternion(this._quat),this._spherical.setFromVector3(this._offset),this._spherical.theta+=this._sphericalDelta.theta,this._autoRotate&&0===this._state){const t=2*Math.PI/60*(this._autoRotateSpeed/60);this._spherical.theta-=t}this._spherical.phi+=this._sphericalDelta.phi,this._spherical.phi=Math.max(0,Math.min(Math.PI,this._spherical.phi)),this._spherical.makeSafe(),this._target.add(this._panOffset),this._offset.setFromSpherical(this._spherical),this._offset.applyQuaternion(this._quatInverse),e.copy(this._target).add(this._offset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),e.y<0&&(e.y=0)),t.lookAt(this._target);const n=1-this._dampingFactor;return this._sphericalDelta.theta*=n,this._sphericalDelta.phi*=n,this._panOffset.set(0,0,0),(this._lastPosition.distanceToSquared(e)>ad||8*(1-this._lastQuaternion.dot(t.quaternion))>ad)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0)}reset(){this._target.copy(this._target0),this._camera.position.copy(this._position0),this._camera.updateProjectionMatrix(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._state=0,this.update()}pinResetPosition(){this._camera&&(this._position0.copy(this._camera.position),this._target0.copy(this._target))}setCamera(t){this._camera=t,this._target.set(0,0,0),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._lastPosition.copy(t.position),this._lastQuaternion.copy(t.quaternion),this._state=0,t.updateMatrixWorld(!0)}isAutoRotating(){return this._autoRotate}setAutoRotate(t){this._autoRotate=t,this._host?.invalidate()}setFloorConstraint(t){this._floorConstraint=t,this.update()}markCameraChanged(){this._host?.invalidate()}dollyAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,r=i.position.distanceTo(this._target),s=Math.max(1,Math.min(5e4,r*t));if(Math.abs(s-r)<ad)return;const o=Math.tan(i.fov/2*Math.PI/180)/i.zoom,a=r-s,c=e*a*o*i.aspect,l=n*a*o;this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(c),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(l),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),this._panCalcOffset.subVectors(i.position,this._target).normalize().multiplyScalar(s),i.position.copy(this._target).add(this._panCalcOffset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),i.position.y<0&&(i.position.y=0)),this._host?.invalidate()}zoomOrthoAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,r=i.zoom,s=Math.max(.1,Math.min(20,r*t)),o=e*(i.right-i.left)/2*(1/r-1/s),a=n*(i.top-i.bottom)/2*(1/r-1/s);this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(o),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(a),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),i.zoom=s,i.updateProjectionMatrix(),this._host?.invalidate()}destroy(){delete this._camera,delete this._host}_getViewportSize(){const t=this._host?.element;if(t){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return{width:e.width,height:e.height}}const{width:e,height:n}=this._host.bounds;return{width:Math.abs(e)||1,height:Math.abs(n)||1}}_handleRotateMove(t,e){this._rotateEnd.set(t,e),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart);const{width:n,height:i}=this._getViewportSize();this._sphericalDelta.theta-=2*Math.PI*this._rotateDelta.x/n*this._rotateSpeed,this._sphericalDelta.phi-=2*Math.PI*this._rotateDelta.y/i*this._rotateSpeed,this._rotateStart.copy(this._rotateEnd),this._host?.invalidate()}_handlePanMove(t,e){this._panEnd.set(t,e),this._panDelta.subVectors(this._panEnd,this._panStart),this._isOrthoLocked?this._panOrtho(this._panDelta.x,this._panDelta.y):this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this._host?.invalidate()}_panOrtho(t,e){const n=this._camera,{width:i,height:r}=this._getViewportSize();this._panLeftV.setFromMatrixColumn(n.matrix,0),this._panLeftV.multiplyScalar(-t*(n.right-n.left)/n.zoom/i),this._panUpV.setFromMatrixColumn(n.matrix,1),this._panUpV.multiplyScalar(e*(n.top-n.bottom)/n.zoom/r),this._target.add(this._panLeftV).add(this._panUpV),n.position.add(this._panLeftV).add(this._panUpV)}panByPixels(t,e){this._onUserInteraction?.(),this._pan(t,e),this._target.add(this._panOffset),this._camera.position.add(this._panOffset),this._panOffset.set(0,0,0),this._host?.invalidate()}_pan(t,e){t*=this._panSpeed,e*=this._panSpeed;const{width:n,height:i}=this._getViewportSize(),r=this._camera;if(r.isPerspectiveCamera){this._panCalcOffset.copy(r.position).sub(this._target);let n=this._panCalcOffset.length();n*=Math.tan(r.fov/2*Math.PI/180),this._panLeftV.setFromMatrixColumn(r.matrix,0),this._panLeftV.multiplyScalar(-2*t*n/i),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(r.matrix,1),this._panUpV.multiplyScalar(2*e*n/i),this._panOffset.add(this._panUpV)}else r.isOrthographicCamera&&(this._panLeftV.setFromMatrixColumn(r.matrix,0),this._panLeftV.multiplyScalar(-t*(r.right-r.left)/r.zoom/n),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(r.matrix,1),this._panUpV.multiplyScalar(e*(r.top-r.bottom)/r.zoom/i),this._panOffset.add(this._panUpV))}}class ld{constructor(){this._mouse=new e.Vector2,this._raycaster=new e.Raycaster}get mouse(){return this._mouse}get lastFocused(){return this._lastFocused}set lastFocused(t){this._lastFocused=t}get lastHovered(){return this._lastHovered}set lastHovered(t){this._lastHovered=t}updateMouseNDC(t,e,n,i,r,s){this._mouse.x=(t-n)/r*2-1,this._mouse.y=-(e-i)/s*2+1}getObjectByRaycast(t,e){const n=this.getObjectsByRaycast(t,e);if(n&&n.length>0)for(const t of n){if(!this._isWorldVisible(t.object))continue;let e=t.object;for(;e;){if(e.userData.context)return e;e=e.parent}}}_isWorldVisible(t){let e=t;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}getObjectsByRaycast(t,e){return this._raycaster.setFromCamera(this._mouse,t),this._raycaster.intersectObjects(e.children,!0)}setHUD(t,e){this._hudScene=t,this._hudCamera=e}handleClick(t,e,n){let i;this._lastFocused&&(this._lastFocused.focused=!1),this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const r=i?.userData.context;return r&&(r.focused=!0,this._lastFocused=r,r.component?.trigger("click",n)),r}handleHover(t,e,n){let i;this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const r=i?.userData.context;r!==this._lastHovered&&(this._lastHovered&&(this._lastHovered.component?.trigger("mouseleave",n),this._lastHovered=void 0),r&&(this._lastHovered=r,this._lastHovered.component?.trigger("mouseenter",n)))}destroy(){this._lastFocused=void 0,this._lastHovered=void 0,this._hudScene=void 0,this._hudCamera=void 0}}const hd=Math.PI/180*15;class dd{constructor(){this._mode="translate",this._isDragging=!1}get controls(){return this._controls}get mode(){return this._mode}get attached(){return this._attached}get isAttached(){return!!this._attached}get isDragging(){return this._isDragging}get isEngaged(){return!!this._controls?.axis}setup(t,e,n){this.destroy(),this._scene=n;const i=document.createElement("div");i.style.cssText="position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none",i.setPointerCapture=()=>{},i.releasePointerCapture=()=>{},e.appendChild(i),this._proxyElement=i,this._controls=new k(t,i),this._controls.setMode(this._mode),n.add(this._controls.getHelper()),this._controls.addEventListener("dragging-changed",t=>{this._isDragging=t.value,this.onDraggingChanged?.(t.value)}),this._controls.addEventListener("change",()=>{this._attached&&this.onObjectChange?.(this._attached)})}forwardEvent(t,e){if(!this._proxyElement||!this._controls)return;"rotate"===this._mode&&this._controls.setRotationSnap(t.shiftKey?hd:null);const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:t.button??0,pointerId:1,pointerType:"mouse",bubbles:!0});this._proxyElement.dispatchEvent(n)}forwardTouch(t,e){if(!this._proxyElement||!this._controls)return;const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:0,pointerId:t.identifier+10,pointerType:"touch",bubbles:!0});this._proxyElement.dispatchEvent(n)}setMode(t){this._mode=t,this._controls?.setMode(t)}attach(t){this._attached=t,this._controls?.attach(t),this._controls?.getHelper().updateMatrixWorld(!0),this.onAttachChanged?.(!0)}detach(){this._controls?.detach(),this._attached=void 0,this.onAttachChanged?.(!1)}setRotationSnap(t){this._controls&&this._controls.setRotationSnap(t?hd:null)}updateCamera(t){this._controls&&(this._controls.camera=t)}destroy(){this._controls&&(this._controls.detach(),this._controls.dispose(),this._scene&&this._scene.remove(this._controls.getHelper()),this._controls=void 0),this._proxyElement?.parentNode&&this._proxyElement.parentNode.removeChild(this._proxyElement),this._proxyElement=void 0,this._attached=void 0,this._isDragging=!1}}const ud=.01;function pd(t){const[e,n,i]=t,r=Math.abs(e-1),s=Math.abs(n-1),o=Math.abs(i-1);return r<ud&&s<ud&&o<ud?null:r>=s&&r>=o?e:s>=r&&s>=o?n:i}class fd{constructor(){this._mouseDownAltKey=!1}captureAltKey(t){this._mouseDownAltKey=t}setupCallbacks(t,e,n,i){t.onDraggingChanged=r=>{e.setEnabled(!r);const s=n();s&&(i?.onDraggingChanged?.(r),r?(this._onDragStart(t,s),s.hostElement&&this._showInfoOverlay(s.hostElement)):(this._hideInfoOverlay(),this._onDragEnd(t,s)),s.app?.commander?.execute(null),s.invalidate())},t.onObjectChange=e=>{if(this._syncFromGizmo(t,e),this._infoOverlay){const n=t.controls?.axis??null;this._updateInfoOverlay(t.mode,e,n)}n()?.invalidate()},t.onAttachChanged=t=>{i?.onAttachChanged?.(t)}}_onDragStart(t,e){this._mouseDownAltKey&&"translate"===t.mode&&this._performAltDragDuplicate(e);const n=e.root?.selected||[];n.length>1&&this._captureMultiSelectState(t,n);const i=t.attached;i&&("rotate"!==t.mode||this._gizmoInitialRotation?"translate"!==t.mode||this._dragStartPosition||(this._dragStartPosition=i.position.clone()):this._gizmoInitialRotation=i.rotation.clone()),"scale"===t.mode&&this._captureScalePreDrag(t)}_performAltDragDuplicate(t){const e=t.root?.selected||[];if(0===e.length||!t.root)return;const n=t.root,i=[];for(const t of e){const e=t.parent,r=new Map,s=wl(t,t=>{const e=n.getNewRefid();return void 0!==t&&r.set(t,e),e});s.replaceRefids(r),e.addComponent(s),i.push({component:s,to_container:e})}this._altDragDuplicates=i}_captureMultiSelectState(t,e){const n=t.attached;if(n)if("translate"===t.mode){const t=new Map,i=n.position;for(let n=1;n<e.length;n++){const r=e[n]._realObject;r?.object3d&&r.gizmoTransformable&&t.set(r,r.object3d.position.clone().sub(i))}this._multiSelectOffsets=t}else if("rotate"===t.mode){this._gizmoInitialRotation=n.rotation.clone();const t=new Map;for(let n=1;n<e.length;n++){const i=e[n]._realObject;i?.object3d&&i.gizmoTransformable&&t.set(i,i.object3d.rotation.clone())}this._multiSelectInitialRotations=t}else if("scale"===t.mode){const t=new Map;for(let n=1;n<e.length;n++){const i=e[n],r=i._realObject;if(r?.object3d&&r.gizmoTransformable){const{left:e,top:n,width:s,height:o}=i.bounds,{zPos:a=0}=i.state,c=i.state.depth;t.set(r,{left:e,top:n,width:s,height:o,depth:c,zPos:a,scaleX:r.object3d.scale.x,scaleY:r.object3d.scale.y,scaleZ:r.object3d.scale.z})}}this._multiSelectPreDragDimensions=t}}_captureScalePreDrag(t){const e=t.attached,n=e?.userData.context;if(!n||!e)return;const{left:i,top:r,width:s,height:o}=n.component.bounds,{zPos:a=0}=n.component.state,c=n.component.state.depth??n.effectiveDepth;this._preDragDimension={left:i,top:r,width:s,height:o,depth:c,zPos:a},this._preDragScale={x:e.scale.x,y:e.scale.y,z:e.scale.z},this._preDragEffectiveDepth=void 0,this._scaleAnchorSign=this._computeAnchorSign(t,e),this._preDragAttachedPosition=e.position.clone()}_computeAnchorSign(t,n){const i=t.controls;if(!i)return{x:0,y:0,z:0};const r=i.axis;if(!r||"XYZE"===r)return{x:0,y:0,z:0};if(r.includes("X")&&r.includes("Y")&&r.includes("Z"))return{x:0,y:0,z:0};const s=new e.Quaternion;n.getWorldQuaternion(s),s.invert();const o=i.pointStart.clone().applyQuaternion(s),a=.001,c={x:0,y:0,z:0};return r.includes("X")&&Math.abs(o.x)>a&&(c.x=Math.sign(o.x)),r.includes("Y")&&Math.abs(o.y)>a&&(c.y=Math.sign(o.y)),r.includes("Z")&&Math.abs(o.z)>a&&(c.z=Math.sign(o.z)),c}_onDragEnd(t,e){if(this._altDragDuplicates&&this._altDragDuplicates.length>0&&(e.app?.commander.execute(new bl({changes:this._altDragDuplicates})),this._altDragDuplicates=void 0),this._multiSelectOffsets=void 0,this._gizmoInitialRotation=void 0,this._multiSelectInitialRotations=void 0,this._dragStartPosition=void 0,this._preDragDimension){const e=t.attached,n=e?.userData.context;if(n&&(void 0!==this._preDragEffectiveDepth&&n.applyDimensionFromGizmo({depth:this._preDragEffectiveDepth}),n.update()),this._multiSelectPreDragDimensions)for(const[t]of this._multiSelectPreDragDimensions)t.update()}const n=e.root?.selected||[];for(const e of n){const n=e._realObject;n?.onGizmoDragEnd(t.mode)}for(const t of n){let e=t.parent;for(;e?.isGroup?.();){const t=[];e._realObject&&t.push(e._realObject);for(const n of e.components||[])n._realObject&&t.push(n._realObject);for(const e of t)e._suppressOnchange=!0;e.calculateBounds();for(const e of t)e._suppressOnchange=!1,e.updateTransform();e=e.parent}}this._preDragDimension=void 0,this._preDragScale=void 0,this._preDragEffectiveDepth=void 0,this._multiSelectPreDragDimensions=void 0,this._scaleAnchorSign=void 0,this._preDragAttachedPosition=void 0}_syncFromGizmo(t,e){const n=e.userData.context;if(n)if("scale"===t.mode&&this._preDragDimension&&this._preDragScale){const{ratioX:t,ratioY:i,ratioZ:r,sign:s}=this._syncDimensionFromGizmo(n,e);if(this._multiSelectPreDragDimensions)for(const[e,n]of this._multiSelectPreDragDimensions)e.applyDimensionFromGizmo(this._computeAnchorProps(n,t,i,r,s))}else{if(n.syncFromObject3D(),"translate"===t.mode&&this._applyGroundSnap(e,n),this._multiSelectOffsets){const n=e.position;for(const[e,i]of this._multiSelectOffsets)e.object3d&&(e.object3d.position.copy(n).add(i),"translate"===t.mode&&this._applyGroundSnap(e.object3d,e),e.syncFromObject3D())}if(this._multiSelectInitialRotations&&this._gizmoInitialRotation){const t=e.rotation.x-this._gizmoInitialRotation.x,n=e.rotation.y-this._gizmoInitialRotation.y,i=e.rotation.z-this._gizmoInitialRotation.z;for(const[e,r]of this._multiSelectInitialRotations)e.object3d&&(e.object3d.rotation.set(r.x+t,r.y+n,r.z+i),e.syncFromObject3D())}}}_applyGroundSnap(t,e){const n=e.effectiveDepth/2,i=t.position.y-n,r=Math.abs(i);if(r<2)t.position.y=n,e.syncFromObject3D();else if(r<10){const s=(r-2)/8,o=1-s*s;t.position.y=n+i*(1-o),e.syncFromObject3D()}}_syncDimensionFromGizmo(t,e){const n=this._preDragDimension,i=this._preDragScale;let r={...this._scaleAnchorSign??{x:0,y:0,z:0}},s=e.scale.x/i.x,o=e.scale.y/i.y,a=e.scale.z/i.z;if(t.component.state.ratioLock){const t=pd([s,o,a]);if(t){s=o=a=t,e.scale.set(t*i.x,t*i.y,t*i.z);const n=r.x||r.y||r.z;n&&(r={x:n,y:n,z:n})}}return t.applyDimensionFromGizmo(this._computeAnchorProps(n,s,o,a,r)),!this._preDragAttachedPosition||0===r.x&&0===r.y&&0===r.z||this._applyAnchorPositionCorrection(e,n,i,r),{ratioX:s,ratioY:o,ratioZ:a,sign:r}}_computeAnchorProps(t,e,n,i,r){const s=t.width*e,o=t.height*i,a=r.x>0?0:r.x<0?t.width-s:(t.width-s)/2,c=r.z>0?0:r.z<0?t.height-o:(t.height-o)/2,l={left:t.left+a,top:t.top+c,width:s,height:o};if(void 0!==t.depth){const e=t.depth*n,i=r.y>0?0:r.y<0?t.depth-e:(t.depth-e)/2;l.depth=e,l.zPos=t.zPos+i}return l}_applyAnchorPositionCorrection(t,n,i,r){const s=new e.Vector3(r.x*(t.scale.x-i.x)*n.width/2,r.y*(t.scale.y-i.y)*(n.depth??0)/2,r.z*(t.scale.z-i.z)*n.height/2),o=new e.Quaternion;t.getWorldQuaternion(o),s.applyQuaternion(o);const a=this._preDragAttachedPosition;t.position.set(a.x+s.x,a.y+s.y,a.z+s.z)}_showInfoOverlay(t){if(this._infoHostElement=t,this._infoOverlay)return;const e=document.createElement("div");e.style.cssText="\n position: absolute; z-index: 10000; pointer-events: none;\n left: 50%; top: 16px; transform: translateX(-50%);\n padding: 6px 16px; border-radius: 6px;\n background: rgba(0,0,0,0.8); color: #fff;\n font: bold 16px/1.4 'Pretendard', system-ui, sans-serif;\n letter-spacing: 0.5px;\n white-space: nowrap; opacity: 0; transition: opacity 0.15s;\n box-shadow: 0 2px 8px rgba(0,0,0,0.3);\n ",t.style.position="relative",t.appendChild(e),this._infoOverlay=e,requestAnimationFrame(()=>{e.style.opacity="1"})}_updateInfoOverlay(t,e,n){if(!this._infoOverlay)return;const i=t=>(t>=0?"+":"")+t.toFixed(1);if("rotate"===t){if(!this._gizmoInitialRotation)return;const t=180/Math.PI,n=(e.rotation.x-this._gizmoInitialRotation.x)*t,r=(e.rotation.y-this._gizmoInitialRotation.y)*t,s=(e.rotation.z-this._gizmoInitialRotation.z)*t,o=[Math.abs(n),Math.abs(r),Math.abs(s)],a=o.indexOf(Math.max(...o)),c=["X","Y","Z"],l=[n,r,s],h=[e.rotation.x*t,e.rotation.y*t,e.rotation.z*t];this._infoOverlay.textContent=`↻ ${c[a]}: ${h[a].toFixed(1)}° (${i(l[a])})`}else if("translate"===t){if(!this._dragStartPosition)return;const t=e.position.clone().sub(this._dragStartPosition),n=e.position,r=(t,e,n)=>Math.abs(n)<.05?`${t}:${e.toFixed(0)}`:`${t}:${e.toFixed(0)}(${i(n)})`;this._infoOverlay.textContent=`↔ ${r("X",n.x,t.x)} ${r("Y",n.y,t.y)} ${r("Z",n.z,t.z)}`}else if("scale"===t){if(!this._preDragScale)return;this._infoOverlay.textContent=this._formatScaleInfo(e,n)}}_formatScaleInfo(t,e){const n=this._preDragScale,i=this._preDragDimension,r=t.scale.x/(n.x||1),s=t.scale.y/(n.y||1),o=t.scale.z/(n.z||1),a=i?i.width*r:t.scale.x,c=null!=i?.depth?i.depth*s:t.scale.y,l=i?i.height*o:t.scale.z,h=i?i.width*(r-1):t.scale.x-n.x,d=null!=i?.depth?i.depth*(s-1):t.scale.y-n.y,u=i?i.height*(o-1):t.scale.z-n.z,p=t=>(t>=0?"+":"")+t.toFixed(0),f=t=>t.toFixed(0);switch(e){case"X":return`⤢ W ${f(a)}px (${p(h)})`;case"Y":return`⤢ D ${f(c)}px (${p(d)})`;case"Z":return`⤢ H ${f(l)}px (${p(u)})`}return Math.abs(r-s)<.01&&Math.abs(s-o)<.01?`⤢ ×${r.toFixed(2)} (${f(a)}×${f(c)}×${f(l)})`:`⤢ W:${f(a)}(${p(h)}) D:${f(c)}(${p(d)}) H:${f(l)}(${p(u)})`}_hideInfoOverlay(){this._infoOverlay&&(this._infoOverlay.remove(),this._infoOverlay=void 0),this._infoHostElement=void 0}}class gd{constructor(){this._mouseIsDown=!1,this._isDragging=!1,this._touchGizmoCaptured=!1,this._mouseDownPos={x:0,y:0}}get hostElement(){return this._hostElement}setup(t,e,n){this.cleanup(),this._hostElement=t,this._gizmo=e.gizmo,this._controls=e.controls,this._camera=e.camera,this._scene=e.scene,this._event=e.event,this._delegate=n,t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.style.outline="none";const i={mousedown:t=>this._onMouseDown(t),mousemove:t=>this._onMouseMove(t),wheel:t=>{t.stopPropagation(),this._delegate.handleWheel(t)},dblclick:t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleDblClick(t)},contextmenu:t=>{t.preventDefault()},touchstart:t=>{if(t.stopPropagation(),1===t.touches?.length&&this._gizmo?.isAttached){const e=t.touches[0];if(this._gizmo.forwardTouch(e,"pointermove"),this._gizmo.isEngaged)return this._gizmo.forwardTouch(e,"pointerdown"),this._touchGizmoCaptured=!0,void t.preventDefault()}this._touchGizmoCaptured=!1,this._delegate.handleTouchStart(t)},touchmove:t=>{if(t.stopPropagation(),this._touchGizmoCaptured&&1===t.touches.length)return this._gizmo.forwardTouch(t.touches[0],"pointermove"),void t.preventDefault();this._delegate.handleTouchMove(t)},touchend:t=>{if(t.stopPropagation(),this._touchGizmoCaptured){const e=t.changedTouches[0];return e&&this._gizmo.forwardTouch(e,"pointerup"),void(this._touchGizmoCaptured=!1)}this._delegate.handleTouchEnd(t)},keydown:t=>{!this._delegate.handleKeyDown(t)||t.ctrlKey||t.metaKey||t.stopPropagation()},keyup:t=>{(this._delegate.handleKeyUp?.(t)??!1)&&t.stopPropagation()}};t.addEventListener("mousedown",i.mousedown),t.addEventListener("mousemove",i.mousemove),t.addEventListener("wheel",i.wheel),t.addEventListener("dblclick",i.dblclick),t.addEventListener("contextmenu",i.contextmenu),t.addEventListener("touchstart",i.touchstart,{passive:!1}),t.addEventListener("touchmove",i.touchmove,{passive:!1}),t.addEventListener("touchend",i.touchend),t.addEventListener("keydown",i.keydown),t.addEventListener("keyup",i.keyup),this._boundHandlers=i}cleanup(){this._removeDocCapture();const t=this._hostElement,e=this._boundHandlers;t&&e&&(t.removeEventListener("mousedown",e.mousedown),t.removeEventListener("mousemove",e.mousemove),t.removeEventListener("wheel",e.wheel),t.removeEventListener("dblclick",e.dblclick),t.removeEventListener("contextmenu",e.contextmenu),t.removeEventListener("touchstart",e.touchstart),t.removeEventListener("touchmove",e.touchmove),t.removeEventListener("touchend",e.touchend),t.removeEventListener("keydown",e.keydown),t.removeEventListener("keyup",e.keyup),t.removeAttribute("tabindex"),t.style.outline=""),this._boundHandlers=void 0,this._hostElement=void 0,this._mouseIsDown=!1,this._isDragging=!1}forceCleanupDragState(){this._removeDocCapture(),this._mouseIsDown=!1,this._isDragging=!1}clientToElementCoords(t,e){const n=this._hostElement;if(!n)return{x:t,y:e};const i=n.getBoundingClientRect();return{x:t-i.left,y:e-i.top}}updateMouseNDCFromClient(t,e){const n=this._hostElement?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const i=t-n.left,r=e-n.top;this._event.updateMouseNDC(i,r,0,0,n.width,n.height)}_onMouseDown(t){if(t.stopPropagation(),this._hostElement.focus(),this._delegate.isPlacementMode())return void this._delegate.handlePlacementClick(t);if(this._delegate.isSpacePanning?.()??!1)return this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation();const e=t.clientX-this._mouseDownPos.x,n=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(e*e+n*n<gd.DRAG_THRESHOLD)return;this._isDragging=!0;const t=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:t.x,offsetY:t.y,altKey:!0})}const i=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:i.x,offsetY:i.y,altKey:!0})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);if(t.shiftKey&&!t.altKey&&!this._gizmo?.isEngaged){const e=this.clientToElementCoords(t.clientX,t.clientY);return this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation();const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<gd.DRAG_THRESHOLD)return;this._isDragging=!0,this._delegate.handleBoxSelectionStart?.(e.x,e.y)}const r=this.clientToElementCoords(t.clientX,t.clientY);this._delegate.handleBoxSelectionUpdate?.(r.x,r.y)},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging)this._delegate.handleBoxSelectionEnd?.(t.shiftKey,t.ctrlKey||t.metaKey);else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0)}if(this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.tryVertexDragStart?.(t))return this._mouseIsDown=!0,this._isDragging=!0,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleVertexDragMove?.(t)},this._docUpHandler=t=>{t.stopPropagation(),this._removeDocCapture(),this._delegate.handleVertexDragEnd?.(t),this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);this._delegate.captureMouseDownAltKey(t.altKey),this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown");let e=this._gizmo.isDragging;!e&&t.altKey&&this._delegate.tryAltClickSelect(t)&&(this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown"),e=this._gizmo.isDragging),this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{if(t.stopPropagation(),e)return void this._gizmo.forwardEvent(t,"pointermove");const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<gd.DRAG_THRESHOLD)return;this._isDragging=!0;const e=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:e.x,offsetY:e.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}const r=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:r.x,offsetY:r.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),e)return this._gizmo.forwardEvent(t,"pointerup"),this._mouseIsDown=!1,void(this._isDragging=!1);if(this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),document.addEventListener("mouseup",this._docUpHandler,!0)}_onMouseMove(t){if(t.stopPropagation(),this._mouseIsDown)return;if(this._delegate.isPlacementMode())return void this._delegate.handlePlacementHover(t);this.updateMouseNDCFromClient(t.clientX,t.clientY);const e=this._camera.activeCamera;e&&this._scene.scene&&this._event.handleHover(e,this._scene.scene,t),this._gizmo.forwardEvent(t,"pointermove")}_removeDocCapture(){this._docMoveHandler&&(document.removeEventListener("mousemove",this._docMoveHandler,!0),this._docMoveHandler=void 0),this._docUpHandler&&(document.removeEventListener("mouseup",this._docUpHandler,!0),this._docUpHandler=void 0)}}gd.DRAG_THRESHOLD=16;class md{constructor(){this._groundPlane=new e.Plane(new e.Vector3(0,1,0),0)}get isActive(){return!!this._pendingModels}get pendingModels(){return this._pendingModels}setup(t,e){this._camera=t.camera,this._event=t.event,this._scene=t.scene,this._delegate=e}start(t){this._pendingModels=t}stop(){this._pendingModels=void 0,this._removeIndicator()}destroy(){this._removeIndicator(),this._pendingModels=void 0}raycastGroundPlane(t){this._delegate.updateMouseNDCFromClient(t.clientX,t.clientY);const n=this._camera.activeCamera;if(!n)return null;n.updateMatrixWorld(!0);const i=new e.Raycaster;i.setFromCamera(this._event.mouse,n);const r=new e.Vector3;return i.ray.intersectPlane(this._groundPlane,r)}updateIndicator(t){if(!t)return void(this._placementIndicator&&(this._placementIndicator.visible=!1));if(!this._placementIndicator){const t=this._scene?.scene;if(!t)return;const n=new e.RingGeometry(.8,1,32);n.rotateX(-Math.PI/2);const i=new e.MeshBasicMaterial({color:48340,opacity:.6,transparent:!0,side:e.DoubleSide,depthTest:!1});this._placementIndicator=new e.Mesh(n,i),this._placementIndicator.renderOrder=999,t.add(this._placementIndicator)}const n=this._pendingModels?.[0],i=n?.rx??n?.width??50,r=n?.ry??n?.height??50;this._placementIndicator.scale.set(i,1,r),this._placementIndicator.position.copy(t),this._placementIndicator.position.y=1,this._placementIndicator.visible=!0}_removeIndicator(){if(this._placementIndicator){const t=this._placementIndicator;this._scene?.scene?.remove(t),t.geometry.dispose(),t.material.dispose(),this._placementIndicator=void 0}}}const yd={linear:t=>t,"ease-in":t=>t*t,"ease-out":t=>1-(1-t)*(1-t),"ease-in-out":t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2};function bd(t,n,i,r,s,o=new e.Vector3){const a=t*t,c=a*t;return o.set(.5*(2*i.x+(-n.x+r.x)*t+(2*n.x-5*i.x+4*r.x-s.x)*a+(-n.x+3*i.x-3*r.x+s.x)*c),.5*(2*i.y+(-n.y+r.y)*t+(2*n.y-5*i.y+4*r.y-s.y)*a+(-n.y+3*i.y-3*r.y+s.y)*c),.5*(2*i.z+(-n.z+r.z)*t+(2*n.z-5*i.z+4*r.z-s.z)*a+(-n.z+3*i.z-3*r.z+s.z)*c))}class vd{constructor(){this._slots=new Array(10),this._animating=!1,this._animationProgress=0,this._playStartOffset=0,this._lastPlayProgress=-1,this._playIndex=-1,this._playing=!1,this._orbitRotating=!1,this._orbitPaused=!1}get isAnimating(){return this._animating}get isPlaying(){return this._playing}get isOrbitRotating(){return this._orbitRotating}get isOrbitPaused(){return this._orbitPaused}get playIndex(){return this._playIndex}get lastPlayProgress(){return this._lastPlayProgress}get playProgress(){if(!this._playing||this._playIndex<0)return 0;const t=this.getPlayableSlots().length;if(t<2)return 0;const e=(this._playIndex-1+t)%t;let n=this._animating?this._animationProgress:1;return this._playStartOffset>0&&(n=this._playStartOffset+n*(1-this._playStartOffset)),(e+n)%t/t}setCallbacks(t,e){this._onInvalidate=t,this._onAnimationComplete=e}saveSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];this._slots[t]={...e,name:"name"in e?e.name:n?.name}}renameSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];n&&(n.name=e||void 0)}clearSlot(t){t<0||t>9||(this._slots[t]=void 0)}getSlot(t){return this._slots[t]}exportSlots(){return this._slots.map(t=>t?{...t}:null)}importSlots(t){if(Array.isArray(t))for(let e=0;e<10;e++){const n=t[e];this._slots[e]=n?{...n}:void 0}}resetAll(){this._slots=new Array(10)}getPlayableSlots(){return this._slots.map((t,e)=>t&&!t.excludeFromPlay?e:-1).filter(t=>t>=0)}swapSlots(t,e){if(t<0||t>9||e<0||e>9||t===e)return;const n=this._slots[t];this._slots[t]=this._slots[e],this._slots[e]=n}moveSlot(t,e){if(t<1||t>9||e<1||e>9||t===e)return;const n=this._slots[t];this._slots.splice(t,1),this._slots.splice(e,0,n)}animateToSlot(t,n,i,r=800,s){const o=this._slots[t];if(!o)return!1;this.stopAnimation(),this._animating=!0,this._animationProgress=0;const a=n.position.clone(),c=i.target.clone(),l=new e.Vector3(o.position.x,o.position.y,o.position.z),h=new e.Vector3(o.target.x,o.target.y,o.target.z),d=.01,u=Math.max(a.distanceTo(c),d),p=Math.max(l.distanceTo(h),d),f=(new e.Vector3).subVectors(c,a),g=(new e.Vector3).subVectors(h,l),m=f.lengthSq()>1e-4?f.normalize():new e.Vector3(0,0,-1).applyQuaternion(n.quaternion),y=g.lengthSq()>1e-4?g.normalize():m.clone(),b=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),m),v=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),y),_=yd[o.easing??"ease-in-out"];return this._runAnimation(r,_,t=>{s?bd(t,s.prevPos,a,l,s.nextPos,n.position):n.position.lerpVectors(a,l,t);const r=b.clone().slerp(v,t),o=new e.Vector3(0,0,-1).applyQuaternion(r),c=u+(p-u)*t,h=n.position.clone().add(o.multiplyScalar(c));i.restoreTarget(h)}),!0}_animatePathSegment(t,e,n,i,r,s){const o=yd[i];this._runAnimation(n,o,n=>{const i=t+(e-t)*n,o=this.evaluatePath(i<=1?i:i-1);o&&(r.position.copy(o.position),s.restoreTarget(o.target))})}_runAnimation(t,e,n){this.stopAnimation(),this._animating=!0,this._animationProgress=0;const i=performance.now(),r=()=>{const s=performance.now()-i,o=Math.min(s/t,1),a=e(o);this._animationProgress=a,n(a),this._onInvalidate?.(),o<1?this._animationId=requestAnimationFrame(r):(this._animating=!1,this._animationId=void 0,this._onAnimationComplete?.())};this._animationId=requestAnimationFrame(r)}_initFromProgress(t,e){const n=t*e,i=Math.min(Math.floor(n),e-1);this._playStartOffset=n-i,this._playIndex=(i+1)%e}startPlay(t,n,i=2e3,r=1200,s=-1,o=!1){if(this._playing)return void this.stopPlay();const a=this.getPlayableSlots();if(a.length<2)return;this._playing=!0;let c=!0,l=-1;const h=s>=0&&s<=1?s:this._lastPlayProgress>0&&this._lastPlayProgress<1?this._lastPlayProgress:-1;o?this._playIndex=0:h>=0?(this._initFromProgress(h,a.length),l=h,c=!1):this._playIndex=0;const d=t=>new e.Vector3(t.x,t.y,t.z),u=t=>{this._onAnimationComplete=()=>{this._playing&&(this._playStartOffset=0,setTimeout(()=>{this._playing&&(this._playIndex=(this._playIndex+1)%a.length,p())},t))}},p=()=>{if(!this._playing)return;const e=a[this._playIndex],s=this._slots[e],o=s?.holdDuration??i,h=s?.transitionDuration??r;if(l>=0){const e=l;let i=this._playIndex/a.length;i<=e&&(i+=1),l=-1;const r=this._playStartOffset,c=Math.max(Math.round(h*(1-r)),100);return u(o),void this._animatePathSegment(e,i,c,s?.easing??"ease-in-out",t,n)}const p=this._buildSplineContext(a,c,t,n,d);c=!1,u(o),this.animateToSlot(e,t,n,h,p)};p()}_buildSplineContext(t,e,n,i,r){if(t.length<3)return;const s=t.length,o=t[(this._playIndex+1)%s],a=this._slots[o];if(!a)return;if(e)return{prevPos:n.position.clone(),nextPos:r(a.position)};const c=t[(this._playIndex-2+s)%s],l=this._slots[c];return l?{prevPos:r(l.position),nextPos:r(a.position)}:void 0}setProgressForSlot(t){const e=this.getPlayableSlots(),n=e.indexOf(t);n<0||e.length<2?this._lastPlayProgress=-1:this._lastPlayProgress=n/e.length}stopPlay(){this._lastPlayProgress=this.playProgress,this._playing=!1,this._playIndex=-1,this._playStartOffset=0,this._onAnimationComplete=void 0,this.stopAnimation()}resetPlay(){this.stopPlay(),this._lastPlayProgress=-1}toggleOrbitRotation(t){const e=t.isAutoRotating();this._orbitRotating=!e,this._orbitPaused=!this._orbitRotating,t.setAutoRotate(this._orbitRotating)}stopOrbitRotation(t){this._orbitRotating=!1,this._orbitPaused=!1,t.setAutoRotate(!1)}evaluatePath(t){const n=this.getPlayableSlots();if(n.length<2)return null;const i=n.length,r=Math.max(0,Math.min(1,t)),s=t=>{const r=this._slots[n[(t%i+i)%i]];return r?new e.Vector3(r.position.x,r.position.y,r.position.z):new e.Vector3},o=t=>{const r=this._slots[n[(t%i+i)%i]];return r?new e.Vector3(r.target.x,r.target.y,r.target.z):new e.Vector3};if(2===i){const t=r<.5?2*r:2*(1-r);return{position:s(0).lerp(s(1),t),target:o(0).lerp(o(1),t)}}const a=r*i,c=Math.min(Math.floor(a),i-1),l=a-c,h=bd(l,s(c-1),s(c),s(c+1),s(c+2)),d=s(c),u=s(c+1),p=o(c),f=o(c+1),g=.01,m=Math.max(d.distanceTo(p),g),y=Math.max(u.distanceTo(f),g),b=(new e.Vector3).subVectors(p,d),v=(new e.Vector3).subVectors(f,u),_=b.lengthSq()>1e-4?b.normalize():new e.Vector3(0,0,-1),x=v.lengthSq()>1e-4?v.normalize():_.clone(),w=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),_),M=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),x),S=w.clone().slerp(M,l),k=new e.Vector3(0,0,-1).applyQuaternion(S),A=m+(y-m)*l,E=h.clone().add(k.multiplyScalar(A));return{position:h,target:E}}stopAnimation(){void 0!==this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=void 0),this._animating=!1}destroy(){this.stopPlay(),this.stopAnimation(),this._orbitPaused=!1,this._slots=new Array(10),this._onInvalidate=void 0,this._onAnimationComplete=void 0}}class _d{constructor(){this._overlay=null,this._hostElement=null,this._startX=0,this._startY=0,this._currentX=0,this._currentY=0,this._active=!1}get isActive(){return this._active}setup(t){this._hostElement=t}startSelection(t,e){this._hostElement&&(this._startX=t,this._startY=e,this._currentX=t,this._currentY=e,this._active=!0,this._overlay=document.createElement("div"),this._overlay.style.cssText="\n position: absolute;\n border: 1px solid #4a9eff;\n background: rgba(74, 158, 255, 0.1);\n pointer-events: none;\n z-index: 1000;\n ",this._hostElement.appendChild(this._overlay),this._updateOverlay())}updateSelection(t,e){this._active&&(this._currentX=t,this._currentY=e,this._updateOverlay())}endSelection(t,n,i){if(!this._active||!this._hostElement)return this.cancelSelection(),[];const r=this._hostElement.getBoundingClientRect(),s=r.width,o=r.height,a=Math.min(this._startX,this._currentX),c=Math.max(this._startX,this._currentX),l=Math.min(this._startY,this._currentY),h=Math.max(this._startY,this._currentY);if(c-a<5&&h-l<5)return this.cancelSelection(),[];const d=a/s*2-1,u=c/s*2-1,p=-h/o*2+1,f=-l/o*2+1,g=[],m=new e.Vector3;for(const e of i){const n=e._realObject;n?.object3d&&(m.copy(n.object3d.position),m.project(t),m.z>1||m.x>=d&&m.x<=u&&m.y>=p&&m.y<=f&&g.push(e))}return this.cancelSelection(),g}cancelSelection(){this._active=!1,this._overlay&&this._hostElement&&this._hostElement.removeChild(this._overlay),this._overlay=null}destroy(){this.cancelSelection(),this._hostElement=null}_updateOverlay(){if(!this._overlay)return;const t=Math.min(this._startX,this._currentX),e=Math.min(this._startY,this._currentY),n=Math.abs(this._currentX-this._startX),i=Math.abs(this._currentY-this._startY);this._overlay.style.left=`${t}px`,this._overlay.style.top=`${e}px`,this._overlay.style.width=`${n}px`,this._overlay.style.height=`${i}px`}}const xd=4890367,wd=16750592;class Md{constructor(){this._componentHandles=[],this._activeVertexHandles=[],this._activeHandleIndex=-1,this._isDragging=!1,this._isExtending=!1,this._dragPlane=new e.Plane,this._dragOffset=new e.Vector3,this._raycaster=new e.Raycaster,this._intersection=new e.Vector3}get isDragging(){return this._isDragging}get isAttached(){return this._componentHandles.length>0}setVisible(t){this._handleGroup&&(this._handleGroup.visible=t)}attachMultiple(t,n,i){this.detach();const r=t.filter(t=>t.mutable&&t.path&&t.path.length>=2);if(0!==r.length){this._scene3d=n,this._commander=i,this._handleGroup=new e.Group,this._handleGroup.name="__vertexHandles__",this._handleGroup.renderOrder=1e4;for(const t of r){const e=this._buildComponentHandles(t);this._componentHandles.push(e)}n.add(this._handleGroup)}}attach(t,e,n){this.attachMultiple([t],e,n)}detach(){this._handleGroup&&this._scene3d&&(this._scene3d.remove(this._handleGroup),Hh(this._handleGroup)),this._componentHandles=[],this._handleGroup=void 0,this._scene3d=void 0,this._commander=void 0,this._activeComponent=void 0,this._activeVertexHandles=[],this._activeHandleIndex=-1,this._isDragging=!1,this._isExtending=!1}_buildComponentHandles(t){const n=[],i=[],r=t.path;if(!r||!this._handleGroup)return{component:t,vertexHandles:n,midpointHandles:i};const{width:s=0,height:o=0}=t.parent?.bounds??{},a=t._realObject,c=a?a.object3d.position.y:0;for(let i=0;i<r.length;i++){const a=r[i],l=new e.Vector3(a.x-s/2,(a.z||0)+c,a.y-o/2),h=this._createVertexHandle(l,i,t);n.push(h),this._handleGroup.add(h)}if(t.pathExtendable)for(let n=0;n<r.length-1;n++){const a=r[n],l=r[n+1],h=new e.Vector3((a.x+l.x)/2-s/2,((a.z||0)+(l.z||0))/2+c,(a.y+l.y)/2-o/2),d=this._createMidpointHandle(h,n,t);i.push(d),this._handleGroup.add(d)}return{component:t,vertexHandles:n,midpointHandles:i}}_rebuildComponentHandles(t){const e=this._componentHandles.findIndex(e=>e.component===t);if(e<0||!this._handleGroup)return;const n=this._componentHandles[e];for(const t of[...n.vertexHandles,...n.midpointHandles])this._handleGroup.remove(t),t.geometry.dispose(),t.material.dispose();this._componentHandles[e]=this._buildComponentHandles(t),this._activeComponent===t&&(this._activeVertexHandles=this._componentHandles[e].vertexHandles)}_createVertexHandle(t,n,i){const r=new e.SphereGeometry(1,16,12),s=new e.MeshBasicMaterial({color:xd,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(r,s);return o.position.copy(t),o.userData.vertexIndex=n,o.userData.handleType="vertex",o.userData.component=i,o.renderOrder=10001,o}_createMidpointHandle(t,n,i){const r=new e.OctahedronGeometry(.7,0),s=new e.MeshBasicMaterial({color:16735602,transparent:!0,opacity:.7,depthTest:!1}),o=new e.Mesh(r,s);return o.position.copy(t),o.userData.segmentIndex=n,o.userData.handleType="midpoint",o.userData.component=i,o.renderOrder=10001,o}_handlePosToPoint(t,e){const{width:n=0,height:i=0}=e.parent?.bounds??{},r=e._realObject,s=r?r.object3d.position.y:0,o={x:t.x+n/2,y:t.z+i/2},a=t.y-s;return Math.abs(a)>.001&&(o.z=a),o}_execMutatePath(t,e){const n=this._commander;n?il.around(n,()=>{t.mutatePath(null,e)}):t.mutatePath(null,e)}_getAllHandles(){const t=[];for(const e of this._componentHandles)t.push(...e.vertexHandles,...e.midpointHandles);return t}_findComponentHandles(t){return this._componentHandles.find(e=>e.component===t)}onPointerDown(t,e,n){if(!this._handleGroup)return!1;const i=this._getAllHandles();if(0===i.length)return!1;this._raycaster.setFromCamera(t,e);const r=this._raycaster.intersectObjects(i,!1);if(0===r.length)return!1;const s=r[0].object,o=s.userData.handleType,a=s.userData.component,c=this._findComponentHandles(a);if(!c)return!1;if(this._activeComponent=a,this._activeVertexHandles=c.vertexHandles,"midpoint"===o)return this._startMidpointDrag(s,a,e);const l=s.userData.vertexIndex,h=a.path;if(!h)return!1;const d=0===l||l===h.length-1;return n.altKey&&d&&a.pathExtendable?this._startEndpointExtend(s,l,a,e):(this._activeHandleIndex=l,this._isDragging=!0,this._isExtending=!1,s.material.color.setHex(wd),this._setupDragPlane(e,s.position),!0)}_startMidpointDrag(t,e,n){const i=t.userData.segmentIndex+1,r=this._handlePosToPoint(t.position,e);this._execMutatePath(e,t=>{t.splice(i,0,r)}),this._rebuildComponentHandles(e);const s=this._activeVertexHandles[i];return!!s&&(this._activeHandleIndex=i,this._isDragging=!0,this._isExtending=!1,s.material.color.setHex(wd),this._setupDragPlane(n,s.position),!0)}_startEndpointExtend(t,e,n,i){const r=n.path;if(!r)return!1;const s=this._handlePosToPoint(t.position,n),o=0===e?0:r.length;this._execMutatePath(n,t=>{t.splice(o,0,s)}),this._rebuildComponentHandles(n);const a=this._activeVertexHandles[o];return!!a&&(this._activeHandleIndex=o,this._isDragging=!0,this._isExtending=!0,a.material.color.setHex(wd),this._setupDragPlane(i,a.position),!0)}_setupDragPlane(t,n){const i=new e.Vector3;t.getWorldDirection(i),this._dragPlane.setFromNormalAndCoplanarPoint(i,n),this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection),this._dragOffset.copy(n).sub(this._intersection)}onPointerMove(t,e,n){if(!this._isDragging||this._activeHandleIndex<0)return!1;this._raycaster.setFromCamera(t,e),this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection);const i=this._intersection.add(this._dragOffset);if(n.shiftKey){const t=this._activeVertexHandles[this._activeHandleIndex];t&&(i.x=t.position.x,i.z=t.position.z)}const r=this._activeVertexHandles[this._activeHandleIndex];return r&&r.position.copy(i),this._updateLinePreview(),!0}_updateLinePreview(){if(!this._activeComponent)return;const t=this._activeComponent._realObject;if(!t?._line2)return;const{width:e=0,height:n=0}=this._activeComponent.parent?.bounds??{},{x:i,y:r}=this._activeComponent.center,s=t.object3d?t.object3d.position.y:0,o=[];for(const t of this._activeVertexHandles){const a=t.position.x+e/2-i,c=t.position.y-s,l=t.position.z+n/2-r;o.push(a,c,l)}if(o.length<6)return;t._line2.geometry.setPositions(o),t._line2.computeLineDistances()}onPointerUp(){if(!this._isDragging||this._activeHandleIndex<0||!this._activeComponent)return!1;const t=this._activeHandleIndex,e=this._activeVertexHandles[t],n=this._activeComponent;if(!e)return this._isDragging=!1,this._activeHandleIndex=-1,this._isExtending=!1,!0;e.material.color.setHex(xd);const i=this._handlePosToPoint(e.position,n);return this._execMutatePath(n,e=>{e[t]=i}),this._isDragging=!1,this._activeHandleIndex=-1,this._isExtending=!1,this._rebuildComponentHandles(n),!0}onDblClick(t,e){if(!this._handleGroup)return!1;const n=[];for(const t of this._componentHandles)n.push(...t.vertexHandles);this._raycaster.setFromCamera(t,e);const i=this._raycaster.intersectObjects(n,!1);if(0===i.length)return!1;const r=i[0].object,s=r.userData.component;if(!s.pathExtendable)return!1;const o=s.path;if(!o||o.length<=2)return!1;const a=r.userData.vertexIndex;return this._execMutatePath(s,t=>{t.splice(a,1)}),this._rebuildComponentHandles(s),!0}syncHandles(){for(const t of this._componentHandles)this._rebuildComponentHandles(t.component)}updateHandleScales(t){const e=this._getAllHandles();if(0!==e.length)for(const n of e){const e=t.position.distanceTo(n.position),i="midpoint"===n.userData.handleType?5:8;let r;if(t.isPerspectiveCamera){const n=t.fov,s=2*Math.tan(n*Math.PI/360)*e;r=i/window.innerHeight*s}else{const e=t,n=(e.top-e.bottom)/e.zoom;r=i/window.innerHeight*n}n.scale.setScalar(Math.max(r,.1))}}destroy(){this.detach()}}class Sd{constructor(){this.sceneManager=new id,this.cameraManager=new rd,this.rendererManager=new sd,this.lightManager=new od,this.controlsManager=new cd,this.eventManager=new ld,this.gizmoManager=new dd,this.interactionManager=new gd,this.placementManager=new md,this.gizmoOperationManager=new fd,this.bookmarkManager=new vd,this.boxSelectionManager=new _d,this.vertexGizmoManager=new Md,this._isSpacePanning=!1,this._initialized=!1,this._decoratorOutlines=new Set,this._selectionOutlineObjects=[],this._highlightedMarkerIndex=-1,this._arrows=new Map,this._pathVisible=!1}get isInitialized(){return this._initialized}get host(){return this._host}get scene3d(){return this.sceneManager.scene}get renderer3d(){return this.rendererManager.renderer}get mixer(){return this.sceneManager.mixer}get camera(){return this.cameraManager.camera}get activeCamera(){return this.cameraManager.activeCamera}get css3DScene(){return this.rendererManager.css3DScene}get css3DRenderer(){return this.rendererManager.css3DRenderer}get noSupportWebgl(){return this.rendererManager.noSupportWebgl}get isActive(){return this.controlsManager.isActive}setGizmoMode(t){if(this.gizmoManager.mode===t&&this.gizmoManager.attached)return this.gizmoManager.detach(),void this._host?.invalidate();this.gizmoManager.setMode(t),this.onGizmoModeChanged?.(t);const e=this._host?.root?.selected,n=e?.filter(t=>t!==this._host&&t._realObject)||[];if(n.length>=1){const e=n[0]._realObject;if(e?.object3d&&e.gizmoTransformable){const n=e.allowedGizmoModes;!n||n.includes(t)?this.gizmoManager.attach(e.object3d):this.gizmoManager.detach()}this._host?.invalidate()}}get gizmoMode(){return this.gizmoManager.mode}init(t,e){this.interactionManager.cleanup(),this._cleanupEventHandlers(),this._host=t,this.sceneManager.scene&&this.destroy(),this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this._initialized=!0,this._setupScene(e),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged)),t.app?.isEditMode&&t.root?.on&&(this._onAddStart=t=>{this.placementManager.start(t),this._host?.element&&(this._host.element.style.cursor="crosshair",this._host.element.focus())},this._onAddStop=()=>{this.placementManager.stop(),this._host?.element&&(this._host.element.style.cursor="")},t.root.on("addstart",this._onAddStart),t.root.on("addstop",this._onAddStop))}_cleanupEventHandlers(){const t=this._host;t&&(this._redrawHandler&&(t.root.off("redraw",this._redrawHandler),this._redrawHandler=void 0),t.off&&(this._onComponentAdd&&(t.off("add",this._onComponentAdd),this._onComponentAdd=void 0),this._onComponentRemove&&(t.off("remove",this._onComponentRemove),this._onComponentRemove=void 0)),this._onSelectionChanged&&t.root?.off&&(t.root.off("selected",this._onSelectionChanged),this._onSelectionChanged=void 0),this._onAddStart&&t.root?.off&&(t.root.off("addstart",this._onAddStart),this._onAddStart=void 0),this._onAddStop&&t.root?.off&&(t.root.off("addstop",this._onAddStop),this._onAddStop=void 0))}_setupScene(t){const e=this._host;let{width:n,height:i}=e.bounds;n=Math.abs(n)||1,i=Math.abs(i)||1;const{fov:r=45,near:s=.1,far:o=2e4,antialias:a=!0,precision:c="highp",cameraX:l,cameraY:h,cameraZ:d,exposure:u=1.2}=e.state,p=e.components||[],f=t?.lightingConfig??{hemisphere:{skyColor:16777215,groundColor:4473924,intensity:.4}},g=t?.css3DSceneAttribute??"three-container:css3d-renderer",m=this.sceneManager.setup(),y=this.cameraManager.setup(n,i,{fov:r,near:s,far:o,cameraX:l,cameraY:h,cameraZ:d});this.cameraManager.addToScene(m);const b=e.app?.postprocessing,v=!t?.skipShadowMap&&void 0,_=!t?.skipPostprocessing&&void 0;if(this.rendererManager.setupWebGL(n,i,{precision:c,antialias:a,exposure:u,postprocessing:b,shadowMap:v,logarithmicDepthBuffer:_})){if(t?.skipEnvironment||this.sceneManager.setupEnvironment(this.rendererManager.renderer),this.controlsManager.setup(y,e),this.controlsManager.setOnUserInteraction(()=>{this.bookmarkManager.isPlaying&&(this.bookmarkManager.stopPlay(),this._pathVisible&&this.showBookmarkPath()),this.bookmarkManager.isOrbitRotating&&this.bookmarkManager.stopOrbitRotation(this.controlsManager)}),e.app?.isEditMode&&e.element&&(this.gizmoManager.setup(y,e.element,m),this._setupGizmoCallbacks()),this.placementManager.setup({camera:this.cameraManager,event:this.eventManager,scene:this.sceneManager},{updateMouseNDCFromClient:(t,e)=>this._updateMouseNDCFromClient(t,e)}),this.lightManager.setup(m,y,f),this.sceneManager.setupMixer(),this.createObjects(p),y.updateProjectionMatrix(),t?.skipFloor||this.sceneManager.addFloor(e),this.sceneManager.setSky(e.state.sky,e.state.skyColor),t?.skipPostprocessing||!1===e.app?.postprocessing)t?.useLightComposer?this.rendererManager.setupLightComposer(m,y,n,i):this.rendererManager.setDirectRenderTargets(m,y);else{const t=this.gizmoManager.controls?.getHelper();this.rendererManager.setupComposer(m,y,n,i,t)}this.rendererManager.setupHUD(n,i),this.rendererManager.hudCamera&&this.eventManager.setHUD(this.rendererManager.hudScene,this.rendererManager.hudCamera),this.rendererManager.setupCSS3D(e.app.isViewMode,g),this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus),e.element&&(this.interactionManager.setup(e.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate()),e.app?.isEditMode&&this.boxSelectionManager.setup(e.element))}}_setupGizmoCallbacks(){this.gizmoOperationManager.setupCallbacks(this.gizmoManager,this.controlsManager,()=>{const t=this._host;if(t)return Object.create(t,{hostElement:{get:()=>t.target??t.element??void 0}})},{onAttachChanged:t=>this.onGizmoAttachChanged?.(t),onDraggingChanged:t=>{t?this.vertexGizmoManager.setVisible(!1):(this.vertexGizmoManager.syncHandles(),this.vertexGizmoManager.setVisible(!0))}})}createObjects(t){for(const e of t)this.addObject(e)}addObject(t){if(t._realObject){const e=t._realObject;if(e.object3d&&!e.object3d.parent){const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}return}if(!t.is3dContainer?.()){try{if(!t.isLine?.()){const{width:e,height:n}=t.bounds;if(!e||!n)return}if(t.isHTMLElement()&&!t.element)return;const e=Qh(t);if(e){if(t._realObject=e,e.update(),e.updateTransform(),t.state.screenFixed)e instanceof Wh?this.rendererManager.hudCSS3DScene.add(e.object3d):this.rendererManager.hudScene.add(e.object3d);else if(e instanceof Wh)this.rendererManager.css3DScene.add(e.object3d);else{const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}const n=this._host?.root?.selected;n&&n.length>0&&n[0]===t&&e.object3d&&e.gizmoTransformable&&this.gizmoManager.attached&&this.gizmoManager.attach(e.object3d)}}catch(t){Ki(t)}if(t.isContainer()){const e=t,n=e.components||[];this.createObjects(n),e.on&&(e.on("add",this._onComponentAdd),e.on("remove",this._onComponentRemove))}}}removeObject(t){if(t.is3dContainer?.())return;if(t.isContainer()){const e=t,n=e.components||[];for(const t of n)this.removeObject(t);e.off&&(e.off("add",this._onComponentAdd),e.off("remove",this._onComponentRemove))}const e=t._realObject;if(e)try{const n=e.object3d;n&&this.gizmoManager.attached===n&&this.gizmoManager.detach(),n&&(e instanceof Wh?this.rendererManager.css3DScene.remove(n):n.removeFromParent()),e.dispose?.(),t._realObject=void 0}catch(t){Ki(t)}}resize(t,e,n=!1){const i=this._host;if(!i)return;if(void 0===t||void 0===e){const n=i.bounds;t=n.width,e=n.height}if(t=Math.abs(t)||1,e=Math.abs(e)||1,n)return void this._applyResize(t,e);this.rendererManager.css3DRenderer?.setSize(t,e);const r=t,s=e;clearTimeout(this._resizeDebouncer),this._resizeDebouncer=window.setTimeout(()=>{this._resizeDebouncer=void 0,this._applyResize(r,s)},100)}_applyResize(t,n){this.cameraManager.updateAspect(t,n),this.rendererManager.resize(t,n);const i=new e.Vector2(t,n);for(const t of this._arrows.values())t.traverse(t=>{t instanceof p&&t.material.resolution.copy(i)});this._initialized&&this.renderThreeD()}animate(){if(!this._initialized||!this.controlsManager.isActive)return;this.sceneManager.updateAnimation();let t=!1;const e=n=>{for(const i of n)i._animation?.started&&i._realObject&&(i._realObject.syncAnimationDelta(),t=!0),i.components&&e(i.components)};e(this._host?.components||[]),this.controlsManager.update(),this.renderThreeD(),t&&this._host?.invalidate()}renderThreeD(){this._initialized&&(this.vertexGizmoManager?.isAttached&&this.vertexGizmoManager.updateHandleScales(this.cameraManager.activeCamera),this.rendererManager.render(),this.renderCSS3D())}setCameraView(t,e){const n=this._host;if(!n)return;const{width:i,height:r}=n.bounds,s=n.element,o=s?.clientWidth||i,a=s?.clientHeight||r;let c;c="perspective"===t?this.cameraManager.restorePerspective():this.cameraManager.setOrthoView(t,i,r,o,a),this.controlsManager.setCamera(c),this.gizmoManager.updateCamera(c),this.rendererManager.updateRenderPassCamera(c),!1!==e?.render&&this.renderThreeD(),this.onCameraViewChanged?.(t)}renderCSS3D(){const t=this.cameraManager.activeCamera;t&&this.rendererManager.renderCSS3D(t)}buildOverlays(){const t=this._host;if(!t?.element)return;t.element.appendChild(this.css3DRenderer.domElement);const e=this.rendererManager.hudCSS3DRenderer?.domElement;e&&t.element.appendChild(e)}destroy(){this.interactionManager.cleanup(),this._resizeDebouncer&&(clearTimeout(this._resizeDebouncer),this._resizeDebouncer=void 0),this._onFocus&&(window.removeEventListener("focus",this._onFocus),this._onFocus=void 0),this.vertexGizmoManager.destroy(),this.boxSelectionManager.destroy(),this.bookmarkManager.destroy(),this.gizmoManager.destroy(),this.controlsManager.destroy(),this.lightManager.destroy(),this.rendererManager.destroy(),this.cameraManager.destroy(),this.sceneManager.destroy(),this.eventManager.destroy(),this._initialized=!1}forceCleanupDragState(){this.interactionManager.forceCleanupDragState(),this.boxSelectionManager.isActive&&(this.boxSelectionManager.cancelSelection(),this.controlsManager.setEnabled(!0)),this._isSpacePanning&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0)),this._host?.element&&(this._host.element.style.cursor="")}clearAllObjects(){this.gizmoManager.detach();const t=this._host?.components||[];for(const e of t)e._realObject&&this.removeObject(e)}rebuildForHost(t,e){this.interactionManager.cleanup();try{this._cleanupEventHandlers()}catch(t){}this._host=t,this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged),this._onAddStart=t=>{this.placementManager.start(t),this._host?.element&&(this._host.element.style.cursor="crosshair",this._host.element.focus())},this._onAddStop=()=>{this.placementManager.stop(),this._host?.element&&(this._host.element.style.cursor="")},t.root.on("addstart",this._onAddStart),t.root.on("addstop",this._onAddStop)),this.createObjects(t.components||[]),t.element&&this.interactionManager.setup(t.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate());const n=this.controlsManager._position0?.clone(),i=this.controlsManager._target0?.clone();this.controlsManager.setup(this.cameraManager.camera,t),n&&this.controlsManager._position0.copy(n),i&&this.controlsManager._target0.copy(i),t.app?.isEditMode&&t.element&&this.boxSelectionManager.setup(t.element),t.app?.isEditMode&&t.element&&this.sceneManager.scene&&(this.gizmoManager.setup(this.cameraManager.camera,t.element,this.sceneManager.scene),this._setupGizmoCallbacks()),this._onFocus||(this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus)),this.renderThreeD()}dispose(){const t=e=>{for(const n of e)if(!n.is3dContainer?.()){if(n.isContainer()){const e=n.components||[];t(e)}n._realObject&&(n._realObject.dispose?.(),n._realObject=void 0)}};t(this._host?.components||[]),this._decoratorOutlines.clear(),this._selectionOutlineObjects=[],this.clearArrows(),this.placementManager.destroy(),this._cleanupEventHandlers(),this.rendererManager.disposeCSS3DScene(),this.destroy(),this._host=void 0}_buildInteractionDelegate(){return{isPlacementMode:()=>this.placementManager.isActive,handlePlacementClick:t=>{if(!this._host?.root)return;const e=this.placementManager.raycastGroundPlane(t);if(e){const t=this._host,n=t.bounds.width||800,i=t.bounds.height||600,r=e.x+n/2,s=e.z+i/2;Ml.call(t.root,this.placementManager.pendingModels,{cx:r,cy:s}),t.root.trigger("addstop")}},handlePlacementHover:t=>{const e=this.placementManager.raycastGroundPlane(t);this.placementManager.updateIndicator(e),this.renderThreeD()},tryAltClickSelect:t=>{if(!this._host?.app?.isEditMode||!this._host.root)return!1;this._updateMouseNDCFromClient(t.clientX,t.clientY);const e=this.cameraManager.activeCamera;if(e&&this.sceneManager.scene){const n=this.eventManager.handleClick(e,this.sceneManager.scene,t);if(n?.component)return this._host.root.selected=[n.component],!0}return!1},captureMouseDownAltKey:t=>{this.gizmoOperationManager.captureAltKey(t)},handleClickAt:(t,e,n)=>{this._handleClickAt(n)},handleWheel:t=>this.onWheel(t),handleDblClick:t=>this.onDblClick(t),handleTouchStart:t=>this.onTouchStart(t),handleTouchMove:t=>this.onPan(t),handleTouchEnd:t=>this.onTouchEnd(t),handleKeyDown:t=>this.onKeyDown(t),handleKeyUp:t=>this._onKeyUp(t),isSpacePanning:()=>this._isSpacePanning,handleBoxSelectionStart:(t,e)=>{this.controlsManager.setEnabled(!1),this._host?.element&&(this._host.element.style.cursor="crosshair"),this.boxSelectionManager.startSelection(t,e)},handleBoxSelectionUpdate:(t,e)=>{this.boxSelectionManager.updateSelection(t,e)},tryVertexDragStart:t=>{if(!this.vertexGizmoManager.isAttached)return!1;const e=this.cameraManager.activeCamera;if(!e)return!1;const n=this.eventManager.mouse,i=this.vertexGizmoManager.onPointerDown(n,e,t);return i&&this.controlsManager.setEnabled(!1),i},handleVertexDragMove:t=>{const e=this.cameraManager.activeCamera;if(!e)return;const n=this.eventManager.mouse;this.vertexGizmoManager.onPointerMove(n,e,t),this._host?.invalidate()},handleVertexDragEnd:t=>{this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),this._host?.invalidate()},handleBoxSelectionEnd:(t,e)=>{this.controlsManager.setEnabled(!0),this._host?.element&&(this._host.element.style.cursor="");const n=this.cameraManager.activeCamera,i=this.sceneManager.scene,r=this._host?.components||[];if(n&&i){let s=this.boxSelectionManager.endSelection(n,i,r);if(e&&t){const t=this._host?.root?.selected||[];if(t.length>0){const e=t[0].state?.type;e&&(s=s.filter(t=>t.state?.type===e))}}if(s.length>0&&this._host?.root)if(t){const t=this._host,e=(this._host.root.selected||[]).filter(e=>e!==t);for(const t of s)e.includes(t)||e.push(t);this._host.root.selected=e}else this._host.root.selected=s}else this.boxSelectionManager.cancelSelection()}}}_handleClickAt(t){const n=this._host,i=this.cameraManager.activeCamera;if(!i||!this.sceneManager.scene)return;if(this._pathMarkers&&this._pathMarkers.children.length>0){const t=new e.Raycaster,n=this.eventManager.mouse;t.setFromCamera(n,i);const r=t.intersectObjects(this._pathMarkers.children,!0);if(r.length>0){let t=r[0].object;for(;t&&void 0===t.userData.bookmarkSlotIndex;)t=t.parent;if(t&&void 0!==t.userData.bookmarkSlotIndex)return void this.animateToSlot(t.userData.bookmarkSlotIndex)}}if(this.vertexGizmoManager?.isDragging)return this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),void this._host?.invalidate();const r=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),r)return;const s=this.eventManager.handleClick(i,this.sceneManager.scene,t);if(n.root){const t=n.app?.mode;if(4===t||5===t){if(!s?.component){const e=4===t?"stylepastestop":"databindpastestop";n.root.trigger(e)}return}}n.app?.isEditMode&&n.root&&this._applySelection(n.root,s?.component,t.shiftKey)}_applySelection(t,e,n){if(e)if(n){const n=(t.selected||[]).slice(),i=n.indexOf(e);-1===i?n.push(e):n.splice(i,1),t.selected=n}else{let n=null,i=e.parent;for(;i?.isGroup?.();)n=i,i=i.parent;if(n){if(!(t.selected||[]).some(t=>{if(t===n)return!0;let e=t.parent;for(;e?.isGroup?.();){if(e===n)return!0;e=e.parent}return!1}))return void(t.selected=[n])}t.selected=[e]}else n||(t.selected=[])}getObjectByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectByRaycast(t,this.sceneManager.scene):void 0}getObjectsByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectsByRaycast(t,this.sceneManager.scene):void 0}_updateMouseNDCFromClient(t,e){const n=this._host?.element;if(n){const i=n.getBoundingClientRect();if(i.width>0&&i.height>0){const n=t-i.left,r=e-i.top;return void this.eventManager.updateMouseNDC(n,r,0,0,i.width,i.height)}}const i=this._host;if(i){const{left:n,top:r,width:s,height:o}=i.bounds;s>0&&o>0&&this.eventManager.updateMouseNDC(t,e,n,r,Math.abs(s),Math.abs(o))}}_eventToNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0)return{ndcX:(t.clientX-n.left)/n.width*2-1,ndcY:-(t.clientY-n.top)/n.height*2+1}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const r=n.transcoordC2S(t.offsetX,t.offsetY);return{ndcX:r.x/Math.abs(e)*2-1,ndcY:-(r.y/Math.abs(i)*2-1)}}}return{ndcX:0,ndcY:0}}_updateMouseNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0){const e=t.clientX-n.left,i=t.clientY-n.top;return void this.eventManager.updateMouseNDC(e,i,0,0,n.width,n.height)}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const r=n.transcoordC2S(t.offsetX,t.offsetY);this.eventManager.updateMouseNDC(r.x,r.y,0,0,Math.abs(e),Math.abs(i))}}}onMouseUp(t){if(this.controlsManager.isActive){const e=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),e)return t.stopPropagation(),!0;const n=this.cameraManager.activeCamera;this._updateMouseNDC(t);const i=this.eventManager.handleClick(n,this.sceneManager.scene,t),r=this._host;return r?.app?.isEditMode&&r.root&&this._applySelection(r.root,i?.component,t.shiftKey),t.stopPropagation(),!0}return!1}onMouseMove(t){if(this.controlsManager.isActive){this.gizmoManager.forwardEvent(t,"pointermove");const e=this.cameraManager.activeCamera;return this._updateMouseNDC(t),this.eventManager.handleHover(e,this.sceneManager.scene,t),t.stopPropagation(),!0}return!1}onMouseDown(t){return!(!this.controlsManager.isActive||(this.gizmoManager.forwardEvent(t,"pointerdown"),!this.gizmoManager.isDragging))&&(t.stopPropagation(),!0)}onMouseLeave(t){return!1}onWheel(t){if(this.controlsManager.isActive){const{ndcX:e,ndcY:n}=this._eventToNDC(t);if("perspective"!==this.cameraManager.activeView){const i=t.deltaY>0?.9:1.1;this.controlsManager.zoomOrthoAtCursor(i,e,n),this.renderThreeD()}else{const i=Math.pow(.999,-t.deltaY);this.controlsManager.dollyAtCursor(i,e,n),this.renderThreeD()}return t.stopPropagation(),!0}return!1}onDblClick(t){if(!this.controlsManager.isActive)return!1;const e=this._host,n=this.cameraManager.activeCamera;if(!n||!this.sceneManager.scene)return this.controlsManager.reset(),!0;if(e?.app?.isEditMode&&e.root){if(this.vertexGizmoManager.isAttached){const t=this.eventManager.mouse;if(this.vertexGizmoManager.onDblClick(t,n))return this._host?.invalidate(),!0}const t=this.eventManager.getObjectByRaycast(n,this.sceneManager.scene),e=t?.userData?.context?.component;if(e?.hasTextProperty)return Zh(e,this.rendererManager,()=>{this.renderThreeD()}),!0}return this.controlsManager.reset(),t.stopPropagation(),!0}pinResetPosition(){this.controlsManager.pinResetPosition()}onDragStart(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(t.stopPropagation(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.bookmarkManager.stopPlay(),this.controlsManager.onDragStart(t),t.stopPropagation(),!0))}onDragMove(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointermove"),t.stopPropagation(),!0):(this.controlsManager.onDragMove(t),t.stopPropagation(),!0))}onDragEnd(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointerup"),t.stopPropagation(),!0):(this.controlsManager.onDragEnd(t),t.stopPropagation(),!0))}onTouchStart(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchStart(t),t.stopPropagation(),!0)}onPan(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchMove(t),t.stopPropagation(),!0)}onTouchEnd(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchEnd(t),t.stopPropagation(),!0)}onKeyDown(t){return!t.isComposing&&229!==t.keyCode&&(!!this.controlsManager.isActive&&(!!this._handleEscapeKey(t)||(!(!this._host?.app?.isEditMode||!this._handleEditModeKey(t))||(!!this._handleCursorHintKey(t)||(!!this._handleCameraAndViewKey(t)||(!!this._handlePlaybackKey(t)||(!t.shiftKey||t.ctrlKey||t.metaKey||t.altKey||"KeyB"!==t.code||!this._host?.app?.isEditMode?(this.controlsManager.onKeyDown(t),t.ctrlKey||t.metaKey||t.stopPropagation(),!0):(this.onBookmarkEditToggle?.(),t.preventDefault(),!0))))))))}_handleEscapeKey(t){if("Escape"!==t.key&&"Escape"!==t.code)return!1;if(this.placementManager.isActive&&this._host?.root)return this._host.root.trigger("addstop"),t.stopPropagation(),!0;const e=this._host?.app,n=this._host?.root;return e&&4===e.mode?(n?.trigger("stylepastestop"),!0):e&&5===e.mode?(n?.trigger("databindpastestop"),!0):!(!e?.isEditMode||!n)&&(this.gizmoManager.detach(),n.selected=[],!0)}_handleEditModeKey(t){const e=this._host.root;if(t.metaKey||t.ctrlKey)switch(t.code){case"KeyZ":{const n=this._host?.app?.commander,i=(e?.selected||[]).filter(t=>t!==this._host).map(t=>t.state?.id).filter(Boolean);if(t.shiftKey?n?.redo():n?.undo(),e&&i.length>0){const t=i.map(t=>e.findById(t)).filter(Boolean);t.length>0&&(e.selected=t)}return t.preventDefault(),!0}case"KeyC":return e&&(this._clipboard=zl.call(e)),t.preventDefault(),!0;case"KeyX":return e&&(this._clipboard=Il.call(e)),t.preventDefault(),!0;case"KeyV":return e&&this._clipboard&&Ll.call(e,this._clipboard),t.preventDefault(),!0;case"KeyD":return e&&(this._clipboard=zl.call(e),this._clipboard&&Ll.call(e,this._clipboard)),t.preventDefault(),!0;default:return!1}if("Enter"===t.code||"NumpadEnter"===t.code){const n=e?.selected;if(1===n?.length&&n[0].hasTextProperty)return Zh(n[0],this.rendererManager,()=>{this.renderThreeD()}),t.preventDefault(),!0}switch(t.code){case"KeyW":return this.setGizmoMode("translate"),!0;case"KeyE":return this.setGizmoMode("rotate"),!0;case"KeyR":return this.setGizmoMode("scale"),!0;case"Delete":case"Backspace":return e&&kl.call(e),!0}return this._handleArrowKeyMove(t,e)}_handleArrowKeyMove(t,e){const n=e?.selected;if(!n||0===n.length)return!1;const i=t.shiftKey?this._host.MPP||10:1;let r;switch(t.code){case"ArrowLeft":r={x:-i,y:0};break;case"ArrowRight":r={x:i,y:0};break;case"ArrowUp":r={x:0,y:-i};break;case"ArrowDown":r={x:0,y:i}}return!!r&&(il.around(this._host.app.commander,()=>{n.forEach(t=>{t.stuck||t.move(r,!1)})}),t.preventDefault(),t.stopPropagation(),!0)}_handleCursorHintKey(t){return!(t.repeat||!this._host?.app?.isEditMode)&&("AltLeft"===t.code||"AltRight"===t.code?(this._host?.element&&(this._host.element.style.cursor="grab"),!0):("ShiftLeft"===t.code||"ShiftRight"===t.code)&&(this._host?.element&&(this._host.element.style.cursor=this.gizmoManager.isEngaged?"grab":"crosshair"),!0))}_handleCameraAndViewKey(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return!1;switch(t.code){case"KeyQ":case"Digit0":return this._host?.toggleThreeD?.(),t.preventDefault(),!0;case"Digit1":return this.setCameraView("perspective"),t.preventDefault(),!0;case"Digit2":return this.setCameraView("top"),t.preventDefault(),!0;case"Digit3":return this.setCameraView("front"),t.preventDefault(),!0;case"Digit4":return this.setCameraView("back"),t.preventDefault(),!0;case"Digit5":return this.setCameraView("right"),t.preventDefault(),!0;case"Digit6":return this.setCameraView("left"),t.preventDefault(),!0;case"KeyH":return this.onHelpToggle?.(),t.preventDefault(),!0;case"KeyB":return this.onBookmarkNavToggle?.(),t.preventDefault(),!0;case"KeyF":return this.onSearchToggle?.(),t.preventDefault(),!0;case"KeyD":return this.onDataBindingToggle?.(),t.preventDefault(),!0;case"KeyM":return this.onMonitorToggle?.(),t.preventDefault(),!0}return!1}_handlePlaybackKey(t){return!(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)&&("KeyP"!==t.code||this._host?.app?.isEditMode?"Space"===t.code&&this._host?.app?.isEditMode?(this._isSpacePanning=!0,this._beforeSpaceMode=this._host.app.mode,this._host.app.mode=2,this._host?.element&&(this._host.element.style.cursor="grab"),t.preventDefault(),!0):"Space"!==t.code||this._host?.app?.isEditMode?"KeyO"===t.code&&!this._host?.app?.isEditMode&&(this.bookmarkManager.resetPlay(),this.bookmarkManager.toggleOrbitRotation(this.controlsManager),t.preventDefault(),!0):(this.bookmarkManager.isOrbitRotating||this.bookmarkManager.isOrbitPaused?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):(this.bookmarkManager.isPlaying||this.bookmarkManager.lastPlayProgress>=0)&&this.togglePlay(),t.preventDefault(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.restartPlay(),t.preventDefault(),!0))}_onKeyUp(t){return"AltLeft"===t.code||"AltRight"===t.code||"ShiftLeft"===t.code||"ShiftRight"===t.code?(this._host?.element&&!this._isSpacePanning&&(this._host.element.style.cursor=""),!0):!("Space"!==t.code||!this._isSpacePanning)&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0),this._host?.element&&(this._host.element.style.cursor=""),t.preventDefault(),!0)}onPinch(t){if(this.controlsManager.isActive){if("perspective"!==this.cameraManager.activeView){const e=this.cameraManager.activeCamera,n=t.scale||1;e.zoom=Math.max(.1,Math.min(20,e.zoom*n)),e.updateProjectionMatrix(),this.controlsManager.markCameraChanged(),this.renderThreeD()}else{const e=t.scale||1;Math.abs(e-1)>.01&&(this.controlsManager.dollyAtCursor(1/e,0,0),this.renderThreeD())}return t.stopPropagation(),!0}return!1}onDoubleTap(){this.controlsManager.reset()}getCameraState(){const t=this._host;if(!t)return null;const e=this.cameraManager.camera;if(!e)return null;const{width:n,height:i}=t.bounds,r=Math.floor(Math.min(n,i))||1;return{view:this.cameraManager.activeView,cameraX:e.position.x/(n||1),cameraY:e.position.z/(i||1),cameraZ:e.position.y/r}}getCameraWorldState(){const t=this.cameraManager.camera;if(!t)return null;const e=this.controlsManager.target;return{position:{x:t.position.x,y:t.position.y,z:t.position.z},target:{x:e.x,y:e.y,z:e.z}}}captureSessionState(){const t=this.cameraManager.activeView,e=this.cameraManager.camera,n=this.controlsManager.target,i={view:t};return e&&(i.perspPosition={x:e.position.x,y:e.position.y,z:e.position.z}),i.orbitTarget={x:n.x,y:n.y,z:n.z},i}captureViewportInfo(){const t=this.cameraManager.activeCamera,e=this.controlsManager.target.clone();let n=0,i=0;if(t?.fov){i=2*t.position.distanceTo(e)*Math.tan(t.fov*Math.PI/180/2),n=i*(t.aspect||1)}return{target:e,visibleWidth:n,visibleHeight:i}}restoreSessionState(t){"perspective"!==t.view&&this.setCameraView(t.view,{render:!1});const n=this.cameraManager.camera;n&&t.perspPosition&&n.position.set(t.perspPosition.x,t.perspPosition.y,t.perspPosition.z),t.orbitTarget&&this.controlsManager.restoreTarget(new e.Vector3(t.orbitTarget.x,t.orbitTarget.y,t.orbitTarget.z))}saveCameraToSlot(t){if(!this._host?.app?.isEditMode)return;const n=this.cameraManager.camera;if(!n)return;if("perspective"!==this.cameraManager.activeView)return;const i=this.controlsManager.target,r=n.position;let s=i.x,o=i.y,a=i.z;if(r.distanceTo(i)<1){const t=new e.Vector3(0,0,-1).applyQuaternion(n.quaternion);s=r.x+1*t.x,o=r.y+1*t.y,a=r.z+1*t.z}const c={position:{x:r.x,y:r.y,z:r.z},target:{x:s,y:o,z:a}};this.bookmarkManager.saveSlot(t,c),this._host?.app?.isEditMode&&this._host?.set?.("cameraBookmarks",this.bookmarkManager.exportSlots()),this.onBookmarkChanged?.()}positionCameraForViewport(t,n,i,r,s){const o=this.cameraManager.activeCamera;if(!o?.position)return;const a=(o.fov||45)*Math.PI/180,c=o.aspect||1,l=r/2/Math.tan(a/2),h=i/2/(c*Math.tan(a/2)),d=Math.max(l,h),u=s?.orbitTarget?.y??0,p=new e.Vector3(t,u,n);let f;if(s?.perspPosition&&s?.orbitTarget){const t=new e.Vector3(s.perspPosition.x,s.perspPosition.y,s.perspPosition.z),n=new e.Vector3(s.orbitTarget.x,s.orbitTarget.y,s.orbitTarget.z);f=t.sub(n).normalize()}else f=o.position.clone().normalize();o.position.copy(p.clone().add(f.multiplyScalar(d)));try{this.controlsManager.restoreTarget(p)}catch{o.lookAt(p)}this._host?.invalidate()}centerToComponent(t,n){const i=this.cameraManager.activeCamera;if(!i)return;const r=new e.Vector3,s=t._realObject;if(s?.object3d)s.object3d.getWorldPosition(r);else{const{x:e=0,y:n=0}=t.center,{width:i=0,height:s=0}=t.parent?.bounds??{};r.set(e-i/2,0,n-s/2)}const o=this.controlsManager.target,a=i.position.clone().sub(o),c=r.clone().add(a);if(!n)return i.position.copy(c),this.controlsManager.restoreTarget(r),void this._host?.invalidate();const l=i.position.clone(),h=o.clone(),d=performance.now(),u=()=>{const t=performance.now()-d,e=Math.min(t/800,1),n=e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2;i.position.lerpVectors(l,c,n);const s=h.clone().lerp(r,n);this.controlsManager.restoreTarget(s),this._host?.invalidate(),e<1&&requestAnimationFrame(u)};requestAnimationFrame(u)}animateToSlot(t){const e=this.cameraManager.camera;e&&(this.bookmarkManager.isPlaying&&this.bookmarkManager.stopPlay(),"perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.animateToSlot(t,e,this.controlsManager),this.bookmarkManager.setProgressForSlot(t))}scrubPath(t){const e=this.cameraManager.camera;if(!e)return;const n=this.bookmarkManager.evaluatePath(t);n&&(e.position.copy(n.position),this.controlsManager.restoreTarget(n.target),this._host?.invalidate())}togglePlay(t=-1){const e=this.cameraManager.camera;if(e){if("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.isPlaying)return this.bookmarkManager.stopPlay(),void(this._pathVisible&&this.showBookmarkPath());this.hideBookmarkPath(),this.bookmarkManager.startPlay(e,this.controlsManager,2e3,1200,t)}}restartPlay(){const t=this.cameraManager.camera;t&&("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.stopPlay(),this.hideBookmarkPath(),this.bookmarkManager.startPlay(t,this.controlsManager,2e3,1200,-1,!0))}startAutoPlay(t){"orbit"===t?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):"play"===t&&this.togglePlay()}showBookmarkPath(){this._pathVisible=!0,this.hideBookmarkPath();const t=this.sceneManager.scene;if(!t)return;const n=this.bookmarkManager.getPlayableSlots();if(0===n.length)return;const i=[];for(const t of n){const n=this.bookmarkManager.getSlot(t);n&&i.push(new e.Vector3(n.position.x,n.position.y,n.position.z))}if(i.length>=2){let n=0;for(let t=1;t<i.length;t++)n+=i[t].distanceTo(i[t-1]);const r=n/(i.length-1),s=i.length>=3?new e.CatmullRomCurve3(i,!0,"centripetal").getPoints(30*i.length):i,o=(new e.BufferGeometry).setFromPoints(s),a=new e.LineDashedMaterial({color:4890367,dashSize:.06*r,gapSize:.03*r,opacity:.5,transparent:!0,depthTest:!1});this._pathLine=new e.Line(o,a),this._pathLine.computeLineDistances(),this._pathLine.renderOrder=9999,t.add(this._pathLine)}let r;if(i.length>=2){let t=0;for(let e=1;e<i.length;e++)t+=i[e].distanceTo(i[e-1]);r=t/(i.length-1)*.08}else{const t=this.bookmarkManager.getSlot(n[0]);r=.08*(t?new e.Vector3(t.position.x,t.position.y,t.position.z).distanceTo(new e.Vector3(t.target.x,t.target.y,t.target.z)):10)}this._pathMarkers=new e.Group,this._pathMarkers.renderOrder=9999;const s=new e.MeshBasicMaterial({color:4890367,opacity:.6,transparent:!0,depthTest:!1}),o=new e.MeshBasicMaterial({color:4890367,opacity:.15,transparent:!0,depthTest:!1,side:e.DoubleSide});for(const t of n){const n=this.bookmarkManager.getSlot(t);if(!n)continue;const i=new e.Vector3(n.position.x,n.position.y,n.position.z),a=new e.Vector3(n.target.x,n.target.y,n.target.z),c=(new e.Vector3).subVectors(a,i).normalize(),l=new e.Group;l.position.copy(i);const h=(new e.Matrix4).lookAt(new e.Vector3(0,0,0),c,new e.Vector3(0,1,0));l.quaternion.setFromRotationMatrix(h);const d=.2*r,u=new e.BoxGeometry(1.2*d,.8*d,d),p=new e.Mesh(u,s);p.renderOrder=9999,l.add(p);const f=Math.max(.06*i.distanceTo(a),.5*d),g=.35*f,m=9*g/16,y=new e.BufferGeometry,b=[0,0,0,-g,m,-f,g,m,-f,g,-m,-f,-g,-m,-f],v=[0,1,2,0,2,3,0,3,4,0,4,1];y.setAttribute("position",new e.Float32BufferAttribute(b,3)),y.setIndex(v),y.computeVertexNormals();const _=new e.Mesh(y,o);_.position.z=.5*-d,_.renderOrder=9999,l.add(_);const x=new Float32Array([0,0,0,-g,m,-f,0,0,0,g,m,-f,0,0,0,g,-m,-f,0,0,0,-g,-m,-f,-g,m,-f,g,m,-f,g,m,-f,g,-m,-f,g,-m,-f,-g,-m,-f,-g,-m,-f,-g,m,-f]),w=new e.BufferGeometry;w.setAttribute("position",new e.BufferAttribute(x,3));const M=new e.LineSegments(w,new e.LineBasicMaterial({color:4890367,opacity:.5,transparent:!0,depthTest:!1}));M.position.z=.5*-d,M.renderOrder=9999,l.add(M),l.userData.bookmarkSlotIndex=t,this._pathMarkers.add(l)}t.add(this._pathMarkers),this._host?.invalidate()}hideBookmarkPath(t=!1){t&&(this._pathVisible=!1);const e=this.sceneManager.scene;if(this._pathLine&&(e?.remove(this._pathLine),this._pathLine.geometry.dispose(),this._pathLine.material.dispose(),this._pathLine=void 0),this._pathMarkers){e?.remove(this._pathMarkers);const t=new Set;this._pathMarkers.traverse(e=>{e.geometry&&e.geometry.dispose();const n=e.material;n&&!t.has(n)&&(n.dispose(),t.add(n))}),this._pathMarkers=void 0}this._host?.invalidate()}initBookmarks(){const t=this._host;if(!t)return;const e=t.state.cameraBookmarks;Array.isArray(e)&&this.bookmarkManager.importSlots(e),this.bookmarkManager.setCallbacks(()=>this._host?.invalidate())}onchange(t){if(t.hasOwnProperty("autoRotate")&&this.controlsManager.setAutoRotate(t.autoRotate),t.hasOwnProperty("cameraFloorConstraint")){const e=!this._host?.app?.isEditMode;this.controlsManager.setFloorConstraint(e&&!!t.cameraFloorConstraint)}if(t.hasOwnProperty("fov")||t.hasOwnProperty("near")||t.hasOwnProperty("far")){const t=this._host;if(t){const{near:e,far:n,fov:i}=t.state;this.cameraManager.updateProperties({near:e,far:n,fov:i}),this.controlsManager.markCameraChanged()}}t.hasOwnProperty("exposure")&&(this.rendererManager.setExposure(Number(t.exposure)||1),this.renderThreeD());let e=!1;if((t.hasOwnProperty("hemiIntensity")||t.hasOwnProperty("hemiSkyColor")||t.hasOwnProperty("hemiGroundColor"))&&(this.lightManager.updateHemisphere({intensity:t.hemiIntensity,skyColor:t.hemiSkyColor,groundColor:t.hemiGroundColor}),e=!0),t.hasOwnProperty("dirLightEnabled")){const n=this._host;n&&this.lightManager.setDirectionalEnabled(t.dirLightEnabled,{color:n.state.dirLightColor,intensity:n.state.dirLightIntensity}),e=!0}if((t.hasOwnProperty("dirLightColor")||t.hasOwnProperty("dirLightIntensity"))&&(this.lightManager.updateDirectional({color:t.dirLightColor,intensity:t.dirLightIntensity}),e=!0),t.hasOwnProperty("dirLightFollowCamera")){if(this.lightManager.setDirectionalFollowCamera(!1!==t.dirLightFollowCamera),!1===t.dirLightFollowCamera){const t=this._host?.state;this.lightManager.setDirectionalAngle(t?.dirLightAzimuth??30,t?.dirLightElevation??45)}e=!0}if(t.hasOwnProperty("dirLightAzimuth")||t.hasOwnProperty("dirLightElevation")){const n=this._host?.state;!1===n?.dirLightFollowCamera&&this.lightManager.setDirectionalAngle(t.dirLightAzimuth??n?.dirLightAzimuth??30,t.dirLightElevation??n?.dirLightElevation??45),e=!0}if(t.hasOwnProperty("dirShadowEnabled")||t.hasOwnProperty("dirShadowBias")){const n=this.lightManager.dirLight;n&&(t.hasOwnProperty("dirShadowEnabled")&&(n.castShadow=!1!==t.dirShadowEnabled),t.hasOwnProperty("dirShadowBias")&&(n.shadow.bias=t.dirShadowBias??-5e-4)),e=!0}e&&this.renderThreeD(),(t.hasOwnProperty("fillStyle")||t.hasOwnProperty("floorMaterial3d"))&&(this.sceneManager.updateFloor(this._host),this.renderThreeD()),(t.hasOwnProperty("sky")||t.hasOwnProperty("skyColor"))&&(this.sceneManager.setSky(this._host.state.sky,this._host.state.skyColor),this.renderThreeD()),t.hasOwnProperty("placement")&&(this.sceneManager.updateFloor(this._host),this._cascadeUpdateTransform(this._host),this.renderThreeD())}_cascadeUpdateTransform(t){const e=t?._realObject;e&&e.updateTransform?.();const n=t?.components;if(n)for(const t of n)this._cascadeUpdateTransform(t)}get domElement(){return this.rendererManager.domElement}getRendererSize(){return this.rendererManager.getSize()}showWebglNoSupportText(t,e,n){t.save(),t.font=e/20+"px Arial",t.textAlign="center",t.fillText("WebGL no support",e/2-e/40,n/2),t.restore()}showDebugFPS(t){t.font="100px Arial",t.textAlign="center",t.fillStyle="black",t.globalAlpha=.5,t.fillText(String(vh()),100,100)}get decoratorOutlines(){return this._decoratorOutlines}addOutline(t){this._decoratorOutlines.add(t),this._syncOutlinePass(),this._host?.invalidate()}removeOutline(t){this._decoratorOutlines.delete(t),this._syncOutlinePass(),this._host?.invalidate()}clearOutlines(){this._decoratorOutlines.clear(),this._syncOutlinePass(),this._host?.invalidate()}addArrow(t,n,i,r={}){this.removeArrow(t);const s=n._realObject,o=i._realObject;if(!s?.object3d||!o?.object3d)return;const a=new e.Vector3,c=new e.Vector3;s.object3d.getWorldPosition(a),o.object3d.getWorldPosition(c),a.y+=1,c.y+=1;const l=this.rendererManager.getSize(),h=Ah(a,c,r,new e.Vector2(l.width,l.height));h.name=`arrow-${t}`,h.userData._arrowStyle=r,this.sceneManager.scene?.add(h),this._arrows.set(t,h),this._host?.invalidate()}removeArrow(t){const n=this._arrows.get(t);n&&(n.traverse(t=>{if(t instanceof p)return t.geometry.dispose(),void t.material.dispose();if(t instanceof e.Sprite){const e=t.material.map;if(e){e.dispose();const t=e.source?.data;t instanceof HTMLCanvasElement&&(t.width=0,t.height=0)}return void t.material.dispose()}(t instanceof e.Mesh||t instanceof e.Line)&&(t.geometry.dispose(),t.material instanceof e.Material&&t.material.dispose())}),n.removeFromParent(),this._arrows.delete(t),this._host?.invalidate())}clearArrows(){for(const t of this._arrows.keys())this.removeArrow(t)}updateArrow(t,e,n){const i=this._getArrowStyle(t);i&&this.addArrow(t,e,n,i)}_getArrowStyle(t){const e=this._arrows.get(t);return e?e.userData._arrowStyle??null:null}highlightBookmarkMarker(t){this._highlightedMarkerIndex!==t&&(this._highlightedMarkerIndex=t,this._syncOutlinePass(),this._host?.invalidate())}clearBookmarkMarkerHighlight(){-1!==this._highlightedMarkerIndex&&(this._highlightedMarkerIndex=-1,this._syncOutlinePass(),this._host?.invalidate())}_syncOutlinePass(){const t=[...this._selectionOutlineObjects];for(const e of this._decoratorOutlines){const n=e._realObject;n?.object3d&&!t.includes(n.object3d)&&t.push(n.object3d)}if(this._highlightedMarkerIndex>=0&&this._pathMarkers)for(const e of this._pathMarkers.children)if(e.userData.bookmarkSlotIndex===this._highlightedMarkerIndex){e.traverse(e=>{e.isMesh&&t.push(e)});break}this.rendererManager.setOutlineObjects(t)}_handleSelectionChanged(t){const e=t.filter(t=>t!==this._host&&t._realObject);if(e.length>=1){const t=e[0]._realObject;t?.object3d&&t.gizmoTransformable?this.gizmoManager.attached&&this.gizmoManager.attach(t.object3d):this.gizmoManager.detach()}else this.gizmoManager.detach();const n=e.filter(t=>t.mutable&&t.path);n.length>0&&this.sceneManager.scene?this.vertexGizmoManager.attachMultiple(n,this.sceneManager.scene,this._host?.app?.commander):this.vertexGizmoManager.detach(),this._updateSelectionOutline(e),this._host?.invalidate()}_updateSelectionOutline(t){this._selectionOutlineObjects=[];for(const e of t){const t=e._realObject;t?.object3d&&this._selectionOutlineObjects.push(t.object3d)}this._syncOutlinePass()}}yc.register("three",{reflow:function(t){},capturables:function(t){return t.state.threed?[]:t.components},drawables:function(t){return t.state.threed?[]:t.components},isStuck:function(t){return!1}});const kd={x:1,y:1},Ad={x:0,y:0},Ed='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M4 5l12-1v12l-12-1z"/>\n <circle cx="10" cy="10" r="1.5"/>\n</svg>',Cd='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <rect x="4" y="4" width="12" height="12" rx="1"/>\n <path d="M10 2v2M10 16v2"/>\n <path d="M10 7v3l2-1.5" opacity="0.5"/>\n</svg>',Td='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M4 14l2-10h8l2 10z"/>\n <path d="M6 4h8" stroke-width="2"/>\n</svg>',Pd='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M4 6l2 10h8l2-10z"/>\n <path d="M6 16h8" stroke-width="2"/>\n</svg>',Dd='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M6 4l10 2v8l-10 2z"/>\n <path d="M16 6v8" stroke-width="2"/>\n</svg>',Od='<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M14 4L4 6v8l10 2z"/>\n <path d="M4 6v8" stroke-width="2"/>\n</svg>',zd={mutable:!1,resizable:!0,rotatable:!1,properties:[{type:"number",label:"width",name:"width"},{type:"number",label:"height",name:"height"},{type:"select",label:"fit-mode",name:"fitMode",property:{options:["ratio","both","width","height","center","none"]}}]};class Id extends Nc{constructor(){super(...arguments),this._threeDUserDeactivated=!1}get nature(){return zd}get is3dMode(){return!!this._threeCapability?.isInitialized}is3dContainer(){return this.is3dMode}get gizmoMode(){return this._threeCapability?.gizmoMode}setGizmoMode(t){this._threeCapability?.setGizmoMode(t)}get scene3d(){return this._threeCapability?.scene3d}get renderer3d(){return this._threeCapability?.renderer3d}get activeCamera3d(){return this._threeCapability?.activeCamera}get mixer(){return this._threeCapability?.mixer}addArrow3D(t,e,n,i){this._threeCapability?.addArrow(t,e,n,i)}removeArrow3D(t){this._threeCapability?.removeArrow(t)}clearArrows3D(){this._threeCapability?.clearArrows()}_buildLightingConfig(){const t=this.state,e={hemisphere:{skyColor:t.hemiSkyColor||"#ffffff",groundColor:t.hemiGroundColor||"#444444",intensity:t.hemiIntensity??4}};if(!1!==t.dirLightEnabled){const n=!1!==t.dirLightFollowCamera;if(e.directional={color:t.dirLightColor||"#ffffff",intensity:t.dirLightIntensity??2,attachToCamera:n,castShadow:!1!==t.dirShadowEnabled,shadowMapSize:t.dirShadowMapSize??2048,shadowBias:t.dirShadowBias??-5e-4},!n){const n=(t.dirLightAzimuth??30)*Math.PI/180,i=(t.dirLightElevation??45)*Math.PI/180,r=1e3;e.directional.position=[r*Math.cos(i)*Math.sin(n),r*Math.sin(i),r*Math.cos(i)*Math.cos(n)]}}return e}_hide2DLayers(){this.canvas&&(this.canvas.style.display="none"),this._overlay&&(this._overlay.style.display="none"),this._auxCanvas&&(this._auxCanvas.style.display="none"),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="none");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="none")}get _hasZoomHandler(){return(this.root?.model?.handlers||[]).includes("zoom-handler")}get _needsViewportSync(){return!!this.app?.isEditMode||this._hasZoomHandler}_activateThreeD(t=!1){this._threeCapability&&this._deactivateThreeD(),t&&!this._needsViewportSync&&(this._saved2DViewport={scale:{...this.get("scale")||{x:1,y:1}},translate:{...this.get("translate")||{x:0,y:0}}}),this._threeCapability=new Sd,this._threeCapability.init(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),this._hide2DLayers(),this.root?.transitionEffect?.dispose();const e=Bs.getInstance(),n=[];this.decoratorOverlay&&(n.push(...e.getTargetsWithType(this.decoratorOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorOverlay,"border-highlighting")),this.decoratorAuxOverlay&&(n.push(...e.getTargetsWithType(this.decoratorAuxOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorAuxOverlay,"border-highlighting"));for(const t of n)this._threeCapability.addOutline(t);if(this._threeCapability.domElement&&this.element){const t=this._threeCapability.domElement;t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.pointerEvents="none",t.setAttribute("scene","model-layer-webgl");const e=this._decoratorOverlay||this.element.firstChild;this.element.insertBefore(t,e)}if(this._threeCapability.buildOverlays(),t&&this._needsViewportSync){const t=this.get("scale")||{x:1};this._2dScaleBeforeThreeD=t.x||1,this._initCameraFrom2DViewport();const e=this._threeCapability?.captureViewportInfo();e&&(this._initialVisibleHeight=e.visibleHeight)}else if(this._lastCameraState)this._threeCapability.restoreSessionState(this._lastCameraState);else{const t=this.model.initialCameraView;t&&"perspective"!==t&&this._threeCapability.setCameraView(t,{render:!1})}if(this._pendingCameraView&&(this._threeCapability.setCameraView(this._pendingCameraView,{render:!1}),delete this._pendingCameraView),this._threeCapability.initBookmarks(),!this.app?.isEditMode){const t=this.model?.cameraAutoPlay;"orbit"!==t&&"play"!==t||this._threeCapability.startAutoPlay(t)}this.app?.isEditMode&&this._createToolbar(),this._registerPopupCallbacks();const i=this.root;i?.selected?.length>0&&this._threeCapability._handleSelectionChanged(i.selected),this._resizeThreeD(!0),this.element&&"function"==typeof this.element.focus&&this.element.focus()}_createToolbar(){if(!this.element)return;this._removeToolbar();const t=!!this._threeCapability,e=document.createElement("div");e.setAttribute("scene","threed-toolbar"),e.style.cssText=["position:absolute","top:12px","left:12px","display:flex","flex-direction:column","gap:1px","padding:4px","background:rgba(30,30,30,0.92)","border:1px solid rgba(255,255,255,0.08)","border-radius:8px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 16px rgba(0,0,0,0.4),inset 0 1px 0 rgba(255,255,255,0.05)","user-select:none"].join(";");const n=["width:32px","height:32px","display:flex","align-items:center","justify-content:center","border-radius:5px","cursor:pointer","transition:all 0.12s ease","position:relative"].join(";"),i=(t,e)=>{const i=document.createElement("div");return i.innerHTML=t,i.title=e,i.style.cssText=n,this._applyButtonStyle(i,!1),i.addEventListener("mouseenter",()=>{i.dataset.active||(i.style.background="rgba(255,255,255,0.1)")}),i.addEventListener("mouseleave",()=>{this._applyButtonStyle(i,!!i.dataset.active)}),i},r=()=>{const t=document.createElement("div");return t.style.cssText="height:1px;margin:3px 4px;background:rgba(255,255,255,0.1)",t},s=i(t?'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="14" height="14" rx="1.5"/>\n <line x1="3" y1="10" x2="17" y2="10" opacity="0.4"/>\n <line x1="10" y1="3" x2="10" y2="17" opacity="0.4"/>\n </svg>':'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2l7 4v8l-7 4-7-4V6l7-4z"/>\n <path d="M10 10l7-4M10 10v8M10 10L3 6"/>\n </svg>',t?"2D Mode":"3D Mode");if(this._applyToggleStyle(s,t),s.addEventListener("mouseenter",()=>{s.style.background=t?"rgba(255,160,60,0.35)":"rgba(255,160,60,0.25)"}),s.addEventListener("mouseleave",()=>{this._applyToggleStyle(s,t)}),s.addEventListener("click",()=>{this.toggleThreeD()}),e.appendChild(s),!t)return e.addEventListener("mousedown",t=>t.stopPropagation()),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),void(this._toolbar=e);e.appendChild(r());const o=this._threeCapability,a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:1px";const c=o.getCameraState()?.view??"perspective",l=[{view:"perspective",icon:Ed,title:"Perspective"},{view:"top",icon:Cd,title:"Top"},{view:"front",icon:Td,title:"Front"},{view:"back",icon:Pd,title:"Back"},{view:"right",icon:Dd,title:"Right"},{view:"left",icon:Od,title:"Left"}],h=[];for(const{view:t,icon:e,title:n}of l){const r=i(e,n);r.dataset.view=t,t===c&&(this._applyButtonStyle(r,!0),r.dataset.active="1"),r.addEventListener("click",()=>{this._threeCapability?.setCameraView(t)}),h.push(r),a.appendChild(r)}a.appendChild(r());const d=i('<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2 L13 5 L12 10 L15 13 L5 13 L8 10 L7 5 Z"/>\n <line x1="10" y1="13" x2="10" y2="18"/>\n </svg>',"Pin Camera View");d.addEventListener("click",()=>{const t=this._threeCapability?.getCameraState();t&&(this.set("cameraX",t.cameraX),this.set("cameraY",t.cameraY),this.set("cameraZ",t.cameraZ),this._threeCapability?.pinResetPosition())}),a.appendChild(d),e.appendChild(a),this._cameraButtons=h,o.onGizmoAttachChanged=t=>{this.root?.trigger("gizmoattach",t)},o.onCameraViewChanged=t=>{this._updateCameraButtons(t)},o.onGizmoModeChanged=t=>{this.root?.trigger("gizmomode",t)},e.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),this._toolbar=e}_applyToggleStyle(t,e){e?(t.style.background="rgba(255,140,40,0.3)",t.style.color="#ffaa44",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.5)"):(t.style.background="rgba(255,140,40,0.15)",t.style.color="#cc8833",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.3)")}_applyButtonStyle(t,e){e?(t.style.background="rgba(74,158,255,0.25)",t.style.color="#4a9eff",t.style.boxShadow="inset 0 0 0 1.5px rgba(74,158,255,0.5)",t.dataset.active="1"):(t.style.background="transparent",t.style.color="rgba(255,255,255,0.55)",t.style.boxShadow="none",delete t.dataset.active)}_updateCameraButtons(t){this._cameraButtons?.forEach(e=>{this._applyButtonStyle(e,e.dataset.view===t)})}_registerPopupCallbacks(){const t=this._threeCapability;t&&(t.onHelpToggle=()=>this._toggleHelpPanel(),t.onSearchToggle=()=>this.onSearchToggle?.(),t.onDataBindingToggle=()=>this.onDataBindingToggle?.(),t.onMonitorToggle=()=>this.onMonitorToggle?.(),t.onBookmarkNavToggle=()=>this._toggleBookmarkNav(),t.onBookmarkEditToggle=()=>this._toggleBookmarkEdit())}_closeFloatingPopup(){this._floatingPopupCloseHandler&&(this.target?.removeEventListener("mousedown",this._floatingPopupCloseHandler,!0),this._floatingPopupCloseHandler=void 0),this._floatingPopup?.parentNode&&this._floatingPopup.parentNode.removeChild(this._floatingPopup),this._floatingPopup=void 0}_showFloatingPopup(t,e=!1){this._closeFloatingPopup(),this._floatingPopup=t,e||(this._floatingPopupCloseHandler=e=>{t.contains(e.target)||this._closeFloatingPopup()},setTimeout(()=>{this.target?.addEventListener("mousedown",this._floatingPopupCloseHandler,!0)},0)),t.addEventListener("mousedown",t=>{t.stopPropagation();const e=t.target?.tagName;"INPUT"!==e&&"TEXTAREA"!==e&&"SELECT"!==e&&t.preventDefault()}),t.addEventListener("mouseup",t=>t.stopPropagation()),this._makePopupDraggable(t),this.target.appendChild(t)}_makePopupDraggable(t){let e=0,n=0,i=0,r=0;const s=s=>{const o=s.clientX-e,a=s.clientY-n;t.style.left=i+o+"px",t.style.top=r+a+"px"},o=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",s),t.removeEventListener("pointerup",o),t.style.cursor=""};t.addEventListener("pointerdown",a=>{const c=a.target,l=c.tagName?.toLowerCase();if("button"===l||"input"===l||"select"===l||"pointer"===c.style.cursor)return;if(c.closest("[data-drag-handle]"))return;const h=t.getBoundingClientRect(),d=t.parentElement.getBoundingClientRect();i=h.left-d.left,r=h.top-d.top,t.style.left=i+"px",t.style.top=r+"px",t.style.right="auto",t.style.bottom="auto",t.style.transform="none",e=a.clientX,n=a.clientY,t.style.cursor="grabbing",t.setPointerCapture(a.pointerId),t.addEventListener("pointermove",s),t.addEventListener("pointerup",o)})}_toggleHelpPanel(){if("help"===this._floatingPopup?.dataset.popupType)return void this._closeFloatingPopup();const t=!!this.app?.isEditMode,e=document.createElement("div");e.dataset.popupType="help",e.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","max-width:min(560px, calc(100% - 40px))","max-height:calc(100% - 40px)","overflow-y:auto","padding:16px 20px","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.08)","border-radius:10px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 20px rgba(0,0,0,0.5)","user-select:none","color:rgba(255,255,255,0.85)","font:12px/1.6 -apple-system,BlinkMacSystemFont,sans-serif","z-index:200"].join(";");const n=document.createElement("div");n.textContent="×",n.style.cssText="position:absolute;top:8px;right:12px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",n.addEventListener("click",()=>this._closeFloatingPopup()),n.addEventListener("mouseenter",()=>{n.style.color="#fff"}),n.addEventListener("mouseleave",()=>{n.style.color="rgba(255,255,255,0.4)"}),e.appendChild(n);const i=document.createElement("div");i.textContent="Help",i.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:12px",e.appendChild(i);const r=document.createElement("div");r.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:0 24px",e.appendChild(r);const s=[{label:"Camera",items:[{key:"1",desc:"Perspective",icon:Ed},{key:"2",desc:"Top",icon:Cd},{key:"3",desc:"Front",icon:Td},{key:"4",desc:"Back",icon:Pd},{key:"5",desc:"Right",icon:Dd},{key:"6",desc:"Left",icon:Od},{key:"0 / Q",desc:"Exit 3D"}]},{label:"Bookmarks",items:[{key:"B",desc:"Bookmark navigator"},{key:"Shift+B",desc:"Bookmark editor",editOnly:!0},{key:"P",desc:"Play tour",viewOnly:!0},{key:"O",desc:"Orbit rotation",viewOnly:!0},{key:"Space",desc:"Pan mode (edit) / Pause (view)"}]},{label:"Navigation",items:[{key:"Drag",desc:"Rotate camera"},{key:"Alt+Drag",desc:"Pan camera"},{key:"Space+Drag",desc:"Pan camera (no select)",editOnly:!0},{key:"Shift+Drag",desc:"Box select",editOnly:!0},{key:"Scroll",desc:"Dolly zoom"},{key:"DblClick",desc:"Reset camera"},{key:"Arrows",desc:"Pan camera"}]},{label:"Edit",items:[{key:"W",desc:"Move gizmo",editOnly:!0},{key:"E",desc:"Rotate gizmo",editOnly:!0},{key:"R",desc:"Scale gizmo",editOnly:!0},{key:"Ctrl+Z",desc:"Undo",editOnly:!0},{key:"Ctrl+Shift+Z",desc:"Redo",editOnly:!0},{key:"Ctrl+C/X/V",desc:"Copy / Cut / Paste",editOnly:!0},{key:"Del",desc:"Delete selected",editOnly:!0},{key:"Esc",desc:"Deselect all",editOnly:!0}]},{label:"Misc",items:[{key:"H",desc:"This help"},{key:"F",desc:"Search"}]}].map(e=>({...e,items:e.items.filter(e=>!(e.editOnly&&!t)&&(!e.viewOnly||!t))})).filter(t=>t.items.length>0),o=s.reduce((t,e)=>t+e.items.length+1,0);let a=0,c=s.length;for(let t=0;t<s.length;t++)if(a+=s[t].items.length+1,a>=o/2){c=t+1;break}const l=[s.slice(0,c),s.slice(c)];for(const t of l){const e=document.createElement("div");let n=!0;for(const i of t){if(!n){const t=document.createElement("div");t.style.cssText="height:1px;margin:8px 0;background:rgba(255,255,255,0.08)",e.appendChild(t)}n=!1;const t=document.createElement("div");t.textContent=i.label,t.style.cssText="font-size:10px;font-weight:700;text-transform:uppercase;color:rgba(255,255,255,0.45);margin:0 0 5px;letter-spacing:0.8px",e.appendChild(t);for(const t of i.items){const n=document.createElement("div");n.style.cssText="display:flex;justify-content:space-between;align-items:center;padding:2px 0;gap:12px";const i=document.createElement("span");i.style.cssText="display:inline-flex;gap:2px;flex-shrink:0";for(const e of t.key.split("+")){const n=document.createElement("kbd");if(n.textContent=e.trim(),n.style.cssText="font-size:10px;font-family:monospace;padding:1px 5px;border-radius:3px;background:rgba(255,255,255,0.08);border:1px solid rgba(255,255,255,0.12);color:rgba(255,255,255,0.65);line-height:1.4",i.appendChild(n),e!==t.key.split("+").at(-1)){const t=document.createElement("span");t.textContent="+",t.style.cssText="color:rgba(255,255,255,0.2);font-size:10px;margin:0 1px",i.appendChild(t)}}const r=document.createElement("span");if(r.style.cssText="font-size:11px;color:rgba(255,255,255,0.7);text-align:right;white-space:nowrap;display:inline-flex;align-items:center;gap:4px",r.appendChild(document.createTextNode(t.desc)),t.icon){const e=document.createElement("span");e.innerHTML=t.icon,e.style.cssText="display:inline-flex;opacity:0.6",r.appendChild(e)}n.appendChild(i),n.appendChild(r),e.appendChild(n)}}r.appendChild(e)}this._showFloatingPopup(e)}_toggleBookmarkNav(){"bookmark-nav"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-nav"):this._closeFloatingPopup()}_toggleBookmarkEdit(){"bookmark-edit"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-edit"):this._closeFloatingPopup()}_buildBookmarkPopup(t){const e=this._threeCapability;if(!e)return;const n="bookmark-nav"===t,i=!!this.app?.isEditMode,r=document.createElement("div");r.dataset.popupType=t,r.tabIndex=-1,r.style.cssText=["position:absolute",n?"bottom:12px":"top:12px","right:12px","min-width:"+(n?"140px":"200px"),"padding:10px 12px","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.08)","border-radius:10px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 20px rgba(0,0,0,0.5)","user-select:none","color:rgba(255,255,255,0.85)","font:12px/1.5 -apple-system,BlinkMacSystemFont,sans-serif","z-index:200"].join(";");const s=document.createElement("div");s.textContent="×",s.style.cssText="position:absolute;top:6px;right:10px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",s.addEventListener("click",()=>this._closeFloatingPopup()),s.addEventListener("mouseenter",()=>{s.style.color="#fff"}),s.addEventListener("mouseleave",()=>{s.style.color="rgba(255,255,255,0.4)"}),r.appendChild(s);const o=document.createElement("div");o.textContent="Bookmarks",o.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:8px;cursor:grab",r.appendChild(o);const a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:2px",r.appendChild(a);const c=e.bookmarkManager,l=()=>{i&&this.set?.("cameraBookmarks",c.exportSlots()),e.onBookmarkChanged?.()},h="border:none;background:transparent;color:inherit;cursor:pointer;padding:2px 4px;border-radius:4px;font-size:13px;line-height:1;display:flex;align-items:center;justify-content:center;width:24px;height:24px",d=t=>{const e=28,n=window.devicePixelRatio||1,i=document.createElement("canvas");i.width=e*n,i.height=e*n,i.style.cssText="width:28px;height:28px;flex-shrink:0;border-radius:50%;background:rgba(0,0,0,0.3)";const r=i.getContext("2d");r.scale(n,n);const s=14,o=14,a=12,c=t.position.x-t.target.x,l=t.position.z-t.target.z,h=t.position.y-t.target.y,d=Math.sqrt(c*c+l*l),u=Math.sqrt(c*c+h*h+l*l),p=u>.001?Math.max(0,h/u):0;let f=0,g=0;d>.001&&(f=c/d,g=l/d);const m=1-.6*p,y=s+f*a*.7*m,b=o+g*a*.7*m;r.strokeStyle="rgba(255,255,255,0.12)",r.lineWidth=1,r.beginPath(),r.arc(s,o,a,0,2*Math.PI),r.stroke(),r.strokeStyle="rgba(255,255,255,0.06)",r.beginPath(),r.moveTo(s,2),r.lineTo(s,26),r.moveTo(2,o),r.lineTo(26,o),r.stroke(),r.fillStyle="rgba(255,255,255,0.25)",r.beginPath(),r.arc(s,o,1.5,0,2*Math.PI),r.fill(),r.strokeStyle=`rgba(74,158,255,${.2+.2*p})`,r.lineWidth=1,r.beginPath(),r.moveTo(y,b),r.lineTo(s,o),r.stroke();const v=.6+.4*p;r.fillStyle=`rgba(74,158,255,${v})`,r.beginPath(),r.arc(y,b,3,0,2*Math.PI),r.fill();const _=Math.atan2(g,f),x=Math.PI/8;return r.fillStyle="rgba(74,158,255,0.08)",r.beginPath(),r.moveTo(y,b),r.arc(y,b,.6*a,_+Math.PI-x,_+Math.PI+x),r.closePath(),r.fill(),i},u=()=>{const t=e.getCameraWorldState();if(!t)return-1;const n=.01;for(let e=1;e<=9;e++){const i=c.getSlot(e);if(i&&(Math.abs(t.position.x-i.position.x)<n&&Math.abs(t.position.y-i.position.y)<n&&Math.abs(t.position.z-i.position.z)<n&&Math.abs(t.target.x-i.target.x)<n&&Math.abs(t.target.y-i.target.y)<n&&Math.abs(t.target.z-i.target.z)<n))return e}return-1};let p,f,g=-1;const m=()=>{a.innerHTML="";let t=!1;const i=u(),r=Array.from({length:9},(t,e)=>e+1);for(const s of r){const r=c.getSlot(s),o=!!r,u=s===i;if(n&&!o)continue;t=t||o;const p=document.createElement("div"),f=u?"rgba(74,158,255,0.1)":"transparent";if(p.style.cssText=`display:flex;align-items:center;gap:6px;padding:${n?"6px 8px":"3px 4px"};border-radius:6px;transition:background 0.15s;background:${f}${u?";box-shadow:inset 0 0 0 1px rgba(74,158,255,0.25)":""}`,p.dataset.active=u?"1":"",p.addEventListener("mouseenter",()=>{p.style.background=p.dataset.active?"rgba(74,158,255,0.15)":"rgba(255,255,255,0.06)",!n&&o&&e.highlightBookmarkMarker(s)}),p.addEventListener("mouseleave",()=>{const t=p.dataset.active;p.style.background=t?"rgba(74,158,255,0.1)":"transparent",n||e.clearBookmarkMarkerHighlight()}),n){if(o&&r){const t=d(r);t.style.pointerEvents="none",p.appendChild(t)}const t=document.createElement("span");t.textContent=r?.name||"noname",t.style.cssText=`flex:1;color:${r?.name?"rgba(255,255,255,0.8)":"rgba(255,255,255,0.35)"};font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;pointer-events:none;${r?.name?"":"font-style:italic"}`,p.appendChild(t),p.style.cursor="pointer",p.addEventListener("click",()=>{e.animateToSlot(s)})}else{const t=document.createElement("div");t.textContent="⠿";const n=o,i=o?"color:rgba(255,255,255,0.3)":"color:rgba(255,255,255,0.12)";if(t.style.cssText=`width:16px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;user-select:none;${i}${n?";cursor:grab":""}`,n&&(t.dataset.dragHandle="1",t.addEventListener("mouseenter",()=>{t.style.color="rgba(255,255,255,0.6)"}),t.addEventListener("mouseleave",()=>{t.style.color="rgba(255,255,255,0.3)"})),p.appendChild(t),o&&r){const t=d(r);t.style.pointerEvents="none",p.appendChild(t)}o&&(p.style.cursor="pointer",p.addEventListener("click",t=>{const n=t.target.tagName;"INPUT"!==n&&"BUTTON"!==n&&e.animateToSlot(s)}));const a=document.createElement("input");a.type="text",a.value=r?.name||"",a.placeholder=o?"noname":"Empty",a.style.cssText=`width:80px;font-size:12px;color:${o?"rgba(255,255,255,0.7)":"rgba(255,255,255,0.3)"};background:transparent;border:none;border-bottom:1px solid rgba(255,255,255,0.1);outline:none;padding:2px 0;min-width:0`,a.addEventListener("focus",()=>{a.style.borderBottomColor="rgba(74,158,255,0.5)",a.style.color="rgba(255,255,255,0.9)"}),a.addEventListener("blur",()=>{a.style.borderBottomColor="rgba(255,255,255,0.1)",a.style.color=o?"rgba(255,255,255,0.7)":"rgba(255,255,255,0.3)",o&&(c.renameSlot(s,a.value.trim()),l())}),a.addEventListener("keydown",t=>{t.stopPropagation(),t.isComposing||"Enter"!==t.key||a.blur()}),p.appendChild(a);const u=document.createElement("div");if(u.style.cssText="display:flex;gap:2px;flex-shrink:0",o){const t=document.createElement("button");t.textContent="📌",t.title="Overwrite with current view",t.style.cssText=h+";color:#ffaa44",t.addEventListener("mouseenter",()=>{t.style.background="rgba(255,170,68,0.15)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",()=>{e.saveCameraToSlot(s),m()}),u.appendChild(t);const n=document.createElement("button");n.textContent="🗑",n.title="Delete this slot",n.style.cssText=h+";color:#ff6b6b",n.addEventListener("mouseenter",()=>{n.style.background="rgba(255,107,107,0.15)"}),n.addEventListener("mouseleave",()=>{n.style.background="transparent"}),n.addEventListener("click",()=>{c.clearSlot(s),l(),m()}),u.appendChild(n);const i=document.createElement("button");i.textContent="⋮",i.title="Playlist settings",i.style.cssText=h+";color:rgba(255,255,255,0.35);font-size:14px",i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{i.style.background="transparent"}),u.appendChild(i)}else{const t=document.createElement("button");t.textContent="📌",t.title="Save current view here",t.style.cssText=h+";color:#4ade80",t.addEventListener("mouseenter",()=>{t.style.background="rgba(74,222,128,0.15)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",()=>{e.saveCameraToSlot(s),m()}),u.appendChild(t)}p.appendChild(u)}const y=document.createElement("div");if(y.dataset.slotIndex=String(s),y.dataset.filled=o?"1":"",y.appendChild(p),!n&&o){const t=p.querySelector("[data-drag-handle]");t&&t.addEventListener("pointerdown",e=>{e.preventDefault(),e.stopPropagation(),y.style.opacity="0.3",y.style.pointerEvents="none",y.style.outline="1px dashed rgba(74,158,255,0.4)",y.style.borderRadius="4px",t.style.cursor="grabbing";const n=document.createElement("div");n.style.cssText="height:2px;background:#4a9eff;border-radius:1px;margin:1px 0",t.setPointerCapture(e.pointerId);const i=t=>{const e=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&n.parentNode.removeChild(n);let i=null;for(const n of e){if(n===y)continue;const e=n.getBoundingClientRect();if(t.clientY<e.top+e.height/2){i=n;break}}if(i)a.insertBefore(n,i);else{const t=e[e.length-1];t&&t.after(n)}},r=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",i),t.removeEventListener("pointerup",r),y.style.cssText="",t.style.cursor="grab";const s=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&(a.insertBefore(y,n),n.parentNode.removeChild(n));const o=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]')).map(t=>parseInt(t.dataset.slotIndex)).map(t=>{const e=c.getSlot(t);return e?{...e,name:e.name}:void 0}),h=s.map(t=>parseInt(t.dataset.slotIndex)).sort((t,e)=>t-e);o.forEach((t,e)=>{const n=h[e];t?c.saveSlot(n,t):c.clearSlot(n)}),l(),m()};t.addEventListener("pointermove",i),t.addEventListener("pointerup",r)})}if(!n&&o&&r){const t=document.createElement("div");t.dataset.slotDetail="1";const e=g===s;t.style.cssText=`display:${e?"block":"none"};margin:2px 0 4px 26px;padding:6px 8px;background:rgba(255,255,255,0.03);border-radius:4px;border:1px solid rgba(255,255,255,0.06)`;const n="width:50px;font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none;text-align:right",i="font-size:10px;color:rgba(255,255,255,0.45);white-space:nowrap",o="display:flex;align-items:center;gap:6px;margin-bottom:4px",c=document.createElement("div");c.style.cssText=o;const h=document.createElement("span");h.textContent="Hold",h.style.cssText=i+";width:55px";const d=document.createElement("input");d.type="number",d.min="0",d.step="500",d.value=String(r.holdDuration??2e3),d.style.cssText=n;const u=document.createElement("span");u.textContent="ms",u.style.cssText=i,d.addEventListener("change",()=>{const t=parseInt(d.value);r.holdDuration=isNaN(t)?void 0:Math.max(0,t),l()}),d.addEventListener("keydown",t=>t.stopPropagation()),c.appendChild(h),c.appendChild(d),c.appendChild(u),t.appendChild(c);const f=document.createElement("div");f.style.cssText=o;const m=document.createElement("span");m.textContent="Transition",m.style.cssText=i+";width:55px";const b=document.createElement("input");b.type="number",b.min="0",b.step="200",b.value=String(r.transitionDuration??1200),b.style.cssText=n;const v=document.createElement("span");v.textContent="ms",v.style.cssText=i,b.addEventListener("change",()=>{const t=parseInt(b.value);r.transitionDuration=isNaN(t)?void 0:Math.max(0,t),l()}),b.addEventListener("keydown",t=>t.stopPropagation()),f.appendChild(m),f.appendChild(b),f.appendChild(v),t.appendChild(f);const _=document.createElement("div");_.style.cssText=o;const x=document.createElement("span");x.textContent="Easing",x.style.cssText=i+";width:55px";const w=document.createElement("select");w.style.cssText="font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none";for(const t of["ease-in-out","ease-in","ease-out","linear"]){const e=document.createElement("option");e.value=t,e.textContent=t,e.style.cssText="background:#2a2a2a;color:#ccc",(r.easing??"ease-in-out")===t&&(e.selected=!0),w.appendChild(e)}w.addEventListener("change",()=>{r.easing="ease-in-out"===w.value?void 0:w.value,l()}),_.appendChild(x),_.appendChild(w),t.appendChild(_);const M=document.createElement("div");M.style.cssText=o+";margin-bottom:0";const S=document.createElement("span");S.textContent="Skip in play",S.style.cssText=i+";width:55px";const k=document.createElement("input");k.type="checkbox",k.checked=!!r.excludeFromPlay,k.style.cssText="accent-color:#4a9eff;cursor:pointer",k.addEventListener("change",()=>{r.excludeFromPlay=k.checked||void 0,l()}),M.appendChild(S),M.appendChild(k),t.appendChild(M),y.appendChild(t);const A=p.querySelector("button:last-child");A&&(e&&(A.style.color="#4a9eff"),A.addEventListener("click",()=>{const e="none"!==t.style.display;a.querySelectorAll("[data-slot-detail]").forEach(e=>{if(e!==t&&"none"!==e.style.display){e.style.display="none";const t=e.parentElement?.firstElementChild?.querySelector("button:last-child");t&&(t.style.color="rgba(255,255,255,0.35)")}}),t.style.display=e?"none":"block",A.style.color=e?"rgba(255,255,255,0.35)":"#4a9eff",g=e?-1:s}))}a.appendChild(y)}if(!t){const t=document.createElement("div");if(t.textContent=n?"No bookmarks defined":"No bookmarks saved",t.style.cssText="color:rgba(255,255,255,0.3);font-size:12px;text-align:center;padding:12px 0",a.appendChild(t),!n){const t=document.createElement("div");t.textContent="Use 📌 to save camera positions",t.style.cssText="color:rgba(255,255,255,0.2);font-size:11px;text-align:center;padding:0 0 4px",a.appendChild(t)}}p&&(p.style.display=c.getPlayableSlots().length>=2?"block":"none")};if(m(),!n){p=document.createElement("div"),p.style.cssText="display:none;margin-top:6px;padding:4px 8px;border-top:1px solid rgba(255,255,255,0.06)";const t=document.createElement("div");t.style.cssText="display:flex;align-items:center;gap:6px";const n=document.createElement("input");n.type="range",n.min="0",n.max="1000",n.value="0",n.tabIndex=-1,n.style.cssText="flex:1;min-width:0;margin:0;height:14px;cursor:grab;accent-color:#4a9eff;outline:none";const i=document.createElement("button");i.textContent="▶",i.title="Play / Stop",i.style.cssText="border:none;background:rgba(255,255,255,0.06);color:rgba(255,255,255,0.5);cursor:pointer;font-size:12px;padding:3px 6px;border-radius:4px;line-height:1;flex-shrink:0",i.addEventListener("mouseenter",()=>{i.style.background="rgba(74,158,255,0.15)",i.style.color="#4a9eff"}),i.addEventListener("mouseleave",()=>{i.style.background="rgba(255,255,255,0.06)",i.style.color=c.isPlaying?"#4a9eff":"rgba(255,255,255,0.5)"}),i.addEventListener("click",()=>{const t=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(t),a()}),n.addEventListener("focus",()=>n.blur());let s=!1;n.addEventListener("mousedown",()=>{s=!0,n.style.cursor="grabbing",c.isPlaying&&(e.togglePlay(),a())}),n.addEventListener("input",()=>{const t=parseInt(n.value)/1e3;e.scrubPath(t)});const o=()=>{s&&(s=!1,n.style.cursor="grab")};n.addEventListener("mouseup",o),n.addEventListener("mouseleave",o),r.addEventListener("keydown",t=>{if("Space"===t.code&&"none"!==p.style.display){t.preventDefault(),t.stopPropagation();const i=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(i),a()}}),t.appendChild(n),t.appendChild(i),p.appendChild(t),r.appendChild(p);const a=()=>{const t=c.isPlaying;i.textContent=t?"⏹":"▶",i.style.color=t?"#4a9eff":"rgba(255,255,255,0.5)"};let l=-1;const h=()=>{if(this._floatingPopup===r){if(c.isPlaying){const t=c.playProgress;n.value=String(Math.round(1e3*t)),l=-1}else{"⏹"===i.textContent&&a();const t=c.lastPlayProgress;t>=0&&t!==l&&(n.value=String(Math.round(1e3*t)),l=t)}f=requestAnimationFrame(h)}};f=requestAnimationFrame(h);(()=>{const t=c.getPlayableSlots().length;p.style.display=t>=2?"block":"none"})()}if(!n){const t=document.createElement("button"),e="display:block;width:100%;margin-top:8px;padding:5px 0;border:1px solid rgba(255,255,255,0.12);border-radius:6px;background:transparent;color:rgba(255,255,255,0.45);font-size:11px;cursor:pointer;transition:all 0.15s";i&&(t.textContent="Clear All",t.style.cssText=e,t.addEventListener("mouseenter",()=>{t.style.borderColor="rgba(255,107,107,0.4)",t.style.color="#ff6b6b"}),t.addEventListener("mouseleave",()=>{t.style.borderColor="rgba(255,255,255,0.12)",t.style.color="rgba(255,255,255,0.45)"}),t.addEventListener("click",()=>{c.resetAll(),l(),m()})),r.appendChild(t)}const y=e.onBookmarkChanged;e.onBookmarkChanged=()=>{y?.(),this._floatingPopup===r&&(m(),v=-2,n||e.showBookmarkPath())},this._showFloatingPopup(r,!0),n||e.showBookmarkPath();let b,v=u();const _=()=>{if(this._floatingPopup!==r)return;const t=u();if(t!==v){v=t;a.querySelectorAll("[data-slot-index]").forEach(e=>{const n=parseInt(e.dataset.slotIndex||"-1"),i=e.firstElementChild;if(!i)return;const r=n===t,s=r?"rgba(74,158,255,0.1)":"transparent";i.style.background=s,i.style.boxShadow=r?"inset 0 0 0 1px rgba(74,158,255,0.25)":"none",i.dataset.active=r?"1":""})}b=requestAnimationFrame(_)};b=requestAnimationFrame(_);const x=this._closeFloatingPopup.bind(this);this._closeFloatingPopup=()=>{void 0!==b&&cancelAnimationFrame(b),void 0!==f&&cancelAnimationFrame(f),c.isPlaying&&e.togglePlay(),e.clearBookmarkMarkerHighlight(),e.hideBookmarkPath(!0),this._closeFloatingPopup=x,x()}}_removeToolbar(){this._closeFloatingPopup(),this._threeCapability&&(this._threeCapability.onGizmoModeChanged=void 0,this._threeCapability.onGizmoAttachChanged=void 0,this._threeCapability.onCameraViewChanged=void 0,this._threeCapability.onBookmarkChanged=void 0,this._threeCapability.onHelpToggle=void 0,this._threeCapability.onSearchToggle=void 0,this._threeCapability.onDataBindingToggle=void 0,this._threeCapability.onMonitorToggle=void 0,this._threeCapability.onBookmarkNavToggle=void 0,this._threeCapability.onBookmarkEditToggle=void 0),this._toolbar?.parentNode&&this._toolbar.parentNode.removeChild(this._toolbar),this._toolbar=void 0,this._cameraButtons=void 0}_resizeThreeD(t=!1){if(!this._threeCapability||!this.element)return;const e=this.canvas?.clientWidth??0,n=this.canvas?.clientHeight??0,i=e>0?e:this.element.clientWidth,r=n>0?n:this.element.clientHeight;i>0&&r>0&&this._threeCapability.resize(i,r,t)}detachThreeCapability(){const t=this._threeCapability;if(t)return t.forceCleanupDragState(),t.clearAllObjects(),this._threeCapability=void 0,t}adoptThreeCapability(t){this._threeCapability=t,this._hide2DLayers();const e=t.domElement;if(e&&this.element){e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.pointerEvents="none",e.setAttribute("scene","model-layer-webgl");const t=this._decoratorOverlay||this.element.firstChild;this.element.insertBefore(e,t)}t.buildOverlays(),t.rebuildForHost(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),this.app?.isEditMode&&this._createToolbar(),this._registerPopupCallbacks(),this._resizeThreeD(!0)}_deactivateThreeD(){if(!this._threeCapability)return;this._removeToolbar(),this._lastCameraState=this._threeCapability.captureSessionState();const{target:t,visibleWidth:e,visibleHeight:n}=this._threeCapability.captureViewportInfo();this._threeCapability.forceCleanupDragState();const i=this._threeCapability.domElement,r=this._threeCapability.css3DRenderer?.domElement,s=[...this._threeCapability.decoratorOutlines];this._threeCapability.dispose(),this._threeCapability=void 0,r?.parentNode&&r.parentNode.removeChild(r);for(const t of this.components)if(t.isHTMLElement()&&t.element){const e=t.element,n=this.getOverlay(t);n?.appendChild(e)}i?.parentNode&&i.parentNode.removeChild(i),this.canvas&&(this.canvas.style.display=""),this._overlay&&(this._overlay.style.display=""),this._auxCanvas&&(this._auxCanvas.style.display=""),this._decoratorOverlay&&(this._decoratorOverlay.style.display=""),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="");for(const t of this.components)t.isHTMLElement()&&t.element&&t.reposition();this.app?.isEditMode&&this._createToolbar();for(const t of s)t.disposed||this.applyDecorator(t,"border-highlighting",{distance:8,lineWidth:4,color:"#f007"});this._saved2DViewport?(this.set({scale:this._saved2DViewport.scale,translate:this._saved2DViewport.translate}),this._saved2DViewport=void 0):this._needsViewportSync&&this._init2DViewportFrom3DCamera(t,e,n),this.root.target_element?.focus()}_getViewportSize(){const t=this.target;return{w:t?.clientWidth||this.canvas?.clientWidth||this.state.width||800,h:t?.clientHeight||this.canvas?.clientHeight||this.state.height||600}}_initCameraFrom2DViewport(){if(!this._threeCapability)return;const{w:t,h:e}=this._getViewportSize(),n=this.get("translate")||{x:0,y:0},i=this.get("scale")||{x:1,y:1},r=i.x||1,s=i.y||1,{width:o=800,height:a=600}=this.state,c=(t/2-n.x)/r-o/2,l=(e/2-n.y)/s-a/2,h=t/r,d=e/s;this._threeCapability.positionCameraForViewport(c,l,h,d,this._lastCameraState)}_init2DViewportFrom3DCamera(t,e,n){const{w:i,h:r}=this._getViewportSize(),{width:s=800,height:o=600}=this.state,a=t.x+s/2,c=t.z+o/2;let l;if(this._2dScaleBeforeThreeD&&this._initialVisibleHeight&&n>0){const t=this._initialVisibleHeight/n;l=this._2dScaleBeforeThreeD*t}else if(e>0||n>0){const t=e>0?i/e:1,s=n>0?r/n:1;l=Math.max(t,s)}else l=1;l=Math.max(.1,Math.min(l,10));const h=i/2-a*l,d=r/2-c*l;this.set({translate:{x:h,y:d},scale:{x:l,y:l}}),this._2dScaleBeforeThreeD=void 0,this._initialVisibleHeight=void 0}centerTo(t,e){this.is3dMode&&this._threeCapability?this._threeCapability.centerToComponent(t,e):super.centerTo(t,e)}async ready(){await super.ready(),this.model.threed?this._threeCapability||(await new Promise(t=>setTimeout(t,0)),this._activateThreeD()):this.app?.isEditMode&&this._createToolbar(),this.root?.trigger("dimension",this.model.threed?"3d":"2d")}toggleThreeD(t){const e=t??!this.is3dMode;e?(this._threeDUserDeactivated=!1,this._activateThreeD(!0)):(this._threeDUserDeactivated=!0,this._deactivateThreeD(),this.resize(),this.invalidate()),this.root?.trigger("dimension",e?"3d":"2d")}dispose(){this._deactivateThreeD(),this._removeToolbar(),super.dispose(),this._overlay=null,this._decoratorOverlay&&(Bs.getInstance().removeOverlay(this._decoratorOverlay),this._decoratorOverlay.parentNode&&this._decoratorOverlay.parentNode.removeChild(this._decoratorOverlay),this._decoratorOverlay=null),this._decoratorAuxOverlay&&(Bs.getInstance().removeOverlay(this._decoratorAuxOverlay),this._decoratorAuxOverlay.parentNode&&this._decoratorAuxOverlay.parentNode.removeChild(this._decoratorAuxOverlay),this._decoratorAuxOverlay=null)}contains(t,e){return!0}isRootModel(){return!0}get stuck(){return!0}get layout(){return this.is3dMode?yc.get("three"):bc}get overlay(){if(!this._overlay){const t=document.createElement("div");t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.margin="0",t.style.padding="0",t.style.overflow="initial",t.style["user-select"]="none",t.style["transform-origin"]="top left",t.setAttribute("scene","model-layer-overlay"),this.element.insertBefore(t,this.auxCanvas),this._overlay=t,this._repositionOverlay()}return this._overlay}get auxOverlay(){return this.element??void 0}get decoratorOverlay(){if(!this._decoratorOverlay){const t=document.createElement("div");t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.margin="0",t.style.padding="0",t.style.overflow="initial",t.style["user-select"]="none",t.style["transform-origin"]="top left",t.setAttribute("scene","decorator-overlay"),t.id=`decorator-overlay-${Date.now()}`,this.element.insertBefore(t,this.overlay),this._decoratorOverlay=t,Bs.getInstance().addOverlay(t)}return this._decoratorOverlay}get decoratorAuxOverlay(){if(!this._decoratorAuxOverlay){const t=document.createElement("div");t.style.position="absolute",t.style.width="0",t.style.height="0",t.style.margin="0",t.style.padding="0",t.style.overflow="initial",t.style.zIndex="100",t.style["user-select"]="none",t.style["transform-origin"]="top left",t.setAttribute("scene","decorator-aux-overlay"),t.id=`decorator-overlay-${Date.now()}`,this.element.appendChild(t),this._decoratorAuxOverlay=t,Bs.getInstance().addOverlay(t)}return this._decoratorAuxOverlay}createElement(){const t=super.createElement();return this._overlay&&t.appendChild(this._overlay),t}resize(){if(!this.target||!this.element)return;let{width:t,height:e,fitMode:n}=this.model;this.root.fitMode?n=this.root.fitMode:n||(n="ratio");let i=null;try{i=getComputedStyle(this.target)}catch(t){return void Ki(t,this.target)}let r=i?parseFloat(i.getPropertyValue("width")):this.target.clientWidth,s=i?parseFloat(i.getPropertyValue("height")):this.target.clientHeight;switch(n){case"both":case"ratio":break;case"width":s=e*r/t,this.element.style.overflowX="hidden",this.element.style.overflowY="auto";break;case"height":r=t*s/e,this.element.style.overflowX="auto",this.element.style.overflowY="hidden";break;default:r=Math.max(t,r),s=Math.max(e,s),this.element.style.overflowX=r>t?"hidden":"auto",this.element.style.overflowY=s>e?"hidden":"auto"}this.fitSize(this.element,!0),this.fitSize(this.canvas,!0,r,s),this.fitSize(this.auxCanvas,!0,r,s),this.root?.transitionEffect?.resize(),this.is3dMode&&this._threeCapability.resize(r,s)}draw(t){if(this.is3dMode){if(!this.element)return;return void this._threeCapability.renderCSS3D()}if(this.model.threed&&!this._threeCapability&&!this._threeDUserDeactivated)return;const e=this.root?.transitionEffect;e?.beginDraw(),super.draw(t),e?.endDraw()}get MPP(){const{scale:t={x:1,y:1},unit:e}=this.model;switch(e){case"mm":case"cm":return 1/this.app.PPM/t.x;case"in":return 1/this.app.PPI/t.x;default:return 1/t.x}}capturePath(t,e){const n=this.layout.capturables(this);for(let i=n.length-1;i>=0;i--){const r=n[i];if(!r.isContainer())continue;const s=r.capturePath(t,e);if(s)return s}return!1}getOverlay(t){return t&&!t.scalable?this.auxOverlay:this.overlay}getDecoratorOverlay(t){return t&&!t.scalable?this.decoratorAuxOverlay:this.decoratorOverlay}_onkeydown_root(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;const e=this.rootModel;if(!e)return;if("KeyF"===t.code)return this.onSearchToggle?.(),void t.preventDefault();if("KeyH"===t.code)return this._toggleHelpPanel(),void t.preventDefault();if("KeyD"===t.code)return this.onDataBindingToggle?.(),void t.preventDefault();if("KeyM"===t.code)return this.onMonitorToggle?.(),void t.preventDefault();if("KeyQ"===t.code)return this.toggleThreeD(),void t.preventDefault();if(e.is3dMode)return;const n={Digit1:"perspective",Digit2:"top",Digit3:"front",Digit4:"back",Digit5:"right",Digit6:"left"}[t.code];n&&(e._pendingCameraView=n,this.toggleThreeD(!0),t.preventDefault())}get eventMap(){return{"(self)":{"(all)":{change:this._onchanged_all,mouseenter:this._onmouseenter_all,mouseleave:this._onmouseleave_all,click:this._onclick,mousedown:this._onmousedownup,mouseup:this._onmousedownup,touchstart:this._onmousedownup,touchend:this._onmousedownup,"deco-reset":t=>this.resetDecorator(void 0,t.origin)},"(descendant)":{"deco-anchors":(t,e)=>this.applyDecorator(e.origin,"anchors",t),"deco-anchors-off":t=>this.offdecorator(t.origin,"anchors"),"deco-anchors-reset":t=>this.resetDecorator("anchors"),"deco-dataspread":(t,e)=>this.applyDecorator(e.origin,"data-spread",t),"deco-dataspread-off":t=>this.offdecorator(t.origin,"data-spread"),"deco-dataspread-reset":t=>this.resetDecorator("data-spread"),"deco-link":(t,e)=>this.applyDecorator(e.origin,"link",t),"deco-link-off":t=>this.offdecorator(t.origin,"link"),"deco-link-reset":t=>this.resetDecorator("link"),"deco-arrow":(t,e)=>this.applyDecorator(e.origin,"bouncing-arrow",t),"deco-arrow-off":t=>this.offdecorator(t.origin,"bouncing-arrow"),"deco-arrow-reset":t=>this.resetDecorator("bouncing-arrow"),"deco-icon":(t,e)=>this.applyDecorator(e.origin,"animated-icon",t),"deco-icon-off":t=>this.offdecorator(t.origin,"animated-icon"),"deco-icon-reset":t=>this.resetDecorator("animated-icon"),"deco-border":(t,e)=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.addOutline(e.origin):this.applyDecorator(e.origin,"border-highlighting",t))},"deco-border-off":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.removeOutline(t.origin):this.offdecorator(t.origin,"border-highlighting"))},"deco-border-reset":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.clearOutlines():this.resetDecorator("border-highlighting"))},"deco-tag":(t,e)=>this.applyDecorator(e.origin,"decotag",t),"deco-tag-off":t=>this.offdecorator(t.origin,"decotag"),"deco-tag-reset":t=>this.resetDecorator("decotag",t.origin),"deco-off":t=>{this.offdecorator(t.origin),this._threeCapability?.removeOutline(t.origin)},mouseenter:this.onmouseenterForDecorator,mouseleave:this.onmouseleaveForDecorator},"(self)":{change:this.onChangeForDecorator,redraw:this.onRedrawForDecorator}},"(root)":{"(self)":{selected:this._onRootSelected,keydown:this._onkeydown_root}}}}onRedrawForDecorator(){this.is3dMode||(Bs.getInstance().invalidateOverlay(this.decoratorOverlay),Bs.getInstance().invalidateOverlay(this.decoratorAuxOverlay))}closeScene(t){requestAnimationFrame(()=>this.overlay.dispatchEvent(new CustomEvent("close-scene",{bubbles:!0,composed:!0,detail:t})))}_repositionOverlay(){const t=this._overlay;if(!t)return;const{translate:e=Ad,scale:n=kd,rotation:i=0}=this.model,{left:r,top:s}=this.bounds;t.style.left=r+"px",t.style.top=s+"px",t.style.transform=`rotate(${i}rad) scale(${n.x}, ${n.y}) perspective(1px)`,t.style.marginLeft=`${e.x}px`,t.style.marginTop=`${e.y}px`}onchange(t){const e=this._model;delete e.id,delete e.text,delete e.class,this._repositionOverlay(),t.hasOwnProperty("threed")&&(t.threed?this._activateThreeD(!0):this._deactivateThreeD(),this.root?.trigger("dimension",t.threed?"3d":"2d")),this.is3dMode&&((t.hasOwnProperty("width")||t.hasOwnProperty("height"))&&this._resizeThreeD(),this._threeCapability.onchange(t))}_onRootSelected(t){const e=1===t?.length?t[0]:t&&0!==t.length?null:this;e&&globalThis.dispatchEvent?.(new CustomEvent("clickComponent",{detail:e}))}_onchanged_all(t,e,n){this.invalidate()}_onmouseenter_all(t,e){if(t.stopPropagation(),!this.app||this.app.isEditMode)return;if(!e)return;const n=e.origin;if(n instanceof Id||!n.model.event||!n.model.event.hover)return;if(n.hidden)return;const i=n.model.event.hover;i&&this._doEventAction(i,n,!0,t)}_onmouseleave_all(t,e){if(t.stopPropagation(),!e)return;const n=e.origin;if(!this.app||this.app.isEditMode)return;const i=n.model.event&&n.model.event.hover;i&&this._doEventAction(i,n,!1,t)}_onclick(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,i=n.model.event?.tap;i&&this._doEventAction(i,n,!0,t)}_onmousedownup(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,i=n.model.event?.tap;i&&i.pressed&&this._doMouseDownUpEventAction(i,n,"mousedown"==t.type||"touchstart"==t.type,t)}_doMouseDownUpEventAction(t,e,n,i){const{pressed:r=!1}=t;r&&(n?function(t){if(t.hasOwnProperty("_backupShadow"))return;const e=t.get("shadow");t._backupShadow=e;const{left:n=0,top:i=0}=e||{};t.delta("tx",n),t.delta("ty",i),t.set("shadow",{})}(e):function(t){t.hasOwnProperty("_backupShadow")&&(t.delta("tx",0),t.delta("ty",0),t.set("shadow",t._backupShadow),delete t._backupShadow)}(e))}_doEventAction(t,e,n,i){let{action:r,target:s,value:o,emphasize:a=!1,restore:c=!1,options:l}=t;if(s&&(s=e.access(s)),o&&(o=e.access(o)),a&&(n?function(t){const{hover:e}=t.state.event||{},{emphasize:n}=e||{};if(t.hasOwnProperty("_backupStrokeStyle"))return;if("__backup_emphasize"in t)return;const{strokeStyle:i,lineWidth:r,fillStyle:s}=t.state;t.__backup_emphasize={strokeStyle:i,lineWidth:r,fillStyle:s},t.setState(n)}(e):c&&function(t){"__backup_emphasize"in t&&(t.setState(t.__backup_emphasize),delete t.__backup_emphasize)}(e)),r)switch(r){case"data-toggle":if(!s)return;(n||c)&&this.root.findAll(s,e)?.forEach(t=>{t.data=!t.data});break;case"data-tristate":if(!s)return;(n||c)&&this.root.findAll(s,e)?.forEach(t=>{const e=Math.round(Math.max(Number(t.data)||0,0));t.data=(e+(n?1:2))%3});break;case"data-spreading":if(!s)return;n&&(e.access(o),this.root.findAll(s,e)?.forEach(t=>{t.executeMappings(!0)}));break;case"data-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.data=t})}break;case"partial-data-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.data={...e.data,...t}})}break;case"value-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.value=t})}break;case"partial-value-set":if(!s)return;if(n){const t=e.access(o);this.root.findAll(s,e)?.forEach(e=>{e.value={...e.value,...t}})}break;case"infoWindow":case"info-window":if(!s)return;"click"==i.type||n?gc.show(e,s,c,{x:i.offsetX,y:i.offsetY}):c&&gc.hide(e,s);break;case"toggle-info-window":if(!s)return;gc.toggle(e,s,!1,{x:i.offsetX,y:i.offsetY});break;case"popup":case"modal-popup":if(!s)return;const t=l&&"input"in l?l.input:"(self)",a=!l||(!("output"in l)||l.output);Ic.show(e,s,{data:t&&this.root.findFirst(t,e)?.data,output:a,modal:"modal-popup"===r,closable:!0,draggable:!0,origin:"auto"});break;case"close-scene":this.closeScene(e.data);break;case"goto":case"goto-playlist":this.trigger(r,s,l,e);break;case"mouse-cursor":n?this.target.style.cursor=s||"auto":c&&(this.target.style.cursor="auto");break;default:this.trigger(r,s,o,e)}}applyDecorator(t,e,n={}){const i=this.getDecoratorOverlay(t);if(i){Bs.getInstance().addToOverlay(i,t,e,n)}}offdecorator(t,e){const n=this.getDecoratorOverlay(t);if(n){Bs.getInstance().removeFromOverlay(n,t,e)}}resetDecorator(t,e){const n=this.getDecoratorOverlay(e);n&&Bs.getInstance().removeAllFromOverlay(n,t)}onChangeForDecorator(t,e,n){const{origin:i}=n,r=this.getDecoratorOverlay(i);Bs.getInstance().invalidateOverlay(r)}onmouseenterForDecorator(t,e){const{origin:n}=e;n.decorators&&n.decorators.forEach(t=>{this.applyDecorator(n,t)})}onmouseleaveForDecorator(t,e){const{origin:n}=e;n.decorators&&n.decorators.forEach(t=>{this.offdecorator(n,t)})}}function Ld(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.from?.component===n&&(!e||t.from.anchor===e))}function jd(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.to?.component===n&&(!e||t.to.anchor===e))}function Rd(t){return class extends t{isConnectable(){return!0}postrender(t){super.postrender(t),this._draw_anchors(t)}_draw_anchors(t){const e=this.anchors||[];t.save(),e.forEach(e=>{const{draw:n}=e;if(n){t.beginPath();try{n.call(e,t,this)}catch(t){Ki(t)}t.closePath()}}),t.restore()}contains(t,e){let n=super.contains(t,e);if(n)return n;const i=this.anchors||[];for(const r of i){const i=r.bounds;if(!i)continue;const{left:s,top:o,width:a,height:c}=i;if(n=t<Math.max(s+a,s)&&t>Math.min(s+a,s)&&e<Math.max(o+c,o)&&e>Math.min(o+c,o),n)return n}return!1}findInOutLines(t){return function(t,e){const n=t.state.refid;return t.root.findAll(t=>!(!t.isLine()||(t.from?.component!==n||e&&t.from.anchor!==e)&&(t.to?.component!==n||e&&t.to.anchor!==e)))}(this,t)}findOutletLines(t){return Ld(this,t)}findOutletEnds(t){return function(t,e){return Ld(t,e).map(t=>t.toEnd?.component).filter(Boolean)}(this,t)}findInletLines(t){return jd(this,t)}findInletEnds(t){return function(t,e){return jd(t,e).map(t=>t.fromEnd?.component).filter(Boolean)}(this,t)}}}Id.Popup=Ic,cc.register("model-layer",Id);const Fd={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0}}],help:"scene/component/rect"},Bd={ondragmove:function(t,e,n){const{left:i,width:r,height:s}=n.model;let o=(n.fromParent(t.x,t.y).x-i)/(r/2)*100;o=hc(o,r,s),n.set({round:o})}};class Nd extends(Rd(dc(lc))){is3dish(){return!0}get controls(){let{left:t,top:e,width:n,round:i,height:r}=this.state;return i=null==i?0:hc(i,n,r),[{x:t+n/2*(i/100),y:e,handler:Bd}]}get nature(){return Fd}}cc.register("rect",Nd);const Hd=[1,2,10,20,50,50,50,50,50,50];class Yd extends(dc(lc)){render(t){const{lineWidth:e=1,fillStyle:n="lightgray",font:i="15px Arial",left:r,top:s,origin:o,width:a,height:c,side:l="bottom",strokeStyle:h="#000000",scale:d=1}=this.state;t.translate(r,s),t.beginPath();const u=Math.round(e/2);t.rect(-u,-u,a+2*u,c+2*u),t.clip(),t.beginPath(),t.rect(0,0,a,c),n&&(t.fillStyle=n,t.fill()),t.lineWidth=e,t.strokeStyle=h,t.stroke(),t.beginPath(),t.font=i;const p="bottom"!==l,f=p?0:c;let g=4*c/5,m=2*c/3,y=1*c/2,b=3*c/5;p&&(g=c-g,m=c-m,y=c-y,b=c-1.5*c/5);const v=d*this.app.PPM/this.root.unitScale;let _=Math.ceil(o/v);const x=this.app.PPM/v,w=x<=1.1?1:Hd[Math.round(x)]||100;1!=w&&(_+=(w-_%w)%w);let M=Math.ceil(_*v);const S=o+a;for(t.fillStyle=h;M<S;){if(_%10==0){t.moveTo(M-o,y),t.lineTo(M-o,f);const e=(_/10).toString(),n=t.measureText(e);t.fillText(e,M-o-n.width-6,b)}else _%5==0?(t.moveTo(M-o,m),t.lineTo(M-o,f)):(t.moveTo(M-o,g),t.lineTo(M-o,f));_+=w,M=Math.ceil(_*v)}}}cc.register("ruler",Yd);const Vd=20,Gd=20,Ud=90*Math.PI/180,Wd="9px Verdana",Xd=20,qd="#f4f4f4",Kd="#999";function $d(t,e,n){return{left:-t.x,top:-t.y,width:Vd,height:Xd}}function Qd(t,e,n,i){return{left:Vd-t.x,top:0-t.y,origin:20-t.x,width:e-Vd,height:Xd}}function Zd(t,e,n,i){const r={x:0-t.x+10,y:-t.y+Gd+(n-Gd)/2},s=cc.transcoordRR(0-t.x,-t.y+Gd,r,Ud);return{left:s.x-(n-Gd),top:s.y,origin:20-t.y,width:n-Gd,height:Xd}}function Jd(t){const e=t.get("translate");return{left:-e.x,top:-e.y,width:t.canvas.width/Hr,height:t.canvas.height/Hr}}cc.register("guide-layer",class extends Bc{constructor(t,e){super(t,e),this.appScale={x:1,y:1},"disabled"!==t.ruler&&(this.hruler=new Yd({left:Vd,top:0,origin:20,margin:0,height:Xd,unit:"m",rotation:0,font:Wd,fillStyle:qd,strokeStyle:Kd,capturable:!1}),this.vruler=new Yd({left:0,top:0,origin:20,margin:0,height:Xd,unit:"m",rotation:Ud,font:Wd,side:"top",fillStyle:qd,strokeStyle:Kd,capturable:!1}),this.origin_rect=new Nd({left:-20,top:-20,width:20,height:20,fillStyle:qd,strokeStyle:Kd,lineWidth:1}),this.addComponent(this.hruler),this.addComponent(this.vruler),this.addComponent(this.origin_rect)),this.invalidate()}get capturable(){return!1}async ready(){if(await super.ready(),!this.hruler)return void(this.screen_coord=Jd(this));const t=this.rootModel,e=Object.assign({},t.get("translate"));e.x<Vd&&(e.x+=Vd),e.y<Gd&&(e.y+=Gd);const n=t.get("scale")||{x:1,y:1};this.appScale=n,this.hruler.set("scale",n.x),this.vruler.set("scale",n.y),t.set("translate",e),this.set("translate",e),this.screen_coord=Jd(this);const{width:i,height:r}=this.screen_coord;this.hruler.set(Qd(e,i)),this.vruler.set(Zd(e,0,r)),this.origin_rect.set($d(e))}resize(){super.resize(),this.screen_coord=Jd(this);const{width:t,height:e}=this.screen_coord;this.hruler&&(this.hruler.set(Qd(this.model.translate,t)),this.vruler.set(Zd(this.model.translate,0,e)),this.origin_rect.set($d(this.model.translate)))}render(t){if(this.rootModel?.is3dMode)return;if(!this.guide)return;t.save();const{x:e,y:n}=this.guide,{top:i,left:r,width:s,height:o}=this.screen_coord;t.beginPath(),t.moveTo(e,i),t.lineTo(e,i+o),t.moveTo(r,n),t.lineTo(r+s,n),t.lineWidth=1,t.strokeStyle="tomato",t.setLineDash([2,3]),t.font="10px tahoma",t.fillStyle="#333";const a=this.toGlobal(e,n,this.rootModel);t.textBaseline=a.y>200?"bottom":"top",t.textAlign=a.x>200?"right":"left";const c=a.y>200?-5:5,l=a.x>200?-5:5,h=Math.round(e/this.appScale.x),d=Math.round(n/this.appScale.y);t.fillText(` ${h}, ${d} `,e+l,n+c),t.stroke(),t.restore()}get guide(){return this._guide}set guide(t){this._guide=t,this.invalidate()}contains(t,e){return!0}get eventMap(){return{"(root)":{"(descendant)":{mousemove:this.onmousemove_child,mouseout:this.onmouseout_child,dragmove:this.onmousemove_child},"model-layer":{change:this.onchange_root_model}},"(self)":{"(descendant)":{mousedown:this.onmousedown_origin}}}}onmousedown_origin(t,e){this.rootModel.set("translate",{x:20,y:20})}onchange_root_model(t,e,n){if(t.scale&&(this.appScale=t.scale,this.hruler&&(this.hruler.set("scale",t.scale.x),this.vruler.set("scale",t.scale.y))),t.translate&&this.set({translate:{x:t.translate.x,y:t.translate.y}}),t.scale||t.translate){if(this.screen_coord=Jd(this),this.hruler){const{translate:t}=this.model,{width:e,height:n}=this.screen_coord;this.hruler.set(Qd(t,e)),this.vruler.set(Zd(t,0,n)),this.origin_rect.set($d(t))}this._guide=null}this.invalidate()}onmouseout_child(t){this._guide=null,this.invalidate()}onmousemove_child(t,e){t.target&&"CANVAS"!==t.target.tagName?this.guide=null:this.guide=this.toLocal(t.offsetX,t.offsetY)}});cc.register("shift-layer",class extends Bc{async ready(){await super.ready();const t=this.rootModel.get("translate");this.set("translate",t)}render(t){}get pointerEvents(){return"none"}contains(t,e){return!(2!=this.app.mode)}get eventMap(){return{"(root)":{"(self)":{keydown:this.onkeydown,keyup:this.onkeyup}}}}onkeydown(t){"Space"===t.code&&void 0===this.before_mode&&(this.before_mode=this.app.mode,this.app.mode=2)}onkeyup(t){"Space"===t.code&&(void 0!==this.before_mode&&(this.app.mode=this.before_mode),delete this.before_mode)}ondragstart(t){this.last_position=this.toLocal(t.offsetX,t.offsetY)}ondragmove(t){const{x:e,y:n}=this.toLocal(t.offsetX,t.offsetY);this.rootModel.move({x:e-this.last_position.x,y:n-this.last_position.y},!1),this.last_position=this.toLocal(t.offsetX,t.offsetY)}});function tu(t,e,n,i,r){const s=t.selected;let o=i?s.slice(0):[];e.isContainer()||(e=e.parent);const a=e.layout.capturables(e),c=!!e.layout.joinType;if(i&&n.selected.forEach(t=>{o.splice(o.indexOf(t),1)}),n.selected=[],a.forEach(t=>{!t.capturable||!function(t,e,n){const{sx:i,sy:r,ex:s,ey:o}=e;let a,c,l,h;if(i>s?(a=s,c=i):(a=i,c=s),r>o?(l=o,h=r):(l=r,h=o),n){const e=t.bounds,n=t.transcoordS2TR(e.left,e.top),i=t.transcoordS2TR(e.left+e.width,e.top+e.height),r=n.x,s=i.x,o=n.y,d=i.y,u=Math.min(a,r,c,s),p=Math.max(a,r,c,s),f=Math.min(l,o,h,d),g=Math.max(l,o,h,d);return!(p-u>Math.abs(c-a)+Math.abs(s-r)||g-f>Math.abs(h-l)+Math.abs(d-o))}{const e=t.path;if(!e)return Ki("컴포넌트에 get path가 잘못 구현되어있음.",t),!1;for(let n=0;n<e.length;n++){const i=t.transcoordS2TR(e[n].x,e[n].y);if(a>i.x||c<i.x||l>i.y||h<i.y)return!1}return!0}}(t,n,c)||-1!=o.indexOf(t)||r&&t.state.type!==r||n.selected.push(t)}),o=o.concat(n.selected),s.length!==o.length)t.selected=o;else for(let e=0;e<o.length;e++)if(s[e]!=o[e]){t.selected=o;break}}function eu(t,e,n,i,r,s){r||tu(t,e,n,i,s)}function nu(t,e){const n=t.components||[];for(const t of n){nu(t,e);const n=e.indexOf(t);-1!=n&&e.splice(n,1)}}cc.register("add-layer",class extends Bc{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}get pointerEvents(){return"none"}render(t){const e=this.addbox;if(e){const{sx:n,sy:i,ex:r,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,r-n,s-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle="black",t.stroke()}}contains(t,e){return!(3!=this.app.mode)}get eventMap(){return{"(root)":{"(self)":{addstart:this.onaddstart,addstop:this.onaddstop,keydown:this.onkeydown,dragstart:this.ondragstart,dragmove:this.ondragmove,dragend:this.ondragend,mousedown:this.onmousedown,mouseup:this.onmouseup}},"model-layer":{"(self)":{change:this.onchange_root_model}}}}onchange_root_model(t,e,n){t.translate&&this.set("translate",t.translate),t.scale&&this.set("scale",t.scale)}onaddstart(t,e){void 0===this.before_mode&&(this.before_mode=this.app.mode,this.models=t,this.app.mode=3,this.root.target_element?.focus())}onaddstop(){void 0!==this.before_mode&&(this.app.mode=this.before_mode),delete this.before_mode,delete this.addbox,this.invalidate()}onkeydown(t){3!==this.app.mode||"Esc"!=t.code&&"Escape"!=t.code||this.root.trigger("addstop")}ondragstart(t){const{x:e,y:n}=this.toLocal(t.offsetX,t.offsetY);this.addbox={sx:e,sy:n}}ondragmove(t){if(3!==this.app.mode)return;const{x:e,y:n}=this.toLocal(t.offsetX,t.offsetY);this.addbox&&(this.addbox.ex=e,this.addbox.ey=n,this.invalidate())}ondragend(t,e){if(3!==this.app.mode)return;const{sx:n,sy:i,ex:r,ey:s}=this.addbox;Ml.call(this.root,this.models,{left:Math.min(n,r),top:Math.min(i,s),width:Math.abs(r-n),height:Math.abs(s-i)}),this.root.trigger("addstop")}onmousedown(t,e){3===this.app.mode&&(this.downpoint={x:t.offsetX,y:t.offsetY})}onmouseup(t,e){if(this.downpoint.x!==t.offsetX||this.downpoint.y!==t.offsetY)return;const{x:n,y:i}=this.toLocal(t.offsetX,t.offsetY);Ml.call(this.root,this.models,{cx:n,cy:i}),this.root.trigger("addstop")}});cc.register("selection-layer",class extends Bc{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n);const i=this.root?.target_element;i?.addEventListener("contextmenu",t=>{t.shiftKey&&t.preventDefault()})}contains(t,e){return!1}render(t){const e=this.selbox;if(e){const{sx:n,sy:i,ex:r,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,r-n,s-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle="black",t.stroke()}}get eventMap(){return{"(root)":{"(self)":{keydown:this.onkeydown}},"model-layer":{"(self)":{change:this.onchange_root_model},"(all)":{dragstart:this.ondragstart_selbox,dragmove:this.ondragmove_selbox,dragend:this.ondragend_selbox,mousedown:this.onmousedown_comp,mouseup:this.onmouseup_comp}}}}onkeydown(t,e){const{deliverer:n}=e,i=n.selected;if(1!==i.length)return!1;let r=i[0];const s=r.parent;if(!s||s===n)return!1;if("Tab"===t.code){const e=s.layout.capturables(s);let n=e.indexOf(r);if(-1==n){if(!s.indexOf(r))return $i("Container not contains [",r,"] as a component"),!1;n=0}const i=e.length;t.shiftKey?n--:n++,r=e[(n+i)%i]}else{if(!s.layout.keyNavigate)return!1;r=s.layout.keyNavigate(s,r,t)||r}n.selected=[r],t.preventDefault()}onchange_root_model(t,e,n){t.translate&&this.set("translate",t.translate),t.scale&&this.set("scale",t.scale)}_pendingDecision(t){this.downpoint={x:t.offsetX,y:t.offsetY}}_selectGroupItem(t,e){const n=this.selected.indexOf(t);let i=t.parent;for(;i.parent.isGroup();)i=i.parent;let r=[],s=!1,o=!1;if(this.selected.forEach(t=>{let e=t.parent;if(t!==i){for(;e.parent&&e.parent.isGroup();)e=e.parent;e===i&&(r.push(t),s=!0)}else o=!0}),s)if(e.shiftKey){if(-1!=n)return void this._pendingDecision(e);r.push(t)}else{if(-1!=n)return void this._pendingDecision(e);r=[t]}else{if(o)return void this._pendingDecision(e);if(e.shiftKey)if(this.selected.length>0){if(-1!=this.selected.indexOf(i))return;r=[...this.selected,i]}else r=[i];else r=[i]}this.selected=r}onmousedown_comp(t,e){const{origin:n}=e;if(this.downpoint=null,t.shiftKey){if(n.stuck)return;if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(-1==this.selected.indexOf(n)){if((t.ctrlKey||t.metaKey)&&this.selected.length>0){const t=this.selected[0].state.type;if(n.state.type!==t)return}this.selected=[...this.selected,n]}else this._pendingDecision(t)}else{if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(n.stuck)this.selected.length>0&&(this.selected=[]);else{if(-1!=this.selected.indexOf(n))return;this.selected=[n],this.sameParent=!0}}}onmouseup_comp(t,e){if(!this.downpoint)return;if(this.downpoint.x!==t.offsetX||this.downpoint.y!==t.offsetY)return;const{origin:n}=e;if(t.shiftKey){let t=this.selected.indexOf(n);if(-1==t&&n.parent.isGroup()&&(t=this.selected.indexOf(n.parent)),-1!==t){const e=this.selected.slice();e.splice(t,1),this.selected=e}else{const t=this.selected.filter(t=>!t.isRootModel()&&!!t.parent),e=t.length>0&&t[0].parent;e&&e!==n.parent&&(!function(t,e){let n=t.parent;for(;n;){const t=e.indexOf(n);-1!=t&&e.splice(t,1),n=n.parent}}(n,t),nu(n,t)),t.push(n),this.selected=t}}else if(n.parent.isGroup())return void(this.selected=[n])}ondragstart_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:i,y:r}=this.toLocal(t.offsetX,t.offsetY);this.selbox={sx:i,sy:r,selected:[]}}ondragmove_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:i,y:r}=this.toLocal(t.offsetX,t.offsetY);if(this.selbox){this.selbox.ex=i,this.selbox.ey=r;const e=t.shiftKey&&(t.ctrlKey||t.metaKey)&&this.selected.length>0?this.selected[0].state.type:null;eu(this,n,this.selbox,t.shiftKey,!1,e),this.invalidate()}}ondragend_selbox(t,e){const{origin:n}=e;n.stuck&&(this.last_pos=null,this.selbox=null,eu(this,null,null,!1,!0),this.invalidate())}});class iu{constructor(t){this.layer=t}draw(t,e,n){const{left:i,top:r,width:s,height:o}=e.bounds;0!=s&&0!=o&&(t.beginPath(),t.rect(i,r,s,o),t.clip(),t.beginPath(),t.strokeStyle="#f26522",t.lineWidth=4,t.shadowBlur=10,t.shadowColor="black",t.shadowOffsetX=0,t.shadowOffsetY=0,t.rect(i,r,s,o),t.stroke(),t.closePath())}}class ru{constructor(t){this.layer=t}draw(t,e,n){const i=e.bounds;t.beginPath(),t.rect(i.left-4/n.x,i.top-4/n.y,i.width+8/n.x,i.height+8/n.y),t.setLineDash([3/n.x,4/n.y]),t.lineWidth=1/n.x,t.strokeStyle="black",t.stroke(),t.setLineDash([]),t.closePath()}}class su{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){const r=n.controls;return!!r&&(r.every((r,s)=>(Math.abs(t-r.x)<=4/i.x&&Math.abs(e-r.y)<=4/i.y&&(this.active={component:n,index:s,handler:r.handler}),!this.active)),!!this.active)}draw(t,e,n){const i=e.controls;i&&i.forEach((e,i)=>{t.beginPath(),t.lineWidth=1/n.x,t.ellipse(e.x,e.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.fillStyle="#ff5d72",t.fill(),t.strokeStyle="#fff",t.stroke()})}onevent(t,e){const{handler:n,component:i,index:r}=this.active;let s=i.toLocal(e.offsetX,e.offsetY);s=i.toParent(s.x,s.y),n&&"function"==typeof n[t]&&n[t](s,r,i)}onmousedown(t){this.onevent("onmousedown",t)}ondragstart(t){const e=this.active;e.changes=il.before([e.component]),this.onevent("ondragstart",t)}ondragmove(t){this.onevent("ondragmove",t)}ondragend(t){this.onevent("ondragend",t);const{component:e,changes:n}=this.active;il.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function ou(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}const au=15*Math.PI/180;class cu{constructor(t){this.layer=t}reset(){this.active=null,this.created=null}get selected(){return this.layer.selected}contains(t,e,n,i){return!!n.mutable&&(n.path.every((r,s)=>(Math.abs(t-r.x)<=4/i.x&&Math.abs(e-r.y)<=4/i.y&&(this.active={component:n,index:s}),!this.active)),!!this.active)}startLinkProcess(t,e,n){try{const i=xl(e,t.app,void 0);return t.rootModel.addComponent(i),this.layer.selected=[i],this.active={component:i,index:1},this.ondragstart(n),i}catch(t){$i(t)}}draw(t,e,n){if(!e.mutable||e.stuck)return;const i=e.path,r=this.active;i.forEach((i,s)=>{t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.fillStyle="#fff",r&&r.component===e&&r.index===s&&(t.strokeStyle="#fa7703",r.toFill&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke()})}ondblclick(t){const e=this.active.component;if(!e.pathExtendable)return;const n=e.path.slice();n.length<3||(n.splice(this.active.index,1),e.path=n)}onmousedown(t){this.active.toFill=!0}ondragstart(t){const{index:e,component:n}=this.active;this.created||(this.active.changes=il.before([n])),0!==e&&e!==n.path.length-1||(this.layer.counterEnd=0===e?n.toEnd||{fromto:"to"}:n.fromEnd||{fromto:"from"})}ondragmove(t){const{component:e,index:n}=this.active||{},{offsetX:i,offsetY:r}=t;let s=e.toLocal(i,r);if(s=e.toParent(s.x,s.y),t.shiftKey){const t=e.path.length;let i=e.isLine()&&0==n?e.path[1]:e.path[(n-1+t)%t];i=e.toParent(i.x,i.y);let r=0;if(t>2){let s;e.isLine()?0==n?s=e.path[2]:1!=n&&(s=e.path[n-2]):s=e.path[(n-2+t)%t],s&&(s=e.toParent(s.x,s.y),r=ou(s,i))}const c=Math.round((ou(i,s)-r)/au)*au+r;s=function(t,e,n){return{x:Math.cos(e)*n+t.x,y:Math.sin(e)*n+t.y}}(i,c,(o=i,a=s,Math.sqrt((a.x-o.x)*(a.x-o.x)+(a.y-o.y)*(a.y-o.y))))}var o,a;if(0===n||n===e.path.length-1){const t=this.layer.anchorTarget=e.rootModel.capture(i,r,t=>!t.isConnectable());if(t){const{x:o,y:a}=t.toLocal(i,r),c=this.layer.get("scale")||{x:1,y:1},l=this.layer.counterEnd,h=(t.anchors||[]).find(n=>{const{name:i,inout:r,multiplicity:s=1/0,position:h,filter:d}=n;if(l){const{anchor:t,fromto:e}=l;if(t&&("out"===t.inout&&"out"===r||"in"===t.inout&&"in"===r))return!1;if("from"===e&&"out"===r||"to"===e&&"in"===r)return!1}else Ki("should not be here.");if(Math.abs(o-h.x)>8/c.x||Math.abs(a-h.y)>8/c.y)return!1;const u=t.findInOutLines(i);return!!u.includes(e)||!(s!==1/0&&u.length>=s)&&(!l||!d||!!d.call(n,l))});h?0==n?e.from={component:t.get("refid"),anchor:h.name,position:s}:e.to={component:t.get("refid"),anchor:h.name,position:s}:0==n?e.from={position:s}:e.to={position:s}}else 0==n?e.from={position:s}:e.to={position:s}}e.mutatePath(null,function(t){const e=t[n]?.z;t[n]=s,void 0!==e&&(s.z=e)})}ondragend(t){const{component:e,index:n,changes:i}=this.active;if(0===n||n===e.path.length-1){const{offsetX:i,offsetY:r}=t,s=e.rootModel.capture(i,r,t=>t===e||t.isLine()),{x:o,y:a}=s.toLocal(i,r),c=this.layer.get("scale")||{x:1,y:1},l=(s.anchors||[]).find(t=>t&&Math.abs(o-t.position.x)<=8/c.x&&Math.abs(a-t.position.y)<=8/c.y);l&&(0==n?e.from={component:s.get("refid"),anchor:l.name}:e.to={component:s.get("refid"),anchor:l.name}),this.layer.endLinkProcess()}if(this.created){const t=new bl({changes:[{component:this.created,to_container:this.created.parent}]});this.created.app.commander.execute(t)}else il.after(i,e.app.commander);e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function lu(t,e,n){return t.filter(t=>{const{name:i,inout:r,multiplicity:s=1/0,filter:o}=t;if(n){const{anchor:t,fromto:e}=n;if(t&&("out"===t.inout&&"out"===r||"in"===t.inout&&"in"===r))return!1;if("from"===e&&"out"===r||"to"===e&&"in"===r)return!1}else if("in"===r)return!1;return!(s!==1/0&&e.findInOutLines(i).length>=s)&&(!o||!n||!!o.call(t,n))})}class hu{constructor(t){this.layer=t}get active(){return this._active?.component.disposed&&(this._active=null),this._active}set active(t){this._active=t}reset(){this.active=null}contains(t,e,n,i){const r=this.active?.component===n&&this.active?.anchor;this.active=null;const s=this.layer.counterEnd;return lu(n.isConnectable()&&!n.disposed&&this.getAnchorHandles(n,i)||[],n,s).every(s=>{const o=r===s.name?2:1;return s&&s.position&&Math.abs(t-s.position.x)<=4*o/i.x&&Math.abs(e-s.position.y)<=4*o/i.y&&(this.active={component:n,anchor:s.name,template:s.template}),!this.active}),!!this.active}getAnchorHandles(t,e){const{width:n,height:i}=t.bounds;return n*e.x<30||i*e.y<30?[]:t.anchors}draw(t,e,n){if(!e.get("refid")||e.isLine())return;const i=this.active,r=this.active?.component===e&&this.active?.anchor,s=this.layer.counterEnd;lu(e.isConnectable()&&!e.disposed&&this.getAnchorHandles(e,n)||[],e,s).forEach(s=>{const{name:o,position:a}=s,c=r===o?2:1;a&&(t.beginPath(),t.ellipse(a.x,a.y,4*c/n.x,4*c/n.y,0,0,2*Math.PI),t.setLineDash([0,0]),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",i&&i.component===e&&i.anchor===o&&(t.strokeStyle="#fa7703",i.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e,anchor:n,template:i}=this.active,r=this.layer.toLocal(t.offsetX,t.offsetY);this.layer.startLinkProcess(e,{type:"ortholine",lineWidth:1,strokeStyle:"black",begin:"oval",beginSize:"size9",end:"arrow",endSize:"size9",lineDash:"solid",lineCap:"butt",round:10,...i,from:{component:e.get("refid"),anchor:n,position:r},to:{position:r}},t)}ondragmove(t){}ondragend(t){}}function du(t,e){const{left:n,top:i,width:r,height:s}=t,o=n+r/2,a=i+s/2,c=n+r,l=i+s,h=r*e.x>50,d=s*e.y>50;return[{x:n,y:i},h?{x:o,y:i}:{x:null,y:null},{x:c,y:i},d?{x:c,y:a}:{x:null,y:null},{x:c,y:l},h?{x:o,y:l}:{x:null,y:null},{x:n,y:l},d?{x:n,y:a}:{x:null,y:null}]}class uu{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.resizable)return!1;const r=du(n.bounds,i);for(let s=0;s<r.length;s++){const o=r[s];if(null!=o.x&&null!=o.y&&Math.abs(t-o.x)<=4/i.x&&Math.abs(e-o.y)<=4/i.y)return this.active={component:n,index:s},!0}return!1}draw(t,e,n){if(e.isLine())return;const{left:i,top:r,width:s,height:o}=e.bounds;if(t.beginPath(),t.rect(i-4/n.x,r-4/n.y,s+8/n.x,o+8/n.y),t.setLineDash([3/n.x,4/n.y]),t.lineWidth=1/n.x,t.strokeStyle="black",t.stroke(),t.setLineDash([]),!e.resizable)return;const a=this.active;du(e.bounds,n).forEach((i,r)=>{null!=i.x&&null!=i.y&&(t.beginPath(),t.rect(i.x-4/n.x,i.y-4/n.y,8/n.x,8/n.y),t.setLineDash([]),t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",a&&a.component===e&&a.index===r&&(t.strokeStyle="#fa7703",a.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e}=this.active;this.active.bounds=e.bounds,this.active.boundsList=this.layer.selected.filter(t=>t.resizable).map(t=>t.bounds)}_resizeAll(t,e){const{component:n,index:i,boundsList:r,bounds:s}=this.active,o=n.scalable?this.layer.toLocal(t.offsetX,t.offsetY):{x:t.offsetX,y:t.offsetY};n.bounds=s;const a=function(t,e,n){const{left:i,top:r,width:s,height:o}=t.bounds;let a,c;switch(e){case 0:a=i,c=r;break;case 1:a=i+s/2,c=r;break;case 2:a=i+s,c=r;break;case 3:a=i+s,c=r+o/2;break;case 4:a=i+s,c=r+o;break;case 5:a=i+s/2,c=r+o;break;case 6:a=i,c=r+o;break;case 7:a=i,c=r+o/2}const l=a,h=c,d=t.fromScene(n.x,n.y);return{dx:d.x-l,dy:d.y-h}}(n,i,o);this.layer.selected.filter(t=>t.resizable).forEach((n,s)=>{n.bounds=r[s],function(t,e,n,i,r,s){let{left:o,top:a,width:c,height:l}=t.bounds;const h={left:o,top:a,width:c,height:l};switch(e){case 0:o+=i,a+=r,c-=i,l-=r;break;case 1:a+=r,l-=r;break;case 2:a+=r,c+=i,l-=r;break;case 3:c+=i;break;case 4:c+=i,l+=r;break;case 5:l+=r;break;case 6:o+=i,c-=i,l+=r;break;case 7:o+=i,c-=i}if(t.mutateBounds(function(e){return Math.abs(c)<=.001&&(c=.001),Math.abs(l)<=.001&&(l=.001),t.adjustResize({left:o,top:a,width:c,height:l},h,n)},this),t.isContainer()&&t.layout.ABSOLUTE&&!t.isGroup()){const e=h.left-o,n=h.top-a;return void(s?t.components.forEach(t=>{t.delta("tx",0),t.delta("ty",0),t.move({x:e,y:n},!1)}):t.components.forEach(t=>{t.delta("tx",e),t.delta("ty",n)}))}const d=s&&t.parent;d&&d.isGroup()&&d.calculateBounds()}(n,i,t.shiftKey,a.dx,a.dy,e)})}ondragmove(t){this._resizeAll(t,!1)}ondragend(t){this._resizeAll(t,!0),this.active.component.app.commander.execute(null,!1)}}const pu=2*Math.PI,fu=Math.PI/2;function gu(t,e){const n=t.bounds;return{x:n.left+n.width/2,y:n.top-20/e.y}}class mu{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.rotatable)return!1;const r=gu(n,i);return Math.abs(t-r.x)<=4/i.x&&Math.abs(e-r.y)<=4/i.y&&(this.active={component:n},!0)}draw(t,e,n){if(!e.rotatable)return;t.beginPath();const i=gu(e,n);t.lineWidth=1.5/n.x,t.moveTo(i.x,i.y+20/n.y),t.lineTo(i.x,i.y),t.strokeStyle="#656565",t.stroke(),t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,pu,!0),t.stroke(),t.fillStyle="#fff",t.fill();const r=this.active;r&&r.component===e&&(t.strokeStyle="#fa7703",t.stroke(),r.toFill&&(t.fillStyle="#ffb80c",t.fill()))}onmousedown(t){this.active.toFill=!0}ondragstart(t){const e=this.active;e.start_rotation=e.component.get("rotation"),e.rotations=this.layer.selected.filter(t=>t.rotatable).map(t=>t.get("rotation"))}ondragmove(t){const{component:e}=this.active;let n;e.scalable?(n=e.toLocal(t.offsetX,t.offsetY),n=e.toParent(n.x,n.y)):(n={x:t.offsetX,y:t.offsetY},e.parent?.isRootModel()||(n=e.toParent(n.x,n.y)));const i=e.rotatePoint,r=e.get("rotation")||0;let s=Math.atan((i.y-n.y)/(i.x-n.x));s=i.x>=n.x?s-fu:fu+s;const o=s-r;this.layer.selected.filter(t=>t.rotatable).forEach((e,n)=>{const i=((e.get("rotation")||0)+o)%pu;e.set("rotation",e.adjustRotation(i,t.shiftKey))})}ondragend(t){const{component:e}=this.active;e.app.commander.execute(null,!1)}}cc.register("modeling-layer",class extends Nc{constructor(t,e){super(t,e),this.pathHandler=new cu(this);const n=this.pathHandler,i=new su(this),r=new uu(this),s=new mu(this);this._modelers=[n,i,r,s],this._control_mode_modelers=[i,n,r,s],this.focusOutline=new iu(this),this.groupOutline=new ru(this),this.anchorHandler=new hu(this),this._reversed_modelers=this._modelers.slice().reverse(),this._control_mode_reverse_modelers=this._control_mode_modelers.slice().reverse(),this.hovered=null,this.hoveredDest=null}get modelers(){return this._control_mode?this._control_mode_modelers:this._modelers}get reversedModelers(){return this._control_mode?this._control_mode_reverse_modelers:this._reversed_modelers}async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}capture(t,e,n){return!!this.contains(t,e)&&this}contains(t,e){let n=this.selected.filter(t=>!!t.parent);const i=this.fromParent(t,e),r=this.get("scale")||{x:1,y:1};let s;if(this._state_dragging){if(this._counter_end){let n=r;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(i.x,i.y):(s=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(s.x,s.y,this.anchorTarget,n))return!0}return!0}this.modelers.forEach(t=>t.reset()),n=this.selected.filter(t=>!!t.parent);for(let o=0;o<n.length;o++){const a=n[o];let c=r;a.scalable?s=a.fromScene(i.x,i.y):(s=a.fromScene(t,e),c={x:1,y:1});for(let t=0;t<this.modelers.length;t++){const e=this.modelers[t];if(e.contains(s.x,s.y,a,c))return this.currentModeler=e,!0}}if(this.anchorTarget){let n=r;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(i.x,i.y):(s=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(s.x,s.y,this.anchorTarget,n))return this.currentModeler=this.anchorHandler,!0}else this.anchorHandler.reset();return this.currentModeler=null,!1}_componentDrawer(t,e,n,i){const r=[];let s=e.parent;if(e.isRootModel())return t.save(),i(t,e,n),void t.restore();for((t=this.getContext(e))==this.auxContext2D&&(n={x:1,y:1});s&&!s.isRootModel();)r.push(s),s=s.parent;t.save(),r.reverse().forEach(function(e){const n=e.rotatePoint;t.translate(n.x,n.y);const i=e.get("scale");i&&t.scale(i.x,i.y),t.rotate(e.get("rotation")),t.translate(-n.x,-n.y);const r=e.bounds;t.translate(r.left,r.top)});const o=e.rotatePoint;t.translate(o.x,o.y);const a=e.get("scale");a&&t.scale(a.x,a.y),t.rotate(e.get("rotation")),t.translate(-o.x,-o.y),i(t,e,n),t.restore()}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:i}=this.model;t.save(),t.beginPath(),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.rect(0,0,t.canvas.width,t.canvas.height),t.fillStyle="black",t.globalAlpha=.5,t.fill(),t.restore(),e&&t.translate(e.x*Hr,e.y*Hr),t.scale(n.x*Hr,n.y*Hr),i&&t.rotate(i),t.clearRect(0,0,this.rootModel.get("width"),this.rootModel.get("height"))}render(t){if(this.rootModel?.is3dMode)return;t.beginPath();const e=this.get("scale")||{x:1,y:1},n=this.selected.filter(t=>!!t.parent);if(this.anchorTarget&&this._componentDrawer(t,this.anchorTarget,e,(t,e,n)=>{this.anchorHandler.draw(t,e,n)}),this.focused&&this._componentDrawer(t,this.focused,e,(t,e,n)=>{this.focusOutline.draw(t,e,n)}),n.length>0&&n[0].parent.isGroup()){let i=n[0].parent;for(;i.parent.isGroup();)i=i.parent;this._componentDrawer(t,i,e,(t,e,n)=>{this.groupOutline.draw(t,e,n)})}n.forEach(n=>{this._componentDrawer(t,n,e,(t,e,n)=>{this.reversedModelers.forEach(i=>i.draw(t,e,n))})})}get anchorTarget(){return this.currentModeler===this.anchorHandler||this.currentModeler===this.pathHandler||this.hovered?.isLine()||(this._anchorTarget=this.hovered),this._anchorTarget}set anchorTarget(t){this._anchorTarget=t}get hovered(){return this._hovered}set hovered(t){this._hovered=t,this.invalidate()}startLinkProcess(t,e,n){this.currentModeler=this.pathHandler,this.processingLink=this.pathHandler.startLinkProcess(t,e,n),this.counterEnd=this.processingLink.fromEnd,this.processingLink.trigger("tag")}set counterEnd(t){this.currentModeler=this.pathHandler,this._counter_end=t}get counterEnd(){return this._counter_end}endLinkProcess(){this.processingLink?.trigger("tagreset"),this.processingLink=null,this._counter_end=null}get eventMap(){return{"model-layer":{"(all)":{change:this.onchange_model,wheel:this.onwheel_scale,drop:this.ondrop},"(descendant)":{mouseenter:this.onmouseenter,mouseleave:this.onmouseleave},"(self)":{dblclick:this.ondblclick_model}},"(root)":{"(self)":{selected:this.onselected,keydown:this.onkeydown,keyup:this.onkeyup}}}}onmouseenter(t,e){this.hovered=e?.origin}onmouseleave(t,e){this.hovered=null}onkeydown(t){"Alt"==t.key&&(this._control_mode=!0,this.invalidate())}onkeyup(t){"Alt"==t.key&&(this._control_mode=!1,this.invalidate())}onselected(t,e){this.invalidate()}onchange_model(t,e,n){const{origin:i,deliverer:r}=n;i===r&&(t.translate&&this.set("translate",t.translate),void 0!==t.rotation&&this.set("rotation",t.rotation),t.scale&&this.set("scale",t.scale)),this.invalidate()}ondblclick_model(t,e){const n=e.origin;n?.root.fit()}ondblclick(t){"function"==typeof this.currentModeler.ondblclick&&this.currentModeler.ondblclick(t),this.invalidate()}onmousedown(t){this.currentModeler.onmousedown(t),this.invalidate()}onmouseup(t){"function"==typeof this.currentModeler.onmouseup&&this.currentModeler.onmouseup(t),this.invalidate()}ondragstart(t){this.currentModeler.ondragstart(t),this._state_dragging=!0}ondragmove(t){this.currentModeler.ondragmove(t),this.invalidate()}ondragend(t){this._state_dragging=!1,this.currentModeler.ondragend(t),this.invalidate()}ondrop(t,e){const{origin:n}=e,i=t.dataTransfer.files;if(i.length<1)return;const r=this.rootModel.toLocal(t.offsetX,t.offsetY),s=this.rootModel;Promise.all(Array.from(i).map(t=>new Promise((e,n)=>{const i=new FileReader;i.addEventListener("loadend",t=>{e(i.result)}),["error","abort"].forEach(t=>i.addEventListener(t,t=>{n(t)})),i.readAsDataURL(t)}))).then(e=>{if(t.altKey)return il.around(this.app.commander,()=>{n.ondropfile(i,e)}),void(this.selected=[n]);const o=[],a=e.map((t,e)=>{let n;const a=i[e].type,c=i[e].name;return a.startsWith("image/")?(n=xl({type:a.startsWith("image/gif")?"gif-view":"image-view",top:0,left:0,width:200,height:200,src:t},s.app),o.push(new Promise((e,i)=>{const r=new Image;r.src=t,r.onload=()=>{n.set({width:r.width,height:r.height}),e()},r.onerror=t=>{i(t)}}))):a.startsWith("audio/")?n=xl({type:"audio",top:0,left:0,width:100,height:100,src:t},s.app):a.startsWith("vnd.ms-excel/")||/\.xlsx?$/.test(c)?n=xl({type:"excel",top:0,left:0,width:100,height:100,src:t},s.app):Qi("dropped file",i[e]),n&&(n.center=r,r.x+=50,r.y+=50),n}).filter(Boolean).map(t=>({component:t,to_container:s}));a.length>0&&Promise.all(o).then(()=>{this.app.commander.execute(new bl({changes:a})),this.selected=a.map(t=>t.component)},t=>{Ki(t)})},t=>{Ki(t)})}onwheel_scale(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer;let i;if(t.shiftKey)i=-1!=navigator.userAgent.indexOf("Win")?t.deltaY<0?1:-1:t.deltaX<0?1:-1,t.altKey?il.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("letterSpacing")||Gr.LETTER_SPACING;e+=i,t.set("letterSpacing",e)})}):il.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("fontSize")||Gr.FONT_SIZE;e<1&&(e=1),e+=i,t.set("fontSize",e)})});else{i=t.deltaY<0?1:-1;const e=n.get("scale")||{x:1,y:1},r=n.get("translate"),s=t.offsetX,o=t.offsetY,a=n.toLocal(s,o),c=.1*i,l={x:e.x+c,y:e.y+c};if(i<0&&e.x<.2||i>0&&e.x>10)return;n.set("scale",l);const h=n.toLocal(s,o);n.set("translate",{x:r.x+(h.x-a.x)*l.x,y:r.y+(h.y-a.y)*l.y})}}});cc.register("scroll-layer",class extends Bc{get capturable(){return!0}get pointerEvents(){return"none"}render(t){const{scrolling:e}=this.state;if(t.save(),t.beginPath(),t.fillStyle="#777",this.vscroller){const{left:n,top:i,width:r,height:s}=this.vscroller;t.globalAlpha="v"==e?1:.3,t.fillRect(n,i,r,s)}if(this.hscroller){const{left:n,top:i,width:r,height:s}=this.hscroller;t.globalAlpha="h"==e?1:.3,t.fillRect(n,i,r,s)}t.stroke(),t.restore()}resize(){super.resize(),this.calcScrollerBounds()}contains(t,e){const n=this.vscroller,i=this.hscroller;return this.setState("scrolling",n&&t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height?"v":i&&t>=i.left&&t<=i.left+i.width&&e>=i.top&&e<=i.top+i.height?"h":null),!!this.getState("scrolling")}get eventMap(){return{"(root)":{"model-layer":{change:this.onchangeModelLayer}}}}onchange(t){"scrolling"in t&&this.invalidate()}ondragstart(t,e){this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragmove(t,e){const n=this.root,{clientWidth:i,clientHeight:r}=this.canvas,{width:s,height:o}=this.rootModel.model,{x:a,y:c}={x:t.offsetX,y:t.offsetY},{x:l,y:h}=this._scale,{scrolling:d}=this.state,u=s/i,p=o/r;d&&n.rootModel.move({x:"h"==d?(-a+this.lastPosition.x)*l*u:0,y:"v"==d?(-c+this.lastPosition.y)*h*p:0},!1),this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragend(){delete this.lastPosition,this.setState({scrolling:null})}calcScrollerBounds(){if(!this.rootModel)return;const{clientWidth:t,clientHeight:e}=this.canvas,{width:n,height:i}=this.rootModel.model,{x:r=1,y:s=1}=this._scale||{},{x:o=0,y:a=0}=this._translate||{},c=n/t,l=i/e;let h={left:-o/r/c,top:e-10,width:t/r/c,height:10};this.hscroller=h.left>1||h.width+h.left<t-1?h:null,h={left:t-10,top:-a/s/l,width:10,height:e/s/l},this.vscroller=h.top>1||h.height+h.top<e-1?h:null,this.invalidate()}onchangeModelLayer(t,e,n){if(t.scale){const{x:e=1,y:n=1}=t?.scale||{};this._scale={x:e,y:n},this.calcScrollerBounds()}if(t.translate){const{x:e=0,y:n=0}=t.translate||{};this._translate={x:e,y:n},this.calcScrollerBounds()}}});const yu="#ff3366",bu=[3,3];function vu(){const t=arguments,e=t[t.length-1],n=this.event_pump;n.listeners.forEach(i=>{!function(t,e,n,i,r){for(const s in n){const o=n[s];if(Oa(s,i.origin,0,t))for(const t in o){const n=o[t];t==i.name&&(i.listener=e,n.apply(e,r))}}}(n.deliverer,i.listener,i.cloned_handlers,e,t)})}cc.register("snap-guide-layer",class extends Bc{constructor(){super(...arguments),this._snapResult=null}get pointerEvents(){return"none"}get capturable(){return!1}contains(t,e){return!1}get snapResult(){return this._snapResult}set snapResult(t){this._snapResult=t,this.invalidate()}clear(){this._snapResult&&(this._snapResult=null,this.invalidate())}get eventMap(){return{"(root)":{"model-layer":{change:this.onchange_root_model}}}}onchange_root_model(t){(t.translate||t.scale)&&this.syncTransform()}syncTransform(){const t=this.rootModel;if(!t)return;const e=t.get("translate")||{x:0,y:0},n=t.get("scale")||{x:1,y:1};this.set({translate:e,scale:n})}async ready(){await super.ready(),this.syncTransform()}render(t){const e=this._snapResult;if(e&&0!==e.guides.length){t.save(),t.strokeStyle=yu,t.fillStyle=yu,t.lineWidth=1,t.setLineDash(bu);for(let n=0,i=e.guides.length;n<i;n++){const i=e.guides[n];t.beginPath(),"x"===i.axis?(t.moveTo(i.position,i.from),t.lineTo(i.position,i.to)):(t.moveTo(i.from,i.position),t.lineTo(i.to,i.position)),t.stroke()}t.restore()}}});class _u{constructor(t){if(void 0===t.on)throw new Error("Deliverer should be a event handlable object.");this.deliverer=t,this.listeners=[]}start(){this.deliverer.on("(all)",vu,{event_pump:this})}stop(){this.deliverer.off("(all)",vu)}on(t,e){const n=Object.assign({},e);Object.keys(n).forEach(e=>{if(0==e.indexOf("?")){const i=n[e],r=e.substr(1),s=t.get(r);delete n[e],s?n[s]=i:$i("EventPump#on","variable #{selector} is not evaluated on listener")}}),this.listeners.push({listener:t,handlers:e,cloned_handlers:n})}off(t,e){for(let n=0;n<this.listeners.length;n++){const i=this.listeners[n];i.listener!==t||e&&i.handlers!==e||this.listeners.splice(n,1)}}clear(){this.listeners=[]}dispose(){this.stop(),this.clear()}}class xu{constructor(t){this.eventMaps=[],this.root=t,t.eventMap&&this.add(t,t.eventMap)}set root(t){this._root=t}get root(){return this._root}stop(){this.eventMaps.forEach(t=>t.eventPump.stop())}add(t,e){if(this.root)for(const n in e){const i=e[n];if("(self)"===n&&void 0===t.on)throw new Error("(self) selector not available when deliverer is not a event handlable object.");La(n,this.root,t).forEach(n=>{const r=new _u(n);r.on(t,i),r.start(),this.eventMaps.push({eventPump:r,listener:t,handlerMap:e,deliverer:n})})}}remove(t,e){const n=this.eventMaps.slice(0);for(let i=0;i<n.length;i++){const r=n[i];r.listener!==t||e&&r.handlerMap!==e||(this.eventMaps.splice(i,1),r.eventPump.dispose())}}clear(){this.eventMaps.slice(0).forEach(t=>t.eventPump.dispose()),this.eventMaps=[]}dispose(){this.stop(),this.clear()}}const wu=0,Mu=1,Su=2,ku=0,Au=1,Eu=2;let Cu={},Tu=0;class Pu{constructor(t,e){this._type=e||t.type,this._ctrlKey=t.ctrlKey,this._altKey=t.altKey,this._shiftKey=t.shiftKey,this._metaKey=t.metaKey;const n=function(t){if(t.touches){const e=t.touches[0];if(!e)return Cu;const n=e.target.getBoundingClientRect();return Cu={x:t.offsetX||e.clientX-n.left,y:t.offsetY||e.clientY-n.top},Cu}return{x:t.offsetX,y:t.offsetY}}(t);if(this._offsetX=n.x,this._offsetY=n.y,t.touches&&t.touches[0]?(this._clientX=t.touches[0].clientX,this._clientY=t.touches[0].clientY):(this._clientX=t.clientX,this._clientY=t.clientY),"wheel"==t.type)this.deltaX=t.deltaX,this.deltaY=t.deltaY,this.deltaZ=t.deltaZ;else if("drop"==t.type)this.dataTransfer=t.dataTransfer;else if(t.type.match(/^touch/)&&(this._scale=t.scale,this._touches=t.touches,this._changedTouches=t.changedTouches,null==this._scale)){const e=function(t){let e,n,i=0,r=0,s=0;if(1===t.touches.length)return s;Array.from(t.touches).forEach(t=>{e=null!=e?Math.min(t.screenX,e):t.screenX,i=Math.max(t.screenX,i),n=null!=n?Math.min(t.screenY,n):t.screenY,r=Math.max(t.screenY,r)});const o=i-e||0,a=r-n||0;return s=Math.sqrt(Math.pow(o,2)+Math.pow(a,2))||0,s}(t);Tu>0&&(this._scale=e/Tu),Tu=e}}get type(){return this._type}set type(t){this._type=t}get offsetX(){return this._offsetX}get offsetY(){return this._offsetY}get altKey(){return this._altKey}get ctrlKey(){return this._ctrlKey}get shiftKey(){return this._shiftKey}get metaKey(){return this._metaKey}get clientX(){return this._clientX}get clientY(){return this._clientY}get touches(){return this._touches}get changedTouches(){return this._changedTouches}get scale(){return this._scale}stopPropagation(){this._stop_=!0,this.originalEvent?.stopPropagation()}isPropagationStopped(){return this._stop_}preventDefault(){this._prevented=!0}isDefaultPrevented(){return this._prevented}}function Du(t,e,n){if(!t||!t.app)return;if(t.app.isViewMode&&t.hidden)return;n instanceof Pu&&e===n.type||(n=new Pu(n,e));const i="on"+e;t[i]&&t[i](n),n.isPropagationStopped()||t.trigger(e,n)}class Ou{constructor(t,e){this.gestureHandlerBuilder=t=>{const e=this[`on${t}`];return t=>{const n=new Pu(t),i=this.getChildScrollOffset();return n._offsetX+=this.html_element.scrollLeft+i.scrollLeft,n._offsetY+=this.html_element.scrollTop+i.scrollTop,e(n),n.isDefaultPrevented()&&t.preventDefault(),!1}},this.keyeventHandlerBuilder=t=>this[`on${t}`],this.ondragover=t=>(Du(this.findTarget(t),t.type,t),!1),this.ondrop=t=>(Du(this.findTarget(t),t.type,t),!1),this.ondblclick=t=>(Du(this.findTarget(t),t.type,t),this.last_target=null,!1),this.onkeydown=t=>(this.container.trigger(t.type,t),!1),this.onkeyup=t=>(this.container.trigger(t.type,t),!1),this.onmousemove=t=>{switch(this.status){case Mu:const e=t.offsetX-this.__dragstart_e.offsetX,n=t.offsetY-this.__dragstart_e.offsetY;if(e*e+n*n<16)break;this.status=Su,Du(this.last_target,"dragstart",this.__dragstart_e),this.__dragmove_e=t,Du(this.last_target,"dragmove",t);break;case Su:this.__dragmove_e=t,Du(this.last_target,"dragmove",t);break;default:{const e=this.findTarget(t);this.last_enter_target!==e&&(this.last_enter_target&&Du(this.last_enter_target,"mouseleave",t),e&&Du(e,"mouseenter",t),this.last_enter_target=e),Du(e,t.type,t),this.last_target=e}}return!1},this.onmousedown=t=>{if(this.status===Su)Du(this.last_target,"dragend",t),this.last_target=null,this.status=wu;else{const e=this.findTarget(t);this.last_target=e,this.status=Mu,this.__dragstart_e=t,Du(e,t.type,t)}return!1},this.onmouseup=t=>{if(this.status===Su)Du(this.last_target,"dragend",t);else{const e=this.findTarget(t);Du(e,t.type,t),this.last_target===e&&Du(e,"click",t)}return this.last_target=null,this.status=wu,!1},this.onmouseout=t=>{const e=this.findTarget(t);if(this.status===Su)Du(this.last_target,"dragend",t);else{if(this.last_target&&this.last_target===e)return;this.last_enter_target&&(Du(this.last_enter_target,"mouseleave",t),delete this.last_enter_target)}return this.last_target=null,this.status=wu,!1},this.ontouchstart=t=>{const e=this.findTarget(t);return this.last_target=e,this.status=Au,this.touchPoints||(this.touchPoints=[]),this.touchPoints.push(t.changedTouches[0]),this.holdTimer=setTimeout(()=>{this.status=ku,Du(this.last_target,"hold",t),delete this.holdTimer},500),Du(e,t.type,t),!1},this.ontouchmove=t=>{if(!t.touches||!t.changedTouches)return Du(this.last_target,"dragstart",t),Du(this.last_target,"dragmove",t),!1;let e=this.findTarget(t);switch(this.status){case Au:Array.from(t.changedTouches).forEach(t=>{const e=this.touchPoints.find(e=>e.identifier===t.identifier);if(!e)return;const n=e.clientX-t.clientX,i=e.clientY-t.clientY;return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))>=16?(this.status=Eu,void(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer))):void 0});break;case Eu:if(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer),2===t.changedTouches.length&&null!=t.scale&&1!==t.scale&&(t.scale<.9||t.scale>1.1))return Du(this.last_target,"pinch",t),!1;Du(this.last_target,"pan",t),e=this.last_target;break;default:this.last_enter_target!==e&&(this.last_enter_target&&Du(this.last_enter_target,"mouseleave",t),e&&Du(e,"mouseenter",t),this.last_enter_target=e),this.last_target=e}return Du(e,"touchmove",t),!1},this.ontouchend=t=>{let e=this.findTarget(t);switch(this.status){case Eu:e=this.last_target;break;case Au:{const n=performance.now(),i=n-this.touchedAt;this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer,Du(e,i<500?"doubletap":"tap",t),this.touchedAt=n);break}}Du(e,"touchend",t);const n=this.touchPoints.findIndex(e=>e.identifier===t.changedTouches[0].identifier);return this.touchPoints.splice(n,1),this.last_target=null,this.status=ku,!1},this.onwheel=t=>(Du(this.findTarget(t),t.type,t),!1),this.container=t,this.html_element=e,this.status=wu,this.last_target=null,this.gesture_handlers=Yr.map(t=>this.gestureHandlerBuilder(t)),this.keyevent_handlers=Vr.map(t=>this.keyeventHandlerBuilder(t)),Yr.forEach((t,n)=>e.addEventListener(t,this.gesture_handlers[n]),{passive:!1}),Vr.forEach((t,n)=>e.addEventListener(t,this.keyevent_handlers[n])),e.ondragover=this.gestureHandlerBuilder("dragover"),e.ondrop=this.gestureHandlerBuilder("drop"),e.tabIndex=1}dispose(){this.last_enter_target&&Du(this.last_enter_target,"mouseleave",new CustomEvent("mouseleave")),Yr.forEach((t,e)=>this.html_element.removeEventListener(t,this.gesture_handlers[e])),Vr.forEach((t,e)=>this.html_element.removeEventListener(t,this.keyevent_handlers[e])),delete this.gesture_handlers,delete this.keyevent_handlers,delete this.last_target}getChildScrollOffset(){for(const t of this.html_element.children)if(t.scrollTop>0||t.scrollLeft>0)return{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop};return{scrollLeft:0,scrollTop:0}}findTarget(t){const e=this.container.rootModel;if(e?.is3dMode)return e;const n=this.html_element.getBoundingClientRect(),i=this.getChildScrollOffset(),r=t.clientX-n.left+this.html_element.scrollLeft+i.scrollLeft,s=t.clientY-n.top+this.html_element.scrollTop+i.scrollTop;return this.container.capture(r,s)}}function zu(t,e,n,i=0){if(e.length<2)return e;let r=2;for(;r<e.length;r++){const s=e.substring(0,r);if(!(t.measureText(s).width+(s.length-1)*i<n))break}return e.substring(0,r-1)}function Iu(t,e,n,i,r=0){const s=String(e).split("\n");return i?[].concat.apply([],s.map(e=>function(t,e,n,i=0){const r=e.split(" "),s=[];let o,a,c=[];for(o=0,a=1;a<=r.length;a++)if(c=r.slice(o,a),t.measureText(c.join(" ")).width+(c.join("").length-1)*i>n){if(a-o==1){const e=zu(t,c[0],n,i);s.push([e]),r.splice(o,1,e,c[0].substring(e.length))}else{for(;""==r[a-1];)a++;s.push(r.slice(o,--a))}o=a}return a-o>1&&s.push(c),0==s.length&&s.push([""]),s}(t,e,n,r))):s.map(t=>t.split(" "))}const Lu={},ju={},Ru=()=>{};var Fu={register:function(t,e,n){Lu[t]=e,n&&(ju[t]=n)},unregister:function(t){delete Lu[t],delete ju[t]},get:function(t){return Lu[t]},getDisposer:function(t){return ju[t]||Ru}};function Bu(t){if(!t.hasTextProperty||t.textHidden)return;let{text:e="",bold:n=Gr.BOLD,italic:i=Gr.ITALIC,textWrap:r=Gr.TEXT_WRAP,letterSpacing:s=0,fontFamily:o=Gr.FONT_FAMILY,fontColor:a=Gr.FONT_COLOR,textAlign:c=Gr.TEXT_ALIGN,textBaseline:l=Gr.TEXT_BASELINE,fontSize:h=Gr.FONT_SIZE,lineHeight:d=1.2*h}=t.model;const{left:u,top:p,width:f,height:g}=t.textBounds;h||=Gr.FONT_SIZE,d||=1.2*h,t.textHidden=!0;const m=document.createElement("textarea"),y=new AbortController;Yr.forEach(function(t){m.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:y.signal})});const b=t.toGlobal(u,p),{rotation:v,scale:_}=function(t){let e=0,n=1,i=t;for(;i;){e+=i.get("rotation")||0;const{x:t,y:r}=i.get("scale")||{x:1,y:1};n*=Math.max(t,r)||1,i=i.parent}return{rotation:e,scale:n}}(t);m.value=e;const x={position:"absolute",width:f+"px",height:g+"px",padding:"0",fontFamily:o,fontSize:h+"px",lineHeight:d+"px",overflow:"hidden",resize:"none",outline:"none",border:"0",backgroundColor:"transparent",display:"inline-block",color:a};switch(n&&(x.fontWeight="bold"),i&&(x.fontStyle="italic"),c){case"right":case"end":x.textAlign="right";break;case"justify":x.textAlign="justify";break;case"left":case"start":x.textAlign="left";break;default:x.textAlign="center"}const w=[n,i,h+"px",o].filter(Boolean).join(" ");function M(e){const n={left:0,top:0},i=d*function(t,e,n,i,r=0){const s=t.getContext();let o;return s.save(),s.font=n,o=Iu(s,e,i,t.get("textWrap"),r).length,s.restore(),o}(t,e,w,f,s);switch(x.height=i+"px",l){case"top":case"hanging":break;case"bottom":case"alphabetic":n.top=g-i;break;default:n.top=g/2-i/2}if(!r){const i=function(t,e,n,i){const r=e.split("\n");let s=i;const o=t.getContext();return o.save(),o.font=n,r.forEach(t=>{const e=o.measureText(t).width;e>s&&(s=e)}),o.restore(),s}(t,e,w,f);switch(x.width=i+"px",c){case"right":case"end":n.left=f-i;break;case"left":case"start":break;default:n.left=(f-i)/2}}x.marginLeft=n.left+"px",x.marginTop=n.top+"px",x.transform=`translate(${b.x}px, ${b.y}px) scale(${_}) rotate(${v}rad)`,x.transformOrigin=`${-n.left}px ${-n.top}px`,Object.assign(m.style,x)}M(e);const S=t.root.target_element;S.appendChild(m),m.select();let k,A=!1;m.addEventListener("keydown",function(t){t.stopPropagation(),"Escape"!=t.code&&(t.shiftKey||"Enter"!=t.code&&"NumpadEnter"!=t.code)?setTimeout(()=>{M(m.value)}):(A=k.skipUpdate="Escape"==t.code,"function"==typeof document.createEvent?m.dispatchEvent(k):m.fireEvent(k.eventType,k))},{signal:y.signal}),document.createEvent?(k=document.createEvent("HTMLEvents"),k.initEvent("blur",!0,!1)):(k=document.createEventObject(),k.eventType="blur");const E=t.root.selected,C=function(n){t.root.selected=E,t.textHidden=!1,y.abort(),m.removeEventListener("blur",C,!1),m.parentElement&&m.parentElement.removeChild(m),S.focus(),n.skipUpdate||A||t.app.commander.execute(new il({changes:[{component:t,before:{text:e},after:{text:m.value}}]}))};m.addEventListener("blur",C,!1)}Fu.register("text-editor",{"(root)":{"(self)":{keydown:function(t,e){const{deliverer:n}=e,i=n.selected;return!(1!==i.length||!i[0].hasTextProperty)&&(("Enter"==t.code||"NumpadEnter"==t.code)&&(Bu(i[0]),t.preventDefault(),!0))}}},"model-layer":{"(descendant)":{dblclick:function(t,e){Bu(e.origin)}}}});class Nu{constructor(t){const e=[],n=[];for(let i=0,r=t.length;i<r;i++){const r=t[i],s=r.left,o=r.left+r.width,a=s+r.width/2,c=r.top,l=r.top+r.height,h=c+r.height/2;e.push({value:s,perpMin:c,perpMax:l},{value:a,perpMin:c,perpMax:l},{value:o,perpMin:c,perpMax:l}),n.push({value:c,perpMin:s,perpMax:o},{value:h,perpMin:s,perpMax:o},{value:l,perpMin:s,perpMax:o})}e.sort((t,e)=>t.value-e.value),n.sort((t,e)=>t.value-e.value),this.xEdges=e,this.yEdges=n}get empty(){return 0===this.xEdges.length&&0===this.yEdges.length}calculateSnap(t,e,n,i){if(0===this.xEdges.length&&0===this.yEdges.length)return{dx:e,dy:n,guides:[]};const r={left:t.left+e,top:t.top+n,width:t.width,height:t.height},s=r.left,o=s+r.width,a=s+r.width/2,c=r.top,l=c+r.height,h=c+r.height/2,d=this.findBestSnap(this.xEdges,[s,a,o],i),u=this.findBestSnap(this.yEdges,[c,h,l],i),p=d?e+d.correction:e,f=u?n+u.correction:n;if(!d&&!u)return{dx:e,dy:n,guides:[]};const g=[];if(d){const e=t.top+f,n=e+t.height;for(const t of d.matches)g.push({axis:"x",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}if(u){const e=t.left+p,n=e+t.width;for(const t of u.matches)g.push({axis:"y",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}return{dx:p,dy:f,guides:g}}findBestSnap(t,e,n){let i=n+1,r=0,s=[];for(let o=0;o<3;o++){const a=e[o],c=this.searchNearest(t,a,n);if(!c)continue;const l=Math.abs(c.correction);if(l<i)i=l,r=c.correction,s=c.matches;else if(l===i&&c.correction===r)for(const t of c.matches)s.push(t)}return i<=n?{correction:r,matches:s}:null}searchNearest(t,e,n){const i=t.length;if(0===i)return null;let r=0,s=i;for(;r<s;){const n=r+s>>1;t[n].value<e?r=n+1:s=n}let o=-1,a=n+1;if(r<i){const i=t[r].value-e;i<=n&&(o=r,a=i)}if(r>0){const n=e-t[r-1].value;n<a&&(o=r-1,a=n)}if(o<0||a>n)return null;const c=t[o].value,l=c-e,h=[t[o]];for(let e=o-1;e>=0&&t[e].value===c;e--)h.push(t[e]);for(let e=o+1;e<i&&t[e].value===c;e++)h.push(t[e]);return{correction:l,matches:h}}}function Hu(t){const e=t.root;if(!e||!e.assist_layers)return null;for(const t of e.assist_layers)if("snap-guide-layer"===t.state?.type)return t;return null}const Yu=di(function(t,e,n){if(!t.hasSameParentForAllSelected||n)return void(t.focused=null);const i=[];e[0].parent.isGroup()?t.focused=e[0].parent:(e.forEach(t=>{t.path.forEach(e=>{i.push(t.toScene(e.x,e.y))})}),t.focused=t.capturePath(i,e))},300);let Vu;Fu.register("move-handler",{"model-layer":{"(descendant)":{dragstart:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;let r=i.selected;const s=i.selected.filter(t=>!t.stuck);if(r.length!==s.length&&(r=i.selected=s),0==r.length)return;let o;if(r[0].scalable?(o=r[0].toLocal(t.offsetX,t.offsetY),o=r[0].toParent(o.x,o.y)):o={x:t.offsetX,y:t.offsetY},this.last_pos=o,this.direction=0,i.focused=r[0].parent,t.altKey){const t=[],e=new Map;i.selected=i.selected.filter(t=>!t.isRootModel()).map(n=>{const r=wl(n,t=>{const n=i.root.getNewRefid();return void 0!==t&&e.set(t,n),n});return t.push({component:r,to_container:n.parent}),r}).map(t=>(t.replaceRefids(e),t)),t.forEach(({component:t,to_container:e})=>{e.addComponent(t)}),this.duplicates=i.selected.map(t=>({component:t}))}else this.changes=il.before(r);this.snapIndex=function(t){if(0===t.length)return null;const e=t[0].parent;if(!e||!e.components)return null;const n=new Set(t),i=[];for(const t of e.components)t.isLayer?.()||t.stuck||n.has(t)||i.push(t.bounds);return 0===i.length?null:new Nu(i)}(r);const a=n.rootModel?.get("scale"),c=a?(Math.abs(a.x)+Math.abs(a.y))/2:1;this.snapThreshold=5/(c||1)},dragmove:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const r=i.selected;if(0==r.length||!this.last_pos)return;let s;r[0].scalable?(s=r[0].toLocal(t.offsetX,t.offsetY),s=r[0].toParent(s.x,s.y)):s={x:t.offsetX,y:t.offsetY},t.shiftKey?2==this.direction&&(this.direction=0):this.direction=2;let o=s.x-this.last_pos.x,a=s.y-this.last_pos.y;if(0==this.direction){if(o*o+a*a<25)return;Math.abs(o)>Math.abs(a)?this.direction=3:this.direction=4}3==this.direction?a=0:4==this.direction&&(o=0);const c=this.snapIndex,l=c&&!t.metaKey&&!t.ctrlKey,h=o,d=a;if(l){const t=function(t){return 0===t.length?null:1===t.length?t[0].bounds:_s(t.map(t=>t.bounds))}(r);if(t){const e=c.calculateSnap(t,o,a,this.snapThreshold);o=e.dx,a=e.dy;const n=Hu(i);n&&(n.snapResult=e.guides.length>0?e:null)}}else{const t=Hu(i);t&&(t.snapResult=null)}r.forEach(t=>{t.move({x:o,y:a},1===r.length)}),this.last_pos={x:s.x-(h-o),y:s.y-(d-a)},Yu(i,r)},dragend:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const r=i.selected;if(0==r.length)return;const s=r[0].parent,o=i.focused||e.deliverer;if(this.changes&&!o.isGroup())if(i.hasSameParentForAllSelected&&o&&o!==s){const t=this.changes.map(t=>{const{component:e}=t;return{component:e,to_container:o}});i.app.commander.execute(new bl({changes:t}))}else il.after(this.changes,i.app.commander);else if(this.duplicates){this.duplicates=this.duplicates.map(t=>(t.to_container=o,t));const t=new bl({changes:this.duplicates});i.app.commander.execute(t)}r.forEach(t=>{t.parent&&t.parent.calculateBounds&&t.parent.calculateBounds()}),this.last_pos=null,this.changes=null,this.duplicates=null,this.snapIndex=null,this.snapThreshold=5;const a=Hu(i);a&&a.clear(),Yu(i,r,!0)}}},"(root)":{"(self)":{keydown:function(t,e){const{origin:n,deliverer:i}=e,r={},s=t.shiftKey?n.rootModel.MPP:1;switch(t.which){case 37:r.x=-s,r.y=0;break;case 38:r.x=0,r.y=-s;break;case 39:r.x=s,r.y=0;break;case 40:r.x=0,r.y=s;break;default:return}const o=i.selected;il.around(i.app.commander,function(){o.forEach(t=>{!t.stuck&&t.move(r,!1)})})}}}}),Fu.register("shift-handler",{"model-layer":{"(all)":{dragstart:function(t,e){Vu={x:t.offsetX,y:t.offsetY}},dragmove:function(t,e){const{deliverer:n}=e,i=t.offsetX,r=t.offsetY;n.rootModel.move({x:i-Vu.x,y:r-Vu.y},!1),Vu={x:i,y:r}}}}}),Fu.register("zoom-handler",{"model-layer":{"(all)":{wheel:function(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer,i=t.deltaY<0?1:-1,r=n.get("scale")||{x:1,y:1},s=n.get("translate"),o=t.offsetX,a=t.offsetY,c=n.toLocal(o,a),l=.1*i,h={x:r.x+l,y:r.y+l};if(i<0&&r.x<.2||i>0&&r.x>10)return;n.set("scale",h);const d=n.toLocal(o,a);n.set("translate",{x:s.x+(d.x-c.x)*h.x,y:s.y+(d.y-c.y)*h.y})}},"(self)":{dblclick:function(t,e){const n=e.origin;n?.root.fit()}}}});let Gu={},Uu={};function Wu(t){const e={};for(const n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}Fu.register("paste-handler",{"(root)":{"(self)":{stylepastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{fillStyle:e,strokeStyle:r,alpha:s,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:g,textBaseline:m,textOverflow:y,paddingTop:b,paddingBottom:v,paddingLeft:_,paddingRight:x}=t.state;Gu=Jn({fillStyle:e,strokeStyle:r,alpha:s,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:g,textBaseline:m,textOverflow:y,paddingTop:b,paddingBottom:v,paddingLeft:_,paddingRight:x}),n.mode=4}},stylepastestop:function(t){const{deliverer:e}=t,n=e.app;Gu={},4==n.mode&&(n.mode=1)},databindpastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{mappings:e}=t.state;Uu=Jn({mappings:e}),n.mode=5}},databindpastestop:function(t){const{deliverer:e}=t,n=e.app;Uu={},5==n.mode&&(n.mode=1)},pasteapply:function(t,e){const{deliverer:n}=e,i=n.app;t&&(4==i.mode?il.around(i.commander,()=>{t.set(Wu({...t.model,...Gu}))}):5==i.mode&&il.around(i.commander,()=>{t.set(Wu({...t.model,...Uu}))}))},keydown:function(t,e){const{deliverer:n}=e;"Esc"!=t.code&&"Escape"!=t.code||(4==n.app.mode?n.trigger("stylepastestop"):5==n.app.mode&&n.trigger("databindpastestop"))}}},"model-layer":{"(all)":{click:function(t,e){const{deliverer:n}=e,i=n.app;if(4!=i.mode&&5!=i.mode)return;const r=e.origin;4==i.mode?r===n?n.root.trigger("stylepastestop"):r&&il.around(i.commander,()=>{const t=Wu({...r.model,...Gu});r?.set(t)}):r===n?n.root.trigger("databindpastestop"):r&&il.around(i.commander,()=>{const t=Wu({...r.model,...Uu});r?.set(t)})}}}});class Xu{constructor(){this.animatorMap=new Map}waypoint(t,e){this.animatorMap.has(t)&&this.off(t);let{from:n,to:i}=e;if("string"==typeof n&&(n=t.root?.findById(n)),"string"==typeof i&&(i=t.root.findById(i)),!i)return void $i("WaypointAnimation: Source or target component not found");const r=aa(t,{type:"waypoint",fromComponent:n,toComponent:i,...e,onComplete:()=>{this.off(t)}});r&&(this.animatorMap.set(t,r),r.start())}off(t){const e=this.animatorMap.get(t);e&&(e.stop(),this.animatorMap.delete(t))}reset(t){if(this.animatorMap.size>0){for(const t of this.animatorMap.values())t.stop();this.animatorMap.clear()}}dispose(){this.reset(null),this.animatorMap=null}}function qu(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?.reset()}Fu.register("waypoint-handler",{"model-layer":{"(descendant)":{waypoint:function(t,e){const{origin:n}=e,i=n.root;let{waypointHandler:r}=i;r||(r=new Xu,i.waypointHandler=r),r.waypoint(n,t)},waypointoff:function(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?i.off(e):$i("waypoint-handler not found")},waypointreset:qu},"(self)":{waypointreset:qu}}},function(t){const{waypointHandler:e}=t;e&&(e.dispose(),delete t.waypointHandler)});class Ku{constructor(){this.animatorMap=new Map}transition(t,e){this.animatorMap.has(t)&&this.off(t);const n=aa(t,{type:"transition",fromComponent:e.from,toComponent:e.to,...e,onComplete:()=>{this.off(t)}});n&&(this.animatorMap.set(t,n),n.start())}off(t){const e=this.animatorMap.get(t);e&&(e.stop(),this.animatorMap.delete(t))}reset(){for(const t of this.animatorMap.values())t.stop();this.animatorMap.clear()}dispose(){this.reset(),this.animatorMap=null}}function $u(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?.reset()}function Qu(t){return t<.5?2*t*t:1-2*(1-t)*(1-t)}Fu.register("transition-handler",{"model-layer":{"(descendant)":{transition:function(t,e){const{origin:n}=e,i=n.root;let{transitionHandler:r}=i;r||(r=new Ku,i.transitionHandler=r),r.transition(n,t)},transitionoff:function(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?i.off(e):$i("transition-handler not found")},transitionreset:$u},"(self)":{transitionreset:$u}}},function(t){const{transitionHandler:e}=t;e&&(e.dispose(),delete t.transitionHandler)});class Zu{constructor(t){this.active=new Map,this.rafId=0,this._canvas=null,this._ctx=null,this.root=t}isReparenting(t){return this.active.has(t)}getState(t){return this.active.get(t)||null}begin(t,e){if(this.cancel(t),this.root?.app?.suppressAnimations)return this.cleanup3D(t),t.clearCache?.(),void t.invalidate?.();const n={fromWorld:e.fromWorld,toWorld:e.toWorld,from3D:e.from3D,to3D:e.to3D,duration:Math.max(e.duration,1),startTime:performance.now(),progress:0};if(this.active.set(t,n),n.fromWorld&&this.ensureCanvas(),n.from3D){const e=t._realObject?.object3d;if(e){e.position.copy(n.from3D.pos),e.quaternion.copy(n.from3D.quat);const t=n.from3D.fromScale;t&&e.scale.set(t.x,t.y,t.z)}}this.startLoop()}cancel(t){this.active.has(t)&&this.complete(t)}renderComponent(t,e){const n=this.active.get(t);if(!n?.fromWorld||!n?.toWorld||!this._ctx)return;const i=this._ctx,r=n.progress,s=n.fromWorld,o=n.toWorld,a=s.x+(o.x-s.x)*r,c=s.y+(o.y-s.y)*r,l=s.rotation+(o.rotation-s.rotation)*r,h=s.width+(o.width-s.width)*r,d=s.height+(o.height-s.height)*r,{translate:u={x:0,y:0},scale:p={x:1,y:1}}=e.model;i.save(),i.translate(u.x,u.y),i.scale(p.x,p.y),i.translate(a,c),i.rotate(l);const f=t.bounds;if(f&&f.width&&f.height){const t=h/f.width,e=d/f.height;i.scale(t,e),i.translate(-(f.left+f.width/2),-(f.top+f.height/2))}t.render(i),i.restore()}beginDraw(){if(!this._canvas||!this._ctx)return;this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._ctx.save();const t=globalThis.devicePixelRatio||1;this._ctx.scale(t,t)}endDraw(){this._ctx&&this._ctx.restore()}resize(){if(!this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element.clientWidth,n=t.element.clientHeight;t.fitSize(this._canvas,!0,e,n)}dispose(){for(const[t]of this.active)this.cleanup3D(t);this.active.clear(),this.stopLoop(),this.removeCanvas()}ensureCanvas(){if(this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element;this._canvas=document.createElement("canvas"),this._canvas.width=1,this._canvas.height=1,this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.style.zIndex="50",this._canvas.setAttribute("scene","transition-canvas"),e.appendChild(this._canvas);const n=e.clientWidth,i=e.clientHeight;t.fitSize(this._canvas,!0,n,i),this._ctx=this._canvas.getContext("2d")}removeCanvas(){this._canvas&&(this._canvas.parentNode?.removeChild(this._canvas),this._canvas=null,this._ctx=null)}startLoop(){if(this.rafId)return;const t=()=>{this.tick(),this.active.size>0?this.rafId=requestAnimationFrame(t):this.rafId=0};this.rafId=requestAnimationFrame(t)}stopLoop(){this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=0)}tick(){if(this.root?.app?.suppressAnimations){const t=[...this.active.keys()];for(const e of t)this.complete(e);return}const t=performance.now(),e=[];for(const[n,i]of this.active){const r=t-i.startTime,s=Math.min(r/i.duration,1),o=Qu(s);if(i.progress=o,i.from3D&&i.to3D){const t=n._realObject?.object3d;if(t){t.position.lerpVectors(i.from3D.pos,i.to3D.pos,o),t.quaternion.copy(i.from3D.quat).slerp(i.to3D.quat,o);const e=i.from3D.fromScale,n=i.from3D.toScale;e&&n&&t.scale.set(e.x+(n.x-e.x)*o,e.y+(n.y-e.y)*o,e.z+(n.z-e.z)*o)}}n.clearCache?.(),n.invalidate?.(),s>=1&&e.push(n)}for(const t of e)this.complete(t)}complete(t){this.active.get(t),this.cleanup3D(t),this.active.delete(t),t.clearCache?.(),t.invalidate?.();let e=!1;for(const[,t]of this.active)if(t.fromWorld){e=!0;break}e||this.removeCanvas()}cleanup3D(t){const e=t._realObject;e&&(e.object3d&&e.object3d.scale.set(1,1,1),e.suppressTransform=!1,e.update?.())}}const Ju=[],tp=di(function(){Ju.forEach(t=>{t.resize()})},100);"undefined"!=typeof window&&window.addEventListener("resize",tp);class ep extends Fc{constructor(t,e){super(Object.assign({type:"root",scale:{x:1,y:1}},t||{}),e),this._hasSameParentForAllSelected=!1,this._maxRefid=e?.isViewMode?1e6:0,t=t||{},this.fitMode=t.model&&t.model.fitMode,this._app=e,this.style=t.style,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={},this._serviceMap=new Map,this.transitionEffect=new Zu(this),this.target_element=t.target_element,this.rebuildContentModel(this.model.model),Ju.push(this)}registerService(t,e){this._serviceMap.set(t,e)}getService(t){return this._serviceMap.get(t)}unregisterService(t){this._serviceMap.delete(t)}dispose(){Ic.hideAll(this),this.transitionEffect?.dispose(),this._app&&this._app.dispose(),super.dispose(),this._disposeAllResources(),this.target_element=null,this._refresh_mapping_debouncer&&"function"==typeof this._refresh_mapping_debouncer.cancel&&this._refresh_mapping_debouncer.cancel(),delete this._refresh_mapping_debouncer;const t=Ju.indexOf(this);t>=0&&Ju.splice(t,1),this.refidIndexMap.clear(),this.indexMap.clear(),this._serviceMap.clear(),this._maxRefid=0}isRoot(){return!0}get app(){return this._app}get target_element(){return this._target_element}set target_element(t){this._ua_event_handler&&(this._ua_event_handler.dispose(),delete this._ua_event_handler),t&&(t.style.position="absolute",t.style.cursor="default",t.style.overflow="hidden",t.setAttribute("scene","root-container"),this._ua_event_handler=new Ou(this,t)),this.forEach(e=>e.target=t),this._target_element=t}get fitMode(){return this._fitMode}set fitMode(t){this._fitMode=t}get hasSameParentForAllSelected(){return this._hasSameParentForAllSelected}set hasSameParentForAllSelected(t){this._hasSameParentForAllSelected=t}get unitScale(){switch(this.model_layer&&this.model_layer.get("unit")){case"mm":case"cm":case"in":return this.app.PPM/10;default:return 1}}addTemplate(t,e){const n=this.templateMap[t];n&&Ki("Template replaced (duplicated)",t,e,n),this.templateMap[t]=e,delete this.templatePrefixes}removeTemplate(t,e){const n=this.templateMap[t];n!==e?$i("Removing template failed (different)",t,e,n):delete this.templateMap[t],delete this.templatePrefixes}findTemplateFor(t){this.templatePrefixes||(this.templatePrefixes=Object.keys(this.templateMap).sort().reverse());const e=this.templatePrefixes.find(e=>t.startsWith(e));if(e)return this.templateMap[e]}addIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);i?i.push(e):this.indexMap.set(n,[e])}removeIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);if(!i)return;const r=i.indexOf(e);-1===r?$i("Removing index failed (not found)",t,e):(i.splice(r,1),0===i.length&&this.indexMap.delete(n))}addRefidIndex(t,e){null==t&&(t=this.getNewRefid(),e.set("refid",t)),this._maxRefid=Math.max(t,this._maxRefid);const n=this.refidIndexMap.get(t);n&&Ki("Refid Index replaced (has not to be)",t,e,n),this.refidIndexMap.set(t,e)}removeRefidIndex(t,e){if(null==t)return;const n=this.refidIndexMap.get(t);n!==e?Ki("Refid Removing index failed (has not to be)",t,e,n):this.refidIndexMap.delete(t)}getNewRefid(){return this._maxRefid=(this._maxRefid||0)+1,this._maxRefid}async subscribe(t,e){this._app.isViewMode&&t&&this._app&&(e._subscription=await this._app.subscribe(t,e))}async unsubscribe(t,e){e._subscription&&(await e._subscription.unsubscribe(),delete e._subscription)}findById(t){if(!t)return null;const e=this.indexMap.get("#"===t[0]?t.substring(1):t);return e?e[0]:null}findAllById(t){return t&&this.indexMap.get("#"===t[0]?t.substring(1):t)||ep.EMPTY_ARRAY}findByRefid(t){return this.refidIndexMap.get(t)}findOrCreate(t){const e=this.findAllById(t);if(!e||0===e.length){if(this.app&&!this.app.isEditMode){const e=this.findTemplateFor(t);if(e){const n=xl(Object.assign(Jn(e.hierarchy),{id:t,templatePrefix:""}),this.app);return this.model_layer.addComponent(n),[n]}}return[]}return e}resize(){this.components.forEach(t=>{t.resize&&t.resize()}),this.invalidate()}fit(t){const{width:e,height:n,fitMode:i}=this.model_layer.model,r=this.target_element,s=this.model_layer;if(this.fitMode=t||this.fitMode||i||"ratio",e&&n&&r&&r.clientWidth&&r.clientHeight){switch(this.fitMode){case"center":!function(t,e,n){const i=t.unitScale,{width:r,height:s}=e.model;e.set("scale",{x:i,y:i}),e.set("translate",{x:Math.max((n.clientWidth-r*i)/2,0),y:Math.max((n.clientHeight-s*i)/2,0)})}(this,s,r);break;case"both":!function(t,e,n){const{width:i,height:r}=e.model,s=n.clientWidth,o=n.clientHeight;e.set("scale",{x:s/i,y:o/r}),e.set("translate",{x:0,y:0})}(0,s,r);break;case"width":!function(t,e,n){const i=n.clientWidth/e.get("width");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,s,r);break;case"height":!function(t,e,n){const i=n.clientHeight/e.get("height");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,s,r);break;case"ratio":!function(t,e,n){const{width:i,height:r}=e.model,s=n.clientWidth,o=n.clientHeight,a=s/i,c=o/r,l=Math.min(a,c);e.set("scale",{x:l,y:l}),e.set("translate",{x:(s-i*l)/2,y:(o-r*l)/2})}(0,s,r);break;default:!function(t,e){const n=t.unitScale;e.set("scale",{x:n,y:n}),e.set("translate",{x:0,y:0})}(this,s)}this.resize()}}_disposeAllResources(){this.selected=[],this._focused=null,this._ready=!1,this.eventEngine&&(this.assist_handlers&&this.assist_handlers.forEach(t=>{this.eventEngine.remove(t)}),this.eventEngine.dispose(),delete this.eventEngine),(this.model.handlers||[]).map(t=>{Fu.getDisposer(t).call(null,this)}),this.assist_layers&&this.assist_layers.forEach(t=>{t.dispose(),this.removeComponent(t)}),delete this.assist_layers,this.model_layer&&this.model_layer.dispose(),this.model_layer&&this.removeComponent(this.model_layer),delete this.model_layer,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={}}rebuildContentModel(t,e){let n,i;if(e?.preserveThreeD&&this.model_layer?.is3dMode){const t=this.model_layer._threeCapability;t&&(i=t.captureSessionState()),n=this.model_layer.detachThreeCapability()}this._disposeAllResources(),this.eventEngine=new xu(this);const r=this._app?.loadTracker;(t=t||{}).type="model-layer",t.dataLagMonitor&&this._app&&this._app.initLagTracker(t.dataLagMonitor),r?.setPhase("compile"),this.model_layer=xl(t,this.app),this.addComponent(this.model_layer),this.model_layer.target=this.target_element,this.assist_layers=(this.model.layers||[]).map(t=>{const e=xl(t,this.app);if(e)return this.addComponent(e),e.target=this.target_element,e;Ki("Layer compile failed",t)}).filter(Boolean),this.assist_handlers=(this.model.handlers||[]).map(t=>{const e={};return this.eventEngine.add(e,Fu.get(t)),e}),n&&(this.model_layer?.model?.threed?(this.model_layer.adoptThreeCapability(n),i&&n.restoreSessionState(i)):n.dispose()),r?.setPhase("assets"),this._ready=!0,this.traverse(t=>t.ready()),r?.checkComplete(),r?.startGlobalTimeout()}get root(){return this}get anchors(){return[]}get isReady(){return this._ready}get rootModel(){return this.model_layer}get threed(){return this.model_layer?.model?.threed||!1}set threed(t){this.model_layer&&this.model_layer.toggleThreeD(t)}get stuck(){return!0}get data(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].data);return t}set data(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.data=t[e])}}get dataByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.data;return t}set dataByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.data=t[e])}}get values(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].value);return t}set values(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.value=t[e])}}get valuesByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.value;return t}set valuesByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.value=t[e])}}get selected(){return(this._selected||[]).filter(t=>t.parent)}set selected(t){const e=this._selected;if(this._selected=t,!t||t.length<=1)this.hasSameParentForAllSelected=!0;else{const e=t[0].parent;this.hasSameParentForAllSelected=!t.find(t=>t.parent!=e)}this.trigger("selected",t,e)}get focused(){return this._focused}set focused(t){this._focused!==t&&(this._focused=t,this.invalidate())}get style(){return this._style}set style(t){this._style=t,this._compiled_style=t}get hasTextProperty(){return!1}render(){this.components.forEach(t=>t.draw())}contains(t,e){return!0}capturePath(t,e){return this.model_layer.capturePath(t,e)}invalidate(){this.components.forEach(t=>t.invalidate())}_areAliasesEqual(t,e){if(!Array.isArray(t)&&!Array.isArray(e))return!0;if(!Array.isArray(t)||!Array.isArray(e))return!1;if(t.length!==e.length)return!1;const n=[...t].sort(),i=[...e].sort();return n.every((t,e)=>t===i[e])}get eventMap(){return{"(root)":{"(descendant)":{added:this.onadded,removed:this.onremoved,change:this.onchanged}}}}refreshMappings(){if(!this._refresh_mapping_debouncer){if(this.disposed)return;this._refresh_mapping_debouncer=di(function t(e){e.executeMappings(),e.components&&e.components.forEach(e=>t(e))},1e3)}this._refresh_mapping_debouncer(this.model_layer)}_addTraverse(t){t.components&&t.components.forEach(t=>this._addTraverse(t));const{id:e,alias:n,refid:i,tag:r,templatePrefix:s}=t.model;this.addRefidIndex(i,t),e&&this.addIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.addIndex(e,t)}),r&&this.subscribe(r,t),s&&this.addTemplate(s,t);const o=bi({},t.eventMap,t.model.eventMap);this.eventEngine.add(t,o)}_removeTraverse(t){t.components&&t.components.forEach(t=>this._removeTraverse(t));const{id:e,alias:n,refid:i,tag:r,templatePrefix:s}=t.model;this.removeRefidIndex(i,t),e&&this.removeIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.removeIndex(e,t)}),r&&this.unsubscribe(r,t),s&&this.removeTemplate(s,t),this.eventEngine.remove(t)}onadded(t,e){this._addTraverse(e),e._silentAdd||this.refreshMappings(),this.invalidate()}onremoved(t,e){this._removeTraverse(e),this.invalidate()}onchanged(t,e,n){e.templatePrefix&&this.removeTemplate(e.templatePrefix,n.origin),t.templatePrefix&&this.addTemplate(t.templatePrefix,n.origin),e.id&&this.removeIndex(e.id,n.origin),t.id&&this.addIndex(t.id,n.origin),Array.isArray(e.alias)&&e.alias.forEach(t=>{t&&this.removeIndex(t,n.origin)}),Array.isArray(t.alias)&&t.alias.forEach(t=>{t&&this.addIndex(t,n.origin)}),e.tag&&this.unsubscribe(e.tag,n.origin),t.tag&&this.subscribe(t.tag,n.origin),e.id==t.id&&e.class==t.class&&this._areAliasesEqual(e.alias,t.alias)||n.origin._silentAdd||this.refreshMappings()}}ep.EMPTY_ARRAY=[],cc.memoize(ep.prototype,"unitScale",!1);const np=60;class ip{constructor(){this._monitors=new Map,this._disposed=!1}configure(t){const e=Array.isArray(t)?t:[t];for(const t of e)this._monitors.set(t.tag,{config:{...t,warnThreshold:t.warnThreshold??5e3,criticalThreshold:t.criticalThreshold??15e3},fieldKeys:t.timestampField.split("."),samples:new Float64Array(np),writeIdx:0,count:0,baseline:0,baselineSet:!1,baselineSum:0,baselineCount:0,lastLevel:"normal"})}isMonitored(t){return this._monitors.has(t)}recordIfMonitored(t,e){if(this._disposed)return;const n=this._monitors.get(t);if(!n||!e)return;const i=this._extractField(e,n.fieldKeys);if("number"!=typeof i||i<=0)return;const r=Date.now()-i;n.samples[n.writeIdx]=r,n.writeIdx=(n.writeIdx+1)%np,n.count<np&&n.count++,n.baselineSet||(n.baselineSum+=r,n.baselineCount++,n.baselineCount>=5&&(n.baseline=n.baselineSum/n.baselineCount,n.baselineSet=!0))}getStats(t){const e=this._monitors.get(t);if(!e)return null;const{count:n,baseline:i,baselineSet:r}=e;if(0===n)return{tag:t,currentDelta:0,baseline:0,drift:0,driftAvg:0,driftMax:0,trend:"stable",sampleCount:0,level:"normal"};const s=(e.writeIdx-1+np)%np,o=e.samples[s],a=r?o-i:0;let c=0,l=0;const h=this._getRecentDrifts(e);for(const t of h)c+=t,Math.abs(t)>Math.abs(l)&&(l=t);return{tag:t,currentDelta:o,baseline:i,drift:a,driftAvg:h.length>0?c/h.length:0,driftMax:l,trend:this._calcTrend(e),sampleCount:n,level:this._calcLevel(Math.abs(a),e.config)}}getAllStats(){const t=[];for(const e of this._monitors.keys()){const n=this.getStats(e);n&&t.push(n)}return t}evaluateAll(){if(!this._disposed)for(const[t,e]of this._monitors.entries()){const n=this.getStats(t);n&&(n.level!==e.lastLevel&&(e.lastLevel=n.level,this.onLevelChange?.(t,n.level,n)))}}dispose(){this._disposed=!0,this._monitors.clear(),this.onLevelChange=void 0}_extractField(t,e){let n=t;for(const t of e){if(null==n)return;n=n[t]}return n}_getRecentDrifts(t){if(!t.baselineSet||0===t.count)return[];const e=Math.min(t.count,10),n=[];for(let i=0;i<e;i++){const e=(t.writeIdx-1-i+np)%np;n.push(t.samples[e]-t.baseline)}return n.reverse()}_calcTrend(t){if(!t.baselineSet)return"stable";const e=this._getRecentDrifts(t),n=e.length;if(n<3)return"stable";let i=0,r=0,s=0,o=0;for(let t=0;t<n;t++)i+=t,r+=e[t],s+=t*e[t],o+=t*t;const a=(n*s-i*r)/(n*o-i*i),c=r/n,l=e.map(Math.abs),h=l.reduce((t,e)=>t+e,0)/n;if(h>0&&l[n-1]>3*h)return"spike";const d=Math.max(.1*Math.abs(c),50);return a>d?"increasing":a<-d?"decreasing":"stable"}_calcLevel(t,e){return t>=(e.criticalThreshold??15e3)?"critical":t>=(e.warnThreshold??5e3)?"warn":"normal"}}const rp=5e3;class sp{constructor(t){this._entries=new Map,this._phase="fetch",this._phaseHistory=[],this._disposed=!1,this.needsOverlay=!1,this._firstRenderDone=!1,this._options=t||{},this._startTime=performance.now(),this._promise=new Promise(t=>{this._promiseResolve=t}),this._phaseHistory.push({phase:"fetch",timestamp:this._startTime,elapsed:0}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},rp)}get phase(){return this._phase}get phaseHistory(){return this._phaseHistory}get progress(){const t=this._entries.size;if(0===t)return 1;let e=0;for(const t of this._entries.values())"pending"!==t.status&&e++;return e/t}get pending(){const t=[],e=performance.now();for(const n of this._entries.values())"pending"===n.status&&t.push(this._toPublicEntry(n,e));return t}get entries(){const t=performance.now(),e=[];for(const n of this._entries.values())e.push(this._toPublicEntry(n,t));return e}get stats(){let t=0,e=0,n=0,i=0,r=0;for(const s of this._entries.values())switch(s.status){case"loaded":t++;break;case"timeout":e++;break;case"error":n++;break;case"cancelled":i++;break;case"pending":r++}return{total:this._entries.size,loaded:t,timeout:e,error:n,cancelled:i,pending:r,elapsed:this._completedElapsed??performance.now()-this._startTime}}get promise(){return this._promise}markFirstRender(){this._firstRenderDone||this._disposed||(this._firstRenderDone=!0,this.setPhase("render"),this.checkComplete())}setPhase(t){if(this._disposed||this._phase===t||"complete"===this._phase)return;const e=performance.now(),n=this._phaseHistory[this._phaseHistory.length-1];n&&void 0===n.duration&&(n.duration=e-n.timestamp),this._phase=t,"complete"!==t?(this._phaseHistory.push({phase:t,timestamp:e,elapsed:e-this._startTime}),this.onPhase?.(t)):this.onPhase?.(t)}track(t,e,n,i){if(this._disposed)return;const r={id:t,type:e,url:n,startTime:performance.now(),status:"pending"};this._entries.set(t,r),this._options.assetTimeout&&this._options.assetTimeout>0&&(r.timerId=setTimeout(()=>{"pending"===r.status&&(r.status="timeout",r.endTime=performance.now(),r.timerId&&(r.timerId=void 0),this.onTimeout?.(this._toPublicEntry(r)),this._onEntryDone())},this._options.assetTimeout)),i.then(()=>{"pending"===r.status&&(r.status="loaded",r.endTime=performance.now(),this._clearEntryTimer(r),this._onEntryDone())},()=>{"pending"===r.status&&(r.status="error",r.endTime=performance.now(),this._clearEntryTimer(r),this._onEntryDone())})}checkComplete(){if(this._disposed||"complete"===this._phase)return;let t=!1;for(const e of this._entries.values())if("pending"===e.status){t=!0;break}!t&&this._firstRenderDone&&this._doComplete()}startGlobalTimeout(){if(this._disposed)return;const t=this._options.timeout;!t||t<=0||(this._globalTimerId=setTimeout(()=>{if("complete"===this._phase||this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="timeout",e.endTime=t,this._clearEntryTimer(e),this.onTimeout?.(this._toPublicEntry(e)));this._doComplete(!0)},t))}abort(){if(this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="cancelled",e.endTime=t,this._clearEntryTimer(e));this._doComplete(!0)}reset(){for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._entries.clear(),this._phase="fetch",this._startTime=performance.now(),this._phaseHistory=[{phase:"fetch",timestamp:this._startTime,elapsed:0}],this._completedElapsed=void 0,this._firstRenderDone=!1,this.needsOverlay=!1,this._disposed=!1,this._promise=new Promise(t=>{this._promiseResolve=t}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},rp)}dispose(){if(!this._disposed){this._disposed=!0;for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._promiseResolve(),this.onPhase=void 0,this.onProgress=void 0,this.onTimeout=void 0,this.onComplete=void 0,this.onNeedsOverlay=void 0}}_onEntryDone(){this._disposed||(this.onProgress?.(this.stats),this.checkComplete())}_doComplete(t=!1){"complete"!==this._phase&&(this._completedElapsed=performance.now()-this._startTime,this._completedElapsed>rp&&(this.needsOverlay=!0),this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this.setPhase("complete"),this.onComplete?.(this.stats),this._promiseResolve())}_clearEntryTimer(t){t.timerId&&(clearTimeout(t.timerId),t.timerId=void 0)}_toPublicEntry(t,e){const n=t.endTime?t.endTime-t.startTime:(e??performance.now())-t.startTime;return{id:t.id,type:t.type,url:t.url,startTime:t.startTime,status:t.status,elapsed:n}}}let op=13.3;var ap=function(t){return void 0!==t&&(op=t),op};const cp="$base_url";const lp=Math.PI/12;class hp{constructor(t,e){this._postprocessing=!0,this._loadTrackerOwned=!1,this._suppressAnimationsFlag=!1,this._suppressScopeCount=0,this._mode=t,this.screen=ap(),this._baseUrl="undefined"!=typeof window?window.location.origin:null,this._refProvider=e,this.isEditMode&&(this._rotateStep=lp,this._rotateStepForced=!1)}initLoadTracker(t){return this._loadTracker=new sp(t),this._loadTrackerOwned=!0,this._loadTracker}get loadTracker(){return this._loadTracker}adoptLoadTracker(t){this._loadTracker=t,this._loadTrackerOwned=!1}initLagTracker(t){return this._lagTracker=new ip,this._lagTracker.configure(t),this._lagTracker}get lagTracker(){return this._lagTracker}dispose(){this._loadTrackerOwned&&this._loadTracker?.dispose(),this._loadTracker=void 0,this._lagTracker?.dispose(),this._lagTracker=void 0,this._dataSubscriptionProvider?.dispose?.(),delete this._dataStorage}_calcScreen(){const t={width:screen.width,height:screen.height};this._PPI=function(t,e,n,i="d"){t<=0&&(t=1),e<=0&&(e=1);const r=("d"===i?Math.sqrt(t*t+e*e):"w"===i?t:e)/n;return r>0?Math.round(r):0}(t.width,t.height,this.screen),this._PPM=this._PPI/25.4}subscribe(t,e){return this._dataSubscriptionProvider?.subscribe?.(t,e)}get refProvider(){return this._refProvider}set dataSubscriptionProvider(t){this._dataSubscriptionProvider=t}get dataSubscriptionProvider(){return this._dataSubscriptionProvider}set commander(t){this._commander=t}get commander(){return this._commander}get screen(){return this._screen}set screen(t){this._screen=t,this._calcScreen()}get DPPX(){return Hr}get PPI(){return this._PPI}get PPM(){return this._PPM}get mode(){return this._mode}set mode(t){const e=this._mode;e!==t&&(this._mode=t,this.trigger("mode",t,e))}get isViewMode(){return 0===this._mode}get isEditMode(){return 1===this._mode}get baseUrl(){return this._baseUrl}set baseUrl(t){t&&this._baseUrl!==t&&(this._baseUrl=t)}url(t){try{let e;return e=t.includes(cp)?new URL(t.replace(cp,this.baseUrl??""),this.baseUrl??void 0):new URL(t,location.origin),e.href}catch(e){$i(e,t)}}get rotateStep(){return this._rotateStep}set rotateStep(t){this._rotateStep=Number(t)||lp}get rotateStepForced(){return this._rotateStepForced}set rotateStepForced(t){this._rotateStepForced=!!t}get dataStorage(){return this._dataStorage}set dataStorage(t){this._dataStorage=t}get postprocessing(){return this._postprocessing}set postprocessing(t){this._postprocessing=t}get suppressAnimations(){return this._suppressAnimationsFlag||this._suppressScopeCount>0}set suppressAnimations(t){this._suppressAnimationsFlag=!!t}withSuppressedAnimations(t){let e;this._suppressScopeCount++;try{e=t()}catch(t){throw this._suppressScopeCount--,t}return e&&"function"==typeof e.then?e.finally(()=>{this._suppressScopeCount--}):(this._suppressScopeCount--,e)}beginSuppressAnimations(){this._suppressScopeCount++;let t=!1;return{end:()=>{t||(t=!0,this._suppressScopeCount--)}}}}qi(hp.prototype,Fi.withEvent);class dp{constructor(t,e){!(t=Number(t))||t<=0?(Ki("TimeCapsule maxsize should be greater than 0.",t),this.maxsize=10):this.maxsize=t,this.reset(),e&&(this.snapshot(e),this.preserve())}preserve(){this.checkPoint=this.pos}hasUnpreservedChanges(){return this.checkPoint!=this.pos}dispose(){this.reset()}snapshot(t){if(this.q.splice(this.pos+1,this.q.length-(this.pos+1),t),this.q.length>this.maxsize){const t=this.q.splice(0,this.q.length-this.maxsize);this.checkPoint=Math.max(-1,this.checkPoint-t.length)}this.pos=this.q.length-1}forward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.forwardable)return this.q[++this.pos];$i("Not forwardable.")}backward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.backwardable)return this.q[--this.pos];$i("Not backwardable.")}get current(){if(-1!==this.pos)return this.q[this.pos];$i("Non state has been recorded.")}get length(){return this.q.length}get forwardable(){return this.pos<this.q.length-1}get backwardable(){return this.pos>0}get snapshot_taker(){return this._snapshot_taker}set snapshot_taker(t){this._snapshot_taker=t}reset(){this.q=[],this.pos=-1,this.checkPoint=-1}}const up=di(t=>{t.brake||t.take()},1e3,{leading:!0,trailing:!1});function pp(t){!t.brake&&t.dirty&&up(t)}class fp{constructor(t,e){this._brake=!1,this.dirty=!1,this.brake=!1,this.dirty=!1,this.state_holder=t,this.timecapsule=e,this.timecapsule.snapshot_taker=this}dispose(){up.cancel(),this.state_holder=null,this.timecapsule=null}touch(){this.dirty=!0,pp(this)}take(t=!1){(this.dirty||t)&&(this.timecapsule.snapshot(this.state_holder.state),this.dirty=!1)}get brake(){return this._brake}set brake(t){this._brake=!!t,pp(this)}}function gp(t,e){const n=e.model_layer.get("scale"),i=e.model_layer.get("translate"),r=e.model_layer.is3dMode;if(t){const s=JSON.parse(t);s.scale=n,s.translate=i,s.threed=r,e.rebuildContentModel(s,{preserveThreeD:!0})}}class mp{constructor(t){this.container=t,this.timecapsule=new dp(20);const e=this;this.snapshot_taker=new fp({get state(){const t=e.container.model_layer.hierarchy;return JSON.stringify(t,ua)}},this.timecapsule),this.snapshot_taker.take(!0),this.timecapsule.preserve()}dispose(){this.reset(),this.timecapsule&&this.timecapsule.dispose(),this.snapshot_taker&&this.snapshot_taker.dispose(),delete this.container,delete this.timecapsule,delete this.snapshot_taker}preserve(){this.timecapsule.preserve()}hasUnpreservedChanges(){return this.timecapsule.hasUnpreservedChanges()}execute(t,e){!1!==e&&t&&t.execute(),this.snapshot_taker.touch(),this.trigger("execute",t,!0,!1)}undo(){this.timecapsule.backwardable&&(gp(this.timecapsule.backward(),this.container),this.trigger("undo",this.undoable(),this.redoable()))}redo(){this.timecapsule.forwardable&&(gp(this.timecapsule.forward(),this.container),this.trigger("redo",this.undoable(),this.redoable()))}undoable(){return this.timecapsule.backwardable}redoable(){return this.timecapsule.forwardable}reset(){this.timecapsule&&this.timecapsule.reset(),this.trigger("command-reset")}}qi(mp.prototype,Fi.withEvent);const yp=new class{constructor(){this._scenes=[],this.onSceneChange=null,this._watchedComponent=null,this._watchedHandler=null,this.onWatchedComponentChange=null}setWatchedComponent(t,e=0){if(this._clearWatched(),null==t)return!0;const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!r||"function"!=typeof r.on)return!1;const s=(e,n)=>{this.onWatchedComponentChange?.(t,e,n)};return r.on("change",s),this._watchedComponent=r,this._watchedHandler=s,!0}_clearWatched(){this._watchedComponent&&this._watchedHandler&&"function"==typeof this._watchedComponent.off&&this._watchedComponent.off("change",this._watchedHandler),this._watchedComponent=null,this._watchedHandler=null}register(t){this._cleanup(),this._scenes.push(new WeakRef(t)),this.onSceneChange?.(this._scenes.length)}unregister(t){this._clearWatched(),this._scenes=this._scenes.filter(e=>{const n=e.deref();return n&&n!==t}),this.onSceneChange?.(this._scenes.length)}getScenes(){return this._cleanup(),this._scenes.map((t,e)=>{const n=t.deref();if(!n)return null;const i=n.root,r=i?.model||{};return{index:e,model:{width:r.width||0,height:r.height||0,type:r.type||"unknown"}}}).filter(Boolean)}getComponentTree(t=0){const e=this._getScene(t);if(!e)return[];const n=e.rootContainer;if(!n)return[];const i=n.model_layer;return i?this._childrenOf(i):[]}getChildTree(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];let r;return r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),r?this._childrenOf(r):[]}getComponentInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const i=n.rootContainer;if(!i)return null;let r;if(r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),!r)return null;const s=this._safeBounds(r),o={model:this._safeClone(r.model),state:this._safeClone(r.state),nature:r.nature||{},data:this._safeValue(r.data),value:this._safeValue(r.value),bounds:s,type:r.model?.type||"unknown",isContainer:!!r.isContainer?.(),hidden:!!r.model?.hidden};return"model-layer"===r.model?.type&&(o.is3dMode=!!r.model?.threed),o}selectComponent(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;if(!t||"root"===t||"__root__"===t)return i.selected=[],!0;const r=this._findComponent(i,t);return!!r&&(i.selected=[r],!0)}setComponentProperty(t,e,n,i=0){const r=this._getScene(i);if(!r)return!1;const s=r.rootContainer;if(!s)return!1;let o;if(o="root"===t||"__root__"===t?s.model_layer:this._findComponent(s,t),!o)return!1;try{return o.set(e,n),!0}catch{return!1}}setCameraView(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const r=i.model_layer;if(!r||!r._threeCapability)return!1;try{return r._threeCapability.setCameraView(t),!0}catch{return!1}}getCameraState(t=0){const e=this._getScene(t);if(!e)return null;const n=e.rootContainer;if(!n)return null;const i=n.model_layer;if(!i||!i._threeCapability)return null;try{return i._threeCapability.getCameraState()}catch{return null}}toggleHidden(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const r=this._findComponent(i,t);if(!r)return!1;try{return r.set("hidden",!r.model?.hidden),!r.model?.hidden}catch{return!1}}evaluateData(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return r?this._safeValue(r.data):void 0}evaluateValue(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return r?this._safeValue(r.value):void 0}searchComponents(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const r=i.model_layer;if(!r)return[];const s=[],o=t.toLowerCase();return this._traverseComponent(r,t=>{const e=t.state||t.model||{};[e.type||"",e.name||"",e.id||"",e.tag||"",e.class||"",String(e.refid||"")].join(" ").toLowerCase().includes(o)&&s.push(this._toTreeNode(t))}),s}getComponentPath(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const r=i.model_layer;if(!r)return[];const s=[];return this._findPath(r,t,s)?s:[]}getThreedInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const i=n.rootContainer;if(!i)return null;let r;if(r="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),!r)return null;const s=r.model||{},o=s.type||"unknown",a=s.material3d,c={is3dish:"function"==typeof r.is3dish&&r.is3dish(),type:o};if(a&&(c.material3d=this._safeClone(a)),c.resolved=Lh(a),"gltf-object"===o)try{c.nodeNames=r.nodeNames??[],c.animationNames=r.animationNames??[],c.nodes=this._safeClone(r.nodes),c.animations=this._safeClone(r.animations),c.fillStyleTargets=r.fillStyleTargets}catch{}return c}_getScene(t){this._cleanup();const e=this._scenes[t];return e?.deref()??null}_cleanup(){this._scenes=this._scenes.filter(t=>void 0!==t.deref())}_findComponent(t,e){const n=Number(e);if(!isNaN(n)){const e=t.findByRefid(n);if(e)return e}const i=t.findById(e);return i||null}_childrenOf(t){const e=t.components;return e?e.map(t=>this._toTreeNode(t)):[]}_toTreeNode(t){const e=t.components,n=!!e&&e.length>0,i=t.state||t.model||{};return{id:String(i.refid??i.id??""),type:i.type||"unknown",model_id:i.id,hasChildren:n,childCount:n?e.length:0,refid:i.refid,tag:i.tag,name:i.name,hidden:!!i.hidden,clazz:i.class}}_componentId(t){const e=t.state||t.model||{};return String(e.refid??e.id??"")}_findPath(t,e,n){const i=this._componentId(t);if(i===e)return!0;const r=t.components;if(!r)return!1;for(const s of r)if(this._findPath(s,e,n))return n.unshift("model-layer"===t.model?.type?"__root__":i),!0;return!1}_traverseComponent(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverseComponent(t,e)}_safeBounds(t){try{const e=t.bounds;return e?{left:e.left??0,top:e.top??0,width:e.width??0,height:e.height??0}:null}catch{return null}}_safeClone(t){if(!t||"object"!=typeof t)return t??{};try{return JSON.parse(JSON.stringify(t))}catch{const e={};for(const n of Object.keys(t))try{const i=t[n];if("function"==typeof i)continue;e[n]="object"==typeof i?String(i):i}catch{e[n]="[error]"}return e}}_safeValue(t){if(null==t)return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}},bp={fetch:"Fetching model...",parse:"Parsing model...",init:"Initializing...",compile:"Building components...",assets:"Loading assets...",data:"Waiting for data...",render:"Rendering..."},vp={stable:"─",increasing:"▲",decreasing:"▼",spike:"⚡"},_p={normal:"rgba(100,200,100,0.9)",warn:"rgba(255,180,50,0.9)",critical:"rgba(255,80,80,0.9)"};class xp{constructor(){this._visible=!1,this._manualOpen=!1,this._phaseRenderedCount=0}attach(t,e,n){this._targetElement=t,this._tracker=e,this._lagTracker=n,this._phaseRenderedCount=0,this._visible=!1,this._phaseListEl&&(this._phaseListEl.innerHTML=""),this._pendingListEl&&(this._pendingListEl.innerHTML=""),e&&(e.needsOverlay&&this._show(),e.onNeedsOverlay=()=>{this._visible||this._manualOpen||this._show()},e.onComplete=()=>{this._visible&&(this._update(),this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3))})}toggle(){this._visible?(this._hide(),this._manualOpen=!1):(this._manualOpen=!0,this._show())}show(){this._manualOpen=!0,this._show()}hide(){this._manualOpen=!1,this._hide()}destroy(){this._hide(),this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._targetElement=void 0,this._tracker=void 0,this._lagTracker=void 0,this._phaseListEl=void 0}get isVisible(){return this._visible}get isAttached(){return!!this._targetElement}_show(){this._targetElement&&(this._container||this._buildDOM(),this._container&&!this._container.parentElement&&this._targetElement.appendChild(this._container),this._container.style.display="flex",this._visible=!0,this._update(),this._updateTimer||(this._updateTimer=setInterval(()=>this._update(),500)),"complete"!==this._tracker?.phase||this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3))}_hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._updateTimer&&(clearInterval(this._updateTimer),this._updateTimer=void 0)}_update(){if(!this._visible||!this._tracker)return;const t=this._tracker,e=t.stats,n=t.phase,i="complete"===n;this._headerEl&&(this._headerEl.textContent=i?`Scene Monitor — ${(e.elapsed/1e3).toFixed(1)}s`:`Scene Monitor — ${bp[n]||n}`),this._updateProgress(t,i),this._updatePhaseList(t),this._updateAssetList(t,e,i),this._updateLagDisplay(),this._elapsedEl&&(this._elapsedEl.textContent=`${(e.elapsed/1e3).toFixed(1)}s`)}_updateProgress(t,e){if(!this._progressFillEl&&!this._progressTextEl)return;const n=t.phaseHistory,i=n.length,r=n.filter(t=>void 0!==t.duration).length,s=i>0?Math.round(r/i*100):e?100:0;this._progressFillEl&&(this._progressFillEl.style.width=s+"%"),this._progressTextEl&&(this._progressTextEl.textContent=`${r} / ${i}`)}_updatePhaseList(t){if(!this._phaseListEl)return;const e=t.phaseHistory;for(let t=this._phaseRenderedCount;t<e.length;t++){const n=e[t];if("complete"===n.phase)continue;const i=150*(t-this._phaseRenderedCount),r=document.createElement("div");r.dataset.phase=n.phase,r.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px;opacity:0;transition:opacity 0.3s ease",r.innerHTML='<span data-field="icon" style="flex-shrink:0"></span><span data-field="label" style="flex:1"></span><span data-field="time" style="width:60px;text-align:right"></span>',this._phaseListEl.appendChild(r),setTimeout(()=>{r.style.opacity="1"},i+16)}this._phaseRenderedCount=e.length;const n=performance.now();for(const t of Array.from(this._phaseListEl.querySelectorAll("[data-phase]"))){const i=t,r=e.find(t=>t.phase===i.dataset.phase);if(!r)continue;const s=bp[r.phase]||r.phase,o=i.querySelector('[data-field="icon"]'),a=i.querySelector('[data-field="label"]'),c=i.querySelector('[data-field="time"]');void 0===r.duration?(o.textContent="⏳",o.style.color="rgba(255,200,50,0.8)",a.textContent=s,a.style.color="rgba(255,255,255,0.9)",c.textContent=`${((n-r.timestamp)/1e3).toFixed(1)}s`,c.style.color="rgba(255,200,50,0.8)"):(o.textContent="✓",o.style.color="rgba(100,200,100,0.8)",a.textContent=s,a.style.color="rgba(255,255,255,0.5)",c.textContent=`${(r.duration/1e3).toFixed(1)}s`,c.style.color="rgba(255,255,255,0.4)")}}_updateAssetList(t,e,n){if(this._pendingListEl)if(n&&"complete"!==this._pendingListEl.dataset.mode)this._pendingListEl.innerHTML="",this._pendingListEl.dataset.mode="complete",this._renderHistorySummary(e);else if(!n){this._pendingListEl.dataset.mode="pending";const e=t.pending.sort((t,e)=>e.elapsed-t.elapsed),n=e.slice(0,5);for(let t=0;t<n.length;t++)t<this._pendingListEl.children.length?this._updatePendingRow(this._pendingListEl.children[t],n[t]):this._pendingListEl.appendChild(this._createPendingRow(n[t]));const i=n.length+(e.length>5?1:0);for(;this._pendingListEl.children.length>i;)this._pendingListEl.lastChild?.remove();if(e.length>5){const t=this._pendingListEl.lastElementChild;if(t?.dataset?.more)t.textContent=`... ${e.length-5} more`;else{const t=document.createElement("div");t.dataset.more="1",t.style.cssText="color:rgba(255,255,255,0.4);font-size:11px;padding:2px 0",t.textContent=`... ${e.length-5} more`,this._pendingListEl.appendChild(t)}}}}_updateLagDisplay(){if(!this._lagSectionEl||!this._lagTracker)return;this._lagTracker.evaluateAll();const t=this._lagTracker.getAllStats();0!==t.length&&(this._lagSectionEl.dataset.built?this._updateLagSection(t):(this._lagSectionEl.innerHTML="",this._renderLagSection(t),this._lagSectionEl.dataset.built="1"))}_renderHistorySummary(t){if(!this._pendingListEl)return;const e=document.createElement("div");e.style.cssText="color:rgba(255,255,255,0.7);padding:2px 0;font-size:12px",e.textContent=`Total: ${t.total} assets | Loaded: ${t.loaded} | Timeout: ${t.timeout} | Error: ${t.error}`,this._pendingListEl.appendChild(e);const n=this._tracker.entries.filter(t=>"pending"!==t.status).sort((t,e)=>e.elapsed-t.elapsed).slice(0,5);for(const t of n){const e=document.createElement("div");e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px";const n="loaded"===t.status?"✓":"timeout"===t.status?"⚠":"✗",i="loaded"===t.status?"rgba(100,200,100,0.8)":"timeout"===t.status?"rgba(255,180,50,0.8)":"rgba(255,80,80,0.8)";e.innerHTML=`<span style="color:${i}">${n}</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,this._pendingListEl.appendChild(e)}}_renderLagSection(t){if(!this._lagSectionEl)return;const e=document.createElement("div");e.style.cssText="color:rgba(255,255,255,0.5);font-size:11px;padding:4px 0 2px;border-top:1px solid rgba(255,255,255,0.08);margin-top:4px",e.textContent="Data Lag",this._lagSectionEl.appendChild(e);for(const e of t){const t=document.createElement("div");t.dataset.tag=e.tag,t.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px";const n=_p[e.level],i=vp[e.trend];t.innerHTML=`<span style="color:rgba(255,255,255,0.7);flex:1">${e.tag}</span><span data-field="drift" style="color:rgba(255,255,255,0.6)">drift: ${e.drift>=0?"+":""}${(e.drift/1e3).toFixed(1)}s</span><span style="color:rgba(255,255,255,0.4)">base: ${(e.baseline/1e3).toFixed(1)}s</span><span data-field="trend" style="color:${n}">${i}</span>`,this._lagSectionEl.appendChild(t)}}_createPendingRow(t){const e=document.createElement("div");return e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px",e.dataset.id=t.id,e.innerHTML=`<span style="color:rgba(255,200,50,0.7)">⏳</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span data-field="url" style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span data-field="time" style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,e}_updatePendingRow(t,e){const n=t.querySelector('[data-field="url"]'),i=t.querySelector('[data-field="time"]');n&&(n.textContent=this._shortUrl(e.url)),i&&(i.textContent=`${(e.elapsed/1e3).toFixed(1)}s`)}_updateLagSection(t){if(!this._lagSectionEl)return;const e=this._lagSectionEl.querySelectorAll("[data-tag]");for(const n of t){const t=Array.from(e).find(t=>t.dataset.tag===n.tag);if(t){const e=t.querySelector('[data-field="drift"]'),i=t.querySelector('[data-field="trend"]');e&&(e.textContent=`drift: ${n.drift>=0?"+":""}${(n.drift/1e3).toFixed(1)}s`),i&&(i.textContent=vp[n.trend],i.style.color=_p[n.level])}}}_shortUrl(t){if(!t)return"";const e=t.split("/");return e[e.length-1]||t}_buildDOM(){const t=document.createElement("div");t.setAttribute("scene","loading-overlay"),t.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none","z-index:9999",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:320px","max-width:450px","padding:12px 16px","gap:8px"].join(";");const e=document.createElement("div");e.style.cssText="display:flex;align-items:center;justify-content:space-between";const n=document.createElement("span");n.style.cssText="font-weight:600;font-size:13px",n.textContent="Loading...",this._headerEl=n,e.appendChild(n);const i=document.createElement("button");i.textContent="✕",i.title="Close",i.style.cssText="background:none;border:none;color:rgba(255,255,255,0.6);cursor:pointer;font-size:14px;padding:2px 4px;border-radius:3px;line-height:1",i.addEventListener("mouseenter",()=>{i.style.color="rgba(255,255,255,0.9)"}),i.addEventListener("mouseleave",()=>{i.style.color="rgba(255,255,255,0.6)"}),i.addEventListener("click",()=>this.hide()),e.appendChild(i),t.appendChild(e);const r=document.createElement("div");r.style.cssText="display:flex;align-items:center;gap:8px";const s=document.createElement("div");s.style.cssText="flex:1;height:4px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden";const o=document.createElement("div");o.style.cssText="height:100%;width:0%;background:rgba(74,158,255,0.8);border-radius:2px;transition:width 0.3s ease",this._progressFillEl=o,s.appendChild(o),r.appendChild(s);const a=document.createElement("span");a.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;min-width:80px;text-align:right",this._progressTextEl=a,r.appendChild(a),t.appendChild(r);const c=document.createElement("div");c.style.cssText="border-top:1px solid rgba(255,255,255,0.08);padding-top:4px",this._phaseListEl=c,t.appendChild(c);const l=document.createElement("div");l.style.cssText="max-height:120px;overflow-y:auto",this._pendingListEl=l,t.appendChild(l);const h=document.createElement("div");this._lagSectionEl=h,t.appendChild(h);const d=document.createElement("div");d.style.cssText="display:flex;align-items:center;border-top:1px solid rgba(255,255,255,0.08);padding-top:8px";const u=document.createElement("span");u.style.cssText="font-size:11px;color:rgba(255,255,255,0.4)",this._elapsedEl=u,d.appendChild(u),t.appendChild(d),t.addEventListener("keydown",t=>t.stopPropagation()),this._container=t}}class wp extends Uh{constructor(){super(...arguments),this._loadGen=0,this._objectSize=new e.Vector3}get objectSize(){return this._objectSize}build(){super.build();const{src:t}=this.component.state;if(!t)return this.clear(),this._showEmptyPlaceholder(),void(this.object3d.userData.context=this);const e=++this._loadGen,n=this.component.app.url(t),i=this._loadExternal(n).then(t=>{e===this._loadGen&&this._onLoaded(t)},t=>{e===this._loadGen&&(Ki(`${this._formatLabel}.load`,t),this.clear(),this._showErrorPlaceholder(),this.component.setState({loadError:String(t)}))});this.component.root?.app?.loadTracker?.track(`${this._formatLabel}:${t}`,this._formatLabel,t,i)}updateSource(){this.build()}get _placeholderColor(){return 6770852}_showEmptyPlaceholder(){const{width:t=100,height:n=100,depth:i=100}=this.component.state,r=t||100,s=n||100,o=i||100,a=this._placeholderColor,c=new e.BoxGeometry(r,o,s),l=new e.MeshStandardMaterial({color:a,transparent:!0,opacity:.15,depthWrite:!1}),h=new e.Mesh(c,l);h.name="__empty_placeholder__";const d=new e.EdgesGeometry(c),u=new e.LineBasicMaterial({color:a,transparent:!0,opacity:.4}),p=new e.LineSegments(d,u);p.name="__empty_placeholder_edge__",h.add(p),this.object3d.add(h)}_showErrorPlaceholder(){const t=new e.BoxGeometry(1,1,1),n=new e.MeshStandardMaterial({color:13369344,wireframe:!0}),i=new e.Mesh(t,n);i.name="__error_placeholder__",this.object3d.add(i)}clear(){return this.pivot&&Hh(this.pivot),this.pivot=void 0,this._objectSize=void 0,super.clear()}}const Mp="KHR_materials_pbrSpecularGlossiness";class Sp{constructor(t){this.name=Mp,this.parser=t}extendMaterialParams(t,e){const n=this.parser.json.materials?.[t],i=n?.extensions?.[Mp];if(!i)return Promise.resolve();const r=[];if(Array.isArray(i.diffuseFactor)){const[t,n,r,s]=i.diffuseFactor;e.color||(e.color=new h),e.color.setRGB(t,n,r,d),e.opacity=s}null!=i.diffuseTexture&&r.push(this.parser.assignTexture(e,"map",i.diffuseTexture,u));const s=i.glossinessFactor??1;e.roughness=1-s;const o=i.specularFactor??[1,1,1],a=Math.max(o[0],o[1],o[2]);return e.metalness=a>.5?a:0,Promise.all(r)}}(()=>{const t="__urdfBlobCrossOriginPatched__",n=e.ImageLoader.prototype;if(n[t])return;const i=n.load;n.load=function(t,e,n,r){if("string"==typeof t&&t.startsWith("blob:")){const s=this.crossOrigin;this.crossOrigin=void 0;try{return i.call(this,t,e,n,r)}finally{this.crossOrigin=s}}return i.call(this,t,e,n,r)},n[t]=!0})();const kp={once:e.LoopOnce,repeat:e.LoopRepeat,pingpong:e.LoopPingPong};class Ap extends wp{constructor(){super(...arguments),this._nodeIndex=new Map,this._originals=new Map,this._animationActions=new Map,this._fillStyleOriginals=new Map,this._clonedMaterials=new WeakSet}get _formatLabel(){return"gltf"}static getSharedLoader(t){if(!Ap._sharedLoader){const t=new A;!function(t){t.register(t=>new Sp(t))}(t);const e=new E;e.setDecoderPath("/node_modules/three/examples/jsm/libs/draco/"),t.setDRACOLoader(e);const n=new C;n.setTranscoderPath("/node_modules/three/examples/jsm/libs/basis/"),t.setKTX2Loader(n),t.setMeshoptDecoder(T),t.setCrossOrigin("anonymous"),Ap._sharedLoader=t}return t&&Ap._sharedLoader.ktx2Loader?.detectSupport(t),Ap._sharedLoader}static loadGLTF(t,e){let n=Ap._gltfCache.get(t);if(!n){const i=Ap.getSharedLoader(e);n=new Promise((e,n)=>{i.load(t,e,void 0,n)}).catch(e=>{throw Ap._gltfCache.delete(t),e}),Ap._gltfCache.set(t,n)}return n}_ensureOwnMaterial(t){let e=t.material;return this._clonedMaterials.has(e)||(e=e.clone(),t.material=e,this._clonedMaterials.add(e)),e}_loadExternal(t){return Ap.loadGLTF(t,this.threeContainer?.renderer3d)}_onLoaded(t){this.component.state.loadError&&this.component.setState({loadError:void 0});const n=t.scene,i=t.animations,r=P(n);r.userData.context=this,r.traverse(t=>{t.isMesh&&(t.castShadow=!0)});const s=(new e.Box3).setFromObject(r),o=s.getCenter(r.position),a=s.getSize(new e.Vector3);o.multiplyScalar(-1);const c=this.component.state.src;if(c){const t=Ap._topViewCache.get(c);t?this.component._topViewSnapshot=t:this._renderTopViewSnapshot(c,r)}if(this.clear(),this.object3d.userData.context=this,this._objectSize=a,this.pivot=new e.Object3D,this.component.state.floorAlign?this.components3D.add(this.pivot):this.object3d.add(this.pivot),this.pivot.add(r),this._buildNodeIndex(r),this.component.state.autoFit&&a.x>0&&a.y>0&&a.z>0){const t=(Number(this.component.state.autoFitSize)>0?Number(this.component.state.autoFitSize):200)/Math.max(a.x,a.y,a.z),e=Math.max(1,Math.round(a.x*t)),n=Math.max(1,Math.round(a.y*t)),i=Math.max(1,Math.round(a.z*t)),r=this.component;r._ratioLocking=!0;try{this.component.set({width:e,height:i,depth:n,autoFit:!1})}finally{r._ratioLocking=!1}}if(this.updateDimension(),this.component.state.floorAlign){const t=this.scenePlacement;if("space"!==t){this.components3D.updateMatrixWorld(!0);const n=(new e.Box3).setFromObject(this.pivot);if(isFinite(n.min.y)&&isFinite(n.max.y))if("inverted"===t){const t=this.components3D.worldToLocal(n.max.clone());t.y>0&&(this.pivot.position.y-=t.y)}else{const t=this.components3D.worldToLocal(n.min.clone());t.y<0&&(this.pivot.position.y-=t.y)}}}i&&i.length&&this._setupAnimations(i);const l=this.component.state.nodes;l&&this._applyNodeStates(l),this.updateFillStyle()}_renderTopViewSnapshot(t,e){const n=Ap.renderTopView(e);Ap._topViewCache.set(t,n),this.component._topViewSnapshot=n,this.component.invalidate()}static renderTopView(t){const n=256,i=new e.Scene,r=t.parent;i.add(t);const s=new e.AmbientLight(16777215,.8);i.add(s);const o=new e.DirectionalLight(16777215,1);o.position.set(0,10,0),i.add(o);const a=(new e.Box3).setFromObject(t),c=a.getSize(new e.Vector3),l=a.getCenter(new e.Vector3),h=(c.x||1)/2*1.02,d=(c.z||1)/2*1.02,u=new e.OrthographicCamera(-h,h,d,-d,.01,10*c.y+1);u.position.set(l.x,a.max.y+c.y,l.z),u.lookAt(l.x,l.y,l.z);const p=h/d,f=p>=1?n:Math.round(n*p),g=p>=1?Math.round(n/p):n;let m;try{m=new e.WebGLRenderer({antialias:!0,alpha:!0});const t=m.getContext();t&&!t.isContextLost()||(m.dispose(),m=void 0)}catch{m=void 0}if(!m){r?r.add(t):i.remove(t);const e=document.createElement("canvas");return e.width=f,e.height=g,e}m.setClearColor(0,0),m.setSize(f,g),m.render(i,u),r?r.add(t):i.remove(t);const y=document.createElement("canvas");y.width=f,y.height=g;const b=y.getContext("2d");return b&&b.drawImage(m.domElement,0,0),m.dispose(),y}static getTopViewCache(t){return Ap._topViewCache.get(t)}static setTopViewCache(t,e){Ap._topViewCache.set(t,e)}static flushCache(){Ap._gltfCache.clear(),Ap._topViewCache.clear()}_buildNodeIndex(t){this._nodeIndex.clear(),this._originals.clear(),t.traverse(t=>{if(!t.name)return;this._nodeIndex.set(t.name,t);const e={visible:t.visible,scale:t.scale.clone()};if(t.isMesh){const n=t.material;n&&(e.color=n.color.clone(),e.opacity=n.opacity,e.transparent=n.transparent,e.emissive=n.emissive.clone(),e.emissiveIntensity=n.emissiveIntensity)}this._originals.set(t.name,e)})}getNode(t){return this._nodeIndex.get(t)}get nodeNames(){return Array.from(this._nodeIndex.keys())}_applyNodeStates(t){for(const[e,n]of Object.entries(t)){const t=this._nodeIndex.get(e);if(t&&(void 0!==n.visible&&(t.visible=n.visible),void 0!==n.scale&&t.scale.setScalar(n.scale),t.isMesh)){const e=t;if(!(void 0!==n.color||void 0!==n.opacity||void 0!==n.emissive||void 0!==n.emissiveIntensity))continue;const i=this._ensureOwnMaterial(e);void 0!==n.color&&i.color.set(n.color),void 0!==n.opacity&&(i.opacity=n.opacity,i.transparent=n.opacity<1),void 0!==n.emissive&&i.emissive.set(n.emissive),void 0!==n.emissiveIntensity&&(i.emissiveIntensity=n.emissiveIntensity)}}}_resetNode(t){const e=this._nodeIndex.get(t),n=this._originals.get(t);if(e&&n&&(e.visible=n.visible,e.scale.copy(n.scale),e.isMesh)){const t=e.material;t&&n.color&&(t.color.copy(n.color),t.opacity=n.opacity,t.transparent=n.transparent,t.emissive.copy(n.emissive),t.emissiveIntensity=n.emissiveIntensity)}}_resetAllNodes(){for(const t of this._originals.keys())this._resetNode(t)}_setupAnimations(t){const e=this.threeContainer.mixer;this._animationActions.clear();for(const n of t){const t=e.clipAction(n);this._animationActions.set(n.name,t)}!1!==this.component.state.play&&this._playTargetAnimations();const n=this.component.state.animations;n&&this._applyAnimationStates(n)}_playTargetAnimations(){const t=this.component.state.playTargets;if("*"===t)this._animationActions.forEach(t=>t.play());else if(Array.isArray(t)&&t.length>0)for(const e of t)this._animationActions.get(e)?.play()}_applyAnimationStates(t){for(const[n,i]of Object.entries(t)){const t=this._animationActions.get(n);t&&(void 0!==i.loop&&(t.loop=kp[i.loop]??e.LoopRepeat,"once"===i.loop&&(t.clampWhenFinished=!0)),void 0!==i.speed&&(t.timeScale=i.speed),void 0!==i.weight&&(t.weight=i.weight),void 0!==i.play&&(i.play?t.play():t.stop()))}}get animationNames(){return Array.from(this._animationActions.keys())}updateFillStyle(){const{fillStyle:t}=this.component.state;if(!t)return;const e=this.component.state.fillStyleTargets;let n;if("*"===e)n=[...this._nodeIndex.entries()].filter(([,t])=>t.isMesh).map(([t])=>t);else{if(!(Array.isArray(e)&&e.length>0))return;n=e}if(0===n.length)return;const i=Uh.buildFillStyleTexture(this.component);for(const e of n){const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const r=this._ensureOwnMaterial(n);r&&(this._fillStyleOriginals.has(e)||this._fillStyleOriginals.set(e,{color:r.color.clone(),map:r.map,opacity:r.opacity,transparent:r.transparent}),i?(r.map&&r.map!==this._fillStyleOriginals.get(e)?.map&&r.map.dispose(),i.needsUpdate=!0,r.map=i):"string"==typeof t&&("transparent"!==t?r.color.set(t):(r.opacity=0,r.transparent=!0)))}}_restoreFillStyleTargets(t){for(const e of t){const t=this._fillStyleOriginals.get(e);if(!t)continue;const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const i=n.material;i&&(i.map&&i.map!==t.map&&i.map.dispose(),i.color.copy(t.color),i.map=t.map,i.opacity=t.opacity,i.transparent=t.transparent,this._fillStyleOriginals.delete(e))}}clear(){return this._animationActions.forEach(t=>t.stop()),this._animationActions.clear(),this._nodeIndex.clear(),this._originals.clear(),this._fillStyleOriginals.clear(),super.clear()}updateDimension(){const{width:t=1,height:e=1,depth:n=1}=this.component.state,{x:i=1,y:r=1,z:s=1}=this.objectSize||{};this.pivot&&this.pivot.scale.set(t/i,n/r,e/s),this.component.invalidate()}onchange(t,e){if(super.onchange(t,e),("src"in t||"floorAlign"in t)&&this.updateSource(),"nodes"in t){this._resetAllNodes();const e=t.nodes;e&&Object.keys(e).length>0&&this._applyNodeStates(e)}if("animations"in t){const e=t.animations;e&&this._applyAnimationStates(e)}if("fillStyleTargets"in t){const t=[...this._fillStyleOriginals.keys()];t.length>0&&this._restoreFillStyleTargets(t),this.updateFillStyle()}("play"in t||"playTargets"in t)&&(this._animationActions.forEach(t=>t.stop()),!1!==this.component.state.play&&this._playTargetAnimations())}}Ap._topViewCache=new Map,Ap._gltfCache=new Map,Ap._sharedLoader=null;const Ep=["id","name","tag","type","class","text","data","property"];class Cp{constructor(){this._results=[],this._currentIndex=-1,this._lastQuery=""}get results(){return this._results}get currentIndex(){return this._currentIndex}get currentResult(){return this._results[this._currentIndex]}get resultCount(){return this._results.length}search(t,e,n){if(this._lastQuery=e,this._results=[],this._currentIndex=-1,!e||!t)return this._results;const i=n?.fields||Ep,r=n?.caseSensitive??!1,s=n?.includeHidden??!1,o=n?.maxResults??1/0,a=r?e:e.toLowerCase(),c=new Set;return this._traverse(t,t=>{if(c.has(t))return;if(this._results.length>=o)return;if(!s&&t.state.hidden)return;const e=this._matchComponent(t,a,i,r);e&&(c.add(t),this._results.push(e))}),this._results.length>0&&(this._currentIndex=0),this._results}navigateNext(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex+1)%this._results.length,this._results[this._currentIndex]}navigatePrev(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex-1+this._results.length)%this._results.length,this._results[this._currentIndex]}navigateTo(t){if(!(t<0||t>=this._results.length))return this._currentIndex=t,this._results[this._currentIndex]}clear(){this._results=[],this._currentIndex=-1,this._lastQuery=""}_traverse(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverse(t,e)}_matchComponent(t,e,n,i){const r=t.state,s=t=>{if(!t)return!1;return(i?t:t.toLowerCase()).includes(e)};for(const o of n)switch(o){case"id":if(s(r.id))return{component:t,matchType:"id",matchField:"id",matchValue:r.id};break;case"name":if(s(r.name))return{component:t,matchType:"name",matchField:"name",matchValue:r.name};break;case"tag":if(s(r.tag))return{component:t,matchType:"tag",matchField:"tag",matchValue:r.tag};break;case"type":if(s(r.type))return{component:t,matchType:"type",matchField:"type",matchValue:r.type};break;case"class":if(s(r.class))return{component:t,matchType:"class",matchField:"class",matchValue:r.class};break;case"text":if(s(r.text))return{component:t,matchType:"text",matchField:"text",matchValue:r.text};break;case"data":{const n=this._matchDataBinding(t,e,i);if(n)return n;break}case"property":{const n=this._matchProperties(t,e,i);if(n)return n;break}}return null}_matchDataBinding(t,e,n){const i=t._model,r=i?.mappings;if(!r||!Array.isArray(r))return null;const s=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)};for(const e of r){if(s(e.accessor))return{component:t,matchType:"data",matchField:"accessor",matchValue:e.accessor};if(s(e.target))return{component:t,matchType:"data",matchField:"target",matchValue:e.target};if(s(e.property))return{component:t,matchType:"data",matchField:"property",matchValue:e.property};if(s(e.source))return{component:t,matchType:"data",matchField:"source",matchValue:e.source}}return null}_matchProperties(t,e,n){const i=t.state,r=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)},s=["ref","src","value","action"];for(const e of s){const n=i[e];if("string"==typeof n&&r(n))return{component:t,matchType:"property",matchField:e,matchValue:n}}const o=i.fillStyle;if(o){if("string"==typeof o&&r(o))return{component:t,matchType:"property",matchField:"fillStyle",matchValue:o};if("object"==typeof o&&"pattern"===o.type&&"string"==typeof o.image&&r(o.image))return{component:t,matchType:"property",matchField:"fillStyle.image",matchValue:o.image}}return null}}const Tp={id:"ID",name:"Name",tag:"Tag",type:"Type",class:"Class",text:"Text",data:"Data",property:"Prop"};class Pp{constructor(){this._engine=new Cp,this._visible=!1,this._queryHistory=[],this._historyIndex=-1,this._savedInput="",this._keyboardNav=!1}get isVisible(){return this._visible}get engine(){return this._engine}setup(t){this.destroy(),this._host=t}toggle(){this._visible?this._input&&document.activeElement!==this._input?(this._input.focus(),this._input.select()):this.hide():this.show()}show(){this._host?.element&&(this._container||this._buildDOM(),this._container&&!this._container.parentElement&&this._host.element.appendChild(this._container),this._container.style.display="flex",this._visible=!0,requestAnimationFrame(()=>{this._input?.focus(),this._input?.select()}))}hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._historyIndex=-1,this._clearHighlight(),this._engine.clear(),this._updateStatus(),this._hideResultList()}destroy(){this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._input=void 0,this._statusEl=void 0,this._resultListEl=void 0,this._host=void 0,this._visible=!1,this._engine.clear()}_buildDOM(){const t=this._host,e=document.createElement("div");e.setAttribute("scene","search-overlay"),e.style.cssText=["position:absolute","top:8px","right:8px","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none","z-index:10000",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:280px","max-width:400px"].join(";");const n=document.createElement("div");n.style.cssText="display:flex;align-items:center;padding:6px 8px;gap:6px";const i=document.createElement("span");i.textContent="🔍",i.style.cssText="font-size:14px;flex-shrink:0;opacity:0.6",n.appendChild(i);const r=document.createElement("input");r.type="text",r.placeholder="Search: type, id, tag, text, data...",r.style.cssText=["flex:1","background:rgba(255,255,255,0.08)","border:1px solid rgba(255,255,255,0.15)","border-radius:4px","color:white","padding:4px 8px","font-size:13px","outline:none","min-width:0"].join(";"),r.addEventListener("focus",()=>{r.style.borderColor="rgba(74,158,255,0.6)"}),r.addEventListener("blur",()=>{r.style.borderColor="rgba(255,255,255,0.15)"}),n.appendChild(r);const s=document.createElement("span");s.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;flex-shrink:0",n.appendChild(s);const o=document.createElement("button");o.textContent="✕",o.title="Close (Esc)",o.style.cssText=this._buttonStyle(),o.addEventListener("click",()=>this.hide()),n.appendChild(o),e.appendChild(n);const a=document.createElement("div");a.style.cssText=["max-height:240px","overflow-y:auto","border-top:1px solid rgba(255,255,255,0.08)","display:none"].join(";"),e.appendChild(a),r.addEventListener("input",()=>{this._historyIndex=-1,this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>this._doSearch(r.value),150)}),r.addEventListener("keydown",e=>{if(e.stopPropagation(),"Escape"===e.key)return this.hide(),void t.element?.focus();if("ArrowDown"===e.key||"Tab"===e.key){if("Tab"===e.key&&e.shiftKey)return;return this._isHistoryMode()||!this._input?.value&&"ArrowDown"===e.key?this._navigateHistory(1):this._engine.resultCount>0&&this._focusResult(0),void e.preventDefault()}if("ArrowUp"===e.key)return this._navigateHistory(-1),void e.preventDefault();if("Enter"===e.key){const t=this._engine.currentIndex>=0?this._engine.currentIndex:0;return this._selectResult(t),void e.preventDefault()}}),this._container=e,this._input=r,this._statusEl=s,this._resultListEl=a}_buttonStyle(){return["background:none","border:none","color:rgba(255,255,255,0.6)","cursor:pointer","font-size:12px","padding:2px 4px","border-radius:3px","line-height:1"].join(";")}_doSearch(t){if(!this._host?.root)return;const e=t.trim();if(!e)return this._engine.clear(),this._clearHighlight(),this._updateStatus(),void this._hideResultList();this._engine.search(this._host.root,e),this._updateStatus(),this._renderResultList()}_addToHistory(t){const e=t.trim();if(!e)return;const n=this._queryHistory.indexOf(e);n>=0&&this._queryHistory.splice(n,1),this._queryHistory.unshift(e),this._queryHistory.length>Pp.MAX_HISTORY&&this._queryHistory.pop()}_navigateHistory(t){if(0===this._queryHistory.length)return;if(!this._input)return;-1===this._historyIndex&&-1===t&&(this._savedInput=this._input.value);const e=this._historyIndex+(-1===t?1:-1);e<-1||e>=this._queryHistory.length||(this._historyIndex=e,-1===this._historyIndex?this._input.value=this._savedInput:this._input.value=this._queryHistory[this._historyIndex],this._debounceTimer&&clearTimeout(this._debounceTimer),this._doSearch(this._input.value))}_isHistoryMode(){return this._historyIndex>=0}_focusResult(t){if(t<0||t>=this._engine.resultCount)return;if(t>=50)return;this._engine.navigateTo(t),this._keyboardNav=!0,this._updateStatus(),this._updateResultListSelection();const e=this._resultListEl?.querySelector(`[data-index="${t}"]`);e?.focus()}_selectResult(t){if(!this._host)return;if(0===this._engine.resultCount)return;if(t<0||t>=this._engine.resultCount)return;this._engine.navigateTo(t);const e=this._engine.currentResult;if(!e)return;this._addToHistory(this._input?.value||""),this._host.setSelected([e.component]),this._host.centerTo(e.component,!0);const n=this._engine.results.map(t=>t.component);this._host.highlightSearchResults?.(n),this._host.invalidate?.(),this._updateStatus(),this._updateResultListSelection()}_clearHighlight(){this._host?.highlightSearchResults?.([]),this._host?.invalidate?.()}_updateStatus(){if(!this._statusEl)return;const t=this._engine.resultCount,e=this._engine.currentIndex;0===t&&this._input?.value?.trim()?(this._statusEl.textContent="No results",this._statusEl.style.color="rgba(255,120,120,0.8)"):t>0?(this._statusEl.textContent=`${e+1}/${t}`,this._statusEl.style.color="rgba(255,255,255,0.5)"):this._statusEl.textContent=""}_renderResultList(){if(!this._resultListEl)return;const t=this._engine.results;if(this._resultListEl.innerHTML="",0===t.length)return void(this._resultListEl.style.display="none");const e=t.slice(0,50);for(let t=0;t<e.length;t++){const n=e[t],i=document.createElement("div");i.dataset.index=String(t),i.tabIndex=-1,i.style.cssText=["padding:4px 10px","cursor:pointer","display:flex","align-items:center","gap:6px","font-size:12px","border-bottom:1px solid rgba(255,255,255,0.04)","transition:background 0.1s","outline:none"].join(";"),i.addEventListener("mouseenter",()=>{this._keyboardNav=!1,i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{this._engine.currentIndex!==t?i.style.background="none":i.style.background="rgba(74,158,255,0.15)"}),i.addEventListener("click",()=>{this._selectResult(t)}),i.addEventListener("keydown",e=>{e.stopPropagation(),"ArrowDown"===e.key?(this._focusResult(t+1),e.preventDefault()):"ArrowUp"===e.key?(0===t?(this._input?.focus(),this._input?.select()):this._focusResult(t-1),e.preventDefault()):"Enter"===e.key?(this._selectResult(t),e.preventDefault()):"Escape"===e.key?(this.hide(),this._host?.element?.focus(),e.preventDefault()):e.shiftKey&&"Tab"===e.key?(this._input?.focus(),e.preventDefault()):1!==e.key.length||e.metaKey||e.ctrlKey||e.altKey||this._input?.focus()});const r=document.createElement("span");r.textContent=Tp[n.matchType]||n.matchType,r.style.cssText=["font-size:9px","padding:1px 4px","border-radius:3px","background:rgba(74,158,255,0.2)","color:rgba(74,158,255,0.9)","flex-shrink:0","text-transform:uppercase","letter-spacing:0.5px"].join(";"),i.appendChild(r);const s=document.createElement("span");s.textContent=n.component.state.type||"?",s.style.cssText="color:rgba(255,255,255,0.7);flex-shrink:0",i.appendChild(s);const o=document.createElement("span");if(o.textContent=this._truncate(n.matchValue,30),o.style.cssText="color:rgba(255,200,100,0.8);overflow:hidden;text-overflow:ellipsis;white-space:nowrap",i.appendChild(o),"id"!==n.matchType&&n.component.state.id){const t=document.createElement("span");t.textContent=`#${n.component.state.id}`,t.style.cssText="color:rgba(255,255,255,0.3);font-size:11px;margin-left:auto;flex-shrink:0",i.appendChild(t)}this._resultListEl.appendChild(i)}if(t.length>50){const e=document.createElement("div");e.style.cssText="padding:4px 10px;font-size:11px;color:rgba(255,255,255,0.3);text-align:center",e.textContent=`... and ${t.length-50} more`,this._resultListEl.appendChild(e)}this._resultListEl.style.display="block",this._updateResultListSelection()}_updateResultListSelection(){if(!this._resultListEl)return;const t=this._engine.currentIndex;for(const e of Array.from(this._resultListEl.children)){const n=e,i=parseInt(n.dataset.index||"-1",10);n.style.background=i===t?"rgba(74,158,255,0.15)":"none"}const e=this._resultListEl.querySelector(`[data-index="${t}"]`);e?.scrollIntoView({block:"nearest"})}_hideResultList(){this._resultListEl&&(this._resultListEl.style.display="none",this._resultListEl.innerHTML="")}_truncate(t,e){return t.length>e?t.slice(0,e)+"...":t}}Pp.MAX_HISTORY=20;let Dp=0;const Op=new FinalizationRegistry(t=>{Dp--});class zp{static get residents(){return Dp}static get residentsCount(){return Dp}constructor(t){this._searchOverlay=new Pp,this._loadingOverlay=new xp,this._container=t,this.app=t.app,this._commander=new mp(this._container),this.app.commander=this._commander,Dp++,Op.register(this,Dp),yp.register(this),this._container.target_element&&this._setupSearchOverlay()}add(t,e,n){return Ml.call(this._container,t,e,n)}duplicate(){return Sl.call(this._container)}remove(){return kl.call(this._container)}animate(t){return ra.call(this,t)}fullscreen(t){return Dl.call(this._container,t)}get target(){return this._container.target_element}set target(t){let e;if("string"==typeof t){if(e=document.getElementById(t),!e)throw new Error(`target element '${t}' does not exist`);if(e.firstChild)throw new Error(`target element '${t}' already has children`)}else e=t;e&&e.style&&(e.style.cursor="default"),this._container.target_element=e,this._setupSearchOverlay(),this._container.invalidate()}get scale(){return this.root.get("scale")}set scale(t){this.root.set("scale",t)}get translate(){return this.root.get("translate")}set translate(t){this.root.set("translate",t)}get unit(){return this.root.get("unit")||"px"}get PPM(){return this.app.PPM}get PPI(){return this.app.PPI}get DPPX(){return this.app.DPPX}static get DPPX(){return Hr}get unitScale(){return this._container.unitScale}get screen(){return this.app.screen}set screen(t){this.app.screen=t,this._container.resize()}resize(){this._container.resize()}release(){this.dispose()}dispose(){this._loadingOverlay.destroy(),this._searchOverlay.destroy(),yp.unregister(this),this._commander&&this._commander.dispose(),this._container&&this._container.dispose(),Ap.flushCache()}get selected(){return this._container.selected.slice()}set selected(t){this._container.selected=t}select(t,...e){return this._container.selected=this.root?.findAll(t,...e),this.selected}get commander(){return this._commander}undo(){this.commander.undo()}undoable(){return this.commander.undoable()}redo(){this.commander.redo()}redoable(){return this.commander.redoable()}preserve(){this.commander.preserve()}hasUnpreservedChanges(){return this.commander.hasUnpreservedChanges()}cut(){return Il.call(this._container)}copy(){return zl.call(this._container)}paste(t){return Ll.call(this._container,t)}undoableChange(t){return Jl.call(this._container,t)}change(t,e,n){return Zl.call(this.root,t,e,n)}get model(){return this.root.hierarchy}set model(t){this._container.rebuildContentModel(t)}get rootContainer(){return this._container}get root(){return this._container?.model_layer}findAll(t,...e){return this.root.findAll(t,...e)}findFirst(t,...e){return this.root.findFirst(t,...e)}findById(t){return this._container.findById(t)}findAllById(t){return this._container.findAllById(t)}serialize(){return this.root.trim(),this.root.serialize()}align(t){return pl.call(this._container,t)}place(t){return ah.call(this._container,t)}distribute(t){return ml.call(this._container,t)}move(t,e,n){return vl.call(this._container,t,e,n)}zorder(t){return _l.call(this._container,t)}symmetryX(){return $l.call(this._container)}symmetryY(){return Ql.call(this._container)}on(t,e,n){return Cl.call(this._container,t,e,n)}once(t,e,n){return Tl.call(this._container,t,e,n)}off(t,e,n){return this._container&&Pl.call(this._container,t,e,n)}centerTo(t,e){return this.root.centerTo(t,e)}get mode(){return this.app.mode}set mode(t){void 0!==t&&(this.app.mode=t)}toDataURL(t,e,n,i){return Ul.call(this._container,t,e,n,i)}group(){return Wl.call(this._container)}ungroup(){return Xl.call(this._container)}fit(t){this._container.once("redraw",()=>this._container.fit(t)),this._container.invalidate()}get fitMode(){return this._container.fitMode}get ids(){return th.call(this._container)}get data(){return this._container.data}set data(t){this._container.data=t}get dataByRefid(){return this._container.dataByRefid}set dataByRefid(t){this._container.dataByRefid=t}get values(){return this._container.values}set values(t){this._container.values=t}get valuesByRefid(){return this._container.valuesByRefid}set valuesByRefid(t){this._container.valuesByRefid=t}get baseUrl(){return this.app.baseUrl}set baseUrl(t){this.app.baseUrl=t}get suppressAnimations(){return this.app.suppressAnimations}set suppressAnimations(t){this.app.suppressAnimations=t}withSuppressedAnimations(t){return this.app.withSuppressedAnimations(t)}beginSuppressAnimations(){return this.app.beginSuppressAnimations()}startAddMode(t){return ch.call(this._container,t)}startStylePasteMode(){return lh.call(this._container)}stopStylePasteMode(){return hh.call(this._container)}startDatabindPasteMode(){return dh.call(this._container)}stopDatabindPasteMode(){return uh.call(this._container)}get loading(){return this.app.loadTracker}get loadingOverlay(){return this._loadingOverlay}showLoadingOverlay(){this._loadingOverlay.show()}hideLoadingOverlay(){this._loadingOverlay.hide()}toggleLoadingOverlay(){if(!this._loadingOverlay.isAttached){const t=this._container.target_element;t&&this._loadingOverlay.attach(t,this.app.loadTracker,this.app.lagTracker)}this._loadingOverlay.toggle()}get searchOverlay(){return this._searchOverlay}_setupSearchOverlay(){const t=this;this._searchOverlay.setup({get root(){return t.root},get element(){return t.target},centerTo(e,n){t.centerTo(e,n)},setSelected(e){t.selected=e},invalidate(){t._container?.invalidate()}});const e=this._container.model_layer;e&&(e.onSearchToggle=()=>this._searchOverlay.toggle(),e.onDataBindingToggle=()=>this.onDataBindingToggle?.(),e.onMonitorToggle=()=>this.toggleLoadingOverlay())}_setupLoadingOverlay(){const t=this._container.target_element;t&&this._loadingOverlay.attach(t,this.app.loadTracker,this.app.lagTracker)}}const Ip=new class{async load(t){}async save(t,e){}async clear(t){}};function Lp({target:t,model:e,style:n,layers:i=[],handlers:r=[],mode:s=0,refProvider:o,dataSubscriptionProvider:a,dataStorage:c=Ip,baseUrl:l,fitMode:h,postprocessing:d=!0,loading:u}){let p=null;if("string"==typeof t){if(p=document.getElementById(t),!p)throw new Error(`target element '${t}' does not exist`);if(p.firstChild)throw new Error(`target element '${t}' is not empty`)}else p=t??null;p&&p.style&&(p.style.position="absolute",p.style.cursor="default",p.style.overflow="hidden");const f=new hp(s,o);return l&&(f.baseUrl=l),f.postprocessing=d,f.dataSubscriptionProvider=a,f.dataStorage=c,u?.tracker?f.adoptLoadTracker(u.tracker):f.initLoadTracker(u||{}),f.loadTracker?.setPhase("init"),new zp(new ep({target_element:p,model:e,style:n,layers:i,handlers:r,fitMode:h},f))}function jp(t,e,n,i){var r,s=arguments.length,o=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(s<3?r(o):s>3?r(e,n,o):r(e,n))||o);return s>3&&o&&Object.defineProperty(e,n,o),o}function Rp(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function Fp(t,e,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const Bp=["mousemove","mouseup","mousedown","mouseout","wheel","tap","click","touchstart","touchmove","touchend","mouseenter","mouseleave","dragstart","dragmove","dragend","dblclick"];function Np(t){return class extends t{constructor(){super(...arguments),this.userInputEventHandler=t=>{Du(this,t.type,t),t.stopPropagation()}}isHTMLElement(){return!0}isShadowable(){return!0}get element(){return this._element}set element(t){this._element=t}get tagName(){return this.get("type")}setElementProperties(t){throw new Error("Not Implemented Yet")}createElement(){this.element=document.createElement(this.tagName),this.element&&(this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element),this.scalable||(this.element.style.zIndex="100"),Bp.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),Vr.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),this.oncreate_element&&this.oncreate_element(this.element))}reposition(){this.element&&Ss(this)}disposeElement(){if(!this.element)return;Bp.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)}),Vr.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)});const t=this.element;t&&t.parentElement&&t.parentElement.removeChild(t),this.element=null}async ready(){await super.ready(),!this.element&&this.createElement(),this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element),this.setElementProperties(this.element),this.reposition()}dispose(){this.disposeElement(),super.dispose()}get hasTextProperty(){return!0}get textHidden(){return!0}set textHidden(t){}get hidden(){return super.hidden}set hidden(t){super.hidden=t,this.element.style.display=t?"none":"block"}onchange(t,e){this.element&&this.setElementProperties(this.element),"position"in t&&this.onchangePosition(),this.reposition()}onchangePosition(){this.element&&("static"==this.position&&this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element))}isDescendible(t){return t.isHTMLElement()}}}var Hp;const Yp={x:1,y:1},Vp={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"},Gp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"position-origin",name:"origin",property:{options:[{display:"",value:""},{display:"left-top",value:"left-top"},{display:"center-top",value:"center-top"},{display:"right-top",value:"right-top"},{display:"left-middle",value:"left-middle"},{display:"center-middle",value:"center-middle"},{display:"right-middle",value:"right-middle"},{display:"left-bottom",value:"left-bottom"},{display:"center-bottom",value:"center-bottom"},{display:"right-bottom",value:"right-bottom"}]}},{type:"number",label:"offset-x",name:"offsetX"},{type:"number",label:"offset-y",name:"offsetY"},{type:"layout",label:"layout",name:"layoutOption"},{type:"checkbox",label:"closable",name:"closable"},{type:"checkbox",label:"draggable",name:"draggable"},{type:"checkbox",label:"minimizable",name:"minimizable"},{type:"checkbox",label:"minimized",name:"minimized"}],help:"scene/component/container"};class Up extends(Np(Fc)){constructor(){super(...arguments),Hp.set(this,null),this.startDragging=t=>{if(!this.state.draggable)return;t.preventDefault(),t.stopPropagation();const e=t.clientX,n=t.clientY,{left:i,top:r}=this.bounds,s=this.rootModel.getOverlay?.(this)?.style.transform,o=s?.match(/scale\(([^,]+),\s*([^)]+)\)/),a=o?parseFloat(o[1]):1,c=o?parseFloat(o[2]):a,l=t=>{t.preventDefault(),t.stopPropagation();const s=(t.clientX-e)/a,o=(t.clientY-n)/c;this.setState({left:i+s,top:r+o})},h=t=>{t.preventDefault(),t.stopPropagation(),document.removeEventListener("mousemove",l,!0),document.removeEventListener("mouseup",h,!0)};document.addEventListener("mousemove",l,!0),document.addEventListener("mouseup",h,!0)},this.toggleMinimizable=()=>{const{minimized:t}=this.state;this.setState("minimized",!t)},this.closeContainer=()=>{this.setState("hidden",!0)}}get tagName(){return"div"}get nature(){return Gp}isPositionable(){return!0}setElementProperties(t){}get layout(){return yc.get(this.get("layout"))||bc}reposition(){if(!this.element)return;const t=this,{id:e,class:n,scale:i=Yp}=t.state,{rotation:r=0,hidden:s}=t,{left:o,top:a,width:c,height:l}=t.bounds,h=c/2,d=l/2,u=t.element;u.hidden=s,e&&(u.id=e),n&&(u.className=n),Object.assign(u.style,Vp,{left:o+"px",top:a+"px",width:"0px",height:"0px",backgroundColor:"transparent"});const p=t.delta(),f=(i&&i.x||1)*p.sx,g=(i&&i.y||1)*p.sy,m=(r||0)+p.theta,y=p.tx||0,b=p.ty||0;u.style.transform=`translate(${y+h}px, ${b+d}px) rotate(${m}rad) translate(${-h}px, ${-d}px) scale(${f}, ${g}) perspective(1px)`}set path(t){const{minimized:e}=this.state,n=t[0],i=t[2];e?this.set({left:n.x,top:n.y,width:i.x-n.x}):this.set({left:n.x,top:n.y,width:i.x-n.x,height:i.y-n.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){const{minimized:e}=this.state,{left:n=0,top:i=0,width:r=0,height:s=0}=t,o={left:n,top:i};e?this.set({...o,width:r}):this.set({...o,width:r,height:s})}updatePosition(){if(!this.origin)return void(Rp(this,Hp,"f")&&(Rp(this,Hp,"f").disconnect(),Fp(this,Hp,null,"f")));const t=this.rootModel.auxOverlay;if(!t)return;const e=this.bounds,{width:n,height:i}="static"!==this.position?t.getBoundingClientRect():this.parent.bounds,{x:r,y:s}=function(t,e,n){const{left:i,top:r,width:s,height:o}=e,{width:a,height:c}=n;return t?{x:t.includes("left")?i:t.includes("center")?i+(s-a)/2:i+(s-a),y:t.includes("top")?r:t.includes("middle")?r+(o-c)/2:r+(o-c)}:{x:n.left,y:n.top}}(this.origin,{left:0,top:0,width:n,height:i},e),o=this.offset;this.bounds={left:r+(this.origin.includes("right")?-o.x:+o.x),top:s+(this.origin.includes("bottom")?-o.y:+o.y),width:e.width,height:e.height},Rp(this,Hp,"f")||(Fp(this,Hp,new ResizeObserver(()=>{requestAnimationFrame(()=>this.updatePosition())}),"f"),Rp(this,Hp,"f").observe(t))}onchange(t,e){const n=["draggable","minimizable","closable","minimized","width","height","origin","offsetX","offsetY","hidden"];super.onchange(t,e),Object.keys(t).some(t=>n.includes(t))&&this.onchangeButtons(),"minimized"in t&&this.onchangeMinimized(),("origin"in t||"offsetX"in t||"offsetY"in t)&&this.updatePosition()}async ready(){await super.ready(),this.updatePosition()}dispose(){Rp(this,Hp,"f")&&(Rp(this,Hp,"f").disconnect(),Fp(this,Hp,null,"f")),super.dispose()}createElement(){super.createElement(),this.element&&(this.element.setAttribute("scene","container"),this.onchangeButtons(),this.onchangeMinimized())}onchangeButtons(){if(!this.element)return;const{draggable:t,minimizable:e,closable:n,minimized:i,hidden:r}=this.state,{width:s}=this.bounds;this.element.style.setProperty("--container-width",`${s}px`);try{D(r?O:z`
3
3
  <style>
4
4
  [scene='container'] .buttons {
5
5
  position: absolute;