@hatiolab/things-scene 10.1.2 → 10.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/things-scene.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import t from"dompurify";import*as e from"three";import{Color as n,LinearSRGBColorSpace as i,SRGBColorSpace as s,Scene as r,BoxGeometry as o,MeshStandardMaterial as a,BackSide as c,Mesh as l,PointLight as h,MeshLambertMaterial as d,MathUtils as u}from"three";import p from"tinycolor2";import{GLTFLoader as f}from"three/examples/jsm/loaders/GLTFLoader.js";import{DRACOLoader as m}from"three/examples/jsm/loaders/DRACOLoader.js";import{KTX2Loader as g}from"three/examples/jsm/loaders/KTX2Loader.js";import{MeshoptDecoder as y}from"three/examples/jsm/libs/meshopt_decoder.module.js";import{clone as b}from"three/examples/jsm/utils/SkeletonUtils.js";import{CSS3DSprite as _,CSS3DObject as v,CSS3DRenderer as x}from"three/examples/jsm/renderers/CSS3DRenderer.js";import{Line2 as w}from"three/examples/jsm/lines/Line2.js";import{LineMaterial as M}from"three/examples/jsm/lines/LineMaterial.js";import{LineGeometry as S}from"three/examples/jsm/lines/LineGeometry.js";import{Sky as k}from"three/examples/jsm/objects/Sky.js";import{EffectComposer as A}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as E}from"three/examples/jsm/postprocessing/RenderPass.js";import{OutlinePass as C}from"three/examples/jsm/postprocessing/OutlinePass.js";import{OutputPass as T}from"three/examples/jsm/postprocessing/OutputPass.js";import{SMAAPass as P}from"three/examples/jsm/postprocessing/SMAAPass.js";import{TransformControls as O}from"three/examples/jsm/controls/TransformControls.js";import{render as D,nothing as z,html as I}from"lit";import{RoundedBoxGeometry as R}from"three/examples/jsm/geometries/RoundedBoxGeometry.js";import{mergeGeometries as j}from"three/examples/jsm/utils/BufferGeometryUtils.js";function L(t,e){return t===e||t!=t&&e!=e}function F(t,e){for(var n=t.length;n--;)if(L(t[n][0],e))return n;return-1}var N=Array.prototype.splice;function H(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}H.prototype.clear=function(){this.__data__=[],this.size=0},H.prototype.delete=function(t){var e=this.__data__,n=F(e,t);return!(n<0)&&(n==e.length-1?e.pop():N.call(e,n,1),--this.size,!0)},H.prototype.get=function(t){var e=this.__data__,n=F(e,t);return n<0?void 0:e[n][1]},H.prototype.has=function(t){return F(this.__data__,t)>-1},H.prototype.set=function(t,e){var n=this.__data__,i=F(n,t);return i<0?(++this.size,n.push([t,e])):n[i][1]=e,this};var B="object"==typeof global&&global&&global.Object===Object&&global,G="object"==typeof self&&self&&self.Object===Object&&self,V=B||G||Function("return this")(),Y=V.Symbol,W=Object.prototype,U=W.hasOwnProperty,$=W.toString,X=Y?Y.toStringTag:void 0;var q=Object.prototype.toString;var K=Y?Y.toStringTag:void 0;function Q(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":K&&K in Object(t)?function(t){var e=U.call(t,X),n=t[X];try{t[X]=void 0;var i=!0}catch(t){}var s=$.call(t);return i&&(e?t[X]=n:delete t[X]),s}(t):function(t){return q.call(t)}(t)}function Z(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function J(t){if(!Z(t))return!1;var e=Q(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var tt,et=V["__core-js_shared__"],nt=(tt=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||""))?"Symbol(src)_1."+tt:"";var it=Function.prototype.toString;function st(t){if(null!=t){try{return it.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var rt=/^\[object .+?Constructor\]$/,ot=Function.prototype,at=Object.prototype,ct=ot.toString,lt=at.hasOwnProperty,ht=RegExp("^"+ct.call(lt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function dt(t){return!(!Z(t)||(e=t,nt&&nt in e))&&(J(t)?ht:rt).test(st(t));var e}function ut(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return dt(n)?n:void 0}var pt=ut(V,"Map"),ft=ut(Object,"create");var mt=Object.prototype.hasOwnProperty;var gt=Object.prototype.hasOwnProperty;function yt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function bt(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 _t(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}yt.prototype.clear=function(){this.__data__=ft?ft(null):{},this.size=0},yt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},yt.prototype.get=function(t){var e=this.__data__;if(ft){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return mt.call(e,t)?e[t]:void 0},yt.prototype.has=function(t){var e=this.__data__;return ft?void 0!==e[t]:gt.call(e,t)},yt.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=ft&&void 0===e?"__lodash_hash_undefined__":e,this},_t.prototype.clear=function(){this.size=0,this.__data__={hash:new yt,map:new(pt||H),string:new yt}},_t.prototype.delete=function(t){var e=bt(this,t).delete(t);return this.size-=e?1:0,e},_t.prototype.get=function(t){return bt(this,t).get(t)},_t.prototype.has=function(t){return bt(this,t).has(t)},_t.prototype.set=function(t,e){var n=bt(this,t),i=n.size;return n.set(t,e),this.size+=n.size==i?0:1,this};function vt(t){var e=this.__data__=new H(t);this.size=e.size}vt.prototype.clear=function(){this.__data__=new H,this.size=0},vt.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},vt.prototype.get=function(t){return this.__data__.get(t)},vt.prototype.has=function(t){return this.__data__.has(t)},vt.prototype.set=function(t,e){var n=this.__data__;if(n instanceof H){var i=n.__data__;if(!pt||i.length<199)return i.push([t,e]),this.size=++n.size,this;n=this.__data__=new _t(i)}return n.set(t,e),this.size=n.size,this};function xt(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new _t;++e<n;)this.add(t[e])}function wt(t,e){for(var n=-1,i=null==t?0:t.length;++n<i;)if(e(t[n],n,t))return!0;return!1}xt.prototype.add=xt.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},xt.prototype.has=function(t){return this.__data__.has(t)};function Mt(t,e,n,i,s,r){var o=1&n,a=t.length,c=e.length;if(a!=c&&!(o&&c>a))return!1;var l=r.get(t),h=r.get(e);if(l&&h)return l==e&&h==t;var d=-1,u=!0,p=2&n?new xt:void 0;for(r.set(t,e),r.set(e,t);++d<a;){var f=t[d],m=e[d];if(i)var g=o?i(m,f,d,e,t,r):i(f,m,d,t,e,r);if(void 0!==g){if(g)continue;u=!1;break}if(p){if(!wt(e,function(t,e){if(o=e,!p.has(o)&&(f===t||s(f,t,n,i,r)))return p.push(e);var o})){u=!1;break}}else if(f!==m&&!s(f,m,n,i,r)){u=!1;break}}return r.delete(t),r.delete(e),u}var St=V.Uint8Array;function kt(t){var e=-1,n=Array(t.size);return t.forEach(function(t,i){n[++e]=[i,t]}),n}function At(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var Et=Y?Y.prototype:void 0,Ct=Et?Et.valueOf:void 0;function Tt(t,e){for(var n=-1,i=e.length,s=t.length;++n<i;)t[s+n]=e[n];return t}var Pt=Array.isArray;function Ot(){return[]}var Dt=Object.prototype.propertyIsEnumerable,zt=Object.getOwnPropertySymbols,It=zt?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var n=-1,i=null==t?0:t.length,s=0,r=[];++n<i;){var o=t[n];e(o,n,t)&&(r[s++]=o)}return r}(zt(t),function(e){return Dt.call(t,e)}))}:Ot;function Rt(t){return null!=t&&"object"==typeof t}function jt(t){return Rt(t)&&"[object Arguments]"==Q(t)}var Lt=Object.prototype,Ft=Lt.hasOwnProperty,Nt=Lt.propertyIsEnumerable,Ht=jt(function(){return arguments}())?jt:function(t){return Rt(t)&&Ft.call(t,"callee")&&!Nt.call(t,"callee")};var Bt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Gt=Bt&&"object"==typeof module&&module&&!module.nodeType&&module,Vt=Gt&&Gt.exports===Bt?V.Buffer:void 0,Yt=(Vt?Vt.isBuffer:void 0)||function(){return!1},Wt=/^(?:0|[1-9]\d*)$/;function Ut(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&Wt.test(t))&&t>-1&&t%1==0&&t<e}function $t(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var Xt={};function qt(t){return function(e){return t(e)}}Xt["[object Float32Array]"]=Xt["[object Float64Array]"]=Xt["[object Int8Array]"]=Xt["[object Int16Array]"]=Xt["[object Int32Array]"]=Xt["[object Uint8Array]"]=Xt["[object Uint8ClampedArray]"]=Xt["[object Uint16Array]"]=Xt["[object Uint32Array]"]=!0,Xt["[object Arguments]"]=Xt["[object Array]"]=Xt["[object ArrayBuffer]"]=Xt["[object Boolean]"]=Xt["[object DataView]"]=Xt["[object Date]"]=Xt["[object Error]"]=Xt["[object Function]"]=Xt["[object Map]"]=Xt["[object Number]"]=Xt["[object Object]"]=Xt["[object RegExp]"]=Xt["[object Set]"]=Xt["[object String]"]=Xt["[object WeakMap]"]=!1;var Kt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Qt=Kt&&"object"==typeof module&&module&&!module.nodeType&&module,Zt=Qt&&Qt.exports===Kt&&B.process,Jt=function(){try{var t=Qt&&Qt.require&&Qt.require("util").types;return t||Zt&&Zt.binding&&Zt.binding("util")}catch(t){}}(),te=Jt&&Jt.isTypedArray,ee=te?qt(te):function(t){return Rt(t)&&$t(t.length)&&!!Xt[Q(t)]},ne=Object.prototype.hasOwnProperty;function ie(t,e){var n=Pt(t),i=!n&&Ht(t),s=!n&&!i&&Yt(t),r=!n&&!i&&!s&&ee(t),o=n||i||s||r,a=o?function(t,e){for(var n=-1,i=Array(t);++n<t;)i[n]=e(n);return i}(t.length,String):[],c=a.length;for(var l in t)!e&&!ne.call(t,l)||o&&("length"==l||s&&("offset"==l||"parent"==l)||r&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Ut(l,c))||a.push(l);return a}var se=Object.prototype;function re(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||se)}function oe(t,e){return function(n){return t(e(n))}}var ae=oe(Object.keys,Object),ce=Object.prototype.hasOwnProperty;function le(t){if(!re(t))return ae(t);var e=[];for(var n in Object(t))ce.call(t,n)&&"constructor"!=n&&e.push(n);return e}function he(t){return null!=t&&$t(t.length)&&!J(t)}function de(t){return he(t)?ie(t):le(t)}function ue(t){return function(t,e,n){var i=e(t);return Pt(t)?i:Tt(i,n(t))}(t,de,It)}var pe=Object.prototype.hasOwnProperty;var fe=ut(V,"DataView"),me=ut(V,"Promise"),ge=ut(V,"Set"),ye=ut(V,"WeakMap"),be="[object Map]",_e="[object Promise]",ve="[object Set]",xe="[object WeakMap]",we="[object DataView]",Me=st(fe),Se=st(pt),ke=st(me),Ae=st(ge),Ee=st(ye),Ce=Q;(fe&&Ce(new fe(new ArrayBuffer(1)))!=we||pt&&Ce(new pt)!=be||me&&Ce(me.resolve())!=_e||ge&&Ce(new ge)!=ve||ye&&Ce(new ye)!=xe)&&(Ce=function(t){var e=Q(t),n="[object Object]"==e?t.constructor:void 0,i=n?st(n):"";if(i)switch(i){case Me:return we;case Se:return be;case ke:return _e;case Ae:return ve;case Ee:return xe}return e});var Te="[object Arguments]",Pe="[object Array]",Oe="[object Object]",De=Object.prototype.hasOwnProperty;function ze(t,e,n,i,s,r){var o=Pt(t),a=Pt(e),c=o?Pe:Ce(t),l=a?Pe:Ce(e),h=(c=c==Te?Oe:c)==Oe,d=(l=l==Te?Oe:l)==Oe,u=c==l;if(u&&Yt(t)){if(!Yt(e))return!1;o=!0,h=!1}if(u&&!h)return r||(r=new vt),o||ee(t)?Mt(t,e,n,i,s,r):function(t,e,n,i,s,r,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||!r(new St(t),new St(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return L(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var a=kt;case"[object Set]":var c=1&i;if(a||(a=At),t.size!=e.size&&!c)return!1;var l=o.get(t);if(l)return l==e;i|=2,o.set(t,e);var h=Mt(a(t),a(e),i,s,r,o);return o.delete(t),h;case"[object Symbol]":if(Ct)return Ct.call(t)==Ct.call(e)}return!1}(t,e,c,n,i,s,r);if(!(1&n)){var p=h&&De.call(t,"__wrapped__"),f=d&&De.call(e,"__wrapped__");if(p||f){var m=p?t.value():t,g=f?e.value():e;return r||(r=new vt),s(m,g,n,i,r)}}return!!u&&(r||(r=new vt),function(t,e,n,i,s,r){var o=1&n,a=ue(t),c=a.length;if(c!=ue(e).length&&!o)return!1;for(var l=c;l--;){var h=a[l];if(!(o?h in e:pe.call(e,h)))return!1}var d=r.get(t),u=r.get(e);if(d&&u)return d==e&&u==t;var p=!0;r.set(t,e),r.set(e,t);for(var f=o;++l<c;){var m=t[h=a[l]],g=e[h];if(i)var y=o?i(g,m,h,e,t,r):i(m,g,h,t,e,r);if(!(void 0===y?m===g||s(m,g,n,i,r):y)){p=!1;break}f||(f="constructor"==h)}if(p&&!f){var b=t.constructor,_=e.constructor;b==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof _&&_ instanceof _||(p=!1)}return r.delete(t),r.delete(e),p}(t,e,n,i,s,r))}function Ie(t,e,n,i,s){return t===e||(null==t||null==e||!Rt(t)&&!Rt(e)?t!=t&&e!=e:ze(t,e,n,i,Ie,s))}function Re(t,e){for(var n=-1,i=null==t?0:t.length;++n<i&&!1!==e(t[n],n,t););return t}var je=function(){try{var t=ut(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Le(t,e,n){"__proto__"==e&&je?je(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var Fe=Object.prototype.hasOwnProperty;function Ne(t,e,n){var i=t[e];Fe.call(t,e)&&L(i,n)&&(void 0!==n||e in t)||Le(t,e,n)}function He(t,e,n,i){var s=!n;n||(n={});for(var r=-1,o=e.length;++r<o;){var a=e[r],c=i?i(n[a],t[a],a,n,t):void 0;void 0===c&&(c=t[a]),s?Le(n,a,c):Ne(n,a,c)}return n}function Be(t){return t}function Ge(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 Ve=Math.max;function Ye(t){return function(){return t}}var We=je?function(t,e){return je(t,"toString",{configurable:!0,enumerable:!1,value:Ye(e),writable:!0})}:Be,Ue=Date.now;var $e=function(t){var e=0,n=0;return function(){var i=Ue(),s=16-(i-n);if(n=i,s>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(We);function Xe(t,e){return $e(function(t,e,n){return e=Ve(void 0===e?t.length-1:e,0),function(){for(var i=arguments,s=-1,r=Ve(i.length-e,0),o=Array(r);++s<r;)o[s]=i[e+s];s=-1;for(var a=Array(e+1);++s<e;)a[s]=i[s];return a[e]=n(o),Ge(t,this,a)}}(t,e,Be),t+"")}function qe(t,e,n){if(!Z(n))return!1;var i=typeof e;return!!("number"==i?he(n)&&Ut(e,n.length):"string"==i&&e in n)&&L(n[e],t)}var Ke,Qe=(Ke=function(t,e,n,i){He(e,de(e),t,i)},Xe(function(t,e){var n=-1,i=e.length,s=i>1?e[i-1]:void 0,r=i>2?e[2]:void 0;for(s=Ke.length>3&&"function"==typeof s?(i--,s):void 0,r&&qe(e[0],e[1],r)&&(s=i<3?void 0:s,i=1),t=Object(t);++n<i;){var o=e[n];o&&Ke(t,o,n,s)}return t})),Ze=oe(Object.getPrototypeOf,Object),Je=Function.prototype,tn=Object.prototype,en=Je.toString,nn=tn.hasOwnProperty,sn=en.call(Object);function rn(t){if(!Rt(t))return!1;var e=Q(t);return"[object Error]"==e||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!function(t){if(!Rt(t)||"[object Object]"!=Q(t))return!1;var e=Ze(t);if(null===e)return!0;var n=nn.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&en.call(n)==sn}(t)}var on=Xe(function(t,e){try{return Ge(t,void 0,e)}catch(t){return rn(t)?t:new Error(t)}});function an(t,e){for(var n=-1,i=null==t?0:t.length,s=Array(i);++n<i;)s[n]=e(t[n],n,t);return s}var cn=Object.prototype,ln=cn.hasOwnProperty;function hn(t,e,n,i){return void 0===t||L(t,cn[n])&&!ln.call(i,n)?e:t}var dn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"};function un(t){return"\\"+dn[t]}var pn=/<%=([\s\S]+?)%>/g;var fn,mn=(fn={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},function(t){return null==fn?void 0:fn[t]});function gn(t){return"symbol"==typeof t||Rt(t)&&"[object Symbol]"==Q(t)}var yn=Y?Y.prototype:void 0,bn=yn?yn.toString:void 0;function _n(t){if("string"==typeof t)return t;if(Pt(t))return an(t,_n)+"";if(gn(t))return bn?bn.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function vn(t){return null==t?"":_n(t)}var xn=/[&<>"']/g,wn=RegExp(xn.source);var Mn={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:pn,variable:"",imports:{_:{escape:function(t){return(t=vn(t))&&wn.test(t)?t.replace(xn,mn):t}}}},Sn=/\b__p \+= '';/g,kn=/\b(__p \+=) '' \+/g,An=/(__e\(.*?\)|\b__t\)) \+\n'';/g,En=/[()=,{}\[\]\/\s]/,Cn=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Tn=/($^)/,Pn=/['\n\r\u2028\u2029\\]/g,On=Object.prototype.hasOwnProperty;var Dn=Object.prototype.hasOwnProperty;function zn(t){if(!Z(t))return function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}(t);var e=re(t),n=[];for(var i in t)("constructor"!=i||!e&&Dn.call(t,i))&&n.push(i);return n}function In(t,e){return t&&He(e,function(t){return he(t)?ie(t,!0):zn(t)}(e),t)}var Rn="object"==typeof exports&&exports&&!exports.nodeType&&exports,jn=Rn&&"object"==typeof module&&module&&!module.nodeType&&module,Ln=jn&&jn.exports===Rn?V.Buffer:void 0,Fn=Ln?Ln.allocUnsafe:void 0;var Nn=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Tt(e,It(t)),t=Ze(t);return e}:Ot;var Hn=Object.prototype.hasOwnProperty;var Bn=/\w*$/;var Gn=Y?Y.prototype:void 0,Vn=Gn?Gn.valueOf:void 0;function Yn(t,e,n){var i,s,r,o,a,c=t.constructor;switch(e){case"[object ArrayBuffer]":return a=new(o=t).constructor(o.byteLength),new St(a).set(new St(o)),a;case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return r=(s=t).buffer,new s.constructor(r,s.byteOffset,s.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,Bn.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return i=t,Vn?Object(Vn.call(i)):{}}}var Wn=Object.create,Un=function(){function t(){}return function(e){if(!Z(e))return{};if(Wn)return Wn(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}();var $n=Jt&&Jt.isMap,Xn=$n?qt($n):function(t){return Rt(t)&&"[object Map]"==Ce(t)};var qn=Jt&&Jt.isSet,Kn=qn?qt(qn):function(t){return Rt(t)&&"[object Set]"==Ce(t)},Qn="[object Arguments]",Zn="[object Function]",Jn="[object Object]",ti={};function ei(t,e,n,i,s,r){var o,a=2&e;if(void 0!==o)return o;if(!Z(t))return t;var c=Pt(t);if(c)return o=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&Hn.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),function(t,e){var n=-1,i=t.length;for(e||(e=Array(i));++n<i;)e[n]=t[n];return e}(t,o);var l=Ce(t),h=l==Zn||"[object GeneratorFunction]"==l;if(Yt(t))return function(t){var e=t.length,n=Fn?Fn(e):new t.constructor(e);return t.copy(n),n}(t);if(l==Jn||l==Qn||h&&!s)return o=h?{}:function(t){return"function"!=typeof t.constructor||re(t)?{}:Un(Ze(t))}(t),a?function(t,e){return He(t,Nn(t),e)}(t,In(o,t)):function(t,e){return He(t,It(t),e)}(t,function(t,e){return t&&He(e,de(e),t)}(o,t));if(!ti[l])return s?t:{};o=Yn(t,l),r||(r=new vt);var d=r.get(t);if(d)return d;r.set(t,o),Kn(t)?t.forEach(function(i){o.add(ei(i,e,n,i,t,r))}):Xn(t)&&t.forEach(function(i,s){o.set(s,ei(i,e,n,s,t,r))});var u=c?void 0:ue(t);return Re(u||t,function(i,s){u&&(i=t[s=i]),Ne(o,s,ei(i,e,n,s,t,r))}),o}ti[Qn]=ti["[object Array]"]=ti["[object ArrayBuffer]"]=ti["[object DataView]"]=ti["[object Boolean]"]=ti["[object Date]"]=ti["[object Float32Array]"]=ti["[object Float64Array]"]=ti["[object Int8Array]"]=ti["[object Int16Array]"]=ti["[object Int32Array]"]=ti["[object Map]"]=ti["[object Number]"]=ti[Jn]=ti["[object RegExp]"]=ti["[object Set]"]=ti["[object String]"]=ti["[object Symbol]"]=ti["[object Uint8Array]"]=ti["[object Uint8ClampedArray]"]=ti["[object Uint16Array]"]=ti["[object Uint32Array]"]=!0,ti["[object Error]"]=ti[Zn]=ti["[object WeakMap]"]=!1;function ni(t){return ei(t,4)}var ii=function(){return V.Date.now()},si=/\s/;var ri=/^\s+/;function oi(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&si.test(t.charAt(e)););return e}(t)+1).replace(ri,""):t}var ai=/^[-+]0x[0-9a-f]+$/i,ci=/^0b[01]+$/i,li=/^0o[0-7]+$/i,hi=parseInt;function di(t){if("number"==typeof t)return t;if(gn(t))return NaN;if(Z(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Z(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=oi(t);var n=ci.test(t);return n||li.test(t)?hi(t.slice(2),n?2:8):ai.test(t)?NaN:+t}var ui=Math.max,pi=Math.min;function fi(t,e,n){var i,s,r,o,a,c,l=0,h=!1,d=!1,u=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function p(e){var n=i,r=s;return i=s=void 0,l=e,o=t.apply(r,n)}function f(t){var n=t-c;return void 0===c||n>=e||n<0||d&&t-l>=r}function m(){var t=ii();if(f(t))return g(t);a=setTimeout(m,function(t){var n=e-(t-c);return d?pi(n,r-(t-l)):n}(t))}function g(t){return a=void 0,u&&i?p(t):(i=s=void 0,o)}function y(){var t=ii(),n=f(t);if(i=arguments,s=this,c=t,n){if(void 0===a)return function(t){return l=t,a=setTimeout(m,e),h?p(t):o}(c);if(d)return clearTimeout(a),a=setTimeout(m,e),p(c)}return void 0===a&&(a=setTimeout(m,e)),o}return e=di(e)||0,Z(n)&&(h=!!n.leading,r=(d="maxWait"in n)?ui(di(n.maxWait)||0,e):r,u="trailing"in n?!!n.trailing:u),y.cancel=function(){void 0!==a&&clearTimeout(a),l=0,i=c=s=a=void 0},y.flush=function(){return void 0===a?o:g(ii())},y}var mi=1/0;function gi(t){var e=function(t){return t?(t=di(t))===mi||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 yi(t){return function(t,e){var n;if("function"!=typeof e)throw new TypeError("Expected a function");return t=gi(t),function(){return--t>0&&(n=e.apply(this,arguments)),t<=1&&(e=void 0),n}}(2,t)}var bi=Object.prototype.hasOwnProperty;function _i(t){if(null==t)return!0;if(he(t)&&(Pt(t)||"string"==typeof t||"function"==typeof t.splice||Yt(t)||ee(t)||Ht(t)))return!t.length;var e=Ce(t);if("[object Map]"==e||"[object Set]"==e)return!t.size;if(re(t))return!le(t).length;for(var n in t)if(bi.call(t,n))return!1;return!0}let vi=0;function xi(t={},...e){return"object"!=typeof t&&(t={}),e.forEach(e=>{for(const n in e)"object"!=typeof e[n]?t[n]=e[n]:e[n].length>0?t[n]=e[n].map(t=>{let i;return i="object"!=typeof e[n]?t:xi({},t),i}):t[n]=xi(t[n],e[n])}),t}function wi(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 Mi(t,e){if(!this.__collection__)return this;return-1==this.__collection__.indexOf(e)&&this.__collection__.splice(t,0,e),this}function Si(t){return this.__collection__||(this.__collection__=[]),-1==this.__collection__.indexOf(t)&&this.__collection__.push(t),this}function ki(t){return this.__collection__||(this.__collection__=[]),-1==this.__collection__.indexOf(t)&&this.__collection__.unshift(t),this}function Ai(t){if(!this.__collection__)return this;const e=this.__collection__.indexOf(t);return e>=0&&this.__collection__.splice(e,1),this}function Ei(t){if(this.__collection__)return this.__collection__[t]}function Ci(t,e){this.__collection__&&this.__collection__.forEach(t,e)}function Ti(t){return this.__collection__?this.__collection__.indexOf(t):-1}function Pi(){return this.__collection__?this.__collection__.length:0}function Oi(){this.__collection__=[]}function Di(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this.__collection__[e]=this.__collection__[e-1],this.__collection__[e-1]=t)}function zi(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 Ii(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this.__collection__.splice(0,e),i=this.__collection__.splice(1);this.__collection__=this.__collection__.concat(n,i)}function Ri(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this.__collection__.splice(0,e),i=this.__collection__.splice(1);this.__collection__=n.concat(i,this.__collection__)}class ji{constructor(){this.__collection__=[],this.insertAt=Mi,this.append=Si,this.prepend=ki,this.remove=Ai,this.getAt=Ei,this.forEach=Ci,this.indexOf=Ti,this.size=Pi,this.clear=Oi,this.moveForward=Di,this.moveBackward=zi,this.moveToHead=Ii,this.moveToTail=Ri}}const Li=new class{constructor(){this.enabled=!1,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}enable(){this.drawCount=0,this.drawTimeSum=0,this.drawTimeLast=0,this.invalidateCount=0,this.triggerCount=0,this.cacheHit=0,this.cacheMiss=0,this._frameCount=0,this._lastSnapshotTime=0,this.enabled=!0}disable(){this.enabled=!1}registerResidents(t){this._getResidents=t}countFrame(){this._frameCount++}snapshot(){this.enabled||this.enable();const t=performance.now(),e=this.drawCount,n=this.cacheHit+this.cacheMiss,i=this._getResidents?.()??null;let s=0;if(this._lastSnapshotTime>0){const e=t-this._lastSnapshotTime;e>0&&(s=Math.round(1e3*this._frameCount/e))}this._lastSnapshotTime=t,this._frameCount=0;const r={fps:s,drawCount:e,drawTimeAvg:e>0?Math.round(this.drawTimeSum/e*100)/100:0,drawTimeLast:Math.round(100*this.drawTimeLast)/100,invalidateCount:this.invalidateCount,triggerCount:this.triggerCount,cacheHitRate:n>0?Math.round(this.cacheHit/n*1e3)/10:0,...i??{}};return this.drawCount=0,this.drawTimeSum=0,this.invalidateCount=0,this.triggerCount=0,this.cacheHit=0,this.cacheMiss=0,r}},Fi=/\s+/;function Ni(t,e,n,i){if(!n)return!0;if("object"==typeof n){for(const i in n){const s=n[i];t[e].apply(t,[i,s])}return!1}if(Fi.test(n)){return n.split(Fi).forEach(n=>t[e].apply(t,[n].concat(i))),!1}return!0}const Hi=["on","off","once","delegate_on","delegate_off","trigger","listenTo"],Bi={withEvent(){Hi.forEach(t=>this[t]=Bi[t])},on(t,e,n){if(!Ni(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(!Ni(this,"once",t,[e,n])||!e)return this;const i=this,s=yi(function(){i.off(t,s,n),e.apply(i,arguments)});return s._callback=e,this.on(t,s,n),this},off(t,e,n){if(!this._listeners||!Ni(this,"off",t,[e,n]))return this;if(!t&&!e&&!n)return this._listeners=void 0,this;let i;i=t&&"string"==typeof t?[t]:Object.keys(this._listeners||{});for(let t=0;t<i.length;t++){const s=i[t],r=this._listeners?.[s];if(r){const t=[];if(this._listeners[s]=t,e||n)for(let i=0;i<r.length;i++){const s=r[i];(e&&e!==s.callback&&e!==s.callback._callback||n&&n!==s.context)&&t.push(s)}t.length||delete this._listeners[s]}}return this},delegate_on(t){return this._delegators||(this._delegators=new ji),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&&Vi(this._delegators,arguments),!this._listeners)return this;const t=arguments.length-1,e=arguments[t];arguments[t]={origin:e.origin,name:e.name,deliverer:this};const n=this._listeners[e.name],i=this._listeners["(all)"];return n&&Gi(n,arguments),i&&Gi(i,arguments),this},trigger(t){Li.enabled&&Li.triggerCount++;const e=[].slice.call(arguments,1);if(e.push({origin:this,name:t,deliverer:this}),this._delegators&&this._delegators.size()>0&&Vi(this._delegators,e),!this._listeners)return this;if(!Ni(this,"trigger",t,e))return this;const n=this._listeners[t],i=this._listeners["(all)"];return n&&Gi(n,e),i&&Gi(i,e),this},stopListening(t,e,n){let i=this._listeningTo;if(!i)return this;const s=!e&&!n;n||"object"!=typeof e||(n=this),t&&(i={},i[t._listenId]=t);for(const t in i){const r=i[t];r.off(e,n,this),(s||_i(r._events))&&delete this._listeningTo[t]}return this}};function Gi(t,e){t.forEach(t=>t.callback.apply(t.ctx,e))}function Vi(t,e){t.forEach(t=>Bi.delegate.apply(t,e))}const Yi={listenTo:"on",listenToOnce:"once"};for(const t in Yi){const e=Yi[t];Bi[t]=function(t,n,i){this._listeningTo||(this._listeningTo={});const s=this._listeningTo;t._listenId||(t._listenId=`${"l"}${++vi}`);return s[t._listenId]=t,i||"object"!=typeof n||(i=this),t[e](n,i,this),this}}const Wi=Bi.on,Ui=Bi.off,$i=Bi.once,Xi=Bi.trigger,qi=Bi.delegate_on,Ki=Bi.delegate_off;function Qi(t,e){if(e instanceof Array)e.forEach(e=>Qi(t,e));else{if(t.mixedIn=t.hasOwnProperty("mixedIn")?t.mixedIn:[],t.mixingIn=t.hasOwnProperty("mixingIn")?t.mixingIn:[],t.mixedIn.indexOf(e)>=0)return t;if(t.mixingIn.indexOf(e)>=0)throw new Error(`found cyclic dependencies between ${t.mixingIn}`);t.mixingIn.push(e),e.call(t),t.mixingIn.pop(),t.mixedIn.push(e)}return t}const Zi=(...t)=>{const e=[];t.forEach(t=>t&&t.stack&&e.push(t.stack)),console.error("[ERROR]",...t,e.join(" "))},Ji=(...t)=>{const e=[];t.forEach(t=>t&&t.stack&&e.push(t.stack)),console.warn("[WARN]",...t,e.join(" "))},ts=(...t)=>console.log("[DEBUG]",...t);function es(t,e,n){const i=function(t,e){let n=t;for(;n;){const t=Object.getOwnPropertyDescriptor(n,e);if(t?.get)return t;n=Object.getPrototypeOf(n)}}(t,e);if(!i?.get)return void Zi(`${String(e)} is not defined in ${t.constructor.name}`);const s=i.get,r={get:n?function(){return e in this.__cache__?Li.enabled&&Li.cacheHit++:(Li.enabled&&Li.cacheMiss++,this.__cache__[e]=Object.freeze(s.call(this))),this.__cache__[e]}:function(){return e in this.__cache__?Li.enabled&&Li.cacheHit++:(Li.enabled&&Li.cacheMiss++,this.__cache__[e]=s.call(this)),this.__cache__[e]},configurable:!0};i.set&&(r.set=i.set),Object.defineProperty(t,e,r)}var ns="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function is(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function ss(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 rs,os={exports:{}};var as=(rs||(rs=1,function(t){var e=function(t){var e,n=Object.prototype,i=n.hasOwnProperty,s=Object.defineProperty||function(t,e,n){t[e]=n.value},r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",c=r.toStringTag||"@@toStringTag";function l(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,n){return t[e]=n}}function h(t,e,n,i){var r=e&&e.prototype instanceof y?e:y,o=Object.create(r.prototype),a=new P(i||[]);return s(o,"_invoke",{value:A(t,n,a)}),o}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=h;var u="suspendedStart",p="suspendedYield",f="executing",m="completed",g={};function y(){}function b(){}function _(){}var v={};l(v,o,function(){return this});var x=Object.getPrototypeOf,w=x&&x(x(O([])));w&&w!==n&&i.call(w,o)&&(v=w);var M=_.prototype=y.prototype=Object.create(v);function S(t){["next","throw","return"].forEach(function(e){l(t,e,function(t){return this._invoke(e,t)})})}function k(t,e){function n(s,r,o,a){var c=d(t[s],t,r);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==typeof h&&i.call(h,"__await")?e.resolve(h.__await).then(function(t){n("next",t,o,a)},function(t){n("throw",t,o,a)}):e.resolve(h).then(function(t){l.value=t,o(l)},function(t){return n("throw",t,o,a)})}a(c.arg)}var r;s(this,"_invoke",{value:function(t,i){function s(){return new e(function(e,s){n(t,i,e,s)})}return r=r?r.then(s,s):s()}})}function A(t,n,i){var s=u;return function(r,o){if(s===f)throw new Error("Generator is already running");if(s===m){if("throw"===r)throw o;return{value:e,done:!0}}for(i.method=r,i.arg=o;;){var a=i.delegate;if(a){var c=E(a,i);if(c){if(c===g)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(s===u)throw s=m,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);s=f;var l=d(t,n,i);if("normal"===l.type){if(s=i.done?m:p,l.arg===g)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(s=m,i.method="throw",i.arg=l.arg)}}}function E(t,n){var i=n.method,s=t.iterator[i];if(s===e)return n.delegate=null,"throw"===i&&t.iterator.return&&(n.method="return",n.arg=e,E(t,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),g;var r=d(s,t.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,g;var o=r.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,g):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,g)}function C(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(C,this),this.reset(!0)}function 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 s=-1,r=function n(){for(;++s<t.length;)if(i.call(t,s))return n.value=t[s],n.done=!1,n;return n.value=e,n.done=!0,n};return r.next=r}}throw new TypeError(typeof t+" is not iterable")}return b.prototype=_,s(M,"constructor",{value:_,configurable:!0}),s(_,"constructor",{value:b,configurable:!0}),b.displayName=l(_,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,_):(t.__proto__=_,l(t,c,"GeneratorFunction")),t.prototype=Object.create(M),t},t.awrap=function(t){return{__await:t}},S(k.prototype),l(k.prototype,a,function(){return this}),t.AsyncIterator=k,t.async=function(e,n,i,s,r){void 0===r&&(r=Promise);var o=new k(h(e,n,i,s),r);return t.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},S(M),l(M,c,"Generator"),l(M,o,function(){return this}),l(M,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},t.values=O,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(T),!t)for(var n in this)"t"===n.charAt(0)&&i.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function s(i,s){return a.type="throw",a.arg=t,n.next=i,s&&(n.method="next",n.arg=e),!!s}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return s("end");if(o.tryLoc<=this.prev){var c=i.call(o,"catchLoc"),l=i.call(o,"finallyLoc");if(c&&l){if(this.prev<o.catchLoc)return s(o.catchLoc,!0);if(this.prev<o.finallyLoc)return s(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return s(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return s(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var s=this.tryEntries[n];if(s.tryLoc<=this.prev&&i.call(s,"finallyLoc")&&this.prev<s.finallyLoc){var r=s;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=t,o.arg=e,r?(this.method="next",this.next=r.finallyLoc,g):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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var s=i.arg;T(n)}return s}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,i){return this.delegate={iterator:O(t),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=e),g}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}Number.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},String.fromCodePoint||function(t){var e=function(e){for(var n=[],i=0,s="",r=0,o=arguments.length;r!==o;++r){var a=+arguments[r];if(!(a<1114111&&a>>>0===a))throw RangeError("Invalid code point: "+a);a<=65535?i=n.push(a):(a-=65536,i=n.push(55296+(a>>10),a%1024+56320)),i>=16383&&(s+=t.apply(null,n),n.length=0)}return s+t.apply(null,n)};try{Object.defineProperty(String,"fromCodePoint",{value:e,configurable:!0,writable:!0})}catch(t){String.fromCodePoint=e}}(String.fromCharCode),Object.is||(Object.is=function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e})
2
- /*! https://mths.be/codepointat v0.2.0 by @mathias */,String.prototype.codePointAt||function(){var t=function(){try{var t={},e=Object.defineProperty,n=e(t,t,t)&&e}catch(t){}return n}(),e=function(t){if(null==this)throw TypeError();var e=String(this),n=e.length,i=t?Number(t):0;if(i!=i&&(i=0),!(i<0||i>=n)){var s,r=e.charCodeAt(i);return r>=55296&&r<=56319&&n>i+1&&(s=e.charCodeAt(i+1))>=56320&&s<=57343?1024*(r-55296)+s-56320+65536:r}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e}(),Math.log10=Math.log10||function(t){return Math.log(t)*Math.LOG10E},t.exports=function(){function t(e,n,i){function s(o,a){if(!n[o]){if(!e[o]){if(!a&&ss)return ss(o);if(r)return r(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 s(e[o][1][t]||t)},l,l.exports,t,e,n,i)}return n[o].exports}for(var r=ss,o=0;o<i.length;o++)s(i[o]);return s}return t}()({1:[function(t,e,n){var i=t("./utils"),s=function(){var t=i.stringToArray,e=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],n=["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fifteenth","Sixteenth","Seventeenth","Eighteenth","Nineteenth"],s=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],r=["Thousand","Million","Billion","Trillion"];function o(t,i){var o=function(t,i,a){var c="";if(t<=19)c=(i?" and ":"")+(a?n[t]:e[t]);else if(t<100){var l=Math.floor(t/10),h=t%10;c=(i?" and ":"")+s[l-2],h>0?c+="-"+o(h,!1,a):a&&(c=c.substring(0,c.length-1)+"ieth")}else if(t<1e3){var d=Math.floor(t/100),u=t%100;c=(i?", ":"")+e[d]+" Hundred",u>0?c+=o(u,!0,a):a&&(c+="th")}else{var p=Math.floor(Math.log10(t)/3);p>r.length&&(p=r.length);var f=Math.pow(10,3*p),m=Math.floor(t/f),g=t-m*f;c=(i?", ":"")+o(m,!1,!1)+" "+r[p-1],g>0?c+=o(g,!0,a):a&&(c+="th")}return c};return o(t,!1,i)}var a=Object.create(null);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}),s.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,r.forEach(function(t,e){var n=t.toLowerCase(),i=Math.pow(10,3*(e+1));a[n]=i,a[n+"th"]=i});var l=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]],h={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};function d(t){for(var e=0;e<l.length;e++){var n=l[e];if(t>=n[0])return n[1]+d(t-n[0])}return""}function u(t){for(var e=0,n=1,i=t.length-1;i>=0;i--){var s=t[i],r=h[s];r<n?e-=r:(n=r,e+=r)}return e}function p(t,e){for(var n=[],i=e.charCodeAt(0);t>0;)n.unshift(String.fromCharCode((t-1)%26+i)),t=Math.floor((t-1)/26);return n.join("")}function f(t,e){for(var n=e.charCodeAt(0),i=0,s=0;s<t.length;s++)i+=(t.charCodeAt(t.length-s-1)-n+1)*Math.pow(26,s);return i}function m(t,e){if(void 0!==t)return b(t=Math.floor(t),v(e))}var g={DECIMAL:"decimal",LETTERS:"letters",ROMAN:"roman",WORDS:"words",SEQUENCE:"sequence"},y={UPPER:"upper",LOWER:"lower",TITLE:"title"};function b(e,n){var i,s=e<0;switch(e=Math.abs(e),n.primary){case g.LETTERS:i=p(e,n.case===y.UPPER?"A":"a");break;case g.ROMAN:i=d(e),n.case===y.UPPER&&(i=i.toUpperCase());break;case g.WORDS:i=o(e,n.ordinal),n.case===y.UPPER?i=i.toUpperCase():n.case===y.LOWER&&(i=i.toLowerCase());break;case g.DECIMAL:i=""+e;var r=n.mandatoryDigits-i.length;if(r>0){var a=new Array(r+1).join("0");i=a+i}if(48!==n.zeroCode&&(i=t(i).map(function(t){return String.fromCodePoint(t.codePointAt(0)+n.zeroCode-48)}).join("")),n.regular)for(var c=Math.floor((i.length-1)/n.groupingSeparators.position);c>0;c--){var l=i.length-c*n.groupingSeparators.position;i=i.substr(0,l)+n.groupingSeparators.character+i.substr(l)}else n.groupingSeparators.reverse().forEach(function(t){var e=i.length-t.position;i=i.substr(0,e)+t.character+i.substr(e)});if(n.ordinal){var h={1:"st",2:"nd",3:"rd"}[i[i.length-1]];(!h||i.length>1&&"1"===i[i.length-2])&&(h="th"),i+=h}break;case g.SEQUENCE:throw{code:"D3130",value:n.token}}return s&&(i="-"+i),i}var _=[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 v(e){var n,i={type:"integer",primary:g.DECIMAL,case:y.LOWER,ordinal:!1},s=e.lastIndexOf(";");switch(-1===s?n=e:(n=e.substring(0,s),"o"===e.substring(s+1)[0]&&(i.ordinal=!0)),n){case"A":i.case=y.UPPER;case"a":i.primary=g.LETTERS;break;case"I":i.case=y.UPPER;case"i":i.primary=g.ROMAN;break;case"W":i.case=y.UPPER,i.primary=g.WORDS;break;case"Ww":i.case=y.TITLE,i.primary=g.WORDS;break;case"w":i.primary=g.WORDS;break;default:var r=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<_.length;n++){var i=_[n];if(t>=i&&t<=i+9){if(e=!0,o++,l++,null===r)r=i;else if(i!==r)throw{code:"D3131"};break}}e||(35===t?(l++,a++):c.push({position:l,character:String.fromCodePoint(t)}))}),o>0){i.primary=g.DECIMAL,i.zeroCode=r,i.mandatoryDigits=o,i.optionalDigits=a;var h=function(t){if(0===t.length)return 0;for(var e=t[0].character,n=1;n<t.length;n++)if(t[n].character!==e)return 0;for(var i=t.map(function(t){return t.position}),s=function(t,e){return 0===e?t:s(e,t%e)},r=i.reduce(s),o=1;o<=i.length;o++)if(-1===i.indexOf(o*r))return 0;return r}(c);h>0?(i.regular=!0,i.groupingSeparators={position:h,character:c[0].character}):(i.regular=!1,i.groupingSeparators=c)}else i.primary=g.SEQUENCE,i.token=n}return i}var x={Y:"1",M:"1",D:"1",d:"1",F:"n",W:"1",w:"1",X:"1",x:"1",H:"1",h:"1",P:"n",m:"01",s:"01",f:"1",Z:"01:01",z:"01:01",C:"n",E:"n"};function w(t){for(var e=[],n={type:"datetime",parts:e},i=function(n,i){if(i>n){var s=t.substring(n,i);s=s.split("]]").join("]"),e.push({type:"literal",value:s})}},s=0,r=0;r<t.length;){if("["===t.charAt(r)){if("["===t.charAt(r+1)){i(s,r),e.push({type:"literal",value:"["}),s=r+=2;continue}if(i(s,r),s=r,-1===(r=t.indexOf("]",s)))throw{code:"D3135"};var o,a=t.substring(s+1,r),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 m={min:f(u),max:f(p)};c.width=m,o=a.substring(1,l)}else o=a.substring(1);if(1===o.length)c.presentation1=o;else if(o.length>1){var g=o.charAt(o.length-1);-1!=="atco".indexOf(g)?(c.presentation2=g,"o"===g&&(c.ordinal=!0),c.presentation1=o.substring(0,o.length-1)):c.presentation1=o}else c.presentation1=x[c.component];if(void 0===c.presentation1)throw{code:"D3132",value:c.component};if("n"===c.presentation1[0])c.names=y.LOWER;else if("N"===c.presentation1[0])"n"===c.presentation1[1]?c.names=y.TITLE:c.names=y.UPPER;else if(-1!=="YMDdFWwXxHhmsf".indexOf(c.component)){var b=c.presentation1;if(c.presentation2&&(b+=";"+c.presentation2),c.integerFormat=v(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 _=c.integerFormat.mandatoryDigits+c.integerFormat.optionalDigits;_>=2&&(c.n=_)}}"Z"!==c.component&&"z"!==c.component||(c.integerFormat=v(c.presentation1)),e.push(c),s=r+1}r++}return i(s,r),n}var M=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],S=["January","February","March","April","May","June","July","August","September","October","November","December"],k=864e5,A=function(t){var e=Date.UTC(t.year,t.month),n=new Date(e).getUTCDay();return 0===n&&(n=7),n>4?e+(8-n)*k:e-(n-1)*k},E=function(t,e){return{year:t,month:e,nextMonth:function(){return 11===e?E(t+1,0):E(t,e+1)},previousMonth:function(){return 0===e?E(t-1,11):E(t,e-1)},nextYear:function(){return E(t+1,e)},previousYear:function(){return E(t-1,e)}}},C=function(t,e){return(e-t)/(7*k)+1},T=function(t,e){var n;switch(e){case"Y":n=t.getUTCFullYear();break;case"M":n=t.getUTCMonth()+1;break;case"D":n=t.getUTCDate();break;case"d":n=(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-Date.UTC(t.getUTCFullYear(),0))/k+1;break;case"F":0===(n=t.getUTCDay())&&(n=7);break;case"W":var i=E(t.getUTCFullYear(),0),s=A(i),r=Date.UTC(i.year,t.getUTCMonth(),t.getUTCDate()),o=C(s,r);if(o>52)r>=A(i.nextYear())&&(o=1);else if(o<1){var a=A(i.previousYear());o=C(a,r)}n=Math.floor(o);break;case"w":var c=E(t.getUTCFullYear(),t.getUTCMonth()),l=A(c),h=Date.UTC(c.year,c.month,t.getUTCDate()),d=C(l,h);if(d>4)h>=A(c.nextMonth())&&(d=1);else if(d<1){var u=A(c.previousMonth());d=C(u,h)}n=Math.floor(d);break;case"X":var p=E(t.getUTCFullYear(),0),f=A(p),m=A(p.nextYear()),g=t.getTime();n=g<f?p.year-1:g>=m?p.year+1:p.year;break;case"x":var y=E(t.getUTCFullYear(),t.getUTCMonth()),b=A(y),_=y.nextMonth(),v=A(_),x=t.getTime();n=x<b?y.previousMonth().month+1:x>=v?_.month+1:y.month+1;break;case"H":n=t.getUTCHours();break;case"h":n=t.getUTCHours(),0==(n%=12)&&(n=12);break;case"P":n=t.getUTCHours()>=12?"pm":"am";break;case"m":n=t.getUTCMinutes();break;case"s":n=t.getUTCSeconds();break;case"f":n=t.getUTCMilliseconds();break;case"Z":case"z":break;case"C":case"E":n="ISO"}return n},P=null;function O(t,e,n){var i=0,s=0;if(void 0!==n){var r=parseInt(n);i=Math.floor(r/100),s=r%100}var o,a=function(t,e){var n=T(t,e.component);if(-1!=="YMDdFWwXxHhms".indexOf(e.component))if("Y"===e.component&&-1!==e.n&&(n%=Math.pow(10,e.n)),e.names){if("M"===e.component||"x"===e.component)n=S[n-1];else{if("F"!==e.component)throw{code:"D3133",value:e.component};n=M[n]}e.names===y.UPPER?n=n.toUpperCase():e.names===y.LOWER&&(n=n.toLowerCase()),e.width&&n.length>e.width.max&&(n=n.substring(0,e.width.max))}else n=b(n,e.integerFormat);else if("f"===e.component)n=b(n,e.integerFormat);else if("Z"===e.component||"z"===e.component){var r=100*i+s;if(e.integerFormat.regular)n=b(r,e.integerFormat);else{var o=e.integerFormat.mandatoryDigits;if(1===o||2===o)n=b(i,e.integerFormat),0!==s&&(n+=":"+m(s,"00"));else{if(3!==o&&4!==o)throw{code:"D3134",value:o};n=b(r,e.integerFormat)}}r>=0&&(n="+"+n),"z"===e.component&&(n="GMT"+n),0===r&&"t"===e.presentation2&&(n="Z")}return n};void 0===e?(null===P&&(P=w("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),o=P):o=w(e);var c=new Date(t+60*(60*i+s)*1e3),l="";return o.parts.forEach(function(t){"literal"===t.type?l+=t.value:l+=a(c,t)}),l}function D(t){var e=Object.create(null);if("datetime"===t.type)e.type="datetime",e.parts=t.parts.map(function(t){var e=Object.create(null);if("literal"===t.type)e.regex=t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if("Z"===t.component||"z"===t.component){var n;Array.isArray(t.integerFormat.groupingSeparators)||(n=t.integerFormat.groupingSeparators),e.regex="","z"===t.component&&(e.regex="GMT"),e.regex+="[-+][0-9]+",n&&(e.regex+=n.character+"[0-9]+"),e.parse=function(e){"z"===t.component&&(e=e.substring(3));var i=0,s=0;return n?(i=Number.parseInt(e.substring(0,e.indexOf(n.character))),s=Number.parseInt(e.substring(e.indexOf(n.character)+1))):e.length-1<=2?i=Number.parseInt(e):(i=Number.parseInt(e.substring(0,3)),s=Number.parseInt(e.substring(3))),60*i+s}}else if("f"===t.component)e.regex="[0-9]+",e.parse=function(t){return 1e3*parseFloat("0."+t.substring(0,3))};else if(t.integerFormat)t.integerFormat.n=t.n,e=D(t.integerFormat);else{e.regex="[a-zA-Z]+";var i=Object.create(null);if("M"===t.component||"x"===t.component)S.forEach(function(e,n){t.width&&t.width.max?i[e.substring(0,t.width.max)]=n+1:i[e]=n+1});else if("F"===t.component)M.forEach(function(e,n){n>0&&(t.width&&t.width.max?i[e.substring(0,t.width.max)]=n:i[e]=n)});else{if("P"!==t.component)throw{code:"D3133",value:t.component};i={am:0,AM:0,pm:1,PM:1}}e.parse=function(t){return i[t]}}return e.component=t.component,e});else{e.type="integer";var n,s=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 g.LETTERS:e.regex=s?"[A-Z]+":"[a-z]+",e.parse=function(t){return f(t,s?"A":"a")};break;case g.ROMAN:e.regex=s?"[MDCLXVI]+":"[mdclxvi]+",e.parse=function(t){return u(s?t:t.toUpperCase())};break;case g.WORDS:e.regex="(?:"+i.keys(a).concat("and","[\\-, ]").join("|")+")+",e.parse=function(t){return c(t.toLowerCase())};break;case g.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 g.SEQUENCE:throw{code:"D3130",value:t.token}}}return e}function z(t,e){if(void 0!==t)return D(v(e)).parse(t)}function I(t,e){var n=D(w(e)),i="^"+n.parts.map(function(t){return"("+t.regex+")"}).join("")+"$",s=new RegExp(i,"i").exec(t);if(null!==s){for(var r=161,o=130,a=84,c=72,l=23,h=47,d=Object.create(null),u=1;u<s.length;u++){var p=n.parts[u-1];p.parse&&(d[p.component]=p.parse(s[u]))}if(0===Object.getOwnPropertyNames(d).length)return;var f=0,m=function(t){f<<=1,f+=t?1:0},g=function(t){return!(~t&f||!(t&f))};"YXMxWwdD".split("").forEach(function(t){return m(d[t])});var y=!g(r)&&g(o),b=g(a),_=!b&&g(c);f=0,"PHhmsf".split("").forEach(function(t){return m(d[t])});var v=!g(l)&&g(h),x=(y?"YD":b?"XxwF":_?"XWF":"YMD")+(v?"Phmsf":"Hmsf"),M=this.environment.timestamp,S=!1,k=!1;if(x.split("").forEach(function(t){if(void 0===d[t])S?(d[t]=-1!=="MDd".indexOf(t)?1:0,k=!0):d[t]=T(M,t);else if(S=!0,k)throw{code:"D3136"}}),d.M>0?d.M-=1:d.M=0,y){var A=Date.UTC(d.Y,0),E=1e3*(d.d-1)*60*60*24,C=new Date(A+E);d.M=C.getUTCMonth(),d.D=C.getUTCDate()}if(b)throw{code:"D3136"};if(_)throw{code:"D3136"};v&&(d.H=12===d.h?0:d.h,1===d.P&&(d.H+=12));var P=Date.UTC(d.Y,d.M,d.D,d.H,d.m,d.s,d.f);return(d.Z||d.z)&&(P-=60*(d.Z||d.z)*1e3),P}}var R=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(!R.test(t))throw{stack:(new Error).stack,code:"D3110",value:t};return Date.parse(t)}return I.call(this,t,e)}}function L(t,e,n){if(void 0!==t)return O.call(this,t,e,n)}return{formatInteger:m,parseInteger:z,fromMillis:L,toMillis:j}}();e.exports=s},{"./utils":6}],2:[function(t,e,n){(function(n){(function(){function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=s(t))||e){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}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 s(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.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)?r(t,e):void 0}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function a(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(o(t)+" is not iterable")}function c(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var t,e,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",s=n.toStringTag||"@@toStringTag";function r(n,i,s,r){var c=i&&i.prototype instanceof a?i:a,h=Object.create(c.prototype);return l(h,"_invoke",function(n,i,s){var r,a,c,l=0,h=s||[],d=!1,u={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,a=0,c=t,u.n=n,o}};function p(n,i){for(a=n,c=i,e=0;!d&&l&&!s&&e<h.length;e++){var s,r=h[e],p=u.p,f=r[2];n>3?(s=f===i)&&(c=r[(a=r[4])?5:(a=3,3)],r[4]=r[5]=t):r[0]<=p&&((s=n<2&&p<r[1])?(a=0,u.v=i,u.n=r[1]):p<f&&(s=n<3||r[0]>i||i>f)&&(r[4]=n,r[5]=i,u.n=f,a=0))}if(s||n>1)return o;throw d=!0,i}return function(s,h,f){if(l>1)throw TypeError("Generator is already running");for(d&&1===h&&p(h,f),a=h,c=f;(e=a<2?t:c)||!d;){r||(a?a<3?(a>1&&(u.n=-1),p(a,c)):u.n=c:u.v=c);try{if(l=2,r){if(a||(s="next"),e=r[s]){if(!(e=e.call(r,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=r.return)&&e.call(r),a<2&&(c=TypeError("The iterator does not provide a '"+s+"' method"),a=1);r=t}else if((e=(d=u.n<0)?c:n.call(i,u))!==o)break}catch(e){r=t,a=1,c=e}finally{l=1}}return{value:e,done:d}}}(n,s,r),!0),h}var o={};function a(){}function h(){}function d(){}e=Object.getPrototypeOf;var u=[][i]?e(e([][i]())):(l(e={},i,function(){return this}),e),p=d.prototype=a.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,l(t,s,"GeneratorFunction")),t.prototype=Object.create(p),t}return h.prototype=d,l(p,"constructor",d),l(d,"constructor",h),h.displayName="GeneratorFunction",l(d,s,"GeneratorFunction"),l(p),l(p,s,"Generator"),l(p,i,function(){return this}),l(p,"toString",function(){return"[object Generator]"}),(c=function(){return{w:r,m:f}})()}function l(t,e,n,i){var s=Object.defineProperty;try{s({},"",{})}catch(t){s=0}l=function(t,e,n,i){function r(e,n){l(t,e,function(t){return this._invoke(e,n,t)})}e?s?s(t,e,{value:n,enumerable:!i,configurable:!i,writable:!i}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},l(t,e,n,i)}var h=t("./utils"),d=function(){var t=c().m(V),e=c().m(Y),s=c().m(W),r=c().m(U),l=c().m(J),d=c().m(ft),u=c().m(mt),p=c().m(gt),f=c().m(bt),m=c().m(At),g=c().m(Pt),y=c().m(zt),b=h.isNumeric,_=h.isArrayOfStrings,v=h.isArrayOfNumbers,x=h.createSequence,w=h.isSequence,M=h.isFunction,S=h.isLambda,k=h.isIterable,A=h.getFunctionArity,E=h.isDeepEqual,C=h.stringToArray;function T(t){if(void 0!==t){var e=0;return t.forEach(function(t){e+=t}),e}}function P(t){return void 0===t?0:t.length}function O(t){if(void 0!==t&&0!==t.length)return Math.max.apply(Math,t)}function D(t){if(void 0!==t&&0!==t.length)return Math.min.apply(Math,t)}function z(t){if(void 0!==t&&0!==t.length){var e=0;return t.forEach(function(t){e+=t}),e/t.length}}function I(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(M(t))n="";else{if("number"==typeof t&&!isFinite(t))throw{code:"D3001",value:t,stack:(new Error).stack};var i=e?2:0;Array.isArray(t)&&t.outerWrapper&&(t=t[0]),n=JSON.stringify(t,function(t,e){return null!=e&&e.toPrecision&&b(e)?Number(e.toPrecision(15)):e&&M(e)?"":e},i)}return n}}function R(t,e,n){if(void 0!==t){var i=C(t),s=i.length;if(s+e<0&&(e=0),void 0!==n){if(n<=0)return"";var r=e>=0?e+n:s+e+n;return i.slice(e,r).join("")}return i.slice(e).join("")}}function j(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 F(t){if(void 0!==t)return t.toLowerCase()}function N(t){if(void 0!==t)return t.toUpperCase()}function H(t){if(void 0!==t)return C(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 G(t,e,n){if(void 0!==t){var i;void 0!==n&&0!==n.length||(n=" ");var s=Math.abs(e)-H(t);if(s>0){var r=new Array(s+1).join(n);n.length>1&&(r=R(r,0,s)),i=e>0?t+r:r+t}else i=t;return i}}function V(e,n){var i;return c().w(function(t){for(;;)switch(t.n){case 0:if(i=e.apply(this,[n]),!k(i)){t.n=2;break}return t.d(a(i),1);case 1:i=t.v;case 2:if(!i||"number"==typeof i.start||"number"===i.end||Array.isArray(i.groups)||M(i.next)){t.n=3;break}throw{code:"T1010",stack:(new Error).stack};case 3:return t.a(2,i)}},t,this)}function Y(t,n){var i,s;return c().w(function(e){for(;;)switch(e.n){case 0:if(void 0!==t){e.n=1;break}return e.a(2,void 0);case 1:if("string"!=typeof n){e.n=2;break}i=-1!==t.indexOf(n),e.n=4;break;case 2:return e.d(a(V(n,t)),3);case 3:s=e.v,i=void 0!==s;case 4:return e.a(2,i)}},e)}function W(t,e,n){var i,r,o;return c().w(function(s){for(;;)switch(s.n){case 0:if(void 0!==t){s.n=1;break}return s.a(2,void 0);case 1:if(!(n<0)){s.n=2;break}throw{stack:(new Error).stack,value:n,code:"D3040",index:3};case 2:if(i=x(),!(void 0===n||n>0)){s.n=6;break}return r=0,s.d(a(V(e,t)),3);case 3:if(void 0===(o=s.v)){s.n=6;break}case 4:if(void 0===o||!(void 0===n||r<n)){s.n=6;break}return i.push({match:o.match,index:o.start,groups:o.groups}),s.d(a(V(o.next)),5);case 5:o=s.v,r++,s.n=4;break;case 6:return s.a(2,i)}},s)}function U(t,e,n,i){var s,o,l,h,d,u,p,f;return c().w(function(r){for(;;)switch(r.n){case 0:if(void 0!==t){r.n=1;break}return r.a(2,void 0);case 1:if(s=this,""!==e){r.n=2;break}throw{code:"D3010",stack:(new Error).stack,value:e,index:2};case 2:if(!(i<0)){r.n=3;break}throw{code:"D3011",stack:(new Error).stack,value:i,index:4};case 3:if(o="string"==typeof n?function(t){for(var e="",i=0,s=n.indexOf("$",i);-1!==s&&i<n.length;){e+=n.substring(i,s),i=s+1;var r=n.charAt(i);if("$"===r)e+="$",i++;else if("0"===r)e+=t.match,i++;else{var o;if(o=0===t.groups.length?1:Math.floor(Math.log(t.groups.length)*Math.LOG10E)+1,s=parseInt(n.substring(i,i+o),10),o>1&&s>t.groups.length&&(s=parseInt(n.substring(i,i+o-1),10)),isNaN(s))e+="$";else{if(t.groups.length>0){var a=t.groups[s-1];void 0!==a&&(e+=a)}i+=s.toString().length}}s=n.indexOf("$",i)}return e+=n.substring(i)}:n,l="",h=0,!(void 0===i||i>0)){r.n=15;break}if(d=0,"string"!=typeof e){r.n=4;break}for(u=t.indexOf(e,h);-1!==u&&(void 0===i||d<i);)l+=t.substring(h,u),l+=n,h=u+e.length,d++,u=t.indexOf(e,h);l+=t.substring(h),r.n=14;break;case 4:return r.d(a(V(e,t)),5);case 5:if(void 0===(p=r.v)){r.n=13;break}case 6:if(void 0===p||!(void 0===i||d<i)){r.n=12;break}if(l+=t.substring(h,p.start),f=o.apply(s,[p]),!k(f)){r.n=8;break}return r.d(a(f),7);case 7:f=r.v;case 8:if("string"!=typeof f){r.n=9;break}l+=f,r.n=10;break;case 9:throw{code:"D3012",stack:(new Error).stack,value:f};case 10:return h=p.start+p.match.length,d++,r.d(a(V(p.next)),11);case 11:p=r.v,r.n=6;break;case 12:l+=t.substring(h),r.n=14;break;case 13:l=t;case 14:r.n=16;break;case 15:l=t;case 16:return r.a(2,l)}},r,this)}function $(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 X(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 q(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 K(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 Q(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 Z(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 J(t,e,n){var i,s,r,o;return c().w(function(c){for(;;)switch(c.n){case 0:if(void 0!==t){c.n=1;break}return c.a(2,void 0);case 1:if(!(n<0)){c.n=2;break}throw{code:"D3020",stack:(new Error).stack,value:n,index:3};case 2:if(i=[],!(void 0===n||n>0)){c.n=9;break}if("string"!=typeof e){c.n=3;break}i=t.split(e,n),c.n=9;break;case 3:return s=0,c.d(a(V(e,t)),4);case 4:if(void 0===(r=c.v)){c.n=8;break}o=0;case 5:if(void 0===r||!(void 0===n||s<n)){c.n=7;break}return i.push(t.substring(o,r.start)),o=r.end,c.d(a(V(r.next)),6);case 6:r=c.v,s++,c.n=5;break;case 7:(void 0===n||s<n)&&i.push(t.substring(o)),c.n=9;break;case 8:i.push(t);case 9:return c.a(2,i)}},l)}function tt(t,e){if(void 0!==t)return void 0===e&&(e=""),t.join(e)}function et(t,e,n){if(void 0!==t){var i={"decimal-separator":".","grouping-separator":",","exponent-separator":"e",infinity:"Infinity","minus-sign":"-",NaN:"NaN",percent:"%","per-mille":"‰","zero-digit":"0",digit:"#","pattern-separator":";"};void 0!==n&&h.keys(n).forEach(function(t){i[t]=n[t]});for(var s=[],r=i["zero-digit"].charCodeAt(0),o=r;o<r+10;o++)s.push(String.fromCharCode(o));var a=s.concat([i["decimal-separator"],i["exponent-separator"],i["grouping-separator"],i.digit,i["pattern-separator"]]),c=e.split(i["pattern-separator"]);if(c.length>2)throw{code:"D3080",stack:(new Error).stack};var l=function(t){var e,n,s,r,o=function(){for(var e,n=0;n<t.length;n++)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(0,n)}(),c=function(){for(var e,n=t.length-1;n>=0;n--)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(n+1)}(),l=t.substring(o.length,t.length-c.length),h=t.indexOf(i["exponent-separator"],o.length);-1===h||h>t.length-c.length?(e=l,n=void 0):(e=l.substring(0,h),n=l.substring(h+1));var d=e.indexOf(i["decimal-separator"]);return-1===d?(s=e,r=c):(s=e.substring(0,d),r=e.substring(d+1)),{prefix:o,suffix:c,activePart:l,mantissaPart:e,exponentPart:n,integerPart:s,fractionalPart:r,subpicture:t}},d=function(t){var e,n,r=t.subpicture,o=r.indexOf(i["decimal-separator"]);o!==r.lastIndexOf(i["decimal-separator"])&&(e="D3081"),r.indexOf(i.percent)!==r.lastIndexOf(i.percent)&&(e="D3082"),r.indexOf(i["per-mille"])!==r.lastIndexOf(i["per-mille"])&&(e="D3083"),-1!==r.indexOf(i.percent)&&-1!==r.indexOf(i["per-mille"])&&(e="D3084");var c=!1;for(n=0;n<t.mantissaPart.length;n++){var l=t.mantissaPart.charAt(n);if(-1!==s.indexOf(l)||l===i.digit){c=!0;break}}c||(e="D3085"),-1!==t.activePart.split("").map(function(t){return-1===a.indexOf(t)?"p":"a"}).join("").indexOf("p")&&(e="D3086"),-1!==o?r.charAt(o-1)!==i["grouping-separator"]&&r.charAt(o+1)!==i["grouping-separator"]||(e="D3087"):t.integerPart.charAt(t.integerPart.length-1)===i["grouping-separator"]&&(e="D3088"),-1!==r.indexOf(i["grouping-separator"]+i["grouping-separator"])&&(e="D3089");var h=t.integerPart.indexOf(i.digit);-1!==h&&t.integerPart.substring(0,h).split("").filter(function(t){return s.indexOf(t)>-1}).length>0&&(e="D3090"),-1!==(h=t.fractionalPart.lastIndexOf(i.digit))&&t.fractionalPart.substring(h).split("").filter(function(t){return s.indexOf(t)>-1}).length>0&&(e="D3091");var d="string"==typeof t.exponentPart;if(d&&t.exponentPart.length>0&&(-1!==r.indexOf(i.percent)||-1!==r.indexOf(i["per-mille"]))&&(e="D3092"),d&&(0===t.exponentPart.length||t.exponentPart.split("").filter(function(t){return-1===s.indexOf(t)}).length>0)&&(e="D3093"),e)throw{code:e,stack:(new Error).stack}},u=function(t){var e=function(e,n){for(var r=[],o=e.indexOf(i["grouping-separator"]);-1!==o;){var a=(n?e.substring(0,o):e.substring(o)).split("").filter(function(t){return-1!==s.indexOf(t)||t===i.digit}).length;r.push(a),o=t.integerPart.indexOf(i["grouping-separator"],o+1)}return r},n=e(t.integerPart),r=function(t){if(0===t.length)return 0;for(var e=function(t,n){return 0===n?t:e(n,t%n)},n=t.reduce(e),i=1;i<=t.length;i++)if(-1===t.indexOf(i*n))return 0;return n}(n),o=e(t.fractionalPart,!0),a=t.integerPart.split("").filter(function(t){return-1!==s.indexOf(t)}).length,c=a,l=t.fractionalPart.split(""),h=l.filter(function(t){return-1!==s.indexOf(t)}).length,d=l.filter(function(t){return-1!==s.indexOf(t)||t===i.digit}).length,u="string"==typeof t.exponentPart;0===a&&0===d&&(u?(h=1,d=1):a=1),u&&0===a&&-1!==t.integerPart.indexOf(i.digit)&&(a=1),0===a&&0===h&&(h=1);var p=0;return u&&(p=t.exponentPart.split("").filter(function(t){return-1!==s.indexOf(t)}).length),{integerPartGroupingPositions:n,regularGrouping:r,minimumIntegerPartSize:a,scalingFactor:c,prefix:t.prefix,fractionalPartGroupingPositions:o,minimumFactionalPartSize:h,maximumFactionalPartSize:d,minimumExponentSize:p,suffix:t.suffix,picture:t.subpicture}},p=c.map(l);p.forEach(d);var f,m,g,y,b=p.map(u),_=i["minus-sign"],v=i["zero-digit"],x=i["decimal-separator"],w=i["grouping-separator"];if(1===b.length&&(b.push(JSON.parse(JSON.stringify(b[0]))),b[1].prefix=_+b[1].prefix),m=-1!==(f=t>=0?b[0]:b[1]).picture.indexOf(i.percent)?100*t:-1!==f.picture.indexOf(i["per-mille"])?1e3*t:t,0===f.minimumExponentSize)g=m;else{var M=Math.pow(10,f.scalingFactor),S=Math.pow(10,f.scalingFactor-1);for(g=m,y=0;g<S;)g*=10,y-=1;for(;g>M;)g/=10,y+=1}var k=function(t,e){var n=Math.abs(t).toFixed(e);return"0"!==v&&(n=n.split("").map(function(t){return t>="0"&&t<="9"?s[t.charCodeAt(0)-48]:t}).join("")),n},A=k(at(g,f.maximumFactionalPartSize),f.maximumFactionalPartSize),E=A.indexOf(".");for(-1===E?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);E=A.indexOf(x);var C=f.minimumIntegerPartSize-E,T=f.minimumFactionalPartSize-(A.length-E-1);if(A=(C>0?new Array(C+1).join(v):"")+A,A+=T>0?new Array(T+1).join(v):"",E=A.indexOf(x),f.regularGrouping>0)for(var P=Math.floor((E-1)/f.regularGrouping),O=1;O<=P;O++)A=[A.slice(0,E-O*f.regularGrouping),w,A.slice(E-O*f.regularGrouping)].join("");else f.integerPartGroupingPositions.forEach(function(t){A=[A.slice(0,E-t),w,A.slice(E-t)].join(""),E++});if(E=A.indexOf(x),f.fractionalPartGroupingPositions.forEach(function(t){A=[A.slice(0,t+E+1),w,A.slice(t+E+1)].join("")}),E=A.indexOf(x),-1!==f.picture.indexOf(x)&&E!==A.length-1||(A=A.substring(0,A.length-1)),void 0!==y){var D=k(y,0);(C=f.minimumExponentSize-D.length)>0&&(D=new Array(C+1).join(v)+D),A=A+i["exponent-separator"]+(y<0?_:"")+D}return A=f.prefix+A+f.suffix}}function nt(t,e){if(void 0!==t){if(t=at(t),(e=void 0===e?10:at(e))<2||e>36)throw{code:"D3100",stack:(new Error).stack,value:e};return t.toString(e)}}function it(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 st(t){if(void 0!==t)return Math.abs(t)}function rt(t){if(void 0!==t)return Math.floor(t)}function ot(t){if(void 0!==t)return Math.ceil(t)}function at(t,e){var n;if(void 0!==t){if(e){var i=t.toString().split("e");t=+(i[0]+"e"+(i[1]?+i[1]+e:e))}var s=(n=Math.round(t))-t;return.5===Math.abs(s)&&1===Math.abs(n%2)&&(n-=1),e&&(i=n.toString().split("e"),n=+(i[0]+"e"+(i[1]?+i[1]-e:-e))),Object.is(n,-0)&&(n=0),n}}function ct(t){if(void 0!==t){if(t<0)throw{stack:(new Error).stack,code:"D3060",index:1,value:t};return Math.sqrt(t)}}function lt(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 ht(){return Math.random()}function dt(t){if(void 0!==t){var e=!1;return Array.isArray(t)?1===t.length?e=dt(t[0]):t.length>1&&(e=t.filter(function(t){return dt(t)}).length>0):"string"==typeof t?t.length>0&&(e=!0):b(t)?0!==t&&(e=!0):null!==t&&"object"===o(t)?h.keys(t).length>0&&(e=!0):"boolean"==typeof t&&!0===t&&(e=!0),e}}function ut(t){if(void 0!==t)return!dt(t)}function pt(t,e,n,i){var s=[e],r=A(t);return r>=2&&s.push(n),r>=3&&s.push(i),s}function ft(t,e){var n,i,s,r;return c().w(function(o){for(;;)switch(o.n){case 0:if(void 0!==t){o.n=1;break}return o.a(2,void 0);case 1:n=x(),i=0;case 2:if(!(i<t.length)){o.n=5;break}return s=pt(e,t[i],i,t),o.d(a(e.apply(this,s)),3);case 3:void 0!==(r=o.v)&&n.push(r);case 4:i++,o.n=2;break;case 5:return o.a(2,n)}},d,this)}function mt(t,e){var n,i,s,r;return c().w(function(o){for(;;)switch(o.n){case 0:if(void 0!==t){o.n=1;break}return o.a(2,void 0);case 1:n=x(),i=0;case 2:if(!(i<t.length)){o.n=5;break}return s=t[i],r=pt(e,s,i,t),o.d(a(e.apply(this,r)),3);case 3:dt(o.v)&&n.push(s);case 4:i++,o.n=2;break;case 5:return o.a(2,n)}},u,this)}function gt(t,e){var n,i,s,r,o,l,h;return c().w(function(c){for(;;)switch(c.n){case 0:if(void 0!==t){c.n=1;break}return c.a(2,void 0);case 1:n=!1,s=0;case 2:if(!(s<t.length)){c.n=7;break}if(r=t[s],o=!0,void 0===e){c.n=4;break}return l=pt(e,r,s,t),c.d(a(e.apply(this,l)),3);case 3:h=c.v,o=dt(h);case 4:if(!o){c.n=6;break}if(n){c.n=5;break}i=r,n=!0,c.n=6;break;case 5:throw{stack:(new Error).stack,code:"D3138",index:s};case 6:s++,c.n=2;break;case 7:if(n){c.n=8;break}throw{stack:(new Error).stack,code:"D3139"};case 8:return c.a(2,i)}},p,this)}function yt(){for(var t=[],e=Array.prototype.slice.call(arguments),n=Math.min.apply(Math,e.map(function(t){return Array.isArray(t)?t.length:0})),i=0;i<n;i++){var s=e.map(function(t){return t[i]});t.push(s)}return t}function bt(t,e,n){var i,s,r,o;return c().w(function(c){for(;;)switch(c.n){case 0:if(void 0!==t){c.n=1;break}return c.a(2,void 0);case 1:if(!((s=A(e))<2)){c.n=2;break}throw{stack:(new Error).stack,code:"D3050",index:1};case 2:void 0===n&&t.length>0?(i=t[0],r=1):(i=n,r=0);case 3:if(!(r<t.length)){c.n=5;break}return o=[i,t[r]],s>=3&&o.push(r),s>=4&&o.push(t),c.d(a(e.apply(this,o)),4);case 4:i=c.v,r++,c.n=3;break;case 5:return c.a(2,i)}},f,this)}function _t(t){var e=x();if(Array.isArray(t)){var n=Object.create(null);t.forEach(function(t){_t(t).forEach(function(t){n[t]=!0})}),e=_t(n)}else null===t||"object"!==o(t)||S(t)||h.keys(t).forEach(function(t){return e.push(t)});return e}function vt(t,e){var n;if(Array.isArray(t)){n=x();for(var i=0;i<t.length;i++){var s=vt(t[i],e);void 0!==s&&(Array.isArray(s)?s.forEach(function(t){return n.push(t)}):n.push(s))}}else null!==t&&"object"===o(t)&&Object.prototype.hasOwnProperty.call(t,e)&&!M(t)&&(n=t[e]);return n}function xt(t,e){return void 0===t?e:void 0===e?t:(Array.isArray(t)||(t=x(t)),Array.isArray(e)||(e=[e]),t.concat(e))}function wt(t){return void 0!==t}function Mt(t){var e=x();if(Array.isArray(t))t.forEach(function(t){e=xt(e,Mt(t))});else if(null===t||"object"!==o(t)||S(t))e=t;else{var n,s=i(h.keys(t));try{for(s.s();!(n=s.n()).done;){var r=n.value,a=Object.create(null);a[r]=t[r],e.push(a)}}catch(t){s.e(t)}finally{s.f()}}return e}function St(t){if(void 0!==t){var e=Object.create(null);return t.forEach(function(t){var n,s=i(h.keys(t));try{for(s.s();!(n=s.n()).done;){var r=n.value;e[r]=t[r]}}catch(t){s.e(t)}finally{s.f()}}),e}}function kt(t){if(void 0!==t){if(t.length<=1)return t;for(var e=t.length,n=new Array(e),i=0;i<e;i++)n[e-i-1]=t[i];return n}}function At(t,e){var n,s,r,o,l,d,u;return c().w(function(c){for(;;)switch(c.p=c.n){case 0:n=x(),s=i(h.keys(t)),c.p=1,s.s();case 2:if((r=s.n()).done){c.n=5;break}return o=r.value,l=pt(e,t[o],o,t),c.d(a(e.apply(this,l)),3);case 3:void 0!==(d=c.v)&&n.push(d);case 4:c.n=2;break;case 5:c.n=7;break;case 6:c.p=6,u=c.v,s.e(u);case 7:return c.p=7,s.f(),c.f(7);case 8:return c.a(2,n)}},m,this,[[1,6,7,8]])}function Et(t){throw{code:"D3137",stack:(new Error).stack,message:t||"$error() function evaluated"}}function Ct(t,e){if(!t)throw{code:"D3141",stack:(new Error).stack,message:e||"$assert() statement failed"}}function Tt(t){if(void 0!==t)return null===t?"null":b(t)?"number":"string"==typeof t?"string":"boolean"==typeof t?"boolean":Array.isArray(t)?"array":M(t)?"function":"object"}function Pt(t,e){var n,i,s,r;return c().w(function(o){for(;;)switch(o.n){case 0:if(void 0!==t){o.n=1;break}return o.a(2,void 0);case 1:if(!(t.length<=1)){o.n=2;break}return o.a(2,t);case 2:if(void 0!==e){o.n=4;break}if(v(t)||_(t)){o.n=3;break}throw{stack:(new Error).stack,code:"D3070",index:1};case 3:n=c().m(function t(e,n){return c().w(function(t){for(;;)if(0===t.n)return t.a(2,e>n)},t)}),o.n=5;break;case 4:n=e;case 5:return i=c().m(function t(e,i){var s,r;return c().w(function(t){for(;;)switch(t.n){case 0:return s=c().m(function t(e,i,r){return c().w(function(t){for(;;)switch(t.n){case 0:if(0!==i.length){t.n=1;break}Array.prototype.push.apply(e,r),t.n=6;break;case 1:if(0!==r.length){t.n=2;break}Array.prototype.push.apply(e,i),t.n=6;break;case 2:return t.d(a(n(i[0],r[0])),3);case 3:if(!t.v){t.n=5;break}return e.push(r[0]),t.d(a(s(e,i,r.slice(1))),4);case 4:t.n=6;break;case 5:return e.push(i[0]),t.d(a(s(e,i.slice(1),r)),6);case 6:return t.a(2)}},t)}),r=[],t.d(a(s(r,e,i)),1);case 1:return t.a(2,r)}},t)}),s=c().m(function t(e){var n,r,o;return c().w(function(t){for(;;)switch(t.n){case 0:if(Array.isArray(e)&&!(e.length<=1)){t.n=1;break}return t.a(2,e);case 1:return n=Math.floor(e.length/2),r=e.slice(0,n),o=e.slice(n),t.d(a(s(r)),2);case 2:return r=t.v,t.d(a(s(o)),3);case 3:return o=t.v,t.d(a(i(r,o)),4);case 4:return t.a(2,t.v);case 5:return t.a(2)}},t)}),o.d(a(s(t)),6);case 6:return r=o.v,o.a(2,r)}},g)}function Ot(t){if(void 0!==t){if(t.length<=1)return t;for(var e=new Array(t.length),n=0;n<t.length;n++){var i=Math.floor(Math.random()*(n+1));n!==i&&(e[n]=e[i]),e[i]=t[n]}return e}}function Dt(t){if(void 0!==t){if(!Array.isArray(t)||t.length<=1)return t;for(var e=w(t)?x():[],n=0;n<t.length;n++){for(var i=t[n],s=!1,r=0;r<e.length;r++)if(E(i,e[r])){s=!0;break}s||e.push(i)}return e}}function zt(t,e){var n,s,r,o,l,d,u;return c().w(function(c){for(;;)switch(c.p=c.n){case 0:n=Object.create(null),s=i(h.keys(t)),c.p=1,s.s();case 2:if((r=s.n()).done){c.n=5;break}return o=r.value,l=t[o],d=pt(e,l,o,t),c.d(a(e.apply(this,d)),3);case 3:dt(c.v)&&(n[o]=l);case 4:c.n=2;break;case 5:c.n=7;break;case 6:c.p=6,u=c.v,s.e(u);case 7:return c.p=7,s.f(),c.f(7);case 8:return 0===h.keys(n).length&&(n=void 0),c.a(2,n)}},y,this,[[1,6,7,8]])}return{sum:T,count:P,max:O,min:D,average:z,string:I,substring:R,substringBefore:j,substringAfter:L,lowercase:F,uppercase:N,length:H,trim:B,pad:G,match:W,contains:Y,replace:U,split:J,join:tt,formatNumber:et,formatBase:nt,number:it,floor:rt,ceil:ot,round:at,abs:st,sqrt:ct,power:lt,random:ht,boolean:dt,not:ut,map:ft,zip:yt,filter:mt,single:gt,foldLeft:bt,sift:zt,keys:_t,lookup:vt,append:xt,exists:wt,spread:Mt,merge:St,reverse:kt,each:At,error:Et,assert:Ct,type:Tt,sort:Pt,shuffle:Ot,distinct:Dt,base64encode:$,base64decode:X,encodeUrlComponent:q,encodeUrl:K,decodeUrlComponent:Q,decodeUrl:Z}}();e.exports=d}).call(this)}).call(this,void 0!==ns?ns:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils":6}],3:[function(t,e,n){function i(t){var e=Object(t),n=[];for(var i in e)n.unshift(i);return function t(){for(;n.length;)if((i=n.pop())in e)return t.value=i,t.done=!1,t;return t.done=!0,t}}function s(t){return s="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},s(t)}function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e){n&&(t=n);var i=0,s=function(){};return{s:s,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}function o(t,e){if(t){if("string"==typeof t)return a(t,e);var n={}.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)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function c(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(s(t)+" is not iterable")}function l(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var t,e,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",s=n.toStringTag||"@@toStringTag";function r(n,i,s,r){var c=i&&i.prototype instanceof a?i:a,l=Object.create(c.prototype);return h(l,"_invoke",function(n,i,s){var r,a,c,l=0,h=s||[],d=!1,u={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,a=0,c=t,u.n=n,o}};function p(n,i){for(a=n,c=i,e=0;!d&&l&&!s&&e<h.length;e++){var s,r=h[e],p=u.p,f=r[2];n>3?(s=f===i)&&(c=r[(a=r[4])?5:(a=3,3)],r[4]=r[5]=t):r[0]<=p&&((s=n<2&&p<r[1])?(a=0,u.v=i,u.n=r[1]):p<f&&(s=n<3||r[0]>i||i>f)&&(r[4]=n,r[5]=i,u.n=f,a=0))}if(s||n>1)return o;throw d=!0,i}return function(s,h,f){if(l>1)throw TypeError("Generator is already running");for(d&&1===h&&p(h,f),a=h,c=f;(e=a<2?t:c)||!d;){r||(a?a<3?(a>1&&(u.n=-1),p(a,c)):u.n=c:u.v=c);try{if(l=2,r){if(a||(s="next"),e=r[s]){if(!(e=e.call(r,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=r.return)&&e.call(r),a<2&&(c=TypeError("The iterator does not provide a '"+s+"' method"),a=1);r=t}else if((e=(d=u.n<0)?c:n.call(i,u))!==o)break}catch(e){r=t,a=1,c=e}finally{l=1}}return{value:e,done:d}}}(n,s,r),!0),l}var o={};function a(){}function c(){}function d(){}e=Object.getPrototypeOf;var u=[][i]?e(e([][i]())):(h(e={},i,function(){return this}),e),p=d.prototype=a.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,h(t,s,"GeneratorFunction")),t.prototype=Object.create(p),t}return c.prototype=d,h(p,"constructor",d),h(d,"constructor",c),c.displayName="GeneratorFunction",h(d,s,"GeneratorFunction"),h(p),h(p,s,"Generator"),h(p,i,function(){return this}),h(p,"toString",function(){return"[object Generator]"}),(l=function(){return{w:r,m:f}})()}function h(t,e,n,i){var s=Object.defineProperty;try{s({},"",{})}catch(t){s=0}h=function(t,e,n,i){function r(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?s?s(t,e,{value:n,enumerable:!i,configurable:!i,writable:!i}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},h(t,e,n,i)}var d=t("./datetime"),u=t("./functions"),p=t("./utils"),f=t("./parser"),m=t("./signature"),g=function(){var t=l().m(V),e=l().m(Y),n=l().m(U),o=l().m($),a=l().m(X),h=l().m(q),g=l().m(K),y=l().m(Q),b=l().m(ct),_=l().m(dt),v=l().m(ft),x=l().m(mt),w=l().m(gt),M=l().m(_t),S=l().m(wt),k=l().m(Mt),A=l().m(St),E=l().m(kt),C=l().m(Et),T=l().m(Tt),P=l().m(Dt),O=l().m(Rt),D=p.isNumeric,z=p.isArrayOfStrings,I=p.isArrayOfNumbers,R=p.createSequence,j=p.isSequence,L=p.isFunction,F=p.isLambda,N=p.isIterable,H=p.getFunctionArity,B=p.isDeepEqual,G=Lt(null);function V(e,n,i){var s,r,o,a,h;return l().w(function(t){for(;;)switch(t.n){case 0:(r=i.lookup("__evaluate_entry"))&&r(e,n,i),h=e.type,t.n="path"===h?1:"binary"===h?3:"unary"===h?5:"name"===h?7:"string"===h||"number"===h||"value"===h?8:"wildcard"===h?9:"descendant"===h?10:"parent"===h?11:"condition"===h?12:"block"===h?14:"bind"===h?16:"regex"===h?18:"function"===h?19:"variable"===h?21:"lambda"===h?22:"partial"===h?23:"apply"===h?25:"transform"===h?27:28;break;case 1:return t.d(c(Y(e,n,i)),2);case 2:return s=t.v,t.a(3,28);case 3:return t.d(c(K(e,n,i)),4);case 4:return s=t.v,t.a(3,28);case 5:return t.d(c(Q(e,n,i)),6);case 6:return s=t.v,t.a(3,28);case 7:return s=Z(e,n),t.a(3,28);case 8:return s=J(e),t.a(3,28);case 9:return s=tt(e,n),t.a(3,28);case 10:return s=nt(e,n),t.a(3,28);case 11:return s=i.lookup(e.slot.label),t.a(3,28);case 12:return t.d(c(mt(e,n,i)),13);case 13:return s=t.v,t.a(3,28);case 14:return t.d(c(gt(e,n,i)),15);case 15:return s=t.v,t.a(3,28);case 16:return t.d(c(ft(e,n,i)),17);case 17:return s=t.v,t.a(3,28);case 18:return s=yt(e),t.a(3,28);case 19:return t.d(c(Mt(e,n,i)),20);case 20:return s=t.v,t.a(3,28);case 21:return s=bt(e,n,i),t.a(3,28);case 22:return s=At(e,n,i),t.a(3,28);case 23:return t.d(c(Et(e,n,i)),24);case 24:return s=t.v,t.a(3,28);case 25:return t.d(c(wt(e,n,i)),26);case 26:return s=t.v,t.a(3,28);case 27:return s=vt(e,n,i),t.a(3,28);case 28:if(!i.async||null!=s&&"function"==typeof s.then||(s=Promise.resolve(s)),!i.async||"function"!=typeof s.then||!e.nextFunction||"function"!=typeof s[e.nextFunction]){t.n=29;break}t.n=31;break;case 29:return t.n=30,s;case 30:s=t.v;case 31:if(!Object.prototype.hasOwnProperty.call(e,"predicate")){t.n=35;break}o=0;case 32:if(!(o<e.predicate.length)){t.n=35;break}return t.d(c(q(e.predicate[o].expr,s,i)),33);case 33:s=t.v;case 34:o++,t.n=32;break;case 35:if("path"===e.type||!Object.prototype.hasOwnProperty.call(e,"group")){t.n=37;break}return t.d(c(dt(e.group,s,i)),36);case 36:s=t.v;case 37:return(a=i.lookup("__evaluate_exit"))&&a(e,n,i,s),s&&j(s)&&!s.tupleStream&&(e.keepArray&&(s.keepSingleton=!0),0===s.length?s=void 0:1===s.length&&(s=s.keepSingleton?s:s[0])),t.a(2,s)}},t)}function Y(t,n,i){var s,r,o,a,h,d;return l().w(function(e){for(;;)switch(e.n){case 0:s=Array.isArray(n)&&"variable"!==t.steps[0].type?n:R(n),o=!1,a=void 0,h=0;case 1:if(!(h<t.steps.length)){e.n=10;break}if((d=t.steps[h]).tuple&&(o=!0),0!==h||!d.consarray){e.n=3;break}return e.d(c(V(d,s,i)),2);case 2:r=e.v,e.n=7;break;case 3:if(!o){e.n=5;break}return e.d(c(X(d,s,a,i)),4);case 4:a=e.v,e.n=7;break;case 5:return e.d(c(U(d,s,i,h===t.steps.length-1)),6);case 6:r=e.v;case 7:if(o||void 0!==r&&0!==r.length){e.n=8;break}return e.a(3,10);case 8:void 0===d.focus&&(s=r);case 9:h++,e.n=1;break;case 10:if(o)if(t.tuple)r=a;else for(r=R(),h=0;h<a.length;h++)r.push(a[h]["@"]);if(t.keepSingletonArray&&(Array.isArray(r)&&r.cons&&!r.sequence&&(r=R(r)),r.keepSingleton=!0),!Object.prototype.hasOwnProperty.call(t,"group")){e.n=12;break}return e.d(c(dt(t.group,o?a:r,i)),11);case 11:r=e.v;case 12:return e.a(2,r)}},e)}function W(t,e){var n,i=Lt(t),s=r(p.keys(e));try{for(s.s();!(n=s.n()).done;){var o=n.value;i.bind(o,e[o])}}catch(t){s.e(t)}finally{s.f()}return i}function U(t,e,i,s){var r,o,a,h,d;return l().w(function(n){for(;;)switch(n.n){case 0:if("sort"!==t.type){n.n=4;break}return n.d(c(_t(t,e,i)),1);case 1:if(r=n.v,!t.stages){n.n=3;break}return n.d(c($(t.stages,r,i)),2);case 2:r=n.v;case 3:return n.a(2,r);case 4:r=R(),o=0;case 5:if(!(o<e.length)){n.n=12;break}return n.d(c(V(t,e[o],i)),6);case 6:if(a=n.v,!t.stages){n.n=10;break}h=0;case 7:if(!(h<t.stages.length)){n.n=10;break}return n.d(c(q(t.stages[h].expr,a,i)),8);case 8:a=n.v;case 9:h++,n.n=7;break;case 10:void 0!==a&&r.push(a);case 11:o++,n.n=5;break;case 12:return d=R(),s&&1===r.length&&Array.isArray(r[0])&&!j(r[0])?d=r[0]:Array.prototype.forEach.call(r,function(t){!Array.isArray(t)||t.cons?d.push(t):Array.prototype.forEach.call(t,function(t){return d.push(t)})}),n.a(2,d)}},n)}function $(t,e,n){var i,s,r,a,h;return l().w(function(o){for(;;)switch(o.n){case 0:i=e,s=0;case 1:if(!(s<t.length)){o.n=6;break}r=t[s],h=r.type,o.n="filter"===h?2:"index"===h?4:5;break;case 2:return o.d(c(q(r.expr,i,n)),3);case 3:return i=o.v,o.a(3,5);case 4:for(a=0;a<i.length;a++)i[a][r.value]=a;return o.a(3,5);case 5:s++,o.n=1;break;case 6:return o.a(2,i)}},o)}function X(t,e,n,i){var s,r,o,h,d,u,p,f;return l().w(function(a){for(;;)switch(a.n){case 0:if("sort"!==t.type){a.n=7;break}if(!n){a.n=2;break}return a.d(c(_t(t,n,i)),1);case 1:s=a.v,a.n=4;break;case 2:return a.d(c(_t(t,e,i)),3);case 3:for(r=a.v,(s=R()).tupleStream=!0,o=0;o<r.length;o++)(h={"@":r[o]})[t.index]=o,s.push(h);case 4:if(!t.stages){a.n=6;break}return a.d(c($(t.stages,s,i)),5);case 5:s=a.v;case 6:return a.a(2,s);case 7:(s=R()).tupleStream=!0,d=i,void 0===n&&(n=e.map(function(t){return{"@":t}})),u=0;case 8:if(!(u<n.length)){a.n=11;break}return d=W(i,n[u]),a.d(c(V(t,n[u]["@"],d)),9);case 9:if(void 0!==(p=a.v))for(Array.isArray(p)||(p=[p]),f=0;f<p.length;f++)h=Object.create(null),Object.assign(h,n[u]),p.tupleStream?Object.assign(h,p[f]):(t.focus?(h[t.focus]=p[f],h["@"]=n[u]["@"]):h["@"]=p[f],t.index&&(h[t.index]=f),t.ancestor&&(h[t.ancestor.label]=n[u]["@"])),s.push(h);case 10:u++,a.n=8;break;case 11:if(!t.stages){a.n=13;break}return a.d(c($(t.stages,s,i)),12);case 12:s=a.v;case 13:return a.a(2,s)}},a)}function q(t,e,n){var i,s,r,o,a,d;return l().w(function(l){for(;;)switch(l.n){case 0:if(i=R(),e&&e.tupleStream&&(i.tupleStream=!0),Array.isArray(e)||(e=R(e)),"number"!==t.type){l.n=1;break}(s=Math.floor(t.value))<0&&(s=e.length+s),void 0!==(r=e[s])&&(Array.isArray(r)?i=r:i.push(r)),l.n=5;break;case 1:s=0;case 2:if(!(s<e.length)){l.n=5;break}return r=e[s],o=r,a=n,e.tupleStream&&(o=r["@"],a=W(n,r)),l.d(c(V(t,o,a)),3);case 3:d=l.v,D(d)&&(d=[d]),I(d)?Array.prototype.forEach.call(d,function(t){var n=Math.floor(t);n<0&&(n=e.length+n),n===s&&i.push(r)}):u.boolean(d)&&i.push(r);case 4:s++,l.n=2;break;case 5:return l.a(2,i)}},h)}function K(t,e,n){var i,s,r,o,a,h,d,u;return l().w(function(p){for(;;)switch(p.p=p.n){case 0:return p.d(c(V(t.lhs,e,n)),1);case 1:if(s=p.v,r=t.value,o=l().m(function i(){return l().w(function(i){for(;;)switch(i.n){case 0:return i.d(c(V(t.rhs,e,n)),1);case 1:return i.a(2,i.v)}},i)}),"and"!==r&&"or"!==r){p.n=5;break}return p.p=2,p.d(c(ct(s,o,r)),3);case 3:return p.a(2,p.v);case 4:throw p.p=4,(h=p.v).position=t.position,h.token=r,h;case 5:return p.d(c(o()),6);case 6:a=p.v,p.p=7,d=r,p.n="+"===d||"-"===d||"*"===d||"/"===d||"%"===d?8:"="===d||"!="===d?9:"<"===d||"<="===d||">"===d||">="===d?10:"&"===d?11:".."===d?12:"in"===d?13:14;break;case 8:return i=st(s,a,r),p.a(3,14);case 9:return i=rt(s,a,r),p.a(3,14);case 10:return i=ot(s,a,r),p.a(3,14);case 11:return i=ht(s,a),p.a(3,14);case 12:return i=pt(s,a),p.a(3,14);case 13:return i=at(s,a),p.a(3,14);case 14:p.n=16;break;case 15:throw p.p=15,(u=p.v).position=t.position,u.token=r,u;case 16:return p.a(2,i)}},g,null,[[7,15],[2,4]])}function Q(t,e,n){var i,s,r,o,a;return l().w(function(l){for(;;)switch(l.n){case 0:a=t.value,l.n="-"===a?1:"["===a?6:"{"===a?11:13;break;case 1:return l.d(c(V(t.expression,e,n)),2);case 2:if(void 0!==(i=l.v)){l.n=3;break}i=void 0,l.n=5;break;case 3:if(!D(i)){l.n=4;break}i=-i,l.n=5;break;case 4:throw{code:"D1002",stack:(new Error).stack,position:t.position,token:t.value,value:i};case 5:return l.a(3,13);case 6:i=[],s=0;case 7:if(!(s<t.expressions.length)){l.n=10;break}return r=t.expressions[s],l.d(c(V(r,e,n)),8);case 8:void 0!==(o=l.v)&&("["===r.value?i.push(o):i=u.append(i,o));case 9:s++,l.n=7;break;case 10:return t.consarray&&Object.defineProperty(i,"cons",{enumerable:!1,configurable:!1,value:!0}),l.a(3,13);case 11:return l.d(c(dt(t,e,n)),12);case 12:return i=l.v,l.a(3,13);case 13:return l.a(2,i)}},y)}function Z(t,e,n){return u.lookup(e,t.value)}function J(t){return t.value}function tt(t,e){var n=R();return Array.isArray(e)&&e.outerWrapper&&e.length>0&&(e=e[0]),null===e||"object"!==s(e)||L(e)||p.keys(e).forEach(function(t){var i=e[t];Array.isArray(i)?(i=et(i),n=u.append(n,i)):n.push(i)}),n}function et(t,e){return void 0===e&&(e=[]),Array.isArray(t)?Array.prototype.forEach.call(t,function(t){et(t,e)}):e.push(t),e}function nt(t,e){var n,i=R();return void 0!==e&&(it(e,i),n=1===i.length?i[0]:i),n}function it(t,e){Array.isArray(t)||e.push(t),Array.isArray(t)?Array.prototype.forEach.call(t,function(t){it(t,e)}):null===t||"object"!==s(t)||L(t)||p.keys(t).forEach(function(n){it(t[n],e)})}function st(t,e,n){var i;if(void 0!==t&&!D(t))throw{code:"T2001",stack:(new Error).stack,value:t};if(void 0!==e&&!D(e))throw{code:"T2002",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return i;switch(n){case"+":i=t+e;break;case"-":i=t-e;break;case"*":i=t*e;break;case"/":i=t/e;break;case"%":i=t%e}return i}function rt(t,e,n){var i,r=s(t),o=s(e);if("undefined"===r||"undefined"===o)return!1;switch(n){case"=":i=B(t,e);break;case"!=":i=!B(t,e)}return i}function ot(t,e,n){var i,r=s(t),o=s(e);if("undefined"!==r&&"string"!==r&&"number"!==r||"undefined"!==o&&"string"!==o&&"number"!==o)throw{code:"T2010",stack:(new Error).stack,value:"string"!==r&&"number"!==r?t:e};if("undefined"!==r&&"undefined"!==o){if(r!==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 at(t,e){var n=!1;if(void 0===t||void 0===e)return!1;Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)if(e[i]===t){n=!0;break}return n}function ct(t,e,n){var i,s,r,o,a,h,d;return l().w(function(l){for(;;)switch(l.n){case 0:s=lt(t),r=n,l.n="and"===r?1:"or"===r?4:7;break;case 1:if(!(o=s)){l.n=3;break}return a=lt,l.d(c(e()),2);case 2:o=a(l.v);case 3:return i=o,l.a(3,7);case 4:if(h=s){l.n=6;break}return d=lt,l.d(c(e()),5);case 5:h=d(l.v);case 6:return i=h,l.a(3,7);case 7:return l.a(2,i)}},b)}function lt(t){var e=u.boolean(t);return void 0!==e&&e}function ht(t,e){var n="",i="";return void 0!==t&&(n=u.string(t)),void 0!==e&&(i=u.string(e)),n.concat(i)}function dt(t,e,n){var s,r,o,a,h,d,p,f,m,g,y,b,v,x,w;return l().w(function(l){for(;;)switch(l.n){case 0:s=Object.create(null),r=Object.create(null),o=!(!e||!e.tupleStream),Array.isArray(e)||(e=R(e)),0===e.length&&e.push(void 0),a=0;case 1:if(!(a<e.length)){l.n=10;break}h=e[a],d=o?W(n,h):n,p=0;case 2:if(!(p<t.lhs.length)){l.n=9;break}return f=t.lhs[p],l.d(c(V(f[0],o?h["@"]:h,d)),3);case 3:if("string"==typeof(m=l.v)||void 0===m){l.n=4;break}throw{code:"T1003",stack:(new Error).stack,position:t.position,value:m};case 4:if(void 0===m){l.n=8;break}if("_jsonata_lambda"!==m&&"_jsonata_function"!==m){l.n=5;break}throw{code:"D1013",stack:(new Error).stack,position:t.position,value:m};case 5:if(g={data:h,exprIndex:p},!Object.prototype.hasOwnProperty.call(r,m)){l.n=7;break}if(r[m].exprIndex===p){l.n=6;break}throw{code:"D1009",stack:(new Error).stack,position:t.position,value:m};case 6:r[m].data=u.append(r[m].data,h),l.n=8;break;case 7:r[m]=g;case 8:p++,l.n=2;break;case 9:a++,l.n=1;break;case 10:x=i(r);case 11:if((w=x()).done){l.n=13;break}return m=w.value,g=r[m],y=g.data,d=n,o&&(b=ut(g.data),y=b["@"],delete b["@"],d=W(n,b)),l.d(c(V(t.lhs[g.exprIndex][1],y,d)),12);case 12:void 0!==(v=l.v)&&(s[m]=v),l.n=11;break;case 13:return l.a(2,s)}},_)}function ut(t){if(!Array.isArray(t))return t;var e=Object.create(null);Object.assign(e,t[0]);for(var n=1;n<t.length;n++){var i,s=r(p.keys(t[n]));try{for(s.s();!(i=s.n()).done;){var o=i.value;e[o]=u.append(e[o],t[n][o])}}catch(t){s.e(t)}finally{s.f()}}return e}function pt(t,e){var n;if(void 0!==t&&!Number.isInteger(t))throw{code:"T2003",stack:(new Error).stack,value:t};if(void 0!==e&&!Number.isInteger(e))throw{code:"T2004",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return n;if(t>e)return n;var i=e-t+1;if(i>1e7)throw{code:"D2014",stack:(new Error).stack,value:i};n=new Array(i);for(var s=t,r=0;s<=e;s++,r++)n[r]=s;return n.sequence=!0,n}function ft(t,e,n){var i;return l().w(function(s){for(;;)switch(s.n){case 0:return s.d(c(V(t.rhs,e,n)),1);case 1:return i=s.v,n.bind(t.lhs.value,i),s.a(2,i)}},v)}function mt(t,e,n){var i,s;return l().w(function(r){for(;;)switch(r.n){case 0:return r.d(c(V(t.condition,e,n)),1);case 1:if(s=r.v,!u.boolean(s)){r.n=3;break}return r.d(c(V(t.then,e,n)),2);case 2:i=r.v,r.n=5;break;case 3:if(void 0===t.else){r.n=5;break}return r.d(c(V(t.else,e,n)),4);case 4:i=r.v;case 5:return r.a(2,i)}},x)}function gt(t,e,n){var i,s,r;return l().w(function(o){for(;;)switch(o.n){case 0:s=Lt(n),r=0;case 1:if(!(r<t.expressions.length)){o.n=4;break}return o.d(c(V(t.expressions[r],e,s)),2);case 2:i=o.v;case 3:r++,o.n=1;break;case 4:return o.a(2,i)}},w)}function yt(t){var e=new Ht.RegexEngine(t.value),n=function(i,s){var r;e.lastIndex=s||0;var o=e.exec(i);if(null!==o){if(r={match:o[0],start:o.index,end:o.index+o[0].length,groups:[]},o.length>1)for(var a=1;a<o.length;a++)r.groups.push(o[a]);r.next=function(){if(!(e.lastIndex>=i.length)){var s=n(i,e.lastIndex);if(s&&""===s.match)throw{code:"D1004",stack:(new Error).stack,position:t.position,value:t.value.source};return s}}}return r};return n}function bt(t,e,n){return""===t.value?e&&e.outerWrapper?e[0]:e:n.lookup(t.value)}function _t(t,e,n){var i,r,o,a,h;return l().w(function(d){for(;;)switch(d.n){case 0:return r=e,o=!!e.tupleStream,a=l().m(function e(i,r){var a,h,d,u,p,f,m,g,y;return l().w(function(e){for(;;)switch(e.n){case 0:a=0,h=0;case 1:if(!(0===a&&h<t.terms.length)){e.n=11;break}return d=t.terms[h],u=i,p=n,o&&(u=i["@"],p=W(n,i)),e.d(c(V(d.expression,u,p)),2);case 2:return f=e.v,u=r,p=n,o&&(u=r["@"],p=W(n,r)),e.d(c(V(d.expression,u,p)),3);case 3:if(m=e.v,g=s(f),y=s(m),"undefined"!==g){e.n=4;break}return a="undefined"===y?0:1,e.a(3,10);case 4:if("undefined"!==y){e.n=5;break}return a=-1,e.a(3,10);case 5:if(!("string"!==g&&"number"!==g||"string"!==y&&"number"!==y)){e.n=6;break}throw{code:"T2008",stack:(new Error).stack,position:t.position,value:"string"!==g&&"number"!==g?f:m};case 6:if(g===y){e.n=7;break}throw{code:"T2007",stack:(new Error).stack,position:t.position,value:f,value2:m};case 7:if(f!==m){e.n=8;break}return e.a(3,10);case 8:a=f<m?-1:1;case 9:!0===d.descending&&(a=-a);case 10:h++,e.n=1;break;case 11:return e.a(2,1===a)}},e)}),h={environment:n,input:e},d.d(c(u.sort.apply(h,[r,a])),1);case 1:return i=d.v,d.a(2,i)}},M)}function vt(t,e,n){var i=l().m(function e(i){var o,a,h,d,u,f,m,g,y,b,_,v,x;return l().w(function(e){for(;;)switch(e.n){case 0:if(void 0!==i){e.n=1;break}return e.a(2,void 0);case 1:if(o=n.lookup("clone"),L(o)){e.n=2;break}throw{code:"T2013",stack:(new Error).stack,position:t.position};case 2:return e.d(c(St(o,[i],null,n)),3);case 3:return a=e.v,e.d(c(V(t.pattern,a,n)),4);case 4:if(void 0===(h=e.v)){e.n=12;break}Array.isArray(h)||(h=[h]),d=0;case 5:if(!(d<h.length)){e.n=12;break}return u=h[d],e.d(c(V(t.update,u,n)),6);case 6:if(f=e.v,"undefined"===(m=s(f))){e.n=8;break}if("object"===m&&null!==f&&!Array.isArray(f)){e.n=7;break}throw{code:"T2011",stack:(new Error).stack,position:t.update.position,value:f};case 7:g=r(p.keys(f));try{for(g.s();!(y=g.n()).done;)b=y.value,u[b]=f[b]}catch(t){g.e(t)}finally{g.f()}case 8:if(void 0===t.delete){e.n=11;break}return e.d(c(V(t.delete,u,n)),9);case 9:if(void 0===(_=e.v)){e.n=11;break}if(v=_,Array.isArray(_)||(_=[_]),z(_)){e.n=10;break}throw{code:"T2012",stack:(new Error).stack,position:t.delete.position,value:v};case 10:for(x=0;x<_.length;x++)"object"===s(u)&&null!==u&&delete u[_[x]];case 11:d++,e.n=5;break;case 12:return e.a(2,a)}},e)});return It(i,"<(oa):o>")}var xt=f("function($f, $g) { function($x){ $g($f($x)) } }");function wt(t,e,n){var i,s,r,o;return l().w(function(a){for(;;)switch(a.n){case 0:return a.d(c(V(t.lhs,e,n)),1);case 1:if(s=a.v,"function"!==t.rhs.type){a.n=3;break}return a.d(c(Mt(t.rhs,e,n,{context:s})),2);case 2:i=a.v,a.n=10;break;case 3:return a.d(c(V(t.rhs,e,n)),4);case 4:if(r=a.v,L(r)){a.n=5;break}throw{code:"T2006",stack:(new Error).stack,position:t.position,value:r};case 5:if(!L(s)){a.n=8;break}return a.d(c(V(xt,null,n)),6);case 6:return o=a.v,a.d(c(St(o,[s,r],null,n)),7);case 7:i=a.v,a.n=10;break;case 8:return a.d(c(St(r,[s],null,n)),9);case 9:i=a.v;case 10:return a.a(2,i)}},S)}function Mt(t,e,n,i){var r,o,a,h,d,u,p;return l().w(function(f){for(;;)switch(f.p=f.n){case 0:return f.d(c(V(t.procedure,e,n)),1);case 1:if(void 0!==(o=f.v)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){f.n=2;break}throw{code:"T1005",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 2:a=[],void 0!==i&&a.push(i.context),h=l().m(function i(){var s,r;return l().w(function(i){for(;;)switch(i.n){case 0:return i.d(c(V(t.arguments[d],e,n)),1);case 1:s=i.v,L(s)?(r=l().m(function t(){var e,i,r,o=arguments;return l().w(function(t){for(;;)switch(t.n){case 0:for(e=o.length,i=new Array(e),r=0;r<e;r++)i[r]=o[r];return t.d(c(St(s,i,null,n)),1);case 1:return t.a(2,t.v)}},t)}),r.arity=H(s),a.push(r)):a.push(s);case 2:return i.a(2)}},i)}),d=0;case 3:if(!(d<t.arguments.length)){f.n=5;break}return f.d(c(h()),4);case 4:d++,f.n=3;break;case 5:return u="path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value,f.p=6,"object"===s(o)&&(o.token=u,o.position=t.position),f.d(c(St(o,a,e,n)),7);case 7:r=f.v,f.n=9;break;case 8:throw f.p=8,(p=f.v).position||(p.position=t.position),p.token||(p.token=u),p;case 9:return f.a(2,r)}},k,null,[[6,8]])}function St(t,e,n,i){var s,r,o,a,h;return l().w(function(l){for(;;)switch(l.n){case 0:return l.d(c(kt(t,e,n,i)),1);case 1:s=l.v;case 2:if(!F(s)||!0!==s.thunk){l.n=9;break}return l.d(c(V(s.body.procedure,s.input,s.environment)),3);case 3:r=l.v,"variable"===s.body.procedure.type&&(r.token=s.body.procedure.value),r.position=s.body.procedure.position,o=[],a=0;case 4:if(!(a<s.body.arguments.length)){l.n=7;break}return h=o,l.d(c(V(s.body.arguments[a],s.input,s.environment)),5);case 5:h.push.call(h,l.v);case 6:a++,l.n=4;break;case 7:return l.d(c(kt(r,o,n,i)),8);case 8:s=l.v,l.n=2;break;case 9:return l.a(2,s)}},A)}function kt(t,e,n,i){var s,r,o,a;return l().w(function(l){for(;;)switch(l.p=l.n){case 0:if(l.p=0,r=e,t&&(r=Ct(t.signature,e,n)),!F(t)){l.n=2;break}return l.d(c(Tt(t,r)),1);case 1:s=l.v,l.n=9;break;case 2:if(!t||!0!==t._jsonata_function){l.n=5;break}if(o={environment:i,input:n},s=t.implementation.apply(o,r),!N(s)){l.n=4;break}return l.d(c(s),3);case 3:s=l.v;case 4:l.n=9;break;case 5:if("function"!=typeof t){l.n=8;break}if(s=t.apply(n,r),!N(s)){l.n=7;break}return l.d(c(s),6);case 6:s=l.v;case 7:l.n=9;break;case 8:throw{code:"T1006",stack:(new Error).stack};case 9:l.n=11;break;case 10:throw l.p=10,a=l.v,t&&(void 0===a.token&&void 0!==t.token&&(a.token=t.token),a.position=t.position||a.position),a;case 11:return l.a(2,s)}},E,null,[[0,10]])}function At(t,e,n){var i={_jsonata_lambda:!0,input:e,environment:n,arguments:t.arguments,signature:t.signature,body:t.body};return!0===t.thunk&&(i.thunk=!0),i.apply=l().m(function t(n,s){return l().w(function(t){for(;;)switch(t.n){case 0:return t.d(c(St(i,s,e,n.environment)),1);case 1:return t.a(2,t.v)}},t)}),i}function Et(t,e,n){var i,s,r,o,a,h;return l().w(function(l){for(;;)switch(l.n){case 0:s=[],r=0;case 1:if(!(r<t.arguments.length)){l.n=5;break}if("operator"!==(o=t.arguments[r]).type||"?"!==o.value){l.n=2;break}s.push(o),l.n=4;break;case 2:return h=s,l.d(c(V(o,e,n)),3);case 3:h.push.call(h,l.v);case 4:r++,l.n=1;break;case 5:return l.d(c(V(t.procedure,e,n)),6);case 6:if(void 0!==(a=l.v)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){l.n=7;break}throw{code:"T1007",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 7:if(!F(a)){l.n=8;break}i=Pt(a,s),l.n=11;break;case 8:if(!a||!0!==a._jsonata_function){l.n=9;break}i=Ot(a.implementation,s),l.n=11;break;case 9:if("function"!=typeof a){l.n=10;break}i=Ot(a,s),l.n=11;break;case 10:throw{code:"T1008",stack:(new Error).stack,position:t.position,token:"path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value};case 11:return l.a(2,i)}},C)}function Ct(t,e,n){return void 0===t?e:t.validate(e,n)}function Tt(t,e){var n,i;return l().w(function(s){for(;;)switch(s.n){case 0:if(i=Lt(t.environment),Array.prototype.forEach.call(t.arguments,function(t,n){i.bind(t.value,e[n])}),"function"!=typeof t.body){s.n=2;break}return s.d(c(Dt(t.body,i)),1);case 1:n=s.v,s.n=4;break;case 2:return s.d(c(V(t.body,t.input,i)),3);case 3:n=s.v;case 4:return s.a(2,n)}},T)}function Pt(t,e){var n=Lt(t.environment),i=[];return Array.prototype.forEach.call(t.arguments,function(t,s){var r=e[s];r&&"operator"===r.type&&"?"===r.value?i.push(t):n.bind(t.value,r)}),{_jsonata_lambda:!0,input:t.input,environment:n,arguments:i,body:t.body}}function Ot(t,e){var n=zt(t),i="function("+(n=n.map(function(t){return"$"+t.trim()})).join(", ")+"){ _ }",s=f(i);return s.body=t,Pt(s,e)}function Dt(t,e){var n,i,s,r;return l().w(function(o){for(;;)switch(o.n){case 0:if(n=zt(t),i=n.map(function(t){return e.lookup(t.trim())}),s={environment:e},r=t.apply(s,i),!N(r)){o.n=2;break}return o.d(c(r),1);case 1:r=o.v;case 2:return o.a(2,r)}},P)}function zt(t){var e=t.toString();return/\(([^)]*)\)/.exec(e)[1].split(",")}function It(t,e){var n={_jsonata_function:!0,implementation:t};return void 0!==e&&(n.signature=m(e)),n}function Rt(t,e){var n,i,s,r,o;return l().w(function(a){for(;;)switch(a.p=a.n){case 0:if(void 0!==t){a.n=1;break}return a.a(2,void 0);case 1:n=this.input,void 0!==e&&(n=e,Array.isArray(n)&&!j(n)&&((n=R(n)).outerWrapper=!0)),a.p=2,i=f(t,!1),a.n=4;break;case 3:throw a.p=3,Nt(r=a.v),{stack:(new Error).stack,code:"D3120",value:r.message,error:r};case 4:return a.p=4,a.d(c(V(i,n,this.environment)),5);case 5:s=a.v,a.n=7;break;case 6:throw a.p=6,Nt(o=a.v),{stack:(new Error).stack,code:"D3121",value:o.message,error:o};case 7:return a.a(2,s)}},O,this,[[4,6],[2,3]])}function jt(t){if(void 0!==t)return JSON.parse(u.string(t))}function Lt(t){var e=Object.create(null);return{bind:function(t,n){e[t]=n},lookup:function(n){var i;return Object.prototype.hasOwnProperty.call(e,n)?i=e[n]:t&&(i=t.lookup(n)),i},timestamp:t?t.timestamp:null,async:!!t&&t.async,global:t?t.global:{ancestry:[null]}}}G.bind("sum",It(u.sum,"<a<n>:n>")),G.bind("count",It(u.count,"<a:n>")),G.bind("max",It(u.max,"<a<n>:n>")),G.bind("min",It(u.min,"<a<n>:n>")),G.bind("average",It(u.average,"<a<n>:n>")),G.bind("string",It(u.string,"<x-b?:s>")),G.bind("substring",It(u.substring,"<s-nn?:s>")),G.bind("substringBefore",It(u.substringBefore,"<s-s:s>")),G.bind("substringAfter",It(u.substringAfter,"<s-s:s>")),G.bind("lowercase",It(u.lowercase,"<s-:s>")),G.bind("uppercase",It(u.uppercase,"<s-:s>")),G.bind("length",It(u.length,"<s-:n>")),G.bind("trim",It(u.trim,"<s-:s>")),G.bind("pad",It(u.pad,"<s-ns?:s>")),G.bind("match",It(u.match,"<s-f<s:o>n?:a<o>>")),G.bind("contains",It(u.contains,"<s-(sf):b>")),G.bind("replace",It(u.replace,"<s-(sf)(sf)n?:s>")),G.bind("split",It(u.split,"<s-(sf)n?:a<s>>")),G.bind("join",It(u.join,"<a<s>s?:s>")),G.bind("formatNumber",It(u.formatNumber,"<n-so?:s>")),G.bind("formatBase",It(u.formatBase,"<n-n?:s>")),G.bind("formatInteger",It(d.formatInteger,"<n-s:s>")),G.bind("parseInteger",It(d.parseInteger,"<s-s:n>")),G.bind("number",It(u.number,"<(nsb)-:n>")),G.bind("floor",It(u.floor,"<n-:n>")),G.bind("ceil",It(u.ceil,"<n-:n>")),G.bind("round",It(u.round,"<n-n?:n>")),G.bind("abs",It(u.abs,"<n-:n>")),G.bind("sqrt",It(u.sqrt,"<n-:n>")),G.bind("power",It(u.power,"<n-n:n>")),G.bind("random",It(u.random,"<:n>")),G.bind("boolean",It(u.boolean,"<x-:b>")),G.bind("not",It(u.not,"<x-:b>")),G.bind("map",It(u.map,"<af>")),G.bind("zip",It(u.zip,"<a+>")),G.bind("filter",It(u.filter,"<af>")),G.bind("single",It(u.single,"<af?>")),G.bind("reduce",It(u.foldLeft,"<afj?:j>")),G.bind("sift",It(u.sift,"<o-f?:o>")),G.bind("keys",It(u.keys,"<x-:a<s>>")),G.bind("lookup",It(u.lookup,"<x-s:x>")),G.bind("append",It(u.append,"<xx:a>")),G.bind("exists",It(u.exists,"<x:b>")),G.bind("spread",It(u.spread,"<x-:a<o>>")),G.bind("merge",It(u.merge,"<a<o>:o>")),G.bind("reverse",It(u.reverse,"<a:a>")),G.bind("each",It(u.each,"<o-f:a>")),G.bind("error",It(u.error,"<s?:x>")),G.bind("assert",It(u.assert,"<bs?:x>")),G.bind("type",It(u.type,"<x:s>")),G.bind("sort",It(u.sort,"<af?:a>")),G.bind("shuffle",It(u.shuffle,"<a:a>")),G.bind("distinct",It(u.distinct,"<x:x>")),G.bind("base64encode",It(u.base64encode,"<s-:s>")),G.bind("base64decode",It(u.base64decode,"<s-:s>")),G.bind("encodeUrlComponent",It(u.encodeUrlComponent,"<s-:s>")),G.bind("encodeUrl",It(u.encodeUrl,"<s-:s>")),G.bind("decodeUrlComponent",It(u.decodeUrlComponent,"<s-:s>")),G.bind("decodeUrl",It(u.decodeUrl,"<s-:s>")),G.bind("eval",It(Rt,"<sx?:x>")),G.bind("toMillis",It(d.toMillis,"<s-s?:n>")),G.bind("fromMillis",It(d.fromMillis,"<n-s?s?:s>")),G.bind("clone",It(jt,"<(oa)-:o>"));var Ft={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}}",D1013:"Object property names starting with _jsonata_ are reserved for internal use: {{value}}",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 Nt(t){var e=Ft[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 Ht(t,e){var n,i;try{n=f(t,e&&e.recover),i=n.errors,delete n.errors}catch(t){throw Nt(t),t}var s=Lt(G),o=new Date;return s.bind("now",It(function(t,e){return d.fromMillis(o.getTime(),t,e)},"<s?s?:s>")),s.bind("millis",It(function(){return o.getTime()},"<:n>")),e&&e.RegexEngine?Ht.RegexEngine=e.RegexEngine:Ht.RegexEngine=RegExp,{evaluate:function(t,e,a){if(void 0!==i){var c={code:"S0500",position:0};throw Nt(c),c}if(void 0!==e){var l;l=Lt(s);var h,d=r(p.keys(e));try{for(d.s();!(h=d.n()).done;){var u=h.value;l.bind(u,e[u])}}catch(c){d.e(c)}finally{d.f()}}else l=s;var f,m;if(l.bind("$",t),o=new Date,l.timestamp=o,Array.isArray(t)&&!j(t)&&((t=R(t)).outerWrapper=!0),"function"==typeof a){l.async=!0;var g=function(t){Nt(t),a(t,null)},y=function(t){(f=m.next(t)).done?a(null,f.value):f.value.then(y).catch(g)};m=V(n,t,l),(f=m.next()).value.then(y).catch(g)}else try{for(m=V(n,t,l),f=m.next();!f.done;)f=m.next(f.value);return f.value}catch(c){throw Nt(c),c}},assign:function(t,e){s.bind(t,e)},registerFunction:function(t,e,n){var i=It(e,n);s.bind(t,i)},ast:function(){return n},errors:function(){return i}}}return Ht.parser=f,Ht}();e.exports=g},{"./datetime":1,"./functions":2,"./parser":4,"./signature":5,"./utils":6}],4:[function(t,e,n){var i=t("./signature"),s=function(){var t={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":80,"#":80,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"^":40,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},e={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},n=function(n){var i=0,s=n.length,r=function(t,e){return{type:t,value:e,position:i}},o=function(){for(var t,e,r=i,o=0;i<s;){var a=n.charAt(i);if("/"===a&&"\\"!==n.charAt(i-1)&&0===o){if(""===(t=n.substring(r,i)))throw{code:"S0301",stack:(new Error).stack,position:i};for(i++,a=n.charAt(i),r=i;"i"===a||"m"===a;)i++,a=n.charAt(i);return e=n.substring(r,i)+"g",new RegExp(t,e)}"("!==a&&"["!==a&&"{"!==a||"\\"===n.charAt(i-1)||o++,")"!==a&&"]"!==a&&"}"!==a||"\\"===n.charAt(i-1)||o--,i++}throw{code:"S0302",stack:(new Error).stack,position:i}},a=function(c){if(i>=s)return null;for(var l=n.charAt(i);i<s&&" \t\n\r\v".indexOf(l)>-1;)i++,l=n.charAt(i);if("/"===l&&"*"===n.charAt(i+1)){var h=i;for(i+=2,l=n.charAt(i);"*"!==l||"/"!==n.charAt(i+1);)if(l=n.charAt(++i),i>=s)throw{code:"S0106",stack:(new Error).stack,position:h};return i+=2,l=n.charAt(i),a(c)}if(!0!==c&&"/"===l)return i++,r("regex",o());if("."===l&&"."===n.charAt(i+1))return i+=2,r("operator","..");if(":"===l&&"="===n.charAt(i+1))return i+=2,r("operator",":=");if("!"===l&&"="===n.charAt(i+1))return i+=2,r("operator","!=");if(">"===l&&"="===n.charAt(i+1))return i+=2,r("operator",">=");if("<"===l&&"="===n.charAt(i+1))return i+=2,r("operator","<=");if("*"===l&&"*"===n.charAt(i+1))return i+=2,r("operator","**");if("~"===l&&">"===n.charAt(i+1))return i+=2,r("operator","~>");if(Object.prototype.hasOwnProperty.call(t,l))return i++,r("operator",l);if('"'===l||"'"===l){var d=l;i++;for(var u="";i<s;){if("\\"===(l=n.charAt(i)))if(i++,l=n.charAt(i),Object.prototype.hasOwnProperty.call(e,l))u+=e[l];else{if("u"!==l)throw{code:"S0103",stack:(new Error).stack,position:i,token:l};var p=n.substr(i+1,4);if(!/^[0-9a-fA-F]+$/.test(p))throw{code:"S0104",stack:(new Error).stack,position:i};var f=parseInt(p,16);u+=String.fromCharCode(f),i+=4}else{if(l===d)return i++,r("string",u);u+=l}i++}throw{code:"S0101",stack:(new Error).stack,position:i}}var m,g=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/.exec(n.substring(i));if(null!==g){var y=parseFloat(g[0]);if(!isNaN(y)&&isFinite(y))return i+=g[0].length,r("number",y);throw{code:"S0102",stack:(new Error).stack,position:i,token:g[0]}}if("`"===l){i++;var b=n.indexOf("`",i);if(-1!==b)return m=n.substring(i,b),i=b+1,r("name",m);throw i=s,{code:"S0105",stack:(new Error).stack,position:i}}for(var _,v=i;;)if(_=n.charAt(v),v===s||" \t\n\r\v".indexOf(_)>-1||Object.prototype.hasOwnProperty.call(t,_)){if("$"===n.charAt(i))return m=n.substring(i+1,v),i=v,r("variable",m);switch(m=n.substring(i,v),i=v,m){case"or":case"in":case"and":return r("operator",m);case"true":return r("value",!0);case"false":return r("value",!1);case"null":return r("value",null);default:return i===s&&""===m?null:r("name",m)}}else v++};return a},s=function(e,s){var r,o,a=Object.create(null),c=[],l=function(){var t=[];"(end)"!==r.id&&t.push({type:r.type,value:r.value,position:r.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(s)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(s){t.remaining=l(),c.push(t);var e=a["(error)"];return(r=Object.create(e)).error=t,r.type="(error)",r}throw t.stack=(new Error).stack,t},p=function(t,n){if(t&&r.id!==t){var i={code:"(end)"===r.id?"S0203":"S0202",position:r.position,token:r.value,value:t};return u(i)}var s=o(n);if(null===s)return(r=a["(end)"]).position=e.length,r;var c,l=s.value,h=s.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:s.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:s.position,token:l})}return(r=Object.create(c)).value=l,r.type=h,r.position=s.position,r},f=function(t){var e,n=r;for(p(null,!0),e=n.nud();t<r.lbp;)n=r,p(),e=n.led(e);return e},m=function(t){d(t,0).nud=function(){return this}},g=function(e,n,i){var s=n||t[e],r=d(e,s);return r.led=i||function(t){return this.lhs=t,this.rhs=f(s),this.type="binary",this},r},y=function(t,e,n){var i=d(t,e);return i.led=n,i},b=function(t,e){var n=d(t);return n.nud=e||function(){return this.expression=f(70),this.type="unary",this},n};m("(end)"),m("(name)"),m("(literal)"),m("(regex)"),d(":"),d(";"),d(","),d(")"),d("]"),d("}"),d(".."),g("."),g("+"),g("-"),g("*"),g("/"),g("%"),g("="),g("<"),g(">"),g("!="),g("<="),g(">="),g("&"),g("and"),g("or"),g("in"),m("and"),m("or"),m("in"),b("-"),g("~>"),y("(error)",10,function(t){return this.lhs=t,this.error=r.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}),g("(",t["("],function(t){if(this.procedure=t,this.type="function",this.arguments=[],")"!==r.id)for(;"operator"===r.type&&"?"===r.id?(this.type="partial",this.arguments.push(r),p("?")):this.arguments.push(f(0)),","===r.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","<"===r.id){for(var e=r.position,n=1,s="<";n>0&&"{"!==r.id&&"(end)"!==r.id;){var o=p();">"===o.id?n--:"<"===o.id&&n++,s+=o.value}p(">");try{this.signature=i(s)}catch(t){return t.position=e+t.offset,u(t)}}p("{"),this.body=f(0),p("}")}return this}),b("(",function(){for(var t=[];")"!==r.id&&(t.push(f(0)),";"===r.id);)p(";");return p(")",!0),this.type="block",this.expressions=t,this}),b("[",function(){var t=[];if("]"!==r.id)for(;;){var e=f(0);if(".."===r.id){var n={type:"binary",value:"..",position:r.position,lhs:e};p(".."),n.rhs=f(0),e=n}if(t.push(e),","!==r.id)break;p(",")}return p("]",!0),this.expressions=t,this.type="unary",this}),g("[",t["["],function(e){if("]"===r.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}),g("^",t["^"],function(t){p("(");for(var e=[];;){var n={descending:!1};if("<"===r.id?p("<"):">"===r.id&&(n.descending=!0,p(">")),n.expression=f(0),e.push(n),","!==r.id)break;p(",")}return p(")"),this.lhs=t,this.rhs=e,this.type="binary",this});var _=function(t){var e=[];if("}"!==r.id)for(;;){var n=f(0);p(":");var i=f(0);if(e.push([n,i]),","!==r.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("{",_),g("{",t["{"],_),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)}),g("@",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)}),g("#",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)}),g("?",t["?"],function(t){return this.type="condition",this.condition=t,this.then=f(0),":"===r.id&&(p(":"),this.else=f(0)),this}),b("|",function(){return this.type="transform",this.pattern=f(0),p("|"),this.update=f(0),","===r.id&&(p(","),this.delete=f(0)),p("|"),this});var v=function(t){var e;if("function"!==t.type||t.predicate)if("condition"===t.type)t.then=v(t.then),void 0!==t.else&&(t.else=v(t.else)),e=t;else if("block"===t.type){var n=t.expressions.length;n>0&&(t.expressions[n-1]=v(t.expressions[n-1])),e=t}else e=t;else{var i={type:"lambda",thunk:!0,arguments:[],position:t.position};i.body=t,e=i}return e},x=0,w=0,M=[],S=function(t,e){switch(t.type){case"name":case"wildcard":e.level--,0===e.level&&(void 0===t.ancestor||(M[e.index].slot.label=t.ancestor.label),t.ancestor=e,t.tuple=!0);break;case"parent":e.level++;break;case"block":t.expressions.length>0&&(t.tuple=!0,e=S(t.expressions[t.expressions.length-1],e));break;case"path":t.tuple=!0;var n=t.steps.length-1;for(e=S(t.steps[n--],e);e.level>0&&n>=0;)e=S(t.steps[n--],e);break;default:throw{code:"S0217",token:t.type,position:t.position}}return e},k=function(t,e){if(void 0!==e.seekingParent||"parent"===e.type){var n=void 0!==e.seekingParent?e.seekingParent:[];"parent"===e.type&&n.push(e.slot),void 0===t.seekingParent?t.seekingParent=n:Array.prototype.push.apply(t.seekingParent,n)}},A=function(t){var e=t.steps.length-1,n=t.steps[e],i=void 0!==n.seekingParent?n.seekingParent:[];"parent"===n.type&&i.push(n.slot);for(var s=0;s<i.length;s++){var r=i[s];for(e=t.steps.length-2;r.level>0;){if(e<0){void 0===t.seekingParent?t.seekingParent=[r]:t.seekingParent.push(r);break}for(var o=t.steps[e--];e>=0&&o.focus&&t.steps[e].focus;)o=t.steps[e--];r=S(o,r)}}},E=function(t){var e;switch(t.type){case"binary":switch(t.value){case".":var n=E(t.lhs);e="path"===n.type?n:{type:"path",steps:[n]},"parent"===n.type&&(e.seekingParent=[n.slot]);var i=E(t.rhs);"function"===i.type&&"path"===i.procedure.type&&1===i.procedure.steps.length&&"name"===i.procedure.steps[0].type&&"function"===e.steps[e.steps.length-1].type&&(e.steps[e.steps.length-1].nextFunction=i.procedure.steps[0].value),"path"===i.type?Array.prototype.push.apply(e.steps,i.steps):(void 0!==i.predicate&&(i.stages=i.predicate,delete i.predicate),e.steps.push(i)),e.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"}),e.steps.filter(function(t){return!0===t.keepArray}).length>0&&(e.keepSingletonArray=!0);var r=e.steps[0];"unary"===r.type&&"["===r.value&&(r.consarray=!0);var o=e.steps[e.steps.length-1];"unary"===o.type&&"["===o.value&&(o.consarray=!0),A(e);break;case"[":var a=e=E(t.lhs),l="predicate";if("path"===e.type&&(a=e.steps[e.steps.length-1],l="stages"),void 0!==a.group)throw{code:"S0209",stack:(new Error).stack,position:t.position};void 0===a[l]&&(a[l]=[]);var h=E(t.rhs);void 0!==h.seekingParent&&(h.seekingParent.forEach(function(t){1===t.level?S(a,t):t.level--}),k(a,h)),a[l].push({type:"filter",expr:h,position:t.position});break;case"{":if(void 0!==(e=E(t.lhs)).group)throw{code:"S0210",stack:(new Error).stack,position:t.position};e.group={lhs:t.rhs.map(function(t){return[E(t[0]),E(t[1])]}),position:t.position};break;case"^":"path"!==(e=E(t.lhs)).type&&(e={type:"path",steps:[e]});var d={type:"sort",position:t.position};d.terms=t.rhs.map(function(t){var e=E(t.expression);return k(d,e),{descending:t.descending,expression:e}}),e.steps.push(d),A(e);break;case":=":(e={type:"bind",value:t.value,position:t.position}).lhs=E(t.lhs),e.rhs=E(t.rhs),k(e,e.rhs);break;case"@":if(e=E(t.lhs),a=e,"path"===e.type&&(a=e.steps[e.steps.length-1]),void 0!==a.stages||void 0!==a.predicate)throw{code:"S0215",stack:(new Error).stack,position:t.position};if("sort"===a.type)throw{code:"S0216",stack:(new Error).stack,position:t.position};t.keepArray&&(a.keepArray=!0),a.focus=t.rhs.value,a.tuple=!0;break;case"#":e=E(t.lhs),a=e,"path"===e.type?a=e.steps[e.steps.length-1]:(e={type:"path",steps:[e]},void 0!==a.predicate&&(a.stages=a.predicate,delete a.predicate)),void 0===a.stages?a.index=t.rhs.value:a.stages.push({type:"index",value:t.rhs.value,position:t.position}),a.tuple=!0;break;case"~>":(e={type:"apply",value:t.value,position:t.position}).lhs=E(t.lhs),e.rhs=E(t.rhs);break;default:(e={type:t.type,value:t.value,position:t.position}).lhs=E(t.lhs),e.rhs=E(t.rhs),k(e,e.lhs),k(e,e.rhs)}break;case"unary":e={type:t.type,value:t.value,position:t.position},"["===t.value?e.expressions=t.expressions.map(function(t){var n=E(t);return k(e,n),n}):"{"===t.value?e.lhs=t.lhs.map(function(t){var n=E(t[0]);k(e,n);var i=E(t[1]);return k(e,i),[n,i]}):(e.expression=E(t.expression),"-"===t.value&&"number"===e.expression.type?(e=e.expression).value=-e.value:k(e,e.expression));break;case"function":case"partial":(e={type:t.type,name:t.name,value:t.value,position:t.position}).arguments=t.arguments.map(function(t){var n=E(t);return k(e,n),n}),e.procedure=E(t.procedure);break;case"lambda":e={type:t.type,arguments:t.arguments,signature:t.signature,position:t.position};var u=E(t.body);e.body=v(u);break;case"condition":(e={type:t.type,position:t.position}).condition=E(t.condition),k(e,e.condition),e.then=E(t.then),k(e,e.then),void 0!==t.else&&(e.else=E(t.else),k(e,e.else));break;case"transform":(e={type:t.type,position:t.position}).pattern=E(t.pattern),e.update=E(t.update),void 0!==t.delete&&(e.delete=E(t.delete));break;case"block":(e={type:t.type,position:t.position}).expressions=t.expressions.map(function(t){var n=E(t);return k(e,n),(n.consarray||"path"===n.type&&n.steps[0].consarray)&&(e.consarray=!0),n});break;case"name":e={type:"path",steps:[t]},t.keepArray&&(e.keepSingletonArray=!0);break;case"parent":e={type:"parent",slot:{label:"!"+x++,level:1,index:w++}},M.push(e);break;case"string":case"number":case"value":case"wildcard":case"descendant":case"variable":case"regex":e=t;break;case"operator":if("and"===t.value||"or"===t.value||"in"===t.value)t.type="name",e=E(t);else{if("?"!==t.value)throw{code:"S0201",stack:(new Error).stack,position:t.position,token:t.value};e=t}break;case"error":e=t,t.lhs&&(e=E(t.lhs));break;default:var p="S0206";"(end)"===t.id&&(p="S0207");var f={code:p,position:t.position,token:t.value};if(s)return c.push(f),{type:"error",error:f};throw f.stack=(new Error).stack,f}return t.keepArray&&(e.keepArray=!0),e};o=n(e),p();var C=f(0);if("(end)"!==r.id){var T={code:"S0201",position:r.position,token:r.value};u(T)}if("parent"===(C=E(C)).type||void 0!==C.seekingParent)throw{code:"S0217",token:C.type,position:C.position};return c.length>0&&(C.errors=c),C};return s}();e.exports=s},{"./signature":5}],5:[function(t,e,n){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}var s=t("./utils"),r=function(){var t={a:"arrays",b:"booleans",f:"functions",n:"numbers",o:"objects",s:"strings"};function e(e){for(var n=1,r=[],o=Object.create(null),a=o;n<e.length;){var c=e.charAt(n);if(":"===c)break;var l=function(){r.push(o),a=o,o=Object.create(null)},h=function(t,e,n,i){for(var s=1,r=e;r<t.length;)if(r++,(c=t.charAt(r))===i){if(0===--s)break}else c===n&&s++;return r};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="^"+r.map(function(t){return"("+t.regex+")"}).join("")+"$",m=new RegExp(f),g=function(t){var e;if(s.isFunction(t))e="f";else switch(i(t)){case"string":e="s";break;case"number":e="n";break;case"boolean":e="b";break;case"object":e=null===t?"l":Array.isArray(t)?"a":"o";break;default:e="m"}return e},y=function(t,e){for(var n="^",i=0,s=0;s<r.length;s++){n+=r[s].regex;var o=e.match(n);if(null===o)throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1};i=o[0].length}throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1}};return{definition:e,validate:function(e,n){var i="";e.forEach(function(t){i+=g(t)});var s=m.exec(i);if(s){var o=[],a=0;return r.forEach(function(i,r){var c=e[a],l=s[r+1];if(""===l)if(i.context&&i.contextRegex){var h=g(n);if(!i.contextRegex.test(h))throw{code:"T0411",stack:(new Error).stack,value:n,index:a+1};o.push(n)}else o.push(c),a++;else l.split("").forEach(function(n){if("a"===i.type){if("m"===n)c=void 0;else{c=e[a];var s=!0;if(void 0!==i.subtype)if("a"!==n&&l!==i.subtype)s=!1;else if("a"===n&&c.length>0){var r=g(c[0]);s=r===i.subtype.charAt(0)&&0===c.filter(function(t){return g(t)!==r}).length}if(!s)throw{code:"T0412",stack:(new Error).stack,value:c,index:a+1,type:t[i.subtype]};"a"!==n&&(c=[c])}o.push(c),a++}else o.push(c),a++})}),o}y(e,i)}}}return e}();e.exports=r},{"./utils":6}],6:[function(t,e,n){function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=s(t))||e){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}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 s(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.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)?r(t,e):void 0}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}var a=function(){function t(t){var e=!1;if("number"==typeof t&&(e=!isNaN(t))&&!isFinite(t))throw{code:"D1001",value:t,stack:(new Error).stack};return e}function e(t){var e=!1;return Array.isArray(t)&&(e=0===t.filter(function(t){return"string"!=typeof t}).length),e}function n(e){var n=!1;return Array.isArray(e)&&(n=0===e.filter(function(e){return!t(e)}).length),n}function s(){var t=[];return t.sequence=!0,1===arguments.length&&t.push(arguments[0]),t}function r(t){return!0===t.sequence&&Array.isArray(t)}function a(t){return t&&(!0===t._jsonata_function||!0===t._jsonata_lambda)||"function"==typeof t}function c(t){return"number"==typeof t.arity?t.arity:"function"==typeof t.implementation?t.implementation.length:"number"==typeof t.length?t.length:t.arguments.length}function l(t){return t&&!0===t._jsonata_lambda}var h=("function"==typeof Symbol?Symbol:{}).iterator||"@@iterator";function d(t){return"object"===o(t)&&null!==t&&h in t&&"next"in t&&"function"==typeof t.next}function u(t,e){if(t===e)return!0;if("object"===o(t)&&"object"===o(e)&&null!==t&&null!==e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!u(t[n],e[n]))return!1;return!0}var i=Object.getOwnPropertyNames(t),s=Object.getOwnPropertyNames(e);if(i.length!==s.length)return!1;for(i=i.sort(),s=s.sort(),n=0;n<i.length;n++)if(i[n]!==s[n])return!1;for(n=0;n<i.length;n++){var r=i[n];if(!u(t[r],e[r]))return!1}return!0}return!1}function p(t){var e,n=[],s=i(t);try{for(s.s();!(e=s.n()).done;){var r=e.value;n.push(r)}}catch(t){s.e(t)}finally{s.f()}return n}function f(t){return"object"===o(t)&&null!==t?Object.keys(t):[]}return{isNumeric:t,isArrayOfStrings:e,isArrayOfNumbers:n,createSequence:s,isSequence:r,isFunction:a,isLambda:l,isIterable:d,getFunctionArity:c,isDeepEqual:u,stringToArray:p,keys:f}}();e.exports=a},{}]},{},[3])(3)}(os)),os.exports),cs=is(as);const ls=function(t){return t};function hs(t){if(!t)return ls;try{const e=cs(function(t){return t.replace(/(?<=^|\.|\[)([a-zA-Z_][\w]*-[\w-]*)(?=\.|$|\[|])/g,"`$1`")}(t));return function(t){return e.evaluate(t)}}catch(t){return Zi(t),ls}}function ds(t){const e=wi(t);return null==e?"":String(e)}function us(t){return Number(wi(t))}function ps(t){return t}function fs(t){return ds(t)}function ms(t){return us(t)}function gs(t){if(this.param)return t=ds(t),this.param.hasOwnProperty(t)?this.param[t]:this.param.default}function ys(t){const{param:e}=this;if(e){for(const n in e){let[i,s]=n.split("~");const r=!!i,o=!!s,a=parseFloat(i),c=parseFloat(s);if(t=us(t),r&&!o&&t>=a)return e[n];if(!r&&o&&t<a)return e[n];if(t>=a&&t<c)return e[n]}return e.default}}function bs(t){return us(t)*Math.PI/180}function _s(){}const vs=[/\bimport\b/,/\brequire\b/,/\b__proto__\b/,/\bconstructor\s*\[/,/\bprototype\b/];const xs=["globalThis","self","top","parent","frames","fetch","XMLHttpRequest","eval","Function","require","importScripts","process"],ws=new Array(xs.length).fill(void 0),Ms=Object.getPrototypeOf(async function(){}).constructor;function Ss(t,e){!function(t){for(const e of vs)if(e.test(t))throw new Error(`Blocked pattern detected: ${e}`)}(t);const n=function(t){return/\bawait\b/.test(t)}(t),i=new(n?Ms:Function)(...e,...xs,t);return function(t,...e){return i.call(t,...e,...ws)}}function ks(t,e,n,i,s){switch(n){case"value":return"text"===s||"string"===s?fs.bind(t):"number"===s?ms.bind(t):ps.bind(e);case"map":return gs.bind(t);case"range":return ys.bind(t);case"radian":return bs.bind(t);case"eval":return function(t){try{const e=Ss(t,["value","targets","scene"]);return function(t,n){try{const i=e(this,t,n,globalThis.scene);return i&&"function"==typeof i.then?i.catch(t=>{Zi(t)}):i}catch(t){return void Zi(t)}}}catch(t){return Zi(t),_s}}(i).bind(e);default:return ps.bind(e)}}class As{constructor(t,e){this.owner=e,this.model=t}dispose(){this._model=null,this.owner=null,this.evaluator=null,this.accessor=null}get model(){return this._model}set model(t){const{target:e,property:n,rule:i,param:s,accessor:r}=t;this._model=t,this.evaluator=ks(this,this.owner,i,s,function(t){switch(t){case"ref":case"fillStyle":case"strokeStyle":return"string";default:return}}(n)),this.accessor=hs(r);const o=e.match(/\[(.*?)\]/);if(o){const[t,e]=o[1].split(":");this.propAccessor=hs(t),this.partAccessor=hs(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 Es(t,e,n,i){const s=e.split(".");if(1===s.length)return void(t[e]=i?{...t[e],...n}:n);const r=s[0],o=void 0!==t[r]?t[r]:"function"==typeof t.get?t.get(r):void 0,a=o?{...o}:{};let c=a;for(let t=1;t<s.length-1;t++)c[s[t]]=c[s[t]]?{...c[s[t]]}:{},c=c[s[t]];const l=s[s.length-1];c[l]=i?{...c[l],...n}:n,t[r]=a}function Cs(t,e,n,i){t.forEach(t=>Es(t,e,n,i))}function Ts(t,e,n,i){t&&"function"==typeof t.then?t.then(t=>{void 0!==n&&void 0!==i&&n._dataGeneration!==i||e(t)}).catch(t=>Zi(t)):e(t)}function Ps(t=!1){if(!t&&void 0===this.data)return;this._dataGeneration=(this._dataGeneration??0)+1;const e=this._dataGeneration,n=this;this.mappings&&this.mappings.forEach(t=>{try{let i,{source:s,target:r,property:o,accessor:a,propAccessor:c,partAccessor:l,ndnsp:h=!1,partial:d=!1}=t;r=(r||"(self)").trim(),t.rule||(t.rule="value"),s&&"(self)"!=s?(s.startsWith("#")&&(s=s.substring(1)),i=this.root.findById(s)?.data||{}):i=this.data;const u=a(i);if("(root)"==r||"(key)"==r){if(null==u)return;const i=Object.keys(u||{}).map(t=>this.root.findOrCreate(t)).filter(Boolean).flat();i.length>0&&i.forEach(i=>{Ts(t.evaluator(u[i.get("id")],[i]),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Es(i,o,t,d)},n,e)})}else if(r.startsWith("[")){if(null==u)return;if(u instanceof Array)u.forEach(i=>{const s=c(i);if(s){const r=this.root.findOrCreate(s);r&&Ts(t.evaluator(l(i),r),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Cs(r,o,t,d)},n,e)}});else{if(!(u instanceof Object))throw String("mapping data should be an object to target property-id.("+u+")");{const i=c(u);if(i){const s=this.root.findOrCreate(i);s&&Ts(t.evaluator(l(u),s),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Cs(s,o,t,d)},n,e)}}}}else{const i=this.root.findAll(r,this);i.length>0&&Ts(t.evaluator(u,i),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Cs(i,o,t,d)},n,e)}}catch(e){Zi(e,this,t)}})}function Os(t,e){this.state.persistent&&this.app?.isViewMode&&this.app?.dataStorage.save(this,t.data),Ps.call(this,!0)}function Ds(){if(this._model.mappings)return this._model.mappings instanceof Array?void(this._mappings=(this._model.mappings||[]).filter(t=>t.property).map(t=>new As({target:"(self)",rule:"value",...t},this))):(Zi("Mappings model is invalid (should be a Array) ..",this._model.mappings),void(this._mappings=[]));this._mappings=[]}function zs(){this._mappings&&this._mappings.forEach(t=>t.dispose()),delete this._mappings}function Is(t,e){this.disposeMappings(),Ps.call(this)}function Rs(t){if(!t||"object"!=typeof t||Array.isArray(t))return[];const e={tap:"click",hover:"mouseenter",dblclick:"dblclick",longpress:"longpress"},n=[];for(const i of Object.keys(t)){const s=e[i];if(!s)continue;const r=t[i];if(r&&"object"==typeof r){if("script"===r.action){const t="string"==typeof r.value?r.value:r.value&&"object"==typeof r.value?r.value.script:"";t&&n.push({trigger:s,action:"script",code:t,target:r.target});continue}n.push({trigger:s,action:r.action,target:r.target,value:r.value,options:{emphasize:r.emphasize,restore:r.restore,pressed:r.pressed,...r.options??{}}})}}return n}function js(t){if(!t)return[];const e=t.eventHandlers;return Array.isArray(e)?e:Rs(t.event)}function Ls(t,e,n,i,s,r){e.complete?t.drawImage(e,n,i,s,r):e.addEventListener("load",()=>{this.invalidate()})}function Fs(t){const{effects:e}=this.state;(e||[]).forEach(e=>{this.effect(t,e)})}const Ns={},Hs=0,Bs=1,Gs=2,Vs=3,Ys=4,Ws=5,Us={VIEW:0,EDIT:1,SHIFT:2,ADD:3},$s=30,Xs="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),qs=["mousemove","mouseup","mousedown","mouseout","wheel","touchstart","touchmove","touchend","dblclick"],Ks=["keydown","keyup"],Qs={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},Zs=()=>{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";Qs.FONT_FAMILY=e||n},Js=()=>{if("undefined"!=typeof window&&"undefined"!=typeof document&&(window.addEventListener("load",()=>{Zs()}),"fonts"in document&&"ready"in document.fonts&&document.fonts.ready.then(Zs),"undefined"!=typeof MutationObserver&&document.documentElement)){new MutationObserver(()=>{Zs()}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}};let tr;function er(t,e,n,i,s){const{alpha:r=1}=i,o=s.fillStyle;if(t.globalAlpha*=r,o)if("string"==typeof o)t.fillStyle=o,t.fill();else if("object"==typeof o)if("gradient"==o.type){t.translate(n.x,n.y);let i,{width:s,height:r}=e;if("linear"==o.gradientType){const e=3.141592653589793,n="number"==typeof o.rotation&&Number.isFinite(o.rotation)?o.rotation:0;if(n>=.436332&&n<=1.13446||n>=2.00713&&n<=2.70526||n>=3.57792&&n<=4.27606||n>=5.14872&&n<=5.84685){let o=Math.sqrt(Math.pow((s-4)/2,2)+Math.pow((r-4)/2,2));o-=o-(s+r)/3,i=t.createLinearGradient(o*Math.cos(n+e),o*Math.sin(n+e),o*Math.cos(n),o*Math.sin(n))}else i=t.createLinearGradient((s-4)/2*Math.cos(n+e),(r-4)/2*Math.sin(n+e),(s-4)/2*Math.cos(n),(r-4)/2*Math.sin(n))}else if("radial"==o.gradientType){const e=.95*Math.sqrt(Math.pow((s-4)/2,2)+Math.pow((r-4)/2,2));switch(o.center){case"center":default:i=t.createRadialGradient(0,0,0,0,0,e);break;case"left-top":i=t.createRadialGradient(-s/2,-r/2,0,-s/2,-r/2,2*e);break;case"right-top":i=t.createRadialGradient(s/2,-r/2,0,s/2,-r/2,2*e);break;case"left-bottom":i=t.createRadialGradient(-s/2,r/2,0,-s/2,r/2,2*e);break;case"right-bottom":i=t.createRadialGradient(s/2,r/2,0,s/2,r/2,2*e)}}(Array.isArray(o.colorStops)?o.colorStops:Array.isArray(o.gradientStops)?o.gradientStops:[]).forEach(t=>{if(t.position>=0&&t.position<=1)try{i.addColorStop(t.position,t.color)}catch(e){Ji("Invalid Color for colorstop : ",t.color),i.addColorStop(t.position,"#fff")}}),t.fillStyle=i,t.fill(),t.translate(-n.x,-n.y)}else if("pattern"==o.type&&o.image)if(o.guideOnly&&1!=s.app.mode)o.color&&(t.fillStyle=o.color,t.fill());else{s.prepareFillIf(!s._pattern_image_origin);const n=s._pattern_image;if(!n||!n.width||!n.height)return;let i=0,r=0,a=0,c=0,l=e.left,h=e.top;if(!o.fitPattern){i=o.offsetX,r=o.offsetY;const t=o.width?o.width:n.width,s=o.height?o.height:n.height;switch(o.align){case"center":a=e.width/2-t/2,c=e.height/2-s/2;break;case"left-top":a=0,c=0;break;case"left-bottom":a=0,c=e.height-s;break;case"right-top":a=e.width-t,c=0;break;case"right-bottom":a=e.width-t,c=e.height-s;break;case"left":a=0,c=e.height/2-s/2;break;case"right":a=e.width-t,c=e.height/2-s/2;break;case"top":a=e.width/2-t/2,c=0;break;case"bottom":a=e.width/2-t/2,c=e.height-s}l+=i+a,h+=r+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 s._pattern_image,delete s._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 nr(t,e){const n=this.fillStyle;if(!n||"pattern"!=n.type||!n.image)return void t(this);if("string"!=typeof n.image)return this._pattern_image_origin=this._pattern_image=n.image,void t(this);this._pattern_image=null,this._pattern_image_origin=new Image;const i=this;this._pattern_image_origin.onload=function(){if(!n.fitPattern&&!n.width&&!n.height)return i._pattern_image=i._pattern_image_origin,void t(this);let e=n.width||this.width,s=n.height||this.height;n.fitPattern&&(e=i.bounds.width,s=i.bounds.height);const r=tr(e,s);r.getContext("2d").drawImage(this,0,0,this.width,this.height,0,0,e,s),i._pattern_image=r,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 ir(t){t&&this.prepareFill(t=>{this.invalidate()},t=>{Zi(t)})}function sr(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 rr(t,e,n){let{strokeStyle:i,lineDash:s,lineWidth:r,lineCap:o,lineJoin:a,alpha:c}=e;if(i&&0!=r){if(o&&(t.lineCap=o),s){const e="round"==o;switch(s){case"solid":s=[0,0];break;case"round-dot":s=e?[0,2*r]:[r,r];break;case"square-dot":s=e?[r,2*r]:[2*r,r];break;case"dash":s=e?[3*r,2.5*r]:[4*r,1.5*r];break;case"dash-dot":s=e?[3*r,3*r,0,3*r]:[4*r,2*r,r,2*r];break;case"long-dash":s=e?[5*r,4*r]:[6*r,3*r];break;case"long-dash-dot":s=e?[5*r,3*r,0,3*r]:[6*r,2*r,r,2*r];break;case"long-dash-dot-dot":s=e?[5*r,2*r,0,2*r,0,2*r]:[6*r,r,r,r,r,r]}Array.isArray(s)||(s=[]),t.setLineDash(s)}t.globalAlpha*=c,t.strokeStyle=i,t.lineWidth=r,t.lineJoin=a,t.stroke()}}function or(t){const e=/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3|([^\*_]+)/g,n=[];let i;for(;null!==(i=e.exec(t));)i[1]?n.push({text:i[2],bold:!0,italic:!1}):i[3]?n.push({text:i[4],bold:!1,italic:!0}):i[5]&&n.push({text:i[5],bold:!1,italic:!1});return n}function ar(t,e,n,i=0){if(e.text.length<2)return e;let s=2;for(;s<e.text.length;s++){const r=e.text.substring(0,s);if(!(t.measureText(r).width+(s-1)*i<n))break}return{...e,text:e.text.substring(0,s-1)}}function cr(t,e,n,i,s,r=0){const o=String(e).split("\n");return i?[].concat(...o.map(e=>function(t,e,n,i=0){const s=[];let r=[],o=0;return e.forEach(e=>{let a=e.text;for(;a.length>0;){const c=n-o,l=t.measureText(a).width+(a.length-1)*i;if(l<=c)r.push({...e,text:a}),o+=l,a="";else{const n=ar(t,{...e,text:a},c,i);r.push(n),s.push(r),r=[],o=0,a=a.substring(n.text.length)}}}),r.length>0&&s.push(r),s}(t,s?or(e):[{text:e,bold:!1,italic:!1}],n,r))):o.map(t=>s?or(t):[{text:t,bold:!1,italic:!1}])}function lr(t,e,n,i,s,r,o=0){if(!i)return[];t.save(),t.font=n;const a=cr(t,i,e,!!s,r,o);return t.restore(),a}function hr(t){const{fontFamily:e=Qs.FONT_FAMILY,bold:n=Qs.BOLD,italic:i=Qs.ITALIC,fontSize:s=Qs.FONT_SIZE}=t,r=[];return n&&r.push("bold"),i&&r.push("italic"),r.push(s+"px"),r.push(e),r.join(" ")}function dr(t,e){const n=t.bold||e.bold,i=t.italic||e.italic;return hr({...t,bold:n,italic:i})}function ur(t,e,n,i){let{alpha:s,rotation:r,keepTextAngle:o=!1,fontColor:a=Qs.FONT_COLOR,textAlign:c=Qs.TEXT_ALIGN,textBaseline:l=Qs.TEXT_BASELINE,textBackgroundStyle:h,fontSize:d,lineHeight:u,textWrap:p,textOverflow:f,letterSpacing:m=0}=i;s=void 0!==s?s:1,d||=Qs.FONT_SIZE,u||=1.2*d,t.save();const{left:g,top:y,width:b,height:_}=e;if(r&&o&&(t.translate(g+b/2,y+_/2),t.rotate(-r),t.translate(-(g+b/2),-(y+_/2))),t.beginPath(),t.font=hr(i),!p&&f){const e=function(t,e,n,i){const s="ellipsis"===t?"…":"",r=e.measureText(s).width,o=[];let a=0;for(const s of n){const n=[];for(const c of s){const s=e.measureText(c.text).width;if(!(a+s<=i-("ellipsis"===t?r:0))){const s=pr(e,c,i-a-("ellipsis"===t?r:0),t);return n.push(s),o.push(n),o}n.push(c),a+=s}o.push(n),a=0}return o}(f,t,n,b);n=e}const v=n.length*u;let x;switch(l){case"top":x=y,t.textBaseline="top";break;case"bottom":x=y+_-v+u,t.textBaseline="bottom";break;default:x=y+_/2-v/2+u/2,t.textBaseline="middle"}t.globalAlpha*=s,t.fillStyle=a,n.forEach((e,s)=>{const r=x+s*u,o=function(t,e,n,i=0){return e.reduce((e,s)=>(t.font=dr(n,s),e+t.measureText(s.text).width+i*(s.text.length-1)),0)}(t,e,i,m);let l=g;switch(c){case"left":case"justify":l=g;break;case"right":l=g+b-o;break;case"center":l=g+(b-o)/2}if(h&&(t.fillStyle=h,function(t,e,n,i,s,r=0,o=!1,a=!0){r="number"==typeof r?{tl:r,tr:r,br:r,bl:r}:{tl:0,tr:0,br:0,bl:0,...r},t.beginPath(),t.moveTo(e+r.tl,n),t.lineTo(e+i-r.tr,n),t.quadraticCurveTo(e+i,n,e+i,n+r.tr),t.lineTo(e+i,n+s-r.br),t.quadraticCurveTo(e+i,n+s,e+i-r.br,n+s),t.lineTo(e+r.bl,n+s),t.quadraticCurveTo(e,n+s,e,n+s-r.bl),t.lineTo(e,n+r.tl),t.quadraticCurveTo(e,n,e+r.tl,n),t.closePath(),o&&t.fill(),a&&t.stroke()}(t,l-4,r-d/2-4,o+8,d+8,4,!0,!1),t.fillStyle=a),"justify"===c&&s<n.length-1&&e.length>1){const n=b-o,s=e.length-1,a=n/s;e.forEach((e,n)=>{t.font=dr(i,e),t.fillText(e.text,l,r),l+=t.measureText(e.text).width+(n<s?a:0)})}else e.forEach(e=>{t.font=dr(i,e),[...e.text].forEach(e=>{t.fillText(e,l,r),l+=t.measureText(e).width+m})})}),t.restore()}function pr(t,e,n,i){let s="";for(let i=0;i<e.text.length;i++){const r=s+e.text[i];if(t.measureText(r).width>n)break;s=r}return{...e,text:s+("ellipsis"===i?"…":"")}}function fr(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})}Js(),Zs(),tr="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 mr=[];function gr(t,e,n={x:0,y:0},i=0,s={x:1,y:1}){if(1!==s.x||1!==s.y?(t=(t-n.x)/s.x,e=(e-n.y)/s.y):(t-=n.x,e-=n.y),0!==i){const n=Math.cos(-i),s=Math.sin(-i),r=t*s+e*n;t=t*n-e*s,e=r}return{x:t+n.x,y:e+n.y}}function yr(t,e,n={x:0,y:0},i=0,s={x:1,y:1}){if(t-=n.x,e-=n.y,0!==i){const n=Math.cos(i),s=Math.sin(i),r=t*s+e*n;t=t*n-e*s,e=r}return 1!==s.x||1!==s.y?{x:t*s.x+n.x,y:e*s.y+n.y}:{x:t+n.x,y:e+n.y}}function br(t,e,n){if(!this.parent)return{x:t,y:e};const{rotation:i=0,scale:s={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,r=gr(t,e,n,i,s);return n&&(r.x-=n.x,r.y-=n.y),r}return gr(t,e,n=n||this.rotatePoint,i,s)}function _r(t,e,n){if(!this.parent)return{x:t,y:e};let{rotation:i=0,scale:s={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,r=yr(t,e,void 0,i+(this._delta?.theta??0),s);return n&&(r.x+=n.x,r.y+=n.y),r}n=n||this.rotatePoint;const{theta:r=0,tx:o=0,ty:a=0,sx:c=1,sy:l=1}=this._delta||{};if(0===r&&0===o&&0===a&&1===c&&1===l)return yr(t,e,n,i,s);return yr(t+o,e+a,{x:n.x+o,y:n.y+a},i+r,{x:s.x*c,y:s.y*l})}function vr(t,e,n){n=n||this.rootModel;const i=this.transcoordS2T(t,e,n);return yr(i.x,i.y,void 0,(n.get("rotation")||0)+n._delta.theta)}function xr(t,e,n){n=n||this.rootModel,mr.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)mr.push(t);let i=this.transcoordS2P(t,e);for(let t=0;t<mr.length;t++){const e=mr[t],n=e.bounds;i.x+=n.left,i.y+=n.top,i=e.transcoordS2P(i.x,i.y)}return i}function wr(t,e,n){n=n||this.rootModel,mr.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)mr.push(t);let i={x:t,y:e};for(let t=mr.length-1;t>=0;t--){const e=mr[t];i=e.transcoordP2S(i.x,i.y);const n=e.bounds;i.x-=n.left,i.y-=n.top}return i}function Mr(t,e,n){const i=this.transcoordT2P(t,e,n);return this.transcoordP2S(i.x,i.y)}function Sr(t,e,n){const i=this.rootModel,s=this.transcoordS2T(t,e,i);return n.transcoordT2S(s.x,s.y,i)}function kr(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;const{translate:i={x:0,y:0},scale:s={x:1,y:1},rotation:r=0}=n.model,o=gr(t,e,i,r,s);return i&&(o.x-=i.x,o.y-=i.y),n===this?o:this.transcoordT2S(o.x,o.y,n)}function Ar(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;let i;if(i=n!==this?this.transcoordS2T(t,e,n):{x:t,y:e},!this.scalable)return i;const{translate:s={x:0,y:0},rotation:r=0,scale:o={x:1,y:1}}=n.model;return i=yr(i.x,i.y,void 0,r+n._delta.theta,o),s&&(i.x+=s.x,i.y+=s.y),i}function Er(t){let e=0,n=0,i=0,s=0,r=!1;return t.forEach(t=>{r?(e=Math.min(t.left,e),n=Math.min(t.top,n),i=Math.max(t.left+t.width,i),s=Math.max(t.top+t.height,s)):(e=t.left,n=t.top,i=t.left+t.width,s=t.top+t.height,r=!0)}),{left:e,top:n,width:i-e,height:s-n}}function Cr(t){const e=t.element,n=t.fillStyle,i=e.style;if(n)if("string"==typeof n)i.backgroundColor=n;else switch(n.type){case"pattern":if(i.backgroundImage="url("+n.image+")",i.backgroundColor="transparent",n.fitPattern?i.backgroundSize="100% 100%":n.width||n.height?i.backgroundSize=`${n.width?n.width+"px":"auto"} ${n.height?n.height+"px":"auto"}`:i.backgroundSize="contain",n.fitPattern)i.backgroundRepeat="no-repeat";else{const{offsetX:t,offsetY:e,noRepeat:s,align:r,color:o}=n;if(s&&(i.backgroundRepeat="no-repeat"),o&&(i.backgroundColor=o),r)switch(r){case"center":i.backgroundPosition="center center";break;case"left-top":i.backgroundPosition="left top";break;case"left-bottom":i.backgroundPosition="left bottom";break;case"right-top":i.backgroundPosition="right top";break;case"right-bottom":i.backgroundPosition="right bottom";break;case"left":i.backgroundPosition="left center";break;case"right":i.backgroundPosition="right center";break;case"top":i.backgroundPosition="center top";break;case"bottom":i.backgroundPosition="center bottom"}else t||e?i.backgroundPosition=`${Number(t)||0}px ${Number(e)||0}px`:delete i.backgroundPosition}break;case"gradient":i.background=function(t,e){const n=e.colorStops,i=e.gradientType;if(n instanceof Array&&n.length>0)switch(i){case"radial":return"radial-gradient(farthest-corner at "+function(t,e){const{width:n,height:i}=t.bounds;switch(e){case"center":return[n/2,i/2];case"left-top":return[0,0];case"right-top":return[n,0];case"left-bottom":return[0,i];default:return[n,i]}}(t,e.center||"center").map(t=>t+"px").join(" ")+","+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")";case"linear":return"linear-gradient("+(180*(e.rotation||0)/3.141592653589793+90+"deg")+", "+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")"}return""}(t,n)}else i.background="transparent"}const Tr={x:1,y:1},Pr={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"};function Or(t){let{id:e,scale:n=Tr,bold:i,italic:s,fontFamily:r="",textAlign:o,textBaseline:a,textOverflow:c,paddingTop:l,paddingBottom:h,paddingLeft:d,paddingRight:u,fontSize:p=Qs.FONT_SIZE,lineWidth:f=0,lineHeight:m,lineDash:g}=t.state;h||=0,l||=0,d||=0,u||=0;const y=t.state.class,{strokeStyle:b,rotation:_=0,fontColor:v,hidden:x}=t,{left:w,top:M,width:S,height:k}=t.bounds,A=t.element;if(A.hidden=!t.app?.isEditMode&&x,e&&(A.id=e),y&&(A.className=y),Object.assign(A.style,Pr,{fontFamily:r,fontSize:p+"px",width:S+"px",height:k+"px",paddingTop:l+"px",paddingRight:u+"px",paddingBottom:h+"px",paddingLeft:d+"px",border:f+"px",borderColor:b,borderStyle:f>0?g||Qs.LINE_DASH:"",color:v,fontWeight:i?"bold":"",fontStyle:s?"italic":"",textAlign:"end"==o?"right":"start"==o?"left":o,verticalAlign:a,lineHeight:void 0===m?"":m+"px",whiteSpace:c?"nowrap":"",overflow:c?"hidden":"",textOverflow:c||""},t.isIn3DSpace()?{}:{left:w+"px",top:M+"px"}),Cr(t),function(t){if(!t.isShadowable()||!t.state.shadow)return;const e=t.state.shadow,n=e.offsetX??e.left??0,i=e.offsetY??e.top??0,s=e.blur??e.blurSize??0,r=e.color??"transparent";t.element.style.boxShadow=`${n}px ${i}px ${s}px ${r}`}(t),t.isIn3DSpace())return;const E=t.delta(),C=(n&&n.x||1)*E.sx,T=(n&&n.y||1)*E.sy,P=(_||0)+E.theta,O=E.tx||0,D=E.ty||0;A.style.transform=`rotate(${P}rad) translate(${O}px, ${D}px) scale(${C}, ${T}) perspective(1px)`}function Dr(t,e){let n=this.bounds,i=this.rotatePoint;const s=this.get("rotation"),r=this.get("scale");if(t){const i=t.call(e,n);i&&(n=i)}const{left:o,top:a,width:c,height:l}=n;let h=[{x:o,y:a},{x:o+c,y:a+l}];h=h.map(t=>yr(t.x,t.y,i,s,r));let d=h[0],u=h[1];i={x:(d.x+u.x)/2,y:(d.y+u.y)/2},h=h.map(t=>gr(t.x,t.y,i,s,r)),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 zr(t,e,n){let i=this.path,s=this.rotatePoint;t&&(i=t.call(n,i));let r=i.map(t=>{const e=this.toParent(t.x,t.y);return{...t,x:e.x,y:e.y}});if(e){const t=e.call(n,r);t&&(r=t)}const o={x:0,y:0};let a,c,l,h;i=r.map(t=>this.fromParent(t.x,t.y,o)),a=c=i[0].x,l=h=i[0].y;for(let t=1;t<i.length;t++){const e=i[t];e.x<a?a=e.x:e.x>c&&(c=e.x),e.y<l?l=e.y:e.y>h&&(h=e.y)}s={x:(a+c)/2,y:(l+h)/2},s=this.toParent(s.x,s.y,o),this.path=r.map(t=>{const e=this.fromParent(t.x,t.y,s);return{...t,x:e.x,y:e.y}})}const Ir=new class{constructor(){this._now=0,this._speed=1,this._paused=!1,this._listeners=new Set}get now(){return this._now}get speed(){return this._speed}set speed(t){this._speed=Math.max(0,t),this._speed>0&&(this._paused=!1)}get isPaused(){return this._paused}pause(){this._paused=!0}resume(){this._paused=!1}tick(t){if(this._paused||0===this._speed)return 0;const e=Math.min(t,200)*this._speed;return this._now+=e,this._notify(e),e}step(t){t<=0||(this._now+=t,this._notify(t))}onTick(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(t){this._listeners.forEach(e=>e(t))}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_SIM_CLOCK__=Ir);function Rr(t){const e=t?.state;return{type:e?.type??t?.constructor?.name,id:e?.id,refid:e?.refid,className:t?.constructor?.name}}const jr=new class{constructor(){this._realTime=0,this._totalTicks=0,this._subs=new Set,this._nextId=1,this._externals=new Set,this._externalNextId=1,this._rafId=null,this._lastWallTime=null,this._emaDt=16.67,this._ticking=!1,this._hasPendingRemoval=!1}get realTime(){return this._realTime}get simTime(){return Ir.now}get isRunning(){return null!==this._rafId}subscribe(t,e){const n=e?.component,i=n?.app??n?.root?.app;if(i&&"boolean"==typeof i.isViewMode&&!i.isViewMode)return()=>{};const s={id:this._nextId++,handler:t,description:e?.description??`<anonymous#${this._nextId-1}>`,componentRef:null!=e?.component&&"undefined"!=typeof WeakRef?new WeakRef(e.component):void 0,targetsGetter:e?.getTargets,metadata:e?.metadata,registeredAt:this._realTime,tickCount:0,totalDurationMs:0,lastDt:0,lastDurationMs:0};return this._subs.add(s),this.isRunning||this.start(),()=>{this._ticking?(s._removed=!0,this._hasPendingRemoval=!0):(this._subs.delete(s),0===this._subs.size&&this.stop())}}tick(t){const e=Math.min(Math.max(t,0),200);this._realTime+=e,Li.enabled&&(this._totalTicks++,e>0&&(this._emaDt=.9*this._emaDt+.1*e));const n=Ir.tick(e),i=Ir.now;if(this._ticking=!0,Li.enabled)for(const t of this._subs){if(t._removed)continue;const e=performance.now();try{t.handler(n,i)}finally{const i=performance.now()-e;t.tickCount++,t.totalDurationMs+=i,t.lastDt=n,t.lastDurationMs=i}}else for(const t of this._subs)t._removed||t.handler(n,i);if(this._ticking=!1,this._hasPendingRemoval){this._hasPendingRemoval=!1;for(const t of this._subs)t._removed&&this._subs.delete(t);0===this._subs.size&&this.stop()}}start(){if(null!==this._rafId)return;if("undefined"==typeof requestAnimationFrame)return;this._lastWallTime=null;const t=()=>{if(null===this._rafId)return;const e=performance.now(),n=null===this._lastWallTime?0:e-this._lastWallTime;this._lastWallTime=e,this.tick(n),null!==this._rafId&&(this._rafId=requestAnimationFrame(t))};this._rafId=requestAnimationFrame(t)}stop(){null!==this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._lastWallTime=null}registerExternalAnimation(t,e,n){const i={id:this._externalNextId++,description:t,source:e,metadata:n,registeredAt:this._realTime};return this._externals.add(i),{update:t=>{i.metadata={...i.metadata??{},...t}},unregister:()=>{this._externals.delete(i)}}}snapshot(){const t=[];for(const e of this._subs){if(e._removed)continue;let n;const i=e.componentRef?.deref();let s;if(i&&(n=Rr(i)),e.targetsGetter)try{const t=e.targetsGetter();if(null!=t){const e=Array.isArray(t)?t:[t],n=[];for(const t of e)null!=t&&n.push(Rr(t));n.length>0&&(s=n)}}catch{}t.push({id:e.id,description:e.description,componentInfo:n,targetInfos:s,metadata:e.metadata,registeredAt:e.registeredAt,tickCount:e.tickCount,totalDurationMs:Math.round(100*e.totalDurationMs)/100,avgDurationMs:e.tickCount>0?Math.round(e.totalDurationMs/e.tickCount*100)/100:0,lastDt:Math.round(100*e.lastDt)/100,lastDurationMs:Math.round(100*e.lastDurationMs)/100})}const e=[];for(const t of this._externals)e.push({id:t.id,description:t.description,source:t.source,metadata:t.metadata,registeredAt:t.registeredAt,liveDurationMs:Math.round(this._realTime-t.registeredAt)});return{realTime:Math.round(this._realTime),simTime:Math.round(Ir.now),isRunning:this.isRunning,speed:Ir.speed,paused:Ir.isPaused,totalTicks:this._totalTicks,ticksPerSecond:this._emaDt>0?Math.round(1e3/this._emaDt):0,totalSubs:t.length,subscriptions:t,externalAnimations:e}}},Lr=new Map;let Fr=null;function Nr(){Fr&&(Fr(),Fr=null)}function Hr(t){return!t.disposed&&t.retention>0&&!t.isTemplate()&&t.app&&t.app.isViewMode}var Br=new class{add(t){var e;Hr(t)&&!Lr.has(t)&&(Lr.set(t,0),e=t?.root,Fr||(Fr=jr.subscribe(t=>{if(0===t)return;const e=[];for(const[n,i]of Lr){if(!Hr(n)){e.push(n);continue}const s=i+t;s>=n.retention?e.push(n):Lr.set(n,s)}for(const t of e){Lr.delete(t);try{t.disposed||t.removeSelf?.(!0)}catch(t){Zi("RetentionManager removeSelf failed:",t)}}0===Lr.size&&Nr()},{description:"retention timer",component:e,getTargets:()=>Array.from(Lr.keys()),metadata:{get count(){return Lr.size},get preview(){return Array.from(Lr.entries()).slice(0,3).map(([t,e])=>({type:t?.state?.type,id:t?.state?.id??"-",retentionMs:t?.retention,remainingMs:Math.max(0,Math.round(t?.retention-e))}))}}})))}remove(t){Lr.delete(t)&&0===Lr.size&&Nr()}touch(t){t&&Lr.has(t)&&Lr.set(t,0)}dispose(){Nr(),Lr.clear()}get length(){return Lr.size}};const Gr=function(t){return t};function Vr(t){const e=t.indexOf("||");let n="",i="";-1!=e&&(n=t,i=t.substring(e+2,t.length-1).trim(),t=t.replace(t.substring(e,t.length-1),"").trim());const s=t.substr(2,t.length-3).trim().replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".").filter(t=>!!t.trim()),r=s.slice(1);return{defaultValue:i,match:t,originText:n||t,target:s[0],accessor:r.length>0?function(t){return r.reduce((t,e)=>t?t[e]:void 0,t)}:Gr}}function Yr(t){if(!t)return;const e=String(t),n=(e.match(/#{(\S*)}/)||[]).map(t=>Vr(t))[0];if(n)return n.accessor(this.getState(n.target));const i=(e.match(/\${[^}]*}/)||[]).map(t=>Vr(t))[0];if(i){const t=this.root.findById(i.target);return i.accessor(this.getState(t))}return t}function Wr(t,e){if(!t)return;const n=String(t),i=e||wi,s=(n.match(/#{(\S*)}/gi)||[]).map(t=>Vr(t)),r=(n.match(/\${[^}]*}/gi)||[]).map(t=>Vr(t));if(0==s.length&&0==r.length)return n;let o=n;return s.forEach(t=>{const e=i(t.accessor(this.getState(t.target)));o=o.replace(t.match,void 0===e?"":e)}),r.forEach(t=>{const e=this.root.findById(t.target),n=i(t.accessor(e&&e.data));o=o.replace(t.match,void 0===n?"":n)}),o}function Ur(t,e,n){if(!t)return;const i=n||wi,s=String(t),r=(s.match(/#{[^}]*}/gi)||[]).map(t=>Vr(t)),o=(s.match(/\${[^}]*}/gi)||[]).map(t=>Vr(t));return 0!=r.length||0!=o.length?function(){let t=s;return r.forEach(n=>{const s=i(n.accessor(e.getState(n.target)));t=t.replace(n.originText,void 0===s?n.defaultValue||"":s)}),o.forEach(n=>{const s=e.root.findById(n.target),r=i(n.accessor(s&&s.data));t=t.replace(n.originText,void 0===r?n.defaultValue||"":r)}),t}:void 0}class $r{constructor(){}static registerDecorator(t,e){$r.constructors.set(t,e)}static create(t,e,n={},i){const s=$r.constructors.get(t);if(!s)throw new Error(`unknown decorator type: ${t}`);return new s(i,e,n)}}$r.constructors=new Map;class Xr{constructor(){this.overlays=new WeakMap,this._pendingOverlays=new Set}static getInstance(){return Xr.instance||(Xr.instance=new Xr),Xr.instance}addOverlay(t){if(this.overlays.has(t))return!1;const e={element:t,registry:new Map};return this.overlays.set(t,e),!0}removeOverlay(t){if(!this.overlays.has(t))return!1;const e=this.overlays.get(t);for(const[n]of e.registry)this.removeFromOverlay(t,n);return this.overlays.delete(t),!0}addToOverlay(t,e,n,i={}){this.overlays.has(t)||this.addOverlay(t);const s=this.overlays.get(t);s.registry.has(e)||s.registry.set(e,new Map);const r=s.registry.get(e);r.has(n)&&r.get(n).stop();const o=$r.create(n,e,i,t);return r.set(n,o),o.start(),o}removeFromOverlay(t,e,n){if(!this.overlays.has(t))return;const i=this.overlays.get(t);if(!i.registry.has(e))return;const s=i.registry.get(e);let r=null;if(n){if(s.has(n))try{const t=s.get(n);r=n,t&&"function"==typeof t.stop&&t.stop(),s.delete(n)}catch(t){Zi(`데코레이터(${n}) 제거 중 오류:`,t)}}else{const t=Array.from(s.keys());for(const e of t)try{const t=s.get(e);t&&"function"==typeof t.stop&&t.stop(),s.delete(e)}catch(t){Zi(`데코레이터(${e}) 제거 중 오류:`,t)}r="_all_"}0===s.size&&i.registry.delete(e),!r||"data-spread"!==r&&"_all_"!==r||this.restartBorderAnimations(t,e)}restartBorderAnimations(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);for(const[t,i]of n.registry.entries()){if(e&&t===e)continue;const n=i.get("border-highlighting");if(n)try{"function"==typeof n.invalidate&&n.invalidate();const t=n;"function"==typeof t.startAnimations&&t.options&&t.options.animation&&t.startAnimations()}catch(t){Zi("애니메이션 재시작 중 오류:",t)}}}removeAllFromOverlay(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);if(e)for(const[i]of n.registry)this.removeFromOverlay(t,i,e);else{for(const[,t]of n.registry)for(const e of t.values())e.stop();n.registry.clear()}}getDecoratorFromOverlay(t,e,n){const i=this.overlays.get(t);return i?.registry.get(e)?.get(n)}getDecoratorsFromOverlay(t,e){const n=this.overlays.get(t);return n&&n.registry.has(e)?Array.from(n.registry.get(e).values()):[]}getTargetsWithType(t,e){const n=this.overlays.get(t);if(!n)return[];const i=[];for(const[t,s]of n.registry)s.has(e)&&i.push(t);return i}updateInOverlay(t,e,n,i){const s=this.getDecoratorFromOverlay(t,e,n);s&&s.update(i)}invalidateOverlay(t){this.overlays.has(t)&&(this._pendingOverlays.add(t),null==this._rafId&&(this._rafId=requestAnimationFrame(()=>{this._rafId=void 0;const t=Array.from(this._pendingOverlays);this._pendingOverlays.clear();for(const e of t)this._flushOverlay(e)})))}_flushOverlay(t){if(!this.overlays.has(t))return;const e=this.overlays.get(t),n=Array.from(e.registry.entries());for(const[e,i]of n){if(e.disposed){this.removeFromOverlay(t,e);continue}this.getDecoratorsFromOverlay(t,e).forEach(t=>{t.invalidate()})}}}const qr=.5;function Kr(t){const e=t.bulge;return null!=e&&Number.isFinite(e)&&Math.abs(e)>=qr}function Qr(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(i*i+s*s);if(0===r||!Number.isFinite(n)||Math.abs(n)<1e-9)return null;const o=Math.abs(n),a=(r*r+4*o*o)/(8*o),c=n>0?1:-1,l=a-o,h=(t.x+e.x)/2-c*(s/r)*l,d=(t.y+e.y)/2-c*-(i/r)*l;return{cx:h,cy:d,radius:a,startAngle:Math.atan2(t.y-d,t.x-h),endAngle:Math.atan2(e.y-d,e.x-h),clockwise:n<0}}function Zr(t,e,n=0,i=16){const s=e.x-t.x,r=e.y-t.y,o=Math.sqrt(s*s+r*r);if(0===o)return null;const a=r/o,c=-(s/o),l=Number.isFinite(n)?n:0,h=Math.abs(l)>=1e-6?l:i;return{x:(t.x+e.x)/2+a*h,y:(t.y+e.y)/2+c*h,perpX:a,perpY:c}}function Jr(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(i*i+s*s);if(0===r)return 0;const o=s/r,a=-(i/r),c=(t.x+e.x)/2,l=(t.y+e.y)/2;let h=(n.x-c)*o+(n.y-l)*a;if(Math.abs(h)<qr)return 0;return h>r&&(h=r),h<-r&&(h=-r),h}function to(t,e){const n=t.radius,i=Number.isFinite(e)?e:0;return null!=n&&Number.isFinite(n)?Math.max(0,n):Math.max(0,i)}function eo(t,e,n,i,s=16){const r=t.x-e.x,o=t.y-e.y,a=Math.sqrt(r*r+o*o);if(0===a)return null;const c=n.x-e.x,l=n.y-e.y,h=Math.sqrt(c*c+l*l);if(0===h)return null;const d=r/a+c/h,u=o/a+l/h,p=Math.sqrt(d*d+u*u);if(p<1e-9)return null;const f=d/p,m=u/p,g=Math.max(i,s);return{x:e.x+f*g,y:e.y+m*g,bisectorX:f,bisectorY:m}}function no(t,e,n,i){const s=t.x-e.x,r=t.y-e.y,o=Math.sqrt(s*s+r*r),a=n.x-e.x,c=n.y-e.y,l=Math.sqrt(a*a+c*c);if(0===o||0===l)return 0;const h=s/o+a/l,d=r/o+c/l,u=Math.sqrt(h*h+d*d);if(u<1e-9)return 0;const p=h/u,f=d/u,m=(i.x-e.x)*p+(i.y-e.y)*f,g=Math.min(o,l)/2;return Math.max(0,Math.min(m,g))}function io(t){if(0===t.length)return 0;let e;for(const n of t){const t=n.z??0;if(!Number.isFinite(t))return null;if(void 0===e)e=t;else if(Math.abs(t-e)>1e-9)return null}return e??0}function so(t,e){const n=e.x-t.x,i=e.y-t.y,s=Math.sqrt(n*n+i*i);if(!Kr(t))return s;const r=Qr(t,e,t.bulge);if(!r)return s;const o=Math.min(r.radius,s/2),a=2*Math.asin(o/r.radius);return r.radius*a}function ro(t,e){const n=t.path.slice();if(!n||!n.length)return void Zi("path should not be empty");let i=1;const s=[];if(t.isLine()||n.push(n[0]),e<=0)return t.toScene(n[0].x,n[0].y);if(e>=1)return t.toScene(n[n.length-1].x,n[n.length-1].y);for(;n[i];)s.push(so(n[i-1],n[i])),i++;const r=s.reduce(function(t,e){return t+e},0);i=0;let o=0;do{o+=s[i++]}while(o/r<e);o-=s[--i];e=(e-o/r)*(r/s[i]);const a=n[i%n.length],c=n[(i+1)%n.length],{x:l,y:h}=function(t,e,n){if(Kr(t)){const i=Qr(t,e,t.bulge);if(i){let t=i.endAngle-i.startAngle;i.clockwise?t>0&&(t-=2*Math.PI):t<0&&(t+=2*Math.PI);const e=i.startAngle+n*t;return{x:i.cx+i.radius*Math.cos(e),y:i.cy+i.radius*Math.sin(e)}}}return{x:t.x+Math.round((e.x-t.x)*n),y:t.y+Math.round((e.y-t.y)*n)}}(a,c,e);return t.toScene(l,h)}function oo(t,e){return!1}function ao({x:t,y:e},...n){const i=this.path,s=t,r=e;this.path=i.map(t=>({...t,x:t.x+s,y:t.y+r}))}function co(t){const e=t??this.center.x,{rotation:n}=this.state,i=this.fillStyle;if(this.set("rotation",2*Math.PI-n),i&&"gradient"===i.type&&"linear"===i.gradientType){const t=ni(i);t.rotation=(Math.PI-parseFloat(i.rotation||0))%(2*Math.PI),this.set("fillStyle",t)}this.path=this.path.map(t=>({...t,x:2*e-t.x,y:t.y}))}function lo(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 ho(t,e,n){if(n){const e=this.bounds,n=e.height/e.width;let i=t.width-e.width,s=t.height-e.height;i*n>s?s=i*n:i=s/n;let r=t.left-e.left,o=t.top-e.top;return 0!=r&&0!=o?(o=-s,r=-i):0!=r?r=-i:0!=o&&(o=-s),{left:e.left+r,top:e.top+o,width:e.width+i,height:e.height+s}}return t}function uo(t,e){if(e||this.app.rotateStepForced){const e=this.app.rotateStep;return Math.floor((t+e/2)/e)*e}return t}function po(t){return ro(this,t||0)}function fo(){const t=this.path;let e,n,i,s;e=n=t[0].x,i=s=t[0].y;for(let r=1;r<t.length;r++){const o=t[r];o.x<e?e=o.x:o.x>n&&(n=o.x),o.y<i?i=o.y:o.y>s&&(s=o.y)}return{left:e,top:i,width:n-e,height:s-i}}function mo(t){const e=this.bounds;if(Math.round(100*t.width)/100==Math.round(100*e.width)/100&&Math.round(100*t.height)/100==Math.round(100*e.height)/100&&Math.round(100*t.left)/100==Math.round(100*e.left)/100&&Math.round(100*t.top)/100==Math.round(100*e.top)/100)return;const n=0==e.width?1:t.width/e.width,i=0==e.height?1:t.height/e.height;this.path=this.path.map(s=>({...s,x:t.left+(s.x-e.left)*n,y:t.top+(s.y-e.top)*i}))}function go(){const t=this.bounds;return{x:t.left+t.width/2,y:t.top+t.height/2}}function yo(t){if(!t||isNaN(t.x)||isNaN(t.y))return;const e=this.center;if(Math.round(100*t.x)/100==Math.round(100*e.x)/100&&Math.round(100*t.y)/100==Math.round(100*e.y)/100)return;const n=t.x-e.x,i=t.y-e.y;this.path=this.path.map(t=>({...t,x:t.x+n,y:t.y+i}))}function bo(){const{x:t,y:e}=this.center;return{x:t,y:e,z:this.state.zPos}}function _o(t){const{x:e,y:n,z:i}=t||{};this.center={x:e,y:n},isNaN(i)||this.setState("zPos",Number(i))}function vo(){const{rotationX:t,rotationY:e,rotation:n}=this.state;return{x:t,y:e,z:-n}}function xo(t){const{x:e,y:n,z:i}=t;this.setState({rotationX:e,rotationY:n,rotation:-i})}function wo(){const{width:t,height:e}=this.bounds,{depth:n}=this.state;return{width:t,height:e,depth:n}}function Mo(t){const{width:e,height:n,depth:i}=t,{top:s,left:r}=this.bounds;this.bounds={top:s,left:r,width:e,height:n},this.setState("depth",i)}function So(){return Zi("이 컴포넌트에 get path 가 구현되어있지 않음.",this),[]}function ko(t){Zi("이 컴포넌트에 get path 가 구현되어있지 않음.",this)}function Ao(){return this.path}function Eo(){return this.center}function Co(){return this.nature.mutable}function To(){return this.nature.resizable&&!this.stuck}function Po(){return this.nature.rotatable&&!this.stuck}const Oo={x:1,y:1};function Do(t,e,n){const{offsetX:i,offsetY:s,blur:r,color:o}=function(t){return{offsetX:t.offsetX??t.left??0,offsetY:t.offsetY??t.top??0,blur:t.blur??t.blurSize??0,color:t.color??"transparent"}}(e),a=n.rootModel.get("scale")??Oo;t.shadowOffsetX=i*a.x*Xs,t.shadowOffsetY=s*a.y*Xs,t.shadowBlur=r*a.x*Xs,t.shadowColor=o}function zo(t){const e=t?.app;if(!e?.isEditMode)return!1;const n=e.focusFilter;return!!(t.hidden||n&&!n(t))}function Io(t){t.save(),this.prerender(t);const e=this.app,n=!0===t.__inHiddenSubtree;e?.isEditMode&&((zo(this)||n)&&(t.globalAlpha*=.5),this.hidden&&(t.__inHiddenSubtree=!0)),this.render(t),this.postrender(t),t.__inHiddenSubtree=n,t.restore()}function Ro(t){const e=this.rotatePoint,{scale:n,rotation:i,shadow:s,alpha:r}=this.state,o=(n&&n.x||1)*this._delta.sx,a=(n&&n.y||1)*this._delta.sy,c=(i||0)+this._delta.theta,{tx:l=0,ty:h=0}=this._delta,d=(r||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),s&&Do(t,s,this)}function jo(t){}function Lo(t){this.drawText(t)}function Fo(t,e){t(this)}function No(t){t&&this.prepare&&this.prepare(t=>{this.invalidate()},t=>{Zi(t)})}function Ho(t){!this.textHidden&&this.text&&this.hasTextProperty&&ur(t,this.textBounds,this.textLines(t),this.state)}function Bo(t,e){rr(t,e?{...this.state,...e}:this.state)}function Go(t,e){this.fillStyle&&"transparent"!=this.fillStyle&&(er(t,this.bounds,this.center,e?{...this.state,...e}:this.state,this),function(t){t.shadowColor="transparent"}(t))}function Vo(){return this.get("strokeStyle")}function Yo(t){this.set("strokeStyle",t)}function Wo(){return this.getState("fillStyle")}function Uo(t){this.setState("fillStyle",t)}function $o(){return this.get("fontColor")}function Xo(t){this.set("fontColor",String(wi(t)))}function qo(){return this.getState("rotation")}function Ko(t){this.setState("rotation",Number(wi(t)))}function Qo(){return this.app.isEditMode?["decotag","data-spread"]:[]}function Zo(){const{id:t,tag:e}=this.state;return(t?`#${t}`:"")+(e?`@${e}`:"")}function Jo(){return this.getState("hidden")||!this.data&&0!==this.data&&this.getState("ndns")||this.isTemplate()}function ta(t){this.setState("hidden",t)}function ea(){return this.state.tag}function na(t){this.setState("tag",t)}function ia(){}function sa(t){this.data instanceof Array?this.data=this.data.concat(t):this.data instanceof Object?this.data={...this.data,...t}:this.data??=t}function ra(){const t=this.getState("text");return null==t?"":String(t)}function oa(t){const{textWrap:e,supportMarkdown:n}=this.state;return lr(t||this.getContext(),this.textBounds.width,this.font,this.text,e,n)}function aa(){return hr(this.model)}function ca(){const t=this.get("lineHeight");return t||1.2*this.fontSize}function la(){return this._text_substitutor||(this._text_substitutor=Ur(this.getState("text"),this,void 0)||this.defaultTextSubstitutor),this._text_substitutor}function ha(){const t=this.get("textFormat");return t?function(t,e){if(!t||isNaN(+e))return e;let n,i,s,r,o,a,c,l,h,d,u,p=t.length,f=t.search(/[0-9\-\+#]/),m=f>0?t.substring(0,f):"",g=t.split("").reverse().join(""),y=g.search(/[0-9\-\+#]/),b=p-y,_=t.substring(b,b+1),v=b+("."===_||","===_?1:0),x=y>0?t.substring(v,p):"";if(n=(e="-"===(t=t.substring(f,v)).charAt(0)?-e:+e)<0?e=-e:0,i=t.match(/[^\d\-\+#]/g),s=".",r=i&&i[1]&&i[0]||",",t=t.split("."),e=+(e=e.toFixed(t[1]&&t[1].length))+"",a=t[1]&&t[1].lastIndexOf("0"),l=e.split("."),(!l[1]||l[1]&&l[1].length<=a)&&(e=(+e).toFixed(a+1)),h=t[0].split(r),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],g="",b=d.length%c,p=d.length,v=0;v<p;v++)g+=d.charAt(v),!((v-b+1)%c)&&v<p-c&&(g+=r);e[0]=g}return e[1]=t[1]&&e[1]?"."+e[1]:"",i=e.join(""),"0"!==i&&""!==i||(n=!1),u="+"==t[0].substring(0,1)?n?"-":"+":n?"-":"",m+(u+i)+x}(t,this.textSubstitutor()):this.textSubstitutor()}function da(t){delete this._text_substitutor;const e=wi(t);this.setState("text",null==e?"":String(e))}function ua(){let{paddingTop:t,paddingLeft:e,paddingRight:n,paddingBottom:i}=this.state;i||=0,t||=0,e||=0,n||=0;const{left:s,top:r,width:o,height:a}=this.bounds;return{left:s+e,top:r+t,width:Math.max(o-e-n,0),height:Math.max(a-t-i,0)}}function pa(){return 0}function fa(){return!!this._textHidden}function ma(t){this._textHidden=!!t,this.invalidate()}function ga(){return!0}function ya(t){return t}function ba(t){return Math.pow(t,2)}function _a(t){return 1-Math.sin(Math.acos(t))}function va(t,e={x:1.5}){return Math.pow(t,2)*((e.x+1)*t-e.x)}function xa(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 wa(t,e={x:1.5}){return Math.pow(2,10*(t-1))*Math.cos(20*Math.PI*e.x/3*t)}var Ma={linear:ya,quad:ba,circ:_a,back:va,bounce:xa,elastic:wa},Sa=Object.freeze({__proto__:null,back:va,bounce:xa,circ:_a,default:Ma,elastic:wa,linear:ya,quad:ba});function ka(t){const{duration:e=1e3,easing:n,component:i,step:s=()=>{},onStart:r,onProgress:o,onComplete:a,options:c,repeat:l=!1,delta:h}=t;let d;d="string"==typeof h?Sa[h]:h||ya,"out"===n?d=function(t,e){return function(n){return 1-t(1-n,e)}}(d,c):"inout"===n&&(d=function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(d,c));let u=!1,p=null;return{start:function(){if(u)return this;if(i?.root?.app?.suppressAnimations)return this;u=!0,r&&r();let t=0;const n=()=>jr.simTime;return p=jr.subscribe(()=>{if(!u)return;if(i?.root?.app?.suppressAnimations)return this.stop(),void(t=0);0===t&&(t=n());const r=(n()-t)/e,a=l?r%1:Math.min(r,1);s(d(a,c)),o&&o(a),!(r>=1)||l&&u||(this.stop(),t=0)},{description:"animate()",component:i,metadata:{duration:e,repeat:l}}),this},stop:function(){return u=!1,p&&(p(),p=null),a&&a(),this}}}class Aa{constructor(t,e){this._started=!1,this._unsub=null,this._timeout=null,this.client=t,this.config=e,this._started=!1;const{delta:n="linear",options:i,ease:s}=this.config;let r;r="string"==typeof n?Ma[n]:n,this.delta="out"===s?function(t,e){return function(n){return 1-t(1-n,e)}}(r,i):"inout"===s?function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(r,i):r,this.init()}dispose(){this.stop(),delete this.client}init(){}start(){if(this._started)return;if(this.client?.root?.app?.suppressAnimations)return;const{duration:t=2e3,delay:e=0,repeat:n=!1,interval:i=0,onComplete:s}=this.config;this._started=!0;const r=this.config?.type??"animation";let o=0,a=0;const c=()=>jr.simTime,l=()=>{if(!this._started)return;if(this.client?.root?.app?.suppressAnimations)return void this.stop(s);0==o&&(o=c(),this.client?.touch?.());const h=c()-o,d=Math.max((h-e)%(t+i),0)/t,u=i<=0&&a>d;if(a=d,d>=1||u){if(this.step(1),this.client&&this.client.invalidate?.(),!n||!this._started)return this.stop(s),void(o=0);if(i>0)return this._unsub?.(),this._unsub=null,void(this._timeout=setTimeout(()=>{this._timeout=null,this.step(0),this.client&&this.client.invalidate?.(),this._timeout=setTimeout(()=>{this._timeout=null,this._started&&(this._unsub=jr.subscribe(l,{description:`animation: ${r}`,component:this.client,metadata:{duration:t,delay:e,repeat:n,interval:i}}))},i/2)},i/2))}else this.step(this.delta(d)),this.client&&this.client.invalidate?.()};this._unsub=jr.subscribe(l,{description:`animation: ${r}`,component:this.client,metadata:{duration:t,delay:e,repeat:n,interval:i}})}stop(t){this._unsub&&(this._unsub(),this._unsub=null),this._timeout&&clearTimeout(this._timeout),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 Aa{step(t){const{theta:e=6.28}=this.config;this.client.delta?.("theta",t*e)}},vibration:class extends Aa{step(t){const{theta:e=.2617993877991494}=this.config,n=4*e;let i=t*n;t<1/4?i*=-1:t<3/4?i-=2*e:i=n-i,this.client.delta?.("theta",i)}},heartbeat:class extends Aa{step(t){const{scale:e=1.3}=this.config,n=2*(e-1);let i;i=t<.5?1+n*t:1+(1-t)*n,this.client.delta?.({sx:i,sy:i,sz:i})}},moving:class extends Aa{step(t){const{x:e=0,y:n=0}=this.config;this.client.delta?.({tx:t*e,ty:t*n})}},outline:class extends Aa{step(t){const{rideOn:e}=this.config;if(!e||!this.client)return;const n=this.client.root.findById(e);if(!n)return;let i={tx:0,ty:0};const s=this.client.delta("");s&&"object"==typeof s&&"tx"in s&&"ty"in s&&(i=s);const{tx:r,ty:o}=i,a=n.outline(t),{x:c,y:l}=this.client.center,h=this.client.toScene(c,l);this.client.delta({tx:a.x-h.x+r,ty:a.y-h.y+o})}},fade:class extends Aa{step(t){const{startAlpha:e=1,endAlpha:n=0}=this.config,i=Math.max(Math.min(e,n,1),0),s=2*(Math.min(Math.max(e,n,1),1)-i);let r;r=t<.5?s*t:(1-t)*s,this.client.delta?.("fade",r)}},waypoint:class extends Aa{constructor(){super(...arguments),this._startX=0,this._startY=0,this._endX=0,this._endY=0}start(){let{toComponent:t,fromComponent:e}=this.config;e||(e=t);const n=e.center,i=t.center,{x:s,y:r}=e.toScene(n.x,n.y),{x:o,y:a}=t.toScene(i.x,i.y);this._startX=s,this._startY=r,this._endX=o,this._endY=a;const c=this.config.yawOffset??Math.PI/2,l=Math.atan2(a-r,o-s)+c;this.client.location={x:s,y:r},this.client.setState("rotation",l),super.start()}stop(t){const{toComponent:e,finalize:n="snap"}=this.config;if(super.stop(t),"snap"===n&&e){const t=e.center,n=e.toScene(t.x,t.y);this.client.delta({tx:0,ty:0}),this.client.location=n}}step(t){const e=(this._endX-this._startX)*t,n=(this._endY-this._startY)*t;this.client.location={x:this._startX+e,y:this._startY+n}}}};function Ca(t,e){const n=e.type?Ea[e.type]:void 0;return n?new n(t,e):null}const Ta={gradation:function(t,e,n){const{subType:i,from:s,to:r,colors:o}=n;let a;switch(i){case"linear":default:a=e.createLinearGradient(s.x,s.y,r.x,r.y);break;case"radial":a=e.createRadialGradient(s.x,s.y,s.r,r.x,r.y,r.r)}o&&(o.forEach(function(t){a.addColorStop(t.endPoint,t.color)}),e.fillStyle=a,e.fill())},shadow:Do};function Pa(t){return this._animate&&this._animate.stop(),this._animate=ka({component:this,...t}),this._animate}function Oa(t,e){return function(t,e,n){const i=Ta[n.type];i&&i(t,e,n)}(this,t,e)}const Da=100;function za(t,e){if(null!==e){if("number"==typeof e){if(!Number.isFinite(e))return;if(!Number.isInteger(e))return Math.round(e*Da)/Da}return e}}function Ia(t){if(null==t||"object"!=typeof t)return t;for(const e in t){const n=t[e];null===n?delete t[e]:"number"==typeof n?Number.isFinite(n)?Number.isInteger(n)||(t[e]=Math.round(n*Da)/Da):delete t[e]:"object"==typeof n&&Ia(n)}return t}function Ra(...t){return JSON.stringify(this.hierarchy,za,...t)}function ja(){delete this._model[""],"chartjs"!==this._model.type&&delete this._model.chart}function La(t){this.rootModel.closeScene(t)}function Fa(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 Na(){this.parent&&this.parent.invalidate()}function Ha(){const t=this.nature["value-property"]||"text";return"value"==t?this.getState("value"):this[t]}function Ba(t){const e=this.nature["value-property"]||"text";"value"==e?this.setState("value",t):this[e]=t}function Ga(){return this.getState("data")}function Va(t){this.setState("data",t),this.touch()}function Ya(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 Wa(){return!this._mappings&&this.parent&&this.buildMappings(),this._mappings}function Ua(){return Number(this.get("retention"))||0}function $a(){if(this.app.isViewMode&&!this.isTemplate()){if(!this._animation){const t=this.state.animation;t&&t.oncreate&&(this._animation=Ca(this,t.oncreate))}return this._animation}}function Xa(){return!!this.animation?.started}function qa(t){this.animation&&(this.animation.started=t)}function Ka(){}function Qa(t,e,n,i){const s=e.get("class");if(!s)return!1;return(s.split(" ")||[]).indexOf(t.substr(1))>=0}function Za(t,e,n,i){return t==e.get("type")}function Ja(t,e,n,i){if("(all)"==t)return!0;switch(t.charAt(0)){case"#":return function(t,e){return t.substring(1)==e.get("id")}(t,e);case".":return Qa(t,e);case"(":return function(t,e,n,i){switch(t){case"(all)":return!0;case"(self)":return i===e;case"(root)":return!i.parent&&i===e;case"(descendant)":return i!==e;case"(child)":return i===e.parent;default:return!1}}(t,e,0,i);default:return Za(t,e)}}function tc(t,e,n,i,s,r){return t(e,n,i,s)&&r.push(n),n.components&&n.components.forEach(n=>{tc(t,e,n,i,s,r)}),r}function ec(t,e,n,i){switch(t){case"(all)":return!0;case"(parent)":return n&&n.parent===e;case"(child)":case"(children)":return n&&n===e.parent;case"(sibling)":case"(siblings)":return n&&n.parent===e.parent&&n!==e;default:return!1}}function nc(t,e,n){if("(root)"==t)return[e];if("(self)"==t)return n?[n]:[];let i;switch(t.charAt(0)){case"#":const n=e.root.findAllById?.(t.substring(1));return n||[];case".":i=Qa;break;case"(":i=ec;break;default:i=Za}return tc(i,t,e,n,e,[])}function ic(t,...e){if(t(this,...e))return this}function sc(t,...e){return"string"==typeof t?nc(t,this,e[0]||this):"function"==typeof t&&t(this,...e)?[this]:void 0}function rc(t,e,n){if(!this.capturable||n?.(this))return!1;const i=this.fromParent(t,e);return this.contains(i.x,i.y)?this:void 0}function oc(t){return this.anchors.find(e=>e.name===t)}function ac(t){return!0}function cc(t){return this._parent.getContext(t??this)}function lc(){return this.isRoot()?this:this.parent&&this.parent.root}function hc(){return this.isRootModel()?this:this.parent&&this.parent.rootModel}function dc(){return this._parent}function uc(t){this._parent=t}function pc(){return this.nature.anchors||[]}function fc(){let t=this.position,e=this;for(;"static"===t&&e.parent;)e=e.parent,t=e.position;return"static"==t}function mc(){if(this.parent&&this.parent.layout.isStuck(this)||this.get("locked"))return!0;const t=this.app?.focusFilter;return!(!this.app?.isEditMode||!t||t(this))}function gc(){if(!1===this.get("capturable"))return!1;const t=this.app?.isEditMode;if(!t&&this.hidden)return!1;if(t){if(this.get("locked"))return!1;const t=this.app.focusFilter;if(t&&!t(this))return!1}return!0}function yc(){return this.app?.isViewMode&&this.isPositionable()?this.state.position??"static":"static"}function bc(){return this.app&&this.app.isViewMode&&this.state.origin||""}function _c(){const{offsetX:t=0,offsetY:e=0}=this.state;return{x:t,y:e}}function vc(){return!this._app&&this.parent&&(this._app=this.parent.app),this._app}const xc={},wc={mutable:!1,resizable:!0,rotatable:!0,properties:[],"value-property":"text"},Mc=[],Sc=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"]),kc={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0};let Ac=0;const Ec={};const Cc=new FinalizationRegistry(t=>{!function(t){Ac--;let e=Ec[t];e||(e=Ec[t]={up:0,down:0}),e.down++}(t)});class Tc{static get nature(){return wc}static register(t,e){if(!e)return xc[t];xc[t]=e}static types(){return Object.keys(xc)}static get residents(){return Ec}static get residentsCount(){return Ac}static registerDecorator(t,e){$r.registerDecorator(t,e)}constructor(t,e){if(this._readyInvoked=!1,this._app=e,this._model=t||{},this._model.event&&"object"==typeof this._model.event&&!Array.isArray(this._model.event)&&!Array.isArray(this._model.eventHandlers)){const t=Rs(this._model.event);t.length>0&&(this._model.eventHandlers=t)}this._state={},this._delta=ni(kc),e&&this.animation?.config&&(1==this.animation.config.autoplay||(this.animation.config.autoplay??!0))&&(this.animation.started=!0),this.clearCache(),Br.add(this),function(t){Ac++;let e=Ec[t];e||(e=Ec[t]={up:0,down:0}),e.up++}(this._model.type),Cc.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))}}invokeReady(){if(!this._readyInvoked)return this._readyInvoked=!0,this.ready()}touch(){this.updatedAt=performance.now(),Br.touch(this)}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=ni(kc))}dispose(){this.resetAnimation(),this.disposeMappings();const t=this.parent;t&&"function"==typeof t.removeItem&&-1!==t._items?.indexOf?.(this)&&t.removeItem(this),t?.removeComponent?.(this),delete this._text_substitutor,delete this._value_substitutor,this._disposed=!0,this._realObject&&(this._realObject.dispose(),this._realObject=void 0),this.retention&&Br.touch(),this.clearCache(),delete this._app}get nature(){return this.constructor.nature}get disposed(){return!!this._disposed}isLayer(){return!1}isGroup(){return!1}isContainer(){return!1}isLine(){return!1}isRoot(){return!1}isRootModel(){return!1}is3dish(){return!0}get is3dMode(){return!1}isIn3DSpace(){return!!this._realObject}isTemplate(){return!!this.get("templatePrefix")}isHTMLElement(){return!1}isConnectable(){return!1}isIdentifiable(){return!0}isPositionable(){return this.parent?.isRootModel()}replaceRefids(t){}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=this;return this._applyProps(this._model,t,{getBeforeVal:function(t){return n._model[t]},clearState:!0,sensitive:!1,beforeFillStyle:function(t,e){t.hasOwnProperty("retention")&&Br.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 refid(){return this.get("refid")}get hierarchy(){const t=ni(this._model);return this.volatile.forEach(e=>{delete t[e]}),Ia(t)}get volatile(){return Mc}_applyProps(t,e,n){const i={},s={};let r=!1;const o=ni(e),a=this;if(Object.getOwnPropertyNames(o).forEach(function(e){const c=n.getBeforeVal(e),l=o[e];!n.sensitive&&function(t,e){return Ie(t,e)}(c,l)||(s[e]=c,i[e]=l,t[e]=l,n.clearState&&delete a._state[e],r=!0)}),r){this._cachedState=null;Object.keys(i).some(t=>!Sc.has(t))&&this.clearCache(),i.hasOwnProperty("text")&&delete this._text_substitutor,n.beforeFillStyle&&n.beforeFillStyle(i,s),i.hasOwnProperty("fillStyle")&&this.onchangeFill(i,s),n.afterFillStyle&&n.afterFillStyle(i,s),i.hasOwnProperty("data")&&this.onchangeData(i,s),this.onchange&&this.onchange(i,s),this.trigger("change",i,s)}return this}contains(t,e){return oo.call(this,t,e)}move(t,...e){ao.call(this,t,...e)}symmetryX(t){co.call(this,t)}symmetryY(t){lo.call(this,t)}adjustResize(t,e,n){return ho.call(this,t,e,n)}adjustRotation(t,e){return uo.call(this,t,e)}outline(t){return po.call(this,t)}get bounds(){return fo.call(this)}set bounds(t){mo.call(this,t)}get center(){return go.call(this)}set center(t){yo.call(this,t)}get location(){return bo.call(this)}set location(t){_o.call(this,t)}get rotate(){return vo.call(this)}set rotate(t){xo.call(this,t)}get dimension(){return wo.call(this)}set dimension(t){Mo.call(this,t)}get path(){return So.call(this)}set path(t){ko.call(this,t)}get drawPath(){return Ao.call(this)}get rotatePoint(){return Eo.call(this)}get mutable(){return Co.call(this)}get resizable(){return To.call(this)}get rotatable(){return Po.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&&Io.call(this,t)}prerender(t){Ro.call(this,t)}render(t){jo.call(this,t)}postrender(t){Lo.call(this,t)}prepare(t,e){Fo.call(this,t,e)}prepareIf(t){No.call(this,t)}drawText(t){Ho.call(this,t)}drawStroke(t,e){Bo.call(this,t,e)}drawFill(t,e){Go.call(this,t,e)}get strokeStyle(){return Vo.call(this)}set strokeStyle(t){Yo.call(this,t)}get fillStyle(){return Wo.call(this)}set fillStyle(t){Uo.call(this,t)}get fontColor(){return $o.call(this)}set fontColor(t){Xo.call(this,t)}get rotation(){return qo.call(this)}set rotation(t){Ko.call(this,t)}get decorators(){return Qo.call(this)}get decotag(){return Zo.call(this)}get hidden(){return Jo.call(this)}set hidden(t){ta.call(this,t)}get tag(){return ea.call(this)}set tag(t){na.call(this,t)}get appendum(){return ia.call(this)}set appendum(t){sa.call(this,t)}defaultTextSubstitutor(){return ra.call(this)}textLines(t){return oa.call(this,t)}get font(){return aa.call(this)}get lineHeight(){return ca.call(this)}get textSubstitutor(){return la.call(this)}get text(){return ha.call(this)}set text(t){da.call(this,t)}get textBounds(){return ua.call(this)}get textRotation(){return pa.call(this)}get textHidden(){return fa.call(this)}set textHidden(t){ma.call(this,t)}get hasTextProperty(){return ga.call(this)}animate(t){return Pa.call(this,t)}effect(t,e){return Oa.call(this,t,e)}serialize(...t){return Ra.call(this,...t)}trim(){ja.call(this)}closeScene(t){La.call(this,t)}delta(t,e){return Fa.call(this,t,e)}invalidate(){Na.call(this)}get value(){return Ha.call(this)}set value(t){Ba.call(this,t)}get data(){return Ga.call(this)}set data(t){Va.call(this,t)}set tap(t){Ya.call(this,t)}get mappings(){return Wa.call(this)}get retention(){return Ua.call(this)}get animation(){return $a.call(this)}get started(){return Xa.call(this)}set started(t){qa.call(this,t)}get controls(){return Ka.call(this)}findFirst(t,...e){return ic.call(this,t,...e)}findAll(t,...e){return sc.call(this,t,...e)}capture(t,e,n){return rc.call(this,t,e,n)}findAnchor(t){return oc.call(this,t)}isDescendible(t){return ac.call(this,t)}getContext(t){return cc.call(this,t)}get root(){return lc.call(this)}get rootModel(){return hc.call(this)}get parent(){return dc.call(this)}set parent(t){uc.call(this,t)}get anchors(){return pc.call(this)}get scalable(){return fc.call(this)}get stuck(){return mc.call(this)}get capturable(){return gc.call(this)}get position(){return yc.call(this)}get origin(){return bc.call(this)}get offset(){return _c.call(this)}get app(){return vc.call(this)}drawEffect(t){Fs.call(this,t)}prepareFill(t,e){nr.call(this,t,e)}prepareFillIf(t){ir.call(this,t)}onchangeFill(t,e){sr.call(this,t,e)}drawImage(t,e,n,i,s,r){Ls.call(this,t,e,n,i,s,r)}mutateBounds(t,e){Dr.call(this,t,e)}mutatePath(t,e,n){zr.call(this,t,e,n)}access(t){return Yr.call(this,t)}substitute(t,e){return Wr.call(this,t,e)}onchangeMappings(t,e){Is.call(this,t,e)}onchangeData(t,e){Os.call(this,t,e)}buildMappings(){Ds.call(this)}executeMappings(t){Ps.call(this,t)}disposeMappings(){zs.call(this)}ondropfile(t,e){fr.call(this,t,e)}transcoordS2P(t,e,n){return _r.call(this,t,e,n)}transcoordP2S(t,e,n){return br.call(this,t,e,n)}transcoordS2T(t,e,n){return xr.call(this,t,e,n)}transcoordT2P(t,e,n){return wr.call(this,t,e,n)}transcoordT2S(t,e,n){return Mr.call(this,t,e,n)}transcoordS2TR(t,e,n){return vr.call(this,t,e,n)}transcoordS2O(t,e,n){return Sr.call(this,t,e,n)}transcoordC2S(t,e,n){return kr.call(this,t,e,n)}transcoordS2C(t,e,n){return Ar.call(this,t,e,n)}toParent(t,e,n){return _r.call(this,t,e,n)}fromParent(t,e,n){return br.call(this,t,e,n)}toScene(t,e,n){return xr.call(this,t,e,n)}fromScene(t,e,n){return Mr.call(this,t,e,n)}toLocal(t,e,n){return kr.call(this,t,e,n)}toGlobal(t,e,n){return Ar.call(this,t,e,n)}toOther(t,e,n){return Sr.call(this,t,e,n)}on(t,e,n){return Wi.call(this,t,e,n)}off(t,e,n){return Ui.call(this,t,e,n)}once(t,e,n){return $i.call(this,t,e,n)}trigger(t,...e){return Xi.call(this,t,...e)}delegate_on(t){return qi.call(this,t)}delegate_off(t){return Ki.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.capabilities=[],Tc.requires3d=!1,Tc.union=Er,Tc.transcoordR=gr,Tc.transcoordRR=yr,Tc.createCanvas=tr,Tc.memoize=es,Tc.mixin=Qi,Tc.drawText=ur,Tc.font=hr,Tc.textLines=lr,Tc.drawStroke=rr,Tc.drawFill=er,Tc.reposition=Or,Tc.RetentionManager=Br,Tc.template=function(t,e,n){var i=Mn.imports._.templateSettings||Mn;n&&qe(t,e,n)&&(e=void 0),t=vn(t),e=Qe({},e,i,hn);var s=Qe({},e.imports,i.imports,hn),r=de(s),o=function(t,e){return an(e,function(e){return t[e]})}(s,r);Re(r,function(t){if(En.test(t))throw new Error("Invalid `imports` option passed into `_.template`")});var a,c,l=0,h=e.interpolate||Tn,d="__p += '",u=RegExp((e.escape||Tn).source+"|"+h.source+"|"+(h===pn?Cn:Tn).source+"|"+(e.evaluate||Tn).source+"|$","g"),p=On.call(e,"sourceURL")?"//# sourceURL="+(e.sourceURL+"").replace(/\s/g," ")+"\n":"";t.replace(u,function(e,n,i,s,r,o){return i||(i=s),d+=t.slice(l,o).replace(Pn,un),n&&(a=!0,d+="' +\n__e("+n+") +\n'"),r&&(c=!0,d+="';\n"+r+";\n__p += '"),i&&(d+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),l=o+e.length,e}),d+="';\n";var f=On.call(e,"variable")&&e.variable;if(f){if(En.test(f))throw new Error("Invalid `variable` option passed into `_.template`")}else d="with (obj) {\n"+d+"\n}\n";d=(c?d.replace(Sn,""):d).replace(kn,"$1").replace(An,"$1;"),d="function("+(f||"obj")+") {\n"+(f?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(a?", __e = _.escape":"")+(c?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+d+"return __p\n}";var m=on(function(){return Function(r,p+"return "+d).apply(void 0,o)});if(m.source=d,rn(m))throw m;return m},Tc.buildSubstitutor=Ur,["rotatePoint","font","lineHeight","retention"].forEach(t=>Tc.memoize(Tc.prototype,t,!1)),["bounds","center","textBounds"].forEach(t=>Tc.memoize(Tc.prototype,t,!0));class Pc 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 i=0;i<e.length;i++){const s=e[(i-1+e.length)%e.length],r=e[(i+e.length)%e.length],o=e[(i+1)%e.length];if(s.x===r.x&&s.y===r.y)continue;const a=to(r,n);let c=Math.sqrt((s.x-r.x)*(s.x-r.x)+(s.y-r.y)*(s.y-r.y)),l=0!==c?Math.atan2(s.x-r.x,s.y-r.y):0,h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;const u=a>0||0!==c?{x:h,y:d}:r;c=Math.sqrt((o.x-r.x)*(o.x-r.x)+(o.y-r.y)*(o.y-r.y)),l=0!==c?Math.atan2(o.x-r.x,o.y-r.y):0,h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;const p=a>0||0!==c?{x:h,y:d}:r;if(0==i?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y),a>0&&t.quadraticCurveTo(r.x,r.y,p.x,p.y),Kr(r)){const e=to(o,n),i=Math.sqrt((r.x-o.x)**2+(r.y-o.y)**2),s=0!==i?Math.atan2(r.x-o.x,r.y-o.y):0,a=Math.sin(s)*Math.min(e,i/2)+o.x,c=Math.cos(s)*Math.min(e,i/2)+o.y,l=Qr({x:p.x,y:p.y},{x:a,y:c},r.bulge);l&&t.arc(l.cx,l.cy,l.radius,l.startAngle,l.endAngle,l.clockwise)}}t.closePath()}}}function Oc(t,e,n){return Math.max(0,Math.min(t,Math.min(n,e)/2))}function Dc(t){const e=class extends t{contains(t,e){const{left:n,top:i,width:s,height:r,lineWidth:o=0}=this.state,a=o/2;return t<Math.max(n+s,n)+a&&t>Math.min(n+s,n)-a&&e<Math.max(i+r,i)+a&&e>Math.min(i+r,i)-a}set path(t){const e=t[0],n=t[2];this.set({left:e.x,top:e.y,width:n.x-e.x,height:n.y-e.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get anchors(){return function(t){const{left:e,top:n,width:i,height:s}=t.bounds,r=e+i/2,o=n+s/2;return[{name:"TOP",position:{x:r,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:r,y:n+s}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){this.set({left:0,top:0,width:0,height:0,...t})}render(t){let{round:e=0}=this.model;const{left:n,top:i,width:s,height:r}=this.bounds;t.translate(n,i),t.beginPath(),e=Oc(e,s,r),e>0?t.roundRect(0,0,s,r,e):t.rect(0,0,s,r),t.translate(-n,-i)}};return es(e.prototype,"path",!1),es(e.prototype,"bounds",!0),e}const zc={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 Ic=20;function Rc(t,e){const n=t.split(/\s+/),i=n.indexOf(e);return-1!=i?n.splice(i,1):n.splice(-1,0,e),n.join(" ")}class jc extends(Dc(Pc)){static get image(){return jc._image||(jc._image=new Image,jc._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=="),jc._image}static toggle(t,e,n,i){if(!e)return void Ji("InfoWindow not defined.");const s=t.root.findById(e);s?s._findInfoWindowByComponent(t)?jc.hide(t,e):jc.show(t,e,n,i):Ji("InfoWindow Not Found.",e)}static hide(t,e){if(!e)return;const n=t.root.findById(e);n?n._removeInfoWindow(t):Ji("InfoWindow Not Found.",e)}static show(e,n,i,s){if(!n)return void Ji("InfoWindow not defined.");const r=e.root.findById(n);if(!r)return void Ji("InfoWindow Not Found.",n);if(r._findInfoWindowByComponent(e))return;const{frontSideTemplate:o="",backSideTemplate:a=""}=r.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">&#88</button>':"",n?'<button class="flipable">&#8652</button>':"","</div>"]:[]).concat(['<div class="info-window-content">',t,"</div>"]).join("")}(t,!i,2==c.length))),0==c.length)return;const l='\n.flip {\n backface-visibility: hidden;\n border-radius: 7px;\n height: auto;\n font: normal 14px helvetica, arial, san serif;\n position: absolute;\n opacity: 0.9;\n transform-origin: 50% 50% 0px;\n transition: all 2s;\n min-width: 100px;\n min-height: 50px;\n background-color: #3e424e;\n box-shadow: 2px 3px 2px 0px rgba(0,0,0,0.15);\n}\n\n#side-1 {\n transform: rotateY(0deg);\n}\n\n.flip:after {\n content: "";\n display: block;\n position: absolute;\n opacity: 0.9;\n width: 0;\n height: 0;\n}\n\n.flip.arrow-top:after {\n left: 45%;\n top: -17px;\n border-left: 10px solid transparent;\n border-bottom: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-right:after {\n left: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-left: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n.flip.arrow-bottom:after {\n left: 45%;\n top: 100%;\n border-left: 10px solid transparent;\n border-top: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-left:after {\n right: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-right: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n#side-2 {\n transform: rotateY(180deg);\n}\n\n.flip-side-1 {\n transform: rotateY(0deg) !important;\n}\n\n.flip-side-2 {\n transform: rotateY(180deg) !important;\n}\n\n.info-window-btns {\n position: absolute;\n top: -18px;\n right: 5px;\n overflow: hidden;\n}\n\n.info-window-content {\n padding: 10px;\n color: #efefef;\n font-size: 13px;\n line-height: 1.4;\n}\n\n.info-window-btns button {\n width: 40px;\n height: 40px;\n float: right;\n border: 0;\n border-radius: 50%;\n background-color: #2a7da1;\n margin-right: 3px;\n text-align: center;\n cursor: pointer;\n font-size: 35px;\n color: #fff;\n line-height: 0;\n}\n\n.info-window-btns button:hover {\n background-color: #60bb23;\n}\n'+r.get("style");let{left:h,top:d}=e.bounds;const{x:u,y:p}=s?e.rootModel.toLocal(s.x,s.y):e.toScene(h,d);h=u,d=p;const f=document.createElement("span");f.style.position="absolute";const m=document.createElement("style");let g,y;m.type="text/css",m.appendChild(document.createTextNode(l)),f.appendChild(m),c[0]&&(g=document.createElement("div"),g.id="side-1",g.className="flip",g.style.display="inline-block",g.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);g&&f.appendChild(g),y&&f.appendChild(y),b.appendChild(f);const _=r._addInfoWindow(e,f,m).signal;if(qs.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),Ks.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),g){const t=g.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=Rc(y.className,"flip-side-1"),g.className=Rc(g.className,"flip-side-2")},{signal:_});const i=g.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),jc.hide(e,n)},{signal:_})}if(y){const t=y.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=Rc(y.className,"flip-side-1"),g.className=Rc(g.className,"flip-side-2")},{signal:_});const i=y.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),jc.hide(e,n)},{signal:_})}const v=g.offsetWidth,x=g.offsetHeight,w=e.rootModel.target.getBoundingClientRect(),M=[];g&&M.push(g),y&&M.push(y);const S={x:h,y:d};let k=e.toGlobal(S.x,S.y);if(k.x+v/2+w.left<w.right&&k.x-v/2>w.left){if(x+Ic<k.y)return f.style.marginLeft=S.x-v/2+"px",f.style.marginTop=S.y-x-Ic+"px",void M.forEach(t=>t.className+=" arrow-bottom");if(k=e.toGlobal(S.x,S.y+x+Ic),w.bottom>k.y+w.top)return f.style.marginLeft=S.x-v/2+"px",f.style.marginTop=S.y+Ic+"px",void M.forEach(t=>t.className+=" arrow-top")}if(k=e.toGlobal(S.x,S.y),k.x-(v+Ic)>w.left)return f.style.marginLeft=S.x-v-Ic+"px",f.style.marginTop=S.y-x/2+"px",void M.forEach(t=>t.className+=" arrow-right");f.style.marginLeft=S.x+Ic+"px",f.style.marginTop=S.y-x/2+"px",M.forEach(t=>t.className+=" arrow-left")}dispose(){this.infoWindows.map(t=>t.component).forEach(t=>this._removeInfoWindow(t)),super.dispose()}get infoWindows(){return this._windows||(this._windows=[]),this._windows}_findInfoWindowByComponent(t){return this.infoWindows.find(e=>e.component===t)}_addInfoWindow(t,e,n){if(this._findInfoWindowByComponent(t))return;const i=new AbortController;return this._windows.push({component:t,window:e,styleElement:n,abortController:i}),i}_removeInfoWindow(t){const e=this._findInfoWindowByComponent(t);if(!e)return;e.abortController.abort();const n=e.window;n&&n.parentNode.removeChild(n);const i=this.infoWindows.lastIndexOf(e);this.infoWindows.splice(i,1)}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,jc.image,e,n,i,s)}get hasTextProperty(){return!1}get nature(){return zc}}Tc.register("info-window",jc);const Lc={};var Fc={list:function(){return{...Lc}},register:function(t,e){Lc[t]=e},unregister:function(t){delete Lc[t]},get:function(t){if(!t)return;const e=Lc[t];return e||Zi("Layout Not Found - ",t),e}};const Nc=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}};Fc.register("html-absolute",Nc);const Hc=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 Bc(t){const e=t.components.filter(t=>!t.hidden),n=t.getState("layoutConfig")||{},i=e[n&&n.activeIndex||0];return i&&[i]||[]}Fc.register("absolute",Hc);const Gc=new class{reflow(t){const e=t.bounds,n=t.getState("layoutConfig")||{},i={left:0,top:0,width:e.width,height:e.height};t.forEach((t,e)=>{const s=e!=(n.activeIndex||0);t.bounds=i,t.setState("rotation",0),"element"in t&&t.element&&(t.element.style.visibility=s?"hidden":"visible")})}capturables(t){return Bc(t)}drawables(t){return Bc(t)}isStuck(t){return!0}};function Vc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}Fc.register("card",Gc);const Yc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+Vc(e),0),s=t.bounds,r=i>0?(s.width-((n.left||0)+(n.right||0)))/i:s.width,o=s.height-((n.top||0)+(n.bottom||0));let a=0;e.forEach(t=>{const e=Vc(t),i=t.getState("margin")||{};t.bounds={left:r*a+(n.left||0)+(i.left||0),top:0+(n.top||0)+(i.top||0),width:e*r-((i.left||0)+(i.right||0)),height:o-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};function Wc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}Fc.register("linear-horizontal",Yc);const Uc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+Wc(e),0),s=t.bounds,r=i>0?(s.height-((n.top||0)+(n.bottom||0)))/i:s.height,o=s.width-((n.left||0)+(n.right||0));let a=0;e.forEach(t=>{const e=Wc(t),i=t.getState("margin")||{};t.bounds={left:0+(n.left||0)+(i.left||0),top:r*a+(n.top||0)+(i.top||0),width:o-((i.left||0)+(i.right||0)),height:e*r-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};Fc.register("linear-vertical",Uc);const $c=new class{constructor(){this.joinType=!0}reflow(t){const e=t.getState("layoutConfig"),n=e&&e.columns||t.getState("columns"),i=e&&e.rows||t.getState("rows"),s=e&&e.widths||t.getState("widths"),r=e&&e.heights||t.getState("heights"),o=s?s.filter((t,e)=>e<n).reduce((t,e)=>t+e,0):n,a=r?r.filter((t,e)=>e<i).reduce((t,e)=>t+e,0):i,c=t.textBounds,l=t.getState("paddingLeft")||0,h=t.getState("paddingTop")||0,d=c.width/o,u=c.height/a;let p=0,f=0;t.components.forEach((t,e)=>{const i=s?s[e%n]:1,o=r?r[Math.floor(e/n)]:1;let a=t.colspan||1,c=0;for(;--a>0;)c+=s?s[(e+a)%n]:1;let m=t.rowspan||1,g=0;for(;--m>0;)g+=r?r[Math.floor(e/n)+m]:1;t.bounds={left:l+p,top:h+f,width:d*(i+c),height:u*(o+g)},t.setState("rotation",0),e%n==n-1?(p=0,f+=o*u):p+=i*d})}capturables(t){return t.components.filter(t=>!t.merged)}drawables(t){return t.components.filter(t=>!t.merged&&!t.hidden)}isStuck(t){return!0}keyNavigate(t,e,n){const i=t.getState("layoutConfig"),s=i&&i.columns||t.getState("columns"),r=i&&i.rows||t.getState("rows"),{row:o,column:a}=t.getRowColumn(e);switch(n.code){case"ArrowUp":if(o>0)return t.getAt?.((o-1)*s+a);break;case"ArrowDown":if(o<r-1)return t.getAt?.((o+1)*s+a);break;case"ArrowRight":if(a<s-1)return t.getAt?.(o*s+a+1);break;case"ArrowLeft":if(a>0)return t.getAt?.(o*s+a-1);break;default:return e}}};function Xc(){const t=arguments,e=t[t.length-1],n=this.event_pump;n.listeners.forEach(i=>{!function(t,e,n,i,s){for(const r in n){const o=n[r];if(Ja(r,i.origin,0,t))for(const t in o){const n=o[t];t==i.name&&(i.listener=e,n.apply(e,s))}}}(n.deliverer,i.listener,i.cloned_handlers,e,t)})}Fc.register("table",$c);class qc{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)",Xc,{event_pump:this})}stop(){this.deliverer.off("(all)",Xc)}on(t,e){const n=Object.assign({},e);Object.keys(n).forEach(e=>{if(0==e.indexOf("?")){const i=n[e],s=e.substr(1),r=t.get(s);delete n[e],r?n[r]=i:Ji("EventPump#on","variable #{selector} is not evaluated on listener")}}),this.listeners.push({listener:t,handlers:e,cloned_handlers:n})}off(t,e){for(let n=0;n<this.listeners.length;n++){const i=this.listeners[n];i.listener!==t||e&&i.handlers!==e||this.listeners.splice(n,1)}}clear(){this.listeners=[]}dispose(){this.stop(),this.clear()}}class Kc{constructor(t){this.eventMaps=[],this.root=t,t.eventMap&&this.add(t,t.eventMap)}set root(t){this._root=t}get root(){return this._root}stop(){this.eventMaps.forEach(t=>t.eventPump.stop())}add(t,e){if(this.root)for(const n in e){const i=e[n];if("(self)"===n&&void 0===t.on)throw new Error("(self) selector not available when deliverer is not a event handlable object.");nc(n,this.root,t).forEach(n=>{const s=new qc(n);s.on(t,i),s.start(),this.eventMaps.push({eventPump:s,listener:t,handlerMap:e,deliverer:n})})}}remove(t,e){const n=this.eventMaps.slice(0);for(let i=0;i<n.length;i++){const s=n[i];s.listener!==t||e&&s.handlerMap!==e||(this.eventMaps.splice(i,1),s.eventPump.dispose())}}clear(){this.eventMaps.slice(0).forEach(t=>t.eventPump.dispose()),this.eventMaps=[]}dispose(){this.stop(),this.clear()}}const Qc=0,Zc=1,Jc=2,tl=0,el=1,nl=2;let il={},sl=0;class rl{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 il;const n=e.target.getBoundingClientRect();return il={x:t.offsetX||e.clientX-n.left,y:t.offsetY||e.clientY-n.top},il}return{x:t.offsetX,y:t.offsetY}}(t);if(this._offsetX=n.x,this._offsetY=n.y,t.touches&&t.touches[0]?(this._clientX=t.touches[0].clientX,this._clientY=t.touches[0].clientY):(this._clientX=t.clientX,this._clientY=t.clientY),"wheel"==t.type)this.deltaX=t.deltaX,this.deltaY=t.deltaY,this.deltaZ=t.deltaZ;else if("drop"==t.type)this.dataTransfer=t.dataTransfer;else if(t.type.match(/^touch/)&&(this._scale=t.scale,this._touches=t.touches,this._changedTouches=t.changedTouches,null==this._scale)){const e=function(t){let e,n,i=0,s=0,r=0;if(1===t.touches.length)return r;Array.from(t.touches).forEach(t=>{e=null!=e?Math.min(t.screenX,e):t.screenX,i=Math.max(t.screenX,i),n=null!=n?Math.min(t.screenY,n):t.screenY,s=Math.max(t.screenY,s)});const o=i-e||0,a=s-n||0;return r=Math.sqrt(Math.pow(o,2)+Math.pow(a,2))||0,r}(t);sl>0&&(this._scale=e/sl),sl=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 ol(t,e,n){if(!t||!t.app)return;if(t.app.isViewMode&&t.hidden)return;n instanceof rl&&e===n.type||(n=new rl(n,e));const i="on"+e;t[i]&&t[i](n),n.isPropagationStopped()||t.trigger(e,n)}class al{constructor(t,e){this.gestureHandlerBuilder=t=>{const e=this[`on${t}`];return t=>{const n=new rl(t),i=this.getChildScrollOffset();return n._offsetX+=this.html_element.scrollLeft+i.scrollLeft,n._offsetY+=this.html_element.scrollTop+i.scrollTop,e(n),n.isDefaultPrevented()&&t.preventDefault(),!1}},this.keyeventHandlerBuilder=t=>this[`on${t}`],this.ondragover=t=>(ol(this.findTarget(t),t.type,t),!1),this.ondrop=t=>(ol(this.findTarget(t),t.type,t),!1),this.ondblclick=t=>(ol(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 Zc:const e=t.offsetX-this.__dragstart_e.offsetX,n=t.offsetY-this.__dragstart_e.offsetY;if(e*e+n*n<16)break;this.status=Jc,ol(this.last_target,"dragstart",this.__dragstart_e),this.__dragmove_e=t,ol(this.last_target,"dragmove",t);break;case Jc:this.__dragmove_e=t,ol(this.last_target,"dragmove",t);break;default:{const e=this.findTarget(t);this.last_enter_target!==e&&(this.last_enter_target&&ol(this.last_enter_target,"mouseleave",t),e&&ol(e,"mouseenter",t),this.last_enter_target=e),ol(e,t.type,t),this.last_target=e}}return!1},this.onmousedown=t=>{if(this.status===Jc)ol(this.last_target,"dragend",t),this.last_target=null,this.status=Qc;else{const e=this.findTarget(t);this.last_target=e,this.status=Zc,this.__dragstart_e=t,ol(e,t.type,t)}return!1},this.onmouseup=t=>{if(this.status===Jc)ol(this.last_target,"dragend",t);else{const e=this.findTarget(t);ol(e,t.type,t),this.last_target===e&&ol(e,"click",t)}return this.last_target=null,this.status=Qc,!1},this.onmouseout=t=>{const e=this.findTarget(t);if(this.status===Jc)ol(this.last_target,"dragend",t);else{if(this.last_target&&this.last_target===e)return;this.last_enter_target&&(ol(this.last_enter_target,"mouseleave",t),delete this.last_enter_target)}return this.last_target=null,this.status=Qc,!1},this.ontouchstart=t=>{const e=this.findTarget(t);return this.last_target=e,this.status=el,this.touchPoints||(this.touchPoints=[]),this.touchPoints.push(t.changedTouches[0]),this.holdTimer=setTimeout(()=>{this.status=tl,ol(this.last_target,"hold",t),delete this.holdTimer},500),ol(e,t.type,t),!1},this.ontouchmove=t=>{if(!t.touches||!t.changedTouches)return ol(this.last_target,"dragstart",t),ol(this.last_target,"dragmove",t),!1;let e=this.findTarget(t);switch(this.status){case el:Array.from(t.changedTouches).forEach(t=>{const e=this.touchPoints.find(e=>e.identifier===t.identifier);if(!e)return;const n=e.clientX-t.clientX,i=e.clientY-t.clientY;return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))>=16?(this.status=nl,void(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer))):void 0});break;case nl: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 ol(this.last_target,"pinch",t),!1;ol(this.last_target,"pan",t),e=this.last_target;break;default:this.last_enter_target!==e&&(this.last_enter_target&&ol(this.last_enter_target,"mouseleave",t),e&&ol(e,"mouseenter",t),this.last_enter_target=e),this.last_target=e}return ol(e,"touchmove",t),!1},this.ontouchend=t=>{let e=this.findTarget(t);switch(this.status){case nl:e=this.last_target;break;case el:{const n=performance.now(),i=n-this.touchedAt;this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer,ol(e,i<500?"doubletap":"tap",t),this.touchedAt=n);break}}ol(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=tl,!1},this.onwheel=t=>(ol(this.findTarget(t),t.type,t),!1),this.container=t,this.html_element=e,this.status=Qc,this.last_target=null,this.gesture_handlers=qs.map(t=>this.gestureHandlerBuilder(t)),this.keyevent_handlers=Ks.map(t=>this.keyeventHandlerBuilder(t)),qs.forEach((t,n)=>e.addEventListener(t,this.gesture_handlers[n]),{passive:!1}),Ks.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&&ol(this.last_enter_target,"mouseleave",new CustomEvent("mouseleave")),qs.forEach((t,e)=>this.html_element.removeEventListener(t,this.gesture_handlers[e])),Ks.forEach((t,e)=>this.html_element.removeEventListener(t,this.keyevent_handlers[e])),delete this.gesture_handlers,delete this.keyevent_handlers,delete this.last_target}getChildScrollOffset(){for(const t of this.html_element.children)if(t.scrollTop>0||t.scrollLeft>0)return{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop};return{scrollLeft:0,scrollTop:0}}findTarget(t){const e=this.container.rootModel;if(e?.is3dMode)return e;const n=this.html_element.getBoundingClientRect(),i=this.getChildScrollOffset(),s=t.clientX-n.left+this.html_element.scrollLeft+i.scrollLeft,r=t.clientY-n.top+this.html_element.scrollTop+i.scrollTop;return this.container.capture(s,r)}}class cl{constructor(t){this.params=Object.assign({},t)}excute(){}}class ll extends cl{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)}}function hl(t,e,n,i=0){if(e.length<2)return e;let s=2;for(;s<e.length;s++){const r=e.substring(0,s);if(!(t.measureText(r).width+(r.length-1)*i<n))break}return e.substring(0,s-1)}function dl(t,e,n,i,s=0){const r=String(e).split("\n");return i?[].concat.apply([],r.map(e=>function(t,e,n,i=0){const s=e.split(" "),r=[];let o,a,c=[];for(o=0,a=1;a<=s.length;a++)if(c=s.slice(o,a),t.measureText(c.join(" ")).width+(c.join("").length-1)*i>n){if(a-o==1){const e=hl(t,c[0],n,i);r.push([e]),s.splice(o,1,e,c[0].substring(e.length))}else{for(;""==s[a-1];)a++;r.push(s.slice(o,--a))}o=a}return a-o>1&&r.push(c),0==r.length&&r.push([""]),r}(t,e,n,s))):r.map(t=>t.split(" "))}const ul={},pl={},fl=()=>{};var ml={register:function(t,e,n){ul[t]=e,n&&(pl[t]=n)},unregister:function(t){delete ul[t],delete pl[t]},get:function(t){return ul[t]},getDisposer:function(t){return pl[t]||fl}};function gl(t){if(!t.hasTextProperty||t.textHidden)return;let{text:e="",bold:n=Qs.BOLD,italic:i=Qs.ITALIC,textWrap:s=Qs.TEXT_WRAP,letterSpacing:r=0,fontFamily:o=Qs.FONT_FAMILY,fontColor:a=Qs.FONT_COLOR,textAlign:c=Qs.TEXT_ALIGN,textBaseline:l=Qs.TEXT_BASELINE,fontSize:h=Qs.FONT_SIZE,lineHeight:d=1.2*h}=t.model;const{left:u,top:p,width:f,height:m}=t.textBounds;h||=Qs.FONT_SIZE,d||=1.2*h,t.textHidden=!0;const g=document.createElement("textarea"),y=new AbortController;qs.forEach(function(t){g.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:y.signal})});const b=t.toGlobal(u,p),{rotation:_,scale:v}=function(t){let e=0,n=1,i=t;for(;i;){e+=i.get("rotation")||0;const{x:t,y:s}=i.get("scale")||{x:1,y:1};n*=Math.max(t,s)||1,i=i.parent}return{rotation:e,scale:n}}(t);g.value=e;const x={position:"absolute",width:f+"px",height:m+"px",padding:"0",fontFamily:o,fontSize:h+"px",lineHeight:d+"px",overflow:"hidden",resize:"none",outline:"none",border:"0",backgroundColor:"transparent",display:"inline-block",color:a};switch(n&&(x.fontWeight="bold"),i&&(x.fontStyle="italic"),c){case"right":case"end":x.textAlign="right";break;case"justify":x.textAlign="justify";break;case"left":case"start":x.textAlign="left";break;default:x.textAlign="center"}const w=[n,i,h+"px",o].filter(Boolean).join(" ");function M(e){const n={left:0,top:0},i=d*function(t,e,n,i,s=0){const r=t.getContext();let o;return r.save(),r.font=n,o=dl(r,e,i,t.get("textWrap"),s).length,r.restore(),o}(t,e,w,f,r);switch(x.height=i+"px",l){case"top":case"hanging":break;case"bottom":case"alphabetic":n.top=m-i;break;default:n.top=m/2-i/2}if(!s){const i=function(t,e,n,i){const s=e.split("\n");let r=i;const o=t.getContext();return o.save(),o.font=n,s.forEach(t=>{const e=o.measureText(t).width;e>r&&(r=e)}),o.restore(),r}(t,e,w,f);switch(x.width=i+"px",c){case"right":case"end":n.left=f-i;break;case"left":case"start":break;default:n.left=(f-i)/2}}x.marginLeft=n.left+"px",x.marginTop=n.top+"px",x.transform=`translate(${b.x}px, ${b.y}px) scale(${v}) rotate(${_}rad)`,x.transformOrigin=`${-n.left}px ${-n.top}px`,Object.assign(g.style,x)}M(e);const S=t.root.target_element;S.appendChild(g),g.select();let k,A=!1;g.addEventListener("keydown",function(t){t.stopPropagation(),"Escape"!=t.code&&(t.shiftKey||"Enter"!=t.code&&"NumpadEnter"!=t.code)?setTimeout(()=>{M(g.value)}):(A=k.skipUpdate="Escape"==t.code,"function"==typeof document.createEvent?g.dispatchEvent(k):g.fireEvent(k.eventType,k))},{signal:y.signal}),document.createEvent?(k=document.createEvent("HTMLEvents"),k.initEvent("blur",!0,!1)):(k=document.createEventObject(),k.eventType="blur");const E=t.root.selected,C=function(n){t.root.selected=E,t.textHidden=!1,y.abort(),g.removeEventListener("blur",C,!1),g.parentElement&&g.parentElement.removeChild(g),S.focus(),n.skipUpdate||A||t.app.commander.execute(new ll({changes:[{component:t,before:{text:e},after:{text:g.value}}]}))};g.addEventListener("blur",C,!1)}ml.register("text-editor",{"(root)":{"(self)":{keydown:function(t,e){const{deliverer:n}=e,i=n.selected;return!(1!==i.length||!i[0].hasTextProperty)&&(("Enter"==t.code||"NumpadEnter"==t.code)&&(gl(i[0]),t.preventDefault(),!0))}}},"model-layer":{"(descendant)":{dblclick:function(t,e){gl(e.origin)}}}});const yl=new e.Vector3,bl=new e.Quaternion,_l=new e.Matrix4,vl=new e.Vector3;class xl{constructor(t,n){t instanceof e.Vector3?this.position=t.clone():this.position=t?new e.Vector3(t.x,t.y,t.z):new e.Vector3,n instanceof e.Quaternion?this.rotation=n.clone():this.rotation=n?new e.Quaternion(n.x,n.y,n.z,n.w):new e.Quaternion}compose(t){const e=yl.copy(t.position).applyQuaternion(this.rotation).add(this.position),n=bl.copy(this.rotation).multiply(t.rotation);return new xl(e,n)}inverse(){const t=bl.copy(this.rotation).invert(),e=yl.copy(this.position).applyQuaternion(t).negate();return new xl(e,t)}transformPoint(t){return t.clone().applyQuaternion(this.rotation).add(this.position)}transformPose(t){return this.compose(t)}toMatrix4(t){const n=t??new e.Matrix4;return n.compose(this.position,this.rotation,vl.set(1,1,1)),n}static fromMatrix4(t){const n=new e.Vector3,i=new e.Quaternion,s=new e.Vector3;return t.decompose(n,i,s),new xl(n,i)}static fromObject3D(t,n=!1){if(n){const n=new e.Vector3,i=new e.Quaternion,s=new e.Vector3;return _l.copy(t.matrixWorld).decompose(n,i,s),new xl(n,i)}return new xl(t.position,t.quaternion)}applyToObject3D(t){t.position.copy(this.position),t.quaternion.copy(this.rotation)}static identity(){return new xl}equals(t,e=1e-9){if(Math.abs(this.position.x-t.position.x)>e)return!1;if(Math.abs(this.position.y-t.position.y)>e)return!1;if(Math.abs(this.position.z-t.position.z)>e)return!1;const n=this.rotation.x*t.rotation.x+this.rotation.y*t.rotation.y+this.rotation.z*t.rotation.z+this.rotation.w*t.rotation.w;return 1-Math.abs(n)<e}clone(){return new xl(this.position,this.rotation)}toJSON(){return{position:{x:this.position.x,y:this.position.y,z:this.position.z},rotation:{x:this.rotation.x,y:this.rotation.y,z:this.rotation.z,w:this.rotation.w}}}static fromJSON(t){return new xl(t.position,t.rotation)}}const wl=new e.Euler,Ml=new e.Vector3,Sl=new e.Quaternion,kl=new e.Vector3;function Al(t){const n=t._realObject;if(n?.position&&n?.rotation){const t=n.position,i=n.rotation,s=(new e.Quaternion).setFromEuler(wl.set(i.x,i.y,i.z,"XYZ"));return new xl(new e.Vector3(t.x,t.y,t.z),s)}const i=t.center??{x:0,y:0},s=t.parent?.bounds??{width:0,height:0},r=("function"==typeof t.delta?t.delta():null)??{tx:0,ty:0},o=t.state??{},a=(i.x??0)+(r.tx??0)-(s.width??0)/2,c=(i.y??0)+(r.ty??0)-(s.height??0)/2,l=o.rotation??0,h=o.rotationX??0,d=o.rotationY??0,u=(new e.Quaternion).setFromEuler(wl.set(h,-l,d,"XYZ"));return new xl(new e.Vector3(a,0,c),u)}function El(t){const e=t._realObject?.object3d;if(e)return e.updateWorldMatrix(!0,!1),e.matrixWorld.decompose(Ml,Sl,kl),new xl(Ml,Sl);let n=Al(t),i=t.parent;for(;i&&!i.isRootModel?.();)n=Al(i).compose(n),i=i.parent;return n}function Cl(t,e){const n=t.parent?.bounds??{width:0,height:0},i=("function"==typeof t.delta?t.delta():null)??{tx:0,ty:0,tz:0},s=t._realObject,r=e.position.x-(i.tx??0)+(n.width??0)/2,o=e.position.z-(i.ty??0)+(n.height??0)/2,a=t.bounds??{width:0,height:0},c={left:r-a.width/2,top:o-a.height/2};if(s){const n=s.syncZPosOffset??0,r=t.parent?._realObject,o=r?.geometricOffsetY??0,a=r?.receivingSurfaceY??0;c.zPos=e.position.y-(i.tz??0)-n+o-a}wl.setFromQuaternion(e.rotation,"XYZ"),c.rotationX=wl.x,c.rotation=-wl.y,c.rotationY=wl.z,"function"==typeof t.setState?t.setState(c):"function"==typeof t.set&&t.set(c)}function Tl(t,e){const n=t.parent;if(!n||n.isRootModel?.())return void Cl(t,e);Cl(t,El(n).inverse().compose(e))}function Pl(t){let e=0;for(;t&&!t.isRootModel();)e+=t.get("rotation")||0,t=t.parent;return e%(2*Math.PI)}class Ol extends cl{execute(){this.params.changes.forEach(t=>{const{component:e,to_container:n,to_index:i,to_left:s,to_top:r}=t,o=function(t){if(t.isRootModel())return t.bounds;const{bounds:e,rotatePoint:n}=t;let i=n;return i=t.toScene(i.x,i.y),{left:i.x-(n.x-e.left),top:i.y-(n.y-e.top),width:e.width,height:e.height}}(e),a=Pl(e),c=e._realObject?El(e):null;if(e.removeSelf(!n),e.bounds=o,e.set("rotation",a),n){e.set("rotation",function(t,e){return((t.get("rotation")||0)-Pl(e))%(2*Math.PI)}(e,n));const o=function(t,e){if(e.isRootModel())return t.bounds;const{bounds:n,rotatePoint:i}=t,s=e.fromScene(i.x,i.y),r=e.bounds;return{left:s.x-(i.x-n.left)-r.left,top:s.y-(i.y-n.top)-r.top,width:n.width,height:n.height}}(e,n);t.to_left=void 0!==s?s:o.left,t.to_top=void 0!==r?r:o.top,e.bounds={left:t.to_left,top:t.to_top,width:o.width,height:o.height},void 0===i?n.addComponent(e):n.insertComponentAt(e,i),function(t,e,n){const i=t._realObject;if(!i||!n)return;const s=El(e).inverse().compose(n),r=e?._realObject,o=r?.geometricOffsetY??0,a=r?.receivingSurfaceY??0,c=("function"==typeof t.delta?t.delta()?.tz:0)??0,l=i.syncZPosOffset??0;t.set("zPos",s.position.y-c-l+o-a)}(e,n,c)}})}}class Dl{constructor(t){const e=[],n=[];for(let i=0,s=t.length;i<s;i++){const s=t[i],r=s.left,o=s.left+s.width,a=r+s.width/2,c=s.top,l=s.top+s.height,h=c+s.height/2;e.push({value:r,perpMin:c,perpMax:l},{value:a,perpMin:c,perpMax:l},{value:o,perpMin:c,perpMax:l}),n.push({value:c,perpMin:r,perpMax:o},{value:h,perpMin:r,perpMax:o},{value:l,perpMin:r,perpMax:o})}e.sort((t,e)=>t.value-e.value),n.sort((t,e)=>t.value-e.value),this.xEdges=e,this.yEdges=n}get empty(){return 0===this.xEdges.length&&0===this.yEdges.length}calculateSnap(t,e,n,i){if(0===this.xEdges.length&&0===this.yEdges.length)return{dx:e,dy:n,guides:[]};const s={left:t.left+e,top:t.top+n,width:t.width,height:t.height},r=s.left,o=r+s.width,a=r+s.width/2,c=s.top,l=c+s.height,h=c+s.height/2,d=this.findBestSnap(this.xEdges,[r,a,o],i),u=this.findBestSnap(this.yEdges,[c,h,l],i),p=d?e+d.correction:e,f=u?n+u.correction:n;if(!d&&!u)return{dx:e,dy:n,guides:[]};const m=[];if(d){const e=t.top+f,n=e+t.height;for(const t of d.matches)m.push({axis:"x",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}if(u){const e=t.left+p,n=e+t.width;for(const t of u.matches)m.push({axis:"y",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}return{dx:p,dy:f,guides:m}}findBestSnap(t,e,n){let i=n+1,s=0,r=[];for(let o=0;o<3;o++){const a=e[o],c=this.searchNearest(t,a,n);if(!c)continue;const l=Math.abs(c.correction);if(l<i)i=l,s=c.correction,r=c.matches;else if(l===i&&c.correction===s)for(const t of c.matches)r.push(t)}return i<=n?{correction:s,matches:r}:null}searchNearest(t,e,n){const i=t.length;if(0===i)return null;let s=0,r=i;for(;s<r;){const n=s+r>>1;t[n].value<e?s=n+1:r=n}let o=-1,a=n+1;if(s<i){const i=t[s].value-e;i<=n&&(o=s,a=i)}if(s>0){const n=e-t[s-1].value;n<a&&(o=s-1,a=n)}if(o<0||a>n)return null;const c=t[o].value,l=c-e,h=[t[o]];for(let e=o-1;e>=0&&t[e].value===c;e--)h.push(t[e]);for(let e=o+1;e<i&&t[e].value===c;e++)h.push(t[e]);return{correction:l,matches:h}}}function zl(t,e,n,i){const s=Tc.register(t.type);if(!s)return Ji("Class not found",t.type),null;n&&(t.refid=n(t.refid)),t.id&&i&&i(t.id)&&delete t.id;const r=new s(t,e);return t.components&&r.isContainer()&&(t.components.forEach(t=>{const s=zl(t,e,n,i);s&&r.addComponent(s)}),delete t.components),r.created(),r}function Il(t,e){const n=ni(t.hierarchy);return delete n.id,zl(n,t.app,e)}function Rl(t){const e=t.root;if(!e||!e.assist_layers)return null;for(const t of e.assist_layers)if("snap-guide-layer"===t.state?.type)return t;return null}function jl(t,e){if(t.scalable){const n=t.toLocal(e.offsetX,e.offsetY);return t.toParent(n.x,n.y)}return{x:e.offsetX,y:e.offsetY}}const Ll=fi(function(t,e,n){if(!t.hasSameParentForAllSelected||n)return void(t.focused=null);const i=[];e[0].parent.isGroup()?t.focused=e[0].parent:(e.forEach(t=>{t.path.forEach(e=>{i.push(t.toScene(e.x,e.y))})}),t.focused=t.capturePath(i,e))},300);let Fl;ml.register("move-handler",{"model-layer":{"(descendant)":{dragstart:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;if(n.showMoveHandle)return;let s=i.selected;const r=i.selected.filter(t=>!t.stuck);if(s.length!==r.length&&(s=i.selected=r),0==s.length)return;const o=jl(s[0],t);if(this.last_pos=o,this.direction=0,i.focused=s[0].parent,t.altKey){const t=[],e=new Map;i.selected=i.selected.filter(t=>!t.isRootModel()).map(n=>{const s=Il(n,t=>{const n=i.root.getNewRefid();return void 0!==t&&e.set(t,n),n});return t.push({component:s,to_container:n.parent}),s}).map(t=>(t.replaceRefids(e),t)),t.forEach(({component:t,to_container:e})=>{e.addComponent(t)}),this.duplicates=i.selected.map(t=>({component:t}))}else this.changes=ll.before(s);this.snapIndex=function(t){if(0===t.length)return null;const e=t[0].parent;if(!e||!e.components)return null;const n=new Set(t),i=[];for(const t of e.components)t.isLayer?.()||t.stuck||n.has(t)||i.push(t.bounds);return 0===i.length?null:new Dl(i)}(s);const a=n.rootModel?.get("scale"),c=a?(Math.abs(a.x)+Math.abs(a.y))/2:1;this.snapThreshold=5/(c||1)},dragmove:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const s=i.selected;if(0==s.length||!this.last_pos)return;const r=jl(s[0],t);t.shiftKey?2==this.direction&&(this.direction=0):this.direction=2;let o=r.x-this.last_pos.x,a=r.y-this.last_pos.y;if(0==this.direction){if(o*o+a*a<25)return;Math.abs(o)>Math.abs(a)?this.direction=3:this.direction=4}3==this.direction?a=0:4==this.direction&&(o=0);const c=this.snapIndex,l=c&&!t.metaKey&&!t.ctrlKey,h=o,d=a;if(l){const t=function(t){return 0===t.length?null:1===t.length?t[0].bounds:Er(t.map(t=>t.bounds))}(s);if(t){const e=c.calculateSnap(t,o,a,this.snapThreshold);o=e.dx,a=e.dy;const n=Rl(i);n&&(n.snapResult=e.guides.length>0?e:null)}}else{const t=Rl(i);t&&(t.snapResult=null)}s.forEach(t=>{t.move({x:o,y:a},1===s.length)}),this.last_pos={x:r.x-(h-o),y:r.y-(d-a)},Ll(i,s)},dragend:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const s=i.selected;if(0==s.length)return;const r=s[0].parent,o=i.focused||e.deliverer;if(this.changes&&!o.isGroup())if(i.hasSameParentForAllSelected&&o&&o!==r){const t=this.changes.map(t=>{const{component:e}=t;return{component:e,to_container:o}});i.app.commander.execute(new Ol({changes:t}))}else ll.after(this.changes,i.app.commander);else if(this.duplicates){this.duplicates=this.duplicates.map(t=>(t.to_container=o,t));const t=new Ol({changes:this.duplicates});i.app.commander.execute(t)}s.forEach(t=>{t.parent&&t.parent.calculateBounds&&t.parent.calculateBounds()}),this.last_pos=null,this.changes=null,this.duplicates=null,this.snapIndex=null,this.snapThreshold=5;const a=Rl(i);a&&a.clear(),Ll(i,s,!0)}}},"(root)":{"(self)":{keydown:function(t,e){const{origin:n,deliverer:i}=e,s={},r=t.shiftKey?n.rootModel.MPP:1;switch(t.which){case 37:s.x=-r,s.y=0;break;case 38:s.x=0,s.y=-r;break;case 39:s.x=r,s.y=0;break;case 40:s.x=0,s.y=r;break;default:return}const o=i.selected;ll.around(i.app.commander,function(){o.forEach(t=>{!t.stuck&&t.move(s,!1)})})}}}}),ml.register("shift-handler",{"model-layer":{"(all)":{dragstart:function(t,e){Fl={x:t.offsetX,y:t.offsetY}},dragmove:function(t,e){const{deliverer:n}=e,i=t.offsetX,s=t.offsetY;n.rootModel.move({x:i-Fl.x,y:s-Fl.y},!1),Fl={x:i,y:s}}}}}),ml.register("zoom-handler",{"model-layer":{"(all)":{wheel:function(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer,i=t.deltaY<0?1:-1,s=n.get("scale")||{x:1,y:1},r=n.get("translate"),o=t.offsetX,a=t.offsetY,c=n.toLocal(o,a),l=.1*i,h={x:s.x+l,y:s.y+l};if(i<0&&s.x<.2||i>0&&s.x>10)return;n.set("scale",h);const d=n.toLocal(o,a);n.set("translate",{x:r.x+(d.x-c.x)*h.x,y:r.y+(d.y-c.y)*h.y})}},"(self)":{dblclick:function(t,e){const n=e.origin;n?.root.fit()}}}});let Nl={},Hl={};function Bl(t){const e={};for(const n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}ml.register("paste-handler",{"(root)":{"(self)":{stylepastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{fillStyle:e,strokeStyle:s,alpha:r,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:m,textBaseline:g,textOverflow:y,paddingTop:b,paddingBottom:_,paddingLeft:v,paddingRight:x}=t.state;Nl=ni({fillStyle:e,strokeStyle:s,alpha:r,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:m,textBaseline:g,textOverflow:y,paddingTop:b,paddingBottom:_,paddingLeft:v,paddingRight:x}),n.mode=4}},stylepastestop:function(t){const{deliverer:e}=t,n=e.app;Nl={},4==n.mode&&(n.mode=1)},databindpastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{mappings:e}=t.state;Hl=ni({mappings:e}),n.mode=5}},databindpastestop:function(t){const{deliverer:e}=t,n=e.app;Hl={},5==n.mode&&(n.mode=1)},pasteapply:function(t,e){const{deliverer:n}=e,i=n.app;t&&(4==i.mode?ll.around(i.commander,()=>{t.set(Bl({...t.model,...Nl}))}):5==i.mode&&ll.around(i.commander,()=>{t.set(Bl({...t.model,...Hl}))}))},keydown:function(t,e){const{deliverer:n}=e;"Esc"!=t.code&&"Escape"!=t.code||(4==n.app.mode?n.trigger("stylepastestop"):5==n.app.mode&&n.trigger("databindpastestop"))}}},"model-layer":{"(all)":{click:function(t,e){const{deliverer:n}=e,i=n.app;if(4!=i.mode&&5!=i.mode)return;const s=e.origin;4==i.mode?s===n?n.root.trigger("stylepastestop"):s&&ll.around(i.commander,()=>{const t=Bl({...s.model,...Nl});s?.set(t)}):s===n?n.root.trigger("databindpastestop"):s&&ll.around(i.commander,()=>{const t=Bl({...s.model,...Hl});s?.set(t)})}}}});class Gl{constructor(){this.animatorMap=new Map}waypoint(t,e){this.animatorMap.has(t)&&this.off(t);let{from:n,to:i}=e;if("string"==typeof n&&(n=t.root?.findById(n)),"string"==typeof i&&(i=t.root.findById(i)),!i)return void Ji("WaypointAnimation: Source or target component not found");const s=Ca(t,{type:"waypoint",fromComponent:n,toComponent:i,...e,onComplete:()=>{this.off(t)}});s&&(this.animatorMap.set(t,s),s.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 Vl(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?.reset()}ml.register("waypoint-handler",{"model-layer":{"(descendant)":{waypoint:function(t,e){const{origin:n}=e,i=n.root;let{waypointHandler:s}=i;s||(s=new Gl,i.waypointHandler=s),s.waypoint(n,t)},waypointoff:function(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?i.off(e):Ji("waypoint-handler not found")},waypointreset:Vl},"(self)":{waypointreset:Vl}}},function(t){const{waypointHandler:e}=t;e&&(e.dispose(),delete t.waypointHandler)});class Yl{constructor(){this.animatorMap=new Map}transition(t,e){this.animatorMap.has(t)&&this.off(t);const n=Ca(t,{type:"transition",fromComponent:e.from,toComponent:e.to,...e,onComplete:()=>{this.off(t)}});n&&(this.animatorMap.set(t,n),n.start())}off(t){const e=this.animatorMap.get(t);e&&(e.stop(),this.animatorMap.delete(t))}reset(){for(const t of this.animatorMap.values())t.stop();this.animatorMap.clear()}dispose(){this.reset(),this.animatorMap=null}}function Wl(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?.reset()}function Ul(t){return t<.5?2*t*t:1-2*(1-t)*(1-t)}ml.register("transition-handler",{"model-layer":{"(descendant)":{transition:function(t,e){const{origin:n}=e,i=n.root;let{transitionHandler:s}=i;s||(s=new Yl,i.transitionHandler=s),s.transition(n,t)},transitionoff:function(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?i.off(e):Ji("transition-handler not found")},transitionreset:Wl},"(self)":{transitionreset:Wl}}},function(t){const{transitionHandler:e}=t;e&&(e.dispose(),delete t.transitionHandler)});class $l{constructor(t){this.active=new Map,this._liveOverlay=new Set,this.unsubscribeTick=null,this._canvas=null,this._ctx=null,this.root=t}isReparenting(t){return this.active.has(t)||this._liveOverlay.has(t)}setLiveOverlay(t,e){e?this._liveOverlay.has(t)||(this._liveOverlay.add(t),this.ensureCanvas()):this._liveOverlay.delete(t)}getState(t){return this.active.get(t)||null}begin(t,e){if(this.cancel(t),this.root?.app?.suppressAnimations)return this.cleanup3D(t),t.clearCache?.(),void t.invalidate?.();const n={fromWorld:e.fromWorld,toWorld:e.toWorld,from3D:e.from3D,to3D:e.to3D,duration:Math.max(e.duration,1),startTime:jr.simTime,progress:0,keepSuppressed:e.keepSuppressed,ease:e.ease};this.active.set(t,n);const i=t._realObject;if(i?.setTransientPlacement){const t={};(e.from3D?.worldQuatLock||e.to3D?.worldQuatLock)&&(t.worldQuatLock=e.to3D?.worldQuatLock??e.from3D?.worldQuatLock),e.keepSuppressed&&(t.keepSuppressed=!0),i.setTransientPlacement({policy:"transitioning",meta:t})}if(n.fromWorld&&this.ensureCanvas(),n.from3D){const e=t._realObject?.object3d;if(e){e.position.copy(n.from3D.pos),e.quaternion.copy(n.from3D.quat);const t=n.from3D.fromScale;t&&e.scale.set(t.x,t.y,t.z)}}this.startLoop()}cancel(t){this.active.has(t)&&this.complete(t)}renderComponent(t,e){if(!this._ctx)return;const n=this._ctx,i=this.active.get(t);let s,r,o,a,c,l=!1;if(i?.fromWorld&&i?.toWorld){const t=i.progress,e=i.fromWorld,n=i.toWorld;s=e.x+(n.x-e.x)*t,r=e.y+(n.y-e.y)*t,o=e.rotation+(n.rotation-e.rotation)*t,a=e.width+(n.width-e.width)*t,c=e.height+(n.height-e.height)*t}else{if(!this._liveOverlay.has(t))return;{if("function"!=typeof t.toScene||!t.parent||!t.bounds)return void this._liveOverlay.delete(t);const e=t.center,n=t.toScene(e.x,e.y);let i=0;for(let e=t.parent;e&&!e.isRootModel?.();e=e.parent)i+=e.state?.rotation||0;const h=t.bounds;s=n.x,r=n.y,o=i,a=h.width,c=h.height,l=!0}}const{translate:h={x:0,y:0},scale:d={x:1,y:1}}=e.model;n.save(),n.translate(h.x,h.y),n.scale(d.x,d.y),n.translate(s,r),n.rotate(o);const u=t.bounds;if(u&&u.width&&u.height){const t=a/u.width,e=c/u.height;n.scale(t,e),n.translate(-(u.left+u.width/2),-(u.top+u.height/2))}l?t.draw(n):t.render(n),n.restore()}beginDraw(){if(!this._canvas||!this._ctx)return;this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._ctx.save();const t=globalThis.devicePixelRatio||1;this._ctx.scale(t,t)}endDraw(){if(!this._ctx)return;const t=this.root?.model_layer;if(t&&(this.active.size>0||this._liveOverlay.size>0)){const e=new Set;for(const n of this.active.keys())e.has(n)||(e.add(n),this.renderComponent(n,t));for(const n of[...this._liveOverlay])e.has(n)||(e.add(n),this.renderComponent(n,t))}this._ctx.restore()}resize(){if(!this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element.clientWidth,n=t.element.clientHeight;t.fitSize(this._canvas,!0,e,n)}dispose(){for(const[t]of this.active)this.cleanup3D(t);this.active.clear(),this._liveOverlay.clear(),this.stopLoop(),this.removeCanvas()}ensureCanvas(){if(this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element;this._canvas=document.createElement("canvas"),this._canvas.width=1,this._canvas.height=1,this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.style.zIndex="150",this._canvas.setAttribute("scene","transition-canvas"),e.appendChild(this._canvas);const n=e.clientWidth,i=e.clientHeight;t.fitSize(this._canvas,!0,n,i),this._ctx=this._canvas.getContext("2d")}removeCanvas(){this._canvas&&(this._canvas.parentNode?.removeChild(this._canvas),this._canvas=null,this._ctx=null)}startLoop(){this.unsubscribeTick||(this.unsubscribeTick=jr.subscribe(()=>this.tick(),{description:"reparent",component:this.root,getTargets:()=>[...this.active.keys()]}))}stopLoop(){this.unsubscribeTick&&(this.unsubscribeTick(),this.unsubscribeTick=null)}tick(){if(this.root?.app?.suppressAnimations){const t=[...this.active.keys()];for(const e of t)this.complete(e);return}const t=jr.simTime,e=[];for(const[n,i]of this.active){const s=t-i.startTime,r=Math.min(s/i.duration,1),o="linear"===i.ease?r:Ul(r);if(i.progress=o,i.from3D&&i.to3D){const t=n._realObject?.object3d;if(t){t.position.lerpVectors(i.from3D.pos,i.to3D.pos,o),t.quaternion.copy(i.from3D.quat).slerp(i.to3D.quat,o);const e=i.from3D.fromScale,n=i.from3D.toScale;e&&n&&t.scale.set(e.x+(n.x-e.x)*o,e.y+(n.y-e.y)*o,e.z+(n.z-e.z)*o);const s=i.to3D.worldQuatLock??i.from3D.worldQuatLock,r=t.parent;s&&r&&(r.updateWorldMatrix(!0,!1),r.getWorldQuaternion(t.quaternion),t.quaternion.invert(),t.quaternion.multiply(s))}}n.clearCache?.(),n.invalidate?.(),r>=1&&e.push(n)}for(const t of e)this.complete(t);0===this.active.size&&this.stopLoop()}complete(t){this.cleanup3D(t),this.active.delete(t),t.clearCache?.(),t.invalidate?.();let e=!1;for(const[,t]of this.active)if(t.fromWorld){e=!0;break}e||0!==this._liveOverlay.size||this.removeCanvas()}cleanup3D(t){const e=this.active.get(t),n=t._realObject;if(n){if(n.object3d){const t=n.dimensionScale??{x:1,y:1,z:1};n.object3d.scale.set(t.x,t.y,t.z)}e?.keepSuppressed?n.clearTransientPlacement?.():(n.suppressTransform=!1,n.clearTransientPlacement?.(),n.update?.())}}}function Xl(t){return class extends t{get showMoveHandle(){return!1}}}const ql=[];class Kl extends(Xl(Dc(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 Fc.get(this.get("layout"))||Hc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){if(!t)return;const{animated:n=!1,duration:i=2e3,ease:s="inout"}=e,r=t.parent;if(!r||r===this)return;const o=t=>{let e=0,n=t;for(;n&&!n.isRootModel?.();)e+=n.state?.rotation||0,n=n.parent;return e},a=!(!t._realObject?.object3d||!this._realObject?.object3d);let c=null,l=null,h=null,d=null;if(a){const n=e.toParent3D??this._realObject.object3d,i=t._realObject.object3d,s=t._realObject.dimension||{width:1,height:1,depth:1};n.updateWorldMatrix(!0,!1),i.updateWorldMatrix(!0,!1),n.attach(i),c={pos:i.position.clone(),quat:i.quaternion.clone(),fromDimW:s.width||1,fromDimH:s.height||1,fromDimD:s.depth||1},t._realObject.suppressTransform=!0}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);h={x:i.x,y:i.y,rotation:o(r),width:e.width,height:e.height}}if(this.addComponent(t,{silent:!0}),a){const e=t._realObject.object3d;t.clearCache();const n=t._realObject.position,i=t._realObject.rotation,s=t._realObject.dimension||{width:1,height:1,depth:1},r=s.width||1,o=s.height||1,a=s.depth||1,h={x:c.fromDimW/r,y:c.fromDimH/o,z:c.fromDimD/a};l={pos:e.position.clone().set(n.x,n.y,n.z),quat:e.quaternion.clone().setFromEuler(e.rotation.clone().set(i.x,i.y,i.z))},c.fromScale=h,c.toScale={x:1,y:1,z:1},e.position.copy(c.pos),e.quaternion.copy(c.quat)}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);d={x:i.x,y:i.y,rotation:o(this),width:e.width,height:e.height}}if(n){const e=this.root?.transitionEffect;e&&e.begin(t,{fromWorld:h,toWorld:d,from3D:c,to3D:l,duration:i,ease:s})}}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,s=t.parent;if(s){if(this===s)return;"function"==typeof s.removeItem&&-1!==s._items?.indexOf?.(t)&&s.removeItem(t),s.removeComponent(t,n||i)}const r=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,r),t.delegate_on(this),i?(s&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,r),t.trigger("added",this,t,r),delete t._silentAdd):n||t.trigger("added",this,t,r),this.root&&this.root.isReady&&t.invokeReady()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const s=this._components.splice(0,e);this._components=s.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||ql).indexOf(t)}size(){return(this._components||ql).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const s=this._components.splice(1);this._components=i.concat(s),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return nc(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const s=this.components[i].findAll(t,...e);s&&(n=n.concat(s))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return nc(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}contains(t,e){let n=super.contains(t,e);if(!n){const{left:i,top:s,width:r,height:o}=this.state;n=t<Math.max(i+r,i)&&t>Math.min(i+r,i)&&e<Math.max(s+o,s)&&e>Math.min(s+o,s)}return n}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const s=this.bounds;i.x-=s.left,i.y-=s.top;const r=this.layout.capturables(this);for(let s=r.length-1;s>=0;s--){const o=r[s];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:s,width:r,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+r||a.y<s||a.y>s+o)return!1;a.x-=i,a.y-=s,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const s=i.capturePath(n,e);if(s)return s}return this.focusible&&this}render(t){if("popup"===this.position)return;const{left:e=0,top:n=0,width:i,height:s}=this.bounds;t.beginPath(),t.rect(e,n,i,s),t.closePath(),this.drawFill(t),this.drawStroke(t)}postrender(t){if("popup"===this.position)return void super.postrender(t);const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:s,height:r}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,s,r),t.clip(),t.closePath()),({top:i,left:n}=this.state),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)||e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>Tc.memoize(Kl.prototype,t,!1));const Ql=1e6;const Zl=[],Jl=fi(function(){Zl.forEach(t=>{t.resize()})},100);"undefined"!=typeof window&&window.addEventListener("resize",Jl);class th extends Kl{get showMoveHandle(){return!1}static onBeforeDispose(t){return th._beforeDisposeHooks.push(t),()=>{const e=th._beforeDisposeHooks.indexOf(t);e>=0&&th._beforeDisposeHooks.splice(e,1)}}constructor(t,e){super(Object.assign({type:"root",scale:{x:1,y:1}},t||{}),e),this._hasSameParentForAllSelected=!1,this._maxRefid=e?.isViewMode?Ql:0,t=t||{},this.fitMode=t.model&&t.model.fitMode,this._app=e,this.style=t.style,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={},this._serviceMap=new Map,this.transitionEffect=new $l(this),this.target_element=t.target_element,this.rebuildContentModel(this.model.model),Zl.push(this)}registerService(t,e){this._serviceMap.set(t,e)}getService(t){return this._serviceMap.get(t)}unregisterService(t){this._serviceMap.delete(t)}dispose(){for(const t of th._beforeDisposeHooks)try{t(this)}catch(t){Zi("RootContainer beforeDispose hook 실패",t)}this.transitionEffect?.dispose(),this._app&&this._app.dispose(),super.dispose(),this._disposeAllResources(),this.target_element=null,this._refresh_mapping_debouncer&&"function"==typeof this._refresh_mapping_debouncer.cancel&&this._refresh_mapping_debouncer.cancel(),delete this._refresh_mapping_debouncer;const t=Zl.indexOf(this);t>=0&&Zl.splice(t,1),this.refidIndexMap.clear(),this.indexMap.clear(),this._serviceMap.clear(),this._maxRefid=0}isRoot(){return!0}get app(){return this._app}get target_element(){return this._target_element}set target_element(t){this._ua_event_handler&&(this._ua_event_handler.dispose(),delete this._ua_event_handler),t&&(t.style.position="absolute",t.style.cursor="default",t.style.overflow="hidden",t.setAttribute("scene","root-container"),this._ua_event_handler=new al(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&&Zi("Template replaced (duplicated)",t,e,n),this.templateMap[t]=e,delete this.templatePrefixes}removeTemplate(t,e){const n=this.templateMap[t];n!==e?Ji("Removing template failed (different)",t,e,n):delete this.templateMap[t],delete this.templatePrefixes}findTemplateFor(t){this.templatePrefixes||(this.templatePrefixes=Object.keys(this.templateMap).sort().reverse());const e=this.templatePrefixes.find(e=>t.startsWith(e));if(e)return this.templateMap[e]}addIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);i?i.push(e):this.indexMap.set(n,[e])}removeIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);if(!i)return;const s=i.indexOf(e);-1!==s&&(i.splice(s,1),0===i.length&&this.indexMap.delete(n))}addRefidIndex(t,e){null==t&&(t=this.getNewRefid(),e.set("refid",t)),(this._app?.isViewMode||"number"!=typeof t||t<Ql)&&(this._maxRefid=Math.max(t,this._maxRefid));const n=this.refidIndexMap.get(t);n&&Zi("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?Zi("Refid Removing index failed (has not to be)",t,e,n):this.refidIndexMap.delete(t)}getNewRefid(){return this._maxRefid=(this._maxRefid||0)+1,this._maxRefid}async subscribe(t,e){this._app.isViewMode&&t&&this._app&&(e._subscription=await this._app.subscribe(t,e))}async unsubscribe(t,e){e._subscription&&(await e._subscription.unsubscribe(),delete e._subscription)}findById(t){if(!t)return null;const e=this.indexMap.get("#"===t[0]?t.substring(1):t);return e?e[0]:null}findAllById(t){return t&&this.indexMap.get("#"===t[0]?t.substring(1):t)||th.EMPTY_ARRAY}findByRefid(t){return this.refidIndexMap.get(t)}findOrCreate(t){const e=this.findAllById(t);if(!e||0===e.length){if(this.app&&!this.app.isEditMode){const e=this.findTemplateFor(t);if(e){const n=zl(Object.assign(ni(e.hierarchy),{id:t,templatePrefix:""}),this.app);return this.model_layer.addComponent(n),[n]}}return[]}return e}resize(){this.components.forEach(t=>{t.resize&&t.resize()}),this.invalidate()}fit(t){const{width:e,height:n,fitMode:i}=this.model_layer.model,s=this.target_element,r=this.model_layer;if(this.fitMode=t||this.fitMode||i||"ratio",e&&n&&s&&s.clientWidth&&s.clientHeight){switch(this.fitMode){case"center":!function(t,e,n){const i=t.unitScale,{width:s,height:r}=e.model;e.set("scale",{x:i,y:i}),e.set("translate",{x:Math.max((n.clientWidth-s*i)/2,0),y:Math.max((n.clientHeight-r*i)/2,0)})}(this,r,s);break;case"both":!function(t,e,n){const{width:i,height:s}=e.model,r=n.clientWidth,o=n.clientHeight;e.set("scale",{x:r/i,y:o/s}),e.set("translate",{x:0,y:0})}(0,r,s);break;case"width":!function(t,e,n){const i=n.clientWidth/e.get("width");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,r,s);break;case"height":!function(t,e,n){const i=n.clientHeight/e.get("height");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,r,s);break;case"ratio":!function(t,e,n){const{width:i,height:s}=e.model,r=n.clientWidth,o=n.clientHeight,a=r/i,c=o/s,l=Math.min(a,c);e.set("scale",{x:l,y:l}),e.set("translate",{x:(r-i*l)/2,y:(o-s*l)/2})}(0,r,s);break;default:!function(t,e){const n=t.unitScale;e.set("scale",{x:n,y:n}),e.set("translate",{x:0,y:0})}(this,r)}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=>{ml.getDisposer(t).call(null,this)}),this.assist_layers&&this.assist_layers.forEach(t=>{t.dispose(),this.removeComponent(t)}),delete this.assist_layers,this.model_layer&&this.model_layer.dispose(),this.model_layer&&this.removeComponent(this.model_layer),delete this.model_layer,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={}}rebuildContentModel(t,e){let n,i;if(e?.preserveThreeD&&this.model_layer?.is3dMode){const t=this.model_layer._threeCapability;t&&(i=t.captureSessionState()),n=this.model_layer.detachThreeCapability()}this._disposeAllResources(),this.eventEngine=new Kc(this);const s=this._app?.loadTracker;(t=t||{}).type="model-layer",t.dataLagMonitor&&this._app&&this._app.initLagTracker(t.dataLagMonitor),s?.setPhase("compile"),this.model_layer=zl(t,this.app),e?.preserveThreeD&&(this.model_layer._rebuildPreserveThreeD=!0),this.addComponent(this.model_layer),this.model_layer.target=this.target_element,this.assist_layers=(this.model.layers||[]).map(t=>{const e=zl(t,this.app);if(e)return this.addComponent(e),e.target=this.target_element,e;Zi("Layer compile failed",t)}).filter(Boolean),this.assist_handlers=(this.model.handlers||[]).map(t=>{const e={};return this.eventEngine.add(e,ml.get(t)),e}),n&&(this.model_layer.adoptThreeCapability(n),i&&n.restoreSessionState(i)),s?.setPhase("assets"),this._ready=!0,this.traverse(t=>t.invokeReady()),s?.checkComplete(),s?.startGlobalTimeout()}get root(){return this}get anchors(){return[]}get isReady(){return this._ready}get rootModel(){return this.model_layer}get threed(){return this.model_layer?.model?.threed||!1}set threed(t){this.model_layer&&this.model_layer.toggleThreeD(t)}get stuck(){return!0}get data(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].data);return t}set data(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.data=t[e])}}get dataByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.data;return t}set dataByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.data=t[e])}}get values(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].value);return t}set values(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.value=t[e])}}get valuesByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.value;return t}set valuesByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.value=t[e])}}get selected(){return(this._selected||[]).filter(t=>t.parent)}set selected(t){const e=this._selected;if(this._selected=t,!t||t.length<=1)this.hasSameParentForAllSelected=!0;else{const e=t[0].parent;this.hasSameParentForAllSelected=!t.find(t=>t.parent!=e)}this.trigger("selected",t,e)}get focused(){return this._focused}set focused(t){this._focused!==t&&(this._focused=t,this.invalidate())}get style(){return this._style}set style(t){this._style=t,this._compiled_style=t}get hasTextProperty(){return!1}render(){this.layout.drawables(this).forEach(t=>t.draw())}contains(t,e){return!0}capturePath(t,e){return this.model_layer.capturePath(t,e)}invalidate(){this.components.forEach(t=>t.invalidate())}_areAliasesEqual(t,e){if(!Array.isArray(t)&&!Array.isArray(e))return!0;if(!Array.isArray(t)||!Array.isArray(e))return!1;if(t.length!==e.length)return!1;const n=[...t].sort(),i=[...e].sort();return n.every((t,e)=>t===i[e])}get eventMap(){return{"(root)":{"(descendant)":{added:this.onadded,removed:this.onremoved,change:this.onchanged}}}}refreshMappings(){if(!this._refresh_mapping_debouncer){if(this.disposed)return;this._refresh_mapping_debouncer=fi(function t(e){e.executeMappings(),e.components&&e.components.forEach(e=>t(e))},1e3)}this._refresh_mapping_debouncer(this.model_layer)}_addTraverse(t){t.components&&t.components.forEach(t=>this._addTraverse(t));const{id:e,alias:n,refid:i,tag:s,templatePrefix:r}=t.model;this.addRefidIndex(i,t),e&&this.addIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.addIndex(e,t)}),s&&this.subscribe(s,t),r&&this.addTemplate(r,t);const o=xi({},t.eventMap,t.model.eventMap);this.eventEngine.add(t,o)}_removeTraverse(t){t.components&&t.components.forEach(t=>this._removeTraverse(t));const{id:e,alias:n,refid:i,tag:s,templatePrefix:r}=t.model;this.removeRefidIndex(i,t),e&&this.removeIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.removeIndex(e,t)}),s&&this.unsubscribe(s,t),r&&this.removeTemplate(r,t),this.eventEngine.remove(t)}onadded(t,e){this._addTraverse(e),e._silentAdd||this.refreshMappings(),this.invalidate()}onremoved(t,e){this._removeTraverse(e),this.invalidate()}onchanged(t,e,n){e.templatePrefix&&this.removeTemplate(e.templatePrefix,n.origin),t.templatePrefix&&this.addTemplate(t.templatePrefix,n.origin),e.id&&this.removeIndex(e.id,n.origin),t.id&&this.addIndex(t.id,n.origin),Array.isArray(e.alias)&&e.alias.forEach(t=>{t&&this.removeIndex(t,n.origin)}),Array.isArray(t.alias)&&t.alias.forEach(t=>{t&&this.addIndex(t,n.origin)}),e.tag&&this.unsubscribe(e.tag,n.origin),t.tag&&this.subscribe(t.tag,n.origin),e.id==t.id&&e.class==t.class&&this._areAliasesEqual(e.alias,t.alias)||n.origin._silentAdd||this.refreshMappings()}}th._beforeDisposeHooks=[],th.EMPTY_ARRAY=[],Tc.memoize(th.prototype,"unitScale",!1);class eh{constructor(){this._current=0,this._min=1/0,this._max=-1/0,this._count=0,this._baseline=0,this._baselineSet=!1,this._baselineSum=0,this._baselineCount=0,this._warn=5e3,this._critical=15e3,this._lastLevel="normal",this._disposed=!1}configure(t){const e=Array.isArray(t)?t[0]:t;e&&(this._warn=e.warnThreshold??this._warn,this._critical=e.criticalThreshold??this._critical)}record(t,e){if(this._disposed)return;const n="number"==typeof e?e:t;if("number"!=typeof n||n<=0)return;const i=Date.now()-n;this._current=i,this._count++,i<this._min&&(this._min=i),i>this._max&&(this._max=i),this._baselineSet||(this._baselineSum+=i,this._baselineCount++,this._baselineCount>=5&&(this._baseline=this._baselineSum/this._baselineCount,this._baselineSet=!0))}getStats(){if(0===this._count)return{current:0,baseline:0,drift:0,min:0,max:0,sampleCount:0,level:"normal"};const t=this._baselineSet?this._baseline:this._baselineCount>0?this._baselineSum/this._baselineCount:this._current,e=this._current-t;return{current:this._current,baseline:t,drift:e,min:this._min,max:this._max,sampleCount:this._count,level:this._calcLevel(Math.abs(e))}}evaluate(){if(this._disposed)return;const t=this.getStats();t.level!==this._lastLevel&&(this._lastLevel=t.level,this.onLevelChange?.(t.level,t))}reset(){this._current=0,this._min=1/0,this._max=-1/0,this._count=0,this._baseline=0,this._baselineSet=!1,this._baselineSum=0,this._baselineCount=0,this._lastLevel="normal"}dispose(){this._disposed=!0,this.onLevelChange=void 0}_calcLevel(t){return t>=this._critical?"critical":t>=this._warn?"warn":"normal"}}const nh=new eh,ih=5e3;class sh{constructor(t){this._entries=new Map,this._phase="fetch",this._phaseHistory=[],this._disposed=!1,this.needsOverlay=!1,this._firstRenderDone=!1,this._options=t||{},this._startTime=performance.now(),this._promise=new Promise(t=>{this._promiseResolve=t}),this._phaseHistory.push({phase:"fetch",timestamp:this._startTime,elapsed:0}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},ih)}get phase(){return this._phase}get phaseHistory(){return this._phaseHistory}get progress(){const t=this._entries.size;if(0===t)return 1;let e=0;for(const t of this._entries.values())"pending"!==t.status&&e++;return e/t}get pending(){const t=[],e=performance.now();for(const n of this._entries.values())"pending"===n.status&&t.push(this._toPublicEntry(n,e));return t}get entries(){const t=performance.now(),e=[];for(const n of this._entries.values())e.push(this._toPublicEntry(n,t));return e}get stats(){let t=0,e=0,n=0,i=0,s=0;for(const r of this._entries.values())switch(r.status){case"loaded":t++;break;case"timeout":e++;break;case"error":n++;break;case"cancelled":i++;break;case"pending":s++}return{total:this._entries.size,loaded:t,timeout:e,error:n,cancelled:i,pending:s,elapsed:this._completedElapsed??performance.now()-this._startTime}}get promise(){return this._promise}markFirstRender(){this._firstRenderDone||this._disposed||(this._firstRenderDone=!0,this.setPhase("render"),this.checkComplete())}setPhase(t){if(this._disposed||this._phase===t||"complete"===this._phase)return;const e=performance.now(),n=this._phaseHistory[this._phaseHistory.length-1];n&&void 0===n.duration&&(n.duration=e-n.timestamp),this._phase=t,"complete"!==t?(this._phaseHistory.push({phase:t,timestamp:e,elapsed:e-this._startTime}),this.onPhase?.(t)):this.onPhase?.(t)}track(t,e,n,i){if(this._disposed)return;const s={id:t,type:e,url:n,startTime:performance.now(),status:"pending"};this._entries.set(t,s),this._options.assetTimeout&&this._options.assetTimeout>0&&(s.timerId=setTimeout(()=>{"pending"===s.status&&(s.status="timeout",s.endTime=performance.now(),s.timerId&&(s.timerId=void 0),this.onTimeout?.(this._toPublicEntry(s)),this._onEntryDone())},this._options.assetTimeout)),i.then(()=>{"pending"===s.status&&(s.status="loaded",s.endTime=performance.now(),this._clearEntryTimer(s),this._onEntryDone())},()=>{"pending"===s.status&&(s.status="error",s.endTime=performance.now(),this._clearEntryTimer(s),this._onEntryDone())})}checkComplete(){if(this._disposed||"complete"===this._phase)return;let t=!1;for(const e of this._entries.values())if("pending"===e.status){t=!0;break}!t&&this._firstRenderDone&&this._doComplete()}startGlobalTimeout(){if(this._disposed)return;const t=this._options.timeout;!t||t<=0||(this._globalTimerId=setTimeout(()=>{if("complete"===this._phase||this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="timeout",e.endTime=t,this._clearEntryTimer(e),this.onTimeout?.(this._toPublicEntry(e)));this._doComplete(!0)},t))}abort(){if(this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="cancelled",e.endTime=t,this._clearEntryTimer(e));this._doComplete(!0)}reset(){for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._entries.clear(),this._phase="fetch",this._startTime=performance.now(),this._phaseHistory=[{phase:"fetch",timestamp:this._startTime,elapsed:0}],this._completedElapsed=void 0,this._firstRenderDone=!1,this.needsOverlay=!1,this._disposed=!1,this._promise=new Promise(t=>{this._promiseResolve=t}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},ih)}dispose(){if(!this._disposed){this._disposed=!0;for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._promiseResolve(),this.onPhase=void 0,this.onProgress=void 0,this.onTimeout=void 0,this.onComplete=void 0,this.onNeedsOverlay=void 0}}_onEntryDone(){this._disposed||(this.onProgress?.(this.stats),this.checkComplete())}_doComplete(t=!1){"complete"!==this._phase&&(this._completedElapsed=performance.now()-this._startTime,this._completedElapsed>ih&&(this.needsOverlay=!0),this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this.setPhase("complete"),this.onComplete?.(this.stats),this._promiseResolve())}_clearEntryTimer(t){t.timerId&&(clearTimeout(t.timerId),t.timerId=void 0)}_toPublicEntry(t,e){const n=t.endTime?t.endTime-t.startTime:(e??performance.now())-t.startTime;return{id:t.id,type:t.type,url:t.url,startTime:t.startTime,status:t.status,elapsed:n}}}let rh=13.3;var oh=function(t){return void 0!==t&&(rh=t),rh};const ah="$base_url";const ch=Math.PI/12;class lh{constructor(t,e){this._postprocessing=!0,this._loadTrackerOwned=!1,this._suppressAnimationsFlag=!1,this._suppressScopeCount=0,this.isSelecting=!1,this._mode=t,this.screen=oh(),this._baseUrl="undefined"!=typeof window?window.location.origin:null,this._refProvider=e,this.isEditMode&&(this._rotateStep=ch,this._rotateStepForced=!1)}initLoadTracker(t){return this._loadTracker=new sh(t),this._loadTrackerOwned=!0,this._loadTracker}get loadTracker(){return this._loadTracker}adoptLoadTracker(t){this._loadTracker=t,this._loadTrackerOwned=!1}initLagTracker(t){return nh.configure(t),nh}get lagTracker(){return nh}dispose(){this._loadTrackerOwned&&this._loadTracker?.dispose(),this._loadTracker=void 0,this._dataSubscriptionProvider?.dispose?.(),delete this._dataStorage}_calcScreen(){const t={width:screen.width,height:screen.height};this._PPI=function(t,e,n,i="d"){t<=0&&(t=1),e<=0&&(e=1);const s=("d"===i?Math.sqrt(t*t+e*e):"w"===i?t:e)/n;return s>0?Math.round(s):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 Xs}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 focusFilter(){return this._focusFilter}set focusFilter(t){this._focusFilter=t}get baseUrl(){return this._baseUrl}set baseUrl(t){t&&this._baseUrl!==t&&(this._baseUrl=t)}url(t){try{let e;return e=t.includes(ah)?new URL(t.replace(ah,this.baseUrl??""),this.baseUrl??void 0):new URL(t,location.origin),e.href}catch(e){Ji(e,t)}}get rotateStep(){return this._rotateStep}set rotateStep(t){this._rotateStep=Number(t)||ch}get rotateStepForced(){return this._rotateStepForced}set rotateStepForced(t){this._rotateStepForced=!!t}get dataStorage(){return this._dataStorage}set dataStorage(t){this._dataStorage=t}get postprocessing(){return this._postprocessing}set postprocessing(t){this._postprocessing=t}get logarithmicDepth(){return this._logarithmicDepth}set logarithmicDepth(t){this._logarithmicDepth=t}get suppressAnimations(){return this._suppressAnimationsFlag||this._suppressScopeCount>0}set suppressAnimations(t){this._suppressAnimationsFlag=!!t}withSuppressedAnimations(t){let e;this._suppressScopeCount++;try{e=t()}catch(t){throw this._suppressScopeCount--,t}return e&&"function"==typeof e.then?e.finally(()=>{this._suppressScopeCount--}):(this._suppressScopeCount--,e)}beginSuppressAnimations(){this._suppressScopeCount++;let t=!1;return{end:()=>{t||(t=!0,this._suppressScopeCount--)}}}}Qi(lh.prototype,Bi.withEvent);class hh{constructor(t,e){!(t=Number(t))||t<=0?(Zi("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];Ji("Not forwardable.")}backward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.backwardable)return this.q[--this.pos];Ji("Not backwardable.")}get current(){if(-1!==this.pos)return this.q[this.pos];Ji("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 dh=fi(t=>{t.brake||t.take()},1e3,{leading:!0,trailing:!1});function uh(t){!t.brake&&t.dirty&&dh(t)}class ph{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(){dh.cancel(),this.state_holder=null,this.timecapsule=null}touch(){this.dirty=!0,uh(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,uh(this)}}function fh(t,e){const n=e.model_layer.get("scale"),i=e.model_layer.get("translate");if(t){const s=JSON.parse(t);s.scale=n,s.translate=i,e.rebuildContentModel(s,{preserveThreeD:!0})}}class mh{constructor(t){this.container=t,this.timecapsule=new hh(20);const e=this;this.snapshot_taker=new ph({get state(){const t=e.container.model_layer.hierarchy;return JSON.stringify(t,za)}},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&&(fh(this.timecapsule.backward(),this.container),this.trigger("undo",this.undoable(),this.redoable()))}redo(){this.timecapsule.forwardable&&(fh(this.timecapsule.forward(),this.container),this.trigger("redo",this.undoable(),this.redoable()))}undoable(){return this.timecapsule.backwardable}redoable(){return this.timecapsule.forwardable}reset(){this.timecapsule&&this.timecapsule.reset(),this.trigger("command-reset")}}Qi(mh.prototype,Bi.withEvent);const gh="left",yh="right",bh="center",_h="bottom",vh="middle",xh="z-front",wh="z-back",Mh="z-middle",Sh=[gh,yh,bh,"top",vh,_h,xh,wh,Mh];function kh(t){if(!this.hasSameParentForAllSelected||-1===Sh.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(e.length<=1)return;const n=this.app.commander;ll.around(n,function(){!function(t,e){const n=JSON.parse(JSON.stringify(e[0].bounds));let i=n.left+n.width,s=n.top+n.height;for(let t=0;t<e.length;t++){const r=e[t].bounds;n.left=r.left>n.left?n.left:r.left,n.top=r.top>n.top?n.top:r.top,i=r.left+r.width>i?r.left+r.width:i,s=r.top+r.height>s?r.top+r.height:s}switch(n.width=i-n.left,n.height=s-n.top,t){case gh:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left,top:i.top,width:i.width,height:i.height}}break;case bh:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left+n.width/2-i.width/2,top:i.top,width:i.width,height:i.height}}break;case yh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:i-n.width,top:n.top,width:n.width,height:n.height}}break;case"top":for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top,width:i.width,height:i.height}}break;case vh:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top+n.height/2-i.height/2,width:i.width,height:i.height}}break;case _h:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:n.left,top:s-n.height,width:n.width,height:n.height}}break;case xh:{let t=1/0;for(let n=0;n<e.length;n++){const i=e[n].state.zPos||0;i<t&&(t=i)}for(let n=0;n<e.length;n++)e[n].set({zPos:t});break}case wh:{let t=-1/0;for(let n=0;n<e.length;n++){const i=(e[n].state.zPos||0)+(e[n].state.depth||0);i>t&&(t=i)}for(let n=0;n<e.length;n++){const i=e[n].state.depth||0;e[n].set({zPos:t-i})}break}case Mh:{let t=1/0,n=-1/0;for(let i=0;i<e.length;i++){const s=e[i].state.zPos||0,r=e[i].state.depth||0;s<t&&(t=s),s+r>n&&(n=s+r)}const i=(t+n)/2;for(let t=0;t<e.length;t++){const n=e[t].state.depth||0;e[t].set({zPos:i-n/2})}break}default:;}}(t,e)})}const Ah="VERTICAL",Eh=[Ah,"HORIZONTAL","Z"];function Ch(t){if(!this.hasSameParentForAllSelected||-1===Eh.indexOf(t))return;const e=this.selected;if(e.length<=1)return;const n=this.app.commander;ll.around(n,function(){!function(t,e){if("Z"===t)return void function(t){const e=t.filter(t=>!t.stuck).slice(0);e.sort((t,e)=>(t.state.zPos||0)+(t.state.depth||0)/2-((e.state.zPos||0)+(e.state.depth||0)/2));const n=e.reduce((t,e)=>t+(e.state.depth||0),0),i=e[0].state.zPos||0,s=((e[e.length-1].state.zPos||0)+(e[e.length-1].state.depth||0)-i-n)/(e.length-1);let r=i+(e[0].state.depth||0);for(let t=1;t<e.length-1;t++){const n=e[t],i=n.state.depth||0;r+=s,n.set({zPos:r}),r+=i}}(e);const n=e.filter(t=>!t.stuck).slice(0);n.sort(function(e,n){const i=e.center,s=n.center;return t===Ah?i.y-s.y:i.x-s.x});const i=n.reduce((e,n)=>e+(t===Ah?n.bounds.height:n.bounds.width),0),s=n[0].bounds,r=n[n.length-1].bounds,o=((t===Ah?r.top+r.height-s.top:r.left+r.width-s.left)-i)/(n.length-1);let a=t===Ah?s.top+s.height:s.left+s.width;for(let e=1;e<n.length-1;e++){const i=n[e],s=i.bounds;a+=o,t===Ah?(i.bounds={left:s.left,top:a,width:s.width,height:s.height},a+=s.height):(i.bounds={left:a,top:s.top,width:s.width,height:s.height},a+=s.width)}}(t,e)})}function Th(t,e,n){this.app.commander.execute(new Ol({changes:[{component:t,to_container:e,to_index:n}]}))}function Ph(t){const e=this.selected.filter(t=>!t.stuck);if(0===e.length||e[0].isRootModel())return;if(e.length>1&&("forward"===t||"backward"===t))return;const n=e[0].parent;let i;if("forward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t+1}]}else if("backward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t-1}]}else i=e.filter(t=>t.parent===n).sort((e,i)=>{const s=n.indexOf(e)<n.indexOf(i);return"front"===t?s:!s}).map((e,i)=>({component:e,to_container:n,to_index:"front"===t?n.components.length-i-1:i}));const s=new Ol({changes:i});this.app.commander.execute(s)}function Oh(t,e,n){t instanceof Array||(t=[t]),n||(n=this.model_layer);const i=[],s=new Map;this.selected=t.map(t=>{try{return zl(t,n.app,t=>{const e=this.getNewRefid();return void 0!==t&&s.set(t,e),e},t=>(this.indexMap[t]||[])[0])}catch(t){return Ji(t),!1}}).filter(Boolean).map(t=>{const{left:r,top:o,width:a,height:c,x:l,y:h,cx:d,cy:u}=e;return t.replaceRefids(s),isNaN(r)||isNaN(o)||isNaN(a)||isNaN(c)||(t.bounds={left:r,top:o,width:a,height:c}),isNaN(l)||isNaN(h)||t.move({x:l,y:h},!1),isNaN(d)||isNaN(u)||(t.center={x:d,y:u}),i.push({component:t,to_container:n}),t}),this.app.commander.execute(new Ol({changes:i}))}function Dh(){const t=[],e=new Map;if(this.selected=this.selected.filter(t=>!t.isRootModel()).map(n=>{const i=Il(n,t=>{const n=this.getNewRefid();return void 0!==t&&e.set(t,n),n});return i.move({x:20,y:20},!1),t.push({component:i,to_container:n.parent}),i}).map(t=>(t.replaceRefids(e),t)),0===t.length)return;const n=new Ol({changes:t});this.app.commander.execute(n)}function zh(){const t=this.selected;this.selected=[];let e=null;const n=t.filter(t=>!t.isRootModel()&&(t.parent.focusible||t.parent.isGroup())).map(t=>(e||(e=t.parent),{component:t,to_container:null}));for(;e&&e.isGroup();){const t=[];if(e.components.filter(t=>!n.find(e=>e.component===t)).forEach(e=>t.push(e)),t.length>1)break;const i=e.parent;t.forEach(t=>n.push({component:t,to_container:i})),n.push({component:e,to_container:null}),e=i}n.length>0&&this.app.commander.execute(new Ol({changes:n})),e&&e.calculateBounds&&e.calculateBounds()}const Ih=new Set(["execute","redo","undo","command-reset"]);function Rh(t,e,n,i){const s=function(t,e){return void 0!==e&&Ih.has(e)?t.app?.commander:"mode"===e?t.app:t}(this,e);s?.[t](e,n,i)}function jh(t,e,n){Rh.call(this,"on",t,e,n)}function Lh(t,e,n){Rh.call(this,"once",t,e,n)}function Fh(t,e,n){Rh.call(this,"off",t,e,n)}function Nh(t){const e=this.target_element,n=t||this.fitMode,i=this;function s(){i.fit(n),document.fullscreenElement||document.removeEventListener("fullscreenchange",s)}document.addEventListener("fullscreenchange",s),e.requestFullscreen().catch(()=>{document.removeEventListener("fullscreenchange",s)})}let Hh=0;function Bh(){const t=this.selected.filter(t=>!t.isRootModel()).map(t=>t.hierarchy);if(0!==t.length)return Hh=0,JSON.stringify(t,null,2)}function Gh(){Hh=0;const t=Bh.call(this);return zh.call(this),t}function Vh(t){if(t)try{Hh++,Oh.call(this,JSON.parse(t),{x:15*Hh,y:15*Hh})}catch(e){Zi(e,t)}}const Yh=function(){return{escape:function(t){return t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")},parseExtension:t,mimeType:function(e){const n=t(e).toLowerCase();return function(){const t="application/font-woff",e="image/jpeg";return{woff:t,woff2:t,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:e,jpeg:e,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}()[n]||""},dataAsUrl:function(t,e){return"data:"+e+";base64,"+t},isDataUrl:function(t){return-1!==t.search(/^(data:)/)},canvasToBlob:function(t){return t.toBlob?new Promise(function(e){t.toBlob(e)}):function(t){return new Promise(function(e){const n=window.atob(t.toDataURL().split(",")[1]),i=n.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=n.charCodeAt(t);e(new Blob([s],{type:"image/png"}))})}(t)},resolveUrl:function(t,e){const n=document.implementation.createHTMLDocument(),i=n.createElement("base");n.head.appendChild(i);const s=n.createElement("a");return n.body.appendChild(s),i.href=e,s.href=t,s.href},getAndEncode:function(t){const e=3e4;Zh.impl.options.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());return new Promise(function(n){const i=new XMLHttpRequest;let s;if(i.onreadystatechange=r,i.ontimeout=o,i.responseType="blob",i.timeout=e,i.open("GET",t,!0),i.send(),Zh.impl.options.imagePlaceholder){const t=Zh.impl.options.imagePlaceholder.split(/,/);t&&t[1]&&(s=t[1])}function r(){if(4!==i.readyState)return;if(200!==i.status)return void(s?n(s):a("cannot fetch resource: "+t+", status: "+i.status));const e=new FileReader;e.onloadend=function(){const t=e.result.split(/,/)[1];n(t)},e.readAsDataURL(i.response)}function o(){s?n(s):a("timeout of "+e+"ms occured while fetching resource: "+t)}function a(t){Zi(t),n("")}})},uid:function(){let t=0;return function(){return"u"+e()+t++;function e(){return("0000"+(Math.random()*Math.pow(36,4)|0).toString(36)).slice(-4)}}}(),delay:function(t){return function(e){return new Promise(function(n){setTimeout(function(){n(e)},t)})}},asArray:function(t){const e=[],n=t.length;for(let i=0;i<n;i++)e.push(t[i]);return e},escapeXhtml:function(t){return t.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(t){return new Promise(function(e,n){const i=new Image;i.onload=function(){e(i)},i.onerror=n,i.src=t})},width:function(t){const n=e(t,"border-left-width"),i=e(t,"border-right-width");return t.scrollWidth+n+i},height:function(t){const n=e(t,"border-top-width"),i=e(t,"border-bottom-width");return t.scrollHeight+n+i}};function t(t){const e=/\.([^\.\/]*?)$/g.exec(t);return e?e[1]:""}function e(t,e){const n=window.getComputedStyle(t).getPropertyValue(e);return parseFloat(n.replace("px",""))}}(),Wh=function(){const t=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(t,s,r){return o()?Promise.resolve(t):Promise.resolve(t).then(n).then(function(e){let n=Promise.resolve(t);return e.forEach(function(t){n=n.then(function(e){return i(e,t,s,r)})}),n});function o(){return!e(t)}},shouldProcess:e,impl:{readUrls:n,inline:i}};function e(e){return-1!==e.search(t)}function n(e){const n=[];let i;for(;null!==(i=t.exec(e));)n.push(i[1]);return n.filter(function(t){return!Yh.isDataUrl(t)})}function i(t,e,n,i){return Promise.resolve(e).then(function(t){return n?Yh.resolveUrl(t,n):t}).then(i||Yh.getAndEncode).then(function(t){return Yh.dataAsUrl(t,Yh.mimeType(e))}).then(function(n){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+Yh.escape(t)+")(['\"]?\\))","g")}(e),"$1"+n+"$3")})}}(),Uh=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(Yh.asArray(document.styleSheets)).then(function(t){const e=[];return t.forEach(function(t){try{Yh.asArray(t.cssRules||[]).forEach(t=>e.push(t))}catch(e){Ji("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 Wh.shouldProcess(t.style.getPropertyValue("src"))})}).then(function(e){return e.map(t)});function t(t){return{resolve:function(){const e=(t.parentStyleSheet||{}).href;return Wh.inlineAll(t.cssText,e)},src:function(){return t.style.getPropertyValue("src")}}}}}(),$h=function(){return{inlineAll:function e(n){return n instanceof Element?i(n).then(function(){return n instanceof HTMLImageElement?t(n).inline().then(()=>n):Promise.all(Yh.asArray(n.childNodes).map(function(t){return e(t)})).then(()=>n)}):Promise.resolve(n);function i(t){const e=t.style.getPropertyValue("background");return e?Wh.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 Yh.isDataUrl(t.src)?Promise.resolve():Promise.resolve(t.src).then(e||Yh.getAndEncode).then(function(e){return Yh.dataAsUrl(e,Yh.mimeType(t.src))}).then(function(e){return new Promise(function(n,i){t.onload=n,t.onerror=i,t.src=e})})}}}}(),Xh={imagePlaceholder:void 0,cacheBust:!1};function qh(t,e){return function(t){void 0===t.imagePlaceholder?Zh.impl.options.imagePlaceholder=Xh.imagePlaceholder:Zh.impl.options.imagePlaceholder=t.imagePlaceholder;void 0===t.cacheBust?Zh.impl.options.cacheBust=Xh.cacheBust:Zh.impl.options.cacheBust=t.cacheBust}(e=e||{}),Promise.resolve(t).then(function(t){return Qh(t,e.filter,!0)}).then(function(t){return function(t){return $h.inlineAll(t).then(function(){return t})}(t)}).then(function(t){const{bgcolor:n,width:i,height:s,style:r,sx:o=1,sy:a=1}=e||{},c=t.style;n&&(c.backgroundColor=n);i&&(c.width=i+"px");s&&(c.height=s+"px");c["margin-left"]="0px",c["margin-top"]="0px",c.transform=`rotate(0rad) translate(0px, 0px) scale(${o}, ${a}) perspective(1px)`,r&&Object.keys(r).forEach(function(t){c[t]=r[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(Yh.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||Yh.width(t),e.height||Yh.height(t))})}function Kh(t,e){return qh(t,e).then(Yh.makeImage).then(Yh.delay(100)).then(function(n){const i=function(t){const n=document.createElement("canvas");if(n.width=e.width||Yh.width(t),n.height=e.height||Yh.height(t),e.bgcolor){const t=n.getContext("2d");t.fillStyle=e.bgcolor,t.fillRect(0,0,n.width,n.height)}return n}(t);return i.getContext("2d").drawImage(n,0,0),i})}function Qh(t,e,n){return n||!e||e(t)?Promise.resolve(t).then(function(t){if(t instanceof HTMLCanvasElement)try{return Yh.makeImage(t.toDataURL()).then(t=>t)}catch(t){Ji(t)}return t.cloneNode(!1)}).then(function(n){return function(t,e,n){const i=t.childNodes;return 0===i.length?Promise.resolve(e):s(e,Yh.asArray(i),n).then(function(){return e});function s(t,e,n){let i=Promise.resolve();return e.forEach(function(e){i=i.then(function(){return Qh(e,n,!1)}).then(function(e){e&&t.appendChild(e)})}),i}}(t,n,e)}).then(function(e){return function(t,e){return e instanceof Element?Promise.resolve().then(n).then(i).then(s).then(r).then(function(){return e}):e;function n(){function n(t,e){function n(t,e){Yh.asArray(t).forEach(function(n){e.setProperty(n,t.getPropertyValue(n),t.getPropertyPriority(n))})}t.cssText?e.cssText=t.cssText:n(t,e)}n(window.getComputedStyle(t),e.style)}function i(){function n(n){const i=window.getComputedStyle(t,n),s=i.getPropertyValue("content");if(""===s||"none"===s)return;const r=Yh.uid(),o=e;o.className=o.className+" "+r;const a=document.createElement("style");function c(t,e,n){const i="."+t+":"+e,s=n.cssText?r(n):o(n);return document.createTextNode(i+"{"+s+"}");function r(t){const e=t.getPropertyValue("content");return t.cssText+" content: "+e+";"}function o(t){return Yh.asArray(t).map(e).join("; ")+";";function e(e){return e+": "+t.getPropertyValue(e)+(t.getPropertyPriority(e)?" !important":"")}}}a.appendChild(c(r,n,i)),e.appendChild(a)}[":before",":after"].forEach(function(t){n(t)})}function s(){t instanceof HTMLTextAreaElement&&e instanceof HTMLTextAreaElement&&(e.textContent=t.value),t instanceof HTMLInputElement&&e instanceof HTMLInputElement&&e.setAttribute("value",t.value)}function r(){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 Zh={toSvg:qh,toPng:function(t,e){return Kh(t,e||{}).then(function(t){return t.toDataURL()})},toJpeg:function(t,e){return Kh(t,e=e||{}).then(function(t){return t.toDataURL("image/jpeg",e.quality||1)})},toBlob:function(t,e){return Kh(t,e||{}).then(t=>Yh.canvasToBlob(t))},toPixelData:function(t,e){return Kh(t,e||{}).then(function(e){return e.getContext("2d").getImageData(0,0,Yh.width(t),Yh.height(t)).data})},impl:{fontFaces:Uh,images:$h,util:Yh,inliner:Wh,options:{}}};function Jh(t,e,n,i){const s=this.model_layer,r=s._overlay;return new Promise(function(o,a){if(s){const a=s.get("width"),c=s.get("height"),l=n||a,h=i||c,d=s.get("translate"),u=s.get("scale"),p=Math.min(l/a,h/c),f=a*p,m=c*p;s.set("translate",{x:0,y:0}),s.set("scale",{x:p/Xs,y:p/Xs});let g=Tc.createCanvas(f,m);const y=g.getContext("2d");if(s.draw(y),s.set("translate",d),s.set("scale",u),!r)return o(g.toDataURL(t,e)),void(g=null);Zh.toPng(r,{sx:p,sy:p,width:f,height:m}).then(function(n){const i=new Image;i.onload=function(){y.drawImage(i,0,0,f,m),o(g.toDataURL(t,e)),g=null},i.src=n},function(n){Zi(n),o(g.toDataURL(t,e)),g=null})}else a("No target model")})}function td(){if(!this.hasSameParentForAllSelected)return;const t=this.selected.filter(t=>!!t.parent&&!t.stuck);if(t.length<2)return;const e=t[0].parent,n=[],i=t.sort((t,n)=>e.components.indexOf(t)-e.components.indexOf(n));i.forEach(t=>{n.push(t.bounds)});const s=Tc.union(n);let r=t[0].fromParent(s.left,s.top);r=t[0].toScene(r.x,r.y);const o=new Map,a=zl({type:"group",left:r.x,top:r.y,width:s.width,height:s.height},e.app,t=>{const e=this.getNewRefid();return void 0!==t&&o.set(t,e),e});a.replaceRefids(o);const c=[{component:a,to_container:e}];i.forEach(t=>{c.push({component:t,to_container:a})}),this.app.commander.execute(new Ol({changes:c})),this.selected=[a]}function ed(){if(0===this.selected.length)return;const t=[],e=[];this.selected.forEach(n=>{if(!n.isGroup())return;const i=n.parent;n.components.forEach(n=>{t.push(n),e.push({component:n,to_container:i})}),e.push({component:n,to_container:null})}),this.app.commander.execute(new Ol({changes:e})),this.selected=t}function nd(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=Tc.union(e),i=n.left+n.width/2;t.map(t=>{t.symmetryX(i)})}function id(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=Tc.union(e),i=n.top+n.height/2;t.map(t=>{t.symmetryY(i)})}function sd(){ll.around(this.app.commander,nd,this)}function rd(){ll.around(this.app.commander,id,this)}function od(t,e,n){const i=this.findAll(t,n);return i.forEach(t=>{t.set(e)}),i}function ad(t){ll.around(this.app.commander,t)}function cd(){const t=this.indexMap;if(!t)return[];return("function"==typeof t.entries?[...t.entries()]:Object.entries(t)).flatMap(([,t])=>t.map(t=>{const{id:e,data:n}=t.model;return{key:e,value:n}})).sort((t,e)=>t.key>e.key?1:-1)}const ld="left",hd="right",dd="center",ud="bottom",pd="middle",fd=[ld,hd,dd,"top",pd,ud];function md(t){if(!this.hasSameParentForAllSelected||-1===fd.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(0===e.length)return;const n=this.app.commander;ll.around(n,function(){!function(t,e){const n=e[0].parent,{width:i,height:s}=n.bounds;switch(t){case ld:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:0}}break;case dd:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i/2-n.width/2}}break;case hd:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i-n.width}}break;case"top":for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:0}}break;case pd:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:s/2-n.height/2}}break;case ud:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:s-n.height}}break;default:;}}(t,e)})}function gd(t){t instanceof Array||(t=[t]),this.trigger("addstart",t)}function yd(t,e){return new Promise(n=>{let i=!1;const s=t=>{i||(i=!0,this.off("bulkareaselected",r),this.off("addstop",o),n(t))},r=t=>s(t),o=()=>s(null);this.on("bulkareaselected",r),this.on("addstop",o),this.trigger("addstart",[],{bulkMode:!0,template:t,boxStrokeStyle:e?.boxStrokeStyle})})}function bd(){this.trigger("stylepastestart")}function _d(){this.trigger("stylepastestop")}function vd(){this.trigger("databindpastestart")}function xd(){this.trigger("databindpastestop")}const wd={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 Md(t){if(!t)return{metalness:0,roughness:.4,emissive:"#000000",emissiveIntensity:0,opacity:1,envMapIntensity:.5,side:"double",flatShading:!1,castShadow:!0,receiveShadow:!1};const e=wd[t.preset??"default"]??wd.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",flatShading:t.flatShading??!1,castShadow:t.castShadow??!0,receiveShadow:t.receiveShadow??!1}}const Sd={double:e.DoubleSide,front:e.FrontSide,back:e.BackSide};function kd(t){return Sd[t]??e.DoubleSide}function Ad(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=kd(e.side),t.flatShading!==e.flatShading&&(t.flatShading=e.flatShading,t.needsUpdate=!0)}const Ed=new class{constructor(){this._scenes=[],this.onSceneChange=null,this._watchedComponent=null,this._watchedHandler=null,this.onWatchedComponentChange=null}setWatchedComponent(t,e=0){if(this._clearWatched(),null==t)return!0;const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s||"function"!=typeof s.on)return!1;const r=(e,n)=>{this.onWatchedComponentChange?.(t,e,n)};return s.on("change",r),this._watchedComponent=s,this._watchedHandler=r,!0}_clearWatched(){this._watchedComponent&&this._watchedHandler&&"function"==typeof this._watchedComponent.off&&this._watchedComponent.off("change",this._watchedHandler),this._watchedComponent=null,this._watchedHandler=null}register(t){this._cleanup(),this._scenes.push(new WeakRef(t)),this.onSceneChange?.(this._scenes.length)}unregister(t){this._clearWatched(),this._scenes=this._scenes.filter(e=>{const n=e.deref();return n&&n!==t}),this.onSceneChange?.(this._scenes.length)}getScenes(){return this._cleanup(),this._scenes.map((t,e)=>{const n=t.deref();if(!n)return null;const i=n.root,s=i?.model||{};return{index:e,model:{width:s.width||0,height:s.height||0,type:s.type||"unknown"}}}).filter(Boolean)}getComponentTree(t=0){const e=this._getScene(t);if(!e)return[];const n=e.rootContainer;if(!n)return[];const i=n.model_layer;return i?this._childrenOf(i):[]}getChildTree(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];let s;return s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),s?this._childrenOf(s):[]}getComponentInfo(t,e=0,n){const i=this._getScene(e);if(!i)return null;const s=i.rootContainer;if(!s)return null;let r;if(r="root"===t||"__root__"===t?s.model_layer:this._findComponent(s,t),!r)return null;const o=this._safeBounds(r),a={model:this._safeClone(r.model),state:this._safeClone(r.state),nature:r.nature||{},data:this._safeValue(r.data),value:this._safeValue(r.value),bounds:o,type:r.model?.type||"unknown",isContainer:!!r.isContainer?.(),hidden:!!r.model?.hidden};if("model-layer"===r.model?.type&&(a.is3dMode=!!r.model?.threed),n?.includeItems){const t=r._items;Array.isArray(t)&&t.length>0&&(a.items=t.map(t=>this._toTreeNode(t)))}const c=r;if("function"==typeof c.slotIds&&"function"==typeof c.occupiedSlotIds&&"function"==typeof c.emptySlotIds)try{const t=Array.from(c.slotIds()??[]).map(t=>String(t)),e=Array.from(c.occupiedSlotIds()??[]).map(t=>String(t)),n=Array.from(c.emptySlotIds()??[]).map(t=>String(t));(t.length>0||e.length>0||n.length>0)&&(a.slottedHolder={slotIds:t,occupiedSlotIds:e,emptySlotIds:n})}catch{}return a}getItems(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];const r=s._items;return Array.isArray(r)?r.map(t=>this._toTreeNode(t)):[]}getRecords(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];try{const t=s.data;return Array.isArray(t)?t:[]}catch{return[]}}selectComponent(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;if(!t||"root"===t||"__root__"===t)return i.selected=[],!0;const s=this._findComponent(i,t);return!!s&&(i.selected=[s],!0)}setComponentProperty(t,e,n,i=0){const s=this._getScene(i);if(!s)return!1;const r=s.rootContainer;if(!r)return!1;let o;if(o="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),!o)return!1;try{return o.set(e,n),!0}catch{return!1}}setCameraView(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const s=i.model_layer;if(!s||!s._threeCapability)return!1;try{return s._threeCapability.setCameraView(t),!0}catch{return!1}}getCameraState(t=0){const e=this._getScene(t);if(!e)return null;const n=e.rootContainer;if(!n)return null;const i=n.model_layer;if(!i||!i._threeCapability)return null;try{return i._threeCapability.getCameraState()}catch{return null}}toggleHidden(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const s=this._findComponent(i,t);if(!s)return!1;try{return s.set("hidden",!s.model?.hidden),!s.model?.hidden}catch{return!1}}evaluateData(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return s?this._safeValue(s.data):void 0}evaluateValue(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return s?this._safeValue(s.value):void 0}searchComponents(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s=i.model_layer;if(!s)return[];const r=[],o=t.toLowerCase();return this._traverseComponent(s,t=>{const e=t.state||t.model||{};[e.type||"",e.name||"",e.id||"",e.tag||"",e.class||"",String(e.refid||"")].join(" ").toLowerCase().includes(o)&&r.push(this._toTreeNode(t))}),r}getComponentPath(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s=i.model_layer;if(!s)return[];const r=[];return this._findPath(s,t,r)?r:[]}getThreedInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const i=n.rootContainer;if(!i)return null;let s;if(s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),!s)return null;const r=s.model||{},o=r.type||"unknown",a=r.material3d,c={is3dish:"function"==typeof s.is3dish&&s.is3dish(),type:o};a&&(c.material3d=this._safeClone(a)),c.resolved=Md(a),c.visibilityWarnings=this._materialVisibilityWarnings(s,c.resolved);const l=s?._realObject;if(l&&"object"==typeof l.materialSharing&&null!==l.materialSharing&&(c.materialSharing=this._safeClone(l.materialSharing)),"gltf-object"===o)try{c.nodeNames=s.nodeNames??[],c.animationNames=s.animationNames??[],c.nodes=this._safeClone(s.nodes),c.animations=this._safeClone(s.animations),c.fillStyleTargets=s.fillStyleTargets}catch{}return c}_materialVisibilityWarnings(t,e){const n=[],i=t?._realObject?.threeContainer;return i&&"boolean"==typeof i.hasEnvironment?(e.metalness>=.5&&!i.hasEnvironment&&n.push({code:"metal-without-environment",metalness:e.metalness,message:`metalness ${e.metalness} 인데 반사할 환경이 없다 — 고른 색과 무관하게 어둡게 나온다. 3D 컨테이너에 environment(또는 sky)를 주면 의도대로 보인다.`}),n):n}_getScene(t){this._cleanup();const e=this._scenes[t];return e?.deref()??null}_cleanup(){this._scenes=this._scenes.filter(t=>void 0!==t.deref())}_findComponent(t,e){const n=Number(e);if(!isNaN(n)){const e=t.findByRefid(n);if(e)return e}const i=t.findById(e);return i||null}_childrenOf(t){const e=Array.isArray(t.components)?t.components:[],n=Array.isArray(t._items)?t._items:[];if(0===e.length&&0===n.length)return[];const i=new Set(e),s=e.map(t=>this._toTreeNode(t));for(const t of n){if(i.has(t))continue;i.add(t);const e=this._toTreeNode(t);e.isItem=!0,s.push(e)}return s}_toTreeNode(t){const e=Array.isArray(t.components)?t.components:[],n=Array.isArray(t._items)?t._items:[],i=new Set(e);let s=0;for(const t of n)i.has(t)||(i.add(t),s++);const r=e.length+s,o=t.state||t.model||{};return{id:String(o.refid??o.id??""),type:o.type||"unknown",model_id:o.id,hasChildren:r>0,childCount:r,refid:o.refid,tag:o.tag,name:o.name,hidden:!!o.hidden,clazz:o.class}}_componentId(t){const e=t.state||t.model||{};return String(e.refid??"")}_findPath(t,e,n){const i=this._componentId(t);if(i===e)return!0;const s=t.components;if(!s)return!1;for(const r of s)if(this._findPath(r,e,n))return n.unshift("model-layer"===t.model?.type?"__root__":i),!0;return!1}_traverseComponent(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverseComponent(t,e)}_safeBounds(t){try{const e=t.bounds;return e?{left:e.left??0,top:e.top??0,width:e.width??0,height:e.height??0}:null}catch{return null}}_safeClone(t){if(!t||"object"!=typeof t)return t??{};try{return JSON.parse(JSON.stringify(t))}catch{const e={};for(const n of Object.keys(t))try{const i=t[n];if("function"==typeof i)continue;e[n]="object"==typeof i?String(i):i}catch{e[n]="[error]"}return e}}_safeValue(t){if(null==t)return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}transferLog(){try{const t=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(!t)return null;const e={};if("function"==typeof t.flows){t.flows().forEach((t,n)=>{e[n]=t})}const n={};if("function"==typeof t.targetCounts){t.targetCounts().forEach((t,e)=>{n[e]=t})}const i={};if("function"==typeof t.rejectReasonCounts){t.rejectReasonCounts().forEach((t,e)=>{i[e]=t})}return{entries:"function"==typeof t.toJSON?t.toJSON():[],stats:t.stats(),flows:e,targetCounts:n,rejectReasonCounts:i}}catch{return null}}reservations(){try{const t=globalThis.__THINGS_SCENE_RESERVATION_TABLE__,e=globalThis.__THINGS_SCENE_SIM_CLOCK__;if(!t)return null;const n=[...t.all()],i={},s={};for(const t of n)(i[t.resource]??=[]).push(t),(s[t.reserverId]??=[]).push(t);for(const t of Object.values(i))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);return{simTime:e?.now??0,all:n,byResource:i,byReserver:s}}catch{return null}}conflicts(){try{const t=globalThis.__THINGS_SCENE_RESERVATION_TABLE__,e=globalThis.__THINGS_SCENE_SIM_CLOCK__;if(!t||"function"!=typeof t.conflictLog)return null;const n=[...t.conflictLog()],i={},s={};let r=0,o=0;for(const t of n)i[t.resource]=(i[t.resource]??0)+1,s[t.proposed.reserverId]=(s[t.proposed.reserverId]??0)+1,"rejected"===t.outcome?r++:o++;return{simTime:e?.now??0,log:n,total:n.length,rejected:r,preempted:o,byResource:i,byReserver:s}}catch{return null}}contractSummary(t,e=0){const n=this._getScene(e);if(!n)return null;const i=this._findComponent(n.rootContainer,t);if(!i)return null;const s={type:i.constructor?.name??"Component",id:t};if(!0===i.isItem&&(s.isItem=!0),!0===i.isMover&&(s.isMover=!0),"function"!=typeof i.canReceive&&"function"!=typeof i.canAccept||(s.isHolder=!0),"function"==typeof i.pickupFrames)try{const t=i.pickupFrames();s.isPickable=t.length>0,s.pickupFrames=this._safeValue(t)}catch{}if("string"==typeof i.toolType&&(s.toolType=i.toolType),i.slots)try{const t="function"==typeof i.slots?i.slots():i.slots;s.slots=this._safeValue(t)}catch{}return s}getComponentCapabilities(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];const r=new Set;let o=s.constructor;for(;o&&o!==Object&&o!==Function.prototype;){const t=o.capabilities;if(Array.isArray(t))for(const e of t)"string"==typeof e&&r.add(e);o=Object.getPrototypeOf(o)}return[...r]}async componentCapabilityReports(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];const r=[];{const t=new Set;let e=s.constructor;for(;e&&e!==Object&&e!==Function.prototype;){const n=e.capabilities;if(Array.isArray(n))for(const e of n)"string"!=typeof e||t.has(e)||(t.add(e),r.push(e));e=Object.getPrototypeOf(e)}}if(0===r.length)return[];const o=s.state??{},a=[];try{const t=await Promise.resolve().then(function(){return Fm}),e=s.describeCapability;for(const n of r){const i=t.getCapabilityMeta(n);let r,c,l;if("function"==typeof e)try{r=e.call(s,n)}catch{r=void 0}if(i?.stateFields&&i.stateFields.length>0){const t={};for(const e of i.stateFields)e in o&&(t[e]=this._safeValue(o[e]));Object.keys(t).length>0&&(c=t)}if(i?.classFields&&i.classFields.length>0){const t=s.constructor,e={};for(const n of i.classFields){const i=t?.[n];void 0!==i&&(e[n]=this._safeValue(i))}Object.keys(e).length>0&&(l=e)}a.push({name:n,description:i?.description,methods:i?.methods,models:i?.models,stateFields:i?.stateFields,stateValues:c,classFields:i?.classFields,classValues:l,sourceFile:i?.sourceFile,instance:r?this._safeValue(r):void 0})}}catch{for(const t of r)a.push({name:t})}return a}async systemTopology(t=0,e){const n=this._getScene(t);if(!n)return{nodes:[],edges:[],issues:[]};const i=n.rootContainer;if(!i)return{nodes:[],edges:[],issues:[]};const s=i.model_layer;if(!s)return{nodes:[],edges:[],issues:[]};let r;try{const t=await Promise.resolve().then(function(){return Fm});r=t.getCapabilityMeta}catch{}const o=[],a=[],c=new Set;this._traverseComponent(s,t=>{const e=this._componentId(t);if(!e||c.has(e))return;if(t===s)return;c.add(e);const n=(t=>{const e=[],n=new Set;let i=t.constructor;for(;i&&i!==Object&&i!==Function.prototype;){const t=i.capabilities;if(Array.isArray(t))for(const i of t)"string"!=typeof i||n.has(i)||(n.add(i),e.push(i));i=Object.getPrototypeOf(i)}return e})(t),i=this._safeBounds(t);o.push({id:e,type:t.model?.type??t.constructor?.name??"unknown",bounds:i,capabilities:n,refid:t.model?.refid,tag:t.model?.tag,hidden:!!t.model?.hidden})});try{const t=globalThis.__operatoBuildFlowGraph;"function"==typeof t&&t(i,e)}catch{}const l=i.__flowGraph,h=l?.graph?.out,d=l?.components;if(h&&"function"==typeof h.forEach){const t=t=>{const e=d?.get(t);return e?this._componentId(e):t};h.forEach((e,n)=>{const i=t(n);for(const n of e||[])n&&a.push({source:i,target:t(n),via:"flow-graph"})})}if(r)for(const t of o)t.capabilityMeta=t.capabilities.map(t=>r(t)).filter(Boolean).map(t=>({name:t.name,description:t.description}));return{nodes:o,edges:a,issues:l?.issues??[]}}async topologyStats(t=0){const e={flows:{},utilization:{},conflicts:{},distribution:{}},n=this._getScene(t);if(!n)return e;const i=n.rootContainer;if(!i)return e;const s=i.model_layer;if(!s)return e;const r={},o={};try{const t=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(t){if("function"==typeof t.flows){t.flows().forEach((t,e)=>{r[e]=t})}if("function"==typeof t.targetCounts){t.targetCounts().forEach((t,e)=>{o[e]=t})}}}catch{}const a={},c={};this._traverseComponent(s,t=>{if(t===s)return;const e=this._componentId(t);if(!e)return;const n=t?.state?.destination;"string"==typeof n&&n.length>0&&(c[String(e)]=n);const i=t?.state?.received;let r,l;if("number"==typeof i&&i>0&&(o[String(e)]=i),t.carrierMap instanceof Map){let e=0;t.carrierMap.forEach(t=>{t&&null!=t.occupant&&e++}),r=e,l=t.carrierMap.size}else if(t.slots instanceof Map){let e=0;t.slots.forEach(t=>{t&&null!=t.occupant&&e++}),r=e,l=t.slots.size}else if(Array.isArray(t.components)){r=t.components.filter(e=>e&&e.parent===t).length;const e=t.state?.capacity??t.state?.maxCapacity;"number"==typeof e&&e>0&&(l=e)}if(void 0!==r){const t={occupied:r};void 0!==l&&l>0&&(t.capacity=l,t.ratio=r/l),a[e]=t}});const l={};try{const t=n.reservationTable;if(t&&"function"==typeof t.getRecentConflicts){const e=t.getRecentConflicts();if(Array.isArray(e))for(const t of e){const e=t?.componentId??t?.id;e&&(l[String(e)]=(l[String(e)]??0)+1)}}}catch{}const h={},d={};for(const t in o){const e=c[t],n=o[t],i={count:n};e&&(i.destination=e,d[e]||(d[e]={ids:[],total:0}),d[e].ids.push(t),d[e].total+=n),h[t]=i}for(const t in d){const e=d[t];if(0===e.total||0===e.ids.length)continue;const n=1/e.ids.length;for(const t of e.ids){const i=h[t].count/e.total;h[t].share=i,h[t].deviation=Math.min(Math.abs(i-n)/(1-n||1),1)}}return{flows:r,utilization:a,conflicts:l,distribution:h}}async carrierJourney(t,e=0){const n={carrierId:t,steps:[]};if(!this._getScene(e))return n;try{const e=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(!e)return n;const i="function"==typeof e.toJSON?e.toJSON():"function"==typeof e.entries?e.entries():[];if(!Array.isArray(i))return n;const s=i.filter(e=>{const n=e.carrierId??e.carrier?.state?.id??e.carrier?.refid;return null!=n&&String(n)===String(t)}).map(t=>({from:t.sourceId??t.source?.state?.id??t.source?.refid??null,to:t.targetId??t.target?.state?.id??t.target?.refid??null,at:t.timeline?.initiatedAt??t.timeline?.committedAt??0,phase:t.phase,slotId:t.slotId,rejectReason:t.rejectReason})).sort((t,e)=>(t.at??0)-(e.at??0));return{carrierId:t,steps:s}}catch{return n}}async activeCarrierIds(t=0,e=200){const n=this._getScene(t);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s=new Set,r=i.model_layer;r&&this._traverseComponent(r,t=>{if(t===r)return;if(s.size>=e)return;if(!(!0===t.isItem||"Carrier"===t.constructor?.name||"Carrier"===t.model?.type))return;const n=this._componentId(t);n&&s.add(n)});try{const t=i.carrierManager??i.root?.carrierManager??n.carrierManager,r=t?.carriers;if(r instanceof Map)r.forEach((t,n)=>{"string"==typeof n&&s.size<e&&s.add(n)});else if(r&&"object"==typeof r)for(const t of Object.keys(r))s.size<e&&s.add(t)}catch{}try{const t=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(t){const n="function"==typeof t.toJSON?t.toJSON():"function"==typeof t.entries?t.entries():[];if(Array.isArray(n))for(let t=n.length-1;t>=0&&s.size<e;t--){const e=n[t],i=e.carrierId??e.carrier?.state?.id??e.carrier?.refid;null!=i&&s.add(String(i))}}}catch{}return[...s]}};class Cd{constructor(){this._built=!1,this._visible=!1,this._manualOpen=!1,this._renderer=new jd}get renderer(){return this._renderer}set renderer(t){if(t===this._renderer)return;const e=this._visible;this._teardownContainer(),this._renderer=t,e&&this._show()}attach(t,e,n){this._targetElement=t,this._tracker=e,this._lagTracker=n,this._visible=!1,e&&(e.needsOverlay&&this._show(),e.onNeedsOverlay=()=>{this._visible||this._manualOpen||this._show()},e.onComplete=()=>{this._visible&&(this._update(),this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3))})}toggle(){this._visible?(this._hide(),this._manualOpen=!1):(this._manualOpen=!0,this._show())}show(){this._manualOpen=!0,this._show()}hide(){this._manualOpen=!1,this._hide()}destroy(){this._hide(),this._teardownContainer(),this._targetElement=void 0,this._tracker=void 0,this._lagTracker=void 0}get isVisible(){return this._visible}get isAttached(){return!!this._targetElement}_teardownContainer(){if(this._renderer.destroy)try{this._renderer.destroy()}catch{}this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._built=!1}get _host(){return{hide:()=>this.hide(),cancel:()=>this._cancel()}}_show(){if(this._targetElement){if(!this._container){const t=document.createElement("div");t.setAttribute("scene","loading-overlay"),t.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:9999",t.addEventListener("keydown",t=>t.stopPropagation()),this._container=t}this._built||(this._renderer.build(this._container,this._host),this._built=!0),this._container.parentElement||this._targetElement.appendChild(this._container),this._container.style.display="block",this._visible=!0,this._update(),this._updateTimer||(this._updateTimer=setInterval(()=>this._update(),500)),"complete"!==this._tracker?.phase||this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3)}}_hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._updateTimer&&(clearInterval(this._updateTimer),this._updateTimer=void 0)}_update(){this._visible&&this._tracker&&this._renderer.update(this._assembleState())}_assembleState(){const t=this._tracker;let e;if(this._lagTracker){this._lagTracker.evaluate();const t=this._lagTracker.getStats();t.sampleCount>0&&(e=t)}return{phase:t.phase,isComplete:"complete"===t.phase,stats:t.stats,phaseHistory:t.phaseHistory,pending:t.pending,entries:t.entries,lag:e}}_cancel(){if(this.hide(),this.onCancel)try{this.onCancel()}catch{}else try{window.history.back()}catch{}}}const Td={fetch:"Fetching model...",parse:"Parsing model...",init:"Initializing...",compile:"Building components...",assets:"Loading assets...",data:"Waiting for data...",render:"Rendering..."},Pd={leading:{word:"LEAD",arrow:"◂",color:"#3ddc84"},lagging:{word:"LAG",arrow:"▸",color:"#ff5a5a"},ontrack:{word:"SYNC",arrow:"≈",color:"#aab0b6"}},Od={warn:"#ff4040",critical:"#ff1f1f"};function Dd(t){const e=Math.abs(t);return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function zd(t){return`${Math.round(t).toLocaleString()}ms`}function Id(t,e){return"lagging"===t?Od[e]||Pd.lagging.color:Pd[t].color}function Rd(t,e){const n=Pd[t],i=function(t){const e=Math.round(t);return`${e>0?"+":e<0?"−":"±"}${Math.abs(e).toLocaleString()}ms`}(e);return"lagging"===t?`${n.word} ${i} ${n.arrow}`:`${n.arrow} ${n.word} ${i}`}class jd{constructor(){this._phaseRenderedCount=0}build(t,e){this._phaseRenderedCount=0;const n=document.createElement("div");n.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:320px","max-width:450px","padding:12px 16px","gap:8px"].join(";");const i=document.createElement("div");i.style.cssText="display:flex;align-items:center;justify-content:space-between";const s=document.createElement("span");s.style.cssText="font-weight:600;font-size:13px",s.textContent="Loading...",this._headerEl=s,i.appendChild(s);const r=document.createElement("button");r.textContent="✕",r.title="Close",r.style.cssText="background:none;border:none;color:rgba(255,255,255,0.6);cursor:pointer;font-size:14px;padding:2px 4px;border-radius:3px;line-height:1",r.addEventListener("mouseenter",()=>{r.style.color="rgba(255,255,255,0.9)"}),r.addEventListener("mouseleave",()=>{r.style.color="rgba(255,255,255,0.6)"}),r.addEventListener("click",()=>e.hide()),i.appendChild(r),n.appendChild(i);const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:8px";const a=document.createElement("div");a.style.cssText="flex:1;height:4px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden";const c=document.createElement("div");c.style.cssText="height:100%;width:0%;background:rgba(74,158,255,0.8);border-radius:2px;transition:width 0.3s ease",this._progressFillEl=c,a.appendChild(c),o.appendChild(a);const l=document.createElement("span");l.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;min-width:80px;text-align:right",this._progressTextEl=l,o.appendChild(l),n.appendChild(o);const h=document.createElement("div");h.style.cssText="border-top:1px solid rgba(255,255,255,0.08);padding-top:4px",this._phaseListEl=h,n.appendChild(h);const d=document.createElement("div");d.style.cssText="max-height:120px;overflow-y:auto",this._pendingListEl=d,n.appendChild(d);const u=document.createElement("div");this._lagSectionEl=u,n.appendChild(u);const p=document.createElement("div");p.style.cssText="display:flex;align-items:center;justify-content:center;border-top:1px solid rgba(255,255,255,0.08);padding-top:8px",this._footerRowEl=p;const f=document.createElement("button");f.textContent="← Cancel loading",f.title="Cancel loading and go back",f.style.cssText="background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);color:rgba(255,255,255,0.7);cursor:pointer;font-size:11px;padding:5px 12px;border-radius:4px;line-height:1",f.addEventListener("mouseenter",()=>{f.style.background="rgba(255,80,80,0.18)",f.style.color="rgba(255,255,255,0.95)"}),f.addEventListener("mouseleave",()=>{f.style.background="rgba(255,255,255,0.06)",f.style.color="rgba(255,255,255,0.7)"}),f.addEventListener("click",()=>e.cancel()),p.appendChild(f),n.appendChild(p),t.appendChild(n)}update(t){const{phase:e,isComplete:n,stats:i}=t;if(this._headerEl){const t=`${(i.elapsed/1e3).toFixed(1)}s`;this._headerEl.textContent=n?`Scene Monitor — ${t}`:`Scene Monitor — ${Td[e]||e} · ${t}`}this._footerRowEl&&(this._footerRowEl.style.display=n?"none":"flex"),this._updateProgress(t),this._updatePhaseList(t),this._updateAssetList(t),this._updateLagDisplay(t)}destroy(){this._headerEl=void 0,this._progressFillEl=void 0,this._progressTextEl=void 0,this._phaseListEl=void 0,this._pendingListEl=void 0,this._lagSectionEl=void 0,this._footerRowEl=void 0,this._phaseRenderedCount=0}_updateProgress(t){if(!this._progressFillEl&&!this._progressTextEl)return;const e=t.phaseHistory,n=e.length,i=e.filter(t=>void 0!==t.duration).length,s=n>0?Math.round(i/n*100):t.isComplete?100:0;this._progressFillEl&&(this._progressFillEl.style.width=s+"%"),this._progressTextEl&&(this._progressTextEl.textContent=`${i} / ${n}`)}_updatePhaseList(t){if(!this._phaseListEl)return;const e=t.phaseHistory;for(let t=this._phaseRenderedCount;t<e.length;t++){const n=e[t];if("complete"===n.phase)continue;const i=150*(t-this._phaseRenderedCount),s=document.createElement("div");s.dataset.phase=n.phase,s.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px;opacity:0;transition:opacity 0.3s ease",s.innerHTML='<span data-field="icon" style="flex-shrink:0"></span><span data-field="label" style="flex:1"></span><span data-field="time" style="width:60px;text-align:right"></span>',this._phaseListEl.appendChild(s),setTimeout(()=>{s.style.opacity="1"},i+16)}this._phaseRenderedCount=e.length;const n=performance.now();for(const t of Array.from(this._phaseListEl.querySelectorAll("[data-phase]"))){const i=t,s=e.find(t=>t.phase===i.dataset.phase);if(!s)continue;const r=Td[s.phase]||s.phase,o=i.querySelector('[data-field="icon"]'),a=i.querySelector('[data-field="label"]'),c=i.querySelector('[data-field="time"]');void 0===s.duration?(o.textContent="⏳",o.style.color="rgba(255,200,50,0.8)",a.textContent=r,a.style.color="rgba(255,255,255,0.9)",c.textContent=`${((n-s.timestamp)/1e3).toFixed(1)}s`,c.style.color="rgba(255,200,50,0.8)"):(o.textContent="✓",o.style.color="rgba(100,200,100,0.8)",a.textContent=r,a.style.color="rgba(255,255,255,0.5)",c.textContent=`${(s.duration/1e3).toFixed(1)}s`,c.style.color="rgba(255,255,255,0.4)")}}_updateAssetList(t){if(!this._pendingListEl)return;const{isComplete:e,stats:n}=t;if(e&&"complete"!==this._pendingListEl.dataset.mode)this._pendingListEl.innerHTML="",this._pendingListEl.dataset.mode="complete",this._renderHistorySummary(n,t.entries);else if(!e){this._pendingListEl.dataset.mode="pending";const e=t.pending.slice().sort((t,e)=>e.elapsed-t.elapsed),n=e.slice(0,5);for(let t=0;t<n.length;t++)t<this._pendingListEl.children.length?this._updatePendingRow(this._pendingListEl.children[t],n[t]):this._pendingListEl.appendChild(this._createPendingRow(n[t]));const i=n.length+(e.length>5?1:0);for(;this._pendingListEl.children.length>i;)this._pendingListEl.lastChild?.remove();if(e.length>5){const t=this._pendingListEl.lastElementChild;if(t?.dataset?.more)t.textContent=`... ${e.length-5} more`;else{const t=document.createElement("div");t.dataset.more="1",t.style.cssText="color:rgba(255,255,255,0.4);font-size:11px;padding:2px 0",t.textContent=`... ${e.length-5} more`,this._pendingListEl.appendChild(t)}}}}_updateLagDisplay(t){if(!this._lagSectionEl)return;const e=t.lag;e&&(this._lagSectionEl.dataset.built?this._updateLagSection(e):(this._lagSectionEl.innerHTML="",this._renderLagSection(e),this._lagSectionEl.dataset.built="1"))}_renderHistorySummary(t,e){if(!this._pendingListEl)return;const n=document.createElement("div");n.style.cssText="color:rgba(255,255,255,0.7);padding:2px 0;font-size:12px",n.textContent=`Total: ${t.total} assets | Loaded: ${t.loaded} | Timeout: ${t.timeout} | Error: ${t.error}`,this._pendingListEl.appendChild(n);const i=e.filter(t=>"pending"!==t.status).sort((t,e)=>e.elapsed-t.elapsed).slice(0,5);for(const t of i){const e=document.createElement("div");e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px";const n="loaded"===t.status?"✓":"timeout"===t.status?"⚠":"✗",i="loaded"===t.status?"rgba(100,200,100,0.8)":"timeout"===t.status?"rgba(255,180,50,0.8)":"rgba(255,80,80,0.8)";e.innerHTML=`<span style="color:${i}">${n}</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,this._pendingListEl.appendChild(e)}}_lagGauge(t){const{current:e,baseline:n,min:i,max:s,drift:r}=t,o=Math.max(n-i,s-n,1e3),a=t=>{return 50+50*(s=1,(e=(t-n)/o)<(i=-1)?i:e>s?s:e);var e,i,s},c=function(t){const e=Math.round(t);return e>0?"lagging":e<0?"leading":"ontrack"}(r);return{curPct:a(e),minPct:a(i),maxPct:a(s),direction:c}}_lagFill(t){return t>=50?`left:50%;width:${(t-50).toFixed(2)}%`:`left:${t.toFixed(2)}%;width:${(50-t).toFixed(2)}%`}_renderLagSection(t){if(!this._lagSectionEl)return;const e=Dd,{curPct:n,minPct:i,maxPct:s,direction:r}=this._lagGauge(t),o=Id(r,t.level),a=document.createElement("div");a.style.cssText="display:flex;align-items:baseline;gap:8px;padding:4px 0 3px;border-top:1px solid rgba(255,255,255,0.08);margin-top:4px",a.innerHTML=`<span style="color:rgba(255,255,255,0.5);font-size:11px;flex:1">Data Lag</span><span data-field="cur" style="color:rgba(255,255,255,0.5);font-size:11px">cur ${zd(t.current)}</span><span data-field="dir" style="color:${o};font-size:10px;font-weight:600;white-space:nowrap">${Rd(r,t.drift)}</span>`,this._lagSectionEl.appendChild(a);const c=(t,e)=>`<div data-field="${t}" style="position:absolute;left:${e}%;top:-1px;width:1px;height:8px;background:rgba(255,255,255,0.28);transform:translateX(-50%)"></div>`,l=document.createElement("div");l.style.cssText="position:relative;height:6px;background:rgba(255,255,255,0.08);border-radius:3px;margin:2px 0 3px",l.innerHTML='<div style="position:absolute;left:50%;top:-3px;width:1px;height:12px;background:rgba(255,255,255,0.45);transform:translateX(-50%)"></div>'+c("mintick",i)+c("maxtick",s)+`<div data-field="fill" style="position:absolute;top:50%;height:3px;transform:translateY(-50%);border-radius:2px;background:${o};opacity:0.5;${this._lagFill(n)}"></div>`+`<div data-field="dot" style="position:absolute;top:50%;width:9px;height:9px;border-radius:50%;background:${o};box-shadow:0 0 0 2px rgba(0,0,0,0.35);transform:translate(-50%,-50%);left:${n}%;transition:left 0.3s ease"></div>`,this._lagSectionEl.appendChild(l);const h=document.createElement("div");h.style.cssText="display:flex;align-items:center;font-size:10px;color:rgba(255,255,255,0.4)",h.innerHTML=`<span data-field="min" style="flex:1">min ${e(t.min)}</span><span data-field="base" style="flex:1;text-align:center;color:rgba(255,255,255,0.3)">base ${e(t.baseline)} · n ${t.sampleCount}</span><span data-field="max" style="flex:1;text-align:right">max ${e(t.max)}</span>`,this._lagSectionEl.appendChild(h)}_createPendingRow(t){const e=document.createElement("div");return e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px",e.dataset.id=t.id,e.innerHTML=`<span style="color:rgba(255,200,50,0.7)">⏳</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span data-field="url" style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span data-field="time" style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,e}_updatePendingRow(t,e){const n=t.querySelector('[data-field="url"]'),i=t.querySelector('[data-field="time"]');n&&(n.textContent=this._shortUrl(e.url)),i&&(i.textContent=`${(e.elapsed/1e3).toFixed(1)}s`)}_updateLagSection(t){if(!this._lagSectionEl)return;const e=Dd,{curPct:n,minPct:i,maxPct:s,direction:r}=this._lagGauge(t),o=Id(r,t.level),a=t=>this._lagSectionEl.querySelector(t),c=a('[data-field="cur"]');c&&(c.textContent=`cur ${zd(t.current)}`);const l=a('[data-field="dir"]');l&&(l.textContent=Rd(r,t.drift),l.style.color=o);const h=a('[data-field="dot"]');h&&(h.style.left=`${n}%`,h.style.background=o);const d=a('[data-field="fill"]');d&&(d.style.background=o,n>=50?(d.style.left="50%",d.style.width=`${(n-50).toFixed(2)}%`):(d.style.left=`${n.toFixed(2)}%`,d.style.width=`${(50-n).toFixed(2)}%`));const u=a('[data-field="mintick"]');u&&(u.style.left=`${i}%`);const p=a('[data-field="maxtick"]');p&&(p.style.left=`${s}%`);const f=a('[data-field="min"]');f&&(f.textContent=`min ${e(t.min)}`);const m=a('[data-field="base"]');m&&(m.textContent=`base ${e(t.baseline)} · n ${t.sampleCount}`);const g=a('[data-field="max"]');g&&(g.textContent=`max ${e(t.max)}`)}_shortUrl(t){if(!t)return"";const e=t.split("/");return e[e.length-1]||t}}const Ld=new WeakMap,Fd="__canonicalMaterial",Nd="base";function Hd(t){return Math.max(0,Math.round(100*t)/100)}function Bd(t){const n=[];var i;return null!=t.color&&n.push("c:"+(i=t.color,new e.Color(i).getHexString())),null!=t.opacityFactor&&Hd(t.opacityFactor)<1&&n.push("o:"+Hd(t.opacityFactor)),n.join("|")}function Gd(t,e){const n=Bd(e);if(""===n)return t;let i=Ld.get(t);i||Ld.set(t,i=new Map);let s=i.get(n);return s||(s=t.clone(),s.userData={__isVariant:!0,[Nd]:t},i.set(n,s)),function(t,e,n){if(null!=n.color&&t.color&&t.color.set(n.color),null!=n.opacityFactor){t.opacity=e.opacity*Hd(n.opacityFactor);const i=t.opacity<1||!!e.transparent;t.transparent!==i&&(t.transparent=i,t.needsUpdate=!0)}}(s,t,e),s}function Vd(t){t.traverse?.(t=>{const e=t.userData?.[Fd];e&&(t.material=e,delete t.userData[Fd])})}function Yd(t){const e=Ld.get(t);if(e){for(const t of e.values())t.dispose();Ld.delete(t)}}const Wd=.001;function Ud(t){return t&&"none"!=t&&"transparent"!=t?"string"==typeof t?p(t).getAlpha():1:0}function $d(t,e,n){const i=Ud(n);t.opacity=i,t.transparent=i<1}function Xd(t){const e=p(t);return e.isValid()?e.toHexString():t}const qd={width:1,height:1,depth:1},Kd={x:1,y:1,z:1},Qd={x:0,y:0,z:0},Zd={x:0,y:0,z:0},Jd=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap"];function tu(t){const e=t.userData;if(!e?.__bankOwned&&!e?.__isVariant){for(const e of Jd){const n=t[e];n?.dispose()}Yd(t),t.dispose()}}function eu(t){t.traverse(t=>{const e=t.userData?.dispose;if("function"==typeof e)try{e()}catch{}if(t.geometry&&!0!==t.geometry.userData?.__bankOwned&&t.geometry.dispose(),t.material){const e=Array.isArray(t.material)?t.material:[t.material];for(const t of e)tu(t)}})}function nu(t,e,n){const i=document.createElement("canvas");i.width=e,i.height=n;const s=i.getContext("2d");if(!s)return null;let r;if("radial"===t.gradientType){const i=e/2,o=n/2,a=Math.max(e,n)/2;switch(t.center){case"left-top":r=s.createRadialGradient(0,0,0,0,0,2*a);break;case"right-top":r=s.createRadialGradient(e,0,0,e,0,2*a);break;case"left-bottom":r=s.createRadialGradient(0,n,0,0,n,2*a);break;case"right-bottom":r=s.createRadialGradient(e,n,0,e,n,2*a);break;default:r=s.createRadialGradient(i,o,0,i,o,a)}}else{const i=t.rotation??0,o=e/2,a=n/2,c=Math.cos(i)*o,l=Math.sin(i)*a;r=s.createLinearGradient(o-c,a-l,o+c,a+l)}const o=Array.isArray(t.colorStops)?t.colorStops:Array.isArray(t.gradientStops)?t.gradientStops:[];for(const t of o)if(t.position>=0&&t.position<=1)try{r.addColorStop(t.position,t.color)}catch{r.addColorStop(t.position,"#fff")}return s.fillStyle=r,s.fillRect(0,0,e,n),i}function iu(t,n){n&&(!0===n.mirror&&(t.wrapS=e.RepeatWrapping,t.repeat.x=-t.repeat.x,t.offset.x=1-t.offset.x),n.rotation&&(t.center.set(.5,.5),t.rotation=n.rotation*Math.PI/180))}function su(t,n,i){const s=void 0!==n?n:t.state.fillStyle;if(!s||"object"!=typeof s)return;const r=s;if("pattern"===r.type&&r.image)return function(t,n,i){const{width:s,height:r}=t.bounds,o=Math.abs(s)||1,a=Math.abs(r)||1,c=new e.Texture;c.colorSpace=e.SRGBColorSpace;const l=new Image;"data"!==String(n.image).substring(0,4)&&(l.crossOrigin="anonymous"),l.onload=()=>{if(n.fitPattern){const t=2*o,i=2*a,s=document.createElement("canvas");s.width=t,s.height=i;const r=s.getContext("2d");if(!r)return;n.color&&(r.fillStyle=n.color,r.fillRect(0,0,t,i)),r.drawImage(l,0,0,t,i),c.image=s,c.wrapS=e.ClampToEdgeWrapping,c.wrapT=e.ClampToEdgeWrapping,c.repeat.set(1,1),c.offset.set(0,0)}else if(n.noRepeat){const t=2*o,i=2*a,s=2*(n.width||l.naturalWidth),r=2*(n.height||l.naturalHeight),h=2*(n.offsetX||0),d=2*(n.offsetY||0);let u=0,p=0;switch(n.align){case"center":u=(t-s)/2,p=(i-r)/2;break;case"left-top":break;case"left-bottom":p=i-r;break;case"right-top":u=t-s;break;case"right-bottom":u=t-s,p=i-r;break;case"left":p=(i-r)/2;break;case"right":u=t-s,p=(i-r)/2;break;case"top":u=(t-s)/2;break;case"bottom":u=(t-s)/2,p=i-r}const f=document.createElement("canvas");f.width=t,f.height=i;const m=f.getContext("2d");if(!m)return;n.color&&(m.fillStyle=n.color,m.fillRect(0,0,t,i)),m.drawImage(l,0,0,l.naturalWidth,l.naturalHeight,h+u,d+p,s,r),c.image=f,c.wrapS=e.ClampToEdgeWrapping,c.wrapT=e.ClampToEdgeWrapping,c.repeat.set(1,1),c.offset.set(0,0)}else{const t=n.width||l.naturalWidth,i=n.height||l.naturalHeight,s=2*t,r=2*i,h=document.createElement("canvas");h.width=s,h.height=r;const d=h.getContext("2d");if(!d)return;n.color&&(d.fillStyle=n.color,d.fillRect(0,0,s,r)),d.drawImage(l,0,0,s,r);let u=0,p=0;switch(n.align){case"center":u=(o-t)/2,p=(a-i)/2;break;case"left-top":break;case"left-bottom":p=a-i;break;case"right-top":u=o-t;break;case"right-bottom":u=o-t,p=a-i;break;case"left":p=(a-i)/2;break;case"right":u=o-t,p=(a-i)/2;break;case"top":u=(o-t)/2;break;case"bottom":u=(o-t)/2,p=a-i}const f=(n.offsetX||0)+u,m=(n.offsetY||0)+p;c.image=h,c.wrapS=e.RepeatWrapping,c.wrapT=e.RepeatWrapping,c.repeat.set(o/t,a/i),c.offset.set(-f/t,m/i)}c.minFilter=e.LinearFilter,iu(c,i),c.needsUpdate=!0,t.invalidate()},l.onerror=t=>{Zi("Pattern texture load error:",t)};const h=n.image;l.src=t.app.url(h);const d=t.root?.app?.loadTracker;if(d){const t=new Promise((t,e)=>{l.addEventListener("load",()=>t(),{once:!0}),l.addEventListener("error",()=>e(),{once:!0})});d.track(`pattern:${h}`,"pattern",h,t)}return c}(t,r,i);if("gradient"===r.type){if(Array.isArray(r.colorStops)&&r.colorStops.length>0||Array.isArray(r.gradientStops)&&r.gradientStops.length>0){const t=function(t){const n=nu(t,256,256);if(!n)return;const i=new e.CanvasTexture(n);return i.colorSpace=e.SRGBColorSpace,i.needsUpdate=!0,i}(r);return t&&iu(t,i),t}}}const ru={policy:"state-driven"};function ou(t){return"state-driven"===t.policy}const au={BACKDROP:4,FLOOR:2,OBJECTS:0,DECAL:-1,OUTLINE:-4};function cu(t){return t&&Number.isFinite(t)?{enabled:!0,factor:t,units:t}:{enabled:!1,factor:0,units:0}}function lu(t,e){const n=cu(e);t.traverse(t=>{const e=t;if(!e.isMesh&&!t.isLine&&!t.isPoints)return;const i=e.material;if(i)if(Array.isArray(i))for(const t of i)hu(t,n);else hu(i,n)})}function hu(t,e){t.polygonOffset=e.enabled,t.polygonOffsetFactor=e.factor,t.polygonOffsetUnits=e.units,t.needsUpdate=!0}function du(t,e){return-1!==t.findIndex(t=>t in e)}const uu=()=>{};class pu{static buildFillStyleTexture(t,e,n){return su(t,e,n)}constructor(t){this._focused=!1,this._suppressOnchange=!1,this._onchangeWrapper=(t,e,n)=>{this._suppressOnchange||n&&n.origin&&n.origin!==this._component||this.onchange(t,e)},this.suppressTransform=!1,this._dimensionScale={x:1,y:1,z:1},this._component=t,this.object3d=this.getObject3dInstance(),this.component.on("change",this._onchangeWrapper)}update(){this.clear(),this.build(),this.updateTransform(),this.updateFillStyle(),this.updateStrokeStyle(),this.updateAlpha(),this.applyFocusDim(),this.updateHidden(),this.updateText(),this._applyZPriority(),this._applyRaycastTarget()}_applyZPriority(){const t=this.component.state?.zPriority,e="number"==typeof t&&Number.isFinite(t)?t:this.zPriority;0!==e&&lu(this.object3d,e)}get zPriority(){return au.OBJECTS}getObject3dInstance(){return new e.Object3D}build(){this.object3d.userData.context=this;const t=Md(this.component.state.material3d),{cast:e,receive:n}=this.resolveShadow(t.castShadow,t.receiveShadow);this._applyShadow(e,n),this.object3d.name=this.component.state.id}updateMaterial3d(){const t=Md(this.component.state.material3d),{cast:e,receive:n}=this.resolveShadow(t.castShadow,t.receiveShadow);this._applyShadow(e,n)}resolveShadow(t=!0,e=!1){return{cast:t,receive:e}}_applyShadow(t,e){const n=i=>{i.castShadow=t,i.receiveShadow=e;for(const t of i.children){const e=t.userData?.context;e&&e!==this||n(t)}};n(this.object3d)}get gizmoTransformable(){return!0}get allowedGizmoModes(){return null}get component(){return this._component}get threeContainer(){let t=this.component;for(;t;){if("is3dContainer"in t&&t.is3dContainer())return t;t=t.parent}}get focused(){return this._focused}set focused(t){this._focused=t,t&&(this._focusedAt=performance.now())}dispose(){this.component.off("change",this._onchangeWrapper),this.clear()}clear(){const t=[];for(const e of this.object3d.children){const n=e.userData?.context;n&&n!==this&&n instanceof pu?t.push(e):(Vd(e),eu(e))}this._components3D=void 0,this.object3d.userData={},this.object3d.clear();for(const e of t)this.object3d.add(e);return this.object3d}get placement(){return this._transientPlacement??ru}setTransientPlacement(t){this._transientPlacement=t}clearTransientPlacement(){this._transientPlacement=void 0}layoutHeldItems(){const t=this.component,e=t?._items??[];if(0===e.length||"function"!=typeof t.placementFor)return;const n=new Set((t.slots??[]).map(t=>t?.id));let i=0;for(const s of e){const e=s?._transferSlotId;if(null!=e&&n.has(e))continue;const r=s?._realObject?.object3d;if(!r){i++;continue}const o=t.placementFor(s,{index:i,occupantCount:i});i++,o?.position&&(r.parent!==this.object3d&&this.object3d.attach(r),r.position.set(o.position.x,o.position.y,o.position.z),o.rotation?r.quaternion.set(o.rotation.x,o.rotation.y,o.rotation.z,o.rotation.w):r.quaternion.identity())}}updateTransform(){if(this.suppressTransform)return;if(!ou(this.placement))return;if(this.component.state.screenFixed&&this.component.isHTMLElement()){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{};return this.object3d.position.set(t-n/2,-(e-i/2),0),void this.object3d.rotation.set(0,0,0)}const{x:t,y:e,z:n}=this.position,{x:i,y:s,z:r}=this.rotation,{x:o,y:a,z:c}=this.scale;this.object3d.position.set(t,e,n),this.object3d.rotation.set(i,s,r),this.applyScale(o,a,c)}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 t=this.effectiveZPos,{tz:e=0}=this.component.delta(),n=this.component.parent?._realObject,i=n?.geometricOffsetY??0,s=n?.receivingSurfaceY??0;return t+e+this.syncZPosOffset-i+s}get receivingSurfaceY(){return 0}surfaceAtLocalY(t){return t+this.geometricOffsetY}placementSurfaceY(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return this.surfaceAtLocalY(0);case"inverted":return this.surfaceAtLocalY(-t);default:return this.surfaceAtLocalY(t)}}get effectiveZPos(){const t=this.component.state.zPos;if("number"==typeof t&&Number.isFinite(t))return t;const e=this.component.effectiveZPos;return"number"==typeof e&&Number.isFinite(e)?e:0}get geometricOffsetY(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get scenePlacement(){const t=this.component.rootModel??this.component,e=t?.state?.placement;return"space"===e||"inverted"===e?e:"floor"}get placementMode(){return this.scenePlacement}get components3D(){return this._components3D&&this._components3D.parent===this.object3d||(this._components3D=new e.Group,this.object3d.add(this._components3D)),this._components3D.position.y=-this.geometricOffsetY,this._components3D}get center(){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{},{tx:s=0,ty:r=0}=this.component.delta();return{x:t+s-n/2,y:e+r-i/2,z:this.cz}}freezeDimension(){this._frozenDimension={...this.dimension}}unfreezeDimension(){delete this._frozenDimension}get dimension(){if(this._frozenDimension)return this._frozenDimension;const{width:t,height:e}=this.component.bounds;return{width:Math.abs(t)||1,height:Math.abs(e)||1,depth:this.effectiveDepth}}get effectiveDepth(){const t=this.component.state.depth;if("number"==typeof t&&Number.isFinite(t)&&t>0)return t;const e=this.component.effectiveDepth;return"number"==typeof e&&Number.isFinite(e)&&e>0?e: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)}get dimensionScale(){return this._dimensionScale}setDimensionScale(t,e,n){Number.isFinite(t)&&Number.isFinite(e)&&Number.isFinite(n)&&(this._dimensionScale={x:t,y:e,z:n},this.updateScale())}applyScale(t,e,n){const i=this._dimensionScale;this.object3d.scale.set(Math.max(t*i.x,Wd),Math.max(e*i.y,Wd),Math.max(n*i.z,Wd))}updateScale(){const{x:t=1,y:e=1,z:n=1}=this.scale;this.applyScale(t,e,n)}syncAnimationDelta(){if(this.suppressTransform)return;const t=this.component.delta();this.updatePosition();const{rotationX:e=0,rotationY:n=0,rotation:i=0}=this.component.state,s=t.theta||0,r=t.rx||0,o=t.ry||0,a=t.rz||0;this.object3d.rotation.set(e+r,-(i+s)+o,n+a);const{scale:c}=this.component.state,l="number"==typeof c?c:c?.x??1,h=t.sx??1,d=t.sy??1,u=t.sz??1;this.applyScale(l*h,l*d,l*u);const p=t.fade||0;if(0!==p){const t=(this.component.state.alpha??1)*(1-p);this.object3d.traverse(e=>{if(e.isMesh&&e.material){const n=Array.isArray(e.material)?e.material:[e.material];for(const e of n)e.opacity=t,e.transparent=e.opacity<1}})}}updateDimension(){this.clear(),this.build()}updateAlpha(){this.applyMaterialOpacity()}isModelingFaint(){return zo(this.component)}applyMaterialOpacity(){const t=this.component.state.alpha,e=null==t?1:t,n=this.isModelingFaint(),i=t=>{t.material&&function(t,e,n){if(!t.material)return;let i=t.userData[Fd];i||(i=t.material,t.userData[Fd]=i);const s=t=>{const i=t?.userData?.[Nd]??t;return n?Gd(i,{opacityFactor:.5}):e<1?Gd(i,{color:t.color,opacityFactor:e}):t};t.material=Array.isArray(i)?i.map(s):s(i)}(t,e,n);for(const e of t.children){const t=e.userData?.context;t&&t!==this&&t instanceof pu||i(e)}};i(this.object3d)}applyFocusDim(){this.applyMaterialOpacity()}updateHidden(){const t=this.component.app;if(t?.isEditMode)return this.object3d.visible=!0,void this.applyFocusDim();this.object3d.visible=!this.component.state.hidden}updateStrokeStyle(){}updateFillStyle(){}updateText(){}topOutline(){return null}_applyRaycastTarget(){const t=this.component.state.raycastTarget;let e;if("boolean"==typeof t)e=t;else{const t=this.component.constructor;e=!1!==t.raycastTargetDefault}const n=t=>{const i=t.userData?.context;if(t===this.object3d||!i||i===this){t.userData?.alwaysRaycast||(e?delete t.raycast:t.raycast=uu);for(const e of t.children)n(e)}};n(this.object3d)}get syncZPosOffset(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get textSurfaceYOffset(){return this.effectiveDepth-this.syncZPosOffset}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},s=e.bounds,{tx:r=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0,e.bounds={left:t.position.x-r+n/2-s.width/2,top:t.position.z-o+i/2-s.height/2,width:s.width,height:s.height};const c=this.component.parent?._realObject,l=c?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+l,rotationX:t.rotation.x,rotation:-t.rotation.y,rotationY:t.rotation.z}),this._suppressOnchange=!1}onGizmoDragEnd(t){}applyDimensionFromGizmo(t){this._suppressOnchange=!0,this._component.set(t),this._suppressOnchange=!1}onchange(t,e){if("screenFixed"in t&&this.updateTransform(),du(["cx","cy","cz","zPos","left","top"],t)&&!this.suppressTransform&&ou(this.placement)&&this.updatePosition(),du(["width","height","depth","lineWidth","round","rx","ry","rz"],t)&&(this.updateDimension(),"depth"in t)){this.updatePosition();const t=this.component.components;if(t)for(const e of t){const t=e?._realObject;t?.updateTransform&&t.updateTransform()}}if(du(["segments","heightSegments"],t)&&this.update(),du(["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(),du(["text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline"],t))this._lastText=this.component.hasTextProperty?this.component.text:"",this.updateText();else if(du(["value","data"],t)){const t=this.component.hasTextProperty?this.component.text:"";t!==this._lastText&&(this._lastText=t,this.updateText())}"material3d"in t&&this.updateMaterial3d(),"raycastTarget"in t&&this._applyRaycastTarget()}}function fu(t){if(!t||"object"!=typeof t)return!1;const e=t;return"function"==typeof e.partNames&&"function"==typeof e.partObject&&"function"==typeof e.partAt}function mu(t,e){for(let n=t;n;n=n.parent){if(e.get(n.name)===n)return n.name}}class gu extends pu{constructor(){super(...arguments),this._loadGen=0,this._objectSize=new e.Vector3}get objectSize(){return this._objectSize}build(){super.build();const{src:t}=this.component.state;if(!t)return this.clear(),this._showEmptyPlaceholder(),void(this.object3d.userData.context=this);const e=++this._loadGen,n=this.component.app.url(t),i=this._loadExternal(n).then(t=>{e===this._loadGen&&this._onLoaded(t)},t=>{e===this._loadGen&&(Zi(`${this._formatLabel}.load`,t),this.clear(),this._showErrorPlaceholder(),this.component.setState({loadError:String(t)}))});this.component.root?.app?.loadTracker?.track(`${this._formatLabel}:${t}`,this._formatLabel,t,i)}updateSource(){this.build()}get _placeholderColor(){return 6770852}_showEmptyPlaceholder(){const{width:t=100,height:n=100,depth:i=100}=this.component.state,s=t||100,r=n||100,o=i||100,a=this._placeholderColor,c=new e.BoxGeometry(s,o,r),l=new e.MeshStandardMaterial({color:a,transparent:!0,opacity:.15,depthWrite:!1}),h=new e.Mesh(c,l);h.name="__empty_placeholder__";const d=new e.EdgesGeometry(c),u=new e.LineBasicMaterial({color:a,transparent:!0,opacity:.4}),p=new e.LineSegments(d,u);p.name="__empty_placeholder_edge__",h.add(p),this.object3d.add(h)}_showErrorPlaceholder(){const t=new e.BoxGeometry(1,1,1),n=new e.MeshStandardMaterial({color:13369344,wireframe:!0}),i=new e.Mesh(t,n);i.name="__error_placeholder__",this.object3d.add(i)}clear(){return this.pivot&&eu(this.pivot),this.pivot=void 0,this._objectSize=void 0,super.clear()}}const yu="KHR_materials_pbrSpecularGlossiness";class bu{constructor(t){this.name=yu,this.parser=t}extendMaterialParams(t,e){const r=this.parser.json.materials?.[t],o=r?.extensions?.[yu];if(!o)return Promise.resolve();const a=[];if(Array.isArray(o.diffuseFactor)){const[t,s,r,a]=o.diffuseFactor;e.color||(e.color=new n),e.color.setRGB(t,s,r,i),e.opacity=a}null!=o.diffuseTexture&&a.push(this.parser.assignTexture(e,"map",o.diffuseTexture,s));const c=o.glossinessFactor??1;e.roughness=1-c;const l=o.specularFactor??[1,1,1],h=Math.max(l[0],l[1],l[2]);return e.metalness=h>.5?h:0,Promise.all(a)}}(()=>{const t="__urdfBlobCrossOriginPatched__",n=e.ImageLoader.prototype;if(n[t])return;const i=n.load;n.load=function(t,e,n,s){if("string"==typeof t&&t.startsWith("blob:")){const r=this.crossOrigin;this.crossOrigin=void 0;try{return i.call(this,t,e,n,s)}finally{this.crossOrigin=r}}return i.call(this,t,e,n,s)},n[t]=!0})();const _u={once:e.LoopOnce,repeat:e.LoopRepeat,pingpong:e.LoopPingPong};class vu extends gu{constructor(){super(...arguments),this._nodeIndex=new Map,this._originals=new Map,this._animationActions=new Map,this._fillStyleOriginals=new Map,this._clonedMaterials=new WeakSet}get _formatLabel(){return"gltf"}static getSharedSnapshotRenderer(){const t=vu._sharedSnapshotRenderer;if(t){const e=t.getContext();if(e&&!e.isContextLost())return t;try{t.forceContextLoss()}catch{}t.dispose(),vu._sharedSnapshotRenderer=void 0}try{const t=new e.WebGLRenderer({antialias:!0,alpha:!0}),n=t.getContext();if(!n||n.isContextLost()){try{t.forceContextLoss()}catch{}return void t.dispose()}return vu._sharedSnapshotRenderer=t,t}catch{return}}static getSharedLoader(t){if(!vu._sharedLoader){const t=new f;!function(t){t.register(t=>new bu(t))}(t);const e=new m;e.setDecoderPath("/node_modules/three/examples/jsm/libs/draco/"),t.setDRACOLoader(e);const n=new g;n.setTranscoderPath("/node_modules/three/examples/jsm/libs/basis/"),t.setKTX2Loader(n),t.setMeshoptDecoder(y),t.setCrossOrigin("anonymous"),vu._sharedLoader=t}return t&&vu._sharedLoader.ktx2Loader?.detectSupport(t),vu._sharedLoader}static loadGLTF(t,e){let n=vu._gltfCache.get(t);if(!n){const i=vu.getSharedLoader(e);n=new Promise((e,n)=>{i.load(t,e,void 0,n)}).catch(e=>{throw vu._gltfCache.delete(t),e}),vu._gltfCache.set(t,n)}return n}_ensureOwnMaterial(t){let e=t.material;return this._clonedMaterials.has(e)||(e=e.clone(),t.material=e,this._clonedMaterials.add(e)),e}_loadExternal(t){return vu.loadGLTF(t,this.threeContainer?.renderer3d)}_onLoaded(t){this.component.state.loadError&&this.component.setState({loadError:void 0});const n=t.scene,i=t.animations,s=b(n);s.userData.context=this,s.traverse(t=>{t.isMesh&&(t.castShadow=!0)});const r=(new e.Box3).setFromObject(s),o=r.getCenter(s.position),a=r.getSize(new e.Vector3);if(o.multiplyScalar(-1),this.clear(),this.object3d.userData.context=this,this._objectSize=a,this.pivot=new e.Object3D,this.component.state.floorAlign?this.components3D.add(this.pivot):this.object3d.add(this.pivot),this.pivot.add(s),this._buildNodeIndex(s),this.component.state.autoFit&&a.x>0&&a.y>0&&a.z>0){const t=(Number(this.component.state.autoFitSize)>0?Number(this.component.state.autoFitSize):200)/Math.max(a.x,a.y,a.z),e=Math.max(1,Math.round(a.x*t)),n=Math.max(1,Math.round(a.y*t)),i=Math.max(1,Math.round(a.z*t)),s=this.component;s._ratioLocking=!0;try{this.component.set({width:e,height:i,depth:n,autoFit:!1})}finally{s._ratioLocking=!1}}if(this.updateDimension(),this.component.state.floorAlign){const t=this.scenePlacement;if("space"!==t){this.components3D.updateMatrixWorld(!0);const n=(new e.Box3).setFromObject(this.pivot);if(isFinite(n.min.y)&&isFinite(n.max.y))if("inverted"===t){const t=this.components3D.worldToLocal(n.max.clone());t.y>0&&(this.pivot.position.y-=t.y)}else{const t=this.components3D.worldToLocal(n.min.clone());t.y<0&&(this.pivot.position.y-=t.y)}}}i&&i.length&&this._setupAnimations(i);const c=this.component.state.nodes;c&&this._applyNodeStates(c),this.updateFillStyle()}static renderTopView(t){const n=256,i=new e.Scene,s=t.parent;i.add(t);const r=new e.AmbientLight(16777215,.8);i.add(r);const o=new e.DirectionalLight(16777215,1);o.position.set(0,10,0),i.add(o);const a=(new e.Box3).setFromObject(t),c=a.getSize(new e.Vector3),l=a.getCenter(new e.Vector3),h=(c.x||1)/2*1.02,d=(c.z||1)/2*1.02,u=new e.OrthographicCamera(-h,h,d,-d,.01,10*c.y+1);u.position.set(l.x,a.max.y+c.y,l.z),u.lookAt(l.x,l.y,l.z);const p=h/d,f=p>=1?n:Math.round(n*p),m=p>=1?Math.round(n/p):n,g=vu.getSharedSnapshotRenderer();if(!g){s?s.add(t):i.remove(t);const e=document.createElement("canvas");return e.width=f,e.height=m,e}g.setClearColor(0,0),g.setSize(f,m),g.render(i,u),s?s.add(t):i.remove(t);const y=document.createElement("canvas");y.width=f,y.height=m;const b=y.getContext("2d");return b&&b.drawImage(g.domElement,0,0),y}static getTopViewCache(t){return vu._topViewCache.get(t)}static setTopViewCache(t,e){vu._topViewCache.set(t,e)}static flushCache(){if(vu._gltfCache.clear(),vu._topViewCache.clear(),vu._sharedSnapshotRenderer){try{vu._sharedSnapshotRenderer.forceContextLoss()}catch{}vu._sharedSnapshotRenderer.dispose(),vu._sharedSnapshotRenderer=void 0}}_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())}partNames(){return this.nodeNames}partObject(t){return this._nodeIndex.get(t)}partAt(t){return mu(t,this._nodeIndex)}_applyNodeStates(t){for(const[e,n]of Object.entries(t)){const t=this._nodeIndex.get(e);if(t&&(void 0!==n.visible&&(t.visible=n.visible),void 0!==n.scale&&t.scale.setScalar(n.scale),t.isMesh)){const e=t;if(!(void 0!==n.color||void 0!==n.opacity||void 0!==n.emissive||void 0!==n.emissiveIntensity))continue;const i=this._ensureOwnMaterial(e);void 0!==n.color&&i.color.set(n.color),void 0!==n.opacity&&(i.opacity=n.opacity,i.transparent=n.opacity<1),void 0!==n.emissive&&i.emissive.set(n.emissive),void 0!==n.emissiveIntensity&&(i.emissiveIntensity=n.emissiveIntensity)}}}_resetNode(t){const e=this._nodeIndex.get(t),n=this._originals.get(t);if(e&&n&&(e.visible=n.visible,e.scale.copy(n.scale),e.isMesh)){const t=e.material;t&&n.color&&(t.color.copy(n.color),t.opacity=n.opacity,t.transparent=n.transparent,t.emissive.copy(n.emissive),t.emissiveIntensity=n.emissiveIntensity)}}_resetAllNodes(){for(const t of this._originals.keys())this._resetNode(t)}_setupAnimations(t){const e=this.threeContainer.mixer;this._animationActions.clear();for(const n of t){const t=e.clipAction(n);this._animationActions.set(n.name,t)}!1!==this.component.state.play&&this._playTargetAnimations();const n=this.component.state.animations;n&&this._applyAnimationStates(n)}_playTargetAnimations(){const t=this.component.state.playTargets;if("*"===t)this._animationActions.forEach(t=>t.play());else if(Array.isArray(t)&&t.length>0)for(const e of t)this._animationActions.get(e)?.play()}_applyAnimationStates(t){for(const[n,i]of Object.entries(t)){const t=this._animationActions.get(n);t&&(void 0!==i.loop&&(t.loop=_u[i.loop]??e.LoopRepeat,"once"===i.loop&&(t.clampWhenFinished=!0)),void 0!==i.speed&&(t.timeScale=i.speed),void 0!==i.weight&&(t.weight=i.weight),void 0!==i.play&&(i.play?t.play():t.stop()))}}get animationNames(){return Array.from(this._animationActions.keys())}updateFillStyle(){const{fillStyle:t}=this.component.state;if(!t)return;const e=this.component.state.fillStyleTargets;let n;if("*"===e)n=[...this._nodeIndex.entries()].filter(([,t])=>t.isMesh).map(([t])=>t);else{if(!(Array.isArray(e)&&e.length>0))return;n=e}if(0===n.length)return;const i=pu.buildFillStyleTexture(this.component);for(const e of n){const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const s=this._ensureOwnMaterial(n);s&&(this._fillStyleOriginals.has(e)||this._fillStyleOriginals.set(e,{color:s.color.clone(),map:s.map,opacity:s.opacity,transparent:s.transparent}),i?(s.map&&s.map!==this._fillStyleOriginals.get(e)?.map&&s.map.dispose(),i.needsUpdate=!0,s.map=i):"string"==typeof t&&("transparent"!==t?s.color.set(t):(s.opacity=0,s.transparent=!0)))}}_restoreFillStyleTargets(t){for(const e of t){const t=this._fillStyleOriginals.get(e);if(!t)continue;const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const i=n.material;i&&(i.map&&i.map!==t.map&&i.map.dispose(),i.color.copy(t.color),i.map=t.map,i.opacity=t.opacity,i.transparent=t.transparent,this._fillStyleOriginals.delete(e))}}clear(){return this._animationActions.forEach(t=>t.stop()),this._animationActions.clear(),this._nodeIndex.clear(),this._originals.clear(),this._fillStyleOriginals.clear(),super.clear()}updateDimension(){const{width:t=1,height:e=1,depth:n=1}=this.component.state,{x:i=1,y:s=1,z:r=1}=this.objectSize||{};this.pivot&&this.pivot.scale.set(t/i,n/s,e/r),this.component.invalidate()}onchange(t,e){if(super.onchange(t,e),("src"in t||"floorAlign"in t)&&this.updateSource(),"nodes"in t){this._resetAllNodes();const e=t.nodes;e&&Object.keys(e).length>0&&this._applyNodeStates(e)}if("animations"in t){const e=t.animations;e&&this._applyAnimationStates(e)}if("fillStyleTargets"in t){const t=[...this._fillStyleOriginals.keys()];t.length>0&&this._restoreFillStyleTargets(t),this.updateFillStyle()}("play"in t||"playTargets"in t)&&(this._animationActions.forEach(t=>t.stop()),!1!==this.component.state.play&&this._playTargetAnimations())}}vu._topViewCache=new Map,vu._gltfCache=new Map,vu._sharedLoader=null;let xu=!0;function wu(){return xu}function Mu(t){xu=t}const Su=["id","name","tag","type","class","text","data","property"];class ku{constructor(){this._results=[],this._currentIndex=-1}get results(){return this._results}get currentIndex(){return this._currentIndex}get currentResult(){return this._results[this._currentIndex]}get resultCount(){return this._results.length}search(t,e,n){if(this._results=[],this._currentIndex=-1,!e||!t)return this._results;const i=n?.fields||Su,s=n?.caseSensitive??!1,r=n?.includeHidden??!1,o=n?.maxResults??1/0,a=s?e:e.toLowerCase(),c=new Set;return this._traverse(t,t=>{if(c.has(t))return;if(this._results.length>=o)return;if(!r&&t.state.hidden)return;const e=this._matchComponent(t,a,i,s);e&&(c.add(t),this._results.push(e))}),this._results.length>0&&(this._currentIndex=0),this._results}navigateNext(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex+1)%this._results.length,this._results[this._currentIndex]}navigatePrev(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex-1+this._results.length)%this._results.length,this._results[this._currentIndex]}navigateTo(t){if(!(t<0||t>=this._results.length))return this._currentIndex=t,this._results[this._currentIndex]}clear(){this._results=[],this._currentIndex=-1}_traverse(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverse(t,e)}_matchComponent(t,e,n,i){const s=t.state,r=t=>{if(!t)return!1;return(i?t:t.toLowerCase()).includes(e)};for(const o of n)switch(o){case"id":if(r(s.id))return{component:t,matchType:"id",matchField:"id",matchValue:s.id};break;case"name":if(r(s.name))return{component:t,matchType:"name",matchField:"name",matchValue:s.name};break;case"tag":if(r(s.tag))return{component:t,matchType:"tag",matchField:"tag",matchValue:s.tag};break;case"type":if(r(s.type))return{component:t,matchType:"type",matchField:"type",matchValue:s.type};break;case"class":if(r(s.class))return{component:t,matchType:"class",matchField:"class",matchValue:s.class};break;case"text":if(r(s.text))return{component:t,matchType:"text",matchField:"text",matchValue:s.text};break;case"data":{const n=this._matchDataBinding(t,e,i);if(n)return n;break}case"property":{const n=this._matchProperties(t,e,i);if(n)return n;break}}return null}_matchDataBinding(t,e,n){const i=t._model,s=i?.mappings;if(!s||!Array.isArray(s))return null;const r=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)};for(const e of s){if(r(e.accessor))return{component:t,matchType:"data",matchField:"accessor",matchValue:e.accessor};if(r(e.target))return{component:t,matchType:"data",matchField:"target",matchValue:e.target};if(r(e.property))return{component:t,matchType:"data",matchField:"property",matchValue:e.property};if(r(e.source))return{component:t,matchType:"data",matchField:"source",matchValue:e.source}}return null}_matchProperties(t,e,n){const i=t.state,s=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)},r=["ref","src","value","action"];for(const e of r){const n=i[e];if("string"==typeof n&&s(n))return{component:t,matchType:"property",matchField:e,matchValue:n}}const o=i.fillStyle;if(o){if("string"==typeof o&&s(o))return{component:t,matchType:"property",matchField:"fillStyle",matchValue:o};if("object"==typeof o&&"pattern"===o.type&&"string"==typeof o.image&&s(o.image))return{component:t,matchType:"property",matchField:"fillStyle.image",matchValue:o.image}}return null}}const Au={id:"ID",name:"Name",tag:"Tag",type:"Type",class:"Class",text:"Text",data:"Data",property:"Prop"};class Eu{constructor(){this._engine=new ku,this._visible=!1,this._queryHistory=[],this._historyIndex=-1,this._savedInput=""}get isVisible(){return this._visible}get engine(){return this._engine}setup(t){this.destroy(),this._host=t}toggle(){this._visible?this._input&&document.activeElement!==this._input?(this._input.focus(),this._input.select()):this.hide():this.show()}show(){this._host?.element&&(this._container||this._buildDOM(),this._container&&!this._container.parentElement&&this._host.element.appendChild(this._container),this._container.style.display="flex",this._visible=!0,requestAnimationFrame(()=>{this._input?.focus(),this._input?.select()}))}hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._historyIndex=-1,this._clearHighlight(),this._engine.clear(),this._updateStatus(),this._hideResultList(),this._isEditMode()||(this._host?.root?.trigger?.("search-close",{}),this._invokeViewClose())}destroy(){this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._input=void 0,this._statusEl=void 0,this._resultListEl=void 0,this._host=void 0,this._visible=!1,this._engine.clear()}_buildDOM(){const t=this._host,e=document.createElement("div");e.setAttribute("scene","search-overlay"),["click","dblclick","mousedown","mouseup","mousemove","pointerdown","pointerup","pointermove","wheel","contextmenu","touchstart","touchmove","touchend"].forEach(t=>e.addEventListener(t,t=>t.stopPropagation())),e.style.cssText=["position:absolute","top:8px","left:50%","transform:translateX(-50%)","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none","z-index:10000",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:280px","max-width:400px"].join(";");const n=document.createElement("div");n.style.cssText="display:flex;align-items:center;padding:6px 8px;gap:6px";const i=document.createElement("span");i.textContent="🔍",i.style.cssText="font-size:14px;flex-shrink:0;opacity:0.6;cursor:pointer",i.addEventListener("click",()=>this._submitQuery()),n.appendChild(i);const s=document.createElement("input");s.type="text",s.placeholder="Search: type, id, tag, text, data...",s.style.cssText=["flex:1","background:rgba(255,255,255,0.08)","border:1px solid rgba(255,255,255,0.15)","border-radius:4px","color:white","padding:4px 8px","font-size:13px","outline:none","min-width:0"].join(";"),s.addEventListener("focus",()=>{s.style.borderColor="rgba(74,158,255,0.6)"}),s.addEventListener("blur",()=>{s.style.borderColor="rgba(255,255,255,0.15)"}),n.appendChild(s);const r=document.createElement("span");r.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;flex-shrink:0",n.appendChild(r);const o=document.createElement("button");o.textContent="✕",o.title="Close (Esc)",o.style.cssText=this._buttonStyle(),o.addEventListener("click",()=>this.hide()),n.appendChild(o),e.appendChild(n);const a=document.createElement("div");a.style.cssText=["max-height:240px","overflow-y:auto","border-top:1px solid rgba(255,255,255,0.08)","display:none"].join(";"),e.appendChild(a),s.addEventListener("input",()=>{this._historyIndex=-1,this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>this._doSearch(s.value),150)}),s.addEventListener("keydown",e=>{if(e.stopPropagation(),"Escape"===e.key)return this.hide(),void t.element?.focus();if("ArrowDown"===e.key||"Tab"===e.key){if("Tab"===e.key&&e.shiftKey)return;return this._isHistoryMode()||!this._input?.value&&"ArrowDown"===e.key?this._navigateHistory(1):this._engine.resultCount>0&&this._focusResult(0),void e.preventDefault()}if("ArrowUp"===e.key)return this._navigateHistory(-1),void e.preventDefault();if("Enter"===e.key){if(this._submitQuery())return void e.preventDefault();const t=this._engine.currentIndex>=0?this._engine.currentIndex:0;return this._selectResult(t),void e.preventDefault()}}),this._container=e,this._input=s,this._statusEl=r,this._resultListEl=a,this._setupDrag(e,n)}_setupDrag(t,e){e.style.cursor="move",e.addEventListener("mousedown",e=>{if(e.target.closest("input, button"))return;e.preventDefault();const n=t.getBoundingClientRect(),i=t.offsetParent?.getBoundingClientRect(),s=n.left-(i?.left||0),r=n.top-(i?.top||0);t.style.transform="",t.style.right="auto",t.style.left=`${s}px`,t.style.top=`${r}px`;const o=e.clientX,a=e.clientY,c=e=>{t.style.left=s+e.clientX-o+"px",t.style.top=r+e.clientY-a+"px"},l=()=>{document.removeEventListener("mousemove",c,!0),document.removeEventListener("mouseup",l,!0)};document.addEventListener("mousemove",c,!0),document.addEventListener("mouseup",l,!0)})}_buttonStyle(){return["background:none","border:none","color:rgba(255,255,255,0.6)","cursor:pointer","font-size:12px","padding:2px 4px","border-radius:3px","line-height:1"].join(";")}_doSearch(t){if(!this._host?.root)return;const e=t.trim();if(!e)return this._engine.clear(),this._clearHighlight(),this._updateStatus(),void this._hideResultList();this._engine.search(this._host.root,e),this._updateStatus(),this._renderResultList()}_addToHistory(t){const e=t.trim();if(!e)return;const n=this._queryHistory.indexOf(e);n>=0&&this._queryHistory.splice(n,1),this._queryHistory.unshift(e),this._queryHistory.length>Eu.MAX_HISTORY&&this._queryHistory.pop()}_navigateHistory(t){if(0===this._queryHistory.length)return;if(!this._input)return;-1===this._historyIndex&&-1===t&&(this._savedInput=this._input.value);const e=this._historyIndex+(-1===t?1:-1);e<-1||e>=this._queryHistory.length||(this._historyIndex=e,-1===this._historyIndex?this._input.value=this._savedInput:this._input.value=this._queryHistory[this._historyIndex],this._debounceTimer&&clearTimeout(this._debounceTimer),this._doSearch(this._input.value))}_isHistoryMode(){return this._historyIndex>=0}_submitQuery(){const t=(this._input?.value||"").trim();if(!t)return!1;if(this._isEditMode()){if(this._engine.resultCount>0){const t=this._engine.currentIndex>=0?this._engine.currentIndex:0;this._selectResult(t)}return!0}const e={query:t,results:this._engine.results.slice()};return this._host?.root?.trigger?.("query-submit",e),this._invokeViewSubmit(e),this._addToHistory(t),!0}_invokeViewSubmit(t){const e=this._host;if(e){if("function"==typeof e.onSearchSubmit){if(!0===e.onSearchSubmit(t,e))return}e.tracker?.start?.(t.query,e.trackerOptions)}}_invokeViewClose(){const t=this._host;if(t){if("function"==typeof t.onSearchClose){if(!0===t.onSearchClose(t))return}t.tracker?.stop?.()}}_focusResult(t){if(t<0||t>=this._engine.resultCount)return;if(t>=50)return;this._engine.navigateTo(t),this._updateStatus(),this._updateResultListSelection();const e=this._resultListEl?.querySelector(`[data-index="${t}"]`);e?.focus()}_isEditMode(){return!!this._host?.root?.app?.isEditMode}_selectResult(t){if(!this._host)return;if(0===this._engine.resultCount)return;if(t<0||t>=this._engine.resultCount)return;this._engine.navigateTo(t);const e=this._engine.currentResult;if(!e)return;this._addToHistory(this._input?.value||"");const n=e.component.state?.id;if(n&&this._input&&(this._input.value=String(n),this._doSearch(this._input.value)),this._isEditMode()){this._host.setSelected([e.component]),this._host.centerTo(e.component,!0);const t=this._engine.results.map(t=>t.component);this._host.highlightSearchResults?.(t),this._host.invalidate?.()}else{const t={query:e.component.state?.id||"",results:this._engine.results.slice(),selected:e.component};this._host.root?.trigger?.("query-submit",t),this._invokeViewSubmit(t)}this._updateStatus(),this._updateResultListSelection()}_clearHighlight(){this._host?.highlightSearchResults?.([]),this._host?.invalidate?.()}_updateStatus(){if(!this._statusEl)return;const t=this._engine.resultCount,e=this._engine.currentIndex;0===t&&this._input?.value?.trim()?(this._statusEl.textContent="No results",this._statusEl.style.color="rgba(255,120,120,0.8)"):t>0?(this._statusEl.textContent=`${e+1}/${t}`,this._statusEl.style.color="rgba(255,255,255,0.5)"):this._statusEl.textContent=""}_renderResultList(){if(!this._resultListEl)return;const t=this._engine.results;if(this._resultListEl.innerHTML="",0===t.length)return void(this._resultListEl.style.display="none");const e=t.slice(0,50);for(let t=0;t<e.length;t++){const n=e[t],i=document.createElement("div");i.dataset.index=String(t),i.tabIndex=-1,i.style.cssText=["padding:4px 10px","cursor:pointer","display:flex","align-items:center","gap:6px","font-size:12px","border-bottom:1px solid rgba(255,255,255,0.04)","transition:background 0.1s","outline:none"].join(";"),i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{this._engine.currentIndex!==t?i.style.background="none":i.style.background="rgba(74,158,255,0.15)"}),i.addEventListener("click",()=>{this._selectResult(t)}),i.addEventListener("keydown",e=>{e.stopPropagation(),"ArrowDown"===e.key?(this._focusResult(t+1),e.preventDefault()):"ArrowUp"===e.key?(0===t?(this._input?.focus(),this._input?.select()):this._focusResult(t-1),e.preventDefault()):"Enter"===e.key?(this._selectResult(t),e.preventDefault()):"Escape"===e.key?(this.hide(),this._host?.element?.focus(),e.preventDefault()):e.shiftKey&&"Tab"===e.key?(this._input?.focus(),e.preventDefault()):1!==e.key.length||e.metaKey||e.ctrlKey||e.altKey||this._input?.focus()});const s=document.createElement("span");s.textContent=Au[n.matchType]||n.matchType,s.style.cssText=["font-size:9px","padding:1px 4px","border-radius:3px","background:rgba(74,158,255,0.2)","color:rgba(74,158,255,0.9)","flex-shrink:0","text-transform:uppercase","letter-spacing:0.5px"].join(";"),i.appendChild(s);const r=document.createElement("span");r.textContent=n.component.state.type||"?",r.style.cssText="color:rgba(255,255,255,0.7);flex-shrink:0",i.appendChild(r);const o=document.createElement("span");if(o.textContent=this._truncate(n.matchValue,30),o.style.cssText="color:rgba(255,200,100,0.8);overflow:hidden;text-overflow:ellipsis;white-space:nowrap",i.appendChild(o),"id"!==n.matchType&&n.component.state.id){const t=document.createElement("span");t.textContent=`#${n.component.state.id}`,t.style.cssText="color:rgba(255,255,255,0.3);font-size:11px;margin-left:auto;flex-shrink:0",i.appendChild(t)}this._resultListEl.appendChild(i)}if(t.length>50){const e=document.createElement("div");e.style.cssText="padding:4px 10px;font-size:11px;color:rgba(255,255,255,0.3);text-align:center",e.textContent=`... and ${t.length-50} more`,this._resultListEl.appendChild(e)}this._resultListEl.style.display="block",this._updateResultListSelection()}_updateResultListSelection(){if(!this._resultListEl)return;const t=this._engine.currentIndex;for(const e of Array.from(this._resultListEl.children)){const n=e,i=parseInt(n.dataset.index||"-1",10);n.style.background=i===t?"rgba(74,158,255,0.15)":"none"}const e=this._resultListEl.querySelector(`[data-index="${t}"]`);e?.scrollIntoView({block:"nearest"})}_hideResultList(){this._resultListEl&&(this._resultListEl.style.display="none",this._resultListEl.innerHTML="")}_truncate(t,e){return t.length>e?t.slice(0,e)+"...":t}}Eu.MAX_HISTORY=20;const Cu={color:"#00aaff7f",intervalMs:1e3};class Tu{constructor(t){this._id=null,this._target=null,this._fallback=null,this._lastCheckMs=0,this._options=Cu,this._scene=t}get trackingId(){return this._id}start(t,e){t&&(this._id&&this.stop(),this._id=String(t),this._options={...Cu,...e},this._setOutlineColorFromHex(this._options.color),this._tickOnce(!0),this._lastCheckMs=0,this._unsubscribe=jr.subscribe(()=>{const t=Date.now();t-this._lastCheckMs<this._options.intervalMs||(this._lastCheckMs=t,this._tickOnce(!1))},{description:`tracker#${this._id}`,component:this._scene?.root}))}stop(){this._clearTarget(),this._clearFallback(),this._id=null,this._unsubscribe&&(this._unsubscribe(),this._unsubscribe=void 0),this._lastCheckMs=0,this._setOutlineColor(15885602)}dispose(){this.stop()}_tickOnce(t){if(!this._id)return;const e=this._findTarget();if(e)return this._fallback&&this._fallback!==e&&this._clearFallback(),this._target=e,e.trigger("deco-border",this._decoOptions(this._options.color)),void(t&&this._scene.centerTo?.(e,!0));this._clearTarget();const n=this._options.fallback?.(this._id,this._scene)??null;n&&n!==this._fallback?(this._clearFallback(),this._fallback=n,n.trigger("deco-border",this._decoOptions(this._options.fallbackColor||this._options.color))):n?n.trigger("deco-border",this._decoOptions(this._options.fallbackColor||this._options.color)):this._clearFallback()}_findTarget(){const t=this._scene.findAll?.(`#${this._id}`);return t?.[0]??null}_clearTarget(){this._target&&(this._target.trigger?.("deco-border-off"),this._target=null)}_clearFallback(){this._fallback&&(this._fallback.trigger?.("deco-border-off"),this._fallback=null)}_decoOptions(t){return{distance:8,lineWidth:4,color:t}}_setOutlineColorFromHex(t){const e=(t||"").replace("#","").slice(0,6);/^[0-9a-fA-F]{6}$/.test(e)&&this._setOutlineColor(parseInt(e,16))}_setOutlineColor(t){const e=this._scene?.root;e?.model_layer?.setOutlineColor?.(t)}}let Pu=null;const Ou=[],Du=new Set;function zu(t){if(!t)return;const e=t?.state?.id??t?.id??t?.refid;return void 0!==e?String(e):void 0}const Iu={beginContext(t){Pu=t},endContext(){Pu=null},current:()=>Pu,log(t){const e={role:t.role,contract:t.contract,componentId:t.componentId??zu(t.component),componentType:t.componentType??(n=t.component,n?.state?.type??n?.type),atSimMs:Ir.now,args:t.args,result:t.result,error:t.error};var n;Pu?Pu.pushTrace(e):(Ou.push(e),Ou.length>500&&Ou.shift(),Du.forEach(t=>{try{t(e)}catch{}}))},standaloneEvents:()=>[...Ou],onStandalone:t=>(Du.add(t),()=>{Du.delete(t)}),clearStandalone(){Ou.length=0}};function Ru(t){if(!t)return;const e=t?.state?.refid??t?.refid;if(null==e)return;const n=String(e);return n.length>0?n:void 0}function ju(t){const e={transferId:t.transferId,phase:t.phase,timeline:{...t.timeline}},n=t.sourceId??Ru(t.source),i=t.targetId??Ru(t.target),s=t.carrierId??Ru(t.carrier);return void 0!==n&&(e.sourceId=n),void 0!==i&&(e.targetId=i),void 0!==s&&(e.carrierId=s),void 0!==t.slotId&&(e.slotId=t.slotId),void 0!==t.rejectReason&&(e.rejectReason=t.rejectReason),e}let Lu=1;class Fu{constructor(t){this._phase="pending",this._slot=null,this._reservation=null,this._traceEvents=[],this.meta={},this.id="xfer-"+Lu++,this.source=t.source,this.target=t.target,this.carrier=t.carrier,this.options=t.options??{},this.physical=t.physical??null,this._timeline={initiatedAt:Ir.now}}pushTrace(t){this._traceEvents.push({atSimMs:t.atSimMs??Ir.now,...t})}get phase(){return this._phase}get timeline(){return this._timeline}_rollback(){this._phase="rolled-back";const t=this._buildReceipt();return Nu.append(t),t}_planAndReserve(){this._phase="planning",this._timeline.planStartAt=Ir.now;const t=this.target.canAccept?.(this.carrier);if(t&&t.ok)this._slot=t.slot;else{if(t&&!t.ok&&"no-slots-defined"!==t.reason)return this._rejectReason=t.reason,this._rollback();if(t||"function"!=typeof this.target.canReceive)this._slot=null;else{if(!this.target.canReceive(this.carrier))return this._rejectReason="cannot-receive",this._rollback();this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}}return null===this._slot||"function"!=typeof this.target.reserve||"function"!=typeof this.target.commit||(this._reservation=this.target.reserve(this.carrier,{source:this.source}),this._reservation)?(this._timeline.planEndAt=Ir.now,null):(this._rejectReason="cannot-reserve",this._rollback())}_physicalFailed(t){return this._reservation&&this.target.release?.(this._reservation),this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._rollback()}_handoffFailed(t){throw this._rejectReason=`handoff-failed: ${t.message??"unknown"}`,this._phase="rolled-back",Nu.append(this._buildReceipt()),t}_commitReserved(){if(this._reservation&&"function"==typeof this.target.commit){try{this.target.commit(this._reservation,this.carrier,this.options)}catch(t){this.target.release?.(this._reservation),this._handoffFailed(t)}return!0}return!1}_finishCommitted(){this._phase="committed",this._timeline.committedAt=Ir.now;const t=this._buildReceipt();return Nu.append(t),t}_runPhysicalSync(){if(!this.physical)return null;this._phase="physical",this._timeline.physicalStartAt=Ir.now;try{const t=this.physical();t instanceof Promise&&t.catch(()=>{})}catch(t){return this._physicalFailed(t)}return this._timeline.physicalEndAt=Ir.now,null}async _runPhysicalAsync(){if(!this.physical)return null;this._phase="physical",this._timeline.physicalStartAt=Ir.now;try{await this.physical()}catch(t){return this._physicalFailed(t)}return this._timeline.physicalEndAt=Ir.now,null}_runReceiveSync(){const t=this.target.accept??this.target.receive;if("function"==typeof t)try{const e=t.call(this.target,this.carrier,this.options);e instanceof Promise&&e.catch(()=>{})}catch(t){this._handoffFailed(t)}else Iu.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method"}})}async _runReceiveAsync(){const t=this.target.accept??this.target.receive;if("function"==typeof t)try{await t.call(this.target,this.carrier,this.options)}catch(t){this._handoffFailed(t)}else Iu.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method"}})}async execute(){Iu.beginContext(this),Iu.log({role:"transfer",contract:"execute:begin",args:{transferId:this.id,source:Ru(this.source),target:Ru(this.target),carrier:Ru(this.carrier)}});try{return await this._executeImpl()}finally{Iu.log({role:"transfer",contract:"execute:end",args:{transferId:this.id,phase:this._phase}}),Iu.endContext()}}executeSync(){Iu.beginContext(this),Iu.log({role:"transfer",contract:"executeSync:begin",args:{transferId:this.id,source:Ru(this.source),target:Ru(this.target),carrier:Ru(this.carrier)}});try{const t=this._planAndReserve();if(t)return t;const e=this._runPhysicalSync();return e||(this._phase="handoff",this._timeline.handoffAt=Ir.now,this._commitReserved()||this._runReceiveSync(),this._finishCommitted())}finally{Iu.log({role:"transfer",contract:"executeSync:end",args:{transferId:this.id,phase:this._phase}}),Iu.endContext()}}async _executeImpl(){const t=this._planAndReserve();if(t)return t;const e=await this._runPhysicalAsync();return e||(this._phase="handoff",this._timeline.handoffAt=Ir.now,this._commitReserved()||await this._runReceiveAsync(),this._finishCommitted())}rollback(){if("committed"===this._phase)throw new Error("Cannot rollback a committed transfer");this._rejectReason=this._rejectReason??"manual-rollback",this._phase="rolled-back",Nu.append(this._buildReceipt())}_buildReceipt(){return{transferId:this.id,source:this.source,target:this.target,carrier:this.carrier,sourceId:Ru(this.source),targetId:Ru(this.target),carrierId:Ru(this.carrier),phase:this._phase,timeline:{...this._timeline},slotId:this._slot?.id,rejectReason:this._rejectReason,traceEvents:[...this._traceEvents],meta:Object.keys(this.meta).length>0?{...this.meta}:void 0}}}const Nu=new class{constructor(){this._flows=new Map,this._targetCount=new Map,this._byPhase=new Map,this._byRejectReason=new Map,this._total=0,this._committedDurationSum=0,this._committedCount=0,this._listeners=new Set}append(t){this._total++,this._byPhase.set(t.phase,(this._byPhase.get(t.phase)??0)+1);const e=t.sourceId??Ru(t.source),n=t.targetId??Ru(t.target);if("committed"===t.phase){if(e&&n){const t=e+">"+n;this._flows.set(t,(this._flows.get(t)??0)+1)}n&&this._targetCount.set(n,(this._targetCount.get(n)??0)+1),void 0!==t.timeline.committedAt&&(this._committedDurationSum+=t.timeline.committedAt-t.timeline.initiatedAt,this._committedCount++)}else if("rolled-back"===t.phase&&t.rejectReason){this._byRejectReason.set(t.rejectReason,(this._byRejectReason.get(t.rejectReason)??0)+1);try{t.source?._bumpRejected?.(t.carrier,t.rejectReason)}catch{}}this._listeners.forEach(e=>e(t))}flows(){return this._flows}targetCounts(){return this._targetCount}stats(){const t={};this._byPhase.forEach((e,n)=>{t[n]=e});const e=t["rolled-back"]??0;return{total:this._total,byPhase:t,committed:t.committed??0,rolledBack:e,rejectionRate:this._total>0?e/this._total:0,avgTransferDurationMs:this._committedCount>0?this._committedDurationSum/this._committedCount:0}}rejectReasonCounts(){return this._byRejectReason}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}clear(){this._flows.clear(),this._targetCount.clear(),this._byPhase.clear(),this._byRejectReason.clear(),this._total=0,this._committedDurationSum=0,this._committedCount=0}entries(){return[]}forCarrier(t){return[]}forCarrierId(t){return[]}forSourceId(t){return[]}forTargetId(t){return[]}forPhase(t){return[]}inTimeRange(t,e,n){return[]}groupByRejectReason(){return new Map}toJSON(){return[]}fromJSON(t){}replayTo(t){}setMaxEntries(t){}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_TRANSFER_LOG__=Nu);let Hu=0;const Bu=new FinalizationRegistry(t=>{Hu--});class Gu{static get residents(){return Hu}static get residentsCount(){return Hu}constructor(t){this._searchOverlay=new Eu,this._loadingOverlay=new Cd,this._container=t,this.app=t.app,this._commander=new mh(this._container),this.app.commander=this._commander,Hu++,Bu.register(this,Hu),Ed.register(this),this._container.target_element&&this._setupSearchOverlay()}add(t,e,n){return Oh.call(this._container,t,e,n)}duplicate(){return Dh.call(this._container)}remove(){return zh.call(this._container)}animate(t){return ka.call(this,t)}fullscreen(t){return Nh.call(this._container,t)}get target(){return this._container.target_element}set target(t){let e;if("string"==typeof t){if(e=document.getElementById(t),!e)throw new Error(`target element '${t}' does not exist`);if(e.firstChild)throw new Error(`target element '${t}' already has children`)}else e=t;e&&e.style&&(e.style.cursor="default"),this._container.target_element=e,this._setupSearchOverlay(),this._container.invalidate()}get scale(){return this.root.get("scale")}set scale(t){this.root.set("scale",t)}get translate(){return this.root.get("translate")}set translate(t){this.root.set("translate",t)}get unit(){return this.root.get("unit")||"px"}get PPM(){return this.app.PPM}get PPI(){return this.app.PPI}get DPPX(){return this.app.DPPX}static get DPPX(){return Xs}get unitScale(){return this._container.unitScale}get screen(){return this.app.screen}set screen(t){this.app.screen=t,this._container.resize()}resize(){this._container.resize()}release(){this.dispose()}dispose(){this._loadingOverlay.destroy(),this._searchOverlay.destroy(),this._tracker?.dispose(),Ed.unregister(this),this._commander&&this._commander.dispose(),this._container&&this._container.dispose(),vu.flushCache(),Nu.clear()}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 Gh.call(this._container)}copy(){return Bh.call(this._container)}paste(t){return Vh.call(this._container,t)}undoableChange(t){return ad.call(this._container,t)}change(t,e,n){return od.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 kh.call(this._container,t)}place(t){return md.call(this._container,t)}distribute(t){return Ch.call(this._container,t)}move(t,e,n){return Th.call(this._container,t,e,n)}zorder(t){return Ph.call(this._container,t)}symmetryX(){return sd.call(this._container)}symmetryY(){return rd.call(this._container)}on(t,e,n){return jh.call(this._container,t,e,n)}once(t,e,n){return Lh.call(this._container,t,e,n)}off(t,e,n){return this._container&&Fh.call(this._container,t,e,n)}centerTo(t,e){const n=this.root?.rootModel?.is3dMode;if(!this.app?.isViewMode||n)return this.root.centerTo(t,e)}get tracker(){return this._tracker||(this._tracker=new Tu(this)),this._tracker}get mode(){return this.app.mode}set mode(t){void 0!==t&&(this.app.mode=t)}get threedEnabled(){return wu()}get isSelecting(){return!!this.app?.isSelecting}get focusFilter(){return this.app?.focusFilter}set focusFilter(t){this.app&&(this.app.focusFilter=t),this._reapplyModelingFaint(),this._container?.invalidate()}_reapplyModelingFaint(){const t=e=>{e?._realObject?.applyFocusDim?.(),e?.applyElementModelingFaint?.(),(e?.components||[]).forEach(t),(e?.items||[]).forEach?.(t)};t(this._container)}toDataURL(t,e,n,i){return Jh.call(this._container,t,e,n,i)}group(){return td.call(this._container)}ungroup(){return ed.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 cd.call(this._container)}get data(){return this._container.data}set data(t){this._container.data=t}get dataByRefid(){return this._container.dataByRefid}set dataByRefid(t){this._container.dataByRefid=t}get values(){return this._container.values}set values(t){this._container.values=t}get valuesByRefid(){return this._container.valuesByRefid}set valuesByRefid(t){this._container.valuesByRefid=t}get baseUrl(){return this.app.baseUrl}set baseUrl(t){this.app.baseUrl=t}get suppressAnimations(){return this.app.suppressAnimations}set suppressAnimations(t){this.app.suppressAnimations=t}withSuppressedAnimations(t){return this.app.withSuppressedAnimations(t)}beginSuppressAnimations(){return this.app.beginSuppressAnimations()}startAddMode(t){return gd.call(this._container,t)}startBulkCreateMode(t,e){return yd.call(this._container,t,e)}startStylePasteMode(){return bd.call(this._container)}stopStylePasteMode(){return _d.call(this._container)}startDatabindPasteMode(){return vd.call(this._container)}stopDatabindPasteMode(){return xd.call(this._container)}get loading(){return this.app.loadTracker}get loadingOverlay(){return this._loadingOverlay}showLoadingOverlay(){this._loadingOverlay.show()}hideLoadingOverlay(){this._loadingOverlay.hide()}toggleLoadingOverlay(){if(!this._loadingOverlay.isAttached){const t=this._container.target_element;t&&this._loadingOverlay.attach(t,this.app.loadTracker,this.app.lagTracker)}this._loadingOverlay.toggle()}get searchOverlay(){return this._searchOverlay}_setupSearchOverlay(){const t=this;this._searchOverlay.setup({get root(){return t.root},get element(){return t.target},centerTo(e,n){t.centerTo(e,n)},setSelected(e){t.selected=e},invalidate(){t._container?.invalidate()},get tracker(){return t.tracker},get trackerOptions(){return t.trackerOptions},get onSearchSubmit(){return t.onSearchSubmit},get onSearchClose(){return t.onSearchClose}});const e=this._container.model_layer;e&&(e.onSearchToggle=()=>this._searchOverlay.toggle(),e.onDataBindingToggle=()=>this.onDataBindingToggle?.(),e.onMonitorToggle=()=>this.toggleLoadingOverlay())}}const Vu=new class{async load(t){}async save(t,e){}async clear(t){}};function Yu({target:t,model:e,style:n,layers:i=[],handlers:s=[],mode:r=0,refProvider:o,dataSubscriptionProvider:a,dataStorage:c=Vu,baseUrl:l,fitMode:h,postprocessing:d=!0,logarithmicDepth:u,loading:p}){let f=null;if("string"==typeof t){if(f=document.getElementById(t),!f)throw new Error(`target element '${t}' does not exist`);if(f.firstChild)throw new Error(`target element '${t}' is not empty`)}else f=t??null;f&&f.style&&(f.style.position="absolute",f.style.cursor="default",f.style.overflow="hidden");const m=new lh(r,o);return l&&(m.baseUrl=l),m.postprocessing=d,m.logarithmicDepth=u,m.dataSubscriptionProvider=a,m.dataStorage=c,p?.tracker?m.adoptLoadTracker(p.tracker):m.initLoadTracker(p||{}),m.loadTracker?.setPhase("init"),new Gu(new th({target_element:f,model:e,style:n,layers:i,handlers:s,fitMode:h},m))}const Wu=20;function Uu(t,e="static",n,i,s,r,o={}){const{title:a="",gap:c=Wu}=o;if("auto"===n){const{x:e,y:n}=function(t,e,n,i="",s=Wu){const r=Math.max(e.width/4-n.width/2,s),o=Math.min(3*e.width/4+n.width/2,e.width-s)-n.width,a=Math.max(e.height/4-n.height/2,s),c=Math.min(3*e.height/4+n.height/2,e.height-s)-n.height+(i?-30:0);return{x:t.x<e.width/2?Math.min(o,t.x+20):Math.max(r,t.x-(n.width+20)),y:t.y<e.height/2?Math.min(c,t.y+20+(i?30:0)):Math.max(a,t.y-(n.height+20))}}(i,s,r,a,c);Object.assign(t.style,{position:"absolute",left:`${e}px`,top:`${n}px`})}else"static"===e?function(t,e,n,i,s){const r=t.style,o=e.includes("left")?s:e.includes("right")?n.width-i.width-s:n.width/2-i.width/2,a=e.includes("top")?s:e.includes("bottom")?n.height-i.height-s:n.height/2-i.height/2;Object.assign(r,{left:`${o}px`,top:`${a}px`})}(t,n,s,r,c):function(t,e,n=Wu){const i=t.style;switch(Object.assign(i,{position:"absolute",left:"",right:"",top:"",bottom:"",transform:""}),e){case"center-middle":default:Object.assign(i,{left:"50%",top:"50%",transform:"translate(-50%, -50%)"});break;case"center-top":Object.assign(i,{left:"50%",top:`${n}px`,transform:"translateX(-50%)"});break;case"center-bottom":Object.assign(i,{left:"50%",bottom:`${n}px`,transform:"translateX(-50%)"});break;case"left-middle":Object.assign(i,{left:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"right-middle":Object.assign(i,{right:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"left-top":Object.assign(i,{left:`${n}px`,top:`${n}px`});break;case"right-top":Object.assign(i,{right:`${n}px`,top:`${n}px`});break;case"left-bottom":Object.assign(i,{left:`${n}px`,bottom:`${n}px`});break;case"right-bottom":Object.assign(i,{right:`${n}px`,bottom:`${n}px`})}}(t,n,c)}function $u(t,e,n={sx:1,sy:1},i={}){const{signal:s}=i;let r,o,a=0,c=0,l=!1;const h=/translate\(([-\d.]+)px,\s*([-\d.]+)px\)/;function d(){const e=(t.style.transform||"").match(h);return{x:e?parseFloat(e[1]):0,y:e?parseFloat(e[2]):0}}function u(t,e){l=!0;const n=d();a=n.x,c=n.y,r=t,o=e}function p(e,i){if(!l)return;const s=e-r,h=i-o,{sx:d,sy:u}=n;!function(e,n){t.style.transform=`translate(${e}px, ${n}px)`}(a+s/d,c+h/u)}function f(){const t=d();a=t.x,c=t.y,l=!1}function m(t){if(!s)return t.signal;const e=AbortSignal.any;return e?e([t.signal,s]):(s.aborted?t.abort():s.addEventListener("abort",()=>t.abort(),{once:!0}),t.signal)}e?.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),u(t.clientX,t.clientY);const e=new AbortController,n=m(e);window.addEventListener("mousemove",t=>{t.preventDefault(),p(t.clientX,t.clientY)},{capture:!0,signal:n}),window.addEventListener("mouseup",t=>{t.preventDefault(),f(),e.abort()},{capture:!0,signal:n})},{signal:s}),e?.addEventListener("touchstart",t=>{if(1!==t.touches.length)return;t.preventDefault(),t.stopPropagation(),u(t.touches[0].clientX,t.touches[0].clientY);const e=new AbortController,n=m(e);window.addEventListener("touchmove",t=>{1===t.touches.length&&(t.preventDefault(),p(t.touches[0].clientX,t.touches[0].clientY))},{capture:!0,signal:n});const i=()=>{f(),e.abort()};window.addEventListener("touchend",i,{capture:!0,signal:n}),window.addEventListener("touchcancel",i,{capture:!0,signal:n})},{signal:s})}function Xu(t,n,i){const s=t.rootModel;if(s?.is3dMode){const n=t._realObject?.object3d,i=s.activeCamera3d,r=s.renderer3d;if(n&&i&&r){const t=new e.Vector3;n.getWorldPosition(t);const s=t.clone().project(i),o=r.domElement;return{x:(.5*s.x+.5)*o.clientWidth,y:(.5*-s.y+.5)*o.clientHeight}}return null}const r=t.toGlobal(n,i,s);return isNaN(r.x)||isNaN(r.y)?null:r}const qu=new e.Box3,Ku=new e.Vector3;function Qu(t,n="top",i={},s=new e.Vector3){const r=t._realObject;return r?.object3d?(r.object3d.updateWorldMatrix(!0,!0),"center"===n?s.setFromMatrixPosition(r.object3d.matrixWorld):(qu.setFromObject(r.object3d),qu.isEmpty()?s.setFromMatrixPosition(r.object3d.matrixWorld):(qu.getCenter(Ku),"bottom"===n?s.set(Ku.x,qu.min.y,Ku.z):s.set(Ku.x,qu.max.y,Ku.z))),s.x+=i.x??0,s.y+=i.y??0,s.z+=i.z??0,Number.isFinite(s.x)&&Number.isFinite(s.y)&&Number.isFinite(s.z)?s:null):null}function Zu(t){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("style","position:absolute; left:0; top:0; width:100%; height:100%; pointer-events:none; overflow:visible; opacity:0; transition: opacity 200ms ease;"),e.dataset.role="tether";const n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttribute("r","8"),n.setAttribute("opacity","0"),e.appendChild(n);const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("fill","none"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),e.appendChild(i);const s=document.createElementNS("http://www.w3.org/2000/svg","circle");return s.setAttribute("r","3.5"),s.setAttribute("opacity","0"),e.appendChild(s),t.appendChild(e),{svg:e,path:i,halo:n,dot:s}}function Ju(t,e,n,i,s,r,o,a,c,l,h){const{svg:d,path:u,halo:p,dot:f}=t;d.setAttribute("width",String(l)),d.setAttribute("height",String(h)),d.setAttribute("viewBox",`0 0 ${l} ${h}`);const m=function(t,e,n,i,s,r){const o=n+s/2,a=i+r/2,c=t-o,l=e-a;if(Math.abs(c)*r>Math.abs(l)*s)return{x:c>0?n+s:n,y:a};return{x:o,y:l>0?i+r:i}}(e,n,i,s,r,o),g=m.x-e,y=m.y-n,b=(e+m.x)/2,_=(n+m.y)/2,v=Math.sqrt(g*g+y*y),x=v>0?-y/v:0,w=v>0?g/v:0,M=Math.min(18,.12*v),S=b+x*M,k=_+w*M;u.setAttribute("d",`M ${e} ${n} Q ${S} ${k} ${m.x} ${m.y}`),u.setAttribute("stroke",a),u.setAttribute("opacity",String(c)),p.setAttribute("cx",String(e)),p.setAttribute("cy",String(n)),p.setAttribute("fill",a),p.setAttribute("opacity",String(.25*c)),f.setAttribute("cx",String(e)),f.setAttribute("cy",String(n)),f.setAttribute("fill",a),f.setAttribute("opacity",String(c))}function tp(t){t.path.setAttribute("d",""),t.halo.setAttribute("opacity","0"),t.dot.setAttribute("opacity","0")}function ep(t){t.svg.parentNode?.removeChild(t.svg)}const np=["run","goto","goto-playlist","link-open","link-move","route-page","start-scenario","run-scenario","export-data","import-data"];function ip(t,e){const n=document.createElement("button");return n.className=t,n.textContent=e,n}function sp(t){const{component:e,anchor:n,anchorPin:i,anchorOffset:s,popupRoot:r,popupSize:o,constantSize:a,billboard:c,tetherEnabled:l,offScreen:h,signal:d,popupEntry:u}=t,p=e.rootModel??e.root;if(!p?.on)return;if(!a)return void function(t){const{component:e,anchor:n,anchorPin:i,anchorOffset:s,popupRoot:r,billboard:o,tetherEnabled:a,signal:c,popupEntry:l}=t,h=e.rootModel??e.root,d=h?._threeCapability,u=d?.rendererManager?.css3DScene;if(!u)return void Zi("perspective popup requires 3D mode active (css3DScene unavailable)");r.style.position="absolute";const p=o?new _(r):new v(r);u.add(p),r.dataset.perspectiveCss3d="true";const f=()=>ap.hide(e);n.on?.("removed",f);const m=h.target??null;let g;a&&m&&(g=Zu(m),l&&(l.tether=g));const y=()=>{const t=Qu(n,i,s);if(t){if(p.position.set(t.x,t.y,t.z),g&&m){const t=Xu(n,0,0),e=m.getBoundingClientRect(),i=r.getBoundingClientRect();if(t&&e.width>0&&e.height>0&&i.width>0){const n=i.left-e.left,s=i.top-e.top,r=o;Ju(g,t.x,t.y,r?n:n+i.width/2,r?s:s+i.height/2,r?i.width:0,r?i.height:0,"rgba(80, 120, 200, 0.7)",1,e.width,e.height)}}}else g&&tp(g)},b=()=>y();h.on("redraw",b),y(),h.invalidate?.(),c.addEventListener("abort",()=>{h.off?.("redraw",b),n.off?.("removed",f),u.remove(p),r.parentNode&&r.parentNode.removeChild(r),g&&ep(g)})}({component:e,anchor:n,anchorPin:i,anchorOffset:s,popupRoot:r,billboard:c,tetherEnabled:l,signal:d,popupEntry:u});Object.assign(r.style,{position:"absolute",pointerEvents:"auto"});const f=r.parentElement;let m;l&&f&&(m=Zu(f),u&&(u.tether=m));const g=()=>ap.hide(e);n.on?.("removed",g);const y=()=>{if(!Qu(n,i,s))return void("hide"===h&&(r.style.opacity="0",m&&tp(m)));const t=Xu(n,0,0);if(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y))return void("hide"===h&&(r.style.opacity="0",m&&tp(m)));const e=f?.getBoundingClientRect(),a=e?.width??0,c=e?.height??0,l=t.x<0||t.x>a||t.y<0||t.y>c;if(l&&"hide"===h)return r.style.opacity="0",void(m&&tp(m));if(l&&"keep-last"===h)return;let{x:d,y:u}=t;l&&"edge-pin"===h&&(d=Math.max(0,Math.min(a,d)),u=Math.max(0,Math.min(c,u)));const p=d+24,g=u-24-o.height,y=Math.max(8,Math.min(p,a-o.width-8)),b=Math.max(8,Math.min(g,c-o.height-8));r.style.opacity="1",r.style.left=`${y}px`,r.style.top=`${b}px`,m&&Ju(m,d,u,y,b,o.width,o.height,"rgba(80, 120, 200, 0.7)",1,a,c)},b=()=>y();p.on("redraw",b),y(),p.invalidate?.(),d.addEventListener("abort",()=>{p.off?.("redraw",b),n.off?.("removed",g),m&&ep(m)})}const rp=new WeakMap;function op(t){const e=t.root,n=rp.get(e);if(!n)return;if(e===t)return n.forEach(t=>op(t[0])),void rp.delete(e);const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const s=n[i][1];cancelAnimationFrame(s.rafId),s.ac.abort(),s.div.parentNode?.removeChild(s.div),s.scene.target=null,s.scene.release?.(),n.splice(i,1)}class ap{static hideAll(t){(rp.get(t)||[]).forEach(([t])=>op(t))}static hide(t){const e=t.root,n=rp.get(e);if(!n)return;const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const s=n[i][1],r=()=>{s.div.style.backgroundColor="transparent",s.rafId=function(t,e,n){const i="true"===t.dataset.perspectiveCss3d;t.style.opacity="1";const s=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();i||(t.style.transform=`${s} scale(1)`);let r=0;const o=Date.now(),a=()=>{if(n?.aborted)return;const c=Math.min((Date.now()-o)/200,1);t.style.opacity=String(1-c),i||(t.style.transform=`${s} scale(${1-c})`.trim()),c<1?r=requestAnimationFrame(a):(t.style.display="none",e&&e())};return r=requestAnimationFrame(a),r}(s.div,()=>{op(t)},s.ac.signal)};s.tether?(s.tether.svg.style.opacity="0",setTimeout(r,200)):r()}static show(t,e,n={}){const{data:i,modal:s=!1,closable:r=!0,minimizable:o=!1,draggable:a=!1,output:c=!0,popupPosition:l="static",origin:h="center-middle",title:d="",threed:u=!1,anchor:p,anchorPin:f="top",anchorOffsetX:m=0,anchorOffsetY:g=0,anchorOffsetZ:y=0,constantSize:b=!0,billboard:_=!0,tether:v=!1,offScreen:x="hide"}=n,w=t.app?.refProvider,M=!!p&&!s&&!a,S=!!t.rootModel?.is3dMode,k=M||S?"absolute":l,A=!k||"static"===k;let E;n.containerRef?E=function(t,e){const n=t.rootModel,i=n?.findById?.(e);if(!i)return Zi(`PopupContainer not found: ${e}`),Promise.reject(new Error(`PopupContainer not found: ${e}`));const s=ni(i.hierarchy);delete s.id,s.position="static",s.left=0,s.top=0;const{width:r=320,height:o=200}=i.bounds||{},a={width:r,height:o,components:[s]},c=t.app;return Promise.resolve(Yu({model:a,mode:0,refProvider:c?.refProvider,dataSubscriptionProvider:c?.dataSubscriptionProvider,dataStorage:c?.dataStorage,baseUrl:c?.baseUrl,fitMode:"both"}))}(t,n.containerRef):n.htmlTemplate?E=function(t){const e={width:320,height:200};let n=null;const i={root:{model:e,bounds:e},data:void 0,fit(){},on(){},off(){},release(){}};return Object.defineProperty(i,"target",{get:()=>n,set:e=>{n=e,e&&(e.innerHTML=t)},configurable:!0}),Promise.resolve(i)}(n.htmlTemplate):e&&(E=w?.create?w.create(e):w?.get(e,!0)),E?.then(e=>{const n=document.createElement("div");n.setAttribute("popup",""),"absolute"==k&&(n.style.zIndex="100");const w=n.style;if(s){const{width:e,height:n}=A?t.rootModel.bounds:t.rootModel.auxOverlay.getBoundingClientRect();Object.assign(w,{position:"absolute",zIndex:"100",left:0,top:0,width:A?`${e}px`:"100%",height:A?`${n}px`:"100%",overflow:"hidden",backgroundColor:"transparent"})}else Object.assign(w,{position:"absolute",display:"inline-block"});n.appendChild(function(t){const e=document.createDocumentFragment(),n=document.createElement("div");n.className="popup-wrap";const i=document.createElement("div");if(i.className="popup-translate",t){const t=document.createElement("div");t.className="popup-title-bar";const e=document.createElement("div");e.className="popup-title",t.appendChild(e);const n=document.createElement("div");n.className="popup-buttons-wrap",n.appendChild(ip("closable","close")),n.appendChild(ip("minimizable","minimize")),n.appendChild(ip("draggable","drag_pan")),t.appendChild(n),i.appendChild(t)}else{const t=document.createElement("div");t.className="popup-buttons-wrap float-right",t.appendChild(ip("closable","close")),t.appendChild(ip("minimizable","minimize")),t.appendChild(ip("draggable","drag_pan")),i.appendChild(t)}const s=document.createElement("div");return s.className="popup-content",i.appendChild(s),n.appendChild(i),e.appendChild(n),e}(!!d));const S=n.querySelector(".popup-content"),{width:E,height:C}=e.root.model;Object.assign(S.style,{width:`${E}px`,height:`${C}px`});const T=document.createElement("style");T.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 /* 배경을 강제하지 않는다 — 로딩된 보드의 자체 배경/투명도가 그대로 보이도록.\n * 보드가 transparent 일 때 popup 안의 round corner / 그림자 효과가 망가지지 않게.\n * 흰 배경이 필요하면 보드 root 의 fillStyle 로 설정하거나 (또는 popup-content\n * CSS 변수를 외부에서 override). */\n background-color: transparent;\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(T);const P=new AbortController,O=P.signal;np.forEach(n=>{const i=(...e)=>t.trigger(n,...e);e.on(n,i),O.addEventListener("abort",()=>e.off?.(n,i))});const D=n.querySelector(".draggable");[...qs,...Ks].forEach(t=>{S.addEventListener(t,t=>t.stopPropagation(),{signal:O})}),[...qs,...Ks].forEach(t=>{n.addEventListener(t,t=>t.stopPropagation(),{signal:O})}),s&&r&&n.addEventListener("click",e=>{e.target===n&&ap.hide(t)},{signal:O});const z=t.rootModel.getOverlay?.({...t,scalable:!k||"static"==k});z?.appendChild(n),function(t,e,n,i,s){const r=t.root;if(r===t)return;op(t);let o=rp.get(r)||[];o=[...o,[t,{div:e,scene:n,ac:i,rafId:s}]],rp.set(r,o)}(t,n,e,P,0);const I=rp.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 R=n.querySelector(".popup-translate");if(a&&($u(R,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),{signal:O}),d?D&&(D.style.display="block"):(R?.addEventListener("mouseenter",()=>{D&&(D.style.display="block")},{signal:O}),R?.addEventListener("mouseleave",()=>{D&&(D.style.display="none")},{signal:O}))),o){const t=n.querySelector(".minimizable");let e=!1;t.addEventListener("click",t=>{t.preventDefault(),e=!e;const i=n.querySelector(".popup-wrap");!function(t,e,n){const i=e.querySelector(".minimizable"),s=e.querySelector(".popup-translate");s&&(n?(i.textContent="crop_square",s.style.height="30px"):(i.textContent="minimize",s.style.height="100%"))}(0,s?i:n,e)},{signal:O}),d?t&&(t.style.display="block"):(R?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:O}),R?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:O}))}if(r){const t=n.querySelector(".closable");d?t&&(t.style.display="block"):(R?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:O}),R?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:O}))}n.querySelector(".closable")?.addEventListener("click",e=>{e.preventDefault(),ap.hide(t)},{signal:O}),n.addEventListener("close-scene",e=>{e.preventDefault(),e.stopPropagation(),ap.hide(t),c&&(t.data=e.detail)},{signal:O}),e.target=S,e.data=i||t.data,e.fit("both"),u&&(e.root.threed=!0);const{x:j,y:L}=t.center,F=t.toScene(j,L),N=s?n.querySelector(".popup-wrap"):n;M?sp({component:t,anchor:p,anchorPin:f,anchorOffset:{x:m,y:g,z:y},popupRoot:n,popupSize:{width:E,height:d?C+30:C},constantSize:b,billboard:_,tetherEnabled:v,offScreen:x,signal:O,popupEntry:I}):Uu(N,k,h,F,e.root.bounds,{width:E,height:C},{title:d}),s?Object.assign(N.style,{position:"absolute",pointerEvents:"none",width:`${E}px`,height:`${d?C+30:C}px`}):Object.assign(N.style,{pointerEvents:"none",width:`${E}px`,height:`${d?C+30:C}px`});const H=function(t,e,n){const i="true"===t.dataset.perspectiveCss3d;t.style.opacity="0";const s=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();i||(t.style.transform=`${s} scale(0)`),t.style.display="block";let r=0;const o=Date.now(),a=()=>{if(n?.aborted)return;const c=Math.min((Date.now()-o)/200,1);t.style.opacity=String(c),i||(t.style.transform=`${s} scale(${c})`.trim()),c<1?r=requestAnimationFrame(a):e&&e()};return r=requestAnimationFrame(a),r}(n,()=>{s&&(n.style.backgroundColor="rgba(0,0,0,0.3)"),I?.tether&&(I.tether.svg.style.opacity="1")},O);I&&(I.rafId=H)},t=>{Zi("cannot fetch board: "+e,t)})}}th.onBeforeDispose(t=>ap.hideAll(t));class cp extends Kl{get showMoveHandle(){return!1}constructor(t,e){super(t,e),this._element=null,this._firstDrawReported=!1,t.translate=t.translate||{x:0,y:0},this._draw_reserved=!1,this.__draw__=()=>{if(this._draw_reserved=!1,Li.enabled){const t=performance.now();this.trigger("redraw"),this.reflow(),this.draw();const e=performance.now()-t;Li.drawCount++,Li.drawTimeSum+=e,Li.drawTimeLast=e,Li.countFrame()}else this.trigger("redraw"),this.reflow(),this.draw();this._firstDrawReported||(this._firstDrawReported=!0,this.app?.loadTracker?.markFirstRender())},this.throttle_render=()=>{this._draw_reserved||requestAnimationFrame(this.__draw__),this._draw_reserved=!0}}get element(){return this._element}set element(t){this._element=t}fitSize(t,e,n,i){if(this.target){if(e){const t=getComputedStyle(this.target);n=n||(t?parseFloat(t.getPropertyValue("width")):this.target.clientWidth),i=i||(t?parseFloat(t.getPropertyValue("height")):this.target.clientHeight)}else n=this.model.width,i=this.model.height;"CANVAS"==t.tagName&&(t.setAttribute("width",n*Xs),t.setAttribute("height",i*Xs)),t.style.width=n+"px",t.style.height=i+"px"}}resize(){this.fitSize(this.element,!0)}isLayer(){return!0}get showOverflow(){return this.app.isEditMode}get anchors(){}createElement(){const t=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:i}=this.model;t.clearRect(0,0,t.canvas.width,t.canvas.height),e&&t.translate(e.x*Xs,e.y*Xs),t.scale(n.x*Xs,n.y*Xs),i&&t.rotate(i)}get rotatePoint(){return{x:0,y:0}}contains(t,e){return!1}invalidate(){Li.enabled&&Li.invalidateCount++,this.throttle_render()}move(t){const e=this.get("translate")||{x:0,y:0};this.set({translate:{x:e.x+t.x,y:e.y+t.y}})}centerTo(t,e){const n=t.rootModel.toLocal(this.canvas.clientWidth/2,this.canvas.clientHeight/2),{x:i,y:s}=t.center,{x:r,y:o}=t.fromParent(i,s),{x:a,y:c}=t.toScene(r,o),{x:l,y:h}=t.rootModel.get("translate"),{x:d,y:u}=t.rootModel.get("scale");e?ka({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 lp extends cp{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){return t?t.scalable?this.context2D:this.auxContext2D:this.context2D}draw(t){this.canvas&&this.element&&(t=t||this.getContext(void 0))&&(this.auxContext2D.clearRect(0,0,this.auxCanvas.width,this.auxCanvas.height),this.auxContext2D.save(),this.auxContext2D.scale(Xs,Xs),super.draw(t),this.auxContext2D.restore())}}var hp,dp,up,pp;!function(t){t.CANVAS="canvas",t.DOM="dom"}(hp||(hp={}));class fp{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;Xr.getInstance().addOverlay(t)}}determineOptimalMode(){return!1!==this.options.animation?hp.DOM:hp.CANVAS}start(){if(!this.isActive&&(this.isActive=!0,this.mode===hp.DOM)){this.overlay?(this.createDOMElements(),this.target.on("change",this.handleTargetChange,this),this.target.on("removed",this.handleTargetRemoved,this)):(Ji("오버레이가 설정되지 않아 DOM 모드 데코레이터를 시작할 수 없습니다."),this.isActive=!1)}}stop(){this.isActive&&(this.isActive=!1,this.mode===hp.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===hp.DOM&&this.isActive&&this.updateDOMElements()}render(t,e){return!(this.mode!==hp.CANVAS||!this.isActive)&&this.renderCanvas(t,e)}removeDOMElements(){this.element&&this.element.parentNode&&(this.element.parentNode.removeChild(this.element),this.element=null)}updateDOMElements(){this.removeDOMElements(),this.createDOMElements()}getComponentPosition(){const{left:t,top:e,width:n,height:i}=this.target.bounds;if("function"==typeof this.target.toGlobal)try{const{x:s,y:r}=this.target.toGlobal(t,e,this.target.rootModel);return{x:s,y:r,width:n,height:i}}catch(t){Ji("좌표 변환 실패, 기본값 사용:",t)}return{x:t,y:e,width:n,height:i}}handleTargetChange(t,e){this.target.disposed?this.stop():this.invalidate()}handleTargetRemoved(){this.stop()}invalidate(){}}class mp extends fp{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:hp.DOM,...n}),this.vectorElement=null,this.animationElements=[],this.svgContainer=null,this.animationElement=null}getDecoratorType(){return this.constructor.DECORATOR_TYPE}dispose(){this.removeDOMElements()}determineOptimalMode(){return hp.DOM}renderCanvas(t,e){return Ji("VectorDecorator는 Canvas 렌더링을 지원하지 않습니다. DOM 모드를 사용하세요."),!1}getSvgContainer(){if(!this.overlay)throw new Error("오버레이 요소가 없습니다.");if(!mp.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),mp.svgContainerCache.set(this.overlay,t)}return mp.svgContainerCache.get(this.overlay)}getOrCreateDecoratorGroup(t=!1){const e=this.getSvgContainer(),n=this.getVectorGroupId(),i=this.getDecoratorType();let s=e.querySelector(`g[data-decorator-type-container="${i}"]`);if(!s){s=document.createElementNS("http://www.w3.org/2000/svg","g"),s.setAttribute("data-decorator-type-container",i),s.setAttribute("class",`${i}-container`),e.appendChild(s);const t=document.createElementNS("http://www.w3.org/2000/svg","defs");t.setAttribute("data-defs-for",i),s.appendChild(t)}let r=s.querySelector(`g[data-decorator-group-id="${n}"]`);if(!r){const{id:t}=this.target.state;return r=document.createElementNS("http://www.w3.org/2000/svg","g"),r.setAttribute("data-decorator-group-id",n),r.setAttribute("data-decorator-type",i),t&&r.setAttribute("data-component-id",t),s.appendChild(r),r}if(t)for(;r.firstChild;)r.removeChild(r.firstChild);return r}getDefsForType(){const t=this.getSvgContainer(),e=this.getDecoratorType();let n=t.querySelector(`g[data-decorator-type-container="${e}"]`);n||(this.getOrCreateDecoratorGroup(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`));let i=n.querySelector(`defs[data-defs-for="${e}"]`);return i||(i=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.setAttribute("data-defs-for",e),n.appendChild(i)),i}getDecoratorGroup(){const t=this.getSvgContainer(),e=this.getVectorGroupId(),n=t.querySelector(`g[data-decorator-group-id="${e}"]`);if(n)return n}createFadeAnimation(t=0,e=1,n=1e3,i={}){const s=document.createElementNS("http://www.w3.org/2000/svg","animate");return s.setAttribute("attributeName","opacity"),s.setAttribute("from",t.toString()),s.setAttribute("to",e.toString()),s.setAttribute("dur",`${n}ms`),i.delay&&s.setAttribute("begin",`${i.delay}ms`),s.setAttribute("fill","freeze"),i.repeat?s.setAttribute("repeatCount","indefinite"):s.setAttribute("repeatCount","1"),s}createTranslateAnimation(t,e=[],n=1e3,i={}){const s=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return s.setAttribute("attributeName","transform"),s.setAttribute("type","translate"),s.setAttribute("values",t.join(";")),e.length>0&&s.setAttribute("keyTimes",e.join(";")),s.setAttribute("dur",`${n}ms`),i.delay&&s.setAttribute("begin",`${i.delay}ms`),i.repeat?s.setAttribute("repeatCount","indefinite"):s.setAttribute("repeatCount","1"),s}createRotateAnimation(t=0,e=360,n=0,i=0,s=1e3,r={}){const o=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return o.setAttribute("attributeName","transform"),o.setAttribute("type","rotate"),o.setAttribute("from",`${t} ${n} ${i}`),o.setAttribute("to",`${e} ${n} ${i}`),o.setAttribute("dur",`${s}ms`),r.delay&&o.setAttribute("begin",`${r.delay}ms`),r.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 Xu(t,e,n)}updatePosition(){if(!this.vectorElement)return;const t=this.options,{left:e,top:n}=this.target.bounds,i=this.projectComponentPoint(this.target,e,n);if(!i)return;const s=i.x+(t.x??0),r=i.y+(t.y??0);this.vectorElement.setAttribute("transform",`translate(${s}, ${r})`)}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=mp.svgContainerCache.get(this.overlay);if(!t)return;const e=this.getVectorGroupId(),n=this.getDecoratorType(),i=t.querySelector(`g[data-decorator-type-container="${n}"]`);if(i){const t=i.querySelector(`g[data-decorator-group-id="${e}"]`);if(t&&(this.vectorElement&&(this.vectorElement===t||t.contains(this.vectorElement))&&(this.vectorElement=null),this.animationElements=this.animationElements.filter(e=>!t.contains(e)),t.remove()),!i.querySelector("g[data-decorator-group-id]")){const t=i.querySelector(`defs[data-defs-for="${n}"]`);t&&t.remove(),i.remove()}}0===t.children.length&&(t.remove(),mp.svgContainerCache.delete(this.overlay))}catch(t){Zi("벡터 요소 제거 실패:",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===hp.DOM&&this.isActive&&this.updateDOMElements()}touch(){}applyFadeValue(t){if(this.vectorElement){const e=t.toFixed(2);this.vectorElement.setAttribute("opacity",e)}}applyRotationValue(t){if(this.vectorElement){const e=this.getComponentBounds(),n=e.width/2,i=e.height/2,s=(180*t/Math.PI).toFixed(1);this.vectorElement.setAttribute("transform",`rotate(${s} ${n} ${i})`)}}applyTranslateValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("translate")){const i=n.replace(/translate\([^)]+\)/,`translate(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} translate(${t}, ${e})`.trim())}}applyScaleValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("scale")){const i=n.replace(/scale\([^)]+\)/,`scale(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} scale(${t}, ${e})`.trim())}}getComponentBounds(){return this.target&&this.target.bounds?this.target.bounds:{top:0,left:0,width:100,height:100}}}mp.svgContainerCache=new WeakMap,mp.DECORATOR_TYPE="vector";class gp extends fp{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 hp.CANVAS}createDOMElements(){Ji("RasterDecorator는 DOM 렌더링을 지원하지 않습니다. Canvas 모드를 사용하세요.")}setAnimationState(t=3e3,e=!1){gp.animationStateMap.set(this.target,{startTime:Date.now(),duration:t,repeat:e})}getAnimationState(){const t=gp.animationStateMap.get(this.target);if(!t)return{delta:0,finished:!0};const{startTime:e,duration:n,repeat:i}=t,s=Date.now()-e;let r=Math.min(1,s/n),o=r>=1;return i&&o&&(gp.animationStateMap.set(this.target,{startTime:Date.now(),duration:n,repeat:i}),r=0,o=!1),{delta:r,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(),gp.animationStateMap.delete(this.target)}applyTransform(t,e,n){const i=this.options,s=i.scale||1,r=i.rotation||0;if(1!==s||0!==r){if(t.translate(e,n),0!==r){const e=r*Math.PI/180;t.rotate(e)}1!==s&&t.scale(s,s),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}}gp.animationStateMap=new WeakMap;class yp extends mp{constructor(t,e,n={}){super(t,e,{size:1,showId:!1,animation:!1,...n})}createDOMElements(){if(this.overlay)try{const t=this.getOrCreateDecoratorGroup(!0);t.setAttribute("transform","translate(0, 0)");const{size:e=1,showId:n=!1,duration:i=3e3,repeat:s=!0}=this.options,r=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",r),o.setAttribute("stroke",r),o.setAttribute("stroke-width","1"),o.setAttribute("class","bouncing-arrow");const a=[];if(this.options.animation){const t=this.createBounceAnimation(i,s);if(a.push(t),this.options.fadeOut){const t=this.createFadeAnimation(1,0,i,{repeat:s});a.push(t)}}if(this.addAnimations(o,a),t.appendChild(o),n&&this.target.state?.id){const n=this.createArrowLabel(0,0,r,this.target.state.id,e);if(this.options.animation){const t=[],e=this.createBounceAnimation(i,s);if(t.push(e),this.options.fadeOut){const e=this.createFadeAnimation(1,0,i,{repeat:s});t.push(e)}this.addAnimations(n,t)}t.appendChild(n)}this.vectorElement=t,this.updatePosition(),this.options.animation&&this.startAnimations()}catch(t){Zi("화살표 SVG 요소 생성 실패:",t)}}createArrowPath(t,e,n=1){const i=n/this.getScale();return`\n M${t-10*i},${e-16*i} \n L${t+10*i},${e-16*i} \n L${t+10*i},${e-8*i} \n L${t+16*i},${e-8*i} \n L${t},${e} \n L${t-16*i},${e-8*i} \n L${t-10*i},${e-8*i} \n Z\n `}getScale(){try{if(this.target.rootModel&&"number"==typeof this.target.rootModel.scale)return this.target.rootModel.scale||1}catch(t){Ji("스케일 계산 실패, 기본값 사용",t)}return 1}createBounceAnimation(t,e){const n=["0,-10"],i=["0"];for(let t=1;t<=20;t++){const e=t/20;let s=Math.pow(e,.5).toFixed(3);parseFloat(i[i.length-1])>=parseFloat(s)&&(s=(parseFloat(i[i.length-1])+.01).toFixed(3)),n.push("0,0"),n.push("0,-10"),i.push(s),i.push((parseFloat(s)+.01).toFixed(3))}return i[i.length-1]="1.000",this.createTranslateAnimation(n,i,t,{repeat:e})}createArrowLabel(t,e,n,i,s=1){const r=document.createElementNS("http://www.w3.org/2000/svg","g");r.setAttribute("class","bouncing-arrow-label");const o=document.createElementNS("http://www.w3.org/2000/svg","rect");o.setAttribute("x",`${t+20*s}`),o.setAttribute("y",""+(e-20*s)),o.setAttribute("width",""+40*s),o.setAttribute("height",""+20*s),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*s}`),a.setAttribute("y",""+(e-6*s)),a.setAttribute("fill","white"),a.setAttribute("font-size",12*s+"px"),a.setAttribute("text-anchor","middle"),a.textContent=i,r.appendChild(o),r.appendChild(a),r}startAnimations(){setTimeout(()=>{this.animationElements.forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&t.beginElement()}catch(t){Zi("애니메이션 시작 오류:",t)}})},10)}invalidate(){this.updatePosition()}updatePosition(){if(!this.vectorElement)return;const{left:t,top:e,width:n}=this.target.bounds,i=this.projectComponentPoint(this.target,t+n/2,e);if(!i)return;const s=Math.max(i.x,20),r=Math.max(i.y,20);this.vectorElement.setAttribute("transform",`translate(${s}, ${r})`)}}yp.DECORATOR_TYPE="bouncing-arrow",function(t){t.ROTATE="rotate",t.TRANSLATE_X="translateX",t.TRANSLATE_Y="translateY",t.SCALE="scale",t.FADE="fade"}(dp||(dp={})),function(t){t.VIBRATION="vibration",t.ROTATION="rotation",t.HEARTBEAT="heartbeat",t.MOVING="moving",t.OUTLINE="outline",t.FADE="fade",t.WAYPOINT="waypoint"}(up||(up={})),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"}(pp||(pp={}));class bp extends mp{constructor(t,e,n={}){const{animations:i,...s}=n;super(t,e,{icon:"arrow_forward",size:24,color:"#FF0000",deltaX:0,deltaY:0,...s}),this.animations=[],this._location=null,this.element=null,this._delta={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0},this.animations=this.createAnimations(i)}delta(t,e){if(!t)return this._delta;switch(typeof t){case"object":this._delta={...this._delta,...t};break;case"string":if(void 0===e)return this._delta[t];this._delta[t]=e}const{tx:n,ty:i,sx:s,sy:r,theta:o,fade:a}=this._delta;return this.element&&Object.assign(this._getElement().style,{opacity:1-a,transform:`rotate(${o}rad) translate(${n}px, ${i}px) scale(${s}, ${r}) perspective(1px)`}),this._delta}getScaledSize(){const t=this.options.size||24,{x:e}=this.target.rootModel?.state.scale||{x:1},{x:n}=this.target.state.scale||{x:1};return t*e*n}get location(){if(this._location)return this._location;const{location:t,position:e,size:n}=this.options,{bounds:i}=this.target,{left:s,top:r,width:o,height:a}=i,c=n/2;let l;switch(e||t||pp.CENTER){case pp.TOP_LEFT:case"top-left":l={x:s,y:r-n};break;case pp.TOP:case"top":l={x:s+(o-n)/2,y:r-n};break;case pp.TOP_RIGHT:case"top-right":l={x:s+o-n,y:r-n};break;case pp.BOTTOM_LEFT:case"bottom-left":l={x:s,y:r+a};break;case pp.BOTTOM:case"bottom":l={x:s+(o-n)/2,y:r+a};break;case pp.BOTTOM_RIGHT:case"bottom-right":l={x:s+o-n,y:r+a};break;case pp.LEFT_TOP:case"left-top":l={x:s-n,y:r};break;case pp.LEFT:case"left":l={x:s-n,y:r+(a-n)/2};break;case pp.LEFT_BOTTOM:case"left-bottom":l={x:s-n,y:r+(a-n)};break;case pp.RIGHT_TOP:case"right-top":l={x:s+o,y:r};break;case pp.RIGHT:case"right":l={x:s+o,y:r+(a-n)/2};break;case pp.RIGHT_BOTTOM:case"right-bottom":l={x:s+o,y:r+(a-n)};break;case pp.TOP_LEFT_CORNER:case"top-left-corner":l={x:s-c,y:r-c};break;case pp.TOP_RIGHT_CORNER:case"top-right-corner":l={x:s+o-c,y:r-c};break;case pp.BOTTOM_LEFT_CORNER:case"bottom-left-corner":l={x:s-c,y:r+a-c};break;case pp.BOTTOM_RIGHT_CORNER:case"bottom-right-corner":l={x:s+o-c,y:r+a-c};break;case pp.CENTER:default:l={x:s+o/2-n/2,y:r+a/2-n/2}}return this._location=this.toGlobal(l.x,l.y),this._location}_getElement(){return this.element||this._createElementIfNeeded(),this.element}_createElementIfNeeded(){if(this.element)return;const{icon:t="arrow_forward",color:e="#FF0000"}=this.options,n=this.getScaledSize(),{x:i,y:s}=this.location,r=document.createElement("div");r.setAttribute("scene","animated-icon"),Object.assign(r.style,{position:"absolute",fontVariationSettings:"'FILL' 1",fontFamily:"Material Symbols Outlined",fontSize:n+"px",width:n+"px",height:n+"px",lineHeight:n+"px",padding:0,margin:0,color:e,textAlign:"center",verticalAlign:"middle",left:i+"px",top:s+"px",pointerEvents:"none"}),r.textContent=t,this.element=r}updateIconSizeAndPosition(){if(!this.element)return;this._location=null;const t=this.getScaledSize(),{x:e,y:n}=this.location;Object.assign(this.element.style,{fontSize:t+"px",width:t+"px",height:t+"px",lineHeight:t+"px",left:e+"px",top:n+"px"})}touch(){}invalidate(){this.updateIconSizeAndPosition()}start(){if(super.start(),this.isActive){if(this.overlay&&this._getElement().parentNode!==this.overlay&&this.overlay.appendChild(this._getElement()),this.target?.root?.app?.suppressAnimations)return;this.animations.forEach(t=>t.start())}}stop(){this.animations.forEach(t=>t.stop()),this.element&&this._getElement().parentNode&&this._getElement().parentNode.removeChild(this._getElement()),this._location=null,super.stop()}get center(){const t=this.getScaledSize(),{x:e,y:n}=this.location;return{x:e+t/2,y:n+t/2}}toGlobal(t,e){const{tx:n,ty:i}=this._delta;return this.projectComponentPoint(this.target,t+n,e+i)??this.target.toGlobal(t+n,e+i)}get root(){return this.target.root}createDOMElements(){this._getElement()}updateDOMElements(){this.element?this.updateIconSizeAndPosition():this._getElement()}updatePosition(){this.updateIconSizeAndPosition()}createAnimations(t){if(Array.isArray(t))return t.map(t=>("theta"in t&&(t={...t,theta:t.theta*(Math.PI/180)}),Ca(this,t)));if(t){const e={...t};return"theta"in e&&(e.theta=e.theta*(Math.PI/180)),[Ca(this,e)]}return[]}}bp.DECORATOR_TYPE="animated-icon";class _p extends mp{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{const t=this.getOrCreateDecoratorGroup(!0);this.decoratorGroup=t;const e=this.getDefsForType(),n=this.getVectorGroupId();this.elementId=`${n}-border`;const{color:i="#FF0000",animation:s=!1}=this.options,{fillStyle:r}=this.target.state||{},o=this.createFilter(this.elementId,this.options.fillStyle||r||"rgba(0, 0, 0, 0.5)");if(e.appendChild(o),s){const t=this.createGradient(this.elementId,i);e.appendChild(t)}const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("fill","none"),a.setAttribute("stroke-width",(this.options.lineWidth||2).toString()),a.setAttribute("stroke-linejoin","round"),a.setAttribute("pointer-events","none"),a.setAttribute("class","border-highlighting-path"),a.setAttribute("filter",`url(#${this.elementId}-filter)`),s?a.setAttribute("stroke",`url(#${this.elementId})`):a.setAttribute("stroke",i),t.appendChild(a),this.pathElement=a,this.vectorElement=t,this.updatePathData(),this.options.animation&&this.startAnimations()}catch(t){Zi("테두리 하이라이팅 요소 생성 실패:",t)}}updatePathData(){if(!this.pathElement)return;this.pathElement.setAttribute("visibility","visible"),this.pathElement.setAttribute("opacity","1"),this.decoratorGroup&&(this.decoratorGroup.setAttribute("visibility","visible"),this.decoratorGroup.setAttribute("opacity","1"));const t=this.getPathPoints(),e=this.createOffsetPath(t,this.options.distance),{round:n=0}=this.target.state||{},i=this.pointsToPathData(e,n);this.pathElement.setAttribute("d",i)}invalidate(){this.updatePathData()}startAnimations(){if(!this.isActive||!this.options.animation||!this.pathElement)return;if(this.target?.root?.app?.suppressAnimations)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){Zi("애니메이션 시작 오류:",t)}})}}}getPathPoints(){if(!this.target.path||!Array.isArray(this.target.path)){const{left:t,top:e,width:n,height:i}=this.target.bounds;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}return this.target.path.map(t=>this.target.toGlobal(t.x,t.y))}createOffsetPath(t,e){const n=[],i=t.length;for(let s=0;s<i;s++){const r=t[(s-1+i)%i],o=t[s],a=t[(s+1)%i],c=o.x-r.x,l=o.y-r.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}),m={x:o.x+f.x*e,y:o.y+f.y*e};n.push(m)}return n}normalize(t){const e=Math.sqrt(t.x*t.x+t.y*t.y);return{x:t.x/e||0,y:t.y/e||0}}pointsToPathData(t,e=0){if(t.length<2)return"";let n="";const i=t.length,s=(t,e,n)=>{const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(i*i+s*s);return{x:t.x+i/r*n,y:t.y+s/r*n}};for(let r=0;r<i;r++){const o=t[r],a=t[(r+1)%i],c=t[(r-1+i)%i],l=Math.sqrt((o.x-c.x)**2+(o.y-c.y)**2),h=Math.sqrt((o.x-a.x)**2+(o.y-a.y)**2),d=Math.min(e,l/2,h/2),u=s(o,c,d),p=s(o,a,d);n+=0===r?`M${u.x},${u.y}`:` L${u.x},${u.y}`,n+=` Q${o.x},${o.y} ${p.x},${p.y}`}return n+=" Z",n}createFilter(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","filter");n.setAttribute("id",`${t}-filter`);const i=document.createElementNS("http://www.w3.org/2000/svg","feFlood");i.setAttribute("flood-color",e),i.setAttribute("result","flood");const s=document.createElementNS("http://www.w3.org/2000/svg","feComposite");s.setAttribute("in","flood"),s.setAttribute("in2","SourceAlpha"),s.setAttribute("operator","in"),s.setAttribute("result","mask");const r=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"),r.appendChild(o),r.appendChild(a),n.appendChild(i),n.appendChild(s),n.appendChild(r),n}createGradient(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");n.setAttribute("id",t),n.setAttribute("x1","0%"),n.setAttribute("y1","0%"),n.setAttribute("x2","100%"),n.setAttribute("y2","0%");const i=this.alterColor(e,120),s=this.alterColor(e,240),r=document.createElementNS("http://www.w3.org/2000/svg","stop");r.setAttribute("offset","0%"),r.setAttribute("stop-color",e);const o=document.createElementNS("http://www.w3.org/2000/svg","animate");o.setAttribute("attributeName","stop-color"),o.setAttribute("values",`${e};${i};${s};${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",s);const c=document.createElementNS("http://www.w3.org/2000/svg","animate");return c.setAttribute("attributeName","stop-color"),c.setAttribute("values",`${s};${e};${i};${s}`),c.setAttribute("dur","5s"),c.setAttribute("repeatCount","indefinite"),r.appendChild(o),a.appendChild(c),n.appendChild(r),n.appendChild(a),n}alterColor(t,e){const n=this.convertToHex(t),i=parseInt(n.substring(1,3),16),s=parseInt(n.substring(3,5),16),r=parseInt(n.substring(5,7),16),o=this.rgbToHsl(i,s,r);o[0]=(o[0]+e/360)%1;const a=this.hslToRgb(o[0],o[1],o[2]);return`#${a[0].toString(16).padStart(2,"0")}${a[1].toString(16).padStart(2,"0")}${a[2].toString(16).padStart(2,"0")}`}rgbToHsl(t,e,n){t/=255,e/=255,n/=255;const i=Math.max(t,e,n),s=Math.min(t,e,n);let r=0,o=0;const a=(i+s)/2;if(i!==s){const c=i-s;switch(o=a>.5?c/(2-i-s):c/(i+s),i){case t:r=(e-n)/c+(e<n?6:0);break;case e:r=(n-t)/c+2;break;case n:r=(t-e)/c+4}r/=6}return[r,o,a]}hslToRgb(t,e,n){let i,s,r;if(0===e)i=s=r=n;else{const o=(t,e,n)=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t),a=n<.5?n*(1+e):n+e-n*e,c=2*n-a;i=o(c,a,t+1/3),s=o(c,a,t),r=o(c,a,t-1/3)}return[Math.round(255*i),Math.round(255*s),Math.round(255*r)]}convertToHex(t){if(/^#([0-9A-F]{6})$/i.test(t))return t;const e=document.createElement("canvas");e.width=1,e.height=1;const n=e.getContext("2d");if(!n)return"#FF0000";n.fillStyle=t,n.fillRect(0,0,1,1);const i=n.getImageData(0,0,1,1).data;return`#${i[0].toString(16).padStart(2,"0")}${i[1].toString(16).padStart(2,"0")}${i[2].toString(16).padStart(2,"0")}`}start(){super.start(),this.isActive&&this.options.animation&&this.startAnimations()}removeDOMElements(){try{if(this.pathElement&&this.pathElement.parentNode&&this.pathElement.parentNode.removeChild(this.pathElement),this.pathElement=null,this.overlay){const t=this.getDefsForType();if(t&&this.elementId){const e=t.querySelector(`#${this.elementId}-filter`);e&&e.remove();const n=t.querySelector(`#${this.elementId}`);n&&n.remove()}}super.removeDOMElements()}catch(t){Zi("테두리 하이라이팅 요소 제거 중 오류:",t)}}}_p.DECORATOR_TYPE="border-highlighting";class vp extends mp{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",...n}),this.textElements=[],this.rectElements=[]}updateDOMElements(){if(!this.target.anchors||!this.target.anchors.length)return void this.removeDOMElements();const t=this.options,e=this.target.anchors,n=this.getOrCreateDecoratorGroup(!0);this.textElements=[],this.rectElements=[];const i=this.getComponentBounds();e.forEach(e=>{const{name:s,position:r}=e;let{x:o,y:a}=r||{};if(!s)return;let c=this.calculateOffsetX(o,i),l=this.calculateOffsetY(a,i);const h=this.projectComponentPoint(this.target,o,a);if(!h)return;o=h.x,a=h.y;const d=document.createElementNS("http://www.w3.org/2000/svg","text");d.setAttribute("fill",t.textColor),d.setAttribute("font-family",t.fontFamily),d.setAttribute("font-size",t.fontSize),d.textContent=s,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 m=document.createElementNS("http://www.w3.org/2000/svg","rect");m.setAttribute("x",(o+c).toString()),m.setAttribute("y",(a+l).toString()),m.setAttribute("width",(p+6).toString()),m.setAttribute("height",(f+6).toString()),m.setAttribute("rx",t.cornerRadius.toString()),m.setAttribute("ry",t.cornerRadius.toString()),m.setAttribute("fill",t.bgColor),n.appendChild(m),n.appendChild(d),this.rectElements.push(m),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()}}vp.DECORATOR_TYPE="anchors";class xp extends mp{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",offsetX:3,offsetY:-8,animation:!1,...n}),this.textElement=null,this.backgroundElement=null,this.currentTag=""}createDOMElements(){const t=this.target.decotag;if(!t)return;this.currentTag=t;const{fontFamily:e,fontSize:n,textColor:i,padding:s,cornerRadius:r,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",`${s}`),this.textElement.setAttribute("y",`-${n}`),this.textElement.setAttribute("font-family",e),this.textElement.setAttribute("font-size",n),this.textElement.setAttribute("fill",i),this.textElement.setAttribute("dominant-baseline","middle"),h.appendChild(this.textElement);const d=this.textElement.getBBox();if(this.backgroundElement=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.backgroundElement.setAttribute("x",(d.x-s).toString()),this.backgroundElement.setAttribute("y",(d.y-s).toString()),this.backgroundElement.setAttribute("width",(d.width+2*s).toString()),this.backgroundElement.setAttribute("height",(d.height+2*s).toString()),this.backgroundElement.setAttribute("rx",r.toString()),this.backgroundElement.setAttribute("ry",r.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()}}xp.DECORATOR_TYPE="decotag";class wp extends mp{constructor(t,e,n={}){super(t,e,{arrowColor:"#FFA500",arrowHeadLength:12,lineWidth:1.5,startAlpha:.6,endAlpha:1,animated:!0,animationDuration:5e3,repeat:!1,...n}),this.currentMappings=null,this.cachedArrows=[],this._incomingTimer=null}findIncomingSources(){const t=this.target.root;if(!t)return[];const e=this.target.state?.id;if(!e)return[];const n=[];return t.traverse(i=>{if(i===this.target)return;const s=i.model?.mappings;if(s)for(const r of s){if(!r.target)continue;if(r.target===`#${e}`){n.push({from:i,to:this.target});break}const s=t.findAll(r.target,i);if(s?.some(t=>t===this.target)){n.push({from:i,to:this.target});break}}}),n}appendArrow(t,e,n,i,s,r){const o=e.center,a=n.center,c=this.projectComponentPoint(e,o.x,o.y),l=this.projectComponentPoint(n,a.x,a.y);if(!c||!l)return;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,r.arrowHeadLength),u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",h),u.setAttribute("stroke",s),u.setAttribute("stroke-width",String(r.lineWidth||2)),u.setAttribute("fill","none"),u.setAttribute("data-source-id",e.state?.id||""),u.setAttribute("data-target-id",n.state?.id||"");const p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d",d),p.setAttribute("fill",i),p.setAttribute("stroke","none"),t.appendChild(u),t.appendChild(p)}createDOMElements(){this.removeDOMElements();const t=this.target.mappings&&this.target.mappings.length>0;this.currentMappings=this.target.mappings;const e=this.options,n=e.arrowColor||"#FFA500",i=this.getOrCreateDecoratorGroup(!0),s=this.getDefsForType(),r=`data-spread-style-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,o=document.createElementNS("http://www.w3.org/2000/svg","style");o.setAttribute("id",r),o.textContent=`\n @keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: ${e.repeat?"0.2":"0"}; }\n }\n .arrow-animated {\n animation: fadeOut ${e.animationDuration||2e3}ms linear ${e.repeat?"infinite":"1"} forwards;\n }\n `,s.appendChild(o);const a=Date.now(),c=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),l=`arrow-gradient-out-${a}-${c}`,h=this.createGradient(l,n,e);s.appendChild(h);const d=wp.INCOMING_ARROW_COLOR,u=`arrow-gradient-in-${a}-${c}`,p=this.createGradient(u,d,e);s.appendChild(p);const f=document.createElementNS("http://www.w3.org/2000/svg","g");if(f.setAttribute("class",e.animated?"arrow-animated":""),i.appendChild(f),this.cachedArrows=[],t){this.target.mappings.forEach(t=>{const i=this.target.root.findAll(t.target,this.target);i?.length&&i.forEach(t=>{t!==this.target&&(this.cachedArrows.push({from:this.target,to:t}),this.appendArrow(f,this.target,t,n,`url(#${l})`,e))})})}this.vectorElement=i,this._incomingTimer=setTimeout(()=>{if(this._incomingTimer=null,!this.vectorElement)return;this.findIncomingSources().forEach(({from:t})=>{this.cachedArrows.push({from:t,to:this.target}),this.appendArrow(f,t,this.target,d,`url(#${u})`,e)})},wp.INCOMING_DEBOUNCE_MS)}createGradient(t,e,n){const i=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");i.setAttribute("id",t),i.setAttribute("gradientUnits","userSpaceOnUse");const s=document.createElementNS("http://www.w3.org/2000/svg","stop");s.setAttribute("offset","0%"),s.setAttribute("stop-color",e),s.setAttribute("stop-opacity",(n.startAlpha||.5).toString());const r=document.createElementNS("http://www.w3.org/2000/svg","stop");return r.setAttribute("offset","100%"),r.setAttribute("stop-color",e),r.setAttribute("stop-opacity",(n.endAlpha||1).toString()),i.appendChild(s),i.appendChild(r),i}createArrowPaths(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=Math.atan2(s,i),o=e.x+n*Math.cos(r+wp.ARROW_ANGLE_1),a=e.y+n*Math.sin(r+wp.ARROW_ANGLE_1),c=e.x+n*Math.cos(r+wp.ARROW_ANGLE_2),l=e.y+n*Math.sin(r+wp.ARROW_ANGLE_2);return{linePath:`M ${t.x} ${t.y} L ${e.x} ${e.y}`,headPath:`M ${e.x} ${e.y} L ${o} ${a} L ${c} ${l} Z`}}updateDOMElements(){if(!this.target.app?.isEditMode)return void this.removeDOMElements();this.target.mappings!==this.currentMappings?(this.removeDOMElements(),requestAnimationFrame(()=>{this.createDOMElements()})):this.vectorElement&&this.updatePosition()}updatePosition(){const t=this.getDecoratorType(),e=this.getSvgContainer().querySelector(`g[data-decorator-type-container="${t}"]`);if(!e)return;const n=this.getVectorGroupId(),i=e.querySelector(`g[data-decorator-group-id="${n}"]`);if(!i)return;const s=this.options,r=i.querySelector("g.arrow-animated")||i,o=Array.from(r.querySelectorAll('path[fill="none"]')),a=Array.from(r.querySelectorAll('path[stroke="none"]'));if(0===o.length)return;const c=Math.min(o.length,a.length,this.cachedArrows.length);for(let t=0;t<c;t++){const{from:e,to:n}=this.cachedArrows[t],i=e.center,r=n.center,c=this.projectComponentPoint(e,i.x,i.y),l=this.projectComponentPoint(n,r.x,r.y);if(!c||!l)continue;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,s.arrowHeadLength);o[t].setAttribute("d",h),a[t].setAttribute("d",d)}}removeDOMElements(){this.currentMappings=null,this.cachedArrows=[],this._incomingTimer&&(clearTimeout(this._incomingTimer),this._incomingTimer=null);try{if(this.overlay){const t=this.getSvgContainer();if(t){const e=this.getDecoratorType(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`);if(n){const t=n.querySelector(`defs[data-defs-for="${e}"]`);if(t){t.querySelectorAll("style").forEach(t=>t.remove());t.querySelectorAll("linearGradient").forEach(t=>t.remove())}}}}this.animationElements=[],super.removeDOMElements()}catch(t){Zi("데이터 스프레드 데코레이터 요소 제거 중 오류:",t)}}invalidate(){this.updatePosition()}}wp.DECORATOR_TYPE="data-spread",wp.ARROW_ANGLE_1=160*Math.PI/180,wp.ARROW_ANGLE_2=200*Math.PI/180,wp.INCOMING_ARROW_COLOR="#4A9EFF",wp.INCOMING_DEBOUNCE_MS=500;class Mp extends mp{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:2,padding:2,fontSize:"12px",fontFamily:"Arial",offsetX:4,offsetY:4,...n}),this.textElements=[],this.rectElements=[]}createDOMElements(){this.updateDOMElements()}updateDOMElements(){if(!this.target.isLine||!this.target.isLine())return void this.removeDOMElements();const{offsetX:t,offsetY:e,padding:n,textColor:i,bgColor:s,cornerRadius:r,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:m,y:g}=f;const y=document.createElementNS("http://www.w3.org/2000/svg","g"),b=document.createElementNS("http://www.w3.org/2000/svg","text");b.setAttribute("text-anchor","middle"),b.setAttribute("dominant-baseline","middle"),b.setAttribute("x","0"),b.setAttribute("y","0"),b.setAttribute("fill",i),b.setAttribute("font-family",a),b.setAttribute("font-size",o),b.textContent=u,c.appendChild(b);const _=b.getBBox();c.removeChild(b);const v=document.createElementNS("http://www.w3.org/2000/svg","rect"),x=_.width+2*(n??0),w=_.height+2*(n??0);m+=(t??0)+x/2,g+=(e??0)+w/2,v.setAttribute("x",(-x/2).toString()),v.setAttribute("y",(-w/2).toString()),v.setAttribute("width",x.toString()),v.setAttribute("height",w.toString()),v.setAttribute("rx",(r??0).toString()),v.setAttribute("ry",(r??0).toString()),v.setAttribute("fill",s),y.appendChild(v),y.appendChild(b),y.setAttribute("transform",`translate(${m}, ${g})`),c.appendChild(y),this.rectElements.push(v),this.textElements.push(b)})}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}}Mp.DECORATOR_TYPE="link",$r.registerDecorator("bouncing-arrow",yp),$r.registerDecorator("animated-icon",bp),$r.registerDecorator("border-highlighting",_p),$r.registerDecorator("anchors",vp),$r.registerDecorator("decotag",xp),$r.registerDecorator("data-spread",wp),$r.registerDecorator("link",Mp);let Sp=0,kp=0,Ap=0,Ep=null;function Cp(){Ap++;const t=performance.now(),e=t-kp;e>=1e3&&(Sp=Math.round(1e3*Ap/e),kp=t,Ap=0),Ep=requestAnimationFrame(Cp)}function Tp(){null!==Ep&&(cancelAnimationFrame(Ep),Ep=null)}function Pp(){return null===Ep&&(kp=performance.now(),Ap=0,Ep=requestAnimationFrame(Cp)),Sp}const Op=function(){if("undefined"==typeof document)return 1;const t=document.createElement("canvas").getContext("2d");return("undefined"!=typeof window&&window.devicePixelRatio||1)/(t&&(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio)||1)}();function Dp(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 zp=Math.sqrt(3);function Ip(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 Rp(t,n,i){switch(t){case"none":default:return null;case"arrow":{const t=zp*n.X,i=n.Y,s=new e.ConeGeometry(i,t,16);return s.rotateZ(-Math.PI/2),s.translate(-t/2,0,0),{mesh:new e.Mesh(s,new e.MeshBasicMaterial)}}case"sharp-arrow":{const t=zp*n.X*1.3,i=.65*n.Y,s=new e.ConeGeometry(i,t,16);return s.rotateZ(-Math.PI/2),s.translate(-t/2,0,0),{mesh:new e.Mesh(s,new e.MeshBasicMaterial)}}case"open-arrow":{const t=zp*n.X,i=n.Y,s=new e.ConeGeometry(i,t,6);return s.rotateZ(-Math.PI/2),s.translate(-t/2,0,0),{mesh:new e.Mesh(s,new e.MeshBasicMaterial({wireframe:!0}))}}case"diamond":{const t=new e.OctahedronGeometry(1);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"oval":{const t=new e.SphereGeometry(1,16,12);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"cross":{const t=Math.max(n.X,n.Y),i=.9*t,s=.25*t,r=.15*t,o=new e.Group,a=[new e.Vector3(1,1,1).normalize(),new e.Vector3(1,-1,-1).normalize(),new e.Vector3(-1,1,-1).normalize(),new e.Vector3(-1,-1,1).normalize()];for(const t of a){const n=new e.CylinderGeometry(s,r,i,6),a=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,1,0),t);n.applyQuaternion(a),n.translate(t.x*i/2,t.y*i/2,t.z*i/2),o.add(new e.Mesh(n,new e.MeshBasicMaterial))}return{group:o}}}}function jp(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Lp(t,n,i,s){const{strokeStyle:r,alpha:o=1,lineWidth:a=2,begin:c="none",beginSize:l="size2",end:h="arrow",endSize:d="size2",label:u}=i,p=(new e.Vector3).subVectors(n,t),f=p.length(),m=new e.Group;if(f<.01)return m;const g=p.clone().normalize(),y=jp(c,a),b=jp(h,a),_=t.clone().add(g.clone().multiplyScalar(y)),v=n.clone().sub(g.clone().multiplyScalar(b));let x;if(Array.isArray(r)&&r.length>=2){const t=r[1];x=new e.Color(t.length>7?t.slice(0,7):t)}else x=new e.Color("string"==typeof r?r:"#00B050");const k=function(t,n,i,s){const{strokeStyle:r,alpha:o=1,lineWidth:a=2,lineDash:c="solid"}=i,l=new S;let h;l.setPositions([t.x,t.y,t.z,n.x,n.y,n.z]);let d=!1;if(Array.isArray(r)&&r.length>=2){const t=new e.Color(r[0].length>7?r[0].slice(0,7):r[0]),n=new e.Color(r[1].length>7?r[1].slice(0,7):r[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 r?r:"#00B050");const{dashed:u,dashSize:p,gapSize:f}=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),m=new M({color:d?16777215:h.getHex(),linewidth:a,worldUnits:!0,vertexColors:d,dashed:u,dashSize:p,gapSize:f,transparent:o<1||Array.isArray(r)&&r.some(t=>t.length>7),opacity:o,resolution:s}),g=new w(l,m);return g.computeLineDistances(),g}(_,v,i,s);m.add(k);const A=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),g),E=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),g.clone().negate()),C=(t,e,n)=>{if(!t)return;const i=t.mesh||t.line2||t.group;if(i){if(i.position.copy(e),i.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(x),e.transparent=o<1,e.opacity=o}else if(t.line2){const e=t.line2.material;e.color.copy(x),e.transparent=o<1,e.opacity=o,e.resolution.copy(s)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color.copy(x),e.transparent=o<1,e.opacity=o,e.resolution&&e.resolution.copy(s)}});m.add(i)}};C(Rp(h,Ip(d,a)),n,A);if(C(Rp(c,Ip(l,a)),t,E),u){const i=(new e.Vector3).addVectors(t,n).multiplyScalar(.5);i.y+=3;const s=function(t,n,i){const s="Arial",r=Dp(256,64),o=r.getContext("2d");o.font=`bold 28px ${s}`;const a=o.measureText(t).width;o.fillStyle=n,o.fillRect(0,0,a+12,40),o.fillStyle="white",o.font=`bold 28px ${s}`,o.textBaseline="top",o.fillText(t,6,6);const c=new e.CanvasTexture(r);c.needsUpdate=!0,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace;const l=new e.SpriteMaterial({map:c,transparent:!0}),h=new e.Sprite(l);h.position.copy(i);const d=(a+12)/40;return h.scale.set(4*d,4,1),h}(u,"string"==typeof r?r:Array.isArray(r)&&r[1]||"#00B050",i);m.add(s)}return m}function Fp(t){return"double"===t?"visible":"hidden"}class Np extends pu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}getObject3dInstance(){return new v(this.component.element)}get rotation(){const{rotationX:t=0,rotationY:e=0,rotation:n=0}=this.component.state;return{x:t-Math.PI/2,y:e,z:-n}}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},s=e.bounds,{tx:r=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0;const c=t.scale.x;e.bounds={left:t.position.x-r+n/2-s.width/2,top:t.position.z-o+i/2-s.height/2,width:s.width,height:s.height};const l=this.component.parent?._realObject,h=l?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+h,rotationX:t.rotation.x+Math.PI/2,rotation:-t.rotation.z,rotationY:t.rotation.y,scale:{x:c,y:c}}),this._suppressOnchange=!1}build(){super.build();const t=this.component.element;if(!t)return;t.style.left="",t.style.top="";const e=Md(this.component.state.material3d);if(t.style.backfaceVisibility=Fp(e.side),this.component.state.screenFixed&&this.component.isContainer?.())return;const{width:n,height:i}=this.component.bounds;t.style.width=n+"px",t.style.height=i+"px"}updateMaterial3d(){super.updateMaterial3d();const t=this.component.element;if(!t)return;const e=Md(this.component.state.material3d);t.style.backfaceVisibility=Fp(e.side)}updateDimension(){if(this.component.state.screenFixed&&this.component.isContainer?.())return;super.updateDimension();const t=this.dimension,e=this.component.element;e&&(e.style.width=t.width+"px",e.style.height=t.height+"px")}applyFocusDim(){this.component.applyElementModelingFaint?.()}updateAlpha(){this.component.applyElementModelingFaint?.()}}const Hp=new Map;let Bp;function Gp(t,e){Hp.set(t,e)}function Vp(t){Bp=t}function Yp(t){const e=t.buildRealObject();if(e)return e;const n=t.model?.type,i=n?Hp.get(n):void 0;if(i)return i(t);if(t.isHTMLElement()){const e=Hp.get("html-overlay-element");if(e)return e(t)}return Bp?.(t)}function Wp(t,n,i){if(!t.hasTextProperty||t.textHidden)return;const s=t._realObject;if(!s?.object3d)return;const{text:r="",bold:o=Qs.BOLD,italic:a=Qs.ITALIC,fontFamily:c=Qs.FONT_FAMILY,fontColor:l=Qs.FONT_COLOR,fontSize:h=Qs.FONT_SIZE,textAlign:d=Qs.TEXT_ALIGN,textBaseline:u=Qs.TEXT_BASELINE,width:p,height:f}=t.model,m=Math.abs(p)||1,g=Math.abs(f)||1,y=document.createElement("textarea"),b=new AbortController;qs.forEach(t=>{y.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:b.signal})}),y.value=r;const _="right"===d||"end"===d?"right":"left"===d||"start"===d?"left":"justify"===d?"justify":"center";let x="0";if("bottom"===u||"alphabetic"===u){const t=1.2*h*Math.max(1,(r.match(/\n/g)||[]).length+1);x=Math.max(0,g-t)+"px"}else if("middle"===u){const t=1.2*h*Math.max(1,(r.match(/\n/g)||[]).length+1);x=Math.max(0,(g-t)/2)+"px"}y.style.cssText=[`width: ${m}px`,`height: ${g}px`,`padding: ${x} 0 0 0`,"margin: 0",`font-family: ${c}`,`font-size: ${h}px`,`line-height: ${1.2*h}px`,"overflow: hidden","resize: none","outline: 1px solid #f26522","border: 0","background-color: rgba(255, 255, 255, 0.85)","display: block",`color: ${l}`,"box-sizing: border-box","font-weight: "+(o?"bold":"normal"),"font-style: "+(a?"italic":"normal"),`text-align: ${_}`].join("; ");const w=new v(y),M=s.object3d;M.updateWorldMatrix(!0,!1);const S=new e.Vector3,k=new e.Quaternion,A=new e.Vector3;M.matrixWorld.decompose(S,k,A);const E=new e.Vector3(0,s.textSurfaceYOffset,0);E.multiply(A),E.applyQuaternion(k),w.position.copy(S).add(E);const C=(new e.Quaternion).setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2);w.quaternion.copy(k).multiply(C),w.scale.copy(A),n.css3DScene.add(w),i();const T=n.css3DRenderer.domElement,P=T.style.getPropertyValue("pointer-events"),O=T.style.getPropertyPriority("pointer-events"),D=[];let z=y;for(;z&&z!==T.parentElement;)D.push({el:z,saved:z.style.pointerEvents}),z.style.setProperty("pointer-events","auto","important"),z=z.parentElement;y.focus(),y.select();let I=!1;const R=t.root?.selected;y.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"!==t.code&&(t.shiftKey||"Enter"!==t.code&&"NumpadEnter"!==t.code)||(I="Escape"===t.code,y.blur())},{signal:b.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?T.style.setProperty("pointer-events",P,O):P&&T.style.setProperty("pointer-events",P),b.abort(),y.removeEventListener("blur",j),R&&t.root&&(t.root.selected=R),I||y.value===r||t.app.commander.execute(new ll({changes:[{component:t,before:{text:r},after:{text:y.value}}]})),i()};y.addEventListener("blur",j)}const Up=[{name:"X",dir:[1,0,0],color:13590367},{name:"Y",dir:[0,1,0],color:5482594},{name:"Z",dir:[0,0,1],color:5603535}];function $p(t){const e=Math.max(t,1)/5,n=Math.pow(10,Math.floor(Math.log10(e))),i=e/n,s=i<1.5?1:i<3.5?2:i<7.5?5:10;return Math.max(1,s*n)}function Xp(t,e){const n=Math.min(1,t/e);return Math.max(0,1-n*n)}function qp(t){const n=Math.max(t.step,1e-6),i=Math.max(2,Math.round(t.cells??16)),s=n*i,r=new e.Color(t.background??"#7c7c7c"),o=(t,n)=>r.clone().lerp(new e.Color(t),n),a=new e.Group;a.name="coordinate-ground",a.raycast=()=>{},a.add(function(t,e,n,i){const s=[],r=[],o=(t,e,o)=>{const a=i(16777215,Xp(Math.hypot(t,e),n)*(o?.85:.45));s.push(t,0,e),r.push(a.r,a.g,a.b)};for(let n=-e;n<=e;n++){if(0===n)continue;const i=n%5==0,s=n*t;for(let n=-e;n<e;n++){const e=n*t,r=(n+1)*t;o(e,s,i),o(r,s,i),o(s,e,i),o(s,r,i)}}return Qp(s,r)}(n,i,s,o));for(const i of Up){const r=new e.Vector3(...i.dir).multiplyScalar(s),c=r.clone().negate();a.add(Kp(c,r,i.color,s,o)),!1!==t.labels&&(a.add(Zp("+"+i.name,i.color,r.clone().multiplyScalar(1.08),n)),a.add(Zp("-"+i.name,i.color,c.clone().multiplyScalar(1.08),n)))}return a}function Kp(t,e,n,i,s){const r=[],o=[],a=t=>{const e=s(n,Xp(t.length(),i));r.push(t.x,t.y,t.z),o.push(e.r,e.g,e.b)};for(let n=0;n<24;n++)a(t.clone().lerp(e,n/24)),a(t.clone().lerp(e,(n+1)/24));return Qp(r,o)}function Qp(t,n){const i=new e.BufferGeometry;i.setAttribute("position",new e.Float32BufferAttribute(t,3)),i.setAttribute("color",new e.Float32BufferAttribute(n,3));const s=new e.LineSegments(i,new e.LineBasicMaterial({vertexColors:!0}));return s.raycast=()=>{},s}function Zp(t,n,i,s){const r=document.createElement("canvas");r.width=64,r.height=64;const o=r.getContext("2d");o.font="bold 34px system-ui, sans-serif",o.textAlign="center",o.textBaseline="middle",o.fillStyle="#"+n.toString(16).padStart(6,"0"),o.fillText(t,32,32);const a=new e.CanvasTexture(r);a.colorSpace=e.SRGBColorSpace;const c=new e.Sprite(new e.SpriteMaterial({map:a,transparent:!0}));return c.position.copy(i),c.scale.setScalar(.55*s),c.raycast=()=>{},c}function Jp(t){t.traverse(t=>{const e=t;e.geometry?.dispose?.();const n=e.material;n&&(n.map?.dispose?.(),n.dispose?.())}),t.removeFromParent()}class tf extends r{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()}}tf.recommendsLogarithmicDepth=!1;class ef extends tf{constructor(){super(),this.name="WarehouseEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:8425632}),n=new l(t,e);n.position.set(0,18,0),n.scale.set(50,40,40),this.add(n);const i=new a({color:9474192,roughness:.9}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(50,.5,40),this.add(s);const r=new h(15266047,600,50,2);r.position.set(-10,30,0),this.add(r);const u=new h(15266047,600,50,2);u.position.set(10,30,0),this.add(u);const p=(e,n,i)=>{const s=new d({color:0,emissive:15266047,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,35,n),r.scale.set(8,.1,2),r};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 l(t,new d({color:0,emissive:16772829,emissiveIntensity:15}));f.position.set(0,10,-19),f.scale.set(12,8,.1),this.add(f)}}ef.recommendsLogarithmicDepth=!0;class nf extends tf{constructor(){super(),this.name="FactoryEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:6318192,metalness:.1,roughness:.8}),n=new l(t,e);n.position.set(0,20,0),n.scale.set(60,44,45),this.add(n);const i=new a({color:8028272,roughness:.7,metalness:.05}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(60,.5,45),this.add(s);const r=(t,e)=>{const n=new h(15791615,800,55,2);return n.position.set(t,35,e),n};this.add(r(-15,-10)),this.add(r(-15,10)),this.add(r(0,0)),this.add(r(15,-10)),this.add(r(15,10));const u=(e,n,i)=>{const s=new d({color:0,emissive:15791615,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,38,n),r.scale.set(6,.1,3),r};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 l(t,new d({color:0,emissive:11206570,emissiveIntensity:10}));p.position.set(28,14,-21),p.scale.set(1,2,.1),this.add(p);const f=new l(t,new d({color:0,emissive:16772829,emissiveIntensity:25}));f.position.set(0,8,-22),f.scale.set(10,10,.1),this.add(f)}}nf.recommendsLogarithmicDepth=!0;class sf extends tf{constructor(){super(),this.name="OfficeEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:14209224}),n=new l(t,e);n.position.set(0,10,0),n.scale.set(35,22,30),this.add(n);const i=new a({color:10524808,roughness:.85}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(35,.5,30),this.add(s);const r=new h(16774374,400,30,2);r.position.set(0,17,0),this.add(r);const u=(e,n,i)=>{const s=new d({color:0,emissive:16775408,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,19.5,n),r.scale.set(4,.1,4),r};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 l(t,new d({color:0,emissive:14544639,emissiveIntensity:30}));p.position.set(17,10,0),p.scale.set(.1,6,12),this.add(p);const f=new l(t,new d({color:0,emissive:14544639,emissiveIntensity:20}));f.position.set(-17,10,0),f.scale.set(.1,4,8),this.add(f)}}sf.recommendsLogarithmicDepth=!0;class rf extends tf{constructor(){super(),this.name="HomeEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:15261136}),n=new l(t,e);n.position.set(0,8,0),n.scale.set(28,18,24),this.add(n);const i=new a({color:11571312,roughness:.7}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(28,.5,24),this.add(s);const r=new h(16770244,300,25,2);r.position.set(0,14,0),this.add(r);const u=new h(16767152,100,20,2);u.position.set(-8,12,-6),this.add(u);const p=(e,n,i)=>{const s=new d({color:0,emissive:16771280,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,15.5,n),r.scale.set(3,.1,3),r};this.add(p(0,0,40)),this.add(p(-6,-4,25)),this.add(p(6,4,25));const f=new l(t,new d({color:0,emissive:14544639,emissiveIntensity:35}));f.position.set(13.5,8,0),f.scale.set(.1,8,10),this.add(f);const m=new l(t,new d({color:0,emissive:14544639,emissiveIntensity:15}));m.position.set(-13.5,9,3),m.scale.set(.1,5,6),this.add(m)}}rf.recommendsLogarithmicDepth=!0;function of(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity,t.polygonOffset=!0,t.polygonOffsetFactor=1,t.polygonOffsetUnits=1}function af(t){const{fillStyle:n,floorMaterial3d:i,placement:s,floor:r}=t.state;if(!1===r)return;const o=Md({...i,preset:i?.preset??"rubber",envMapIntensity:i?.envMapIntensity??0});if("none"===n)return;if("space"===s)return;const a=new e.BoxGeometry(1,1,1);let c;if(n){const i=pu.buildFillStyleTexture(t);if(i){const t="#424b57",n=[new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({map:i}),new e.MeshStandardMaterial({color:t})];n.forEach(t=>of(t,o)),c=n}else if("string"==typeof n){const t=new e.MeshStandardMaterial({color:n});of(t,o),c=t}}if(!c){const t=new e.MeshStandardMaterial({color:"#e0e0e0"});of(t,o),c=t}const l=new e.Mesh(a,c),{width:h,height:d}=t.state;return l.scale.set(h,d,5),l.rotation.x=-Math.PI/2,l.position.y="inverted"===s?3.5:-3.5,l.name="floor",l.receiveShadow=!1!==i?.receiveShadow,l.castShadow=!0===i?.castShadow,l}const cf={studio:class extends tf{constructor(){super(),this.name="StudioEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:13421772}),n=new l(t,e);n.position.set(0,13,0),n.scale.set(40,30,35),this.add(n);const i=new a({color:11184810,roughness:.8}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(40,.5,35),this.add(s);const r=new h(16777215,500,40,2);r.position.set(0,24,0),this.add(r);const u=new h(16777215,200,30,2);u.position.set(-10,22,-8),this.add(u);const p=new h(16777215,200,30,2);p.position.set(10,22,8),this.add(p);const f=(e,n,i)=>{const s=new d({color:0,emissive:16777215,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,26,n),r.scale.set(6,.1,6),r};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:ef,factory:nf,office:sf,home:rf,sunny:class extends tf{constructor(){super(),this.name="SunnyEnvironment";const t=new k;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=2,e.rayleigh.value=1.5,e.mieCoefficient.value=.005,e.mieDirectionalG.value=.8;const n=u.degToRad(60),i=u.degToRad(135),s=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,s,i),this.add(t)}},cloudy:class extends tf{constructor(){super(),this.name="CloudyEnvironment";const t=new k;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=10,e.rayleigh.value=.3,e.mieCoefficient.value=.03,e.mieDirectionalG.value=.7;const n=u.degToRad(50),i=u.degToRad(120),s=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,s,i),this.add(t)}},rainy:class extends tf{constructor(){super(),this.name="RainyEnvironment";const t=new k;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=20,e.rayleigh.value=.1,e.mieCoefficient.value=.05,e.mieDirectionalG.value=.6;const n=u.degToRad(40),i=u.degToRad(110),s=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,s,i),this.add(t)}}};function lf(t){if(!t||!(t in cf))return!1;return!0===cf[t].recommendsLogarithmicDepth}class hf{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}_makeEnvTexture(t){if(!this._renderer)return;const n=new(0,cf[t]),i=new e.PMREMGenerator(this._renderer),s=i.fromScene(n).texture;return n.dispose(),i.dispose(),s}_applyEnvironment(t){this._clearEnvironment(),this._renderer&&this._scene&&(this._envTexture=this._makeEnvTexture(t),this._scene.environment=this._envTexture??null)}_clearEnvironment(){this._envTexture&&(this._envTexture.dispose(),this._envTexture=void 0),this._scene&&(this._scene.environment=null)}_clearBackgroundTexture(){this._bgTexture&&(this._bgTexture.dispose(),this._bgTexture=void 0)}get hasEnvironment(){return!!this._scene?.environment}setSky(t,n,i){if(!this._scene||!this._renderer)return;const s=t,r=!!s&&s in cf,o=i;if(void 0===i||""===i?r?this._applyEnvironment(s):this._clearEnvironment():"none"===i?this._clearEnvironment():o in cf?this._applyEnvironment(o):(console.warn(`[things-scene] 모르는 environment 프리셋: '${i}'. 쓸 수 있는 것 — ${Object.keys(cf).join(", ")}, none`),r?this._applyEnvironment(s):this._clearEnvironment()),this._clearBackgroundTexture(),r){this._envTexture&&(void 0===i||""===i||i===t)?this._scene.background=this._envTexture:(this._bgTexture=this._makeEnvTexture(s),this._scene.background=this._bgTexture??null)}else this._scene.background="color"===t&&n?new e.Color(n):null}addFloor(t){const e=af(t);e&&this._scene.add(e)}updateFloor(t){if(!this._scene)return;const e=this._scene.children.find(t=>"floor"===t.name);e&&(eu(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._bgTexture&&(this._bgTexture.dispose(),delete this._bgTexture),this._scene&&(this._scene.environment=null,this._scene.background=null,eu(this._scene),this._scene.clear()),delete this._scene,delete this._mixer,delete this._renderer,this._timer&&this._timer.disconnect(),delete this._timer}}class df{constructor(){this._activeView="perspective",this._cameraZPos=0}get camera(){return this._perspCamera}get activeCamera(){return"perspective"!==this._activeView&&this._orthoCamera?this._orthoCamera:this._perspCamera}get activeView(){return this._activeView}get cameraZPos(){return this._cameraZPos}setup(t,n,i){const{fov:s,near:r,far:o,cameraX:a,cameraY:c,cameraZ:l}=i,h=t/n;this._perspCamera=new e.PerspectiveCamera(s,h,r,o);const d=Math.sqrt(t*t+n*n),u=(s||45)/2*Math.PI/180,p=d/2/Math.tan(u)*.75,f=25*Math.PI/180,m=30*Math.PI/180,g=p*Math.sin(f),y=p*Math.cos(f);let b=y*Math.sin(m),_=y*Math.cos(m);return this._cameraZPos=Math.floor(g),null!=a&&(b=a*t),null!=c&&(_=c*n),null!=l&&(this._cameraZPos=l*Math.floor(Math.min(t,n))),this._perspCamera.position.set(b,this._cameraZPos,_),this._activeView="perspective",this._perspCamera}addToScene(t){t.add(this._perspCamera),this._perspCamera.lookAt(t.position)}updateAspect(t,e){if(this._perspCamera&&(this._perspCamera.aspect=t/e,this._perspCamera.updateProjectionMatrix()),this._orthoCamera){const n=this._orthoCamera,i=(n.top-n.bottom)/2,s=t/e;n.left=-i*s,n.right=i*s,n.updateProjectionMatrix()}}updateProperties(t){this._perspCamera&&(void 0!==t.fov&&(this._perspCamera.fov=t.fov),void 0!==t.near&&(this._perspCamera.near=t.near),void 0!==t.far&&(this._perspCamera.far=t.far),this._perspCamera.updateProjectionMatrix())}setOrthoView(t,n,i,s,r){this._orthoCamera||(this._orthoCamera=new e.OrthographicCamera(-1,1,1,-1,.1,5e4)),this.updateOrthoFrustum(n,i,s,r);const o=this._orthoCamera;o.zoom=1;const a=2*Math.max(n,i);switch(t){case"top":o.position.set(0,a,0),o.up.set(0,0,-1);break;case"front":o.position.set(0,0,a),o.up.set(0,1,0);break;case"back":o.position.set(0,0,-a),o.up.set(0,1,0);break;case"right":o.position.set(a,0,0),o.up.set(0,1,0);break;case"left":o.position.set(-a,0,0),o.up.set(0,1,0)}return o.lookAt(0,0,0),o.updateProjectionMatrix(),this._activeView=t,o}restorePerspective(){return this._activeView="perspective",this._perspCamera}updateOrthoFrustum(t,e,n,i){if(!this._orthoCamera)return;const s=(n||t)/(i||e),r=Math.max(t,e)/2;s>=1?(this._orthoCamera.left=-r*s,this._orthoCamera.right=r*s,this._orthoCamera.top=r,this._orthoCamera.bottom=-r):(this._orthoCamera.left=-r,this._orthoCamera.right=r,this._orthoCamera.top=r/s,this._orthoCamera.bottom=-r/s),this._orthoCamera.updateProjectionMatrix()}destroy(){delete this._perspCamera,delete this._orthoCamera,this._activeView="perspective"}}class uf{constructor(){this._noSupportWebgl=!1}get renderer(){return this._renderer}setExposure(t){this._renderer&&(this._renderer.toneMappingExposure=t)}get css3DRenderer(){return this._css3DRenderer||(this._css3DRenderer=this.createCSS3DRenderer()),this._css3DRenderer}get css3DScene(){return this._css3DScene||(this._css3DScene=new e.Scene),this._css3DScene}get composer(){return this._composer}get noSupportWebgl(){return this._noSupportWebgl}get domElement(){return this._renderer?.domElement}get hudScene(){return this._hudScene||(this._hudScene=new e.Scene),this._hudScene}get hudCSS3DScene(){return this._hudCSS3DScene||(this._hudCSS3DScene=new e.Scene),this._hudCSS3DScene}get hudCamera(){return this._hudCamera}setupHUD(t,n){this._hudCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCamera.position.set(0,5e3,0),this._hudCamera.lookAt(0,0,0),this._hudCSS3DCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCSS3DCamera.position.set(0,0,1e3),this._hudCSS3DCamera.lookAt(0,0,0),this._hudCSS3DRenderer=new x,this._hudCSS3DRenderer.setSize(t,n);const i=this._hudCSS3DRenderer.domElement;i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.pointerEvents="none",i.setAttribute("scene","model-layer:css3d-hud-renderer");const s=new e.AmbientLight(16777215,3);this.hudScene.add(s);const r=new Float32Array(64).fill(1),o=new e.DataTexture(r,4,4,e.RGBAFormat,e.FloatType);o.mapping=e.EquirectangularReflectionMapping,o.needsUpdate=!0,this.hudScene.environment=o}resizeHUD(t,e){this._hudCamera&&(this._hudCamera.right=t,this._hudCamera.bottom=-e,this._hudCamera.updateProjectionMatrix())}setupWebGL(t,n,i){try{const s=document.createElement("canvas"),r=s.getContext("webgl2");if(!r)return this._noSupportWebgl=!0,!1;const o=new e.WebGLRenderer({canvas:s,context:r,precision:i.precision,alpha:!0,antialias:i.antialias,logarithmicDepthBuffer:i.logarithmicDepthBuffer??!1!==i.postprocessing,premultipliedAlpha:!1});return o.autoClear=!0,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.ACESFilmicToneMapping,o.toneMappingExposure=i.exposure,o.shadowMap.enabled=!1!==i.shadowMap,o.shadowMap.type=e.PCFShadowMap,o.setClearColor(16777215,1),o.setPixelRatio(void 0===i.pixelRatio?window.devicePixelRatio:Math.max(.5,Math.min(3,i.pixelRatio))),o.setSize(t,n,!1),s.style.width="100%",s.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 x}setupComposer(t,n,i,s,r){const o=new e.WebGLRenderTarget(i,s,{samples:4});this._composer=new A(this._renderer,o),this._composer.setSize(i,s);const a=new E(t,n);this._composer.addPass(a);const c=new C(new e.Vector2(i,s),t,n);if(c.visibleEdgeColor.set(15885602),c.hiddenEdgeColor.set(16755268),c.edgeStrength=6,c.edgeThickness=3,c.edgeGlow=1,c.pulsePeriod=0,r){const t=c.render.bind(c);c.render=(e,n,i,s,o)=>{const a=r.visible;r.visible=!1,t(e,n,i,s,o),r.visible=a}}return this._outlinePass=c,this._composer.addPass(c),this._composer.addPass(new P),this._composer.addPass(new T),this._composer}setupLightComposer(t,n,i,s){const r=new e.WebGLRenderTarget(i,s);this._composer=new A(this._renderer,r),this._composer.setSize(i,s),this._composer.addPass(new E(t,n));const o=new C(new e.Vector2(i,s),t,n);return o.visibleEdgeColor.set(15885602),o.hiddenEdgeColor.set(16755268),o.edgeStrength=6,o.edgeThickness=3,o.edgeGlow=1,o.pulsePeriod=0,this._outlinePass=o,this._composer.addPass(o),this._composer.addPass(new T),this._composer}get hasOutlinePass(){return!!this._outlinePass}updateRenderPassCamera(t){this._composer&&this._composer.passes.length>0&&(this._composer.passes[0].camera=t),this._outlinePass&&(this._outlinePass.renderCamera=t),this._camera&&(this._camera=t)}setOutlineObjects(t){this._outlinePass&&(this._outlinePass.selectedObjects=t)}setOutlineColor(t){this._outlinePass&&(this._outlinePass.visibleEdgeColor.set(t),this._outlinePass.hiddenEdgeColor.set(t))}resize(t,e){if(this._renderer?.setSize(t,e,!1),this._css3DRenderer?.setSize(t,e),this._composer?.setSize(t,e),this._hudCSS3DRenderer&&this._hudCSS3DCamera){const n=t/(this._hudCSS3DCamera.right-this._hudCSS3DCamera.left),i=e/(this._hudCSS3DCamera.top-this._hudCSS3DCamera.bottom),s=this._hudCSS3DRenderer.domElement;s.style.transformOrigin="0 0",s.style.transform=`scale(${n}, ${i})`}}teardownLightComposer(){this._composer&&(this._outlinePass=void 0,this._composer.dispose(),this._composer=void 0)}setDirectRenderTargets(t,e){this._scene=t,this._camera=e}render(){if(this._composer){if(this._composer.render(),this._renderer){const t=this._renderer.getContext();t.colorMask(!1,!1,!1,!0),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.colorMask(!0,!0,!0,!0)}}else this._renderer&&this._scene&&this._camera&&this._renderer.render(this._scene,this._camera);this.renderHUD()}renderHUD(){if(!this._renderer||!this._hudScene||!this._hudCamera)return;if(0===this._hudScene.children.length)return;const t=this._renderer.autoClear;this._renderer.autoClear=!1,this._renderer.setRenderTarget(null),this._renderer.clearDepth(),this._renderer.render(this._hudScene,this._hudCamera),this._renderer.autoClear=t}renderCSS3D(t){if(this._css3DRenderer?.render(this.css3DScene,t),this._hudCSS3DRenderer&&this._hudCSS3DCamera&&this._hudCSS3DScene){const t=this._hudCSS3DRenderer.domElement;this._hudCSS3DScene.children.length>0?(t.style.display="",this._hudCSS3DRenderer.render(this._hudCSS3DScene,this._hudCSS3DCamera)):t.style.display="none"}}get hudCSS3DRenderer(){return this._hudCSS3DRenderer}getSize(){const t=new e.Vector2;return this._renderer?.getSize(t),{width:t.x,height:t.y}}destroy(){this._outlinePass=void 0,this._composer?.dispose(),this._renderer?.forceContextLoss(),this._renderer?.dispose(),delete this._composer,delete this._renderer,this.disposeHUD()}disposeHUD(){if(this._hudScene){[...this._hudScene.children].forEach(t=>{if(this._hudScene.remove(t),t.geometry&&t.geometry.dispose(),t.material){const e=t.material;e.map&&e.map.dispose(),e.dispose()}}),this._hudScene.environment&&(this._hudScene.environment.dispose(),this._hudScene.environment=null),this._hudScene=void 0}if(this._hudCamera=void 0,this._hudCSS3DScene){[...this._hudCSS3DScene.children].forEach(t=>this._hudCSS3DScene.remove(t)),this._hudCSS3DScene=void 0}this._hudCSS3DRenderer&&(this._hudCSS3DRenderer.domElement.remove(),this._hudCSS3DRenderer=void 0),this._hudCSS3DCamera=void 0}disposeCSS3DScene(){if(this._css3DScene){[...this._css3DScene.children].forEach(t=>this._css3DScene.remove(t))}}}class pf{constructor(){this.lights=[]}get hemiLight(){return this._hemiLight}get dirLight(){return this._dirLight}setup(t,n,i){this._scene=t,this._camera=n;const{hemisphere:s,directional:r,point:o}=i;if(this._hemiLight=new e.HemisphereLight(s.skyColor,s.groundColor,s.intensity),t.add(this._hemiLight),this.lights.push(this._hemiLight),r){if(this._dirLight=new e.DirectionalLight(r.color,r.intensity),r.position&&this._dirLight.position.set(...r.position),!1!==r.castShadow){this._dirLight.castShadow=!0;const t=r.shadowMapSize??2048;this._dirLight.shadow.mapSize.set(t,t),this._dirLight.shadow.bias=r.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}r.attachToCamera?n.add(this._dirLight):t.add(this._dirLight),this.lights.push(this._dirLight)}if(o){const n=new e.PointLight(o.color,o.intensity,void 0,o.decay);n.power=o.power,n.castShadow=o.castShadow,n.position.set(...o.position),n.shadow.camera.near=o.shadowNear,n.shadow.camera.far=o.shadowFar,t.add(n),this.lights.push(n)}}updateHemisphere(t){this._hemiLight&&(void 0!==t.skyColor&&this._hemiLight.color.set(t.skyColor),void 0!==t.groundColor&&this._hemiLight.groundColor.set(t.groundColor),void 0!==t.intensity&&(this._hemiLight.intensity=t.intensity))}updateDirectional(t){this._dirLight&&(void 0!==t.color&&this._dirLight.color.set(t.color),void 0!==t.intensity&&(this._dirLight.intensity=t.intensity))}setDirectionalFollowCamera(t){this._dirLight&&this._scene&&this._camera&&(this._dirLight.removeFromParent(),t?this._camera.add(this._dirLight):this._scene.add(this._dirLight))}setDirectionalAngle(t,e,n=1e3){if(!this._dirLight)return;const i=t*Math.PI/180,s=e*Math.PI/180,r=n;this._dirLight.position.set(r*Math.cos(s)*Math.sin(i),r*Math.sin(s),r*Math.cos(s)*Math.cos(i)),this._dirLight.target.position.set(0,0,0),!this._dirLight.target.parent&&this._scene&&this._scene.add(this._dirLight.target)}setDirectionalEnabled(t,n){if(t&&!this._dirLight&&this._camera){const t=n?.color??16777215,i=n?.intensity??2;this._dirLight=new e.DirectionalLight(t,i),this._camera.add(this._dirLight),this.lights.push(this._dirLight)}else!t&&this._dirLight&&(this._dirLight.removeFromParent(),this._dirLight.dispose(),this.lights=this.lights.filter(t=>t!==this._dirLight),this._dirLight=void 0)}destroy(){this.lights.forEach(t=>t.dispose()),this.lights=[],this._hemiLight=void 0,this._dirLight=void 0,this._scene=void 0,this._camera=void 0}}const ff=1e-6;class mf{constructor(){this._enabled=!0,this._state=0,this._autoRotate=!1,this._autoRotateSpeed=2,this._dampingFactor=.15,this._rotateSpeed=.1,this._panSpeed=1,this._dollyStart=0,this._lastScale=1,this._floorConstraint=!1,this._spherical=new e.Spherical,this._sphericalDelta=new e.Spherical,this._panOffset=new e.Vector3,this._target=new e.Vector3,this._target0=new e.Vector3,this._position0=new e.Vector3,this._rotateStart=new e.Vector2,this._rotateEnd=new e.Vector2,this._rotateDelta=new e.Vector2,this._panStart=new e.Vector2,this._panEnd=new e.Vector2,this._panDelta=new e.Vector2,this._offset=new e.Vector3,this._lastPosition=new e.Vector3,this._lastQuaternion=new e.Quaternion,this._panLeftV=new e.Vector3,this._panUpV=new e.Vector3,this._panCalcOffset=new e.Vector3}get isActive(){return!!this._camera}get target(){return this._target.clone()}restoreTarget(t){this._target.copy(t),this.update()}get _isOrthoLocked(){return!!this._camera?.isOrthographicCamera}setup(t,n){this._camera=t,this._host=n,this._target.set(0,0,0),this._target0.copy(this._target),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert();const i=n.state;this._autoRotate=!n.app?.isEditMode&&(i.autoRotate||"orbit"===i.cameraAutoPlay)||!1,this._autoRotateSpeed=i.rotationSpeed||2,this._floorConstraint=!n.app?.isEditMode&&!!i.cameraFloorConstraint||!1,this.update()}setEnabled(t){this._enabled=t}setOnUserInteraction(t){this._onUserInteraction=t}onDragStart(t){this._enabled&&(this._onUserInteraction?.(),this._isOrthoLocked?(this._state=2,this._panStart.set(t.offsetX,t.offsetY)):(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,1===this._state?this._rotateStart.set(t.offsetX,t.offsetY):3===this._state?this._dollyStart=t.offsetY:this._panStart.set(t.offsetX,t.offsetY)))}onDragMove(t){if(this._enabled)if(this._isOrthoLocked)this._state=2,this._handlePanMove(t.offsetX,t.offsetY);else if(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,3===this._state){const e=t.offsetY-this._dollyStart;this._dollyStart=t.offsetY;const n=1+.005*e;this.dollyAtCursor(n,0,0)}else 1===this._state?this._handleRotateMove(t.offsetX,t.offsetY):this._handlePanMove(t.offsetX,t.offsetY)}onDragEnd(t){this._state=0,this._host?.invalidate()}onTouchStart(t){this._onUserInteraction?.();const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)return this._panStart.set(n,i),void(this._state=5);switch(t.touches.length){case 1:this._rotateStart.set(n,i),this._state=4;break;case 2:this._lastScale=t.scale||1,this._panStart.set(n,i),this._state=5;break;default:this._state=0}}onTouchMove(t){const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)this._handlePanMove(n,i);else switch(t.touches.length){case 1:if(4!==this._state)return;this._handleRotateMove(n,i);break;case 2:{if(5!==this._state)return;const e=t.scale||1;if(Math.abs(this._lastScale-e)>.01){const t=this._lastScale/e;this._lastScale=e,this.dollyAtCursor(t,0,0)}else this._handlePanMove(n,i);break}default:this._state=0}}onTouchEnd(t){this._lastScale=1,this._state=0}onKeyDown(t){switch(t.code){case"ArrowUp":this._pan(0,7);break;case"ArrowDown":this._pan(0,-7);break;case"ArrowLeft":this._pan(7,0);break;case"ArrowRight":this._pan(-7,0);break;default:return}this.update()}update(){const t=this._camera,e=t.position;if(this._isOrthoLocked)return this._panOffset.lengthSq()>0&&(this._target.add(this._panOffset),e.add(this._panOffset),this._panOffset.set(0,0,0)),(this._lastPosition.distanceToSquared(e)>ff||8*(1-this._lastQuaternion.dot(t.quaternion))>ff)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0);if(this._offset.copy(e).sub(this._target),this._offset.applyQuaternion(this._quat),this._spherical.setFromVector3(this._offset),this._spherical.theta+=this._sphericalDelta.theta,this._autoRotate&&0===this._state){const t=2*Math.PI/60*(this._autoRotateSpeed/60);this._spherical.theta-=t}this._spherical.phi+=this._sphericalDelta.phi,this._spherical.phi=Math.max(0,Math.min(Math.PI,this._spherical.phi)),this._spherical.makeSafe(),this._target.add(this._panOffset),this._offset.setFromSpherical(this._spherical),this._offset.applyQuaternion(this._quatInverse),e.copy(this._target).add(this._offset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),e.y<0&&(e.y=0)),t.lookAt(this._target);const n=1-this._dampingFactor;return this._sphericalDelta.theta*=n,this._sphericalDelta.phi*=n,this._panOffset.set(0,0,0),(this._lastPosition.distanceToSquared(e)>ff||8*(1-this._lastQuaternion.dot(t.quaternion))>ff)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0)}reset(){this._target.copy(this._target0),this._camera.position.copy(this._position0),this._camera.updateProjectionMatrix(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._state=0,this.update()}pinResetPosition(){this._camera&&(this._position0.copy(this._camera.position),this._target0.copy(this._target))}setCamera(t){this._camera=t,this._target.set(0,0,0),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._lastPosition.copy(t.position),this._lastQuaternion.copy(t.quaternion),this._state=0,t.updateMatrixWorld(!0)}isAutoRotating(){return this._autoRotate}setAutoRotate(t){this._autoRotate=t,this._host?.invalidate()}setFloorConstraint(t){this._floorConstraint=t,this.update()}markCameraChanged(){this._host?.invalidate()}dollyAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,s=i.position.distanceTo(this._target),r=Math.max(1,Math.min(5e4,s*t));if(Math.abs(r-s)<ff)return;const o=Math.tan(i.fov/2*Math.PI/180)/i.zoom,a=s-r,c=e*a*o*i.aspect,l=n*a*o;this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(c),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(l),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),this._panCalcOffset.subVectors(i.position,this._target).normalize().multiplyScalar(r),i.position.copy(this._target).add(this._panCalcOffset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),i.position.y<0&&(i.position.y=0)),this._host?.invalidate()}zoomOrthoAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,s=i.zoom,r=Math.max(.1,Math.min(20,s*t)),o=e*(i.right-i.left)/2*(1/s-1/r),a=n*(i.top-i.bottom)/2*(1/s-1/r);this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(o),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(a),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),i.zoom=r,i.updateProjectionMatrix(),this._host?.invalidate()}destroy(){delete this._camera,delete this._host}_getViewportSize(){const t=this._host;if(!t)return{width:1,height:1};const e=t?.element;if(e){const t=e.getBoundingClientRect();if(t.width>0&&t.height>0)return{width:t.width,height:t.height}}const n=t.bounds;return{width:Math.abs(n?.width)||1,height:Math.abs(n?.height)||1}}_handleRotateMove(t,e){this._rotateEnd.set(t,e),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart);const{width:n,height:i}=this._getViewportSize();this._sphericalDelta.theta-=2*Math.PI*this._rotateDelta.x/n*this._rotateSpeed,this._sphericalDelta.phi-=2*Math.PI*this._rotateDelta.y/i*this._rotateSpeed,this._rotateStart.copy(this._rotateEnd),this._host?.invalidate()}_handlePanMove(t,e){this._panEnd.set(t,e),this._panDelta.subVectors(this._panEnd,this._panStart),this._isOrthoLocked?this._panOrtho(this._panDelta.x,this._panDelta.y):this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this._host?.invalidate()}_panOrtho(t,e){const n=this._camera,{width:i,height:s}=this._getViewportSize();this._panLeftV.setFromMatrixColumn(n.matrix,0),this._panLeftV.multiplyScalar(-t*(n.right-n.left)/n.zoom/i),this._panUpV.setFromMatrixColumn(n.matrix,1),this._panUpV.multiplyScalar(e*(n.top-n.bottom)/n.zoom/s),this._target.add(this._panLeftV).add(this._panUpV),n.position.add(this._panLeftV).add(this._panUpV)}panByPixels(t,e){this._onUserInteraction?.(),this._pan(t,e),this._target.add(this._panOffset),this._camera.position.add(this._panOffset),this._panOffset.set(0,0,0),this._host?.invalidate()}_pan(t,e){t*=this._panSpeed,e*=this._panSpeed;const{width:n,height:i}=this._getViewportSize(),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/n),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 gf{constructor(){this._mouse=new e.Vector2,this._raycaster=new e.Raycaster}get mouse(){return this._mouse}get lastFocused(){return this._lastFocused}set lastFocused(t){this._lastFocused=t}get lastHovered(){return this._lastHovered}set lastHovered(t){this._lastHovered=t}updateMouseNDC(t,e,n,i,s,r){this._mouse.x=(t-n)/s*2-1,this._mouse.y=-(e-i)/r*2+1}getObjectByRaycast(t,e){this._lastHit=void 0;const n=this.getObjectsByRaycast(t,e);if(n&&n.length>0)for(const t of n){if(!this._isWorldVisible(t.object))continue;const e=!!t.object.userData?.alwaysRaycast;let n=t.object;for(;n;){if(n.userData.context){const i=n.userData.context.component;if(!e&&i&&!1===i.capturable)break;return this._lastHit=t.object,n}n=n.parent}}}_isWorldVisible(t){let e=t;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}getObjectsByRaycast(t,e){return this._raycaster.setFromCamera(this._mouse,t),this._raycaster.intersectObjects(e.children,!0)}setHUD(t,e){this._hudScene=t,this._hudCamera=e}handleClick(t,e,n){let i;this._lastFocused&&(this._lastFocused.focused=!1),this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const s=i?.userData.context;return s&&(s.focused=!0,this._lastFocused=s,this._lastHit&&fu(s)&&(s.pickedPart=s.partAt(this._lastHit)),s.component?.trigger("click",n)),s}handleHover(t,e,n){let i;this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const s=i?.userData.context;s!==this._lastHovered&&(this._lastHovered&&(this._lastHovered.component?.trigger("mouseleave",n),this._lastHovered=void 0),s&&(this._lastHovered=s,this._lastHovered.component?.trigger("mouseenter",n)))}clearHoverIfUnpickable(){const t=this._lastHovered?.component;t&&!1===t.capturable&&(this._lastHovered?.component?.trigger("mouseleave"),this._lastHovered=void 0)}destroy(){this._lastFocused=void 0,this._lastHovered=void 0,this._hudScene=void 0,this._hudCamera=void 0}}const yf=Math.PI/180*15;class bf{constructor(){this._mode="translate",this._isDragging=!1}get controls(){return this._controls}get mode(){return this._mode}get attached(){return this._attached}get isAttached(){return!!this._attached}get isDragging(){return this._isDragging}get isEngaged(){return!!this._controls?.axis}setup(t,e,n){this.destroy(),this._scene=n;const i=document.createElement("div");i.style.cssText="position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none",i.setPointerCapture=()=>{},i.releasePointerCapture=()=>{},e.appendChild(i),this._proxyElement=i,this._controls=new O(t,i),this._controls.setMode(this._mode),n.add(this._controls.getHelper()),this._controls.addEventListener("dragging-changed",t=>{this._isDragging=t.value,this.onDraggingChanged?.(t.value)}),this._controls.addEventListener("change",()=>{this._attached&&this.onObjectChange?.(this._attached)})}forwardEvent(t,e){if(!this._proxyElement||!this._controls)return;"rotate"===this._mode&&this._controls.setRotationSnap(t.shiftKey?yf:null);const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:t.button??0,pointerId:1,pointerType:"mouse",bubbles:!0});this._proxyElement.dispatchEvent(n)}forwardTouch(t,e){if(!this._proxyElement||!this._controls)return;const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:0,pointerId:t.identifier+10,pointerType:"touch",bubbles:!0});this._proxyElement.dispatchEvent(n)}setMode(t){this._mode=t,this._controls?.setMode(t)}attach(t){this._attached=t,this._controls?.attach(t),this._controls?.getHelper().updateMatrixWorld(!0),this.onAttachChanged?.(!0)}detach(){this._controls?.detach(),this._attached=void 0,this.onAttachChanged?.(!1)}setRotationSnap(t){this._controls&&this._controls.setRotationSnap(t?yf:null)}updateCamera(t){this._controls&&(this._controls.camera=t)}destroy(){this._controls&&(this._controls.detach(),this._controls.dispose(),this._scene&&this._scene.remove(this._controls.getHelper()),this._controls=void 0),this._proxyElement?.parentNode&&this._proxyElement.parentNode.removeChild(this._proxyElement),this._proxyElement=void 0,this._attached=void 0,this._isDragging=!1}}const _f=.01;function vf(t){const[e,n,i]=t,s=Math.abs(e-1),r=Math.abs(n-1),o=Math.abs(i-1);return s<_f&&r<_f&&o<_f?null:s>=r&&s>=o?e:r>=s&&r>=o?n:i}class xf{constructor(){this._mouseDownAltKey=!1}captureAltKey(t){this._mouseDownAltKey=t}setupCallbacks(t,e,n,i){t.onDraggingChanged=s=>{e.setEnabled(!s);const r=n();r&&(i?.onDraggingChanged?.(s),s?(this._onDragStart(t,r),r.hostElement&&this._showInfoOverlay(r.hostElement)):(this._hideInfoOverlay(),this._onDragEnd(t,r)),r.app?.commander?.execute(null),r.invalidate())},t.onObjectChange=e=>{if(this._syncFromGizmo(t,e),this._infoOverlay){const n=t.controls?.axis??null;this._updateInfoOverlay(t.mode,e,n)}n()?.invalidate()},t.onAttachChanged=t=>{i?.onAttachChanged?.(t)}}_onDragStart(t,e){this._mouseDownAltKey&&"translate"===t.mode&&this._performAltDragDuplicate(e);const n=e.root?.selected||[];n.length>1&&this._captureMultiSelectState(t,n);const i=t.attached;i&&("rotate"!==t.mode||this._gizmoInitialRotation?"translate"!==t.mode||this._dragStartPosition||(this._dragStartPosition=i.position.clone()):this._gizmoInitialRotation=i.rotation.clone()),"scale"===t.mode&&this._captureScalePreDrag(t)}_performAltDragDuplicate(t){const e=t.root?.selected||[];if(0===e.length||!t.root)return;const n=t.root,i=[];for(const t of e){const e=t.parent,s=new Map,r=Il(t,t=>{const e=n.getNewRefid();return void 0!==t&&s.set(t,e),e});r.replaceRefids(s),e.addComponent(r),i.push({component:r,to_container:e})}this._altDragDuplicates=i}_captureMultiSelectState(t,e){const n=t.attached;if(n)if("translate"===t.mode){const t=new Map,i=n.position;for(let n=1;n<e.length;n++){const s=e[n]._realObject;s?.object3d&&s.gizmoTransformable&&t.set(s,s.object3d.position.clone().sub(i))}this._multiSelectOffsets=t}else if("rotate"===t.mode){this._gizmoInitialRotation=n.rotation.clone();const t=new Map;for(let n=1;n<e.length;n++){const i=e[n]._realObject;i?.object3d&&i.gizmoTransformable&&t.set(i,i.object3d.rotation.clone())}this._multiSelectInitialRotations=t}else if("scale"===t.mode){const t=new Map;for(let n=1;n<e.length;n++){const i=e[n],s=i._realObject;if(s?.object3d&&s.gizmoTransformable){const{left:e,top:n,width:r,height:o}=i.bounds,{zPos:a=0}=i.state,c=i.state.depth;t.set(s,{left:e,top:n,width:r,height:o,depth:c,zPos:a,scaleX:s.object3d.scale.x,scaleY:s.object3d.scale.y,scaleZ:s.object3d.scale.z})}}this._multiSelectPreDragDimensions=t}}_captureScalePreDrag(t){const e=t.attached,n=e?.userData.context;if(!n||!e)return;const{left:i,top:s,width:r,height:o}=n.component.bounds,{zPos:a=0}=n.component.state,c=n.component.state.depth??n.effectiveDepth;this._preDragDimension={left:i,top:s,width:r,height:o,depth:c,zPos:a},this._preDragScale={x:e.scale.x,y:e.scale.y,z:e.scale.z},this._preDragEffectiveDepth=void 0,this._scaleAnchorSign=this._computeAnchorSign(t,e),this._preDragAttachedPosition=e.position.clone()}_computeAnchorSign(t,n){const i=t.controls;if(!i)return{x:0,y:0,z:0};const s=i.axis;if(!s||"XYZE"===s)return{x:0,y:0,z:0};if(s.includes("X")&&s.includes("Y")&&s.includes("Z"))return{x:0,y:0,z:0};const r=new e.Quaternion;n.getWorldQuaternion(r),r.invert();const o=i.pointStart.clone().applyQuaternion(r),a=.001,c={x:0,y:0,z:0};return s.includes("X")&&Math.abs(o.x)>a&&(c.x=Math.sign(o.x)),s.includes("Y")&&Math.abs(o.y)>a&&(c.y=Math.sign(o.y)),s.includes("Z")&&Math.abs(o.z)>a&&(c.z=Math.sign(o.z)),c}_onDragEnd(t,e){if(this._altDragDuplicates&&this._altDragDuplicates.length>0&&(e.app?.commander.execute(new Ol({changes:this._altDragDuplicates})),this._altDragDuplicates=void 0),this._multiSelectOffsets=void 0,this._gizmoInitialRotation=void 0,this._multiSelectInitialRotations=void 0,this._dragStartPosition=void 0,this._preDragDimension){const e=t.attached,n=e?.userData.context;if(n&&(void 0!==this._preDragEffectiveDepth&&n.applyDimensionFromGizmo({depth:this._preDragEffectiveDepth}),n.update()),this._multiSelectPreDragDimensions)for(const[t]of this._multiSelectPreDragDimensions)t.update()}const n=e.root?.selected||[];for(const e of n){const n=e._realObject;n?.onGizmoDragEnd(t.mode)}for(const t of n){let e=t.parent;for(;e?.isGroup?.();){const t=[];e._realObject&&t.push(e._realObject);for(const n of e.components||[])n._realObject&&t.push(n._realObject);for(const e of t)e._suppressOnchange=!0;e.calculateBounds();for(const e of t)e._suppressOnchange=!1,e.updateTransform();e=e.parent}}this._preDragDimension=void 0,this._preDragScale=void 0,this._preDragEffectiveDepth=void 0,this._multiSelectPreDragDimensions=void 0,this._scaleAnchorSign=void 0,this._preDragAttachedPosition=void 0}_syncPartFromGizmo(t){for(let e=t.parent;e;e=e.parent){const n=e.userData?.context;if(n){if(fu(n)){const e=n.partAt(t);e&&n.partMoved?.(e,t)}return}}}_syncFromGizmo(t,e){const n=e.userData.context;if(n)if("scale"===t.mode&&this._preDragDimension&&this._preDragScale){const{ratioX:t,ratioY:i,ratioZ:s,sign:r}=this._syncDimensionFromGizmo(n,e);if(this._multiSelectPreDragDimensions)for(const[e,n]of this._multiSelectPreDragDimensions)e.applyDimensionFromGizmo(this._computeAnchorProps(n,t,i,s,r))}else{if(n.syncFromObject3D(),"translate"===t.mode&&this._applyGroundSnap(e,n),this._multiSelectOffsets){const n=e.position;for(const[e,i]of this._multiSelectOffsets)e.object3d&&(e.object3d.position.copy(n).add(i),"translate"===t.mode&&this._applyGroundSnap(e.object3d,e),e.syncFromObject3D())}if(this._multiSelectInitialRotations&&this._gizmoInitialRotation){const t=e.rotation.x-this._gizmoInitialRotation.x,n=e.rotation.y-this._gizmoInitialRotation.y,i=e.rotation.z-this._gizmoInitialRotation.z;for(const[e,s]of this._multiSelectInitialRotations)e.object3d&&(e.object3d.rotation.set(s.x+t,s.y+n,s.z+i),e.syncFromObject3D())}}else this._syncPartFromGizmo(e)}_applyGroundSnap(t,e){const n=e.effectiveDepth/2,i=t.position.y-n,s=Math.abs(i);if(s<2)t.position.y=n,e.syncFromObject3D();else if(s<10){const r=(s-2)/8,o=1-r*r;t.position.y=n+i*(1-o),e.syncFromObject3D()}}_syncDimensionFromGizmo(t,e){const n=this._preDragDimension,i=this._preDragScale;let s={...this._scaleAnchorSign??{x:0,y:0,z:0}},r=e.scale.x/i.x,o=e.scale.y/i.y,a=e.scale.z/i.z;if(t.component.state.ratioLock){const t=vf([r,o,a]);if(t){r=o=a=t,e.scale.set(t*i.x,t*i.y,t*i.z);const n=s.x||s.y||s.z;n&&(s={x:n,y:n,z:n})}}return t.applyDimensionFromGizmo(this._computeAnchorProps(n,r,o,a,s)),!this._preDragAttachedPosition||0===s.x&&0===s.y&&0===s.z||this._applyAnchorPositionCorrection(e,n,i,s),{ratioX:r,ratioY:o,ratioZ:a,sign:s}}_computeAnchorProps(t,e,n,i,s){const r=t.width*e,o=t.height*i,a=s.x>0?0:s.x<0?t.width-r:(t.width-r)/2,c=s.z>0?0:s.z<0?t.height-o:(t.height-o)/2,l={left:t.left+a,top:t.top+c,width:r,height:o};if(void 0!==t.depth){const e=t.depth*n,i=s.y>0?0:s.y<0?t.depth-e:(t.depth-e)/2;l.depth=e,l.zPos=t.zPos+i}return l}_applyAnchorPositionCorrection(t,n,i,s){const r=new e.Vector3(s.x*(t.scale.x-i.x)*n.width/2,s.y*(t.scale.y-i.y)*(n.depth??0)/2,s.z*(t.scale.z-i.z)*n.height/2),o=new e.Quaternion;t.getWorldQuaternion(o),r.applyQuaternion(o);const a=this._preDragAttachedPosition;t.position.set(a.x+r.x,a.y+r.y,a.z+r.z)}_showInfoOverlay(t){if(this._infoOverlay)return;const e=document.createElement("div");e.style.cssText="\n position: absolute; z-index: 10000; pointer-events: none;\n left: 50%; top: 16px; transform: translateX(-50%);\n padding: 6px 16px; border-radius: 6px;\n background: rgba(0,0,0,0.8); color: #fff;\n font: bold 16px/1.4 'Pretendard', system-ui, sans-serif;\n letter-spacing: 0.5px;\n white-space: nowrap; opacity: 0; transition: opacity 0.15s;\n box-shadow: 0 2px 8px rgba(0,0,0,0.3);\n ",t.style.position="relative",t.appendChild(e),this._infoOverlay=e,requestAnimationFrame(()=>{e.style.opacity="1"})}_updateInfoOverlay(t,e,n){if(!this._infoOverlay)return;const i=t=>(t>=0?"+":"")+t.toFixed(1);if("rotate"===t){if(!this._gizmoInitialRotation)return;const t=180/Math.PI,n=(e.rotation.x-this._gizmoInitialRotation.x)*t,s=(e.rotation.y-this._gizmoInitialRotation.y)*t,r=(e.rotation.z-this._gizmoInitialRotation.z)*t,o=[Math.abs(n),Math.abs(s),Math.abs(r)],a=o.indexOf(Math.max(...o)),c=["X","Y","Z"],l=[n,s,r],h=[e.rotation.x*t,e.rotation.y*t,e.rotation.z*t];this._infoOverlay.textContent=`↻ ${c[a]}: ${h[a].toFixed(1)}° (${i(l[a])})`}else if("translate"===t){if(!this._dragStartPosition)return;const t=e.position.clone().sub(this._dragStartPosition),n=e.position,s=(t,e,n)=>Math.abs(n)<.05?`${t}:${e.toFixed(0)}`:`${t}:${e.toFixed(0)}(${i(n)})`;this._infoOverlay.textContent=`↔ ${s("X",n.x,t.x)} ${s("Y",n.y,t.y)} ${s("Z",n.z,t.z)}`}else if("scale"===t){if(!this._preDragScale)return;this._infoOverlay.textContent=this._formatScaleInfo(e,n)}}_formatScaleInfo(t,e){const n=this._preDragScale,i=this._preDragDimension,s=t.scale.x/(n.x||1),r=t.scale.y/(n.y||1),o=t.scale.z/(n.z||1),a=i?i.width*s:t.scale.x,c=null!=i?.depth?i.depth*r:t.scale.y,l=i?i.height*o:t.scale.z,h=i?i.width*(s-1):t.scale.x-n.x,d=null!=i?.depth?i.depth*(r-1):t.scale.y-n.y,u=i?i.height*(o-1):t.scale.z-n.z,p=t=>(t>=0?"+":"")+t.toFixed(0),f=t=>t.toFixed(0);switch(e){case"X":return`⤢ W ${f(a)}px (${p(h)})`;case"Y":return`⤢ D ${f(c)}px (${p(d)})`;case"Z":return`⤢ H ${f(l)}px (${p(u)})`}return Math.abs(s-r)<.01&&Math.abs(r-o)<.01?`⤢ ×${s.toFixed(2)} (${f(a)}×${f(c)}×${f(l)})`:`⤢ W:${f(a)}(${p(h)}) D:${f(c)}(${p(d)}) H:${f(l)}(${p(u)})`}_hideInfoOverlay(){this._infoOverlay&&(this._infoOverlay.remove(),this._infoOverlay=void 0)}}class wf{constructor(){this._mouseIsDown=!1,this._isDragging=!1,this._touchGizmoCaptured=!1,this._mouseDownPos={x:0,y:0}}get hostElement(){return this._hostElement}setup(t,e,n){this.cleanup(),this._hostElement=t,this._gizmo=e.gizmo,this._controls=e.controls,this._camera=e.camera,this._scene=e.scene,this._event=e.event,this._delegate=n,t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.style.outline="none";const i={mousedown:t=>this._onMouseDown(t),mousemove:t=>this._onMouseMove(t),wheel:t=>{t.stopPropagation(),this._delegate.handleWheel(t)},dblclick:t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleDblClick(t)},contextmenu:t=>{t.preventDefault()},touchstart:t=>{if(t.stopPropagation(),1===t.touches?.length&&this._gizmo?.isAttached){const e=t.touches[0];if(this._gizmo.forwardTouch(e,"pointermove"),this._gizmo.isEngaged)return this._gizmo.forwardTouch(e,"pointerdown"),this._touchGizmoCaptured=!0,void t.preventDefault()}this._touchGizmoCaptured=!1,this._delegate.handleTouchStart(t)},touchmove:t=>{if(t.stopPropagation(),this._touchGizmoCaptured&&1===t.touches.length)return this._gizmo.forwardTouch(t.touches[0],"pointermove"),void t.preventDefault();this._delegate.handleTouchMove(t)},touchend:t=>{if(t.stopPropagation(),this._touchGizmoCaptured){const e=t.changedTouches[0];return e&&this._gizmo.forwardTouch(e,"pointerup"),void(this._touchGizmoCaptured=!1)}this._delegate.handleTouchEnd(t)},keydown:t=>{!this._delegate.handleKeyDown(t)||t.ctrlKey||t.metaKey||t.stopPropagation()},keyup:t=>{(this._delegate.handleKeyUp?.(t)??!1)&&t.stopPropagation()}};t.addEventListener("mousedown",i.mousedown),t.addEventListener("mousemove",i.mousemove),t.addEventListener("wheel",i.wheel),t.addEventListener("dblclick",i.dblclick),t.addEventListener("contextmenu",i.contextmenu),t.addEventListener("touchstart",i.touchstart,{passive:!1}),t.addEventListener("touchmove",i.touchmove,{passive:!1}),t.addEventListener("touchend",i.touchend),t.addEventListener("keydown",i.keydown),t.addEventListener("keyup",i.keyup),this._boundHandlers=i}cleanup(){this._removeDocCapture();const t=this._hostElement,e=this._boundHandlers;t&&e&&(t.removeEventListener("mousedown",e.mousedown),t.removeEventListener("mousemove",e.mousemove),t.removeEventListener("wheel",e.wheel),t.removeEventListener("dblclick",e.dblclick),t.removeEventListener("contextmenu",e.contextmenu),t.removeEventListener("touchstart",e.touchstart),t.removeEventListener("touchmove",e.touchmove),t.removeEventListener("touchend",e.touchend),t.removeEventListener("keydown",e.keydown),t.removeEventListener("keyup",e.keyup),t.removeAttribute("tabindex"),t.style.outline=""),this._boundHandlers=void 0,this._hostElement=void 0,this._mouseIsDown=!1,this._isDragging=!1}forceCleanupDragState(){this._removeDocCapture(),this._mouseIsDown=!1,this._isDragging=!1}clientToElementCoords(t,e){const n=this._hostElement;if(!n)return{x:t,y:e};const i=n.getBoundingClientRect();return{x:t-i.left,y:e-i.top}}updateMouseNDCFromClient(t,e){const n=this._hostElement?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const i=t-n.left,s=e-n.top;this._event.updateMouseNDC(i,s,0,0,n.width,n.height)}_onMouseDown(t){if(t.stopPropagation(),0!==t.button)return void(this._mouseIsDown&&(this._removeDocCapture(),this._isDragging&&(this._gizmo?.forwardEvent(new MouseEvent("pointerup",{bubbles:!1}),"pointerup"),this._controls?.onDragEnd?.({offsetX:t.offsetX,offsetY:t.offsetY})),this._mouseIsDown=!1,this._isDragging=!1));if(this._hostElement.focus(),this._removeDocCapture(),this._mouseIsDown=!1,this._isDragging=!1,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<wf.DRAG_THRESHOLD)return;this._isDragging=!0;const t=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:t.x,offsetY:t.y,altKey:!0})}const i=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:i.x,offsetY:i.y,altKey:!0})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);if(t.shiftKey&&!t.altKey&&!this._gizmo?.isEngaged){const e=this.clientToElementCoords(t.clientX,t.clientY);return this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation();const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<wf.DRAG_THRESHOLD)return;this._isDragging=!0,this._delegate.handleBoxSelectionStart?.(e.x,e.y)}const s=this.clientToElementCoords(t.clientX,t.clientY);this._delegate.handleBoxSelectionUpdate?.(s.x,s.y)},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging)this._delegate.handleBoxSelectionEnd?.(t.shiftKey,t.ctrlKey||t.metaKey);else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0)}if(this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.tryVertexDragStart?.(t))return this._mouseIsDown=!0,this._isDragging=!0,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleVertexDragMove?.(t)},this._docUpHandler=t=>{t.stopPropagation(),this._removeDocCapture(),this._delegate.handleVertexDragEnd?.(t),this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);this._delegate.captureMouseDownAltKey(t.altKey),this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown");let e=this._gizmo.isDragging;!e&&t.altKey&&this._delegate.tryAltClickSelect(t)&&(this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown"),e=this._gizmo.isDragging),this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{if(t.stopPropagation(),e)return void this._gizmo.forwardEvent(t,"pointermove");const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<wf.DRAG_THRESHOLD)return;this._isDragging=!0;const e=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:e.x,offsetY:e.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}const s=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:s.x,offsetY:s.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),e)return this._gizmo.forwardEvent(t,"pointerup"),this._mouseIsDown=!1,void(this._isDragging=!1);if(this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),document.addEventListener("mouseup",this._docUpHandler,!0)}_onMouseMove(t){if(t.stopPropagation(),this._mouseIsDown)return;if(this._delegate.isPlacementMode())return void this._delegate.handlePlacementHover(t);this.updateMouseNDCFromClient(t.clientX,t.clientY);const e=this._camera.activeCamera;e&&this._scene.scene&&this._event.handleHover(e,this._scene.scene,t),this._gizmo.forwardEvent(t,"pointermove")}_removeDocCapture(){this._docMoveHandler&&(document.removeEventListener("mousemove",this._docMoveHandler,!0),this._docMoveHandler=void 0),this._docUpHandler&&(document.removeEventListener("mouseup",this._docUpHandler,!0),this._docUpHandler=void 0)}}wf.DRAG_THRESHOLD=16;class Mf{constructor(){this._groundPlane=new e.Plane(new e.Vector3(0,1,0),0)}get isActive(){return!!this._pendingModels}get pendingModels(){return this._pendingModels}setup(t,e){this._camera=t.camera,this._event=t.event,this._scene=t.scene,this._delegate=e}start(t){this._pendingModels=t}stop(){this._pendingModels=void 0,this._removeIndicator()}destroy(){this._removeIndicator(),this._pendingModels=void 0}raycastGroundPlane(t){this._delegate.updateMouseNDCFromClient(t.clientX,t.clientY);const n=this._camera.activeCamera;if(!n)return null;n.updateMatrixWorld(!0);const i=new e.Raycaster;i.setFromCamera(this._event.mouse,n);const s=new e.Vector3;return i.ray.intersectPlane(this._groundPlane,s)}updateIndicator(t){if(!t)return void(this._placementIndicator&&(this._placementIndicator.visible=!1));if(!this._placementIndicator){const t=this._scene?.scene;if(!t)return;const n=new e.RingGeometry(.8,1,32);n.rotateX(-Math.PI/2);const i=new e.MeshBasicMaterial({color:48340,opacity:.6,transparent:!0,side:e.DoubleSide,depthTest:!1});this._placementIndicator=new e.Mesh(n,i),this._placementIndicator.renderOrder=999,t.add(this._placementIndicator)}const n=this._pendingModels?.[0],i=n?.rx??n?.width??50,s=n?.ry??n?.height??50;this._placementIndicator.scale.set(i,1,s),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 Sf={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 kf(t,n,i,s,r,o=new e.Vector3){const a=t*t,c=a*t;return o.set(.5*(2*i.x+(-n.x+s.x)*t+(2*n.x-5*i.x+4*s.x-r.x)*a+(-n.x+3*i.x-3*s.x+r.x)*c),.5*(2*i.y+(-n.y+s.y)*t+(2*n.y-5*i.y+4*s.y-r.y)*a+(-n.y+3*i.y-3*s.y+r.y)*c),.5*(2*i.z+(-n.z+s.z)*t+(2*n.z-5*i.z+4*s.z-r.z)*a+(-n.z+3*i.z-3*s.z+r.z)*c))}class Af{constructor(){this._slots=new Array(10),this._animating=!1,this._animationProgress=0,this._playStartOffset=0,this._lastPlayProgress=-1,this._playIndex=-1,this._playing=!1,this._orbitRotating=!1,this._orbitPaused=!1}get isAnimating(){return this._animating}get isPlaying(){return this._playing}get isOrbitRotating(){return this._orbitRotating}get isOrbitPaused(){return this._orbitPaused}get playIndex(){return this._playIndex}get lastPlayProgress(){return this._lastPlayProgress}get playProgress(){if(!this._playing||this._playIndex<0)return 0;const t=this.getPlayableSlots().length;if(t<2)return 0;const e=(this._playIndex-1+t)%t;let n=this._animating?this._animationProgress:1;return this._playStartOffset>0&&(n=this._playStartOffset+n*(1-this._playStartOffset)),(e+n)%t/t}setCallbacks(t,e){this._onInvalidate=t,this._onAnimationComplete=e}saveSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];this._slots[t]={...e,name:"name"in e?e.name:n?.name}}renameSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];n&&(n.name=e||void 0)}clearSlot(t){t<0||t>9||(this._slots[t]=void 0)}getSlot(t){return this._slots[t]}exportSlots(){return this._slots.map(t=>t?{...t}:null)}importSlots(t){if(Array.isArray(t))for(let e=0;e<10;e++){const n=t[e];this._slots[e]=n?{...n}:void 0}}resetAll(){this._slots=new Array(10)}getPlayableSlots(){return this._slots.map((t,e)=>t&&!t.excludeFromPlay?e:-1).filter(t=>t>=0)}swapSlots(t,e){if(t<0||t>9||e<0||e>9||t===e)return;const n=this._slots[t];this._slots[t]=this._slots[e],this._slots[e]=n}moveSlot(t,e){if(t<1||t>9||e<1||e>9||t===e)return;const n=this._slots[t];this._slots.splice(t,1),this._slots.splice(e,0,n)}animateToSlot(t,n,i,s=800,r){const o=this._slots[t];if(!o)return!1;this.stopAnimation(),this._animating=!0,this._animationProgress=0;const a=n.position.clone(),c=i.target.clone(),l=new e.Vector3(o.position.x,o.position.y,o.position.z),h=new e.Vector3(o.target.x,o.target.y,o.target.z),d=.01,u=Math.max(a.distanceTo(c),d),p=Math.max(l.distanceTo(h),d),f=(new e.Vector3).subVectors(c,a),m=(new e.Vector3).subVectors(h,l),g=f.lengthSq()>1e-4?f.normalize():new e.Vector3(0,0,-1).applyQuaternion(n.quaternion),y=m.lengthSq()>1e-4?m.normalize():g.clone(),b=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),g),_=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),y),v=Sf[o.easing??"ease-in-out"];return this._runAnimation(s,v,t=>{r?kf(t,r.prevPos,a,l,r.nextPos,n.position):n.position.lerpVectors(a,l,t);const s=b.clone().slerp(_,t),o=new e.Vector3(0,0,-1).applyQuaternion(s),c=u+(p-u)*t,h=n.position.clone().add(o.multiplyScalar(c));i.restoreTarget(h)}),!0}_animatePathSegment(t,e,n,i,s,r){const o=Sf[i];this._runAnimation(n,o,n=>{const i=t+(e-t)*n,o=this.evaluatePath(i<=1?i:i-1);o&&(s.position.copy(o.position),r.restoreTarget(o.target))})}_runAnimation(t,e,n){this.stopAnimation(),this._animating=!0,this._animationProgress=0;const i=performance.now(),s=()=>{const r=performance.now()-i,o=Math.min(r/t,1),a=e(o);this._animationProgress=a,n(a),this._onInvalidate?.(),o<1?this._animationId=requestAnimationFrame(s):(this._animating=!1,this._animationId=void 0,this._onAnimationComplete?.())};this._animationId=requestAnimationFrame(s)}_initFromProgress(t,e){const n=t*e,i=Math.min(Math.floor(n),e-1);this._playStartOffset=n-i,this._playIndex=(i+1)%e}startPlay(t,n,i=2e3,s=1200,r=-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=r>=0&&r<=1?r: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],r=this._slots[e],o=r?.holdDuration??i,h=r?.transitionDuration??s;if(l>=0){const e=l;let i=this._playIndex/a.length;i<=e&&(i+=1),l=-1;const s=this._playStartOffset,c=Math.max(Math.round(h*(1-s)),100);return u(o),void this._animatePathSegment(e,i,c,r?.easing??"ease-in-out",t,n)}const p=this._buildSplineContext(a,c,t,n,d);c=!1,u(o),this.animateToSlot(e,t,n,h,p)};p()}_buildSplineContext(t,e,n,i,s){if(t.length<3)return;const r=t.length,o=t[(this._playIndex+1)%r],a=this._slots[o];if(!a)return;if(e)return{prevPos:n.position.clone(),nextPos:s(a.position)};const c=t[(this._playIndex-2+r)%r],l=this._slots[c];return l?{prevPos:s(l.position),nextPos:s(a.position)}:void 0}setProgressForSlot(t){const e=this.getPlayableSlots(),n=e.indexOf(t);n<0||e.length<2?this._lastPlayProgress=-1:this._lastPlayProgress=n/e.length}stopPlay(){this._lastPlayProgress=this.playProgress,this._playing=!1,this._playIndex=-1,this._playStartOffset=0,this._onAnimationComplete=void 0,this.stopAnimation()}resetPlay(){this.stopPlay(),this._lastPlayProgress=-1}toggleOrbitRotation(t){const e=t.isAutoRotating();this._orbitRotating=!e,this._orbitPaused=!this._orbitRotating,t.setAutoRotate(this._orbitRotating)}stopOrbitRotation(t){this._orbitRotating=!1,this._orbitPaused=!1,t.setAutoRotate(!1)}evaluatePath(t){const n=this.getPlayableSlots();if(n.length<2)return null;const i=n.length,s=Math.max(0,Math.min(1,t)),r=t=>{const s=this._slots[n[(t%i+i)%i]];return s?new e.Vector3(s.position.x,s.position.y,s.position.z):new e.Vector3},o=t=>{const s=this._slots[n[(t%i+i)%i]];return s?new e.Vector3(s.target.x,s.target.y,s.target.z):new e.Vector3};if(2===i){const t=s<.5?2*s:2*(1-s);return{position:r(0).lerp(r(1),t),target:o(0).lerp(o(1),t)}}const a=s*i,c=Math.min(Math.floor(a),i-1),l=a-c,h=kf(l,r(c-1),r(c),r(c+1),r(c+2)),d=r(c),u=r(c+1),p=o(c),f=o(c+1),m=.01,g=Math.max(d.distanceTo(p),m),y=Math.max(u.distanceTo(f),m),b=(new e.Vector3).subVectors(p,d),_=(new e.Vector3).subVectors(f,u),v=b.lengthSq()>1e-4?b.normalize():new e.Vector3(0,0,-1),x=_.lengthSq()>1e-4?_.normalize():v.clone(),w=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),v),M=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),x),S=w.clone().slerp(M,l),k=new e.Vector3(0,0,-1).applyQuaternion(S),A=g+(y-g)*l,E=h.clone().add(k.multiplyScalar(A));return{position:h,target:E}}stopAnimation(){void 0!==this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=void 0),this._animating=!1}destroy(){this.stopPlay(),this.stopAnimation(),this._orbitPaused=!1,this._slots=new Array(10),this._onInvalidate=void 0,this._onAnimationComplete=void 0}}class Ef{constructor(){this._overlay=null,this._hostElement=null,this._startX=0,this._startY=0,this._currentX=0,this._currentY=0,this._active=!1}get isActive(){return this._active}setup(t){this._hostElement=t}startSelection(t,e){this._hostElement&&(this._startX=t,this._startY=e,this._currentX=t,this._currentY=e,this._active=!0,this._overlay=document.createElement("div"),this._overlay.style.cssText="\n position: absolute;\n border: 1px solid #4a9eff;\n background: rgba(74, 158, 255, 0.1);\n pointer-events: none;\n z-index: 1000;\n ",this._hostElement.appendChild(this._overlay),this._updateOverlay())}updateSelection(t,e){this._active&&(this._currentX=t,this._currentY=e,this._updateOverlay())}endSelection(t,n,i){if(!this._active||!this._hostElement)return this.cancelSelection(),[];const s=this._hostElement.getBoundingClientRect(),r=s.width,o=s.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/r*2-1,u=c/r*2-1,p=-h/o*2+1,f=-l/o*2+1,m=[],g=new e.Vector3;for(const e of i){const n=e._realObject;n?.object3d&&(g.copy(n.object3d.position),g.project(t),g.z>1||g.x>=d&&g.x<=u&&g.y>=p&&g.y<=f&&m.push(e))}return this.cancelSelection(),m}cancelSelection(){this._active=!1,this._overlay&&this._hostElement&&this._hostElement.removeChild(this._overlay),this._overlay=null}destroy(){this.cancelSelection(),this._hostElement=null}_updateOverlay(){if(!this._overlay)return;const t=Math.min(this._startX,this._currentX),e=Math.min(this._startY,this._currentY),n=Math.abs(this._currentX-this._startX),i=Math.abs(this._currentY-this._startY);this._overlay.style.left=`${t}px`,this._overlay.style.top=`${e}px`,this._overlay.style.width=`${n}px`,this._overlay.style.height=`${i}px`}}const Cf=4890367,Tf=16750592,Pf=1733608,Of=8077298;class Df{constructor(){this._componentHandles=[],this._activeVertexHandles=[],this._activeHandleIndex=-1,this._activeKind="vertex",this._isDragging=!1,this._isPending=!1,this._pendingScreenStart={x:0,y:0},this._dragPlane=new e.Plane,this._dragOffset=new e.Vector3,this._raycaster=new e.Raycaster,this._intersection=new e.Vector3}get isDragging(){return this._isDragging}get isAttached(){return this._componentHandles.length>0}setVisible(t){this._handleGroup&&(this._handleGroup.visible=t)}attachMultiple(t,n,i){this.detach();const s=t.filter(t=>t.mutable&&t.path&&t.path.length>=2);if(0!==s.length){this._scene3d=n,this._commander=i,this._handleGroup=new e.Group,this._handleGroup.name="__vertexHandles__",this._handleGroup.renderOrder=1e4;for(const t of s){const e=this._buildComponentHandles(t);this._componentHandles.push(e)}n.add(this._handleGroup)}}attach(t,e,n){this.attachMultiple([t],e,n)}detach(){this._handleGroup&&this._scene3d&&(this._scene3d.remove(this._handleGroup),eu(this._handleGroup)),this._componentHandles=[],this._handleGroup=void 0,this._scene3d=void 0,this._commander=void 0,this._activeComponent=void 0,this._activeVertexHandles=[],this._activeHandleIndex=-1,this._activeKind="vertex",this._activeHandle=void 0,this._isDragging=!1,this._isPending=!1,this._pendingHit=void 0,this._pendingHandleType=void 0}_buildComponentHandles(t){const n=[],i=[],s=[],r=[],o={component:t,vertexHandles:n,midpointHandles:i,cornerHandles:s,bulgeHandles:r},a=t.path;if(!a||!this._handleGroup)return o;const{width:c=0,height:l=0}=t.parent?.bounds??{},h=t._realObject,d=h?h.object3d.position.y:0,u=!!t.cornerEditable,p=t.state?.round??0,f=u&&!t.isLine?.();for(let i=0;i<a.length;i++){const s=a[i],r=new e.Vector3(s.x-c/2,(s.z||0)+d,s.y-l/2),o=this._createVertexHandle(r,i,t);n.push(o),this._handleGroup.add(o)}if(t.pathExtendable)for(let n=0;n<a.length-1;n++){const s=a[n],r=a[n+1],o=new e.Vector3((s.x+r.x)/2-c/2,((s.z||0)+(r.z||0))/2+d,(s.y+r.y)/2-l/2),h=this._createMidpointHandle(o,n,t);i.push(h),this._handleGroup.add(h)}if(u){const n=f?0:1,i=f?a.length:a.length-1;for(let r=n;r<i;r++){const n=a[(r-1+a.length)%a.length],i=a[r],o=eo(n,i,a[(r+1)%a.length],to(i,p),24);if(!o)continue;const h=new e.Vector3(o.x-c/2,(i.z||0)+d,o.y-l/2),u=this._createCornerHandle(h,r,t);s.push(u),this._handleGroup.add(u)}const o=f?a.length:a.length-1;for(let n=0;n<o;n++){const i=a[n],s=a[(n+1)%a.length],o=Zr(i,s,i.bulge??0,24);if(!o)continue;const h=new e.Vector3(o.x-c/2,((i.z||0)+(s.z||0))/2+d,o.y-l/2),u=this._createBulgeHandle(h,n,t);r.push(u),this._handleGroup.add(u)}}return{component:t,vertexHandles:n,midpointHandles:i,cornerHandles:s,bulgeHandles:r}}_rebuildComponentHandles(t){const e=this._componentHandles.findIndex(e=>e.component===t);if(e<0||!this._handleGroup)return;const n=this._componentHandles[e];for(const t of[...n.vertexHandles,...n.midpointHandles,...n.cornerHandles,...n.bulgeHandles])this._handleGroup.remove(t),t.geometry.dispose(),t.material.dispose();this._componentHandles[e]=this._buildComponentHandles(t),this._activeComponent===t&&(this._activeVertexHandles=this._componentHandles[e].vertexHandles)}_createVertexHandle(t,n,i){const s=new e.SphereGeometry(1,16,12),r=new e.MeshBasicMaterial({color:Cf,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.vertexIndex=n,o.userData.handleType="vertex",o.userData.component=i,o.renderOrder=10001,o}_createMidpointHandle(t,n,i){const s=new e.OctahedronGeometry(.7,0),r=new e.MeshBasicMaterial({color:16735602,transparent:!0,opacity:.7,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.segmentIndex=n,o.userData.handleType="midpoint",o.userData.component=i,o.renderOrder=10001,o}_createCornerHandle(t,n,i){const s=new e.SphereGeometry(1,12,10),r=new e.MeshBasicMaterial({color:Pf,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.vertexIndex=n,o.userData.handleType="corner",o.userData.component=i,o.renderOrder=10001,o}_createBulgeHandle(t,n,i){const s=new e.OctahedronGeometry(1,0),r=new e.MeshBasicMaterial({color:Of,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.segmentIndex=n,o.userData.handleType="bulge",o.userData.component=i,o.renderOrder=10001,o}_handlePosToPoint(t,e){const{width:n=0,height:i=0}=e.parent?.bounds??{},s=e._realObject,r=s?s.object3d.position.y:0,o={x:t.x+n/2,y:t.z+i/2},a=t.y-r;return Math.abs(a)>.001&&(o.z=a),o}_execMutatePath(t,e){const n=this._commander;n?ll.around(n,()=>{t.mutatePath(null,e)}):t.mutatePath(null,e)}_getAllHandles(){const t=[];for(const e of this._componentHandles)t.push(...e.vertexHandles,...e.midpointHandles,...e.cornerHandles,...e.bulgeHandles);return t}_findComponentHandles(t){return this._componentHandles.find(e=>e.component===t)}onPointerDown(t,e,n){if(this._isPending=!1,this._pendingHit=void 0,this._pendingHandleType=void 0,!this._handleGroup)return!1;this._raycaster.setFromCamera(t,e);const i=[];for(const t of this._componentHandles)i.push(...t.vertexHandles,...t.midpointHandles);let s,r,o=i.length>0?this._raycaster.intersectObjects(i,!1):[];if(o.length>0)s=o[0].object,r=s.userData.handleType;else{const t=[];for(const e of this._componentHandles)t.push(...e.cornerHandles,...e.bulgeHandles);if(0===t.length)return!1;if(o=this._raycaster.intersectObjects(t,!1),0===o.length)return!1;s=o[0].object,r=s.userData.handleType}if(!s||!r)return!1;const a=s.userData.component,c=this._findComponentHandles(a);return!!c&&(this._activeComponent=a,this._activeVertexHandles=c.vertexHandles,this._pendingHit=s,this._pendingHandleType=r,this._pendingScreenStart={x:n.clientX,y:n.clientY},this._isPending=!0,this._isDragging=!1,!0)}_beginDrag(t,e){const n=this._pendingHit,i=this._activeComponent,s=this._pendingHandleType;if(!n||!i||!s)return!1;if("midpoint"===s)return this._activeKind="midpoint",this._startMidpointDrag(n,i,t);if("corner"===s)return this._startCornerDrag(n,i,t);if("bulge"===s)return this._startBulgeDrag(n,i,t);const r=n.userData.vertexIndex,o=i.path;if(!o)return!1;const a=0===r||r===o.length-1;return e.altKey&&a&&i.pathExtendable?(this._activeKind="vertex",this._startEndpointExtend(n,r,i,t)):(this._activeKind="vertex",this._activeHandle=n,this._activeHandleIndex=r,this._isDragging=!0,n.material.color.setHex(Tf),this._setupDragPlane(t,n.position),!0)}_startCornerDrag(t,e,n){const i=t.userData.vertexIndex;return!!e.path&&(this._activeKind="corner",this._activeHandleIndex=i,this._activeHandle=t,this._isDragging=!0,t.material.color.setHex(Tf),this._setupDragPlane(n,t.position),!0)}_startBulgeDrag(t,e,n){const i=t.userData.segmentIndex;return!!e.path&&(this._activeKind="bulge",this._activeHandleIndex=i,this._activeHandle=t,this._isDragging=!0,t.material.color.setHex(Tf),this._setupDragPlane(n,t.position),!0)}_startMidpointDrag(t,e,n){const i=t.userData.segmentIndex+1,s=this._handlePosToPoint(t.position,e);this._execMutatePath(e,t=>{t.splice(i,0,s)}),this._rebuildComponentHandles(e);const r=this._activeVertexHandles[i];return!!r&&(this._activeHandleIndex=i,this._isDragging=!0,r.material.color.setHex(Tf),this._setupDragPlane(n,r.position),!0)}_startEndpointExtend(t,e,n,i){const s=n.path;if(!s)return!1;const r=this._handlePosToPoint(t.position,n),o=0===e?0:s.length;this._execMutatePath(n,t=>{t.splice(o,0,r)}),this._rebuildComponentHandles(n);const a=this._activeVertexHandles[o];return!!a&&(this._activeHandleIndex=o,this._isDragging=!0,a.material.color.setHex(Tf),this._setupDragPlane(i,a.position),!0)}_setupDragPlane(t,n){const i=new e.Vector3;t.getWorldDirection(i),this._dragPlane.setFromNormalAndCoplanarPoint(i,n),this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection),this._dragOffset.copy(n).sub(this._intersection)}onPointerMove(t,e,n){if(this._raycaster.setFromCamera(t,e),this._isPending){const t=n.clientX-this._pendingScreenStart.x,i=n.clientY-this._pendingScreenStart.y;if(t*t+i*i<16)return!1;if(this._isPending=!1,!this._beginDrag(e,n))return!1}if(!this._isDragging||this._activeHandleIndex<0)return!1;this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection);const i=this._intersection.add(this._dragOffset);if("corner"===this._activeKind)return this._dragCornerLive(i),!0;if("bulge"===this._activeKind)return this._dragBulgeLive(i),!0;if(n.shiftKey){const t=this._activeVertexHandles[this._activeHandleIndex];t&&(i.x=t.position.x,i.z=t.position.z)}const s=this._activeVertexHandles[this._activeHandleIndex];s&&s.position.copy(i);const r=this._activeComponent;if(r){const t=this._activeHandleIndex,e=this._handlePosToPoint(i,r);r.mutatePath(null,n=>{const i={...n[t]||{},x:e.x,y:e.y};void 0!==e.z&&(i.z=e.z),n[t]=i}),r.invalidate?.()}return this._updateLinePreview(),!0}_dragCornerLive(t){const e=this._activeComponent;if(!e)return;const n=e.path,i=this._activeHandleIndex;if(!n||i<0)return;const{width:s=0,height:r=0}=e.parent?.bounds??{},o={x:t.x+s/2,y:t.z+r/2},a=n[(i-1+n.length)%n.length],c=n[i],l=n[(i+1)%n.length],h=no(a,c,l,o);if(e.mutatePath(null,function(t){const e=t[i]||{};t[i]={...e,radius:h}}),e.invalidate?.(),this._activeHandle){const t=e.state?.round??0,n=e._realObject,i=n?n.object3d.position.y:0,o=eo(a,c,l,to(c,t),24);o&&this._activeHandle.position.set(o.x-s/2,(c.z||0)+i,o.y-r/2)}}_dragBulgeLive(t){const e=this._activeComponent;if(!e)return;const n=e.path,i=this._activeHandleIndex;if(!n||i<0)return;const{width:s=0,height:r=0}=e.parent?.bounds??{},o={x:t.x+s/2,y:t.z+r/2},a=n[i],c=n[(i+1)%n.length],l=Jr(a,c,o);if(e.mutatePath(null,function(t){const e=t[i]||{};if(0===l){const{bulge:n,...s}=e;t[i]=s}else t[i]={...e,bulge:l}}),e.invalidate?.(),this._activeHandle){const t=e._realObject,n=t?t.object3d.position.y:0,i=Zr(a,c,l,24);i&&this._activeHandle.position.set(i.x-s/2,((a.z||0)+(c.z||0))/2+n,i.y-r/2)}}_updateLinePreview(){if(!this._activeComponent)return;const t=this._activeComponent._realObject;if(!t?._line2)return;const{width:e=0,height:n=0}=this._activeComponent.parent?.bounds??{},{x:i,y:s}=this._activeComponent.center,r=t.object3d?t.object3d.position.y:0,o=[];for(const t of this._activeVertexHandles){const a=t.position.x+e/2-i,c=t.position.y-r,l=t.position.z+n/2-s;o.push(a,c,l)}if(o.length<6)return;t._line2.geometry.setPositions(o),t._line2.computeLineDistances()}onPointerUp(){if(this._isPending&&!this._isDragging)return this._isPending=!1,this._pendingHit=void 0,this._pendingHandleType=void 0,this._activeComponent=void 0,this._activeHandle=void 0,this._activeHandleIndex=-1,!0;if(!this._isDragging||this._activeHandleIndex<0||!this._activeComponent)return!1;const t=this._activeComponent,e=this._activeHandleIndex,n=this._activeKind;if("corner"===n||"bulge"===n){if(this._activeHandle){const t="corner"===n?Pf:Of;this._activeHandle.material.color.setHex(t)}return this._isDragging=!1,this._activeHandleIndex=-1,this._activeHandle=void 0,this._rebuildComponentHandles(t),!0}const i=this._activeVertexHandles[e];if(!i)return this._isDragging=!1,this._activeHandleIndex=-1,!0;i.material.color.setHex(Cf);const s=this._handlePosToPoint(i.position,t);return this._execMutatePath(t,t=>{const n={...t[e]||{},x:s.x,y:s.y};void 0!==s.z&&(n.z=s.z),t[e]=n}),this._isDragging=!1,this._activeHandleIndex=-1,this._activeHandle=void 0,this._rebuildComponentHandles(t),!0}onDblClick(t,e){if(!this._handleGroup)return!1;this._raycaster.setFromCamera(t,e);const n=[];for(const t of this._componentHandles)n.push(...t.vertexHandles);if(n.length>0){const t=this._raycaster.intersectObjects(n,!1);if(t.length>0){const e=t[0].object,n=e.userData.component;if(!n.pathExtendable)return!1;const i=n.path;if(!i||i.length<=2)return!1;const s=e.userData.vertexIndex;return this._execMutatePath(n,t=>{t.splice(s,1)}),this._rebuildComponentHandles(n),!0}}const i=[];for(const t of this._componentHandles)i.push(...t.cornerHandles,...t.bulgeHandles);if(0===i.length)return!1;const s=this._raycaster.intersectObjects(i,!1);if(0===s.length)return!1;const r=s[0].object,o=r.userData.handleType,a=r.userData.component;if("corner"===o){const t=r.userData.vertexIndex;return this._execMutatePath(a,e=>{const n=e[t]||{},{radius:i,...s}=n;e[t]=s}),this._rebuildComponentHandles(a),!0}if("bulge"===o){const t=r.userData.segmentIndex;return this._execMutatePath(a,e=>{const n=e[t]||{},{bulge:i,...s}=n;e[t]=s}),this._rebuildComponentHandles(a),!0}return!1}syncHandles(){for(const t of this._componentHandles)this._rebuildComponentHandles(t.component)}updateHandleScales(t){const e=this._getAllHandles();if(0!==e.length)for(const n of e){const e=t.position.distanceTo(n.position),i=n.userData.handleType,s="midpoint"===i?5:"corner"===i||"bulge"===i?9:8;let r;if(t.isPerspectiveCamera){const n=t.fov,i=2*Math.tan(n*Math.PI/360)*e;r=s/window.innerHeight*i}else{const e=t,n=(e.top-e.bottom)/e.zoom;r=s/window.innerHeight*n}n.scale.setScalar(Math.max(r,.1))}}destroy(){this.detach()}}class zf{constructor(){this.sceneManager=new hf,this.cameraManager=new df,this.rendererManager=new uf,this.lightManager=new pf,this.controlsManager=new mf,this.eventManager=new gf,this.gizmoManager=new bf,this.interactionManager=new wf,this.placementManager=new Mf,this.gizmoOperationManager=new xf,this.bookmarkManager=new Af,this.boxSelectionManager=new Ef,this.vertexGizmoManager=new Df,this._isSpacePanning=!1,this._initialized=!1,this._decoratorOutlines=new Set,this._selectionOutlineObjects=[],this._highlightedMarkerIndex=-1,this._arrows=new Map,this._pathVisible=!1}get isInitialized(){return this._initialized}get host(){return this._host}get scene3d(){return this.sceneManager.scene}get renderer3d(){return this.rendererManager.renderer}get mixer(){return this.sceneManager.mixer}get camera(){return this.cameraManager.camera}get activeCamera(){return this.cameraManager.activeCamera}get css3DScene(){return this.rendererManager.css3DScene}get css3DRenderer(){return this.rendererManager.css3DRenderer}get noSupportWebgl(){return this.rendererManager.noSupportWebgl}get isActive(){return this.controlsManager.isActive}setGizmoMode(t){if(this.gizmoManager.mode===t&&this.gizmoManager.attached)return this.gizmoManager.detach(),void this._host?.invalidate();this.gizmoManager.setMode(t),this.onGizmoModeChanged?.(t);const e=this._host?.root?.selected,n=e?.filter(t=>t!==this._host&&t._realObject)||[];if(n.length>=1){const e=n[0]._realObject;if(e?.object3d&&e.gizmoTransformable&&!n[0].stuck){const n=e.allowedGizmoModes;if(!n||n.includes(t)){const t=fu(e)&&e.pickedPart?e.partObject(e.pickedPart):void 0;this.gizmoManager.attach(t??e.object3d)}else this.gizmoManager.detach()}else this.gizmoManager.detach();this._host?.invalidate()}}get gizmoMode(){return this.gizmoManager.mode}init(t,e){this.interactionManager.cleanup(),this._cleanupEventHandlers(),this._host=t,this.sceneManager.scene&&this.destroy(),this._redrawHandler=()=>{this.eventManager.clearHoverIfUnpickable(),this.animate()},t.root.on("redraw",this._redrawHandler),this._initialized=!0,this._setupScene(e),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),this._onItemAdd=(t,e)=>this.addObject(e),this._onItemRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove),t.on("hold",this._onItemAdd),t.on("release",this._onItemRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged),this._onPartChanged=()=>{this._updateSelectionOutline(t.root?.selected??[]),this._host?.invalidate()},t.root.on("partchanged",this._onPartChanged)),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._onItemAdd&&(t.off("hold",this._onItemAdd),this._onItemAdd=void 0),this._onItemRemove&&(t.off("release",this._onItemRemove),this._onItemRemove=void 0)),this._onSelectionChanged&&t.root?.off&&(t.root.off("selected",this._onSelectionChanged),this._onSelectionChanged=void 0),this._onPartChanged&&t.root?.off&&(t.root.off("partchanged",this._onPartChanged),this._onPartChanged=void 0),this._onAddStart&&t.root?.off&&(t.root.off("addstart",this._onAddStart),this._onAddStart=void 0),this._onAddStop&&t.root?.off&&(t.root.off("addstop",this._onAddStop),this._onAddStop=void 0))}_setupScene(t){const e=this._host;let{width:n,height:i}=e.bounds;n=Math.abs(n)||1,i=Math.abs(i)||1;const{fov:s=45,near:r=.1,far:o=2e4,antialias:a=!0,pixelRatio:c,precision:l="highp",cameraX:h,cameraY:d,cameraZ:u,exposure:p=1.2}=e.state,f=e.components||[],m=t?.lightingConfig??{hemisphere:{skyColor:16777215,groundColor:4473924,intensity:.4}},g=t?.css3DSceneAttribute??"three-container:css3d-renderer",y=this.sceneManager.setup();this._setupCoordinateGround(y,e);const b=this.cameraManager.setup(n,i,{fov:s,near:r,far:o,cameraX:h,cameraY:d,cameraZ:u});this.cameraManager.addToScene(y);const _=e.app?.postprocessing,v=!t?.skipShadowMap&&void 0;let x;if(x=!t?.skipPostprocessing&&("boolean"==typeof e.state?.logarithmicDepth?e.state.logarithmicDepth:"boolean"==typeof e.app?.logarithmicDepth?e.app.logarithmicDepth:!!lf(e.state?.sky)||void 0),this.rendererManager.setupWebGL(n,i,{precision:l,antialias:a,exposure:p,postprocessing:_,shadowMap:v,logarithmicDepthBuffer:x,pixelRatio:c})){if(t?.skipEnvironment||this.sceneManager.setupEnvironment(this.rendererManager.renderer),this.controlsManager.setup(b,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(b,e.element,y),this._setupGizmoCallbacks()),this.placementManager.setup({camera:this.cameraManager,event:this.eventManager,scene:this.sceneManager},{updateMouseNDCFromClient:(t,e)=>this._updateMouseNDCFromClient(t,e)}),this.lightManager.setup(y,b,m),this.sceneManager.setupMixer(),this.createObjects(f),b.updateProjectionMatrix(),t?.skipFloor||this.sceneManager.addFloor(e),this.sceneManager.setSky(e.state.sky,e.state.skyColor,e.state.environment),t?.skipPostprocessing||!1===e.app?.postprocessing)t?.useLightComposer?this.rendererManager.setupLightComposer(y,b,n,i):this.rendererManager.setDirectRenderTargets(y,b);else{const t=this.gizmoManager.controls?.getHelper();this.rendererManager.setupComposer(y,b,n,i,t)}this.rendererManager.setupHUD(n,i),this.rendererManager.hudCamera&&this.eventManager.setHUD(this.rendererManager.hudScene,this.rendererManager.hudCamera),this.rendererManager.setupCSS3D(e.app.isViewMode,g),this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus),e.element&&(this.interactionManager.setup(e.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate()),e.app?.isEditMode&&this.boxSelectionManager.setup(e.element))}}_setupGizmoCallbacks(){this.gizmoOperationManager.setupCallbacks(this.gizmoManager,this.controlsManager,()=>{const t=this._host;if(t)return Object.create(t,{hostElement:{get:()=>t.target??t.element??void 0}})},{onAttachChanged:t=>this.onGizmoAttachChanged?.(t),onDraggingChanged:t=>{t?this.vertexGizmoManager.setVisible(!1):(this.vertexGizmoManager.syncHandles(),this.vertexGizmoManager.setVisible(!0))}})}createObjects(t){for(const e of t)this.addObject(e)}addObject(t){if(t._realObject){const e=t._realObject;if(e.object3d&&!e.object3d.parent)if(t.state.screenFixed)e instanceof Np?this.rendererManager.hudCSS3DScene.add(e.object3d):this.rendererManager.hudScene.add(e.object3d);else if(e instanceof Np)this.rendererManager.css3DScene.add(e.object3d);else{const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}return}if(!t.is3dContainer?.()&&"popup"!==t.state?.position){try{if(!t.isLine?.()){const{width:e,height:n}=t.bounds;if(!e||!n)return}if(t.isHTMLElement()&&!t.element)return;const e=Yp(t);if(e){if(t._realObject=e,e.update(),e.updateTransform(),t.state.screenFixed)e instanceof Np?this.rendererManager.hudCSS3DScene.add(e.object3d):this.rendererManager.hudScene.add(e.object3d);else if(e instanceof Np)this.rendererManager.css3DScene.add(e.object3d);else{const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}const n=this._host?.root?.selected;n&&n.length>0&&n[0]===t&&e.object3d&&e.gizmoTransformable&&this.gizmoManager.attached&&this.gizmoManager.attach(e.object3d)}}catch(t){Zi(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))}{const e=t;Array.isArray(e._items)&&(e._items.length>0&&(this.createObjects(e._items),t._realObject?.layoutHeldItems?.()),e.on&&(e.on("hold",this._onItemAdd),e.on("release",this._onItemRemove)))}}}removeObject(t){if(t.is3dContainer?.())return;if(t.isContainer()){const e=t,n=e.components||[];for(const t of n)this.removeObject(t);e.off&&(e.off("add",this._onComponentAdd),e.off("remove",this._onComponentRemove))}{const e=t;if(Array.isArray(e._items)){for(const t of e._items)this.removeObject(t);e.off&&(e.off("hold",this._onItemAdd),e.off("release",this._onItemRemove))}}const e=t._realObject;if(e)try{const n=e.object3d;n&&this.gizmoManager.attached===n&&this.gizmoManager.detach(),n&&(e instanceof Np?this.rendererManager.css3DScene.remove(n):n.removeFromParent()),e.dispose?.(),t._realObject=void 0}catch(t){Zi(t)}}resize(t,e,n=!1){const i=this._host;if(!i)return;if(void 0===t||void 0===e){const n=i.bounds;t=n.width,e=n.height}if(t=Math.abs(t)||1,e=Math.abs(e)||1,n)return void this._applyResize(t,e);this.rendererManager.css3DRenderer?.setSize(t,e);const s=t,r=e;clearTimeout(this._resizeDebouncer),this._resizeDebouncer=window.setTimeout(()=>{this._resizeDebouncer=void 0,this._applyResize(s,r)},100)}_applyResize(t,n){this.cameraManager.updateAspect(t,n),this.rendererManager.resize(t,n);const i=new e.Vector2(t,n);for(const t of this._arrows.values())t.traverse(t=>{t instanceof w&&t.material.resolution.copy(i)});this._initialized&&(this.renderThreeD(),this._host?.invalidate())}animate(){if(!this._initialized||!this.controlsManager.isActive)return;this.sceneManager.updateAnimation();let t=!1;const e=n=>{for(const i of n)i._animation?.started&&i._realObject&&(i._realObject.syncAnimationDelta(),t=!0),i.components&&e(i.components)};e(this._host?.components||[]),this.controlsManager.update(),this.renderThreeD(),t&&this._host?.invalidate()}get hasEnvironment(){return this.sceneManager.hasEnvironment}renderThreeD(){this._initialized&&(this.vertexGizmoManager?.isAttached&&this.vertexGizmoManager.updateHandleScales(this.cameraManager.activeCamera),this.rendererManager.render(),this.renderCSS3D())}setCameraView(t,e){const n=this._host;if(!n)return;const{width:i,height:s}=n.bounds,r=n.element,o=r?.clientWidth||i,a=r?.clientHeight||s;let c;c="perspective"===t?this.cameraManager.restorePerspective():this.cameraManager.setOrthoView(t,i,s,o,a),this.controlsManager.setCamera(c),this.gizmoManager.updateCamera(c),this.rendererManager.updateRenderPassCamera(c),!1!==e?.render&&this.renderThreeD(),this.onCameraViewChanged?.(t)}renderCSS3D(){const t=this.cameraManager.activeCamera;t&&this.rendererManager.renderCSS3D(t)}buildOverlays(){const t=this._host;if(!t?.element)return;t.element.appendChild(this.css3DRenderer.domElement);const e=this.rendererManager.hudCSS3DRenderer?.domElement;e&&t.element.appendChild(e)}_setupCoordinateGround(t,e){if(this._coordinateGround=void 0,!0!==e.state?.grid)return;const n=Number(e.state?.width)||0,i=Number(e.state?.height)||0,s=Number(e.state?.gridStep)||0,r=qp({step:s>0?s:$p(Math.max(n,i)),cells:Number(e.state?.gridCells)||void 0,background:"string"==typeof e.state?.skyColor?e.state.skyColor:void 0,labels:!1!==e.state?.gridLabels});t.add(r),this._coordinateGround=r}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._coordinateGround&&(Jp(this._coordinateGround),this._coordinateGround=void 0),this.vertexGizmoManager.destroy(),this.boxSelectionManager.destroy(),this.bookmarkManager.destroy(),this.gizmoManager.destroy(),this.controlsManager.destroy(),this.lightManager.destroy(),this.rendererManager.destroy(),this.cameraManager.destroy(),this.sceneManager.destroy(),this.eventManager.destroy(),this._initialized=!1}forceCleanupDragState(){this.interactionManager.forceCleanupDragState(),this.boxSelectionManager.isActive&&(this.boxSelectionManager.cancelSelection(),this.controlsManager.setEnabled(!0)),this._isSpacePanning&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0)),this._host?.element&&(this._host.element.style.cursor="")}clearAllObjects(){this.gizmoManager.detach();const t=this._host?.components||[];for(const e of t)e._realObject&&this.removeObject(e)}rebuildForHost(t,e){this.interactionManager.cleanup();try{this._cleanupEventHandlers()}catch(t){}this._host=t,this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged),this._onAddStart=t=>{this.placementManager.start(t),this._host?.element&&(this._host.element.style.cursor="crosshair",this._host.element.focus())},this._onAddStop=()=>{this.placementManager.stop(),this._host?.element&&(this._host.element.style.cursor="")},t.root.on("addstart",this._onAddStart),t.root.on("addstop",this._onAddStop)),this.createObjects(t.components||[]),t.element&&this.interactionManager.setup(t.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate());const n=this.controlsManager._position0?.clone(),i=this.controlsManager._target0?.clone();this.controlsManager.setup(this.cameraManager.camera,t),n&&this.controlsManager._position0.copy(n),i&&this.controlsManager._target0.copy(i),t.app?.isEditMode&&t.element&&this.boxSelectionManager.setup(t.element),t.app?.isEditMode&&t.element&&this.sceneManager.scene&&(this.gizmoManager.setup(this.cameraManager.camera,t.element,this.sceneManager.scene),this._setupGizmoCallbacks()),this._onFocus||(this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus)),this.renderThreeD()}dispose(){const t=e=>{for(const n of e)if(!n.is3dContainer?.()){if(n.isContainer()){const e=n.components||[];t(e)}n._realObject&&(n._realObject.dispose?.(),n._realObject=void 0)}};t(this._host?.components||[]),this._decoratorOutlines.clear(),this._selectionOutlineObjects=[],this.clearArrows(),this.placementManager.destroy(),this._cleanupEventHandlers(),this.rendererManager.disposeCSS3DScene(),this.destroy(),this._host=void 0}_buildInteractionDelegate(){return{isPlacementMode:()=>this.placementManager.isActive,handlePlacementClick:t=>{if(!this._host?.root)return;const e=this.placementManager.raycastGroundPlane(t);if(e){const t=this._host,n=t.bounds.width||800,i=t.bounds.height||600,s=e.x+n/2,r=e.z+i/2;Oh.call(t.root,this.placementManager.pendingModels,{cx:s,cy:r}),t.root.trigger("addstop")}},handlePlacementHover:t=>{const e=this.placementManager.raycastGroundPlane(t);this.placementManager.updateIndicator(e),this.renderThreeD()},tryAltClickSelect:t=>{if(!this._host?.app?.isEditMode||!this._host.root)return!1;this._updateMouseNDCFromClient(t.clientX,t.clientY);const e=this.cameraManager.activeCamera;if(e&&this.sceneManager.scene){const n=this.eventManager.handleClick(e,this.sceneManager.scene,t);if(n?.component)return this._host.root.selected=[n.component],!0}return!1},captureMouseDownAltKey:t=>{this.gizmoOperationManager.captureAltKey(t)},handleClickAt:(t,e,n)=>{this._handleClickAt(n)},handleWheel:t=>this.onWheel(t),handleDblClick:t=>this.onDblClick(t),handleTouchStart:t=>this.onTouchStart(t),handleTouchMove:t=>this.onPan(t),handleTouchEnd:t=>this.onTouchEnd(t),handleKeyDown:t=>this.onKeyDown(t),handleKeyUp:t=>this._onKeyUp(t),isSpacePanning:()=>this._isSpacePanning,handleBoxSelectionStart:(t,e)=>{this.controlsManager.setEnabled(!1),this._host?.element&&(this._host.element.style.cursor="crosshair"),this.boxSelectionManager.startSelection(t,e)},handleBoxSelectionUpdate:(t,e)=>{this.boxSelectionManager.updateSelection(t,e)},tryVertexDragStart:t=>{if(!this.vertexGizmoManager.isAttached)return!1;const e=this.cameraManager.activeCamera;if(!e)return!1;const n=this.eventManager.mouse,i=this.vertexGizmoManager.onPointerDown(n,e,t);return i&&this.controlsManager.setEnabled(!1),i},handleVertexDragMove:t=>{const e=this.cameraManager.activeCamera;if(!e)return;const n=this.eventManager.mouse;this.vertexGizmoManager.onPointerMove(n,e,t),this._host?.invalidate()},handleVertexDragEnd:t=>{this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),this._host?.invalidate()},handleBoxSelectionEnd:(t,e)=>{this.controlsManager.setEnabled(!0),this._host?.element&&(this._host.element.style.cursor="");const n=this.cameraManager.activeCamera,i=this.sceneManager.scene,s=this._host?.components||[];if(n&&i){let r=this.boxSelectionManager.endSelection(n,i,s);if(e&&t){const t=this._host?.root?.selected||[];if(t.length>0){const e=t[0].state?.type;e&&(r=r.filter(t=>t.state?.type===e))}}if(r.length>0&&this._host?.root)if(t){const t=this._host,e=(this._host.root.selected||[]).filter(e=>e!==t);for(const t of r)e.includes(t)||e.push(t);this._host.root.selected=e}else this._host.root.selected=r}else this.boxSelectionManager.cancelSelection()}}}_handleClickAt(t){const n=this._host,i=this.cameraManager.activeCamera;if(!i||!this.sceneManager.scene)return;if(this._pathMarkers&&this._pathMarkers.children.length>0){const t=new e.Raycaster,n=this.eventManager.mouse;t.setFromCamera(n,i);const s=t.intersectObjects(this._pathMarkers.children,!0);if(s.length>0){let t=s[0].object;for(;t&&void 0===t.userData.bookmarkSlotIndex;)t=t.parent;if(t&&void 0!==t.userData.bookmarkSlotIndex)return void this.animateToSlot(t.userData.bookmarkSlotIndex)}}if(this.vertexGizmoManager?.isDragging)return this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),void this._host?.invalidate();const s=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),s)return;const r=this.eventManager.handleClick(i,this.sceneManager.scene,t);if(n.root){const t=n.app?.mode;if(4===t||5===t){if(!r?.component){const e=4===t?"stylepastestop":"databindpastestop";n.root.trigger(e)}return}}n.app?.isEditMode&&n.root&&(this._applySelection(n.root,r?.component,t.shiftKey),fu(r)&&(this._updateSelectionOutline(n.root.selected??[]),this._host?.invalidate()))}_applySelection(t,e,n){if(e)if(n){const n=(t.selected||[]).slice(),i=n.indexOf(e);-1===i?n.push(e):n.splice(i,1),t.selected=n}else{let n=null,i=e.parent;for(;i?.isGroup?.();)n=i,i=i.parent;if(n){if(!(t.selected||[]).some(t=>{if(t===n)return!0;let e=t.parent;for(;e?.isGroup?.();){if(e===n)return!0;e=e.parent}return!1}))return void(t.selected=[n])}t.selected=[e]}else n||(t.selected=[])}getObjectByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectByRaycast(t,this.sceneManager.scene):void 0}getObjectsByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectsByRaycast(t,this.sceneManager.scene):void 0}_updateMouseNDCFromClient(t,e){const n=this._host?.element;if(n){const i=n.getBoundingClientRect();if(i.width>0&&i.height>0){const n=t-i.left,s=e-i.top;return void this.eventManager.updateMouseNDC(n,s,0,0,i.width,i.height)}}const i=this._host;if(i){const{left:n,top:s,width:r,height:o}=i.bounds;r>0&&o>0&&this.eventManager.updateMouseNDC(t,e,n,s,Math.abs(r),Math.abs(o))}}_eventToNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0)return{ndcX:(t.clientX-n.left)/n.width*2-1,ndcY:-(t.clientY-n.top)/n.height*2+1}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const s=n.transcoordC2S(t.offsetX,t.offsetY);return{ndcX:s.x/Math.abs(e)*2-1,ndcY:-(s.y/Math.abs(i)*2-1)}}}return{ndcX:0,ndcY:0}}_updateMouseNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0){const e=t.clientX-n.left,i=t.clientY-n.top;return void this.eventManager.updateMouseNDC(e,i,0,0,n.width,n.height)}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const s=n.transcoordC2S(t.offsetX,t.offsetY);this.eventManager.updateMouseNDC(s.x,s.y,0,0,Math.abs(e),Math.abs(i))}}}onMouseUp(t){if(this.controlsManager.isActive){const e=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),e)return t.stopPropagation(),!0;const n=this.cameraManager.activeCamera;this._updateMouseNDC(t);const i=this.eventManager.handleClick(n,this.sceneManager.scene,t),s=this._host;return s?.app?.isEditMode&&s.root&&this._applySelection(s.root,i?.component,t.shiftKey),t.stopPropagation(),!0}return!1}onMouseMove(t){if(this.controlsManager.isActive){this.gizmoManager.forwardEvent(t,"pointermove");const e=this.cameraManager.activeCamera;return this._updateMouseNDC(t),this.eventManager.handleHover(e,this.sceneManager.scene,t),t.stopPropagation(),!0}return!1}onMouseDown(t){return!(!this.controlsManager.isActive||(this.gizmoManager.forwardEvent(t,"pointerdown"),!this.gizmoManager.isDragging))&&(t.stopPropagation(),!0)}onMouseLeave(t){return!1}onWheel(t){if(this.controlsManager.isActive){const{ndcX:e,ndcY:n}=this._eventToNDC(t);if("perspective"!==this.cameraManager.activeView){const i=t.deltaY>0?.9:1.1;this.controlsManager.zoomOrthoAtCursor(i,e,n),this.renderThreeD()}else{const i=Math.pow(.999,-t.deltaY);this.controlsManager.dollyAtCursor(i,e,n),this.renderThreeD()}return t.stopPropagation(),!0}return!1}onDblClick(t){if(!this.controlsManager.isActive)return!1;const e=this._host,n=this.cameraManager.activeCamera;if(!n||!this.sceneManager.scene)return this.controlsManager.reset(),!0;if(e?.app?.isEditMode&&e.root){if(this.vertexGizmoManager.isAttached){const t=this.eventManager.mouse;if(this.vertexGizmoManager.onDblClick(t,n))return this._host?.invalidate(),!0}const t=this.eventManager.getObjectByRaycast(n,this.sceneManager.scene),e=t?.userData?.context?.component;if(e?.hasTextProperty)return Wp(e,this.rendererManager,()=>{this.renderThreeD()}),!0}return this.controlsManager.reset(),t.stopPropagation(),!0}pinResetPosition(){this.controlsManager.pinResetPosition()}onDragStart(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(t.stopPropagation(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.bookmarkManager.stopPlay(),this.controlsManager.onDragStart(t),t.stopPropagation(),!0))}onDragMove(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointermove"),t.stopPropagation(),!0):(this.controlsManager.onDragMove(t),t.stopPropagation(),!0))}onDragEnd(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointerup"),t.stopPropagation(),!0):(this.controlsManager.onDragEnd(t),t.stopPropagation(),!0))}onTouchStart(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchStart(t),t.stopPropagation(),!0)}onPan(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchMove(t),t.stopPropagation(),!0)}onTouchEnd(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchEnd(t),t.stopPropagation(),!0)}onKeyDown(t){return!t.isComposing&&229!==t.keyCode&&(!!this.controlsManager.isActive&&(!!this._handleEscapeKey(t)||(!(!this._host?.app?.isEditMode||!this._handleEditModeKey(t))||(!!this._handleCursorHintKey(t)||(!!this._handleCameraAndViewKey(t)||(!!this._handlePlaybackKey(t)||(!t.shiftKey||t.ctrlKey||t.metaKey||t.altKey||"KeyB"!==t.code||!this._host?.app?.isEditMode?(this.controlsManager.onKeyDown(t),t.ctrlKey||t.metaKey||t.stopPropagation(),!0):(this.onBookmarkEditToggle?.(),t.preventDefault(),!0))))))))}_handleEscapeKey(t){if("Escape"!==t.key&&"Escape"!==t.code)return!1;if(this.placementManager.isActive&&this._host?.root)return this._host.root.trigger("addstop"),t.stopPropagation(),!0;const e=this._host?.app,n=this._host?.root;return e&&4===e.mode?(n?.trigger("stylepastestop"),!0):e&&5===e.mode?(n?.trigger("databindpastestop"),!0):!(!e?.isEditMode||!n)&&(this.gizmoManager.detach(),n.selected=[],!0)}_handleEditModeKey(t){const e=this._host.root;if(t.metaKey||t.ctrlKey)switch(t.code){case"KeyZ":{const n=this._host?.app?.commander,i=(e?.selected||[]).filter(t=>t!==this._host).map(t=>t.state?.id).filter(Boolean);if(t.shiftKey?n?.redo():n?.undo(),e&&i.length>0){const t=i.map(t=>e.findById(t)).filter(Boolean);t.length>0&&(e.selected=t)}return t.preventDefault(),!0}case"KeyC":return e&&(this._clipboard=Bh.call(e)),t.preventDefault(),!0;case"KeyX":return e&&(this._clipboard=Gh.call(e)),t.preventDefault(),!0;case"KeyV":return e&&this._clipboard&&Vh.call(e,this._clipboard),t.preventDefault(),!0;case"KeyD":return e&&(this._clipboard=Bh.call(e),this._clipboard&&Vh.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 Wp(n[0],this.rendererManager,()=>{this.renderThreeD()}),t.preventDefault(),!0}switch(t.code){case"KeyW":return this.setGizmoMode("translate"),!0;case"KeyE":return this.setGizmoMode("rotate"),!0;case"KeyR":return this.setGizmoMode("scale"),!0;case"Delete":case"Backspace":return e&&zh.call(e),!0}return this._handleArrowKeyMove(t,e)}_handleArrowKeyMove(t,e){const n=e?.selected;if(!n||0===n.length)return!1;const i=t.shiftKey?this._host.MPP||10:1;let s;switch(t.code){case"ArrowLeft":s={x:-i,y:0};break;case"ArrowRight":s={x:i,y:0};break;case"ArrowUp":s={x:0,y:-i};break;case"ArrowDown":s={x:0,y:i}}return!!s&&(ll.around(this._host.app.commander,()=>{n.forEach(t=>{t.stuck||t.move(s,!1)})}),t.preventDefault(),t.stopPropagation(),!0)}_handleCursorHintKey(t){return!(t.repeat||!this._host?.app?.isEditMode)&&("AltLeft"===t.code||"AltRight"===t.code?(this._host?.element&&(this._host.element.style.cursor="grab"),!0):("ShiftLeft"===t.code||"ShiftRight"===t.code)&&(this._host?.element&&(this._host.element.style.cursor=this.gizmoManager.isEngaged?"grab":"crosshair"),!0))}_handleCameraAndViewKey(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return!1;switch(t.code){case"KeyQ":case"Digit0":return!!wu()&&(this._host?.toggleThreeD?.(),t.preventDefault(),!0);case"Digit1":return this.setCameraView("perspective"),t.preventDefault(),!0;case"Digit2":return this.setCameraView("top"),t.preventDefault(),!0;case"Digit3":return this.setCameraView("front"),t.preventDefault(),!0;case"Digit4":return this.setCameraView("back"),t.preventDefault(),!0;case"Digit5":return this.setCameraView("right"),t.preventDefault(),!0;case"Digit6":return this.setCameraView("left"),t.preventDefault(),!0;case"KeyH":return this.onHelpToggle?.(),t.preventDefault(),!0;case"KeyB":return this.onBookmarkNavToggle?.(),t.preventDefault(),!0;case"KeyF":return this.onSearchToggle?.(),t.preventDefault(),!0;case"KeyD":return this.onDataBindingToggle?.(),t.preventDefault(),!0;case"KeyM":return this.onMonitorToggle?.(),t.preventDefault(),!0}return!1}_handlePlaybackKey(t){return!(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)&&("KeyP"!==t.code||this._host?.app?.isEditMode?"Space"===t.code&&this._host?.app?.isEditMode?(this._isSpacePanning=!0,this._beforeSpaceMode=this._host.app.mode,this._host.app.mode=2,this._host?.element&&(this._host.element.style.cursor="grab"),t.preventDefault(),!0):"Space"!==t.code||this._host?.app?.isEditMode?"KeyO"===t.code&&!this._host?.app?.isEditMode&&(this.bookmarkManager.resetPlay(),this.bookmarkManager.toggleOrbitRotation(this.controlsManager),t.preventDefault(),!0):(this.bookmarkManager.isOrbitRotating||this.bookmarkManager.isOrbitPaused?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):(this.bookmarkManager.isPlaying||this.bookmarkManager.lastPlayProgress>=0)&&this.togglePlay(),t.preventDefault(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.restartPlay(),t.preventDefault(),!0))}_onKeyUp(t){return"AltLeft"===t.code||"AltRight"===t.code||"ShiftLeft"===t.code||"ShiftRight"===t.code?(this._host?.element&&!this._isSpacePanning&&(this._host.element.style.cursor=""),!0):!("Space"!==t.code||!this._isSpacePanning)&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0),this._host?.element&&(this._host.element.style.cursor=""),t.preventDefault(),!0)}onPinch(t){if(this.controlsManager.isActive){if("perspective"!==this.cameraManager.activeView){const e=this.cameraManager.activeCamera,n=t.scale||1;e.zoom=Math.max(.1,Math.min(20,e.zoom*n)),e.updateProjectionMatrix(),this.controlsManager.markCameraChanged(),this.renderThreeD()}else{const e=t.scale||1;Math.abs(e-1)>.01&&(this.controlsManager.dollyAtCursor(1/e,0,0),this.renderThreeD())}return t.stopPropagation(),!0}return!1}onDoubleTap(){this.controlsManager.reset()}getCameraState(){const t=this._host;if(!t)return null;const e=this.cameraManager.camera;if(!e)return null;const{width:n,height:i}=t.bounds,s=Math.floor(Math.min(n,i))||1;return{view:this.cameraManager.activeView,cameraX:e.position.x/(n||1),cameraY:e.position.z/(i||1),cameraZ:e.position.y/s}}getCameraWorldState(){const t=this.cameraManager.camera;if(!t)return null;const e=this.controlsManager.target;return{position:{x:t.position.x,y:t.position.y,z:t.position.z},target:{x:e.x,y:e.y,z:e.z}}}captureSessionState(){const t=this.cameraManager.activeView,e=this.cameraManager.camera,n=this.controlsManager.target,i={view:t};return e&&(i.perspPosition={x:e.position.x,y:e.position.y,z:e.position.z}),i.orbitTarget={x:n.x,y:n.y,z:n.z},i}captureViewportInfo(){const t=this.cameraManager.activeCamera,e=this.controlsManager.target.clone();let n=0,i=0;if(t?.fov){i=2*t.position.distanceTo(e)*Math.tan(t.fov*Math.PI/180/2),n=i*(t.aspect||1)}return{target:e,visibleWidth:n,visibleHeight:i}}restoreSessionState(t){"perspective"!==t.view&&this.setCameraView(t.view,{render:!1});const n=this.cameraManager.camera;n&&t.perspPosition&&n.position.set(t.perspPosition.x,t.perspPosition.y,t.perspPosition.z),t.orbitTarget&&this.controlsManager.restoreTarget(new e.Vector3(t.orbitTarget.x,t.orbitTarget.y,t.orbitTarget.z))}saveCameraToSlot(t){if(!this._host?.app?.isEditMode)return;const n=this.cameraManager.camera;if(!n)return;if("perspective"!==this.cameraManager.activeView)return;const i=this.controlsManager.target,s=n.position;let r=i.x,o=i.y,a=i.z;if(s.distanceTo(i)<1){const t=new e.Vector3(0,0,-1).applyQuaternion(n.quaternion);r=s.x+1*t.x,o=s.y+1*t.y,a=s.z+1*t.z}const c={position:{x:s.x,y:s.y,z:s.z},target:{x:r,y:o,z:a}};this.bookmarkManager.saveSlot(t,c),this._host?.app?.isEditMode&&this._host?.set?.("cameraBookmarks",this.bookmarkManager.exportSlots()),this.onBookmarkChanged?.()}positionCameraForViewport(t,n,i,s,r){const o=this.cameraManager.activeCamera;if(!o?.position)return;const a=(o.fov||45)*Math.PI/180,c=o.aspect||1,l=s/2/Math.tan(a/2),h=i/2/(c*Math.tan(a/2)),d=Math.max(l,h),u=r?.orbitTarget?.y??0,p=new e.Vector3(t,u,n);let f;if(r?.perspPosition&&r?.orbitTarget){const t=new e.Vector3(r.perspPosition.x,r.perspPosition.y,r.perspPosition.z),n=new e.Vector3(r.orbitTarget.x,r.orbitTarget.y,r.orbitTarget.z);f=t.sub(n).normalize()}else f=o.position.clone().normalize();o.position.copy(p.clone().add(f.multiplyScalar(d)));try{this.controlsManager.restoreTarget(p)}catch{o.lookAt(p)}this._host?.invalidate()}centerToComponent(t,n){const i=this.cameraManager.activeCamera;if(!i)return;const s=new e.Vector3,r=t._realObject;if(r?.object3d)r.object3d.getWorldPosition(s);else{const{x:e=0,y:n=0}=t.center,{width:i=0,height:r=0}=t.parent?.bounds??{};s.set(e-i/2,0,n-r/2)}const o=this.controlsManager.target,a=i.position.clone().sub(o),c=s.clone().add(a);if(!n)return i.position.copy(c),this.controlsManager.restoreTarget(s),void this._host?.invalidate();const l=i.position.clone(),h=o.clone(),d=performance.now(),u=()=>{const t=performance.now()-d,e=Math.min(t/800,1),n=e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2;i.position.lerpVectors(l,c,n);const r=h.clone().lerp(s,n);this.controlsManager.restoreTarget(r),this._host?.invalidate(),e<1&&requestAnimationFrame(u)};requestAnimationFrame(u)}animateToSlot(t){const e=this.cameraManager.camera;e&&(this.bookmarkManager.isPlaying&&this.bookmarkManager.stopPlay(),"perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.animateToSlot(t,e,this.controlsManager),this.bookmarkManager.setProgressForSlot(t))}scrubPath(t){const e=this.cameraManager.camera;if(!e)return;const n=this.bookmarkManager.evaluatePath(t);n&&(e.position.copy(n.position),this.controlsManager.restoreTarget(n.target),this._host?.invalidate())}togglePlay(t=-1){const e=this.cameraManager.camera;if(e){if("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.isPlaying)return this.bookmarkManager.stopPlay(),void(this._pathVisible&&this.showBookmarkPath());this.hideBookmarkPath(),this.bookmarkManager.startPlay(e,this.controlsManager,2e3,1200,t)}}restartPlay(){const t=this.cameraManager.camera;t&&("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.stopPlay(),this.hideBookmarkPath(),this.bookmarkManager.startPlay(t,this.controlsManager,2e3,1200,-1,!0))}startAutoPlay(t){"orbit"===t?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):"play"===t&&this.togglePlay()}showBookmarkPath(){this._pathVisible=!0,this.hideBookmarkPath();const t=this.sceneManager.scene;if(!t)return;const n=this.bookmarkManager.getPlayableSlots();if(0===n.length)return;const i=[];for(const t of n){const n=this.bookmarkManager.getSlot(t);n&&i.push(new e.Vector3(n.position.x,n.position.y,n.position.z))}if(i.length>=2){let n=0;for(let t=1;t<i.length;t++)n+=i[t].distanceTo(i[t-1]);const s=n/(i.length-1),r=i.length>=3?new e.CatmullRomCurve3(i,!0,"centripetal").getPoints(30*i.length):i,o=(new e.BufferGeometry).setFromPoints(r),a=new e.LineDashedMaterial({color:4890367,dashSize:.06*s,gapSize:.03*s,opacity:.5,transparent:!0,depthTest:!1});this._pathLine=new e.Line(o,a),this._pathLine.computeLineDistances(),this._pathLine.renderOrder=9999,t.add(this._pathLine)}let s;if(i.length>=2){let t=0;for(let e=1;e<i.length;e++)t+=i[e].distanceTo(i[e-1]);s=t/(i.length-1)*.08}else{const t=this.bookmarkManager.getSlot(n[0]);s=.08*(t?new e.Vector3(t.position.x,t.position.y,t.position.z).distanceTo(new e.Vector3(t.target.x,t.target.y,t.target.z)):10)}this._pathMarkers=new e.Group,this._pathMarkers.renderOrder=9999;const r=new e.MeshBasicMaterial({color:4890367,opacity:.6,transparent:!0,depthTest:!1}),o=new e.MeshBasicMaterial({color:4890367,opacity:.15,transparent:!0,depthTest:!1,side:e.DoubleSide});for(const t of n){const n=this.bookmarkManager.getSlot(t);if(!n)continue;const i=new e.Vector3(n.position.x,n.position.y,n.position.z),a=new e.Vector3(n.target.x,n.target.y,n.target.z),c=(new e.Vector3).subVectors(a,i).normalize(),l=new e.Group;l.position.copy(i);const h=(new e.Matrix4).lookAt(new e.Vector3(0,0,0),c,new e.Vector3(0,1,0));l.quaternion.setFromRotationMatrix(h);const d=.2*s,u=new e.BoxGeometry(1.2*d,.8*d,d),p=new e.Mesh(u,r);p.renderOrder=9999,l.add(p);const f=Math.max(.06*i.distanceTo(a),.5*d),m=.35*f,g=9*m/16,y=new e.BufferGeometry,b=[0,0,0,-m,g,-f,m,g,-f,m,-g,-f,-m,-g,-f],_=[0,1,2,0,2,3,0,3,4,0,4,1];y.setAttribute("position",new e.Float32BufferAttribute(b,3)),y.setIndex(_),y.computeVertexNormals();const v=new e.Mesh(y,o);v.position.z=.5*-d,v.renderOrder=9999,l.add(v);const x=new Float32Array([0,0,0,-m,g,-f,0,0,0,m,g,-f,0,0,0,m,-g,-f,0,0,0,-m,-g,-f,-m,g,-f,m,g,-f,m,g,-f,m,-g,-f,m,-g,-f,-m,-g,-f,-m,-g,-f,-m,g,-f]),w=new e.BufferGeometry;w.setAttribute("position",new e.BufferAttribute(x,3));const M=new e.LineSegments(w,new e.LineBasicMaterial({color:4890367,opacity:.5,transparent:!0,depthTest:!1}));M.position.z=.5*-d,M.renderOrder=9999,l.add(M),l.userData.bookmarkSlotIndex=t,this._pathMarkers.add(l)}t.add(this._pathMarkers),this._host?.invalidate()}hideBookmarkPath(t=!1){t&&(this._pathVisible=!1);const e=this.sceneManager.scene;if(this._pathLine&&(e?.remove(this._pathLine),this._pathLine.geometry.dispose(),this._pathLine.material.dispose(),this._pathLine=void 0),this._pathMarkers){e?.remove(this._pathMarkers);const t=new Set;this._pathMarkers.traverse(e=>{e.geometry&&e.geometry.dispose();const n=e.material;n&&!t.has(n)&&(n.dispose(),t.add(n))}),this._pathMarkers=void 0}this._host?.invalidate()}initBookmarks(){const t=this._host;if(!t)return;const e=t.state.cameraBookmarks;Array.isArray(e)&&this.bookmarkManager.importSlots(e),this.bookmarkManager.setCallbacks(()=>this._host?.invalidate())}onchange(t){if(t.hasOwnProperty("autoRotate")&&this.controlsManager.setAutoRotate(t.autoRotate),t.hasOwnProperty("cameraFloorConstraint")){const e=!this._host?.app?.isEditMode;this.controlsManager.setFloorConstraint(e&&!!t.cameraFloorConstraint)}if(t.hasOwnProperty("fov")||t.hasOwnProperty("near")||t.hasOwnProperty("far")){const t=this._host;if(t){const{near:e,far:n,fov:i}=t.state;this.cameraManager.updateProperties({near:e,far:n,fov:i}),this.controlsManager.markCameraChanged()}}t.hasOwnProperty("exposure")&&(this.rendererManager.setExposure(Number(t.exposure)||1),this.renderThreeD());let e=!1;if((t.hasOwnProperty("hemiIntensity")||t.hasOwnProperty("hemiSkyColor")||t.hasOwnProperty("hemiGroundColor"))&&(this.lightManager.updateHemisphere({intensity:t.hemiIntensity,skyColor:t.hemiSkyColor,groundColor:t.hemiGroundColor}),e=!0),t.hasOwnProperty("dirLightEnabled")){const n=this._host;n&&this.lightManager.setDirectionalEnabled(t.dirLightEnabled,{color:n.state.dirLightColor,intensity:n.state.dirLightIntensity}),e=!0}if((t.hasOwnProperty("dirLightColor")||t.hasOwnProperty("dirLightIntensity"))&&(this.lightManager.updateDirectional({color:t.dirLightColor,intensity:t.dirLightIntensity}),e=!0),t.hasOwnProperty("dirLightFollowCamera")){if(this.lightManager.setDirectionalFollowCamera(!1!==t.dirLightFollowCamera),!1===t.dirLightFollowCamera){const t=this._host?.state;this.lightManager.setDirectionalAngle(t?.dirLightAzimuth??30,t?.dirLightElevation??45)}e=!0}if(t.hasOwnProperty("dirLightAzimuth")||t.hasOwnProperty("dirLightElevation")){const n=this._host?.state;!1===n?.dirLightFollowCamera&&this.lightManager.setDirectionalAngle(t.dirLightAzimuth??n?.dirLightAzimuth??30,t.dirLightElevation??n?.dirLightElevation??45),e=!0}if(t.hasOwnProperty("dirShadowEnabled")||t.hasOwnProperty("dirShadowBias")){const n=this.lightManager.dirLight;n&&(t.hasOwnProperty("dirShadowEnabled")&&(n.castShadow=!1!==t.dirShadowEnabled),t.hasOwnProperty("dirShadowBias")&&(n.shadow.bias=t.dirShadowBias??-5e-4)),e=!0}e&&this.renderThreeD(),(t.hasOwnProperty("fillStyle")||t.hasOwnProperty("floor")||t.hasOwnProperty("floorMaterial3d"))&&(this.sceneManager.updateFloor(this._host),this.renderThreeD()),(t.hasOwnProperty("sky")||t.hasOwnProperty("skyColor")||t.hasOwnProperty("environment"))&&(this.sceneManager.setSky(this._host.state.sky,this._host.state.skyColor,this._host.state.environment),this.renderThreeD()),t.hasOwnProperty("placement")&&(this.sceneManager.updateFloor(this._host),this._cascadeUpdateTransform(this._host),this.renderThreeD())}_cascadeUpdateTransform(t){const e=t?._realObject;e&&e.updateTransform?.();const n=t?.components;if(n)for(const t of n)this._cascadeUpdateTransform(t)}get domElement(){return this.rendererManager.domElement}getRendererSize(){return this.rendererManager.getSize()}showWebglNoSupportText(t,e,n){t.save(),t.font=e/20+"px Arial",t.textAlign="center",t.fillText("WebGL no support",e/2-e/40,n/2),t.restore()}showDebugFPS(t){t.font="100px Arial",t.textAlign="center",t.fillStyle="black",t.globalAlpha=.5,t.fillText(String(Pp()),100,100)}get decoratorOutlines(){return this._decoratorOutlines}addOutline(t){this._decoratorOutlines.add(t),this._syncOutlinePass(),this._host?.invalidate()}removeOutline(t){this._decoratorOutlines.delete(t),this._syncOutlinePass(),this._host?.invalidate()}clearOutlines(){this._decoratorOutlines.clear(),this._syncOutlinePass(),this._host?.invalidate()}addArrow(t,n,i,s={}){this.removeArrow(t);const r=n._realObject,o=i._realObject;if(!r?.object3d||!o?.object3d)return;const a=new e.Vector3,c=new e.Vector3;r.object3d.getWorldPosition(a),o.object3d.getWorldPosition(c),a.y+=1,c.y+=1;const l=this.rendererManager.getSize(),h=Lp(a,c,s,new e.Vector2(l.width,l.height));h.name=`arrow-${t}`,h.userData._arrowStyle=s,this.sceneManager.scene?.add(h),this._arrows.set(t,h),this._host?.invalidate()}setOutlineColor(t){this.rendererManager.setOutlineColor(t)}removeArrow(t){const n=this._arrows.get(t);n&&(n.traverse(t=>{if(t instanceof w)return t.geometry.dispose(),void t.material.dispose();if(t instanceof e.Sprite){const e=t.material.map;if(e){e.dispose();const t=e.source?.data;t instanceof HTMLCanvasElement&&(t.width=0,t.height=0)}return void t.material.dispose()}(t instanceof e.Mesh||t instanceof e.Line)&&(t.geometry.dispose(),t.material instanceof e.Material&&t.material.dispose())}),n.removeFromParent(),this._arrows.delete(t),this._host?.invalidate())}clearArrows(){for(const t of this._arrows.keys())this.removeArrow(t)}updateArrow(t,e,n){const i=this._getArrowStyle(t);i&&this.addArrow(t,e,n,i)}_getArrowStyle(t){const e=this._arrows.get(t);return e?e.userData._arrowStyle??null:null}highlightBookmarkMarker(t){this._highlightedMarkerIndex!==t&&(this._highlightedMarkerIndex=t,this._syncOutlinePass(),this._host?.invalidate())}clearBookmarkMarkerHighlight(){-1!==this._highlightedMarkerIndex&&(this._highlightedMarkerIndex=-1,this._syncOutlinePass(),this._host?.invalidate())}_syncOutlinePass(){const t=[...this._selectionOutlineObjects];for(const e of this._decoratorOutlines){const n=e._realObject;n?.object3d&&!t.includes(n.object3d)&&t.push(n.object3d)}if(this._highlightedMarkerIndex>=0&&this._pathMarkers)for(const e of this._pathMarkers.children)if(e.userData.bookmarkSlotIndex===this._highlightedMarkerIndex){e.traverse(e=>{e.isMesh&&t.push(e)});break}this.rendererManager.setOutlineObjects(t)}_handleSelectionChanged(t){const e=t.filter(t=>t!==this._host&&t._realObject);if(e.length>=1){const t=e[0]._realObject;t?.object3d&&t.gizmoTransformable&&!e[0].stuck?this.gizmoManager.attached&&this.gizmoManager.attach(t.object3d):this.gizmoManager.detach()}else this.gizmoManager.detach();const n=e.filter(t=>t.mutable&&t.path);n.length>0&&this.sceneManager.scene?this.vertexGizmoManager.attachMultiple(n,this.sceneManager.scene,this._host?.app?.commander):this.vertexGizmoManager.detach(),this._updateSelectionOutline(e),this._host?.invalidate()}_updateSelectionOutline(t){this._selectionOutlineObjects=[];for(const e of t){const t=e._realObject;if(!t?.object3d)continue;const n=fu(t)&&t.pickedPart?t.partObject(t.pickedPart):void 0;this._selectionOutlineObjects.push(n??t.object3d)}this._syncOutlinePass()}}Fc.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 If='<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>',Rf='<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>',jf='<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>',Lf='<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>',Ff='<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>',Nf='<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>',Hf=[{label:"Camera",requires3dAvailable:!0,items:[{key:"1",desc:"Perspective",icon:If},{key:"2",desc:"Top",icon:Rf},{key:"3",desc:"Front",icon:jf},{key:"4",desc:"Back",icon:Lf},{key:"5",desc:"Right",icon:Ff},{key:"6",desc:"Left",icon:Nf},{key:"0 / Q",desc:"Exit 3D",requires3d:!0}]},{label:"Bookmarks",requires3d:!0,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",requires3d:!0,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,requires3d:!0},{key:"E",desc:"Rotate gizmo",editOnly:!0,requires3d:!0},{key:"R",desc:"Scale gizmo",editOnly:!0,requires3d:!0},{key:"Ctrl+Z",desc:"Undo",editOnly:!0},{key:"Ctrl+Shift+Z",desc:"Redo",editOnly:!0},{key:"Ctrl+C",desc:"Copy",editOnly:!0},{key:"Ctrl+X",desc:"Cut",editOnly:!0},{key:"Ctrl+V",desc:"Paste",editOnly:!0},{key:"Ctrl+Shift+V",desc:"Bulk paste (N copies)",editOnly:!0},{key:"Del",desc:"Delete selected",editOnly:!0},{key:"Esc",desc:"Deselect all",editOnly:!0}]},{label:"Drag modifiers",items:[{key:"Ctrl+Drag",desc:"Suppress snap",editOnly:!0},{key:"Ctrl+Shift+Drag",desc:"Box select same type",editOnly:!0}]},{label:"Misc",items:[{key:"H",desc:"This help"},{key:"F",desc:"Search"}]}];function Bf(t){const{threed:e,edit:n}=t,i=t.threedAvailable??e;return Hf.filter(t=>!(t.requires3d&&!e||t.requires3dAvailable&&!i)).map(t=>({...t,items:t.items.filter(t=>!(t.requires3d&&!e)&&(!(t.requires3dAvailable&&!i)&&(!(t.editOnly&&!n)&&(!t.viewOnly||!n))))})).filter(t=>t.items.length>0)}const Gf={x:1,y:1},Vf={x:0,y:0},Yf={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"]}},{type:"checkbox",label:"logarithmic-depth",name:"logarithmicDepth"}]};class Wf extends lp{constructor(){super(...arguments),this._outlineColor=15885602,this._outlineDecoColor="#f262227f",this._threeDActivationPending=!1,this._rebuildPreserveThreeD=!1}get volatile(){return[...super.volatile,"scale","translate"]}get nature(){return Yf}get is3dMode(){return!!this._threeCapability?.isInitialized}get _threedEnabled(){return wu()}is3dContainer(){return this.is3dMode}get hasEnvironment(){return this._threeCapability?.hasEnvironment??!1}get gizmoMode(){return this._threeCapability?.gizmoMode}setGizmoMode(t){this._threeCapability?.setGizmoMode(t)}toggleHelp(){this._toggleHelpPanel()}toggleBookmarkNavigator(){this._toggleBookmarkNav()}toggleBookmarkEditor(){this._toggleBookmarkEdit()}setCameraView(t){this.is3dMode?this._threeCapability?.setCameraView(t):this._threedEnabled&&(this._pendingCameraView=t,this.toggleThreeD(!0))}get scene3d(){return this._threeCapability?.scene3d}get renderer3d(){return this._threeCapability?.renderer3d}get activeCamera3d(){return this._threeCapability?.activeCamera}get mixer(){return this._threeCapability?.mixer}addArrow3D(t,e,n,i){this._threeCapability?.addArrow(t,e,n,i)}removeArrow3D(t){this._threeCapability?.removeArrow(t)}setOutlineColor(t){this._outlineColor=t,this._threeCapability?.setOutlineColor(t),this._outlineDecoColor="#"+t.toString(16).padStart(6,"0").slice(0,6)+"7f"}clearArrows3D(){this._threeCapability?.clearArrows()}_buildLightingConfig(){const t=this.state,e={hemisphere:{skyColor:t.hemiSkyColor||"#ffffff",groundColor:t.hemiGroundColor||"#444444",intensity:t.hemiIntensity??4}};if(!1!==t.dirLightEnabled){const n=!1!==t.dirLightFollowCamera;if(e.directional={color:t.dirLightColor||"#ffffff",intensity:t.dirLightIntensity??2,attachToCamera:n,castShadow:!1!==t.dirShadowEnabled,shadowMapSize:t.dirShadowMapSize??2048,shadowBias:t.dirShadowBias??-5e-4},!n){const n=(t.dirLightAzimuth??30)*Math.PI/180,i=(t.dirLightElevation??45)*Math.PI/180,s=1e3;e.directional.position=[s*Math.cos(i)*Math.sin(n),s*Math.sin(i),s*Math.cos(i)*Math.cos(n)]}}return e}_hide2DLayers(){this.canvas&&(this.canvas.style.display="none"),this._overlay&&(this._overlay.style.display="none"),this._auxCanvas&&(this._auxCanvas.style.display="none"),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="none");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="none")}get _hasZoomHandler(){return(this.root?.model?.handlers||[]).includes("zoom-handler")}get _needsViewportSync(){return!!this.app?.isEditMode||this._hasZoomHandler}_activateThreeD(t=!1){if(!this._threedEnabled)return void(this._threeDActivationPending=!1);ap.hideAll(this.root),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 zf,this._threeCapability.init(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),15885602!==this._outlineColor&&this._threeCapability.setOutlineColor(this._outlineColor),this._hide2DLayers(),this.root?.transitionEffect?.dispose();const e=Xr.getInstance(),n=[];this.decoratorOverlay&&(n.push(...e.getTargetsWithType(this.decoratorOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorOverlay,"border-highlighting")),this.decoratorAuxOverlay&&(n.push(...e.getTargetsWithType(this.decoratorAuxOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorAuxOverlay,"border-highlighting"));for(const t of n)this._threeCapability.addOutline(t);if(this._threeCapability.domElement&&this.element){const t=this._threeCapability.domElement;t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.pointerEvents="none",t.setAttribute("scene","model-layer-webgl");const e=this._decoratorOverlay||this.element.firstChild;this.element.insertBefore(t,e)}if(this._threeCapability.buildOverlays(),t&&this._needsViewportSync){const t=this.get("scale")||{x:1};this._2dScaleBeforeThreeD=t.x||1,this._initCameraFrom2DViewport();const e=this._threeCapability?.captureViewportInfo();e&&(this._initialVisibleHeight=e.visibleHeight)}else if(this._lastCameraState)this._threeCapability.restoreSessionState(this._lastCameraState);else{const t=this.model.initialCameraView;t&&"perspective"!==t&&this._threeCapability.setCameraView(t,{render:!1})}if(this._pendingCameraView&&(this._threeCapability.setCameraView(this._pendingCameraView,{render:!1}),delete this._pendingCameraView),this._threeCapability.initBookmarks(),!this.app?.isEditMode){const t=this.model?.cameraAutoPlay;"orbit"!==t&&"play"!==t||this._threeCapability.startAutoPlay(t)}this.app?.isEditMode&&this._createToolbar(),this._registerPopupCallbacks();const i=this.root;i?.selected?.length>0&&this._threeCapability._handleSelectionChanged(i.selected),this._resizeThreeD(!0),this.element&&"function"==typeof this.element.focus&&this.element.focus(),this._threeDActivationPending=!1}_createToolbar(){if(!this.element)return;if(!this._threedEnabled)return;this._removeToolbar();const t=!!this._threeCapability,e=document.createElement("div");e.setAttribute("scene","threed-toolbar"),e.style.cssText=["position:absolute","top:12px","left:12px","display:flex","flex-direction:column","gap:1px","padding:4px","background:rgba(30,30,30,0.92)","border:1px solid rgba(255,255,255,0.08)","border-radius:8px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 16px rgba(0,0,0,0.4),inset 0 1px 0 rgba(255,255,255,0.05)","user-select:none"].join(";");const n=["width:32px","height:32px","display:flex","align-items:center","justify-content:center","border-radius:5px","cursor:pointer","transition:all 0.12s ease","position:relative"].join(";"),i=(t,e)=>{const i=document.createElement("div");return i.innerHTML=t,i.title=e,i.style.cssText=n,this._applyButtonStyle(i,!1),i.addEventListener("mouseenter",()=>{i.dataset.active||(i.style.background="rgba(255,255,255,0.1)")}),i.addEventListener("mouseleave",()=>{this._applyButtonStyle(i,!!i.dataset.active)}),i},s=()=>{const t=document.createElement("div");return t.style.cssText="height:1px;margin:3px 4px;background:rgba(255,255,255,0.1)",t},r=i(t?'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="14" height="14" rx="1.5"/>\n <line x1="3" y1="10" x2="17" y2="10" opacity="0.4"/>\n <line x1="10" y1="3" x2="10" y2="17" opacity="0.4"/>\n </svg>':'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2l7 4v8l-7 4-7-4V6l7-4z"/>\n <path d="M10 10l7-4M10 10v8M10 10L3 6"/>\n </svg>',t?"2D Mode":"3D Mode");if(this._applyToggleStyle(r,t),r.addEventListener("mouseenter",()=>{r.style.background=t?"rgba(255,160,60,0.35)":"rgba(255,160,60,0.25)"}),r.addEventListener("mouseleave",()=>{this._applyToggleStyle(r,t)}),r.addEventListener("click",()=>{this.toggleThreeD()}),e.appendChild(r),!t)return e.addEventListener("mousedown",t=>t.stopPropagation()),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),void(this._toolbar=e);e.appendChild(s());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:If,title:"Perspective"},{view:"top",icon:Rf,title:"Top"},{view:"front",icon:jf,title:"Front"},{view:"back",icon:Lf,title:"Back"},{view:"right",icon:Ff,title:"Right"},{view:"left",icon:Nf,title:"Left"}],h=[];for(const{view:t,icon:e,title:n}of l){const s=i(e,n);s.dataset.view=t,t===c&&(this._applyButtonStyle(s,!0),s.dataset.active="1"),s.addEventListener("click",()=>{this._threeCapability?.setCameraView(t)}),h.push(s),a.appendChild(s)}a.appendChild(s());const d=i('<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2 L13 5 L12 10 L15 13 L5 13 L8 10 L7 5 Z"/>\n <line x1="10" y1="13" x2="10" y2="18"/>\n </svg>',"Pin Camera View");d.addEventListener("click",()=>{const t=this._threeCapability?.getCameraState();t&&(this.set("cameraX",t.cameraX),this.set("cameraY",t.cameraY),this.set("cameraZ",t.cameraZ),this._threeCapability?.pinResetPosition())}),a.appendChild(d),e.appendChild(a),this._cameraButtons=h,o.onGizmoAttachChanged=t=>{this.root?.trigger("gizmoattach",t)},o.onCameraViewChanged=t=>{this._updateCameraButtons(t)},o.onGizmoModeChanged=t=>{this.root?.trigger("gizmomode",t)},e.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),this._toolbar=e}_applyToggleStyle(t,e){e?(t.style.background="rgba(255,140,40,0.3)",t.style.color="#ffaa44",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.5)"):(t.style.background="rgba(255,140,40,0.15)",t.style.color="#cc8833",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.3)")}_applyButtonStyle(t,e){e?(t.style.background="rgba(74,158,255,0.25)",t.style.color="#4a9eff",t.style.boxShadow="inset 0 0 0 1.5px rgba(74,158,255,0.5)",t.dataset.active="1"):(t.style.background="transparent",t.style.color="rgba(255,255,255,0.55)",t.style.boxShadow="none",delete t.dataset.active)}_updateCameraButtons(t){this._cameraButtons?.forEach(e=>{this._applyButtonStyle(e,e.dataset.view===t)})}_registerPopupCallbacks(){const t=this._threeCapability;t&&(t.onHelpToggle=()=>this._toggleHelpPanel(),t.onSearchToggle=()=>this.onSearchToggle?.(),t.onDataBindingToggle=()=>this.onDataBindingToggle?.(),t.onMonitorToggle=()=>this.onMonitorToggle?.(),t.onBookmarkNavToggle=()=>this._toggleBookmarkNav(),t.onBookmarkEditToggle=()=>this._toggleBookmarkEdit())}_closeFloatingPopup(){this._floatingPopupCloseHandler&&(this.target?.removeEventListener("mousedown",this._floatingPopupCloseHandler,!0),this._floatingPopupCloseHandler=void 0),this._floatingPopup?.parentNode&&this._floatingPopup.parentNode.removeChild(this._floatingPopup),this._floatingPopup=void 0}_showFloatingPopup(t,e=!1){this._closeFloatingPopup(),this._floatingPopup=t,e||(this._floatingPopupCloseHandler=e=>{t.contains(e.target)||this._closeFloatingPopup()},setTimeout(()=>{this.target?.addEventListener("mousedown",this._floatingPopupCloseHandler,!0)},0)),t.addEventListener("mousedown",t=>{t.stopPropagation();const e=t.target?.tagName;"INPUT"!==e&&"TEXTAREA"!==e&&"SELECT"!==e&&t.preventDefault()}),t.addEventListener("mouseup",t=>t.stopPropagation()),this._makePopupDraggable(t),this.target.appendChild(t)}_makePopupDraggable(t){let e=0,n=0,i=0,s=0;const r=r=>{const o=r.clientX-e,a=r.clientY-n;t.style.left=i+o+"px",t.style.top=s+a+"px"},o=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",r),t.removeEventListener("pointerup",o),t.style.cursor=""};t.addEventListener("pointerdown",a=>{const c=a.target,l=c.tagName?.toLowerCase();if("button"===l||"input"===l||"select"===l||"pointer"===c.style.cursor)return;if(c.closest("[data-drag-handle]"))return;const h=t.getBoundingClientRect(),d=t.parentElement.getBoundingClientRect();i=h.left-d.left,s=h.top-d.top,t.style.left=i+"px",t.style.top=s+"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",r),t.addEventListener("pointerup",o)})}_toggleHelpPanel(){if("help"===this._floatingPopup?.dataset.popupType)return void this._closeFloatingPopup();const t=!!this.app?.isEditMode,e=document.createElement("div");e.dataset.popupType="help",e.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","max-width:min(560px, calc(100% - 40px))","max-height:calc(100% - 40px)","overflow-y:auto","padding:16px 20px","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.08)","border-radius:10px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 20px rgba(0,0,0,0.5)","user-select:none","color:rgba(255,255,255,0.85)","font:12px/1.6 -apple-system,BlinkMacSystemFont,sans-serif","z-index:200"].join(";");const n=document.createElement("div");n.textContent="×",n.style.cssText="position:absolute;top:8px;right:12px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",n.addEventListener("click",()=>this._closeFloatingPopup()),n.addEventListener("mouseenter",()=>{n.style.color="#fff"}),n.addEventListener("mouseleave",()=>{n.style.color="rgba(255,255,255,0.4)"}),e.appendChild(n);const i=document.createElement("div");i.textContent="Help",i.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:12px",e.appendChild(i);const s=document.createElement("div");s.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:0 24px",e.appendChild(s);const r=Bf({threed:this.is3dMode,threedAvailable:this._threedEnabled,edit:t}),o=r.reduce((t,e)=>t+e.items.length+1,0);let a=0,c=r.length;for(let t=0;t<r.length;t++)if(a+=r[t].items.length+1,a>=o/2){c=t+1;break}const l=[r.slice(0,c),r.slice(c)];for(const t of l){const e=document.createElement("div");let n=!0;for(const i of t){if(!n){const t=document.createElement("div");t.style.cssText="height:1px;margin:8px 0;background:rgba(255,255,255,0.08)",e.appendChild(t)}n=!1;const t=document.createElement("div");t.textContent=i.label,t.style.cssText="font-size:10px;font-weight:700;text-transform:uppercase;color:rgba(255,255,255,0.45);margin:0 0 5px;letter-spacing:0.8px",e.appendChild(t);for(const t of i.items){const n=document.createElement("div");n.style.cssText="display:flex;justify-content:space-between;align-items:center;padding:2px 0;gap:12px";const i=document.createElement("span");i.style.cssText="display:inline-flex;gap:2px;flex-shrink:0";for(const e of t.key.split("+")){const n=document.createElement("kbd");if(n.textContent=e.trim(),n.style.cssText="font-size:10px;font-family:monospace;padding:1px 5px;border-radius:3px;background:rgba(255,255,255,0.08);border:1px solid rgba(255,255,255,0.12);color:rgba(255,255,255,0.65);line-height:1.4",i.appendChild(n),e!==t.key.split("+").at(-1)){const t=document.createElement("span");t.textContent="+",t.style.cssText="color:rgba(255,255,255,0.2);font-size:10px;margin:0 1px",i.appendChild(t)}}const s=document.createElement("span");if(s.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",s.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",s.appendChild(e)}n.appendChild(i),n.appendChild(s),e.appendChild(n)}}s.appendChild(e)}this._showFloatingPopup(e)}_toggleBookmarkNav(){"bookmark-nav"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-nav"):this._closeFloatingPopup()}_toggleBookmarkEdit(){"bookmark-edit"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-edit"):this._closeFloatingPopup()}_buildBookmarkPopup(t){const e=this._threeCapability;if(!e)return;const n="bookmark-nav"===t,i=!!this.app?.isEditMode,s=document.createElement("div");s.dataset.popupType=t,s.tabIndex=-1,s.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 r=document.createElement("div");r.textContent="×",r.style.cssText="position:absolute;top:6px;right:10px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",r.addEventListener("click",()=>this._closeFloatingPopup()),r.addEventListener("mouseenter",()=>{r.style.color="#fff"}),r.addEventListener("mouseleave",()=>{r.style.color="rgba(255,255,255,0.4)"}),s.appendChild(r);const o=document.createElement("div");o.textContent="Bookmarks",o.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:8px;cursor:grab",s.appendChild(o);const a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:2px",s.appendChild(a);const c=e.bookmarkManager,l=()=>{i&&this.set?.("cameraBookmarks",c.exportSlots()),e.onBookmarkChanged?.()},h="border:none;background:transparent;color:inherit;cursor:pointer;padding:2px 4px;border-radius:4px;font-size:13px;line-height:1;display:flex;align-items:center;justify-content:center;width:24px;height:24px",d=t=>{const e=28,n=window.devicePixelRatio||1,i=document.createElement("canvas");i.width=e*n,i.height=e*n,i.style.cssText="width:28px;height:28px;flex-shrink:0;border-radius:50%;background:rgba(0,0,0,0.3)";const s=i.getContext("2d");s.scale(n,n);const r=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,m=0;d>.001&&(f=c/d,m=l/d);const g=1-.6*p,y=r+f*a*.7*g,b=o+m*a*.7*g;s.strokeStyle="rgba(255,255,255,0.12)",s.lineWidth=1,s.beginPath(),s.arc(r,o,a,0,2*Math.PI),s.stroke(),s.strokeStyle="rgba(255,255,255,0.06)",s.beginPath(),s.moveTo(r,2),s.lineTo(r,26),s.moveTo(2,o),s.lineTo(26,o),s.stroke(),s.fillStyle="rgba(255,255,255,0.25)",s.beginPath(),s.arc(r,o,1.5,0,2*Math.PI),s.fill(),s.strokeStyle=`rgba(74,158,255,${.2+.2*p})`,s.lineWidth=1,s.beginPath(),s.moveTo(y,b),s.lineTo(r,o),s.stroke();const _=.6+.4*p;s.fillStyle=`rgba(74,158,255,${_})`,s.beginPath(),s.arc(y,b,3,0,2*Math.PI),s.fill();const v=Math.atan2(m,f),x=Math.PI/8;return s.fillStyle="rgba(74,158,255,0.08)",s.beginPath(),s.moveTo(y,b),s.arc(y,b,.6*a,v+Math.PI-x,v+Math.PI+x),s.closePath(),s.fill(),i},u=()=>{const t=e.getCameraWorldState();if(!t)return-1;const n=.01;for(let e=1;e<=9;e++){const i=c.getSlot(e);if(i&&(Math.abs(t.position.x-i.position.x)<n&&Math.abs(t.position.y-i.position.y)<n&&Math.abs(t.position.z-i.position.z)<n&&Math.abs(t.target.x-i.target.x)<n&&Math.abs(t.target.y-i.target.y)<n&&Math.abs(t.target.z-i.target.z)<n))return e}return-1};let p,f,m=-1;const g=()=>{a.innerHTML="";let t=!1;const i=u(),s=Array.from({length:9},(t,e)=>e+1);for(const r of s){const s=c.getSlot(r),o=!!s,u=r===i;if(n&&!o)continue;t=t||o;const p=document.createElement("div"),f=u?"rgba(74,158,255,0.1)":"transparent";if(p.style.cssText=`display:flex;align-items:center;gap:6px;padding:${n?"6px 8px":"3px 4px"};border-radius:6px;transition:background 0.15s;background:${f}${u?";box-shadow:inset 0 0 0 1px rgba(74,158,255,0.25)":""}`,p.dataset.active=u?"1":"",p.addEventListener("mouseenter",()=>{p.style.background=p.dataset.active?"rgba(74,158,255,0.15)":"rgba(255,255,255,0.06)",!n&&o&&e.highlightBookmarkMarker(r)}),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&&s){const t=d(s);t.style.pointerEvents="none",p.appendChild(t)}const t=document.createElement("span");t.textContent=s?.name||"noname",t.style.cssText=`flex:1;color:${s?.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;${s?.name?"":"font-style:italic"}`,p.appendChild(t),p.style.cursor="pointer",p.addEventListener("click",()=>{e.animateToSlot(r)})}else{const t=document.createElement("div");t.textContent="⠿";const n=o,i=o?"color:rgba(255,255,255,0.3)":"color:rgba(255,255,255,0.12)";if(t.style.cssText=`width:16px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;user-select:none;${i}${n?";cursor:grab":""}`,n&&(t.dataset.dragHandle="1",t.addEventListener("mouseenter",()=>{t.style.color="rgba(255,255,255,0.6)"}),t.addEventListener("mouseleave",()=>{t.style.color="rgba(255,255,255,0.3)"})),p.appendChild(t),o&&s){const t=d(s);t.style.pointerEvents="none",p.appendChild(t)}o&&(p.style.cursor="pointer",p.addEventListener("click",t=>{const n=t.target.tagName;"INPUT"!==n&&"BUTTON"!==n&&e.animateToSlot(r)}));const a=document.createElement("input");a.type="text",a.value=s?.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(r,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(r),g()}),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(r),l(),g()}),u.appendChild(n);const i=document.createElement("button");i.textContent="⋮",i.title="Playlist settings",i.style.cssText=h+";color:rgba(255,255,255,0.35);font-size:14px",i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{i.style.background="transparent"}),u.appendChild(i)}else{const t=document.createElement("button");t.textContent="📌",t.title="Save current view here",t.style.cssText=h+";color:#4ade80",t.addEventListener("mouseenter",()=>{t.style.background="rgba(74,222,128,0.15)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",()=>{e.saveCameraToSlot(r),g()}),u.appendChild(t)}p.appendChild(u)}const y=document.createElement("div");if(y.dataset.slotIndex=String(r),y.dataset.filled=o?"1":"",y.appendChild(p),!n&&o){const t=p.querySelector("[data-drag-handle]");t&&t.addEventListener("pointerdown",e=>{e.preventDefault(),e.stopPropagation(),y.style.opacity="0.3",y.style.pointerEvents="none",y.style.outline="1px dashed rgba(74,158,255,0.4)",y.style.borderRadius="4px",t.style.cursor="grabbing";const n=document.createElement("div");n.style.cssText="height:2px;background:#4a9eff;border-radius:1px;margin:1px 0",t.setPointerCapture(e.pointerId);const i=t=>{const e=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&n.parentNode.removeChild(n);let i=null;for(const n of e){if(n===y)continue;const e=n.getBoundingClientRect();if(t.clientY<e.top+e.height/2){i=n;break}}if(i)a.insertBefore(n,i);else{const t=e[e.length-1];t&&t.after(n)}},s=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",i),t.removeEventListener("pointerup",s),y.style.cssText="",t.style.cursor="grab";const r=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=r.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(),g()};t.addEventListener("pointermove",i),t.addEventListener("pointerup",s)})}if(!n&&o&&s){const t=document.createElement("div");t.dataset.slotDetail="1";const e=m===r;t.style.cssText=`display:${e?"block":"none"};margin:2px 0 4px 26px;padding:6px 8px;background:rgba(255,255,255,0.03);border-radius:4px;border:1px solid rgba(255,255,255,0.06)`;const n="width:50px;font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none;text-align:right",i="font-size:10px;color:rgba(255,255,255,0.45);white-space:nowrap",o="display:flex;align-items:center;gap:6px;margin-bottom:4px",c=document.createElement("div");c.style.cssText=o;const h=document.createElement("span");h.textContent="Hold",h.style.cssText=i+";width:55px";const d=document.createElement("input");d.type="number",d.min="0",d.step="500",d.value=String(s.holdDuration??2e3),d.style.cssText=n;const u=document.createElement("span");u.textContent="ms",u.style.cssText=i,d.addEventListener("change",()=>{const t=parseInt(d.value);s.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 g=document.createElement("span");g.textContent="Transition",g.style.cssText=i+";width:55px";const b=document.createElement("input");b.type="number",b.min="0",b.step="200",b.value=String(s.transitionDuration??1200),b.style.cssText=n;const _=document.createElement("span");_.textContent="ms",_.style.cssText=i,b.addEventListener("change",()=>{const t=parseInt(b.value);s.transitionDuration=isNaN(t)?void 0:Math.max(0,t),l()}),b.addEventListener("keydown",t=>t.stopPropagation()),f.appendChild(g),f.appendChild(b),f.appendChild(_),t.appendChild(f);const v=document.createElement("div");v.style.cssText=o;const x=document.createElement("span");x.textContent="Easing",x.style.cssText=i+";width:55px";const w=document.createElement("select");w.style.cssText="font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none";for(const t of["ease-in-out","ease-in","ease-out","linear"]){const e=document.createElement("option");e.value=t,e.textContent=t,e.style.cssText="background:#2a2a2a;color:#ccc",(s.easing??"ease-in-out")===t&&(e.selected=!0),w.appendChild(e)}w.addEventListener("change",()=>{s.easing="ease-in-out"===w.value?void 0:w.value,l()}),v.appendChild(x),v.appendChild(w),t.appendChild(v);const M=document.createElement("div");M.style.cssText=o+";margin-bottom:0";const S=document.createElement("span");S.textContent="Skip in play",S.style.cssText=i+";width:55px";const k=document.createElement("input");k.type="checkbox",k.checked=!!s.excludeFromPlay,k.style.cssText="accent-color:#4a9eff;cursor:pointer",k.addEventListener("change",()=>{s.excludeFromPlay=k.checked||void 0,l()}),M.appendChild(S),M.appendChild(k),t.appendChild(M),y.appendChild(t);const A=p.querySelector("button:last-child");A&&(e&&(A.style.color="#4a9eff"),A.addEventListener("click",()=>{const e="none"!==t.style.display;a.querySelectorAll("[data-slot-detail]").forEach(e=>{if(e!==t&&"none"!==e.style.display){e.style.display="none";const t=e.parentElement?.firstElementChild?.querySelector("button:last-child");t&&(t.style.color="rgba(255,255,255,0.35)")}}),t.style.display=e?"none":"block",A.style.color=e?"rgba(255,255,255,0.35)":"#4a9eff",m=e?-1:r}))}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(g(),!n){p=document.createElement("div"),p.style.cssText="display:none;margin-top:6px;padding:4px 8px;border-top:1px solid rgba(255,255,255,0.06)";const t=document.createElement("div");t.style.cssText="display:flex;align-items:center;gap:6px";const n=document.createElement("input");n.type="range",n.min="0",n.max="1000",n.value="0",n.tabIndex=-1,n.style.cssText="flex:1;min-width:0;margin:0;height:14px;cursor:grab;accent-color:#4a9eff;outline:none";const i=document.createElement("button");i.textContent="▶",i.title="Play / Stop",i.style.cssText="border:none;background:rgba(255,255,255,0.06);color:rgba(255,255,255,0.5);cursor:pointer;font-size:12px;padding:3px 6px;border-radius:4px;line-height:1;flex-shrink:0",i.addEventListener("mouseenter",()=>{i.style.background="rgba(74,158,255,0.15)",i.style.color="#4a9eff"}),i.addEventListener("mouseleave",()=>{i.style.background="rgba(255,255,255,0.06)",i.style.color=c.isPlaying?"#4a9eff":"rgba(255,255,255,0.5)"}),i.addEventListener("click",()=>{const t=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(t),a()}),n.addEventListener("focus",()=>n.blur());let r=!1;n.addEventListener("mousedown",()=>{r=!0,n.style.cursor="grabbing",c.isPlaying&&(e.togglePlay(),a())}),n.addEventListener("input",()=>{const t=parseInt(n.value)/1e3;e.scrubPath(t)});const o=()=>{r&&(r=!1,n.style.cursor="grab")};n.addEventListener("mouseup",o),n.addEventListener("mouseleave",o),s.addEventListener("keydown",t=>{if("Space"===t.code&&"none"!==p.style.display){t.preventDefault(),t.stopPropagation();const i=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(i),a()}}),t.appendChild(n),t.appendChild(i),p.appendChild(t),s.appendChild(p);const a=()=>{const t=c.isPlaying;i.textContent=t?"⏹":"▶",i.style.color=t?"#4a9eff":"rgba(255,255,255,0.5)"};let l=-1;const h=()=>{if(this._floatingPopup===s){if(c.isPlaying){const t=c.playProgress;n.value=String(Math.round(1e3*t)),l=-1}else{"⏹"===i.textContent&&a();const t=c.lastPlayProgress;t>=0&&t!==l&&(n.value=String(Math.round(1e3*t)),l=t)}f=requestAnimationFrame(h)}};f=requestAnimationFrame(h);(()=>{const t=c.getPlayableSlots().length;p.style.display=t>=2?"block":"none"})()}if(!n){const t=document.createElement("button"),e="display:block;width:100%;margin-top:8px;padding:5px 0;border:1px solid rgba(255,255,255,0.12);border-radius:6px;background:transparent;color:rgba(255,255,255,0.45);font-size:11px;cursor:pointer;transition:all 0.15s";i&&(t.textContent="Clear All",t.style.cssText=e,t.addEventListener("mouseenter",()=>{t.style.borderColor="rgba(255,107,107,0.4)",t.style.color="#ff6b6b"}),t.addEventListener("mouseleave",()=>{t.style.borderColor="rgba(255,255,255,0.12)",t.style.color="rgba(255,255,255,0.45)"}),t.addEventListener("click",()=>{c.resetAll(),l(),g()})),s.appendChild(t)}const y=e.onBookmarkChanged;e.onBookmarkChanged=()=>{y?.(),this._floatingPopup===s&&(g(),_=-2,n||e.showBookmarkPath())},this._showFloatingPopup(s,!0),n||e.showBookmarkPath();let b,_=u();const v=()=>{if(this._floatingPopup!==s)return;const t=u();if(t!==_){_=t;a.querySelectorAll("[data-slot-index]").forEach(e=>{const n=parseInt(e.dataset.slotIndex||"-1"),i=e.firstElementChild;if(!i)return;const s=n===t,r=s?"rgba(74,158,255,0.1)":"transparent";i.style.background=r,i.style.boxShadow=s?"inset 0 0 0 1px rgba(74,158,255,0.25)":"none",i.dataset.active=s?"1":""})}b=requestAnimationFrame(v)};b=requestAnimationFrame(v);const x=this._closeFloatingPopup.bind(this);this._closeFloatingPopup=()=>{void 0!==b&&cancelAnimationFrame(b),void 0!==f&&cancelAnimationFrame(f),c.isPlaying&&e.togglePlay(),e.clearBookmarkMarkerHighlight(),e.hideBookmarkPath(!0),this._closeFloatingPopup=x,x()}}_removeToolbar(){this._closeFloatingPopup(),this._threeCapability&&(this._threeCapability.onGizmoModeChanged=void 0,this._threeCapability.onGizmoAttachChanged=void 0,this._threeCapability.onCameraViewChanged=void 0,this._threeCapability.onBookmarkChanged=void 0,this._threeCapability.onHelpToggle=void 0,this._threeCapability.onSearchToggle=void 0,this._threeCapability.onDataBindingToggle=void 0,this._threeCapability.onMonitorToggle=void 0,this._threeCapability.onBookmarkNavToggle=void 0,this._threeCapability.onBookmarkEditToggle=void 0),this._toolbar?.parentNode&&this._toolbar.parentNode.removeChild(this._toolbar),this._toolbar=void 0,this._cameraButtons=void 0}_resizeThreeD(t=!1){if(!this._threeCapability||!this.element)return;const e=this.canvas?.clientWidth??0,n=this.canvas?.clientHeight??0,i=e>0?e:this.element.clientWidth,s=n>0?n:this.element.clientHeight;i>0&&s>0&&this._threeCapability.resize(i,s,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._threeDActivationPending=!1,!this._threeCapability)return;ap.hideAll(this.root),this._removeToolbar(),this._lastCameraState=this._threeCapability.captureSessionState();const{target:t,visibleWidth:e,visibleHeight:n}=this._threeCapability.captureViewportInfo();this._threeCapability.forceCleanupDragState();const i=this._threeCapability.domElement,s=this._threeCapability.css3DRenderer?.domElement,r=[...this._threeCapability.decoratorOutlines];this._threeCapability.dispose(),this._threeCapability=void 0,s?.parentNode&&s.parentNode.removeChild(s);for(const t of this.components)if(t.isHTMLElement()&&t.element){const e=t.element,n=this.getOverlay(t);n?.appendChild(e)}i?.parentNode&&i.parentNode.removeChild(i),this.canvas&&(this.canvas.style.display=""),this._overlay&&(this._overlay.style.display=""),this._auxCanvas&&(this._auxCanvas.style.display=""),this._decoratorOverlay&&(this._decoratorOverlay.style.display=""),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="");for(const t of this.components)t.isHTMLElement()&&t.element&&t.reposition();this.app?.isEditMode&&this._createToolbar();for(const t of r)t.disposed||this.applyDecorator(t,"border-highlighting",{distance:8,lineWidth:4,color:this._outlineDecoColor});this._saved2DViewport?(this.set({scale:this._saved2DViewport.scale,translate:this._saved2DViewport.translate}),this._saved2DViewport=void 0):this._needsViewportSync&&this._init2DViewportFrom3DCamera(t,e,n),this.root.target_element?.focus()}_getViewportSize(){const t=this.target;return{w:t?.clientWidth||this.canvas?.clientWidth||this.state.width||800,h:t?.clientHeight||this.canvas?.clientHeight||this.state.height||600}}_initCameraFrom2DViewport(){if(!this._threeCapability)return;const{w:t,h:e}=this._getViewportSize(),n=this.get("translate")||{x:0,y:0},i=this.get("scale")||{x:1,y:1},s=i.x||1,r=i.y||1,{width:o=800,height:a=600}=this.state,c=(t/2-n.x)/s-o/2,l=(e/2-n.y)/r-a/2,h=t/s,d=e/r;this._threeCapability.positionCameraForViewport(c,l,h,d,this._lastCameraState)}_init2DViewportFrom3DCamera(t,e,n){const{w:i,h:s}=this._getViewportSize(),{width:r=800,height:o=600}=this.state,a=t.x+r/2,c=t.z+o/2;let l;if(this._2dScaleBeforeThreeD&&this._initialVisibleHeight&&n>0){const t=this._initialVisibleHeight/n;l=this._2dScaleBeforeThreeD*t}else if(e>0||n>0){const t=e>0?i/e:1,r=n>0?s/n:1;l=Math.max(t,r)}else l=1;l=Math.max(.1,Math.min(l,10));const h=i/2-a*l,d=s/2-c*l;this.set({translate:{x:h,y:d},scale:{x:l,y:l}}),this._2dScaleBeforeThreeD=void 0,this._initialVisibleHeight=void 0}centerTo(t,e){this.is3dMode&&this._threeCapability?this._threeCapability.centerToComponent(t,e):super.centerTo(t,e)}async ready(){await super.ready();const t=this._rebuildPreserveThreeD;this._rebuildPreserveThreeD=!1,!t&&this.model.threed&&!this._threeCapability&&this._threedEnabled?(this._threeDActivationPending=!0,await new Promise(t=>setTimeout(t,0)),this._activateThreeD()):this.app?.isEditMode&&!this.is3dMode&&this._createToolbar(),this.root?.trigger("dimension",this.is3dMode?"3d":"2d")}toggleThreeD(t){if(!this._threedEnabled)return;const e=t??!this.is3dMode;e?this._activateThreeD(!0):(this._deactivateThreeD(),this.resize(),this.invalidate()),this.root?.trigger("dimension",e?"3d":"2d")}dispose(){this._deactivateThreeD(),this._removeToolbar(),super.dispose(),this._overlay=null,this._decoratorOverlay&&(Xr.getInstance().removeOverlay(this._decoratorOverlay),this._decoratorOverlay.parentNode&&this._decoratorOverlay.parentNode.removeChild(this._decoratorOverlay),this._decoratorOverlay=null),this._decoratorAuxOverlay&&(Xr.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?Fc.get("three"):Nc}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,Xr.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,Xr.getInstance().addOverlay(t)}return this._decoratorAuxOverlay}createElement(){const t=super.createElement();return this._overlay&&t.appendChild(this._overlay),t}resize(){if(!this.target||!this.element)return;let{width:t,height:e,fitMode:n}=this.model;this.root.fitMode?n=this.root.fitMode:n||(n="ratio");let i=null;try{i=getComputedStyle(this.target)}catch(t){return void Zi(t,this.target)}let s=i?parseFloat(i.getPropertyValue("width")):this.target.clientWidth,r=i?parseFloat(i.getPropertyValue("height")):this.target.clientHeight;switch(n){case"both":case"ratio":break;case"width":r=e*s/t,this.element.style.overflowX="hidden",this.element.style.overflowY="auto";break;case"height":s=t*r/e,this.element.style.overflowX="auto",this.element.style.overflowY="hidden";break;default:s=Math.max(t,s),r=Math.max(e,r),this.element.style.overflowX=s>t?"hidden":"auto",this.element.style.overflowY=r>e?"hidden":"auto"}this.fitSize(this.element,!0),this.fitSize(this.canvas,!0,s,r),this.fitSize(this.auxCanvas,!0,s,r),this.root?.transitionEffect?.resize(),this.is3dMode&&this._threeCapability.resize(s,r)}draw(t){if(this.is3dMode){if(!this.element)return;return void this._threeCapability.renderCSS3D()}if(this._threeDActivationPending)return;const e=this.root?.transitionEffect;e?.beginDraw(),super.draw(t),e?.endDraw()}get MPP(){const{scale:t={x:1,y:1},unit:e}=this.model;switch(e){case"mm":case"cm":return 1/this.app.PPM/t.x;case"in":return 1/this.app.PPI/t.x;default:return 1/t.x}}capturePath(t,e){const n=this.layout.capturables(this);for(let i=n.length-1;i>=0;i--){const s=n[i];if(!s.isContainer())continue;const r=s.capturePath(t,e);if(r)return r}return!1}getOverlay(t){return t&&!t.scalable?this.auxOverlay:this.overlay}getDecoratorOverlay(t){return t&&!t.scalable?this.decoratorAuxOverlay:this.decoratorOverlay}_onkeydown_root(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;const e=this.rootModel;if(!e)return;if("KeyF"===t.code)return this.onSearchToggle?.(),void t.preventDefault();if("KeyH"===t.code)return this._toggleHelpPanel(),void t.preventDefault();if("KeyD"===t.code)return this.onDataBindingToggle?.(),void t.preventDefault();if("KeyM"===t.code)return this.onMonitorToggle?.(),void t.preventDefault();if("KeyQ"===t.code){if(!this._threedEnabled)return;return this.toggleThreeD(),void t.preventDefault()}if(e.is3dMode)return;if(!this._threedEnabled)return;const n={Digit1:"perspective",Digit2:"top",Digit3:"front",Digit4:"back",Digit5:"right",Digit6:"left"}[t.code];n&&(e._pendingCameraView=n,this.toggleThreeD(!0),t.preventDefault())}get eventMap(){return{"(self)":{"(all)":{change:this._onchanged_all,mouseenter:this._onmouseenter_all,mouseleave:this._onmouseleave_all,click:this._onclick,mousedown:this._onmousedownup,mouseup:this._onmousedownup,touchstart:this._onmousedownup,touchend:this._onmousedownup,"deco-reset":t=>this.resetDecorator(void 0,t.origin)},"(descendant)":{"deco-anchors":(t,e)=>this.applyDecorator(e.origin,"anchors",t),"deco-anchors-off":t=>this.offdecorator(t.origin,"anchors"),"deco-anchors-reset":t=>this.resetDecorator("anchors"),"deco-dataspread":(t,e)=>this.applyDecorator(e.origin,"data-spread",t),"deco-dataspread-off":t=>this.offdecorator(t.origin,"data-spread"),"deco-dataspread-reset":t=>this.resetDecorator("data-spread"),"deco-link":(t,e)=>this.applyDecorator(e.origin,"link",t),"deco-link-off":t=>this.offdecorator(t.origin,"link"),"deco-link-reset":t=>this.resetDecorator("link"),"deco-arrow":(t,e)=>this.applyDecorator(e.origin,"bouncing-arrow",t),"deco-arrow-off":t=>this.offdecorator(t.origin,"bouncing-arrow"),"deco-arrow-reset":t=>this.resetDecorator("bouncing-arrow"),"deco-icon":(t,e)=>this.applyDecorator(e.origin,"animated-icon",t),"deco-icon-off":t=>this.offdecorator(t.origin,"animated-icon"),"deco-icon-reset":t=>this.resetDecorator("animated-icon"),"deco-border":(t,e)=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.addOutline(e.origin):this.applyDecorator(e.origin,"border-highlighting",t))},"deco-border-off":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.removeOutline(t.origin):this.offdecorator(t.origin,"border-highlighting"))},"deco-border-reset":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.clearOutlines():this.resetDecorator("border-highlighting"))},"deco-tag":(t,e)=>this.applyDecorator(e.origin,"decotag",t),"deco-tag-off":t=>this.offdecorator(t.origin,"decotag"),"deco-tag-reset":t=>this.resetDecorator("decotag",t.origin),"deco-off":t=>{this.offdecorator(t.origin),this._threeCapability?.removeOutline(t.origin)},mouseenter:this.onmouseenterForDecorator,mouseleave:this.onmouseleaveForDecorator},"(self)":{change:this.onChangeForDecorator,redraw:this.onRedrawForDecorator}},"(root)":{"(self)":{selected:this._onRootSelected,keydown:this._onkeydown_root}}}}onRedrawForDecorator(){Xr.getInstance().invalidateOverlay(this.decoratorOverlay),Xr.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=Vf,scale:n=Gf,rotation:i=0}=this.model,{left:s,top:r}=this.bounds;t.style.left=s+"px",t.style.top=r+"px",t.style.transform=`rotate(${i}rad) scale(${n.x}, ${n.y}) perspective(1px)`,t.style.marginLeft=`${e.x}px`,t.style.marginTop=`${e.y}px`}onchange(t){const e=this._model;delete e.id,delete e.text,delete e.class,this._repositionOverlay(),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 Wf)return;const i=Array.isArray(n.state?.eventHandlers)&&n.state.eventHandlers.length>0,s=!!n.model?.event?.hover;(i||s)&&(n.hidden||this._dispatchEventHandlers(n,["mouseenter","hover"],t,!0))}_onmouseleave_all(t,e){if(t.stopPropagation(),!e)return;const n=e.origin;this.app&&!this.app.isEditMode&&this._dispatchEventHandlers(n,["mouseleave","hover"],t,!1)}_onclick(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin;this._dispatchEventHandlers(n,["click","tap"],t,!0)}_dispatchEventHandlers(t,e,n,i){if(!t)return;for(const s of e){const e=this._triggerToMethodName(s,i);if(e&&"function"==typeof t[e])try{const i=t[e](n,this.root);i&&"function"==typeof i.then&&i.catch(t=>Zi(t))}catch(t){Zi(t)}}if(!t.state)return;const s=js(t.state);if(!s.length)return;const r=s.filter(t=>!t.disabled&&e.includes(t.trigger));for(const e of r)this._executeHandler(e,t,n,i)}_triggerToMethodName(t,e){switch(t){case"click":case"tap":return"onTap";case"dblclick":return"onDoubleClick";case"mouseenter":case"hover":return e?"onMouseEnter":"onMouseLeave";case"mouseleave":return"onMouseLeave";case"longpress":return"onLongPress";case"mousedown":return"onMouseDown";case"mouseup":return"onMouseUp";case"pressed":return e?"onMouseDown":"onMouseUp"}}_executeHandler(t,e,n,i){const s=t.action;if(!s)return;if("script"===s){if(!i)return;const s=t.code;if(!s||"string"!=typeof s)return;const r=t.target?this.root.findAll(t.target,e)??[]:[];try{const i=Ss(s,["component","scene","event","targets","value"])(e,e,this.root,n,r,t.value);i&&"function"==typeof i.then&&i.catch(t=>Zi(t))}catch(t){Zi(t)}return}const r={action:s,target:t.target,value:t.value,...t.options??{}};this._doEventAction(r,e,i,n)}_onmousedownup(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,i="mousedown"==t.type||"touchstart"==t.type,s=n.model.event?.tap;if(s&&s.pressed)this._doMouseDownUpEventAction(s,n,i,t);else if(n.state){js(n.state).some(t=>!t.disabled&&("click"===t.trigger||"tap"===t.trigger||"pressed"===t.trigger)&&t.options?.pressed)&&this._doMouseDownUpEventAction({pressed:!0},n,i,t)}}_doMouseDownUpEventAction(t,e,n,i){const{pressed:s=!1}=t;s&&(n?function(t){if(t.hasOwnProperty("_backupShadow"))return;const e=t.get("shadow");t._backupShadow=e;const{left:n=0,top:i=0}=e||{};t.delta("tx",n),t.delta("ty",i),t.set("shadow",{})}(e):function(t){t.hasOwnProperty("_backupShadow")&&(t.delta("tx",0),t.delta("ty",0),t.set("shadow",t._backupShadow),delete t._backupShadow)}(e))}_doEventAction(t,e,n,i){let{action:s,target:r,value:o,emphasize:a=!1,restore:c=!1,options:l}=t;if(r&&(r=e.access(r)),o&&(o=e.access(o)),a&&(n?function(t){const{hover:e}=t.state.event||{},{emphasize:n}=e||{};if(t.hasOwnProperty("_backupStrokeStyle"))return;if("__backup_emphasize"in t)return;const{strokeStyle:i,lineWidth:s,fillStyle:r}=t.state;t.__backup_emphasize={strokeStyle:i,lineWidth:s,fillStyle:r},t.setState(n)}(e):c&&function(t){"__backup_emphasize"in t&&(t.setState(t.__backup_emphasize),delete t.__backup_emphasize)}(e)),s)switch(s){case"data-toggle":if(!r)return;(n||c)&&this.root.findAll(r,e)?.forEach(t=>{t.data=!t.data});break;case"data-tristate":if(!r)return;(n||c)&&this.root.findAll(r,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(!r)return;n&&this.root.findAll(r,e)?.forEach(t=>{t.executeMappings(!0)});break;case"data-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.data=t})}break;case"partial-data-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.data={...e.data,...t}})}break;case"value-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.value=t})}break;case"partial-value-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.value={...e.value,...t}})}break;case"script":{if(!n)return;const t="string"==typeof o?o:o&&"object"==typeof o?o.script:null;if(!t||"string"!=typeof t)return;const s=r?this.root.findAll(r,e)??[]:[];try{const n=Ss(t,["component","scene","event","targets","value"])(e,e,this.root,i,s,o);n&&"function"==typeof n.then&&n.catch(t=>Zi(t))}catch(t){Zi(t)}break}case"infoWindow":case"info-window":if(!r)return;"click"==i.type||n?jc.show(e,r,c,{x:i.offsetX,y:i.offsetY}):c&&jc.hide(e,r);break;case"toggle-info-window":if(!r)return;jc.toggle(e,r,!1,{x:i.offsetX,y:i.offsetY});break;case"popup":case"modal-popup":if(!r)return;const t=l&&"input"in l?l.input:"(self)",a=!l||(!("output"in l)||l.output),h=this.is3dMode&&"modal-popup"!==s;ap.show(e,r,{data:t&&this.root.findFirst(t,e)?.data,output:a,modal:"modal-popup"===s,closable:!0,draggable:!h,origin:"auto",anchor:h?e:void 0,tether:h});break;case"inline-popup":case"inline-modal-popup":{if(!r)return;const t=this.root.findById(r);if(!t)return;const n=t.state||{},i="inline-modal-popup"===s,o=this.is3dMode&&!i;ap.show(e,"",{containerRef:r,modal:i,closable:!0,draggable:!o,origin:"auto",anchor:o?e:void 0,constantSize:n.constantSize??!0,billboard:n.billboard??!0,tether:n.tether??o,offScreen:n.offScreen??"hide",data:e.data});break}case"close-scene":this.closeScene(e.data);break;case"goto":case"goto-playlist":this.trigger(s,r,l,e);break;case"mouse-cursor":n?this.target.style.cursor=r||"auto":c&&(this.target.style.cursor="auto");break;default:this.trigger(s,r,o,e)}}applyDecorator(t,e,n={}){const i=this.getDecoratorOverlay(t);if(i){Xr.getInstance().addToOverlay(i,t,e,n)}}offdecorator(t,e){const n=this.getDecoratorOverlay(t);if(n){Xr.getInstance().removeFromOverlay(n,t,e)}}resetDecorator(t,e){const n=this.getDecoratorOverlay(e);n&&Xr.getInstance().removeAllFromOverlay(n,t)}onChangeForDecorator(t,e,n){const{origin:i}=n,s=this.getDecoratorOverlay(i);Xr.getInstance().invalidateOverlay(s)}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 Uf(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.from?.component===n&&(!e||t.from.anchor===e))}function $f(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.to?.component===n&&(!e||t.to.anchor===e))}function Xf(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){Zi(t)}t.closePath()}}),t.restore()}contains(t,e){let n=super.contains(t,e);if(n)return n;const i=this.anchors||[];for(const s of i){const i=s.bounds;if(!i)continue;const{left:r,top:o,width:a,height:c}=i;if(n=t<Math.max(r+a,r)&&t>Math.min(r+a,r)&&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 Uf(this,t)}findOutletEnds(t){return function(t,e){return Uf(t,e).map(t=>t.toEnd?.component).filter(Boolean)}(this,t)}findInletLines(t){return $f(this,t)}findInletEnds(t){return function(t,e){return $f(t,e).map(t=>t.fromEnd?.component).filter(Boolean)}(this,t)}}}Wf.Popup=ap,Tc.register("model-layer",Wf);const qf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0}}],help:"scene/component/rect"},Kf={ondragmove:function(t,e,n){const{left:i,width:s,height:r}=n.model;let o=(n.fromParent(t.x,t.y).x-i)/(s/2)*100;o=Oc(o,s,r),n.set({round:o})}};class Qf extends(Xf(Dc(Pc))){is3dish(){return!0}get controls(){let{left:t,top:e,width:n,round:i,height:s}=this.state;return i=null==i?0:Oc(i,n,s),[{x:t+n/2*(i/100),y:e,handler:Kf}]}get nature(){return qf}}Tc.register("rect",Qf);const Zf=[1,2,10,20,50,50,50,50,50,50];class Jf extends(Dc(Pc)){render(t){const{lineWidth:e=1,fillStyle:n="lightgray",font:i="15px Arial",left:s,top:r,origin:o,width:a,height:c,side:l="bottom",strokeStyle:h="#000000",scale:d=1}=this.state;t.translate(s,r),t.beginPath();const u=Math.round(e/2);t.rect(-u,-u,a+2*u,c+2*u),t.clip(),t.beginPath(),t.rect(0,0,a,c),n&&(t.fillStyle=n,t.fill()),t.lineWidth=e,t.strokeStyle=h,t.stroke(),t.beginPath(),t.font=i;const p="bottom"!==l,f=p?0:c;let m=4*c/5,g=2*c/3,y=1*c/2,b=3*c/5;p&&(m=c-m,g=c-g,y=c-y,b=c-1.5*c/5);const _=d*this.app.PPM/this.root.unitScale;let v=Math.ceil(o/_);const x=this.app.PPM/_,w=x<=1.1?1:Zf[Math.round(x)]||100;1!=w&&(v+=(w-v%w)%w);let M=Math.ceil(v*_);const S=o+a;for(t.fillStyle=h;M<S;){if(v%10==0){t.moveTo(M-o,y),t.lineTo(M-o,f);const e=(v/10).toString(),n=t.measureText(e);t.fillText(e,M-o-n.width-6,b)}else v%5==0?(t.moveTo(M-o,g),t.lineTo(M-o,f)):(t.moveTo(M-o,m),t.lineTo(M-o,f));v+=w,M=Math.ceil(v*_)}}}Tc.register("ruler",Jf);const tm=20,em=20,nm=90*Math.PI/180,im="9px Verdana",sm=20,rm="#f4f4f4",om="#999";function am(t,e,n){return{left:-t.x,top:-t.y,width:tm,height:sm}}function cm(t,e,n,i){return{left:tm-t.x,top:0-t.y,origin:20-t.x,width:e-tm,height:sm}}function lm(t,e,n,i){const s={x:0-t.x+10,y:-t.y+em+(n-em)/2},r=Tc.transcoordRR(0-t.x,-t.y+em,s,nm);return{left:r.x-(n-em),top:r.y,origin:20-t.y,width:n-em,height:sm}}function hm(t){const e=t.get("translate");return{left:-e.x,top:-e.y,width:t.canvas.width/Xs,height:t.canvas.height/Xs}}Tc.register("guide-layer",class extends cp{constructor(t,e){super(t,e),this.appScale={x:1,y:1},"disabled"!==t.ruler&&(this.hruler=new Jf({left:tm,top:0,origin:20,margin:0,height:sm,unit:"m",rotation:0,font:im,fillStyle:rm,strokeStyle:om,capturable:!1}),this.vruler=new Jf({left:0,top:0,origin:20,margin:0,height:sm,unit:"m",rotation:nm,font:im,side:"top",fillStyle:rm,strokeStyle:om,capturable:!1}),this.origin_rect=new Qf({left:-20,top:-20,width:20,height:20,fillStyle:rm,strokeStyle:om,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=hm(this));const t=this.rootModel,e=Object.assign({},t.get("translate"));e.x<tm&&(e.x+=tm),e.y<em&&(e.y+=em);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=hm(this);const{width:i,height:s}=this.screen_coord;this.hruler.set(cm(e,i)),this.vruler.set(lm(e,0,s)),this.origin_rect.set(am(e))}resize(){super.resize(),this.screen_coord=hm(this);const{width:t,height:e}=this.screen_coord;this.hruler&&(this.hruler.set(cm(this.model.translate,t)),this.vruler.set(lm(this.model.translate,0,e)),this.origin_rect.set(am(this.model.translate)))}render(t){if(this.rootModel?.is3dMode)return;if(!this.guide)return;t.save();const{x:e,y:n}=this.guide,{top:i,left:s,width:r,height:o}=this.screen_coord;t.beginPath(),t.moveTo(e,i),t.lineTo(e,i+o),t.moveTo(s,n),t.lineTo(s+r,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=hm(this),this.hruler){const{translate:t}=this.model,{width:e,height:n}=this.screen_coord;this.hruler.set(cm(t,e)),this.vruler.set(lm(t,0,n)),this.origin_rect.set(am(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 cp{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 dm(t,e,n,i,s){const r=t.selected;let o=i?r.slice(0):[];e.isContainer()||(e=e.parent);const a=e.layout.capturables(e),c=!!e.layout.joinType;if(i&&n.selected.forEach(t=>{o.splice(o.indexOf(t),1)}),n.selected=[],a.forEach(t=>{!t.capturable||!function(t,e,n){const{sx:i,sy:s,ex:r,ey:o}=e;let a,c,l,h;if(i>r?(a=r,c=i):(a=i,c=r),s>o?(l=o,h=s):(l=s,h=o),n){const e=t.bounds,n=t.transcoordS2TR(e.left,e.top),i=t.transcoordS2TR(e.left+e.width,e.top+e.height),s=n.x,r=i.x,o=n.y,d=i.y,u=Math.min(a,s,c,r),p=Math.max(a,s,c,r),f=Math.min(l,o,h,d),m=Math.max(l,o,h,d);return!(p-u>Math.abs(c-a)+Math.abs(r-s)||m-f>Math.abs(h-l)+Math.abs(d-o))}{const e=t.path;if(!e)return Zi("컴포넌트에 get path가 잘못 구현되어있음.",t),!1;for(let n=0;n<e.length;n++){const i=t.transcoordS2TR(e[n].x,e[n].y);if(a>i.x||c<i.x||l>i.y||h<i.y)return!1}return!0}}(t,n,c)||-1!=o.indexOf(t)||s&&t.state.type!==s||n.selected.push(t)}),o=o.concat(n.selected),r.length!==o.length)t.selected=o;else for(let e=0;e<o.length;e++)if(r[e]!=o[e]){t.selected=o;break}}function um(t,e,n,i,s,r){s||dm(t,e,n,i,r)}function pm(t,e){const n=t.components||[];for(const t of n){pm(t,e);const n=e.indexOf(t);-1!=n&&e.splice(n,1)}}Tc.register("add-layer",class extends cp{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}get pointerEvents(){return"none"}render(t){const e=this.addbox;if(e){const{sx:n,sy:i,ex:s,ey:r}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,s-n,r-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle=this.boxStrokeStyle||"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.bulkMode=!!e?.bulkMode,this.template=e?.template,this.boxStrokeStyle=e?.boxStrokeStyle||"",this.dragStarted=!1,delete this.addbox,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,delete this.bulkMode,delete this.template,delete this.boxStrokeStyle,delete this.dragStarted,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},this.dragStarted=!0}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;if(!this.dragStarted||!this.addbox)return void this.root.trigger("addstop");const{sx:n,sy:i,ex:s,ey:r}=this.addbox;if("number"!=typeof s||"number"!=typeof r||Math.abs(s-n)<4||Math.abs(r-i)<4)return void this.root.trigger("addstop");const o={left:Math.min(n,s),top:Math.min(i,r),width:Math.abs(s-n),height:Math.abs(r-i)};this.bulkMode?this.root.trigger("bulkareaselected",{area:o,template:this.template}):Oh.call(this.root,this.models,o),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;if(this.bulkMode)return void this.root.trigger("addstop");const{x:n,y:i}=this.toLocal(t.offsetX,t.offsetY);Oh.call(this.root,this.models,{cx:n,cy:i}),this.root.trigger("addstop")}});Tc.register("selection-layer",class extends cp{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n);const i=this.root?.target_element;i?.addEventListener("contextmenu",t=>{t.shiftKey&&t.preventDefault()})}contains(t,e){return!1}render(t){const e=this.selbox;if(e){const{sx:n,sy:i,ex:s,ey:r}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,s-n,r-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle="black",t.stroke()}}get eventMap(){return{"(root)":{"(self)":{keydown:this.onkeydown}},"model-layer":{"(self)":{change:this.onchange_root_model},"(all)":{dragstart:this.ondragstart_selbox,dragmove:this.ondragmove_selbox,dragend:this.ondragend_selbox,mousedown:this.onmousedown_comp,mouseup:this.onmouseup_comp}}}}onkeydown(t,e){const{deliverer:n}=e,i=n.selected;if(1!==i.length)return!1;let s=i[0];const r=s.parent;if(!r||r===n)return!1;if("Tab"===t.code){const e=r.layout.capturables(r);let n=e.indexOf(s);if(-1==n){if(!r.indexOf(s))return Ji("Container not contains [",s,"] as a component"),!1;n=0}const i=e.length;t.shiftKey?n--:n++,s=e[(n+i)%i]}else{if(!r.layout.keyNavigate)return!1;s=r.layout.keyNavigate(r,s,t)||s}n.selected=[s],t.preventDefault()}onchange_root_model(t,e,n){t.translate&&this.set("translate",t.translate),t.scale&&this.set("scale",t.scale)}_pendingDecision(t){this.downpoint={x:t.offsetX,y:t.offsetY}}_selectGroupItem(t,e){const n=this.selected.indexOf(t);let i=t.parent;for(;i.parent.isGroup();)i=i.parent;let s=[],r=!1,o=!1;if(this.selected.forEach(t=>{let e=t.parent;if(t!==i){for(;e.parent&&e.parent.isGroup();)e=e.parent;e===i&&(s.push(t),r=!0)}else o=!0}),r)if(e.shiftKey){if(-1!=n)return void this._pendingDecision(e);s.push(t)}else{if(-1!=n)return void this._pendingDecision(e);s=[t]}else{if(o)return void this._pendingDecision(e);if(e.shiftKey)if(this.selected.length>0){if(-1!=this.selected.indexOf(i))return;s=[...this.selected,i]}else s=[i];else s=[i]}this.selected=s}onmousedown_comp(t,e){const{origin:n}=e;if(this.downpoint=null,t.shiftKey){if(n.stuck)return;if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(-1==this.selected.indexOf(n)){if((t.ctrlKey||t.metaKey)&&this.selected.length>0){const t=this.selected[0].state.type;if(n.state.type!==t)return}this.selected=[...this.selected,n]}else this._pendingDecision(t)}else{if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(n.stuck)this.selected.length>0&&(this.selected=[]);else{if(-1!=this.selected.indexOf(n))return;this.selected=[n],this.sameParent=!0}}}onmouseup_comp(t,e){if(!this.downpoint)return;if(this.downpoint.x!==t.offsetX||this.downpoint.y!==t.offsetY)return;const{origin:n}=e;if(t.shiftKey){let t=this.selected.indexOf(n);if(-1==t&&n.parent.isGroup()&&(t=this.selected.indexOf(n.parent)),-1!==t){const e=this.selected.slice();e.splice(t,1),this.selected=e}else{const t=this.selected.filter(t=>!t.isRootModel()&&!!t.parent),e=t.length>0&&t[0].parent;e&&e!==n.parent&&(!function(t,e){let n=t.parent;for(;n;){const t=e.indexOf(n);-1!=t&&e.splice(t,1),n=n.parent}}(n,t),pm(n,t)),t.push(n),this.selected=t}}else if(n.parent.isGroup())return void(this.selected=[n])}_isSelboxOrigin(t){return t.stuck||t.showMoveHandle}ondragstart_selbox(t,e){const{origin:n}=e;if(!this._isSelboxOrigin(n))return;const{x:i,y:s}=this.toLocal(t.offsetX,t.offsetY);this.selbox={sx:i,sy:s,selected:[]},this.app&&(this.app.isSelecting=!0)}ondragmove_selbox(t,e){const{origin:n}=e;if(!this._isSelboxOrigin(n))return;const{x:i,y:s}=this.toLocal(t.offsetX,t.offsetY);if(this.selbox){this.selbox.ex=i,this.selbox.ey=s;const e=t.shiftKey&&(t.ctrlKey||t.metaKey)&&this.selected.length>0?this.selected[0].state.type:null;um(this,n,this.selbox,t.shiftKey,!1,e),this.invalidate()}}ondragend_selbox(t,e){const{origin:n}=e;this._isSelboxOrigin(n)&&(this.last_pos=null,this.selbox=null,this.app&&(this.app.isSelecting=!1),um(this,null,null,!1,!0),this.invalidate())}});class fm{constructor(t){this.layer=t}draw(t,e,n){const{left:i,top:s,width:r,height:o}=e.bounds;0!=r&&0!=o&&(t.beginPath(),t.rect(i,s,r,o),t.clip(),t.beginPath(),t.strokeStyle="#f26522",t.lineWidth=4,t.shadowBlur=10,t.shadowColor="black",t.shadowOffsetX=0,t.shadowOffsetY=0,t.rect(i,s,r,o),t.stroke(),t.closePath())}}class mm{constructor(t){this.layer=t}draw(t,e,n){const i=e.bounds;t.beginPath(),t.rect(i.left-4/n.x,i.top-4/n.y,i.width+8/n.x,i.height+8/n.y),t.setLineDash([3/n.x,4/n.y]),t.lineWidth=1/n.x,t.strokeStyle="black",t.stroke(),t.setLineDash([]),t.closePath()}}class gm{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){const s=n.controls;return!!s&&(s.every((s,r)=>(Math.abs(t-s.x)<=4/i.x&&Math.abs(e-s.y)<=4/i.y&&(this.active={component:n,index:r,handler:s.handler}),!this.active)),!!this.active)}draw(t,e,n){const i=e.controls;i&&i.forEach((e,i)=>{t.beginPath(),t.lineWidth=1/n.x,t.ellipse(e.x,e.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.fillStyle="#ff5d72",t.fill(),t.strokeStyle="#fff",t.stroke()})}onevent(t,e){const{handler:n,component:i,index:s}=this.active;let r=i.toLocal(e.offsetX,e.offsetY);r=i.toParent(r.x,r.y),n&&"function"==typeof n[t]&&n[t](r,s,i)}onmousedown(t){this.onevent("onmousedown",t)}ondragstart(t){const e=this.active;e.changes=ll.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;ll.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function ym(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}const bm=15*Math.PI/180;class _m{constructor(t){this.layer=t}reset(){this.active=null,this.created=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.mutable)return!1;if(n.path.every((s,r)=>(Math.abs(t-s.x)<=4/i.x&&Math.abs(e-s.y)<=4/i.y&&(this.active={component:n,index:r,kind:"vertex"}),!this.active)),this.active)return!0;const s=!n.isLine();if(n.cornerEditable){const r=n.path,o=n.state?.round??0,a=s?0:1,c=s?r.length:r.length-1;for(let s=a;s<c;s++){const a=r[(s-1+r.length)%r.length],c=r[s],l=eo(a,c,r[(s+1)%r.length],to(c,o),24);if(l&&(Math.abs(t-l.x)<=6/i.x&&Math.abs(e-l.y)<=6/i.y)){this.active={component:n,index:s,kind:"corner"};break}}}if(this.active)return!0;if(n.cornerEditable){const r=n.path,o=s?r.length:r.length-1;for(let s=0;s<o;s++){const o=r[s],a=Zr(o,r[(s+1)%r.length],o.bulge??0,24);if(a&&(Math.abs(t-a.x)<=7/i.x&&Math.abs(e-a.y)<=7/i.y)){this.active={component:n,index:s,kind:"bulge"};break}}}return!!this.active}startLinkProcess(t,e,n){try{const i=zl(e,t.app,void 0);return t.rootModel.addComponent(i),this.layer.selected=[i],this.active={component:i,index:1},this.ondragstart(n),i}catch(t){Ji(t)}}draw(t,e,n){if(!e.mutable||e.stuck)return;const i=e.path,s=this.active;i.forEach((i,r)=>{t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.fillStyle="#fff",s&&s.component===e&&s.index===r&&"corner"!==s.kind&&(t.strokeStyle="#fa7703",s.toFill&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke()});const r=!e.isLine();if(e.cornerEditable){const o=e.state?.round??0,a=r?0:1,c=r?i.length:i.length-1;for(let r=a;r<c;r++){const a=i[(r-1+i.length)%i.length],c=i[r],l=eo(a,c,i[(r+1)%i.length],to(c,o),24);l&&(t.beginPath(),t.ellipse(l.x,l.y,6/n.x,6/n.y,0,0,2*Math.PI,!0),t.lineWidth=2/n.x,t.strokeStyle="#1a73e8",t.fillStyle="#dbe8fb",s&&s.component===e&&s.index===r&&"corner"===s.kind&&(t.fillStyle="#a4c8ff"),t.fill(),t.stroke())}}if(e.cornerEditable){const o=7/n.x,a=r?i.length:i.length-1;for(let r=0;r<a;r++){const a=i[r],c=Zr(a,i[(r+1)%i.length],a.bulge??0,24);if(!c)continue;t.beginPath(),t.moveTo(c.x,c.y-o),t.lineTo(c.x+o,c.y),t.lineTo(c.x,c.y+o),t.lineTo(c.x-o,c.y),t.closePath(),t.lineWidth=2/n.x,t.strokeStyle="#7b3ff2";const l=Math.abs(a.bulge??0)>=1e-6;t.fillStyle=l?"#d1c0ff":"#ece4ff",s&&s.component===e&&s.index===r&&"bulge"===s.kind&&(t.fillStyle="#b594ff"),t.fill(),t.stroke()}}}ondblclick(t){const{component:e,index:n,kind:i}=this.active;if("corner"===i)return void e.mutatePath(null,function(t){const e=t[n]||{},{radius:i,...s}=e;t[n]=s});if("bulge"===i)return void e.mutatePath(null,function(t){const e=t[n]||{},{bulge:i,...s}=e;t[n]=s});if(!e.pathExtendable)return;const s=e.path.slice();s.length<3||(s.splice(n,1),e.path=s)}onmousedown(t){this.active.toFill=!0}ondragstart(t){const{index:e,component:n,kind:i}=this.active;this.created||(this.active.changes=ll.before([n])),("vertex"!==i||0!==e&&e!==n.path.length-1)&&(void 0!==i||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,kind:i}=this.active||{},{offsetX:s,offsetY:r}=t;let o=e.toLocal(s,r);if(o=e.toParent(o.x,o.y),"corner"===i){const t=e.path,i=t[n],s=no(t[(n-1+t.length)%t.length],i,t[(n+1)%t.length],o);return void e.mutatePath(null,function(t){const e=t[n]||{};t[n]={...e,radius:s}})}if("bulge"===i){const t=e.path,i=Jr(t[n],t[(n+1)%t.length],o);return void e.mutatePath(null,function(t){const e=t[n]||{};if(0===i){const{bulge:i,...s}=e;t[n]=s}else t[n]={...e,bulge:i}})}if(t.shiftKey){const t=e.path.length;let i=e.isLine()&&0==n?e.path[1]:e.path[(n-1+t)%t];i=e.toParent(i.x,i.y);let s=0;if(t>2){let r;e.isLine()?0==n?r=e.path[2]:1!=n&&(r=e.path[n-2]):r=e.path[(n-2+t)%t],r&&(r=e.toParent(r.x,r.y),s=ym(r,i))}const r=Math.round((ym(i,o)-s)/bm)*bm+s;o=function(t,e,n){return{x:Math.cos(e)*n+t.x,y:Math.sin(e)*n+t.y}}(i,r,(a=i,c=o,Math.sqrt((c.x-a.x)*(c.x-a.x)+(c.y-a.y)*(c.y-a.y))))}var a,c;if(0===n||n===e.path.length-1){const t=this.layer.anchorTarget=e.rootModel.capture(s,r,t=>!t.isConnectable());if(t){const{x:i,y:a}=t.toLocal(s,r),c=this.layer.get("scale")||{x:1,y:1},l=this.layer.counterEnd,h=(t.anchors||[]).find(n=>{const{name:s,inout:r,multiplicity:o=1/0,position:h,filter:d}=n;if(l){const{anchor:t,fromto:e}=l;if(t&&("out"===t.inout&&"out"===r||"in"===t.inout&&"in"===r))return!1;if("from"===e&&"out"===r||"to"===e&&"in"===r)return!1}else Zi("should not be here.");if(Math.abs(i-h.x)>8/c.x||Math.abs(a-h.y)>8/c.y)return!1;const u=t.findInOutLines(s);return!!u.includes(e)||!(o!==1/0&&u.length>=o)&&(!l||!d||!!d.call(n,l))});h?0==n?e.from={component:t.get("refid"),anchor:h.name,position:o}:e.to={component:t.get("refid"),anchor:h.name,position:o}:0==n?e.from={position:o}:e.to={position:o}}else 0==n?e.from={position:o}:e.to={position:o}}e.mutatePath(null,function(t){const e=t[n];t[n]={...e||{},x:o.x,y:o.y}})}ondragend(t){const{component:e,index:n,changes:i,kind:s}=this.active;if("corner"!==s&&"bulge"!==s&&(0===n||n===e.path.length-1)){const{offsetX:i,offsetY:s}=t,r=e.rootModel.capture(i,s,t=>t===e||t.isLine()),{x:o,y:a}=r.toLocal(i,s),c=this.layer.get("scale")||{x:1,y:1},l=(r.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:r.get("refid"),anchor:l.name}:e.to={component:r.get("refid"),anchor:l.name}),this.layer.endLinkProcess()}if(this.created){const t=new Ol({changes:[{component:this.created,to_container:this.created.parent}]});this.created.app.commander.execute(t)}else ll.after(i,e.app.commander);e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function vm(t,e,n){return t.filter(t=>{const{name:i,inout:s,multiplicity:r=1/0,filter:o}=t;if(n){const{anchor:t,fromto:e}=n;if(t&&("out"===t.inout&&"out"===s||"in"===t.inout&&"in"===s))return!1;if("from"===e&&"out"===s||"to"===e&&"in"===s)return!1}else if("in"===s)return!1;return!(r!==1/0&&e.findInOutLines(i).length>=r)&&(!o||!n||!!o.call(t,n))})}class xm{constructor(t){this.layer=t}get active(){return this._active?.component.disposed&&(this._active=null),this._active}set active(t){this._active=t}reset(){this.active=null}contains(t,e,n,i){const s=this.active?.component===n&&this.active?.anchor;this.active=null;const r=this.layer.counterEnd;return vm(n.isConnectable()&&!n.disposed&&this.getAnchorHandles(n,i)||[],n,r).every(r=>{const o=s===r.name?2:1;return r&&r.position&&Math.abs(t-r.position.x)<=4*o/i.x&&Math.abs(e-r.position.y)<=4*o/i.y&&(this.active={component:n,anchor:r.name,template:r.template}),!this.active}),!!this.active}getAnchorHandles(t,e){const{width:n,height:i}=t.bounds;return n*e.x<30||i*e.y<30?[]:t.anchors}draw(t,e,n){if(!e.get("refid")||e.isLine())return;const i=this.active,s=this.active?.component===e&&this.active?.anchor,r=this.layer.counterEnd;vm(e.isConnectable()&&!e.disposed&&this.getAnchorHandles(e,n)||[],e,r).forEach(r=>{const{name:o,position:a}=r,c=s===o?2:1;a&&(t.beginPath(),t.ellipse(a.x,a.y,4*c/n.x,4*c/n.y,0,0,2*Math.PI),t.setLineDash([0,0]),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",i&&i.component===e&&i.anchor===o&&(t.strokeStyle="#fa7703",i.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e,anchor:n,template:i}=this.active,s=this.layer.toLocal(t.offsetX,t.offsetY);this.layer.startLinkProcess(e,{type:"ortholine",lineWidth:1,strokeStyle:"black",begin:"oval",beginSize:"size9",end:"arrow",endSize:"size9",lineDash:"solid",lineCap:"butt",round:10,...i,from:{component:e.get("refid"),anchor:n,position:s},to:{position:s}},t)}ondragmove(t){}ondragend(t){}}function wm(t,e){const{left:n,top:i,width:s,height:r}=t,o=n+s/2,a=i+r/2,c=n+s,l=i+r,h=s*e.x>50,d=r*e.y>50;return[{x:n,y:i},h?{x:o,y:i}:{x:null,y:null},{x:c,y:i},d?{x:c,y:a}:{x:null,y:null},{x:c,y:l},h?{x:o,y:l}:{x:null,y:null},{x:n,y:l},d?{x:n,y:a}:{x:null,y:null}]}class Mm{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.resizable)return!1;const s=wm(n.bounds,i);for(let r=0;r<s.length;r++){const o=s[r];if(null!=o.x&&null!=o.y&&Math.abs(t-o.x)<=4/i.x&&Math.abs(e-o.y)<=4/i.y)return this.active={component:n,index:r},!0}return!1}draw(t,e,n){if(e.isLine())return;const{left:i,top:s,width:r,height:o}=e.bounds;if(t.beginPath(),t.rect(i-4/n.x,s-4/n.y,r+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;wm(e.bounds,n).forEach((i,s)=>{null!=i.x&&null!=i.y&&(t.beginPath(),t.rect(i.x-4/n.x,i.y-4/n.y,8/n.x,8/n.y),t.setLineDash([]),t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",a&&a.component===e&&a.index===s&&(t.strokeStyle="#fa7703",a.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e}=this.active;this.active.bounds=e.bounds,this.active.boundsList=this.layer.selected.filter(t=>t.resizable).map(t=>t.bounds)}_resizeAll(t,e){const{component:n,index:i,boundsList:s,bounds:r}=this.active,o=n.scalable?this.layer.toLocal(t.offsetX,t.offsetY):{x:t.offsetX,y:t.offsetY};n.bounds=r;const a=function(t,e,n){const{left:i,top:s,width:r,height:o}=t.bounds;let a,c;switch(e){case 0:a=i,c=s;break;case 1:a=i+r/2,c=s;break;case 2:a=i+r,c=s;break;case 3:a=i+r,c=s+o/2;break;case 4:a=i+r,c=s+o;break;case 5:a=i+r/2,c=s+o;break;case 6:a=i,c=s+o;break;case 7:a=i,c=s+o/2}const l=a,h=c,d=t.fromScene(n.x,n.y);return{dx:d.x-l,dy:d.y-h}}(n,i,o);this.layer.selected.filter(t=>t.resizable).forEach((n,r)=>{n.bounds=s[r],function(t,e,n,i,s,r){let{left:o,top:a,width:c,height:l}=t.bounds;const h={left:o,top:a,width:c,height:l};switch(e){case 0:o+=i,a+=s,c-=i,l-=s;break;case 1:a+=s,l-=s;break;case 2:a+=s,c+=i,l-=s;break;case 3:c+=i;break;case 4:c+=i,l+=s;break;case 5:l+=s;break;case 6:o+=i,c-=i,l+=s;break;case 7:o+=i,c-=i}if(t.mutateBounds(function(e){return Math.abs(c)<=.001&&(c=.001),Math.abs(l)<=.001&&(l=.001),t.adjustResize({left:o,top:a,width:c,height:l},h,n)},this),t.isContainer()&&t.layout.ABSOLUTE&&!t.isGroup()){const e=h.left-o,n=h.top-a;return void(r?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=r&&t.parent;d&&d.isGroup()&&d.calculateBounds()}(n,i,t.shiftKey,a.dx,a.dy,e)})}ondragmove(t){this._resizeAll(t,!1)}ondragend(t){this._resizeAll(t,!0),this.active.component.app.commander.execute(null,!1)}}const Sm=2*Math.PI,km=Math.PI/2;function Am(t,e){const n=t.bounds;return{x:n.left+n.width/2,y:n.top-20/e.y}}class Em{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.rotatable)return!1;const s=Am(n,i);return Math.abs(t-s.x)<=4/i.x&&Math.abs(e-s.y)<=4/i.y&&(this.active={component:n},!0)}draw(t,e,n){if(!e.rotatable)return;t.beginPath();const i=Am(e,n);t.lineWidth=1.5/n.x,t.moveTo(i.x,i.y+20/n.y),t.lineTo(i.x,i.y),t.strokeStyle="#656565",t.stroke(),t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,Sm,!0),t.stroke(),t.fillStyle="#fff",t.fill();const s=this.active;s&&s.component===e&&(t.strokeStyle="#fa7703",t.stroke(),s.toFill&&(t.fillStyle="#ffb80c",t.fill()))}onmousedown(t){this.active.toFill=!0}ondragstart(t){const e=this.active;e.start_rotation=e.component.get("rotation"),e.rotations=this.layer.selected.filter(t=>t.rotatable).map(t=>t.get("rotation"))}ondragmove(t){const{component:e}=this.active;let n;e.scalable?(n=e.toLocal(t.offsetX,t.offsetY),n=e.toParent(n.x,n.y)):(n={x:t.offsetX,y:t.offsetY},e.parent?.isRootModel()||(n=e.toParent(n.x,n.y)));const i=e.rotatePoint,s=e.get("rotation")||0;let r=Math.atan((i.y-n.y)/(i.x-n.x));r=i.x>=n.x?r-km:km+r;const o=r-s;this.layer.selected.filter(t=>t.rotatable).forEach((e,n)=>{const i=((e.get("rotation")||0)+o)%Sm;e.set("rotation",e.adjustRotation(i,t.shiftKey))})}ondragend(t){const{component:e}=this.active;e.app.commander.execute(null,!1)}}let Cm=null;class Tm{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}_rect(t,e){const{left:n,top:i,width:s}=t.bounds;return{x:n+s,y:i,w:25/e.x,h:25/e.y}}contains(t,e,n,i){if(!n.showMoveHandle)return!1;const{x:s,y:r,w:o,h:a}=this._rect(n,i);return t>=s&&t<=s+o&&e>=r&&e<=r+a&&(this.active={component:n},!0)}draw(t,e,n){if(!e.showMoveHandle)return;const{x:i,y:s,w:r,h:o}=this._rect(e,n);t.save(),t.beginPath(),t.globalAlpha=1,t.rect(i,s,r,o),t.fillStyle="rgba(238, 238, 238, 0.95)",t.fill();const a=(Cm||(Cm=new Image,Cm.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAclBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0BbqFAAAAJXRSTlMAgAP3VSI6/g9fBk5FavJsMrariSjzPnO1enRRL5SMhmOOWB9keFTE0wAAANxJREFUOMutk9kWgyAMRLFuiLjUtdp9yf//YglVsQXz1HniMPcEMgHGvpX2O0Ypi+EgCL+IAShC+wB7QfubRDT7AFcnUPoLMLiP4PyJbsb55i05AgnR5iaQDsICgtH0cotBWoAP1c7kC6kFxEseCfZfB6gEgbNeBrira2QmH1uVYCXlA3is8UmgUCPIyQJKEmu8QtQJN0e9DPXVpzG2G216c1CqRmcBOdxXk07sWUSPv07zo0amCNQycv+NzmR6cRcwmfbuI7p2nZ/z4be0P83Foz6vIkhfZXr82XgDlZsspIq4peUAAAAASUVORK5CYII="),Cm);a.complete&&a.naturalWidth>0&&t.drawImage(a,i+.15*r,s+.15*o,.7*r,.7*o),t.closePath(),t.restore()}onmousedown(t){const{component:e}=this.active;-1===this.layer.selected.indexOf(e)&&(this.layer.selected=[e])}ondragstart(t){const{component:e}=this.active;this.active.changes=ll.before([e]),this.active.last=this._pointOf(e,t)}ondragmove(t){const{component:e,last:n}=this.active,i=this._pointOf(e,t);e.move({x:i.x-n.x,y:i.y-n.y},!1),this.active.last=i}ondragend(t){const{component:e,changes:n}=this.active;ll.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}_pointOf(t,e){if(t.scalable){const n=t.toLocal(e.offsetX,e.offsetY);return t.toParent(n.x,n.y)}return{x:e.offsetX,y:e.offsetY}}}Tc.register("modeling-layer",class extends lp{constructor(t,e){super(t,e),this.pathHandler=new _m(this);const n=this.pathHandler,i=new gm(this),s=new Mm(this),r=new Em(this);this._modelers=[n,i,s,r],this._control_mode_modelers=[i,n,s,r],this.focusOutline=new fm(this),this.groupOutline=new mm(this),this.anchorHandler=new xm(this),this.moveHandleModeler=new Tm(this),this._reversed_modelers=this._modelers.slice().reverse(),this._control_mode_reverse_modelers=this._control_mode_modelers.slice().reverse(),this.hovered=null,this.hoveredDest=null}get modelers(){return this._control_mode?this._control_mode_modelers:this._modelers}get reversedModelers(){return this._control_mode?this._control_mode_reverse_modelers:this._reversed_modelers}async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}capture(t,e,n){return!!this.contains(t,e)&&this}contains(t,e){let n=this.selected.filter(t=>!!t.parent);const i=this.fromParent(t,e),s=this.get("scale")||{x:1,y:1};let r;if(this._state_dragging){if(this._counter_end){let n=s;if(this.anchorTarget.scalable?r=this.anchorTarget.fromScene(i.x,i.y):(r=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(r.x,r.y,this.anchorTarget,n))return!0}return!0}this.modelers.forEach(t=>t.reset()),this.moveHandleModeler.reset(),n=this.selected.filter(t=>!!t.parent);for(let o=0;o<n.length;o++){const a=n[o];let c=s;a.scalable?r=a.fromScene(i.x,i.y):(r=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(r.x,r.y,a,c))return this.currentModeler=e,!0}}const o=this._resolveMoveHandleOwner();if(o){let n,r=s;if(o.scalable?n=o.fromScene(i.x,i.y):(n=o.fromScene(t,e),r={x:1,y:1}),this.moveHandleModeler.contains(n.x,n.y,o,r))return this.currentModeler=this.moveHandleModeler,!0}if(this.anchorTarget){let n=s;if(this.anchorTarget.scalable?r=this.anchorTarget.fromScene(i.x,i.y):(r=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(r.x,r.y,this.anchorTarget,n))return this.currentModeler=this.anchorHandler,!0}else this.anchorHandler.reset();return this.currentModeler=null,!1}_componentDrawer(t,e,n,i){const s=[];let r=e.parent;if(e.isRootModel())return t.save(),i(t,e,n),void t.restore();for((t=this.getContext(e))==this.auxContext2D&&(n={x:1,y:1});r&&!r.isRootModel();)s.push(r),r=r.parent;t.save(),s.reverse().forEach(function(e){const n=e.rotatePoint;t.translate(n.x,n.y);const i=e.get("scale");i&&t.scale(i.x,i.y),t.rotate(e.get("rotation")),t.translate(-n.x,-n.y);const s=e.bounds;t.translate(s.left,s.top)});const o=e.rotatePoint;t.translate(o.x,o.y);const a=e.get("scale");a&&t.scale(a.x,a.y),t.rotate(e.get("rotation")),t.translate(-o.x,-o.y),i(t,e,n),t.restore()}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:i}=this.model;t.save(),t.beginPath(),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.rect(0,0,t.canvas.width,t.canvas.height),t.fillStyle="black",t.globalAlpha=.5,t.fill(),t.restore(),e&&t.translate(e.x*Xs,e.y*Xs),t.scale(n.x*Xs,n.y*Xs),i&&t.rotate(i),t.clearRect(0,0,this.rootModel.get("width"),this.rootModel.get("height"))}render(t){if(this.rootModel?.is3dMode)return;t.beginPath();const e=this.get("scale")||{x:1,y:1},n=this.selected.filter(t=>!!t.parent);if(this.anchorTarget&&this._componentDrawer(t,this.anchorTarget,e,(t,e,n)=>{this.anchorHandler.draw(t,e,n)}),this.focused&&this._componentDrawer(t,this.focused,e,(t,e,n)=>{this.focusOutline.draw(t,e,n)}),n.length>0&&n[0].parent.isGroup()){let i=n[0].parent;for(;i.parent.isGroup();)i=i.parent;this._componentDrawer(t,i,e,(t,e,n)=>{this.groupOutline.draw(t,e,n)})}n.forEach(n=>{this._componentDrawer(t,n,e,(t,e,n)=>{this.reversedModelers.forEach(i=>i.draw(t,e,n))})});const i=this._resolveMoveHandleOwner();i&&this._componentDrawer(t,i,e,(t,e,n)=>this.moveHandleModeler.draw(t,e,n))}_moveHandleOwner(t){let e=t;for(;e&&!e.showMoveHandle;)e=e.parent;return e&&e.showMoveHandle?e:null}_resolveMoveHandleOwner(){return this._moveHandleSticky&&!this._moveHandleSticky.parent&&(this._moveHandleSticky=null),this._moveHandleSticky}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;const e=this._moveHandleOwner(t);e?(this._moveHandleSticky=e,this._clearMoveHandleHideTimer()):this._moveHandleSticky&&this._scheduleMoveHandleHide(),this.invalidate()}_scheduleMoveHandleHide(){this._clearMoveHandleHideTimer(),this._moveHandleHideTimer=setTimeout(()=>{this._moveHandleHideTimer=null,this.disposed||this.moveHandleModeler.active||(this._moveHandleSticky=null,this.invalidate())},1e3)}_clearMoveHandleHideTimer(){this._moveHandleHideTimer&&(clearTimeout(this._moveHandleHideTimer),this._moveHandleHideTimer=null)}dispose(){this._clearMoveHandleHideTimer(),super.dispose()}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.moveHandleModeler.active?this._clearMoveHandleHideTimer():this.hovered=e?.origin}onmouseleave(t,e){this.moveHandleModeler.active||(this.hovered=null)}onkeydown(t){"Alt"==t.key&&(this._control_mode=!0,this.invalidate())}onkeyup(t){"Alt"==t.key&&(this._control_mode=!1,this.invalidate())}onselected(t,e){this.invalidate()}onchange_model(t,e,n){const{origin:i,deliverer:s}=n;i===s&&(t.translate&&this.set("translate",t.translate),void 0!==t.rotation&&this.set("rotation",t.rotation),t.scale&&this.set("scale",t.scale)),this.invalidate()}ondblclick_model(t,e){const n=e.origin;n?.root.fit()}ondblclick(t){"function"==typeof this.currentModeler.ondblclick&&this.currentModeler.ondblclick(t),this.invalidate()}onmousedown(t){this.currentModeler.onmousedown(t),this.invalidate()}onmouseup(t){"function"==typeof this.currentModeler.onmouseup&&this.currentModeler.onmouseup(t),this.invalidate()}ondragstart(t){this.currentModeler.ondragstart(t),this._state_dragging=!0}ondragmove(t){this.currentModeler.ondragmove(t),this.invalidate()}ondragend(t){this._state_dragging=!1,this.currentModeler.ondragend(t),this.invalidate()}ondrop(t,e){const{origin:n}=e,i=t.dataTransfer.files;if(i.length<1)return;const s=this.rootModel.toLocal(t.offsetX,t.offsetY),r=this.rootModel;Promise.all(Array.from(i).map(t=>new Promise((e,n)=>{const i=new FileReader;i.addEventListener("loadend",t=>{e(i.result)}),["error","abort"].forEach(t=>i.addEventListener(t,t=>{n(t)})),i.readAsDataURL(t)}))).then(e=>{if(t.altKey)return ll.around(this.app.commander,()=>{n.ondropfile(i,e)}),void(this.selected=[n]);const o=[],a=e.map((t,e)=>{let n;const a=i[e].type,c=i[e].name;return a.startsWith("image/")?(n=zl({type:a.startsWith("image/gif")?"gif-view":"image-view",top:0,left:0,width:200,height:200,src:t},r.app),o.push(new Promise((e,i)=>{const s=new Image;s.src=t,s.onload=()=>{n.set({width:s.width,height:s.height}),e()},s.onerror=t=>{i(t)}}))):a.startsWith("audio/")?n=zl({type:"audio",top:0,left:0,width:100,height:100,src:t},r.app):a.startsWith("vnd.ms-excel/")||/\.xlsx?$/.test(c)?n=zl({type:"excel",top:0,left:0,width:100,height:100,src:t},r.app):ts("dropped file",i[e]),n&&(n.center=s,s.x+=50,s.y+=50),n}).filter(Boolean).map(t=>({component:t,to_container:r}));a.length>0&&Promise.all(o).then(()=>{this.app.commander.execute(new Ol({changes:a})),this.selected=a.map(t=>t.component)},t=>{Zi(t)})},t=>{Zi(t)})}onwheel_scale(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer;let i;if(t.shiftKey)i=-1!=navigator.userAgent.indexOf("Win")?t.deltaY<0?1:-1:t.deltaX<0?1:-1,t.altKey?ll.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("letterSpacing")||Qs.LETTER_SPACING;e+=i,t.set("letterSpacing",e)})}):ll.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("fontSize")||Qs.FONT_SIZE;e<1&&(e=1),e+=i,t.set("fontSize",e)})});else{i=t.deltaY<0?1:-1;const e=n.get("scale")||{x:1,y:1},s=n.get("translate"),r=t.offsetX,o=t.offsetY,a=n.toLocal(r,o),c=.1*i,l={x:e.x+c,y:e.y+c};if(i<0&&e.x<.2||i>0&&e.x>10)return;n.set("scale",l);const h=n.toLocal(r,o);n.set("translate",{x:s.x+(h.x-a.x)*l.x,y:s.y+(h.y-a.y)*l.y})}}});Tc.register("scroll-layer",class extends cp{get capturable(){return!0}get pointerEvents(){return"none"}render(t){const{scrolling:e}=this.state;if(t.save(),t.beginPath(),t.fillStyle="#777",this.vscroller){const{left:n,top:i,width:s,height:r}=this.vscroller;t.globalAlpha="v"==e?1:.3,t.fillRect(n,i,s,r)}if(this.hscroller){const{left:n,top:i,width:s,height:r}=this.hscroller;t.globalAlpha="h"==e?1:.3,t.fillRect(n,i,s,r)}t.stroke(),t.restore()}resize(){super.resize(),this.calcScrollerBounds()}contains(t,e){const n=this.vscroller,i=this.hscroller;return this.setState("scrolling",n&&t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height?"v":i&&t>=i.left&&t<=i.left+i.width&&e>=i.top&&e<=i.top+i.height?"h":null),!!this.getState("scrolling")}get eventMap(){return{"(root)":{"model-layer":{change:this.onchangeModelLayer}}}}onchange(t){"scrolling"in t&&this.invalidate()}ondragstart(t,e){this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragmove(t,e){const n=this.root,{clientWidth:i,clientHeight:s}=this.canvas,{width:r,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=r/i,p=o/s;d&&n.rootModel.move({x:"h"==d?(-a+this.lastPosition.x)*l*u:0,y:"v"==d?(-c+this.lastPosition.y)*h*p:0},!1),this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragend(){delete this.lastPosition,this.setState({scrolling:null})}calcScrollerBounds(){if(!this.rootModel)return;const{clientWidth:t,clientHeight:e}=this.canvas,{width:n,height:i}=this.rootModel.model,{x:s=1,y:r=1}=this._scale||{},{x:o=0,y:a=0}=this._translate||{},c=n/t,l=i/e;let h={left:-o/s/c,top:e-10,width:t/s/c,height:10};this.hscroller=h.left>1||h.width+h.left<t-1?h:null,h={left:t-10,top:-a/r/l,width:10,height:e/r/l},this.vscroller=h.top>1||h.height+h.top<e-1?h:null,this.invalidate()}onchangeModelLayer(t,e,n){if(t.scale){const{x:e=1,y:n=1}=t?.scale||{};this._scale={x:e,y:n},this.calcScrollerBounds()}if(t.translate){const{x:e=0,y:n=0}=t.translate||{};this._translate={x:e,y:n},this.calcScrollerBounds()}}});const Pm="#ff3366",Om=[3,3];function Dm(t,e){const n=t?.capabilities??t?.constructor?.capabilities;return Array.isArray(n)&&n.includes(e)}function zm(...t){return e=>{const n=Object.getPrototypeOf(e),i=Array.isArray(n?.capabilities)?n.capabilities:[],s=new Set([...i,...t]);return Object.defineProperty(e,"capabilities",{value:Object.freeze([...s]),writable:!1,configurable:!0}),e}}Tc.register("snap-guide-layer",class extends cp{constructor(){super(...arguments),this._snapResult=null}get pointerEvents(){return"none"}get capturable(){return!1}contains(t,e){return!1}get snapResult(){return this._snapResult}set snapResult(t){this._snapResult=t,this.invalidate()}clear(){this._snapResult&&(this._snapResult=null,this.invalidate())}get eventMap(){return{"(root)":{"model-layer":{change:this.onchange_root_model}}}}onchange_root_model(t){(t.translate||t.scale)&&this.syncTransform()}syncTransform(){const t=this.rootModel;if(!t)return;const e=t.get("translate")||{x:0,y:0},n=t.get("scale")||{x:1,y:1};this.set({translate:e,scale:n})}async ready(){await super.ready(),this.syncTransform()}render(t){const e=this._snapResult;if(e&&0!==e.guides.length){t.save(),t.strokeStyle=Pm,t.fillStyle=Pm,t.lineWidth=1,t.setLineDash(Om);for(let n=0,i=e.guides.length;n<i;n++){const i=e.guides[n];t.beginPath(),"x"===i.axis?(t.moveTo(i.position,i.from),t.lineTo(i.position,i.to)):(t.moveTo(i.from,i.position),t.lineTo(i.to,i.position)),t.stroke()}t.restore()}}});const Im=new Map;function Rm(t){Im.set(t.name,t)}function jm(t){return Im.get(t)}function Lm(){return[...Im.values()]}var Fm=Object.freeze({__proto__:null,capability:zm,getAllCapabilityMeta:Lm,getCapabilityMeta:jm,hasCapability:Dm,registerCapabilityMeta:Rm});function Nm(t,e,n,i){var s,r=arguments.length,o=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(o=(r<3?s(o):r>3?s(e,n,o):s(e,n))||o);return r>3&&o&&Object.defineProperty(e,n,o),o}function Hm(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function Bm(t,e,n,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(t,n):s?s.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const Gm=["mousemove","mouseup","mousedown","mouseout","wheel","tap","click","touchstart","touchmove","touchend","mouseenter","mouseleave","dragstart","dragmove","dragend","dblclick"];function Vm(t){return class extends t{constructor(){super(...arguments),this.userInputEventHandler=t=>{ol(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&&("popup"!==this.position&&(this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element)),this.scalable||(this.element.style.zIndex="100"),Gm.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),Ks.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),this.oncreate_element&&this.oncreate_element(this.element))}reposition(){this.state.screenFixed&&this.isContainer?.()||this.element&&Or(this)}disposeElement(){if(!this.element)return;Gm.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)}),Ks.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(),"popup"!==this.position&&(this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element)),this.setElementProperties(this.element),this.reposition(),this.applyElementModelingFaint()}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.applyElementModelingFaint()}applyElementModelingFaint(){const t=this.element;if(!t)return;const{alpha:e=1}=this.state,n=e*(zo(this)?.5:1);t.style.display=!this.app?.isEditMode&&this.hidden?"none":"block",t.style.opacity=n<1?String(n):""}onchange(t,e){this.element&&this.setElementProperties(this.element),"position"in t&&this.onchangePosition(),this.reposition(),this.applyElementModelingFaint()}onchangePosition(){this.element&&("popup"!==this.position?"static"==this.position&&this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element):this.element.parentNode?.removeChild(this.element))}isDescendible(t){return t.isHTMLElement()}}}var Ym;const Wm={x:1,y:1},Um={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"},$m={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 Xm extends(Vm(Kl)){constructor(){super(...arguments),Ym.set(this,null),this.startDragging=t=>{if(!this.state.draggable)return;t.preventDefault(),t.stopPropagation();const e=t.clientX,n=t.clientY,{left:i,top:s}=this.bounds,r=this.rootModel.getOverlay?.(this)?.style.transform,o=r?.match(/scale\(([^,]+),\s*([^)]+)\)/),a=o?parseFloat(o[1]):1,c=o?parseFloat(o[2]):a,l=t=>{t.preventDefault(),t.stopPropagation();const r=(t.clientX-e)/a,o=(t.clientY-n)/c;this.setState({left:i+r,top:s+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 $m}isPositionable(){return!0}setElementProperties(t){}get layout(){return Fc.get(this.get("layout"))||Nc}reposition(){if(!this.element)return;const t=this,{id:e,class:n,scale:i=Wm}=t.state,{rotation:s=0,hidden:r}=t,{left:o,top:a,width:c,height:l}=t.bounds,h=c/2,d=l/2,u=t.element;u.hidden=r,e&&(u.id=e),n&&(u.className=n),Object.assign(u.style,Um,{left:o+"px",top:a+"px",width:"0px",height:"0px",backgroundColor:"transparent"});const p=t.delta(),f=(i&&i.x||1)*p.sx,m=(i&&i.y||1)*p.sy,g=(s||0)+p.theta,y=p.tx||0,b=p.ty||0;u.style.transform=`translate(${y+h}px, ${b+d}px) rotate(${g}rad) translate(${-h}px, ${-d}px) scale(${f}, ${m}) perspective(1px)`}set path(t){const{minimized:e}=this.state,n=t[0],i=t[2];e?this.set({left:n.x,top:n.y,width:i.x-n.x}):this.set({left:n.x,top:n.y,width:i.x-n.x,height:i.y-n.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){const{minimized:e}=this.state,{left:n=0,top:i=0,width:s=0,height:r=0}=t,o={left:n,top:i};e?this.set({...o,width:s}):this.set({...o,width:s,height:r})}updatePosition(){if(!this.origin)return void(Hm(this,Ym,"f")&&(Hm(this,Ym,"f").disconnect(),Bm(this,Ym,null,"f")));const t=this.rootModel.auxOverlay;if(!t)return;const e=this.bounds,{width:n,height:i}="static"!==this.position?t.getBoundingClientRect():this.parent.bounds,{x:s,y:r}=function(t,e,n){const{left:i,top:s,width:r,height:o}=e,{width:a,height:c}=n;return t?{x:t.includes("left")?i:t.includes("center")?i+(r-a)/2:i+(r-a),y:t.includes("top")?s:t.includes("middle")?s+(o-c)/2:s+(o-c)}:{x:n.left,y:n.top}}(this.origin,{left:0,top:0,width:n,height:i},e),o=this.offset;this.bounds={left:s+(this.origin.includes("right")?-o.x:+o.x),top:r+(this.origin.includes("bottom")?-o.y:+o.y),width:e.width,height:e.height},Hm(this,Ym,"f")||(Bm(this,Ym,new ResizeObserver(()=>{requestAnimationFrame(()=>this.updatePosition())}),"f"),Hm(this,Ym,"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(){Hm(this,Ym,"f")&&(Hm(this,Ym,"f").disconnect(),Bm(this,Ym,null,"f")),super.dispose()}createElement(){super.createElement(),this.element&&(this.element.setAttribute("scene","container"),this.onchangeButtons(),this.onchangeMinimized())}onchangeButtons(){if(!this.element)return;const{draggable:t,minimizable:e,closable:n,minimized:i,hidden:s}=this.state,{width:r}=this.bounds;this.element.style.setProperty("--container-width",`${r}px`);try{D(s?z:I`
2
+ /*! https://mths.be/codepointat v0.2.0 by @mathias */,String.prototype.codePointAt||function(){var t=function(){try{var t={},e=Object.defineProperty,n=e(t,t,t)&&e}catch(t){}return n}(),e=function(t){if(null==this)throw TypeError();var e=String(this),n=e.length,i=t?Number(t):0;if(i!=i&&(i=0),!(i<0||i>=n)){var s,r=e.charCodeAt(i);return r>=55296&&r<=56319&&n>i+1&&(s=e.charCodeAt(i+1))>=56320&&s<=57343?1024*(r-55296)+s-56320+65536:r}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e}(),Math.log10=Math.log10||function(t){return Math.log(t)*Math.LOG10E},t.exports=function(){function t(e,n,i){function s(o,a){if(!n[o]){if(!e[o]){if(!a&&ss)return ss(o);if(r)return r(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 s(e[o][1][t]||t)},l,l.exports,t,e,n,i)}return n[o].exports}for(var r=ss,o=0;o<i.length;o++)s(i[o]);return s}return t}()({1:[function(t,e,n){var i=t("./utils"),s=function(){var t=i.stringToArray,e=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],n=["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fifteenth","Sixteenth","Seventeenth","Eighteenth","Nineteenth"],s=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],r=["Thousand","Million","Billion","Trillion"];function o(t,i){var o=function(t,i,a){var c="";if(t<=19)c=(i?" and ":"")+(a?n[t]:e[t]);else if(t<100){var l=Math.floor(t/10),h=t%10;c=(i?" and ":"")+s[l-2],h>0?c+="-"+o(h,!1,a):a&&(c=c.substring(0,c.length-1)+"ieth")}else if(t<1e3){var d=Math.floor(t/100),u=t%100;c=(i?", ":"")+e[d]+" Hundred",u>0?c+=o(u,!0,a):a&&(c+="th")}else{var p=Math.floor(Math.log10(t)/3);p>r.length&&(p=r.length);var f=Math.pow(10,3*p),m=Math.floor(t/f),g=t-m*f;c=(i?", ":"")+o(m,!1,!1)+" "+r[p-1],g>0?c+=o(g,!0,a):a&&(c+="th")}return c};return o(t,!1,i)}var a=Object.create(null);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}),s.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,r.forEach(function(t,e){var n=t.toLowerCase(),i=Math.pow(10,3*(e+1));a[n]=i,a[n+"th"]=i});var l=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]],h={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};function d(t){for(var e=0;e<l.length;e++){var n=l[e];if(t>=n[0])return n[1]+d(t-n[0])}return""}function u(t){for(var e=0,n=1,i=t.length-1;i>=0;i--){var s=t[i],r=h[s];r<n?e-=r:(n=r,e+=r)}return e}function p(t,e){for(var n=[],i=e.charCodeAt(0);t>0;)n.unshift(String.fromCharCode((t-1)%26+i)),t=Math.floor((t-1)/26);return n.join("")}function f(t,e){for(var n=e.charCodeAt(0),i=0,s=0;s<t.length;s++)i+=(t.charCodeAt(t.length-s-1)-n+1)*Math.pow(26,s);return i}function m(t,e){if(void 0!==t)return b(t=Math.floor(t),v(e))}var g={DECIMAL:"decimal",LETTERS:"letters",ROMAN:"roman",WORDS:"words",SEQUENCE:"sequence"},y={UPPER:"upper",LOWER:"lower",TITLE:"title"};function b(e,n){var i,s=e<0;switch(e=Math.abs(e),n.primary){case g.LETTERS:i=p(e,n.case===y.UPPER?"A":"a");break;case g.ROMAN:i=d(e),n.case===y.UPPER&&(i=i.toUpperCase());break;case g.WORDS:i=o(e,n.ordinal),n.case===y.UPPER?i=i.toUpperCase():n.case===y.LOWER&&(i=i.toLowerCase());break;case g.DECIMAL:i=""+e;var r=n.mandatoryDigits-i.length;if(r>0){var a=new Array(r+1).join("0");i=a+i}if(48!==n.zeroCode&&(i=t(i).map(function(t){return String.fromCodePoint(t.codePointAt(0)+n.zeroCode-48)}).join("")),n.regular)for(var c=Math.floor((i.length-1)/n.groupingSeparators.position);c>0;c--){var l=i.length-c*n.groupingSeparators.position;i=i.substr(0,l)+n.groupingSeparators.character+i.substr(l)}else n.groupingSeparators.reverse().forEach(function(t){var e=i.length-t.position;i=i.substr(0,e)+t.character+i.substr(e)});if(n.ordinal){var h={1:"st",2:"nd",3:"rd"}[i[i.length-1]];(!h||i.length>1&&"1"===i[i.length-2])&&(h="th"),i+=h}break;case g.SEQUENCE:throw{code:"D3130",value:n.token}}return s&&(i="-"+i),i}var _=[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 v(e){var n,i={type:"integer",primary:g.DECIMAL,case:y.LOWER,ordinal:!1},s=e.lastIndexOf(";");switch(-1===s?n=e:(n=e.substring(0,s),"o"===e.substring(s+1)[0]&&(i.ordinal=!0)),n){case"A":i.case=y.UPPER;case"a":i.primary=g.LETTERS;break;case"I":i.case=y.UPPER;case"i":i.primary=g.ROMAN;break;case"W":i.case=y.UPPER,i.primary=g.WORDS;break;case"Ww":i.case=y.TITLE,i.primary=g.WORDS;break;case"w":i.primary=g.WORDS;break;default:var r=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<_.length;n++){var i=_[n];if(t>=i&&t<=i+9){if(e=!0,o++,l++,null===r)r=i;else if(i!==r)throw{code:"D3131"};break}}e||(35===t?(l++,a++):c.push({position:l,character:String.fromCodePoint(t)}))}),o>0){i.primary=g.DECIMAL,i.zeroCode=r,i.mandatoryDigits=o,i.optionalDigits=a;var h=function(t){if(0===t.length)return 0;for(var e=t[0].character,n=1;n<t.length;n++)if(t[n].character!==e)return 0;for(var i=t.map(function(t){return t.position}),s=function(t,e){return 0===e?t:s(e,t%e)},r=i.reduce(s),o=1;o<=i.length;o++)if(-1===i.indexOf(o*r))return 0;return r}(c);h>0?(i.regular=!0,i.groupingSeparators={position:h,character:c[0].character}):(i.regular=!1,i.groupingSeparators=c)}else i.primary=g.SEQUENCE,i.token=n}return i}var x={Y:"1",M:"1",D:"1",d:"1",F:"n",W:"1",w:"1",X:"1",x:"1",H:"1",h:"1",P:"n",m:"01",s:"01",f:"1",Z:"01:01",z:"01:01",C:"n",E:"n"};function w(t){for(var e=[],n={type:"datetime",parts:e},i=function(n,i){if(i>n){var s=t.substring(n,i);s=s.split("]]").join("]"),e.push({type:"literal",value:s})}},s=0,r=0;r<t.length;){if("["===t.charAt(r)){if("["===t.charAt(r+1)){i(s,r),e.push({type:"literal",value:"["}),s=r+=2;continue}if(i(s,r),s=r,-1===(r=t.indexOf("]",s)))throw{code:"D3135"};var o,a=t.substring(s+1,r),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 m={min:f(u),max:f(p)};c.width=m,o=a.substring(1,l)}else o=a.substring(1);if(1===o.length)c.presentation1=o;else if(o.length>1){var g=o.charAt(o.length-1);-1!=="atco".indexOf(g)?(c.presentation2=g,"o"===g&&(c.ordinal=!0),c.presentation1=o.substring(0,o.length-1)):c.presentation1=o}else c.presentation1=x[c.component];if(void 0===c.presentation1)throw{code:"D3132",value:c.component};if("n"===c.presentation1[0])c.names=y.LOWER;else if("N"===c.presentation1[0])"n"===c.presentation1[1]?c.names=y.TITLE:c.names=y.UPPER;else if(-1!=="YMDdFWwXxHhmsf".indexOf(c.component)){var b=c.presentation1;if(c.presentation2&&(b+=";"+c.presentation2),c.integerFormat=v(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 _=c.integerFormat.mandatoryDigits+c.integerFormat.optionalDigits;_>=2&&(c.n=_)}}"Z"!==c.component&&"z"!==c.component||(c.integerFormat=v(c.presentation1)),e.push(c),s=r+1}r++}return i(s,r),n}var M=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],S=["January","February","March","April","May","June","July","August","September","October","November","December"],k=864e5,A=function(t){var e=Date.UTC(t.year,t.month),n=new Date(e).getUTCDay();return 0===n&&(n=7),n>4?e+(8-n)*k:e-(n-1)*k},E=function(t,e){return{year:t,month:e,nextMonth:function(){return 11===e?E(t+1,0):E(t,e+1)},previousMonth:function(){return 0===e?E(t-1,11):E(t,e-1)},nextYear:function(){return E(t+1,e)},previousYear:function(){return E(t-1,e)}}},C=function(t,e){return(e-t)/(7*k)+1},T=function(t,e){var n;switch(e){case"Y":n=t.getUTCFullYear();break;case"M":n=t.getUTCMonth()+1;break;case"D":n=t.getUTCDate();break;case"d":n=(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-Date.UTC(t.getUTCFullYear(),0))/k+1;break;case"F":0===(n=t.getUTCDay())&&(n=7);break;case"W":var i=E(t.getUTCFullYear(),0),s=A(i),r=Date.UTC(i.year,t.getUTCMonth(),t.getUTCDate()),o=C(s,r);if(o>52)r>=A(i.nextYear())&&(o=1);else if(o<1){var a=A(i.previousYear());o=C(a,r)}n=Math.floor(o);break;case"w":var c=E(t.getUTCFullYear(),t.getUTCMonth()),l=A(c),h=Date.UTC(c.year,c.month,t.getUTCDate()),d=C(l,h);if(d>4)h>=A(c.nextMonth())&&(d=1);else if(d<1){var u=A(c.previousMonth());d=C(u,h)}n=Math.floor(d);break;case"X":var p=E(t.getUTCFullYear(),0),f=A(p),m=A(p.nextYear()),g=t.getTime();n=g<f?p.year-1:g>=m?p.year+1:p.year;break;case"x":var y=E(t.getUTCFullYear(),t.getUTCMonth()),b=A(y),_=y.nextMonth(),v=A(_),x=t.getTime();n=x<b?y.previousMonth().month+1:x>=v?_.month+1:y.month+1;break;case"H":n=t.getUTCHours();break;case"h":n=t.getUTCHours(),0==(n%=12)&&(n=12);break;case"P":n=t.getUTCHours()>=12?"pm":"am";break;case"m":n=t.getUTCMinutes();break;case"s":n=t.getUTCSeconds();break;case"f":n=t.getUTCMilliseconds();break;case"Z":case"z":break;case"C":case"E":n="ISO"}return n},P=null;function O(t,e,n){var i=0,s=0;if(void 0!==n){var r=parseInt(n);i=Math.floor(r/100),s=r%100}var o,a=function(t,e){var n=T(t,e.component);if(-1!=="YMDdFWwXxHhms".indexOf(e.component))if("Y"===e.component&&-1!==e.n&&(n%=Math.pow(10,e.n)),e.names){if("M"===e.component||"x"===e.component)n=S[n-1];else{if("F"!==e.component)throw{code:"D3133",value:e.component};n=M[n]}e.names===y.UPPER?n=n.toUpperCase():e.names===y.LOWER&&(n=n.toLowerCase()),e.width&&n.length>e.width.max&&(n=n.substring(0,e.width.max))}else n=b(n,e.integerFormat);else if("f"===e.component)n=b(n,e.integerFormat);else if("Z"===e.component||"z"===e.component){var r=100*i+s;if(e.integerFormat.regular)n=b(r,e.integerFormat);else{var o=e.integerFormat.mandatoryDigits;if(1===o||2===o)n=b(i,e.integerFormat),0!==s&&(n+=":"+m(s,"00"));else{if(3!==o&&4!==o)throw{code:"D3134",value:o};n=b(r,e.integerFormat)}}r>=0&&(n="+"+n),"z"===e.component&&(n="GMT"+n),0===r&&"t"===e.presentation2&&(n="Z")}return n};void 0===e?(null===P&&(P=w("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),o=P):o=w(e);var c=new Date(t+60*(60*i+s)*1e3),l="";return o.parts.forEach(function(t){"literal"===t.type?l+=t.value:l+=a(c,t)}),l}function D(t){var e=Object.create(null);if("datetime"===t.type)e.type="datetime",e.parts=t.parts.map(function(t){var e=Object.create(null);if("literal"===t.type)e.regex=t.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if("Z"===t.component||"z"===t.component){var n;Array.isArray(t.integerFormat.groupingSeparators)||(n=t.integerFormat.groupingSeparators),e.regex="","z"===t.component&&(e.regex="GMT"),e.regex+="[-+][0-9]+",n&&(e.regex+=n.character+"[0-9]+"),e.parse=function(e){"z"===t.component&&(e=e.substring(3));var i=0,s=0;return n?(i=Number.parseInt(e.substring(0,e.indexOf(n.character))),s=Number.parseInt(e.substring(e.indexOf(n.character)+1))):e.length-1<=2?i=Number.parseInt(e):(i=Number.parseInt(e.substring(0,3)),s=Number.parseInt(e.substring(3))),60*i+s}}else if("f"===t.component)e.regex="[0-9]+",e.parse=function(t){return 1e3*parseFloat("0."+t.substring(0,3))};else if(t.integerFormat)t.integerFormat.n=t.n,e=D(t.integerFormat);else{e.regex="[a-zA-Z]+";var i=Object.create(null);if("M"===t.component||"x"===t.component)S.forEach(function(e,n){t.width&&t.width.max?i[e.substring(0,t.width.max)]=n+1:i[e]=n+1});else if("F"===t.component)M.forEach(function(e,n){n>0&&(t.width&&t.width.max?i[e.substring(0,t.width.max)]=n:i[e]=n)});else{if("P"!==t.component)throw{code:"D3133",value:t.component};i={am:0,AM:0,pm:1,PM:1}}e.parse=function(t){return i[t]}}return e.component=t.component,e});else{e.type="integer";var n,s=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 g.LETTERS:e.regex=s?"[A-Z]+":"[a-z]+",e.parse=function(t){return f(t,s?"A":"a")};break;case g.ROMAN:e.regex=s?"[MDCLXVI]+":"[mdclxvi]+",e.parse=function(t){return u(s?t:t.toUpperCase())};break;case g.WORDS:e.regex="(?:"+i.keys(a).concat("and","[\\-, ]").join("|")+")+",e.parse=function(t){return c(t.toLowerCase())};break;case g.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 g.SEQUENCE:throw{code:"D3130",value:t.token}}}return e}function z(t,e){if(void 0!==t)return D(v(e)).parse(t)}function I(t,e){var n=D(w(e)),i="^"+n.parts.map(function(t){return"("+t.regex+")"}).join("")+"$",s=new RegExp(i,"i").exec(t);if(null!==s){for(var r=161,o=130,a=84,c=72,l=23,h=47,d=Object.create(null),u=1;u<s.length;u++){var p=n.parts[u-1];p.parse&&(d[p.component]=p.parse(s[u]))}if(0===Object.getOwnPropertyNames(d).length)return;var f=0,m=function(t){f<<=1,f+=t?1:0},g=function(t){return!(~t&f||!(t&f))};"YXMxWwdD".split("").forEach(function(t){return m(d[t])});var y=!g(r)&&g(o),b=g(a),_=!b&&g(c);f=0,"PHhmsf".split("").forEach(function(t){return m(d[t])});var v=!g(l)&&g(h),x=(y?"YD":b?"XxwF":_?"XWF":"YMD")+(v?"Phmsf":"Hmsf"),M=this.environment.timestamp,S=!1,k=!1;if(x.split("").forEach(function(t){if(void 0===d[t])S?(d[t]=-1!=="MDd".indexOf(t)?1:0,k=!0):d[t]=T(M,t);else if(S=!0,k)throw{code:"D3136"}}),d.M>0?d.M-=1:d.M=0,y){var A=Date.UTC(d.Y,0),E=1e3*(d.d-1)*60*60*24,C=new Date(A+E);d.M=C.getUTCMonth(),d.D=C.getUTCDate()}if(b)throw{code:"D3136"};if(_)throw{code:"D3136"};v&&(d.H=12===d.h?0:d.h,1===d.P&&(d.H+=12));var P=Date.UTC(d.Y,d.M,d.D,d.H,d.m,d.s,d.f);return(d.Z||d.z)&&(P-=60*(d.Z||d.z)*1e3),P}}var R=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(!R.test(t))throw{stack:(new Error).stack,code:"D3110",value:t};return Date.parse(t)}return I.call(this,t,e)}}function L(t,e,n){if(void 0!==t)return O.call(this,t,e,n)}return{formatInteger:m,parseInteger:z,fromMillis:L,toMillis:j}}();e.exports=s},{"./utils":6}],2:[function(t,e,n){(function(n){(function(){function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=s(t))||e){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}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 s(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.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)?r(t,e):void 0}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function a(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(o(t)+" is not iterable")}function c(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var t,e,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",s=n.toStringTag||"@@toStringTag";function r(n,i,s,r){var c=i&&i.prototype instanceof a?i:a,h=Object.create(c.prototype);return l(h,"_invoke",function(n,i,s){var r,a,c,l=0,h=s||[],d=!1,u={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,a=0,c=t,u.n=n,o}};function p(n,i){for(a=n,c=i,e=0;!d&&l&&!s&&e<h.length;e++){var s,r=h[e],p=u.p,f=r[2];n>3?(s=f===i)&&(c=r[(a=r[4])?5:(a=3,3)],r[4]=r[5]=t):r[0]<=p&&((s=n<2&&p<r[1])?(a=0,u.v=i,u.n=r[1]):p<f&&(s=n<3||r[0]>i||i>f)&&(r[4]=n,r[5]=i,u.n=f,a=0))}if(s||n>1)return o;throw d=!0,i}return function(s,h,f){if(l>1)throw TypeError("Generator is already running");for(d&&1===h&&p(h,f),a=h,c=f;(e=a<2?t:c)||!d;){r||(a?a<3?(a>1&&(u.n=-1),p(a,c)):u.n=c:u.v=c);try{if(l=2,r){if(a||(s="next"),e=r[s]){if(!(e=e.call(r,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=r.return)&&e.call(r),a<2&&(c=TypeError("The iterator does not provide a '"+s+"' method"),a=1);r=t}else if((e=(d=u.n<0)?c:n.call(i,u))!==o)break}catch(e){r=t,a=1,c=e}finally{l=1}}return{value:e,done:d}}}(n,s,r),!0),h}var o={};function a(){}function h(){}function d(){}e=Object.getPrototypeOf;var u=[][i]?e(e([][i]())):(l(e={},i,function(){return this}),e),p=d.prototype=a.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,l(t,s,"GeneratorFunction")),t.prototype=Object.create(p),t}return h.prototype=d,l(p,"constructor",d),l(d,"constructor",h),h.displayName="GeneratorFunction",l(d,s,"GeneratorFunction"),l(p),l(p,s,"Generator"),l(p,i,function(){return this}),l(p,"toString",function(){return"[object Generator]"}),(c=function(){return{w:r,m:f}})()}function l(t,e,n,i){var s=Object.defineProperty;try{s({},"",{})}catch(t){s=0}l=function(t,e,n,i){function r(e,n){l(t,e,function(t){return this._invoke(e,n,t)})}e?s?s(t,e,{value:n,enumerable:!i,configurable:!i,writable:!i}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},l(t,e,n,i)}var h=t("./utils"),d=function(){var t=c().m(V),e=c().m(Y),s=c().m(W),r=c().m(U),l=c().m(J),d=c().m(ft),u=c().m(mt),p=c().m(gt),f=c().m(bt),m=c().m(At),g=c().m(Pt),y=c().m(zt),b=h.isNumeric,_=h.isArrayOfStrings,v=h.isArrayOfNumbers,x=h.createSequence,w=h.isSequence,M=h.isFunction,S=h.isLambda,k=h.isIterable,A=h.getFunctionArity,E=h.isDeepEqual,C=h.stringToArray;function T(t){if(void 0!==t){var e=0;return t.forEach(function(t){e+=t}),e}}function P(t){return void 0===t?0:t.length}function O(t){if(void 0!==t&&0!==t.length)return Math.max.apply(Math,t)}function D(t){if(void 0!==t&&0!==t.length)return Math.min.apply(Math,t)}function z(t){if(void 0!==t&&0!==t.length){var e=0;return t.forEach(function(t){e+=t}),e/t.length}}function I(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(M(t))n="";else{if("number"==typeof t&&!isFinite(t))throw{code:"D3001",value:t,stack:(new Error).stack};var i=e?2:0;Array.isArray(t)&&t.outerWrapper&&(t=t[0]),n=JSON.stringify(t,function(t,e){return null!=e&&e.toPrecision&&b(e)?Number(e.toPrecision(15)):e&&M(e)?"":e},i)}return n}}function R(t,e,n){if(void 0!==t){var i=C(t),s=i.length;if(s+e<0&&(e=0),void 0!==n){if(n<=0)return"";var r=e>=0?e+n:s+e+n;return i.slice(e,r).join("")}return i.slice(e).join("")}}function j(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 F(t){if(void 0!==t)return t.toLowerCase()}function N(t){if(void 0!==t)return t.toUpperCase()}function H(t){if(void 0!==t)return C(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 G(t,e,n){if(void 0!==t){var i;void 0!==n&&0!==n.length||(n=" ");var s=Math.abs(e)-H(t);if(s>0){var r=new Array(s+1).join(n);n.length>1&&(r=R(r,0,s)),i=e>0?t+r:r+t}else i=t;return i}}function V(e,n){var i;return c().w(function(t){for(;;)switch(t.n){case 0:if(i=e.apply(this,[n]),!k(i)){t.n=2;break}return t.d(a(i),1);case 1:i=t.v;case 2:if(!i||"number"==typeof i.start||"number"===i.end||Array.isArray(i.groups)||M(i.next)){t.n=3;break}throw{code:"T1010",stack:(new Error).stack};case 3:return t.a(2,i)}},t,this)}function Y(t,n){var i,s;return c().w(function(e){for(;;)switch(e.n){case 0:if(void 0!==t){e.n=1;break}return e.a(2,void 0);case 1:if("string"!=typeof n){e.n=2;break}i=-1!==t.indexOf(n),e.n=4;break;case 2:return e.d(a(V(n,t)),3);case 3:s=e.v,i=void 0!==s;case 4:return e.a(2,i)}},e)}function W(t,e,n){var i,r,o;return c().w(function(s){for(;;)switch(s.n){case 0:if(void 0!==t){s.n=1;break}return s.a(2,void 0);case 1:if(!(n<0)){s.n=2;break}throw{stack:(new Error).stack,value:n,code:"D3040",index:3};case 2:if(i=x(),!(void 0===n||n>0)){s.n=6;break}return r=0,s.d(a(V(e,t)),3);case 3:if(void 0===(o=s.v)){s.n=6;break}case 4:if(void 0===o||!(void 0===n||r<n)){s.n=6;break}return i.push({match:o.match,index:o.start,groups:o.groups}),s.d(a(V(o.next)),5);case 5:o=s.v,r++,s.n=4;break;case 6:return s.a(2,i)}},s)}function U(t,e,n,i){var s,o,l,h,d,u,p,f;return c().w(function(r){for(;;)switch(r.n){case 0:if(void 0!==t){r.n=1;break}return r.a(2,void 0);case 1:if(s=this,""!==e){r.n=2;break}throw{code:"D3010",stack:(new Error).stack,value:e,index:2};case 2:if(!(i<0)){r.n=3;break}throw{code:"D3011",stack:(new Error).stack,value:i,index:4};case 3:if(o="string"==typeof n?function(t){for(var e="",i=0,s=n.indexOf("$",i);-1!==s&&i<n.length;){e+=n.substring(i,s),i=s+1;var r=n.charAt(i);if("$"===r)e+="$",i++;else if("0"===r)e+=t.match,i++;else{var o;if(o=0===t.groups.length?1:Math.floor(Math.log(t.groups.length)*Math.LOG10E)+1,s=parseInt(n.substring(i,i+o),10),o>1&&s>t.groups.length&&(s=parseInt(n.substring(i,i+o-1),10)),isNaN(s))e+="$";else{if(t.groups.length>0){var a=t.groups[s-1];void 0!==a&&(e+=a)}i+=s.toString().length}}s=n.indexOf("$",i)}return e+=n.substring(i)}:n,l="",h=0,!(void 0===i||i>0)){r.n=15;break}if(d=0,"string"!=typeof e){r.n=4;break}for(u=t.indexOf(e,h);-1!==u&&(void 0===i||d<i);)l+=t.substring(h,u),l+=n,h=u+e.length,d++,u=t.indexOf(e,h);l+=t.substring(h),r.n=14;break;case 4:return r.d(a(V(e,t)),5);case 5:if(void 0===(p=r.v)){r.n=13;break}case 6:if(void 0===p||!(void 0===i||d<i)){r.n=12;break}if(l+=t.substring(h,p.start),f=o.apply(s,[p]),!k(f)){r.n=8;break}return r.d(a(f),7);case 7:f=r.v;case 8:if("string"!=typeof f){r.n=9;break}l+=f,r.n=10;break;case 9:throw{code:"D3012",stack:(new Error).stack,value:f};case 10:return h=p.start+p.match.length,d++,r.d(a(V(p.next)),11);case 11:p=r.v,r.n=6;break;case 12:l+=t.substring(h),r.n=14;break;case 13:l=t;case 14:r.n=16;break;case 15:l=t;case 16:return r.a(2,l)}},r,this)}function $(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 X(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 q(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 K(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 Q(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 Z(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 J(t,e,n){var i,s,r,o;return c().w(function(c){for(;;)switch(c.n){case 0:if(void 0!==t){c.n=1;break}return c.a(2,void 0);case 1:if(!(n<0)){c.n=2;break}throw{code:"D3020",stack:(new Error).stack,value:n,index:3};case 2:if(i=[],!(void 0===n||n>0)){c.n=9;break}if("string"!=typeof e){c.n=3;break}i=t.split(e,n),c.n=9;break;case 3:return s=0,c.d(a(V(e,t)),4);case 4:if(void 0===(r=c.v)){c.n=8;break}o=0;case 5:if(void 0===r||!(void 0===n||s<n)){c.n=7;break}return i.push(t.substring(o,r.start)),o=r.end,c.d(a(V(r.next)),6);case 6:r=c.v,s++,c.n=5;break;case 7:(void 0===n||s<n)&&i.push(t.substring(o)),c.n=9;break;case 8:i.push(t);case 9:return c.a(2,i)}},l)}function tt(t,e){if(void 0!==t)return void 0===e&&(e=""),t.join(e)}function et(t,e,n){if(void 0!==t){var i={"decimal-separator":".","grouping-separator":",","exponent-separator":"e",infinity:"Infinity","minus-sign":"-",NaN:"NaN",percent:"%","per-mille":"‰","zero-digit":"0",digit:"#","pattern-separator":";"};void 0!==n&&h.keys(n).forEach(function(t){i[t]=n[t]});for(var s=[],r=i["zero-digit"].charCodeAt(0),o=r;o<r+10;o++)s.push(String.fromCharCode(o));var a=s.concat([i["decimal-separator"],i["exponent-separator"],i["grouping-separator"],i.digit,i["pattern-separator"]]),c=e.split(i["pattern-separator"]);if(c.length>2)throw{code:"D3080",stack:(new Error).stack};var l=function(t){var e,n,s,r,o=function(){for(var e,n=0;n<t.length;n++)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(0,n)}(),c=function(){for(var e,n=t.length-1;n>=0;n--)if(e=t.charAt(n),-1!==a.indexOf(e)&&e!==i["exponent-separator"])return t.substring(n+1)}(),l=t.substring(o.length,t.length-c.length),h=t.indexOf(i["exponent-separator"],o.length);-1===h||h>t.length-c.length?(e=l,n=void 0):(e=l.substring(0,h),n=l.substring(h+1));var d=e.indexOf(i["decimal-separator"]);return-1===d?(s=e,r=c):(s=e.substring(0,d),r=e.substring(d+1)),{prefix:o,suffix:c,activePart:l,mantissaPart:e,exponentPart:n,integerPart:s,fractionalPart:r,subpicture:t}},d=function(t){var e,n,r=t.subpicture,o=r.indexOf(i["decimal-separator"]);o!==r.lastIndexOf(i["decimal-separator"])&&(e="D3081"),r.indexOf(i.percent)!==r.lastIndexOf(i.percent)&&(e="D3082"),r.indexOf(i["per-mille"])!==r.lastIndexOf(i["per-mille"])&&(e="D3083"),-1!==r.indexOf(i.percent)&&-1!==r.indexOf(i["per-mille"])&&(e="D3084");var c=!1;for(n=0;n<t.mantissaPart.length;n++){var l=t.mantissaPart.charAt(n);if(-1!==s.indexOf(l)||l===i.digit){c=!0;break}}c||(e="D3085"),-1!==t.activePart.split("").map(function(t){return-1===a.indexOf(t)?"p":"a"}).join("").indexOf("p")&&(e="D3086"),-1!==o?r.charAt(o-1)!==i["grouping-separator"]&&r.charAt(o+1)!==i["grouping-separator"]||(e="D3087"):t.integerPart.charAt(t.integerPart.length-1)===i["grouping-separator"]&&(e="D3088"),-1!==r.indexOf(i["grouping-separator"]+i["grouping-separator"])&&(e="D3089");var h=t.integerPart.indexOf(i.digit);-1!==h&&t.integerPart.substring(0,h).split("").filter(function(t){return s.indexOf(t)>-1}).length>0&&(e="D3090"),-1!==(h=t.fractionalPart.lastIndexOf(i.digit))&&t.fractionalPart.substring(h).split("").filter(function(t){return s.indexOf(t)>-1}).length>0&&(e="D3091");var d="string"==typeof t.exponentPart;if(d&&t.exponentPart.length>0&&(-1!==r.indexOf(i.percent)||-1!==r.indexOf(i["per-mille"]))&&(e="D3092"),d&&(0===t.exponentPart.length||t.exponentPart.split("").filter(function(t){return-1===s.indexOf(t)}).length>0)&&(e="D3093"),e)throw{code:e,stack:(new Error).stack}},u=function(t){var e=function(e,n){for(var r=[],o=e.indexOf(i["grouping-separator"]);-1!==o;){var a=(n?e.substring(0,o):e.substring(o)).split("").filter(function(t){return-1!==s.indexOf(t)||t===i.digit}).length;r.push(a),o=t.integerPart.indexOf(i["grouping-separator"],o+1)}return r},n=e(t.integerPart),r=function(t){if(0===t.length)return 0;for(var e=function(t,n){return 0===n?t:e(n,t%n)},n=t.reduce(e),i=1;i<=t.length;i++)if(-1===t.indexOf(i*n))return 0;return n}(n),o=e(t.fractionalPart,!0),a=t.integerPart.split("").filter(function(t){return-1!==s.indexOf(t)}).length,c=a,l=t.fractionalPart.split(""),h=l.filter(function(t){return-1!==s.indexOf(t)}).length,d=l.filter(function(t){return-1!==s.indexOf(t)||t===i.digit}).length,u="string"==typeof t.exponentPart;0===a&&0===d&&(u?(h=1,d=1):a=1),u&&0===a&&-1!==t.integerPart.indexOf(i.digit)&&(a=1),0===a&&0===h&&(h=1);var p=0;return u&&(p=t.exponentPart.split("").filter(function(t){return-1!==s.indexOf(t)}).length),{integerPartGroupingPositions:n,regularGrouping:r,minimumIntegerPartSize:a,scalingFactor:c,prefix:t.prefix,fractionalPartGroupingPositions:o,minimumFactionalPartSize:h,maximumFactionalPartSize:d,minimumExponentSize:p,suffix:t.suffix,picture:t.subpicture}},p=c.map(l);p.forEach(d);var f,m,g,y,b=p.map(u),_=i["minus-sign"],v=i["zero-digit"],x=i["decimal-separator"],w=i["grouping-separator"];if(1===b.length&&(b.push(JSON.parse(JSON.stringify(b[0]))),b[1].prefix=_+b[1].prefix),m=-1!==(f=t>=0?b[0]:b[1]).picture.indexOf(i.percent)?100*t:-1!==f.picture.indexOf(i["per-mille"])?1e3*t:t,0===f.minimumExponentSize)g=m;else{var M=Math.pow(10,f.scalingFactor),S=Math.pow(10,f.scalingFactor-1);for(g=m,y=0;g<S;)g*=10,y-=1;for(;g>M;)g/=10,y+=1}var k=function(t,e){var n=Math.abs(t).toFixed(e);return"0"!==v&&(n=n.split("").map(function(t){return t>="0"&&t<="9"?s[t.charCodeAt(0)-48]:t}).join("")),n},A=k(at(g,f.maximumFactionalPartSize),f.maximumFactionalPartSize),E=A.indexOf(".");for(-1===E?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);E=A.indexOf(x);var C=f.minimumIntegerPartSize-E,T=f.minimumFactionalPartSize-(A.length-E-1);if(A=(C>0?new Array(C+1).join(v):"")+A,A+=T>0?new Array(T+1).join(v):"",E=A.indexOf(x),f.regularGrouping>0)for(var P=Math.floor((E-1)/f.regularGrouping),O=1;O<=P;O++)A=[A.slice(0,E-O*f.regularGrouping),w,A.slice(E-O*f.regularGrouping)].join("");else f.integerPartGroupingPositions.forEach(function(t){A=[A.slice(0,E-t),w,A.slice(E-t)].join(""),E++});if(E=A.indexOf(x),f.fractionalPartGroupingPositions.forEach(function(t){A=[A.slice(0,t+E+1),w,A.slice(t+E+1)].join("")}),E=A.indexOf(x),-1!==f.picture.indexOf(x)&&E!==A.length-1||(A=A.substring(0,A.length-1)),void 0!==y){var D=k(y,0);(C=f.minimumExponentSize-D.length)>0&&(D=new Array(C+1).join(v)+D),A=A+i["exponent-separator"]+(y<0?_:"")+D}return A=f.prefix+A+f.suffix}}function nt(t,e){if(void 0!==t){if(t=at(t),(e=void 0===e?10:at(e))<2||e>36)throw{code:"D3100",stack:(new Error).stack,value:e};return t.toString(e)}}function it(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 st(t){if(void 0!==t)return Math.abs(t)}function rt(t){if(void 0!==t)return Math.floor(t)}function ot(t){if(void 0!==t)return Math.ceil(t)}function at(t,e){var n;if(void 0!==t){if(e){var i=t.toString().split("e");t=+(i[0]+"e"+(i[1]?+i[1]+e:e))}var s=(n=Math.round(t))-t;return.5===Math.abs(s)&&1===Math.abs(n%2)&&(n-=1),e&&(i=n.toString().split("e"),n=+(i[0]+"e"+(i[1]?+i[1]-e:-e))),Object.is(n,-0)&&(n=0),n}}function ct(t){if(void 0!==t){if(t<0)throw{stack:(new Error).stack,code:"D3060",index:1,value:t};return Math.sqrt(t)}}function lt(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 ht(){return Math.random()}function dt(t){if(void 0!==t){var e=!1;return Array.isArray(t)?1===t.length?e=dt(t[0]):t.length>1&&(e=t.filter(function(t){return dt(t)}).length>0):"string"==typeof t?t.length>0&&(e=!0):b(t)?0!==t&&(e=!0):null!==t&&"object"===o(t)?h.keys(t).length>0&&(e=!0):"boolean"==typeof t&&!0===t&&(e=!0),e}}function ut(t){if(void 0!==t)return!dt(t)}function pt(t,e,n,i){var s=[e],r=A(t);return r>=2&&s.push(n),r>=3&&s.push(i),s}function ft(t,e){var n,i,s,r;return c().w(function(o){for(;;)switch(o.n){case 0:if(void 0!==t){o.n=1;break}return o.a(2,void 0);case 1:n=x(),i=0;case 2:if(!(i<t.length)){o.n=5;break}return s=pt(e,t[i],i,t),o.d(a(e.apply(this,s)),3);case 3:void 0!==(r=o.v)&&n.push(r);case 4:i++,o.n=2;break;case 5:return o.a(2,n)}},d,this)}function mt(t,e){var n,i,s,r;return c().w(function(o){for(;;)switch(o.n){case 0:if(void 0!==t){o.n=1;break}return o.a(2,void 0);case 1:n=x(),i=0;case 2:if(!(i<t.length)){o.n=5;break}return s=t[i],r=pt(e,s,i,t),o.d(a(e.apply(this,r)),3);case 3:dt(o.v)&&n.push(s);case 4:i++,o.n=2;break;case 5:return o.a(2,n)}},u,this)}function gt(t,e){var n,i,s,r,o,l,h;return c().w(function(c){for(;;)switch(c.n){case 0:if(void 0!==t){c.n=1;break}return c.a(2,void 0);case 1:n=!1,s=0;case 2:if(!(s<t.length)){c.n=7;break}if(r=t[s],o=!0,void 0===e){c.n=4;break}return l=pt(e,r,s,t),c.d(a(e.apply(this,l)),3);case 3:h=c.v,o=dt(h);case 4:if(!o){c.n=6;break}if(n){c.n=5;break}i=r,n=!0,c.n=6;break;case 5:throw{stack:(new Error).stack,code:"D3138",index:s};case 6:s++,c.n=2;break;case 7:if(n){c.n=8;break}throw{stack:(new Error).stack,code:"D3139"};case 8:return c.a(2,i)}},p,this)}function yt(){for(var t=[],e=Array.prototype.slice.call(arguments),n=Math.min.apply(Math,e.map(function(t){return Array.isArray(t)?t.length:0})),i=0;i<n;i++){var s=e.map(function(t){return t[i]});t.push(s)}return t}function bt(t,e,n){var i,s,r,o;return c().w(function(c){for(;;)switch(c.n){case 0:if(void 0!==t){c.n=1;break}return c.a(2,void 0);case 1:if(!((s=A(e))<2)){c.n=2;break}throw{stack:(new Error).stack,code:"D3050",index:1};case 2:void 0===n&&t.length>0?(i=t[0],r=1):(i=n,r=0);case 3:if(!(r<t.length)){c.n=5;break}return o=[i,t[r]],s>=3&&o.push(r),s>=4&&o.push(t),c.d(a(e.apply(this,o)),4);case 4:i=c.v,r++,c.n=3;break;case 5:return c.a(2,i)}},f,this)}function _t(t){var e=x();if(Array.isArray(t)){var n=Object.create(null);t.forEach(function(t){_t(t).forEach(function(t){n[t]=!0})}),e=_t(n)}else null===t||"object"!==o(t)||S(t)||h.keys(t).forEach(function(t){return e.push(t)});return e}function vt(t,e){var n;if(Array.isArray(t)){n=x();for(var i=0;i<t.length;i++){var s=vt(t[i],e);void 0!==s&&(Array.isArray(s)?s.forEach(function(t){return n.push(t)}):n.push(s))}}else null!==t&&"object"===o(t)&&Object.prototype.hasOwnProperty.call(t,e)&&!M(t)&&(n=t[e]);return n}function xt(t,e){return void 0===t?e:void 0===e?t:(Array.isArray(t)||(t=x(t)),Array.isArray(e)||(e=[e]),t.concat(e))}function wt(t){return void 0!==t}function Mt(t){var e=x();if(Array.isArray(t))t.forEach(function(t){e=xt(e,Mt(t))});else if(null===t||"object"!==o(t)||S(t))e=t;else{var n,s=i(h.keys(t));try{for(s.s();!(n=s.n()).done;){var r=n.value,a=Object.create(null);a[r]=t[r],e.push(a)}}catch(t){s.e(t)}finally{s.f()}}return e}function St(t){if(void 0!==t){var e=Object.create(null);return t.forEach(function(t){var n,s=i(h.keys(t));try{for(s.s();!(n=s.n()).done;){var r=n.value;e[r]=t[r]}}catch(t){s.e(t)}finally{s.f()}}),e}}function kt(t){if(void 0!==t){if(t.length<=1)return t;for(var e=t.length,n=new Array(e),i=0;i<e;i++)n[e-i-1]=t[i];return n}}function At(t,e){var n,s,r,o,l,d,u;return c().w(function(c){for(;;)switch(c.p=c.n){case 0:n=x(),s=i(h.keys(t)),c.p=1,s.s();case 2:if((r=s.n()).done){c.n=5;break}return o=r.value,l=pt(e,t[o],o,t),c.d(a(e.apply(this,l)),3);case 3:void 0!==(d=c.v)&&n.push(d);case 4:c.n=2;break;case 5:c.n=7;break;case 6:c.p=6,u=c.v,s.e(u);case 7:return c.p=7,s.f(),c.f(7);case 8:return c.a(2,n)}},m,this,[[1,6,7,8]])}function Et(t){throw{code:"D3137",stack:(new Error).stack,message:t||"$error() function evaluated"}}function Ct(t,e){if(!t)throw{code:"D3141",stack:(new Error).stack,message:e||"$assert() statement failed"}}function Tt(t){if(void 0!==t)return null===t?"null":b(t)?"number":"string"==typeof t?"string":"boolean"==typeof t?"boolean":Array.isArray(t)?"array":M(t)?"function":"object"}function Pt(t,e){var n,i,s,r;return c().w(function(o){for(;;)switch(o.n){case 0:if(void 0!==t){o.n=1;break}return o.a(2,void 0);case 1:if(!(t.length<=1)){o.n=2;break}return o.a(2,t);case 2:if(void 0!==e){o.n=4;break}if(v(t)||_(t)){o.n=3;break}throw{stack:(new Error).stack,code:"D3070",index:1};case 3:n=c().m(function t(e,n){return c().w(function(t){for(;;)if(0===t.n)return t.a(2,e>n)},t)}),o.n=5;break;case 4:n=e;case 5:return i=c().m(function t(e,i){var s,r;return c().w(function(t){for(;;)switch(t.n){case 0:return s=c().m(function t(e,i,r){return c().w(function(t){for(;;)switch(t.n){case 0:if(0!==i.length){t.n=1;break}Array.prototype.push.apply(e,r),t.n=6;break;case 1:if(0!==r.length){t.n=2;break}Array.prototype.push.apply(e,i),t.n=6;break;case 2:return t.d(a(n(i[0],r[0])),3);case 3:if(!t.v){t.n=5;break}return e.push(r[0]),t.d(a(s(e,i,r.slice(1))),4);case 4:t.n=6;break;case 5:return e.push(i[0]),t.d(a(s(e,i.slice(1),r)),6);case 6:return t.a(2)}},t)}),r=[],t.d(a(s(r,e,i)),1);case 1:return t.a(2,r)}},t)}),s=c().m(function t(e){var n,r,o;return c().w(function(t){for(;;)switch(t.n){case 0:if(Array.isArray(e)&&!(e.length<=1)){t.n=1;break}return t.a(2,e);case 1:return n=Math.floor(e.length/2),r=e.slice(0,n),o=e.slice(n),t.d(a(s(r)),2);case 2:return r=t.v,t.d(a(s(o)),3);case 3:return o=t.v,t.d(a(i(r,o)),4);case 4:return t.a(2,t.v);case 5:return t.a(2)}},t)}),o.d(a(s(t)),6);case 6:return r=o.v,o.a(2,r)}},g)}function Ot(t){if(void 0!==t){if(t.length<=1)return t;for(var e=new Array(t.length),n=0;n<t.length;n++){var i=Math.floor(Math.random()*(n+1));n!==i&&(e[n]=e[i]),e[i]=t[n]}return e}}function Dt(t){if(void 0!==t){if(!Array.isArray(t)||t.length<=1)return t;for(var e=w(t)?x():[],n=0;n<t.length;n++){for(var i=t[n],s=!1,r=0;r<e.length;r++)if(E(i,e[r])){s=!0;break}s||e.push(i)}return e}}function zt(t,e){var n,s,r,o,l,d,u;return c().w(function(c){for(;;)switch(c.p=c.n){case 0:n=Object.create(null),s=i(h.keys(t)),c.p=1,s.s();case 2:if((r=s.n()).done){c.n=5;break}return o=r.value,l=t[o],d=pt(e,l,o,t),c.d(a(e.apply(this,d)),3);case 3:dt(c.v)&&(n[o]=l);case 4:c.n=2;break;case 5:c.n=7;break;case 6:c.p=6,u=c.v,s.e(u);case 7:return c.p=7,s.f(),c.f(7);case 8:return 0===h.keys(n).length&&(n=void 0),c.a(2,n)}},y,this,[[1,6,7,8]])}return{sum:T,count:P,max:O,min:D,average:z,string:I,substring:R,substringBefore:j,substringAfter:L,lowercase:F,uppercase:N,length:H,trim:B,pad:G,match:W,contains:Y,replace:U,split:J,join:tt,formatNumber:et,formatBase:nt,number:it,floor:rt,ceil:ot,round:at,abs:st,sqrt:ct,power:lt,random:ht,boolean:dt,not:ut,map:ft,zip:yt,filter:mt,single:gt,foldLeft:bt,sift:zt,keys:_t,lookup:vt,append:xt,exists:wt,spread:Mt,merge:St,reverse:kt,each:At,error:Et,assert:Ct,type:Tt,sort:Pt,shuffle:Ot,distinct:Dt,base64encode:$,base64decode:X,encodeUrlComponent:q,encodeUrl:K,decodeUrlComponent:Q,decodeUrl:Z}}();e.exports=d}).call(this)}).call(this,void 0!==ns?ns:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils":6}],3:[function(t,e,n){function i(t){var e=Object(t),n=[];for(var i in e)n.unshift(i);return function t(){for(;n.length;)if((i=n.pop())in e)return t.value=i,t.done=!1,t;return t.done=!0,t}}function s(t){return s="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},s(t)}function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e){n&&(t=n);var i=0,s=function(){};return{s:s,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}function o(t,e){if(t){if("string"==typeof t)return a(t,e);var n={}.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)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function c(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(s(t)+" is not iterable")}function l(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var t,e,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",s=n.toStringTag||"@@toStringTag";function r(n,i,s,r){var c=i&&i.prototype instanceof a?i:a,l=Object.create(c.prototype);return h(l,"_invoke",function(n,i,s){var r,a,c,l=0,h=s||[],d=!1,u={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,a=0,c=t,u.n=n,o}};function p(n,i){for(a=n,c=i,e=0;!d&&l&&!s&&e<h.length;e++){var s,r=h[e],p=u.p,f=r[2];n>3?(s=f===i)&&(c=r[(a=r[4])?5:(a=3,3)],r[4]=r[5]=t):r[0]<=p&&((s=n<2&&p<r[1])?(a=0,u.v=i,u.n=r[1]):p<f&&(s=n<3||r[0]>i||i>f)&&(r[4]=n,r[5]=i,u.n=f,a=0))}if(s||n>1)return o;throw d=!0,i}return function(s,h,f){if(l>1)throw TypeError("Generator is already running");for(d&&1===h&&p(h,f),a=h,c=f;(e=a<2?t:c)||!d;){r||(a?a<3?(a>1&&(u.n=-1),p(a,c)):u.n=c:u.v=c);try{if(l=2,r){if(a||(s="next"),e=r[s]){if(!(e=e.call(r,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=r.return)&&e.call(r),a<2&&(c=TypeError("The iterator does not provide a '"+s+"' method"),a=1);r=t}else if((e=(d=u.n<0)?c:n.call(i,u))!==o)break}catch(e){r=t,a=1,c=e}finally{l=1}}return{value:e,done:d}}}(n,s,r),!0),l}var o={};function a(){}function c(){}function d(){}e=Object.getPrototypeOf;var u=[][i]?e(e([][i]())):(h(e={},i,function(){return this}),e),p=d.prototype=a.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,h(t,s,"GeneratorFunction")),t.prototype=Object.create(p),t}return c.prototype=d,h(p,"constructor",d),h(d,"constructor",c),c.displayName="GeneratorFunction",h(d,s,"GeneratorFunction"),h(p),h(p,s,"Generator"),h(p,i,function(){return this}),h(p,"toString",function(){return"[object Generator]"}),(l=function(){return{w:r,m:f}})()}function h(t,e,n,i){var s=Object.defineProperty;try{s({},"",{})}catch(t){s=0}h=function(t,e,n,i){function r(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?s?s(t,e,{value:n,enumerable:!i,configurable:!i,writable:!i}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},h(t,e,n,i)}var d=t("./datetime"),u=t("./functions"),p=t("./utils"),f=t("./parser"),m=t("./signature"),g=function(){var t=l().m(V),e=l().m(Y),n=l().m(U),o=l().m($),a=l().m(X),h=l().m(q),g=l().m(K),y=l().m(Q),b=l().m(ct),_=l().m(dt),v=l().m(ft),x=l().m(mt),w=l().m(gt),M=l().m(_t),S=l().m(wt),k=l().m(Mt),A=l().m(St),E=l().m(kt),C=l().m(Et),T=l().m(Tt),P=l().m(Dt),O=l().m(Rt),D=p.isNumeric,z=p.isArrayOfStrings,I=p.isArrayOfNumbers,R=p.createSequence,j=p.isSequence,L=p.isFunction,F=p.isLambda,N=p.isIterable,H=p.getFunctionArity,B=p.isDeepEqual,G=Lt(null);function V(e,n,i){var s,r,o,a,h;return l().w(function(t){for(;;)switch(t.n){case 0:(r=i.lookup("__evaluate_entry"))&&r(e,n,i),h=e.type,t.n="path"===h?1:"binary"===h?3:"unary"===h?5:"name"===h?7:"string"===h||"number"===h||"value"===h?8:"wildcard"===h?9:"descendant"===h?10:"parent"===h?11:"condition"===h?12:"block"===h?14:"bind"===h?16:"regex"===h?18:"function"===h?19:"variable"===h?21:"lambda"===h?22:"partial"===h?23:"apply"===h?25:"transform"===h?27:28;break;case 1:return t.d(c(Y(e,n,i)),2);case 2:return s=t.v,t.a(3,28);case 3:return t.d(c(K(e,n,i)),4);case 4:return s=t.v,t.a(3,28);case 5:return t.d(c(Q(e,n,i)),6);case 6:return s=t.v,t.a(3,28);case 7:return s=Z(e,n),t.a(3,28);case 8:return s=J(e),t.a(3,28);case 9:return s=tt(e,n),t.a(3,28);case 10:return s=nt(e,n),t.a(3,28);case 11:return s=i.lookup(e.slot.label),t.a(3,28);case 12:return t.d(c(mt(e,n,i)),13);case 13:return s=t.v,t.a(3,28);case 14:return t.d(c(gt(e,n,i)),15);case 15:return s=t.v,t.a(3,28);case 16:return t.d(c(ft(e,n,i)),17);case 17:return s=t.v,t.a(3,28);case 18:return s=yt(e),t.a(3,28);case 19:return t.d(c(Mt(e,n,i)),20);case 20:return s=t.v,t.a(3,28);case 21:return s=bt(e,n,i),t.a(3,28);case 22:return s=At(e,n,i),t.a(3,28);case 23:return t.d(c(Et(e,n,i)),24);case 24:return s=t.v,t.a(3,28);case 25:return t.d(c(wt(e,n,i)),26);case 26:return s=t.v,t.a(3,28);case 27:return s=vt(e,n,i),t.a(3,28);case 28:if(!i.async||null!=s&&"function"==typeof s.then||(s=Promise.resolve(s)),!i.async||"function"!=typeof s.then||!e.nextFunction||"function"!=typeof s[e.nextFunction]){t.n=29;break}t.n=31;break;case 29:return t.n=30,s;case 30:s=t.v;case 31:if(!Object.prototype.hasOwnProperty.call(e,"predicate")){t.n=35;break}o=0;case 32:if(!(o<e.predicate.length)){t.n=35;break}return t.d(c(q(e.predicate[o].expr,s,i)),33);case 33:s=t.v;case 34:o++,t.n=32;break;case 35:if("path"===e.type||!Object.prototype.hasOwnProperty.call(e,"group")){t.n=37;break}return t.d(c(dt(e.group,s,i)),36);case 36:s=t.v;case 37:return(a=i.lookup("__evaluate_exit"))&&a(e,n,i,s),s&&j(s)&&!s.tupleStream&&(e.keepArray&&(s.keepSingleton=!0),0===s.length?s=void 0:1===s.length&&(s=s.keepSingleton?s:s[0])),t.a(2,s)}},t)}function Y(t,n,i){var s,r,o,a,h,d;return l().w(function(e){for(;;)switch(e.n){case 0:s=Array.isArray(n)&&"variable"!==t.steps[0].type?n:R(n),o=!1,a=void 0,h=0;case 1:if(!(h<t.steps.length)){e.n=10;break}if((d=t.steps[h]).tuple&&(o=!0),0!==h||!d.consarray){e.n=3;break}return e.d(c(V(d,s,i)),2);case 2:r=e.v,e.n=7;break;case 3:if(!o){e.n=5;break}return e.d(c(X(d,s,a,i)),4);case 4:a=e.v,e.n=7;break;case 5:return e.d(c(U(d,s,i,h===t.steps.length-1)),6);case 6:r=e.v;case 7:if(o||void 0!==r&&0!==r.length){e.n=8;break}return e.a(3,10);case 8:void 0===d.focus&&(s=r);case 9:h++,e.n=1;break;case 10:if(o)if(t.tuple)r=a;else for(r=R(),h=0;h<a.length;h++)r.push(a[h]["@"]);if(t.keepSingletonArray&&(Array.isArray(r)&&r.cons&&!r.sequence&&(r=R(r)),r.keepSingleton=!0),!Object.prototype.hasOwnProperty.call(t,"group")){e.n=12;break}return e.d(c(dt(t.group,o?a:r,i)),11);case 11:r=e.v;case 12:return e.a(2,r)}},e)}function W(t,e){var n,i=Lt(t),s=r(p.keys(e));try{for(s.s();!(n=s.n()).done;){var o=n.value;i.bind(o,e[o])}}catch(t){s.e(t)}finally{s.f()}return i}function U(t,e,i,s){var r,o,a,h,d;return l().w(function(n){for(;;)switch(n.n){case 0:if("sort"!==t.type){n.n=4;break}return n.d(c(_t(t,e,i)),1);case 1:if(r=n.v,!t.stages){n.n=3;break}return n.d(c($(t.stages,r,i)),2);case 2:r=n.v;case 3:return n.a(2,r);case 4:r=R(),o=0;case 5:if(!(o<e.length)){n.n=12;break}return n.d(c(V(t,e[o],i)),6);case 6:if(a=n.v,!t.stages){n.n=10;break}h=0;case 7:if(!(h<t.stages.length)){n.n=10;break}return n.d(c(q(t.stages[h].expr,a,i)),8);case 8:a=n.v;case 9:h++,n.n=7;break;case 10:void 0!==a&&r.push(a);case 11:o++,n.n=5;break;case 12:return d=R(),s&&1===r.length&&Array.isArray(r[0])&&!j(r[0])?d=r[0]:Array.prototype.forEach.call(r,function(t){!Array.isArray(t)||t.cons?d.push(t):Array.prototype.forEach.call(t,function(t){return d.push(t)})}),n.a(2,d)}},n)}function $(t,e,n){var i,s,r,a,h;return l().w(function(o){for(;;)switch(o.n){case 0:i=e,s=0;case 1:if(!(s<t.length)){o.n=6;break}r=t[s],h=r.type,o.n="filter"===h?2:"index"===h?4:5;break;case 2:return o.d(c(q(r.expr,i,n)),3);case 3:return i=o.v,o.a(3,5);case 4:for(a=0;a<i.length;a++)i[a][r.value]=a;return o.a(3,5);case 5:s++,o.n=1;break;case 6:return o.a(2,i)}},o)}function X(t,e,n,i){var s,r,o,h,d,u,p,f;return l().w(function(a){for(;;)switch(a.n){case 0:if("sort"!==t.type){a.n=7;break}if(!n){a.n=2;break}return a.d(c(_t(t,n,i)),1);case 1:s=a.v,a.n=4;break;case 2:return a.d(c(_t(t,e,i)),3);case 3:for(r=a.v,(s=R()).tupleStream=!0,o=0;o<r.length;o++)(h={"@":r[o]})[t.index]=o,s.push(h);case 4:if(!t.stages){a.n=6;break}return a.d(c($(t.stages,s,i)),5);case 5:s=a.v;case 6:return a.a(2,s);case 7:(s=R()).tupleStream=!0,d=i,void 0===n&&(n=e.map(function(t){return{"@":t}})),u=0;case 8:if(!(u<n.length)){a.n=11;break}return d=W(i,n[u]),a.d(c(V(t,n[u]["@"],d)),9);case 9:if(void 0!==(p=a.v))for(Array.isArray(p)||(p=[p]),f=0;f<p.length;f++)h=Object.create(null),Object.assign(h,n[u]),p.tupleStream?Object.assign(h,p[f]):(t.focus?(h[t.focus]=p[f],h["@"]=n[u]["@"]):h["@"]=p[f],t.index&&(h[t.index]=f),t.ancestor&&(h[t.ancestor.label]=n[u]["@"])),s.push(h);case 10:u++,a.n=8;break;case 11:if(!t.stages){a.n=13;break}return a.d(c($(t.stages,s,i)),12);case 12:s=a.v;case 13:return a.a(2,s)}},a)}function q(t,e,n){var i,s,r,o,a,d;return l().w(function(l){for(;;)switch(l.n){case 0:if(i=R(),e&&e.tupleStream&&(i.tupleStream=!0),Array.isArray(e)||(e=R(e)),"number"!==t.type){l.n=1;break}(s=Math.floor(t.value))<0&&(s=e.length+s),void 0!==(r=e[s])&&(Array.isArray(r)?i=r:i.push(r)),l.n=5;break;case 1:s=0;case 2:if(!(s<e.length)){l.n=5;break}return r=e[s],o=r,a=n,e.tupleStream&&(o=r["@"],a=W(n,r)),l.d(c(V(t,o,a)),3);case 3:d=l.v,D(d)&&(d=[d]),I(d)?Array.prototype.forEach.call(d,function(t){var n=Math.floor(t);n<0&&(n=e.length+n),n===s&&i.push(r)}):u.boolean(d)&&i.push(r);case 4:s++,l.n=2;break;case 5:return l.a(2,i)}},h)}function K(t,e,n){var i,s,r,o,a,h,d,u;return l().w(function(p){for(;;)switch(p.p=p.n){case 0:return p.d(c(V(t.lhs,e,n)),1);case 1:if(s=p.v,r=t.value,o=l().m(function i(){return l().w(function(i){for(;;)switch(i.n){case 0:return i.d(c(V(t.rhs,e,n)),1);case 1:return i.a(2,i.v)}},i)}),"and"!==r&&"or"!==r){p.n=5;break}return p.p=2,p.d(c(ct(s,o,r)),3);case 3:return p.a(2,p.v);case 4:throw p.p=4,(h=p.v).position=t.position,h.token=r,h;case 5:return p.d(c(o()),6);case 6:a=p.v,p.p=7,d=r,p.n="+"===d||"-"===d||"*"===d||"/"===d||"%"===d?8:"="===d||"!="===d?9:"<"===d||"<="===d||">"===d||">="===d?10:"&"===d?11:".."===d?12:"in"===d?13:14;break;case 8:return i=st(s,a,r),p.a(3,14);case 9:return i=rt(s,a,r),p.a(3,14);case 10:return i=ot(s,a,r),p.a(3,14);case 11:return i=ht(s,a),p.a(3,14);case 12:return i=pt(s,a),p.a(3,14);case 13:return i=at(s,a),p.a(3,14);case 14:p.n=16;break;case 15:throw p.p=15,(u=p.v).position=t.position,u.token=r,u;case 16:return p.a(2,i)}},g,null,[[7,15],[2,4]])}function Q(t,e,n){var i,s,r,o,a;return l().w(function(l){for(;;)switch(l.n){case 0:a=t.value,l.n="-"===a?1:"["===a?6:"{"===a?11:13;break;case 1:return l.d(c(V(t.expression,e,n)),2);case 2:if(void 0!==(i=l.v)){l.n=3;break}i=void 0,l.n=5;break;case 3:if(!D(i)){l.n=4;break}i=-i,l.n=5;break;case 4:throw{code:"D1002",stack:(new Error).stack,position:t.position,token:t.value,value:i};case 5:return l.a(3,13);case 6:i=[],s=0;case 7:if(!(s<t.expressions.length)){l.n=10;break}return r=t.expressions[s],l.d(c(V(r,e,n)),8);case 8:void 0!==(o=l.v)&&("["===r.value?i.push(o):i=u.append(i,o));case 9:s++,l.n=7;break;case 10:return t.consarray&&Object.defineProperty(i,"cons",{enumerable:!1,configurable:!1,value:!0}),l.a(3,13);case 11:return l.d(c(dt(t,e,n)),12);case 12:return i=l.v,l.a(3,13);case 13:return l.a(2,i)}},y)}function Z(t,e,n){return u.lookup(e,t.value)}function J(t){return t.value}function tt(t,e){var n=R();return Array.isArray(e)&&e.outerWrapper&&e.length>0&&(e=e[0]),null===e||"object"!==s(e)||L(e)||p.keys(e).forEach(function(t){var i=e[t];Array.isArray(i)?(i=et(i),n=u.append(n,i)):n.push(i)}),n}function et(t,e){return void 0===e&&(e=[]),Array.isArray(t)?Array.prototype.forEach.call(t,function(t){et(t,e)}):e.push(t),e}function nt(t,e){var n,i=R();return void 0!==e&&(it(e,i),n=1===i.length?i[0]:i),n}function it(t,e){Array.isArray(t)||e.push(t),Array.isArray(t)?Array.prototype.forEach.call(t,function(t){it(t,e)}):null===t||"object"!==s(t)||L(t)||p.keys(t).forEach(function(n){it(t[n],e)})}function st(t,e,n){var i;if(void 0!==t&&!D(t))throw{code:"T2001",stack:(new Error).stack,value:t};if(void 0!==e&&!D(e))throw{code:"T2002",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return i;switch(n){case"+":i=t+e;break;case"-":i=t-e;break;case"*":i=t*e;break;case"/":i=t/e;break;case"%":i=t%e}return i}function rt(t,e,n){var i,r=s(t),o=s(e);if("undefined"===r||"undefined"===o)return!1;switch(n){case"=":i=B(t,e);break;case"!=":i=!B(t,e)}return i}function ot(t,e,n){var i,r=s(t),o=s(e);if("undefined"!==r&&"string"!==r&&"number"!==r||"undefined"!==o&&"string"!==o&&"number"!==o)throw{code:"T2010",stack:(new Error).stack,value:"string"!==r&&"number"!==r?t:e};if("undefined"!==r&&"undefined"!==o){if(r!==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 at(t,e){var n=!1;if(void 0===t||void 0===e)return!1;Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)if(e[i]===t){n=!0;break}return n}function ct(t,e,n){var i,s,r,o,a,h,d;return l().w(function(l){for(;;)switch(l.n){case 0:s=lt(t),r=n,l.n="and"===r?1:"or"===r?4:7;break;case 1:if(!(o=s)){l.n=3;break}return a=lt,l.d(c(e()),2);case 2:o=a(l.v);case 3:return i=o,l.a(3,7);case 4:if(h=s){l.n=6;break}return d=lt,l.d(c(e()),5);case 5:h=d(l.v);case 6:return i=h,l.a(3,7);case 7:return l.a(2,i)}},b)}function lt(t){var e=u.boolean(t);return void 0!==e&&e}function ht(t,e){var n="",i="";return void 0!==t&&(n=u.string(t)),void 0!==e&&(i=u.string(e)),n.concat(i)}function dt(t,e,n){var s,r,o,a,h,d,p,f,m,g,y,b,v,x,w;return l().w(function(l){for(;;)switch(l.n){case 0:s=Object.create(null),r=Object.create(null),o=!(!e||!e.tupleStream),Array.isArray(e)||(e=R(e)),0===e.length&&e.push(void 0),a=0;case 1:if(!(a<e.length)){l.n=10;break}h=e[a],d=o?W(n,h):n,p=0;case 2:if(!(p<t.lhs.length)){l.n=9;break}return f=t.lhs[p],l.d(c(V(f[0],o?h["@"]:h,d)),3);case 3:if("string"==typeof(m=l.v)||void 0===m){l.n=4;break}throw{code:"T1003",stack:(new Error).stack,position:t.position,value:m};case 4:if(void 0===m){l.n=8;break}if("_jsonata_lambda"!==m&&"_jsonata_function"!==m){l.n=5;break}throw{code:"D1013",stack:(new Error).stack,position:t.position,value:m};case 5:if(g={data:h,exprIndex:p},!Object.prototype.hasOwnProperty.call(r,m)){l.n=7;break}if(r[m].exprIndex===p){l.n=6;break}throw{code:"D1009",stack:(new Error).stack,position:t.position,value:m};case 6:r[m].data=u.append(r[m].data,h),l.n=8;break;case 7:r[m]=g;case 8:p++,l.n=2;break;case 9:a++,l.n=1;break;case 10:x=i(r);case 11:if((w=x()).done){l.n=13;break}return m=w.value,g=r[m],y=g.data,d=n,o&&(b=ut(g.data),y=b["@"],delete b["@"],d=W(n,b)),l.d(c(V(t.lhs[g.exprIndex][1],y,d)),12);case 12:void 0!==(v=l.v)&&(s[m]=v),l.n=11;break;case 13:return l.a(2,s)}},_)}function ut(t){if(!Array.isArray(t))return t;var e=Object.create(null);Object.assign(e,t[0]);for(var n=1;n<t.length;n++){var i,s=r(p.keys(t[n]));try{for(s.s();!(i=s.n()).done;){var o=i.value;e[o]=u.append(e[o],t[n][o])}}catch(t){s.e(t)}finally{s.f()}}return e}function pt(t,e){var n;if(void 0!==t&&!Number.isInteger(t))throw{code:"T2003",stack:(new Error).stack,value:t};if(void 0!==e&&!Number.isInteger(e))throw{code:"T2004",stack:(new Error).stack,value:e};if(void 0===t||void 0===e)return n;if(t>e)return n;var i=e-t+1;if(i>1e7)throw{code:"D2014",stack:(new Error).stack,value:i};n=new Array(i);for(var s=t,r=0;s<=e;s++,r++)n[r]=s;return n.sequence=!0,n}function ft(t,e,n){var i;return l().w(function(s){for(;;)switch(s.n){case 0:return s.d(c(V(t.rhs,e,n)),1);case 1:return i=s.v,n.bind(t.lhs.value,i),s.a(2,i)}},v)}function mt(t,e,n){var i,s;return l().w(function(r){for(;;)switch(r.n){case 0:return r.d(c(V(t.condition,e,n)),1);case 1:if(s=r.v,!u.boolean(s)){r.n=3;break}return r.d(c(V(t.then,e,n)),2);case 2:i=r.v,r.n=5;break;case 3:if(void 0===t.else){r.n=5;break}return r.d(c(V(t.else,e,n)),4);case 4:i=r.v;case 5:return r.a(2,i)}},x)}function gt(t,e,n){var i,s,r;return l().w(function(o){for(;;)switch(o.n){case 0:s=Lt(n),r=0;case 1:if(!(r<t.expressions.length)){o.n=4;break}return o.d(c(V(t.expressions[r],e,s)),2);case 2:i=o.v;case 3:r++,o.n=1;break;case 4:return o.a(2,i)}},w)}function yt(t){var e=new Ht.RegexEngine(t.value),n=function(i,s){var r;e.lastIndex=s||0;var o=e.exec(i);if(null!==o){if(r={match:o[0],start:o.index,end:o.index+o[0].length,groups:[]},o.length>1)for(var a=1;a<o.length;a++)r.groups.push(o[a]);r.next=function(){if(!(e.lastIndex>=i.length)){var s=n(i,e.lastIndex);if(s&&""===s.match)throw{code:"D1004",stack:(new Error).stack,position:t.position,value:t.value.source};return s}}}return r};return n}function bt(t,e,n){return""===t.value?e&&e.outerWrapper?e[0]:e:n.lookup(t.value)}function _t(t,e,n){var i,r,o,a,h;return l().w(function(d){for(;;)switch(d.n){case 0:return r=e,o=!!e.tupleStream,a=l().m(function e(i,r){var a,h,d,u,p,f,m,g,y;return l().w(function(e){for(;;)switch(e.n){case 0:a=0,h=0;case 1:if(!(0===a&&h<t.terms.length)){e.n=11;break}return d=t.terms[h],u=i,p=n,o&&(u=i["@"],p=W(n,i)),e.d(c(V(d.expression,u,p)),2);case 2:return f=e.v,u=r,p=n,o&&(u=r["@"],p=W(n,r)),e.d(c(V(d.expression,u,p)),3);case 3:if(m=e.v,g=s(f),y=s(m),"undefined"!==g){e.n=4;break}return a="undefined"===y?0:1,e.a(3,10);case 4:if("undefined"!==y){e.n=5;break}return a=-1,e.a(3,10);case 5:if(!("string"!==g&&"number"!==g||"string"!==y&&"number"!==y)){e.n=6;break}throw{code:"T2008",stack:(new Error).stack,position:t.position,value:"string"!==g&&"number"!==g?f:m};case 6:if(g===y){e.n=7;break}throw{code:"T2007",stack:(new Error).stack,position:t.position,value:f,value2:m};case 7:if(f!==m){e.n=8;break}return e.a(3,10);case 8:a=f<m?-1:1;case 9:!0===d.descending&&(a=-a);case 10:h++,e.n=1;break;case 11:return e.a(2,1===a)}},e)}),h={environment:n,input:e},d.d(c(u.sort.apply(h,[r,a])),1);case 1:return i=d.v,d.a(2,i)}},M)}function vt(t,e,n){var i=l().m(function e(i){var o,a,h,d,u,f,m,g,y,b,_,v,x;return l().w(function(e){for(;;)switch(e.n){case 0:if(void 0!==i){e.n=1;break}return e.a(2,void 0);case 1:if(o=n.lookup("clone"),L(o)){e.n=2;break}throw{code:"T2013",stack:(new Error).stack,position:t.position};case 2:return e.d(c(St(o,[i],null,n)),3);case 3:return a=e.v,e.d(c(V(t.pattern,a,n)),4);case 4:if(void 0===(h=e.v)){e.n=12;break}Array.isArray(h)||(h=[h]),d=0;case 5:if(!(d<h.length)){e.n=12;break}return u=h[d],e.d(c(V(t.update,u,n)),6);case 6:if(f=e.v,"undefined"===(m=s(f))){e.n=8;break}if("object"===m&&null!==f&&!Array.isArray(f)){e.n=7;break}throw{code:"T2011",stack:(new Error).stack,position:t.update.position,value:f};case 7:g=r(p.keys(f));try{for(g.s();!(y=g.n()).done;)b=y.value,u[b]=f[b]}catch(t){g.e(t)}finally{g.f()}case 8:if(void 0===t.delete){e.n=11;break}return e.d(c(V(t.delete,u,n)),9);case 9:if(void 0===(_=e.v)){e.n=11;break}if(v=_,Array.isArray(_)||(_=[_]),z(_)){e.n=10;break}throw{code:"T2012",stack:(new Error).stack,position:t.delete.position,value:v};case 10:for(x=0;x<_.length;x++)"object"===s(u)&&null!==u&&delete u[_[x]];case 11:d++,e.n=5;break;case 12:return e.a(2,a)}},e)});return It(i,"<(oa):o>")}var xt=f("function($f, $g) { function($x){ $g($f($x)) } }");function wt(t,e,n){var i,s,r,o;return l().w(function(a){for(;;)switch(a.n){case 0:return a.d(c(V(t.lhs,e,n)),1);case 1:if(s=a.v,"function"!==t.rhs.type){a.n=3;break}return a.d(c(Mt(t.rhs,e,n,{context:s})),2);case 2:i=a.v,a.n=10;break;case 3:return a.d(c(V(t.rhs,e,n)),4);case 4:if(r=a.v,L(r)){a.n=5;break}throw{code:"T2006",stack:(new Error).stack,position:t.position,value:r};case 5:if(!L(s)){a.n=8;break}return a.d(c(V(xt,null,n)),6);case 6:return o=a.v,a.d(c(St(o,[s,r],null,n)),7);case 7:i=a.v,a.n=10;break;case 8:return a.d(c(St(r,[s],null,n)),9);case 9:i=a.v;case 10:return a.a(2,i)}},S)}function Mt(t,e,n,i){var r,o,a,h,d,u,p;return l().w(function(f){for(;;)switch(f.p=f.n){case 0:return f.d(c(V(t.procedure,e,n)),1);case 1:if(void 0!==(o=f.v)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){f.n=2;break}throw{code:"T1005",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 2:a=[],void 0!==i&&a.push(i.context),h=l().m(function i(){var s,r;return l().w(function(i){for(;;)switch(i.n){case 0:return i.d(c(V(t.arguments[d],e,n)),1);case 1:s=i.v,L(s)?(r=l().m(function t(){var e,i,r,o=arguments;return l().w(function(t){for(;;)switch(t.n){case 0:for(e=o.length,i=new Array(e),r=0;r<e;r++)i[r]=o[r];return t.d(c(St(s,i,null,n)),1);case 1:return t.a(2,t.v)}},t)}),r.arity=H(s),a.push(r)):a.push(s);case 2:return i.a(2)}},i)}),d=0;case 3:if(!(d<t.arguments.length)){f.n=5;break}return f.d(c(h()),4);case 4:d++,f.n=3;break;case 5:return u="path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value,f.p=6,"object"===s(o)&&(o.token=u,o.position=t.position),f.d(c(St(o,a,e,n)),7);case 7:r=f.v,f.n=9;break;case 8:throw f.p=8,(p=f.v).position||(p.position=t.position),p.token||(p.token=u),p;case 9:return f.a(2,r)}},k,null,[[6,8]])}function St(t,e,n,i){var s,r,o,a,h;return l().w(function(l){for(;;)switch(l.n){case 0:return l.d(c(kt(t,e,n,i)),1);case 1:s=l.v;case 2:if(!F(s)||!0!==s.thunk){l.n=9;break}return l.d(c(V(s.body.procedure,s.input,s.environment)),3);case 3:r=l.v,"variable"===s.body.procedure.type&&(r.token=s.body.procedure.value),r.position=s.body.procedure.position,o=[],a=0;case 4:if(!(a<s.body.arguments.length)){l.n=7;break}return h=o,l.d(c(V(s.body.arguments[a],s.input,s.environment)),5);case 5:h.push.call(h,l.v);case 6:a++,l.n=4;break;case 7:return l.d(c(kt(r,o,n,i)),8);case 8:s=l.v,l.n=2;break;case 9:return l.a(2,s)}},A)}function kt(t,e,n,i){var s,r,o,a;return l().w(function(l){for(;;)switch(l.p=l.n){case 0:if(l.p=0,r=e,t&&(r=Ct(t.signature,e,n)),!F(t)){l.n=2;break}return l.d(c(Tt(t,r)),1);case 1:s=l.v,l.n=9;break;case 2:if(!t||!0!==t._jsonata_function){l.n=5;break}if(o={environment:i,input:n},s=t.implementation.apply(o,r),!N(s)){l.n=4;break}return l.d(c(s),3);case 3:s=l.v;case 4:l.n=9;break;case 5:if("function"!=typeof t){l.n=8;break}if(s=t.apply(n,r),!N(s)){l.n=7;break}return l.d(c(s),6);case 6:s=l.v;case 7:l.n=9;break;case 8:throw{code:"T1006",stack:(new Error).stack};case 9:l.n=11;break;case 10:throw l.p=10,a=l.v,t&&(void 0===a.token&&void 0!==t.token&&(a.token=t.token),a.position=t.position||a.position),a;case 11:return l.a(2,s)}},E,null,[[0,10]])}function At(t,e,n){var i={_jsonata_lambda:!0,input:e,environment:n,arguments:t.arguments,signature:t.signature,body:t.body};return!0===t.thunk&&(i.thunk=!0),i.apply=l().m(function t(n,s){return l().w(function(t){for(;;)switch(t.n){case 0:return t.d(c(St(i,s,e,n.environment)),1);case 1:return t.a(2,t.v)}},t)}),i}function Et(t,e,n){var i,s,r,o,a,h;return l().w(function(l){for(;;)switch(l.n){case 0:s=[],r=0;case 1:if(!(r<t.arguments.length)){l.n=5;break}if("operator"!==(o=t.arguments[r]).type||"?"!==o.value){l.n=2;break}s.push(o),l.n=4;break;case 2:return h=s,l.d(c(V(o,e,n)),3);case 3:h.push.call(h,l.v);case 4:r++,l.n=1;break;case 5:return l.d(c(V(t.procedure,e,n)),6);case 6:if(void 0!==(a=l.v)||"path"!==t.procedure.type||!n.lookup(t.procedure.steps[0].value)){l.n=7;break}throw{code:"T1007",stack:(new Error).stack,position:t.position,token:t.procedure.steps[0].value};case 7:if(!F(a)){l.n=8;break}i=Pt(a,s),l.n=11;break;case 8:if(!a||!0!==a._jsonata_function){l.n=9;break}i=Ot(a.implementation,s),l.n=11;break;case 9:if("function"!=typeof a){l.n=10;break}i=Ot(a,s),l.n=11;break;case 10:throw{code:"T1008",stack:(new Error).stack,position:t.position,token:"path"===t.procedure.type?t.procedure.steps[0].value:t.procedure.value};case 11:return l.a(2,i)}},C)}function Ct(t,e,n){return void 0===t?e:t.validate(e,n)}function Tt(t,e){var n,i;return l().w(function(s){for(;;)switch(s.n){case 0:if(i=Lt(t.environment),Array.prototype.forEach.call(t.arguments,function(t,n){i.bind(t.value,e[n])}),"function"!=typeof t.body){s.n=2;break}return s.d(c(Dt(t.body,i)),1);case 1:n=s.v,s.n=4;break;case 2:return s.d(c(V(t.body,t.input,i)),3);case 3:n=s.v;case 4:return s.a(2,n)}},T)}function Pt(t,e){var n=Lt(t.environment),i=[];return Array.prototype.forEach.call(t.arguments,function(t,s){var r=e[s];r&&"operator"===r.type&&"?"===r.value?i.push(t):n.bind(t.value,r)}),{_jsonata_lambda:!0,input:t.input,environment:n,arguments:i,body:t.body}}function Ot(t,e){var n=zt(t),i="function("+(n=n.map(function(t){return"$"+t.trim()})).join(", ")+"){ _ }",s=f(i);return s.body=t,Pt(s,e)}function Dt(t,e){var n,i,s,r;return l().w(function(o){for(;;)switch(o.n){case 0:if(n=zt(t),i=n.map(function(t){return e.lookup(t.trim())}),s={environment:e},r=t.apply(s,i),!N(r)){o.n=2;break}return o.d(c(r),1);case 1:r=o.v;case 2:return o.a(2,r)}},P)}function zt(t){var e=t.toString();return/\(([^)]*)\)/.exec(e)[1].split(",")}function It(t,e){var n={_jsonata_function:!0,implementation:t};return void 0!==e&&(n.signature=m(e)),n}function Rt(t,e){var n,i,s,r,o;return l().w(function(a){for(;;)switch(a.p=a.n){case 0:if(void 0!==t){a.n=1;break}return a.a(2,void 0);case 1:n=this.input,void 0!==e&&(n=e,Array.isArray(n)&&!j(n)&&((n=R(n)).outerWrapper=!0)),a.p=2,i=f(t,!1),a.n=4;break;case 3:throw a.p=3,Nt(r=a.v),{stack:(new Error).stack,code:"D3120",value:r.message,error:r};case 4:return a.p=4,a.d(c(V(i,n,this.environment)),5);case 5:s=a.v,a.n=7;break;case 6:throw a.p=6,Nt(o=a.v),{stack:(new Error).stack,code:"D3121",value:o.message,error:o};case 7:return a.a(2,s)}},O,this,[[4,6],[2,3]])}function jt(t){if(void 0!==t)return JSON.parse(u.string(t))}function Lt(t){var e=Object.create(null);return{bind:function(t,n){e[t]=n},lookup:function(n){var i;return Object.prototype.hasOwnProperty.call(e,n)?i=e[n]:t&&(i=t.lookup(n)),i},timestamp:t?t.timestamp:null,async:!!t&&t.async,global:t?t.global:{ancestry:[null]}}}G.bind("sum",It(u.sum,"<a<n>:n>")),G.bind("count",It(u.count,"<a:n>")),G.bind("max",It(u.max,"<a<n>:n>")),G.bind("min",It(u.min,"<a<n>:n>")),G.bind("average",It(u.average,"<a<n>:n>")),G.bind("string",It(u.string,"<x-b?:s>")),G.bind("substring",It(u.substring,"<s-nn?:s>")),G.bind("substringBefore",It(u.substringBefore,"<s-s:s>")),G.bind("substringAfter",It(u.substringAfter,"<s-s:s>")),G.bind("lowercase",It(u.lowercase,"<s-:s>")),G.bind("uppercase",It(u.uppercase,"<s-:s>")),G.bind("length",It(u.length,"<s-:n>")),G.bind("trim",It(u.trim,"<s-:s>")),G.bind("pad",It(u.pad,"<s-ns?:s>")),G.bind("match",It(u.match,"<s-f<s:o>n?:a<o>>")),G.bind("contains",It(u.contains,"<s-(sf):b>")),G.bind("replace",It(u.replace,"<s-(sf)(sf)n?:s>")),G.bind("split",It(u.split,"<s-(sf)n?:a<s>>")),G.bind("join",It(u.join,"<a<s>s?:s>")),G.bind("formatNumber",It(u.formatNumber,"<n-so?:s>")),G.bind("formatBase",It(u.formatBase,"<n-n?:s>")),G.bind("formatInteger",It(d.formatInteger,"<n-s:s>")),G.bind("parseInteger",It(d.parseInteger,"<s-s:n>")),G.bind("number",It(u.number,"<(nsb)-:n>")),G.bind("floor",It(u.floor,"<n-:n>")),G.bind("ceil",It(u.ceil,"<n-:n>")),G.bind("round",It(u.round,"<n-n?:n>")),G.bind("abs",It(u.abs,"<n-:n>")),G.bind("sqrt",It(u.sqrt,"<n-:n>")),G.bind("power",It(u.power,"<n-n:n>")),G.bind("random",It(u.random,"<:n>")),G.bind("boolean",It(u.boolean,"<x-:b>")),G.bind("not",It(u.not,"<x-:b>")),G.bind("map",It(u.map,"<af>")),G.bind("zip",It(u.zip,"<a+>")),G.bind("filter",It(u.filter,"<af>")),G.bind("single",It(u.single,"<af?>")),G.bind("reduce",It(u.foldLeft,"<afj?:j>")),G.bind("sift",It(u.sift,"<o-f?:o>")),G.bind("keys",It(u.keys,"<x-:a<s>>")),G.bind("lookup",It(u.lookup,"<x-s:x>")),G.bind("append",It(u.append,"<xx:a>")),G.bind("exists",It(u.exists,"<x:b>")),G.bind("spread",It(u.spread,"<x-:a<o>>")),G.bind("merge",It(u.merge,"<a<o>:o>")),G.bind("reverse",It(u.reverse,"<a:a>")),G.bind("each",It(u.each,"<o-f:a>")),G.bind("error",It(u.error,"<s?:x>")),G.bind("assert",It(u.assert,"<bs?:x>")),G.bind("type",It(u.type,"<x:s>")),G.bind("sort",It(u.sort,"<af?:a>")),G.bind("shuffle",It(u.shuffle,"<a:a>")),G.bind("distinct",It(u.distinct,"<x:x>")),G.bind("base64encode",It(u.base64encode,"<s-:s>")),G.bind("base64decode",It(u.base64decode,"<s-:s>")),G.bind("encodeUrlComponent",It(u.encodeUrlComponent,"<s-:s>")),G.bind("encodeUrl",It(u.encodeUrl,"<s-:s>")),G.bind("decodeUrlComponent",It(u.decodeUrlComponent,"<s-:s>")),G.bind("decodeUrl",It(u.decodeUrl,"<s-:s>")),G.bind("eval",It(Rt,"<sx?:x>")),G.bind("toMillis",It(d.toMillis,"<s-s?:n>")),G.bind("fromMillis",It(d.fromMillis,"<n-s?s?:s>")),G.bind("clone",It(jt,"<(oa)-:o>"));var Ft={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}}",D1013:"Object property names starting with _jsonata_ are reserved for internal use: {{value}}",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 Nt(t){var e=Ft[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 Ht(t,e){var n,i;try{n=f(t,e&&e.recover),i=n.errors,delete n.errors}catch(t){throw Nt(t),t}var s=Lt(G),o=new Date;return s.bind("now",It(function(t,e){return d.fromMillis(o.getTime(),t,e)},"<s?s?:s>")),s.bind("millis",It(function(){return o.getTime()},"<:n>")),e&&e.RegexEngine?Ht.RegexEngine=e.RegexEngine:Ht.RegexEngine=RegExp,{evaluate:function(t,e,a){if(void 0!==i){var c={code:"S0500",position:0};throw Nt(c),c}if(void 0!==e){var l;l=Lt(s);var h,d=r(p.keys(e));try{for(d.s();!(h=d.n()).done;){var u=h.value;l.bind(u,e[u])}}catch(c){d.e(c)}finally{d.f()}}else l=s;var f,m;if(l.bind("$",t),o=new Date,l.timestamp=o,Array.isArray(t)&&!j(t)&&((t=R(t)).outerWrapper=!0),"function"==typeof a){l.async=!0;var g=function(t){Nt(t),a(t,null)},y=function(t){(f=m.next(t)).done?a(null,f.value):f.value.then(y).catch(g)};m=V(n,t,l),(f=m.next()).value.then(y).catch(g)}else try{for(m=V(n,t,l),f=m.next();!f.done;)f=m.next(f.value);return f.value}catch(c){throw Nt(c),c}},assign:function(t,e){s.bind(t,e)},registerFunction:function(t,e,n){var i=It(e,n);s.bind(t,i)},ast:function(){return n},errors:function(){return i}}}return Ht.parser=f,Ht}();e.exports=g},{"./datetime":1,"./functions":2,"./parser":4,"./signature":5,"./utils":6}],4:[function(t,e,n){var i=t("./signature"),s=function(){var t={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":80,"#":80,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"^":40,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},e={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},n=function(n){var i=0,s=n.length,r=function(t,e){return{type:t,value:e,position:i}},o=function(){for(var t,e,r=i,o=0;i<s;){var a=n.charAt(i);if("/"===a&&"\\"!==n.charAt(i-1)&&0===o){if(""===(t=n.substring(r,i)))throw{code:"S0301",stack:(new Error).stack,position:i};for(i++,a=n.charAt(i),r=i;"i"===a||"m"===a;)i++,a=n.charAt(i);return e=n.substring(r,i)+"g",new RegExp(t,e)}"("!==a&&"["!==a&&"{"!==a||"\\"===n.charAt(i-1)||o++,")"!==a&&"]"!==a&&"}"!==a||"\\"===n.charAt(i-1)||o--,i++}throw{code:"S0302",stack:(new Error).stack,position:i}},a=function(c){if(i>=s)return null;for(var l=n.charAt(i);i<s&&" \t\n\r\v".indexOf(l)>-1;)i++,l=n.charAt(i);if("/"===l&&"*"===n.charAt(i+1)){var h=i;for(i+=2,l=n.charAt(i);"*"!==l||"/"!==n.charAt(i+1);)if(l=n.charAt(++i),i>=s)throw{code:"S0106",stack:(new Error).stack,position:h};return i+=2,l=n.charAt(i),a(c)}if(!0!==c&&"/"===l)return i++,r("regex",o());if("."===l&&"."===n.charAt(i+1))return i+=2,r("operator","..");if(":"===l&&"="===n.charAt(i+1))return i+=2,r("operator",":=");if("!"===l&&"="===n.charAt(i+1))return i+=2,r("operator","!=");if(">"===l&&"="===n.charAt(i+1))return i+=2,r("operator",">=");if("<"===l&&"="===n.charAt(i+1))return i+=2,r("operator","<=");if("*"===l&&"*"===n.charAt(i+1))return i+=2,r("operator","**");if("~"===l&&">"===n.charAt(i+1))return i+=2,r("operator","~>");if(Object.prototype.hasOwnProperty.call(t,l))return i++,r("operator",l);if('"'===l||"'"===l){var d=l;i++;for(var u="";i<s;){if("\\"===(l=n.charAt(i)))if(i++,l=n.charAt(i),Object.prototype.hasOwnProperty.call(e,l))u+=e[l];else{if("u"!==l)throw{code:"S0103",stack:(new Error).stack,position:i,token:l};var p=n.substr(i+1,4);if(!/^[0-9a-fA-F]+$/.test(p))throw{code:"S0104",stack:(new Error).stack,position:i};var f=parseInt(p,16);u+=String.fromCharCode(f),i+=4}else{if(l===d)return i++,r("string",u);u+=l}i++}throw{code:"S0101",stack:(new Error).stack,position:i}}var m,g=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/.exec(n.substring(i));if(null!==g){var y=parseFloat(g[0]);if(!isNaN(y)&&isFinite(y))return i+=g[0].length,r("number",y);throw{code:"S0102",stack:(new Error).stack,position:i,token:g[0]}}if("`"===l){i++;var b=n.indexOf("`",i);if(-1!==b)return m=n.substring(i,b),i=b+1,r("name",m);throw i=s,{code:"S0105",stack:(new Error).stack,position:i}}for(var _,v=i;;)if(_=n.charAt(v),v===s||" \t\n\r\v".indexOf(_)>-1||Object.prototype.hasOwnProperty.call(t,_)){if("$"===n.charAt(i))return m=n.substring(i+1,v),i=v,r("variable",m);switch(m=n.substring(i,v),i=v,m){case"or":case"in":case"and":return r("operator",m);case"true":return r("value",!0);case"false":return r("value",!1);case"null":return r("value",null);default:return i===s&&""===m?null:r("name",m)}}else v++};return a},s=function(e,s){var r,o,a=Object.create(null),c=[],l=function(){var t=[];"(end)"!==r.id&&t.push({type:r.type,value:r.value,position:r.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(s)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(s){t.remaining=l(),c.push(t);var e=a["(error)"];return(r=Object.create(e)).error=t,r.type="(error)",r}throw t.stack=(new Error).stack,t},p=function(t,n){if(t&&r.id!==t){var i={code:"(end)"===r.id?"S0203":"S0202",position:r.position,token:r.value,value:t};return u(i)}var s=o(n);if(null===s)return(r=a["(end)"]).position=e.length,r;var c,l=s.value,h=s.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:s.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:s.position,token:l})}return(r=Object.create(c)).value=l,r.type=h,r.position=s.position,r},f=function(t){var e,n=r;for(p(null,!0),e=n.nud();t<r.lbp;)n=r,p(),e=n.led(e);return e},m=function(t){d(t,0).nud=function(){return this}},g=function(e,n,i){var s=n||t[e],r=d(e,s);return r.led=i||function(t){return this.lhs=t,this.rhs=f(s),this.type="binary",this},r},y=function(t,e,n){var i=d(t,e);return i.led=n,i},b=function(t,e){var n=d(t);return n.nud=e||function(){return this.expression=f(70),this.type="unary",this},n};m("(end)"),m("(name)"),m("(literal)"),m("(regex)"),d(":"),d(";"),d(","),d(")"),d("]"),d("}"),d(".."),g("."),g("+"),g("-"),g("*"),g("/"),g("%"),g("="),g("<"),g(">"),g("!="),g("<="),g(">="),g("&"),g("and"),g("or"),g("in"),m("and"),m("or"),m("in"),b("-"),g("~>"),y("(error)",10,function(t){return this.lhs=t,this.error=r.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}),g("(",t["("],function(t){if(this.procedure=t,this.type="function",this.arguments=[],")"!==r.id)for(;"operator"===r.type&&"?"===r.id?(this.type="partial",this.arguments.push(r),p("?")):this.arguments.push(f(0)),","===r.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","<"===r.id){for(var e=r.position,n=1,s="<";n>0&&"{"!==r.id&&"(end)"!==r.id;){var o=p();">"===o.id?n--:"<"===o.id&&n++,s+=o.value}p(">");try{this.signature=i(s)}catch(t){return t.position=e+t.offset,u(t)}}p("{"),this.body=f(0),p("}")}return this}),b("(",function(){for(var t=[];")"!==r.id&&(t.push(f(0)),";"===r.id);)p(";");return p(")",!0),this.type="block",this.expressions=t,this}),b("[",function(){var t=[];if("]"!==r.id)for(;;){var e=f(0);if(".."===r.id){var n={type:"binary",value:"..",position:r.position,lhs:e};p(".."),n.rhs=f(0),e=n}if(t.push(e),","!==r.id)break;p(",")}return p("]",!0),this.expressions=t,this.type="unary",this}),g("[",t["["],function(e){if("]"===r.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}),g("^",t["^"],function(t){p("(");for(var e=[];;){var n={descending:!1};if("<"===r.id?p("<"):">"===r.id&&(n.descending=!0,p(">")),n.expression=f(0),e.push(n),","!==r.id)break;p(",")}return p(")"),this.lhs=t,this.rhs=e,this.type="binary",this});var _=function(t){var e=[];if("}"!==r.id)for(;;){var n=f(0);p(":");var i=f(0);if(e.push([n,i]),","!==r.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("{",_),g("{",t["{"],_),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)}),g("@",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)}),g("#",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)}),g("?",t["?"],function(t){return this.type="condition",this.condition=t,this.then=f(0),":"===r.id&&(p(":"),this.else=f(0)),this}),b("|",function(){return this.type="transform",this.pattern=f(0),p("|"),this.update=f(0),","===r.id&&(p(","),this.delete=f(0)),p("|"),this});var v=function(t){var e;if("function"!==t.type||t.predicate)if("condition"===t.type)t.then=v(t.then),void 0!==t.else&&(t.else=v(t.else)),e=t;else if("block"===t.type){var n=t.expressions.length;n>0&&(t.expressions[n-1]=v(t.expressions[n-1])),e=t}else e=t;else{var i={type:"lambda",thunk:!0,arguments:[],position:t.position};i.body=t,e=i}return e},x=0,w=0,M=[],S=function(t,e){switch(t.type){case"name":case"wildcard":e.level--,0===e.level&&(void 0===t.ancestor||(M[e.index].slot.label=t.ancestor.label),t.ancestor=e,t.tuple=!0);break;case"parent":e.level++;break;case"block":t.expressions.length>0&&(t.tuple=!0,e=S(t.expressions[t.expressions.length-1],e));break;case"path":t.tuple=!0;var n=t.steps.length-1;for(e=S(t.steps[n--],e);e.level>0&&n>=0;)e=S(t.steps[n--],e);break;default:throw{code:"S0217",token:t.type,position:t.position}}return e},k=function(t,e){if(void 0!==e.seekingParent||"parent"===e.type){var n=void 0!==e.seekingParent?e.seekingParent:[];"parent"===e.type&&n.push(e.slot),void 0===t.seekingParent?t.seekingParent=n:Array.prototype.push.apply(t.seekingParent,n)}},A=function(t){var e=t.steps.length-1,n=t.steps[e],i=void 0!==n.seekingParent?n.seekingParent:[];"parent"===n.type&&i.push(n.slot);for(var s=0;s<i.length;s++){var r=i[s];for(e=t.steps.length-2;r.level>0;){if(e<0){void 0===t.seekingParent?t.seekingParent=[r]:t.seekingParent.push(r);break}for(var o=t.steps[e--];e>=0&&o.focus&&t.steps[e].focus;)o=t.steps[e--];r=S(o,r)}}},E=function(t){var e;switch(t.type){case"binary":switch(t.value){case".":var n=E(t.lhs);e="path"===n.type?n:{type:"path",steps:[n]},"parent"===n.type&&(e.seekingParent=[n.slot]);var i=E(t.rhs);"function"===i.type&&"path"===i.procedure.type&&1===i.procedure.steps.length&&"name"===i.procedure.steps[0].type&&"function"===e.steps[e.steps.length-1].type&&(e.steps[e.steps.length-1].nextFunction=i.procedure.steps[0].value),"path"===i.type?Array.prototype.push.apply(e.steps,i.steps):(void 0!==i.predicate&&(i.stages=i.predicate,delete i.predicate),e.steps.push(i)),e.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"}),e.steps.filter(function(t){return!0===t.keepArray}).length>0&&(e.keepSingletonArray=!0);var r=e.steps[0];"unary"===r.type&&"["===r.value&&(r.consarray=!0);var o=e.steps[e.steps.length-1];"unary"===o.type&&"["===o.value&&(o.consarray=!0),A(e);break;case"[":var a=e=E(t.lhs),l="predicate";if("path"===e.type&&(a=e.steps[e.steps.length-1],l="stages"),void 0!==a.group)throw{code:"S0209",stack:(new Error).stack,position:t.position};void 0===a[l]&&(a[l]=[]);var h=E(t.rhs);void 0!==h.seekingParent&&(h.seekingParent.forEach(function(t){1===t.level?S(a,t):t.level--}),k(a,h)),a[l].push({type:"filter",expr:h,position:t.position});break;case"{":if(void 0!==(e=E(t.lhs)).group)throw{code:"S0210",stack:(new Error).stack,position:t.position};e.group={lhs:t.rhs.map(function(t){return[E(t[0]),E(t[1])]}),position:t.position};break;case"^":"path"!==(e=E(t.lhs)).type&&(e={type:"path",steps:[e]});var d={type:"sort",position:t.position};d.terms=t.rhs.map(function(t){var e=E(t.expression);return k(d,e),{descending:t.descending,expression:e}}),e.steps.push(d),A(e);break;case":=":(e={type:"bind",value:t.value,position:t.position}).lhs=E(t.lhs),e.rhs=E(t.rhs),k(e,e.rhs);break;case"@":if(e=E(t.lhs),a=e,"path"===e.type&&(a=e.steps[e.steps.length-1]),void 0!==a.stages||void 0!==a.predicate)throw{code:"S0215",stack:(new Error).stack,position:t.position};if("sort"===a.type)throw{code:"S0216",stack:(new Error).stack,position:t.position};t.keepArray&&(a.keepArray=!0),a.focus=t.rhs.value,a.tuple=!0;break;case"#":e=E(t.lhs),a=e,"path"===e.type?a=e.steps[e.steps.length-1]:(e={type:"path",steps:[e]},void 0!==a.predicate&&(a.stages=a.predicate,delete a.predicate)),void 0===a.stages?a.index=t.rhs.value:a.stages.push({type:"index",value:t.rhs.value,position:t.position}),a.tuple=!0;break;case"~>":(e={type:"apply",value:t.value,position:t.position}).lhs=E(t.lhs),e.rhs=E(t.rhs);break;default:(e={type:t.type,value:t.value,position:t.position}).lhs=E(t.lhs),e.rhs=E(t.rhs),k(e,e.lhs),k(e,e.rhs)}break;case"unary":e={type:t.type,value:t.value,position:t.position},"["===t.value?e.expressions=t.expressions.map(function(t){var n=E(t);return k(e,n),n}):"{"===t.value?e.lhs=t.lhs.map(function(t){var n=E(t[0]);k(e,n);var i=E(t[1]);return k(e,i),[n,i]}):(e.expression=E(t.expression),"-"===t.value&&"number"===e.expression.type?(e=e.expression).value=-e.value:k(e,e.expression));break;case"function":case"partial":(e={type:t.type,name:t.name,value:t.value,position:t.position}).arguments=t.arguments.map(function(t){var n=E(t);return k(e,n),n}),e.procedure=E(t.procedure);break;case"lambda":e={type:t.type,arguments:t.arguments,signature:t.signature,position:t.position};var u=E(t.body);e.body=v(u);break;case"condition":(e={type:t.type,position:t.position}).condition=E(t.condition),k(e,e.condition),e.then=E(t.then),k(e,e.then),void 0!==t.else&&(e.else=E(t.else),k(e,e.else));break;case"transform":(e={type:t.type,position:t.position}).pattern=E(t.pattern),e.update=E(t.update),void 0!==t.delete&&(e.delete=E(t.delete));break;case"block":(e={type:t.type,position:t.position}).expressions=t.expressions.map(function(t){var n=E(t);return k(e,n),(n.consarray||"path"===n.type&&n.steps[0].consarray)&&(e.consarray=!0),n});break;case"name":e={type:"path",steps:[t]},t.keepArray&&(e.keepSingletonArray=!0);break;case"parent":e={type:"parent",slot:{label:"!"+x++,level:1,index:w++}},M.push(e);break;case"string":case"number":case"value":case"wildcard":case"descendant":case"variable":case"regex":e=t;break;case"operator":if("and"===t.value||"or"===t.value||"in"===t.value)t.type="name",e=E(t);else{if("?"!==t.value)throw{code:"S0201",stack:(new Error).stack,position:t.position,token:t.value};e=t}break;case"error":e=t,t.lhs&&(e=E(t.lhs));break;default:var p="S0206";"(end)"===t.id&&(p="S0207");var f={code:p,position:t.position,token:t.value};if(s)return c.push(f),{type:"error",error:f};throw f.stack=(new Error).stack,f}return t.keepArray&&(e.keepArray=!0),e};o=n(e),p();var C=f(0);if("(end)"!==r.id){var T={code:"S0201",position:r.position,token:r.value};u(T)}if("parent"===(C=E(C)).type||void 0!==C.seekingParent)throw{code:"S0217",token:C.type,position:C.position};return c.length>0&&(C.errors=c),C};return s}();e.exports=s},{"./signature":5}],5:[function(t,e,n){function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}var s=t("./utils"),r=function(){var t={a:"arrays",b:"booleans",f:"functions",n:"numbers",o:"objects",s:"strings"};function e(e){for(var n=1,r=[],o=Object.create(null),a=o;n<e.length;){var c=e.charAt(n);if(":"===c)break;var l=function(){r.push(o),a=o,o=Object.create(null)},h=function(t,e,n,i){for(var s=1,r=e;r<t.length;)if(r++,(c=t.charAt(r))===i){if(0===--s)break}else c===n&&s++;return r};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="^"+r.map(function(t){return"("+t.regex+")"}).join("")+"$",m=new RegExp(f),g=function(t){var e;if(s.isFunction(t))e="f";else switch(i(t)){case"string":e="s";break;case"number":e="n";break;case"boolean":e="b";break;case"object":e=null===t?"l":Array.isArray(t)?"a":"o";break;default:e="m"}return e},y=function(t,e){for(var n="^",i=0,s=0;s<r.length;s++){n+=r[s].regex;var o=e.match(n);if(null===o)throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1};i=o[0].length}throw{code:"T0410",stack:(new Error).stack,value:t[i],index:i+1}};return{definition:e,validate:function(e,n){var i="";e.forEach(function(t){i+=g(t)});var s=m.exec(i);if(s){var o=[],a=0;return r.forEach(function(i,r){var c=e[a],l=s[r+1];if(""===l)if(i.context&&i.contextRegex){var h=g(n);if(!i.contextRegex.test(h))throw{code:"T0411",stack:(new Error).stack,value:n,index:a+1};o.push(n)}else o.push(c),a++;else l.split("").forEach(function(n){if("a"===i.type){if("m"===n)c=void 0;else{c=e[a];var s=!0;if(void 0!==i.subtype)if("a"!==n&&l!==i.subtype)s=!1;else if("a"===n&&c.length>0){var r=g(c[0]);s=r===i.subtype.charAt(0)&&0===c.filter(function(t){return g(t)!==r}).length}if(!s)throw{code:"T0412",stack:(new Error).stack,value:c,index:a+1,type:t[i.subtype]};"a"!==n&&(c=[c])}o.push(c),a++}else o.push(c),a++})}),o}y(e,i)}}}return e}();e.exports=r},{"./utils":6}],6:[function(t,e,n){function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=s(t))||e){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}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 s(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.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)?r(t,e):void 0}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}var a=function(){function t(t){var e=!1;if("number"==typeof t&&(e=!isNaN(t))&&!isFinite(t))throw{code:"D1001",value:t,stack:(new Error).stack};return e}function e(t){var e=!1;return Array.isArray(t)&&(e=0===t.filter(function(t){return"string"!=typeof t}).length),e}function n(e){var n=!1;return Array.isArray(e)&&(n=0===e.filter(function(e){return!t(e)}).length),n}function s(){var t=[];return t.sequence=!0,1===arguments.length&&t.push(arguments[0]),t}function r(t){return!0===t.sequence&&Array.isArray(t)}function a(t){return t&&(!0===t._jsonata_function||!0===t._jsonata_lambda)||"function"==typeof t}function c(t){return"number"==typeof t.arity?t.arity:"function"==typeof t.implementation?t.implementation.length:"number"==typeof t.length?t.length:t.arguments.length}function l(t){return t&&!0===t._jsonata_lambda}var h=("function"==typeof Symbol?Symbol:{}).iterator||"@@iterator";function d(t){return"object"===o(t)&&null!==t&&h in t&&"next"in t&&"function"==typeof t.next}function u(t,e){if(t===e)return!0;if("object"===o(t)&&"object"===o(e)&&null!==t&&null!==e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!u(t[n],e[n]))return!1;return!0}var i=Object.getOwnPropertyNames(t),s=Object.getOwnPropertyNames(e);if(i.length!==s.length)return!1;for(i=i.sort(),s=s.sort(),n=0;n<i.length;n++)if(i[n]!==s[n])return!1;for(n=0;n<i.length;n++){var r=i[n];if(!u(t[r],e[r]))return!1}return!0}return!1}function p(t){var e,n=[],s=i(t);try{for(s.s();!(e=s.n()).done;){var r=e.value;n.push(r)}}catch(t){s.e(t)}finally{s.f()}return n}function f(t){return"object"===o(t)&&null!==t?Object.keys(t):[]}return{isNumeric:t,isArrayOfStrings:e,isArrayOfNumbers:n,createSequence:s,isSequence:r,isFunction:a,isLambda:l,isIterable:d,getFunctionArity:c,isDeepEqual:u,stringToArray:p,keys:f}}();e.exports=a},{}]},{},[3])(3)}(os)),os.exports),cs=is(as);const ls=function(t){return t};function hs(t){if(!t)return ls;try{const e=cs(function(t){return t.replace(/(?<=^|\.|\[)([a-zA-Z_][\w]*-[\w-]*)(?=\.|$|\[|])/g,"`$1`")}(t));return function(t){return e.evaluate(t)}}catch(t){return Zi(t),ls}}function ds(t){const e=wi(t);return null==e?"":String(e)}function us(t){return Number(wi(t))}function ps(t){return t}function fs(t){return ds(t)}function ms(t){return us(t)}function gs(t){if(this.param)return t=ds(t),this.param.hasOwnProperty(t)?this.param[t]:this.param.default}function ys(t){const{param:e}=this;if(e){for(const n in e){let[i,s]=n.split("~");const r=!!i,o=!!s,a=parseFloat(i),c=parseFloat(s);if(t=us(t),r&&!o&&t>=a)return e[n];if(!r&&o&&t<a)return e[n];if(t>=a&&t<c)return e[n]}return e.default}}function bs(t){return us(t)*Math.PI/180}function _s(){}const vs=[/\bimport\b/,/\brequire\b/,/\b__proto__\b/,/\bconstructor\s*\[/,/\bprototype\b/];const xs=["globalThis","self","top","parent","frames","fetch","XMLHttpRequest","eval","Function","require","importScripts","process"],ws=new Array(xs.length).fill(void 0),Ms=Object.getPrototypeOf(async function(){}).constructor;function Ss(t,e){!function(t){for(const e of vs)if(e.test(t))throw new Error(`Blocked pattern detected: ${e}`)}(t);const n=function(t){return/\bawait\b/.test(t)}(t),i=new(n?Ms:Function)(...e,...xs,t);return function(t,...e){return i.call(t,...e,...ws)}}function ks(t,e,n,i,s){switch(n){case"value":return"text"===s||"string"===s?fs.bind(t):"number"===s?ms.bind(t):ps.bind(e);case"map":return gs.bind(t);case"range":return ys.bind(t);case"radian":return bs.bind(t);case"eval":return function(t){try{const e=Ss(t,["value","targets","scene"]);return function(t,n){try{const i=e(this,t,n,globalThis.scene);return i&&"function"==typeof i.then?i.catch(t=>{Zi(t)}):i}catch(t){return void Zi(t)}}}catch(t){return Zi(t),_s}}(i).bind(e);default:return ps.bind(e)}}class As{constructor(t,e){this.owner=e,this.model=t}dispose(){this._model=null,this.owner=null,this.evaluator=null,this.accessor=null}get model(){return this._model}set model(t){const{target:e,property:n,rule:i,param:s,accessor:r}=t;this._model=t,this.evaluator=ks(this,this.owner,i,s,function(t){switch(t){case"ref":case"fillStyle":case"strokeStyle":return"string";default:return}}(n)),this.accessor=hs(r);const o=e.match(/\[(.*?)\]/);if(o){const[t,e]=o[1].split(":");this.propAccessor=hs(t),this.partAccessor=hs(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 Es(t,e,n,i){const s=e.split(".");if(1===s.length)return void(t[e]=i?{...t[e],...n}:n);const r=s[0],o=void 0!==t[r]?t[r]:"function"==typeof t.get?t.get(r):void 0,a=o?{...o}:{};let c=a;for(let t=1;t<s.length-1;t++)c[s[t]]=c[s[t]]?{...c[s[t]]}:{},c=c[s[t]];const l=s[s.length-1];c[l]=i?{...c[l],...n}:n,t[r]=a}function Cs(t,e,n,i){t.forEach(t=>Es(t,e,n,i))}function Ts(t,e,n,i){t&&"function"==typeof t.then?t.then(t=>{void 0!==n&&void 0!==i&&n._dataGeneration!==i||e(t)}).catch(t=>Zi(t)):e(t)}function Ps(t=!1){if(!t&&void 0===this.data)return;this._dataGeneration=(this._dataGeneration??0)+1;const e=this._dataGeneration,n=this;this.mappings&&this.mappings.forEach(t=>{try{let i,{source:s,target:r,property:o,accessor:a,propAccessor:c,partAccessor:l,ndnsp:h=!1,partial:d=!1}=t;r=(r||"(self)").trim(),t.rule||(t.rule="value"),s&&"(self)"!=s?(s.startsWith("#")&&(s=s.substring(1)),i=this.root.findById(s)?.data||{}):i=this.data;const u=a(i);if("(root)"==r||"(key)"==r){if(null==u)return;const i=Object.keys(u||{}).map(t=>this.root.findOrCreate(t)).filter(Boolean).flat();i.length>0&&i.forEach(i=>{Ts(t.evaluator(u[i.get("id")],[i]),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Es(i,o,t,d)},n,e)})}else if(r.startsWith("[")){if(null==u)return;if(u instanceof Array)u.forEach(i=>{const s=c(i);if(s){const r=this.root.findOrCreate(s);r&&Ts(t.evaluator(l(i),r),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Cs(r,o,t,d)},n,e)}});else{if(!(u instanceof Object))throw String("mapping data should be an object to target property-id.("+u+")");{const i=c(u);if(i){const s=this.root.findOrCreate(i);s&&Ts(t.evaluator(l(u),s),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Cs(s,o,t,d)},n,e)}}}}else{const i=this.root.findAll(r,this);i.length>0&&Ts(t.evaluator(u,i),t=>{!o||"(action)"===o||h&&!t&&0!==t&&!1!==t||Cs(i,o,t,d)},n,e)}}catch(e){Zi(e,this,t)}})}function Os(t,e){this.state.persistent&&this.app?.isViewMode&&this.app?.dataStorage.save(this,t.data),Ps.call(this,!0)}function Ds(){if(this._model.mappings)return this._model.mappings instanceof Array?void(this._mappings=(this._model.mappings||[]).filter(t=>t.property).map(t=>new As({target:"(self)",rule:"value",...t},this))):(Zi("Mappings model is invalid (should be a Array) ..",this._model.mappings),void(this._mappings=[]));this._mappings=[]}function zs(){this._mappings&&this._mappings.forEach(t=>t.dispose()),delete this._mappings}function Is(t,e){this.disposeMappings(),Ps.call(this)}function Rs(t){if(!t||"object"!=typeof t||Array.isArray(t))return[];const e={tap:"click",hover:"mouseenter",dblclick:"dblclick",longpress:"longpress"},n=[];for(const i of Object.keys(t)){const s=e[i];if(!s)continue;const r=t[i];if(r&&"object"==typeof r){if("script"===r.action){const t="string"==typeof r.value?r.value:r.value&&"object"==typeof r.value?r.value.script:"";t&&n.push({trigger:s,action:"script",code:t,target:r.target});continue}n.push({trigger:s,action:r.action,target:r.target,value:r.value,options:{emphasize:r.emphasize,restore:r.restore,pressed:r.pressed,...r.options??{}}})}}return n}function js(t){if(!t)return[];const e=t.eventHandlers;return Array.isArray(e)?e:Rs(t.event)}function Ls(t,e,n,i,s,r){e.complete?t.drawImage(e,n,i,s,r):e.addEventListener("load",()=>{this.invalidate()})}function Fs(t){const{effects:e}=this.state;(e||[]).forEach(e=>{this.effect(t,e)})}const Ns={},Hs=0,Bs=1,Gs=2,Vs=3,Ys=4,Ws=5,Us={VIEW:0,EDIT:1,SHIFT:2,ADD:3},$s=30,Xs="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),qs=["mousemove","mouseup","mousedown","mouseout","wheel","touchstart","touchmove","touchend","dblclick"],Ks=["keydown","keyup"],Qs={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},Zs=()=>{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";Qs.FONT_FAMILY=e||n},Js=()=>{if("undefined"!=typeof window&&"undefined"!=typeof document&&(window.addEventListener("load",()=>{Zs()}),"fonts"in document&&"ready"in document.fonts&&document.fonts.ready.then(Zs),"undefined"!=typeof MutationObserver&&document.documentElement)){new MutationObserver(()=>{Zs()}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}};let tr;function er(t,e,n,i,s){const{alpha:r=1}=i,o=s.fillStyle;if(t.globalAlpha*=r,o)if("string"==typeof o)t.fillStyle=o,t.fill();else if("object"==typeof o)if("gradient"==o.type){t.translate(n.x,n.y);let i,{width:s,height:r}=e;if("linear"==o.gradientType){const e=3.141592653589793,n="number"==typeof o.rotation&&Number.isFinite(o.rotation)?o.rotation:0;if(n>=.436332&&n<=1.13446||n>=2.00713&&n<=2.70526||n>=3.57792&&n<=4.27606||n>=5.14872&&n<=5.84685){let o=Math.sqrt(Math.pow((s-4)/2,2)+Math.pow((r-4)/2,2));o-=o-(s+r)/3,i=t.createLinearGradient(o*Math.cos(n+e),o*Math.sin(n+e),o*Math.cos(n),o*Math.sin(n))}else i=t.createLinearGradient((s-4)/2*Math.cos(n+e),(r-4)/2*Math.sin(n+e),(s-4)/2*Math.cos(n),(r-4)/2*Math.sin(n))}else if("radial"==o.gradientType){const e=.95*Math.sqrt(Math.pow((s-4)/2,2)+Math.pow((r-4)/2,2));switch(o.center){case"center":default:i=t.createRadialGradient(0,0,0,0,0,e);break;case"left-top":i=t.createRadialGradient(-s/2,-r/2,0,-s/2,-r/2,2*e);break;case"right-top":i=t.createRadialGradient(s/2,-r/2,0,s/2,-r/2,2*e);break;case"left-bottom":i=t.createRadialGradient(-s/2,r/2,0,-s/2,r/2,2*e);break;case"right-bottom":i=t.createRadialGradient(s/2,r/2,0,s/2,r/2,2*e)}}(Array.isArray(o.colorStops)?o.colorStops:Array.isArray(o.gradientStops)?o.gradientStops:[]).forEach(t=>{if(t.position>=0&&t.position<=1)try{i.addColorStop(t.position,t.color)}catch(e){Ji("Invalid Color for colorstop : ",t.color),i.addColorStop(t.position,"#fff")}}),t.fillStyle=i,t.fill(),t.translate(-n.x,-n.y)}else if("pattern"==o.type&&o.image)if(o.guideOnly&&1!=s.app.mode)o.color&&(t.fillStyle=o.color,t.fill());else{s.prepareFillIf(!s._pattern_image_origin);const n=s._pattern_image;if(!n||!n.width||!n.height)return;let i=0,r=0,a=0,c=0,l=e.left,h=e.top;if(!o.fitPattern){i=o.offsetX,r=o.offsetY;const t=o.width?o.width:n.width,s=o.height?o.height:n.height;switch(o.align){case"center":a=e.width/2-t/2,c=e.height/2-s/2;break;case"left-top":a=0,c=0;break;case"left-bottom":a=0,c=e.height-s;break;case"right-top":a=e.width-t,c=0;break;case"right-bottom":a=e.width-t,c=e.height-s;break;case"left":a=0,c=e.height/2-s/2;break;case"right":a=e.width-t,c=e.height/2-s/2;break;case"top":a=e.width/2-t/2,c=0;break;case"bottom":a=e.width/2-t/2,c=e.height-s}l+=i+a,h+=r+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 s._pattern_image,delete s._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 nr(t,e){const n=this.fillStyle;if(!n||"pattern"!=n.type||!n.image)return void t(this);if("string"!=typeof n.image)return this._pattern_image_origin=this._pattern_image=n.image,void t(this);this._pattern_image=null,this._pattern_image_origin=new Image;const i=this;this._pattern_image_origin.onload=function(){if(!n.fitPattern&&!n.width&&!n.height)return i._pattern_image=i._pattern_image_origin,void t(this);let e=n.width||this.width,s=n.height||this.height;n.fitPattern&&(e=i.bounds.width,s=i.bounds.height);const r=tr(e,s);r.getContext("2d").drawImage(this,0,0,this.width,this.height,0,0,e,s),i._pattern_image=r,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 ir(t){t&&this.prepareFill(t=>{this.invalidate()},t=>{Zi(t)})}function sr(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 rr(t,e,n){let{strokeStyle:i,lineDash:s,lineWidth:r,lineCap:o,lineJoin:a,alpha:c}=e;if(i&&0!=r){if(o&&(t.lineCap=o),s){const e="round"==o;switch(s){case"solid":s=[0,0];break;case"round-dot":s=e?[0,2*r]:[r,r];break;case"square-dot":s=e?[r,2*r]:[2*r,r];break;case"dash":s=e?[3*r,2.5*r]:[4*r,1.5*r];break;case"dash-dot":s=e?[3*r,3*r,0,3*r]:[4*r,2*r,r,2*r];break;case"long-dash":s=e?[5*r,4*r]:[6*r,3*r];break;case"long-dash-dot":s=e?[5*r,3*r,0,3*r]:[6*r,2*r,r,2*r];break;case"long-dash-dot-dot":s=e?[5*r,2*r,0,2*r,0,2*r]:[6*r,r,r,r,r,r]}Array.isArray(s)||(s=[]),t.setLineDash(s)}t.globalAlpha*=c,t.strokeStyle=i,t.lineWidth=r,t.lineJoin=a,t.stroke()}}function or(t){const e=/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3|([^\*_]+)/g,n=[];let i;for(;null!==(i=e.exec(t));)i[1]?n.push({text:i[2],bold:!0,italic:!1}):i[3]?n.push({text:i[4],bold:!1,italic:!0}):i[5]&&n.push({text:i[5],bold:!1,italic:!1});return n}function ar(t,e,n,i=0){if(e.text.length<2)return e;let s=2;for(;s<e.text.length;s++){const r=e.text.substring(0,s);if(!(t.measureText(r).width+(s-1)*i<n))break}return{...e,text:e.text.substring(0,s-1)}}function cr(t,e,n,i,s,r=0){const o=String(e).split("\n");return i?[].concat(...o.map(e=>function(t,e,n,i=0){const s=[];let r=[],o=0;return e.forEach(e=>{let a=e.text;for(;a.length>0;){const c=n-o,l=t.measureText(a).width+(a.length-1)*i;if(l<=c)r.push({...e,text:a}),o+=l,a="";else{const n=ar(t,{...e,text:a},c,i);r.push(n),s.push(r),r=[],o=0,a=a.substring(n.text.length)}}}),r.length>0&&s.push(r),s}(t,s?or(e):[{text:e,bold:!1,italic:!1}],n,r))):o.map(t=>s?or(t):[{text:t,bold:!1,italic:!1}])}function lr(t,e,n,i,s,r,o=0){if(!i)return[];t.save(),t.font=n;const a=cr(t,i,e,!!s,r,o);return t.restore(),a}function hr(t){const{fontFamily:e=Qs.FONT_FAMILY,bold:n=Qs.BOLD,italic:i=Qs.ITALIC,fontSize:s=Qs.FONT_SIZE}=t,r=[];return n&&r.push("bold"),i&&r.push("italic"),r.push(s+"px"),r.push(e),r.join(" ")}function dr(t,e){const n=t.bold||e.bold,i=t.italic||e.italic;return hr({...t,bold:n,italic:i})}function ur(t,e,n,i){let{alpha:s,rotation:r,keepTextAngle:o=!1,fontColor:a=Qs.FONT_COLOR,textAlign:c=Qs.TEXT_ALIGN,textBaseline:l=Qs.TEXT_BASELINE,textBackgroundStyle:h,fontSize:d,lineHeight:u,textWrap:p,textOverflow:f,letterSpacing:m=0}=i;s=void 0!==s?s:1,d||=Qs.FONT_SIZE,u||=1.2*d,t.save();const{left:g,top:y,width:b,height:_}=e;if(r&&o&&(t.translate(g+b/2,y+_/2),t.rotate(-r),t.translate(-(g+b/2),-(y+_/2))),t.beginPath(),t.font=hr(i),!p&&f){const e=function(t,e,n,i){const s="ellipsis"===t?"…":"",r=e.measureText(s).width,o=[];let a=0;for(const s of n){const n=[];for(const c of s){const s=e.measureText(c.text).width;if(!(a+s<=i-("ellipsis"===t?r:0))){const s=pr(e,c,i-a-("ellipsis"===t?r:0),t);return n.push(s),o.push(n),o}n.push(c),a+=s}o.push(n),a=0}return o}(f,t,n,b);n=e}const v=n.length*u;let x;switch(l){case"top":x=y,t.textBaseline="top";break;case"bottom":x=y+_-v+u,t.textBaseline="bottom";break;default:x=y+_/2-v/2+u/2,t.textBaseline="middle"}t.globalAlpha*=s,t.fillStyle=a,n.forEach((e,s)=>{const r=x+s*u,o=function(t,e,n,i=0){return e.reduce((e,s)=>(t.font=dr(n,s),e+t.measureText(s.text).width+i*(s.text.length-1)),0)}(t,e,i,m);let l=g;switch(c){case"left":case"justify":l=g;break;case"right":l=g+b-o;break;case"center":l=g+(b-o)/2}if(h&&(t.fillStyle=h,function(t,e,n,i,s,r=0,o=!1,a=!0){r="number"==typeof r?{tl:r,tr:r,br:r,bl:r}:{tl:0,tr:0,br:0,bl:0,...r},t.beginPath(),t.moveTo(e+r.tl,n),t.lineTo(e+i-r.tr,n),t.quadraticCurveTo(e+i,n,e+i,n+r.tr),t.lineTo(e+i,n+s-r.br),t.quadraticCurveTo(e+i,n+s,e+i-r.br,n+s),t.lineTo(e+r.bl,n+s),t.quadraticCurveTo(e,n+s,e,n+s-r.bl),t.lineTo(e,n+r.tl),t.quadraticCurveTo(e,n,e+r.tl,n),t.closePath(),o&&t.fill(),a&&t.stroke()}(t,l-4,r-d/2-4,o+8,d+8,4,!0,!1),t.fillStyle=a),"justify"===c&&s<n.length-1&&e.length>1){const n=b-o,s=e.length-1,a=n/s;e.forEach((e,n)=>{t.font=dr(i,e),t.fillText(e.text,l,r),l+=t.measureText(e.text).width+(n<s?a:0)})}else e.forEach(e=>{t.font=dr(i,e),[...e.text].forEach(e=>{t.fillText(e,l,r),l+=t.measureText(e).width+m})})}),t.restore()}function pr(t,e,n,i){let s="";for(let i=0;i<e.text.length;i++){const r=s+e.text[i];if(t.measureText(r).width>n)break;s=r}return{...e,text:s+("ellipsis"===i?"…":"")}}function fr(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})}Js(),Zs(),tr="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 mr=[];function gr(t,e,n={x:0,y:0},i=0,s={x:1,y:1}){if(1!==s.x||1!==s.y?(t=(t-n.x)/s.x,e=(e-n.y)/s.y):(t-=n.x,e-=n.y),0!==i){const n=Math.cos(-i),s=Math.sin(-i),r=t*s+e*n;t=t*n-e*s,e=r}return{x:t+n.x,y:e+n.y}}function yr(t,e,n={x:0,y:0},i=0,s={x:1,y:1}){if(t-=n.x,e-=n.y,0!==i){const n=Math.cos(i),s=Math.sin(i),r=t*s+e*n;t=t*n-e*s,e=r}return 1!==s.x||1!==s.y?{x:t*s.x+n.x,y:e*s.y+n.y}:{x:t+n.x,y:e+n.y}}function br(t,e,n){if(!this.parent)return{x:t,y:e};const{rotation:i=0,scale:s={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,r=gr(t,e,n,i,s);return n&&(r.x-=n.x,r.y-=n.y),r}return gr(t,e,n=n||this.rotatePoint,i,s)}function _r(t,e,n){if(!this.parent)return{x:t,y:e};let{rotation:i=0,scale:s={x:1,y:1}}=this.state;if(this.isLayer()){const n=this.state.translate,r=yr(t,e,void 0,i+(this._delta?.theta??0),s);return n&&(r.x+=n.x,r.y+=n.y),r}n=n||this.rotatePoint;const{theta:r=0,tx:o=0,ty:a=0,sx:c=1,sy:l=1}=this._delta||{};if(0===r&&0===o&&0===a&&1===c&&1===l)return yr(t,e,n,i,s);return yr(t+o,e+a,{x:n.x+o,y:n.y+a},i+r,{x:s.x*c,y:s.y*l})}function vr(t,e,n){n=n||this.rootModel;const i=this.transcoordS2T(t,e,n);return yr(i.x,i.y,void 0,(n.get("rotation")||0)+n._delta.theta)}function xr(t,e,n){n=n||this.rootModel,mr.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)mr.push(t);let i=this.transcoordS2P(t,e);for(let t=0;t<mr.length;t++){const e=mr[t],n=e.bounds;i.x+=n.left,i.y+=n.top,i=e.transcoordS2P(i.x,i.y)}return i}function wr(t,e,n){n=n||this.rootModel,mr.length=0;for(let t=this.parent;t&&t!==n;t=t.parent)mr.push(t);let i={x:t,y:e};for(let t=mr.length-1;t>=0;t--){const e=mr[t];i=e.transcoordP2S(i.x,i.y);const n=e.bounds;i.x-=n.left,i.y-=n.top}return i}function Mr(t,e,n){const i=this.transcoordT2P(t,e,n);return this.transcoordP2S(i.x,i.y)}function Sr(t,e,n){const i=this.rootModel,s=this.transcoordS2T(t,e,i);return n.transcoordT2S(s.x,s.y,i)}function kr(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;const{translate:i={x:0,y:0},scale:s={x:1,y:1},rotation:r=0}=n.model,o=gr(t,e,i,r,s);return i&&(o.x-=i.x,o.y-=i.y),n===this?o:this.transcoordT2S(o.x,o.y,n)}function Ar(t,e,n){if(!n)for(n=this;n&&!n.isLayer();)n=n.parent;let i;if(i=n!==this?this.transcoordS2T(t,e,n):{x:t,y:e},!this.scalable)return i;const{translate:s={x:0,y:0},rotation:r=0,scale:o={x:1,y:1}}=n.model;return i=yr(i.x,i.y,void 0,r+n._delta.theta,o),s&&(i.x+=s.x,i.y+=s.y),i}function Er(t){let e=0,n=0,i=0,s=0,r=!1;return t.forEach(t=>{r?(e=Math.min(t.left,e),n=Math.min(t.top,n),i=Math.max(t.left+t.width,i),s=Math.max(t.top+t.height,s)):(e=t.left,n=t.top,i=t.left+t.width,s=t.top+t.height,r=!0)}),{left:e,top:n,width:i-e,height:s-n}}function Cr(t){const e=t.element,n=t.fillStyle,i=e.style;if(n)if("string"==typeof n)i.backgroundColor=n;else switch(n.type){case"pattern":if(i.backgroundImage="url("+n.image+")",i.backgroundColor="transparent",n.fitPattern?i.backgroundSize="100% 100%":n.width||n.height?i.backgroundSize=`${n.width?n.width+"px":"auto"} ${n.height?n.height+"px":"auto"}`:i.backgroundSize="contain",n.fitPattern)i.backgroundRepeat="no-repeat";else{const{offsetX:t,offsetY:e,noRepeat:s,align:r,color:o}=n;if(s&&(i.backgroundRepeat="no-repeat"),o&&(i.backgroundColor=o),r)switch(r){case"center":i.backgroundPosition="center center";break;case"left-top":i.backgroundPosition="left top";break;case"left-bottom":i.backgroundPosition="left bottom";break;case"right-top":i.backgroundPosition="right top";break;case"right-bottom":i.backgroundPosition="right bottom";break;case"left":i.backgroundPosition="left center";break;case"right":i.backgroundPosition="right center";break;case"top":i.backgroundPosition="center top";break;case"bottom":i.backgroundPosition="center bottom"}else t||e?i.backgroundPosition=`${Number(t)||0}px ${Number(e)||0}px`:delete i.backgroundPosition}break;case"gradient":i.background=function(t,e){const n=e.colorStops,i=e.gradientType;if(n instanceof Array&&n.length>0)switch(i){case"radial":return"radial-gradient(farthest-corner at "+function(t,e){const{width:n,height:i}=t.bounds;switch(e){case"center":return[n/2,i/2];case"left-top":return[0,0];case"right-top":return[n,0];case"left-bottom":return[0,i];default:return[n,i]}}(t,e.center||"center").map(t=>t+"px").join(" ")+","+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")";case"linear":return"linear-gradient("+(180*(e.rotation||0)/3.141592653589793+90+"deg")+", "+n.map(t=>`${t.color} ${100*t.position}%`).join(",")+")"}return""}(t,n)}else i.background="transparent"}const Tr={x:1,y:1},Pr={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"};function Or(t){let{id:e,scale:n=Tr,bold:i,italic:s,fontFamily:r="",textAlign:o,textBaseline:a,textOverflow:c,paddingTop:l,paddingBottom:h,paddingLeft:d,paddingRight:u,fontSize:p=Qs.FONT_SIZE,lineWidth:f=0,lineHeight:m,lineDash:g}=t.state;h||=0,l||=0,d||=0,u||=0;const y=t.state.class,{strokeStyle:b,rotation:_=0,fontColor:v,hidden:x}=t,{left:w,top:M,width:S,height:k}=t.bounds,A=t.element;if(A.hidden=!t.app?.isEditMode&&x,e&&(A.id=e),y&&(A.className=y),Object.assign(A.style,Pr,{fontFamily:r,fontSize:p+"px",width:S+"px",height:k+"px",paddingTop:l+"px",paddingRight:u+"px",paddingBottom:h+"px",paddingLeft:d+"px",border:f+"px",borderColor:b,borderStyle:f>0?g||Qs.LINE_DASH:"",color:v,fontWeight:i?"bold":"",fontStyle:s?"italic":"",textAlign:"end"==o?"right":"start"==o?"left":o,verticalAlign:a,lineHeight:void 0===m?"":m+"px",whiteSpace:c?"nowrap":"",overflow:c?"hidden":"",textOverflow:c||""},t.isIn3DSpace()?{}:{left:w+"px",top:M+"px"}),Cr(t),function(t){if(!t.isShadowable()||!t.state.shadow)return;const e=t.state.shadow,n=e.offsetX??e.left??0,i=e.offsetY??e.top??0,s=e.blur??e.blurSize??0,r=e.color??"transparent";t.element.style.boxShadow=`${n}px ${i}px ${s}px ${r}`}(t),t.isIn3DSpace())return;const E=t.delta(),C=(n&&n.x||1)*E.sx,T=(n&&n.y||1)*E.sy,P=(_||0)+E.theta,O=E.tx||0,D=E.ty||0;A.style.transform=`rotate(${P}rad) translate(${O}px, ${D}px) scale(${C}, ${T}) perspective(1px)`}function Dr(t,e){let n=this.bounds,i=this.rotatePoint;const s=this.get("rotation"),r=this.get("scale");if(t){const i=t.call(e,n);i&&(n=i)}const{left:o,top:a,width:c,height:l}=n;let h=[{x:o,y:a},{x:o+c,y:a+l}];h=h.map(t=>yr(t.x,t.y,i,s,r));let d=h[0],u=h[1];i={x:(d.x+u.x)/2,y:(d.y+u.y)/2},h=h.map(t=>gr(t.x,t.y,i,s,r)),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 zr(t,e,n){let i=this.path,s=this.rotatePoint;t&&(i=t.call(n,i));let r=i.map(t=>{const e=this.toParent(t.x,t.y);return{...t,x:e.x,y:e.y}});if(e){const t=e.call(n,r);t&&(r=t)}const o={x:0,y:0};let a,c,l,h;i=r.map(t=>this.fromParent(t.x,t.y,o)),a=c=i[0].x,l=h=i[0].y;for(let t=1;t<i.length;t++){const e=i[t];e.x<a?a=e.x:e.x>c&&(c=e.x),e.y<l?l=e.y:e.y>h&&(h=e.y)}s={x:(a+c)/2,y:(l+h)/2},s=this.toParent(s.x,s.y,o),this.path=r.map(t=>{const e=this.fromParent(t.x,t.y,s);return{...t,x:e.x,y:e.y}})}const Ir=new class{constructor(){this._now=0,this._speed=1,this._paused=!1,this._listeners=new Set}get now(){return this._now}get speed(){return this._speed}set speed(t){this._speed=Math.max(0,t),this._speed>0&&(this._paused=!1)}get isPaused(){return this._paused}pause(){this._paused=!0}resume(){this._paused=!1}tick(t){if(this._paused||0===this._speed)return 0;const e=Math.min(t,200)*this._speed;return this._now+=e,this._notify(e),e}step(t){t<=0||(this._now+=t,this._notify(t))}onTick(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(t){this._listeners.forEach(e=>e(t))}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_SIM_CLOCK__=Ir);function Rr(t){const e=t?.state;return{type:e?.type??t?.constructor?.name,id:e?.id,refid:e?.refid,className:t?.constructor?.name}}const jr=new class{constructor(){this._realTime=0,this._totalTicks=0,this._subs=new Set,this._nextId=1,this._externals=new Set,this._externalNextId=1,this._rafId=null,this._lastWallTime=null,this._emaDt=16.67,this._ticking=!1,this._hasPendingRemoval=!1}get realTime(){return this._realTime}get simTime(){return Ir.now}get isRunning(){return null!==this._rafId}subscribe(t,e){const n=e?.component,i=n?.app??n?.root?.app;if(i&&"boolean"==typeof i.isViewMode&&!i.isViewMode)return()=>{};const s={id:this._nextId++,handler:t,description:e?.description??`<anonymous#${this._nextId-1}>`,componentRef:null!=e?.component&&"undefined"!=typeof WeakRef?new WeakRef(e.component):void 0,targetsGetter:e?.getTargets,metadata:e?.metadata,registeredAt:this._realTime,tickCount:0,totalDurationMs:0,lastDt:0,lastDurationMs:0};return this._subs.add(s),this.isRunning||this.start(),()=>{this._ticking?(s._removed=!0,this._hasPendingRemoval=!0):(this._subs.delete(s),0===this._subs.size&&this.stop())}}tick(t){const e=Math.min(Math.max(t,0),200);this._realTime+=e,Li.enabled&&(this._totalTicks++,e>0&&(this._emaDt=.9*this._emaDt+.1*e));const n=Ir.tick(e),i=Ir.now;if(this._ticking=!0,Li.enabled)for(const t of this._subs){if(t._removed)continue;const e=performance.now();try{t.handler(n,i)}finally{const i=performance.now()-e;t.tickCount++,t.totalDurationMs+=i,t.lastDt=n,t.lastDurationMs=i}}else for(const t of this._subs)t._removed||t.handler(n,i);if(this._ticking=!1,this._hasPendingRemoval){this._hasPendingRemoval=!1;for(const t of this._subs)t._removed&&this._subs.delete(t);0===this._subs.size&&this.stop()}}start(){if(null!==this._rafId)return;if("undefined"==typeof requestAnimationFrame)return;this._lastWallTime=null;const t=()=>{if(null===this._rafId)return;const e=performance.now(),n=null===this._lastWallTime?0:e-this._lastWallTime;this._lastWallTime=e,this.tick(n),null!==this._rafId&&(this._rafId=requestAnimationFrame(t))};this._rafId=requestAnimationFrame(t)}stop(){null!==this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._lastWallTime=null}registerExternalAnimation(t,e,n){const i={id:this._externalNextId++,description:t,source:e,metadata:n,registeredAt:this._realTime};return this._externals.add(i),{update:t=>{i.metadata={...i.metadata??{},...t}},unregister:()=>{this._externals.delete(i)}}}snapshot(){const t=[];for(const e of this._subs){if(e._removed)continue;let n;const i=e.componentRef?.deref();let s;if(i&&(n=Rr(i)),e.targetsGetter)try{const t=e.targetsGetter();if(null!=t){const e=Array.isArray(t)?t:[t],n=[];for(const t of e)null!=t&&n.push(Rr(t));n.length>0&&(s=n)}}catch{}t.push({id:e.id,description:e.description,componentInfo:n,targetInfos:s,metadata:e.metadata,registeredAt:e.registeredAt,tickCount:e.tickCount,totalDurationMs:Math.round(100*e.totalDurationMs)/100,avgDurationMs:e.tickCount>0?Math.round(e.totalDurationMs/e.tickCount*100)/100:0,lastDt:Math.round(100*e.lastDt)/100,lastDurationMs:Math.round(100*e.lastDurationMs)/100})}const e=[];for(const t of this._externals)e.push({id:t.id,description:t.description,source:t.source,metadata:t.metadata,registeredAt:t.registeredAt,liveDurationMs:Math.round(this._realTime-t.registeredAt)});return{realTime:Math.round(this._realTime),simTime:Math.round(Ir.now),isRunning:this.isRunning,speed:Ir.speed,paused:Ir.isPaused,totalTicks:this._totalTicks,ticksPerSecond:this._emaDt>0?Math.round(1e3/this._emaDt):0,totalSubs:t.length,subscriptions:t,externalAnimations:e}}},Lr=new Map;let Fr=null;function Nr(){Fr&&(Fr(),Fr=null)}function Hr(t){return!t.disposed&&t.retention>0&&!t.isTemplate()&&t.app&&t.app.isViewMode}var Br=new class{add(t){var e;Hr(t)&&!Lr.has(t)&&(Lr.set(t,0),e=t?.root,Fr||(Fr=jr.subscribe(t=>{if(0===t)return;const e=[];for(const[n,i]of Lr){if(!Hr(n)){e.push(n);continue}const s=i+t;s>=n.retention?e.push(n):Lr.set(n,s)}for(const t of e){Lr.delete(t);try{t.disposed||t.removeSelf?.(!0)}catch(t){Zi("RetentionManager removeSelf failed:",t)}}0===Lr.size&&Nr()},{description:"retention timer",component:e,getTargets:()=>Array.from(Lr.keys()),metadata:{get count(){return Lr.size},get preview(){return Array.from(Lr.entries()).slice(0,3).map(([t,e])=>({type:t?.state?.type,id:t?.state?.id??"-",retentionMs:t?.retention,remainingMs:Math.max(0,Math.round(t?.retention-e))}))}}})))}remove(t){Lr.delete(t)&&0===Lr.size&&Nr()}touch(t){t&&Lr.has(t)&&Lr.set(t,0)}dispose(){Nr(),Lr.clear()}get length(){return Lr.size}};const Gr=function(t){return t};function Vr(t){const e=t.indexOf("||");let n="",i="";-1!=e&&(n=t,i=t.substring(e+2,t.length-1).trim(),t=t.replace(t.substring(e,t.length-1),"").trim());const s=t.substr(2,t.length-3).trim().replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".").filter(t=>!!t.trim()),r=s.slice(1);return{defaultValue:i,match:t,originText:n||t,target:s[0],accessor:r.length>0?function(t){return r.reduce((t,e)=>t?t[e]:void 0,t)}:Gr}}function Yr(t){if(!t)return;const e=String(t),n=(e.match(/#{(\S*)}/)||[]).map(t=>Vr(t))[0];if(n)return n.accessor(this.getState(n.target));const i=(e.match(/\${[^}]*}/)||[]).map(t=>Vr(t))[0];if(i){const t=this.root.findById(i.target);return i.accessor(this.getState(t))}return t}function Wr(t,e){if(!t)return;const n=String(t),i=e||wi,s=(n.match(/#{(\S*)}/gi)||[]).map(t=>Vr(t)),r=(n.match(/\${[^}]*}/gi)||[]).map(t=>Vr(t));if(0==s.length&&0==r.length)return n;let o=n;return s.forEach(t=>{const e=i(t.accessor(this.getState(t.target)));o=o.replace(t.match,void 0===e?"":e)}),r.forEach(t=>{const e=this.root.findById(t.target),n=i(t.accessor(e&&e.data));o=o.replace(t.match,void 0===n?"":n)}),o}function Ur(t,e,n){if(!t)return;const i=n||wi,s=String(t),r=(s.match(/#{[^}]*}/gi)||[]).map(t=>Vr(t)),o=(s.match(/\${[^}]*}/gi)||[]).map(t=>Vr(t));return 0!=r.length||0!=o.length?function(){let t=s;return r.forEach(n=>{const s=i(n.accessor(e.getState(n.target)));t=t.replace(n.originText,void 0===s?n.defaultValue||"":s)}),o.forEach(n=>{const s=e.root.findById(n.target),r=i(n.accessor(s&&s.data));t=t.replace(n.originText,void 0===r?n.defaultValue||"":r)}),t}:void 0}class $r{constructor(){}static registerDecorator(t,e){$r.constructors.set(t,e)}static create(t,e,n={},i){const s=$r.constructors.get(t);if(!s)throw new Error(`unknown decorator type: ${t}`);return new s(i,e,n)}}$r.constructors=new Map;class Xr{constructor(){this.overlays=new WeakMap,this._pendingOverlays=new Set}static getInstance(){return Xr.instance||(Xr.instance=new Xr),Xr.instance}addOverlay(t){if(this.overlays.has(t))return!1;const e={element:t,registry:new Map};return this.overlays.set(t,e),!0}removeOverlay(t){if(!this.overlays.has(t))return!1;const e=this.overlays.get(t);for(const[n]of e.registry)this.removeFromOverlay(t,n);return this.overlays.delete(t),!0}addToOverlay(t,e,n,i={}){this.overlays.has(t)||this.addOverlay(t);const s=this.overlays.get(t);s.registry.has(e)||s.registry.set(e,new Map);const r=s.registry.get(e);r.has(n)&&r.get(n).stop();const o=$r.create(n,e,i,t);return r.set(n,o),o.start(),o}removeFromOverlay(t,e,n){if(!this.overlays.has(t))return;const i=this.overlays.get(t);if(!i.registry.has(e))return;const s=i.registry.get(e);let r=null;if(n){if(s.has(n))try{const t=s.get(n);r=n,t&&"function"==typeof t.stop&&t.stop(),s.delete(n)}catch(t){Zi(`데코레이터(${n}) 제거 중 오류:`,t)}}else{const t=Array.from(s.keys());for(const e of t)try{const t=s.get(e);t&&"function"==typeof t.stop&&t.stop(),s.delete(e)}catch(t){Zi(`데코레이터(${e}) 제거 중 오류:`,t)}r="_all_"}0===s.size&&i.registry.delete(e),!r||"data-spread"!==r&&"_all_"!==r||this.restartBorderAnimations(t,e)}restartBorderAnimations(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);for(const[t,i]of n.registry.entries()){if(e&&t===e)continue;const n=i.get("border-highlighting");if(n)try{"function"==typeof n.invalidate&&n.invalidate();const t=n;"function"==typeof t.startAnimations&&t.options&&t.options.animation&&t.startAnimations()}catch(t){Zi("애니메이션 재시작 중 오류:",t)}}}removeAllFromOverlay(t,e){if(!this.overlays.has(t))return;const n=this.overlays.get(t);if(e)for(const[i]of n.registry)this.removeFromOverlay(t,i,e);else{for(const[,t]of n.registry)for(const e of t.values())e.stop();n.registry.clear()}}getDecoratorFromOverlay(t,e,n){const i=this.overlays.get(t);return i?.registry.get(e)?.get(n)}getDecoratorsFromOverlay(t,e){const n=this.overlays.get(t);return n&&n.registry.has(e)?Array.from(n.registry.get(e).values()):[]}getTargetsWithType(t,e){const n=this.overlays.get(t);if(!n)return[];const i=[];for(const[t,s]of n.registry)s.has(e)&&i.push(t);return i}updateInOverlay(t,e,n,i){const s=this.getDecoratorFromOverlay(t,e,n);s&&s.update(i)}invalidateOverlay(t){this.overlays.has(t)&&(this._pendingOverlays.add(t),null==this._rafId&&(this._rafId=requestAnimationFrame(()=>{this._rafId=void 0;const t=Array.from(this._pendingOverlays);this._pendingOverlays.clear();for(const e of t)this._flushOverlay(e)})))}_flushOverlay(t){if(!this.overlays.has(t))return;const e=this.overlays.get(t),n=Array.from(e.registry.entries());for(const[e,i]of n){if(e.disposed){this.removeFromOverlay(t,e);continue}this.getDecoratorsFromOverlay(t,e).forEach(t=>{t.invalidate()})}}}const qr=.5;function Kr(t){const e=t.bulge;return null!=e&&Number.isFinite(e)&&Math.abs(e)>=qr}function Qr(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(i*i+s*s);if(0===r||!Number.isFinite(n)||Math.abs(n)<1e-9)return null;const o=Math.abs(n),a=(r*r+4*o*o)/(8*o),c=n>0?1:-1,l=a-o,h=(t.x+e.x)/2-c*(s/r)*l,d=(t.y+e.y)/2-c*-(i/r)*l;return{cx:h,cy:d,radius:a,startAngle:Math.atan2(t.y-d,t.x-h),endAngle:Math.atan2(e.y-d,e.x-h),clockwise:n<0}}function Zr(t,e,n=0,i=16){const s=e.x-t.x,r=e.y-t.y,o=Math.sqrt(s*s+r*r);if(0===o)return null;const a=r/o,c=-(s/o),l=Number.isFinite(n)?n:0,h=Math.abs(l)>=1e-6?l:i;return{x:(t.x+e.x)/2+a*h,y:(t.y+e.y)/2+c*h,perpX:a,perpY:c}}function Jr(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(i*i+s*s);if(0===r)return 0;const o=s/r,a=-(i/r),c=(t.x+e.x)/2,l=(t.y+e.y)/2;let h=(n.x-c)*o+(n.y-l)*a;if(Math.abs(h)<qr)return 0;return h>r&&(h=r),h<-r&&(h=-r),h}function to(t,e){const n=t.radius,i=Number.isFinite(e)?e:0;return null!=n&&Number.isFinite(n)?Math.max(0,n):Math.max(0,i)}function eo(t,e,n,i,s=16){const r=t.x-e.x,o=t.y-e.y,a=Math.sqrt(r*r+o*o);if(0===a)return null;const c=n.x-e.x,l=n.y-e.y,h=Math.sqrt(c*c+l*l);if(0===h)return null;const d=r/a+c/h,u=o/a+l/h,p=Math.sqrt(d*d+u*u);if(p<1e-9)return null;const f=d/p,m=u/p,g=Math.max(i,s);return{x:e.x+f*g,y:e.y+m*g,bisectorX:f,bisectorY:m}}function no(t,e,n,i){const s=t.x-e.x,r=t.y-e.y,o=Math.sqrt(s*s+r*r),a=n.x-e.x,c=n.y-e.y,l=Math.sqrt(a*a+c*c);if(0===o||0===l)return 0;const h=s/o+a/l,d=r/o+c/l,u=Math.sqrt(h*h+d*d);if(u<1e-9)return 0;const p=h/u,f=d/u,m=(i.x-e.x)*p+(i.y-e.y)*f,g=Math.min(o,l)/2;return Math.max(0,Math.min(m,g))}function io(t){if(0===t.length)return 0;let e;for(const n of t){const t=n.z??0;if(!Number.isFinite(t))return null;if(void 0===e)e=t;else if(Math.abs(t-e)>1e-9)return null}return e??0}function so(t,e){const n=e.x-t.x,i=e.y-t.y,s=Math.sqrt(n*n+i*i);if(!Kr(t))return s;const r=Qr(t,e,t.bulge);if(!r)return s;const o=Math.min(r.radius,s/2),a=2*Math.asin(o/r.radius);return r.radius*a}function ro(t,e){const n=t.path.slice();if(!n||!n.length)return void Zi("path should not be empty");let i=1;const s=[];if(t.isLine()||n.push(n[0]),e<=0)return t.toScene(n[0].x,n[0].y);if(e>=1)return t.toScene(n[n.length-1].x,n[n.length-1].y);for(;n[i];)s.push(so(n[i-1],n[i])),i++;const r=s.reduce(function(t,e){return t+e},0);i=0;let o=0;do{o+=s[i++]}while(o/r<e);o-=s[--i];e=(e-o/r)*(r/s[i]);const a=n[i%n.length],c=n[(i+1)%n.length],{x:l,y:h}=function(t,e,n){if(Kr(t)){const i=Qr(t,e,t.bulge);if(i){let t=i.endAngle-i.startAngle;i.clockwise?t>0&&(t-=2*Math.PI):t<0&&(t+=2*Math.PI);const e=i.startAngle+n*t;return{x:i.cx+i.radius*Math.cos(e),y:i.cy+i.radius*Math.sin(e)}}}return{x:t.x+Math.round((e.x-t.x)*n),y:t.y+Math.round((e.y-t.y)*n)}}(a,c,e);return t.toScene(l,h)}function oo(t,e){return!1}function ao({x:t,y:e},...n){const i=this.path,s=t,r=e;this.path=i.map(t=>({...t,x:t.x+s,y:t.y+r}))}function co(t){const e=t??this.center.x,{rotation:n}=this.state,i=this.fillStyle;if(this.set("rotation",2*Math.PI-n),i&&"gradient"===i.type&&"linear"===i.gradientType){const t=ni(i);t.rotation=(Math.PI-parseFloat(i.rotation||0))%(2*Math.PI),this.set("fillStyle",t)}this.path=this.path.map(t=>({...t,x:2*e-t.x,y:t.y}))}function lo(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 ho(t,e,n){if(n){const e=this.bounds,n=e.height/e.width;let i=t.width-e.width,s=t.height-e.height;i*n>s?s=i*n:i=s/n;let r=t.left-e.left,o=t.top-e.top;return 0!=r&&0!=o?(o=-s,r=-i):0!=r?r=-i:0!=o&&(o=-s),{left:e.left+r,top:e.top+o,width:e.width+i,height:e.height+s}}return t}function uo(t,e){if(e||this.app.rotateStepForced){const e=this.app.rotateStep;return Math.floor((t+e/2)/e)*e}return t}function po(t){return ro(this,t||0)}function fo(){const t=this.path;let e,n,i,s;e=n=t[0].x,i=s=t[0].y;for(let r=1;r<t.length;r++){const o=t[r];o.x<e?e=o.x:o.x>n&&(n=o.x),o.y<i?i=o.y:o.y>s&&(s=o.y)}return{left:e,top:i,width:n-e,height:s-i}}function mo(t){const e=this.bounds;if(Math.round(100*t.width)/100==Math.round(100*e.width)/100&&Math.round(100*t.height)/100==Math.round(100*e.height)/100&&Math.round(100*t.left)/100==Math.round(100*e.left)/100&&Math.round(100*t.top)/100==Math.round(100*e.top)/100)return;const n=0==e.width?1:t.width/e.width,i=0==e.height?1:t.height/e.height;this.path=this.path.map(s=>({...s,x:t.left+(s.x-e.left)*n,y:t.top+(s.y-e.top)*i}))}function go(){const t=this.bounds;return{x:t.left+t.width/2,y:t.top+t.height/2}}function yo(t){if(!t||isNaN(t.x)||isNaN(t.y))return;const e=this.center;if(Math.round(100*t.x)/100==Math.round(100*e.x)/100&&Math.round(100*t.y)/100==Math.round(100*e.y)/100)return;const n=t.x-e.x,i=t.y-e.y;this.path=this.path.map(t=>({...t,x:t.x+n,y:t.y+i}))}function bo(){const{x:t,y:e}=this.center;return{x:t,y:e,z:this.state.zPos}}function _o(t){const{x:e,y:n,z:i}=t||{};this.center={x:e,y:n},isNaN(i)||this.setState("zPos",Number(i))}function vo(){const{rotationX:t,rotationY:e,rotation:n}=this.state;return{x:t,y:e,z:-n}}function xo(t){const{x:e,y:n,z:i}=t;this.setState({rotationX:e,rotationY:n,rotation:-i})}function wo(){const{width:t,height:e}=this.bounds,{depth:n}=this.state;return{width:t,height:e,depth:n}}function Mo(t){const{width:e,height:n,depth:i}=t,{top:s,left:r}=this.bounds;this.bounds={top:s,left:r,width:e,height:n},this.setState("depth",i)}function So(){return Zi("이 컴포넌트에 get path 가 구현되어있지 않음.",this),[]}function ko(t){Zi("이 컴포넌트에 get path 가 구현되어있지 않음.",this)}function Ao(){return this.path}function Eo(){return this.center}function Co(){return this.nature.mutable}function To(){return this.nature.resizable&&!this.stuck}function Po(){return this.nature.rotatable&&!this.stuck}const Oo={x:1,y:1};function Do(t,e,n){const{offsetX:i,offsetY:s,blur:r,color:o}=function(t){return{offsetX:t.offsetX??t.left??0,offsetY:t.offsetY??t.top??0,blur:t.blur??t.blurSize??0,color:t.color??"transparent"}}(e),a=n.rootModel.get("scale")??Oo;t.shadowOffsetX=i*a.x*Xs,t.shadowOffsetY=s*a.y*Xs,t.shadowBlur=r*a.x*Xs,t.shadowColor=o}function zo(t){const e=t?.app;if(!e?.isEditMode)return!1;const n=e.focusFilter;return!!(t.hidden||n&&!n(t))}function Io(t){t.save(),this.prerender(t);const e=this.app,n=!0===t.__inHiddenSubtree;e?.isEditMode&&((zo(this)||n)&&(t.globalAlpha*=.5),this.hidden&&(t.__inHiddenSubtree=!0)),this.render(t),this.postrender(t),t.__inHiddenSubtree=n,t.restore()}function Ro(t){const e=this.rotatePoint,{scale:n,rotation:i,shadow:s,alpha:r}=this.state,o=(n&&n.x||1)*this._delta.sx,a=(n&&n.y||1)*this._delta.sy,c=(i||0)+this._delta.theta,{tx:l=0,ty:h=0}=this._delta,d=(r||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),s&&Do(t,s,this)}function jo(t){}function Lo(t){this.drawText(t)}function Fo(t,e){t(this)}function No(t){t&&this.prepare&&this.prepare(t=>{this.invalidate()},t=>{Zi(t)})}function Ho(t){!this.textHidden&&this.text&&this.hasTextProperty&&ur(t,this.textBounds,this.textLines(t),this.state)}function Bo(t,e){rr(t,e?{...this.state,...e}:this.state)}function Go(t,e){this.fillStyle&&"transparent"!=this.fillStyle&&(er(t,this.bounds,this.center,e?{...this.state,...e}:this.state,this),function(t){t.shadowColor="transparent"}(t))}function Vo(){return this.get("strokeStyle")}function Yo(t){this.set("strokeStyle",t)}function Wo(){return this.getState("fillStyle")}function Uo(t){this.setState("fillStyle",t)}function $o(){return this.get("fontColor")}function Xo(t){this.set("fontColor",String(wi(t)))}function qo(){return this.getState("rotation")}function Ko(t){this.setState("rotation",Number(wi(t)))}function Qo(){return this.app.isEditMode?["decotag","data-spread"]:[]}function Zo(){const{id:t,tag:e}=this.state;return(t?`#${t}`:"")+(e?`@${e}`:"")}function Jo(){return this.getState("hidden")||!this.data&&0!==this.data&&this.getState("ndns")||this.isTemplate()}function ta(t){this.setState("hidden",t)}function ea(){return this.state.tag}function na(t){this.setState("tag",t)}function ia(){}function sa(t){this.data instanceof Array?this.data=this.data.concat(t):this.data instanceof Object?this.data={...this.data,...t}:this.data??=t}function ra(){const t=this.getState("text");return null==t?"":String(t)}function oa(t){const{textWrap:e,supportMarkdown:n}=this.state;return lr(t||this.getContext(),this.textBounds.width,this.font,this.text,e,n)}function aa(){return hr(this.model)}function ca(){const t=this.get("lineHeight");return t||1.2*this.fontSize}function la(){return this._text_substitutor||(this._text_substitutor=Ur(this.getState("text"),this,void 0)||this.defaultTextSubstitutor),this._text_substitutor}function ha(){const t=this.get("textFormat");return t?function(t,e){if(!t||isNaN(+e))return e;let n,i,s,r,o,a,c,l,h,d,u,p=t.length,f=t.search(/[0-9\-\+#]/),m=f>0?t.substring(0,f):"",g=t.split("").reverse().join(""),y=g.search(/[0-9\-\+#]/),b=p-y,_=t.substring(b,b+1),v=b+("."===_||","===_?1:0),x=y>0?t.substring(v,p):"";if(n=(e="-"===(t=t.substring(f,v)).charAt(0)?-e:+e)<0?e=-e:0,i=t.match(/[^\d\-\+#]/g),s=".",r=i&&i[1]&&i[0]||",",t=t.split("."),e=+(e=e.toFixed(t[1]&&t[1].length))+"",a=t[1]&&t[1].lastIndexOf("0"),l=e.split("."),(!l[1]||l[1]&&l[1].length<=a)&&(e=(+e).toFixed(a+1)),h=t[0].split(r),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],g="",b=d.length%c,p=d.length,v=0;v<p;v++)g+=d.charAt(v),!((v-b+1)%c)&&v<p-c&&(g+=r);e[0]=g}return e[1]=t[1]&&e[1]?"."+e[1]:"",i=e.join(""),"0"!==i&&""!==i||(n=!1),u="+"==t[0].substring(0,1)?n?"-":"+":n?"-":"",m+(u+i)+x}(t,this.textSubstitutor()):this.textSubstitutor()}function da(t){delete this._text_substitutor;const e=wi(t);this.setState("text",null==e?"":String(e))}function ua(){let{paddingTop:t,paddingLeft:e,paddingRight:n,paddingBottom:i}=this.state;i||=0,t||=0,e||=0,n||=0;const{left:s,top:r,width:o,height:a}=this.bounds;return{left:s+e,top:r+t,width:Math.max(o-e-n,0),height:Math.max(a-t-i,0)}}function pa(){return 0}function fa(){return!!this._textHidden}function ma(t){this._textHidden=!!t,this.invalidate()}function ga(){return!0}function ya(t){return t}function ba(t){return Math.pow(t,2)}function _a(t){return 1-Math.sin(Math.acos(t))}function va(t,e={x:1.5}){return Math.pow(t,2)*((e.x+1)*t-e.x)}function xa(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 wa(t,e={x:1.5}){return Math.pow(2,10*(t-1))*Math.cos(20*Math.PI*e.x/3*t)}var Ma={linear:ya,quad:ba,circ:_a,back:va,bounce:xa,elastic:wa},Sa=Object.freeze({__proto__:null,back:va,bounce:xa,circ:_a,default:Ma,elastic:wa,linear:ya,quad:ba});function ka(t){const{duration:e=1e3,easing:n,component:i,step:s=()=>{},onStart:r,onProgress:o,onComplete:a,options:c,repeat:l=!1,delta:h}=t;let d;d="string"==typeof h?Sa[h]:h||ya,"out"===n?d=function(t,e){return function(n){return 1-t(1-n,e)}}(d,c):"inout"===n&&(d=function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(d,c));let u=!1,p=null;return{start:function(){if(u)return this;if(i?.root?.app?.suppressAnimations)return this;u=!0,r&&r();let t=0;const n=()=>jr.simTime;return p=jr.subscribe(()=>{if(!u)return;if(i?.root?.app?.suppressAnimations)return this.stop(),void(t=0);0===t&&(t=n());const r=(n()-t)/e,a=l?r%1:Math.min(r,1);s(d(a,c)),o&&o(a),!(r>=1)||l&&u||(this.stop(),t=0)},{description:"animate()",component:i,metadata:{duration:e,repeat:l}}),this},stop:function(){return u=!1,p&&(p(),p=null),a&&a(),this}}}class Aa{constructor(t,e){this._started=!1,this._unsub=null,this._timeout=null,this.client=t,this.config=e,this._started=!1;const{delta:n="linear",options:i,ease:s}=this.config;let r;r="string"==typeof n?Ma[n]:n,this.delta="out"===s?function(t,e){return function(n){return 1-t(1-n,e)}}(r,i):"inout"===s?function(t,e){return function(n){return n<.5?t(2*n,e)/2:(2-t(2*(1-n),e))/2}}(r,i):r,this.init()}dispose(){this.stop(),delete this.client}init(){}start(){if(this._started)return;if(this.client?.root?.app?.suppressAnimations)return;const{duration:t=2e3,delay:e=0,repeat:n=!1,interval:i=0,onComplete:s}=this.config;this._started=!0;const r=this.config?.type??"animation";let o=0,a=0;const c=()=>jr.simTime,l=()=>{if(!this._started)return;if(this.client?.root?.app?.suppressAnimations)return void this.stop(s);0==o&&(o=c(),this.client?.touch?.());const h=c()-o,d=Math.max((h-e)%(t+i),0)/t,u=i<=0&&a>d;if(a=d,d>=1||u){if(this.step(1),this.client&&this.client.invalidate?.(),!n||!this._started)return this.stop(s),void(o=0);if(i>0)return this._unsub?.(),this._unsub=null,void(this._timeout=setTimeout(()=>{this._timeout=null,this.step(0),this.client&&this.client.invalidate?.(),this._timeout=setTimeout(()=>{this._timeout=null,this._started&&(this._unsub=jr.subscribe(l,{description:`animation: ${r}`,component:this.client,metadata:{duration:t,delay:e,repeat:n,interval:i}}))},i/2)},i/2))}else this.step(this.delta(d)),this.client&&this.client.invalidate?.()};this._unsub=jr.subscribe(l,{description:`animation: ${r}`,component:this.client,metadata:{duration:t,delay:e,repeat:n,interval:i}})}stop(t){this._unsub&&(this._unsub(),this._unsub=null),this._timeout&&clearTimeout(this._timeout),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 Aa{step(t){const{theta:e=6.28}=this.config;this.client.delta?.("theta",t*e)}},vibration:class extends Aa{step(t){const{theta:e=.2617993877991494}=this.config,n=4*e;let i=t*n;t<1/4?i*=-1:t<3/4?i-=2*e:i=n-i,this.client.delta?.("theta",i)}},heartbeat:class extends Aa{step(t){const{scale:e=1.3}=this.config,n=2*(e-1);let i;i=t<.5?1+n*t:1+(1-t)*n,this.client.delta?.({sx:i,sy:i,sz:i})}},moving:class extends Aa{step(t){const{x:e=0,y:n=0}=this.config;this.client.delta?.({tx:t*e,ty:t*n})}},outline:class extends Aa{step(t){const{rideOn:e}=this.config;if(!e||!this.client)return;const n=this.client.root.findById(e);if(!n)return;let i={tx:0,ty:0};const s=this.client.delta("");s&&"object"==typeof s&&"tx"in s&&"ty"in s&&(i=s);const{tx:r,ty:o}=i,a=n.outline(t),{x:c,y:l}=this.client.center,h=this.client.toScene(c,l);this.client.delta({tx:a.x-h.x+r,ty:a.y-h.y+o})}},fade:class extends Aa{step(t){const{startAlpha:e=1,endAlpha:n=0}=this.config,i=Math.max(Math.min(e,n,1),0),s=2*(Math.min(Math.max(e,n,1),1)-i);let r;r=t<.5?s*t:(1-t)*s,this.client.delta?.("fade",r)}},waypoint:class extends Aa{constructor(){super(...arguments),this._startX=0,this._startY=0,this._endX=0,this._endY=0}start(){let{toComponent:t,fromComponent:e}=this.config;e||(e=t);const n=e.center,i=t.center,{x:s,y:r}=e.toScene(n.x,n.y),{x:o,y:a}=t.toScene(i.x,i.y);this._startX=s,this._startY=r,this._endX=o,this._endY=a;const c=this.config.yawOffset??Math.PI/2,l=Math.atan2(a-r,o-s)+c;this.client.location={x:s,y:r},this.client.setState("rotation",l),super.start()}stop(t){const{toComponent:e,finalize:n="snap"}=this.config;if(super.stop(t),"snap"===n&&e){const t=e.center,n=e.toScene(t.x,t.y);this.client.delta({tx:0,ty:0}),this.client.location=n}}step(t){const e=(this._endX-this._startX)*t,n=(this._endY-this._startY)*t;this.client.location={x:this._startX+e,y:this._startY+n}}}};function Ca(t,e){const n=e.type?Ea[e.type]:void 0;return n?new n(t,e):null}const Ta={gradation:function(t,e,n){const{subType:i,from:s,to:r,colors:o}=n;let a;switch(i){case"linear":default:a=e.createLinearGradient(s.x,s.y,r.x,r.y);break;case"radial":a=e.createRadialGradient(s.x,s.y,s.r,r.x,r.y,r.r)}o&&(o.forEach(function(t){a.addColorStop(t.endPoint,t.color)}),e.fillStyle=a,e.fill())},shadow:Do};function Pa(t){return this._animate&&this._animate.stop(),this._animate=ka({component:this,...t}),this._animate}function Oa(t,e){return function(t,e,n){const i=Ta[n.type];i&&i(t,e,n)}(this,t,e)}const Da=100;function za(t,e){if(null!==e){if("number"==typeof e){if(!Number.isFinite(e))return;if(!Number.isInteger(e))return Math.round(e*Da)/Da}return e}}function Ia(t){if(null==t||"object"!=typeof t)return t;for(const e in t){const n=t[e];null===n?delete t[e]:"number"==typeof n?Number.isFinite(n)?Number.isInteger(n)||(t[e]=Math.round(n*Da)/Da):delete t[e]:"object"==typeof n&&Ia(n)}return t}function Ra(...t){return JSON.stringify(this.hierarchy,za,...t)}function ja(){delete this._model[""],"chartjs"!==this._model.type&&delete this._model.chart}function La(t){this.rootModel.closeScene(t)}function Fa(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 Na(){this.parent&&this.parent.invalidate()}function Ha(){const t=this.nature["value-property"]||"text";return"value"==t?this.getState("value"):this[t]}function Ba(t){const e=this.nature["value-property"]||"text";"value"==e?this.setState("value",t):this[e]=t}function Ga(){return this.getState("data")}function Va(t){this.setState("data",t),this.touch()}function Ya(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 Wa(){return!this._mappings&&this.parent&&this.buildMappings(),this._mappings}function Ua(){return Number(this.get("retention"))||0}function $a(){if(this.app.isViewMode&&!this.isTemplate()){if(!this._animation){const t=this.state.animation;t&&t.oncreate&&(this._animation=Ca(this,t.oncreate))}return this._animation}}function Xa(){return!!this.animation?.started}function qa(t){this.animation&&(this.animation.started=t)}function Ka(){}function Qa(t,e,n,i){const s=e.get("class");if(!s)return!1;return(s.split(" ")||[]).indexOf(t.substr(1))>=0}function Za(t,e,n,i){return t==e.get("type")}function Ja(t,e,n,i){if("(all)"==t)return!0;switch(t.charAt(0)){case"#":return function(t,e){return t.substring(1)==e.get("id")}(t,e);case".":return Qa(t,e);case"(":return function(t,e,n,i){switch(t){case"(all)":return!0;case"(self)":return i===e;case"(root)":return!i.parent&&i===e;case"(descendant)":return i!==e;case"(child)":return i===e.parent;default:return!1}}(t,e,0,i);default:return Za(t,e)}}function tc(t,e,n,i,s,r){return t(e,n,i,s)&&r.push(n),n.components&&n.components.forEach(n=>{tc(t,e,n,i,s,r)}),r}function ec(t,e,n,i){switch(t){case"(all)":return!0;case"(parent)":return n&&n.parent===e;case"(child)":case"(children)":return n&&n===e.parent;case"(sibling)":case"(siblings)":return n&&n.parent===e.parent&&n!==e;default:return!1}}function nc(t,e,n){if("(root)"==t)return[e];if("(self)"==t)return n?[n]:[];let i;switch(t.charAt(0)){case"#":const n=e.root.findAllById?.(t.substring(1));return n||[];case".":i=Qa;break;case"(":i=ec;break;default:i=Za}return tc(i,t,e,n,e,[])}function ic(t,...e){if(t(this,...e))return this}function sc(t,...e){return"string"==typeof t?nc(t,this,e[0]||this):"function"==typeof t&&t(this,...e)?[this]:void 0}function rc(t,e,n){if(!this.capturable||n?.(this))return!1;const i=this.fromParent(t,e);return this.contains(i.x,i.y)?this:void 0}function oc(t){return this.anchors.find(e=>e.name===t)}function ac(t){return!0}function cc(t){return this._parent.getContext(t??this)}function lc(){return this.isRoot()?this:this.parent&&this.parent.root}function hc(){return this.isRootModel()?this:this.parent&&this.parent.rootModel}function dc(){return this._parent}function uc(t){this._parent=t}function pc(){return this.nature.anchors||[]}function fc(){let t=this.position,e=this;for(;"static"===t&&e.parent;)e=e.parent,t=e.position;return"static"==t}function mc(){if(this.parent&&this.parent.layout.isStuck(this)||this.get("locked"))return!0;const t=this.app?.focusFilter;return!(!this.app?.isEditMode||!t||t(this))}function gc(){if(!1===this.get("capturable"))return!1;const t=this.app?.isEditMode;if(!t&&this.hidden)return!1;if(t){if(this.get("locked"))return!1;const t=this.app.focusFilter;if(t&&!t(this))return!1}return!0}function yc(){return this.app?.isViewMode&&this.isPositionable()?this.state.position??"static":"static"}function bc(){return this.app&&this.app.isViewMode&&this.state.origin||""}function _c(){const{offsetX:t=0,offsetY:e=0}=this.state;return{x:t,y:e}}function vc(){return!this._app&&this.parent&&(this._app=this.parent.app),this._app}const xc={},wc={mutable:!1,resizable:!0,rotatable:!0,properties:[],"value-property":"text"},Mc=[],Sc=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"]),kc={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0};let Ac=0;const Ec={};const Cc=new FinalizationRegistry(t=>{!function(t){Ac--;let e=Ec[t];e||(e=Ec[t]={up:0,down:0}),e.down++}(t)});class Tc{static get nature(){return wc}static register(t,e){if(!e)return xc[t];xc[t]=e}static types(){return Object.keys(xc)}static get residents(){return Ec}static get residentsCount(){return Ac}static registerDecorator(t,e){$r.registerDecorator(t,e)}constructor(t,e){if(this._readyInvoked=!1,this._app=e,this._model=t||{},this._model.event&&"object"==typeof this._model.event&&!Array.isArray(this._model.event)&&!Array.isArray(this._model.eventHandlers)){const t=Rs(this._model.event);t.length>0&&(this._model.eventHandlers=t)}this._state={},this._delta=ni(kc),e&&this.animation?.config&&(1==this.animation.config.autoplay||(this.animation.config.autoplay??!0))&&(this.animation.started=!0),this.clearCache(),Br.add(this),function(t){Ac++;let e=Ec[t];e||(e=Ec[t]={up:0,down:0}),e.up++}(this._model.type),Cc.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))}}invokeReady(){if(!this._readyInvoked)return this._readyInvoked=!0,this.ready()}touch(){this.updatedAt=performance.now(),Br.touch(this)}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=ni(kc))}dispose(){this.resetAnimation(),this.disposeMappings();const t=this.parent;t&&"function"==typeof t.removeItem&&-1!==t._items?.indexOf?.(this)&&t.removeItem(this),t?.removeComponent?.(this),delete this._text_substitutor,delete this._value_substitutor,this._disposed=!0,this._realObject&&(this._realObject.dispose(),this._realObject=void 0),this.retention&&Br.touch(),this.clearCache(),delete this._app}get nature(){return this.constructor.nature}get disposed(){return!!this._disposed}isLayer(){return!1}isGroup(){return!1}isContainer(){return!1}isLine(){return!1}isRoot(){return!1}isRootModel(){return!1}is3dish(){return!0}get is3dMode(){return!1}isIn3DSpace(){return!!this._realObject}isTemplate(){return!!this.get("templatePrefix")}isHTMLElement(){return!1}isConnectable(){return!1}isIdentifiable(){return!0}isPositionable(){return this.parent?.isRootModel()}replaceRefids(t){}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=this;return this._applyProps(this._model,t,{getBeforeVal:function(t){return n._model[t]},clearState:!0,sensitive:!1,beforeFillStyle:function(t,e){t.hasOwnProperty("retention")&&Br.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 refid(){return this.get("refid")}get hierarchy(){const t=ni(this._model);return this.volatile.forEach(e=>{delete t[e]}),Ia(t)}get volatile(){return Mc}_applyProps(t,e,n){const i={},s={};let r=!1;const o=ni(e),a=this;if(Object.getOwnPropertyNames(o).forEach(function(e){const c=n.getBeforeVal(e),l=o[e];!n.sensitive&&function(t,e){return Ie(t,e)}(c,l)||(s[e]=c,i[e]=l,t[e]=l,n.clearState&&delete a._state[e],r=!0)}),r){this._cachedState=null;Object.keys(i).some(t=>!Sc.has(t))&&this.clearCache(),i.hasOwnProperty("text")&&delete this._text_substitutor,n.beforeFillStyle&&n.beforeFillStyle(i,s),i.hasOwnProperty("fillStyle")&&this.onchangeFill(i,s),n.afterFillStyle&&n.afterFillStyle(i,s),i.hasOwnProperty("data")&&this.onchangeData(i,s),this.onchange&&this.onchange(i,s),this.trigger("change",i,s)}return this}contains(t,e){return oo.call(this,t,e)}move(t,...e){ao.call(this,t,...e)}symmetryX(t){co.call(this,t)}symmetryY(t){lo.call(this,t)}adjustResize(t,e,n){return ho.call(this,t,e,n)}adjustRotation(t,e){return uo.call(this,t,e)}outline(t){return po.call(this,t)}get bounds(){return fo.call(this)}set bounds(t){mo.call(this,t)}get center(){return go.call(this)}set center(t){yo.call(this,t)}get location(){return bo.call(this)}set location(t){_o.call(this,t)}get rotate(){return vo.call(this)}set rotate(t){xo.call(this,t)}get dimension(){return wo.call(this)}set dimension(t){Mo.call(this,t)}get path(){return So.call(this)}set path(t){ko.call(this,t)}get drawPath(){return Ao.call(this)}get rotatePoint(){return Eo.call(this)}get mutable(){return Co.call(this)}get resizable(){return To.call(this)}get rotatable(){return Po.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&&Io.call(this,t)}prerender(t){Ro.call(this,t)}render(t){jo.call(this,t)}postrender(t){Lo.call(this,t)}prepare(t,e){Fo.call(this,t,e)}prepareIf(t){No.call(this,t)}drawText(t){Ho.call(this,t)}drawStroke(t,e){Bo.call(this,t,e)}drawFill(t,e){Go.call(this,t,e)}get strokeStyle(){return Vo.call(this)}set strokeStyle(t){Yo.call(this,t)}get fillStyle(){return Wo.call(this)}set fillStyle(t){Uo.call(this,t)}get fontColor(){return $o.call(this)}set fontColor(t){Xo.call(this,t)}get rotation(){return qo.call(this)}set rotation(t){Ko.call(this,t)}get decorators(){return Qo.call(this)}get decotag(){return Zo.call(this)}get hidden(){return Jo.call(this)}set hidden(t){ta.call(this,t)}get tag(){return ea.call(this)}set tag(t){na.call(this,t)}get appendum(){return ia.call(this)}set appendum(t){sa.call(this,t)}defaultTextSubstitutor(){return ra.call(this)}textLines(t){return oa.call(this,t)}get font(){return aa.call(this)}get lineHeight(){return ca.call(this)}get textSubstitutor(){return la.call(this)}get text(){return ha.call(this)}set text(t){da.call(this,t)}get textBounds(){return ua.call(this)}get textRotation(){return pa.call(this)}get textHidden(){return fa.call(this)}set textHidden(t){ma.call(this,t)}get hasTextProperty(){return ga.call(this)}animate(t){return Pa.call(this,t)}effect(t,e){return Oa.call(this,t,e)}serialize(...t){return Ra.call(this,...t)}trim(){ja.call(this)}closeScene(t){La.call(this,t)}delta(t,e){return Fa.call(this,t,e)}invalidate(){Na.call(this)}get value(){return Ha.call(this)}set value(t){Ba.call(this,t)}get data(){return Ga.call(this)}set data(t){Va.call(this,t)}set tap(t){Ya.call(this,t)}get mappings(){return Wa.call(this)}get retention(){return Ua.call(this)}get animation(){return $a.call(this)}get started(){return Xa.call(this)}set started(t){qa.call(this,t)}get controls(){return Ka.call(this)}findFirst(t,...e){return ic.call(this,t,...e)}findAll(t,...e){return sc.call(this,t,...e)}capture(t,e,n){return rc.call(this,t,e,n)}findAnchor(t){return oc.call(this,t)}isDescendible(t){return ac.call(this,t)}getContext(t){return cc.call(this,t)}get root(){return lc.call(this)}get rootModel(){return hc.call(this)}get parent(){return dc.call(this)}set parent(t){uc.call(this,t)}get anchors(){return pc.call(this)}get scalable(){return fc.call(this)}get stuck(){return mc.call(this)}get capturable(){return gc.call(this)}get position(){return yc.call(this)}get origin(){return bc.call(this)}get offset(){return _c.call(this)}get app(){return vc.call(this)}drawEffect(t){Fs.call(this,t)}prepareFill(t,e){nr.call(this,t,e)}prepareFillIf(t){ir.call(this,t)}onchangeFill(t,e){sr.call(this,t,e)}drawImage(t,e,n,i,s,r){Ls.call(this,t,e,n,i,s,r)}mutateBounds(t,e){Dr.call(this,t,e)}mutatePath(t,e,n){zr.call(this,t,e,n)}access(t){return Yr.call(this,t)}substitute(t,e){return Wr.call(this,t,e)}onchangeMappings(t,e){Is.call(this,t,e)}onchangeData(t,e){Os.call(this,t,e)}buildMappings(){Ds.call(this)}executeMappings(t){Ps.call(this,t)}disposeMappings(){zs.call(this)}ondropfile(t,e){fr.call(this,t,e)}transcoordS2P(t,e,n){return _r.call(this,t,e,n)}transcoordP2S(t,e,n){return br.call(this,t,e,n)}transcoordS2T(t,e,n){return xr.call(this,t,e,n)}transcoordT2P(t,e,n){return wr.call(this,t,e,n)}transcoordT2S(t,e,n){return Mr.call(this,t,e,n)}transcoordS2TR(t,e,n){return vr.call(this,t,e,n)}transcoordS2O(t,e,n){return Sr.call(this,t,e,n)}transcoordC2S(t,e,n){return kr.call(this,t,e,n)}transcoordS2C(t,e,n){return Ar.call(this,t,e,n)}toParent(t,e,n){return _r.call(this,t,e,n)}fromParent(t,e,n){return br.call(this,t,e,n)}toScene(t,e,n){return xr.call(this,t,e,n)}fromScene(t,e,n){return Mr.call(this,t,e,n)}toLocal(t,e,n){return kr.call(this,t,e,n)}toGlobal(t,e,n){return Ar.call(this,t,e,n)}toOther(t,e,n){return Sr.call(this,t,e,n)}on(t,e,n){return Wi.call(this,t,e,n)}off(t,e,n){return Ui.call(this,t,e,n)}once(t,e,n){return $i.call(this,t,e,n)}trigger(t,...e){return Xi.call(this,t,...e)}delegate_on(t){return qi.call(this,t)}delegate_off(t){return Ki.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.capabilities=[],Tc.requires3d=!1,Tc.union=Er,Tc.transcoordR=gr,Tc.transcoordRR=yr,Tc.createCanvas=tr,Tc.memoize=es,Tc.mixin=Qi,Tc.drawText=ur,Tc.font=hr,Tc.textLines=lr,Tc.drawStroke=rr,Tc.drawFill=er,Tc.reposition=Or,Tc.RetentionManager=Br,Tc.template=function(t,e,n){var i=Mn.imports._.templateSettings||Mn;n&&qe(t,e,n)&&(e=void 0),t=vn(t),e=Qe({},e,i,hn);var s=Qe({},e.imports,i.imports,hn),r=de(s),o=function(t,e){return an(e,function(e){return t[e]})}(s,r);Re(r,function(t){if(En.test(t))throw new Error("Invalid `imports` option passed into `_.template`")});var a,c,l=0,h=e.interpolate||Tn,d="__p += '",u=RegExp((e.escape||Tn).source+"|"+h.source+"|"+(h===pn?Cn:Tn).source+"|"+(e.evaluate||Tn).source+"|$","g"),p=On.call(e,"sourceURL")?"//# sourceURL="+(e.sourceURL+"").replace(/\s/g," ")+"\n":"";t.replace(u,function(e,n,i,s,r,o){return i||(i=s),d+=t.slice(l,o).replace(Pn,un),n&&(a=!0,d+="' +\n__e("+n+") +\n'"),r&&(c=!0,d+="';\n"+r+";\n__p += '"),i&&(d+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),l=o+e.length,e}),d+="';\n";var f=On.call(e,"variable")&&e.variable;if(f){if(En.test(f))throw new Error("Invalid `variable` option passed into `_.template`")}else d="with (obj) {\n"+d+"\n}\n";d=(c?d.replace(Sn,""):d).replace(kn,"$1").replace(An,"$1;"),d="function("+(f||"obj")+") {\n"+(f?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(a?", __e = _.escape":"")+(c?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+d+"return __p\n}";var m=on(function(){return Function(r,p+"return "+d).apply(void 0,o)});if(m.source=d,rn(m))throw m;return m},Tc.buildSubstitutor=Ur,["rotatePoint","font","lineHeight","retention"].forEach(t=>Tc.memoize(Tc.prototype,t,!1)),["bounds","center","textBounds"].forEach(t=>Tc.memoize(Tc.prototype,t,!0));class Pc 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 i=0;i<e.length;i++){const s=e[(i-1+e.length)%e.length],r=e[(i+e.length)%e.length],o=e[(i+1)%e.length];if(s.x===r.x&&s.y===r.y)continue;const a=to(r,n);let c=Math.sqrt((s.x-r.x)*(s.x-r.x)+(s.y-r.y)*(s.y-r.y)),l=0!==c?Math.atan2(s.x-r.x,s.y-r.y):0,h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;const u=a>0||0!==c?{x:h,y:d}:r;c=Math.sqrt((o.x-r.x)*(o.x-r.x)+(o.y-r.y)*(o.y-r.y)),l=0!==c?Math.atan2(o.x-r.x,o.y-r.y):0,h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;const p=a>0||0!==c?{x:h,y:d}:r;if(0==i?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y),a>0&&t.quadraticCurveTo(r.x,r.y,p.x,p.y),Kr(r)){const e=to(o,n),i=Math.sqrt((r.x-o.x)**2+(r.y-o.y)**2),s=0!==i?Math.atan2(r.x-o.x,r.y-o.y):0,a=Math.sin(s)*Math.min(e,i/2)+o.x,c=Math.cos(s)*Math.min(e,i/2)+o.y,l=Qr({x:p.x,y:p.y},{x:a,y:c},r.bulge);l&&t.arc(l.cx,l.cy,l.radius,l.startAngle,l.endAngle,l.clockwise)}}t.closePath()}}}function Oc(t,e,n){return Math.max(0,Math.min(t,Math.min(n,e)/2))}function Dc(t){const e=class extends t{contains(t,e){const{left:n,top:i,width:s,height:r,lineWidth:o=0}=this.state,a=o/2;return t<Math.max(n+s,n)+a&&t>Math.min(n+s,n)-a&&e<Math.max(i+r,i)+a&&e>Math.min(i+r,i)-a}set path(t){const e=t[0],n=t[2];this.set({left:e.x,top:e.y,width:n.x-e.x,height:n.y-e.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get anchors(){return function(t){const{left:e,top:n,width:i,height:s}=t.bounds,r=e+i/2,o=n+s/2;return[{name:"TOP",position:{x:r,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:r,y:n+s}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){this.set({left:0,top:0,width:0,height:0,...t})}render(t){let{round:e=0}=this.model;const{left:n,top:i,width:s,height:r}=this.bounds;t.translate(n,i),t.beginPath(),e=Oc(e,s,r),e>0?t.roundRect(0,0,s,r,e):t.rect(0,0,s,r),t.translate(-n,-i)}};return es(e.prototype,"path",!1),es(e.prototype,"bounds",!0),e}const zc={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 Ic=20;function Rc(t,e){const n=t.split(/\s+/),i=n.indexOf(e);return-1!=i?n.splice(i,1):n.splice(-1,0,e),n.join(" ")}class jc extends(Dc(Pc)){static get image(){return jc._image||(jc._image=new Image,jc._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=="),jc._image}static toggle(t,e,n,i){if(!e)return void Ji("InfoWindow not defined.");const s=t.root.findById(e);s?s._findInfoWindowByComponent(t)?jc.hide(t,e):jc.show(t,e,n,i):Ji("InfoWindow Not Found.",e)}static hide(t,e){if(!e)return;const n=t.root.findById(e);n?n._removeInfoWindow(t):Ji("InfoWindow Not Found.",e)}static show(e,n,i,s){if(!n)return void Ji("InfoWindow not defined.");const r=e.root.findById(n);if(!r)return void Ji("InfoWindow Not Found.",n);if(r._findInfoWindowByComponent(e))return;const{frontSideTemplate:o="",backSideTemplate:a=""}=r.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">&#88</button>':"",n?'<button class="flipable">&#8652</button>':"","</div>"]:[]).concat(['<div class="info-window-content">',t,"</div>"]).join("")}(t,!i,2==c.length))),0==c.length)return;const l='\n.flip {\n backface-visibility: hidden;\n border-radius: 7px;\n height: auto;\n font: normal 14px helvetica, arial, san serif;\n position: absolute;\n opacity: 0.9;\n transform-origin: 50% 50% 0px;\n transition: all 2s;\n min-width: 100px;\n min-height: 50px;\n background-color: #3e424e;\n box-shadow: 2px 3px 2px 0px rgba(0,0,0,0.15);\n}\n\n#side-1 {\n transform: rotateY(0deg);\n}\n\n.flip:after {\n content: "";\n display: block;\n position: absolute;\n opacity: 0.9;\n width: 0;\n height: 0;\n}\n\n.flip.arrow-top:after {\n left: 45%;\n top: -17px;\n border-left: 10px solid transparent;\n border-bottom: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-right:after {\n left: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-left: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n.flip.arrow-bottom:after {\n left: 45%;\n top: 100%;\n border-left: 10px solid transparent;\n border-top: 18px solid #323b44;\n border-right: 10px solid transparent;\n}\n\n.flip.arrow-left:after {\n right: 100%;\n top: 48%;\n border-top: 10px solid transparent;\n border-right: 18px solid #323b44;\n border-bottom: 10px solid transparent;\n}\n\n#side-2 {\n transform: rotateY(180deg);\n}\n\n.flip-side-1 {\n transform: rotateY(0deg) !important;\n}\n\n.flip-side-2 {\n transform: rotateY(180deg) !important;\n}\n\n.info-window-btns {\n position: absolute;\n top: -18px;\n right: 5px;\n overflow: hidden;\n}\n\n.info-window-content {\n padding: 10px;\n color: #efefef;\n font-size: 13px;\n line-height: 1.4;\n}\n\n.info-window-btns button {\n width: 40px;\n height: 40px;\n float: right;\n border: 0;\n border-radius: 50%;\n background-color: #2a7da1;\n margin-right: 3px;\n text-align: center;\n cursor: pointer;\n font-size: 35px;\n color: #fff;\n line-height: 0;\n}\n\n.info-window-btns button:hover {\n background-color: #60bb23;\n}\n'+r.get("style");let{left:h,top:d}=e.bounds;const{x:u,y:p}=s?e.rootModel.toLocal(s.x,s.y):e.toScene(h,d);h=u,d=p;const f=document.createElement("span");f.style.position="absolute";const m=document.createElement("style");let g,y;m.type="text/css",m.appendChild(document.createTextNode(l)),f.appendChild(m),c[0]&&(g=document.createElement("div"),g.id="side-1",g.className="flip",g.style.display="inline-block",g.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);g&&f.appendChild(g),y&&f.appendChild(y),b.appendChild(f);const _=r._addInfoWindow(e,f,m).signal;if(qs.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),Ks.forEach(function(t){f.addEventListener(t,t=>t.stopPropagation(),{signal:_})}),g){const t=g.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=Rc(y.className,"flip-side-1"),g.className=Rc(g.className,"flip-side-2")},{signal:_});const i=g.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),jc.hide(e,n)},{signal:_})}if(y){const t=y.querySelector(".info-window-btns > .flipable");t&&t.addEventListener("click",function(t){t.preventDefault(),y.className=Rc(y.className,"flip-side-1"),g.className=Rc(g.className,"flip-side-2")},{signal:_});const i=y.querySelector(".info-window-btns > .closable");i&&i.addEventListener("click",function(t){t.preventDefault(),jc.hide(e,n)},{signal:_})}const v=g.offsetWidth,x=g.offsetHeight,w=e.rootModel.target.getBoundingClientRect(),M=[];g&&M.push(g),y&&M.push(y);const S={x:h,y:d};let k=e.toGlobal(S.x,S.y);if(k.x+v/2+w.left<w.right&&k.x-v/2>w.left){if(x+Ic<k.y)return f.style.marginLeft=S.x-v/2+"px",f.style.marginTop=S.y-x-Ic+"px",void M.forEach(t=>t.className+=" arrow-bottom");if(k=e.toGlobal(S.x,S.y+x+Ic),w.bottom>k.y+w.top)return f.style.marginLeft=S.x-v/2+"px",f.style.marginTop=S.y+Ic+"px",void M.forEach(t=>t.className+=" arrow-top")}if(k=e.toGlobal(S.x,S.y),k.x-(v+Ic)>w.left)return f.style.marginLeft=S.x-v-Ic+"px",f.style.marginTop=S.y-x/2+"px",void M.forEach(t=>t.className+=" arrow-right");f.style.marginLeft=S.x+Ic+"px",f.style.marginTop=S.y-x/2+"px",M.forEach(t=>t.className+=" arrow-left")}dispose(){this.infoWindows.map(t=>t.component).forEach(t=>this._removeInfoWindow(t)),super.dispose()}get infoWindows(){return this._windows||(this._windows=[]),this._windows}_findInfoWindowByComponent(t){return this.infoWindows.find(e=>e.component===t)}_addInfoWindow(t,e,n){if(this._findInfoWindowByComponent(t))return;const i=new AbortController;return this._windows.push({component:t,window:e,styleElement:n,abortController:i}),i}_removeInfoWindow(t){const e=this._findInfoWindowByComponent(t);if(!e)return;e.abortController.abort();const n=e.window;n&&n.parentNode.removeChild(n);const i=this.infoWindows.lastIndexOf(e);this.infoWindows.splice(i,1)}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,jc.image,e,n,i,s)}get hasTextProperty(){return!1}get nature(){return zc}}Tc.register("info-window",jc);const Lc={};var Fc={list:function(){return{...Lc}},register:function(t,e){Lc[t]=e},unregister:function(t){delete Lc[t]},get:function(t){if(!t)return;const e=Lc[t];return e||Zi("Layout Not Found - ",t),e}};const Nc=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}};Fc.register("html-absolute",Nc);const Hc=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 Bc(t){const e=t.components.filter(t=>!t.hidden),n=t.getState("layoutConfig")||{},i=e[n&&n.activeIndex||0];return i&&[i]||[]}Fc.register("absolute",Hc);const Gc=new class{reflow(t){const e=t.bounds,n=t.getState("layoutConfig")||{},i={left:0,top:0,width:e.width,height:e.height};t.forEach((t,e)=>{const s=e!=(n.activeIndex||0);t.bounds=i,t.setState("rotation",0),"element"in t&&t.element&&(t.element.style.visibility=s?"hidden":"visible")})}capturables(t){return Bc(t)}drawables(t){return Bc(t)}isStuck(t){return!0}};function Vc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}Fc.register("card",Gc);const Yc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+Vc(e),0),s=t.bounds,r=i>0?(s.width-((n.left||0)+(n.right||0)))/i:s.width,o=s.height-((n.top||0)+(n.bottom||0));let a=0;e.forEach(t=>{const e=Vc(t),i=t.getState("margin")||{};t.bounds={left:r*a+(n.left||0)+(i.left||0),top:0+(n.top||0)+(i.top||0),width:e*r-((i.left||0)+(i.right||0)),height:o-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};function Wc(t){const e=t.getState("layoutConfig");return e&&e.weight||1}Fc.register("linear-horizontal",Yc);const Uc=new class{reflow(t){const e=this.drawables(t),n=t.getState("padding")||{},i=e.reduce((t,e)=>t+Wc(e),0),s=t.bounds,r=i>0?(s.height-((n.top||0)+(n.bottom||0)))/i:s.height,o=s.width-((n.left||0)+(n.right||0));let a=0;e.forEach(t=>{const e=Wc(t),i=t.getState("margin")||{};t.bounds={left:0+(n.left||0)+(i.left||0),top:r*a+(n.top||0)+(i.top||0),width:o-((i.left||0)+(i.right||0)),height:e*r-((i.top||0)+(i.bottom||0))},t.setState("rotation",0),a+=e})}capturables(t){return t.components}drawables(t){return t.app?.isViewMode?t.components.filter(t=>!t.hidden):t.components}isStuck(t){return!0}};Fc.register("linear-vertical",Uc);const $c=new class{constructor(){this.joinType=!0}reflow(t){const e=t.getState("layoutConfig"),n=e&&e.columns||t.getState("columns"),i=e&&e.rows||t.getState("rows"),s=e&&e.widths||t.getState("widths"),r=e&&e.heights||t.getState("heights"),o=s?s.filter((t,e)=>e<n).reduce((t,e)=>t+e,0):n,a=r?r.filter((t,e)=>e<i).reduce((t,e)=>t+e,0):i,c=t.textBounds,l=t.getState("paddingLeft")||0,h=t.getState("paddingTop")||0,d=c.width/o,u=c.height/a;let p=0,f=0;t.components.forEach((t,e)=>{const i=s?s[e%n]:1,o=r?r[Math.floor(e/n)]:1;let a=t.colspan||1,c=0;for(;--a>0;)c+=s?s[(e+a)%n]:1;let m=t.rowspan||1,g=0;for(;--m>0;)g+=r?r[Math.floor(e/n)+m]:1;t.bounds={left:l+p,top:h+f,width:d*(i+c),height:u*(o+g)},t.setState("rotation",0),e%n==n-1?(p=0,f+=o*u):p+=i*d})}capturables(t){return t.components.filter(t=>!t.merged)}drawables(t){return t.components.filter(t=>!t.merged&&!t.hidden)}isStuck(t){return!0}keyNavigate(t,e,n){const i=t.getState("layoutConfig"),s=i&&i.columns||t.getState("columns"),r=i&&i.rows||t.getState("rows"),{row:o,column:a}=t.getRowColumn(e);switch(n.code){case"ArrowUp":if(o>0)return t.getAt?.((o-1)*s+a);break;case"ArrowDown":if(o<r-1)return t.getAt?.((o+1)*s+a);break;case"ArrowRight":if(a<s-1)return t.getAt?.(o*s+a+1);break;case"ArrowLeft":if(a>0)return t.getAt?.(o*s+a-1);break;default:return e}}};function Xc(){const t=arguments,e=t[t.length-1],n=this.event_pump;n.listeners.forEach(i=>{!function(t,e,n,i,s){for(const r in n){const o=n[r];if(Ja(r,i.origin,0,t))for(const t in o){const n=o[t];t==i.name&&(i.listener=e,n.apply(e,s))}}}(n.deliverer,i.listener,i.cloned_handlers,e,t)})}Fc.register("table",$c);class qc{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)",Xc,{event_pump:this})}stop(){this.deliverer.off("(all)",Xc)}on(t,e){const n=Object.assign({},e);Object.keys(n).forEach(e=>{if(0==e.indexOf("?")){const i=n[e],s=e.substr(1),r=t.get(s);delete n[e],r?n[r]=i:Ji("EventPump#on","variable #{selector} is not evaluated on listener")}}),this.listeners.push({listener:t,handlers:e,cloned_handlers:n})}off(t,e){for(let n=0;n<this.listeners.length;n++){const i=this.listeners[n];i.listener!==t||e&&i.handlers!==e||this.listeners.splice(n,1)}}clear(){this.listeners=[]}dispose(){this.stop(),this.clear()}}class Kc{constructor(t){this.eventMaps=[],this.root=t,t.eventMap&&this.add(t,t.eventMap)}set root(t){this._root=t}get root(){return this._root}stop(){this.eventMaps.forEach(t=>t.eventPump.stop())}add(t,e){if(this.root)for(const n in e){const i=e[n];if("(self)"===n&&void 0===t.on)throw new Error("(self) selector not available when deliverer is not a event handlable object.");nc(n,this.root,t).forEach(n=>{const s=new qc(n);s.on(t,i),s.start(),this.eventMaps.push({eventPump:s,listener:t,handlerMap:e,deliverer:n})})}}remove(t,e){const n=this.eventMaps.slice(0);for(let i=0;i<n.length;i++){const s=n[i];s.listener!==t||e&&s.handlerMap!==e||(this.eventMaps.splice(i,1),s.eventPump.dispose())}}clear(){this.eventMaps.slice(0).forEach(t=>t.eventPump.dispose()),this.eventMaps=[]}dispose(){this.stop(),this.clear()}}const Qc=0,Zc=1,Jc=2,tl=0,el=1,nl=2;let il={},sl=0;class rl{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 il;const n=e.target.getBoundingClientRect();return il={x:t.offsetX||e.clientX-n.left,y:t.offsetY||e.clientY-n.top},il}return{x:t.offsetX,y:t.offsetY}}(t);if(this._offsetX=n.x,this._offsetY=n.y,t.touches&&t.touches[0]?(this._clientX=t.touches[0].clientX,this._clientY=t.touches[0].clientY):(this._clientX=t.clientX,this._clientY=t.clientY),"wheel"==t.type)this.deltaX=t.deltaX,this.deltaY=t.deltaY,this.deltaZ=t.deltaZ;else if("drop"==t.type)this.dataTransfer=t.dataTransfer;else if(t.type.match(/^touch/)&&(this._scale=t.scale,this._touches=t.touches,this._changedTouches=t.changedTouches,null==this._scale)){const e=function(t){let e,n,i=0,s=0,r=0;if(1===t.touches.length)return r;Array.from(t.touches).forEach(t=>{e=null!=e?Math.min(t.screenX,e):t.screenX,i=Math.max(t.screenX,i),n=null!=n?Math.min(t.screenY,n):t.screenY,s=Math.max(t.screenY,s)});const o=i-e||0,a=s-n||0;return r=Math.sqrt(Math.pow(o,2)+Math.pow(a,2))||0,r}(t);sl>0&&(this._scale=e/sl),sl=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 ol(t,e,n){if(!t||!t.app)return;if(t.app.isViewMode&&t.hidden)return;n instanceof rl&&e===n.type||(n=new rl(n,e));const i="on"+e;t[i]&&t[i](n),n.isPropagationStopped()||t.trigger(e,n)}class al{constructor(t,e){this.gestureHandlerBuilder=t=>{const e=this[`on${t}`];return t=>{const n=new rl(t),i=this.getChildScrollOffset();return n._offsetX+=this.html_element.scrollLeft+i.scrollLeft,n._offsetY+=this.html_element.scrollTop+i.scrollTop,e(n),n.isDefaultPrevented()&&t.preventDefault(),!1}},this.keyeventHandlerBuilder=t=>this[`on${t}`],this.ondragover=t=>(ol(this.findTarget(t),t.type,t),!1),this.ondrop=t=>(ol(this.findTarget(t),t.type,t),!1),this.ondblclick=t=>(ol(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 Zc:const e=t.offsetX-this.__dragstart_e.offsetX,n=t.offsetY-this.__dragstart_e.offsetY;if(e*e+n*n<16)break;this.status=Jc,ol(this.last_target,"dragstart",this.__dragstart_e),this.__dragmove_e=t,ol(this.last_target,"dragmove",t);break;case Jc:this.__dragmove_e=t,ol(this.last_target,"dragmove",t);break;default:{const e=this.findTarget(t);this.last_enter_target!==e&&(this.last_enter_target&&ol(this.last_enter_target,"mouseleave",t),e&&ol(e,"mouseenter",t),this.last_enter_target=e),ol(e,t.type,t),this.last_target=e}}return!1},this.onmousedown=t=>{if(this.status===Jc)ol(this.last_target,"dragend",t),this.last_target=null,this.status=Qc;else{const e=this.findTarget(t);this.last_target=e,this.status=Zc,this.__dragstart_e=t,ol(e,t.type,t)}return!1},this.onmouseup=t=>{if(this.status===Jc)ol(this.last_target,"dragend",t);else{const e=this.findTarget(t);ol(e,t.type,t),this.last_target===e&&ol(e,"click",t)}return this.last_target=null,this.status=Qc,!1},this.onmouseout=t=>{const e=this.findTarget(t);if(this.status===Jc)ol(this.last_target,"dragend",t);else{if(this.last_target&&this.last_target===e)return;this.last_enter_target&&(ol(this.last_enter_target,"mouseleave",t),delete this.last_enter_target)}return this.last_target=null,this.status=Qc,!1},this.ontouchstart=t=>{const e=this.findTarget(t);return this.last_target=e,this.status=el,this.touchPoints||(this.touchPoints=[]),this.touchPoints.push(t.changedTouches[0]),this.holdTimer=setTimeout(()=>{this.status=tl,ol(this.last_target,"hold",t),delete this.holdTimer},500),ol(e,t.type,t),!1},this.ontouchmove=t=>{if(!t.touches||!t.changedTouches)return ol(this.last_target,"dragstart",t),ol(this.last_target,"dragmove",t),!1;let e=this.findTarget(t);switch(this.status){case el:Array.from(t.changedTouches).forEach(t=>{const e=this.touchPoints.find(e=>e.identifier===t.identifier);if(!e)return;const n=e.clientX-t.clientX,i=e.clientY-t.clientY;return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))>=16?(this.status=nl,void(this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer))):void 0});break;case nl: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 ol(this.last_target,"pinch",t),!1;ol(this.last_target,"pan",t),e=this.last_target;break;default:this.last_enter_target!==e&&(this.last_enter_target&&ol(this.last_enter_target,"mouseleave",t),e&&ol(e,"mouseenter",t),this.last_enter_target=e),this.last_target=e}return ol(e,"touchmove",t),!1},this.ontouchend=t=>{let e=this.findTarget(t);switch(this.status){case nl:e=this.last_target;break;case el:{const n=performance.now(),i=n-this.touchedAt;this.holdTimer&&(clearTimeout(this.holdTimer),delete this.holdTimer,ol(e,i<500?"doubletap":"tap",t),this.touchedAt=n);break}}ol(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=tl,!1},this.onwheel=t=>(ol(this.findTarget(t),t.type,t),!1),this.container=t,this.html_element=e,this.status=Qc,this.last_target=null,this.gesture_handlers=qs.map(t=>this.gestureHandlerBuilder(t)),this.keyevent_handlers=Ks.map(t=>this.keyeventHandlerBuilder(t)),qs.forEach((t,n)=>e.addEventListener(t,this.gesture_handlers[n]),{passive:!1}),Ks.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&&ol(this.last_enter_target,"mouseleave",new CustomEvent("mouseleave")),qs.forEach((t,e)=>this.html_element.removeEventListener(t,this.gesture_handlers[e])),Ks.forEach((t,e)=>this.html_element.removeEventListener(t,this.keyevent_handlers[e])),delete this.gesture_handlers,delete this.keyevent_handlers,delete this.last_target}getChildScrollOffset(){for(const t of this.html_element.children)if(t.scrollTop>0||t.scrollLeft>0)return{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop};return{scrollLeft:0,scrollTop:0}}findTarget(t){const e=this.container.rootModel;if(e?.is3dMode)return e;const n=this.html_element.getBoundingClientRect(),i=this.getChildScrollOffset(),s=t.clientX-n.left+this.html_element.scrollLeft+i.scrollLeft,r=t.clientY-n.top+this.html_element.scrollTop+i.scrollTop;return this.container.capture(s,r)}}class cl{constructor(t){this.params=Object.assign({},t)}excute(){}}class ll extends cl{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)}}function hl(t,e,n,i=0){if(e.length<2)return e;let s=2;for(;s<e.length;s++){const r=e.substring(0,s);if(!(t.measureText(r).width+(r.length-1)*i<n))break}return e.substring(0,s-1)}function dl(t,e,n,i,s=0){const r=String(e).split("\n");return i?[].concat.apply([],r.map(e=>function(t,e,n,i=0){const s=e.split(" "),r=[];let o,a,c=[];for(o=0,a=1;a<=s.length;a++)if(c=s.slice(o,a),t.measureText(c.join(" ")).width+(c.join("").length-1)*i>n){if(a-o==1){const e=hl(t,c[0],n,i);r.push([e]),s.splice(o,1,e,c[0].substring(e.length))}else{for(;""==s[a-1];)a++;r.push(s.slice(o,--a))}o=a}return a-o>1&&r.push(c),0==r.length&&r.push([""]),r}(t,e,n,s))):r.map(t=>t.split(" "))}const ul={},pl={},fl=()=>{};var ml={register:function(t,e,n){ul[t]=e,n&&(pl[t]=n)},unregister:function(t){delete ul[t],delete pl[t]},get:function(t){return ul[t]},getDisposer:function(t){return pl[t]||fl}};function gl(t){if(!t.hasTextProperty||t.textHidden)return;let{text:e="",bold:n=Qs.BOLD,italic:i=Qs.ITALIC,textWrap:s=Qs.TEXT_WRAP,letterSpacing:r=0,fontFamily:o=Qs.FONT_FAMILY,fontColor:a=Qs.FONT_COLOR,textAlign:c=Qs.TEXT_ALIGN,textBaseline:l=Qs.TEXT_BASELINE,fontSize:h=Qs.FONT_SIZE,lineHeight:d=1.2*h}=t.model;const{left:u,top:p,width:f,height:m}=t.textBounds;h||=Qs.FONT_SIZE,d||=1.2*h,t.textHidden=!0;const g=document.createElement("textarea"),y=new AbortController;qs.forEach(function(t){g.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:y.signal})});const b=t.toGlobal(u,p),{rotation:_,scale:v}=function(t){let e=0,n=1,i=t;for(;i;){e+=i.get("rotation")||0;const{x:t,y:s}=i.get("scale")||{x:1,y:1};n*=Math.max(t,s)||1,i=i.parent}return{rotation:e,scale:n}}(t);g.value=e;const x={position:"absolute",width:f+"px",height:m+"px",padding:"0",fontFamily:o,fontSize:h+"px",lineHeight:d+"px",overflow:"hidden",resize:"none",outline:"none",border:"0",backgroundColor:"transparent",display:"inline-block",color:a};switch(n&&(x.fontWeight="bold"),i&&(x.fontStyle="italic"),c){case"right":case"end":x.textAlign="right";break;case"justify":x.textAlign="justify";break;case"left":case"start":x.textAlign="left";break;default:x.textAlign="center"}const w=[n,i,h+"px",o].filter(Boolean).join(" ");function M(e){const n={left:0,top:0},i=d*function(t,e,n,i,s=0){const r=t.getContext();let o;return r.save(),r.font=n,o=dl(r,e,i,t.get("textWrap"),s).length,r.restore(),o}(t,e,w,f,r);switch(x.height=i+"px",l){case"top":case"hanging":break;case"bottom":case"alphabetic":n.top=m-i;break;default:n.top=m/2-i/2}if(!s){const i=function(t,e,n,i){const s=e.split("\n");let r=i;const o=t.getContext();return o.save(),o.font=n,s.forEach(t=>{const e=o.measureText(t).width;e>r&&(r=e)}),o.restore(),r}(t,e,w,f);switch(x.width=i+"px",c){case"right":case"end":n.left=f-i;break;case"left":case"start":break;default:n.left=(f-i)/2}}x.marginLeft=n.left+"px",x.marginTop=n.top+"px",x.transform=`translate(${b.x}px, ${b.y}px) scale(${v}) rotate(${_}rad)`,x.transformOrigin=`${-n.left}px ${-n.top}px`,Object.assign(g.style,x)}M(e);const S=t.root.target_element;S.appendChild(g),g.select();let k,A=!1;g.addEventListener("keydown",function(t){t.stopPropagation(),"Escape"!=t.code&&(t.shiftKey||"Enter"!=t.code&&"NumpadEnter"!=t.code)?setTimeout(()=>{M(g.value)}):(A=k.skipUpdate="Escape"==t.code,"function"==typeof document.createEvent?g.dispatchEvent(k):g.fireEvent(k.eventType,k))},{signal:y.signal}),document.createEvent?(k=document.createEvent("HTMLEvents"),k.initEvent("blur",!0,!1)):(k=document.createEventObject(),k.eventType="blur");const E=t.root.selected,C=function(n){t.root.selected=E,t.textHidden=!1,y.abort(),g.removeEventListener("blur",C,!1),g.parentElement&&g.parentElement.removeChild(g),S.focus(),n.skipUpdate||A||t.app.commander.execute(new ll({changes:[{component:t,before:{text:e},after:{text:g.value}}]}))};g.addEventListener("blur",C,!1)}ml.register("text-editor",{"(root)":{"(self)":{keydown:function(t,e){const{deliverer:n}=e,i=n.selected;return!(1!==i.length||!i[0].hasTextProperty)&&(("Enter"==t.code||"NumpadEnter"==t.code)&&(gl(i[0]),t.preventDefault(),!0))}}},"model-layer":{"(descendant)":{dblclick:function(t,e){gl(e.origin)}}}});const yl=new e.Vector3,bl=new e.Quaternion,_l=new e.Matrix4,vl=new e.Vector3;class xl{constructor(t,n){t instanceof e.Vector3?this.position=t.clone():this.position=t?new e.Vector3(t.x,t.y,t.z):new e.Vector3,n instanceof e.Quaternion?this.rotation=n.clone():this.rotation=n?new e.Quaternion(n.x,n.y,n.z,n.w):new e.Quaternion}compose(t){const e=yl.copy(t.position).applyQuaternion(this.rotation).add(this.position),n=bl.copy(this.rotation).multiply(t.rotation);return new xl(e,n)}inverse(){const t=bl.copy(this.rotation).invert(),e=yl.copy(this.position).applyQuaternion(t).negate();return new xl(e,t)}transformPoint(t){return t.clone().applyQuaternion(this.rotation).add(this.position)}transformPose(t){return this.compose(t)}toMatrix4(t){const n=t??new e.Matrix4;return n.compose(this.position,this.rotation,vl.set(1,1,1)),n}static fromMatrix4(t){const n=new e.Vector3,i=new e.Quaternion,s=new e.Vector3;return t.decompose(n,i,s),new xl(n,i)}static fromObject3D(t,n=!1){if(n){const n=new e.Vector3,i=new e.Quaternion,s=new e.Vector3;return _l.copy(t.matrixWorld).decompose(n,i,s),new xl(n,i)}return new xl(t.position,t.quaternion)}applyToObject3D(t){t.position.copy(this.position),t.quaternion.copy(this.rotation)}static identity(){return new xl}equals(t,e=1e-9){if(Math.abs(this.position.x-t.position.x)>e)return!1;if(Math.abs(this.position.y-t.position.y)>e)return!1;if(Math.abs(this.position.z-t.position.z)>e)return!1;const n=this.rotation.x*t.rotation.x+this.rotation.y*t.rotation.y+this.rotation.z*t.rotation.z+this.rotation.w*t.rotation.w;return 1-Math.abs(n)<e}clone(){return new xl(this.position,this.rotation)}toJSON(){return{position:{x:this.position.x,y:this.position.y,z:this.position.z},rotation:{x:this.rotation.x,y:this.rotation.y,z:this.rotation.z,w:this.rotation.w}}}static fromJSON(t){return new xl(t.position,t.rotation)}}const wl=new e.Euler,Ml=new e.Vector3,Sl=new e.Quaternion,kl=new e.Vector3;function Al(t){const n=t._realObject;if(n?.position&&n?.rotation){const t=n.position,i=n.rotation,s=(new e.Quaternion).setFromEuler(wl.set(i.x,i.y,i.z,"XYZ"));return new xl(new e.Vector3(t.x,t.y,t.z),s)}const i=t.center??{x:0,y:0},s=t.parent?.bounds??{width:0,height:0},r=("function"==typeof t.delta?t.delta():null)??{tx:0,ty:0},o=t.state??{},a=(i.x??0)+(r.tx??0)-(s.width??0)/2,c=(i.y??0)+(r.ty??0)-(s.height??0)/2,l=o.rotation??0,h=o.rotationX??0,d=o.rotationY??0,u=(new e.Quaternion).setFromEuler(wl.set(h,-l,d,"XYZ"));return new xl(new e.Vector3(a,0,c),u)}function El(t){const e=t._realObject?.object3d;if(e)return e.updateWorldMatrix(!0,!1),e.matrixWorld.decompose(Ml,Sl,kl),new xl(Ml,Sl);let n=Al(t),i=t.parent;for(;i&&!i.isRootModel?.();)n=Al(i).compose(n),i=i.parent;return n}function Cl(t,e){const n=t.parent?.bounds??{width:0,height:0},i=("function"==typeof t.delta?t.delta():null)??{tx:0,ty:0,tz:0},s=t._realObject,r=e.position.x-(i.tx??0)+(n.width??0)/2,o=e.position.z-(i.ty??0)+(n.height??0)/2,a=t.bounds??{width:0,height:0},c={left:r-a.width/2,top:o-a.height/2};if(s){const n=s.syncZPosOffset??0,r=t.parent?._realObject,o=r?.geometricOffsetY??0,a=r?.receivingSurfaceY??0;c.zPos=e.position.y-(i.tz??0)-n+o-a}wl.setFromQuaternion(e.rotation,"XYZ"),c.rotationX=wl.x,c.rotation=-wl.y,c.rotationY=wl.z,"function"==typeof t.setState?t.setState(c):"function"==typeof t.set&&t.set(c)}function Tl(t,e){const n=t.parent;if(!n||n.isRootModel?.())return void Cl(t,e);Cl(t,El(n).inverse().compose(e))}function Pl(t){let e=0;for(;t&&!t.isRootModel();)e+=t.get("rotation")||0,t=t.parent;return e%(2*Math.PI)}class Ol extends cl{execute(){this.params.changes.forEach(t=>{const{component:e,to_container:n,to_index:i,to_left:s,to_top:r}=t,o=function(t){if(t.isRootModel())return t.bounds;const{bounds:e,rotatePoint:n}=t;let i=n;return i=t.toScene(i.x,i.y),{left:i.x-(n.x-e.left),top:i.y-(n.y-e.top),width:e.width,height:e.height}}(e),a=Pl(e),c=e._realObject?El(e):null;if(e.removeSelf(!n),e.bounds=o,e.set("rotation",a),n){e.set("rotation",function(t,e){return((t.get("rotation")||0)-Pl(e))%(2*Math.PI)}(e,n));const o=function(t,e){if(e.isRootModel())return t.bounds;const{bounds:n,rotatePoint:i}=t,s=e.fromScene(i.x,i.y),r=e.bounds;return{left:s.x-(i.x-n.left)-r.left,top:s.y-(i.y-n.top)-r.top,width:n.width,height:n.height}}(e,n);t.to_left=void 0!==s?s:o.left,t.to_top=void 0!==r?r:o.top,e.bounds={left:t.to_left,top:t.to_top,width:o.width,height:o.height},void 0===i?n.addComponent(e):n.insertComponentAt(e,i),function(t,e,n){const i=t._realObject;if(!i||!n)return;const s=El(e).inverse().compose(n),r=e?._realObject,o=r?.geometricOffsetY??0,a=r?.receivingSurfaceY??0,c=("function"==typeof t.delta?t.delta()?.tz:0)??0,l=i.syncZPosOffset??0;t.set("zPos",s.position.y-c-l+o-a)}(e,n,c)}})}}class Dl{constructor(t){const e=[],n=[];for(let i=0,s=t.length;i<s;i++){const s=t[i],r=s.left,o=s.left+s.width,a=r+s.width/2,c=s.top,l=s.top+s.height,h=c+s.height/2;e.push({value:r,perpMin:c,perpMax:l},{value:a,perpMin:c,perpMax:l},{value:o,perpMin:c,perpMax:l}),n.push({value:c,perpMin:r,perpMax:o},{value:h,perpMin:r,perpMax:o},{value:l,perpMin:r,perpMax:o})}e.sort((t,e)=>t.value-e.value),n.sort((t,e)=>t.value-e.value),this.xEdges=e,this.yEdges=n}get empty(){return 0===this.xEdges.length&&0===this.yEdges.length}calculateSnap(t,e,n,i){if(0===this.xEdges.length&&0===this.yEdges.length)return{dx:e,dy:n,guides:[]};const s={left:t.left+e,top:t.top+n,width:t.width,height:t.height},r=s.left,o=r+s.width,a=r+s.width/2,c=s.top,l=c+s.height,h=c+s.height/2,d=this.findBestSnap(this.xEdges,[r,a,o],i),u=this.findBestSnap(this.yEdges,[c,h,l],i),p=d?e+d.correction:e,f=u?n+u.correction:n;if(!d&&!u)return{dx:e,dy:n,guides:[]};const m=[];if(d){const e=t.top+f,n=e+t.height;for(const t of d.matches)m.push({axis:"x",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}if(u){const e=t.left+p,n=e+t.width;for(const t of u.matches)m.push({axis:"y",position:t.value,from:Math.min(e,t.perpMin),to:Math.max(n,t.perpMax)})}return{dx:p,dy:f,guides:m}}findBestSnap(t,e,n){let i=n+1,s=0,r=[];for(let o=0;o<3;o++){const a=e[o],c=this.searchNearest(t,a,n);if(!c)continue;const l=Math.abs(c.correction);if(l<i)i=l,s=c.correction,r=c.matches;else if(l===i&&c.correction===s)for(const t of c.matches)r.push(t)}return i<=n?{correction:s,matches:r}:null}searchNearest(t,e,n){const i=t.length;if(0===i)return null;let s=0,r=i;for(;s<r;){const n=s+r>>1;t[n].value<e?s=n+1:r=n}let o=-1,a=n+1;if(s<i){const i=t[s].value-e;i<=n&&(o=s,a=i)}if(s>0){const n=e-t[s-1].value;n<a&&(o=s-1,a=n)}if(o<0||a>n)return null;const c=t[o].value,l=c-e,h=[t[o]];for(let e=o-1;e>=0&&t[e].value===c;e--)h.push(t[e]);for(let e=o+1;e<i&&t[e].value===c;e++)h.push(t[e]);return{correction:l,matches:h}}}function zl(t,e,n,i){const s=Tc.register(t.type);if(!s)return Ji("Class not found",t.type),null;n&&(t.refid=n(t.refid)),t.id&&i&&i(t.id)&&delete t.id;const r=new s(t,e);return t.components&&r.isContainer()&&(t.components.forEach(t=>{const s=zl(t,e,n,i);s&&r.addComponent(s)}),delete t.components),r.created(),r}function Il(t,e){const n=ni(t.hierarchy);return delete n.id,zl(n,t.app,e)}function Rl(t){const e=t.root;if(!e||!e.assist_layers)return null;for(const t of e.assist_layers)if("snap-guide-layer"===t.state?.type)return t;return null}function jl(t,e){if(t.scalable){const n=t.toLocal(e.offsetX,e.offsetY);return t.toParent(n.x,n.y)}return{x:e.offsetX,y:e.offsetY}}const Ll=fi(function(t,e,n){if(!t.hasSameParentForAllSelected||n)return void(t.focused=null);const i=[];e[0].parent.isGroup()?t.focused=e[0].parent:(e.forEach(t=>{t.path.forEach(e=>{i.push(t.toScene(e.x,e.y))})}),t.focused=t.capturePath(i,e))},300);let Fl;ml.register("move-handler",{"model-layer":{"(descendant)":{dragstart:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;if(n.showMoveHandle)return;let s=i.selected;const r=i.selected.filter(t=>!t.stuck);if(s.length!==r.length&&(s=i.selected=r),0==s.length)return;const o=jl(s[0],t);if(this.last_pos=o,this.direction=0,i.focused=s[0].parent,t.altKey){const t=[],e=new Map;i.selected=i.selected.filter(t=>!t.isRootModel()).map(n=>{const s=Il(n,t=>{const n=i.root.getNewRefid();return void 0!==t&&e.set(t,n),n});return t.push({component:s,to_container:n.parent}),s}).map(t=>(t.replaceRefids(e),t)),t.forEach(({component:t,to_container:e})=>{e.addComponent(t)}),this.duplicates=i.selected.map(t=>({component:t}))}else this.changes=ll.before(s);this.snapIndex=function(t){if(0===t.length)return null;const e=t[0].parent;if(!e||!e.components)return null;const n=new Set(t),i=[];for(const t of e.components)t.isLayer?.()||t.stuck||n.has(t)||i.push(t.bounds);return 0===i.length?null:new Dl(i)}(s);const a=n.rootModel?.get("scale"),c=a?(Math.abs(a.x)+Math.abs(a.y))/2:1;this.snapThreshold=5/(c||1)},dragmove:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const s=i.selected;if(0==s.length||!this.last_pos)return;const r=jl(s[0],t);t.shiftKey?2==this.direction&&(this.direction=0):this.direction=2;let o=r.x-this.last_pos.x,a=r.y-this.last_pos.y;if(0==this.direction){if(o*o+a*a<25)return;Math.abs(o)>Math.abs(a)?this.direction=3:this.direction=4}3==this.direction?a=0:4==this.direction&&(o=0);const c=this.snapIndex,l=c&&!t.metaKey&&!t.ctrlKey,h=o,d=a;if(l){const t=function(t){return 0===t.length?null:1===t.length?t[0].bounds:Er(t.map(t=>t.bounds))}(s);if(t){const e=c.calculateSnap(t,o,a,this.snapThreshold);o=e.dx,a=e.dy;const n=Rl(i);n&&(n.snapResult=e.guides.length>0?e:null)}}else{const t=Rl(i);t&&(t.snapResult=null)}s.forEach(t=>{t.move({x:o,y:a},1===s.length)}),this.last_pos={x:r.x-(h-o),y:r.y-(d-a)},Ll(i,s)},dragend:function(t,e){const{origin:n,deliverer:i}=e;if(n.stuck)return;const s=i.selected;if(0==s.length)return;const r=s[0].parent,o=i.focused||e.deliverer;if(this.changes&&!o.isGroup())if(i.hasSameParentForAllSelected&&o&&o!==r){const t=this.changes.map(t=>{const{component:e}=t;return{component:e,to_container:o}});i.app.commander.execute(new Ol({changes:t}))}else ll.after(this.changes,i.app.commander);else if(this.duplicates){this.duplicates=this.duplicates.map(t=>(t.to_container=o,t));const t=new Ol({changes:this.duplicates});i.app.commander.execute(t)}s.forEach(t=>{t.parent&&t.parent.calculateBounds&&t.parent.calculateBounds()}),this.last_pos=null,this.changes=null,this.duplicates=null,this.snapIndex=null,this.snapThreshold=5;const a=Rl(i);a&&a.clear(),Ll(i,s,!0)}}},"(root)":{"(self)":{keydown:function(t,e){const{origin:n,deliverer:i}=e,s={},r=t.shiftKey?n.rootModel.MPP:1;switch(t.which){case 37:s.x=-r,s.y=0;break;case 38:s.x=0,s.y=-r;break;case 39:s.x=r,s.y=0;break;case 40:s.x=0,s.y=r;break;default:return}const o=i.selected;ll.around(i.app.commander,function(){o.forEach(t=>{!t.stuck&&t.move(s,!1)})})}}}}),ml.register("shift-handler",{"model-layer":{"(all)":{dragstart:function(t,e){Fl={x:t.offsetX,y:t.offsetY}},dragmove:function(t,e){const{deliverer:n}=e,i=t.offsetX,s=t.offsetY;n.rootModel.move({x:i-Fl.x,y:s-Fl.y},!1),Fl={x:i,y:s}}}}}),ml.register("zoom-handler",{"model-layer":{"(all)":{wheel:function(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer,i=t.deltaY<0?1:-1,s=n.get("scale")||{x:1,y:1},r=n.get("translate"),o=t.offsetX,a=t.offsetY,c=n.toLocal(o,a),l=.1*i,h={x:s.x+l,y:s.y+l};if(i<0&&s.x<.2||i>0&&s.x>10)return;n.set("scale",h);const d=n.toLocal(o,a);n.set("translate",{x:r.x+(d.x-c.x)*h.x,y:r.y+(d.y-c.y)*h.y})}},"(self)":{dblclick:function(t,e){const n=e.origin;n?.root.fit()}}}});let Nl={},Hl={};function Bl(t){const e={};for(const n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}ml.register("paste-handler",{"(root)":{"(self)":{stylepastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{fillStyle:e,strokeStyle:s,alpha:r,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:m,textBaseline:g,textOverflow:y,paddingTop:b,paddingBottom:_,paddingLeft:v,paddingRight:x}=t.state;Nl=ni({fillStyle:e,strokeStyle:s,alpha:r,lineWidth:o,lineDash:a,lineCap:c,lineJoin:l,fontColor:h,fontSize:d,fontFamily:u,bold:p,italic:f,textAlign:m,textBaseline:g,textOverflow:y,paddingTop:b,paddingBottom:_,paddingLeft:v,paddingRight:x}),n.mode=4}},stylepastestop:function(t){const{deliverer:e}=t,n=e.app;Nl={},4==n.mode&&(n.mode=1)},databindpastestart:function(t){const{deliverer:e}=t,n=e.app,i=e.selected;if(i&&i[0]&&i!==e.rootModel){const t=i[0],{mappings:e}=t.state;Hl=ni({mappings:e}),n.mode=5}},databindpastestop:function(t){const{deliverer:e}=t,n=e.app;Hl={},5==n.mode&&(n.mode=1)},pasteapply:function(t,e){const{deliverer:n}=e,i=n.app;t&&(4==i.mode?ll.around(i.commander,()=>{t.set(Bl({...t.model,...Nl}))}):5==i.mode&&ll.around(i.commander,()=>{t.set(Bl({...t.model,...Hl}))}))},keydown:function(t,e){const{deliverer:n}=e;"Esc"!=t.code&&"Escape"!=t.code||(4==n.app.mode?n.trigger("stylepastestop"):5==n.app.mode&&n.trigger("databindpastestop"))}}},"model-layer":{"(all)":{click:function(t,e){const{deliverer:n}=e,i=n.app;if(4!=i.mode&&5!=i.mode)return;const s=e.origin;4==i.mode?s===n?n.root.trigger("stylepastestop"):s&&ll.around(i.commander,()=>{const t=Bl({...s.model,...Nl});s?.set(t)}):s===n?n.root.trigger("databindpastestop"):s&&ll.around(i.commander,()=>{const t=Bl({...s.model,...Hl});s?.set(t)})}}}});class Gl{constructor(){this.animatorMap=new Map}waypoint(t,e){this.animatorMap.has(t)&&this.off(t);let{from:n,to:i}=e;if("string"==typeof n&&(n=t.root?.findById(n)),"string"==typeof i&&(i=t.root.findById(i)),!i)return void Ji("WaypointAnimation: Source or target component not found");const s=Ca(t,{type:"waypoint",fromComponent:n,toComponent:i,...e,onComplete:()=>{this.off(t)}});s&&(this.animatorMap.set(t,s),s.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 Vl(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?.reset()}ml.register("waypoint-handler",{"model-layer":{"(descendant)":{waypoint:function(t,e){const{origin:n}=e,i=n.root;let{waypointHandler:s}=i;s||(s=new Gl,i.waypointHandler=s),s.waypoint(n,t)},waypointoff:function(t){const{origin:e}=t,n=e.root,{waypointHandler:i}=n;i?i.off(e):Ji("waypoint-handler not found")},waypointreset:Vl},"(self)":{waypointreset:Vl}}},function(t){const{waypointHandler:e}=t;e&&(e.dispose(),delete t.waypointHandler)});class Yl{constructor(){this.animatorMap=new Map}transition(t,e){this.animatorMap.has(t)&&this.off(t);const n=Ca(t,{type:"transition",fromComponent:e.from,toComponent:e.to,...e,onComplete:()=>{this.off(t)}});n&&(this.animatorMap.set(t,n),n.start())}off(t){const e=this.animatorMap.get(t);e&&(e.stop(),this.animatorMap.delete(t))}reset(){for(const t of this.animatorMap.values())t.stop();this.animatorMap.clear()}dispose(){this.reset(),this.animatorMap=null}}function Wl(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?.reset()}function Ul(t){return t<.5?2*t*t:1-2*(1-t)*(1-t)}ml.register("transition-handler",{"model-layer":{"(descendant)":{transition:function(t,e){const{origin:n}=e,i=n.root;let{transitionHandler:s}=i;s||(s=new Yl,i.transitionHandler=s),s.transition(n,t)},transitionoff:function(t){const{origin:e}=t,n=e.root,{transitionHandler:i}=n;i?i.off(e):Ji("transition-handler not found")},transitionreset:Wl},"(self)":{transitionreset:Wl}}},function(t){const{transitionHandler:e}=t;e&&(e.dispose(),delete t.transitionHandler)});class $l{constructor(t){this.active=new Map,this._liveOverlay=new Set,this.unsubscribeTick=null,this._canvas=null,this._ctx=null,this.root=t}isReparenting(t){return this.active.has(t)||this._liveOverlay.has(t)}setLiveOverlay(t,e){e?this._liveOverlay.has(t)||(this._liveOverlay.add(t),this.ensureCanvas()):this._liveOverlay.delete(t)}getState(t){return this.active.get(t)||null}begin(t,e){if(this.cancel(t),this.root?.app?.suppressAnimations)return this.cleanup3D(t),t.clearCache?.(),void t.invalidate?.();const n={fromWorld:e.fromWorld,toWorld:e.toWorld,from3D:e.from3D,to3D:e.to3D,duration:Math.max(e.duration,1),startTime:jr.simTime,progress:0,keepSuppressed:e.keepSuppressed,ease:e.ease};this.active.set(t,n);const i=t._realObject;if(i?.setTransientPlacement){const t={};(e.from3D?.worldQuatLock||e.to3D?.worldQuatLock)&&(t.worldQuatLock=e.to3D?.worldQuatLock??e.from3D?.worldQuatLock),e.keepSuppressed&&(t.keepSuppressed=!0),i.setTransientPlacement({policy:"transitioning",meta:t})}if(n.fromWorld&&this.ensureCanvas(),n.from3D){const e=t._realObject?.object3d;if(e){e.position.copy(n.from3D.pos),e.quaternion.copy(n.from3D.quat);const t=n.from3D.fromScale;t&&e.scale.set(t.x,t.y,t.z)}}this.startLoop()}cancel(t){this.active.has(t)&&this.complete(t)}renderComponent(t,e){if(!this._ctx)return;const n=this._ctx,i=this.active.get(t);let s,r,o,a,c,l=!1;if(i?.fromWorld&&i?.toWorld){const t=i.progress,e=i.fromWorld,n=i.toWorld;s=e.x+(n.x-e.x)*t,r=e.y+(n.y-e.y)*t,o=e.rotation+(n.rotation-e.rotation)*t,a=e.width+(n.width-e.width)*t,c=e.height+(n.height-e.height)*t}else{if(!this._liveOverlay.has(t))return;{if("function"!=typeof t.toScene||!t.parent||!t.bounds)return void this._liveOverlay.delete(t);const e=t.center,n=t.toScene(e.x,e.y);let i=0;for(let e=t.parent;e&&!e.isRootModel?.();e=e.parent)i+=e.state?.rotation||0;const h=t.bounds;s=n.x,r=n.y,o=i,a=h.width,c=h.height,l=!0}}const{translate:h={x:0,y:0},scale:d={x:1,y:1}}=e.model;n.save(),n.translate(h.x,h.y),n.scale(d.x,d.y),n.translate(s,r),n.rotate(o);const u=t.bounds;if(u&&u.width&&u.height){const t=a/u.width,e=c/u.height;n.scale(t,e),n.translate(-(u.left+u.width/2),-(u.top+u.height/2))}l?t.draw(n):t.render(n),n.restore()}beginDraw(){if(!this._canvas||!this._ctx)return;this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._ctx.save();const t=globalThis.devicePixelRatio||1;this._ctx.scale(t,t)}endDraw(){if(!this._ctx)return;const t=this.root?.model_layer;if(t&&(this.active.size>0||this._liveOverlay.size>0)){const e=new Set;for(const n of this.active.keys())e.has(n)||(e.add(n),this.renderComponent(n,t));for(const n of[...this._liveOverlay])e.has(n)||(e.add(n),this.renderComponent(n,t))}this._ctx.restore()}resize(){if(!this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element.clientWidth,n=t.element.clientHeight;t.fitSize(this._canvas,!0,e,n)}dispose(){for(const[t]of this.active)this.cleanup3D(t);this.active.clear(),this._liveOverlay.clear(),this.stopLoop(),this.removeCanvas()}ensureCanvas(){if(this._canvas)return;const t=this.root?.model_layer;if(!t?.element)return;const e=t.element;this._canvas=document.createElement("canvas"),this._canvas.width=1,this._canvas.height=1,this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.style.zIndex="150",this._canvas.setAttribute("scene","transition-canvas"),e.appendChild(this._canvas);const n=e.clientWidth,i=e.clientHeight;t.fitSize(this._canvas,!0,n,i),this._ctx=this._canvas.getContext("2d")}removeCanvas(){this._canvas&&(this._canvas.parentNode?.removeChild(this._canvas),this._canvas=null,this._ctx=null)}startLoop(){this.unsubscribeTick||(this.unsubscribeTick=jr.subscribe(()=>this.tick(),{description:"reparent",component:this.root,getTargets:()=>[...this.active.keys()]}))}stopLoop(){this.unsubscribeTick&&(this.unsubscribeTick(),this.unsubscribeTick=null)}tick(){if(this.root?.app?.suppressAnimations){const t=[...this.active.keys()];for(const e of t)this.complete(e);return}const t=jr.simTime,e=[];for(const[n,i]of this.active){const s=t-i.startTime,r=Math.min(s/i.duration,1),o="linear"===i.ease?r:Ul(r);if(i.progress=o,i.from3D&&i.to3D){const t=n._realObject?.object3d;if(t){t.position.lerpVectors(i.from3D.pos,i.to3D.pos,o),t.quaternion.copy(i.from3D.quat).slerp(i.to3D.quat,o);const e=i.from3D.fromScale,n=i.from3D.toScale;e&&n&&t.scale.set(e.x+(n.x-e.x)*o,e.y+(n.y-e.y)*o,e.z+(n.z-e.z)*o);const s=i.to3D.worldQuatLock??i.from3D.worldQuatLock,r=t.parent;s&&r&&(r.updateWorldMatrix(!0,!1),r.getWorldQuaternion(t.quaternion),t.quaternion.invert(),t.quaternion.multiply(s))}}n.clearCache?.(),n.invalidate?.(),r>=1&&e.push(n)}for(const t of e)this.complete(t);0===this.active.size&&this.stopLoop()}complete(t){this.cleanup3D(t),this.active.delete(t),t.clearCache?.(),t.invalidate?.();let e=!1;for(const[,t]of this.active)if(t.fromWorld){e=!0;break}e||0!==this._liveOverlay.size||this.removeCanvas()}cleanup3D(t){const e=this.active.get(t),n=t._realObject;if(n){if(n.object3d){const t=n.dimensionScale??{x:1,y:1,z:1};n.object3d.scale.set(t.x,t.y,t.z)}e?.keepSuppressed?n.clearTransientPlacement?.():(n.suppressTransform=!1,n.clearTransientPlacement?.(),n.update?.())}}}function Xl(t){return class extends t{get showMoveHandle(){return!1}}}const ql=[];class Kl extends(Xl(Dc(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 Fc.get(this.get("layout"))||Hc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){if(!t)return;const{animated:n=!1,duration:i=2e3,ease:s="inout"}=e,r=t.parent;if(!r||r===this)return;const o=t=>{let e=0,n=t;for(;n&&!n.isRootModel?.();)e+=n.state?.rotation||0,n=n.parent;return e},a=!(!t._realObject?.object3d||!this._realObject?.object3d);let c=null,l=null,h=null,d=null;if(a){const n=e.toParent3D??this._realObject.object3d,i=t._realObject.object3d,s=t._realObject.dimension||{width:1,height:1,depth:1};n.updateWorldMatrix(!0,!1),i.updateWorldMatrix(!0,!1),n.attach(i),c={pos:i.position.clone(),quat:i.quaternion.clone(),fromDimW:s.width||1,fromDimH:s.height||1,fromDimD:s.depth||1},t._realObject.suppressTransform=!0}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);h={x:i.x,y:i.y,rotation:o(r),width:e.width,height:e.height}}if(this.addComponent(t,{silent:!0}),a){const e=t._realObject.object3d;t.clearCache();const n=t._realObject.position,i=t._realObject.rotation,s=t._realObject.dimension||{width:1,height:1,depth:1},r=s.width||1,o=s.height||1,a=s.depth||1,h={x:c.fromDimW/r,y:c.fromDimH/o,z:c.fromDimD/a};l={pos:e.position.clone().set(n.x,n.y,n.z),quat:e.quaternion.clone().setFromEuler(e.rotation.clone().set(i.x,i.y,i.z))},c.fromScale=h,c.toScale={x:1,y:1,z:1},e.position.copy(c.pos),e.quaternion.copy(c.quat)}else{const e=t.bounds,n=t.center,i=t.toScene(n.x,n.y);d={x:i.x,y:i.y,rotation:o(this),width:e.width,height:e.height}}if(n){const e=this.root?.transitionEffect;e&&e.begin(t,{fromWorld:h,toWorld:d,from3D:c,to3D:l,duration:i,ease:s})}}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,s=t.parent;if(s){if(this===s)return;"function"==typeof s.removeItem&&-1!==s._items?.indexOf?.(t)&&s.removeItem(t),s.removeComponent(t,n||i)}const r=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,r),t.delegate_on(this),i?(s&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,r),t.trigger("added",this,t,r),delete t._silentAdd):n||t.trigger("added",this,t,r),this.root&&this.root.isReady&&t.invokeReady()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const s=this._components.splice(0,e);this._components=s.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||ql).indexOf(t)}size(){return(this._components||ql).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const s=this._components.splice(1);this._components=i.concat(s),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return nc(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const s=this.components[i].findAll(t,...e);s&&(n=n.concat(s))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return nc(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}contains(t,e){let n=super.contains(t,e);if(!n){const{left:i,top:s,width:r,height:o}=this.state;n=t<Math.max(i+r,i)&&t>Math.min(i+r,i)&&e<Math.max(s+o,s)&&e>Math.min(s+o,s)}return n}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const s=this.bounds;i.x-=s.left,i.y-=s.top;const r=this.layout.capturables(this);for(let s=r.length-1;s>=0;s--){const o=r[s];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:s,width:r,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+r||a.y<s||a.y>s+o)return!1;a.x-=i,a.y-=s,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const s=i.capturePath(n,e);if(s)return s}return this.focusible&&this}render(t){if("popup"===this.position)return;const{left:e=0,top:n=0,width:i,height:s}=this.bounds;t.beginPath(),t.rect(e,n,i,s),t.closePath(),this.drawFill(t),this.drawStroke(t)}postrender(t){if("popup"===this.position)return void super.postrender(t);const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:s,height:r}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,s,r),t.clip(),t.closePath()),({top:i,left:n}=this.state),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)||e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>Tc.memoize(Kl.prototype,t,!1));const Ql=1e6;const Zl=[],Jl=fi(function(){Zl.forEach(t=>{t.resize()})},100);"undefined"!=typeof window&&window.addEventListener("resize",Jl);class th extends Kl{get showMoveHandle(){return!1}static onBeforeDispose(t){return th._beforeDisposeHooks.push(t),()=>{const e=th._beforeDisposeHooks.indexOf(t);e>=0&&th._beforeDisposeHooks.splice(e,1)}}constructor(t,e){super(Object.assign({type:"root",scale:{x:1,y:1}},t||{}),e),this._hasSameParentForAllSelected=!1,this._maxRefid=e?.isViewMode?Ql:0,t=t||{},this.fitMode=t.model&&t.model.fitMode,this._app=e,this.style=t.style,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={},this._serviceMap=new Map,this.transitionEffect=new $l(this),this.target_element=t.target_element,this.rebuildContentModel(this.model.model),Zl.push(this)}registerService(t,e){this._serviceMap.set(t,e)}getService(t){return this._serviceMap.get(t)}unregisterService(t){this._serviceMap.delete(t)}dispose(){for(const t of th._beforeDisposeHooks)try{t(this)}catch(t){Zi("RootContainer beforeDispose hook 실패",t)}this.transitionEffect?.dispose(),this._app&&this._app.dispose(),super.dispose(),this._disposeAllResources(),this.target_element=null,this._refresh_mapping_debouncer&&"function"==typeof this._refresh_mapping_debouncer.cancel&&this._refresh_mapping_debouncer.cancel(),delete this._refresh_mapping_debouncer;const t=Zl.indexOf(this);t>=0&&Zl.splice(t,1),this.refidIndexMap.clear(),this.indexMap.clear(),this._serviceMap.clear(),this._maxRefid=0}isRoot(){return!0}get app(){return this._app}get target_element(){return this._target_element}set target_element(t){this._ua_event_handler&&(this._ua_event_handler.dispose(),delete this._ua_event_handler),t&&(t.style.position="absolute",t.style.cursor="default",t.style.overflow="hidden",t.setAttribute("scene","root-container"),this._ua_event_handler=new al(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&&Zi("Template replaced (duplicated)",t,e,n),this.templateMap[t]=e,delete this.templatePrefixes}removeTemplate(t,e){const n=this.templateMap[t];n!==e?Ji("Removing template failed (different)",t,e,n):delete this.templateMap[t],delete this.templatePrefixes}findTemplateFor(t){this.templatePrefixes||(this.templatePrefixes=Object.keys(this.templateMap).sort().reverse());const e=this.templatePrefixes.find(e=>t.startsWith(e));if(e)return this.templateMap[e]}addIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);i?i.push(e):this.indexMap.set(n,[e])}removeIndex(t,e){if(!t)return;const n="#"===t[0]?t.substring(1):t,i=this.indexMap.get(n);if(!i)return;const s=i.indexOf(e);-1!==s&&(i.splice(s,1),0===i.length&&this.indexMap.delete(n))}addRefidIndex(t,e){null==t&&(t=this.getNewRefid(),e.set("refid",t)),(this._app?.isViewMode||"number"!=typeof t||t<Ql)&&(this._maxRefid=Math.max(t,this._maxRefid));const n=this.refidIndexMap.get(t);n&&Zi("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?Zi("Refid Removing index failed (has not to be)",t,e,n):this.refidIndexMap.delete(t)}getNewRefid(){return this._maxRefid=(this._maxRefid||0)+1,this._maxRefid}async subscribe(t,e){this._app.isViewMode&&t&&this._app&&(e._subscription=await this._app.subscribe(t,e))}async unsubscribe(t,e){e._subscription&&(await e._subscription.unsubscribe(),delete e._subscription)}findById(t){if(!t)return null;const e=this.indexMap.get("#"===t[0]?t.substring(1):t);return e?e[0]:null}findAllById(t){return t&&this.indexMap.get("#"===t[0]?t.substring(1):t)||th.EMPTY_ARRAY}findByRefid(t){return this.refidIndexMap.get(t)}findOrCreate(t){const e=this.findAllById(t);if(!e||0===e.length){if(this.app&&!this.app.isEditMode){const e=this.findTemplateFor(t);if(e){const n=zl(Object.assign(ni(e.hierarchy),{id:t,templatePrefix:""}),this.app);return this.model_layer.addComponent(n),[n]}}return[]}return e}resize(){this.components.forEach(t=>{t.resize&&t.resize()}),this.invalidate()}fit(t){const{width:e,height:n,fitMode:i}=this.model_layer.model,s=this.target_element,r=this.model_layer;if(this.fitMode=t||this.fitMode||i||"ratio",e&&n&&s&&s.clientWidth&&s.clientHeight){switch(this.fitMode){case"center":!function(t,e,n){const i=t.unitScale,{width:s,height:r}=e.model;e.set("scale",{x:i,y:i}),e.set("translate",{x:Math.max((n.clientWidth-s*i)/2,0),y:Math.max((n.clientHeight-r*i)/2,0)})}(this,r,s);break;case"both":!function(t,e,n){const{width:i,height:s}=e.model,r=n.clientWidth,o=n.clientHeight;e.set("scale",{x:r/i,y:o/s}),e.set("translate",{x:0,y:0})}(0,r,s);break;case"width":!function(t,e,n){const i=n.clientWidth/e.get("width");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,r,s);break;case"height":!function(t,e,n){const i=n.clientHeight/e.get("height");e.set("scale",{x:i,y:i}),e.set("translate",{x:0,y:0})}(0,r,s);break;case"ratio":!function(t,e,n){const{width:i,height:s}=e.model,r=n.clientWidth,o=n.clientHeight,a=r/i,c=o/s,l=Math.min(a,c);e.set("scale",{x:l,y:l}),e.set("translate",{x:(r-i*l)/2,y:(o-s*l)/2})}(0,r,s);break;default:!function(t,e){const n=t.unitScale;e.set("scale",{x:n,y:n}),e.set("translate",{x:0,y:0})}(this,r)}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=>{ml.getDisposer(t).call(null,this)}),this.assist_layers&&this.assist_layers.forEach(t=>{t.dispose(),this.removeComponent(t)}),delete this.assist_layers,this.model_layer&&this.model_layer.dispose(),this.model_layer&&this.removeComponent(this.model_layer),delete this.model_layer,this.indexMap=new Map,this.refidIndexMap=new Map,this.templateMap={}}rebuildContentModel(t,e){let n,i;if(e?.preserveThreeD&&this.model_layer?.is3dMode){const t=this.model_layer._threeCapability;t&&(i=t.captureSessionState()),n=this.model_layer.detachThreeCapability()}this._disposeAllResources(),this.eventEngine=new Kc(this);const s=this._app?.loadTracker;(t=t||{}).type="model-layer",t.dataLagMonitor&&this._app&&this._app.initLagTracker(t.dataLagMonitor),s?.setPhase("compile"),this.model_layer=zl(t,this.app),e?.preserveThreeD&&(this.model_layer._rebuildPreserveThreeD=!0),this.addComponent(this.model_layer),this.model_layer.target=this.target_element,this.assist_layers=(this.model.layers||[]).map(t=>{const e=zl(t,this.app);if(e)return this.addComponent(e),e.target=this.target_element,e;Zi("Layer compile failed",t)}).filter(Boolean),this.assist_handlers=(this.model.handlers||[]).map(t=>{const e={};return this.eventEngine.add(e,ml.get(t)),e}),n&&(this.model_layer.adoptThreeCapability(n),i&&n.restoreSessionState(i)),s?.setPhase("assets"),this._ready=!0,this.traverse(t=>t.invokeReady()),s?.checkComplete(),s?.startGlobalTimeout()}get root(){return this}get anchors(){return[]}get isReady(){return this._ready}get rootModel(){return this.model_layer}get threed(){return this.model_layer?.model?.threed||!1}set threed(t){this.model_layer&&this.model_layer.toggleThreeD(t)}get stuck(){return!0}get data(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].data);return t}set data(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.data=t[e])}}get dataByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.data;return t}set dataByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.data=t[e])}}get values(){const t={};for(const[e,n]of this.indexMap.entries())n.length>0&&(t[e]=n[0].value);return t}set values(t){for(const e in t){const n=this.findOrCreate(e);n&&0!==n.length&&n.forEach(n=>n.value=t[e])}}get valuesByRefid(){const t={};for(const[e,n]of this.refidIndexMap.entries())t[e]=n.value;return t}set valuesByRefid(t){for(const e in t){const n=this.findByRefid(Number(e));n&&(n.value=t[e])}}get selected(){return(this._selected||[]).filter(t=>t.parent)}set selected(t){const e=this._selected;if(this._selected=t,!t||t.length<=1)this.hasSameParentForAllSelected=!0;else{const e=t[0].parent;this.hasSameParentForAllSelected=!t.find(t=>t.parent!=e)}this.trigger("selected",t,e)}get focused(){return this._focused}set focused(t){this._focused!==t&&(this._focused=t,this.invalidate())}get style(){return this._style}set style(t){this._style=t,this._compiled_style=t}get hasTextProperty(){return!1}render(){this.layout.drawables(this).forEach(t=>t.draw())}contains(t,e){return!0}capturePath(t,e){return this.model_layer.capturePath(t,e)}invalidate(){this.components.forEach(t=>t.invalidate())}_areAliasesEqual(t,e){if(!Array.isArray(t)&&!Array.isArray(e))return!0;if(!Array.isArray(t)||!Array.isArray(e))return!1;if(t.length!==e.length)return!1;const n=[...t].sort(),i=[...e].sort();return n.every((t,e)=>t===i[e])}get eventMap(){return{"(root)":{"(descendant)":{added:this.onadded,removed:this.onremoved,change:this.onchanged}}}}refreshMappings(){if(!this._refresh_mapping_debouncer){if(this.disposed)return;this._refresh_mapping_debouncer=fi(function t(e){e.executeMappings(),e.components&&e.components.forEach(e=>t(e))},1e3)}this._refresh_mapping_debouncer(this.model_layer)}_addTraverse(t){t.components&&t.components.forEach(t=>this._addTraverse(t));const{id:e,alias:n,refid:i,tag:s,templatePrefix:r}=t.model;this.addRefidIndex(i,t),e&&this.addIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.addIndex(e,t)}),s&&this.subscribe(s,t),r&&this.addTemplate(r,t);const o=xi({},t.eventMap,t.model.eventMap);this.eventEngine.add(t,o)}_removeTraverse(t){t.components&&t.components.forEach(t=>this._removeTraverse(t));const{id:e,alias:n,refid:i,tag:s,templatePrefix:r}=t.model;this.removeRefidIndex(i,t),e&&this.removeIndex(e,t),Array.isArray(n)&&n.forEach(e=>{e&&this.removeIndex(e,t)}),s&&this.unsubscribe(s,t),r&&this.removeTemplate(r,t),this.eventEngine.remove(t)}onadded(t,e){this._addTraverse(e),e._silentAdd||this.refreshMappings(),this.invalidate()}onremoved(t,e){this._removeTraverse(e),this.invalidate()}onchanged(t,e,n){e.templatePrefix&&this.removeTemplate(e.templatePrefix,n.origin),t.templatePrefix&&this.addTemplate(t.templatePrefix,n.origin),e.id&&this.removeIndex(e.id,n.origin),t.id&&this.addIndex(t.id,n.origin),Array.isArray(e.alias)&&e.alias.forEach(t=>{t&&this.removeIndex(t,n.origin)}),Array.isArray(t.alias)&&t.alias.forEach(t=>{t&&this.addIndex(t,n.origin)}),e.tag&&this.unsubscribe(e.tag,n.origin),t.tag&&this.subscribe(t.tag,n.origin),e.id==t.id&&e.class==t.class&&this._areAliasesEqual(e.alias,t.alias)||n.origin._silentAdd||this.refreshMappings()}}th._beforeDisposeHooks=[],th.EMPTY_ARRAY=[],Tc.memoize(th.prototype,"unitScale",!1);class eh{constructor(){this._current=0,this._min=1/0,this._max=-1/0,this._count=0,this._baseline=0,this._baselineSet=!1,this._baselineSum=0,this._baselineCount=0,this._warn=5e3,this._critical=15e3,this._lastLevel="normal",this._disposed=!1}configure(t){const e=Array.isArray(t)?t[0]:t;e&&(this._warn=e.warnThreshold??this._warn,this._critical=e.criticalThreshold??this._critical)}record(t,e){if(this._disposed)return;const n="number"==typeof e?e:t;if("number"!=typeof n||n<=0)return;const i=Date.now()-n;this._current=i,this._count++,i<this._min&&(this._min=i),i>this._max&&(this._max=i),this._baselineSet||(this._baselineSum+=i,this._baselineCount++,this._baselineCount>=5&&(this._baseline=this._baselineSum/this._baselineCount,this._baselineSet=!0))}getStats(){if(0===this._count)return{current:0,baseline:0,drift:0,min:0,max:0,sampleCount:0,level:"normal"};const t=this._baselineSet?this._baseline:this._baselineCount>0?this._baselineSum/this._baselineCount:this._current,e=this._current-t;return{current:this._current,baseline:t,drift:e,min:this._min,max:this._max,sampleCount:this._count,level:this._calcLevel(Math.abs(e))}}evaluate(){if(this._disposed)return;const t=this.getStats();t.level!==this._lastLevel&&(this._lastLevel=t.level,this.onLevelChange?.(t.level,t))}reset(){this._current=0,this._min=1/0,this._max=-1/0,this._count=0,this._baseline=0,this._baselineSet=!1,this._baselineSum=0,this._baselineCount=0,this._lastLevel="normal"}dispose(){this._disposed=!0,this.onLevelChange=void 0}_calcLevel(t){return t>=this._critical?"critical":t>=this._warn?"warn":"normal"}}const nh=new eh,ih=5e3;class sh{constructor(t){this._entries=new Map,this._phase="fetch",this._phaseHistory=[],this._disposed=!1,this.needsOverlay=!1,this._firstRenderDone=!1,this._options=t||{},this._startTime=performance.now(),this._promise=new Promise(t=>{this._promiseResolve=t}),this._phaseHistory.push({phase:"fetch",timestamp:this._startTime,elapsed:0}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},ih)}get phase(){return this._phase}get phaseHistory(){return this._phaseHistory}get progress(){const t=this._entries.size;if(0===t)return 1;let e=0;for(const t of this._entries.values())"pending"!==t.status&&e++;return e/t}get pending(){const t=[],e=performance.now();for(const n of this._entries.values())"pending"===n.status&&t.push(this._toPublicEntry(n,e));return t}get entries(){const t=performance.now(),e=[];for(const n of this._entries.values())e.push(this._toPublicEntry(n,t));return e}get stats(){let t=0,e=0,n=0,i=0,s=0;for(const r of this._entries.values())switch(r.status){case"loaded":t++;break;case"timeout":e++;break;case"error":n++;break;case"cancelled":i++;break;case"pending":s++}return{total:this._entries.size,loaded:t,timeout:e,error:n,cancelled:i,pending:s,elapsed:this._completedElapsed??performance.now()-this._startTime}}get promise(){return this._promise}markFirstRender(){this._firstRenderDone||this._disposed||(this._firstRenderDone=!0,this.setPhase("render"),this.checkComplete())}setPhase(t){if(this._disposed||this._phase===t||"complete"===this._phase)return;const e=performance.now(),n=this._phaseHistory[this._phaseHistory.length-1];n&&void 0===n.duration&&(n.duration=e-n.timestamp),this._phase=t,"complete"!==t?(this._phaseHistory.push({phase:t,timestamp:e,elapsed:e-this._startTime}),this.onPhase?.(t)):this.onPhase?.(t)}track(t,e,n,i){if(this._disposed)return;const s={id:t,type:e,url:n,startTime:performance.now(),status:"pending"};this._entries.set(t,s),this._options.assetTimeout&&this._options.assetTimeout>0&&(s.timerId=setTimeout(()=>{"pending"===s.status&&(s.status="timeout",s.endTime=performance.now(),s.timerId&&(s.timerId=void 0),this.onTimeout?.(this._toPublicEntry(s)),this._onEntryDone())},this._options.assetTimeout)),i.then(()=>{"pending"===s.status&&(s.status="loaded",s.endTime=performance.now(),this._clearEntryTimer(s),this._onEntryDone())},()=>{"pending"===s.status&&(s.status="error",s.endTime=performance.now(),this._clearEntryTimer(s),this._onEntryDone())})}checkComplete(){if(this._disposed||"complete"===this._phase)return;let t=!1;for(const e of this._entries.values())if("pending"===e.status){t=!0;break}!t&&this._firstRenderDone&&this._doComplete()}startGlobalTimeout(){if(this._disposed)return;const t=this._options.timeout;!t||t<=0||(this._globalTimerId=setTimeout(()=>{if("complete"===this._phase||this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="timeout",e.endTime=t,this._clearEntryTimer(e),this.onTimeout?.(this._toPublicEntry(e)));this._doComplete(!0)},t))}abort(){if(this._disposed)return;const t=performance.now();for(const e of this._entries.values())"pending"===e.status&&(e.status="cancelled",e.endTime=t,this._clearEntryTimer(e));this._doComplete(!0)}reset(){for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._entries.clear(),this._phase="fetch",this._startTime=performance.now(),this._phaseHistory=[{phase:"fetch",timestamp:this._startTime,elapsed:0}],this._completedElapsed=void 0,this._firstRenderDone=!1,this.needsOverlay=!1,this._disposed=!1,this._promise=new Promise(t=>{this._promiseResolve=t}),this._slowTimerId=setTimeout(()=>{"complete"===this._phase||this._disposed||(this.needsOverlay=!0,this.onNeedsOverlay?.())},ih)}dispose(){if(!this._disposed){this._disposed=!0;for(const t of this._entries.values())this._clearEntryTimer(t);this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this._slowTimerId&&(clearTimeout(this._slowTimerId),this._slowTimerId=void 0),this._promiseResolve(),this.onPhase=void 0,this.onProgress=void 0,this.onTimeout=void 0,this.onComplete=void 0,this.onNeedsOverlay=void 0}}_onEntryDone(){this._disposed||(this.onProgress?.(this.stats),this.checkComplete())}_doComplete(t=!1){"complete"!==this._phase&&(this._completedElapsed=performance.now()-this._startTime,this._completedElapsed>ih&&(this.needsOverlay=!0),this._globalTimerId&&(clearTimeout(this._globalTimerId),this._globalTimerId=void 0),this.setPhase("complete"),this.onComplete?.(this.stats),this._promiseResolve())}_clearEntryTimer(t){t.timerId&&(clearTimeout(t.timerId),t.timerId=void 0)}_toPublicEntry(t,e){const n=t.endTime?t.endTime-t.startTime:(e??performance.now())-t.startTime;return{id:t.id,type:t.type,url:t.url,startTime:t.startTime,status:t.status,elapsed:n}}}let rh=13.3;var oh=function(t){return void 0!==t&&(rh=t),rh};const ah="$base_url";const ch=Math.PI/12;class lh{constructor(t,e){this._postprocessing=!0,this._loadTrackerOwned=!1,this._suppressAnimationsFlag=!1,this._suppressScopeCount=0,this.isSelecting=!1,this._mode=t,this.screen=oh(),this._baseUrl="undefined"!=typeof window?window.location.origin:null,this._refProvider=e,this.isEditMode&&(this._rotateStep=ch,this._rotateStepForced=!1)}initLoadTracker(t){return this._loadTracker=new sh(t),this._loadTrackerOwned=!0,this._loadTracker}get loadTracker(){return this._loadTracker}adoptLoadTracker(t){this._loadTracker=t,this._loadTrackerOwned=!1}initLagTracker(t){return nh.configure(t),nh}get lagTracker(){return nh}dispose(){this._loadTrackerOwned&&this._loadTracker?.dispose(),this._loadTracker=void 0,this._dataSubscriptionProvider?.dispose?.(),delete this._dataStorage}_calcScreen(){const t={width:screen.width,height:screen.height};this._PPI=function(t,e,n,i="d"){t<=0&&(t=1),e<=0&&(e=1);const s=("d"===i?Math.sqrt(t*t+e*e):"w"===i?t:e)/n;return s>0?Math.round(s):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 Xs}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 focusFilter(){return this._focusFilter}set focusFilter(t){this._focusFilter=t}get baseUrl(){return this._baseUrl}set baseUrl(t){t&&this._baseUrl!==t&&(this._baseUrl=t)}url(t){try{let e;return e=t.includes(ah)?new URL(t.replace(ah,this.baseUrl??""),this.baseUrl??void 0):new URL(t,location.origin),e.href}catch(e){Ji(e,t)}}get rotateStep(){return this._rotateStep}set rotateStep(t){this._rotateStep=Number(t)||ch}get rotateStepForced(){return this._rotateStepForced}set rotateStepForced(t){this._rotateStepForced=!!t}get dataStorage(){return this._dataStorage}set dataStorage(t){this._dataStorage=t}get postprocessing(){return this._postprocessing}set postprocessing(t){this._postprocessing=t}get logarithmicDepth(){return this._logarithmicDepth}set logarithmicDepth(t){this._logarithmicDepth=t}get suppressAnimations(){return this._suppressAnimationsFlag||this._suppressScopeCount>0}set suppressAnimations(t){this._suppressAnimationsFlag=!!t}withSuppressedAnimations(t){let e;this._suppressScopeCount++;try{e=t()}catch(t){throw this._suppressScopeCount--,t}return e&&"function"==typeof e.then?e.finally(()=>{this._suppressScopeCount--}):(this._suppressScopeCount--,e)}beginSuppressAnimations(){this._suppressScopeCount++;let t=!1;return{end:()=>{t||(t=!0,this._suppressScopeCount--)}}}}Qi(lh.prototype,Bi.withEvent);class hh{constructor(t,e){!(t=Number(t))||t<=0?(Zi("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];Ji("Not forwardable.")}backward(){if(this.snapshot_taker&&this.snapshot_taker.take(),this.backwardable)return this.q[--this.pos];Ji("Not backwardable.")}get current(){if(-1!==this.pos)return this.q[this.pos];Ji("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 dh=fi(t=>{t.brake||t.take()},1e3,{leading:!0,trailing:!1});function uh(t){!t.brake&&t.dirty&&dh(t)}class ph{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(){dh.cancel(),this.state_holder=null,this.timecapsule=null}touch(){this.dirty=!0,uh(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,uh(this)}}function fh(t,e){const n=e.model_layer.get("scale"),i=e.model_layer.get("translate");if(t){const s=JSON.parse(t);s.scale=n,s.translate=i,e.rebuildContentModel(s,{preserveThreeD:!0})}}class mh{constructor(t){this.container=t,this.timecapsule=new hh(20);const e=this;this.snapshot_taker=new ph({get state(){const t=e.container.model_layer.hierarchy;return JSON.stringify(t,za)}},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&&(fh(this.timecapsule.backward(),this.container),this.trigger("undo",this.undoable(),this.redoable()))}redo(){this.timecapsule.forwardable&&(fh(this.timecapsule.forward(),this.container),this.trigger("redo",this.undoable(),this.redoable()))}undoable(){return this.timecapsule.backwardable}redoable(){return this.timecapsule.forwardable}reset(){this.timecapsule&&this.timecapsule.reset(),this.trigger("command-reset")}}Qi(mh.prototype,Bi.withEvent);const gh="left",yh="right",bh="center",_h="bottom",vh="middle",xh="z-front",wh="z-back",Mh="z-middle",Sh=[gh,yh,bh,"top",vh,_h,xh,wh,Mh];function kh(t){if(!this.hasSameParentForAllSelected||-1===Sh.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(e.length<=1)return;const n=this.app.commander;ll.around(n,function(){!function(t,e){const n=JSON.parse(JSON.stringify(e[0].bounds));let i=n.left+n.width,s=n.top+n.height;for(let t=0;t<e.length;t++){const r=e[t].bounds;n.left=r.left>n.left?n.left:r.left,n.top=r.top>n.top?n.top:r.top,i=r.left+r.width>i?r.left+r.width:i,s=r.top+r.height>s?r.top+r.height:s}switch(n.width=i-n.left,n.height=s-n.top,t){case gh:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left,top:i.top,width:i.width,height:i.height}}break;case bh:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:n.left+n.width/2-i.width/2,top:i.top,width:i.width,height:i.height}}break;case yh:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:i-n.width,top:n.top,width:n.width,height:n.height}}break;case"top":for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top,width:i.width,height:i.height}}break;case vh:for(let t=0;t<e.length;t++){const i=e[t].bounds;e[t].bounds={left:i.left,top:n.top+n.height/2-i.height/2,width:i.width,height:i.height}}break;case _h:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={left:n.left,top:s-n.height,width:n.width,height:n.height}}break;case xh:{let t=1/0;for(let n=0;n<e.length;n++){const i=e[n].state.zPos||0;i<t&&(t=i)}for(let n=0;n<e.length;n++)e[n].set({zPos:t});break}case wh:{let t=-1/0;for(let n=0;n<e.length;n++){const i=(e[n].state.zPos||0)+(e[n].state.depth||0);i>t&&(t=i)}for(let n=0;n<e.length;n++){const i=e[n].state.depth||0;e[n].set({zPos:t-i})}break}case Mh:{let t=1/0,n=-1/0;for(let i=0;i<e.length;i++){const s=e[i].state.zPos||0,r=e[i].state.depth||0;s<t&&(t=s),s+r>n&&(n=s+r)}const i=(t+n)/2;for(let t=0;t<e.length;t++){const n=e[t].state.depth||0;e[t].set({zPos:i-n/2})}break}default:;}}(t,e)})}const Ah="VERTICAL",Eh=[Ah,"HORIZONTAL","Z"];function Ch(t){if(!this.hasSameParentForAllSelected||-1===Eh.indexOf(t))return;const e=this.selected;if(e.length<=1)return;const n=this.app.commander;ll.around(n,function(){!function(t,e){if("Z"===t)return void function(t){const e=t.filter(t=>!t.stuck).slice(0);e.sort((t,e)=>(t.state.zPos||0)+(t.state.depth||0)/2-((e.state.zPos||0)+(e.state.depth||0)/2));const n=e.reduce((t,e)=>t+(e.state.depth||0),0),i=e[0].state.zPos||0,s=((e[e.length-1].state.zPos||0)+(e[e.length-1].state.depth||0)-i-n)/(e.length-1);let r=i+(e[0].state.depth||0);for(let t=1;t<e.length-1;t++){const n=e[t],i=n.state.depth||0;r+=s,n.set({zPos:r}),r+=i}}(e);const n=e.filter(t=>!t.stuck).slice(0);n.sort(function(e,n){const i=e.center,s=n.center;return t===Ah?i.y-s.y:i.x-s.x});const i=n.reduce((e,n)=>e+(t===Ah?n.bounds.height:n.bounds.width),0),s=n[0].bounds,r=n[n.length-1].bounds,o=((t===Ah?r.top+r.height-s.top:r.left+r.width-s.left)-i)/(n.length-1);let a=t===Ah?s.top+s.height:s.left+s.width;for(let e=1;e<n.length-1;e++){const i=n[e],s=i.bounds;a+=o,t===Ah?(i.bounds={left:s.left,top:a,width:s.width,height:s.height},a+=s.height):(i.bounds={left:a,top:s.top,width:s.width,height:s.height},a+=s.width)}}(t,e)})}function Th(t,e,n){this.app.commander.execute(new Ol({changes:[{component:t,to_container:e,to_index:n}]}))}function Ph(t){const e=this.selected.filter(t=>!t.stuck);if(0===e.length||e[0].isRootModel())return;if(e.length>1&&("forward"===t||"backward"===t))return;const n=e[0].parent;let i;if("forward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t+1}]}else if("backward"===t){const t=n.indexOf(e[0]);i=[{component:e[0],from_container:n,to_container:n,from_index:t,to_index:t-1}]}else i=e.filter(t=>t.parent===n).sort((e,i)=>{const s=n.indexOf(e)<n.indexOf(i);return"front"===t?s:!s}).map((e,i)=>({component:e,to_container:n,to_index:"front"===t?n.components.length-i-1:i}));const s=new Ol({changes:i});this.app.commander.execute(s)}function Oh(t,e,n){t instanceof Array||(t=[t]),n||(n=this.model_layer);const i=[],s=new Map;this.selected=t.map(t=>{try{return zl(t,n.app,t=>{const e=this.getNewRefid();return void 0!==t&&s.set(t,e),e},t=>(this.indexMap[t]||[])[0])}catch(t){return Ji(t),!1}}).filter(Boolean).map(t=>{const{left:r,top:o,width:a,height:c,x:l,y:h,cx:d,cy:u}=e;return t.replaceRefids(s),isNaN(r)||isNaN(o)||isNaN(a)||isNaN(c)||(t.bounds={left:r,top:o,width:a,height:c}),isNaN(l)||isNaN(h)||t.move({x:l,y:h},!1),isNaN(d)||isNaN(u)||(t.center={x:d,y:u}),i.push({component:t,to_container:n}),t}),this.app.commander.execute(new Ol({changes:i}))}function Dh(){const t=[],e=new Map;if(this.selected=this.selected.filter(t=>!t.isRootModel()).map(n=>{const i=Il(n,t=>{const n=this.getNewRefid();return void 0!==t&&e.set(t,n),n});return i.move({x:20,y:20},!1),t.push({component:i,to_container:n.parent}),i}).map(t=>(t.replaceRefids(e),t)),0===t.length)return;const n=new Ol({changes:t});this.app.commander.execute(n)}function zh(){const t=this.selected;this.selected=[];let e=null;const n=t.filter(t=>!t.isRootModel()&&(t.parent.focusible||t.parent.isGroup())).map(t=>(e||(e=t.parent),{component:t,to_container:null}));for(;e&&e.isGroup();){const t=[];if(e.components.filter(t=>!n.find(e=>e.component===t)).forEach(e=>t.push(e)),t.length>1)break;const i=e.parent;t.forEach(t=>n.push({component:t,to_container:i})),n.push({component:e,to_container:null}),e=i}n.length>0&&this.app.commander.execute(new Ol({changes:n})),e&&e.calculateBounds&&e.calculateBounds()}const Ih=new Set(["execute","redo","undo","command-reset"]);function Rh(t,e,n,i){const s=function(t,e){return void 0!==e&&Ih.has(e)?t.app?.commander:"mode"===e?t.app:t}(this,e);s?.[t](e,n,i)}function jh(t,e,n){Rh.call(this,"on",t,e,n)}function Lh(t,e,n){Rh.call(this,"once",t,e,n)}function Fh(t,e,n){Rh.call(this,"off",t,e,n)}function Nh(t){const e=this.target_element,n=t||this.fitMode,i=this;function s(){i.fit(n),document.fullscreenElement||document.removeEventListener("fullscreenchange",s)}document.addEventListener("fullscreenchange",s),e.requestFullscreen().catch(()=>{document.removeEventListener("fullscreenchange",s)})}let Hh=0;function Bh(){const t=this.selected.filter(t=>!t.isRootModel()).map(t=>t.hierarchy);if(0!==t.length)return Hh=0,JSON.stringify(t,null,2)}function Gh(){Hh=0;const t=Bh.call(this);return zh.call(this),t}function Vh(t){if(t)try{Hh++,Oh.call(this,JSON.parse(t),{x:15*Hh,y:15*Hh})}catch(e){Zi(e,t)}}const Yh=function(){return{escape:function(t){return t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")},parseExtension:t,mimeType:function(e){const n=t(e).toLowerCase();return function(){const t="application/font-woff",e="image/jpeg";return{woff:t,woff2:t,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:e,jpeg:e,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}()[n]||""},dataAsUrl:function(t,e){return"data:"+e+";base64,"+t},isDataUrl:function(t){return-1!==t.search(/^(data:)/)},canvasToBlob:function(t){return t.toBlob?new Promise(function(e){t.toBlob(e)}):function(t){return new Promise(function(e){const n=window.atob(t.toDataURL().split(",")[1]),i=n.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=n.charCodeAt(t);e(new Blob([s],{type:"image/png"}))})}(t)},resolveUrl:function(t,e){const n=document.implementation.createHTMLDocument(),i=n.createElement("base");n.head.appendChild(i);const s=n.createElement("a");return n.body.appendChild(s),i.href=e,s.href=t,s.href},getAndEncode:function(t){const e=3e4;Zh.impl.options.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());return new Promise(function(n){const i=new XMLHttpRequest;let s;if(i.onreadystatechange=r,i.ontimeout=o,i.responseType="blob",i.timeout=e,i.open("GET",t,!0),i.send(),Zh.impl.options.imagePlaceholder){const t=Zh.impl.options.imagePlaceholder.split(/,/);t&&t[1]&&(s=t[1])}function r(){if(4!==i.readyState)return;if(200!==i.status)return void(s?n(s):a("cannot fetch resource: "+t+", status: "+i.status));const e=new FileReader;e.onloadend=function(){const t=e.result.split(/,/)[1];n(t)},e.readAsDataURL(i.response)}function o(){s?n(s):a("timeout of "+e+"ms occured while fetching resource: "+t)}function a(t){Zi(t),n("")}})},uid:function(){let t=0;return function(){return"u"+e()+t++;function e(){return("0000"+(Math.random()*Math.pow(36,4)|0).toString(36)).slice(-4)}}}(),delay:function(t){return function(e){return new Promise(function(n){setTimeout(function(){n(e)},t)})}},asArray:function(t){const e=[],n=t.length;for(let i=0;i<n;i++)e.push(t[i]);return e},escapeXhtml:function(t){return t.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(t){return new Promise(function(e,n){const i=new Image;i.onload=function(){e(i)},i.onerror=n,i.src=t})},width:function(t){const n=e(t,"border-left-width"),i=e(t,"border-right-width");return t.scrollWidth+n+i},height:function(t){const n=e(t,"border-top-width"),i=e(t,"border-bottom-width");return t.scrollHeight+n+i}};function t(t){const e=/\.([^\.\/]*?)$/g.exec(t);return e?e[1]:""}function e(t,e){const n=window.getComputedStyle(t).getPropertyValue(e);return parseFloat(n.replace("px",""))}}(),Wh=function(){const t=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(t,s,r){return o()?Promise.resolve(t):Promise.resolve(t).then(n).then(function(e){let n=Promise.resolve(t);return e.forEach(function(t){n=n.then(function(e){return i(e,t,s,r)})}),n});function o(){return!e(t)}},shouldProcess:e,impl:{readUrls:n,inline:i}};function e(e){return-1!==e.search(t)}function n(e){const n=[];let i;for(;null!==(i=t.exec(e));)n.push(i[1]);return n.filter(function(t){return!Yh.isDataUrl(t)})}function i(t,e,n,i){return Promise.resolve(e).then(function(t){return n?Yh.resolveUrl(t,n):t}).then(i||Yh.getAndEncode).then(function(t){return Yh.dataAsUrl(t,Yh.mimeType(e))}).then(function(n){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+Yh.escape(t)+")(['\"]?\\))","g")}(e),"$1"+n+"$3")})}}(),Uh=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(Yh.asArray(document.styleSheets)).then(function(t){const e=[];return t.forEach(function(t){try{Yh.asArray(t.cssRules||[]).forEach(t=>e.push(t))}catch(e){Ji("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 Wh.shouldProcess(t.style.getPropertyValue("src"))})}).then(function(e){return e.map(t)});function t(t){return{resolve:function(){const e=(t.parentStyleSheet||{}).href;return Wh.inlineAll(t.cssText,e)},src:function(){return t.style.getPropertyValue("src")}}}}}(),$h=function(){return{inlineAll:function e(n){return n instanceof Element?i(n).then(function(){return n instanceof HTMLImageElement?t(n).inline().then(()=>n):Promise.all(Yh.asArray(n.childNodes).map(function(t){return e(t)})).then(()=>n)}):Promise.resolve(n);function i(t){const e=t.style.getPropertyValue("background");return e?Wh.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 Yh.isDataUrl(t.src)?Promise.resolve():Promise.resolve(t.src).then(e||Yh.getAndEncode).then(function(e){return Yh.dataAsUrl(e,Yh.mimeType(t.src))}).then(function(e){return new Promise(function(n,i){t.onload=n,t.onerror=i,t.src=e})})}}}}(),Xh={imagePlaceholder:void 0,cacheBust:!1};function qh(t,e){return function(t){void 0===t.imagePlaceholder?Zh.impl.options.imagePlaceholder=Xh.imagePlaceholder:Zh.impl.options.imagePlaceholder=t.imagePlaceholder;void 0===t.cacheBust?Zh.impl.options.cacheBust=Xh.cacheBust:Zh.impl.options.cacheBust=t.cacheBust}(e=e||{}),Promise.resolve(t).then(function(t){return Qh(t,e.filter,!0)}).then(function(t){return function(t){return $h.inlineAll(t).then(function(){return t})}(t)}).then(function(t){const{bgcolor:n,width:i,height:s,style:r,sx:o=1,sy:a=1}=e||{},c=t.style;n&&(c.backgroundColor=n);i&&(c.width=i+"px");s&&(c.height=s+"px");c["margin-left"]="0px",c["margin-top"]="0px",c.transform=`rotate(0rad) translate(0px, 0px) scale(${o}, ${a}) perspective(1px)`,r&&Object.keys(r).forEach(function(t){c[t]=r[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(Yh.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||Yh.width(t),e.height||Yh.height(t))})}function Kh(t,e){return qh(t,e).then(Yh.makeImage).then(Yh.delay(100)).then(function(n){const i=function(t){const n=document.createElement("canvas");if(n.width=e.width||Yh.width(t),n.height=e.height||Yh.height(t),e.bgcolor){const t=n.getContext("2d");t.fillStyle=e.bgcolor,t.fillRect(0,0,n.width,n.height)}return n}(t);return i.getContext("2d").drawImage(n,0,0),i})}function Qh(t,e,n){return n||!e||e(t)?Promise.resolve(t).then(function(t){if(t instanceof HTMLCanvasElement)try{return Yh.makeImage(t.toDataURL()).then(t=>t)}catch(t){Ji(t)}return t.cloneNode(!1)}).then(function(n){return function(t,e,n){const i=t.childNodes;return 0===i.length?Promise.resolve(e):s(e,Yh.asArray(i),n).then(function(){return e});function s(t,e,n){let i=Promise.resolve();return e.forEach(function(e){i=i.then(function(){return Qh(e,n,!1)}).then(function(e){e&&t.appendChild(e)})}),i}}(t,n,e)}).then(function(e){return function(t,e){return e instanceof Element?Promise.resolve().then(n).then(i).then(s).then(r).then(function(){return e}):e;function n(){function n(t,e){function n(t,e){Yh.asArray(t).forEach(function(n){e.setProperty(n,t.getPropertyValue(n),t.getPropertyPriority(n))})}t.cssText?e.cssText=t.cssText:n(t,e)}n(window.getComputedStyle(t),e.style)}function i(){function n(n){const i=window.getComputedStyle(t,n),s=i.getPropertyValue("content");if(""===s||"none"===s)return;const r=Yh.uid(),o=e;o.className=o.className+" "+r;const a=document.createElement("style");function c(t,e,n){const i="."+t+":"+e,s=n.cssText?r(n):o(n);return document.createTextNode(i+"{"+s+"}");function r(t){const e=t.getPropertyValue("content");return t.cssText+" content: "+e+";"}function o(t){return Yh.asArray(t).map(e).join("; ")+";";function e(e){return e+": "+t.getPropertyValue(e)+(t.getPropertyPriority(e)?" !important":"")}}}a.appendChild(c(r,n,i)),e.appendChild(a)}[":before",":after"].forEach(function(t){n(t)})}function s(){t instanceof HTMLTextAreaElement&&e instanceof HTMLTextAreaElement&&(e.textContent=t.value),t instanceof HTMLInputElement&&e instanceof HTMLInputElement&&e.setAttribute("value",t.value)}function r(){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 Zh={toSvg:qh,toPng:function(t,e){return Kh(t,e||{}).then(function(t){return t.toDataURL()})},toJpeg:function(t,e){return Kh(t,e=e||{}).then(function(t){return t.toDataURL("image/jpeg",e.quality||1)})},toBlob:function(t,e){return Kh(t,e||{}).then(t=>Yh.canvasToBlob(t))},toPixelData:function(t,e){return Kh(t,e||{}).then(function(e){return e.getContext("2d").getImageData(0,0,Yh.width(t),Yh.height(t)).data})},impl:{fontFaces:Uh,images:$h,util:Yh,inliner:Wh,options:{}}};function Jh(t,e,n,i){const s=this.model_layer,r=s._overlay;return new Promise(function(o,a){if(s){const a=s.get("width"),c=s.get("height"),l=n||a,h=i||c,d=s.get("translate"),u=s.get("scale"),p=Math.min(l/a,h/c),f=a*p,m=c*p;s.set("translate",{x:0,y:0}),s.set("scale",{x:p/Xs,y:p/Xs});let g=Tc.createCanvas(f,m);const y=g.getContext("2d");if(s.draw(y),s.set("translate",d),s.set("scale",u),!r)return o(g.toDataURL(t,e)),void(g=null);Zh.toPng(r,{sx:p,sy:p,width:f,height:m}).then(function(n){const i=new Image;i.onload=function(){y.drawImage(i,0,0,f,m),o(g.toDataURL(t,e)),g=null},i.src=n},function(n){Zi(n),o(g.toDataURL(t,e)),g=null})}else a("No target model")})}function td(){if(!this.hasSameParentForAllSelected)return;const t=this.selected.filter(t=>!!t.parent&&!t.stuck);if(t.length<2)return;const e=t[0].parent,n=[],i=t.sort((t,n)=>e.components.indexOf(t)-e.components.indexOf(n));i.forEach(t=>{n.push(t.bounds)});const s=Tc.union(n);let r=t[0].fromParent(s.left,s.top);r=t[0].toScene(r.x,r.y);const o=new Map,a=zl({type:"group",left:r.x,top:r.y,width:s.width,height:s.height},e.app,t=>{const e=this.getNewRefid();return void 0!==t&&o.set(t,e),e});a.replaceRefids(o);const c=[{component:a,to_container:e}];i.forEach(t=>{c.push({component:t,to_container:a})}),this.app.commander.execute(new Ol({changes:c})),this.selected=[a]}function ed(){if(0===this.selected.length)return;const t=[],e=[];this.selected.forEach(n=>{if(!n.isGroup())return;const i=n.parent;n.components.forEach(n=>{t.push(n),e.push({component:n,to_container:i})}),e.push({component:n,to_container:null})}),this.app.commander.execute(new Ol({changes:e})),this.selected=t}function nd(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=Tc.union(e),i=n.left+n.width/2;t.map(t=>{t.symmetryX(i)})}function id(){const t=this.selected;if(0===t.length)return;const e=t.map(t=>t.bounds),n=Tc.union(e),i=n.top+n.height/2;t.map(t=>{t.symmetryY(i)})}function sd(){ll.around(this.app.commander,nd,this)}function rd(){ll.around(this.app.commander,id,this)}function od(t,e,n){const i=this.findAll(t,n);return i.forEach(t=>{t.set(e)}),i}function ad(t){ll.around(this.app.commander,t)}function cd(){const t=this.indexMap;if(!t)return[];return("function"==typeof t.entries?[...t.entries()]:Object.entries(t)).flatMap(([,t])=>t.map(t=>{const{id:e,data:n}=t.model;return{key:e,value:n}})).sort((t,e)=>t.key>e.key?1:-1)}const ld="left",hd="right",dd="center",ud="bottom",pd="middle",fd=[ld,hd,dd,"top",pd,ud];function md(t){if(!this.hasSameParentForAllSelected||-1===fd.indexOf(t))return;const e=this.selected.filter(t=>!t.stuck);if(0===e.length)return;const n=this.app.commander;ll.around(n,function(){!function(t,e){const n=e[0].parent,{width:i,height:s}=n.bounds;switch(t){case ld:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:0}}break;case dd:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i/2-n.width/2}}break;case hd:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,left:i-n.width}}break;case"top":for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:0}}break;case pd:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:s/2-n.height/2}}break;case ud:for(let t=0;t<e.length;t++){const n=e[t].bounds;e[t].bounds={...n,top:s-n.height}}break;default:;}}(t,e)})}function gd(t){t instanceof Array||(t=[t]),this.trigger("addstart",t)}function yd(t,e){return new Promise(n=>{let i=!1;const s=t=>{i||(i=!0,this.off("bulkareaselected",r),this.off("addstop",o),n(t))},r=t=>s(t),o=()=>s(null);this.on("bulkareaselected",r),this.on("addstop",o),this.trigger("addstart",[],{bulkMode:!0,template:t,boxStrokeStyle:e?.boxStrokeStyle})})}function bd(){this.trigger("stylepastestart")}function _d(){this.trigger("stylepastestop")}function vd(){this.trigger("databindpastestart")}function xd(){this.trigger("databindpastestop")}const wd={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 Md(t){if(!t)return{metalness:0,roughness:.4,emissive:"#000000",emissiveIntensity:0,opacity:1,envMapIntensity:.5,side:"double",flatShading:!1,castShadow:!0,receiveShadow:!1};const e=wd[t.preset??"default"]??wd.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",flatShading:t.flatShading??!1,castShadow:t.castShadow??!0,receiveShadow:t.receiveShadow??!1}}const Sd={double:e.DoubleSide,front:e.FrontSide,back:e.BackSide};function kd(t){return Sd[t]??e.DoubleSide}function Ad(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=kd(e.side),t.flatShading!==e.flatShading&&(t.flatShading=e.flatShading,t.needsUpdate=!0)}const Ed=new class{constructor(){this._scenes=[],this.onSceneChange=null,this._watchedComponent=null,this._watchedHandler=null,this.onWatchedComponentChange=null}setWatchedComponent(t,e=0){if(this._clearWatched(),null==t)return!0;const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s||"function"!=typeof s.on)return!1;const r=(e,n)=>{this.onWatchedComponentChange?.(t,e,n)};return s.on("change",r),this._watchedComponent=s,this._watchedHandler=r,!0}_clearWatched(){this._watchedComponent&&this._watchedHandler&&"function"==typeof this._watchedComponent.off&&this._watchedComponent.off("change",this._watchedHandler),this._watchedComponent=null,this._watchedHandler=null}register(t){this._cleanup(),this._scenes.push(new WeakRef(t)),this.onSceneChange?.(this._scenes.length)}unregister(t){this._clearWatched(),this._scenes=this._scenes.filter(e=>{const n=e.deref();return n&&n!==t}),this.onSceneChange?.(this._scenes.length)}getScenes(){return this._cleanup(),this._scenes.map((t,e)=>{const n=t.deref();if(!n)return null;const i=n.root,s=i?.model||{};return{index:e,model:{width:s.width||0,height:s.height||0,type:s.type||"unknown"}}}).filter(Boolean)}getComponentTree(t=0){const e=this._getScene(t);if(!e)return[];const n=e.rootContainer;if(!n)return[];const i=n.model_layer;return i?this._childrenOf(i):[]}getChildTree(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];let s;return s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),s?this._childrenOf(s):[]}getComponentInfo(t,e=0,n){const i=this._getScene(e);if(!i)return null;const s=i.rootContainer;if(!s)return null;let r;if(r="root"===t||"__root__"===t?s.model_layer:this._findComponent(s,t),!r)return null;const o=this._safeBounds(r),a={model:this._safeClone(r.model),state:this._safeClone(r.state),nature:r.nature||{},data:this._safeValue(r.data),value:this._safeValue(r.value),bounds:o,type:r.model?.type||"unknown",isContainer:!!r.isContainer?.(),hidden:!!r.model?.hidden};if("model-layer"===r.model?.type&&(a.is3dMode=!!r.model?.threed),n?.includeItems){const t=r._items;Array.isArray(t)&&t.length>0&&(a.items=t.map(t=>this._toTreeNode(t)))}const c=r;if("function"==typeof c.slotIds&&"function"==typeof c.occupiedSlotIds&&"function"==typeof c.emptySlotIds)try{const t=Array.from(c.slotIds()??[]).map(t=>String(t)),e=Array.from(c.occupiedSlotIds()??[]).map(t=>String(t)),n=Array.from(c.emptySlotIds()??[]).map(t=>String(t));(t.length>0||e.length>0||n.length>0)&&(a.slottedHolder={slotIds:t,occupiedSlotIds:e,emptySlotIds:n})}catch{}return a}getItems(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];const r=s._items;return Array.isArray(r)?r.map(t=>this._toTreeNode(t)):[]}getRecords(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];try{const t=s.data;return Array.isArray(t)?t:[]}catch{return[]}}selectComponent(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;if(!t||"root"===t||"__root__"===t)return i.selected=[],!0;const s=this._findComponent(i,t);return!!s&&(i.selected=[s],!0)}setComponentProperty(t,e,n,i=0){const s=this._getScene(i);if(!s)return!1;const r=s.rootContainer;if(!r)return!1;let o;if(o="root"===t||"__root__"===t?r.model_layer:this._findComponent(r,t),!o)return!1;try{return o.set(e,n),!0}catch{return!1}}setCameraView(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const s=i.model_layer;if(!s||!s._threeCapability)return!1;try{return s._threeCapability.setCameraView(t),!0}catch{return!1}}getCameraState(t=0){const e=this._getScene(t);if(!e)return null;const n=e.rootContainer;if(!n)return null;const i=n.model_layer;if(!i||!i._threeCapability)return null;try{return i._threeCapability.getCameraState()}catch{return null}}toggleHidden(t,e=0){const n=this._getScene(e);if(!n)return!1;const i=n.rootContainer;if(!i)return!1;const s=this._findComponent(i,t);if(!s)return!1;try{return s.set("hidden",!s.model?.hidden),!s.model?.hidden}catch{return!1}}evaluateData(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return s?this._safeValue(s.data):void 0}evaluateValue(t,e=0){const n=this._getScene(e);if(!n)return;const i=n.rootContainer;if(!i)return;const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);return s?this._safeValue(s.value):void 0}searchComponents(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s=i.model_layer;if(!s)return[];const r=[],o=t.toLowerCase();return this._traverseComponent(s,t=>{const e=t.state||t.model||{};[e.type||"",e.name||"",e.id||"",e.tag||"",e.class||"",String(e.refid||"")].join(" ").toLowerCase().includes(o)&&r.push(this._toTreeNode(t))}),r}getComponentPath(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s=i.model_layer;if(!s)return[];const r=[];return this._findPath(s,t,r)?r:[]}getThreedInfo(t,e=0){const n=this._getScene(e);if(!n)return null;const i=n.rootContainer;if(!i)return null;let s;if(s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t),!s)return null;const r=s.model||{},o=r.type||"unknown",a=r.material3d,c={is3dish:"function"==typeof s.is3dish&&s.is3dish(),type:o};a&&(c.material3d=this._safeClone(a)),c.resolved=Md(a),c.visibilityWarnings=this._materialVisibilityWarnings(s,c.resolved);const l=s?._realObject;if(l&&"object"==typeof l.materialSharing&&null!==l.materialSharing&&(c.materialSharing=this._safeClone(l.materialSharing)),"gltf-object"===o)try{c.nodeNames=s.nodeNames??[],c.animationNames=s.animationNames??[],c.nodes=this._safeClone(s.nodes),c.animations=this._safeClone(s.animations),c.fillStyleTargets=s.fillStyleTargets}catch{}return c}_materialVisibilityWarnings(t,e){const n=[],i=t?._realObject?.threeContainer;return i&&"boolean"==typeof i.hasEnvironment?(e.metalness>=.5&&!i.hasEnvironment&&n.push({code:"metal-without-environment",metalness:e.metalness,message:`metalness ${e.metalness} 인데 반사할 환경이 없다 — 고른 색과 무관하게 어둡게 나온다. 3D 컨테이너에 environment(또는 sky)를 주면 의도대로 보인다.`}),n):n}_getScene(t){this._cleanup();const e=this._scenes[t];return e?.deref()??null}_cleanup(){this._scenes=this._scenes.filter(t=>void 0!==t.deref())}_findComponent(t,e){const n=Number(e);if(!isNaN(n)){const e=t.findByRefid(n);if(e)return e}const i=t.findById(e);return i||null}_childrenOf(t){const e=Array.isArray(t.components)?t.components:[],n=Array.isArray(t._items)?t._items:[];if(0===e.length&&0===n.length)return[];const i=new Set(e),s=e.map(t=>this._toTreeNode(t));for(const t of n){if(i.has(t))continue;i.add(t);const e=this._toTreeNode(t);e.isItem=!0,s.push(e)}return s}_toTreeNode(t){const e=Array.isArray(t.components)?t.components:[],n=Array.isArray(t._items)?t._items:[],i=new Set(e);let s=0;for(const t of n)i.has(t)||(i.add(t),s++);const r=e.length+s,o=t.state||t.model||{};return{id:String(o.refid??o.id??""),type:o.type||"unknown",model_id:o.id,hasChildren:r>0,childCount:r,refid:o.refid,tag:o.tag,name:o.name,hidden:!!o.hidden,clazz:o.class}}_componentId(t){const e=t.state||t.model||{};return String(e.refid??"")}_findPath(t,e,n){const i=this._componentId(t);if(i===e)return!0;const s=t.components;if(!s)return!1;for(const r of s)if(this._findPath(r,e,n))return n.unshift("model-layer"===t.model?.type?"__root__":i),!0;return!1}_traverseComponent(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverseComponent(t,e)}_safeBounds(t){try{const e=t.bounds;return e?{left:e.left??0,top:e.top??0,width:e.width??0,height:e.height??0}:null}catch{return null}}_safeClone(t){if(!t||"object"!=typeof t)return t??{};try{return JSON.parse(JSON.stringify(t))}catch{const e={};for(const n of Object.keys(t))try{const i=t[n];if("function"==typeof i)continue;e[n]="object"==typeof i?String(i):i}catch{e[n]="[error]"}return e}}_safeValue(t){if(null==t)return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}transferLog(){try{const t=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(!t)return null;const e={};if("function"==typeof t.flows){t.flows().forEach((t,n)=>{e[n]=t})}const n={};if("function"==typeof t.targetCounts){t.targetCounts().forEach((t,e)=>{n[e]=t})}const i={};if("function"==typeof t.rejectReasonCounts){t.rejectReasonCounts().forEach((t,e)=>{i[e]=t})}return{entries:"function"==typeof t.toJSON?t.toJSON():[],stats:t.stats(),flows:e,targetCounts:n,rejectReasonCounts:i}}catch{return null}}reservations(){try{const t=globalThis.__THINGS_SCENE_RESERVATION_TABLE__,e=globalThis.__THINGS_SCENE_SIM_CLOCK__;if(!t)return null;const n=[...t.all()],i={},s={};for(const t of n)(i[t.resource]??=[]).push(t),(s[t.reserverId]??=[]).push(t);for(const t of Object.values(i))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);return{simTime:e?.now??0,all:n,byResource:i,byReserver:s}}catch{return null}}conflicts(){try{const t=globalThis.__THINGS_SCENE_RESERVATION_TABLE__,e=globalThis.__THINGS_SCENE_SIM_CLOCK__;if(!t||"function"!=typeof t.conflictLog)return null;const n=[...t.conflictLog()],i={},s={};let r=0,o=0;for(const t of n)i[t.resource]=(i[t.resource]??0)+1,s[t.proposed.reserverId]=(s[t.proposed.reserverId]??0)+1,"rejected"===t.outcome?r++:o++;return{simTime:e?.now??0,log:n,total:n.length,rejected:r,preempted:o,byResource:i,byReserver:s}}catch{return null}}contractSummary(t,e=0){const n=this._getScene(e);if(!n)return null;const i=this._findComponent(n.rootContainer,t);if(!i)return null;const s={type:i.constructor?.name??"Component",id:t};if(!0===i.isItem&&(s.isItem=!0),!0===i.isMover&&(s.isMover=!0),"function"!=typeof i.canReceive&&"function"!=typeof i.canAccept||(s.isHolder=!0),"function"==typeof i.pickupFrames)try{const t=i.pickupFrames();s.isPickable=t.length>0,s.pickupFrames=this._safeValue(t)}catch{}if("string"==typeof i.toolType&&(s.toolType=i.toolType),i.slots)try{const t="function"==typeof i.slots?i.slots():i.slots;s.slots=this._safeValue(t)}catch{}return s}getComponentCapabilities(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];const r=new Set;let o=s.constructor;for(;o&&o!==Object&&o!==Function.prototype;){const t=o.capabilities;if(Array.isArray(t))for(const e of t)"string"==typeof e&&r.add(e);o=Object.getPrototypeOf(o)}return[...r]}async componentCapabilityReports(t,e=0){const n=this._getScene(e);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s="root"===t||"__root__"===t?i.model_layer:this._findComponent(i,t);if(!s)return[];const r=[];{const t=new Set;let e=s.constructor;for(;e&&e!==Object&&e!==Function.prototype;){const n=e.capabilities;if(Array.isArray(n))for(const e of n)"string"!=typeof e||t.has(e)||(t.add(e),r.push(e));e=Object.getPrototypeOf(e)}}if(0===r.length)return[];const o=s.state??{},a=[];try{const t=await Promise.resolve().then(function(){return Fm}),e=s.describeCapability;for(const n of r){const i=t.getCapabilityMeta(n);let r,c,l;if("function"==typeof e)try{r=e.call(s,n)}catch{r=void 0}if(i?.stateFields&&i.stateFields.length>0){const t={};for(const e of i.stateFields)e in o&&(t[e]=this._safeValue(o[e]));Object.keys(t).length>0&&(c=t)}if(i?.classFields&&i.classFields.length>0){const t=s.constructor,e={};for(const n of i.classFields){const i=t?.[n];void 0!==i&&(e[n]=this._safeValue(i))}Object.keys(e).length>0&&(l=e)}a.push({name:n,description:i?.description,methods:i?.methods,models:i?.models,stateFields:i?.stateFields,stateValues:c,classFields:i?.classFields,classValues:l,sourceFile:i?.sourceFile,instance:r?this._safeValue(r):void 0})}}catch{for(const t of r)a.push({name:t})}return a}async systemTopology(t=0,e){const n=this._getScene(t);if(!n)return{nodes:[],edges:[],issues:[]};const i=n.rootContainer;if(!i)return{nodes:[],edges:[],issues:[]};const s=i.model_layer;if(!s)return{nodes:[],edges:[],issues:[]};let r;try{const t=await Promise.resolve().then(function(){return Fm});r=t.getCapabilityMeta}catch{}const o=[],a=[],c=new Set;this._traverseComponent(s,t=>{const e=this._componentId(t);if(!e||c.has(e))return;if(t===s)return;c.add(e);const n=(t=>{const e=[],n=new Set;let i=t.constructor;for(;i&&i!==Object&&i!==Function.prototype;){const t=i.capabilities;if(Array.isArray(t))for(const i of t)"string"!=typeof i||n.has(i)||(n.add(i),e.push(i));i=Object.getPrototypeOf(i)}return e})(t),i=this._safeBounds(t);o.push({id:e,type:t.model?.type??t.constructor?.name??"unknown",bounds:i,capabilities:n,refid:t.model?.refid,tag:t.model?.tag,hidden:!!t.model?.hidden})});try{const t=globalThis.__operatoBuildFlowGraph;"function"==typeof t&&t(i,e)}catch{}const l=i.__flowGraph,h=l?.graph?.out,d=l?.components;if(h&&"function"==typeof h.forEach){const t=t=>{const e=d?.get(t);return e?this._componentId(e):t};h.forEach((e,n)=>{const i=t(n);for(const n of e||[])n&&a.push({source:i,target:t(n),via:"flow-graph"})})}if(r)for(const t of o)t.capabilityMeta=t.capabilities.map(t=>r(t)).filter(Boolean).map(t=>({name:t.name,description:t.description}));return{nodes:o,edges:a,issues:l?.issues??[]}}async topologyStats(t=0){const e={flows:{},utilization:{},conflicts:{},distribution:{}},n=this._getScene(t);if(!n)return e;const i=n.rootContainer;if(!i)return e;const s=i.model_layer;if(!s)return e;const r={},o={};try{const t=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(t){if("function"==typeof t.flows){t.flows().forEach((t,e)=>{r[e]=t})}if("function"==typeof t.targetCounts){t.targetCounts().forEach((t,e)=>{o[e]=t})}}}catch{}const a={},c={};this._traverseComponent(s,t=>{if(t===s)return;const e=this._componentId(t);if(!e)return;const n=t?.state?.destination;"string"==typeof n&&n.length>0&&(c[String(e)]=n);const i=t?.state?.received;let r,l;if("number"==typeof i&&i>0&&(o[String(e)]=i),t.carrierMap instanceof Map){let e=0;t.carrierMap.forEach(t=>{t&&null!=t.occupant&&e++}),r=e,l=t.carrierMap.size}else if(t.slots instanceof Map){let e=0;t.slots.forEach(t=>{t&&null!=t.occupant&&e++}),r=e,l=t.slots.size}else if(Array.isArray(t.components)){r=t.components.filter(e=>e&&e.parent===t).length;const e=t.state?.capacity??t.state?.maxCapacity;"number"==typeof e&&e>0&&(l=e)}if(void 0!==r){const t={occupied:r};void 0!==l&&l>0&&(t.capacity=l,t.ratio=r/l),a[e]=t}});const l={};try{const t=n.reservationTable;if(t&&"function"==typeof t.getRecentConflicts){const e=t.getRecentConflicts();if(Array.isArray(e))for(const t of e){const e=t?.componentId??t?.id;e&&(l[String(e)]=(l[String(e)]??0)+1)}}}catch{}const h={},d={};for(const t in o){const e=c[t],n=o[t],i={count:n};e&&(i.destination=e,d[e]||(d[e]={ids:[],total:0}),d[e].ids.push(t),d[e].total+=n),h[t]=i}for(const t in d){const e=d[t];if(0===e.total||0===e.ids.length)continue;const n=1/e.ids.length;for(const t of e.ids){const i=h[t].count/e.total;h[t].share=i,h[t].deviation=Math.min(Math.abs(i-n)/(1-n||1),1)}}return{flows:r,utilization:a,conflicts:l,distribution:h}}async carrierJourney(t,e=0){const n={carrierId:t,steps:[]};if(!this._getScene(e))return n;try{const e=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(!e)return n;const i="function"==typeof e.toJSON?e.toJSON():"function"==typeof e.entries?e.entries():[];if(!Array.isArray(i))return n;const s=i.filter(e=>{const n=e.carrierId??e.carrier?.state?.id??e.carrier?.refid;return null!=n&&String(n)===String(t)}).map(t=>({from:t.sourceId??t.source?.state?.id??t.source?.refid??null,to:t.targetId??t.target?.state?.id??t.target?.refid??null,at:t.timeline?.initiatedAt??t.timeline?.committedAt??0,phase:t.phase,slotId:t.slotId,rejectReason:t.rejectReason})).sort((t,e)=>(t.at??0)-(e.at??0));return{carrierId:t,steps:s}}catch{return n}}async activeCarrierIds(t=0,e=200){const n=this._getScene(t);if(!n)return[];const i=n.rootContainer;if(!i)return[];const s=new Set,r=i.model_layer;r&&this._traverseComponent(r,t=>{if(t===r)return;if(s.size>=e)return;if(!(!0===t.isItem||"Carrier"===t.constructor?.name||"Carrier"===t.model?.type))return;const n=this._componentId(t);n&&s.add(n)});try{const t=i.carrierManager??i.root?.carrierManager??n.carrierManager,r=t?.carriers;if(r instanceof Map)r.forEach((t,n)=>{"string"==typeof n&&s.size<e&&s.add(n)});else if(r&&"object"==typeof r)for(const t of Object.keys(r))s.size<e&&s.add(t)}catch{}try{const t=globalThis.__THINGS_SCENE_TRANSFER_LOG__;if(t){const n="function"==typeof t.toJSON?t.toJSON():"function"==typeof t.entries?t.entries():[];if(Array.isArray(n))for(let t=n.length-1;t>=0&&s.size<e;t--){const e=n[t],i=e.carrierId??e.carrier?.state?.id??e.carrier?.refid;null!=i&&s.add(String(i))}}}catch{}return[...s]}};class Cd{constructor(){this._built=!1,this._visible=!1,this._manualOpen=!1,this._renderer=new jd}get renderer(){return this._renderer}set renderer(t){if(t===this._renderer)return;const e=this._visible;this._teardownContainer(),this._renderer=t,e&&this._show()}attach(t,e,n){this._targetElement=t,this._tracker=e,this._lagTracker=n,this._visible=!1,e&&(e.needsOverlay&&this._show(),e.onNeedsOverlay=()=>{this._visible||this._manualOpen||this._show()},e.onComplete=()=>{this._visible&&(this._update(),this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3))})}toggle(){this._visible?(this._hide(),this._manualOpen=!1):(this._manualOpen=!0,this._show())}show(){this._manualOpen=!0,this._show()}hide(){this._manualOpen=!1,this._hide()}destroy(){this._hide(),this._teardownContainer(),this._targetElement=void 0,this._tracker=void 0,this._lagTracker=void 0}get isVisible(){return this._visible}get isAttached(){return!!this._targetElement}_teardownContainer(){if(this._renderer.destroy)try{this._renderer.destroy()}catch{}this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._built=!1}get _host(){return{hide:()=>this.hide(),cancel:()=>this._cancel()}}_show(){if(this._targetElement){if(!this._container){const t=document.createElement("div");t.setAttribute("scene","loading-overlay"),t.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:9999",t.addEventListener("keydown",t=>t.stopPropagation()),this._container=t}this._built||(this._renderer.build(this._container,this._host),this._built=!0),this._container.parentElement||this._targetElement.appendChild(this._container),this._container.style.display="block",this._visible=!0,this._update(),this._updateTimer||(this._updateTimer=setInterval(()=>this._update(),500)),"complete"!==this._tracker?.phase||this._manualOpen||setTimeout(()=>{this._manualOpen||this._hide()},5e3)}}_hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._updateTimer&&(clearInterval(this._updateTimer),this._updateTimer=void 0)}_update(){this._visible&&this._tracker&&this._renderer.update(this._assembleState())}_assembleState(){const t=this._tracker;let e;if(this._lagTracker){this._lagTracker.evaluate();const t=this._lagTracker.getStats();t.sampleCount>0&&(e=t)}return{phase:t.phase,isComplete:"complete"===t.phase,stats:t.stats,phaseHistory:t.phaseHistory,pending:t.pending,entries:t.entries,lag:e}}_cancel(){if(this.hide(),this.onCancel)try{this.onCancel()}catch{}else try{window.history.back()}catch{}}}const Td={fetch:"Fetching model...",parse:"Parsing model...",init:"Initializing...",compile:"Building components...",assets:"Loading assets...",data:"Waiting for data...",render:"Rendering..."},Pd={leading:{word:"LEAD",arrow:"◂",color:"#3ddc84"},lagging:{word:"LAG",arrow:"▸",color:"#ff5a5a"},ontrack:{word:"SYNC",arrow:"≈",color:"#aab0b6"}},Od={warn:"#ff4040",critical:"#ff1f1f"};function Dd(t){const e=Math.abs(t);return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function zd(t){return`${Math.round(t).toLocaleString()}ms`}function Id(t,e){return"lagging"===t?Od[e]||Pd.lagging.color:Pd[t].color}function Rd(t,e){const n=Pd[t],i=function(t){const e=Math.round(t);return`${e>0?"+":e<0?"−":"±"}${Math.abs(e).toLocaleString()}ms`}(e);return"lagging"===t?`${n.word} ${i} ${n.arrow}`:`${n.arrow} ${n.word} ${i}`}class jd{constructor(){this._phaseRenderedCount=0}build(t,e){this._phaseRenderedCount=0;const n=document.createElement("div");n.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:320px","max-width:450px","padding:12px 16px","gap:8px"].join(";");const i=document.createElement("div");i.style.cssText="display:flex;align-items:center;justify-content:space-between";const s=document.createElement("span");s.style.cssText="font-weight:600;font-size:13px",s.textContent="Loading...",this._headerEl=s,i.appendChild(s);const r=document.createElement("button");r.textContent="✕",r.title="Close",r.style.cssText="background:none;border:none;color:rgba(255,255,255,0.6);cursor:pointer;font-size:14px;padding:2px 4px;border-radius:3px;line-height:1",r.addEventListener("mouseenter",()=>{r.style.color="rgba(255,255,255,0.9)"}),r.addEventListener("mouseleave",()=>{r.style.color="rgba(255,255,255,0.6)"}),r.addEventListener("click",()=>e.hide()),i.appendChild(r),n.appendChild(i);const o=document.createElement("div");o.style.cssText="display:flex;align-items:center;gap:8px";const a=document.createElement("div");a.style.cssText="flex:1;height:4px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden";const c=document.createElement("div");c.style.cssText="height:100%;width:0%;background:rgba(74,158,255,0.8);border-radius:2px;transition:width 0.3s ease",this._progressFillEl=c,a.appendChild(c),o.appendChild(a);const l=document.createElement("span");l.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;min-width:80px;text-align:right",this._progressTextEl=l,o.appendChild(l),n.appendChild(o);const h=document.createElement("div");h.style.cssText="border-top:1px solid rgba(255,255,255,0.08);padding-top:4px",this._phaseListEl=h,n.appendChild(h);const d=document.createElement("div");d.style.cssText="max-height:120px;overflow-y:auto",this._pendingListEl=d,n.appendChild(d);const u=document.createElement("div");this._lagSectionEl=u,n.appendChild(u);const p=document.createElement("div");p.style.cssText="display:flex;align-items:center;justify-content:center;border-top:1px solid rgba(255,255,255,0.08);padding-top:8px",this._footerRowEl=p;const f=document.createElement("button");f.textContent="← Cancel loading",f.title="Cancel loading and go back",f.style.cssText="background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);color:rgba(255,255,255,0.7);cursor:pointer;font-size:11px;padding:5px 12px;border-radius:4px;line-height:1",f.addEventListener("mouseenter",()=>{f.style.background="rgba(255,80,80,0.18)",f.style.color="rgba(255,255,255,0.95)"}),f.addEventListener("mouseleave",()=>{f.style.background="rgba(255,255,255,0.06)",f.style.color="rgba(255,255,255,0.7)"}),f.addEventListener("click",()=>e.cancel()),p.appendChild(f),n.appendChild(p),t.appendChild(n)}update(t){const{phase:e,isComplete:n,stats:i}=t;if(this._headerEl){const t=`${(i.elapsed/1e3).toFixed(1)}s`;this._headerEl.textContent=n?`Scene Monitor — ${t}`:`Scene Monitor — ${Td[e]||e} · ${t}`}this._footerRowEl&&(this._footerRowEl.style.display=n?"none":"flex"),this._updateProgress(t),this._updatePhaseList(t),this._updateAssetList(t),this._updateLagDisplay(t)}destroy(){this._headerEl=void 0,this._progressFillEl=void 0,this._progressTextEl=void 0,this._phaseListEl=void 0,this._pendingListEl=void 0,this._lagSectionEl=void 0,this._footerRowEl=void 0,this._phaseRenderedCount=0}_updateProgress(t){if(!this._progressFillEl&&!this._progressTextEl)return;const e=t.phaseHistory,n=e.length,i=e.filter(t=>void 0!==t.duration).length,s=n>0?Math.round(i/n*100):t.isComplete?100:0;this._progressFillEl&&(this._progressFillEl.style.width=s+"%"),this._progressTextEl&&(this._progressTextEl.textContent=`${i} / ${n}`)}_updatePhaseList(t){if(!this._phaseListEl)return;const e=t.phaseHistory;for(let t=this._phaseRenderedCount;t<e.length;t++){const n=e[t];if("complete"===n.phase)continue;const i=150*(t-this._phaseRenderedCount),s=document.createElement("div");s.dataset.phase=n.phase,s.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px;opacity:0;transition:opacity 0.3s ease",s.innerHTML='<span data-field="icon" style="flex-shrink:0"></span><span data-field="label" style="flex:1"></span><span data-field="time" style="width:60px;text-align:right"></span>',this._phaseListEl.appendChild(s),setTimeout(()=>{s.style.opacity="1"},i+16)}this._phaseRenderedCount=e.length;const n=performance.now();for(const t of Array.from(this._phaseListEl.querySelectorAll("[data-phase]"))){const i=t,s=e.find(t=>t.phase===i.dataset.phase);if(!s)continue;const r=Td[s.phase]||s.phase,o=i.querySelector('[data-field="icon"]'),a=i.querySelector('[data-field="label"]'),c=i.querySelector('[data-field="time"]');void 0===s.duration?(o.textContent="⏳",o.style.color="rgba(255,200,50,0.8)",a.textContent=r,a.style.color="rgba(255,255,255,0.9)",c.textContent=`${((n-s.timestamp)/1e3).toFixed(1)}s`,c.style.color="rgba(255,200,50,0.8)"):(o.textContent="✓",o.style.color="rgba(100,200,100,0.8)",a.textContent=r,a.style.color="rgba(255,255,255,0.5)",c.textContent=`${(s.duration/1e3).toFixed(1)}s`,c.style.color="rgba(255,255,255,0.4)")}}_updateAssetList(t){if(!this._pendingListEl)return;const{isComplete:e,stats:n}=t;if(e&&"complete"!==this._pendingListEl.dataset.mode)this._pendingListEl.innerHTML="",this._pendingListEl.dataset.mode="complete",this._renderHistorySummary(n,t.entries);else if(!e){this._pendingListEl.dataset.mode="pending";const e=t.pending.slice().sort((t,e)=>e.elapsed-t.elapsed),n=e.slice(0,5);for(let t=0;t<n.length;t++)t<this._pendingListEl.children.length?this._updatePendingRow(this._pendingListEl.children[t],n[t]):this._pendingListEl.appendChild(this._createPendingRow(n[t]));const i=n.length+(e.length>5?1:0);for(;this._pendingListEl.children.length>i;)this._pendingListEl.lastChild?.remove();if(e.length>5){const t=this._pendingListEl.lastElementChild;if(t?.dataset?.more)t.textContent=`... ${e.length-5} more`;else{const t=document.createElement("div");t.dataset.more="1",t.style.cssText="color:rgba(255,255,255,0.4);font-size:11px;padding:2px 0",t.textContent=`... ${e.length-5} more`,this._pendingListEl.appendChild(t)}}}}_updateLagDisplay(t){if(!this._lagSectionEl)return;const e=t.lag;e&&(this._lagSectionEl.dataset.built?this._updateLagSection(e):(this._lagSectionEl.innerHTML="",this._renderLagSection(e),this._lagSectionEl.dataset.built="1"))}_renderHistorySummary(t,e){if(!this._pendingListEl)return;const n=document.createElement("div");n.style.cssText="color:rgba(255,255,255,0.7);padding:2px 0;font-size:12px",n.textContent=`Total: ${t.total} assets | Loaded: ${t.loaded} | Timeout: ${t.timeout} | Error: ${t.error}`,this._pendingListEl.appendChild(n);const i=e.filter(t=>"pending"!==t.status).sort((t,e)=>e.elapsed-t.elapsed).slice(0,5);for(const t of i){const e=document.createElement("div");e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px";const n="loaded"===t.status?"✓":"timeout"===t.status?"⚠":"✗",i="loaded"===t.status?"rgba(100,200,100,0.8)":"timeout"===t.status?"rgba(255,180,50,0.8)":"rgba(255,80,80,0.8)";e.innerHTML=`<span style="color:${i}">${n}</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,this._pendingListEl.appendChild(e)}}_lagGauge(t){const{current:e,baseline:n,min:i,max:s,drift:r}=t,o=Math.max(n-i,s-n,1e3),a=t=>{return 50+50*(s=1,(e=(t-n)/o)<(i=-1)?i:e>s?s:e);var e,i,s},c=function(t){const e=Math.round(t);return e>0?"lagging":e<0?"leading":"ontrack"}(r);return{curPct:a(e),minPct:a(i),maxPct:a(s),direction:c}}_lagFill(t){return t>=50?`left:50%;width:${(t-50).toFixed(2)}%`:`left:${t.toFixed(2)}%;width:${(50-t).toFixed(2)}%`}_renderLagSection(t){if(!this._lagSectionEl)return;const e=Dd,{curPct:n,minPct:i,maxPct:s,direction:r}=this._lagGauge(t),o=Id(r,t.level),a=document.createElement("div");a.style.cssText="display:flex;align-items:baseline;gap:8px;padding:4px 0 3px;border-top:1px solid rgba(255,255,255,0.08);margin-top:4px",a.innerHTML=`<span style="color:rgba(255,255,255,0.5);font-size:11px;flex:1">Data Lag</span><span data-field="cur" style="color:rgba(255,255,255,0.5);font-size:11px">cur ${zd(t.current)}</span><span data-field="dir" style="color:${o};font-size:10px;font-weight:600;white-space:nowrap">${Rd(r,t.drift)}</span>`,this._lagSectionEl.appendChild(a);const c=(t,e)=>`<div data-field="${t}" style="position:absolute;left:${e}%;top:-1px;width:1px;height:8px;background:rgba(255,255,255,0.28);transform:translateX(-50%)"></div>`,l=document.createElement("div");l.style.cssText="position:relative;height:6px;background:rgba(255,255,255,0.08);border-radius:3px;margin:2px 0 3px",l.innerHTML='<div style="position:absolute;left:50%;top:-3px;width:1px;height:12px;background:rgba(255,255,255,0.45);transform:translateX(-50%)"></div>'+c("mintick",i)+c("maxtick",s)+`<div data-field="fill" style="position:absolute;top:50%;height:3px;transform:translateY(-50%);border-radius:2px;background:${o};opacity:0.5;${this._lagFill(n)}"></div>`+`<div data-field="dot" style="position:absolute;top:50%;width:9px;height:9px;border-radius:50%;background:${o};box-shadow:0 0 0 2px rgba(0,0,0,0.35);transform:translate(-50%,-50%);left:${n}%;transition:left 0.3s ease"></div>`,this._lagSectionEl.appendChild(l);const h=document.createElement("div");h.style.cssText="display:flex;align-items:center;font-size:10px;color:rgba(255,255,255,0.4)",h.innerHTML=`<span data-field="min" style="flex:1">min ${e(t.min)}</span><span data-field="base" style="flex:1;text-align:center;color:rgba(255,255,255,0.3)">base ${e(t.baseline)} · n ${t.sampleCount}</span><span data-field="max" style="flex:1;text-align:right">max ${e(t.max)}</span>`,this._lagSectionEl.appendChild(h)}_createPendingRow(t){const e=document.createElement("div");return e.style.cssText="display:flex;gap:8px;align-items:center;padding:1px 0;font-size:11px",e.dataset.id=t.id,e.innerHTML=`<span style="color:rgba(255,200,50,0.7)">⏳</span><span style="color:rgba(74,158,255,0.8);width:50px">${t.type}</span><span data-field="url" style="color:rgba(255,255,255,0.6);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${this._shortUrl(t.url)}</span><span data-field="time" style="color:rgba(255,255,255,0.5);width:50px;text-align:right">${(t.elapsed/1e3).toFixed(1)}s</span>`,e}_updatePendingRow(t,e){const n=t.querySelector('[data-field="url"]'),i=t.querySelector('[data-field="time"]');n&&(n.textContent=this._shortUrl(e.url)),i&&(i.textContent=`${(e.elapsed/1e3).toFixed(1)}s`)}_updateLagSection(t){if(!this._lagSectionEl)return;const e=Dd,{curPct:n,minPct:i,maxPct:s,direction:r}=this._lagGauge(t),o=Id(r,t.level),a=t=>this._lagSectionEl.querySelector(t),c=a('[data-field="cur"]');c&&(c.textContent=`cur ${zd(t.current)}`);const l=a('[data-field="dir"]');l&&(l.textContent=Rd(r,t.drift),l.style.color=o);const h=a('[data-field="dot"]');h&&(h.style.left=`${n}%`,h.style.background=o);const d=a('[data-field="fill"]');d&&(d.style.background=o,n>=50?(d.style.left="50%",d.style.width=`${(n-50).toFixed(2)}%`):(d.style.left=`${n.toFixed(2)}%`,d.style.width=`${(50-n).toFixed(2)}%`));const u=a('[data-field="mintick"]');u&&(u.style.left=`${i}%`);const p=a('[data-field="maxtick"]');p&&(p.style.left=`${s}%`);const f=a('[data-field="min"]');f&&(f.textContent=`min ${e(t.min)}`);const m=a('[data-field="base"]');m&&(m.textContent=`base ${e(t.baseline)} · n ${t.sampleCount}`);const g=a('[data-field="max"]');g&&(g.textContent=`max ${e(t.max)}`)}_shortUrl(t){if(!t)return"";const e=t.split("/");return e[e.length-1]||t}}const Ld=new WeakMap,Fd="__canonicalMaterial",Nd="base";function Hd(t){return Math.max(0,Math.round(100*t)/100)}function Bd(t){const n=[];var i;return null!=t.color&&n.push("c:"+(i=t.color,new e.Color(i).getHexString())),null!=t.opacityFactor&&Hd(t.opacityFactor)<1&&n.push("o:"+Hd(t.opacityFactor)),n.join("|")}function Gd(t,e){const n=Bd(e);if(""===n)return t;let i=Ld.get(t);i||Ld.set(t,i=new Map);let s=i.get(n);return s||(s=t.clone(),s.userData={__isVariant:!0,[Nd]:t},i.set(n,s)),function(t,e,n){if(null!=n.color&&t.color&&t.color.set(n.color),null!=n.opacityFactor){t.opacity=e.opacity*Hd(n.opacityFactor);const i=t.opacity<1||!!e.transparent;t.transparent!==i&&(t.transparent=i,t.needsUpdate=!0)}}(s,t,e),s}function Vd(t){t.traverse?.(t=>{const e=t.userData?.[Fd];e&&(t.material=e,delete t.userData[Fd])})}function Yd(t){const e=Ld.get(t);if(e){for(const t of e.values())t.dispose();Ld.delete(t)}}const Wd=.001;function Ud(t){return t&&"none"!=t&&"transparent"!=t?"string"==typeof t?p(t).getAlpha():1:0}function $d(t,e,n){const i=Ud(n);t.opacity=i,t.transparent=i<1}function Xd(t){const e=p(t);return e.isValid()?e.toHexString():t}const qd={width:1,height:1,depth:1},Kd={x:1,y:1,z:1},Qd={x:0,y:0,z:0},Zd={x:0,y:0,z:0},Jd=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap"];function tu(t){const e=t.userData;if(!e?.__bankOwned&&!e?.__isVariant){for(const e of Jd){const n=t[e];n?.dispose()}Yd(t),t.dispose()}}function eu(t){t.traverse(t=>{const e=t.userData?.dispose;if("function"==typeof e)try{e()}catch{}if(t.geometry&&!0!==t.geometry.userData?.__bankOwned&&t.geometry.dispose(),t.material){const e=Array.isArray(t.material)?t.material:[t.material];for(const t of e)tu(t)}})}function nu(t,e,n){const i=document.createElement("canvas");i.width=e,i.height=n;const s=i.getContext("2d");if(!s)return null;let r;if("radial"===t.gradientType){const i=e/2,o=n/2,a=Math.max(e,n)/2;switch(t.center){case"left-top":r=s.createRadialGradient(0,0,0,0,0,2*a);break;case"right-top":r=s.createRadialGradient(e,0,0,e,0,2*a);break;case"left-bottom":r=s.createRadialGradient(0,n,0,0,n,2*a);break;case"right-bottom":r=s.createRadialGradient(e,n,0,e,n,2*a);break;default:r=s.createRadialGradient(i,o,0,i,o,a)}}else{const i=t.rotation??0,o=e/2,a=n/2,c=Math.cos(i)*o,l=Math.sin(i)*a;r=s.createLinearGradient(o-c,a-l,o+c,a+l)}const o=Array.isArray(t.colorStops)?t.colorStops:Array.isArray(t.gradientStops)?t.gradientStops:[];for(const t of o)if(t.position>=0&&t.position<=1)try{r.addColorStop(t.position,t.color)}catch{r.addColorStop(t.position,"#fff")}return s.fillStyle=r,s.fillRect(0,0,e,n),i}function iu(t,n){n&&(!0===n.mirror&&(t.wrapS=e.RepeatWrapping,t.repeat.x=-t.repeat.x,t.offset.x=1-t.offset.x),n.rotation&&(t.center.set(.5,.5),t.rotation=n.rotation*Math.PI/180))}function su(t,n,i){const s=void 0!==n?n:t.state.fillStyle;if(!s||"object"!=typeof s)return;const r=s;if("pattern"===r.type&&r.image)return function(t,n,i){const{width:s,height:r}=t.bounds,o=Math.abs(s)||1,a=Math.abs(r)||1,c=new e.Texture;c.colorSpace=e.SRGBColorSpace;const l=new Image;"data"!==String(n.image).substring(0,4)&&(l.crossOrigin="anonymous"),l.onload=()=>{if(n.fitPattern){const t=2*o,i=2*a,s=document.createElement("canvas");s.width=t,s.height=i;const r=s.getContext("2d");if(!r)return;n.color&&(r.fillStyle=n.color,r.fillRect(0,0,t,i)),r.drawImage(l,0,0,t,i),c.image=s,c.wrapS=e.ClampToEdgeWrapping,c.wrapT=e.ClampToEdgeWrapping,c.repeat.set(1,1),c.offset.set(0,0)}else if(n.noRepeat){const t=2*o,i=2*a,s=2*(n.width||l.naturalWidth),r=2*(n.height||l.naturalHeight),h=2*(n.offsetX||0),d=2*(n.offsetY||0);let u=0,p=0;switch(n.align){case"center":u=(t-s)/2,p=(i-r)/2;break;case"left-top":break;case"left-bottom":p=i-r;break;case"right-top":u=t-s;break;case"right-bottom":u=t-s,p=i-r;break;case"left":p=(i-r)/2;break;case"right":u=t-s,p=(i-r)/2;break;case"top":u=(t-s)/2;break;case"bottom":u=(t-s)/2,p=i-r}const f=document.createElement("canvas");f.width=t,f.height=i;const m=f.getContext("2d");if(!m)return;n.color&&(m.fillStyle=n.color,m.fillRect(0,0,t,i)),m.drawImage(l,0,0,l.naturalWidth,l.naturalHeight,h+u,d+p,s,r),c.image=f,c.wrapS=e.ClampToEdgeWrapping,c.wrapT=e.ClampToEdgeWrapping,c.repeat.set(1,1),c.offset.set(0,0)}else{const t=n.width||l.naturalWidth,i=n.height||l.naturalHeight,s=2*t,r=2*i,h=document.createElement("canvas");h.width=s,h.height=r;const d=h.getContext("2d");if(!d)return;n.color&&(d.fillStyle=n.color,d.fillRect(0,0,s,r)),d.drawImage(l,0,0,s,r);let u=0,p=0;switch(n.align){case"center":u=(o-t)/2,p=(a-i)/2;break;case"left-top":break;case"left-bottom":p=a-i;break;case"right-top":u=o-t;break;case"right-bottom":u=o-t,p=a-i;break;case"left":p=(a-i)/2;break;case"right":u=o-t,p=(a-i)/2;break;case"top":u=(o-t)/2;break;case"bottom":u=(o-t)/2,p=a-i}const f=(n.offsetX||0)+u,m=(n.offsetY||0)+p;c.image=h,c.wrapS=e.RepeatWrapping,c.wrapT=e.RepeatWrapping,c.repeat.set(o/t,a/i),c.offset.set(-f/t,m/i)}c.minFilter=e.LinearFilter,iu(c,i),c.needsUpdate=!0,t.invalidate()},l.onerror=t=>{Zi("Pattern texture load error:",t)};const h=n.image;l.src=t.app.url(h);const d=t.root?.app?.loadTracker;if(d){const t=new Promise((t,e)=>{l.addEventListener("load",()=>t(),{once:!0}),l.addEventListener("error",()=>e(),{once:!0})});d.track(`pattern:${h}`,"pattern",h,t)}return c}(t,r,i);if("gradient"===r.type){if(Array.isArray(r.colorStops)&&r.colorStops.length>0||Array.isArray(r.gradientStops)&&r.gradientStops.length>0){const t=function(t){const n=nu(t,256,256);if(!n)return;const i=new e.CanvasTexture(n);return i.colorSpace=e.SRGBColorSpace,i.needsUpdate=!0,i}(r);return t&&iu(t,i),t}}}const ru={policy:"state-driven"};function ou(t){return"state-driven"===t.policy}const au={BACKDROP:4,FLOOR:2,OBJECTS:0,DECAL:-1,OUTLINE:-4};function cu(t){return t&&Number.isFinite(t)?{enabled:!0,factor:t,units:t}:{enabled:!1,factor:0,units:0}}function lu(t,e){const n=cu(e);t.traverse(t=>{const e=t;if(!e.isMesh&&!t.isLine&&!t.isPoints)return;const i=e.material;if(i)if(Array.isArray(i))for(const t of i)hu(t,n);else hu(i,n)})}function hu(t,e){t.polygonOffset=e.enabled,t.polygonOffsetFactor=e.factor,t.polygonOffsetUnits=e.units,t.needsUpdate=!0}function du(t,e){return-1!==t.findIndex(t=>t in e)}const uu=()=>{};class pu{static buildFillStyleTexture(t,e,n){return su(t,e,n)}constructor(t){this._focused=!1,this._suppressOnchange=!1,this._onchangeWrapper=(t,e,n)=>{this._suppressOnchange||n&&n.origin&&n.origin!==this._component||this.onchange(t,e)},this.suppressTransform=!1,this._dimensionScale={x:1,y:1,z:1},this._component=t,this.object3d=this.getObject3dInstance(),this.component.on("change",this._onchangeWrapper)}update(){this.clear(),this.build(),this.updateTransform(),this.updateFillStyle(),this.updateStrokeStyle(),this.updateAlpha(),this.applyFocusDim(),this.updateHidden(),this.updateText(),this._applyZPriority(),this._applyRaycastTarget()}_applyZPriority(){const t=this.component.state?.zPriority,e="number"==typeof t&&Number.isFinite(t)?t:this.zPriority;0!==e&&lu(this.object3d,e)}get zPriority(){return au.OBJECTS}getObject3dInstance(){return new e.Object3D}build(){this.object3d.userData.context=this;const t=Md(this.component.state.material3d),{cast:e,receive:n}=this.resolveShadow(t.castShadow,t.receiveShadow);this._applyShadow(e,n),this.object3d.name=this.component.state.id}updateMaterial3d(){const t=Md(this.component.state.material3d),{cast:e,receive:n}=this.resolveShadow(t.castShadow,t.receiveShadow);this._applyShadow(e,n)}resolveShadow(t=!0,e=!1){return{cast:t,receive:e}}_applyShadow(t,e){const n=i=>{i.castShadow=t,i.receiveShadow=e;for(const t of i.children){const e=t.userData?.context;e&&e!==this||n(t)}};n(this.object3d)}get gizmoTransformable(){return!0}get allowedGizmoModes(){return null}get component(){return this._component}get threeContainer(){let t=this.component;for(;t;){if("is3dContainer"in t&&t.is3dContainer())return t;t=t.parent}}get focused(){return this._focused}set focused(t){this._focused=t,t&&(this._focusedAt=performance.now())}dispose(){this.component.off("change",this._onchangeWrapper),this.clear()}clear(){const t=[];for(const e of this.object3d.children){const n=e.userData?.context;n&&n!==this&&n instanceof pu?t.push(e):(Vd(e),eu(e))}this._components3D=void 0,this.object3d.userData={},this.object3d.clear();for(const e of t)this.object3d.add(e);return this.object3d}get placement(){return this._transientPlacement??ru}setTransientPlacement(t){this._transientPlacement=t}clearTransientPlacement(){this._transientPlacement=void 0}layoutHeldItems(){const t=this.component,e=t?._items??[];if(0===e.length||"function"!=typeof t.placementFor)return;const n=new Set((t.slots??[]).map(t=>t?.id));let i=0;for(const s of e){const e=s?._transferSlotId;if(null!=e&&n.has(e))continue;const r=s?._realObject?.object3d;if(!r){i++;continue}const o=t.placementFor(s,{index:i,occupantCount:i});i++,o?.position&&(r.parent!==this.object3d&&this.object3d.attach(r),r.position.set(o.position.x,o.position.y,o.position.z),o.rotation?r.quaternion.set(o.rotation.x,o.rotation.y,o.rotation.z,o.rotation.w):r.quaternion.identity())}}updateTransform(){if(this.suppressTransform)return;if(!ou(this.placement))return;if(this.component.state.screenFixed&&this.component.isHTMLElement()){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{};return this.object3d.position.set(t-n/2,-(e-i/2),0),void this.object3d.rotation.set(0,0,0)}const{x:t,y:e,z:n}=this.position,{x:i,y:s,z:r}=this.rotation,{x:o,y:a,z:c}=this.scale;this.object3d.position.set(t,e,n),this.object3d.rotation.set(i,s,r),this.applyScale(o,a,c)}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 t=this.effectiveZPos,{tz:e=0}=this.component.delta(),n=this.component.parent?._realObject,i=n?.geometricOffsetY??0,s=n?.receivingSurfaceY??0;return t+e+this.syncZPosOffset-i+s}get receivingSurfaceY(){return 0}surfaceAtLocalY(t){return t+this.geometricOffsetY}placementSurfaceY(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return this.surfaceAtLocalY(0);case"inverted":return this.surfaceAtLocalY(-t);default:return this.surfaceAtLocalY(t)}}get effectiveZPos(){const t=this.component.state.zPos;if("number"==typeof t&&Number.isFinite(t))return t;const e=this.component.effectiveZPos;return"number"==typeof e&&Number.isFinite(e)?e:0}get geometricOffsetY(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get scenePlacement(){const t=this.component.rootModel??this.component,e=t?.state?.placement;return"space"===e||"inverted"===e?e:"floor"}get placementMode(){return this.scenePlacement}get components3D(){return this._components3D&&this._components3D.parent===this.object3d||(this._components3D=new e.Group,this.object3d.add(this._components3D)),this._components3D.position.y=-this.geometricOffsetY,this._components3D}get center(){const{x:t=0,y:e=0}=this.component.center,{width:n=0,height:i=0}=this.component.parent?.bounds??{},{tx:s=0,ty:r=0}=this.component.delta();return{x:t+s-n/2,y:e+r-i/2,z:this.cz}}freezeDimension(){this._frozenDimension={...this.dimension}}unfreezeDimension(){delete this._frozenDimension}get dimension(){if(this._frozenDimension)return this._frozenDimension;const{width:t,height:e}=this.component.bounds;return{width:Math.abs(t)||1,height:Math.abs(e)||1,depth:this.effectiveDepth}}get effectiveDepth(){const t=this.component.state.depth;if("number"==typeof t&&Number.isFinite(t)&&t>0)return t;const e=this.component.effectiveDepth;return"number"==typeof e&&Number.isFinite(e)&&e>0?e: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)}get dimensionScale(){return this._dimensionScale}setDimensionScale(t,e,n){Number.isFinite(t)&&Number.isFinite(e)&&Number.isFinite(n)&&(this._dimensionScale={x:t,y:e,z:n},this.updateScale())}applyScale(t,e,n){const i=this._dimensionScale;this.object3d.scale.set(Math.max(t*i.x,Wd),Math.max(e*i.y,Wd),Math.max(n*i.z,Wd))}updateScale(){const{x:t=1,y:e=1,z:n=1}=this.scale;this.applyScale(t,e,n)}syncAnimationDelta(){if(this.suppressTransform)return;const t=this.component.delta();this.updatePosition();const{rotationX:e=0,rotationY:n=0,rotation:i=0}=this.component.state,s=t.theta||0,r=t.rx||0,o=t.ry||0,a=t.rz||0;this.object3d.rotation.set(e+r,-(i+s)+o,n+a);const{scale:c}=this.component.state,l="number"==typeof c?c:c?.x??1,h=t.sx??1,d=t.sy??1,u=t.sz??1;this.applyScale(l*h,l*d,l*u);const p=t.fade||0;if(0!==p){const t=(this.component.state.alpha??1)*(1-p);this.object3d.traverse(e=>{if(e.isMesh&&e.material){const n=Array.isArray(e.material)?e.material:[e.material];for(const e of n)e.opacity=t,e.transparent=e.opacity<1}})}}updateDimension(){this.clear(),this.build()}updateAlpha(){this.applyMaterialOpacity()}isModelingFaint(){return zo(this.component)}applyMaterialOpacity(){const t=this.component.state.alpha,e=null==t?1:t,n=this.isModelingFaint(),i=t=>{t.material&&function(t,e,n){if(!t.material)return;let i=t.userData[Fd];i||(i=t.material,t.userData[Fd]=i);const s=t=>{const i=t?.userData?.[Nd]??t;return n?Gd(i,{opacityFactor:.5}):e<1?Gd(i,{color:t.color,opacityFactor:e}):t};t.material=Array.isArray(i)?i.map(s):s(i)}(t,e,n);for(const e of t.children){const t=e.userData?.context;t&&t!==this&&t instanceof pu||i(e)}};i(this.object3d)}applyFocusDim(){this.applyMaterialOpacity()}updateHidden(){const t=this.component.app;if(t?.isEditMode)return this.object3d.visible=!0,void this.applyFocusDim();this.object3d.visible=!this.component.state.hidden}updateStrokeStyle(){}updateFillStyle(){}updateText(){}topOutline(){return null}_applyRaycastTarget(){const t=this.component.state.raycastTarget;let e;if("boolean"==typeof t)e=t;else{const t=this.component.constructor;e=!1!==t.raycastTargetDefault}const n=t=>{const i=t.userData?.context;if(t===this.object3d||!i||i===this){t.userData?.alwaysRaycast||(e?delete t.raycast:t.raycast=uu);for(const e of t.children)n(e)}};n(this.object3d)}get syncZPosOffset(){const t=this.effectiveDepth/2;switch(this.scenePlacement){case"space":return 0;case"inverted":return-t;default:return t}}get textSurfaceYOffset(){return this.effectiveDepth-this.syncZPosOffset}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},s=e.bounds,{tx:r=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0,e.bounds={left:t.position.x-r+n/2-s.width/2,top:t.position.z-o+i/2-s.height/2,width:s.width,height:s.height};const c=this.component.parent?._realObject,l=c?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+l,rotationX:t.rotation.x,rotation:-t.rotation.y,rotationY:t.rotation.z}),this._suppressOnchange=!1}onGizmoDragEnd(t){}applyDimensionFromGizmo(t){this._suppressOnchange=!0,this._component.set(t),this._suppressOnchange=!1}onchange(t,e){if("screenFixed"in t&&this.updateTransform(),du(["cx","cy","cz","zPos","left","top"],t)&&!this.suppressTransform&&ou(this.placement)&&this.updatePosition(),du(["width","height","depth","lineWidth","round","rx","ry","rz"],t)&&(this.updateDimension(),"depth"in t)){this.updatePosition();const t=this.component.components;if(t)for(const e of t){const t=e?._realObject;t?.updateTransform&&t.updateTransform()}}if(du(["segments","heightSegments"],t)&&this.update(),du(["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(),du(["text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline"],t))this._lastText=this.component.hasTextProperty?this.component.text:"",this.updateText();else if(du(["value","data"],t)){const t=this.component.hasTextProperty?this.component.text:"";t!==this._lastText&&(this._lastText=t,this.updateText())}"material3d"in t&&this.updateMaterial3d(),"raycastTarget"in t&&this._applyRaycastTarget()}}function fu(t){if(!t||"object"!=typeof t)return!1;const e=t;return"function"==typeof e.partNames&&"function"==typeof e.partObject&&"function"==typeof e.partAt}function mu(t,e){for(let n=t;n;n=n.parent){if(e.get(n.name)===n)return n.name}}class gu extends pu{constructor(){super(...arguments),this._loadGen=0,this._objectSize=new e.Vector3}get objectSize(){return this._objectSize}build(){super.build();const{src:t}=this.component.state;if(!t)return this.clear(),this._showEmptyPlaceholder(),void(this.object3d.userData.context=this);const e=++this._loadGen,n=this.component.app.url(t),i=this._loadExternal(n).then(t=>{e===this._loadGen&&this._onLoaded(t)},t=>{e===this._loadGen&&(Zi(`${this._formatLabel}.load`,t),this.clear(),this._showErrorPlaceholder(),this.component.setState({loadError:String(t)}))});this.component.root?.app?.loadTracker?.track(`${this._formatLabel}:${t}`,this._formatLabel,t,i)}updateSource(){this.build()}get _placeholderColor(){return 6770852}_showEmptyPlaceholder(){const{width:t=100,height:n=100,depth:i=100}=this.component.state,s=t||100,r=n||100,o=i||100,a=this._placeholderColor,c=new e.BoxGeometry(s,o,r),l=new e.MeshStandardMaterial({color:a,transparent:!0,opacity:.15,depthWrite:!1}),h=new e.Mesh(c,l);h.name="__empty_placeholder__";const d=new e.EdgesGeometry(c),u=new e.LineBasicMaterial({color:a,transparent:!0,opacity:.4}),p=new e.LineSegments(d,u);p.name="__empty_placeholder_edge__",h.add(p),this.object3d.add(h)}_showErrorPlaceholder(){const t=new e.BoxGeometry(1,1,1),n=new e.MeshStandardMaterial({color:13369344,wireframe:!0}),i=new e.Mesh(t,n);i.name="__error_placeholder__",this.object3d.add(i)}clear(){return this.pivot&&eu(this.pivot),this.pivot=void 0,this._objectSize=void 0,super.clear()}}const yu="KHR_materials_pbrSpecularGlossiness";class bu{constructor(t){this.name=yu,this.parser=t}extendMaterialParams(t,e){const r=this.parser.json.materials?.[t],o=r?.extensions?.[yu];if(!o)return Promise.resolve();const a=[];if(Array.isArray(o.diffuseFactor)){const[t,s,r,a]=o.diffuseFactor;e.color||(e.color=new n),e.color.setRGB(t,s,r,i),e.opacity=a}null!=o.diffuseTexture&&a.push(this.parser.assignTexture(e,"map",o.diffuseTexture,s));const c=o.glossinessFactor??1;e.roughness=1-c;const l=o.specularFactor??[1,1,1],h=Math.max(l[0],l[1],l[2]);return e.metalness=h>.5?h:0,Promise.all(a)}}(()=>{const t="__urdfBlobCrossOriginPatched__",n=e.ImageLoader.prototype;if(n[t])return;const i=n.load;n.load=function(t,e,n,s){if("string"==typeof t&&t.startsWith("blob:")){const r=this.crossOrigin;this.crossOrigin=void 0;try{return i.call(this,t,e,n,s)}finally{this.crossOrigin=r}}return i.call(this,t,e,n,s)},n[t]=!0})();const _u={once:e.LoopOnce,repeat:e.LoopRepeat,pingpong:e.LoopPingPong};class vu extends gu{constructor(){super(...arguments),this._nodeIndex=new Map,this._originals=new Map,this._animationActions=new Map,this._fillStyleOriginals=new Map,this._clonedMaterials=new WeakSet}get _formatLabel(){return"gltf"}static getSharedSnapshotRenderer(){const t=vu._sharedSnapshotRenderer;if(t){const e=t.getContext();if(e&&!e.isContextLost())return t;try{t.forceContextLoss()}catch{}t.dispose(),vu._sharedSnapshotRenderer=void 0}try{const t=new e.WebGLRenderer({antialias:!0,alpha:!0}),n=t.getContext();if(!n||n.isContextLost()){try{t.forceContextLoss()}catch{}return void t.dispose()}return vu._sharedSnapshotRenderer=t,t}catch{return}}static getSharedLoader(t){if(!vu._sharedLoader){const t=new f;!function(t){t.register(t=>new bu(t))}(t);const e=new m;e.setDecoderPath("/node_modules/three/examples/jsm/libs/draco/"),t.setDRACOLoader(e);const n=new g;n.setTranscoderPath("/node_modules/three/examples/jsm/libs/basis/"),t.setKTX2Loader(n),t.setMeshoptDecoder(y),t.setCrossOrigin("anonymous"),vu._sharedLoader=t}return t&&vu._sharedLoader.ktx2Loader?.detectSupport(t),vu._sharedLoader}static loadGLTF(t,e){let n=vu._gltfCache.get(t);if(!n){const i=vu.getSharedLoader(e);n=new Promise((e,n)=>{i.load(t,e,void 0,n)}).catch(e=>{throw vu._gltfCache.delete(t),e}),vu._gltfCache.set(t,n)}return n}_ensureOwnMaterial(t){let e=t.material;return this._clonedMaterials.has(e)||(e=e.clone(),t.material=e,this._clonedMaterials.add(e)),e}_loadExternal(t){return vu.loadGLTF(t,this.threeContainer?.renderer3d)}_onLoaded(t){this.component.state.loadError&&this.component.setState({loadError:void 0});const n=t.scene,i=t.animations,s=b(n);s.userData.context=this,s.traverse(t=>{t.isMesh&&(t.castShadow=!0)});const r=(new e.Box3).setFromObject(s),o=r.getCenter(s.position),a=r.getSize(new e.Vector3);if(o.multiplyScalar(-1),this.clear(),this.object3d.userData.context=this,this._objectSize=a,this.pivot=new e.Object3D,this.component.state.floorAlign?this.components3D.add(this.pivot):this.object3d.add(this.pivot),this.pivot.add(s),this._buildNodeIndex(s),this.component.state.autoFit&&a.x>0&&a.y>0&&a.z>0){const t=(Number(this.component.state.autoFitSize)>0?Number(this.component.state.autoFitSize):200)/Math.max(a.x,a.y,a.z),e=Math.max(1,Math.round(a.x*t)),n=Math.max(1,Math.round(a.y*t)),i=Math.max(1,Math.round(a.z*t)),s=this.component;s._ratioLocking=!0;try{this.component.set({width:e,height:i,depth:n,autoFit:!1})}finally{s._ratioLocking=!1}}if(this.updateDimension(),this.component.state.floorAlign){const t=this.scenePlacement;if("space"!==t){this.components3D.updateMatrixWorld(!0);const n=(new e.Box3).setFromObject(this.pivot);if(isFinite(n.min.y)&&isFinite(n.max.y))if("inverted"===t){const t=this.components3D.worldToLocal(n.max.clone());t.y>0&&(this.pivot.position.y-=t.y)}else{const t=this.components3D.worldToLocal(n.min.clone());t.y<0&&(this.pivot.position.y-=t.y)}}}i&&i.length&&this._setupAnimations(i);const c=this.component.state.nodes;c&&this._applyNodeStates(c),this.updateFillStyle()}static renderTopView(t){const n=256,i=new e.Scene,s=t.parent;i.add(t);const r=new e.AmbientLight(16777215,.8);i.add(r);const o=new e.DirectionalLight(16777215,1);o.position.set(0,10,0),i.add(o);const a=(new e.Box3).setFromObject(t),c=a.getSize(new e.Vector3),l=a.getCenter(new e.Vector3),h=(c.x||1)/2*1.02,d=(c.z||1)/2*1.02,u=new e.OrthographicCamera(-h,h,d,-d,.01,10*c.y+1);u.position.set(l.x,a.max.y+c.y,l.z),u.lookAt(l.x,l.y,l.z);const p=h/d,f=p>=1?n:Math.round(n*p),m=p>=1?Math.round(n/p):n,g=vu.getSharedSnapshotRenderer();if(!g){s?s.add(t):i.remove(t);const e=document.createElement("canvas");return e.width=f,e.height=m,e}g.setClearColor(0,0),g.setSize(f,m),g.render(i,u),s?s.add(t):i.remove(t);const y=document.createElement("canvas");y.width=f,y.height=m;const b=y.getContext("2d");return b&&b.drawImage(g.domElement,0,0),y}static getTopViewCache(t){return vu._topViewCache.get(t)}static setTopViewCache(t,e){vu._topViewCache.set(t,e)}static flushCache(){if(vu._gltfCache.clear(),vu._topViewCache.clear(),vu._sharedSnapshotRenderer){try{vu._sharedSnapshotRenderer.forceContextLoss()}catch{}vu._sharedSnapshotRenderer.dispose(),vu._sharedSnapshotRenderer=void 0}}_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())}partNames(){return this.nodeNames}partObject(t){return this._nodeIndex.get(t)}partAt(t){return mu(t,this._nodeIndex)}_applyNodeStates(t){for(const[e,n]of Object.entries(t)){const t=this._nodeIndex.get(e);if(t&&(void 0!==n.visible&&(t.visible=n.visible),void 0!==n.scale&&t.scale.setScalar(n.scale),t.isMesh)){const e=t;if(!(void 0!==n.color||void 0!==n.opacity||void 0!==n.emissive||void 0!==n.emissiveIntensity))continue;const i=this._ensureOwnMaterial(e);void 0!==n.color&&i.color.set(n.color),void 0!==n.opacity&&(i.opacity=n.opacity,i.transparent=n.opacity<1),void 0!==n.emissive&&i.emissive.set(n.emissive),void 0!==n.emissiveIntensity&&(i.emissiveIntensity=n.emissiveIntensity)}}}_resetNode(t){const e=this._nodeIndex.get(t),n=this._originals.get(t);if(e&&n&&(e.visible=n.visible,e.scale.copy(n.scale),e.isMesh)){const t=e.material;t&&n.color&&(t.color.copy(n.color),t.opacity=n.opacity,t.transparent=n.transparent,t.emissive.copy(n.emissive),t.emissiveIntensity=n.emissiveIntensity)}}_resetAllNodes(){for(const t of this._originals.keys())this._resetNode(t)}_setupAnimations(t){const e=this.threeContainer.mixer;this._animationActions.clear();for(const n of t){const t=e.clipAction(n);this._animationActions.set(n.name,t)}!1!==this.component.state.play&&this._playTargetAnimations();const n=this.component.state.animations;n&&this._applyAnimationStates(n)}_playTargetAnimations(){const t=this.component.state.playTargets;if("*"===t)this._animationActions.forEach(t=>t.play());else if(Array.isArray(t)&&t.length>0)for(const e of t)this._animationActions.get(e)?.play()}_applyAnimationStates(t){for(const[n,i]of Object.entries(t)){const t=this._animationActions.get(n);t&&(void 0!==i.loop&&(t.loop=_u[i.loop]??e.LoopRepeat,"once"===i.loop&&(t.clampWhenFinished=!0)),void 0!==i.speed&&(t.timeScale=i.speed),void 0!==i.weight&&(t.weight=i.weight),void 0!==i.play&&(i.play?t.play():t.stop()))}}get animationNames(){return Array.from(this._animationActions.keys())}updateFillStyle(){const{fillStyle:t}=this.component.state;if(!t)return;const e=this.component.state.fillStyleTargets;let n;if("*"===e)n=[...this._nodeIndex.entries()].filter(([,t])=>t.isMesh).map(([t])=>t);else{if(!(Array.isArray(e)&&e.length>0))return;n=e}if(0===n.length)return;const i=pu.buildFillStyleTexture(this.component);for(const e of n){const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const s=this._ensureOwnMaterial(n);s&&(this._fillStyleOriginals.has(e)||this._fillStyleOriginals.set(e,{color:s.color.clone(),map:s.map,opacity:s.opacity,transparent:s.transparent}),i?(s.map&&s.map!==this._fillStyleOriginals.get(e)?.map&&s.map.dispose(),i.needsUpdate=!0,s.map=i):"string"==typeof t&&("transparent"!==t?s.color.set(t):(s.opacity=0,s.transparent=!0)))}}_restoreFillStyleTargets(t){for(const e of t){const t=this._fillStyleOriginals.get(e);if(!t)continue;const n=this._nodeIndex.get(e);if(!n||!n.isMesh)continue;const i=n.material;i&&(i.map&&i.map!==t.map&&i.map.dispose(),i.color.copy(t.color),i.map=t.map,i.opacity=t.opacity,i.transparent=t.transparent,this._fillStyleOriginals.delete(e))}}clear(){return this._animationActions.forEach(t=>t.stop()),this._animationActions.clear(),this._nodeIndex.clear(),this._originals.clear(),this._fillStyleOriginals.clear(),super.clear()}updateDimension(){const{width:t=1,height:e=1,depth:n=1}=this.component.state,{x:i=1,y:s=1,z:r=1}=this.objectSize||{};this.pivot&&this.pivot.scale.set(t/i,n/s,e/r),this.component.invalidate()}onchange(t,e){if(super.onchange(t,e),("src"in t||"floorAlign"in t)&&this.updateSource(),"nodes"in t){this._resetAllNodes();const e=t.nodes;e&&Object.keys(e).length>0&&this._applyNodeStates(e)}if("animations"in t){const e=t.animations;e&&this._applyAnimationStates(e)}if("fillStyleTargets"in t){const t=[...this._fillStyleOriginals.keys()];t.length>0&&this._restoreFillStyleTargets(t),this.updateFillStyle()}("play"in t||"playTargets"in t)&&(this._animationActions.forEach(t=>t.stop()),!1!==this.component.state.play&&this._playTargetAnimations())}}vu._topViewCache=new Map,vu._gltfCache=new Map,vu._sharedLoader=null;let xu=!0;function wu(){return xu}function Mu(t){xu=t}const Su=["id","name","tag","type","class","text","data","property"];class ku{constructor(){this._results=[],this._currentIndex=-1}get results(){return this._results}get currentIndex(){return this._currentIndex}get currentResult(){return this._results[this._currentIndex]}get resultCount(){return this._results.length}search(t,e,n){if(this._results=[],this._currentIndex=-1,!e||!t)return this._results;const i=n?.fields||Su,s=n?.caseSensitive??!1,r=n?.includeHidden??!1,o=n?.maxResults??1/0,a=s?e:e.toLowerCase(),c=new Set;return this._traverse(t,t=>{if(c.has(t))return;if(this._results.length>=o)return;if(!r&&t.state.hidden)return;const e=this._matchComponent(t,a,i,s);e&&(c.add(t),this._results.push(e))}),this._results.length>0&&(this._currentIndex=0),this._results}navigateNext(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex+1)%this._results.length,this._results[this._currentIndex]}navigatePrev(){if(0!==this._results.length)return this._currentIndex=(this._currentIndex-1+this._results.length)%this._results.length,this._results[this._currentIndex]}navigateTo(t){if(!(t<0||t>=this._results.length))return this._currentIndex=t,this._results[this._currentIndex]}clear(){this._results=[],this._currentIndex=-1}_traverse(t,e){e(t);const n=t.components;if(n)for(const t of n)this._traverse(t,e)}_matchComponent(t,e,n,i){const s=t.state,r=t=>{if(!t)return!1;return(i?t:t.toLowerCase()).includes(e)};for(const o of n)switch(o){case"id":if(r(s.id))return{component:t,matchType:"id",matchField:"id",matchValue:s.id};break;case"name":if(r(s.name))return{component:t,matchType:"name",matchField:"name",matchValue:s.name};break;case"tag":if(r(s.tag))return{component:t,matchType:"tag",matchField:"tag",matchValue:s.tag};break;case"type":if(r(s.type))return{component:t,matchType:"type",matchField:"type",matchValue:s.type};break;case"class":if(r(s.class))return{component:t,matchType:"class",matchField:"class",matchValue:s.class};break;case"text":if(r(s.text))return{component:t,matchType:"text",matchField:"text",matchValue:s.text};break;case"data":{const n=this._matchDataBinding(t,e,i);if(n)return n;break}case"property":{const n=this._matchProperties(t,e,i);if(n)return n;break}}return null}_matchDataBinding(t,e,n){const i=t._model,s=i?.mappings;if(!s||!Array.isArray(s))return null;const r=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)};for(const e of s){if(r(e.accessor))return{component:t,matchType:"data",matchField:"accessor",matchValue:e.accessor};if(r(e.target))return{component:t,matchType:"data",matchField:"target",matchValue:e.target};if(r(e.property))return{component:t,matchType:"data",matchField:"property",matchValue:e.property};if(r(e.source))return{component:t,matchType:"data",matchField:"source",matchValue:e.source}}return null}_matchProperties(t,e,n){const i=t.state,s=t=>{if(!t)return!1;return(n?t:t.toLowerCase()).includes(e)},r=["ref","src","value","action"];for(const e of r){const n=i[e];if("string"==typeof n&&s(n))return{component:t,matchType:"property",matchField:e,matchValue:n}}const o=i.fillStyle;if(o){if("string"==typeof o&&s(o))return{component:t,matchType:"property",matchField:"fillStyle",matchValue:o};if("object"==typeof o&&"pattern"===o.type&&"string"==typeof o.image&&s(o.image))return{component:t,matchType:"property",matchField:"fillStyle.image",matchValue:o.image}}return null}}const Au={id:"ID",name:"Name",tag:"Tag",type:"Type",class:"Class",text:"Text",data:"Data",property:"Prop"};class Eu{constructor(){this._engine=new ku,this._visible=!1,this._queryHistory=[],this._historyIndex=-1,this._savedInput=""}get isVisible(){return this._visible}get engine(){return this._engine}setup(t){this.destroy(),this._host=t}toggle(){this._visible?this._input&&document.activeElement!==this._input?(this._input.focus(),this._input.select()):this.hide():this.show()}show(){this._host?.element&&(this._container||this._buildDOM(),this._container&&!this._container.parentElement&&this._host.element.appendChild(this._container),this._container.style.display="flex",this._visible=!0,requestAnimationFrame(()=>{this._input?.focus(),this._input?.select()}))}hide(){this._container&&(this._container.style.display="none"),this._visible=!1,this._historyIndex=-1,this._clearHighlight(),this._engine.clear(),this._updateStatus(),this._hideResultList(),this._isEditMode()||(this._host?.root?.trigger?.("search-close",{}),this._invokeViewClose())}destroy(){this._container?.parentElement&&this._container.parentElement.removeChild(this._container),this._container=void 0,this._input=void 0,this._statusEl=void 0,this._resultListEl=void 0,this._host=void 0,this._visible=!1,this._engine.clear()}_buildDOM(){const t=this._host,e=document.createElement("div");e.setAttribute("scene","search-overlay"),["click","dblclick","mousedown","mouseup","mousemove","pointerdown","pointerup","pointermove","wheel","contextmenu","touchstart","touchmove","touchend"].forEach(t=>e.addEventListener(t,t=>t.stopPropagation())),e.style.cssText=["position:absolute","top:8px","left:50%","transform:translateX(-50%)","display:flex","flex-direction:column","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.12)","border-radius:8px","backdrop-filter:blur(12px)","pointer-events:auto","user-select:none","z-index:10000",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"font-size:13px","color:rgba(255,255,255,0.9)","box-shadow:0 4px 16px rgba(0,0,0,0.3)","min-width:280px","max-width:400px"].join(";");const n=document.createElement("div");n.style.cssText="display:flex;align-items:center;padding:6px 8px;gap:6px";const i=document.createElement("span");i.textContent="🔍",i.style.cssText="font-size:14px;flex-shrink:0;opacity:0.6;cursor:pointer",i.addEventListener("click",()=>this._submitQuery()),n.appendChild(i);const s=document.createElement("input");s.type="text",s.placeholder="Search: type, id, tag, text, data...",s.style.cssText=["flex:1","background:rgba(255,255,255,0.08)","border:1px solid rgba(255,255,255,0.15)","border-radius:4px","color:white","padding:4px 8px","font-size:13px","outline:none","min-width:0"].join(";"),s.addEventListener("focus",()=>{s.style.borderColor="rgba(74,158,255,0.6)"}),s.addEventListener("blur",()=>{s.style.borderColor="rgba(255,255,255,0.15)"}),n.appendChild(s);const r=document.createElement("span");r.style.cssText="font-size:11px;color:rgba(255,255,255,0.5);white-space:nowrap;flex-shrink:0",n.appendChild(r);const o=document.createElement("button");o.textContent="✕",o.title="Close (Esc)",o.style.cssText=this._buttonStyle(),o.addEventListener("click",()=>this.hide()),n.appendChild(o),e.appendChild(n);const a=document.createElement("div");a.style.cssText=["max-height:240px","overflow-y:auto","border-top:1px solid rgba(255,255,255,0.08)","display:none"].join(";"),e.appendChild(a),s.addEventListener("input",()=>{this._historyIndex=-1,this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>this._doSearch(s.value),150)}),s.addEventListener("keydown",e=>{if(e.stopPropagation(),"Escape"===e.key)return this.hide(),void t.element?.focus();if("ArrowDown"===e.key||"Tab"===e.key){if("Tab"===e.key&&e.shiftKey)return;return this._isHistoryMode()||!this._input?.value&&"ArrowDown"===e.key?this._navigateHistory(1):this._engine.resultCount>0&&this._focusResult(0),void e.preventDefault()}if("ArrowUp"===e.key)return this._navigateHistory(-1),void e.preventDefault();if("Enter"===e.key){if(this._submitQuery())return void e.preventDefault();const t=this._engine.currentIndex>=0?this._engine.currentIndex:0;return this._selectResult(t),void e.preventDefault()}}),this._container=e,this._input=s,this._statusEl=r,this._resultListEl=a,this._setupDrag(e,n)}_setupDrag(t,e){e.style.cursor="move",e.addEventListener("mousedown",e=>{if(e.target.closest("input, button"))return;e.preventDefault();const n=t.getBoundingClientRect(),i=t.offsetParent?.getBoundingClientRect(),s=n.left-(i?.left||0),r=n.top-(i?.top||0);t.style.transform="",t.style.right="auto",t.style.left=`${s}px`,t.style.top=`${r}px`;const o=e.clientX,a=e.clientY,c=e=>{t.style.left=s+e.clientX-o+"px",t.style.top=r+e.clientY-a+"px"},l=()=>{document.removeEventListener("mousemove",c,!0),document.removeEventListener("mouseup",l,!0)};document.addEventListener("mousemove",c,!0),document.addEventListener("mouseup",l,!0)})}_buttonStyle(){return["background:none","border:none","color:rgba(255,255,255,0.6)","cursor:pointer","font-size:12px","padding:2px 4px","border-radius:3px","line-height:1"].join(";")}_doSearch(t){if(!this._host?.root)return;const e=t.trim();if(!e)return this._engine.clear(),this._clearHighlight(),this._updateStatus(),void this._hideResultList();this._engine.search(this._host.root,e),this._updateStatus(),this._renderResultList()}_addToHistory(t){const e=t.trim();if(!e)return;const n=this._queryHistory.indexOf(e);n>=0&&this._queryHistory.splice(n,1),this._queryHistory.unshift(e),this._queryHistory.length>Eu.MAX_HISTORY&&this._queryHistory.pop()}_navigateHistory(t){if(0===this._queryHistory.length)return;if(!this._input)return;-1===this._historyIndex&&-1===t&&(this._savedInput=this._input.value);const e=this._historyIndex+(-1===t?1:-1);e<-1||e>=this._queryHistory.length||(this._historyIndex=e,-1===this._historyIndex?this._input.value=this._savedInput:this._input.value=this._queryHistory[this._historyIndex],this._debounceTimer&&clearTimeout(this._debounceTimer),this._doSearch(this._input.value))}_isHistoryMode(){return this._historyIndex>=0}_submitQuery(){const t=(this._input?.value||"").trim();if(!t)return!1;if(this._isEditMode()){if(this._engine.resultCount>0){const t=this._engine.currentIndex>=0?this._engine.currentIndex:0;this._selectResult(t)}return!0}const e={query:t,results:this._engine.results.slice()};return this._host?.root?.trigger?.("query-submit",e),this._invokeViewSubmit(e),this._addToHistory(t),!0}_invokeViewSubmit(t){const e=this._host;if(e){if("function"==typeof e.onSearchSubmit){if(!0===e.onSearchSubmit(t,e))return}e.tracker?.start?.(t.query,e.trackerOptions)}}_invokeViewClose(){const t=this._host;if(t){if("function"==typeof t.onSearchClose){if(!0===t.onSearchClose(t))return}t.tracker?.stop?.()}}_focusResult(t){if(t<0||t>=this._engine.resultCount)return;if(t>=50)return;this._engine.navigateTo(t),this._updateStatus(),this._updateResultListSelection();const e=this._resultListEl?.querySelector(`[data-index="${t}"]`);e?.focus()}_isEditMode(){return!!this._host?.root?.app?.isEditMode}_selectResult(t){if(!this._host)return;if(0===this._engine.resultCount)return;if(t<0||t>=this._engine.resultCount)return;this._engine.navigateTo(t);const e=this._engine.currentResult;if(!e)return;this._addToHistory(this._input?.value||"");const n=e.component.state?.id;if(n&&this._input&&(this._input.value=String(n),this._doSearch(this._input.value)),this._isEditMode()){this._host.setSelected([e.component]),this._host.centerTo(e.component,!0);const t=this._engine.results.map(t=>t.component);this._host.highlightSearchResults?.(t),this._host.invalidate?.()}else{const t={query:e.component.state?.id||"",results:this._engine.results.slice(),selected:e.component};this._host.root?.trigger?.("query-submit",t),this._invokeViewSubmit(t)}this._updateStatus(),this._updateResultListSelection()}_clearHighlight(){this._host?.highlightSearchResults?.([]),this._host?.invalidate?.()}_updateStatus(){if(!this._statusEl)return;const t=this._engine.resultCount,e=this._engine.currentIndex;0===t&&this._input?.value?.trim()?(this._statusEl.textContent="No results",this._statusEl.style.color="rgba(255,120,120,0.8)"):t>0?(this._statusEl.textContent=`${e+1}/${t}`,this._statusEl.style.color="rgba(255,255,255,0.5)"):this._statusEl.textContent=""}_renderResultList(){if(!this._resultListEl)return;const t=this._engine.results;if(this._resultListEl.innerHTML="",0===t.length)return void(this._resultListEl.style.display="none");const e=t.slice(0,50);for(let t=0;t<e.length;t++){const n=e[t],i=document.createElement("div");i.dataset.index=String(t),i.tabIndex=-1,i.style.cssText=["padding:4px 10px","cursor:pointer","display:flex","align-items:center","gap:6px","font-size:12px","border-bottom:1px solid rgba(255,255,255,0.04)","transition:background 0.1s","outline:none"].join(";"),i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{this._engine.currentIndex!==t?i.style.background="none":i.style.background="rgba(74,158,255,0.15)"}),i.addEventListener("click",()=>{this._selectResult(t)}),i.addEventListener("keydown",e=>{e.stopPropagation(),"ArrowDown"===e.key?(this._focusResult(t+1),e.preventDefault()):"ArrowUp"===e.key?(0===t?(this._input?.focus(),this._input?.select()):this._focusResult(t-1),e.preventDefault()):"Enter"===e.key?(this._selectResult(t),e.preventDefault()):"Escape"===e.key?(this.hide(),this._host?.element?.focus(),e.preventDefault()):e.shiftKey&&"Tab"===e.key?(this._input?.focus(),e.preventDefault()):1!==e.key.length||e.metaKey||e.ctrlKey||e.altKey||this._input?.focus()});const s=document.createElement("span");s.textContent=Au[n.matchType]||n.matchType,s.style.cssText=["font-size:9px","padding:1px 4px","border-radius:3px","background:rgba(74,158,255,0.2)","color:rgba(74,158,255,0.9)","flex-shrink:0","text-transform:uppercase","letter-spacing:0.5px"].join(";"),i.appendChild(s);const r=document.createElement("span");r.textContent=n.component.state.type||"?",r.style.cssText="color:rgba(255,255,255,0.7);flex-shrink:0",i.appendChild(r);const o=document.createElement("span");if(o.textContent=this._truncate(n.matchValue,30),o.style.cssText="color:rgba(255,200,100,0.8);overflow:hidden;text-overflow:ellipsis;white-space:nowrap",i.appendChild(o),"id"!==n.matchType&&n.component.state.id){const t=document.createElement("span");t.textContent=`#${n.component.state.id}`,t.style.cssText="color:rgba(255,255,255,0.3);font-size:11px;margin-left:auto;flex-shrink:0",i.appendChild(t)}this._resultListEl.appendChild(i)}if(t.length>50){const e=document.createElement("div");e.style.cssText="padding:4px 10px;font-size:11px;color:rgba(255,255,255,0.3);text-align:center",e.textContent=`... and ${t.length-50} more`,this._resultListEl.appendChild(e)}this._resultListEl.style.display="block",this._updateResultListSelection()}_updateResultListSelection(){if(!this._resultListEl)return;const t=this._engine.currentIndex;for(const e of Array.from(this._resultListEl.children)){const n=e,i=parseInt(n.dataset.index||"-1",10);n.style.background=i===t?"rgba(74,158,255,0.15)":"none"}const e=this._resultListEl.querySelector(`[data-index="${t}"]`);e?.scrollIntoView({block:"nearest"})}_hideResultList(){this._resultListEl&&(this._resultListEl.style.display="none",this._resultListEl.innerHTML="")}_truncate(t,e){return t.length>e?t.slice(0,e)+"...":t}}Eu.MAX_HISTORY=20;const Cu={color:"#00aaff7f",intervalMs:1e3};class Tu{constructor(t){this._id=null,this._target=null,this._fallback=null,this._lastCheckMs=0,this._options=Cu,this._scene=t}get trackingId(){return this._id}start(t,e){t&&(this._id&&this.stop(),this._id=String(t),this._options={...Cu,...e},this._setOutlineColorFromHex(this._options.color),this._tickOnce(!0),this._lastCheckMs=0,this._unsubscribe=jr.subscribe(()=>{const t=Date.now();t-this._lastCheckMs<this._options.intervalMs||(this._lastCheckMs=t,this._tickOnce(!1))},{description:`tracker#${this._id}`,component:this._scene?.root}))}stop(){this._clearTarget(),this._clearFallback(),this._id=null,this._unsubscribe&&(this._unsubscribe(),this._unsubscribe=void 0),this._lastCheckMs=0,this._setOutlineColor(15885602)}dispose(){this.stop()}_tickOnce(t){if(!this._id)return;const e=this._findTarget();if(e)return this._fallback&&this._fallback!==e&&this._clearFallback(),this._target=e,e.trigger("deco-border",this._decoOptions(this._options.color)),void(t&&this._scene.centerTo?.(e,!0));this._clearTarget();const n=this._options.fallback?.(this._id,this._scene)??null;n&&n!==this._fallback?(this._clearFallback(),this._fallback=n,n.trigger("deco-border",this._decoOptions(this._options.fallbackColor||this._options.color))):n?n.trigger("deco-border",this._decoOptions(this._options.fallbackColor||this._options.color)):this._clearFallback()}_findTarget(){const t=this._scene.findAll?.(`#${this._id}`);return t?.[0]??null}_clearTarget(){this._target&&(this._target.trigger?.("deco-border-off"),this._target=null)}_clearFallback(){this._fallback&&(this._fallback.trigger?.("deco-border-off"),this._fallback=null)}_decoOptions(t){return{distance:8,lineWidth:4,color:t}}_setOutlineColorFromHex(t){const e=(t||"").replace("#","").slice(0,6);/^[0-9a-fA-F]{6}$/.test(e)&&this._setOutlineColor(parseInt(e,16))}_setOutlineColor(t){const e=this._scene?.root;e?.model_layer?.setOutlineColor?.(t)}}let Pu=null;const Ou=[],Du=new Set;function zu(t){if(!t)return;const e=t?.state?.id??t?.id??t?.refid;return void 0!==e?String(e):void 0}const Iu={beginContext(t){Pu=t},endContext(){Pu=null},current:()=>Pu,log(t){const e={role:t.role,contract:t.contract,componentId:t.componentId??zu(t.component),componentType:t.componentType??(n=t.component,n?.state?.type??n?.type),atSimMs:Ir.now,args:t.args,result:t.result,error:t.error};var n;Pu?Pu.pushTrace(e):(Ou.push(e),Ou.length>500&&Ou.shift(),Du.forEach(t=>{try{t(e)}catch{}}))},standaloneEvents:()=>[...Ou],onStandalone:t=>(Du.add(t),()=>{Du.delete(t)}),clearStandalone(){Ou.length=0}};function Ru(t){if(!t)return;const e=t?.state?.refid??t?.refid;if(null==e)return;const n=String(e);return n.length>0?n:void 0}function ju(t){const e={transferId:t.transferId,phase:t.phase,timeline:{...t.timeline}},n=t.sourceId??Ru(t.source),i=t.targetId??Ru(t.target),s=t.carrierId??Ru(t.carrier);return void 0!==n&&(e.sourceId=n),void 0!==i&&(e.targetId=i),void 0!==s&&(e.carrierId=s),void 0!==t.slotId&&(e.slotId=t.slotId),void 0!==t.rejectReason&&(e.rejectReason=t.rejectReason),e}let Lu=1;class Fu{constructor(t){this._phase="pending",this._slot=null,this._reservation=null,this._traceEvents=[],this.meta={},this.id="xfer-"+Lu++,this.source=t.source,this.target=t.target,this.carrier=t.carrier,this.options=t.options??{},this.physical=t.physical??null,this._timeline={initiatedAt:Ir.now}}pushTrace(t){this._traceEvents.push({atSimMs:t.atSimMs??Ir.now,...t})}get phase(){return this._phase}get timeline(){return this._timeline}_rollback(){this._phase="rolled-back";const t=this._buildReceipt();return Nu.append(t),t}_planAndReserve(){this._phase="planning",this._timeline.planStartAt=Ir.now;const t=this.target.canAccept?.(this.carrier);if(t&&t.ok)this._slot=t.slot;else{if(t&&!t.ok&&"no-slots-defined"!==t.reason)return this._rejectReason=t.reason,this._rollback();if(t||"function"!=typeof this.target.canReceive)this._slot=null;else{if(!this.target.canReceive(this.carrier))return this._rejectReason="cannot-receive",this._rollback();this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}}return null===this._slot||"function"!=typeof this.target.reserve||"function"!=typeof this.target.commit||(this._reservation=this.target.reserve(this.carrier,{source:this.source}),this._reservation)?(this._timeline.planEndAt=Ir.now,null):(this._rejectReason="cannot-reserve",this._rollback())}_physicalFailed(t){return this._reservation&&this.target.release?.(this._reservation),this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._rollback()}_handoffFailed(t){throw this._rejectReason=`handoff-failed: ${t.message??"unknown"}`,this._phase="rolled-back",Nu.append(this._buildReceipt()),t}_commitReserved(){if(this._reservation&&"function"==typeof this.target.commit){try{this.target.commit(this._reservation,this.carrier,this.options)}catch(t){this.target.release?.(this._reservation),this._handoffFailed(t)}return!0}return!1}_finishCommitted(){this._phase="committed",this._timeline.committedAt=Ir.now;const t=this._buildReceipt();return Nu.append(t),t}_runPhysicalSync(){if(!this.physical)return null;this._phase="physical",this._timeline.physicalStartAt=Ir.now;try{const t=this.physical();t instanceof Promise&&t.catch(()=>{})}catch(t){return this._physicalFailed(t)}return this._timeline.physicalEndAt=Ir.now,null}async _runPhysicalAsync(){if(!this.physical)return null;this._phase="physical",this._timeline.physicalStartAt=Ir.now;try{await this.physical()}catch(t){return this._physicalFailed(t)}return this._timeline.physicalEndAt=Ir.now,null}_runReceiveSync(){const t=this.target.accept??this.target.receive;if("function"==typeof t)try{const e=t.call(this.target,this.carrier,this.options);e instanceof Promise&&e.catch(()=>{})}catch(t){this._handoffFailed(t)}else Iu.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method"}})}async _runReceiveAsync(){const t=this.target.accept??this.target.receive;if("function"==typeof t)try{await t.call(this.target,this.carrier,this.options)}catch(t){this._handoffFailed(t)}else Iu.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method"}})}async execute(){Iu.beginContext(this),Iu.log({role:"transfer",contract:"execute:begin",args:{transferId:this.id,source:Ru(this.source),target:Ru(this.target),carrier:Ru(this.carrier)}});try{return await this._executeImpl()}finally{Iu.log({role:"transfer",contract:"execute:end",args:{transferId:this.id,phase:this._phase}}),Iu.endContext()}}executeSync(){Iu.beginContext(this),Iu.log({role:"transfer",contract:"executeSync:begin",args:{transferId:this.id,source:Ru(this.source),target:Ru(this.target),carrier:Ru(this.carrier)}});try{const t=this._planAndReserve();if(t)return t;const e=this._runPhysicalSync();return e||(this._phase="handoff",this._timeline.handoffAt=Ir.now,this._commitReserved()||this._runReceiveSync(),this._finishCommitted())}finally{Iu.log({role:"transfer",contract:"executeSync:end",args:{transferId:this.id,phase:this._phase}}),Iu.endContext()}}async _executeImpl(){const t=this._planAndReserve();if(t)return t;const e=await this._runPhysicalAsync();return e||(this._phase="handoff",this._timeline.handoffAt=Ir.now,this._commitReserved()||await this._runReceiveAsync(),this._finishCommitted())}rollback(){if("committed"===this._phase)throw new Error("Cannot rollback a committed transfer");this._rejectReason=this._rejectReason??"manual-rollback",this._phase="rolled-back",Nu.append(this._buildReceipt())}_buildReceipt(){return{transferId:this.id,source:this.source,target:this.target,carrier:this.carrier,sourceId:Ru(this.source),targetId:Ru(this.target),carrierId:Ru(this.carrier),phase:this._phase,timeline:{...this._timeline},slotId:this._slot?.id,rejectReason:this._rejectReason,traceEvents:[...this._traceEvents],meta:Object.keys(this.meta).length>0?{...this.meta}:void 0}}}const Nu=new class{constructor(){this._flows=new Map,this._targetCount=new Map,this._byPhase=new Map,this._byRejectReason=new Map,this._total=0,this._committedDurationSum=0,this._committedCount=0,this._listeners=new Set}append(t){this._total++,this._byPhase.set(t.phase,(this._byPhase.get(t.phase)??0)+1);const e=t.sourceId??Ru(t.source),n=t.targetId??Ru(t.target);if("committed"===t.phase){if(e&&n){const t=e+">"+n;this._flows.set(t,(this._flows.get(t)??0)+1)}n&&this._targetCount.set(n,(this._targetCount.get(n)??0)+1),void 0!==t.timeline.committedAt&&(this._committedDurationSum+=t.timeline.committedAt-t.timeline.initiatedAt,this._committedCount++)}else if("rolled-back"===t.phase&&t.rejectReason){this._byRejectReason.set(t.rejectReason,(this._byRejectReason.get(t.rejectReason)??0)+1);try{t.source?._bumpRejected?.(t.carrier,t.rejectReason)}catch{}}this._listeners.forEach(e=>e(t))}flows(){return this._flows}targetCounts(){return this._targetCount}stats(){const t={};this._byPhase.forEach((e,n)=>{t[n]=e});const e=t["rolled-back"]??0;return{total:this._total,byPhase:t,committed:t.committed??0,rolledBack:e,rejectionRate:this._total>0?e/this._total:0,avgTransferDurationMs:this._committedCount>0?this._committedDurationSum/this._committedCount:0}}rejectReasonCounts(){return this._byRejectReason}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}clear(){this._flows.clear(),this._targetCount.clear(),this._byPhase.clear(),this._byRejectReason.clear(),this._total=0,this._committedDurationSum=0,this._committedCount=0}entries(){return[]}forCarrier(t){return[]}forCarrierId(t){return[]}forSourceId(t){return[]}forTargetId(t){return[]}forPhase(t){return[]}inTimeRange(t,e,n){return[]}groupByRejectReason(){return new Map}toJSON(){return[]}fromJSON(t){}replayTo(t){}setMaxEntries(t){}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_TRANSFER_LOG__=Nu);let Hu=0;const Bu=new FinalizationRegistry(t=>{Hu--});class Gu{static get residents(){return Hu}static get residentsCount(){return Hu}constructor(t){this._searchOverlay=new Eu,this._loadingOverlay=new Cd,this._container=t,this.app=t.app,this._commander=new mh(this._container),this.app.commander=this._commander,Hu++,Bu.register(this,Hu),Ed.register(this),this._container.target_element&&this._setupSearchOverlay()}add(t,e,n){return Oh.call(this._container,t,e,n)}duplicate(){return Dh.call(this._container)}remove(){return zh.call(this._container)}animate(t){return ka.call(this,t)}fullscreen(t){return Nh.call(this._container,t)}get target(){return this._container.target_element}set target(t){let e;if("string"==typeof t){if(e=document.getElementById(t),!e)throw new Error(`target element '${t}' does not exist`);if(e.firstChild)throw new Error(`target element '${t}' already has children`)}else e=t;e&&e.style&&(e.style.cursor="default"),this._container.target_element=e,this._setupSearchOverlay(),this._container.invalidate()}get scale(){return this.root.get("scale")}set scale(t){this.root.set("scale",t)}get translate(){return this.root.get("translate")}set translate(t){this.root.set("translate",t)}get unit(){return this.root.get("unit")||"px"}get PPM(){return this.app.PPM}get PPI(){return this.app.PPI}get DPPX(){return this.app.DPPX}static get DPPX(){return Xs}get unitScale(){return this._container.unitScale}get screen(){return this.app.screen}set screen(t){this.app.screen=t,this._container.resize()}resize(){this._container.resize()}release(){this.dispose()}dispose(){this._loadingOverlay.destroy(),this._searchOverlay.destroy(),this._tracker?.dispose(),Ed.unregister(this),this._commander&&this._commander.dispose(),this._container&&this._container.dispose(),vu.flushCache(),Nu.clear()}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 Gh.call(this._container)}copy(){return Bh.call(this._container)}paste(t){return Vh.call(this._container,t)}undoableChange(t){return ad.call(this._container,t)}change(t,e,n){return od.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 kh.call(this._container,t)}place(t){return md.call(this._container,t)}distribute(t){return Ch.call(this._container,t)}move(t,e,n){return Th.call(this._container,t,e,n)}zorder(t){return Ph.call(this._container,t)}symmetryX(){return sd.call(this._container)}symmetryY(){return rd.call(this._container)}on(t,e,n){return jh.call(this._container,t,e,n)}once(t,e,n){return Lh.call(this._container,t,e,n)}off(t,e,n){return this._container&&Fh.call(this._container,t,e,n)}centerTo(t,e){const n=this.root?.rootModel?.is3dMode;if(!this.app?.isViewMode||n)return this.root.centerTo(t,e)}get tracker(){return this._tracker||(this._tracker=new Tu(this)),this._tracker}get mode(){return this.app.mode}set mode(t){void 0!==t&&(this.app.mode=t)}get threedEnabled(){return wu()}get isSelecting(){return!!this.app?.isSelecting}get focusFilter(){return this.app?.focusFilter}set focusFilter(t){this.app&&(this.app.focusFilter=t),this._reapplyModelingFaint(),this._container?.invalidate()}_reapplyModelingFaint(){const t=e=>{e?._realObject?.applyFocusDim?.(),e?.applyElementModelingFaint?.(),(e?.components||[]).forEach(t),(e?.items||[]).forEach?.(t)};t(this._container)}toDataURL(t,e,n,i){return Jh.call(this._container,t,e,n,i)}group(){return td.call(this._container)}ungroup(){return ed.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 cd.call(this._container)}get data(){return this._container.data}set data(t){this._container.data=t}get dataByRefid(){return this._container.dataByRefid}set dataByRefid(t){this._container.dataByRefid=t}get values(){return this._container.values}set values(t){this._container.values=t}get valuesByRefid(){return this._container.valuesByRefid}set valuesByRefid(t){this._container.valuesByRefid=t}get baseUrl(){return this.app.baseUrl}set baseUrl(t){this.app.baseUrl=t}get suppressAnimations(){return this.app.suppressAnimations}set suppressAnimations(t){this.app.suppressAnimations=t}withSuppressedAnimations(t){return this.app.withSuppressedAnimations(t)}beginSuppressAnimations(){return this.app.beginSuppressAnimations()}startAddMode(t){return gd.call(this._container,t)}startBulkCreateMode(t,e){return yd.call(this._container,t,e)}startStylePasteMode(){return bd.call(this._container)}stopStylePasteMode(){return _d.call(this._container)}startDatabindPasteMode(){return vd.call(this._container)}stopDatabindPasteMode(){return xd.call(this._container)}get loading(){return this.app.loadTracker}get loadingOverlay(){return this._loadingOverlay}showLoadingOverlay(){this._loadingOverlay.show()}hideLoadingOverlay(){this._loadingOverlay.hide()}toggleLoadingOverlay(){if(!this._loadingOverlay.isAttached){const t=this._container.target_element;t&&this._loadingOverlay.attach(t,this.app.loadTracker,this.app.lagTracker)}this._loadingOverlay.toggle()}get searchOverlay(){return this._searchOverlay}_setupSearchOverlay(){const t=this;this._searchOverlay.setup({get root(){return t.root},get element(){return t.target},centerTo(e,n){t.centerTo(e,n)},setSelected(e){t.selected=e},invalidate(){t._container?.invalidate()},get tracker(){return t.tracker},get trackerOptions(){return t.trackerOptions},get onSearchSubmit(){return t.onSearchSubmit},get onSearchClose(){return t.onSearchClose}});const e=this._container.model_layer;e&&(e.onSearchToggle=()=>this._searchOverlay.toggle(),e.onDataBindingToggle=()=>this.onDataBindingToggle?.(),e.onMonitorToggle=()=>this.toggleLoadingOverlay())}}const Vu=new class{async load(t){}async save(t,e){}async clear(t){}};function Yu({target:t,model:e,style:n,layers:i=[],handlers:s=[],mode:r=0,refProvider:o,dataSubscriptionProvider:a,dataStorage:c=Vu,baseUrl:l,fitMode:h,postprocessing:d=!0,logarithmicDepth:u,loading:p}){let f=null;if("string"==typeof t){if(f=document.getElementById(t),!f)throw new Error(`target element '${t}' does not exist`);if(f.firstChild)throw new Error(`target element '${t}' is not empty`)}else f=t??null;f&&f.style&&(f.style.position="absolute",f.style.cursor="default",f.style.overflow="hidden");const m=new lh(r,o);return l&&(m.baseUrl=l),m.postprocessing=d,m.logarithmicDepth=u,m.dataSubscriptionProvider=a,m.dataStorage=c,p?.tracker?m.adoptLoadTracker(p.tracker):m.initLoadTracker(p||{}),m.loadTracker?.setPhase("init"),new Gu(new th({target_element:f,model:e,style:n,layers:i,handlers:s,fitMode:h},m))}const Wu=20;function Uu(t,e="static",n,i,s,r,o={}){const{title:a="",gap:c=Wu}=o;if("auto"===n){const{x:e,y:n}=function(t,e,n,i="",s=Wu){const r=Math.max(e.width/4-n.width/2,s),o=Math.min(3*e.width/4+n.width/2,e.width-s)-n.width,a=Math.max(e.height/4-n.height/2,s),c=Math.min(3*e.height/4+n.height/2,e.height-s)-n.height+(i?-30:0);return{x:t.x<e.width/2?Math.min(o,t.x+20):Math.max(r,t.x-(n.width+20)),y:t.y<e.height/2?Math.min(c,t.y+20+(i?30:0)):Math.max(a,t.y-(n.height+20))}}(i,s,r,a,c);Object.assign(t.style,{position:"absolute",left:`${e}px`,top:`${n}px`})}else"static"===e?function(t,e,n,i,s){const r=t.style,o=e.includes("left")?s:e.includes("right")?n.width-i.width-s:n.width/2-i.width/2,a=e.includes("top")?s:e.includes("bottom")?n.height-i.height-s:n.height/2-i.height/2;Object.assign(r,{left:`${o}px`,top:`${a}px`})}(t,n,s,r,c):function(t,e,n=Wu){const i=t.style;switch(Object.assign(i,{position:"absolute",left:"",right:"",top:"",bottom:"",transform:""}),e){case"center-middle":default:Object.assign(i,{left:"50%",top:"50%",transform:"translate(-50%, -50%)"});break;case"center-top":Object.assign(i,{left:"50%",top:`${n}px`,transform:"translateX(-50%)"});break;case"center-bottom":Object.assign(i,{left:"50%",bottom:`${n}px`,transform:"translateX(-50%)"});break;case"left-middle":Object.assign(i,{left:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"right-middle":Object.assign(i,{right:`${n}px`,top:"50%",transform:"translateY(-50%)"});break;case"left-top":Object.assign(i,{left:`${n}px`,top:`${n}px`});break;case"right-top":Object.assign(i,{right:`${n}px`,top:`${n}px`});break;case"left-bottom":Object.assign(i,{left:`${n}px`,bottom:`${n}px`});break;case"right-bottom":Object.assign(i,{right:`${n}px`,bottom:`${n}px`})}}(t,n,c)}function $u(t,e,n={sx:1,sy:1},i={}){const{signal:s}=i;let r,o,a=0,c=0,l=!1;const h=/translate\(([-\d.]+)px,\s*([-\d.]+)px\)/;function d(){const e=(t.style.transform||"").match(h);return{x:e?parseFloat(e[1]):0,y:e?parseFloat(e[2]):0}}function u(t,e){l=!0;const n=d();a=n.x,c=n.y,r=t,o=e}function p(e,i){if(!l)return;const s=e-r,h=i-o,{sx:d,sy:u}=n;!function(e,n){t.style.transform=`translate(${e}px, ${n}px)`}(a+s/d,c+h/u)}function f(){const t=d();a=t.x,c=t.y,l=!1}function m(t){if(!s)return t.signal;const e=AbortSignal.any;return e?e([t.signal,s]):(s.aborted?t.abort():s.addEventListener("abort",()=>t.abort(),{once:!0}),t.signal)}e?.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),u(t.clientX,t.clientY);const e=new AbortController,n=m(e);window.addEventListener("mousemove",t=>{t.preventDefault(),p(t.clientX,t.clientY)},{capture:!0,signal:n}),window.addEventListener("mouseup",t=>{t.preventDefault(),f(),e.abort()},{capture:!0,signal:n})},{signal:s}),e?.addEventListener("touchstart",t=>{if(1!==t.touches.length)return;t.preventDefault(),t.stopPropagation(),u(t.touches[0].clientX,t.touches[0].clientY);const e=new AbortController,n=m(e);window.addEventListener("touchmove",t=>{1===t.touches.length&&(t.preventDefault(),p(t.touches[0].clientX,t.touches[0].clientY))},{capture:!0,signal:n});const i=()=>{f(),e.abort()};window.addEventListener("touchend",i,{capture:!0,signal:n}),window.addEventListener("touchcancel",i,{capture:!0,signal:n})},{signal:s})}function Xu(t,n,i){const s=t.rootModel;if(s?.is3dMode){const n=t._realObject?.object3d,i=s.activeCamera3d,r=s.renderer3d;if(n&&i&&r){const t=new e.Vector3;n.getWorldPosition(t);const s=t.clone().project(i),o=r.domElement;return{x:(.5*s.x+.5)*o.clientWidth,y:(.5*-s.y+.5)*o.clientHeight}}return null}const r=t.toGlobal(n,i,s);return isNaN(r.x)||isNaN(r.y)?null:r}const qu=new e.Box3,Ku=new e.Vector3;function Qu(t,n="top",i={},s=new e.Vector3){const r=t._realObject;return r?.object3d?(r.object3d.updateWorldMatrix(!0,!0),"center"===n?s.setFromMatrixPosition(r.object3d.matrixWorld):(qu.setFromObject(r.object3d),qu.isEmpty()?s.setFromMatrixPosition(r.object3d.matrixWorld):(qu.getCenter(Ku),"bottom"===n?s.set(Ku.x,qu.min.y,Ku.z):s.set(Ku.x,qu.max.y,Ku.z))),s.x+=i.x??0,s.y+=i.y??0,s.z+=i.z??0,Number.isFinite(s.x)&&Number.isFinite(s.y)&&Number.isFinite(s.z)?s:null):null}function Zu(t){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("style","position:absolute; left:0; top:0; width:100%; height:100%; pointer-events:none; overflow:visible; opacity:0; transition: opacity 200ms ease;"),e.dataset.role="tether";const n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttribute("r","8"),n.setAttribute("opacity","0"),e.appendChild(n);const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("fill","none"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),e.appendChild(i);const s=document.createElementNS("http://www.w3.org/2000/svg","circle");return s.setAttribute("r","3.5"),s.setAttribute("opacity","0"),e.appendChild(s),t.appendChild(e),{svg:e,path:i,halo:n,dot:s}}function Ju(t,e,n,i,s,r,o,a,c,l,h){const{svg:d,path:u,halo:p,dot:f}=t;d.setAttribute("width",String(l)),d.setAttribute("height",String(h)),d.setAttribute("viewBox",`0 0 ${l} ${h}`);const m=function(t,e,n,i,s,r){const o=n+s/2,a=i+r/2,c=t-o,l=e-a;if(Math.abs(c)*r>Math.abs(l)*s)return{x:c>0?n+s:n,y:a};return{x:o,y:l>0?i+r:i}}(e,n,i,s,r,o),g=m.x-e,y=m.y-n,b=(e+m.x)/2,_=(n+m.y)/2,v=Math.sqrt(g*g+y*y),x=v>0?-y/v:0,w=v>0?g/v:0,M=Math.min(18,.12*v),S=b+x*M,k=_+w*M;u.setAttribute("d",`M ${e} ${n} Q ${S} ${k} ${m.x} ${m.y}`),u.setAttribute("stroke",a),u.setAttribute("opacity",String(c)),p.setAttribute("cx",String(e)),p.setAttribute("cy",String(n)),p.setAttribute("fill",a),p.setAttribute("opacity",String(.25*c)),f.setAttribute("cx",String(e)),f.setAttribute("cy",String(n)),f.setAttribute("fill",a),f.setAttribute("opacity",String(c))}function tp(t){t.path.setAttribute("d",""),t.halo.setAttribute("opacity","0"),t.dot.setAttribute("opacity","0")}function ep(t){t.svg.parentNode?.removeChild(t.svg)}const np=["run","goto","goto-playlist","link-open","link-move","route-page","start-scenario","run-scenario","export-data","import-data"];function ip(t,e){const n=document.createElement("button");return n.className=t,n.textContent=e,n}function sp(t){const{component:e,anchor:n,anchorPin:i,anchorOffset:s,popupRoot:r,popupSize:o,constantSize:a,billboard:c,tetherEnabled:l,offScreen:h,signal:d,popupEntry:u}=t,p=e.rootModel??e.root;if(!p?.on)return;if(!a)return void function(t){const{component:e,anchor:n,anchorPin:i,anchorOffset:s,popupRoot:r,billboard:o,tetherEnabled:a,signal:c,popupEntry:l}=t,h=e.rootModel??e.root,d=h?._threeCapability,u=d?.rendererManager?.css3DScene;if(!u)return void Zi("perspective popup requires 3D mode active (css3DScene unavailable)");r.style.position="absolute";const p=o?new _(r):new v(r);u.add(p),r.dataset.perspectiveCss3d="true";const f=()=>ap.hide(e);n.on?.("removed",f);const m=h.target??null;let g;a&&m&&(g=Zu(m),l&&(l.tether=g));const y=()=>{const t=Qu(n,i,s);if(t){if(p.position.set(t.x,t.y,t.z),g&&m){const t=Xu(n,0,0),e=m.getBoundingClientRect(),i=r.getBoundingClientRect();if(t&&e.width>0&&e.height>0&&i.width>0){const n=i.left-e.left,s=i.top-e.top,r=o;Ju(g,t.x,t.y,r?n:n+i.width/2,r?s:s+i.height/2,r?i.width:0,r?i.height:0,"rgba(80, 120, 200, 0.7)",1,e.width,e.height)}}}else g&&tp(g)},b=()=>y();h.on("redraw",b),y(),h.invalidate?.(),c.addEventListener("abort",()=>{h.off?.("redraw",b),n.off?.("removed",f),u.remove(p),r.parentNode&&r.parentNode.removeChild(r),g&&ep(g)})}({component:e,anchor:n,anchorPin:i,anchorOffset:s,popupRoot:r,billboard:c,tetherEnabled:l,signal:d,popupEntry:u});Object.assign(r.style,{position:"absolute",pointerEvents:"auto"});const f=r.parentElement;let m;l&&f&&(m=Zu(f),u&&(u.tether=m));const g=()=>ap.hide(e);n.on?.("removed",g);const y=()=>{if(!Qu(n,i,s))return void("hide"===h&&(r.style.opacity="0",m&&tp(m)));const t=Xu(n,0,0);if(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y))return void("hide"===h&&(r.style.opacity="0",m&&tp(m)));const e=f?.getBoundingClientRect(),a=e?.width??0,c=e?.height??0,l=t.x<0||t.x>a||t.y<0||t.y>c;if(l&&"hide"===h)return r.style.opacity="0",void(m&&tp(m));if(l&&"keep-last"===h)return;let{x:d,y:u}=t;l&&"edge-pin"===h&&(d=Math.max(0,Math.min(a,d)),u=Math.max(0,Math.min(c,u)));const p=d+24,g=u-24-o.height,y=Math.max(8,Math.min(p,a-o.width-8)),b=Math.max(8,Math.min(g,c-o.height-8));r.style.opacity="1",r.style.left=`${y}px`,r.style.top=`${b}px`,m&&Ju(m,d,u,y,b,o.width,o.height,"rgba(80, 120, 200, 0.7)",1,a,c)},b=()=>y();p.on("redraw",b),y(),p.invalidate?.(),d.addEventListener("abort",()=>{p.off?.("redraw",b),n.off?.("removed",g),m&&ep(m)})}const rp=new WeakMap;function op(t){const e=t.root,n=rp.get(e);if(!n)return;if(e===t)return n.forEach(t=>op(t[0])),void rp.delete(e);const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const s=n[i][1];cancelAnimationFrame(s.rafId),s.ac.abort(),s.div.parentNode?.removeChild(s.div),s.scene.target=null,s.scene.release?.(),n.splice(i,1)}class ap{static hideAll(t){(rp.get(t)||[]).forEach(([t])=>op(t))}static hide(t){const e=t.root,n=rp.get(e);if(!n)return;const i=n.findIndex(e=>e[0]===t);if(-1===i)return;const s=n[i][1],r=()=>{s.div.style.backgroundColor="transparent",s.rafId=function(t,e,n){const i="true"===t.dataset.perspectiveCss3d;t.style.opacity="1";const s=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();i||(t.style.transform=`${s} scale(1)`);let r=0;const o=Date.now(),a=()=>{if(n?.aborted)return;const c=Math.min((Date.now()-o)/200,1);t.style.opacity=String(1-c),i||(t.style.transform=`${s} scale(${1-c})`.trim()),c<1?r=requestAnimationFrame(a):(t.style.display="none",e&&e())};return r=requestAnimationFrame(a),r}(s.div,()=>{op(t)},s.ac.signal)};s.tether?(s.tether.svg.style.opacity="0",setTimeout(r,200)):r()}static show(t,e,n={}){const{data:i,modal:s=!1,closable:r=!0,minimizable:o=!1,draggable:a=!1,output:c=!0,popupPosition:l="static",origin:h="center-middle",title:d="",threed:u=!1,anchor:p,anchorPin:f="top",anchorOffsetX:m=0,anchorOffsetY:g=0,anchorOffsetZ:y=0,constantSize:b=!0,billboard:_=!0,tether:v=!1,offScreen:x="hide"}=n,w=t.app?.refProvider,M=!!p&&!s&&!a,S=!!t.rootModel?.is3dMode,k=M||S?"absolute":l,A=!k||"static"===k;let E;n.containerRef?E=function(t,e){const n=t.rootModel,i=n?.findById?.(e);if(!i)return Zi(`PopupContainer not found: ${e}`),Promise.reject(new Error(`PopupContainer not found: ${e}`));const s=ni(i.hierarchy);delete s.id,s.position="static",s.left=0,s.top=0;const{width:r=320,height:o=200}=i.bounds||{},a={width:r,height:o,components:[s]},c=t.app;return Promise.resolve(Yu({model:a,mode:0,refProvider:c?.refProvider,dataSubscriptionProvider:c?.dataSubscriptionProvider,dataStorage:c?.dataStorage,baseUrl:c?.baseUrl,fitMode:"both"}))}(t,n.containerRef):n.htmlTemplate?E=function(t){const e={width:320,height:200};let n=null;const i={root:{model:e,bounds:e},data:void 0,fit(){},on(){},off(){},release(){}};return Object.defineProperty(i,"target",{get:()=>n,set:e=>{n=e,e&&(e.innerHTML=t)},configurable:!0}),Promise.resolve(i)}(n.htmlTemplate):e&&(E=w?.create?w.create(e):w?.get(e,!0)),E?.then(e=>{const n=document.createElement("div");n.setAttribute("popup",""),"absolute"==k&&(n.style.zIndex="100");const w=n.style;if(s){const{width:e,height:n}=A?t.rootModel.bounds:t.rootModel.auxOverlay.getBoundingClientRect();Object.assign(w,{position:"absolute",zIndex:"100",left:0,top:0,width:A?`${e}px`:"100%",height:A?`${n}px`:"100%",overflow:"hidden",backgroundColor:"transparent"})}else Object.assign(w,{position:"absolute",display:"inline-block"});n.appendChild(function(t){const e=document.createDocumentFragment(),n=document.createElement("div");n.className="popup-wrap";const i=document.createElement("div");if(i.className="popup-translate",t){const t=document.createElement("div");t.className="popup-title-bar";const e=document.createElement("div");e.className="popup-title",t.appendChild(e);const n=document.createElement("div");n.className="popup-buttons-wrap",n.appendChild(ip("closable","close")),n.appendChild(ip("minimizable","minimize")),n.appendChild(ip("draggable","drag_pan")),t.appendChild(n),i.appendChild(t)}else{const t=document.createElement("div");t.className="popup-buttons-wrap float-right",t.appendChild(ip("closable","close")),t.appendChild(ip("minimizable","minimize")),t.appendChild(ip("draggable","drag_pan")),i.appendChild(t)}const s=document.createElement("div");return s.className="popup-content",i.appendChild(s),n.appendChild(i),e.appendChild(n),e}(!!d));const S=n.querySelector(".popup-content"),{width:E,height:C}=e.root.model;Object.assign(S.style,{width:`${E}px`,height:`${C}px`});const T=document.createElement("style");T.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 /* 배경을 강제하지 않는다 — 로딩된 보드의 자체 배경/투명도가 그대로 보이도록.\n * 보드가 transparent 일 때 popup 안의 round corner / 그림자 효과가 망가지지 않게.\n * 흰 배경이 필요하면 보드 root 의 fillStyle 로 설정하거나 (또는 popup-content\n * CSS 변수를 외부에서 override). */\n background-color: transparent;\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(T);const P=new AbortController,O=P.signal;np.forEach(n=>{const i=(...e)=>t.trigger(n,...e);e.on(n,i),O.addEventListener("abort",()=>e.off?.(n,i))});const D=n.querySelector(".draggable");[...qs,...Ks].forEach(t=>{S.addEventListener(t,t=>t.stopPropagation(),{signal:O})}),[...qs,...Ks].forEach(t=>{n.addEventListener(t,t=>t.stopPropagation(),{signal:O})}),s&&r&&n.addEventListener("click",e=>{e.target===n&&ap.hide(t)},{signal:O});const z=t.rootModel.getOverlay?.({...t,scalable:!k||"static"==k});z?.appendChild(n),function(t,e,n,i,s){const r=t.root;if(r===t)return;op(t);let o=rp.get(r)||[];o=[...o,[t,{div:e,scene:n,ac:i,rafId:s}]],rp.set(r,o)}(t,n,e,P,0);const I=rp.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 R=n.querySelector(".popup-translate");if(a&&($u(R,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),{signal:O}),d?D&&(D.style.display="block"):(R?.addEventListener("mouseenter",()=>{D&&(D.style.display="block")},{signal:O}),R?.addEventListener("mouseleave",()=>{D&&(D.style.display="none")},{signal:O}))),o){const t=n.querySelector(".minimizable");let e=!1;t.addEventListener("click",t=>{t.preventDefault(),e=!e;const i=n.querySelector(".popup-wrap");!function(t,e,n){const i=e.querySelector(".minimizable"),s=e.querySelector(".popup-translate");s&&(n?(i.textContent="crop_square",s.style.height="30px"):(i.textContent="minimize",s.style.height="100%"))}(0,s?i:n,e)},{signal:O}),d?t&&(t.style.display="block"):(R?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:O}),R?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:O}))}if(r){const t=n.querySelector(".closable");d?t&&(t.style.display="block"):(R?.addEventListener("mouseenter",()=>{t&&(t.style.display="block")},{signal:O}),R?.addEventListener("mouseleave",()=>{t&&(t.style.display="none")},{signal:O}))}n.querySelector(".closable")?.addEventListener("click",e=>{e.preventDefault(),ap.hide(t)},{signal:O}),n.addEventListener("close-scene",e=>{e.preventDefault(),e.stopPropagation(),ap.hide(t),c&&(t.data=e.detail)},{signal:O}),e.target=S,e.data=i||t.data,e.fit("both"),u&&(e.root.threed=!0);const{x:j,y:L}=t.center,F=t.toScene(j,L),N=s?n.querySelector(".popup-wrap"):n;M?sp({component:t,anchor:p,anchorPin:f,anchorOffset:{x:m,y:g,z:y},popupRoot:n,popupSize:{width:E,height:d?C+30:C},constantSize:b,billboard:_,tetherEnabled:v,offScreen:x,signal:O,popupEntry:I}):Uu(N,k,h,F,e.root.bounds,{width:E,height:C},{title:d}),s?Object.assign(N.style,{position:"absolute",pointerEvents:"none",width:`${E}px`,height:`${d?C+30:C}px`}):Object.assign(N.style,{pointerEvents:"none",width:`${E}px`,height:`${d?C+30:C}px`});const H=function(t,e,n){const i="true"===t.dataset.perspectiveCss3d;t.style.opacity="0";const s=(t.style.transform||"").replace(/scale\([^)]+\)/,"").trim();i||(t.style.transform=`${s} scale(0)`),t.style.display="block";let r=0;const o=Date.now(),a=()=>{if(n?.aborted)return;const c=Math.min((Date.now()-o)/200,1);t.style.opacity=String(c),i||(t.style.transform=`${s} scale(${c})`.trim()),c<1?r=requestAnimationFrame(a):e&&e()};return r=requestAnimationFrame(a),r}(n,()=>{s&&(n.style.backgroundColor="rgba(0,0,0,0.3)"),I?.tether&&(I.tether.svg.style.opacity="1")},O);I&&(I.rafId=H)},t=>{Zi("cannot fetch board: "+e,t)})}}th.onBeforeDispose(t=>ap.hideAll(t));class cp extends Kl{get showMoveHandle(){return!1}constructor(t,e){super(t,e),this._element=null,this._firstDrawReported=!1,t.translate=t.translate||{x:0,y:0},this._draw_reserved=!1,this.__draw__=()=>{if(this._draw_reserved=!1,Li.enabled){const t=performance.now();this.trigger("redraw"),this.reflow(),this.draw();const e=performance.now()-t;Li.drawCount++,Li.drawTimeSum+=e,Li.drawTimeLast=e,Li.countFrame()}else this.trigger("redraw"),this.reflow(),this.draw();this._firstDrawReported||(this._firstDrawReported=!0,this.app?.loadTracker?.markFirstRender())},this.throttle_render=()=>{this._draw_reserved||requestAnimationFrame(this.__draw__),this._draw_reserved=!0}}get element(){return this._element}set element(t){this._element=t}fitSize(t,e,n,i){if(this.target){if(e){const t=getComputedStyle(this.target);n=n||(t?parseFloat(t.getPropertyValue("width")):this.target.clientWidth),i=i||(t?parseFloat(t.getPropertyValue("height")):this.target.clientHeight)}else n=this.model.width,i=this.model.height;"CANVAS"==t.tagName&&(t.setAttribute("width",n*Xs),t.setAttribute("height",i*Xs)),t.style.width=n+"px",t.style.height=i+"px"}}resize(){this.fitSize(this.element,!0)}isLayer(){return!0}get showOverflow(){return this.app.isEditMode}get anchors(){}createElement(){const t=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:i}=this.model;t.clearRect(0,0,t.canvas.width,t.canvas.height),e&&t.translate(e.x*Xs,e.y*Xs),t.scale(n.x*Xs,n.y*Xs),i&&t.rotate(i)}get rotatePoint(){return{x:0,y:0}}contains(t,e){return!1}invalidate(){Li.enabled&&Li.invalidateCount++,this.throttle_render()}move(t){const e=this.get("translate")||{x:0,y:0};this.set({translate:{x:e.x+t.x,y:e.y+t.y}})}centerTo(t,e){const n=t.rootModel.toLocal(this.canvas.clientWidth/2,this.canvas.clientHeight/2),{x:i,y:s}=t.center,{x:r,y:o}=t.fromParent(i,s),{x:a,y:c}=t.toScene(r,o),{x:l,y:h}=t.rootModel.get("translate"),{x:d,y:u}=t.rootModel.get("scale");e?ka({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 lp extends cp{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){return t?t.scalable?this.context2D:this.auxContext2D:this.context2D}draw(t){this.canvas&&this.element&&(t=t||this.getContext(void 0))&&(this.auxContext2D.clearRect(0,0,this.auxCanvas.width,this.auxCanvas.height),this.auxContext2D.save(),this.auxContext2D.scale(Xs,Xs),super.draw(t),this.auxContext2D.restore())}}var hp,dp,up,pp;!function(t){t.CANVAS="canvas",t.DOM="dom"}(hp||(hp={}));class fp{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;Xr.getInstance().addOverlay(t)}}determineOptimalMode(){return!1!==this.options.animation?hp.DOM:hp.CANVAS}start(){if(!this.isActive&&(this.isActive=!0,this.mode===hp.DOM)){this.overlay?(this.createDOMElements(),this.target.on("change",this.handleTargetChange,this),this.target.on("removed",this.handleTargetRemoved,this)):(Ji("오버레이가 설정되지 않아 DOM 모드 데코레이터를 시작할 수 없습니다."),this.isActive=!1)}}stop(){this.isActive&&(this.isActive=!1,this.mode===hp.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===hp.DOM&&this.isActive&&this.updateDOMElements()}render(t,e){return!(this.mode!==hp.CANVAS||!this.isActive)&&this.renderCanvas(t,e)}removeDOMElements(){this.element&&this.element.parentNode&&(this.element.parentNode.removeChild(this.element),this.element=null)}updateDOMElements(){this.removeDOMElements(),this.createDOMElements()}getComponentPosition(){const{left:t,top:e,width:n,height:i}=this.target.bounds;if("function"==typeof this.target.toGlobal)try{const{x:s,y:r}=this.target.toGlobal(t,e,this.target.rootModel);return{x:s,y:r,width:n,height:i}}catch(t){Ji("좌표 변환 실패, 기본값 사용:",t)}return{x:t,y:e,width:n,height:i}}handleTargetChange(t,e){this.target.disposed?this.stop():this.invalidate()}handleTargetRemoved(){this.stop()}invalidate(){}}class mp extends fp{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:hp.DOM,...n}),this.vectorElement=null,this.animationElements=[],this.svgContainer=null,this.animationElement=null}getDecoratorType(){return this.constructor.DECORATOR_TYPE}dispose(){this.removeDOMElements()}determineOptimalMode(){return hp.DOM}renderCanvas(t,e){return Ji("VectorDecorator는 Canvas 렌더링을 지원하지 않습니다. DOM 모드를 사용하세요."),!1}getSvgContainer(){if(!this.overlay)throw new Error("오버레이 요소가 없습니다.");if(!mp.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),mp.svgContainerCache.set(this.overlay,t)}return mp.svgContainerCache.get(this.overlay)}getOrCreateDecoratorGroup(t=!1){const e=this.getSvgContainer(),n=this.getVectorGroupId(),i=this.getDecoratorType();let s=e.querySelector(`g[data-decorator-type-container="${i}"]`);if(!s){s=document.createElementNS("http://www.w3.org/2000/svg","g"),s.setAttribute("data-decorator-type-container",i),s.setAttribute("class",`${i}-container`),e.appendChild(s);const t=document.createElementNS("http://www.w3.org/2000/svg","defs");t.setAttribute("data-defs-for",i),s.appendChild(t)}let r=s.querySelector(`g[data-decorator-group-id="${n}"]`);if(!r){const{id:t}=this.target.state;return r=document.createElementNS("http://www.w3.org/2000/svg","g"),r.setAttribute("data-decorator-group-id",n),r.setAttribute("data-decorator-type",i),t&&r.setAttribute("data-component-id",t),s.appendChild(r),r}if(t)for(;r.firstChild;)r.removeChild(r.firstChild);return r}getDefsForType(){const t=this.getSvgContainer(),e=this.getDecoratorType();let n=t.querySelector(`g[data-decorator-type-container="${e}"]`);n||(this.getOrCreateDecoratorGroup(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`));let i=n.querySelector(`defs[data-defs-for="${e}"]`);return i||(i=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.setAttribute("data-defs-for",e),n.appendChild(i)),i}getDecoratorGroup(){const t=this.getSvgContainer(),e=this.getVectorGroupId(),n=t.querySelector(`g[data-decorator-group-id="${e}"]`);if(n)return n}createFadeAnimation(t=0,e=1,n=1e3,i={}){const s=document.createElementNS("http://www.w3.org/2000/svg","animate");return s.setAttribute("attributeName","opacity"),s.setAttribute("from",t.toString()),s.setAttribute("to",e.toString()),s.setAttribute("dur",`${n}ms`),i.delay&&s.setAttribute("begin",`${i.delay}ms`),s.setAttribute("fill","freeze"),i.repeat?s.setAttribute("repeatCount","indefinite"):s.setAttribute("repeatCount","1"),s}createTranslateAnimation(t,e=[],n=1e3,i={}){const s=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return s.setAttribute("attributeName","transform"),s.setAttribute("type","translate"),s.setAttribute("values",t.join(";")),e.length>0&&s.setAttribute("keyTimes",e.join(";")),s.setAttribute("dur",`${n}ms`),i.delay&&s.setAttribute("begin",`${i.delay}ms`),i.repeat?s.setAttribute("repeatCount","indefinite"):s.setAttribute("repeatCount","1"),s}createRotateAnimation(t=0,e=360,n=0,i=0,s=1e3,r={}){const o=document.createElementNS("http://www.w3.org/2000/svg","animateTransform");return o.setAttribute("attributeName","transform"),o.setAttribute("type","rotate"),o.setAttribute("from",`${t} ${n} ${i}`),o.setAttribute("to",`${e} ${n} ${i}`),o.setAttribute("dur",`${s}ms`),r.delay&&o.setAttribute("begin",`${r.delay}ms`),r.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 Xu(t,e,n)}updatePosition(){if(!this.vectorElement)return;const t=this.options,{left:e,top:n}=this.target.bounds,i=this.projectComponentPoint(this.target,e,n);if(!i)return;const s=i.x+(t.x??0),r=i.y+(t.y??0);this.vectorElement.setAttribute("transform",`translate(${s}, ${r})`)}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=mp.svgContainerCache.get(this.overlay);if(!t)return;const e=this.getVectorGroupId(),n=this.getDecoratorType(),i=t.querySelector(`g[data-decorator-type-container="${n}"]`);if(i){const t=i.querySelector(`g[data-decorator-group-id="${e}"]`);if(t&&(this.vectorElement&&(this.vectorElement===t||t.contains(this.vectorElement))&&(this.vectorElement=null),this.animationElements=this.animationElements.filter(e=>!t.contains(e)),t.remove()),!i.querySelector("g[data-decorator-group-id]")){const t=i.querySelector(`defs[data-defs-for="${n}"]`);t&&t.remove(),i.remove()}}0===t.children.length&&(t.remove(),mp.svgContainerCache.delete(this.overlay))}catch(t){Zi("벡터 요소 제거 실패:",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===hp.DOM&&this.isActive&&this.updateDOMElements()}touch(){}applyFadeValue(t){if(this.vectorElement){const e=t.toFixed(2);this.vectorElement.setAttribute("opacity",e)}}applyRotationValue(t){if(this.vectorElement){const e=this.getComponentBounds(),n=e.width/2,i=e.height/2,s=(180*t/Math.PI).toFixed(1);this.vectorElement.setAttribute("transform",`rotate(${s} ${n} ${i})`)}}applyTranslateValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("translate")){const i=n.replace(/translate\([^)]+\)/,`translate(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} translate(${t}, ${e})`.trim())}}applyScaleValues(t,e){if(this.vectorElement){const n=this.vectorElement.getAttribute("transform")||"";if(n.includes("scale")){const i=n.replace(/scale\([^)]+\)/,`scale(${t}, ${e})`);this.vectorElement.setAttribute("transform",i)}else this.vectorElement.setAttribute("transform",`${n} scale(${t}, ${e})`.trim())}}getComponentBounds(){return this.target&&this.target.bounds?this.target.bounds:{top:0,left:0,width:100,height:100}}}mp.svgContainerCache=new WeakMap,mp.DECORATOR_TYPE="vector";class gp extends fp{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 hp.CANVAS}createDOMElements(){Ji("RasterDecorator는 DOM 렌더링을 지원하지 않습니다. Canvas 모드를 사용하세요.")}setAnimationState(t=3e3,e=!1){gp.animationStateMap.set(this.target,{startTime:Date.now(),duration:t,repeat:e})}getAnimationState(){const t=gp.animationStateMap.get(this.target);if(!t)return{delta:0,finished:!0};const{startTime:e,duration:n,repeat:i}=t,s=Date.now()-e;let r=Math.min(1,s/n),o=r>=1;return i&&o&&(gp.animationStateMap.set(this.target,{startTime:Date.now(),duration:n,repeat:i}),r=0,o=!1),{delta:r,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(),gp.animationStateMap.delete(this.target)}applyTransform(t,e,n){const i=this.options,s=i.scale||1,r=i.rotation||0;if(1!==s||0!==r){if(t.translate(e,n),0!==r){const e=r*Math.PI/180;t.rotate(e)}1!==s&&t.scale(s,s),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}}gp.animationStateMap=new WeakMap;class yp extends mp{constructor(t,e,n={}){super(t,e,{size:1,showId:!1,animation:!1,...n})}createDOMElements(){if(this.overlay)try{const t=this.getOrCreateDecoratorGroup(!0);t.setAttribute("transform","translate(0, 0)");const{size:e=1,showId:n=!1,duration:i=3e3,repeat:s=!0}=this.options,r=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",r),o.setAttribute("stroke",r),o.setAttribute("stroke-width","1"),o.setAttribute("class","bouncing-arrow");const a=[];if(this.options.animation){const t=this.createBounceAnimation(i,s);if(a.push(t),this.options.fadeOut){const t=this.createFadeAnimation(1,0,i,{repeat:s});a.push(t)}}if(this.addAnimations(o,a),t.appendChild(o),n&&this.target.state?.id){const n=this.createArrowLabel(0,0,r,this.target.state.id,e);if(this.options.animation){const t=[],e=this.createBounceAnimation(i,s);if(t.push(e),this.options.fadeOut){const e=this.createFadeAnimation(1,0,i,{repeat:s});t.push(e)}this.addAnimations(n,t)}t.appendChild(n)}this.vectorElement=t,this.updatePosition(),this.options.animation&&this.startAnimations()}catch(t){Zi("화살표 SVG 요소 생성 실패:",t)}}createArrowPath(t,e,n=1){const i=n/this.getScale();return`\n M${t-10*i},${e-16*i} \n L${t+10*i},${e-16*i} \n L${t+10*i},${e-8*i} \n L${t+16*i},${e-8*i} \n L${t},${e} \n L${t-16*i},${e-8*i} \n L${t-10*i},${e-8*i} \n Z\n `}getScale(){try{if(this.target.rootModel&&"number"==typeof this.target.rootModel.scale)return this.target.rootModel.scale||1}catch(t){Ji("스케일 계산 실패, 기본값 사용",t)}return 1}createBounceAnimation(t,e){const n=["0,-10"],i=["0"];for(let t=1;t<=20;t++){const e=t/20;let s=Math.pow(e,.5).toFixed(3);parseFloat(i[i.length-1])>=parseFloat(s)&&(s=(parseFloat(i[i.length-1])+.01).toFixed(3)),n.push("0,0"),n.push("0,-10"),i.push(s),i.push((parseFloat(s)+.01).toFixed(3))}return i[i.length-1]="1.000",this.createTranslateAnimation(n,i,t,{repeat:e})}createArrowLabel(t,e,n,i,s=1){const r=document.createElementNS("http://www.w3.org/2000/svg","g");r.setAttribute("class","bouncing-arrow-label");const o=document.createElementNS("http://www.w3.org/2000/svg","rect");o.setAttribute("x",`${t+20*s}`),o.setAttribute("y",""+(e-20*s)),o.setAttribute("width",""+40*s),o.setAttribute("height",""+20*s),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*s}`),a.setAttribute("y",""+(e-6*s)),a.setAttribute("fill","white"),a.setAttribute("font-size",12*s+"px"),a.setAttribute("text-anchor","middle"),a.textContent=i,r.appendChild(o),r.appendChild(a),r}startAnimations(){setTimeout(()=>{this.animationElements.forEach(t=>{try{t instanceof SVGElement&&"beginElement"in t&&t.beginElement()}catch(t){Zi("애니메이션 시작 오류:",t)}})},10)}invalidate(){this.updatePosition()}updatePosition(){if(!this.vectorElement)return;const{left:t,top:e,width:n}=this.target.bounds,i=this.projectComponentPoint(this.target,t+n/2,e);if(!i)return;const s=Math.max(i.x,20),r=Math.max(i.y,20);this.vectorElement.setAttribute("transform",`translate(${s}, ${r})`)}}yp.DECORATOR_TYPE="bouncing-arrow",function(t){t.ROTATE="rotate",t.TRANSLATE_X="translateX",t.TRANSLATE_Y="translateY",t.SCALE="scale",t.FADE="fade"}(dp||(dp={})),function(t){t.VIBRATION="vibration",t.ROTATION="rotation",t.HEARTBEAT="heartbeat",t.MOVING="moving",t.OUTLINE="outline",t.FADE="fade",t.WAYPOINT="waypoint"}(up||(up={})),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"}(pp||(pp={}));class bp extends mp{constructor(t,e,n={}){const{animations:i,...s}=n;super(t,e,{icon:"arrow_forward",size:24,color:"#FF0000",deltaX:0,deltaY:0,...s}),this.animations=[],this._location=null,this.element=null,this._delta={theta:0,tx:0,ty:0,sx:1,sy:1,fade:0},this.animations=this.createAnimations(i)}delta(t,e){if(!t)return this._delta;switch(typeof t){case"object":this._delta={...this._delta,...t};break;case"string":if(void 0===e)return this._delta[t];this._delta[t]=e}const{tx:n,ty:i,sx:s,sy:r,theta:o,fade:a}=this._delta;return this.element&&Object.assign(this._getElement().style,{opacity:1-a,transform:`rotate(${o}rad) translate(${n}px, ${i}px) scale(${s}, ${r}) perspective(1px)`}),this._delta}getScaledSize(){const t=this.options.size||24,{x:e}=this.target.rootModel?.state.scale||{x:1},{x:n}=this.target.state.scale||{x:1};return t*e*n}get location(){if(this._location)return this._location;const{location:t,position:e,size:n}=this.options,{bounds:i}=this.target,{left:s,top:r,width:o,height:a}=i,c=n/2;let l;switch(e||t||pp.CENTER){case pp.TOP_LEFT:case"top-left":l={x:s,y:r-n};break;case pp.TOP:case"top":l={x:s+(o-n)/2,y:r-n};break;case pp.TOP_RIGHT:case"top-right":l={x:s+o-n,y:r-n};break;case pp.BOTTOM_LEFT:case"bottom-left":l={x:s,y:r+a};break;case pp.BOTTOM:case"bottom":l={x:s+(o-n)/2,y:r+a};break;case pp.BOTTOM_RIGHT:case"bottom-right":l={x:s+o-n,y:r+a};break;case pp.LEFT_TOP:case"left-top":l={x:s-n,y:r};break;case pp.LEFT:case"left":l={x:s-n,y:r+(a-n)/2};break;case pp.LEFT_BOTTOM:case"left-bottom":l={x:s-n,y:r+(a-n)};break;case pp.RIGHT_TOP:case"right-top":l={x:s+o,y:r};break;case pp.RIGHT:case"right":l={x:s+o,y:r+(a-n)/2};break;case pp.RIGHT_BOTTOM:case"right-bottom":l={x:s+o,y:r+(a-n)};break;case pp.TOP_LEFT_CORNER:case"top-left-corner":l={x:s-c,y:r-c};break;case pp.TOP_RIGHT_CORNER:case"top-right-corner":l={x:s+o-c,y:r-c};break;case pp.BOTTOM_LEFT_CORNER:case"bottom-left-corner":l={x:s-c,y:r+a-c};break;case pp.BOTTOM_RIGHT_CORNER:case"bottom-right-corner":l={x:s+o-c,y:r+a-c};break;case pp.CENTER:default:l={x:s+o/2-n/2,y:r+a/2-n/2}}return this._location=this.toGlobal(l.x,l.y),this._location}_getElement(){return this.element||this._createElementIfNeeded(),this.element}_createElementIfNeeded(){if(this.element)return;const{icon:t="arrow_forward",color:e="#FF0000"}=this.options,n=this.getScaledSize(),{x:i,y:s}=this.location,r=document.createElement("div");r.setAttribute("scene","animated-icon"),Object.assign(r.style,{position:"absolute",fontVariationSettings:"'FILL' 1",fontFamily:"Material Symbols Outlined",fontSize:n+"px",width:n+"px",height:n+"px",lineHeight:n+"px",padding:0,margin:0,color:e,textAlign:"center",verticalAlign:"middle",left:i+"px",top:s+"px",pointerEvents:"none"}),r.textContent=t,this.element=r}updateIconSizeAndPosition(){if(!this.element)return;this._location=null;const t=this.getScaledSize(),{x:e,y:n}=this.location;Object.assign(this.element.style,{fontSize:t+"px",width:t+"px",height:t+"px",lineHeight:t+"px",left:e+"px",top:n+"px"})}touch(){}invalidate(){this.updateIconSizeAndPosition()}start(){if(super.start(),this.isActive){if(this.overlay&&this._getElement().parentNode!==this.overlay&&this.overlay.appendChild(this._getElement()),this.target?.root?.app?.suppressAnimations)return;this.animations.forEach(t=>t.start())}}stop(){this.animations.forEach(t=>t.stop()),this.element&&this._getElement().parentNode&&this._getElement().parentNode.removeChild(this._getElement()),this._location=null,super.stop()}get center(){const t=this.getScaledSize(),{x:e,y:n}=this.location;return{x:e+t/2,y:n+t/2}}toGlobal(t,e){const{tx:n,ty:i}=this._delta;return this.projectComponentPoint(this.target,t+n,e+i)??this.target.toGlobal(t+n,e+i)}get root(){return this.target.root}createDOMElements(){this._getElement()}updateDOMElements(){this.element?this.updateIconSizeAndPosition():this._getElement()}updatePosition(){this.updateIconSizeAndPosition()}createAnimations(t){if(Array.isArray(t))return t.map(t=>("theta"in t&&(t={...t,theta:t.theta*(Math.PI/180)}),Ca(this,t)));if(t){const e={...t};return"theta"in e&&(e.theta=e.theta*(Math.PI/180)),[Ca(this,e)]}return[]}}bp.DECORATOR_TYPE="animated-icon";class _p extends mp{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{const t=this.getOrCreateDecoratorGroup(!0);this.decoratorGroup=t;const e=this.getDefsForType(),n=this.getVectorGroupId();this.elementId=`${n}-border`;const{color:i="#FF0000",animation:s=!1}=this.options,{fillStyle:r}=this.target.state||{},o=this.createFilter(this.elementId,this.options.fillStyle||r||"rgba(0, 0, 0, 0.5)");if(e.appendChild(o),s){const t=this.createGradient(this.elementId,i);e.appendChild(t)}const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("fill","none"),a.setAttribute("stroke-width",(this.options.lineWidth||2).toString()),a.setAttribute("stroke-linejoin","round"),a.setAttribute("pointer-events","none"),a.setAttribute("class","border-highlighting-path"),a.setAttribute("filter",`url(#${this.elementId}-filter)`),s?a.setAttribute("stroke",`url(#${this.elementId})`):a.setAttribute("stroke",i),t.appendChild(a),this.pathElement=a,this.vectorElement=t,this.updatePathData(),this.options.animation&&this.startAnimations()}catch(t){Zi("테두리 하이라이팅 요소 생성 실패:",t)}}updatePathData(){if(!this.pathElement)return;this.pathElement.setAttribute("visibility","visible"),this.pathElement.setAttribute("opacity","1"),this.decoratorGroup&&(this.decoratorGroup.setAttribute("visibility","visible"),this.decoratorGroup.setAttribute("opacity","1"));const t=this.getPathPoints(),e=this.createOffsetPath(t,this.options.distance),{round:n=0}=this.target.state||{},i=this.pointsToPathData(e,n);this.pathElement.setAttribute("d",i)}invalidate(){this.updatePathData()}startAnimations(){if(!this.isActive||!this.options.animation||!this.pathElement)return;if(this.target?.root?.app?.suppressAnimations)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){Zi("애니메이션 시작 오류:",t)}})}}}getPathPoints(){if(!this.target.path||!Array.isArray(this.target.path)){const{left:t,top:e,width:n,height:i}=this.target.bounds;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}return this.target.path.map(t=>this.target.toGlobal(t.x,t.y))}createOffsetPath(t,e){const n=[],i=t.length;for(let s=0;s<i;s++){const r=t[(s-1+i)%i],o=t[s],a=t[(s+1)%i],c=o.x-r.x,l=o.y-r.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}),m={x:o.x+f.x*e,y:o.y+f.y*e};n.push(m)}return n}normalize(t){const e=Math.sqrt(t.x*t.x+t.y*t.y);return{x:t.x/e||0,y:t.y/e||0}}pointsToPathData(t,e=0){if(t.length<2)return"";let n="";const i=t.length,s=(t,e,n)=>{const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(i*i+s*s);return{x:t.x+i/r*n,y:t.y+s/r*n}};for(let r=0;r<i;r++){const o=t[r],a=t[(r+1)%i],c=t[(r-1+i)%i],l=Math.sqrt((o.x-c.x)**2+(o.y-c.y)**2),h=Math.sqrt((o.x-a.x)**2+(o.y-a.y)**2),d=Math.min(e,l/2,h/2),u=s(o,c,d),p=s(o,a,d);n+=0===r?`M${u.x},${u.y}`:` L${u.x},${u.y}`,n+=` Q${o.x},${o.y} ${p.x},${p.y}`}return n+=" Z",n}createFilter(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","filter");n.setAttribute("id",`${t}-filter`);const i=document.createElementNS("http://www.w3.org/2000/svg","feFlood");i.setAttribute("flood-color",e),i.setAttribute("result","flood");const s=document.createElementNS("http://www.w3.org/2000/svg","feComposite");s.setAttribute("in","flood"),s.setAttribute("in2","SourceAlpha"),s.setAttribute("operator","in"),s.setAttribute("result","mask");const r=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"),r.appendChild(o),r.appendChild(a),n.appendChild(i),n.appendChild(s),n.appendChild(r),n}createGradient(t,e){const n=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");n.setAttribute("id",t),n.setAttribute("x1","0%"),n.setAttribute("y1","0%"),n.setAttribute("x2","100%"),n.setAttribute("y2","0%");const i=this.alterColor(e,120),s=this.alterColor(e,240),r=document.createElementNS("http://www.w3.org/2000/svg","stop");r.setAttribute("offset","0%"),r.setAttribute("stop-color",e);const o=document.createElementNS("http://www.w3.org/2000/svg","animate");o.setAttribute("attributeName","stop-color"),o.setAttribute("values",`${e};${i};${s};${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",s);const c=document.createElementNS("http://www.w3.org/2000/svg","animate");return c.setAttribute("attributeName","stop-color"),c.setAttribute("values",`${s};${e};${i};${s}`),c.setAttribute("dur","5s"),c.setAttribute("repeatCount","indefinite"),r.appendChild(o),a.appendChild(c),n.appendChild(r),n.appendChild(a),n}alterColor(t,e){const n=this.convertToHex(t),i=parseInt(n.substring(1,3),16),s=parseInt(n.substring(3,5),16),r=parseInt(n.substring(5,7),16),o=this.rgbToHsl(i,s,r);o[0]=(o[0]+e/360)%1;const a=this.hslToRgb(o[0],o[1],o[2]);return`#${a[0].toString(16).padStart(2,"0")}${a[1].toString(16).padStart(2,"0")}${a[2].toString(16).padStart(2,"0")}`}rgbToHsl(t,e,n){t/=255,e/=255,n/=255;const i=Math.max(t,e,n),s=Math.min(t,e,n);let r=0,o=0;const a=(i+s)/2;if(i!==s){const c=i-s;switch(o=a>.5?c/(2-i-s):c/(i+s),i){case t:r=(e-n)/c+(e<n?6:0);break;case e:r=(n-t)/c+2;break;case n:r=(t-e)/c+4}r/=6}return[r,o,a]}hslToRgb(t,e,n){let i,s,r;if(0===e)i=s=r=n;else{const o=(t,e,n)=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t),a=n<.5?n*(1+e):n+e-n*e,c=2*n-a;i=o(c,a,t+1/3),s=o(c,a,t),r=o(c,a,t-1/3)}return[Math.round(255*i),Math.round(255*s),Math.round(255*r)]}convertToHex(t){if(/^#([0-9A-F]{6})$/i.test(t))return t;const e=document.createElement("canvas");e.width=1,e.height=1;const n=e.getContext("2d");if(!n)return"#FF0000";n.fillStyle=t,n.fillRect(0,0,1,1);const i=n.getImageData(0,0,1,1).data;return`#${i[0].toString(16).padStart(2,"0")}${i[1].toString(16).padStart(2,"0")}${i[2].toString(16).padStart(2,"0")}`}start(){super.start(),this.isActive&&this.options.animation&&this.startAnimations()}removeDOMElements(){try{if(this.pathElement&&this.pathElement.parentNode&&this.pathElement.parentNode.removeChild(this.pathElement),this.pathElement=null,this.overlay){const t=this.getDefsForType();if(t&&this.elementId){const e=t.querySelector(`#${this.elementId}-filter`);e&&e.remove();const n=t.querySelector(`#${this.elementId}`);n&&n.remove()}}super.removeDOMElements()}catch(t){Zi("테두리 하이라이팅 요소 제거 중 오류:",t)}}}_p.DECORATOR_TYPE="border-highlighting";class vp extends mp{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",...n}),this.textElements=[],this.rectElements=[]}updateDOMElements(){if(!this.target.anchors||!this.target.anchors.length)return void this.removeDOMElements();const t=this.options,e=this.target.anchors,n=this.getOrCreateDecoratorGroup(!0);this.textElements=[],this.rectElements=[];const i=this.getComponentBounds();e.forEach(e=>{const{name:s,position:r}=e;let{x:o,y:a}=r||{};if(!s)return;let c=this.calculateOffsetX(o,i),l=this.calculateOffsetY(a,i);const h=this.projectComponentPoint(this.target,o,a);if(!h)return;o=h.x,a=h.y;const d=document.createElementNS("http://www.w3.org/2000/svg","text");d.setAttribute("fill",t.textColor),d.setAttribute("font-family",t.fontFamily),d.setAttribute("font-size",t.fontSize),d.textContent=s,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 m=document.createElementNS("http://www.w3.org/2000/svg","rect");m.setAttribute("x",(o+c).toString()),m.setAttribute("y",(a+l).toString()),m.setAttribute("width",(p+6).toString()),m.setAttribute("height",(f+6).toString()),m.setAttribute("rx",t.cornerRadius.toString()),m.setAttribute("ry",t.cornerRadius.toString()),m.setAttribute("fill",t.bgColor),n.appendChild(m),n.appendChild(d),this.rectElements.push(m),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()}}vp.DECORATOR_TYPE="anchors";class xp extends mp{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:3,padding:3,fontSize:"12px",fontFamily:"Arial",offsetX:3,offsetY:-8,animation:!1,...n}),this.textElement=null,this.backgroundElement=null,this.currentTag=""}createDOMElements(){const t=this.target.decotag;if(!t)return;this.currentTag=t;const{fontFamily:e,fontSize:n,textColor:i,padding:s,cornerRadius:r,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",`${s}`),this.textElement.setAttribute("y",`-${n}`),this.textElement.setAttribute("font-family",e),this.textElement.setAttribute("font-size",n),this.textElement.setAttribute("fill",i),this.textElement.setAttribute("dominant-baseline","middle"),h.appendChild(this.textElement);const d=this.textElement.getBBox();if(this.backgroundElement=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.backgroundElement.setAttribute("x",(d.x-s).toString()),this.backgroundElement.setAttribute("y",(d.y-s).toString()),this.backgroundElement.setAttribute("width",(d.width+2*s).toString()),this.backgroundElement.setAttribute("height",(d.height+2*s).toString()),this.backgroundElement.setAttribute("rx",r.toString()),this.backgroundElement.setAttribute("ry",r.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()}}xp.DECORATOR_TYPE="decotag";class wp extends mp{constructor(t,e,n={}){super(t,e,{arrowColor:"#FFA500",arrowHeadLength:12,lineWidth:1.5,startAlpha:.6,endAlpha:1,animated:!0,animationDuration:5e3,repeat:!1,...n}),this.currentMappings=null,this.cachedArrows=[],this._incomingTimer=null}findIncomingSources(){const t=this.target.root;if(!t)return[];const e=this.target.state?.id;if(!e)return[];const n=[];return t.traverse(i=>{if(i===this.target)return;const s=i.model?.mappings;if(s)for(const r of s){if(!r.target)continue;if(r.target===`#${e}`){n.push({from:i,to:this.target});break}const s=t.findAll(r.target,i);if(s?.some(t=>t===this.target)){n.push({from:i,to:this.target});break}}}),n}appendArrow(t,e,n,i,s,r){const o=e.center,a=n.center,c=this.projectComponentPoint(e,o.x,o.y),l=this.projectComponentPoint(n,a.x,a.y);if(!c||!l)return;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,r.arrowHeadLength),u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",h),u.setAttribute("stroke",s),u.setAttribute("stroke-width",String(r.lineWidth||2)),u.setAttribute("fill","none"),u.setAttribute("data-source-id",e.state?.id||""),u.setAttribute("data-target-id",n.state?.id||"");const p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d",d),p.setAttribute("fill",i),p.setAttribute("stroke","none"),t.appendChild(u),t.appendChild(p)}createDOMElements(){this.removeDOMElements();const t=this.target.mappings&&this.target.mappings.length>0;this.currentMappings=this.target.mappings;const e=this.options,n=e.arrowColor||"#FFA500",i=this.getOrCreateDecoratorGroup(!0),s=this.getDefsForType(),r=`data-spread-style-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,o=document.createElementNS("http://www.w3.org/2000/svg","style");o.setAttribute("id",r),o.textContent=`\n @keyframes fadeOut {\n from { opacity: 1; }\n to { opacity: ${e.repeat?"0.2":"0"}; }\n }\n .arrow-animated {\n animation: fadeOut ${e.animationDuration||2e3}ms linear ${e.repeat?"infinite":"1"} forwards;\n }\n `,s.appendChild(o);const a=Date.now(),c=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),l=`arrow-gradient-out-${a}-${c}`,h=this.createGradient(l,n,e);s.appendChild(h);const d=wp.INCOMING_ARROW_COLOR,u=`arrow-gradient-in-${a}-${c}`,p=this.createGradient(u,d,e);s.appendChild(p);const f=document.createElementNS("http://www.w3.org/2000/svg","g");if(f.setAttribute("class",e.animated?"arrow-animated":""),i.appendChild(f),this.cachedArrows=[],t){this.target.mappings.forEach(t=>{const i=this.target.root.findAll(t.target,this.target);i?.length&&i.forEach(t=>{t!==this.target&&(this.cachedArrows.push({from:this.target,to:t}),this.appendArrow(f,this.target,t,n,`url(#${l})`,e))})})}this.vectorElement=i,this._incomingTimer=setTimeout(()=>{if(this._incomingTimer=null,!this.vectorElement)return;this.findIncomingSources().forEach(({from:t})=>{this.cachedArrows.push({from:t,to:this.target}),this.appendArrow(f,t,this.target,d,`url(#${u})`,e)})},wp.INCOMING_DEBOUNCE_MS)}createGradient(t,e,n){const i=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");i.setAttribute("id",t),i.setAttribute("gradientUnits","userSpaceOnUse");const s=document.createElementNS("http://www.w3.org/2000/svg","stop");s.setAttribute("offset","0%"),s.setAttribute("stop-color",e),s.setAttribute("stop-opacity",(n.startAlpha||.5).toString());const r=document.createElementNS("http://www.w3.org/2000/svg","stop");return r.setAttribute("offset","100%"),r.setAttribute("stop-color",e),r.setAttribute("stop-opacity",(n.endAlpha||1).toString()),i.appendChild(s),i.appendChild(r),i}createArrowPaths(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=Math.atan2(s,i),o=e.x+n*Math.cos(r+wp.ARROW_ANGLE_1),a=e.y+n*Math.sin(r+wp.ARROW_ANGLE_1),c=e.x+n*Math.cos(r+wp.ARROW_ANGLE_2),l=e.y+n*Math.sin(r+wp.ARROW_ANGLE_2);return{linePath:`M ${t.x} ${t.y} L ${e.x} ${e.y}`,headPath:`M ${e.x} ${e.y} L ${o} ${a} L ${c} ${l} Z`}}updateDOMElements(){if(!this.target.app?.isEditMode)return void this.removeDOMElements();this.target.mappings!==this.currentMappings?(this.removeDOMElements(),requestAnimationFrame(()=>{this.createDOMElements()})):this.vectorElement&&this.updatePosition()}updatePosition(){const t=this.getDecoratorType(),e=this.getSvgContainer().querySelector(`g[data-decorator-type-container="${t}"]`);if(!e)return;const n=this.getVectorGroupId(),i=e.querySelector(`g[data-decorator-group-id="${n}"]`);if(!i)return;const s=this.options,r=i.querySelector("g.arrow-animated")||i,o=Array.from(r.querySelectorAll('path[fill="none"]')),a=Array.from(r.querySelectorAll('path[stroke="none"]'));if(0===o.length)return;const c=Math.min(o.length,a.length,this.cachedArrows.length);for(let t=0;t<c;t++){const{from:e,to:n}=this.cachedArrows[t],i=e.center,r=n.center,c=this.projectComponentPoint(e,i.x,i.y),l=this.projectComponentPoint(n,r.x,r.y);if(!c||!l)continue;const{linePath:h,headPath:d}=this.createArrowPaths(c,l,s.arrowHeadLength);o[t].setAttribute("d",h),a[t].setAttribute("d",d)}}removeDOMElements(){this.currentMappings=null,this.cachedArrows=[],this._incomingTimer&&(clearTimeout(this._incomingTimer),this._incomingTimer=null);try{if(this.overlay){const t=this.getSvgContainer();if(t){const e=this.getDecoratorType(),n=t.querySelector(`g[data-decorator-type-container="${e}"]`);if(n){const t=n.querySelector(`defs[data-defs-for="${e}"]`);if(t){t.querySelectorAll("style").forEach(t=>t.remove());t.querySelectorAll("linearGradient").forEach(t=>t.remove())}}}}this.animationElements=[],super.removeDOMElements()}catch(t){Zi("데이터 스프레드 데코레이터 요소 제거 중 오류:",t)}}invalidate(){this.updatePosition()}}wp.DECORATOR_TYPE="data-spread",wp.ARROW_ANGLE_1=160*Math.PI/180,wp.ARROW_ANGLE_2=200*Math.PI/180,wp.INCOMING_ARROW_COLOR="#4A9EFF",wp.INCOMING_DEBOUNCE_MS=500;class Mp extends mp{constructor(t,e,n={}){super(t,e,{bgColor:"#FF0000",textColor:"white",cornerRadius:2,padding:2,fontSize:"12px",fontFamily:"Arial",offsetX:4,offsetY:4,...n}),this.textElements=[],this.rectElements=[]}createDOMElements(){this.updateDOMElements()}updateDOMElements(){if(!this.target.isLine||!this.target.isLine())return void this.removeDOMElements();const{offsetX:t,offsetY:e,padding:n,textColor:i,bgColor:s,cornerRadius:r,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:m,y:g}=f;const y=document.createElementNS("http://www.w3.org/2000/svg","g"),b=document.createElementNS("http://www.w3.org/2000/svg","text");b.setAttribute("text-anchor","middle"),b.setAttribute("dominant-baseline","middle"),b.setAttribute("x","0"),b.setAttribute("y","0"),b.setAttribute("fill",i),b.setAttribute("font-family",a),b.setAttribute("font-size",o),b.textContent=u,c.appendChild(b);const _=b.getBBox();c.removeChild(b);const v=document.createElementNS("http://www.w3.org/2000/svg","rect"),x=_.width+2*(n??0),w=_.height+2*(n??0);m+=(t??0)+x/2,g+=(e??0)+w/2,v.setAttribute("x",(-x/2).toString()),v.setAttribute("y",(-w/2).toString()),v.setAttribute("width",x.toString()),v.setAttribute("height",w.toString()),v.setAttribute("rx",(r??0).toString()),v.setAttribute("ry",(r??0).toString()),v.setAttribute("fill",s),y.appendChild(v),y.appendChild(b),y.setAttribute("transform",`translate(${m}, ${g})`),c.appendChild(y),this.rectElements.push(v),this.textElements.push(b)})}updatePosition(){super.updatePosition(),this.updateDOMElements()}invalidate(){this.updatePosition()}}Mp.DECORATOR_TYPE="link",$r.registerDecorator("bouncing-arrow",yp),$r.registerDecorator("animated-icon",bp),$r.registerDecorator("border-highlighting",_p),$r.registerDecorator("anchors",vp),$r.registerDecorator("decotag",xp),$r.registerDecorator("data-spread",wp),$r.registerDecorator("link",Mp);let Sp=0,kp=0,Ap=0,Ep=null;function Cp(){Ap++;const t=performance.now(),e=t-kp;e>=1e3&&(Sp=Math.round(1e3*Ap/e),kp=t,Ap=0),Ep=requestAnimationFrame(Cp)}function Tp(){null!==Ep&&(cancelAnimationFrame(Ep),Ep=null)}function Pp(){return null===Ep&&(kp=performance.now(),Ap=0,Ep=requestAnimationFrame(Cp)),Sp}const Op=function(){if("undefined"==typeof document)return 1;const t=document.createElement("canvas").getContext("2d");return("undefined"!=typeof window&&window.devicePixelRatio||1)/(t&&(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio)||1)}();function Dp(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 zp=Math.sqrt(3);function Ip(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 Rp(t,n,i){switch(t){case"none":default:return null;case"arrow":{const t=zp*n.X,i=n.Y,s=new e.ConeGeometry(i,t,16);return s.rotateZ(-Math.PI/2),s.translate(-t/2,0,0),{mesh:new e.Mesh(s,new e.MeshBasicMaterial)}}case"sharp-arrow":{const t=zp*n.X*1.3,i=.65*n.Y,s=new e.ConeGeometry(i,t,16);return s.rotateZ(-Math.PI/2),s.translate(-t/2,0,0),{mesh:new e.Mesh(s,new e.MeshBasicMaterial)}}case"open-arrow":{const t=zp*n.X,i=n.Y,s=new e.ConeGeometry(i,t,6);return s.rotateZ(-Math.PI/2),s.translate(-t/2,0,0),{mesh:new e.Mesh(s,new e.MeshBasicMaterial({wireframe:!0}))}}case"diamond":{const t=new e.OctahedronGeometry(1);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"oval":{const t=new e.SphereGeometry(1,16,12);return t.scale(n.X,n.Y,n.Y),{mesh:new e.Mesh(t,new e.MeshBasicMaterial)}}case"cross":{const t=Math.max(n.X,n.Y),i=.9*t,s=.25*t,r=.15*t,o=new e.Group,a=[new e.Vector3(1,1,1).normalize(),new e.Vector3(1,-1,-1).normalize(),new e.Vector3(-1,1,-1).normalize(),new e.Vector3(-1,-1,1).normalize()];for(const t of a){const n=new e.CylinderGeometry(s,r,i,6),a=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,1,0),t);n.applyQuaternion(a),n.translate(t.x*i/2,t.y*i/2,t.z*i/2),o.add(new e.Mesh(n,new e.MeshBasicMaterial))}return{group:o}}}}function jp(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Lp(t,n,i,s){const{strokeStyle:r,alpha:o=1,lineWidth:a=2,begin:c="none",beginSize:l="size2",end:h="arrow",endSize:d="size2",label:u}=i,p=(new e.Vector3).subVectors(n,t),f=p.length(),m=new e.Group;if(f<.01)return m;const g=p.clone().normalize(),y=jp(c,a),b=jp(h,a),_=t.clone().add(g.clone().multiplyScalar(y)),v=n.clone().sub(g.clone().multiplyScalar(b));let x;if(Array.isArray(r)&&r.length>=2){const t=r[1];x=new e.Color(t.length>7?t.slice(0,7):t)}else x=new e.Color("string"==typeof r?r:"#00B050");const k=function(t,n,i,s){const{strokeStyle:r,alpha:o=1,lineWidth:a=2,lineDash:c="solid"}=i,l=new S;let h;l.setPositions([t.x,t.y,t.z,n.x,n.y,n.z]);let d=!1;if(Array.isArray(r)&&r.length>=2){const t=new e.Color(r[0].length>7?r[0].slice(0,7):r[0]),n=new e.Color(r[1].length>7?r[1].slice(0,7):r[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 r?r:"#00B050");const{dashed:u,dashSize:p,gapSize:f}=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),m=new M({color:d?16777215:h.getHex(),linewidth:a,worldUnits:!0,vertexColors:d,dashed:u,dashSize:p,gapSize:f,transparent:o<1||Array.isArray(r)&&r.some(t=>t.length>7),opacity:o,resolution:s}),g=new w(l,m);return g.computeLineDistances(),g}(_,v,i,s);m.add(k);const A=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),g),E=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),g.clone().negate()),C=(t,e,n)=>{if(!t)return;const i=t.mesh||t.line2||t.group;if(i){if(i.position.copy(e),i.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(x),e.transparent=o<1,e.opacity=o}else if(t.line2){const e=t.line2.material;e.color.copy(x),e.transparent=o<1,e.opacity=o,e.resolution.copy(s)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color.copy(x),e.transparent=o<1,e.opacity=o,e.resolution&&e.resolution.copy(s)}});m.add(i)}};C(Rp(h,Ip(d,a)),n,A);if(C(Rp(c,Ip(l,a)),t,E),u){const i=(new e.Vector3).addVectors(t,n).multiplyScalar(.5);i.y+=3;const s=function(t,n,i){const s="Arial",r=Dp(256,64),o=r.getContext("2d");o.font=`bold 28px ${s}`;const a=o.measureText(t).width;o.fillStyle=n,o.fillRect(0,0,a+12,40),o.fillStyle="white",o.font=`bold 28px ${s}`,o.textBaseline="top",o.fillText(t,6,6);const c=new e.CanvasTexture(r);c.needsUpdate=!0,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace;const l=new e.SpriteMaterial({map:c,transparent:!0}),h=new e.Sprite(l);h.position.copy(i);const d=(a+12)/40;return h.scale.set(4*d,4,1),h}(u,"string"==typeof r?r:Array.isArray(r)&&r[1]||"#00B050",i);m.add(s)}return m}function Fp(t){return"double"===t?"visible":"hidden"}class Np extends pu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}getObject3dInstance(){return new v(this.component.element)}get rotation(){const{rotationX:t=0,rotationY:e=0,rotation:n=0}=this.component.state;return{x:t-Math.PI/2,y:e,z:-n}}syncFromObject3D(){const t=this.object3d,e=this._component,{width:n=0,height:i=0}=e.parent?.bounds??{},s=e.bounds,{tx:r=0,ty:o=0,tz:a=0}=e.delta();this._suppressOnchange=!0;const c=t.scale.x;e.bounds={left:t.position.x-r+n/2-s.width/2,top:t.position.z-o+i/2-s.height/2,width:s.width,height:s.height};const l=this.component.parent?._realObject,h=l?.geometricOffsetY??0;e.set({zPos:t.position.y-a-this.syncZPosOffset+h,rotationX:t.rotation.x+Math.PI/2,rotation:-t.rotation.z,rotationY:t.rotation.y,scale:{x:c,y:c}}),this._suppressOnchange=!1}build(){super.build();const t=this.component.element;if(!t)return;t.style.left="",t.style.top="";const e=Md(this.component.state.material3d);if(t.style.backfaceVisibility=Fp(e.side),this.component.state.screenFixed&&this.component.isContainer?.())return;const{width:n,height:i}=this.component.bounds;t.style.width=n+"px",t.style.height=i+"px"}updateMaterial3d(){super.updateMaterial3d();const t=this.component.element;if(!t)return;const e=Md(this.component.state.material3d);t.style.backfaceVisibility=Fp(e.side)}updateDimension(){if(this.component.state.screenFixed&&this.component.isContainer?.())return;super.updateDimension();const t=this.dimension,e=this.component.element;e&&(e.style.width=t.width+"px",e.style.height=t.height+"px")}applyFocusDim(){this.component.applyElementModelingFaint?.()}updateAlpha(){this.component.applyElementModelingFaint?.()}}const Hp=new Map;let Bp;function Gp(t,e){Hp.set(t,e)}function Vp(t){Bp=t}function Yp(t){const e=t.buildRealObject();if(e)return e;const n=t.model?.type,i=n?Hp.get(n):void 0;if(i)return i(t);if(t.isHTMLElement()){const e=Hp.get("html-overlay-element");if(e)return e(t)}return Bp?.(t)}function Wp(t,n,i){if(!t.hasTextProperty||t.textHidden)return;const s=t._realObject;if(!s?.object3d)return;const{text:r="",bold:o=Qs.BOLD,italic:a=Qs.ITALIC,fontFamily:c=Qs.FONT_FAMILY,fontColor:l=Qs.FONT_COLOR,fontSize:h=Qs.FONT_SIZE,textAlign:d=Qs.TEXT_ALIGN,textBaseline:u=Qs.TEXT_BASELINE,width:p,height:f}=t.model,m=Math.abs(p)||1,g=Math.abs(f)||1,y=document.createElement("textarea"),b=new AbortController;qs.forEach(t=>{y.addEventListener(t,t=>t.stopPropagation(),{capture:!0,signal:b.signal})}),y.value=r;const _="right"===d||"end"===d?"right":"left"===d||"start"===d?"left":"justify"===d?"justify":"center";let x="0";if("bottom"===u||"alphabetic"===u){const t=1.2*h*Math.max(1,(r.match(/\n/g)||[]).length+1);x=Math.max(0,g-t)+"px"}else if("middle"===u){const t=1.2*h*Math.max(1,(r.match(/\n/g)||[]).length+1);x=Math.max(0,(g-t)/2)+"px"}y.style.cssText=[`width: ${m}px`,`height: ${g}px`,`padding: ${x} 0 0 0`,"margin: 0",`font-family: ${c}`,`font-size: ${h}px`,`line-height: ${1.2*h}px`,"overflow: hidden","resize: none","outline: 1px solid #f26522","border: 0","background-color: rgba(255, 255, 255, 0.85)","display: block",`color: ${l}`,"box-sizing: border-box","font-weight: "+(o?"bold":"normal"),"font-style: "+(a?"italic":"normal"),`text-align: ${_}`].join("; ");const w=new v(y),M=s.object3d;M.updateWorldMatrix(!0,!1);const S=new e.Vector3,k=new e.Quaternion,A=new e.Vector3;M.matrixWorld.decompose(S,k,A);const E=new e.Vector3(0,s.textSurfaceYOffset,0);E.multiply(A),E.applyQuaternion(k),w.position.copy(S).add(E);const C=(new e.Quaternion).setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2);w.quaternion.copy(k).multiply(C),w.scale.copy(A),n.css3DScene.add(w),i();const T=n.css3DRenderer.domElement,P=T.style.getPropertyValue("pointer-events"),O=T.style.getPropertyPriority("pointer-events"),D=[];let z=y;for(;z&&z!==T.parentElement;)D.push({el:z,saved:z.style.pointerEvents}),z.style.setProperty("pointer-events","auto","important"),z=z.parentElement;y.focus(),y.select();let I=!1;const R=t.root?.selected;y.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"!==t.code&&(t.shiftKey||"Enter"!==t.code&&"NumpadEnter"!==t.code)||(I="Escape"===t.code,y.blur())},{signal:b.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?T.style.setProperty("pointer-events",P,O):P&&T.style.setProperty("pointer-events",P),b.abort(),y.removeEventListener("blur",j),R&&t.root&&(t.root.selected=R),I||y.value===r||t.app.commander.execute(new ll({changes:[{component:t,before:{text:r},after:{text:y.value}}]})),i()};y.addEventListener("blur",j)}const Up=[{name:"X",dir:[1,0,0],color:13590367},{name:"Y",dir:[0,1,0],color:5482594},{name:"Z",dir:[0,0,1],color:5603535}];function $p(t){const e=Math.max(t,1)/5,n=Math.pow(10,Math.floor(Math.log10(e))),i=e/n,s=i<1.5?1:i<3.5?2:i<7.5?5:10;return Math.max(1,s*n)}function Xp(t,e){const n=Math.min(1,t/e);return Math.max(0,1-n*n)}function qp(t){const n=Math.max(t.step,1e-6),i=Math.max(2,Math.round(t.cells??16)),s=n*i,r=new e.Color(t.background??"#7c7c7c"),o=(t,n)=>r.clone().lerp(new e.Color(t),n),a=new e.Group;a.name="coordinate-ground",a.raycast=()=>{},a.add(function(t,e,n,i){const s=[],r=[],o=(t,e,o)=>{const a=i(16777215,Xp(Math.hypot(t,e),n)*(o?.85:.45));s.push(t,0,e),r.push(a.r,a.g,a.b)};for(let n=-e;n<=e;n++){if(0===n)continue;const i=n%5==0,s=n*t;for(let n=-e;n<e;n++){const e=n*t,r=(n+1)*t;o(e,s,i),o(r,s,i),o(s,e,i),o(s,r,i)}}return Qp(s,r)}(n,i,s,o));for(const i of Up){const r=new e.Vector3(...i.dir).multiplyScalar(s),c=r.clone().negate();a.add(Kp(c,r,i.color,s,o)),!1!==t.labels&&(a.add(Zp("+"+i.name,i.color,r.clone().multiplyScalar(1.08),n)),a.add(Zp("-"+i.name,i.color,c.clone().multiplyScalar(1.08),n)))}return a}function Kp(t,e,n,i,s){const r=[],o=[],a=t=>{const e=s(n,Xp(t.length(),i));r.push(t.x,t.y,t.z),o.push(e.r,e.g,e.b)};for(let n=0;n<24;n++)a(t.clone().lerp(e,n/24)),a(t.clone().lerp(e,(n+1)/24));return Qp(r,o)}function Qp(t,n){const i=new e.BufferGeometry;i.setAttribute("position",new e.Float32BufferAttribute(t,3)),i.setAttribute("color",new e.Float32BufferAttribute(n,3));const s=new e.LineSegments(i,new e.LineBasicMaterial({vertexColors:!0}));return s.raycast=()=>{},s}function Zp(t,n,i,s){const r=document.createElement("canvas");r.width=64,r.height=64;const o=r.getContext("2d");o.font="bold 34px system-ui, sans-serif",o.textAlign="center",o.textBaseline="middle",o.fillStyle="#"+n.toString(16).padStart(6,"0"),o.fillText(t,32,32);const a=new e.CanvasTexture(r);a.colorSpace=e.SRGBColorSpace;const c=new e.Sprite(new e.SpriteMaterial({map:a,transparent:!0}));return c.position.copy(i),c.scale.setScalar(.55*s),c.raycast=()=>{},c}function Jp(t){t.traverse(t=>{const e=t;e.geometry?.dispose?.();const n=e.material;n&&(n.map?.dispose?.(),n.dispose?.())}),t.removeFromParent()}class tf extends r{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()}}tf.recommendsLogarithmicDepth=!1;class ef extends tf{constructor(){super(),this.name="WarehouseEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:8425632}),n=new l(t,e);n.position.set(0,18,0),n.scale.set(50,40,40),this.add(n);const i=new a({color:9474192,roughness:.9}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(50,.5,40),this.add(s);const r=new h(15266047,600,50,2);r.position.set(-10,30,0),this.add(r);const u=new h(15266047,600,50,2);u.position.set(10,30,0),this.add(u);const p=(e,n,i)=>{const s=new d({color:0,emissive:15266047,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,35,n),r.scale.set(8,.1,2),r};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 l(t,new d({color:0,emissive:16772829,emissiveIntensity:15}));f.position.set(0,10,-19),f.scale.set(12,8,.1),this.add(f)}}ef.recommendsLogarithmicDepth=!0;class nf extends tf{constructor(){super(),this.name="FactoryEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:6318192,metalness:.1,roughness:.8}),n=new l(t,e);n.position.set(0,20,0),n.scale.set(60,44,45),this.add(n);const i=new a({color:8028272,roughness:.7,metalness:.05}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(60,.5,45),this.add(s);const r=(t,e)=>{const n=new h(15791615,800,55,2);return n.position.set(t,35,e),n};this.add(r(-15,-10)),this.add(r(-15,10)),this.add(r(0,0)),this.add(r(15,-10)),this.add(r(15,10));const u=(e,n,i)=>{const s=new d({color:0,emissive:15791615,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,38,n),r.scale.set(6,.1,3),r};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 l(t,new d({color:0,emissive:11206570,emissiveIntensity:10}));p.position.set(28,14,-21),p.scale.set(1,2,.1),this.add(p);const f=new l(t,new d({color:0,emissive:16772829,emissiveIntensity:25}));f.position.set(0,8,-22),f.scale.set(10,10,.1),this.add(f)}}nf.recommendsLogarithmicDepth=!0;class sf extends tf{constructor(){super(),this.name="OfficeEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:14209224}),n=new l(t,e);n.position.set(0,10,0),n.scale.set(35,22,30),this.add(n);const i=new a({color:10524808,roughness:.85}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(35,.5,30),this.add(s);const r=new h(16774374,400,30,2);r.position.set(0,17,0),this.add(r);const u=(e,n,i)=>{const s=new d({color:0,emissive:16775408,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,19.5,n),r.scale.set(4,.1,4),r};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 l(t,new d({color:0,emissive:14544639,emissiveIntensity:30}));p.position.set(17,10,0),p.scale.set(.1,6,12),this.add(p);const f=new l(t,new d({color:0,emissive:14544639,emissiveIntensity:20}));f.position.set(-17,10,0),f.scale.set(.1,4,8),this.add(f)}}sf.recommendsLogarithmicDepth=!0;class rf extends tf{constructor(){super(),this.name="HomeEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:15261136}),n=new l(t,e);n.position.set(0,8,0),n.scale.set(28,18,24),this.add(n);const i=new a({color:11571312,roughness:.7}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(28,.5,24),this.add(s);const r=new h(16770244,300,25,2);r.position.set(0,14,0),this.add(r);const u=new h(16767152,100,20,2);u.position.set(-8,12,-6),this.add(u);const p=(e,n,i)=>{const s=new d({color:0,emissive:16771280,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,15.5,n),r.scale.set(3,.1,3),r};this.add(p(0,0,40)),this.add(p(-6,-4,25)),this.add(p(6,4,25));const f=new l(t,new d({color:0,emissive:14544639,emissiveIntensity:35}));f.position.set(13.5,8,0),f.scale.set(.1,8,10),this.add(f);const m=new l(t,new d({color:0,emissive:14544639,emissiveIntensity:15}));m.position.set(-13.5,9,3),m.scale.set(.1,5,6),this.add(m)}}rf.recommendsLogarithmicDepth=!0;function of(t,e){t.metalness=e.metalness,t.roughness=e.roughness,t.opacity=e.opacity,t.transparent=e.opacity<1,t.envMapIntensity=e.envMapIntensity,t.polygonOffset=!0,t.polygonOffsetFactor=1,t.polygonOffsetUnits=1}function af(t){const{fillStyle:n,floorMaterial3d:i,placement:s,floor:r}=t.state;if(!1===r)return;const o=Md({...i,preset:i?.preset??"rubber",envMapIntensity:i?.envMapIntensity??0});if("none"===n)return;if("space"===s)return;const a=new e.BoxGeometry(1,1,1);let c;if(n){const i=pu.buildFillStyleTexture(t);if(i){const t="#424b57",n=[new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({color:t}),new e.MeshStandardMaterial({map:i}),new e.MeshStandardMaterial({color:t})];n.forEach(t=>of(t,o)),c=n}else if("string"==typeof n){const t=new e.MeshStandardMaterial({color:n});of(t,o),c=t}}if(!c){const t=new e.MeshStandardMaterial({color:"#e0e0e0"});of(t,o),c=t}const l=new e.Mesh(a,c),{width:h,height:d}=t.state;return l.scale.set(h,d,5),l.rotation.x=-Math.PI/2,l.position.y="inverted"===s?3.5:-3.5,l.name="floor",l.receiveShadow=!1!==i?.receiveShadow,l.castShadow=!0===i?.castShadow,l}const cf={studio:class extends tf{constructor(){super(),this.name="StudioEnvironment",this.position.y=-3.5;const t=new o;t.deleteAttribute("uv");const e=new a({side:c,color:13421772}),n=new l(t,e);n.position.set(0,13,0),n.scale.set(40,30,35),this.add(n);const i=new a({color:11184810,roughness:.8}),s=new l(t,i);s.position.set(0,-1.5,0),s.scale.set(40,.5,35),this.add(s);const r=new h(16777215,500,40,2);r.position.set(0,24,0),this.add(r);const u=new h(16777215,200,30,2);u.position.set(-10,22,-8),this.add(u);const p=new h(16777215,200,30,2);p.position.set(10,22,8),this.add(p);const f=(e,n,i)=>{const s=new d({color:0,emissive:16777215,emissiveIntensity:i}),r=new l(t,s);return r.position.set(e,26,n),r.scale.set(6,.1,6),r};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:ef,factory:nf,office:sf,home:rf,sunny:class extends tf{constructor(){super(),this.name="SunnyEnvironment";const t=new k;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=2,e.rayleigh.value=1.5,e.mieCoefficient.value=.005,e.mieDirectionalG.value=.8;const n=u.degToRad(60),i=u.degToRad(135),s=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,s,i),this.add(t)}},cloudy:class extends tf{constructor(){super(),this.name="CloudyEnvironment";const t=new k;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=10,e.rayleigh.value=.3,e.mieCoefficient.value=.03,e.mieDirectionalG.value=.7;const n=u.degToRad(50),i=u.degToRad(120),s=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,s,i),this.add(t)}},rainy:class extends tf{constructor(){super(),this.name="RainyEnvironment";const t=new k;t.scale.setScalar(1e3);const e=t.material.uniforms;e.turbidity.value=20,e.rayleigh.value=.1,e.mieCoefficient.value=.05,e.mieDirectionalG.value=.6;const n=u.degToRad(40),i=u.degToRad(110),s=Math.PI/2-n;e.sunPosition.value.setFromSphericalCoords(1,s,i),this.add(t)}}};function lf(t){if(!t||!(t in cf))return!1;return!0===cf[t].recommendsLogarithmicDepth}class hf{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}_makeEnvTexture(t){if(!this._renderer)return;const n=new(0,cf[t]),i=new e.PMREMGenerator(this._renderer),s=i.fromScene(n).texture;return n.dispose(),i.dispose(),s}_applyEnvironment(t){this._clearEnvironment(),this._renderer&&this._scene&&(this._envTexture=this._makeEnvTexture(t),this._scene.environment=this._envTexture??null)}_clearEnvironment(){this._envTexture&&(this._envTexture.dispose(),this._envTexture=void 0),this._scene&&(this._scene.environment=null)}_clearBackgroundTexture(){this._bgTexture&&(this._bgTexture.dispose(),this._bgTexture=void 0)}get hasEnvironment(){return!!this._scene?.environment}setSky(t,n,i){if(!this._scene||!this._renderer)return;const s=t,r=!!s&&s in cf,o=i;if(void 0===i||""===i?r?this._applyEnvironment(s):this._clearEnvironment():"none"===i?this._clearEnvironment():o in cf?this._applyEnvironment(o):(console.warn(`[things-scene] 모르는 environment 프리셋: '${i}'. 쓸 수 있는 것 — ${Object.keys(cf).join(", ")}, none`),r?this._applyEnvironment(s):this._clearEnvironment()),this._clearBackgroundTexture(),r){this._envTexture&&(void 0===i||""===i||i===t)?this._scene.background=this._envTexture:(this._bgTexture=this._makeEnvTexture(s),this._scene.background=this._bgTexture??null)}else this._scene.background="color"===t&&n?new e.Color(n):null}addFloor(t){const e=af(t);e&&this._scene.add(e)}updateFloor(t){if(!this._scene)return;const e=this._scene.children.find(t=>"floor"===t.name);e&&(eu(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._bgTexture&&(this._bgTexture.dispose(),delete this._bgTexture),this._scene&&(this._scene.environment=null,this._scene.background=null,eu(this._scene),this._scene.clear()),delete this._scene,delete this._mixer,delete this._renderer,this._timer&&this._timer.disconnect(),delete this._timer}}class df{constructor(){this._activeView="perspective",this._cameraZPos=0}get camera(){return this._perspCamera}get activeCamera(){return"perspective"!==this._activeView&&this._orthoCamera?this._orthoCamera:this._perspCamera}get activeView(){return this._activeView}get cameraZPos(){return this._cameraZPos}setup(t,n,i){const{fov:s,near:r,far:o,cameraX:a,cameraY:c,cameraZ:l}=i,h=t/n;this._perspCamera=new e.PerspectiveCamera(s,h,r,o);const d=Math.sqrt(t*t+n*n),u=(s||45)/2*Math.PI/180,p=d/2/Math.tan(u)*.75,f=25*Math.PI/180,m=30*Math.PI/180,g=p*Math.sin(f),y=p*Math.cos(f);let b=y*Math.sin(m),_=y*Math.cos(m);return this._cameraZPos=Math.floor(g),null!=a&&(b=a*t),null!=c&&(_=c*n),null!=l&&(this._cameraZPos=l*Math.floor(Math.min(t,n))),this._perspCamera.position.set(b,this._cameraZPos,_),this._activeView="perspective",this._perspCamera}addToScene(t){t.add(this._perspCamera),this._perspCamera.lookAt(t.position)}updateAspect(t,e){if(this._perspCamera&&(this._perspCamera.aspect=t/e,this._perspCamera.updateProjectionMatrix()),this._orthoCamera){const n=this._orthoCamera,i=(n.top-n.bottom)/2,s=t/e;n.left=-i*s,n.right=i*s,n.updateProjectionMatrix()}}updateProperties(t){this._perspCamera&&(void 0!==t.fov&&(this._perspCamera.fov=t.fov),void 0!==t.near&&(this._perspCamera.near=t.near),void 0!==t.far&&(this._perspCamera.far=t.far),this._perspCamera.updateProjectionMatrix())}setOrthoView(t,n,i,s,r){this._orthoCamera||(this._orthoCamera=new e.OrthographicCamera(-1,1,1,-1,.1,5e4)),this.updateOrthoFrustum(n,i,s,r);const o=this._orthoCamera;o.zoom=1;const a=2*Math.max(n,i);switch(t){case"top":o.position.set(0,a,0),o.up.set(0,0,-1);break;case"front":o.position.set(0,0,a),o.up.set(0,1,0);break;case"back":o.position.set(0,0,-a),o.up.set(0,1,0);break;case"right":o.position.set(a,0,0),o.up.set(0,1,0);break;case"left":o.position.set(-a,0,0),o.up.set(0,1,0)}return o.lookAt(0,0,0),o.updateProjectionMatrix(),this._activeView=t,o}restorePerspective(){return this._activeView="perspective",this._perspCamera}updateOrthoFrustum(t,e,n,i){if(!this._orthoCamera)return;const s=(n||t)/(i||e),r=Math.max(t,e)/2;s>=1?(this._orthoCamera.left=-r*s,this._orthoCamera.right=r*s,this._orthoCamera.top=r,this._orthoCamera.bottom=-r):(this._orthoCamera.left=-r,this._orthoCamera.right=r,this._orthoCamera.top=r/s,this._orthoCamera.bottom=-r/s),this._orthoCamera.updateProjectionMatrix()}destroy(){delete this._perspCamera,delete this._orthoCamera,this._activeView="perspective"}}class uf{constructor(){this._noSupportWebgl=!1}get renderer(){return this._renderer}setExposure(t){this._renderer&&(this._renderer.toneMappingExposure=t)}get css3DRenderer(){return this._css3DRenderer||(this._css3DRenderer=this.createCSS3DRenderer()),this._css3DRenderer}get css3DScene(){return this._css3DScene||(this._css3DScene=new e.Scene),this._css3DScene}get composer(){return this._composer}get noSupportWebgl(){return this._noSupportWebgl}get domElement(){return this._renderer?.domElement}get hudScene(){return this._hudScene||(this._hudScene=new e.Scene),this._hudScene}get hudCSS3DScene(){return this._hudCSS3DScene||(this._hudCSS3DScene=new e.Scene),this._hudCSS3DScene}get hudCamera(){return this._hudCamera}setupHUD(t,n){this._hudCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCamera.position.set(0,5e3,0),this._hudCamera.lookAt(0,0,0),this._hudCSS3DCamera=new e.OrthographicCamera(-t/2,t/2,n/2,-n/2,.1,1e4),this._hudCSS3DCamera.position.set(0,0,1e3),this._hudCSS3DCamera.lookAt(0,0,0),this._hudCSS3DRenderer=new x,this._hudCSS3DRenderer.setSize(t,n);const i=this._hudCSS3DRenderer.domElement;i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.pointerEvents="none",i.setAttribute("scene","model-layer:css3d-hud-renderer");const s=new e.AmbientLight(16777215,3);this.hudScene.add(s);const r=new Float32Array(64).fill(1),o=new e.DataTexture(r,4,4,e.RGBAFormat,e.FloatType);o.mapping=e.EquirectangularReflectionMapping,o.needsUpdate=!0,this.hudScene.environment=o}resizeHUD(t,e){this._hudCamera&&(this._hudCamera.right=t,this._hudCamera.bottom=-e,this._hudCamera.updateProjectionMatrix())}setupWebGL(t,n,i){try{const s=document.createElement("canvas"),r=s.getContext("webgl2");if(!r)return this._noSupportWebgl=!0,!1;const o=new e.WebGLRenderer({canvas:s,context:r,precision:i.precision,alpha:!0,antialias:i.antialias,logarithmicDepthBuffer:i.logarithmicDepthBuffer??!1!==i.postprocessing,premultipliedAlpha:!1});return o.autoClear=!0,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.ACESFilmicToneMapping,o.toneMappingExposure=i.exposure,o.shadowMap.enabled=!1!==i.shadowMap,o.shadowMap.type=e.PCFShadowMap,o.setClearColor(16777215,1),o.setPixelRatio(void 0===i.pixelRatio?window.devicePixelRatio:Math.max(.5,Math.min(3,i.pixelRatio))),o.setSize(t,n,!1),s.style.width="100%",s.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 x}setupComposer(t,n,i,s,r){const o=new e.WebGLRenderTarget(i,s,{samples:4});this._composer=new A(this._renderer,o),this._composer.setSize(i,s);const a=new E(t,n);this._composer.addPass(a);const c=new C(new e.Vector2(i,s),t,n);if(c.visibleEdgeColor.set(15885602),c.hiddenEdgeColor.set(16755268),c.edgeStrength=6,c.edgeThickness=3,c.edgeGlow=1,c.pulsePeriod=0,r){const t=c.render.bind(c);c.render=(e,n,i,s,o)=>{const a=r.visible;r.visible=!1,t(e,n,i,s,o),r.visible=a}}return this._outlinePass=c,this._composer.addPass(c),this._composer.addPass(new P),this._composer.addPass(new T),this._composer}setupLightComposer(t,n,i,s){const r=new e.WebGLRenderTarget(i,s);this._composer=new A(this._renderer,r),this._composer.setSize(i,s),this._composer.addPass(new E(t,n));const o=new C(new e.Vector2(i,s),t,n);return o.visibleEdgeColor.set(15885602),o.hiddenEdgeColor.set(16755268),o.edgeStrength=6,o.edgeThickness=3,o.edgeGlow=1,o.pulsePeriod=0,this._outlinePass=o,this._composer.addPass(o),this._composer.addPass(new T),this._composer}get hasOutlinePass(){return!!this._outlinePass}updateRenderPassCamera(t){this._composer&&this._composer.passes.length>0&&(this._composer.passes[0].camera=t),this._outlinePass&&(this._outlinePass.renderCamera=t),this._camera&&(this._camera=t)}setOutlineObjects(t){this._outlinePass&&(this._outlinePass.selectedObjects=t)}setOutlineColor(t){this._outlinePass&&(this._outlinePass.visibleEdgeColor.set(t),this._outlinePass.hiddenEdgeColor.set(t))}resize(t,e){if(this._renderer?.setSize(t,e,!1),this._css3DRenderer?.setSize(t,e),this._composer?.setSize(t,e),this._hudCSS3DRenderer&&this._hudCSS3DCamera){const n=t/(this._hudCSS3DCamera.right-this._hudCSS3DCamera.left),i=e/(this._hudCSS3DCamera.top-this._hudCSS3DCamera.bottom),s=this._hudCSS3DRenderer.domElement;s.style.transformOrigin="0 0",s.style.transform=`scale(${n}, ${i})`}}teardownLightComposer(){this._composer&&(this._outlinePass=void 0,this._composer.dispose(),this._composer=void 0)}setDirectRenderTargets(t,e){this._scene=t,this._camera=e}render(){if(this._composer){if(this._composer.render(),this._renderer){const t=this._renderer.getContext();t.colorMask(!1,!1,!1,!0),t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.colorMask(!0,!0,!0,!0)}}else this._renderer&&this._scene&&this._camera&&this._renderer.render(this._scene,this._camera);this.renderHUD()}renderHUD(){if(!this._renderer||!this._hudScene||!this._hudCamera)return;if(0===this._hudScene.children.length)return;const t=this._renderer.autoClear;this._renderer.autoClear=!1,this._renderer.setRenderTarget(null),this._renderer.clearDepth(),this._renderer.render(this._hudScene,this._hudCamera),this._renderer.autoClear=t}renderCSS3D(t){if(this._css3DRenderer?.render(this.css3DScene,t),this._hudCSS3DRenderer&&this._hudCSS3DCamera&&this._hudCSS3DScene){const t=this._hudCSS3DRenderer.domElement;this._hudCSS3DScene.children.length>0?(t.style.display="",this._hudCSS3DRenderer.render(this._hudCSS3DScene,this._hudCSS3DCamera)):t.style.display="none"}}get hudCSS3DRenderer(){return this._hudCSS3DRenderer}getSize(){const t=new e.Vector2;return this._renderer?.getSize(t),{width:t.x,height:t.y}}destroy(){this._outlinePass=void 0,this._composer?.dispose(),this._renderer?.forceContextLoss(),this._renderer?.dispose(),delete this._composer,delete this._renderer,this.disposeHUD()}disposeHUD(){if(this._hudScene){[...this._hudScene.children].forEach(t=>{if(this._hudScene.remove(t),t.geometry&&t.geometry.dispose(),t.material){const e=t.material;e.map&&e.map.dispose(),e.dispose()}}),this._hudScene.environment&&(this._hudScene.environment.dispose(),this._hudScene.environment=null),this._hudScene=void 0}if(this._hudCamera=void 0,this._hudCSS3DScene){[...this._hudCSS3DScene.children].forEach(t=>this._hudCSS3DScene.remove(t)),this._hudCSS3DScene=void 0}this._hudCSS3DRenderer&&(this._hudCSS3DRenderer.domElement.remove(),this._hudCSS3DRenderer=void 0),this._hudCSS3DCamera=void 0}disposeCSS3DScene(){if(this._css3DScene){[...this._css3DScene.children].forEach(t=>this._css3DScene.remove(t))}}}class pf{constructor(){this.lights=[]}get hemiLight(){return this._hemiLight}get dirLight(){return this._dirLight}setup(t,n,i){this._scene=t,this._camera=n;const{hemisphere:s,directional:r,point:o}=i;if(this._hemiLight=new e.HemisphereLight(s.skyColor,s.groundColor,s.intensity),t.add(this._hemiLight),this.lights.push(this._hemiLight),r){if(this._dirLight=new e.DirectionalLight(r.color,r.intensity),r.position&&this._dirLight.position.set(...r.position),!1!==r.castShadow){this._dirLight.castShadow=!0;const t=r.shadowMapSize??2048;this._dirLight.shadow.mapSize.set(t,t),this._dirLight.shadow.bias=r.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}r.attachToCamera?n.add(this._dirLight):t.add(this._dirLight),this.lights.push(this._dirLight)}if(o){const n=new e.PointLight(o.color,o.intensity,void 0,o.decay);n.power=o.power,n.castShadow=o.castShadow,n.position.set(...o.position),n.shadow.camera.near=o.shadowNear,n.shadow.camera.far=o.shadowFar,t.add(n),this.lights.push(n)}}updateHemisphere(t){this._hemiLight&&(void 0!==t.skyColor&&this._hemiLight.color.set(t.skyColor),void 0!==t.groundColor&&this._hemiLight.groundColor.set(t.groundColor),void 0!==t.intensity&&(this._hemiLight.intensity=t.intensity))}updateDirectional(t){this._dirLight&&(void 0!==t.color&&this._dirLight.color.set(t.color),void 0!==t.intensity&&(this._dirLight.intensity=t.intensity))}setDirectionalFollowCamera(t){this._dirLight&&this._scene&&this._camera&&(this._dirLight.removeFromParent(),t?this._camera.add(this._dirLight):this._scene.add(this._dirLight))}setDirectionalAngle(t,e,n=1e3){if(!this._dirLight)return;const i=t*Math.PI/180,s=e*Math.PI/180,r=n;this._dirLight.position.set(r*Math.cos(s)*Math.sin(i),r*Math.sin(s),r*Math.cos(s)*Math.cos(i)),this._dirLight.target.position.set(0,0,0),!this._dirLight.target.parent&&this._scene&&this._scene.add(this._dirLight.target)}setDirectionalEnabled(t,n){if(t&&!this._dirLight&&this._camera){const t=n?.color??16777215,i=n?.intensity??2;this._dirLight=new e.DirectionalLight(t,i),this._camera.add(this._dirLight),this.lights.push(this._dirLight)}else!t&&this._dirLight&&(this._dirLight.removeFromParent(),this._dirLight.dispose(),this.lights=this.lights.filter(t=>t!==this._dirLight),this._dirLight=void 0)}destroy(){this.lights.forEach(t=>t.dispose()),this.lights=[],this._hemiLight=void 0,this._dirLight=void 0,this._scene=void 0,this._camera=void 0}}const ff=1e-6;class mf{constructor(){this._enabled=!0,this._state=0,this._autoRotate=!1,this._autoRotateSpeed=2,this._dampingFactor=.15,this._rotateSpeed=.1,this._panSpeed=1,this._dollyStart=0,this._lastScale=1,this._floorConstraint=!1,this._spherical=new e.Spherical,this._sphericalDelta=new e.Spherical,this._panOffset=new e.Vector3,this._target=new e.Vector3,this._target0=new e.Vector3,this._position0=new e.Vector3,this._rotateStart=new e.Vector2,this._rotateEnd=new e.Vector2,this._rotateDelta=new e.Vector2,this._panStart=new e.Vector2,this._panEnd=new e.Vector2,this._panDelta=new e.Vector2,this._offset=new e.Vector3,this._lastPosition=new e.Vector3,this._lastQuaternion=new e.Quaternion,this._panLeftV=new e.Vector3,this._panUpV=new e.Vector3,this._panCalcOffset=new e.Vector3}get isActive(){return!!this._camera}get target(){return this._target.clone()}restoreTarget(t){this._target.copy(t),this.update()}get _isOrthoLocked(){return!!this._camera?.isOrthographicCamera}setup(t,n){this._camera=t,this._host=n,this._target.set(0,0,0),this._target0.copy(this._target),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert();const i=n.state;this._autoRotate=!n.app?.isEditMode&&(i.autoRotate||"orbit"===i.cameraAutoPlay)||!1,this._autoRotateSpeed=i.rotationSpeed||2,this._floorConstraint=!n.app?.isEditMode&&!!i.cameraFloorConstraint||!1,this.update()}setEnabled(t){this._enabled=t}setOnUserInteraction(t){this._onUserInteraction=t}onDragStart(t){this._enabled&&(this._onUserInteraction?.(),this._isOrthoLocked?(this._state=2,this._panStart.set(t.offsetX,t.offsetY)):(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,1===this._state?this._rotateStart.set(t.offsetX,t.offsetY):3===this._state?this._dollyStart=t.offsetY:this._panStart.set(t.offsetX,t.offsetY)))}onDragMove(t){if(this._enabled)if(this._isOrthoLocked)this._state=2,this._handlePanMove(t.offsetX,t.offsetY);else if(this._state=t.altKey?2:t.ctrlKey||t.metaKey?3:1,3===this._state){const e=t.offsetY-this._dollyStart;this._dollyStart=t.offsetY;const n=1+.005*e;this.dollyAtCursor(n,0,0)}else 1===this._state?this._handleRotateMove(t.offsetX,t.offsetY):this._handlePanMove(t.offsetX,t.offsetY)}onDragEnd(t){this._state=0,this._host?.invalidate()}onTouchStart(t){this._onUserInteraction?.();const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)return this._panStart.set(n,i),void(this._state=5);switch(t.touches.length){case 1:this._rotateStart.set(n,i),this._state=4;break;case 2:this._lastScale=t.scale||1,this._panStart.set(n,i),this._state=5;break;default:this._state=0}}onTouchMove(t){const e=t.touches[0],n=e.offsetX??e.pageX,i=e.offsetY??e.pageY;if(this._isOrthoLocked)this._handlePanMove(n,i);else switch(t.touches.length){case 1:if(4!==this._state)return;this._handleRotateMove(n,i);break;case 2:{if(5!==this._state)return;const e=t.scale||1;if(Math.abs(this._lastScale-e)>.01){const t=this._lastScale/e;this._lastScale=e,this.dollyAtCursor(t,0,0)}else this._handlePanMove(n,i);break}default:this._state=0}}onTouchEnd(t){this._lastScale=1,this._state=0}onKeyDown(t){switch(t.code){case"ArrowUp":this._pan(0,7);break;case"ArrowDown":this._pan(0,-7);break;case"ArrowLeft":this._pan(7,0);break;case"ArrowRight":this._pan(-7,0);break;default:return}this.update()}update(){const t=this._camera,e=t.position;if(this._isOrthoLocked)return this._panOffset.lengthSq()>0&&(this._target.add(this._panOffset),e.add(this._panOffset),this._panOffset.set(0,0,0)),(this._lastPosition.distanceToSquared(e)>ff||8*(1-this._lastQuaternion.dot(t.quaternion))>ff)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0);if(this._offset.copy(e).sub(this._target),this._offset.applyQuaternion(this._quat),this._spherical.setFromVector3(this._offset),this._spherical.theta+=this._sphericalDelta.theta,this._autoRotate&&0===this._state){const t=2*Math.PI/60*(this._autoRotateSpeed/60);this._spherical.theta-=t}this._spherical.phi+=this._sphericalDelta.phi,this._spherical.phi=Math.max(0,Math.min(Math.PI,this._spherical.phi)),this._spherical.makeSafe(),this._target.add(this._panOffset),this._offset.setFromSpherical(this._spherical),this._offset.applyQuaternion(this._quatInverse),e.copy(this._target).add(this._offset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),e.y<0&&(e.y=0)),t.lookAt(this._target);const n=1-this._dampingFactor;return this._sphericalDelta.theta*=n,this._sphericalDelta.phi*=n,this._panOffset.set(0,0,0),(this._lastPosition.distanceToSquared(e)>ff||8*(1-this._lastQuaternion.dot(t.quaternion))>ff)&&(this._lastPosition.copy(e),this._lastQuaternion.copy(t.quaternion),this._host?.invalidate(),!0)}reset(){this._target.copy(this._target0),this._camera.position.copy(this._position0),this._camera.updateProjectionMatrix(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._state=0,this.update()}pinResetPosition(){this._camera&&(this._position0.copy(this._camera.position),this._target0.copy(this._target))}setCamera(t){this._camera=t,this._target.set(0,0,0),this._position0.copy(t.position),this._quat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0),this._lastPosition.copy(t.position),this._lastQuaternion.copy(t.quaternion),this._state=0,t.updateMatrixWorld(!0)}isAutoRotating(){return this._autoRotate}setAutoRotate(t){this._autoRotate=t,this._host?.invalidate()}setFloorConstraint(t){this._floorConstraint=t,this.update()}markCameraChanged(){this._host?.invalidate()}dollyAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,s=i.position.distanceTo(this._target),r=Math.max(1,Math.min(5e4,s*t));if(Math.abs(r-s)<ff)return;const o=Math.tan(i.fov/2*Math.PI/180)/i.zoom,a=s-r,c=e*a*o*i.aspect,l=n*a*o;this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(c),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(l),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),this._panCalcOffset.subVectors(i.position,this._target).normalize().multiplyScalar(r),i.position.copy(this._target).add(this._panCalcOffset),this._floorConstraint&&(this._target.y<0&&(this._target.y=0),i.position.y<0&&(i.position.y=0)),this._host?.invalidate()}zoomOrthoAtCursor(t,e,n){this._onUserInteraction?.();const i=this._camera,s=i.zoom,r=Math.max(.1,Math.min(20,s*t)),o=e*(i.right-i.left)/2*(1/s-1/r),a=n*(i.top-i.bottom)/2*(1/s-1/r);this._panLeftV.setFromMatrixColumn(i.matrix,0).multiplyScalar(o),this._panUpV.setFromMatrixColumn(i.matrix,1).multiplyScalar(a),this._target.add(this._panLeftV).add(this._panUpV),i.position.add(this._panLeftV).add(this._panUpV),i.zoom=r,i.updateProjectionMatrix(),this._host?.invalidate()}destroy(){delete this._camera,delete this._host}_getViewportSize(){const t=this._host;if(!t)return{width:1,height:1};const e=t?.element;if(e){const t=e.getBoundingClientRect();if(t.width>0&&t.height>0)return{width:t.width,height:t.height}}const n=t.bounds;return{width:Math.abs(n?.width)||1,height:Math.abs(n?.height)||1}}_handleRotateMove(t,e){this._rotateEnd.set(t,e),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart);const{width:n,height:i}=this._getViewportSize();this._sphericalDelta.theta-=2*Math.PI*this._rotateDelta.x/n*this._rotateSpeed,this._sphericalDelta.phi-=2*Math.PI*this._rotateDelta.y/i*this._rotateSpeed,this._rotateStart.copy(this._rotateEnd),this._host?.invalidate()}_handlePanMove(t,e){this._panEnd.set(t,e),this._panDelta.subVectors(this._panEnd,this._panStart),this._isOrthoLocked?this._panOrtho(this._panDelta.x,this._panDelta.y):this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this._host?.invalidate()}_panOrtho(t,e){const n=this._camera,{width:i,height:s}=this._getViewportSize();this._panLeftV.setFromMatrixColumn(n.matrix,0),this._panLeftV.multiplyScalar(-t*(n.right-n.left)/n.zoom/i),this._panUpV.setFromMatrixColumn(n.matrix,1),this._panUpV.multiplyScalar(e*(n.top-n.bottom)/n.zoom/s),this._target.add(this._panLeftV).add(this._panUpV),n.position.add(this._panLeftV).add(this._panUpV)}panByPixels(t,e){this._onUserInteraction?.(),this._pan(t,e),this._target.add(this._panOffset),this._camera.position.add(this._panOffset),this._panOffset.set(0,0,0),this._host?.invalidate()}_pan(t,e){t*=this._panSpeed,e*=this._panSpeed;const{width:n,height:i}=this._getViewportSize(),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/n),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 gf{constructor(){this._mouse=new e.Vector2,this._raycaster=new e.Raycaster}get mouse(){return this._mouse}get lastFocused(){return this._lastFocused}set lastFocused(t){this._lastFocused=t}get lastHovered(){return this._lastHovered}set lastHovered(t){this._lastHovered=t}updateMouseNDC(t,e,n,i,s,r){this._mouse.x=(t-n)/s*2-1,this._mouse.y=-(e-i)/r*2+1}getObjectByRaycast(t,e){this._lastHit=void 0;const n=this.getObjectsByRaycast(t,e);if(n&&n.length>0)for(const t of n){if(!this._isWorldVisible(t.object))continue;const e=!!t.object.userData?.alwaysRaycast;let n=t.object;for(;n;){if(n.userData.context){const i=n.userData.context.component;if(!e&&i&&!1===i.capturable)break;return this._lastHit=t.object,n}n=n.parent}}}_isWorldVisible(t){let e=t;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}getObjectsByRaycast(t,e){return this._raycaster.setFromCamera(this._mouse,t),this._raycaster.intersectObjects(e.children,!0)}setHUD(t,e){this._hudScene=t,this._hudCamera=e}handleClick(t,e,n){let i;this._lastFocused&&(this._lastFocused.focused=!1),this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const s=i?.userData.context;return s&&(s.focused=!0,this._lastFocused=s,this._lastHit&&fu(s)&&(s.pickedPart=s.partAt(this._lastHit)),s.component?.trigger("click",n)),s}handleHover(t,e,n){let i;this._hudScene&&this._hudCamera&&(i=this.getObjectByRaycast(this._hudCamera,this._hudScene)),i||(i=this.getObjectByRaycast(t,e));const s=i?.userData.context;s!==this._lastHovered&&(this._lastHovered&&(this._lastHovered.component?.trigger("mouseleave",n),this._lastHovered=void 0),s&&(this._lastHovered=s,this._lastHovered.component?.trigger("mouseenter",n)))}clearHoverIfUnpickable(){const t=this._lastHovered?.component;t&&!1===t.capturable&&(this._lastHovered?.component?.trigger("mouseleave"),this._lastHovered=void 0)}destroy(){this._lastFocused=void 0,this._lastHovered=void 0,this._hudScene=void 0,this._hudCamera=void 0}}const yf=Math.PI/180*15;class bf{constructor(){this._mode="translate",this._isDragging=!1}get controls(){return this._controls}get mode(){return this._mode}get attached(){return this._attached}get isAttached(){return!!this._attached}get isDragging(){return this._isDragging}get isEngaged(){return!!this._controls?.axis}setup(t,e,n){this.destroy(),this._scene=n;const i=document.createElement("div");i.style.cssText="position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none",i.setPointerCapture=()=>{},i.releasePointerCapture=()=>{},e.appendChild(i),this._proxyElement=i,this._controls=new O(t,i),this._controls.setMode(this._mode),n.add(this._controls.getHelper()),this._controls.addEventListener("dragging-changed",t=>{this._isDragging=t.value,this.onDraggingChanged?.(t.value)}),this._controls.addEventListener("change",()=>{this._attached&&this.onObjectChange?.(this._attached)})}forwardEvent(t,e){if(!this._proxyElement||!this._controls)return;"rotate"===this._mode&&this._controls.setRotationSnap(t.shiftKey?yf:null);const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:t.button??0,pointerId:1,pointerType:"mouse",bubbles:!0});this._proxyElement.dispatchEvent(n)}forwardTouch(t,e){if(!this._proxyElement||!this._controls)return;const n=new PointerEvent(e,{clientX:t.clientX,clientY:t.clientY,button:"pointermove"===e?-1:0,pointerId:t.identifier+10,pointerType:"touch",bubbles:!0});this._proxyElement.dispatchEvent(n)}setMode(t){this._mode=t,this._controls?.setMode(t)}attach(t){this._attached=t,this._controls?.attach(t),this._controls?.getHelper().updateMatrixWorld(!0),this.onAttachChanged?.(!0)}detach(){this._controls?.detach(),this._attached=void 0,this.onAttachChanged?.(!1)}setRotationSnap(t){this._controls&&this._controls.setRotationSnap(t?yf:null)}updateCamera(t){this._controls&&(this._controls.camera=t)}destroy(){this._controls&&(this._controls.detach(),this._controls.dispose(),this._scene&&this._scene.remove(this._controls.getHelper()),this._controls=void 0),this._proxyElement?.parentNode&&this._proxyElement.parentNode.removeChild(this._proxyElement),this._proxyElement=void 0,this._attached=void 0,this._isDragging=!1}}const _f=.01;function vf(t){const[e,n,i]=t,s=Math.abs(e-1),r=Math.abs(n-1),o=Math.abs(i-1);return s<_f&&r<_f&&o<_f?null:s>=r&&s>=o?e:r>=s&&r>=o?n:i}class xf{constructor(){this._mouseDownAltKey=!1}captureAltKey(t){this._mouseDownAltKey=t}setupCallbacks(t,e,n,i){t.onDraggingChanged=s=>{e.setEnabled(!s);const r=n();r&&(i?.onDraggingChanged?.(s),s?(this._onDragStart(t,r),r.hostElement&&this._showInfoOverlay(r.hostElement)):(this._hideInfoOverlay(),this._onDragEnd(t,r)),r.app?.commander?.execute(null),r.invalidate())},t.onObjectChange=e=>{if(this._syncFromGizmo(t,e),this._infoOverlay){const n=t.controls?.axis??null;this._updateInfoOverlay(t.mode,e,n)}n()?.invalidate()},t.onAttachChanged=t=>{i?.onAttachChanged?.(t)}}_onDragStart(t,e){this._mouseDownAltKey&&"translate"===t.mode&&this._performAltDragDuplicate(e);const n=e.root?.selected||[];n.length>1&&this._captureMultiSelectState(t,n);const i=t.attached;i&&("rotate"!==t.mode||this._gizmoInitialRotation?"translate"!==t.mode||this._dragStartPosition||(this._dragStartPosition=i.position.clone()):this._gizmoInitialRotation=i.rotation.clone()),"scale"===t.mode&&this._captureScalePreDrag(t)}_performAltDragDuplicate(t){const e=t.root?.selected||[];if(0===e.length||!t.root)return;const n=t.root,i=[];for(const t of e){const e=t.parent,s=new Map,r=Il(t,t=>{const e=n.getNewRefid();return void 0!==t&&s.set(t,e),e});r.replaceRefids(s),e.addComponent(r),i.push({component:r,to_container:e})}this._altDragDuplicates=i}_captureMultiSelectState(t,e){const n=t.attached;if(n)if("translate"===t.mode){const t=new Map,i=n.position;for(let n=1;n<e.length;n++){const s=e[n]._realObject;s?.object3d&&s.gizmoTransformable&&t.set(s,s.object3d.position.clone().sub(i))}this._multiSelectOffsets=t}else if("rotate"===t.mode){this._gizmoInitialRotation=n.rotation.clone();const t=new Map;for(let n=1;n<e.length;n++){const i=e[n]._realObject;i?.object3d&&i.gizmoTransformable&&t.set(i,i.object3d.rotation.clone())}this._multiSelectInitialRotations=t}else if("scale"===t.mode){const t=new Map;for(let n=1;n<e.length;n++){const i=e[n],s=i._realObject;if(s?.object3d&&s.gizmoTransformable){const{left:e,top:n,width:r,height:o}=i.bounds,{zPos:a=0}=i.state,c=i.state.depth;t.set(s,{left:e,top:n,width:r,height:o,depth:c,zPos:a,scaleX:s.object3d.scale.x,scaleY:s.object3d.scale.y,scaleZ:s.object3d.scale.z})}}this._multiSelectPreDragDimensions=t}}_captureScalePreDrag(t){const e=t.attached,n=e?.userData.context;if(!n||!e)return;const{left:i,top:s,width:r,height:o}=n.component.bounds,{zPos:a=0}=n.component.state,c=n.component.state.depth??n.effectiveDepth;this._preDragDimension={left:i,top:s,width:r,height:o,depth:c,zPos:a},this._preDragScale={x:e.scale.x,y:e.scale.y,z:e.scale.z},this._preDragEffectiveDepth=void 0,this._scaleAnchorSign=this._computeAnchorSign(t,e),this._preDragAttachedPosition=e.position.clone()}_computeAnchorSign(t,n){const i=t.controls;if(!i)return{x:0,y:0,z:0};const s=i.axis;if(!s||"XYZE"===s)return{x:0,y:0,z:0};if(s.includes("X")&&s.includes("Y")&&s.includes("Z"))return{x:0,y:0,z:0};const r=new e.Quaternion;n.getWorldQuaternion(r),r.invert();const o=i.pointStart.clone().applyQuaternion(r),a=.001,c={x:0,y:0,z:0};return s.includes("X")&&Math.abs(o.x)>a&&(c.x=Math.sign(o.x)),s.includes("Y")&&Math.abs(o.y)>a&&(c.y=Math.sign(o.y)),s.includes("Z")&&Math.abs(o.z)>a&&(c.z=Math.sign(o.z)),c}_onDragEnd(t,e){if(this._altDragDuplicates&&this._altDragDuplicates.length>0&&(e.app?.commander.execute(new Ol({changes:this._altDragDuplicates})),this._altDragDuplicates=void 0),this._multiSelectOffsets=void 0,this._gizmoInitialRotation=void 0,this._multiSelectInitialRotations=void 0,this._dragStartPosition=void 0,this._preDragDimension){const e=t.attached,n=e?.userData.context;if(n&&(void 0!==this._preDragEffectiveDepth&&n.applyDimensionFromGizmo({depth:this._preDragEffectiveDepth}),n.update()),this._multiSelectPreDragDimensions)for(const[t]of this._multiSelectPreDragDimensions)t.update()}const n=e.root?.selected||[];for(const e of n){const n=e._realObject;n?.onGizmoDragEnd(t.mode)}for(const t of n){let e=t.parent;for(;e?.isGroup?.();){const t=[];e._realObject&&t.push(e._realObject);for(const n of e.components||[])n._realObject&&t.push(n._realObject);for(const e of t)e._suppressOnchange=!0;e.calculateBounds();for(const e of t)e._suppressOnchange=!1,e.updateTransform();e=e.parent}}this._preDragDimension=void 0,this._preDragScale=void 0,this._preDragEffectiveDepth=void 0,this._multiSelectPreDragDimensions=void 0,this._scaleAnchorSign=void 0,this._preDragAttachedPosition=void 0}_syncPartFromGizmo(t){for(let e=t.parent;e;e=e.parent){const n=e.userData?.context;if(n){if(fu(n)){const e=n.partAt(t);e&&n.partMoved?.(e,t)}return}}}_syncFromGizmo(t,e){const n=e.userData.context;if(n)if("scale"===t.mode&&this._preDragDimension&&this._preDragScale){const{ratioX:t,ratioY:i,ratioZ:s,sign:r}=this._syncDimensionFromGizmo(n,e);if(this._multiSelectPreDragDimensions)for(const[e,n]of this._multiSelectPreDragDimensions)e.applyDimensionFromGizmo(this._computeAnchorProps(n,t,i,s,r))}else{if(n.syncFromObject3D(),"translate"===t.mode&&this._applyGroundSnap(e,n),this._multiSelectOffsets){const n=e.position;for(const[e,i]of this._multiSelectOffsets)e.object3d&&(e.object3d.position.copy(n).add(i),"translate"===t.mode&&this._applyGroundSnap(e.object3d,e),e.syncFromObject3D())}if(this._multiSelectInitialRotations&&this._gizmoInitialRotation){const t=e.rotation.x-this._gizmoInitialRotation.x,n=e.rotation.y-this._gizmoInitialRotation.y,i=e.rotation.z-this._gizmoInitialRotation.z;for(const[e,s]of this._multiSelectInitialRotations)e.object3d&&(e.object3d.rotation.set(s.x+t,s.y+n,s.z+i),e.syncFromObject3D())}}else this._syncPartFromGizmo(e)}_applyGroundSnap(t,e){const n=e.effectiveDepth/2,i=t.position.y-n,s=Math.abs(i);if(s<2)t.position.y=n,e.syncFromObject3D();else if(s<10){const r=(s-2)/8,o=1-r*r;t.position.y=n+i*(1-o),e.syncFromObject3D()}}_syncDimensionFromGizmo(t,e){const n=this._preDragDimension,i=this._preDragScale;let s={...this._scaleAnchorSign??{x:0,y:0,z:0}},r=e.scale.x/i.x,o=e.scale.y/i.y,a=e.scale.z/i.z;if(t.component.state.ratioLock){const t=vf([r,o,a]);if(t){r=o=a=t,e.scale.set(t*i.x,t*i.y,t*i.z);const n=s.x||s.y||s.z;n&&(s={x:n,y:n,z:n})}}return t.applyDimensionFromGizmo(this._computeAnchorProps(n,r,o,a,s)),!this._preDragAttachedPosition||0===s.x&&0===s.y&&0===s.z||this._applyAnchorPositionCorrection(e,n,i,s),{ratioX:r,ratioY:o,ratioZ:a,sign:s}}_computeAnchorProps(t,e,n,i,s){const r=t.width*e,o=t.height*i,a=s.x>0?0:s.x<0?t.width-r:(t.width-r)/2,c=s.z>0?0:s.z<0?t.height-o:(t.height-o)/2,l={left:t.left+a,top:t.top+c,width:r,height:o};if(void 0!==t.depth){const e=t.depth*n,i=s.y>0?0:s.y<0?t.depth-e:(t.depth-e)/2;l.depth=e,l.zPos=t.zPos+i}return l}_applyAnchorPositionCorrection(t,n,i,s){const r=new e.Vector3(s.x*(t.scale.x-i.x)*n.width/2,s.y*(t.scale.y-i.y)*(n.depth??0)/2,s.z*(t.scale.z-i.z)*n.height/2),o=new e.Quaternion;t.getWorldQuaternion(o),r.applyQuaternion(o);const a=this._preDragAttachedPosition;t.position.set(a.x+r.x,a.y+r.y,a.z+r.z)}_showInfoOverlay(t){if(this._infoOverlay)return;const e=document.createElement("div");e.style.cssText="\n position: absolute; z-index: 10000; pointer-events: none;\n left: 50%; top: 16px; transform: translateX(-50%);\n padding: 6px 16px; border-radius: 6px;\n background: rgba(0,0,0,0.8); color: #fff;\n font: bold 16px/1.4 'Pretendard', system-ui, sans-serif;\n letter-spacing: 0.5px;\n white-space: nowrap; opacity: 0; transition: opacity 0.15s;\n box-shadow: 0 2px 8px rgba(0,0,0,0.3);\n ",t.style.position="relative",t.appendChild(e),this._infoOverlay=e,requestAnimationFrame(()=>{e.style.opacity="1"})}_updateInfoOverlay(t,e,n){if(!this._infoOverlay)return;const i=t=>(t>=0?"+":"")+t.toFixed(1);if("rotate"===t){if(!this._gizmoInitialRotation)return;const t=180/Math.PI,n=(e.rotation.x-this._gizmoInitialRotation.x)*t,s=(e.rotation.y-this._gizmoInitialRotation.y)*t,r=(e.rotation.z-this._gizmoInitialRotation.z)*t,o=[Math.abs(n),Math.abs(s),Math.abs(r)],a=o.indexOf(Math.max(...o)),c=["X","Y","Z"],l=[n,s,r],h=[e.rotation.x*t,e.rotation.y*t,e.rotation.z*t];this._infoOverlay.textContent=`↻ ${c[a]}: ${h[a].toFixed(1)}° (${i(l[a])})`}else if("translate"===t){if(!this._dragStartPosition)return;const t=e.position.clone().sub(this._dragStartPosition),n=e.position,s=(t,e,n)=>Math.abs(n)<.05?`${t}:${e.toFixed(0)}`:`${t}:${e.toFixed(0)}(${i(n)})`;this._infoOverlay.textContent=`↔ ${s("X",n.x,t.x)} ${s("Y",n.y,t.y)} ${s("Z",n.z,t.z)}`}else if("scale"===t){if(!this._preDragScale)return;this._infoOverlay.textContent=this._formatScaleInfo(e,n)}}_formatScaleInfo(t,e){const n=this._preDragScale,i=this._preDragDimension,s=t.scale.x/(n.x||1),r=t.scale.y/(n.y||1),o=t.scale.z/(n.z||1),a=i?i.width*s:t.scale.x,c=null!=i?.depth?i.depth*r:t.scale.y,l=i?i.height*o:t.scale.z,h=i?i.width*(s-1):t.scale.x-n.x,d=null!=i?.depth?i.depth*(r-1):t.scale.y-n.y,u=i?i.height*(o-1):t.scale.z-n.z,p=t=>(t>=0?"+":"")+t.toFixed(0),f=t=>t.toFixed(0);switch(e){case"X":return`⤢ W ${f(a)}px (${p(h)})`;case"Y":return`⤢ D ${f(c)}px (${p(d)})`;case"Z":return`⤢ H ${f(l)}px (${p(u)})`}return Math.abs(s-r)<.01&&Math.abs(r-o)<.01?`⤢ ×${s.toFixed(2)} (${f(a)}×${f(c)}×${f(l)})`:`⤢ W:${f(a)}(${p(h)}) D:${f(c)}(${p(d)}) H:${f(l)}(${p(u)})`}_hideInfoOverlay(){this._infoOverlay&&(this._infoOverlay.remove(),this._infoOverlay=void 0)}}class wf{constructor(){this._mouseIsDown=!1,this._isDragging=!1,this._touchGizmoCaptured=!1,this._mouseDownPos={x:0,y:0}}get hostElement(){return this._hostElement}setup(t,e,n){this.cleanup(),this._hostElement=t,this._gizmo=e.gizmo,this._controls=e.controls,this._camera=e.camera,this._scene=e.scene,this._event=e.event,this._delegate=n,t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.style.outline="none";const i={mousedown:t=>this._onMouseDown(t),mousemove:t=>this._onMouseMove(t),wheel:t=>{t.stopPropagation(),this._delegate.handleWheel(t)},dblclick:t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleDblClick(t)},contextmenu:t=>{t.preventDefault()},touchstart:t=>{if(t.stopPropagation(),1===t.touches?.length&&this._gizmo?.isAttached){const e=t.touches[0];if(this._gizmo.forwardTouch(e,"pointermove"),this._gizmo.isEngaged)return this._gizmo.forwardTouch(e,"pointerdown"),this._touchGizmoCaptured=!0,void t.preventDefault()}this._touchGizmoCaptured=!1,this._delegate.handleTouchStart(t)},touchmove:t=>{if(t.stopPropagation(),this._touchGizmoCaptured&&1===t.touches.length)return this._gizmo.forwardTouch(t.touches[0],"pointermove"),void t.preventDefault();this._delegate.handleTouchMove(t)},touchend:t=>{if(t.stopPropagation(),this._touchGizmoCaptured){const e=t.changedTouches[0];return e&&this._gizmo.forwardTouch(e,"pointerup"),void(this._touchGizmoCaptured=!1)}this._delegate.handleTouchEnd(t)},keydown:t=>{!this._delegate.handleKeyDown(t)||t.ctrlKey||t.metaKey||t.stopPropagation()},keyup:t=>{(this._delegate.handleKeyUp?.(t)??!1)&&t.stopPropagation()}};t.addEventListener("mousedown",i.mousedown),t.addEventListener("mousemove",i.mousemove),t.addEventListener("wheel",i.wheel),t.addEventListener("dblclick",i.dblclick),t.addEventListener("contextmenu",i.contextmenu),t.addEventListener("touchstart",i.touchstart,{passive:!1}),t.addEventListener("touchmove",i.touchmove,{passive:!1}),t.addEventListener("touchend",i.touchend),t.addEventListener("keydown",i.keydown),t.addEventListener("keyup",i.keyup),this._boundHandlers=i}cleanup(){this._removeDocCapture();const t=this._hostElement,e=this._boundHandlers;t&&e&&(t.removeEventListener("mousedown",e.mousedown),t.removeEventListener("mousemove",e.mousemove),t.removeEventListener("wheel",e.wheel),t.removeEventListener("dblclick",e.dblclick),t.removeEventListener("contextmenu",e.contextmenu),t.removeEventListener("touchstart",e.touchstart),t.removeEventListener("touchmove",e.touchmove),t.removeEventListener("touchend",e.touchend),t.removeEventListener("keydown",e.keydown),t.removeEventListener("keyup",e.keyup),t.removeAttribute("tabindex"),t.style.outline=""),this._boundHandlers=void 0,this._hostElement=void 0,this._mouseIsDown=!1,this._isDragging=!1}forceCleanupDragState(){this._removeDocCapture(),this._mouseIsDown=!1,this._isDragging=!1}clientToElementCoords(t,e){const n=this._hostElement;if(!n)return{x:t,y:e};const i=n.getBoundingClientRect();return{x:t-i.left,y:e-i.top}}updateMouseNDCFromClient(t,e){const n=this._hostElement?.getBoundingClientRect();if(!n||0===n.width||0===n.height)return;const i=t-n.left,s=e-n.top;this._event.updateMouseNDC(i,s,0,0,n.width,n.height)}_onMouseDown(t){if(t.stopPropagation(),0!==t.button)return void(this._mouseIsDown&&(this._removeDocCapture(),this._isDragging&&(this._gizmo?.forwardEvent(new MouseEvent("pointerup",{bubbles:!1}),"pointerup"),this._controls?.onDragEnd?.({offsetX:t.offsetX,offsetY:t.offsetY})),this._mouseIsDown=!1,this._isDragging=!1));if(this._hostElement.focus(),this._removeDocCapture(),this._mouseIsDown=!1,this._isDragging=!1,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<wf.DRAG_THRESHOLD)return;this._isDragging=!0;const t=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:t.x,offsetY:t.y,altKey:!0})}const i=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:i.x,offsetY:i.y,altKey:!0})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);if(t.shiftKey&&!t.altKey&&!this._gizmo?.isEngaged){const e=this.clientToElementCoords(t.clientX,t.clientY);return this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation();const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<wf.DRAG_THRESHOLD)return;this._isDragging=!0,this._delegate.handleBoxSelectionStart?.(e.x,e.y)}const s=this.clientToElementCoords(t.clientX,t.clientY);this._delegate.handleBoxSelectionUpdate?.(s.x,s.y)},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),this._isDragging)this._delegate.handleBoxSelectionEnd?.(t.shiftKey,t.ctrlKey||t.metaKey);else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0)}if(this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.tryVertexDragStart?.(t))return this._mouseIsDown=!0,this._isDragging=!0,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{t.stopPropagation(),this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleVertexDragMove?.(t)},this._docUpHandler=t=>{t.stopPropagation(),this._removeDocCapture(),this._delegate.handleVertexDragEnd?.(t),this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),void document.addEventListener("mouseup",this._docUpHandler,!0);this._delegate.captureMouseDownAltKey(t.altKey),this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown");let e=this._gizmo.isDragging;!e&&t.altKey&&this._delegate.tryAltClickSelect(t)&&(this._gizmo.forwardEvent(t,"pointermove"),this._gizmo.forwardEvent(t,"pointerdown"),e=this._gizmo.isDragging),this._mouseIsDown=!0,this._isDragging=!1,this._mouseDownPos={x:t.clientX,y:t.clientY},this._docMoveHandler=t=>{if(t.stopPropagation(),e)return void this._gizmo.forwardEvent(t,"pointermove");const n=t.clientX-this._mouseDownPos.x,i=t.clientY-this._mouseDownPos.y;if(!this._isDragging){if(n*n+i*i<wf.DRAG_THRESHOLD)return;this._isDragging=!0;const e=this.clientToElementCoords(this._mouseDownPos.x,this._mouseDownPos.y);this._controls.onDragStart({offsetX:e.x,offsetY:e.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}const s=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragMove({offsetX:s.x,offsetY:s.y,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})},this._docUpHandler=t=>{if(t.stopPropagation(),this._removeDocCapture(),e)return this._gizmo.forwardEvent(t,"pointerup"),this._mouseIsDown=!1,void(this._isDragging=!1);if(this._isDragging){const e=this.clientToElementCoords(t.clientX,t.clientY);this._controls.onDragEnd({offsetX:e.x,offsetY:e.y})}else{const e=this.clientToElementCoords(t.clientX,t.clientY);this.updateMouseNDCFromClient(t.clientX,t.clientY),this._delegate.handleClickAt(e.x,e.y,t)}this._mouseIsDown=!1,this._isDragging=!1},document.addEventListener("mousemove",this._docMoveHandler,!0),document.addEventListener("mouseup",this._docUpHandler,!0)}_onMouseMove(t){if(t.stopPropagation(),this._mouseIsDown)return;if(this._delegate.isPlacementMode())return void this._delegate.handlePlacementHover(t);this.updateMouseNDCFromClient(t.clientX,t.clientY);const e=this._camera.activeCamera;e&&this._scene.scene&&this._event.handleHover(e,this._scene.scene,t),this._gizmo.forwardEvent(t,"pointermove")}_removeDocCapture(){this._docMoveHandler&&(document.removeEventListener("mousemove",this._docMoveHandler,!0),this._docMoveHandler=void 0),this._docUpHandler&&(document.removeEventListener("mouseup",this._docUpHandler,!0),this._docUpHandler=void 0)}}wf.DRAG_THRESHOLD=16;class Mf{constructor(){this._groundPlane=new e.Plane(new e.Vector3(0,1,0),0)}get isActive(){return!!this._pendingModels}get pendingModels(){return this._pendingModels}setup(t,e){this._camera=t.camera,this._event=t.event,this._scene=t.scene,this._delegate=e}start(t){this._pendingModels=t}stop(){this._pendingModels=void 0,this._removeIndicator()}destroy(){this._removeIndicator(),this._pendingModels=void 0}raycastGroundPlane(t){this._delegate.updateMouseNDCFromClient(t.clientX,t.clientY);const n=this._camera.activeCamera;if(!n)return null;n.updateMatrixWorld(!0);const i=new e.Raycaster;i.setFromCamera(this._event.mouse,n);const s=new e.Vector3;return i.ray.intersectPlane(this._groundPlane,s)}updateIndicator(t){if(!t)return void(this._placementIndicator&&(this._placementIndicator.visible=!1));if(!this._placementIndicator){const t=this._scene?.scene;if(!t)return;const n=new e.RingGeometry(.8,1,32);n.rotateX(-Math.PI/2);const i=new e.MeshBasicMaterial({color:48340,opacity:.6,transparent:!0,side:e.DoubleSide,depthTest:!1});this._placementIndicator=new e.Mesh(n,i),this._placementIndicator.renderOrder=999,t.add(this._placementIndicator)}const n=this._pendingModels?.[0],i=n?.rx??n?.width??50,s=n?.ry??n?.height??50;this._placementIndicator.scale.set(i,1,s),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 Sf={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 kf(t,n,i,s,r,o=new e.Vector3){const a=t*t,c=a*t;return o.set(.5*(2*i.x+(-n.x+s.x)*t+(2*n.x-5*i.x+4*s.x-r.x)*a+(-n.x+3*i.x-3*s.x+r.x)*c),.5*(2*i.y+(-n.y+s.y)*t+(2*n.y-5*i.y+4*s.y-r.y)*a+(-n.y+3*i.y-3*s.y+r.y)*c),.5*(2*i.z+(-n.z+s.z)*t+(2*n.z-5*i.z+4*s.z-r.z)*a+(-n.z+3*i.z-3*s.z+r.z)*c))}class Af{constructor(){this._slots=new Array(10),this._animating=!1,this._animationProgress=0,this._playStartOffset=0,this._lastPlayProgress=-1,this._playIndex=-1,this._playing=!1,this._orbitRotating=!1,this._orbitPaused=!1}get isAnimating(){return this._animating}get isPlaying(){return this._playing}get isOrbitRotating(){return this._orbitRotating}get isOrbitPaused(){return this._orbitPaused}get playIndex(){return this._playIndex}get lastPlayProgress(){return this._lastPlayProgress}get playProgress(){if(!this._playing||this._playIndex<0)return 0;const t=this.getPlayableSlots().length;if(t<2)return 0;const e=(this._playIndex-1+t)%t;let n=this._animating?this._animationProgress:1;return this._playStartOffset>0&&(n=this._playStartOffset+n*(1-this._playStartOffset)),(e+n)%t/t}setCallbacks(t,e){this._onInvalidate=t,this._onAnimationComplete=e}saveSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];this._slots[t]={...e,name:"name"in e?e.name:n?.name}}renameSlot(t,e){if(t<0||t>9)return;const n=this._slots[t];n&&(n.name=e||void 0)}clearSlot(t){t<0||t>9||(this._slots[t]=void 0)}getSlot(t){return this._slots[t]}exportSlots(){return this._slots.map(t=>t?{...t}:null)}importSlots(t){if(Array.isArray(t))for(let e=0;e<10;e++){const n=t[e];this._slots[e]=n?{...n}:void 0}}resetAll(){this._slots=new Array(10)}getPlayableSlots(){return this._slots.map((t,e)=>t&&!t.excludeFromPlay?e:-1).filter(t=>t>=0)}swapSlots(t,e){if(t<0||t>9||e<0||e>9||t===e)return;const n=this._slots[t];this._slots[t]=this._slots[e],this._slots[e]=n}moveSlot(t,e){if(t<1||t>9||e<1||e>9||t===e)return;const n=this._slots[t];this._slots.splice(t,1),this._slots.splice(e,0,n)}animateToSlot(t,n,i,s=800,r){const o=this._slots[t];if(!o)return!1;this.stopAnimation(),this._animating=!0,this._animationProgress=0;const a=n.position.clone(),c=i.target.clone(),l=new e.Vector3(o.position.x,o.position.y,o.position.z),h=new e.Vector3(o.target.x,o.target.y,o.target.z),d=.01,u=Math.max(a.distanceTo(c),d),p=Math.max(l.distanceTo(h),d),f=(new e.Vector3).subVectors(c,a),m=(new e.Vector3).subVectors(h,l),g=f.lengthSq()>1e-4?f.normalize():new e.Vector3(0,0,-1).applyQuaternion(n.quaternion),y=m.lengthSq()>1e-4?m.normalize():g.clone(),b=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),g),_=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),y),v=Sf[o.easing??"ease-in-out"];return this._runAnimation(s,v,t=>{r?kf(t,r.prevPos,a,l,r.nextPos,n.position):n.position.lerpVectors(a,l,t);const s=b.clone().slerp(_,t),o=new e.Vector3(0,0,-1).applyQuaternion(s),c=u+(p-u)*t,h=n.position.clone().add(o.multiplyScalar(c));i.restoreTarget(h)}),!0}_animatePathSegment(t,e,n,i,s,r){const o=Sf[i];this._runAnimation(n,o,n=>{const i=t+(e-t)*n,o=this.evaluatePath(i<=1?i:i-1);o&&(s.position.copy(o.position),r.restoreTarget(o.target))})}_runAnimation(t,e,n){this.stopAnimation(),this._animating=!0,this._animationProgress=0;const i=performance.now(),s=()=>{const r=performance.now()-i,o=Math.min(r/t,1),a=e(o);this._animationProgress=a,n(a),this._onInvalidate?.(),o<1?this._animationId=requestAnimationFrame(s):(this._animating=!1,this._animationId=void 0,this._onAnimationComplete?.())};this._animationId=requestAnimationFrame(s)}_initFromProgress(t,e){const n=t*e,i=Math.min(Math.floor(n),e-1);this._playStartOffset=n-i,this._playIndex=(i+1)%e}startPlay(t,n,i=2e3,s=1200,r=-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=r>=0&&r<=1?r: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],r=this._slots[e],o=r?.holdDuration??i,h=r?.transitionDuration??s;if(l>=0){const e=l;let i=this._playIndex/a.length;i<=e&&(i+=1),l=-1;const s=this._playStartOffset,c=Math.max(Math.round(h*(1-s)),100);return u(o),void this._animatePathSegment(e,i,c,r?.easing??"ease-in-out",t,n)}const p=this._buildSplineContext(a,c,t,n,d);c=!1,u(o),this.animateToSlot(e,t,n,h,p)};p()}_buildSplineContext(t,e,n,i,s){if(t.length<3)return;const r=t.length,o=t[(this._playIndex+1)%r],a=this._slots[o];if(!a)return;if(e)return{prevPos:n.position.clone(),nextPos:s(a.position)};const c=t[(this._playIndex-2+r)%r],l=this._slots[c];return l?{prevPos:s(l.position),nextPos:s(a.position)}:void 0}setProgressForSlot(t){const e=this.getPlayableSlots(),n=e.indexOf(t);n<0||e.length<2?this._lastPlayProgress=-1:this._lastPlayProgress=n/e.length}stopPlay(){this._lastPlayProgress=this.playProgress,this._playing=!1,this._playIndex=-1,this._playStartOffset=0,this._onAnimationComplete=void 0,this.stopAnimation()}resetPlay(){this.stopPlay(),this._lastPlayProgress=-1}toggleOrbitRotation(t){const e=t.isAutoRotating();this._orbitRotating=!e,this._orbitPaused=!this._orbitRotating,t.setAutoRotate(this._orbitRotating)}stopOrbitRotation(t){this._orbitRotating=!1,this._orbitPaused=!1,t.setAutoRotate(!1)}evaluatePath(t){const n=this.getPlayableSlots();if(n.length<2)return null;const i=n.length,s=Math.max(0,Math.min(1,t)),r=t=>{const s=this._slots[n[(t%i+i)%i]];return s?new e.Vector3(s.position.x,s.position.y,s.position.z):new e.Vector3},o=t=>{const s=this._slots[n[(t%i+i)%i]];return s?new e.Vector3(s.target.x,s.target.y,s.target.z):new e.Vector3};if(2===i){const t=s<.5?2*s:2*(1-s);return{position:r(0).lerp(r(1),t),target:o(0).lerp(o(1),t)}}const a=s*i,c=Math.min(Math.floor(a),i-1),l=a-c,h=kf(l,r(c-1),r(c),r(c+1),r(c+2)),d=r(c),u=r(c+1),p=o(c),f=o(c+1),m=.01,g=Math.max(d.distanceTo(p),m),y=Math.max(u.distanceTo(f),m),b=(new e.Vector3).subVectors(p,d),_=(new e.Vector3).subVectors(f,u),v=b.lengthSq()>1e-4?b.normalize():new e.Vector3(0,0,-1),x=_.lengthSq()>1e-4?_.normalize():v.clone(),w=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),v),M=(new e.Quaternion).setFromUnitVectors(new e.Vector3(0,0,-1),x),S=w.clone().slerp(M,l),k=new e.Vector3(0,0,-1).applyQuaternion(S),A=g+(y-g)*l,E=h.clone().add(k.multiplyScalar(A));return{position:h,target:E}}stopAnimation(){void 0!==this._animationId&&(cancelAnimationFrame(this._animationId),this._animationId=void 0),this._animating=!1}destroy(){this.stopPlay(),this.stopAnimation(),this._orbitPaused=!1,this._slots=new Array(10),this._onInvalidate=void 0,this._onAnimationComplete=void 0}}class Ef{constructor(){this._overlay=null,this._hostElement=null,this._startX=0,this._startY=0,this._currentX=0,this._currentY=0,this._active=!1}get isActive(){return this._active}setup(t){this._hostElement=t}startSelection(t,e){this._hostElement&&(this._startX=t,this._startY=e,this._currentX=t,this._currentY=e,this._active=!0,this._overlay=document.createElement("div"),this._overlay.style.cssText="\n position: absolute;\n border: 1px solid #4a9eff;\n background: rgba(74, 158, 255, 0.1);\n pointer-events: none;\n z-index: 1000;\n ",this._hostElement.appendChild(this._overlay),this._updateOverlay())}updateSelection(t,e){this._active&&(this._currentX=t,this._currentY=e,this._updateOverlay())}endSelection(t,n,i){if(!this._active||!this._hostElement)return this.cancelSelection(),[];const s=this._hostElement.getBoundingClientRect(),r=s.width,o=s.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/r*2-1,u=c/r*2-1,p=-h/o*2+1,f=-l/o*2+1,m=[],g=new e.Vector3;for(const e of i){const n=e._realObject;n?.object3d&&(g.copy(n.object3d.position),g.project(t),g.z>1||g.x>=d&&g.x<=u&&g.y>=p&&g.y<=f&&m.push(e))}return this.cancelSelection(),m}cancelSelection(){this._active=!1,this._overlay&&this._hostElement&&this._hostElement.removeChild(this._overlay),this._overlay=null}destroy(){this.cancelSelection(),this._hostElement=null}_updateOverlay(){if(!this._overlay)return;const t=Math.min(this._startX,this._currentX),e=Math.min(this._startY,this._currentY),n=Math.abs(this._currentX-this._startX),i=Math.abs(this._currentY-this._startY);this._overlay.style.left=`${t}px`,this._overlay.style.top=`${e}px`,this._overlay.style.width=`${n}px`,this._overlay.style.height=`${i}px`}}const Cf=4890367,Tf=16750592,Pf=1733608,Of=8077298;class Df{constructor(){this._componentHandles=[],this._activeVertexHandles=[],this._activeHandleIndex=-1,this._activeKind="vertex",this._isDragging=!1,this._isPending=!1,this._pendingScreenStart={x:0,y:0},this._dragPlane=new e.Plane,this._dragOffset=new e.Vector3,this._raycaster=new e.Raycaster,this._intersection=new e.Vector3}get isDragging(){return this._isDragging}get isAttached(){return this._componentHandles.length>0}setVisible(t){this._handleGroup&&(this._handleGroup.visible=t)}attachMultiple(t,n,i){this.detach();const s=t.filter(t=>t.mutable&&t.path&&t.path.length>=2);if(0!==s.length){this._scene3d=n,this._commander=i,this._handleGroup=new e.Group,this._handleGroup.name="__vertexHandles__",this._handleGroup.renderOrder=1e4;for(const t of s){const e=this._buildComponentHandles(t);this._componentHandles.push(e)}n.add(this._handleGroup)}}attach(t,e,n){this.attachMultiple([t],e,n)}detach(){this._handleGroup&&this._scene3d&&(this._scene3d.remove(this._handleGroup),eu(this._handleGroup)),this._componentHandles=[],this._handleGroup=void 0,this._scene3d=void 0,this._commander=void 0,this._activeComponent=void 0,this._activeVertexHandles=[],this._activeHandleIndex=-1,this._activeKind="vertex",this._activeHandle=void 0,this._isDragging=!1,this._isPending=!1,this._pendingHit=void 0,this._pendingHandleType=void 0}_buildComponentHandles(t){const n=[],i=[],s=[],r=[],o={component:t,vertexHandles:n,midpointHandles:i,cornerHandles:s,bulgeHandles:r},a=t.path;if(!a||!this._handleGroup)return o;const{width:c=0,height:l=0}=t.parent?.bounds??{},h=t._realObject,d=h?h.object3d.position.y:0,u=!!t.cornerEditable,p=t.state?.round??0,f=u&&!t.isLine?.();for(let i=0;i<a.length;i++){const s=a[i],r=new e.Vector3(s.x-c/2,(s.z||0)+d,s.y-l/2),o=this._createVertexHandle(r,i,t);n.push(o),this._handleGroup.add(o)}if(t.pathExtendable)for(let n=0;n<a.length-1;n++){const s=a[n],r=a[n+1],o=new e.Vector3((s.x+r.x)/2-c/2,((s.z||0)+(r.z||0))/2+d,(s.y+r.y)/2-l/2),h=this._createMidpointHandle(o,n,t);i.push(h),this._handleGroup.add(h)}if(u){const n=f?0:1,i=f?a.length:a.length-1;for(let r=n;r<i;r++){const n=a[(r-1+a.length)%a.length],i=a[r],o=eo(n,i,a[(r+1)%a.length],to(i,p),24);if(!o)continue;const h=new e.Vector3(o.x-c/2,(i.z||0)+d,o.y-l/2),u=this._createCornerHandle(h,r,t);s.push(u),this._handleGroup.add(u)}const o=f?a.length:a.length-1;for(let n=0;n<o;n++){const i=a[n],s=a[(n+1)%a.length],o=Zr(i,s,i.bulge??0,24);if(!o)continue;const h=new e.Vector3(o.x-c/2,((i.z||0)+(s.z||0))/2+d,o.y-l/2),u=this._createBulgeHandle(h,n,t);r.push(u),this._handleGroup.add(u)}}return{component:t,vertexHandles:n,midpointHandles:i,cornerHandles:s,bulgeHandles:r}}_rebuildComponentHandles(t){const e=this._componentHandles.findIndex(e=>e.component===t);if(e<0||!this._handleGroup)return;const n=this._componentHandles[e];for(const t of[...n.vertexHandles,...n.midpointHandles,...n.cornerHandles,...n.bulgeHandles])this._handleGroup.remove(t),t.geometry.dispose(),t.material.dispose();this._componentHandles[e]=this._buildComponentHandles(t),this._activeComponent===t&&(this._activeVertexHandles=this._componentHandles[e].vertexHandles)}_createVertexHandle(t,n,i){const s=new e.SphereGeometry(1,16,12),r=new e.MeshBasicMaterial({color:Cf,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.vertexIndex=n,o.userData.handleType="vertex",o.userData.component=i,o.renderOrder=10001,o}_createMidpointHandle(t,n,i){const s=new e.OctahedronGeometry(.7,0),r=new e.MeshBasicMaterial({color:16735602,transparent:!0,opacity:.7,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.segmentIndex=n,o.userData.handleType="midpoint",o.userData.component=i,o.renderOrder=10001,o}_createCornerHandle(t,n,i){const s=new e.SphereGeometry(1,12,10),r=new e.MeshBasicMaterial({color:Pf,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.vertexIndex=n,o.userData.handleType="corner",o.userData.component=i,o.renderOrder=10001,o}_createBulgeHandle(t,n,i){const s=new e.OctahedronGeometry(1,0),r=new e.MeshBasicMaterial({color:Of,transparent:!0,opacity:.8,depthTest:!1}),o=new e.Mesh(s,r);return o.position.copy(t),o.userData.segmentIndex=n,o.userData.handleType="bulge",o.userData.component=i,o.renderOrder=10001,o}_handlePosToPoint(t,e){const{width:n=0,height:i=0}=e.parent?.bounds??{},s=e._realObject,r=s?s.object3d.position.y:0,o={x:t.x+n/2,y:t.z+i/2},a=t.y-r;return Math.abs(a)>.001&&(o.z=a),o}_execMutatePath(t,e){const n=this._commander;n?ll.around(n,()=>{t.mutatePath(null,e)}):t.mutatePath(null,e)}_getAllHandles(){const t=[];for(const e of this._componentHandles)t.push(...e.vertexHandles,...e.midpointHandles,...e.cornerHandles,...e.bulgeHandles);return t}_findComponentHandles(t){return this._componentHandles.find(e=>e.component===t)}onPointerDown(t,e,n){if(this._isPending=!1,this._pendingHit=void 0,this._pendingHandleType=void 0,!this._handleGroup)return!1;this._raycaster.setFromCamera(t,e);const i=[];for(const t of this._componentHandles)i.push(...t.vertexHandles,...t.midpointHandles);let s,r,o=i.length>0?this._raycaster.intersectObjects(i,!1):[];if(o.length>0)s=o[0].object,r=s.userData.handleType;else{const t=[];for(const e of this._componentHandles)t.push(...e.cornerHandles,...e.bulgeHandles);if(0===t.length)return!1;if(o=this._raycaster.intersectObjects(t,!1),0===o.length)return!1;s=o[0].object,r=s.userData.handleType}if(!s||!r)return!1;const a=s.userData.component,c=this._findComponentHandles(a);return!!c&&(this._activeComponent=a,this._activeVertexHandles=c.vertexHandles,this._pendingHit=s,this._pendingHandleType=r,this._pendingScreenStart={x:n.clientX,y:n.clientY},this._isPending=!0,this._isDragging=!1,!0)}_beginDrag(t,e){const n=this._pendingHit,i=this._activeComponent,s=this._pendingHandleType;if(!n||!i||!s)return!1;if("midpoint"===s)return this._activeKind="midpoint",this._startMidpointDrag(n,i,t);if("corner"===s)return this._startCornerDrag(n,i,t);if("bulge"===s)return this._startBulgeDrag(n,i,t);const r=n.userData.vertexIndex,o=i.path;if(!o)return!1;const a=0===r||r===o.length-1;return e.altKey&&a&&i.pathExtendable?(this._activeKind="vertex",this._startEndpointExtend(n,r,i,t)):(this._activeKind="vertex",this._activeHandle=n,this._activeHandleIndex=r,this._isDragging=!0,n.material.color.setHex(Tf),this._setupDragPlane(t,n.position),!0)}_startCornerDrag(t,e,n){const i=t.userData.vertexIndex;return!!e.path&&(this._activeKind="corner",this._activeHandleIndex=i,this._activeHandle=t,this._isDragging=!0,t.material.color.setHex(Tf),this._setupDragPlane(n,t.position),!0)}_startBulgeDrag(t,e,n){const i=t.userData.segmentIndex;return!!e.path&&(this._activeKind="bulge",this._activeHandleIndex=i,this._activeHandle=t,this._isDragging=!0,t.material.color.setHex(Tf),this._setupDragPlane(n,t.position),!0)}_startMidpointDrag(t,e,n){const i=t.userData.segmentIndex+1,s=this._handlePosToPoint(t.position,e);this._execMutatePath(e,t=>{t.splice(i,0,s)}),this._rebuildComponentHandles(e);const r=this._activeVertexHandles[i];return!!r&&(this._activeHandleIndex=i,this._isDragging=!0,r.material.color.setHex(Tf),this._setupDragPlane(n,r.position),!0)}_startEndpointExtend(t,e,n,i){const s=n.path;if(!s)return!1;const r=this._handlePosToPoint(t.position,n),o=0===e?0:s.length;this._execMutatePath(n,t=>{t.splice(o,0,r)}),this._rebuildComponentHandles(n);const a=this._activeVertexHandles[o];return!!a&&(this._activeHandleIndex=o,this._isDragging=!0,a.material.color.setHex(Tf),this._setupDragPlane(i,a.position),!0)}_setupDragPlane(t,n){const i=new e.Vector3;t.getWorldDirection(i),this._dragPlane.setFromNormalAndCoplanarPoint(i,n),this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection),this._dragOffset.copy(n).sub(this._intersection)}onPointerMove(t,e,n){if(this._raycaster.setFromCamera(t,e),this._isPending){const t=n.clientX-this._pendingScreenStart.x,i=n.clientY-this._pendingScreenStart.y;if(t*t+i*i<16)return!1;if(this._isPending=!1,!this._beginDrag(e,n))return!1}if(!this._isDragging||this._activeHandleIndex<0)return!1;this._raycaster.ray.intersectPlane(this._dragPlane,this._intersection);const i=this._intersection.add(this._dragOffset);if("corner"===this._activeKind)return this._dragCornerLive(i),!0;if("bulge"===this._activeKind)return this._dragBulgeLive(i),!0;if(n.shiftKey){const t=this._activeVertexHandles[this._activeHandleIndex];t&&(i.x=t.position.x,i.z=t.position.z)}const s=this._activeVertexHandles[this._activeHandleIndex];s&&s.position.copy(i);const r=this._activeComponent;if(r){const t=this._activeHandleIndex,e=this._handlePosToPoint(i,r);r.mutatePath(null,n=>{const i={...n[t]||{},x:e.x,y:e.y};void 0!==e.z&&(i.z=e.z),n[t]=i}),r.invalidate?.()}return this._updateLinePreview(),!0}_dragCornerLive(t){const e=this._activeComponent;if(!e)return;const n=e.path,i=this._activeHandleIndex;if(!n||i<0)return;const{width:s=0,height:r=0}=e.parent?.bounds??{},o={x:t.x+s/2,y:t.z+r/2},a=n[(i-1+n.length)%n.length],c=n[i],l=n[(i+1)%n.length],h=no(a,c,l,o);if(e.mutatePath(null,function(t){const e=t[i]||{};t[i]={...e,radius:h}}),e.invalidate?.(),this._activeHandle){const t=e.state?.round??0,n=e._realObject,i=n?n.object3d.position.y:0,o=eo(a,c,l,to(c,t),24);o&&this._activeHandle.position.set(o.x-s/2,(c.z||0)+i,o.y-r/2)}}_dragBulgeLive(t){const e=this._activeComponent;if(!e)return;const n=e.path,i=this._activeHandleIndex;if(!n||i<0)return;const{width:s=0,height:r=0}=e.parent?.bounds??{},o={x:t.x+s/2,y:t.z+r/2},a=n[i],c=n[(i+1)%n.length],l=Jr(a,c,o);if(e.mutatePath(null,function(t){const e=t[i]||{};if(0===l){const{bulge:n,...s}=e;t[i]=s}else t[i]={...e,bulge:l}}),e.invalidate?.(),this._activeHandle){const t=e._realObject,n=t?t.object3d.position.y:0,i=Zr(a,c,l,24);i&&this._activeHandle.position.set(i.x-s/2,((a.z||0)+(c.z||0))/2+n,i.y-r/2)}}_updateLinePreview(){if(!this._activeComponent)return;const t=this._activeComponent._realObject;if(!t?._line2)return;const{width:e=0,height:n=0}=this._activeComponent.parent?.bounds??{},{x:i,y:s}=this._activeComponent.center,r=t.object3d?t.object3d.position.y:0,o=[];for(const t of this._activeVertexHandles){const a=t.position.x+e/2-i,c=t.position.y-r,l=t.position.z+n/2-s;o.push(a,c,l)}if(o.length<6)return;t._line2.geometry.setPositions(o),t._line2.computeLineDistances()}onPointerUp(){if(this._isPending&&!this._isDragging)return this._isPending=!1,this._pendingHit=void 0,this._pendingHandleType=void 0,this._activeComponent=void 0,this._activeHandle=void 0,this._activeHandleIndex=-1,!0;if(!this._isDragging||this._activeHandleIndex<0||!this._activeComponent)return!1;const t=this._activeComponent,e=this._activeHandleIndex,n=this._activeKind;if("corner"===n||"bulge"===n){if(this._activeHandle){const t="corner"===n?Pf:Of;this._activeHandle.material.color.setHex(t)}return this._isDragging=!1,this._activeHandleIndex=-1,this._activeHandle=void 0,this._rebuildComponentHandles(t),!0}const i=this._activeVertexHandles[e];if(!i)return this._isDragging=!1,this._activeHandleIndex=-1,!0;i.material.color.setHex(Cf);const s=this._handlePosToPoint(i.position,t);return this._execMutatePath(t,t=>{const n={...t[e]||{},x:s.x,y:s.y};void 0!==s.z&&(n.z=s.z),t[e]=n}),this._isDragging=!1,this._activeHandleIndex=-1,this._activeHandle=void 0,this._rebuildComponentHandles(t),!0}onDblClick(t,e){if(!this._handleGroup)return!1;this._raycaster.setFromCamera(t,e);const n=[];for(const t of this._componentHandles)n.push(...t.vertexHandles);if(n.length>0){const t=this._raycaster.intersectObjects(n,!1);if(t.length>0){const e=t[0].object,n=e.userData.component;if(!n.pathExtendable)return!1;const i=n.path;if(!i||i.length<=2)return!1;const s=e.userData.vertexIndex;return this._execMutatePath(n,t=>{t.splice(s,1)}),this._rebuildComponentHandles(n),!0}}const i=[];for(const t of this._componentHandles)i.push(...t.cornerHandles,...t.bulgeHandles);if(0===i.length)return!1;const s=this._raycaster.intersectObjects(i,!1);if(0===s.length)return!1;const r=s[0].object,o=r.userData.handleType,a=r.userData.component;if("corner"===o){const t=r.userData.vertexIndex;return this._execMutatePath(a,e=>{const n=e[t]||{},{radius:i,...s}=n;e[t]=s}),this._rebuildComponentHandles(a),!0}if("bulge"===o){const t=r.userData.segmentIndex;return this._execMutatePath(a,e=>{const n=e[t]||{},{bulge:i,...s}=n;e[t]=s}),this._rebuildComponentHandles(a),!0}return!1}syncHandles(){for(const t of this._componentHandles)this._rebuildComponentHandles(t.component)}updateHandleScales(t){const e=this._getAllHandles();if(0!==e.length)for(const n of e){const e=t.position.distanceTo(n.position),i=n.userData.handleType,s="midpoint"===i?5:"corner"===i||"bulge"===i?9:8;let r;if(t.isPerspectiveCamera){const n=t.fov,i=2*Math.tan(n*Math.PI/360)*e;r=s/window.innerHeight*i}else{const e=t,n=(e.top-e.bottom)/e.zoom;r=s/window.innerHeight*n}n.scale.setScalar(Math.max(r,.1))}}destroy(){this.detach()}}class zf{constructor(){this.sceneManager=new hf,this.cameraManager=new df,this.rendererManager=new uf,this.lightManager=new pf,this.controlsManager=new mf,this.eventManager=new gf,this.gizmoManager=new bf,this.interactionManager=new wf,this.placementManager=new Mf,this.gizmoOperationManager=new xf,this.bookmarkManager=new Af,this.boxSelectionManager=new Ef,this.vertexGizmoManager=new Df,this._isSpacePanning=!1,this._initialized=!1,this._decoratorOutlines=new Set,this._selectionOutlineObjects=[],this._highlightedMarkerIndex=-1,this._arrows=new Map,this._pathVisible=!1}get isInitialized(){return this._initialized}get host(){return this._host}get scene3d(){return this.sceneManager.scene}get renderer3d(){return this.rendererManager.renderer}get mixer(){return this.sceneManager.mixer}get camera(){return this.cameraManager.camera}get activeCamera(){return this.cameraManager.activeCamera}get css3DScene(){return this.rendererManager.css3DScene}get css3DRenderer(){return this.rendererManager.css3DRenderer}get noSupportWebgl(){return this.rendererManager.noSupportWebgl}get isActive(){return this.controlsManager.isActive}setGizmoMode(t){if(this.gizmoManager.mode===t&&this.gizmoManager.attached)return this.gizmoManager.detach(),void this._host?.invalidate();this.gizmoManager.setMode(t),this.onGizmoModeChanged?.(t);const e=this._host?.root?.selected,n=e?.filter(t=>t!==this._host&&t._realObject)||[];if(n.length>=1){const e=n[0]._realObject;if(e?.object3d&&e.gizmoTransformable&&!n[0].stuck){const n=e.allowedGizmoModes;if(!n||n.includes(t)){const t=fu(e)&&e.pickedPart?e.partObject(e.pickedPart):void 0;this.gizmoManager.attach(t??e.object3d)}else this.gizmoManager.detach()}else this.gizmoManager.detach();this._host?.invalidate()}}get gizmoMode(){return this.gizmoManager.mode}init(t,e){this.interactionManager.cleanup(),this._cleanupEventHandlers(),this._host=t,this.sceneManager.scene&&this.destroy(),this._redrawHandler=()=>{this.eventManager.clearHoverIfUnpickable(),this.animate()},t.root.on("redraw",this._redrawHandler),this._initialized=!0,this._setupScene(e),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),this._onItemAdd=(t,e)=>this.addObject(e),this._onItemRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove),t.on("hold",this._onItemAdd),t.on("release",this._onItemRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged),this._onPartChanged=()=>{this._updateSelectionOutline(t.root?.selected??[]),this._host?.invalidate()},t.root.on("partchanged",this._onPartChanged)),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._onItemAdd&&(t.off("hold",this._onItemAdd),this._onItemAdd=void 0),this._onItemRemove&&(t.off("release",this._onItemRemove),this._onItemRemove=void 0)),this._onSelectionChanged&&t.root?.off&&(t.root.off("selected",this._onSelectionChanged),this._onSelectionChanged=void 0),this._onPartChanged&&t.root?.off&&(t.root.off("partchanged",this._onPartChanged),this._onPartChanged=void 0),this._onAddStart&&t.root?.off&&(t.root.off("addstart",this._onAddStart),this._onAddStart=void 0),this._onAddStop&&t.root?.off&&(t.root.off("addstop",this._onAddStop),this._onAddStop=void 0))}_setupScene(t){const e=this._host;let{width:n,height:i}=e.bounds;n=Math.abs(n)||1,i=Math.abs(i)||1;const{fov:s=45,near:r=.1,far:o=2e4,antialias:a=!0,pixelRatio:c,precision:l="highp",cameraX:h,cameraY:d,cameraZ:u,exposure:p=1.2}=e.state,f=e.components||[],m=t?.lightingConfig??{hemisphere:{skyColor:16777215,groundColor:4473924,intensity:.4}},g=t?.css3DSceneAttribute??"three-container:css3d-renderer",y=this.sceneManager.setup();this._setupCoordinateGround(y,e);const b=this.cameraManager.setup(n,i,{fov:s,near:r,far:o,cameraX:h,cameraY:d,cameraZ:u});this.cameraManager.addToScene(y);const _=e.app?.postprocessing,v=!t?.skipShadowMap&&void 0;let x;if(x=!t?.skipPostprocessing&&("boolean"==typeof e.state?.logarithmicDepth?e.state.logarithmicDepth:"boolean"==typeof e.app?.logarithmicDepth?e.app.logarithmicDepth:!!lf(e.state?.sky)||void 0),this.rendererManager.setupWebGL(n,i,{precision:l,antialias:a,exposure:p,postprocessing:_,shadowMap:v,logarithmicDepthBuffer:x,pixelRatio:c})){if(t?.skipEnvironment||this.sceneManager.setupEnvironment(this.rendererManager.renderer),this.controlsManager.setup(b,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(b,e.element,y),this._setupGizmoCallbacks()),this.placementManager.setup({camera:this.cameraManager,event:this.eventManager,scene:this.sceneManager},{updateMouseNDCFromClient:(t,e)=>this._updateMouseNDCFromClient(t,e)}),this.lightManager.setup(y,b,m),this.sceneManager.setupMixer(),this.createObjects(f),b.updateProjectionMatrix(),t?.skipFloor||this.sceneManager.addFloor(e),this.sceneManager.setSky(e.state.sky,e.state.skyColor,e.state.environment),t?.skipPostprocessing||!1===e.app?.postprocessing)t?.useLightComposer?this.rendererManager.setupLightComposer(y,b,n,i):this.rendererManager.setDirectRenderTargets(y,b);else{const t=this.gizmoManager.controls?.getHelper();this.rendererManager.setupComposer(y,b,n,i,t)}this.rendererManager.setupHUD(n,i),this.rendererManager.hudCamera&&this.eventManager.setHUD(this.rendererManager.hudScene,this.rendererManager.hudCamera),this.rendererManager.setupCSS3D(e.app.isViewMode,g),this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus),e.element&&(this.interactionManager.setup(e.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate()),e.app?.isEditMode&&this.boxSelectionManager.setup(e.element))}}_setupGizmoCallbacks(){this.gizmoOperationManager.setupCallbacks(this.gizmoManager,this.controlsManager,()=>{const t=this._host;if(t)return Object.create(t,{hostElement:{get:()=>t.target??t.element??void 0}})},{onAttachChanged:t=>this.onGizmoAttachChanged?.(t),onDraggingChanged:t=>{t?this.vertexGizmoManager.setVisible(!1):(this.vertexGizmoManager.syncHandles(),this.vertexGizmoManager.setVisible(!0))}})}createObjects(t){for(const e of t)this.addObject(e)}addObject(t){if(t._realObject){const e=t._realObject;if(e.object3d&&!e.object3d.parent)if(t.state.screenFixed)e instanceof Np?this.rendererManager.hudCSS3DScene.add(e.object3d):this.rendererManager.hudScene.add(e.object3d);else if(e instanceof Np)this.rendererManager.css3DScene.add(e.object3d);else{const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}return}if(!t.is3dContainer?.()&&"popup"!==t.state?.position){try{if(!t.isLine?.()){const{width:e,height:n}=t.bounds;if(!e||!n)return}if(t.isHTMLElement()&&!t.element)return;const e=Yp(t);if(e){if(t._realObject=e,e.update(),e.updateTransform(),t.state.screenFixed)e instanceof Np?this.rendererManager.hudCSS3DScene.add(e.object3d):this.rendererManager.hudScene.add(e.object3d);else if(e instanceof Np)this.rendererManager.css3DScene.add(e.object3d);else{const n=t.parent?._realObject?.object3d;n&&n!==this.sceneManager.scene?n.add(e.object3d):this.sceneManager.scene&&this.sceneManager.scene.add(e.object3d)}const n=this._host?.root?.selected;n&&n.length>0&&n[0]===t&&e.object3d&&e.gizmoTransformable&&this.gizmoManager.attached&&this.gizmoManager.attach(e.object3d)}}catch(t){Zi(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))}{const e=t;Array.isArray(e._items)&&(e._items.length>0&&(this.createObjects(e._items),t._realObject?.layoutHeldItems?.()),e.on&&(e.on("hold",this._onItemAdd),e.on("release",this._onItemRemove)))}}}removeObject(t){if(t.is3dContainer?.())return;if(t.isContainer()){const e=t,n=e.components||[];for(const t of n)this.removeObject(t);e.off&&(e.off("add",this._onComponentAdd),e.off("remove",this._onComponentRemove))}{const e=t;if(Array.isArray(e._items)){for(const t of e._items)this.removeObject(t);e.off&&(e.off("hold",this._onItemAdd),e.off("release",this._onItemRemove))}}const e=t._realObject;if(e)try{const n=e.object3d;n&&this.gizmoManager.attached===n&&this.gizmoManager.detach(),n&&(e instanceof Np?this.rendererManager.css3DScene.remove(n):n.removeFromParent()),e.dispose?.(),t._realObject=void 0}catch(t){Zi(t)}}resize(t,e,n=!1){const i=this._host;if(!i)return;if(void 0===t||void 0===e){const n=i.bounds;t=n.width,e=n.height}if(t=Math.abs(t)||1,e=Math.abs(e)||1,n)return void this._applyResize(t,e);this.rendererManager.css3DRenderer?.setSize(t,e);const s=t,r=e;clearTimeout(this._resizeDebouncer),this._resizeDebouncer=window.setTimeout(()=>{this._resizeDebouncer=void 0,this._applyResize(s,r)},100)}_applyResize(t,n){this.cameraManager.updateAspect(t,n),this.rendererManager.resize(t,n);const i=new e.Vector2(t,n);for(const t of this._arrows.values())t.traverse(t=>{t instanceof w&&t.material.resolution.copy(i)});this._initialized&&(this.renderThreeD(),this._host?.invalidate())}animate(){if(!this._initialized||!this.controlsManager.isActive)return;this.sceneManager.updateAnimation();let t=!1;const e=n=>{for(const i of n)i._animation?.started&&i._realObject&&(i._realObject.syncAnimationDelta(),t=!0),i.components&&e(i.components)};e(this._host?.components||[]),this.controlsManager.update(),this.renderThreeD(),t&&this._host?.invalidate()}get hasEnvironment(){return this.sceneManager.hasEnvironment}renderThreeD(){this._initialized&&(this.vertexGizmoManager?.isAttached&&this.vertexGizmoManager.updateHandleScales(this.cameraManager.activeCamera),this.rendererManager.render(),this.renderCSS3D())}setCameraView(t,e){const n=this._host;if(!n)return;const{width:i,height:s}=n.bounds,r=n.element,o=r?.clientWidth||i,a=r?.clientHeight||s;let c;c="perspective"===t?this.cameraManager.restorePerspective():this.cameraManager.setOrthoView(t,i,s,o,a),this.controlsManager.setCamera(c),this.gizmoManager.updateCamera(c),this.rendererManager.updateRenderPassCamera(c),!1!==e?.render&&this.renderThreeD(),this.onCameraViewChanged?.(t)}renderCSS3D(){const t=this.cameraManager.activeCamera;t&&this.rendererManager.renderCSS3D(t)}buildOverlays(){const t=this._host;if(!t?.element)return;t.element.appendChild(this.css3DRenderer.domElement);const e=this.rendererManager.hudCSS3DRenderer?.domElement;e&&t.element.appendChild(e)}_setupCoordinateGround(t,e){if(this._coordinateGround=void 0,!0!==e.state?.grid)return;const n=Number(e.state?.width)||0,i=Number(e.state?.height)||0,s=Number(e.state?.gridStep)||0,r=qp({step:s>0?s:$p(Math.max(n,i)),cells:Number(e.state?.gridCells)||void 0,background:"string"==typeof e.state?.skyColor?e.state.skyColor:void 0,labels:!1!==e.state?.gridLabels});t.add(r),this._coordinateGround=r}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._coordinateGround&&(Jp(this._coordinateGround),this._coordinateGround=void 0),this.vertexGizmoManager.destroy(),this.boxSelectionManager.destroy(),this.bookmarkManager.destroy(),this.gizmoManager.destroy(),this.controlsManager.destroy(),this.lightManager.destroy(),this.rendererManager.destroy(),this.cameraManager.destroy(),this.sceneManager.destroy(),this.eventManager.destroy(),this._initialized=!1}forceCleanupDragState(){this.interactionManager.forceCleanupDragState(),this.boxSelectionManager.isActive&&(this.boxSelectionManager.cancelSelection(),this.controlsManager.setEnabled(!0)),this._isSpacePanning&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0)),this._host?.element&&(this._host.element.style.cursor="")}clearAllObjects(){this.gizmoManager.detach();const t=this._host?.components||[];for(const e of t)e._realObject&&this.removeObject(e)}rebuildForHost(t,e){this.interactionManager.cleanup();try{this._cleanupEventHandlers()}catch(t){}this._host=t,this._redrawHandler=()=>this.animate(),t.root.on("redraw",this._redrawHandler),this._onComponentAdd=(t,e)=>this.addObject(e),this._onComponentRemove=(t,e)=>this.removeObject(e),t.on&&(t.on("add",this._onComponentAdd),t.on("remove",this._onComponentRemove)),t.app?.isEditMode&&t.root?.on&&(this._onSelectionChanged=t=>this._handleSelectionChanged(t),t.root.on("selected",this._onSelectionChanged),this._onAddStart=t=>{this.placementManager.start(t),this._host?.element&&(this._host.element.style.cursor="crosshair",this._host.element.focus())},this._onAddStop=()=>{this.placementManager.stop(),this._host?.element&&(this._host.element.style.cursor="")},t.root.on("addstart",this._onAddStart),t.root.on("addstop",this._onAddStop)),this.createObjects(t.components||[]),t.element&&this.interactionManager.setup(t.element,{gizmo:this.gizmoManager,controls:this.controlsManager,camera:this.cameraManager,scene:this.sceneManager,event:this.eventManager},this._buildInteractionDelegate());const n=this.controlsManager._position0?.clone(),i=this.controlsManager._target0?.clone();this.controlsManager.setup(this.cameraManager.camera,t),n&&this.controlsManager._position0.copy(n),i&&this.controlsManager._target0.copy(i),t.app?.isEditMode&&t.element&&this.boxSelectionManager.setup(t.element),t.app?.isEditMode&&t.element&&this.sceneManager.scene&&(this.gizmoManager.setup(this.cameraManager.camera,t.element,this.sceneManager.scene),this._setupGizmoCallbacks()),this._onFocus||(this._onFocus=()=>this.renderThreeD(),window.addEventListener("focus",this._onFocus)),this.renderThreeD()}dispose(){const t=e=>{for(const n of e)if(!n.is3dContainer?.()){if(n.isContainer()){const e=n.components||[];t(e)}n._realObject&&(n._realObject.dispose?.(),n._realObject=void 0)}};t(this._host?.components||[]),this._decoratorOutlines.clear(),this._selectionOutlineObjects=[],this.clearArrows(),this.placementManager.destroy(),this._cleanupEventHandlers(),this.rendererManager.disposeCSS3DScene(),this.destroy(),this._host=void 0}_buildInteractionDelegate(){return{isPlacementMode:()=>this.placementManager.isActive,handlePlacementClick:t=>{if(!this._host?.root)return;const e=this.placementManager.raycastGroundPlane(t);if(e){const t=this._host,n=t.bounds.width||800,i=t.bounds.height||600,s=e.x+n/2,r=e.z+i/2;Oh.call(t.root,this.placementManager.pendingModels,{cx:s,cy:r}),t.root.trigger("addstop")}},handlePlacementHover:t=>{const e=this.placementManager.raycastGroundPlane(t);this.placementManager.updateIndicator(e),this.renderThreeD()},tryAltClickSelect:t=>{if(!this._host?.app?.isEditMode||!this._host.root)return!1;this._updateMouseNDCFromClient(t.clientX,t.clientY);const e=this.cameraManager.activeCamera;if(e&&this.sceneManager.scene){const n=this.eventManager.handleClick(e,this.sceneManager.scene,t);if(n?.component)return this._host.root.selected=[n.component],!0}return!1},captureMouseDownAltKey:t=>{this.gizmoOperationManager.captureAltKey(t)},handleClickAt:(t,e,n)=>{this._handleClickAt(n)},handleWheel:t=>this.onWheel(t),handleDblClick:t=>this.onDblClick(t),handleTouchStart:t=>this.onTouchStart(t),handleTouchMove:t=>this.onPan(t),handleTouchEnd:t=>this.onTouchEnd(t),handleKeyDown:t=>this.onKeyDown(t),handleKeyUp:t=>this._onKeyUp(t),isSpacePanning:()=>this._isSpacePanning,handleBoxSelectionStart:(t,e)=>{this.controlsManager.setEnabled(!1),this._host?.element&&(this._host.element.style.cursor="crosshair"),this.boxSelectionManager.startSelection(t,e)},handleBoxSelectionUpdate:(t,e)=>{this.boxSelectionManager.updateSelection(t,e)},tryVertexDragStart:t=>{if(!this.vertexGizmoManager.isAttached)return!1;const e=this.cameraManager.activeCamera;if(!e)return!1;const n=this.eventManager.mouse,i=this.vertexGizmoManager.onPointerDown(n,e,t);return i&&this.controlsManager.setEnabled(!1),i},handleVertexDragMove:t=>{const e=this.cameraManager.activeCamera;if(!e)return;const n=this.eventManager.mouse;this.vertexGizmoManager.onPointerMove(n,e,t),this._host?.invalidate()},handleVertexDragEnd:t=>{this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),this._host?.invalidate()},handleBoxSelectionEnd:(t,e)=>{this.controlsManager.setEnabled(!0),this._host?.element&&(this._host.element.style.cursor="");const n=this.cameraManager.activeCamera,i=this.sceneManager.scene,s=this._host?.components||[];if(n&&i){let r=this.boxSelectionManager.endSelection(n,i,s);if(e&&t){const t=this._host?.root?.selected||[];if(t.length>0){const e=t[0].state?.type;e&&(r=r.filter(t=>t.state?.type===e))}}if(r.length>0&&this._host?.root)if(t){const t=this._host,e=(this._host.root.selected||[]).filter(e=>e!==t);for(const t of r)e.includes(t)||e.push(t);this._host.root.selected=e}else this._host.root.selected=r}else this.boxSelectionManager.cancelSelection()}}}_handleClickAt(t){const n=this._host,i=this.cameraManager.activeCamera;if(!i||!this.sceneManager.scene)return;if(this._pathMarkers&&this._pathMarkers.children.length>0){const t=new e.Raycaster,n=this.eventManager.mouse;t.setFromCamera(n,i);const s=t.intersectObjects(this._pathMarkers.children,!0);if(s.length>0){let t=s[0].object;for(;t&&void 0===t.userData.bookmarkSlotIndex;)t=t.parent;if(t&&void 0!==t.userData.bookmarkSlotIndex)return void this.animateToSlot(t.userData.bookmarkSlotIndex)}}if(this.vertexGizmoManager?.isDragging)return this.vertexGizmoManager.onPointerUp(),this.controlsManager.setEnabled(!0),void this._host?.invalidate();const s=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),s)return;const r=this.eventManager.handleClick(i,this.sceneManager.scene,t);if(n.root){const t=n.app?.mode;if(4===t||5===t){if(!r?.component){const e=4===t?"stylepastestop":"databindpastestop";n.root.trigger(e)}return}}n.app?.isEditMode&&n.root&&(this._applySelection(n.root,r?.component,t.shiftKey),fu(r)&&(this._updateSelectionOutline(n.root.selected??[]),this._host?.invalidate()))}_applySelection(t,e,n){if(e)if(n){const n=(t.selected||[]).slice(),i=n.indexOf(e);-1===i?n.push(e):n.splice(i,1),t.selected=n}else{let n=null,i=e.parent;for(;i?.isGroup?.();)n=i,i=i.parent;if(n){if(!(t.selected||[]).some(t=>{if(t===n)return!0;let e=t.parent;for(;e?.isGroup?.();){if(e===n)return!0;e=e.parent}return!1}))return void(t.selected=[n])}t.selected=[e]}else n||(t.selected=[])}getObjectByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectByRaycast(t,this.sceneManager.scene):void 0}getObjectsByRaycast(){if(!this.sceneManager.scene)return;const t=this.cameraManager.activeCamera;return t?this.eventManager.getObjectsByRaycast(t,this.sceneManager.scene):void 0}_updateMouseNDCFromClient(t,e){const n=this._host?.element;if(n){const i=n.getBoundingClientRect();if(i.width>0&&i.height>0){const n=t-i.left,s=e-i.top;return void this.eventManager.updateMouseNDC(n,s,0,0,i.width,i.height)}}const i=this._host;if(i){const{left:n,top:s,width:r,height:o}=i.bounds;r>0&&o>0&&this.eventManager.updateMouseNDC(t,e,n,s,Math.abs(r),Math.abs(o))}}_eventToNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0)return{ndcX:(t.clientX-n.left)/n.width*2-1,ndcY:-(t.clientY-n.top)/n.height*2+1}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const s=n.transcoordC2S(t.offsetX,t.offsetY);return{ndcX:s.x/Math.abs(e)*2-1,ndcY:-(s.y/Math.abs(i)*2-1)}}}return{ndcX:0,ndcY:0}}_updateMouseNDC(t){const e=this._host?.element;if(e){const n=e.getBoundingClientRect();if(n.width>0&&n.height>0){const e=t.clientX-n.left,i=t.clientY-n.top;return void this.eventManager.updateMouseNDC(e,i,0,0,n.width,n.height)}}const n=this._host;if(n?.transcoordC2S){const{width:e,height:i}=n.bounds;if(Math.abs(e)>0&&Math.abs(i)>0){const s=n.transcoordC2S(t.offsetX,t.offsetY);this.eventManager.updateMouseNDC(s.x,s.y,0,0,Math.abs(e),Math.abs(i))}}}onMouseUp(t){if(this.controlsManager.isActive){const e=this.gizmoManager.isDragging;if(this.gizmoManager.forwardEvent(t,"pointerup"),e)return t.stopPropagation(),!0;const n=this.cameraManager.activeCamera;this._updateMouseNDC(t);const i=this.eventManager.handleClick(n,this.sceneManager.scene,t),s=this._host;return s?.app?.isEditMode&&s.root&&this._applySelection(s.root,i?.component,t.shiftKey),t.stopPropagation(),!0}return!1}onMouseMove(t){if(this.controlsManager.isActive){this.gizmoManager.forwardEvent(t,"pointermove");const e=this.cameraManager.activeCamera;return this._updateMouseNDC(t),this.eventManager.handleHover(e,this.sceneManager.scene,t),t.stopPropagation(),!0}return!1}onMouseDown(t){return!(!this.controlsManager.isActive||(this.gizmoManager.forwardEvent(t,"pointerdown"),!this.gizmoManager.isDragging))&&(t.stopPropagation(),!0)}onMouseLeave(t){return!1}onWheel(t){if(this.controlsManager.isActive){const{ndcX:e,ndcY:n}=this._eventToNDC(t);if("perspective"!==this.cameraManager.activeView){const i=t.deltaY>0?.9:1.1;this.controlsManager.zoomOrthoAtCursor(i,e,n),this.renderThreeD()}else{const i=Math.pow(.999,-t.deltaY);this.controlsManager.dollyAtCursor(i,e,n),this.renderThreeD()}return t.stopPropagation(),!0}return!1}onDblClick(t){if(!this.controlsManager.isActive)return!1;const e=this._host,n=this.cameraManager.activeCamera;if(!n||!this.sceneManager.scene)return this.controlsManager.reset(),!0;if(e?.app?.isEditMode&&e.root){if(this.vertexGizmoManager.isAttached){const t=this.eventManager.mouse;if(this.vertexGizmoManager.onDblClick(t,n))return this._host?.invalidate(),!0}const t=this.eventManager.getObjectByRaycast(n,this.sceneManager.scene),e=t?.userData?.context?.component;if(e?.hasTextProperty)return Wp(e,this.rendererManager,()=>{this.renderThreeD()}),!0}return this.controlsManager.reset(),t.stopPropagation(),!0}pinResetPosition(){this.controlsManager.pinResetPosition()}onDragStart(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(t.stopPropagation(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.bookmarkManager.stopPlay(),this.controlsManager.onDragStart(t),t.stopPropagation(),!0))}onDragMove(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointermove"),t.stopPropagation(),!0):(this.controlsManager.onDragMove(t),t.stopPropagation(),!0))}onDragEnd(t){return!!this.controlsManager.isActive&&(this.gizmoManager.isDragging?(this.gizmoManager.forwardEvent(t,"pointerup"),t.stopPropagation(),!0):(this.controlsManager.onDragEnd(t),t.stopPropagation(),!0))}onTouchStart(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchStart(t),t.stopPropagation(),!0)}onPan(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchMove(t),t.stopPropagation(),!0)}onTouchEnd(t){return!!this.controlsManager.isActive&&(this.controlsManager.onTouchEnd(t),t.stopPropagation(),!0)}onKeyDown(t){return!t.isComposing&&229!==t.keyCode&&(!!this.controlsManager.isActive&&(!!this._handleEscapeKey(t)||(!(!this._host?.app?.isEditMode||!this._handleEditModeKey(t))||(!!this._handleCursorHintKey(t)||(!!this._handleCameraAndViewKey(t)||(!!this._handlePlaybackKey(t)||(!t.shiftKey||t.ctrlKey||t.metaKey||t.altKey||"KeyB"!==t.code||!this._host?.app?.isEditMode?(this.controlsManager.onKeyDown(t),t.ctrlKey||t.metaKey||t.stopPropagation(),!0):(this.onBookmarkEditToggle?.(),t.preventDefault(),!0))))))))}_handleEscapeKey(t){if("Escape"!==t.key&&"Escape"!==t.code)return!1;if(this.placementManager.isActive&&this._host?.root)return this._host.root.trigger("addstop"),t.stopPropagation(),!0;const e=this._host?.app,n=this._host?.root;return e&&4===e.mode?(n?.trigger("stylepastestop"),!0):e&&5===e.mode?(n?.trigger("databindpastestop"),!0):!(!e?.isEditMode||!n)&&(this.gizmoManager.detach(),n.selected=[],!0)}_handleEditModeKey(t){const e=this._host.root;if(t.metaKey||t.ctrlKey)switch(t.code){case"KeyZ":{const n=this._host?.app?.commander,i=(e?.selected||[]).filter(t=>t!==this._host).map(t=>t.state?.id).filter(Boolean);if(t.shiftKey?n?.redo():n?.undo(),e&&i.length>0){const t=i.map(t=>e.findById(t)).filter(Boolean);t.length>0&&(e.selected=t)}return t.preventDefault(),!0}case"KeyC":return e&&(this._clipboard=Bh.call(e)),t.preventDefault(),!0;case"KeyX":return e&&(this._clipboard=Gh.call(e)),t.preventDefault(),!0;case"KeyV":return e&&this._clipboard&&Vh.call(e,this._clipboard),t.preventDefault(),!0;case"KeyD":return e&&(this._clipboard=Bh.call(e),this._clipboard&&Vh.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 Wp(n[0],this.rendererManager,()=>{this.renderThreeD()}),t.preventDefault(),!0}switch(t.code){case"KeyW":return this.setGizmoMode("translate"),!0;case"KeyE":return this.setGizmoMode("rotate"),!0;case"KeyR":return this.setGizmoMode("scale"),!0;case"Delete":case"Backspace":return e&&zh.call(e),!0}return this._handleArrowKeyMove(t,e)}_handleArrowKeyMove(t,e){const n=e?.selected;if(!n||0===n.length)return!1;const i=t.shiftKey?this._host.MPP||10:1;let s;switch(t.code){case"ArrowLeft":s={x:-i,y:0};break;case"ArrowRight":s={x:i,y:0};break;case"ArrowUp":s={x:0,y:-i};break;case"ArrowDown":s={x:0,y:i}}return!!s&&(ll.around(this._host.app.commander,()=>{n.forEach(t=>{t.stuck||t.move(s,!1)})}),t.preventDefault(),t.stopPropagation(),!0)}_handleCursorHintKey(t){return!(t.repeat||!this._host?.app?.isEditMode)&&("AltLeft"===t.code||"AltRight"===t.code?(this._host?.element&&(this._host.element.style.cursor="grab"),!0):("ShiftLeft"===t.code||"ShiftRight"===t.code)&&(this._host?.element&&(this._host.element.style.cursor=this.gizmoManager.isEngaged?"grab":"crosshair"),!0))}_handleCameraAndViewKey(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return!1;switch(t.code){case"KeyQ":case"Digit0":return!!wu()&&(this._host?.toggleThreeD?.(),t.preventDefault(),!0);case"Digit1":return this.setCameraView("perspective"),t.preventDefault(),!0;case"Digit2":return this.setCameraView("top"),t.preventDefault(),!0;case"Digit3":return this.setCameraView("front"),t.preventDefault(),!0;case"Digit4":return this.setCameraView("back"),t.preventDefault(),!0;case"Digit5":return this.setCameraView("right"),t.preventDefault(),!0;case"Digit6":return this.setCameraView("left"),t.preventDefault(),!0;case"KeyH":return this.onHelpToggle?.(),t.preventDefault(),!0;case"KeyB":return this.onBookmarkNavToggle?.(),t.preventDefault(),!0;case"KeyF":return this.onSearchToggle?.(),t.preventDefault(),!0;case"KeyD":return this.onDataBindingToggle?.(),t.preventDefault(),!0;case"KeyM":return this.onMonitorToggle?.(),t.preventDefault(),!0}return!1}_handlePlaybackKey(t){return!(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)&&("KeyP"!==t.code||this._host?.app?.isEditMode?"Space"===t.code&&this._host?.app?.isEditMode?(this._isSpacePanning=!0,this._beforeSpaceMode=this._host.app.mode,this._host.app.mode=2,this._host?.element&&(this._host.element.style.cursor="grab"),t.preventDefault(),!0):"Space"!==t.code||this._host?.app?.isEditMode?"KeyO"===t.code&&!this._host?.app?.isEditMode&&(this.bookmarkManager.resetPlay(),this.bookmarkManager.toggleOrbitRotation(this.controlsManager),t.preventDefault(),!0):(this.bookmarkManager.isOrbitRotating||this.bookmarkManager.isOrbitPaused?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):(this.bookmarkManager.isPlaying||this.bookmarkManager.lastPlayProgress>=0)&&this.togglePlay(),t.preventDefault(),!0):(this.bookmarkManager.stopOrbitRotation(this.controlsManager),this.restartPlay(),t.preventDefault(),!0))}_onKeyUp(t){return"AltLeft"===t.code||"AltRight"===t.code||"ShiftLeft"===t.code||"ShiftRight"===t.code?(this._host?.element&&!this._isSpacePanning&&(this._host.element.style.cursor=""),!0):!("Space"!==t.code||!this._isSpacePanning)&&(this._isSpacePanning=!1,void 0!==this._beforeSpaceMode&&this._host?.app&&(this._host.app.mode=this._beforeSpaceMode,this._beforeSpaceMode=void 0),this._host?.element&&(this._host.element.style.cursor=""),t.preventDefault(),!0)}onPinch(t){if(this.controlsManager.isActive){if("perspective"!==this.cameraManager.activeView){const e=this.cameraManager.activeCamera,n=t.scale||1;e.zoom=Math.max(.1,Math.min(20,e.zoom*n)),e.updateProjectionMatrix(),this.controlsManager.markCameraChanged(),this.renderThreeD()}else{const e=t.scale||1;Math.abs(e-1)>.01&&(this.controlsManager.dollyAtCursor(1/e,0,0),this.renderThreeD())}return t.stopPropagation(),!0}return!1}onDoubleTap(){this.controlsManager.reset()}getCameraState(){const t=this._host;if(!t)return null;const e=this.cameraManager.camera;if(!e)return null;const{width:n,height:i}=t.bounds,s=Math.floor(Math.min(n,i))||1;return{view:this.cameraManager.activeView,cameraX:e.position.x/(n||1),cameraY:e.position.z/(i||1),cameraZ:e.position.y/s}}getCameraWorldState(){const t=this.cameraManager.camera;if(!t)return null;const e=this.controlsManager.target;return{position:{x:t.position.x,y:t.position.y,z:t.position.z},target:{x:e.x,y:e.y,z:e.z}}}captureSessionState(){const t=this.cameraManager.activeView,e=this.cameraManager.camera,n=this.controlsManager.target,i={view:t};return e&&(i.perspPosition={x:e.position.x,y:e.position.y,z:e.position.z}),i.orbitTarget={x:n.x,y:n.y,z:n.z},i}captureViewportInfo(){const t=this.cameraManager.activeCamera,e=this.controlsManager.target.clone();let n=0,i=0;if(t?.fov){i=2*t.position.distanceTo(e)*Math.tan(t.fov*Math.PI/180/2),n=i*(t.aspect||1)}return{target:e,visibleWidth:n,visibleHeight:i}}restoreSessionState(t){"perspective"!==t.view&&this.setCameraView(t.view,{render:!1});const n=this.cameraManager.camera;n&&t.perspPosition&&n.position.set(t.perspPosition.x,t.perspPosition.y,t.perspPosition.z),t.orbitTarget&&this.controlsManager.restoreTarget(new e.Vector3(t.orbitTarget.x,t.orbitTarget.y,t.orbitTarget.z))}saveCameraToSlot(t){if(!this._host?.app?.isEditMode)return;const n=this.cameraManager.camera;if(!n)return;if("perspective"!==this.cameraManager.activeView)return;const i=this.controlsManager.target,s=n.position;let r=i.x,o=i.y,a=i.z;if(s.distanceTo(i)<1){const t=new e.Vector3(0,0,-1).applyQuaternion(n.quaternion);r=s.x+1*t.x,o=s.y+1*t.y,a=s.z+1*t.z}const c={position:{x:s.x,y:s.y,z:s.z},target:{x:r,y:o,z:a}};this.bookmarkManager.saveSlot(t,c),this._host?.app?.isEditMode&&this._host?.set?.("cameraBookmarks",this.bookmarkManager.exportSlots()),this.onBookmarkChanged?.()}positionCameraForViewport(t,n,i,s,r){const o=this.cameraManager.activeCamera;if(!o?.position)return;const a=(o.fov||45)*Math.PI/180,c=o.aspect||1,l=s/2/Math.tan(a/2),h=i/2/(c*Math.tan(a/2)),d=Math.max(l,h),u=r?.orbitTarget?.y??0,p=new e.Vector3(t,u,n);let f;if(r?.perspPosition&&r?.orbitTarget){const t=new e.Vector3(r.perspPosition.x,r.perspPosition.y,r.perspPosition.z),n=new e.Vector3(r.orbitTarget.x,r.orbitTarget.y,r.orbitTarget.z);f=t.sub(n).normalize()}else f=o.position.clone().normalize();o.position.copy(p.clone().add(f.multiplyScalar(d)));try{this.controlsManager.restoreTarget(p)}catch{o.lookAt(p)}this._host?.invalidate()}centerToComponent(t,n){const i=this.cameraManager.activeCamera;if(!i)return;const s=new e.Vector3,r=t._realObject;if(r?.object3d)r.object3d.getWorldPosition(s);else{const{x:e=0,y:n=0}=t.center,{width:i=0,height:r=0}=t.parent?.bounds??{};s.set(e-i/2,0,n-r/2)}const o=this.controlsManager.target,a=i.position.clone().sub(o),c=s.clone().add(a);if(!n)return i.position.copy(c),this.controlsManager.restoreTarget(s),void this._host?.invalidate();const l=i.position.clone(),h=o.clone(),d=performance.now(),u=()=>{const t=performance.now()-d,e=Math.min(t/800,1),n=e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2;i.position.lerpVectors(l,c,n);const r=h.clone().lerp(s,n);this.controlsManager.restoreTarget(r),this._host?.invalidate(),e<1&&requestAnimationFrame(u)};requestAnimationFrame(u)}animateToSlot(t){const e=this.cameraManager.camera;e&&(this.bookmarkManager.isPlaying&&this.bookmarkManager.stopPlay(),"perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.animateToSlot(t,e,this.controlsManager),this.bookmarkManager.setProgressForSlot(t))}scrubPath(t){const e=this.cameraManager.camera;if(!e)return;const n=this.bookmarkManager.evaluatePath(t);n&&(e.position.copy(n.position),this.controlsManager.restoreTarget(n.target),this._host?.invalidate())}togglePlay(t=-1){const e=this.cameraManager.camera;if(e){if("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.isPlaying)return this.bookmarkManager.stopPlay(),void(this._pathVisible&&this.showBookmarkPath());this.hideBookmarkPath(),this.bookmarkManager.startPlay(e,this.controlsManager,2e3,1200,t)}}restartPlay(){const t=this.cameraManager.camera;t&&("perspective"!==this.cameraManager.activeView&&this.setCameraView("perspective",{render:!1}),this.bookmarkManager.stopPlay(),this.hideBookmarkPath(),this.bookmarkManager.startPlay(t,this.controlsManager,2e3,1200,-1,!0))}startAutoPlay(t){"orbit"===t?this.bookmarkManager.toggleOrbitRotation(this.controlsManager):"play"===t&&this.togglePlay()}showBookmarkPath(){this._pathVisible=!0,this.hideBookmarkPath();const t=this.sceneManager.scene;if(!t)return;const n=this.bookmarkManager.getPlayableSlots();if(0===n.length)return;const i=[];for(const t of n){const n=this.bookmarkManager.getSlot(t);n&&i.push(new e.Vector3(n.position.x,n.position.y,n.position.z))}if(i.length>=2){let n=0;for(let t=1;t<i.length;t++)n+=i[t].distanceTo(i[t-1]);const s=n/(i.length-1),r=i.length>=3?new e.CatmullRomCurve3(i,!0,"centripetal").getPoints(30*i.length):i,o=(new e.BufferGeometry).setFromPoints(r),a=new e.LineDashedMaterial({color:4890367,dashSize:.06*s,gapSize:.03*s,opacity:.5,transparent:!0,depthTest:!1});this._pathLine=new e.Line(o,a),this._pathLine.computeLineDistances(),this._pathLine.renderOrder=9999,t.add(this._pathLine)}let s;if(i.length>=2){let t=0;for(let e=1;e<i.length;e++)t+=i[e].distanceTo(i[e-1]);s=t/(i.length-1)*.08}else{const t=this.bookmarkManager.getSlot(n[0]);s=.08*(t?new e.Vector3(t.position.x,t.position.y,t.position.z).distanceTo(new e.Vector3(t.target.x,t.target.y,t.target.z)):10)}this._pathMarkers=new e.Group,this._pathMarkers.renderOrder=9999;const r=new e.MeshBasicMaterial({color:4890367,opacity:.6,transparent:!0,depthTest:!1}),o=new e.MeshBasicMaterial({color:4890367,opacity:.15,transparent:!0,depthTest:!1,side:e.DoubleSide});for(const t of n){const n=this.bookmarkManager.getSlot(t);if(!n)continue;const i=new e.Vector3(n.position.x,n.position.y,n.position.z),a=new e.Vector3(n.target.x,n.target.y,n.target.z),c=(new e.Vector3).subVectors(a,i).normalize(),l=new e.Group;l.position.copy(i);const h=(new e.Matrix4).lookAt(new e.Vector3(0,0,0),c,new e.Vector3(0,1,0));l.quaternion.setFromRotationMatrix(h);const d=.2*s,u=new e.BoxGeometry(1.2*d,.8*d,d),p=new e.Mesh(u,r);p.renderOrder=9999,l.add(p);const f=Math.max(.06*i.distanceTo(a),.5*d),m=.35*f,g=9*m/16,y=new e.BufferGeometry,b=[0,0,0,-m,g,-f,m,g,-f,m,-g,-f,-m,-g,-f],_=[0,1,2,0,2,3,0,3,4,0,4,1];y.setAttribute("position",new e.Float32BufferAttribute(b,3)),y.setIndex(_),y.computeVertexNormals();const v=new e.Mesh(y,o);v.position.z=.5*-d,v.renderOrder=9999,l.add(v);const x=new Float32Array([0,0,0,-m,g,-f,0,0,0,m,g,-f,0,0,0,m,-g,-f,0,0,0,-m,-g,-f,-m,g,-f,m,g,-f,m,g,-f,m,-g,-f,m,-g,-f,-m,-g,-f,-m,-g,-f,-m,g,-f]),w=new e.BufferGeometry;w.setAttribute("position",new e.BufferAttribute(x,3));const M=new e.LineSegments(w,new e.LineBasicMaterial({color:4890367,opacity:.5,transparent:!0,depthTest:!1}));M.position.z=.5*-d,M.renderOrder=9999,l.add(M),l.userData.bookmarkSlotIndex=t,this._pathMarkers.add(l)}t.add(this._pathMarkers),this._host?.invalidate()}hideBookmarkPath(t=!1){t&&(this._pathVisible=!1);const e=this.sceneManager.scene;if(this._pathLine&&(e?.remove(this._pathLine),this._pathLine.geometry.dispose(),this._pathLine.material.dispose(),this._pathLine=void 0),this._pathMarkers){e?.remove(this._pathMarkers);const t=new Set;this._pathMarkers.traverse(e=>{e.geometry&&e.geometry.dispose();const n=e.material;n&&!t.has(n)&&(n.dispose(),t.add(n))}),this._pathMarkers=void 0}this._host?.invalidate()}initBookmarks(){const t=this._host;if(!t)return;const e=t.state.cameraBookmarks;Array.isArray(e)&&this.bookmarkManager.importSlots(e),this.bookmarkManager.setCallbacks(()=>this._host?.invalidate())}onchange(t){if(t.hasOwnProperty("autoRotate")&&this.controlsManager.setAutoRotate(t.autoRotate),t.hasOwnProperty("cameraFloorConstraint")){const e=!this._host?.app?.isEditMode;this.controlsManager.setFloorConstraint(e&&!!t.cameraFloorConstraint)}if(t.hasOwnProperty("fov")||t.hasOwnProperty("near")||t.hasOwnProperty("far")){const t=this._host;if(t){const{near:e,far:n,fov:i}=t.state;this.cameraManager.updateProperties({near:e,far:n,fov:i}),this.controlsManager.markCameraChanged()}}t.hasOwnProperty("exposure")&&(this.rendererManager.setExposure(Number(t.exposure)||1),this.renderThreeD());let e=!1;if((t.hasOwnProperty("hemiIntensity")||t.hasOwnProperty("hemiSkyColor")||t.hasOwnProperty("hemiGroundColor"))&&(this.lightManager.updateHemisphere({intensity:t.hemiIntensity,skyColor:t.hemiSkyColor,groundColor:t.hemiGroundColor}),e=!0),t.hasOwnProperty("dirLightEnabled")){const n=this._host;n&&this.lightManager.setDirectionalEnabled(t.dirLightEnabled,{color:n.state.dirLightColor,intensity:n.state.dirLightIntensity}),e=!0}if((t.hasOwnProperty("dirLightColor")||t.hasOwnProperty("dirLightIntensity"))&&(this.lightManager.updateDirectional({color:t.dirLightColor,intensity:t.dirLightIntensity}),e=!0),t.hasOwnProperty("dirLightFollowCamera")){if(this.lightManager.setDirectionalFollowCamera(!1!==t.dirLightFollowCamera),!1===t.dirLightFollowCamera){const t=this._host?.state;this.lightManager.setDirectionalAngle(t?.dirLightAzimuth??30,t?.dirLightElevation??45)}e=!0}if(t.hasOwnProperty("dirLightAzimuth")||t.hasOwnProperty("dirLightElevation")){const n=this._host?.state;!1===n?.dirLightFollowCamera&&this.lightManager.setDirectionalAngle(t.dirLightAzimuth??n?.dirLightAzimuth??30,t.dirLightElevation??n?.dirLightElevation??45),e=!0}if(t.hasOwnProperty("dirShadowEnabled")||t.hasOwnProperty("dirShadowBias")){const n=this.lightManager.dirLight;n&&(t.hasOwnProperty("dirShadowEnabled")&&(n.castShadow=!1!==t.dirShadowEnabled),t.hasOwnProperty("dirShadowBias")&&(n.shadow.bias=t.dirShadowBias??-5e-4)),e=!0}e&&this.renderThreeD(),(t.hasOwnProperty("fillStyle")||t.hasOwnProperty("floor")||t.hasOwnProperty("floorMaterial3d"))&&(this.sceneManager.updateFloor(this._host),this.renderThreeD()),(t.hasOwnProperty("sky")||t.hasOwnProperty("skyColor")||t.hasOwnProperty("environment"))&&(this.sceneManager.setSky(this._host.state.sky,this._host.state.skyColor,this._host.state.environment),this.renderThreeD()),t.hasOwnProperty("placement")&&(this.sceneManager.updateFloor(this._host),this._cascadeUpdateTransform(this._host),this.renderThreeD())}_cascadeUpdateTransform(t){const e=t?._realObject;e&&e.updateTransform?.();const n=t?.components;if(n)for(const t of n)this._cascadeUpdateTransform(t)}get domElement(){return this.rendererManager.domElement}getRendererSize(){return this.rendererManager.getSize()}showWebglNoSupportText(t,e,n){t.save(),t.font=e/20+"px Arial",t.textAlign="center",t.fillText("WebGL no support",e/2-e/40,n/2),t.restore()}showDebugFPS(t){t.font="100px Arial",t.textAlign="center",t.fillStyle="black",t.globalAlpha=.5,t.fillText(String(Pp()),100,100)}get decoratorOutlines(){return this._decoratorOutlines}addOutline(t){this._decoratorOutlines.add(t),this._syncOutlinePass(),this._host?.invalidate()}removeOutline(t){this._decoratorOutlines.delete(t),this._syncOutlinePass(),this._host?.invalidate()}clearOutlines(){this._decoratorOutlines.clear(),this._syncOutlinePass(),this._host?.invalidate()}addArrow(t,n,i,s={}){this.removeArrow(t);const r=n._realObject,o=i._realObject;if(!r?.object3d||!o?.object3d)return;const a=new e.Vector3,c=new e.Vector3;r.object3d.getWorldPosition(a),o.object3d.getWorldPosition(c),a.y+=1,c.y+=1;const l=this.rendererManager.getSize(),h=Lp(a,c,s,new e.Vector2(l.width,l.height));h.name=`arrow-${t}`,h.userData._arrowStyle=s,this.sceneManager.scene?.add(h),this._arrows.set(t,h),this._host?.invalidate()}setOutlineColor(t){this.rendererManager.setOutlineColor(t)}removeArrow(t){const n=this._arrows.get(t);n&&(n.traverse(t=>{if(t instanceof w)return t.geometry.dispose(),void t.material.dispose();if(t instanceof e.Sprite){const e=t.material.map;if(e){e.dispose();const t=e.source?.data;t instanceof HTMLCanvasElement&&(t.width=0,t.height=0)}return void t.material.dispose()}(t instanceof e.Mesh||t instanceof e.Line)&&(t.geometry.dispose(),t.material instanceof e.Material&&t.material.dispose())}),n.removeFromParent(),this._arrows.delete(t),this._host?.invalidate())}clearArrows(){for(const t of this._arrows.keys())this.removeArrow(t)}updateArrow(t,e,n){const i=this._getArrowStyle(t);i&&this.addArrow(t,e,n,i)}_getArrowStyle(t){const e=this._arrows.get(t);return e?e.userData._arrowStyle??null:null}highlightBookmarkMarker(t){this._highlightedMarkerIndex!==t&&(this._highlightedMarkerIndex=t,this._syncOutlinePass(),this._host?.invalidate())}clearBookmarkMarkerHighlight(){-1!==this._highlightedMarkerIndex&&(this._highlightedMarkerIndex=-1,this._syncOutlinePass(),this._host?.invalidate())}_syncOutlinePass(){const t=[...this._selectionOutlineObjects];for(const e of this._decoratorOutlines){const n=e._realObject;n?.object3d&&!t.includes(n.object3d)&&t.push(n.object3d)}if(this._highlightedMarkerIndex>=0&&this._pathMarkers)for(const e of this._pathMarkers.children)if(e.userData.bookmarkSlotIndex===this._highlightedMarkerIndex){e.traverse(e=>{e.isMesh&&t.push(e)});break}this.rendererManager.setOutlineObjects(t)}_handleSelectionChanged(t){const e=t.filter(t=>t!==this._host&&t._realObject);if(e.length>=1){const t=e[0]._realObject;t?.object3d&&t.gizmoTransformable&&!e[0].stuck?this.gizmoManager.attached&&this.gizmoManager.attach(t.object3d):this.gizmoManager.detach()}else this.gizmoManager.detach();const n=e.filter(t=>t.mutable&&t.path);n.length>0&&this.sceneManager.scene?this.vertexGizmoManager.attachMultiple(n,this.sceneManager.scene,this._host?.app?.commander):this.vertexGizmoManager.detach(),this._updateSelectionOutline(e),this._host?.invalidate()}_updateSelectionOutline(t){this._selectionOutlineObjects=[];for(const e of t){const t=e._realObject;if(!t?.object3d)continue;const n=fu(t)&&t.pickedPart?t.partObject(t.pickedPart):void 0;this._selectionOutlineObjects.push(n??t.object3d)}this._syncOutlinePass()}}Fc.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 If='<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>',Rf='<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>',jf='<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>',Lf='<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>',Ff='<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>',Nf='<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>',Hf=[{label:"Camera",requires3dAvailable:!0,items:[{key:"1",desc:"Perspective",icon:If},{key:"2",desc:"Top",icon:Rf},{key:"3",desc:"Front",icon:jf},{key:"4",desc:"Back",icon:Lf},{key:"5",desc:"Right",icon:Ff},{key:"6",desc:"Left",icon:Nf},{key:"0 / Q",desc:"Exit 3D",requires3d:!0}]},{label:"Bookmarks",requires3d:!0,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",requires3d:!0,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,requires3d:!0},{key:"E",desc:"Rotate gizmo",editOnly:!0,requires3d:!0},{key:"R",desc:"Scale gizmo",editOnly:!0,requires3d:!0},{key:"Ctrl+Z",desc:"Undo",editOnly:!0},{key:"Ctrl+Shift+Z",desc:"Redo",editOnly:!0},{key:"Ctrl+C",desc:"Copy",editOnly:!0},{key:"Ctrl+X",desc:"Cut",editOnly:!0},{key:"Ctrl+V",desc:"Paste",editOnly:!0},{key:"Ctrl+Shift+V",desc:"Bulk paste (N copies)",editOnly:!0},{key:"Del",desc:"Delete selected",editOnly:!0},{key:"Esc",desc:"Deselect all",editOnly:!0}]},{label:"Drag modifiers",items:[{key:"Ctrl+Drag",desc:"Suppress snap",editOnly:!0},{key:"Ctrl+Shift+Drag",desc:"Box select same type",editOnly:!0}]},{label:"Misc",items:[{key:"H",desc:"This help"},{key:"F",desc:"Search"}]}];function Bf(t){const{threed:e,edit:n}=t,i=t.threedAvailable??e;return Hf.filter(t=>!(t.requires3d&&!e||t.requires3dAvailable&&!i)).map(t=>({...t,items:t.items.filter(t=>!(t.requires3d&&!e)&&(!(t.requires3dAvailable&&!i)&&(!(t.editOnly&&!n)&&(!t.viewOnly||!n))))})).filter(t=>t.items.length>0)}const Gf={x:1,y:1},Vf={x:0,y:0},Yf={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"]}},{type:"checkbox",label:"logarithmic-depth",name:"logarithmicDepth"}]};class Wf extends lp{constructor(){super(...arguments),this._outlineColor=15885602,this._outlineDecoColor="#f262227f",this._threeDActivationPending=!1,this._rebuildPreserveThreeD=!1}get volatile(){return[...super.volatile,"scale","translate"]}get nature(){return Yf}get is3dMode(){return!!this._threeCapability?.isInitialized}get _threedEnabled(){return wu()}is3dContainer(){return this.is3dMode}get hasEnvironment(){return this._threeCapability?.hasEnvironment??!1}get gizmoMode(){return this._threeCapability?.gizmoMode}setGizmoMode(t){this._threeCapability?.setGizmoMode(t)}fitCameraToModel(t=1.15){const e=this._threeCapability;if(!e)return void(this._pendingFitMargin=t);if(void 0!==this.get("cameraX")||void 0!==this.get("cameraY"))return;const n=Number(this.get("width"))||0,i=Number(this.get("height"))||0;if(!(n>0&&i>0))return;this._resizeThreeD(!0);const s=Number(this.get("depth"))||0,r=s/2;e.positionCameraForViewport(0,0,n*t,Math.max(i,s)*t,{view:"perspective",orbitTarget:{x:0,y:r,z:0}})}toggleHelp(){this._toggleHelpPanel()}toggleBookmarkNavigator(){this._toggleBookmarkNav()}toggleBookmarkEditor(){this._toggleBookmarkEdit()}setCameraView(t){this.is3dMode?this._threeCapability?.setCameraView(t):this._threedEnabled&&(this._pendingCameraView=t,this.toggleThreeD(!0))}get scene3d(){return this._threeCapability?.scene3d}get renderer3d(){return this._threeCapability?.renderer3d}get activeCamera3d(){return this._threeCapability?.activeCamera}get mixer(){return this._threeCapability?.mixer}addArrow3D(t,e,n,i){this._threeCapability?.addArrow(t,e,n,i)}removeArrow3D(t){this._threeCapability?.removeArrow(t)}setOutlineColor(t){this._outlineColor=t,this._threeCapability?.setOutlineColor(t),this._outlineDecoColor="#"+t.toString(16).padStart(6,"0").slice(0,6)+"7f"}clearArrows3D(){this._threeCapability?.clearArrows()}_buildLightingConfig(){const t=this.state,e={hemisphere:{skyColor:t.hemiSkyColor||"#ffffff",groundColor:t.hemiGroundColor||"#444444",intensity:t.hemiIntensity??4}};if(!1!==t.dirLightEnabled){const n=!1!==t.dirLightFollowCamera;if(e.directional={color:t.dirLightColor||"#ffffff",intensity:t.dirLightIntensity??2,attachToCamera:n,castShadow:!1!==t.dirShadowEnabled,shadowMapSize:t.dirShadowMapSize??2048,shadowBias:t.dirShadowBias??-5e-4},!n){const n=(t.dirLightAzimuth??30)*Math.PI/180,i=(t.dirLightElevation??45)*Math.PI/180,s=1e3;e.directional.position=[s*Math.cos(i)*Math.sin(n),s*Math.sin(i),s*Math.cos(i)*Math.cos(n)]}}return e}_hide2DLayers(){this.canvas&&(this.canvas.style.display="none"),this._overlay&&(this._overlay.style.display="none"),this._auxCanvas&&(this._auxCanvas.style.display="none"),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="none");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="none")}get _hasZoomHandler(){return(this.root?.model?.handlers||[]).includes("zoom-handler")}get _needsViewportSync(){return!!this.app?.isEditMode||this._hasZoomHandler}_activateThreeD(t=!1){if(!this._threedEnabled)return void(this._threeDActivationPending=!1);ap.hideAll(this.root),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 zf,this._threeCapability.init(this,{lightingConfig:this._buildLightingConfig(),css3DSceneAttribute:"model-layer:css3d-renderer"}),15885602!==this._outlineColor&&this._threeCapability.setOutlineColor(this._outlineColor),this._hide2DLayers(),this.root?.transitionEffect?.dispose();const e=Xr.getInstance(),n=[];this.decoratorOverlay&&(n.push(...e.getTargetsWithType(this.decoratorOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorOverlay,"border-highlighting")),this.decoratorAuxOverlay&&(n.push(...e.getTargetsWithType(this.decoratorAuxOverlay,"border-highlighting")),e.removeAllFromOverlay(this.decoratorAuxOverlay,"border-highlighting"));for(const t of n)this._threeCapability.addOutline(t);if(this._threeCapability.domElement&&this.element){const t=this._threeCapability.domElement;t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.pointerEvents="none",t.setAttribute("scene","model-layer-webgl");const e=this._decoratorOverlay||this.element.firstChild;this.element.insertBefore(t,e)}if(this._threeCapability.buildOverlays(),t&&this._needsViewportSync){const t=this.get("scale")||{x:1};this._2dScaleBeforeThreeD=t.x||1,this._initCameraFrom2DViewport();const e=this._threeCapability?.captureViewportInfo();e&&(this._initialVisibleHeight=e.visibleHeight)}else if(this._lastCameraState)this._threeCapability.restoreSessionState(this._lastCameraState);else{const t=this.model.initialCameraView;t&&"perspective"!==t&&this._threeCapability.setCameraView(t,{render:!1})}if(this._pendingCameraView&&(this._threeCapability.setCameraView(this._pendingCameraView,{render:!1}),delete this._pendingCameraView),void 0!==this._pendingFitMargin){const t=this._pendingFitMargin;this._pendingFitMargin=void 0,this.fitCameraToModel(t)}if(this._threeCapability.initBookmarks(),!this.app?.isEditMode){const t=this.model?.cameraAutoPlay;"orbit"!==t&&"play"!==t||this._threeCapability.startAutoPlay(t)}this.app?.isEditMode&&this._createToolbar(),this._registerPopupCallbacks();const i=this.root;i?.selected?.length>0&&this._threeCapability._handleSelectionChanged(i.selected),this._resizeThreeD(!0),this.element&&"function"==typeof this.element.focus&&this.element.focus(),this._threeDActivationPending=!1}_createToolbar(){if(!this.element)return;if(!this._threedEnabled)return;this._removeToolbar();const t=!!this._threeCapability,e=document.createElement("div");e.setAttribute("scene","threed-toolbar"),e.style.cssText=["position:absolute","top:12px","left:12px","display:flex","flex-direction:column","gap:1px","padding:4px","background:rgba(30,30,30,0.92)","border:1px solid rgba(255,255,255,0.08)","border-radius:8px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 16px rgba(0,0,0,0.4),inset 0 1px 0 rgba(255,255,255,0.05)","user-select:none"].join(";");const n=["width:32px","height:32px","display:flex","align-items:center","justify-content:center","border-radius:5px","cursor:pointer","transition:all 0.12s ease","position:relative"].join(";"),i=(t,e)=>{const i=document.createElement("div");return i.innerHTML=t,i.title=e,i.style.cssText=n,this._applyButtonStyle(i,!1),i.addEventListener("mouseenter",()=>{i.dataset.active||(i.style.background="rgba(255,255,255,0.1)")}),i.addEventListener("mouseleave",()=>{this._applyButtonStyle(i,!!i.dataset.active)}),i},s=()=>{const t=document.createElement("div");return t.style.cssText="height:1px;margin:3px 4px;background:rgba(255,255,255,0.1)",t},r=i(t?'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="14" height="14" rx="1.5"/>\n <line x1="3" y1="10" x2="17" y2="10" opacity="0.4"/>\n <line x1="10" y1="3" x2="10" y2="17" opacity="0.4"/>\n </svg>':'<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2l7 4v8l-7 4-7-4V6l7-4z"/>\n <path d="M10 10l7-4M10 10v8M10 10L3 6"/>\n </svg>',t?"2D Mode":"3D Mode");if(this._applyToggleStyle(r,t),r.addEventListener("mouseenter",()=>{r.style.background=t?"rgba(255,160,60,0.35)":"rgba(255,160,60,0.25)"}),r.addEventListener("mouseleave",()=>{this._applyToggleStyle(r,t)}),r.addEventListener("click",()=>{this.toggleThreeD()}),e.appendChild(r),!t)return e.addEventListener("mousedown",t=>t.stopPropagation()),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),void(this._toolbar=e);e.appendChild(s());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:If,title:"Perspective"},{view:"top",icon:Rf,title:"Top"},{view:"front",icon:jf,title:"Front"},{view:"back",icon:Lf,title:"Back"},{view:"right",icon:Ff,title:"Right"},{view:"left",icon:Nf,title:"Left"}],h=[];for(const{view:t,icon:e,title:n}of l){const s=i(e,n);s.dataset.view=t,t===c&&(this._applyButtonStyle(s,!0),s.dataset.active="1"),s.addEventListener("click",()=>{this._threeCapability?.setCameraView(t)}),h.push(s),a.appendChild(s)}a.appendChild(s());const d=i('<svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">\n <path d="M10 2 L13 5 L12 10 L15 13 L5 13 L8 10 L7 5 Z"/>\n <line x1="10" y1="13" x2="10" y2="18"/>\n </svg>',"Pin Camera View");d.addEventListener("click",()=>{const t=this._threeCapability?.getCameraState();t&&(this.set("cameraX",t.cameraX),this.set("cameraY",t.cameraY),this.set("cameraZ",t.cameraZ),this._threeCapability?.pinResetPosition())}),a.appendChild(d),e.appendChild(a),this._cameraButtons=h,o.onGizmoAttachChanged=t=>{this.root?.trigger("gizmoattach",t)},o.onCameraViewChanged=t=>{this._updateCameraButtons(t)},o.onGizmoModeChanged=t=>{this.root?.trigger("gizmomode",t)},e.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),e.addEventListener("mouseup",t=>t.stopPropagation()),this.target.appendChild(e),this._toolbar=e}_applyToggleStyle(t,e){e?(t.style.background="rgba(255,140,40,0.3)",t.style.color="#ffaa44",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.5)"):(t.style.background="rgba(255,140,40,0.15)",t.style.color="#cc8833",t.style.boxShadow="inset 0 0 0 1.5px rgba(255,140,40,0.3)")}_applyButtonStyle(t,e){e?(t.style.background="rgba(74,158,255,0.25)",t.style.color="#4a9eff",t.style.boxShadow="inset 0 0 0 1.5px rgba(74,158,255,0.5)",t.dataset.active="1"):(t.style.background="transparent",t.style.color="rgba(255,255,255,0.55)",t.style.boxShadow="none",delete t.dataset.active)}_updateCameraButtons(t){this._cameraButtons?.forEach(e=>{this._applyButtonStyle(e,e.dataset.view===t)})}_registerPopupCallbacks(){const t=this._threeCapability;t&&(t.onHelpToggle=()=>this._toggleHelpPanel(),t.onSearchToggle=()=>this.onSearchToggle?.(),t.onDataBindingToggle=()=>this.onDataBindingToggle?.(),t.onMonitorToggle=()=>this.onMonitorToggle?.(),t.onBookmarkNavToggle=()=>this._toggleBookmarkNav(),t.onBookmarkEditToggle=()=>this._toggleBookmarkEdit())}_closeFloatingPopup(){this._floatingPopupCloseHandler&&(this.target?.removeEventListener("mousedown",this._floatingPopupCloseHandler,!0),this._floatingPopupCloseHandler=void 0),this._floatingPopup?.parentNode&&this._floatingPopup.parentNode.removeChild(this._floatingPopup),this._floatingPopup=void 0}_showFloatingPopup(t,e=!1){this._closeFloatingPopup(),this._floatingPopup=t,e||(this._floatingPopupCloseHandler=e=>{t.contains(e.target)||this._closeFloatingPopup()},setTimeout(()=>{this.target?.addEventListener("mousedown",this._floatingPopupCloseHandler,!0)},0)),t.addEventListener("mousedown",t=>{t.stopPropagation();const e=t.target?.tagName;"INPUT"!==e&&"TEXTAREA"!==e&&"SELECT"!==e&&t.preventDefault()}),t.addEventListener("mouseup",t=>t.stopPropagation()),this._makePopupDraggable(t),this.target.appendChild(t)}_makePopupDraggable(t){let e=0,n=0,i=0,s=0;const r=r=>{const o=r.clientX-e,a=r.clientY-n;t.style.left=i+o+"px",t.style.top=s+a+"px"},o=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",r),t.removeEventListener("pointerup",o),t.style.cursor=""};t.addEventListener("pointerdown",a=>{const c=a.target,l=c.tagName?.toLowerCase();if("button"===l||"input"===l||"select"===l||"pointer"===c.style.cursor)return;if(c.closest("[data-drag-handle]"))return;const h=t.getBoundingClientRect(),d=t.parentElement.getBoundingClientRect();i=h.left-d.left,s=h.top-d.top,t.style.left=i+"px",t.style.top=s+"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",r),t.addEventListener("pointerup",o)})}_toggleHelpPanel(){if("help"===this._floatingPopup?.dataset.popupType)return void this._closeFloatingPopup();const t=!!this.app?.isEditMode,e=document.createElement("div");e.dataset.popupType="help",e.style.cssText=["position:absolute","top:50%","left:50%","transform:translate(-50%,-50%)","max-width:min(560px, calc(100% - 40px))","max-height:calc(100% - 40px)","overflow-y:auto","padding:16px 20px","background:rgba(30,30,30,0.94)","border:1px solid rgba(255,255,255,0.08)","border-radius:10px","pointer-events:auto","backdrop-filter:blur(8px)","-webkit-backdrop-filter:blur(8px)","box-shadow:0 4px 20px rgba(0,0,0,0.5)","user-select:none","color:rgba(255,255,255,0.85)","font:12px/1.6 -apple-system,BlinkMacSystemFont,sans-serif","z-index:200"].join(";");const n=document.createElement("div");n.textContent="×",n.style.cssText="position:absolute;top:8px;right:12px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",n.addEventListener("click",()=>this._closeFloatingPopup()),n.addEventListener("mouseenter",()=>{n.style.color="#fff"}),n.addEventListener("mouseleave",()=>{n.style.color="rgba(255,255,255,0.4)"}),e.appendChild(n);const i=document.createElement("div");i.textContent="Help",i.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:12px",e.appendChild(i);const s=document.createElement("div");s.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:0 24px",e.appendChild(s);const r=Bf({threed:this.is3dMode,threedAvailable:this._threedEnabled,edit:t}),o=r.reduce((t,e)=>t+e.items.length+1,0);let a=0,c=r.length;for(let t=0;t<r.length;t++)if(a+=r[t].items.length+1,a>=o/2){c=t+1;break}const l=[r.slice(0,c),r.slice(c)];for(const t of l){const e=document.createElement("div");let n=!0;for(const i of t){if(!n){const t=document.createElement("div");t.style.cssText="height:1px;margin:8px 0;background:rgba(255,255,255,0.08)",e.appendChild(t)}n=!1;const t=document.createElement("div");t.textContent=i.label,t.style.cssText="font-size:10px;font-weight:700;text-transform:uppercase;color:rgba(255,255,255,0.45);margin:0 0 5px;letter-spacing:0.8px",e.appendChild(t);for(const t of i.items){const n=document.createElement("div");n.style.cssText="display:flex;justify-content:space-between;align-items:center;padding:2px 0;gap:12px";const i=document.createElement("span");i.style.cssText="display:inline-flex;gap:2px;flex-shrink:0";for(const e of t.key.split("+")){const n=document.createElement("kbd");if(n.textContent=e.trim(),n.style.cssText="font-size:10px;font-family:monospace;padding:1px 5px;border-radius:3px;background:rgba(255,255,255,0.08);border:1px solid rgba(255,255,255,0.12);color:rgba(255,255,255,0.65);line-height:1.4",i.appendChild(n),e!==t.key.split("+").at(-1)){const t=document.createElement("span");t.textContent="+",t.style.cssText="color:rgba(255,255,255,0.2);font-size:10px;margin:0 1px",i.appendChild(t)}}const s=document.createElement("span");if(s.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",s.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",s.appendChild(e)}n.appendChild(i),n.appendChild(s),e.appendChild(n)}}s.appendChild(e)}this._showFloatingPopup(e)}_toggleBookmarkNav(){"bookmark-nav"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-nav"):this._closeFloatingPopup()}_toggleBookmarkEdit(){"bookmark-edit"!==this._floatingPopup?.dataset.popupType?this._buildBookmarkPopup("bookmark-edit"):this._closeFloatingPopup()}_buildBookmarkPopup(t){const e=this._threeCapability;if(!e)return;const n="bookmark-nav"===t,i=!!this.app?.isEditMode,s=document.createElement("div");s.dataset.popupType=t,s.tabIndex=-1,s.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 r=document.createElement("div");r.textContent="×",r.style.cssText="position:absolute;top:6px;right:10px;cursor:pointer;font-size:18px;color:rgba(255,255,255,0.4);line-height:1",r.addEventListener("click",()=>this._closeFloatingPopup()),r.addEventListener("mouseenter",()=>{r.style.color="#fff"}),r.addEventListener("mouseleave",()=>{r.style.color="rgba(255,255,255,0.4)"}),s.appendChild(r);const o=document.createElement("div");o.textContent="Bookmarks",o.style.cssText="font-size:13px;font-weight:600;color:#4a9eff;margin-bottom:8px;cursor:grab",s.appendChild(o);const a=document.createElement("div");a.style.cssText="display:flex;flex-direction:column;gap:2px",s.appendChild(a);const c=e.bookmarkManager,l=()=>{i&&this.set?.("cameraBookmarks",c.exportSlots()),e.onBookmarkChanged?.()},h="border:none;background:transparent;color:inherit;cursor:pointer;padding:2px 4px;border-radius:4px;font-size:13px;line-height:1;display:flex;align-items:center;justify-content:center;width:24px;height:24px",d=t=>{const e=28,n=window.devicePixelRatio||1,i=document.createElement("canvas");i.width=e*n,i.height=e*n,i.style.cssText="width:28px;height:28px;flex-shrink:0;border-radius:50%;background:rgba(0,0,0,0.3)";const s=i.getContext("2d");s.scale(n,n);const r=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,m=0;d>.001&&(f=c/d,m=l/d);const g=1-.6*p,y=r+f*a*.7*g,b=o+m*a*.7*g;s.strokeStyle="rgba(255,255,255,0.12)",s.lineWidth=1,s.beginPath(),s.arc(r,o,a,0,2*Math.PI),s.stroke(),s.strokeStyle="rgba(255,255,255,0.06)",s.beginPath(),s.moveTo(r,2),s.lineTo(r,26),s.moveTo(2,o),s.lineTo(26,o),s.stroke(),s.fillStyle="rgba(255,255,255,0.25)",s.beginPath(),s.arc(r,o,1.5,0,2*Math.PI),s.fill(),s.strokeStyle=`rgba(74,158,255,${.2+.2*p})`,s.lineWidth=1,s.beginPath(),s.moveTo(y,b),s.lineTo(r,o),s.stroke();const _=.6+.4*p;s.fillStyle=`rgba(74,158,255,${_})`,s.beginPath(),s.arc(y,b,3,0,2*Math.PI),s.fill();const v=Math.atan2(m,f),x=Math.PI/8;return s.fillStyle="rgba(74,158,255,0.08)",s.beginPath(),s.moveTo(y,b),s.arc(y,b,.6*a,v+Math.PI-x,v+Math.PI+x),s.closePath(),s.fill(),i},u=()=>{const t=e.getCameraWorldState();if(!t)return-1;const n=.01;for(let e=1;e<=9;e++){const i=c.getSlot(e);if(i&&(Math.abs(t.position.x-i.position.x)<n&&Math.abs(t.position.y-i.position.y)<n&&Math.abs(t.position.z-i.position.z)<n&&Math.abs(t.target.x-i.target.x)<n&&Math.abs(t.target.y-i.target.y)<n&&Math.abs(t.target.z-i.target.z)<n))return e}return-1};let p,f,m=-1;const g=()=>{a.innerHTML="";let t=!1;const i=u(),s=Array.from({length:9},(t,e)=>e+1);for(const r of s){const s=c.getSlot(r),o=!!s,u=r===i;if(n&&!o)continue;t=t||o;const p=document.createElement("div"),f=u?"rgba(74,158,255,0.1)":"transparent";if(p.style.cssText=`display:flex;align-items:center;gap:6px;padding:${n?"6px 8px":"3px 4px"};border-radius:6px;transition:background 0.15s;background:${f}${u?";box-shadow:inset 0 0 0 1px rgba(74,158,255,0.25)":""}`,p.dataset.active=u?"1":"",p.addEventListener("mouseenter",()=>{p.style.background=p.dataset.active?"rgba(74,158,255,0.15)":"rgba(255,255,255,0.06)",!n&&o&&e.highlightBookmarkMarker(r)}),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&&s){const t=d(s);t.style.pointerEvents="none",p.appendChild(t)}const t=document.createElement("span");t.textContent=s?.name||"noname",t.style.cssText=`flex:1;color:${s?.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;${s?.name?"":"font-style:italic"}`,p.appendChild(t),p.style.cursor="pointer",p.addEventListener("click",()=>{e.animateToSlot(r)})}else{const t=document.createElement("div");t.textContent="⠿";const n=o,i=o?"color:rgba(255,255,255,0.3)":"color:rgba(255,255,255,0.12)";if(t.style.cssText=`width:16px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;user-select:none;${i}${n?";cursor:grab":""}`,n&&(t.dataset.dragHandle="1",t.addEventListener("mouseenter",()=>{t.style.color="rgba(255,255,255,0.6)"}),t.addEventListener("mouseleave",()=>{t.style.color="rgba(255,255,255,0.3)"})),p.appendChild(t),o&&s){const t=d(s);t.style.pointerEvents="none",p.appendChild(t)}o&&(p.style.cursor="pointer",p.addEventListener("click",t=>{const n=t.target.tagName;"INPUT"!==n&&"BUTTON"!==n&&e.animateToSlot(r)}));const a=document.createElement("input");a.type="text",a.value=s?.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(r,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(r),g()}),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(r),l(),g()}),u.appendChild(n);const i=document.createElement("button");i.textContent="⋮",i.title="Playlist settings",i.style.cssText=h+";color:rgba(255,255,255,0.35);font-size:14px",i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.08)"}),i.addEventListener("mouseleave",()=>{i.style.background="transparent"}),u.appendChild(i)}else{const t=document.createElement("button");t.textContent="📌",t.title="Save current view here",t.style.cssText=h+";color:#4ade80",t.addEventListener("mouseenter",()=>{t.style.background="rgba(74,222,128,0.15)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",()=>{e.saveCameraToSlot(r),g()}),u.appendChild(t)}p.appendChild(u)}const y=document.createElement("div");if(y.dataset.slotIndex=String(r),y.dataset.filled=o?"1":"",y.appendChild(p),!n&&o){const t=p.querySelector("[data-drag-handle]");t&&t.addEventListener("pointerdown",e=>{e.preventDefault(),e.stopPropagation(),y.style.opacity="0.3",y.style.pointerEvents="none",y.style.outline="1px dashed rgba(74,158,255,0.4)",y.style.borderRadius="4px",t.style.cursor="grabbing";const n=document.createElement("div");n.style.cssText="height:2px;background:#4a9eff;border-radius:1px;margin:1px 0",t.setPointerCapture(e.pointerId);const i=t=>{const e=Array.from(a.querySelectorAll('[data-slot-index][data-filled="1"]'));n.parentNode&&n.parentNode.removeChild(n);let i=null;for(const n of e){if(n===y)continue;const e=n.getBoundingClientRect();if(t.clientY<e.top+e.height/2){i=n;break}}if(i)a.insertBefore(n,i);else{const t=e[e.length-1];t&&t.after(n)}},s=e=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",i),t.removeEventListener("pointerup",s),y.style.cssText="",t.style.cursor="grab";const r=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=r.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(),g()};t.addEventListener("pointermove",i),t.addEventListener("pointerup",s)})}if(!n&&o&&s){const t=document.createElement("div");t.dataset.slotDetail="1";const e=m===r;t.style.cssText=`display:${e?"block":"none"};margin:2px 0 4px 26px;padding:6px 8px;background:rgba(255,255,255,0.03);border-radius:4px;border:1px solid rgba(255,255,255,0.06)`;const n="width:50px;font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none;text-align:right",i="font-size:10px;color:rgba(255,255,255,0.45);white-space:nowrap",o="display:flex;align-items:center;gap:6px;margin-bottom:4px",c=document.createElement("div");c.style.cssText=o;const h=document.createElement("span");h.textContent="Hold",h.style.cssText=i+";width:55px";const d=document.createElement("input");d.type="number",d.min="0",d.step="500",d.value=String(s.holdDuration??2e3),d.style.cssText=n;const u=document.createElement("span");u.textContent="ms",u.style.cssText=i,d.addEventListener("change",()=>{const t=parseInt(d.value);s.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 g=document.createElement("span");g.textContent="Transition",g.style.cssText=i+";width:55px";const b=document.createElement("input");b.type="number",b.min="0",b.step="200",b.value=String(s.transitionDuration??1200),b.style.cssText=n;const _=document.createElement("span");_.textContent="ms",_.style.cssText=i,b.addEventListener("change",()=>{const t=parseInt(b.value);s.transitionDuration=isNaN(t)?void 0:Math.max(0,t),l()}),b.addEventListener("keydown",t=>t.stopPropagation()),f.appendChild(g),f.appendChild(b),f.appendChild(_),t.appendChild(f);const v=document.createElement("div");v.style.cssText=o;const x=document.createElement("span");x.textContent="Easing",x.style.cssText=i+";width:55px";const w=document.createElement("select");w.style.cssText="font-size:11px;color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.12);border-radius:3px;padding:2px 4px;outline:none";for(const t of["ease-in-out","ease-in","ease-out","linear"]){const e=document.createElement("option");e.value=t,e.textContent=t,e.style.cssText="background:#2a2a2a;color:#ccc",(s.easing??"ease-in-out")===t&&(e.selected=!0),w.appendChild(e)}w.addEventListener("change",()=>{s.easing="ease-in-out"===w.value?void 0:w.value,l()}),v.appendChild(x),v.appendChild(w),t.appendChild(v);const M=document.createElement("div");M.style.cssText=o+";margin-bottom:0";const S=document.createElement("span");S.textContent="Skip in play",S.style.cssText=i+";width:55px";const k=document.createElement("input");k.type="checkbox",k.checked=!!s.excludeFromPlay,k.style.cssText="accent-color:#4a9eff;cursor:pointer",k.addEventListener("change",()=>{s.excludeFromPlay=k.checked||void 0,l()}),M.appendChild(S),M.appendChild(k),t.appendChild(M),y.appendChild(t);const A=p.querySelector("button:last-child");A&&(e&&(A.style.color="#4a9eff"),A.addEventListener("click",()=>{const e="none"!==t.style.display;a.querySelectorAll("[data-slot-detail]").forEach(e=>{if(e!==t&&"none"!==e.style.display){e.style.display="none";const t=e.parentElement?.firstElementChild?.querySelector("button:last-child");t&&(t.style.color="rgba(255,255,255,0.35)")}}),t.style.display=e?"none":"block",A.style.color=e?"rgba(255,255,255,0.35)":"#4a9eff",m=e?-1:r}))}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(g(),!n){p=document.createElement("div"),p.style.cssText="display:none;margin-top:6px;padding:4px 8px;border-top:1px solid rgba(255,255,255,0.06)";const t=document.createElement("div");t.style.cssText="display:flex;align-items:center;gap:6px";const n=document.createElement("input");n.type="range",n.min="0",n.max="1000",n.value="0",n.tabIndex=-1,n.style.cssText="flex:1;min-width:0;margin:0;height:14px;cursor:grab;accent-color:#4a9eff;outline:none";const i=document.createElement("button");i.textContent="▶",i.title="Play / Stop",i.style.cssText="border:none;background:rgba(255,255,255,0.06);color:rgba(255,255,255,0.5);cursor:pointer;font-size:12px;padding:3px 6px;border-radius:4px;line-height:1;flex-shrink:0",i.addEventListener("mouseenter",()=>{i.style.background="rgba(74,158,255,0.15)",i.style.color="#4a9eff"}),i.addEventListener("mouseleave",()=>{i.style.background="rgba(255,255,255,0.06)",i.style.color=c.isPlaying?"#4a9eff":"rgba(255,255,255,0.5)"}),i.addEventListener("click",()=>{const t=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(t),a()}),n.addEventListener("focus",()=>n.blur());let r=!1;n.addEventListener("mousedown",()=>{r=!0,n.style.cursor="grabbing",c.isPlaying&&(e.togglePlay(),a())}),n.addEventListener("input",()=>{const t=parseInt(n.value)/1e3;e.scrubPath(t)});const o=()=>{r&&(r=!1,n.style.cursor="grab")};n.addEventListener("mouseup",o),n.addEventListener("mouseleave",o),s.addEventListener("keydown",t=>{if("Space"===t.code&&"none"!==p.style.display){t.preventDefault(),t.stopPropagation();const i=c.isPlaying?-1:parseInt(n.value)/1e3;e.togglePlay(i),a()}}),t.appendChild(n),t.appendChild(i),p.appendChild(t),s.appendChild(p);const a=()=>{const t=c.isPlaying;i.textContent=t?"⏹":"▶",i.style.color=t?"#4a9eff":"rgba(255,255,255,0.5)"};let l=-1;const h=()=>{if(this._floatingPopup===s){if(c.isPlaying){const t=c.playProgress;n.value=String(Math.round(1e3*t)),l=-1}else{"⏹"===i.textContent&&a();const t=c.lastPlayProgress;t>=0&&t!==l&&(n.value=String(Math.round(1e3*t)),l=t)}f=requestAnimationFrame(h)}};f=requestAnimationFrame(h);(()=>{const t=c.getPlayableSlots().length;p.style.display=t>=2?"block":"none"})()}if(!n){const t=document.createElement("button"),e="display:block;width:100%;margin-top:8px;padding:5px 0;border:1px solid rgba(255,255,255,0.12);border-radius:6px;background:transparent;color:rgba(255,255,255,0.45);font-size:11px;cursor:pointer;transition:all 0.15s";i&&(t.textContent="Clear All",t.style.cssText=e,t.addEventListener("mouseenter",()=>{t.style.borderColor="rgba(255,107,107,0.4)",t.style.color="#ff6b6b"}),t.addEventListener("mouseleave",()=>{t.style.borderColor="rgba(255,255,255,0.12)",t.style.color="rgba(255,255,255,0.45)"}),t.addEventListener("click",()=>{c.resetAll(),l(),g()})),s.appendChild(t)}const y=e.onBookmarkChanged;e.onBookmarkChanged=()=>{y?.(),this._floatingPopup===s&&(g(),_=-2,n||e.showBookmarkPath())},this._showFloatingPopup(s,!0),n||e.showBookmarkPath();let b,_=u();const v=()=>{if(this._floatingPopup!==s)return;const t=u();if(t!==_){_=t;a.querySelectorAll("[data-slot-index]").forEach(e=>{const n=parseInt(e.dataset.slotIndex||"-1"),i=e.firstElementChild;if(!i)return;const s=n===t,r=s?"rgba(74,158,255,0.1)":"transparent";i.style.background=r,i.style.boxShadow=s?"inset 0 0 0 1px rgba(74,158,255,0.25)":"none",i.dataset.active=s?"1":""})}b=requestAnimationFrame(v)};b=requestAnimationFrame(v);const x=this._closeFloatingPopup.bind(this);this._closeFloatingPopup=()=>{void 0!==b&&cancelAnimationFrame(b),void 0!==f&&cancelAnimationFrame(f),c.isPlaying&&e.togglePlay(),e.clearBookmarkMarkerHighlight(),e.hideBookmarkPath(!0),this._closeFloatingPopup=x,x()}}_removeToolbar(){this._closeFloatingPopup(),this._threeCapability&&(this._threeCapability.onGizmoModeChanged=void 0,this._threeCapability.onGizmoAttachChanged=void 0,this._threeCapability.onCameraViewChanged=void 0,this._threeCapability.onBookmarkChanged=void 0,this._threeCapability.onHelpToggle=void 0,this._threeCapability.onSearchToggle=void 0,this._threeCapability.onDataBindingToggle=void 0,this._threeCapability.onMonitorToggle=void 0,this._threeCapability.onBookmarkNavToggle=void 0,this._threeCapability.onBookmarkEditToggle=void 0),this._toolbar?.parentNode&&this._toolbar.parentNode.removeChild(this._toolbar),this._toolbar=void 0,this._cameraButtons=void 0}_resizeThreeD(t=!1){if(!this._threeCapability||!this.element)return;const e=this.canvas?.clientWidth??0,n=this.canvas?.clientHeight??0,i=e>0?e:this.element.clientWidth,s=n>0?n:this.element.clientHeight;i>0&&s>0&&this._threeCapability.resize(i,s,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._threeDActivationPending=!1,!this._threeCapability)return;ap.hideAll(this.root),this._removeToolbar(),this._lastCameraState=this._threeCapability.captureSessionState();const{target:t,visibleWidth:e,visibleHeight:n}=this._threeCapability.captureViewportInfo();this._threeCapability.forceCleanupDragState();const i=this._threeCapability.domElement,s=this._threeCapability.css3DRenderer?.domElement,r=[...this._threeCapability.decoratorOutlines];this._threeCapability.dispose(),this._threeCapability=void 0,s?.parentNode&&s.parentNode.removeChild(s);for(const t of this.components)if(t.isHTMLElement()&&t.element){const e=t.element,n=this.getOverlay(t);n?.appendChild(e)}i?.parentNode&&i.parentNode.removeChild(i),this.canvas&&(this.canvas.style.display=""),this._overlay&&(this._overlay.style.display=""),this._auxCanvas&&(this._auxCanvas.style.display=""),this._decoratorOverlay&&(this._decoratorOverlay.style.display=""),this._decoratorAuxOverlay&&(this._decoratorAuxOverlay.style.display="");for(const t of this.root?.assist_layers||[])t.element&&(t.element.style.display="");for(const t of this.components)t.isHTMLElement()&&t.element&&t.reposition();this.app?.isEditMode&&this._createToolbar();for(const t of r)t.disposed||this.applyDecorator(t,"border-highlighting",{distance:8,lineWidth:4,color:this._outlineDecoColor});this._saved2DViewport?(this.set({scale:this._saved2DViewport.scale,translate:this._saved2DViewport.translate}),this._saved2DViewport=void 0):this._needsViewportSync&&this._init2DViewportFrom3DCamera(t,e,n),this.root.target_element?.focus()}_getViewportSize(){const t=this.target;return{w:t?.clientWidth||this.canvas?.clientWidth||this.state.width||800,h:t?.clientHeight||this.canvas?.clientHeight||this.state.height||600}}_initCameraFrom2DViewport(){if(!this._threeCapability)return;const{w:t,h:e}=this._getViewportSize(),n=this.get("translate")||{x:0,y:0},i=this.get("scale")||{x:1,y:1},s=i.x||1,r=i.y||1,{width:o=800,height:a=600}=this.state,c=(t/2-n.x)/s-o/2,l=(e/2-n.y)/r-a/2,h=t/s,d=e/r;this._threeCapability.positionCameraForViewport(c,l,h,d,this._lastCameraState)}_init2DViewportFrom3DCamera(t,e,n){const{w:i,h:s}=this._getViewportSize(),{width:r=800,height:o=600}=this.state,a=t.x+r/2,c=t.z+o/2;let l;if(this._2dScaleBeforeThreeD&&this._initialVisibleHeight&&n>0){const t=this._initialVisibleHeight/n;l=this._2dScaleBeforeThreeD*t}else if(e>0||n>0){const t=e>0?i/e:1,r=n>0?s/n:1;l=Math.max(t,r)}else l=1;l=Math.max(.1,Math.min(l,10));const h=i/2-a*l,d=s/2-c*l;this.set({translate:{x:h,y:d},scale:{x:l,y:l}}),this._2dScaleBeforeThreeD=void 0,this._initialVisibleHeight=void 0}centerTo(t,e){this.is3dMode&&this._threeCapability?this._threeCapability.centerToComponent(t,e):super.centerTo(t,e)}async ready(){await super.ready();const t=this._rebuildPreserveThreeD;this._rebuildPreserveThreeD=!1,!t&&this.model.threed&&!this._threeCapability&&this._threedEnabled?(this._threeDActivationPending=!0,await new Promise(t=>setTimeout(t,0)),this._activateThreeD()):this.app?.isEditMode&&!this.is3dMode&&this._createToolbar(),this.root?.trigger("dimension",this.is3dMode?"3d":"2d")}toggleThreeD(t){if(!this._threedEnabled)return;const e=t??!this.is3dMode;e?this._activateThreeD(!0):(this._deactivateThreeD(),this.resize(),this.invalidate()),this.root?.trigger("dimension",e?"3d":"2d")}dispose(){this._deactivateThreeD(),this._removeToolbar(),super.dispose(),this._overlay=null,this._decoratorOverlay&&(Xr.getInstance().removeOverlay(this._decoratorOverlay),this._decoratorOverlay.parentNode&&this._decoratorOverlay.parentNode.removeChild(this._decoratorOverlay),this._decoratorOverlay=null),this._decoratorAuxOverlay&&(Xr.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?Fc.get("three"):Nc}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,Xr.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,Xr.getInstance().addOverlay(t)}return this._decoratorAuxOverlay}createElement(){const t=super.createElement();return this._overlay&&t.appendChild(this._overlay),t}resize(){if(!this.target||!this.element)return;let{width:t,height:e,fitMode:n}=this.model;this.root.fitMode?n=this.root.fitMode:n||(n="ratio");let i=null;try{i=getComputedStyle(this.target)}catch(t){return void Zi(t,this.target)}let s=i?parseFloat(i.getPropertyValue("width")):this.target.clientWidth,r=i?parseFloat(i.getPropertyValue("height")):this.target.clientHeight;switch(n){case"both":case"ratio":break;case"width":r=e*s/t,this.element.style.overflowX="hidden",this.element.style.overflowY="auto";break;case"height":s=t*r/e,this.element.style.overflowX="auto",this.element.style.overflowY="hidden";break;default:s=Math.max(t,s),r=Math.max(e,r),this.element.style.overflowX=s>t?"hidden":"auto",this.element.style.overflowY=r>e?"hidden":"auto"}this.fitSize(this.element,!0),this.fitSize(this.canvas,!0,s,r),this.fitSize(this.auxCanvas,!0,s,r),this.root?.transitionEffect?.resize(),this.is3dMode&&this._threeCapability.resize(s,r)}draw(t){if(this.is3dMode){if(!this.element)return;return void this._threeCapability.renderCSS3D()}if(this._threeDActivationPending)return;const e=this.root?.transitionEffect;e?.beginDraw(),super.draw(t),e?.endDraw()}get MPP(){const{scale:t={x:1,y:1},unit:e}=this.model;switch(e){case"mm":case"cm":return 1/this.app.PPM/t.x;case"in":return 1/this.app.PPI/t.x;default:return 1/t.x}}capturePath(t,e){const n=this.layout.capturables(this);for(let i=n.length-1;i>=0;i--){const s=n[i];if(!s.isContainer())continue;const r=s.capturePath(t,e);if(r)return r}return!1}getOverlay(t){return t&&!t.scalable?this.auxOverlay:this.overlay}getDecoratorOverlay(t){return t&&!t.scalable?this.decoratorAuxOverlay:this.decoratorOverlay}_onkeydown_root(t){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;const e=this.rootModel;if(!e)return;if("KeyF"===t.code)return this.onSearchToggle?.(),void t.preventDefault();if("KeyH"===t.code)return this._toggleHelpPanel(),void t.preventDefault();if("KeyD"===t.code)return this.onDataBindingToggle?.(),void t.preventDefault();if("KeyM"===t.code)return this.onMonitorToggle?.(),void t.preventDefault();if("KeyQ"===t.code){if(!this._threedEnabled)return;return this.toggleThreeD(),void t.preventDefault()}if(e.is3dMode)return;if(!this._threedEnabled)return;const n={Digit1:"perspective",Digit2:"top",Digit3:"front",Digit4:"back",Digit5:"right",Digit6:"left"}[t.code];n&&(e._pendingCameraView=n,this.toggleThreeD(!0),t.preventDefault())}get eventMap(){return{"(self)":{"(all)":{change:this._onchanged_all,mouseenter:this._onmouseenter_all,mouseleave:this._onmouseleave_all,click:this._onclick,mousedown:this._onmousedownup,mouseup:this._onmousedownup,touchstart:this._onmousedownup,touchend:this._onmousedownup,"deco-reset":t=>this.resetDecorator(void 0,t.origin)},"(descendant)":{"deco-anchors":(t,e)=>this.applyDecorator(e.origin,"anchors",t),"deco-anchors-off":t=>this.offdecorator(t.origin,"anchors"),"deco-anchors-reset":t=>this.resetDecorator("anchors"),"deco-dataspread":(t,e)=>this.applyDecorator(e.origin,"data-spread",t),"deco-dataspread-off":t=>this.offdecorator(t.origin,"data-spread"),"deco-dataspread-reset":t=>this.resetDecorator("data-spread"),"deco-link":(t,e)=>this.applyDecorator(e.origin,"link",t),"deco-link-off":t=>this.offdecorator(t.origin,"link"),"deco-link-reset":t=>this.resetDecorator("link"),"deco-arrow":(t,e)=>this.applyDecorator(e.origin,"bouncing-arrow",t),"deco-arrow-off":t=>this.offdecorator(t.origin,"bouncing-arrow"),"deco-arrow-reset":t=>this.resetDecorator("bouncing-arrow"),"deco-icon":(t,e)=>this.applyDecorator(e.origin,"animated-icon",t),"deco-icon-off":t=>this.offdecorator(t.origin,"animated-icon"),"deco-icon-reset":t=>this.resetDecorator("animated-icon"),"deco-border":(t,e)=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.addOutline(e.origin):this.applyDecorator(e.origin,"border-highlighting",t))},"deco-border-off":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.removeOutline(t.origin):this.offdecorator(t.origin,"border-highlighting"))},"deco-border-reset":t=>{this.app.isEditMode||(this._threeCapability?this._threeCapability.clearOutlines():this.resetDecorator("border-highlighting"))},"deco-tag":(t,e)=>this.applyDecorator(e.origin,"decotag",t),"deco-tag-off":t=>this.offdecorator(t.origin,"decotag"),"deco-tag-reset":t=>this.resetDecorator("decotag",t.origin),"deco-off":t=>{this.offdecorator(t.origin),this._threeCapability?.removeOutline(t.origin)},mouseenter:this.onmouseenterForDecorator,mouseleave:this.onmouseleaveForDecorator},"(self)":{change:this.onChangeForDecorator,redraw:this.onRedrawForDecorator}},"(root)":{"(self)":{selected:this._onRootSelected,keydown:this._onkeydown_root}}}}onRedrawForDecorator(){Xr.getInstance().invalidateOverlay(this.decoratorOverlay),Xr.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=Vf,scale:n=Gf,rotation:i=0}=this.model,{left:s,top:r}=this.bounds;t.style.left=s+"px",t.style.top=r+"px",t.style.transform=`rotate(${i}rad) scale(${n.x}, ${n.y}) perspective(1px)`,t.style.marginLeft=`${e.x}px`,t.style.marginTop=`${e.y}px`}onchange(t){const e=this._model;delete e.id,delete e.text,delete e.class,this._repositionOverlay(),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 Wf)return;const i=Array.isArray(n.state?.eventHandlers)&&n.state.eventHandlers.length>0,s=!!n.model?.event?.hover;(i||s)&&(n.hidden||this._dispatchEventHandlers(n,["mouseenter","hover"],t,!0))}_onmouseleave_all(t,e){if(t.stopPropagation(),!e)return;const n=e.origin;this.app&&!this.app.isEditMode&&this._dispatchEventHandlers(n,["mouseleave","hover"],t,!1)}_onclick(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin;this._dispatchEventHandlers(n,["click","tap"],t,!0)}_dispatchEventHandlers(t,e,n,i){if(!t)return;for(const s of e){const e=this._triggerToMethodName(s,i);if(e&&"function"==typeof t[e])try{const i=t[e](n,this.root);i&&"function"==typeof i.then&&i.catch(t=>Zi(t))}catch(t){Zi(t)}}if(!t.state)return;const s=js(t.state);if(!s.length)return;const r=s.filter(t=>!t.disabled&&e.includes(t.trigger));for(const e of r)this._executeHandler(e,t,n,i)}_triggerToMethodName(t,e){switch(t){case"click":case"tap":return"onTap";case"dblclick":return"onDoubleClick";case"mouseenter":case"hover":return e?"onMouseEnter":"onMouseLeave";case"mouseleave":return"onMouseLeave";case"longpress":return"onLongPress";case"mousedown":return"onMouseDown";case"mouseup":return"onMouseUp";case"pressed":return e?"onMouseDown":"onMouseUp"}}_executeHandler(t,e,n,i){const s=t.action;if(!s)return;if("script"===s){if(!i)return;const s=t.code;if(!s||"string"!=typeof s)return;const r=t.target?this.root.findAll(t.target,e)??[]:[];try{const i=Ss(s,["component","scene","event","targets","value"])(e,e,this.root,n,r,t.value);i&&"function"==typeof i.then&&i.catch(t=>Zi(t))}catch(t){Zi(t)}return}const r={action:s,target:t.target,value:t.value,...t.options??{}};this._doEventAction(r,e,i,n)}_onmousedownup(t,e){if(t.stopPropagation(),this.app.isEditMode)return;if(!e)return;const n=e.origin,i="mousedown"==t.type||"touchstart"==t.type,s=n.model.event?.tap;if(s&&s.pressed)this._doMouseDownUpEventAction(s,n,i,t);else if(n.state){js(n.state).some(t=>!t.disabled&&("click"===t.trigger||"tap"===t.trigger||"pressed"===t.trigger)&&t.options?.pressed)&&this._doMouseDownUpEventAction({pressed:!0},n,i,t)}}_doMouseDownUpEventAction(t,e,n,i){const{pressed:s=!1}=t;s&&(n?function(t){if(t.hasOwnProperty("_backupShadow"))return;const e=t.get("shadow");t._backupShadow=e;const{left:n=0,top:i=0}=e||{};t.delta("tx",n),t.delta("ty",i),t.set("shadow",{})}(e):function(t){t.hasOwnProperty("_backupShadow")&&(t.delta("tx",0),t.delta("ty",0),t.set("shadow",t._backupShadow),delete t._backupShadow)}(e))}_doEventAction(t,e,n,i){let{action:s,target:r,value:o,emphasize:a=!1,restore:c=!1,options:l}=t;if(r&&(r=e.access(r)),o&&(o=e.access(o)),a&&(n?function(t){const{hover:e}=t.state.event||{},{emphasize:n}=e||{};if(t.hasOwnProperty("_backupStrokeStyle"))return;if("__backup_emphasize"in t)return;const{strokeStyle:i,lineWidth:s,fillStyle:r}=t.state;t.__backup_emphasize={strokeStyle:i,lineWidth:s,fillStyle:r},t.setState(n)}(e):c&&function(t){"__backup_emphasize"in t&&(t.setState(t.__backup_emphasize),delete t.__backup_emphasize)}(e)),s)switch(s){case"data-toggle":if(!r)return;(n||c)&&this.root.findAll(r,e)?.forEach(t=>{t.data=!t.data});break;case"data-tristate":if(!r)return;(n||c)&&this.root.findAll(r,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(!r)return;n&&this.root.findAll(r,e)?.forEach(t=>{t.executeMappings(!0)});break;case"data-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.data=t})}break;case"partial-data-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.data={...e.data,...t}})}break;case"value-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.value=t})}break;case"partial-value-set":if(!r)return;if(n){const t=e.access(o);this.root.findAll(r,e)?.forEach(e=>{e.value={...e.value,...t}})}break;case"script":{if(!n)return;const t="string"==typeof o?o:o&&"object"==typeof o?o.script:null;if(!t||"string"!=typeof t)return;const s=r?this.root.findAll(r,e)??[]:[];try{const n=Ss(t,["component","scene","event","targets","value"])(e,e,this.root,i,s,o);n&&"function"==typeof n.then&&n.catch(t=>Zi(t))}catch(t){Zi(t)}break}case"infoWindow":case"info-window":if(!r)return;"click"==i.type||n?jc.show(e,r,c,{x:i.offsetX,y:i.offsetY}):c&&jc.hide(e,r);break;case"toggle-info-window":if(!r)return;jc.toggle(e,r,!1,{x:i.offsetX,y:i.offsetY});break;case"popup":case"modal-popup":if(!r)return;const t=l&&"input"in l?l.input:"(self)",a=!l||(!("output"in l)||l.output),h=this.is3dMode&&"modal-popup"!==s;ap.show(e,r,{data:t&&this.root.findFirst(t,e)?.data,output:a,modal:"modal-popup"===s,closable:!0,draggable:!h,origin:"auto",anchor:h?e:void 0,tether:h});break;case"inline-popup":case"inline-modal-popup":{if(!r)return;const t=this.root.findById(r);if(!t)return;const n=t.state||{},i="inline-modal-popup"===s,o=this.is3dMode&&!i;ap.show(e,"",{containerRef:r,modal:i,closable:!0,draggable:!o,origin:"auto",anchor:o?e:void 0,constantSize:n.constantSize??!0,billboard:n.billboard??!0,tether:n.tether??o,offScreen:n.offScreen??"hide",data:e.data});break}case"close-scene":this.closeScene(e.data);break;case"goto":case"goto-playlist":this.trigger(s,r,l,e);break;case"mouse-cursor":n?this.target.style.cursor=r||"auto":c&&(this.target.style.cursor="auto");break;default:this.trigger(s,r,o,e)}}applyDecorator(t,e,n={}){const i=this.getDecoratorOverlay(t);if(i){Xr.getInstance().addToOverlay(i,t,e,n)}}offdecorator(t,e){const n=this.getDecoratorOverlay(t);if(n){Xr.getInstance().removeFromOverlay(n,t,e)}}resetDecorator(t,e){const n=this.getDecoratorOverlay(e);n&&Xr.getInstance().removeAllFromOverlay(n,t)}onChangeForDecorator(t,e,n){const{origin:i}=n,s=this.getDecoratorOverlay(i);Xr.getInstance().invalidateOverlay(s)}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 Uf(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.from?.component===n&&(!e||t.from.anchor===e))}function $f(t,e){const n=t.state.refid;return t.root.findAll(t=>t.isLine()&&t.to?.component===n&&(!e||t.to.anchor===e))}function Xf(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){Zi(t)}t.closePath()}}),t.restore()}contains(t,e){let n=super.contains(t,e);if(n)return n;const i=this.anchors||[];for(const s of i){const i=s.bounds;if(!i)continue;const{left:r,top:o,width:a,height:c}=i;if(n=t<Math.max(r+a,r)&&t>Math.min(r+a,r)&&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 Uf(this,t)}findOutletEnds(t){return function(t,e){return Uf(t,e).map(t=>t.toEnd?.component).filter(Boolean)}(this,t)}findInletLines(t){return $f(this,t)}findInletEnds(t){return function(t,e){return $f(t,e).map(t=>t.fromEnd?.component).filter(Boolean)}(this,t)}}}Wf.Popup=ap,Tc.register("model-layer",Wf);const qf={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0}}],help:"scene/component/rect"},Kf={ondragmove:function(t,e,n){const{left:i,width:s,height:r}=n.model;let o=(n.fromParent(t.x,t.y).x-i)/(s/2)*100;o=Oc(o,s,r),n.set({round:o})}};class Qf extends(Xf(Dc(Pc))){is3dish(){return!0}get controls(){let{left:t,top:e,width:n,round:i,height:s}=this.state;return i=null==i?0:Oc(i,n,s),[{x:t+n/2*(i/100),y:e,handler:Kf}]}get nature(){return qf}}Tc.register("rect",Qf);const Zf=[1,2,10,20,50,50,50,50,50,50];class Jf extends(Dc(Pc)){render(t){const{lineWidth:e=1,fillStyle:n="lightgray",font:i="15px Arial",left:s,top:r,origin:o,width:a,height:c,side:l="bottom",strokeStyle:h="#000000",scale:d=1}=this.state;t.translate(s,r),t.beginPath();const u=Math.round(e/2);t.rect(-u,-u,a+2*u,c+2*u),t.clip(),t.beginPath(),t.rect(0,0,a,c),n&&(t.fillStyle=n,t.fill()),t.lineWidth=e,t.strokeStyle=h,t.stroke(),t.beginPath(),t.font=i;const p="bottom"!==l,f=p?0:c;let m=4*c/5,g=2*c/3,y=1*c/2,b=3*c/5;p&&(m=c-m,g=c-g,y=c-y,b=c-1.5*c/5);const _=d*this.app.PPM/this.root.unitScale;let v=Math.ceil(o/_);const x=this.app.PPM/_,w=x<=1.1?1:Zf[Math.round(x)]||100;1!=w&&(v+=(w-v%w)%w);let M=Math.ceil(v*_);const S=o+a;for(t.fillStyle=h;M<S;){if(v%10==0){t.moveTo(M-o,y),t.lineTo(M-o,f);const e=(v/10).toString(),n=t.measureText(e);t.fillText(e,M-o-n.width-6,b)}else v%5==0?(t.moveTo(M-o,g),t.lineTo(M-o,f)):(t.moveTo(M-o,m),t.lineTo(M-o,f));v+=w,M=Math.ceil(v*_)}}}Tc.register("ruler",Jf);const tm=20,em=20,nm=90*Math.PI/180,im="9px Verdana",sm=20,rm="#f4f4f4",om="#999";function am(t,e,n){return{left:-t.x,top:-t.y,width:tm,height:sm}}function cm(t,e,n,i){return{left:tm-t.x,top:0-t.y,origin:20-t.x,width:e-tm,height:sm}}function lm(t,e,n,i){const s={x:0-t.x+10,y:-t.y+em+(n-em)/2},r=Tc.transcoordRR(0-t.x,-t.y+em,s,nm);return{left:r.x-(n-em),top:r.y,origin:20-t.y,width:n-em,height:sm}}function hm(t){const e=t.get("translate");return{left:-e.x,top:-e.y,width:t.canvas.width/Xs,height:t.canvas.height/Xs}}Tc.register("guide-layer",class extends cp{constructor(t,e){super(t,e),this.appScale={x:1,y:1},"disabled"!==t.ruler&&(this.hruler=new Jf({left:tm,top:0,origin:20,margin:0,height:sm,unit:"m",rotation:0,font:im,fillStyle:rm,strokeStyle:om,capturable:!1}),this.vruler=new Jf({left:0,top:0,origin:20,margin:0,height:sm,unit:"m",rotation:nm,font:im,side:"top",fillStyle:rm,strokeStyle:om,capturable:!1}),this.origin_rect=new Qf({left:-20,top:-20,width:20,height:20,fillStyle:rm,strokeStyle:om,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=hm(this));const t=this.rootModel,e=Object.assign({},t.get("translate"));e.x<tm&&(e.x+=tm),e.y<em&&(e.y+=em);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=hm(this);const{width:i,height:s}=this.screen_coord;this.hruler.set(cm(e,i)),this.vruler.set(lm(e,0,s)),this.origin_rect.set(am(e))}resize(){super.resize(),this.screen_coord=hm(this);const{width:t,height:e}=this.screen_coord;this.hruler&&(this.hruler.set(cm(this.model.translate,t)),this.vruler.set(lm(this.model.translate,0,e)),this.origin_rect.set(am(this.model.translate)))}render(t){if(this.rootModel?.is3dMode)return;if(!this.guide)return;t.save();const{x:e,y:n}=this.guide,{top:i,left:s,width:r,height:o}=this.screen_coord;t.beginPath(),t.moveTo(e,i),t.lineTo(e,i+o),t.moveTo(s,n),t.lineTo(s+r,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=hm(this),this.hruler){const{translate:t}=this.model,{width:e,height:n}=this.screen_coord;this.hruler.set(cm(t,e)),this.vruler.set(lm(t,0,n)),this.origin_rect.set(am(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 cp{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 dm(t,e,n,i,s){const r=t.selected;let o=i?r.slice(0):[];e.isContainer()||(e=e.parent);const a=e.layout.capturables(e),c=!!e.layout.joinType;if(i&&n.selected.forEach(t=>{o.splice(o.indexOf(t),1)}),n.selected=[],a.forEach(t=>{!t.capturable||!function(t,e,n){const{sx:i,sy:s,ex:r,ey:o}=e;let a,c,l,h;if(i>r?(a=r,c=i):(a=i,c=r),s>o?(l=o,h=s):(l=s,h=o),n){const e=t.bounds,n=t.transcoordS2TR(e.left,e.top),i=t.transcoordS2TR(e.left+e.width,e.top+e.height),s=n.x,r=i.x,o=n.y,d=i.y,u=Math.min(a,s,c,r),p=Math.max(a,s,c,r),f=Math.min(l,o,h,d),m=Math.max(l,o,h,d);return!(p-u>Math.abs(c-a)+Math.abs(r-s)||m-f>Math.abs(h-l)+Math.abs(d-o))}{const e=t.path;if(!e)return Zi("컴포넌트에 get path가 잘못 구현되어있음.",t),!1;for(let n=0;n<e.length;n++){const i=t.transcoordS2TR(e[n].x,e[n].y);if(a>i.x||c<i.x||l>i.y||h<i.y)return!1}return!0}}(t,n,c)||-1!=o.indexOf(t)||s&&t.state.type!==s||n.selected.push(t)}),o=o.concat(n.selected),r.length!==o.length)t.selected=o;else for(let e=0;e<o.length;e++)if(r[e]!=o[e]){t.selected=o;break}}function um(t,e,n,i,s,r){s||dm(t,e,n,i,r)}function pm(t,e){const n=t.components||[];for(const t of n){pm(t,e);const n=e.indexOf(t);-1!=n&&e.splice(n,1)}}Tc.register("add-layer",class extends cp{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}get pointerEvents(){return"none"}render(t){const e=this.addbox;if(e){const{sx:n,sy:i,ex:s,ey:r}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,s-n,r-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle=this.boxStrokeStyle||"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.bulkMode=!!e?.bulkMode,this.template=e?.template,this.boxStrokeStyle=e?.boxStrokeStyle||"",this.dragStarted=!1,delete this.addbox,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,delete this.bulkMode,delete this.template,delete this.boxStrokeStyle,delete this.dragStarted,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},this.dragStarted=!0}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;if(!this.dragStarted||!this.addbox)return void this.root.trigger("addstop");const{sx:n,sy:i,ex:s,ey:r}=this.addbox;if("number"!=typeof s||"number"!=typeof r||Math.abs(s-n)<4||Math.abs(r-i)<4)return void this.root.trigger("addstop");const o={left:Math.min(n,s),top:Math.min(i,r),width:Math.abs(s-n),height:Math.abs(r-i)};this.bulkMode?this.root.trigger("bulkareaselected",{area:o,template:this.template}):Oh.call(this.root,this.models,o),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;if(this.bulkMode)return void this.root.trigger("addstop");const{x:n,y:i}=this.toLocal(t.offsetX,t.offsetY);Oh.call(this.root,this.models,{cx:n,cy:i}),this.root.trigger("addstop")}});Tc.register("selection-layer",class extends cp{async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n);const i=this.root?.target_element;i?.addEventListener("contextmenu",t=>{t.shiftKey&&t.preventDefault()})}contains(t,e){return!1}render(t){const e=this.selbox;if(e){const{sx:n,sy:i,ex:s,ey:r}=e,o=this.get("scale")||{x:1,y:1};t.beginPath(),t.rect(n,i,s-n,r-i),t.setLineDash([2/o.x,4/o.y]),t.lineWidth=1/o.x,t.strokeStyle="black",t.stroke()}}get eventMap(){return{"(root)":{"(self)":{keydown:this.onkeydown}},"model-layer":{"(self)":{change:this.onchange_root_model},"(all)":{dragstart:this.ondragstart_selbox,dragmove:this.ondragmove_selbox,dragend:this.ondragend_selbox,mousedown:this.onmousedown_comp,mouseup:this.onmouseup_comp}}}}onkeydown(t,e){const{deliverer:n}=e,i=n.selected;if(1!==i.length)return!1;let s=i[0];const r=s.parent;if(!r||r===n)return!1;if("Tab"===t.code){const e=r.layout.capturables(r);let n=e.indexOf(s);if(-1==n){if(!r.indexOf(s))return Ji("Container not contains [",s,"] as a component"),!1;n=0}const i=e.length;t.shiftKey?n--:n++,s=e[(n+i)%i]}else{if(!r.layout.keyNavigate)return!1;s=r.layout.keyNavigate(r,s,t)||s}n.selected=[s],t.preventDefault()}onchange_root_model(t,e,n){t.translate&&this.set("translate",t.translate),t.scale&&this.set("scale",t.scale)}_pendingDecision(t){this.downpoint={x:t.offsetX,y:t.offsetY}}_selectGroupItem(t,e){const n=this.selected.indexOf(t);let i=t.parent;for(;i.parent.isGroup();)i=i.parent;let s=[],r=!1,o=!1;if(this.selected.forEach(t=>{let e=t.parent;if(t!==i){for(;e.parent&&e.parent.isGroup();)e=e.parent;e===i&&(s.push(t),r=!0)}else o=!0}),r)if(e.shiftKey){if(-1!=n)return void this._pendingDecision(e);s.push(t)}else{if(-1!=n)return void this._pendingDecision(e);s=[t]}else{if(o)return void this._pendingDecision(e);if(e.shiftKey)if(this.selected.length>0){if(-1!=this.selected.indexOf(i))return;s=[...this.selected,i]}else s=[i];else s=[i]}this.selected=s}onmousedown_comp(t,e){const{origin:n}=e;if(this.downpoint=null,t.shiftKey){if(n.stuck)return;if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(-1==this.selected.indexOf(n)){if((t.ctrlKey||t.metaKey)&&this.selected.length>0){const t=this.selected[0].state.type;if(n.state.type!==t)return}this.selected=[...this.selected,n]}else this._pendingDecision(t)}else{if(n.parent.isGroup())return void this._selectGroupItem(n,t);if(n.stuck)this.selected.length>0&&(this.selected=[]);else{if(-1!=this.selected.indexOf(n))return;this.selected=[n],this.sameParent=!0}}}onmouseup_comp(t,e){if(!this.downpoint)return;if(this.downpoint.x!==t.offsetX||this.downpoint.y!==t.offsetY)return;const{origin:n}=e;if(t.shiftKey){let t=this.selected.indexOf(n);if(-1==t&&n.parent.isGroup()&&(t=this.selected.indexOf(n.parent)),-1!==t){const e=this.selected.slice();e.splice(t,1),this.selected=e}else{const t=this.selected.filter(t=>!t.isRootModel()&&!!t.parent),e=t.length>0&&t[0].parent;e&&e!==n.parent&&(!function(t,e){let n=t.parent;for(;n;){const t=e.indexOf(n);-1!=t&&e.splice(t,1),n=n.parent}}(n,t),pm(n,t)),t.push(n),this.selected=t}}else if(n.parent.isGroup())return void(this.selected=[n])}_isSelboxOrigin(t){return t.stuck||t.showMoveHandle}ondragstart_selbox(t,e){const{origin:n}=e;if(!this._isSelboxOrigin(n))return;const{x:i,y:s}=this.toLocal(t.offsetX,t.offsetY);this.selbox={sx:i,sy:s,selected:[]},this.app&&(this.app.isSelecting=!0)}ondragmove_selbox(t,e){const{origin:n}=e;if(!this._isSelboxOrigin(n))return;const{x:i,y:s}=this.toLocal(t.offsetX,t.offsetY);if(this.selbox){this.selbox.ex=i,this.selbox.ey=s;const e=t.shiftKey&&(t.ctrlKey||t.metaKey)&&this.selected.length>0?this.selected[0].state.type:null;um(this,n,this.selbox,t.shiftKey,!1,e),this.invalidate()}}ondragend_selbox(t,e){const{origin:n}=e;this._isSelboxOrigin(n)&&(this.last_pos=null,this.selbox=null,this.app&&(this.app.isSelecting=!1),um(this,null,null,!1,!0),this.invalidate())}});class fm{constructor(t){this.layer=t}draw(t,e,n){const{left:i,top:s,width:r,height:o}=e.bounds;0!=r&&0!=o&&(t.beginPath(),t.rect(i,s,r,o),t.clip(),t.beginPath(),t.strokeStyle="#f26522",t.lineWidth=4,t.shadowBlur=10,t.shadowColor="black",t.shadowOffsetX=0,t.shadowOffsetY=0,t.rect(i,s,r,o),t.stroke(),t.closePath())}}class mm{constructor(t){this.layer=t}draw(t,e,n){const i=e.bounds;t.beginPath(),t.rect(i.left-4/n.x,i.top-4/n.y,i.width+8/n.x,i.height+8/n.y),t.setLineDash([3/n.x,4/n.y]),t.lineWidth=1/n.x,t.strokeStyle="black",t.stroke(),t.setLineDash([]),t.closePath()}}class gm{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){const s=n.controls;return!!s&&(s.every((s,r)=>(Math.abs(t-s.x)<=4/i.x&&Math.abs(e-s.y)<=4/i.y&&(this.active={component:n,index:r,handler:s.handler}),!this.active)),!!this.active)}draw(t,e,n){const i=e.controls;i&&i.forEach((e,i)=>{t.beginPath(),t.lineWidth=1/n.x,t.ellipse(e.x,e.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.fillStyle="#ff5d72",t.fill(),t.strokeStyle="#fff",t.stroke()})}onevent(t,e){const{handler:n,component:i,index:s}=this.active;let r=i.toLocal(e.offsetX,e.offsetY);r=i.toParent(r.x,r.y),n&&"function"==typeof n[t]&&n[t](r,s,i)}onmousedown(t){this.onevent("onmousedown",t)}ondragstart(t){const e=this.active;e.changes=ll.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;ll.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function ym(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}const bm=15*Math.PI/180;class _m{constructor(t){this.layer=t}reset(){this.active=null,this.created=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.mutable)return!1;if(n.path.every((s,r)=>(Math.abs(t-s.x)<=4/i.x&&Math.abs(e-s.y)<=4/i.y&&(this.active={component:n,index:r,kind:"vertex"}),!this.active)),this.active)return!0;const s=!n.isLine();if(n.cornerEditable){const r=n.path,o=n.state?.round??0,a=s?0:1,c=s?r.length:r.length-1;for(let s=a;s<c;s++){const a=r[(s-1+r.length)%r.length],c=r[s],l=eo(a,c,r[(s+1)%r.length],to(c,o),24);if(l&&(Math.abs(t-l.x)<=6/i.x&&Math.abs(e-l.y)<=6/i.y)){this.active={component:n,index:s,kind:"corner"};break}}}if(this.active)return!0;if(n.cornerEditable){const r=n.path,o=s?r.length:r.length-1;for(let s=0;s<o;s++){const o=r[s],a=Zr(o,r[(s+1)%r.length],o.bulge??0,24);if(a&&(Math.abs(t-a.x)<=7/i.x&&Math.abs(e-a.y)<=7/i.y)){this.active={component:n,index:s,kind:"bulge"};break}}}return!!this.active}startLinkProcess(t,e,n){try{const i=zl(e,t.app,void 0);return t.rootModel.addComponent(i),this.layer.selected=[i],this.active={component:i,index:1},this.ondragstart(n),i}catch(t){Ji(t)}}draw(t,e,n){if(!e.mutable||e.stuck)return;const i=e.path,s=this.active;i.forEach((i,r)=>{t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,2*Math.PI,!0),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.fillStyle="#fff",s&&s.component===e&&s.index===r&&"corner"!==s.kind&&(t.strokeStyle="#fa7703",s.toFill&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke()});const r=!e.isLine();if(e.cornerEditable){const o=e.state?.round??0,a=r?0:1,c=r?i.length:i.length-1;for(let r=a;r<c;r++){const a=i[(r-1+i.length)%i.length],c=i[r],l=eo(a,c,i[(r+1)%i.length],to(c,o),24);l&&(t.beginPath(),t.ellipse(l.x,l.y,6/n.x,6/n.y,0,0,2*Math.PI,!0),t.lineWidth=2/n.x,t.strokeStyle="#1a73e8",t.fillStyle="#dbe8fb",s&&s.component===e&&s.index===r&&"corner"===s.kind&&(t.fillStyle="#a4c8ff"),t.fill(),t.stroke())}}if(e.cornerEditable){const o=7/n.x,a=r?i.length:i.length-1;for(let r=0;r<a;r++){const a=i[r],c=Zr(a,i[(r+1)%i.length],a.bulge??0,24);if(!c)continue;t.beginPath(),t.moveTo(c.x,c.y-o),t.lineTo(c.x+o,c.y),t.lineTo(c.x,c.y+o),t.lineTo(c.x-o,c.y),t.closePath(),t.lineWidth=2/n.x,t.strokeStyle="#7b3ff2";const l=Math.abs(a.bulge??0)>=1e-6;t.fillStyle=l?"#d1c0ff":"#ece4ff",s&&s.component===e&&s.index===r&&"bulge"===s.kind&&(t.fillStyle="#b594ff"),t.fill(),t.stroke()}}}ondblclick(t){const{component:e,index:n,kind:i}=this.active;if("corner"===i)return void e.mutatePath(null,function(t){const e=t[n]||{},{radius:i,...s}=e;t[n]=s});if("bulge"===i)return void e.mutatePath(null,function(t){const e=t[n]||{},{bulge:i,...s}=e;t[n]=s});if(!e.pathExtendable)return;const s=e.path.slice();s.length<3||(s.splice(n,1),e.path=s)}onmousedown(t){this.active.toFill=!0}ondragstart(t){const{index:e,component:n,kind:i}=this.active;this.created||(this.active.changes=ll.before([n])),("vertex"!==i||0!==e&&e!==n.path.length-1)&&(void 0!==i||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,kind:i}=this.active||{},{offsetX:s,offsetY:r}=t;let o=e.toLocal(s,r);if(o=e.toParent(o.x,o.y),"corner"===i){const t=e.path,i=t[n],s=no(t[(n-1+t.length)%t.length],i,t[(n+1)%t.length],o);return void e.mutatePath(null,function(t){const e=t[n]||{};t[n]={...e,radius:s}})}if("bulge"===i){const t=e.path,i=Jr(t[n],t[(n+1)%t.length],o);return void e.mutatePath(null,function(t){const e=t[n]||{};if(0===i){const{bulge:i,...s}=e;t[n]=s}else t[n]={...e,bulge:i}})}if(t.shiftKey){const t=e.path.length;let i=e.isLine()&&0==n?e.path[1]:e.path[(n-1+t)%t];i=e.toParent(i.x,i.y);let s=0;if(t>2){let r;e.isLine()?0==n?r=e.path[2]:1!=n&&(r=e.path[n-2]):r=e.path[(n-2+t)%t],r&&(r=e.toParent(r.x,r.y),s=ym(r,i))}const r=Math.round((ym(i,o)-s)/bm)*bm+s;o=function(t,e,n){return{x:Math.cos(e)*n+t.x,y:Math.sin(e)*n+t.y}}(i,r,(a=i,c=o,Math.sqrt((c.x-a.x)*(c.x-a.x)+(c.y-a.y)*(c.y-a.y))))}var a,c;if(0===n||n===e.path.length-1){const t=this.layer.anchorTarget=e.rootModel.capture(s,r,t=>!t.isConnectable());if(t){const{x:i,y:a}=t.toLocal(s,r),c=this.layer.get("scale")||{x:1,y:1},l=this.layer.counterEnd,h=(t.anchors||[]).find(n=>{const{name:s,inout:r,multiplicity:o=1/0,position:h,filter:d}=n;if(l){const{anchor:t,fromto:e}=l;if(t&&("out"===t.inout&&"out"===r||"in"===t.inout&&"in"===r))return!1;if("from"===e&&"out"===r||"to"===e&&"in"===r)return!1}else Zi("should not be here.");if(Math.abs(i-h.x)>8/c.x||Math.abs(a-h.y)>8/c.y)return!1;const u=t.findInOutLines(s);return!!u.includes(e)||!(o!==1/0&&u.length>=o)&&(!l||!d||!!d.call(n,l))});h?0==n?e.from={component:t.get("refid"),anchor:h.name,position:o}:e.to={component:t.get("refid"),anchor:h.name,position:o}:0==n?e.from={position:o}:e.to={position:o}}else 0==n?e.from={position:o}:e.to={position:o}}e.mutatePath(null,function(t){const e=t[n];t[n]={...e||{},x:o.x,y:o.y}})}ondragend(t){const{component:e,index:n,changes:i,kind:s}=this.active;if("corner"!==s&&"bulge"!==s&&(0===n||n===e.path.length-1)){const{offsetX:i,offsetY:s}=t,r=e.rootModel.capture(i,s,t=>t===e||t.isLine()),{x:o,y:a}=r.toLocal(i,s),c=this.layer.get("scale")||{x:1,y:1},l=(r.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:r.get("refid"),anchor:l.name}:e.to={component:r.get("refid"),anchor:l.name}),this.layer.endLinkProcess()}if(this.created){const t=new Ol({changes:[{component:this.created,to_container:this.created.parent}]});this.created.app.commander.execute(t)}else ll.after(i,e.app.commander);e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}}function vm(t,e,n){return t.filter(t=>{const{name:i,inout:s,multiplicity:r=1/0,filter:o}=t;if(n){const{anchor:t,fromto:e}=n;if(t&&("out"===t.inout&&"out"===s||"in"===t.inout&&"in"===s))return!1;if("from"===e&&"out"===s||"to"===e&&"in"===s)return!1}else if("in"===s)return!1;return!(r!==1/0&&e.findInOutLines(i).length>=r)&&(!o||!n||!!o.call(t,n))})}class xm{constructor(t){this.layer=t}get active(){return this._active?.component.disposed&&(this._active=null),this._active}set active(t){this._active=t}reset(){this.active=null}contains(t,e,n,i){const s=this.active?.component===n&&this.active?.anchor;this.active=null;const r=this.layer.counterEnd;return vm(n.isConnectable()&&!n.disposed&&this.getAnchorHandles(n,i)||[],n,r).every(r=>{const o=s===r.name?2:1;return r&&r.position&&Math.abs(t-r.position.x)<=4*o/i.x&&Math.abs(e-r.position.y)<=4*o/i.y&&(this.active={component:n,anchor:r.name,template:r.template}),!this.active}),!!this.active}getAnchorHandles(t,e){const{width:n,height:i}=t.bounds;return n*e.x<30||i*e.y<30?[]:t.anchors}draw(t,e,n){if(!e.get("refid")||e.isLine())return;const i=this.active,s=this.active?.component===e&&this.active?.anchor,r=this.layer.counterEnd;vm(e.isConnectable()&&!e.disposed&&this.getAnchorHandles(e,n)||[],e,r).forEach(r=>{const{name:o,position:a}=r,c=s===o?2:1;a&&(t.beginPath(),t.ellipse(a.x,a.y,4*c/n.x,4*c/n.y,0,0,2*Math.PI),t.setLineDash([0,0]),t.lineWidth=1/n.x,t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",i&&i.component===e&&i.anchor===o&&(t.strokeStyle="#fa7703",i.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e,anchor:n,template:i}=this.active,s=this.layer.toLocal(t.offsetX,t.offsetY);this.layer.startLinkProcess(e,{type:"ortholine",lineWidth:1,strokeStyle:"black",begin:"oval",beginSize:"size9",end:"arrow",endSize:"size9",lineDash:"solid",lineCap:"butt",round:10,...i,from:{component:e.get("refid"),anchor:n,position:s},to:{position:s}},t)}ondragmove(t){}ondragend(t){}}function wm(t,e){const{left:n,top:i,width:s,height:r}=t,o=n+s/2,a=i+r/2,c=n+s,l=i+r,h=s*e.x>50,d=r*e.y>50;return[{x:n,y:i},h?{x:o,y:i}:{x:null,y:null},{x:c,y:i},d?{x:c,y:a}:{x:null,y:null},{x:c,y:l},h?{x:o,y:l}:{x:null,y:null},{x:n,y:l},d?{x:n,y:a}:{x:null,y:null}]}class Mm{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.resizable)return!1;const s=wm(n.bounds,i);for(let r=0;r<s.length;r++){const o=s[r];if(null!=o.x&&null!=o.y&&Math.abs(t-o.x)<=4/i.x&&Math.abs(e-o.y)<=4/i.y)return this.active={component:n,index:r},!0}return!1}draw(t,e,n){if(e.isLine())return;const{left:i,top:s,width:r,height:o}=e.bounds;if(t.beginPath(),t.rect(i-4/n.x,s-4/n.y,r+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;wm(e.bounds,n).forEach((i,s)=>{null!=i.x&&null!=i.y&&(t.beginPath(),t.rect(i.x-4/n.x,i.y-4/n.y,8/n.x,8/n.y),t.setLineDash([]),t.strokeStyle="#656565",t.stroke(),t.fillStyle="#fff",a&&a.component===e&&a.index===s&&(t.strokeStyle="#fa7703",a.focus&&(t.fillStyle="#ffb80c")),t.fill(),t.stroke())})}onmousedown(t){this.active.focus=!0}ondragstart(t){const{component:e}=this.active;this.active.bounds=e.bounds,this.active.boundsList=this.layer.selected.filter(t=>t.resizable).map(t=>t.bounds)}_resizeAll(t,e){const{component:n,index:i,boundsList:s,bounds:r}=this.active,o=n.scalable?this.layer.toLocal(t.offsetX,t.offsetY):{x:t.offsetX,y:t.offsetY};n.bounds=r;const a=function(t,e,n){const{left:i,top:s,width:r,height:o}=t.bounds;let a,c;switch(e){case 0:a=i,c=s;break;case 1:a=i+r/2,c=s;break;case 2:a=i+r,c=s;break;case 3:a=i+r,c=s+o/2;break;case 4:a=i+r,c=s+o;break;case 5:a=i+r/2,c=s+o;break;case 6:a=i,c=s+o;break;case 7:a=i,c=s+o/2}const l=a,h=c,d=t.fromScene(n.x,n.y);return{dx:d.x-l,dy:d.y-h}}(n,i,o);this.layer.selected.filter(t=>t.resizable).forEach((n,r)=>{n.bounds=s[r],function(t,e,n,i,s,r){let{left:o,top:a,width:c,height:l}=t.bounds;const h={left:o,top:a,width:c,height:l};switch(e){case 0:o+=i,a+=s,c-=i,l-=s;break;case 1:a+=s,l-=s;break;case 2:a+=s,c+=i,l-=s;break;case 3:c+=i;break;case 4:c+=i,l+=s;break;case 5:l+=s;break;case 6:o+=i,c-=i,l+=s;break;case 7:o+=i,c-=i}if(t.mutateBounds(function(e){return Math.abs(c)<=.001&&(c=.001),Math.abs(l)<=.001&&(l=.001),t.adjustResize({left:o,top:a,width:c,height:l},h,n)},this),t.isContainer()&&t.layout.ABSOLUTE&&!t.isGroup()){const e=h.left-o,n=h.top-a;return void(r?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=r&&t.parent;d&&d.isGroup()&&d.calculateBounds()}(n,i,t.shiftKey,a.dx,a.dy,e)})}ondragmove(t){this._resizeAll(t,!1)}ondragend(t){this._resizeAll(t,!0),this.active.component.app.commander.execute(null,!1)}}const Sm=2*Math.PI,km=Math.PI/2;function Am(t,e){const n=t.bounds;return{x:n.left+n.width/2,y:n.top-20/e.y}}class Em{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}contains(t,e,n,i){if(!n.rotatable)return!1;const s=Am(n,i);return Math.abs(t-s.x)<=4/i.x&&Math.abs(e-s.y)<=4/i.y&&(this.active={component:n},!0)}draw(t,e,n){if(!e.rotatable)return;t.beginPath();const i=Am(e,n);t.lineWidth=1.5/n.x,t.moveTo(i.x,i.y+20/n.y),t.lineTo(i.x,i.y),t.strokeStyle="#656565",t.stroke(),t.beginPath(),t.ellipse(i.x,i.y,4/n.x,4/n.y,0,0,Sm,!0),t.stroke(),t.fillStyle="#fff",t.fill();const s=this.active;s&&s.component===e&&(t.strokeStyle="#fa7703",t.stroke(),s.toFill&&(t.fillStyle="#ffb80c",t.fill()))}onmousedown(t){this.active.toFill=!0}ondragstart(t){const e=this.active;e.start_rotation=e.component.get("rotation"),e.rotations=this.layer.selected.filter(t=>t.rotatable).map(t=>t.get("rotation"))}ondragmove(t){const{component:e}=this.active;let n;e.scalable?(n=e.toLocal(t.offsetX,t.offsetY),n=e.toParent(n.x,n.y)):(n={x:t.offsetX,y:t.offsetY},e.parent?.isRootModel()||(n=e.toParent(n.x,n.y)));const i=e.rotatePoint,s=e.get("rotation")||0;let r=Math.atan((i.y-n.y)/(i.x-n.x));r=i.x>=n.x?r-km:km+r;const o=r-s;this.layer.selected.filter(t=>t.rotatable).forEach((e,n)=>{const i=((e.get("rotation")||0)+o)%Sm;e.set("rotation",e.adjustRotation(i,t.shiftKey))})}ondragend(t){const{component:e}=this.active;e.app.commander.execute(null,!1)}}let Cm=null;class Tm{constructor(t){this.layer=t}reset(){this.active=null}get selected(){return this.layer.selected}_rect(t,e){const{left:n,top:i,width:s}=t.bounds;return{x:n+s,y:i,w:25/e.x,h:25/e.y}}contains(t,e,n,i){if(!n.showMoveHandle)return!1;const{x:s,y:r,w:o,h:a}=this._rect(n,i);return t>=s&&t<=s+o&&e>=r&&e<=r+a&&(this.active={component:n},!0)}draw(t,e,n){if(!e.showMoveHandle)return;const{x:i,y:s,w:r,h:o}=this._rect(e,n);t.save(),t.beginPath(),t.globalAlpha=1,t.rect(i,s,r,o),t.fillStyle="rgba(238, 238, 238, 0.95)",t.fill();const a=(Cm||(Cm=new Image,Cm.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAclBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0BbqFAAAAJXRSTlMAgAP3VSI6/g9fBk5FavJsMrariSjzPnO1enRRL5SMhmOOWB9keFTE0wAAANxJREFUOMutk9kWgyAMRLFuiLjUtdp9yf//YglVsQXz1HniMPcEMgHGvpX2O0Ypi+EgCL+IAShC+wB7QfubRDT7AFcnUPoLMLiP4PyJbsb55i05AgnR5iaQDsICgtH0cotBWoAP1c7kC6kFxEseCfZfB6gEgbNeBrira2QmH1uVYCXlA3is8UmgUCPIyQJKEmu8QtQJN0e9DPXVpzG2G216c1CqRmcBOdxXk07sWUSPv07zo0amCNQycv+NzmR6cRcwmfbuI7p2nZ/z4be0P83Foz6vIkhfZXr82XgDlZsspIq4peUAAAAASUVORK5CYII="),Cm);a.complete&&a.naturalWidth>0&&t.drawImage(a,i+.15*r,s+.15*o,.7*r,.7*o),t.closePath(),t.restore()}onmousedown(t){const{component:e}=this.active;-1===this.layer.selected.indexOf(e)&&(this.layer.selected=[e])}ondragstart(t){const{component:e}=this.active;this.active.changes=ll.before([e]),this.active.last=this._pointOf(e,t)}ondragmove(t){const{component:e,last:n}=this.active,i=this._pointOf(e,t);e.move({x:i.x-n.x,y:i.y-n.y},!1),this.active.last=i}ondragend(t){const{component:e,changes:n}=this.active;ll.after(n,e.app.commander),e.parent&&e.parent.calculateBounds&&e.parent.calculateBounds()}_pointOf(t,e){if(t.scalable){const n=t.toLocal(e.offsetX,e.offsetY);return t.toParent(n.x,n.y)}return{x:e.offsetX,y:e.offsetY}}}Tc.register("modeling-layer",class extends lp{constructor(t,e){super(t,e),this.pathHandler=new _m(this);const n=this.pathHandler,i=new gm(this),s=new Mm(this),r=new Em(this);this._modelers=[n,i,s,r],this._control_mode_modelers=[i,n,s,r],this.focusOutline=new fm(this),this.groupOutline=new mm(this),this.anchorHandler=new xm(this),this.moveHandleModeler=new Tm(this),this._reversed_modelers=this._modelers.slice().reverse(),this._control_mode_reverse_modelers=this._control_mode_modelers.slice().reverse(),this.hovered=null,this.hoveredDest=null}get modelers(){return this._control_mode?this._control_mode_modelers:this._modelers}get reversedModelers(){return this._control_mode?this._control_mode_reverse_modelers:this._reversed_modelers}async ready(){await super.ready();const t=this.rootModel,e=t.get("translate"),n=t.get("scale");this.set("translate",e),this.set("scale",n)}capture(t,e,n){return!!this.contains(t,e)&&this}contains(t,e){let n=this.selected.filter(t=>!!t.parent);const i=this.fromParent(t,e),s=this.get("scale")||{x:1,y:1};let r;if(this._state_dragging){if(this._counter_end){let n=s;if(this.anchorTarget.scalable?r=this.anchorTarget.fromScene(i.x,i.y):(r=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(r.x,r.y,this.anchorTarget,n))return!0}return!0}this.modelers.forEach(t=>t.reset()),this.moveHandleModeler.reset(),n=this.selected.filter(t=>!!t.parent);for(let o=0;o<n.length;o++){const a=n[o];let c=s;a.scalable?r=a.fromScene(i.x,i.y):(r=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(r.x,r.y,a,c))return this.currentModeler=e,!0}}const o=this._resolveMoveHandleOwner();if(o){let n,r=s;if(o.scalable?n=o.fromScene(i.x,i.y):(n=o.fromScene(t,e),r={x:1,y:1}),this.moveHandleModeler.contains(n.x,n.y,o,r))return this.currentModeler=this.moveHandleModeler,!0}if(this.anchorTarget){let n=s;if(this.anchorTarget.scalable?r=this.anchorTarget.fromScene(i.x,i.y):(r=this.anchorTarget.fromScene(t,e),n={x:1,y:1}),this.anchorHandler.contains(r.x,r.y,this.anchorTarget,n))return this.currentModeler=this.anchorHandler,!0}else this.anchorHandler.reset();return this.currentModeler=null,!1}_componentDrawer(t,e,n,i){const s=[];let r=e.parent;if(e.isRootModel())return t.save(),i(t,e,n),void t.restore();for((t=this.getContext(e))==this.auxContext2D&&(n={x:1,y:1});r&&!r.isRootModel();)s.push(r),r=r.parent;t.save(),s.reverse().forEach(function(e){const n=e.rotatePoint;t.translate(n.x,n.y);const i=e.get("scale");i&&t.scale(i.x,i.y),t.rotate(e.get("rotation")),t.translate(-n.x,-n.y);const s=e.bounds;t.translate(s.left,s.top)});const o=e.rotatePoint;t.translate(o.x,o.y);const a=e.get("scale");a&&t.scale(a.x,a.y),t.rotate(e.get("rotation")),t.translate(-o.x,-o.y),i(t,e,n),t.restore()}prerender(t){const{translate:e,scale:n={x:1,y:1},rotation:i}=this.model;t.save(),t.beginPath(),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.rect(0,0,t.canvas.width,t.canvas.height),t.fillStyle="black",t.globalAlpha=.5,t.fill(),t.restore(),e&&t.translate(e.x*Xs,e.y*Xs),t.scale(n.x*Xs,n.y*Xs),i&&t.rotate(i),t.clearRect(0,0,this.rootModel.get("width"),this.rootModel.get("height"))}render(t){if(this.rootModel?.is3dMode)return;t.beginPath();const e=this.get("scale")||{x:1,y:1},n=this.selected.filter(t=>!!t.parent);if(this.anchorTarget&&this._componentDrawer(t,this.anchorTarget,e,(t,e,n)=>{this.anchorHandler.draw(t,e,n)}),this.focused&&this._componentDrawer(t,this.focused,e,(t,e,n)=>{this.focusOutline.draw(t,e,n)}),n.length>0&&n[0].parent.isGroup()){let i=n[0].parent;for(;i.parent.isGroup();)i=i.parent;this._componentDrawer(t,i,e,(t,e,n)=>{this.groupOutline.draw(t,e,n)})}n.forEach(n=>{this._componentDrawer(t,n,e,(t,e,n)=>{this.reversedModelers.forEach(i=>i.draw(t,e,n))})});const i=this._resolveMoveHandleOwner();i&&this._componentDrawer(t,i,e,(t,e,n)=>this.moveHandleModeler.draw(t,e,n))}_moveHandleOwner(t){let e=t;for(;e&&!e.showMoveHandle;)e=e.parent;return e&&e.showMoveHandle?e:null}_resolveMoveHandleOwner(){return this._moveHandleSticky&&!this._moveHandleSticky.parent&&(this._moveHandleSticky=null),this._moveHandleSticky}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;const e=this._moveHandleOwner(t);e?(this._moveHandleSticky=e,this._clearMoveHandleHideTimer()):this._moveHandleSticky&&this._scheduleMoveHandleHide(),this.invalidate()}_scheduleMoveHandleHide(){this._clearMoveHandleHideTimer(),this._moveHandleHideTimer=setTimeout(()=>{this._moveHandleHideTimer=null,this.disposed||this.moveHandleModeler.active||(this._moveHandleSticky=null,this.invalidate())},1e3)}_clearMoveHandleHideTimer(){this._moveHandleHideTimer&&(clearTimeout(this._moveHandleHideTimer),this._moveHandleHideTimer=null)}dispose(){this._clearMoveHandleHideTimer(),super.dispose()}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.moveHandleModeler.active?this._clearMoveHandleHideTimer():this.hovered=e?.origin}onmouseleave(t,e){this.moveHandleModeler.active||(this.hovered=null)}onkeydown(t){"Alt"==t.key&&(this._control_mode=!0,this.invalidate())}onkeyup(t){"Alt"==t.key&&(this._control_mode=!1,this.invalidate())}onselected(t,e){this.invalidate()}onchange_model(t,e,n){const{origin:i,deliverer:s}=n;i===s&&(t.translate&&this.set("translate",t.translate),void 0!==t.rotation&&this.set("rotation",t.rotation),t.scale&&this.set("scale",t.scale)),this.invalidate()}ondblclick_model(t,e){const n=e.origin;n?.root.fit()}ondblclick(t){"function"==typeof this.currentModeler.ondblclick&&this.currentModeler.ondblclick(t),this.invalidate()}onmousedown(t){this.currentModeler.onmousedown(t),this.invalidate()}onmouseup(t){"function"==typeof this.currentModeler.onmouseup&&this.currentModeler.onmouseup(t),this.invalidate()}ondragstart(t){this.currentModeler.ondragstart(t),this._state_dragging=!0}ondragmove(t){this.currentModeler.ondragmove(t),this.invalidate()}ondragend(t){this._state_dragging=!1,this.currentModeler.ondragend(t),this.invalidate()}ondrop(t,e){const{origin:n}=e,i=t.dataTransfer.files;if(i.length<1)return;const s=this.rootModel.toLocal(t.offsetX,t.offsetY),r=this.rootModel;Promise.all(Array.from(i).map(t=>new Promise((e,n)=>{const i=new FileReader;i.addEventListener("loadend",t=>{e(i.result)}),["error","abort"].forEach(t=>i.addEventListener(t,t=>{n(t)})),i.readAsDataURL(t)}))).then(e=>{if(t.altKey)return ll.around(this.app.commander,()=>{n.ondropfile(i,e)}),void(this.selected=[n]);const o=[],a=e.map((t,e)=>{let n;const a=i[e].type,c=i[e].name;return a.startsWith("image/")?(n=zl({type:a.startsWith("image/gif")?"gif-view":"image-view",top:0,left:0,width:200,height:200,src:t},r.app),o.push(new Promise((e,i)=>{const s=new Image;s.src=t,s.onload=()=>{n.set({width:s.width,height:s.height}),e()},s.onerror=t=>{i(t)}}))):a.startsWith("audio/")?n=zl({type:"audio",top:0,left:0,width:100,height:100,src:t},r.app):a.startsWith("vnd.ms-excel/")||/\.xlsx?$/.test(c)?n=zl({type:"excel",top:0,left:0,width:100,height:100,src:t},r.app):ts("dropped file",i[e]),n&&(n.center=s,s.x+=50,s.y+=50),n}).filter(Boolean).map(t=>({component:t,to_container:r}));a.length>0&&Promise.all(o).then(()=>{this.app.commander.execute(new Ol({changes:a})),this.selected=a.map(t=>t.component)},t=>{Zi(t)})},t=>{Zi(t)})}onwheel_scale(t,e){if(0==t.deltaY&&0==t.deltaX)return;const n=e.deliverer;let i;if(t.shiftKey)i=-1!=navigator.userAgent.indexOf("Win")?t.deltaY<0?1:-1:t.deltaX<0?1:-1,t.altKey?ll.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("letterSpacing")||Qs.LETTER_SPACING;e+=i,t.set("letterSpacing",e)})}):ll.around(this.app.commander,()=>{n.selected.forEach(t=>{let e=t.get("fontSize")||Qs.FONT_SIZE;e<1&&(e=1),e+=i,t.set("fontSize",e)})});else{i=t.deltaY<0?1:-1;const e=n.get("scale")||{x:1,y:1},s=n.get("translate"),r=t.offsetX,o=t.offsetY,a=n.toLocal(r,o),c=.1*i,l={x:e.x+c,y:e.y+c};if(i<0&&e.x<.2||i>0&&e.x>10)return;n.set("scale",l);const h=n.toLocal(r,o);n.set("translate",{x:s.x+(h.x-a.x)*l.x,y:s.y+(h.y-a.y)*l.y})}}});Tc.register("scroll-layer",class extends cp{get capturable(){return!0}get pointerEvents(){return"none"}render(t){const{scrolling:e}=this.state;if(t.save(),t.beginPath(),t.fillStyle="#777",this.vscroller){const{left:n,top:i,width:s,height:r}=this.vscroller;t.globalAlpha="v"==e?1:.3,t.fillRect(n,i,s,r)}if(this.hscroller){const{left:n,top:i,width:s,height:r}=this.hscroller;t.globalAlpha="h"==e?1:.3,t.fillRect(n,i,s,r)}t.stroke(),t.restore()}resize(){super.resize(),this.calcScrollerBounds()}contains(t,e){const n=this.vscroller,i=this.hscroller;return this.setState("scrolling",n&&t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height?"v":i&&t>=i.left&&t<=i.left+i.width&&e>=i.top&&e<=i.top+i.height?"h":null),!!this.getState("scrolling")}get eventMap(){return{"(root)":{"model-layer":{change:this.onchangeModelLayer}}}}onchange(t){"scrolling"in t&&this.invalidate()}ondragstart(t,e){this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragmove(t,e){const n=this.root,{clientWidth:i,clientHeight:s}=this.canvas,{width:r,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=r/i,p=o/s;d&&n.rootModel.move({x:"h"==d?(-a+this.lastPosition.x)*l*u:0,y:"v"==d?(-c+this.lastPosition.y)*h*p:0},!1),this.lastPosition={x:t.offsetX,y:t.offsetY}}ondragend(){delete this.lastPosition,this.setState({scrolling:null})}calcScrollerBounds(){if(!this.rootModel)return;const{clientWidth:t,clientHeight:e}=this.canvas,{width:n,height:i}=this.rootModel.model,{x:s=1,y:r=1}=this._scale||{},{x:o=0,y:a=0}=this._translate||{},c=n/t,l=i/e;let h={left:-o/s/c,top:e-10,width:t/s/c,height:10};this.hscroller=h.left>1||h.width+h.left<t-1?h:null,h={left:t-10,top:-a/r/l,width:10,height:e/r/l},this.vscroller=h.top>1||h.height+h.top<e-1?h:null,this.invalidate()}onchangeModelLayer(t,e,n){if(t.scale){const{x:e=1,y:n=1}=t?.scale||{};this._scale={x:e,y:n},this.calcScrollerBounds()}if(t.translate){const{x:e=0,y:n=0}=t.translate||{};this._translate={x:e,y:n},this.calcScrollerBounds()}}});const Pm="#ff3366",Om=[3,3];function Dm(t,e){const n=t?.capabilities??t?.constructor?.capabilities;return Array.isArray(n)&&n.includes(e)}function zm(...t){return e=>{const n=Object.getPrototypeOf(e),i=Array.isArray(n?.capabilities)?n.capabilities:[],s=new Set([...i,...t]);return Object.defineProperty(e,"capabilities",{value:Object.freeze([...s]),writable:!1,configurable:!0}),e}}Tc.register("snap-guide-layer",class extends cp{constructor(){super(...arguments),this._snapResult=null}get pointerEvents(){return"none"}get capturable(){return!1}contains(t,e){return!1}get snapResult(){return this._snapResult}set snapResult(t){this._snapResult=t,this.invalidate()}clear(){this._snapResult&&(this._snapResult=null,this.invalidate())}get eventMap(){return{"(root)":{"model-layer":{change:this.onchange_root_model}}}}onchange_root_model(t){(t.translate||t.scale)&&this.syncTransform()}syncTransform(){const t=this.rootModel;if(!t)return;const e=t.get("translate")||{x:0,y:0},n=t.get("scale")||{x:1,y:1};this.set({translate:e,scale:n})}async ready(){await super.ready(),this.syncTransform()}render(t){const e=this._snapResult;if(e&&0!==e.guides.length){t.save(),t.strokeStyle=Pm,t.fillStyle=Pm,t.lineWidth=1,t.setLineDash(Om);for(let n=0,i=e.guides.length;n<i;n++){const i=e.guides[n];t.beginPath(),"x"===i.axis?(t.moveTo(i.position,i.from),t.lineTo(i.position,i.to)):(t.moveTo(i.from,i.position),t.lineTo(i.to,i.position)),t.stroke()}t.restore()}}});const Im=new Map;function Rm(t){Im.set(t.name,t)}function jm(t){return Im.get(t)}function Lm(){return[...Im.values()]}var Fm=Object.freeze({__proto__:null,capability:zm,getAllCapabilityMeta:Lm,getCapabilityMeta:jm,hasCapability:Dm,registerCapabilityMeta:Rm});function Nm(t,e,n,i){var s,r=arguments.length,o=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(o=(r<3?s(o):r>3?s(e,n,o):s(e,n))||o);return r>3&&o&&Object.defineProperty(e,n,o),o}function Hm(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function Bm(t,e,n,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(t,n):s?s.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const Gm=["mousemove","mouseup","mousedown","mouseout","wheel","tap","click","touchstart","touchmove","touchend","mouseenter","mouseleave","dragstart","dragmove","dragend","dblclick"];function Vm(t){return class extends t{constructor(){super(...arguments),this.userInputEventHandler=t=>{ol(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&&("popup"!==this.position&&(this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element)),this.scalable||(this.element.style.zIndex="100"),Gm.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),Ks.forEach(t=>{this.element.addEventListener(t,this.userInputEventHandler)}),this.oncreate_element&&this.oncreate_element(this.element))}reposition(){this.state.screenFixed&&this.isContainer?.()||this.element&&Or(this)}disposeElement(){if(!this.element)return;Gm.forEach(t=>{this.element.removeEventListener(t,this.userInputEventHandler)}),Ks.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(),"popup"!==this.position&&(this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element)),this.setElementProperties(this.element),this.reposition(),this.applyElementModelingFaint()}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.applyElementModelingFaint()}applyElementModelingFaint(){const t=this.element;if(!t)return;const{alpha:e=1}=this.state,n=e*(zo(this)?.5:1);t.style.display=!this.app?.isEditMode&&this.hidden?"none":"block",t.style.opacity=n<1?String(n):""}onchange(t,e){this.element&&this.setElementProperties(this.element),"position"in t&&this.onchangePosition(),this.reposition(),this.applyElementModelingFaint()}onchangePosition(){this.element&&("popup"!==this.position?"static"==this.position&&this.parent.isHTMLElement()?this.parent.element.appendChild(this.element):this.rootModel.getOverlay?.(this)?.appendChild(this.element):this.element.parentNode?.removeChild(this.element))}isDescendible(t){return t.isHTMLElement()}}}var Ym;const Wm={x:1,y:1},Um={boxSizing:"border-box",margin:"0px",position:"absolute",outline:"none"},$m={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 Xm extends(Vm(Kl)){constructor(){super(...arguments),Ym.set(this,null),this.startDragging=t=>{if(!this.state.draggable)return;t.preventDefault(),t.stopPropagation();const e=t.clientX,n=t.clientY,{left:i,top:s}=this.bounds,r=this.rootModel.getOverlay?.(this)?.style.transform,o=r?.match(/scale\(([^,]+),\s*([^)]+)\)/),a=o?parseFloat(o[1]):1,c=o?parseFloat(o[2]):a,l=t=>{t.preventDefault(),t.stopPropagation();const r=(t.clientX-e)/a,o=(t.clientY-n)/c;this.setState({left:i+r,top:s+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 $m}isPositionable(){return!0}setElementProperties(t){}get layout(){return Fc.get(this.get("layout"))||Nc}reposition(){if(!this.element)return;const t=this,{id:e,class:n,scale:i=Wm}=t.state,{rotation:s=0,hidden:r}=t,{left:o,top:a,width:c,height:l}=t.bounds,h=c/2,d=l/2,u=t.element;u.hidden=r,e&&(u.id=e),n&&(u.className=n),Object.assign(u.style,Um,{left:o+"px",top:a+"px",width:"0px",height:"0px",backgroundColor:"transparent"});const p=t.delta(),f=(i&&i.x||1)*p.sx,m=(i&&i.y||1)*p.sy,g=(s||0)+p.theta,y=p.tx||0,b=p.ty||0;u.style.transform=`translate(${y+h}px, ${b+d}px) rotate(${g}rad) translate(${-h}px, ${-d}px) scale(${f}, ${m}) perspective(1px)`}set path(t){const{minimized:e}=this.state,n=t[0],i=t[2];e?this.set({left:n.x,top:n.y,width:i.x-n.x}):this.set({left:n.x,top:n.y,width:i.x-n.x,height:i.y-n.y})}get path(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return[{x:t,y:e},{x:t+n,y:e},{x:t+n,y:e+i},{x:t,y:e+i}]}get bounds(){const{left:t=0,top:e=0,width:n=0,height:i=0}=this.state;return{left:t,top:e,width:n,height:i}}set bounds(t){const{minimized:e}=this.state,{left:n=0,top:i=0,width:s=0,height:r=0}=t,o={left:n,top:i};e?this.set({...o,width:s}):this.set({...o,width:s,height:r})}updatePosition(){if(!this.origin)return void(Hm(this,Ym,"f")&&(Hm(this,Ym,"f").disconnect(),Bm(this,Ym,null,"f")));const t=this.rootModel.auxOverlay;if(!t)return;const e=this.bounds,{width:n,height:i}="static"!==this.position?t.getBoundingClientRect():this.parent.bounds,{x:s,y:r}=function(t,e,n){const{left:i,top:s,width:r,height:o}=e,{width:a,height:c}=n;return t?{x:t.includes("left")?i:t.includes("center")?i+(r-a)/2:i+(r-a),y:t.includes("top")?s:t.includes("middle")?s+(o-c)/2:s+(o-c)}:{x:n.left,y:n.top}}(this.origin,{left:0,top:0,width:n,height:i},e),o=this.offset;this.bounds={left:s+(this.origin.includes("right")?-o.x:+o.x),top:r+(this.origin.includes("bottom")?-o.y:+o.y),width:e.width,height:e.height},Hm(this,Ym,"f")||(Bm(this,Ym,new ResizeObserver(()=>{requestAnimationFrame(()=>this.updatePosition())}),"f"),Hm(this,Ym,"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(){Hm(this,Ym,"f")&&(Hm(this,Ym,"f").disconnect(),Bm(this,Ym,null,"f")),super.dispose()}createElement(){super.createElement(),this.element&&(this.element.setAttribute("scene","container"),this.onchangeButtons(),this.onchangeMinimized())}onchangeButtons(){if(!this.element)return;const{draggable:t,minimizable:e,closable:n,minimized:i,hidden:s}=this.state,{width:r}=this.bounds;this.element.style.setProperty("--container-width",`${r}px`);try{D(s?z:I`
3
3
  <style>
4
4
  [scene='container'] .buttons {
5
5
  position: absolute;
@@ -47,5 +47,5 @@ import t from"dompurify";import*as e from"three";import{Color as n,LinearSRGBCol
47
47
  </button>`:z}
48
48
  ${n?I`<button class="closable" @click=${this.closeContainer}>close</button>`:z}
49
49
  </div>
50
- `,this.element)}catch(t){}}onchangeMinimized(){const{minimized:t}=this.state;t?this.setState("height",24):this.setState("height",this.get("height"))}}Ym=new WeakMap,Tc.memoize(Xm.prototype,"bounds",!0),Tc.register("container",Xm);const qm=Math.sqrt(3),Km=2;function Qm(t,e,n,i,s){const r=5+s,o=n.x,a=n.y,c=i.x,l=i.y;if(Math.abs(o-c)>r&&Math.abs(a-l)>r){const n=(l-a)/(c-o),i=a-n*o;if(Math.abs(e-(n*t+i))>r)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 Zm(t,e,n,i=2){for(let s=0;s<n.length-1;s++)if(Qm(t,e,n[s],n[s+1],i))return!0;return!1}function Jm(t,e,n,i){if("arrow"!=t.slice(-5))return n;const s=Math.atan2(i.y-n.y,i.x-n.x),r=1.5*e;return{x:n.x+Math.cos(s)*r,y:n.y+Math.sin(s)*r}}function tg(t,e,n){let{lineWidth:i=Km,strokeStyle:s="#000000",lineCap:r=!1,alpha:o=1,begin:a="none",end:c="none",beginSize:l="size5",endSize:h="size5"}=n;if(("none"!=a||"none"!=c)&&(i=Number(i)||Km,t.lineCap=r,t.lineWidth=i,t.strokeStyle=s,t.fillStyle=s,t.globalAlpha*=o,"none"!=a&&eg(t,e[0],e[1],i,a,ng(l,i)),"none"!=c)){const n=e.length;eg(t,e[n-1],e[n-2],i,c,ng(h,i))}}function eg(t,e,n,i,s,r){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),s){case"oval":t.ellipse(0,0,r.X,r.Y,0,0,2*Math.PI),t.fill();break;case"diamond":t.moveTo(-r.X,0),t.lineTo(0,-r.Y),t.lineTo(r.X,0),t.lineTo(0,r.Y),t.fill();break;case"arrow":t.moveTo(0,0),t.lineTo(qm*r.X,-r.Y),t.lineTo(qm*r.X,r.Y),t.fill();break;case"sharp-arrow":t.moveTo(0,0),t.lineTo(qm*r.X,-r.Y),t.lineTo(-r.X/1.5+qm*r.X,0),t.lineTo(qm*r.X,r.Y),t.fill();break;case"open-arrow":t.moveTo(qm*r.X+i,-r.Y),t.lineTo(i,0),t.lineTo(qm*r.X+i,r.Y),t.stroke();break;case"cross":t.moveTo(-r.X,-r.Y),t.lineTo(r.X,r.Y),t.moveTo(r.X,-r.Y),t.lineTo(-r.X,r.Y),t.stroke()}t.rotate(-c),t.translate(-o,-a),t.closePath()}function ng(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 ig="N",sg="S",rg="E",og="W";class ag{constructor({component:t,anchor:e,position:n,self:i}){this.component=t,this._anchorName=e,this._position=n,this.self=i}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 rg;const n=e.position;return n.y<=t.top?ig:n.y>=t.top+t.height?sg:n.x<=t.left?og:rg}get boundaryPosition(){const t=this.anchor;if(t){let{position:e}=t,n=0,i=0;switch(this.direction){case sg:i=20;break;case ig:i=-20;break;case og:n=-20;break;default:n=20}e={x:e.x+n,y:e.y+i};const s=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(s.x,s.y)}}}class cg extends Tc{isLine(){return!0}is3dish(){return!0}replaceRefids(t){["from","to"].forEach(e=>{const n=this.get(e);if(n?.component){const i=t.get(n.component)||n.component;this.set(e,{...n,component:i})}})}get fromEnd(){if(this.parent&&!this._fromEnd){const{component:t,anchor:e,position:n}=this.getState("from")||{};if(!t)return;const i=this.root?.findByRefid?.(t);if(!i)return;this._fromEnd=new ag({component:i,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 i=this.root?.findByRefid?.(t);if(!i)return;this._toEnd=new ag({component:i,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:i,round:s=0}=this.state;let r=this.drawPath;tg(t,r,this.state),t.beginPath();const o=Jm(e,i,r[0],r[1]),a=Jm(n,i,r[r.length-1],r[r.length-2]),c=r[0];r=[o,...r.slice(1,-1),a];let l={x:o.x,y:o.y};if(t.moveTo(o.x,o.y),r.length>=2&&Kr(c)){const e=r[1],n=to(e,s),i=Math.sqrt((o.x-e.x)**2+(o.y-e.y)**2),a=0!==i?Math.atan2(o.x-e.x,o.y-e.y):0,l=Math.sin(a)*Math.min(n,i/2)+e.x,h=Math.cos(a)*Math.min(n,i/2)+e.y,d=Qr({x:o.x,y:o.y},{x:l,y:h},c.bulge);d&&t.arc(d.cx,d.cy,d.radius,d.startAngle,d.endAngle,d.clockwise)}for(let e=1;e<r.length;e++){const n=l;l=r[e];const i=r[e+1];if(n.x===l.x&&n.y===l.y)continue;if(!i){t.lineTo(l.x,l.y);break}const o=to(l,s);let a=Math.sqrt((n.x-l.x)*(n.x-l.x)+(n.y-l.y)*(n.y-l.y)),c=0!==a?Math.atan2(n.x-l.x,n.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const u=o>0||0!==a?{x:h,y:d}:l;a=Math.sqrt((i.x-l.x)*(i.x-l.x)+(i.y-l.y)*(i.y-l.y)),c=0!==a?Math.atan2(i.x-l.x,i.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const p=o>0||0!==a?{x:h,y:d}:l;if(t.lineTo(u.x,u.y),o>0&&t.quadraticCurveTo(l.x,l.y,p.x,p.y),Kr(l)){const e=to(i,s),n=Math.sqrt((l.x-i.x)**2+(l.y-i.y)**2),r=0!==n?Math.atan2(l.x-i.x,l.y-i.y):0,o=Math.sin(r)*Math.min(e,n/2)+i.x,a=Math.cos(r)*Math.min(e,n/2)+i.y,c=Qr({x:p.x,y:p.y},{x:o,y:a},l.bulge);c&&t.arc(c.cx,c.cy,c.radius,c.startAngle,c.endAngle,c.clockwise)}}this.drawStroke(t,void 0)}contains(t,e){const{lineWidth:n}=this.state;return Zm(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:i,x2:s,y2:r}=this.state;return[this.fromEnd?.position||t?.position||{x:n,y:i},this.toEnd?.position||e?.position||{x:s,y:r}]}set path(t){const[e,n]=t,{from:i,to:s}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...i,position:e},to:{...s,position:n}})}get textBounds(){const t=this.drawPath;let e,n,i=0;for(let s=1;s<t.length;s++){const r=t[s-1],o=t[s],a=(r.x-o.x)*(r.x-o.x)+(r.y-o.y)*(r.y-o.y);a>i&&(i=Math.ceil(a),e=r,n=o)}let{paddingTop:s,paddingLeft:r,paddingRight:o,paddingBottom:a}=this.state;return a||=0,s||=0,r||=0,o||=0,{left:Math.min(e.x,n.x)+r,top:Math.min(e.y,n.y)+s,width:Math.max(Math.abs(e.x-n.x)-r-o,0),height:Math.max(Math.abs(e.y-n.y)-s-a,0)}}get decorators(){return this.app.isEditMode?["decotag"]:[]}}cg.getTipNeckPos=Jm,cg.containedInPath=Zm,cg.drawEndTips=tg,Tc.register("line",cg);const lg={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 hg extends(Xf(Pc)){is3dish(){return!0}render(t){const{cx:e,cy:n,rx:i,ry:s,startAngle:r,endAngle:o,anticlockwise:a}=this.state;t.beginPath(),t.ellipse(e,n,Math.abs(i),Math.abs(s),0,r||0,o||2*Math.PI,a),void 0!==r&&void 0!==o&&(t.lineTo(e,n),t.closePath())}get path(){const{cx:t,cy:e,rx:n,ry:i}=this.state;return[{x:t-n,y:e-i},{x:t+n,y:e-i},{x:t+n,y:e+i},{x:t-n,y:e+i}]}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:i,rx:s,ry:r}=this.state,o=(t-n)/(2*s-.5),a=(e-i)/(2*r-.5);return o*o+a*a<.25}outline(t){return function(t,e){const{cx:n,cy:i,rx:s,ry:r}=t.model,o=2*Math.PI*e,a=n+s*Math.cos(o),c=i+r*Math.sin(o);return t.toScene(a,c)}(this,t)}get anchors(){return function(t){const{left:e,top:n,width:i,height:s}=t.bounds,r=e+i/2,o=n+s/2;return[{name:"TOP",position:{x:r,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:r,y:n+s}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get nature(){return lg}}Tc.memoize(hg.prototype,"path",!1),Tc.register("ellipse",hg);const dg={object:{fill:"rgba(180,180,180,0.18)",stroke:"#888888",icon:"?",label:"object"},transport:{fill:"rgba(100,180,255,0.18)",stroke:"#3a78c8",icon:"⇄",label:"transport"},facility:{fill:"rgba(160,140,220,0.18)",stroke:"#6b4ec8",icon:"◫",label:"facility"},vehicle:{fill:"rgba(120,200,140,0.18)",stroke:"#3a8c5e",icon:"⊙",label:"vehicle"},region:{fill:"rgba(220,200,100,0.18)",stroke:"#a0892a",icon:"▢",label:"region"},path:{fill:"rgba(200,140,160,0.18)",stroke:"#a0506a",icon:"⌐",label:"path"},"3d-asset":{fill:"rgba(255,180,80,0.18)",stroke:"#c87a2a",icon:"◈",label:"3D asset"}},ug=[{type:"string",label:"placeholder-label",name:"placeholderLabel",description:'사용자에게 표시할 추가 라벨 (예: "Stocker A1")'},{type:"string",label:"hint",name:"placeholderHint",description:"구체화 시 참고 — 도면의 원본 식별자 / VLM 라벨 등"}];function pg(t,e,n,i,s){const{left:r,top:o,width:a,height:c}=e,l=Math.max(a,1),h=Math.max(c,1);t.save(),t.fillStyle=n.fill,t.fillRect(r,o,l,h),t.strokeStyle=n.stroke,t.lineWidth=1.5,t.setLineDash([4,3]),t.strokeRect(r,o,l,h),t.setLineDash([]),t.restore(),Math.min(l,h)>=24&&(t.save(),t.fillStyle=n.stroke,t.font=`bold ${Math.min(20,.4*Math.min(l,h))}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(n.icon,r+l/2,o+h/2),t.restore());const d=i?`${n.label}: ${i}`:n.label;h>=32&&(t.save(),t.fillStyle=n.stroke,t.font="10px Arial",t.textAlign="center",t.textBaseline="bottom",t.fillText(d,r+l/2,o+h-4),t.restore()),s&&h>=40&&(t.save(),t.fillStyle=n.stroke,t.font="9px Arial",t.textAlign="right",t.textBaseline="top",t.fillText(`hint: ${s}`,r+l-4,o+4),t.restore())}const fg={mutable:!1,resizable:!0,rotatable:!0,properties:[...ug,{type:"placeholder-convert",label:"",name:"_convert"}],help:"scene/component/placeholder"};class mg extends(Dc(Pc)){get nature(){return fg}render(t){const{placeholderLabel:e,placeholderHint:n}=this.state;pg(t,this.bounds,dg.object,e,n)}}Tc.register("placeholder",mg);const gg=["placeholder"];function yg(t,e=[]){return!!t&&(!!gg.includes(t)||e.includes(t))}const bg={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){const i=n[e+1];n[e+1]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},_g={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 vg extends Pc{is3dish(){return!0}get mutable(){return!0}get pathExtendable(){return!0}get cornerEditable(){return!0}get path(){return this.state.path??[]}set path(t){this.set("path",t)}contains(t,e){const n=this.path;let i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}get controls(){const t=this.path;return t.map((e,n)=>{const i=t[n+1>=t.length?0:n+1];return{x:(e.x+i.x)/2,y:(e.y+i.y)/2,handler:bg}})}get nature(){return _g}}Tc.memoize(vg.prototype,"controls",!1),Tc.register("polygon",vg);const xg=[];class wg extends(Xl(vg)){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 Fc.get(this.get("layout"))||Hc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){t&&t.parent!==this&&this.addComponent(t,{silent:!0})}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,s=t.parent;if(s){if(this===s)return;s.removeComponent(t,n||i)}const r=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,r),t.delegate_on(this),i?(s&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,r),t.trigger("added",this,t,r),delete t._silentAdd):n||t.trigger("added",this,t,r),this.root&&this.root.isReady&&t.invokeReady()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const s=this._components.splice(0,e);this._components=s.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||xg).indexOf(t)}size(){return(this._components||xg).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const s=this._components.splice(1);this._components=i.concat(s),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return nc(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const s=this.components[i].findAll(t,...e);s&&(n=n.concat(s))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return nc(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const s=this.bounds;i.x-=s.left,i.y-=s.top;const r=this.layout.capturables(this);for(let s=r.length-1;s>=0;s--){const o=r[s];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:s,width:r,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+r||a.y<s||a.y>s+o)return!1;a.x-=i,a.y-=s,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const s=i.capturePath(n,e);if(s)return s}return this.focusible&&this}render(t){"popup"!==this.position&&super.render(t)}postrender(t){if("popup"===this.position)return void super.postrender(t);const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:s,height:r}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,s,r),t.clip(),t.closePath()),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)||e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>Tc.memoize(wg.prototype,t,!1));const Mg={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){const i=n[e];n[e]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},Sg={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 kg extends cg{get pathExtendable(){return!0}get cornerEditable(){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 i=t[n],s=t[n+1];0==n&&e.push({x:i.x,y:i.y,handler:Mg}),e.push({x:(i.x+s.x)/2,y:(i.y+s.y)/2,handler:Mg}),n==t.length-2&&e.push({x:s.x,y:s.y,handler:Mg})}return e}get nature(){return Sg}}Tc.register("polyline",kg);const Ag={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 Eg extends cg{get pathExtendable(){return!1}get drawPath(){const t=this.path[0],e=this.path[1],{component:n,direction:i,boundaryPosition:s=t}=this.fromEnd||{},{component:r,direction:o,boundaryPosition:a=e}=this.toEnd||{},c=[s,a],l=[];s&&l.push(s);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:s.x,top:s.y,width:0,height:0};d=d||u;let p=r?.bounds;p&&(h=r.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 m=[u,f],g=u.left>f.left?f.left:u.left,y=u.top>f.top?f.top:u.top,b={left:g,top:y,width:u.left+u.width>f.left+f.width?u.left+u.width-g:f.left+f.width-g,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,k,A,E,C,T=0,P=0;d.left+d.width<p.left?(w=0,M=1,E=i,C=o,_=(d.left+d.width+p.left)/2,T=p.left-_):p.left+p.width<d.left&&(w=1,M=0,E=o,C=i,_=(d.left+p.width+p.left)/2,T=d.left-_),d.top+d.height<p.top?(x=0,S=1,k=i,A=o,v=(d.top+d.height+p.top)/2,P=p.top-v):p.top+p.height<d.top&&(x=1,S=0,k=o,A=i,v=(d.top+p.height+p.top)/2,P=d.top-v);const O=[];if(_&&T>P){let t,e,n;switch(C){case og:switch(E){case rg:O.push({x:_,y:c[w].y}),O.push({x:_,y:c[M].y});break;case og:t=m[w].top+m[w].height/2,e=t>c[M].y?Math.min(m[w].top,c[M].y):Math.max(m[w].top+m[w].height,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:c[M].y});break;case ig:case sg:e=E===sg?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:_,y:e}),O.push({x:_,y:c[M].y});break;default:return this.path}break;case rg:switch(E){case rg:e=c[w].y<c[M].y?Math.min(m[M].top,c[w].y):Math.max(m[M].top+m[M].height,c[w].y),n=e;break;case og:e=void 0!==v?v:c[w].y<c[M].y?b.top-.5*T:b.top+b.height+.5*T,n=e;break;case sg:e=void 0!==v?Math.max(v,c[w].y):b.top+b.height,n=e;break;case ig:e=v?Math.min(v,m[w].top):b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case sg:switch(E){case rg:e=c[w].y,n=c[w].y>c[M].y?c[w].y:m[M].top+m[M].height;break;case og:e=v?Math.max(v,m[M].top+m[M].height):b.top+b.height,n=e;break;case sg:e=b.top+b.height,n=e;break;case ig:e=v?Math.min(v,m[w].top):m[w].top,n=v?Math.max(v,m[M].top+m[M].height):m[M].top+m[M].height;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case ig:switch(E){case rg:e=c[w].y,n=c[w].y<c[M].y?c[w].y:m[M].top;break;case og:e=v?Math.min(v,m[M].top):b.top,n=e;break;case sg:e=void 0!==v?Math.max(v,c[w].y):c[w].y,n=void 0!==v?Math.min(v,c[M].y):c[M].y;break;case ig:e=b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;default:return this.path}l.push(...0===w?O:O.reverse())}else if(v){let t,e,n;switch(A){case ig:switch(k){case sg:O.push({x:c[x].x,y:v}),O.push({x:c[S].x,y:v});break;case ig:t=m[x].left+m[x].width/2,e=t>c[S].x?Math.min(m[x].left,c[S].x):Math.max(m[x].left+m[x].width,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case og:e=Math.min(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case rg:e=Math.max(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;default:return this.path}break;case sg:switch(k){case og:e=b.left,n=e;break;case rg:e=void 0!==_?Math.max(_,c[x].x):b.left+b.width,n=e;break;case ig:e=void 0!==_?_:c[x].x<c[S].x?b.left-.5*P:b.left+b.width+.5*P,n=e;break;case sg:e=c[x].x,n=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case rg:switch(k){case og:e=void 0!==_?Math.min(_,c[x].x):c[x].x,n=void 0!==_?Math.max(_,c[S].x):c[S].x;break;case rg:e=b.left+b.width,n=e;break;case ig:e=void 0!==_?Math.max(_,c[S].x):b.left+b.width,n=e;break;case sg:e=c[x].x,n=Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case og:switch(k){case og:e=b.left,n=e;break;case rg:e=void 0!==_?Math.max(_,c[x].x):c[x].x,n=void 0!==_?Math.min(_,c[S].x):c[S].x;break;case ig:e=b.left,n=e;break;case sg:e=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):c[x].x,n=Math.min(e,c[S].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;default:return this.path}l.push(...0===x?O:O.reverse())}else{let t,e;switch(i){case ig:switch(o){case ig:e=b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case sg: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 rg: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 og: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 sg:switch(o){case ig: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 sg:case rg:case og: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 og:switch(o){case ig: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 sg: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 rg: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 og: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 rg:switch(o){case ig: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 sg: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 rg:case og: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 i=n[e-1];return t.x!==i.x||t.y!==i.y}).filter((t,e,n)=>{if(0===e||e>=n.length-1)return!0;const i=n[e-1],s=n[e+1];return!(t.x===i.x&&t.x===s.x||t.y===i.y&&t.y===s.y)})}get nature(){return Ag}}Tc.register("ortholine",Eg);const Cg={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 Tg extends(Dc(Pc)){static get noimage(){return Tg.NOIMAGE||(Tg.NOIMAGE=new Image,Tg.NOIMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII="),Tg.NOIMAGE}dispose(){super.dispose(),this._offcanvas=null,this._image=null}render(t){const{left:e,top:n,width:i,height:s,isGray:r=!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(r&&this._offcanvas)t.drawImage(this._offcanvas,e,n,i,s);else try{t.drawImage(this._image,e,n,i,s)}catch(r){t.drawImage(Tg.noimage,e,n,i,s)}else!this.app.isViewMode&&t.drawImage(Tg.noimage,e,n,i,s)}get nature(){return Cg}get hasTextProperty(){return!1}async ready(){await super.ready();const{src:t}=this.state;if(!this._image&&t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((t,e)=>{this.prepare(()=>t(),t=>e(t))});e.track(`image:${t}`,"image",t,n)}else this.prepareIf(!0)}}prepare(t,e){const{src:n,crossOrigin:i}=this.state;if(n){this._image=new Image;try{i&&(this._image.crossOrigin=i),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 i=function(t,e,n){let i;try{i=t.getImageData(0,0,e,n)}catch(t){return Zi("Get Image Data Error: "+(t instanceof Error?t.message:String(t))),null}const s=i.data;for(let t=0;t<e*n*4;t+=4){const e=s[t],n=s[t+1],r=s[t+2],o=Math.floor((e+n+r)/3);i.data[t]=o,i.data[t+1]=o,i.data[t+2]=o}return i}(n,t,e);n.putImageData(i,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",Tg);class Pg extends(Vm(Dc(Tc))){is3dish(){return!0}prerender(){}}var Og,Dg,zg={},Ig={},Rg={};function jg(){if(Dg)return Ig;Dg=1,Object.defineProperty(Ig,"__esModule",{value:!0});var t=function(){if(Og)return Rg;Og=1,Object.defineProperty(Rg,"__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,i,s=0,r=function(t){for(var n=0,i=0;i<t;i++)e.charCodeAt(s>>3)&1<<(7&s)&&(n|=1<<i),s++;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(i=n,(n=r(l))!==a){if(n===c)break;if(n<h.length)i!==a&&h.push(h[i].concat(h[n][0]));else{if(n!==h.length)throw new Error("Invalid LZW code.");h.push(h[i].concat(h[i][0]))}o.push.apply(o,h[n]),h.length===1<<l&&l<12&&l++}else d();return o},t}();return Rg.SuperGifUtils=t,Rg}(),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 i=t.SuperGifUtils.byteToBitArr(n.stream.readByte());e.reserved=i.splice(0,3),e.disposalMethod=t.SuperGifUtils.bitsToNum(i.splice(0,3)),e.userInput=i.shift(),e.transparencyGiven=i.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 i=this.readSubBlocks();e.pixels=t.SuperGifUtils.lzwDecode(e.lzwMinCodeSize,i),e.interlaced&&(e.pixels=function(t,e){for(var n=new Array(t.length),i=t.length/e,s=function(i,s){var r=t.slice(s*e,(s+1)*e);n.splice.apply(n,[i*e,e].concat(r))},r=[0,4,2,1],o=[8,8,4,2],a=0,c=0;c<4;c++)for(var l=r[c];l<i;l+=o[c])s(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 Ig.SuperGifParser=e,Ig}var Lg,Fg,Ng={};var Hg=function(){if(Fg)return zg;Fg=1,Object.defineProperty(zg,"__esModule",{value:!0});var t=jg(),e=function(){if(Lg)return Ng;Lg=1,Object.defineProperty(Ng,"__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 Ng.SuperGifStream=t,Ng}(),n=function(){function n(t,e){var n=this;for(var i 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[i]=e[i];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,i=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 s=this.frame.getImageData(t.leftPos,t.topPos,t.width,t.height);t.pixels.forEach(function(t,n){t!==e.transparency&&(s.data[4*n+0]=i[t][0],s.data[4*n+1]=i[t][1],s.data[4*n+2]=i[t][2],s.data[4*n+3]=255)}),this.frame.putImageData(s,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 i=this;if(this.loadSetup(n)){var s=new XMLHttpRequest;s.open("GET",t,!0),"overrideMimeType"in s?s.overrideMimeType("text/plain; charset=x-user-defined"):"responseType"in s?s.responseType="arraybuffer":s.setRequestHeader("Accept-Charset","x-user-defined"),s.onloadstart=function(){i.initialized||i.init()},s.onload=function(){if(200===s.status){var t=s.response;t.toString().indexOf("ArrayBuffer")>0&&(t=new Uint8Array(t));var n=new e.SuperGifStream(t);setTimeout(function(){i.parseStream(n)},0)}else i.handleError("xhr - response")},s.onerror=function(){i.handleError("xhr")},s.send()}},n.prototype.load=function(t){this.loadURL(this.gifImgElement.src,t)},n}();return zg.SuperGif=n,zg}();const Bg={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 Gg extends Pg{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 Hg.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 Bg}get tagName(){return"div"}}Tc.register("gif-view",Gg);const Vg={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 Yg extends(Dc(Pc)){static get image(){return Yg.IMAGE||(Yg.IMAGE=new Image,Yg.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="),Yg.IMAGE}dispose(){super.dispose(),this.started=!1,delete this._audio}async ready(){super.ready(),this._audio=new Audio;const{src:t="",loop:e=!1,started:n=!1}=this.state;if(t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((e,n)=>{this._audio.addEventListener("canplay",()=>e(),{once:!0}),this._audio.addEventListener("error",()=>n(new Error(`Audio load failed: ${t}`)),{once:!0})});e.track(`audio:${t}`,"audio",t,n)}}this._audio.addEventListener("canplay",()=>{this.started&&this._audio.play()}),this.onchangeSrc(t),this.onchangeLoop(e),this.onchangeStarted(n)}render(t){const{left:e,top:n,width:i,height:s}=this.state;t.beginPath(),this.drawImage(t,Yg.image,e,n,i,s)}get nature(){return Vg}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 Zi(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",Yg);class Wg extends(Dc(Tc)){is3dish(){return!0}}Tc.register("text",Wg);const Ug=["refid","left","top","width","height","rotation","animation","zPos"];class $g extends Xm{isGroup(){return!0}is3dish(){return!0}get showMoveHandle(){return!1}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=Ug.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{});return super.set(n,void 0)}capture(t,e,n){const i=super.capture(t,e,n);if(i!==this)return i}set bounds(t){if(this.__MUTATING__)return void(super.bounds=t);const e=this.bounds,n=t.width/e.width,i=t.height/e.height;this.path=this.path.map(s=>({x:t.left+(s.x-e.left)*n,y:t.top+(s.y-e.top)*i})),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*i}})});else{const e=t.bounds,s=t.center,r={x:s.x*(1-n),y:s.y*(1-i)},o=e.width*(1-n),a=e.height*(1-i),c=-(r.x-o/2),l=-(r.y-a/2);t.bounds={left:e.left+c,top:e.top+l,width:e.width*n,height:e.height*i}}})}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($g.prototype,"bounds",!0),Tc.register("group",$g);const Xg={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 qg extends(Dc(Pc)){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,i=n.width/e.width,s=n.height/e.height;return"both"===this.model.fit?{x:i,y:s}:{x:Math.min(i,s),y:Math.min(i,s)}}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,i=this.refScale;t.translate(n.x,n.y),t.scale(i.x,i.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:i,height:s}=this.bounds;t.beginPath(),t.rect(e,n,i,s)}get nature(){return Xg}get hasTextProperty(){return!1}}Tc.memoize(qg.prototype,"ref",!1),Tc.memoize(qg.prototype,"refScale",!1),Tc.register("local-ref",qg);class Kg extends(Vm(Kl)){render(t){}is3dish(){return!0}get layout(){return Fc.get(this.get("layout"))||Nc}}const Qg={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 Zg extends Kg{dispose(){this._releaseRef(),super.dispose()}get nature(){return Qg}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){const i=(async()=>{this.__ref=await n.get(t,!0),this.__ref.target=this.element,this.__ref.fit(e),this.__ref.data=this.data})();this.root?.app?.loadTracker?.track(`ref:${t}`,"ref-board",t,i);try{await i}catch(t){Zi(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",Zg);const Jg="center-middle",ty={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",Jg,"right-middle","left-bottom","center-bottom","right-bottom","auto"]}},{type:"string",label:"title",name:"text"},{type:"data",label:"value",name:"value"},{type:"string",label:"container-ref",name:"containerRef",placeholder:"PopupContainer id (same board)"},{type:"textarea",label:"html-template",name:"htmlTemplate",property:{language:"html"}},{type:"string",label:"anchor-ref",name:"anchorRef",placeholder:"component id (3D-tracked anchor)"},{type:"select",label:"anchor-pin",name:"anchorPin",property:{options:[{display:"Top",value:"top"},{display:"Center",value:"center"},{display:"Bottom",value:"bottom"}]}},{type:"number",label:"anchor-offset-x",name:"anchorOffsetX"},{type:"number",label:"anchor-offset-y",name:"anchorOffsetY"},{type:"number",label:"anchor-offset-z",name:"anchorOffsetZ"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup"};class ey extends(Dc(Pc)){static get image(){return ey._image||(ey._image=new Image,ey._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"),ey._image}async ready(){await super.ready(),this.show&&this.onchangeShow(!0)}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,ey.image,e,n,i,s)}onchange(t,e){"value"in t?this.show?this.onchangeShow(!0):this.show=!0:"show"in t&&this.onchangeShow(this.show)}onchangeShow(t){if(this.app.isEditMode)return;(this.getState("board")||this.getState("containerRef")||this.getState("htmlTemplate"))&&(t?this.openPopup(this.value):this.hidePopup())}openPopup(t,e){if(this.app.isEditMode)return;const n=this.getState("anchorRef"),i=n&&this.rootModel?.findById?this.rootModel.findById(n):void 0;ap.show(this,this.getState("board"),{origin:this.getState("origin")||Jg,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,containerRef:this.getState("containerRef"),htmlTemplate:this.getState("htmlTemplate"),anchor:i,anchorPin:this.getState("anchorPin")||"top",anchorOffsetX:this.getState("anchorOffsetX")??0,anchorOffsetY:this.getState("anchorOffsetY")??0,anchorOffsetZ:this.getState("anchorOffsetZ")??0,constantSize:this.getState("constantSize")??!0,tether:this.getState("tether")??!1,offScreen:this.getState("offScreen")||"hide",...e})}hidePopup(){ap.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 ty}}Tc.register("popup",ey);const ny={mutable:!1,resizable:!0,rotatable:!1,properties:[{type:"layout",label:"layout",name:"layoutOption"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"billboard",name:"billboard"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup-container"};class iy extends Xm{get nature(){return ny}isPopupContainer(){return!0}}Tc.register("popup-container",iy);class sy 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 i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}}Tc.register("path",sy);const ry={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 oy extends Pc{is3dish(){return!0}contains(t,e){const{x1:n,y1:i,x2:s,y2:r,x3:o,y3:a}=this.state,c=[n,i,s,r,o,a];let l=!1;for(let n=0;n<c.length;n+=2){const i=(n+2)%c.length,s=c[n],r=c[n+1],o=c[i+1];r>e!=o>e&&t<(c[i]-s)*(e-r)/(o-r)+s&&(l=!l)}return l}get mutable(){return!0}get path(){const{x1:t,y1:e,x2:n,y2:i,x3:s,y3:r}=this.state;return[{x:t,y:e},{x:n,y:i},{x:s,y:r}]}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 ry}}Tc.memoize(oy.prototype,"path",!1),Tc.register("triangle",oy);const ay={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"}],help:"scene/component/donut"},cy={ondragmove:function(t,e,n){let{cx:i,rx:s}=n.model;s=Math.abs(s);let r=(n.fromParent(t.x,t.y).x-i)/s*100;r=r>=100||r<=-100?100:Math.abs(r),n.set({ratio:r})}};class ly extends hg{is3dish(){return!0}render(t){let{ratio:e=50,cx:n,cy:i,rx:s,ry:r,startAngle:o,endAngle:a,anticlockwise:c}=this.state;s=Math.abs(s),r=Math.abs(r),t.beginPath(),t.ellipse(n,i,s,r,0,o||0,a||2*Math.PI,c),t.moveTo(n+s/100*e,i),t.ellipse(n,i,s/100*e,r/100*e,0,o||0,a||2*Math.PI,!0)}contains(t,e){let{cx:n,cy:i,rx:s,ry:r,ratio:o}=this.state;s=Math.abs(s),r=Math.abs(r);const a=(t-n)/(2*s-.5),c=(e-i)/(2*r-.5),l=(t-n)/(s/100*o*2-.5),h=(e-i)/(r/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:i}=this.state;return n=Math.abs(n),[{x:t+n/100*i,y:e,handler:cy}]}get nature(){return ay}}Tc.memoize(ly.prototype,"controls",!1),Tc.register("donut",ly);const hy={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"},dy={ondragmove:function(t,e,n){const{cy:i,ry:s}=n.model;let r=(n.fromParent(t.x,t.y).y-i)/s*100+100;r>=100?r=100:r<=0&&(r=0),n.set({ratio:r})}};class uy extends hg{is3dish(){return!0}render(t){const{ratio:e=30,wing:n=5,cx:i,cy:s,rx:r,ry:o}=this.state;if(n<3)return;const a=1.5707963267948966,c=2*Math.PI/n,l=r-e/100*r,h=o-e/100*o;t.save(),t.beginPath(),t.translate(i,s),t.moveTo(r*Math.cos(-a),o*Math.sin(-a)),t.lineTo((r-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(r*Math.cos(c*e-a),o*Math.sin(c*e-a)),t.lineTo((r-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:i}=this.state;return[{x:t,y:e-n+n*(i/100),handler:dy}]}get nature(){return hy}}Tc.memoize(uy.prototype,"controls",!1),Tc.register("star",uy);const py={mutable:!1,resizable:!1,rotatable:!1,properties:[]};class fy extends(Xf(Pc)){is3dish(){return!1}isDescendible(){return!1}render(t){const{cx:e,cy:n,anticlockwise:i}=this.state,s=this.app?.scale||1;t.beginPath(),t.scale(1/s,1/s),t.ellipse(e,n,Math.abs(fy.RADIUS),Math.abs(fy.RADIUS),0,0,2*Math.PI,i),t.scale(s,s),t.closePath()}get path(){const{cx:t,cy:e}=this.state;return[{x:t-fy.RADIUS,y:e-fy.RADIUS},{x:t+fy.RADIUS,y:e-fy.RADIUS},{x:t+fy.RADIUS,y:e+fy.RADIUS},{x:t-fy.RADIUS,y:e+fy.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:i}=this.state,s=(t-n)/(2*fy.RADIUS-.5),r=(e-i)/(2*fy.RADIUS-.5);return s*s+r*r<.25}outline(t){const{cx:e,cy:n}=this.state;return this.toScene(e,n)}get nature(){return py}}fy.RADIUS=5,Tc.memoize(fy.prototype,"path",!1),Tc.register("node",fy);class my extends pu{getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds,i=this.component.state.depth||.5*Math.min(t,n),s=.15*Math.min(t,n,i),r=new R(1,1,1,4,s/Math.min(t,n,i));r.scale(t,i,n),this.object3d.geometry=r,this.object3d.material=new e.MeshStandardMaterial({color:"#5090d0",transparent:!0,opacity:.35,roughness:.6,metalness:.1,side:e.FrontSide,depthWrite:!1}),this.object3d.visible=!!this.component.app?.isEditMode}updateAlpha(){const t=this.object3d.material;t&&(t.opacity=this.component.app?.isEditMode?.35:0)}updateHidden(){this.object3d.visible=!!this.component.app?.isEditMode&&!this.component.state.hidden}updateDimension(){const{width:t,height:e}=this.component.bounds,n=this.component.state.depth||.5*Math.min(t,e);this.object3d.geometry.computeBoundingBox();const i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}updateFillStyle(){}updateStrokeStyle(){}updateText(){}clear(){return eu(this.object3d),super.clear()}}const gy="data:image/svg+xml;base64,"+btoa('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="#5090d0">\n <path d="M32 20a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm0 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12z"/>\n <path d="M55.4 27.2l-3.6-.6c-.4-1.2-.8-2.4-1.4-3.4l2.2-3c.6-.8.4-2-.2-2.6l-3-3c-.8-.6-1.8-.8-2.6-.2l-3 2.2c-1.2-.6-2.2-1-3.4-1.4l-.6-3.6c-.2-1-1-1.6-2-1.6h-4.2c-1 0-1.8.6-2 1.6l-.6 3.6c-1.2.4-2.4.8-3.4 1.4l-3-2.2c-.8-.6-2-.4-2.6.2l-3 3c-.6.8-.8 1.8-.2 2.6l2.2 3c-.6 1.2-1 2.2-1.4 3.4l-3.6.6c-1 .2-1.6 1-1.6 2v4.2c0 1 .6 1.8 1.6 2l3.6.6c.4 1.2.8 2.4 1.4 3.4l-2.2 3c-.6.8-.4 2 .2 2.6l3 3c.8.6 1.8.8 2.6.2l3-2.2c1.2.6 2.2 1 3.4 1.4l.6 3.6c.2 1 1 1.6 2 1.6h4.2c1 0 1.8-.6 2-1.6l.6-3.6c1.2-.4 2.4-.8 3.4-1.4l3 2.2c.8.6 2 .4 2.6-.2l3-3c.6-.8.8-1.8.2-2.6l-2.2-3c.6-1.2 1-2.2 1.4-3.4l3.6-.6c1-.2 1.6-1 1.6-2v-4.2c0-1-.6-1.8-1.6-2z"/>\n</svg>');class yy extends(Dc(Tc)){static get icon(){return yy._defaultIcon||(yy._defaultIcon=new Image,yy._defaultIcon.src=gy),yy._defaultIcon}get serviceName(){}get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new my(this)}render(t){if(this.app?.isViewMode)return;const{left:e,top:n,width:i,height:s}=this.bounds,r=this.constructor.icon;t.beginPath(),t.globalAlpha=.6,this.drawImage(t,r,e,n,i,s),t.globalAlpha=1}added(t){super.added(t);const e=this.serviceName;e&&(this._registeredRoot=this.root,this._registeredRoot?.registerService?.(e,this))}removed(t){const e=this.serviceName;e&&this._registeredRoot&&(this._registeredRoot.unregisterService?.(e),this._registeredRoot=void 0),super.removed(t)}get controls(){return[]}}function by(t){return class extends t{animOnValueChange(t,e=!1,n){if(t==this._lastValue)return;if(this.root?.app?.suppressAnimations)return this._lastValue=t,this._anim_alpha=0,void this.invalidate();let i;i=e?t-(Number(n)||0):t-(this._lastValue||0),this._lastValue=t,this._anim_alpha=-i,this.animate({step:t=>{this._anim_alpha=i*(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=Ur(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(wi(t)))}}}function _y(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 vy(t){var e;return(e=class extends t{is3dish(){return!0}get hasTextProperty(){return!1}get capturable(){return!1}render(t){}}).raycastTargetDefault=!1,e.requires3d=!0,e}const xy="$base_url",wy=[{type:"gltf-preset",label:"preset",name:"preset"},{type:"gltf-selector",label:"url",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:xy,defaultStorage:"3d-model",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0,category:"application"},observe:function(t){const e=this.parentNode?.querySelector("[name=gltfInfo]");e&&(e.src=t);const n=this.parentNode?.querySelector("[name=fillStyleTargets]");n&&(n.src=t);const i=this.parentNode?.querySelector("[name=playTargets]");i&&(i.src=t)}},{type:"gltf-info",label:"",name:"gltfInfo",readonly:!0,property:{action:(t,e)=>{t._ratioLocking=!0;try{t.set(e)}finally{t._ratioLocking=!1}}},editor:{fullwidth:!0}},{type:"gltf-fill-targets",label:"fill-targets",name:"fillStyleTargets",editor:{fullwidth:!0}},{type:"gltf-play-targets",label:"play-targets",name:"playTargets",editor:{fullwidth:!0}}];function My(t){return class extends t{constructor(){super(...arguments),this._snapshotLoading=!1,this._ratioLocking=!1}is3dish(){return!0}get hasTextProperty(){return!1}get controls(){return[]}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath();const r=this._topViewSnapshot;if(r)return void t.drawImage(r,e,n,i,s);this._ensureTopViewSnapshot(),t.rect(e,n,i,s),t.fillStyle="#f0f0f0",t.fill(),t.strokeStyle="#999",t.lineWidth=1,t.stroke();const o=this.getState("src"),a=o&&o.split("/").pop()?.replace(/\.[^.]+$/,"")||"GLTF",c=Math.max(10,.12*Math.min(i,s));t.fillStyle="#666",t.font=`${c}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(a,e+i/2,n+s/2,.9*i)}onchange(t,e){super.onchange?.(t,e),"src"in t&&(this._topViewSnapshot=void 0)}_ensureTopViewSnapshot(){if(this._snapshotLoading)return;const t=this.getState("src");if(!t)return;const e=vu.getTopViewCache(t);if(e)return this._topViewSnapshot=e,void this.invalidate();this._snapshotLoading=!0;const n=this.app.url(t);vu.loadGLTF(n).then(e=>{if(this._snapshotLoading=!1,this.getState("src")!==t)return;const n=vu.getTopViewCache(t);if(n)return this._topViewSnapshot=n,void this.invalidate();const i=vu.renderTopView(e.scene);vu.setTopViewCache(t,i),this._topViewSnapshot=i,this.invalidate()}).catch(()=>{this._snapshotLoading=!1})}buildRealObject(){return new vu(this)}get source(){return this.getState("src")}set source(t){this.setState("src",t)}get play(){return!1!==this.getState("play")}set play(t){this.setState("play",t)}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 playTargets(){return this.getState("playTargets")}set playTargets(t){this.setState("playTargets",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??[]}set dimension(t){const{width:e=1,height:n=1,depth:i=1}=t;this.setState({width:e,height:n,depth:i}),this.realObject?.updateDimension()}_applyRatioLock(t){if(!("width"in t||"height"in t||"depth"in t))return t;const e=this.state.width||1,n=this.state.height||1,i=this.state.depth||1,s=vf([(t.width??e)/e,(t.height??n)/n,(t.depth??i)/i]);return s?{...t,width:Math.round(e*s),height:Math.round(n*s),depth:Math.round(i*s)}:t}set(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.set(t)}finally{this._ratioLocking=!1}}setState(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.setState(t)}finally{this._ratioLocking=!1}}}}function Sy(t){return function(e){return Array.isArray(t)?t.forEach(t=>{Tc.register(t,e)}):Tc.register(t,e),e}}function ky(t){return!!t&&"function"==typeof t.capacity&&"function"==typeof t.available}function Ay(t){if(ky(t)){const e=t.capacity(),n=t.available();return{capacity:e,available:n,isFull:0===n}}if("function"==typeof t?.slotIds){const e=t.slotIds().length,n="function"==typeof t.emptySlotIds?t.emptySlotIds().length:e;return{capacity:e,available:n,isFull:0===n}}const e=t?.state?.capacity,n=Array.isArray(t?.state?.data)?t.state.data.length:0;if("number"==typeof e){const t=Math.max(0,e-n);return{capacity:e,available:t,isFull:0===t}}return{capacity:1/0,available:1/0,isFull:!1}}class Ey{constructor(){this.wasFull=!1,this.availableListeners=[],this.fullListeners=[]}notify(t){const e=0===t;if(e&&!this.wasFull){this.wasFull=!0;for(const t of this.fullListeners)try{t()}catch(t){}}else if(!e&&this.wasFull){this.wasFull=!1;for(const t of this.availableListeners)try{t()}catch(t){}}}onAvailable(t){return this.availableListeners.push(t),()=>{const e=this.availableListeners.indexOf(t);e>=0&&this.availableListeners.splice(e,1)}}onFull(t){return this.fullListeners.push(t),()=>{const e=this.fullListeners.indexOf(t);e>=0&&this.fullListeners.splice(e,1)}}dispose(){this.availableListeners=[],this.fullListeners=[]}}function Cy(t,e){if(!t||!e)return()=>{};if("function"!=typeof t.pauseEmit||"function"!=typeof t.resumeEmit)return()=>{};if("function"!=typeof e.onFull||"function"!=typeof e.onAvailable)return()=>{};const n=e.onFull(()=>t.pauseEmit()),i=e.onAvailable(()=>t.resumeEmit());return Ay(e).isFull&&t.pauseEmit(),()=>{n?.(),i?.()}}class Ty{constructor(t,e=1,n="horizontal"){this.owner=t,this.itemSpacing=e,this.axis=n}positionAt(t,e,n,i){const s=e.maxCount??1/0;if(t<0||t>=s)return null;const r=this.owner?.state?.width??0,o=this.owner?.state?.height??0,a=i?.state?.width??0,c=i?.state?.height??0;return"horizontal"===this.axis?{x:t*this.itemSpacing,y:Math.max(0,(o-c)/2),z:0}:{x:Math.max(0,(r-a)/2),y:t*this.itemSpacing,z:0}}capacity(t){return t.maxCount??1/0}}function Py(t,e,n,i,s,r,o){const a=n.w,c=n.h,l=i.w,h=i.h,d=i.d,u=[],p=l+s,f=h+s,m=Math.max(1,Math.floor((a+s)/p)),g=Math.max(1,Math.floor((c+s)/f)),y=m*g,b=r&&r>0?Math.floor(r):4;if("row"===t||"column"===t){const n=o?.advanceAlongX??!1,i=o?.reverse??!1,s=n?m:g,r=n?g:m,l=(t,e,i)=>((t,e,n)=>u.push({x:-a/2+(t+.5)*p,y:n*d+d/2,z:-c/2+(e+.5)*f}))(n?t:e,n?e:t,i);let h=0;for(let n=0;n<s&&h<e;n++){const o=i?s-1-n:n;if("column"===t)for(let t=0;t<r&&h<e;t++)for(let n=0;n<b&&h<e;n++)l(o,t,n),h++;else for(let t=0;t<b&&h<e;t++)for(let n=0;n<r&&h<e;n++)l(o,n,t),h++}return u}if("pyramid"===t){let t=e,n=0;for(;t>0;){const e=Math.max(1,m-n),i=Math.max(1,g-n),s=e*i,o=Math.min(t,s);for(let t=0;t<o;t++){const s=t%e,r=Math.floor(t/e),o=-a/2+(s+(m-e)/2+.5)*p,l=-c/2+(r+(g-i)/2+.5)*f;u.push({x:o,y:n*d+d/2,z:l})}if(t-=o,n++,1===e&&1===i){for(let e=0;e<t;e++)u.push({x:0,y:(n+e)*d+d/2,z:0});break}if(r&&n>=r)break}return u}if("pile"===t){const t=t=>(43758.5453*Math.sin(12.9898*t)%1+1)%1;for(let n=0;n<e;n++){const e=Math.floor(n/y),i=n%y,s=i%m,o=Math.floor(i/m),g=(t(2*n)-.5)*l*.2,b=(t(2*n+1)-.5)*h*.2,_=-a/2+(s+.5)*p+g,v=-c/2+(o+.5)*f+b;if(u.push({x:_,y:e*d+d/2,z:v}),r&&e>=r-1&&i===y-1)break}return u}for(let n=0;n<e;n++){const e=Math.floor(n/y);if(r&&e>=r)break;const i=n%y,s=i%m,o=Math.floor(i/m);let l=-a/2+(s+.5)*p;const h=-c/2+(o+.5)*f;"staggered"===t&&e%2==1&&(l+=p/2),u.push({x:l,y:e*d+d/2,z:h})}return u}class Oy{constructor(t,e={}){this.pattern=t,this.defaults=e}layout(t,e,n,i={}){const s=i.gap??this.defaults.gap??0,r=i.heightLimit??this.defaults.heightLimit,o=i.fill??this.defaults.fill;return Py(this.pattern,t,e,n,s,r,o).map(t=>({position:t}))}}class Dy{constructor(t,e,n={}){this.cols=t,this.rows=e,this.defaults=n}layout(t,e,n,i={}){const s=Math.max(1,this.cols),r=Math.max(1,this.rows),o=s*r,a=i.gap??this.defaults.gap??0,c=n.w+a,l=n.h+a,h=[];for(let e=0;e<t;e++){const t=Math.floor(e/o),i=e%o,a=i%s,d=Math.floor(i/s);h.push({position:{x:(a-(s-1)/2)*c,z:(d-(r-1)/2)*l,y:t*n.d+n.d/2}})}return h}}class zy{constructor(t=.1,e=!1,n=!1){this.gapRatio=t,this.fillFromFar=e,this.sliceFirst=n}grid(t,e){const n=e.w*this.gapRatio,i=e.h*this.gapRatio;return{cols:Math.max(1,Math.floor((t.w-n)/(e.w+n))),rows:Math.max(1,Math.floor((t.h-i)/(e.h+i))),pitchX:e.w+n,pitchZ:e.h+i}}capacity(t,e,n){const{cols:i,rows:s}=this.grid(t,e);return i*s*Math.max(1,Math.floor(n))}layout(t,e,n,i={}){const{cols:s,rows:r,pitchX:o,pitchZ:a}=this.grid(e,n),c=n.d+n.d*this.gapRatio,l=null!=i.heightLimit?Math.max(1,Math.floor(i.heightLimit)):1/0,h=Number.isFinite(l),d=this.sliceFirst&&h,u=s*r,p=s*(h?l:1),f=s*r*(h?l:t),m=Math.min(t,f),g=[];for(let t=0;t<m;t++){let e,i,l;if(d){const n=Math.floor(t/p),r=t%p;e=r%s,l=Math.floor(r/s),i=n}else{l=Math.floor(t/u);const n=t%u;e=n%s,i=Math.floor(n/s)}this.fillFromFar&&(i=r-1-i),g.push({position:{x:(e-(s-1)/2)*o,z:(i-(r-1)/2)*a,y:l*c+n.d/2}})}return g}}function Iy(t,e,n,i=0){for(let s=0;s<e.length;s++){const r=e[s],o=n[s];r&&o&&(r.parent!==t&&t.attach(r),r.position.set(o.position.x,i+o.position.y,o.position.z),o.rotation?r.quaternion.set(o.rotation.x,o.rotation.y,o.rotation.z,o.rotation.w):r.quaternion.identity())}}function Ry(t,e,n,i=.12){const s=e.left+e.width/2,r=e.top+e.height/2,o=Math.min(n.w,n.h)*i,a=new Map;for(const e of t){const t=`${Math.round(e.position.x)},${Math.round(e.position.z)}`;let i=a.get(t);i||(i={x:s+e.position.x-n.w/2+o,y:r+e.position.z-n.h/2+o,w:n.w-2*o,h:n.h-2*o,count:0},a.set(t,i)),i.count++}return[...a.values()]}function jy(t){return{id:t?.state?.id??t?.id??t?.refid,type:t?.state?.type??t?.type}}const Ly=new e.Euler;function Fy(t,n){Ly.setFromQuaternion(new e.Quaternion(n.x,n.y,n.z,n.w),"YXZ"),t.rotationX=Ly.x,t.rotation=-Ly.y,t.rotationY=Ly.z}const Ny="_transferSlotId",Hy=new Set(["left","top","width","height","depth","zPos","rotation","rotationX","rotationY","rotationZ","scale","translate","material3d","fillStyle","strokeStyle","lineWidth","lineDash","alpha","opacity","hidden","text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline","shadow","border","cssText","object3d","_realObject","refid","id"]);function By(t){return class extends t{async ready(){await super.ready();const t=this.state?.data;Array.isArray(t)&&0===this._items.length&&!this.isRecordStorage&&this._reconcileItems(t)}set data(t){if(Array.isArray(t)){if(this.isRecordStorage){const e=this.setState;return void("function"==typeof e&&e.call(this,{data:t}))}this._reconcileItems(t)}else this.setState?.({data:t})}get data(){if(this.isRecordStorage)return this.state?.data??[];const t=this._exportSlotRecords();return 0===t.length?this.state?.data:t}_reconcileItems(t){const e=new Map;for(const n of t){const t=this._recordKey(n);t&&e.set(t,n)}const n=new Map;for(const t of this._items){const e=t[Ny];null!=e&&n.set(String(e),t)}for(const[t,i]of n)if(!e.has(t)){try{this.removeItem(i,!0)}catch{}try{i?.dispose?.()}catch{}}for(const[t,i]of e){if(n.has(t))continue;if(null==i.itemId)continue;const e=this._createItemFromRecord(i);if(e){e[Ny]=t;try{this.handoverIn(e)}catch{}}}for(const[t,i]of e){const e=n.get(t);if(e&&(i.itemState&&"function"==typeof e.setState))try{e.setState(i.itemState)}catch{}}}_exportSlotRecords(){const t=this.slotIds?.()??[],e=[],n=new Map,i=[];for(const t of this._items){const e=t[Ny];null!=e?n.set(String(e),t):i.push(t)}for(const i of t){const t=n.get(i)??null;e.push(this._slotRecordOf(i,t))}for(const t of i)e.push(this._slotRecordOf("",t));for(const[i,s]of n)t.includes(i)||e.push(this._slotRecordOf(i,s));return e}_recordKey(t){return t.slotId??t.cellId??""}_slotRecordOf(t,e){if(!e)return{slotId:t,itemId:null};const n=e?.state?.id;return{slotId:t,itemId:null!=n?String(n):null,itemType:e?.state?.type,itemState:this._extractItemState(e)}}_extractItemState(t){const e=t?.state;if(!e||"object"!=typeof e)return;const n=this._businessFields?.();if(Array.isArray(n)){if(0===n.length)return;const t={};for(const i of n)i in e&&void 0!==e[i]&&(t[i]=e[i]);return Object.keys(t).length>0?t:void 0}const i={};for(const t of Object.keys(e))Hy.has(t)||t.startsWith("_")||(i[t]=e[t]);return Object.keys(i).length>0?i:void 0}_businessFields(){return null}_createItemFromRecord(t){const e=t.itemType??t.type;if(!e)return null;try{const n=Tc.register?.(e);if(n&&"function"==typeof n){return new n({type:e,...t.itemState??{}})}}catch{}return null}}}class Gy{positionAt(t,e,n){return 0!==t?null:e.localPosition??{x:0,y:0,z:0}}capacity(t){return 1}}const Vy=new Gy,Yy=[{id:"__default__",maxCount:1/0}];function Wy(t){var n;return n=class extends t{get slots(){return[]}get arrangementStrategy(){return Vy}canReceive(t,e){const n=null!==this.findSlot(t);return Iu.log({role:"target",contract:"canReceive",component:this,args:{carrier:jy(t)},result:n}),n}findSlot(t){const e=this.slots.length?this.slots:Yy;for(const n of e){if(n.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!n.allowedTypes.includes(e))continue}const e=n.maxCount??this.arrangementStrategy.capacity(n),i=this._countOccupied(n.id);if(!(i>=e))return Iu.log({role:"target",contract:"findSlot",component:this,args:{carrier:jy(t)},result:{slotId:n.id,occupied:i,max:e}}),n}return Iu.log({role:"target",contract:"findSlot",component:this,args:{carrier:jy(t)},result:null}),null}acceptanceRotation(t,e){}deliveryWorldRotation(t){const n=this.acceptanceRotation?.(t);if(!n)return;const i=this._realObject?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new e.Quaternion;i.getWorldQuaternion(s);const r=new e.Quaternion(n.x,n.y,n.z,n.w);return s.clone().multiply(r)}deliveryWorldPosition(t){const n=this._realObject,i=n?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new e.Vector3;i.getWorldPosition(s);const r=this._receivingSurfaceLocalY();if(null!==r){const t=new e.Vector3(0,r,0);return i.localToWorld(t),{x:s.x,y:t.y,z:s.z}}return{x:s.x,y:s.y,z:s.z}}attachPointFor(t){const e=t?.[Ny];if(!e)return null;const n=this.slots.find(t=>t.id===e);return n?{position:n.localPosition??{x:0,y:0,z:0},rotation:n.localRotation??{x:0,y:0,z:0},slotId:n.id}:null}placementFor(t,e={}){const n=t&&"object"==typeof t&&"state"in t?t:void 0,i=n?n.state??{}:t??{},s={width:Number(i.width)||0,height:Number(i.height)||0,depth:Number(i.depth)||0},r=e.slot??this.slots.find(t=>{const e=t.maxCount??this.arrangementStrategy.capacity(t);return this._countOccupied(t.id)<e});if(!r)return null;const o=e.index??this._countOccupied(r.id),a=e.occupantCount??o,c=this.arrangementStrategy.positionAt(o,r,a,n??{state:{...s}});if(!c)return null;const l=Number(this.state?.width)||0,h=Number(this.state?.height)||0,d=c.x+s.width/2-l/2,u=c.y+s.height/2-h/2,p=this._realObject,f=p?.placementMode??"floor",m="space"===f?0:"inverted"===f?-s.depth/2:s.depth/2,g=this._receivingSurfaceLocalY();let y;y=null!==g?g+m:r.localPosition&&Number.isFinite(r.localPosition.z)?r.localPosition.z+m:m-(p?.geometricOffsetY??0);const b=this.acceptanceRotation?.(n??s,r)??void 0;return b?{position:{x:d,y:y,z:u},rotation:b}:{position:{x:d,y:y,z:u}}}_zPosFromSeatY(t,e,n){const i=this._realObject,s=i?.receivingSurfaceY??0,r=!(!n.localPosition||!Number.isFinite(n.localPosition.z));if(0===s&&!r)return null;const o=Number(e)||0,a=i?.placementMode??"floor";return t-("space"===a?0:"inverted"===a?-o/2:o/2)+(i?.geometricOffsetY??0)-s}_receivingSurfaceLocalY(){const t=this._realObject,e=t?.receivingSurfaceY;return"number"!=typeof e||0===e?null:e-(t.geometricOffsetY??0)}_countOccupied(t){const e=this._items;if(e)return e.filter(e=>e?.[Ny]===t).length;const n=this.components;return n?n.filter(e=>e.parent===this&&e[Ny]===t).length:0}},n.__hasCapacity=!0,n}function Uy(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return[];const o="number"==typeof t.rotation?t.rotation:0,a=Math.cos(o),c=Math.sin(o),l=n+s/2,h=i+r/2,d="inbound"===e?-1:1;return[{lx:-s/2,lz:0,odx:-1,odz:0},{lx:s/2,lz:0,odx:1,odz:0},{lx:0,lz:-r/2,odx:0,odz:-1},{lx:0,lz:r/2,odx:0,odz:1}].map(t=>{var e,n;return{worldPos:(e=t.lx,n=t.lz,{x:l+e*a-n*c,z:h+e*c+n*a}),direction:{x:d*(t.odx*a-t.odz*c),z:d*(t.odx*c+t.odz*a)},halfSpan:0!==t.odx?r/2:s/2}})}function $y(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return{inbounds:[],outbounds:[]};const o="number"==typeof t.rotation?t.rotation:0,a=e??"reverse"===t.status,c="vertical"===t.orientation||"horizontal"!==t.orientation&&s<r,l=n+s/2,h=i+r/2,d=c?r/2:s/2,u=c?0:1,p=c?1:0,f=Math.cos(o),m=Math.sin(o),g=(t,e)=>({x:l+t*f-e*m,z:h+t*m+e*f}),y=c?{lx:0,lz:-d}:{lx:-d,lz:0},b=c?{lx:0,lz:d}:{lx:d,lz:0},_=g(y.lx,y.lz),v=g(b.lx,b.lz),x={x:u*f-p*m,z:u*m+p*f},w=Math.hypot(x.x,x.z)||1,M={x:x.x/w,z:x.z/w},S={x:-M.x,z:-M.z},k=(c?s:r)/2;return a?{inbounds:[{worldPos:v,direction:S,halfSpan:k}],outbounds:[{worldPos:_,direction:S,halfSpan:k}]}:{inbounds:[{worldPos:_,direction:M,halfSpan:k}],outbounds:[{worldPos:v,direction:M,halfSpan:k}]}}function Xy(t){const e=t.left??0,n=t.top??0,i=t.width??0,s=t.height??0;if(i<=0||s<=0)return null;const r="number"==typeof t.rotation?t.rotation:0,o="vertical"===t.orientation||"horizontal"!==t.orientation&&i<s,a=e+i/2,c=n+s/2,l=o?s/2:i/2,h=Math.cos(r),d=Math.sin(r),u=(t,e)=>({x:a+t*h-e*d,z:c+t*d+e*h});return{start:o?u(0,-l):u(-l,0),end:o?u(0,l):u(l,0)}}function qy(t){const e=t.cx??0,n=t.cy??0,i=Math.abs(t.rx??100),s=Math.abs(t.ry??100),r=t.ratio??50,o=(i+i*r/100)/2,a=(s+s*r/100)/2,c=t.startAngle??0,l=t.endAngle??Math.PI/2,h="reverse"===t.status;if(i<=0||s<=0)return{inbounds:[],outbounds:[]};const d={x:e+o*Math.sin(c),z:n-a*Math.cos(c)},u={x:e+o*Math.sin(l),z:n-a*Math.cos(l)},p={x:Math.cos(c),z:Math.sin(c)},f={x:Math.cos(l),z:Math.sin(l)};return h?{inbounds:[{worldPos:u,direction:{x:-f.x,z:-f.z}}],outbounds:[{worldPos:d,direction:{x:-p.x,z:-p.z}}]}:{inbounds:[{worldPos:d,direction:p}],outbounds:[{worldPos:u,direction:f}]}}function Ky(t){const e=$y(t),n=e.outbounds[0];if(!n)return{inbounds:Uy(t,"inbound"),outbounds:[]};const i=Uy(t,"inbound").filter(t=>{const e=t.worldPos.x-n.worldPos.x,i=t.worldPos.z-n.worldPos.z;return Math.hypot(e,i)>1}),s=n.direction,r=[];for(const t of i){const e=t.direction.x*s.x+t.direction.z*s.z;if(Math.abs(e)>=.1)continue;const n=t.direction.x+s.x,i=t.direction.z+s.z,o=Math.hypot(n,i)||1;r.push({worldPos:t.worldPos,direction:{x:n/o,z:i/o},halfSpan:t.halfSpan})}return{inbounds:[...i,...r],outbounds:e.outbounds}}function Qy(t,e,n={}){const i=n.distance??5,s=n.cosine??.9;if(t.direction.x*e.direction.x+t.direction.z*e.direction.z<s)return!1;const r=t.worldPos.x-e.worldPos.x,o=t.worldPos.z-e.worldPos.z;if("number"==typeof t.halfSpan&&"number"==typeof e.halfSpan){const n=t.direction.x,s=t.direction.z;if(Math.abs(r*n+o*s)>i)return!1;const a=Math.abs(r*-s+o*n);return t.halfSpan+e.halfSpan-a>0}return Math.hypot(r,o)<=i}function Zy(t,e,n,i=0){const s=n.width??0,r=n.height??0;if(s<=0||r<=0)return!1;const o=(n.left??0)+s/2,a=(n.top??0)+r/2,c="number"==typeof n.rotation?n.rotation:0,l=Math.cos(-c),h=Math.sin(-c),d=t-o,u=e-a,p=d*l-u*h,f=d*h+u*l;return Math.abs(p)<=s/2+i&&Math.abs(f)<=r/2+i}function Jy(t,e,n){const i=n.width??0,s=n.height??0;if(i<=0||s<=0)return 1/0;const r=(n.left??0)+i/2,o=(n.top??0)+s/2;let a=t.x-r,c=t.z-o,l=e.x,h=e.z;const d="number"==typeof n.rotation?n.rotation:0;if(0!==d){const t=Math.cos(-d),e=Math.sin(-d),n=a*e+c*t,i=l*e+h*t;a=a*t-c*e,c=n,l=l*t-h*e,h=i}const u=i/2,p=s/2;let f=-1/0,m=1/0;if(Math.abs(l)<1e-9){if(a<-u||a>u)return 1/0}else{const t=(-u-a)/l,e=(u-a)/l;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}if(Math.abs(h)<1e-9){if(c<-p||c>p)return 1/0}else{const t=(-p-c)/h,e=(p-c)/h;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}return m<f?1/0:f>=0?f:m>=0?Math.min(-f,m):-m}function tb(t,e,n,i=6){return!!Zy(t.worldPos.x,t.worldPos.z,e,i)&&(!n||t.direction.x*n.x+t.direction.z*n.z>=0)}function eb(t,e,n){return t.outbounds.map(t=>{const i=[];for(const s of e){let e=null;for(const i of s.topology.inbounds){if(!Qy(t,i,n))continue;const s=t.worldPos.x-i.worldPos.x,r=t.worldPos.z-i.worldPos.z,o=Math.hypot(s,r);(null===e||o<e)&&(e=o)}if(null===e&&s.bounds){const i=s.topology.outbounds[0]?.direction,r=!(s.topology.outbounds&&s.topology.outbounds.length)?n?.sinkMargin??30:6;if(tb(t,s.bounds,i,r)){const n=Jy(t.worldPos,t.direction,s.bounds);if(Number.isFinite(n))e=n+1e3;else{const n=(s.bounds.left??0)+(s.bounds.width??0)/2,i=(s.bounds.top??0)+(s.bounds.height??0)/2;e=Math.hypot(t.worldPos.x-n,t.worldPos.z-i)+1e3}}}null!==e&&i.push({id:s.id,dist:e})}return 0===i.length?null:(i.sort((t,e)=>t.dist-e.dist||(t.id<e.id?-1:1)),i[0].id)})}function nb(t,e){const n=new Map;for(const e of t)n.set(e.id,e);const i=new Map,s=new Set;for(const n of t){const r=t.filter(t=>t.id!==n.id),o=eb(n.topology,r,e);i.set(n.id,o);for(const t of o)null!=t&&s.add(t)}const r=(t,e)=>{if(!n.has(t)||!n.has(e)||t===e)return;const r=i.get(t)??[];r.includes(e)||(r.push(e),i.set(t,r),s.add(e))};for(const e of t)if(e.links){for(const t of e.links.downstream??[])r(e.id,t);for(const t of e.links.upstream??[])r(t,e.id)}const o=new Set,a=new Set;for(const e of t){(i.get(e.id)??[]).some(t=>null!=t)||o.add(e.id),s.has(e.id)||a.add(e.id)}return{nodes:n,out:i,sinks:o,sources:a}}function ib(t,e){const n=new Map;return(t.out.get(e)??[]).map(e=>{if(null==e)return new Set;const i=new Set([e]);for(const s of function(t,e,n){const i=n.get(e);if(i)return i;const s=new Set,r=[e],o=new Set([e]);for(;r.length;){const e=r.shift();for(const n of t.out.get(e)??[])null!=n&&(s.add(n),o.has(n)||(o.add(n),r.push(n)))}return n.set(e,s),s}(t,e,n))i.add(s);return i})}function sb(t,e,n,i){return e===n?0:function(t,e,n){const i=n.get(e);if(i)return i;const s=new Map([[e,0]]),r=[e];for(;r.length;){const e=r.shift(),n=s.get(e);for(const i of t.out.get(e)??[])null==i||s.has(i)||(s.set(i,n+1),r.push(i))}return n.set(e,s),s}(t,e,i).get(n)??1/0}function rb(t,e,n){const i=t.out.get(e)??[],s=new Map,r=[];for(let e=0;e<i.length;e++){const o=i[e];if(null==o)continue;const a=o===n?0:sb(t,o,n,s);a!==1/0&&r.push({i:e,hops:1+a})}return r.sort((t,e)=>t.hops-e.hops||t.i-e.i),r.map(t=>t.i)}function ob(t,e,n){const i=rb(t,e,n);return i.length?i[0]:-1}function ab(t,e,n){return e===n||rb(t,e,n).length>0}function cb(t,e){const n=new Set;for(const i of ib(t,e))for(const e of i)t.sinks.has(e)&&n.add(e);return n}function lb(t,e,n){return hb(t,e,n).map(t=>t.index)}function hb(t,e,n){const i=n instanceof Set?n:new Set(n);if(0===i.size)return[];const s=t.out.get(e)??[],r=new Map,o=[...i].sort(),a=[];for(let e=0;e<s.length;e++){const n=s[e];if(null==n)continue;let i=1/0,c="";for(const e of o){const s=1+(n===e?0:sb(t,n,e,r));s<i&&(i=s,c=e)}i!==1/0&&a.push({index:e,hops:i,target:c})}return a.sort((t,e)=>t.hops-e.hops||t.index-e.index),a}function db(t,e={}){const n=[],i=e.loopCapableIds??new Set,s=e.routingTargetIds??new Set;for(const e of[...t.sources].sort()){const i=t.nodes.get(e);if(!i||!i.topology.outbounds?.length)continue;(t.out.get(e)??[]).some(t=>null!=t)||n.push({severity:"error",code:"orphan-source",nodeId:e,message:`source 노드 "${e}" 가 outgoing edge 0 — 아무 데도 carrier 를 보낼 수 없음`})}for(const e of[...t.nodes.keys()].sort()){(t.out.get(e)??[]).some(t=>null!=t)||(s.has(e)||t.sources.has(e)||n.push({severity:"error",code:"dead-end",nodeId:e,message:`노드 "${e}" 가 outgoing 0 인데 RoutingTarget 자격 없음 — routing 미정의 종착`}))}const r=function(t){const e=[],n=[...t.nodes.keys()].sort(),i=new Set,s=[],r=new Set,o=n=>{i.add(n),s.push(n),r.add(n);for(const a of t.out.get(n)??[])if(null!=a)if(r.has(a)){const t=s.indexOf(a),n=s.slice(t),i=n.indexOf([...n].sort()[0]),r=[...n.slice(i),...n.slice(0,i)],o=r.join("→");e.some(t=>t.join("→")===o)||e.push(r)}else i.has(a)||o(a);s.pop(),r.delete(n)};for(const t of n)i.has(t)||o(t);return e.sort((t,e)=>t[0].localeCompare(e[0])||t.length-e.length),e}(t);for(const t of r){t.some(t=>i.has(t))||n.push({severity:"error",code:"cycle",cycle:t,message:`의도 cycle 자격 (isLoop) 없는 cycle: ${t.join(" → ")} → ${t[0]}`})}const o=e.routingWeights;if(o)for(const[t,e]of[...o].sort((t,e)=>t[0].localeCompare(e[0])))(!Number.isFinite(e)||e<=0)&&n.push({severity:"warning",code:"invalid-weight",nodeId:t,message:`RoutingTarget "${t}" 의 routingWeight=${e} — weight ≤ 0 비정상, weight 정책에서 제외됨`});const a=new Set;for(const e of t.out.values())for(const t of e)null!=t&&a.add(t);for(const e of[...s].sort())t.nodes.has(e)&&(a.has(e)||n.push({severity:"warning",code:"unreachable-target",nodeId:e,message:`RoutingTarget "${e}" 에 incoming edge 0 — 누구도 이쪽으로 carrier 를 보내지 않음`}));return n.sort((t,e)=>t.code!==e.code?t.code.localeCompare(e.code):(t.nodeId??"").localeCompare(e.nodeId??"")),n}function ub(t,e){if(!t)return[];const n=[],i=new Set,s=t=>{if(!t||i.has(t))return;if(i.add(t),t!==e&&"function"==typeof t?.getSegmentTopology){const e=t.state?.id,i=t.refid??t.state?.refid,s="string"==typeof e&&e.length>0?e:null!=i?String(i):void 0;if(s)try{const e=t.getSegmentTopology(),i=t.state??{},r={left:i.left,top:i.top,width:i.width,height:i.height,rotation:i.rotation};e&&n.push({id:s,topology:e,bounds:r})}catch{}}const r=t?.components;if(Array.isArray(r))for(const t of r)s(t)};return s(t),n}function pb(t,e){const n=t.state?.targetRef??t.state?.downstreamRef;if("string"==typeof n&&n.length>0)return n;if("function"!=typeof t.getSegmentTopology)return null;const i=t.getSegmentTopology();if(!i||0===i.outbounds.length)return null;const s=eb(i,ub(t.parent??t.rootModel??t.root,t).filter(t=>t.topology.inbounds.length>0),e);for(const t of s)if(t)return t;return null}function fb(t){return!!t&&"function"==typeof t.routingConstraints}function mb(t){return!!t&&"function"==typeof t.acceptedCarrierData}function gb(t,e=16){const n=[],i=t.parent??t.rootModel??t.root;if(!i)return n;const s=pb(t);if(!s)return n;const r=_b(i,s);if(!r)return n;const o=[{segment:r,accumulated:{},pathIds:[s],visited:new Set([s])}];for(;o.length>0;){const t=o.shift();if(t.pathIds.length>e)continue;const s=fb(t.segment)?t.segment.routingConstraints():null;if(s&&s.length>0)for(const e of s)for(const s of e.candidates){const r=yb(t.accumulated,s);if(!r)continue;const a=bb(t.segment,e.portId,i);a&&!t.visited.has(a.state?.id??"")?o.push({segment:a,accumulated:r,pathIds:[...t.pathIds,a.state?.id??"?"],visited:new Set([...t.visited,a.state?.id??""])}):n.push({data:r,weight:1,pathIds:[...t.pathIds,`${e.portId}`],destination:e.portId})}else{if(mb(t.segment)){const e=t.segment.acceptedCarrierData(),i=t.segment.state?.id;if(0===e.length)n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:i});else for(const s of e){const e=yb(t.accumulated,s);e&&n.push({data:e,weight:1,pathIds:t.pathIds,destination:i})}continue}const e=pb(t.segment);if(!e||t.visited.has(e)){n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:t.pathIds[t.pathIds.length-1]});continue}const s=_b(i,e);if(!s)continue;o.push({segment:s,accumulated:t.accumulated,pathIds:[...t.pathIds,e],visited:new Set([...t.visited,e])})}}return n}function yb(t,e){const n={...t};for(const[t,i]of Object.entries(e)){if(t in n&&n[t]!==i)return null;n[t]=i}return n}function bb(t,e,n){if("straight"===e&&t.state?.downstreamRef)return _b(n,t.state.downstreamRef);const i=_b(n,e);if(i)return i;const s=pb(t);return s?_b(n,s):null}function _b(t,e){if(!t||!e)return null;if("function"==typeof t.findById)return t.findById(e);const n=new Set,i=t=>{if(!t||n.has(t))return null;if(n.add(t),t.state?.id===e)return t;const s=t.components;if(Array.isArray(s))for(const t of s){const e=i(t);if(e)return e}return null};return i(t)}function vb(t,e){return Math.hypot(t.x-e.x,t.z-e.z)}function xb(t,e,n=5,i=[],s=n){const r=t.length,o=new Array(r).fill(void 0),a=new Set,c=(e,n)=>"start"===n?t[e].start:t[e].end,l=[],h=new Map,d=[],u=new Map;for(const t of i){const e=Array.isArray(t),n=e?t:t.positions,i=e?void 0:t.kind;if(!n.length)continue;const s=l.length;l.push({pos:n[0],members:[]});for(const t of n)d.push({pos:t,pt:s});i&&u.set(s,i)}const p=(t,e)=>{const i=c(t,e),s=h.get(`${t}:${"end"===e?"start":"end"}`),r=[];for(const t of d)vb(t.pos,i)<=n&&!r.includes(t.pt)&&r.push(t.pt);for(let t=0;t<l.length;t++)vb(l[t].pos,i)<=n&&!r.includes(t)&&r.push(t);let o=r.find(t=>t!==s)??-1;o<0&&(o=l.length,l.push({pos:i,members:[]})),l[o].members.push({seg:t,end:e}),h.set(`${t}:${e}`,o)};for(let t=0;t<r;t++)p(t,"start"),p(t,"end");const f=new Set,m=new Set,g=new Set;{const t=t=>{let e=-1,n=1/0;for(let i=0;i<l.length;i++){const s=vb(l[i].pos,t);s<n&&(n=s,e=i)}for(const i of d){const s=vb(i.pos,t);s<n&&(n=s,e=i.pt)}return{pt:e,d:n}};for(const n of e){const{pt:e,d:i}=t(n.pos);e>=0&&i<=s&&(f.add(e),("source"===n.kind?m:g).add(e))}}for(const[t,e]of u)f.add(t),("source"===e?m:g).add(t);const y=(t,e)=>"end"===e!==o[t],b=[],_=(e,n)=>{if(void 0===o[e])return o[e]=n,void b.push(e);o[e]!==n&&a.add(t[e].id)},v=t=>{for(const e of["start","end"]){const n=h.get(`${t}:${e}`);if(void 0===n)continue;const i=l[n];if(2!==i.members.length||f.has(n))continue;const s=i.members[0],r=s.seg===t&&s.end===e?i.members[1]:s;if(r.seg===t)continue;const a="end"===e!==o[t],c="end"===r.end!==!a;_(r.seg,c)}},x=()=>{for(;b.length;)v(b.shift())},w=t=>{let e=-1,n="start",i=1/0;for(let s=0;s<r;s++)for(const r of["start","end"]){const o=vb(c(s,r),t.pos);o<i&&(i=o,e=s,n=r)}if(e<0||i>s)return;const o="source"===t.kind?"end"===n:"start"===n;_(e,o)};for(const t of e)"source"===t.kind&&w(t);x();for(const t of e)"sink"===t.kind&&w(t);x();let M=!0;for(;M;){M=!1;for(const t of l){if(t.members.length<3)continue;const e=t.members.filter(t=>void 0===o[t.seg]);if(1!==e.length)continue;let n=0,i=0;for(const e of t.members)void 0!==o[e.seg]&&(y(e.seg,e.end)?n++:i++);const s=e[0];let r;0===i&&n>0?r="end"===s.end:0===n&&i>0&&(r="start"===s.end),void 0!==r&&(o[s.seg]=r,b.push(s.seg),x(),M=!0)}}if(o.some(t=>void 0===t)&&m.size>0&&g.size>0){const t=t=>{const e=new Array(l.length).fill(1/0),n=[];for(const i of t)e[i]=0,n.push(i);for(;n.length;){const t=n.shift();for(const i of l[t].members){const s=h.get(`${i.seg}:${"start"===i.end?"end":"start"}`);void 0!==s&&e[s]>e[t]+1&&(e[s]=e[t]+1,n.push(s))}}return e},e=t(m),n=t(g);for(let t=0;t<r;t++){if(void 0!==o[t])continue;const i=h.get(`${t}:start`),s=h.get(`${t}:end`);if(void 0===i||void 0===s)continue;if(l[i].members.length<2||l[s].members.length<2)continue;if(e[i]===1/0||e[s]===1/0||n[i]===1/0||n[s]===1/0)continue;let r;e[i]!==e[s]?r=e[i]<e[s]:n[i]!==n[s]&&(r=n[s]<n[i]),void 0!==r&&(o[t]=!r,b.push(t))}x()}const S=new Map;for(let e=0;e<r;e++)S.set(t[e].id,void 0===o[e]?"unknown":o[e]?"reverse":"forward");return{directions:S,conflicts:[...a]}}function wb(...t){}function Mb(t){return String(t?.state?.id??t?.refid??t?.state?.refid??"?")}function Sb(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*kb(t){if(!t)return;("function"==typeof t.getSegmentTopology||t.flowOrientable)&&(yield t);const e=t.components;if(Array.isArray(e))for(const t of e)yield*kb(t)}function Ab(t,e,n){const i=e.width??0,s=e.height??0;if(i<=0||s<=0)return!1;const r=(e.left??0)+i/2,o=(e.top??0)+s/2,a="number"==typeof e.rotation?e.rotation:0,c=t.x-r,l=t.z-o,h=Math.cos(-a),d=Math.sin(-a),u=c*h-l*d,p=c*d+l*h;return Math.abs(u)<=i/2+n&&Math.abs(p)<=s/2+n}function Eb(t){const e=[],n=[],i=[],s=[];for(const r of kb(t)){const t=Sb(r);if(!t)continue;if(r.flowOrientable){const n=Xy(r.state??{});n&&e.push({id:t,start:n.start,end:n.end});continue}if("function"==typeof r.openings){const t=r.state??{};(t.width??0)>0&&(t.height??0)>0&&s.push(t);continue}let o;try{o=r.getSegmentTopology()}catch{continue}if(!o)continue;const a=o.inbounds??[],c=o.outbounds??[],l="function"==typeof r.routingDestination;if(0===a.length&&c.length>0)for(const t of c)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"source"});else if(a.length>0&&(0===c.length||l))for(const t of a)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"sink"});else if(a.length>0||c.length>0){const t=[];for(const e of a)t.push({x:e.worldPos.x,z:e.worldPos.z});for(const e of c)t.push({x:e.worldPos.x,z:e.worldPos.z});t.length&&i.push({positions:t})}}for(const t of s){const s=[];for(const n of e)for(const e of[n.start,n.end])Ab(e,t,16)&&s.push(e);let r=!1,o=!1;for(const e of n)Ab(e.pos,t,16)&&("sink"===e.kind?r=!0:o=!0);const a=r&&!o?"sink":o&&!r?"source":void 0;(s.length>=2||a&&s.length>=1)&&i.push({positions:s,kind:a})}if(0===e.length||0===n.length)return new Map;return xb(e,n,8,i,60).directions}function Cb(t){const e=t?.root;if(!e)return;if(e.__flowComputing)return;let n=e.__flowOrientation;if(!n){e.__flowComputing=!0;try{n={map:Eb(e)}}finally{e.__flowComputing=!1}e.__flowOrientation=n}const i=Sb(t),s=i?n.map.get(i):void 0;return"reverse"===s||"forward"!==s&&void 0}function Tb(t){return!!t&&"function"==typeof t.distanceToBoardPoint}function Pb(t,e,n,i){if(!t||!e)return null;const s=[],r=t=>{if(!t||t===i)return;if(Dm(t,e)&&Tb(t)){const e=function(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}(t);e&&s.push({id:e,component:t,distance:t.distanceToBoardPoint(n.x,n.y)})}const o=t.components;if(Array.isArray(o))for(const t of o)r(t)};return r(t),0===s.length?null:(s.sort((t,e)=>t.distance-e.distance||t.id.localeCompare(e.id)),s[0])}function Ob(t){return!!t&&"function"==typeof t.routingDestination}function Db(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*zb(t){if(!t)return;yield t;const e=t.components;if(Array.isArray(e))for(const t of e)yield*zb(t)}function Ib(t){const e=[],n=new Map,i=new Map,s=new Set,r=[];for(const o of zb(t)){"function"==typeof o?.registerWithHost&&r.push(o);const t="function"==typeof o?.getSegmentTopology,a="function"==typeof o?.routingLinks?o.routingLinks():void 0,c=!(!a||!((a.downstream?.length??0)>0||(a.upstream?.length??0)>0));if(!(t||Ob(o)||c||Tb(o)))continue;const l=Db(o);if(!l)continue;let h={inbounds:[],outbounds:[]};if(t){try{h=o.getSegmentTopology()}catch{continue}if(!h)continue}const d=o.state??{},u={left:d.left,top:d.top,width:d.width,height:d.height,rotation:d.rotation};if(e.push({id:l,topology:h,bounds:u,links:a}),i.set(l,o),Ob(o)){s.add(l);const t=o.routingDestination();if("string"==typeof t&&t.length>0){const e=n.get(t)??[];e.push(l),n.set(t,e)}}}return{nodes:e,destToSinks:n,components:i,routingTargetIds:s,stationClients:r}}function Rb(t){if(!t)return null;let e=t.__flowGraph;if(!e){const{nodes:n,destToSinks:i,components:s,routingTargetIds:r,stationClients:o}=Ib(t),a=nb(n);!function(t,e){if(!t)return;const n=t=>{if(!t)return;"function"==typeof t.clearStations&&t.clearStations();const e=t.components;if(Array.isArray(e))for(const t of e)n(t)};n(t);const i=[...e].sort((t,e)=>{const n=Db(t)??"",i=Db(e)??"";return n.localeCompare(i)});for(const e of i){const n=e.declaredHostRef?.();let i=null;if(n&&(i=t.findById?.(n)??null),!i){const n=e.hostCapability?.(),s=e.hostFacingPoint?.();n&&s&&(i=Pb(t,n,s,e)?.component??null)}i&&"function"==typeof e.registerWithHost&&e.registerWithHost(i)}const s=e=>{if(!e)return;if(Tb(e)&&"function"==typeof e.resolveDownstream&&"function"==typeof e.registerDivertStation)for(const n of e.resolveDownstream()){const i=t.findById?.(n);i&&e.registerDivertStation(n,i)}const n=e.components;if(Array.isArray(n))for(const t of n)s(t)};s(t)}(t,o);const c=new Set;for(const[t,e]of s){((e?.state?.type??e?.model?.type??"").includes("loop")||!0===e?.isLoop)&&c.add(t)}const l=new Map;for(const t of r){const e=s.get(t);if("function"==typeof e?.routingWeight){const n=e.routingWeight();"number"==typeof n&&(!Number.isFinite(n)||n<=0)&&l.set(t,n)}}const h=db(a,{routingTargetIds:r,loopCapableIds:c,routingWeights:l});if(h.length>0&&"undefined"!=typeof console){const t=h.filter(t=>"error"===t.severity),e=h.filter(t=>"warning"===t.severity);t.length>0?console.warn(`[FlowGraph] ${t.length} error(s) / ${e.length} warning(s):`,h):console.info(`[FlowGraph] ${e.length} warning(s):`,h)}e={graph:a,destToSinks:i,components:s,issues:h},t.__flowGraph=e}return e}function jb(t){return Rb(t)?.issues??[]}function Lb(t){const e=Rb(t);return e&&e.graph.nodes.size>0?e.graph:null}function Fb(t,e){return Rb(t)?.destToSinks.get(e)??[]}function Nb(t,e){return Rb(t)?.components.get(e)}function Hb(t){const e=Rb(t);return e?[...e.destToSinks.keys()]:[]}function Bb(t){return Db(t)}function Gb(t){const e="number"==typeof t?.inventoryCount?t.inventoryCount:"function"==typeof t?.size?t.size():0,n=t?.state?.capacity;return"number"==typeof n&&n>0?e/n:e}function Vb(t,e,n,i,s){if(1===i.length)return i[0];switch(t){case"index":default:return i[0];case"round-robin":{const t=n.counters.get(e)??0;return n.counters.set(e,t+1),i[t%i.length]}case"weight":{const t=i.map(t=>function(t){if("function"==typeof t?.routingWeight){const e=t.routingWeight();if("number"==typeof e&&Number.isFinite(e)&&e>0)return e}return 1}(s.get(t.target))),r=t.reduce((t,e)=>t+e,0);if(r<=0)return i[0];const o=n.counters.get(e)??0;n.counters.set(e,o+1);let a=o%r;for(let e=0;e<i.length;e++){if(a<t[e])return i[e];a-=t[e]}return i[i.length-1]}case"utilization":{let t=1/0,e=i[0];for(const n of i){const i=Gb(s.get(n.target));i<t&&(t=i,e=n)}return e}}}function Yb(t,e,n){const i=t?.root;if(!i)return null;const s=e?.state?.meta?.destination;if("string"!=typeof s||0===s.length)return null;const r=Rb(i);if(!r||0===r.graph.nodes.size)return null;const o=Db(t);if(!o)return null;let a=r.destToSinks.get(s)??[];0===a.length&&(a=[s]);const c=hb(r.graph,o,a);if(0===c.length)return null;const l=r.graph.out.get(o)??[],h=c.filter(t=>{const n=l[t.index],i=n?r.components.get(n):null;return!i||"function"!=typeof i.canReceive||i.canReceive(e)});if(0===h.length)return l[c[0].index]??null;const d=n?.policy??function(t,e){const n=t?.state?.balancingPolicy;if(n)return n;const i=e?.state?.routingBalancingPolicy;return i||"round-robin"}(t,i),u=Vb(d,o,function(t){return t.__balancingState||(t.__balancingState={counters:new Map}),t.__balancingState}(i),h,r.components);return l[u.index]??null}Rm({name:"Capacity",description:"Item 을 *보유(keep)* 하는 측면 — slot 위상 / 수용 판정(canReceive/findSlot) / 3D 안착(placementFor/attachPointFor/acceptanceRotation) / delivery 좌표 질의 / 점유 수. 이동(receive/dispatch 등)은 Transferable 소관.",methods:["get slots","get arrangementStrategy","canReceive","findSlot","placementFor","attachPointFor","acceptanceRotation","deliveryWorldRotation","deliveryWorldPosition","_countOccupied"],sourceFile:"src/items/capacity-mixin.ts"}),Rm({name:"PlacementSurface",description:"carrier 가 holder 위 *정확히 어디에 앉는가* 의 단일 진입점 — placementFor(carrier, ctx) → SeatingPose (holder object3d local frame, 순수 함수). I1 접촉 (밑면 = 받침 상면) / I2 frame-explicit (parent-child 비가정 — Sovereign handover 와 reparent 양쪽이 같은 값 소비) / I3 순수성 / I4 per-carrier 치수. default 구현은 Capacity(FlowNode) 가 기존 receivingSurfaceY + ArrangementStrategy + acceptanceRotation 합성과 수치 동일하게 제공.",methods:["placementFor"],models:["CarrierDims","PlacementContext","SeatingPose"],sourceFile:"src/items/capacity-mixin.ts"});try{globalThis.__operatoBuildFlowGraph=(t,e)=>{try{return e?.force&&t&&delete t.__flowGraph,Lb(t)}catch{return null}}}catch{}function Wb(t,e,n){const i=Yb(t,e,n);if(null==i)return null;const s=t?.root,r=Nb(s,i)??s?.findById?.(i)??null;return r?{targetId:i,component:r,origin:"explicit"}:null}function Ub(t){const e=t?.root,n=Lb(e),i=Bb(t);if(!n||!i)return null;const s=(n.out.get(i)??[]).find(Boolean);if(!s)return null;const r=Nb(e,s)??e?.findById?.(s)??null;return r?{id:s,component:r}:null}function $b(t){const e=Bb(t);return e?Xb(t?.root,e):[]}function Xb(t,e){if(!t||!e)return[];const n=Lb(t);if(!n)return[];const i=new Set;for(const s of cb(n,e)){const e=Nb(t,s);if(Ob(e)){const t=e.routingDestination();"string"==typeof t&&t.length>0&&i.add(t)}}return[...i]}function qb(t,e){if(!t||!e)return[];const n=Lb(t);if(!n)return[];const i=new Map;for(const t of n.out.values())for(const e of t)null!=e&&i.set(e,(i.get(e)??0)+1);const s=new Map;for(const r of cb(n,e)){const e=Nb(t,r);if(!Ob(e))continue;const n=e.routingDestination();if("string"!=typeof n||0===n.length)continue;let o=null;if("function"==typeof e.routingWeight){const t=e.routingWeight();"number"==typeof t&&Number.isFinite(t)&&t>0&&(o=t)}null===o&&(o=i.get(r)??0,0===o&&(o=1)),s.set(n,(s.get(n)??0)+o)}return[...s].map(([t,e])=>({value:t,weight:e}))}function Kb(t){return Lb(t)}function Qb(t){const e=Lb(t);if(!e)return[];const n=new Set,i=new Set,s=t=>{if(!t)return;const r=Bb(t);if(r&&e.nodes.has(r)){Ob(t)&&n.add(r);((t?.state?.type??t?.model?.type??"").includes("loop")||!0===t?.isLoop)&&i.add(r)}const o=t.components;if(Array.isArray(o))for(const t of o)s(t)};return s(t),db(e,{routingTargetIds:n,loopCapableIds:i})}function Zb(t){if(0===t.length)return;const e=t.reduce((t,e)=>t+e.weight,0);if(e<=0)return t[Math.floor(Math.random()*t.length)].value;const n=Math.random()*e;let i=0;for(const e of t)if(i+=e.weight,n<i)return e.value;return t[t.length-1].value}const Jb={next:Wb,downstream:Ub,reachableDestinations:$b,reachableDestinationsFrom:Xb,reachableDestinationsWeightedFrom:qb,pickWeightedDestination:Zb,graphFor:Kb,validate:Qb};function t_(t){var e;return e=class extends t{constructor(){super(...arguments),this._items=[]}get items(){return this._items}containsItem(t){return-1!==this._items.indexOf(t)}attachPointFor(e,n){const i=t.prototype?.attachPointFor;return"function"==typeof i?i.call(this,e,n):null}addItem(t,e){if(!t||this.containsItem(t))return;const n=t.parent;if(n&&"function"==typeof n.removeItem&&n!==this&&n.removeItem(t,!0),this._items.push(t),t.parent=this,!e?.silent&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}t.held?.(this)}removeItem(t,e){if(!t)return;const n=this._items.indexOf(t);if(-1!==n&&(this._items.splice(n,1),t.parent=null,!e)){if("function"==typeof this.trigger)try{this.trigger("release",this,t,n)}catch{}t.released?.(this)}}forEachItem(t,e){this._items.forEach(t,e)}handoverIn(t,e){if(!t)return;const n=t.parent;n&&("function"==typeof n.removeComponent&&-1!==n._components?.indexOf?.(t)&&n.removeComponent(t,!0),n!==this&&"function"==typeof n.removeItem&&-1!==n._items?.indexOf?.(t)&&n.removeItem(t,!0));const i=-1===this._items.indexOf(t);if(i&&this._items.push(t),t.parent=this,i&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}const s=t._realObject,r=s?.object3d;if(r){let n,i,o=e?.toParent3D,a="world-preserve";if(!o){const s=this.attachPointFor?.(t,{slotId:e?.slotId});s?.attach&&(o=s.attach,n=s.localPosition,i=s.localRotation,a=s.carryPolicy??"world-preserve")}o&&r.parent!==o&&(o.updateWorldMatrix?.(!0,!1),r.updateWorldMatrix?.(!0,!1),o.attach(r),s.suppressTransform=!0),o&&(n&&r.position.set(n.x,n.y,n.z),"world-preserve"!==a?i?r.rotation.set(i.x,i.y,i.z):r.quaternion.identity():i&&r.rotation.set(i.x,i.y,i.z),s?.setTransientPlacement?.({policy:"carried",meta:{carryPolicy:a}}))}t.held?.(this),this._bumpReceived?.(t)}handoverOut(t){this.removeItem(t),this._bumpDispatched?.(t)}dispose(){const t=this._items.slice();this._items.length=0;for(const e of t)try{e.dispose?.()}catch{}super.dispose?.()}_drawItems(t){const e=this.root?.transitionEffect;for(const t of this._items)e?.isReparenting?.(t)||t.draw?.(this.getContext?.(t))}_captureItems(t,e,n,i,s){for(let r=this._items.length-1;r>=0;r--){const o=this._items[r],a="static"===o.position?o.capture?.(t,e,s):o.capture?.(n,i,s);if(a)return a}return null}postrender(t){super.postrender?.(t);const e=this;if("popup"===e.position)return;const n=this._items;if(!n||0===n.length)return;t.save();const i=e.bounds;!e.showOverflow&&i&&(t.beginPath(),t.rect(i.left,i.top,i.width,i.height),t.clip(),t.closePath());const{left:s=0,top:r=0}=e.state??{};t.translate(s,r),this._drawItems(t),t.translate(-s,-r),t.restore()}capture(t,e,n){const i=this,s=this._items;if(s&&s.length>0&&(!i.app||i.app.isEditMode||!i.hidden)){const s=i.fromParent?.(t,e);if(s&&i.contains?.(s.x,s.y)){const r=i.bounds,o=this._captureItems(s.x-r.left,s.y-r.top,t,e,n);if(o)return o}}return super.capture?.(t,e,n)}},e.capabilities=Object.freeze([...t.capabilities??[],"Holdable"]),e}function e_(t){var n;const i=!!t.__hasCapacity,s=!!t.__hasTransferable,r=i?t:Wy(t),o=s?r:function(t){var n;return(n=class extends t{reserve(t,e){const n=this.findSlot(t);return n?{slot:n,token:Symbol("slot-reservation")}:null}release(t){}async receive(t,e={}){Iu.log({role:"target",contract:"receive:enter",component:this,args:{carrier:jy(t),options:e}});const n=this.reserve(t,e);if(!n){Iu.log({role:"target",contract:"receive:reject",component:this,args:{carrier:jy(t)},result:{reason:"no-slot"}}),this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const e=new Error("receive rejected: no-slot");throw e.reason="no-slot",e}this.commit(n,t,e)}commit(t,n,i={}){const s=t.slot,r=this._countOccupied(s.id),o=this.arrangementStrategy.positionAt(r,s,r,n);Iu.log({role:"target",contract:"arrangementStrategy.positionAt",component:this,args:{idx:r,slotId:s.id,occupantCount:r,carrier:jy(n)},result:o}),n[Ny]=s.id;const a=n._realObject;let c,l;a?.object3d&&(a.object3d.updateWorldMatrix(!0,!1),c=new e.Vector3,l=new e.Quaternion,a.object3d.getWorldPosition(c),a.object3d.getWorldQuaternion(l));const{animated:h=!1,duration:d,ease:u}=i;"function"==typeof this.handoverIn?this.handoverIn(n,{slotId:s.id}):this.reparent?.(n,{animated:h,duration:d,ease:u}),!h&&n._realObject&&(n._realObject.suppressTransform=!1);{const t={},e=this.placementFor?.(n,{slot:s,index:r,occupantCount:r})??null;if(Iu.log({role:"target",contract:"placementFor",component:this,args:{carrier:jy(n),slotId:s.id,index:r},result:e}),e){const i=n.state??{},r=this.state??{};t.left=e.position.x-(Number(i.width)||0)/2+(Number(r.width)||0)/2,t.top=e.position.z-(Number(i.height)||0)/2+(Number(r.height)||0)/2;const o=this._zPosFromSeatY(e.position.y,i.depth,s);null!==o&&(t.zPos=o),e.rotation&&Fy(t,e.rotation)}else{if(o&&(t.left=o.x,t.top=o.y),0!==(this._realObject?.receivingSurfaceY??0))t.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const e=this._realObject?.geometricOffsetY??0;t.zPos=s.localPosition.z+e}const e=this.acceptanceRotation?.(n,s);Iu.log({role:"target",contract:"acceptanceRotation",component:this,args:{carrier:jy(n),slotId:s.id},result:e}),e&&Fy(t,e)}const i=this.normalizePose?.(n,s);"function"==typeof this.normalizePose&&Iu.log({role:"target",contract:"normalizePose",component:this,args:{carrier:jy(n),slotId:s.id},result:i}),i&&Object.assign(t,i),Object.keys(t).length&&(n.setState?.(t),Iu.log({role:"target",contract:"receive:setState",component:this,args:{carrier:jy(n),keys:Object.keys(t)}}))}this.trigger("transfer-received",{type:"transfer-received",component:n,container:this,slotId:s.id,preReceiveWorldPos:c,preReceiveWorldQuat:l}),Iu.log({role:"target",contract:"receive:done",component:this,args:{carrier:jy(n),slotId:s.id}})}async dispatch(t,e,n={}){const i=new Fu({source:this,target:e,carrier:t,options:n,physical:async()=>{delete t[Ny]}}),s=await i.execute();"rolled-back"!==s.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:s.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}canAccept(t){const e=(()=>{const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const n=this.findSlot(t);if(!n){const n=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!n||t.allowedTypes.includes(n))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:n}})();return Iu.log({role:"target",contract:"canAccept",component:this,args:{carrier:jy(t)},result:e.ok?{ok:!0,slotId:e.slot.id}:{ok:!1,reason:e.reason}}),e}accept(t,e){return this.receive(t,e)}}).__hasTransferable=!0,n}(r),a=[...t.capabilities??[]];i||a.push("Capacity","PlacementSurface"),s||a.push("Transferable"),a.push("Holdable","FlowNode");var c,l,h;return By((n=class extends(t_(o)){get isFlowNode(){return!0}containable(t){return!!t&&!0===t.isItem}get showMoveHandle(){return!1}inboundPorts(){return[]}outboundPorts(){return[]}_bumpReceived(t){const e=this.state?.received??0;this.setState?.({received:e+1})}_bumpDispatched(t){const e=this.state?.dispatched??0;this.setState?.({dispatched:e+1})}_bumpRejected(t,e){const n=this.state?.rejected??0;this.setState?.({rejected:n+1})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e){}resolveDownstream(){const t=this.state?.downstreamRef;if(!t)return[];return(this.root?.findAll?.(t)??[]).map(t=>t?.state?.id).filter(Boolean)}routingLinks(){return{downstream:this.resolveDownstream()}}},c=n,"symbol"==typeof(l="FlowNodeMixed")&&(l=l.description?"[".concat(l.description,"]"):""),Object.defineProperty(c,"name",{configurable:!0,value:h?"".concat(h," ",l):l}),n.capabilities=Object.freeze(a),n.isFlowNode=!0,n))}function n_(t){return!!t&&!0===t.isFlowNode}Rm({name:"Holdable",description:"어떤 Component 든 item(데이타바인딩 동적 물건) 을 보유하는 capability. _items + add/remove/forEach + handover + hold/release event + dispose cascade. Container(정적 _components) 와 직교 — 컨테이너 비의존.",methods:["addItem","removeItem","forEachItem","containsItem","handoverIn","handoverOut","_drawItems","_captureItems","dispose"],sourceFile:"src/components/mixins/holdable.ts"}),Rm({name:"Transferable",description:"Item 을 노드 간에 옮기는 *이동(move)* 측면. 수용 트랜잭션 라이프사이클(reserve → commit → release)과 receive/accept/dispatch/route 를 제공. 보유(keep — slots/findSlot/canReceive 등)는 Capacity 소관.",methods:["reserve","commit","release","receive","accept","canAccept","dispatch","route","resolveRoute","rejectRoute"],sourceFile:"src/transfer/transferable-mixin.ts"}),Rm({name:"FlowNode",description:"Flow graph 의 노드 — 구조 (inbound/outbound port + slot) + flow (route + 5-phase transfer stat). 보유(_items/handover)는 Holdable base 위임. 모든 flow 컴포넌트의 base — Storable/Mobile/Processable 의도가 위에 직교로 적용.",methods:["inboundPorts","outboundPorts","slotIds","slotAt","route","resolveRoute","rejectRoute"],models:["Port","SlotInfo","Vec3"],sourceFile:"src/flow/flow-node.ts"});const i_={x:0,y:0,z:0,w:1};function s_(t){const e=t/2;return{x:0,y:Math.sin(e),z:0,w:Math.cos(e)}}function r_(t,e){const n=t.rotation,i=e.rotation,s=e.position,r=n.w*s.x+n.y*s.z-n.z*s.y,o=n.w*s.y+n.z*s.x-n.x*s.z,a=n.w*s.z+n.x*s.y-n.y*s.x,c=-n.x*s.x-n.y*s.y-n.z*s.z,l=r*n.w+c*-n.x+o*-n.z-a*-n.y,h=o*n.w+c*-n.y+a*-n.x-r*-n.z,d=a*n.w+c*-n.z+r*-n.y-o*-n.x,u={x:n.w*i.x+n.x*i.w+n.y*i.z-n.z*i.y,y:n.w*i.y-n.x*i.z+n.y*i.w+n.z*i.x,z:n.w*i.z+n.x*i.y-n.y*i.x+n.z*i.w,w:n.w*i.w-n.x*i.x-n.y*i.y-n.z*i.z};return{position:{x:t.position.x+l,y:t.position.y+h,z:t.position.z+d},rotation:u}}const o_={east:{axis:{x:1,y:0,z:0},yaw:0,idSuffix:"east"},west:{axis:{x:-1,y:0,z:0},yaw:Math.PI,idSuffix:"west"},south:{axis:{x:0,y:0,z:1},yaw:-Math.PI/2,idSuffix:"south"},north:{axis:{x:0,y:0,z:-1},yaw:Math.PI/2,idSuffix:"north"}};function a_(t){const{carrierWorld:e,width:n,depth:i,entryHeight:s,mountLocalY:r,approachDistance:o,sides:a,toolType:c,tolerance:l,priority:h}=t,d="number"==typeof r?{position:{x:0,y:r,z:0},rotation:{...i_}}:void 0,u=n/2,p=i/2;return a.map(t=>{const n=o_[t],i="string"==typeof c?c:c[t]??"unknown",r={position:{x:n.axis.x*("east"===t||"west"===t?u:0),y:s,z:n.axis.z*("north"===t||"south"===t?p:0)},rotation:s_(n.yaw)},a={position:{x:r.position.x+n.axis.x*o,y:s,z:r.position.z+n.axis.z*o},rotation:s_(n.yaw)};return{id:`entry-${n.idSuffix}`,toolType:i,approach:r_(e,a),engage:r_(e,r),...d?{mount:d}:{},tolerance:l,priority:h}})}function c_(t){const{carrierWorld:e,topY:n,approachDistance:i,toolType:s,mountLocalY:r,tolerance:o,priority:a,id:c}=t,l={position:{x:0,y:n,z:0},rotation:{...i_}};return{id:c??"top",toolType:s,approach:r_(e,{position:{x:0,y:n+i,z:0},rotation:{...i_}}),engage:r_(e,l),..."number"==typeof r?{mount:{position:{x:0,y:r,z:0},rotation:{...i_}}}:{},tolerance:o,priority:a}}function l_(t,e){return t.filter(t=>t.toolType===e.toolType)}function h_(t,e){if(0===t.length)return null;const n=t.map(t=>{const n=t.approach.position.x-e.x,i=t.approach.position.y-e.y,s=t.approach.position.z-e.z;return{f:t,dist:Math.sqrt(n*n+i*i+s*s)}});return n.sort((t,e)=>{const n=t.f.priority??0,i=e.f.priority??0;return n!==i?n-i:t.dist-e.dist}),n[0].f}class d_{constructor(t){this.owner=t}positionAt(t,e,n,i){if(0!==t)return null;const s=this.owner?.state?.width??0,r=this.owner?.state?.height??0,o=i?.state?.width??0,a=i?.state?.height??0;return{x:Math.max(0,(s-o)/2),y:Math.max(0,(r-a)/2),z:0}}capacity(t){return t.maxCount??1}}let u_=1;function p_(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const f_={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class m_{constructor(t=f_){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+u_++},n=(this._byResource.get(e.resource)??[]).filter(t=>p_(t.timeWindow,e.timeWindow));if(0===n.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=n.map(t=>{const n=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:n}});if(i.every(t=>"b-yields"===t.decision)){const i=n.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:n.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>p_(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const n=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);n<0?e.push(t):e.splice(n,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const n=e.findIndex(e=>e.id===t.id);if(n<0)return!1;e.splice(n,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const g_=new m_;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=g_);class y_{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,n=1/0;for(const i of this.nodes.values()){const s=b_(i.position,t);s<n&&(n=s,e=i)}return e}}function b_(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}function __(t,e){return Math.sqrt(b_(t,e))}function v_(t,e,n={}){const i=new y_,s=n.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const n=`${e.id}:start`,r=`${e.id}:end`;i.addNode({id:n,position:t[0],type:"lane-start"}),i.addNode({id:r,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:n,endNodeId:r});let o=0;for(let e=1;e<t.length;e++)o+=__(t[e-1],t[e]);const a=o/(e.speedLimit??s)*1e3;i.addEdge({fromNode:n,toNode:r,resource:e.id,distance:o,durationMs:a,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:r,toNode:n,resource:e.id,distance:o,durationMs:a,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const n of t.lanes){const s=i.laneEndpoints.get(n);if(!s)continue;const r=i.nodes.get(s.startNodeId).position,o=i.nodes.get(s.endNodeId).position;let a=0,c=0,l=0;for(const e of t.lanes){if(e===n)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const s=i.nodes.get(t.startNodeId).position,h=i.nodes.get(t.endNodeId).position;a+=Math.min(b_(r,s),b_(r,h)),c+=Math.min(b_(o,s),b_(o,h)),l++}if(0===l)continue;const h=a<c?s.startNodeId:s.endNodeId;e.push({laneId:n,nodeId:h,pos:i.nodes.get(h).position})}for(let n=0;n<e.length;n++)for(let s=0;s<e.length;s++){if(n===s)continue;const r=e[n],o=e[s],a=__(r.pos,o.pos);i.addEdge({fromNode:r.nodeId,toNode:o.nodeId,resource:t.id,distance:a,durationMs:t.crossingTimeMs,forward:!0})}}return i}function x_(t,e,n,i={}){const s=t.nodes.get(e),r=t.nodes.get(n);if(!s||!r)return null;const o=i.speed?.max??100,a=e=>{const n=t.nodes.get(e);var i,s;return(i=n.position,s=r.position,Math.sqrt(function(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}(i,s)))/o*1e3},c=new Map,l=new Set,h=new Set,d={nodeId:e,gScore:0,fScore:a(e)};c.set(e,d),l.add(e);const u=i.startSimMs??0,p=i.deadlineSimMs;for(;l.size>0;){let e=null,i=null;for(const t of l){const n=c.get(t);(!i||n.fScore<i.fScore||n.fScore===i.fScore&&t<e)&&(i=n,e=t)}if(!i||!e)return null;if(e===n){const t=[];let e=i,n=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,s=u+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:s,endSimMs:s+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),n+=i.distance,e=c.get(i.fromNodeId)}const s=i.gScore;return void 0!==p&&u+s>p?null:{segments:t,totalDurationMs:s,totalDistance:n}}l.delete(e),h.add(e);for(const n of t.edgesFrom(e)){if(h.has(n.toNode))continue;const e=i.gScore+n.durationMs,s=c.get(n.toNode);if(!s||e<s.gScore){const i=t.nodes.get(n.fromNode),s=t.nodes.get(n.toNode),r={nodeId:n.toNode,gScore:e,fScore:e+a(n.toNode),cameFromEdge:{fromNodeId:n.fromNode,resource:n.resource,distance:n.distance,durationMs:n.durationMs,fromPos:i.position,toPos:s.position}};c.set(n.toNode,r),l.add(n.toNode)}}}return null}function w_(t,e,n=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:n,metadata:i}))}const M_={closed:!0,round:0,divisions:24};class S_{constructor(t,e){this.points=t,this.closed=e;const n=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,s=t[e].y-t[e-1].y;n.push(n[e-1]+Math.sqrt(i*i+s*s))}this.cumulative=n,this.length=n[n.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let n=t;this.closed?n=(t%e+e)%e:n<0?n=0:n>e&&(n=e);const i=this.cumulative;let s=0,r=i.length-2;for(;s<r;){const t=s+r>>1;i[t+1]<=n?s=t+1:r=t}const o=i[s+1]-i[s],a=o>0?(n-i[s])/o:0,c=this.points[s],l=this.points[s+1],h=l.x-c.x,d=l.y-c.y;return{x:c.x+h*a,y:c.y+d*a,theta:0===h&&0===d?0:Math.atan2(d,h)}}}function k_(t,e={}){const n={...M_,...e},i=t.length;if(0===i)return new S_([],n.closed);if(1===i)return new S_([{x:t[0].x,y:t[0].y}],n.closed);const s=[],r=(t,e)=>{if(s.length>0){const n=s[s.length-1];if(Math.abs(n.x-t)<1e-9&&Math.abs(n.y-e)<1e-9)return}s.push({x:t,y:e})},o=(n.closed,i);for(let e=0;e<o;e++){const s=0===e?n.closed?i-1:-1:e-1,o=e===i-1?n.closed?0:-1:e+1,a=s>=0?t[s]:null,c=t[e],l=o>=0?t[o]:null;if(a&&a.x===c.x&&a.y===c.y)continue;const h=a&&l?to(c,n.round):0;let d,u,p,f;if(a){const t=Math.sqrt((a.x-c.x)**2+(a.y-c.y)**2),e=0!==t?Math.atan2(a.x-c.x,a.y-c.y):0,n=Math.min(h,t/2);d=Math.sin(e)*n+c.x,u=Math.cos(e)*n+c.y}else d=c.x,u=c.y;if(l){const t=Math.sqrt((l.x-c.x)**2+(l.y-c.y)**2),e=0!==t?Math.atan2(l.x-c.x,l.y-c.y):0,n=Math.min(h,t/2);p=Math.sin(e)*n+c.x,f=Math.cos(e)*n+c.y}else p=c.x,f=c.y;if(r(d,u),h>0&&a&&l)for(let t=1;t<=n.divisions;t++){const e=t/n.divisions,i=1-e;r(i*i*d+2*i*e*c.x+e*e*p,i*i*u+2*i*e*c.y+e*e*f)}else d===p&&u===f||r(p,f);if(l&&Kr(c)){const t=to(l,n.round),e=Math.sqrt((c.x-l.x)**2+(c.y-l.y)**2),i=0!==e?Math.atan2(c.x-l.x,c.y-l.y):0,s=Math.min(t,e/2),o=Qr({x:p,y:f},{x:Math.sin(i)*s+l.x,y:Math.cos(i)*s+l.y},c.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=n.divisions;e++){const i=e/n.divisions,s=o.startAngle+t*i;r(o.cx+o.radius*Math.cos(s),o.cy+o.radius*Math.sin(s))}}}}if(n.closed&&s.length>0){const t=s[0],e=s[s.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&s.push({x:t.x,y:t.y})}return new S_(s,n.closed)}function A_(t,e){return k_(t,e).length}function E_(t){return t?/forklift|agv|amr|oht|tugger|worker/i.test(t)?"mobile":/conveyor|sorter|induct|chute|belt/i.test(t)?"flow":/rack|shelf|stocker|cell/i.test(t)?"cell":/pallet|box|parcel|crate|drum|tray/i.test(t)?"atomic":/robot[-_]?arm|crane|lift/i.test(t)?"articulated":/spawn[-_]?point|sink[-_]?point/i.test(t)?"boundary":"":""}function C_(t){const e=[];let n=t.parent;for(;n&&!n.isRootModel?.();){const t=n.state?.id??n.constructor?.name;t&&e.unshift(t),n=n.parent}return e.join(" › ")}function T_(t,e=!0){const n=t.constructor?.name??t.state?.type??"Component",i={type:n,id:t.state?.id??`?${t._id??Math.random().toString(36).slice(2,7)}`,category:E_(n),parentId:t.parent?.state?.id,parentPath:C_(t)},s=t._realObject?.object3d;if(s){s.updateWorldMatrix?.(!0,!1);const t=s.matrixWorld?.elements;t&&(i.pose={position:{x:t[12],y:t[13],z:t[14]},rotation:{x:0,y:0,z:0,w:1}})}if(!0===t.isItem&&(i.isItem=!0),!0===t.isMover&&(i.isMover=!0),"function"!=typeof t.canReceive&&"function"!=typeof t.canAccept||(i.isHolder=!0),"function"==typeof t.pickupFrames)try{i.isPickable=t.pickupFrames().length>0}catch{i.isPickable=!1}if("string"==typeof t.toolType||"function"==typeof t.toolType?i.toolType="function"==typeof t.toolType?t.toolType():t.toolType:void 0!==t.toolType&&(i.toolType=String(t.toolType)),t.state&&"object"==typeof t.state){const e={};for(const[n,i]of Object.entries(t.state))"string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i&&null!==i||(e[n]=i);i.state=e}if(e){const e=t.components??[];i.childIds=e.map(t=>t.state?.id).filter(Boolean)}return i}function P_(t){function e(t,n){if(!t)return;n.push(T_(t));const i=t.components??[];for(const t of i)e(t,n)}function n(t,e){if(!e)return null;if(e.state?.id===t)return e;const i=e.components??[];for(const e of i){const i=n(t,e);if(i)return i}return null}return{version:"0.1.0",collectComponents(){const n=[];return e(t?.rootModel??t,n),n},getComponent(e){const i=n(e,t?.rootModel??t);if(!i)return null;const s={...T_(i)};if("function"==typeof i.pickupFrames)try{s.pickupFrames=i.pickupFrames()}catch{}if("object"==typeof i.slots)try{s.slots=Array.isArray(i.slots)?i.slots:"function"==typeof i.slots?i.slots():[]}catch{}if("function"==typeof i.acceptanceRotation)try{s.acceptanceWorldQuat=i.deliveryWorldRotation?.(null)??void 0}catch{}if("function"==typeof i.deliveryWorldPosition)try{s.deliveryWorldPosition=i.deliveryWorldPosition(null)}catch{}return s},simStatus(){let e=0;const n=[t?.rootModel??t];for(;n.length>0;){const t=n.pop();if(!t)continue;!0===t.isItem&&e++;const i=t.components??[];for(const t of i)n.push(t)}return{simTime:Ir.now,realTime:"undefined"!=typeof performance?performance.now():Date.now(),speed:Ir.speed,paused:Ir.isPaused,carrierCount:e}},transferLog(){const t={};Nu.flows().forEach((e,n)=>{t[n]=e});const e={};Nu.targetCounts().forEach((t,n)=>{e[n]=t});const n={};return Nu.rejectReasonCounts().forEach((t,e)=>{n[e]=t}),{entries:Nu.toJSON(),stats:Nu.stats(),flows:t,targetCounts:e,rejectReasonCounts:n}},reservations(){const t=[...g_.all()],e={},n={};for(const i of t)(e[i.resource]??=[]).push(i),(n[i.reserverId]??=[]).push(i);for(const t of Object.values(e))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);for(const t of Object.values(n))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);return{simTime:Ir.now,all:t,byResource:e,byReserver:n}},conflicts(){const t=g_.conflictLog(),e={},n={};let i=0,s=0;for(const r of t)e[r.resource]=(e[r.resource]??0)+1,n[r.proposed.reserverId]=(n[r.proposed.reserverId]??0)+1,"rejected"===r.outcome?i++:s++;return{simTime:Ir.now,log:[...t],total:t.length,rejected:i,preempted:s,byResource:e,byReserver:n}}}}function O_(t){const e=P_(t);return"undefined"!=typeof window&&(window.__SCENE_INSPECTOR__=e),e}let D_=0;const z_=new FinalizationRegistry(()=>{D_--});class I_{static get residents(){return D_}static get residentsCount(){return D_}constructor(t,e){this.counters={},this.references={},this.creator=t,this.disposer=e,D_++,z_.register(this,D_)}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,ts("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,i)=>{const s=this.references[t];if(s)s===e?i(Error("Reference ID and target duplicate")):e?i(Error("Reference ID duplicate")):n(s);else{const s=e=>{e.release=()=>{this.release(e)},this.references[t]=e,this.counters[t]=1,n(e)};if(e)s(e);else{if(!this.creator)return void i(Error("Reference id("+t+") is not allowed. Reference creator should be defined."));this.creator(t,s,i)}}});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 Zi("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,ts("RELEASED",e)))}}const R_={},j_={};let L_=[];function F_(t){const e=t.target,n="SCRIPT"===e.tagName?R_:j_,i=e.src||e.href;n[i]=!0,L_.forEach((t,e)=>{if(!t)return;const{resolve:s,scripts:r,styles:o}=t;if(n===R_){const t=r.indexOf(i);t>-1&&t<r.length-1&&H_(r[t+1])}r.some(t=>!R_[t])||o?.some(t=>!j_[t])||(s(),L_[e]=null)}),L_=L_.filter(Boolean)}function N_(t){if("string"==typeof t)return;const e=t.target,n=e.src,i="SCRIPT"===e.tagName?R_:j_;L_.forEach((e,s)=>{if(!e)return;const{reject:r,scripts:o,styles:a}=e;(i===R_&&o.includes(n)||i===j_&&!!a?.includes(n))&&(r(t),L_[s]=null)}),L_=L_.filter(Boolean),delete i[n],document.head.removeChild(e)}function H_(t){R_[t]=!1;const e=document.createElement("script");e.onload=F_,e.onerror=N_,e.type="text/javascript",e.src=t,document.head.appendChild(e)}class B_{static load(t,e){const n="string"==typeof t?[t]:t,i="string"==typeof e?[e]:e;return new Promise(function(t,e){if(n&&!Array.isArray(n)||i&&!Array.isArray(i))return void e(new Error("invalid sources for load"));let s,r=!0;if(i?.forEach(t=>{t in j_||function(t){j_[t]=!1;const e=document.createElement("link");e.onload=F_,e.onerror=N_,e.type="text/css",e.rel="stylesheet",e.media="screen,print",e.href=t,document.head.appendChild(e)}(t),j_[t]||(r=!1)}),n&&n.length>0)for(const t of n)t in R_?R_[t]||(r=!1):s??=t;if(s)H_(s);else if(r)return void t();L_.push({resolve:t,reject:e,scripts:n,styles:i})})}}const G_="0.0.0";function V_(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 Y_(t){const{lineWidth:n=0}=t.state;let{width:i,height:s}=t.bounds;i+=n,s+=n;const r=V_(2*i),o=V_(2*s),a=Dp(r,o),c=new e.CanvasTexture(a);return W_(a,t,2),c.needsUpdate=!0,c.wrapS=e.RepeatWrapping,c.wrapT=e.RepeatWrapping,c.offset.set(0,1-2*s/o),c.repeat.set(2*i/r,2*s/o),c.magFilter=e.NearestFilter,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace,c}function W_(t,e,n){const{lineWidth:i=0}=e.state;let{left:s,top:r}=e.bounds;s-=i/2,r-=i/2;const o=t.getContext("2d");o.scale(n,n),o.translate(-s,-r),e.render(o),e.postrender(o)}function U_(t,e,n=2){const i=t.getContext("2d");i&&(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,t.width,t.height),W_(t,e,n))}const $_=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class X_ extends pu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds;if(!t||!n)return;const i=Md(this.component.state.material3d),s=new e.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=Y_(this.component),o=new e.MeshStandardMaterial({map:r});Ad(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateDimension(){const{width:t,height:e}=this.component.bounds;this.setDimensionScale(t,1,e)}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this._rebuildTexture()},100)}_rebuildTexture(){this.clear(),this.build(),this.updateTransform(),this.updateDimension(),this.updateHidden()}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(U_(n,this.component,2),e.needsUpdate=!0)}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!$_.has(e)){this._debouncedRebuild();break}}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Md(this.component.state.material3d);Ad(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),eu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const q_=new Map;function K_(t){return Math.round(1e3*t)/1e3}function Q_(t){return new e.Color(t).getHexString()}const Z_={material(t,n,i){const s=t+"::"+function(t){const e=[];return null!=t.color&&e.push("c"+Q_(t.color)),null!=t.metalness&&e.push("m"+K_(t.metalness)),null!=t.roughness&&e.push("r"+K_(t.roughness)),null!=t.opacity&&e.push("o"+K_(t.opacity)),null!=t.emissive&&e.push("E"+Q_(t.emissive)),null!=t.emissiveIntensity&&e.push("I"+K_(t.emissiveIntensity)),null!=t.envMapIntensity&&e.push("e"+K_(t.envMapIntensity)),null!=t.side&&e.push("s"+t.side),t.transparent&&e.push("t"),t.flatShading&&e.push("f"),!1===t.depthWrite&&e.push("dw0"),t.map&&e.push("M"+(t.map.uuid??"")),e.join("|")}(n);let r=q_.get(s);return r||q_.set(s,r=function(t){const n=new e.MeshStandardMaterial;return n.userData.__bankOwned=!0,null!=t.color&&n.color.set(t.color),null!=t.emissive&&n.emissive.set(t.emissive),null!=t.metalness&&(n.metalness=t.metalness),null!=t.roughness&&(n.roughness=t.roughness),null!=t.emissiveIntensity&&(n.emissiveIntensity=t.emissiveIntensity),null!=t.envMapIntensity&&(n.envMapIntensity=t.envMapIntensity),null!=t.side&&(n.side=t.side),null!=t.map&&(n.map=t.map),null!=t.flatShading&&(n.flatShading=t.flatShading),null!=t.depthWrite&&(n.depthWrite=t.depthWrite),null!=t.opacity&&(n.opacity=t.opacity),null!=t.transparent?n.transparent=t.transparent:null!=t.opacity&&t.opacity<1&&(n.transparent=!0),n}(n)),null==i?r:Gd(r,{color:i})},get size(){return q_.size},has(t){const e=t+"::";for(const t of q_.keys())if(t.startsWith(e))return!0;return!1},dispose(){for(const t of q_.values())Yd(t),t.dispose();q_.clear()}};class J_ extends pu{getObject3dInstance(){return new e.Mesh}build(){super.build(),this.buildGeometry(),this.buildMaterial(),this.updateDimension()}updateAlpha(){if(this.canShareMaterial)return void super.updateAlpha();const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}updateFillStyle(){if(this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const{fillStyle:t,alpha:e=1}=this.component.state,n=this.object3d.material;if(!n)return;const i=pu.buildFillStyleTexture(this.component);i?(n.map&&n.map.dispose(),i.needsUpdate=!0,n.map=i,n.needsUpdate=!0):"string"==typeof t&&(n.map&&(n.map.dispose(),n.map=null,n.needsUpdate=!0),"transparent"!==t&&"none"!==t&&n.color.set(Xd(t))),$d(n,0,t)}updateStrokeStyle(){const t=this.object3d.getObjectByName("__edgeLines__");t&&(this.object3d.remove(t),eu(t));const{strokeStyle:n}=this.component.state;if(!n||"transparent"===n||"none"===n)return;const i=this.object3d.geometry;if(!i?.getAttribute("position"))return;const s=new e.EdgesGeometry(i),r=new e.LineBasicMaterial({color:n}),o=new e.LineSegments(s,r);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 i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}get canShareMaterial(){return void 0===this.materialSharingIssue}get materialSharingIssue(){const{fillStyle:t}=this.component.state;if(!t||"object"!=typeof t)return;const e=t.type;return"pattern"===e?"무늬(pattern) fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":"gradient"===e?"그라디언트 fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":`fillStyle 이 색 문자열이 아니다 (type: ${String(e)})`}get requiresSharedMaterial(){return!0===this.component.constructor.requiresSharedMaterial}get materialSharing(){const t=this.materialSharingIssue,e=void 0===t,n=this.requiresSharedMaterial,i={shared:e,required:n,violated:n&&!e};return void 0!==t&&(i.reason=t),e&&(i.bankKey=this.materialBankKey),i}get materialBankKey(){return`mesh|${this.component.state.type??"unknown"}`}materialSpec(){const t=Md(this.component.state.material3d),e=Ud(this.component.state.fillStyle);return{metalness:t.metalness,roughness:t.roughness,emissive:t.emissive,emissiveIntensity:t.emissiveIntensity,envMapIntensity:t.envMapIntensity,side:kd(t.side),flatShading:t.flatShading,opacity:e,transparent:e<1}}buildMaterial(){if(!this.canShareMaterial){const t=Md(this.component.state.material3d),n=new e.MeshStandardMaterial({transparent:!0});return Ad(n,t),void(this.object3d.material=n)}this.applyBankMaterial()}applyBankMaterial(){const{fillStyle:t}=this.component.state,e=Ud(t)>0&&"string"==typeof t?Xd(t):void 0;Vd(this.object3d),this.object3d.material=Z_.material(this.materialBankKey,this.materialSpec(),e)}updateMaterial3d(){if(super.updateMaterial3d(),this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const t=this.object3d.material;t&&Ad(t,Md(this.component.state.material3d))}clear(){return Vd(this.object3d),eu(this.object3d),super.clear()}}function tv(t,e,n,i){return[["bold",t],["italic",e],[n+"px",!0],[i,!0]].filter(t=>t[1]).map(t=>t[0]).join(" ")}function ev(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 nv(t,e,n){const{bold:i=!1,italic:s=!1,fontFamily:r="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",width:h=t.width,height:d=t.height,offsetX:u=0,offsetY:p=0}=n||{},f=t.getContext("2d");let m,g;f.imageSmoothingEnabled=!1,f.fillStyle=a,f.strokeStyle=a,f.font=tv(i,s,o,r),"left"===c||"start"===c?(f.textAlign="left",m=u):"right"===c||"end"===c?(f.textAlign="right",m=u+h):(f.textAlign="center",m=u+h/2);const y=1.2*o,b=String(e).split("\n"),_=y*b.length;g="top"===l||"hanging"===l?p+.1*o:"bottom"===l||"alphabetic"===l?p+d-_+.1*o:p+(d-_)/2+.1*o,f.textBaseline="top";for(const t of b)f.fillText(t,m,g),g+=y}function iv(t,n,i,s){const r=ev(2*n),o=ev(2*i),a=Dp(r,o),c=a.getContext("2d"),{fillStyle:l}=s||{};if(l&&"object"==typeof l&&l.colorStops?.length){const t=nu(l,2*n,2*i);t&&c.drawImage(t,0,0)}c.scale(2,2),"string"==typeof l&&""!==l&&"transparent"!==l&&(c.fillStyle=l,c.fillRect(0,0,n,i)),nv(a,t,s);const h=new e.CanvasTexture(a);return h.needsUpdate=!0,h.wrapS=e.RepeatWrapping,h.wrapT=e.RepeatWrapping,h.offset.set(0,1-2*i/o),h.repeat.set(2*n/r,2*i/o),h.minFilter=e.LinearFilter,h.colorSpace=e.SRGBColorSpace,h}function sv(t,n,i,s,r,o,a){const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const t=2*i,l=2*s,h=ev(t),d=ev(l),u=Dp(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),i=2*(o.offsetX||0),s=2*(o.offsetY||0);let r=0,a=0;switch(o.align){case"center":r=(t-e)/2,a=(l-n)/2;break;case"left-top":break;case"left-bottom":a=l-n;break;case"right-top":r=t-e;break;case"right-bottom":r=t-e,a=l-n;break;case"left":a=(l-n)/2;break;case"right":r=t-e,a=(l-n)/2;break;case"top":r=(t-e)/2;break;case"bottom":r=(t-e)/2,a=l-n}const h=i+r,d=s+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 i=h>0?h-Math.ceil(h/e)*e:h;for(let s=d>0?d-Math.ceil(d/n)*n:d;s<l;s+=n)for(let r=i;r<t;r+=e)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,r,s,e,n);p.restore()}}n&&(p.scale(2,2),nv(u,n,r));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=iv(n,i,s,r);a(t)},c.src=t}function rv(t,e){let{bold:n=!1,italic:i=!1,fontFamily:s="Serif",fontSize:r=10,lineHeight:o="normal"}=e||{};t=void 0===t||""==t?" ":String(t);const a=document.createElement("span");a.style.font=tv(n,i,r,s),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 ov extends J_{get zPriority(){return au.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){this.updateDimension()}updateStrokeStyle(){}updateFillStyle(){this.updateText()}updateDimension(){const{width:t,height:n}=this.component.state,i=Math.abs(t)||1,s=Math.abs(n)||1;this.object3d.geometry&&this.object3d.geometry.dispose();const r=new e.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateText(){const t=this.object3d.material;if(!t)return;const{width:e,height:n,bold:i=!1,italic:s=!1,fontFamily:r="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",m={bold:i,italic:s,fontFamily:r,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 sv(this.component.app.url(h.image),p,d,u,m,h,e=>{t.map&&t.map.dispose(),t.map=e,t.color.set(16777215),t.needsUpdate=!0})}const g=iv(p,d,u,m);g?(t.map&&t.map.dispose(),t.map=g,t.color.set(16777215),g.needsUpdate=!0):"string"==typeof h&&(""!==h&&"transparent"!==h?t.color.set(Xd(h)):t.opacity=0)}updateAlpha(){const t=this.object3d.material;t.opacity=1,t.transparent=!0,super.applyMaterialOpacity()}}Gp("text",t=>new ov(t));const av={input:"css3d",select:"css3d",textarea:"css3d",button:"css3d",iframe:"css3d",video:"css3d",label:"texture",table:"texture",progress:"texture"};function cv(t){const e=t.model?.type??"";return"texture"===(av[e]??"css3d")?new X_(t):new Np(t)}Gp("html-overlay-element",cv),Gp("html-overlay-container",cv);class lv{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,i,s,r){const o=n[3*i],a=n[3*i+1],c=n[3*s],l=n[3*s+1],h=n[3*r],d=n[3*r+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,i,s,r,o){const a=n[3*i],c=n[3*i+1],l=n[3*i+2],h=n[3*s],d=n[3*s+1],u=n[3*s+2],p=n[3*r],f=n[3*r+1],m=n[3*r+2],g=n[3*o],y=n[3*o+1],b=n[3*o+2],_=this.extrudedOptions?.depth||100,v=this.bb,x=v.max.x-v.min.x,w=v.max.y-v.min.y;return Math.abs(c-d)<.01?[new e.Vector2(a/x,1-l/_),new e.Vector2(h/x,1-u/_),new e.Vector2(p/x,1-m/_),new e.Vector2(g/x,1-b/_)]:[new e.Vector2(c/w,1-l/_),new e.Vector2(d/w,1-u/_),new e.Vector2(f/w,1-m/_),new e.Vector2(y/w,1-b/_)]}}function hv(t,e){const n=t/2,i=e/2;return{points:[{x:-n,y:-i},{x:n,y:-i},{x:n,y:i},{x:-n,y:i}]}}function dv(t,e,n){const i=Math.max(3,Math.floor(n)),s=[];for(let n=0;n<i;n++){const r=n/i*Math.PI*2;s.push({x:t*Math.cos(r),y:e*Math.sin(r)})}return{points:s,segments:i}}function uv(t){if(0===t.length)return[];let e=1/0,n=1/0,i=-1/0,s=-1/0;for(const r of t)r.x<e&&(e=r.x),r.x>i&&(i=r.x),r.y<n&&(n=r.y),r.y>s&&(s=r.y);const r=(e+i)/2,o=(n+s)/2,a=t.map(t=>({x:t.x-r,y:t.y-o})),c=a[0],l=a[a.length-1];return a.length>1&&Math.abs(c.x-l.x)<1e-9&&Math.abs(c.y-l.y)<1e-9&&a.pop(),a}class pv extends pu{clear(){return this._mesh=void 0,super.clear()}get shape(){return null}topOutline(){const t=this.shape;if(!t||"function"!=typeof t.getPoints)return null;const e=this.outlineDivisions,n=t.getPoints(e);if(!n||n.length<3)return null;const i=uv(n);return i.length<3?null:{points:i}}get outlineDivisions(){return 12}get boundUVGenerator(){return this._boundUVGenerator||(this._boundUVGenerator=new lv),this._boundUVGenerator}build(){super.build();const t=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator;i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:t}});const s=this.createGeometry(n),r=this.createMaterials();this._mesh=new e.Mesh(s,r),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:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new e.ExtrudeGeometry(t,s);return r.center(),r}createMaterials(){const t=Md(this.component.state.material3d),n=new e.MeshStandardMaterial;Ad(n,t);const i=new e.MeshStandardMaterial;return Ad(i,t),[n,i]}createTexture(){const{width:t,height:n}=this.component.bounds,i=ev(t),s=ev(n),r=Dp(i,s);this.component.render(r.getContext("2d"));const o=new e.CanvasTexture(r);return o.needsUpdate=!0,o.wrapS=e.RepeatWrapping,o.wrapT=e.RepeatWrapping,o.offset.set(0,1-n/s),o.repeat.set(t/i,n/s),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=Md(this.component.state.material3d);for(const n of t)Ad(n,e)}updateAlpha(){const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this.getMaterials();i&&($d(i[0],0,e),$d(i[1],0,n))}updateStrokeStyle(){const t=this.getMaterials();if(!t)return;const{strokeStyle:e}=this.component.state;t[1].color.set(Xd(e))}updateFillStyle(){this._applyCapTexture()}updateText(){this._applyCapTexture()}_applyCapTexture(){const t=this.getMaterials();if(!t)return;const e=t[0],{fillStyle:n}=this.component.state,i=this.component.hasTextProperty?this.component.text:"";if(!i){const t=pu.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(Xd(n))),void(e.needsUpdate=!0)}const{bold:s=!1,italic:r=!1,fontFamily:o="Serif",fontSize:a=10,fontColor:c="black",textAlign:l="center",textBaseline:h="middle",paddingTop:d=0,paddingLeft:u=0,paddingRight:p=0,paddingBottom:f=0}=this.component.state,{width:m,height:g}=this.component.bounds,y=Math.abs(m)||1,b=Math.abs(g)||1,_={bold:s,italic:r,fontFamily:o,fontSize:a,fontColor:c,textAlign:l,textBaseline:h,width:Math.max(y-u-p,0),height:Math.max(b-d-f,0),fillStyle:n,offsetX:u,offsetY:d};if("object"==typeof n&&"pattern"===n?.type&&n.image){return void sv(this.component.app.url(n.image),i,y,b,_,n,t=>{e.map&&e.map.dispose(),e.map=t,e.color.set(16777215),e.needsUpdate=!0})}e.map&&e.map.dispose();const v=iv(i,y,b,_);e.map=v,e.color.set(16777215),e.needsUpdate=!0}updateDimension(){super.updateDimension()}onchange(t,e){if("path"in t&&this._mesh){const t=this._mesh.geometry,e=this.shape;if(e){const n=this.createGeometry(e);this._mesh.geometry=n,t.dispose()}}super.onchange(t,e)}}class fv extends pv{get shape(){const{cx:t=0,cy:n=0,rx:i=1,ry:s=1,startAngle:r=0,endAngle:o=2*Math.PI,anticlockwise:a=!1}=this.component.state,c=new e.EllipseCurve(t,n,Math.abs(i),Math.abs(s),r,o,a,0);return new e.Shape(c.getPoints(50))}}Gp("ellipse",t=>new fv(t));class mv extends pv{get shape(){const{width:t,height:n,round:i=0}=this.component.state,s=Oc(i,t,n);if(s>0){const i=s,r=new e.Path;return r.moveTo(i,0),r.lineTo(t-i,0),r.quadraticCurveTo(t,0,t,i),r.lineTo(t,n-i),r.quadraticCurveTo(t,n,t-i,n),r.lineTo(i,n),r.quadraticCurveTo(0,n,0,n-i),r.lineTo(0,i),r.quadraticCurveTo(0,0,i,0),new e.Shape(r.getPoints(12))}const r=new e.Shape;return r.moveTo(0,0),r.lineTo(t,0),r.lineTo(t,n),r.lineTo(0,n),r.lineTo(0,0),r}}function gv(t,n={}){const i=n.round??0,s=n.divisions??24;if(!t||0===t.length)return new e.Shape;const r=t.some(t=>Kr(t)),o=i>0||t.some(t=>to(t,0)>0);if(r||o){const n=new e.Path;for(let e=0;e<t.length;e++){const s=t[(e-1+t.length)%t.length],r=t[e],o=t[(e+1)%t.length];if(s.x===r.x&&s.y===r.y)continue;const a=to(r,i);let c=Math.sqrt((s.x-r.x)**2+(s.y-r.y)**2),l=0!==c?Math.atan2(s.x-r.x,s.y-r.y):0;const h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;c=Math.sqrt((o.x-r.x)**2+(o.y-r.y)**2),l=0!==c?Math.atan2(o.x-r.x,o.y-r.y):0;const u=Math.sin(l)*Math.min(a,c/2)+r.x,p=Math.cos(l)*Math.min(a,c/2)+r.y;if(0===e?n.moveTo(h,d):n.lineTo(h,d),a>0&&n.quadraticCurveTo(r.x,r.y,u,p),Kr(r)){const t=to(o,i),e=Math.sqrt((r.x-o.x)**2+(r.y-o.y)**2),s=0!==e?Math.atan2(r.x-o.x,r.y-o.y):0,a=Qr({x:u,y:p},{x:Math.sin(s)*Math.min(t,e/2)+o.x,y:Math.cos(s)*Math.min(t,e/2)+o.y},r.bulge);a&&n.absarc(a.cx,a.cy,a.radius,a.startAngle,a.endAngle,a.clockwise)}}return new e.Shape(n.getPoints(s))}const a=new e.Shape;for(let e=0;e<t.length;e++)0===e?a.moveTo(t[e].x,t[e].y):a.lineTo(t[e].x,t[e].y);return a}Gp("rect",t=>new mv(t));class yv extends pv{get shape(){const{path:t=[],round:e=0}=this.component.state;return gv(t,{round:e,divisions:24})}build(){Object.getPrototypeOf(pv.prototype).build.call(this);const t=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator,s=this.minMax;if(i&&void 0!==s.minX&&void 0!==s.maxX&&void 0!==s.minY&&void 0!==s.maxY){const n=new e.Shape;n.moveTo(s.minX,s.minY),n.lineTo(s.maxX,s.minY),n.lineTo(s.maxX,s.maxY),n.lineTo(s.minX,s.maxY),n.closePath(),i.setShape({extrudedShape:n,extrudedOptions:{depth:t}})}else i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:t}});const r=this.createGeometry(n),o=this.createMaterials();this._mesh=new e.Mesh(r,o),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:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new e.ExtrudeGeometry(t,s),o=this.minMax;if(void 0!==o.minX&&void 0!==o.maxX&&void 0!==o.minY&&void 0!==o.maxY){const t=(o.minX+o.maxX)/2,e=(o.minY+o.maxY)/2;r.translate(-t,-e,0),r.computeBoundingBox();const n=r.boundingBox;n&&r.translate(0,0,-(n.min.z+n.max.z)/2)}else r.center();return r}get minMax(){if(!this._minMax){const{path:t}=this.component.state;let e,n,i,s;t.forEach((t,r)=>{if(0==r)return e=i=t.x,void(n=s=t.y);e=Math.min(e,t.x),i=Math.max(i,t.x),n=Math.min(n,t.y),s=Math.max(s,t.y)}),this._minMax={minX:e,minY:n,maxX:i,maxY:s}}return this._minMax}}Gp("polygon",t=>new yv(t));class bv extends pv{get shape(){const{cx:t=0,cy:n=0,rx:i=1,ry:s=1,ratio:r=50,startAngle:o=0,endAngle:a=2*Math.PI,anticlockwise:c=!1}=this.component.state,l=Math.abs(i),h=Math.abs(s),d=new e.EllipseCurve(t,n,l,h,o,a,c,0),u=new e.Shape(d.getPoints(50)),p=l/100*r,f=h/100*r;if(p>0&&f>0){const i=new e.EllipseCurve(t,n,p,f,o,a,c,0),s=new e.Path(i.getPoints(50));u.holes.push(s)}return u}}Gp("donut",t=>new bv(t));class _v extends pv{get shape(){const{x1:t=0,y1:n=0,x2:i=0,y2:s=0,x3:r=0,y3:o=0,round:a=0}=this.component.state,c=[{x:t,y:n},{x:i,y:s},{x:r,y:o}];if(a>0){const t=new e.Path;for(let e=0;e<c.length;e++){const n=c[(e-1+c.length)%c.length],i=c[e],s=c[(e+1)%c.length];let r=Math.sqrt((n.x-i.x)**2+(n.y-i.y)**2),o=0!==r?Math.atan2(n.x-i.x,n.y-i.y):0;const l=Math.sin(o)*Math.min(a,r/2)+i.x,h=Math.cos(o)*Math.min(a,r/2)+i.y;r=Math.sqrt((s.x-i.x)**2+(s.y-i.y)**2),o=0!==r?Math.atan2(s.x-i.x,s.y-i.y):0;const d=Math.sin(o)*Math.min(a,r/2)+i.x,u=Math.cos(o)*Math.min(a,r/2)+i.y;0===e?t.moveTo(l,h):t.lineTo(l,h),t.quadraticCurveTo(i.x,i.y,d,u)}return new e.Shape(t.getPoints(12))}const l=new e.Shape;return l.moveTo(t,n),l.lineTo(i,s),l.lineTo(r,o),l.closePath(),l}}Gp("triangle",t=>new _v(t));class vv extends pv{get shape(){const{ratio:t=30,wing:n=5,cx:i=0,cy:s=0,rx:r=1,ry:o=1}=this.component.state;if(n<3)return null;const a=Math.PI/2,c=2*Math.PI/n,l=r-t/100*r,h=o-t/100*o,d=new e.Shape;d.moveTo(i+r*Math.cos(-a),s+o*Math.sin(-a)),d.lineTo(i+(r-l)*(Math.cos(c-a)+Math.cos(0-a))/2,s+(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let t=1;t<n;t++)d.lineTo(i+r*Math.cos(c*t-a),s+o*Math.sin(c*t-a)),d.lineTo(i+(r-l)*(Math.cos(c*(t+1)-a)+Math.cos(c*t-a))/2,s+(o-h)*(Math.sin(c*(t+1)-a)+Math.sin(c*t-a))/2);return d.closePath(),d}}Gp("star",t=>new vv(t));const xv=new Map;function wv(t){return t.userData.__bankOwned=!0,t}const Mv={primitive(t){const n="primitive::"+function(t){switch(t.kind){case"cylinder":return`cylinder|${t.segments??0}`;case"sphere":return`sphere|${t.segments??0}|${t.heightSegments??0}`;default:return t.kind}}(t);let i=xv.get(n);return i||xv.set(n,i=wv(function(t){switch(t.kind){case"box":return new e.BoxGeometry(1,1,1);case"plane":return new e.PlaneGeometry(1,1);case"cylinder":return new e.CylinderGeometry(.5,.5,1,t.segments??16);case"sphere":return new e.SphereGeometry(.5,t.segments??16,t.heightSegments??Math.max(2,Math.round((t.segments??16)/2)))}}(t))),i},shaped(t,e){const n="shaped::"+t;let i=xv.get(n);return i||xv.set(n,i=wv(e())),i},owns:t=>!0===t.userData?.__bankOwned,get size(){return xv.size},has:t=>xv.has("primitive::"+t)||xv.has("shaped::"+t),dispose(){for(const t of xv.values())t.dispose();xv.clear()}},Sv=[8,12,16],kv={cylinder:25,sphere:32},Av=3,Ev=128;function Cv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(Ev,Math.max(3,Math.floor(t))):e}function Tv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(Ev,Math.max(2,Math.floor(t))):Math.max(2,Math.round(e/2))}function Pv(t){return Sv.includes(t)}const Ov={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"},{type:"number",label:"height-segments",name:"heightSegments",property:"heightSegments"}],help:"scene/component/sphere"};class Dv extends J_{buildGeometry(){const t=this.component.state,e=Cv(t.segments,kv.sphere),n=Tv(t.heightSegments,e);this.object3d.geometry=Mv.primitive({kind:"sphere",segments:e,heightSegments:n})}updateDimension(){const{rx:t=0,ry:e=0,rz:n}=this.component.state,i=n??t;this.setDimensionScale(2*t,2*i,2*e)}get effectiveDepth(){const{rx:t=0,rz:e}=this.component.state,n=e??t;return Math.max(2*n,1)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return dv(t,e,Cv(this.component.state.segments,kv.sphere))}}let zv=class extends hg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Dv(this)}get nature(){return Ov}};zv=Nm([Sy("sphere")],zv);class Iv extends pu{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(),i=this.component.parent?._realObject;return t+n+e/2-(i?.geometricOffsetY??0)}get geometricOffsetY(){const{height:t=0}=this.component.bounds;return t/2}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=pu.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(Xd(t)):e.opacity=0)}}class Rv extends Iv{buildMaterial(){const t=this.object3d.material;t&&t.dispose(),this.object3d.material=new e.SpriteMaterial({map:Y_(this.component),alphaTest:.01,sizeAttenuation:!1})}get scale(){const{width:t,height:e}=this.component.bounds,n=this.threeContainer,{width:i=1,height:s=1}=n?.bounds??{},{scale:r=1}=this.component.state;return{x:r*t/i,y:r*e/s,z:r}}update(){this.build(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateAlpha(){this.update()}updateText(){this.update()}}const jv={mutable:!1,resizable:!0,rotatable:!0,properties:[]};let Lv=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Rv(this)}get nature(){return jv}};Lv=Nm([Sy("sprite")],Lv);const Fv={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cube"};class Nv extends J_{buildGeometry(){this.object3d.geometry=Mv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?hv(t,e):null}}let Hv=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Nv(this)}get nature(){return Fv}};Hv=Nm([Sy("cube")],Hv);const Bv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"}],help:"scene/component/cylinder"};class Gv extends J_{buildGeometry(){const t=Cv(this.component.state.segments,kv.cylinder);this.object3d.geometry=Mv.primitive({kind:"cylinder",segments:t})}updateDimension(){const{rx:t=0,ry:e=0,depth:n=1}=this.component.state;this.setDimensionScale(2*t,n,2*e)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return dv(t,e,Cv(this.component.state.segments,kv.cylinder))}}let Vv=class extends hg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Gv(this)}get nature(){return Bv}};Vv=Nm([Sy("cylinder")],Vv);const Yv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"color",label:"box-color",name:"boxColor",property:"boxColor"}],help:"scene/component/banner"};class Wv extends pu{get zPriority(){return au.DECAL}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 i=this.createTextureBoard(t,n);i.position.set(0,0,.5*e+1),this.object3d.add(i)}createCube(t,n,i){const{boxColor:s="#ccaa76"}=this.component.state,r=Md(this.component.state.material3d),o=new e.BoxGeometry(t,i,n),a=new e.MeshStandardMaterial({color:s,side:e.FrontSide});Ad(a,r);const c=new e.Mesh(o,a);return c.castShadow=r.castShadow,c.receiveShadow=r.receiveShadow,c}createTextureBoard(t,n){const i=Md(this.component.state.material3d),{fillStyle:s="#ccaa76"}=this.component.state,r=pu.buildFillStyleTexture(this.component),o=new e.MeshStandardMaterial(r?{map:r}:{color:s||"#ccaa76",side:e.FrontSide});Ad(o,i);const a=new e.PlaneGeometry(t,n,1,1),c=new e.Mesh(a,o);return c.castShadow=i.castShadow,c.receiveShadow=i.receiveShadow,c}updateMaterial3d(){super.updateMaterial3d();const t=Md(this.component.state.material3d);this.object3d.traverse(e=>{if(e.isMesh){const n=e.material;n&&Ad(n,t),e.castShadow=t.castShadow,e.receiveShadow=t.receiveShadow}})}updateFillStyle(){this.update()}onchange(t,e){super.onchange(t,e),"boxColor"in t&&this.update()}}let Uv=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Yv}buildRealObject(){return new Wv(this)}};var $v;Uv=Nm([Sy("banner")],Uv);const Xv={far:1e5,fov:80,near:1,zoom:1},qv={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 Kv extends pu{getObject3dInstance(){return new e.Mesh}updateCamera(){const{near:t=Xv.near,far:n=Xv.far,fov:i=Xv.fov,zoom:s=Xv.zoom,showHelper:r}=this.component.state;this.camera.far=n,this.camera.fov=i,this.camera.near=t,this.camera.zoom=s,r?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:i=0,fillStyle:s="lightgray"}=this.component.state;this.object3d.geometry=new e.BoxGeometry(t,i,n);const r=Md(this.component.state.material3d),o=new e.MeshStandardMaterial({color:s});Ad(o,r),this.object3d.material=o,this.object3d.castShadow=r.castShadow,this.object3d.receiveShadow=r.receiveShadow,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()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Md(this.component.state.material3d);Ad(t,e),this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}}let Qv=$v=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}static get image(){return $v._image||($v._image=new Image,$v._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=="),$v._image}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,$v.image,e,n,i,s)}buildRealObject(){return new Kv(this)}get nature(){return qv}};Qv=$v=Nm([Sy("camera")],Qv);const Zv={mutable:!1,resizable:!0,rotatable:!0,properties:[...wy],"value-property":"source",help:"scene/component/gltf-object"};let Jv=class extends(My(Dc(Pc))){get nature(){return Zv}};Jv=Nm([Sy("gltf-object")],Jv);const tx={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 ex extends pu{updatePointLight(){const{lightType:t="point",distance:n=0,intensity:i=10,decay:s=1,fillStyle:r="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(r),"point"==t&&(this.object3d.distance=n,this.object3d.decay=s),this.object3d.intensity=i,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 nx=class extends hg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new ex(this)}get anchors(){return[]}get nature(){return tx}};nx=Nm([Sy("light")],nx);const ix={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"}],help:"scene/component/wall"};class sx extends J_{buildGeometry(){this.object3d.geometry=Mv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?hv(t,e):null}}let rx=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new sx(this)}get nature(){return ix}};rx=Nm([Sy("wall")],rx);const ox={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"},{type:"checkbox",label:"hide-in-2d-view",name:"hideIn2DView"},{type:"checkbox",label:"hide-in-3d-view",name:"hideIn3DView"}],help:"scene/component/floor-plate"};class ax extends pu{get zPriority(){return au.FLOOR}get receivingSurfaceY(){return this.placementSurfaceY()}resolveShadow(){const t=this.component.state,e=t.material3d,{alpha:n=1,fillStyle:i}=t,s=n>=.9&&"none"!==i;return{receive:e?.receiveShadow??!0,cast:e?.castShadow??s}}updateHidden(){const t=this.component.state,e=!!this.component.app?.isViewMode;this.object3d.visible=!(t.hidden||e&&t.hideIn3DView)}clear(){return this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0),this._mesh=void 0,super.clear()}build(){super.build();const{width:t,height:n,depth:i=1}=this.component.state;if(!t||!n)return;const s=Math.abs(t),r=Math.abs(n),o=Math.max(i,.5),a=new e.BoxGeometry(s,o,r),c=this._buildTopMaterial(),l=this._buildSideMaterial(),h=[l,l,c,l,l,l];this._mesh=new e.Mesh(a,h),this._mesh.position.y=0;const{cast:d,receive:u}=this.resolveShadow();this._mesh.castShadow=d,this._mesh.receiveShadow=u,this.object3d.add(this._mesh)}_buildTopMaterial(){const{alpha:t=1,fillStyle:n}=this.component.state,i=Md(this.component.state.material3d),s=pu.buildFillStyleTexture(this.component);if(s){this._topTexture=s;const t=new e.MeshStandardMaterial({map:s,side:e.DoubleSide});return $d(t,0,n),t.depthWrite=t.opacity>=.9,Ad(t,i),t}const r="string"==typeof n&&"none"!==n?Xd(n):"#e0e0e0",o=new e.MeshStandardMaterial({color:r,side:e.DoubleSide});return $d(o,0,n),o.depthWrite=o.opacity>=.9,Ad(o,i),o}_buildSideMaterial(){const{strokeStyle:t,alpha:n=1}=this.component.state,i="string"==typeof t&&t?Xd(t):"#999999",s=Md(this.component.state.material3d),r=new e.MeshStandardMaterial({color:i});return Ad(r,s),r.side=e.DoubleSide,$d(r,0,t),r.depthWrite=r.opacity>=.9,r}updateAlpha(){if(!this._mesh)return;const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this._mesh.material;for(let t=0;t<i.length;t++){const s=i[t];$d(s,0,2===t?e:n),s.depthWrite=s.opacity>=.9}}updateFillStyle(){if(!this._mesh)return;this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0);const t=this._mesh.material;t[2].dispose(),t[2]=this._buildTopMaterial()}updateStrokeStyle(){if(!this._mesh)return;const t=this._mesh.material,e=this._buildSideMaterial();for(let n=0;n<t.length;n++)2!==n&&(t[n].dispose(),t[n]=e)}}let cx=class extends Kl{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new ax(this)}get nature(){return ox}get hidden(){return!!this.getState("hideIn2DView")||super.hidden}};cx.requires3d=!0,cx=Nm([Sy("floor-plate")],cx);function lx(t,n={}){const i=n.size??5,s=n.color??4500172,r=n.emissive??2245734,o=new e.SphereGeometry(i,16,12),a=new e.MeshStandardMaterial({color:s,emissive:r,emissiveIntensity:.15,metalness:.3,roughness:.4,transparent:!0,opacity:.35}),c=new e.Mesh(o,a);n.position&&c.position.set(n.position[0],n.position[1],n.position[2]),c.userData.alwaysRaycast=!0,c.scale.setScalar(1),c.visible=n.visible??!(!0===t.app?.isViewMode);const l=()=>{a.emissiveIntensity=.9,a.opacity=.95,c.scale.setScalar(1.35),t.invalidate?.()},h=()=>{a.emissiveIntensity=.15,a.opacity=.35,c.scale.setScalar(1),t.invalidate?.()};return t.on("mouseenter",l),t.on("mouseleave",h),c.userData.dispose=()=>{t.off("mouseenter",l),t.off("mouseleave",h)},c}class hx extends J_{get zPriority(){return au.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){const{width:t,height:n}=this.component.state,i=Math.abs(t)||1,s=Math.abs(n)||1,r=new e.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateDimension(){this.update()}build(){super.build();const{width:t,height:e}=this.component.state,n=Math.abs(t)||1,i=Math.abs(e)||1,s=Math.max(2,.04*Math.min(n,i));this.object3d.add(lx(this.component,{size:s,position:[n/2-s,s,-i/2+s]}))}}const dx={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/decal"};let ux=class extends(vy(Dc(Pc))){buildRealObject(){return new hx(this)}get nature(){return dx}};ux=Nm([Sy("decal")],ux);class px extends pu{getObject3dInstance(){return new e.Group}get allowedGizmoModes(){return this.component.isGroup?.()?["translate"]:null}}const fx="#dde2e8",mx="#9c9c9c",gx="#e8e8ec",yx=.35;function bx(t,n,i,s,r){if(!n.visible)return new e.MeshStandardMaterial({transparent:!0,opacity:0,depthWrite:!1});const o=n.alpha*i,a="wall"===s?fx:"floor"===s?mx:gx,c=new e.MeshStandardMaterial({metalness:0,roughness:"wall"===s?.6:.85,transparent:o<1,opacity:o,side:r?e.BackSide:e.DoubleSide});return function(t,e,n,i,s,r){if("string"==typeof n&&n&&"transparent"!==n)t.color.set(n);else{if(n&&"object"==typeof n){const i=!r,o=pu.buildFillStyleTexture(e,n,{mirror:i,rotation:s});if(o)return t.map&&t.map.dispose(),t.map=o,void t.color.set("#ffffff")}t.color.set(i)}}(c,t,n.fillStyle,a,n.rotation,n.mirror),c}class _x extends px{get zPriority(){return au.BACKDROP}get position(){if(this.component.state.fitToBoard){return{x:0,y:super.position.y,z:0}}return super.position}build(){super.build();const t=this.component.state;let n=t.width,i=t.height;if(t.fitToBoard){const t=this.component.rootModel,e=t?.state;e&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&(n=e.width,i=e.height)}const s=this.effectiveDepth||Math.min(n,i)||200,r=t.alpha??1,o=!1!==t.seeThrough,a={east:this._resolveFace("east",fx,!0,yx),west:this._resolveFace("west",fx,!0,yx),north:this._resolveFace("north",fx,!0,yx),south:this._resolveFace("south",fx,!0,yx),floor:this._resolveFace("floor",mx,!0,1),ceiling:this._resolveFace("ceiling",gx,!0,1)},c=[bx(this.component,a.east,r,"wall",o),bx(this.component,a.west,r,"wall",o),bx(this.component,a.ceiling,r,"ceiling",o),bx(this.component,a.floor,r,"floor",o),bx(this.component,a.south,r,"wall",o),bx(this.component,a.north,r,"wall",o)],l=new e.BoxGeometry(n,s,i),h=new e.Mesh(l,c);if(h.receiveShadow=!0,this.object3d.add(h),this.component.app?.isEditMode){const t=new e.LineBasicMaterial({color:4473941,transparent:!0,opacity:.7}),n=new e.LineSegments(new e.EdgesGeometry(l),t);this.object3d.add(n)}const d=Math.max(2,.04*Math.min(n,i,s));this.object3d.add(lx(this.component,{size:d,position:[n/2,s/2+d,-i/2]}))}_resolveFace(t,e,n,i){const s=this.component.state,r=s.faces?.[t]??{},o=r.visible,a=r.alpha,c=r.rotation,l=90===c||180===c||270===c?c:0;return{fillStyle:r.fillStyle??e,visible:"boolean"==typeof o?o:n,alpha:"number"==typeof a&&Number.isFinite(a)?a:i,rotation:l,mirror:!0===r.mirror}}updateDimension(){}onchange(t,e){["alpha","width","height","depth","fitToBoard","faces","seeThrough"].some(e=>e in t)?this.update():super.onchange(t,e)}updateAlpha(){}}const vx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"checkbox",label:"fit-to-board",name:"fitToBoard"},{type:"checkbox",label:"see-through",name:"seeThrough"},{type:"backdrop-faces",label:"",name:"faces"}],help:"scene/component/backdrop"};let xx=class extends(vy(Dc(Pc))){buildRealObject(){return new _x(this)}get nature(){return vx}added(t){super.added?.(t),this.state.fitToBoard&&(this._syncFromRoot(!0),this._attachRootListener())}async ready(){await super.ready(),this.state.fitToBoard&&this._syncFromRoot(!1)}removed(t){this._detachRootListener(),super.removed?.(t)}dispose(){this._detachRootListener(),super.dispose?.()}onchange(t,e){"fitToBoard"in t&&(t.fitToBoard?(this._syncFromRoot(!0),this._attachRootListener()):this._detachRootListener()),super.onchange?.(t,e)}_syncFromRoot(t=!1){const e=this.rootModel;if(!e||e===this)return;const n=e.state;if(!n)return;const i={},s=Number.isFinite(n.width)?n.width:this.state.width,r=Number.isFinite(n.height)?n.height:this.state.height;s!==this.state.width&&(i.width=s),r!==this.state.height&&(i.height=r);const o=Number.isFinite(n.left)?n.left:0,a=Number.isFinite(n.top)?n.top:0;if(o!==this.state.left&&(i.left=o),a!==this.state.top&&(i.top=a),t){const t=this.state.depth;if(!("number"==typeof t&&Number.isFinite(t)&&t>0)){const e=Math.min(s,r);e!==t&&(i.depth=e)}}Object.keys(i).length>0&&this.set(i)}_attachRootListener(){if(this._onRootChange)return;const t=this.rootModel;t&&t!==this&&(this._onRootChange=t=>{("width"in t||"height"in t||"left"in t||"top"in t)&&this._syncFromRoot()},t.on?.("change",this._onRootChange))}_detachRootListener(){if(!this._onRootChange)return;const t=this.rootModel;t?.off?.("change",this._onRootChange),this._onRootChange=void 0}};function wx(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Mx(t,n,i,s){const r=[];for(let o=1;o<=s;o++){const a=o/s,c=1-a;r.push(new e.Vector3(c*c*t.x+2*c*a*n.x+a*a*i.x,c*c*t.y+2*c*a*n.y+a*a*i.y,c*c*t.z+2*c*a*n.z+a*a*i.z))}return r}xx=Nm([Sy("backdrop")],xx);class Sx extends pu{getObject3dInstance(){return new e.Group}get gizmoTransformable(){return!0}get syncZPosOffset(){return 0}get geometricOffsetY(){return 0}syncFromObject3D(){}applyDimensionFromGizmo(t){}build(){super.build(),this._buildLine()}get smoothedPath(){const t=this.worldPath;if(t.length<2)return t;const{round:n=0}=this.component.state;if(n<=0||t.length<3)return t;const i=[];i.push(t[0]);for(let s=1;s<t.length;s++){const r=t[s-1],o=t[s],a=t[s+1];if(!a){i.push(o);break}const c=r.x-o.x,l=r.y-o.y,h=r.z-o.z,d=Math.sqrt(c*c+l*l+h*h),u=Math.min(n,d/2),p=a.x-o.x,f=a.y-o.y,m=a.z-o.z,g=Math.sqrt(p*p+f*f+m*m),y=Math.min(n,g/2),b=d>0?new e.Vector3(o.x+c/d*u,o.y+l/d*u,o.z+h/d*u):o.clone(),_=g>0?new e.Vector3(o.x+p/g*y,o.y+f/g*y,o.z+m/g*y):o.clone();i.push(b),i.push(...Mx(b,o,_,8))}return i}_buildLine(){const t=this.smoothedPath;if(t.length<2)return;const{strokeStyle:n,lineWidth:i=2,alpha:s=1,lineDash:r,begin:o="none",beginSize:a="size5",end:c="none",endSize:l="size5"}=this.component.state,h=Math.max(i,1),d="string"==typeof n&&"transparent"!==n?Xd(n):"#000000",u=new e.Color(d),p=this._getResolution(),f=o,m=c,g=wx(f,h),y=wx(m,h),b=t[0],_=t[t.length-1],v=(new e.Vector3).subVectors(t[1],b).normalize(),x=(new e.Vector3).subVectors(t[t.length-2],_).normalize(),k=[...t];g>0&&(k[0]=b.clone().add(v.clone().multiplyScalar(g))),y>0&&(k[k.length-1]=_.clone().add(x.clone().multiplyScalar(y)));const A=new S;A.setPositions(k.flatMap(t=>[t.x,t.y,t.z]));const E=function(t,e){switch(t){case"round-dot":return{dashSize:e,gapSize:e};case"square-dot":return{dashSize:2*e,gapSize:e};case"dash":return{dashSize:4*e,gapSize:1.5*e};case"dash-dot":return{dashSize:4*e,gapSize:2*e};case"long-dash":return{dashSize:6*e,gapSize:3*e};case"long-dash-dot":return{dashSize:6*e,gapSize:2*e};case"long-dash-dot-dot":return{dashSize:6*e,gapSize:e};default:return null}}(r,h),C=new M({color:u.getHex(),linewidth:h,worldUnits:!0,transparent:s<1,opacity:s,resolution:p,dashed:!!E,dashSize:E?.dashSize??1,gapSize:E?.gapSize??1,dashScale:1});if(this._line2=new w(A,C),this._line2.computeLineDistances(),this.object3d.add(this._line2),"none"!==f){const t=Rp(f,Ip(a,h));if(t){const n=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),v.clone().negate());this._placeTip(t,b,n,u,s,p)}}if("none"!==m){const t=Rp(m,Ip(l,h));if(t){const n=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),x.clone().negate());this._placeTip(t,_,n,u,s,p)}}}_placeTip(t,e,n,i,s,r){const o=t.mesh||t.line2||t.group;if(o){if(o.position.copy(e),o.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(i),e.transparent=s<1,e.opacity=s}else if(t.line2){const e=t.line2.material;e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution.copy(r)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color&&e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution&&e.resolution.copy(r)}});this.object3d.add(o)}}_getResolution(){const t=this.threeContainer?.renderer3d;if(t){return t.getSize(new e.Vector2)}return new e.Vector2(window.innerWidth,window.innerHeight)}onGizmoDragEnd(t){const e=this._component,n=e.path;if(!n||n.length<2)return;const i=this.object3d,{width:s=0,height:r=0}=e.parent?.bounds??{},{x:o,y:a}=e.center,c=i.position,l=i.rotation,h=i.scale,d=this.position;if(Math.abs(c.x-d.x)<.001&&Math.abs(c.y-d.y)<.001&&Math.abs(c.z-d.z)<.001&&Math.abs(l.x)<.001&&Math.abs(l.y)<.001&&Math.abs(l.z)<.001&&Math.abs(h.x-1)<.001&&Math.abs(h.y-1)<.001&&Math.abs(h.z-1)<.001)return;const u=Sx.computeBakedPath(n,{x:o,y:a},{width:s,height:r},i);this._suppressOnchange=!0,e.set({rotation:0,rotationX:0,rotationY:0,zPos:0}),e.mutatePath(null,()=>u),this._suppressOnchange=!1,this.update()}static computeBakedPath(t,n,i,s){const r=i.width,o=i.height,a=n.x,c=n.y;return s.updateMatrixWorld(!0),t.map(t=>{const n=new e.Vector3(t.x-a,t.z||0,t.y-c).applyMatrix4(s.matrixWorld),i={x:n.x+r/2,y:n.z+o/2};return Math.abs(n.y)>.001&&(i.z=n.y),i})}updateStrokeStyle(){this.updateDimension()}updateAlpha(){this.updateDimension()}updateDimension(){this.clear(),this.build()}onchange(t,e){("path"in t||"from"in t||"to"in t)&&(this.updateDimension(),this.updatePosition()),("round"in t||"lineDash"in t||"lineWidth"in t||"begin"in t||"end"in t||"beginSize"in t||"endSize"in t)&&this.updateDimension(),super.onchange(t,e)}clear(){for(;this.object3d.children.length>0;){const t=this.object3d.children[0];this.object3d.remove(t),eu(t)}return this._line2=void 0,super.clear()}}class kx extends Sx{get worldPath(){const t=this.component.path;if(!t||t.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return t.map((s,a)=>{const c=t.length>1?a/(t.length-1):0;return new e.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}Gp("line",t=>new kx(t));class Ax extends Sx{get worldPath(){const t=this.component.path;if(!t||t.length<2)return[];const{x:n,y:i}=this.component.center;return t.map(t=>new e.Vector3(t.x-n,t.z||0,t.y-i))}}Gp("polyline",t=>new Ax(t));class Ex extends Sx{get worldPath(){const t=this.component.drawPath;if(!t||t.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return t.map((s,a)=>{const c=t.length>1?a/(t.length-1):0;return new e.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}Gp("ortholine",t=>new Ex(t)),Gp("group",t=>new px(t));class Cx{constructor(t){this._count=0,this._placements=[],this._geometry=t.geometry,this._material=t.material,this._capacity=Math.max(1,t.capacity??16),this._name=t.name??"instanced",this._castShadow=t.castShadow??!0,this._receiveShadow=t.receiveShadow??!1,this.object3d=new e.Group,this.object3d.name=this._name,this._mesh=this._makeMesh(this._capacity),this.object3d.add(this._mesh)}_makeMesh(t){const n=new e.InstancedMesh(this._geometry,this._material,t);return n.name=this._name+"__instances",n.castShadow=this._castShadow,n.receiveShadow=this._receiveShadow,n.instanceMatrix.setUsage(e.DynamicDrawUsage),n.count=0,n}get mesh(){return this._mesh}get count(){return this._count}get capacity(){return this._capacity}place(t){const e=t.length;if(e>this._capacity){const t=function(t,e=16){let n=Math.max(e,1);for(;n<t;)n*=2;return n}(e,this._capacity);this.object3d.remove(this._mesh),this._mesh.dispose(),this._capacity=t,this._mesh=this._makeMesh(t),this.object3d.add(this._mesh)}this._placements.length=e;for(let n=0;n<e;n++){const e=t[n];this._placements[n]=e,this._writeMatrix(n,e),void 0!==e.color&&this._writeColor(n,e.color)}this._count=e,this._mesh.count=e,this.commit()}update(t,e){t<0||t>=this._count||(this._placements[t]=e,this._writeMatrix(t,e),void 0!==e.color&&this._writeColor(t,e.color),this.commit())}setRotation(t,e){if(t<0||t>=this._count)return;const n=this._placements[t];n&&(n.rotation=e,this._writeMatrix(t,n))}commitMatrices(){this._mesh.instanceMatrix.needsUpdate=!0}setColor(t,e){t<0||t>=this._count||(this._writeColor(t,e),this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0))}indexOf(t){return t>=0&&t<this._count?t:-1}commit(){this._mesh.instanceMatrix.needsUpdate=!0,this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0),this._mesh.computeBoundingSphere()}dispose(){this.object3d.remove(this._mesh),this._mesh.dispose(),this._placements.length=0,this._count=0}_writeMatrix(t,e){const n=Cx;n._p.set(e.position.x,e.position.y,e.position.z);const i=e.rotation;n._e.set(i?.x??0,i?.y??0,i?.z??0),n._q.setFromEuler(n._e);const s=e.scale;"number"==typeof s?n._s.set(s,s,s):n._s.set(s?.x??1,s?.y??1,s?.z??1),n._m.compose(n._p,n._q,n._s),this._mesh.setMatrixAt(t,n._m)}_writeColor(t,e){Cx._c.set(e),this._mesh.setColorAt(t,Cx._c)}}function Tx(t,e,n){const i=Math.max(1,Math.floor(t.x??1)),s=Math.max(1,Math.floor(t.y??1)),r=Math.max(1,Math.floor(t.z??1)),o=e.x??0,a=e.y??0,c=e.z??0,l=n?.x??0,h=n?.y??0,d=n?.z??0,u=[];for(let t=0;t<s;t++)for(let e=0;e<r;e++)for(let n=0;n<i;n++)u.push({position:{x:l+n*o,y:h+t*a,z:d+e*c}});return u}Cx._m=new e.Matrix4,Cx._p=new e.Vector3,Cx._q=new e.Quaternion,Cx._e=new e.Euler,Cx._s=new e.Vector3,Cx._c=new e.Color;class Px extends pu{build(){super.build()}update(){}}const Ox={far:1e5,fov:80,near:1,zoom:1};class Dx extends pu{build(){super.build()}update(){super.update(),this.updateCamera()}getObject3dInstance(){return new e.PerspectiveCamera}updateCamera(){const{near:t=Ox.near,far:e=Ox.far,fov:n=Ox.fov,zoom:i=Ox.zoom}=this.component.state;this.object3d.far=e,this.object3d.fov=n,this.object3d.near=t,this.object3d.zoom=i}}class zx extends J_{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 Ix extends pu{getObject3dInstance(){return new e.Scene}dispose(){for(const t of this.object3d.children)eu(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=af(this.component)}updateTransform(){}updateDimension(){}updatePosition(){}updateRotate(){}updateScale(){}updateAlpha(){}updateHidden(){}get animationMixer(){return this._animationMixer||(this._animationMixer=new e.AnimationMixer(this.object3d)),this._animationMixer}}const Rx=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class jx extends pu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds;if(!t||!n)return;const i=Md(this.component.state.material3d),s=new e.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=Y_(this.component),o=new e.MeshStandardMaterial({map:r});Ad(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}get dimension(){const{width:t,height:e}=this.component.bounds;return{width:t||1,height:e||1,depth:1}}get scale(){const t=super.scale,{width:e,height:n}=this.dimension;return{x:t.x*e,y:t.y,z:t.z*n}}updateDimension(){this.updateTransform()}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this.update()},100)}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(U_(n,this.component,2),e.needsUpdate=!0)}update(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!Rx.has(e)){this._debouncedRebuild();break}}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Md(this.component.state.material3d);Ad(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),eu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const Lx={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 Fx=class extends Xm{constructor(){super(...arguments),this._capability=new zf}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}get hasEnvironment(){return this._capability.hasEnvironment}containable(t){return!0}is3dContainer(){return!0}getLightingConfig(){return{hemisphere:{skyColor:16777215,groundColor:14540253,intensity:1},directional:{color:16777215,intensity:1.2,attachToCamera:!0,castShadow:!1}}}getCss3DSceneAttribute(){return"three-container:css3d-renderer"}init_scene3d(){this._capability.isInitialized&&this._capability.destroy(),this._capability.init(this,{lightingConfig:this.getLightingConfig(),css3DSceneAttribute:this.getCss3DSceneAttribute(),skipEnvironment:!0,skipPostprocessing:!0,skipShadowMap:!0}),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:i,threed:s}=this.state;let{width:r,height:o}=this.bounds;if(r=Math.floor(r),o=Math.floor(o),s){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 s=this._capability.domElement;if(!s||!s.width||!s.height)return;t.drawImage(s,0,0,s.width,s.height,e,n,r,o),i&&this._capability.showDebugFPS(t)}else super.postrender(t)}dispose(){this._capability.dispose(),super.dispose()}get layout(){return Fc.get("three")}get nature(){return Lx}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()}};Fx=Nm([Sy("3d-container")],Fx),Vp(t=>new X_(t));const Nx=1;function Hx(t){return"number"==typeof t&&Number.isFinite(t)}function Bx(t){if(!t||"object"!=typeof t)return!1;const{x:e,y:n,z:i}=t;return Hx(e)&&Hx(n)&&Hx(i)}function Gx(t){const e=[],n=t;if(!n||"object"!=typeof n)return["청사진이 객체가 아니다"];1!==n.version&&e.push(`읽을 수 없는 판이다 — version ${String(n.version)}, 이 판올림은 1 만 읽는다`),"string"==typeof n.type&&0!==n.type.length||e.push("type 이 없다 — 컴포넌트 타입 이름이 곧 청사진을 찾는 키다");const i=n.base;return i&&Hx(i.x)&&Hx(i.y)&&Hx(i.z)?i.x>0&&i.z>0||e.push("base 의 x·z 는 0 보다 커야 한다 — 평면 배치 비율의 분모다"):e.push("base 의 x·y·z 가 온전하지 않다"),Array.isArray(n.groups)?(0===n.groups.length&&e.push("groups 가 비어 있다 — 그릴 것이 없는 청사진은 등록하지 않는다"),n.groups.forEach((t,n)=>{t&&Array.isArray(t.members)?(0===t.members.length&&e.push(`groups[${n}] 에 부품이 없다`),t.members.forEach((t,i)=>{const s=`groups[${n}].members[${i}]`;"string"==typeof t?.name&&0!==t.name.length||e.push(`${s}.name 이 없다 — 이름이 바인딩·이벤트·애니메이션이 붙는 자리다`);const r=t?.transform;r&&Bx(r.position)&&Bx(r.size)||e.push(`${s}.transform 의 값이 온전하지 않다`)})):e.push(`groups[${n}].members 가 배열이 아니다`)}),e):(e.push("groups 가 배열이 아니다"),e)}const Vx={"palette.primary":"#4a9eff","palette.accent":"#ff9800","palette.neutral":"#9e9e9e","palette.dark":"#37474f","palette.light":"#eceff1","palette.surface":"#607d8b"},Yx=new Map([["default",Vx]]);let Wx="default",Ux=0;function $x(){return Ux}function Xx(t,e){Yx.set(t,e),t===Wx&&Ux++}function qx(t){if(!Yx.has(t))throw new Error(`등록되지 않은 팔레트다: '${t}'. 등록된 것 — ${[...Yx.keys()].join(", ")}`);t!==Wx&&(Wx=t,Ux++)}function Kx(){return Wx}function Qx(){return Yx.get(Wx)}function Zx(t){const e=Qx()[t];if(void 0===e)throw new Error(`팔레트에 없는 토큰이다: '${t}' (팔레트 '${Wx}'). 쓸 수 있는 것 — ${Object.keys(Qx()).join(", ")}`);return e}const Jx=Vx["palette.neutral"];function tw(){Yx.clear(),Yx.set("default",Vx),Wx="default",Ux++}const ew=new Map;let nw=null;function iw(t){nw=t}function sw(t){const e=t.material?.token;return void 0===e?Jx:Zx(e)}function rw(t){const e=new Map;for(const n of t.points??[])e.set(n.name,n);const n=[],i=[];for(const s of t.groups){const t=sw(s);let r;for(const n of s.members){const o=e.get(n.name);o&&!r&&(r=o),i.push({member:n,group:s,color:t,point:o})}n.push({group:s,color:t,point:r})}return i.sort((t,e)=>t.member.transform.position.y-e.member.transform.position.y),{blueprint:t,paintOrder:i,groups:n,paletteVersion:$x()}}function ow(t){const e=Gx(t);if(e.length>0){throw new Error(`Figure '${t?.type??"(이름 없음)"}' 를 등록할 수 없다:\n - ${e.join("\n - ")}`)}const n=rw(t);return ew.set(t.type,n),nw&&nw.registerType?.(t.type),n}function aw(t){const e=ew.get(t);if(!e)return null;if(e.paletteVersion!==$x()){const n=rw(e.blueprint);return ew.set(t,n),n}return e}function cw(){return[...ew.keys()]}function lw(t){return ew.has(t)}function hw(t){return ew.delete(t)}function dw(){ew.clear()}function uw(t){const{size:e,rotation:n}=t.transform;if(!n)return{...e};const i=Math.PI/180,s=Math.cos((n.x??0)*i),r=Math.sin((n.x??0)*i),o=Math.cos((n.y??0)*i),a=Math.sin((n.y??0)*i),c=Math.cos((n.z??0)*i),l=Math.sin((n.z??0)*i),h=[[o*c,-o*l,a],[r*a*c+s*l,-r*a*l+s*c,-r*o],[-s*a*c+r*l,s*a*l+r*c,s*o]],d=t=>Math.abs(t[0])*e.x+Math.abs(t[1])*e.y+Math.abs(t[2])*e.z;return{x:d(h[0]),y:d(h[1]),z:d(h[2])}}function pw(t,e){if("scale"===t.sizing)return{x:1,y:1,z:1};const n={x:fw(e.x),y:fw(e.y),z:fw(e.z)};return"stretch"===t.sizing&&(n[function(t){const{x:e,y:n,z:i}=uw(t);return e>=i&&e>=n?"x":i>=n?"z":"y"}(t)]=1),n}function fw(t){return Number.isFinite(t)&&t>0?1/t:1}function mw(t,e){if("repeat"!==t.sizing||!t.repeat)return null;const n=t.repeat.axis,i=Math.max(0,t.repeat.gap),s=uw(t)[n],r=s+i;if(!(r>0))return null;const o=s*(Number.isFinite(e[n])&&e[n]>0?e[n]:1);return{axis:n,count:Math.max(1,Math.min(gw,Math.round((o+i)/r))),pitch:r}}const gw=100;function yw(t,e,n){return(t-(e-1)/2)*n}function bw(t){const n=vw(t);if(!n)return null;const{position:i,rotation:s}=t.transform;return s&&(n.rotateZ(e.MathUtils.degToRad(s.z??0)),n.rotateY(e.MathUtils.degToRad(s.y??0)),n.rotateX(e.MathUtils.degToRad(s.x??0))),n.translate(i.x,i.y,i.z),n}function _w(t){const n=vw(t);if(!n)return null;const{rotation:i}=t.transform;return i&&(n.rotateZ(e.MathUtils.degToRad(i.z??0)),n.rotateY(e.MathUtils.degToRad(i.y??0)),n.rotateX(e.MathUtils.degToRad(i.x??0))),n}function vw(t){const{size:n}=t.transform;if(!(n.x>0&&n.y>0&&n.z>0))return null;switch(t.primitive){case"cube":case"wall":return new e.BoxGeometry(n.x,n.y,n.z);case"cylinder":case"sphere":{const e=function(t){const e=t.segments;return Cv(e,Sv[0])}(t),i=Mv.primitive({kind:t.primitive,segments:e}).clone();return i.scale(n.x,n.y,n.z),i}case"rect":case"polygon":{const i=function(t){const{size:n}=t.transform,i=n.x,s=n.z,r=-i/2,o=-s/2;if("polygon"===t.primitive){const n=t.shape?.path;if(!n||n.length<3)return null;const i=new e.Shape;i.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++)i.lineTo(n[t].x,n[t].y);return i.closePath(),i}const a=t.shape?.round??0;if(a<=0){const t=new e.Shape;return t.moveTo(r,o),t.lineTo(r+i,o),t.lineTo(r+i,o+s),t.lineTo(r,o+s),t.closePath(),t}const c=Math.min(a,i/2,s/2),l=new e.Path;return l.moveTo(r+c,o),l.lineTo(r+i-c,o),l.quadraticCurveTo(r+i,o,r+i,o+c),l.lineTo(r+i,o+s-c),l.quadraticCurveTo(r+i,o+s,r+i-c,o+s),l.lineTo(r+c,o+s),l.quadraticCurveTo(r,o+s,r,o+s-c),l.lineTo(r,o+c),l.quadraticCurveTo(r,o,r+c,o),new e.Shape(l.getPoints(Sv[0]))}(t);if(!i)return null;const s=new e.ExtrudeGeometry(i,{steps:1,depth:n.y,bevelEnabled:!1});return s.rotateX(Math.PI/2),s.translate(0,n.y/2,0),s}}}function xw(t,n){const{blueprint:i}=t,s=t.groups[n];if(!s)return null;const r=`figure|${i.type}|${n}|${s.group.materialKey}|${function(t){let e=2166136261;const n=t=>{for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619)};for(const e of t.group.members){const{position:t,size:i,rotation:s}=e.transform;n(`${e.geometryKey}@${t.x},${t.y},${t.z}:${i.x},${i.y},${i.z}`),n(s?`%${s.x??0},${s.y??0},${s.z??0};`:";")}return(e>>>0).toString(36)}(s)}`,o=Mv.shaped(r,()=>{const t=[];for(const e of s.group.members){const n=bw(e);n&&t.push(n)}if(0===t.length)return new e.BufferGeometry;let r;if(1===t.length)r=t[0];else{const e=t.map(t=>t.index?t.toNonIndexed():t),o=j(e,!1);if(!o)throw new Error(`Figure '${i.type}' 의 묶음 ${n}(${s.group.materialKey})를 합치지 못했다 — 부품 ${s.group.members.map(t=>t.name).join(", ")}`);r=o;for(const t of e)t.dispose();for(const e of t)e.dispose()}return r});return o.getAttribute("position")?o:null}function ww(t,e){const{material:n}=e.group,i=wd[n.preset??"default"]??wd.default;return Z_.material(`figure|${t.blueprint.type}|${e.group.materialKey}`,{color:e.color,metalness:i.metalness,roughness:i.roughness,envMapIntensity:i.envMapIntensity,flatShading:n.flatShading??!0,transparent:n.transparent??!1,opacity:n.transparent?i.opacity??.3:1})}class Mw extends pu{constructor(){super(...arguments),this._meshByName=new Map,this._sized=[]}get figure(){return aw(this.component.state.type)}build(){super.build();const t=this.figure;t&&(t.groups.forEach((n,i)=>{const s=function(t){const{members:e}=t.group;if(1!==e.length)return null;const n=e[0];return function(t){return"scale"!==t.sizing}(n)?n:null}(n);if(s)return void this.buildSized(t,n,s);const r=xw(t,i);if(!r)return;const o=new e.Mesh(r,ww(t,n));o.castShadow=!0,o.name=n.group.animated?n.group.members[0]?.name??"":"",this.object3d.add(o);for(const t of n.group.members)this._meshByName.has(t.name)||this._meshByName.set(t.name,o)}),this.updateDimension())}buildSized(t,n,i){const s=function(t,n){const{size:i,rotation:s}=n.transform,r=`figure-part|${t.blueprint.type}|${n.geometryKey}|${i.x},${i.y},${i.z}|${s?`${s.x??0},${s.y??0},${s.z??0}`:"-"}`,o=Mv.shaped(r,()=>_w(n)??new e.BufferGeometry);return o.getAttribute("position")?o:null}(t,i);if(!s)return;const r=new e.Object3D,{position:o}=i.transform;r.position.set(o.x,o.y,o.z),r.name=i.name,this.object3d.add(r);const a=new e.Mesh(s,ww(t,n));a.castShadow=!0,r.add(a),this._sized.push({member:i,holder:r,copies:[a]}),this._meshByName.has(i.name)||this._meshByName.set(i.name,a)}applySizing(t){for(const n of this._sized){const{member:i,holder:s,copies:r}=n,o=pw(i,t);s.scale.set(o.x,o.y,o.z);const a=mw(i,t);if(!a){r.forEach((t,e)=>{t.visible=0===e,t.position.set(0,0,0)});continue}const c=r[0];for(;r.length<a.count;){const t=new e.Mesh(c.geometry,c.material);t.castShadow=!0,s.add(t),r.push(t)}r.forEach((t,e)=>{t.visible=e<a.count,t.visible&&(t.position.set(0,0,0),t.position[a.axis]=yw(e,a.count,a.pitch))})}}get effectiveDepth(){const t=this.component.state.depth;if("number"==typeof t&&Number.isFinite(t)&&t>0)return t;const e=this.figure;if(!e)return super.effectiveDepth;const{base:n}=e.blueprint,{width:i,height:s}=this.component.bounds,r=n.x>0?i/n.x:1,o=n.z>0?s/n.z:1;return n.y*Math.sqrt(Math.max(r,0)*Math.max(o,0))}updateDimension(){const t=this.figure;if(!t)return;const{base:e}=t.blueprint,{width:n,height:i}=this.component.bounds,s=this.effectiveDepth,r={x:e.x>0?n/e.x:1,y:e.y>0?s/e.y:1,z:e.z>0?i/e.z:1};this.setDimensionScale(r.x,r.y,r.z),this._sized.length>0&&this.applySizing(r)}topOutline(){return null}clear(){return this._meshByName.clear(),this._sized=[],super.clear()}}const Sw={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure"};class kw extends(Dc(Pc)){static registerType(t){Tc.register(t,kw)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Sw}buildRealObject(){return new Mw(this)}get figure(){return aw(this.state.type)}render(t){const e=this.figure,{left:n=0,top:i=0,width:s=0,height:r=0}=this.state;if(!e)return void this.renderMissing(t,n,i,s,r);const{base:o}=e.blueprint,a=o.x>0?s/o.x:1,c=o.z>0?r/o.z:1,l=n+s/2,h=i+r/2,d={x:a,y:this.depthScale(o,a,c),z:c};for(const n of e.paintOrder)t.fillStyle=n.color,t.beginPath(),this.tracePart(t,n,l,h,a,c,d),t.fill()}depthScale(t,e,n){const i=this.state.depth;return"number"==typeof i&&Number.isFinite(i)&&i>0?t.y>0?i/t.y:1:Math.sqrt(Math.max(e,0)*Math.max(n,0))}tracePart(t,e,n,i,s,r,o){const{member:a}=e,{position:c}=a.transform,l=n+c.x*s,h=i+c.z*r,d=pw(a,o),u=s*d.x,p=r*d.z,f=mw(a,o);if(f&&"y"!==f.axis&&f.count>1)for(let n=0;n<f.count;n++){const i=yw(n,f.count,f.pitch);this.traceOne(t,e,"x"===f.axis?l+i*s:l,"z"===f.axis?h+i*r:h,u,p)}else this.traceOne(t,e,l,h,u,p)}traceOne(t,e,n,i,s,r){const{member:o}=e,{size:a,rotation:c}=o.transform,l=c?.x??0,h=c?.y??0,d=c?.z??0;if(0!==l||0!==d){const e=function(t,e,n,i){const s=Math.PI/180,r=Math.cos(e*s),o=Math.sin(e*s),a=Math.cos(n*s),c=Math.sin(n*s),l=Math.cos(i*s),h=Math.sin(i*s),d=a*l,u=-a*h,p=c,f=o*h-r*c*l,m=o*l+r*c*h,g=r*a,y=t.x/2,b=t.y/2,_=t.z/2;return{u:Math.abs(d)*y+Math.abs(u)*b+Math.abs(p)*_,v:Math.abs(f)*y+Math.abs(m)*b+Math.abs(g)*_}}(a,l,h,d);return void t.rect(n-e.u*s,i-e.v*r,2*e.u*s,2*e.v*r)}if(0!==h)return t.save(),t.translate(n,i),t.rotate(-h*Math.PI/180),this.traceShape(t,e,0,0,s,r),void t.restore();this.traceShape(t,e,n,i,s,r)}traceShape(t,e,n,i,s,r){const{member:o}=e,{size:a}=o.transform,c=a.x*s,l=a.z*r,h=n-c/2,d=i-l/2;switch(o.primitive){case"cylinder":case"sphere":{const e=dv(c/2,l/2,Cv(o.segments,Sv[0])).points;t.moveTo(n+e[0].x,i+e[0].y);for(let s=1;s<e.length;s++)t.lineTo(n+e[s].x,i+e[s].y);return void t.closePath()}case"polygon":{const e=o.shape?.path;if(!e||e.length<3)return;t.moveTo(n+e[0].x*s,i+e[0].y*r);for(let o=1;o<e.length;o++)t.lineTo(n+e[o].x*s,i+e[o].y*r);return void t.closePath()}default:{const e=o.shape?.round??0;if(e>0&&"function"==typeof t.roundRect)return void t.roundRect(h,d,c,l,Math.min(e*s,c/2,l/2));t.rect(h,d,c,l)}}}renderMissing(t,e,n,i,s){t.save(),t.strokeStyle="#e53935",t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.rect(e,n,i,s),t.stroke(),t.restore()}postrender(t){Tc.prototype.postrender.call(this,t)}}iw(kw);const Aw={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure-part"},Ew=["cylinder","sphere"],Cw=["rect","polygon"];function Tw(t){return t.state}class Pw extends pu{build(){super.build();const t=Tw(this.component).primitive??"cube",n=Cw.includes(t)?this.extrudedGeometry(t):this.unitGeometry(t);if(!n)return;const i=new e.Mesh(n,this.material());i.castShadow=!0,this.object3d.add(i),this.updateDimension()}unitGeometry(t){const e=Tw(this.component);return"cylinder"===t||"sphere"===t?Mv.primitive({kind:t,segments:Cv(e.segments,Sv[0])}):Mv.primitive({kind:"box"})}extrudedGeometry(t){const n=Tw(this.component),{width:i=1,height:s=1}=this.component.state,r=n.round??0,o=n.path,a="polygon"===t?`figure-part|polygon|${JSON.stringify(o??[])}`:`figure-part|rect|${i}x${s}|r${r}`,c=Mv.shaped(a,()=>{const n=this.crossSection(t,i,s,r,o);if(!n)return new e.BufferGeometry;const a=new e.ExtrudeGeometry(n,{steps:1,depth:1,bevelEnabled:!1});return a.rotateX(Math.PI/2),a.translate(0,.5,0),a});return c.getAttribute("position")?c:null}crossSection(t,n,i,s,r){if("polygon"===t){if(!r||r.length<3)return null;const t=new e.Shape;t.moveTo(r[0].x,r[0].y);for(let e=1;e<r.length;e++)t.lineTo(r[e].x,r[e].y);return t.closePath(),t}const o=-n/2,a=-i/2;if(s<=0){const t=new e.Shape;return t.moveTo(o,a),t.lineTo(o+n,a),t.lineTo(o+n,a+i),t.lineTo(o,a+i),t.closePath(),t}const c=Math.min(s,n/2,i/2),l=new e.Path;return l.moveTo(o+c,a),l.lineTo(o+n-c,a),l.quadraticCurveTo(o+n,a,o+n,a+c),l.lineTo(o+n,a+i-c),l.quadraticCurveTo(o+n,a+i,o+n-c,a+i),l.lineTo(o+c,a+i),l.quadraticCurveTo(o,a+i,o,a+i-c),l.lineTo(o,a+c),l.quadraticCurveTo(o,a,o+c,a),new e.Shape(l.getPoints(Sv[0]))}material(){const t=Tw(this.component),e=wd[t.preset??"default"]??wd.default,n=t.token?Zx(t.token):Jx,i=t.flatShading??!0,s=t.transparent??!1;return Z_.material(`figure-part|${t.token??"-"}|${t.preset??"default"}|${i}|${s}`,{color:n,metalness:e.metalness,roughness:e.roughness,envMapIntensity:e.envMapIntensity,flatShading:i,transparent:s,opacity:s?e.opacity??.3:1})}updateDimension(){const{width:t=1,height:e=1}=this.component.bounds,n=this.effectiveDepth,i=Tw(this.component).primitive??"cube";Cw.includes(i)?this.setDimensionScale(1,n,1):this.setDimensionScale(t,n,e)}}class Ow extends(Dc(Pc)){static registerType(){Tc.register("figure-part",Ow)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Aw}buildRealObject(){return new Pw(this)}render(t){const{left:e=0,top:n=0,width:i=0,height:s=0}=this.state,r=Tw(this);t.beginPath(),this.traceFootprint(t,r,e,n,i,s),t.fillStyle=r.token?Zx(r.token):Jx,t.fill()}traceFootprint(t,e,n,i,s,r){const o=e.primitive??"cube",a=n+s/2,c=i+r/2;if(Ew.includes(o)){const n=dv(s/2,r/2,Cv(e.segments,Sv[0])).points;t.moveTo(a+n[0].x,c+n[0].y);for(let e=1;e<n.length;e++)t.lineTo(a+n[e].x,c+n[e].y);return void t.closePath()}if("polygon"===o){const n=e.path;if(!n||n.length<3)return;t.moveTo(a+n[0].x,c+n[0].y);for(let e=1;e<n.length;e++)t.lineTo(a+n[e].x,c+n[e].y);return void t.closePath()}const l=e.round??0;l>0&&"function"==typeof t.roundRect?t.roundRect(n,i,s,r,Math.min(l,s/2,r/2)):t.rect(n,i,s,r)}}var Dw;Ow.registerType(),function(t){t.compile=zl,t.duplicate=Il,t.select=nc,t.match=Ja}(Dw||(Dw={})),Li.registerResidents(()=>({componentResidentsCount:Tc.residentsCount,sceneResidentsCount:Gu.residentsCount,referenceMapResidentsCount:I_.residentsCount,sceneResidents:Tc.residents}));var zw=Object.freeze({__proto__:null,AbsoluteLayout:Hc,Animation:Aa,AudioPlayer:Yg,BULGE_EPSILON:qr,get Banner(){return Uv},Banner3D:Wv,BoxSelectionManager:Ef,COMMON_PLACEHOLDER_PROPERTIES:ug,CORE_PLACEHOLDER_TYPES:gg,get Camera(){return Qv},Camera3D:Kv,CameraBookmarkManager:Af,CameraManager:df,Capacity:Wy,CapacityEventTracker:Ey,CardLayout:Gc,CenteringQueueStrategy:Ty,CenteringSlotStrategy:d_,Component:Tc,Connectable:Xf,Container:Xm,ContainerAbstract:Kl,ControlsManager:mf,get Cube(){return Hv},Cube3D:Nv,get Cylinder(){return Vv},Cylinder3D:Gv,DEFAULT:Qs,DEFAULT_PALETTE:Vx,DEFAULT_PLACEMENT:ru,DPPX:Xs,DataLagTracker:eh,DataSource:_y,DefaultLoadingOverlayRenderer:jd,Donut:ly,DonutExtrude:bv,Ellipse:hg,EllipseExtrude:fv,EventManager3D:gf,EventMap:ml,FPS:Pp,FigureInstance:kw,FigurePart:Ow,FigurePartRealObject:Pw,FigureRealObject:Mw,FixedSlotStrategy:Gy,get FloorPlate(){return cx},FlowEngine:Jb,FlowNode:e_,GESTURES:qs,get GLTFObject(){return Jv},GLTF_BASE_URL_ALIAS:xy,GenericObject:mg,GeometryBank:Mv,GifView:Gg,GizmoManager:bf,GizmoOperationManager:xf,GlobalRef:Zg,GltfComponent:My,GridStacking:Dy,Group:$g,HTMLAbsoluteLayout:Nc,HTMLOverlayContainer:Kg,HTMLOverlayElement:Pg,Holdable:t_,ImageView:Tg,InfoWindow:jc,InstancedSet:Cx,InteractionManager:wf,ItemsDataBinding:By,KEYEVENTS:Ks,Layer:cp,Layout:Fc,LightManager:pf,LightObject:ex,Line:cg,Line3D:kx,LinearHorizontalLayout:Yc,LinearVerticalLayout:Uc,LoadTracker:sh,LoadingOverlay:Cd,LocalRef:qg,MATERIAL_PRESETS:wd,MAX_SEGMENTS:Ev,MAX_UNDO_SIZE:30,MIN_SEGMENTS:3,MODE_ADD:3,MODE_EDIT:1,MODE_PASTE_DATABIND:5,MODE_PASTE_STYLE:4,MODE_SHIFT:2,MODE_VIEW:0,MaterialBank:Z_,get Model(){return Dw},MoveHandle:Xl,NOTHING:Ns,NavGraph:y_,Node:fy,OrthoLine:Eg,OrthoLine3D:Ex,PIXEL_RATIO:Op,PLACEHOLDER_THEMES:dg,Path:sy,PatternStacking:Oy,PlacementManager:Mf,get PointLight(){return nx},Polygon:vg,PolygonContainer:wg,PolygonExtrude:yv,PolygonPathPolyline:S_,Polyline:kg,Polyline3D:Ax,Popup:ey,PopupContainer:iy,Pose6DOF:xl,RealObject:pu,RealObjectCamera:Dx,RealObjectDomElement:Np,RealObjectDomTexture:X_,RealObjectDummy:Px,RealObjectExternalModel:gu,RealObjectExtrude:pv,RealObjectGLTF:vu,RealObjectGroup:px,RealObjectLine:Sx,RealObjectMesh:J_,RealObjectPlane:zx,RealObjectPlane2D:jx,RealObjectScene:Ix,RealObjectService:my,RealObjectSprite:Iv,RealObjectSprite2D:Rv,RealObjectText:ov,Rect:Qf,RectExtrude:mv,RectPath:Dc,ReferenceMap:I_,RendererManager:uf,ReservationTable:m_,RootContainer:th,Ruler:Jf,SCALE_MIN:Wd,SCENE_MODE:Us,SEGMENT_DEFAULTS:kv,SEGMENT_PRESETS:Sv,SHORTCUT_SECTIONS:Hf,SUPPORTED_BLUEPRINT_VERSION:1,Scene:Gu,SceneManager:hf,ScenePopup:ap,SceneSearchEngine:ku,ScriptLoader:B_,SearchOverlay:Eu,ServiceComponent:yy,Shape:Pc,get Sphere(){return zv},Sphere3D:Dv,get Sprite(){return Lv},Star:uy,StarExtrude:vv,TRANSFER_SLOT_KEY:Ny,TableLayout:$c,Text:Wg,ThreeCapability:zf,get ThreeContainer(){return Fx},ThreeDOnly:vy,Tracker:Tu,Transfer:Fu,TransitionEffect:$l,Triangle:oy,TriangleExtrude:_v,UNIT_DIMENSION:qd,UNIT_ROTATE:Zd,UNIT_SCALE:Kd,UNIT_TRANSLATE:Qd,UNTOKENED_COLOR:Jx,ValueHolder:by,VertexGizmoManager:Df,VolumeStacking:zy,get Wall(){return rx},Wall3D:sx,Z_PRIORITY:au,activePalette:Qx,activePaletteName:Kx,allDestinations:Hb,anchorsConnect:Qy,animate:ka,applyAlpha:$d,applyMaterial3dProps:Ad,applyPolicy:Vb,applySeatingRotation:Fy,applyStackLayout:Iy,applyZPriorityToMaterials:lu,arcSegmentTopology:qy,autoWireBackPressure:Cy,blueprintProblems:Gx,buildArrow3D:Lp,buildContractInspector:P_,buildCoordinateGround:qp,buildFlowGraph:nb,buildNavGraph:v_,buildShapeFromPolygonPath:gv,buildTether:Zu,bulgeFromDrag:Jr,bulgeHandlePosition:Zr,canReach:ab,capability:zm,centerOnBBox:uv,chooseNearestPickupFrame:h_,clearTether:tp,collectAdjacentSegments:ub,compile:Ca,componentForNode:Nb,computeArcParams:Qr,computeFlowMap:Eb,computeStackPositions:Py,cornerHandlePosition:eo,cornerRadiusFromDrag:no,create:Yu,createCanvas:Dp,createCanvasTexture:Y_,createFloor:af,createRealObjectFor:Yp,createSelectionHandle3D:lx,dataLagTracker:nh,debug:ts,deliversInto:tb,delta:Ma,disposeCoordinateGround:Jp,disposeObject3D:eu,disposeTether:ep,downstream:Ub,drawTextTexture:nv,effectiveCornerRadius:to,ellipseOutline:dv,enumerateDataScenarios:gb,error:Zi,figureTypes:cw,fillStyleOpacity:Ud,filterByToolType:l_,filterShortcuts:Bf,findNearestWithCapability:Pb,flattenPolygonPath:k_,flowGraphFor:Lb,flowGraphIssues:jb,flowReverseFor:Cb,fontStyle:tv,footprint2D:Ry,frameClock:jr,ftId:Mb,ftrace:wb,getAllCapabilityMeta:Lm,getCapabilityMeta:jm,getFigure:aw,getPose:Al,getWorldPose:El,globalSimClock:Ir,gltfNatureProperties:wy,graphFor:Kb,gridPlacements:Tx,hasArc:Kr,hasCapability:Dm,hasCapacity:ky,hasFigure:lw,inferCapacity:Ay,inferDownstreamId:pb,inferFlowDirections:xb,initFontFamilyWatcher:Js,inspector:Ed,installContractInspector:O_,isFlowNode:n_,isGenericPlaceholder:yg,isGeometricHost:Tb,isParted:fu,isRoutingTarget:Ob,isSegmentPreset:Pv,isStateDriven:ou,isThreedEnabled:wu,matchOutbounds:eb,memberGeometry:bw,memberGeometryAtOrigin:vw,memberGeometryTurned:_w,mergedGeometryOf:xw,metrics:Li,next:Wb,nextHop:ob,nextHops:rb,nextHopsToAny:lb,nextHopsToAnyDetailed:hb,niceGridStep:$p,nodeIdOf:Bb,opaqueColor:Xd,paletteVersion:$x,partAtByIndex:mu,pickWeightedDestination:Zb,planPathAStar:x_,planToReservations:w_,pointInRotatedRect:Zy,polygonOffsetForPriority:cu,polygonPathLength:A_,projectToScreen:Xu,quatFromYaw:s_,rayAbsDistanceToRect:Jy,reachableByOutbound:ib,reachableDestinations:$b,reachableDestinationsFrom:Xb,reachableDestinationsWeightedFrom:qb,reachableSinks:cb,receiptToJSON:ju,recommendsLogarithmicDepthForSky:lf,rectFaceAnchors:Uy,rectOutline:hv,rectangularFootprintFrames:a_,registerCapabilityMeta:Rm,registerDefaultRealObjectFactory:Vp,registerFigure:ow,registerPalette:Xx,registerRealObjectFactory:Gp,renderCanvasTexture:W_,renderPlaceholder:pg,reservationTable:g_,resetFigures:dw,resetPalettes:tw,resolveAnchorWorldPosition:Qu,resolveHeightSegments:Tv,resolveMaterial3d:Md,resolveNextHop:Yb,resolveSegments:Cv,resolveToken:Zx,resolveVariant:Gd,sceneComponent:Sy,setActivePalette:qx,setPose:Cl,setThreedEnabled:Mu,setWorldPose:Tl,sinksForDestination:Fb,standardYieldPolicy:f_,stopFPSMeasure:Tp,straightSegmentEndpoints:Xy,straightSegmentMultiInbound:Ky,straightSegmentTopology:$y,textBounds:rv,textTexture:iv,toThreeSide:kd,topApproachFrame:c_,transferLog:Nu,transferTracer:Iu,uniformZ:io,unregisterFigure:hw,updateDefaultFontFamily:Zs,updateTether:Ju,useFigureComponent:iw,validate:Qb,validateFlowGraph:db,version:G_,warn:Ji});const Iw=globalThis;"undefined"==typeof globalThis||Iw.scene||(Iw.scene=zw);export{Hc as AbsoluteLayout,Aa as Animation,Yg as AudioPlayer,qr as BULGE_EPSILON,Uv as Banner,Wv as Banner3D,Ef as BoxSelectionManager,ug as COMMON_PLACEHOLDER_PROPERTIES,gg as CORE_PLACEHOLDER_TYPES,Qv as Camera,Kv as Camera3D,Af as CameraBookmarkManager,df as CameraManager,Wy as Capacity,Ey as CapacityEventTracker,Gc as CardLayout,Ty as CenteringQueueStrategy,d_ as CenteringSlotStrategy,Tc as Component,Xf as Connectable,Xm as Container,Kl as ContainerAbstract,mf as ControlsManager,Hv as Cube,Nv as Cube3D,Vv as Cylinder,Gv as Cylinder3D,Qs as DEFAULT,Vx as DEFAULT_PALETTE,ru as DEFAULT_PLACEMENT,Xs as DPPX,eh as DataLagTracker,_y as DataSource,jd as DefaultLoadingOverlayRenderer,ly as Donut,bv as DonutExtrude,hg as Ellipse,fv as EllipseExtrude,gf as EventManager3D,ml as EventMap,Pp as FPS,kw as FigureInstance,Ow as FigurePart,Pw as FigurePartRealObject,Mw as FigureRealObject,Gy as FixedSlotStrategy,cx as FloorPlate,Jb as FlowEngine,e_ as FlowNode,qs as GESTURES,Jv as GLTFObject,xy as GLTF_BASE_URL_ALIAS,mg as GenericObject,Mv as GeometryBank,Gg as GifView,bf as GizmoManager,xf as GizmoOperationManager,Zg as GlobalRef,My as GltfComponent,Dy as GridStacking,$g as Group,Nc as HTMLAbsoluteLayout,Kg as HTMLOverlayContainer,Pg as HTMLOverlayElement,t_ as Holdable,Tg as ImageView,jc as InfoWindow,Cx as InstancedSet,wf as InteractionManager,By as ItemsDataBinding,Ks as KEYEVENTS,cp as Layer,Fc as Layout,pf as LightManager,ex as LightObject,cg as Line,kx as Line3D,Yc as LinearHorizontalLayout,Uc as LinearVerticalLayout,sh as LoadTracker,Cd as LoadingOverlay,qg as LocalRef,wd as MATERIAL_PRESETS,Ev as MAX_SEGMENTS,$s as MAX_UNDO_SIZE,Av as MIN_SEGMENTS,Vs as MODE_ADD,Bs as MODE_EDIT,Ws as MODE_PASTE_DATABIND,Ys as MODE_PASTE_STYLE,Gs as MODE_SHIFT,Hs as MODE_VIEW,Z_ as MaterialBank,Dw as Model,Xl as MoveHandle,Ns as NOTHING,y_ as NavGraph,fy as Node,Eg as OrthoLine,Ex as OrthoLine3D,Op as PIXEL_RATIO,dg as PLACEHOLDER_THEMES,sy as Path,Oy as PatternStacking,Mf as PlacementManager,nx as PointLight,vg as Polygon,wg as PolygonContainer,yv as PolygonExtrude,S_ as PolygonPathPolyline,kg as Polyline,Ax as Polyline3D,ey as Popup,iy as PopupContainer,xl as Pose6DOF,pu as RealObject,Dx as RealObjectCamera,Np as RealObjectDomElement,X_ as RealObjectDomTexture,Px as RealObjectDummy,gu as RealObjectExternalModel,pv as RealObjectExtrude,vu as RealObjectGLTF,px as RealObjectGroup,Sx as RealObjectLine,J_ as RealObjectMesh,zx as RealObjectPlane,jx as RealObjectPlane2D,Ix as RealObjectScene,my as RealObjectService,Iv as RealObjectSprite,Rv as RealObjectSprite2D,ov as RealObjectText,Qf as Rect,mv as RectExtrude,Dc as RectPath,I_ as ReferenceMap,uf as RendererManager,m_ as ReservationTable,th as RootContainer,Jf as Ruler,Wd as SCALE_MIN,Us as SCENE_MODE,kv as SEGMENT_DEFAULTS,Sv as SEGMENT_PRESETS,Hf as SHORTCUT_SECTIONS,Nx as SUPPORTED_BLUEPRINT_VERSION,Gu as Scene,hf as SceneManager,ap as ScenePopup,ku as SceneSearchEngine,B_ as ScriptLoader,Eu as SearchOverlay,yy as ServiceComponent,Pc as Shape,zv as Sphere,Dv as Sphere3D,Lv as Sprite,uy as Star,vv as StarExtrude,Ny as TRANSFER_SLOT_KEY,$c as TableLayout,Wg as Text,zf as ThreeCapability,Fx as ThreeContainer,vy as ThreeDOnly,Tu as Tracker,Fu as Transfer,$l as TransitionEffect,oy as Triangle,_v as TriangleExtrude,qd as UNIT_DIMENSION,Zd as UNIT_ROTATE,Kd as UNIT_SCALE,Qd as UNIT_TRANSLATE,Jx as UNTOKENED_COLOR,by as ValueHolder,Df as VertexGizmoManager,zy as VolumeStacking,rx as Wall,sx as Wall3D,au as Z_PRIORITY,Qx as activePalette,Kx as activePaletteName,Hb as allDestinations,Qy as anchorsConnect,ka as animate,$d as applyAlpha,Ad as applyMaterial3dProps,Vb as applyPolicy,Fy as applySeatingRotation,Iy as applyStackLayout,lu as applyZPriorityToMaterials,qy as arcSegmentTopology,Cy as autoWireBackPressure,Gx as blueprintProblems,Lp as buildArrow3D,P_ as buildContractInspector,qp as buildCoordinateGround,nb as buildFlowGraph,v_ as buildNavGraph,gv as buildShapeFromPolygonPath,Zu as buildTether,Jr as bulgeFromDrag,Zr as bulgeHandlePosition,ab as canReach,zm as capability,uv as centerOnBBox,h_ as chooseNearestPickupFrame,tp as clearTether,ub as collectAdjacentSegments,Ca as compile,Nb as componentForNode,Qr as computeArcParams,Eb as computeFlowMap,Py as computeStackPositions,eo as cornerHandlePosition,no as cornerRadiusFromDrag,Yu as create,Dp as createCanvas,Y_ as createCanvasTexture,af as createFloor,Yp as createRealObjectFor,lx as createSelectionHandle3D,nh as dataLagTracker,ts as debug,tb as deliversInto,Ma as delta,Jp as disposeCoordinateGround,eu as disposeObject3D,ep as disposeTether,Ub as downstream,nv as drawTextTexture,to as effectiveCornerRadius,dv as ellipseOutline,gb as enumerateDataScenarios,Zi as error,cw as figureTypes,Ud as fillStyleOpacity,l_ as filterByToolType,Bf as filterShortcuts,Pb as findNearestWithCapability,k_ as flattenPolygonPath,Lb as flowGraphFor,jb as flowGraphIssues,Cb as flowReverseFor,tv as fontStyle,Ry as footprint2D,jr as frameClock,Mb as ftId,wb as ftrace,Lm as getAllCapabilityMeta,jm as getCapabilityMeta,aw as getFigure,Al as getPose,El as getWorldPose,Ir as globalSimClock,wy as gltfNatureProperties,Kb as graphFor,Tx as gridPlacements,Kr as hasArc,Dm as hasCapability,ky as hasCapacity,lw as hasFigure,Ay as inferCapacity,pb as inferDownstreamId,xb as inferFlowDirections,Js as initFontFamilyWatcher,Ed as inspector,O_ as installContractInspector,n_ as isFlowNode,yg as isGenericPlaceholder,Tb as isGeometricHost,fu as isParted,Ob as isRoutingTarget,Pv as isSegmentPreset,ou as isStateDriven,wu as isThreedEnabled,eb as matchOutbounds,bw as memberGeometry,vw as memberGeometryAtOrigin,_w as memberGeometryTurned,xw as mergedGeometryOf,Li as metrics,Wb as next,ob as nextHop,rb as nextHops,lb as nextHopsToAny,hb as nextHopsToAnyDetailed,$p as niceGridStep,Bb as nodeIdOf,Xd as opaqueColor,$x as paletteVersion,mu as partAtByIndex,Zb as pickWeightedDestination,x_ as planPathAStar,w_ as planToReservations,Zy as pointInRotatedRect,cu as polygonOffsetForPriority,A_ as polygonPathLength,Xu as projectToScreen,s_ as quatFromYaw,Jy as rayAbsDistanceToRect,ib as reachableByOutbound,$b as reachableDestinations,Xb as reachableDestinationsFrom,qb as reachableDestinationsWeightedFrom,cb as reachableSinks,ju as receiptToJSON,lf as recommendsLogarithmicDepthForSky,Uy as rectFaceAnchors,hv as rectOutline,a_ as rectangularFootprintFrames,Rm as registerCapabilityMeta,Vp as registerDefaultRealObjectFactory,ow as registerFigure,Xx as registerPalette,Gp as registerRealObjectFactory,W_ as renderCanvasTexture,pg as renderPlaceholder,g_ as reservationTable,dw as resetFigures,tw as resetPalettes,Qu as resolveAnchorWorldPosition,Tv as resolveHeightSegments,Md as resolveMaterial3d,Yb as resolveNextHop,Cv as resolveSegments,Zx as resolveToken,Gd as resolveVariant,Sy as sceneComponent,qx as setActivePalette,Cl as setPose,Mu as setThreedEnabled,Tl as setWorldPose,Fb as sinksForDestination,f_ as standardYieldPolicy,Tp as stopFPSMeasure,Xy as straightSegmentEndpoints,Ky as straightSegmentMultiInbound,$y as straightSegmentTopology,rv as textBounds,iv as textTexture,kd as toThreeSide,c_ as topApproachFrame,Nu as transferLog,Iu as transferTracer,io as uniformZ,hw as unregisterFigure,Zs as updateDefaultFontFamily,Ju as updateTether,iw as useFigureComponent,Qb as validate,db as validateFlowGraph,G_ as version,Ji as warn};
50
+ `,this.element)}catch(t){}}onchangeMinimized(){const{minimized:t}=this.state;t?this.setState("height",24):this.setState("height",this.get("height"))}}Ym=new WeakMap,Tc.memoize(Xm.prototype,"bounds",!0),Tc.register("container",Xm);const qm=Math.sqrt(3),Km=2;function Qm(t,e,n,i,s){const r=5+s,o=n.x,a=n.y,c=i.x,l=i.y;if(Math.abs(o-c)>r&&Math.abs(a-l)>r){const n=(l-a)/(c-o),i=a-n*o;if(Math.abs(e-(n*t+i))>r)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 Zm(t,e,n,i=2){for(let s=0;s<n.length-1;s++)if(Qm(t,e,n[s],n[s+1],i))return!0;return!1}function Jm(t,e,n,i){if("arrow"!=t.slice(-5))return n;const s=Math.atan2(i.y-n.y,i.x-n.x),r=1.5*e;return{x:n.x+Math.cos(s)*r,y:n.y+Math.sin(s)*r}}function tg(t,e,n){let{lineWidth:i=Km,strokeStyle:s="#000000",lineCap:r=!1,alpha:o=1,begin:a="none",end:c="none",beginSize:l="size5",endSize:h="size5"}=n;if(("none"!=a||"none"!=c)&&(i=Number(i)||Km,t.lineCap=r,t.lineWidth=i,t.strokeStyle=s,t.fillStyle=s,t.globalAlpha*=o,"none"!=a&&eg(t,e[0],e[1],i,a,ng(l,i)),"none"!=c)){const n=e.length;eg(t,e[n-1],e[n-2],i,c,ng(h,i))}}function eg(t,e,n,i,s,r){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),s){case"oval":t.ellipse(0,0,r.X,r.Y,0,0,2*Math.PI),t.fill();break;case"diamond":t.moveTo(-r.X,0),t.lineTo(0,-r.Y),t.lineTo(r.X,0),t.lineTo(0,r.Y),t.fill();break;case"arrow":t.moveTo(0,0),t.lineTo(qm*r.X,-r.Y),t.lineTo(qm*r.X,r.Y),t.fill();break;case"sharp-arrow":t.moveTo(0,0),t.lineTo(qm*r.X,-r.Y),t.lineTo(-r.X/1.5+qm*r.X,0),t.lineTo(qm*r.X,r.Y),t.fill();break;case"open-arrow":t.moveTo(qm*r.X+i,-r.Y),t.lineTo(i,0),t.lineTo(qm*r.X+i,r.Y),t.stroke();break;case"cross":t.moveTo(-r.X,-r.Y),t.lineTo(r.X,r.Y),t.moveTo(r.X,-r.Y),t.lineTo(-r.X,r.Y),t.stroke()}t.rotate(-c),t.translate(-o,-a),t.closePath()}function ng(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 ig="N",sg="S",rg="E",og="W";class ag{constructor({component:t,anchor:e,position:n,self:i}){this.component=t,this._anchorName=e,this._position=n,this.self=i}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 rg;const n=e.position;return n.y<=t.top?ig:n.y>=t.top+t.height?sg:n.x<=t.left?og:rg}get boundaryPosition(){const t=this.anchor;if(t){let{position:e}=t,n=0,i=0;switch(this.direction){case sg:i=20;break;case ig:i=-20;break;case og:n=-20;break;default:n=20}e={x:e.x+n,y:e.y+i};const s=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(s.x,s.y)}}}class cg extends Tc{isLine(){return!0}is3dish(){return!0}replaceRefids(t){["from","to"].forEach(e=>{const n=this.get(e);if(n?.component){const i=t.get(n.component)||n.component;this.set(e,{...n,component:i})}})}get fromEnd(){if(this.parent&&!this._fromEnd){const{component:t,anchor:e,position:n}=this.getState("from")||{};if(!t)return;const i=this.root?.findByRefid?.(t);if(!i)return;this._fromEnd=new ag({component:i,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 i=this.root?.findByRefid?.(t);if(!i)return;this._toEnd=new ag({component:i,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:i,round:s=0}=this.state;let r=this.drawPath;tg(t,r,this.state),t.beginPath();const o=Jm(e,i,r[0],r[1]),a=Jm(n,i,r[r.length-1],r[r.length-2]),c=r[0];r=[o,...r.slice(1,-1),a];let l={x:o.x,y:o.y};if(t.moveTo(o.x,o.y),r.length>=2&&Kr(c)){const e=r[1],n=to(e,s),i=Math.sqrt((o.x-e.x)**2+(o.y-e.y)**2),a=0!==i?Math.atan2(o.x-e.x,o.y-e.y):0,l=Math.sin(a)*Math.min(n,i/2)+e.x,h=Math.cos(a)*Math.min(n,i/2)+e.y,d=Qr({x:o.x,y:o.y},{x:l,y:h},c.bulge);d&&t.arc(d.cx,d.cy,d.radius,d.startAngle,d.endAngle,d.clockwise)}for(let e=1;e<r.length;e++){const n=l;l=r[e];const i=r[e+1];if(n.x===l.x&&n.y===l.y)continue;if(!i){t.lineTo(l.x,l.y);break}const o=to(l,s);let a=Math.sqrt((n.x-l.x)*(n.x-l.x)+(n.y-l.y)*(n.y-l.y)),c=0!==a?Math.atan2(n.x-l.x,n.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const u=o>0||0!==a?{x:h,y:d}:l;a=Math.sqrt((i.x-l.x)*(i.x-l.x)+(i.y-l.y)*(i.y-l.y)),c=0!==a?Math.atan2(i.x-l.x,i.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const p=o>0||0!==a?{x:h,y:d}:l;if(t.lineTo(u.x,u.y),o>0&&t.quadraticCurveTo(l.x,l.y,p.x,p.y),Kr(l)){const e=to(i,s),n=Math.sqrt((l.x-i.x)**2+(l.y-i.y)**2),r=0!==n?Math.atan2(l.x-i.x,l.y-i.y):0,o=Math.sin(r)*Math.min(e,n/2)+i.x,a=Math.cos(r)*Math.min(e,n/2)+i.y,c=Qr({x:p.x,y:p.y},{x:o,y:a},l.bulge);c&&t.arc(c.cx,c.cy,c.radius,c.startAngle,c.endAngle,c.clockwise)}}this.drawStroke(t,void 0)}contains(t,e){const{lineWidth:n}=this.state;return Zm(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:i,x2:s,y2:r}=this.state;return[this.fromEnd?.position||t?.position||{x:n,y:i},this.toEnd?.position||e?.position||{x:s,y:r}]}set path(t){const[e,n]=t,{from:i,to:s}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...i,position:e},to:{...s,position:n}})}get textBounds(){const t=this.drawPath;let e,n,i=0;for(let s=1;s<t.length;s++){const r=t[s-1],o=t[s],a=(r.x-o.x)*(r.x-o.x)+(r.y-o.y)*(r.y-o.y);a>i&&(i=Math.ceil(a),e=r,n=o)}let{paddingTop:s,paddingLeft:r,paddingRight:o,paddingBottom:a}=this.state;return a||=0,s||=0,r||=0,o||=0,{left:Math.min(e.x,n.x)+r,top:Math.min(e.y,n.y)+s,width:Math.max(Math.abs(e.x-n.x)-r-o,0),height:Math.max(Math.abs(e.y-n.y)-s-a,0)}}get decorators(){return this.app.isEditMode?["decotag"]:[]}}cg.getTipNeckPos=Jm,cg.containedInPath=Zm,cg.drawEndTips=tg,Tc.register("line",cg);const lg={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 hg extends(Xf(Pc)){is3dish(){return!0}render(t){const{cx:e,cy:n,rx:i,ry:s,startAngle:r,endAngle:o,anticlockwise:a}=this.state;t.beginPath(),t.ellipse(e,n,Math.abs(i),Math.abs(s),0,r||0,o||2*Math.PI,a),void 0!==r&&void 0!==o&&(t.lineTo(e,n),t.closePath())}get path(){const{cx:t,cy:e,rx:n,ry:i}=this.state;return[{x:t-n,y:e-i},{x:t+n,y:e-i},{x:t+n,y:e+i},{x:t-n,y:e+i}]}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:i,rx:s,ry:r}=this.state,o=(t-n)/(2*s-.5),a=(e-i)/(2*r-.5);return o*o+a*a<.25}outline(t){return function(t,e){const{cx:n,cy:i,rx:s,ry:r}=t.model,o=2*Math.PI*e,a=n+s*Math.cos(o),c=i+r*Math.sin(o);return t.toScene(a,c)}(this,t)}get anchors(){return function(t){const{left:e,top:n,width:i,height:s}=t.bounds,r=e+i/2,o=n+s/2;return[{name:"TOP",position:{x:r,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:r,y:n+s}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get nature(){return lg}}Tc.memoize(hg.prototype,"path",!1),Tc.register("ellipse",hg);const dg={object:{fill:"rgba(180,180,180,0.18)",stroke:"#888888",icon:"?",label:"object"},transport:{fill:"rgba(100,180,255,0.18)",stroke:"#3a78c8",icon:"⇄",label:"transport"},facility:{fill:"rgba(160,140,220,0.18)",stroke:"#6b4ec8",icon:"◫",label:"facility"},vehicle:{fill:"rgba(120,200,140,0.18)",stroke:"#3a8c5e",icon:"⊙",label:"vehicle"},region:{fill:"rgba(220,200,100,0.18)",stroke:"#a0892a",icon:"▢",label:"region"},path:{fill:"rgba(200,140,160,0.18)",stroke:"#a0506a",icon:"⌐",label:"path"},"3d-asset":{fill:"rgba(255,180,80,0.18)",stroke:"#c87a2a",icon:"◈",label:"3D asset"}},ug=[{type:"string",label:"placeholder-label",name:"placeholderLabel",description:'사용자에게 표시할 추가 라벨 (예: "Stocker A1")'},{type:"string",label:"hint",name:"placeholderHint",description:"구체화 시 참고 — 도면의 원본 식별자 / VLM 라벨 등"}];function pg(t,e,n,i,s){const{left:r,top:o,width:a,height:c}=e,l=Math.max(a,1),h=Math.max(c,1);t.save(),t.fillStyle=n.fill,t.fillRect(r,o,l,h),t.strokeStyle=n.stroke,t.lineWidth=1.5,t.setLineDash([4,3]),t.strokeRect(r,o,l,h),t.setLineDash([]),t.restore(),Math.min(l,h)>=24&&(t.save(),t.fillStyle=n.stroke,t.font=`bold ${Math.min(20,.4*Math.min(l,h))}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(n.icon,r+l/2,o+h/2),t.restore());const d=i?`${n.label}: ${i}`:n.label;h>=32&&(t.save(),t.fillStyle=n.stroke,t.font="10px Arial",t.textAlign="center",t.textBaseline="bottom",t.fillText(d,r+l/2,o+h-4),t.restore()),s&&h>=40&&(t.save(),t.fillStyle=n.stroke,t.font="9px Arial",t.textAlign="right",t.textBaseline="top",t.fillText(`hint: ${s}`,r+l-4,o+4),t.restore())}const fg={mutable:!1,resizable:!0,rotatable:!0,properties:[...ug,{type:"placeholder-convert",label:"",name:"_convert"}],help:"scene/component/placeholder"};class mg extends(Dc(Pc)){get nature(){return fg}render(t){const{placeholderLabel:e,placeholderHint:n}=this.state;pg(t,this.bounds,dg.object,e,n)}}Tc.register("placeholder",mg);const gg=["placeholder"];function yg(t,e=[]){return!!t&&(!!gg.includes(t)||e.includes(t))}const bg={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){const i=n[e+1];n[e+1]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},_g={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 vg extends Pc{is3dish(){return!0}get mutable(){return!0}get pathExtendable(){return!0}get cornerEditable(){return!0}get path(){return this.state.path??[]}set path(t){this.set("path",t)}contains(t,e){const n=this.path;let i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}get controls(){const t=this.path;return t.map((e,n)=>{const i=t[n+1>=t.length?0:n+1];return{x:(e.x+i.x)/2,y:(e.y+i.y)/2,handler:bg}})}get nature(){return _g}}Tc.memoize(vg.prototype,"controls",!1),Tc.register("polygon",vg);const xg=[];class wg extends(Xl(vg)){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 Fc.get(this.get("layout"))||Hc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){t&&t.parent!==this&&this.addComponent(t,{silent:!0})}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,s=t.parent;if(s){if(this===s)return;s.removeComponent(t,n||i)}const r=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,r),t.delegate_on(this),i?(s&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,r),t.trigger("added",this,t,r),delete t._silentAdd):n||t.trigger("added",this,t,r),this.root&&this.root.isReady&&t.invokeReady()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const s=this._components.splice(0,e);this._components=s.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||xg).indexOf(t)}size(){return(this._components||xg).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const s=this._components.splice(1);this._components=i.concat(s),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return nc(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const s=this.components[i].findAll(t,...e);s&&(n=n.concat(s))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return nc(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const s=this.bounds;i.x-=s.left,i.y-=s.top;const r=this.layout.capturables(this);for(let s=r.length-1;s>=0;s--){const o=r[s];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:s,width:r,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+r||a.y<s||a.y>s+o)return!1;a.x-=i,a.y-=s,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const s=i.capturePath(n,e);if(s)return s}return this.focusible&&this}render(t){"popup"!==this.position&&super.render(t)}postrender(t){if("popup"===this.position)return void super.postrender(t);const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:s,height:r}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,s,r),t.clip(),t.closePath()),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)||e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>Tc.memoize(wg.prototype,t,!1));const Mg={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){const i=n[e];n[e]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},Sg={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 kg extends cg{get pathExtendable(){return!0}get cornerEditable(){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 i=t[n],s=t[n+1];0==n&&e.push({x:i.x,y:i.y,handler:Mg}),e.push({x:(i.x+s.x)/2,y:(i.y+s.y)/2,handler:Mg}),n==t.length-2&&e.push({x:s.x,y:s.y,handler:Mg})}return e}get nature(){return Sg}}Tc.register("polyline",kg);const Ag={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 Eg extends cg{get pathExtendable(){return!1}get drawPath(){const t=this.path[0],e=this.path[1],{component:n,direction:i,boundaryPosition:s=t}=this.fromEnd||{},{component:r,direction:o,boundaryPosition:a=e}=this.toEnd||{},c=[s,a],l=[];s&&l.push(s);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:s.x,top:s.y,width:0,height:0};d=d||u;let p=r?.bounds;p&&(h=r.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 m=[u,f],g=u.left>f.left?f.left:u.left,y=u.top>f.top?f.top:u.top,b={left:g,top:y,width:u.left+u.width>f.left+f.width?u.left+u.width-g:f.left+f.width-g,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,k,A,E,C,T=0,P=0;d.left+d.width<p.left?(w=0,M=1,E=i,C=o,_=(d.left+d.width+p.left)/2,T=p.left-_):p.left+p.width<d.left&&(w=1,M=0,E=o,C=i,_=(d.left+p.width+p.left)/2,T=d.left-_),d.top+d.height<p.top?(x=0,S=1,k=i,A=o,v=(d.top+d.height+p.top)/2,P=p.top-v):p.top+p.height<d.top&&(x=1,S=0,k=o,A=i,v=(d.top+p.height+p.top)/2,P=d.top-v);const O=[];if(_&&T>P){let t,e,n;switch(C){case og:switch(E){case rg:O.push({x:_,y:c[w].y}),O.push({x:_,y:c[M].y});break;case og:t=m[w].top+m[w].height/2,e=t>c[M].y?Math.min(m[w].top,c[M].y):Math.max(m[w].top+m[w].height,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:c[M].y});break;case ig:case sg:e=E===sg?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:_,y:e}),O.push({x:_,y:c[M].y});break;default:return this.path}break;case rg:switch(E){case rg:e=c[w].y<c[M].y?Math.min(m[M].top,c[w].y):Math.max(m[M].top+m[M].height,c[w].y),n=e;break;case og:e=void 0!==v?v:c[w].y<c[M].y?b.top-.5*T:b.top+b.height+.5*T,n=e;break;case sg:e=void 0!==v?Math.max(v,c[w].y):b.top+b.height,n=e;break;case ig:e=v?Math.min(v,m[w].top):b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case sg:switch(E){case rg:e=c[w].y,n=c[w].y>c[M].y?c[w].y:m[M].top+m[M].height;break;case og:e=v?Math.max(v,m[M].top+m[M].height):b.top+b.height,n=e;break;case sg:e=b.top+b.height,n=e;break;case ig:e=v?Math.min(v,m[w].top):m[w].top,n=v?Math.max(v,m[M].top+m[M].height):m[M].top+m[M].height;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case ig:switch(E){case rg:e=c[w].y,n=c[w].y<c[M].y?c[w].y:m[M].top;break;case og:e=v?Math.min(v,m[M].top):b.top,n=e;break;case sg:e=void 0!==v?Math.max(v,c[w].y):c[w].y,n=void 0!==v?Math.min(v,c[M].y):c[M].y;break;case ig:e=b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;default:return this.path}l.push(...0===w?O:O.reverse())}else if(v){let t,e,n;switch(A){case ig:switch(k){case sg:O.push({x:c[x].x,y:v}),O.push({x:c[S].x,y:v});break;case ig:t=m[x].left+m[x].width/2,e=t>c[S].x?Math.min(m[x].left,c[S].x):Math.max(m[x].left+m[x].width,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case og:e=Math.min(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case rg:e=Math.max(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;default:return this.path}break;case sg:switch(k){case og:e=b.left,n=e;break;case rg:e=void 0!==_?Math.max(_,c[x].x):b.left+b.width,n=e;break;case ig:e=void 0!==_?_:c[x].x<c[S].x?b.left-.5*P:b.left+b.width+.5*P,n=e;break;case sg:e=c[x].x,n=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case rg:switch(k){case og:e=void 0!==_?Math.min(_,c[x].x):c[x].x,n=void 0!==_?Math.max(_,c[S].x):c[S].x;break;case rg:e=b.left+b.width,n=e;break;case ig:e=void 0!==_?Math.max(_,c[S].x):b.left+b.width,n=e;break;case sg:e=c[x].x,n=Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case og:switch(k){case og:e=b.left,n=e;break;case rg:e=void 0!==_?Math.max(_,c[x].x):c[x].x,n=void 0!==_?Math.min(_,c[S].x):c[S].x;break;case ig:e=b.left,n=e;break;case sg:e=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):c[x].x,n=Math.min(e,c[S].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;default:return this.path}l.push(...0===x?O:O.reverse())}else{let t,e;switch(i){case ig:switch(o){case ig:e=b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case sg: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 rg: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 og: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 sg:switch(o){case ig: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 sg:case rg:case og: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 og:switch(o){case ig: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 sg: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 rg: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 og: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 rg:switch(o){case ig: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 sg: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 rg:case og: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 i=n[e-1];return t.x!==i.x||t.y!==i.y}).filter((t,e,n)=>{if(0===e||e>=n.length-1)return!0;const i=n[e-1],s=n[e+1];return!(t.x===i.x&&t.x===s.x||t.y===i.y&&t.y===s.y)})}get nature(){return Ag}}Tc.register("ortholine",Eg);const Cg={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 Tg extends(Dc(Pc)){static get noimage(){return Tg.NOIMAGE||(Tg.NOIMAGE=new Image,Tg.NOIMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII="),Tg.NOIMAGE}dispose(){super.dispose(),this._offcanvas=null,this._image=null}render(t){const{left:e,top:n,width:i,height:s,isGray:r=!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(r&&this._offcanvas)t.drawImage(this._offcanvas,e,n,i,s);else try{t.drawImage(this._image,e,n,i,s)}catch(r){t.drawImage(Tg.noimage,e,n,i,s)}else!this.app.isViewMode&&t.drawImage(Tg.noimage,e,n,i,s)}get nature(){return Cg}get hasTextProperty(){return!1}async ready(){await super.ready();const{src:t}=this.state;if(!this._image&&t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((t,e)=>{this.prepare(()=>t(),t=>e(t))});e.track(`image:${t}`,"image",t,n)}else this.prepareIf(!0)}}prepare(t,e){const{src:n,crossOrigin:i}=this.state;if(n){this._image=new Image;try{i&&(this._image.crossOrigin=i),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 i=function(t,e,n){let i;try{i=t.getImageData(0,0,e,n)}catch(t){return Zi("Get Image Data Error: "+(t instanceof Error?t.message:String(t))),null}const s=i.data;for(let t=0;t<e*n*4;t+=4){const e=s[t],n=s[t+1],r=s[t+2],o=Math.floor((e+n+r)/3);i.data[t]=o,i.data[t+1]=o,i.data[t+2]=o}return i}(n,t,e);n.putImageData(i,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",Tg);class Pg extends(Vm(Dc(Tc))){is3dish(){return!0}prerender(){}}var Og,Dg,zg={},Ig={},Rg={};function jg(){if(Dg)return Ig;Dg=1,Object.defineProperty(Ig,"__esModule",{value:!0});var t=function(){if(Og)return Rg;Og=1,Object.defineProperty(Rg,"__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,i,s=0,r=function(t){for(var n=0,i=0;i<t;i++)e.charCodeAt(s>>3)&1<<(7&s)&&(n|=1<<i),s++;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(i=n,(n=r(l))!==a){if(n===c)break;if(n<h.length)i!==a&&h.push(h[i].concat(h[n][0]));else{if(n!==h.length)throw new Error("Invalid LZW code.");h.push(h[i].concat(h[i][0]))}o.push.apply(o,h[n]),h.length===1<<l&&l<12&&l++}else d();return o},t}();return Rg.SuperGifUtils=t,Rg}(),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 i=t.SuperGifUtils.byteToBitArr(n.stream.readByte());e.reserved=i.splice(0,3),e.disposalMethod=t.SuperGifUtils.bitsToNum(i.splice(0,3)),e.userInput=i.shift(),e.transparencyGiven=i.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 i=this.readSubBlocks();e.pixels=t.SuperGifUtils.lzwDecode(e.lzwMinCodeSize,i),e.interlaced&&(e.pixels=function(t,e){for(var n=new Array(t.length),i=t.length/e,s=function(i,s){var r=t.slice(s*e,(s+1)*e);n.splice.apply(n,[i*e,e].concat(r))},r=[0,4,2,1],o=[8,8,4,2],a=0,c=0;c<4;c++)for(var l=r[c];l<i;l+=o[c])s(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 Ig.SuperGifParser=e,Ig}var Lg,Fg,Ng={};var Hg=function(){if(Fg)return zg;Fg=1,Object.defineProperty(zg,"__esModule",{value:!0});var t=jg(),e=function(){if(Lg)return Ng;Lg=1,Object.defineProperty(Ng,"__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 Ng.SuperGifStream=t,Ng}(),n=function(){function n(t,e){var n=this;for(var i 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[i]=e[i];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,i=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 s=this.frame.getImageData(t.leftPos,t.topPos,t.width,t.height);t.pixels.forEach(function(t,n){t!==e.transparency&&(s.data[4*n+0]=i[t][0],s.data[4*n+1]=i[t][1],s.data[4*n+2]=i[t][2],s.data[4*n+3]=255)}),this.frame.putImageData(s,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 i=this;if(this.loadSetup(n)){var s=new XMLHttpRequest;s.open("GET",t,!0),"overrideMimeType"in s?s.overrideMimeType("text/plain; charset=x-user-defined"):"responseType"in s?s.responseType="arraybuffer":s.setRequestHeader("Accept-Charset","x-user-defined"),s.onloadstart=function(){i.initialized||i.init()},s.onload=function(){if(200===s.status){var t=s.response;t.toString().indexOf("ArrayBuffer")>0&&(t=new Uint8Array(t));var n=new e.SuperGifStream(t);setTimeout(function(){i.parseStream(n)},0)}else i.handleError("xhr - response")},s.onerror=function(){i.handleError("xhr")},s.send()}},n.prototype.load=function(t){this.loadURL(this.gifImgElement.src,t)},n}();return zg.SuperGif=n,zg}();const Bg={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 Gg extends Pg{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 Hg.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 Bg}get tagName(){return"div"}}Tc.register("gif-view",Gg);const Vg={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 Yg extends(Dc(Pc)){static get image(){return Yg.IMAGE||(Yg.IMAGE=new Image,Yg.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="),Yg.IMAGE}dispose(){super.dispose(),this.started=!1,delete this._audio}async ready(){super.ready(),this._audio=new Audio;const{src:t="",loop:e=!1,started:n=!1}=this.state;if(t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((e,n)=>{this._audio.addEventListener("canplay",()=>e(),{once:!0}),this._audio.addEventListener("error",()=>n(new Error(`Audio load failed: ${t}`)),{once:!0})});e.track(`audio:${t}`,"audio",t,n)}}this._audio.addEventListener("canplay",()=>{this.started&&this._audio.play()}),this.onchangeSrc(t),this.onchangeLoop(e),this.onchangeStarted(n)}render(t){const{left:e,top:n,width:i,height:s}=this.state;t.beginPath(),this.drawImage(t,Yg.image,e,n,i,s)}get nature(){return Vg}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 Zi(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",Yg);class Wg extends(Dc(Tc)){is3dish(){return!0}}Tc.register("text",Wg);const Ug=["refid","left","top","width","height","rotation","animation","zPos"];class $g extends Xm{isGroup(){return!0}is3dish(){return!0}get showMoveHandle(){return!1}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=Ug.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{});return super.set(n,void 0)}capture(t,e,n){const i=super.capture(t,e,n);if(i!==this)return i}set bounds(t){if(this.__MUTATING__)return void(super.bounds=t);const e=this.bounds,n=t.width/e.width,i=t.height/e.height;this.path=this.path.map(s=>({x:t.left+(s.x-e.left)*n,y:t.top+(s.y-e.top)*i})),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*i}})});else{const e=t.bounds,s=t.center,r={x:s.x*(1-n),y:s.y*(1-i)},o=e.width*(1-n),a=e.height*(1-i),c=-(r.x-o/2),l=-(r.y-a/2);t.bounds={left:e.left+c,top:e.top+l,width:e.width*n,height:e.height*i}}})}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($g.prototype,"bounds",!0),Tc.register("group",$g);const Xg={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 qg extends(Dc(Pc)){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,i=n.width/e.width,s=n.height/e.height;return"both"===this.model.fit?{x:i,y:s}:{x:Math.min(i,s),y:Math.min(i,s)}}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,i=this.refScale;t.translate(n.x,n.y),t.scale(i.x,i.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:i,height:s}=this.bounds;t.beginPath(),t.rect(e,n,i,s)}get nature(){return Xg}get hasTextProperty(){return!1}}Tc.memoize(qg.prototype,"ref",!1),Tc.memoize(qg.prototype,"refScale",!1),Tc.register("local-ref",qg);class Kg extends(Vm(Kl)){render(t){}is3dish(){return!0}get layout(){return Fc.get(this.get("layout"))||Nc}}const Qg={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 Zg extends Kg{dispose(){this._releaseRef(),super.dispose()}get nature(){return Qg}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){const i=(async()=>{this.__ref=await n.get(t,!0),this.__ref.target=this.element,this.__ref.fit(e),this.__ref.data=this.data})();this.root?.app?.loadTracker?.track(`ref:${t}`,"ref-board",t,i);try{await i}catch(t){Zi(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",Zg);const Jg="center-middle",ty={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",Jg,"right-middle","left-bottom","center-bottom","right-bottom","auto"]}},{type:"string",label:"title",name:"text"},{type:"data",label:"value",name:"value"},{type:"string",label:"container-ref",name:"containerRef",placeholder:"PopupContainer id (same board)"},{type:"textarea",label:"html-template",name:"htmlTemplate",property:{language:"html"}},{type:"string",label:"anchor-ref",name:"anchorRef",placeholder:"component id (3D-tracked anchor)"},{type:"select",label:"anchor-pin",name:"anchorPin",property:{options:[{display:"Top",value:"top"},{display:"Center",value:"center"},{display:"Bottom",value:"bottom"}]}},{type:"number",label:"anchor-offset-x",name:"anchorOffsetX"},{type:"number",label:"anchor-offset-y",name:"anchorOffsetY"},{type:"number",label:"anchor-offset-z",name:"anchorOffsetZ"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup"};class ey extends(Dc(Pc)){static get image(){return ey._image||(ey._image=new Image,ey._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"),ey._image}async ready(){await super.ready(),this.show&&this.onchangeShow(!0)}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,ey.image,e,n,i,s)}onchange(t,e){"value"in t?this.show?this.onchangeShow(!0):this.show=!0:"show"in t&&this.onchangeShow(this.show)}onchangeShow(t){if(this.app.isEditMode)return;(this.getState("board")||this.getState("containerRef")||this.getState("htmlTemplate"))&&(t?this.openPopup(this.value):this.hidePopup())}openPopup(t,e){if(this.app.isEditMode)return;const n=this.getState("anchorRef"),i=n&&this.rootModel?.findById?this.rootModel.findById(n):void 0;ap.show(this,this.getState("board"),{origin:this.getState("origin")||Jg,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,containerRef:this.getState("containerRef"),htmlTemplate:this.getState("htmlTemplate"),anchor:i,anchorPin:this.getState("anchorPin")||"top",anchorOffsetX:this.getState("anchorOffsetX")??0,anchorOffsetY:this.getState("anchorOffsetY")??0,anchorOffsetZ:this.getState("anchorOffsetZ")??0,constantSize:this.getState("constantSize")??!0,tether:this.getState("tether")??!1,offScreen:this.getState("offScreen")||"hide",...e})}hidePopup(){ap.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 ty}}Tc.register("popup",ey);const ny={mutable:!1,resizable:!0,rotatable:!1,properties:[{type:"layout",label:"layout",name:"layoutOption"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"billboard",name:"billboard"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup-container"};class iy extends Xm{get nature(){return ny}isPopupContainer(){return!0}}Tc.register("popup-container",iy);class sy 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 i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}}Tc.register("path",sy);const ry={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 oy extends Pc{is3dish(){return!0}contains(t,e){const{x1:n,y1:i,x2:s,y2:r,x3:o,y3:a}=this.state,c=[n,i,s,r,o,a];let l=!1;for(let n=0;n<c.length;n+=2){const i=(n+2)%c.length,s=c[n],r=c[n+1],o=c[i+1];r>e!=o>e&&t<(c[i]-s)*(e-r)/(o-r)+s&&(l=!l)}return l}get mutable(){return!0}get path(){const{x1:t,y1:e,x2:n,y2:i,x3:s,y3:r}=this.state;return[{x:t,y:e},{x:n,y:i},{x:s,y:r}]}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 ry}}Tc.memoize(oy.prototype,"path",!1),Tc.register("triangle",oy);const ay={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"}],help:"scene/component/donut"},cy={ondragmove:function(t,e,n){let{cx:i,rx:s}=n.model;s=Math.abs(s);let r=(n.fromParent(t.x,t.y).x-i)/s*100;r=r>=100||r<=-100?100:Math.abs(r),n.set({ratio:r})}};class ly extends hg{is3dish(){return!0}render(t){let{ratio:e=50,cx:n,cy:i,rx:s,ry:r,startAngle:o,endAngle:a,anticlockwise:c}=this.state;s=Math.abs(s),r=Math.abs(r),t.beginPath(),t.ellipse(n,i,s,r,0,o||0,a||2*Math.PI,c),t.moveTo(n+s/100*e,i),t.ellipse(n,i,s/100*e,r/100*e,0,o||0,a||2*Math.PI,!0)}contains(t,e){let{cx:n,cy:i,rx:s,ry:r,ratio:o}=this.state;s=Math.abs(s),r=Math.abs(r);const a=(t-n)/(2*s-.5),c=(e-i)/(2*r-.5),l=(t-n)/(s/100*o*2-.5),h=(e-i)/(r/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:i}=this.state;return n=Math.abs(n),[{x:t+n/100*i,y:e,handler:cy}]}get nature(){return ay}}Tc.memoize(ly.prototype,"controls",!1),Tc.register("donut",ly);const hy={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"},dy={ondragmove:function(t,e,n){const{cy:i,ry:s}=n.model;let r=(n.fromParent(t.x,t.y).y-i)/s*100+100;r>=100?r=100:r<=0&&(r=0),n.set({ratio:r})}};class uy extends hg{is3dish(){return!0}render(t){const{ratio:e=30,wing:n=5,cx:i,cy:s,rx:r,ry:o}=this.state;if(n<3)return;const a=1.5707963267948966,c=2*Math.PI/n,l=r-e/100*r,h=o-e/100*o;t.save(),t.beginPath(),t.translate(i,s),t.moveTo(r*Math.cos(-a),o*Math.sin(-a)),t.lineTo((r-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(r*Math.cos(c*e-a),o*Math.sin(c*e-a)),t.lineTo((r-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:i}=this.state;return[{x:t,y:e-n+n*(i/100),handler:dy}]}get nature(){return hy}}Tc.memoize(uy.prototype,"controls",!1),Tc.register("star",uy);const py={mutable:!1,resizable:!1,rotatable:!1,properties:[]};class fy extends(Xf(Pc)){is3dish(){return!1}isDescendible(){return!1}render(t){const{cx:e,cy:n,anticlockwise:i}=this.state,s=this.app?.scale||1;t.beginPath(),t.scale(1/s,1/s),t.ellipse(e,n,Math.abs(fy.RADIUS),Math.abs(fy.RADIUS),0,0,2*Math.PI,i),t.scale(s,s),t.closePath()}get path(){const{cx:t,cy:e}=this.state;return[{x:t-fy.RADIUS,y:e-fy.RADIUS},{x:t+fy.RADIUS,y:e-fy.RADIUS},{x:t+fy.RADIUS,y:e+fy.RADIUS},{x:t-fy.RADIUS,y:e+fy.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:i}=this.state,s=(t-n)/(2*fy.RADIUS-.5),r=(e-i)/(2*fy.RADIUS-.5);return s*s+r*r<.25}outline(t){const{cx:e,cy:n}=this.state;return this.toScene(e,n)}get nature(){return py}}fy.RADIUS=5,Tc.memoize(fy.prototype,"path",!1),Tc.register("node",fy);class my extends pu{getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds,i=this.component.state.depth||.5*Math.min(t,n),s=.15*Math.min(t,n,i),r=new R(1,1,1,4,s/Math.min(t,n,i));r.scale(t,i,n),this.object3d.geometry=r,this.object3d.material=new e.MeshStandardMaterial({color:"#5090d0",transparent:!0,opacity:.35,roughness:.6,metalness:.1,side:e.FrontSide,depthWrite:!1}),this.object3d.visible=!!this.component.app?.isEditMode}updateAlpha(){const t=this.object3d.material;t&&(t.opacity=this.component.app?.isEditMode?.35:0)}updateHidden(){this.object3d.visible=!!this.component.app?.isEditMode&&!this.component.state.hidden}updateDimension(){const{width:t,height:e}=this.component.bounds,n=this.component.state.depth||.5*Math.min(t,e);this.object3d.geometry.computeBoundingBox();const i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}updateFillStyle(){}updateStrokeStyle(){}updateText(){}clear(){return eu(this.object3d),super.clear()}}const gy="data:image/svg+xml;base64,"+btoa('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="#5090d0">\n <path d="M32 20a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm0 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12z"/>\n <path d="M55.4 27.2l-3.6-.6c-.4-1.2-.8-2.4-1.4-3.4l2.2-3c.6-.8.4-2-.2-2.6l-3-3c-.8-.6-1.8-.8-2.6-.2l-3 2.2c-1.2-.6-2.2-1-3.4-1.4l-.6-3.6c-.2-1-1-1.6-2-1.6h-4.2c-1 0-1.8.6-2 1.6l-.6 3.6c-1.2.4-2.4.8-3.4 1.4l-3-2.2c-.8-.6-2-.4-2.6.2l-3 3c-.6.8-.8 1.8-.2 2.6l2.2 3c-.6 1.2-1 2.2-1.4 3.4l-3.6.6c-1 .2-1.6 1-1.6 2v4.2c0 1 .6 1.8 1.6 2l3.6.6c.4 1.2.8 2.4 1.4 3.4l-2.2 3c-.6.8-.4 2 .2 2.6l3 3c.8.6 1.8.8 2.6.2l3-2.2c1.2.6 2.2 1 3.4 1.4l.6 3.6c.2 1 1 1.6 2 1.6h4.2c1 0 1.8-.6 2-1.6l.6-3.6c1.2-.4 2.4-.8 3.4-1.4l3 2.2c.8.6 2 .4 2.6-.2l3-3c.6-.8.8-1.8.2-2.6l-2.2-3c.6-1.2 1-2.2 1.4-3.4l3.6-.6c1-.2 1.6-1 1.6-2v-4.2c0-1-.6-1.8-1.6-2z"/>\n</svg>');class yy extends(Dc(Tc)){static get icon(){return yy._defaultIcon||(yy._defaultIcon=new Image,yy._defaultIcon.src=gy),yy._defaultIcon}get serviceName(){}get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new my(this)}render(t){if(this.app?.isViewMode)return;const{left:e,top:n,width:i,height:s}=this.bounds,r=this.constructor.icon;t.beginPath(),t.globalAlpha=.6,this.drawImage(t,r,e,n,i,s),t.globalAlpha=1}added(t){super.added(t);const e=this.serviceName;e&&(this._registeredRoot=this.root,this._registeredRoot?.registerService?.(e,this))}removed(t){const e=this.serviceName;e&&this._registeredRoot&&(this._registeredRoot.unregisterService?.(e),this._registeredRoot=void 0),super.removed(t)}get controls(){return[]}}function by(t){return class extends t{animOnValueChange(t,e=!1,n){if(t==this._lastValue)return;if(this.root?.app?.suppressAnimations)return this._lastValue=t,this._anim_alpha=0,void this.invalidate();let i;i=e?t-(Number(n)||0):t-(this._lastValue||0),this._lastValue=t,this._anim_alpha=-i,this.animate({step:t=>{this._anim_alpha=i*(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=Ur(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(wi(t)))}}}function _y(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 vy(t){var e;return(e=class extends t{is3dish(){return!0}get hasTextProperty(){return!1}get capturable(){return!1}render(t){}}).raycastTargetDefault=!1,e.requires3d=!0,e}const xy="$base_url",wy=[{type:"gltf-preset",label:"preset",name:"preset"},{type:"gltf-selector",label:"url",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:xy,defaultStorage:"3d-model",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0,category:"application"},observe:function(t){const e=this.parentNode?.querySelector("[name=gltfInfo]");e&&(e.src=t);const n=this.parentNode?.querySelector("[name=fillStyleTargets]");n&&(n.src=t);const i=this.parentNode?.querySelector("[name=playTargets]");i&&(i.src=t)}},{type:"gltf-info",label:"",name:"gltfInfo",readonly:!0,property:{action:(t,e)=>{t._ratioLocking=!0;try{t.set(e)}finally{t._ratioLocking=!1}}},editor:{fullwidth:!0}},{type:"gltf-fill-targets",label:"fill-targets",name:"fillStyleTargets",editor:{fullwidth:!0}},{type:"gltf-play-targets",label:"play-targets",name:"playTargets",editor:{fullwidth:!0}}];function My(t){return class extends t{constructor(){super(...arguments),this._snapshotLoading=!1,this._ratioLocking=!1}is3dish(){return!0}get hasTextProperty(){return!1}get controls(){return[]}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath();const r=this._topViewSnapshot;if(r)return void t.drawImage(r,e,n,i,s);this._ensureTopViewSnapshot(),t.rect(e,n,i,s),t.fillStyle="#f0f0f0",t.fill(),t.strokeStyle="#999",t.lineWidth=1,t.stroke();const o=this.getState("src"),a=o&&o.split("/").pop()?.replace(/\.[^.]+$/,"")||"GLTF",c=Math.max(10,.12*Math.min(i,s));t.fillStyle="#666",t.font=`${c}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(a,e+i/2,n+s/2,.9*i)}onchange(t,e){super.onchange?.(t,e),"src"in t&&(this._topViewSnapshot=void 0)}_ensureTopViewSnapshot(){if(this._snapshotLoading)return;const t=this.getState("src");if(!t)return;const e=vu.getTopViewCache(t);if(e)return this._topViewSnapshot=e,void this.invalidate();this._snapshotLoading=!0;const n=this.app.url(t);vu.loadGLTF(n).then(e=>{if(this._snapshotLoading=!1,this.getState("src")!==t)return;const n=vu.getTopViewCache(t);if(n)return this._topViewSnapshot=n,void this.invalidate();const i=vu.renderTopView(e.scene);vu.setTopViewCache(t,i),this._topViewSnapshot=i,this.invalidate()}).catch(()=>{this._snapshotLoading=!1})}buildRealObject(){return new vu(this)}get source(){return this.getState("src")}set source(t){this.setState("src",t)}get play(){return!1!==this.getState("play")}set play(t){this.setState("play",t)}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 playTargets(){return this.getState("playTargets")}set playTargets(t){this.setState("playTargets",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??[]}set dimension(t){const{width:e=1,height:n=1,depth:i=1}=t;this.setState({width:e,height:n,depth:i}),this.realObject?.updateDimension()}_applyRatioLock(t){if(!("width"in t||"height"in t||"depth"in t))return t;const e=this.state.width||1,n=this.state.height||1,i=this.state.depth||1,s=vf([(t.width??e)/e,(t.height??n)/n,(t.depth??i)/i]);return s?{...t,width:Math.round(e*s),height:Math.round(n*s),depth:Math.round(i*s)}:t}set(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.set(t)}finally{this._ratioLocking=!1}}setState(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.setState(t)}finally{this._ratioLocking=!1}}}}function Sy(t){return function(e){return Array.isArray(t)?t.forEach(t=>{Tc.register(t,e)}):Tc.register(t,e),e}}function ky(t){return!!t&&"function"==typeof t.capacity&&"function"==typeof t.available}function Ay(t){if(ky(t)){const e=t.capacity(),n=t.available();return{capacity:e,available:n,isFull:0===n}}if("function"==typeof t?.slotIds){const e=t.slotIds().length,n="function"==typeof t.emptySlotIds?t.emptySlotIds().length:e;return{capacity:e,available:n,isFull:0===n}}const e=t?.state?.capacity,n=Array.isArray(t?.state?.data)?t.state.data.length:0;if("number"==typeof e){const t=Math.max(0,e-n);return{capacity:e,available:t,isFull:0===t}}return{capacity:1/0,available:1/0,isFull:!1}}class Ey{constructor(){this.wasFull=!1,this.availableListeners=[],this.fullListeners=[]}notify(t){const e=0===t;if(e&&!this.wasFull){this.wasFull=!0;for(const t of this.fullListeners)try{t()}catch(t){}}else if(!e&&this.wasFull){this.wasFull=!1;for(const t of this.availableListeners)try{t()}catch(t){}}}onAvailable(t){return this.availableListeners.push(t),()=>{const e=this.availableListeners.indexOf(t);e>=0&&this.availableListeners.splice(e,1)}}onFull(t){return this.fullListeners.push(t),()=>{const e=this.fullListeners.indexOf(t);e>=0&&this.fullListeners.splice(e,1)}}dispose(){this.availableListeners=[],this.fullListeners=[]}}function Cy(t,e){if(!t||!e)return()=>{};if("function"!=typeof t.pauseEmit||"function"!=typeof t.resumeEmit)return()=>{};if("function"!=typeof e.onFull||"function"!=typeof e.onAvailable)return()=>{};const n=e.onFull(()=>t.pauseEmit()),i=e.onAvailable(()=>t.resumeEmit());return Ay(e).isFull&&t.pauseEmit(),()=>{n?.(),i?.()}}class Ty{constructor(t,e=1,n="horizontal"){this.owner=t,this.itemSpacing=e,this.axis=n}positionAt(t,e,n,i){const s=e.maxCount??1/0;if(t<0||t>=s)return null;const r=this.owner?.state?.width??0,o=this.owner?.state?.height??0,a=i?.state?.width??0,c=i?.state?.height??0;return"horizontal"===this.axis?{x:t*this.itemSpacing,y:Math.max(0,(o-c)/2),z:0}:{x:Math.max(0,(r-a)/2),y:t*this.itemSpacing,z:0}}capacity(t){return t.maxCount??1/0}}function Py(t,e,n,i,s,r,o){const a=n.w,c=n.h,l=i.w,h=i.h,d=i.d,u=[],p=l+s,f=h+s,m=Math.max(1,Math.floor((a+s)/p)),g=Math.max(1,Math.floor((c+s)/f)),y=m*g,b=r&&r>0?Math.floor(r):4;if("row"===t||"column"===t){const n=o?.advanceAlongX??!1,i=o?.reverse??!1,s=n?m:g,r=n?g:m,l=(t,e,i)=>((t,e,n)=>u.push({x:-a/2+(t+.5)*p,y:n*d+d/2,z:-c/2+(e+.5)*f}))(n?t:e,n?e:t,i);let h=0;for(let n=0;n<s&&h<e;n++){const o=i?s-1-n:n;if("column"===t)for(let t=0;t<r&&h<e;t++)for(let n=0;n<b&&h<e;n++)l(o,t,n),h++;else for(let t=0;t<b&&h<e;t++)for(let n=0;n<r&&h<e;n++)l(o,n,t),h++}return u}if("pyramid"===t){let t=e,n=0;for(;t>0;){const e=Math.max(1,m-n),i=Math.max(1,g-n),s=e*i,o=Math.min(t,s);for(let t=0;t<o;t++){const s=t%e,r=Math.floor(t/e),o=-a/2+(s+(m-e)/2+.5)*p,l=-c/2+(r+(g-i)/2+.5)*f;u.push({x:o,y:n*d+d/2,z:l})}if(t-=o,n++,1===e&&1===i){for(let e=0;e<t;e++)u.push({x:0,y:(n+e)*d+d/2,z:0});break}if(r&&n>=r)break}return u}if("pile"===t){const t=t=>(43758.5453*Math.sin(12.9898*t)%1+1)%1;for(let n=0;n<e;n++){const e=Math.floor(n/y),i=n%y,s=i%m,o=Math.floor(i/m),g=(t(2*n)-.5)*l*.2,b=(t(2*n+1)-.5)*h*.2,_=-a/2+(s+.5)*p+g,v=-c/2+(o+.5)*f+b;if(u.push({x:_,y:e*d+d/2,z:v}),r&&e>=r-1&&i===y-1)break}return u}for(let n=0;n<e;n++){const e=Math.floor(n/y);if(r&&e>=r)break;const i=n%y,s=i%m,o=Math.floor(i/m);let l=-a/2+(s+.5)*p;const h=-c/2+(o+.5)*f;"staggered"===t&&e%2==1&&(l+=p/2),u.push({x:l,y:e*d+d/2,z:h})}return u}class Oy{constructor(t,e={}){this.pattern=t,this.defaults=e}layout(t,e,n,i={}){const s=i.gap??this.defaults.gap??0,r=i.heightLimit??this.defaults.heightLimit,o=i.fill??this.defaults.fill;return Py(this.pattern,t,e,n,s,r,o).map(t=>({position:t}))}}class Dy{constructor(t,e,n={}){this.cols=t,this.rows=e,this.defaults=n}layout(t,e,n,i={}){const s=Math.max(1,this.cols),r=Math.max(1,this.rows),o=s*r,a=i.gap??this.defaults.gap??0,c=n.w+a,l=n.h+a,h=[];for(let e=0;e<t;e++){const t=Math.floor(e/o),i=e%o,a=i%s,d=Math.floor(i/s);h.push({position:{x:(a-(s-1)/2)*c,z:(d-(r-1)/2)*l,y:t*n.d+n.d/2}})}return h}}class zy{constructor(t=.1,e=!1,n=!1){this.gapRatio=t,this.fillFromFar=e,this.sliceFirst=n}grid(t,e){const n=e.w*this.gapRatio,i=e.h*this.gapRatio;return{cols:Math.max(1,Math.floor((t.w-n)/(e.w+n))),rows:Math.max(1,Math.floor((t.h-i)/(e.h+i))),pitchX:e.w+n,pitchZ:e.h+i}}capacity(t,e,n){const{cols:i,rows:s}=this.grid(t,e);return i*s*Math.max(1,Math.floor(n))}layout(t,e,n,i={}){const{cols:s,rows:r,pitchX:o,pitchZ:a}=this.grid(e,n),c=n.d+n.d*this.gapRatio,l=null!=i.heightLimit?Math.max(1,Math.floor(i.heightLimit)):1/0,h=Number.isFinite(l),d=this.sliceFirst&&h,u=s*r,p=s*(h?l:1),f=s*r*(h?l:t),m=Math.min(t,f),g=[];for(let t=0;t<m;t++){let e,i,l;if(d){const n=Math.floor(t/p),r=t%p;e=r%s,l=Math.floor(r/s),i=n}else{l=Math.floor(t/u);const n=t%u;e=n%s,i=Math.floor(n/s)}this.fillFromFar&&(i=r-1-i),g.push({position:{x:(e-(s-1)/2)*o,z:(i-(r-1)/2)*a,y:l*c+n.d/2}})}return g}}function Iy(t,e,n,i=0){for(let s=0;s<e.length;s++){const r=e[s],o=n[s];r&&o&&(r.parent!==t&&t.attach(r),r.position.set(o.position.x,i+o.position.y,o.position.z),o.rotation?r.quaternion.set(o.rotation.x,o.rotation.y,o.rotation.z,o.rotation.w):r.quaternion.identity())}}function Ry(t,e,n,i=.12){const s=e.left+e.width/2,r=e.top+e.height/2,o=Math.min(n.w,n.h)*i,a=new Map;for(const e of t){const t=`${Math.round(e.position.x)},${Math.round(e.position.z)}`;let i=a.get(t);i||(i={x:s+e.position.x-n.w/2+o,y:r+e.position.z-n.h/2+o,w:n.w-2*o,h:n.h-2*o,count:0},a.set(t,i)),i.count++}return[...a.values()]}function jy(t){return{id:t?.state?.id??t?.id??t?.refid,type:t?.state?.type??t?.type}}const Ly=new e.Euler;function Fy(t,n){Ly.setFromQuaternion(new e.Quaternion(n.x,n.y,n.z,n.w),"YXZ"),t.rotationX=Ly.x,t.rotation=-Ly.y,t.rotationY=Ly.z}const Ny="_transferSlotId",Hy=new Set(["left","top","width","height","depth","zPos","rotation","rotationX","rotationY","rotationZ","scale","translate","material3d","fillStyle","strokeStyle","lineWidth","lineDash","alpha","opacity","hidden","text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline","shadow","border","cssText","object3d","_realObject","refid","id"]);function By(t){return class extends t{async ready(){await super.ready();const t=this.state?.data;Array.isArray(t)&&0===this._items.length&&!this.isRecordStorage&&this._reconcileItems(t)}set data(t){if(Array.isArray(t)){if(this.isRecordStorage){const e=this.setState;return void("function"==typeof e&&e.call(this,{data:t}))}this._reconcileItems(t)}else this.setState?.({data:t})}get data(){if(this.isRecordStorage)return this.state?.data??[];const t=this._exportSlotRecords();return 0===t.length?this.state?.data:t}_reconcileItems(t){const e=new Map;for(const n of t){const t=this._recordKey(n);t&&e.set(t,n)}const n=new Map;for(const t of this._items){const e=t[Ny];null!=e&&n.set(String(e),t)}for(const[t,i]of n)if(!e.has(t)){try{this.removeItem(i,!0)}catch{}try{i?.dispose?.()}catch{}}for(const[t,i]of e){if(n.has(t))continue;if(null==i.itemId)continue;const e=this._createItemFromRecord(i);if(e){e[Ny]=t;try{this.handoverIn(e)}catch{}}}for(const[t,i]of e){const e=n.get(t);if(e&&(i.itemState&&"function"==typeof e.setState))try{e.setState(i.itemState)}catch{}}}_exportSlotRecords(){const t=this.slotIds?.()??[],e=[],n=new Map,i=[];for(const t of this._items){const e=t[Ny];null!=e?n.set(String(e),t):i.push(t)}for(const i of t){const t=n.get(i)??null;e.push(this._slotRecordOf(i,t))}for(const t of i)e.push(this._slotRecordOf("",t));for(const[i,s]of n)t.includes(i)||e.push(this._slotRecordOf(i,s));return e}_recordKey(t){return t.slotId??t.cellId??""}_slotRecordOf(t,e){if(!e)return{slotId:t,itemId:null};const n=e?.state?.id;return{slotId:t,itemId:null!=n?String(n):null,itemType:e?.state?.type,itemState:this._extractItemState(e)}}_extractItemState(t){const e=t?.state;if(!e||"object"!=typeof e)return;const n=this._businessFields?.();if(Array.isArray(n)){if(0===n.length)return;const t={};for(const i of n)i in e&&void 0!==e[i]&&(t[i]=e[i]);return Object.keys(t).length>0?t:void 0}const i={};for(const t of Object.keys(e))Hy.has(t)||t.startsWith("_")||(i[t]=e[t]);return Object.keys(i).length>0?i:void 0}_businessFields(){return null}_createItemFromRecord(t){const e=t.itemType??t.type;if(!e)return null;try{const n=Tc.register?.(e);if(n&&"function"==typeof n){return new n({type:e,...t.itemState??{}})}}catch{}return null}}}class Gy{positionAt(t,e,n){return 0!==t?null:e.localPosition??{x:0,y:0,z:0}}capacity(t){return 1}}const Vy=new Gy,Yy=[{id:"__default__",maxCount:1/0}];function Wy(t){var n;return n=class extends t{get slots(){return[]}get arrangementStrategy(){return Vy}canReceive(t,e){const n=null!==this.findSlot(t);return Iu.log({role:"target",contract:"canReceive",component:this,args:{carrier:jy(t)},result:n}),n}findSlot(t){const e=this.slots.length?this.slots:Yy;for(const n of e){if(n.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!n.allowedTypes.includes(e))continue}const e=n.maxCount??this.arrangementStrategy.capacity(n),i=this._countOccupied(n.id);if(!(i>=e))return Iu.log({role:"target",contract:"findSlot",component:this,args:{carrier:jy(t)},result:{slotId:n.id,occupied:i,max:e}}),n}return Iu.log({role:"target",contract:"findSlot",component:this,args:{carrier:jy(t)},result:null}),null}acceptanceRotation(t,e){}deliveryWorldRotation(t){const n=this.acceptanceRotation?.(t);if(!n)return;const i=this._realObject?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new e.Quaternion;i.getWorldQuaternion(s);const r=new e.Quaternion(n.x,n.y,n.z,n.w);return s.clone().multiply(r)}deliveryWorldPosition(t){const n=this._realObject,i=n?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new e.Vector3;i.getWorldPosition(s);const r=this._receivingSurfaceLocalY();if(null!==r){const t=new e.Vector3(0,r,0);return i.localToWorld(t),{x:s.x,y:t.y,z:s.z}}return{x:s.x,y:s.y,z:s.z}}attachPointFor(t){const e=t?.[Ny];if(!e)return null;const n=this.slots.find(t=>t.id===e);return n?{position:n.localPosition??{x:0,y:0,z:0},rotation:n.localRotation??{x:0,y:0,z:0},slotId:n.id}:null}placementFor(t,e={}){const n=t&&"object"==typeof t&&"state"in t?t:void 0,i=n?n.state??{}:t??{},s={width:Number(i.width)||0,height:Number(i.height)||0,depth:Number(i.depth)||0},r=e.slot??this.slots.find(t=>{const e=t.maxCount??this.arrangementStrategy.capacity(t);return this._countOccupied(t.id)<e});if(!r)return null;const o=e.index??this._countOccupied(r.id),a=e.occupantCount??o,c=this.arrangementStrategy.positionAt(o,r,a,n??{state:{...s}});if(!c)return null;const l=Number(this.state?.width)||0,h=Number(this.state?.height)||0,d=c.x+s.width/2-l/2,u=c.y+s.height/2-h/2,p=this._realObject,f=p?.placementMode??"floor",m="space"===f?0:"inverted"===f?-s.depth/2:s.depth/2,g=this._receivingSurfaceLocalY();let y;y=null!==g?g+m:r.localPosition&&Number.isFinite(r.localPosition.z)?r.localPosition.z+m:m-(p?.geometricOffsetY??0);const b=this.acceptanceRotation?.(n??s,r)??void 0;return b?{position:{x:d,y:y,z:u},rotation:b}:{position:{x:d,y:y,z:u}}}_zPosFromSeatY(t,e,n){const i=this._realObject,s=i?.receivingSurfaceY??0,r=!(!n.localPosition||!Number.isFinite(n.localPosition.z));if(0===s&&!r)return null;const o=Number(e)||0,a=i?.placementMode??"floor";return t-("space"===a?0:"inverted"===a?-o/2:o/2)+(i?.geometricOffsetY??0)-s}_receivingSurfaceLocalY(){const t=this._realObject,e=t?.receivingSurfaceY;return"number"!=typeof e||0===e?null:e-(t.geometricOffsetY??0)}_countOccupied(t){const e=this._items;if(e)return e.filter(e=>e?.[Ny]===t).length;const n=this.components;return n?n.filter(e=>e.parent===this&&e[Ny]===t).length:0}},n.__hasCapacity=!0,n}function Uy(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return[];const o="number"==typeof t.rotation?t.rotation:0,a=Math.cos(o),c=Math.sin(o),l=n+s/2,h=i+r/2,d="inbound"===e?-1:1;return[{lx:-s/2,lz:0,odx:-1,odz:0},{lx:s/2,lz:0,odx:1,odz:0},{lx:0,lz:-r/2,odx:0,odz:-1},{lx:0,lz:r/2,odx:0,odz:1}].map(t=>{var e,n;return{worldPos:(e=t.lx,n=t.lz,{x:l+e*a-n*c,z:h+e*c+n*a}),direction:{x:d*(t.odx*a-t.odz*c),z:d*(t.odx*c+t.odz*a)},halfSpan:0!==t.odx?r/2:s/2}})}function $y(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return{inbounds:[],outbounds:[]};const o="number"==typeof t.rotation?t.rotation:0,a=e??"reverse"===t.status,c="vertical"===t.orientation||"horizontal"!==t.orientation&&s<r,l=n+s/2,h=i+r/2,d=c?r/2:s/2,u=c?0:1,p=c?1:0,f=Math.cos(o),m=Math.sin(o),g=(t,e)=>({x:l+t*f-e*m,z:h+t*m+e*f}),y=c?{lx:0,lz:-d}:{lx:-d,lz:0},b=c?{lx:0,lz:d}:{lx:d,lz:0},_=g(y.lx,y.lz),v=g(b.lx,b.lz),x={x:u*f-p*m,z:u*m+p*f},w=Math.hypot(x.x,x.z)||1,M={x:x.x/w,z:x.z/w},S={x:-M.x,z:-M.z},k=(c?s:r)/2;return a?{inbounds:[{worldPos:v,direction:S,halfSpan:k}],outbounds:[{worldPos:_,direction:S,halfSpan:k}]}:{inbounds:[{worldPos:_,direction:M,halfSpan:k}],outbounds:[{worldPos:v,direction:M,halfSpan:k}]}}function Xy(t){const e=t.left??0,n=t.top??0,i=t.width??0,s=t.height??0;if(i<=0||s<=0)return null;const r="number"==typeof t.rotation?t.rotation:0,o="vertical"===t.orientation||"horizontal"!==t.orientation&&i<s,a=e+i/2,c=n+s/2,l=o?s/2:i/2,h=Math.cos(r),d=Math.sin(r),u=(t,e)=>({x:a+t*h-e*d,z:c+t*d+e*h});return{start:o?u(0,-l):u(-l,0),end:o?u(0,l):u(l,0)}}function qy(t){const e=t.cx??0,n=t.cy??0,i=Math.abs(t.rx??100),s=Math.abs(t.ry??100),r=t.ratio??50,o=(i+i*r/100)/2,a=(s+s*r/100)/2,c=t.startAngle??0,l=t.endAngle??Math.PI/2,h="reverse"===t.status;if(i<=0||s<=0)return{inbounds:[],outbounds:[]};const d={x:e+o*Math.sin(c),z:n-a*Math.cos(c)},u={x:e+o*Math.sin(l),z:n-a*Math.cos(l)},p={x:Math.cos(c),z:Math.sin(c)},f={x:Math.cos(l),z:Math.sin(l)};return h?{inbounds:[{worldPos:u,direction:{x:-f.x,z:-f.z}}],outbounds:[{worldPos:d,direction:{x:-p.x,z:-p.z}}]}:{inbounds:[{worldPos:d,direction:p}],outbounds:[{worldPos:u,direction:f}]}}function Ky(t){const e=$y(t),n=e.outbounds[0];if(!n)return{inbounds:Uy(t,"inbound"),outbounds:[]};const i=Uy(t,"inbound").filter(t=>{const e=t.worldPos.x-n.worldPos.x,i=t.worldPos.z-n.worldPos.z;return Math.hypot(e,i)>1}),s=n.direction,r=[];for(const t of i){const e=t.direction.x*s.x+t.direction.z*s.z;if(Math.abs(e)>=.1)continue;const n=t.direction.x+s.x,i=t.direction.z+s.z,o=Math.hypot(n,i)||1;r.push({worldPos:t.worldPos,direction:{x:n/o,z:i/o},halfSpan:t.halfSpan})}return{inbounds:[...i,...r],outbounds:e.outbounds}}function Qy(t,e,n={}){const i=n.distance??5,s=n.cosine??.9;if(t.direction.x*e.direction.x+t.direction.z*e.direction.z<s)return!1;const r=t.worldPos.x-e.worldPos.x,o=t.worldPos.z-e.worldPos.z;if("number"==typeof t.halfSpan&&"number"==typeof e.halfSpan){const n=t.direction.x,s=t.direction.z;if(Math.abs(r*n+o*s)>i)return!1;const a=Math.abs(r*-s+o*n);return t.halfSpan+e.halfSpan-a>0}return Math.hypot(r,o)<=i}function Zy(t,e,n,i=0){const s=n.width??0,r=n.height??0;if(s<=0||r<=0)return!1;const o=(n.left??0)+s/2,a=(n.top??0)+r/2,c="number"==typeof n.rotation?n.rotation:0,l=Math.cos(-c),h=Math.sin(-c),d=t-o,u=e-a,p=d*l-u*h,f=d*h+u*l;return Math.abs(p)<=s/2+i&&Math.abs(f)<=r/2+i}function Jy(t,e,n){const i=n.width??0,s=n.height??0;if(i<=0||s<=0)return 1/0;const r=(n.left??0)+i/2,o=(n.top??0)+s/2;let a=t.x-r,c=t.z-o,l=e.x,h=e.z;const d="number"==typeof n.rotation?n.rotation:0;if(0!==d){const t=Math.cos(-d),e=Math.sin(-d),n=a*e+c*t,i=l*e+h*t;a=a*t-c*e,c=n,l=l*t-h*e,h=i}const u=i/2,p=s/2;let f=-1/0,m=1/0;if(Math.abs(l)<1e-9){if(a<-u||a>u)return 1/0}else{const t=(-u-a)/l,e=(u-a)/l;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}if(Math.abs(h)<1e-9){if(c<-p||c>p)return 1/0}else{const t=(-p-c)/h,e=(p-c)/h;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}return m<f?1/0:f>=0?f:m>=0?Math.min(-f,m):-m}function tb(t,e,n,i=6){return!!Zy(t.worldPos.x,t.worldPos.z,e,i)&&(!n||t.direction.x*n.x+t.direction.z*n.z>=0)}function eb(t,e,n){return t.outbounds.map(t=>{const i=[];for(const s of e){let e=null;for(const i of s.topology.inbounds){if(!Qy(t,i,n))continue;const s=t.worldPos.x-i.worldPos.x,r=t.worldPos.z-i.worldPos.z,o=Math.hypot(s,r);(null===e||o<e)&&(e=o)}if(null===e&&s.bounds){const i=s.topology.outbounds[0]?.direction,r=!(s.topology.outbounds&&s.topology.outbounds.length)?n?.sinkMargin??30:6;if(tb(t,s.bounds,i,r)){const n=Jy(t.worldPos,t.direction,s.bounds);if(Number.isFinite(n))e=n+1e3;else{const n=(s.bounds.left??0)+(s.bounds.width??0)/2,i=(s.bounds.top??0)+(s.bounds.height??0)/2;e=Math.hypot(t.worldPos.x-n,t.worldPos.z-i)+1e3}}}null!==e&&i.push({id:s.id,dist:e})}return 0===i.length?null:(i.sort((t,e)=>t.dist-e.dist||(t.id<e.id?-1:1)),i[0].id)})}function nb(t,e){const n=new Map;for(const e of t)n.set(e.id,e);const i=new Map,s=new Set;for(const n of t){const r=t.filter(t=>t.id!==n.id),o=eb(n.topology,r,e);i.set(n.id,o);for(const t of o)null!=t&&s.add(t)}const r=(t,e)=>{if(!n.has(t)||!n.has(e)||t===e)return;const r=i.get(t)??[];r.includes(e)||(r.push(e),i.set(t,r),s.add(e))};for(const e of t)if(e.links){for(const t of e.links.downstream??[])r(e.id,t);for(const t of e.links.upstream??[])r(t,e.id)}const o=new Set,a=new Set;for(const e of t){(i.get(e.id)??[]).some(t=>null!=t)||o.add(e.id),s.has(e.id)||a.add(e.id)}return{nodes:n,out:i,sinks:o,sources:a}}function ib(t,e){const n=new Map;return(t.out.get(e)??[]).map(e=>{if(null==e)return new Set;const i=new Set([e]);for(const s of function(t,e,n){const i=n.get(e);if(i)return i;const s=new Set,r=[e],o=new Set([e]);for(;r.length;){const e=r.shift();for(const n of t.out.get(e)??[])null!=n&&(s.add(n),o.has(n)||(o.add(n),r.push(n)))}return n.set(e,s),s}(t,e,n))i.add(s);return i})}function sb(t,e,n,i){return e===n?0:function(t,e,n){const i=n.get(e);if(i)return i;const s=new Map([[e,0]]),r=[e];for(;r.length;){const e=r.shift(),n=s.get(e);for(const i of t.out.get(e)??[])null==i||s.has(i)||(s.set(i,n+1),r.push(i))}return n.set(e,s),s}(t,e,i).get(n)??1/0}function rb(t,e,n){const i=t.out.get(e)??[],s=new Map,r=[];for(let e=0;e<i.length;e++){const o=i[e];if(null==o)continue;const a=o===n?0:sb(t,o,n,s);a!==1/0&&r.push({i:e,hops:1+a})}return r.sort((t,e)=>t.hops-e.hops||t.i-e.i),r.map(t=>t.i)}function ob(t,e,n){const i=rb(t,e,n);return i.length?i[0]:-1}function ab(t,e,n){return e===n||rb(t,e,n).length>0}function cb(t,e){const n=new Set;for(const i of ib(t,e))for(const e of i)t.sinks.has(e)&&n.add(e);return n}function lb(t,e,n){return hb(t,e,n).map(t=>t.index)}function hb(t,e,n){const i=n instanceof Set?n:new Set(n);if(0===i.size)return[];const s=t.out.get(e)??[],r=new Map,o=[...i].sort(),a=[];for(let e=0;e<s.length;e++){const n=s[e];if(null==n)continue;let i=1/0,c="";for(const e of o){const s=1+(n===e?0:sb(t,n,e,r));s<i&&(i=s,c=e)}i!==1/0&&a.push({index:e,hops:i,target:c})}return a.sort((t,e)=>t.hops-e.hops||t.index-e.index),a}function db(t,e={}){const n=[],i=e.loopCapableIds??new Set,s=e.routingTargetIds??new Set;for(const e of[...t.sources].sort()){const i=t.nodes.get(e);if(!i||!i.topology.outbounds?.length)continue;(t.out.get(e)??[]).some(t=>null!=t)||n.push({severity:"error",code:"orphan-source",nodeId:e,message:`source 노드 "${e}" 가 outgoing edge 0 — 아무 데도 carrier 를 보낼 수 없음`})}for(const e of[...t.nodes.keys()].sort()){(t.out.get(e)??[]).some(t=>null!=t)||(s.has(e)||t.sources.has(e)||n.push({severity:"error",code:"dead-end",nodeId:e,message:`노드 "${e}" 가 outgoing 0 인데 RoutingTarget 자격 없음 — routing 미정의 종착`}))}const r=function(t){const e=[],n=[...t.nodes.keys()].sort(),i=new Set,s=[],r=new Set,o=n=>{i.add(n),s.push(n),r.add(n);for(const a of t.out.get(n)??[])if(null!=a)if(r.has(a)){const t=s.indexOf(a),n=s.slice(t),i=n.indexOf([...n].sort()[0]),r=[...n.slice(i),...n.slice(0,i)],o=r.join("→");e.some(t=>t.join("→")===o)||e.push(r)}else i.has(a)||o(a);s.pop(),r.delete(n)};for(const t of n)i.has(t)||o(t);return e.sort((t,e)=>t[0].localeCompare(e[0])||t.length-e.length),e}(t);for(const t of r){t.some(t=>i.has(t))||n.push({severity:"error",code:"cycle",cycle:t,message:`의도 cycle 자격 (isLoop) 없는 cycle: ${t.join(" → ")} → ${t[0]}`})}const o=e.routingWeights;if(o)for(const[t,e]of[...o].sort((t,e)=>t[0].localeCompare(e[0])))(!Number.isFinite(e)||e<=0)&&n.push({severity:"warning",code:"invalid-weight",nodeId:t,message:`RoutingTarget "${t}" 의 routingWeight=${e} — weight ≤ 0 비정상, weight 정책에서 제외됨`});const a=new Set;for(const e of t.out.values())for(const t of e)null!=t&&a.add(t);for(const e of[...s].sort())t.nodes.has(e)&&(a.has(e)||n.push({severity:"warning",code:"unreachable-target",nodeId:e,message:`RoutingTarget "${e}" 에 incoming edge 0 — 누구도 이쪽으로 carrier 를 보내지 않음`}));return n.sort((t,e)=>t.code!==e.code?t.code.localeCompare(e.code):(t.nodeId??"").localeCompare(e.nodeId??"")),n}function ub(t,e){if(!t)return[];const n=[],i=new Set,s=t=>{if(!t||i.has(t))return;if(i.add(t),t!==e&&"function"==typeof t?.getSegmentTopology){const e=t.state?.id,i=t.refid??t.state?.refid,s="string"==typeof e&&e.length>0?e:null!=i?String(i):void 0;if(s)try{const e=t.getSegmentTopology(),i=t.state??{},r={left:i.left,top:i.top,width:i.width,height:i.height,rotation:i.rotation};e&&n.push({id:s,topology:e,bounds:r})}catch{}}const r=t?.components;if(Array.isArray(r))for(const t of r)s(t)};return s(t),n}function pb(t,e){const n=t.state?.targetRef??t.state?.downstreamRef;if("string"==typeof n&&n.length>0)return n;if("function"!=typeof t.getSegmentTopology)return null;const i=t.getSegmentTopology();if(!i||0===i.outbounds.length)return null;const s=eb(i,ub(t.parent??t.rootModel??t.root,t).filter(t=>t.topology.inbounds.length>0),e);for(const t of s)if(t)return t;return null}function fb(t){return!!t&&"function"==typeof t.routingConstraints}function mb(t){return!!t&&"function"==typeof t.acceptedCarrierData}function gb(t,e=16){const n=[],i=t.parent??t.rootModel??t.root;if(!i)return n;const s=pb(t);if(!s)return n;const r=_b(i,s);if(!r)return n;const o=[{segment:r,accumulated:{},pathIds:[s],visited:new Set([s])}];for(;o.length>0;){const t=o.shift();if(t.pathIds.length>e)continue;const s=fb(t.segment)?t.segment.routingConstraints():null;if(s&&s.length>0)for(const e of s)for(const s of e.candidates){const r=yb(t.accumulated,s);if(!r)continue;const a=bb(t.segment,e.portId,i);a&&!t.visited.has(a.state?.id??"")?o.push({segment:a,accumulated:r,pathIds:[...t.pathIds,a.state?.id??"?"],visited:new Set([...t.visited,a.state?.id??""])}):n.push({data:r,weight:1,pathIds:[...t.pathIds,`${e.portId}`],destination:e.portId})}else{if(mb(t.segment)){const e=t.segment.acceptedCarrierData(),i=t.segment.state?.id;if(0===e.length)n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:i});else for(const s of e){const e=yb(t.accumulated,s);e&&n.push({data:e,weight:1,pathIds:t.pathIds,destination:i})}continue}const e=pb(t.segment);if(!e||t.visited.has(e)){n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:t.pathIds[t.pathIds.length-1]});continue}const s=_b(i,e);if(!s)continue;o.push({segment:s,accumulated:t.accumulated,pathIds:[...t.pathIds,e],visited:new Set([...t.visited,e])})}}return n}function yb(t,e){const n={...t};for(const[t,i]of Object.entries(e)){if(t in n&&n[t]!==i)return null;n[t]=i}return n}function bb(t,e,n){if("straight"===e&&t.state?.downstreamRef)return _b(n,t.state.downstreamRef);const i=_b(n,e);if(i)return i;const s=pb(t);return s?_b(n,s):null}function _b(t,e){if(!t||!e)return null;if("function"==typeof t.findById)return t.findById(e);const n=new Set,i=t=>{if(!t||n.has(t))return null;if(n.add(t),t.state?.id===e)return t;const s=t.components;if(Array.isArray(s))for(const t of s){const e=i(t);if(e)return e}return null};return i(t)}function vb(t,e){return Math.hypot(t.x-e.x,t.z-e.z)}function xb(t,e,n=5,i=[],s=n){const r=t.length,o=new Array(r).fill(void 0),a=new Set,c=(e,n)=>"start"===n?t[e].start:t[e].end,l=[],h=new Map,d=[],u=new Map;for(const t of i){const e=Array.isArray(t),n=e?t:t.positions,i=e?void 0:t.kind;if(!n.length)continue;const s=l.length;l.push({pos:n[0],members:[]});for(const t of n)d.push({pos:t,pt:s});i&&u.set(s,i)}const p=(t,e)=>{const i=c(t,e),s=h.get(`${t}:${"end"===e?"start":"end"}`),r=[];for(const t of d)vb(t.pos,i)<=n&&!r.includes(t.pt)&&r.push(t.pt);for(let t=0;t<l.length;t++)vb(l[t].pos,i)<=n&&!r.includes(t)&&r.push(t);let o=r.find(t=>t!==s)??-1;o<0&&(o=l.length,l.push({pos:i,members:[]})),l[o].members.push({seg:t,end:e}),h.set(`${t}:${e}`,o)};for(let t=0;t<r;t++)p(t,"start"),p(t,"end");const f=new Set,m=new Set,g=new Set;{const t=t=>{let e=-1,n=1/0;for(let i=0;i<l.length;i++){const s=vb(l[i].pos,t);s<n&&(n=s,e=i)}for(const i of d){const s=vb(i.pos,t);s<n&&(n=s,e=i.pt)}return{pt:e,d:n}};for(const n of e){const{pt:e,d:i}=t(n.pos);e>=0&&i<=s&&(f.add(e),("source"===n.kind?m:g).add(e))}}for(const[t,e]of u)f.add(t),("source"===e?m:g).add(t);const y=(t,e)=>"end"===e!==o[t],b=[],_=(e,n)=>{if(void 0===o[e])return o[e]=n,void b.push(e);o[e]!==n&&a.add(t[e].id)},v=t=>{for(const e of["start","end"]){const n=h.get(`${t}:${e}`);if(void 0===n)continue;const i=l[n];if(2!==i.members.length||f.has(n))continue;const s=i.members[0],r=s.seg===t&&s.end===e?i.members[1]:s;if(r.seg===t)continue;const a="end"===e!==o[t],c="end"===r.end!==!a;_(r.seg,c)}},x=()=>{for(;b.length;)v(b.shift())},w=t=>{let e=-1,n="start",i=1/0;for(let s=0;s<r;s++)for(const r of["start","end"]){const o=vb(c(s,r),t.pos);o<i&&(i=o,e=s,n=r)}if(e<0||i>s)return;const o="source"===t.kind?"end"===n:"start"===n;_(e,o)};for(const t of e)"source"===t.kind&&w(t);x();for(const t of e)"sink"===t.kind&&w(t);x();let M=!0;for(;M;){M=!1;for(const t of l){if(t.members.length<3)continue;const e=t.members.filter(t=>void 0===o[t.seg]);if(1!==e.length)continue;let n=0,i=0;for(const e of t.members)void 0!==o[e.seg]&&(y(e.seg,e.end)?n++:i++);const s=e[0];let r;0===i&&n>0?r="end"===s.end:0===n&&i>0&&(r="start"===s.end),void 0!==r&&(o[s.seg]=r,b.push(s.seg),x(),M=!0)}}if(o.some(t=>void 0===t)&&m.size>0&&g.size>0){const t=t=>{const e=new Array(l.length).fill(1/0),n=[];for(const i of t)e[i]=0,n.push(i);for(;n.length;){const t=n.shift();for(const i of l[t].members){const s=h.get(`${i.seg}:${"start"===i.end?"end":"start"}`);void 0!==s&&e[s]>e[t]+1&&(e[s]=e[t]+1,n.push(s))}}return e},e=t(m),n=t(g);for(let t=0;t<r;t++){if(void 0!==o[t])continue;const i=h.get(`${t}:start`),s=h.get(`${t}:end`);if(void 0===i||void 0===s)continue;if(l[i].members.length<2||l[s].members.length<2)continue;if(e[i]===1/0||e[s]===1/0||n[i]===1/0||n[s]===1/0)continue;let r;e[i]!==e[s]?r=e[i]<e[s]:n[i]!==n[s]&&(r=n[s]<n[i]),void 0!==r&&(o[t]=!r,b.push(t))}x()}const S=new Map;for(let e=0;e<r;e++)S.set(t[e].id,void 0===o[e]?"unknown":o[e]?"reverse":"forward");return{directions:S,conflicts:[...a]}}function wb(...t){}function Mb(t){return String(t?.state?.id??t?.refid??t?.state?.refid??"?")}function Sb(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*kb(t){if(!t)return;("function"==typeof t.getSegmentTopology||t.flowOrientable)&&(yield t);const e=t.components;if(Array.isArray(e))for(const t of e)yield*kb(t)}function Ab(t,e,n){const i=e.width??0,s=e.height??0;if(i<=0||s<=0)return!1;const r=(e.left??0)+i/2,o=(e.top??0)+s/2,a="number"==typeof e.rotation?e.rotation:0,c=t.x-r,l=t.z-o,h=Math.cos(-a),d=Math.sin(-a),u=c*h-l*d,p=c*d+l*h;return Math.abs(u)<=i/2+n&&Math.abs(p)<=s/2+n}function Eb(t){const e=[],n=[],i=[],s=[];for(const r of kb(t)){const t=Sb(r);if(!t)continue;if(r.flowOrientable){const n=Xy(r.state??{});n&&e.push({id:t,start:n.start,end:n.end});continue}if("function"==typeof r.openings){const t=r.state??{};(t.width??0)>0&&(t.height??0)>0&&s.push(t);continue}let o;try{o=r.getSegmentTopology()}catch{continue}if(!o)continue;const a=o.inbounds??[],c=o.outbounds??[],l="function"==typeof r.routingDestination;if(0===a.length&&c.length>0)for(const t of c)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"source"});else if(a.length>0&&(0===c.length||l))for(const t of a)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"sink"});else if(a.length>0||c.length>0){const t=[];for(const e of a)t.push({x:e.worldPos.x,z:e.worldPos.z});for(const e of c)t.push({x:e.worldPos.x,z:e.worldPos.z});t.length&&i.push({positions:t})}}for(const t of s){const s=[];for(const n of e)for(const e of[n.start,n.end])Ab(e,t,16)&&s.push(e);let r=!1,o=!1;for(const e of n)Ab(e.pos,t,16)&&("sink"===e.kind?r=!0:o=!0);const a=r&&!o?"sink":o&&!r?"source":void 0;(s.length>=2||a&&s.length>=1)&&i.push({positions:s,kind:a})}if(0===e.length||0===n.length)return new Map;return xb(e,n,8,i,60).directions}function Cb(t){const e=t?.root;if(!e)return;if(e.__flowComputing)return;let n=e.__flowOrientation;if(!n){e.__flowComputing=!0;try{n={map:Eb(e)}}finally{e.__flowComputing=!1}e.__flowOrientation=n}const i=Sb(t),s=i?n.map.get(i):void 0;return"reverse"===s||"forward"!==s&&void 0}function Tb(t){return!!t&&"function"==typeof t.distanceToBoardPoint}function Pb(t,e,n,i){if(!t||!e)return null;const s=[],r=t=>{if(!t||t===i)return;if(Dm(t,e)&&Tb(t)){const e=function(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}(t);e&&s.push({id:e,component:t,distance:t.distanceToBoardPoint(n.x,n.y)})}const o=t.components;if(Array.isArray(o))for(const t of o)r(t)};return r(t),0===s.length?null:(s.sort((t,e)=>t.distance-e.distance||t.id.localeCompare(e.id)),s[0])}function Ob(t){return!!t&&"function"==typeof t.routingDestination}function Db(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*zb(t){if(!t)return;yield t;const e=t.components;if(Array.isArray(e))for(const t of e)yield*zb(t)}function Ib(t){const e=[],n=new Map,i=new Map,s=new Set,r=[];for(const o of zb(t)){"function"==typeof o?.registerWithHost&&r.push(o);const t="function"==typeof o?.getSegmentTopology,a="function"==typeof o?.routingLinks?o.routingLinks():void 0,c=!(!a||!((a.downstream?.length??0)>0||(a.upstream?.length??0)>0));if(!(t||Ob(o)||c||Tb(o)))continue;const l=Db(o);if(!l)continue;let h={inbounds:[],outbounds:[]};if(t){try{h=o.getSegmentTopology()}catch{continue}if(!h)continue}const d=o.state??{},u={left:d.left,top:d.top,width:d.width,height:d.height,rotation:d.rotation};if(e.push({id:l,topology:h,bounds:u,links:a}),i.set(l,o),Ob(o)){s.add(l);const t=o.routingDestination();if("string"==typeof t&&t.length>0){const e=n.get(t)??[];e.push(l),n.set(t,e)}}}return{nodes:e,destToSinks:n,components:i,routingTargetIds:s,stationClients:r}}function Rb(t){if(!t)return null;let e=t.__flowGraph;if(!e){const{nodes:n,destToSinks:i,components:s,routingTargetIds:r,stationClients:o}=Ib(t),a=nb(n);!function(t,e){if(!t)return;const n=t=>{if(!t)return;"function"==typeof t.clearStations&&t.clearStations();const e=t.components;if(Array.isArray(e))for(const t of e)n(t)};n(t);const i=[...e].sort((t,e)=>{const n=Db(t)??"",i=Db(e)??"";return n.localeCompare(i)});for(const e of i){const n=e.declaredHostRef?.();let i=null;if(n&&(i=t.findById?.(n)??null),!i){const n=e.hostCapability?.(),s=e.hostFacingPoint?.();n&&s&&(i=Pb(t,n,s,e)?.component??null)}i&&"function"==typeof e.registerWithHost&&e.registerWithHost(i)}const s=e=>{if(!e)return;if(Tb(e)&&"function"==typeof e.resolveDownstream&&"function"==typeof e.registerDivertStation)for(const n of e.resolveDownstream()){const i=t.findById?.(n);i&&e.registerDivertStation(n,i)}const n=e.components;if(Array.isArray(n))for(const t of n)s(t)};s(t)}(t,o);const c=new Set;for(const[t,e]of s){((e?.state?.type??e?.model?.type??"").includes("loop")||!0===e?.isLoop)&&c.add(t)}const l=new Map;for(const t of r){const e=s.get(t);if("function"==typeof e?.routingWeight){const n=e.routingWeight();"number"==typeof n&&(!Number.isFinite(n)||n<=0)&&l.set(t,n)}}const h=db(a,{routingTargetIds:r,loopCapableIds:c,routingWeights:l});if(h.length>0&&"undefined"!=typeof console){const t=h.filter(t=>"error"===t.severity),e=h.filter(t=>"warning"===t.severity);t.length>0?console.warn(`[FlowGraph] ${t.length} error(s) / ${e.length} warning(s):`,h):console.info(`[FlowGraph] ${e.length} warning(s):`,h)}e={graph:a,destToSinks:i,components:s,issues:h},t.__flowGraph=e}return e}function jb(t){return Rb(t)?.issues??[]}function Lb(t){const e=Rb(t);return e&&e.graph.nodes.size>0?e.graph:null}function Fb(t,e){return Rb(t)?.destToSinks.get(e)??[]}function Nb(t,e){return Rb(t)?.components.get(e)}function Hb(t){const e=Rb(t);return e?[...e.destToSinks.keys()]:[]}function Bb(t){return Db(t)}function Gb(t){const e="number"==typeof t?.inventoryCount?t.inventoryCount:"function"==typeof t?.size?t.size():0,n=t?.state?.capacity;return"number"==typeof n&&n>0?e/n:e}function Vb(t,e,n,i,s){if(1===i.length)return i[0];switch(t){case"index":default:return i[0];case"round-robin":{const t=n.counters.get(e)??0;return n.counters.set(e,t+1),i[t%i.length]}case"weight":{const t=i.map(t=>function(t){if("function"==typeof t?.routingWeight){const e=t.routingWeight();if("number"==typeof e&&Number.isFinite(e)&&e>0)return e}return 1}(s.get(t.target))),r=t.reduce((t,e)=>t+e,0);if(r<=0)return i[0];const o=n.counters.get(e)??0;n.counters.set(e,o+1);let a=o%r;for(let e=0;e<i.length;e++){if(a<t[e])return i[e];a-=t[e]}return i[i.length-1]}case"utilization":{let t=1/0,e=i[0];for(const n of i){const i=Gb(s.get(n.target));i<t&&(t=i,e=n)}return e}}}function Yb(t,e,n){const i=t?.root;if(!i)return null;const s=e?.state?.meta?.destination;if("string"!=typeof s||0===s.length)return null;const r=Rb(i);if(!r||0===r.graph.nodes.size)return null;const o=Db(t);if(!o)return null;let a=r.destToSinks.get(s)??[];0===a.length&&(a=[s]);const c=hb(r.graph,o,a);if(0===c.length)return null;const l=r.graph.out.get(o)??[],h=c.filter(t=>{const n=l[t.index],i=n?r.components.get(n):null;return!i||"function"!=typeof i.canReceive||i.canReceive(e)});if(0===h.length)return l[c[0].index]??null;const d=n?.policy??function(t,e){const n=t?.state?.balancingPolicy;if(n)return n;const i=e?.state?.routingBalancingPolicy;return i||"round-robin"}(t,i),u=Vb(d,o,function(t){return t.__balancingState||(t.__balancingState={counters:new Map}),t.__balancingState}(i),h,r.components);return l[u.index]??null}Rm({name:"Capacity",description:"Item 을 *보유(keep)* 하는 측면 — slot 위상 / 수용 판정(canReceive/findSlot) / 3D 안착(placementFor/attachPointFor/acceptanceRotation) / delivery 좌표 질의 / 점유 수. 이동(receive/dispatch 등)은 Transferable 소관.",methods:["get slots","get arrangementStrategy","canReceive","findSlot","placementFor","attachPointFor","acceptanceRotation","deliveryWorldRotation","deliveryWorldPosition","_countOccupied"],sourceFile:"src/items/capacity-mixin.ts"}),Rm({name:"PlacementSurface",description:"carrier 가 holder 위 *정확히 어디에 앉는가* 의 단일 진입점 — placementFor(carrier, ctx) → SeatingPose (holder object3d local frame, 순수 함수). I1 접촉 (밑면 = 받침 상면) / I2 frame-explicit (parent-child 비가정 — Sovereign handover 와 reparent 양쪽이 같은 값 소비) / I3 순수성 / I4 per-carrier 치수. default 구현은 Capacity(FlowNode) 가 기존 receivingSurfaceY + ArrangementStrategy + acceptanceRotation 합성과 수치 동일하게 제공.",methods:["placementFor"],models:["CarrierDims","PlacementContext","SeatingPose"],sourceFile:"src/items/capacity-mixin.ts"});try{globalThis.__operatoBuildFlowGraph=(t,e)=>{try{return e?.force&&t&&delete t.__flowGraph,Lb(t)}catch{return null}}}catch{}function Wb(t,e,n){const i=Yb(t,e,n);if(null==i)return null;const s=t?.root,r=Nb(s,i)??s?.findById?.(i)??null;return r?{targetId:i,component:r,origin:"explicit"}:null}function Ub(t){const e=t?.root,n=Lb(e),i=Bb(t);if(!n||!i)return null;const s=(n.out.get(i)??[]).find(Boolean);if(!s)return null;const r=Nb(e,s)??e?.findById?.(s)??null;return r?{id:s,component:r}:null}function $b(t){const e=Bb(t);return e?Xb(t?.root,e):[]}function Xb(t,e){if(!t||!e)return[];const n=Lb(t);if(!n)return[];const i=new Set;for(const s of cb(n,e)){const e=Nb(t,s);if(Ob(e)){const t=e.routingDestination();"string"==typeof t&&t.length>0&&i.add(t)}}return[...i]}function qb(t,e){if(!t||!e)return[];const n=Lb(t);if(!n)return[];const i=new Map;for(const t of n.out.values())for(const e of t)null!=e&&i.set(e,(i.get(e)??0)+1);const s=new Map;for(const r of cb(n,e)){const e=Nb(t,r);if(!Ob(e))continue;const n=e.routingDestination();if("string"!=typeof n||0===n.length)continue;let o=null;if("function"==typeof e.routingWeight){const t=e.routingWeight();"number"==typeof t&&Number.isFinite(t)&&t>0&&(o=t)}null===o&&(o=i.get(r)??0,0===o&&(o=1)),s.set(n,(s.get(n)??0)+o)}return[...s].map(([t,e])=>({value:t,weight:e}))}function Kb(t){return Lb(t)}function Qb(t){const e=Lb(t);if(!e)return[];const n=new Set,i=new Set,s=t=>{if(!t)return;const r=Bb(t);if(r&&e.nodes.has(r)){Ob(t)&&n.add(r);((t?.state?.type??t?.model?.type??"").includes("loop")||!0===t?.isLoop)&&i.add(r)}const o=t.components;if(Array.isArray(o))for(const t of o)s(t)};return s(t),db(e,{routingTargetIds:n,loopCapableIds:i})}function Zb(t){if(0===t.length)return;const e=t.reduce((t,e)=>t+e.weight,0);if(e<=0)return t[Math.floor(Math.random()*t.length)].value;const n=Math.random()*e;let i=0;for(const e of t)if(i+=e.weight,n<i)return e.value;return t[t.length-1].value}const Jb={next:Wb,downstream:Ub,reachableDestinations:$b,reachableDestinationsFrom:Xb,reachableDestinationsWeightedFrom:qb,pickWeightedDestination:Zb,graphFor:Kb,validate:Qb};function t_(t){var e;return e=class extends t{constructor(){super(...arguments),this._items=[]}get items(){return this._items}containsItem(t){return-1!==this._items.indexOf(t)}attachPointFor(e,n){const i=t.prototype?.attachPointFor;return"function"==typeof i?i.call(this,e,n):null}addItem(t,e){if(!t||this.containsItem(t))return;const n=t.parent;if(n&&"function"==typeof n.removeItem&&n!==this&&n.removeItem(t,!0),this._items.push(t),t.parent=this,!e?.silent&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}t.held?.(this)}removeItem(t,e){if(!t)return;const n=this._items.indexOf(t);if(-1!==n&&(this._items.splice(n,1),t.parent=null,!e)){if("function"==typeof this.trigger)try{this.trigger("release",this,t,n)}catch{}t.released?.(this)}}forEachItem(t,e){this._items.forEach(t,e)}handoverIn(t,e){if(!t)return;const n=t.parent;n&&("function"==typeof n.removeComponent&&-1!==n._components?.indexOf?.(t)&&n.removeComponent(t,!0),n!==this&&"function"==typeof n.removeItem&&-1!==n._items?.indexOf?.(t)&&n.removeItem(t,!0));const i=-1===this._items.indexOf(t);if(i&&this._items.push(t),t.parent=this,i&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}const s=t._realObject,r=s?.object3d;if(r){let n,i,o=e?.toParent3D,a="world-preserve";if(!o){const s=this.attachPointFor?.(t,{slotId:e?.slotId});s?.attach&&(o=s.attach,n=s.localPosition,i=s.localRotation,a=s.carryPolicy??"world-preserve")}o&&r.parent!==o&&(o.updateWorldMatrix?.(!0,!1),r.updateWorldMatrix?.(!0,!1),o.attach(r),s.suppressTransform=!0),o&&(n&&r.position.set(n.x,n.y,n.z),"world-preserve"!==a?i?r.rotation.set(i.x,i.y,i.z):r.quaternion.identity():i&&r.rotation.set(i.x,i.y,i.z),s?.setTransientPlacement?.({policy:"carried",meta:{carryPolicy:a}}))}t.held?.(this),this._bumpReceived?.(t)}handoverOut(t){this.removeItem(t),this._bumpDispatched?.(t)}dispose(){const t=this._items.slice();this._items.length=0;for(const e of t)try{e.dispose?.()}catch{}super.dispose?.()}_drawItems(t){const e=this.root?.transitionEffect;for(const t of this._items)e?.isReparenting?.(t)||t.draw?.(this.getContext?.(t))}_captureItems(t,e,n,i,s){for(let r=this._items.length-1;r>=0;r--){const o=this._items[r],a="static"===o.position?o.capture?.(t,e,s):o.capture?.(n,i,s);if(a)return a}return null}postrender(t){super.postrender?.(t);const e=this;if("popup"===e.position)return;const n=this._items;if(!n||0===n.length)return;t.save();const i=e.bounds;!e.showOverflow&&i&&(t.beginPath(),t.rect(i.left,i.top,i.width,i.height),t.clip(),t.closePath());const{left:s=0,top:r=0}=e.state??{};t.translate(s,r),this._drawItems(t),t.translate(-s,-r),t.restore()}capture(t,e,n){const i=this,s=this._items;if(s&&s.length>0&&(!i.app||i.app.isEditMode||!i.hidden)){const s=i.fromParent?.(t,e);if(s&&i.contains?.(s.x,s.y)){const r=i.bounds,o=this._captureItems(s.x-r.left,s.y-r.top,t,e,n);if(o)return o}}return super.capture?.(t,e,n)}},e.capabilities=Object.freeze([...t.capabilities??[],"Holdable"]),e}function e_(t){var n;const i=!!t.__hasCapacity,s=!!t.__hasTransferable,r=i?t:Wy(t),o=s?r:function(t){var n;return(n=class extends t{reserve(t,e){const n=this.findSlot(t);return n?{slot:n,token:Symbol("slot-reservation")}:null}release(t){}async receive(t,e={}){Iu.log({role:"target",contract:"receive:enter",component:this,args:{carrier:jy(t),options:e}});const n=this.reserve(t,e);if(!n){Iu.log({role:"target",contract:"receive:reject",component:this,args:{carrier:jy(t)},result:{reason:"no-slot"}}),this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const e=new Error("receive rejected: no-slot");throw e.reason="no-slot",e}this.commit(n,t,e)}commit(t,n,i={}){const s=t.slot,r=this._countOccupied(s.id),o=this.arrangementStrategy.positionAt(r,s,r,n);Iu.log({role:"target",contract:"arrangementStrategy.positionAt",component:this,args:{idx:r,slotId:s.id,occupantCount:r,carrier:jy(n)},result:o}),n[Ny]=s.id;const a=n._realObject;let c,l;a?.object3d&&(a.object3d.updateWorldMatrix(!0,!1),c=new e.Vector3,l=new e.Quaternion,a.object3d.getWorldPosition(c),a.object3d.getWorldQuaternion(l));const{animated:h=!1,duration:d,ease:u}=i;"function"==typeof this.handoverIn?this.handoverIn(n,{slotId:s.id}):this.reparent?.(n,{animated:h,duration:d,ease:u}),!h&&n._realObject&&(n._realObject.suppressTransform=!1);{const t={},e=this.placementFor?.(n,{slot:s,index:r,occupantCount:r})??null;if(Iu.log({role:"target",contract:"placementFor",component:this,args:{carrier:jy(n),slotId:s.id,index:r},result:e}),e){const i=n.state??{},r=this.state??{};t.left=e.position.x-(Number(i.width)||0)/2+(Number(r.width)||0)/2,t.top=e.position.z-(Number(i.height)||0)/2+(Number(r.height)||0)/2;const o=this._zPosFromSeatY(e.position.y,i.depth,s);null!==o&&(t.zPos=o),e.rotation&&Fy(t,e.rotation)}else{if(o&&(t.left=o.x,t.top=o.y),0!==(this._realObject?.receivingSurfaceY??0))t.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const e=this._realObject?.geometricOffsetY??0;t.zPos=s.localPosition.z+e}const e=this.acceptanceRotation?.(n,s);Iu.log({role:"target",contract:"acceptanceRotation",component:this,args:{carrier:jy(n),slotId:s.id},result:e}),e&&Fy(t,e)}const i=this.normalizePose?.(n,s);"function"==typeof this.normalizePose&&Iu.log({role:"target",contract:"normalizePose",component:this,args:{carrier:jy(n),slotId:s.id},result:i}),i&&Object.assign(t,i),Object.keys(t).length&&(n.setState?.(t),Iu.log({role:"target",contract:"receive:setState",component:this,args:{carrier:jy(n),keys:Object.keys(t)}}))}this.trigger("transfer-received",{type:"transfer-received",component:n,container:this,slotId:s.id,preReceiveWorldPos:c,preReceiveWorldQuat:l}),Iu.log({role:"target",contract:"receive:done",component:this,args:{carrier:jy(n),slotId:s.id}})}async dispatch(t,e,n={}){const i=new Fu({source:this,target:e,carrier:t,options:n,physical:async()=>{delete t[Ny]}}),s=await i.execute();"rolled-back"!==s.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:s.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}canAccept(t){const e=(()=>{const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const n=this.findSlot(t);if(!n){const n=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!n||t.allowedTypes.includes(n))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:n}})();return Iu.log({role:"target",contract:"canAccept",component:this,args:{carrier:jy(t)},result:e.ok?{ok:!0,slotId:e.slot.id}:{ok:!1,reason:e.reason}}),e}accept(t,e){return this.receive(t,e)}}).__hasTransferable=!0,n}(r),a=[...t.capabilities??[]];i||a.push("Capacity","PlacementSurface"),s||a.push("Transferable"),a.push("Holdable","FlowNode");var c,l,h;return By((n=class extends(t_(o)){get isFlowNode(){return!0}containable(t){return!!t&&!0===t.isItem}get showMoveHandle(){return!1}inboundPorts(){return[]}outboundPorts(){return[]}_bumpReceived(t){const e=this.state?.received??0;this.setState?.({received:e+1})}_bumpDispatched(t){const e=this.state?.dispatched??0;this.setState?.({dispatched:e+1})}_bumpRejected(t,e){const n=this.state?.rejected??0;this.setState?.({rejected:n+1})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e){}resolveDownstream(){const t=this.state?.downstreamRef;if(!t)return[];return(this.root?.findAll?.(t)??[]).map(t=>t?.state?.id).filter(Boolean)}routingLinks(){return{downstream:this.resolveDownstream()}}},c=n,"symbol"==typeof(l="FlowNodeMixed")&&(l=l.description?"[".concat(l.description,"]"):""),Object.defineProperty(c,"name",{configurable:!0,value:h?"".concat(h," ",l):l}),n.capabilities=Object.freeze(a),n.isFlowNode=!0,n))}function n_(t){return!!t&&!0===t.isFlowNode}Rm({name:"Holdable",description:"어떤 Component 든 item(데이타바인딩 동적 물건) 을 보유하는 capability. _items + add/remove/forEach + handover + hold/release event + dispose cascade. Container(정적 _components) 와 직교 — 컨테이너 비의존.",methods:["addItem","removeItem","forEachItem","containsItem","handoverIn","handoverOut","_drawItems","_captureItems","dispose"],sourceFile:"src/components/mixins/holdable.ts"}),Rm({name:"Transferable",description:"Item 을 노드 간에 옮기는 *이동(move)* 측면. 수용 트랜잭션 라이프사이클(reserve → commit → release)과 receive/accept/dispatch/route 를 제공. 보유(keep — slots/findSlot/canReceive 등)는 Capacity 소관.",methods:["reserve","commit","release","receive","accept","canAccept","dispatch","route","resolveRoute","rejectRoute"],sourceFile:"src/transfer/transferable-mixin.ts"}),Rm({name:"FlowNode",description:"Flow graph 의 노드 — 구조 (inbound/outbound port + slot) + flow (route + 5-phase transfer stat). 보유(_items/handover)는 Holdable base 위임. 모든 flow 컴포넌트의 base — Storable/Mobile/Processable 의도가 위에 직교로 적용.",methods:["inboundPorts","outboundPorts","slotIds","slotAt","route","resolveRoute","rejectRoute"],models:["Port","SlotInfo","Vec3"],sourceFile:"src/flow/flow-node.ts"});const i_={x:0,y:0,z:0,w:1};function s_(t){const e=t/2;return{x:0,y:Math.sin(e),z:0,w:Math.cos(e)}}function r_(t,e){const n=t.rotation,i=e.rotation,s=e.position,r=n.w*s.x+n.y*s.z-n.z*s.y,o=n.w*s.y+n.z*s.x-n.x*s.z,a=n.w*s.z+n.x*s.y-n.y*s.x,c=-n.x*s.x-n.y*s.y-n.z*s.z,l=r*n.w+c*-n.x+o*-n.z-a*-n.y,h=o*n.w+c*-n.y+a*-n.x-r*-n.z,d=a*n.w+c*-n.z+r*-n.y-o*-n.x,u={x:n.w*i.x+n.x*i.w+n.y*i.z-n.z*i.y,y:n.w*i.y-n.x*i.z+n.y*i.w+n.z*i.x,z:n.w*i.z+n.x*i.y-n.y*i.x+n.z*i.w,w:n.w*i.w-n.x*i.x-n.y*i.y-n.z*i.z};return{position:{x:t.position.x+l,y:t.position.y+h,z:t.position.z+d},rotation:u}}const o_={east:{axis:{x:1,y:0,z:0},yaw:0,idSuffix:"east"},west:{axis:{x:-1,y:0,z:0},yaw:Math.PI,idSuffix:"west"},south:{axis:{x:0,y:0,z:1},yaw:-Math.PI/2,idSuffix:"south"},north:{axis:{x:0,y:0,z:-1},yaw:Math.PI/2,idSuffix:"north"}};function a_(t){const{carrierWorld:e,width:n,depth:i,entryHeight:s,mountLocalY:r,approachDistance:o,sides:a,toolType:c,tolerance:l,priority:h}=t,d="number"==typeof r?{position:{x:0,y:r,z:0},rotation:{...i_}}:void 0,u=n/2,p=i/2;return a.map(t=>{const n=o_[t],i="string"==typeof c?c:c[t]??"unknown",r={position:{x:n.axis.x*("east"===t||"west"===t?u:0),y:s,z:n.axis.z*("north"===t||"south"===t?p:0)},rotation:s_(n.yaw)},a={position:{x:r.position.x+n.axis.x*o,y:s,z:r.position.z+n.axis.z*o},rotation:s_(n.yaw)};return{id:`entry-${n.idSuffix}`,toolType:i,approach:r_(e,a),engage:r_(e,r),...d?{mount:d}:{},tolerance:l,priority:h}})}function c_(t){const{carrierWorld:e,topY:n,approachDistance:i,toolType:s,mountLocalY:r,tolerance:o,priority:a,id:c}=t,l={position:{x:0,y:n,z:0},rotation:{...i_}};return{id:c??"top",toolType:s,approach:r_(e,{position:{x:0,y:n+i,z:0},rotation:{...i_}}),engage:r_(e,l),..."number"==typeof r?{mount:{position:{x:0,y:r,z:0},rotation:{...i_}}}:{},tolerance:o,priority:a}}function l_(t,e){return t.filter(t=>t.toolType===e.toolType)}function h_(t,e){if(0===t.length)return null;const n=t.map(t=>{const n=t.approach.position.x-e.x,i=t.approach.position.y-e.y,s=t.approach.position.z-e.z;return{f:t,dist:Math.sqrt(n*n+i*i+s*s)}});return n.sort((t,e)=>{const n=t.f.priority??0,i=e.f.priority??0;return n!==i?n-i:t.dist-e.dist}),n[0].f}class d_{constructor(t){this.owner=t}positionAt(t,e,n,i){if(0!==t)return null;const s=this.owner?.state?.width??0,r=this.owner?.state?.height??0,o=i?.state?.width??0,a=i?.state?.height??0;return{x:Math.max(0,(s-o)/2),y:Math.max(0,(r-a)/2),z:0}}capacity(t){return t.maxCount??1}}let u_=1;function p_(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const f_={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class m_{constructor(t=f_){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+u_++},n=(this._byResource.get(e.resource)??[]).filter(t=>p_(t.timeWindow,e.timeWindow));if(0===n.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=n.map(t=>{const n=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:n}});if(i.every(t=>"b-yields"===t.decision)){const i=n.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:n.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>p_(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const n=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);n<0?e.push(t):e.splice(n,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const n=e.findIndex(e=>e.id===t.id);if(n<0)return!1;e.splice(n,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const g_=new m_;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=g_);class y_{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,n=1/0;for(const i of this.nodes.values()){const s=b_(i.position,t);s<n&&(n=s,e=i)}return e}}function b_(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}function __(t,e){return Math.sqrt(b_(t,e))}function v_(t,e,n={}){const i=new y_,s=n.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const n=`${e.id}:start`,r=`${e.id}:end`;i.addNode({id:n,position:t[0],type:"lane-start"}),i.addNode({id:r,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:n,endNodeId:r});let o=0;for(let e=1;e<t.length;e++)o+=__(t[e-1],t[e]);const a=o/(e.speedLimit??s)*1e3;i.addEdge({fromNode:n,toNode:r,resource:e.id,distance:o,durationMs:a,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:r,toNode:n,resource:e.id,distance:o,durationMs:a,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const n of t.lanes){const s=i.laneEndpoints.get(n);if(!s)continue;const r=i.nodes.get(s.startNodeId).position,o=i.nodes.get(s.endNodeId).position;let a=0,c=0,l=0;for(const e of t.lanes){if(e===n)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const s=i.nodes.get(t.startNodeId).position,h=i.nodes.get(t.endNodeId).position;a+=Math.min(b_(r,s),b_(r,h)),c+=Math.min(b_(o,s),b_(o,h)),l++}if(0===l)continue;const h=a<c?s.startNodeId:s.endNodeId;e.push({laneId:n,nodeId:h,pos:i.nodes.get(h).position})}for(let n=0;n<e.length;n++)for(let s=0;s<e.length;s++){if(n===s)continue;const r=e[n],o=e[s],a=__(r.pos,o.pos);i.addEdge({fromNode:r.nodeId,toNode:o.nodeId,resource:t.id,distance:a,durationMs:t.crossingTimeMs,forward:!0})}}return i}function x_(t,e,n,i={}){const s=t.nodes.get(e),r=t.nodes.get(n);if(!s||!r)return null;const o=i.speed?.max??100,a=e=>{const n=t.nodes.get(e);var i,s;return(i=n.position,s=r.position,Math.sqrt(function(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}(i,s)))/o*1e3},c=new Map,l=new Set,h=new Set,d={nodeId:e,gScore:0,fScore:a(e)};c.set(e,d),l.add(e);const u=i.startSimMs??0,p=i.deadlineSimMs;for(;l.size>0;){let e=null,i=null;for(const t of l){const n=c.get(t);(!i||n.fScore<i.fScore||n.fScore===i.fScore&&t<e)&&(i=n,e=t)}if(!i||!e)return null;if(e===n){const t=[];let e=i,n=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,s=u+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:s,endSimMs:s+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),n+=i.distance,e=c.get(i.fromNodeId)}const s=i.gScore;return void 0!==p&&u+s>p?null:{segments:t,totalDurationMs:s,totalDistance:n}}l.delete(e),h.add(e);for(const n of t.edgesFrom(e)){if(h.has(n.toNode))continue;const e=i.gScore+n.durationMs,s=c.get(n.toNode);if(!s||e<s.gScore){const i=t.nodes.get(n.fromNode),s=t.nodes.get(n.toNode),r={nodeId:n.toNode,gScore:e,fScore:e+a(n.toNode),cameFromEdge:{fromNodeId:n.fromNode,resource:n.resource,distance:n.distance,durationMs:n.durationMs,fromPos:i.position,toPos:s.position}};c.set(n.toNode,r),l.add(n.toNode)}}}return null}function w_(t,e,n=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:n,metadata:i}))}const M_={closed:!0,round:0,divisions:24};class S_{constructor(t,e){this.points=t,this.closed=e;const n=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,s=t[e].y-t[e-1].y;n.push(n[e-1]+Math.sqrt(i*i+s*s))}this.cumulative=n,this.length=n[n.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let n=t;this.closed?n=(t%e+e)%e:n<0?n=0:n>e&&(n=e);const i=this.cumulative;let s=0,r=i.length-2;for(;s<r;){const t=s+r>>1;i[t+1]<=n?s=t+1:r=t}const o=i[s+1]-i[s],a=o>0?(n-i[s])/o:0,c=this.points[s],l=this.points[s+1],h=l.x-c.x,d=l.y-c.y;return{x:c.x+h*a,y:c.y+d*a,theta:0===h&&0===d?0:Math.atan2(d,h)}}}function k_(t,e={}){const n={...M_,...e},i=t.length;if(0===i)return new S_([],n.closed);if(1===i)return new S_([{x:t[0].x,y:t[0].y}],n.closed);const s=[],r=(t,e)=>{if(s.length>0){const n=s[s.length-1];if(Math.abs(n.x-t)<1e-9&&Math.abs(n.y-e)<1e-9)return}s.push({x:t,y:e})},o=(n.closed,i);for(let e=0;e<o;e++){const s=0===e?n.closed?i-1:-1:e-1,o=e===i-1?n.closed?0:-1:e+1,a=s>=0?t[s]:null,c=t[e],l=o>=0?t[o]:null;if(a&&a.x===c.x&&a.y===c.y)continue;const h=a&&l?to(c,n.round):0;let d,u,p,f;if(a){const t=Math.sqrt((a.x-c.x)**2+(a.y-c.y)**2),e=0!==t?Math.atan2(a.x-c.x,a.y-c.y):0,n=Math.min(h,t/2);d=Math.sin(e)*n+c.x,u=Math.cos(e)*n+c.y}else d=c.x,u=c.y;if(l){const t=Math.sqrt((l.x-c.x)**2+(l.y-c.y)**2),e=0!==t?Math.atan2(l.x-c.x,l.y-c.y):0,n=Math.min(h,t/2);p=Math.sin(e)*n+c.x,f=Math.cos(e)*n+c.y}else p=c.x,f=c.y;if(r(d,u),h>0&&a&&l)for(let t=1;t<=n.divisions;t++){const e=t/n.divisions,i=1-e;r(i*i*d+2*i*e*c.x+e*e*p,i*i*u+2*i*e*c.y+e*e*f)}else d===p&&u===f||r(p,f);if(l&&Kr(c)){const t=to(l,n.round),e=Math.sqrt((c.x-l.x)**2+(c.y-l.y)**2),i=0!==e?Math.atan2(c.x-l.x,c.y-l.y):0,s=Math.min(t,e/2),o=Qr({x:p,y:f},{x:Math.sin(i)*s+l.x,y:Math.cos(i)*s+l.y},c.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=n.divisions;e++){const i=e/n.divisions,s=o.startAngle+t*i;r(o.cx+o.radius*Math.cos(s),o.cy+o.radius*Math.sin(s))}}}}if(n.closed&&s.length>0){const t=s[0],e=s[s.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&s.push({x:t.x,y:t.y})}return new S_(s,n.closed)}function A_(t,e){return k_(t,e).length}function E_(t){return t?/forklift|agv|amr|oht|tugger|worker/i.test(t)?"mobile":/conveyor|sorter|induct|chute|belt/i.test(t)?"flow":/rack|shelf|stocker|cell/i.test(t)?"cell":/pallet|box|parcel|crate|drum|tray/i.test(t)?"atomic":/robot[-_]?arm|crane|lift/i.test(t)?"articulated":/spawn[-_]?point|sink[-_]?point/i.test(t)?"boundary":"":""}function C_(t){const e=[];let n=t.parent;for(;n&&!n.isRootModel?.();){const t=n.state?.id??n.constructor?.name;t&&e.unshift(t),n=n.parent}return e.join(" › ")}function T_(t,e=!0){const n=t.constructor?.name??t.state?.type??"Component",i={type:n,id:t.state?.id??`?${t._id??Math.random().toString(36).slice(2,7)}`,category:E_(n),parentId:t.parent?.state?.id,parentPath:C_(t)},s=t._realObject?.object3d;if(s){s.updateWorldMatrix?.(!0,!1);const t=s.matrixWorld?.elements;t&&(i.pose={position:{x:t[12],y:t[13],z:t[14]},rotation:{x:0,y:0,z:0,w:1}})}if(!0===t.isItem&&(i.isItem=!0),!0===t.isMover&&(i.isMover=!0),"function"!=typeof t.canReceive&&"function"!=typeof t.canAccept||(i.isHolder=!0),"function"==typeof t.pickupFrames)try{i.isPickable=t.pickupFrames().length>0}catch{i.isPickable=!1}if("string"==typeof t.toolType||"function"==typeof t.toolType?i.toolType="function"==typeof t.toolType?t.toolType():t.toolType:void 0!==t.toolType&&(i.toolType=String(t.toolType)),t.state&&"object"==typeof t.state){const e={};for(const[n,i]of Object.entries(t.state))"string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i&&null!==i||(e[n]=i);i.state=e}if(e){const e=t.components??[];i.childIds=e.map(t=>t.state?.id).filter(Boolean)}return i}function P_(t){function e(t,n){if(!t)return;n.push(T_(t));const i=t.components??[];for(const t of i)e(t,n)}function n(t,e){if(!e)return null;if(e.state?.id===t)return e;const i=e.components??[];for(const e of i){const i=n(t,e);if(i)return i}return null}return{version:"0.1.0",collectComponents(){const n=[];return e(t?.rootModel??t,n),n},getComponent(e){const i=n(e,t?.rootModel??t);if(!i)return null;const s={...T_(i)};if("function"==typeof i.pickupFrames)try{s.pickupFrames=i.pickupFrames()}catch{}if("object"==typeof i.slots)try{s.slots=Array.isArray(i.slots)?i.slots:"function"==typeof i.slots?i.slots():[]}catch{}if("function"==typeof i.acceptanceRotation)try{s.acceptanceWorldQuat=i.deliveryWorldRotation?.(null)??void 0}catch{}if("function"==typeof i.deliveryWorldPosition)try{s.deliveryWorldPosition=i.deliveryWorldPosition(null)}catch{}return s},simStatus(){let e=0;const n=[t?.rootModel??t];for(;n.length>0;){const t=n.pop();if(!t)continue;!0===t.isItem&&e++;const i=t.components??[];for(const t of i)n.push(t)}return{simTime:Ir.now,realTime:"undefined"!=typeof performance?performance.now():Date.now(),speed:Ir.speed,paused:Ir.isPaused,carrierCount:e}},transferLog(){const t={};Nu.flows().forEach((e,n)=>{t[n]=e});const e={};Nu.targetCounts().forEach((t,n)=>{e[n]=t});const n={};return Nu.rejectReasonCounts().forEach((t,e)=>{n[e]=t}),{entries:Nu.toJSON(),stats:Nu.stats(),flows:t,targetCounts:e,rejectReasonCounts:n}},reservations(){const t=[...g_.all()],e={},n={};for(const i of t)(e[i.resource]??=[]).push(i),(n[i.reserverId]??=[]).push(i);for(const t of Object.values(e))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);for(const t of Object.values(n))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);return{simTime:Ir.now,all:t,byResource:e,byReserver:n}},conflicts(){const t=g_.conflictLog(),e={},n={};let i=0,s=0;for(const r of t)e[r.resource]=(e[r.resource]??0)+1,n[r.proposed.reserverId]=(n[r.proposed.reserverId]??0)+1,"rejected"===r.outcome?i++:s++;return{simTime:Ir.now,log:[...t],total:t.length,rejected:i,preempted:s,byResource:e,byReserver:n}}}}function O_(t){const e=P_(t);return"undefined"!=typeof window&&(window.__SCENE_INSPECTOR__=e),e}let D_=0;const z_=new FinalizationRegistry(()=>{D_--});class I_{static get residents(){return D_}static get residentsCount(){return D_}constructor(t,e){this.counters={},this.references={},this.creator=t,this.disposer=e,D_++,z_.register(this,D_)}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,ts("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,i)=>{const s=this.references[t];if(s)s===e?i(Error("Reference ID and target duplicate")):e?i(Error("Reference ID duplicate")):n(s);else{const s=e=>{e.release=()=>{this.release(e)},this.references[t]=e,this.counters[t]=1,n(e)};if(e)s(e);else{if(!this.creator)return void i(Error("Reference id("+t+") is not allowed. Reference creator should be defined."));this.creator(t,s,i)}}});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 Zi("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,ts("RELEASED",e)))}}const R_={},j_={};let L_=[];function F_(t){const e=t.target,n="SCRIPT"===e.tagName?R_:j_,i=e.src||e.href;n[i]=!0,L_.forEach((t,e)=>{if(!t)return;const{resolve:s,scripts:r,styles:o}=t;if(n===R_){const t=r.indexOf(i);t>-1&&t<r.length-1&&H_(r[t+1])}r.some(t=>!R_[t])||o?.some(t=>!j_[t])||(s(),L_[e]=null)}),L_=L_.filter(Boolean)}function N_(t){if("string"==typeof t)return;const e=t.target,n=e.src,i="SCRIPT"===e.tagName?R_:j_;L_.forEach((e,s)=>{if(!e)return;const{reject:r,scripts:o,styles:a}=e;(i===R_&&o.includes(n)||i===j_&&!!a?.includes(n))&&(r(t),L_[s]=null)}),L_=L_.filter(Boolean),delete i[n],document.head.removeChild(e)}function H_(t){R_[t]=!1;const e=document.createElement("script");e.onload=F_,e.onerror=N_,e.type="text/javascript",e.src=t,document.head.appendChild(e)}class B_{static load(t,e){const n="string"==typeof t?[t]:t,i="string"==typeof e?[e]:e;return new Promise(function(t,e){if(n&&!Array.isArray(n)||i&&!Array.isArray(i))return void e(new Error("invalid sources for load"));let s,r=!0;if(i?.forEach(t=>{t in j_||function(t){j_[t]=!1;const e=document.createElement("link");e.onload=F_,e.onerror=N_,e.type="text/css",e.rel="stylesheet",e.media="screen,print",e.href=t,document.head.appendChild(e)}(t),j_[t]||(r=!1)}),n&&n.length>0)for(const t of n)t in R_?R_[t]||(r=!1):s??=t;if(s)H_(s);else if(r)return void t();L_.push({resolve:t,reject:e,scripts:n,styles:i})})}}const G_="0.0.0";function V_(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 Y_(t){const{lineWidth:n=0}=t.state;let{width:i,height:s}=t.bounds;i+=n,s+=n;const r=V_(2*i),o=V_(2*s),a=Dp(r,o),c=new e.CanvasTexture(a);return W_(a,t,2),c.needsUpdate=!0,c.wrapS=e.RepeatWrapping,c.wrapT=e.RepeatWrapping,c.offset.set(0,1-2*s/o),c.repeat.set(2*i/r,2*s/o),c.magFilter=e.NearestFilter,c.minFilter=e.LinearFilter,c.colorSpace=e.SRGBColorSpace,c}function W_(t,e,n){const{lineWidth:i=0}=e.state;let{left:s,top:r}=e.bounds;s-=i/2,r-=i/2;const o=t.getContext("2d");o.scale(n,n),o.translate(-s,-r),e.render(o),e.postrender(o)}function U_(t,e,n=2){const i=t.getContext("2d");i&&(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,t.width,t.height),W_(t,e,n))}const $_=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class X_ extends pu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds;if(!t||!n)return;const i=Md(this.component.state.material3d),s=new e.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=Y_(this.component),o=new e.MeshStandardMaterial({map:r});Ad(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateDimension(){const{width:t,height:e}=this.component.bounds;this.setDimensionScale(t,1,e)}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this._rebuildTexture()},100)}_rebuildTexture(){this.clear(),this.build(),this.updateTransform(),this.updateDimension(),this.updateHidden()}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(U_(n,this.component,2),e.needsUpdate=!0)}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!$_.has(e)){this._debouncedRebuild();break}}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Md(this.component.state.material3d);Ad(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),eu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const q_=new Map;function K_(t){return Math.round(1e3*t)/1e3}function Q_(t){return new e.Color(t).getHexString()}const Z_={material(t,n,i){const s=t+"::"+function(t){const e=[];return null!=t.color&&e.push("c"+Q_(t.color)),null!=t.metalness&&e.push("m"+K_(t.metalness)),null!=t.roughness&&e.push("r"+K_(t.roughness)),null!=t.opacity&&e.push("o"+K_(t.opacity)),null!=t.emissive&&e.push("E"+Q_(t.emissive)),null!=t.emissiveIntensity&&e.push("I"+K_(t.emissiveIntensity)),null!=t.envMapIntensity&&e.push("e"+K_(t.envMapIntensity)),null!=t.side&&e.push("s"+t.side),t.transparent&&e.push("t"),t.flatShading&&e.push("f"),!1===t.depthWrite&&e.push("dw0"),t.map&&e.push("M"+(t.map.uuid??"")),e.join("|")}(n);let r=q_.get(s);return r||q_.set(s,r=function(t){const n=new e.MeshStandardMaterial;return n.userData.__bankOwned=!0,null!=t.color&&n.color.set(t.color),null!=t.emissive&&n.emissive.set(t.emissive),null!=t.metalness&&(n.metalness=t.metalness),null!=t.roughness&&(n.roughness=t.roughness),null!=t.emissiveIntensity&&(n.emissiveIntensity=t.emissiveIntensity),null!=t.envMapIntensity&&(n.envMapIntensity=t.envMapIntensity),null!=t.side&&(n.side=t.side),null!=t.map&&(n.map=t.map),null!=t.flatShading&&(n.flatShading=t.flatShading),null!=t.depthWrite&&(n.depthWrite=t.depthWrite),null!=t.opacity&&(n.opacity=t.opacity),null!=t.transparent?n.transparent=t.transparent:null!=t.opacity&&t.opacity<1&&(n.transparent=!0),n}(n)),null==i?r:Gd(r,{color:i})},get size(){return q_.size},has(t){const e=t+"::";for(const t of q_.keys())if(t.startsWith(e))return!0;return!1},dispose(){for(const t of q_.values())Yd(t),t.dispose();q_.clear()}};class J_ extends pu{getObject3dInstance(){return new e.Mesh}build(){super.build(),this.buildGeometry(),this.buildMaterial(),this.updateDimension()}updateAlpha(){if(this.canShareMaterial)return void super.updateAlpha();const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}updateFillStyle(){if(this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const{fillStyle:t,alpha:e=1}=this.component.state,n=this.object3d.material;if(!n)return;const i=pu.buildFillStyleTexture(this.component);i?(n.map&&n.map.dispose(),i.needsUpdate=!0,n.map=i,n.needsUpdate=!0):"string"==typeof t&&(n.map&&(n.map.dispose(),n.map=null,n.needsUpdate=!0),"transparent"!==t&&"none"!==t&&n.color.set(Xd(t))),$d(n,0,t)}updateStrokeStyle(){const t=this.object3d.getObjectByName("__edgeLines__");t&&(this.object3d.remove(t),eu(t));const{strokeStyle:n}=this.component.state;if(!n||"transparent"===n||"none"===n)return;const i=this.object3d.geometry;if(!i?.getAttribute("position"))return;const s=new e.EdgesGeometry(i),r=new e.LineBasicMaterial({color:n}),o=new e.LineSegments(s,r);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 i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}get canShareMaterial(){return void 0===this.materialSharingIssue}get materialSharingIssue(){const{fillStyle:t}=this.component.state;if(!t||"object"!=typeof t)return;const e=t.type;return"pattern"===e?"무늬(pattern) fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":"gradient"===e?"그라디언트 fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":`fillStyle 이 색 문자열이 아니다 (type: ${String(e)})`}get requiresSharedMaterial(){return!0===this.component.constructor.requiresSharedMaterial}get materialSharing(){const t=this.materialSharingIssue,e=void 0===t,n=this.requiresSharedMaterial,i={shared:e,required:n,violated:n&&!e};return void 0!==t&&(i.reason=t),e&&(i.bankKey=this.materialBankKey),i}get materialBankKey(){return`mesh|${this.component.state.type??"unknown"}`}materialSpec(){const t=Md(this.component.state.material3d),e=Ud(this.component.state.fillStyle);return{metalness:t.metalness,roughness:t.roughness,emissive:t.emissive,emissiveIntensity:t.emissiveIntensity,envMapIntensity:t.envMapIntensity,side:kd(t.side),flatShading:t.flatShading,opacity:e,transparent:e<1}}buildMaterial(){if(!this.canShareMaterial){const t=Md(this.component.state.material3d),n=new e.MeshStandardMaterial({transparent:!0});return Ad(n,t),void(this.object3d.material=n)}this.applyBankMaterial()}applyBankMaterial(){const{fillStyle:t}=this.component.state,e=Ud(t)>0&&"string"==typeof t?Xd(t):void 0;Vd(this.object3d),this.object3d.material=Z_.material(this.materialBankKey,this.materialSpec(),e)}updateMaterial3d(){if(super.updateMaterial3d(),this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const t=this.object3d.material;t&&Ad(t,Md(this.component.state.material3d))}clear(){return Vd(this.object3d),eu(this.object3d),super.clear()}}function tv(t,e,n,i){return[["bold",t],["italic",e],[n+"px",!0],[i,!0]].filter(t=>t[1]).map(t=>t[0]).join(" ")}function ev(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 nv(t,e,n){const{bold:i=!1,italic:s=!1,fontFamily:r="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",width:h=t.width,height:d=t.height,offsetX:u=0,offsetY:p=0}=n||{},f=t.getContext("2d");let m,g;f.imageSmoothingEnabled=!1,f.fillStyle=a,f.strokeStyle=a,f.font=tv(i,s,o,r),"left"===c||"start"===c?(f.textAlign="left",m=u):"right"===c||"end"===c?(f.textAlign="right",m=u+h):(f.textAlign="center",m=u+h/2);const y=1.2*o,b=String(e).split("\n"),_=y*b.length;g="top"===l||"hanging"===l?p+.1*o:"bottom"===l||"alphabetic"===l?p+d-_+.1*o:p+(d-_)/2+.1*o,f.textBaseline="top";for(const t of b)f.fillText(t,m,g),g+=y}function iv(t,n,i,s){const r=ev(2*n),o=ev(2*i),a=Dp(r,o),c=a.getContext("2d"),{fillStyle:l}=s||{};if(l&&"object"==typeof l&&l.colorStops?.length){const t=nu(l,2*n,2*i);t&&c.drawImage(t,0,0)}c.scale(2,2),"string"==typeof l&&""!==l&&"transparent"!==l&&(c.fillStyle=l,c.fillRect(0,0,n,i)),nv(a,t,s);const h=new e.CanvasTexture(a);return h.needsUpdate=!0,h.wrapS=e.RepeatWrapping,h.wrapT=e.RepeatWrapping,h.offset.set(0,1-2*i/o),h.repeat.set(2*n/r,2*i/o),h.minFilter=e.LinearFilter,h.colorSpace=e.SRGBColorSpace,h}function sv(t,n,i,s,r,o,a){const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const t=2*i,l=2*s,h=ev(t),d=ev(l),u=Dp(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),i=2*(o.offsetX||0),s=2*(o.offsetY||0);let r=0,a=0;switch(o.align){case"center":r=(t-e)/2,a=(l-n)/2;break;case"left-top":break;case"left-bottom":a=l-n;break;case"right-top":r=t-e;break;case"right-bottom":r=t-e,a=l-n;break;case"left":a=(l-n)/2;break;case"right":r=t-e,a=(l-n)/2;break;case"top":r=(t-e)/2;break;case"bottom":r=(t-e)/2,a=l-n}const h=i+r,d=s+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 i=h>0?h-Math.ceil(h/e)*e:h;for(let s=d>0?d-Math.ceil(d/n)*n:d;s<l;s+=n)for(let r=i;r<t;r+=e)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,r,s,e,n);p.restore()}}n&&(p.scale(2,2),nv(u,n,r));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=iv(n,i,s,r);a(t)},c.src=t}function rv(t,e){let{bold:n=!1,italic:i=!1,fontFamily:s="Serif",fontSize:r=10,lineHeight:o="normal"}=e||{};t=void 0===t||""==t?" ":String(t);const a=document.createElement("span");a.style.font=tv(n,i,r,s),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 ov extends J_{get zPriority(){return au.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){this.updateDimension()}updateStrokeStyle(){}updateFillStyle(){this.updateText()}updateDimension(){const{width:t,height:n}=this.component.state,i=Math.abs(t)||1,s=Math.abs(n)||1;this.object3d.geometry&&this.object3d.geometry.dispose();const r=new e.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateText(){const t=this.object3d.material;if(!t)return;const{width:e,height:n,bold:i=!1,italic:s=!1,fontFamily:r="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",m={bold:i,italic:s,fontFamily:r,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 sv(this.component.app.url(h.image),p,d,u,m,h,e=>{t.map&&t.map.dispose(),t.map=e,t.color.set(16777215),t.needsUpdate=!0})}const g=iv(p,d,u,m);g?(t.map&&t.map.dispose(),t.map=g,t.color.set(16777215),g.needsUpdate=!0):"string"==typeof h&&(""!==h&&"transparent"!==h?t.color.set(Xd(h)):t.opacity=0)}updateAlpha(){const t=this.object3d.material;t.opacity=1,t.transparent=!0,super.applyMaterialOpacity()}}Gp("text",t=>new ov(t));const av={input:"css3d",select:"css3d",textarea:"css3d",button:"css3d",iframe:"css3d",video:"css3d",label:"texture",table:"texture",progress:"texture"};function cv(t){const e=t.model?.type??"";return"texture"===(av[e]??"css3d")?new X_(t):new Np(t)}Gp("html-overlay-element",cv),Gp("html-overlay-container",cv);class lv{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,i,s,r){const o=n[3*i],a=n[3*i+1],c=n[3*s],l=n[3*s+1],h=n[3*r],d=n[3*r+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,i,s,r,o){const a=n[3*i],c=n[3*i+1],l=n[3*i+2],h=n[3*s],d=n[3*s+1],u=n[3*s+2],p=n[3*r],f=n[3*r+1],m=n[3*r+2],g=n[3*o],y=n[3*o+1],b=n[3*o+2],_=this.extrudedOptions?.depth||100,v=this.bb,x=v.max.x-v.min.x,w=v.max.y-v.min.y;return Math.abs(c-d)<.01?[new e.Vector2(a/x,1-l/_),new e.Vector2(h/x,1-u/_),new e.Vector2(p/x,1-m/_),new e.Vector2(g/x,1-b/_)]:[new e.Vector2(c/w,1-l/_),new e.Vector2(d/w,1-u/_),new e.Vector2(f/w,1-m/_),new e.Vector2(y/w,1-b/_)]}}function hv(t,e){const n=t/2,i=e/2;return{points:[{x:-n,y:-i},{x:n,y:-i},{x:n,y:i},{x:-n,y:i}]}}function dv(t,e,n){const i=Math.max(3,Math.floor(n)),s=[];for(let n=0;n<i;n++){const r=n/i*Math.PI*2;s.push({x:t*Math.cos(r),y:e*Math.sin(r)})}return{points:s,segments:i}}function uv(t){if(0===t.length)return[];let e=1/0,n=1/0,i=-1/0,s=-1/0;for(const r of t)r.x<e&&(e=r.x),r.x>i&&(i=r.x),r.y<n&&(n=r.y),r.y>s&&(s=r.y);const r=(e+i)/2,o=(n+s)/2,a=t.map(t=>({x:t.x-r,y:t.y-o})),c=a[0],l=a[a.length-1];return a.length>1&&Math.abs(c.x-l.x)<1e-9&&Math.abs(c.y-l.y)<1e-9&&a.pop(),a}class pv extends pu{clear(){return this._mesh=void 0,super.clear()}get shape(){return null}topOutline(){const t=this.shape;if(!t||"function"!=typeof t.getPoints)return null;const e=this.outlineDivisions,n=t.getPoints(e);if(!n||n.length<3)return null;const i=uv(n);return i.length<3?null:{points:i}}get outlineDivisions(){return 12}get boundUVGenerator(){return this._boundUVGenerator||(this._boundUVGenerator=new lv),this._boundUVGenerator}build(){super.build();const t=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator;i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:t}});const s=this.createGeometry(n),r=this.createMaterials();this._mesh=new e.Mesh(s,r),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:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new e.ExtrudeGeometry(t,s);return r.center(),r}createMaterials(){const t=Md(this.component.state.material3d),n=new e.MeshStandardMaterial;Ad(n,t);const i=new e.MeshStandardMaterial;return Ad(i,t),[n,i]}createTexture(){const{width:t,height:n}=this.component.bounds,i=ev(t),s=ev(n),r=Dp(i,s);this.component.render(r.getContext("2d"));const o=new e.CanvasTexture(r);return o.needsUpdate=!0,o.wrapS=e.RepeatWrapping,o.wrapT=e.RepeatWrapping,o.offset.set(0,1-n/s),o.repeat.set(t/i,n/s),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=Md(this.component.state.material3d);for(const n of t)Ad(n,e)}updateAlpha(){const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this.getMaterials();i&&($d(i[0],0,e),$d(i[1],0,n))}updateStrokeStyle(){const t=this.getMaterials();if(!t)return;const{strokeStyle:e}=this.component.state;t[1].color.set(Xd(e))}updateFillStyle(){this._applyCapTexture()}updateText(){this._applyCapTexture()}_applyCapTexture(){const t=this.getMaterials();if(!t)return;const e=t[0],{fillStyle:n}=this.component.state,i=this.component.hasTextProperty?this.component.text:"";if(!i){const t=pu.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(Xd(n))),void(e.needsUpdate=!0)}const{bold:s=!1,italic:r=!1,fontFamily:o="Serif",fontSize:a=10,fontColor:c="black",textAlign:l="center",textBaseline:h="middle",paddingTop:d=0,paddingLeft:u=0,paddingRight:p=0,paddingBottom:f=0}=this.component.state,{width:m,height:g}=this.component.bounds,y=Math.abs(m)||1,b=Math.abs(g)||1,_={bold:s,italic:r,fontFamily:o,fontSize:a,fontColor:c,textAlign:l,textBaseline:h,width:Math.max(y-u-p,0),height:Math.max(b-d-f,0),fillStyle:n,offsetX:u,offsetY:d};if("object"==typeof n&&"pattern"===n?.type&&n.image){return void sv(this.component.app.url(n.image),i,y,b,_,n,t=>{e.map&&e.map.dispose(),e.map=t,e.color.set(16777215),e.needsUpdate=!0})}e.map&&e.map.dispose();const v=iv(i,y,b,_);e.map=v,e.color.set(16777215),e.needsUpdate=!0}updateDimension(){super.updateDimension()}onchange(t,e){if("path"in t&&this._mesh){const t=this._mesh.geometry,e=this.shape;if(e){const n=this.createGeometry(e);this._mesh.geometry=n,t.dispose()}}super.onchange(t,e)}}class fv extends pv{get shape(){const{cx:t=0,cy:n=0,rx:i=1,ry:s=1,startAngle:r=0,endAngle:o=2*Math.PI,anticlockwise:a=!1}=this.component.state,c=new e.EllipseCurve(t,n,Math.abs(i),Math.abs(s),r,o,a,0);return new e.Shape(c.getPoints(50))}}Gp("ellipse",t=>new fv(t));class mv extends pv{get shape(){const{width:t,height:n,round:i=0}=this.component.state,s=Oc(i,t,n);if(s>0){const i=s,r=new e.Path;return r.moveTo(i,0),r.lineTo(t-i,0),r.quadraticCurveTo(t,0,t,i),r.lineTo(t,n-i),r.quadraticCurveTo(t,n,t-i,n),r.lineTo(i,n),r.quadraticCurveTo(0,n,0,n-i),r.lineTo(0,i),r.quadraticCurveTo(0,0,i,0),new e.Shape(r.getPoints(12))}const r=new e.Shape;return r.moveTo(0,0),r.lineTo(t,0),r.lineTo(t,n),r.lineTo(0,n),r.lineTo(0,0),r}}function gv(t,n={}){const i=n.round??0,s=n.divisions??24;if(!t||0===t.length)return new e.Shape;const r=t.some(t=>Kr(t)),o=i>0||t.some(t=>to(t,0)>0);if(r||o){const n=new e.Path;for(let e=0;e<t.length;e++){const s=t[(e-1+t.length)%t.length],r=t[e],o=t[(e+1)%t.length];if(s.x===r.x&&s.y===r.y)continue;const a=to(r,i);let c=Math.sqrt((s.x-r.x)**2+(s.y-r.y)**2),l=0!==c?Math.atan2(s.x-r.x,s.y-r.y):0;const h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;c=Math.sqrt((o.x-r.x)**2+(o.y-r.y)**2),l=0!==c?Math.atan2(o.x-r.x,o.y-r.y):0;const u=Math.sin(l)*Math.min(a,c/2)+r.x,p=Math.cos(l)*Math.min(a,c/2)+r.y;if(0===e?n.moveTo(h,d):n.lineTo(h,d),a>0&&n.quadraticCurveTo(r.x,r.y,u,p),Kr(r)){const t=to(o,i),e=Math.sqrt((r.x-o.x)**2+(r.y-o.y)**2),s=0!==e?Math.atan2(r.x-o.x,r.y-o.y):0,a=Qr({x:u,y:p},{x:Math.sin(s)*Math.min(t,e/2)+o.x,y:Math.cos(s)*Math.min(t,e/2)+o.y},r.bulge);a&&n.absarc(a.cx,a.cy,a.radius,a.startAngle,a.endAngle,a.clockwise)}}return new e.Shape(n.getPoints(s))}const a=new e.Shape;for(let e=0;e<t.length;e++)0===e?a.moveTo(t[e].x,t[e].y):a.lineTo(t[e].x,t[e].y);return a}Gp("rect",t=>new mv(t));class yv extends pv{get shape(){const{path:t=[],round:e=0}=this.component.state;return gv(t,{round:e,divisions:24})}build(){Object.getPrototypeOf(pv.prototype).build.call(this);const t=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator,s=this.minMax;if(i&&void 0!==s.minX&&void 0!==s.maxX&&void 0!==s.minY&&void 0!==s.maxY){const n=new e.Shape;n.moveTo(s.minX,s.minY),n.lineTo(s.maxX,s.minY),n.lineTo(s.maxX,s.maxY),n.lineTo(s.minX,s.maxY),n.closePath(),i.setShape({extrudedShape:n,extrudedOptions:{depth:t}})}else i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:t}});const r=this.createGeometry(n),o=this.createMaterials();this._mesh=new e.Mesh(r,o),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:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new e.ExtrudeGeometry(t,s),o=this.minMax;if(void 0!==o.minX&&void 0!==o.maxX&&void 0!==o.minY&&void 0!==o.maxY){const t=(o.minX+o.maxX)/2,e=(o.minY+o.maxY)/2;r.translate(-t,-e,0),r.computeBoundingBox();const n=r.boundingBox;n&&r.translate(0,0,-(n.min.z+n.max.z)/2)}else r.center();return r}get minMax(){if(!this._minMax){const{path:t}=this.component.state;let e,n,i,s;t.forEach((t,r)=>{if(0==r)return e=i=t.x,void(n=s=t.y);e=Math.min(e,t.x),i=Math.max(i,t.x),n=Math.min(n,t.y),s=Math.max(s,t.y)}),this._minMax={minX:e,minY:n,maxX:i,maxY:s}}return this._minMax}}Gp("polygon",t=>new yv(t));class bv extends pv{get shape(){const{cx:t=0,cy:n=0,rx:i=1,ry:s=1,ratio:r=50,startAngle:o=0,endAngle:a=2*Math.PI,anticlockwise:c=!1}=this.component.state,l=Math.abs(i),h=Math.abs(s),d=new e.EllipseCurve(t,n,l,h,o,a,c,0),u=new e.Shape(d.getPoints(50)),p=l/100*r,f=h/100*r;if(p>0&&f>0){const i=new e.EllipseCurve(t,n,p,f,o,a,c,0),s=new e.Path(i.getPoints(50));u.holes.push(s)}return u}}Gp("donut",t=>new bv(t));class _v extends pv{get shape(){const{x1:t=0,y1:n=0,x2:i=0,y2:s=0,x3:r=0,y3:o=0,round:a=0}=this.component.state,c=[{x:t,y:n},{x:i,y:s},{x:r,y:o}];if(a>0){const t=new e.Path;for(let e=0;e<c.length;e++){const n=c[(e-1+c.length)%c.length],i=c[e],s=c[(e+1)%c.length];let r=Math.sqrt((n.x-i.x)**2+(n.y-i.y)**2),o=0!==r?Math.atan2(n.x-i.x,n.y-i.y):0;const l=Math.sin(o)*Math.min(a,r/2)+i.x,h=Math.cos(o)*Math.min(a,r/2)+i.y;r=Math.sqrt((s.x-i.x)**2+(s.y-i.y)**2),o=0!==r?Math.atan2(s.x-i.x,s.y-i.y):0;const d=Math.sin(o)*Math.min(a,r/2)+i.x,u=Math.cos(o)*Math.min(a,r/2)+i.y;0===e?t.moveTo(l,h):t.lineTo(l,h),t.quadraticCurveTo(i.x,i.y,d,u)}return new e.Shape(t.getPoints(12))}const l=new e.Shape;return l.moveTo(t,n),l.lineTo(i,s),l.lineTo(r,o),l.closePath(),l}}Gp("triangle",t=>new _v(t));class vv extends pv{get shape(){const{ratio:t=30,wing:n=5,cx:i=0,cy:s=0,rx:r=1,ry:o=1}=this.component.state;if(n<3)return null;const a=Math.PI/2,c=2*Math.PI/n,l=r-t/100*r,h=o-t/100*o,d=new e.Shape;d.moveTo(i+r*Math.cos(-a),s+o*Math.sin(-a)),d.lineTo(i+(r-l)*(Math.cos(c-a)+Math.cos(0-a))/2,s+(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let t=1;t<n;t++)d.lineTo(i+r*Math.cos(c*t-a),s+o*Math.sin(c*t-a)),d.lineTo(i+(r-l)*(Math.cos(c*(t+1)-a)+Math.cos(c*t-a))/2,s+(o-h)*(Math.sin(c*(t+1)-a)+Math.sin(c*t-a))/2);return d.closePath(),d}}Gp("star",t=>new vv(t));const xv=new Map;function wv(t){return t.userData.__bankOwned=!0,t}const Mv={primitive(t){const n="primitive::"+function(t){switch(t.kind){case"cylinder":return`cylinder|${t.segments??0}`;case"sphere":return`sphere|${t.segments??0}|${t.heightSegments??0}`;default:return t.kind}}(t);let i=xv.get(n);return i||xv.set(n,i=wv(function(t){switch(t.kind){case"box":return new e.BoxGeometry(1,1,1);case"plane":return new e.PlaneGeometry(1,1);case"cylinder":return new e.CylinderGeometry(.5,.5,1,t.segments??16);case"sphere":return new e.SphereGeometry(.5,t.segments??16,t.heightSegments??Math.max(2,Math.round((t.segments??16)/2)))}}(t))),i},shaped(t,e){const n="shaped::"+t;let i=xv.get(n);return i||xv.set(n,i=wv(e())),i},owns:t=>!0===t.userData?.__bankOwned,get size(){return xv.size},has:t=>xv.has("primitive::"+t)||xv.has("shaped::"+t),dispose(){for(const t of xv.values())t.dispose();xv.clear()}},Sv=[8,12,16],kv={cylinder:25,sphere:32},Av=3,Ev=128;function Cv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(Ev,Math.max(3,Math.floor(t))):e}function Tv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(Ev,Math.max(2,Math.floor(t))):Math.max(2,Math.round(e/2))}function Pv(t){return Sv.includes(t)}const Ov={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"},{type:"number",label:"height-segments",name:"heightSegments",property:"heightSegments"}],help:"scene/component/sphere"};class Dv extends J_{buildGeometry(){const t=this.component.state,e=Cv(t.segments,kv.sphere),n=Tv(t.heightSegments,e);this.object3d.geometry=Mv.primitive({kind:"sphere",segments:e,heightSegments:n})}updateDimension(){const{rx:t=0,ry:e=0,rz:n}=this.component.state,i=n??t;this.setDimensionScale(2*t,2*i,2*e)}get effectiveDepth(){const{rx:t=0,rz:e}=this.component.state,n=e??t;return Math.max(2*n,1)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return dv(t,e,Cv(this.component.state.segments,kv.sphere))}}let zv=class extends hg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Dv(this)}get nature(){return Ov}};zv=Nm([Sy("sphere")],zv);class Iv extends pu{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(),i=this.component.parent?._realObject;return t+n+e/2-(i?.geometricOffsetY??0)}get geometricOffsetY(){const{height:t=0}=this.component.bounds;return t/2}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=pu.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(Xd(t)):e.opacity=0)}}class Rv extends Iv{buildMaterial(){const t=this.object3d.material;t&&t.dispose(),this.object3d.material=new e.SpriteMaterial({map:Y_(this.component),alphaTest:.01,sizeAttenuation:!1})}get scale(){const{width:t,height:e}=this.component.bounds,n=this.threeContainer,{width:i=1,height:s=1}=n?.bounds??{},{scale:r=1}=this.component.state;return{x:r*t/i,y:r*e/s,z:r}}update(){this.build(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateAlpha(){this.update()}updateText(){this.update()}}const jv={mutable:!1,resizable:!0,rotatable:!0,properties:[]};let Lv=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Rv(this)}get nature(){return jv}};Lv=Nm([Sy("sprite")],Lv);const Fv={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cube"};class Nv extends J_{buildGeometry(){this.object3d.geometry=Mv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?hv(t,e):null}}let Hv=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Nv(this)}get nature(){return Fv}};Hv=Nm([Sy("cube")],Hv);const Bv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"}],help:"scene/component/cylinder"};class Gv extends J_{buildGeometry(){const t=Cv(this.component.state.segments,kv.cylinder);this.object3d.geometry=Mv.primitive({kind:"cylinder",segments:t})}updateDimension(){const{rx:t=0,ry:e=0,depth:n=1}=this.component.state;this.setDimensionScale(2*t,n,2*e)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return dv(t,e,Cv(this.component.state.segments,kv.cylinder))}}let Vv=class extends hg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Gv(this)}get nature(){return Bv}};Vv=Nm([Sy("cylinder")],Vv);const Yv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"color",label:"box-color",name:"boxColor",property:"boxColor"}],help:"scene/component/banner"};class Wv extends pu{get zPriority(){return au.DECAL}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 i=this.createTextureBoard(t,n);i.position.set(0,0,.5*e+1),this.object3d.add(i)}createCube(t,n,i){const{boxColor:s="#ccaa76"}=this.component.state,r=Md(this.component.state.material3d),o=new e.BoxGeometry(t,i,n),a=new e.MeshStandardMaterial({color:s,side:e.FrontSide});Ad(a,r);const c=new e.Mesh(o,a);return c.castShadow=r.castShadow,c.receiveShadow=r.receiveShadow,c}createTextureBoard(t,n){const i=Md(this.component.state.material3d),{fillStyle:s="#ccaa76"}=this.component.state,r=pu.buildFillStyleTexture(this.component),o=new e.MeshStandardMaterial(r?{map:r}:{color:s||"#ccaa76",side:e.FrontSide});Ad(o,i);const a=new e.PlaneGeometry(t,n,1,1),c=new e.Mesh(a,o);return c.castShadow=i.castShadow,c.receiveShadow=i.receiveShadow,c}updateMaterial3d(){super.updateMaterial3d();const t=Md(this.component.state.material3d);this.object3d.traverse(e=>{if(e.isMesh){const n=e.material;n&&Ad(n,t),e.castShadow=t.castShadow,e.receiveShadow=t.receiveShadow}})}updateFillStyle(){this.update()}onchange(t,e){super.onchange(t,e),"boxColor"in t&&this.update()}}let Uv=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Yv}buildRealObject(){return new Wv(this)}};var $v;Uv=Nm([Sy("banner")],Uv);const Xv={far:1e5,fov:80,near:1,zoom:1},qv={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 Kv extends pu{getObject3dInstance(){return new e.Mesh}updateCamera(){const{near:t=Xv.near,far:n=Xv.far,fov:i=Xv.fov,zoom:s=Xv.zoom,showHelper:r}=this.component.state;this.camera.far=n,this.camera.fov=i,this.camera.near=t,this.camera.zoom=s,r?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:i=0,fillStyle:s="lightgray"}=this.component.state;this.object3d.geometry=new e.BoxGeometry(t,i,n);const r=Md(this.component.state.material3d),o=new e.MeshStandardMaterial({color:s});Ad(o,r),this.object3d.material=o,this.object3d.castShadow=r.castShadow,this.object3d.receiveShadow=r.receiveShadow,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()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Md(this.component.state.material3d);Ad(t,e),this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}}let Qv=$v=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}static get image(){return $v._image||($v._image=new Image,$v._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=="),$v._image}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,$v.image,e,n,i,s)}buildRealObject(){return new Kv(this)}get nature(){return qv}};Qv=$v=Nm([Sy("camera")],Qv);const Zv={mutable:!1,resizable:!0,rotatable:!0,properties:[...wy],"value-property":"source",help:"scene/component/gltf-object"};let Jv=class extends(My(Dc(Pc))){get nature(){return Zv}};Jv=Nm([Sy("gltf-object")],Jv);const tx={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 ex extends pu{updatePointLight(){const{lightType:t="point",distance:n=0,intensity:i=10,decay:s=1,fillStyle:r="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(r),"point"==t&&(this.object3d.distance=n,this.object3d.decay=s),this.object3d.intensity=i,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 nx=class extends hg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new ex(this)}get anchors(){return[]}get nature(){return tx}};nx=Nm([Sy("light")],nx);const ix={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"}],help:"scene/component/wall"};class sx extends J_{buildGeometry(){this.object3d.geometry=Mv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?hv(t,e):null}}let rx=class extends(Dc(Pc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new sx(this)}get nature(){return ix}};rx=Nm([Sy("wall")],rx);const ox={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"},{type:"checkbox",label:"hide-in-2d-view",name:"hideIn2DView"},{type:"checkbox",label:"hide-in-3d-view",name:"hideIn3DView"}],help:"scene/component/floor-plate"};class ax extends pu{get zPriority(){return au.FLOOR}get receivingSurfaceY(){return this.placementSurfaceY()}resolveShadow(){const t=this.component.state,e=t.material3d,{alpha:n=1,fillStyle:i}=t,s=n>=.9&&"none"!==i;return{receive:e?.receiveShadow??!0,cast:e?.castShadow??s}}updateHidden(){const t=this.component.state,e=!!this.component.app?.isViewMode;this.object3d.visible=!(t.hidden||e&&t.hideIn3DView)}clear(){return this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0),this._mesh=void 0,super.clear()}build(){super.build();const{width:t,height:n,depth:i=1}=this.component.state;if(!t||!n)return;const s=Math.abs(t),r=Math.abs(n),o=Math.max(i,.5),a=new e.BoxGeometry(s,o,r),c=this._buildTopMaterial(),l=this._buildSideMaterial(),h=[l,l,c,l,l,l];this._mesh=new e.Mesh(a,h),this._mesh.position.y=0;const{cast:d,receive:u}=this.resolveShadow();this._mesh.castShadow=d,this._mesh.receiveShadow=u,this.object3d.add(this._mesh)}_buildTopMaterial(){const{alpha:t=1,fillStyle:n}=this.component.state,i=Md(this.component.state.material3d),s=pu.buildFillStyleTexture(this.component);if(s){this._topTexture=s;const t=new e.MeshStandardMaterial({map:s,side:e.DoubleSide});return $d(t,0,n),t.depthWrite=t.opacity>=.9,Ad(t,i),t}const r="string"==typeof n&&"none"!==n?Xd(n):"#e0e0e0",o=new e.MeshStandardMaterial({color:r,side:e.DoubleSide});return $d(o,0,n),o.depthWrite=o.opacity>=.9,Ad(o,i),o}_buildSideMaterial(){const{strokeStyle:t,alpha:n=1}=this.component.state,i="string"==typeof t&&t?Xd(t):"#999999",s=Md(this.component.state.material3d),r=new e.MeshStandardMaterial({color:i});return Ad(r,s),r.side=e.DoubleSide,$d(r,0,t),r.depthWrite=r.opacity>=.9,r}updateAlpha(){if(!this._mesh)return;const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this._mesh.material;for(let t=0;t<i.length;t++){const s=i[t];$d(s,0,2===t?e:n),s.depthWrite=s.opacity>=.9}}updateFillStyle(){if(!this._mesh)return;this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0);const t=this._mesh.material;t[2].dispose(),t[2]=this._buildTopMaterial()}updateStrokeStyle(){if(!this._mesh)return;const t=this._mesh.material,e=this._buildSideMaterial();for(let n=0;n<t.length;n++)2!==n&&(t[n].dispose(),t[n]=e)}}let cx=class extends Kl{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new ax(this)}get nature(){return ox}get hidden(){return!!this.getState("hideIn2DView")||super.hidden}};cx.requires3d=!0,cx=Nm([Sy("floor-plate")],cx);function lx(t,n={}){const i=n.size??5,s=n.color??4500172,r=n.emissive??2245734,o=new e.SphereGeometry(i,16,12),a=new e.MeshStandardMaterial({color:s,emissive:r,emissiveIntensity:.15,metalness:.3,roughness:.4,transparent:!0,opacity:.35}),c=new e.Mesh(o,a);n.position&&c.position.set(n.position[0],n.position[1],n.position[2]),c.userData.alwaysRaycast=!0,c.scale.setScalar(1),c.visible=n.visible??!(!0===t.app?.isViewMode);const l=()=>{a.emissiveIntensity=.9,a.opacity=.95,c.scale.setScalar(1.35),t.invalidate?.()},h=()=>{a.emissiveIntensity=.15,a.opacity=.35,c.scale.setScalar(1),t.invalidate?.()};return t.on("mouseenter",l),t.on("mouseleave",h),c.userData.dispose=()=>{t.off("mouseenter",l),t.off("mouseleave",h)},c}class hx extends J_{get zPriority(){return au.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){const{width:t,height:n}=this.component.state,i=Math.abs(t)||1,s=Math.abs(n)||1,r=new e.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateDimension(){this.update()}build(){super.build();const{width:t,height:e}=this.component.state,n=Math.abs(t)||1,i=Math.abs(e)||1,s=Math.max(2,.04*Math.min(n,i));this.object3d.add(lx(this.component,{size:s,position:[n/2-s,s,-i/2+s]}))}}const dx={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/decal"};let ux=class extends(vy(Dc(Pc))){buildRealObject(){return new hx(this)}get nature(){return dx}};ux=Nm([Sy("decal")],ux);class px extends pu{getObject3dInstance(){return new e.Group}get allowedGizmoModes(){return this.component.isGroup?.()?["translate"]:null}}const fx="#dde2e8",mx="#9c9c9c",gx="#e8e8ec",yx=.35;function bx(t,n,i,s,r){if(!n.visible)return new e.MeshStandardMaterial({transparent:!0,opacity:0,depthWrite:!1});const o=n.alpha*i,a="wall"===s?fx:"floor"===s?mx:gx,c=new e.MeshStandardMaterial({metalness:0,roughness:"wall"===s?.6:.85,transparent:o<1,opacity:o,side:r?e.BackSide:e.DoubleSide});return function(t,e,n,i,s,r){if("string"==typeof n&&n&&"transparent"!==n)t.color.set(n);else{if(n&&"object"==typeof n){const i=!r,o=pu.buildFillStyleTexture(e,n,{mirror:i,rotation:s});if(o)return t.map&&t.map.dispose(),t.map=o,void t.color.set("#ffffff")}t.color.set(i)}}(c,t,n.fillStyle,a,n.rotation,n.mirror),c}class _x extends px{get zPriority(){return au.BACKDROP}get position(){if(this.component.state.fitToBoard){return{x:0,y:super.position.y,z:0}}return super.position}build(){super.build();const t=this.component.state;let n=t.width,i=t.height;if(t.fitToBoard){const t=this.component.rootModel,e=t?.state;e&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&(n=e.width,i=e.height)}const s=this.effectiveDepth||Math.min(n,i)||200,r=t.alpha??1,o=!1!==t.seeThrough,a={east:this._resolveFace("east",fx,!0,yx),west:this._resolveFace("west",fx,!0,yx),north:this._resolveFace("north",fx,!0,yx),south:this._resolveFace("south",fx,!0,yx),floor:this._resolveFace("floor",mx,!0,1),ceiling:this._resolveFace("ceiling",gx,!0,1)},c=[bx(this.component,a.east,r,"wall",o),bx(this.component,a.west,r,"wall",o),bx(this.component,a.ceiling,r,"ceiling",o),bx(this.component,a.floor,r,"floor",o),bx(this.component,a.south,r,"wall",o),bx(this.component,a.north,r,"wall",o)],l=new e.BoxGeometry(n,s,i),h=new e.Mesh(l,c);if(h.receiveShadow=!0,this.object3d.add(h),this.component.app?.isEditMode){const t=new e.LineBasicMaterial({color:4473941,transparent:!0,opacity:.7}),n=new e.LineSegments(new e.EdgesGeometry(l),t);this.object3d.add(n)}const d=Math.max(2,.04*Math.min(n,i,s));this.object3d.add(lx(this.component,{size:d,position:[n/2,s/2+d,-i/2]}))}_resolveFace(t,e,n,i){const s=this.component.state,r=s.faces?.[t]??{},o=r.visible,a=r.alpha,c=r.rotation,l=90===c||180===c||270===c?c:0;return{fillStyle:r.fillStyle??e,visible:"boolean"==typeof o?o:n,alpha:"number"==typeof a&&Number.isFinite(a)?a:i,rotation:l,mirror:!0===r.mirror}}updateDimension(){}onchange(t,e){["alpha","width","height","depth","fitToBoard","faces","seeThrough"].some(e=>e in t)?this.update():super.onchange(t,e)}updateAlpha(){}}const vx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"checkbox",label:"fit-to-board",name:"fitToBoard"},{type:"checkbox",label:"see-through",name:"seeThrough"},{type:"backdrop-faces",label:"",name:"faces"}],help:"scene/component/backdrop"};let xx=class extends(vy(Dc(Pc))){buildRealObject(){return new _x(this)}get nature(){return vx}added(t){super.added?.(t),this.state.fitToBoard&&(this._syncFromRoot(!0),this._attachRootListener())}async ready(){await super.ready(),this.state.fitToBoard&&this._syncFromRoot(!1)}removed(t){this._detachRootListener(),super.removed?.(t)}dispose(){this._detachRootListener(),super.dispose?.()}onchange(t,e){"fitToBoard"in t&&(t.fitToBoard?(this._syncFromRoot(!0),this._attachRootListener()):this._detachRootListener()),super.onchange?.(t,e)}_syncFromRoot(t=!1){const e=this.rootModel;if(!e||e===this)return;const n=e.state;if(!n)return;const i={},s=Number.isFinite(n.width)?n.width:this.state.width,r=Number.isFinite(n.height)?n.height:this.state.height;s!==this.state.width&&(i.width=s),r!==this.state.height&&(i.height=r);const o=Number.isFinite(n.left)?n.left:0,a=Number.isFinite(n.top)?n.top:0;if(o!==this.state.left&&(i.left=o),a!==this.state.top&&(i.top=a),t){const t=this.state.depth;if(!("number"==typeof t&&Number.isFinite(t)&&t>0)){const e=Math.min(s,r);e!==t&&(i.depth=e)}}Object.keys(i).length>0&&this.set(i)}_attachRootListener(){if(this._onRootChange)return;const t=this.rootModel;t&&t!==this&&(this._onRootChange=t=>{("width"in t||"height"in t||"left"in t||"top"in t)&&this._syncFromRoot()},t.on?.("change",this._onRootChange))}_detachRootListener(){if(!this._onRootChange)return;const t=this.rootModel;t?.off?.("change",this._onRootChange),this._onRootChange=void 0}};function wx(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Mx(t,n,i,s){const r=[];for(let o=1;o<=s;o++){const a=o/s,c=1-a;r.push(new e.Vector3(c*c*t.x+2*c*a*n.x+a*a*i.x,c*c*t.y+2*c*a*n.y+a*a*i.y,c*c*t.z+2*c*a*n.z+a*a*i.z))}return r}xx=Nm([Sy("backdrop")],xx);class Sx extends pu{getObject3dInstance(){return new e.Group}get gizmoTransformable(){return!0}get syncZPosOffset(){return 0}get geometricOffsetY(){return 0}syncFromObject3D(){}applyDimensionFromGizmo(t){}build(){super.build(),this._buildLine()}get smoothedPath(){const t=this.worldPath;if(t.length<2)return t;const{round:n=0}=this.component.state;if(n<=0||t.length<3)return t;const i=[];i.push(t[0]);for(let s=1;s<t.length;s++){const r=t[s-1],o=t[s],a=t[s+1];if(!a){i.push(o);break}const c=r.x-o.x,l=r.y-o.y,h=r.z-o.z,d=Math.sqrt(c*c+l*l+h*h),u=Math.min(n,d/2),p=a.x-o.x,f=a.y-o.y,m=a.z-o.z,g=Math.sqrt(p*p+f*f+m*m),y=Math.min(n,g/2),b=d>0?new e.Vector3(o.x+c/d*u,o.y+l/d*u,o.z+h/d*u):o.clone(),_=g>0?new e.Vector3(o.x+p/g*y,o.y+f/g*y,o.z+m/g*y):o.clone();i.push(b),i.push(...Mx(b,o,_,8))}return i}_buildLine(){const t=this.smoothedPath;if(t.length<2)return;const{strokeStyle:n,lineWidth:i=2,alpha:s=1,lineDash:r,begin:o="none",beginSize:a="size5",end:c="none",endSize:l="size5"}=this.component.state,h=Math.max(i,1),d="string"==typeof n&&"transparent"!==n?Xd(n):"#000000",u=new e.Color(d),p=this._getResolution(),f=o,m=c,g=wx(f,h),y=wx(m,h),b=t[0],_=t[t.length-1],v=(new e.Vector3).subVectors(t[1],b).normalize(),x=(new e.Vector3).subVectors(t[t.length-2],_).normalize(),k=[...t];g>0&&(k[0]=b.clone().add(v.clone().multiplyScalar(g))),y>0&&(k[k.length-1]=_.clone().add(x.clone().multiplyScalar(y)));const A=new S;A.setPositions(k.flatMap(t=>[t.x,t.y,t.z]));const E=function(t,e){switch(t){case"round-dot":return{dashSize:e,gapSize:e};case"square-dot":return{dashSize:2*e,gapSize:e};case"dash":return{dashSize:4*e,gapSize:1.5*e};case"dash-dot":return{dashSize:4*e,gapSize:2*e};case"long-dash":return{dashSize:6*e,gapSize:3*e};case"long-dash-dot":return{dashSize:6*e,gapSize:2*e};case"long-dash-dot-dot":return{dashSize:6*e,gapSize:e};default:return null}}(r,h),C=new M({color:u.getHex(),linewidth:h,worldUnits:!0,transparent:s<1,opacity:s,resolution:p,dashed:!!E,dashSize:E?.dashSize??1,gapSize:E?.gapSize??1,dashScale:1});if(this._line2=new w(A,C),this._line2.computeLineDistances(),this.object3d.add(this._line2),"none"!==f){const t=Rp(f,Ip(a,h));if(t){const n=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),v.clone().negate());this._placeTip(t,b,n,u,s,p)}}if("none"!==m){const t=Rp(m,Ip(l,h));if(t){const n=(new e.Quaternion).setFromUnitVectors(new e.Vector3(1,0,0),x.clone().negate());this._placeTip(t,_,n,u,s,p)}}}_placeTip(t,e,n,i,s,r){const o=t.mesh||t.line2||t.group;if(o){if(o.position.copy(e),o.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(i),e.transparent=s<1,e.opacity=s}else if(t.line2){const e=t.line2.material;e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution.copy(r)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color&&e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution&&e.resolution.copy(r)}});this.object3d.add(o)}}_getResolution(){const t=this.threeContainer?.renderer3d;if(t){return t.getSize(new e.Vector2)}return new e.Vector2(window.innerWidth,window.innerHeight)}onGizmoDragEnd(t){const e=this._component,n=e.path;if(!n||n.length<2)return;const i=this.object3d,{width:s=0,height:r=0}=e.parent?.bounds??{},{x:o,y:a}=e.center,c=i.position,l=i.rotation,h=i.scale,d=this.position;if(Math.abs(c.x-d.x)<.001&&Math.abs(c.y-d.y)<.001&&Math.abs(c.z-d.z)<.001&&Math.abs(l.x)<.001&&Math.abs(l.y)<.001&&Math.abs(l.z)<.001&&Math.abs(h.x-1)<.001&&Math.abs(h.y-1)<.001&&Math.abs(h.z-1)<.001)return;const u=Sx.computeBakedPath(n,{x:o,y:a},{width:s,height:r},i);this._suppressOnchange=!0,e.set({rotation:0,rotationX:0,rotationY:0,zPos:0}),e.mutatePath(null,()=>u),this._suppressOnchange=!1,this.update()}static computeBakedPath(t,n,i,s){const r=i.width,o=i.height,a=n.x,c=n.y;return s.updateMatrixWorld(!0),t.map(t=>{const n=new e.Vector3(t.x-a,t.z||0,t.y-c).applyMatrix4(s.matrixWorld),i={x:n.x+r/2,y:n.z+o/2};return Math.abs(n.y)>.001&&(i.z=n.y),i})}updateStrokeStyle(){this.updateDimension()}updateAlpha(){this.updateDimension()}updateDimension(){this.clear(),this.build()}onchange(t,e){("path"in t||"from"in t||"to"in t)&&(this.updateDimension(),this.updatePosition()),("round"in t||"lineDash"in t||"lineWidth"in t||"begin"in t||"end"in t||"beginSize"in t||"endSize"in t)&&this.updateDimension(),super.onchange(t,e)}clear(){for(;this.object3d.children.length>0;){const t=this.object3d.children[0];this.object3d.remove(t),eu(t)}return this._line2=void 0,super.clear()}}class kx extends Sx{get worldPath(){const t=this.component.path;if(!t||t.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return t.map((s,a)=>{const c=t.length>1?a/(t.length-1):0;return new e.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}Gp("line",t=>new kx(t));class Ax extends Sx{get worldPath(){const t=this.component.path;if(!t||t.length<2)return[];const{x:n,y:i}=this.component.center;return t.map(t=>new e.Vector3(t.x-n,t.z||0,t.y-i))}}Gp("polyline",t=>new Ax(t));class Ex extends Sx{get worldPath(){const t=this.component.drawPath;if(!t||t.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return t.map((s,a)=>{const c=t.length>1?a/(t.length-1):0;return new e.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}Gp("ortholine",t=>new Ex(t)),Gp("group",t=>new px(t));class Cx{constructor(t){this._count=0,this._placements=[],this._geometry=t.geometry,this._material=t.material,this._capacity=Math.max(1,t.capacity??16),this._name=t.name??"instanced",this._castShadow=t.castShadow??!0,this._receiveShadow=t.receiveShadow??!1,this.object3d=new e.Group,this.object3d.name=this._name,this._mesh=this._makeMesh(this._capacity),this.object3d.add(this._mesh)}_makeMesh(t){const n=new e.InstancedMesh(this._geometry,this._material,t);return n.name=this._name+"__instances",n.castShadow=this._castShadow,n.receiveShadow=this._receiveShadow,n.instanceMatrix.setUsage(e.DynamicDrawUsage),n.count=0,n}get mesh(){return this._mesh}get count(){return this._count}get capacity(){return this._capacity}place(t){const e=t.length;if(e>this._capacity){const t=function(t,e=16){let n=Math.max(e,1);for(;n<t;)n*=2;return n}(e,this._capacity);this.object3d.remove(this._mesh),this._mesh.dispose(),this._capacity=t,this._mesh=this._makeMesh(t),this.object3d.add(this._mesh)}this._placements.length=e;for(let n=0;n<e;n++){const e=t[n];this._placements[n]=e,this._writeMatrix(n,e),void 0!==e.color&&this._writeColor(n,e.color)}this._count=e,this._mesh.count=e,this.commit()}update(t,e){t<0||t>=this._count||(this._placements[t]=e,this._writeMatrix(t,e),void 0!==e.color&&this._writeColor(t,e.color),this.commit())}setRotation(t,e){if(t<0||t>=this._count)return;const n=this._placements[t];n&&(n.rotation=e,this._writeMatrix(t,n))}commitMatrices(){this._mesh.instanceMatrix.needsUpdate=!0}setColor(t,e){t<0||t>=this._count||(this._writeColor(t,e),this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0))}indexOf(t){return t>=0&&t<this._count?t:-1}commit(){this._mesh.instanceMatrix.needsUpdate=!0,this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0),this._mesh.computeBoundingSphere()}dispose(){this.object3d.remove(this._mesh),this._mesh.dispose(),this._placements.length=0,this._count=0}_writeMatrix(t,e){const n=Cx;n._p.set(e.position.x,e.position.y,e.position.z);const i=e.rotation;n._e.set(i?.x??0,i?.y??0,i?.z??0),n._q.setFromEuler(n._e);const s=e.scale;"number"==typeof s?n._s.set(s,s,s):n._s.set(s?.x??1,s?.y??1,s?.z??1),n._m.compose(n._p,n._q,n._s),this._mesh.setMatrixAt(t,n._m)}_writeColor(t,e){Cx._c.set(e),this._mesh.setColorAt(t,Cx._c)}}function Tx(t,e,n){const i=Math.max(1,Math.floor(t.x??1)),s=Math.max(1,Math.floor(t.y??1)),r=Math.max(1,Math.floor(t.z??1)),o=e.x??0,a=e.y??0,c=e.z??0,l=n?.x??0,h=n?.y??0,d=n?.z??0,u=[];for(let t=0;t<s;t++)for(let e=0;e<r;e++)for(let n=0;n<i;n++)u.push({position:{x:l+n*o,y:h+t*a,z:d+e*c}});return u}Cx._m=new e.Matrix4,Cx._p=new e.Vector3,Cx._q=new e.Quaternion,Cx._e=new e.Euler,Cx._s=new e.Vector3,Cx._c=new e.Color;class Px extends pu{build(){super.build()}update(){}}const Ox={far:1e5,fov:80,near:1,zoom:1};class Dx extends pu{build(){super.build()}update(){super.update(),this.updateCamera()}getObject3dInstance(){return new e.PerspectiveCamera}updateCamera(){const{near:t=Ox.near,far:e=Ox.far,fov:n=Ox.fov,zoom:i=Ox.zoom}=this.component.state;this.object3d.far=e,this.object3d.fov=n,this.object3d.near=t,this.object3d.zoom=i}}class zx extends J_{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 Ix extends pu{getObject3dInstance(){return new e.Scene}dispose(){for(const t of this.object3d.children)eu(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=af(this.component)}updateTransform(){}updateDimension(){}updatePosition(){}updateRotate(){}updateScale(){}updateAlpha(){}updateHidden(){}get animationMixer(){return this._animationMixer||(this._animationMixer=new e.AnimationMixer(this.object3d)),this._animationMixer}}const Rx=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class jx extends pu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new e.Mesh}build(){super.build();const{width:t,height:n}=this.component.bounds;if(!t||!n)return;const i=Md(this.component.state.material3d),s=new e.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=Y_(this.component),o=new e.MeshStandardMaterial({map:r});Ad(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;$d(this.object3d.material,0,e)}get dimension(){const{width:t,height:e}=this.component.bounds;return{width:t||1,height:e||1,depth:1}}get scale(){const t=super.scale,{width:e,height:n}=this.dimension;return{x:t.x*e,y:t.y,z:t.z*n}}updateDimension(){this.updateTransform()}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this.update()},100)}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(U_(n,this.component,2),e.needsUpdate=!0)}update(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!Rx.has(e)){this._debouncedRebuild();break}}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Md(this.component.state.material3d);Ad(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),eu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const Lx={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 Fx=class extends Xm{constructor(){super(...arguments),this._capability=new zf}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}get hasEnvironment(){return this._capability.hasEnvironment}containable(t){return!0}is3dContainer(){return!0}getLightingConfig(){return{hemisphere:{skyColor:16777215,groundColor:14540253,intensity:1},directional:{color:16777215,intensity:1.2,attachToCamera:!0,castShadow:!1}}}getCss3DSceneAttribute(){return"three-container:css3d-renderer"}init_scene3d(){this._capability.isInitialized&&this._capability.destroy(),this._capability.init(this,{lightingConfig:this.getLightingConfig(),css3DSceneAttribute:this.getCss3DSceneAttribute(),skipEnvironment:!0,skipPostprocessing:!0,skipShadowMap:!0}),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:i,threed:s}=this.state;let{width:r,height:o}=this.bounds;if(r=Math.floor(r),o=Math.floor(o),s){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 s=this._capability.domElement;if(!s||!s.width||!s.height)return;t.drawImage(s,0,0,s.width,s.height,e,n,r,o),i&&this._capability.showDebugFPS(t)}else super.postrender(t)}dispose(){this._capability.dispose(),super.dispose()}get layout(){return Fc.get("three")}get nature(){return Lx}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()}};Fx=Nm([Sy("3d-container")],Fx),Vp(t=>new X_(t));const Nx=1;function Hx(t){return"number"==typeof t&&Number.isFinite(t)}function Bx(t){if(!t||"object"!=typeof t)return!1;const{x:e,y:n,z:i}=t;return Hx(e)&&Hx(n)&&Hx(i)}function Gx(t){const e=[],n=t;if(!n||"object"!=typeof n)return["청사진이 객체가 아니다"];1!==n.version&&e.push(`읽을 수 없는 판이다 — version ${String(n.version)}, 이 판올림은 1 만 읽는다`),"string"==typeof n.type&&0!==n.type.length||e.push("type 이 없다 — 컴포넌트 타입 이름이 곧 청사진을 찾는 키다");const i=n.base;return i&&Hx(i.x)&&Hx(i.y)&&Hx(i.z)?i.x>0&&i.z>0||e.push("base 의 x·z 는 0 보다 커야 한다 — 평면 배치 비율의 분모다"):e.push("base 의 x·y·z 가 온전하지 않다"),Array.isArray(n.groups)?(0===n.groups.length&&e.push("groups 가 비어 있다 — 그릴 것이 없는 청사진은 등록하지 않는다"),n.groups.forEach((t,n)=>{t&&Array.isArray(t.members)?(0===t.members.length&&e.push(`groups[${n}] 에 부품이 없다`),t.members.forEach((t,i)=>{const s=`groups[${n}].members[${i}]`;"string"==typeof t?.name&&0!==t.name.length||e.push(`${s}.name 이 없다 — 이름이 바인딩·이벤트·애니메이션이 붙는 자리다`);const r=t?.transform;r&&Bx(r.position)&&Bx(r.size)||e.push(`${s}.transform 의 값이 온전하지 않다`)})):e.push(`groups[${n}].members 가 배열이 아니다`)}),e):(e.push("groups 가 배열이 아니다"),e)}const Vx={"palette.primary":"#4a9eff","palette.accent":"#ff9800","palette.neutral":"#9e9e9e","palette.dark":"#37474f","palette.light":"#eceff1","palette.surface":"#607d8b"},Yx=new Map([["default",Vx]]);let Wx="default",Ux=0;function $x(){return Ux}function Xx(t,e){Yx.set(t,e),t===Wx&&Ux++}function qx(t){if(!Yx.has(t))throw new Error(`등록되지 않은 팔레트다: '${t}'. 등록된 것 — ${[...Yx.keys()].join(", ")}`);t!==Wx&&(Wx=t,Ux++)}function Kx(){return Wx}function Qx(){return Yx.get(Wx)}function Zx(t){const e=Qx()[t];if(void 0===e)throw new Error(`팔레트에 없는 토큰이다: '${t}' (팔레트 '${Wx}'). 쓸 수 있는 것 — ${Object.keys(Qx()).join(", ")}`);return e}const Jx=Vx["palette.neutral"];function tw(){Yx.clear(),Yx.set("default",Vx),Wx="default",Ux++}const ew=new Map;let nw=null;function iw(t){nw=t}function sw(t){const e=t.material?.token;return void 0===e?Jx:Zx(e)}function rw(t){const e=new Map;for(const n of t.points??[])e.set(n.name,n);const n=[],i=[];for(const s of t.groups){const t=sw(s);let r;for(const n of s.members){const o=e.get(n.name);o&&!r&&(r=o),i.push({member:n,group:s,color:t,point:o})}n.push({group:s,color:t,point:r})}return i.sort((t,e)=>t.member.transform.position.y-e.member.transform.position.y),{blueprint:t,paintOrder:i,groups:n,paletteVersion:$x()}}function ow(t){const e=Gx(t);if(e.length>0){throw new Error(`Figure '${t?.type??"(이름 없음)"}' 를 등록할 수 없다:\n - ${e.join("\n - ")}`)}const n=rw(t);return ew.set(t.type,n),nw&&nw.registerType?.(t.type),n}function aw(t){const e=ew.get(t);if(!e)return null;if(e.paletteVersion!==$x()){const n=rw(e.blueprint);return ew.set(t,n),n}return e}function cw(){return[...ew.keys()]}function lw(t){return ew.has(t)}function hw(t){return ew.delete(t)}function dw(){ew.clear()}function uw(t){return"scale"!==t.sizing}function pw(t){const{size:e,rotation:n}=t.transform;if(!n)return{...e};const i=Math.PI/180,s=Math.cos((n.x??0)*i),r=Math.sin((n.x??0)*i),o=Math.cos((n.y??0)*i),a=Math.sin((n.y??0)*i),c=Math.cos((n.z??0)*i),l=Math.sin((n.z??0)*i),h=[[o*c,-o*l,a],[r*a*c+s*l,-r*a*l+s*c,-r*o],[-s*a*c+r*l,s*a*l+r*c,s*o]],d=t=>Math.abs(t[0])*e.x+Math.abs(t[1])*e.y+Math.abs(t[2])*e.z;return{x:d(h[0]),y:d(h[1]),z:d(h[2])}}function fw(t){const{x:e,y:n,z:i}=pw(t);return e>=i&&e>=n?"x":i>=n?"z":"y"}function mw(t,e){if("scale"===t.sizing)return{x:1,y:1,z:1};const n={x:gw(e.x),y:gw(e.y),z:gw(e.z)};return"stretch"===t.sizing&&(n[fw(t)]=1),n}function gw(t){return Number.isFinite(t)&&t>0?1/t:1}function yw(t,e,n){if("repeat"!==t.sizing||!t.repeat)return null;const i=t.repeat.axis,s=t.repeat.pitch;if(!(Number.isFinite(s)&&s>0))return null;const r=Number.isFinite(e[i])&&e[i]>0?e[i]:1,o=(Number.isFinite(n[i])&&n[i]>0?n[i]:s)*r;return{axis:i,count:Math.max(1,Math.min(bw,Math.floor(o/s))),pitch:s}}const bw=100;function _w(t,e,n){return(t-(e-1)/2)*n}function vw(t){const n=ww(t);if(!n)return null;const{position:i,rotation:s}=t.transform;return s&&(n.rotateZ(e.MathUtils.degToRad(s.z??0)),n.rotateY(e.MathUtils.degToRad(s.y??0)),n.rotateX(e.MathUtils.degToRad(s.x??0))),n.translate(i.x,i.y,i.z),n}function xw(t){const n=ww(t);if(!n)return null;const{rotation:i}=t.transform;return i&&(n.rotateZ(e.MathUtils.degToRad(i.z??0)),n.rotateY(e.MathUtils.degToRad(i.y??0)),n.rotateX(e.MathUtils.degToRad(i.x??0))),n}function ww(t){const{size:n}=t.transform;if(!(n.x>0&&n.y>0&&n.z>0))return null;switch(t.primitive){case"cube":case"wall":return new e.BoxGeometry(n.x,n.y,n.z);case"cylinder":case"sphere":{const e=function(t){const e=t.segments;return Cv(e,Sv[0])}(t),i=Mv.primitive({kind:t.primitive,segments:e}).clone();return i.scale(n.x,n.y,n.z),i}case"rect":case"polygon":{const i=function(t){const{size:n}=t.transform,i=n.x,s=n.z,r=-i/2,o=-s/2;if("polygon"===t.primitive){const n=t.shape?.path;if(!n||n.length<3)return null;const i=new e.Shape;i.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++)i.lineTo(n[t].x,n[t].y);return i.closePath(),i}const a=t.shape?.round??0;if(a<=0){const t=new e.Shape;return t.moveTo(r,o),t.lineTo(r+i,o),t.lineTo(r+i,o+s),t.lineTo(r,o+s),t.closePath(),t}const c=Math.min(a,i/2,s/2),l=new e.Path;return l.moveTo(r+c,o),l.lineTo(r+i-c,o),l.quadraticCurveTo(r+i,o,r+i,o+c),l.lineTo(r+i,o+s-c),l.quadraticCurveTo(r+i,o+s,r+i-c,o+s),l.lineTo(r+c,o+s),l.quadraticCurveTo(r,o+s,r,o+s-c),l.lineTo(r,o+c),l.quadraticCurveTo(r,o,r+c,o),new e.Shape(l.getPoints(Sv[0]))}(t);if(!i)return null;const s=new e.ExtrudeGeometry(i,{steps:1,depth:n.y,bevelEnabled:!1});return s.rotateX(Math.PI/2),s.translate(0,n.y/2,0),s}}}function Mw(t,n){const{blueprint:i}=t,s=t.groups[n];if(!s)return null;const r=`figure|${i.type}|${n}|${s.group.materialKey}|${function(t){let e=2166136261;const n=t=>{for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619)};for(const e of t.group.members){const{position:t,size:i,rotation:s}=e.transform;n(`${e.geometryKey}@${t.x},${t.y},${t.z}:${i.x},${i.y},${i.z}`),n(s?`%${s.x??0},${s.y??0},${s.z??0};`:";")}return(e>>>0).toString(36)}(s)}`,o=Mv.shaped(r,()=>{const t=[];for(const e of s.group.members){const n=vw(e);n&&t.push(n)}if(0===t.length)return new e.BufferGeometry;let r;if(1===t.length)r=t[0];else{const e=t.map(t=>t.index?t.toNonIndexed():t),o=j(e,!1);if(!o)throw new Error(`Figure '${i.type}' 의 묶음 ${n}(${s.group.materialKey})를 합치지 못했다 — 부품 ${s.group.members.map(t=>t.name).join(", ")}`);r=o;for(const t of e)t.dispose();for(const e of t)e.dispose()}return r});return o.getAttribute("position")?o:null}function Sw(t,e){const{material:n}=e.group,i=wd[n.preset??"default"]??wd.default;return Z_.material(`figure|${t.blueprint.type}|${e.group.materialKey}`,{color:e.color,metalness:i.metalness,roughness:i.roughness,envMapIntensity:i.envMapIntensity,flatShading:n.flatShading??!0,transparent:n.transparent??!1,opacity:n.transparent?i.opacity??.3:1})}class kw extends pu{constructor(){super(...arguments),this._meshByName=new Map,this._sized=[]}get figure(){return aw(this.component.state.type)}build(){super.build();const t=this.figure;t&&(t.groups.forEach((n,i)=>{const s=function(t){const{members:e}=t.group;if(1!==e.length)return null;const n=e[0];return uw(n)?n:null}(n);if(s)return void this.buildSized(t,n,s);const r=Mw(t,i);if(!r)return;const o=new e.Mesh(r,Sw(t,n));o.castShadow=!0,o.name=n.group.animated?n.group.members[0]?.name??"":"",this.object3d.add(o);for(const t of n.group.members)this._meshByName.has(t.name)||this._meshByName.set(t.name,o)}),this.updateDimension())}buildSized(t,n,i){const s=function(t,n){const{size:i,rotation:s}=n.transform,r=`figure-part|${t.blueprint.type}|${n.geometryKey}|${i.x},${i.y},${i.z}|${s?`${s.x??0},${s.y??0},${s.z??0}`:"-"}`,o=Mv.shaped(r,()=>xw(n)??new e.BufferGeometry);return o.getAttribute("position")?o:null}(t,i);if(!s)return;const r=new e.Object3D,{position:o}=i.transform;r.position.set(o.x,o.y,o.z),r.name=i.name,this.object3d.add(r);const a=new e.Mesh(s,Sw(t,n));a.castShadow=!0,r.add(a),this._sized.push({member:i,holder:r,copies:[a]}),this._meshByName.has(i.name)||this._meshByName.set(i.name,a)}applySizing(t){const n=this.figure?.blueprint.base;if(n)for(const i of this._sized){const{member:s,holder:r,copies:o}=i,a=mw(s,t);r.scale.set(a.x,a.y,a.z);const c=yw(s,t,n);if(!c){o.forEach((t,e)=>{t.visible=0===e,t.position.set(0,0,0)});continue}const l=o[0];for(;o.length<c.count;){const t=new e.Mesh(l.geometry,l.material);t.castShadow=!0,r.add(t),o.push(t)}o.forEach((t,e)=>{t.visible=e<c.count,t.visible&&(t.position.set(0,0,0),t.position[c.axis]=_w(e,c.count,c.pitch))})}}get effectiveDepth(){const t=this.component.state.depth;if("number"==typeof t&&Number.isFinite(t)&&t>0)return t;const e=this.figure;if(!e)return super.effectiveDepth;const{base:n}=e.blueprint,{width:i,height:s}=this.component.bounds,r=n.x>0?i/n.x:1,o=n.z>0?s/n.z:1;return n.y*Math.sqrt(Math.max(r,0)*Math.max(o,0))}updateDimension(){const t=this.figure;if(!t)return;const{base:e}=t.blueprint,{width:n,height:i}=this.component.bounds,s=this.effectiveDepth,r={x:e.x>0?n/e.x:1,y:e.y>0?s/e.y:1,z:e.z>0?i/e.z:1};this.setDimensionScale(r.x,r.y,r.z),this._sized.length>0&&this.applySizing(r)}topOutline(){return null}clear(){return this._meshByName.clear(),this._sized=[],super.clear()}}const Aw={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure"};class Ew extends(Dc(Pc)){static registerType(t){Tc.register(t,Ew)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Aw}buildRealObject(){return new kw(this)}get figure(){return aw(this.state.type)}render(t){const e=this.figure,{left:n=0,top:i=0,width:s=0,height:r=0}=this.state;if(!e)return void this.renderMissing(t,n,i,s,r);const{base:o}=e.blueprint,a=o.x>0?s/o.x:1,c=o.z>0?r/o.z:1,l=n+s/2,h=i+r/2,d={x:a,y:this.depthScale(o,a,c),z:c};for(const n of e.paintOrder)t.fillStyle=n.color,t.beginPath(),this.tracePart(t,n,l,h,a,c,d,o),t.fill()}depthScale(t,e,n){const i=this.state.depth;return"number"==typeof i&&Number.isFinite(i)&&i>0?t.y>0?i/t.y:1:Math.sqrt(Math.max(e,0)*Math.max(n,0))}tracePart(t,e,n,i,s,r,o,a){const{member:c}=e,{position:l}=c.transform,h=n+l.x*s,d=i+l.z*r,u=mw(c,o),p=s*u.x,f=r*u.z,m=yw(c,o,a);if(m&&"y"!==m.axis&&m.count>1)for(let n=0;n<m.count;n++){const i=_w(n,m.count,m.pitch);this.traceOne(t,e,"x"===m.axis?h+i*s:h,"z"===m.axis?d+i*r:d,p,f)}else this.traceOne(t,e,h,d,p,f)}traceOne(t,e,n,i,s,r){const{member:o}=e,{size:a,rotation:c}=o.transform,l=c?.x??0,h=c?.y??0,d=c?.z??0;if(0!==l||0!==d){const e=function(t,e,n,i){const s=Math.PI/180,r=Math.cos(e*s),o=Math.sin(e*s),a=Math.cos(n*s),c=Math.sin(n*s),l=Math.cos(i*s),h=Math.sin(i*s),d=a*l,u=-a*h,p=c,f=o*h-r*c*l,m=o*l+r*c*h,g=r*a,y=t.x/2,b=t.y/2,_=t.z/2;return{u:Math.abs(d)*y+Math.abs(u)*b+Math.abs(p)*_,v:Math.abs(f)*y+Math.abs(m)*b+Math.abs(g)*_}}(a,l,h,d);return void t.rect(n-e.u*s,i-e.v*r,2*e.u*s,2*e.v*r)}if(0!==h)return t.save(),t.translate(n,i),t.rotate(-h*Math.PI/180),this.traceShape(t,e,0,0,s,r),void t.restore();this.traceShape(t,e,n,i,s,r)}traceShape(t,e,n,i,s,r){const{member:o}=e,{size:a}=o.transform,c=a.x*s,l=a.z*r,h=n-c/2,d=i-l/2;switch(o.primitive){case"cylinder":case"sphere":{const e=dv(c/2,l/2,Cv(o.segments,Sv[0])).points;t.moveTo(n+e[0].x,i+e[0].y);for(let s=1;s<e.length;s++)t.lineTo(n+e[s].x,i+e[s].y);return void t.closePath()}case"polygon":{const e=o.shape?.path;if(!e||e.length<3)return;t.moveTo(n+e[0].x*s,i+e[0].y*r);for(let o=1;o<e.length;o++)t.lineTo(n+e[o].x*s,i+e[o].y*r);return void t.closePath()}default:{const e=o.shape?.round??0;if(e>0&&"function"==typeof t.roundRect)return void t.roundRect(h,d,c,l,Math.min(e*s,c/2,l/2));t.rect(h,d,c,l)}}}renderMissing(t,e,n,i,s){t.save(),t.strokeStyle="#e53935",t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.rect(e,n,i,s),t.stroke(),t.restore()}postrender(t){Tc.prototype.postrender.call(this,t)}}iw(Ew);const Cw={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure-part"},Tw=new e.Vector3,Pw=["cylinder","sphere"],Ow=["rect","polygon"],Dw=["primitive","round","path"],zw=["width","height"],Iw=["token","preset","flatShading","transparent"];function Rw(t){return t.state}class jw extends pu{constructor(){super(...arguments),this._copies=[]}build(){super.build();const t=Rw(this.component).primitive??"cube",n=Ow.includes(t)?this.extrudedGeometry(t):this.unitGeometry(t);if(!n)return;const i=new e.Mesh(n,this.material());i.castShadow=!0,this.object3d.add(i),this._copies=[i],this.updateDimension()}clear(){return this._copies=[],super.clear()}applyRepeat(){const t=this._copies[0];if(!t)return;const n=this.repeatPlanNow();if(!n)return void this._copies.forEach((t,e)=>{t.visible=0===e,t.position.set(0,0,0)});for(;this._copies.length<n.count;){const n=new e.Mesh(t.geometry,t.material);n.castShadow=!0,this.object3d.add(n),this._copies.push(n)}const i=this.repeatUndo();this._copies.forEach((t,e)=>{t.visible=e<n.count,t.visible&&(Tw.set(0,0,0),Tw[n.axis]=_w(e,n.count,n.pitch),Tw.applyQuaternion(i.turn),t.position.set(Tw.x*i.scale.x,Tw.y*i.scale.y,Tw.z*i.scale.z))})}updateRotate(){super.updateRotate(),this.applyRepeat()}onchange(t,e){const n=e=>e.some(e=>e in t);n(Dw)||this.isExtruded&&n(zw)?this.update():(super.onchange(t,e),n(Iw)&&this.applyMaterial(),n(["sizing","repeat"])&&this.applyRepeat())}get isExtruded(){return Ow.includes(Rw(this.component).primitive??"cube")}applyMaterial(){const t=this.material();for(const e of this._copies)e.material=t}repeatPlanNow(){const t=Rw(this.component);if("repeat"!==t.sizing||!t.repeat)return null;const e=this.component.parent;if(!e)return null;const n={x:Number(e.get("width"))||0,y:Number(e.get("depth"))||0,z:Number(e.get("height"))||0};return yw(this.asMember(t),{x:1,y:1,z:1},n)}asMember(t){const e=this.component.state,n=t=>180*(t??0)/Math.PI;return{name:"",primitive:t.primitive??"cube",geometryKey:"",triangles:0,sizing:"repeat",repeat:t.repeat,transform:{position:{x:0,y:0,z:0},size:{x:Number(e.width)||0,y:this.effectiveDepth,z:Number(e.height)||0},rotation:{x:n(e.rotationX),y:-n(e.rotation),z:n(e.rotationY)}}}}repeatUndo(){const t=this.object3d,n=t=>Number.isFinite(t)&&0!==t?1/t:1;return{turn:t.quaternion.clone().invert(),scale:new e.Vector3(n(t.scale.x),n(t.scale.y),n(t.scale.z))}}updateScale(){super.updateScale(),this.applyRepeat()}syncFromObject3D(){super.syncFromObject3D(),this.applyRepeat()}applyDimensionFromGizmo(t){super.applyDimensionFromGizmo(t),this.applyRepeat()}unitGeometry(t){const e=Rw(this.component);return"cylinder"===t||"sphere"===t?Mv.primitive({kind:t,segments:Cv(e.segments,Sv[0])}):Mv.primitive({kind:"box"})}extrudedGeometry(t){const n=Rw(this.component),{width:i=1,height:s=1}=this.component.state,r=n.round??0,o=n.path,a="polygon"===t?`figure-part|polygon|${JSON.stringify(o??[])}`:`figure-part|rect|${i}x${s}|r${r}`,c=Mv.shaped(a,()=>{const n=this.crossSection(t,i,s,r,o);if(!n)return new e.BufferGeometry;const a=new e.ExtrudeGeometry(n,{steps:1,depth:1,bevelEnabled:!1});return a.rotateX(Math.PI/2),a.translate(0,.5,0),a});return c.getAttribute("position")?c:null}crossSection(t,n,i,s,r){if("polygon"===t){if(!r||r.length<3)return null;const t=new e.Shape;t.moveTo(r[0].x,r[0].y);for(let e=1;e<r.length;e++)t.lineTo(r[e].x,r[e].y);return t.closePath(),t}const o=-n/2,a=-i/2;if(s<=0){const t=new e.Shape;return t.moveTo(o,a),t.lineTo(o+n,a),t.lineTo(o+n,a+i),t.lineTo(o,a+i),t.closePath(),t}const c=Math.min(s,n/2,i/2),l=new e.Path;return l.moveTo(o+c,a),l.lineTo(o+n-c,a),l.quadraticCurveTo(o+n,a,o+n,a+c),l.lineTo(o+n,a+i-c),l.quadraticCurveTo(o+n,a+i,o+n-c,a+i),l.lineTo(o+c,a+i),l.quadraticCurveTo(o,a+i,o,a+i-c),l.lineTo(o,a+c),l.quadraticCurveTo(o,a,o+c,a),new e.Shape(l.getPoints(Sv[0]))}material(){const t=Rw(this.component),e=wd[t.preset??"default"]??wd.default,n=t.token?Zx(t.token):Jx,i=t.flatShading??!0,s=t.transparent??!1;return Z_.material(`figure-part|${t.token??"-"}|${t.preset??"default"}|${i}|${s}`,{color:n,metalness:e.metalness,roughness:e.roughness,envMapIntensity:e.envMapIntensity,flatShading:i,transparent:s,opacity:s?e.opacity??.3:1})}updateDimension(){const{width:t=1,height:e=1}=this.component.bounds,n=this.effectiveDepth,i=Rw(this.component).primitive??"cube";Ow.includes(i)?this.setDimensionScale(1,n,1):this.setDimensionScale(t,n,e),this.applyRepeat()}}class Lw extends(Dc(Pc)){static registerType(){Tc.register("figure-part",Lw)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Cw}buildRealObject(){return new jw(this)}render(t){const{left:e=0,top:n=0,width:i=0,height:s=0}=this.state,r=Rw(this);t.beginPath(),this.traceFootprint(t,r,e,n,i,s),t.fillStyle=r.token?Zx(r.token):Jx,t.fill()}traceFootprint(t,e,n,i,s,r){const o=e.primitive??"cube",a=n+s/2,c=i+r/2;if(Pw.includes(o)){const n=dv(s/2,r/2,Cv(e.segments,Sv[0])).points;t.moveTo(a+n[0].x,c+n[0].y);for(let e=1;e<n.length;e++)t.lineTo(a+n[e].x,c+n[e].y);return void t.closePath()}if("polygon"===o){const n=e.path;if(!n||n.length<3)return;t.moveTo(a+n[0].x,c+n[0].y);for(let e=1;e<n.length;e++)t.lineTo(a+n[e].x,c+n[e].y);return void t.closePath()}const l=e.round??0;l>0&&"function"==typeof t.roundRect?t.roundRect(n,i,s,r,Math.min(l,s/2,r/2)):t.rect(n,i,s,r)}}var Fw;Lw.registerType(),function(t){t.compile=zl,t.duplicate=Il,t.select=nc,t.match=Ja}(Fw||(Fw={})),Li.registerResidents(()=>({componentResidentsCount:Tc.residentsCount,sceneResidentsCount:Gu.residentsCount,referenceMapResidentsCount:I_.residentsCount,sceneResidents:Tc.residents}));var Nw=Object.freeze({__proto__:null,AbsoluteLayout:Hc,Animation:Aa,AudioPlayer:Yg,BULGE_EPSILON:qr,get Banner(){return Uv},Banner3D:Wv,BoxSelectionManager:Ef,COMMON_PLACEHOLDER_PROPERTIES:ug,CORE_PLACEHOLDER_TYPES:gg,get Camera(){return Qv},Camera3D:Kv,CameraBookmarkManager:Af,CameraManager:df,Capacity:Wy,CapacityEventTracker:Ey,CardLayout:Gc,CenteringQueueStrategy:Ty,CenteringSlotStrategy:d_,Component:Tc,Connectable:Xf,Container:Xm,ContainerAbstract:Kl,ControlsManager:mf,get Cube(){return Hv},Cube3D:Nv,get Cylinder(){return Vv},Cylinder3D:Gv,DEFAULT:Qs,DEFAULT_PALETTE:Vx,DEFAULT_PLACEMENT:ru,DPPX:Xs,DataLagTracker:eh,DataSource:_y,DefaultLoadingOverlayRenderer:jd,Donut:ly,DonutExtrude:bv,Ellipse:hg,EllipseExtrude:fv,EventManager3D:gf,EventMap:ml,FPS:Pp,FigureInstance:Ew,FigurePart:Lw,FigurePartRealObject:jw,FigureRealObject:kw,FixedSlotStrategy:Gy,get FloorPlate(){return cx},FlowEngine:Jb,FlowNode:e_,GESTURES:qs,get GLTFObject(){return Jv},GLTF_BASE_URL_ALIAS:xy,GenericObject:mg,GeometryBank:Mv,GifView:Gg,GizmoManager:bf,GizmoOperationManager:xf,GlobalRef:Zg,GltfComponent:My,GridStacking:Dy,Group:$g,HTMLAbsoluteLayout:Nc,HTMLOverlayContainer:Kg,HTMLOverlayElement:Pg,Holdable:t_,ImageView:Tg,InfoWindow:jc,InstancedSet:Cx,InteractionManager:wf,ItemsDataBinding:By,KEYEVENTS:Ks,Layer:cp,Layout:Fc,LightManager:pf,LightObject:ex,Line:cg,Line3D:kx,LinearHorizontalLayout:Yc,LinearVerticalLayout:Uc,LoadTracker:sh,LoadingOverlay:Cd,LocalRef:qg,MATERIAL_PRESETS:wd,MAX_SEGMENTS:Ev,MAX_UNDO_SIZE:30,MIN_SEGMENTS:3,MODE_ADD:3,MODE_EDIT:1,MODE_PASTE_DATABIND:5,MODE_PASTE_STYLE:4,MODE_SHIFT:2,MODE_VIEW:0,MaterialBank:Z_,get Model(){return Fw},MoveHandle:Xl,NOTHING:Ns,NavGraph:y_,Node:fy,OrthoLine:Eg,OrthoLine3D:Ex,PIXEL_RATIO:Op,PLACEHOLDER_THEMES:dg,Path:sy,PatternStacking:Oy,PlacementManager:Mf,get PointLight(){return nx},Polygon:vg,PolygonContainer:wg,PolygonExtrude:yv,PolygonPathPolyline:S_,Polyline:kg,Polyline3D:Ax,Popup:ey,PopupContainer:iy,Pose6DOF:xl,REPEAT_LIMIT:bw,RealObject:pu,RealObjectCamera:Dx,RealObjectDomElement:Np,RealObjectDomTexture:X_,RealObjectDummy:Px,RealObjectExternalModel:gu,RealObjectExtrude:pv,RealObjectGLTF:vu,RealObjectGroup:px,RealObjectLine:Sx,RealObjectMesh:J_,RealObjectPlane:zx,RealObjectPlane2D:jx,RealObjectScene:Ix,RealObjectService:my,RealObjectSprite:Iv,RealObjectSprite2D:Rv,RealObjectText:ov,Rect:Qf,RectExtrude:mv,RectPath:Dc,ReferenceMap:I_,RendererManager:uf,ReservationTable:m_,RootContainer:th,Ruler:Jf,SCALE_MIN:Wd,SCENE_MODE:Us,SEGMENT_DEFAULTS:kv,SEGMENT_PRESETS:Sv,SHORTCUT_SECTIONS:Hf,SUPPORTED_BLUEPRINT_VERSION:1,Scene:Gu,SceneManager:hf,ScenePopup:ap,SceneSearchEngine:ku,ScriptLoader:B_,SearchOverlay:Eu,ServiceComponent:yy,Shape:Pc,get Sphere(){return zv},Sphere3D:Dv,get Sprite(){return Lv},Star:uy,StarExtrude:vv,TRANSFER_SLOT_KEY:Ny,TableLayout:$c,Text:Wg,ThreeCapability:zf,get ThreeContainer(){return Fx},ThreeDOnly:vy,Tracker:Tu,Transfer:Fu,TransitionEffect:$l,Triangle:oy,TriangleExtrude:_v,UNIT_DIMENSION:qd,UNIT_ROTATE:Zd,UNIT_SCALE:Kd,UNIT_TRANSLATE:Qd,UNTOKENED_COLOR:Jx,ValueHolder:by,VertexGizmoManager:Df,VolumeStacking:zy,get Wall(){return rx},Wall3D:sx,Z_PRIORITY:au,activePalette:Qx,activePaletteName:Kx,allDestinations:Hb,anchorsConnect:Qy,animate:ka,applyAlpha:$d,applyMaterial3dProps:Ad,applyPolicy:Vb,applySeatingRotation:Fy,applyStackLayout:Iy,applyZPriorityToMaterials:lu,arcSegmentTopology:qy,autoWireBackPressure:Cy,blueprintProblems:Gx,buildArrow3D:Lp,buildContractInspector:P_,buildCoordinateGround:qp,buildFlowGraph:nb,buildNavGraph:v_,buildShapeFromPolygonPath:gv,buildTether:Zu,bulgeFromDrag:Jr,bulgeHandlePosition:Zr,canReach:ab,capability:zm,centerOnBBox:uv,chooseNearestPickupFrame:h_,clearTether:tp,collectAdjacentSegments:ub,compile:Ca,componentForNode:Nb,computeArcParams:Qr,computeFlowMap:Eb,computeStackPositions:Py,cornerHandlePosition:eo,cornerRadiusFromDrag:no,create:Yu,createCanvas:Dp,createCanvasTexture:Y_,createFloor:af,createRealObjectFor:Yp,createSelectionHandle3D:lx,dataLagTracker:nh,debug:ts,deliversInto:tb,delta:Ma,disposeCoordinateGround:Jp,disposeObject3D:eu,disposeTether:ep,downstream:Ub,drawTextTexture:nv,effectiveCornerRadius:to,ellipseOutline:dv,enumerateDataScenarios:gb,error:Zi,figureTypes:cw,fillStyleOpacity:Ud,filterByToolType:l_,filterShortcuts:Bf,findNearestWithCapability:Pb,flattenPolygonPath:k_,flowGraphFor:Lb,flowGraphIssues:jb,flowReverseFor:Cb,fontStyle:tv,footprint2D:Ry,frameClock:jr,ftId:Mb,ftrace:wb,getAllCapabilityMeta:Lm,getCapabilityMeta:jm,getFigure:aw,getPose:Al,getWorldPose:El,globalSimClock:Ir,gltfNatureProperties:wy,graphFor:Kb,gridPlacements:Tx,hasArc:Kr,hasCapability:Dm,hasCapacity:ky,hasFigure:lw,inferCapacity:Ay,inferDownstreamId:pb,inferFlowDirections:xb,initFontFamilyWatcher:Js,inspector:Ed,installContractInspector:O_,isFlowNode:n_,isGenericPlaceholder:yg,isGeometricHost:Tb,isParted:fu,isRoutingTarget:Ob,isSegmentPreset:Pv,isStateDriven:ou,isThreedEnabled:wu,matchOutbounds:eb,memberGeometry:vw,memberGeometryAtOrigin:ww,memberGeometryTurned:xw,mergedGeometryOf:Mw,metrics:Li,needsOwnMesh:uw,next:Wb,nextHop:ob,nextHops:rb,nextHopsToAny:lb,nextHopsToAnyDetailed:hb,niceGridStep:$p,nodeIdOf:Bb,opaqueColor:Xd,paletteVersion:$x,partAtByIndex:mu,pickWeightedDestination:Zb,planPathAStar:x_,planToReservations:w_,pointInRotatedRect:Zy,polygonOffsetForPriority:cu,polygonPathLength:A_,projectToScreen:Xu,quatFromYaw:s_,rayAbsDistanceToRect:Jy,reachableByOutbound:ib,reachableDestinations:$b,reachableDestinationsFrom:Xb,reachableDestinationsWeightedFrom:qb,reachableSinks:cb,receiptToJSON:ju,recommendsLogarithmicDepthForSky:lf,rectFaceAnchors:Uy,rectOutline:hv,rectangularFootprintFrames:a_,registerCapabilityMeta:Rm,registerDefaultRealObjectFactory:Vp,registerFigure:ow,registerPalette:Xx,registerRealObjectFactory:Gp,renderCanvasTexture:W_,renderPlaceholder:pg,repeatOffset:_w,repeatPlan:yw,reservationTable:g_,resetFigures:dw,resetPalettes:tw,resolveAnchorWorldPosition:Qu,resolveHeightSegments:Tv,resolveMaterial3d:Md,resolveNextHop:Yb,resolveSegments:Cv,resolveToken:Zx,resolveVariant:Gd,rotatedExtent:pw,sceneComponent:Sy,setActivePalette:qx,setPose:Cl,setThreedEnabled:Mu,setWorldPose:Tl,sinksForDestination:Fb,sizingScale:mw,standardYieldPolicy:f_,stopFPSMeasure:Tp,straightSegmentEndpoints:Xy,straightSegmentMultiInbound:Ky,straightSegmentTopology:$y,stretchAxis:fw,textBounds:rv,textTexture:iv,toThreeSide:kd,topApproachFrame:c_,transferLog:Nu,transferTracer:Iu,uniformZ:io,unregisterFigure:hw,updateDefaultFontFamily:Zs,updateTether:Ju,useFigureComponent:iw,validate:Qb,validateFlowGraph:db,version:G_,warn:Ji});const Hw=globalThis;"undefined"==typeof globalThis||Hw.scene||(Hw.scene=Nw);export{Hc as AbsoluteLayout,Aa as Animation,Yg as AudioPlayer,qr as BULGE_EPSILON,Uv as Banner,Wv as Banner3D,Ef as BoxSelectionManager,ug as COMMON_PLACEHOLDER_PROPERTIES,gg as CORE_PLACEHOLDER_TYPES,Qv as Camera,Kv as Camera3D,Af as CameraBookmarkManager,df as CameraManager,Wy as Capacity,Ey as CapacityEventTracker,Gc as CardLayout,Ty as CenteringQueueStrategy,d_ as CenteringSlotStrategy,Tc as Component,Xf as Connectable,Xm as Container,Kl as ContainerAbstract,mf as ControlsManager,Hv as Cube,Nv as Cube3D,Vv as Cylinder,Gv as Cylinder3D,Qs as DEFAULT,Vx as DEFAULT_PALETTE,ru as DEFAULT_PLACEMENT,Xs as DPPX,eh as DataLagTracker,_y as DataSource,jd as DefaultLoadingOverlayRenderer,ly as Donut,bv as DonutExtrude,hg as Ellipse,fv as EllipseExtrude,gf as EventManager3D,ml as EventMap,Pp as FPS,Ew as FigureInstance,Lw as FigurePart,jw as FigurePartRealObject,kw as FigureRealObject,Gy as FixedSlotStrategy,cx as FloorPlate,Jb as FlowEngine,e_ as FlowNode,qs as GESTURES,Jv as GLTFObject,xy as GLTF_BASE_URL_ALIAS,mg as GenericObject,Mv as GeometryBank,Gg as GifView,bf as GizmoManager,xf as GizmoOperationManager,Zg as GlobalRef,My as GltfComponent,Dy as GridStacking,$g as Group,Nc as HTMLAbsoluteLayout,Kg as HTMLOverlayContainer,Pg as HTMLOverlayElement,t_ as Holdable,Tg as ImageView,jc as InfoWindow,Cx as InstancedSet,wf as InteractionManager,By as ItemsDataBinding,Ks as KEYEVENTS,cp as Layer,Fc as Layout,pf as LightManager,ex as LightObject,cg as Line,kx as Line3D,Yc as LinearHorizontalLayout,Uc as LinearVerticalLayout,sh as LoadTracker,Cd as LoadingOverlay,qg as LocalRef,wd as MATERIAL_PRESETS,Ev as MAX_SEGMENTS,$s as MAX_UNDO_SIZE,Av as MIN_SEGMENTS,Vs as MODE_ADD,Bs as MODE_EDIT,Ws as MODE_PASTE_DATABIND,Ys as MODE_PASTE_STYLE,Gs as MODE_SHIFT,Hs as MODE_VIEW,Z_ as MaterialBank,Fw as Model,Xl as MoveHandle,Ns as NOTHING,y_ as NavGraph,fy as Node,Eg as OrthoLine,Ex as OrthoLine3D,Op as PIXEL_RATIO,dg as PLACEHOLDER_THEMES,sy as Path,Oy as PatternStacking,Mf as PlacementManager,nx as PointLight,vg as Polygon,wg as PolygonContainer,yv as PolygonExtrude,S_ as PolygonPathPolyline,kg as Polyline,Ax as Polyline3D,ey as Popup,iy as PopupContainer,xl as Pose6DOF,bw as REPEAT_LIMIT,pu as RealObject,Dx as RealObjectCamera,Np as RealObjectDomElement,X_ as RealObjectDomTexture,Px as RealObjectDummy,gu as RealObjectExternalModel,pv as RealObjectExtrude,vu as RealObjectGLTF,px as RealObjectGroup,Sx as RealObjectLine,J_ as RealObjectMesh,zx as RealObjectPlane,jx as RealObjectPlane2D,Ix as RealObjectScene,my as RealObjectService,Iv as RealObjectSprite,Rv as RealObjectSprite2D,ov as RealObjectText,Qf as Rect,mv as RectExtrude,Dc as RectPath,I_ as ReferenceMap,uf as RendererManager,m_ as ReservationTable,th as RootContainer,Jf as Ruler,Wd as SCALE_MIN,Us as SCENE_MODE,kv as SEGMENT_DEFAULTS,Sv as SEGMENT_PRESETS,Hf as SHORTCUT_SECTIONS,Nx as SUPPORTED_BLUEPRINT_VERSION,Gu as Scene,hf as SceneManager,ap as ScenePopup,ku as SceneSearchEngine,B_ as ScriptLoader,Eu as SearchOverlay,yy as ServiceComponent,Pc as Shape,zv as Sphere,Dv as Sphere3D,Lv as Sprite,uy as Star,vv as StarExtrude,Ny as TRANSFER_SLOT_KEY,$c as TableLayout,Wg as Text,zf as ThreeCapability,Fx as ThreeContainer,vy as ThreeDOnly,Tu as Tracker,Fu as Transfer,$l as TransitionEffect,oy as Triangle,_v as TriangleExtrude,qd as UNIT_DIMENSION,Zd as UNIT_ROTATE,Kd as UNIT_SCALE,Qd as UNIT_TRANSLATE,Jx as UNTOKENED_COLOR,by as ValueHolder,Df as VertexGizmoManager,zy as VolumeStacking,rx as Wall,sx as Wall3D,au as Z_PRIORITY,Qx as activePalette,Kx as activePaletteName,Hb as allDestinations,Qy as anchorsConnect,ka as animate,$d as applyAlpha,Ad as applyMaterial3dProps,Vb as applyPolicy,Fy as applySeatingRotation,Iy as applyStackLayout,lu as applyZPriorityToMaterials,qy as arcSegmentTopology,Cy as autoWireBackPressure,Gx as blueprintProblems,Lp as buildArrow3D,P_ as buildContractInspector,qp as buildCoordinateGround,nb as buildFlowGraph,v_ as buildNavGraph,gv as buildShapeFromPolygonPath,Zu as buildTether,Jr as bulgeFromDrag,Zr as bulgeHandlePosition,ab as canReach,zm as capability,uv as centerOnBBox,h_ as chooseNearestPickupFrame,tp as clearTether,ub as collectAdjacentSegments,Ca as compile,Nb as componentForNode,Qr as computeArcParams,Eb as computeFlowMap,Py as computeStackPositions,eo as cornerHandlePosition,no as cornerRadiusFromDrag,Yu as create,Dp as createCanvas,Y_ as createCanvasTexture,af as createFloor,Yp as createRealObjectFor,lx as createSelectionHandle3D,nh as dataLagTracker,ts as debug,tb as deliversInto,Ma as delta,Jp as disposeCoordinateGround,eu as disposeObject3D,ep as disposeTether,Ub as downstream,nv as drawTextTexture,to as effectiveCornerRadius,dv as ellipseOutline,gb as enumerateDataScenarios,Zi as error,cw as figureTypes,Ud as fillStyleOpacity,l_ as filterByToolType,Bf as filterShortcuts,Pb as findNearestWithCapability,k_ as flattenPolygonPath,Lb as flowGraphFor,jb as flowGraphIssues,Cb as flowReverseFor,tv as fontStyle,Ry as footprint2D,jr as frameClock,Mb as ftId,wb as ftrace,Lm as getAllCapabilityMeta,jm as getCapabilityMeta,aw as getFigure,Al as getPose,El as getWorldPose,Ir as globalSimClock,wy as gltfNatureProperties,Kb as graphFor,Tx as gridPlacements,Kr as hasArc,Dm as hasCapability,ky as hasCapacity,lw as hasFigure,Ay as inferCapacity,pb as inferDownstreamId,xb as inferFlowDirections,Js as initFontFamilyWatcher,Ed as inspector,O_ as installContractInspector,n_ as isFlowNode,yg as isGenericPlaceholder,Tb as isGeometricHost,fu as isParted,Ob as isRoutingTarget,Pv as isSegmentPreset,ou as isStateDriven,wu as isThreedEnabled,eb as matchOutbounds,vw as memberGeometry,ww as memberGeometryAtOrigin,xw as memberGeometryTurned,Mw as mergedGeometryOf,Li as metrics,uw as needsOwnMesh,Wb as next,ob as nextHop,rb as nextHops,lb as nextHopsToAny,hb as nextHopsToAnyDetailed,$p as niceGridStep,Bb as nodeIdOf,Xd as opaqueColor,$x as paletteVersion,mu as partAtByIndex,Zb as pickWeightedDestination,x_ as planPathAStar,w_ as planToReservations,Zy as pointInRotatedRect,cu as polygonOffsetForPriority,A_ as polygonPathLength,Xu as projectToScreen,s_ as quatFromYaw,Jy as rayAbsDistanceToRect,ib as reachableByOutbound,$b as reachableDestinations,Xb as reachableDestinationsFrom,qb as reachableDestinationsWeightedFrom,cb as reachableSinks,ju as receiptToJSON,lf as recommendsLogarithmicDepthForSky,Uy as rectFaceAnchors,hv as rectOutline,a_ as rectangularFootprintFrames,Rm as registerCapabilityMeta,Vp as registerDefaultRealObjectFactory,ow as registerFigure,Xx as registerPalette,Gp as registerRealObjectFactory,W_ as renderCanvasTexture,pg as renderPlaceholder,_w as repeatOffset,yw as repeatPlan,g_ as reservationTable,dw as resetFigures,tw as resetPalettes,Qu as resolveAnchorWorldPosition,Tv as resolveHeightSegments,Md as resolveMaterial3d,Yb as resolveNextHop,Cv as resolveSegments,Zx as resolveToken,Gd as resolveVariant,pw as rotatedExtent,Sy as sceneComponent,qx as setActivePalette,Cl as setPose,Mu as setThreedEnabled,Tl as setWorldPose,Fb as sinksForDestination,mw as sizingScale,f_ as standardYieldPolicy,Tp as stopFPSMeasure,Xy as straightSegmentEndpoints,Ky as straightSegmentMultiInbound,$y as straightSegmentTopology,fw as stretchAxis,rv as textBounds,iv as textTexture,kd as toThreeSide,c_ as topApproachFrame,Nu as transferLog,Iu as transferTracer,io as uniformZ,hw as unregisterFigure,Zs as updateDefaultFontFamily,Ju as updateTether,iw as useFigureComponent,Qb as validate,db as validateFlowGraph,G_ as version,Ji as warn};
51
51
  //# sourceMappingURL=things-scene.mjs.map