@hatiolab/things-scene 10.0.0-beta.21 → 10.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-types/threed/environments/base-environment.d.ts +9 -0
- package/dist-types/threed/environments/base-environment.d.ts.map +1 -0
- package/dist-types/threed/environments/factory-environment.d.ts +2 -3
- package/dist-types/threed/environments/factory-environment.d.ts.map +1 -1
- package/dist-types/threed/environments/home-environment.d.ts +2 -3
- package/dist-types/threed/environments/home-environment.d.ts.map +1 -1
- package/dist-types/threed/environments/office-environment.d.ts +2 -3
- package/dist-types/threed/environments/office-environment.d.ts.map +1 -1
- package/dist-types/threed/environments/studio-environment.d.ts +2 -3
- package/dist-types/threed/environments/studio-environment.d.ts.map +1 -1
- package/dist-types/threed/environments/warehouse-environment.d.ts +2 -3
- package/dist-types/threed/environments/warehouse-environment.d.ts.map +1 -1
- package/dist-types/threed/factories/banner.d.ts +1 -1
- package/dist-types/threed/factories/banner.d.ts.map +1 -1
- package/dist-types/threed/managers/box-selection-manager.d.ts.map +1 -1
- package/dist-types/threed/material-3d.d.ts +5 -0
- package/dist-types/threed/material-3d.d.ts.map +1 -1
- package/dist-types/threed/real-object-extrude.d.ts.map +1 -1
- package/dist-types/threed/real-object-mesh.d.ts.map +1 -1
- package/dist-types/threed/real-object.d.ts +0 -6
- package/dist-types/threed/real-object.d.ts.map +1 -1
- package/dist-types/threed/texture/fillstyle-texture.d.ts +37 -0
- package/dist-types/threed/texture/fillstyle-texture.d.ts.map +1 -0
- package/dist-types/threed/texture/text-texture.d.ts.map +1 -1
- package/dist-types/threed/three-capability.d.ts +14 -0
- package/dist-types/threed/three-capability.d.ts.map +1 -1
- package/package.json +1 -1
- package/things-scene-min.js +10 -10
- package/things-scene-min.js.map +1 -1
- package/things-scene.mjs +2 -2
- package/things-scene.mjs.map +1 -1
package/things-scene.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import t from"dompurify";import*as e from"three";import{Scene as n,BoxGeometry as r,MeshStandardMaterial as i,BackSide as s,Mesh as o,PointLight as a,MeshLambertMaterial as c,Color as l,LinearSRGBColorSpace as h,SRGBColorSpace as d}from"three";import{Line2 as u}from"three/examples/jsm/lines/Line2.js";import{LineMaterial as p}from"three/examples/jsm/lines/LineMaterial.js";import{LineGeometry as f}from"three/examples/jsm/lines/LineGeometry.js";import{CSS3DObject as g,CSS3DRenderer as m}from"three/examples/jsm/renderers/CSS3DRenderer.js";import y from"tinycolor2";import{EffectComposer as b}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as v}from"three/examples/jsm/postprocessing/RenderPass.js";import{OutlinePass as x}from"three/examples/jsm/postprocessing/OutlinePass.js";import{OutputPass as _}from"three/examples/jsm/postprocessing/OutputPass.js";import{SMAAPass as w}from"three/examples/jsm/postprocessing/SMAAPass.js";import{TransformControls as M}from"three/examples/jsm/controls/TransformControls.js";import{GLTFLoader as S}from"three/examples/jsm/loaders/GLTFLoader.js";import{DRACOLoader as A}from"three/examples/jsm/loaders/DRACOLoader.js";import{KTX2Loader as k}from"three/examples/jsm/loaders/KTX2Loader.js";import{MeshoptDecoder as E}from"three/examples/jsm/libs/meshopt_decoder.module.js";import{render as C,nothing as P,html as T}from"lit";function O(t,e){return t===e||t!=t&&e!=e}function D(t,e){for(var n=t.length;n--;)if(O(t[n][0],e))return n;return-1}var I=Array.prototype.splice;function z(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}z.prototype.clear=function(){this.__data__=[],this.size=0},z.prototype.delete=function(t){var e=this.__data__,n=D(e,t);return!(n<0)&&(n==e.length-1?e.pop():I.call(e,n,1),--this.size,!0)},z.prototype.get=function(t){var e=this.__data__,n=D(e,t);return n<0?void 0:e[n][1]},z.prototype.has=function(t){return D(this.__data__,t)>-1},z.prototype.set=function(t,e){var n=this.__data__,r=D(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var L="object"==typeof global&&global&&global.Object===Object&&global,j="object"==typeof self&&self&&self.Object===Object&&self,R=L||j||Function("return this")(),F=R.Symbol,B=Object.prototype,N=B.hasOwnProperty,Y=B.toString,V=F?F.toStringTag:void 0;var G=Object.prototype.toString;var H=F?F.toStringTag:void 0;function U(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":H&&H in Object(t)?function(t){var e=N.call(t,V),n=t[V];try{t[V]=void 0;var r=!0}catch(t){}var i=Y.call(t);return r&&(e?t[V]=n:delete t[V]),i}(t):function(t){return G.call(t)}(t)}function W(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function X(t){if(!W(t))return!1;var e=U(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var q,K=R["__core-js_shared__"],$=(q=/[^.]+$/.exec(K&&K.keys&&K.keys.IE_PROTO||""))?"Symbol(src)_1."+q:"";var Q=Function.prototype.toString;function Z(t){if(null!=t){try{return Q.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var J=/^\[object .+?Constructor\]$/,tt=Function.prototype,et=Object.prototype,nt=tt.toString,rt=et.hasOwnProperty,it=RegExp("^"+nt.call(rt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function st(t){return!(!W(t)||(e=t,$&&$ in e))&&(X(t)?it:J).test(Z(t));var e}function ot(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return st(n)?n:void 0}var at=ot(R,"Map"),ct=ot(Object,"create");var lt=Object.prototype.hasOwnProperty;var ht=Object.prototype.hasOwnProperty;function dt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function ut(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 pt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}dt.prototype.clear=function(){this.__data__=ct?ct(null):{},this.size=0},dt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},dt.prototype.get=function(t){var e=this.__data__;if(ct){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return lt.call(e,t)?e[t]:void 0},dt.prototype.has=function(t){var e=this.__data__;return ct?void 0!==e[t]:ht.call(e,t)},dt.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=ct&&void 0===e?"__lodash_hash_undefined__":e,this},pt.prototype.clear=function(){this.size=0,this.__data__={hash:new dt,map:new(at||z),string:new dt}},pt.prototype.delete=function(t){var e=ut(this,t).delete(t);return this.size-=e?1:0,e},pt.prototype.get=function(t){return ut(this,t).get(t)},pt.prototype.has=function(t){return ut(this,t).has(t)},pt.prototype.set=function(t,e){var n=ut(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function ft(t){var e=this.__data__=new z(t);this.size=e.size}ft.prototype.clear=function(){this.__data__=new z,this.size=0},ft.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},ft.prototype.get=function(t){return this.__data__.get(t)},ft.prototype.has=function(t){return this.__data__.has(t)},ft.prototype.set=function(t,e){var n=this.__data__;if(n instanceof z){var r=n.__data__;if(!at||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new pt(r)}return n.set(t,e),this.size=n.size,this};function gt(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new pt;++e<n;)this.add(t[e])}function mt(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}gt.prototype.add=gt.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},gt.prototype.has=function(t){return this.__data__.has(t)};function yt(t,e,n,r,i,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 gt:void 0;for(s.set(t,e),s.set(e,t);++d<a;){var f=t[d],g=e[d];if(r)var m=o?r(g,f,d,e,t,s):r(f,g,d,t,e,s);if(void 0!==m){if(m)continue;u=!1;break}if(p){if(!mt(e,function(t,e){if(o=e,!p.has(o)&&(f===t||i(f,t,n,r,s)))return p.push(e);var o})){u=!1;break}}else if(f!==g&&!i(f,g,n,r,s)){u=!1;break}}return s.delete(t),s.delete(e),u}var bt=R.Uint8Array;function vt(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function xt(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var _t=F?F.prototype:void 0,wt=_t?_t.valueOf:void 0;function Mt(t,e){for(var n=-1,r=e.length,i=t.length;++n<r;)t[i+n]=e[n];return t}var St=Array.isArray;function At(){return[]}var kt=Object.prototype.propertyIsEnumerable,Et=Object.getOwnPropertySymbols,Ct=Et?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var n=-1,r=null==t?0:t.length,i=0,s=[];++n<r;){var o=t[n];e(o,n,t)&&(s[i++]=o)}return s}(Et(t),function(e){return kt.call(t,e)}))}:At;function Pt(t){return null!=t&&"object"==typeof t}function Tt(t){return Pt(t)&&"[object Arguments]"==U(t)}var Ot=Object.prototype,Dt=Ot.hasOwnProperty,It=Ot.propertyIsEnumerable,zt=Tt(function(){return arguments}())?Tt:function(t){return Pt(t)&&Dt.call(t,"callee")&&!It.call(t,"callee")};var Lt="object"==typeof exports&&exports&&!exports.nodeType&&exports,jt=Lt&&"object"==typeof module&&module&&!module.nodeType&&module,Rt=jt&&jt.exports===Lt?R.Buffer:void 0,Ft=(Rt?Rt.isBuffer:void 0)||function(){return!1},Bt=/^(?:0|[1-9]\d*)$/;function Nt(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&Bt.test(t))&&t>-1&&t%1==0&&t<e}function Yt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var Vt={};function Gt(t){return function(e){return t(e)}}Vt["[object Float32Array]"]=Vt["[object Float64Array]"]=Vt["[object Int8Array]"]=Vt["[object Int16Array]"]=Vt["[object Int32Array]"]=Vt["[object Uint8Array]"]=Vt["[object Uint8ClampedArray]"]=Vt["[object Uint16Array]"]=Vt["[object Uint32Array]"]=!0,Vt["[object Arguments]"]=Vt["[object Array]"]=Vt["[object ArrayBuffer]"]=Vt["[object Boolean]"]=Vt["[object DataView]"]=Vt["[object Date]"]=Vt["[object Error]"]=Vt["[object Function]"]=Vt["[object Map]"]=Vt["[object Number]"]=Vt["[object Object]"]=Vt["[object RegExp]"]=Vt["[object Set]"]=Vt["[object String]"]=Vt["[object WeakMap]"]=!1;var Ht="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ut=Ht&&"object"==typeof module&&module&&!module.nodeType&&module,Wt=Ut&&Ut.exports===Ht&&L.process,Xt=function(){try{var t=Ut&&Ut.require&&Ut.require("util").types;return t||Wt&&Wt.binding&&Wt.binding("util")}catch(t){}}(),qt=Xt&&Xt.isTypedArray,Kt=qt?Gt(qt):function(t){return Pt(t)&&Yt(t.length)&&!!Vt[U(t)]},$t=Object.prototype.hasOwnProperty;function Qt(t,e){var n=St(t),r=!n&&zt(t),i=!n&&!r&&Ft(t),s=!n&&!r&&!i&&Kt(t),o=n||r||i||s,a=o?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],c=a.length;for(var l in t)!e&&!$t.call(t,l)||o&&("length"==l||i&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Nt(l,c))||a.push(l);return a}var Zt=Object.prototype;function Jt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Zt)}function te(t,e){return function(n){return t(e(n))}}var ee=te(Object.keys,Object),ne=Object.prototype.hasOwnProperty;function re(t){if(!Jt(t))return ee(t);var e=[];for(var n in Object(t))ne.call(t,n)&&"constructor"!=n&&e.push(n);return e}function ie(t){return null!=t&&Yt(t.length)&&!X(t)}function se(t){return ie(t)?Qt(t):re(t)}function oe(t){return function(t,e,n){var r=e(t);return St(t)?r:Mt(r,n(t))}(t,se,Ct)}var ae=Object.prototype.hasOwnProperty;var ce=ot(R,"DataView"),le=ot(R,"Promise"),he=ot(R,"Set"),de=ot(R,"WeakMap"),ue="[object Map]",pe="[object Promise]",fe="[object Set]",ge="[object WeakMap]",me="[object DataView]",ye=Z(ce),be=Z(at),ve=Z(le),xe=Z(he),_e=Z(de),we=U;(ce&&we(new ce(new ArrayBuffer(1)))!=me||at&&we(new at)!=ue||le&&we(le.resolve())!=pe||he&&we(new he)!=fe||de&&we(new de)!=ge)&&(we=function(t){var e=U(t),n="[object Object]"==e?t.constructor:void 0,r=n?Z(n):"";if(r)switch(r){case ye:return me;case be:return ue;case ve:return pe;case xe:return fe;case _e:return ge}return e});var Me="[object Arguments]",Se="[object Array]",Ae="[object Object]",ke=Object.prototype.hasOwnProperty;function Ee(t,e,n,r,i,s){var o=St(t),a=St(e),c=o?Se:we(t),l=a?Se:we(e),h=(c=c==Me?Ae:c)==Ae,d=(l=l==Me?Ae:l)==Ae,u=c==l;if(u&&Ft(t)){if(!Ft(e))return!1;o=!0,h=!1}if(u&&!h)return s||(s=new ft),o||Kt(t)?yt(t,e,n,r,i,s):function(t,e,n,r,i,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 bt(t),new bt(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return O(+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=vt;case"[object Set]":var c=1&r;if(a||(a=xt),t.size!=e.size&&!c)return!1;var l=o.get(t);if(l)return l==e;r|=2,o.set(t,e);var h=yt(a(t),a(e),r,i,s,o);return o.delete(t),h;case"[object Symbol]":if(wt)return wt.call(t)==wt.call(e)}return!1}(t,e,c,n,r,i,s);if(!(1&n)){var p=h&&ke.call(t,"__wrapped__"),f=d&&ke.call(e,"__wrapped__");if(p||f){var g=p?t.value():t,m=f?e.value():e;return s||(s=new ft),i(g,m,n,r,s)}}return!!u&&(s||(s=new ft),function(t,e,n,r,i,s){var o=1&n,a=oe(t),c=a.length;if(c!=oe(e).length&&!o)return!1;for(var l=c;l--;){var h=a[l];if(!(o?h in e:ae.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(r)var y=o?r(m,g,h,e,t,s):r(g,m,h,t,e,s);if(!(void 0===y?g===m||i(g,m,n,r,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,r,i,s))}function Ce(t,e,n,r,i){return t===e||(null==t||null==e||!Pt(t)&&!Pt(e)?t!=t&&e!=e:Ee(t,e,n,r,Ce,i))}var Pe=function(){try{var t=ot(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Te(t,e,n){"__proto__"==e&&Pe?Pe(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var Oe=Object.prototype.hasOwnProperty;function De(t,e,n){var r=t[e];Oe.call(t,e)&&O(r,n)&&(void 0!==n||e in t)||Te(t,e,n)}function Ie(t,e,n,r){var i=!n;n||(n={});for(var s=-1,o=e.length;++s<o;){var a=e[s],c=r?r(n[a],t[a],a,n,t):void 0;void 0===c&&(c=t[a]),i?Te(n,a,c):De(n,a,c)}return n}function ze(t){return t}function Le(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 je=Math.max;function Re(t){return function(){return t}}var Fe=Pe?function(t,e){return Pe(t,"toString",{configurable:!0,enumerable:!1,value:Re(e),writable:!0})}:ze,Be=Date.now;var Ne=function(t){var e=0,n=0;return function(){var r=Be(),i=16-(r-n);if(n=r,i>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Fe);function Ye(t,e){return Ne(function(t,e,n){return e=je(void 0===e?t.length-1:e,0),function(){for(var r=arguments,i=-1,s=je(r.length-e,0),o=Array(s);++i<s;)o[i]=r[e+i];i=-1;for(var a=Array(e+1);++i<e;)a[i]=r[i];return a[e]=n(o),Le(t,this,a)}}(t,e,ze),t+"")}function Ve(t,e,n){if(!W(n))return!1;var r=typeof e;return!!("number"==r?ie(n)&&Nt(e,n.length):"string"==r&&e in n)&&O(n[e],t)}var Ge=Object.prototype.hasOwnProperty;function He(t){if(!W(t))return function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}(t);var e=Jt(t),n=[];for(var r in t)("constructor"!=r||!e&&Ge.call(t,r))&&n.push(r);return n}function Ue(t){return ie(t)?Qt(t,!0):He(t)}var We,Xe=(We=function(t,e,n,r){Ie(e,Ue(e),t,r)},Ye(function(t,e){var n=-1,r=e.length,i=r>1?e[r-1]:void 0,s=r>2?e[2]:void 0;for(i=We.length>3&&"function"==typeof i?(r--,i):void 0,s&&Ve(e[0],e[1],s)&&(i=r<3?void 0:i,r=1),t=Object(t);++n<r;){var o=e[n];o&&We(t,o,n,i)}return t})),qe=te(Object.getPrototypeOf,Object),Ke=Function.prototype,$e=Object.prototype,Qe=Ke.toString,Ze=$e.hasOwnProperty,Je=Qe.call(Object);function tn(t){if(!Pt(t))return!1;var e=U(t);return"[object Error]"==e||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!function(t){if(!Pt(t)||"[object Object]"!=U(t))return!1;var e=qe(t);if(null===e)return!0;var n=Ze.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&Qe.call(n)==Je}(t)}var en=Ye(function(t,e){try{return Le(t,void 0,e)}catch(t){return tn(t)?t:new Error(t)}});function nn(t,e){for(var n=-1,r=null==t?0:t.length,i=Array(r);++n<r;)i[n]=e(t[n],n,t);return i}var rn=Object.prototype,sn=rn.hasOwnProperty;function on(t,e,n,r){return void 0===t||O(t,rn[n])&&!sn.call(r,n)?e:t}var an={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"};function cn(t){return"\\"+an[t]}var ln=/<%=([\s\S]+?)%>/g;var hn,dn=(hn={"&":"&","<":"<",">":">",'"':""","'":"'"},function(t){return null==hn?void 0:hn[t]});function un(t){return"symbol"==typeof t||Pt(t)&&"[object Symbol]"==U(t)}var pn=F?F.prototype:void 0,fn=pn?pn.toString:void 0;function gn(t){if("string"==typeof t)return t;if(St(t))return nn(t,gn)+"";if(un(t))return fn?fn.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function mn(t){return null==t?"":gn(t)}var yn=/[&<>"']/g,bn=RegExp(yn.source);var vn={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:ln,variable:"",imports:{_:{escape:function(t){return(t=mn(t))&&bn.test(t)?t.replace(yn,dn):t}}}},xn=/\b__p \+= '';/g,_n=/\b(__p \+=) '' \+/g,wn=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Mn=/[()=,{}\[\]\/\s]/,Sn=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,An=/($^)/,kn=/['\n\r\u2028\u2029\\]/g,En=Object.prototype.hasOwnProperty;var Cn="object"==typeof exports&&exports&&!exports.nodeType&&exports,Pn=Cn&&"object"==typeof module&&module&&!module.nodeType&&module,Tn=Pn&&Pn.exports===Cn?R.Buffer:void 0,On=Tn?Tn.allocUnsafe:void 0;var Dn=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Mt(e,Ct(t)),t=qe(t);return e}:At;var In=Object.prototype.hasOwnProperty;var zn=/\w*$/;var Ln=F?F.prototype:void 0,jn=Ln?Ln.valueOf:void 0;function Rn(t,e,n){var r,i,s,o,a,c=t.constructor;switch(e){case"[object ArrayBuffer]":return a=new(o=t).constructor(o.byteLength),new bt(a).set(new bt(o)),a;case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return s=(i=t).buffer,new i.constructor(s,i.byteOffset,i.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,zn.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return r=t,jn?Object(jn.call(r)):{}}}var Fn=Object.create,Bn=function(){function t(){}return function(e){if(!W(e))return{};if(Fn)return Fn(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}();var Nn=Xt&&Xt.isMap,Yn=Nn?Gt(Nn):function(t){return Pt(t)&&"[object Map]"==we(t)};var Vn=Xt&&Xt.isSet,Gn=Vn?Gt(Vn):function(t){return Pt(t)&&"[object Set]"==we(t)},Hn="[object Arguments]",Un="[object Function]",Wn="[object Object]",Xn={};function qn(t,e,n,r,i,s){var o,a=2&e;if(void 0!==o)return o;if(!W(t))return t;var c=St(t);if(c)return o=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&In.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}(t,o);var l=we(t),h=l==Un||"[object GeneratorFunction]"==l;if(Ft(t))return function(t){var e=t.length,n=On?On(e):new t.constructor(e);return t.copy(n),n}(t);if(l==Wn||l==Hn||h&&!i)return o=h?{}:function(t){return"function"!=typeof t.constructor||Jt(t)?{}:Bn(qe(t))}(t),a?function(t,e){return Ie(t,Dn(t),e)}(t,function(t,e){return t&&Ie(e,Ue(e),t)}(o,t)):function(t,e){return Ie(t,Ct(t),e)}(t,function(t,e){return t&&Ie(e,se(e),t)}(o,t));if(!Xn[l])return i?t:{};o=Rn(t,l),s||(s=new ft);var d=s.get(t);if(d)return d;s.set(t,o),Gn(t)?t.forEach(function(r){o.add(qn(r,e,n,r,t,s))}):Yn(t)&&t.forEach(function(r,i){o.set(i,qn(r,e,n,i,t,s))});var u=c?void 0:oe(t);return function(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););}(u||t,function(r,i){u&&(r=t[i=r]),De(o,i,qn(r,e,n,i,t,s))}),o}Xn[Hn]=Xn["[object Array]"]=Xn["[object ArrayBuffer]"]=Xn["[object DataView]"]=Xn["[object Boolean]"]=Xn["[object Date]"]=Xn["[object Float32Array]"]=Xn["[object Float64Array]"]=Xn["[object Int8Array]"]=Xn["[object Int16Array]"]=Xn["[object Int32Array]"]=Xn["[object Map]"]=Xn["[object Number]"]=Xn[Wn]=Xn["[object RegExp]"]=Xn["[object Set]"]=Xn["[object String]"]=Xn["[object Symbol]"]=Xn["[object Uint8Array]"]=Xn["[object Uint8ClampedArray]"]=Xn["[object Uint16Array]"]=Xn["[object Uint32Array]"]=!0,Xn["[object Error]"]=Xn[Un]=Xn["[object WeakMap]"]=!1;function Kn(t){return qn(t,4)}var $n=function(){return R.Date.now()},Qn=/\s/;var Zn=/^\s+/;function Jn(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Qn.test(t.charAt(e)););return e}(t)+1).replace(Zn,""):t}var tr=/^[-+]0x[0-9a-f]+$/i,er=/^0b[01]+$/i,nr=/^0o[0-7]+$/i,rr=parseInt;function ir(t){if("number"==typeof t)return t;if(un(t))return NaN;if(W(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=W(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Jn(t);var n=er.test(t);return n||nr.test(t)?rr(t.slice(2),n?2:8):tr.test(t)?NaN:+t}var sr=Math.max,or=Math.min;function ar(t,e,n){var r,i,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=r,s=i;return r=i=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=$n();if(f(t))return m(t);a=setTimeout(g,function(t){var n=e-(t-c);return d?or(n,s-(t-l)):n}(t))}function m(t){return a=void 0,u&&r?p(t):(r=i=void 0,o)}function y(){var t=$n(),n=f(t);if(r=arguments,i=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=ir(e)||0,W(n)&&(h=!!n.leading,s=(d="maxWait"in n)?sr(ir(n.maxWait)||0,e):s,u="trailing"in n?!!n.trailing:u),y.cancel=function(){void 0!==a&&clearTimeout(a),l=0,r=c=i=a=void 0},y.flush=function(){return void 0===a?o:m($n())},y}function cr(t,e,n){var r=!0,i=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return W(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),ar(t,e,{leading:r,maxWait:e,trailing:i})}var lr=1/0;function hr(t){var e=function(t){return t?(t=ir(t))===lr||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 dr(t){return function(t,e){var n;if("function"!=typeof e)throw new TypeError("Expected a function");return t=hr(t),function(){return--t>0&&(n=e.apply(this,arguments)),t<=1&&(e=void 0),n}}(2,t)}var ur=Object.prototype.hasOwnProperty;function pr(t){if(null==t)return!0;if(ie(t)&&(St(t)||"string"==typeof t||"function"==typeof t.splice||Ft(t)||Kt(t)||zt(t)))return!t.length;var e=we(t);if("[object Map]"==e||"[object Set]"==e)return!t.size;if(Jt(t))return!re(t).length;for(var n in t)if(ur.call(t,n))return!1;return!0}let fr=0;function gr(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 r;return r="object"!=typeof e[n]?t:gr({},t),r}):t[n]=gr(t[n],e[n])}),t}function mr(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 yr(t,e){if(!this.__collection__)return this;return-1==this.__collection__.indexOf(e)&&this.__collection__.splice(t,0,e),this}function br(t){return this.__collection__||(this.__collection__=[]),-1==this.__collection__.indexOf(t)&&this.__collection__.push(t),this}function vr(t){return this.__collection__||(this.__collection__=[]),-1==this.__collection__.indexOf(t)&&this.__collection__.unshift(t),this}function xr(t){if(!this.__collection__)return this;const e=this.__collection__.indexOf(t);return e>=0&&this.__collection__.splice(e,1),this}function _r(t){if(this.__collection__)return this.__collection__[t]}function wr(t,e){this.__collection__&&this.__collection__.forEach(t,e)}function Mr(t){return this.__collection__?this.__collection__.indexOf(t):-1}function Sr(){return this.__collection__?this.__collection__.length:0}function Ar(){this.__collection__=[]}function kr(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this.__collection__[e]=this.__collection__[e-1],this.__collection__[e-1]=t)}function Er(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 Cr(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this.__collection__.splice(0,e),r=this.__collection__.splice(1);this.__collection__=this.__collection__.concat(n,r)}function Pr(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this.__collection__.splice(0,e),r=this.__collection__.splice(1);this.__collection__=n.concat(r,this.__collection__)}class Tr{constructor(){this.__collection__=[],this.insertAt=yr,this.append=br,this.prepend=vr,this.remove=xr,this.getAt=_r,this.forEach=wr,this.indexOf=Mr,this.size=Sr,this.clear=Ar,this.moveForward=kr,this.moveBackward=Er,this.moveToHead=Cr,this.moveToTail=Pr}}const Or=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,r=this._getResidents?.()??null;let i=0;if(this._lastSnapshotTime>0){const e=t-this._lastSnapshotTime;e>0&&(i=Math.round(1e3*this._frameCount/e))}this._lastSnapshotTime=t,this._frameCount=0;const s={fps:i,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,...r??{}};return this.drawCount=0,this.drawTimeSum=0,this.invalidateCount=0,this.triggerCount=0,this.cacheHit=0,this.cacheMiss=0,s}},Dr=/\s+/;function Ir(t,e,n,r){if(!n)return!0;if("object"==typeof n){for(const r in n){const i=n[r];t[e].apply(t,[r,i])}return!1}if(Dr.test(n)){return n.split(Dr).forEach(n=>t[e].apply(t,[n].concat(r))),!1}return!0}const zr=["on","off","once","delegate_on","delegate_off","trigger","listenTo"],Lr={withEvent(){zr.forEach(t=>this[t]=Lr[t])},on(t,e,n){if(!Ir(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(!Ir(this,"once",t,[e,n])||!e)return this;const r=this,i=dr(function(){r.off(t,i,n),e.apply(r,arguments)});return i._callback=e,this.on(t,i,n),this},off(t,e,n){if(!this._listeners||!Ir(this,"off",t,[e,n]))return this;if(!t&&!e&&!n)return this._listeners=void 0,this;let r;r=t&&"string"==typeof t?[t]:Object.keys(this._listeners||{});for(let t=0;t<r.length;t++){const i=r[t],s=this._listeners?.[i];if(s){const t=[];if(this._listeners[i]=t,e||n)for(let r=0;r<s.length;r++){const i=s[r];(e&&e!==i.callback&&e!==i.callback._callback||n&&n!==i.context)&&t.push(i)}t.length||delete this._listeners[i]}}return this},delegate_on(t){return this._delegators||(this._delegators=new Tr),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&&Rr(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],r=this._listeners["(all)"];return n&&jr(n,arguments),r&&jr(r,arguments),this},trigger(t){Or.triggerCount++;const e=[].slice.call(arguments,1);if(e.push({origin:this,name:t,deliverer:this}),this._delegators&&this._delegators.size()>0&&Rr(this._delegators,e),!this._listeners)return this;if(!Ir(this,"trigger",t,e))return this;const n=this._listeners[t],r=this._listeners["(all)"];return n&&jr(n,e),r&&jr(r,e),this},stopListening(t,e,n){let r=this._listeningTo;if(!r)return this;const i=!e&&!n;n||"object"!=typeof e||(n=this),t&&(r={},r[t._listenId]=t);for(const t in r){const s=r[t];s.off(e,n,this),(i||pr(s._events))&&delete this._listeningTo[t]}return this}};function jr(t,e){t.forEach(t=>t.callback.apply(t.ctx,e))}function Rr(t,e){t.forEach(t=>Lr.delegate.apply(t,e))}const Fr={listenTo:"on",listenToOnce:"once"};for(const t in Fr){const e=Fr[t];Lr[t]=function(t,n,r){this._listeningTo||(this._listeningTo={});const i=this._listeningTo;t._listenId||(t._listenId=`${"l"}${++fr}`);return i[t._listenId]=t,r||"object"!=typeof n||(r=this),t[e](n,r,this),this}}const Br=Lr.on,Nr=Lr.off,Yr=Lr.once,Vr=Lr.trigger,Gr=Lr.delegate_on,Hr=Lr.delegate_off;function Ur(t,e){if(e instanceof Array)e.forEach(e=>Ur(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 Wr=(...t)=>{const e=[];t.forEach(t=>t&&t.stack&&e.push(t.stack)),console.error("[ERROR]",...t,e.join(" "))},Xr=(...t)=>{const e=[];t.forEach(t=>t&&t.stack&&e.push(t.stack)),console.warn("[WARN]",...t,e.join(" "))},qr=(...t)=>console.log("[DEBUG]",...t);function Kr(t,e,n){const r=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(!r?.get)return void Wr(`${String(e)} is not defined in ${t.constructor.name}`);const i=r.get,s={get:n?function(){return e in this.__cache__?Or.cacheHit++:(Or.cacheMiss++,this.__cache__[e]=Object.freeze(i.call(this))),this.__cache__[e]}:function(){return e in this.__cache__?Or.cacheHit++:(Or.cacheMiss++,this.__cache__[e]=i.call(this)),this.__cache__[e]},configurable:!0};r.set&&(s.set=r.set),Object.defineProperty(t,e,s)}var $r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Qr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Zr(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 Jr,ti={exports:{}};var ei=(Jr||(Jr=1,function(t){var e=function(t){var e,n=Object.prototype,r=n.hasOwnProperty,i=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,r){var s=e&&e.prototype instanceof y?e:y,o=Object.create(s.prototype),a=new T(r||[]);return i(o,"_invoke",{value:k(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 x={};l(x,o,function(){return this});var _=Object.getPrototypeOf,w=_&&_(_(O([])));w&&w!==n&&r.call(w,o)&&(x=w);var M=v.prototype=y.prototype=Object.create(x);function S(t){["next","throw","return"].forEach(function(e){l(t,e,function(t){return this._invoke(e,t)})})}function A(t,e){function n(i,s,o,a){var c=d(t[i],t,s);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==typeof h&&r.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;i(this,"_invoke",{value:function(t,r){function i(){return new e(function(e,i){n(t,r,e,i)})}return s=s?s.then(i,i):i()}})}function k(t,n,r){var i=u;return function(s,o){if(i===f)throw new Error("Generator is already running");if(i===g){if("throw"===s)throw o;return{value:e,done:!0}}for(r.method=s,r.arg=o;;){var a=r.delegate;if(a){var c=E(a,r);if(c){if(c===m)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===u)throw i=g,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=f;var l=d(t,n,r);if("normal"===l.type){if(i=r.done?g:p,l.arg===m)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(i=g,r.method="throw",r.arg=l.arg)}}}function E(t,n){var r=n.method,i=t.iterator[r];if(i===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,E(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var s=d(i,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 P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(C,this),this.reset(!0)}function O(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 i=-1,s=function n(){for(;++i<t.length;)if(r.call(t,i))return n.value=t[i],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,i(M,"constructor",{value:v,configurable:!0}),i(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(A.prototype),l(A.prototype,a,function(){return this}),t.AsyncIterator=A,t.async=function(e,n,r,i,s){void 0===s&&(s=Promise);var o=new A(h(e,n,r,i),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 r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},t.values=O,T.prototype={constructor:T,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(P),!t)for(var n in this)"t"===n.charAt(0)&&r.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 i(r,i){return a.type="throw",a.arg=t,n.next=r,i&&(n.method="next",n.arg=e),!!i}for(var s=this.tryEntries.length-1;s>=0;--s){var o=this.tryEntries[s],a=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var c=r.call(o,"catchLoc"),l=r.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&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var s=i;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),P(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 r=n.completion;if("throw"===r.type){var i=r.arg;P(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:O(t),resultName:n,nextLoc:r},"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=[],r=0,i="",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?r=n.push(a):(a-=65536,r=n.push(55296+(a>>10),a%1024+56320)),r>=16383&&(i+=t.apply(null,n),n.length=0)}return i+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
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,r=t?Number(t):0;if(r!=r&&(r=0),!(r<0||r>=n)){var i,s=e.charCodeAt(r);return s>=55296&&s<=56319&&n>r+1&&(i=e.charCodeAt(r+1))>=56320&&i<=57343?1024*(s-55296)+i-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,r){function i(o,a){if(!n[o]){if(!e[o]){if(!a&&Zr)return Zr(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 i(e[o][1][t]||t)},l,l.exports,t,e,n,r)}return n[o].exports}for(var s=Zr,o=0;o<r.length;o++)i(r[o]);return i}return t}()({1:[function(t,e,n){var r=t("./utils"),i=function(){var t=r.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"],i=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],s=["Thousand","Million","Billion","Trillion"];function o(t,r){var o=function t(r,o,a){var c="";if(r<=19)c=(o?" and ":"")+(a?n[r]:e[r]);else if(r<100){var l=Math.floor(r/10),h=r%10;c=(o?" and ":"")+i[l-2],h>0?c+="-"+t(h,!1,a):a&&(c=c.substring(0,c.length-1)+"ieth")}else if(r<1e3){var d=Math.floor(r/100),u=r%100;c=(o?", ":"")+e[d]+" Hundred",u>0?c+=t(u,!0,a):a&&(c+="th")}else{var p=Math.floor(Math.log10(r)/3);p>s.length&&(p=s.length);var f=Math.pow(10,3*p),g=Math.floor(r/f),m=r-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,r)}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}),i.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(),r=Math.pow(10,3*(e+1));a[n]=r,a[n+"th"]=r});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,r=t.length-1;r>=0;r--){var i=t[r],s=h[i];s<n?e-=s:(n=s,e+=s)}return e}function p(t,e){for(var n=[],r=e.charCodeAt(0);t>0;)n.unshift(String.fromCharCode((t-1)%26+r)),t=Math.floor((t-1)/26);return n.join("")}function f(t,e){for(var n=e.charCodeAt(0),r=0,i=0;i<t.length;i++)r+=(t.charCodeAt(t.length-i-1)-n+1)*Math.pow(26,i);return r}function g(t,e){if(void 0!==t)return b(t=Math.floor(t),x(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 r,i=e<0;switch(e=Math.abs(e),n.primary){case m.LETTERS:r=p(e,n.case===y.UPPER?"A":"a");break;case m.ROMAN:r=d(e),n.case===y.UPPER&&(r=r.toUpperCase());break;case m.WORDS:r=o(e,n.ordinal),n.case===y.UPPER?r=r.toUpperCase():n.case===y.LOWER&&(r=r.toLowerCase());break;case m.DECIMAL:r=""+e;var s=n.mandatoryDigits-r.length;if(s>0){var a=new Array(s+1).join("0");r=a+r}if(48!==n.zeroCode&&(r=t(r).map(function(t){return String.fromCodePoint(t.codePointAt(0)+n.zeroCode-48)}).join("")),n.regular)for(var c=Math.floor((r.length-1)/n.groupingSeparators.position);c>0;c--){var l=r.length-c*n.groupingSeparators.position;r=r.substr(0,l)+n.groupingSeparators.character+r.substr(l)}else n.groupingSeparators.reverse().forEach(function(t){var e=r.length-t.position;r=r.substr(0,e)+t.character+r.substr(e)});if(n.ordinal){var h={1:"st",2:"nd",3:"rd"}[r[r.length-1]];(!h||r.length>1&&"1"===r[r.length-2])&&(h="th"),r+=h}break;case m.SEQUENCE:throw{code:"D3130",value:n.token}}return i&&(r="-"+r),r}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 x(e){var n,r={type:"integer",primary:m.DECIMAL,case:y.LOWER,ordinal:!1},i=e.lastIndexOf(";");switch(-1===i?n=e:(n=e.substring(0,i),"o"===e.substring(i+1)[0]&&(r.ordinal=!0)),n){case"A":r.case=y.UPPER;case"a":r.primary=m.LETTERS;break;case"I":r.case=y.UPPER;case"i":r.primary=m.ROMAN;break;case"W":r.case=y.UPPER,r.primary=m.WORDS;break;case"Ww":r.case=y.TITLE,r.primary=m.WORDS;break;case"w":r.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 r=v[n];if(t>=r&&t<=r+9){if(e=!0,o++,l++,null===s)s=r;else if(r!==s)throw{code:"D3131"};break}}e||(35===t?(l++,a++):c.push({position:l,character:String.fromCodePoint(t)}))}),o>0){r.primary=m.DECIMAL,r.zeroCode=s,r.mandatoryDigits=o,r.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 r=t.map(function(t){return t.position}),i=function t(e,n){return 0===n?e:t(n,e%n)},s=r.reduce(i),o=1;o<=r.length;o++)if(-1===r.indexOf(o*s))return 0;return s}(c);h>0?(r.regular=!0,r.groupingSeparators={position:h,character:c[0].character}):(r.regular=!1,r.groupingSeparators=c)}else r.primary=m.SEQUENCE,r.token=n}return r}var _={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},r=function(n,r){if(r>n){var i=t.substring(n,r);i=i.split("]]").join("]"),e.push({type:"literal",value:i})}},i=0,s=0;s<t.length;){if("["===t.charAt(s)){if("["===t.charAt(s+1)){r(i,s),e.push({type:"literal",value:"["}),i=s+=2;continue}if(r(i,s),i=s,-1===(s=t.indexOf("]",i)))throw{code:"D3135"};var o,a=t.substring(i+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=_[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=x(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=x(c.presentation1)),e.push(c),i=s+1}s++}return r(i,s),n}var M=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],S=["January","February","March","April","May","June","July","August","September","October","November","December"],A=864e5,k=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)*A:e-(n-1)*A},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*A)+1},P=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))/A+1;break;case"F":0===(n=t.getUTCDay())&&(n=7);break;case"W":var r=E(t.getUTCFullYear(),0),i=k(r),s=Date.UTC(r.year,t.getUTCMonth(),t.getUTCDate()),o=C(i,s);if(o>52)s>=k(r.nextYear())&&(o=1);else if(o<1){var a=k(r.previousYear());o=C(a,s)}n=Math.floor(o);break;case"w":var c=E(t.getUTCFullYear(),t.getUTCMonth()),l=k(c),h=Date.UTC(c.year,c.month,t.getUTCDate()),d=C(l,h);if(d>4)h>=k(c.nextMonth())&&(d=1);else if(d<1){var u=k(c.previousMonth());d=C(u,h)}n=Math.floor(d);break;case"X":var p=E(t.getUTCFullYear(),0),f=k(p),g=k(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=k(y),v=y.nextMonth(),x=k(v),_=t.getTime();n=_<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},T=null;function O(t,e,n){var r=0,i=0;if(void 0!==n){var s=parseInt(n);r=Math.floor(s/100),i=s%100}var o,a=function(t,e){var n=P(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*r+i;if(e.integerFormat.regular)n=b(s,e.integerFormat);else{var o=e.integerFormat.mandatoryDigits;if(1===o||2===o)n=b(r,e.integerFormat),0!==i&&(n+=":"+g(i,"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===T&&(T=w("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),o=T):o=w(e);var c=new Date(t+60*(60*r+i)*1e3),l="";return o.parts.forEach(function(t){"literal"===t.type?l+=t.value:l+=a(c,t)}),l}function D(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 r=0,i=0;return n?(r=Number.parseInt(e.substring(0,e.indexOf(n.character))),i=Number.parseInt(e.substring(e.indexOf(n.character)+1))):e.length-1<=2?r=Number.parseInt(e):(r=Number.parseInt(e.substring(0,3)),i=Number.parseInt(e.substring(3))),60*r+i}}else if(t.integerFormat)t.integerFormat.n=t.n,e=D(t.integerFormat);else{e.regex="[a-zA-Z]+";var r={};if("M"===t.component||"x"===t.component)S.forEach(function(e,n){t.width&&t.width.max?r[e.substring(0,t.width.max)]=n+1:r[e]=n+1});else if("F"===t.component)M.forEach(function(e,n){n>0&&(t.width&&t.width.max?r[e.substring(0,t.width.max)]=n:r[e]=n)});else{if("P"!==t.component)throw{code:"D3133",value:t.component};r={am:0,AM:0,pm:1,PM:1}}e.parse=function(t){return r[t]}}return e.component=t.component,e});else{e.type="integer";var n,r=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=r?"[A-Z]+":"[a-z]+",e.parse=function(t){return f(t,r?"A":"a")};break;case m.ROMAN:e.regex=r?"[MDCLXVI]+":"[mdclxvi]+",e.parse=function(t){return u(r?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 I(t,e){if(void 0!==t)return D(x(e)).parse(t)}function z(t,e){var n=D(w(e)),r="^"+n.parts.map(function(t){return"("+t.regex+")"}).join("")+"$",i=new RegExp(r,"i").exec(t);if(null!==i){for(var s=161,o=130,a=84,c=72,l=23,h=47,d={},u=1;u<i.length;u++){var p=n.parts[u-1];p.parse&&(d[p.component]=p.parse(i[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 x=!m(l)&&m(h),_=(y?"YD":b?"XxwF":v?"XWF":"YMD")+(x?"Phmsf":"Hmsf"),M=this.environment.timestamp,S=!1,A=!1;if(_.split("").forEach(function(t){if(void 0===d[t])S?(d[t]=-1!=="MDd".indexOf(t)?1:0,A=!0):d[t]=P(M,t);else if(S=!0,A)throw{code:"D3136"}}),d.M>0?d.M-=1:d.M=0,y){var k=Date.UTC(d.Y,0),E=1e3*(d.d-1)*60*60*24,C=new Date(k+E);d.M=C.getUTCMonth(),d.D=C.getUTCDate()}if(b)throw{code:"D3136"};if(v)throw{code:"D3136"};x&&(d.H=12===d.h?0:d.h,1===d.P&&(d.H+=12));var T=Date.UTC(d.Y,d.M,d.D,d.H,d.m,d.s,d.f);return(d.Z||d.z)&&(T-=60*(d.Z||d.z)*1e3),T}}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 z.call(this,t,e)}}function R(t,e,n){if(void 0!==t)return O.call(this,t,e,n)}return{formatInteger:g,parseInteger:I,fromMillis:R,toMillis:j}}();e.exports=i},{"./utils":6}],2:[function(t,e,n){(function(n){(function(){function r(t){return r="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},r(t)}function i(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */i=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,r){var i=e&&e.prototype instanceof v?e:v,s=Object.create(i.prototype),a=new D(r||[]);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 x(){}function _(){}var w={};d(w,c,function(){return this});var M=Object.getPrototypeOf,S=M&&M(M(I([])));S&&S!==n&&s.call(S,c)&&(w=S);var A=_.prototype=v.prototype=Object.create(w);function k(t){["next","throw","return"].forEach(function(e){d(t,e,function(t){return this._invoke(e,t)})})}function E(t,e){function n(i,o,a,c){var l=p(t[i],t,o);if("throw"!==l.type){var h=l.arg,d=h.value;return d&&"object"==r(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 i;o(this,"_invoke",{value:function(t,r){function s(){return new e(function(e,i){n(t,r,e,i)})}return i=i?i.then(s,s):s()}})}function C(e,n,r){var i=f;return function(s,o){if(i===m)throw new Error("Generator is already running");if(i===y){if("throw"===s)throw o;return{value:t,done:!0}}for(r.method=s,r.arg=o;;){var a=r.delegate;if(a){var c=P(a,r);if(c){if(c===b)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===f)throw i=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=m;var l=p(e,n,r);if("normal"===l.type){if(i=r.done?y:g,l.arg===b)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(i=y,r.method="throw",r.arg=l.arg)}}}function P(e,n){var r=n.method,i=e.iterator[r];if(i===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,P(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),b;var s=p(i,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 T(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 O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function D(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function I(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 i=-1,o=function n(){for(;++i<e.length;)if(s.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(r(e)+" is not iterable")}return x.prototype=_,o(A,"constructor",{value:_,configurable:!0}),o(_,"constructor",{value:x,configurable:!0}),x.displayName=d(_,h,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===x||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,_):(t.__proto__=_,d(t,h,"GeneratorFunction")),t.prototype=Object.create(A),t},e.awrap=function(t){return{__await:t}},k(E.prototype),d(E.prototype,l,function(){return this}),e.AsyncIterator=E,e.async=function(t,n,r,i,s){void 0===s&&(s=Promise);var o=new E(u(t,n,r,i),s);return e.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},k(A),d(A,h,"Generator"),d(A,c,function(){return this}),d(A,"toString",function(){return"[object Generator]"}),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=I,D.prototype={constructor:D,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(O),!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 r(r,i){return a.type="throw",a.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("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 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&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=t,o.arg=e,i?(this.method="next",this.next=i.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),O(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 r=n.completion;if("throw"===r.type){var i=r.arg;O(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:I(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),b}},e}var s=t("./utils"),o=function(){var t=i().mark(Y),e=i().mark(V),o=i().mark(G),a=i().mark(H),c=i().mark(Q),l=i().mark(ut),h=i().mark(pt),d=i().mark(ft),u=i().mark(mt),p=i().mark(St),f=i().mark(Ct),g=i().mark(Ot),m=s.isNumeric,y=s.isArrayOfStrings,b=s.isArrayOfNumbers,v=s.createSequence,x=s.isSequence,_=s.isFunction,w=s.isLambda,M=s.isIterable,S=s.getFunctionArity,A=s.isDeepEqual,k=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 P(t){if(void 0!==t&&0!==t.length)return Math.max.apply(Math,t)}function T(t){if(void 0!==t&&0!==t.length)return Math.min.apply(Math,t)}function O(t){if(void 0!==t&&0!==t.length){var e=0;return t.forEach(function(t){e+=t}),e/t.length}}function D(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(_(t))n="";else{if("number"==typeof t&&!isFinite(t))throw{code:"D3001",value:t,stack:(new Error).stack};var r=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&&_(e)?"":e},r)}return n}}function I(t,e,n){if(void 0!==t){var r=k(t),i=r.length;if(i+e<0&&(e=0),void 0!==n){if(n<=0)return"";var s=e>=0?e+n:i+e+n;return r.slice(e,s).join("")}return r.slice(e).join("")}}function z(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 k(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 r;void 0!==n&&0!==n.length||(n=" ");var i=Math.abs(e)-F(t);if(i>0){var s=new Array(i+1).join(n);n.length>1&&(s=I(s,0,i)),r=e>0?t+s:s+t}else r=t;return r}}function Y(e,n){var r;return i().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.apply(this,[n]),!M(r)){t.next=4;break}return t.delegateYield(r,"t0",3);case 3:r=t.t0;case 4:if(!r||"number"==typeof r.start||"number"===r.end||Array.isArray(r.groups)||_(r.next)){t.next=6;break}throw{code:"T1010",stack:(new Error).stack};case 6:return t.abrupt("return",r);case 7:case"end":return t.stop()}},t,this)}function V(t,n){var r,s;return i().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}r=-1!==t.indexOf(n),e.next=9;break;case 6:return e.delegateYield(Y(n,t),"t0",7);case 7:s=e.t0,r=void 0!==s;case 9:return e.abrupt("return",r);case 10:case"end":return e.stop()}},e)}function G(t,e,n){var r,s,a;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:if(!(n<0)){i.next=4;break}throw{stack:(new Error).stack,value:n,code:"D3040",index:3};case 4:if(r=v(),!(void 0===n||n>0)){i.next=17;break}return s=0,i.delegateYield(Y(e,t),"t0",8);case 8:if(void 0===(a=i.t0)){i.next=17;break}case 10:if(void 0===a||!(void 0===n||s<n)){i.next=17;break}return r.push({match:a.match,index:a.start,groups:a.groups}),i.delegateYield(Y(a.next),"t1",13);case 13:a=i.t1,s++,i.next=10;break;case 17:return i.abrupt("return",r);case 18:case"end":return i.stop()}},o)}function H(t,e,n,r){var s,o,c,l,h,d,u,p;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:if(s=this,""!==e){i.next=5;break}throw{code:"D3010",stack:(new Error).stack,value:e,index:2};case 5:if(!(r<0)){i.next=7;break}throw{code:"D3011",stack:(new Error).stack,value:r,index:4};case 7:if(o="string"==typeof n?function(t){for(var e="",r=0,i=n.indexOf("$",r);-1!==i&&r<n.length;){e+=n.substring(r,i),r=i+1;var s=n.charAt(r);if("$"===s)e+="$",r++;else if("0"===s)e+=t.match,r++;else{var o;if(o=0===t.groups.length?1:Math.floor(Math.log(t.groups.length)*Math.LOG10E)+1,i=parseInt(n.substring(r,r+o),10),o>1&&i>t.groups.length&&(i=parseInt(n.substring(r,r+o-1),10)),isNaN(i))e+="$";else{if(t.groups.length>0){var a=t.groups[i-1];void 0!==a&&(e+=a)}r+=i.toString().length}}i=n.indexOf("$",r)}return e+=n.substring(r)}:n,c="",l=0,!(void 0===r||r>0)){i.next=44;break}if(h=0,"string"!=typeof e){i.next=18;break}for(d=t.indexOf(e,l);-1!==d&&(void 0===r||h<r);)c+=t.substring(l,d),c+=n,l=d+e.length,h++,d=t.indexOf(e,l);c+=t.substring(l),i.next=42;break;case 18:return i.delegateYield(Y(e,t),"t0",19);case 19:if(void 0===(u=i.t0)){i.next=41;break}case 21:if(void 0===u||!(void 0===r||h<r)){i.next=38;break}if(c+=t.substring(l,u.start),p=o.apply(s,[u]),!M(p)){i.next=27;break}return i.delegateYield(p,"t1",26);case 26:p=i.t1;case 27:if("string"!=typeof p){i.next=31;break}c+=p,i.next=32;break;case 31:throw{code:"D3012",stack:(new Error).stack,value:p};case 32:return l=u.start+u.match.length,h++,i.delegateYield(Y(u.next),"t2",35);case 35:u=i.t2,i.next=21;break;case 38:c+=t.substring(l),i.next=42;break;case 41:c=t;case 42:i.next=45;break;case 44:c=t;case 45:return i.abrupt("return",c);case 46:case"end":return i.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 r,s,o,a;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:if(!(n<0)){i.next=4;break}throw{code:"D3020",stack:(new Error).stack,value:n,index:3};case 4:if(r=[],!(void 0===n||n>0)){i.next=27;break}if("string"!=typeof e){i.next=10;break}r=t.split(e,n),i.next=27;break;case 10:return s=0,i.delegateYield(Y(e,t),"t0",12);case 12:if(void 0===(o=i.t0)){i.next=26;break}a=0;case 15:if(void 0===o||!(void 0===n||s<n)){i.next=23;break}return r.push(t.substring(a,o.start)),a=o.end,i.delegateYield(Y(o.next),"t1",19);case 19:o=i.t1,s++,i.next=15;break;case 23:(void 0===n||s<n)&&r.push(t.substring(a)),i.next=27;break;case 26:r.push(t);case 27:return i.abrupt("return",r);case 28:case"end":return i.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 r={"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){r[t]=n[t]});for(var i=[],s=r["zero-digit"].charCodeAt(0),o=s;o<s+10;o++)i.push(String.fromCharCode(o));var a=i.concat([r["decimal-separator"],r["exponent-separator"],r["grouping-separator"],r.digit,r["pattern-separator"]]),c=e.split(r["pattern-separator"]);if(c.length>2)throw{code:"D3080",stack:(new Error).stack};var l=function(t){var e,n,i,s,o=function(){for(var e,n=0;n<t.length;n++)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==r["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!==r["exponent-separator"])return t.substring(n+1)}(),l=t.substring(o.length,t.length-c.length),h=t.indexOf(r["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(r["decimal-separator"]);return-1===d?(i=e,s=c):(i=e.substring(0,d),s=e.substring(d+1)),{prefix:o,suffix:c,activePart:l,mantissaPart:e,exponentPart:n,integerPart:i,fractionalPart:s,subpicture:t}},h=function(t){var e,n,s=t.subpicture,o=s.indexOf(r["decimal-separator"]);o!==s.lastIndexOf(r["decimal-separator"])&&(e="D3081"),s.indexOf(r.percent)!==s.lastIndexOf(r.percent)&&(e="D3082"),s.indexOf(r["per-mille"])!==s.lastIndexOf(r["per-mille"])&&(e="D3083"),-1!==s.indexOf(r.percent)&&-1!==s.indexOf(r["per-mille"])&&(e="D3084");var c=!1;for(n=0;n<t.mantissaPart.length;n++){var l=t.mantissaPart.charAt(n);if(-1!==i.indexOf(l)||l===r.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)!==r["grouping-separator"]&&s.charAt(o+1)!==r["grouping-separator"]||(e="D3087"):t.integerPart.charAt(t.integerPart.length-1)===r["grouping-separator"]&&(e="D3088"),-1!==s.indexOf(r["grouping-separator"]+r["grouping-separator"])&&(e="D3089");var h=t.integerPart.indexOf(r.digit);-1!==h&&t.integerPart.substring(0,h).split("").filter(function(t){return i.indexOf(t)>-1}).length>0&&(e="D3090"),-1!==(h=t.fractionalPart.lastIndexOf(r.digit))&&t.fractionalPart.substring(h).split("").filter(function(t){return i.indexOf(t)>-1}).length>0&&(e="D3091");var d="string"==typeof t.exponentPart;if(d&&t.exponentPart.length>0&&(-1!==s.indexOf(r.percent)||-1!==s.indexOf(r["per-mille"]))&&(e="D3092"),d&&(0===t.exponentPart.length||t.exponentPart.split("").filter(function(t){return-1===i.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(r["grouping-separator"]);-1!==o;){var a=(n?e.substring(0,o):e.substring(o)).split("").filter(function(t){return-1!==i.indexOf(t)||t===r.digit}).length;s.push(a),o=t.integerPart.indexOf(r["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),r=1;r<=t.length;r++)if(-1===t.indexOf(r*n))return 0;return n}(n),o=e(t.fractionalPart,!0),a=t.integerPart.split("").filter(function(t){return-1!==i.indexOf(t)}).length,c=a,l=t.fractionalPart.split(""),h=l.filter(function(t){return-1!==i.indexOf(t)}).length,d=l.filter(function(t){return-1!==i.indexOf(t)||t===r.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(r.digit)&&(a=1),0===a&&0===h&&(h=1);var p=0;return u&&(p=t.exponentPart.split("").filter(function(t){return-1!==i.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=r["minus-sign"],v=r["zero-digit"],x=r["decimal-separator"],_=r["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(r.percent)?100*t:-1!==p.picture.indexOf(r["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"?i[t.charCodeAt(0)-48]:t}).join("")),n},A=S(st(g,p.maximumFactionalPartSize),p.maximumFactionalPartSize),k=A.indexOf(".");for(-1===k?A+=x:A=A.replace(".",x);A.charAt(0)===v;)A=A.substring(1);for(;A.charAt(A.length-1)===v;)A=A.substring(0,A.length-1);k=A.indexOf(x);var E=p.minimumIntegerPartSize-k,C=p.minimumFactionalPartSize-(A.length-k-1);if(A=(E>0?new Array(E+1).join(v):"")+A,A+=C>0?new Array(C+1).join(v):"",k=A.indexOf(x),p.regularGrouping>0)for(var P=Math.floor((k-1)/p.regularGrouping),T=1;T<=P;T++)A=[A.slice(0,k-T*p.regularGrouping),_,A.slice(k-T*p.regularGrouping)].join("");else p.integerPartGroupingPositions.forEach(function(t){A=[A.slice(0,k-t),_,A.slice(k-t)].join(""),k++});if(k=A.indexOf(x),p.fractionalPartGroupingPositions.forEach(function(t){A=[A.slice(0,t+k+1),_,A.slice(t+k+1)].join("")}),k=A.indexOf(x),-1!==p.picture.indexOf(x)&&k!==A.length-1||(A=A.substring(0,A.length-1)),void 0!==m){var O=S(m,0);(E=p.minimumExponentSize-O.length)>0&&(O=new Array(E+1).join(v)+O),A=A+r["exponent-separator"]+(m<0?b:"")+O}return A=p.prefix+A+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 rt(t){if(void 0!==t)return Math.floor(t)}function it(t){if(void 0!==t)return Math.ceil(t)}function st(t,e){var n;if(void 0!==t){if(e){var r=t.toString().split("e");t=+(r[0]+"e"+(r[1]?+r[1]+e:e))}var i=(n=Math.round(t))-t;return.5===Math.abs(i)&&1===Math.abs(n%2)&&(n-=1),e&&(r=n.toString().split("e"),n=+(r[0]+"e"+(r[1]?+r[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"===r(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,r){var i=[e],s=S(t);return s>=2&&i.push(n),s>=3&&i.push(r),i}function ut(t,e){var n,r,s,o;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:n=v(),r=0;case 4:if(!(r<t.length)){i.next=12;break}return s=dt(e,t[r],r,t),i.delegateYield(e.apply(this,s),"t0",7);case 7:void 0!==(o=i.t0)&&n.push(o);case 9:r++,i.next=4;break;case 12:return i.abrupt("return",n);case 13:case"end":return i.stop()}},l,this)}function pt(t,e){var n,r,s,o;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:n=v(),r=0;case 4:if(!(r<t.length)){i.next=13;break}return s=t[r],o=dt(e,s,r,t),i.delegateYield(e.apply(this,o),"t0",8);case 8:lt(i.t0)&&n.push(s);case 10:r++,i.next=4;break;case 13:return i.abrupt("return",n);case 14:case"end":return i.stop()}},h,this)}function ft(t,e){var n,r,s,o,a,c,l;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:n=!1,s=0;case 4:if(!(s<t.length)){i.next=22;break}if(o=t[s],a=!0,void 0===e){i.next=12;break}return c=dt(e,o,s,t),i.delegateYield(e.apply(this,c),"t0",10);case 10:l=i.t0,a=lt(l);case 12:if(!a){i.next=19;break}if(n){i.next=18;break}r=o,n=!0,i.next=19;break;case 18:throw{stack:(new Error).stack,code:"D3138",index:s};case 19:s++,i.next=4;break;case 22:if(n){i.next=24;break}throw{stack:(new Error).stack,code:"D3139"};case 24:return i.abrupt("return",r);case 25:case"end":return i.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})),r=0;r<n;r++){var i=e.map(function(t){return t[r]});t.push(i)}return t}function mt(t,e,n){var r,s,o,a;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:if(!((s=S(e))<2)){i.next=5;break}throw{stack:(new Error).stack,code:"D3050",index:1};case 5:void 0===n&&t.length>0?(r=t[0],o=1):(r=n,o=0);case 6:if(!(o<t.length)){i.next=15;break}return a=[r,t[o]],s>=3&&a.push(o),s>=4&&a.push(t),i.delegateYield(e.apply(this,a),"t0",11);case 11:r=i.t0,o++,i.next=6;break;case 15:return i.abrupt("return",r);case 16:case"end":return i.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"!==r(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 i=0;i<t.length;i++){var s=bt(t[i],e);void 0!==s&&(Array.isArray(s)?s.forEach(function(t){return n.push(t)}):n.push(s))}}else null!==t&&"object"===r(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 xt(t){return void 0!==t}function _t(t){var e=v();if(Array.isArray(t))t.forEach(function(t){e=vt(e,_t(t))});else if(null===t||"object"!==r(t)||w(t))e=t;else for(var n in t){var i={};i[n]=t[n],e.push(i)}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),r=0;r<e;r++)n[e-r-1]=t[r];return n}}function St(t,e){var n,r,s,o;return i().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n=v(),a.t0=i().keys(t);case 2:if((a.t1=a.t0()).done){a.next=10;break}return r=a.t1.value,s=dt(e,t[r],r,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 At(t){throw{code:"D3137",stack:(new Error).stack,message:t||"$error() function evaluated"}}function kt(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":_(t)?"function":"object"}function Ct(t,e){var n,r,s,o;return i().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=i().mark(function t(e,n){return i().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 r=i().mark(function t(e,r){var s,o;return i().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return s=i().mark(function t(e,r,s){return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(0!==r.length){i.next=4;break}Array.prototype.push.apply(e,s),i.next=16;break;case 4:if(0!==s.length){i.next=8;break}Array.prototype.push.apply(e,r),i.next=16;break;case 8:return i.delegateYield(n(r[0],s[0]),"t0",9);case 9:if(!i.t0){i.next=14;break}return e.push(s[0]),i.delegateYield(t(e,r,s.slice(1)),"t1",12);case 12:i.next=16;break;case 14:return e.push(r[0]),i.delegateYield(t(e,r.slice(1),s),"t2",16);case 16:case"end":return i.stop()}},t)}),o=[],t.delegateYield(s(o,e,r),"t0",3);case 3:return t.abrupt("return",o);case 4:case"end":return t.stop()}},t)}),s=i().mark(function t(e){var n,s,o;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(Array.isArray(e)&&!(e.length<=1)){i.next=4;break}return i.abrupt("return",e);case 4:return n=Math.floor(e.length/2),s=e.slice(0,n),o=e.slice(n),i.delegateYield(t(s),"t0",8);case 8:return s=i.t0,i.delegateYield(t(o),"t1",10);case 10:return o=i.t1,i.delegateYield(r(s,o),"t2",12);case 12:return i.abrupt("return",i.t2);case 13:case"end":return i.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 Pt(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 r=Math.floor(Math.random()*(n+1));n!==r&&(e[n]=e[r]),e[r]=t[n]}return e}}function Tt(t){if(void 0!==t){if(!Array.isArray(t)||t.length<=1)return t;for(var e=x(t)?v():[],n=0;n<t.length;n++){for(var r=t[n],i=!1,s=0;s<e.length;s++)if(A(r,e[s])){i=!0;break}i||e.push(r)}return e}}function Ot(t,e){var n,r,s,o;return i().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n={},a.t0=i().keys(t);case 2:if((a.t1=a.t0()).done){a.next=11;break}return r=a.t1.value,s=t[r],o=dt(e,s,r,t),a.delegateYield(e.apply(this,o),"t2",7);case 7:lt(a.t2)&&(n[r]=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:P,min:T,average:O,string:D,substring:I,substringBefore:z,substringAfter:L,lowercase:j,uppercase:R,length:F,trim:B,pad:N,match:G,contains:V,replace:H,split:Q,join:Z,formatNumber:J,formatBase:tt,number:et,floor:rt,ceil:it,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:Ot,keys:yt,lookup:bt,append:vt,exists:xt,spread:_t,merge:wt,reverse:Mt,each:St,error:At,assert:kt,type:Et,sort:Ct,shuffle:Pt,distinct:Tt,base64encode:U,base64decode:W,encodeUrlComponent:X,encodeUrl:q,decodeUrlComponent:K,decodeUrl:$}}();e.exports=o}).call(this)}).call(this,void 0!==$r?$r:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils":6}],3:[function(t,e,n){function r(t){return r="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},r(t)}function i(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */i=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,r){var i=e&&e.prototype instanceof v?e:v,s=Object.create(i.prototype),a=new D(r||[]);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 x(){}function _(){}var w={};d(w,c,function(){return this});var M=Object.getPrototypeOf,S=M&&M(M(I([])));S&&S!==n&&s.call(S,c)&&(w=S);var A=_.prototype=v.prototype=Object.create(w);function k(t){["next","throw","return"].forEach(function(e){d(t,e,function(t){return this._invoke(e,t)})})}function E(t,e){function n(i,o,a,c){var l=p(t[i],t,o);if("throw"!==l.type){var h=l.arg,d=h.value;return d&&"object"==r(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 i;o(this,"_invoke",{value:function(t,r){function s(){return new e(function(e,i){n(t,r,e,i)})}return i=i?i.then(s,s):s()}})}function C(e,n,r){var i=f;return function(s,o){if(i===m)throw new Error("Generator is already running");if(i===y){if("throw"===s)throw o;return{value:t,done:!0}}for(r.method=s,r.arg=o;;){var a=r.delegate;if(a){var c=P(a,r);if(c){if(c===b)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===f)throw i=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=m;var l=p(e,n,r);if("normal"===l.type){if(i=r.done?y:g,l.arg===b)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(i=y,r.method="throw",r.arg=l.arg)}}}function P(e,n){var r=n.method,i=e.iterator[r];if(i===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,P(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),b;var s=p(i,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 T(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 O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function D(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function I(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 i=-1,o=function n(){for(;++i<e.length;)if(s.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(r(e)+" is not iterable")}return x.prototype=_,o(A,"constructor",{value:_,configurable:!0}),o(_,"constructor",{value:x,configurable:!0}),x.displayName=d(_,h,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===x||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,_):(t.__proto__=_,d(t,h,"GeneratorFunction")),t.prototype=Object.create(A),t},e.awrap=function(t){return{__await:t}},k(E.prototype),d(E.prototype,l,function(){return this}),e.AsyncIterator=E,e.async=function(t,n,r,i,s){void 0===s&&(s=Promise);var o=new E(u(t,n,r,i),s);return e.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},k(A),d(A,h,"Generator"),d(A,c,function(){return this}),d(A,"toString",function(){return"[object Generator]"}),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=I,D.prototype={constructor:D,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(O),!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 r(r,i){return a.type="throw",a.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("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 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&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=t,o.arg=e,i?(this.method="next",this.next=i.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),O(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 r=n.completion;if("throw"===r.type){var i=r.arg;O(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:I(e),resultName:n,nextLoc:r},"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=i().mark(N),e=i().mark(Y),n=i().mark(G),h=i().mark(H),d=i().mark(U),u=i().mark(W),p=i().mark(X),f=i().mark(q),g=i().mark(st),m=i().mark(ct),y=i().mark(dt),b=i().mark(ut),v=i().mark(pt),x=i().mark(mt),_=i().mark(vt),w=i().mark(xt),M=i().mark(_t),S=i().mark(wt),A=i().mark(St),k=i().mark(kt),E=i().mark(Pt),C=i().mark(Dt),P=a.isNumeric,T=a.isArrayOfStrings,O=a.isArrayOfNumbers,D=a.createSequence,I=a.isSequence,z=a.isFunction,L=a.isLambda,j=a.isIterable,R=a.getFunctionArity,F=a.isDeepEqual,B=zt(null);function N(e,n,r){var s,o,a,c;return i().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:(o=r.lookup("__evaluate_entry"))&&o(e,n,r),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(Y(e,n,r),"t1",6);case 6:return s=t.t1,t.abrupt("break",50);case 8:return t.delegateYield(X(e,n,r),"t2",9);case 9:return s=t.t2,t.abrupt("break",50);case 11:return t.delegateYield(q(e,n,r),"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=r.lookup(e.slot.label),t.abrupt("break",50);case 24:return t.delegateYield(ut(e,n,r),"t4",25);case 25:return s=t.t4,t.abrupt("break",50);case 27:return t.delegateYield(pt(e,n,r),"t5",28);case 28:return s=t.t5,t.abrupt("break",50);case 30:return t.delegateYield(dt(e,n,r),"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(xt(e,n,r),"t7",36);case 36:return s=t.t7,t.abrupt("break",50);case 38:return s=gt(e,n,r),t.abrupt("break",50);case 40:return s=Mt(e,n,r),t.abrupt("break",50);case 42:return t.delegateYield(St(e,n,r),"t8",43);case 43:return s=t.t8,t.abrupt("break",50);case 45:return t.delegateYield(vt(e,n,r),"t9",46);case 46:return s=t.t9,t.abrupt("break",50);case 48:return s=yt(e,n,r),t.abrupt("break",50);case 50:if(!r.async||null!=s&&"function"==typeof s.then||(s=Promise.resolve(s)),!r.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,r),"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,r),"t11",67);case 67:s=t.t11;case 68:return(c=r.lookup("__evaluate_exit"))&&c(e,n,r,s),s&&I(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 Y(t,n,r){var s,o,a,c,l,h;return i().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:s=Array.isArray(n)&&"variable"!==t.steps[0].type?n:D(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,r),"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,r),"t1",14);case 14:c=e.t1,e.next=19;break;case 17:return e.delegateYield(G(h,s,r,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=D(),l=0;l<c.length;l++)o.push(c[l]["@"]);if(t.keepSingletonArray&&(Array.isArray(o)&&o.cons&&!o.sequence&&(o=D(o)),o.keepSingleton=!0),!t.hasOwnProperty("group")){e.next=30;break}return e.delegateYield(ct(t.group,a?c:o,r),"t3",29);case 29:o=e.t3;case 30:return e.abrupt("return",o);case 31:case"end":return e.stop()}},e)}function V(t,e){var n=zt(t);for(var r in e)n.bind(r,e[r]);return n}function G(t,e,r,s){var o,a,c,l,h;return i().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,r),"t0",2);case 2:if(o=n.t0,!t.stages){n.next=6;break}return n.delegateYield(H(t.stages,o,r),"t1",5);case 5:o=n.t1;case 6:return n.abrupt("return",o);case 7:o=D(),a=0;case 9:if(!(a<e.length)){n.next=24;break}return n.delegateYield(N(t,e[a],r),"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,r),"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=D(),s&&1===o.length&&Array.isArray(o[0])&&!I(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 H(t,e,n){var r,s,o,a;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:r=e,s=0;case 2:if(!(s<t.length)){i.next=15;break}o=t[s],i.t0=o.type,i.next="filter"===i.t0?7:"index"===i.t0?10:12;break;case 7:return i.delegateYield(W(o.expr,r,n),"t1",8);case 8:return r=i.t1,i.abrupt("break",12);case 10:for(a=0;a<r.length;a++)r[a][o.value]=a;return i.abrupt("break",12);case 12:s++,i.next=2;break;case 15:return i.abrupt("return",r);case 16:case"end":return i.stop()}},h)}function U(t,e,n,r){var s,o,a,c,l,h,u,p;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if("sort"!==t.type){i.next=15;break}if(!n){i.next=6;break}return i.delegateYield(mt(t,n,r),"t0",3);case 3:s=i.t0,i.next=11;break;case 6:return i.delegateYield(mt(t,e,r),"t1",7);case 7:for(o=i.t1,(s=D()).tupleStream=!0,a=0;a<o.length;a++)(c={"@":o[a]})[t.index]=a,s.push(c);case 11:if(!t.stages){i.next=14;break}return i.delegateYield(H(t.stages,s,r),"t2",13);case 13:s=i.t2;case 14:return i.abrupt("return",s);case 15:(s=D()).tupleStream=!0,l=r,void 0===n&&(n=e.map(function(t){return{"@":t}})),h=0;case 20:if(!(h<n.length)){i.next=28;break}return l=V(r,n[h]),i.delegateYield(N(t,n[h]["@"],l),"t3",23);case 23:if(void 0!==(u=i.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++,i.next=20;break;case 28:if(!t.stages){i.next=31;break}return i.delegateYield(H(t.stages,s,r),"t4",30);case 30:s=i.t4;case 31:return i.abrupt("return",s);case 32:case"end":return i.stop()}},d)}function W(t,e,n){var r,s,a,c,l,h;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(r=D(),e&&e.tupleStream&&(r.tupleStream=!0),Array.isArray(e)||(e=D(e)),"number"!==t.type){i.next=10;break}(s=Math.floor(t.value))<0&&(s=e.length+s),void 0!==(a=e[s])&&(Array.isArray(a)?r=a:r.push(a)),i.next=23;break;case 10:s=0;case 11:if(!(s<e.length)){i.next=23;break}return a=e[s],c=a,l=n,e.tupleStream&&(c=a["@"],l=V(n,a)),i.delegateYield(N(t,c,l),"t0",17);case 17:h=i.t0,P(h)&&(h=[h]),O(h)?h.forEach(function(t){var n=Math.floor(t);n<0&&(n=e.length+n),n===s&&r.push(a)}):o.boolean(h)&&r.push(a);case 20:s++,i.next=11;break;case 23:return i.abrupt("return",r);case 24:case"end":return i.stop()}},u)}function X(t,e,n){var r,s,o,a,c;return i().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=i().mark(function r(){return i().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.rhs,e,n),"t0",1);case 1:return r.abrupt("return",r.t0);case 2:case"end":return r.stop()}},r)}),"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 r=et(s,c,o),l.abrupt("break",33);case 23:return r=nt(s,c,o),l.abrupt("break",33);case 25:return r=rt(s,c,o),l.abrupt("break",33);case 27:return r=at(s,c),l.abrupt("break",33);case 29:return r=ht(s,c),l.abrupt("break",33);case 31:return r=it(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",r);case 41:case"end":return l.stop()}},p,null,[[5,10],[17,35]])}function q(t,e,n){var r,s,a,c;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:i.t0=t.value,i.next="-"===i.t0?3:"["===i.t0?15:"{"===i.t0?27:30;break;case 3:return i.delegateYield(N(t.expression,e,n),"t1",4);case 4:if(void 0!==(r=i.t1)){i.next=9;break}r=void 0,i.next=14;break;case 9:if(!P(r)){i.next=13;break}r=-r,i.next=14;break;case 13:throw{code:"D1002",stack:(new Error).stack,position:t.position,token:t.value,value:r};case 14:return i.abrupt("break",30);case 15:r=[],s=0;case 17:if(!(s<t.expressions.length)){i.next=25;break}return a=t.expressions[s],i.delegateYield(N(a,e,n),"t2",20);case 20:void 0!==(c=i.t2)&&("["===a.value?r.push(c):r=o.append(r,c));case 22:s++,i.next=17;break;case 25:return t.consarray&&Object.defineProperty(r,"cons",{enumerable:!1,configurable:!1,value:!0}),i.abrupt("break",30);case 27:return i.delegateYield(ct(t,e,n),"t3",28);case 28:return r=i.t3,i.abrupt("break",30);case 30:return i.abrupt("return",r);case 31:case"end":return i.stop()}},f)}function K(t,e,n){return o.lookup(e,t.value)}function $(t){return t.value}function Q(t,e){var n=D();return Array.isArray(e)&&e.outerWrapper&&e.length>0&&(e=e[0]),null!==e&&"object"===r(e)&&Object.keys(e).forEach(function(t){var r=e[t];Array.isArray(r)?(r=Z(r),n=o.append(n,r)):n.push(r)}),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,r=D();return void 0!==e&&(tt(e,r),n=1===r.length?r[0]:r),n}function tt(t,e){Array.isArray(t)||e.push(t),Array.isArray(t)?t.forEach(function(t){tt(t,e)}):null!==t&&"object"===r(t)&&Object.keys(t).forEach(function(n){tt(t[n],e)})}function et(t,e,n){var r;if(void 0!==t&&!P(t))throw{code:"T2001",stack:(new Error).stack,value:t};if(void 0!==e&&!P(e))throw{code:"T2002",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return r;switch(n){case"+":r=t+e;break;case"-":r=t-e;break;case"*":r=t*e;break;case"/":r=t/e;break;case"%":r=t%e}return r}function nt(t,e,n){var i,s=r(t),o=r(e);if("undefined"===s||"undefined"===o)return!1;switch(n){case"=":i=F(t,e);break;case"!=":i=!F(t,e)}return i}function rt(t,e,n){var i,s=r(t),o=r(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"<":i=t<e;break;case"<=":i=t<=e;break;case">":i=t>e;break;case">=":i=t>=e}return i}}function it(t,e){var n=!1;if(void 0===t||void 0===e)return!1;Array.isArray(e)||(e=[e]);for(var r=0;r<e.length;r++)if(e[r]===t){n=!0;break}return n}function st(t,e,n){var r,s;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:s=ot(t),i.t0=n,i.next="and"===i.t0?4:"or"===i.t0?12:20;break;case 4:if(i.t1=s,!i.t1){i.next=10;break}return i.t2=ot,i.delegateYield(e(),"t3",8);case 8:i.t4=i.t3,i.t1=(0,i.t2)(i.t4);case 10:return r=i.t1,i.abrupt("break",20);case 12:if(i.t5=s,i.t5){i.next=18;break}return i.t6=ot,i.delegateYield(e(),"t7",16);case 16:i.t8=i.t7,i.t5=(0,i.t6)(i.t8);case 18:return r=i.t5,i.abrupt("break",20);case 20:return i.abrupt("return",r);case 21:case"end":return i.stop()}},g)}function ot(t){var e=o.boolean(t);return void 0!==e&&e}function at(t,e){var n="",r="";return void 0!==t&&(n=o.string(t)),void 0!==e&&(r=o.string(e)),n.concat(r)}function ct(t,e,n){var r,s,a,c,l,h,d,u,p,f,g,y,b;return i().wrap(function(m){for(;;)switch(m.prev=m.next){case 0:r={},s={},a=!(!e||!e.tupleStream),Array.isArray(e)||(e=D(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?V(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=i().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=V(n,y)),m.delegateYield(N(t.lhs[f.exprIndex][1],g,h),"t3",39);case 39:void 0!==(b=m.t3)&&(r[p]=b),m.next=32;break;case 43:return m.abrupt("return",r);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 r in t[n])e[r]=o.append(e[r],t[n][r]);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 r=e-t+1;if(r>1e7)throw{code:"D2014",stack:(new Error).stack,value:r};n=new Array(r);for(var i=t,s=0;i<=e;i++,s++)n[s]=i;return n.sequence=!0,n}function dt(t,e,n){var r;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.rhs,e,n),"t0",1);case 1:return r=i.t0,n.bind(t.lhs.value,r),i.abrupt("return",r);case 4:case"end":return i.stop()}},y)}function ut(t,e,n){var r,s;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.condition,e,n),"t0",1);case 1:if(s=i.t0,!o.boolean(s)){i.next=7;break}return i.delegateYield(N(t.then,e,n),"t1",4);case 4:r=i.t1,i.next=10;break;case 7:if(void 0===t.else){i.next=10;break}return i.delegateYield(N(t.else,e,n),"t2",9);case 9:r=i.t2;case 10:return i.abrupt("return",r);case 11:case"end":return i.stop()}},b)}function pt(t,e,n){var r,s,o;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:s=zt(n),o=0;case 2:if(!(o<t.expressions.length)){i.next=8;break}return i.delegateYield(N(t.expressions[o],e,s),"t0",4);case 4:r=i.t0;case 5:o++,i.next=2;break;case 8:return i.abrupt("return",r);case 9:case"end":return i.stop()}},v)}function ft(t){var e=new Rt.RegexEngine(t.value),n=function n(r,i){var s;e.lastIndex=i||0;var o=e.exec(r);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>=r.length)){var i=n(r,e.lastIndex);if(i&&""===i.match)throw{code:"D1004",stack:(new Error).stack,position:t.position,value:t.value.source};return i}}}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 i().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return a=e,c=!!e.tupleStream,l=i().mark(function e(s,o){var a,l,h,d,u,p,f,g,m;return i().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=V(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=V(n,o)),e.delegateYield(N(h.expression,d,u),"t1",13);case 13:if(f=e.t1,g=r(p),m=r(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()}},x)}function yt(t,e,n){var s=i().mark(function e(s){var o,a,c,l,h,d,u,p,f,g,m;return i().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"),z(o)){e.next=5;break}throw{code:"T2013",stack:(new Error).stack,position:t.position};case 5:return e.delegateYield(_t(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=r(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]),T(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"===r(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 Ot(s,"<(oa):o>")}var bt=c("function($f, $g) { function($x){ $g($f($x)) } }");function vt(t,e,n){var r,s,o,a;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(N(t.lhs,e,n),"t0",1);case 1:if(s=i.t0,"function"!==t.rhs.type){i.next=7;break}return i.delegateYield(xt(t.rhs,e,n,{context:s}),"t1",4);case 4:r=i.t1,i.next=20;break;case 7:return i.delegateYield(N(t.rhs,e,n),"t2",8);case 8:if(o=i.t2,z(o)){i.next=11;break}throw{code:"T2006",stack:(new Error).stack,position:t.position,value:o};case 11:if(!z(s)){i.next=18;break}return i.delegateYield(N(bt,null,n),"t3",13);case 13:return a=i.t3,i.delegateYield(_t(a,[s,o],null,n),"t4",15);case 15:r=i.t4,i.next=20;break;case 18:return i.delegateYield(_t(o,[s],null,n),"t5",19);case 19:r=i.t5;case 20:return i.abrupt("return",r);case 21:case"end":return i.stop()}},_)}function xt(t,e,n,s){var o,a,c,l,h,d;return i().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=i().mark(function r(){var s,o;return i().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(N(t.arguments[h],e,n),"t0",1);case 1:s=r.t0,z(s)?(o=i().mark(function t(){var e,r,o,a=arguments;return i().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(e=a.length,r=new Array(e),o=0;o<e;o++)r[o]=a[o];return t.delegateYield(_t(s,r,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 r.stop()}},r)}),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"===r(a)&&(a.token=d,a.position=t.position),u.delegateYield(_t(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 _t(t,e,n,r){var s,o,a,c;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(wt(t,e,n,r),"t0",1);case 1:s=i.t0;case 2:if(!L(s)||!0!==s.thunk){i.next=21;break}return i.delegateYield(N(s.body.procedure,s.input,s.environment),"t1",4);case 4:o=i.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)){i.next=17;break}return i.t2=a,i.delegateYield(N(s.body.arguments[c],s.input,s.environment),"t3",12);case 12:i.t4=i.t3,i.t2.push.call(i.t2,i.t4);case 14:c++,i.next=9;break;case 17:return i.delegateYield(wt(o,a,n,r),"t5",18);case 18:s=i.t5,i.next=2;break;case 21:return i.abrupt("return",s);case 22:case"end":return i.stop()}},M)}function wt(t,e,n,r){var s,o,a;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(i.prev=0,o=e,t&&(o=At(t.signature,e,n)),!L(t)){i.next=8;break}return i.delegateYield(kt(t,o),"t0",5);case 5:s=i.t0,i.next=24;break;case 8:if(!t||!0!==t._jsonata_function){i.next=16;break}if(a={environment:r,input:n},s=t.implementation.apply(a,o),!j(s)){i.next=14;break}return i.delegateYield(s,"t1",13);case 13:s=i.t1;case 14:i.next=24;break;case 16:if("function"!=typeof t){i.next=23;break}if(s=t.apply(n,o),!j(s)){i.next=21;break}return i.delegateYield(s,"t2",20);case 20:s=i.t2;case 21:i.next=24;break;case 23:throw{code:"T1006",stack:(new Error).stack};case 24:i.next=30;break;case 26:throw i.prev=26,i.t3=i.catch(0),t&&(void 0===i.t3.token&&void 0!==t.token&&(i.t3.token=t.token),i.t3.position=t.position||i.t3.position),i.t3;case 30:return i.abrupt("return",s);case 31:case"end":return i.stop()}},S,null,[[0,26]])}function Mt(t,e,n){var r={_jsonata_lambda:!0,input:e,environment:n,arguments:t.arguments,signature:t.signature,body:t.body};return!0===t.thunk&&(r.thunk=!0),r.apply=i().mark(function t(n,s){return i().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(_t(r,s,e,n.environment),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},t)}),r}function St(t,e,n){var r,s,o,a,c;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:s=[],o=0;case 2:if(!(o<t.arguments.length)){i.next=15;break}if("operator"!==(a=t.arguments[o]).type||"?"!==a.value){i.next=8;break}s.push(a),i.next=12;break;case 8:return i.t0=s,i.delegateYield(N(a,e,n),"t1",10);case 10:i.t2=i.t1,i.t0.push.call(i.t0,i.t2);case 12:o++,i.next=2;break;case 15:return i.delegateYield(N(t.procedure,e,n),"t3",16);case 16:if(void 0!==(c=i.t3)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){i.next=19;break}throw{code:"T1007",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 19:if(!L(c)){i.next=23;break}r=Et(c,s),i.next=32;break;case 23:if(!c||!0!==c._jsonata_function){i.next=27;break}r=Ct(c.implementation,s),i.next=32;break;case 27:if("function"!=typeof c){i.next=31;break}r=Ct(c,s),i.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 i.abrupt("return",r);case 33:case"end":return i.stop()}},A)}function At(t,e,n){return void 0===t?e:t.validate(e,n)}function kt(t,e){var n,r;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(r=zt(t.environment),t.arguments.forEach(function(t,n){r.bind(t.value,e[n])}),"function"!=typeof t.body){i.next=7;break}return i.delegateYield(Pt(t.body,r),"t0",4);case 4:n=i.t0,i.next=9;break;case 7:return i.delegateYield(N(t.body,t.input,r),"t1",8);case 8:n=i.t1;case 9:return i.abrupt("return",n);case 10:case"end":return i.stop()}},k)}function Et(t,e){var n=zt(t.environment),r=[];return t.arguments.forEach(function(t,i){var s=e[i];s&&"operator"===s.type&&"?"===s.value?r.push(t):n.bind(t.value,s)}),{_jsonata_lambda:!0,input:t.input,environment:n,arguments:r,body:t.body}}function Ct(t,e){var n=Tt(t),r="function("+(n=n.map(function(t){return"$"+t.trim()})).join(", ")+"){ _ }",i=c(r);return i.body=t,Et(i,e)}function Pt(t,e){var n,r,s,o;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(n=Tt(t),r=n.map(function(t){return e.lookup(t.trim())}),s={environment:e},o=t.apply(s,r),!j(o)){i.next=7;break}return i.delegateYield(o,"t0",6);case 6:o=i.t0;case 7:return i.abrupt("return",o);case 8:case"end":return i.stop()}},E)}function Tt(t){var e=t.toString();return/\(([^)]*)\)/.exec(e)[1].split(",")}function Ot(t,e){var n={_jsonata_function:!0,implementation:t};return void 0!==e&&(n.signature=l(e)),n}function Dt(t,e){var n,r,s;return i().wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(void 0!==t){i.next=2;break}return i.abrupt("return",void 0);case 2:n=this.input,void 0!==e&&(n=e,Array.isArray(n)&&!I(n)&&((n=D(n)).outerWrapper=!0)),i.prev=4,r=c(t,!1),i.next=12;break;case 8:throw i.prev=8,i.t0=i.catch(4),jt(i.t0),{stack:(new Error).stack,code:"D3120",value:i.t0.message,error:i.t0};case 12:return i.prev=12,i.delegateYield(N(r,n,this.environment),"t1",14);case 14:s=i.t1,i.next=21;break;case 17:throw i.prev=17,i.t2=i.catch(12),jt(i.t2),{stack:(new Error).stack,code:"D3121",value:i.t2.message,error:i.t2};case 21:return i.abrupt("return",s);case 22:case"end":return i.stop()}},C,this,[[4,8],[12,17]])}function It(t){if(void 0!==t)return JSON.parse(o.string(t))}function zt(t){var e={};return{bind:function(t,n){e[t]=n},lookup:function(n){var r;return e.hasOwnProperty(n)?r=e[n]:t&&(r=t.lookup(n)),r},timestamp:t?t.timestamp:null,async:!!t&&t.async,global:t?t.global:{ancestry:[null]}}}B.bind("sum",Ot(o.sum,"<a<n>:n>")),B.bind("count",Ot(o.count,"<a:n>")),B.bind("max",Ot(o.max,"<a<n>:n>")),B.bind("min",Ot(o.min,"<a<n>:n>")),B.bind("average",Ot(o.average,"<a<n>:n>")),B.bind("string",Ot(o.string,"<x-b?:s>")),B.bind("substring",Ot(o.substring,"<s-nn?:s>")),B.bind("substringBefore",Ot(o.substringBefore,"<s-s:s>")),B.bind("substringAfter",Ot(o.substringAfter,"<s-s:s>")),B.bind("lowercase",Ot(o.lowercase,"<s-:s>")),B.bind("uppercase",Ot(o.uppercase,"<s-:s>")),B.bind("length",Ot(o.length,"<s-:n>")),B.bind("trim",Ot(o.trim,"<s-:s>")),B.bind("pad",Ot(o.pad,"<s-ns?:s>")),B.bind("match",Ot(o.match,"<s-f<s:o>n?:a<o>>")),B.bind("contains",Ot(o.contains,"<s-(sf):b>")),B.bind("replace",Ot(o.replace,"<s-(sf)(sf)n?:s>")),B.bind("split",Ot(o.split,"<s-(sf)n?:a<s>>")),B.bind("join",Ot(o.join,"<a<s>s?:s>")),B.bind("formatNumber",Ot(o.formatNumber,"<n-so?:s>")),B.bind("formatBase",Ot(o.formatBase,"<n-n?:s>")),B.bind("formatInteger",Ot(s.formatInteger,"<n-s:s>")),B.bind("parseInteger",Ot(s.parseInteger,"<s-s:n>")),B.bind("number",Ot(o.number,"<(nsb)-:n>")),B.bind("floor",Ot(o.floor,"<n-:n>")),B.bind("ceil",Ot(o.ceil,"<n-:n>")),B.bind("round",Ot(o.round,"<n-n?:n>")),B.bind("abs",Ot(o.abs,"<n-:n>")),B.bind("sqrt",Ot(o.sqrt,"<n-:n>")),B.bind("power",Ot(o.power,"<n-n:n>")),B.bind("random",Ot(o.random,"<:n>")),B.bind("boolean",Ot(o.boolean,"<x-:b>")),B.bind("not",Ot(o.not,"<x-:b>")),B.bind("map",Ot(o.map,"<af>")),B.bind("zip",Ot(o.zip,"<a+>")),B.bind("filter",Ot(o.filter,"<af>")),B.bind("single",Ot(o.single,"<af?>")),B.bind("reduce",Ot(o.foldLeft,"<afj?:j>")),B.bind("sift",Ot(o.sift,"<o-f?:o>")),B.bind("keys",Ot(o.keys,"<x-:a<s>>")),B.bind("lookup",Ot(o.lookup,"<x-s:x>")),B.bind("append",Ot(o.append,"<xx:a>")),B.bind("exists",Ot(o.exists,"<x:b>")),B.bind("spread",Ot(o.spread,"<x-:a<o>>")),B.bind("merge",Ot(o.merge,"<a<o>:o>")),B.bind("reverse",Ot(o.reverse,"<a:a>")),B.bind("each",Ot(o.each,"<o-f:a>")),B.bind("error",Ot(o.error,"<s?:x>")),B.bind("assert",Ot(o.assert,"<bs?:x>")),B.bind("type",Ot(o.type,"<x:s>")),B.bind("sort",Ot(o.sort,"<af?:a>")),B.bind("shuffle",Ot(o.shuffle,"<a:a>")),B.bind("distinct",Ot(o.distinct,"<x:x>")),B.bind("base64encode",Ot(o.base64encode,"<s-:s>")),B.bind("base64decode",Ot(o.base64decode,"<s-:s>")),B.bind("encodeUrlComponent",Ot(o.encodeUrlComponent,"<s-:s>")),B.bind("encodeUrl",Ot(o.encodeUrl,"<s-:s>")),B.bind("decodeUrlComponent",Ot(o.decodeUrlComponent,"<s-:s>")),B.bind("decodeUrl",Ot(o.decodeUrl,"<s-:s>")),B.bind("eval",Ot(Dt,"<sx?:x>")),B.bind("toMillis",Ot(s.toMillis,"<s-s?:n>")),B.bind("fromMillis",Ot(s.fromMillis,"<n-s?s?:s>")),B.bind("clone",Ot(It,"<(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,r;try{n=c(t,e&&e.recover),r=n.errors,delete n.errors}catch(t){throw jt(t),t}var i=zt(B),o=new Date;return i.bind("now",Ot(function(t,e){return s.fromMillis(o.getTime(),t,e)},"<s?s?:s>")),i.bind("millis",Ot(function(){return o.getTime()},"<:n>")),e&&e.RegexEngine?Rt.RegexEngine=e.RegexEngine:Rt.RegexEngine=RegExp,{evaluate:function(t,e,s){if(void 0!==r){var a={code:"S0500",position:0};throw jt(a),a}var c,l,h;if(void 0!==e)for(var d in c=zt(i),e)c.bind(d,e[d]);else c=i;if(c.bind("$",t),o=new Date,c.timestamp=o,Array.isArray(t)&&!I(t)&&((t=D(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){i.bind(t,e)},registerFunction:function(t,e,n){var r=Ot(e,n);i.bind(t,r)},ast:function(){return n},errors:function(){return r}}}return Rt.parser=c,Rt}();e.exports=h},{"./datetime":1,"./functions":2,"./parser":4,"./signature":5,"./utils":6}],4:[function(t,e,n){var r=t("./signature"),i=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 r=0,i=n.length,s=function(t,e){return{type:t,value:e,position:r}},o=function(){for(var t,e,s=r,o=0;r<i;){var a=n.charAt(r);if("/"===a&&"\\"!==n.charAt(r-1)&&0===o){if(""===(t=n.substring(s,r)))throw{code:"S0301",stack:(new Error).stack,position:r};for(r++,a=n.charAt(r),s=r;"i"===a||"m"===a;)r++,a=n.charAt(r);return e=n.substring(s,r)+"g",new RegExp(t,e)}"("!==a&&"["!==a&&"{"!==a||"\\"===n.charAt(r-1)||o++,")"!==a&&"]"!==a&&"}"!==a||"\\"===n.charAt(r-1)||o--,r++}throw{code:"S0302",stack:(new Error).stack,position:r}},a=function a(c){if(r>=i)return null;for(var l=n.charAt(r);r<i&&" \t\n\r\v".indexOf(l)>-1;)r++,l=n.charAt(r);if("/"===l&&"*"===n.charAt(r+1)){var h=r;for(r+=2,l=n.charAt(r);"*"!==l||"/"!==n.charAt(r+1);)if(l=n.charAt(++r),r>=i)throw{code:"S0106",stack:(new Error).stack,position:h};return r+=2,l=n.charAt(r),a(c)}if(!0!==c&&"/"===l)return r++,s("regex",o());if("."===l&&"."===n.charAt(r+1))return r+=2,s("operator","..");if(":"===l&&"="===n.charAt(r+1))return r+=2,s("operator",":=");if("!"===l&&"="===n.charAt(r+1))return r+=2,s("operator","!=");if(">"===l&&"="===n.charAt(r+1))return r+=2,s("operator",">=");if("<"===l&&"="===n.charAt(r+1))return r+=2,s("operator","<=");if("*"===l&&"*"===n.charAt(r+1))return r+=2,s("operator","**");if("~"===l&&">"===n.charAt(r+1))return r+=2,s("operator","~>");if(Object.prototype.hasOwnProperty.call(t,l))return r++,s("operator",l);if('"'===l||"'"===l){var d=l;r++;for(var u="";r<i;){if("\\"===(l=n.charAt(r)))if(r++,l=n.charAt(r),Object.prototype.hasOwnProperty.call(e,l))u+=e[l];else{if("u"!==l)throw{code:"S0103",stack:(new Error).stack,position:r,token:l};var p=n.substr(r+1,4);if(!/^[0-9a-fA-F]+$/.test(p))throw{code:"S0104",stack:(new Error).stack,position:r};var f=parseInt(p,16);u+=String.fromCharCode(f),r+=4}else{if(l===d)return r++,s("string",u);u+=l}r++}throw{code:"S0101",stack:(new Error).stack,position:r}}var g,m=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/.exec(n.substring(r));if(null!==m){var y=parseFloat(m[0]);if(!isNaN(y)&&isFinite(y))return r+=m[0].length,s("number",y);throw{code:"S0102",stack:(new Error).stack,position:r,token:m[0]}}if("`"===l){r++;var b=n.indexOf("`",r);if(-1!==b)return g=n.substring(r,b),r=b+1,s("name",g);throw r=i,{code:"S0105",stack:(new Error).stack,position:r}}for(var v,x=r;;)if(v=n.charAt(x),x===i||" \t\n\r\v".indexOf(v)>-1||Object.prototype.hasOwnProperty.call(t,v)){if("$"===n.charAt(r))return g=n.substring(r+1,x),r=x,s("variable",g);switch(g=n.substring(r,x),r=x,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 r===i&&""===g?null:s("name",g)}}else x++};return a},i=function(e,i){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(i)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(i){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 r={code:"(end)"===s.id?"S0203":"S0202",position:s.position,token:s.value,value:t};return u(r)}var i=o(n);if(null===i)return(s=a["(end)"]).position=e.length,s;var c,l=i.value,h=i.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:i.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:i.position,token:l})}return(s=Object.create(c)).value=l,s.type=h,s.position=i.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,r){var i=n||t[e],s=d(e,i);return s.led=r||function(t){return this.lhs=t,this.rhs=f(i),this.type="binary",this},s},y=function(t,e,n){var r=d(t,e);return r.led=n,r},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,i="<";n>0&&"{"!==s.id&&"(end)"!==s.id;){var o=p();">"===o.id?n--:"<"===o.id&&n++,i+=o.value}p(">");try{this.signature=r(i)}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 r=f(0);if(e.push([n,r]),","!==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 x=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 r=e.expressions.length;r>0&&(e.expressions[r-1]=t(e.expressions[r-1])),n=e}else n=e;else{var i={type:"lambda",thunk:!0,arguments:[],position:e.position};i.body=e,n=i}return n},_=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 r=e.steps.length-1;for(n=t(e.steps[r--],n);n.level>0&&r>=0;)n=t(e.steps[r--],n);break;default:throw{code:"S0217",token:e.type,position:e.position}}return n},A=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)}},k=function(t){var e=t.steps.length-1,n=t.steps[e],r=void 0!==n.seekingParent?n.seekingParent:[];"parent"===n.type&&r.push(n.slot);for(var i=0;i<r.length;i++){var s=r[i];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 r=t(e.lhs);n="path"===r.type?r:{type:"path",steps:[r]},"parent"===r.type&&(n.seekingParent=[r.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),k(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--}),A(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 A(u,n),{descending:e.descending,expression:n}}),n.steps.push(u),k(n);break;case":=":(n={type:"bind",value:e.value,position:e.position}).lhs=t(e.lhs),n.rhs=t(e.rhs),A(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),A(n,n.lhs),A(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 r=t(e);return A(n,r),r}):"{"===e.value?n.lhs=e.lhs.map(function(e){var r=t(e[0]);A(n,r);var i=t(e[1]);return A(n,i),[r,i]}):(n.expression=t(e.expression),"-"===e.value&&"number"===n.expression.type?(n=n.expression).value=-n.value:A(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 r=t(e);return A(n,r),r}),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=x(p);break;case"condition":(n={type:e.type,position:e.position}).condition=t(e.condition),A(n,n.condition),n.then=t(e.then),A(n,n.then),void 0!==e.else&&(n.else=t(e.else),A(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 r=t(e);return A(n,r),(r.consarray||"path"===r.type&&r.steps[0].consarray)&&(n.consarray=!0),r});break;case"name":n={type:"path",steps:[e]},e.keepArray&&(n.keepSingletonArray=!0);break;case"parent":n={type:"parent",slot:{label:"!"+_++,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(i)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 P={code:"S0201",position:s.position,token:s.value};u(P)}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 i}();e.exports=i},{"./signature":5}],5:[function(t,e,n){function r(t){return r="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},r(t)}var i=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,r){for(var i=1,s=e;s<t.length;)if(s++,(c=t.charAt(s))===r){if(0===--i)break}else c===n&&i++;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(i.isFunction(t))e="f";else switch(r(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="^",r=0,i=0;i<s.length;i++){n+=s[i].regex;var o=e.match(n);if(null===o)throw{code:"T0410",stack:(new Error).stack,value:t[r],index:r+1};r=o[0].length}throw{code:"T0410",stack:(new Error).stack,value:t[r],index:r+1}};return{definition:e,validate:function(e,n){var r="";e.forEach(function(t){r+=m(t)});var i=g.exec(r);if(i){var o=[],a=0;return s.forEach(function(r,s){var c=e[a],l=i[s+1];if(""===l)if(r.context&&r.contextRegex){var h=m(n);if(!r.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"===r.type){if("m"===n)c=void 0;else{c=e[a];var i=!0;if(void 0!==r.subtype)if("a"!==n&&l!==r.subtype)i=!1;else if("a"===n&&c.length>0){var s=m(c[0]);i=s===r.subtype.charAt(0)&&0===c.filter(function(t){return m(t)!==s}).length}if(!i)throw{code:"T0412",stack:(new Error).stack,value:c,index:a+1,type:t[r.subtype]};"a"!==n&&(c=[c])}o.push(c),a++}else o.push(c),a++})}),o}y(e,r)}}}return e}();e.exports=s},{"./utils":6}],6:[function(t,e,n){function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=i(t))||e){n&&(t=n);var r=0,s=function(){};return{s:s,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},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 i(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,r=new Array(e);n<e;n++)r[n]=t[n];return r}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 i(){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 r=Object.getOwnPropertyNames(t),i=Object.getOwnPropertyNames(e);if(r.length!==i.length)return!1;for(r=r.sort(),i=i.sort(),n=0;n<r.length;n++)if(r[n]!==i[n])return!1;for(n=0;n<r.length;n++){var s=r[n];if(!u(t[s],e[s]))return!1}return!0}return!1}function p(t){var e,n=[],i=r(t);try{for(i.s();!(e=i.n()).done;){var s=e.value;n.push(s)}}catch(t){i.e(t)}finally{i.f()}return n}return{isNumeric:t,isArrayOfStrings:e,isArrayOfNumbers:n,createSequence:i,isSequence:s,isFunction:a,isLambda:l,isIterable:d,getFunctionArity:c,isDeepEqual:u,stringToArray:p}}();e.exports=a},{}]},{},[3])(3)}(ti)),ti.exports),ni=Qr(ei);const ri=function(t){return t};function ii(t){if(!t)return ri;try{const e=ni(function(t){return t.replace(/(?<=^|\.|\[)([a-zA-Z_][\w]*-[\w-]*)(?=\.|$|\[|])/g,"`$1`")}(t));return function(t){return e.evaluate(t)}}catch(t){return Wr(t),ri}}function si(t){const e=mr(t);return null==e?"":String(e)}function oi(t){return Number(mr(t))}function ai(t){return t}function ci(t){return si(t)}function li(t){return oi(t)}function hi(t){if(this.param)return t=si(t),this.param.hasOwnProperty(t)?this.param[t]:this.param.default}function di(t){const{param:e}=this;if(e){for(const n in e){let[r,i]=n.split("~");const s=!!r,o=!!i,a=parseFloat(r),c=parseFloat(i);if(t=oi(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 ui(t){return oi(t)*Math.PI/180}function pi(){}const fi=[/\bimport\b/,/\brequire\b/,/\b__proto__\b/,/\bconstructor\s*\[/,/\bprototype\b/];const gi=["globalThis","self","top","parent","frames","fetch","XMLHttpRequest","eval","Function","require","importScripts","process"],mi=new Array(gi.length).fill(void 0);function yi(t){try{!function(t){for(const e of fi)if(e.test(t))throw new Error(`Blocked pattern detected: ${e}`)}(t);const e=new Function("value","targets","scene",...gi,t);return function(t,n){try{return e.call(this,t,n,globalThis.scene,...mi)}catch(t){return void Wr(t)}}}catch(t){return Wr(t),pi}}function bi(t,e,n,r,i){switch(n){case"value":return"text"===i||"string"===i?ci.bind(t):"number"===i?li.bind(t):ai.bind(e);case"map":return hi.bind(t);case"range":return di.bind(t);case"radian":return ui.bind(t);case"eval":return yi(r).bind(e);default:return ai.bind(e)}}class vi{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:r,param:i,accessor:s}=t;this._model=t,this.evaluator=bi(this,this.owner,r,i,function(t){switch(t){case"ref":case"fillStyle":case"strokeStyle":return"string";default:return}}(n)),this.accessor=ii(s);const o=e.match(/\[(.*?)\]/);if(o){const[t,e]=o[1].split(":");this.propAccessor=ii(t),this.partAccessor=ii(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 xi(t,e,n,r){r?t.forEach(t=>t[e]={...t[e],...n}):t.forEach(t=>t[e]=n)}function _i(t=!1){(t||void 0!==this.data)&&this.mappings&&this.mappings.forEach(t=>{try{let e,{source:n,target:r,property:i,accessor:s,propAccessor:o,partAccessor:a,ndnsp:c=!1,partial:l=!1}=t;n&&"(self)"!=n?(n.startsWith("#")&&(n=n.substring(1)),e=this.root.findById(n)?.data||{}):e=this.data;const h=s(e);if(r=r.trim(),"(root)"==r||"(key)"==r){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]);!i||"(action)"===i||c&&!n&&0!==n&&!1!==n||(e[i]=l?{...e[i],...n}:n)})}else if(r.startsWith("[")){if(null==h)return;if(h instanceof Array)h.forEach(e=>{const n=o(e);if(n){const r=this.root.findOrCreate(n);if(r){const n=t.evaluator(a(e),r);!i||"(action)"===i||c&&!n&&0!==n&&!1!==n||xi(r,i,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);!i||"(action)"===i||c&&!e&&0!==e&&!1!==e||xi(n,i,e,l)}}}}}else{const e=this.root.findAll(r,this);if(e.length>0){const n=t.evaluator(h,e);!i||"(action)"===i||c&&!n&&0!==n&&!1!==n||xi(e,i,n,l)}}}catch(e){Wr(e,this,t)}})}function wi(t,e){this.state.persistent&&this.app?.isViewMode&&this.app?.dataStorage.save(this,t.data),_i.call(this,!0)}function Mi(){if(this._model.mappings)return this._model.mappings instanceof Array?void(this._mappings=(this._model.mappings||[]).filter(t=>t.rule&&t.target).map(t=>new vi(t,this))):(Wr("Mappings model is invalid (should be a Array) ..",this._model.mappings),void(this._mappings=[]));this._mappings=[]}function Si(){this._mappings&&this._mappings.forEach(t=>t.dispose()),delete this._mappings}function Ai(t,e){this.disposeMappings(),_i.call(this)}function ki(t,e,n,r,i,s){e.complete?t.drawImage(e,n,r,i,s):e.addEventListener("load",()=>{this.invalidate()})}function Ei(t){const{effects:e}=this.state;(e||[]).forEach(e=>{this.effect(t,e)})}const Ci={},Pi=0,Ti=1,Oi=2,Di=3,Ii=4,zi=5,Li={VIEW:0,EDIT:1,SHIFT:2,ADD:3},ji=30,Ri="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),Fi=["mousemove","mouseup","mousedown","mouseout","wheel","touchstart","touchmove","touchend","dblclick"],Bi=["keydown","keyup"],Ni={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},Yi=()=>{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";Ni.FONT_FAMILY=e||n},Vi=()=>{if("undefined"!=typeof window&&"undefined"!=typeof document&&(window.addEventListener("load",()=>{Yi()}),"fonts"in document&&"ready"in document.fonts&&document.fonts.ready.then(Yi),"undefined"!=typeof MutationObserver&&document.documentElement)){new MutationObserver(()=>{Yi()}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}};let Gi;function Hi(t,e,n,r,i){const{alpha:s=1}=r,o=i.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 r,{width:i,height:s}=e;if("linear"==o.gradientType){const e=3.141592653589793,n=o.rotation;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((i-4)/2,2)+Math.pow((s-4)/2,2));o-=o-(i+s)/3,r=t.createLinearGradient(o*Math.cos(n+e),o*Math.sin(n+e),o*Math.cos(n),o*Math.sin(n))}else r=t.createLinearGradient((i-4)/2*Math.cos(n+e),(s-4)/2*Math.sin(n+e),(i-4)/2*Math.cos(n),(s-4)/2*Math.sin(n))}else if("radial"==o.gradientType){const e=.95*Math.sqrt(Math.pow((i-4)/2,2)+Math.pow((s-4)/2,2));switch(o.center){case"center":default:r=t.createRadialGradient(0,0,0,0,0,e);break;case"left-top":r=t.createRadialGradient(-i/2,-s/2,0,-i/2,-s/2,2*e);break;case"right-top":r=t.createRadialGradient(i/2,-s/2,0,i/2,-s/2,2*e);break;case"left-bottom":r=t.createRadialGradient(-i/2,s/2,0,-i/2,s/2,2*e);break;case"right-bottom":r=t.createRadialGradient(i/2,s/2,0,i/2,s/2,2*e)}}o.colorStops.forEach(t=>{if(t.position>=0&&t.position<=1)try{r.addColorStop(t.position,t.color)}catch(e){Xr("Invalid Color for colorstop : ",t.color),r.addColorStop(t.position,"#fff")}}),t.fillStyle=r,t.fill(),t.translate(-n.x,-n.y)}else if("pattern"==o.type&&o.image)if(o.guideOnly&&1!=i.app.mode)o.color&&(t.fillStyle=o.color,t.fill());else{i.prepareFillIf(!i._pattern_image_origin);const n=i._pattern_image;if(!n)return;let r=0,s=0,a=0,c=0,l=e.left,h=e.top;if(!o.fitPattern){r=o.offsetX,s=o.offsetY;const t=o.width?o.width:n.width,i=o.height?o.height:n.height;switch(o.align){case"center":a=e.width/2-t/2,c=e.height/2-i/2;break;case"left-top":a=0,c=0;break;case"left-bottom":a=0,c=e.height-i;break;case"right-top":a=e.width-t,c=0;break;case"right-bottom":a=e.width-t,c=e.height-i;break;case"left":a=0,c=e.height/2-i/2;break;case"right":a=e.width-t,c=e.height/2-i/2;break;case"top":a=e.width/2-t/2,c=0;break;case"bottom":a=e.width/2-t/2,c=e.height-i}l+=r+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 i._pattern_image,delete i._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 Ui(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 r=this;this._pattern_image_origin.onload=function(){if(!n.fitPattern&&!n.width&&!n.height)return r._pattern_image=r._pattern_image_origin,void t(this);let e=n.width||this.width,i=n.height||this.height;n.fitPattern&&(e=r.bounds.width,i=r.bounds.height);const s=Gi(e,i);s.getContext("2d").drawImage(this,0,0,this.width,this.height,0,0,e,i),r._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 Wi(t){t&&this.prepareFill(t=>{this.invalidate()},t=>{Wr(t)})}function Xi(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 qi(t,e,n){let{strokeStyle:r,lineDash:i,lineWidth:s,lineCap:o,lineJoin:a,alpha:c}=e;if(r&&0!=s){if(o&&(t.lineCap=o),i){const e="round"==o;switch(i){case"solid":i=[0,0];break;case"round-dot":i=e?[0,2*s]:[s,s];break;case"square-dot":i=e?[s,2*s]:[2*s,s];break;case"dash":i=e?[3*s,2.5*s]:[4*s,1.5*s];break;case"dash-dot":i=e?[3*s,3*s,0,3*s]:[4*s,2*s,s,2*s];break;case"long-dash":i=e?[5*s,4*s]:[6*s,3*s];break;case"long-dash-dot":i=e?[5*s,3*s,0,3*s]:[6*s,2*s,s,2*s];break;case"long-dash-dot-dot":i=e?[5*s,2*s,0,2*s,0,2*s]:[6*s,s,s,s,s,s]}t.setLineDash(i)}t.globalAlpha*=c,t.strokeStyle=r,t.lineWidth=s,t.lineJoin=a,t.stroke()}}function Ki(t){const e=/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3|([^\*_]+)/g,n=[];let r;for(;null!==(r=e.exec(t));)r[1]?n.push({text:r[2],bold:!0,italic:!1}):r[3]?n.push({text:r[4],bold:!1,italic:!0}):r[5]&&n.push({text:r[5],bold:!1,italic:!1});return n}function $i(t,e,n,r=0){if(e.text.length<2)return e;let i=2;for(;i<e.text.length;i++){const s=e.text.substring(0,i);if(!(t.measureText(s).width+(i-1)*r<n))break}return{...e,text:e.text.substring(0,i-1)}}function Qi(t,e,n,r,i,s=0){const o=String(e).split("\n");return r?[].concat(...o.map(e=>function(t,e,n,r=0){const i=[];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)*r;if(l<=c)s.push({...e,text:a}),o+=l,a="";else{const n=$i(t,{...e,text:a},c,r);s.push(n),i.push(s),s=[],o=0,a=a.substring(n.text.length)}}}),s.length>0&&i.push(s),i}(t,i?Ki(e):[{text:e,bold:!1,italic:!1}],n,s))):o.map(t=>i?Ki(t):[{text:t,bold:!1,italic:!1}])}function Zi(t,e,n,r,i,s,o=0){if(!r)return[];t.save(),t.font=n;const a=Qi(t,r,e,!!i,s,o);return t.restore(),a}function Ji(t){const{fontFamily:e=Ni.FONT_FAMILY,bold:n=Ni.BOLD,italic:r=Ni.ITALIC,fontSize:i=Ni.FONT_SIZE}=t,s=[];return n&&s.push("bold"),r&&s.push("italic"),s.push(i+"px"),s.push(e),s.join(" ")}function ts(t,e){const n=t.bold||e.bold,r=t.italic||e.italic;return Ji({...t,bold:n,italic:r})}function es(t,e,n,r){let{alpha:i,rotation:s,keepTextAngle:o=!1,fontColor:a=Ni.FONT_COLOR,textAlign:c=Ni.TEXT_ALIGN,textBaseline:l=Ni.TEXT_BASELINE,textBackgroundStyle:h,fontSize:d,lineHeight:u,textWrap:p,textOverflow:f,letterSpacing:g=0}=r;i=void 0!==i?i:1,d||=Ni.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=Ji(r),!p&&f){const e=function(t,e,n,r){const i="ellipsis"===t?"…":"",s=e.measureText(i).width,o=[];let a=0;for(const i of n){const n=[];for(const c of i){const i=e.measureText(c.text).width;if(!(a+i<=r-("ellipsis"===t?s:0))){const i=ns(e,c,r-a-("ellipsis"===t?s:0),t);return n.push(i),o.push(n),o}n.push(c),a+=i}o.push(n),a=0}return o}(f,t,n,b);n=e}const x=n.length*u;let _;switch(l){case"top":_=y,t.textBaseline="top";break;case"bottom":_=y+v-x+u,t.textBaseline="bottom";break;default:_=y+v/2-x/2+u/2,t.textBaseline="middle"}t.globalAlpha*=i,t.fillStyle=a,n.forEach((e,i)=>{const s=_+i*u,o=function(t,e,n,r=0){return e.reduce((e,i)=>(t.font=ts(n,i),e+t.measureText(i.text).width+r*(i.text.length-1)),0)}(t,e,r,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,r,i,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+r-s.tr,n),t.quadraticCurveTo(e+r,n,e+r,n+s.tr),t.lineTo(e+r,n+i-s.br),t.quadraticCurveTo(e+r,n+i,e+r-s.br,n+i),t.lineTo(e+s.bl,n+i),t.quadraticCurveTo(e,n+i,e,n+i-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&&i<n.length-1&&e.length>1){const n=b-o,i=e.length-1,a=n/i;e.forEach((e,n)=>{t.font=ts(r,e),t.fillText(e.text,l,s),l+=t.measureText(e.text).width+(n<i?a:0)})}else e.forEach(e=>{t.font=ts(r,e),[...e.text].forEach(e=>{t.fillText(e,l,s),l+=t.measureText(e).width+g})})}),t.restore()}function ns(t,e,n,r){let i="";for(let r=0;r<e.text.length;r++){const s=i+e.text[r];if(t.measureText(s).width>n)break;i=s}return{...e,text:i+("ellipsis"===r?"…":"")}}function rs(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})}Vi(),Yi(),Gi="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 is=[];function ss(t,e,n={x:0,y:0},r=0,i={x:1,y:1}){const s=Math.cos(-r),o=Math.sin(-r);return{x:((t-=n.x)*s-(e-=n.y)*o+n.x)/i.x,y:(t*o+e*s+n.y)/i.y}}function os(t,e,n={x:0,y:0},r=0,i={x:1,y:1}){const s=Math.cos(r),o=Math.sin(r);return{x:((t-=n.x)*s-(e-=n.y)*o+n.x)*i.x,y:(t*o+e*s+n.y)*i.y}}function as(t,e,n){if(!this.parent)return{x:t,y:e};const{rotation:r=0,scale:i={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,s=ss(t,e,n,r,i);return n&&(s.x-=n.x/i.x,s.y-=n.y/i.y),s}const s=ss(t,e,n=n||this.rotatePoint,r,i);return{x:s.x+(n.x-n.x/i.x),y:s.y+(n.y-n.y/i.y)}}function cs(t,e,n){if(!this.parent)return{x:t,y:e};let{rotation:r=0,scale:i={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,s=os(t,e,void 0,r+(this._delta?.theta??0),i);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||{};n={x:n.x+o,y:n.y+a},i={x:i.x*c,y:i.y*l};const h=os(t+o,e+a,n,r+s,i);return{x:h.x-(n.x*i.x-n.x),y:h.y-(n.y*i.y-n.y)}}function ls(t,e,n){n=n||this.rootModel;const r=this.transcoordS2T(t,e,n);return os(r.x,r.y,void 0,(n.get("rotation")||0)+n._delta.theta)}function hs(t,e,n){n=n||this.rootModel,is.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)is.push(t);let r=this.transcoordS2P(t,e);for(let t=0;t<is.length;t++){const e=is[t],{scale:n}=e.model,i=e.bounds;if(n){const t=e.rotatePoint;r.x+=(t.x-i.left)*n.x,r.y+=(t.y-i.top)*n.y}else r.x+=i.left,r.y+=i.top;r=e.transcoordS2P(r.x,r.y)}return r}function ds(t,e,n){n=n||this.rootModel,is.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)is.push(t);let r={x:t,y:e};for(let t=is.length-1;t>=0;t--){const e=is[t],{scale:n}=e.model;r=e.transcoordP2S(r.x,r.y);const i=e.bounds;if(n){const t=e.rotatePoint;r.x-=(t.x-i.left)/n.x,r.y-=(t.y-i.top)/n.y}else r.x-=i.left,r.y-=i.top}return r}function us(t,e,n){const r=this.transcoordT2P(t,e,n);return this.transcoordP2S(r.x,r.y)}function ps(t,e,n){const r=this.rootModel,i=this.transcoordS2T(t,e,r);return n.transcoordT2S(i.x,i.y,r)}function fs(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;const{translate:r={x:0,y:0},scale:i={x:1,y:1},rotation:s=0}=n.model,o=ss(t,e,r,s,i);return r&&(o.x-=r.x/i.x,o.y-=r.y/i.y),n===this?o:this.transcoordT2S(o.x,o.y,n)}function gs(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;let r;if(r=n!==this?this.transcoordS2T(t,e,n):{x:t,y:e},!this.scalable)return r;const{translate:i={x:0,y:0},rotation:s=0,scale:o={x:1,y:1}}=n.model;return r=os(r.x,r.y,void 0,s+n._delta.theta,o),i&&(r.x+=i.x,r.y+=i.y),r}function ms(t){const e=t.element,n=t.fillStyle,r=e.style;if(n)if("string"==typeof n)r.backgroundColor=n;else switch(n.type){case"pattern":if(r.backgroundImage="url("+n.image+")",r.backgroundColor="transparent",n.fitPattern?r.backgroundSize="100% 100%":n.width||n.height?r.backgroundSize=`${n.width?n.width+"px":"auto"} ${n.height?n.height+"px":"auto"}`:r.backgroundSize="contain",n.fitPattern)r.backgroundRepeat="no-repeat";else{const{offsetX:t,offsetY:e,noRepeat:i,align:s,color:o}=n;if(i&&(r.backgroundRepeat="no-repeat"),o&&(r.backgroundColor=o),s)switch(s){case"center":r.backgroundPosition="center center";break;case"left-top":r.backgroundPosition="left top";break;case"left-bottom":r.backgroundPosition="left bottom";break;case"right-top":r.backgroundPosition="right top";break;case"right-bottom":r.backgroundPosition="right bottom";break;case"left":r.backgroundPosition="left center";break;case"right":r.backgroundPosition="right center";break;case"top":r.backgroundPosition="center top";break;case"bottom":r.backgroundPosition="center bottom"}else t||e?r.backgroundPosition=`${Number(t)||0}px ${Number(e)||0}px`:delete r.backgroundPosition}break;case"gradient":r.background=function(t,e){const n=e.colorStops,r=e.gradientType;if(n instanceof Array&&n.length>0)switch(r){case"radial":return"radial-gradient(farthest-corner at "+function(t,e){const{width:n,height:r}=t.bounds;switch(e){case"center":return[n/2,r/2];case"left-top":return[0,0];case"right-top":return[n,0];case"left-bottom":return[0,r];default:return[n,r]}}(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 r.background="transparent"}const ys={x:1,y:1},bs={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"};function vs(t){let{id:e,scale:n=ys,bold:r,italic:i,fontFamily:s="",textAlign:o,textBaseline:a,textOverflow:c,paddingTop:l,paddingBottom:h,paddingLeft:d,paddingRight:u,fontSize:p=Ni.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:x,hidden:_}=t,{left:w,top:M,width:S,height:A}=t.bounds,k=t.element;if(k.hidden=_,e&&(k.id=e),y&&(k.className=y),Object.assign(k.style,bs,{fontFamily:s,fontSize:p+"px",width:S+"px",height:A+"px",paddingTop:l+"px",paddingRight:u+"px",paddingBottom:h+"px",paddingLeft:d+"px",border:f+"px",borderColor:b,borderStyle:f>0?m||Ni.LINE_DASH:"",color:x,fontWeight:r?"bold":"",fontStyle:i?"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"}),ms(t),function(t){if(!t.isShadowable()||!t.state.shadow)return;const e=t.element,{left:n=0,top:r=0,blurSize:i=0,color:s="transparent"}=t.state.shadow;e.style.boxShadow=`${n}px ${r}px ${i}px ${s}`}(t),t.isIn3DSpace())return;const E=t.delta(),C=(n&&n.x||1)*E.sx,P=(n&&n.y||1)*E.sy,T=(v||0)+E.theta,O=E.tx||0,D=E.ty||0;k.style.transform=`rotate(${T}rad) translate(${O}px, ${D}px) scale(${C}, ${P}) perspective(1px)`}function xs(t,e){let n=this.bounds,r=this.rotatePoint;const i=this.get("rotation"),s=this.get("scale");if(t){const r=t.call(e,n);r&&(n=r)}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=>os(t.x,t.y,r,i,s));let d=h[0],u=h[1];r={x:(d.x+u.x)/2,y:(d.y+u.y)/2},h=h.map(t=>ss(t.x,t.y,r,i,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 _s(t,e,n){let r=this.path,i=this.rotatePoint;this.get("rotation"),this.get("scale"),t&&(r=t.call(n,r));let s=r.map(t=>this.toParent(t.x,t.y));if(e){const t=e.call(n,s);t&&(s=t)}const o={x:0,y:0};let a,c,l,h;r=s.map(t=>this.fromParent(t.x,t.y,o)),a=c=r[0].x,l=h=r[0].y;for(let t=1;t<r.length;t++){const e=r[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)}i={x:(a+c)/2,y:(l+h)/2},i=this.toParent(i.x,i.y,o),this.path=s.map(t=>this.fromParent(t.x,t.y,i))}let ws,Ms=[];function Ss(){ws=null;const t=performance.now();Ms=Ms.filter(t=>As(t));const e=Ms.reduce((e,n)=>{const r=t-n.updatedAt;return r>=n.retention?e.kills.push(n):e.next=0==e.next?n.retention-r:Math.min(e.next,n.retention-r),e},{next:0,kills:[]});e.kills.forEach(t=>{const e=Ms.indexOf(t);-1!=e?(Ms.splice(e,1),t.removeSelf(!0)):Wr("Should not be here. Maybe reentrance problem.")}),e.next>0&&(ws=setTimeout(ks,Math.max(e.next,500)))}function As(t){return!t.disposed&&t.retention>0&&!t.isTemplate()&&t.app&&t.app.isViewMode}const ks=cr(function(){requestAnimationFrame(Ss)},500);var Es=new class{add(t){As(t)&&-1==Ms.indexOf(t)&&(Ms.push(t),t.touch()),this.touch()}remove(t){const e=Ms.indexOf(t);e>0&&Ms.splice(e,1),this.touch()}touch(){null!==ws&&(clearTimeout(ws),ws=null),ks()}dispose(){ks.cancel(),null!==ws&&(clearTimeout(ws),ws=null),Ms=[]}get length(){return Ms.length}};const Cs=function(t){return t};function Ps(t){const e=t.indexOf("||");let n="",r="";-1!=e&&(n=t,r=t.substring(e+2,t.length-1).trim(),t=t.replace(t.substring(e,t.length-1),"").trim());const i=t.substr(2,t.length-3).trim().replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".").filter(t=>!!t.trim()),s=i.slice(1);return{defaultValue:r,match:t,originText:n||t,target:i[0],accessor:s.length>0?function(t){return s.reduce((t,e)=>t?t[e]:void 0,t)}:Cs}}function Ts(t){if(!t)return;const e=String(t),n=(e.match(/#{(\S*)}/)||[]).map(t=>Ps(t))[0];if(n)return n.accessor(this.getState(n.target));const r=(e.match(/\${[^}]*}/)||[]).map(t=>Ps(t))[0];if(r){const t=this.root.findById(r.target);return r.accessor(this.getState(t))}return t}function Os(t,e){if(!t)return;const n=String(t),r=e||mr,i=(n.match(/#{(\S*)}/gi)||[]).map(t=>Ps(t)),s=(n.match(/\${[^}]*}/gi)||[]).map(t=>Ps(t));if(0==i.length&&0==s.length)return n;let o=n;return i.forEach(t=>{const e=r(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=r(t.accessor(e&&e.data));o=o.replace(t.match,void 0===n?"":n)}),o}function Ds(t,e,n){if(!t)return;const r=n||mr,i=String(t),s=(i.match(/#{[^}]*}/gi)||[]).map(t=>Ps(t)),o=(i.match(/\${[^}]*}/gi)||[]).map(t=>Ps(t));return 0!=s.length||0!=o.length?function(){let t=i;return s.forEach(n=>{const i=r(n.accessor(e.getState(n.target)));t=t.replace(n.originText,void 0===i?n.defaultValue||"":i)}),o.forEach(n=>{const i=e.root.findById(n.target),s=r(n.accessor(i&&i.data));t=t.replace(n.originText,void 0===s?n.defaultValue||"":s)}),t}:void 0}class Is{constructor(){}static registerDecorator(t,e){Is.constructors.set(t,e)}static create(t,e,n={},r){const i=Is.constructors.get(t);if(!i)throw new Error(`unknown decorator type: ${t}`);return new i(r,e,n)}}Is.constructors=new Map;class zs{constructor(){this.overlays=new WeakMap}static getInstance(){return zs.instance||(zs.instance=new zs),zs.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,r={}){this.overlays.has(t)||this.addOverlay(t);const i=this.overlays.get(t);i.registry.has(e)||i.registry.set(e,new Map);const s=i.registry.get(e);s.has(n)&&s.get(n).stop();const o=Is.create(n,e,r,t);return s.set(n,o),o.start(),o}removeFromOverlay(t,e,n){if(!this.overlays.has(t))return;const r=this.overlays.get(t);if(!r.registry.has(e))return;const i=r.registry.get(e);let s=null;if(n){if(i.has(n))try{const t=i.get(n);s=n,t&&"function"==typeof t.stop&&t.stop(),i.delete(n)}catch(t){Wr(`데코레이터(${n}) 제거 중 오류:`,t)}}else{const t=Array.from(i.keys());for(const e of t)try{const t=i.get(e);t&&"function"==typeof t.stop&&t.stop(),i.delete(e)}catch(t){Wr(`데코레이터(${e}) 제거 중 오류:`,t)}s="_all_"}0===i.size&&r.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,r]of n.registry.entries()){if(e&&t===e)continue;const n=r.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){Wr("애니메이션 재시작 중 오류:",t)}}}removeAllFromOverlay(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);if(e)for(const[r]of n.registry)this.removeFromOverlay(t,r,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 r=this.overlays.get(t);return r?.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 r=[];for(const[t,i]of n.registry)i.has(e)&&r.push(t);return r}updateInOverlay(t,e,n,r){const i=this.getDecoratorFromOverlay(t,e,n);i&&i.update(r)}invalidateOverlay(t){if(!this.overlays.has(t))return;const e=this.overlays.get(t),n=Array.from(e.registry.entries());for(const[e,r]of n){if(e.disposed){this.removeFromOverlay(t,e);continue}this.getDecoratorsFromOverlay(t,e).forEach(t=>{t.invalidate()})}}}function Ls(t,e){return!1}function js({x:t,y:e},...n){const r=this.path,i=t,s=e;this.path=r.map(t=>({x:t.x+i,y:t.y+s}))}function Rs(t){const e=t??this.center.x,{rotation:n}=this.state,r=this.fillStyle;if(this.set("rotation",2*Math.PI-n),r&&"gradient"===r.type&&"linear"===r.gradientType){const t=Kn(r);t.rotation=(Math.PI-parseFloat(r.rotation||0))%(2*Math.PI),this.set("fillStyle",t)}this.path=this.path.map(t=>({x:2*e-t.x,y:t.y}))}function Fs(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 Bs(t,e,n){if(n){const e=this.bounds,n=e.height/e.width;let r=t.width-e.width,i=t.height-e.height;r*n>i?i=r*n:r=i/n;let s=t.left-e.left,o=t.top-e.top;return 0!=s&&0!=o?(o=-i,s=-r):0!=s?s=-r:0!=o&&(o=-i),{left:e.left+s,top:e.top+o,width:e.width+r,height:e.height+i}}return t}function Ns(t,e){if(e||this.app.rotateStepForced){const e=this.app.rotateStep;return Math.floor((t+e/2)/e)*e}return t}function Ys(t){return function(t,e){const n=t.path.slice();if(!n||!n.length)return void Wr("path should not be empty");let r=1;const i=[];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[r];){const t=n[r-1],e=n[r],s=e.x-t.x,o=e.y-t.y;i.push(Math.sqrt(s*s+o*o)),r++}const s=i.reduce(function(t,e){return t+e},0);r=0;let o=0;do{o+=i[r++]}while(o/s<e);o-=i[--r],e=(e-o/s)*(s/i[r]);const a=n[r%n.length],c=n[(r+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 Vs(){const t=this.path;let e,n,r,i;e=n=t[0].x,r=i=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<r?r=o.y:o.y>i&&(i=o.y)}return{left:e,top:r,width:n-e,height:i-r}}function Gs(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,r=0==e.height?1:t.height/e.height;this.path=this.path.map(i=>({x:t.left+(i.x-e.left)*n,y:t.top+(i.y-e.top)*r}))}function Hs(){const t=this.bounds;return{x:t.left+t.width/2,y:t.top+t.height/2}}function Us(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,r=t.y-e.y;this.path=this.path.map(t=>({x:t.x+n,y:t.y+r}))}function Ws(){const{x:t,y:e}=this.center;return{x:t,y:e,z:this.state.zPos}}function Xs(t){const{x:e,y:n,z:r}=t||{};this.center={x:e,y:n},isNaN(r)||this.setState("zPos",Number(r))}function qs(){const{rotationX:t,rotationY:e,rotation:n}=this.state;return{x:t,y:e,z:-n}}function Ks(t){const{x:e,y:n,z:r}=t;this.setState({rotationX:e,rotationY:n,rotation:-r})}function $s(){const{width:t,height:e}=this.bounds,{depth:n}=this.state;return{width:t,height:e,depth:n}}function Qs(t){const{width:e,height:n,depth:r}=t,{top:i,left:s}=this.bounds;this.bounds={top:i,left:s,width:e,height:n},this.setState("depth",r)}function Zs(){return Wr("이 컴포넌트에 get path 가 구현되어있지 않음.",this),[]}function Js(t){Wr("이 컴포넌트에 get path 가 구현되어있지 않음.",this)}function to(){return this.path}function eo(){return this.center}function no(){return this.nature.mutable}function ro(){return this.nature.resizable&&!this.stuck}function io(){return this.nature.rotatable&&!this.stuck}const so={x:1,y:1};function oo(t,e,n){const{left:r=0,top:i=0,blurSize:s=0,color:o="transparent"}=e,a=n.rootModel.get("scale")||so;t.shadowOffsetX=r*a.x*Ri,t.shadowOffsetY=i*a.y*Ri,t.shadowBlur=s*a.x*Ri,t.shadowColor=o}function ao(t){t.save(),this.prerender(t),this.render(t),this.postrender(t),t.restore()}function co(t){const e=this.rotatePoint,{scale:n,rotation:r,shadow:i,alpha:s}=this.state,o=(n&&n.x||1)*this._delta.sx,a=(n&&n.y||1)*this._delta.sy,c=(r||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),i&&oo(t,i,this),this.app.isEditMode&&this.hidden&&(t.globalAlpha*=.5)}function lo(t){}function ho(t){this.drawText(t)}function uo(t,e){t(this)}function po(t){t&&this.prepare&&this.prepare(t=>{this.invalidate()},t=>{Wr(t)})}function fo(t){!this.textHidden&&this.text&&this.hasTextProperty&&es(t,this.textBounds,this.textLines(t),this.state)}function go(t,e){qi(t,e?{...this.state,...e}:this.state)}function mo(t,e){this.fillStyle&&"transparent"!=this.fillStyle&&(Hi(t,this.bounds,this.center,e?{...this.state,...e}:this.state,this),function(t){t.shadowColor="transparent"}(t))}function yo(){return this.get("strokeStyle")}function bo(t){this.set("strokeStyle",t)}function vo(){return this.getState("fillStyle")}function xo(t){this.setState("fillStyle",t)}function _o(){return this.get("fontColor")}function wo(t){this.set("fontColor",String(mr(t)))}function Mo(){return this.getState("rotation")}function So(t){this.setState("rotation",Number(mr(t)))}function Ao(){return this.app.isEditMode?["decotag","data-spread"]:[]}function ko(){const{id:t,tag:e}=this.state;return(t?`#${t}`:"")+(e?`@${e}`:"")}function Eo(){return this.getState("hidden")||!this.data&&0!==this.data&&this.getState("ndns")||this.isTemplate()}function Co(t){this.setState("hidden",t)}function Po(){return this.state.tag}function To(t){this.setState("tag",t)}function Oo(){}function Do(t){this.data instanceof Array?this.data=this.data.concat(t):this.data instanceof Object?this.data={...this.data,...t}:this.data??=t}function Io(){const t=this.getState("text");return null==t?"":String(t)}function zo(t){const{textWrap:e,supportMarkdown:n}=this.state;return Zi(t||this.getContext(),this.textBounds.width,this.font,this.text,e,n)}function Lo(){return Ji(this.model)}function jo(){const t=this.get("lineHeight");return t||1.2*this.fontSize}function Ro(){return this._text_substitutor||(this._text_substitutor=Ds(this.getState("text"),this,void 0)||this.defaultTextSubstitutor),this._text_substitutor}function Fo(){const t=this.get("textFormat");return t?function(t,e){if(!t||isNaN(+e))return e;let n,r,i,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),x=b+("."===v||","===v?1:0),_=y>0?t.substring(x,p):"";if(n=(e="-"===(t=t.substring(f,x)).charAt(0)?-e:+e)<0?e=-e:0,r=t.match(/[^\d\-\+#]/g),i=".",s=r&&r[1]&&r[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,x=0;x<p;x++)m+=d.charAt(x),!((x-b+1)%c)&&x<p-c&&(m+=s);e[0]=m}return e[1]=t[1]&&e[1]?"."+e[1]:"",r=e.join(""),"0"!==r&&""!==r||(n=!1),u="+"==t[0].substring(0,1)?n?"-":"+":n?"-":"",g+(u+r)+_}(t,this.textSubstitutor()):this.textSubstitutor()}function Bo(t){delete this._text_substitutor;const e=mr(t);this.setState("text",null==e?"":String(e))}function No(){let{paddingTop:t,paddingLeft:e,paddingRight:n,paddingBottom:r}=this.state;r||=0,t||=0,e||=0,n||=0;const{left:i,top:s,width:o,height:a}=this.bounds;return{left:i+e,top:s+t,width:Math.max(o-e-n,0),height:Math.max(a-t-r,0)}}function Yo(){return 0}function Vo(){return!!this._textHidden}function Go(t){this._textHidden=!!t,this.invalidate()}function Ho(){return!0}function Uo(t){return t}function Wo(t){return Math.pow(t,2)}function Xo(t){return 1-Math.sin(Math.acos(t))}function qo(t,e={x:1.5}){return Math.pow(t,2)*((e.x+1)*t-e.x)}function Ko(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 $o(t,e={x:1.5}){return Math.pow(2,10*(t-1))*Math.cos(20*Math.PI*e.x/3*t)}var Qo={linear:Uo,quad:Wo,circ:Xo,back:qo,bounce:Ko,elastic:$o},Zo=Object.freeze({__proto__:null,back:qo,bounce:Ko,circ:Xo,default:Qo,elastic:$o,linear:Uo,quad:Wo});function Jo(t){const{duration:e=1e3,easing:n,step:r=()=>{},onStart:i,onProgress:s,onComplete:o,options:a,repeat:c=!1,delta:l}=t;let h;h="string"==typeof l?Zo[l]:l||Uo,"out"===n?h=function(t,e){return function(n){return 1-t(1-n,e)}}(h,a):"inout"===n&&(h=function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(h,a));let d=!1,u=null;return{start:function(){if(d)return this;d=!0,i&&i();let t=0;const n=()=>{if(!d)return;0===t&&(t=performance.now());const i=(performance.now()-t)/e,o=c?i%1:Math.min(i,1);r(h(o,a)),s&&s(o),!(i>=1)||c&&d||(this.stop(),t=0),d&&(u=requestAnimationFrame(n))};return u=requestAnimationFrame(n),this},stop:function(){return d=!1,null!==u&&(cancelAnimationFrame(u),u=null),o&&o(),this}}}class ta{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:r,ease:i}=this.config;let s;s="string"==typeof n?Qo[n]:n,this.delta="out"===i?function(t,e){return function(n){return 1-t(1-n,e)}}(s,r):"inout"===i?function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(s,r):s,this.init()}dispose(){this.stop(),delete this.client}init(){}start(){if(this._started)return;const{duration:t=2e3,delay:e=0,repeat:n=!1,interval:r=0,onComplete:i}=this.config;this._started=!0;let s=0,o=0;const a=()=>{if(this._raf=null,this._timeout=null,!this._started)return;0==s&&(s=performance.now(),this.client?.touch?.());const c=performance.now()-s,l=Math.max((c-e)%(t+r),0)/t,h=r<=0&&o>l;if(o=l,l>=1||h){if(this.step(1),this.client&&this.client.invalidate?.(),!n||!this._started)return this.stop(i),void(s=0);if(r>0)return void(this._timeout=setTimeout(()=>{this.step(0),this.client&&this.client.invalidate?.(),this._timeout=setTimeout(a,r/2)},r/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 ea={rotation:class extends ta{step(t){const{theta:e=6.28}=this.config;this.client.delta?.("theta",t*e)}},vibration:class extends ta{step(t){const{theta:e=.2617993877991494}=this.config,n=4*e;let r=t*n;t<1/4?r*=-1:t<3/4?r-=2*e:r=n-r,this.client.delta?.("theta",r)}},heartbeat:class extends ta{step(t){const{scale:e=1.3}=this.config,n=2*(e-1);let r;r=t<.5?1+n*t:1+(1-t)*n,this.client.delta?.({sx:r,sy:r})}},moving:class extends ta{step(t){const{x:e=0,y:n=0}=this.config;this.client.delta?.({tx:t*e,ty:t*n})}},outline:class extends ta{step(t){const{rideOn:e}=this.config;if(!e||!this.client)return;const n=this.client.root.findById(e);if(!n)return;let r={tx:0,ty:0};const i=this.client.delta("");i&&"object"==typeof i&&"tx"in i&&"ty"in i&&(r=i);const{tx:s,ty:o}=r,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 ta{step(t){const{startAlpha:e=1,endAlpha:n=0}=this.config,r=Math.max(Math.min(e,n,1),0),i=2*(Math.min(Math.max(e,n,1),1)-r);let s;s=t<.5?i*t:(1-t)*i,this.client.delta?.("fade",s)}},waypoint:class extends ta{start(){let{toComponent:t,fromComponent:e}=this.config;e||(e=t);const n=e.center,r=t.center,{x:i,y:s}=e.toScene(n.x,n.y),{x:o,y:a}=t.toScene(r.x,r.y),c=Math.atan2(a-s,o-i)+Math.PI/2;this.client.location={x:i,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 r=n.center,i=e.center,{x:s,y:o}=n.toScene(r.x,r.y),{x:a,y:c}=e.toScene(i.x,i.y),l=(a-s)*t,h=(c-o)*t;this.client.location={x:s+l,y:o+h}}}};function na(t,e){const n=e.type?ea[e.type]:void 0;return n?new n(t,e):null}const ra={gradation:function(t,e,n){const{subType:r,from:i,to:s,colors:o}=n;let a;switch(r){case"linear":default:a=e.createLinearGradient(i.x,i.y,s.x,s.y);break;case"radial":a=e.createRadialGradient(i.x,i.y,i.r,s.x,s.y,s.r)}o&&(o.forEach(function(t){a.addColorStop(t.endPoint,t.color)}),e.fillStyle=a,e.fill())},shadow:oo};function ia(t){return this._animate&&this._animate.stop(),this._animate=Jo(t),this._animate}function sa(t,e){return function(t,e,n){const r=ra[n.type];r&&r(t,e,n)}(this,t,e)}function oa(...t){return JSON.stringify(this.hierarchy,...t)}function aa(){delete this._model[""],"chartjs"!==this._model.type&&delete this._model.chart}function ca(t){this.rootModel.closeScene(t)}function la(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 ha(){this.parent&&this.parent.invalidate()}function da(){const t=this.nature["value-property"]||"text";return"value"==t?this.getState("value"):this[t]}function ua(t){const e=this.nature["value-property"]||"text";"value"==e?this.setState("value",t):this[e]=t}function pa(){return this.getState("data")}function fa(t){this.setState("data",t),this.touch()}function ga(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 ma(){return!this._mappings&&this.parent&&this.buildMappings(),this._mappings}function ya(){return Number(this.get("retention"))||0}function ba(){if(this.app.isViewMode&&!this.isTemplate()){if(!this._animation){const t=this.state.animation;t&&t.oncreate&&(this._animation=na(this,t.oncreate))}return this._animation}}function va(){return!!this.animation?.started}function xa(t){this.animation&&(this.animation.started=t)}function _a(){}function wa(t,e,n,r){const i=e.get("class");if(!i)return!1;return(i.split(" ")||[]).indexOf(t.substr(1))>=0}function Ma(t,e,n,r){return t==e.get("type")}function Sa(t,e,n,r){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 wa(t,e);case"(":return function(t,e,n,r){switch(t){case"(all)":return!0;case"(self)":return r===e;case"(root)":return!r.parent&&r===e;case"(descendant)":return r!==e;case"(child)":return r===e.parent;default:return!1}}(t,e,0,r);default:return Ma(t,e)}}function Aa(t,e,n,r,i,s){return t(e,n,r,i)&&s.push(n),n.components&&n.components.forEach(n=>{Aa(t,e,n,r,i,s)}),s}function ka(t,e,n,r){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 Ea(t,e,n){if("(root)"==t)return[e];if("(self)"==t)return n?[n]:[];let r;switch(t.charAt(0)){case"#":const n=e.root.findAllById?.(t.substring(1));return n||[];case".":r=wa;break;case"(":r=ka;break;default:r=Ma}return Aa(r,t,e,n,e,[])}function Ca(t,...e){if(t(this,...e))return this}function Pa(t,...e){return"string"==typeof t?Ea(t,this,e[0]||this):"function"==typeof t&&t(this,...e)?[this]:void 0}function Ta(t,e,n){if(!this.capturable||n?.(this))return!1;const r=this.fromParent(t,e);return this.contains(r.x,r.y)?this:void 0}function Oa(t){return this.anchors.find(e=>e.name===t)}function Da(t){return!0}function Ia(t){return this._parent.getContext(t??this)}function za(){return this.isRoot()?this:this.parent&&this.parent.root}function La(){return this.isRootModel()?this:this.parent&&this.parent.rootModel}function ja(){return this._parent}function Ra(t){this._parent=t}function Fa(){return this.nature.anchors||[]}function Ba(){let t=this.position,e=this;for(;"static"===t&&e.parent;)e=e.parent,t=e.position;return"static"==t}function Na(){return!!(this.parent&&this.parent.layout.isStuck(this)||this.get("locked"))}function Ya(){return!1!==this.get("capturable")&&(this.app.isEditMode||!this.hidden)}function Va(){return this.app?.isViewMode&&this.isPositionable()?this.state.position??"static":"static"}function Ga(){return this.app&&this.app.isViewMode&&this.state.origin||""}function Ha(){const{offsetX:t=0,offsetY:e=0}=this.state;return{x:t,y:e}}function Ua(){return!this._app&&this.parent&&(this._app=this.parent.app),this._app}const Wa={},Xa={mutable:!1,resizable:!0,rotatable:!0,properties:[],"value-property":"text"},qa=[],Ka=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"]),$a={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0};let Qa=0;const Za={};const Ja=new FinalizationRegistry(t=>{!function(t){Qa--;let e=Za[t];e||(e=Za[t]={up:0,down:0}),e.down++}(t)});class tc{static get nature(){return Xa}static register(t,e){if(!e)return Wa[t];Wa[t]=e}static get residents(){return Za}static get residentsCount(){return Qa}static registerDecorator(t,e){Is.registerDecorator(t,e)}constructor(t,e){this._app=e,this._model=t||{},this._state={},this._delta=Kn($a),e&&this.animation?.config&&(1==this.animation.config.autoplay||(this.animation.config.autoplay??1))&&(this.animation.started=!0),this.clearCache(),Es.add(this),function(t){Qa++;let e=Za[t];e||(e=Za[t]={up:0,down:0}),e.up++}(this._model.type),Ja.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=Kn($a))}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&&Es.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!1}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")&&Es.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=Kn(this._model);return this.volatile.forEach(e=>{delete t[e]}),t}get volatile(){return qa}_applyProps(t,e,n){const r={},i={};let s=!1;const o=Kn(e),a=this;if(Object.getOwnPropertyNames(o).forEach(function(e){const c=n.getBeforeVal(e),l=o[e];!n.sensitive&&function(t,e){return Ce(t,e)}(c,l)||(i[e]=c,r[e]=l,t[e]=l,n.clearState&&delete a._state[e],s=!0)}),s){this._cachedState=null;Object.keys(r).some(t=>!Ka.has(t))&&this.clearCache(),r.hasOwnProperty("text")&&delete this._text_substitutor,n.beforeFillStyle&&n.beforeFillStyle(r,i),r.hasOwnProperty("fillStyle")&&this.onchangeFill(r,i),n.afterFillStyle&&n.afterFillStyle(r,i),r.hasOwnProperty("data")&&this.onchangeData(r,i),this.onchange&&this.onchange(r,i),this.trigger("change",r,i)}return this}contains(t,e){return Ls.call(this,t,e)}move(t,...e){js.call(this,t,...e)}symmetryX(t){Rs.call(this,t)}symmetryY(t){Fs.call(this,t)}adjustResize(t,e,n){return Bs.call(this,t,e,n)}adjustRotation(t,e){return Ns.call(this,t,e)}outline(t){return Ys.call(this,t)}get bounds(){return Vs.call(this)}set bounds(t){Gs.call(this,t)}get center(){return Hs.call(this)}set center(t){Us.call(this,t)}get location(){return Ws.call(this)}set location(t){Xs.call(this,t)}get rotate(){return qs.call(this)}set rotate(t){Ks.call(this,t)}get dimension(){return $s.call(this)}set dimension(t){Qs.call(this,t)}get path(){return Zs.call(this)}set path(t){Js.call(this,t)}get drawPath(){return to.call(this)}get rotatePoint(){return eo.call(this)}get mutable(){return no.call(this)}get resizable(){return ro.call(this)}get rotatable(){return io.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&&ao.call(this,t)}prerender(t){co.call(this,t)}render(t){lo.call(this,t)}postrender(t){ho.call(this,t)}prepare(t,e){uo.call(this,t,e)}prepareIf(t){po.call(this,t)}drawText(t){fo.call(this,t)}drawStroke(t,e){go.call(this,t,e)}drawFill(t,e){mo.call(this,t,e)}get strokeStyle(){return yo.call(this)}set strokeStyle(t){bo.call(this,t)}get fillStyle(){return vo.call(this)}set fillStyle(t){xo.call(this,t)}get fontColor(){return _o.call(this)}set fontColor(t){wo.call(this,t)}get rotation(){return Mo.call(this)}set rotation(t){So.call(this,t)}get decorators(){return Ao.call(this)}get decotag(){return ko.call(this)}get hidden(){return Eo.call(this)}set hidden(t){Co.call(this,t)}get tag(){return Po.call(this)}set tag(t){To.call(this,t)}get appendum(){return Oo.call(this)}set appendum(t){Do.call(this,t)}defaultTextSubstitutor(){return Io.call(this)}textLines(t){return zo.call(this,t)}get font(){return Lo.call(this)}get lineHeight(){return jo.call(this)}get textSubstitutor(){return Ro.call(this)}get text(){return Fo.call(this)}set text(t){Bo.call(this,t)}get textBounds(){return No.call(this)}get textRotation(){return Yo.call(this)}get textHidden(){return Vo.call(this)}set textHidden(t){Go.call(this,t)}get hasTextProperty(){return Ho.call(this)}animate(t){return ia.call(this,t)}effect(t,e){return sa.call(this,t,e)}serialize(...t){return oa.call(this,...t)}trim(){aa.call(this)}closeScene(t){ca.call(this,t)}delta(t,e){return la.call(this,t,e)}invalidate(){ha.call(this)}get value(){return da.call(this)}set value(t){ua.call(this,t)}get data(){return pa.call(this)}set data(t){fa.call(this,t)}set tap(t){ga.call(this,t)}get mappings(){return ma.call(this)}get retention(){return ya.call(this)}get animation(){return ba.call(this)}get started(){return va.call(this)}set started(t){xa.call(this,t)}get controls(){return _a.call(this)}findFirst(t,...e){return Ca.call(this,t,...e)}findAll(t,...e){return Pa.call(this,t,...e)}capture(t,e,n){return Ta.call(this,t,e,n)}findAnchor(t){return Oa.call(this,t)}isDescendible(t){return Da.call(this,t)}getContext(t){return Ia.call(this,t)}get root(){return za.call(this)}get rootModel(){return La.call(this)}get parent(){return ja.call(this)}set parent(t){Ra.call(this,t)}get anchors(){return Fa.call(this)}get scalable(){return Ba.call(this)}get stuck(){return Na.call(this)}get capturable(){return Ya.call(this)}get position(){return Va.call(this)}get origin(){return Ga.call(this)}get offset(){return Ha.call(this)}get app(){return Ua.call(this)}drawEffect(t){Ei.call(this,t)}prepareFill(t,e){Ui.call(this,t,e)}prepareFillIf(t){Wi.call(this,t)}onchangeFill(t,e){Xi.call(this,t,e)}drawImage(t,e,n,r,i,s){ki.call(this,t,e,n,r,i,s)}mutateBounds(t,e){xs.call(this,t,e)}mutatePath(t,e,n){_s.call(this,t,e,n)}access(t){return Ts.call(this,t)}substitute(t,e){return Os.call(this,t,e)}onchangeMappings(t,e){Ai.call(this,t,e)}onchangeData(t,e){wi.call(this,t,e)}buildMappings(){Mi.call(this)}executeMappings(t){_i.call(this,t)}disposeMappings(){Si.call(this)}ondropfile(t,e){rs.call(this,t,e)}transcoordS2P(t,e,n){return cs.call(this,t,e,n)}transcoordP2S(t,e,n){return as.call(this,t,e,n)}transcoordS2T(t,e,n){return hs.call(this,t,e,n)}transcoordT2P(t,e,n){return ds.call(this,t,e,n)}transcoordT2S(t,e,n){return us.call(this,t,e,n)}transcoordS2TR(t,e,n){return ls.call(this,t,e,n)}transcoordS2O(t,e,n){return ps.call(this,t,e,n)}transcoordC2S(t,e,n){return fs.call(this,t,e,n)}transcoordS2C(t,e,n){return gs.call(this,t,e,n)}toParent(t,e,n){return cs.call(this,t,e,n)}fromParent(t,e,n){return as.call(this,t,e,n)}toScene(t,e,n){return hs.call(this,t,e,n)}fromScene(t,e,n){return us.call(this,t,e,n)}toLocal(t,e,n){return fs.call(this,t,e,n)}toGlobal(t,e,n){return gs.call(this,t,e,n)}toOther(t,e,n){return ps.call(this,t,e,n)}on(t,e,n){return Br.call(this,t,e,n)}off(t,e,n){return Nr.call(this,t,e,n)}once(t,e,n){return Yr.call(this,t,e,n)}trigger(t,...e){return Vr.call(this,t,...e)}delegate_on(t){return Gr.call(this,t)}delegate_off(t){return Hr.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){}}tc.union=function(t){let e=0,n=0,r=0,i=0,s=!1;return t.forEach(t=>{s?(e=Math.min(t.left,e),n=Math.min(t.top,n),r=Math.max(t.left+t.width,r),i=Math.max(t.top+t.height,i)):(e=t.left,n=t.top,r=t.left+t.width,i=t.top+t.height,s=!0)}),{left:e,top:n,width:r-e,height:i-n}},tc.transcoordR=ss,tc.transcoordRR=os,tc.createCanvas=Gi,tc.memoize=Kr,tc.mixin=Ur,tc.drawText=es,tc.font=Ji,tc.textLines=Zi,tc.drawStroke=qi,tc.drawFill=Hi,tc.reposition=vs,tc.RetentionManager=Es,tc.template=function(t,e,n){var r=vn.imports._.templateSettings||vn;n&&Ve(t,e,n)&&(e=void 0),t=mn(t),e=Xe({},e,r,on);var i,s,o=Xe({},e.imports,r.imports,on),a=se(o),c=function(t,e){return nn(e,function(e){return t[e]})}(o,a),l=0,h=e.interpolate||An,d="__p += '",u=RegExp((e.escape||An).source+"|"+h.source+"|"+(h===ln?Sn:An).source+"|"+(e.evaluate||An).source+"|$","g"),p=En.call(e,"sourceURL")?"//# sourceURL="+(e.sourceURL+"").replace(/\s/g," ")+"\n":"";t.replace(u,function(e,n,r,o,a,c){return r||(r=o),d+=t.slice(l,c).replace(kn,cn),n&&(i=!0,d+="' +\n__e("+n+") +\n'"),a&&(s=!0,d+="';\n"+a+";\n__p += '"),r&&(d+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),l=c+e.length,e}),d+="';\n";var f=En.call(e,"variable")&&e.variable;if(f){if(Mn.test(f))throw new Error("Invalid `variable` option passed into `_.template`")}else d="with (obj) {\n"+d+"\n}\n";d=(s?d.replace(xn,""):d).replace(_n,"$1").replace(wn,"$1;"),d="function("+(f||"obj")+") {\n"+(f?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(i?", __e = _.escape":"")+(s?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+d+"return __p\n}";var g=en(function(){return Function(a,p+"return "+d).apply(void 0,c)});if(g.source=d,tn(g))throw g;return g},tc.buildSubstitutor=Ds,["rotatePoint","font","lineHeight","retention"].forEach(t=>tc.memoize(tc.prototype,t,!1)),["bounds","center","textBounds"].forEach(t=>tc.memoize(tc.prototype,t,!0));class ec extends tc{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 r=0;r<e.length;r++){const i=e[(r-1+e.length)%e.length],s=e[(r+e.length)%e.length],o=e[(r+1)%e.length];if(i.x===s.x&&i.y===s.y)continue;let a=Math.sqrt((i.x-s.x)*(i.x-s.x)+(i.y-s.y)*(i.y-s.y)),c=0!==a?Math.atan2(i.x-s.x,i.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==r?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 nc(t,e,n){return Math.max(0,Math.min(t,Math.min(n,e)/2))}function rc(t){const e=class extends t{contains(t,e){const{left:n,top:r,width:i,height:s,lineWidth:o=0}=this.state,a=o/2;return t<Math.max(n+i,n)+a&&t>Math.min(n+i,n)-a&&e<Math.max(r+s,r)+a&&e>Math.min(r+s,r)-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:r=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+r},{x:t,y:e+r}]}get anchors(){return function(t){const{left:e,top:n,width:r,height:i}=t.bounds,s=e+r/2,o=n+i/2;return[{name:"TOP",position:{x:s,y:n}},{name:"RIGHT",position:{x:e+r,y:o}},{name:"BOTTOM",position:{x:s,y:n+i}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get bounds(){const{left:t=0,top:e=0,width:n=0,height:r=0}=this.state;return{left:t,top:e,width:n,height:r}}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:r,width:i,height:s}=this.bounds;t.translate(n,r),t.beginPath(),e=nc(e,i,s),e>0?t.roundRect(0,0,i,s,e):t.rect(0,0,i,s),t.translate(-n,-r)}};return Kr(e.prototype,"path",!1),Kr(e.prototype,"bounds",!0),e}const ic={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 sc=20;function oc(t,e){const n=t.split(/\s+/),r=n.indexOf(e);return-1!=r?n.splice(r,1):n.splice(-1,0,e),n.join(" ")}class ac extends(rc(ec)){static get image(){return ac._image||(ac._image=new Image,ac._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=="),ac._image}static toggle(t,e,n,r){if(!e)return void Xr("InfoWindow not defined.");const i=t.root.findById(e);i?i._findInfoWindowByComponent(t)?ac.hide(t,e):ac.show(t,e,n,r):Xr("InfoWindow Not Found.",e)}static hide(t,e){if(!e)return;const n=t.root.findById(e);n?n._removeInfoWindow(t):Xr("InfoWindow Not Found.",e)}static show(e,n,r,i){if(!n)return void Xr("InfoWindow not defined.");const s=e.root.findById(n);if(!s)return void Xr("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=>tc.template(function(t,e,n){return(e||n?['<div class="info-window-btns">',e?'<button class="closable">X</button>':"",n?'<button class="flipable">⇌</button>':"","</div>"]:[]).concat(['<div class="info-window-content">',t,"</div>"]).join("")}(t,!r,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}=i?e.rootModel.toLocal(i.x,i.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(Fi.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),Bi.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=oc(y.className,"flip-side-1"),m.className=oc(m.className,"flip-side-2")},{signal:v});const r=m.querySelector(".info-window-btns > .closable");r&&r.addEventListener("click",function(t){t.preventDefault(),ac.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=oc(y.className,"flip-side-1"),m.className=oc(m.className,"flip-side-2")},{signal:v});const r=y.querySelector(".info-window-btns > .closable");r&&r.addEventListener("click",function(t){t.preventDefault(),ac.hide(e,n)},{signal:v})}const x=m.offsetWidth,_=m.offsetHeight,w=e.rootModel.target.getBoundingClientRect(),M=[];m&&M.push(m),y&&M.push(y);const S={x:h,y:d};let A=e.toGlobal(S.x,S.y);if(A.x+x/2+w.left<w.right&&A.x-x/2>w.left){if(_+sc<A.y)return f.style.marginLeft=S.x-x/2+"px",f.style.marginTop=S.y-_-sc+"px",void M.forEach(t=>t.className+=" arrow-bottom");if(A=e.toGlobal(S.x,S.y+_+sc),w.bottom>A.y+w.top)return f.style.marginLeft=S.x-x/2+"px",f.style.marginTop=S.y+sc+"px",void M.forEach(t=>t.className+=" arrow-top")}if(A=e.toGlobal(S.x,S.y),A.x-(x+sc)>w.left)return f.style.marginLeft=S.x-x-sc+"px",f.style.marginTop=S.y-_/2+"px",void M.forEach(t=>t.className+=" arrow-right");f.style.marginLeft=S.x+sc+"px",f.style.marginTop=S.y-_/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 r=new AbortController;return this._windows.push({component:t,window:e,styleElement:n,abortController:r}),r}_removeInfoWindow(t){const e=this._findInfoWindowByComponent(t);if(!e)return;e.abortController.abort();const n=e.window;n&&n.parentNode.removeChild(n);const r=this.infoWindows.lastIndexOf(e);this.infoWindows.splice(r,1)}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),this.drawImage(t,ac.image,e,n,r,i)}get hasTextProperty(){return!1}get nature(){return ic}}tc.register("info-window",ac);const cc={};var lc={list:function(){return{...cc}},register:function(t,e){cc[t]=e},unregister:function(t){delete cc[t]},get:function(t){if(!t)return;const e=cc[t];return e||Wr("Layout Not Found - ",t),e}};const hc=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}};lc.register("html-absolute",hc);const dc=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 uc(t){const e=t.components.filter(t=>!t.hidden),n=t.getState("layoutConfig")||{},r=e[n&&n.activeIndex||0];return r&&[r]||[]}lc.register("absolute",dc);const pc=new class{reflow(t){const e=t.bounds,n=t.getState("layoutConfig")||{},r={left:0,top:0,width:e.width,height:e.height};t.forEach((t,e)=>{const i=e!=(n.activeIndex||0);t.bounds=r,t.setState("rotation",0),"element"in t&&t.element&&(t.element.style.visibility=i?"hidden":"visible")})}capturables(t){return uc(t)}drawables(t){return uc(t)}isStuck(t){return!0}};function fc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}lc.register("card",pc);const gc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},r=e.reduce((t,e)=>t+fc(e),0),i=t.bounds,s=r>0?(i.width-((n.left||0)+(n.right||0)))/r:i.width,o=i.height-((n.top||0)+(n.bottom||0));let a=0;e.forEach(t=>{const e=fc(t),r=t.getState("margin")||{};t.bounds={left:s*a+(n.left||0)+(r.left||0),top:0+(n.top||0)+(r.top||0),width:e*s-((r.left||0)+(r.right||0)),height:o-((r.top||0)+(r.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 mc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}lc.register("linear-horizontal",gc);const yc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},r=e.reduce((t,e)=>t+mc(e),0),i=t.bounds,s=r>0?(i.height-((n.top||0)+(n.bottom||0)))/r:i.height,o=i.width-((n.left||0)+(n.right||0));let a=0;e.forEach(t=>{const e=mc(t),r=t.getState("margin")||{};t.bounds={left:0+(n.left||0)+(r.left||0),top:s*a+(n.top||0)+(r.top||0),width:o-((r.left||0)+(r.right||0)),height:e*s-((r.top||0)+(r.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}};lc.register("linear-vertical",yc);const bc=new class{constructor(){this.joinType=!0}reflow(t){const e=t.getState("layoutConfig"),n=e&&e.columns||t.getState("columns"),r=e&&e.rows||t.getState("rows"),i=e&&e.widths||t.getState("widths"),s=e&&e.heights||t.getState("heights"),o=i?i.filter((t,e)=>e<n).reduce((t,e)=>t+e,0):n,a=s?s.filter((t,e)=>e<r).reduce((t,e)=>t+e,0):r,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 r=i?i[e%n]:1,o=s?s[Math.floor(e/n)]:1;let a=t.colspan||1,c=0;for(;--a>0;)c+=i?i[(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*(r+c),height:u*(o+m)},t.setState("rotation",0),e%n==n-1?(p=0,f+=o*u):p+=r*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 r=t.getState("layoutConfig"),i=r&&r.columns||t.getState("columns"),s=r&&r.rows||t.getState("rows"),{row:o,column:a}=t.getRowColumn(e);switch(n.code){case"ArrowUp":if(o>0)return t.getAt?.((o-1)*i+a);break;case"ArrowDown":if(o<s-1)return t.getAt?.((o+1)*i+a);break;case"ArrowRight":if(a<i-1)return t.getAt?.(o*i+a+1);break;case"ArrowLeft":if(a>0)return t.getAt?.(o*i+a-1);break;default:return e}}};lc.register("table",bc);const vc=20;function xc(t,e="static",n,r,i,s,o={}){const{title:a="",gap:c=vc}=o;if("auto"===n){const{x:e,y:n}=function(t,e,n,r="",i=vc){const s=Math.max(e.width/4-n.width/2,i),o=Math.min(3*e.width/4+n.width/2,e.width-i)-n.width,a=Math.max(e.height/4-n.height/2,i),c=Math.min(3*e.height/4+n.height/2,e.height-i)-n.height+(r?-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+(r?30:0)):Math.max(a,t.y-(n.height+20))}}(r,i,s,a,c);Object.assign(t.style,{position:"absolute",left:`${e}px`,top:`${n}px`})}else"static"===e?function(t,e,n,r,i){const s=t.style,o=e.includes("left")?i:e.includes("right")?n.width-r.width-i:n.width/2-r.width/2,a=e.includes("top")?i:e.includes("bottom")?n.height-r.height-i:n.height/2-r.height/2;Object.assign(s,{left:`${o}px`,top:`${a}px`})}(t,n,i,s,c):function(t,e,n=vc){const r=t.style;switch(Object.assign(r,{position:"absolute",left:"",right:"",top:"",bottom:"",transform:""}),e){case"center-middle":default:Object.assign(r,{left:"50%",top:"50%",transform:"translate(-50%, -50%)"});break;case"center-top":Object.assign(r,{left:"50%",top:`${n}px`,transform:"translateX(-50%)"});break;case"center-bottom":Object.assign(r,{left:"50%",bottom:`${n}px`,transform:"translateX(-50%)"});break;case"left-middle":Object.assign(r,{left:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"right-middle":Object.assign(r,{right:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"left-top":Object.assign(r,{left:`${n}px`,top:`${n}px`});break;case"right-top":Object.assign(r,{right:`${n}px`,top:`${n}px`});break;case"left-bottom":Object.assign(r,{left:`${n}px`,bottom:`${n}px`});break;case"right-bottom":Object.assign(r,{right:`${n}px`,bottom:`${n}px`})}}(t,n,c)}function _c(t,e,n={sx:1,sy:1}){let r,i,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,r=t,i=e}function d(e,c){if(!a)return;const l=e-r,h=c-i,{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 wc=["run","goto","goto-playlist","link-open","link-move","route-page","start-scenario","run-scenario","export-data","import-data"];function Mc(t,e){const n=document.createElement("button");return n.className=t,n.textContent=e,n}const Sc=new WeakMap;function Ac(t){const e=t.root,n=Sc.get(e);if(!n)return;if(e===t)return n.forEach(t=>Ac(t[0])),void Sc.delete(e);const r=n.findIndex(e=>e[0]===t);if(-1===r)return;const i=n[r][1];cancelAnimationFrame(i.rafId),i.ac.abort(),i.div.parentNode?.removeChild(i.div),i.scene.target=null,i.scene.release?.(),n.splice(r,1)}class kc{static hideAll(t){(Sc.get(t)||[]).forEach(([t])=>Ac(t))}static hide(t){const e=t.root,n=Sc.get(e);if(!n)return;const r=n.findIndex(e=>e[0]===t);if(-1===r)return;const i=n[r][1];i.div.style.backgroundColor="transparent",i.rafId=function(t,e,n){t.style.opacity="1";const r=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();t.style.transform=`${r} scale(1)`;let i=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=`${r} scale(${1-a})`.trim(),a<1?i=requestAnimationFrame(o):(t.style.display="none",e&&e())};return i=requestAnimationFrame(o),i}(i.div,()=>{Ac(t)},i.ac.signal)}static show(t,e,n={}){const{data:r,modal:i=!1,closable:s=!0,minimizable:o=!1,draggable:a=!1,output:c=!0,popupPosition:l="static",origin:h="center-middle",title:d=""}=n,u=t.app?.refProvider,p=!l||"static"===l;u?.get(e,!0).then(e=>{const n=document.createElement("div");n.setAttribute("popup",""),"absolute"==l&&(n.style.zIndex="100");const u=n.style;if(i){const{width:e,height:n}=p?t.rootModel.bounds:t.rootModel.auxOverlay.getBoundingClientRect();Object.assign(u,{position:"absolute",zIndex:"100",left:0,top:0,width:p?`${e}px`:"100%",height:p?`${n}px`:"100%",overflow:"hidden",backgroundColor:"transparent"})}else Object.assign(u,{position:"absolute",display:"inline-block"});n.appendChild(function(t){const e=document.createDocumentFragment(),n=document.createElement("div");n.className="popup-wrap";const r=document.createElement("div");if(r.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(Mc("closable","close")),n.appendChild(Mc("minimizable","minimize")),n.appendChild(Mc("draggable","drag_pan")),t.appendChild(n),r.appendChild(t)}else{const t=document.createElement("div");t.className="popup-buttons-wrap float-right",t.appendChild(Mc("closable","close")),t.appendChild(Mc("minimizable","minimize")),t.appendChild(Mc("draggable","drag_pan")),r.appendChild(t)}const i=document.createElement("div");return i.className="popup-content",r.appendChild(i),n.appendChild(r),e.appendChild(n),e}(!!d));const f=n.querySelector(".popup-content"),{width:g,height:m}=e.root.model;Object.assign(f.style,{width:`${g}px`,height:`${m}px`});const y=document.createElement("style");y.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(y),wc.forEach(n=>{e.on(n,(...e)=>{t.trigger(n,...e)})});const b=new AbortController,v=b.signal,x=n.querySelector(".draggable");[...Fi,...Bi].forEach(t=>{f.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),[...Fi,...Bi].forEach(t=>{n.addEventListener(t,t=>t.stopPropagation(),{signal:v})}),i&&s&&n.addEventListener("click",e=>{e.target===n&&kc.hide(t)},{signal:v});const _=t.rootModel.getOverlay?.({...t,scalable:!l||"static"==l});_?.appendChild(n),function(t,e,n,r,i){const s=t.root;if(s===t)return;Ac(t);let o=Sc.get(s)||[];o=[...o,[t,{div:e,scene:n,ac:r,rafId:i}]],Sc.set(s,o)}(t,n,e,b,0);const w=Sc.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 M=n.querySelector(".popup-translate");if(a&&(_c(M,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"):(M?.addEventListener("mouseenter",()=>{x&&(x.style.display="block")},{signal:v}),M?.addEventListener("mouseleave",()=>{x&&(x.style.display="none")},{signal:v}))),o){const t=n.querySelector(".minimizable");let e=!1;t.addEventListener("click",t=>{t.preventDefault(),e=!e;const r=n.querySelector(".popup-wrap");!function(t,e,n){const r=e.querySelector(".minimizable"),i=e.querySelector(".popup-translate");i&&(n?(r.textContent="crop_square",i.style.height="30px"):(r.textContent="minimize",i.style.height="100%"))}(0,i?r:n,e)},{signal:v}),d?t&&(t.style.display="block"):(M?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:v}),M?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:v}))}if(s){const t=n.querySelector(".closable");d?t&&(t.style.display="block"):(M?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:v}),M?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:v}))}n.querySelector(".closable")?.addEventListener("click",e=>{e.preventDefault(),kc.hide(t)},{signal:v}),n.addEventListener("close-scene",e=>{e.preventDefault(),e.stopPropagation(),kc.hide(t),c&&(t.data=e.detail)},{signal:v}),e.target=f,e.data=r||t.data,e.fit("both");const{x:S,y:A}=t.center,k=t.toScene(S,A),E=i?n.querySelector(".popup-wrap"):n;xc(E,l,h,k,e.root.bounds,{width:g,height:m},{title:d}),i?Object.assign(E.style,{position:"absolute",pointerEvents:"none",width:`${g}px`,height:`${d?m+30:m}px`}):Object.assign(E.style,{pointerEvents:"none",width:`${g}px`,height:`${d?m+30:m}px`});const C=function(t,e,n){t.style.opacity="0";const r=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();t.style.transform=`${r} scale(0)`,t.style.display="block";let i=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=`${r} scale(${a})`.trim(),a<1?i=requestAnimationFrame(o):e&&e()};return i=requestAnimationFrame(o),i}(n,()=>{i&&(n.style.backgroundColor="rgba(0,0,0,0.3)")},v);w&&(w.rafId=C)},t=>{Wr("cannot fetch board: "+e,t)})}}const Ec=new Image;function Cc(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:r}=this.bounds;t.save(),t.beginPath(),t.globalAlpha=1,t.rect(e+r,n,25,25);t.fillStyle="rgba(235, 235, 235, 1)",t.fill(),t.drawImage(Ec,e+r+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:r,top:i,width:s}=this.bounds,o=r+s,a=25;this.showMoveHandle&&(n=t<Math.max(o+25,o)&&t>Math.min(o+25,o)&&e<Math.max(i+a,i)&&e>Math.min(i+a,i))}return this._focused!==n&&(this._focused=n,this.invalidate()),n}}}Ec.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAclBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0BbqFAAAAJXRSTlMAgAP3VSI6/g9fBk5FavJsMrariSjzPnO1enRRL5SMhmOOWB9keFTE0wAAANxJREFUOMutk9kWgyAMRLFuiLjUtdp9yf//YglVsQXz1HniMPcEMgHGvpX2O0Ypi+EgCL+IAShC+wB7QfubRDT7AFcnUPoLMLiP4PyJbsb55i05AgnR5iaQDsICgtH0cotBWoAP1c7kC6kFxEseCfZfB6gEgbNeBrira2QmH1uVYCXlA3is8UmgUCPIyQJKEmu8QtQJN0e9DPXVpzG2G216c1CqRmcBOdxXk07sWUSPv07zo0amCNQycv+NzmR6cRcwmfbuI7p2nZ/z4be0P83Foz6vIkhfZXr82XgDlZsspIq4peUAAAAASUVORK5CYII=";const Pc=[];class Tc extends(Cc(rc(tc))){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 lc.get(this.get("layout"))||dc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components&&(t.components=this.components.map(t=>t.hierarchy)),t}addComponent(t,e=!1){const n=t.parent;if(n){if(this===n)return;n.removeComponent(t,e)}const r=this._components.push(t)-1;t.parent=this,t.added(this),e||this.trigger("add",this,t,r),t.delegate_on(this),e||t.trigger("added",this,t,r),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 r=t.parent;r&&r.removeComponent(t,n);const i=this._components.splice(0,e);this._components=i.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||Pc).indexOf(t)}size(){return(this._components||Pc).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let r=this._components.splice(0,n);const i=this._components.splice(1);this._components=r.concat(i),t=Math.max(0,t),t=Math.min(t,this._components.length),r=this._components.splice(0,t),this._components=r.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),r=this._components.splice(1);this._components=n.concat(r,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),r=this._components.splice(1);this._components=this._components.concat(n,r)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return Ea(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let r=this.components.length-1;r>=0;r--){const i=this.components[r].findAll(t,...e);i&&(n=n.concat(i))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return Ea(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const r=this.components[n].findFirst(t,...e);if(null!=r)return r}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:r,top:i,width:s,height:o}=this.state;n=t<Math.max(r+s,r)&&t>Math.min(r+s,r)&&e<Math.max(i+o,i)&&e>Math.min(i+o,i)}return n}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const r=this.fromParent(t,e);if(!this.contains(r.x,r.y))return!1;const i=this.bounds;r.x-=i.left,r.y-=i.top;const s=this.layout.capturables(this);for(let i=s.length-1;i>=0;i--){const o=s[i];let a;if(a="static"==o.position?o.capture(r.x,r.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:r,top:i,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<r||a.x>r+s||a.y<i||a.y>i+o)return!1;a.x-=r,a.y-=i,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const r=a[t];if(!r.isContainer())continue;const i=r.capturePath(n,e);if(i)return i}return this.focusible&&this}render(t){const{left:e=0,top:n=0,width:r,height:i}=this.bounds;t.beginPath(),t.rect(e,n,r,i),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:r=0,width:i,height:s}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,r,i,s),t.clip(),t.closePath()),({top:r,left:n}=this.state),t.translate(n,r),e.forEach(e=>{e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-r),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>tc.memoize(Tc.prototype,t,!1));class Oc extends Tc{constructor(t,e){super(t,e),this._element=null,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;Or.drawCount++,Or.drawTimeSum+=e,Or.drawTimeLast=e,Or.countFrame()},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,r){if(this.target){if(e){const t=getComputedStyle(this.target);n=n||(t?parseFloat(t.getPropertyValue("width")):this.target.clientWidth),r=r||(t?parseFloat(t.getPropertyValue("height")):this.target.clientHeight)}else n=this.model.width,r=this.model.height;"CANVAS"==t.tagName&&(t.setAttribute("width",n*Ri),t.setAttribute("height",r*Ri)),t.style.width=n+"px",t.style.height=r+"px"}}resize(){this.fitSize(this.element,!0)}isLayer(){return!0}get showOverflow(){return this.app.isEditMode}get anchors(){}createElement(){const t=tc.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:r}=this.model;t.clearRect(0,0,t.canvas.width,t.canvas.height),e&&t.translate(e.x*Ri,e.y*Ri),t.scale(n.x*Ri,n.y*Ri),r&&t.rotate(r)}get rotatePoint(){return{x:0,y:0}}contains(t,e){return!1}invalidate(){Or.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:r,y:i}=t.center,{x:s,y:o}=t.fromParent(r,i),{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?Jo({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 Dc extends Oc{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=tc.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=tc.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){/*!this.app.isViewMode || */
|
|
3
|
-
return!t||t.scalable?this.context2D:this.auxContext2D}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(Ri,Ri),super.draw(t),this.auxContext2D.restore())}}var Ic,zc,Lc,jc;!function(t){t.CANVAS="canvas",t.DOM="dom"}(Ic||(Ic={}));class Rc{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;zs.getInstance().addOverlay(t)}}determineOptimalMode(){return!1!==this.options.animation?Ic.DOM:Ic.CANVAS}start(){if(!this.isActive&&(this.isActive=!0,this.mode===Ic.DOM)){this.overlay?(this.createDOMElements(),this.target.on("change",this.handleTargetChange,this),this.target.on("removed",this.handleTargetRemoved,this)):(Xr("오버레이가 설정되지 않아 DOM 모드 데코레이터를 시작할 수 없습니다."),this.isActive=!1)}}stop(){this.isActive&&(this.isActive=!1,this.mode===Ic.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===Ic.DOM&&this.isActive&&this.updateDOMElements()}render(t,e){return!(this.mode!==Ic.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:r}=this.target.bounds;if("function"==typeof this.target.toGlobal)try{const{x:i,y:s}=this.target.toGlobal(t,e,this.target.rootModel);return{x:i,y:s,width:n,height:r}}catch(t){Xr("좌표 변환 실패, 기본값 사용:",t)}return{x:t,y:e,width:n,height:r}}handleTargetChange(t,e){this.target.disposed?this.stop():this.invalidate()}handleTargetRemoved(){this.stop()}invalidate(){}}function Fc(t,n,r){const i=t.rootModel;if(i?.is3dMode){const n=t._realObject?.object3d,r=i.activeCamera3d,s=i.renderer3d;if(n&&r&&s){const t=new e.Vector3;n.getWorldPosition(t);const i=t.clone().project(r),o=s.domElement;return{x:(.5*i.x+.5)*o.clientWidth,y:(.5*-i.y+.5)*o.clientHeight}}return null}const s=t.toGlobal(n,r,i);return isNaN(s.x)||isNaN(s.y)?null:s}class Bc extends Rc{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:Ic.DOM,...n}),this.vectorElement=null,this.animationElements=[],this.svgContainer=null,this.animationElement=null}getDecoratorType(){return this.constructor.DECORATOR_TYPE}dispose(){this.removeDOMElements()}determineOptimalMode(){return Ic.DOM}renderCanvas(t,e){return Xr("VectorDecorator는 Canvas 렌더링을 지원하지 않습니다. DOM 모드를 사용하세요."),!1}getSvgContainer(){if(!this.overlay)throw new Error("오버레이 요소가 없습니다.");if(!Bc.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),Bc.svgContainerCache.set(this.overlay,t)}return Bc.svgContainerCache.get(this.overlay)}getOrCreateDecoratorGroup(t=!1){const e=this.getSvgContainer(),n=this.getVectorGroupId(),r=this.getDecoratorType();let i=e.querySelector(`g[data-decorator-type-container="${r}"]`);if(!i){i=document.createElementNS("http://www.w3.org/2000/svg","g"),i.setAttribute("data-decorator-type-container",r),i.setAttribute("class",`${r}-container`),e.appendChild(i);const t=document.createElementNS("http://www.w3.org/2000/svg","defs");t.setAttribute("data-defs-for",r),i.appendChild(t)}let s=i.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",r),t&&s.setAttribute("data-component-id",t),i.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 r=n.querySelector(`defs[data-defs-for="${e}"]`);return r||(r=document.createElementNS("http://www.w3.org/2000/svg","defs"),r.setAttribute("data-defs-for",e),n.appendChild(r)),r}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,r={}){const i=document.createElementNS("http://www.w3.org/2000/svg","animate");return i.setAttribute("attributeName","opacity"),i.setAttribute("from",t.toString()),i.setAttribute("to",e.toString()),i.setAttribute("dur",`${n}ms`),r.delay&&i.setAttribute("begin",`${r.delay}ms`),i.setAttribute("fill","freeze"),r.repeat?i.setAttribute("repeatCount","indefinite"):i.setAttribute("repeatCount","1"),i}createTranslateAnimation(t,e=[],n=1e3,r={}){const i=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return i.setAttribute("attributeName","transform"),i.setAttribute("type","translate"),i.setAttribute("values",t.join(";")),e.length>0&&i.setAttribute("keyTimes",e.join(";")),i.setAttribute("dur",`${n}ms`),r.delay&&i.setAttribute("begin",`${r.delay}ms`),r.repeat?i.setAttribute("repeatCount","indefinite"):i.setAttribute("repeatCount","1"),i}createRotateAnimation(t=0,e=360,n=0,r=0,i=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} ${r}`),o.setAttribute("to",`${e} ${n} ${r}`),o.setAttribute("dur",`${i}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 Fc(t,e,n)}updatePosition(){if(!this.vectorElement)return;const t=this.options,{left:e,top:n}=this.target.bounds,r=this.projectComponentPoint(this.target,e,n);if(!r)return;const i=r.x+(t.x??0),s=r.y+(t.y??0);this.vectorElement.setAttribute("transform",`translate(${i}, ${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=Bc.svgContainerCache.get(this.overlay);if(!t)return;const e=this.getVectorGroupId(),n=this.getDecoratorType(),r=t.querySelector(`g[data-decorator-type-container="${n}"]`);if(r){const t=r.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()),!r.querySelector("g[data-decorator-group-id]")){const t=r.querySelector(`defs[data-defs-for="${n}"]`);t&&t.remove(),r.remove()}}0===t.children.length&&(t.remove(),Bc.svgContainerCache.delete(this.overlay))}catch(t){Wr("벡터 요소 제거 실패:",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===Ic.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,r=e.height/2,i=(180*t/Math.PI).toFixed(1);this.vectorElement.setAttribute("transform",`rotate(${i} ${n} ${r})`)}}applyTranslateValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("translate")){const r=n.replace(/translate\([^)]+\)/,`translate(${t}, ${e})`);this.vectorElement.setAttribute("transform",r)}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 r=n.replace(/scale\([^)]+\)/,`scale(${t}, ${e})`);this.vectorElement.setAttribute("transform",r)}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}}}Bc.svgContainerCache=new WeakMap,Bc.DECORATOR_TYPE="vector";class Nc extends Rc{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 Ic.CANVAS}createDOMElements(){Xr("RasterDecorator는 DOM 렌더링을 지원하지 않습니다. Canvas 모드를 사용하세요.")}setAnimationState(t=3e3,e=!1){Nc.animationStateMap.set(this.target,{startTime:Date.now(),duration:t,repeat:e})}getAnimationState(){const t=Nc.animationStateMap.get(this.target);if(!t)return{delta:0,finished:!0};const{startTime:e,duration:n,repeat:r}=t,i=Date.now()-e;let s=Math.min(1,i/n),o=s>=1;return r&&o&&(Nc.animationStateMap.set(this.target,{startTime:Date.now(),duration:n,repeat:r}),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(),Nc.animationStateMap.delete(this.target)}applyTransform(t,e,n){const r=this.options,i=r.scale||1,s=r.rotation||0;if(1!==i||0!==s){if(t.translate(e,n),0!==s){const e=s*Math.PI/180;t.rotate(e)}1!==i&&t.scale(i,i),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}}Nc.animationStateMap=new WeakMap;class Yc extends Bc{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:r=3e3,repeat:i=!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(r,i);if(a.push(t),this.options.fadeOut){const t=this.createFadeAnimation(1,0,r,{repeat:i});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(r,i);if(t.push(e),this.options.fadeOut){const e=this.createFadeAnimation(1,0,r,{repeat:i});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){Wr("화살표 SVG 요소 생성 실패:",t)}}createArrowPath(t,e,n=1){const r=n/this.getScale();return`\n M${t-10*r},${e-16*r} \n L${t+10*r},${e-16*r} \n L${t+10*r},${e-8*r} \n L${t+16*r},${e-8*r} \n L${t},${e} \n L${t-16*r},${e-8*r} \n L${t-10*r},${e-8*r} \n Z\n `}getScale(){try{if(this.target.rootModel&&"number"==typeof this.target.rootModel.scale)return this.target.rootModel.scale||1}catch(t){Xr("스케일 계산 실패, 기본값 사용",t)}return 1}createBounceAnimation(t,e){const n=["0,-10"],r=["0"];for(let t=1;t<=20;t++){const e=t/20;let i=Math.pow(e,.5).toFixed(3);parseFloat(r[r.length-1])>=parseFloat(i)&&(i=(parseFloat(r[r.length-1])+.01).toFixed(3)),n.push("0,0"),n.push("0,-10"),r.push(i),r.push((parseFloat(i)+.01).toFixed(3))}return r[r.length-1]="1.000",this.createTranslateAnimation(n,r,t,{repeat:e})}createArrowLabel(t,e,n,r,i=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*i}`),o.setAttribute("y",""+(e-20*i)),o.setAttribute("width",""+40*i),o.setAttribute("height",""+20*i),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*i}`),a.setAttribute("y",""+(e-6*i)),a.setAttribute("fill","white"),a.setAttribute("font-size",12*i+"px"),a.setAttribute("text-anchor","middle"),a.textContent=r,s.appendChild(o),s.appendChild(a),s}startAnimations(){setTimeout(()=>{this.animationElements.forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&t.beginElement()}catch(t){Wr("애니메이션 시작 오류:",t)}})},10)}invalidate(){this.updatePosition()}updatePosition(){if(!this.vectorElement)return;const{left:t,top:e,width:n}=this.target.bounds,r=this.projectComponentPoint(this.target,t+n/2,e);if(!r)return;const i=Math.max(r.x,20),s=Math.max(r.y,20);this.vectorElement.setAttribute("transform",`translate(${i}, ${s})`)}}Yc.DECORATOR_TYPE="bouncing-arrow",function(t){t.ROTATE="rotate",t.TRANSLATE_X="translateX",t.TRANSLATE_Y="translateY",t.SCALE="scale",t.FADE="fade"}(zc||(zc={})),function(t){t.VIBRATION="vibration",t.ROTATION="rotation",t.HEARTBEAT="heartbeat",t.MOVING="moving",t.OUTLINE="outline",t.FADE="fade",t.WAYPOINT="waypoint"}(Lc||(Lc={})),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"}(jc||(jc={}));class Vc extends Bc{constructor(t,e,n={}){const{animations:r,...i}=n;super(t,e,{icon:"arrow_forward",size:24,color:"#FF0000",deltaX:0,deltaY:0,...i}),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(r)}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:r,sx:i,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, ${r}px) scale(${i}, ${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:r}=this.target,{left:i,top:s,width:o,height:a}=r,c=n/2;let l;switch(e||t||jc.CENTER){case jc.TOP_LEFT:case"top-left":l={x:i,y:s-n};break;case jc.TOP:case"top":l={x:i+(o-n)/2,y:s-n};break;case jc.TOP_RIGHT:case"top-right":l={x:i+o-n,y:s-n};break;case jc.BOTTOM_LEFT:case"bottom-left":l={x:i,y:s+a};break;case jc.BOTTOM:case"bottom":l={x:i+(o-n)/2,y:s+a};break;case jc.BOTTOM_RIGHT:case"bottom-right":l={x:i+o-n,y:s+a};break;case jc.LEFT_TOP:case"left-top":l={x:i-n,y:s};break;case jc.LEFT:case"left":l={x:i-n,y:s+(a-n)/2};break;case jc.LEFT_BOTTOM:case"left-bottom":l={x:i-n,y:s+(a-n)};break;case jc.RIGHT_TOP:case"right-top":l={x:i+o,y:s};break;case jc.RIGHT:case"right":l={x:i+o,y:s+(a-n)/2};break;case jc.RIGHT_BOTTOM:case"right-bottom":l={x:i+o,y:s+(a-n)};break;case jc.TOP_LEFT_CORNER:case"top-left-corner":l={x:i-c,y:s-c};break;case jc.TOP_RIGHT_CORNER:case"top-right-corner":l={x:i+o-c,y:s-c};break;case jc.BOTTOM_LEFT_CORNER:case"bottom-left-corner":l={x:i-c,y:s+a-c};break;case jc.BOTTOM_RIGHT_CORNER:case"bottom-right-corner":l={x:i+o-c,y:s+a-c};break;case jc.CENTER:default:l={x:i+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:r,y:i}=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:r+"px",top:i+"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(){super.start(),this.isActive&&(this.overlay&&this._getElement().parentNode!==this.overlay&&this.overlay.appendChild(this._getElement()),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:r}=this._delta;return this.projectComponentPoint(this.target,t+n,e+r)??this.target.toGlobal(t+n,e+r)}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)}),na(this,t)));if(t){const e={...t};return"theta"in e&&(e.theta=e.theta*(Math.PI/180)),[na(this,e)]}return[]}}Vc.DECORATOR_TYPE="animated-icon";class Gc extends Bc{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:r="#FF0000",animation:i=!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),i){const t=this.createGradient(this.elementId,r);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)`),i?a.setAttribute("stroke",`url(#${this.elementId})`):a.setAttribute("stroke",r),t.appendChild(a),this.pathElement=a,this.vectorElement=t,this.updatePathData(),this.options.animation&&this.startAnimations()}catch(t){Wr("테두리 하이라이팅 요소 생성 실패:",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||{},r=this.pointsToPathData(e,n);this.pathElement.setAttribute("d",r)}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){Wr("애니메이션 시작 오류:",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:r}=this.target.bounds;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+r},{x:t,y:e+r}]}return this.target.path.map(t=>this.target.toGlobal(t.x,t.y))}createOffsetPath(t,e){const n=[],r=t.length;for(let i=0;i<r;i++){const s=t[(i-1+r)%r],o=t[i],a=t[(i+1)%r],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 r=t.length,i=(t,e,n)=>{const r=e.x-t.x,i=e.y-t.y,s=Math.sqrt(r*r+i*i);return{x:t.x+r/s*n,y:t.y+i/s*n}};for(let s=0;s<r;s++){const o=t[s],a=t[(s+1)%r],c=t[(s-1+r)%r],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=i(o,c,d),p=i(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 r=document.createElementNS("http://www.w3.org/2000/svg","feFlood");r.setAttribute("flood-color",e),r.setAttribute("result","flood");const i=document.createElementNS("http://www.w3.org/2000/svg","feComposite");i.setAttribute("in","flood"),i.setAttribute("in2","SourceAlpha"),i.setAttribute("operator","in"),i.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(r),n.appendChild(i),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 r=this.alterColor(e,120),i=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};${r};${i};${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",i);const c=document.createElementNS("http://www.w3.org/2000/svg","animate");return c.setAttribute("attributeName","stop-color"),c.setAttribute("values",`${i};${e};${r};${i}`),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),r=parseInt(n.substring(1,3),16),i=parseInt(n.substring(3,5),16),s=parseInt(n.substring(5,7),16),o=this.rgbToHsl(r,i,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 r=Math.max(t,e,n),i=Math.min(t,e,n);let s=0,o=0;const a=(r+i)/2;if(r!==i){const c=r-i;switch(o=a>.5?c/(2-r-i):c/(r+i),r){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 r,i,s;if(0===e)r=i=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;r=o(c,a,t+1/3),i=o(c,a,t),s=o(c,a,t-1/3)}return[Math.round(255*r),Math.round(255*i),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 r=n.getImageData(0,0,1,1).data;return`#${r[0].toString(16).padStart(2,"0")}${r[1].toString(16).padStart(2,"0")}${r[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){Wr("테두리 하이라이팅 요소 제거 중 오류:",t)}}}Gc.DECORATOR_TYPE="border-highlighting";class Hc extends Bc{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 r=this.getComponentBounds();e.forEach(e=>{const{name:i,position:s}=e;let{x:o,y:a}=s||{};if(!i)return;let c=this.calculateOffsetX(o,r),l=this.calculateOffsetY(a,r);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=i,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()}}Hc.DECORATOR_TYPE="anchors";class Uc extends Bc{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:r,padding:i,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",`${i}`),this.textElement.setAttribute("y",`-${n}`),this.textElement.setAttribute("font-family",e),this.textElement.setAttribute("font-size",n),this.textElement.setAttribute("fill",r),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-i).toString()),this.backgroundElement.setAttribute("y",(d.y-i).toString()),this.backgroundElement.setAttribute("width",(d.width+2*i).toString()),this.backgroundElement.setAttribute("height",(d.height+2*i).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()}}Uc.DECORATOR_TYPE="decotag";class Wc extends Bc{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}createDOMElements(){if(this.removeDOMElements(),!this.target.mappings||!this.target.mappings.length)return;this.currentMappings=this.target.mappings;const t=this.options,e=this.getOrCreateDecoratorGroup(!0),n=this.getDefsForType(),r=`data-spread-style-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,i=document.createElementNS("http://www.w3.org/2000/svg","style");i.setAttribute("id",r),i.textContent=`\n @keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: ${t.repeat?"0.2":"0"}; }\n }\n .arrow-animated {\n animation: fadeOut ${t.animationDuration||2e3}ms linear ${t.repeat?"infinite":"1"} forwards;\n }\n `,n.appendChild(i);const s=`arrow-gradient-${Date.now()}-${Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}`,o=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");o.setAttribute("id",s),o.setAttribute("gradientUnits","userSpaceOnUse");const a=document.createElementNS("http://www.w3.org/2000/svg","stop");a.setAttribute("offset","0%"),a.setAttribute("stop-color",t.arrowColor||"#FFA500"),a.setAttribute("stop-opacity",(t.startAlpha||.5).toString());const c=document.createElementNS("http://www.w3.org/2000/svg","stop");c.setAttribute("offset","100%"),c.setAttribute("stop-color",t.arrowColor||"#FFA500"),c.setAttribute("stop-opacity",(t.endAlpha||1).toString()),o.appendChild(a),o.appendChild(c),n.appendChild(o);const l=document.createElementNS("http://www.w3.org/2000/svg","g");l.setAttribute("class",t.animated?"arrow-animated":""),e.appendChild(l);this.target.mappings.forEach(e=>{const n=this.target.root.findAll(e.target,this.target);n&&n.length&&n.forEach(e=>{const n=this.target.center,r=e.center,i=this.projectComponentPoint(this.target,n.x,n.y),a=this.projectComponentPoint(e,r.x,r.y);if(!i||!a)return;o.setAttribute("x1",i.x.toString()),o.setAttribute("y1",i.y.toString()),o.setAttribute("x2",a.x.toString()),o.setAttribute("y2",a.y.toString());const{linePath:c,headPath:h}=this.createArrowPaths(i,a,t.arrowHeadLength),d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("d",c),d.setAttribute("stroke",`url(#${s})`),d.setAttribute("stroke-width",String(t.lineWidth||2)),d.setAttribute("fill","none"),d.setAttribute("data-target-id",e.state?.id||""),d.setAttribute("data-source-id",this.target.state?.id||"");const u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",h),u.setAttribute("fill",t.arrowColor||"#FFA500"),u.setAttribute("stroke","none"),l.appendChild(d),l.appendChild(u)})}),this.vectorElement=e}createArrowPaths(t,e,n){const r=e.x-t.x,i=e.y-t.y,s=Math.atan2(i,r),o=e.x+n*Math.cos(s+Wc.ARROW_ANGLE_1),a=e.y+n*Math.sin(s+Wc.ARROW_ANGLE_1),c=e.x+n*Math.cos(s+Wc.ARROW_ANGLE_2),l=e.y+n*Math.sin(s+Wc.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();const t=this.target.mappings;t&&t===this.currentMappings?this.vectorElement&&this.updatePosition():(this.removeDOMElements(),requestAnimationFrame(()=>{this.createDOMElements()}))}updatePosition(){const t=this.getDecoratorType(),e=this.getSvgContainer().querySelector(`g[data-decorator-type-container="${t}"]`);if(!e)return;const n=this.getVectorGroupId(),r=e.querySelector(`g[data-decorator-group-id="${n}"]`);if(!r)return;const i=this.options;if(!this.target.mappings||!this.target.mappings.length)return;const s=r.querySelector("g.arrow-animated")||r,o=Array.from(s.querySelectorAll('path[fill="none"]')),a=Array.from(s.querySelectorAll('path[stroke="none"]'));if(0===o.length)return;const c=e.querySelector(`defs[data-defs-for="${t}"]`);if(!c)return;const l=c.querySelector("linearGradient");if(!l)return;const h=this.target.mappings;let d=[];h.forEach(t=>{const e=this.target.root.findAll(t.target,this.target);e&&e.length&&(d=[...d,...e])});for(let t=0;t<Math.min(o.length,a.length,d.length);t++){const e=o[t],n=a[t],r=d[t],s=this.target.center,c=r.center,h=this.projectComponentPoint(this.target,s.x,s.y),u=this.projectComponentPoint(r,c.x,c.y);if(!h||!u)continue;const{linePath:p,headPath:f}=this.createArrowPaths(h,u,i.arrowHeadLength);e.setAttribute("d",p),n.setAttribute("d",f),0===t&&l&&(l.setAttribute("x1",h.x.toString()),l.setAttribute("y1",h.y.toString()),l.setAttribute("x2",u.x.toString()),l.setAttribute("y2",u.y.toString()))}}removeDOMElements(){this.currentMappings=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){Wr("데이터 스프레드 데코레이터 요소 제거 중 오류:",t)}}invalidate(){this.updatePosition()}}Wc.DECORATOR_TYPE="data-spread",Wc.ARROW_ANGLE_1=160*Math.PI/180,Wc.ARROW_ANGLE_2=200*Math.PI/180;class Xc extends Bc{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:r,bgColor:i,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",r),b.setAttribute("font-family",a),b.setAttribute("font-size",o),b.textContent=u,c.appendChild(b);const v=b.getBBox();c.removeChild(b);const x=document.createElementNS("http://www.w3.org/2000/svg","rect"),_=v.width+2*(n??0),w=v.height+2*(n??0);g+=(t??0)+_/2,m+=(e??0)+w/2,x.setAttribute("x",(-_/2).toString()),x.setAttribute("y",(-w/2).toString()),x.setAttribute("width",_.toString()),x.setAttribute("height",w.toString()),x.setAttribute("rx",(s??0).toString()),x.setAttribute("ry",(s??0).toString()),x.setAttribute("fill",i),y.appendChild(x),y.appendChild(b),y.setAttribute("transform",`translate(${g}, ${m})`),c.appendChild(y),this.rectElements.push(x),this.textElements.push(b)})}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}}Xc.DECORATOR_TYPE="link",Is.registerDecorator("bouncing-arrow",Yc),Is.registerDecorator("animated-icon",Vc),Is.registerDecorator("border-highlighting",Gc),Is.registerDecorator("anchors",Hc),Is.registerDecorator("decotag",Uc),Is.registerDecorator("data-spread",Wc),Is.registerDecorator("link",Xc);class qc{constructor(t){this.params=Object.assign({},t)}excute(){}}class Kc extends qc{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 $c="left",Qc="right",Zc="center",Jc="bottom",tl="middle",el="z-front",nl="z-back",rl="z-middle",il=[$c,Qc,Zc,"top",tl,Jc,el,nl,rl];function sl(t){if(!this.hasSameParentForAllSelected||-1===il.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(e.length<=1)return;const n=this.app.commander;Kc.around(n,function(){!function(t,e){const n=JSON.parse(JSON.stringify(e[0].bounds));let r=n.left+n.width,i=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,r=s.left+s.width>r?s.left+s.width:r,i=s.top+s.height>i?s.top+s.height:i}switch(n.width=r-n.left,n.height=i-n.top,t){case $c:for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:n.left,top:r.top,width:r.width,height:r.height}}break;case Zc:for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:n.left+n.width/2-r.width/2,top:r.top,width:r.width,height:r.height}}break;case Qc:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:r-n.width,top:n.top,width:n.width,height:n.height}}break;case"top":for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:r.left,top:n.top,width:r.width,height:r.height}}break;case tl:for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:r.left,top:n.top+n.height/2-r.height/2,width:r.width,height:r.height}}break;case Jc:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:n.left,top:i-n.height,width:n.width,height:n.height}}break;case el:{let t=1/0;for(let n=0;n<e.length;n++){const r=e[n].state.zPos||0;r<t&&(t=r)}for(let n=0;n<e.length;n++)e[n].set({zPos:t});break}case nl:{let t=-1/0;for(let n=0;n<e.length;n++){const r=(e[n].state.zPos||0)+(e[n].state.depth||0);r>t&&(t=r)}for(let n=0;n<e.length;n++){const r=e[n].state.depth||0;e[n].set({zPos:t-r})}break}case rl:{let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){const i=e[r].state.zPos||0,s=e[r].state.depth||0;i<t&&(t=i),i+s>n&&(n=i+s)}const r=(t+n)/2;for(let t=0;t<e.length;t++){const n=e[t].state.depth||0;e[t].set({zPos:r-n/2})}break}default:;}}(t,e)})}const ol="VERTICAL",al=[ol,"HORIZONTAL","Z"];function cl(t){if(!this.hasSameParentForAllSelected||-1===al.indexOf(t))return;const e=this.selected;if(e.length<=1)return;const n=this.app.commander;Kc.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),r=e[0].state.zPos||0,i=((e[e.length-1].state.zPos||0)+(e[e.length-1].state.depth||0)-r-n)/(e.length-1);let s=r+(e[0].state.depth||0);for(let t=1;t<e.length-1;t++){const n=e[t],r=n.state.depth||0;s+=i,n.set({zPos:s}),s+=r}}(e);const n=e.filter(t=>!t.stuck).slice(0);n.sort(function(e,n){const r=e.center,i=n.center;return t===ol?r.y-i.y:r.x-i.x});const r=n.reduce((e,n)=>e+(t===ol?n.bounds.height:n.bounds.width),0),i=n[0].bounds,s=n[n.length-1].bounds,o=((t===ol?s.top+s.height-i.top:s.left+s.width-i.left)-r)/(n.length-1);let a=t===ol?i.top+i.height:i.left+i.width;for(let e=1;e<n.length-1;e++){const r=n[e],i=r.bounds;a+=o,t===ol?(r.bounds={left:i.left,top:a,width:i.width,height:i.height},a+=i.height):(r.bounds={left:a,top:i.top,width:i.width,height:i.height},a+=i.width)}}(t,e)})}function ll(t){let e=0;for(;t&&!t.isRootModel();)e+=t.get("rotation")||0,t=t.parent;return e%(2*Math.PI)}class hl extends qc{execute(){this.params.changes.forEach(t=>{const{component:e,to_container:n,to_index:r,to_left:i,to_top:s}=t,o=function(t){if(t.isRootModel())return t.bounds;const{bounds:e,rotatePoint:n}=t;let r=n;return r=t.toScene(r.x,r.y),{left:r.x-(n.x-e.left),top:r.y-(n.y-e.top),width:e.width,height:e.height}}(e),a=ll(e);if(e.removeSelf(!n),e.bounds=o,e.set("rotation",a),n){e.set("rotation",function(t,e){return((t.get("rotation")||0)-ll(e))%(2*Math.PI)}(e,n));const o=function(t,e){if(e.isRootModel())return t.bounds;const{bounds:n,rotatePoint:r}=t,i=e.fromScene(r.x,r.y),s=e.bounds;return{left:i.x-(r.x-n.left)-s.left,top:i.y-(r.y-n.top)-s.top,width:n.width,height:n.height}}(e,n);t.to_left=void 0!==i?i: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===r?n.addComponent(e):n.insertComponentAt(e,r)}})}}function dl(t,e,n){this.app.commander.execute(new hl({changes:[{component:t,to_container:e,to_index:n}]}))}function ul(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 r;if("forward"===t){const t=n.indexOf(e[0]);r=[{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]);r=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t-1}]}else r=e.filter(t=>t.parent===n).sort((e,r)=>{const i=n.indexOf(e)<n.indexOf(r);return"front"===t?i:!i}).map((e,r)=>(n.indexOf(e),{component:e,to_container:n,to_index:"front"===t?n.components.length-r-1:r}));const i=new hl({changes:r});this.app.commander.execute(i)}function pl(t,e,n,r){const i=tc.register(t.type);if(!i)return Xr("Class not found",t.type),null;n&&(t.refid=n(t.refid)),t.id&&r&&r(t.id)&&delete t.id;const s=new i(t,e);return t.components&&s.isContainer()&&(t.components.forEach(t=>{const i=pl(t,e,n,r);i&&s.addComponent(i)}),delete t.components),s.created(),s}function fl(t,e){const n=Kn(t.hierarchy);return delete n.id,pl(n,t.app,e)}function gl(t,e,n){t instanceof Array||(t=[t]),n||(n=this.model_layer);const r=[],i=new Map;this.selected=t.map(t=>{try{return pl(t,n.app,t=>{const e=this.getNewRefid();return void 0!==t&&i.set(t,e),e},t=>(this.indexMap[t]||[])[0])}catch(t){return Xr(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(i),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}),r.push({component:t,to_container:n}),t}),this.app.commander.execute(new hl({changes:r}))}function ml(){const t=[],e=new Map;if(this.selected=this.selected.filter(t=>!t.isRootModel()).map(n=>{const r=fl(n,t=>{const n=this.getNewRefid();return void 0!==t&&e.set(t,n),n});return r.move({x:20,y:20},!1),t.push({component:r,to_container:n.parent}),r}).map(t=>(t.replaceRefids(e),t)),0===t.length)return;const n=new hl({changes:t});this.app.commander.execute(n)}function yl(){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 r=e.parent;t.forEach(t=>n.push({component:t,to_container:r})),n.push({component:e,to_container:null}),e=r}n.length>0&&this.app.commander.execute(new hl({changes:n})),e&&e.calculateBounds&&e.calculateBounds()}const bl=new Set(["execute","redo","undo","command-reset"]);function vl(t,e,n,r){const i=function(t,e){return bl.has(e)?t.app?.commander:"mode"===e?t.app:t}(this,e);i?.[t](e,n,r)}function xl(t,e,n){vl.call(this,"on",t,e,n)}function _l(t,e,n){vl.call(this,"once",t,e,n)}function wl(t,e,n){vl.call(this,"off",t,e,n)}function Ml(t){const e=this.target_element,n=t||this.fitMode,r=this;function i(){r.fit(n),document.fullscreenElement||document.removeEventListener("fullscreenchange",i)}document.addEventListener("fullscreenchange",i),e.requestFullscreen().catch(()=>{document.removeEventListener("fullscreenchange",i)})}let Sl=0;function Al(){const t=this.selected.filter(t=>!t.isRootModel()).map(t=>t.hierarchy);if(0!==t.length)return Sl=0,JSON.stringify(t,null,2)}function kl(){Sl=0;const t=Al.call(this);return yl.call(this),t}function El(t){if(t)try{Sl++,gl.call(this,JSON.parse(t),{x:15*Sl,y:15*Sl})}catch(e){Wr(e,t)}}const Cl=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]),r=n.length,i=new Uint8Array(r);for(let t=0;t<r;t++)i[t]=n.charCodeAt(t);e(new Blob([i],{type:"image/png"}))})}(t)},resolveUrl:function(t,e){const n=document.implementation.createHTMLDocument(),r=n.createElement("base");n.head.appendChild(r);const i=n.createElement("a");return n.body.appendChild(i),r.href=e,i.href=t,i.href},getAndEncode:function(t){const e=3e4;jl.impl.options.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());return new Promise(function(n){const r=new XMLHttpRequest;let i;if(r.onreadystatechange=s,r.ontimeout=o,r.responseType="blob",r.timeout=e,r.open("GET",t,!0),r.send(),jl.impl.options.imagePlaceholder){const t=jl.impl.options.imagePlaceholder.split(/,/);t&&t[1]&&(i=t[1])}function s(){if(4!==r.readyState)return;if(200!==r.status)return void(i?n(i):a("cannot fetch resource: "+t+", status: "+r.status));const e=new FileReader;e.onloadend=function(){const t=e.result.split(/,/)[1];n(t)},e.readAsDataURL(r.response)}function o(){i?n(i):a("timeout of "+e+"ms occured while fetching resource: "+t)}function a(t){Wr(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 r=0;r<n;r++)e.push(t[r]);return e},escapeXhtml:function(t){return t.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(t){return new Promise(function(e,n){const r=new Image;r.onload=function(){e(r)},r.onerror=n,r.src=t})},width:function(t){const n=e(t,"border-left-width"),r=e(t,"border-right-width");return t.scrollWidth+n+r},height:function(t){const n=e(t,"border-top-width"),r=e(t,"border-bottom-width");return t.scrollHeight+n+r}};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",""))}}(),Pl=function(){const t=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(t,i,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 r(e,t,i,s)})}),n});function o(){return!e(t)}},shouldProcess:e,impl:{readUrls:n,inline:r}};function e(e){return-1!==e.search(t)}function n(e){const n=[];let r;for(;null!==(r=t.exec(e));)n.push(r[1]);return n.filter(function(t){return!Cl.isDataUrl(t)})}function r(t,e,n,r){return Promise.resolve(e).then(function(t){return n?Cl.resolveUrl(t,n):t}).then(r||Cl.getAndEncode).then(function(t){return Cl.dataAsUrl(t,Cl.mimeType(e))}).then(function(n){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+Cl.escape(t)+")(['\"]?\\))","g")}(e),"$1"+n+"$3")})}}(),Tl=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(Cl.asArray(document.styleSheets)).then(function(t){const e=[];return t.forEach(function(t){try{Cl.asArray(t.cssRules||[]).forEach(t=>e.push(t))}catch(e){Xr("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 Pl.shouldProcess(t.style.getPropertyValue("src"))})}).then(function(e){return e.map(t)});function t(t){return{resolve:function(){const e=(t.parentStyleSheet||{}).href;return Pl.inlineAll(t.cssText,e)},src:function(){return t.style.getPropertyValue("src")}}}}}(),Ol=function(){return{inlineAll:function e(n){return n instanceof Element?r(n).then(function(){return n instanceof HTMLImageElement?t(n).inline().then(()=>n):Promise.all(Cl.asArray(n.childNodes).map(function(t){return e(t)})).then(()=>n)}):Promise.resolve(n);function r(t){const e=t.style.getPropertyValue("background");return e?Pl.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 Cl.isDataUrl(t.src)?Promise.resolve():Promise.resolve(t.src).then(e||Cl.getAndEncode).then(function(e){return Cl.dataAsUrl(e,Cl.mimeType(t.src))}).then(function(e){return new Promise(function(n,r){t.onload=n,t.onerror=r,t.src=e})})}}}}(),Dl={imagePlaceholder:void 0,cacheBust:!1};function Il(t,e){return function(t){void 0===t.imagePlaceholder?jl.impl.options.imagePlaceholder=Dl.imagePlaceholder:jl.impl.options.imagePlaceholder=t.imagePlaceholder;void 0===t.cacheBust?jl.impl.options.cacheBust=Dl.cacheBust:jl.impl.options.cacheBust=t.cacheBust}(e=e||{}),Promise.resolve(t).then(function(t){return Ll(t,e.filter,!0)}).then(function(t){return function(t){return Ol.inlineAll(t).then(function(){return t})}(t)}).then(function(t){const{bgcolor:n,width:r,height:i,style:s,sx:o=1,sy:a=1}=e||{},c=t.style;n&&(c.backgroundColor=n);r&&(c.width=r+"px");i&&(c.height=i+"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(Cl.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||Cl.width(t),e.height||Cl.height(t))})}function zl(t,e){return Il(t,e).then(Cl.makeImage).then(Cl.delay(100)).then(function(n){const r=function(t){const n=document.createElement("canvas");if(n.width=e.width||Cl.width(t),n.height=e.height||Cl.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 r.getContext("2d").drawImage(n,0,0),r})}function Ll(t,e,n){return n||!e||e(t)?Promise.resolve(t).then(function(t){if(t instanceof HTMLCanvasElement)try{return Cl.makeImage(t.toDataURL()).then(t=>t)}catch(t){Xr(t)}return t.cloneNode(!1)}).then(function(n){return function(t,e,n){const r=t.childNodes;return 0===r.length?Promise.resolve(e):i(e,Cl.asArray(r),n).then(function(){return e});function i(t,e,n){let r=Promise.resolve();return e.forEach(function(e){r=r.then(function(){return Ll(e,n,!1)}).then(function(e){e&&t.appendChild(e)})}),r}}(t,n,e)}).then(function(e){return function(t,e){return e instanceof Element?Promise.resolve().then(n).then(r).then(i).then(s).then(function(){return e}):e;function n(){function n(t,e){function n(t,e){Cl.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 r(){function n(n){const r=window.getComputedStyle(t,n),i=r.getPropertyValue("content");if(""===i||"none"===i)return;const s=Cl.uid(),o=e;o.className=o.className+" "+s;const a=document.createElement("style");function c(t,e,n){const r="."+t+":"+e,i=n.cssText?s(n):o(n);return document.createTextNode(r+"{"+i+"}");function s(t){const e=t.getPropertyValue("content");return t.cssText+" content: "+e+";"}function o(t){return Cl.asArray(t).map(e).join("; ")+";";function e(e){return e+": "+t.getPropertyValue(e)+(t.getPropertyPriority(e)?" !important":"")}}}a.appendChild(c(s,n,r)),e.appendChild(a)}[":before",":after"].forEach(function(t){n(t)})}function i(){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 jl={toSvg:Il,toPng:function(t,e){return zl(t,e||{}).then(function(t){return t.toDataURL()})},toJpeg:function(t,e){return zl(t,e=e||{}).then(function(t){return t.toDataURL("image/jpeg",e.quality||1)})},toBlob:function(t,e){return zl(t,e||{}).then(t=>Cl.canvasToBlob(t))},toPixelData:function(t,e){return zl(t,e||{}).then(function(e){return e.getContext("2d").getImageData(0,0,Cl.width(t),Cl.height(t)).data})},impl:{fontFaces:Tl,images:Ol,util:Cl,inliner:Pl,options:{}}};function Rl(t,e,n,r){const i=this.model_layer,s=i._overlay;return new Promise(function(o,a){if(i){const a=i.get("width"),c=i.get("height");n=n||a,r=r||c;const l=i.get("translate"),h=i.get("scale"),d=Math.min(n/a,r/c);n=a*d,r=c*d,i.set("translate",{x:0,y:0}),i.set("scale",{x:d/Ri,y:d/Ri});let u=tc.createCanvas(n,r);const p=u.getContext("2d");if(i.draw(p),i.set("translate",l),i.set("scale",h),!s)return o(u.toDataURL(t,e)),void(u=null);jl.toPng(s,{sx:d,sy:d,width:n,height:r}).then(function(i){const s=new Image;s.onload=function(){p.drawImage(s,0,0,n,r),o(u.toDataURL(t,e)),u=null},s.src=i},function(n){Wr(n),o(u.toDataURL(t,e)),u=null})}else a("No target model")})}function Fl(){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=[],r=t.sort((t,n)=>e.components.indexOf(t)-e.components.indexOf(n));r.forEach(t=>{n.push(t.bounds)});const i=tc.union(n);let s=t[0].fromParent(i.left,i.top);s=t[0].toScene(s.x,s.y);const o=new Map,a=pl({type:"group",left:s.x,top:s.y,width:i.width,height:i.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}];r.forEach(t=>{c.push({component:t,to_container:a})}),this.app.commander.execute(new hl({changes:c})),this.selected=[a]}function Bl(){if(0===this.selected.length)return;const t=[],e=[];this.selected.forEach(n=>{if(!n.isGroup())return;const r=n.parent;n.components.forEach(n=>{t.push(n),e.push({component:n,to_container:r})}),e.push({component:n,to_container:null})}),this.app.commander.execute(new hl({changes:e})),this.selected=t}function Nl(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=tc.union(e),r=n.left+n.width/2;t.map(t=>{t.symmetryX(r)})}function Yl(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=tc.union(e),r=n.top+n.height/2;t.map(t=>{t.symmetryY(r)})}function Vl(){Kc.around(this.app.commander,Nl,this)}function Gl(){Kc.around(this.app.commander,Yl,this)}function Hl(t,e,n){const r=this.findAll(t,n);return r.forEach(t=>{t.set(e)}),r}function Ul(t){Kc.around(this.app.commander,t)}function Wl(){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 Xl="left",ql="right",Kl="center",$l="bottom",Ql="middle",Zl=[Xl,ql,Kl,"top",Ql,$l];function Jl(t){if(!this.hasSameParentForAllSelected||-1===Zl.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck),n=this.app.commander;Kc.around(n,function(){!function(t,e){const n=e[0].parent,{width:r,height:i}=n.bounds;switch(t){case Xl:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:0}}break;case Kl:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:r/2-n.width/2}}break;case ql:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:r-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 Ql:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:i/2-n.height/2}}break;case $l:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:i-n.height}}break;default:;}}(t,e)})}function th(t){t instanceof Array||(t=[t]),this.trigger("addstart",t)}function eh(){this.trigger("stylepastestart")}function nh(){this.trigger("stylepastestop")}function rh(){this.trigger("databindpastestart")}function ih(){this.trigger("databindpastestop")}let sh=0,oh=0,ah=0,ch=null;function lh(){ah++;const t=performance.now(),e=t-oh;e>=1e3&&(sh=Math.round(1e3*ah/e),oh=t,ah=0),ch=requestAnimationFrame(lh)}function hh(){null!==ch&&(cancelAnimationFrame(ch),ch=null)}function dh(){return null===ch&&(oh=performance.now(),ah=0,ch=requestAnimationFrame(lh)),sh}const uh=function(){const t=document.createElement("canvas").getContext("2d");return(window.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)}();function ph(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 fh=Math.sqrt(3);function gh(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 mh(t,n,r){switch(t){case"none":default:return null;case"arrow":{const t=new e.Shape;t.moveTo(0,0),t.lineTo(-fh*n.X,-n.Y),t.lineTo(-fh*n.X,n.Y),t.closePath();const r=new e.ShapeGeometry(t),i=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(r,i)}}case"sharp-arrow":{const t=new e.Shape;t.moveTo(0,0),t.lineTo(-fh*n.X,-n.Y),t.lineTo(n.X/1.5-fh*n.X,0),t.lineTo(-fh*n.X,n.Y),t.closePath();const r=new e.ShapeGeometry(t),i=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(r,i)}}case"open-arrow":{const t=[-(fh*n.X+r),-n.Y,0,-r,0,0,-(fh*n.X+r),n.Y,0],e=new f;e.setPositions(t);const i=new p({linewidth:r,worldUnits:!0});return{line2:new u(e,i)}}case"diamond":{const t=new e.Shape;t.moveTo(-n.X,0),t.lineTo(0,-n.Y),t.lineTo(n.X,0),t.lineTo(0,n.Y),t.closePath();const r=new e.ShapeGeometry(t),i=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(r,i)}}case"oval":{const t=new e.CircleGeometry(n.X,24);t.scale(1,n.Y/n.X,1);const r=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(t,r)}}case"cross":{const t=new e.Group,i=new f;i.setPositions([-n.X,-n.Y,0,n.X,n.Y,0]);const s=new p({linewidth:r,worldUnits:!0}),o=new u(i,s);o.computeLineDistances(),t.add(o);const a=new f;a.setPositions([n.X,-n.Y,0,-n.X,n.Y,0]);const c=new p({linewidth:r,worldUnits:!0}),l=new u(a,c);return l.computeLineDistances(),t.add(l),{group:t}}}}function yh(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function bh(t,n,r,i){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,begin:c="none",beginSize:l="size2",end:h="arrow",endSize:d="size2",label:g}=r,m=(new e.Vector3).subVectors(n,t),y=m.length(),b=new e.Group;if(y<.01)return b;const v=m.clone().normalize(),x=yh(c,a),_=yh(h,a),w=t.clone().add(v.clone().multiplyScalar(x)),M=n.clone().sub(v.clone().multiplyScalar(_));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 A=function(t,n,r,i){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,lineDash:c="solid"}=r,l=new f;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:g,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 p({color:d?16777215:h.getHex(),linewidth:a,worldUnits:!0,vertexColors:d,dashed:g,dashSize:m,gapSize:y,transparent:o<1||Array.isArray(s)&&s.some(t=>t.length>7),opacity:o,resolution:i}),v=new u(l,b);return v.computeLineDistances(),v}(w,M,r,i);b.add(A);const k=(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 r=t.mesh||t.line2||t.group;if(r){if(r.position.copy(e),r.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(i)}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(i)}});b.add(r)}};C(mh(h,gh(d,a),a),n,k);if(C(mh(c,gh(l,a),a),t,E),g){const r=(new e.Vector3).addVectors(t,n).multiplyScalar(.5);r.y+=3;const i=function(t,n,r){const i="Arial",s=ph(256,64),o=s.getContext("2d");o.font=`bold 28px ${i}`;const a=o.measureText(t).width;o.fillStyle=n,o.fillRect(0,0,a+12,40),o.fillStyle="white",o.font=`bold 28px ${i}`,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(r);const d=(a+12)/40;return h.scale.set(4*d,4,1),h}(g,"string"==typeof s?s:Array.isArray(s)&&s[1]||"#00B050",r);b.add(i)}return b}const vh=.001;function xh(t,e,n){let r=1;if(n&&"none"!=n&&"transparent"!=n){r=e*("string"==typeof n?y(n).getAlpha():1)}else r=0;t.opacity=r,t.transparent=r<1}function _h(t){const e=y(t);return e.isValid()?e.toHexString():t}const wh={width:1,height:1,depth:1},Mh={x:1,y:1,z:1},Sh={x:0,y:0,z:0},Ah={x:0,y:0,z:0},kh={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 Eh(t){if(!t)return{metalness:0,roughness:.4,emissive:"#000000",emissiveIntensity:0,opacity:1,envMapIntensity:.5,side:"double",castShadow:!0,receiveShadow:!1};const e=kh[t.preset??"default"]??kh.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 Ch={double:e.DoubleSide,front:e.FrontSide,back:e.BackSide};function Ph(t){return Ch[t]??e.DoubleSide}const Th=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap"];function Oh(t){for(const e of Th){const n=t[e];n?.dispose()}t.dispose()}function Dh(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)Oh(t)}})}function Ih(t,e){return-1!==t.findIndex(t=>t in e)}class zh{static buildFillStyleTexture(t){const{fillStyle:e}=t.state;if("object"==typeof e)return"pattern"===e.type&&e.image?zh.buildPatternTexture(t,e):"gradient"===e.type&&e.colorStops?.length?zh.buildGradientTexture(e,t.bounds):void 0}static buildPatternTexture(t,n){const{width:r,height:i}=t.state,s=Math.abs(r)||1,o=Math.abs(i)||1,a=new e.Texture;a.colorSpace=e.SRGBColorSpace;const c=new Image;return"data"!==String(n.image).substring(0,4)&&(c.crossOrigin="anonymous"),c.onload=()=>{const r=2*s,i=2*o,l=document.createElement("canvas");l.width=r,l.height=i;const h=l.getContext("2d");if(h){if(n.color&&(h.fillStyle=n.color,h.fillRect(0,0,r,i)),n.fitPattern)h.drawImage(c,0,0,r,i);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=(r-t)/2,l=(i-e)/2;break;case"left-top":break;case"left-bottom":l=i-e;break;case"right-top":a=r-t;break;case"right-bottom":a=r-t,l=i-e;break;case"left":l=(i-e)/2;break;case"right":a=r-t,l=(i-e)/2;break;case"top":a=(r-t)/2;break;case"bottom":a=(r-t)/2,l=i-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,r,i),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<i;s+=e)for(let i=n;i<r;i+=t)h.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,i,s,t,e);h.restore()}}a.image=l,a.minFilter=e.LinearFilter,a.needsUpdate=!0,t.invalidate()}},c.onerror=t=>{Wr("Pattern texture load error:",t)},c.src=t.app.url(n.image),a}static buildGradientTexture(t,n){const r=256,i=document.createElement("canvas");i.width=r,i.height=r;const s=i.getContext("2d");if(!s)return;let o;if("radial"===t.gradientType){const e=128,n=128,i=128;switch(t.center){case"left-top":o=s.createRadialGradient(0,0,0,0,0,2*i);break;case"right-top":o=s.createRadialGradient(r,0,0,r,0,2*i);break;case"left-bottom":o=s.createRadialGradient(0,r,0,0,r,2*i);break;case"right-bottom":o=s.createRadialGradient(r,r,0,r,r,2*i);break;default:o=s.createRadialGradient(e,n,0,e,n,i)}}else{const e=t.rotation??0,n=128,r=128,i=Math.cos(e)*n,a=Math.sin(e)*r;o=s.createLinearGradient(n-i,r-a,n+i,r+a)}for(const e of t.colorStops)if(e.position>=0&&e.position<=1)try{o.addColorStop(e.position,e.color)}catch{o.addColorStop(e.position,"#fff")}s.fillStyle=o,s.fillRect(0,0,r,r);const a=new e.CanvasTexture(i);return a.colorSpace=e.SRGBColorSpace,a.needsUpdate=!0,a}constructor(t){this._focused=!1,this._suppressOnchange=!1,this._onchangeWrapper=(t,e)=>{this._suppressOnchange||this.onchange(t,e)},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=Eh(this.component.state.material3d);this._applyShadow(t.castShadow,t.receiveShadow),this.object3d.name=this.component.state.id}updateMaterial3d(){const t=Eh(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 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(){for(const t of this.object3d.children)Dh(t);return this.object3d.userData={},this.object3d.clear()}updateTransform(){const{x:t,y:e,z:n}=this.position,{x:r,y:i,z:s}=this.rotation,{x:o,y:a,z:c}=this.scale;this.object3d.position.set(t,e,n),this.object3d.rotation.set(r,i,s),this.object3d.scale.set(Math.max(o,vh),Math.max(a,vh),Math.max(c,vh))}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();return t+e+this.syncZPosOffset}get center(){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:r=0}=this.component.parent?.bounds??{},{tx:i=0,ty:s=0}=this.component.delta();return{x:t+i-n/2,y:e+s-r/2,z:this.cz}}get dimension(){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,vh),Math.max(e,vh),Math.max(n,vh))}syncAnimationDelta(){const t=this.component.delta();this.updatePosition();const{rotationX:e=0,rotationY:n=0,rotation:r=0}=this.component.state,i=t.theta||0;this.object3d.rotation.set(e,-(r+i),n);const{scale:s}=this.component.state,o="number"==typeof s?s:s?.x??1,a=t.sx??1,c=t.sy??1;this.object3d.scale.set(Math.max(o*a,vh),Math.max(o*c,vh),Math.max(o,vh));const l=t.fade||0;if(0!==l){const t=(this.component.state.alpha??1)*(1-l);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(){return this.effectiveDepth/2}get textSurfaceYOffset(){return this.effectiveDepth-this.syncZPosOffset}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:r=0}=e.parent?.bounds??{},i=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-i.width/2,top:t.position.z-o+r/2-i.height/2,width:i.width,height:i.height},e.set({zPos:t.position.y-a-this.syncZPosOffset,rotationX:t.rotation.x,rotation:-t.rotation.y,rotationY:t.rotation.z}),this._suppressOnchange=!1}applyDimensionFromGizmo(t){this._suppressOnchange=!0,this._component.set(t),this._suppressOnchange=!1}onchange(t,e){Ih(["cx","cy","cz","zPos","left","top"],t)&&this.updatePosition(),Ih(["width","height","depth","lineWidth"],t)&&this.updateDimension(),Ih(["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(),Ih(["text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline"],t)&&this.updateText(),"material3d"in t&&this.updateMaterial3d()}}class Lh extends zh{get syncZPosOffset(){return this.effectiveDepth}getObject3dInstance(){return new g(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:r=0}=e.parent?.bounds??{},i=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-i.width/2,top:t.position.z-o+r/2-i.height/2,width:i.width,height:i.height},e.set({zPos:t.position.y-a-this.syncZPosOffset,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 jh=new Map;let Rh;function Fh(t,e){jh.set(t,e)}function Bh(t){Rh=t}function Nh(t){const e=t.buildRealObject();if(e)return e;const n=t.model?.type,r=n?jh.get(n):void 0;if(r)return r(t);if(t.isHTMLElement()){const e=jh.get("html-overlay-element");if(e)return e(t)}return Rh?.(t)}function Yh(t,n,r){if(!t.hasTextProperty||t.textHidden)return;const i=t._realObject;if(!i?.object3d)return;const{text:s="",bold:o=Ni.BOLD,italic:a=Ni.ITALIC,fontFamily:c=Ni.FONT_FAMILY,fontColor:l=Ni.FONT_COLOR,fontSize:h=Ni.FONT_SIZE,textAlign:d=Ni.TEXT_ALIGN,textBaseline:u=Ni.TEXT_BASELINE,width:p,height:f}=t.model,m=Math.abs(p)||1,y=Math.abs(f)||1,b=document.createElement("textarea"),v=new AbortController;Fi.forEach(t=>{b.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:v.signal})}),b.value=s;const x="right"===d||"end"===d?"right":"left"===d||"start"===d?"left":"justify"===d?"justify":"center";let _="0";if("bottom"===u||"alphabetic"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);_=Math.max(0,y-t)+"px"}else if("middle"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);_=Math.max(0,(y-t)/2)+"px"}b.style.cssText=[`width: ${m}px`,`height: ${y}px`,`padding: ${_} 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: ${x}`].join("; ");const w=new g(b),M=i.object3d;M.updateWorldMatrix(!0,!1);const S=new e.Vector3,A=new e.Quaternion,k=new e.Vector3;M.matrixWorld.decompose(S,A,k);const E=new e.Vector3(0,i.textSurfaceYOffset,0);E.multiply(k),E.applyQuaternion(A),w.position.copy(S).add(E);const C=(new e.Quaternion).setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2);w.quaternion.copy(A).multiply(C),w.scale.copy(k),n.css3DScene.add(w),r();const P=n.css3DRenderer.domElement,T=P.style.getPropertyValue("pointer-events"),O=P.style.getPropertyPriority("pointer-events"),D=[];let I=b;for(;I&&I!==P.parentElement;)D.push({el:I,saved:I.style.pointerEvents}),I.style.setProperty("pointer-events","auto","important"),I=I.parentElement;b.focus(),b.select();let z=!1;const L=t.root?.selected;b.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"!==t.code&&(t.shiftKey||"Enter"!==t.code&&"NumpadEnter"!==t.code)||(z="Escape"===t.code,b.blur())},{signal:v.signal});const j=()=>{n.css3DScene.remove(w);for(const{el:t,saved:e}of D)e?t.style.pointerEvents=e:t.style.removeProperty("pointer-events");O?P.style.setProperty("pointer-events",T,O):T&&P.style.setProperty("pointer-events",T),v.abort(),b.removeEventListener("blur",j),L&&t.root&&(t.root.selected=L),z||b.value===s||t.app.commander.execute(new Kc({changes:[{component:t,before:{text:s},after:{text:b.value}}]})),r()};b.addEventListener("blur",j)}function Vh(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity}function Gh(t){const{fillStyle:n,floorMaterial3d:r}=t.state,i=Eh(r);if("none"===n)return;const s=new e.BoxGeometry(1,1,1);let o;if(n){const r=zh.buildFillStyleTexture(t);if(r){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:r}),new e.MeshStandardMaterial({color:t})];n.forEach(t=>Vh(t,i)),o=n}else if("string"==typeof n){const t=new e.MeshStandardMaterial({color:n});Vh(t,i),o=t}}if(!o){const t=new e.MeshStandardMaterial({color:"#e0e0e0"});Vh(t,i),o=t}const a=new e.Mesh(s,o),{width:c,height:l}=t.state;return a.scale.set(c,l,5),a.rotation.x=-Math.PI/2,a.position.y=-3.5,a.name="floor",a.receiveShadow=!1!==r?.receiveShadow,a.castShadow=!0===r?.castShadow,a}const Hh={studio:class extends n{constructor(){super(),this.name="StudioEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:16777215,emissiveIntensity:r}),s=new o(t,i);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))}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()}},warehouse:class extends n{constructor(){super(),this.name="WarehouseEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:15266047,emissiveIntensity:r}),s=new o(t,i);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)}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()}},factory:class extends n{constructor(){super(),this.name="FactoryEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:15791615,emissiveIntensity:r}),s=new o(t,i);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)}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()}},office:class extends n{constructor(){super(),this.name="OfficeEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:16775408,emissiveIntensity:r}),s=new o(t,i);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)}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()}},home:class extends n{constructor(){super(),this.name="HomeEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:16771280,emissiveIntensity:r}),s=new o(t,i);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)}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()}}};class Uh{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,this._applyEnvironment("studio")}_applyEnvironment(t){this._envTexture&&this._envTexture.dispose();const n=new(0,Hh[t]),r=new e.PMREMGenerator(this._renderer);this._envTexture=r.fromScene(n).texture,this._scene.environment=this._envTexture,n.dispose(),r.dispose()}setSky(t,n){if(!this._scene||!this._renderer)return;const r=t;r&&r in Hh?(this._applyEnvironment(r),this._scene.background=this._envTexture):this._scene.background="color"===t&&n?new e.Color(n):null}addFloor(t){const e=Gh(t);e&&this._scene.add(e)}updateFloor(t){if(!this._scene)return;const e=this._scene.children.find(t=>"floor"===t.name);e&&(Dh(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,Dh(this._scene),this._scene.clear()),delete this._scene,delete this._mixer,delete this._renderer,this._timer&&this._timer.disconnect(),delete this._timer}}class Wh{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,r){const{fov:i,near:s,far:o,cameraX:a,cameraY:c,cameraZ:l}=r,h=t/n;this._perspCamera=new e.PerspectiveCamera(i,h,s,o);let d=.4*n,u=.4*t;return this._cameraZPos=Math.min(250,Math.floor(.5*Math.min(t,n))),null!=a&&(d=a*t),null!=c&&(u=c*n),null!=l&&(this._cameraZPos=l*Math.floor(Math.min(t,n))),this._perspCamera.position.set(d,this._cameraZPos,u),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,r=(n.top-n.bottom)/2,i=t/e;n.left=-r*i,n.right=r*i,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,r,i,s){this._orthoCamera||(this._orthoCamera=new e.OrthographicCamera(-1,1,1,-1,.1,5e4)),this.updateOrthoFrustum(n,r,i,s);const o=this._orthoCamera;o.zoom=1;const a=2*Math.max(n,r);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,r){if(!this._orthoCamera)return;const i=(n||t)/(r||e),s=Math.max(t,e)/2;i>=1?(this._orthoCamera.left=-s*i,this._orthoCamera.right=s*i,this._orthoCamera.top=s,this._orthoCamera.bottom=-s):(this._orthoCamera.left=-s,this._orthoCamera.right=s,this._orthoCamera.top=s/i,this._orthoCamera.bottom=-s/i),this._orthoCamera.updateProjectionMatrix()}destroy(){delete this._perspCamera,delete this._orthoCamera,this._activeView="perspective"}}class Xh{constructor(){this._noSupportWebgl=!1}get renderer(){return this._renderer}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}setupWebGL(t,n,r){try{const i=document.createElement("canvas"),s=i.getContext("webgl2");if(!s)return this._noSupportWebgl=!0,!1;const o=new e.WebGLRenderer({canvas:i,context:s,precision:r.precision,alpha:!0,antialias:r.antialias,logarithmicDepthBuffer:!1!==r.postprocessing,premultipliedAlpha:!1});return o.autoClear=!0,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.NoToneMapping,o.toneMappingExposure=r.exposure,o.shadowMap.enabled=!0,o.shadowMap.type=e.PCFShadowMap,o.setClearColor(16777215,1),o.setPixelRatio(window.devicePixelRatio),o.setSize(t,n,!1),i.style.width="100%",i.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 m}setupComposer(t,n,r,i,s){const o=new e.WebGLRenderTarget(r,i,{samples:4});this._composer=new b(this._renderer,o),this._composer.setSize(r,i);const a=new v(t,n);this._composer.addPass(a);const c=new x(new e.Vector2(r,i),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,r,i,o)=>{const a=s.visible;s.visible=!1,t(e,n,r,i,o),s.visible=a}}return this._outlinePass=c,this._composer.addPass(c),this._composer.addPass(new w),this._composer.addPass(new _),this._composer}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){this._renderer?.setSize(t,e,!1),this._css3DRenderer?.setSize(t,e),this._composer?.setSize(t,e)}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)}renderCSS3D(t){this._css3DRenderer?.render(this.css3DScene,t)}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?.dispose(),delete this._composer,delete this._renderer}disposeCSS3DScene(){if(this._css3DScene){[...this._css3DScene.children].forEach(t=>this._css3DScene.remove(t))}}}class qh{constructor(){this.lights=[]}get hemiLight(){return this._hemiLight}get dirLight(){return this._dirLight}setup(t,n,r){this._scene=t,this._camera=n;const{hemisphere:i,directional:s,point:o}=r;if(this._hemiLight=new e.HemisphereLight(i.skyColor,i.groundColor,i.intensity),t.add(this._hemiLight),this.lights.push(this._hemiLight),s){if(this._dirLight=new e.DirectionalLight(s.color,s.intensity),!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))}setDirectionalEnabled(t,n){if(t&&!this._dirLight&&this._camera){const t=n?.color??16777215,r=n?.intensity??.8;this._dirLight=new e.DirectionalLight(t,r),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 Kh=1e-6;class $h{constructor(){this._enabled=!0,this._state=0,this._autoRotate=!1,this._autoRotateSpeed=2,this._dampingFactor=.15,this._rotateSpeed=.1,this._panSpeed=1,this._lastScale=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 r=n.state;this._autoRotate=!n.app?.isEditMode&&(r.autoRotate||"orbit"===r.cameraAutoPlay)||!1,this._autoRotateSpeed=r.rotationSpeed||2,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:1,1===this._state?this._rotateStart.set(t.offsetX,t.offsetY):this._panStart.set(t.offsetX,t.offsetY)))}onDragMove(t){this._enabled&&(this._isOrthoLocked?(this._state=2,this._handlePanMove(t.offsetX,t.offsetY)):(this._state=t.altKey?2:1,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,r=e.offsetY??e.pageY;if(this._isOrthoLocked)return this._panStart.set(n,r),void(this._state=4);switch(t.touches.length){case 1:this._rotateStart.set(n,r),this._state=3;break;case 2:this._lastScale=t.scale||1,this._panStart.set(n,r),this._state=4;break;default:this._state=0}}onTouchMove(t){const e=t.touches[0],n=e.offsetX??e.pageX,r=e.offsetY??e.pageY;if(this._isOrthoLocked)this._handlePanMove(n,r);else switch(t.touches.length){case 1:if(3!==this._state)return;this._handleRotateMove(n,r);break;case 2:if(Math.abs(this._lastScale-(t.scale||1))>.05)return;if(4!==this._state)return;this._handlePanMove(n,r);break;default:this._state=0}}onTouchEnd(t){this._lastScale=1,this._state=0}onKeyDown(t){switch(t.keyCode){case 38:this._pan(0,7);break;case 40:this._pan(0,-7);break;case 37:this._pan(7,0);break;case 39: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)>Kh||8*(1-this._lastQuaternion.dot(t.quaternion))>Kh)&&(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),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)>Kh||8*(1-this._lastQuaternion.dot(t.quaternion))>Kh)&&(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()}markCameraChanged(){this._host?.invalidate()}dollyAtCursor(t,e,n){this._onUserInteraction?.();const r=this._camera,i=r.position.distanceTo(this._target),s=Math.max(1,Math.min(5e4,i*t));if(Math.abs(s-i)<Kh)return;const o=Math.tan(r.fov/2*Math.PI/180)/r.zoom,a=i-s,c=e*a*o*r.aspect,l=n*a*o;this._panLeftV.setFromMatrixColumn(r.matrix,0).multiplyScalar(c),this._panUpV.setFromMatrixColumn(r.matrix,1).multiplyScalar(l),this._target.add(this._panLeftV).add(this._panUpV),r.position.add(this._panLeftV).add(this._panUpV),this._panCalcOffset.subVectors(r.position,this._target).normalize().multiplyScalar(s),r.position.copy(this._target).add(this._panCalcOffset),this._host?.invalidate()}zoomOrthoAtCursor(t,e,n){this._onUserInteraction?.();const r=this._camera,i=r.zoom,s=Math.max(.1,Math.min(20,i*t)),o=e*(r.right-r.left)/2*(1/i-1/s),a=n*(r.top-r.bottom)/2*(1/i-1/s);this._panLeftV.setFromMatrixColumn(r.matrix,0).multiplyScalar(o),this._panUpV.setFromMatrixColumn(r.matrix,1).multiplyScalar(a),this._target.add(this._panLeftV).add(this._panUpV),r.position.add(this._panLeftV).add(this._panUpV),r.zoom=s,r.updateProjectionMatrix(),this._host?.invalidate()}destroy(){delete this._camera,delete this._host}_handleRotateMove(t,e){this._rotateEnd.set(t,e),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart);const n=this._host?.element;let r,i;if(n){const t=n.getBoundingClientRect();r=t.width,i=t.height}else{const{width:t,height:e}=this._host.bounds;r=t,i=e}this._sphericalDelta.theta-=2*Math.PI*this._rotateDelta.x/r*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,r=this._host?.element;let i,s;if(r){const t=r.getBoundingClientRect();i=t.width,s=t.height}else{const{width:t,height:e}=this._host.bounds;i=t,s=e}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/s),this._target.add(this._panLeftV).add(this._panUpV),n.position.add(this._panLeftV).add(this._panUpV)}_pan(t,e){t*=this._panSpeed,e*=this._panSpeed;const n=this._host?.element;let r,i;if(n){const t=n.getBoundingClientRect();r=t.width,i=t.height}else{const{width:t,height:e}=this._host.bounds;r=t,i=e}const s=this._camera;if(s.isPerspectiveCamera){this._panCalcOffset.copy(s.position).sub(this._target);let n=this._panCalcOffset.length();n*=Math.tan(s.fov/2*Math.PI/180),this._panLeftV.setFromMatrixColumn(s.matrix,0),this._panLeftV.multiplyScalar(-2*t*n/i),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(s.matrix,1),this._panUpV.multiplyScalar(2*e*n/i),this._panOffset.add(this._panUpV)}else s.isOrthographicCamera&&(this._panLeftV.setFromMatrixColumn(s.matrix,0),this._panLeftV.multiplyScalar(-t*(s.right-s.left)/s.zoom/r),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(s.matrix,1),this._panUpV.multiplyScalar(e*(s.top-s.bottom)/s.zoom/i),this._panOffset.add(this._panUpV))}}class Qh{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,r,i,s){this._mouse.x=(t-n)/i*2-1,this._mouse.y=-(e-r)/s*2+1}getObjectByRaycast(t,e){const n=this.getObjectsByRaycast(t,e);if(n&&n.length>0)for(const t of n){let e=t.object;for(;e;){if(e.userData.context){if(e.visible)return e;break}e=e.parent}}}getObjectsByRaycast(t,e){return this._raycaster.setFromCamera(this._mouse,t),this._raycaster.intersectObjects(e.children,!0)}handleClick(t,e,n){this._lastFocused&&(this._lastFocused.focused=!1);const r=this.getObjectByRaycast(t,e),i=r?.userData.context;return i&&(i.focused=!0,this._lastFocused=i,i.component?.trigger("click",n)),i}handleHover(t,e,n){const r=this.getObjectByRaycast(t,e),i=r?.userData.context;i!==this._lastHovered&&(this._lastHovered&&(this._lastHovered.component?.trigger("mouseleave",n),this._lastHovered=void 0),i&&(this._lastHovered=i,this._lastHovered.component?.trigger("mouseenter",n)))}destroy(){this._lastFocused=void 0,this._lastHovered=void 0}}class Zh{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}setup(t,e,n){this.destroy(),this._scene=n;const r=document.createElement("div");r.style.cssText="position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none",r.setPointerCapture=()=>{},r.releasePointerCapture=()=>{},e.appendChild(r),this._proxyElement=r,this._controls=new M(t,r),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;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)}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)}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}}class Jh{constructor(){this._mouseDownAltKey=!1}captureAltKey(t){this._mouseDownAltKey=t}setupCallbacks(t,e,n,r){t.onDraggingChanged=r=>{e.setEnabled(!r);const i=n();i&&(r?this._onDragStart(t,i):this._onDragEnd(t,i),i.app?.commander?.execute(null),i.invalidate())},t.onObjectChange=e=>{this._syncFromGizmo(t,e),n()?.invalidate()},t.onAttachChanged=t=>{r?.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),"scale"===t.mode&&this._captureScalePreDrag(t)}_performAltDragDuplicate(t){const e=t.root?.selected||[];if(0===e.length||!t.root)return;const n=t.root,r=[];for(const t of e){const e=t.parent,i=new Map,s=fl(t,t=>{const e=n.getNewRefid();return void 0!==t&&i.set(t,e),e});s.replaceRefids(i),e.addComponent(s),r.push({component:s,to_container:e})}this._altDragDuplicates=r}_captureMultiSelectState(t,e){const n=t.attached;if(n)if("translate"===t.mode){const t=new Map,r=n.position;for(let n=1;n<e.length;n++){const i=e[n]._realObject;i?.object3d&&t.set(i,i.object3d.position.clone().sub(r))}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 r=e[n]._realObject;r?.object3d&&t.set(r,r.object3d.rotation.clone())}this._multiSelectInitialRotations=t}else if("scale"===t.mode){const t=new Map;for(let n=1;n<e.length;n++){const r=e[n],i=r._realObject;if(i?.object3d){const{left:e,top:n,width:s,height:o}=r.bounds,{zPos:a=0}=r.state,c=r.state.depth;t.set(i,{left:e,top:n,width:s,height:o,depth:c,zPos:a,scaleX:i.object3d.scale.x,scaleY:i.object3d.scale.y,scaleZ:i.object3d.scale.z})}}this._multiSelectPreDragDimensions=t}}_captureScalePreDrag(t){const e=t.attached,n=e?.userData.context;if(!n||!e)return;const{left:r,top:i,width:s,height:o}=n.component.bounds,{zPos:a=0}=n.component.state,c=n.component.state.depth;this._preDragDimension={left:r,top:i,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===c?n.effectiveDepth:void 0}_onDragEnd(t,e){if(this._altDragDuplicates&&this._altDragDuplicates.length>0&&(e.app?.commander.execute(new hl({changes:this._altDragDuplicates})),this._altDragDuplicates=void 0),this._multiSelectOffsets=void 0,this._gizmoInitialRotation=void 0,this._multiSelectInitialRotations=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()}this._preDragDimension=void 0,this._preDragScale=void 0,this._preDragEffectiveDepth=void 0,this._multiSelectPreDragDimensions=void 0}_syncFromGizmo(t,e){const n=e.userData.context;if(n)if("scale"===t.mode&&this._preDragDimension&&this._preDragScale){if(this._syncDimensionFromGizmo(n,e),this._multiSelectPreDragDimensions&&this._preDragScale){const t=e.scale.x/this._preDragScale.x,n=e.scale.y/this._preDragScale.y,r=e.scale.z/this._preDragScale.z;for(const[e,i]of this._multiSelectPreDragDimensions){const s=i.width*t,o=i.height*r,a={left:i.left+(i.width-s)/2,top:i.top+(i.height-o)/2,width:s,height:o};if(void 0!==i.depth){const t=i.depth*n;a.depth=t,a.zPos=i.zPos+(i.depth-t)/2}e.applyDimensionFromGizmo(a)}}}else{if(n.syncFromObject3D(),"translate"===t.mode&&this._applyGroundSnap(e,n),this._multiSelectOffsets){const n=e.position;for(const[e,r]of this._multiSelectOffsets)e.object3d&&(e.object3d.position.copy(n).add(r),"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,r=e.rotation.z-this._gizmoInitialRotation.z;for(const[e,i]of this._multiSelectInitialRotations)e.object3d&&(e.object3d.rotation.set(i.x+t,i.y+n,i.z+r),e.syncFromObject3D())}}}_applyGroundSnap(t,e){const n=e.effectiveDepth/2,r=t.position.y-n,i=Math.abs(r);if(i<2)t.position.y=n,e.syncFromObject3D();else if(i<10){const s=(i-2)/8,o=1-s*s;t.position.y=n+r*(1-o),e.syncFromObject3D()}}_syncDimensionFromGizmo(t,e){const n=this._preDragDimension,r=this._preDragScale,i=n.width*(e.scale.x/r.x),s=n.height*(e.scale.z/r.z),o={left:n.left+(n.width-i)/2,top:n.top+(n.height-s)/2,width:i,height:s};if(void 0!==n.depth){const t=n.depth*(e.scale.y/r.y);o.depth=t,o.zPos=n.zPos+(n.depth-t)/2}t.applyDimensionFromGizmo(o)}}class td{constructor(){this._mouseIsDown=!1,this._isDragging=!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 r={mousedown:t=>this._onMouseDown(t),mousemove:t=>this._onMouseMove(t),wheel:t=>{t.stopPropagation(),this._delegate.handleWheel(t)},dblclick:t=>{t.stopPropagation(),this._delegate.handleDblClick(t)},contextmenu:t=>{t.preventDefault()},touchstart:t=>{t.stopPropagation(),this._delegate.handleTouchStart(t)},touchmove:t=>{t.stopPropagation(),this._delegate.handleTouchMove(t)},touchend:t=>{t.stopPropagation(),this._delegate.handleTouchEnd(t)},keydown:t=>{this._delegate.handleKeyDown(t)&&t.stopPropagation()},keyup:t=>{(this._delegate.handleKeyUp?.(t)??!1)&&t.stopPropagation()}};t.addEventListener("mousedown",r.mousedown),t.addEventListener("mousemove",r.mousemove),t.addEventListener("wheel",r.wheel),t.addEventListener("dblclick",r.dblclick),t.addEventListener("contextmenu",r.contextmenu),t.addEventListener("touchstart",r.touchstart,{passive:!1}),t.addEventListener("touchmove",r.touchmove,{passive:!1}),t.addEventListener("touchend",r.touchend),t.addEventListener("keydown",r.keydown),t.addEventListener("keyup",r.keyup),this._boundHandlers=r}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 r=n.getBoundingClientRect();return{x:t-r.left,y:e-r.top}}updateMouseNDCFromClient(t,e){const n=this._hostElement?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const r=t-n.left,i=e-n.top;this._event.updateMouseNDC(r,i,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<td.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 r=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:r.x,offsetY:r.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&&!t.metaKey&&!t.ctrlKey){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,r=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+r*r<td.DRAG_THRESHOLD)return;this._isDragging=!0,this._delegate.handleBoxSelectionStart?.(e.x,e.y)}const i=this.clientToElementCoords(t.clientX,t.clientY);this._delegate.handleBoxSelectionUpdate?.(i.x,i.y)},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging)this._delegate.handleBoxSelectionEnd?.(t.shiftKey);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)}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,r=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+r*r<td.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})}const i=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:i.x,offsetY:i.y,altKey:t.altKey})},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)}}td.DRAG_THRESHOLD=16;class ed{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 r=new e.Raycaster;r.setFromCamera(this._event.mouse,n);const i=new e.Vector3;return r.ray.intersectPlane(this._groundPlane,i)}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 r=new e.MeshBasicMaterial({color:48340,opacity:.6,transparent:!0,side:e.DoubleSide,depthTest:!1});this._placementIndicator=new e.Mesh(n,r),this._placementIndicator.renderOrder=999,t.add(this._placementIndicator)}const n=this._pendingModels?.[0],r=n?.rx??n?.width??50,i=n?.ry??n?.height??50;this._placementIndicator.scale.set(r,1,i),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 nd={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 rd(t,n,r,i,s,o=new e.Vector3){const a=t*t,c=a*t;return o.set(.5*(2*r.x+(-n.x+i.x)*t+(2*n.x-5*r.x+4*i.x-s.x)*a+(-n.x+3*r.x-3*i.x+s.x)*c),.5*(2*r.y+(-n.y+i.y)*t+(2*n.y-5*r.y+4*i.y-s.y)*a+(-n.y+3*r.y-3*i.y+s.y)*c),.5*(2*r.z+(-n.z+i.z)*t+(2*n.z-5*r.z+4*i.z-s.z)*a+(-n.z+3*r.z-3*i.z+s.z)*c))}class id{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,r,i=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=r.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),x=nd[o.easing??"ease-in-out"];return this._runAnimation(i,x,t=>{s?rd(t,s.prevPos,a,l,s.nextPos,n.position):n.position.lerpVectors(a,l,t);const i=b.clone().slerp(v,t),o=new e.Vector3(0,0,-1).applyQuaternion(i),c=u+(p-u)*t,h=n.position.clone().add(o.multiplyScalar(c));r.restoreTarget(h)}),!0}_animatePathSegment(t,e,n,r,i,s){const o=nd[r];this._runAnimation(n,o,n=>{const r=t+(e-t)*n,o=this.evaluatePath(r<=1?r:r-1);o&&(i.position.copy(o.position),s.restoreTarget(o.target))})}_runAnimation(t,e,n){this.stopAnimation(),this._animating=!0,this._animationProgress=0;const r=performance.now(),i=()=>{const s=performance.now()-r,o=Math.min(s/t,1),a=e(o);this._animationProgress=a,n(a),this._onInvalidate?.(),o<1?this._animationId=requestAnimationFrame(i):(this._animating=!1,this._animationId=void 0,this._onAnimationComplete?.())};this._animationId=requestAnimationFrame(i)}_initFromProgress(t,e){const n=t*e,r=Math.min(Math.floor(n),e-1);this._playStartOffset=n-r,this._playIndex=(r+1)%e}startPlay(t,n,r=2e3,i=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??r,h=s?.transitionDuration??i;if(l>=0){const e=l;let r=this._playIndex/a.length;r<=e&&(r+=1),l=-1;const i=this._playStartOffset,c=Math.max(Math.round(h*(1-i)),100);return u(o),void this._animatePathSegment(e,r,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,r,i){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:i(a.position)};const c=t[(this._playIndex-2+s)%s],l=this._slots[c];return l?{prevPos:i(l.position),nextPos:i(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 r=n.length,i=Math.max(0,Math.min(1,t)),s=t=>{const i=this._slots[n[(t%r+r)%r]];return i?new e.Vector3(i.position.x,i.position.y,i.position.z):new e.Vector3},o=t=>{const i=this._slots[n[(t%r+r)%r]];return i?new e.Vector3(i.target.x,i.target.y,i.target.z):new e.Vector3};if(2===r){const t=i<.5?2*i:2*(1-i);return{position:s(0).lerp(s(1),t),target:o(0).lerp(o(1),t)}}const a=i*r,c=Math.min(Math.floor(a),r-1),l=a-c,h=rd(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),x=b.lengthSq()>1e-4?b.normalize():new e.Vector3(0,0,-1),_=v.lengthSq()>1e-4?v.normalize():x.clone(),w=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),x),M=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),_),S=w.clone().slerp(M,l),A=new e.Vector3(0,0,-1).applyQuaternion(S),k=m+(y-m)*l,E=h.clone().add(A.multiplyScalar(k));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 sd{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.style.position="relative",this._hostElement.appendChild(this._overlay),this._updateOverlay())}updateSelection(t,e){this._active&&(this._currentX=t,this._currentY=e,this._updateOverlay())}endSelection(t,n,r){if(!this._active||!this._hostElement)return this.cancelSelection(),[];const i=this._hostElement.getBoundingClientRect(),s=i.width,o=i.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 r){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),r=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=`${r}px`}}class od{constructor(){this.sceneManager=new Uh,this.cameraManager=new Wh,this.rendererManager=new Xh,this.lightManager=new qh,this.controlsManager=new $h,this.eventManager=new Qh,this.gizmoManager=new Zh,this.interactionManager=new td,this.placementManager=new ed,this.gizmoOperationManager=new Jh,this.bookmarkManager=new id,this.boxSelectionManager=new sd,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 t=n[0]._realObject;t?.object3d&&this.gizmoManager.attach(t.object3d),this._host?.invalidate()}}get gizmoMode(){return this.gizmoManager.mode}init(t,e){this.interactionManager.cleanup(),this._cleanupEventHandlers(),this._host=t,this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this.sceneManager.scene&&this.destroy(),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:r}=e.bounds;n=Math.abs(n)||1,r=Math.abs(r)||1;const{fov:i=45,near:s=.1,far:o=2e4,antialias:a=!0,precision:c="highp",cameraX:l,cameraY:h,cameraZ:d,exposure:u=1}=e.state,p=e.components||[],f=t?.lightingConfig??{hemisphere:{skyColor:16777215,groundColor:4473924,intensity:.4},directional:{color:16777215,intensity:1,attachToCamera:!0}},g=t?.css3DSceneAttribute??"three-container:css3d-renderer",m=this.sceneManager.setup(),y=this.cameraManager.setup(n,r,{fov:i,near:s,far:o,cameraX:l,cameraY:h,cameraZ:d});this.cameraManager.addToScene(m);const b=e.app?.postprocessing;if(this.rendererManager.setupWebGL(n,r,{precision:c,antialias:a,exposure:u,postprocessing:b})){if(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(),this.sceneManager.addFloor(e),this.sceneManager.setSky(e.state.sky,e.state.skyColor),!1!==e.app.postprocessing){const t=this.gizmoManager.controls?.getHelper();this.rendererManager.setupComposer(m,y,n,r,t)}else this.rendererManager.setDirectRenderTargets(m,y);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,()=>this._host,{onAttachChanged:t=>this.onGizmoAttachChanged?.(t)})}createObjects(t){for(const e of t)this.addObject(e)}addObject(t){if(!t._realObject){try{const{width:e,height:n}=t.bounds;if(!e||!n)return;if(t.isHTMLElement()&&!t.element)return;const r=Nh(t);if(r){if(t._realObject=r,r.update(),r.updateTransform(),r instanceof Lh)this.rendererManager.css3DScene.add(r.object3d);else{const e=t.parent?._realObject?.object3d;e&&e!==this.sceneManager.scene?e.add(r.object3d):this.sceneManager.scene.add(r.object3d)}const e=this._host?.root?.selected;e&&e.length>0&&e[0]===t&&r.object3d&&this.gizmoManager.attached&&this.gizmoManager.attach(r.object3d)}}catch(t){Wr(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.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 Lh?this.rendererManager.css3DScene.remove(n):n.removeFromParent()),e.dispose?.(),t._realObject=void 0}catch(t){Wr(t)}}resize(t,e,n=!1){const r=this._host;if(!r)return;if(void 0===t||void 0===e){const n=r.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 i=t,s=e;clearTimeout(this._resizeDebouncer),this._resizeDebouncer=window.setTimeout(()=>{this._resizeDebouncer=void 0,this._applyResize(i,s)},100)}_applyResize(t,n){this.cameraManager.updateAspect(t,n),this.rendererManager.resize(t,n);const r=new e.Vector2(t,n);for(const t of this._arrows.values())t.traverse(t=>{t instanceof u&&t.material.resolution.copy(r)});this._initialized&&(this.renderThreeD(),this.renderCSS3D())}animate(){if(!this._initialized||!this.controlsManager.isActive)return;this.sceneManager.updateAnimation();const t=this._host?.components||[];for(const e of t)e._animation?.started&&e._realObject&&e._realObject.syncAnimationDelta();this.controlsManager.update(),this.renderThreeD()}renderThreeD(){this._initialized&&this.rendererManager.render()}setCameraView(t,e){const n=this._host;if(!n)return;const{width:r,height:i}=n.bounds,s=n.element,o=s?.clientWidth||r,a=s?.clientHeight||i;let c;c="perspective"===t?this.cameraManager.restorePerspective():this.cameraManager.setOrthoView(t,r,i,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;t?.element&&t.element.appendChild(this.css3DRenderer.domElement)}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.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()}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(),this._redrawHandler=void 0,this._onComponentAdd=void 0,this._onComponentRemove=void 0,this._onSelectionChanged=void 0,this._onAddStart=void 0,this._onAddStop=void 0,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()),this.controlsManager.setup(this.cameraManager.camera,t),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.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,r=t.bounds.height||600,i=e.x+n/2,s=e.z+r/2;gl.call(t.root,this.placementManager.pendingModels,{cx:i,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)},handleBoxSelectionEnd:t=>{this.controlsManager.setEnabled(!0),this._host?.element&&(this._host.element.style.cursor="");const e=this.cameraManager.activeCamera,n=this.sceneManager.scene,r=this._host?.components||[];if(e&&n){const i=this.boxSelectionManager.endSelection(e,n,r);if(i.length>0&&this._host?.root)if(t){const t=(this._host.root.selected||[]).slice();for(const e of i)t.includes(e)||t.push(e);this._host.root.selected=t}else this._host.root.selected=i}else this.boxSelectionManager.cancelSelection()}}}_handleClickAt(t){const n=this._host,r=this.cameraManager.activeCamera;if(!r||!this.sceneManager.scene)return;if(this._pathMarkers&&this._pathMarkers.children.length>0){const t=new e.Raycaster,n=this.eventManager.mouse;t.setFromCamera(n,r);const i=t.intersectObjects(this._pathMarkers.children,!0);if(i.length>0){let t=i[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)}}const i=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),i)return;const s=this.eventManager.handleClick(r,this.sceneManager.scene,t);if(n.app?.isEditMode&&n.root){const e=n.app.mode;if(4===e||5===e){if(s?.component)n.root.trigger("pasteapply",s.component);else{const t=4===e?"stylepastestop":"databindpastestop";n.root.trigger(t)}return}if(s?.component)if(t.shiftKey){const t=(n.root.selected||[]).slice(),e=t.indexOf(s.component);-1===e?t.push(s.component):t.splice(e,1),n.root.selected=t}else n.root.selected=[s.component];else t.shiftKey||(n.root.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?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const r=t-n.left,i=e-n.top;this.eventManager.updateMouseNDC(r,i,0,0,n.width,n.height)}_updateMouseNDC(t){this._updateMouseNDCFromClient(t.clientX,t.clientY)}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 r=this.eventManager.handleClick(n,this.sceneManager.scene,t),i=this._host;if(i?.app?.isEditMode&&i.root)if(r?.component)if(t.shiftKey){const t=(i.root.selected||[]).slice(),e=t.indexOf(r.component);-1===e?t.push(r.component):t.splice(e,1),i.root.selected=t}else i.root.selected=[r.component];else t.shiftKey||(i.root.selected=[]);return 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){if("perspective"!==this.cameraManager.activeView){const e=t.deltaY>0?.9:1.1,n=this._host?.element;let r=0,i=0;if(n){const e=n.getBoundingClientRect();r=(t.clientX-e.left)/e.width*2-1,i=-(t.clientY-e.top)/e.height*2+1}this.controlsManager.zoomOrthoAtCursor(e,r,i),this.renderThreeD()}else{const e=Math.pow(.999,-t.deltaY),n=this._host?.element;let r=0,i=0;if(n){const e=n.getBoundingClientRect();r=(t.clientX-e.left)/e.width*2-1,i=-(t.clientY-e.top)/e.height*2+1}this.controlsManager.dollyAtCursor(e,r,i),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){const t=this.eventManager.getObjectByRaycast(n,this.sceneManager.scene),e=t?.userData?.context?.component;if(e?.hasTextProperty)return Yh(e,this.rendererManager,()=>{this.renderThreeD(),this.renderCSS3D()}),!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){if(t.isComposing||229===t.keyCode)return!1;if(this.controlsManager.isActive){if("Escape"===t.key&&this.placementManager.isActive&&this._host?.root)return this._host.root.trigger("addstop"),t.stopPropagation(),!0;if("Escape"===t.code){const t=this._host?.app,e=this._host?.root;if(t&&4===t.mode)return e?.trigger("stylepastestop"),!0;if(t&&5===t.mode)return e?.trigger("databindpastestop"),!0}if(this._host?.app?.isEditMode){const e=this._host.root;if(t.metaKey||t.ctrlKey)switch(t.code){case"KeyZ":{const n=this._host?.app?.commander,r=(e?.selected||[]).filter(t=>t!==this._host).map(t=>t.state?.id).filter(Boolean);if(t.shiftKey?n?.redo():n?.undo(),e&&r.length>0){const t=r.map(t=>e.findById(t)).filter(Boolean);t.length>0&&(e.selected=t)}t.preventDefault();break}case"KeyC":e&&(this._clipboard=Al.call(e)),t.preventDefault();break;case"KeyX":e&&(this._clipboard=kl.call(e)),t.preventDefault();break;case"KeyV":e&&this._clipboard&&El.call(e,this._clipboard),t.preventDefault();break;case"KeyD":e&&(this._clipboard=Al.call(e),this._clipboard&&El.call(e,this._clipboard)),t.preventDefault();break;default:return!1}if("Enter"===t.code||"NumpadEnter"===t.code){const n=e?.selected;if(1===n?.length&&n[0].hasTextProperty)return Yh(n[0],this.rendererManager,()=>{this.renderThreeD(),this.renderCSS3D()}),t.preventDefault(),!0}switch(t.code){case"KeyW":this.setGizmoMode("translate");break;case"KeyE":this.setGizmoMode("rotate");break;case"KeyR":this.setGizmoMode("scale");break;case"Delete":case"Backspace":e&&yl.call(e);break;case"Escape":this.gizmoManager.detach(),e&&(e.selected=[])}const n=e?.selected;if(n&&n.length>0){const e=t.shiftKey?this._host.MPP||10:1;let r;switch(t.code){case"ArrowLeft":r={x:-e,y:0};break;case"ArrowRight":r={x:e,y:0};break;case"ArrowUp":r={x:0,y:-e};break;case"ArrowDown":r={x:0,y:e}}if(r)return Kc.around(this._host.app.commander,()=>{n.forEach(t=>{t.stuck||t.move(r,!1)})}),t.preventDefault(),t.stopPropagation(),!0}}if(("AltLeft"===t.code||"AltRight"===t.code)&&!t.repeat&&this._host?.app?.isEditMode)return this._host?.element&&(this._host.element.style.cursor="grab"),!0;if(("ShiftLeft"===t.code||"ShiftRight"===t.code)&&!t.repeat&&this._host?.app?.isEditMode)return this._host?.element&&(this._host.element.style.cursor="crosshair"),!0;if(!(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)){switch(t.code){case"KeyQ":case"Digit0":return this._host?.set?.("threed",!1),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}if("KeyS"===t.code)return this.onShortcutHelpToggle?.(),t.preventDefault(),!0;if("KeyB"===t.code)return this.onBookmarkNavToggle?.(),t.preventDefault(),!0;if("KeyP"===t.code&&!this._host?.app?.isEditMode)return this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.restartPlay(),t.preventDefault(),!0;if("Space"===t.code&&this._host?.app?.isEditMode)return 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;if("Space"===t.code&&!this._host?.app?.isEditMode)return this.bookmarkManager.isOrbitRotating||this.bookmarkManager.isOrbitPaused?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):(this.bookmarkManager.isPlaying||this.bookmarkManager.lastPlayProgress>=0)&&this.togglePlay(),t.preventDefault(),!0;if("KeyO"===t.code&&!this._host?.app?.isEditMode)return this.bookmarkManager.resetPlay(),this.bookmarkManager.toggleOrbitRotation(this.controlsManager),t.preventDefault(),!0}return!t.shiftKey||t.ctrlKey||t.metaKey||t.altKey||"KeyB"!==t.code||!this._host?.app?.isEditMode?(this.controlsManager.onKeyDown(t),t.stopPropagation(),!0):(this.onBookmarkEditToggle?.(),t.preventDefault(),!0)}return!1}_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:r}=t.bounds,i=Math.floor(Math.min(n,r))||1;return{view:this.cameraManager.activeView,cameraX:e.position.x/(n||1),cameraY:e.position.z/(r||1),cameraZ:e.position.y/i}}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,r={view:t};return e&&(r.perspPosition={x:e.position.x,y:e.position.y,z:e.position.z}),r.orbitTarget={x:n.x,y:n.y,z:n.z},r}captureViewportInfo(){const t=this.cameraManager.activeCamera,e=this.controlsManager.target.clone();let n=0,r=0;if(t?.fov){r=2*t.position.distanceTo(e)*Math.tan(t.fov*Math.PI/180/2),n=r*(t.aspect||1)}return{target:e,visibleWidth:n,visibleHeight:r}}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 r=this.controlsManager.target,i=n.position;let s=r.x,o=r.y,a=r.z;if(i.distanceTo(r)<1){const t=new e.Vector3(0,0,-1).applyQuaternion(n.quaternion);s=i.x+1*t.x,o=i.y+1*t.y,a=i.z+1*t.z}const c={position:{x:i.x,y:i.y,z:i.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,r,i,s){const o=this.cameraManager.activeCamera;if(!o?.position)return;const a=(o.fov||45)*Math.PI/180,c=o.aspect||1,l=i/2/Math.tan(a/2),h=r/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 r=this.cameraManager.activeCamera;if(!r)return;const i=new e.Vector3,s=t._realObject;if(s?.object3d)s.object3d.getWorldPosition(i);else{const{x:e=0,y:n=0}=t.center,{width:r=0,height:s=0}=t.parent?.bounds??{};i.set(e-r/2,0,n-s/2)}const o=this.controlsManager.target,a=r.position.clone().sub(o),c=i.clone().add(a);if(!n)return r.position.copy(c),this.controlsManager.restoreTarget(i),void this._host?.invalidate();const l=r.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;r.position.lerpVectors(l,c,n);const s=h.clone().lerp(i,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(n.length<2)return;const r=[];for(const t of n){const n=this.bookmarkManager.getSlot(t);n&&r.push(new e.Vector3(n.position.x,n.position.y,n.position.z))}let i=0;for(let t=1;t<r.length;t++)i+=r[t].distanceTo(r[t-1]);const s=i/(r.length-1),o=.08*s,a=r.length>=3?new e.CatmullRomCurve3(r,!0,"centripetal").getPoints(30*r.length):r,c=(new e.BufferGeometry).setFromPoints(a),l=new e.LineDashedMaterial({color:4890367,dashSize:.06*s,gapSize:.03*s,opacity:.5,transparent:!0,depthTest:!1});this._pathLine=new e.Line(c,l),this._pathLine.computeLineDistances(),this._pathLine.renderOrder=9999,t.add(this._pathLine),this._pathMarkers=new e.Group,this._pathMarkers.renderOrder=9999;const h=new e.MeshBasicMaterial({color:4890367,opacity:.6,transparent:!0,depthTest:!1}),d=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 r=new e.Vector3(n.position.x,n.position.y,n.position.z),i=new e.Vector3(n.target.x,n.target.y,n.target.z),s=(new e.Vector3).subVectors(i,r).normalize(),a=new e.Group;a.position.copy(r);const c=(new e.Matrix4).lookAt(new e.Vector3(0,0,0),s,new e.Vector3(0,1,0));a.quaternion.setFromRotationMatrix(c);const l=.2*o,u=new e.BoxGeometry(1.2*l,.8*l,l),p=new e.Mesh(u,h);p.renderOrder=9999,a.add(p);const f=Math.max(.06*r.distanceTo(i),.5*l),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 x=new e.Mesh(y,d);x.position.z=.5*-l,x.renderOrder=9999,a.add(x);const _=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(_,3));const M=new e.LineSegments(w,new e.LineBasicMaterial({color:4890367,opacity:.5,transparent:!0,depthTest:!1}));M.position.z=.5*-l,M.renderOrder=9999,a.add(M),a.userData.bookmarkSlotIndex=t,this._pathMarkers.add(a)}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("fov")||t.hasOwnProperty("near")||t.hasOwnProperty("far")){const t=this._host;if(t){const{near:e,far:n,fov:r}=t.state;this.cameraManager.updateProperties({near:e,far:n,fov:r}),this.controlsManager.markCameraChanged()}}let e=!1;if(t.hasOwnProperty("hemiIntensity")&&(this.lightManager.updateHemisphere({intensity:t.hemiIntensity}),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}(t.hasOwnProperty("dirLightColor")||t.hasOwnProperty("dirLightIntensity"))&&(this.lightManager.updateDirectional({color:t.dirLightColor,intensity:t.dirLightIntensity}),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())}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(dh()),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,r,i={}){this.removeArrow(t);const s=n._realObject,o=r._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=bh(a,c,i,new e.Vector2(l.width,l.height));h.name=`arrow-${t}`,h.userData._arrowStyle=i,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 u)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 r=this._getArrowStyle(t);r&&this.addArrow(t,e,n,r)}_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?this.gizmoManager.attached&&this.gizmoManager.attach(t.object3d):this.gizmoManager.detach()}else this.gizmoManager.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()}}lc.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 ad={x:1,y:1},cd={x:0,y:0},ld='<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>',hd='<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>',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="M4 14l2-10h8l2 10z"/>\n <path d="M6 4h8" stroke-width="2"/>\n</svg>',ud='<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>',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="M6 4l10 2v8l-10 2z"/>\n <path d="M16 6v8" stroke-width="2"/>\n</svg>',fd='<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>',gd={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 md extends Dc{get nature(){return gd}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,r){this._threeCapability?.addArrow(t,e,n,r)}removeArrow3D(t){this._threeCapability?.removeArrow(t)}clearArrows3D(){this._threeCapability?.clearArrows()}_buildLightingConfig(){const t=this.state,e={hemisphere:{skyColor:16777215,groundColor:4473924,intensity:t.hemiIntensity??1}};return!1!==t.dirLightEnabled&&(e.directional={color:t.dirLightColor||"#ffffff",intensity:t.dirLightIntensity??.8,attachToCamera:!0,castShadow:!1!==t.dirShadowEnabled,shadowMapSize:t.dirShadowMapSize??2048,shadowBias:t.dirShadowBias??-5e-4}),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 od,this._threeCapability.init(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),this._hide2DLayers();const e=zs.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)this._initCameraFrom2DViewport();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 r=this.root;r?.selected?.length>0&&this._threeCapability._handleSelectionChanged(r.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(";"),r=(t,e)=>{const r=document.createElement("div");return r.innerHTML=t,r.title=e,r.style.cssText=n,this._applyButtonStyle(r,!1),r.addEventListener("mouseenter",()=>{r.dataset.active||(r.style.background="rgba(255,255,255,0.1)")}),r.addEventListener("mouseleave",()=>{this._applyButtonStyle(r,!!r.dataset.active)}),r},i=()=>{const t=document.createElement("div");return t.style.cssText="height:1px;margin:3px 4px;background:rgba(255,255,255,0.1)",t},s=r(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.set("threed",!this.model.threed)}),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(i());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:ld,title:"Perspective"},{view:"top",icon:hd,title:"Top"},{view:"front",icon:dd,title:"Front"},{view:"back",icon:ud,title:"Back"},{view:"right",icon:pd,title:"Right"},{view:"left",icon:fd,title:"Left"}],h=[];for(const{view:t,icon:e,title:n}of l){const i=r(e,n);i.dataset.view=t,t===c&&(this._applyButtonStyle(i,!0),i.dataset.active="1"),i.addEventListener("click",()=>{this._threeCapability?.setCameraView(t)}),h.push(i),a.appendChild(i)}a.appendChild(i());const d=r('<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.onShortcutHelpToggle=()=>this._toggleShortcutHelp(),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,r=0,i=0;const s=s=>{const o=s.clientX-e,a=s.clientY-n;t.style.left=r+o+"px",t.style.top=i+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();r=h.left-d.left,i=h.top-d.top,t.style.left=r+"px",t.style.top=i+"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)})}_toggleShortcutHelp(){if("shortcuts"===this._floatingPopup?.dataset.popupType)return void this._closeFloatingPopup();const t=!!this.app?.isEditMode,e=document.createElement("div");e.dataset.popupType="shortcuts",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 r=document.createElement("div");r.textContent="Keyboard Shortcuts",r.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:12px",e.appendChild(r);const i=document.createElement("div");i.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:0 24px",e.appendChild(i);const s=[{label:"Camera",items:[{key:"1",desc:"Perspective",icon:ld},{key:"2",desc:"Top",icon:hd},{key:"3",desc:"Front",icon:dd},{key:"4",desc:"Back",icon:ud},{key:"5",desc:"Right",icon:pd},{key:"6",desc:"Left",icon:fd},{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:"S",desc:"This help"}]}].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 r 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=r.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 r.items){const n=document.createElement("div");n.style.cssText="display:flex;justify-content:space-between;align-items:center;padding:2px 0;gap:12px";const r=document.createElement("span");r.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",r.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",r.appendChild(t)}}const i=document.createElement("span");if(i.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",i.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",i.appendChild(e)}n.appendChild(r),n.appendChild(i),e.appendChild(n)}}i.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,r=!!this.app?.isEditMode,i=document.createElement("div");i.dataset.popupType=t,i.tabIndex=-1,i.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)"}),i.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",i.appendChild(o);const a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:2px",i.appendChild(a);const c=e.bookmarkManager,l=()=>{r&&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,r=document.createElement("canvas");r.width=e*n,r.height=e*n,r.style.cssText="width:28px;height:28px;flex-shrink:0;border-radius:50%;background:rgba(0,0,0,0.3)";const i=r.getContext("2d");i.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;i.strokeStyle="rgba(255,255,255,0.12)",i.lineWidth=1,i.beginPath(),i.arc(s,o,a,0,2*Math.PI),i.stroke(),i.strokeStyle="rgba(255,255,255,0.06)",i.beginPath(),i.moveTo(s,2),i.lineTo(s,26),i.moveTo(2,o),i.lineTo(26,o),i.stroke(),i.fillStyle="rgba(255,255,255,0.25)",i.beginPath(),i.arc(s,o,1.5,0,2*Math.PI),i.fill(),i.strokeStyle=`rgba(74,158,255,${.2+.2*p})`,i.lineWidth=1,i.beginPath(),i.moveTo(y,b),i.lineTo(s,o),i.stroke();const v=.6+.4*p;i.fillStyle=`rgba(74,158,255,${v})`,i.beginPath(),i.arc(y,b,3,0,2*Math.PI),i.fill();const x=Math.atan2(g,f),_=Math.PI/8;return i.fillStyle="rgba(74,158,255,0.08)",i.beginPath(),i.moveTo(y,b),i.arc(y,b,.6*a,x+Math.PI-_,x+Math.PI+_),i.closePath(),i.fill(),r},u=()=>{const t=e.getCameraWorldState();if(!t)return-1;const n=.01;for(let e=1;e<=9;e++){const r=c.getSlot(e);if(r&&(Math.abs(t.position.x-r.position.x)<n&&Math.abs(t.position.y-r.position.y)<n&&Math.abs(t.position.z-r.position.z)<n&&Math.abs(t.target.x-r.target.x)<n&&Math.abs(t.target.y-r.target.y)<n&&Math.abs(t.target.z-r.target.z)<n))return e}return-1};let p,f,g=-1;const m=()=>{a.innerHTML="";let t=!1;const r=u(),i=Array.from({length:9},(t,e)=>e+1);for(const s of i){const i=c.getSlot(s),o=!!i,u=s===r;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&&i){const t=d(i);t.style.pointerEvents="none",p.appendChild(t)}const t=document.createElement("span");t.textContent=i?.name||"noname",t.style.cssText=`flex:1;color:${i?.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;${i?.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,r=o?"color:rgba(255,255,255,0.3)":"color:rgba(255,255,255,0.12)";t.style.cssText=`width:16px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;user-select:none;${r}${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&&i&&p.appendChild(d(i)),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=i?.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 r=document.createElement("button");r.textContent="⋮",r.title="Playlist settings",r.style.cssText=h+";color:rgba(255,255,255,0.35);font-size:14px",r.addEventListener("mouseenter",()=>{r.style.background="rgba(255,255,255,0.08)"}),r.addEventListener("mouseleave",()=>{r.style.background="transparent"}),u.appendChild(r)}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 r=t=>{const e=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&n.parentNode.removeChild(n);let r=null;for(const n of e){if(n===y)continue;const e=n.getBoundingClientRect();if(t.clientY<e.top+e.height/2){r=n;break}}if(r)a.insertBefore(n,r);else{const t=e[e.length-1];t&&t.after(n)}},i=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",r),t.removeEventListener("pointerup",i),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",r),t.addEventListener("pointerup",i)})}if(!n&&o&&i){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",r="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=r+";width:55px";const d=document.createElement("input");d.type="number",d.min="0",d.step="500",d.value=String(i.holdDuration??2e3),d.style.cssText=n;const u=document.createElement("span");u.textContent="ms",u.style.cssText=r,d.addEventListener("change",()=>{const t=parseInt(d.value);i.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=r+";width:55px";const b=document.createElement("input");b.type="number",b.min="0",b.step="200",b.value=String(i.transitionDuration??1200),b.style.cssText=n;const v=document.createElement("span");v.textContent="ms",v.style.cssText=r,b.addEventListener("change",()=>{const t=parseInt(b.value);i.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 x=document.createElement("div");x.style.cssText=o;const _=document.createElement("span");_.textContent="Easing",_.style.cssText=r+";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",(i.easing??"ease-in-out")===t&&(e.selected=!0),w.appendChild(e)}w.addEventListener("change",()=>{i.easing="ease-in-out"===w.value?void 0:w.value,l()}),x.appendChild(_),x.appendChild(w),t.appendChild(x);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=r+";width:55px";const A=document.createElement("input");A.type="checkbox",A.checked=!!i.excludeFromPlay,A.style.cssText="accent-color:#4a9eff;cursor:pointer",A.addEventListener("change",()=>{i.excludeFromPlay=A.checked||void 0,l()}),M.appendChild(S),M.appendChild(A),t.appendChild(M),y.appendChild(t);const k=p.querySelector("button:last-child");k&&(e&&(k.style.color="#4a9eff"),k.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",k.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 r=document.createElement("button");r.textContent="▶",r.title="Play / Stop",r.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",r.addEventListener("mouseenter",()=>{r.style.background="rgba(74,158,255,0.15)",r.style.color="#4a9eff"}),r.addEventListener("mouseleave",()=>{r.style.background="rgba(255,255,255,0.06)",r.style.color=c.isPlaying?"#4a9eff":"rgba(255,255,255,0.5)"}),r.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),i.addEventListener("keydown",t=>{if("Space"===t.code&&"none"!==p.style.display){t.preventDefault(),t.stopPropagation();const r=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(r),a()}}),t.appendChild(n),t.appendChild(r),p.appendChild(t),i.appendChild(p);const a=()=>{const t=c.isPlaying;r.textContent=t?"⏹":"▶",r.style.color=t?"#4a9eff":"rgba(255,255,255,0.5)"};let l=-1;const h=()=>{if(this._floatingPopup===i){if(c.isPlaying){const t=c.playProgress;n.value=String(Math.round(1e3*t)),l=-1}else{"⏹"===r.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";r&&(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()})),i.appendChild(t)}const y=e.onBookmarkChanged;e.onBookmarkChanged=()=>{y?.(),this._floatingPopup===i&&(m(),v=-2,n||e.showBookmarkPath())},this._showFloatingPopup(i,!0),n||e.showBookmarkPath();let b,v=u();const x=()=>{if(this._floatingPopup!==i)return;const t=u();if(t!==v){v=t;a.querySelectorAll("[data-slot-index]").forEach(e=>{const n=parseInt(e.dataset.slotIndex||"-1"),r=e.firstElementChild;if(!r)return;const i=n===t,s=i?"rgba(74,158,255,0.1)":"transparent";r.style.background=s,r.style.boxShadow=i?"inset 0 0 0 1px rgba(74,158,255,0.25)":"none",r.dataset.active=i?"1":""})}b=requestAnimationFrame(x)};b=requestAnimationFrame(x);const _=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=_,_()}}_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.onShortcutHelpToggle=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,r=e>0?e:this.element.clientWidth,i=n>0?n:this.element.clientHeight;r>0&&i>0&&this._threeCapability.resize(r,i,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 r=this._threeCapability.domElement,i=this._threeCapability.css3DRenderer?.domElement,s=[...this._threeCapability.decoratorOutlines];this._threeCapability.dispose(),this._threeCapability=void 0,i?.parentNode&&i.parentNode.removeChild(i);for(const t of this.components)if(t.isHTMLElement()&&t.element){const e=t.element,n=this.getOverlay(t);n?.appendChild(e)}r?.parentNode&&r.parentNode.removeChild(r),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},r=this.get("scale")||{x:1,y:1},i=r.x||1,s=r.y||1,{width:o=800,height:a=600}=this.state,c=(t/2-n.x)/i-o/2,l=(e/2-n.y)/s-a/2,h=t/i,d=e/s;this._threeCapability.positionCameraForViewport(c,l,h,d,this._lastCameraState)}_init2DViewportFrom3DCamera(t,e,n){if(!e&&!n)return;const{w:r,h:i}=this._getViewportSize(),{width:s=800,height:o=600}=this.state,a=t.x+s/2,c=t.z+o/2,l=e>0?r/e:1/0,h=n>0?i/n:1/0,d=Math.max(.1,Math.min(Math.min(l,h),10)),u=r/2-a*d,p=i/2-c*d;this.set({translate:{x:u,y:p},scale:{x:d,y:d}})}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")}dispose(){this._deactivateThreeD(),this._removeToolbar(),super.dispose(),this._overlay=null,this._decoratorOverlay&&(zs.getInstance().removeOverlay(this._decoratorOverlay),this._decoratorOverlay.parentNode&&this._decoratorOverlay.parentNode.removeChild(this._decoratorOverlay),this._decoratorOverlay=null),this._decoratorAuxOverlay&&(zs.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?lc.get("three"):hc}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,zs.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,zs.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 r=null;try{r=getComputedStyle(this.target)}catch(t){return void Wr(t,this.target)}let i=r?parseFloat(r.getPropertyValue("width")):this.target.clientWidth,s=r?parseFloat(r.getPropertyValue("height")):this.target.clientHeight;switch(n){case"both":case"ratio":break;case"width":s=e*i/t,this.element.style.overflowX="hidden",this.element.style.overflowY="auto";break;case"height":i=t*s/e,this.element.style.overflowX="auto",this.element.style.overflowY="hidden";break;default:i=Math.max(t,i),s=Math.max(e,s),this.element.style.overflowX=i>t?"hidden":"auto",this.element.style.overflowY=s>e?"hidden":"auto"}this.fitSize(this.element,!0),this.fitSize(this.canvas,!0,i,s),this.fitSize(this.auxCanvas,!0,i,s),this.is3dMode&&this._threeCapability.resize(i,s)}draw(t){if(this.is3dMode){if(!this.element)return;this._threeCapability.renderCSS3D()}else this.model.threed||super.draw(t)}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 r=n.length-1;r>=0;r--){const i=n[r];if(!i.isContainer())continue;const s=i.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||e.is3dMode)return;if("KeyQ"===t.code)return e.set("threed",!0),void t.preventDefault();const n={Digit1:"perspective",Digit2:"top",Digit3:"front",Digit4:"back",Digit5:"right",Digit6:"left"}[t.code];n&&(e._pendingCameraView=n,e.set("threed",!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||(zs.getInstance().invalidateOverlay(this.decoratorOverlay),zs.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=cd,scale:n=ad,rotation:r=0}=this.model,{left:i,top:s}=this.bounds;t.style.left=i+"px",t.style.top=s+"px",t.style.transform=`rotate(${r}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 md||!n.model.event||!n.model.event.hover)return;if(n.hidden)return;const r=n.model.event.hover;r&&this._doEventAction(r,n,!0,t)}_onmouseleave_all(t,e){if(t.stopPropagation(),!e)return;const n=e.origin;if(!this.app||this.app.isEditMode)return;const r=n.model.event&&n.model.event.hover;r&&this._doEventAction(r,n,!1,t)}_onclick(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,r=n.model.event?.tap;r&&this._doEventAction(r,n,!0,t)}_onmousedownup(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,r=n.model.event?.tap;r&&r.pressed&&this._doMouseDownUpEventAction(r,n,"mousedown"==t.type||"touchstart"==t.type,t)}_doMouseDownUpEventAction(t,e,n,r){const{pressed:i=!1}=t;i&&(n?function(t){if(t.hasOwnProperty("_backupShadow"))return;const e=t.get("shadow");t._backupShadow=e;const{left:n=0,top:r=0}=e||{};t.delta("tx",n),t.delta("ty",r),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,r){let{action:i,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:r,lineWidth:i,fillStyle:s}=t.state;t.__backup_emphasize={strokeStyle:r,lineWidth:i,fillStyle:s},t.setState(n)}(e):c&&function(t){"__backup_emphasize"in t&&(t.setState(t.__backup_emphasize),delete t.__backup_emphasize)}(e)),i)switch(i){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"==r.type||n?ac.show(e,s,c,{x:r.offsetX,y:r.offsetY}):c&&ac.hide(e,s);break;case"toggle-info-window":if(!s)return;ac.toggle(e,s,!1,{x:r.offsetX,y:r.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);kc.show(e,s,{data:t&&this.root.findFirst(t,e)?.data,output:a,modal:"modal-popup"===i,closable:!0,draggable:!0,origin:"auto"});break;case"close-scene":this.closeScene(e.data);break;case"goto":case"goto-playlist":this.trigger(i,s,l,e);break;case"mouse-cursor":n?this.target.style.cursor=s||"auto":c&&(this.target.style.cursor="auto");break;default:this.trigger(i,s,o,e)}}applyDecorator(t,e,n={}){const r=this.getDecoratorOverlay(t);if(r){zs.getInstance().addToOverlay(r,t,e,n)}}offdecorator(t,e){const n=this.getDecoratorOverlay(t);if(n){zs.getInstance().removeFromOverlay(n,t,e)}}resetDecorator(t,e){const n=this.getDecoratorOverlay(e);n&&zs.getInstance().removeAllFromOverlay(n,t)}onChangeForDecorator(t,e,n){const{origin:r}=n,i=this.getDecoratorOverlay(r);zs.getInstance().invalidateOverlay(i)}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 yd(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.from.component===n&&(!e||t.from.anchor===e))}function bd(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.to.component===n&&(!e||t.to.anchor===e))}function vd(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){Wr(t)}t.closePath()}}),t.restore()}contains(t,e){let n=super.contains(t,e);if(n)return n;const r=this.anchors||[];for(const i of r){const r=i.bounds;if(!r)continue;const{left:s,top:o,width:a,height:c}=r;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 yd(this,t)}findOutletEnds(t){return function(t,e){return yd(t,e).map(t=>t.toEnd?.component).filter(Boolean)}(this,t)}findInletLines(t){return bd(this,t)}findInletEnds(t){return function(t,e){return bd(t,e).map(t=>t.fromEnd?.component).filter(Boolean)}(this,t)}}}md.Popup=kc,tc.register("model-layer",md);const xd={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0}}],help:"scene/component/rect"},_d={ondragmove:function(t,e,n){const{left:r,width:i,height:s}=n.model;let o=(n.fromParent(t.x,t.y).x-r)/(i/2)*100;o=nc(o,i,s),n.set({round:o})}};class wd extends(vd(rc(ec))){is3dish(){return!0}get controls(){let{left:t,top:e,width:n,round:r,height:i}=this.state;return r=null==r?0:nc(r,n,i),[{x:t+n/2*(r/100),y:e,handler:_d}]}get nature(){return xd}}tc.register("rect",wd);const Md=[1,2,10,20,50,50,50,50,50,50];class Sd extends(rc(ec)){render(t){const{lineWidth:e=1,fillStyle:n="lightgray",font:r="15px Arial",left:i,top:s,origin:o,width:a,height:c,side:l="bottom",strokeStyle:h="#000000",scale:d=1}=this.state;t.translate(i,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=r;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 x=Math.ceil(o/v);const _=this.app.PPM/v,w=_<=1.1?1:Md[Math.round(_)]||100;1!=w&&(x+=(w-x%w)%w);let M=Math.ceil(x*v);const S=o+a;for(t.fillStyle=h;M<S;){if(x%10==0){t.moveTo(M-o,y),t.lineTo(M-o,f);const e=(x/10).toString(),n=t.measureText(e);t.fillText(e,M-o-n.width-6,b)}else x%5==0?(t.moveTo(M-o,m),t.lineTo(M-o,f)):(t.moveTo(M-o,g),t.lineTo(M-o,f));x+=w,M=Math.ceil(x*v)}}}tc.register("ruler",Sd);const Ad=20,kd=20,Ed=90*Math.PI/180,Cd="9px Verdana",Pd=20,Td="#f4f4f4",Od="#999";function Dd(t,e,n){return{left:-t.x,top:-t.y,width:Ad,height:Pd}}function Id(t,e,n,r){return{left:Ad-t.x,top:0-t.y,origin:20-t.x,width:e-Ad,height:Pd}}function zd(t,e,n,r){const i={x:0-t.x+10,y:-t.y+kd+(n-kd)/2},s=tc.transcoordRR(0-t.x,-t.y+kd,i,Ed);return{left:s.x-(n-kd),top:s.y,origin:20-t.y,width:n-kd,height:Pd}}function Ld(t){const e=t.get("translate");return{left:-e.x,top:-e.y,width:t.canvas.width/Ri,height:t.canvas.height/Ri}}tc.register("guide-layer",class extends Oc{constructor(t,e){super(t,e),this.appScale={x:1,y:1},"disabled"!==t.ruler&&(this.hruler=new Sd({left:Ad,top:0,origin:20,margin:0,height:Pd,unit:"m",rotation:0,font:Cd,fillStyle:Td,strokeStyle:Od,capturable:!1}),this.vruler=new Sd({left:0,top:0,origin:20,margin:0,height:Pd,unit:"m",rotation:Ed,font:Cd,side:"top",fillStyle:Td,strokeStyle:Od,capturable:!1}),this.origin_rect=new wd({left:-20,top:-20,width:20,height:20,fillStyle:Td,strokeStyle:Od,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=Ld(this));const t=this.rootModel,e=Object.assign({},t.get("translate"));e.x<Ad&&(e.x+=Ad),e.y<kd&&(e.y+=kd);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=Ld(this);const{width:r,height:i}=this.screen_coord;this.hruler.set(Id(e,r)),this.vruler.set(zd(e,0,i)),this.origin_rect.set(Dd(e))}resize(){super.resize(),this.screen_coord=Ld(this);const{width:t,height:e}=this.screen_coord;this.hruler&&(this.hruler.set(Id(this.model.translate,t)),this.vruler.set(zd(this.model.translate,0,e)),this.origin_rect.set(Dd(this.model.translate)))}render(t){if(this.rootModel?.is3dMode)return;if(!this.guide)return;t.save();const{x:e,y:n}=this.guide,{top:r,left:i,width:s,height:o}=this.screen_coord;t.beginPath(),t.moveTo(e,r),t.lineTo(e,r+o),t.moveTo(i,n),t.lineTo(i+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=Ld(this),this.hruler){const{translate:t}=this.model,{width:e,height:n}=this.screen_coord;this.hruler.set(Id(t,e)),this.vruler.set(zd(t,0,n)),this.origin_rect.set(Dd(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)}});tc.register("shift-layer",class extends Oc{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 jd(t,e,n,r){const i=t.selected;let s=r?i.slice(0):[];r&&s.length>0?e=s[0].parent:e.isContainer()||(e=e.parent);const o=e.layout.capturables(e),a=!!e.layout.joinType;if(r&&n.selected.forEach(t=>{s.splice(s.indexOf(t),1)}),n.selected=[],o.forEach(t=>{t.capturable&&function(t,e,n){const{sx:r,sy:i,ex:s,ey:o}=e;let a,c,l,h;if(r>s?(a=s,c=r):(a=r,c=s),i>o?(l=o,h=i):(l=i,h=o),n){const e=t.bounds,n=t.transcoordS2TR(e.left,e.top),r=t.transcoordS2TR(e.left+e.width,e.top+e.height),i=n.x,s=r.x,o=n.y,d=r.y,u=Math.min(a,i,c,s),p=Math.max(a,i,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-i)||g-f>Math.abs(h-l)+Math.abs(d-o))}{const e=t.path;if(!e)return Wr("컴포넌트에 get path가 잘못 구현되어있음.",t),!1;for(let n=0;n<e.length;n++){const r=t.transcoordS2TR(e[n].x,e[n].y);if(a>r.x||c<r.x||l>r.y||h<r.y)return!1}return!0}}(t,n,a)&&-1==s.indexOf(t)&&n.selected.push(t)}),s=s.concat(n.selected),i.length!==s.length)t.selected=s;else for(let e=0;e<s.length;e++)if(i[e]!=s[e]){t.selected=s;break}}function Rd(t,e,n,r,i){i||jd(t,e,n,r)}function Fd(t,e){const n=t.components||[];for(const t of n){Fd(t,e);const n=e.indexOf(t);-1!=n&&e.splice(n,1)}}tc.register("add-layer",class extends Oc{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:r,ex:i,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,r,i-n,s-r),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:r,ex:i,ey:s}=this.addbox;gl.call(this.root,this.models,{left:Math.min(n,i),top:Math.min(r,s),width:Math.abs(i-n),height:Math.abs(s-r)}),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:r}=this.toLocal(t.offsetX,t.offsetY);gl.call(this.root,this.models,{cx:n,cy:r}),this.root.trigger("addstop")}});tc.register("selection-layer",class extends Oc{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)}contains(t,e){return!1}render(t){const e=this.selbox;if(e){const{sx:n,sy:r,ex:i,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,r,i-n,s-r),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,r=n.selected;if(1!==r.length)return!1;let i=r[0];const s=i.parent;if(!s||s===n)return!1;if("Tab"===t.code){const e=s.layout.capturables(s);let n=e.indexOf(i);if(-1==n){if(!s.indexOf(i))return Xr("Container not contains [",i,"] as a component"),!1;n=0}const r=e.length;t.shiftKey?n--:n++,i=e[(n+r)%r]}else{if(!s.layout.keyNavigate)return!1;i=s.layout.keyNavigate(s,i,t)||i}n.selected=[i],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 r=t.parent;for(;r.parent.isGroup();)r=r.parent;let i=[],s=!1,o=!1;if(this.selected.forEach(t=>{let e=t.parent;if(t!==r){for(;e.parent&&e.parent.isGroup();)e=e.parent;e===r&&(i.push(t),s=!0)}else o=!0}),s)if(e.shiftKey){if(-1!=n)return void this._pendingDecision(e);i.push(t)}else{if(-1!=n)return void this._pendingDecision(e);i=[t]}else{if(o)return void this._pendingDecision(e);if(e.shiftKey)if(this.selected.length>0){if(-1!=this.selected.indexOf(r))return;i=[...this.selected,r]}else i=[r];else i=[r]}this.selected=i}onmousedown_comp(t,e){const{origin:n}=e;if(this.downpoint=null,t.shiftKey){if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(-1!=this.selected.indexOf(n))return void this._pendingDecision(t);{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),Fd(n,t)),t.push(n),this.selected=t}}else{if(n.parent.isGroup())return void this._selectGroupItem(n,t);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;let r=this.selected.indexOf(n);if(-1==r&&n.parent.isGroup()&&(r=this.selected.indexOf(n.parent)),-1!==r&&t.shiftKey){const t=this.selected.slice();return r>-1&&t.splice(r,1),void(this.selected=t)}n.parent.isGroup()&&(this.selected=[n])}ondragstart_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:r,y:i}=this.toLocal(t.offsetX,t.offsetY);this.selbox={sx:r,sy:i,selected:[]}}ondragmove_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:r,y:i}=this.toLocal(t.offsetX,t.offsetY);this.selbox&&(this.selbox.ex=r,this.selbox.ey=i,Rd(this,n,this.selbox,t.shiftKey,!1),this.invalidate())}ondragend_selbox(t,e){const{origin:n}=e;n.stuck&&(this.last_pos=null,this.selbox=null,Rd(this,null,null,!1,!0),this.invalidate())}});class Bd{constructor(t){this.layer=t}draw(t,e,n){const{left:r,top:i,width:s,height:o}=e.bounds;0!=s&&0!=o&&(t.beginPath(),t.rect(r,i,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(r,i,s,o),t.stroke(),t.closePath())}}class Nd{constructor(t){this.layer=t}draw(t,e,n){const r=e.bounds;t.beginPath(),t.rect(r.left-4/n.x,r.top-4/n.y,r.width+8/n.x,r.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 Yd{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,r){const i=n.controls;return!!i&&(i.every((i,s)=>(Math.abs(t-i.x)<=4/r.x&&Math.abs(e-i.y)<=4/r.y&&(this.active={component:n,index:s,handler:i.handler}),!this.active)),!!this.active)}draw(t,e,n){const r=e.controls;r&&r.forEach((e,r)=>{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:r,index:i}=this.active;let s=r.toLocal(e.offsetX,e.offsetY);s=r.toParent(s.x,s.y),n&&"function"==typeof n[t]&&n[t](s,i,r)}onmousedown(t){this.onevent("onmousedown",t)}ondragstart(t){const e=this.active;e.changes=Kc.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;Kc.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function Vd(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}const Gd=15*Math.PI/180;class Hd{constructor(t){this.layer=t}reset(){this.active=null,this.created=null}get selected(){return this.layer.selected}contains(t,e,n,r){return!!n.mutable&&(n.path.every((i,s)=>(Math.abs(t-i.x)<=4/r.x&&Math.abs(e-i.y)<=4/r.y&&(this.active={component:n,index:s}),!this.active)),!!this.active)}startLinkProcess(t,e,n){try{const r=pl(e,t.app,void 0);return t.rootModel.addComponent(r),this.layer.selected=[r],this.active={component:r,index:1},this.ondragstart(n),r}catch(t){Xr(t)}}draw(t,e,n){if(!e.mutable||e.stuck)return;const r=e.path,i=this.active;r.forEach((r,s)=>{t.beginPath(),t.ellipse(r.x,r.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.fillStyle="#fff",i&&i.component===e&&i.index===s&&(t.strokeStyle="#fa7703",i.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=Kc.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:r,offsetY:i}=t;let s=e.toLocal(r,i);if(s=e.toParent(s.x,s.y),t.shiftKey){const t=e.path.length;let r=e.isLine()&&0==n?e.path[1]:e.path[(n-1+t)%t];r=e.toParent(r.x,r.y);let i=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),i=Vd(s,r))}const c=Math.round((Vd(r,s)-i)/Gd)*Gd+i;s=function(t,e,n){return{x:Math.cos(e)*n+t.x,y:Math.sin(e)*n+t.y}}(r,c,(o=r,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(r,i,t=>!t.isConnectable());if(t){const{x:o,y:a}=t.toLocal(r,i),c=this.layer.get("scale")||{x:1,y:1},l=this.layer.counterEnd,h=(t.anchors||[]).find(n=>{const{name:r,inout:i,multiplicity:s=1/0,position:h,filter:d}=n;if(l){const{anchor:t,fromto:e}=l;if(t&&("out"===t.inout&&"out"===i||"in"===t.inout&&"in"===i))return!1;if("from"===e&&"out"===i||"to"===e&&"in"===i)return!1}else Wr("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(r);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}}}e.mutatePath(null,function(t){t[n]=s})}ondragend(t){const{component:e,index:n,changes:r}=this.active;if(0===n||n===e.path.length-1){const{offsetX:r,offsetY:i}=t,s=e.rootModel.capture(r,i,t=>t===e||t.isLine()),{x:o,y:a}=s.toLocal(r,i),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 hl({changes:[{component:this.created,to_container:this.created.parent}]});this.created.app.commander.execute(t)}else Kc.after(r,e.app.commander);e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function Ud(t,e,n){return t.filter(t=>{const{name:r,inout:i,multiplicity:s=1/0,filter:o}=t;if(n){const{anchor:t,fromto:e}=n;if(t&&("out"===t.inout&&"out"===i||"in"===t.inout&&"in"===i))return!1;if("from"===e&&"out"===i||"to"===e&&"in"===i)return!1}else if("in"===i)return!1;return!(s!==1/0&&e.findInOutLines(r).length>=s)&&(!o||!n||!!o.call(t,n))})}class Wd{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,r){const i=this.active?.component===n&&this.active?.anchor;this.active=null;const s=this.layer.counterEnd;return Ud(n.isConnectable()&&!n.disposed&&this.getAnchorHandles(n,r)||[],n,s).every(s=>{const o=i===s.name?2:1;return s&&s.position&&Math.abs(t-s.position.x)<=4*o/r.x&&Math.abs(e-s.position.y)<=4*o/r.y&&(this.active={component:n,anchor:s.name,template:s.template}),!this.active}),!!this.active}getAnchorHandles(t,e){const{width:n,height:r}=t.bounds;return n*e.x<30||r*e.y<30?[]:t.anchors}draw(t,e,n){if(!e.get("refid")||e.isLine())return;const r=this.active,i=this.active?.component===e&&this.active?.anchor,s=this.layer.counterEnd;Ud(e.isConnectable()&&!e.disposed&&this.getAnchorHandles(e,n)||[],e,s).forEach(s=>{const{name:o,position:a}=s,c=i===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",r&&r.component===e&&r.anchor===o&&(t.strokeStyle="#fa7703",r.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e,anchor:n,template:r}=this.active,i=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,...r,from:{component:e.get("refid"),anchor:n,position:i},to:{position:i}},t)}ondragmove(t){}ondragend(t){}}function Xd(t,e){const{left:n,top:r,width:i,height:s}=t,o=n+i/2,a=r+s/2,c=n+i,l=r+s,h=i*e.x>50,d=s*e.y>50;return[{x:n,y:r},h?{x:o,y:r}:{x:null,y:null},{x:c,y:r},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 qd{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,r){if(!n.resizable)return!1;const i=Xd(n.bounds,r);for(let s=0;s<i.length;s++){const o=i[s];if(null!=o.x&&null!=o.y&&Math.abs(t-o.x)<=4/r.x&&Math.abs(e-o.y)<=4/r.y)return this.active={component:n,index:s},!0}return!1}draw(t,e,n){if(e.isLine())return;const{left:r,top:i,width:s,height:o}=e.bounds;if(t.beginPath(),t.rect(r-4/n.x,i-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;Xd(e.bounds,n).forEach((r,i)=>{null!=r.x&&null!=r.y&&(t.beginPath(),t.rect(r.x-4/n.x,r.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===i&&(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:r,boundsList:i,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:r,top:i,width:s,height:o}=t.bounds;let a,c;switch(e){case 0:a=r,c=i;break;case 1:a=r+s/2,c=i;break;case 2:a=r+s,c=i;break;case 3:a=r+s,c=i+o/2;break;case 4:a=r+s,c=i+o;break;case 5:a=r+s/2,c=i+o;break;case 6:a=r,c=i+o;break;case 7:a=r,c=i+o/2}const l=a,h=c,d=t.fromScene(n.x,n.y);return{dx:d.x-l,dy:d.y-h}}(n,r,o);this.layer.selected.filter(t=>t.resizable).forEach((n,s)=>{n.bounds=i[s],function(t,e,n,r,i,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+=r,a+=i,c-=r,l-=i;break;case 1:a+=i,l-=i;break;case 2:a+=i,c+=r,l-=i;break;case 3:c+=r;break;case 4:c+=r,l+=i;break;case 5:l+=i;break;case 6:o+=r,c-=r,l+=i;break;case 7:o+=r,c-=r}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,r,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 Kd=2*Math.PI,$d=Math.PI/2;function Qd(t,e){const n=t.bounds;return{x:n.left+n.width/2,y:n.top-20/e.y}}class Zd{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,r){if(!n.rotatable)return!1;const i=Qd(n,r);return Math.abs(t-i.x)<=4/r.x&&Math.abs(e-i.y)<=4/r.y&&(this.active={component:n},!0)}draw(t,e,n){if(!e.rotatable)return;t.beginPath();const r=Qd(e,n);t.lineWidth=1.5/n.x,t.moveTo(r.x,r.y+20/n.y),t.lineTo(r.x,r.y),t.strokeStyle="#656565",t.stroke(),t.beginPath(),t.ellipse(r.x,r.y,4/n.x,4/n.y,0,0,Kd,!0),t.stroke(),t.fillStyle="#fff",t.fill();const i=this.active;i&&i.component===e&&(t.strokeStyle="#fa7703",t.stroke(),i.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 r=e.rotatePoint,i=e.get("rotation")||0;let s=Math.atan((r.y-n.y)/(r.x-n.x));s=r.x>=n.x?s-$d:$d+s;const o=s-i;this.layer.selected.filter(t=>t.rotatable).forEach((e,n)=>{const r=((e.get("rotation")||0)+o)%Kd;e.set("rotation",e.adjustRotation(r,t.shiftKey))})}ondragend(t){const{component:e}=this.active;e.app.commander.execute(null,!1)}}tc.register("modeling-layer",class extends Dc{constructor(t,e){super(t,e),this.pathHandler=new Hd(this);const n=this.pathHandler,r=new Yd(this),i=new qd(this),s=new Zd(this);this._modelers=[n,r,i,s],this._control_mode_modelers=[r,n,i,s],this.focusOutline=new Bd(this),this.groupOutline=new Nd(this),this.anchorHandler=new Wd(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 r=this.fromParent(t,e),i=this.get("scale")||{x:1,y:1};let s;if(this._state_dragging){if(this._counter_end){let n=i;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(r.x,r.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=i;a.scalable?s=a.fromScene(r.x,r.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=i;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(r.x,r.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,r){const i=[];let s=e.parent;if(e.isRootModel())return t.save(),r(t,e,n),void t.restore();for((t=this.getContext(e))==this.auxContext2D&&(n={x:1,y:1});s&&!s.isRootModel();)i.push(s),s=s.parent;t.save(),i.reverse().forEach(function(e){const n=e.rotatePoint;t.translate(n.x,n.y);const r=e.get("scale");r&&t.scale(r.x,r.y),t.rotate(e.get("rotation")),t.translate(-n.x,-n.y);const i=e.bounds;t.translate(i.left,i.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),r(t,e,n),t.restore()}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:r}=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*Ri,e.y*Ri),t.scale(n.x*Ri,n.y*Ri),r&&t.rotate(r),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 r=n[0].parent;for(;r.parent.isGroup();)r=r.parent;this._componentDrawer(t,r,e,(t,e,n)=>{this.groupOutline.draw(t,e,n)})}n.forEach(n=>{this._componentDrawer(t,n,e,(t,e,n)=>{this.reversedModelers.forEach(r=>r.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:r,deliverer:i}=n;r===i&&(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,r=t.dataTransfer.files;if(r.length<1)return;const i=this.rootModel.toLocal(t.offsetX,t.offsetY),s=this.rootModel;Promise.all(Array.from(r).map(t=>new Promise((e,n)=>{const r=new FileReader;r.addEventListener("loadend",t=>{e(r.result)}),["error","abort"].forEach(t=>r.addEventListener(t,t=>{n(t)})),r.readAsDataURL(t)}))).then(e=>{if(t.altKey)return Kc.around(this.app.commander,()=>{n.ondropfile(r,e)}),void(this.selected=[n]);const o=[],a=e.map((t,e)=>{let n;const a=r[e].type,c=r[e].name;return a.startsWith("image/")?(n=pl({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,r)=>{const i=new Image;i.src=t,i.onload=()=>{n.set({width:i.width,height:i.height}),e()},i.onerror=t=>{r(t)}}))):a.startsWith("audio/")?n=pl({type:"audio",top:0,left:0,width:100,height:100,src:t},s.app):a.startsWith("vnd.ms-excel/")||/\.xlsx?$/.test(c)?n=pl({type:"excel",top:0,left:0,width:100,height:100,src:t},s.app):qr("dropped file",r[e]),n&&(n.center=i,i.x+=50,i.y+=50),n}).filter(Boolean).map(t=>({component:t,to_container:s}));a.length>0&&Promise.all(o).then(()=>{this.app.commander.execute(new hl({changes:a})),this.selected=a.map(t=>t.component)},t=>{Wr(t)})},t=>{Wr(t)})}onwheel_scale(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer;let r;if(t.shiftKey)r=-1!=navigator.userAgent.indexOf("Win")?t.deltaY<0?1:-1:t.deltaX<0?1:-1,t.altKey?Kc.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("letterSpacing")||Ni.LETTER_SPACING;e+=r,t.set("letterSpacing",e)})}):Kc.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("fontSize")||Ni.FONT_SIZE;e<1&&(e=1),e+=r,t.set("fontSize",e)})});else{r=t.deltaY<0?1:-1;const e=n.get("scale")||{x:1,y:1},i=n.get("translate"),s=t.offsetX,o=t.offsetY,a=n.toLocal(s,o),c=.1*r,l={x:e.x+c,y:e.y+c};if(r<0&&e.x<.2||r>0&&e.x>10)return;n.set("scale",l);const h=n.toLocal(s,o);n.set("translate",{x:i.x+(h.x-a.x)*l.x,y:i.y+(h.y-a.y)*l.y})}}});function Jd(){const t=arguments,e=t[t.length-1],n=this.event_pump;n.listeners.forEach(r=>{!function(t,e,n,r,i){for(const s in n){const o=n[s];if(Sa(s,r.origin,0,t))for(const t in o){const n=o[t];t==r.name&&(r.listener=e,n.apply(e,i))}}}(n.deliverer,r.listener,r.cloned_handlers,e,t)})}tc.register("scroll-layer",class extends Oc{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:r,width:i,height:s}=this.vscroller;t.globalAlpha="v"==e?1:.3,t.fillRect(n,r,i,s)}if(this.hscroller){const{left:n,top:r,width:i,height:s}=this.hscroller;t.globalAlpha="h"==e?1:.3,t.fillRect(n,r,i,s)}t.stroke(),t.restore()}resize(){super.resize(),this.calcScrollerBounds()}contains(t,e){const n=this.vscroller,r=this.hscroller;return this.setState("scrolling",n&&t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height?"v":r&&t>=r.left&&t<=r.left+r.width&&e>=r.top&&e<=r.top+r.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:r,clientHeight:i}=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/r,p=o/i;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:r}=this.rootModel.model,{x:i=1,y:s=1}=this._scale||{},{x:o=0,y:a=0}=this._translate||{},c=n/t,l=r/e;let h={left:-o/i/c,top:e-10,width:t/i/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()}}});class tu{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)",Jd,{event_pump:this})}stop(){this.deliverer.off("(all)",Jd)}on(t,e){const n=Object.assign({},e);Object.keys(n).forEach(e=>{if(0==e.indexOf("?")){const r=n[e],i=e.substr(1),s=t.get(i);delete n[e],s?n[s]=r:Xr("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 r=this.listeners[n];r.listener!==t||e&&r.handlers!==e||this.listeners.splice(n,1)}}clear(){this.listeners=[]}dispose(){this.stop(),this.clear()}}class eu{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 r=e[n];if("(self)"===n&&void 0===t.on)throw new Error("(self) selector not available when deliverer is not a event handlable object.");Ea(n,this.root,t).forEach(n=>{const i=new tu(n);i.on(t,r),i.start(),this.eventMaps.push({eventPump:i,listener:t,handlerMap:e,deliverer:n})})}}remove(t,e){const n=this.eventMaps.slice(0);for(let r=0;r<n.length;r++){const i=n[r];i.listener!==t||e&&i.handlerMap!==e||(this.eventMaps.splice(r,1),i.eventPump.dispose())}}clear(){this.eventMaps.slice(0).forEach(t=>t.eventPump.dispose()),this.eventMaps=[]}dispose(){this.stop(),this.clear()}}const nu=0,ru=1,iu=2,su=0,ou=1,au=2;let cu={},lu=0;class hu{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,r=0,i=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,r=Math.max(t.screenX,r),n=null!=n?Math.min(t.screenY,n):t.screenY,i=Math.max(t.screenY,i)});const o=r-e||0,a=i-n||0;return s=Math.sqrt(Math.pow(o,2)+Math.pow(a,2))||0,s}(t);lu>0&&(this._scale=e/lu),lu=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 hu&&e===n.type||(n=new hu(n,e));const r="on"+e;t[r]&&t[r](n),n.isPropagationStopped()||t.trigger(e,n)}class uu{constructor(t,e){this.gestureHandlerBuilder=t=>{const e=this[`on${t}`];return t=>{const n=new hu(t),r=this.getChildScrollOffset();return n._offsetX+=this.html_element.scrollLeft+r.scrollLeft,n._offsetY+=this.html_element.scrollTop+r.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 ru:const e=t.offsetX-this.__dragstart_e.offsetX,n=t.offsetY-this.__dragstart_e.offsetY;if(e*e+n*n<16)break;this.status=iu,du(this.last_target,"dragstart",this.__dragstart_e),this.__dragmove_e=t,du(this.last_target,"dragmove",t);break;case iu: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===iu)du(this.last_target,"dragend",t),this.last_target=null,this.status=nu;else{const e=this.findTarget(t);this.last_target=e,this.status=ru,this.__dragstart_e=t,du(e,t.type,t)}return!1},this.onmouseup=t=>{if(this.status===iu)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=nu,!1},this.onmouseout=t=>{const e=this.findTarget(t);if(this.status===iu)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=nu,!1},this.ontouchstart=t=>{const e=this.findTarget(t);return this.last_target=e,this.status=ou,this.touchPoints||(this.touchPoints=[]),this.touchPoints.push(t.changedTouches[0]),this.holdTimer=setTimeout(()=>{this.status=su,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 ou: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,r=e.clientY-t.clientY;return Math.sqrt(Math.pow(n,2)+Math.pow(r,2))>=16?(this.status=au,void(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer))):void 0});break;case au: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 au:e=this.last_target;break;case ou:{const n=performance.now(),r=n-this.touchedAt;this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer,du(e,r<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=su,!1},this.onwheel=t=>(du(this.findTarget(t),t.type,t),!1),this.container=t,this.html_element=e,this.status=nu,this.last_target=null,this.gesture_handlers=Fi.map(t=>this.gestureHandlerBuilder(t)),this.keyevent_handlers=Bi.map(t=>this.keyeventHandlerBuilder(t)),Fi.forEach((t,n)=>e.addEventListener(t,this.gesture_handlers[n]),{passive:!1}),Bi.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")),Fi.forEach((t,e)=>this.html_element.removeEventListener(t,this.gesture_handlers[e])),Bi.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(),r=this.getChildScrollOffset(),i=t.clientX-n.left+this.html_element.scrollLeft+r.scrollLeft,s=t.clientY-n.top+this.html_element.scrollTop+r.scrollTop;return this.container.capture(i,s)}}function pu(t,e,n,r=0){if(e.length<2)return e;let i=2;for(;i<e.length;i++){const s=e.substring(0,i);if(!(t.measureText(s).width+(s.length-1)*r<n))break}return e.substring(0,i-1)}function fu(t,e,n,r,i=0){const s=String(e).split("\n");return r?[].concat.apply([],s.map(e=>function(t,e,n,r=0){const i=e.split(" "),s=[];let o,a,c=[];for(o=0,a=1;a<=i.length;a++)if(c=i.slice(o,a),t.measureText(c.join(" ")).width+(c.join("").length-1)*r>n){if(a-o==1){const e=pu(t,c[0],n,r);s.push([e]),i.splice(o,1,e,c[0].substring(e.length))}else{for(;""==i[a-1];)a++;s.push(i.slice(o,--a))}o=a}return a-o>1&&s.push(c),0==s.length&&s.push([""]),s}(t,e,n,i))):s.map(t=>t.split(" "))}const gu={},mu={},yu=()=>{};var bu={register:function(t,e,n){gu[t]=e,n&&(mu[t]=n)},unregister:function(t){delete gu[t],delete mu[t]},get:function(t){return gu[t]},getDisposer:function(t){return mu[t]||yu}};function vu(t){if(!t.hasTextProperty||t.textHidden)return;let{text:e="",bold:n=Ni.BOLD,italic:r=Ni.ITALIC,textWrap:i=Ni.TEXT_WRAP,letterSpacing:s=0,fontFamily:o=Ni.FONT_FAMILY,fontColor:a=Ni.FONT_COLOR,textAlign:c=Ni.TEXT_ALIGN,textBaseline:l=Ni.TEXT_BASELINE,fontSize:h=Ni.FONT_SIZE,lineHeight:d=1.2*h}=t.model;const{left:u,top:p,width:f,height:g}=t.textBounds;h||=Ni.FONT_SIZE,d||=1.2*h,t.textHidden=!0;const m=document.createElement("textarea"),y=new AbortController;Fi.forEach(function(t){m.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:y.signal})});const b=t.toGlobal(u,p),{rotation:v,scale:x}=function(t){let e=0,n=1,r=t;for(;r;){e+=r.get("rotation")||0;const{x:t,y:i}=r.get("scale")||{x:1,y:1};n*=Math.max(t,i)||1,r=r.parent}return{rotation:e,scale:n}}(t);m.value=e;const _={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&&(_.fontWeight="bold"),r&&(_.fontStyle="italic"),c){case"right":case"end":_.textAlign="right";break;case"justify":_.textAlign="justify";break;case"left":case"start":_.textAlign="left";break;default:_.textAlign="center"}const w=[n,r,h+"px",o].filter(Boolean).join(" ");function M(e){const n={left:0,top:0},r=d*function(t,e,n,r,i=0){const s=t.getContext();let o;return s.save(),s.font=n,o=fu(s,e,r,t.get("textWrap"),i).length,s.restore(),o}(t,e,w,f,s);switch(_.height=r+"px",l){case"top":case"hanging":break;case"bottom":case"alphabetic":n.top=g-r;break;default:n.top=g/2-r/2}if(!i){const r=function(t,e,n,r){const i=e.split("\n");let s=r;const o=t.getContext();return o.save(),o.font=n,i.forEach(t=>{const e=o.measureText(t).width;e>s&&(s=e)}),o.restore(),s}(t,e,w,f);switch(_.width=r+"px",c){case"right":case"end":n.left=f-r;break;case"left":case"start":break;default:n.left=(f-r)/2}}_.marginLeft=n.left+"px",_.marginTop=n.top+"px",_.transform=`translate(${b.x}px, ${b.y}px) scale(${x}) rotate(${v}rad)`,_.transformOrigin=`${-n.left}px ${-n.top}px`,Object.assign(m.style,_)}M(e);const S=t.root.target_element;S.appendChild(m),m.select();let A,k=!1;m.addEventListener("keydown",function(t){t.stopPropagation(),"Escape"!=t.code&&(t.shiftKey||"Enter"!=t.code&&"NumpadEnter"!=t.code)?setTimeout(()=>{M(m.value)}):(k=A.skipUpdate="Escape"==t.code,"function"==typeof document.createEvent?m.dispatchEvent(A):m.fireEvent(A.eventType,A))},{signal:y.signal}),document.createEvent?(A=document.createEvent("HTMLEvents"),A.initEvent("blur",!0,!1)):(A=document.createEventObject(),A.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||k||t.app.commander.execute(new Kc({changes:[{component:t,before:{text:e},after:{text:m.value}}]}))};m.addEventListener("blur",C,!1)}bu.register("text-editor",{"(root)":{"(self)":{keydown:function(t,e){const{deliverer:n}=e,r=n.selected;return!(1!==r.length||!r[0].hasTextProperty)&&(("Enter"==t.code||"NumpadEnter"==t.code)&&(vu(r[0]),t.preventDefault(),!0))}}},"model-layer":{"(descendant)":{dblclick:function(t,e){vu(e.origin)}}}});const xu=ar(function(t,e,n){if(!t.hasSameParentForAllSelected||n)return void(t.focused=null);const r=[];e[0].parent.isGroup()?t.focused=e[0].parent:(e.forEach(t=>{t.path.forEach(e=>{r.push(t.toScene(e.x,e.y))})}),t.focused=t.capturePath(r,e))},300);let _u,wu,Mu;bu.register("move-handler",{"model-layer":{"(descendant)":{dragstart:function(t,e){const{origin:n,deliverer:r}=e;if(n.stuck)return;let i=r.selected;const s=r.selected.filter(t=>!t.stuck);if(i.length!==s.length&&(i=r.selected=s),0==i.length)return;let o;if(i[0].scalable?(o=i[0].toLocal(t.offsetX,t.offsetY),o=i[0].toParent(o.x,o.y)):o={x:t.offsetX,y:t.offsetY},this.last_pos=o,this.direction=0,r.focused=i[0].parent,t.altKey){const t=[],e=new Map;r.selected=r.selected.filter(t=>!t.isRootModel()).map(n=>{const i=fl(n,t=>{const n=r.root.getNewRefid();return void 0!==t&&e.set(t,n),n});return t.push({component:i,to_container:n.parent}),i}).map(t=>(t.replaceRefids(e),t)),t.forEach(({component:t,to_container:e})=>{e.addComponent(t)}),this.duplicates=r.selected.map(t=>({component:t}))}else this.changes=Kc.before(i)},dragmove:function(t,e){const{origin:n,deliverer:r}=e;if(n.stuck)return;const i=r.selected;if(0==i.length)return;let s;i[0].scalable?(s=i[0].toLocal(t.offsetX,t.offsetY),s=i[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),i.forEach(t=>{t.move({x:o,y:a},1===i.length)}),this.last_pos=s,xu(r,i)},dragend:function(t,e){const{origin:n,deliverer:r}=e;if(n.stuck)return;const i=r.selected;if(0==i.length)return;const s=i[0].parent,o=r.focused||e.deliverer;if(this.changes&&!o.isGroup())if(r.hasSameParentForAllSelected&&o&&o!==s){const t=this.changes.map(t=>{const{component:e}=t;return{component:e,to_container:o}});r.app.commander.execute(new hl({changes:t}))}else Kc.after(this.changes,r.app.commander);else if(this.duplicates){this.duplicates=this.duplicates.map(t=>(t.to_container=o,t));const t=new hl({changes:this.duplicates});r.app.commander.execute(t)}i.forEach(t=>{t.parent&&t.parent.calculateBounds&&t.parent.calculateBounds()}),this.last_pos=null,this.changes=null,this.duplicates=null,xu(r,i,!0)}}},"(root)":{"(self)":{keydown:function(t,e){const{origin:n,deliverer:r}=e,i={},s=t.shiftKey?n.rootModel.MPP:1;switch(t.which){case 37:i.x=-s,i.y=0;break;case 38:i.x=0,i.y=-s;break;case 39:i.x=s,i.y=0;break;case 40:i.x=0,i.y=s;break;default:return}const o=r.selected;Kc.around(r.app.commander,function(){o.forEach(t=>{!t.stuck&&t.move(i,!1)})})}}}});const Su=cr(()=>{const{x:t,y:e}=Mu,n=wu.deref();n&&(n.rootModel.move({x:t-_u.x,y:e-_u.y},!1),_u={x:t,y:e})},60,{leading:!0,trailing:!0});bu.register("shift-handler",{"model-layer":{"(all)":{dragstart:function(t,e){_u={x:t.offsetX,y:t.offsetY}},dragmove:function(t,e){wu=new WeakRef(e.deliverer),Mu={x:t.offsetX,y:t.offsetY},Su()}}}}),bu.register("zoom-handler",{"model-layer":{"(all)":{wheel:function(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer,r=t.deltaY<0?1:-1,i=n.get("scale")||{x:1,y:1},s=n.get("translate"),o=t.offsetX,a=t.offsetY,c=n.toLocal(o,a),l=.1*r,h={x:i.x+l,y:i.y+l};if(r<0&&i.x<.2||r>0&&i.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 Au={},ku={};function Eu(t){const e={};for(const n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}bu.register("paste-handler",{"(root)":{"(self)":{stylepastestart:function(t){const{deliverer:e}=t,n=e.app,r=e.selected;if(r&&r[0]&&r!==e.rootModel){const t=r[0],{fillStyle:e,strokeStyle:i,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:x,paddingRight:_}=t.state;Au=Kn({fillStyle:e,strokeStyle:i,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:x,paddingRight:_}),n.mode=4}},stylepastestop:function(t){const{deliverer:e}=t,n=e.app;Au={},4==n.mode&&(n.mode=1)},databindpastestart:function(t){const{deliverer:e}=t,n=e.app,r=e.selected;if(r&&r[0]&&r!==e.rootModel){const t=r[0],{mappings:e}=t.state;ku=Kn({mappings:e}),n.mode=5}},databindpastestop:function(t){const{deliverer:e}=t,n=e.app;ku={},5==n.mode&&(n.mode=1)},pasteapply:function(t,e){const{deliverer:n}=e,r=n.app;t&&(4==r.mode?Kc.around(r.commander,()=>{t.set(Eu({...t.model,...Au}))}):5==r.mode&&Kc.around(r.commander,()=>{t.set(Eu({...t.model,...ku}))}))},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,r=n.app;if(4!=r.mode&&5!=r.mode)return;const i=e.origin;4==r.mode?i===n?n.root.trigger("stylepastestop"):i&&Kc.around(r.commander,()=>{const t=Eu({...i.model,...Au});i?.set(t)}):i===n?n.root.trigger("databindpastestop"):i&&Kc.around(r.commander,()=>{const t=Eu({...i.model,...ku});i?.set(t)})}}}});class Cu{constructor(){this.animatorMap=new Map}waypoint(t,e){this.animatorMap.has(t)&&this.off(t);let{from:n,to:r}=e;if("string"==typeof n&&(n=t.root?.findById(n)),"string"==typeof r&&(r=t.root.findById(r)),!r)return void Xr("WaypointAnimation: Source or target component not found");const i=na(t,{type:"waypoint",fromComponent:n,toComponent:r,...e,onComplete:()=>{this.off(t)}});i&&(this.animatorMap.set(t,i),i.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 Pu(t){const{origin:e}=t,n=e.root,{waypointHandler:r}=n;r?.reset()}bu.register("waypoint-handler",{"model-layer":{"(descendant)":{waypoint:function(t,e){const{origin:n}=e,r=n.root;let{waypointHandler:i}=r;i||(i=new Cu,r.waypointHandler=i),i.waypoint(n,t)},waypointoff:function(t){const{origin:e}=t,n=e.root,{waypointHandler:r}=n;r?r.off(e):Xr("waypoint-handler not found")},waypointreset:Pu},"(self)":{waypointreset:Pu}}},function(t){const{waypointHandler:e}=t;e&&(e.dispose(),delete t.waypointHandler)});const Tu=[],Ou=ar(function(){Tu.forEach(t=>{t.resize()})},100);"undefined"!=typeof window&&window.addEventListener("resize",Ou);class Du extends Tc{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.target_element=t.target_element,this.rebuildContentModel(this.model.model),Tu.push(this)}dispose(){kc.hideAll(this),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=Tu.indexOf(this);t>=0&&Tu.splice(t,1),this.refidIndexMap.clear(),this.indexMap.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 uu(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&&Wr("Template replaced (duplicated)",t,e,n),this.templateMap[t]=e,delete this.templatePrefixes}removeTemplate(t,e){const n=this.templateMap[t];n!==e?Xr("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.toString().replace(/^#/,""),r=this.indexMap.get(n)||[];r.push(e),this.indexMap.set(n,r)}removeIndex(t,e){if(!t)return;const n=t.toString().replace(/^#/,""),r=this.indexMap.get(n)||[],i=r.indexOf(e);-1===i?Xr("Removing index failed (not found)",t,e):(r.splice(i,1),0===r.length?this.indexMap.delete(n):this.indexMap.set(n,r))}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&&Wr("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?Wr("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=t.toString().replace(/^#/,"");return(this.indexMap.get(e)||[])[0]}findAllById(t){if(!t)return[];const e=t.toString().replace(/^#/,"");return this.indexMap.get(e)||[]}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=pl(Object.assign(Kn(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:r}=this.model_layer.model,i=this.target_element,s=this.model_layer;if(this.fitMode=t||this.fitMode||r||"ratio",e&&n&&i&&i.clientWidth&&i.clientHeight){switch(this.fitMode){case"center":!function(t,e,n){const r=t.unitScale,{width:i,height:s}=e.model;e.set("scale",{x:r,y:r}),e.set("translate",{x:Math.max((n.clientWidth-i*r)/2,0),y:Math.max((n.clientHeight-s*r)/2,0)})}(this,s,i);break;case"both":!function(t,e,n){const{width:r,height:i}=e.model,s=n.clientWidth,o=n.clientHeight;e.set("scale",{x:s/r,y:o/i}),e.set("translate",{x:0,y:0})}(0,s,i);break;case"width":!function(t,e,n){const r=n.clientWidth/e.get("width");e.set("scale",{x:r,y:r}),e.set("translate",{x:0,y:0})}(0,s,i);break;case"height":!function(t,e,n){const r=n.clientHeight/e.get("height");e.set("scale",{x:r,y:r}),e.set("translate",{x:0,y:0})}(0,s,i);break;case"ratio":!function(t,e,n){const{width:r,height:i}=e.model,s=n.clientWidth,o=n.clientHeight,a=s/r,c=o/i,l=Math.min(a,c);e.set("scale",{x:l,y:l}),e.set("translate",{x:(s-r*l)/2,y:(o-i*l)/2})}(0,s,i);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=>{bu.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;e?.preserveThreeD&&this.model_layer?.is3dMode&&(n=this.model_layer.detachThreeCapability()),this._disposeAllResources(),this.eventEngine=new eu(this),(t=t||{}).type="model-layer",this.model_layer=pl(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=pl(t,this.app);if(e)return this.addComponent(e),e.target=this.target_element,e;Wr("Layer compile failed",t)}).filter(Boolean),this.assist_handlers=(this.model.handlers||[]).map(t=>{const e={};return this.eventEngine.add(e,bu.get(t)),e}),n&&(this.model_layer?.model?.threed?this.model_layer.adoptThreeCapability(n):n.dispose()),this._ready=!0,this.traverse(t=>t.ready())}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.set("threed",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(),r=[...e].sort();return n.every((t,e)=>t===r[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=ar(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:r,tag:i,templatePrefix:s}=t.model;this.addRefidIndex(r,t),e&&this.addIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.addIndex(e,t)}),i&&this.subscribe(i,t),s&&this.addTemplate(s,t);const o=gr({},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:r,tag:i,templatePrefix:s}=t.model;this.removeRefidIndex(r,t),e&&this.removeIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.removeIndex(e,t)}),i&&this.unsubscribe(i,t),s&&this.removeTemplate(s,t),this.eventEngine.remove(t)}onadded(t,e){this._addTraverse(e),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)||this.refreshMappings()}}tc.memoize(Du.prototype,"unitScale",!1);let Iu=13.3;var zu=function(t){return void 0!==t&&(Iu=t),Iu};const Lu="$base_url";const ju=Math.PI/12;class Ru{constructor(t,e){this._postprocessing=!0,this._mode=t,this.screen=zu(),this._baseUrl="undefined"!=typeof window?window.location.origin:null,this._refProvider=e,this.isEditMode&&(this._rotateStep=ju,this._rotateStepForced=!1)}dispose(){this._dataSubscriptionProvider?.dispose?.(),delete this._dataStorage}_calcScreen(){const t={width:screen.width,height:screen.height};this._PPI=function(t,e,n,r="d"){t<=0&&(t=1),e<=0&&(e=1);const i=("d"===r?Math.sqrt(t*t+e*e):"w"===r?t:e)/n;return i>0?Math.round(i):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 Ri}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(Lu)?new URL(t.replace(Lu,this.baseUrl??""),this.baseUrl??void 0):new URL(t,location.origin),e.href}catch(e){Xr(e,t)}}get rotateStep(){return this._rotateStep}set rotateStep(t){this._rotateStep=Number(t)||ju}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}}Ur(Ru.prototype,Lr.withEvent);class Fu{constructor(t,e){!(t=Number(t))||t<=0?(Wr("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];Xr("Not forwardable.")}backward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.backwardable)return this.q[--this.pos];Xr("Not backwardable.")}get current(){if(-1!==this.pos)return this.q[this.pos];Xr("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 Bu=ar(t=>{t.brake||t.take()},1e3,{leading:!0,trailing:!1});function Nu(t){!t.brake&&t.dirty&&Bu(t)}class Yu{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(){Bu.cancel(),this.state_holder=null,this.timecapsule=null}touch(){this.dirty=!0,Nu(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,Nu(this)}}function Vu(t,e){const n=e.model_layer.get("scale"),r=e.model_layer.get("translate"),i=e.model_layer.get("threed");if(t){const s=JSON.parse(t);s.scale=n,s.translate=r,s.threed=i,e.rebuildContentModel(s,{preserveThreeD:!0})}}class Gu{constructor(t){this.container=t,this.timecapsule=new Fu(20);const e=this;this.snapshot_taker=new Yu({get state(){const t=e.container.model_layer.hierarchy;return JSON.stringify(t)}},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&&(Vu(this.timecapsule.backward(),this.container),this.trigger("undo",this.undoable(),this.redoable()))}redo(){this.timecapsule.forwardable&&(Vu(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")}}Ur(Gu.prototype,Lr.withEvent);const Hu=new class{constructor(){this._scenes=[],this.onSceneChange=null}register(t){this._cleanup(),this._scenes.push(new WeakRef(t)),this.onSceneChange?.(this._scenes.length)}unregister(t){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 r=n.root,i=r?.model||{};return{index:e,model:{width:i.width||0,height:i.height||0,type:i.type||"unknown"}}}).filter(Boolean)}getComponentTree(t=0){const e=this._getScene(t);if(!e)return[];const n=e.rootContainer;if(!n)return[];const r=n.model_layer;return r?this._childrenOf(r):[]}getChildTree(t,e=0){const n=this._getScene(e);if(!n)return[];const r=n.rootContainer;if(!r)return[];let i;return i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),i?this._childrenOf(i):[]}getComponentInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const r=n.rootContainer;if(!r)return null;let i;if(i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),!i)return null;const s=this._safeBounds(i),o={model:this._safeClone(i.model),state:this._safeClone(i.state),nature:i.nature||{},data:this._safeValue(i.data),value:this._safeValue(i.value),bounds:s,type:i.model?.type||"unknown",isContainer:!!i.isContainer?.(),hidden:!!i.model?.hidden};return"model-layer"===i.model?.type&&(o.is3dMode=!!i.model?.threed),o}selectComponent(t,e=0){const n=this._getScene(e);if(!n)return!1;const r=n.rootContainer;if(!r)return!1;if(!t||"root"===t||"__root__"===t)return r.selected=[],!0;const i=this._findComponent(r,t);return!!i&&(r.selected=[i],!0)}setComponentProperty(t,e,n,r=0){const i=this._getScene(r);if(!i)return!1;const s=i.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 r=n.rootContainer;if(!r)return!1;const i=r.model_layer;if(!i||!i._threeCapability)return!1;try{return i._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 r=n.model_layer;if(!r||!r._threeCapability)return null;try{return r._threeCapability.getCameraState()}catch{return null}}toggleHidden(t,e=0){const n=this._getScene(e);if(!n)return!1;const r=n.rootContainer;if(!r)return!1;const i=this._findComponent(r,t);if(!i)return!1;try{return i.set("hidden",!i.model?.hidden),!i.model?.hidden}catch{return!1}}evaluateData(t,e=0){const n=this._getScene(e);if(!n)return;const r=n.rootContainer;if(!r)return;const i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t);return i?this._safeValue(i.data):void 0}evaluateValue(t,e=0){const n=this._getScene(e);if(!n)return;const r=n.rootContainer;if(!r)return;const i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t);return i?this._safeValue(i.value):void 0}searchComponents(t,e=0){const n=this._getScene(e);if(!n)return[];const r=n.rootContainer;if(!r)return[];const i=r.model_layer;if(!i)return[];const s=[],o=t.toLowerCase();return this._traverseComponent(i,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 r=n.rootContainer;if(!r)return[];const i=r.model_layer;if(!i)return[];const s=[];return this._findPath(i,t,s)?s:[]}getThreedInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const r=n.rootContainer;if(!r)return null;let i;if(i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),!i)return null;const s=i.model||{},o=s.type||"unknown",a=s.material3d,c={is3dish:"function"==typeof i.is3dish&&i.is3dish(),type:o};if(a&&(c.material3d=this._safeClone(a)),c.resolved=Eh(a),"gltf-object"===o)try{c.nodeNames=i.nodeNames??[],c.animationNames=i.animationNames??[],c.autoPlay=!1!==i.autoPlay,c.nodes=this._safeClone(i.nodes),c.animations=this._safeClone(i.animations),c.fillStyleTargets=i.fillStyleTargets}catch{}return a?.spriteMode&&(c.spriteMode=a.spriteMode),a?.renderMode&&(c.renderMode=a.renderMode),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 r=t.findById(e);return r||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,r=t.state||t.model||{};return{id:String(r.refid??r.id??""),type:r.type||"unknown",model_id:r.id,hasChildren:n,childCount:n?e.length:0,refid:r.refid,tag:r.tag,name:r.name,hidden:!!r.hidden,clazz:r.class}}_componentId(t){const e=t.state||t.model||{};return String(e.refid??e.id??"")}_findPath(t,e,n){const r=this._componentId(t);if(r===e)return!0;const i=t.components;if(!i)return!1;for(const s of i)if(this._findPath(s,e,n))return n.unshift("model-layer"===t.model?.type?"__root__":r),!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 r=t[n];if("function"==typeof r)continue;e[n]="object"==typeof r?String(r):r}catch{e[n]="[error]"}return e}}_safeValue(t){if(null==t)return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}},Uu="KHR_materials_pbrSpecularGlossiness";class Wu{constructor(t){this.name=Uu,this.parser=t}extendMaterialParams(t,e){const n=this.parser.json.materials?.[t],r=n?.extensions?.[Uu];if(!r)return Promise.resolve();const i=[];if(Array.isArray(r.diffuseFactor)){const[t,n,i,s]=r.diffuseFactor;e.color||(e.color=new l),e.color.setRGB(t,n,i,h),e.opacity=s}null!=r.diffuseTexture&&i.push(this.parser.assignTexture(e,"map",r.diffuseTexture,d));const s=r.glossinessFactor??1;e.roughness=1-s;const o=r.specularFactor??[1,1,1],a=Math.max(o[0],o[1],o[2]);return e.metalness=a>.5?a:0,Promise.all(i)}}const Xu={once:e.LoopOnce,repeat:e.LoopRepeat,pingpong:e.LoopPingPong};class qu extends zh{constructor(){super(...arguments),this.objectSize=new e.Vector3,this._nodeIndex=new Map,this._originals=new Map,this._animationActions=new Map,this._fillStyleOriginals=new Map,this._clonedMaterials=new WeakSet,this._loadGen=0}static getSharedLoader(t){if(!qu._sharedLoader){const t=new S;!function(t){t.register(t=>new Wu(t))}(t);const e=new A;e.setDecoderPath("/node_modules/three/examples/jsm/libs/draco/"),t.setDRACOLoader(e);const n=new k;n.setTranscoderPath("/node_modules/three/examples/jsm/libs/basis/"),t.setKTX2Loader(n),t.setMeshoptDecoder(E),t.setCrossOrigin("anonymous"),qu._sharedLoader=t}return t&&qu._sharedLoader.ktx2Loader?.detectSupport(t),qu._sharedLoader}static loadGLTF(t,e){let n=qu._gltfCache.get(t);if(!n){const r=qu.getSharedLoader(e);n=new Promise((e,n)=>{r.load(t,e,void 0,n)}).catch(e=>{throw qu._gltfCache.delete(t),e}),qu._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}build(){super.build();const{src:t}=this.component.state;if(!t)return void this.clear();const e=++this._loadGen,n=this.component.app.url(t);qu.loadGLTF(n,this.threeContainer?.renderer3d).then(t=>{e===this._loadGen&&this.gltfLoaded(t)},t=>{e===this._loadGen&&(Wr("GLTFLoader.load",t),this.clear(),this._showErrorPlaceholder(),this.component.setState({loadError:String(t)}))})}gltfLoaded(t){this.component.state.loadError&&this.component.setState({loadError:void 0});const n=t.scene,r=t.animations,i=n.clone();i.userData.context=this,i.traverse(t=>{t.isMesh&&(t.castShadow=!0)});const s=(new e.Box3).setFromObject(i),o=s.getCenter(i.position),a=s.getSize(new e.Vector3);o.multiplyScalar(-1);const c=this.component.state.src;if(c){const t=qu._topViewCache.get(c);t?this.component._topViewSnapshot=t:this._renderTopViewSnapshot(c,i)}this.clear(),this.object3d.userData.context=this,this.objectSize=a,this.pivot=new e.Object3D,this.object3d.add(this.pivot),this.pivot.add(i),this._buildNodeIndex(i),this.updateDimension(),r&&r.length&&this._setupAnimations(r);const l=this.component.state.nodes;l&&this._applyNodeStates(l),this.updateFillStyle()}_renderTopViewSnapshot(t,e){const n=qu.renderTopView(e);qu._topViewCache.set(t,n),this.component._topViewSnapshot=n,this.component.invalidate()}static renderTopView(t){const n=256,r=new e.Scene,i=t.parent;r.add(t);const s=new e.AmbientLight(16777215,.8);r.add(s);const o=new e.DirectionalLight(16777215,1);o.position.set(0,10,0),r.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){i?i.add(t):r.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(r,u),i?i.add(t):r.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 qu._topViewCache.get(t)}static setTopViewCache(t,e){qu._topViewCache.set(t,e)}static flushCache(){qu._gltfCache.clear(),qu._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 r=this._ensureOwnMaterial(e);void 0!==n.color&&r.color.set(n.color),void 0!==n.opacity&&(r.opacity=n.opacity,r.transparent=n.opacity<1),void 0!==n.emissive&&r.emissive.set(n.emissive),void 0!==n.emissiveIntensity&&(r.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.autoPlay&&this._animationActions.forEach(t=>t.play());const n=this.component.state.animations;n&&this._applyAnimationStates(n)}_applyAnimationStates(t){for(const[n,r]of Object.entries(t)){const t=this._animationActions.get(n);t&&(void 0!==r.loop&&(t.loop=Xu[r.loop]??e.LoopRepeat,"once"===r.loop&&(t.clampWhenFinished=!0)),void 0!==r.speed&&(t.timeScale=r.speed),void 0!==r.weight&&(t.weight=r.weight),void 0!==r.play&&(r.play?t.play():t.stop()))}}get animationNames(){return Array.from(this._animationActions.keys())}_showErrorPlaceholder(){const t=new e.BoxGeometry(1,1,1),n=new e.MeshStandardMaterial({color:13369344,wireframe:!0}),r=new e.Mesh(t,n);r.name="__error_placeholder__",this.object3d.add(r)}updateFillStyle(){const t=this.component.state.fillStyleTargets;if(!t||0===t.length)return;const{fillStyle:e}=this.component.state;if(!e)return;const n=zh.buildFillStyleTexture(this.component);for(const r of t){const t=this._nodeIndex.get(r);if(!t||!t.isMesh)continue;const i=this._ensureOwnMaterial(t);i&&(this._fillStyleOriginals.has(r)||this._fillStyleOriginals.set(r,{color:i.color.clone(),map:i.map,opacity:i.opacity,transparent:i.transparent}),n?(i.map&&i.map!==this._fillStyleOriginals.get(r)?.map&&i.map.dispose(),n.needsUpdate=!0,i.map=n):"string"==typeof e&&("transparent"!==e?i.color.set(e):(i.opacity=0,i.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 r=n.material;r&&(r.map&&r.map!==t.map&&r.map.dispose(),r.color.copy(t.color),r.map=t.map,r.opacity=t.opacity,r.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(),this.pivot&&Dh(this.pivot),this.pivot=void 0,this.objectSize=void 0,super.clear()}updateDimension(){const{width:t=1,height:e=1,depth:n=1}=this.component.state,{x:r=1,y:i=1,z:s=1}=this.objectSize||{};this.pivot&&this.pivot.scale.set(t/r,n/i,e/s),this.component.invalidate()}updateSource(){this.build()}onchange(t,e){if(super.onchange(t,e),"src"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=e.fillStyleTargets??[];t.length>0&&this._restoreFillStyleTargets(t),this.updateFillStyle()}"autoPlay"in t&&(!1!==t.autoPlay?this._animationActions.forEach(t=>t.play()):this._animationActions.forEach(t=>t.stop()))}}qu._topViewCache=new Map,qu._gltfCache=new Map,qu._sharedLoader=null;let Ku=0;const $u=new FinalizationRegistry(t=>{Ku--});class Qu{static get residents(){return Ku}static get residentsCount(){return Ku}constructor(t){this._container=t,this.app=t.app,this._commander=new Gu(this._container),this.app.commander=this._commander,Ku++,$u.register(this,Ku),Hu.register(this)}add(t,e,n){return gl.call(this._container,t,e,n)}duplicate(){return ml.call(this._container)}remove(){return yl.call(this._container)}animate(t){return Jo.call(this,t)}fullscreen(t){return Ml.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._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 Ri}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(){Hu.unregister(this),this._commander&&this._commander.dispose(),this._container&&this._container.dispose(),qu.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 kl.call(this._container)}copy(){return Al.call(this._container)}paste(t){return El.call(this._container,t)}undoableChange(t){return Ul.call(this._container,t)}change(t,e,n){return Hl.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 sl.call(this._container,t)}place(t){return Jl.call(this._container,t)}distribute(t){return cl.call(this._container,t)}move(t,e,n){return dl.call(this._container,t,e,n)}zorder(t){return ul.call(this._container,t)}symmetryX(){return Vl.call(this._container)}symmetryY(){return Gl.call(this._container)}on(t,e,n){return xl.call(this._container,t,e,n)}once(t,e,n){return _l.call(this._container,t,e,n)}off(t,e,n){return this._container&&wl.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,r){return Rl.call(this._container,t,e,n,r)}group(){return Fl.call(this._container)}ungroup(){return Bl.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 Wl.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}startAddMode(t){return th.call(this._container,t)}startStylePasteMode(){return eh.call(this._container)}stopStylePasteMode(){return nh.call(this._container)}startDatabindPasteMode(){return rh.call(this._container)}stopDatabindPasteMode(){return ih.call(this._container)}}const Zu=new class{async load(t){}async save(t,e){}async clear(t){}};function Ju({target:t,model:e,style:n,layers:r=[],handlers:i=[],mode:s=0,refProvider:o,dataSubscriptionProvider:a,dataStorage:c=Zu,baseUrl:l,fitMode:h,postprocessing:d=!0}){let u=null;if("string"==typeof t){if(u=document.getElementById(t),!u)throw new Error(`target element '${t}' does not exist`);if(u.firstChild)throw new Error(`target element '${t}' is not empty`)}else u=t??null;u&&u.style&&(u.style.position="absolute",u.style.cursor="default",u.style.overflow="hidden");const p=new Ru(s,o);return l&&(p.baseUrl=l),p.postprocessing=d,p.dataSubscriptionProvider=a,p.dataStorage=c,new Qu(new Du({target_element:u,model:e,style:n,layers:r,handlers:i,fitMode:h},p))}function tp(t,e,n,r){var i,s=arguments.length,o=s<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,n,o):i(e,n))||o);return s>3&&o&&Object.defineProperty(e,n,o),o}function ep(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function np(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const rp=["mousemove","mouseup","mousedown","mouseout","wheel","tap","click","touchstart","touchmove","touchend","mouseenter","mouseleave","dragstart","dragmove","dragend","dblclick"];function ip(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"),rp.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),Bi.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),this.oncreate_element&&this.oncreate_element(this.element))}reposition(){this.element&&vs(this)}disposeElement(){if(!this.element)return;rp.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)}),Bi.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 sp;const op={x:1,y:1},ap={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"},cp={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 lp extends(ip(Tc)){constructor(){super(...arguments),sp.set(this,null),this.startDragging=t=>{if(!this.state.draggable)return;t.preventDefault(),t.stopPropagation();const e=t.clientX,n=t.clientY,{left:r,top:i}=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:r+s,top:i+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 cp}isPositionable(){return!0}setElementProperties(t){}get layout(){return lc.get(this.get("layout"))||hc}reposition(){if(!this.element)return;const t=this,{id:e,class:n,scale:r=op}=t.state,{rotation:i=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,ap,{left:o+"px",top:a+"px",width:"0px",height:"0px",backgroundColor:"transparent"});const p=t.delta(),f=(r&&r.x||1)*p.sx,g=(r&&r.y||1)*p.sy,m=(i||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],r=t[2];e?this.set({left:n.x,top:n.y,width:r.x-n.x}):this.set({left:n.x,top:n.y,width:r.x-n.x,height:r.y-n.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:r=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+r},{x:t,y:e+r}]}get bounds(){const{left:t=0,top:e=0,width:n=0,height:r=0}=this.state;return{left:t,top:e,width:n,height:r}}set bounds(t){const{minimized:e}=this.state,{left:n=0,top:r=0,width:i=0,height:s=0}=t,o={left:n,top:r};e?this.set({...o,width:i}):this.set({...o,width:i,height:s})}updatePosition(){if(!this.origin)return void(ep(this,sp,"f")&&(ep(this,sp,"f").disconnect(),np(this,sp,null,"f")));const t=this.rootModel.auxOverlay;if(!t)return;const e=this.bounds,{width:n,height:r}="static"!==this.position?t.getBoundingClientRect():this.parent.bounds,{x:i,y:s}=function(t,e,n){const{left:r,top:i,width:s,height:o}=e,{width:a,height:c}=n;return t?{x:t.includes("left")?r:t.includes("center")?r+(s-a)/2:r+(s-a),y:t.includes("top")?i:t.includes("middle")?i+(o-c)/2:i+(o-c)}:{x:n.left,y:n.top}}(this.origin,{left:0,top:0,width:n,height:r},e),o=this.offset;this.bounds={left:i+(this.origin.includes("right")?-o.x:+o.x),top:s+(this.origin.includes("bottom")?-o.y:+o.y),width:e.width,height:e.height},ep(this,sp,"f")||(np(this,sp,new ResizeObserver(()=>{requestAnimationFrame(()=>this.updatePosition())}),"f"),ep(this,sp,"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(){ep(this,sp,"f")&&(ep(this,sp,"f").disconnect(),np(this,sp,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:r,hidden:i}=this.state,{width:s}=this.bounds;this.element.style.setProperty("--container-width",`${s}px`);try{C(i?P:T`
|
|
3
|
+
return!t||t.scalable?this.context2D:this.auxContext2D}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(Ri,Ri),super.draw(t),this.auxContext2D.restore())}}var Ic,zc,Lc,jc;!function(t){t.CANVAS="canvas",t.DOM="dom"}(Ic||(Ic={}));class Rc{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;zs.getInstance().addOverlay(t)}}determineOptimalMode(){return!1!==this.options.animation?Ic.DOM:Ic.CANVAS}start(){if(!this.isActive&&(this.isActive=!0,this.mode===Ic.DOM)){this.overlay?(this.createDOMElements(),this.target.on("change",this.handleTargetChange,this),this.target.on("removed",this.handleTargetRemoved,this)):(Xr("오버레이가 설정되지 않아 DOM 모드 데코레이터를 시작할 수 없습니다."),this.isActive=!1)}}stop(){this.isActive&&(this.isActive=!1,this.mode===Ic.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===Ic.DOM&&this.isActive&&this.updateDOMElements()}render(t,e){return!(this.mode!==Ic.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:r}=this.target.bounds;if("function"==typeof this.target.toGlobal)try{const{x:i,y:s}=this.target.toGlobal(t,e,this.target.rootModel);return{x:i,y:s,width:n,height:r}}catch(t){Xr("좌표 변환 실패, 기본값 사용:",t)}return{x:t,y:e,width:n,height:r}}handleTargetChange(t,e){this.target.disposed?this.stop():this.invalidate()}handleTargetRemoved(){this.stop()}invalidate(){}}function Fc(t,n,r){const i=t.rootModel;if(i?.is3dMode){const n=t._realObject?.object3d,r=i.activeCamera3d,s=i.renderer3d;if(n&&r&&s){const t=new e.Vector3;n.getWorldPosition(t);const i=t.clone().project(r),o=s.domElement;return{x:(.5*i.x+.5)*o.clientWidth,y:(.5*-i.y+.5)*o.clientHeight}}return null}const s=t.toGlobal(n,r,i);return isNaN(s.x)||isNaN(s.y)?null:s}class Bc extends Rc{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:Ic.DOM,...n}),this.vectorElement=null,this.animationElements=[],this.svgContainer=null,this.animationElement=null}getDecoratorType(){return this.constructor.DECORATOR_TYPE}dispose(){this.removeDOMElements()}determineOptimalMode(){return Ic.DOM}renderCanvas(t,e){return Xr("VectorDecorator는 Canvas 렌더링을 지원하지 않습니다. DOM 모드를 사용하세요."),!1}getSvgContainer(){if(!this.overlay)throw new Error("오버레이 요소가 없습니다.");if(!Bc.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),Bc.svgContainerCache.set(this.overlay,t)}return Bc.svgContainerCache.get(this.overlay)}getOrCreateDecoratorGroup(t=!1){const e=this.getSvgContainer(),n=this.getVectorGroupId(),r=this.getDecoratorType();let i=e.querySelector(`g[data-decorator-type-container="${r}"]`);if(!i){i=document.createElementNS("http://www.w3.org/2000/svg","g"),i.setAttribute("data-decorator-type-container",r),i.setAttribute("class",`${r}-container`),e.appendChild(i);const t=document.createElementNS("http://www.w3.org/2000/svg","defs");t.setAttribute("data-defs-for",r),i.appendChild(t)}let s=i.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",r),t&&s.setAttribute("data-component-id",t),i.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 r=n.querySelector(`defs[data-defs-for="${e}"]`);return r||(r=document.createElementNS("http://www.w3.org/2000/svg","defs"),r.setAttribute("data-defs-for",e),n.appendChild(r)),r}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,r={}){const i=document.createElementNS("http://www.w3.org/2000/svg","animate");return i.setAttribute("attributeName","opacity"),i.setAttribute("from",t.toString()),i.setAttribute("to",e.toString()),i.setAttribute("dur",`${n}ms`),r.delay&&i.setAttribute("begin",`${r.delay}ms`),i.setAttribute("fill","freeze"),r.repeat?i.setAttribute("repeatCount","indefinite"):i.setAttribute("repeatCount","1"),i}createTranslateAnimation(t,e=[],n=1e3,r={}){const i=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return i.setAttribute("attributeName","transform"),i.setAttribute("type","translate"),i.setAttribute("values",t.join(";")),e.length>0&&i.setAttribute("keyTimes",e.join(";")),i.setAttribute("dur",`${n}ms`),r.delay&&i.setAttribute("begin",`${r.delay}ms`),r.repeat?i.setAttribute("repeatCount","indefinite"):i.setAttribute("repeatCount","1"),i}createRotateAnimation(t=0,e=360,n=0,r=0,i=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} ${r}`),o.setAttribute("to",`${e} ${n} ${r}`),o.setAttribute("dur",`${i}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 Fc(t,e,n)}updatePosition(){if(!this.vectorElement)return;const t=this.options,{left:e,top:n}=this.target.bounds,r=this.projectComponentPoint(this.target,e,n);if(!r)return;const i=r.x+(t.x??0),s=r.y+(t.y??0);this.vectorElement.setAttribute("transform",`translate(${i}, ${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=Bc.svgContainerCache.get(this.overlay);if(!t)return;const e=this.getVectorGroupId(),n=this.getDecoratorType(),r=t.querySelector(`g[data-decorator-type-container="${n}"]`);if(r){const t=r.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()),!r.querySelector("g[data-decorator-group-id]")){const t=r.querySelector(`defs[data-defs-for="${n}"]`);t&&t.remove(),r.remove()}}0===t.children.length&&(t.remove(),Bc.svgContainerCache.delete(this.overlay))}catch(t){Wr("벡터 요소 제거 실패:",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===Ic.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,r=e.height/2,i=(180*t/Math.PI).toFixed(1);this.vectorElement.setAttribute("transform",`rotate(${i} ${n} ${r})`)}}applyTranslateValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("translate")){const r=n.replace(/translate\([^)]+\)/,`translate(${t}, ${e})`);this.vectorElement.setAttribute("transform",r)}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 r=n.replace(/scale\([^)]+\)/,`scale(${t}, ${e})`);this.vectorElement.setAttribute("transform",r)}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}}}Bc.svgContainerCache=new WeakMap,Bc.DECORATOR_TYPE="vector";class Nc extends Rc{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 Ic.CANVAS}createDOMElements(){Xr("RasterDecorator는 DOM 렌더링을 지원하지 않습니다. Canvas 모드를 사용하세요.")}setAnimationState(t=3e3,e=!1){Nc.animationStateMap.set(this.target,{startTime:Date.now(),duration:t,repeat:e})}getAnimationState(){const t=Nc.animationStateMap.get(this.target);if(!t)return{delta:0,finished:!0};const{startTime:e,duration:n,repeat:r}=t,i=Date.now()-e;let s=Math.min(1,i/n),o=s>=1;return r&&o&&(Nc.animationStateMap.set(this.target,{startTime:Date.now(),duration:n,repeat:r}),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(),Nc.animationStateMap.delete(this.target)}applyTransform(t,e,n){const r=this.options,i=r.scale||1,s=r.rotation||0;if(1!==i||0!==s){if(t.translate(e,n),0!==s){const e=s*Math.PI/180;t.rotate(e)}1!==i&&t.scale(i,i),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}}Nc.animationStateMap=new WeakMap;class Yc extends Bc{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:r=3e3,repeat:i=!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(r,i);if(a.push(t),this.options.fadeOut){const t=this.createFadeAnimation(1,0,r,{repeat:i});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(r,i);if(t.push(e),this.options.fadeOut){const e=this.createFadeAnimation(1,0,r,{repeat:i});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){Wr("화살표 SVG 요소 생성 실패:",t)}}createArrowPath(t,e,n=1){const r=n/this.getScale();return`\n M${t-10*r},${e-16*r} \n L${t+10*r},${e-16*r} \n L${t+10*r},${e-8*r} \n L${t+16*r},${e-8*r} \n L${t},${e} \n L${t-16*r},${e-8*r} \n L${t-10*r},${e-8*r} \n Z\n `}getScale(){try{if(this.target.rootModel&&"number"==typeof this.target.rootModel.scale)return this.target.rootModel.scale||1}catch(t){Xr("스케일 계산 실패, 기본값 사용",t)}return 1}createBounceAnimation(t,e){const n=["0,-10"],r=["0"];for(let t=1;t<=20;t++){const e=t/20;let i=Math.pow(e,.5).toFixed(3);parseFloat(r[r.length-1])>=parseFloat(i)&&(i=(parseFloat(r[r.length-1])+.01).toFixed(3)),n.push("0,0"),n.push("0,-10"),r.push(i),r.push((parseFloat(i)+.01).toFixed(3))}return r[r.length-1]="1.000",this.createTranslateAnimation(n,r,t,{repeat:e})}createArrowLabel(t,e,n,r,i=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*i}`),o.setAttribute("y",""+(e-20*i)),o.setAttribute("width",""+40*i),o.setAttribute("height",""+20*i),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*i}`),a.setAttribute("y",""+(e-6*i)),a.setAttribute("fill","white"),a.setAttribute("font-size",12*i+"px"),a.setAttribute("text-anchor","middle"),a.textContent=r,s.appendChild(o),s.appendChild(a),s}startAnimations(){setTimeout(()=>{this.animationElements.forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&t.beginElement()}catch(t){Wr("애니메이션 시작 오류:",t)}})},10)}invalidate(){this.updatePosition()}updatePosition(){if(!this.vectorElement)return;const{left:t,top:e,width:n}=this.target.bounds,r=this.projectComponentPoint(this.target,t+n/2,e);if(!r)return;const i=Math.max(r.x,20),s=Math.max(r.y,20);this.vectorElement.setAttribute("transform",`translate(${i}, ${s})`)}}Yc.DECORATOR_TYPE="bouncing-arrow",function(t){t.ROTATE="rotate",t.TRANSLATE_X="translateX",t.TRANSLATE_Y="translateY",t.SCALE="scale",t.FADE="fade"}(zc||(zc={})),function(t){t.VIBRATION="vibration",t.ROTATION="rotation",t.HEARTBEAT="heartbeat",t.MOVING="moving",t.OUTLINE="outline",t.FADE="fade",t.WAYPOINT="waypoint"}(Lc||(Lc={})),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"}(jc||(jc={}));class Vc extends Bc{constructor(t,e,n={}){const{animations:r,...i}=n;super(t,e,{icon:"arrow_forward",size:24,color:"#FF0000",deltaX:0,deltaY:0,...i}),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(r)}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:r,sx:i,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, ${r}px) scale(${i}, ${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:r}=this.target,{left:i,top:s,width:o,height:a}=r,c=n/2;let l;switch(e||t||jc.CENTER){case jc.TOP_LEFT:case"top-left":l={x:i,y:s-n};break;case jc.TOP:case"top":l={x:i+(o-n)/2,y:s-n};break;case jc.TOP_RIGHT:case"top-right":l={x:i+o-n,y:s-n};break;case jc.BOTTOM_LEFT:case"bottom-left":l={x:i,y:s+a};break;case jc.BOTTOM:case"bottom":l={x:i+(o-n)/2,y:s+a};break;case jc.BOTTOM_RIGHT:case"bottom-right":l={x:i+o-n,y:s+a};break;case jc.LEFT_TOP:case"left-top":l={x:i-n,y:s};break;case jc.LEFT:case"left":l={x:i-n,y:s+(a-n)/2};break;case jc.LEFT_BOTTOM:case"left-bottom":l={x:i-n,y:s+(a-n)};break;case jc.RIGHT_TOP:case"right-top":l={x:i+o,y:s};break;case jc.RIGHT:case"right":l={x:i+o,y:s+(a-n)/2};break;case jc.RIGHT_BOTTOM:case"right-bottom":l={x:i+o,y:s+(a-n)};break;case jc.TOP_LEFT_CORNER:case"top-left-corner":l={x:i-c,y:s-c};break;case jc.TOP_RIGHT_CORNER:case"top-right-corner":l={x:i+o-c,y:s-c};break;case jc.BOTTOM_LEFT_CORNER:case"bottom-left-corner":l={x:i-c,y:s+a-c};break;case jc.BOTTOM_RIGHT_CORNER:case"bottom-right-corner":l={x:i+o-c,y:s+a-c};break;case jc.CENTER:default:l={x:i+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:r,y:i}=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:r+"px",top:i+"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(){super.start(),this.isActive&&(this.overlay&&this._getElement().parentNode!==this.overlay&&this.overlay.appendChild(this._getElement()),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:r}=this._delta;return this.projectComponentPoint(this.target,t+n,e+r)??this.target.toGlobal(t+n,e+r)}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)}),na(this,t)));if(t){const e={...t};return"theta"in e&&(e.theta=e.theta*(Math.PI/180)),[na(this,e)]}return[]}}Vc.DECORATOR_TYPE="animated-icon";class Gc extends Bc{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:r="#FF0000",animation:i=!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),i){const t=this.createGradient(this.elementId,r);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)`),i?a.setAttribute("stroke",`url(#${this.elementId})`):a.setAttribute("stroke",r),t.appendChild(a),this.pathElement=a,this.vectorElement=t,this.updatePathData(),this.options.animation&&this.startAnimations()}catch(t){Wr("테두리 하이라이팅 요소 생성 실패:",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||{},r=this.pointsToPathData(e,n);this.pathElement.setAttribute("d",r)}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){Wr("애니메이션 시작 오류:",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:r}=this.target.bounds;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+r},{x:t,y:e+r}]}return this.target.path.map(t=>this.target.toGlobal(t.x,t.y))}createOffsetPath(t,e){const n=[],r=t.length;for(let i=0;i<r;i++){const s=t[(i-1+r)%r],o=t[i],a=t[(i+1)%r],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 r=t.length,i=(t,e,n)=>{const r=e.x-t.x,i=e.y-t.y,s=Math.sqrt(r*r+i*i);return{x:t.x+r/s*n,y:t.y+i/s*n}};for(let s=0;s<r;s++){const o=t[s],a=t[(s+1)%r],c=t[(s-1+r)%r],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=i(o,c,d),p=i(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 r=document.createElementNS("http://www.w3.org/2000/svg","feFlood");r.setAttribute("flood-color",e),r.setAttribute("result","flood");const i=document.createElementNS("http://www.w3.org/2000/svg","feComposite");i.setAttribute("in","flood"),i.setAttribute("in2","SourceAlpha"),i.setAttribute("operator","in"),i.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(r),n.appendChild(i),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 r=this.alterColor(e,120),i=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};${r};${i};${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",i);const c=document.createElementNS("http://www.w3.org/2000/svg","animate");return c.setAttribute("attributeName","stop-color"),c.setAttribute("values",`${i};${e};${r};${i}`),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),r=parseInt(n.substring(1,3),16),i=parseInt(n.substring(3,5),16),s=parseInt(n.substring(5,7),16),o=this.rgbToHsl(r,i,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 r=Math.max(t,e,n),i=Math.min(t,e,n);let s=0,o=0;const a=(r+i)/2;if(r!==i){const c=r-i;switch(o=a>.5?c/(2-r-i):c/(r+i),r){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 r,i,s;if(0===e)r=i=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;r=o(c,a,t+1/3),i=o(c,a,t),s=o(c,a,t-1/3)}return[Math.round(255*r),Math.round(255*i),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 r=n.getImageData(0,0,1,1).data;return`#${r[0].toString(16).padStart(2,"0")}${r[1].toString(16).padStart(2,"0")}${r[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){Wr("테두리 하이라이팅 요소 제거 중 오류:",t)}}}Gc.DECORATOR_TYPE="border-highlighting";class Hc extends Bc{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 r=this.getComponentBounds();e.forEach(e=>{const{name:i,position:s}=e;let{x:o,y:a}=s||{};if(!i)return;let c=this.calculateOffsetX(o,r),l=this.calculateOffsetY(a,r);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=i,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()}}Hc.DECORATOR_TYPE="anchors";class Uc extends Bc{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:r,padding:i,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",`${i}`),this.textElement.setAttribute("y",`-${n}`),this.textElement.setAttribute("font-family",e),this.textElement.setAttribute("font-size",n),this.textElement.setAttribute("fill",r),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-i).toString()),this.backgroundElement.setAttribute("y",(d.y-i).toString()),this.backgroundElement.setAttribute("width",(d.width+2*i).toString()),this.backgroundElement.setAttribute("height",(d.height+2*i).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()}}Uc.DECORATOR_TYPE="decotag";class Wc extends Bc{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}createDOMElements(){if(this.removeDOMElements(),!this.target.mappings||!this.target.mappings.length)return;this.currentMappings=this.target.mappings;const t=this.options,e=this.getOrCreateDecoratorGroup(!0),n=this.getDefsForType(),r=`data-spread-style-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,i=document.createElementNS("http://www.w3.org/2000/svg","style");i.setAttribute("id",r),i.textContent=`\n @keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: ${t.repeat?"0.2":"0"}; }\n }\n .arrow-animated {\n animation: fadeOut ${t.animationDuration||2e3}ms linear ${t.repeat?"infinite":"1"} forwards;\n }\n `,n.appendChild(i);const s=`arrow-gradient-${Date.now()}-${Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}`,o=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");o.setAttribute("id",s),o.setAttribute("gradientUnits","userSpaceOnUse");const a=document.createElementNS("http://www.w3.org/2000/svg","stop");a.setAttribute("offset","0%"),a.setAttribute("stop-color",t.arrowColor||"#FFA500"),a.setAttribute("stop-opacity",(t.startAlpha||.5).toString());const c=document.createElementNS("http://www.w3.org/2000/svg","stop");c.setAttribute("offset","100%"),c.setAttribute("stop-color",t.arrowColor||"#FFA500"),c.setAttribute("stop-opacity",(t.endAlpha||1).toString()),o.appendChild(a),o.appendChild(c),n.appendChild(o);const l=document.createElementNS("http://www.w3.org/2000/svg","g");l.setAttribute("class",t.animated?"arrow-animated":""),e.appendChild(l);this.target.mappings.forEach(e=>{const n=this.target.root.findAll(e.target,this.target);n&&n.length&&n.forEach(e=>{const n=this.target.center,r=e.center,i=this.projectComponentPoint(this.target,n.x,n.y),a=this.projectComponentPoint(e,r.x,r.y);if(!i||!a)return;o.setAttribute("x1",i.x.toString()),o.setAttribute("y1",i.y.toString()),o.setAttribute("x2",a.x.toString()),o.setAttribute("y2",a.y.toString());const{linePath:c,headPath:h}=this.createArrowPaths(i,a,t.arrowHeadLength),d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("d",c),d.setAttribute("stroke",`url(#${s})`),d.setAttribute("stroke-width",String(t.lineWidth||2)),d.setAttribute("fill","none"),d.setAttribute("data-target-id",e.state?.id||""),d.setAttribute("data-source-id",this.target.state?.id||"");const u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",h),u.setAttribute("fill",t.arrowColor||"#FFA500"),u.setAttribute("stroke","none"),l.appendChild(d),l.appendChild(u)})}),this.vectorElement=e}createArrowPaths(t,e,n){const r=e.x-t.x,i=e.y-t.y,s=Math.atan2(i,r),o=e.x+n*Math.cos(s+Wc.ARROW_ANGLE_1),a=e.y+n*Math.sin(s+Wc.ARROW_ANGLE_1),c=e.x+n*Math.cos(s+Wc.ARROW_ANGLE_2),l=e.y+n*Math.sin(s+Wc.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();const t=this.target.mappings;t&&t===this.currentMappings?this.vectorElement&&this.updatePosition():(this.removeDOMElements(),requestAnimationFrame(()=>{this.createDOMElements()}))}updatePosition(){const t=this.getDecoratorType(),e=this.getSvgContainer().querySelector(`g[data-decorator-type-container="${t}"]`);if(!e)return;const n=this.getVectorGroupId(),r=e.querySelector(`g[data-decorator-group-id="${n}"]`);if(!r)return;const i=this.options;if(!this.target.mappings||!this.target.mappings.length)return;const s=r.querySelector("g.arrow-animated")||r,o=Array.from(s.querySelectorAll('path[fill="none"]')),a=Array.from(s.querySelectorAll('path[stroke="none"]'));if(0===o.length)return;const c=e.querySelector(`defs[data-defs-for="${t}"]`);if(!c)return;const l=c.querySelector("linearGradient");if(!l)return;const h=this.target.mappings;let d=[];h.forEach(t=>{const e=this.target.root.findAll(t.target,this.target);e&&e.length&&(d=[...d,...e])});for(let t=0;t<Math.min(o.length,a.length,d.length);t++){const e=o[t],n=a[t],r=d[t],s=this.target.center,c=r.center,h=this.projectComponentPoint(this.target,s.x,s.y),u=this.projectComponentPoint(r,c.x,c.y);if(!h||!u)continue;const{linePath:p,headPath:f}=this.createArrowPaths(h,u,i.arrowHeadLength);e.setAttribute("d",p),n.setAttribute("d",f),0===t&&l&&(l.setAttribute("x1",h.x.toString()),l.setAttribute("y1",h.y.toString()),l.setAttribute("x2",u.x.toString()),l.setAttribute("y2",u.y.toString()))}}removeDOMElements(){this.currentMappings=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){Wr("데이터 스프레드 데코레이터 요소 제거 중 오류:",t)}}invalidate(){this.updatePosition()}}Wc.DECORATOR_TYPE="data-spread",Wc.ARROW_ANGLE_1=160*Math.PI/180,Wc.ARROW_ANGLE_2=200*Math.PI/180;class Xc extends Bc{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:r,bgColor:i,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",r),b.setAttribute("font-family",a),b.setAttribute("font-size",o),b.textContent=u,c.appendChild(b);const v=b.getBBox();c.removeChild(b);const x=document.createElementNS("http://www.w3.org/2000/svg","rect"),_=v.width+2*(n??0),w=v.height+2*(n??0);g+=(t??0)+_/2,m+=(e??0)+w/2,x.setAttribute("x",(-_/2).toString()),x.setAttribute("y",(-w/2).toString()),x.setAttribute("width",_.toString()),x.setAttribute("height",w.toString()),x.setAttribute("rx",(s??0).toString()),x.setAttribute("ry",(s??0).toString()),x.setAttribute("fill",i),y.appendChild(x),y.appendChild(b),y.setAttribute("transform",`translate(${g}, ${m})`),c.appendChild(y),this.rectElements.push(x),this.textElements.push(b)})}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}}Xc.DECORATOR_TYPE="link",Is.registerDecorator("bouncing-arrow",Yc),Is.registerDecorator("animated-icon",Vc),Is.registerDecorator("border-highlighting",Gc),Is.registerDecorator("anchors",Hc),Is.registerDecorator("decotag",Uc),Is.registerDecorator("data-spread",Wc),Is.registerDecorator("link",Xc);class qc{constructor(t){this.params=Object.assign({},t)}excute(){}}class Kc extends qc{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 $c="left",Qc="right",Zc="center",Jc="bottom",tl="middle",el="z-front",nl="z-back",rl="z-middle",il=[$c,Qc,Zc,"top",tl,Jc,el,nl,rl];function sl(t){if(!this.hasSameParentForAllSelected||-1===il.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(e.length<=1)return;const n=this.app.commander;Kc.around(n,function(){!function(t,e){const n=JSON.parse(JSON.stringify(e[0].bounds));let r=n.left+n.width,i=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,r=s.left+s.width>r?s.left+s.width:r,i=s.top+s.height>i?s.top+s.height:i}switch(n.width=r-n.left,n.height=i-n.top,t){case $c:for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:n.left,top:r.top,width:r.width,height:r.height}}break;case Zc:for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:n.left+n.width/2-r.width/2,top:r.top,width:r.width,height:r.height}}break;case Qc:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:r-n.width,top:n.top,width:n.width,height:n.height}}break;case"top":for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:r.left,top:n.top,width:r.width,height:r.height}}break;case tl:for(let t=0;t<e.length;t++){const r=e[t].bounds;e[t].bounds={left:r.left,top:n.top+n.height/2-r.height/2,width:r.width,height:r.height}}break;case Jc:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:n.left,top:i-n.height,width:n.width,height:n.height}}break;case el:{let t=1/0;for(let n=0;n<e.length;n++){const r=e[n].state.zPos||0;r<t&&(t=r)}for(let n=0;n<e.length;n++)e[n].set({zPos:t});break}case nl:{let t=-1/0;for(let n=0;n<e.length;n++){const r=(e[n].state.zPos||0)+(e[n].state.depth||0);r>t&&(t=r)}for(let n=0;n<e.length;n++){const r=e[n].state.depth||0;e[n].set({zPos:t-r})}break}case rl:{let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){const i=e[r].state.zPos||0,s=e[r].state.depth||0;i<t&&(t=i),i+s>n&&(n=i+s)}const r=(t+n)/2;for(let t=0;t<e.length;t++){const n=e[t].state.depth||0;e[t].set({zPos:r-n/2})}break}default:;}}(t,e)})}const ol="VERTICAL",al=[ol,"HORIZONTAL","Z"];function cl(t){if(!this.hasSameParentForAllSelected||-1===al.indexOf(t))return;const e=this.selected;if(e.length<=1)return;const n=this.app.commander;Kc.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),r=e[0].state.zPos||0,i=((e[e.length-1].state.zPos||0)+(e[e.length-1].state.depth||0)-r-n)/(e.length-1);let s=r+(e[0].state.depth||0);for(let t=1;t<e.length-1;t++){const n=e[t],r=n.state.depth||0;s+=i,n.set({zPos:s}),s+=r}}(e);const n=e.filter(t=>!t.stuck).slice(0);n.sort(function(e,n){const r=e.center,i=n.center;return t===ol?r.y-i.y:r.x-i.x});const r=n.reduce((e,n)=>e+(t===ol?n.bounds.height:n.bounds.width),0),i=n[0].bounds,s=n[n.length-1].bounds,o=((t===ol?s.top+s.height-i.top:s.left+s.width-i.left)-r)/(n.length-1);let a=t===ol?i.top+i.height:i.left+i.width;for(let e=1;e<n.length-1;e++){const r=n[e],i=r.bounds;a+=o,t===ol?(r.bounds={left:i.left,top:a,width:i.width,height:i.height},a+=i.height):(r.bounds={left:a,top:i.top,width:i.width,height:i.height},a+=i.width)}}(t,e)})}function ll(t){let e=0;for(;t&&!t.isRootModel();)e+=t.get("rotation")||0,t=t.parent;return e%(2*Math.PI)}class hl extends qc{execute(){this.params.changes.forEach(t=>{const{component:e,to_container:n,to_index:r,to_left:i,to_top:s}=t,o=function(t){if(t.isRootModel())return t.bounds;const{bounds:e,rotatePoint:n}=t;let r=n;return r=t.toScene(r.x,r.y),{left:r.x-(n.x-e.left),top:r.y-(n.y-e.top),width:e.width,height:e.height}}(e),a=ll(e);if(e.removeSelf(!n),e.bounds=o,e.set("rotation",a),n){e.set("rotation",function(t,e){return((t.get("rotation")||0)-ll(e))%(2*Math.PI)}(e,n));const o=function(t,e){if(e.isRootModel())return t.bounds;const{bounds:n,rotatePoint:r}=t,i=e.fromScene(r.x,r.y),s=e.bounds;return{left:i.x-(r.x-n.left)-s.left,top:i.y-(r.y-n.top)-s.top,width:n.width,height:n.height}}(e,n);t.to_left=void 0!==i?i: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===r?n.addComponent(e):n.insertComponentAt(e,r)}})}}function dl(t,e,n){this.app.commander.execute(new hl({changes:[{component:t,to_container:e,to_index:n}]}))}function ul(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 r;if("forward"===t){const t=n.indexOf(e[0]);r=[{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]);r=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t-1}]}else r=e.filter(t=>t.parent===n).sort((e,r)=>{const i=n.indexOf(e)<n.indexOf(r);return"front"===t?i:!i}).map((e,r)=>(n.indexOf(e),{component:e,to_container:n,to_index:"front"===t?n.components.length-r-1:r}));const i=new hl({changes:r});this.app.commander.execute(i)}function pl(t,e,n,r){const i=tc.register(t.type);if(!i)return Xr("Class not found",t.type),null;n&&(t.refid=n(t.refid)),t.id&&r&&r(t.id)&&delete t.id;const s=new i(t,e);return t.components&&s.isContainer()&&(t.components.forEach(t=>{const i=pl(t,e,n,r);i&&s.addComponent(i)}),delete t.components),s.created(),s}function fl(t,e){const n=Kn(t.hierarchy);return delete n.id,pl(n,t.app,e)}function gl(t,e,n){t instanceof Array||(t=[t]),n||(n=this.model_layer);const r=[],i=new Map;this.selected=t.map(t=>{try{return pl(t,n.app,t=>{const e=this.getNewRefid();return void 0!==t&&i.set(t,e),e},t=>(this.indexMap[t]||[])[0])}catch(t){return Xr(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(i),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}),r.push({component:t,to_container:n}),t}),this.app.commander.execute(new hl({changes:r}))}function ml(){const t=[],e=new Map;if(this.selected=this.selected.filter(t=>!t.isRootModel()).map(n=>{const r=fl(n,t=>{const n=this.getNewRefid();return void 0!==t&&e.set(t,n),n});return r.move({x:20,y:20},!1),t.push({component:r,to_container:n.parent}),r}).map(t=>(t.replaceRefids(e),t)),0===t.length)return;const n=new hl({changes:t});this.app.commander.execute(n)}function yl(){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 r=e.parent;t.forEach(t=>n.push({component:t,to_container:r})),n.push({component:e,to_container:null}),e=r}n.length>0&&this.app.commander.execute(new hl({changes:n})),e&&e.calculateBounds&&e.calculateBounds()}const bl=new Set(["execute","redo","undo","command-reset"]);function vl(t,e,n,r){const i=function(t,e){return bl.has(e)?t.app?.commander:"mode"===e?t.app:t}(this,e);i?.[t](e,n,r)}function xl(t,e,n){vl.call(this,"on",t,e,n)}function _l(t,e,n){vl.call(this,"once",t,e,n)}function wl(t,e,n){vl.call(this,"off",t,e,n)}function Ml(t){const e=this.target_element,n=t||this.fitMode,r=this;function i(){r.fit(n),document.fullscreenElement||document.removeEventListener("fullscreenchange",i)}document.addEventListener("fullscreenchange",i),e.requestFullscreen().catch(()=>{document.removeEventListener("fullscreenchange",i)})}let Sl=0;function Al(){const t=this.selected.filter(t=>!t.isRootModel()).map(t=>t.hierarchy);if(0!==t.length)return Sl=0,JSON.stringify(t,null,2)}function kl(){Sl=0;const t=Al.call(this);return yl.call(this),t}function El(t){if(t)try{Sl++,gl.call(this,JSON.parse(t),{x:15*Sl,y:15*Sl})}catch(e){Wr(e,t)}}const Cl=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]),r=n.length,i=new Uint8Array(r);for(let t=0;t<r;t++)i[t]=n.charCodeAt(t);e(new Blob([i],{type:"image/png"}))})}(t)},resolveUrl:function(t,e){const n=document.implementation.createHTMLDocument(),r=n.createElement("base");n.head.appendChild(r);const i=n.createElement("a");return n.body.appendChild(i),r.href=e,i.href=t,i.href},getAndEncode:function(t){const e=3e4;jl.impl.options.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());return new Promise(function(n){const r=new XMLHttpRequest;let i;if(r.onreadystatechange=s,r.ontimeout=o,r.responseType="blob",r.timeout=e,r.open("GET",t,!0),r.send(),jl.impl.options.imagePlaceholder){const t=jl.impl.options.imagePlaceholder.split(/,/);t&&t[1]&&(i=t[1])}function s(){if(4!==r.readyState)return;if(200!==r.status)return void(i?n(i):a("cannot fetch resource: "+t+", status: "+r.status));const e=new FileReader;e.onloadend=function(){const t=e.result.split(/,/)[1];n(t)},e.readAsDataURL(r.response)}function o(){i?n(i):a("timeout of "+e+"ms occured while fetching resource: "+t)}function a(t){Wr(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 r=0;r<n;r++)e.push(t[r]);return e},escapeXhtml:function(t){return t.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(t){return new Promise(function(e,n){const r=new Image;r.onload=function(){e(r)},r.onerror=n,r.src=t})},width:function(t){const n=e(t,"border-left-width"),r=e(t,"border-right-width");return t.scrollWidth+n+r},height:function(t){const n=e(t,"border-top-width"),r=e(t,"border-bottom-width");return t.scrollHeight+n+r}};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",""))}}(),Pl=function(){const t=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(t,i,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 r(e,t,i,s)})}),n});function o(){return!e(t)}},shouldProcess:e,impl:{readUrls:n,inline:r}};function e(e){return-1!==e.search(t)}function n(e){const n=[];let r;for(;null!==(r=t.exec(e));)n.push(r[1]);return n.filter(function(t){return!Cl.isDataUrl(t)})}function r(t,e,n,r){return Promise.resolve(e).then(function(t){return n?Cl.resolveUrl(t,n):t}).then(r||Cl.getAndEncode).then(function(t){return Cl.dataAsUrl(t,Cl.mimeType(e))}).then(function(n){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+Cl.escape(t)+")(['\"]?\\))","g")}(e),"$1"+n+"$3")})}}(),Tl=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(Cl.asArray(document.styleSheets)).then(function(t){const e=[];return t.forEach(function(t){try{Cl.asArray(t.cssRules||[]).forEach(t=>e.push(t))}catch(e){Xr("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 Pl.shouldProcess(t.style.getPropertyValue("src"))})}).then(function(e){return e.map(t)});function t(t){return{resolve:function(){const e=(t.parentStyleSheet||{}).href;return Pl.inlineAll(t.cssText,e)},src:function(){return t.style.getPropertyValue("src")}}}}}(),Ol=function(){return{inlineAll:function e(n){return n instanceof Element?r(n).then(function(){return n instanceof HTMLImageElement?t(n).inline().then(()=>n):Promise.all(Cl.asArray(n.childNodes).map(function(t){return e(t)})).then(()=>n)}):Promise.resolve(n);function r(t){const e=t.style.getPropertyValue("background");return e?Pl.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 Cl.isDataUrl(t.src)?Promise.resolve():Promise.resolve(t.src).then(e||Cl.getAndEncode).then(function(e){return Cl.dataAsUrl(e,Cl.mimeType(t.src))}).then(function(e){return new Promise(function(n,r){t.onload=n,t.onerror=r,t.src=e})})}}}}(),Dl={imagePlaceholder:void 0,cacheBust:!1};function Il(t,e){return function(t){void 0===t.imagePlaceholder?jl.impl.options.imagePlaceholder=Dl.imagePlaceholder:jl.impl.options.imagePlaceholder=t.imagePlaceholder;void 0===t.cacheBust?jl.impl.options.cacheBust=Dl.cacheBust:jl.impl.options.cacheBust=t.cacheBust}(e=e||{}),Promise.resolve(t).then(function(t){return Ll(t,e.filter,!0)}).then(function(t){return function(t){return Ol.inlineAll(t).then(function(){return t})}(t)}).then(function(t){const{bgcolor:n,width:r,height:i,style:s,sx:o=1,sy:a=1}=e||{},c=t.style;n&&(c.backgroundColor=n);r&&(c.width=r+"px");i&&(c.height=i+"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(Cl.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||Cl.width(t),e.height||Cl.height(t))})}function zl(t,e){return Il(t,e).then(Cl.makeImage).then(Cl.delay(100)).then(function(n){const r=function(t){const n=document.createElement("canvas");if(n.width=e.width||Cl.width(t),n.height=e.height||Cl.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 r.getContext("2d").drawImage(n,0,0),r})}function Ll(t,e,n){return n||!e||e(t)?Promise.resolve(t).then(function(t){if(t instanceof HTMLCanvasElement)try{return Cl.makeImage(t.toDataURL()).then(t=>t)}catch(t){Xr(t)}return t.cloneNode(!1)}).then(function(n){return function(t,e,n){const r=t.childNodes;return 0===r.length?Promise.resolve(e):i(e,Cl.asArray(r),n).then(function(){return e});function i(t,e,n){let r=Promise.resolve();return e.forEach(function(e){r=r.then(function(){return Ll(e,n,!1)}).then(function(e){e&&t.appendChild(e)})}),r}}(t,n,e)}).then(function(e){return function(t,e){return e instanceof Element?Promise.resolve().then(n).then(r).then(i).then(s).then(function(){return e}):e;function n(){function n(t,e){function n(t,e){Cl.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 r(){function n(n){const r=window.getComputedStyle(t,n),i=r.getPropertyValue("content");if(""===i||"none"===i)return;const s=Cl.uid(),o=e;o.className=o.className+" "+s;const a=document.createElement("style");function c(t,e,n){const r="."+t+":"+e,i=n.cssText?s(n):o(n);return document.createTextNode(r+"{"+i+"}");function s(t){const e=t.getPropertyValue("content");return t.cssText+" content: "+e+";"}function o(t){return Cl.asArray(t).map(e).join("; ")+";";function e(e){return e+": "+t.getPropertyValue(e)+(t.getPropertyPriority(e)?" !important":"")}}}a.appendChild(c(s,n,r)),e.appendChild(a)}[":before",":after"].forEach(function(t){n(t)})}function i(){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 jl={toSvg:Il,toPng:function(t,e){return zl(t,e||{}).then(function(t){return t.toDataURL()})},toJpeg:function(t,e){return zl(t,e=e||{}).then(function(t){return t.toDataURL("image/jpeg",e.quality||1)})},toBlob:function(t,e){return zl(t,e||{}).then(t=>Cl.canvasToBlob(t))},toPixelData:function(t,e){return zl(t,e||{}).then(function(e){return e.getContext("2d").getImageData(0,0,Cl.width(t),Cl.height(t)).data})},impl:{fontFaces:Tl,images:Ol,util:Cl,inliner:Pl,options:{}}};function Rl(t,e,n,r){const i=this.model_layer,s=i._overlay;return new Promise(function(o,a){if(i){const a=i.get("width"),c=i.get("height");n=n||a,r=r||c;const l=i.get("translate"),h=i.get("scale"),d=Math.min(n/a,r/c);n=a*d,r=c*d,i.set("translate",{x:0,y:0}),i.set("scale",{x:d/Ri,y:d/Ri});let u=tc.createCanvas(n,r);const p=u.getContext("2d");if(i.draw(p),i.set("translate",l),i.set("scale",h),!s)return o(u.toDataURL(t,e)),void(u=null);jl.toPng(s,{sx:d,sy:d,width:n,height:r}).then(function(i){const s=new Image;s.onload=function(){p.drawImage(s,0,0,n,r),o(u.toDataURL(t,e)),u=null},s.src=i},function(n){Wr(n),o(u.toDataURL(t,e)),u=null})}else a("No target model")})}function Fl(){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=[],r=t.sort((t,n)=>e.components.indexOf(t)-e.components.indexOf(n));r.forEach(t=>{n.push(t.bounds)});const i=tc.union(n);let s=t[0].fromParent(i.left,i.top);s=t[0].toScene(s.x,s.y);const o=new Map,a=pl({type:"group",left:s.x,top:s.y,width:i.width,height:i.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}];r.forEach(t=>{c.push({component:t,to_container:a})}),this.app.commander.execute(new hl({changes:c})),this.selected=[a]}function Bl(){if(0===this.selected.length)return;const t=[],e=[];this.selected.forEach(n=>{if(!n.isGroup())return;const r=n.parent;n.components.forEach(n=>{t.push(n),e.push({component:n,to_container:r})}),e.push({component:n,to_container:null})}),this.app.commander.execute(new hl({changes:e})),this.selected=t}function Nl(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=tc.union(e),r=n.left+n.width/2;t.map(t=>{t.symmetryX(r)})}function Yl(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=tc.union(e),r=n.top+n.height/2;t.map(t=>{t.symmetryY(r)})}function Vl(){Kc.around(this.app.commander,Nl,this)}function Gl(){Kc.around(this.app.commander,Yl,this)}function Hl(t,e,n){const r=this.findAll(t,n);return r.forEach(t=>{t.set(e)}),r}function Ul(t){Kc.around(this.app.commander,t)}function Wl(){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 Xl="left",ql="right",Kl="center",$l="bottom",Ql="middle",Zl=[Xl,ql,Kl,"top",Ql,$l];function Jl(t){if(!this.hasSameParentForAllSelected||-1===Zl.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck),n=this.app.commander;Kc.around(n,function(){!function(t,e){const n=e[0].parent,{width:r,height:i}=n.bounds;switch(t){case Xl:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:0}}break;case Kl:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:r/2-n.width/2}}break;case ql:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:r-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 Ql:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:i/2-n.height/2}}break;case $l:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:i-n.height}}break;default:;}}(t,e)})}function th(t){t instanceof Array||(t=[t]),this.trigger("addstart",t)}function eh(){this.trigger("stylepastestart")}function nh(){this.trigger("stylepastestop")}function rh(){this.trigger("databindpastestart")}function ih(){this.trigger("databindpastestop")}let sh=0,oh=0,ah=0,ch=null;function lh(){ah++;const t=performance.now(),e=t-oh;e>=1e3&&(sh=Math.round(1e3*ah/e),oh=t,ah=0),ch=requestAnimationFrame(lh)}function hh(){null!==ch&&(cancelAnimationFrame(ch),ch=null)}function dh(){return null===ch&&(oh=performance.now(),ah=0,ch=requestAnimationFrame(lh)),sh}const uh=function(){const t=document.createElement("canvas").getContext("2d");return(window.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)}();function ph(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 fh=Math.sqrt(3);function gh(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 mh(t,n,r){switch(t){case"none":default:return null;case"arrow":{const t=new e.Shape;t.moveTo(0,0),t.lineTo(-fh*n.X,-n.Y),t.lineTo(-fh*n.X,n.Y),t.closePath();const r=new e.ShapeGeometry(t),i=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(r,i)}}case"sharp-arrow":{const t=new e.Shape;t.moveTo(0,0),t.lineTo(-fh*n.X,-n.Y),t.lineTo(n.X/1.5-fh*n.X,0),t.lineTo(-fh*n.X,n.Y),t.closePath();const r=new e.ShapeGeometry(t),i=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(r,i)}}case"open-arrow":{const t=[-(fh*n.X+r),-n.Y,0,-r,0,0,-(fh*n.X+r),n.Y,0],e=new f;e.setPositions(t);const i=new p({linewidth:r,worldUnits:!0});return{line2:new u(e,i)}}case"diamond":{const t=new e.Shape;t.moveTo(-n.X,0),t.lineTo(0,-n.Y),t.lineTo(n.X,0),t.lineTo(0,n.Y),t.closePath();const r=new e.ShapeGeometry(t),i=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(r,i)}}case"oval":{const t=new e.CircleGeometry(n.X,24);t.scale(1,n.Y/n.X,1);const r=new e.MeshBasicMaterial({side:e.DoubleSide});return{mesh:new e.Mesh(t,r)}}case"cross":{const t=new e.Group,i=new f;i.setPositions([-n.X,-n.Y,0,n.X,n.Y,0]);const s=new p({linewidth:r,worldUnits:!0}),o=new u(i,s);o.computeLineDistances(),t.add(o);const a=new f;a.setPositions([n.X,-n.Y,0,-n.X,n.Y,0]);const c=new p({linewidth:r,worldUnits:!0}),l=new u(a,c);return l.computeLineDistances(),t.add(l),{group:t}}}}function yh(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function bh(t,n,r,i){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,begin:c="none",beginSize:l="size2",end:h="arrow",endSize:d="size2",label:g}=r,m=(new e.Vector3).subVectors(n,t),y=m.length(),b=new e.Group;if(y<.01)return b;const v=m.clone().normalize(),x=yh(c,a),_=yh(h,a),w=t.clone().add(v.clone().multiplyScalar(x)),M=n.clone().sub(v.clone().multiplyScalar(_));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 A=function(t,n,r,i){const{strokeStyle:s,alpha:o=1,lineWidth:a=2,lineDash:c="solid"}=r,l=new f;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:g,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 p({color:d?16777215:h.getHex(),linewidth:a,worldUnits:!0,vertexColors:d,dashed:g,dashSize:m,gapSize:y,transparent:o<1||Array.isArray(s)&&s.some(t=>t.length>7),opacity:o,resolution:i}),v=new u(l,b);return v.computeLineDistances(),v}(w,M,r,i);b.add(A);const k=(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 r=t.mesh||t.line2||t.group;if(r){if(r.position.copy(e),r.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(i)}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(i)}});b.add(r)}};C(mh(h,gh(d,a),a),n,k);if(C(mh(c,gh(l,a),a),t,E),g){const r=(new e.Vector3).addVectors(t,n).multiplyScalar(.5);r.y+=3;const i=function(t,n,r){const i="Arial",s=ph(256,64),o=s.getContext("2d");o.font=`bold 28px ${i}`;const a=o.measureText(t).width;o.fillStyle=n,o.fillRect(0,0,a+12,40),o.fillStyle="white",o.font=`bold 28px ${i}`,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(r);const d=(a+12)/40;return h.scale.set(4*d,4,1),h}(g,"string"==typeof s?s:Array.isArray(s)&&s[1]||"#00B050",r);b.add(i)}return b}const vh=.001;function xh(t,e,n){let r=1;if(n&&"none"!=n&&"transparent"!=n){r=e*("string"==typeof n?y(n).getAlpha():1)}else r=0;t.opacity=r,t.transparent=r<1}function _h(t){const e=y(t);return e.isValid()?e.toHexString():t}const wh={width:1,height:1,depth:1},Mh={x:1,y:1,z:1},Sh={x:0,y:0,z:0},Ah={x:0,y:0,z:0},kh={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 Eh(t){if(!t)return{metalness:0,roughness:.4,emissive:"#000000",emissiveIntensity:0,opacity:1,envMapIntensity:.5,side:"double",castShadow:!0,receiveShadow:!1};const e=kh[t.preset??"default"]??kh.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 Ch={double:e.DoubleSide,front:e.FrontSide,back:e.BackSide};function Ph(t){return Ch[t]??e.DoubleSide}function Th(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=Ph(e.side)}const Oh=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap"];function Dh(t){for(const e of Oh){const n=t[e];n?.dispose()}t.dispose()}function Ih(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)Dh(t)}})}function zh(t,e,n){const r=document.createElement("canvas");r.width=e,r.height=n;const i=r.getContext("2d");if(!i)return null;let s;if("radial"===t.gradientType){const r=e/2,o=n/2,a=Math.max(e,n)/2;switch(t.center){case"left-top":s=i.createRadialGradient(0,0,0,0,0,2*a);break;case"right-top":s=i.createRadialGradient(e,0,0,e,0,2*a);break;case"left-bottom":s=i.createRadialGradient(0,n,0,0,n,2*a);break;case"right-bottom":s=i.createRadialGradient(e,n,0,e,n,2*a);break;default:s=i.createRadialGradient(r,o,0,r,o,a)}}else{const r=t.rotation??0,o=e/2,a=n/2,c=Math.cos(r)*o,l=Math.sin(r)*a;s=i.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 i.fillStyle=s,i.fillRect(0,0,e,n),r}function Lh(t){const{fillStyle:n}=t.state;if("object"==typeof n)return"pattern"===n.type&&n.image?function(t,n){const{width:r,height:i}=t.state,s=Math.abs(r)||1,o=Math.abs(i)||1,a=new e.Texture;a.colorSpace=e.SRGBColorSpace;const c=new Image;return"data"!==String(n.image).substring(0,4)&&(c.crossOrigin="anonymous"),c.onload=()=>{const r=2*s,i=2*o,l=document.createElement("canvas");l.width=r,l.height=i;const h=l.getContext("2d");if(h){if(n.color&&(h.fillStyle=n.color,h.fillRect(0,0,r,i)),n.fitPattern)h.drawImage(c,0,0,r,i);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=(r-t)/2,l=(i-e)/2;break;case"left-top":break;case"left-bottom":l=i-e;break;case"right-top":a=r-t;break;case"right-bottom":a=r-t,l=i-e;break;case"left":l=(i-e)/2;break;case"right":a=r-t,l=(i-e)/2;break;case"top":a=(r-t)/2;break;case"bottom":a=(r-t)/2,l=i-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,r,i),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<i;s+=e)for(let i=n;i<r;i+=t)h.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,i,s,t,e);h.restore()}}a.image=l,a.minFilter=e.LinearFilter,a.needsUpdate=!0,t.invalidate()}},c.onerror=t=>{Wr("Pattern texture load error:",t)},c.src=t.app.url(n.image),a}(t,n):"gradient"===n.type&&n.colorStops?.length?function(t){const n=zh(t,256,256);if(!n)return;const r=new e.CanvasTexture(n);return r.colorSpace=e.SRGBColorSpace,r.needsUpdate=!0,r}(n):void 0}function jh(t,e){return-1!==t.findIndex(t=>t in e)}class Rh{static buildFillStyleTexture(t){return Lh(t)}constructor(t){this._focused=!1,this._suppressOnchange=!1,this._onchangeWrapper=(t,e)=>{this._suppressOnchange||this.onchange(t,e)},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=Eh(this.component.state.material3d);this._applyShadow(t.castShadow,t.receiveShadow),this.object3d.name=this.component.state.id}updateMaterial3d(){const t=Eh(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 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(){for(const t of this.object3d.children)Ih(t);return this.object3d.userData={},this.object3d.clear()}updateTransform(){const{x:t,y:e,z:n}=this.position,{x:r,y:i,z:s}=this.rotation,{x:o,y:a,z:c}=this.scale;this.object3d.position.set(t,e,n),this.object3d.rotation.set(r,i,s),this.object3d.scale.set(Math.max(o,vh),Math.max(a,vh),Math.max(c,vh))}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();return t+e+this.syncZPosOffset}get center(){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:r=0}=this.component.parent?.bounds??{},{tx:i=0,ty:s=0}=this.component.delta();return{x:t+i-n/2,y:e+s-r/2,z:this.cz}}get dimension(){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,vh),Math.max(e,vh),Math.max(n,vh))}syncAnimationDelta(){const t=this.component.delta();this.updatePosition();const{rotationX:e=0,rotationY:n=0,rotation:r=0}=this.component.state,i=t.theta||0;this.object3d.rotation.set(e,-(r+i),n);const{scale:s}=this.component.state,o="number"==typeof s?s:s?.x??1,a=t.sx??1,c=t.sy??1;this.object3d.scale.set(Math.max(o*a,vh),Math.max(o*c,vh),Math.max(o,vh));const l=t.fade||0;if(0!==l){const t=(this.component.state.alpha??1)*(1-l);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(){return this.effectiveDepth/2}get textSurfaceYOffset(){return this.effectiveDepth-this.syncZPosOffset}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:r=0}=e.parent?.bounds??{},i=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-i.width/2,top:t.position.z-o+r/2-i.height/2,width:i.width,height:i.height},e.set({zPos:t.position.y-a-this.syncZPosOffset,rotationX:t.rotation.x,rotation:-t.rotation.y,rotationY:t.rotation.z}),this._suppressOnchange=!1}applyDimensionFromGizmo(t){this._suppressOnchange=!0,this._component.set(t),this._suppressOnchange=!1}onchange(t,e){jh(["cx","cy","cz","zPos","left","top"],t)&&this.updatePosition(),jh(["width","height","depth","lineWidth"],t)&&this.updateDimension(),jh(["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(),jh(["text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline"],t)&&this.updateText(),"material3d"in t&&this.updateMaterial3d()}}class Fh extends Rh{get syncZPosOffset(){return this.effectiveDepth}getObject3dInstance(){return new g(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:r=0}=e.parent?.bounds??{},i=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-i.width/2,top:t.position.z-o+r/2-i.height/2,width:i.width,height:i.height},e.set({zPos:t.position.y-a-this.syncZPosOffset,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 Bh=new Map;let Nh;function Yh(t,e){Bh.set(t,e)}function Vh(t){Nh=t}function Gh(t){const e=t.buildRealObject();if(e)return e;const n=t.model?.type,r=n?Bh.get(n):void 0;if(r)return r(t);if(t.isHTMLElement()){const e=Bh.get("html-overlay-element");if(e)return e(t)}return Nh?.(t)}function Hh(t,n,r){if(!t.hasTextProperty||t.textHidden)return;const i=t._realObject;if(!i?.object3d)return;const{text:s="",bold:o=Ni.BOLD,italic:a=Ni.ITALIC,fontFamily:c=Ni.FONT_FAMILY,fontColor:l=Ni.FONT_COLOR,fontSize:h=Ni.FONT_SIZE,textAlign:d=Ni.TEXT_ALIGN,textBaseline:u=Ni.TEXT_BASELINE,width:p,height:f}=t.model,m=Math.abs(p)||1,y=Math.abs(f)||1,b=document.createElement("textarea"),v=new AbortController;Fi.forEach(t=>{b.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:v.signal})}),b.value=s;const x="right"===d||"end"===d?"right":"left"===d||"start"===d?"left":"justify"===d?"justify":"center";let _="0";if("bottom"===u||"alphabetic"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);_=Math.max(0,y-t)+"px"}else if("middle"===u){const t=1.2*h*Math.max(1,(s.match(/\n/g)||[]).length+1);_=Math.max(0,(y-t)/2)+"px"}b.style.cssText=[`width: ${m}px`,`height: ${y}px`,`padding: ${_} 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: ${x}`].join("; ");const w=new g(b),M=i.object3d;M.updateWorldMatrix(!0,!1);const S=new e.Vector3,A=new e.Quaternion,k=new e.Vector3;M.matrixWorld.decompose(S,A,k);const E=new e.Vector3(0,i.textSurfaceYOffset,0);E.multiply(k),E.applyQuaternion(A),w.position.copy(S).add(E);const C=(new e.Quaternion).setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2);w.quaternion.copy(A).multiply(C),w.scale.copy(k),n.css3DScene.add(w),r();const P=n.css3DRenderer.domElement,T=P.style.getPropertyValue("pointer-events"),O=P.style.getPropertyPriority("pointer-events"),D=[];let I=b;for(;I&&I!==P.parentElement;)D.push({el:I,saved:I.style.pointerEvents}),I.style.setProperty("pointer-events","auto","important"),I=I.parentElement;b.focus(),b.select();let z=!1;const L=t.root?.selected;b.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"!==t.code&&(t.shiftKey||"Enter"!==t.code&&"NumpadEnter"!==t.code)||(z="Escape"===t.code,b.blur())},{signal:v.signal});const j=()=>{n.css3DScene.remove(w);for(const{el:t,saved:e}of D)e?t.style.pointerEvents=e:t.style.removeProperty("pointer-events");O?P.style.setProperty("pointer-events",T,O):T&&P.style.setProperty("pointer-events",T),v.abort(),b.removeEventListener("blur",j),L&&t.root&&(t.root.selected=L),z||b.value===s||t.app.commander.execute(new Kc({changes:[{component:t,before:{text:s},after:{text:b.value}}]})),r()};b.addEventListener("blur",j)}class Uh 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 Wh(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity}function Xh(t){const{fillStyle:n,floorMaterial3d:r}=t.state,i=Eh(r);if("none"===n)return;const s=new e.BoxGeometry(1,1,1);let o;if(n){const r=Rh.buildFillStyleTexture(t);if(r){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:r}),new e.MeshStandardMaterial({color:t})];n.forEach(t=>Wh(t,i)),o=n}else if("string"==typeof n){const t=new e.MeshStandardMaterial({color:n});Wh(t,i),o=t}}if(!o){const t=new e.MeshStandardMaterial({color:"#e0e0e0"});Wh(t,i),o=t}const a=new e.Mesh(s,o),{width:c,height:l}=t.state;return a.scale.set(c,l,5),a.rotation.x=-Math.PI/2,a.position.y=-3.5,a.name="floor",a.receiveShadow=!1!==r?.receiveShadow,a.castShadow=!0===r?.castShadow,a}const qh={studio:class extends Uh{constructor(){super(),this.name="StudioEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:16777215,emissiveIntensity:r}),s=new o(t,i);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 Uh{constructor(){super(),this.name="WarehouseEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:15266047,emissiveIntensity:r}),s=new o(t,i);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 Uh{constructor(){super(),this.name="FactoryEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:15791615,emissiveIntensity:r}),s=new o(t,i);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 Uh{constructor(){super(),this.name="OfficeEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:16775408,emissiveIntensity:r}),s=new o(t,i);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 Uh{constructor(){super(),this.name="HomeEnvironment",this.position.y=-3.5;const t=new r;t.deleteAttribute("uv");const e=new i({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 i({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,r)=>{const i=new c({color:0,emissive:16771280,emissiveIntensity:r}),s=new o(t,i);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)}}};class Kh{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,this._applyEnvironment("studio")}_applyEnvironment(t){this._envTexture&&this._envTexture.dispose();const n=new(0,qh[t]),r=new e.PMREMGenerator(this._renderer);this._envTexture=r.fromScene(n).texture,this._scene.environment=this._envTexture,n.dispose(),r.dispose()}setSky(t,n){if(!this._scene||!this._renderer)return;const r=t;r&&r in qh?(this._applyEnvironment(r),this._scene.background=this._envTexture):this._scene.background="color"===t&&n?new e.Color(n):null}addFloor(t){const e=Xh(t);e&&this._scene.add(e)}updateFloor(t){if(!this._scene)return;const e=this._scene.children.find(t=>"floor"===t.name);e&&(Ih(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,Ih(this._scene),this._scene.clear()),delete this._scene,delete this._mixer,delete this._renderer,this._timer&&this._timer.disconnect(),delete this._timer}}class $h{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,r){const{fov:i,near:s,far:o,cameraX:a,cameraY:c,cameraZ:l}=r,h=t/n;this._perspCamera=new e.PerspectiveCamera(i,h,s,o);let d=.4*n,u=.4*t;return this._cameraZPos=Math.min(250,Math.floor(.5*Math.min(t,n))),null!=a&&(d=a*t),null!=c&&(u=c*n),null!=l&&(this._cameraZPos=l*Math.floor(Math.min(t,n))),this._perspCamera.position.set(d,this._cameraZPos,u),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,r=(n.top-n.bottom)/2,i=t/e;n.left=-r*i,n.right=r*i,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,r,i,s){this._orthoCamera||(this._orthoCamera=new e.OrthographicCamera(-1,1,1,-1,.1,5e4)),this.updateOrthoFrustum(n,r,i,s);const o=this._orthoCamera;o.zoom=1;const a=2*Math.max(n,r);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,r){if(!this._orthoCamera)return;const i=(n||t)/(r||e),s=Math.max(t,e)/2;i>=1?(this._orthoCamera.left=-s*i,this._orthoCamera.right=s*i,this._orthoCamera.top=s,this._orthoCamera.bottom=-s):(this._orthoCamera.left=-s,this._orthoCamera.right=s,this._orthoCamera.top=s/i,this._orthoCamera.bottom=-s/i),this._orthoCamera.updateProjectionMatrix()}destroy(){delete this._perspCamera,delete this._orthoCamera,this._activeView="perspective"}}class Qh{constructor(){this._noSupportWebgl=!1}get renderer(){return this._renderer}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}setupWebGL(t,n,r){try{const i=document.createElement("canvas"),s=i.getContext("webgl2");if(!s)return this._noSupportWebgl=!0,!1;const o=new e.WebGLRenderer({canvas:i,context:s,precision:r.precision,alpha:!0,antialias:r.antialias,logarithmicDepthBuffer:!1!==r.postprocessing,premultipliedAlpha:!1});return o.autoClear=!0,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.NoToneMapping,o.toneMappingExposure=r.exposure,o.shadowMap.enabled=!0,o.shadowMap.type=e.PCFShadowMap,o.setClearColor(16777215,1),o.setPixelRatio(window.devicePixelRatio),o.setSize(t,n,!1),i.style.width="100%",i.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 m}setupComposer(t,n,r,i,s){const o=new e.WebGLRenderTarget(r,i,{samples:4});this._composer=new b(this._renderer,o),this._composer.setSize(r,i);const a=new v(t,n);this._composer.addPass(a);const c=new x(new e.Vector2(r,i),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,r,i,o)=>{const a=s.visible;s.visible=!1,t(e,n,r,i,o),s.visible=a}}return this._outlinePass=c,this._composer.addPass(c),this._composer.addPass(new w),this._composer.addPass(new _),this._composer}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){this._renderer?.setSize(t,e,!1),this._css3DRenderer?.setSize(t,e),this._composer?.setSize(t,e)}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)}renderCSS3D(t){this._css3DRenderer?.render(this.css3DScene,t)}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?.dispose(),delete this._composer,delete this._renderer}disposeCSS3DScene(){if(this._css3DScene){[...this._css3DScene.children].forEach(t=>this._css3DScene.remove(t))}}}class Zh{constructor(){this.lights=[]}get hemiLight(){return this._hemiLight}get dirLight(){return this._dirLight}setup(t,n,r){this._scene=t,this._camera=n;const{hemisphere:i,directional:s,point:o}=r;if(this._hemiLight=new e.HemisphereLight(i.skyColor,i.groundColor,i.intensity),t.add(this._hemiLight),this.lights.push(this._hemiLight),s){if(this._dirLight=new e.DirectionalLight(s.color,s.intensity),!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))}setDirectionalEnabled(t,n){if(t&&!this._dirLight&&this._camera){const t=n?.color??16777215,r=n?.intensity??.8;this._dirLight=new e.DirectionalLight(t,r),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 Jh=1e-6;class td{constructor(){this._enabled=!0,this._state=0,this._autoRotate=!1,this._autoRotateSpeed=2,this._dampingFactor=.15,this._rotateSpeed=.1,this._panSpeed=1,this._lastScale=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 r=n.state;this._autoRotate=!n.app?.isEditMode&&(r.autoRotate||"orbit"===r.cameraAutoPlay)||!1,this._autoRotateSpeed=r.rotationSpeed||2,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:1,1===this._state?this._rotateStart.set(t.offsetX,t.offsetY):this._panStart.set(t.offsetX,t.offsetY)))}onDragMove(t){this._enabled&&(this._isOrthoLocked?(this._state=2,this._handlePanMove(t.offsetX,t.offsetY)):(this._state=t.altKey?2:1,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,r=e.offsetY??e.pageY;if(this._isOrthoLocked)return this._panStart.set(n,r),void(this._state=4);switch(t.touches.length){case 1:this._rotateStart.set(n,r),this._state=3;break;case 2:this._lastScale=t.scale||1,this._panStart.set(n,r),this._state=4;break;default:this._state=0}}onTouchMove(t){const e=t.touches[0],n=e.offsetX??e.pageX,r=e.offsetY??e.pageY;if(this._isOrthoLocked)this._handlePanMove(n,r);else switch(t.touches.length){case 1:if(3!==this._state)return;this._handleRotateMove(n,r);break;case 2:if(Math.abs(this._lastScale-(t.scale||1))>.05)return;if(4!==this._state)return;this._handlePanMove(n,r);break;default:this._state=0}}onTouchEnd(t){this._lastScale=1,this._state=0}onKeyDown(t){switch(t.keyCode){case 38:this._pan(0,7);break;case 40:this._pan(0,-7);break;case 37:this._pan(7,0);break;case 39: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)>Jh||8*(1-this._lastQuaternion.dot(t.quaternion))>Jh)&&(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),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)>Jh||8*(1-this._lastQuaternion.dot(t.quaternion))>Jh)&&(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()}markCameraChanged(){this._host?.invalidate()}dollyAtCursor(t,e,n){this._onUserInteraction?.();const r=this._camera,i=r.position.distanceTo(this._target),s=Math.max(1,Math.min(5e4,i*t));if(Math.abs(s-i)<Jh)return;const o=Math.tan(r.fov/2*Math.PI/180)/r.zoom,a=i-s,c=e*a*o*r.aspect,l=n*a*o;this._panLeftV.setFromMatrixColumn(r.matrix,0).multiplyScalar(c),this._panUpV.setFromMatrixColumn(r.matrix,1).multiplyScalar(l),this._target.add(this._panLeftV).add(this._panUpV),r.position.add(this._panLeftV).add(this._panUpV),this._panCalcOffset.subVectors(r.position,this._target).normalize().multiplyScalar(s),r.position.copy(this._target).add(this._panCalcOffset),this._host?.invalidate()}zoomOrthoAtCursor(t,e,n){this._onUserInteraction?.();const r=this._camera,i=r.zoom,s=Math.max(.1,Math.min(20,i*t)),o=e*(r.right-r.left)/2*(1/i-1/s),a=n*(r.top-r.bottom)/2*(1/i-1/s);this._panLeftV.setFromMatrixColumn(r.matrix,0).multiplyScalar(o),this._panUpV.setFromMatrixColumn(r.matrix,1).multiplyScalar(a),this._target.add(this._panLeftV).add(this._panUpV),r.position.add(this._panLeftV).add(this._panUpV),r.zoom=s,r.updateProjectionMatrix(),this._host?.invalidate()}destroy(){delete this._camera,delete this._host}_handleRotateMove(t,e){this._rotateEnd.set(t,e),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart);const n=this._host?.element;let r,i;if(n){const t=n.getBoundingClientRect();r=t.width,i=t.height}else{const{width:t,height:e}=this._host.bounds;r=t,i=e}this._sphericalDelta.theta-=2*Math.PI*this._rotateDelta.x/r*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,r=this._host?.element;let i,s;if(r){const t=r.getBoundingClientRect();i=t.width,s=t.height}else{const{width:t,height:e}=this._host.bounds;i=t,s=e}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/s),this._target.add(this._panLeftV).add(this._panUpV),n.position.add(this._panLeftV).add(this._panUpV)}_pan(t,e){t*=this._panSpeed,e*=this._panSpeed;const n=this._host?.element;let r,i;if(n){const t=n.getBoundingClientRect();r=t.width,i=t.height}else{const{width:t,height:e}=this._host.bounds;r=t,i=e}const s=this._camera;if(s.isPerspectiveCamera){this._panCalcOffset.copy(s.position).sub(this._target);let n=this._panCalcOffset.length();n*=Math.tan(s.fov/2*Math.PI/180),this._panLeftV.setFromMatrixColumn(s.matrix,0),this._panLeftV.multiplyScalar(-2*t*n/i),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(s.matrix,1),this._panUpV.multiplyScalar(2*e*n/i),this._panOffset.add(this._panUpV)}else s.isOrthographicCamera&&(this._panLeftV.setFromMatrixColumn(s.matrix,0),this._panLeftV.multiplyScalar(-t*(s.right-s.left)/s.zoom/r),this._panOffset.add(this._panLeftV),this._panUpV.setFromMatrixColumn(s.matrix,1),this._panUpV.multiplyScalar(e*(s.top-s.bottom)/s.zoom/i),this._panOffset.add(this._panUpV))}}class ed{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,r,i,s){this._mouse.x=(t-n)/i*2-1,this._mouse.y=-(e-r)/s*2+1}getObjectByRaycast(t,e){const n=this.getObjectsByRaycast(t,e);if(n&&n.length>0)for(const t of n){let e=t.object;for(;e;){if(e.userData.context){if(e.visible)return e;break}e=e.parent}}}getObjectsByRaycast(t,e){return this._raycaster.setFromCamera(this._mouse,t),this._raycaster.intersectObjects(e.children,!0)}handleClick(t,e,n){this._lastFocused&&(this._lastFocused.focused=!1);const r=this.getObjectByRaycast(t,e),i=r?.userData.context;return i&&(i.focused=!0,this._lastFocused=i,i.component?.trigger("click",n)),i}handleHover(t,e,n){const r=this.getObjectByRaycast(t,e),i=r?.userData.context;i!==this._lastHovered&&(this._lastHovered&&(this._lastHovered.component?.trigger("mouseleave",n),this._lastHovered=void 0),i&&(this._lastHovered=i,this._lastHovered.component?.trigger("mouseenter",n)))}destroy(){this._lastFocused=void 0,this._lastHovered=void 0}}class nd{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}setup(t,e,n){this.destroy(),this._scene=n;const r=document.createElement("div");r.style.cssText="position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none",r.setPointerCapture=()=>{},r.releasePointerCapture=()=>{},e.appendChild(r),this._proxyElement=r,this._controls=new M(t,r),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;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)}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)}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}}class rd{constructor(){this._mouseDownAltKey=!1}captureAltKey(t){this._mouseDownAltKey=t}setupCallbacks(t,e,n,r){t.onDraggingChanged=r=>{e.setEnabled(!r);const i=n();i&&(r?this._onDragStart(t,i):this._onDragEnd(t,i),i.app?.commander?.execute(null),i.invalidate())},t.onObjectChange=e=>{this._syncFromGizmo(t,e),n()?.invalidate()},t.onAttachChanged=t=>{r?.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),"scale"===t.mode&&this._captureScalePreDrag(t)}_performAltDragDuplicate(t){const e=t.root?.selected||[];if(0===e.length||!t.root)return;const n=t.root,r=[];for(const t of e){const e=t.parent,i=new Map,s=fl(t,t=>{const e=n.getNewRefid();return void 0!==t&&i.set(t,e),e});s.replaceRefids(i),e.addComponent(s),r.push({component:s,to_container:e})}this._altDragDuplicates=r}_captureMultiSelectState(t,e){const n=t.attached;if(n)if("translate"===t.mode){const t=new Map,r=n.position;for(let n=1;n<e.length;n++){const i=e[n]._realObject;i?.object3d&&t.set(i,i.object3d.position.clone().sub(r))}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 r=e[n]._realObject;r?.object3d&&t.set(r,r.object3d.rotation.clone())}this._multiSelectInitialRotations=t}else if("scale"===t.mode){const t=new Map;for(let n=1;n<e.length;n++){const r=e[n],i=r._realObject;if(i?.object3d){const{left:e,top:n,width:s,height:o}=r.bounds,{zPos:a=0}=r.state,c=r.state.depth;t.set(i,{left:e,top:n,width:s,height:o,depth:c,zPos:a,scaleX:i.object3d.scale.x,scaleY:i.object3d.scale.y,scaleZ:i.object3d.scale.z})}}this._multiSelectPreDragDimensions=t}}_captureScalePreDrag(t){const e=t.attached,n=e?.userData.context;if(!n||!e)return;const{left:r,top:i,width:s,height:o}=n.component.bounds,{zPos:a=0}=n.component.state,c=n.component.state.depth;this._preDragDimension={left:r,top:i,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===c?n.effectiveDepth:void 0}_onDragEnd(t,e){if(this._altDragDuplicates&&this._altDragDuplicates.length>0&&(e.app?.commander.execute(new hl({changes:this._altDragDuplicates})),this._altDragDuplicates=void 0),this._multiSelectOffsets=void 0,this._gizmoInitialRotation=void 0,this._multiSelectInitialRotations=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()}this._preDragDimension=void 0,this._preDragScale=void 0,this._preDragEffectiveDepth=void 0,this._multiSelectPreDragDimensions=void 0}_syncFromGizmo(t,e){const n=e.userData.context;if(n)if("scale"===t.mode&&this._preDragDimension&&this._preDragScale){if(this._syncDimensionFromGizmo(n,e),this._multiSelectPreDragDimensions&&this._preDragScale){const t=e.scale.x/this._preDragScale.x,n=e.scale.y/this._preDragScale.y,r=e.scale.z/this._preDragScale.z;for(const[e,i]of this._multiSelectPreDragDimensions){const s=i.width*t,o=i.height*r,a={left:i.left+(i.width-s)/2,top:i.top+(i.height-o)/2,width:s,height:o};if(void 0!==i.depth){const t=i.depth*n;a.depth=t,a.zPos=i.zPos+(i.depth-t)/2}e.applyDimensionFromGizmo(a)}}}else{if(n.syncFromObject3D(),"translate"===t.mode&&this._applyGroundSnap(e,n),this._multiSelectOffsets){const n=e.position;for(const[e,r]of this._multiSelectOffsets)e.object3d&&(e.object3d.position.copy(n).add(r),"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,r=e.rotation.z-this._gizmoInitialRotation.z;for(const[e,i]of this._multiSelectInitialRotations)e.object3d&&(e.object3d.rotation.set(i.x+t,i.y+n,i.z+r),e.syncFromObject3D())}}}_applyGroundSnap(t,e){const n=e.effectiveDepth/2,r=t.position.y-n,i=Math.abs(r);if(i<2)t.position.y=n,e.syncFromObject3D();else if(i<10){const s=(i-2)/8,o=1-s*s;t.position.y=n+r*(1-o),e.syncFromObject3D()}}_syncDimensionFromGizmo(t,e){const n=this._preDragDimension,r=this._preDragScale,i=n.width*(e.scale.x/r.x),s=n.height*(e.scale.z/r.z),o={left:n.left+(n.width-i)/2,top:n.top+(n.height-s)/2,width:i,height:s};if(void 0!==n.depth){const t=n.depth*(e.scale.y/r.y);o.depth=t,o.zPos=n.zPos+(n.depth-t)/2}t.applyDimensionFromGizmo(o)}}class id{constructor(){this._mouseIsDown=!1,this._isDragging=!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 r={mousedown:t=>this._onMouseDown(t),mousemove:t=>this._onMouseMove(t),wheel:t=>{t.stopPropagation(),this._delegate.handleWheel(t)},dblclick:t=>{t.stopPropagation(),this._delegate.handleDblClick(t)},contextmenu:t=>{t.preventDefault()},touchstart:t=>{t.stopPropagation(),this._delegate.handleTouchStart(t)},touchmove:t=>{t.stopPropagation(),this._delegate.handleTouchMove(t)},touchend:t=>{t.stopPropagation(),this._delegate.handleTouchEnd(t)},keydown:t=>{this._delegate.handleKeyDown(t)&&t.stopPropagation()},keyup:t=>{(this._delegate.handleKeyUp?.(t)??!1)&&t.stopPropagation()}};t.addEventListener("mousedown",r.mousedown),t.addEventListener("mousemove",r.mousemove),t.addEventListener("wheel",r.wheel),t.addEventListener("dblclick",r.dblclick),t.addEventListener("contextmenu",r.contextmenu),t.addEventListener("touchstart",r.touchstart,{passive:!1}),t.addEventListener("touchmove",r.touchmove,{passive:!1}),t.addEventListener("touchend",r.touchend),t.addEventListener("keydown",r.keydown),t.addEventListener("keyup",r.keyup),this._boundHandlers=r}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 r=n.getBoundingClientRect();return{x:t-r.left,y:e-r.top}}updateMouseNDCFromClient(t,e){const n=this._hostElement?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const r=t-n.left,i=e-n.top;this._event.updateMouseNDC(r,i,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<id.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 r=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:r.x,offsetY:r.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&&!t.metaKey&&!t.ctrlKey){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,r=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+r*r<id.DRAG_THRESHOLD)return;this._isDragging=!0,this._delegate.handleBoxSelectionStart?.(e.x,e.y)}const i=this.clientToElementCoords(t.clientX,t.clientY);this._delegate.handleBoxSelectionUpdate?.(i.x,i.y)},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging)this._delegate.handleBoxSelectionEnd?.(t.shiftKey);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)}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,r=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+r*r<id.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})}const i=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:i.x,offsetY:i.y,altKey:t.altKey})},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)}}id.DRAG_THRESHOLD=16;class sd{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 r=new e.Raycaster;r.setFromCamera(this._event.mouse,n);const i=new e.Vector3;return r.ray.intersectPlane(this._groundPlane,i)}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 r=new e.MeshBasicMaterial({color:48340,opacity:.6,transparent:!0,side:e.DoubleSide,depthTest:!1});this._placementIndicator=new e.Mesh(n,r),this._placementIndicator.renderOrder=999,t.add(this._placementIndicator)}const n=this._pendingModels?.[0],r=n?.rx??n?.width??50,i=n?.ry??n?.height??50;this._placementIndicator.scale.set(r,1,i),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 od={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 ad(t,n,r,i,s,o=new e.Vector3){const a=t*t,c=a*t;return o.set(.5*(2*r.x+(-n.x+i.x)*t+(2*n.x-5*r.x+4*i.x-s.x)*a+(-n.x+3*r.x-3*i.x+s.x)*c),.5*(2*r.y+(-n.y+i.y)*t+(2*n.y-5*r.y+4*i.y-s.y)*a+(-n.y+3*r.y-3*i.y+s.y)*c),.5*(2*r.z+(-n.z+i.z)*t+(2*n.z-5*r.z+4*i.z-s.z)*a+(-n.z+3*r.z-3*i.z+s.z)*c))}class cd{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,r,i=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=r.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),x=od[o.easing??"ease-in-out"];return this._runAnimation(i,x,t=>{s?ad(t,s.prevPos,a,l,s.nextPos,n.position):n.position.lerpVectors(a,l,t);const i=b.clone().slerp(v,t),o=new e.Vector3(0,0,-1).applyQuaternion(i),c=u+(p-u)*t,h=n.position.clone().add(o.multiplyScalar(c));r.restoreTarget(h)}),!0}_animatePathSegment(t,e,n,r,i,s){const o=od[r];this._runAnimation(n,o,n=>{const r=t+(e-t)*n,o=this.evaluatePath(r<=1?r:r-1);o&&(i.position.copy(o.position),s.restoreTarget(o.target))})}_runAnimation(t,e,n){this.stopAnimation(),this._animating=!0,this._animationProgress=0;const r=performance.now(),i=()=>{const s=performance.now()-r,o=Math.min(s/t,1),a=e(o);this._animationProgress=a,n(a),this._onInvalidate?.(),o<1?this._animationId=requestAnimationFrame(i):(this._animating=!1,this._animationId=void 0,this._onAnimationComplete?.())};this._animationId=requestAnimationFrame(i)}_initFromProgress(t,e){const n=t*e,r=Math.min(Math.floor(n),e-1);this._playStartOffset=n-r,this._playIndex=(r+1)%e}startPlay(t,n,r=2e3,i=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??r,h=s?.transitionDuration??i;if(l>=0){const e=l;let r=this._playIndex/a.length;r<=e&&(r+=1),l=-1;const i=this._playStartOffset,c=Math.max(Math.round(h*(1-i)),100);return u(o),void this._animatePathSegment(e,r,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,r,i){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:i(a.position)};const c=t[(this._playIndex-2+s)%s],l=this._slots[c];return l?{prevPos:i(l.position),nextPos:i(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 r=n.length,i=Math.max(0,Math.min(1,t)),s=t=>{const i=this._slots[n[(t%r+r)%r]];return i?new e.Vector3(i.position.x,i.position.y,i.position.z):new e.Vector3},o=t=>{const i=this._slots[n[(t%r+r)%r]];return i?new e.Vector3(i.target.x,i.target.y,i.target.z):new e.Vector3};if(2===r){const t=i<.5?2*i:2*(1-i);return{position:s(0).lerp(s(1),t),target:o(0).lerp(o(1),t)}}const a=i*r,c=Math.min(Math.floor(a),r-1),l=a-c,h=ad(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),x=b.lengthSq()>1e-4?b.normalize():new e.Vector3(0,0,-1),_=v.lengthSq()>1e-4?v.normalize():x.clone(),w=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),x),M=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),_),S=w.clone().slerp(M,l),A=new e.Vector3(0,0,-1).applyQuaternion(S),k=m+(y-m)*l,E=h.clone().add(A.multiplyScalar(k));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 ld{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,r){if(!this._active||!this._hostElement)return this.cancelSelection(),[];const i=this._hostElement.getBoundingClientRect(),s=i.width,o=i.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 r){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),r=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=`${r}px`}}class hd{constructor(){this.sceneManager=new Kh,this.cameraManager=new $h,this.rendererManager=new Qh,this.lightManager=new Zh,this.controlsManager=new td,this.eventManager=new ed,this.gizmoManager=new nd,this.interactionManager=new id,this.placementManager=new sd,this.gizmoOperationManager=new rd,this.bookmarkManager=new cd,this.boxSelectionManager=new ld,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 t=n[0]._realObject;t?.object3d&&this.gizmoManager.attach(t.object3d),this._host?.invalidate()}}get gizmoMode(){return this.gizmoManager.mode}init(t,e){this.interactionManager.cleanup(),this._cleanupEventHandlers(),this._host=t,this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this.sceneManager.scene&&this.destroy(),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:r}=e.bounds;n=Math.abs(n)||1,r=Math.abs(r)||1;const{fov:i=45,near:s=.1,far:o=2e4,antialias:a=!0,precision:c="highp",cameraX:l,cameraY:h,cameraZ:d,exposure:u=1}=e.state,p=e.components||[],f=t?.lightingConfig??{hemisphere:{skyColor:16777215,groundColor:4473924,intensity:.4},directional:{color:16777215,intensity:1,attachToCamera:!0}},g=t?.css3DSceneAttribute??"three-container:css3d-renderer",m=this.sceneManager.setup(),y=this.cameraManager.setup(n,r,{fov:i,near:s,far:o,cameraX:l,cameraY:h,cameraZ:d});this.cameraManager.addToScene(m);const b=e.app?.postprocessing;if(this.rendererManager.setupWebGL(n,r,{precision:c,antialias:a,exposure:u,postprocessing:b})){if(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(),this.sceneManager.addFloor(e),this.sceneManager.setSky(e.state.sky,e.state.skyColor),!1!==e.app.postprocessing){const t=this.gizmoManager.controls?.getHelper();this.rendererManager.setupComposer(m,y,n,r,t)}else this.rendererManager.setDirectRenderTargets(m,y);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,()=>this._host,{onAttachChanged:t=>this.onGizmoAttachChanged?.(t)})}createObjects(t){for(const e of t)this.addObject(e)}addObject(t){if(!t._realObject){try{const{width:e,height:n}=t.bounds;if(!e||!n)return;if(t.isHTMLElement()&&!t.element)return;const r=Gh(t);if(r){if(t._realObject=r,r.update(),r.updateTransform(),r instanceof Fh)this.rendererManager.css3DScene.add(r.object3d);else{const e=t.parent?._realObject?.object3d;e&&e!==this.sceneManager.scene?e.add(r.object3d):this.sceneManager.scene.add(r.object3d)}const e=this._host?.root?.selected;e&&e.length>0&&e[0]===t&&r.object3d&&this.gizmoManager.attached&&this.gizmoManager.attach(r.object3d)}}catch(t){Wr(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.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 Fh?this.rendererManager.css3DScene.remove(n):n.removeFromParent()),e.dispose?.(),t._realObject=void 0}catch(t){Wr(t)}}resize(t,e,n=!1){const r=this._host;if(!r)return;if(void 0===t||void 0===e){const n=r.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 i=t,s=e;clearTimeout(this._resizeDebouncer),this._resizeDebouncer=window.setTimeout(()=>{this._resizeDebouncer=void 0,this._applyResize(i,s)},100)}_applyResize(t,n){this.cameraManager.updateAspect(t,n),this.rendererManager.resize(t,n);const r=new e.Vector2(t,n);for(const t of this._arrows.values())t.traverse(t=>{t instanceof u&&t.material.resolution.copy(r)});this._initialized&&(this.renderThreeD(),this.renderCSS3D())}animate(){if(!this._initialized||!this.controlsManager.isActive)return;this.sceneManager.updateAnimation();const t=this._host?.components||[];for(const e of t)e._animation?.started&&e._realObject&&e._realObject.syncAnimationDelta();this.controlsManager.update(),this.renderThreeD()}renderThreeD(){this._initialized&&this.rendererManager.render()}setCameraView(t,e){const n=this._host;if(!n)return;const{width:r,height:i}=n.bounds,s=n.element,o=s?.clientWidth||r,a=s?.clientHeight||i;let c;c="perspective"===t?this.cameraManager.restorePerspective():this.cameraManager.setOrthoView(t,r,i,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;t?.element&&t.element.appendChild(this.css3DRenderer.domElement)}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.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(),this._redrawHandler=void 0,this._onComponentAdd=void 0,this._onComponentRemove=void 0,this._onSelectionChanged=void 0,this._onAddStart=void 0,this._onAddStop=void 0,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()),this.controlsManager.setup(this.cameraManager.camera,t),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.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,r=t.bounds.height||600,i=e.x+n/2,s=e.z+r/2;gl.call(t.root,this.placementManager.pendingModels,{cx:i,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)},handleBoxSelectionEnd:t=>{this.controlsManager.setEnabled(!0),this._host?.element&&(this._host.element.style.cursor="");const e=this.cameraManager.activeCamera,n=this.sceneManager.scene,r=this._host?.components||[];if(e&&n){const i=this.boxSelectionManager.endSelection(e,n,r);if(i.length>0&&this._host?.root)if(t){const t=(this._host.root.selected||[]).slice();for(const e of i)t.includes(e)||t.push(e);this._host.root.selected=t}else this._host.root.selected=i}else this.boxSelectionManager.cancelSelection()}}}_handleClickAt(t){const n=this._host,r=this.cameraManager.activeCamera;if(!r||!this.sceneManager.scene)return;if(this._pathMarkers&&this._pathMarkers.children.length>0){const t=new e.Raycaster,n=this.eventManager.mouse;t.setFromCamera(n,r);const i=t.intersectObjects(this._pathMarkers.children,!0);if(i.length>0){let t=i[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)}}const i=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),i)return;const s=this.eventManager.handleClick(r,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(),r=n.indexOf(e);-1===r?n.push(e):n.splice(r,1),t.selected=n}else 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?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const r=t-n.left,i=e-n.top;this.eventManager.updateMouseNDC(r,i,0,0,n.width,n.height)}_updateMouseNDC(t){this._updateMouseNDCFromClient(t.clientX,t.clientY)}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 r=this.eventManager.handleClick(n,this.sceneManager.scene,t),i=this._host;return i?.app?.isEditMode&&i.root&&this._applySelection(i.root,r?.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){if("perspective"!==this.cameraManager.activeView){const e=t.deltaY>0?.9:1.1,n=this._host?.element;let r=0,i=0;if(n){const e=n.getBoundingClientRect();r=(t.clientX-e.left)/e.width*2-1,i=-(t.clientY-e.top)/e.height*2+1}this.controlsManager.zoomOrthoAtCursor(e,r,i),this.renderThreeD()}else{const e=Math.pow(.999,-t.deltaY),n=this._host?.element;let r=0,i=0;if(n){const e=n.getBoundingClientRect();r=(t.clientX-e.left)/e.width*2-1,i=-(t.clientY-e.top)/e.height*2+1}this.controlsManager.dollyAtCursor(e,r,i),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){const t=this.eventManager.getObjectByRaycast(n,this.sceneManager.scene),e=t?.userData?.context?.component;if(e?.hasTextProperty)return Hh(e,this.rendererManager,()=>{this.renderThreeD(),this.renderCSS3D()}),!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.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,r=(e?.selected||[]).filter(t=>t!==this._host).map(t=>t.state?.id).filter(Boolean);if(t.shiftKey?n?.redo():n?.undo(),e&&r.length>0){const t=r.map(t=>e.findById(t)).filter(Boolean);t.length>0&&(e.selected=t)}return t.preventDefault(),!0}case"KeyC":return e&&(this._clipboard=Al.call(e)),t.preventDefault(),!0;case"KeyX":return e&&(this._clipboard=kl.call(e)),t.preventDefault(),!0;case"KeyV":return e&&this._clipboard&&El.call(e,this._clipboard),t.preventDefault(),!0;case"KeyD":return e&&(this._clipboard=Al.call(e),this._clipboard&&El.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 Hh(n[0],this.rendererManager,()=>{this.renderThreeD(),this.renderCSS3D()}),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&&yl.call(e),!0}return this._handleArrowKeyMove(t,e)}_handleArrowKeyMove(t,e){const n=e?.selected;if(!n||0===n.length)return!1;const r=t.shiftKey?this._host.MPP||10:1;let i;switch(t.code){case"ArrowLeft":i={x:-r,y:0};break;case"ArrowRight":i={x:r,y:0};break;case"ArrowUp":i={x:0,y:-r};break;case"ArrowDown":i={x:0,y:r}}return!!i&&(Kc.around(this._host.app.commander,()=>{n.forEach(t=>{t.stuck||t.move(i,!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="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?.set?.("threed",!1),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"KeyS":return this.onShortcutHelpToggle?.(),t.preventDefault(),!0;case"KeyB":return this.onBookmarkNavToggle?.(),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:r}=t.bounds,i=Math.floor(Math.min(n,r))||1;return{view:this.cameraManager.activeView,cameraX:e.position.x/(n||1),cameraY:e.position.z/(r||1),cameraZ:e.position.y/i}}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,r={view:t};return e&&(r.perspPosition={x:e.position.x,y:e.position.y,z:e.position.z}),r.orbitTarget={x:n.x,y:n.y,z:n.z},r}captureViewportInfo(){const t=this.cameraManager.activeCamera,e=this.controlsManager.target.clone();let n=0,r=0;if(t?.fov){r=2*t.position.distanceTo(e)*Math.tan(t.fov*Math.PI/180/2),n=r*(t.aspect||1)}return{target:e,visibleWidth:n,visibleHeight:r}}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 r=this.controlsManager.target,i=n.position;let s=r.x,o=r.y,a=r.z;if(i.distanceTo(r)<1){const t=new e.Vector3(0,0,-1).applyQuaternion(n.quaternion);s=i.x+1*t.x,o=i.y+1*t.y,a=i.z+1*t.z}const c={position:{x:i.x,y:i.y,z:i.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,r,i,s){const o=this.cameraManager.activeCamera;if(!o?.position)return;const a=(o.fov||45)*Math.PI/180,c=o.aspect||1,l=i/2/Math.tan(a/2),h=r/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 r=this.cameraManager.activeCamera;if(!r)return;const i=new e.Vector3,s=t._realObject;if(s?.object3d)s.object3d.getWorldPosition(i);else{const{x:e=0,y:n=0}=t.center,{width:r=0,height:s=0}=t.parent?.bounds??{};i.set(e-r/2,0,n-s/2)}const o=this.controlsManager.target,a=r.position.clone().sub(o),c=i.clone().add(a);if(!n)return r.position.copy(c),this.controlsManager.restoreTarget(i),void this._host?.invalidate();const l=r.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;r.position.lerpVectors(l,c,n);const s=h.clone().lerp(i,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(n.length<2)return;const r=[];for(const t of n){const n=this.bookmarkManager.getSlot(t);n&&r.push(new e.Vector3(n.position.x,n.position.y,n.position.z))}let i=0;for(let t=1;t<r.length;t++)i+=r[t].distanceTo(r[t-1]);const s=i/(r.length-1),o=.08*s,a=r.length>=3?new e.CatmullRomCurve3(r,!0,"centripetal").getPoints(30*r.length):r,c=(new e.BufferGeometry).setFromPoints(a),l=new e.LineDashedMaterial({color:4890367,dashSize:.06*s,gapSize:.03*s,opacity:.5,transparent:!0,depthTest:!1});this._pathLine=new e.Line(c,l),this._pathLine.computeLineDistances(),this._pathLine.renderOrder=9999,t.add(this._pathLine),this._pathMarkers=new e.Group,this._pathMarkers.renderOrder=9999;const h=new e.MeshBasicMaterial({color:4890367,opacity:.6,transparent:!0,depthTest:!1}),d=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 r=new e.Vector3(n.position.x,n.position.y,n.position.z),i=new e.Vector3(n.target.x,n.target.y,n.target.z),s=(new e.Vector3).subVectors(i,r).normalize(),a=new e.Group;a.position.copy(r);const c=(new e.Matrix4).lookAt(new e.Vector3(0,0,0),s,new e.Vector3(0,1,0));a.quaternion.setFromRotationMatrix(c);const l=.2*o,u=new e.BoxGeometry(1.2*l,.8*l,l),p=new e.Mesh(u,h);p.renderOrder=9999,a.add(p);const f=Math.max(.06*r.distanceTo(i),.5*l),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 x=new e.Mesh(y,d);x.position.z=.5*-l,x.renderOrder=9999,a.add(x);const _=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(_,3));const M=new e.LineSegments(w,new e.LineBasicMaterial({color:4890367,opacity:.5,transparent:!0,depthTest:!1}));M.position.z=.5*-l,M.renderOrder=9999,a.add(M),a.userData.bookmarkSlotIndex=t,this._pathMarkers.add(a)}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("fov")||t.hasOwnProperty("near")||t.hasOwnProperty("far")){const t=this._host;if(t){const{near:e,far:n,fov:r}=t.state;this.cameraManager.updateProperties({near:e,far:n,fov:r}),this.controlsManager.markCameraChanged()}}let e=!1;if(t.hasOwnProperty("hemiIntensity")&&(this.lightManager.updateHemisphere({intensity:t.hemiIntensity}),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}(t.hasOwnProperty("dirLightColor")||t.hasOwnProperty("dirLightIntensity"))&&(this.lightManager.updateDirectional({color:t.dirLightColor,intensity:t.dirLightIntensity}),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())}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(dh()),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,r,i={}){this.removeArrow(t);const s=n._realObject,o=r._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=bh(a,c,i,new e.Vector2(l.width,l.height));h.name=`arrow-${t}`,h.userData._arrowStyle=i,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 u)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 r=this._getArrowStyle(t);r&&this.addArrow(t,e,n,r)}_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?this.gizmoManager.attached&&this.gizmoManager.attach(t.object3d):this.gizmoManager.detach()}else this.gizmoManager.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()}}lc.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 dd={x:1,y:1},ud={x:0,y:0},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 5l12-1v12l-12-1z"/>\n <circle cx="10" cy="10" r="1.5"/>\n</svg>',fd='<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>',gd='<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>',md='<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>',yd='<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>',bd='<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>',vd={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 xd extends Dc{get nature(){return vd}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,r){this._threeCapability?.addArrow(t,e,n,r)}removeArrow3D(t){this._threeCapability?.removeArrow(t)}clearArrows3D(){this._threeCapability?.clearArrows()}_buildLightingConfig(){const t=this.state,e={hemisphere:{skyColor:16777215,groundColor:4473924,intensity:t.hemiIntensity??1}};return!1!==t.dirLightEnabled&&(e.directional={color:t.dirLightColor||"#ffffff",intensity:t.dirLightIntensity??.8,attachToCamera:!0,castShadow:!1!==t.dirShadowEnabled,shadowMapSize:t.dirShadowMapSize??2048,shadowBias:t.dirShadowBias??-5e-4}),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 hd,this._threeCapability.init(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),this._hide2DLayers();const e=zs.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)this._initCameraFrom2DViewport();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 r=this.root;r?.selected?.length>0&&this._threeCapability._handleSelectionChanged(r.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(";"),r=(t,e)=>{const r=document.createElement("div");return r.innerHTML=t,r.title=e,r.style.cssText=n,this._applyButtonStyle(r,!1),r.addEventListener("mouseenter",()=>{r.dataset.active||(r.style.background="rgba(255,255,255,0.1)")}),r.addEventListener("mouseleave",()=>{this._applyButtonStyle(r,!!r.dataset.active)}),r},i=()=>{const t=document.createElement("div");return t.style.cssText="height:1px;margin:3px 4px;background:rgba(255,255,255,0.1)",t},s=r(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.set("threed",!this.model.threed)}),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(i());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:pd,title:"Perspective"},{view:"top",icon:fd,title:"Top"},{view:"front",icon:gd,title:"Front"},{view:"back",icon:md,title:"Back"},{view:"right",icon:yd,title:"Right"},{view:"left",icon:bd,title:"Left"}],h=[];for(const{view:t,icon:e,title:n}of l){const i=r(e,n);i.dataset.view=t,t===c&&(this._applyButtonStyle(i,!0),i.dataset.active="1"),i.addEventListener("click",()=>{this._threeCapability?.setCameraView(t)}),h.push(i),a.appendChild(i)}a.appendChild(i());const d=r('<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.onShortcutHelpToggle=()=>this._toggleShortcutHelp(),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,r=0,i=0;const s=s=>{const o=s.clientX-e,a=s.clientY-n;t.style.left=r+o+"px",t.style.top=i+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();r=h.left-d.left,i=h.top-d.top,t.style.left=r+"px",t.style.top=i+"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)})}_toggleShortcutHelp(){if("shortcuts"===this._floatingPopup?.dataset.popupType)return void this._closeFloatingPopup();const t=!!this.app?.isEditMode,e=document.createElement("div");e.dataset.popupType="shortcuts",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 r=document.createElement("div");r.textContent="Keyboard Shortcuts",r.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:12px",e.appendChild(r);const i=document.createElement("div");i.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:0 24px",e.appendChild(i);const s=[{label:"Camera",items:[{key:"1",desc:"Perspective",icon:pd},{key:"2",desc:"Top",icon:fd},{key:"3",desc:"Front",icon:gd},{key:"4",desc:"Back",icon:md},{key:"5",desc:"Right",icon:yd},{key:"6",desc:"Left",icon:bd},{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:"S",desc:"This help"}]}].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 r 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=r.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 r.items){const n=document.createElement("div");n.style.cssText="display:flex;justify-content:space-between;align-items:center;padding:2px 0;gap:12px";const r=document.createElement("span");r.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",r.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",r.appendChild(t)}}const i=document.createElement("span");if(i.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",i.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",i.appendChild(e)}n.appendChild(r),n.appendChild(i),e.appendChild(n)}}i.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,r=!!this.app?.isEditMode,i=document.createElement("div");i.dataset.popupType=t,i.tabIndex=-1,i.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)"}),i.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",i.appendChild(o);const a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:2px",i.appendChild(a);const c=e.bookmarkManager,l=()=>{r&&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,r=document.createElement("canvas");r.width=e*n,r.height=e*n,r.style.cssText="width:28px;height:28px;flex-shrink:0;border-radius:50%;background:rgba(0,0,0,0.3)";const i=r.getContext("2d");i.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;i.strokeStyle="rgba(255,255,255,0.12)",i.lineWidth=1,i.beginPath(),i.arc(s,o,a,0,2*Math.PI),i.stroke(),i.strokeStyle="rgba(255,255,255,0.06)",i.beginPath(),i.moveTo(s,2),i.lineTo(s,26),i.moveTo(2,o),i.lineTo(26,o),i.stroke(),i.fillStyle="rgba(255,255,255,0.25)",i.beginPath(),i.arc(s,o,1.5,0,2*Math.PI),i.fill(),i.strokeStyle=`rgba(74,158,255,${.2+.2*p})`,i.lineWidth=1,i.beginPath(),i.moveTo(y,b),i.lineTo(s,o),i.stroke();const v=.6+.4*p;i.fillStyle=`rgba(74,158,255,${v})`,i.beginPath(),i.arc(y,b,3,0,2*Math.PI),i.fill();const x=Math.atan2(g,f),_=Math.PI/8;return i.fillStyle="rgba(74,158,255,0.08)",i.beginPath(),i.moveTo(y,b),i.arc(y,b,.6*a,x+Math.PI-_,x+Math.PI+_),i.closePath(),i.fill(),r},u=()=>{const t=e.getCameraWorldState();if(!t)return-1;const n=.01;for(let e=1;e<=9;e++){const r=c.getSlot(e);if(r&&(Math.abs(t.position.x-r.position.x)<n&&Math.abs(t.position.y-r.position.y)<n&&Math.abs(t.position.z-r.position.z)<n&&Math.abs(t.target.x-r.target.x)<n&&Math.abs(t.target.y-r.target.y)<n&&Math.abs(t.target.z-r.target.z)<n))return e}return-1};let p,f,g=-1;const m=()=>{a.innerHTML="";let t=!1;const r=u(),i=Array.from({length:9},(t,e)=>e+1);for(const s of i){const i=c.getSlot(s),o=!!i,u=s===r;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&&i){const t=d(i);t.style.pointerEvents="none",p.appendChild(t)}const t=document.createElement("span");t.textContent=i?.name||"noname",t.style.cssText=`flex:1;color:${i?.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;${i?.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,r=o?"color:rgba(255,255,255,0.3)":"color:rgba(255,255,255,0.12)";t.style.cssText=`width:16px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;user-select:none;${r}${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&&i&&p.appendChild(d(i)),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=i?.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 r=document.createElement("button");r.textContent="⋮",r.title="Playlist settings",r.style.cssText=h+";color:rgba(255,255,255,0.35);font-size:14px",r.addEventListener("mouseenter",()=>{r.style.background="rgba(255,255,255,0.08)"}),r.addEventListener("mouseleave",()=>{r.style.background="transparent"}),u.appendChild(r)}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 r=t=>{const e=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&n.parentNode.removeChild(n);let r=null;for(const n of e){if(n===y)continue;const e=n.getBoundingClientRect();if(t.clientY<e.top+e.height/2){r=n;break}}if(r)a.insertBefore(n,r);else{const t=e[e.length-1];t&&t.after(n)}},i=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",r),t.removeEventListener("pointerup",i),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",r),t.addEventListener("pointerup",i)})}if(!n&&o&&i){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",r="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=r+";width:55px";const d=document.createElement("input");d.type="number",d.min="0",d.step="500",d.value=String(i.holdDuration??2e3),d.style.cssText=n;const u=document.createElement("span");u.textContent="ms",u.style.cssText=r,d.addEventListener("change",()=>{const t=parseInt(d.value);i.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=r+";width:55px";const b=document.createElement("input");b.type="number",b.min="0",b.step="200",b.value=String(i.transitionDuration??1200),b.style.cssText=n;const v=document.createElement("span");v.textContent="ms",v.style.cssText=r,b.addEventListener("change",()=>{const t=parseInt(b.value);i.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 x=document.createElement("div");x.style.cssText=o;const _=document.createElement("span");_.textContent="Easing",_.style.cssText=r+";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",(i.easing??"ease-in-out")===t&&(e.selected=!0),w.appendChild(e)}w.addEventListener("change",()=>{i.easing="ease-in-out"===w.value?void 0:w.value,l()}),x.appendChild(_),x.appendChild(w),t.appendChild(x);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=r+";width:55px";const A=document.createElement("input");A.type="checkbox",A.checked=!!i.excludeFromPlay,A.style.cssText="accent-color:#4a9eff;cursor:pointer",A.addEventListener("change",()=>{i.excludeFromPlay=A.checked||void 0,l()}),M.appendChild(S),M.appendChild(A),t.appendChild(M),y.appendChild(t);const k=p.querySelector("button:last-child");k&&(e&&(k.style.color="#4a9eff"),k.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",k.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 r=document.createElement("button");r.textContent="▶",r.title="Play / Stop",r.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",r.addEventListener("mouseenter",()=>{r.style.background="rgba(74,158,255,0.15)",r.style.color="#4a9eff"}),r.addEventListener("mouseleave",()=>{r.style.background="rgba(255,255,255,0.06)",r.style.color=c.isPlaying?"#4a9eff":"rgba(255,255,255,0.5)"}),r.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),i.addEventListener("keydown",t=>{if("Space"===t.code&&"none"!==p.style.display){t.preventDefault(),t.stopPropagation();const r=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(r),a()}}),t.appendChild(n),t.appendChild(r),p.appendChild(t),i.appendChild(p);const a=()=>{const t=c.isPlaying;r.textContent=t?"⏹":"▶",r.style.color=t?"#4a9eff":"rgba(255,255,255,0.5)"};let l=-1;const h=()=>{if(this._floatingPopup===i){if(c.isPlaying){const t=c.playProgress;n.value=String(Math.round(1e3*t)),l=-1}else{"⏹"===r.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";r&&(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()})),i.appendChild(t)}const y=e.onBookmarkChanged;e.onBookmarkChanged=()=>{y?.(),this._floatingPopup===i&&(m(),v=-2,n||e.showBookmarkPath())},this._showFloatingPopup(i,!0),n||e.showBookmarkPath();let b,v=u();const x=()=>{if(this._floatingPopup!==i)return;const t=u();if(t!==v){v=t;a.querySelectorAll("[data-slot-index]").forEach(e=>{const n=parseInt(e.dataset.slotIndex||"-1"),r=e.firstElementChild;if(!r)return;const i=n===t,s=i?"rgba(74,158,255,0.1)":"transparent";r.style.background=s,r.style.boxShadow=i?"inset 0 0 0 1px rgba(74,158,255,0.25)":"none",r.dataset.active=i?"1":""})}b=requestAnimationFrame(x)};b=requestAnimationFrame(x);const _=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=_,_()}}_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.onShortcutHelpToggle=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,r=e>0?e:this.element.clientWidth,i=n>0?n:this.element.clientHeight;r>0&&i>0&&this._threeCapability.resize(r,i,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 r=this._threeCapability.domElement,i=this._threeCapability.css3DRenderer?.domElement,s=[...this._threeCapability.decoratorOutlines];this._threeCapability.dispose(),this._threeCapability=void 0,i?.parentNode&&i.parentNode.removeChild(i);for(const t of this.components)if(t.isHTMLElement()&&t.element){const e=t.element,n=this.getOverlay(t);n?.appendChild(e)}r?.parentNode&&r.parentNode.removeChild(r),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},r=this.get("scale")||{x:1,y:1},i=r.x||1,s=r.y||1,{width:o=800,height:a=600}=this.state,c=(t/2-n.x)/i-o/2,l=(e/2-n.y)/s-a/2,h=t/i,d=e/s;this._threeCapability.positionCameraForViewport(c,l,h,d,this._lastCameraState)}_init2DViewportFrom3DCamera(t,e,n){if(!e&&!n)return;const{w:r,h:i}=this._getViewportSize(),{width:s=800,height:o=600}=this.state,a=t.x+s/2,c=t.z+o/2,l=e>0?r/e:1/0,h=n>0?i/n:1/0,d=Math.max(.1,Math.min(Math.min(l,h),10)),u=r/2-a*d,p=i/2-c*d;this.set({translate:{x:u,y:p},scale:{x:d,y:d}})}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")}dispose(){this._deactivateThreeD(),this._removeToolbar(),super.dispose(),this._overlay=null,this._decoratorOverlay&&(zs.getInstance().removeOverlay(this._decoratorOverlay),this._decoratorOverlay.parentNode&&this._decoratorOverlay.parentNode.removeChild(this._decoratorOverlay),this._decoratorOverlay=null),this._decoratorAuxOverlay&&(zs.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?lc.get("three"):hc}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,zs.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,zs.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 r=null;try{r=getComputedStyle(this.target)}catch(t){return void Wr(t,this.target)}let i=r?parseFloat(r.getPropertyValue("width")):this.target.clientWidth,s=r?parseFloat(r.getPropertyValue("height")):this.target.clientHeight;switch(n){case"both":case"ratio":break;case"width":s=e*i/t,this.element.style.overflowX="hidden",this.element.style.overflowY="auto";break;case"height":i=t*s/e,this.element.style.overflowX="auto",this.element.style.overflowY="hidden";break;default:i=Math.max(t,i),s=Math.max(e,s),this.element.style.overflowX=i>t?"hidden":"auto",this.element.style.overflowY=s>e?"hidden":"auto"}this.fitSize(this.element,!0),this.fitSize(this.canvas,!0,i,s),this.fitSize(this.auxCanvas,!0,i,s),this.is3dMode&&this._threeCapability.resize(i,s)}draw(t){if(this.is3dMode){if(!this.element)return;this._threeCapability.renderCSS3D()}else this.model.threed||super.draw(t)}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 r=n.length-1;r>=0;r--){const i=n[r];if(!i.isContainer())continue;const s=i.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||e.is3dMode)return;if("KeyQ"===t.code)return e.set("threed",!0),void t.preventDefault();const n={Digit1:"perspective",Digit2:"top",Digit3:"front",Digit4:"back",Digit5:"right",Digit6:"left"}[t.code];n&&(e._pendingCameraView=n,e.set("threed",!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||(zs.getInstance().invalidateOverlay(this.decoratorOverlay),zs.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=ud,scale:n=dd,rotation:r=0}=this.model,{left:i,top:s}=this.bounds;t.style.left=i+"px",t.style.top=s+"px",t.style.transform=`rotate(${r}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 xd||!n.model.event||!n.model.event.hover)return;if(n.hidden)return;const r=n.model.event.hover;r&&this._doEventAction(r,n,!0,t)}_onmouseleave_all(t,e){if(t.stopPropagation(),!e)return;const n=e.origin;if(!this.app||this.app.isEditMode)return;const r=n.model.event&&n.model.event.hover;r&&this._doEventAction(r,n,!1,t)}_onclick(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,r=n.model.event?.tap;r&&this._doEventAction(r,n,!0,t)}_onmousedownup(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,r=n.model.event?.tap;r&&r.pressed&&this._doMouseDownUpEventAction(r,n,"mousedown"==t.type||"touchstart"==t.type,t)}_doMouseDownUpEventAction(t,e,n,r){const{pressed:i=!1}=t;i&&(n?function(t){if(t.hasOwnProperty("_backupShadow"))return;const e=t.get("shadow");t._backupShadow=e;const{left:n=0,top:r=0}=e||{};t.delta("tx",n),t.delta("ty",r),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,r){let{action:i,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:r,lineWidth:i,fillStyle:s}=t.state;t.__backup_emphasize={strokeStyle:r,lineWidth:i,fillStyle:s},t.setState(n)}(e):c&&function(t){"__backup_emphasize"in t&&(t.setState(t.__backup_emphasize),delete t.__backup_emphasize)}(e)),i)switch(i){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"==r.type||n?ac.show(e,s,c,{x:r.offsetX,y:r.offsetY}):c&&ac.hide(e,s);break;case"toggle-info-window":if(!s)return;ac.toggle(e,s,!1,{x:r.offsetX,y:r.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);kc.show(e,s,{data:t&&this.root.findFirst(t,e)?.data,output:a,modal:"modal-popup"===i,closable:!0,draggable:!0,origin:"auto"});break;case"close-scene":this.closeScene(e.data);break;case"goto":case"goto-playlist":this.trigger(i,s,l,e);break;case"mouse-cursor":n?this.target.style.cursor=s||"auto":c&&(this.target.style.cursor="auto");break;default:this.trigger(i,s,o,e)}}applyDecorator(t,e,n={}){const r=this.getDecoratorOverlay(t);if(r){zs.getInstance().addToOverlay(r,t,e,n)}}offdecorator(t,e){const n=this.getDecoratorOverlay(t);if(n){zs.getInstance().removeFromOverlay(n,t,e)}}resetDecorator(t,e){const n=this.getDecoratorOverlay(e);n&&zs.getInstance().removeAllFromOverlay(n,t)}onChangeForDecorator(t,e,n){const{origin:r}=n,i=this.getDecoratorOverlay(r);zs.getInstance().invalidateOverlay(i)}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 _d(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.from.component===n&&(!e||t.from.anchor===e))}function wd(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.to.component===n&&(!e||t.to.anchor===e))}function Md(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){Wr(t)}t.closePath()}}),t.restore()}contains(t,e){let n=super.contains(t,e);if(n)return n;const r=this.anchors||[];for(const i of r){const r=i.bounds;if(!r)continue;const{left:s,top:o,width:a,height:c}=r;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 _d(this,t)}findOutletEnds(t){return function(t,e){return _d(t,e).map(t=>t.toEnd?.component).filter(Boolean)}(this,t)}findInletLines(t){return wd(this,t)}findInletEnds(t){return function(t,e){return wd(t,e).map(t=>t.fromEnd?.component).filter(Boolean)}(this,t)}}}xd.Popup=kc,tc.register("model-layer",xd);const Sd={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0}}],help:"scene/component/rect"},Ad={ondragmove:function(t,e,n){const{left:r,width:i,height:s}=n.model;let o=(n.fromParent(t.x,t.y).x-r)/(i/2)*100;o=nc(o,i,s),n.set({round:o})}};class kd extends(Md(rc(ec))){is3dish(){return!0}get controls(){let{left:t,top:e,width:n,round:r,height:i}=this.state;return r=null==r?0:nc(r,n,i),[{x:t+n/2*(r/100),y:e,handler:Ad}]}get nature(){return Sd}}tc.register("rect",kd);const Ed=[1,2,10,20,50,50,50,50,50,50];class Cd extends(rc(ec)){render(t){const{lineWidth:e=1,fillStyle:n="lightgray",font:r="15px Arial",left:i,top:s,origin:o,width:a,height:c,side:l="bottom",strokeStyle:h="#000000",scale:d=1}=this.state;t.translate(i,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=r;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 x=Math.ceil(o/v);const _=this.app.PPM/v,w=_<=1.1?1:Ed[Math.round(_)]||100;1!=w&&(x+=(w-x%w)%w);let M=Math.ceil(x*v);const S=o+a;for(t.fillStyle=h;M<S;){if(x%10==0){t.moveTo(M-o,y),t.lineTo(M-o,f);const e=(x/10).toString(),n=t.measureText(e);t.fillText(e,M-o-n.width-6,b)}else x%5==0?(t.moveTo(M-o,m),t.lineTo(M-o,f)):(t.moveTo(M-o,g),t.lineTo(M-o,f));x+=w,M=Math.ceil(x*v)}}}tc.register("ruler",Cd);const Pd=20,Td=20,Od=90*Math.PI/180,Dd="9px Verdana",Id=20,zd="#f4f4f4",Ld="#999";function jd(t,e,n){return{left:-t.x,top:-t.y,width:Pd,height:Id}}function Rd(t,e,n,r){return{left:Pd-t.x,top:0-t.y,origin:20-t.x,width:e-Pd,height:Id}}function Fd(t,e,n,r){const i={x:0-t.x+10,y:-t.y+Td+(n-Td)/2},s=tc.transcoordRR(0-t.x,-t.y+Td,i,Od);return{left:s.x-(n-Td),top:s.y,origin:20-t.y,width:n-Td,height:Id}}function Bd(t){const e=t.get("translate");return{left:-e.x,top:-e.y,width:t.canvas.width/Ri,height:t.canvas.height/Ri}}tc.register("guide-layer",class extends Oc{constructor(t,e){super(t,e),this.appScale={x:1,y:1},"disabled"!==t.ruler&&(this.hruler=new Cd({left:Pd,top:0,origin:20,margin:0,height:Id,unit:"m",rotation:0,font:Dd,fillStyle:zd,strokeStyle:Ld,capturable:!1}),this.vruler=new Cd({left:0,top:0,origin:20,margin:0,height:Id,unit:"m",rotation:Od,font:Dd,side:"top",fillStyle:zd,strokeStyle:Ld,capturable:!1}),this.origin_rect=new kd({left:-20,top:-20,width:20,height:20,fillStyle:zd,strokeStyle:Ld,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=Bd(this));const t=this.rootModel,e=Object.assign({},t.get("translate"));e.x<Pd&&(e.x+=Pd),e.y<Td&&(e.y+=Td);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=Bd(this);const{width:r,height:i}=this.screen_coord;this.hruler.set(Rd(e,r)),this.vruler.set(Fd(e,0,i)),this.origin_rect.set(jd(e))}resize(){super.resize(),this.screen_coord=Bd(this);const{width:t,height:e}=this.screen_coord;this.hruler&&(this.hruler.set(Rd(this.model.translate,t)),this.vruler.set(Fd(this.model.translate,0,e)),this.origin_rect.set(jd(this.model.translate)))}render(t){if(this.rootModel?.is3dMode)return;if(!this.guide)return;t.save();const{x:e,y:n}=this.guide,{top:r,left:i,width:s,height:o}=this.screen_coord;t.beginPath(),t.moveTo(e,r),t.lineTo(e,r+o),t.moveTo(i,n),t.lineTo(i+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=Bd(this),this.hruler){const{translate:t}=this.model,{width:e,height:n}=this.screen_coord;this.hruler.set(Rd(t,e)),this.vruler.set(Fd(t,0,n)),this.origin_rect.set(jd(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)}});tc.register("shift-layer",class extends Oc{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 Nd(t,e,n,r){const i=t.selected;let s=r?i.slice(0):[];r&&s.length>0?e=s[0].parent:e.isContainer()||(e=e.parent);const o=e.layout.capturables(e),a=!!e.layout.joinType;if(r&&n.selected.forEach(t=>{s.splice(s.indexOf(t),1)}),n.selected=[],o.forEach(t=>{t.capturable&&function(t,e,n){const{sx:r,sy:i,ex:s,ey:o}=e;let a,c,l,h;if(r>s?(a=s,c=r):(a=r,c=s),i>o?(l=o,h=i):(l=i,h=o),n){const e=t.bounds,n=t.transcoordS2TR(e.left,e.top),r=t.transcoordS2TR(e.left+e.width,e.top+e.height),i=n.x,s=r.x,o=n.y,d=r.y,u=Math.min(a,i,c,s),p=Math.max(a,i,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-i)||g-f>Math.abs(h-l)+Math.abs(d-o))}{const e=t.path;if(!e)return Wr("컴포넌트에 get path가 잘못 구현되어있음.",t),!1;for(let n=0;n<e.length;n++){const r=t.transcoordS2TR(e[n].x,e[n].y);if(a>r.x||c<r.x||l>r.y||h<r.y)return!1}return!0}}(t,n,a)&&-1==s.indexOf(t)&&n.selected.push(t)}),s=s.concat(n.selected),i.length!==s.length)t.selected=s;else for(let e=0;e<s.length;e++)if(i[e]!=s[e]){t.selected=s;break}}function Yd(t,e,n,r,i){i||Nd(t,e,n,r)}function Vd(t,e){const n=t.components||[];for(const t of n){Vd(t,e);const n=e.indexOf(t);-1!=n&&e.splice(n,1)}}tc.register("add-layer",class extends Oc{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:r,ex:i,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,r,i-n,s-r),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:r,ex:i,ey:s}=this.addbox;gl.call(this.root,this.models,{left:Math.min(n,i),top:Math.min(r,s),width:Math.abs(i-n),height:Math.abs(s-r)}),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:r}=this.toLocal(t.offsetX,t.offsetY);gl.call(this.root,this.models,{cx:n,cy:r}),this.root.trigger("addstop")}});tc.register("selection-layer",class extends Oc{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)}contains(t,e){return!1}render(t){const e=this.selbox;if(e){const{sx:n,sy:r,ex:i,ey:s}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,r,i-n,s-r),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,r=n.selected;if(1!==r.length)return!1;let i=r[0];const s=i.parent;if(!s||s===n)return!1;if("Tab"===t.code){const e=s.layout.capturables(s);let n=e.indexOf(i);if(-1==n){if(!s.indexOf(i))return Xr("Container not contains [",i,"] as a component"),!1;n=0}const r=e.length;t.shiftKey?n--:n++,i=e[(n+r)%r]}else{if(!s.layout.keyNavigate)return!1;i=s.layout.keyNavigate(s,i,t)||i}n.selected=[i],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 r=t.parent;for(;r.parent.isGroup();)r=r.parent;let i=[],s=!1,o=!1;if(this.selected.forEach(t=>{let e=t.parent;if(t!==r){for(;e.parent&&e.parent.isGroup();)e=e.parent;e===r&&(i.push(t),s=!0)}else o=!0}),s)if(e.shiftKey){if(-1!=n)return void this._pendingDecision(e);i.push(t)}else{if(-1!=n)return void this._pendingDecision(e);i=[t]}else{if(o)return void this._pendingDecision(e);if(e.shiftKey)if(this.selected.length>0){if(-1!=this.selected.indexOf(r))return;i=[...this.selected,r]}else i=[r];else i=[r]}this.selected=i}onmousedown_comp(t,e){const{origin:n}=e;if(this.downpoint=null,t.shiftKey){if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(-1!=this.selected.indexOf(n))return void this._pendingDecision(t);{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),Vd(n,t)),t.push(n),this.selected=t}}else{if(n.parent.isGroup())return void this._selectGroupItem(n,t);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;let r=this.selected.indexOf(n);if(-1==r&&n.parent.isGroup()&&(r=this.selected.indexOf(n.parent)),-1!==r&&t.shiftKey){const t=this.selected.slice();return r>-1&&t.splice(r,1),void(this.selected=t)}n.parent.isGroup()&&(this.selected=[n])}ondragstart_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:r,y:i}=this.toLocal(t.offsetX,t.offsetY);this.selbox={sx:r,sy:i,selected:[]}}ondragmove_selbox(t,e){const{origin:n}=e;if(!n.stuck)return;const{x:r,y:i}=this.toLocal(t.offsetX,t.offsetY);this.selbox&&(this.selbox.ex=r,this.selbox.ey=i,Yd(this,n,this.selbox,t.shiftKey,!1),this.invalidate())}ondragend_selbox(t,e){const{origin:n}=e;n.stuck&&(this.last_pos=null,this.selbox=null,Yd(this,null,null,!1,!0),this.invalidate())}});class Gd{constructor(t){this.layer=t}draw(t,e,n){const{left:r,top:i,width:s,height:o}=e.bounds;0!=s&&0!=o&&(t.beginPath(),t.rect(r,i,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(r,i,s,o),t.stroke(),t.closePath())}}class Hd{constructor(t){this.layer=t}draw(t,e,n){const r=e.bounds;t.beginPath(),t.rect(r.left-4/n.x,r.top-4/n.y,r.width+8/n.x,r.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 Ud{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,r){const i=n.controls;return!!i&&(i.every((i,s)=>(Math.abs(t-i.x)<=4/r.x&&Math.abs(e-i.y)<=4/r.y&&(this.active={component:n,index:s,handler:i.handler}),!this.active)),!!this.active)}draw(t,e,n){const r=e.controls;r&&r.forEach((e,r)=>{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:r,index:i}=this.active;let s=r.toLocal(e.offsetX,e.offsetY);s=r.toParent(s.x,s.y),n&&"function"==typeof n[t]&&n[t](s,i,r)}onmousedown(t){this.onevent("onmousedown",t)}ondragstart(t){const e=this.active;e.changes=Kc.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;Kc.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function Wd(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}const Xd=15*Math.PI/180;class qd{constructor(t){this.layer=t}reset(){this.active=null,this.created=null}get selected(){return this.layer.selected}contains(t,e,n,r){return!!n.mutable&&(n.path.every((i,s)=>(Math.abs(t-i.x)<=4/r.x&&Math.abs(e-i.y)<=4/r.y&&(this.active={component:n,index:s}),!this.active)),!!this.active)}startLinkProcess(t,e,n){try{const r=pl(e,t.app,void 0);return t.rootModel.addComponent(r),this.layer.selected=[r],this.active={component:r,index:1},this.ondragstart(n),r}catch(t){Xr(t)}}draw(t,e,n){if(!e.mutable||e.stuck)return;const r=e.path,i=this.active;r.forEach((r,s)=>{t.beginPath(),t.ellipse(r.x,r.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.fillStyle="#fff",i&&i.component===e&&i.index===s&&(t.strokeStyle="#fa7703",i.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=Kc.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:r,offsetY:i}=t;let s=e.toLocal(r,i);if(s=e.toParent(s.x,s.y),t.shiftKey){const t=e.path.length;let r=e.isLine()&&0==n?e.path[1]:e.path[(n-1+t)%t];r=e.toParent(r.x,r.y);let i=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),i=Wd(s,r))}const c=Math.round((Wd(r,s)-i)/Xd)*Xd+i;s=function(t,e,n){return{x:Math.cos(e)*n+t.x,y:Math.sin(e)*n+t.y}}(r,c,(o=r,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(r,i,t=>!t.isConnectable());if(t){const{x:o,y:a}=t.toLocal(r,i),c=this.layer.get("scale")||{x:1,y:1},l=this.layer.counterEnd,h=(t.anchors||[]).find(n=>{const{name:r,inout:i,multiplicity:s=1/0,position:h,filter:d}=n;if(l){const{anchor:t,fromto:e}=l;if(t&&("out"===t.inout&&"out"===i||"in"===t.inout&&"in"===i))return!1;if("from"===e&&"out"===i||"to"===e&&"in"===i)return!1}else Wr("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(r);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}}}e.mutatePath(null,function(t){t[n]=s})}ondragend(t){const{component:e,index:n,changes:r}=this.active;if(0===n||n===e.path.length-1){const{offsetX:r,offsetY:i}=t,s=e.rootModel.capture(r,i,t=>t===e||t.isLine()),{x:o,y:a}=s.toLocal(r,i),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 hl({changes:[{component:this.created,to_container:this.created.parent}]});this.created.app.commander.execute(t)}else Kc.after(r,e.app.commander);e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function Kd(t,e,n){return t.filter(t=>{const{name:r,inout:i,multiplicity:s=1/0,filter:o}=t;if(n){const{anchor:t,fromto:e}=n;if(t&&("out"===t.inout&&"out"===i||"in"===t.inout&&"in"===i))return!1;if("from"===e&&"out"===i||"to"===e&&"in"===i)return!1}else if("in"===i)return!1;return!(s!==1/0&&e.findInOutLines(r).length>=s)&&(!o||!n||!!o.call(t,n))})}class $d{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,r){const i=this.active?.component===n&&this.active?.anchor;this.active=null;const s=this.layer.counterEnd;return Kd(n.isConnectable()&&!n.disposed&&this.getAnchorHandles(n,r)||[],n,s).every(s=>{const o=i===s.name?2:1;return s&&s.position&&Math.abs(t-s.position.x)<=4*o/r.x&&Math.abs(e-s.position.y)<=4*o/r.y&&(this.active={component:n,anchor:s.name,template:s.template}),!this.active}),!!this.active}getAnchorHandles(t,e){const{width:n,height:r}=t.bounds;return n*e.x<30||r*e.y<30?[]:t.anchors}draw(t,e,n){if(!e.get("refid")||e.isLine())return;const r=this.active,i=this.active?.component===e&&this.active?.anchor,s=this.layer.counterEnd;Kd(e.isConnectable()&&!e.disposed&&this.getAnchorHandles(e,n)||[],e,s).forEach(s=>{const{name:o,position:a}=s,c=i===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",r&&r.component===e&&r.anchor===o&&(t.strokeStyle="#fa7703",r.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e,anchor:n,template:r}=this.active,i=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,...r,from:{component:e.get("refid"),anchor:n,position:i},to:{position:i}},t)}ondragmove(t){}ondragend(t){}}function Qd(t,e){const{left:n,top:r,width:i,height:s}=t,o=n+i/2,a=r+s/2,c=n+i,l=r+s,h=i*e.x>50,d=s*e.y>50;return[{x:n,y:r},h?{x:o,y:r}:{x:null,y:null},{x:c,y:r},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 Zd{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,r){if(!n.resizable)return!1;const i=Qd(n.bounds,r);for(let s=0;s<i.length;s++){const o=i[s];if(null!=o.x&&null!=o.y&&Math.abs(t-o.x)<=4/r.x&&Math.abs(e-o.y)<=4/r.y)return this.active={component:n,index:s},!0}return!1}draw(t,e,n){if(e.isLine())return;const{left:r,top:i,width:s,height:o}=e.bounds;if(t.beginPath(),t.rect(r-4/n.x,i-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;Qd(e.bounds,n).forEach((r,i)=>{null!=r.x&&null!=r.y&&(t.beginPath(),t.rect(r.x-4/n.x,r.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===i&&(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:r,boundsList:i,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:r,top:i,width:s,height:o}=t.bounds;let a,c;switch(e){case 0:a=r,c=i;break;case 1:a=r+s/2,c=i;break;case 2:a=r+s,c=i;break;case 3:a=r+s,c=i+o/2;break;case 4:a=r+s,c=i+o;break;case 5:a=r+s/2,c=i+o;break;case 6:a=r,c=i+o;break;case 7:a=r,c=i+o/2}const l=a,h=c,d=t.fromScene(n.x,n.y);return{dx:d.x-l,dy:d.y-h}}(n,r,o);this.layer.selected.filter(t=>t.resizable).forEach((n,s)=>{n.bounds=i[s],function(t,e,n,r,i,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+=r,a+=i,c-=r,l-=i;break;case 1:a+=i,l-=i;break;case 2:a+=i,c+=r,l-=i;break;case 3:c+=r;break;case 4:c+=r,l+=i;break;case 5:l+=i;break;case 6:o+=r,c-=r,l+=i;break;case 7:o+=r,c-=r}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,r,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 Jd=2*Math.PI,tu=Math.PI/2;function eu(t,e){const n=t.bounds;return{x:n.left+n.width/2,y:n.top-20/e.y}}class nu{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,r){if(!n.rotatable)return!1;const i=eu(n,r);return Math.abs(t-i.x)<=4/r.x&&Math.abs(e-i.y)<=4/r.y&&(this.active={component:n},!0)}draw(t,e,n){if(!e.rotatable)return;t.beginPath();const r=eu(e,n);t.lineWidth=1.5/n.x,t.moveTo(r.x,r.y+20/n.y),t.lineTo(r.x,r.y),t.strokeStyle="#656565",t.stroke(),t.beginPath(),t.ellipse(r.x,r.y,4/n.x,4/n.y,0,0,Jd,!0),t.stroke(),t.fillStyle="#fff",t.fill();const i=this.active;i&&i.component===e&&(t.strokeStyle="#fa7703",t.stroke(),i.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 r=e.rotatePoint,i=e.get("rotation")||0;let s=Math.atan((r.y-n.y)/(r.x-n.x));s=r.x>=n.x?s-tu:tu+s;const o=s-i;this.layer.selected.filter(t=>t.rotatable).forEach((e,n)=>{const r=((e.get("rotation")||0)+o)%Jd;e.set("rotation",e.adjustRotation(r,t.shiftKey))})}ondragend(t){const{component:e}=this.active;e.app.commander.execute(null,!1)}}tc.register("modeling-layer",class extends Dc{constructor(t,e){super(t,e),this.pathHandler=new qd(this);const n=this.pathHandler,r=new Ud(this),i=new Zd(this),s=new nu(this);this._modelers=[n,r,i,s],this._control_mode_modelers=[r,n,i,s],this.focusOutline=new Gd(this),this.groupOutline=new Hd(this),this.anchorHandler=new $d(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 r=this.fromParent(t,e),i=this.get("scale")||{x:1,y:1};let s;if(this._state_dragging){if(this._counter_end){let n=i;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(r.x,r.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=i;a.scalable?s=a.fromScene(r.x,r.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=i;if(this.anchorTarget.scalable?s=this.anchorTarget.fromScene(r.x,r.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,r){const i=[];let s=e.parent;if(e.isRootModel())return t.save(),r(t,e,n),void t.restore();for((t=this.getContext(e))==this.auxContext2D&&(n={x:1,y:1});s&&!s.isRootModel();)i.push(s),s=s.parent;t.save(),i.reverse().forEach(function(e){const n=e.rotatePoint;t.translate(n.x,n.y);const r=e.get("scale");r&&t.scale(r.x,r.y),t.rotate(e.get("rotation")),t.translate(-n.x,-n.y);const i=e.bounds;t.translate(i.left,i.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),r(t,e,n),t.restore()}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:r}=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*Ri,e.y*Ri),t.scale(n.x*Ri,n.y*Ri),r&&t.rotate(r),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 r=n[0].parent;for(;r.parent.isGroup();)r=r.parent;this._componentDrawer(t,r,e,(t,e,n)=>{this.groupOutline.draw(t,e,n)})}n.forEach(n=>{this._componentDrawer(t,n,e,(t,e,n)=>{this.reversedModelers.forEach(r=>r.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:r,deliverer:i}=n;r===i&&(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,r=t.dataTransfer.files;if(r.length<1)return;const i=this.rootModel.toLocal(t.offsetX,t.offsetY),s=this.rootModel;Promise.all(Array.from(r).map(t=>new Promise((e,n)=>{const r=new FileReader;r.addEventListener("loadend",t=>{e(r.result)}),["error","abort"].forEach(t=>r.addEventListener(t,t=>{n(t)})),r.readAsDataURL(t)}))).then(e=>{if(t.altKey)return Kc.around(this.app.commander,()=>{n.ondropfile(r,e)}),void(this.selected=[n]);const o=[],a=e.map((t,e)=>{let n;const a=r[e].type,c=r[e].name;return a.startsWith("image/")?(n=pl({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,r)=>{const i=new Image;i.src=t,i.onload=()=>{n.set({width:i.width,height:i.height}),e()},i.onerror=t=>{r(t)}}))):a.startsWith("audio/")?n=pl({type:"audio",top:0,left:0,width:100,height:100,src:t},s.app):a.startsWith("vnd.ms-excel/")||/\.xlsx?$/.test(c)?n=pl({type:"excel",top:0,left:0,width:100,height:100,src:t},s.app):qr("dropped file",r[e]),n&&(n.center=i,i.x+=50,i.y+=50),n}).filter(Boolean).map(t=>({component:t,to_container:s}));a.length>0&&Promise.all(o).then(()=>{this.app.commander.execute(new hl({changes:a})),this.selected=a.map(t=>t.component)},t=>{Wr(t)})},t=>{Wr(t)})}onwheel_scale(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer;let r;if(t.shiftKey)r=-1!=navigator.userAgent.indexOf("Win")?t.deltaY<0?1:-1:t.deltaX<0?1:-1,t.altKey?Kc.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("letterSpacing")||Ni.LETTER_SPACING;e+=r,t.set("letterSpacing",e)})}):Kc.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("fontSize")||Ni.FONT_SIZE;e<1&&(e=1),e+=r,t.set("fontSize",e)})});else{r=t.deltaY<0?1:-1;const e=n.get("scale")||{x:1,y:1},i=n.get("translate"),s=t.offsetX,o=t.offsetY,a=n.toLocal(s,o),c=.1*r,l={x:e.x+c,y:e.y+c};if(r<0&&e.x<.2||r>0&&e.x>10)return;n.set("scale",l);const h=n.toLocal(s,o);n.set("translate",{x:i.x+(h.x-a.x)*l.x,y:i.y+(h.y-a.y)*l.y})}}});function ru(){const t=arguments,e=t[t.length-1],n=this.event_pump;n.listeners.forEach(r=>{!function(t,e,n,r,i){for(const s in n){const o=n[s];if(Sa(s,r.origin,0,t))for(const t in o){const n=o[t];t==r.name&&(r.listener=e,n.apply(e,i))}}}(n.deliverer,r.listener,r.cloned_handlers,e,t)})}tc.register("scroll-layer",class extends Oc{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:r,width:i,height:s}=this.vscroller;t.globalAlpha="v"==e?1:.3,t.fillRect(n,r,i,s)}if(this.hscroller){const{left:n,top:r,width:i,height:s}=this.hscroller;t.globalAlpha="h"==e?1:.3,t.fillRect(n,r,i,s)}t.stroke(),t.restore()}resize(){super.resize(),this.calcScrollerBounds()}contains(t,e){const n=this.vscroller,r=this.hscroller;return this.setState("scrolling",n&&t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height?"v":r&&t>=r.left&&t<=r.left+r.width&&e>=r.top&&e<=r.top+r.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:r,clientHeight:i}=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/r,p=o/i;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:r}=this.rootModel.model,{x:i=1,y:s=1}=this._scale||{},{x:o=0,y:a=0}=this._translate||{},c=n/t,l=r/e;let h={left:-o/i/c,top:e-10,width:t/i/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()}}});class iu{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)",ru,{event_pump:this})}stop(){this.deliverer.off("(all)",ru)}on(t,e){const n=Object.assign({},e);Object.keys(n).forEach(e=>{if(0==e.indexOf("?")){const r=n[e],i=e.substr(1),s=t.get(i);delete n[e],s?n[s]=r:Xr("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 r=this.listeners[n];r.listener!==t||e&&r.handlers!==e||this.listeners.splice(n,1)}}clear(){this.listeners=[]}dispose(){this.stop(),this.clear()}}class su{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 r=e[n];if("(self)"===n&&void 0===t.on)throw new Error("(self) selector not available when deliverer is not a event handlable object.");Ea(n,this.root,t).forEach(n=>{const i=new iu(n);i.on(t,r),i.start(),this.eventMaps.push({eventPump:i,listener:t,handlerMap:e,deliverer:n})})}}remove(t,e){const n=this.eventMaps.slice(0);for(let r=0;r<n.length;r++){const i=n[r];i.listener!==t||e&&i.handlerMap!==e||(this.eventMaps.splice(r,1),i.eventPump.dispose())}}clear(){this.eventMaps.slice(0).forEach(t=>t.eventPump.dispose()),this.eventMaps=[]}dispose(){this.stop(),this.clear()}}const ou=0,au=1,cu=2,lu=0,hu=1,du=2;let uu={},pu=0;class fu{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 uu;const n=e.target.getBoundingClientRect();return uu={x:t.offsetX||e.clientX-n.left,y:t.offsetY||e.clientY-n.top},uu}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,r=0,i=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,r=Math.max(t.screenX,r),n=null!=n?Math.min(t.screenY,n):t.screenY,i=Math.max(t.screenY,i)});const o=r-e||0,a=i-n||0;return s=Math.sqrt(Math.pow(o,2)+Math.pow(a,2))||0,s}(t);pu>0&&(this._scale=e/pu),pu=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 gu(t,e,n){if(!t||!t.app)return;if(t.app.isViewMode&&t.hidden)return;n instanceof fu&&e===n.type||(n=new fu(n,e));const r="on"+e;t[r]&&t[r](n),n.isPropagationStopped()||t.trigger(e,n)}class mu{constructor(t,e){this.gestureHandlerBuilder=t=>{const e=this[`on${t}`];return t=>{const n=new fu(t),r=this.getChildScrollOffset();return n._offsetX+=this.html_element.scrollLeft+r.scrollLeft,n._offsetY+=this.html_element.scrollTop+r.scrollTop,e(n),n.isDefaultPrevented()&&t.preventDefault(),!1}},this.keyeventHandlerBuilder=t=>this[`on${t}`],this.ondragover=t=>(gu(this.findTarget(t),t.type,t),!1),this.ondrop=t=>(gu(this.findTarget(t),t.type,t),!1),this.ondblclick=t=>(gu(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 au:const e=t.offsetX-this.__dragstart_e.offsetX,n=t.offsetY-this.__dragstart_e.offsetY;if(e*e+n*n<16)break;this.status=cu,gu(this.last_target,"dragstart",this.__dragstart_e),this.__dragmove_e=t,gu(this.last_target,"dragmove",t);break;case cu:this.__dragmove_e=t,gu(this.last_target,"dragmove",t);break;default:{const e=this.findTarget(t);this.last_enter_target!==e&&(this.last_enter_target&&gu(this.last_enter_target,"mouseleave",t),e&&gu(e,"mouseenter",t),this.last_enter_target=e),gu(e,t.type,t),this.last_target=e}}return!1},this.onmousedown=t=>{if(this.status===cu)gu(this.last_target,"dragend",t),this.last_target=null,this.status=ou;else{const e=this.findTarget(t);this.last_target=e,this.status=au,this.__dragstart_e=t,gu(e,t.type,t)}return!1},this.onmouseup=t=>{if(this.status===cu)gu(this.last_target,"dragend",t);else{const e=this.findTarget(t);gu(e,t.type,t),this.last_target===e&&gu(e,"click",t)}return this.last_target=null,this.status=ou,!1},this.onmouseout=t=>{const e=this.findTarget(t);if(this.status===cu)gu(this.last_target,"dragend",t);else{if(this.last_target&&this.last_target===e)return;this.last_enter_target&&(gu(this.last_enter_target,"mouseleave",t),delete this.last_enter_target)}return this.last_target=null,this.status=ou,!1},this.ontouchstart=t=>{const e=this.findTarget(t);return this.last_target=e,this.status=hu,this.touchPoints||(this.touchPoints=[]),this.touchPoints.push(t.changedTouches[0]),this.holdTimer=setTimeout(()=>{this.status=lu,gu(this.last_target,"hold",t),delete this.holdTimer},500),gu(e,t.type,t),!1},this.ontouchmove=t=>{if(!t.touches||!t.changedTouches)return gu(this.last_target,"dragstart",t),gu(this.last_target,"dragmove",t),!1;let e=this.findTarget(t);switch(this.status){case hu: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,r=e.clientY-t.clientY;return Math.sqrt(Math.pow(n,2)+Math.pow(r,2))>=16?(this.status=du,void(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer))):void 0});break;case du: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 gu(this.last_target,"pinch",t),!1;gu(this.last_target,"pan",t),e=this.last_target;break;default:this.last_enter_target!==e&&(this.last_enter_target&&gu(this.last_enter_target,"mouseleave",t),e&&gu(e,"mouseenter",t),this.last_enter_target=e),this.last_target=e}return gu(e,"touchmove",t),!1},this.ontouchend=t=>{let e=this.findTarget(t);switch(this.status){case du:e=this.last_target;break;case hu:{const n=performance.now(),r=n-this.touchedAt;this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer,gu(e,r<500?"doubletap":"tap",t),this.touchedAt=n);break}}gu(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=lu,!1},this.onwheel=t=>(gu(this.findTarget(t),t.type,t),!1),this.container=t,this.html_element=e,this.status=ou,this.last_target=null,this.gesture_handlers=Fi.map(t=>this.gestureHandlerBuilder(t)),this.keyevent_handlers=Bi.map(t=>this.keyeventHandlerBuilder(t)),Fi.forEach((t,n)=>e.addEventListener(t,this.gesture_handlers[n]),{passive:!1}),Bi.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&&gu(this.last_enter_target,"mouseleave",new CustomEvent("mouseleave")),Fi.forEach((t,e)=>this.html_element.removeEventListener(t,this.gesture_handlers[e])),Bi.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(),r=this.getChildScrollOffset(),i=t.clientX-n.left+this.html_element.scrollLeft+r.scrollLeft,s=t.clientY-n.top+this.html_element.scrollTop+r.scrollTop;return this.container.capture(i,s)}}function yu(t,e,n,r=0){if(e.length<2)return e;let i=2;for(;i<e.length;i++){const s=e.substring(0,i);if(!(t.measureText(s).width+(s.length-1)*r<n))break}return e.substring(0,i-1)}function bu(t,e,n,r,i=0){const s=String(e).split("\n");return r?[].concat.apply([],s.map(e=>function(t,e,n,r=0){const i=e.split(" "),s=[];let o,a,c=[];for(o=0,a=1;a<=i.length;a++)if(c=i.slice(o,a),t.measureText(c.join(" ")).width+(c.join("").length-1)*r>n){if(a-o==1){const e=yu(t,c[0],n,r);s.push([e]),i.splice(o,1,e,c[0].substring(e.length))}else{for(;""==i[a-1];)a++;s.push(i.slice(o,--a))}o=a}return a-o>1&&s.push(c),0==s.length&&s.push([""]),s}(t,e,n,i))):s.map(t=>t.split(" "))}const vu={},xu={},_u=()=>{};var wu={register:function(t,e,n){vu[t]=e,n&&(xu[t]=n)},unregister:function(t){delete vu[t],delete xu[t]},get:function(t){return vu[t]},getDisposer:function(t){return xu[t]||_u}};function Mu(t){if(!t.hasTextProperty||t.textHidden)return;let{text:e="",bold:n=Ni.BOLD,italic:r=Ni.ITALIC,textWrap:i=Ni.TEXT_WRAP,letterSpacing:s=0,fontFamily:o=Ni.FONT_FAMILY,fontColor:a=Ni.FONT_COLOR,textAlign:c=Ni.TEXT_ALIGN,textBaseline:l=Ni.TEXT_BASELINE,fontSize:h=Ni.FONT_SIZE,lineHeight:d=1.2*h}=t.model;const{left:u,top:p,width:f,height:g}=t.textBounds;h||=Ni.FONT_SIZE,d||=1.2*h,t.textHidden=!0;const m=document.createElement("textarea"),y=new AbortController;Fi.forEach(function(t){m.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:y.signal})});const b=t.toGlobal(u,p),{rotation:v,scale:x}=function(t){let e=0,n=1,r=t;for(;r;){e+=r.get("rotation")||0;const{x:t,y:i}=r.get("scale")||{x:1,y:1};n*=Math.max(t,i)||1,r=r.parent}return{rotation:e,scale:n}}(t);m.value=e;const _={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&&(_.fontWeight="bold"),r&&(_.fontStyle="italic"),c){case"right":case"end":_.textAlign="right";break;case"justify":_.textAlign="justify";break;case"left":case"start":_.textAlign="left";break;default:_.textAlign="center"}const w=[n,r,h+"px",o].filter(Boolean).join(" ");function M(e){const n={left:0,top:0},r=d*function(t,e,n,r,i=0){const s=t.getContext();let o;return s.save(),s.font=n,o=bu(s,e,r,t.get("textWrap"),i).length,s.restore(),o}(t,e,w,f,s);switch(_.height=r+"px",l){case"top":case"hanging":break;case"bottom":case"alphabetic":n.top=g-r;break;default:n.top=g/2-r/2}if(!i){const r=function(t,e,n,r){const i=e.split("\n");let s=r;const o=t.getContext();return o.save(),o.font=n,i.forEach(t=>{const e=o.measureText(t).width;e>s&&(s=e)}),o.restore(),s}(t,e,w,f);switch(_.width=r+"px",c){case"right":case"end":n.left=f-r;break;case"left":case"start":break;default:n.left=(f-r)/2}}_.marginLeft=n.left+"px",_.marginTop=n.top+"px",_.transform=`translate(${b.x}px, ${b.y}px) scale(${x}) rotate(${v}rad)`,_.transformOrigin=`${-n.left}px ${-n.top}px`,Object.assign(m.style,_)}M(e);const S=t.root.target_element;S.appendChild(m),m.select();let A,k=!1;m.addEventListener("keydown",function(t){t.stopPropagation(),"Escape"!=t.code&&(t.shiftKey||"Enter"!=t.code&&"NumpadEnter"!=t.code)?setTimeout(()=>{M(m.value)}):(k=A.skipUpdate="Escape"==t.code,"function"==typeof document.createEvent?m.dispatchEvent(A):m.fireEvent(A.eventType,A))},{signal:y.signal}),document.createEvent?(A=document.createEvent("HTMLEvents"),A.initEvent("blur",!0,!1)):(A=document.createEventObject(),A.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||k||t.app.commander.execute(new Kc({changes:[{component:t,before:{text:e},after:{text:m.value}}]}))};m.addEventListener("blur",C,!1)}wu.register("text-editor",{"(root)":{"(self)":{keydown:function(t,e){const{deliverer:n}=e,r=n.selected;return!(1!==r.length||!r[0].hasTextProperty)&&(("Enter"==t.code||"NumpadEnter"==t.code)&&(Mu(r[0]),t.preventDefault(),!0))}}},"model-layer":{"(descendant)":{dblclick:function(t,e){Mu(e.origin)}}}});const Su=ar(function(t,e,n){if(!t.hasSameParentForAllSelected||n)return void(t.focused=null);const r=[];e[0].parent.isGroup()?t.focused=e[0].parent:(e.forEach(t=>{t.path.forEach(e=>{r.push(t.toScene(e.x,e.y))})}),t.focused=t.capturePath(r,e))},300);let Au,ku,Eu;wu.register("move-handler",{"model-layer":{"(descendant)":{dragstart:function(t,e){const{origin:n,deliverer:r}=e;if(n.stuck)return;let i=r.selected;const s=r.selected.filter(t=>!t.stuck);if(i.length!==s.length&&(i=r.selected=s),0==i.length)return;let o;if(i[0].scalable?(o=i[0].toLocal(t.offsetX,t.offsetY),o=i[0].toParent(o.x,o.y)):o={x:t.offsetX,y:t.offsetY},this.last_pos=o,this.direction=0,r.focused=i[0].parent,t.altKey){const t=[],e=new Map;r.selected=r.selected.filter(t=>!t.isRootModel()).map(n=>{const i=fl(n,t=>{const n=r.root.getNewRefid();return void 0!==t&&e.set(t,n),n});return t.push({component:i,to_container:n.parent}),i}).map(t=>(t.replaceRefids(e),t)),t.forEach(({component:t,to_container:e})=>{e.addComponent(t)}),this.duplicates=r.selected.map(t=>({component:t}))}else this.changes=Kc.before(i)},dragmove:function(t,e){const{origin:n,deliverer:r}=e;if(n.stuck)return;const i=r.selected;if(0==i.length)return;let s;i[0].scalable?(s=i[0].toLocal(t.offsetX,t.offsetY),s=i[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),i.forEach(t=>{t.move({x:o,y:a},1===i.length)}),this.last_pos=s,Su(r,i)},dragend:function(t,e){const{origin:n,deliverer:r}=e;if(n.stuck)return;const i=r.selected;if(0==i.length)return;const s=i[0].parent,o=r.focused||e.deliverer;if(this.changes&&!o.isGroup())if(r.hasSameParentForAllSelected&&o&&o!==s){const t=this.changes.map(t=>{const{component:e}=t;return{component:e,to_container:o}});r.app.commander.execute(new hl({changes:t}))}else Kc.after(this.changes,r.app.commander);else if(this.duplicates){this.duplicates=this.duplicates.map(t=>(t.to_container=o,t));const t=new hl({changes:this.duplicates});r.app.commander.execute(t)}i.forEach(t=>{t.parent&&t.parent.calculateBounds&&t.parent.calculateBounds()}),this.last_pos=null,this.changes=null,this.duplicates=null,Su(r,i,!0)}}},"(root)":{"(self)":{keydown:function(t,e){const{origin:n,deliverer:r}=e,i={},s=t.shiftKey?n.rootModel.MPP:1;switch(t.which){case 37:i.x=-s,i.y=0;break;case 38:i.x=0,i.y=-s;break;case 39:i.x=s,i.y=0;break;case 40:i.x=0,i.y=s;break;default:return}const o=r.selected;Kc.around(r.app.commander,function(){o.forEach(t=>{!t.stuck&&t.move(i,!1)})})}}}});const Cu=cr(()=>{const{x:t,y:e}=Eu,n=ku.deref();n&&(n.rootModel.move({x:t-Au.x,y:e-Au.y},!1),Au={x:t,y:e})},60,{leading:!0,trailing:!0});wu.register("shift-handler",{"model-layer":{"(all)":{dragstart:function(t,e){Au={x:t.offsetX,y:t.offsetY}},dragmove:function(t,e){ku=new WeakRef(e.deliverer),Eu={x:t.offsetX,y:t.offsetY},Cu()}}}}),wu.register("zoom-handler",{"model-layer":{"(all)":{wheel:function(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer,r=t.deltaY<0?1:-1,i=n.get("scale")||{x:1,y:1},s=n.get("translate"),o=t.offsetX,a=t.offsetY,c=n.toLocal(o,a),l=.1*r,h={x:i.x+l,y:i.y+l};if(r<0&&i.x<.2||r>0&&i.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 Pu={},Tu={};function Ou(t){const e={};for(const n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}wu.register("paste-handler",{"(root)":{"(self)":{stylepastestart:function(t){const{deliverer:e}=t,n=e.app,r=e.selected;if(r&&r[0]&&r!==e.rootModel){const t=r[0],{fillStyle:e,strokeStyle:i,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:x,paddingRight:_}=t.state;Pu=Kn({fillStyle:e,strokeStyle:i,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:x,paddingRight:_}),n.mode=4}},stylepastestop:function(t){const{deliverer:e}=t,n=e.app;Pu={},4==n.mode&&(n.mode=1)},databindpastestart:function(t){const{deliverer:e}=t,n=e.app,r=e.selected;if(r&&r[0]&&r!==e.rootModel){const t=r[0],{mappings:e}=t.state;Tu=Kn({mappings:e}),n.mode=5}},databindpastestop:function(t){const{deliverer:e}=t,n=e.app;Tu={},5==n.mode&&(n.mode=1)},pasteapply:function(t,e){const{deliverer:n}=e,r=n.app;t&&(4==r.mode?Kc.around(r.commander,()=>{t.set(Ou({...t.model,...Pu}))}):5==r.mode&&Kc.around(r.commander,()=>{t.set(Ou({...t.model,...Tu}))}))},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,r=n.app;if(4!=r.mode&&5!=r.mode)return;const i=e.origin;4==r.mode?i===n?n.root.trigger("stylepastestop"):i&&Kc.around(r.commander,()=>{const t=Ou({...i.model,...Pu});i?.set(t)}):i===n?n.root.trigger("databindpastestop"):i&&Kc.around(r.commander,()=>{const t=Ou({...i.model,...Tu});i?.set(t)})}}}});class Du{constructor(){this.animatorMap=new Map}waypoint(t,e){this.animatorMap.has(t)&&this.off(t);let{from:n,to:r}=e;if("string"==typeof n&&(n=t.root?.findById(n)),"string"==typeof r&&(r=t.root.findById(r)),!r)return void Xr("WaypointAnimation: Source or target component not found");const i=na(t,{type:"waypoint",fromComponent:n,toComponent:r,...e,onComplete:()=>{this.off(t)}});i&&(this.animatorMap.set(t,i),i.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 Iu(t){const{origin:e}=t,n=e.root,{waypointHandler:r}=n;r?.reset()}wu.register("waypoint-handler",{"model-layer":{"(descendant)":{waypoint:function(t,e){const{origin:n}=e,r=n.root;let{waypointHandler:i}=r;i||(i=new Du,r.waypointHandler=i),i.waypoint(n,t)},waypointoff:function(t){const{origin:e}=t,n=e.root,{waypointHandler:r}=n;r?r.off(e):Xr("waypoint-handler not found")},waypointreset:Iu},"(self)":{waypointreset:Iu}}},function(t){const{waypointHandler:e}=t;e&&(e.dispose(),delete t.waypointHandler)});const zu=[],Lu=ar(function(){zu.forEach(t=>{t.resize()})},100);"undefined"!=typeof window&&window.addEventListener("resize",Lu);class ju extends Tc{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.target_element=t.target_element,this.rebuildContentModel(this.model.model),zu.push(this)}dispose(){kc.hideAll(this),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=zu.indexOf(this);t>=0&&zu.splice(t,1),this.refidIndexMap.clear(),this.indexMap.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 mu(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&&Wr("Template replaced (duplicated)",t,e,n),this.templateMap[t]=e,delete this.templatePrefixes}removeTemplate(t,e){const n=this.templateMap[t];n!==e?Xr("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.toString().replace(/^#/,""),r=this.indexMap.get(n)||[];r.push(e),this.indexMap.set(n,r)}removeIndex(t,e){if(!t)return;const n=t.toString().replace(/^#/,""),r=this.indexMap.get(n)||[],i=r.indexOf(e);-1===i?Xr("Removing index failed (not found)",t,e):(r.splice(i,1),0===r.length?this.indexMap.delete(n):this.indexMap.set(n,r))}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&&Wr("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?Wr("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=t.toString().replace(/^#/,"");return(this.indexMap.get(e)||[])[0]}findAllById(t){if(!t)return[];const e=t.toString().replace(/^#/,"");return this.indexMap.get(e)||[]}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=pl(Object.assign(Kn(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:r}=this.model_layer.model,i=this.target_element,s=this.model_layer;if(this.fitMode=t||this.fitMode||r||"ratio",e&&n&&i&&i.clientWidth&&i.clientHeight){switch(this.fitMode){case"center":!function(t,e,n){const r=t.unitScale,{width:i,height:s}=e.model;e.set("scale",{x:r,y:r}),e.set("translate",{x:Math.max((n.clientWidth-i*r)/2,0),y:Math.max((n.clientHeight-s*r)/2,0)})}(this,s,i);break;case"both":!function(t,e,n){const{width:r,height:i}=e.model,s=n.clientWidth,o=n.clientHeight;e.set("scale",{x:s/r,y:o/i}),e.set("translate",{x:0,y:0})}(0,s,i);break;case"width":!function(t,e,n){const r=n.clientWidth/e.get("width");e.set("scale",{x:r,y:r}),e.set("translate",{x:0,y:0})}(0,s,i);break;case"height":!function(t,e,n){const r=n.clientHeight/e.get("height");e.set("scale",{x:r,y:r}),e.set("translate",{x:0,y:0})}(0,s,i);break;case"ratio":!function(t,e,n){const{width:r,height:i}=e.model,s=n.clientWidth,o=n.clientHeight,a=s/r,c=o/i,l=Math.min(a,c);e.set("scale",{x:l,y:l}),e.set("translate",{x:(s-r*l)/2,y:(o-i*l)/2})}(0,s,i);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=>{wu.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;e?.preserveThreeD&&this.model_layer?.is3dMode&&(n=this.model_layer.detachThreeCapability()),this._disposeAllResources(),this.eventEngine=new su(this),(t=t||{}).type="model-layer",this.model_layer=pl(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=pl(t,this.app);if(e)return this.addComponent(e),e.target=this.target_element,e;Wr("Layer compile failed",t)}).filter(Boolean),this.assist_handlers=(this.model.handlers||[]).map(t=>{const e={};return this.eventEngine.add(e,wu.get(t)),e}),n&&(this.model_layer?.model?.threed?this.model_layer.adoptThreeCapability(n):n.dispose()),this._ready=!0,this.traverse(t=>t.ready())}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.set("threed",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(),r=[...e].sort();return n.every((t,e)=>t===r[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=ar(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:r,tag:i,templatePrefix:s}=t.model;this.addRefidIndex(r,t),e&&this.addIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.addIndex(e,t)}),i&&this.subscribe(i,t),s&&this.addTemplate(s,t);const o=gr({},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:r,tag:i,templatePrefix:s}=t.model;this.removeRefidIndex(r,t),e&&this.removeIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.removeIndex(e,t)}),i&&this.unsubscribe(i,t),s&&this.removeTemplate(s,t),this.eventEngine.remove(t)}onadded(t,e){this._addTraverse(e),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)||this.refreshMappings()}}tc.memoize(ju.prototype,"unitScale",!1);let Ru=13.3;var Fu=function(t){return void 0!==t&&(Ru=t),Ru};const Bu="$base_url";const Nu=Math.PI/12;class Yu{constructor(t,e){this._postprocessing=!0,this._mode=t,this.screen=Fu(),this._baseUrl="undefined"!=typeof window?window.location.origin:null,this._refProvider=e,this.isEditMode&&(this._rotateStep=Nu,this._rotateStepForced=!1)}dispose(){this._dataSubscriptionProvider?.dispose?.(),delete this._dataStorage}_calcScreen(){const t={width:screen.width,height:screen.height};this._PPI=function(t,e,n,r="d"){t<=0&&(t=1),e<=0&&(e=1);const i=("d"===r?Math.sqrt(t*t+e*e):"w"===r?t:e)/n;return i>0?Math.round(i):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 Ri}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(Bu)?new URL(t.replace(Bu,this.baseUrl??""),this.baseUrl??void 0):new URL(t,location.origin),e.href}catch(e){Xr(e,t)}}get rotateStep(){return this._rotateStep}set rotateStep(t){this._rotateStep=Number(t)||Nu}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}}Ur(Yu.prototype,Lr.withEvent);class Vu{constructor(t,e){!(t=Number(t))||t<=0?(Wr("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];Xr("Not forwardable.")}backward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.backwardable)return this.q[--this.pos];Xr("Not backwardable.")}get current(){if(-1!==this.pos)return this.q[this.pos];Xr("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 Gu=ar(t=>{t.brake||t.take()},1e3,{leading:!0,trailing:!1});function Hu(t){!t.brake&&t.dirty&&Gu(t)}class Uu{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(){Gu.cancel(),this.state_holder=null,this.timecapsule=null}touch(){this.dirty=!0,Hu(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,Hu(this)}}function Wu(t,e){const n=e.model_layer.get("scale"),r=e.model_layer.get("translate"),i=e.model_layer.get("threed");if(t){const s=JSON.parse(t);s.scale=n,s.translate=r,s.threed=i,e.rebuildContentModel(s,{preserveThreeD:!0})}}class Xu{constructor(t){this.container=t,this.timecapsule=new Vu(20);const e=this;this.snapshot_taker=new Uu({get state(){const t=e.container.model_layer.hierarchy;return JSON.stringify(t)}},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&&(Wu(this.timecapsule.backward(),this.container),this.trigger("undo",this.undoable(),this.redoable()))}redo(){this.timecapsule.forwardable&&(Wu(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")}}Ur(Xu.prototype,Lr.withEvent);const qu=new class{constructor(){this._scenes=[],this.onSceneChange=null}register(t){this._cleanup(),this._scenes.push(new WeakRef(t)),this.onSceneChange?.(this._scenes.length)}unregister(t){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 r=n.root,i=r?.model||{};return{index:e,model:{width:i.width||0,height:i.height||0,type:i.type||"unknown"}}}).filter(Boolean)}getComponentTree(t=0){const e=this._getScene(t);if(!e)return[];const n=e.rootContainer;if(!n)return[];const r=n.model_layer;return r?this._childrenOf(r):[]}getChildTree(t,e=0){const n=this._getScene(e);if(!n)return[];const r=n.rootContainer;if(!r)return[];let i;return i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),i?this._childrenOf(i):[]}getComponentInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const r=n.rootContainer;if(!r)return null;let i;if(i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),!i)return null;const s=this._safeBounds(i),o={model:this._safeClone(i.model),state:this._safeClone(i.state),nature:i.nature||{},data:this._safeValue(i.data),value:this._safeValue(i.value),bounds:s,type:i.model?.type||"unknown",isContainer:!!i.isContainer?.(),hidden:!!i.model?.hidden};return"model-layer"===i.model?.type&&(o.is3dMode=!!i.model?.threed),o}selectComponent(t,e=0){const n=this._getScene(e);if(!n)return!1;const r=n.rootContainer;if(!r)return!1;if(!t||"root"===t||"__root__"===t)return r.selected=[],!0;const i=this._findComponent(r,t);return!!i&&(r.selected=[i],!0)}setComponentProperty(t,e,n,r=0){const i=this._getScene(r);if(!i)return!1;const s=i.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 r=n.rootContainer;if(!r)return!1;const i=r.model_layer;if(!i||!i._threeCapability)return!1;try{return i._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 r=n.model_layer;if(!r||!r._threeCapability)return null;try{return r._threeCapability.getCameraState()}catch{return null}}toggleHidden(t,e=0){const n=this._getScene(e);if(!n)return!1;const r=n.rootContainer;if(!r)return!1;const i=this._findComponent(r,t);if(!i)return!1;try{return i.set("hidden",!i.model?.hidden),!i.model?.hidden}catch{return!1}}evaluateData(t,e=0){const n=this._getScene(e);if(!n)return;const r=n.rootContainer;if(!r)return;const i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t);return i?this._safeValue(i.data):void 0}evaluateValue(t,e=0){const n=this._getScene(e);if(!n)return;const r=n.rootContainer;if(!r)return;const i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t);return i?this._safeValue(i.value):void 0}searchComponents(t,e=0){const n=this._getScene(e);if(!n)return[];const r=n.rootContainer;if(!r)return[];const i=r.model_layer;if(!i)return[];const s=[],o=t.toLowerCase();return this._traverseComponent(i,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 r=n.rootContainer;if(!r)return[];const i=r.model_layer;if(!i)return[];const s=[];return this._findPath(i,t,s)?s:[]}getThreedInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const r=n.rootContainer;if(!r)return null;let i;if(i="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),!i)return null;const s=i.model||{},o=s.type||"unknown",a=s.material3d,c={is3dish:"function"==typeof i.is3dish&&i.is3dish(),type:o};if(a&&(c.material3d=this._safeClone(a)),c.resolved=Eh(a),"gltf-object"===o)try{c.nodeNames=i.nodeNames??[],c.animationNames=i.animationNames??[],c.autoPlay=!1!==i.autoPlay,c.nodes=this._safeClone(i.nodes),c.animations=this._safeClone(i.animations),c.fillStyleTargets=i.fillStyleTargets}catch{}return a?.spriteMode&&(c.spriteMode=a.spriteMode),a?.renderMode&&(c.renderMode=a.renderMode),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 r=t.findById(e);return r||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,r=t.state||t.model||{};return{id:String(r.refid??r.id??""),type:r.type||"unknown",model_id:r.id,hasChildren:n,childCount:n?e.length:0,refid:r.refid,tag:r.tag,name:r.name,hidden:!!r.hidden,clazz:r.class}}_componentId(t){const e=t.state||t.model||{};return String(e.refid??e.id??"")}_findPath(t,e,n){const r=this._componentId(t);if(r===e)return!0;const i=t.components;if(!i)return!1;for(const s of i)if(this._findPath(s,e,n))return n.unshift("model-layer"===t.model?.type?"__root__":r),!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 r=t[n];if("function"==typeof r)continue;e[n]="object"==typeof r?String(r):r}catch{e[n]="[error]"}return e}}_safeValue(t){if(null==t)return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}},Ku="KHR_materials_pbrSpecularGlossiness";class $u{constructor(t){this.name=Ku,this.parser=t}extendMaterialParams(t,e){const n=this.parser.json.materials?.[t],r=n?.extensions?.[Ku];if(!r)return Promise.resolve();const i=[];if(Array.isArray(r.diffuseFactor)){const[t,n,i,s]=r.diffuseFactor;e.color||(e.color=new l),e.color.setRGB(t,n,i,h),e.opacity=s}null!=r.diffuseTexture&&i.push(this.parser.assignTexture(e,"map",r.diffuseTexture,d));const s=r.glossinessFactor??1;e.roughness=1-s;const o=r.specularFactor??[1,1,1],a=Math.max(o[0],o[1],o[2]);return e.metalness=a>.5?a:0,Promise.all(i)}}const Qu={once:e.LoopOnce,repeat:e.LoopRepeat,pingpong:e.LoopPingPong};class Zu extends Rh{constructor(){super(...arguments),this.objectSize=new e.Vector3,this._nodeIndex=new Map,this._originals=new Map,this._animationActions=new Map,this._fillStyleOriginals=new Map,this._clonedMaterials=new WeakSet,this._loadGen=0}static getSharedLoader(t){if(!Zu._sharedLoader){const t=new S;!function(t){t.register(t=>new $u(t))}(t);const e=new A;e.setDecoderPath("/node_modules/three/examples/jsm/libs/draco/"),t.setDRACOLoader(e);const n=new k;n.setTranscoderPath("/node_modules/three/examples/jsm/libs/basis/"),t.setKTX2Loader(n),t.setMeshoptDecoder(E),t.setCrossOrigin("anonymous"),Zu._sharedLoader=t}return t&&Zu._sharedLoader.ktx2Loader?.detectSupport(t),Zu._sharedLoader}static loadGLTF(t,e){let n=Zu._gltfCache.get(t);if(!n){const r=Zu.getSharedLoader(e);n=new Promise((e,n)=>{r.load(t,e,void 0,n)}).catch(e=>{throw Zu._gltfCache.delete(t),e}),Zu._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}build(){super.build();const{src:t}=this.component.state;if(!t)return void this.clear();const e=++this._loadGen,n=this.component.app.url(t);Zu.loadGLTF(n,this.threeContainer?.renderer3d).then(t=>{e===this._loadGen&&this.gltfLoaded(t)},t=>{e===this._loadGen&&(Wr("GLTFLoader.load",t),this.clear(),this._showErrorPlaceholder(),this.component.setState({loadError:String(t)}))})}gltfLoaded(t){this.component.state.loadError&&this.component.setState({loadError:void 0});const n=t.scene,r=t.animations,i=n.clone();i.userData.context=this,i.traverse(t=>{t.isMesh&&(t.castShadow=!0)});const s=(new e.Box3).setFromObject(i),o=s.getCenter(i.position),a=s.getSize(new e.Vector3);o.multiplyScalar(-1);const c=this.component.state.src;if(c){const t=Zu._topViewCache.get(c);t?this.component._topViewSnapshot=t:this._renderTopViewSnapshot(c,i)}this.clear(),this.object3d.userData.context=this,this.objectSize=a,this.pivot=new e.Object3D,this.object3d.add(this.pivot),this.pivot.add(i),this._buildNodeIndex(i),this.updateDimension(),r&&r.length&&this._setupAnimations(r);const l=this.component.state.nodes;l&&this._applyNodeStates(l),this.updateFillStyle()}_renderTopViewSnapshot(t,e){const n=Zu.renderTopView(e);Zu._topViewCache.set(t,n),this.component._topViewSnapshot=n,this.component.invalidate()}static renderTopView(t){const n=256,r=new e.Scene,i=t.parent;r.add(t);const s=new e.AmbientLight(16777215,.8);r.add(s);const o=new e.DirectionalLight(16777215,1);o.position.set(0,10,0),r.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){i?i.add(t):r.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(r,u),i?i.add(t):r.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 Zu._topViewCache.get(t)}static setTopViewCache(t,e){Zu._topViewCache.set(t,e)}static flushCache(){Zu._gltfCache.clear(),Zu._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 r=this._ensureOwnMaterial(e);void 0!==n.color&&r.color.set(n.color),void 0!==n.opacity&&(r.opacity=n.opacity,r.transparent=n.opacity<1),void 0!==n.emissive&&r.emissive.set(n.emissive),void 0!==n.emissiveIntensity&&(r.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.autoPlay&&this._animationActions.forEach(t=>t.play());const n=this.component.state.animations;n&&this._applyAnimationStates(n)}_applyAnimationStates(t){for(const[n,r]of Object.entries(t)){const t=this._animationActions.get(n);t&&(void 0!==r.loop&&(t.loop=Qu[r.loop]??e.LoopRepeat,"once"===r.loop&&(t.clampWhenFinished=!0)),void 0!==r.speed&&(t.timeScale=r.speed),void 0!==r.weight&&(t.weight=r.weight),void 0!==r.play&&(r.play?t.play():t.stop()))}}get animationNames(){return Array.from(this._animationActions.keys())}_showErrorPlaceholder(){const t=new e.BoxGeometry(1,1,1),n=new e.MeshStandardMaterial({color:13369344,wireframe:!0}),r=new e.Mesh(t,n);r.name="__error_placeholder__",this.object3d.add(r)}updateFillStyle(){const t=this.component.state.fillStyleTargets;if(!t||0===t.length)return;const{fillStyle:e}=this.component.state;if(!e)return;const n=Rh.buildFillStyleTexture(this.component);for(const r of t){const t=this._nodeIndex.get(r);if(!t||!t.isMesh)continue;const i=this._ensureOwnMaterial(t);i&&(this._fillStyleOriginals.has(r)||this._fillStyleOriginals.set(r,{color:i.color.clone(),map:i.map,opacity:i.opacity,transparent:i.transparent}),n?(i.map&&i.map!==this._fillStyleOriginals.get(r)?.map&&i.map.dispose(),n.needsUpdate=!0,i.map=n):"string"==typeof e&&("transparent"!==e?i.color.set(e):(i.opacity=0,i.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 r=n.material;r&&(r.map&&r.map!==t.map&&r.map.dispose(),r.color.copy(t.color),r.map=t.map,r.opacity=t.opacity,r.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(),this.pivot&&Ih(this.pivot),this.pivot=void 0,this.objectSize=void 0,super.clear()}updateDimension(){const{width:t=1,height:e=1,depth:n=1}=this.component.state,{x:r=1,y:i=1,z:s=1}=this.objectSize||{};this.pivot&&this.pivot.scale.set(t/r,n/i,e/s),this.component.invalidate()}updateSource(){this.build()}onchange(t,e){if(super.onchange(t,e),"src"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=e.fillStyleTargets??[];t.length>0&&this._restoreFillStyleTargets(t),this.updateFillStyle()}"autoPlay"in t&&(!1!==t.autoPlay?this._animationActions.forEach(t=>t.play()):this._animationActions.forEach(t=>t.stop()))}}Zu._topViewCache=new Map,Zu._gltfCache=new Map,Zu._sharedLoader=null;let Ju=0;const tp=new FinalizationRegistry(t=>{Ju--});class ep{static get residents(){return Ju}static get residentsCount(){return Ju}constructor(t){this._container=t,this.app=t.app,this._commander=new Xu(this._container),this.app.commander=this._commander,Ju++,tp.register(this,Ju),qu.register(this)}add(t,e,n){return gl.call(this._container,t,e,n)}duplicate(){return ml.call(this._container)}remove(){return yl.call(this._container)}animate(t){return Jo.call(this,t)}fullscreen(t){return Ml.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._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 Ri}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(){qu.unregister(this),this._commander&&this._commander.dispose(),this._container&&this._container.dispose(),Zu.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 kl.call(this._container)}copy(){return Al.call(this._container)}paste(t){return El.call(this._container,t)}undoableChange(t){return Ul.call(this._container,t)}change(t,e,n){return Hl.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 sl.call(this._container,t)}place(t){return Jl.call(this._container,t)}distribute(t){return cl.call(this._container,t)}move(t,e,n){return dl.call(this._container,t,e,n)}zorder(t){return ul.call(this._container,t)}symmetryX(){return Vl.call(this._container)}symmetryY(){return Gl.call(this._container)}on(t,e,n){return xl.call(this._container,t,e,n)}once(t,e,n){return _l.call(this._container,t,e,n)}off(t,e,n){return this._container&&wl.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,r){return Rl.call(this._container,t,e,n,r)}group(){return Fl.call(this._container)}ungroup(){return Bl.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 Wl.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}startAddMode(t){return th.call(this._container,t)}startStylePasteMode(){return eh.call(this._container)}stopStylePasteMode(){return nh.call(this._container)}startDatabindPasteMode(){return rh.call(this._container)}stopDatabindPasteMode(){return ih.call(this._container)}}const np=new class{async load(t){}async save(t,e){}async clear(t){}};function rp({target:t,model:e,style:n,layers:r=[],handlers:i=[],mode:s=0,refProvider:o,dataSubscriptionProvider:a,dataStorage:c=np,baseUrl:l,fitMode:h,postprocessing:d=!0}){let u=null;if("string"==typeof t){if(u=document.getElementById(t),!u)throw new Error(`target element '${t}' does not exist`);if(u.firstChild)throw new Error(`target element '${t}' is not empty`)}else u=t??null;u&&u.style&&(u.style.position="absolute",u.style.cursor="default",u.style.overflow="hidden");const p=new Yu(s,o);return l&&(p.baseUrl=l),p.postprocessing=d,p.dataSubscriptionProvider=a,p.dataStorage=c,new ep(new ju({target_element:u,model:e,style:n,layers:r,handlers:i,fitMode:h},p))}function ip(t,e,n,r){var i,s=arguments.length,o=s<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,n,o):i(e,n))||o);return s>3&&o&&Object.defineProperty(e,n,o),o}function sp(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function op(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const ap=["mousemove","mouseup","mousedown","mouseout","wheel","tap","click","touchstart","touchmove","touchend","mouseenter","mouseleave","dragstart","dragmove","dragend","dblclick"];function cp(t){return class extends t{constructor(){super(...arguments),this.userInputEventHandler=t=>{gu(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"),ap.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),Bi.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),this.oncreate_element&&this.oncreate_element(this.element))}reposition(){this.element&&vs(this)}disposeElement(){if(!this.element)return;ap.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)}),Bi.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 lp;const hp={x:1,y:1},dp={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"},up={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 pp extends(cp(Tc)){constructor(){super(...arguments),lp.set(this,null),this.startDragging=t=>{if(!this.state.draggable)return;t.preventDefault(),t.stopPropagation();const e=t.clientX,n=t.clientY,{left:r,top:i}=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:r+s,top:i+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 up}isPositionable(){return!0}setElementProperties(t){}get layout(){return lc.get(this.get("layout"))||hc}reposition(){if(!this.element)return;const t=this,{id:e,class:n,scale:r=hp}=t.state,{rotation:i=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,dp,{left:o+"px",top:a+"px",width:"0px",height:"0px",backgroundColor:"transparent"});const p=t.delta(),f=(r&&r.x||1)*p.sx,g=(r&&r.y||1)*p.sy,m=(i||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],r=t[2];e?this.set({left:n.x,top:n.y,width:r.x-n.x}):this.set({left:n.x,top:n.y,width:r.x-n.x,height:r.y-n.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:r=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+r},{x:t,y:e+r}]}get bounds(){const{left:t=0,top:e=0,width:n=0,height:r=0}=this.state;return{left:t,top:e,width:n,height:r}}set bounds(t){const{minimized:e}=this.state,{left:n=0,top:r=0,width:i=0,height:s=0}=t,o={left:n,top:r};e?this.set({...o,width:i}):this.set({...o,width:i,height:s})}updatePosition(){if(!this.origin)return void(sp(this,lp,"f")&&(sp(this,lp,"f").disconnect(),op(this,lp,null,"f")));const t=this.rootModel.auxOverlay;if(!t)return;const e=this.bounds,{width:n,height:r}="static"!==this.position?t.getBoundingClientRect():this.parent.bounds,{x:i,y:s}=function(t,e,n){const{left:r,top:i,width:s,height:o}=e,{width:a,height:c}=n;return t?{x:t.includes("left")?r:t.includes("center")?r+(s-a)/2:r+(s-a),y:t.includes("top")?i:t.includes("middle")?i+(o-c)/2:i+(o-c)}:{x:n.left,y:n.top}}(this.origin,{left:0,top:0,width:n,height:r},e),o=this.offset;this.bounds={left:i+(this.origin.includes("right")?-o.x:+o.x),top:s+(this.origin.includes("bottom")?-o.y:+o.y),width:e.width,height:e.height},sp(this,lp,"f")||(op(this,lp,new ResizeObserver(()=>{requestAnimationFrame(()=>this.updatePosition())}),"f"),sp(this,lp,"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(){sp(this,lp,"f")&&(sp(this,lp,"f").disconnect(),op(this,lp,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:r,hidden:i}=this.state,{width:s}=this.bounds;this.element.style.setProperty("--container-width",`${s}px`);try{C(i?P:T`
|
|
4
4
|
<style>
|
|
5
5
|
[scene='container'] .buttons {
|
|
6
6
|
position: absolute;
|
|
@@ -48,5 +48,5 @@ return!t||t.scalable?this.context2D:this.auxContext2D}draw(t){this.canvas&&this.
|
|
|
48
48
|
</button>`:P}
|
|
49
49
|
${n?T`<button class="closable" @click=${this.closeContainer}>close</button>`:P}
|
|
50
50
|
</div>
|
|
51
|
-
`,this.element)}catch(t){}}onchangeMinimized(){const{minimized:t}=this.state;t?this.setState("height",24):this.setState("height",this.get("height"))}}sp=new WeakMap,tc.memoize(lp.prototype,"bounds",!0),tc.register("container",lp);const hp=Math.sqrt(3),dp=2;function up(t,e,n,r,i){const s=5+i,o=n.x,a=n.y,c=r.x,l=r.y;if(Math.abs(o-c)>s&&Math.abs(a-l)>s){const n=(l-a)/(c-o),r=a-n*o;if(Math.abs(e-(n*t+r))>s)return!1}let h,d,u,p;return o>c?(d=o,h=c):(d=c,h=o),a>l?(p=a,u=l):(p=l,u=a),!(d+5<t)&&(!(h-5>t)&&(!(p+5<e)&&!(u-5>e)))}function pp(t,e,n,r=2){for(let i=0;i<n.length-1;i++)if(up(t,e,n[i],n[i+1],r))return!0;return!1}function fp(t,e,n,r){if("arrow"!=t.slice(-5))return n;const i=Math.atan2(r.y-n.y,r.x-n.x),s=1.5*e;return{x:n.x+Math.cos(i)*s,y:n.y+Math.sin(i)*s}}function gp(t,e,n){let{lineWidth:r=dp,strokeStyle:i="#000000",lineCap:s=!1,alpha:o=1,begin:a="none",end:c="none",beginSize:l="size5",endSize:h="size5"}=n;if(("none"!=a||"none"!=c)&&(r=Number(r)||dp,t.lineCap=s,t.lineWidth=r,t.strokeStyle=i,t.fillStyle=i,t.globalAlpha*=o,"none"!=a&&mp(t,e[0],e[1],r,a,yp(l,r)),"none"!=c)){const n=e.length;mp(t,e[n-1],e[n-2],r,c,yp(h,r))}}function mp(t,e,n,r,i,s){const{x:o,y:a}=e,c=Math.atan2(n.y-a,n.x-o);switch(t.beginPath(),t.translate(o,a),t.rotate(c),i){case"oval":t.ellipse(0,0,s.X,s.Y,0,0,2*Math.PI),t.fill();break;case"diamond":t.moveTo(-s.X,0),t.lineTo(0,-s.Y),t.lineTo(s.X,0),t.lineTo(0,s.Y),t.fill();break;case"arrow":t.moveTo(0,0),t.lineTo(hp*s.X,-s.Y),t.lineTo(hp*s.X,s.Y),t.fill();break;case"sharp-arrow":t.moveTo(0,0),t.lineTo(hp*s.X,-s.Y),t.lineTo(-s.X/1.5+hp*s.X,0),t.lineTo(hp*s.X,s.Y),t.fill();break;case"open-arrow":t.moveTo(hp*s.X+r,-s.Y),t.lineTo(r,0),t.lineTo(hp*s.X+r,s.Y),t.stroke();break;case"cross":t.moveTo(-s.X,-s.Y),t.lineTo(s.X,s.Y),t.moveTo(s.X,-s.Y),t.lineTo(-s.X,s.Y),t.stroke()}t.rotate(-c),t.translate(-o,-a),t.closePath()}function yp(t,e){const n={X:0,Y:0};switch(e*=1.2,t){case"size1":n.X=e,n.Y=e;break;case"size2":n.X=1.5*e,n.Y=e;break;case"size3":n.X=2*e,n.Y=e;break;case"size4":n.X=e,n.Y=1.5*e;break;case"size5":default:n.X=1.5*e,n.Y=1.5*e;break;case"size6":n.X=2*e,n.Y=1.5*e;break;case"size7":n.X=e,n.Y=2*e;break;case"size8":n.X=1.5*e,n.Y=2*e;break;case"size9":n.X=2*e,n.Y=2*e}return n}const bp="N",vp="S",xp="E",_p="W";class wp{constructor({component:t,anchor:e,position:n,self:r}){this.component=t,this._anchorName=e,this._position=n,this.self=r}get position(){const t=this.anchor;if(t){const{position:e}=t,n=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(n.x,n.y)}return this._position}set position({x:t,y:e}){this._position={x:t,y:e}}get anchor(){return this.component?.findAnchor(this._anchorName)}get direction(){const t=this.component.bounds,e=this.anchor;if(!e)return xp;const n=e.position;return n.y<=t.top?bp:n.y>=t.top+t.height?vp:n.x<=t.left?_p:xp}get boundaryPosition(){const t=this.anchor;if(t){let{position:e}=t,n=0,r=0;switch(this.direction){case vp:r=20;break;case bp:r=-20;break;case _p:n=-20;break;default:n=20}e={x:e.x+n,y:e.y+r};const i=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(i.x,i.y)}}}class Mp extends tc{isLine(){return!0}replaceRefids(t){["from","to"].forEach(e=>{const n=this.get(e);if(n?.component){const r=t.get(n.component)||n.component;this.set(e,{...n,component:r})}})}get fromEnd(){if(this.parent&&!this._fromEnd){const{component:t,anchor:e,position:n}=this.getState("from")||{};if(!t)return;const r=this.root?.findByRefid?.(t);if(!r)return;this._fromEnd=new wp({component:r,fromto:"from",anchor:e,position:n,self:this})}return this._fromEnd}get from(){return this.getState("from")}set from(t){delete this._fromEnd,this.set("from",t)}get toEnd(){if(this.parent&&!this._toEnd){const{component:t,anchor:e,position:n}=this.getState("to")||{};if(!t)return;const r=this.root?.findByRefid?.(t);if(!r)return;this._toEnd=new wp({component:r,fromto:"to",anchor:e,position:n,self:this})}return this._toEnd}get to(){return this.getState("to")}set to(t){delete this._toEnd,this.set("to",t)}move({x:t,y:e},n){n&&(this.from={position:this._fromEnd?.position||this.getState("from")?.position||{x:0,y:0}},this.to={position:this._toEnd?.position||this.getState("to")?.position||{x:0,y:0}}),super.move({x:t,y:e})}render(t){const{begin:e="none",end:n="none",lineWidth:r,round:i=0}=this.state;let s=this.drawPath;gp(t,s,this.state),t.beginPath();const o=fp(e,r,s[0],s[1]),a=fp(n,r,s[s.length-1],s[s.length-2]);s=[o,...s.slice(1,-1),a];let c={x:o.x,y:o.y};t.moveTo(o.x,o.y);for(let e=1;e<s.length;e++){const n=c;c=s[e];const r=s[e+1];if(n.x===c.x&&n.y===c.y)continue;if(!r){t.lineTo(c.x,c.y);break}let o=Math.sqrt((n.x-c.x)*(n.x-c.x)+(n.y-c.y)*(n.y-c.y)),a=0!==o?Math.atan2(n.x-c.x,n.y-c.y):0,l=Math.sin(a)*Math.min(i,o/2)+c.x,h=Math.cos(a)*Math.min(i,o/2)+c.y;const d=i>0||0!==o?{x:l,y:h}:c;o=Math.sqrt((r.x-c.x)*(r.x-c.x)+(r.y-c.y)*(r.y-c.y)),a=0!==o?Math.atan2(r.x-c.x,r.y-c.y):0,l=Math.sin(a)*Math.min(i,o/2)+c.x,h=Math.cos(a)*Math.min(i,o/2)+c.y;const u=i>0||0!==o?{x:l,y:h}:c;t.lineTo(d.x,d.y),i>0&&t.quadraticCurveTo(c.x,c.y,u.x,u.y)}this.drawStroke(t,void 0)}contains(t,e){const{lineWidth:n}=this.state;return pp(t,e,this.drawPath,n)}get resizable(){return!1}get mutable(){return!0}get rotatable(){return!1}get path(){const{from:t,to:e}=this.state,{x1:n,y1:r,x2:i,y2:s}=this.state;return[this.fromEnd?.position||t?.position||{x:n,y:r},this.toEnd?.position||e?.position||{x:i,y:s}]}set path(t){const[e,n]=t,{from:r,to:i}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...r,position:e},to:{...i,position:n}})}get textBounds(){const t=this.drawPath;let e,n,r=0;for(let i=1;i<t.length;i++){const s=t[i-1],o=t[i],a=(s.x-o.x)*(s.x-o.x)+(s.y-o.y)*(s.y-o.y);a>r&&(r=Math.ceil(a),e=s,n=o)}let{paddingTop:i,paddingLeft:s,paddingRight:o,paddingBottom:a}=this.state;return a||=0,i||=0,s||=0,o||=0,{left:Math.min(e.x,n.x)+s,top:Math.min(e.y,n.y)+i,width:Math.max(Math.abs(e.x-n.x)-s-o,0),height:Math.max(Math.abs(e.y-n.y)-i-a,0)}}get decorators(){return this.app.isEditMode?["decotag"]:[]}}Mp.getTipNeckPos=fp,Mp.containedInPath=pp,Mp.drawEndTips=gp,tc.register("line",Mp);const Sp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"angle",label:"start-angle",name:"startAngle",property:"startAngle"},{type:"angle",label:"end-angle",name:"endAngle",property:"endAngle"}],"value-property":"text"};class Ap extends(vd(ec)){is3dish(){return!0}render(t){const{cx:e,cy:n,rx:r,ry:i,startAngle:s,endAngle:o,anticlockwise:a}=this.state;t.beginPath(),t.ellipse(e,n,Math.abs(r),Math.abs(i),0,s||0,o||2*Math.PI,a),void 0!==s&&void 0!==o&&(t.lineTo(e,n),t.closePath())}get path(){const{cx:t,cy:e,rx:n,ry:r}=this.state;return[{x:t-n,y:e-r},{x:t+n,y:e-r},{x:t+n,y:e+r},{x:t-n,y:e+r}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2,rx:(n.x-e.x)/2,ry:(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:r,rx:i,ry:s}=this.state,o=(t-n)/(2*i-.5),a=(e-r)/(2*s-.5);return o*o+a*a<.25}outline(t){return function(t,e){const{cx:n,cy:r,rx:i,ry:s}=t.model,o=2*Math.PI*e,a=n+i*Math.cos(o),c=r+s*Math.sin(o);return t.toScene(a,c)}(this,t)}get anchors(){return function(t){const{left:e,top:n,width:r,height:i}=t.bounds,s=e+r/2,o=n+i/2;return[{name:"TOP",position:{x:s,y:n}},{name:"RIGHT",position:{x:e+r,y:o}},{name:"BOTTOM",position:{x:s,y:n+i}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get nature(){return Sp}}tc.memoize(Ap.prototype,"path",!1),tc.register("ellipse",Ap);const kp={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e+1,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){n[e+1]=t})},ondragend:function(t,e,n){}},Ep={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polygon"};class Cp extends ec{is3dish(){return!0}get mutable(){return!0}get pathExtendable(){return!0}get path(){return this.state.path}set path(t){this.set("path",t)}contains(t,e){const n=this.state.path;let r=!1;return n.forEach((i,s)=>{const o=(s+n.length+1)%n.length,a=i.x,c=i.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(r=!r)}),r}get controls(){const t=this.path;return t.map((e,n)=>{const r=t[n+1>=t.length?0:n+1];return{x:(e.x+r.x)/2,y:(e.y+r.y)/2,handler:kp}})}get nature(){return Ep}}tc.memoize(Cp.prototype,"controls",!1),tc.register("polygon",Cp);const Pp={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){n[e]=t})},ondragend:function(t,e,n){}},Tp={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polyline"};class Op extends Mp{get pathExtendable(){return!0}get path(){const{from:t,to:e}=this.state,{path:n}=this.state;return[this.fromEnd?.position||t?.position||n[0],...n.slice(1,-1),this.toEnd?.position||e?.position||n[n.length-1]]}set path(t){const{from:e,to:n}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...e,position:t[0]},to:{...n,position:t[t.length-1]},path:t})}get controls(){const t=this.path,e=[];for(let n=0;n<t.length-1;n++){const r=t[n],i=t[n+1];0==n&&e.push({x:r.x,y:r.y,handler:Pp}),e.push({x:(r.x+i.x)/2,y:(r.y+i.y)/2,handler:Pp}),n==t.length-2&&e.push({x:i.x,y:i.y,handler:Pp})}return e}get nature(){return Tp}}tc.register("polyline",Op);const Dp={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/ortholine"};class Ip extends Mp{get pathExtendable(){return!1}get drawPath(){const t=this.path[0],e=this.path[1],{component:n,direction:r,boundaryPosition:i=t}=this.fromEnd||{},{component:s,direction:o,boundaryPosition:a=e}=this.toEnd||{},c=[i,a],l=[];i&&l.push(i);let h,d=n?.bounds;d&&(h=n.toScene(d.left,d.top),h=this.transcoordT2P(h.x,h.y),d={...d,left:h.x,top:h.y});const u=d?{left:d.left-20,top:d.top-20,width:d.width+40,height:d.height+40}:{left:i.x,top:i.y,width:0,height:0};d=d||u;let p=s?.bounds;p&&(h=s.toScene(p.left,p.top),h=this.transcoordT2P(h.x,h.y),p={...p,left:h.x,top:h.y});const f=p?{left:p.left-20,top:p.top-20,width:p.width+40,height:p.height+40}:{left:a.x,top:a.y,width:0,height:0};p=p||f;const g=[u,f],m=u.left>f.left?f.left:u.left,y=u.top>f.top?f.top:u.top,b={left:m,top:y,width:u.left+u.width>f.left+f.width?u.left+u.width-m:f.left+f.width-m,height:u.top+u.height>f.top+f.height?u.top+u.height-y:f.top+f.height-y};let v,x,_,w,M,S,A,k,E,C,P=0,T=0;d.left+d.width<p.left?(w=0,M=1,E=r,C=o,v=(d.left+d.width+p.left)/2,P=p.left-v):p.left+p.width<d.left&&(w=1,M=0,E=o,C=r,v=(d.left+p.width+p.left)/2,P=d.left-v),d.top+d.height<p.top?(_=0,S=1,A=r,k=o,x=(d.top+d.height+p.top)/2,T=p.top-x):p.top+p.height<d.top&&(_=1,S=0,A=o,k=r,x=(d.top+p.height+p.top)/2,T=d.top-x);const O=[];if(v&&P>T){let t,e,n;switch(C){case _p:switch(E){case xp:O.push({x:v,y:c[w].y}),O.push({x:v,y:c[M].y});break;case _p:t=g[w].top+g[w].height/2,e=t>c[M].y?Math.min(g[w].top,c[M].y):Math.max(g[w].top+g[w].height,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:c[M].y});break;case bp:case vp:e=E===vp?Math.max(c[w].y,c[M].y):Math.min(c[w].y,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:c[M].y});break;default:return this.path}break;case xp:switch(E){case xp:e=c[w].y<c[M].y?Math.min(g[M].top,c[w].y):Math.max(g[M].top+g[M].height,c[w].y),n=e;break;case _p:e=void 0!==x?x:c[w].y<c[M].y?b.top-.5*P:b.top+b.height+.5*P,n=e;break;case vp:e=void 0!==x?Math.max(x,c[w].y):b.top+b.height,n=e;break;case bp:e=x?Math.min(x,g[w].top):b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:n}),O.push({x:c[M].x,y:n});break;case vp:switch(E){case xp:e=c[w].y,n=c[w].y>c[M].y?c[w].y:g[M].top+g[M].height;break;case _p:e=x?Math.max(x,g[M].top+g[M].height):b.top+b.height,n=e;break;case vp:e=b.top+b.height,n=e;break;case bp:e=x?Math.min(x,g[w].top):g[w].top,n=x?Math.max(x,g[M].top+g[M].height):g[M].top+g[M].height;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:n}),O.push({x:c[M].x,y:n});break;case bp:switch(E){case xp:e=c[w].y,n=c[w].y<c[M].y?c[w].y:g[M].top;break;case _p:e=x?Math.min(x,g[M].top):b.top,n=e;break;case vp:e=void 0!==x?Math.max(x,c[w].y):c[w].y,n=void 0!==x?Math.min(x,c[M].y):c[M].y;break;case bp:e=b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:n}),O.push({x:c[M].x,y:n});break;default:return this.path}l.push(...0===w?O:O.reverse())}else if(x){let t,e,n;switch(k){case bp:switch(A){case vp:O.push({x:c[_].x,y:x}),O.push({x:c[S].x,y:x});break;case bp:t=g[_].left+g[_].width/2,e=t>c[S].x?Math.min(g[_].left,c[S].x):Math.max(g[_].left+g[_].width,c[S].x),O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:c[S].x,y:x});break;case _p:e=Math.min(c[_].x,c[S].x),O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:c[S].x,y:x});break;case xp:e=Math.max(c[_].x,c[S].x),O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:c[S].x,y:x});break;default:return this.path}break;case vp:switch(A){case _p:e=b.left,n=e;break;case xp:e=void 0!==v?Math.max(v,c[_].x):b.left+b.width,n=e;break;case bp:e=void 0!==v?v:c[_].x<c[S].x?b.left-.5*T:b.left+b.width+.5*T,n=e;break;case vp:e=c[_].x,n=c[_].x<c[S].x?Math.min(g[S].left,c[_].x):Math.max(g[S].left+g[S].width,c[_].x);break;default:return this.path}O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:n,y:x}),O.push({x:n,y:c[S].y});break;case xp:switch(A){case _p:e=void 0!==v?Math.min(v,c[_].x):c[_].x,n=void 0!==v?Math.max(v,c[S].x):c[S].x;break;case xp:e=b.left+b.width,n=e;break;case bp:e=void 0!==v?Math.max(v,c[S].x):b.left+b.width,n=e;break;case vp:e=c[_].x,n=Math.max(g[S].left+g[S].width,c[_].x);break;default:return this.path}O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:n,y:x}),O.push({x:n,y:c[S].y});break;case _p:switch(A){case _p:e=b.left,n=e;break;case xp:e=void 0!==v?Math.max(v,c[_].x):c[_].x,n=void 0!==v?Math.min(v,c[S].x):c[S].x;break;case bp:e=b.left,n=e;break;case vp:e=c[_].x<c[S].x?Math.min(g[S].left,c[_].x):c[_].x,n=Math.min(e,c[S].x);break;default:return this.path}O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:n,y:x}),O.push({x:n,y:c[S].y});break;default:return this.path}l.push(...0===_?O:O.reverse())}else{let t,e;switch(r){case bp:switch(o){case bp:e=b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case vp:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top+b.height}),l.push({x:c[1].x,y:b.top+b.height});break;case xp:t=c[1].y<c[0].y&&c[1].x<c[0].x?c[0].x:b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;case _p:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case vp:switch(o){case bp:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top}),l.push({x:c[1].x,y:b.top});break;case vp:case xp:case _p:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;case _p:switch(o){case bp:t=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].x:b.left,e=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].y:Math.min(b.top,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case vp:t=b.left,e=Math.max(b.top+b.height,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case xp:t=b.left+b.width,l.push({x:c[0].x,y:b.top}),l.push({x:t,y:b.top}),l.push({x:t,y:c[1].y});break;case _p:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case xp:switch(o){case bp:e=c[0].y<c[1].y&&c[0].x<c[1].x?c[0].y:b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case vp:e=c[0].y>c[1].y&&c[0].x<c[1].x?c[0].y:b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case xp:case _p:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;default:return this.path}}return a&&l.push(a),[t,...l,e].filter((t,e,n)=>{if(0===e)return!0;const r=n[e-1];return t.x!==r.x||t.y!==r.y}).filter((t,e,n)=>{if(0===e||e>=n.length-1)return!0;const r=n[e-1],i=n[e+1];return!(t.x===r.x&&t.x===i.x||t.y===r.y&&t.y===i.y)})}get nature(){return Dp}}tc.register("ortholine",Ip);const zp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"image-src",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:"$base_url",defaultStorage:"scene-image",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0}},{type:"select",label:"cross-origin",name:"crossOrigin",property:{options:["","anonymous","use-credentials"]}}],"value-property":"src",help:"scene/component/image-view"};class Lp extends(rc(ec)){static get noimage(){return Lp.NOIMAGE||(Lp.NOIMAGE=new Image,Lp.NOIMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII="),Lp.NOIMAGE}dispose(){super.dispose(),this._offcanvas=null,this._image=null}render(t){const{left:e,top:n,width:r,height:i,isGray:s=!1,alpha:o=1,src:a}=this.state;if(this.prepareIf(!this._image&&a),t.beginPath(),t.globalAlpha*=o,this._image&&this._image.complete)if(s&&this._offcanvas)t.drawImage(this._offcanvas,e,n,r,i);else try{t.drawImage(this._image,e,n,r,i)}catch(s){t.drawImage(Lp.noimage,e,n,r,i)}else!this.app.isViewMode&&t.drawImage(Lp.noimage,e,n,r,i)}get nature(){return zp}get hasTextProperty(){return!1}async ready(){await super.ready(),this.prepareIf(!this._image&&this.state.src)}prepare(t,e){const{src:n,crossOrigin:r}=this.state;if(n){this._image=new Image;try{r&&(this._image.crossOrigin=r),this._image.src=this.app.url(n)||""}catch(t){return void e(t)}this._image.onload=()=>{if(this.get("isGray")){const t=this._image.width,e=this._image.height;this._offcanvas=tc.createCanvas(t,e);const n=this._offcanvas.getContext("2d");n.drawImage(this._image,0,0);const r=function(t,e,n){let r;try{r=t.getImageData(0,0,e,n)}catch(t){return Wr("Get Image Data Error: "+(t instanceof Error?t.message:String(t))),null}const i=r.data;for(let t=0;t<e*n*4;t+=4){const e=i[t],n=i[t+1],s=i[t+2],o=Math.floor((e+n+s)/3);r.data[t]=o,r.data[t+1]=o,r.data[t+2]=o}return r}(n,t,e);n.putImageData(r,0,0)}t(this)},this._image.onerror=t=>{this._image&&!this._image.currentSrc&&(this._image=null),e(t)}}else t(this)}get src(){return this.get("src")}set src(t){this.set("src",t)}onchange(t,e){(t.hasOwnProperty("src")||t.hasOwnProperty("isGray"))&&(this._offcanvas=null,this._image=null,this.prepareIf(t.src))}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("image/"))return void(this.src=e[n])}}tc.register("image-view",Lp);class jp extends(ip(rc(tc))){is3dish(){return!0}prerender(){}}var Rp,Fp,Bp={},Np={},Yp={};function Vp(){if(Fp)return Np;Fp=1,Object.defineProperty(Np,"__esModule",{value:!0});var t=function(){if(Rp)return Yp;Rp=1,Object.defineProperty(Yp,"__esModule",{value:!0});var t=function(){function t(){}return t.bitsToNum=function(t){return t.reduce(function(t,e){return 2*t+e},0)},t.byteToBitArr=function(t){for(var e=[],n=7;n>=0;n--)e.push(!!(t&1<<n));return e},t.lzwDecode=function(t,e){for(var n,r,i=0,s=function(t){for(var n=0,r=0;r<t;r++)e.charCodeAt(i>>3)&1<<(7&i)&&(n|=1<<r),i++;return n},o=[],a=1<<t,c=a+1,l=t+1,h=[],d=function(){h=[],l=t+1;for(var e=0;e<a;e++)h[e]=[e];h[a]=[],h[c]=null};;)if(r=n,(n=s(l))!==a){if(n===c)break;if(n<h.length)r!==a&&h.push(h[r].concat(h[n][0]));else{if(n!==h.length)throw new Error("Invalid LZW code.");h.push(h[r].concat(h[r][0]))}o.push.apply(o,h[n]),h.length===1<<l&&l<12&&l++}else d();return o},t}();return Yp.SuperGifUtils=t,Yp}(),e=function(){function e(t,e){this.stream=t,this.handler=e}return e.prototype.parseCT=function(t){for(var e=[],n=0;n<t;n++)e.push(this.stream.readBytes(3));return e},e.prototype.readSubBlocks=function(){var t,e;e="";do{t=this.stream.readByte(),e+=this.stream.read(t)}while(0!==t);return e},e.prototype.parseHeader=function(){var e={};if(e.sig=this.stream.read(3),e.ver=this.stream.read(3),"GIF"!==e.sig)throw new Error("Not a GIF file.");e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.gctFlag=n.shift(),e.colorRes=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.sorted=n.shift(),e.gctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.bgColor=this.stream.readByte(),e.pixelAspectRatio=this.stream.readByte(),e.gctFlag&&(e.gct=this.parseCT(1<<e.gctSize+1)),this.handler.hdr&&this.handler.hdr(e)},e.prototype.parseExt=function(e){var n=this;switch(e.label=this.stream.readByte(),e.label){case 249:e.extType="gce",function(e){n.stream.readByte();var r=t.SuperGifUtils.byteToBitArr(n.stream.readByte());e.reserved=r.splice(0,3),e.disposalMethod=t.SuperGifUtils.bitsToNum(r.splice(0,3)),e.userInput=r.shift(),e.transparencyGiven=r.shift(),e.delayTime=n.stream.readUnsigned(),e.transparencyIndex=n.stream.readByte(),e.terminator=n.stream.readByte(),n.handler.gce&&n.handler.gce(e)}(e);break;case 254:e.extType="com",function(t){t.comment=n.readSubBlocks(),n.handler.com&&n.handler.com(t)}(e);break;case 1:e.extType="pte",function(t){n.stream.readByte(),t.ptHeader=n.stream.readBytes(12),t.ptData=n.readSubBlocks(),n.handler.pte&&n.handler.pte(t)}(e);break;case 255:e.extType="app",function(t){n.stream.readByte(),t.identifier=n.stream.read(8),t.authCode=n.stream.read(3),"NETSCAPE"===t.identifier?function(t){n.stream.readByte(),t.unknown=n.stream.readByte(),t.iterations=n.stream.readUnsigned(),t.terminator=n.stream.readByte(),n.handler.app&&n.handler.app.NETSCAPE&&n.handler.app.NETSCAPE(t)}(t):function(t){t.appData=n.readSubBlocks(),n.handler.app&&n.handler.app[t.identifier]&&n.handler.app[t.identifier](t)}(t)}(e);break;default:e.extType="unknown",function(t){t.data=n.readSubBlocks(),n.handler.unknown&&n.handler.unknown(t)}(e)}},e.prototype.parseImg=function(e){e.leftPos=this.stream.readUnsigned(),e.topPos=this.stream.readUnsigned(),e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.lctFlag=n.shift(),e.interlaced=n.shift(),e.sorted=n.shift(),e.reserved=n.splice(0,2),e.lctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.lctFlag&&(e.lct=this.parseCT(1<<e.lctSize+1)),e.lzwMinCodeSize=this.stream.readByte();var r=this.readSubBlocks();e.pixels=t.SuperGifUtils.lzwDecode(e.lzwMinCodeSize,r),e.interlaced&&(e.pixels=function(t,e){for(var n=new Array(t.length),r=t.length/e,i=function(r,i){var s=t.slice(i*e,(i+1)*e);n.splice.apply(n,[r*e,e].concat(s))},s=[0,4,2,1],o=[8,8,4,2],a=0,c=0;c<4;c++)for(var l=s[c];l<r;l+=o[c])i(l,a),a++;return n}(e.pixels,e.width)),this.handler.img&&this.handler.img(e)},e.prototype.parseBlock=function(){var t={};switch(t.sentinel=this.stream.readByte(),String.fromCharCode(t.sentinel)){case"!":t.type="ext",this.parseExt(t);break;case",":t.type="img",this.parseImg(t);break;case";":t.type="eof",this.handler.eof&&this.handler.eof(t);break;default:throw new Error("Unknown block: 0x"+t.sentinel.toString(16))}"eof"!==t.type&&setTimeout(this.parseBlock.bind(this),0)},e.prototype.parse=function(){this.parseHeader(),setTimeout(this.parseBlock.bind(this),0)},e}();return Np.SuperGifParser=e,Np}var Gp,Hp,Up={};var Wp=function(){if(Hp)return Bp;Hp=1,Object.defineProperty(Bp,"__esModule",{value:!0});var t=Vp(),e=function(){if(Gp)return Up;Gp=1,Object.defineProperty(Up,"__esModule",{value:!0});var t=function(){function t(t){this.data=t,this.position=0}return t.prototype.readByte=function(){if(this.position>=this.data.length)throw new Error("Attempted to read past end of stream.");return this.data instanceof Uint8Array?this.data[this.position++]:255&this.data.charCodeAt(this.position++)},t.prototype.readBytes=function(t){for(var e=[],n=0;n<t;n++)e.push(this.readByte());return e},t.prototype.read=function(t){for(var e="",n=0;n<t;n++)e+=String.fromCharCode(this.readByte());return e},t.prototype.readUnsigned=function(){var t=this.readBytes(2);return(t[1]<<8)+t[0]},t}();return Up.SuperGifStream=t,Up}(),n=function(){function n(t,e){var n=this;for(var r in this.gifImgElement=t,this.options={autoPlay:!0},this.loading=!1,this.ready=!1,this.transparency=null,this.delay=null,this.disposalMethod=null,this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,this.playing=!0,this.forward=!0,this.ctxScaled=!1,this.frames=[],this.frameOffsets=[],this.initialized=!1,this.currentFrameIndex=-1,this.iterationCount=0,this.stepping=!1,this.handler={hdr:this.withProgress(this.doHdr.bind(this)),gce:this.withProgress(this.doGCE.bind(this)),com:this.withProgress(this.doNothing.bind(this)),app:{NETSCAPE:this.withProgress(this.doNothing.bind(this))},img:this.withProgress(this.doImg.bind(this)),eof:function(){n.pushFrame(),n.canvas.width=n.hdr.width*n.getCanvasScale(),n.canvas.height=n.hdr.height*n.getCanvasScale(),n.playerInit(),n.loading=!1,n.ready=!0,n.loadCallback&&n.loadCallback(n.gifImgElement)}},e)this.options[r]=e[r];this.onEndListener=e.onEnd,this.loopDelay=e.loopDelay||0,this.overrideLoopMode=null!=e.loopMode?e.loopMode:"auto",this.drawWhileLoading=null==e.drawWhileLoading||e.drawWhileLoading}return n.prototype.init=function(){var t=this.gifImgElement.parentNode,e=document.createElement("div");this.canvas=document.createElement("canvas"),this.canvasContext=this.canvas.getContext("2d"),this.tmpCanvas=document.createElement("canvas"),e.className=this.options.enclosingClass||"super-gif",e.appendChild(this.canvas),t&&(t.insertBefore(e,this.gifImgElement),t.removeChild(this.gifImgElement)),this.initialized=!0},n.prototype.loadSetup=function(t){return!this.loading&&(t&&(this.loadCallback=t),this.loading=!0,this.frames=[],this.clear(),this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,!0)},n.prototype.completeLoop=function(){this.onEndListener&&this.onEndListener(this.gifImgElement),this.iterationCount++,!1!==this.overrideLoopMode||this.iterationCount<0?this.doStep():(this.stepping=!1,this.playing=!1)},n.prototype.doStep=function(){if(this.stepping=this.playing,this.stepping){this.stepFrame(1);var t=10*this.frames[this.currentFrameIndex].delay;t||(t=100),0===this.getNextFrameNo()?(t+=this.loopDelay,setTimeout(this.completeLoop.bind(this),t)):setTimeout(this.doStep.bind(this),t)}},n.prototype.step=function(){this.stepping||setTimeout(this.doStep.bind(this),0)},n.prototype.putFrame=function(){var t;this.currentFrameIndex=parseInt(this.currentFrameIndex.toString(),10),this.currentFrameIndex>this.frames.length-1&&(this.currentFrameIndex=0),this.currentFrameIndex<0&&(this.currentFrameIndex=0),t=this.frameOffsets[this.currentFrameIndex],this.tmpCanvas.getContext("2d").putImageData(this.frames[this.currentFrameIndex].data,t.x,t.y),this.canvasContext.globalCompositeOperation="copy",this.canvasContext.drawImage(this.tmpCanvas,0,0)},n.prototype.playerInit=function(){this.loadErrorCause||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.options.autoPlay?this.step():(this.currentFrameIndex=0,this.putFrame()))},n.prototype.clear=function(){this.transparency=null,this.delay=null,this.lastDisposalMethod=this.disposalMethod,this.disposalMethod=null,this.frame=null},n.prototype.parseStream=function(e){try{new t.SuperGifParser(e,this.handler).parse()}catch(t){this.handleError("parse")}},n.prototype.setSizes=function(t,e){this.canvas.width=t*this.getCanvasScale(),this.canvas.height=e*this.getCanvasScale(),this.tmpCanvas.width=t,this.tmpCanvas.height=e,this.tmpCanvas.style.width=t+"px",this.tmpCanvas.style.height=e+"px",this.tmpCanvas.getContext("2d").setTransform(1,0,0,1,0,0)},n.prototype.drawError=function(){this.canvasContext.fillStyle="black",this.canvasContext.fillRect(0,0,this.hdr.width,this.hdr.height),this.canvasContext.strokeStyle="red",this.canvasContext.lineWidth=3,this.canvasContext.moveTo(0,0),this.canvasContext.lineTo(this.hdr.width,this.hdr.height),this.canvasContext.moveTo(0,this.hdr.height),this.canvasContext.lineTo(this.hdr.width,0),this.canvasContext.stroke()},n.prototype.handleError=function(t){this.loadErrorCause=t,this.hdr={width:this.gifImgElement.width,height:this.gifImgElement.height},this.frames=[],this.drawError()},n.prototype.doHdr=function(t){this.hdr=t,this.setSizes(this.hdr.width,this.hdr.height)},n.prototype.doGCE=function(t){this.pushFrame(),this.clear(),this.transparency=t.transparencyGiven?t.transparencyIndex:null,this.delay=t.delayTime,this.disposalMethod=t.disposalMethod},n.prototype.pushFrame=function(){this.frame&&(this.frames.push({data:this.frame.getImageData(0,0,this.hdr.width,this.hdr.height),delay:this.delay}),this.frameOffsets.push({x:0,y:0}))},n.prototype.doImg=function(t){var e=this;this.frame||(this.frame=this.tmpCanvas.getContext("2d"));var n=this.frames.length,r=t.lctFlag?t.lct:this.hdr.gct;n>0&&(3===this.lastDisposalMethod?null!==this.disposalRestoreFromIdx?this.frame.putImageData(frames[this.disposalRestoreFromIdx].data,0,0):this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height):this.disposalRestoreFromIdx=n-1,2===this.lastDisposalMethod&&this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height));var i=this.frame.getImageData(t.leftPos,t.topPos,t.width,t.height);t.pixels.forEach(function(t,n){t!==e.transparency&&(i.data[4*n+0]=r[t][0],i.data[4*n+1]=r[t][1],i.data[4*n+2]=r[t][2],i.data[4*n+3]=255)}),this.frame.putImageData(i,t.leftPos,t.topPos),this.ctxScaled||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.ctxScaled=!0),this.drawWhileLoading&&(this.canvasContext.drawImage(this.tmpCanvas,0,0),this.drawWhileLoading=this.options.autoPlay),this.lastImg=t},n.prototype.doNothing=function(){},n.prototype.withProgress=function(t){return function(e){t(e)}},n.prototype.getNextFrameNo=function(){var t=this.forward?1:-1;return(this.currentFrameIndex+t+this.frames.length)%this.frames.length},n.prototype.stepFrame=function(t){this.currentFrameIndex=this.currentFrameIndex+t,this.putFrame()},n.prototype.getCanvasScale=function(){return this.options.maxWidth&&this.hdr&&this.hdr.width>this.options.maxWidth?this.options.maxWidth/this.hdr.width:window.devicePixelRatio||1},n.prototype.play=function(){this.playing=!0,this.step()},n.prototype.pause=function(){this.playing=!1},n.prototype.isPlaying=function(){return this.playing},n.prototype.getCanvas=function(){return this.canvas},n.prototype.isLoading=function(){return this.loading},n.prototype.isReady=function(){return this.ready},n.prototype.isAutoPlay=function(){return this.options.autoPlay},n.prototype.getLength=function(){return this.frames.length},n.prototype.getCurrentFrame=function(){return this.currentFrameIndex},n.prototype.moveTo=function(t){this.currentFrameIndex=t,this.putFrame()},n.prototype.loadURL=function(t,n){var r=this;if(this.loadSetup(n)){var i=new XMLHttpRequest;i.open("GET",t,!0),"overrideMimeType"in i?i.overrideMimeType("text/plain; charset=x-user-defined"):"responseType"in i?i.responseType="arraybuffer":i.setRequestHeader("Accept-Charset","x-user-defined"),i.onloadstart=function(){r.initialized||r.init()},i.onload=function(){if(200===i.status){var t=i.response;t.toString().indexOf("ArrayBuffer")>0&&(t=new Uint8Array(t));var n=new e.SuperGifStream(t);setTimeout(function(){r.parseStream(n)},0)}else r.handleError("xhr - response")},i.onerror=function(){r.handleError("xhr")},i.send()}},n.prototype.load=function(t){this.loadURL(this.gifImgElement.src,t)},n}();return Bp.SuperGif=n,Bp}();const Xp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"src",name:"src"},{type:"checkbox",label:"play",name:"play"}],"value-property":"src",help:"scene/component/gif-view"};class qp extends jp{async oncreate_element(t){const{src:e,play:n}=this.state;this.onchangesrc(e),this.onchangeplay(n)}buildImg(){const t=this.element;if(!t)return document.createElement("img");t.replaceChildren();const e=document.createElement("img");return e.style.width="100%",e.style.height="100%",t.appendChild(e),e}onchange(t,e){super.onchange(t,e),"src"in t&&this.onchangesrc(t.src),"play"in t&&this.onchangeplay(t.play)}setElementProperties(t){}onchangeplay(t){const e=this._superGif;e&&e.isReady()&&(t?e.play():e.pause())}onchangesrc(t){const e=this.buildImg();t||(t="data:image/gif;base64,R0lGODlhYABIAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKio+Pj5iYmKCgoKampqurq66urrCwsLGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrOzs7S0tLa2tre3t7m5ubu7u7+/v8DAwMHBwcPDw8XFxcfHx8vLy8/Pz9LS0tXV1dfX193d3eTk5Onp6fj4+Pz8/P7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v///////////////////////////////////////////////////////////////////////////////yH5BAkAAPUAIf47R2VuZXJhdGVkIGJ5IGpzZ2lmIChodHRwczovL2dpdGh1Yi5jb20vYW50aW1hdHRlcjE1L2pzZ2lmLykALAAAAABgAEgAAAj+AGcJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8ePIEOKHEmypMmR9VKqXMmypcuXMGPKnJkSIs2bOHPqZGlzp8+fQOv1DEq0KMyhRpMmRaq0KVCmTqPmhCq1qkyqLrFRSyYwGTVsVo1iZXmNa8Fk18ISHasSm1mDycCq/ck2JTWF1ObSfTjz7cFken3WFbow8M7BDA3rHOwXruKpfGXeTZg3qDVrUge7RRg3KLZjx+Q2HVyvLNy0QaMJjBaVdD2tZr2K/mmNIObRkR+n9AsYt0Pddg1WXppb8bWDx1CLLW74GcJnSl3TtDY8Zu2Et4tKl7n52eyWnxXvhl7+26jqrspbnlfIWjtz2gWPZV95neH8veU9NxZYfbfD3kFt99J6Bnmn0mQO9XfYezrVxxlmx0GUXIAM4hSeffsxBN1TFd5E4Ef3QZbfTg6CNJ5gHXJ3TEntLThiTh+KFCJNAqZU4kgAitjQTheepOBMNcZI0oQ6JpbTjSZtiNN2PZ400IxHpdiSc07G911M0iFZZYtAStnWilUeBGVLrlEZpmM0elmPlmfO8iOZXl4DZpsGEYmll2bSWWCXLwJXVY1+urhjoGEBSuiSah6K36CKtpZoo4s9CimielZq6aWYZqrpppx26umnoIZ6UkAAOw=="),e.src=t,e.setAttribute("rel:animated_src",t),e.setAttribute("rel:auto_play",String(0)),this._superGif=new Wp.SuperGif(e,{autoPlay:!1}),this._superGif.init(),this.element&&Array.from(this.element.children).forEach(t=>{t.style.width="100%",t.style.height="100%"});const n=this._superGif.getCanvas();n.style.width="100%",n.style.height="100%",this._superGif.load(()=>{setTimeout(()=>{this._superGif.moveTo(0),this.play&&this._superGif.play()},100)})}ondropfile(t,e){for(let n=0;n<t.length;n++)if(/\.gif$/.test(t[n].name))return void(this.src=e[n])}get src(){return this.getState("src")}set src(t){this.set("src",t)}get play(){return this.getState("play")}set play(t){this.setState("play",t)}get nature(){return Xp}get tagName(){return"div"}}tc.register("gif-view",qp);const Kp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"attachment-selector",label:"src",name:"src",property:{category:"audio"}},{type:"checkbox",label:"started",name:"started"},{type:"checkbox",label:"loop",name:"loop"}],"value-property":"src",help:"scene/component/audio"};class $p extends(rc(ec)){static get image(){return $p.IMAGE||($p.IMAGE=new Image,$p.IMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAMAAAC3Ycb+AAAAP1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACzJYIvAAAAFHRSTlMA8BAwgNBgQKB/wCBwUJDg37CvXyUlBK8AABFYSURBVHja7NsBkqIwFIThTiAQgyBq3/+sm6p1tnamZkaTMhJJf1f4S/JeEIiIiIiIiIiIiIiIiEhD7Hg4BH84TpAKjJ4f3NFCtjVd+InXz2RTs+FXlxGylYHfcVfIJmb+YFWSLUyGVJKKBJJKUo+Rd6w63l/qzLuCkryO5fe0l2xk5mMWbe+v0fNBRqf7S3je6CipQ2ACr+dWcYEpzBFS1plpguatsnomMgdIQSOTuQ5SjmE6/UgK8szgdJIUM/FG41YlFmYJ2kkKsY5ZzAwBurHDk3WGeRY0bvYrGa1+rqNI22f7dS32ZnUK1GMr0eSK3mEc9dhKMxp+ZTo8kT2emOXS5LQ1kCxbJBocSd2k5PaIjMVzjWcdJPk9ooBnmzx1t5XbIxqBKpJ4NGTgzwKiGpK4do72gb+ZUMIYtCPm9WCPMsYTE5k2hq2ZvzujlCE1iRmwf3dvmRyKsT0T7b9I7HEPCpqCiqT2IIqaT1pI0noQZdlFC8l/PbYPAnRORT56VBEE6FXkb49agmByKhJ71BME6FsvEntUFQTdqekisUdlQWCXhovEHtUFAWbTapHYo8YgmFybO3vsUWcQYGmxSOxRbRAMprkisUfFQVKmrX18sxt7VB0ENjT1xir2qDxIwkFi3v89e+xRfxAMzfzzIfZ4hyAYDR9zwVuLPd4jCDrTwoLYGb5LEFi3/+E3rweR6urX20c/Fvls2Pvwm9mDSGIPhv8YPyGf3/eo9Ye7O8B2FIShAAooakEttex/rbODad5/yTHIAjqn505IQPv+Xz06dz+4VXORHEZcgAcB8updM8F6e25jBzwIkE07l+x8amMnPDp6nsNJ+BoZ7Q6F8egqAda9VEuRNlZjBzwYkMskdXR73okd8GBAJiKYjBcZKKqG9OiKDbgdfxJ5VhsBPDiQZhaouD3p4hfw4EAmwxisz3MSHwAPEmQ1TB1N+SmXWoAHC7JbZsWl/IxLLcCDBplNo3lrfMLsmwAPGmShAxX5/1vOEzjEz3iyfQ/hI36W4TctsUesOAifPdrQg8M++KYl95iCBkjI1r8634betBAPHZDTPFAmD3zLiHgogVTziMsahz0eIh5aIGHGRSJ2mFtHPR4iHhQIP2UvWGMf8wk74qEIEib7rLjPiBfxiAcCwp8V+Nae3uMdRhAPDIR/J5f/Q2DTcC+hIB7qIGEq3Ti9bx+sryMeAAgS70OK8G2kBD8L8QBAoLWU3g3vUVIc6D0txAMAsY+4jBWowXHO64gHBGKfYJ2T5qY1BxcL98BB+PQ+XiS9xxh9EQ8ChA6C5UXWIUoE9MBB8LVHQoS7ib8/dRn3sAcJ6bQRSdH96RDxIEH4QEX+AHF4LxHEAwUh12xyr1V8lwjiQYDYF8kuf1jluUQQDwrEvkhW8Wc6LhHUgwfhi4QPlHm7LRHawx4kpE191Dq8lgjhAYDQa1cftYrPEiE8OJDb40uqyzdQCA8WhAzL4G/PT4c3WrgHD2IfllGl53V37zsgHg5ApPNvVvq4Fn4spx4oiH1W3CwtEV+PDhEPJyBSkVX4aa7emkM83ICEKWpGM7wdvYCCeDgCEYpcwhLxczhEPFyBCEUWnRL5T6X59SBASBF+9l28TL5F7uEORCZyCUvEx+S7yT0cgoRVb9JaXLR1qUdfgksQ0fTbgmhFB20d8HAKEha14+F8f1sHPNyCiL6EqK+n20/rgIdjkFC0Ho1s6Gndvcc9ICkr/ey8/rHO6vp9KawL8DAFOV6l9Fyub7IbflsCag1qRfVsXWvxHjxIejU+BHZV6uvHD1XiEb++Bw8i+dNd+Wv0eCQmhcPhRPwUUt2DB5G1sfa1aeyzAuyJj9x2HjyIdKzIKw5SI14ieFtvo3kIQERj3lVhkUOnRD7AnjV5369QkAOJZeCH+Jh41xOLs73dQwAifY6dpxCCbjTDzLf1Bm1Y93tAIDOWXcLPvrHyr2hVoEAceEAgDQzB4jetk0/c2OXRHB48EJCpa4dgpYh2ETxtrshz7zx4ICCzfuTSDn8p/EOS9OTjwgMB+cABP3yWYuOPIofs33LigYCULlpZNXJppVU30Vf14kGAUCLijf1D71lN9FW9eFiA9KgZ8FPpPUsSnufGA+8hvAg2Kpz0nrX//qp+PIgpC3i6xJRITOye9fn1VT15ICCrVlQG5rywo0H8x965bVkNwmCYQ2kR6Gmb939WXV65dFnI/tPdjPBfO7XMN4EkTUJtqZp4sCJ1+8jwkhMu0KpMxFXFA8hlVfQSMxGH5mDK1VKV8QCyvTVtUiYyo7V358VStfGoAEFMhGYhEwloxZy9WKo2Hjwg5iSOvFDXeUYd33+PuVfHgwnEBWLocDJp+IIa2fyvperjwQRiXCKGosyXqoA+YfsIELuYu4HAt+msMknfDK4jfQJIzOZ2IPAQWJtFOhQKivR2IDZ6Awis7V0iLxqBI7uEZo19dakTogLSwKvf8yk8Jq6CGK0GKvWlatG7b7kkUU/Lo1gdXWn7/4E0j0qeJDpqN/ABqQcgJgdqURb4chjQktIugDS6wFFiz3JgaJj7AGJmholAe9YKhoZLJ0Ca6smjwJ4VwVN96gVIE5GM71kHaGKxGyAtRDaB2NBhLVmpHyANRKzDO28W7FS3HQFpaIWa8TrfCXQwegJSL5k+8M9UJ+pm9QTEnCIZrR0MDQeQ9ua0iCcYQaBTV0CqNXQW/yiyYG7W1heQanPaCkciBXuH1BkQJzHcDQxmpgGkPatl4WkbCXO/bW9AqlNg4H0PPMi6A1IxkQmOZ8D0ousNSMVEEuyreTAQ6Q7IRJeCX2YZQHhv6SrBOmpkM+YUzN0BqSRQCupmTeCP9wdkhiOREwtEzgGEsWcF9BhK9R8fQDiN7A8DiR0CKXQlj/q9IM8OgXjIzcKBlAHkD6FulgNzJwPIHwpo8mQAkX3LiPq9dKUMAQk9AqmcqmjuBAJCPQIpA4guIAsKJA0gnwNy3A4kDyBIHCEPxAwgf8gPILqA5AFEF5CxZX0lIHYc6rqADLf380BmFMgxgIzUyf8MJKLTRelKHgKy9wgkjfS7LiA0gKgC8vQn3HUA4RQ5LKPIAQciWbqIEg0YkLNDIHYUyqkCsmKN5vg3+W0AYTRATaPY+uu1IwS6UMGAlO6AFPjSCQMStaNh53cdcPG7Hx1Uupo+rx+Bltn1BuTAj5BptEV/bHAAwbnJMICwRmtUDOSEA8s4Rmtw3nITGD6TwUNoG0Ca7xi2YKSPj2eKXQFxQWKA2QbGMWEMMGseOb7C7T47uJS1JyAzVbTjqZdU3zbHzMXWS+qp4Fgn8Ahy/QCRGqQcwU1vGnN7fylboWn8Bzg//hyjxltvdcl45bwFfYKzFyBy11UU9BnjuoqfWizVlQXulpzBTNbaB5Aid+VRrkBFB630AMS9BC8FK2ggE7u/FGy1kvfcB9TKQufX5uUXNWl3EjvWCi4k/u9A3Ddq1CpTIQGe6VN1qd8ArcvDQNw3S41Kn6qQmOq5e7pRr+8fAYLiIJtFrrvYRMYL0q06vj8EZLXUriJzRY8H1xEagOCK7gkghRg6RQYO0I6aWPwIEAru80AiMWSdzAeuDXUKyr+WqpAID8hMHC1Ct8F4mUsQ6W8pJMICki0JHCBczAFdBl38G3VE6ErQhhWlih4LWrCSLpaqjggHiGe9mVjRY0YPoelyqcqIcIDEe97rqJFFH7FcLlUZEQ6Qg5plvZiBFNhtri1VFREGEC/Eg4nZoU5vqi1VFREGkIXDQ8xAIhzoT/WlKiLCAFIYPOQMxOPdjfWlKiLCADJRm3YGj+pDE2xktmmpaogwgMz8d8GrumZ4xzpbvinqISJ+hiTWm7wEqoJdI9JEV9JChAEkS3xCZzKecLcgN6YwlRBhAGmweTsblg6qKMM7Vmh321UQ4QAp1VfwhqVJIh+Wm03W0qV0EOEAybXtivkCmWrKeH2EZ/xBaSBCV2L9Re+LYSqJJIxDu1ew07U0EGEBcTtmHty4JuPtQhvLh1BAhK7Uvvq0GK484QZST0GvvFDqeSJ1IA0r2mfDljvqBoJ//rVsq7yZCA6kXgVkJ2f4ijIGMjOfMVsCBBORB2Jy+sM6ijNvaBUqmw/cStZ8EiKciHwp6Rp++88qmxXQeTUxDiJWJ9wSISvBicgXW+dypn1PqWTznlwgwdZdfiLHr5OELEAEASKvJFRE5JCPKbh8OxHdQKJU0crEzRXrJ/IEkFms6tGyrUw9kQeALFRXvK2iSzsRAAi6BLxM+60xdsqJAEBuXMAMxDLVp+gmAgC57/UT4qvVj3TVRCAgSAYL91aXtyNLzUQAIFhAiP8m0/NHOp+ILiBtPFKrs6bgSOcT0QTEB8nO3QR1yKslggKRf+m11UB0HOl8IlqAeCvauXuo8HnfIqIDyCw6G8XMcGiplMingMzCnbuHFp/3LSLPA4nUpqm5YkWNzwsQeQxIDsKjH5wVSU5qJPIJIIt4jjpqNBAekQeBfJOeHWS81FQoo4/I7UDcS3wUh0liTzLqiEgDqddx4ZHDrNZAACIAEMw88HPYWb0GAhABgEDmgf9Vb5oNBCByOxD3uqWYbCHVBgIQuRlIsbfwMEG5gQBE7gSyHMDsOayrxJvHBRC5B0hOxJH1nK4SlUE6QOR+IG6ju3iYQEqDdIDIzUDyZu/jMRHpS/OiRG4FkiPRfTw8kbrvIAJEACAIDpyHC1/GQHhEbgKSXwTyqIeEur6kixEBgABHOTr7YSX1MSFAhA0E307wUU76Y0KACAsI/tvCRzkF+iIuL0AEAYLbR2QOfvhKJ/obRESBxNt5rPSFXN4f7dyNdqMgEIbhAXWwJErT/e7/Wreb5HTT07QVgWSAeW5g7b4n8qOSUCRPEId4HP93SXp5dDNGRJFcQTxihSH+NW1Bb1cXKpIryJAwnG/zhl8ZcSP6jiKZghwRaaWLnP/AkcSKKJIniEcUs8QfjFLdEmRvkSxB4lfn0QN6DY+lshQpHiT96Dlr6r5hxRUpHST9ZEY71X7DOmOZQVZLsd5Q8wzrPxYYJDiKNqOBG1ZCkZKzrNXu6lHvkjChSFqQsdTPg45ApXtYaUXKr9TNuPcvqO2pVMkitFXAL2a79/qr3HQvVSTXUtofCl79RDXh5CDpw3pwu6+9kRlvtiI5VtPhmHLltT4EKVQkfb8pcOHrXqk6nBAksUjgpKtuYsskaxGKYT0+84uYgziE4YQgMdx0m8PRfis2MbL33PMXoVjD6PEunI4HSjDjStiJP08vQk9hZzQ7oH/geoLYCUBDW4rf4FqCDFt7THUO6B+4jiDn2XNTW7zf4hqCMND4BOsGyw+yAmh0x+QeFh7EeqD5Ce8nLDrI8NpbDyIWHIQNruo4GyAPlhrEzuixBxHLDDJMnfYgYolBricHNfjIdgMWF+Qyu+pkgX4HCwuymL57ELGkIHZG7z2IWE6Q5VV7vGMhQewbtMcZiwhyHj26ne9+xs8PcvDQHnFFqCD7Au0RW4TK+fOKqw4eoOcqYqgU53HR3/5uShFPCfKey9hFDyJO/vAi7RDZnp7X5igyUH72xSDW1E2Pn4tMRCQgR8vLwbgii4gcmLvqQcSPGtIPX3M08wn6I4qYQ94cM/Yw9Xxhmw+X/59wHrtMlX1AmIkzdyaaAnLg1Nnw8WGYSk40X/BOh4+El6LMSBnN2Cd0tPq4w/LJXGrMbCX06PZ2dcM65yzlNertShSHf3SzRAyPM332IcSAHUKPi8EHmXU0l8Uglmni0yipDoi16s+jJKejhywLooz68yiMEcHr2qM4h81CJ++VPJfTu5UwBpv4Pp9DJSi6MJx0bvUwiw4ewgT8zNR0LHUL+OccOpY/3ElzyGKD5pBlMJpDlsOkMythRoNbXh95PJsdA67MrMtAEYbjeDqNo+7oKqWUUkoppZRSSimllFJKFfMXp4vmSjB8n6sAAAAASUVORK5CYII="),$p.IMAGE}dispose(){super.dispose(),this.started=!1,delete this._audio}async ready(){super.ready(),this._audio=new Audio,this._audio.addEventListener("canplay",()=>{this.started&&this._audio.play()});const{src:t="",loop:e=!1,started:n=!1}=this.state;this.onchangeSrc(t),this.onchangeLoop(e),this.onchangeStarted(n)}render(t){const{left:e,top:n,width:r,height:i}=this.state;t.beginPath(),this.drawImage(t,$p.image,e,n,r,i)}get nature(){return Kp}get hasTextProperty(){return!1}get src(){return this.get("src")}set src(t){this.set("src",t)}get started(){return!!this.get("started")}set started(t){this.set("started",t)}start(){this._audio&&(this._audio.classList.add("active"),this._audio.play())}pause(){this._audio&&(this._audio.classList.remove("active"),this._audio.pause())}onchangeSrc(t){try{"data"!==String(t).substring(0,4)?this._audio.crossOrigin="use-credentials":this._audio.crossOrigin=null,this._audio.src="string"==typeof t?this.app.url(t):t}catch(t){return void Wr(t)}}onchangeStarted(t){const e=this._audio;t?4==e.readyState&&e.play():e.pause()}onchangeLoop(t){this._audio.loop=t}onchange(t,e){"src"in t&&this.onchangeSrc(t.src),"started"in t&&this.onchangeStarted(t.started),"loop"in t&&this.onchangeLoop(t.loop)}ondblclick(t){this.started=!this.started}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("audio/"))return void(this.src=e[n])}}tc.register("audio",$p);class Qp extends(rc(tc)){is3dish(){return!0}}tc.register("text",Qp);const Zp=["refid","left","top","width","height","rotation","animation"];class Jp extends lp{isGroup(){return!0}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=Zp.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{});return super.set(n,void 0)}capture(t,e,n){const r=super.capture(t,e,n);if(r!==this)return r}set bounds(t){if(this.__MUTATING__)return void(super.bounds=t);const e=this.bounds,n=t.width/e.width,r=t.height/e.height;this.path=this.path.map(i=>({x:t.left+(i.x-e.left)*n,y:t.top+(i.y-e.top)*r})),this.components&&this.components.forEach(t=>{if(t.mutable)t.mutatePath(null,function(t){return t.map(function(t){return{x:t.x*n,y:t.y*r}})});else{const e=t.bounds,i=t.center,s={x:i.x*(1-n),y:i.y*(1-r)},o=e.width*(1-n),a=e.height*(1-r),c=-(s.x-o/2),l=-(s.y-a/2);t.bounds={left:e.left+c,top:e.top+l,width:e.width*n,height:e.height*r}}})}get focusible(){return!1}get bounds(){return super.bounds}get hasTextProperty(){return!1}isIdentifiable(){return!1}calculateBounds(){this.clearCache(),this.__MUTATING__=!0,this.mutateBounds(function(t){const e=tc.union(this.components.map(t=>t.bounds));return this.components.forEach(t=>{const n=t.bounds;t.bounds={left:n.left-e.left,top:n.top-e.top,width:n.width,height:n.height}}),{left:t.left+e.left,top:t.top+e.top,width:e.width,height:e.height}},this),this.__MUTATING__=!1,this.parent.isGroup()&&this.parent.calculateBounds?.()}render(t){}postrender(t){const{top:e,left:n}=this.state;t.translate(n,e),this.layout.drawables(this).forEach(e=>{e.draw(t)}),t.translate(-n,-e)}}tc.memoize(Jp.prototype,"bounds",!0),tc.register("group",Jp);const tf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"id-input",label:"ref",name:"ref"},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio"]}}],"value-property":"ref",help:"scene/component/local-ref"};class ef extends(rc(ec)){get ref(){const t=this.getState("ref");return t&&"string"==typeof t?this.root.findById?.(t):null}set ref(t){this.setState("ref",t)}get refScale(){const t=this.ref;if(!t)return{x:1,y:1};const e=t.bounds,n=this.bounds,r=n.width/e.width,i=n.height/e.height;return"both"===this.model.fit?{x:r,y:i}:{x:Math.min(r,i),y:Math.min(r,i)}}draw(t){this._drawing||(this._drawing=!0,super.draw(t),this._drawing=!1)}prerender(t){if(super.prerender(t),this.ref){const e=this.ref.center,n=this.center,r=this.refScale;t.translate(n.x,n.y),t.scale(r.x,r.y),t.translate(-e.x,-e.y)}}postrender(t){if(this.ref)return this.ref.postrender(t);super.postrender(t)}render(t){if(this.ref)return this.ref.render(t);const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),t.rect(e,n,r,i)}get nature(){return tf}get hasTextProperty(){return!1}}tc.memoize(ef.prototype,"ref",!1),tc.memoize(ef.prototype,"refScale",!1),tc.register("local-ref",ef);class nf extends(ip(Tc)){render(t){}is3dish(){return!0}get layout(){return lc.get(this.get("layout"))||hc}}const rf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"scene-number",name:"ref",placeholder:"SCENE-1"},{type:"number",label:"round",name:"round",property:{min:0}},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio","width","height","none"]}},{type:"select",label:"mode",name:"mode",property:{options:["view","interaction"]}}],"value-property":"ref",help:"scene/component/global-ref"};class sf extends nf{dispose(){this._releaseRef(),super.dispose()}get nature(){return rf}get hasTextProperty(){return!1}get tagName(){return"div"}setElementProperties(t){const{mode:e="view",round:n=0}=this.state;t.style.pointerEvents="view"==e?"none":"inherit",t.style.borderRadius=n+"px"}async ready(){super.ready(),this.fetchRef()}reposition(){if(!this.element)return;super.reposition();const t=this._element_bounds,{offsetWidth:e,offsetHeight:n}=this.element;if(this._element_bounds={offsetWidth:e,offsetHeight:n},(!t||t.offsetWidth!=e||t.offsetHeight!=n)&&this.ref&&this.root.target_element){const{fit:t="ratio"}=this.state;this.ref.fit(t)}}async fetchRef(){this._releaseRef();const{ref:t,fit:e="ratio"}=this.state;if(!t)return;const n=this.app.refProvider;if(n&&t)try{this.__ref=await n.get(t,!0),this.__ref.target=this.element,this.__ref.fit(e),this.__ref.data=this.data}catch(t){Wr(t)}}get ref(){return this.__ref}set ref(t){this.setState("ref",t)}_releaseRef(){this.__ref&&this.__ref.release&&this.__ref.release(),delete this.__ref}onchange(t,e,n){super.onchange(t,e),"ref"in t&&this.fetchRef(),"fit"in t&&this.ref&&requestAnimationFrame(()=>{const{fit:t}=this.state;this.ref.fit(t)}),"data"in t&&this.ref&&requestAnimationFrame(()=>{this.ref.data=t.data})}}tc.register("global-ref",sf);const of="center-middle",af={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"board",name:"board"},{type:"checkbox",label:"modal",name:"modal"},{type:"checkbox",label:"closable",name:"closable"},{type:"checkbox",label:"draggable",name:"draggable"},{type:"checkbox",label:"minimizable",name:"minimizable"},{type:"checkbox",label:"show",name:"show"},{type:"select",label:"popup-position",name:"popupPosition",property:{options:["static","absolute"]}},{type:"select",label:"popup-origin",name:"origin",property:{options:["left-top","center-top","right-top","left-middle",of,"right-middle","left-bottom","center-bottom","right-bottom","auto"]}},{type:"string",label:"title",name:"text"},{type:"data",label:"value",name:"value"}],help:"scene/component/popup"};class cf extends(rc(ec)){static get image(){return cf._image||(cf._image=new Image,cf._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAMAAABG8BK2AAADJmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNy4xLWMwMDAgNzkuZGFiYWNiYiwgMjAyMS8wNC8xNC0wMDozOTo0NCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIzLjAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RkM4QzQxNUMzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RkM4QzQxNUQzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpENjlENTQ3RjMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpENjlENTQ4MDMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsiUYSQAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAA51BMVEVHcEwzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzOguTm2AAAATHRSTlMARhB73r9B7YLrsqdE+0cq9Avzeg31eQx4aQ+Ks6aUd5DsYKixEX1w8vyT2VjoZ3YezY/cCEDvl+QTvRwJ0ifwK/5T/aw6+IuFuCImAcS6MQAAAeJJREFUWMPt2FlX2zAQhuHJYmOSFhIggbC0QNn3rS1dKXSH9///Hi58CJLxKIpEWi6YO8c5z4lG/nxGEXmu/1OVLGnhrFaSVQYg1SZetTTvUibqeFZ9QlfmvRWoV1VmCaCRzroXPpsuAjTV7gLUfPahBqD1OQMW/fazAWTKvQRI/ZgUSJR7U8CM/dHZ+/2VcatWdvdEZAaYUhiAwkerJXt0rnzXwdRKmHfDM0fHD5kxjTFyVLzVfvvirn7+cDJWjhy7c7XlYuwc6Urvu2tRhRypyhwAf1sKY+TIxfQA+H39q5wxc+RgVrcBduTmZTlj5khnDgH4IzKpMGaOVCbvyyvRGTNHGtPrKypjXirM5jb910I4k69oQeKY+77EMAcALEsck/+W6f71tyCma/ZFROTrJVwMy7wmf3bv6/MX+Dgkkysblvxps/dhOKZb6IvrTakzXXuPApnpYneDGOeKvJlaSXcDmA7AicQyW84VeTOnY+NdiWcG1uiZksFEHdyAlsJEjEkmkwGNsKHNZCJGSKtVTYC1tO022mnjwUBrMdXg8dreuOBhv7D/62/8lGZ1wLxXyZKOm+iUHIQintyny0TkaATHjYgcjeAoFpEje9R/nGPqIx2aw3NU9odCQI6e6x/VLY32cKQXVBnkAAAAAElFTkSuQmCC"),cf._image}async ready(){await super.ready(),this.show&&this.onchangeShow(!0)}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),this.drawImage(t,cf.image,e,n,r,i)}onchange(t,e){"value"in t?this.show?this.onchangeShow(!0):this.show=!0:"show"in t&&this.onchangeShow(this.show)}onchangeShow(t){!this.app.isEditMode&&this.getState("board")&&(t?this.openPopup(this.value):this.hidePopup())}openPopup(t,e){this.app.isEditMode||kc.show(this,this.getState("board"),{origin:this.getState("origin")||of,modal:this.getState("modal"),closable:this.getState("closable")||!1,draggable:this.getState("draggable")||!1,minimizable:this.getState("minimizable")||!1,popupPosition:this.getState("popupPosition"),title:this.text,data:t||this.value,...e})}hidePopup(){kc.hide(this)}get board(){return this.getState("board")}set board(t){this.set("board",t)}get show(){return this.getState("show")}set show(t){this.setState("show",t)}get started(){return this.getState("show")}set started(t){this.setState("show",t)}get value(){return this.getState("value")}set value(t){this.setState("value",t)}get hasTextProperty(){return!1}get nature(){return af}}tc.register("popup",cf);class lf extends tc{render(t){const{path:e=[]}=this.state;if(!(e.length<=1)){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)t.lineTo(e[n].x,e[n].y);t.closePath(),this.drawStroke(t,void 0)}}get path(){return this.model.path}set path(t){this.set("path",t)}contains(t,e){const n=this.state.path;let r=!1;return n.forEach((i,s)=>{const o=(s+n.length+1)%n.length,a=i.x,c=i.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(r=!r)}),r}}tc.register("path",lf);const hf={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/triangle"};class df extends ec{is3dish(){return!0}contains(t,e){const{x1:n,y1:r,x2:i,y2:s,x3:o,y3:a}=this.state,c=[n,r,i,s,o,a];let l=!1;for(let n=0;n<c.length;n+=2){const r=(n+2)%c.length,i=c[n],s=c[n+1],o=c[r+1];s>e!=o>e&&t<(c[r]-i)*(e-s)/(o-s)+i&&(l=!l)}return l}get mutable(){return!0}get path(){const{x1:t,y1:e,x2:n,y2:r,x3:i,y3:s}=this.state;return[{x:t,y:e},{x:n,y:r},{x:i,y:s}]}set path(t){this.set({x1:t[0].x,y1:t[0].y,x2:t[1].x,y2:t[1].y,x3:t[2].x,y3:t[2].y})}get nature(){return hf}}tc.memoize(df.prototype,"path",!1),tc.register("triangle",df);const uf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"}],help:"scene/component/donut"},pf={ondragmove:function(t,e,n){let{cx:r,rx:i}=n.model;i=Math.abs(i);let s=(n.fromParent(t.x,t.y).x-r)/i*100;s=s>=100||s<=-100?100:Math.abs(s),n.set({ratio:s})}};class ff extends Ap{is3dish(){return!0}render(t){let{ratio:e=50,cx:n,cy:r,rx:i,ry:s,startAngle:o,endAngle:a,anticlockwise:c}=this.state;i=Math.abs(i),s=Math.abs(s),t.beginPath(),t.ellipse(n,r,i,s,0,o||0,a||2*Math.PI,c),t.moveTo(n+i/100*e,r),t.ellipse(n,r,i/100*e,s/100*e,0,o||0,a||2*Math.PI,!0)}contains(t,e){let{cx:n,cy:r,rx:i,ry:s,ratio:o}=this.state;i=Math.abs(i),s=Math.abs(s);const a=(t-n)/(2*i-.5),c=(e-r)/(2*s-.5),l=(t-n)/(i/100*o*2-.5),h=(e-r)/(s/100*o*2-.5);let d=!1;return a*a+c*c<.25&&l*l+h*h>.25&&(d=!d),d}get controls(){let{cx:t,cy:e,rx:n,ratio:r}=this.state;return n=Math.abs(n),[{x:t+n/100*r,y:e,handler:pf}]}get nature(){return uf}}tc.memoize(ff.prototype,"controls",!1),tc.register("donut",ff);const gf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"},{type:"number",label:"wing",name:"wing",property:"wing"}],help:"scene/component/star"},mf={ondragmove:function(t,e,n){const{cy:r,ry:i}=n.model;let s=(n.fromParent(t.x,t.y).y-r)/i*100+100;s>=100?s=100:s<=0&&(s=0),n.set({ratio:s})}};class yf extends Ap{is3dish(){return!0}render(t){const{ratio:e=30,wing:n=5,cx:r,cy:i,rx:s,ry:o}=this.state;if(n<3)return;const a=1.5707963267948966,c=2*Math.PI/n,l=s-e/100*s,h=o-e/100*o;t.save(),t.beginPath(),t.translate(r,i),t.moveTo(s*Math.cos(-a),o*Math.sin(-a)),t.lineTo((s-l)*(Math.cos(c-a)+Math.cos(0-a))/2,(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let e=1;e<n;e++)t.lineTo(s*Math.cos(c*e-a),o*Math.sin(c*e-a)),t.lineTo((s-l)*(Math.cos(c*(e+1)-a)+Math.cos(c*e-a))/2,(o-h)*(Math.sin(c*(e+1)-a)+Math.sin(c*e-a))/2);t.closePath(),t.restore()}get controls(){const{cx:t,cy:e,ry:n,ratio:r}=this.state;return[{x:t,y:e-n+n*(r/100),handler:mf}]}get nature(){return gf}}tc.memoize(yf.prototype,"controls",!1),tc.register("star",yf);const bf={mutable:!1,resizable:!1,rotatable:!1,properties:[]};class vf extends(vd(ec)){is3dish(){return!1}isDescendible(){return!1}render(t){const{cx:e,cy:n,anticlockwise:r}=this.state,i=this.app?.scale||1;t.beginPath(),t.scale(1/i,1/i),t.ellipse(e,n,Math.abs(vf.RADIUS),Math.abs(vf.RADIUS),0,0,2*Math.PI,r),t.scale(i,i),t.closePath()}get path(){const{cx:t,cy:e}=this.state;return[{x:t-vf.RADIUS,y:e-vf.RADIUS},{x:t+vf.RADIUS,y:e-vf.RADIUS},{x:t+vf.RADIUS,y:e+vf.RADIUS},{x:t-vf.RADIUS,y:e+vf.RADIUS}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:r}=this.state,i=(t-n)/(2*vf.RADIUS-.5),s=(e-r)/(2*vf.RADIUS-.5);return i*i+s*s<.25}outline(t){const{cx:e,cy:n}=this.state;return this.toScene(e,n)}get nature(){return bf}}function xf(t){return class extends t{animOnValueChange(t,e=!1,n){if(t==this._lastValue)return;let r;r=e?t-(Number(n)||0):t-(this._lastValue||0),this._lastValue=t,this._anim_alpha=-r,this.animate({step:t=>{this._anim_alpha=r*(t-1),this.invalidate()},duration:1e3,delta:"circ",options:{x:1},ease:"out"}).start()}dispose(){super.dispose(),delete this._value_substitutor}onchange(t,e){t.hasOwnProperty("value")&&delete this._value_substitutor}get animAlpha(){return this._anim_alpha||0}get animValue(){return(this._lastValue||0)+(this._anim_alpha||0)}defaultValueSubstitutor(){return this.getState("value")}get valueSubstitutor(){return this._value_substitutor||(this._value_substitutor=Ds(this.getState("value"),this,void 0)||this.defaultValueSubstitutor),this._value_substitutor}get value(){return Number(this.valueSubstitutor())||0}set value(t){delete this._value_substitutor,this.setState("value",Number(mr(t)))}}}function _f(t){return class extends t{_convertDataFormat(t,e){let n;if("json"===e)n=JSON.parse(t);else n=t;return n}isDataSource(){return!0}}}function wf(t){return function(e){return Array.isArray(t)?t.forEach(t=>{tc.register(t,e)}):tc.register(t,e),e}}vf.RADIUS=5,tc.memoize(vf.prototype,"path",!1),tc.register("node",vf);let Mf=0;const Sf=new FinalizationRegistry(()=>{Mf--});class Af{static get residents(){return Mf}static get residentsCount(){return Mf}constructor(t,e){this.counters={},this.references={},this.creator=t,this.disposer=e,Mf++,Sf.register(this,Mf)}dispose(){if(this.disposer)for(const t in this.references)this.disposer(t,this.references[t]);this.references={},this.counters={}}get ids(){return Object.keys(this.references)}create(t){return new Promise((e,n)=>{this.creator?this.creator(t,n=>{n.release=()=>{this.disposer?.(t,n),delete n.release,qr("RELEASED",t)},e(n)},n):n(Error("Reference id("+t+") could not be created. Reference creator should be defined."))})}add(t,e){const n=new Promise((n,r)=>{const i=this.references[t];if(i)i===e?r(Error("Reference ID and target duplicate")):e?r(Error("Reference ID duplicate")):n(i);else{const i=e=>{e.release=()=>{this.release(e)},this.references[t]=e,this.counters[t]=1,n(e)};if(e)i(e);else{if(!this.creator)return void r(Error("Reference id("+t+") is not allowed. Reference creator should be defined."));this.creator(t,i,r)}}});return this.references[t]||(this.references[t]=n),n}async get(t,e=!1){let n=this.references[t];if(n){if(!(n instanceof Promise)){if(!(t in this.counters))throw new Error("No Reference Count");return this.counters[t]++,n}if(e)return n=await n,this.counters[t]++,n}if(e)return await this.add(t);throw new Error("No References for "+t)}_id(t){for(const e in this.references){if(this.references[e]===t)return e}}release(t){const e=this._id(t);if(!e)return void Wr("No Referenced ID");const n=this.references[e];n&&(this.counters[e]--,0==this.counters[e]&&(this.disposer?.(e,n),delete this.references[e],delete this.counters[e],delete t.release,qr("RELEASED",e)))}}const kf={},Ef={};let Cf=[];function Pf(t){const e=t.target,n="SCRIPT"===e.tagName?kf:Ef,r=e.src||e.href;n[r]=!0,Cf.forEach((t,e)=>{if(!t)return;const{resolve:i,scripts:s,styles:o}=t;if(n===kf){const t=s.indexOf(r);t>-1&&t<s.length-1&&Of(s[t+1])}s.some(t=>!kf[t])||o?.some(t=>!Ef[t])||(i(),Cf[e]=null)}),Cf=Cf.filter(Boolean)}function Tf(t){if("string"==typeof t)return;const e=t.target,n=e.src,r="SCRIPT"===e.tagName?kf:Ef;Cf.forEach((e,i)=>{if(!e)return;const{reject:s,scripts:o,styles:a}=e;(r===kf&&o.includes(n)||r===Ef&&!!a?.includes(n))&&(s(t),Cf[i]=null)}),Cf=Cf.filter(Boolean),delete r[n],document.head.removeChild(e)}function Of(t){kf[t]=!1;const e=document.createElement("script");e.onload=Pf,e.onerror=Tf,e.type="text/javascript",e.src=t,document.head.appendChild(e)}class Df{static load(t,e){const n="string"==typeof t?[t]:t,r="string"==typeof e?[e]:e;return new Promise(function(t,e){if(n&&!Array.isArray(n)||r&&!Array.isArray(r))return void e(new Error("invalid sources for load"));let i,s=!0;if(r?.forEach(t=>{t in Ef||function(t){Ef[t]=!1;const e=document.createElement("link");e.onload=Pf,e.onerror=Tf,e.type="text/css",e.rel="stylesheet",e.media="screen,print",e.href=t,document.head.appendChild(e)}(t),Ef[t]||(s=!1)}),n&&n.length>0)for(const t of n)t in kf?kf[t]||(s=!1):i??=t;if(i)Of(i);else if(s)return void t();Cf.push({resolve:t,reject:e,scripts:n,styles:r})})}}const If="0.0.0";class zf extends zh{getObject3dInstance(){return new e.Sprite}build(){super.build(),this.buildMaterial()}get cz(){const{zPos:t=0}=this.component.state,{height:e}=this.component.bounds,{tz:n=0}=this.component.delta();return t+n+e/2}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=zh.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(_h(t)):e.opacity=0)}}function Lf(t){if(!(t>0))return 1;let e=0;if(!(t&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function jf(t){const{lineWidth:n=0}=t.state;let{width:r,height:i}=t.bounds;r+=n,i+=n;const s=Lf(2*r),o=Lf(2*i),a=ph(s,o),c=new e.CanvasTexture(a);return Rf(a,t,2),c.needsUpdate=!0,c.wrapS=e.RepeatWrapping,c.wrapT=e.RepeatWrapping,c.offset.set(0,1-2*i/o),c.repeat.set(2*r/s,2*i/o),c.magFilter=e.NearestFilter,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace,c}function Rf(t,e,n){const{lineWidth:r=0}=e.state;let{left:i,top:s}=e.bounds;i-=r/2,s-=r/2;const o=t.getContext("2d");o.scale(n,n),o.translate(-i,-s),e.render(o),e.postrender(o)}class Ff extends zf{buildMaterial(){const t=this.object3d.material;t&&t.dispose(),this.object3d.material=new e.SpriteMaterial({map:jf(this.component),alphaTest:.01,sizeAttenuation:!1})}get scale(){const{width:t,height:e}=this.component.bounds,n=this.threeContainer,{width:r=1,height:i=1}=n?.bounds??{},{scale:s=1}=this.component.state;return{x:s*t/r,y:s*e/i,z:s}}update(){this.build(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateAlpha(){this.update()}updateText(){this.update()}}class Bf extends zh{get syncZPosOffset(){return this.effectiveDepth}getObject3dInstance(){return new e.Mesh}build(){super.build();const t=Eh(this.component.state.material3d),n=new e.PlaneGeometry(1,1);n.rotateX(-Math.PI/2),this.object3d.geometry=n;const r=jf(this.component);this.object3d.material=new e.MeshStandardMaterial({map:r,transparent:!0,alphaTest:.01,side:e.DoubleSide,metalness:t.metalness,roughness:t.roughness,emissive:new e.Color(t.emissive),emissiveIntensity:t.emissiveIntensity}),this.object3d.castShadow=t.castShadow,this.object3d.receiveShadow=t.receiveShadow}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateDimension(){const{width:t,height:e}=this.component.bounds;this.object3d.scale.set(t,1,e)}update(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateText(){this.update()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Eh(this.component.state.material3d);t.metalness=e.metalness,t.roughness=e.roughness,t.emissive.set(e.emissive),t.emissiveIntensity=e.emissiveIntensity}clear(){return Dh(this.object3d),super.clear()}}class Nf extends zh{getObject3dInstance(){return new e.Mesh}build(){super.build(),this.buildGeometry(),this.buildMaterial()}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=zh.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(_h(t)):e.opacity=0)}updateStrokeStyle(){const t=this.object3d.getObjectByName("__edgeLines__");t&&(this.object3d.remove(t),Dh(t));const{strokeStyle:n}=this.component.state;if(!n||"transparent"===n||"none"===n)return;const r=this.object3d.geometry;if(!r?.getAttribute("position"))return;const i=new e.EdgesGeometry(r),s=new e.LineBasicMaterial({color:n}),o=new e.LineSegments(i,s);o.name="__edgeLines__",this.object3d.add(o)}updateDimension(){const{width:t,height:e}=this.component.bounds,{depth:n=1}=this.component.state;if(!this.object3d)return;this.object3d.geometry.computeBoundingBox();const r=this.object3d.geometry.boundingBox;if(r){const i=r.max.x-r.min.x,s=r.max.y-r.min.y,o=r.max.z-r.min.z;this.object3d.scale.set(t/i,n/s,e/o)}}buildMaterial(){const t=Eh(this.component.state.material3d);this.object3d.material=new e.MeshStandardMaterial({transparent:!0,side:Ph(t.side),metalness:t.metalness,roughness:t.roughness,emissive:new e.Color(t.emissive),emissiveIntensity:t.emissiveIntensity,opacity:t.opacity,envMapIntensity:t.envMapIntensity})}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Eh(this.component.state.material3d);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=Ph(e.side)}clear(){return Dh(this.object3d),super.clear()}}function Yf(t,e,n,r){return[["bold",t],["italic",e],[n+"px",!0],[r,!0]].filter(t=>t[1]).map(t=>t[0]).join(" ")}function Vf(t){let e=0;if(!((t=Math.abs(t)||1)&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function Gf(t,e,n){const{bold:r=!1,italic:i=!1,fontFamily:s="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",width:h=t.width,height:d=t.height}=n||{},u=t.getContext("2d");let p,f;u.imageSmoothingEnabled=!1,u.fillStyle=a,u.strokeStyle=a,u.font=Yf(r,i,o,s),"left"===c||"start"===c?(u.textAlign="left",p=0):"right"===c||"end"===c?(u.textAlign="right",p=h):(u.textAlign="center",p=h/2);const g=1.2*o,m=String(e).split("\n"),y=g*m.length;f="top"===l||"hanging"===l?.1*o:"bottom"===l||"alphabetic"===l?d-y+.1*o:(d-y)/2+.1*o,u.textBaseline="top";for(const t of m)u.fillText(t,p,f),f+=g}function Hf(t,n,r,i){const s=Vf(2*n),o=Vf(2*r),a=ph(s,o),c=a.getContext("2d"),{fillStyle:l}=i||{};if(l&&"object"==typeof l&&l.colorStops?.length){const t=function(t,e,n){const r=document.createElement("canvas");r.width=e,r.height=n;const i=r.getContext("2d");if(!i)return null;let s;if("radial"===t.gradientType){const r=e/2,o=n/2,a=Math.max(e,n)/2;switch(t.center){case"left-top":s=i.createRadialGradient(0,0,0,0,0,2*a);break;case"right-top":s=i.createRadialGradient(e,0,0,e,0,2*a);break;case"left-bottom":s=i.createRadialGradient(0,n,0,0,n,2*a);break;case"right-bottom":s=i.createRadialGradient(e,n,0,e,n,2*a);break;default:s=i.createRadialGradient(r,o,0,r,o,a)}}else{const r=t.rotation??0,o=e/2,a=n/2,c=Math.cos(r)*o,l=Math.sin(r)*a;s=i.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 i.fillStyle=s,i.fillRect(0,0,e,n),r}(l,2*n,2*r);t&&c.drawImage(t,0,0)}c.scale(2,2),"string"==typeof l&&""!==l&&"transparent"!==l&&(c.fillStyle=l,c.fillRect(0,0,n,r)),Gf(a,t,i);const h=new e.CanvasTexture(a);return h.needsUpdate=!0,h.wrapS=e.RepeatWrapping,h.wrapT=e.RepeatWrapping,h.offset.set(0,1-2*r/o),h.repeat.set(2*n/s,2*r/o),h.minFilter=e.LinearFilter,h.colorSpace=e.SRGBColorSpace,h}function Uf(t,n,r,i,s,o,a){const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const t=2*r,l=2*i,h=Vf(t),d=Vf(l),u=ph(h,d),p=u.getContext("2d");if(o.color&&(p.fillStyle=o.color,p.fillRect(0,0,t,l)),o.fitPattern)p.drawImage(c,0,0,t,l);else{const e=2*(o.width||c.naturalWidth),n=2*(o.height||c.naturalHeight),r=2*(o.offsetX||0),i=2*(o.offsetY||0);let s=0,a=0;switch(o.align){case"center":s=(t-e)/2,a=(l-n)/2;break;case"left-top":break;case"left-bottom":a=l-n;break;case"right-top":s=t-e;break;case"right-bottom":s=t-e,a=l-n;break;case"left":a=(l-n)/2;break;case"right":s=t-e,a=(l-n)/2;break;case"top":s=(t-e)/2;break;case"bottom":s=(t-e)/2,a=l-n}const h=r+s,d=i+a;if(o.noRepeat)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,h,d,e,n);else{p.save(),p.rect(0,0,t,l),p.clip();const r=h>0?h-Math.ceil(h/e)*e:h;for(let i=d>0?d-Math.ceil(d/n)*n:d;i<l;i+=n)for(let s=r;s<t;s+=e)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,s,i,e,n);p.restore()}}n&&(p.scale(2,2),Gf(u,n,s));const f=new e.CanvasTexture(u);f.needsUpdate=!0,f.wrapS=e.RepeatWrapping,f.wrapT=e.RepeatWrapping,f.offset.set(0,1-l/d),f.repeat.set(t/h,l/d),f.minFilter=e.LinearFilter,f.colorSpace=e.SRGBColorSpace,a(f)},c.onerror=()=>{const t=Hf(n,r,i,s);a(t)},c.src=t}function Wf(t,e){let{bold:n=!1,italic:r=!1,fontFamily:i="Serif",fontSize:s=10,lineHeight:o="normal"}=e||{};t=void 0===t||""==t?" ":String(t);const a=document.createElement("span");a.style.font=Yf(n,r,s,i),a.style.lineHeight=String(o),a.style.whiteSpace="pre",a.style.position="absolute",a.textContent=t,document.body.appendChild(a);const c=a.getBoundingClientRect();return document.body.removeChild(a),{width:c.width,height:c.height}}class Xf extends Nf{get syncZPosOffset(){return this.effectiveDepth}buildGeometry(){this.updateDimension()}updateStrokeStyle(){}updateFillStyle(){this.updateText()}updateDimension(){const{width:t,height:n}=this.component.state,r=Math.abs(t)||1,i=Math.abs(n)||1;this.object3d.geometry&&this.object3d.geometry.dispose();const s=new e.PlaneGeometry(r,i);s.rotateX(-Math.PI/2),this.object3d.geometry=s}updateText(){const t=this.object3d.material;if(!t)return;const{width:e,height:n,bold:r=!1,italic:i=!1,fontFamily:s="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",fillStyle:h}=this.component.state,d=Math.abs(e)||1,u=Math.abs(n)||1,p=this.component.text,f=h&&"none"!==h?h:"transparent",g={bold:r,italic:i,fontFamily:s,fontSize:o,fontColor:a,textAlign:c,textBaseline:l,width:d,height:u,fillStyle:f};if("object"==typeof f&&"pattern"===f?.type&&f.image){return void Uf(this.component.app.url(h.image),p,d,u,g,h,e=>{t.map&&t.map.dispose(),t.map=e,t.color.set(16777215),t.needsUpdate=!0})}const m=Hf(p,d,u,g);m?(t.map&&t.map.dispose(),t.map=m,t.color.set(16777215),m.needsUpdate=!0):"string"==typeof h&&(""!==h&&"transparent"!==h?t.color.set(_h(h)):t.opacity=0)}updateAlpha(){const{alpha:t=1}=this.component.state,e=this.object3d.material;e.opacity=t,e.transparent=!0}}Fh("text",t=>new Xf(t));class qf extends zh{get syncZPosOffset(){return this.effectiveDepth}getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds;if(!t||!n)return;const r=Eh(this.component.state.material3d),i=new e.PlaneGeometry(1,1);i.rotateX(-Math.PI/2),this.object3d.geometry=i;const s=jf(this.component);this.object3d.material=new e.MeshStandardMaterial({map:s,transparent:!0,side:e.DoubleSide,metalness:r.metalness,roughness:r.roughness,emissive:new e.Color(r.emissive),emissiveIntensity:r.emissiveIntensity}),this.object3d.castShadow=r.castShadow,this.object3d.receiveShadow=r.receiveShadow}updateDimension(){const{width:t,height:e}=this.component.bounds;this.object3d.scale.set(t,1,e)}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this._rebuildTexture()},100)}_rebuildTexture(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Eh(this.component.state.material3d);t.metalness=e.metalness,t.roughness=e.roughness,t.emissive.set(e.emissive),t.emissiveIntensity=e.emissiveIntensity}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),Dh(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),super.dispose()}}const Kf={input:"css3d",select:"css3d",textarea:"css3d",button:"css3d",iframe:"css3d",video:"css3d",label:"texture",table:"texture",progress:"texture"};function $f(t){const e=function(t){const e=t.state?.material3d?.renderMode;if("css3d"===e||"texture"===e)return e;const n=t.model?.type??"";return Kf[n]??"css3d"}(t);return"texture"===e?new qf(t):new Lh(t)}Fh("html-overlay-element",$f),Fh("html-overlay-container",$f);class Qf{setShape({extrudedShape:t,extrudedOptions:n}){this.extrudedShape=t,this.bb=new e.Box2,this.bb.setFromPoints(this.extrudedShape?.extractPoints(0).shape),this.extrudedOptions=n}generateTopUV(t,n,r,i,s){const o=n[3*r],a=n[3*r+1],c=n[3*i],l=n[3*i+1],h=n[3*s],d=n[3*s+1],u=this.bb,p=u.max.x-u.min.x,f=u.max.y-u.min.y;return[new e.Vector2((o-u.min.x)/p,1-(a-u.min.y)/f),new e.Vector2((c-u.min.x)/p,1-(l-u.min.y)/f),new e.Vector2((h-u.min.x)/p,1-(d-u.min.y)/f)]}generateSideWallUV(t,n,r,i,s,o){const a=n[3*r],c=n[3*r+1],l=n[3*r+2],h=n[3*i],d=n[3*i+1],u=n[3*i+2],p=n[3*s],f=n[3*s+1],g=n[3*s+2],m=n[3*o],y=n[3*o+1],b=n[3*o+2],v=this.extrudedOptions?.depth||100,x=this.bb,_=x.max.x-x.min.x,w=x.max.y-x.min.y;return Math.abs(c-d)<.01?[new e.Vector2(a/_,1-l/v),new e.Vector2(h/_,1-u/v),new e.Vector2(p/_,1-g/v),new e.Vector2(m/_,1-b/v)]:[new e.Vector2(c/w,1-l/v),new e.Vector2(d/w,1-u/v),new e.Vector2(f/w,1-g/v),new e.Vector2(y/w,1-b/v)]}}class Zf extends zh{clear(){return this._mesh=void 0,super.clear()}get shape(){return null}get boundUVGenerator(){return this._boundUVGenerator||(this._boundUVGenerator=new Qf),this._boundUVGenerator}build(){super.build();const t=this.effectiveDepth,n=this.shape;if(!n)return;const r=this.boundUVGenerator;r&&r.setShape({extrudedShape:n,extrudedOptions:{depth:t}});const i=this.createGeometry(n),s=this.createMaterials();this._mesh=new e.Mesh(i,s),this._mesh.rotation.x=-Math.PI/2,this._mesh.rotation.y=-Math.PI,this._mesh.rotation.z=-Math.PI,this._mesh.castShadow=!0,this.object3d.add(this._mesh),this.updateFillStyle(),this.updateStrokeStyle()}createGeometry(t){const n=this.effectiveDepth,{lineWidth:r=0}=this.component.state,i={steps:1,depth:n,bevelEnabled:r>0,bevelThickness:0,bevelSize:r,bevelSegments:1,UVGenerator:this.boundUVGenerator},s=new e.ExtrudeGeometry(t,i);return s.center(),s}createMaterials(){const t=Eh(this.component.state.material3d),n={metalness:t.metalness,roughness:t.roughness,emissive:new e.Color(t.emissive),emissiveIntensity:t.emissiveIntensity,opacity:t.opacity,transparent:t.opacity<1,envMapIntensity:t.envMapIntensity,side:Ph(t.side)};return[new e.MeshStandardMaterial(n),new e.MeshStandardMaterial(n)]}createTexture(){function t(t){let e=0;if(t&&!(t&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}const{width:n,height:r}=this.component.bounds,i=t(n),s=t(r),o=ph(i,s);this.component.render(o.getContext("2d"));const a=new e.CanvasTexture(o);return a.needsUpdate=!0,a.wrapS=e.RepeatWrapping,a.wrapT=e.RepeatWrapping,a.offset.set(0,1-r/s),a.repeat.set(n/i,r/s),a.minFilter=e.LinearFilter,a}getMaterials(){if(!this._mesh)return;const t=this._mesh.material;return Array.isArray(t)?t:void 0}updateMaterial3d(){super.updateMaterial3d();const t=Eh(this.component.state.material3d),e=Ph(t.side),n=this.getMaterials();if(n)for(const r of n)r.metalness=t.metalness,r.roughness=t.roughness,r.emissive.set(t.emissive),r.emissiveIntensity=t.emissiveIntensity,r.opacity=t.opacity,r.transparent=t.opacity<1,r.envMapIntensity=t.envMapIntensity,r.side=e}updateAlpha(){const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,r=this.getMaterials();r&&(xh(r[0],t,e),xh(r[1],t,n))}updateStrokeStyle(){const t=this.getMaterials();if(!t)return;const{strokeStyle:e}=this.component.state;t[1].color.set(_h(e))}updateFillStyle(){this._applyCapTexture()}updateText(){this._applyCapTexture()}_applyCapTexture(){const t=this.getMaterials();if(!t)return;const e=t[0],{fillStyle:n}=this.component.state,r=this.component.hasTextProperty?this.component.text:"";if(!r){const t=zh.buildFillStyleTexture(this.component);return t?(e.map&&e.map.dispose(),e.map=t,e.color.set(16777215)):(e.map&&(e.map.dispose(),e.map=null),e.color.set(_h(n))),void(e.needsUpdate=!0)}const{width:i,height:s,bold:o=!1,italic:a=!1,fontFamily:c="Serif",fontSize:l=10,fontColor:h="black",textAlign:d="center",textBaseline:u="middle"}=this.component.state,p=Math.abs(i)||1,f=Math.abs(s)||1,g={bold:o,italic:a,fontFamily:c,fontSize:l,fontColor:h,textAlign:d,textBaseline:u,width:p,height:f,fillStyle:n};if("object"==typeof n&&"pattern"===n?.type&&n.image){return void Uf(this.component.app.url(n.image),r,p,f,g,n,t=>{e.map&&e.map.dispose(),e.map=t,e.color.set(16777215),e.needsUpdate=!0})}e.map&&e.map.dispose();const m=Hf(r,p,f,g);e.map=m,e.color.set(16777215),e.needsUpdate=!0}updateDimension(){super.updateDimension()}}class Jf extends Zf{get shape(){const{cx:t=0,cy:n=0,rx:r=1,ry:i=1,startAngle:s=0,endAngle:o=2*Math.PI,anticlockwise:a=!1}=this.component.state,c=new e.EllipseCurve(t,n,Math.abs(r),Math.abs(i),s,o,a,0);return new e.Shape(c.getPoints(50))}}Fh("ellipse",t=>new Jf(t));class tg extends Zf{get shape(){const{width:t,height:n,round:r}=this.component.state,i=new e.Shape;if(r>0){const e=r/100*(t/2);i.moveTo(e,0),i.lineTo(t-e,0),i.quadraticCurveTo(t,0,t,e),i.lineTo(t,n-e),i.quadraticCurveTo(t,n,t-e,n),i.lineTo(e,n),i.quadraticCurveTo(0,n,0,n-e),i.lineTo(0,e),i.quadraticCurveTo(0,0,e,0)}else i.moveTo(0,0),i.lineTo(t,0),i.lineTo(t,n),i.lineTo(0,n),i.lineTo(0,0);return i}}Fh("rect",t=>new tg(t));class eg extends Zf{get shape(){const{path:t=[],round:n=0}=this.component.state,r=new e.Shape;for(let e=0;e<t.length;e++){const i=t[(e-1+t.length)%t.length],s=t[(e+t.length)%t.length],o=t[(e+1)%t.length];if(i.x===s.x&&i.y===s.y)continue;let a=Math.sqrt((i.x-s.x)*(i.x-s.x)+(i.y-s.y)*(i.y-s.y)),c=0!==a?Math.atan2(i.x-s.x,i.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==e?r.moveTo(d.x,d.y):r.lineTo(d.x,d.y),n>0&&r.quadraticCurveTo(s.x,s.y,u.x,u.y)}return r}get minMax(){if(!this._minMax){const{path:t}=this.component.state;let e,n,r,i;t.forEach((t,s)=>{if(0==s)return e=r=t.x,void(n=i=t.y);e=Math.min(e,t.x),r=Math.max(r,t.x),n=Math.min(n,t.y),i=Math.max(i,t.y)}),this._minMax={minX:e,minY:n,maxX:r,maxY:i}}return this._minMax}}Fh("polygon",t=>new eg(t));class ng extends Zf{get shape(){const{cx:t=0,cy:n=0,rx:r=1,ry:i=1,ratio:s=50,startAngle:o=0,endAngle:a=2*Math.PI,anticlockwise:c=!1}=this.component.state,l=Math.abs(r),h=Math.abs(i),d=new e.EllipseCurve(t,n,l,h,o,a,c,0),u=new e.Shape(d.getPoints(50)),p=l/100*s,f=h/100*s;if(p>0&&f>0){const r=new e.EllipseCurve(t,n,p,f,o,a,c,0),i=new e.Path(r.getPoints(50));u.holes.push(i)}return u}}Fh("donut",t=>new ng(t));class rg extends Zf{get shape(){const{x1:t=0,y1:n=0,x2:r=0,y2:i=0,x3:s=0,y3:o=0}=this.component.state,a=new e.Shape;return a.moveTo(t,n),a.lineTo(r,i),a.lineTo(s,o),a.closePath(),a}}Fh("triangle",t=>new rg(t));class ig extends Zf{get shape(){const{ratio:t=30,wing:n=5,cx:r=0,cy:i=0,rx:s=1,ry:o=1}=this.component.state;if(n<3)return null;const a=Math.PI/2,c=2*Math.PI/n,l=s-t/100*s,h=o-t/100*o,d=new e.Shape;d.moveTo(r+s*Math.cos(-a),i+o*Math.sin(-a)),d.lineTo(r+(s-l)*(Math.cos(c-a)+Math.cos(0-a))/2,i+(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let t=1;t<n;t++)d.lineTo(r+s*Math.cos(c*t-a),i+o*Math.sin(c*t-a)),d.lineTo(r+(s-l)*(Math.cos(c*(t+1)-a)+Math.cos(c*t-a))/2,i+(o-h)*(Math.sin(c*(t+1)-a)+Math.sin(c*t-a))/2);return d.closePath(),d}}Fh("star",t=>new ig(t));const sg={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/sphere"};class og extends Nf{buildGeometry(){const{rx:t=0,ry:n=0,rz:r}=this.component.state,i=r??t,s=new e.SphereGeometry(1,32,16);s.scale(t,i,n),this.object3d.geometry=s}updateDimension(){this.buildGeometry()}}let ag=class extends Ap{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new og(this)}get nature(){return sg}};ag=tp([wf("sphere")],ag);const cg={mutable:!1,resizable:!0,rotatable:!0,properties:[]};let lg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Ff(this)}get nature(){return cg}};lg=tp([wf("sprite")],lg);const hg={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cube"};class dg extends Nf{buildGeometry(){const{width:t=0,height:n=0,depth:r=0}=this.component.state,i=new e.BoxGeometry(1,1,1);i.scale(t,r,n),this.object3d.geometry=i}}let ug=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new dg(this)}get nature(){return hg}};ug=tp([wf("cube")],ug);const pg={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cylinder"};class fg extends Nf{buildGeometry(){const{rx:t=0,ry:n=0}=this.component.state,r=this.component.state.depth??1,i=new e.CylinderGeometry(1,1,1,25);i.scale(t||1,r||1,n||1),this.object3d.geometry=i}updateDimension(){this.buildGeometry()}}let gg=class extends Ap{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new fg(this)}get nature(){return pg}};gg=tp([wf("cylinder")],gg);const mg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"color",label:"box-color",name:"boxColor",property:"boxColor"}],help:"scene/component/banner"};class yg extends zh{build(){super.build();const{width:t=1,height:e=1,depth:n=1}=this.component.state;this.object3d.add(this.createCube(t,e,n));const r=this.createTextureBoard(t,n);r.position.set(0,0,.5*e+1),this.object3d.add(r)}createCube(t,n,r){const{boxColor:i="#ccaa76"}=this.component.state,s=Eh(this.component.state.material3d),o=new e.BoxGeometry(t,r,n),a=new e.MeshStandardMaterial({color:i,side:e.FrontSide,metalness:s.metalness,roughness:s.roughness,emissive:new e.Color(s.emissive),emissiveIntensity:s.emissiveIntensity}),c=new e.Mesh(o,a);return c.castShadow=s.castShadow,c.receiveShadow=s.receiveShadow,c}createTextureBoard(t,n){let r;const i=Eh(this.component.state.material3d),{fillStyle:s="#ccaa76"}=this.component.state,o=zh.buildFillStyleTexture(this.component);r=o?new e.MeshStandardMaterial({map:o,metalness:i.metalness,roughness:i.roughness,emissive:new e.Color(i.emissive),emissiveIntensity:i.emissiveIntensity}):new e.MeshStandardMaterial({color:s||"#ccaa76",side:e.FrontSide,metalness:i.metalness,roughness:i.roughness,emissive:new e.Color(i.emissive),emissiveIntensity:i.emissiveIntensity});const a=new e.PlaneGeometry(t,n,1,1),c=new e.Mesh(a,r);return c.castShadow=i.castShadow,c.receiveShadow=i.receiveShadow,c}updateMaterial3d(){super.updateMaterial3d();const t=Eh(this.component.state.material3d);this.object3d.traverse(e=>{if(e.isMesh){const n=e.material;n&&(n.metalness=t.metalness,n.roughness=t.roughness,n.emissive.set(t.emissive),n.emissiveIntensity=t.emissiveIntensity),e.castShadow=t.castShadow,e.receiveShadow=t.receiveShadow}})}}let bg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return mg}buildRealObject(){return new yg(this)}};var vg;bg=tp([wf("banner")],bg);const xg={far:1e5,fov:80,near:1,zoom:1},_g={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"near",name:"near"},{type:"number",label:"far",name:"far"},{type:"number",label:"fov",name:"fov"},{type:"number",label:"zoom",name:"zoom"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/camera"};class wg extends zh{getObject3dInstance(){return new e.Mesh}updateCamera(){const{near:t=xg.near,far:n=xg.far,fov:r=xg.fov,zoom:i=xg.zoom,showHelper:s}=this.component.state;this.camera.far=n,this.camera.fov=r,this.camera.near=t,this.camera.zoom=i,s?this.helper||(this.helper=new e.CameraHelper(this.camera),this.object3d.add(this.helper)):this.helper&&(this.object3d.remove(this.helper),delete this.helper)}build(){super.build();const{width:t=0,height:n=0,depth:r=0,fillStyle:i="lightgray"}=this.component.state;this.object3d.geometry=new e.BoxGeometry(t,r,n),this.object3d.material=new e.MeshStandardMaterial({color:i,side:e.FrontSide}),this.camera=new e.PerspectiveCamera,this.camera.position.set(0,0,0),this.object3d.add(this.camera),this.object3d.lookAt(0,0,0),this.updateCamera()}}let Mg=vg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}static get image(){return vg._image||(vg._image=new Image,vg._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1IAAANSAQMAAABV6G1EAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAABlBMVEX6+voBAQGV71ZvAAAFO0lEQVR42u3dMZLkNBiGYakUKFRIqKOISxDvETiCTBEQcgQOQE7clyAi8REm7KDXIhgYoMa/7fbIX+2K9w022MCP/25Z28GW5RwRERERERERERERERERERERERERERERERERERERERERERERERHRl9mv7fdPn7879sf8Mcq3J3r5EJXaUy3Wddrcd6qNybx9F2/lZ63H+nVCa9Oe9elZa5ksa/dDbE+3fsm4v27C89bd+i6W3l+XdcnSWtuxyvPW+hqorbWb0Jr7Pl3m4tjfVMIZ625d6L5pxTPWw7rQY9P6pqu1dF8aq5d83cE3rXrGWluIxV6h53eotv4c1V3Ln7Nm66ZvvZf8SSues16sD2jubz2sC839fmvYiz7t//LJna27wsr7VjlnNWtPeHTfNlae2bZvnaTePUd+74fqV2LNxv6zdN8O3z9HSWhlc4F+dOvdsKbe2+F7q+zPddq6W2ts6r31vrN825/rtPWwvvcL5losy11uxQNz5U6fYT4w12mrWf80TUNZdetXal/LtwNW6WOFI1Y9bU3GVnfFXM9bneZKwrmKcK4qnKsK52q6uULTzRWFVjpkta/OykKrCq02puWFVhRaSWjlQa0itJrO8oNaQWgloZWFVhnUqjrLN50VBrWi0MpCqwitOqjVdFYQWlFopUGtLLSq0GpjWl5oRaGVBrWy0KpCq+ksP6gVhFYSWllolUGtqrNW/jvBZVYY1IpCKwutIrTqoFbTWUFoxUGtJLSK0KpCq41peaEVhVYa1MpCqwqtprP8oFYUWklo5UGtIrSazvJCKwxqRaGVhVYZ1Ko664ems34UWj8Nav0stBoWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhbW/9L6RWgp37WofIek8j2cyveLTkqrCq0itLLQSkJL+Q5k5budle/HVr73e/24gAHenZ6FlvK9+srzAoLQUp65oDy3QnoeRxFaWWgpz2pRnncThJbyzCDpuUtVaBWhlYWW8qwx5RlqynPovNBSnuUnPaOwCK0stJLQUp4BqjzbVHk+rFNaVWgVoZWFlvJc6Si0lGdzK88cV57bLj2PvgitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqxyyahcrH7JKFysJ54rCuYJwLi+cywnn+vdlLp+rCOfKwrnStXP95zLxiJX7WEFoeaHljO/xEqsaf9/FWqz1bM+VzloP655df2uxrnP9XPHKue7OeMDsuWInyx+Y67T1Yv0gs+cKvay6P5fvZZULrdnYFBbbcr2sdKF1MxbZFdZkLLItq3aay6/vJ102eusD2rJKl633nw/o3n+uxbrpLSv1svL6M95hQ3xYNz33t16sC21Zoc+28Xahm+u+Ic7WhbYs1+dRfrvQ5LpvHOaFNq3SZ8n/faEt6twDtli7wrJpxT6P1183/di0Ti36u3XT903Ld1qGrzf9smmdWhyTddNzf8t8UqdtK/dZGq8P2DZ1ZnHcrQ/osWO5PkvDuby7NE58Yctk7Qq3PSv3+bpc3F0aJ56wF+uLX9xu6eOb4es9z/vWc0vR3oZuByjnf2t/fP/54B/2WvvWEREREREREREREREREREREREREREREREREREREREREREREREREX2J/QlrTpqHD8xO1gAAAABJRU5ErkJggg=="),vg._image}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),this.drawImage(t,vg.image,e,n,r,i)}buildRealObject(){return new wg(this)}get nature(){return _g}};Mg=vg=tp([wf("camera")],Mg);const Sg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"gltf-selector",label:"url",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:"$base_url",defaultStorage:"3d-model",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0,category:"application"},observe:function(t){this.parentNode.querySelector("[name=gltfInfo]").src=t;const e=this.parentNode.querySelector("[name=fillStyleTargets]");e&&(e.src=t)}},{type:"gltf-info",label:"",name:"gltfInfo",readonly:!0,property:{action:(t,e)=>{t.set(e)}},editor:{fullwidth:!0}},{type:"gltf-fill-targets",label:"fill-targets",name:"fillStyleTargets",editor:{fullwidth:!0}}],"value-property":"source",help:"scene/component/gltf-object"};let Ag=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}get controls(){return[]}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath();const s=this._topViewSnapshot;if(s)t.drawImage(s,e,n,r,i);else{t.rect(e,n,r,i),t.fillStyle="#f0f0f0",t.fill(),t.strokeStyle="#999",t.lineWidth=1,t.stroke();const s=this.getState("src"),o=s&&s.split("/").pop()?.replace(/\.[^.]+$/,"")||"GLTF",a=Math.max(10,.12*Math.min(r,i));t.fillStyle="#666",t.font=`${a}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(o,e+r/2,n+i/2,.9*r)}}async ready(){await super.ready(),this._ensureTopViewSnapshot()}onchange(t,e){super.onchange(t,e),"src"in t&&(this._topViewSnapshot=void 0,this._ensureTopViewSnapshot())}_ensureTopViewSnapshot(){const t=this.getState("src");if(!t)return;const e=qu.getTopViewCache(t);if(e)return this._topViewSnapshot=e,void this.invalidate();const n=this.app.url(t);qu.loadGLTF(n).then(e=>{if(this.getState("src")!==t)return;const n=qu.getTopViewCache(t);if(n)return this._topViewSnapshot=n,void this.invalidate();const r=qu.renderTopView(e.scene);qu.setTopViewCache(t,r),this._topViewSnapshot=r,this.invalidate()})}buildRealObject(){return new qu(this)}get nature(){return Sg}get source(){return this.getState("src")}set source(t){this.setState("src",t)}set dimension(t){const{width:e=1,height:n=1,depth:r=1}=t;this.setState({width:e,height:n,depth:r}),this.realObject?.updateDimension()}get nodes(){return this.getState("nodes")}set nodes(t){this.setState("nodes",t)}get animations(){return this.getState("animations")}set animations(t){this.setState("animations",t)}get autoPlay(){return!1!==this.getState("autoPlay")}set autoPlay(t){this.setState("autoPlay",t)}get fillStyleTargets(){return this.getState("fillStyleTargets")}set fillStyleTargets(t){this.setState("fillStyleTargets",t)}get nodeNames(){const t=this.realObject;return t?.nodeNames??[]}get animationNames(){const t=this.realObject;return t?.animationNames??[]}};Ag=tp([wf("gltf-object")],Ag);const kg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"light-type",name:"lightType",property:{options:["","point","directional"]}},{type:"number",label:"intensity",name:"intensity"},{type:"number",label:"distance",name:"distance"},{type:"number",label:"decay",name:"decay"},{type:"checkbox",label:"cast-shadow",name:"castShadow"},{type:"number",label:"near",name:"near",placeholder:"0.5"},{type:"number",label:"far",name:"far",placeholder:"1000"},{type:"number",label:"fov",name:"fov",placeholder:"90"},{type:"number",label:"zoom",name:"zoom",placeholder:"1"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/light"};class Eg extends zh{updatePointLight(){const{lightType:t="point",distance:n=0,intensity:r=10,decay:i=1,fillStyle:s="white",castShadow:o,near:a=.5,far:c=1e3,fov:l=90,zoom:h=1,showHelper:d}=this.component.state;if(this.object3d.color=new e.Color(s),"point"==t&&(this.object3d.distance=n,this.object3d.decay=i),this.object3d.intensity=r,this.object3d.castShadow=o,o){const t=this.object3d.shadow?.camera;t.far=c,t.near=a,t.fov=l,t.zoom=h}if(d){const t=this.object3d.shadow?.camera;this.helper||(this.helper=new e.CameraHelper(t),this.object3d.add(this.helper))}else this.helper&&(this.object3d.remove(this.helper),delete this.helper)}getObject3dInstance(){const{lightType:t="point"}=this.component.state;return"point"==t?new e.PointLight:new e.DirectionalLight}update(){this.clear(),this.build(),this.updateDimension(),this.updateHidden(),this.updatePointLight()}}let Cg=class extends Ap{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Eg(this)}get anchors(){return[]}get nature(){return kg}};Cg=tp([wf("light")],Cg);const Pg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"}],help:"scene/component/wall"};class Tg extends Nf{buildGeometry(){const{width:t=0,height:n=0,depth:r=0}=this.component.state,i=new e.BoxGeometry(1,1,1);i.scale(t,r,n),this.object3d.geometry=i}}let Og=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Tg(this)}get nature(){return Pg}};Og=tp([wf("wall")],Og);class Dg extends zh{build(){super.build()}update(){}}const Ig={far:1e5,fov:80,near:1,zoom:1};class zg extends zh{build(){super.build()}update(){super.update(),this.updateCamera()}getObject3dInstance(){return new e.PerspectiveCamera}updateCamera(){const{near:t=Ig.near,far:e=Ig.far,fov:n=Ig.fov,zoom:r=Ig.zoom}=this.component.state;this.object3d.far=e,this.object3d.fov=n,this.object3d.near=t,this.object3d.zoom=r}}class Lg extends zh{getObject3dInstance(){return new e.Group}}class jg extends Nf{buildGeometry(){const{width:t,height:n}=this.component.state.dimension;this.object3d.geometry=new e.PlaneGeometry(t,n)}buildMaterial(){this.object3d.material=new e.MeshStandardMaterial({opacity:0,side:e.DoubleSide,blending:e.NoBlending})}}class Rg extends zh{getObject3dInstance(){return new e.Scene}dispose(){for(const t of this.object3d.children)Dh(t);this._animationMixer&&(this._animationMixer.stopAllAction(),this._animationMixer.uncacheRoot(this.object3d),this._animationMixer=void 0),super.dispose()}clear(){return this._floor&&(this.object3d.remove(this._floor),this._floor.material instanceof Array?this._floor.material.forEach(t=>t.dispose()):this._floor.material.dispose(),this._floor.geometry.dispose(),delete this._floor),super.clear()}get floor(){return this._floor}set floor(t){this._floor&&(this.object3d.remove(this._floor),this._floor.clear(),delete this._floor),t&&(this._floor=t,this.object3d.add(t)),this.component.invalidate()}build(){super.build(),this.floor=Gh(this.component)}updateTransform(){}updateDimension(){}updatePosition(){}updateRotate(){}updateScale(){}updateAlpha(){}updateHidden(){}get animationMixer(){return this._animationMixer||(this._animationMixer=new e.AnimationMixer(this.object3d)),this._animationMixer}}const Fg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"precision",name:"precision",property:{options:[{display:"High",value:"highp"},{display:"Medium",value:"mediump"},{display:"Low",value:"lowp"}]}},{type:"checkbox",label:"anti-alias",name:"antialias",property:"antialias"},{type:"checkbox",label:"3dmode",name:"threed",property:"threed"},{type:"checkbox",label:"auto-rotate",name:"autoRotate",property:"autoRotate"},{type:"checkbox",label:"debug",name:"debug",property:"debug"}],help:"scene/component/three-container"};let Bg=class extends lp{constructor(){super(...arguments),this._capability=new od}get sceneManager(){return this._capability.sceneManager}get cameraManager(){return this._capability.cameraManager}get rendererManager(){return this._capability.rendererManager}get lightManager(){return this._capability.lightManager}get controlsManager(){return this._capability.controlsManager}get eventManager(){return this._capability.eventManager}containable(t){return!0}is3dContainer(){return!0}getLightingConfig(){return{hemisphere:{skyColor:14540253,groundColor:3355443,intensity:.035}}}getCss3DSceneAttribute(){return"three-container:css3d-renderer"}init_scene3d(){this._capability.isInitialized&&this._capability.destroy(),this._capability.init(this,{lightingConfig:this.getLightingConfig(),css3DSceneAttribute:this.getCss3DSceneAttribute()}),this._capability.buildOverlays(),this._capability.resize(),this.onchangeData&&this.onchangeData(this.data,this.data)}destroy_scene3d(){this.stop(),this._capability.destroy()}stop(){}resize(){this._capability.resize()}get scene3d(){return this._capability.isInitialized||this.init_scene3d(),this._capability.scene3d}get renderer3d(){return this._capability.renderer3d}get mixer(){return this._capability.mixer}get css3DScene(){return this._capability.css3DScene}get css3DRenderer(){return this._capability.css3DRenderer}render_threed(){this._capability.renderThreeD()}get _parentIs3dMode(){return!!this.rootModel?.is3dMode}render(t){this._parentIs3dMode||(this.app.isViewMode&&this.setState("threed",!0),!this.state.threed||this._capability.noSupportWebgl?super.render(t):this._capability.camera&&this._capability.renderCSS3D())}postrender(t){if(this._parentIs3dMode)return;const{left:e,top:n,debug:r,threed:i}=this.state;let{width:s,height:o}=this.bounds;if(s=Math.floor(s),o=Math.floor(o),i){if(this._capability.isInitialized||this.init_scene3d(),this._capability.noSupportWebgl)return void this._capability.showWebglNoSupportText(t,this.state.width,this.state.height);if(!this._capability.renderer3d)return;this._capability.renderThreeD();const i=this._capability.domElement;t.drawImage(i,0,0,i.width,i.height,e,n,s,o),r&&this._capability.showDebugFPS(t)}else super.postrender(t)}dispose(){this._capability.dispose(),super.dispose()}get layout(){return lc.get("three")}get nature(){return Fg}getObjectByRaycast(){return this._capability.getObjectByRaycast()}getObjectsByRaycast(){return this._capability.getObjectsByRaycast()}onchange(t,e){(t.hasOwnProperty("width")||t.hasOwnProperty("height"))&&this._capability.destroy(),this._capability.onchange(t)}onmousedown(t){this._capability.onMouseDown(t)}onmouseup(t){this._capability.onMouseUp(t)}onmousemove(t){this._capability.onMouseMove(t)}onmouseleave(t){this._capability.onMouseLeave(t)}onwheel(t){this._capability.onWheel(t)&&this.invalidate()}ondblclick(t){this._capability.onDblClick(t)&&this.invalidate()}ondragstart(t){this._capability.onDragStart(t)}ondragmove(t){this._capability.onDragMove(t)&&this.invalidate()}ondragend(t){this._capability.onDragEnd(t)&&this.invalidate()}ontouchstart(t){this._capability.onTouchStart(t)}onpan(t){this._capability.onPan(t)&&this.invalidate()}ontouchend(t){this._capability.onTouchEnd(t)}onkeydown(t){this._capability.onKeyDown(t)}onpinch(t){this._capability.onPinch(t)&&this.invalidate()}ondoubletap(){this._capability.onDoubleTap(),this.invalidate()}};var Ng;Bg=tp([wf("3d-container")],Bg),Bh(t=>{const e=t.state.material3d?.spriteMode;return"plane"===e?new Bf(t):new Ff(t)}),function(t){t.compile=pl,t.duplicate=fl,t.select=Ea,t.match=Sa}(Ng||(Ng={})),Or.registerResidents(()=>({componentResidentsCount:tc.residentsCount,sceneResidentsCount:Qu.residentsCount,referenceMapResidentsCount:Af.residentsCount,sceneResidents:tc.residents}));var Yg=Object.freeze({__proto__:null,AbsoluteLayout:dc,Animation:ta,AudioPlayer:$p,get Banner(){return bg},Banner3D:yg,BoxSelectionManager:sd,get Camera(){return Mg},Camera3D:wg,CameraBookmarkManager:id,CameraManager:Wh,CardLayout:pc,Component:tc,Connectable:vd,Container:lp,ContainerAbstract:Tc,ControlsManager:$h,get Cube(){return ug},Cube3D:dg,get Cylinder(){return gg},Cylinder3D:fg,DEFAULT:Ni,DPPX:Ri,DataSource:_f,Donut:ff,DonutExtrude:ng,Ellipse:Ap,EllipseExtrude:Jf,EventManager3D:Qh,EventMap:bu,FPS:dh,GESTURES:Fi,get GLTFObject(){return Ag},GifView:qp,GizmoManager:Zh,GizmoOperationManager:Jh,GlobalRef:sf,Group:Jp,HTMLAbsoluteLayout:hc,HTMLOverlayContainer:nf,HTMLOverlayElement:jp,ImageView:Lp,InfoWindow:ac,InteractionManager:td,KEYEVENTS:Bi,Layer:Oc,Layout:lc,LightManager:qh,LightObject:Eg,Line:Mp,LinearHorizontalLayout:gc,LinearVerticalLayout:yc,LocalRef:ef,MATERIAL_PRESETS:kh,MAX_UNDO_SIZE:30,MODE_ADD:3,MODE_EDIT:1,MODE_PASTE_DATABIND:5,MODE_PASTE_STYLE:4,MODE_SHIFT:2,MODE_VIEW:0,get Model(){return Ng},MoveHandle:Cc,NOTHING:Ci,Node:vf,OrthoLine:Ip,PIXEL_RATIO:uh,Path:lf,PlacementManager:ed,get PointLight(){return Cg},Polygon:Cp,PolygonExtrude:eg,Polyline:Op,Popup:cf,RealObject:zh,RealObjectCamera:zg,RealObjectDomElement:Lh,RealObjectDomTexture:qf,RealObjectDummy:Dg,RealObjectExtrude:Zf,RealObjectGLTF:qu,RealObjectGroup:Lg,RealObjectMesh:Nf,RealObjectPlane:jg,RealObjectPlane2D:Bf,RealObjectScene:Rg,RealObjectSprite:zf,RealObjectSprite2D:Ff,RealObjectText:Xf,Rect:wd,RectExtrude:tg,RectPath:rc,ReferenceMap:Af,RendererManager:Xh,RootContainer:Du,Ruler:Sd,SCALE_MIN:vh,SCENE_MODE:Li,Scene:Qu,SceneManager:Uh,ScenePopup:kc,ScriptLoader:Df,Shape:ec,get Sphere(){return ag},Sphere3D:og,get Sprite(){return lg},Star:yf,StarExtrude:ig,TableLayout:bc,Text:Qp,ThreeCapability:od,get ThreeContainer(){return Bg},Triangle:df,TriangleExtrude:rg,UNIT_DIMENSION:wh,UNIT_ROTATE:Ah,UNIT_SCALE:Mh,UNIT_TRANSLATE:Sh,ValueHolder:xf,get Wall(){return Og},Wall3D:Tg,animate:Jo,applyAlpha:xh,buildArrow3D:bh,compile:na,create:Ju,createCanvas:ph,createCanvasTexture:jf,createFloor:Gh,createRealObjectFor:Nh,debug:qr,delta:Qo,disposeObject3D:Dh,drawTextTexture:Gf,error:Wr,fontStyle:Yf,initFontFamilyWatcher:Vi,inspector:Hu,metrics:Or,opaqueColor:_h,projectToScreen:Fc,registerDefaultRealObjectFactory:Bh,registerRealObjectFactory:Fh,renderCanvasTexture:Rf,resolveMaterial3d:Eh,sceneComponent:wf,stopFPSMeasure:hh,textBounds:Wf,textTexture:Hf,toThreeSide:Ph,updateDefaultFontFamily:Yi,version:If,warn:Xr});const Vg=globalThis;"undefined"==typeof globalThis||Vg.scene||(Vg.scene=Yg);export{dc as AbsoluteLayout,ta as Animation,$p as AudioPlayer,bg as Banner,yg as Banner3D,sd as BoxSelectionManager,Mg as Camera,wg as Camera3D,id as CameraBookmarkManager,Wh as CameraManager,pc as CardLayout,tc as Component,vd as Connectable,lp as Container,Tc as ContainerAbstract,$h as ControlsManager,ug as Cube,dg as Cube3D,gg as Cylinder,fg as Cylinder3D,Ni as DEFAULT,Ri as DPPX,_f as DataSource,ff as Donut,ng as DonutExtrude,Ap as Ellipse,Jf as EllipseExtrude,Qh as EventManager3D,bu as EventMap,dh as FPS,Fi as GESTURES,Ag as GLTFObject,qp as GifView,Zh as GizmoManager,Jh as GizmoOperationManager,sf as GlobalRef,Jp as Group,hc as HTMLAbsoluteLayout,nf as HTMLOverlayContainer,jp as HTMLOverlayElement,Lp as ImageView,ac as InfoWindow,td as InteractionManager,Bi as KEYEVENTS,Oc as Layer,lc as Layout,qh as LightManager,Eg as LightObject,Mp as Line,gc as LinearHorizontalLayout,yc as LinearVerticalLayout,ef as LocalRef,kh as MATERIAL_PRESETS,ji as MAX_UNDO_SIZE,Di as MODE_ADD,Ti as MODE_EDIT,zi as MODE_PASTE_DATABIND,Ii as MODE_PASTE_STYLE,Oi as MODE_SHIFT,Pi as MODE_VIEW,Ng as Model,Cc as MoveHandle,Ci as NOTHING,vf as Node,Ip as OrthoLine,uh as PIXEL_RATIO,lf as Path,ed as PlacementManager,Cg as PointLight,Cp as Polygon,eg as PolygonExtrude,Op as Polyline,cf as Popup,zh as RealObject,zg as RealObjectCamera,Lh as RealObjectDomElement,qf as RealObjectDomTexture,Dg as RealObjectDummy,Zf as RealObjectExtrude,qu as RealObjectGLTF,Lg as RealObjectGroup,Nf as RealObjectMesh,jg as RealObjectPlane,Bf as RealObjectPlane2D,Rg as RealObjectScene,zf as RealObjectSprite,Ff as RealObjectSprite2D,Xf as RealObjectText,wd as Rect,tg as RectExtrude,rc as RectPath,Af as ReferenceMap,Xh as RendererManager,Du as RootContainer,Sd as Ruler,vh as SCALE_MIN,Li as SCENE_MODE,Qu as Scene,Uh as SceneManager,kc as ScenePopup,Df as ScriptLoader,ec as Shape,ag as Sphere,og as Sphere3D,lg as Sprite,yf as Star,ig as StarExtrude,bc as TableLayout,Qp as Text,od as ThreeCapability,Bg as ThreeContainer,df as Triangle,rg as TriangleExtrude,wh as UNIT_DIMENSION,Ah as UNIT_ROTATE,Mh as UNIT_SCALE,Sh as UNIT_TRANSLATE,xf as ValueHolder,Og as Wall,Tg as Wall3D,Jo as animate,xh as applyAlpha,bh as buildArrow3D,na as compile,Ju as create,ph as createCanvas,jf as createCanvasTexture,Gh as createFloor,Nh as createRealObjectFor,qr as debug,Qo as delta,Dh as disposeObject3D,Gf as drawTextTexture,Wr as error,Yf as fontStyle,Vi as initFontFamilyWatcher,Hu as inspector,Or as metrics,_h as opaqueColor,Fc as projectToScreen,Bh as registerDefaultRealObjectFactory,Fh as registerRealObjectFactory,Rf as renderCanvasTexture,Eh as resolveMaterial3d,wf as sceneComponent,hh as stopFPSMeasure,Wf as textBounds,Hf as textTexture,Ph as toThreeSide,Yi as updateDefaultFontFamily,If as version,Xr as warn};
|
|
51
|
+
`,this.element)}catch(t){}}onchangeMinimized(){const{minimized:t}=this.state;t?this.setState("height",24):this.setState("height",this.get("height"))}}lp=new WeakMap,tc.memoize(pp.prototype,"bounds",!0),tc.register("container",pp);const fp=Math.sqrt(3),gp=2;function mp(t,e,n,r,i){const s=5+i,o=n.x,a=n.y,c=r.x,l=r.y;if(Math.abs(o-c)>s&&Math.abs(a-l)>s){const n=(l-a)/(c-o),r=a-n*o;if(Math.abs(e-(n*t+r))>s)return!1}let h,d,u,p;return o>c?(d=o,h=c):(d=c,h=o),a>l?(p=a,u=l):(p=l,u=a),!(d+5<t)&&(!(h-5>t)&&(!(p+5<e)&&!(u-5>e)))}function yp(t,e,n,r=2){for(let i=0;i<n.length-1;i++)if(mp(t,e,n[i],n[i+1],r))return!0;return!1}function bp(t,e,n,r){if("arrow"!=t.slice(-5))return n;const i=Math.atan2(r.y-n.y,r.x-n.x),s=1.5*e;return{x:n.x+Math.cos(i)*s,y:n.y+Math.sin(i)*s}}function vp(t,e,n){let{lineWidth:r=gp,strokeStyle:i="#000000",lineCap:s=!1,alpha:o=1,begin:a="none",end:c="none",beginSize:l="size5",endSize:h="size5"}=n;if(("none"!=a||"none"!=c)&&(r=Number(r)||gp,t.lineCap=s,t.lineWidth=r,t.strokeStyle=i,t.fillStyle=i,t.globalAlpha*=o,"none"!=a&&xp(t,e[0],e[1],r,a,_p(l,r)),"none"!=c)){const n=e.length;xp(t,e[n-1],e[n-2],r,c,_p(h,r))}}function xp(t,e,n,r,i,s){const{x:o,y:a}=e,c=Math.atan2(n.y-a,n.x-o);switch(t.beginPath(),t.translate(o,a),t.rotate(c),i){case"oval":t.ellipse(0,0,s.X,s.Y,0,0,2*Math.PI),t.fill();break;case"diamond":t.moveTo(-s.X,0),t.lineTo(0,-s.Y),t.lineTo(s.X,0),t.lineTo(0,s.Y),t.fill();break;case"arrow":t.moveTo(0,0),t.lineTo(fp*s.X,-s.Y),t.lineTo(fp*s.X,s.Y),t.fill();break;case"sharp-arrow":t.moveTo(0,0),t.lineTo(fp*s.X,-s.Y),t.lineTo(-s.X/1.5+fp*s.X,0),t.lineTo(fp*s.X,s.Y),t.fill();break;case"open-arrow":t.moveTo(fp*s.X+r,-s.Y),t.lineTo(r,0),t.lineTo(fp*s.X+r,s.Y),t.stroke();break;case"cross":t.moveTo(-s.X,-s.Y),t.lineTo(s.X,s.Y),t.moveTo(s.X,-s.Y),t.lineTo(-s.X,s.Y),t.stroke()}t.rotate(-c),t.translate(-o,-a),t.closePath()}function _p(t,e){const n={X:0,Y:0};switch(e*=1.2,t){case"size1":n.X=e,n.Y=e;break;case"size2":n.X=1.5*e,n.Y=e;break;case"size3":n.X=2*e,n.Y=e;break;case"size4":n.X=e,n.Y=1.5*e;break;case"size5":default:n.X=1.5*e,n.Y=1.5*e;break;case"size6":n.X=2*e,n.Y=1.5*e;break;case"size7":n.X=e,n.Y=2*e;break;case"size8":n.X=1.5*e,n.Y=2*e;break;case"size9":n.X=2*e,n.Y=2*e}return n}const wp="N",Mp="S",Sp="E",Ap="W";class kp{constructor({component:t,anchor:e,position:n,self:r}){this.component=t,this._anchorName=e,this._position=n,this.self=r}get position(){const t=this.anchor;if(t){const{position:e}=t,n=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(n.x,n.y)}return this._position}set position({x:t,y:e}){this._position={x:t,y:e}}get anchor(){return this.component?.findAnchor(this._anchorName)}get direction(){const t=this.component.bounds,e=this.anchor;if(!e)return Sp;const n=e.position;return n.y<=t.top?wp:n.y>=t.top+t.height?Mp:n.x<=t.left?Ap:Sp}get boundaryPosition(){const t=this.anchor;if(t){let{position:e}=t,n=0,r=0;switch(this.direction){case Mp:r=20;break;case wp:r=-20;break;case Ap:n=-20;break;default:n=20}e={x:e.x+n,y:e.y+r};const i=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(i.x,i.y)}}}class Ep extends tc{isLine(){return!0}replaceRefids(t){["from","to"].forEach(e=>{const n=this.get(e);if(n?.component){const r=t.get(n.component)||n.component;this.set(e,{...n,component:r})}})}get fromEnd(){if(this.parent&&!this._fromEnd){const{component:t,anchor:e,position:n}=this.getState("from")||{};if(!t)return;const r=this.root?.findByRefid?.(t);if(!r)return;this._fromEnd=new kp({component:r,fromto:"from",anchor:e,position:n,self:this})}return this._fromEnd}get from(){return this.getState("from")}set from(t){delete this._fromEnd,this.set("from",t)}get toEnd(){if(this.parent&&!this._toEnd){const{component:t,anchor:e,position:n}=this.getState("to")||{};if(!t)return;const r=this.root?.findByRefid?.(t);if(!r)return;this._toEnd=new kp({component:r,fromto:"to",anchor:e,position:n,self:this})}return this._toEnd}get to(){return this.getState("to")}set to(t){delete this._toEnd,this.set("to",t)}move({x:t,y:e},n){n&&(this.from={position:this._fromEnd?.position||this.getState("from")?.position||{x:0,y:0}},this.to={position:this._toEnd?.position||this.getState("to")?.position||{x:0,y:0}}),super.move({x:t,y:e})}render(t){const{begin:e="none",end:n="none",lineWidth:r,round:i=0}=this.state;let s=this.drawPath;vp(t,s,this.state),t.beginPath();const o=bp(e,r,s[0],s[1]),a=bp(n,r,s[s.length-1],s[s.length-2]);s=[o,...s.slice(1,-1),a];let c={x:o.x,y:o.y};t.moveTo(o.x,o.y);for(let e=1;e<s.length;e++){const n=c;c=s[e];const r=s[e+1];if(n.x===c.x&&n.y===c.y)continue;if(!r){t.lineTo(c.x,c.y);break}let o=Math.sqrt((n.x-c.x)*(n.x-c.x)+(n.y-c.y)*(n.y-c.y)),a=0!==o?Math.atan2(n.x-c.x,n.y-c.y):0,l=Math.sin(a)*Math.min(i,o/2)+c.x,h=Math.cos(a)*Math.min(i,o/2)+c.y;const d=i>0||0!==o?{x:l,y:h}:c;o=Math.sqrt((r.x-c.x)*(r.x-c.x)+(r.y-c.y)*(r.y-c.y)),a=0!==o?Math.atan2(r.x-c.x,r.y-c.y):0,l=Math.sin(a)*Math.min(i,o/2)+c.x,h=Math.cos(a)*Math.min(i,o/2)+c.y;const u=i>0||0!==o?{x:l,y:h}:c;t.lineTo(d.x,d.y),i>0&&t.quadraticCurveTo(c.x,c.y,u.x,u.y)}this.drawStroke(t,void 0)}contains(t,e){const{lineWidth:n}=this.state;return yp(t,e,this.drawPath,n)}get resizable(){return!1}get mutable(){return!0}get rotatable(){return!1}get path(){const{from:t,to:e}=this.state,{x1:n,y1:r,x2:i,y2:s}=this.state;return[this.fromEnd?.position||t?.position||{x:n,y:r},this.toEnd?.position||e?.position||{x:i,y:s}]}set path(t){const[e,n]=t,{from:r,to:i}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...r,position:e},to:{...i,position:n}})}get textBounds(){const t=this.drawPath;let e,n,r=0;for(let i=1;i<t.length;i++){const s=t[i-1],o=t[i],a=(s.x-o.x)*(s.x-o.x)+(s.y-o.y)*(s.y-o.y);a>r&&(r=Math.ceil(a),e=s,n=o)}let{paddingTop:i,paddingLeft:s,paddingRight:o,paddingBottom:a}=this.state;return a||=0,i||=0,s||=0,o||=0,{left:Math.min(e.x,n.x)+s,top:Math.min(e.y,n.y)+i,width:Math.max(Math.abs(e.x-n.x)-s-o,0),height:Math.max(Math.abs(e.y-n.y)-i-a,0)}}get decorators(){return this.app.isEditMode?["decotag"]:[]}}Ep.getTipNeckPos=bp,Ep.containedInPath=yp,Ep.drawEndTips=vp,tc.register("line",Ep);const Cp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"angle",label:"start-angle",name:"startAngle",property:"startAngle"},{type:"angle",label:"end-angle",name:"endAngle",property:"endAngle"}],"value-property":"text"};class Pp extends(Md(ec)){is3dish(){return!0}render(t){const{cx:e,cy:n,rx:r,ry:i,startAngle:s,endAngle:o,anticlockwise:a}=this.state;t.beginPath(),t.ellipse(e,n,Math.abs(r),Math.abs(i),0,s||0,o||2*Math.PI,a),void 0!==s&&void 0!==o&&(t.lineTo(e,n),t.closePath())}get path(){const{cx:t,cy:e,rx:n,ry:r}=this.state;return[{x:t-n,y:e-r},{x:t+n,y:e-r},{x:t+n,y:e+r},{x:t-n,y:e+r}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2,rx:(n.x-e.x)/2,ry:(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:r,rx:i,ry:s}=this.state,o=(t-n)/(2*i-.5),a=(e-r)/(2*s-.5);return o*o+a*a<.25}outline(t){return function(t,e){const{cx:n,cy:r,rx:i,ry:s}=t.model,o=2*Math.PI*e,a=n+i*Math.cos(o),c=r+s*Math.sin(o);return t.toScene(a,c)}(this,t)}get anchors(){return function(t){const{left:e,top:n,width:r,height:i}=t.bounds,s=e+r/2,o=n+i/2;return[{name:"TOP",position:{x:s,y:n}},{name:"RIGHT",position:{x:e+r,y:o}},{name:"BOTTOM",position:{x:s,y:n+i}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get nature(){return Cp}}tc.memoize(Pp.prototype,"path",!1),tc.register("ellipse",Pp);const Tp={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e+1,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){n[e+1]=t})},ondragend:function(t,e,n){}},Op={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polygon"};class Dp extends ec{is3dish(){return!0}get mutable(){return!0}get pathExtendable(){return!0}get path(){return this.state.path}set path(t){this.set("path",t)}contains(t,e){const n=this.state.path;let r=!1;return n.forEach((i,s)=>{const o=(s+n.length+1)%n.length,a=i.x,c=i.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(r=!r)}),r}get controls(){const t=this.path;return t.map((e,n)=>{const r=t[n+1>=t.length?0:n+1];return{x:(e.x+r.x)/2,y:(e.y+r.y)/2,handler:Tp}})}get nature(){return Op}}tc.memoize(Dp.prototype,"controls",!1),tc.register("polygon",Dp);const Ip={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){n[e]=t})},ondragend:function(t,e,n){}},zp={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polyline"};class Lp extends Ep{get pathExtendable(){return!0}get path(){const{from:t,to:e}=this.state,{path:n}=this.state;return[this.fromEnd?.position||t?.position||n[0],...n.slice(1,-1),this.toEnd?.position||e?.position||n[n.length-1]]}set path(t){const{from:e,to:n}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...e,position:t[0]},to:{...n,position:t[t.length-1]},path:t})}get controls(){const t=this.path,e=[];for(let n=0;n<t.length-1;n++){const r=t[n],i=t[n+1];0==n&&e.push({x:r.x,y:r.y,handler:Ip}),e.push({x:(r.x+i.x)/2,y:(r.y+i.y)/2,handler:Ip}),n==t.length-2&&e.push({x:i.x,y:i.y,handler:Ip})}return e}get nature(){return zp}}tc.register("polyline",Lp);const jp={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/ortholine"};class Rp extends Ep{get pathExtendable(){return!1}get drawPath(){const t=this.path[0],e=this.path[1],{component:n,direction:r,boundaryPosition:i=t}=this.fromEnd||{},{component:s,direction:o,boundaryPosition:a=e}=this.toEnd||{},c=[i,a],l=[];i&&l.push(i);let h,d=n?.bounds;d&&(h=n.toScene(d.left,d.top),h=this.transcoordT2P(h.x,h.y),d={...d,left:h.x,top:h.y});const u=d?{left:d.left-20,top:d.top-20,width:d.width+40,height:d.height+40}:{left:i.x,top:i.y,width:0,height:0};d=d||u;let p=s?.bounds;p&&(h=s.toScene(p.left,p.top),h=this.transcoordT2P(h.x,h.y),p={...p,left:h.x,top:h.y});const f=p?{left:p.left-20,top:p.top-20,width:p.width+40,height:p.height+40}:{left:a.x,top:a.y,width:0,height:0};p=p||f;const g=[u,f],m=u.left>f.left?f.left:u.left,y=u.top>f.top?f.top:u.top,b={left:m,top:y,width:u.left+u.width>f.left+f.width?u.left+u.width-m:f.left+f.width-m,height:u.top+u.height>f.top+f.height?u.top+u.height-y:f.top+f.height-y};let v,x,_,w,M,S,A,k,E,C,P=0,T=0;d.left+d.width<p.left?(w=0,M=1,E=r,C=o,v=(d.left+d.width+p.left)/2,P=p.left-v):p.left+p.width<d.left&&(w=1,M=0,E=o,C=r,v=(d.left+p.width+p.left)/2,P=d.left-v),d.top+d.height<p.top?(_=0,S=1,A=r,k=o,x=(d.top+d.height+p.top)/2,T=p.top-x):p.top+p.height<d.top&&(_=1,S=0,A=o,k=r,x=(d.top+p.height+p.top)/2,T=d.top-x);const O=[];if(v&&P>T){let t,e,n;switch(C){case Ap:switch(E){case Sp:O.push({x:v,y:c[w].y}),O.push({x:v,y:c[M].y});break;case Ap:t=g[w].top+g[w].height/2,e=t>c[M].y?Math.min(g[w].top,c[M].y):Math.max(g[w].top+g[w].height,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:c[M].y});break;case wp:case Mp:e=E===Mp?Math.max(c[w].y,c[M].y):Math.min(c[w].y,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:c[M].y});break;default:return this.path}break;case Sp:switch(E){case Sp:e=c[w].y<c[M].y?Math.min(g[M].top,c[w].y):Math.max(g[M].top+g[M].height,c[w].y),n=e;break;case Ap:e=void 0!==x?x:c[w].y<c[M].y?b.top-.5*P:b.top+b.height+.5*P,n=e;break;case Mp:e=void 0!==x?Math.max(x,c[w].y):b.top+b.height,n=e;break;case wp:e=x?Math.min(x,g[w].top):b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:n}),O.push({x:c[M].x,y:n});break;case Mp:switch(E){case Sp:e=c[w].y,n=c[w].y>c[M].y?c[w].y:g[M].top+g[M].height;break;case Ap:e=x?Math.max(x,g[M].top+g[M].height):b.top+b.height,n=e;break;case Mp:e=b.top+b.height,n=e;break;case wp:e=x?Math.min(x,g[w].top):g[w].top,n=x?Math.max(x,g[M].top+g[M].height):g[M].top+g[M].height;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:n}),O.push({x:c[M].x,y:n});break;case wp:switch(E){case Sp:e=c[w].y,n=c[w].y<c[M].y?c[w].y:g[M].top;break;case Ap:e=x?Math.min(x,g[M].top):b.top,n=e;break;case Mp:e=void 0!==x?Math.max(x,c[w].y):c[w].y,n=void 0!==x?Math.min(x,c[M].y):c[M].y;break;case wp:e=b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:v,y:e}),O.push({x:v,y:n}),O.push({x:c[M].x,y:n});break;default:return this.path}l.push(...0===w?O:O.reverse())}else if(x){let t,e,n;switch(k){case wp:switch(A){case Mp:O.push({x:c[_].x,y:x}),O.push({x:c[S].x,y:x});break;case wp:t=g[_].left+g[_].width/2,e=t>c[S].x?Math.min(g[_].left,c[S].x):Math.max(g[_].left+g[_].width,c[S].x),O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:c[S].x,y:x});break;case Ap:e=Math.min(c[_].x,c[S].x),O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:c[S].x,y:x});break;case Sp:e=Math.max(c[_].x,c[S].x),O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:c[S].x,y:x});break;default:return this.path}break;case Mp:switch(A){case Ap:e=b.left,n=e;break;case Sp:e=void 0!==v?Math.max(v,c[_].x):b.left+b.width,n=e;break;case wp:e=void 0!==v?v:c[_].x<c[S].x?b.left-.5*T:b.left+b.width+.5*T,n=e;break;case Mp:e=c[_].x,n=c[_].x<c[S].x?Math.min(g[S].left,c[_].x):Math.max(g[S].left+g[S].width,c[_].x);break;default:return this.path}O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:n,y:x}),O.push({x:n,y:c[S].y});break;case Sp:switch(A){case Ap:e=void 0!==v?Math.min(v,c[_].x):c[_].x,n=void 0!==v?Math.max(v,c[S].x):c[S].x;break;case Sp:e=b.left+b.width,n=e;break;case wp:e=void 0!==v?Math.max(v,c[S].x):b.left+b.width,n=e;break;case Mp:e=c[_].x,n=Math.max(g[S].left+g[S].width,c[_].x);break;default:return this.path}O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:n,y:x}),O.push({x:n,y:c[S].y});break;case Ap:switch(A){case Ap:e=b.left,n=e;break;case Sp:e=void 0!==v?Math.max(v,c[_].x):c[_].x,n=void 0!==v?Math.min(v,c[S].x):c[S].x;break;case wp:e=b.left,n=e;break;case Mp:e=c[_].x<c[S].x?Math.min(g[S].left,c[_].x):c[_].x,n=Math.min(e,c[S].x);break;default:return this.path}O.push({x:e,y:c[_].y}),O.push({x:e,y:x}),O.push({x:n,y:x}),O.push({x:n,y:c[S].y});break;default:return this.path}l.push(...0===_?O:O.reverse())}else{let t,e;switch(r){case wp:switch(o){case wp:e=b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case Mp:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top+b.height}),l.push({x:c[1].x,y:b.top+b.height});break;case Sp:t=c[1].y<c[0].y&&c[1].x<c[0].x?c[0].x:b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;case Ap:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case Mp:switch(o){case wp:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top}),l.push({x:c[1].x,y:b.top});break;case Mp:case Sp:case Ap:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;case Ap:switch(o){case wp:t=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].x:b.left,e=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].y:Math.min(b.top,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case Mp:t=b.left,e=Math.max(b.top+b.height,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case Sp:t=b.left+b.width,l.push({x:c[0].x,y:b.top}),l.push({x:t,y:b.top}),l.push({x:t,y:c[1].y});break;case Ap:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case Sp:switch(o){case wp:e=c[0].y<c[1].y&&c[0].x<c[1].x?c[0].y:b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case Mp:e=c[0].y>c[1].y&&c[0].x<c[1].x?c[0].y:b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case Sp:case Ap:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;default:return this.path}}return a&&l.push(a),[t,...l,e].filter((t,e,n)=>{if(0===e)return!0;const r=n[e-1];return t.x!==r.x||t.y!==r.y}).filter((t,e,n)=>{if(0===e||e>=n.length-1)return!0;const r=n[e-1],i=n[e+1];return!(t.x===r.x&&t.x===i.x||t.y===r.y&&t.y===i.y)})}get nature(){return jp}}tc.register("ortholine",Rp);const Fp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"image-src",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:"$base_url",defaultStorage:"scene-image",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0}},{type:"select",label:"cross-origin",name:"crossOrigin",property:{options:["","anonymous","use-credentials"]}}],"value-property":"src",help:"scene/component/image-view"};class Bp extends(rc(ec)){static get noimage(){return Bp.NOIMAGE||(Bp.NOIMAGE=new Image,Bp.NOIMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII="),Bp.NOIMAGE}dispose(){super.dispose(),this._offcanvas=null,this._image=null}render(t){const{left:e,top:n,width:r,height:i,isGray:s=!1,alpha:o=1,src:a}=this.state;if(this.prepareIf(!this._image&&a),t.beginPath(),t.globalAlpha*=o,this._image&&this._image.complete)if(s&&this._offcanvas)t.drawImage(this._offcanvas,e,n,r,i);else try{t.drawImage(this._image,e,n,r,i)}catch(s){t.drawImage(Bp.noimage,e,n,r,i)}else!this.app.isViewMode&&t.drawImage(Bp.noimage,e,n,r,i)}get nature(){return Fp}get hasTextProperty(){return!1}async ready(){await super.ready(),this.prepareIf(!this._image&&this.state.src)}prepare(t,e){const{src:n,crossOrigin:r}=this.state;if(n){this._image=new Image;try{r&&(this._image.crossOrigin=r),this._image.src=this.app.url(n)||""}catch(t){return void e(t)}this._image.onload=()=>{if(this.get("isGray")){const t=this._image.width,e=this._image.height;this._offcanvas=tc.createCanvas(t,e);const n=this._offcanvas.getContext("2d");n.drawImage(this._image,0,0);const r=function(t,e,n){let r;try{r=t.getImageData(0,0,e,n)}catch(t){return Wr("Get Image Data Error: "+(t instanceof Error?t.message:String(t))),null}const i=r.data;for(let t=0;t<e*n*4;t+=4){const e=i[t],n=i[t+1],s=i[t+2],o=Math.floor((e+n+s)/3);r.data[t]=o,r.data[t+1]=o,r.data[t+2]=o}return r}(n,t,e);n.putImageData(r,0,0)}t(this)},this._image.onerror=t=>{this._image&&!this._image.currentSrc&&(this._image=null),e(t)}}else t(this)}get src(){return this.get("src")}set src(t){this.set("src",t)}onchange(t,e){(t.hasOwnProperty("src")||t.hasOwnProperty("isGray"))&&(this._offcanvas=null,this._image=null,this.prepareIf(t.src))}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("image/"))return void(this.src=e[n])}}tc.register("image-view",Bp);class Np extends(cp(rc(tc))){is3dish(){return!0}prerender(){}}var Yp,Vp,Gp={},Hp={},Up={};function Wp(){if(Vp)return Hp;Vp=1,Object.defineProperty(Hp,"__esModule",{value:!0});var t=function(){if(Yp)return Up;Yp=1,Object.defineProperty(Up,"__esModule",{value:!0});var t=function(){function t(){}return t.bitsToNum=function(t){return t.reduce(function(t,e){return 2*t+e},0)},t.byteToBitArr=function(t){for(var e=[],n=7;n>=0;n--)e.push(!!(t&1<<n));return e},t.lzwDecode=function(t,e){for(var n,r,i=0,s=function(t){for(var n=0,r=0;r<t;r++)e.charCodeAt(i>>3)&1<<(7&i)&&(n|=1<<r),i++;return n},o=[],a=1<<t,c=a+1,l=t+1,h=[],d=function(){h=[],l=t+1;for(var e=0;e<a;e++)h[e]=[e];h[a]=[],h[c]=null};;)if(r=n,(n=s(l))!==a){if(n===c)break;if(n<h.length)r!==a&&h.push(h[r].concat(h[n][0]));else{if(n!==h.length)throw new Error("Invalid LZW code.");h.push(h[r].concat(h[r][0]))}o.push.apply(o,h[n]),h.length===1<<l&&l<12&&l++}else d();return o},t}();return Up.SuperGifUtils=t,Up}(),e=function(){function e(t,e){this.stream=t,this.handler=e}return e.prototype.parseCT=function(t){for(var e=[],n=0;n<t;n++)e.push(this.stream.readBytes(3));return e},e.prototype.readSubBlocks=function(){var t,e;e="";do{t=this.stream.readByte(),e+=this.stream.read(t)}while(0!==t);return e},e.prototype.parseHeader=function(){var e={};if(e.sig=this.stream.read(3),e.ver=this.stream.read(3),"GIF"!==e.sig)throw new Error("Not a GIF file.");e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.gctFlag=n.shift(),e.colorRes=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.sorted=n.shift(),e.gctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.bgColor=this.stream.readByte(),e.pixelAspectRatio=this.stream.readByte(),e.gctFlag&&(e.gct=this.parseCT(1<<e.gctSize+1)),this.handler.hdr&&this.handler.hdr(e)},e.prototype.parseExt=function(e){var n=this;switch(e.label=this.stream.readByte(),e.label){case 249:e.extType="gce",function(e){n.stream.readByte();var r=t.SuperGifUtils.byteToBitArr(n.stream.readByte());e.reserved=r.splice(0,3),e.disposalMethod=t.SuperGifUtils.bitsToNum(r.splice(0,3)),e.userInput=r.shift(),e.transparencyGiven=r.shift(),e.delayTime=n.stream.readUnsigned(),e.transparencyIndex=n.stream.readByte(),e.terminator=n.stream.readByte(),n.handler.gce&&n.handler.gce(e)}(e);break;case 254:e.extType="com",function(t){t.comment=n.readSubBlocks(),n.handler.com&&n.handler.com(t)}(e);break;case 1:e.extType="pte",function(t){n.stream.readByte(),t.ptHeader=n.stream.readBytes(12),t.ptData=n.readSubBlocks(),n.handler.pte&&n.handler.pte(t)}(e);break;case 255:e.extType="app",function(t){n.stream.readByte(),t.identifier=n.stream.read(8),t.authCode=n.stream.read(3),"NETSCAPE"===t.identifier?function(t){n.stream.readByte(),t.unknown=n.stream.readByte(),t.iterations=n.stream.readUnsigned(),t.terminator=n.stream.readByte(),n.handler.app&&n.handler.app.NETSCAPE&&n.handler.app.NETSCAPE(t)}(t):function(t){t.appData=n.readSubBlocks(),n.handler.app&&n.handler.app[t.identifier]&&n.handler.app[t.identifier](t)}(t)}(e);break;default:e.extType="unknown",function(t){t.data=n.readSubBlocks(),n.handler.unknown&&n.handler.unknown(t)}(e)}},e.prototype.parseImg=function(e){e.leftPos=this.stream.readUnsigned(),e.topPos=this.stream.readUnsigned(),e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.lctFlag=n.shift(),e.interlaced=n.shift(),e.sorted=n.shift(),e.reserved=n.splice(0,2),e.lctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.lctFlag&&(e.lct=this.parseCT(1<<e.lctSize+1)),e.lzwMinCodeSize=this.stream.readByte();var r=this.readSubBlocks();e.pixels=t.SuperGifUtils.lzwDecode(e.lzwMinCodeSize,r),e.interlaced&&(e.pixels=function(t,e){for(var n=new Array(t.length),r=t.length/e,i=function(r,i){var s=t.slice(i*e,(i+1)*e);n.splice.apply(n,[r*e,e].concat(s))},s=[0,4,2,1],o=[8,8,4,2],a=0,c=0;c<4;c++)for(var l=s[c];l<r;l+=o[c])i(l,a),a++;return n}(e.pixels,e.width)),this.handler.img&&this.handler.img(e)},e.prototype.parseBlock=function(){var t={};switch(t.sentinel=this.stream.readByte(),String.fromCharCode(t.sentinel)){case"!":t.type="ext",this.parseExt(t);break;case",":t.type="img",this.parseImg(t);break;case";":t.type="eof",this.handler.eof&&this.handler.eof(t);break;default:throw new Error("Unknown block: 0x"+t.sentinel.toString(16))}"eof"!==t.type&&setTimeout(this.parseBlock.bind(this),0)},e.prototype.parse=function(){this.parseHeader(),setTimeout(this.parseBlock.bind(this),0)},e}();return Hp.SuperGifParser=e,Hp}var Xp,qp,Kp={};var $p=function(){if(qp)return Gp;qp=1,Object.defineProperty(Gp,"__esModule",{value:!0});var t=Wp(),e=function(){if(Xp)return Kp;Xp=1,Object.defineProperty(Kp,"__esModule",{value:!0});var t=function(){function t(t){this.data=t,this.position=0}return t.prototype.readByte=function(){if(this.position>=this.data.length)throw new Error("Attempted to read past end of stream.");return this.data instanceof Uint8Array?this.data[this.position++]:255&this.data.charCodeAt(this.position++)},t.prototype.readBytes=function(t){for(var e=[],n=0;n<t;n++)e.push(this.readByte());return e},t.prototype.read=function(t){for(var e="",n=0;n<t;n++)e+=String.fromCharCode(this.readByte());return e},t.prototype.readUnsigned=function(){var t=this.readBytes(2);return(t[1]<<8)+t[0]},t}();return Kp.SuperGifStream=t,Kp}(),n=function(){function n(t,e){var n=this;for(var r in this.gifImgElement=t,this.options={autoPlay:!0},this.loading=!1,this.ready=!1,this.transparency=null,this.delay=null,this.disposalMethod=null,this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,this.playing=!0,this.forward=!0,this.ctxScaled=!1,this.frames=[],this.frameOffsets=[],this.initialized=!1,this.currentFrameIndex=-1,this.iterationCount=0,this.stepping=!1,this.handler={hdr:this.withProgress(this.doHdr.bind(this)),gce:this.withProgress(this.doGCE.bind(this)),com:this.withProgress(this.doNothing.bind(this)),app:{NETSCAPE:this.withProgress(this.doNothing.bind(this))},img:this.withProgress(this.doImg.bind(this)),eof:function(){n.pushFrame(),n.canvas.width=n.hdr.width*n.getCanvasScale(),n.canvas.height=n.hdr.height*n.getCanvasScale(),n.playerInit(),n.loading=!1,n.ready=!0,n.loadCallback&&n.loadCallback(n.gifImgElement)}},e)this.options[r]=e[r];this.onEndListener=e.onEnd,this.loopDelay=e.loopDelay||0,this.overrideLoopMode=null!=e.loopMode?e.loopMode:"auto",this.drawWhileLoading=null==e.drawWhileLoading||e.drawWhileLoading}return n.prototype.init=function(){var t=this.gifImgElement.parentNode,e=document.createElement("div");this.canvas=document.createElement("canvas"),this.canvasContext=this.canvas.getContext("2d"),this.tmpCanvas=document.createElement("canvas"),e.className=this.options.enclosingClass||"super-gif",e.appendChild(this.canvas),t&&(t.insertBefore(e,this.gifImgElement),t.removeChild(this.gifImgElement)),this.initialized=!0},n.prototype.loadSetup=function(t){return!this.loading&&(t&&(this.loadCallback=t),this.loading=!0,this.frames=[],this.clear(),this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,!0)},n.prototype.completeLoop=function(){this.onEndListener&&this.onEndListener(this.gifImgElement),this.iterationCount++,!1!==this.overrideLoopMode||this.iterationCount<0?this.doStep():(this.stepping=!1,this.playing=!1)},n.prototype.doStep=function(){if(this.stepping=this.playing,this.stepping){this.stepFrame(1);var t=10*this.frames[this.currentFrameIndex].delay;t||(t=100),0===this.getNextFrameNo()?(t+=this.loopDelay,setTimeout(this.completeLoop.bind(this),t)):setTimeout(this.doStep.bind(this),t)}},n.prototype.step=function(){this.stepping||setTimeout(this.doStep.bind(this),0)},n.prototype.putFrame=function(){var t;this.currentFrameIndex=parseInt(this.currentFrameIndex.toString(),10),this.currentFrameIndex>this.frames.length-1&&(this.currentFrameIndex=0),this.currentFrameIndex<0&&(this.currentFrameIndex=0),t=this.frameOffsets[this.currentFrameIndex],this.tmpCanvas.getContext("2d").putImageData(this.frames[this.currentFrameIndex].data,t.x,t.y),this.canvasContext.globalCompositeOperation="copy",this.canvasContext.drawImage(this.tmpCanvas,0,0)},n.prototype.playerInit=function(){this.loadErrorCause||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.options.autoPlay?this.step():(this.currentFrameIndex=0,this.putFrame()))},n.prototype.clear=function(){this.transparency=null,this.delay=null,this.lastDisposalMethod=this.disposalMethod,this.disposalMethod=null,this.frame=null},n.prototype.parseStream=function(e){try{new t.SuperGifParser(e,this.handler).parse()}catch(t){this.handleError("parse")}},n.prototype.setSizes=function(t,e){this.canvas.width=t*this.getCanvasScale(),this.canvas.height=e*this.getCanvasScale(),this.tmpCanvas.width=t,this.tmpCanvas.height=e,this.tmpCanvas.style.width=t+"px",this.tmpCanvas.style.height=e+"px",this.tmpCanvas.getContext("2d").setTransform(1,0,0,1,0,0)},n.prototype.drawError=function(){this.canvasContext.fillStyle="black",this.canvasContext.fillRect(0,0,this.hdr.width,this.hdr.height),this.canvasContext.strokeStyle="red",this.canvasContext.lineWidth=3,this.canvasContext.moveTo(0,0),this.canvasContext.lineTo(this.hdr.width,this.hdr.height),this.canvasContext.moveTo(0,this.hdr.height),this.canvasContext.lineTo(this.hdr.width,0),this.canvasContext.stroke()},n.prototype.handleError=function(t){this.loadErrorCause=t,this.hdr={width:this.gifImgElement.width,height:this.gifImgElement.height},this.frames=[],this.drawError()},n.prototype.doHdr=function(t){this.hdr=t,this.setSizes(this.hdr.width,this.hdr.height)},n.prototype.doGCE=function(t){this.pushFrame(),this.clear(),this.transparency=t.transparencyGiven?t.transparencyIndex:null,this.delay=t.delayTime,this.disposalMethod=t.disposalMethod},n.prototype.pushFrame=function(){this.frame&&(this.frames.push({data:this.frame.getImageData(0,0,this.hdr.width,this.hdr.height),delay:this.delay}),this.frameOffsets.push({x:0,y:0}))},n.prototype.doImg=function(t){var e=this;this.frame||(this.frame=this.tmpCanvas.getContext("2d"));var n=this.frames.length,r=t.lctFlag?t.lct:this.hdr.gct;n>0&&(3===this.lastDisposalMethod?null!==this.disposalRestoreFromIdx?this.frame.putImageData(frames[this.disposalRestoreFromIdx].data,0,0):this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height):this.disposalRestoreFromIdx=n-1,2===this.lastDisposalMethod&&this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height));var i=this.frame.getImageData(t.leftPos,t.topPos,t.width,t.height);t.pixels.forEach(function(t,n){t!==e.transparency&&(i.data[4*n+0]=r[t][0],i.data[4*n+1]=r[t][1],i.data[4*n+2]=r[t][2],i.data[4*n+3]=255)}),this.frame.putImageData(i,t.leftPos,t.topPos),this.ctxScaled||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.ctxScaled=!0),this.drawWhileLoading&&(this.canvasContext.drawImage(this.tmpCanvas,0,0),this.drawWhileLoading=this.options.autoPlay),this.lastImg=t},n.prototype.doNothing=function(){},n.prototype.withProgress=function(t){return function(e){t(e)}},n.prototype.getNextFrameNo=function(){var t=this.forward?1:-1;return(this.currentFrameIndex+t+this.frames.length)%this.frames.length},n.prototype.stepFrame=function(t){this.currentFrameIndex=this.currentFrameIndex+t,this.putFrame()},n.prototype.getCanvasScale=function(){return this.options.maxWidth&&this.hdr&&this.hdr.width>this.options.maxWidth?this.options.maxWidth/this.hdr.width:window.devicePixelRatio||1},n.prototype.play=function(){this.playing=!0,this.step()},n.prototype.pause=function(){this.playing=!1},n.prototype.isPlaying=function(){return this.playing},n.prototype.getCanvas=function(){return this.canvas},n.prototype.isLoading=function(){return this.loading},n.prototype.isReady=function(){return this.ready},n.prototype.isAutoPlay=function(){return this.options.autoPlay},n.prototype.getLength=function(){return this.frames.length},n.prototype.getCurrentFrame=function(){return this.currentFrameIndex},n.prototype.moveTo=function(t){this.currentFrameIndex=t,this.putFrame()},n.prototype.loadURL=function(t,n){var r=this;if(this.loadSetup(n)){var i=new XMLHttpRequest;i.open("GET",t,!0),"overrideMimeType"in i?i.overrideMimeType("text/plain; charset=x-user-defined"):"responseType"in i?i.responseType="arraybuffer":i.setRequestHeader("Accept-Charset","x-user-defined"),i.onloadstart=function(){r.initialized||r.init()},i.onload=function(){if(200===i.status){var t=i.response;t.toString().indexOf("ArrayBuffer")>0&&(t=new Uint8Array(t));var n=new e.SuperGifStream(t);setTimeout(function(){r.parseStream(n)},0)}else r.handleError("xhr - response")},i.onerror=function(){r.handleError("xhr")},i.send()}},n.prototype.load=function(t){this.loadURL(this.gifImgElement.src,t)},n}();return Gp.SuperGif=n,Gp}();const Qp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"src",name:"src"},{type:"checkbox",label:"play",name:"play"}],"value-property":"src",help:"scene/component/gif-view"};class Zp extends Np{async oncreate_element(t){const{src:e,play:n}=this.state;this.onchangesrc(e),this.onchangeplay(n)}buildImg(){const t=this.element;if(!t)return document.createElement("img");t.replaceChildren();const e=document.createElement("img");return e.style.width="100%",e.style.height="100%",t.appendChild(e),e}onchange(t,e){super.onchange(t,e),"src"in t&&this.onchangesrc(t.src),"play"in t&&this.onchangeplay(t.play)}setElementProperties(t){}onchangeplay(t){const e=this._superGif;e&&e.isReady()&&(t?e.play():e.pause())}onchangesrc(t){const e=this.buildImg();t||(t="data:image/gif;base64,R0lGODlhYABIAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKio+Pj5iYmKCgoKampqurq66urrCwsLGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrOzs7S0tLa2tre3t7m5ubu7u7+/v8DAwMHBwcPDw8XFxcfHx8vLy8/Pz9LS0tXV1dfX193d3eTk5Onp6fj4+Pz8/P7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v///////////////////////////////////////////////////////////////////////////////yH5BAkAAPUAIf47R2VuZXJhdGVkIGJ5IGpzZ2lmIChodHRwczovL2dpdGh1Yi5jb20vYW50aW1hdHRlcjE1L2pzZ2lmLykALAAAAABgAEgAAAj+AGcJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8ePIEOKHEmypMmR9VKqXMmypcuXMGPKnJkSIs2bOHPqZGlzp8+fQOv1DEq0KMyhRpMmRaq0KVCmTqPmhCq1qkyqLrFRSyYwGTVsVo1iZXmNa8Fk18ISHasSm1mDycCq/ck2JTWF1ObSfTjz7cFken3WFbow8M7BDA3rHOwXruKpfGXeTZg3qDVrUge7RRg3KLZjx+Q2HVyvLNy0QaMJjBaVdD2tZr2K/mmNIObRkR+n9AsYt0Pddg1WXppb8bWDx1CLLW74GcJnSl3TtDY8Zu2Et4tKl7n52eyWnxXvhl7+26jqrspbnlfIWjtz2gWPZV95neH8veU9NxZYfbfD3kFt99J6Bnmn0mQO9XfYezrVxxlmx0GUXIAM4hSeffsxBN1TFd5E4Ef3QZbfTg6CNJ5gHXJ3TEntLThiTh+KFCJNAqZU4kgAitjQTheepOBMNcZI0oQ6JpbTjSZtiNN2PZ400IxHpdiSc07G911M0iFZZYtAStnWilUeBGVLrlEZpmM0elmPlmfO8iOZXl4DZpsGEYmll2bSWWCXLwJXVY1+urhjoGEBSuiSah6K36CKtpZoo4s9CimielZq6aWYZqrpppx26umnoIZ6UkAAOw=="),e.src=t,e.setAttribute("rel:animated_src",t),e.setAttribute("rel:auto_play",String(0)),this._superGif=new $p.SuperGif(e,{autoPlay:!1}),this._superGif.init(),this.element&&Array.from(this.element.children).forEach(t=>{t.style.width="100%",t.style.height="100%"});const n=this._superGif.getCanvas();n.style.width="100%",n.style.height="100%",this._superGif.load(()=>{setTimeout(()=>{this._superGif.moveTo(0),this.play&&this._superGif.play()},100)})}ondropfile(t,e){for(let n=0;n<t.length;n++)if(/\.gif$/.test(t[n].name))return void(this.src=e[n])}get src(){return this.getState("src")}set src(t){this.set("src",t)}get play(){return this.getState("play")}set play(t){this.setState("play",t)}get nature(){return Qp}get tagName(){return"div"}}tc.register("gif-view",Zp);const Jp={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"attachment-selector",label:"src",name:"src",property:{category:"audio"}},{type:"checkbox",label:"started",name:"started"},{type:"checkbox",label:"loop",name:"loop"}],"value-property":"src",help:"scene/component/audio"};class tf extends(rc(ec)){static get image(){return tf.IMAGE||(tf.IMAGE=new Image,tf.IMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAMAAAC3Ycb+AAAAP1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACzJYIvAAAAFHRSTlMA8BAwgNBgQKB/wCBwUJDg37CvXyUlBK8AABFYSURBVHja7NsBkqIwFIThTiAQgyBq3/+sm6p1tnamZkaTMhJJf1f4S/JeEIiIiIiIiIiIiIiIiEhD7Hg4BH84TpAKjJ4f3NFCtjVd+InXz2RTs+FXlxGylYHfcVfIJmb+YFWSLUyGVJKKBJJKUo+Rd6w63l/qzLuCkryO5fe0l2xk5mMWbe+v0fNBRqf7S3je6CipQ2ACr+dWcYEpzBFS1plpguatsnomMgdIQSOTuQ5SjmE6/UgK8szgdJIUM/FG41YlFmYJ2kkKsY5ZzAwBurHDk3WGeRY0bvYrGa1+rqNI22f7dS32ZnUK1GMr0eSK3mEc9dhKMxp+ZTo8kT2emOXS5LQ1kCxbJBocSd2k5PaIjMVzjWcdJPk9ooBnmzx1t5XbIxqBKpJ4NGTgzwKiGpK4do72gb+ZUMIYtCPm9WCPMsYTE5k2hq2ZvzujlCE1iRmwf3dvmRyKsT0T7b9I7HEPCpqCiqT2IIqaT1pI0noQZdlFC8l/PbYPAnRORT56VBEE6FXkb49agmByKhJ71BME6FsvEntUFQTdqekisUdlQWCXhovEHtUFAWbTapHYo8YgmFybO3vsUWcQYGmxSOxRbRAMprkisUfFQVKmrX18sxt7VB0ENjT1xir2qDxIwkFi3v89e+xRfxAMzfzzIfZ4hyAYDR9zwVuLPd4jCDrTwoLYGb5LEFi3/+E3rweR6urX20c/Fvls2Pvwm9mDSGIPhv8YPyGf3/eo9Ye7O8B2FIShAAooakEttex/rbODad5/yTHIAjqn505IQPv+Xz06dz+4VXORHEZcgAcB8updM8F6e25jBzwIkE07l+x8amMnPDp6nsNJ+BoZ7Q6F8egqAda9VEuRNlZjBzwYkMskdXR73okd8GBAJiKYjBcZKKqG9OiKDbgdfxJ5VhsBPDiQZhaouD3p4hfw4EAmwxisz3MSHwAPEmQ1TB1N+SmXWoAHC7JbZsWl/IxLLcCDBplNo3lrfMLsmwAPGmShAxX5/1vOEzjEz3iyfQ/hI36W4TctsUesOAifPdrQg8M++KYl95iCBkjI1r8634betBAPHZDTPFAmD3zLiHgogVTziMsahz0eIh5aIGHGRSJ2mFtHPR4iHhQIP2UvWGMf8wk74qEIEib7rLjPiBfxiAcCwp8V+Nae3uMdRhAPDIR/J5f/Q2DTcC+hIB7qIGEq3Ti9bx+sryMeAAgS70OK8G2kBD8L8QBAoLWU3g3vUVIc6D0txAMAsY+4jBWowXHO64gHBGKfYJ2T5qY1BxcL98BB+PQ+XiS9xxh9EQ8ChA6C5UXWIUoE9MBB8LVHQoS7ib8/dRn3sAcJ6bQRSdH96RDxIEH4QEX+AHF4LxHEAwUh12xyr1V8lwjiQYDYF8kuf1jluUQQDwrEvkhW8Wc6LhHUgwfhi4QPlHm7LRHawx4kpE191Dq8lgjhAYDQa1cftYrPEiE8OJDb40uqyzdQCA8WhAzL4G/PT4c3WrgHD2IfllGl53V37zsgHg5ApPNvVvq4Fn4spx4oiH1W3CwtEV+PDhEPJyBSkVX4aa7emkM83ICEKWpGM7wdvYCCeDgCEYpcwhLxczhEPFyBCEUWnRL5T6X59SBASBF+9l28TL5F7uEORCZyCUvEx+S7yT0cgoRVb9JaXLR1qUdfgksQ0fTbgmhFB20d8HAKEha14+F8f1sHPNyCiL6EqK+n20/rgIdjkFC0Ho1s6Gndvcc9ICkr/ey8/rHO6vp9KawL8DAFOV6l9Fyub7IbflsCag1qRfVsXWvxHjxIejU+BHZV6uvHD1XiEb++Bw8i+dNd+Wv0eCQmhcPhRPwUUt2DB5G1sfa1aeyzAuyJj9x2HjyIdKzIKw5SI14ieFtvo3kIQERj3lVhkUOnRD7AnjV5369QkAOJZeCH+Jh41xOLs73dQwAifY6dpxCCbjTDzLf1Bm1Y93tAIDOWXcLPvrHyr2hVoEAceEAgDQzB4jetk0/c2OXRHB48EJCpa4dgpYh2ETxtrshz7zx4ICCzfuTSDn8p/EOS9OTjwgMB+cABP3yWYuOPIofs33LigYCULlpZNXJppVU30Vf14kGAUCLijf1D71lN9FW9eFiA9KgZ8FPpPUsSnufGA+8hvAg2Kpz0nrX//qp+PIgpC3i6xJRITOye9fn1VT15ICCrVlQG5rywo0H8x965bVkNwmCYQ2kR6Gmb939WXV65dFnI/tPdjPBfO7XMN4EkTUJtqZp4sCJ1+8jwkhMu0KpMxFXFA8hlVfQSMxGH5mDK1VKV8QCyvTVtUiYyo7V358VStfGoAEFMhGYhEwloxZy9WKo2Hjwg5iSOvFDXeUYd33+PuVfHgwnEBWLocDJp+IIa2fyvperjwQRiXCKGosyXqoA+YfsIELuYu4HAt+msMknfDK4jfQJIzOZ2IPAQWJtFOhQKivR2IDZ6Awis7V0iLxqBI7uEZo19dakTogLSwKvf8yk8Jq6CGK0GKvWlatG7b7kkUU/Lo1gdXWn7/4E0j0qeJDpqN/ABqQcgJgdqURb4chjQktIugDS6wFFiz3JgaJj7AGJmholAe9YKhoZLJ0Ca6smjwJ4VwVN96gVIE5GM71kHaGKxGyAtRDaB2NBhLVmpHyANRKzDO28W7FS3HQFpaIWa8TrfCXQwegJSL5k+8M9UJ+pm9QTEnCIZrR0MDQeQ9ua0iCcYQaBTV0CqNXQW/yiyYG7W1heQanPaCkciBXuH1BkQJzHcDQxmpgGkPatl4WkbCXO/bW9AqlNg4H0PPMi6A1IxkQmOZ8D0ousNSMVEEuyreTAQ6Q7IRJeCX2YZQHhv6SrBOmpkM+YUzN0BqSRQCupmTeCP9wdkhiOREwtEzgGEsWcF9BhK9R8fQDiN7A8DiR0CKXQlj/q9IM8OgXjIzcKBlAHkD6FulgNzJwPIHwpo8mQAkX3LiPq9dKUMAQk9AqmcqmjuBAJCPQIpA4guIAsKJA0gnwNy3A4kDyBIHCEPxAwgf8gPILqA5AFEF5CxZX0lIHYc6rqADLf380BmFMgxgIzUyf8MJKLTRelKHgKy9wgkjfS7LiA0gKgC8vQn3HUA4RQ5LKPIAQciWbqIEg0YkLNDIHYUyqkCsmKN5vg3+W0AYTRATaPY+uu1IwS6UMGAlO6AFPjSCQMStaNh53cdcPG7Hx1Uupo+rx+Bltn1BuTAj5BptEV/bHAAwbnJMICwRmtUDOSEA8s4Rmtw3nITGD6TwUNoG0Ca7xi2YKSPj2eKXQFxQWKA2QbGMWEMMGseOb7C7T47uJS1JyAzVbTjqZdU3zbHzMXWS+qp4Fgn8Ahy/QCRGqQcwU1vGnN7fylboWn8Bzg//hyjxltvdcl45bwFfYKzFyBy11UU9BnjuoqfWizVlQXulpzBTNbaB5Aid+VRrkBFB630AMS9BC8FK2ggE7u/FGy1kvfcB9TKQufX5uUXNWl3EjvWCi4k/u9A3Ddq1CpTIQGe6VN1qd8ArcvDQNw3S41Kn6qQmOq5e7pRr+8fAYLiIJtFrrvYRMYL0q06vj8EZLXUriJzRY8H1xEagOCK7gkghRg6RQYO0I6aWPwIEAru80AiMWSdzAeuDXUKyr+WqpAID8hMHC1Ct8F4mUsQ6W8pJMICki0JHCBczAFdBl38G3VE6ErQhhWlih4LWrCSLpaqjggHiGe9mVjRY0YPoelyqcqIcIDEe97rqJFFH7FcLlUZEQ6Qg5plvZiBFNhtri1VFREGEC/Eg4nZoU5vqi1VFREGkIXDQ8xAIhzoT/WlKiLCAFIYPOQMxOPdjfWlKiLCADJRm3YGj+pDE2xktmmpaogwgMz8d8GrumZ4xzpbvinqISJ+hiTWm7wEqoJdI9JEV9JChAEkS3xCZzKecLcgN6YwlRBhAGmweTsblg6qKMM7Vmh321UQ4QAp1VfwhqVJIh+Wm03W0qV0EOEAybXtivkCmWrKeH2EZ/xBaSBCV2L9Re+LYSqJJIxDu1ew07U0EGEBcTtmHty4JuPtQhvLh1BAhK7Uvvq0GK484QZST0GvvFDqeSJ1IA0r2mfDljvqBoJ//rVsq7yZCA6kXgVkJ2f4ijIGMjOfMVsCBBORB2Jy+sM6ijNvaBUqmw/cStZ8EiKciHwp6Rp++88qmxXQeTUxDiJWJ9wSISvBicgXW+dypn1PqWTznlwgwdZdfiLHr5OELEAEASKvJFRE5JCPKbh8OxHdQKJU0crEzRXrJ/IEkFms6tGyrUw9kQeALFRXvK2iSzsRAAi6BLxM+60xdsqJAEBuXMAMxDLVp+gmAgC57/UT4qvVj3TVRCAgSAYL91aXtyNLzUQAIFhAiP8m0/NHOp+ILiBtPFKrs6bgSOcT0QTEB8nO3QR1yKslggKRf+m11UB0HOl8IlqAeCvauXuo8HnfIqIDyCw6G8XMcGiplMingMzCnbuHFp/3LSLPA4nUpqm5YkWNzwsQeQxIDsKjH5wVSU5qJPIJIIt4jjpqNBAekQeBfJOeHWS81FQoo4/I7UDcS3wUh0liTzLqiEgDqddx4ZHDrNZAACIAEMw88HPYWb0GAhABgEDmgf9Vb5oNBCByOxD3uqWYbCHVBgIQuRlIsbfwMEG5gQBE7gSyHMDsOayrxJvHBRC5B0hOxJH1nK4SlUE6QOR+IG6ju3iYQEqDdIDIzUDyZu/jMRHpS/OiRG4FkiPRfTw8kbrvIAJEACAIDpyHC1/GQHhEbgKSXwTyqIeEur6kixEBgABHOTr7YSX1MSFAhA0E307wUU76Y0KACAsI/tvCRzkF+iIuL0AEAYLbR2QOfvhKJ/obRESBxNt5rPSFXN4f7dyNdqMgEIbhAXWwJErT/e7/Wreb5HTT07QVgWSAeW5g7b4n8qOSUCRPEId4HP93SXp5dDNGRJFcQTxihSH+NW1Bb1cXKpIryJAwnG/zhl8ZcSP6jiKZghwRaaWLnP/AkcSKKJIniEcUs8QfjFLdEmRvkSxB4lfn0QN6DY+lshQpHiT96Dlr6r5hxRUpHST9ZEY71X7DOmOZQVZLsd5Q8wzrPxYYJDiKNqOBG1ZCkZKzrNXu6lHvkjChSFqQsdTPg45ApXtYaUXKr9TNuPcvqO2pVMkitFXAL2a79/qr3HQvVSTXUtofCl79RDXh5CDpw3pwu6+9kRlvtiI5VtPhmHLltT4EKVQkfb8pcOHrXqk6nBAksUjgpKtuYsskaxGKYT0+84uYgziE4YQgMdx0m8PRfis2MbL33PMXoVjD6PEunI4HSjDjStiJP08vQk9hZzQ7oH/geoLYCUBDW4rf4FqCDFt7THUO6B+4jiDn2XNTW7zf4hqCMND4BOsGyw+yAmh0x+QeFh7EeqD5Ce8nLDrI8NpbDyIWHIQNruo4GyAPlhrEzuixBxHLDDJMnfYgYolBricHNfjIdgMWF+Qyu+pkgX4HCwuymL57ELGkIHZG7z2IWE6Q5VV7vGMhQewbtMcZiwhyHj26ne9+xs8PcvDQHnFFqCD7Au0RW4TK+fOKqw4eoOcqYqgU53HR3/5uShFPCfKey9hFDyJO/vAi7RDZnp7X5igyUH72xSDW1E2Pn4tMRCQgR8vLwbgii4gcmLvqQcSPGtIPX3M08wn6I4qYQ94cM/Yw9Xxhmw+X/59wHrtMlX1AmIkzdyaaAnLg1Nnw8WGYSk40X/BOh4+El6LMSBnN2Cd0tPq4w/LJXGrMbCX06PZ2dcM65yzlNertShSHf3SzRAyPM332IcSAHUKPi8EHmXU0l8Uglmni0yipDoi16s+jJKejhywLooz68yiMEcHr2qM4h81CJ++VPJfTu5UwBpv4Pp9DJSi6MJx0bvUwiw4ewgT8zNR0LHUL+OccOpY/3ElzyGKD5pBlMJpDlsOkMythRoNbXh95PJsdA67MrMtAEYbjeDqNo+7oKqWUUkoppZRSSimllFJKFfMXp4vmSjB8n6sAAAAASUVORK5CYII="),tf.IMAGE}dispose(){super.dispose(),this.started=!1,delete this._audio}async ready(){super.ready(),this._audio=new Audio,this._audio.addEventListener("canplay",()=>{this.started&&this._audio.play()});const{src:t="",loop:e=!1,started:n=!1}=this.state;this.onchangeSrc(t),this.onchangeLoop(e),this.onchangeStarted(n)}render(t){const{left:e,top:n,width:r,height:i}=this.state;t.beginPath(),this.drawImage(t,tf.image,e,n,r,i)}get nature(){return Jp}get hasTextProperty(){return!1}get src(){return this.get("src")}set src(t){this.set("src",t)}get started(){return!!this.get("started")}set started(t){this.set("started",t)}start(){this._audio&&(this._audio.classList.add("active"),this._audio.play())}pause(){this._audio&&(this._audio.classList.remove("active"),this._audio.pause())}onchangeSrc(t){try{"data"!==String(t).substring(0,4)?this._audio.crossOrigin="use-credentials":this._audio.crossOrigin=null,this._audio.src="string"==typeof t?this.app.url(t):t}catch(t){return void Wr(t)}}onchangeStarted(t){const e=this._audio;t?4==e.readyState&&e.play():e.pause()}onchangeLoop(t){this._audio.loop=t}onchange(t,e){"src"in t&&this.onchangeSrc(t.src),"started"in t&&this.onchangeStarted(t.started),"loop"in t&&this.onchangeLoop(t.loop)}ondblclick(t){this.started=!this.started}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("audio/"))return void(this.src=e[n])}}tc.register("audio",tf);class ef extends(rc(tc)){is3dish(){return!0}}tc.register("text",ef);const nf=["refid","left","top","width","height","rotation","animation"];class rf extends pp{isGroup(){return!0}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=nf.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{});return super.set(n,void 0)}capture(t,e,n){const r=super.capture(t,e,n);if(r!==this)return r}set bounds(t){if(this.__MUTATING__)return void(super.bounds=t);const e=this.bounds,n=t.width/e.width,r=t.height/e.height;this.path=this.path.map(i=>({x:t.left+(i.x-e.left)*n,y:t.top+(i.y-e.top)*r})),this.components&&this.components.forEach(t=>{if(t.mutable)t.mutatePath(null,function(t){return t.map(function(t){return{x:t.x*n,y:t.y*r}})});else{const e=t.bounds,i=t.center,s={x:i.x*(1-n),y:i.y*(1-r)},o=e.width*(1-n),a=e.height*(1-r),c=-(s.x-o/2),l=-(s.y-a/2);t.bounds={left:e.left+c,top:e.top+l,width:e.width*n,height:e.height*r}}})}get focusible(){return!1}get bounds(){return super.bounds}get hasTextProperty(){return!1}isIdentifiable(){return!1}calculateBounds(){this.clearCache(),this.__MUTATING__=!0,this.mutateBounds(function(t){const e=tc.union(this.components.map(t=>t.bounds));return this.components.forEach(t=>{const n=t.bounds;t.bounds={left:n.left-e.left,top:n.top-e.top,width:n.width,height:n.height}}),{left:t.left+e.left,top:t.top+e.top,width:e.width,height:e.height}},this),this.__MUTATING__=!1,this.parent.isGroup()&&this.parent.calculateBounds?.()}render(t){}postrender(t){const{top:e,left:n}=this.state;t.translate(n,e),this.layout.drawables(this).forEach(e=>{e.draw(t)}),t.translate(-n,-e)}}tc.memoize(rf.prototype,"bounds",!0),tc.register("group",rf);const sf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"id-input",label:"ref",name:"ref"},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio"]}}],"value-property":"ref",help:"scene/component/local-ref"};class of extends(rc(ec)){get ref(){const t=this.getState("ref");return t&&"string"==typeof t?this.root.findById?.(t):null}set ref(t){this.setState("ref",t)}get refScale(){const t=this.ref;if(!t)return{x:1,y:1};const e=t.bounds,n=this.bounds,r=n.width/e.width,i=n.height/e.height;return"both"===this.model.fit?{x:r,y:i}:{x:Math.min(r,i),y:Math.min(r,i)}}draw(t){this._drawing||(this._drawing=!0,super.draw(t),this._drawing=!1)}prerender(t){if(super.prerender(t),this.ref){const e=this.ref.center,n=this.center,r=this.refScale;t.translate(n.x,n.y),t.scale(r.x,r.y),t.translate(-e.x,-e.y)}}postrender(t){if(this.ref)return this.ref.postrender(t);super.postrender(t)}render(t){if(this.ref)return this.ref.render(t);const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),t.rect(e,n,r,i)}get nature(){return sf}get hasTextProperty(){return!1}}tc.memoize(of.prototype,"ref",!1),tc.memoize(of.prototype,"refScale",!1),tc.register("local-ref",of);class af extends(cp(Tc)){render(t){}is3dish(){return!0}get layout(){return lc.get(this.get("layout"))||hc}}const cf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"scene-number",name:"ref",placeholder:"SCENE-1"},{type:"number",label:"round",name:"round",property:{min:0}},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio","width","height","none"]}},{type:"select",label:"mode",name:"mode",property:{options:["view","interaction"]}}],"value-property":"ref",help:"scene/component/global-ref"};class lf extends af{dispose(){this._releaseRef(),super.dispose()}get nature(){return cf}get hasTextProperty(){return!1}get tagName(){return"div"}setElementProperties(t){const{mode:e="view",round:n=0}=this.state;t.style.pointerEvents="view"==e?"none":"inherit",t.style.borderRadius=n+"px"}async ready(){super.ready(),this.fetchRef()}reposition(){if(!this.element)return;super.reposition();const t=this._element_bounds,{offsetWidth:e,offsetHeight:n}=this.element;if(this._element_bounds={offsetWidth:e,offsetHeight:n},(!t||t.offsetWidth!=e||t.offsetHeight!=n)&&this.ref&&this.root.target_element){const{fit:t="ratio"}=this.state;this.ref.fit(t)}}async fetchRef(){this._releaseRef();const{ref:t,fit:e="ratio"}=this.state;if(!t)return;const n=this.app.refProvider;if(n&&t)try{this.__ref=await n.get(t,!0),this.__ref.target=this.element,this.__ref.fit(e),this.__ref.data=this.data}catch(t){Wr(t)}}get ref(){return this.__ref}set ref(t){this.setState("ref",t)}_releaseRef(){this.__ref&&this.__ref.release&&this.__ref.release(),delete this.__ref}onchange(t,e,n){super.onchange(t,e),"ref"in t&&this.fetchRef(),"fit"in t&&this.ref&&requestAnimationFrame(()=>{const{fit:t}=this.state;this.ref.fit(t)}),"data"in t&&this.ref&&requestAnimationFrame(()=>{this.ref.data=t.data})}}tc.register("global-ref",lf);const hf="center-middle",df={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"board",name:"board"},{type:"checkbox",label:"modal",name:"modal"},{type:"checkbox",label:"closable",name:"closable"},{type:"checkbox",label:"draggable",name:"draggable"},{type:"checkbox",label:"minimizable",name:"minimizable"},{type:"checkbox",label:"show",name:"show"},{type:"select",label:"popup-position",name:"popupPosition",property:{options:["static","absolute"]}},{type:"select",label:"popup-origin",name:"origin",property:{options:["left-top","center-top","right-top","left-middle",hf,"right-middle","left-bottom","center-bottom","right-bottom","auto"]}},{type:"string",label:"title",name:"text"},{type:"data",label:"value",name:"value"}],help:"scene/component/popup"};class uf extends(rc(ec)){static get image(){return uf._image||(uf._image=new Image,uf._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAMAAABG8BK2AAADJmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNy4xLWMwMDAgNzkuZGFiYWNiYiwgMjAyMS8wNC8xNC0wMDozOTo0NCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIzLjAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RkM4QzQxNUMzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RkM4QzQxNUQzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpENjlENTQ3RjMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpENjlENTQ4MDMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsiUYSQAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAA51BMVEVHcEwzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzOguTm2AAAATHRSTlMARhB73r9B7YLrsqdE+0cq9Avzeg31eQx4aQ+Ks6aUd5DsYKixEX1w8vyT2VjoZ3YezY/cCEDvl+QTvRwJ0ifwK/5T/aw6+IuFuCImAcS6MQAAAeJJREFUWMPt2FlX2zAQhuHJYmOSFhIggbC0QNn3rS1dKXSH9///Hi58CJLxKIpEWi6YO8c5z4lG/nxGEXmu/1OVLGnhrFaSVQYg1SZetTTvUibqeFZ9QlfmvRWoV1VmCaCRzroXPpsuAjTV7gLUfPahBqD1OQMW/fazAWTKvQRI/ZgUSJR7U8CM/dHZ+/2VcatWdvdEZAaYUhiAwkerJXt0rnzXwdRKmHfDM0fHD5kxjTFyVLzVfvvirn7+cDJWjhy7c7XlYuwc6Urvu2tRhRypyhwAf1sKY+TIxfQA+H39q5wxc+RgVrcBduTmZTlj5khnDgH4IzKpMGaOVCbvyyvRGTNHGtPrKypjXirM5jb910I4k69oQeKY+77EMAcALEsck/+W6f71tyCma/ZFROTrJVwMy7wmf3bv6/MX+Dgkkysblvxps/dhOKZb6IvrTakzXXuPApnpYneDGOeKvJlaSXcDmA7AicQyW84VeTOnY+NdiWcG1uiZksFEHdyAlsJEjEkmkwGNsKHNZCJGSKtVTYC1tO022mnjwUBrMdXg8dreuOBhv7D/62/8lGZ1wLxXyZKOm+iUHIQintyny0TkaATHjYgcjeAoFpEje9R/nGPqIx2aw3NU9odCQI6e6x/VLY32cKQXVBnkAAAAAElFTkSuQmCC"),uf._image}async ready(){await super.ready(),this.show&&this.onchangeShow(!0)}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),this.drawImage(t,uf.image,e,n,r,i)}onchange(t,e){"value"in t?this.show?this.onchangeShow(!0):this.show=!0:"show"in t&&this.onchangeShow(this.show)}onchangeShow(t){!this.app.isEditMode&&this.getState("board")&&(t?this.openPopup(this.value):this.hidePopup())}openPopup(t,e){this.app.isEditMode||kc.show(this,this.getState("board"),{origin:this.getState("origin")||hf,modal:this.getState("modal"),closable:this.getState("closable")||!1,draggable:this.getState("draggable")||!1,minimizable:this.getState("minimizable")||!1,popupPosition:this.getState("popupPosition"),title:this.text,data:t||this.value,...e})}hidePopup(){kc.hide(this)}get board(){return this.getState("board")}set board(t){this.set("board",t)}get show(){return this.getState("show")}set show(t){this.setState("show",t)}get started(){return this.getState("show")}set started(t){this.setState("show",t)}get value(){return this.getState("value")}set value(t){this.setState("value",t)}get hasTextProperty(){return!1}get nature(){return df}}tc.register("popup",uf);class pf extends tc{render(t){const{path:e=[]}=this.state;if(!(e.length<=1)){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)t.lineTo(e[n].x,e[n].y);t.closePath(),this.drawStroke(t,void 0)}}get path(){return this.model.path}set path(t){this.set("path",t)}contains(t,e){const n=this.state.path;let r=!1;return n.forEach((i,s)=>{const o=(s+n.length+1)%n.length,a=i.x,c=i.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(r=!r)}),r}}tc.register("path",pf);const ff={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/triangle"};class gf extends ec{is3dish(){return!0}contains(t,e){const{x1:n,y1:r,x2:i,y2:s,x3:o,y3:a}=this.state,c=[n,r,i,s,o,a];let l=!1;for(let n=0;n<c.length;n+=2){const r=(n+2)%c.length,i=c[n],s=c[n+1],o=c[r+1];s>e!=o>e&&t<(c[r]-i)*(e-s)/(o-s)+i&&(l=!l)}return l}get mutable(){return!0}get path(){const{x1:t,y1:e,x2:n,y2:r,x3:i,y3:s}=this.state;return[{x:t,y:e},{x:n,y:r},{x:i,y:s}]}set path(t){this.set({x1:t[0].x,y1:t[0].y,x2:t[1].x,y2:t[1].y,x3:t[2].x,y3:t[2].y})}get nature(){return ff}}tc.memoize(gf.prototype,"path",!1),tc.register("triangle",gf);const mf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"}],help:"scene/component/donut"},yf={ondragmove:function(t,e,n){let{cx:r,rx:i}=n.model;i=Math.abs(i);let s=(n.fromParent(t.x,t.y).x-r)/i*100;s=s>=100||s<=-100?100:Math.abs(s),n.set({ratio:s})}};class bf extends Pp{is3dish(){return!0}render(t){let{ratio:e=50,cx:n,cy:r,rx:i,ry:s,startAngle:o,endAngle:a,anticlockwise:c}=this.state;i=Math.abs(i),s=Math.abs(s),t.beginPath(),t.ellipse(n,r,i,s,0,o||0,a||2*Math.PI,c),t.moveTo(n+i/100*e,r),t.ellipse(n,r,i/100*e,s/100*e,0,o||0,a||2*Math.PI,!0)}contains(t,e){let{cx:n,cy:r,rx:i,ry:s,ratio:o}=this.state;i=Math.abs(i),s=Math.abs(s);const a=(t-n)/(2*i-.5),c=(e-r)/(2*s-.5),l=(t-n)/(i/100*o*2-.5),h=(e-r)/(s/100*o*2-.5);let d=!1;return a*a+c*c<.25&&l*l+h*h>.25&&(d=!d),d}get controls(){let{cx:t,cy:e,rx:n,ratio:r}=this.state;return n=Math.abs(n),[{x:t+n/100*r,y:e,handler:yf}]}get nature(){return mf}}tc.memoize(bf.prototype,"controls",!1),tc.register("donut",bf);const vf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"},{type:"number",label:"wing",name:"wing",property:"wing"}],help:"scene/component/star"},xf={ondragmove:function(t,e,n){const{cy:r,ry:i}=n.model;let s=(n.fromParent(t.x,t.y).y-r)/i*100+100;s>=100?s=100:s<=0&&(s=0),n.set({ratio:s})}};class _f extends Pp{is3dish(){return!0}render(t){const{ratio:e=30,wing:n=5,cx:r,cy:i,rx:s,ry:o}=this.state;if(n<3)return;const a=1.5707963267948966,c=2*Math.PI/n,l=s-e/100*s,h=o-e/100*o;t.save(),t.beginPath(),t.translate(r,i),t.moveTo(s*Math.cos(-a),o*Math.sin(-a)),t.lineTo((s-l)*(Math.cos(c-a)+Math.cos(0-a))/2,(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let e=1;e<n;e++)t.lineTo(s*Math.cos(c*e-a),o*Math.sin(c*e-a)),t.lineTo((s-l)*(Math.cos(c*(e+1)-a)+Math.cos(c*e-a))/2,(o-h)*(Math.sin(c*(e+1)-a)+Math.sin(c*e-a))/2);t.closePath(),t.restore()}get controls(){const{cx:t,cy:e,ry:n,ratio:r}=this.state;return[{x:t,y:e-n+n*(r/100),handler:xf}]}get nature(){return vf}}tc.memoize(_f.prototype,"controls",!1),tc.register("star",_f);const wf={mutable:!1,resizable:!1,rotatable:!1,properties:[]};class Mf extends(Md(ec)){is3dish(){return!1}isDescendible(){return!1}render(t){const{cx:e,cy:n,anticlockwise:r}=this.state,i=this.app?.scale||1;t.beginPath(),t.scale(1/i,1/i),t.ellipse(e,n,Math.abs(Mf.RADIUS),Math.abs(Mf.RADIUS),0,0,2*Math.PI,r),t.scale(i,i),t.closePath()}get path(){const{cx:t,cy:e}=this.state;return[{x:t-Mf.RADIUS,y:e-Mf.RADIUS},{x:t+Mf.RADIUS,y:e-Mf.RADIUS},{x:t+Mf.RADIUS,y:e+Mf.RADIUS},{x:t-Mf.RADIUS,y:e+Mf.RADIUS}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:r}=this.state,i=(t-n)/(2*Mf.RADIUS-.5),s=(e-r)/(2*Mf.RADIUS-.5);return i*i+s*s<.25}outline(t){const{cx:e,cy:n}=this.state;return this.toScene(e,n)}get nature(){return wf}}function Sf(t){return class extends t{animOnValueChange(t,e=!1,n){if(t==this._lastValue)return;let r;r=e?t-(Number(n)||0):t-(this._lastValue||0),this._lastValue=t,this._anim_alpha=-r,this.animate({step:t=>{this._anim_alpha=r*(t-1),this.invalidate()},duration:1e3,delta:"circ",options:{x:1},ease:"out"}).start()}dispose(){super.dispose(),delete this._value_substitutor}onchange(t,e){t.hasOwnProperty("value")&&delete this._value_substitutor}get animAlpha(){return this._anim_alpha||0}get animValue(){return(this._lastValue||0)+(this._anim_alpha||0)}defaultValueSubstitutor(){return this.getState("value")}get valueSubstitutor(){return this._value_substitutor||(this._value_substitutor=Ds(this.getState("value"),this,void 0)||this.defaultValueSubstitutor),this._value_substitutor}get value(){return Number(this.valueSubstitutor())||0}set value(t){delete this._value_substitutor,this.setState("value",Number(mr(t)))}}}function Af(t){return class extends t{_convertDataFormat(t,e){let n;if("json"===e)n=JSON.parse(t);else n=t;return n}isDataSource(){return!0}}}function kf(t){return function(e){return Array.isArray(t)?t.forEach(t=>{tc.register(t,e)}):tc.register(t,e),e}}Mf.RADIUS=5,tc.memoize(Mf.prototype,"path",!1),tc.register("node",Mf);let Ef=0;const Cf=new FinalizationRegistry(()=>{Ef--});class Pf{static get residents(){return Ef}static get residentsCount(){return Ef}constructor(t,e){this.counters={},this.references={},this.creator=t,this.disposer=e,Ef++,Cf.register(this,Ef)}dispose(){if(this.disposer)for(const t in this.references)this.disposer(t,this.references[t]);this.references={},this.counters={}}get ids(){return Object.keys(this.references)}create(t){return new Promise((e,n)=>{this.creator?this.creator(t,n=>{n.release=()=>{this.disposer?.(t,n),delete n.release,qr("RELEASED",t)},e(n)},n):n(Error("Reference id("+t+") could not be created. Reference creator should be defined."))})}add(t,e){const n=new Promise((n,r)=>{const i=this.references[t];if(i)i===e?r(Error("Reference ID and target duplicate")):e?r(Error("Reference ID duplicate")):n(i);else{const i=e=>{e.release=()=>{this.release(e)},this.references[t]=e,this.counters[t]=1,n(e)};if(e)i(e);else{if(!this.creator)return void r(Error("Reference id("+t+") is not allowed. Reference creator should be defined."));this.creator(t,i,r)}}});return this.references[t]||(this.references[t]=n),n}async get(t,e=!1){let n=this.references[t];if(n){if(!(n instanceof Promise)){if(!(t in this.counters))throw new Error("No Reference Count");return this.counters[t]++,n}if(e)return n=await n,this.counters[t]++,n}if(e)return await this.add(t);throw new Error("No References for "+t)}_id(t){for(const e in this.references){if(this.references[e]===t)return e}}release(t){const e=this._id(t);if(!e)return void Wr("No Referenced ID");const n=this.references[e];n&&(this.counters[e]--,0==this.counters[e]&&(this.disposer?.(e,n),delete this.references[e],delete this.counters[e],delete t.release,qr("RELEASED",e)))}}const Tf={},Of={};let Df=[];function If(t){const e=t.target,n="SCRIPT"===e.tagName?Tf:Of,r=e.src||e.href;n[r]=!0,Df.forEach((t,e)=>{if(!t)return;const{resolve:i,scripts:s,styles:o}=t;if(n===Tf){const t=s.indexOf(r);t>-1&&t<s.length-1&&Lf(s[t+1])}s.some(t=>!Tf[t])||o?.some(t=>!Of[t])||(i(),Df[e]=null)}),Df=Df.filter(Boolean)}function zf(t){if("string"==typeof t)return;const e=t.target,n=e.src,r="SCRIPT"===e.tagName?Tf:Of;Df.forEach((e,i)=>{if(!e)return;const{reject:s,scripts:o,styles:a}=e;(r===Tf&&o.includes(n)||r===Of&&!!a?.includes(n))&&(s(t),Df[i]=null)}),Df=Df.filter(Boolean),delete r[n],document.head.removeChild(e)}function Lf(t){Tf[t]=!1;const e=document.createElement("script");e.onload=If,e.onerror=zf,e.type="text/javascript",e.src=t,document.head.appendChild(e)}class jf{static load(t,e){const n="string"==typeof t?[t]:t,r="string"==typeof e?[e]:e;return new Promise(function(t,e){if(n&&!Array.isArray(n)||r&&!Array.isArray(r))return void e(new Error("invalid sources for load"));let i,s=!0;if(r?.forEach(t=>{t in Of||function(t){Of[t]=!1;const e=document.createElement("link");e.onload=If,e.onerror=zf,e.type="text/css",e.rel="stylesheet",e.media="screen,print",e.href=t,document.head.appendChild(e)}(t),Of[t]||(s=!1)}),n&&n.length>0)for(const t of n)t in Tf?Tf[t]||(s=!1):i??=t;if(i)Lf(i);else if(s)return void t();Df.push({resolve:t,reject:e,scripts:n,styles:r})})}}const Rf="0.0.0";class Ff extends Rh{getObject3dInstance(){return new e.Sprite}build(){super.build(),this.buildMaterial()}get cz(){const{zPos:t=0}=this.component.state,{height:e}=this.component.bounds,{tz:n=0}=this.component.delta();return t+n+e/2}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=Rh.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(_h(t)):e.opacity=0)}}function Bf(t){if(!(t>0))return 1;let e=0;if(!(t&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function Nf(t){const{lineWidth:n=0}=t.state;let{width:r,height:i}=t.bounds;r+=n,i+=n;const s=Bf(2*r),o=Bf(2*i),a=ph(s,o),c=new e.CanvasTexture(a);return Yf(a,t,2),c.needsUpdate=!0,c.wrapS=e.RepeatWrapping,c.wrapT=e.RepeatWrapping,c.offset.set(0,1-2*i/o),c.repeat.set(2*r/s,2*i/o),c.magFilter=e.NearestFilter,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace,c}function Yf(t,e,n){const{lineWidth:r=0}=e.state;let{left:i,top:s}=e.bounds;i-=r/2,s-=r/2;const o=t.getContext("2d");o.scale(n,n),o.translate(-i,-s),e.render(o),e.postrender(o)}class Vf extends Ff{buildMaterial(){const t=this.object3d.material;t&&t.dispose(),this.object3d.material=new e.SpriteMaterial({map:Nf(this.component),alphaTest:.01,sizeAttenuation:!1})}get scale(){const{width:t,height:e}=this.component.bounds,n=this.threeContainer,{width:r=1,height:i=1}=n?.bounds??{},{scale:s=1}=this.component.state;return{x:s*t/r,y:s*e/i,z:s}}update(){this.build(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateAlpha(){this.update()}updateText(){this.update()}}class Gf extends Rh{get syncZPosOffset(){return this.effectiveDepth}getObject3dInstance(){return new e.Mesh}build(){super.build();const t=Eh(this.component.state.material3d),n=new e.PlaneGeometry(1,1);n.rotateX(-Math.PI/2),this.object3d.geometry=n;const r=Nf(this.component);this.object3d.material=new e.MeshStandardMaterial({map:r,transparent:!0,alphaTest:.01,side:e.DoubleSide,metalness:t.metalness,roughness:t.roughness,emissive:new e.Color(t.emissive),emissiveIntensity:t.emissiveIntensity}),this.object3d.castShadow=t.castShadow,this.object3d.receiveShadow=t.receiveShadow}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateDimension(){const{width:t,height:e}=this.component.bounds;this.object3d.scale.set(t,1,e)}update(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateText(){this.update()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Eh(this.component.state.material3d);t.metalness=e.metalness,t.roughness=e.roughness,t.emissive.set(e.emissive),t.emissiveIntensity=e.emissiveIntensity}clear(){return Ih(this.object3d),super.clear()}}class Hf extends Rh{getObject3dInstance(){return new e.Mesh}build(){super.build(),this.buildGeometry(),this.buildMaterial()}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=Rh.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(_h(t)):e.opacity=0)}updateStrokeStyle(){const t=this.object3d.getObjectByName("__edgeLines__");t&&(this.object3d.remove(t),Ih(t));const{strokeStyle:n}=this.component.state;if(!n||"transparent"===n||"none"===n)return;const r=this.object3d.geometry;if(!r?.getAttribute("position"))return;const i=new e.EdgesGeometry(r),s=new e.LineBasicMaterial({color:n}),o=new e.LineSegments(i,s);o.name="__edgeLines__",this.object3d.add(o)}updateDimension(){const{width:t,height:e}=this.component.bounds,{depth:n=1}=this.component.state;if(!this.object3d)return;this.object3d.geometry.computeBoundingBox();const r=this.object3d.geometry.boundingBox;if(r){const i=r.max.x-r.min.x,s=r.max.y-r.min.y,o=r.max.z-r.min.z;this.object3d.scale.set(t/i,n/s,e/o)}}buildMaterial(){const t=Eh(this.component.state.material3d),n=new e.MeshStandardMaterial({transparent:!0});Th(n,t),this.object3d.material=n}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;t&&Th(t,Eh(this.component.state.material3d))}clear(){return Ih(this.object3d),super.clear()}}function Uf(t,e,n,r){return[["bold",t],["italic",e],[n+"px",!0],[r,!0]].filter(t=>t[1]).map(t=>t[0]).join(" ")}function Wf(t){let e=0;if(!((t=Math.abs(t)||1)&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function Xf(t,e,n){const{bold:r=!1,italic:i=!1,fontFamily:s="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",width:h=t.width,height:d=t.height}=n||{},u=t.getContext("2d");let p,f;u.imageSmoothingEnabled=!1,u.fillStyle=a,u.strokeStyle=a,u.font=Uf(r,i,o,s),"left"===c||"start"===c?(u.textAlign="left",p=0):"right"===c||"end"===c?(u.textAlign="right",p=h):(u.textAlign="center",p=h/2);const g=1.2*o,m=String(e).split("\n"),y=g*m.length;f="top"===l||"hanging"===l?.1*o:"bottom"===l||"alphabetic"===l?d-y+.1*o:(d-y)/2+.1*o,u.textBaseline="top";for(const t of m)u.fillText(t,p,f),f+=g}function qf(t,n,r,i){const s=Wf(2*n),o=Wf(2*r),a=ph(s,o),c=a.getContext("2d"),{fillStyle:l}=i||{};if(l&&"object"==typeof l&&l.colorStops?.length){const t=zh(l,2*n,2*r);t&&c.drawImage(t,0,0)}c.scale(2,2),"string"==typeof l&&""!==l&&"transparent"!==l&&(c.fillStyle=l,c.fillRect(0,0,n,r)),Xf(a,t,i);const h=new e.CanvasTexture(a);return h.needsUpdate=!0,h.wrapS=e.RepeatWrapping,h.wrapT=e.RepeatWrapping,h.offset.set(0,1-2*r/o),h.repeat.set(2*n/s,2*r/o),h.minFilter=e.LinearFilter,h.colorSpace=e.SRGBColorSpace,h}function Kf(t,n,r,i,s,o,a){const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const t=2*r,l=2*i,h=Wf(t),d=Wf(l),u=ph(h,d),p=u.getContext("2d");if(o.color&&(p.fillStyle=o.color,p.fillRect(0,0,t,l)),o.fitPattern)p.drawImage(c,0,0,t,l);else{const e=2*(o.width||c.naturalWidth),n=2*(o.height||c.naturalHeight),r=2*(o.offsetX||0),i=2*(o.offsetY||0);let s=0,a=0;switch(o.align){case"center":s=(t-e)/2,a=(l-n)/2;break;case"left-top":break;case"left-bottom":a=l-n;break;case"right-top":s=t-e;break;case"right-bottom":s=t-e,a=l-n;break;case"left":a=(l-n)/2;break;case"right":s=t-e,a=(l-n)/2;break;case"top":s=(t-e)/2;break;case"bottom":s=(t-e)/2,a=l-n}const h=r+s,d=i+a;if(o.noRepeat)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,h,d,e,n);else{p.save(),p.rect(0,0,t,l),p.clip();const r=h>0?h-Math.ceil(h/e)*e:h;for(let i=d>0?d-Math.ceil(d/n)*n:d;i<l;i+=n)for(let s=r;s<t;s+=e)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,s,i,e,n);p.restore()}}n&&(p.scale(2,2),Xf(u,n,s));const f=new e.CanvasTexture(u);f.needsUpdate=!0,f.wrapS=e.RepeatWrapping,f.wrapT=e.RepeatWrapping,f.offset.set(0,1-l/d),f.repeat.set(t/h,l/d),f.minFilter=e.LinearFilter,f.colorSpace=e.SRGBColorSpace,a(f)},c.onerror=()=>{const t=qf(n,r,i,s);a(t)},c.src=t}function $f(t,e){let{bold:n=!1,italic:r=!1,fontFamily:i="Serif",fontSize:s=10,lineHeight:o="normal"}=e||{};t=void 0===t||""==t?" ":String(t);const a=document.createElement("span");a.style.font=Uf(n,r,s,i),a.style.lineHeight=String(o),a.style.whiteSpace="pre",a.style.position="absolute",a.textContent=t,document.body.appendChild(a);const c=a.getBoundingClientRect();return document.body.removeChild(a),{width:c.width,height:c.height}}class Qf extends Hf{get syncZPosOffset(){return this.effectiveDepth}buildGeometry(){this.updateDimension()}updateStrokeStyle(){}updateFillStyle(){this.updateText()}updateDimension(){const{width:t,height:n}=this.component.state,r=Math.abs(t)||1,i=Math.abs(n)||1;this.object3d.geometry&&this.object3d.geometry.dispose();const s=new e.PlaneGeometry(r,i);s.rotateX(-Math.PI/2),this.object3d.geometry=s}updateText(){const t=this.object3d.material;if(!t)return;const{width:e,height:n,bold:r=!1,italic:i=!1,fontFamily:s="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",fillStyle:h}=this.component.state,d=Math.abs(e)||1,u=Math.abs(n)||1,p=this.component.text,f=h&&"none"!==h?h:"transparent",g={bold:r,italic:i,fontFamily:s,fontSize:o,fontColor:a,textAlign:c,textBaseline:l,width:d,height:u,fillStyle:f};if("object"==typeof f&&"pattern"===f?.type&&f.image){return void Kf(this.component.app.url(h.image),p,d,u,g,h,e=>{t.map&&t.map.dispose(),t.map=e,t.color.set(16777215),t.needsUpdate=!0})}const m=qf(p,d,u,g);m?(t.map&&t.map.dispose(),t.map=m,t.color.set(16777215),m.needsUpdate=!0):"string"==typeof h&&(""!==h&&"transparent"!==h?t.color.set(_h(h)):t.opacity=0)}updateAlpha(){const{alpha:t=1}=this.component.state,e=this.object3d.material;e.opacity=t,e.transparent=!0}}Yh("text",t=>new Qf(t));class Zf extends Rh{get syncZPosOffset(){return this.effectiveDepth}getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds;if(!t||!n)return;const r=Eh(this.component.state.material3d),i=new e.PlaneGeometry(1,1);i.rotateX(-Math.PI/2),this.object3d.geometry=i;const s=Nf(this.component);this.object3d.material=new e.MeshStandardMaterial({map:s,transparent:!0,side:e.DoubleSide,metalness:r.metalness,roughness:r.roughness,emissive:new e.Color(r.emissive),emissiveIntensity:r.emissiveIntensity}),this.object3d.castShadow=r.castShadow,this.object3d.receiveShadow=r.receiveShadow}updateDimension(){const{width:t,height:e}=this.component.bounds;this.object3d.scale.set(t,1,e)}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;xh(this.object3d.material,t,e)}updateHidden(){this.object3d.visible=!this.component.state.hidden}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this._rebuildTexture()},100)}_rebuildTexture(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Eh(this.component.state.material3d);t.metalness=e.metalness,t.roughness=e.roughness,t.emissive.set(e.emissive),t.emissiveIntensity=e.emissiveIntensity}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),Ih(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),super.dispose()}}const Jf={input:"css3d",select:"css3d",textarea:"css3d",button:"css3d",iframe:"css3d",video:"css3d",label:"texture",table:"texture",progress:"texture"};function tg(t){const e=function(t){const e=t.state?.material3d?.renderMode;if("css3d"===e||"texture"===e)return e;const n=t.model?.type??"";return Jf[n]??"css3d"}(t);return"texture"===e?new Zf(t):new Fh(t)}Yh("html-overlay-element",tg),Yh("html-overlay-container",tg);class eg{setShape({extrudedShape:t,extrudedOptions:n}){this.extrudedShape=t,this.bb=new e.Box2,this.bb.setFromPoints(this.extrudedShape?.extractPoints(0).shape),this.extrudedOptions=n}generateTopUV(t,n,r,i,s){const o=n[3*r],a=n[3*r+1],c=n[3*i],l=n[3*i+1],h=n[3*s],d=n[3*s+1],u=this.bb,p=u.max.x-u.min.x,f=u.max.y-u.min.y;return[new e.Vector2((o-u.min.x)/p,1-(a-u.min.y)/f),new e.Vector2((c-u.min.x)/p,1-(l-u.min.y)/f),new e.Vector2((h-u.min.x)/p,1-(d-u.min.y)/f)]}generateSideWallUV(t,n,r,i,s,o){const a=n[3*r],c=n[3*r+1],l=n[3*r+2],h=n[3*i],d=n[3*i+1],u=n[3*i+2],p=n[3*s],f=n[3*s+1],g=n[3*s+2],m=n[3*o],y=n[3*o+1],b=n[3*o+2],v=this.extrudedOptions?.depth||100,x=this.bb,_=x.max.x-x.min.x,w=x.max.y-x.min.y;return Math.abs(c-d)<.01?[new e.Vector2(a/_,1-l/v),new e.Vector2(h/_,1-u/v),new e.Vector2(p/_,1-g/v),new e.Vector2(m/_,1-b/v)]:[new e.Vector2(c/w,1-l/v),new e.Vector2(d/w,1-u/v),new e.Vector2(f/w,1-g/v),new e.Vector2(y/w,1-b/v)]}}class ng extends Rh{clear(){return this._mesh=void 0,super.clear()}get shape(){return null}get boundUVGenerator(){return this._boundUVGenerator||(this._boundUVGenerator=new eg),this._boundUVGenerator}build(){super.build();const t=this.effectiveDepth,n=this.shape;if(!n)return;const r=this.boundUVGenerator;r&&r.setShape({extrudedShape:n,extrudedOptions:{depth:t}});const i=this.createGeometry(n),s=this.createMaterials();this._mesh=new e.Mesh(i,s),this._mesh.rotation.x=-Math.PI/2,this._mesh.rotation.y=-Math.PI,this._mesh.rotation.z=-Math.PI,this._mesh.castShadow=!0,this.object3d.add(this._mesh),this.updateFillStyle(),this.updateStrokeStyle()}createGeometry(t){const n=this.effectiveDepth,{lineWidth:r=0}=this.component.state,i={steps:1,depth:n,bevelEnabled:r>0,bevelThickness:0,bevelSize:r,bevelSegments:1,UVGenerator:this.boundUVGenerator},s=new e.ExtrudeGeometry(t,i);return s.center(),s}createMaterials(){const t=Eh(this.component.state.material3d),n=new e.MeshStandardMaterial;Th(n,t);const r=new e.MeshStandardMaterial;return Th(r,t),[n,r]}createTexture(){const{width:t,height:n}=this.component.bounds,r=Wf(t),i=Wf(n),s=ph(r,i);this.component.render(s.getContext("2d"));const o=new e.CanvasTexture(s);return o.needsUpdate=!0,o.wrapS=e.RepeatWrapping,o.wrapT=e.RepeatWrapping,o.offset.set(0,1-n/i),o.repeat.set(t/r,n/i),o.minFilter=e.LinearFilter,o}getMaterials(){if(!this._mesh)return;const t=this._mesh.material;return Array.isArray(t)?t:void 0}updateMaterial3d(){super.updateMaterial3d();const t=this.getMaterials();if(!t)return;const e=Eh(this.component.state.material3d);for(const n of t)Th(n,e)}updateAlpha(){const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,r=this.getMaterials();r&&(xh(r[0],t,e),xh(r[1],t,n))}updateStrokeStyle(){const t=this.getMaterials();if(!t)return;const{strokeStyle:e}=this.component.state;t[1].color.set(_h(e))}updateFillStyle(){this._applyCapTexture()}updateText(){this._applyCapTexture()}_applyCapTexture(){const t=this.getMaterials();if(!t)return;const e=t[0],{fillStyle:n}=this.component.state,r=this.component.hasTextProperty?this.component.text:"";if(!r){const t=Rh.buildFillStyleTexture(this.component);return t?(e.map&&e.map.dispose(),e.map=t,e.color.set(16777215)):(e.map&&(e.map.dispose(),e.map=null),e.color.set(_h(n))),void(e.needsUpdate=!0)}const{width:i,height:s,bold:o=!1,italic:a=!1,fontFamily:c="Serif",fontSize:l=10,fontColor:h="black",textAlign:d="center",textBaseline:u="middle"}=this.component.state,p=Math.abs(i)||1,f=Math.abs(s)||1,g={bold:o,italic:a,fontFamily:c,fontSize:l,fontColor:h,textAlign:d,textBaseline:u,width:p,height:f,fillStyle:n};if("object"==typeof n&&"pattern"===n?.type&&n.image){return void Kf(this.component.app.url(n.image),r,p,f,g,n,t=>{e.map&&e.map.dispose(),e.map=t,e.color.set(16777215),e.needsUpdate=!0})}e.map&&e.map.dispose();const m=qf(r,p,f,g);e.map=m,e.color.set(16777215),e.needsUpdate=!0}updateDimension(){super.updateDimension()}}class rg extends ng{get shape(){const{cx:t=0,cy:n=0,rx:r=1,ry:i=1,startAngle:s=0,endAngle:o=2*Math.PI,anticlockwise:a=!1}=this.component.state,c=new e.EllipseCurve(t,n,Math.abs(r),Math.abs(i),s,o,a,0);return new e.Shape(c.getPoints(50))}}Yh("ellipse",t=>new rg(t));class ig extends ng{get shape(){const{width:t,height:n,round:r}=this.component.state,i=new e.Shape;if(r>0){const e=r/100*(t/2);i.moveTo(e,0),i.lineTo(t-e,0),i.quadraticCurveTo(t,0,t,e),i.lineTo(t,n-e),i.quadraticCurveTo(t,n,t-e,n),i.lineTo(e,n),i.quadraticCurveTo(0,n,0,n-e),i.lineTo(0,e),i.quadraticCurveTo(0,0,e,0)}else i.moveTo(0,0),i.lineTo(t,0),i.lineTo(t,n),i.lineTo(0,n),i.lineTo(0,0);return i}}Yh("rect",t=>new ig(t));class sg extends ng{get shape(){const{path:t=[],round:n=0}=this.component.state,r=new e.Shape;for(let e=0;e<t.length;e++){const i=t[(e-1+t.length)%t.length],s=t[(e+t.length)%t.length],o=t[(e+1)%t.length];if(i.x===s.x&&i.y===s.y)continue;let a=Math.sqrt((i.x-s.x)*(i.x-s.x)+(i.y-s.y)*(i.y-s.y)),c=0!==a?Math.atan2(i.x-s.x,i.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==e?r.moveTo(d.x,d.y):r.lineTo(d.x,d.y),n>0&&r.quadraticCurveTo(s.x,s.y,u.x,u.y)}return r}get minMax(){if(!this._minMax){const{path:t}=this.component.state;let e,n,r,i;t.forEach((t,s)=>{if(0==s)return e=r=t.x,void(n=i=t.y);e=Math.min(e,t.x),r=Math.max(r,t.x),n=Math.min(n,t.y),i=Math.max(i,t.y)}),this._minMax={minX:e,minY:n,maxX:r,maxY:i}}return this._minMax}}Yh("polygon",t=>new sg(t));class og extends ng{get shape(){const{cx:t=0,cy:n=0,rx:r=1,ry:i=1,ratio:s=50,startAngle:o=0,endAngle:a=2*Math.PI,anticlockwise:c=!1}=this.component.state,l=Math.abs(r),h=Math.abs(i),d=new e.EllipseCurve(t,n,l,h,o,a,c,0),u=new e.Shape(d.getPoints(50)),p=l/100*s,f=h/100*s;if(p>0&&f>0){const r=new e.EllipseCurve(t,n,p,f,o,a,c,0),i=new e.Path(r.getPoints(50));u.holes.push(i)}return u}}Yh("donut",t=>new og(t));class ag extends ng{get shape(){const{x1:t=0,y1:n=0,x2:r=0,y2:i=0,x3:s=0,y3:o=0}=this.component.state,a=new e.Shape;return a.moveTo(t,n),a.lineTo(r,i),a.lineTo(s,o),a.closePath(),a}}Yh("triangle",t=>new ag(t));class cg extends ng{get shape(){const{ratio:t=30,wing:n=5,cx:r=0,cy:i=0,rx:s=1,ry:o=1}=this.component.state;if(n<3)return null;const a=Math.PI/2,c=2*Math.PI/n,l=s-t/100*s,h=o-t/100*o,d=new e.Shape;d.moveTo(r+s*Math.cos(-a),i+o*Math.sin(-a)),d.lineTo(r+(s-l)*(Math.cos(c-a)+Math.cos(0-a))/2,i+(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let t=1;t<n;t++)d.lineTo(r+s*Math.cos(c*t-a),i+o*Math.sin(c*t-a)),d.lineTo(r+(s-l)*(Math.cos(c*(t+1)-a)+Math.cos(c*t-a))/2,i+(o-h)*(Math.sin(c*(t+1)-a)+Math.sin(c*t-a))/2);return d.closePath(),d}}Yh("star",t=>new cg(t));const lg={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/sphere"};class hg extends Hf{buildGeometry(){const{rx:t=0,ry:n=0,rz:r}=this.component.state,i=r??t,s=new e.SphereGeometry(1,32,16);s.scale(t,i,n),this.object3d.geometry=s}updateDimension(){this.buildGeometry()}}let dg=class extends Pp{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new hg(this)}get nature(){return lg}};dg=ip([kf("sphere")],dg);const ug={mutable:!1,resizable:!0,rotatable:!0,properties:[]};let pg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Vf(this)}get nature(){return ug}};pg=ip([kf("sprite")],pg);const fg={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cube"};class gg extends Hf{buildGeometry(){const{width:t=0,height:n=0,depth:r=0}=this.component.state,i=new e.BoxGeometry(1,1,1);i.scale(t,r,n),this.object3d.geometry=i}}let mg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new gg(this)}get nature(){return fg}};mg=ip([kf("cube")],mg);const yg={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cylinder"};class bg extends Hf{buildGeometry(){const{rx:t=0,ry:n=0}=this.component.state,r=this.component.state.depth??1,i=new e.CylinderGeometry(1,1,1,25);i.scale(t||1,r||1,n||1),this.object3d.geometry=i}updateDimension(){this.buildGeometry()}}let vg=class extends Pp{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new bg(this)}get nature(){return yg}};vg=ip([kf("cylinder")],vg);const xg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"color",label:"box-color",name:"boxColor",property:"boxColor"}],help:"scene/component/banner"};class _g extends Rh{build(){super.build();const{width:t=1,height:e=1,depth:n=1}=this.component.state;this.object3d.add(this.createCube(t,e,n));const r=this.createTextureBoard(t,n);r.position.set(0,0,.5*e+1),this.object3d.add(r)}createCube(t,n,r){const{boxColor:i="#ccaa76"}=this.component.state,s=Eh(this.component.state.material3d),o=new e.BoxGeometry(t,r,n),a=new e.MeshStandardMaterial({color:i,side:e.FrontSide});Th(a,s);const c=new e.Mesh(o,a);return c.castShadow=s.castShadow,c.receiveShadow=s.receiveShadow,c}createTextureBoard(t,n){const r=Eh(this.component.state.material3d),{fillStyle:i="#ccaa76"}=this.component.state,s=Rh.buildFillStyleTexture(this.component),o=new e.MeshStandardMaterial(s?{map:s}:{color:i||"#ccaa76",side:e.FrontSide});Th(o,r);const a=new e.PlaneGeometry(t,n,1,1),c=new e.Mesh(a,o);return c.castShadow=r.castShadow,c.receiveShadow=r.receiveShadow,c}updateMaterial3d(){super.updateMaterial3d();const t=Eh(this.component.state.material3d);this.object3d.traverse(e=>{if(e.isMesh){const n=e.material;n&&Th(n,t),e.castShadow=t.castShadow,e.receiveShadow=t.receiveShadow}})}}let wg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return xg}buildRealObject(){return new _g(this)}};var Mg;wg=ip([kf("banner")],wg);const Sg={far:1e5,fov:80,near:1,zoom:1},Ag={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"near",name:"near"},{type:"number",label:"far",name:"far"},{type:"number",label:"fov",name:"fov"},{type:"number",label:"zoom",name:"zoom"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/camera"};class kg extends Rh{getObject3dInstance(){return new e.Mesh}updateCamera(){const{near:t=Sg.near,far:n=Sg.far,fov:r=Sg.fov,zoom:i=Sg.zoom,showHelper:s}=this.component.state;this.camera.far=n,this.camera.fov=r,this.camera.near=t,this.camera.zoom=i,s?this.helper||(this.helper=new e.CameraHelper(this.camera),this.object3d.add(this.helper)):this.helper&&(this.object3d.remove(this.helper),delete this.helper)}build(){super.build();const{width:t=0,height:n=0,depth:r=0,fillStyle:i="lightgray"}=this.component.state;this.object3d.geometry=new e.BoxGeometry(t,r,n),this.object3d.material=new e.MeshStandardMaterial({color:i,side:e.FrontSide}),this.camera=new e.PerspectiveCamera,this.camera.position.set(0,0,0),this.object3d.add(this.camera),this.object3d.lookAt(0,0,0),this.updateCamera()}}let Eg=Mg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}static get image(){return Mg._image||(Mg._image=new Image,Mg._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1IAAANSAQMAAABV6G1EAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAABlBMVEX6+voBAQGV71ZvAAAFO0lEQVR42u3dMZLkNBiGYakUKFRIqKOISxDvETiCTBEQcgQOQE7clyAi8REm7KDXIhgYoMa/7fbIX+2K9w022MCP/25Z28GW5RwRERERERERERERERERERERERERERERERERERERERERERERERHRl9mv7fdPn7879sf8Mcq3J3r5EJXaUy3Wddrcd6qNybx9F2/lZ63H+nVCa9Oe9elZa5ksa/dDbE+3fsm4v27C89bd+i6W3l+XdcnSWtuxyvPW+hqorbWb0Jr7Pl3m4tjfVMIZ625d6L5pxTPWw7rQY9P6pqu1dF8aq5d83cE3rXrGWluIxV6h53eotv4c1V3Ln7Nm66ZvvZf8SSues16sD2jubz2sC839fmvYiz7t//LJna27wsr7VjlnNWtPeHTfNlae2bZvnaTePUd+74fqV2LNxv6zdN8O3z9HSWhlc4F+dOvdsKbe2+F7q+zPddq6W2ts6r31vrN825/rtPWwvvcL5losy11uxQNz5U6fYT4w12mrWf80TUNZdetXal/LtwNW6WOFI1Y9bU3GVnfFXM9bneZKwrmKcK4qnKsK52q6uULTzRWFVjpkta/OykKrCq02puWFVhRaSWjlQa0itJrO8oNaQWgloZWFVhnUqjrLN50VBrWi0MpCqwitOqjVdFYQWlFopUGtLLSq0GpjWl5oRaGVBrWy0KpCq+ksP6gVhFYSWllolUGtqrNW/jvBZVYY1IpCKwutIrTqoFbTWUFoxUGtJLSK0KpCq41peaEVhVYa1MpCqwqtprP8oFYUWklo5UGtIrSazvJCKwxqRaGVhVYZ1Ko664ems34UWj8Nav0stBoWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhbW/9L6RWgp37WofIek8j2cyveLTkqrCq0itLLQSkJL+Q5k5budle/HVr73e/24gAHenZ6FlvK9+srzAoLQUp65oDy3QnoeRxFaWWgpz2pRnncThJbyzCDpuUtVaBWhlYWW8qwx5RlqynPovNBSnuUnPaOwCK0stJLQUp4BqjzbVHk+rFNaVWgVoZWFlvJc6Si0lGdzK88cV57bLj2PvgitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqxyyahcrH7JKFysJ54rCuYJwLi+cywnn+vdlLp+rCOfKwrnStXP95zLxiJX7WEFoeaHljO/xEqsaf9/FWqz1bM+VzloP655df2uxrnP9XPHKue7OeMDsuWInyx+Y67T1Yv0gs+cKvay6P5fvZZULrdnYFBbbcr2sdKF1MxbZFdZkLLItq3aay6/vJ102eusD2rJKl633nw/o3n+uxbrpLSv1svL6M95hQ3xYNz33t16sC21Zoc+28Xahm+u+Ic7WhbYs1+dRfrvQ5LpvHOaFNq3SZ8n/faEt6twDtli7wrJpxT6P1183/di0Ti36u3XT903Ld1qGrzf9smmdWhyTddNzf8t8UqdtK/dZGq8P2DZ1ZnHcrQ/osWO5PkvDuby7NE58Yctk7Qq3PSv3+bpc3F0aJ56wF+uLX9xu6eOb4es9z/vWc0vR3oZuByjnf2t/fP/54B/2WvvWEREREREREREREREREREREREREREREREREREREREREREREREREX2J/QlrTpqHD8xO1gAAAABJRU5ErkJggg=="),Mg._image}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath(),this.drawImage(t,Mg.image,e,n,r,i)}buildRealObject(){return new kg(this)}get nature(){return Ag}};Eg=Mg=ip([kf("camera")],Eg);const Cg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"gltf-selector",label:"url",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:"$base_url",defaultStorage:"3d-model",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0,category:"application"},observe:function(t){this.parentNode.querySelector("[name=gltfInfo]").src=t;const e=this.parentNode.querySelector("[name=fillStyleTargets]");e&&(e.src=t)}},{type:"gltf-info",label:"",name:"gltfInfo",readonly:!0,property:{action:(t,e)=>{t.set(e)}},editor:{fullwidth:!0}},{type:"gltf-fill-targets",label:"fill-targets",name:"fillStyleTargets",editor:{fullwidth:!0}}],"value-property":"source",help:"scene/component/gltf-object"};let Pg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}get controls(){return[]}render(t){const{left:e,top:n,width:r,height:i}=this.bounds;t.beginPath();const s=this._topViewSnapshot;if(s)t.drawImage(s,e,n,r,i);else{t.rect(e,n,r,i),t.fillStyle="#f0f0f0",t.fill(),t.strokeStyle="#999",t.lineWidth=1,t.stroke();const s=this.getState("src"),o=s&&s.split("/").pop()?.replace(/\.[^.]+$/,"")||"GLTF",a=Math.max(10,.12*Math.min(r,i));t.fillStyle="#666",t.font=`${a}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(o,e+r/2,n+i/2,.9*r)}}async ready(){await super.ready(),this._ensureTopViewSnapshot()}onchange(t,e){super.onchange(t,e),"src"in t&&(this._topViewSnapshot=void 0,this._ensureTopViewSnapshot())}_ensureTopViewSnapshot(){const t=this.getState("src");if(!t)return;const e=Zu.getTopViewCache(t);if(e)return this._topViewSnapshot=e,void this.invalidate();const n=this.app.url(t);Zu.loadGLTF(n).then(e=>{if(this.getState("src")!==t)return;const n=Zu.getTopViewCache(t);if(n)return this._topViewSnapshot=n,void this.invalidate();const r=Zu.renderTopView(e.scene);Zu.setTopViewCache(t,r),this._topViewSnapshot=r,this.invalidate()})}buildRealObject(){return new Zu(this)}get nature(){return Cg}get source(){return this.getState("src")}set source(t){this.setState("src",t)}set dimension(t){const{width:e=1,height:n=1,depth:r=1}=t;this.setState({width:e,height:n,depth:r}),this.realObject?.updateDimension()}get nodes(){return this.getState("nodes")}set nodes(t){this.setState("nodes",t)}get animations(){return this.getState("animations")}set animations(t){this.setState("animations",t)}get autoPlay(){return!1!==this.getState("autoPlay")}set autoPlay(t){this.setState("autoPlay",t)}get fillStyleTargets(){return this.getState("fillStyleTargets")}set fillStyleTargets(t){this.setState("fillStyleTargets",t)}get nodeNames(){const t=this.realObject;return t?.nodeNames??[]}get animationNames(){const t=this.realObject;return t?.animationNames??[]}};Pg=ip([kf("gltf-object")],Pg);const Tg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"light-type",name:"lightType",property:{options:["","point","directional"]}},{type:"number",label:"intensity",name:"intensity"},{type:"number",label:"distance",name:"distance"},{type:"number",label:"decay",name:"decay"},{type:"checkbox",label:"cast-shadow",name:"castShadow"},{type:"number",label:"near",name:"near",placeholder:"0.5"},{type:"number",label:"far",name:"far",placeholder:"1000"},{type:"number",label:"fov",name:"fov",placeholder:"90"},{type:"number",label:"zoom",name:"zoom",placeholder:"1"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/light"};class Og extends Rh{updatePointLight(){const{lightType:t="point",distance:n=0,intensity:r=10,decay:i=1,fillStyle:s="white",castShadow:o,near:a=.5,far:c=1e3,fov:l=90,zoom:h=1,showHelper:d}=this.component.state;if(this.object3d.color=new e.Color(s),"point"==t&&(this.object3d.distance=n,this.object3d.decay=i),this.object3d.intensity=r,this.object3d.castShadow=o,o){const t=this.object3d.shadow?.camera;t.far=c,t.near=a,t.fov=l,t.zoom=h}if(d){const t=this.object3d.shadow?.camera;this.helper||(this.helper=new e.CameraHelper(t),this.object3d.add(this.helper))}else this.helper&&(this.object3d.remove(this.helper),delete this.helper)}getObject3dInstance(){const{lightType:t="point"}=this.component.state;return"point"==t?new e.PointLight:new e.DirectionalLight}update(){this.clear(),this.build(),this.updateDimension(),this.updateHidden(),this.updatePointLight()}}let Dg=class extends Pp{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Og(this)}get anchors(){return[]}get nature(){return Tg}};Dg=ip([kf("light")],Dg);const Ig={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"}],help:"scene/component/wall"};class zg extends Hf{buildGeometry(){const{width:t=0,height:n=0,depth:r=0}=this.component.state,i=new e.BoxGeometry(1,1,1);i.scale(t,r,n),this.object3d.geometry=i}}let Lg=class extends(rc(ec)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new zg(this)}get nature(){return Ig}};Lg=ip([kf("wall")],Lg);class jg extends Rh{build(){super.build()}update(){}}const Rg={far:1e5,fov:80,near:1,zoom:1};class Fg extends Rh{build(){super.build()}update(){super.update(),this.updateCamera()}getObject3dInstance(){return new e.PerspectiveCamera}updateCamera(){const{near:t=Rg.near,far:e=Rg.far,fov:n=Rg.fov,zoom:r=Rg.zoom}=this.component.state;this.object3d.far=e,this.object3d.fov=n,this.object3d.near=t,this.object3d.zoom=r}}class Bg extends Rh{getObject3dInstance(){return new e.Group}}class Ng extends Hf{buildGeometry(){const{width:t,height:n}=this.component.state.dimension;this.object3d.geometry=new e.PlaneGeometry(t,n)}buildMaterial(){this.object3d.material=new e.MeshStandardMaterial({opacity:0,side:e.DoubleSide,blending:e.NoBlending})}}class Yg extends Rh{getObject3dInstance(){return new e.Scene}dispose(){for(const t of this.object3d.children)Ih(t);this._animationMixer&&(this._animationMixer.stopAllAction(),this._animationMixer.uncacheRoot(this.object3d),this._animationMixer=void 0),super.dispose()}clear(){return this._floor&&(this.object3d.remove(this._floor),this._floor.material instanceof Array?this._floor.material.forEach(t=>t.dispose()):this._floor.material.dispose(),this._floor.geometry.dispose(),delete this._floor),super.clear()}get floor(){return this._floor}set floor(t){this._floor&&(this.object3d.remove(this._floor),this._floor.clear(),delete this._floor),t&&(this._floor=t,this.object3d.add(t)),this.component.invalidate()}build(){super.build(),this.floor=Xh(this.component)}updateTransform(){}updateDimension(){}updatePosition(){}updateRotate(){}updateScale(){}updateAlpha(){}updateHidden(){}get animationMixer(){return this._animationMixer||(this._animationMixer=new e.AnimationMixer(this.object3d)),this._animationMixer}}const Vg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"precision",name:"precision",property:{options:[{display:"High",value:"highp"},{display:"Medium",value:"mediump"},{display:"Low",value:"lowp"}]}},{type:"checkbox",label:"anti-alias",name:"antialias",property:"antialias"},{type:"checkbox",label:"3dmode",name:"threed",property:"threed"},{type:"checkbox",label:"auto-rotate",name:"autoRotate",property:"autoRotate"},{type:"checkbox",label:"debug",name:"debug",property:"debug"}],help:"scene/component/three-container"};let Gg=class extends pp{constructor(){super(...arguments),this._capability=new hd}get sceneManager(){return this._capability.sceneManager}get cameraManager(){return this._capability.cameraManager}get rendererManager(){return this._capability.rendererManager}get lightManager(){return this._capability.lightManager}get controlsManager(){return this._capability.controlsManager}get eventManager(){return this._capability.eventManager}containable(t){return!0}is3dContainer(){return!0}getLightingConfig(){return{hemisphere:{skyColor:14540253,groundColor:3355443,intensity:.035}}}getCss3DSceneAttribute(){return"three-container:css3d-renderer"}init_scene3d(){this._capability.isInitialized&&this._capability.destroy(),this._capability.init(this,{lightingConfig:this.getLightingConfig(),css3DSceneAttribute:this.getCss3DSceneAttribute()}),this._capability.buildOverlays(),this._capability.resize(),this.onchangeData&&this.onchangeData(this.data,this.data)}destroy_scene3d(){this.stop(),this._capability.destroy()}stop(){}resize(){this._capability.resize()}get scene3d(){return this._capability.isInitialized||this.init_scene3d(),this._capability.scene3d}get renderer3d(){return this._capability.renderer3d}get mixer(){return this._capability.mixer}get css3DScene(){return this._capability.css3DScene}get css3DRenderer(){return this._capability.css3DRenderer}render_threed(){this._capability.renderThreeD()}get _parentIs3dMode(){return!!this.rootModel?.is3dMode}render(t){this._parentIs3dMode||(this.app.isViewMode&&this.setState("threed",!0),!this.state.threed||this._capability.noSupportWebgl?super.render(t):this._capability.camera&&this._capability.renderCSS3D())}postrender(t){if(this._parentIs3dMode)return;const{left:e,top:n,debug:r,threed:i}=this.state;let{width:s,height:o}=this.bounds;if(s=Math.floor(s),o=Math.floor(o),i){if(this._capability.isInitialized||this.init_scene3d(),this._capability.noSupportWebgl)return void this._capability.showWebglNoSupportText(t,this.state.width,this.state.height);if(!this._capability.renderer3d)return;this._capability.renderThreeD();const i=this._capability.domElement;t.drawImage(i,0,0,i.width,i.height,e,n,s,o),r&&this._capability.showDebugFPS(t)}else super.postrender(t)}dispose(){this._capability.dispose(),super.dispose()}get layout(){return lc.get("three")}get nature(){return Vg}getObjectByRaycast(){return this._capability.getObjectByRaycast()}getObjectsByRaycast(){return this._capability.getObjectsByRaycast()}onchange(t,e){(t.hasOwnProperty("width")||t.hasOwnProperty("height"))&&this._capability.destroy(),this._capability.onchange(t)}onmousedown(t){this._capability.onMouseDown(t)}onmouseup(t){this._capability.onMouseUp(t)}onmousemove(t){this._capability.onMouseMove(t)}onmouseleave(t){this._capability.onMouseLeave(t)}onwheel(t){this._capability.onWheel(t)&&this.invalidate()}ondblclick(t){this._capability.onDblClick(t)&&this.invalidate()}ondragstart(t){this._capability.onDragStart(t)}ondragmove(t){this._capability.onDragMove(t)&&this.invalidate()}ondragend(t){this._capability.onDragEnd(t)&&this.invalidate()}ontouchstart(t){this._capability.onTouchStart(t)}onpan(t){this._capability.onPan(t)&&this.invalidate()}ontouchend(t){this._capability.onTouchEnd(t)}onkeydown(t){this._capability.onKeyDown(t)}onpinch(t){this._capability.onPinch(t)&&this.invalidate()}ondoubletap(){this._capability.onDoubleTap(),this.invalidate()}};var Hg;Gg=ip([kf("3d-container")],Gg),Vh(t=>{const e=t.state.material3d?.spriteMode;return"plane"===e?new Gf(t):new Vf(t)}),function(t){t.compile=pl,t.duplicate=fl,t.select=Ea,t.match=Sa}(Hg||(Hg={})),Or.registerResidents(()=>({componentResidentsCount:tc.residentsCount,sceneResidentsCount:ep.residentsCount,referenceMapResidentsCount:Pf.residentsCount,sceneResidents:tc.residents}));var Ug=Object.freeze({__proto__:null,AbsoluteLayout:dc,Animation:ta,AudioPlayer:tf,get Banner(){return wg},Banner3D:_g,BoxSelectionManager:ld,get Camera(){return Eg},Camera3D:kg,CameraBookmarkManager:cd,CameraManager:$h,CardLayout:pc,Component:tc,Connectable:Md,Container:pp,ContainerAbstract:Tc,ControlsManager:td,get Cube(){return mg},Cube3D:gg,get Cylinder(){return vg},Cylinder3D:bg,DEFAULT:Ni,DPPX:Ri,DataSource:Af,Donut:bf,DonutExtrude:og,Ellipse:Pp,EllipseExtrude:rg,EventManager3D:ed,EventMap:wu,FPS:dh,GESTURES:Fi,get GLTFObject(){return Pg},GifView:Zp,GizmoManager:nd,GizmoOperationManager:rd,GlobalRef:lf,Group:rf,HTMLAbsoluteLayout:hc,HTMLOverlayContainer:af,HTMLOverlayElement:Np,ImageView:Bp,InfoWindow:ac,InteractionManager:id,KEYEVENTS:Bi,Layer:Oc,Layout:lc,LightManager:Zh,LightObject:Og,Line:Ep,LinearHorizontalLayout:gc,LinearVerticalLayout:yc,LocalRef:of,MATERIAL_PRESETS:kh,MAX_UNDO_SIZE:30,MODE_ADD:3,MODE_EDIT:1,MODE_PASTE_DATABIND:5,MODE_PASTE_STYLE:4,MODE_SHIFT:2,MODE_VIEW:0,get Model(){return Hg},MoveHandle:Cc,NOTHING:Ci,Node:Mf,OrthoLine:Rp,PIXEL_RATIO:uh,Path:pf,PlacementManager:sd,get PointLight(){return Dg},Polygon:Dp,PolygonExtrude:sg,Polyline:Lp,Popup:uf,RealObject:Rh,RealObjectCamera:Fg,RealObjectDomElement:Fh,RealObjectDomTexture:Zf,RealObjectDummy:jg,RealObjectExtrude:ng,RealObjectGLTF:Zu,RealObjectGroup:Bg,RealObjectMesh:Hf,RealObjectPlane:Ng,RealObjectPlane2D:Gf,RealObjectScene:Yg,RealObjectSprite:Ff,RealObjectSprite2D:Vf,RealObjectText:Qf,Rect:kd,RectExtrude:ig,RectPath:rc,ReferenceMap:Pf,RendererManager:Qh,RootContainer:ju,Ruler:Cd,SCALE_MIN:vh,SCENE_MODE:Li,Scene:ep,SceneManager:Kh,ScenePopup:kc,ScriptLoader:jf,Shape:ec,get Sphere(){return dg},Sphere3D:hg,get Sprite(){return pg},Star:_f,StarExtrude:cg,TableLayout:bc,Text:ef,ThreeCapability:hd,get ThreeContainer(){return Gg},Triangle:gf,TriangleExtrude:ag,UNIT_DIMENSION:wh,UNIT_ROTATE:Ah,UNIT_SCALE:Mh,UNIT_TRANSLATE:Sh,ValueHolder:Sf,get Wall(){return Lg},Wall3D:zg,animate:Jo,applyAlpha:xh,applyMaterial3dProps:Th,buildArrow3D:bh,compile:na,create:rp,createCanvas:ph,createCanvasTexture:Nf,createFloor:Xh,createRealObjectFor:Gh,debug:qr,delta:Qo,disposeObject3D:Ih,drawTextTexture:Xf,error:Wr,fontStyle:Uf,initFontFamilyWatcher:Vi,inspector:qu,metrics:Or,opaqueColor:_h,projectToScreen:Fc,registerDefaultRealObjectFactory:Vh,registerRealObjectFactory:Yh,renderCanvasTexture:Yf,resolveMaterial3d:Eh,sceneComponent:kf,stopFPSMeasure:hh,textBounds:$f,textTexture:qf,toThreeSide:Ph,updateDefaultFontFamily:Yi,version:Rf,warn:Xr});const Wg=globalThis;"undefined"==typeof globalThis||Wg.scene||(Wg.scene=Ug);export{dc as AbsoluteLayout,ta as Animation,tf as AudioPlayer,wg as Banner,_g as Banner3D,ld as BoxSelectionManager,Eg as Camera,kg as Camera3D,cd as CameraBookmarkManager,$h as CameraManager,pc as CardLayout,tc as Component,Md as Connectable,pp as Container,Tc as ContainerAbstract,td as ControlsManager,mg as Cube,gg as Cube3D,vg as Cylinder,bg as Cylinder3D,Ni as DEFAULT,Ri as DPPX,Af as DataSource,bf as Donut,og as DonutExtrude,Pp as Ellipse,rg as EllipseExtrude,ed as EventManager3D,wu as EventMap,dh as FPS,Fi as GESTURES,Pg as GLTFObject,Zp as GifView,nd as GizmoManager,rd as GizmoOperationManager,lf as GlobalRef,rf as Group,hc as HTMLAbsoluteLayout,af as HTMLOverlayContainer,Np as HTMLOverlayElement,Bp as ImageView,ac as InfoWindow,id as InteractionManager,Bi as KEYEVENTS,Oc as Layer,lc as Layout,Zh as LightManager,Og as LightObject,Ep as Line,gc as LinearHorizontalLayout,yc as LinearVerticalLayout,of as LocalRef,kh as MATERIAL_PRESETS,ji as MAX_UNDO_SIZE,Di as MODE_ADD,Ti as MODE_EDIT,zi as MODE_PASTE_DATABIND,Ii as MODE_PASTE_STYLE,Oi as MODE_SHIFT,Pi as MODE_VIEW,Hg as Model,Cc as MoveHandle,Ci as NOTHING,Mf as Node,Rp as OrthoLine,uh as PIXEL_RATIO,pf as Path,sd as PlacementManager,Dg as PointLight,Dp as Polygon,sg as PolygonExtrude,Lp as Polyline,uf as Popup,Rh as RealObject,Fg as RealObjectCamera,Fh as RealObjectDomElement,Zf as RealObjectDomTexture,jg as RealObjectDummy,ng as RealObjectExtrude,Zu as RealObjectGLTF,Bg as RealObjectGroup,Hf as RealObjectMesh,Ng as RealObjectPlane,Gf as RealObjectPlane2D,Yg as RealObjectScene,Ff as RealObjectSprite,Vf as RealObjectSprite2D,Qf as RealObjectText,kd as Rect,ig as RectExtrude,rc as RectPath,Pf as ReferenceMap,Qh as RendererManager,ju as RootContainer,Cd as Ruler,vh as SCALE_MIN,Li as SCENE_MODE,ep as Scene,Kh as SceneManager,kc as ScenePopup,jf as ScriptLoader,ec as Shape,dg as Sphere,hg as Sphere3D,pg as Sprite,_f as Star,cg as StarExtrude,bc as TableLayout,ef as Text,hd as ThreeCapability,Gg as ThreeContainer,gf as Triangle,ag as TriangleExtrude,wh as UNIT_DIMENSION,Ah as UNIT_ROTATE,Mh as UNIT_SCALE,Sh as UNIT_TRANSLATE,Sf as ValueHolder,Lg as Wall,zg as Wall3D,Jo as animate,xh as applyAlpha,Th as applyMaterial3dProps,bh as buildArrow3D,na as compile,rp as create,ph as createCanvas,Nf as createCanvasTexture,Xh as createFloor,Gh as createRealObjectFor,qr as debug,Qo as delta,Ih as disposeObject3D,Xf as drawTextTexture,Wr as error,Uf as fontStyle,Vi as initFontFamilyWatcher,qu as inspector,Or as metrics,_h as opaqueColor,Fc as projectToScreen,Vh as registerDefaultRealObjectFactory,Yh as registerRealObjectFactory,Yf as renderCanvasTexture,Eh as resolveMaterial3d,kf as sceneComponent,hh as stopFPSMeasure,$f as textBounds,qf as textTexture,Ph as toThreeSide,Yi as updateDefaultFontFamily,Rf as version,Xr as warn};
|
|
52
52
|
//# sourceMappingURL=things-scene.mjs.map
|