laymur 0.14.2 → 0.15.1
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/README.md +98 -35
- package/dist/elements/UIAnchor/UIAnchor.d.ts +1 -2
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -9
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +10 -0
- package/dist/elements/UIElement/UIElement.d.ts +1 -0
- package/dist/elements/UIGraphics/UIGraphics.d.ts +1 -1
- package/dist/elements/UIInputDummy/UIInputDummy.Internal.d.ts +12 -0
- package/dist/elements/UIInputDummy/UIInputDummy.d.ts +19 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +150 -149
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +12 -0
- package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +11 -1
- package/dist/layers/UILayer/UILayer.Internal.d.ts +0 -9
- package/dist/layers/UILayer/UILayer.d.ts +11 -2
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +1 -1
- package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -5
- package/dist/miscellaneous/texture/UITextureView.d.ts +4 -2
- package/package.json +3 -3
- package/dist/miscellaneous/UIInputEvent.d.ts +0 -13
package/dist/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{MathUtils as t,Color as i,Vector4 as s,Texture as e,Vector2 as h,Vector3 as r,Matrix3 as n,Matrix4 as o,PlaneGeometry as a,InstancedBufferGeometry as c,ShaderMaterial as u,InstancedBufferAttribute as l,Mesh as f,Scene as d,OrthographicCamera as p,Quaternion as w,CanvasTexture as g,UVMapping as v,ClampToEdgeWrapping as y,LinearFilter as m,RGBAFormat as x,UnsignedByteType as b,SRGBColorSpace as _,NoColorSpace as I,WebGLRenderTarget as S,PerspectiveCamera as E,Ray as M}from"three";class C{constructor(t,i,s=0){this.t=new WeakMap,this.i=new Map,void 0!==t&&(void 0===i?this.i.set(t,s):this.t.set(i,new Map([[t,s]])))}insert(t,i,s=0){if(void 0===i){if(this.i.has(t))return;return void this.i.set(t,s)}const e=this.t.get(i);void 0===e?this.t.set(i,new Map([[t,s]])):e.has(t)||e.set(t,s)}remove(t,i){if(void 0===i)return void this.i.delete(t);const s=this.t.get(i);void 0!==s&&(s.delete(t),0===s.size&&this.t.delete(i))}has(t,i){if(void 0===i)return this.i.has(t);const s=this.t.get(i);return void 0!==s&&s.has(t)}getPriority(t,i){if(void 0===i)return this.i.get(t);const s=this.t.get(i);return void 0!==s?s.get(t):void 0}}class T{constructor(){this.o=new Map}on(t,i,s,e=0){return this.h(t,!1,e,i,s),this}once(t,i,s,e=0){return this.h(t,!0,e,i,s),this}off(t,i,s){const e=this.o.get(t);if(void 0===e)return this;e.u&&(e.u=!1,e.v=e.v.slice());const h=e.v;if(0===h.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;h.length>t;t++){const i=h[t];e.l.remove(i._,i.p)}return this}{const r=h.length;if(h[0]._===i&&h[0].p===s)return 1===r?this.o.delete(t):h.shift(),this;const n=r-1;if(h[n]._===i&&h[n].p===s)return h.pop(),this;if(10>r||h[0].M===h[n].M)for(let t=1;n>t;t++){const e=h[t];if(e._===i&&e.p===s)return h.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let r=0,n=h.length-1;for(;n>=r;){const i=r+n>>>1;t>h[i].M?r=i+1:n=i-1}const o=r;for(n=h.length-1;n>=r;){const i=r+n>>>1;h[i].M>t?n=i-1:r=i+1}const a=n;for(let t=o;a>=t;t++)if(h[t]._===i&&h[t].p===s)return h.splice(t,1),this}}return this}emit(t,...i){const s=this.o.get(t);if(void 0===s)return!1;if(0===s.v.length)return!1;s.u?s.v=s.v.slice():s.u=!0;const e=s.v;let h=!1;for(let t=0;e.length>t;t++){const s=e[t];s._.apply(s.p,i),s.k&&(h=!0,s.m=!0)}const r=this.o.get(t);if(void 0===r)return!0;r.v===e&&(r.u=!1);const n=r.v;if(h){let i=0;for(let t=0;n.length>t;t++){const s=n[t];s.m?r.l.remove(s._,s.p):n[i++]=s}0===i?this.o.delete(t):n.length=i}return!0}h(t,i,s,e,h){let r=this.o.get(t);if(void 0===r)return void this.o.set(t,{v:[{_:e,p:h,M:s,k:i,m:!1}],u:!1,l:new C(e,h,s)});if(r.l.has(e,h))throw Error("Event listener already exists");r.l.insert(e,h,s);const n={_:e,p:h,M:s,k:i,m:!1};r.u&&(r.u=!1,r.v=r.v.slice());{const t=r.v,i=n.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(n);if(t[0].M>=i)return void t.unshift(n);{let s=0,e=t.length;for(;e>s;){const h=s+e>>>1;i>t[h].M?s=h+1:e=h}t.splice(s,0,n)}}}}var A,P;function U(t){return t===A.INTERACTIVE||t===A.INTERACTIVE_TRANSPARENT}function H(t){return t!==A.HIDDEN}function R(){return new B}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE",t[t.INTERACTIVE_TRANSPARENT=3]="INTERACTIVE_TRANSPARENT"})(A||(A={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(P||(P={}));class B{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new V(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new V(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new B;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class V{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new V(this.first,this.second)}}class L{constructor(t=""){this.I=t}id(){return this.S}name(){return this.I}setName(t){this.I=t}context(){return this.C}setContext(t){this.C=t}value(){return this.T}setValue(t){this.T=t}plus(t){return new k(this,t)}minus(t){return new k(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new k([t,this])}divide(t){return new k([1/t,this])}toJSON(){return{name:this.I,value:this.T}}toString(){return this.C+"["+this.I+":"+this.T+"]"}I;T=0;C=null;S=D++}let D=0;class k{constructor(){let t=(t=>{let i=0,s=()=>0,e=R();for(let h=0,r=t.length;r>h;++h){let r=t[h];if("number"==typeof r)i+=r;else if(r instanceof L)e.setDefault(r,s).second+=1;else if(r instanceof k){i+=r.constant();let t=r.terms();for(let i=0,h=t.size();h>i;i++){let h=t.itemAt(i);e.setDefault(h.first,s).second+=h.second}}else{if(!(r instanceof Array))throw Error("invalid Expression argument: "+r);{if(2!==r.length)throw Error("array must have length 2");let t=r[0],h=r[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(h instanceof L)e.setDefault(h,s).second+=t;else{if(!(h instanceof k))throw Error("array item 1 must be a variable or expression");{i+=h.constant()*t;let r=h.terms();for(let i=0,h=r.size();h>i;i++){let h=r.itemAt(i);e.setDefault(h.first,s).second+=h.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.A=t.terms,this.P=t.constant}terms(){return this.A}constant(){return this.P}value(){let t=this.P;for(let i=0,s=this.A.size();s>i;i++){let s=this.A.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new k(this,t)}minus(t){return new k(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new k([t,this])}divide(t){return new k([1/t,this])}isConstant(){return 0==this.A.size()}toString(){let t=this.A.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.P||(t+=" + "),t+=this.P,t}A;P}class W{static create(t,i,s,e=1){let h=0;return h+=1e6*Math.max(0,Math.min(1e3,t*e)),h+=1e3*Math.max(0,Math.min(1e3,i*e)),h+=Math.max(0,Math.min(1e3,s*e)),h}static required=W.create(1e3,1e3,1e3);static strong=W.create(1,0,0);static medium=W.create(0,1,0);static weak=W.create(0,0,1);static clip(t){return Math.max(0,Math.min(W.required,t))}}var $;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})($||($={}));class N{constructor(t,i,s,e=W.required){this.U=i,this.H=W.clip(e),this.R=void 0===s&&t instanceof k?t:t.minus(s)}id(){return this.S}expression(){return this.R}op(){return this.U}strength(){return this.H}toString(){return this.R+" "+["<=",">=","="][this.U]+" 0 ("+this.H+")"}R;U;H;S=z++}let z=0;class F{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=W.required){let h=new N(t,i,s,e);return this.addConstraint(h),h}addConstraint(t){if(void 0!==this.B.find(t))throw Error("duplicate constraint");let i=this.V(t),s=i.row,e=i.tag,h=this.L(s,e);if(h.type()===G.Invalid&&s.allDummies()){if(!O(s.constant()))throw Error("unsatisfiable constraint");h=e.marker}if(h.type()===G.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(h),this.W(h,s),this.$.insert(h,s);this.B.insert(t,e),this.N(this.F)}removeConstraint(t){let i=this.B.erase(t);if(void 0===i)throw Error("unknown constraint");this.O(t,i.second);let s=i.second.marker,e=this.$.erase(s);if(void 0===e){let t=this.G(s);if(t.type()===G.Invalid)throw Error("failed to find leaving row");e=this.$.erase(t),e.second.solveForEx(t,s),this.W(s,e.second)}this.N(this.F)}hasConstraint(t){return this.B.contains(t)}getConstraints(){return this.B.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.j.find(t))throw Error("duplicate edit variable");if((i=W.clip(i))===W.required)throw Error("bad required strength");let s=new k(t),e=new N(s,$.Eq,void 0,i);this.addConstraint(e);let h=this.B.find(e).second;this.j.insert(t,{tag:h,constraint:e,constant:0})}removeEditVariable(t){let i=this.j.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.j.contains(t)}suggestValue(t,i){let s=this.j.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.$,h=s.second,r=i-h.constant;h.constant=i;let n=h.tag.marker,o=e.find(n);if(void 0!==o)return 0>o.second.add(-r)&&this.Y.push(n),void this.X();let a=h.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(r)&&this.Y.push(a),void this.X();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,h=s.coefficientFor(n);0!==h&&0>s.add(r*h)&&i.first.type()!==G.External&&this.Y.push(i.first)}this.X()}updateVariables(){let t=this.q,i=this.$;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),h=i.find(e.second);e.first.setValue(void 0!==h?h.second.constant():0)}}Z(t){return this.q.setDefault(t,()=>this.J(G.External)).second}V(t){let i=t.expression(),s=new X(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!O(i.second)){let t=this.Z(i.first),e=this.$.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let h=this.F,r=t.strength(),n={marker:Y,other:Y};switch(t.op()){case $.Le:case $.Ge:{let i=t.op()===$.Le?1:-1,e=this.J(G.Slack);if(n.marker=e,s.insertSymbol(e,i),W.required>r){let t=this.J(G.Error);n.other=t,s.insertSymbol(t,-i),h.insertSymbol(t,r)}break}case $.Eq:if(W.required>r){let t=this.J(G.Error),i=this.J(G.Error);n.marker=t,n.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),h.insertSymbol(t,r),h.insertSymbol(i,r)}else{let t=this.J(G.Dummy);n.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:n}}L(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===G.External)return i.first}let e=i.marker.type();return e!==G.Slack&&e!==G.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==G.Slack&&e!==G.Error||t.coefficientFor(i.other)>=0?Y:i.other):i.marker}D(t){let i=this.J(G.Slack);this.$.insert(i,t.copy()),this.K=t.copy(),this.N(this.K);let s=O(this.K.constant());this.K=null;let e=this.$.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let h=this.tt(t);if(h.type()===G.Invalid)return!1;t.solveForEx(i,h),this.W(h,t),this.$.insert(h,t)}let h=this.$;for(let t=0,s=h.size();s>t;++t)h.itemAt(t).second.removeSymbol(i);return this.F.removeSymbol(i),s}W(t,i){let s=this.$;for(let e=0,h=s.size();h>e;++e){let h=s.itemAt(e);h.second.substitute(t,i),0>h.second.constant()&&h.first.type()!==G.External&&this.Y.push(h.first)}this.F.substitute(t,i),this.K&&this.K.substitute(t,i)}N(t){let i=0;for(;this.maxIterations>i;){let s=this.it(t);if(s.type()===G.Invalid)return;let e=this.st(s);if(e.type()===G.Invalid)throw Error("the objective is unbounded");let h=this.$.erase(e).second;h.solveForEx(e,s),this.W(s,h),this.$.insert(s,h),i++}throw Error("solver iterations exceeded")}X(){let t=this.$,i=this.Y;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.et(e.second);if(i.type()===G.Invalid)throw Error("dual optimize failed");let h=e.second;t.erase(s),h.solveForEx(s,i),this.W(i,h),t.insert(i,h)}}}it(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first;if(0>s.second&&e.type()!==G.Dummy)return e}return Y}et(t){let i=Number.MAX_VALUE,s=Y,e=t.cells();for(let t=0,h=e.size();h>t;++t){let h=e.itemAt(t),r=h.first,n=h.second;if(n>0&&r.type()!==G.Dummy){let t=this.F.coefficientFor(r)/n;i>t&&(i=t,s=r)}}return s}st(t){let i=Number.MAX_VALUE,s=Y,e=this.$;for(let h=0,r=e.size();r>h;++h){let r=e.itemAt(h),n=r.first;if(n.type()!==G.External){let e=r.second,h=e.coefficientFor(t);if(0>h){let t=-e.constant()/h;i>t&&(i=t,s=n)}}}return s}G(t){let i=Number.MAX_VALUE,s=i,e=i,h=Y,r=h,n=h,o=h,a=this.$;for(let i=0,h=a.size();h>i;++i){let h=a.itemAt(i),c=h.second,u=c.coefficientFor(t);if(0===u)continue;let l=h.first;if(l.type()===G.External)o=l;else if(0>u){let t=-c.constant()/u;s>t&&(s=t,r=l)}else{let t=c.constant()/u;e>t&&(e=t,n=l)}}return r!==h?r:n!==h?n:o}O(t,i){i.marker.type()===G.Error&&this.ht(i.marker,t.strength()),i.other.type()===G.Error&&this.ht(i.other,t.strength())}ht(t,i){let s=this.$.find(t);void 0!==s?this.F.insertRow(s.second,-i):this.F.insertSymbol(t,-i)}tt(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first.type();if(e===G.Slack||e===G.Error)return s.first}return Y}J(t){return new j(t,this.rt++)}B=(()=>R())();$=(()=>R())();q=(()=>R())();j=(()=>R())();Y=[];F=new X;K=null;rt=0}function O(t){return 0>t?1e-8>-t:1e-8>t}var G;(t=>{t[t.Invalid=0]="Invalid",t[t.External=1]="External",t[t.Slack=2]="Slack",t[t.Error=3]="Error",t[t.Dummy=4]="Dummy"})(G||(G={}));class j{constructor(t,i){this.S=i,this.nt=t}id(){return this.S}type(){return this.nt}S;nt}let Y=new j(G.Invalid,-1);class X{constructor(t=0){this.P=t}cells(){return this.ot}constant(){return this.P}isConstant(){return this.ot.empty()}allDummies(){let t=this.ot;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==G.Dummy)return!1;return!0}copy(){let t=new X(this.P);return t.ot=this.ot.copy(),t}add(t){return this.P+=t}insertSymbol(t,i=1){O(this.ot.setDefault(t,()=>0).second+=i)&&this.ot.erase(t)}insertRow(t,i=1){this.P+=t.P*i;let s=t.ot;for(let t=0,e=s.size();e>t;++t){let e=s.itemAt(t);this.insertSymbol(e.first,e.second*i)}}removeSymbol(t){this.ot.erase(t)}reverseSign(){this.P=-this.P;let t=this.ot;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.ot,s=-1/i.erase(t).second;this.P*=s;for(let t=0,e=i.size();e>t;++t)i.itemAt(t).second*=s}solveForEx(t,i){this.insertSymbol(t,-1),this.solveFor(i)}coefficientFor(t){let i=this.ot.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.ot.erase(t);void 0!==s&&this.insertRow(i,s.second)}ot=R();P}const q=1e3;var Z;function J(t){switch(t){case Z.P0:return W.create(q,q,q);case Z.P1:return W.create(100,0,0);case Z.P2:return W.create(10,0,0);case Z.P3:return W.create(0,100,0);case Z.P4:return W.create(0,10,0);case Z.P5:return W.create(0,0,100);case Z.P6:return W.create(0,0,10);case Z.P7:return W.create(0,0,1);default:throw Error("convertPriority.priority: invalid priority")}}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(Z||(Z={}));class K{constructor(){this.dirty=!1,this.ct=!1,this.ut=[],this.lt=0}createInputCatcher(t,i,s,e){const h=this.lt++;return this.ut.push({handler:h,catchPointerDown:t,catchPointerMove:i,catchPointerUp:s,zIndex:e,active:!0}),this.ct=!0,this.dirty=!0,h}destroyInputCatcher(t){const i=this.ut.findIndex(i=>i.handler===t);if(-1===i)throw Error("UIInputWrapper.destroyInputCatcher.handler: handler not found");this.ut.splice(i,1)}getZIndex(t){this.ft();const i=this.ut.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getZIndex.handler: handler not found");return i.zIndex}setZIndex(t,i){const s=this.ut.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setZIndex.handler: handler not found");s.zIndex!==i&&(s.zIndex=i,this.ct=!0,this.dirty=!0)}getActive(t){const i=this.ut.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getActive.handler: handler not found");return i.active}setActive(t,i){const s=this.ut.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setActive.handler: handler not found");s.active!==i&&(s.active=i)}onPointerDown(t,i,s){this.ft();for(let e=this.ut.length-1;e>=0;e--){const h=this.ut[e];if(h.active&&h.catchPointerDown(t,i,s))break}}onPointerMove(t,i,s){this.ft();for(let e=this.ut.length-1;e>=0;e--){const h=this.ut[e];if(h.active&&h.catchPointerMove(t,i,s))break}}onPointerUp(t,i,s){this.ft();for(let e=this.ut.length-1;e>=0;e--){const h=this.ut[e];if(h.active&&h.catchPointerUp(t,i,s))break}}ft(){if(this.ct){this.ut.sort((t,i)=>t.zIndex-i.zIndex);const t=this.ut.length,i=1024>t?1:1024/t;for(let s=0;t>s;s++)this.ut[s].zIndex=s*i;this.ct=!1}}}function Q(t){return.04045>t?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function tt(t){return.0031308>t?12.92*t:1.055*Math.pow(t,.41666)-.055}const it={black:0,white:16777215,red:16711680,green:32768,blue:255,yellow:16776960,cyan:65535,magenta:16711935,gray:8421504,grey:8421504,silver:12632256,maroon:8388608,olive:8421376,lime:65280,aqua:65535,teal:32896,navy:128,fuchsia:16711935,purple:8388736,orange:16753920,pink:16761035,brown:10824234,gold:16766720,violet:15631086,indigo:4915330,coral:16744272,salmon:16416882,khaki:15787660,plum:14524637,orchid:14315734,tan:13808780,beige:16119260,mint:10025880,lavender:15132410,crimson:14423100,azure:15794175,ivory:16777200,snow:16775930};class st{constructor(...t){this.dt=1,this.wt=1,this.gt=1,this.vt=1,this.yt=0,this.xt=0,this.bt=1,this._t=!1,this.It=!1,this.St=!1,t.length>0&&this.set(...t)}static get black(){return new st("black")}static get white(){return new st("white")}static get red(){return new st("red")}static get green(){return new st("green")}static get blue(){return new st("blue")}static get yellow(){return new st("yellow")}static get cyan(){return new st("cyan")}static get magenta(){return new st("magenta")}static get gray(){return new st("gray")}static get grey(){return new st("grey")}static get silver(){return new st("silver")}static get maroon(){return new st("maroon")}static get olive(){return new st("olive")}static get lime(){return new st("lime")}static get aqua(){return new st("aqua")}static get teal(){return new st("teal")}static get navy(){return new st("navy")}static get fuchsia(){return new st("fuchsia")}static get purple(){return new st("purple")}static get orange(){return new st("orange")}static get pink(){return new st("pink")}static get brown(){return new st("brown")}static get gold(){return new st("gold")}static get violet(){return new st("violet")}static get indigo(){return new st("indigo")}static get coral(){return new st("coral")}static get salmon(){return new st("salmon")}static get khaki(){return new st("khaki")}static get plum(){return new st("plum")}static get orchid(){return new st("orchid")}static get tan(){return new st("tan")}static get beige(){return new st("beige")}static get mint(){return new st("mint")}static get lavender(){return new st("lavender")}static get crimson(){return new st("crimson")}static get azure(){return new st("azure")}static get ivory(){return new st("ivory")}static get snow(){return new st("snow")}get r(){return this.Et(),this.dt}get g(){return this.Et(),this.wt}get b(){return this.Et(),this.gt}get a(){return this.vt}get hue(){return this.Mt(),this.yt}get saturation(){return this.Mt(),this.xt}get lightness(){return this.Mt(),this.bt}get dirty(){return this._t}set r(i){i=t.clamp(i,0,1),this.Et(),i!==this.dt&&(this.dt=i,this.St=!0,this._t=!0)}set g(i){i=t.clamp(i,0,1),this.Et(),i!==this.wt&&(this.wt=i,this.St=!0,this._t=!0)}set b(i){i=t.clamp(i,0,1),this.Et(),i!==this.gt&&(this.gt=i,this.St=!0,this._t=!0)}set a(i){(i=t.clamp(i,0,1))!==this.vt&&(this.vt=i,this._t=!0)}set hue(i){i=t.clamp(i,0,360),this.Mt(),i!==this.yt&&(this.yt=i,this.It=!0,this._t=!0)}set saturation(i){i=t.clamp(i,0,1),this.Mt(),i!==this.xt&&(this.xt=i,this.It=!0,this._t=!0)}set lightness(i){i=t.clamp(i,0,1),this.Mt(),i!==this.bt&&(this.bt=i,this.It=!0,this._t=!0)}setDirtyFalse(){this._t=!1}set(...t){if(0===t.length||void 0===t[0])return this.setRGBA(1,1,1,1);if(t.length>=3&&"number"==typeof t[0]){const[i,s,e,h=1]=t;return this.setRGBA(i,s,e,h)}const[s,e=1]=t;if("string"==typeof s)return s.startsWith("#")?this.setHexString(s):this.setColorName(s,e);if(s instanceof st)return this.copy(s);if(s instanceof i)return this.setThreeColor(s,e);if("number"==typeof s)return this.setHexRGB(s,e);throw Error("UIColor.set: cannot create color from provided arguments")}setRGBA(i,s,e,h=this.vt){return i=t.clamp(i,0,1),s=t.clamp(s,0,1),e=t.clamp(e,0,1),h=t.clamp(h,0,1),this.Et(),i===this.dt&&s===this.wt&&e===this.gt&&h===this.vt||(this.dt=i,this.wt=s,this.gt=e,this.vt=h,this.St=!0,this._t=!0),this}getHexRGBA(){return this.Et(),Math.round(255*this.dt)<<24|Math.round(255*this.wt)<<16|Math.round(255*this.gt)<<8|Math.round(255*this.vt)}getHexRGB(){return this.Et(),Math.round(255*this.dt)<<16|Math.round(255*this.wt)<<8|Math.round(255*this.gt)}getHexStringRGB(){return"#"+this.getHexRGB().toString(16).padStart(6,"0")}getHexStringRGBA(){return"#"+this.getHexRGBA().toString(16).padStart(8,"0")}setHexRGBA(t){this.Et();const i=(t>>16&255)/255,s=(t>>8&255)/255,e=(255&t)/255,h=(t>>24&255)/255;return i===this.dt&&s===this.wt&&e===this.gt&&h===this.vt||(this.dt=i,this.wt=s,this.gt=e,this.vt=h,this.St=!0,this._t=!0),this}setHexRGB(i,s=this.vt){s=t.clamp(s,0,1),this.Et();const e=(i>>16&255)/255,h=(i>>8&255)/255,r=(255&i)/255;return e===this.dt&&h===this.wt&&r===this.gt&&s===this.vt||(this.dt=e,this.wt=h,this.gt=r,this.vt=s,this.St=!0,this._t=!0),this}setHexString(t){if(!t.startsWith("#"))throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"');const i=t.slice(1);if(6===i.length){const t=parseInt(i,16);if(isNaN(t))throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"');return this.setHexRGB(t)}if(8===i.length){const t=parseInt(i,16);if(isNaN(t))throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"');return this.setHexRGBA(t)}throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"')}setHSL(i,s,e,h=this.vt){return i=t.clamp(i,0,360),s=t.clamp(s,0,1),e=t.clamp(e,0,1),h=t.clamp(h,0,1),this.Mt(),i===this.yt&&s===this.xt&&e===this.bt&&h===this.vt||(this.yt=i,this.xt=s,this.bt=e,this.vt=h,this.It=!0,this._t=!0),this}setColorName(i,s=this.vt){s=t.clamp(s,0,1);const e=i.toLowerCase().trim(),h=it[e];if(void 0===h)throw Error("UIColor.setColorName.colorName: unknown color name");return this.setHexRGB(h,s)}setGLSLColor(i,s,e,h=this.vt){h=t.clamp(h,0,1),this.Et();const r=tt(i),n=tt(s),o=tt(e);return r===this.dt&&n===this.wt&&o===this.gt&&h===this.vt||(this.dt=r,this.wt=n,this.gt=o,this.vt=h,this.St=!0,this._t=!0),this}setThreeColor(i,s=this.vt){return s=t.clamp(s,0,1),this.Et(),i.r===this.dt&&i.g===this.wt&&i.b===this.gt&&s===this.vt||(this.dt=i.r,this.wt=i.g,this.gt=i.b,this.vt=s,this.St=!0,this._t=!0),this}toCSSColor(){return this.Et(),`rgba(${Math.round(255*this.dt)}, ${Math.round(255*this.wt)}, ${Math.round(255*this.gt)}, ${this.vt})`}toGLSLColor(t=new s){return this.Et(),t.x=Q(this.dt),t.y=Q(this.wt),t.z=Q(this.gt),t.w=this.vt,t}toThreeColor(t=new i){return this.Et(),t.r=this.dt,t.g=this.wt,t.b=this.gt,t}copy(t){return t instanceof st?(this.Et(),t.Et(),this.dt===t.dt&&this.wt===t.wt&&this.gt===t.gt&&this.vt===t.vt||(this.dt=t.dt,this.wt=t.wt,this.gt=t.gt,this.vt=t.vt,this.St=!0,this._t=!0)):(this.Et(),this.dt===t.r&&this.wt===t.g&&this.gt===t.b&&1===this.vt||(this.dt=t.r,this.wt=t.g,this.gt=t.b,this.vt=1,this.St=!0,this._t=!0)),this}clone(){return this.Et(),new st(this.dt,this.wt,this.gt,this.vt)}Et(){if(this.It){const{yt:t,xt:i,bt:s}=this,e=(1-Math.abs(2*s-1))*i,h=t/60,r=e*(1-Math.abs(h%2-1));let[n,o,a]=1>h?[e,r,0]:2>h?[r,e,0]:3>h?[0,e,r]:4>h?[0,r,e]:5>h?[r,0,e]:[e,0,r];const c=s-e/2;this.dt=n+c,this.wt=o+c,this.gt=a+c,this.It=!1}}Mt(){if(this.St){const{dt:t,wt:i,gt:s}=this,e=Math.max(t,i,s),h=Math.min(t,i,s),r=e-h,n=(e+h)/2;let o=0;0!==r&&(o=e===t?(i-s)/r+(s>i?6:0):e===i?(s-t)/r+2:(t-i)/r+4,o*=60);const a=0===r?0:r/(1-Math.abs(2*n-1));this.yt=o,this.xt=a,this.bt=n,this.St=!1}}}let et,ht;const rt=()=>(ht??(ht=(()=>{const t=document.createElement("canvas"),i=t.getContext("webgl2")??t.getContext("webgl");if(!i)return!1;if(i instanceof WebGL2RenderingContext)try{const t=i.createTexture();i.bindTexture(i.TEXTURE_2D,t),i.texStorage2D(i.TEXTURE_2D,1,i.SRGB8_ALPHA8,2,2);const s=i.getError();return i.deleteTexture(t),s===i.NO_ERROR}catch{return!1}const s=i.getExtension("EXT_sRGB");if(!s)return!1;try{const t=i.createTexture();i.bindTexture(i.TEXTURE_2D,t),i.texImage2D(i.TEXTURE_2D,0,s.SRGB_ALPHA_EXT,2,2,0,s.SRGB_ALPHA_EXT,i.UNSIGNED_BYTE,null);const e=i.getError();return i.deleteTexture(t),e===i.NO_ERROR}catch{return!1}})()),ht),nt=Object.freeze({glslTypeName:"float",bufferSize:1,instantiable:!0}),ot=Object.freeze({glslTypeName:"sampler2D",bufferSize:-1,instantiable:!1}),at=Object.freeze({glslTypeName:"vec2",bufferSize:2,instantiable:!0}),ct=Object.freeze({glslTypeName:"vec3",bufferSize:3,instantiable:!0}),ut=Object.freeze({glslTypeName:"vec4",bufferSize:4,instantiable:!0}),lt=Object.freeze({glslTypeName:"mat3",bufferSize:9,instantiable:!0}),ft=Object.freeze({glslTypeName:"mat4",bufferSize:16,instantiable:!0});function dt(t){if("string"==typeof t)switch(t){case"number":return nt;case"Texture":return ot;case"UIColor":case"Vector4":return ut;case"Vector2":return at;case"Vector3":return ct;case"Matrix3":return lt;case"Matrix4":return ft;default:throw Error("resolveGLSLTypeInfo.value: unsupported property type name")}if("function"==typeof t){if(t===Number)return nt;if(t===e)return ot;if(t===st)return ut;if(t===h)return at;if(t===r)return ct;if(t===s)return ut;if(t===n)return lt;if(t===o)return ft;throw Error("resolveGLSLTypeInfo.value: unsupported property type constructor")}if("number"==typeof t)return nt;if(t instanceof e)return ot;if(t instanceof st)return ut;if(t instanceof h)return at;if(t instanceof r)return ct;if(t instanceof s)return ut;if(t instanceof n)return lt;if(t instanceof o)return ft;throw Error("resolveGLSLTypeInfo.value: unsupported property type")}function pt(t,i){const s=i.uniforms["p_"+t];if(void 0===s)throw Error("resolvePropertyUniform.name: unknown uniform");return s}function wt(t){const i={};for(const s in t){const e=t[s];i[s]={value:e,glslTypeInfo:dt(e)}}return i}function gt(t){return"number"==typeof t||t instanceof e?t:t.clone()}function vt(t){const i={};for(const s in t){const e=t[s];i[s]={value:gt(e.value),glslTypeInfo:e.glslTypeInfo}}return i}function yt(t){return t.elements[14]}var mt;(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(mt||(mt={}));const xt=(()=>{const t=new a(1,1);t.translate(.5,.5,0);const i=new c;return i.index=t.index,i.setAttribute("position",t.attributes.position),i.setAttribute("uv",t.attributes.uv),t.dispose(),i})(),bt=new s;function _t(t,i,e){if(t instanceof st)t.toGLSLColor(bt),i[e]=bt.x,i[e+1]=bt.y,i[e+2]=bt.z,i[e+3]=bt.w;else if(t instanceof h)i[e]=t.x,i[e+1]=t.y;else if(t instanceof r)i[e]=t.x,i[e+1]=t.y,i[e+2]=t.z;else if(t instanceof s)i[e]=t.x,i[e+1]=t.y,i[e+2]=t.z,i[e+3]=t.w;else if(t instanceof n||t instanceof o){const s=t.elements;for(let t=0;s.length>t;t++)i[e+t]=s[t]}else"number"==typeof t&&(i[e]=t)}function It(t,i){const s=dt(t);if(!s.instantiable)throw Error("buildEmptyInstancedBufferAttribute.value: cannot create instanced attribute for non-instantiable type");return new l(new Float32Array(i*s.bufferSize),s.bufferSize)}function St(t,i,e){if("number"==typeof t)return i[e];if(t instanceof h)return new h(i[e],i[e+1]);if(t instanceof r)return new r(i[e],i[e+1],i[e+2]);if(t instanceof s)return new s(i[e],i[e+1],i[e+2],i[e+3]);if(t instanceof st)return(new st).setGLSLColor(i[e],i[e+1],i[e+2],i[e+3]);if(t instanceof n){const t=new n;return t.fromArray(i,e),t}if(t instanceof o){const t=new o;return t.fromArray(i,e),t}throw Error("reconstructValue.referenceValue: cannot reconstruct value for type")}function Et(t,i,s,e,h){if(0>=e||0===h)return;const r=s*i;t.copyWithin((s+h)*i,r,r+e*i)}function Mt(t,i,s,e,h){for(let r=0;h>r;r++)s[e+r]=t[i+r]}class Ct extends f{constructor(t,i,s,e=1){const h={},r={instanceVisibility:{value:1,glslTypeInfo:dt("number")},instanceTransform:{value:(new o).identity(),glslTypeInfo:dt("Matrix4")}};for(const t in i){const s=i[t];s.glslTypeInfo.instantiable?r[t]=s:h[t]=s}const n=xt.clone(),a=((t,i,s,e)=>{const h={},r=[],n=[],o=[],a=[];for(const t in i){const{value:s,glslTypeInfo:e}=i[t];h["p_"+t]={value:s instanceof st?s.toGLSLColor():s},r.push(`uniform ${e.glslTypeName} p_${t};`)}for(const t in s){const{glslTypeInfo:i}=s[t];n.push(`attribute ${i.glslTypeName} a_${t};`),o.push(`varying ${i.glslTypeName} p_${t};`),a.push(`p_${t} = a_${t};`)}const c=`\n // User attributes\n ${n.join("\n")}\n\n // Uniforms\n ${r.join("\n")}\n\n // Builtin varyings\n varying vec3 p_position;\n varying vec2 p_uv;\n\n // User varyings\n ${o.join("\n")}\n\n void main() {\n if (a_instanceVisibility < 0.5) {\n gl_Position = vec4(2.0, 2.0, 2.0, 1.0);\n return;\n }\n\n ${a.join("\n")}\n\n p_position = position;\n p_uv = uv;\n\n gl_Position = projectionMatrix * a_instanceTransform * vec4(position, 1.0);\n }\n `,l=((t,i,s)=>`\n // Defines\n #define PI 3.14159265359\n #define SRGB_SUPPORTED ${rt()?"1":"0"}\n\n // Uniforms\n ${t.join("\n")}\n\n // Builtin varyings\n varying vec3 p_position;\n varying vec2 p_uv;\n\n // User varyings\n ${i.join("\n")}\n\n #include <alphahash_pars_fragment>\n\n // sRGB decode helper\n vec4 srgbTexture2D(sampler2D textureSampler, vec2 uv) {\n #if SRGB_SUPPORTED\n return texture2D(textureSampler, uv);\n #else\n vec4 textureValue = texture2D(textureSampler, uv);\n return vec4(pow(textureValue.rgb, vec3(2.2)), textureValue.a);\n #endif\n }\n\n // Source must define vec4 draw() function\n ${s}\n void main() {\n vec4 diffuseColor = draw();\n #ifdef USE_ALPHATEST\n if (diffuseColor.a < 0.50) {\n discard;\n }\n #endif\n #ifdef USE_ALPHAHASH\n if (diffuseColor.a < getAlphaHashThreshold(p_position)) {\n discard;\n }\n #endif\n gl_FragColor = linearToOutputTexel(diffuseColor);\n }\n `)(r,o,t);return new u({uniforms:h,vertexShader:c,fragmentShader:l,transparent:e===mt.BLEND,alphaTest:e===mt.CLIP?.5:0,alphaHash:e===mt.HASH,depthWrite:e!==mt.BLEND,depthTest:!0})})(t,h,r,s);super(n,a),this.frustumCulled=!1,this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1,this.source=t,this.transparency=s,this.Ct=n,this.Tt=a,this.At=h,this.Pt=r,this.Ut=new Map,this.Ht=Math.max(4*Math.ceil(e/4),4),this.Rt=0,this.Ct.instanceCount=0;for(const t in this.Pt){const{value:i}=this.Pt[t],s=It(i,this.Ht);this.Ct.setAttribute("a_"+t,s),this.Ut.set(t,s)}for(const t in this.At){const{value:i}=this.At[t];pt(t,this.Tt).value=i}this.Tt.uniformsNeedUpdate=!0}get instancesCount(){return this.Rt}insertAt(t,i,s,e){if(0>t||t>this.Rt)throw Error(`UIGenericInstancedPlane.insertAt.index: out of bounds (index=${t}, count=${this.Rt})`);this.Bt(this.Rt+1),this.Rt>t&&this.Vt(t,1),this.Lt(t,i,s,e),this.Rt++,this.Ct.instanceCount=this.Rt}removeAt(t){if(0>t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.removeAt.index: out of bounds (index=${t}, count=${this.Rt})`);this.Rt-1>t&&this.Dt(t+1,1),this.Rt--,this.Ct.instanceCount=this.Rt}setPropertiesAt(t,i){if(0>t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.setPropertiesAt.index: out of bounds (index=${t}, count=${this.Rt})`);for(const s in i){const{value:e,glslTypeInfo:h}=i[s];if(h.instantiable){const i=this.kt(s);_t(e,i.array,t*i.itemSize),i.needsUpdate=!0}else pt(s,this.Tt).value=e,this.Tt.uniformsNeedUpdate=!0}}setTransformAt(t,i){if(0>t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.setTransformAt.index: out of bounds (index=${t}, count=${this.Rt})`);const s=this.kt("instanceTransform"),e=s.array,h=16*t,r=i.elements;for(let t=0;16>t;t++)e[h+t]=r[t];s.needsUpdate=!0}setVisibilityAt(t,i){if(0>t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.setVisibilityAt.index: out of bounds (index=${t}, count=${this.Rt})`);const s=this.kt("instanceVisibility");s.array[t]=i?1:0,s.needsUpdate=!0}extractDataAt(t){if(0>t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.extractDataAt.index: out of bounds (index=${t}, count=${this.Rt})`);const i={};for(const t in this.At){const s=this.At[t];i[t]={value:gt(s.value),glslTypeInfo:s.glslTypeInfo}}for(const s in this.Pt){if("instanceVisibility"===s||"instanceTransform"===s)continue;const{value:e,glslTypeInfo:h}=this.Pt[s],r=this.Ut.get(s);i[s]={value:St(e,r.array,t*r.itemSize),glslTypeInfo:h}}const s=this.Ut.get("instanceTransform").array,e=new o;e.fromArray(s,16*t);const h=this.Ut.get("instanceVisibility");return{source:this.source,properties:i,transform:e,visibility:h.array[t]>=.5,transparency:this.transparency}}getZIndexAt(t){if(0>t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.getZIndexAt.index: out of bounds (index=${t}, count=${this.Rt})`);return this.Ut.get("instanceTransform").array[16*t+14]}merge(t){if(0!==t.Rt){this.Bt(this.Rt+t.Rt);for(const[i,s]of this.Ut){const e=t.Ut.get(i);if(!e)throw Error(`UIGenericInstancedPlane.merge: missing attribute ${i} in source`);const h=s.itemSize;Mt(e.array,0,s.array,this.Rt*h,t.Rt*h),s.needsUpdate=!0}this.Rt+=t.Rt,this.Ct.instanceCount=this.Rt,t.Rt=0,t.Ct.instanceCount=0}}split(t){if(0>=t||t>=this.Rt)throw Error(`UIGenericInstancedPlane.split.atIndex: must be in range (0, count) (atIndex=${t}, count=${this.Rt})`);const i=this.Rt-t,s=new Ct(this.source,vt({...this.At,...this.Pt}),this.transparency,i);for(const[e,h]of this.Ut){const r=s.Ut.get(e);if(!r)throw Error(`UIGenericInstancedPlane.split: missing attribute ${e} in new plane`);const n=h.itemSize;Mt(h.array,t*n,r.array,0,i*n),r.needsUpdate=!0}return s.Rt=i,s.Ct.instanceCount=i,this.Rt=t,this.Ct.instanceCount=t,s}isCompatibleWith(t,i,s){return this.source===t&&this.transparency===s&&((t,i)=>{for(const s in i){if(!(s in t))return!1;const e=t[s].glslTypeInfo;if(e.glslTypeName!==i[s].glslTypeInfo.glslTypeName)return!1;if(!e.instantiable&&t[s].value!==i[s].value)return!1}return!0})({...this.At,...this.Pt},i)}getProperties(){return{...this.At,...this.Pt}}clearInstances(){this.Rt=0,this.Ct.instanceCount=0}destroy(){this.Ct.dispose(),this.Tt.dispose(),this.Ut.clear()}Bt(t){if(this.Ht>=t)return;const i=4*Math.ceil(t/4);for(const[t,s]of this.Ut){const e=s.itemSize,h=new Float32Array(i*e);h.set(s.array);const r=new l(h,e);this.Ct.setAttribute("a_"+t,r),this.Ut.set(t,r)}this.Ht=i}Vt(t,i){const s=this.Rt-t;if(s>0)for(const e of this.Ut.values())Et(e.array,e.itemSize,t,s,i),e.needsUpdate=!0}Dt(t,i){const s=this.Rt-t;if(s>0)for(const e of this.Ut.values())Et(e.array,e.itemSize,t,s,-i),e.needsUpdate=!0}Lt(t,i,s,e){const h=this.kt("instanceVisibility");h.array[t]=e?1:0,h.needsUpdate=!0;const r=this.kt("instanceTransform"),n=r.array,o=16*t,a=s.elements;for(let t=0;16>t;t++)n[o+t]=a[t];r.needsUpdate=!0;for(const s in i){const{value:e,glslTypeInfo:h}=i[s];if(h.instantiable){const i=this.Ut.get(s);i&&(_t(e,i.array,t*i.itemSize),i.needsUpdate=!0)}else pt(s,this.Tt).value=e,this.Tt.uniformsNeedUpdate=!0}}kt(t){const i=this.Ut.get(t);if(void 0===i)throw Error(`UIGenericInstancedPlane.resolveAttribute.name: unknown attribute "${t}"`);return i}}class Tt{constructor(t){this.Wt=new Map,this.lt=0,this.$t=[],this.Nt=new Map,this.zt=new Set,this.Ft=new Set,this.Ot=new Set,this.Gt=!1,this.jt=t}createPlane(t,i,s,e,h){const r=this.lt++,n=wt((t=>{const i={};for(const s in t)i[s]=gt(t[s]);return i})(i)),o=yt(s),a={source:t,properties:n,transform:s.clone(),visibility:e,transparency:h,zIndex:o};return this.Wt.set(r,a),this.zt.add(r),this.Gt=!0,r}destroyPlane(t){if(!this.Wt.has(t))throw Error(`UIPlaneRegistry.destroyPlane: handler ${t} not found`);this.Wt.delete(t),this.zt.has(t)?this.zt.delete(t):(this.Ot.delete(t),this.Ft.add(t),this.Gt=!0)}setProperties(t,i){const s=this.Yt(t),e=wt(i);let h=!1;for(const t in e){const i=e[t];i.glslTypeInfo.instantiable||s.properties[t].value!==i.value&&(h=!0),s.properties[t]={value:i.value,glslTypeInfo:i.glslTypeInfo}}if(h&&!this.zt.has(t))this.Ot.add(t),this.Gt=!0;else{const i=this.Nt.get(t);i&&i.mesh.setPropertiesAt(i.instanceIndex,e)}}setTransform(t,i){const s=this.Yt(t),e=yt(i),h=s.zIndex;if(s.transform.copy(i),s.zIndex=e,h===e||this.zt.has(t)){const s=this.Nt.get(t);s&&s.mesh.setTransformAt(s.instanceIndex,i)}else this.Ot.add(t),this.Gt=!0}setVisibility(t,i){this.Yt(t).visibility=i;const s=this.Nt.get(t);s&&s.mesh.setVisibilityAt(s.instanceIndex,i)}setTransparency(t,i){const s=this.Yt(t);s.transparency!==i&&(s.transparency=i,this.zt.has(t)||(this.Ot.add(t),this.Gt=!0))}flush(){this.Gt&&(this.Xt(),this.qt(),this.Zt(),this.Jt(),this.Kt(),this.Qt(),this.zt.clear(),this.Ft.clear(),this.Ot.clear(),this.Gt=!1)}Xt(){for(const t of this.Ft){const i=this.Nt.get(t);if(!i)continue;const{mesh:s,instanceIndex:e}=i;s.removeAt(e),this.ti(s,e+1,-1),this.Nt.delete(t)}}qt(){for(const t of this.Ot){const i=this.Nt.get(t);if(!i)continue;const{mesh:s,instanceIndex:e}=i;s.removeAt(e),this.ti(s,e+1,-1),this.Nt.delete(t),this.zt.add(t)}}Zt(){if(0===this.zt.size)return;const t=[];for(const i of this.zt){const s=this.Wt.get(i);s&&t.push({handler:i,state:s})}t.sort((t,i)=>t.state.zIndex-i.state.zIndex);for(let i=1;t.length>i;i++)if(t[i].state.zIndex===t[i-1].state.zIndex)throw Error(`UIPlaneRegistry.flush: duplicate zIndex=${t[i].state.zIndex} for handlers ${t[i-1].handler} and ${t[i].handler}`);for(const{handler:i,state:s}of t)this.ii(i,s)}ii(t,i){const{source:s,properties:e,transform:h,visibility:r,transparency:n,zIndex:o}=i;let a=null;for(const t of this.$t){if(!t.isCompatibleWith(s,e,n))continue;if(0===t.instancesCount){a=t;break}const i=t.getZIndexAt(0),h=t.getZIndexAt(t.instancesCount-1);if(o>=i-1&&h+1>=o){a=t;break}}if(a){const i=this.si(a,o);a.insertAt(i,e,h,r),this.ti(a,i,1),this.Nt.set(t,{mesh:a,instanceIndex:i})}else{const i=this.ei(o),a=new Ct(s,vt(e),n);a.insertAt(0,e,h,r),this.$t.splice(i,0,a),this.jt.add(a),this.Nt.set(t,{mesh:a,instanceIndex:0})}}Jt(){let t=0;for(;this.$t.length-1>t;){const i=this.$t[t],s=this.$t[t+1];if(0===i.instancesCount||0===s.instancesCount){t++;continue}const e=i.getZIndexAt(i.instancesCount-1);if(s.getZIndexAt(0)>e&&i.isCompatibleWith(s.source,s.getProperties(),s.transparency)){const e=i.instancesCount;i.merge(s),this.hi(s,i,e),this.jt.remove(s),s.destroy(),this.$t.splice(t+1,1);continue}t++}}Kt(){for(let t=this.$t.length-1;t>=0;t--){const i=this.$t[t];0===i.instancesCount&&(this.jt.remove(i),i.destroy(),this.$t.splice(t,1))}}Yt(t){const i=this.Wt.get(t);if(!i)throw Error(`UIPlaneRegistry.resolveState: handler ${t} not found`);return i}ei(t){for(let i=0;this.$t.length>i;i++){const s=this.$t[i];if(s.instancesCount>0&&s.getZIndexAt(0)>t)return i}return this.$t.length}si(t,i){for(let s=0;t.instancesCount>s;s++)if(t.getZIndexAt(s)>i)return s;return t.instancesCount}ti(t,i,s){for(const e of this.Nt.values())e.mesh!==t||i>e.instanceIndex||(e.instanceIndex+=s)}hi(t,i,s){for(const e of this.Nt.values())e.mesh===t&&(e.mesh=i,e.instanceIndex+=s)}Qt(){this.$t.sort((t,i)=>(t.instancesCount>0?t.getZIndexAt(0):0)-(i.instancesCount>0?i.getZIndexAt(0):0));for(let t=0;this.$t.length>t;t++)this.$t[t].renderOrder=t}}let At=new i,Pt=0,Ut=!1,Ht=!1,Rt=!1,Bt=!1;class Vt{constructor(t,i){this.jt=new d,this.ri=new Tt(this.jt),this.ni=new p(0,t,i,0,-1024,1024),this.ni.matrixAutoUpdate=!1,this.ni.matrixWorldAutoUpdate=!1}createPlane(t,i,s,e,h){return this.ri.createPlane(t,i,s,e,h)}destroyPlane(t){this.ri.destroyPlane(t)}setTransform(t,i){this.ri.setTransform(t,i)}setProperties(t,i){this.ri.setProperties(t,i)}setVisibility(t,i){this.ri.setVisibility(t,i)}setTransparency(t,i){this.ri.setTransparency(t,i)}insertCustomObject(t){return this.jt.add(t),this}removeCustomObject(t){return this.jt.remove(t),this}resize(t,i){return this.ni.right=t,this.ni.top=i,this.ni.updateProjectionMatrix(),this}render(t){return this.ri.flush(),At=t.getClearColor(At),Pt=t.getClearAlpha(),Ut=t.autoClear,Ht=t.autoClearColor,Rt=t.autoClearDepth,Bt=t.autoClearStencil,t.autoClear=!1,t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.setClearColor(0,1),t.clear(!1,!0,!0),t.render(this.jt,this.ni),t.setClearColor(At),t.setClearAlpha(Pt),t.autoClear=Ut,t.autoClearColor=Ht,t.autoClearDepth=Rt,t.autoClearStencil=Bt,this}}class Lt{constructor(t=0,i){if(this.constant=t,this.oi=i?new Map(i):new Map,i)for(let t=0;i.length>t;t++)jt()}static plus(t,i){const s=new Lt(t.constant+i.constant,Array.from(t.oi.entries()));for(const[t,e]of i.oi)s.plus(t,e);return s}static minus(t,i){const s=new Lt(t.constant-i.constant,Array.from(t.oi.entries()));for(const[t,e]of i.oi)s.minus(t,e);return s}plus(t,i){return this.oi.set(t,(this.oi.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this.oi)this.oi.set(i,s*t);return this}divide(t){if(0===t)throw Error("UIExpression.divide.value: cannot divide by zero");return this.multiply(1/t)}hasTerm(t){return this.oi.has(t)}copy(t){this.constant=t.constant,this.oi.clear();for(const[i,s]of t.oi)this.oi.set(i,s);return this}clone(){return new Lt(this.constant,Array.from(this.oi.entries()))}prepareTerms(){return Array.from(this.oi.entries())}}var Dt,kt;(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(Dt||(Dt={}));class Wt{constructor(){this.dirty=!1,this.ai=new F,this.ci=!1,this.ui=new Map,this.li=0,this.fi=new Map,this.di=0}createVariable(t,i){const s=this.li++,e=new L;if(i===Z.P0){const h={variable:e,priority:i,value:t};this.ui.set(s,h),h.constraint=this.pi(new Lt(0,[[s,1]]),new Lt(t),Dt.EQUAL,i);try{this.ai?.addConstraint(h.constraint)}catch{this.ai=void 0}}else{this.ui.set(s,{variable:e,priority:i,value:t});try{this.ai?.addEditVariable(e,J(i)),this.ai?.suggestValue(e,t)}catch{this.ai=void 0}}return this.ci=!0,this.dirty=!0,s}removeVariable(t){const i=this.ui.get(t);if(void 0===i)throw Error("UISolverWrapper.removeVariable.index: variable does not exist");for(const i of this.fi.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error("UISolverWrapper.removeVariable.index: variable is used in constraint");try{i.constraint?this.ai?.removeConstraint(i.constraint):this.ai?.removeEditVariable(i.variable)}catch{this.ai=void 0}this.ui.delete(t),this.ci=!0,this.dirty=!0}suggestVariableValue(t,i){const s=this.ui.get(t);if(void 0===s)throw Error("UISolverWrapper.suggestVariableValue.index: variable does not exist");s.value!==i&&(s.value=i,s.constraint?s.constraint=this.wi(s.constraint,(new Lt).plus(t,1),new Lt(s.value),Dt.EQUAL,s.priority):this.ai?.suggestValue(s.variable,i),this.ci=!0,this.dirty=!0)}setVariablePriority(t,i){const s=this.ui.get(t);if(void 0===s)throw Error("UISolverWrapper.setVariablePriority.index: variable does not exist");if(i!==s.priority){if(s.priority=i,s.priority===Z.P0){const i=(new Lt).plus(t,1),e=new Lt(s.value);s.constraint=this.pi(i,e,Dt.EQUAL,s.priority);try{this.ai?.addConstraint(s.constraint)}catch{this.ai=void 0}}else{if(s.constraint)try{this.ai?.removeConstraint(s.constraint)}catch{this.ai=void 0}s.constraint=void 0,this.gi(t,s)}this.ci=!0,this.dirty=!0}}readVariableValue(t){const i=this.ui.get(t);if(void 0===i)throw Error("UISolverWrapper.readVariableValue.index: variable does not exist");return void 0===this.ai&&this.yi(),this.ci&&(this.ai?.updateVariables(),this.ci=!1),i.variable.value()}createConstraint(t,i,s,e,h){const r=this.di++,n=this.pi(t,i,s,e);if(this.fi.set(r,{constraint:n,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:h}),h){try{this.ai?.addConstraint(n)}catch{this.ai=void 0}this.ci=!0,this.dirty=!0}return r}removeConstraint(t){const i=this.fi.get(t);if(void 0===i)throw Error("UISolverWrapper.removeConstraint.index: constraint does not exist");if(i.enabled)try{this.ai?.removeConstraint(i.constraint)}catch{this.ai=void 0}this.fi.delete(t),this.ci=!0,this.dirty=!0}setConstraintLHS(t,i){const s=this.fi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintLHS.index: constraint does not exist");s.lhs.copy(i),this.mi(s),this.ci=!0,this.dirty=!0}setConstraintRHS(t,i){const s=this.fi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRHS.index: constraint does not exist");s.rhs.copy(i),this.mi(s),this.ci=!0,this.dirty=!0}setConstraintRelation(t,i){const s=this.fi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRelation.index: constraint does not exist");s.relation!==i&&(s.relation=i,this.mi(s),this.ci=!0,this.dirty=!0)}setConstraintPriority(t,i){const s=this.fi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintPriority.index: constraint does not exist");s.priority!==i&&(s.priority=i,this.mi(s),this.ci=!0,this.dirty=!0)}setConstraintEnabled(t,i){const s=this.fi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintEnabled.index: constraint does not exist");if(i!==s.enabled){s.enabled=i;try{s.enabled?this.ai?.addConstraint(s.constraint):this.ai?.removeConstraint(s.constraint)}catch{this.ai=void 0}this.ci=!0,this.dirty=!0}}gi(t,i){const s=[];for(const i of this.fi.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.ai?.removeConstraint(i.constraint)}catch{this.ai=void 0}s.push(i)}this.ai?.removeEditVariable(i.variable),this.ai?.addEditVariable(i.variable,J(i.priority));for(const t of s)t.constraint=this.pi(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.ai?.addConstraint(t.constraint)}catch{this.ai=void 0;break}}mi(t){t.constraint=t.enabled?this.wi(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.pi(t.lhs,t.rhs,t.relation,t.priority)}wi(t,i,s,e,h){try{this.ai?.removeConstraint(t)}catch{this.ai=void 0}const r=this.pi(i,s,e,h);try{this.ai?.addConstraint(r)}catch{this.ai=void 0}return r}pi(t,i,s,e){return new N(this.xi(t),(t=>{switch(t){case Dt.EQUAL:return $.Eq;case Dt.LESS_THAN:return $.Le;case Dt.GREATER_THAN:return $.Ge;default:throw Error("convertRelation.relation: invalid relation")}})(s),this.xi(i),J(e))}xi(t){return new k(...t.prepareTerms().map(([t,i])=>{const s=this.ui.get(t);if(void 0===s)throw Error("UISolverWrapper.convertExpression.expression: variable does not exist");return[i,s.variable]}),t.constant)}yi(){if(this.ai)throw Error("UISolverWrapper.rebuildSolver: solver already exists");this.ai=new F;for(const t of this.ui.values())t.constraint?this.ai.addConstraint(t.constraint):(this.ai.addEditVariable(t.variable,J(t.priority)),this.ai.suggestValue(t.variable,t.value));for(const t of this.fi.values())t.enabled&&this.ai.addConstraint(t.constraint);this.ci=!0,this.dirty=!0}}(t=>{t.ORIENTATION_CHANGED="orientation_changed",t.MODE_CHANGED="mode_changed",t.RENDERING="rendering"})(kt||(kt={}));const $t=A.VISIBLE;class Nt extends T{constructor(t){super(),this.name="",this.inputWrapperInternal=new K,this.bi=new Wt;const i=t.width??1024,s=t.height??1024;this._i=new Vt(i,s),this.name=t.name??"",this.Ii=t.mode??$t,this.Si=i>s?P.HORIZONTAL:P.VERTICAL,this.xVariable=this.bi.createVariable(0,Z.P0),this.yVariable=this.bi.createVariable(0,Z.P0),this.wVariable=this.bi.createVariable(i,Z.P0),this.hVariable=this.bi.createVariable(s,Z.P0)}get sceneWrapper(){return this._i}get solverWrapper(){return this.bi}get inputWrapper(){return this.inputWrapperInternal}get x(){return this.bi.readVariableValue(this.xVariable)}get y(){return this.bi.readVariableValue(this.yVariable)}get width(){return this.bi.readVariableValue(this.wVariable)}get height(){return this.bi.readVariableValue(this.hVariable)}get mode(){return this.Ii}get orientation(){return this.Si}set mode(t){t!==this.Ii&&(this.Ii=t,this.emit(kt.MODE_CHANGED,this.Ii,this))}resizeInternal(t,i){this.bi.suggestVariableValue(this.wVariable,t),this.bi.suggestVariableValue(this.hVariable,i),this._i.resize(t,i);const s=t>i?P.HORIZONTAL:P.VERTICAL;s!==this.Si&&(this.Si=s,this.emit(kt.ORIENTATION_CHANGED,this.Si,this))}renderInternal(t,i){H(this.mode)&&(this.emit(kt.RENDERING,t,i,this),this._i.render(t)),this.bi.dirty=!1,this.inputWrapperInternal.dirty=!1}}const zt=1e-6;function Ft(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof Nt}function Ot(t){return"object"==typeof t&&null!==t&&"number"==typeof t.xVariable&&"number"==typeof t.yVariable&&"number"==typeof t.x&&"number"==typeof t.y}function Gt(t){return Ot(t)&&"number"==typeof t.wVariable&&"number"==typeof t.hVariable&&"number"==typeof t.width&&"number"==typeof t.height}function jt(){}function Yt(t,i,s){if(t instanceof Nt)return t;if(Ft(t))return t.layer;if(i instanceof Nt)return i;if(Ft(i))return i.layer;throw Error(s+": no valid subjects found")}function Xt(t,i,s){if(Ft(i))return i.layer;if(Ft(s))return s.layer;if(i instanceof Nt)return i;if(s instanceof Nt)return s;throw Error(t+": no valid subjects found")}class qt{constructor(t,i){this.layer=t,this.solverWrapper=this.layer.solverWrapper,this.name=i??""}}class Zt extends qt{constructor(t,i){var s,e,h;super(t,i?.name),this.Ei=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.Mi=(s=i?.priority,s??Z.P0),this.Ci=(e=i?.relation,e??Dt.EQUAL),this.Si=(h=i?.orientation,h??P.ALWAYS),this.layer.on(kt.ORIENTATION_CHANGED,this.Ei)}get priority(){return this.Mi}get relation(){return this.Ci}get orientation(){return this.Si}set priority(t){t!==this.Mi&&(this.Mi=t,this.solverWrapper.setConstraintPriority(this.constraint,this.Mi))}set relation(t){t!==this.Ci&&(this.Ci=t,this.solverWrapper.setConstraintRelation(this.constraint,this.Ci))}set orientation(t){t!==this.Si&&(this.Si=t,this.Ei())}destroy(){this.layer.off(kt.ORIENTATION_CHANGED,this.Ei),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.Si===P.ALWAYS||this.Si===this.layer.orientation}}class Jt extends Zt{constructor(t,i={}){super(t.layer,i),this.Ti=t,this.Ai=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new Lt(0,[[this.Ti.hVariable,1]]),new Lt(this.Ai),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.Ai}set height(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintRHS(this.constraint,new Lt(t)))}}class Kt extends Zt{constructor(t,i,s={}){super(Yt(t,i,"UIHorizontalDistanceConstraint.constructor"),s),this.Pi=t,this.Ui=i,this.Hi=s.anchorA??.5,this.Ri=s.anchorB??.5,this.Bi=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new Lt(this.Bi),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Bi}get anchorA(){return this.Hi}get anchorB(){return this.Ri}set distance(t){this.Bi!==t&&(this.Bi=t,this.solverWrapper.setConstraintRHS(this.constraint,new Lt(this.Bi)))}set anchorA(t){this.Hi!==t&&(this.Hi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i;if(Gt(this.Pi))t=new Lt(0,[[this.Pi.xVariable,1],[this.Pi.wVariable,this.Hi]]);else{if(!Ot(this.Pi))throw Error("UIHorizontalDistanceConstraint.buildLHS.a: invalid element type");t=(new Lt).plus(this.Pi.xVariable,1)}if(Gt(this.Ui))i=new Lt(0,[[this.Ui.xVariable,1],[this.Ui.wVariable,this.Ri]]);else{if(!Ot(this.Ui))throw Error("UIHorizontalDistanceConstraint.buildLHS.b: invalid element type");i=(new Lt).plus(this.Ui.xVariable,1)}return Lt.minus(i,t)}}class Qt extends Zt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Xt("UIHorizontalInterpolationConstraint.constructor",t,i),e),this.Pi=t,this.Ui=i,this.Li=s,this.Hi=h,this.Ri=h,this.Di=e.anchorC??.5,this.ki=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new Lt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.ki}get anchorA(){return this.Hi}get anchorB(){return this.Ri}get anchorC(){return this.Di}set t(t){this.ki!==t&&(this.ki=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorA(t){this.Hi!==t&&(this.Hi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorC(t){this.Di!==t&&(this.Di=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i,s;if(Gt(this.Pi))t=new Lt(0,[[this.Pi.xVariable,1],[this.Pi.wVariable,this.Hi]]);else{if(!Ot(this.Pi))throw Error("UIHorizontalInterpolationConstraint.buildLHS.a: invalid element type");t=(new Lt).plus(this.Pi.xVariable,1)}if(Gt(this.Ui))i=new Lt(0,[[this.Ui.xVariable,1],[this.Ui.wVariable,this.Ri]]);else{if(!Ot(this.Ui))throw Error("UIHorizontalInterpolationConstraint.buildLHS.b: invalid element type");i=(new Lt).plus(this.Ui.xVariable,1)}if(Gt(this.Li))s=new Lt(0,[[this.Li.xVariable,1],[this.Li.wVariable,this.Di]]);else{if(!Ot(this.Li))throw Error("UIHorizontalInterpolationConstraint.buildLHS.c: invalid element type");s=(new Lt).plus(this.Li.xVariable,1)}const e=t.clone().multiply(1-this.ki),h=i.clone().multiply(this.ki);return Lt.minus(Lt.minus(s,e),h)}}class ti extends Zt{constructor(t,i,s={}){super(Yt(t,i,"UIHorizontalProportionConstraint.constructor"),s),this.Pi=t,this.Ui=i,this.Wi=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new Lt(0),this.$i(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.Wi}set proportion(t){this.Wi!==t&&(this.Wi=t,this.solverWrapper.setConstraintRHS(this.constraint,this.$i()))}$i(){return Lt.minus(new Lt(0,[[this.Pi.wVariable,this.Wi]]),new Lt(0,[[this.Ui.wVariable,1]]))}}class ii extends Zt{constructor(t,i,s={}){super(Yt(t,i,"UIVerticalDistanceConstraint.constructor"),s),this.Pi=t,this.Ui=i,this.Hi=s.anchorA??.5,this.Ri=s.anchorB??.5,this.Bi=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new Lt(this.Bi),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Bi}get anchorA(){return this.Hi}get anchorB(){return this.Ri}set distance(t){this.Bi!==t&&(this.Bi=t,this.solverWrapper.setConstraintRHS(this.constraint,new Lt(this.Bi)))}set anchorA(t){this.Hi!==t&&(this.Hi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i;if(Gt(this.Pi))t=new Lt(0,[[this.Pi.yVariable,1],[this.Pi.hVariable,this.Hi]]);else{if(!Ot(this.Pi))throw Error("UIVerticalDistanceConstraint.buildLHS.a: invalid element type");t=(new Lt).plus(this.Pi.yVariable,1)}if(Gt(this.Ui))i=new Lt(0,[[this.Ui.yVariable,1],[this.Ui.hVariable,this.Ri]]);else{if(!Ot(this.Ui))throw Error("UIVerticalDistanceConstraint.buildLHS.b: invalid element type");i=(new Lt).plus(this.Ui.yVariable,1)}return Lt.minus(i,t)}}class si extends Zt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Xt("UIVerticalInterpolationConstraint.constructor",t,i),e),this.Pi=t,this.Ui=i,this.Li=s,this.Hi=h,this.Ri=h,this.Di=e.anchorC??.5,this.ki=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new Lt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.ki}get anchorA(){return this.Hi}get anchorB(){return this.Ri}get anchorC(){return this.Di}set t(t){this.ki!==t&&(this.ki=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorA(t){this.Hi!==t&&(this.Hi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorC(t){this.Di!==t&&(this.Di=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i,s;if(Gt(this.Pi))t=new Lt(0,[[this.Pi.yVariable,1],[this.Pi.hVariable,this.Hi]]);else{if(!Ot(this.Pi))throw Error("UIVerticalInterpolationConstraint.buildLHS.a: invalid element type");t=(new Lt).plus(this.Pi.yVariable,1)}if(Gt(this.Ui))i=new Lt(0,[[this.Ui.yVariable,1],[this.Ui.hVariable,this.Ri]]);else{if(!Ot(this.Ui))throw Error("UIVerticalInterpolationConstraint.buildLHS.b: invalid element type");i=(new Lt).plus(this.Ui.yVariable,1)}if(Gt(this.Li))s=new Lt(0,[[this.Li.yVariable,1],[this.Li.hVariable,this.Di]]);else{if(!Ot(this.Li))throw Error("UIVerticalInterpolationConstraint.buildLHS.c: invalid element type");s=(new Lt).plus(this.Li.yVariable,1)}const e=t.clone().multiply(1-this.ki),h=i.clone().multiply(this.ki);return Lt.minus(Lt.minus(s,e),h)}}class ei extends Zt{constructor(t,i,s={}){super(Yt(t,i,"UIVerticalProportionConstraint.constructor"),s),this.Pi=t,this.Ui=i,this.Wi=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new Lt(0),this.$i(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.Wi}set proportion(t){this.Wi!==t&&(this.Wi=t,this.solverWrapper.setConstraintRHS(this.constraint,this.$i()))}$i(){return Lt.minus(new Lt(0,[[this.Pi.hVariable,this.Wi]]),new Lt(0,[[this.Ui.hVariable,1]]))}}class hi extends Zt{constructor(t,i={}){super(t.layer,i),this.Ti=t,this.Ni=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new Lt(0,[[this.Ti.wVariable,1]]),new Lt(this.Ni),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Ni}set width(t){this.Ni!==t&&(this.Ni=t,this.solverWrapper.setConstraintRHS(this.constraint,new Lt(t)))}}function ri(t){return void 0===t?{}:Array.isArray(t)?{h:t[0],v:t[1]}:"object"==typeof t&&null!==t&&("h"in t||"v"in t)?t:{h:t,v:t}}class ni{static size(t,i={}){const s=ri(i.size),e=ri(i.priority),h=ri(i.relation),r=ri(i.orientation);return{h:new hi(t,{width:s.h,priority:e.h,relation:h.h,orientation:r.h}),v:new Jt(t,{height:s.v,priority:e.v,relation:h.v,orientation:r.v})}}static distance(t,i,s={}){const e=ri(s.anchorA),h=ri(s.anchorB),r=ri(s.distance),n=ri(s.priority),o=ri(s.relation),a=ri(s.orientation);return{h:new Kt(t,i,{anchorA:e.h,anchorB:h.h,distance:r.h,priority:n.h,relation:o.h,orientation:a.h}),v:new ii(t,i,{anchorA:e.v,anchorB:h.v,distance:r.v,priority:n.v,relation:o.v,orientation:a.v})}}static proportion(t,i,s={}){const e=ri(s.proportion),h=ri(s.priority),r=ri(s.relation),n=ri(s.orientation);return{h:new ti(t,i,{proportion:e.h,priority:h.h,relation:r.h,orientation:n.h}),v:new ei(t,i,{proportion:e.v,priority:h.v,relation:r.v,orientation:n.v})}}static interpolation(t,i,s,e={}){const h=ri(e.anchorA),r=ri(e.anchorB),n=ri(e.anchorC),o=ri(e.t),a=ri(e.priority),c=ri(e.relation),u=ri(e.orientation);return{h:new Qt(t,i,s,{anchorA:h.h,anchorB:r.h,anchorC:n.h,t:o.h,priority:a.h,relation:c.h,orientation:u.h}),v:new si(t,i,s,{anchorA:h.v,anchorB:r.v,anchorC:n.v,t:o.v,priority:a.v,relation:c.v,orientation:u.v})}}}class oi extends Zt{constructor(t,i={}){super(t.layer,i),this.Ti=t,this.zi=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new Lt(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.zi}set aspect(t){this.zi!==t&&(this.zi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){return new Lt(0,[[this.Ti.wVariable,1],[this.Ti.hVariable,-this.zi]])}}const ai=.5;class ci{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new oi(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Kt(t,i,{anchorA:s.anchorH??ai,anchorB:s.anchorH??ai,orientation:s.orientation}),yConstraint:new ii(t,i,{anchorA:s.anchorV??ai,anchorB:s.anchorV??ai,orientation:s.orientation}),widthConstraint:new ti(t,i,{proportion:1,relation:Dt.GREATER_THAN,orientation:s.orientation}),heightConstraint:new ei(t,i,{proportion:1,priority:Z.P1,orientation:s.orientation})}}}const ui=.5;class li{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new oi(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Kt(t,i,{anchorA:s.anchorH??ui,anchorB:s.anchorH??ui,orientation:s.orientation}),yConstraint:new ii(t,i,{anchorA:s.anchorV??ui,anchorB:s.anchorV??ui,orientation:s.orientation}),widthConstraint:new ti(t,i,{proportion:1,relation:Dt.LESS_THAN,orientation:s.orientation}),heightConstraint:new ei(t,i,{proportion:1,priority:Z.P1,orientation:s.orientation})}}}class fi extends Zt{constructor(t,i,s,e={}){super(t,e),this.Fi=i,this.Oi=s,this.constraint=this.solverWrapper.createConstraint(this.Fi,this.Oi,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Fi}get rhs(){return this.Oi}setLHS(t){this.Fi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Fi)}setRHS(t){this.Oi=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Oi)}}class di extends T{constructor(t,i){const s=i?.x??0,e=i?.y??0;super(),this.layer=t,this.name="",this.solverWrapper=this.layer.solverWrapper,this.xVariable=this.solverWrapper.createVariable(s,Z.P7),this.yVariable=this.solverWrapper.createVariable(e,Z.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}var pi;(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(pi||(pi={}));const wi=.5,gi=pi.ROTATION_SCALE,vi=new r,yi=new w,mi=new r,xi=new o,bi=new r(0,0,1);function _i(t,i,s,e,h,r,n,o,a,c,u,l,f,d,p,w,g){const v=s-d-p,y=e-w-g,m=o*s*c,x=a*e*u,b=Math.cos(l),_=Math.sin(l),I=m*b-x*_,S=m*_+x*b,E=d*c,M=g*u,C=E*b-M*_,T=E*_+M*b;if(f===pi.POSITION_ROTATION_SCALE)vi.x=t+r-I+C,vi.y=i+n-S+T;else{const h=a*e;vi.x=t+o*s-I+r+C,vi.y=i+h-S+n+T}return vi.z=h,mi.x=v*c,mi.y=y*u,yi.setFromAxisAngle(bi,l),xi.compose(vi,yi,mi),xi}const Ii=new e;var Si;(t=>{t[t.DIMENSIONS_CHANGED=0]="DIMENSIONS_CHANGED"})(Si||(Si={}));class Ei extends T{constructor(t){super(),this.Gi=Ii,this.ji=2,this.Yi=2,this.Xi=0,this.qi=0,this.Zi=2,this.Ji=2,this.Ki=!1,this.Qi=1,this.ts=0,this.ss=0,this.es=0,this.hs=0,this.rs=!1,this.ns=!1,this.cs=!1,void 0!==t&&this.set(t)}get width(){return this.ji/this.Qi}get height(){return this.Yi/this.Qi}get trimmedWidth(){return(this.Ki?this.Ji:this.Zi)/this.Qi}get trimmedHeight(){return(this.Ki?this.Zi:this.Ji)/this.Qi}get texture(){return this.Gi}get rotated(){return this.Ki}get scale(){return this.Qi}get trim(){const t=this.Qi;return{left:this.ts/t,right:this.ss/t,top:this.es/t,bottom:this.hs/t}}get textureDirty(){return this.rs}get uvTransformDirty(){return this.ns}get trimDirty(){return this.cs}setTextureDirtyFalse(){this.rs=!1}setUVTransformDirtyFalse(){this.ns=!1}setTrimDirtyFalse(){this.cs=!1}calculateUVTransform(t=new n){const i=this.Gi.image?.naturalWidth??2,s=this.Gi.image?.naturalHeight??2;if(this.Ki){const e=this.Zi,h=e/s;t.set(0,this.Ji/i,this.Xi/i,-h,0,(s-this.qi-e)/s+h,0,0,1)}else t.set(this.Zi/i,0,this.Xi/i,0,this.Ji/s,(s-this.qi-this.Ji)/s,0,0,1);return t}getResolution(t=new h){return t.set(this.width,this.height)}set(t){const i=this.width,s=this.height;t instanceof e?this.us(t):this.ls(t),this.width===i&&this.height===s||this.emit(Si.DIMENSIONS_CHANGED,this.width,this.height,this)}us(t){const i=t.image?.naturalWidth??2,s=t.image?.naturalHeight??2;this.ji=i,this.Yi=s,this.texture!==t&&(this.Gi=t,this.rs=!0),(0!==this.Xi||0!==this.qi||this.Zi!==i||this.Ji!==s||1!==this.Qi||this.Ki)&&(this.Xi=0,this.qi=0,this.Zi=i,this.Ji=s,this.Ki=!1,this.Qi=1,this.ns=!0),0===this.ts&&0===this.ss&&0===this.es&&0===this.hs||(this.ts=0,this.ss=0,this.es=0,this.hs=0,this.cs=!0)}ls(t){this.ji=t.sourceSize.w,this.Yi=t.sourceSize.h,this.texture!==t.texture&&(this.Gi=t.texture,this.rs=!0);const i=t.scale??1,s=t.rotated??!1;0===this.Xi&&0===this.qi&&this.Zi===t.frame.w&&this.Ji===t.frame.h&&this.Qi===i&&this.Ki===s||(this.Xi=t.frame.x,this.qi=t.frame.y,this.Zi=t.frame.w,this.Ji=t.frame.h,this.Qi=i,this.Ki=s,this.ns=!0);const e=t.spriteSourceSize,h=e.x,r=e.y,n=this.ji-e.x-e.w,o=this.Yi-e.y-e.h;this.ts===h&&this.ss===n&&this.es===r&&this.hs===o||(this.ts=h,this.ss=n,this.es=r,this.hs=o,this.cs=!0)}}var Mi,Ci="vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;return srgbTexture2D(p_texture,transformedUV)*p_color;}";class Ti{constructor(t){this._t=!0,this.fs=t?.x??0,this.ds=t?.y??0,this.ps=t?.anchorX??wi,this.ws=t?.anchorY??wi,this.gs=t?.scaleX??1,this.vs=t?.scaleY??1,this.ys=t?.rotation??0,this.xs=t?.anchorMode??gi}get x(){return this.fs}get y(){return this.ds}get anchorX(){return this.ps}get anchorY(){return this.ws}get scaleX(){return this.gs}get scaleY(){return this.vs}get angle(){return t.radToDeg(this.ys)}get anchorMode(){return this.xs}get rotation(){return this.ys}get dirty(){return this._t}set x(t){t!==this.fs&&(this.fs=t,this._t=!0)}set y(t){t!==this.ds&&(this.ds=t,this._t=!0)}set anchorX(t){t!==this.ps&&(this.ps=t,this._t=!0)}set anchorY(t){t!==this.ws&&(this.ws=t,this._t=!0)}set scaleX(t){t!==this.gs&&(this.gs=t,this._t=!0)}set scaleY(t){t!==this.vs&&(this.vs=t,this._t=!0)}set angle(i){const s=t.degToRad(i);s!==this.ys&&(this.ys=s,this._t=!0)}set rotation(t){t!==this.ys&&(this.ys=t,this._t=!0)}set anchorMode(t){t!==this.xs&&(this.xs=t,this._t=!0)}setDirtyFalse(){this._t=!1}reset(){0===this.fs&&0===this.ds&&this.ps===wi&&this.ws===wi&&1===this.gs&&1===this.vs&&0===this.ys||(this.fs=0,this.ds=0,this.ps=wi,this.ws=wi,this.gs=1,this.vs=1,this.ys=0,this._t=!0)}copy(t){this.fs===t.fs&&this.ds===t.ds&&this.ps===t.ps&&this.ws===t.ws&&this.gs===t.gs&&this.vs===t.vs&&this.ys===t.ys&&this.xs===t.xs||(this.fs=t.fs,this.ds=t.ds,this.ps=t.ps,this.ws=t.ws,this.gs=t.gs,this.vs=t.vs,this.ys=t.ys,this.xs=t.xs,this._t=!0)}}class Ai{}class Pi extends Ai{constructor(t,i,s,e){super(),this.x=t,this.y=i,this.width=s,this.height=e}contains(t,i){return!(this.x>t||t>this.x+this.width||this.y>i||i>this.y+this.height)}}(t=>{t.PRESSED="pointerdown",t.MOVED="pointermove",t.RELEASED="pointerup",t.ENTERED="pointerenter",t.LEFT="pointerleave"})(Mi||(Mi={}));const Ui=A.VISIBLE;class Hi extends di{constructor(t,i){const s=i?.width??64,e=i?.height??32;super(t,i),this.bs=!1,this.catchPointerDown=(t,i,s)=>this.handleInputEvent(t,i,s,Mi.PRESSED),this.catchPointerMove=(t,i,s)=>this.handleInputEvent(t,i,s,Mi.MOVED),this.catchPointerUp=(t,i,s)=>this.handleInputEvent(t,i,s,Mi.RELEASED),this.interactionArea=i?.interactionArea??new Pi(0,0,1,1),this.modeInternal=i?.mode??Ui,this.inputWrapper=this.layer.inputWrapper,this.wVariable=this.solverWrapper.createVariable(s,Z.P6),this.hVariable=this.solverWrapper.createVariable(e,Z.P6),this._s=this.inputWrapper.createInputCatcher(this.catchPointerDown,this.catchPointerMove,this.catchPointerUp,0),this.inputWrapper.setActive(this._s,U(this.modeInternal))}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get oppositeX(){return this.x+this.width}get oppositeY(){return this.y+this.height}get centerX(){return this.x+this.width/2}get centerY(){return this.y+this.height/2}get mode(){return this.modeInternal}get zIndex(){return this.inputWrapper.getZIndex(this._s)}set width(t){this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){this.solverWrapper.suggestVariableValue(this.hVariable,t)}set oppositeX(t){this.x=t-this.width}set oppositeY(t){this.y=t-this.height}set centerX(t){this.x=t-this.width/2}set centerY(t){this.y=t-this.height/2}set mode(t){if(this.modeInternal!==t){const i=U(t);this.inputWrapper.setActive(this._s,i),this.modeInternal=t}}set zIndex(t){this.inputWrapper.setZIndex(this._s,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.inputWrapper.destroyInputCatcher(this._s),super.destroy()}handleInputEvent(i,s,e,h){const r=this.interactionArea.contains(t.mapLinear(i,this.x,this.oppositeX,0,1),t.mapLinear(s,this.y,this.oppositeY,0,1));return r&&this.emit(h,i,s,e,this),this.bs&&!r?this.emit(Mi.LEFT,i,s,e,this):!this.bs&&r&&this.emit(Mi.ENTERED,i,s,e,this),this.bs=r,this.modeInternal!==A.INTERACTIVE_TRANSPARENT&&r}}const Ri=mt.BLEND;class Bi extends Hi{constructor(t,i,s,e){super(t,e),this.Is=!1,this.Ss=!1,this.micro=new Ti(e?.micro),this.Es=e?.transparencyMode??Ri,this.sceneWrapper=this.layer.sceneWrapper,this.planeHandler=this.sceneWrapper.createPlane(i,s,(new o).identity(),H(e?.mode??this.mode),this.Es),this.layer.on(kt.RENDERING,this.onWillRender,this)}get transparencyMode(){return this.Es}set transparencyMode(t){this.Es!==t&&(this.Es=t,this.Is=!0)}set mode(t){this.modeInternal!==t&&(this.Ss=H(this.modeInternal)!==H(t),super.mode=t)}destroy(){this.layer.off(kt.RENDERING,this.onWillRender,this),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}setPlaneTransform(){(this.micro.dirty||this.inputWrapper.dirty||this.solverWrapper.dirty)&&(this.sceneWrapper.setTransform(this.planeHandler,((t,i,s,e,h,r,n,o,a,c,u,l,f)=>{const d=s*this.micro.scaleX,p=e*this.micro.scaleY,w=o*d,g=a*p,v=Math.cos(l),y=Math.sin(l),m=w*v-g*y,x=w*y+g*v;if(f===pi.POSITION_ROTATION_SCALE)vi.x=t+r-m,vi.y=i+n-x;else{const h=a*e;vi.x=t+o*s-m+r,vi.y=i+h-x+n}return vi.z=h,mi.x=d,mi.y=p,yi.setFromAxisAngle(bi,l),xi.compose(vi,yi,mi),xi})(this.x,this.y,this.width,this.height,this.zIndex,this.micro.x,this.micro.y,this.micro.anchorX,this.micro.anchorY,0,0,this.micro.rotation,this.micro.anchorMode)),this.micro.setDirtyFalse())}onWillRender(t,i){this.Is&&(this.sceneWrapper.setTransparency(this.planeHandler,this.Es),this.Is=!1),this.Ss&&(this.sceneWrapper.setVisibility(this.planeHandler,H(this.modeInternal)),this.Ss=!1),this.setPlaneTransform()}}var Vi,Li;(t=>{t[t.PLAYED=0]="PLAYED",t[t.PAUSED=1]="PAUSED",t[t.STOPPED=2]="STOPPED"})(Vi||(Vi={})),(t=>{t[t.NONE=0]="NONE",t[t.LOOP=1]="LOOP",t[t.PING_PONG=2]="PING_PONG"})(Li||(Li={}));const Di=Li.LOOP;class ki extends Bi{constructor(t,i,s={}){const e=new st(s.color),h=i.map(t=>new Ei(t)),r=h[0];s.width=s.width??r.width,s.height=s.height??r.height;const n=r.calculateUVTransform();super(t,Ci,{texture:r.texture,textureTransform:n,color:e},s),this.Ms=!1,this.Cs=0,this.Ts=!1,this.As=0,this.Ps=(t,i,s)=>{this.Us[this.Cs]===s&&(this.width=t,this.height=i)},this.Hs=e,this.Us=h,this.Rs=n,this.Bs=s.frameRate??24,this.Vs=s.timeScale??1,this.Ls=s.loopMode??Di,this.Ds(),!0===s.playByDefault&&this.play()}get color(){return this.Hs}get duration(){return this.Us.length/this.Bs}get frameRate(){return this.Bs}get loopMode(){return this.Ls}get sequence(){return this.Us}get timeScale(){return this.Vs}set color(t){this.Hs.set(t)}set frameRate(t){this.Bs=t}set loopMode(t){this.Ls=t}set sequence(t){this.stop(),this.ks();const i=t.length,s=this.Us.length;for(let e=0;Math.min(i,s)>e;e++)this.Us[e].set(t[e]);if(s>i)this.Us.length=i;else if(i>s)for(let e=s;i>e;e++)this.Us.push(new Ei(t[e]));this.Ds()}set timeScale(t){this.Vs=t}destroy(){this.ks(),super.destroy()}play(){this.Ms||(this.Ms=!0,this.emit(Vi.PLAYED))}pause(){this.Ms&&(this.Ms=!1,this.emit(Vi.PAUSED))}stop(){(this.Ms||this.As>0||this.Cs>0)&&(this.Ms=!1,this.As=0,this.Cs=0,this.Ts=!0,this.emit(Vi.STOPPED))}onWillRender(t,i){if(this.Ms&&0!==this.Vs){this.As+=i*this.Vs;const t=1/this.Bs,s=this.Us.length,e=s-1;if(this.Vs>0)for(;this.As>=t;){if(this.As-=t,this.Cs+=1,this.Cs>=s)if(this.Ls===Li.LOOP)this.Cs=0;else{if(this.Ls!==Li.PING_PONG){this.Cs=e,this.Ms=!1,this.emit(Vi.PAUSED);break}this.Cs=e,this.Vs=-this.Vs}this.Ts=!0}else for(;-t>=this.As;){if(this.As+=t,this.Cs-=1,0>this.Cs)if(this.Ls===Li.LOOP)this.Cs=e;else{if(this.Ls!==Li.PING_PONG){this.Cs=0,this.Ms=!1,this.emit(Vi.PAUSED);break}this.Cs=0,this.Vs=-this.Vs}this.Ts=!0}}super.onWillRender(t,i)}setPlaneTransform(){let t;this.Hs.dirty&&(t??(t={}),t.color=this.Hs,this.Hs.setDirtyFalse());const i=this.Us[this.Cs];if((i.textureDirty||this.Ts)&&(t??(t={}),t.texture=i.texture,i.setTextureDirtyFalse()),(i.uvTransformDirty||this.Ts)&&(t??(t={}),t.textureTransform=i.calculateUVTransform(this.Rs),i.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.Ts||this.micro.dirty||i.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,s=i.trim;this.sceneWrapper.setTransform(this.planeHandler,_i(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,s.left,s.right,s.top,s.bottom)),this.Ts=!1,this.micro.setDirtyFalse(),i.setTrimDirtyFalse()}}Ds(){for(const t of this.Us)t.on(Si.DIMENSIONS_CHANGED,this.Ps)}ks(){for(const t of this.Us)t.off(Si.DIMENSIONS_CHANGED,this.Ps)}}function Wi(t,i){if(et??(et=(()=>{if("undefined"==typeof OffscreenCanvas)return!1;const t=document.createElement("canvas");t.width=4,t.height=4;const i=t.getContext("webgl")??t.getContext("webgl2");if(!i)return!1;try{const t=new OffscreenCanvas(4,4),s=t.getContext("2d");if(!s)return!1;s.fillStyle="#ff0000",s.fillRect(0,0,4,4);const e=i.createTexture();if(i.bindTexture(i.TEXTURE_2D,e),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.getError()!==i.NO_ERROR)return i.deleteTexture(e),!1;const h=i.createFramebuffer();if(i.bindFramebuffer(i.FRAMEBUFFER,h),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),i.checkFramebufferStatus(i.FRAMEBUFFER)!==i.FRAMEBUFFER_COMPLETE)return i.deleteFramebuffer(h),i.deleteTexture(e),!1;const r=new Uint8Array(4);return i.readPixels(0,0,1,1,i.RGBA,i.UNSIGNED_BYTE,r),i.bindFramebuffer(i.FRAMEBUFFER,null),i.deleteFramebuffer(h),i.deleteTexture(e),!!(r[0]>200&&50>r[1]&&50>r[2]&&r[3]>200)}catch(t){return!1}})()),et)return new OffscreenCanvas(t,i);const s=document.createElement("canvas");return s.width=t,s.height=i,s}function $i(t){const i=new g(t,v,y,y,m,m,x,b,1);return i.colorSpace=rt()?_:I,i.generateMipmaps=!1,i}const Ni=new st;class zi extends Bi{constructor(t,i){const s=i?.width??2,e=i?.height??2,h=new st(i?.color),r=Wi(s,e),o=r.getContext("2d");if(!o)throw Error("UIGraphics.constructor: failed to get 2D context from canvas");const a=$i(r);a.needsUpdate=!0,super(t,Ci,{texture:a,textureTransform:new n,color:h},i),this.Ws=r,this.$s=o,this.Ns=a,this.Hs=h}get color(){return this.Hs}set color(t){this.Hs.set(t)}clear(t){return this.$s.clearRect(0,0,this.Ws.width,this.Ws.height),void 0!==t&&(this.$s.fillStyle=Ni.set(t).toCSSColor(),this.$s.fillRect(0,0,this.Ws.width,this.Ws.height)),this.Ns.needsUpdate=!0,this}drawRect(t,i,s,e,h){return this.$s.fillStyle=Ni.set(h).toCSSColor(),this.$s.fillRect(t,i,s,e),this.Ns.needsUpdate=!0,this}drawCircle(t,i,s,e){return this.$s.fillStyle=Ni.set(e).toCSSColor(),this.$s.beginPath(),this.$s.arc(t,i,s,0,2*Math.PI),this.$s.fill(),this.Ns.needsUpdate=!0,this}drawArc(t,i,s,e,h,r){return this.$s.fillStyle=Ni.set(r).toCSSColor(),this.$s.beginPath(),this.$s.arc(t,i,s,e,h),this.$s.fill(),this.Ns.needsUpdate=!0,this}drawPolyline(t,i,s=1){if(2>t.length)return this;this.$s.strokeStyle=Ni.set(i).toCSSColor(),this.$s.lineWidth=s,this.$s.beginPath(),this.$s.moveTo(t[0][0],t[0][1]);for(let i=1;t.length>i;i++)this.$s.lineTo(t[i][0],t[i][1]);return this.$s.stroke(),this.Ns.needsUpdate=!0,this}destroy(){this.Ns.dispose(),super.destroy()}onWillRender(t,i){this.Hs.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.Hs}),this.Hs.setDirtyFalse()),super.onWillRender(t,i)}}class Fi extends Bi{constructor(t,i,s={}){const e=new st(s.color),h=new Ei(i),r=h.calculateUVTransform();s.width=s.width??h.width,s.height=s.height??h.height,super(t,Ci,{texture:h.texture,textureTransform:r,color:e},s),this.Ps=(t,i)=>{this.width=t,this.height=i},this.texture=h,this.Rs=r,this.Hs=e,this.texture.on(Si.DIMENSIONS_CHANGED,this.Ps)}get color(){return this.Hs}set color(t){this.Hs.set(t)}destroy(){this.texture.off(Si.DIMENSIONS_CHANGED,this.Ps),super.destroy()}setPlaneTransform(){let t;if(this.Hs.dirty&&(t??(t={}),t.color=this.Hs,this.Hs.setDirtyFalse()),this.texture.textureDirty&&(t??(t={}),t.texture=this.texture.texture,this.texture.setTextureDirtyFalse()),this.texture.uvTransformDirty&&(t??(t={}),t.textureTransform=this.texture.calculateUVTransform(this.Rs),this.texture.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.micro.dirty||this.texture.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,i=this.texture.trim;this.sceneWrapper.setTransform(this.planeHandler,_i(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom)),this.micro.setDirtyFalse(),this.texture.setTrimDirtyFalse()}}}class Oi{constructor(t){this.bt=0,this.dt=0,this.ki=0,this.gt=0,this._t=!1,this.set(t)}get left(){return this.bt}get right(){return this.dt}get top(){return this.ki}get bottom(){return this.gt}get dirty(){return this._t}set left(t){this.bt!==t&&(this.bt=t,this._t=!0)}set right(t){this.dt!==t&&(this.dt=t,this._t=!0)}set top(t){this.ki!==t&&(this.ki=t,this._t=!0)}set bottom(t){this.gt!==t&&(this.gt=t,this._t=!0)}setHorizontal(t){this.bt===t&&this.dt===t||(this.bt=t,this.dt=t,this._t=!0)}setVertical(t){this.ki===t&&this.gt===t||(this.ki=t,this.gt=t,this._t=!0)}setUnified(t){this.bt===t&&this.dt===t&&this.ki===t&&this.gt===t||(this.bt=t,this.dt=t,this.ki=t,this.gt=t,this._t=!0)}set(t){const i=this.bt,s=this.dt,e=this.ki,h=this.gt;if(void 0===t)this.bt=0,this.dt=0,this.ki=0,this.gt=0;else if("number"==typeof t)this.bt=t,this.dt=t,this.ki=t,this.gt=t;else if(Array.isArray(t))if(2===t.length){const i=t[0],s=t[1];this.bt=i,this.dt=i,this.ki=s,this.gt=s}else{const i=t[1],s=t[2],e=t[3];this.bt=t[0],this.dt=i,this.ki=s,this.gt=e}else if("left"in t){const i=t.right,s=t.top,e=t.bottom;this.bt=t.left,this.dt=i,this.ki=s,this.gt=e}else{const i=t.horizontal,s=t.vertical;this.bt=i,this.dt=i,this.ki=s,this.gt=s}this.bt===i&&this.dt===s&&this.ki===e&&this.gt===h||(this._t=!0)}setVector4(t){this.bt===t.x&&this.dt===t.y&&this.ki===t.z&&this.gt===t.w||(this.bt=t.x,this.dt=t.y,this.ki=t.z,this.gt=t.w,this._t=!0)}toVector4(t=new s){return t.set(this.bt,this.dt,this.ki,this.gt)}reset(){this.setUnified(0)}copy(t){this.bt===t.bt&&this.dt===t.dt&&this.ki===t.ki&&this.gt===t.gt||(this.bt=t.bt,this.dt=t.dt,this.ki=t.ki,this.gt=t.gt,this._t=!0)}setDirtyFalse(){this._t=!1}}var Gi;(t=>{t[t.NORMALIZED=0]="NORMALIZED",t[t.WORLD=1]="WORLD"})(Gi||(Gi={}));const ji=Gi.WORLD;class Yi extends Bi{constructor(t,i,e={}){const h=new st(e.color),r=new Ei(i),n=r.calculateUVTransform();e.width=e.width??r.width,e.height=e.height??r.height;const o=new Oi(e.sliceBorders??.1),a=new Oi(e.sliceRegions??.1),c=e.regionMode??ji,u=new s,l=new s;super(t,"vec4 draw(){vec2 localUV=p_uv;float left=p_sliceBorders.x;float right=p_sliceBorders.y;float top=p_sliceBorders.z;float bottom=p_sliceBorders.w;float leftFill=p_sliceRegions.x;float rightFill=p_sliceRegions.y;float topFill=p_sliceRegions.z;float bottomFill=p_sliceRegions.w;float lB=leftFill;float rB=1.0-rightFill;float bB=bottomFill;float tB=1.0-topFill;{float regionL=step(p_uv.x,lB);float regionR=step(rB,p_uv.x);float regionM=1.0-regionL-regionR;float xL=(p_uv.x/lB)*left;float xR=1.0-right+((p_uv.x-rB)/rightFill)*right;float xM=left+((p_uv.x-lB)/(rB-lB))*(1.0-left-right);localUV.x=regionL*xL+regionM*xM+regionR*xR;}{float regionB=step(p_uv.y,bB);float regionT=step(tB,p_uv.y);float regionC=1.0-regionB-regionT;float yB=(p_uv.y/bB)*bottom;float yT=1.0-top+((p_uv.y-tB)/topFill)*top;float yC=bottom+((p_uv.y-bB)/(tB-bB))*(1.0-bottom-top);localUV.y=regionB*yB+regionC*yC+regionT*yT;}vec2 transformedUV=(p_textureTransform*vec3(localUV,1.0)).xy;return srgbTexture2D(p_texture,transformedUV)*p_color;}",{texture:r.texture,textureTransform:n,color:h,sliceBorders:u,sliceRegions:l},e),this.zs=!0,this.Fs=new s,this.Os=new s,this.Gs=!0,this.Ps=()=>{this.Gs=!0},this.texture=r,this.Rs=n,this.Hs=h,this.js=o,this.Ys=a,this.Xs=c,this.Fs=u,this.Os=l,this.qs=this.width,this.Zs=this.height,this.texture.on(Si.DIMENSIONS_CHANGED,this.Ps)}get color(){return this.Hs}get regionMode(){return this.Xs}get sliceBorders(){return this.js}get sliceRegions(){return this.Ys}set color(t){this.Hs.set(t)}set regionMode(t){this.Xs!==t&&(this.Xs=t,this.zs=!0)}set sliceBorders(t){this.js.set(t)}set sliceRegions(t){this.Ys.set(t)}destroy(){this.texture.off(Si.DIMENSIONS_CHANGED,this.Ps),super.destroy()}setPlaneTransform(){let t;if((this.Gs||this.js.dirty||this.texture.trimDirty)&&(t??(t={}),t.sliceBorders=this.Js(this.Fs),this.js.setDirtyFalse(),this.Gs=!1),(this.Ys.dirty||this.zs||this.Xs===Gi.WORLD&&this.Ks())&&(t??(t={}),t.sliceRegions=this.Qs(this.Os),this.Ys.setDirtyFalse(),this.zs=!1,this.te()),this.Hs.dirty&&(t??(t={}),t.color=this.Hs,this.Hs.setDirtyFalse()),this.texture.textureDirty&&(t??(t={}),t.texture=this.texture.texture,this.texture.setTextureDirtyFalse()),this.texture.uvTransformDirty&&(t??(t={}),t.textureTransform=this.texture.calculateUVTransform(this.Rs),this.texture.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.micro.dirty||this.texture.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,i=this.texture.trim;this.sceneWrapper.setTransform(this.planeHandler,_i(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom)),this.micro.setDirtyFalse(),this.texture.setTrimDirtyFalse()}}Js(t){const i=this.texture.width,s=this.texture.height,e=this.texture.trim,h=e.right/i,r=e.top/s,n=e.bottom/s,o=(i-e.left-e.right)/i,a=(s-e.top-e.bottom)/s,c=this.js.right,u=this.js.top,l=this.js.bottom,f=Math.max(0,this.js.left-e.left/i)/o,d=Math.max(0,c-h)/o,p=Math.max(0,u-r)/a,w=Math.max(0,l-n)/a;return t.set(Math.min(1,f),Math.min(1,d),Math.min(1,p),Math.min(1,w))}Qs(t){if(this.Xs===Gi.NORMALIZED)return t.set(this.Ys.left,this.Ys.right,this.Ys.top,this.Ys.bottom);const i=this.width,s=this.height;return t.set(this.Ys.left/i,this.Ys.right/i,this.Ys.top/s,this.Ys.bottom/s)}Ks(){return this.solverWrapper.dirty&&(this.qs!==Math.round(this.width)||this.Zs!==Math.round(this.height))}te(){this.qs=Math.round(this.width),this.Zs=Math.round(this.height)}}class Xi{constructor(t){this.source=t,this.dirtyInternal=!1}get dirty(){return this.dirtyInternal}setDirtyFalse(){this.dirtyInternal=!1}}class qi extends Xi{constructor(t={x:1,y:0}){super("float calculateMask(){float aspect=p_textureResolution.x/p_textureResolution.y;vec2 halfExtents=vec2(aspect,1.0)*0.5;float maxProjection=dot(halfExtents,abs(p_direction));vec2 correctedUV=(p_uv-0.5)*vec2(aspect,1.0);float projection=dot(correctedUV,p_direction);float offset=(projection/maxProjection+1.0)*0.5;return step(offset,p_progress);}"),this.direction=new h,this.ie=new h,this.direction.set(t.x,t.y).normalize(),this.ie.copy(this.direction)}get dirty(){return this.se(),this.dirtyInternal||!this.ie.equals(this.direction)}setDirtyFalse(){this.se(),this.ie.copy(this.direction),super.setDirtyFalse()}enumerateProperties(){return this.se(),{direction:this.direction}}se(){const t=this.direction.lengthSq();Math.abs(t)>zt?Math.abs(t-1)>zt&&this.direction.divideScalar(t):this.direction.set(1,0)}}var Zi,Ji="vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=srgbTexture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}";class Ki extends Bi{constructor(i,s,e={}){const h=new st(e.color),r=new Ei(s),n=r.calculateUVTransform(),o=r.getResolution();e.width=e.width??r.width,e.height=e.height??r.height;const a=t.clamp(e.progress??1,0,1),c=e.maskFunction??new qi;super(i,c.source+Ji,{texture:r.texture,textureTransform:n,textureResolution:o,color:h,progress:a,...c.enumerateProperties()},e),this.ee=!1,this.he=!1,this.Ps=(t,i)=>{this.width===t&&this.height===i||(this.width=t,this.height=i,this.he=!0)},this.texture=r,this.Rs=n,this.re=o,this.Hs=h,this.ne=a,this.oe=c,this.texture.on(Si.DIMENSIONS_CHANGED,this.Ps)}get color(){return this.Hs}get maskFunction(){return this.oe}get progress(){return this.ne}set color(t){this.Hs.set(t)}set maskFunction(t){this.oe!==t&&(this.oe=t,this.ae())}set progress(i){i=t.clamp(i,0,1),this.ne!==i&&(this.ne=i,this.ee=!0)}setPlaneTransform(){let t;if(this.Hs.dirty&&(t??(t={}),t.color=this.Hs,this.Hs.setDirtyFalse()),this.texture.textureDirty&&(t??(t={}),t.texture=this.texture.texture,this.texture.setTextureDirtyFalse()),this.texture.uvTransformDirty&&(t??(t={}),t.textureTransform=this.texture.calculateUVTransform(this.Rs),this.texture.setUVTransformDirtyFalse()),this.ee&&(t??(t={}),t.progress=this.ne,this.ee=!1),this.he&&(t??(t={}),t.textureResolution=this.texture.getResolution(this.re),this.he=!1),this.maskFunction.dirty){t??(t={});const i=this.maskFunction.enumerateProperties();for(const s in i)t[s]=i[s];this.maskFunction.setDirtyFalse()}if(t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.micro.dirty||this.texture.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,i=this.texture.trim;this.sceneWrapper.setTransform(this.planeHandler,_i(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom)),this.micro.setDirtyFalse(),this.texture.setTrimDirtyFalse()}}ae(){this.sceneWrapper.destroyPlane(this.planeHandler);const t=this.micro,i=this.texture.trim;this.planeHandler=this.sceneWrapper.createPlane(this.oe.source+Ji,{texture:this.texture.texture,textureTransform:this.texture.calculateUVTransform(this.Rs),textureResolution:this.texture.getResolution(this.re),color:this.Hs,progress:this.ne,...this.oe.enumerateProperties()},_i(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom),H(this.mode),this.transparencyMode),this.Hs.setDirtyFalse(),this.texture.setTextureDirtyFalse(),this.texture.setUVTransformDirtyFalse(),this.texture.setTrimDirtyFalse(),this.ee=!1,this.he=!1,this.oe.setDirtyFalse(),this.micro.setDirtyFalse()}}(t=>{t[t.EVERY_FRAME=1]="EVERY_FRAME",t[t.EVERY_SECOND_FRAME=2]="EVERY_SECOND_FRAME",t[t.ON_PROPERTIES_CHANGE=3]="ON_PROPERTIES_CHANGE",t[t.ON_DIMENSIONS_CHANGE=4]="ON_DIMENSIONS_CHANGE",t[t.MANUAL=5]="MANUAL"})(Zi||(Zi={}));const Qi=Zi.ON_PROPERTIES_CHANGE,ts=new st(0,0,0,1);class is extends Bi{constructor(i,s={}){const e=t.clamp(s.resolutionFactor??.5,.1,2),h=s.width??64,r=s.height??32,o=new S(h*e,r*e,{format:x,minFilter:m,magFilter:m,type:b,depthBuffer:s.enableDepthBuffer??!0,stencilBuffer:!1}),a=new st(s.color);super(i,Ci,{texture:o.texture,textureTransform:new n,color:a},s),this.ce=!0,this.ue=!1,this.le=!1,this.fe=!1,this.Hs=a,this.de=new st(s.clearColor??ts),this.pe=o,this.we=s.scene??new d,this.ge=s.camera??new E(60,h/r,.1,100),this.ve=e,this.ye=s.updateMode??Qi,this.fe=s.updateMode!==Zi.MANUAL}get camera(){return this.ge}get clearColor(){return this.de}get color(){return this.Hs}get resolutionFactor(){return this.ve}get scene(){return this.we}get updateMode(){return this.ye}set camera(t){this.ge!==t&&(this.ge=t,this.fe=!0)}set clearColor(t){this.de.set(t)}set color(t){this.Hs.set(t)}set resolutionFactor(i){i=t.clamp(i,.1,2),this.ve!==i&&(this.ve=i,this.le=!0)}set scene(t){this.we!==t&&(this.we=t,this.fe=!0)}set updateMode(t){this.ye!==t&&(this.ye=t,this.fe=!0)}destroy(){this.pe.dispose(),super.destroy()}requestUpdate(){this.ue=!0}onWillRender(t,i){this.ce=!this.ce,(this.ue||this.ye===Zi.EVERY_FRAME||this.ye===Zi.EVERY_SECOND_FRAME&&this.ce||this.ye===Zi.ON_PROPERTIES_CHANGE&&this.fe||this.Hs.dirty||this.de.dirty||this.ye===Zi.ON_DIMENSIONS_CHANGE&&(this.le||this.solverWrapper.dirty))&&((this.le||this.solverWrapper.dirty)&&(this.pe.setSize(this.width*this.ve,this.height*this.ve),this.le=!1),this.Hs.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.Hs}),this.Hs.setDirtyFalse()),t.setClearColor(this.de.getHexRGB(),this.de.a),t.setRenderTarget(this.pe),t.clear(!0,!0,!1),t.render(this.we,this.ge),this.fe=!1,this.ue=!1),super.onWillRender(t,i)}}const ss="#000000",es="left",hs="Arial",rs="normal",ns="normal",os=!1,as="transparent",cs=!1,us="#000000";class ls{constructor(t){this._t=!0,this.Hs=t?.color,this.me=t?.align,this.xe=t?.fontFamily,this.be=t?.fontSize,this._e=t?.fontStyle,this.Ie=t?.fontWeight,this.Se=t?.lineHeight,this.Ee=t?.enableShadow,this.Me=t?.shadowOffsetX,this.Ce=t?.shadowOffsetY,this.Te=t?.shadowBlur,this.Ae=t?.shadowColor,this.Pe=t?.enableStroke,this.Ue=t?.strokeColor,this.He=t?.strokeThickness}get color(){return this.Hs}get align(){return this.me}get fontFamily(){return this.xe}get fontSize(){return this.be}get fontStyle(){return this._e}get fontWeight(){return this.Ie}get lineHeight(){return this.Se}get enableShadow(){return this.Ee}get shadowOffsetX(){return this.Me}get shadowOffsetY(){return this.Ce}get shadowBlur(){return this.Te}get shadowColor(){return this.Ae}get enableStroke(){return this.Pe}get strokeColor(){return this.Ue}get strokeThickness(){return this.He}get dirty(){return this._t}set color(t){t!==this.Hs&&(this.Hs=t,this._t=!0)}set align(t){t!==this.me&&(this.me=t,this._t=!0)}set fontFamily(t){t!==this.xe&&(this.xe=t,this._t=!0)}set fontSize(t){t!==this.be&&(this.be=t,this._t=!0)}set fontStyle(t){t!==this._e&&(this._e=t,this._t=!0)}set fontWeight(t){t!==this.Ie&&(this.Ie=t,this._t=!0)}set lineHeight(t){t!==this.Se&&(this.Se=t,this._t=!0)}set enableShadow(t){t!==this.Ee&&(this.Ee=t,this._t=!0)}set shadowOffsetX(t){t!==this.Me&&(this.Me=t,this._t=!0)}set shadowOffsetY(t){t!==this.Ce&&(this.Ce=t,this._t=!0)}set shadowBlur(t){t!==this.Te&&(this.Te=t,this._t=!0)}set shadowColor(t){t!==this.Ae&&(this.Ae=t,this._t=!0)}set enableStroke(t){t!==this.Pe&&(this.Pe=t,this._t=!0)}set strokeColor(t){t!==this.Ue&&(this.Ue=t,this._t=!0)}set strokeThickness(t){t!==this.He&&(this.He=t,this._t=!0)}static resolve(t,i){const s=t.be??i.be??16;return{color:t.Hs??i.Hs??ss,align:t.me??i.me??es,fontFamily:t.xe??i.xe??hs,fontSize:s,fontStyle:t._e??i._e??rs,fontWeight:t.Ie??i.Ie??ns,lineHeight:t.Se??i.Se??1.2*s,enableShadow:t.Ee??i.Ee??os,shadowOffsetX:t.Me??i.Me??0,shadowOffsetY:t.Ce??i.Ce??0,shadowBlur:t.Te??i.Te??0,shadowColor:t.Ae??i.Ae??as,enableStroke:t.Pe??i.Pe??cs,strokeColor:t.Ue??i.Ue??us,strokeThickness:t.He??i.He??0}}setDirtyFalse(){this._t=!1}setDefaults(){this.Hs===ss&&this.me===es&&this.xe===hs&&16===this.be&&this._e===rs&&this.Ie===ns&&19.2===this.Se&&this.Ee===os&&0===this.Me&&0===this.Ce&&0===this.Te&&this.Ae===as&&this.Pe===cs&&this.Ue===us&&0===this.He||(this.Hs=ss,this.me=es,this.xe=hs,this.be=16,this._e=rs,this.Ie=ns,this.Se=19.2,this.Ee=os,this.Me=0,this.Ce=0,this.Te=0,this.Ae=as,this.Pe=cs,this.Ue=us,this.He=0,this._t=!0)}clear(){void 0===this.Hs&&void 0===this.me&&void 0===this.xe&&void 0===this.be&&void 0===this._e&&void 0===this.Ie&&void 0===this.Se&&void 0===this.Ee&&void 0===this.Me&&void 0===this.Ce&&void 0===this.Te&&void 0===this.Ae&&void 0===this.Pe&&void 0===this.Ue&&void 0===this.He||(this.Hs=void 0,this.me=void 0,this.xe=void 0,this.be=void 0,this._e=void 0,this.Ie=void 0,this.Se=void 0,this.Ee=void 0,this.Me=void 0,this.Ce=void 0,this.Te=void 0,this.Ae=void 0,this.Pe=void 0,this.Ue=void 0,this.He=void 0,this._t=!0)}copy(t){this.Hs===t.Hs&&this.me===t.me&&this.xe===t.xe&&this.be===t.be&&this._e===t._e&&this.Ie===t.Ie&&this.Se===t.Se&&this.Ee===t.Ee&&this.Me===t.Me&&this.Ce===t.Ce&&this.Te===t.Te&&this.Ae===t.Ae&&this.Pe===t.Pe&&this.Ue===t.Ue&&this.He===t.He||(this.Hs=t.Hs,this.me=t.me,this.xe=t.xe,this.be=t.be,this._e=t._e,this.Ie=t.Ie,this.Se=t.Se,this.Ee=t.Ee,this.Me=t.Me,this.Ce=t.Ce,this.Te=t.Te,this.Ae=t.Ae,this.Pe=t.Pe,this.Ue=t.Ue,this.He=t.He,this._t=!0)}calculatePadding(){let t=0;if(void 0!==this.Pe&&(t+=this.He??0),void 0!==this.Ee){const i=this.Ce??0,s=2*(this.Te??0);t+=Math.max(Math.abs(this.Me??0)+s,Math.abs(i)+s)}return Math.ceil(t)}}class fs{constructor(t){this._t=!0,this.Re=t.text,this.style=new ls(t.style)}get text(){return this.Re}get dirty(){return this._t||this.style.dirty}set text(t){t!==this.Re&&(this.Re=t,this._t=!0)}setDirtyFalse(){this._t=!1,this.style.setDirtyFalse()}}var ds;(t=>{t[t.BREAK=0]="BREAK",t[t.SCALE=1]="SCALE"})(ds||(ds={}));const ps=ds.SCALE;function ws(t){return t.match(/\S+|\s|\n/g)??[]}function gs(t,i,s){if(t.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px "${s.fontFamily}"`,"\n"===i)return{width:1,height:s.lineHeight,baseline:0,lineHeight:s.lineHeight};const e=t.measureText(i);return{width:Math.ceil(e.width),height:Math.ceil(e.actualBoundingBoxAscent+e.actualBoundingBoxDescent),baseline:e.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function vs(t,i){const s=((t,i)=>{const s=[];let e=[],h=0,r=0,n=0,o=0;for(const a of i)"\n"!==a.text?0!==e.length&&h+a.metrics.width>t?(s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),e=[a],h=a.metrics.width,r=a.metrics.height,n=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),h+=a.metrics.width,r=Math.max(r,a.metrics.height),n=Math.max(n,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),e=[],h=0,r=0,n=0,o=0);return e.length>0&&s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),s})(i,t),e=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map(t=>t.width));let s=0;for(let i=0;t.length>i;i++){const e=t[i];s+=0===i?e.height:e.lineHeight}return{width:i,height:s}})(s);return{lines:s,size:e}}function ys(t,i,s,e,h){h.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px "${e.fontFamily}"`,e.enableShadow&&(h.shadowOffsetX=e.shadowOffsetX,h.shadowOffsetY=e.shadowOffsetY,h.shadowBlur=e.shadowBlur,h.shadowColor=e.shadowColor),e.enableStroke&&(h.strokeStyle=e.strokeColor,h.lineWidth=e.strokeThickness,h.strokeText(s,t,i)),h.fillStyle=e.color,h.fillText(s,t,i)}function ms(t,i,s,e){let h=t,r=0;for(const t of s)r=Math.max(t.width,r);for(let t=0;s.length>t;t++){const n=s[t],o=n.chunks[0]?.style.align??es,a=n.chunks.every(t=>t.style.align===o)?o:es;let c=0;"center"===a?c=(r-n.width)/2:"right"===a&&(c=r-n.width);let u=i+c;h+=0===t?n.height:n.lineHeight;for(const t of n.chunks)ys(u,h,t.text,t.style,e),u+=t.metrics.width}}class xs extends Bi{constructor(t,i,s={}){const e=Wi(2,2),h=e.getContext("2d");if(!h)throw Error("UIText.constructor: failed to create canvas context");const r=$i(e);r.needsUpdate=!0;const o=new st(s.color);switch(super(t,Ci,{texture:r,textureTransform:new n,color:o}),this.Be=[],this.Ve=!1,this.De=!1,this.ke=!1,this.We=[],this.$e=!1,this.Hs=o,this.Ne=new Oi(s.padding),this.commonStyle=new ls(s.commonStyle),this.ze=s.maxLineWidth??1024,this.Fe=s.resizeMode??ps,this.Ws=e,this.$s=h,this.Ns=r,this.content=i,this.Oe=this.width,this.je=this.height,void 0===s.padding&&this.Ne.setUnified(this.content.reduce((t,i)=>Math.max(t,i.style.calculatePadding()),this.commonStyle.calculatePadding())),this.Fe){case ds.SCALE:this.Ye();break;case ds.BREAK:this.Xe()}}get color(){return this.Hs}get content(){return this.Be}get maxLineWidth(){return this.ze}get padding(){return this.Ne}get resizeMode(){return this.Fe}set color(t){this.Hs.set(t)}set content(t){this.Be!==t&&(this.Be="string"==typeof t?[new fs({text:t,style:new ls})]:Array.isArray(t)?t.map(t=>new fs("string"==typeof t?{text:t,style:new ls}:{text:t.text,style:new ls(t.style)})):[new fs({text:t.text,style:new ls(t.style)})],this.Ve=!0,this.$e=!0)}set maxLineWidth(t){this.ze!==t&&(this.ze=t,this.De=!0)}set padding(t){this.Ne.set(t)}set resizeMode(t){this.Fe!==t&&(this.Fe=t,this.ke=!0)}destroy(){this.Ns.dispose(),super.destroy()}onWillRender(t,i){switch(this.Fe){case ds.SCALE:this.Ye();break;case ds.BREAK:this.Xe()}super.onWillRender(t,i)}Ye(){if(!(this.Hs.dirty||this.ke||this.De||this.Ne.dirty||this.solverWrapper.dirty&&this.Oe/this.je!==Math.round(this.width)/Math.round(this.height)||this.qe()))return;const t=this.Ze(),{lines:i,size:s}=vs(t,this.ze),e=s.height+(this.Ne.top+this.Ne.bottom),h=s.width+(this.Ne.left+this.Ne.right);this.width=h,this.height=e/h*Math.round(this.width),this.width=h/e*Math.round(this.height);const r=this.Oe!==e||this.je!==h;r&&(this.Ws.height=e,this.Ws.width=h),ms(this.Ne.top,this.Ne.left,i,this.$s),this.Je(r),this.ke=!1,this.De=!1,this.Ne.setDirtyFalse(),this.Ke(),this.Qe()}Xe(){if(!(this.Hs.dirty||this.ke||this.De||this.Ne.dirty||this.th()||this.qe()))return;const t=this.Ze(),{size:i}=vs(t,this.ze),s=this.Ne.top+this.Ne.bottom,e=this.Ne.left+this.Ne.right;this.height=i.height+s,this.width=i.width+e;const{lines:h,size:r}=vs(t,Math.round(this.width)-e);this.height=r.height+s,this.width=r.width+e;const n=Math.max(Math.round(this.width),2),o=Math.max(Math.round(this.height),2),a=this.Oe!==n||this.je!==o;a&&(this.Ws.width=n,this.Ws.height=o),ms(this.Ne.top,this.Ne.left,h,this.$s),this.Je(a),this.ke=!1,this.De=!1,this.Ne.setDirtyFalse(),this.Ke(),this.Qe()}Je(t){let i;this.Hs.dirty&&(i??(i={}),i.color=this.Hs,this.Hs.setDirtyFalse()),t&&(this.Ns.dispose(),this.Ns=$i(this.Ws),this.Ns.needsUpdate=!0,i??(i={}),i.texture=this.Ns),i&&this.sceneWrapper.setProperties(this.planeHandler,i)}Ze(){return this.$e&&(this.We=((t,i,s)=>{const e=[];for(const h of i){const i=ls.resolve(h.style,s);for(const s of ws(h.text)){const h=gs(t,s,i);e.push({text:s,style:i,metrics:h})}}return e})(this.$s,this.Be,this.commonStyle),this.$e=!1),this.We}th(){return this.solverWrapper.dirty&&(this.Oe!==Math.round(this.width)||this.je!==Math.round(this.height))}Ke(){this.Oe=Math.round(this.width),this.je=Math.round(this.height)}qe(){return this.Ve||this.content.some(t=>t.dirty)}Qe(){this.Ve=!1;for(const t of this.content)t.setDirtyFalse()}}class bs{constructor(){this.dirty=!1}}class _s extends bs{calculateScale(t,i){return 1}}const Is=new _s;class Ss extends Nt{constructor(t){const i=t?.resizePolicy??Is,s=i.calculateScale(window.innerWidth,window.innerHeight);super({width:window.innerWidth*s,height:window.innerHeight*s,...t}),this.ih=!1,this.sh=()=>{const t=this.resizePolicy.calculateScale(window.innerWidth,window.innerHeight);this.resizePolicy.dirty=!1,this.ih=!1,this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.eh=t=>{this.hh(t,"onPointerDown",Mi.PRESSED)},this.rh=t=>{this.hh(t,"onPointerMove",Mi.MOVED)},this.nh=t=>{this.hh(t,"onPointerUp",Mi.RELEASED)},this.oh=i,window.addEventListener("resize",this.sh),window.addEventListener("pointerdown",this.eh),window.addEventListener("pointermove",this.rh),window.addEventListener("pointerup",this.nh)}get resizePolicy(){return this.oh}set resizePolicy(t){this.oh!==t&&(this.oh=t,this.ih=!0)}destroy(){window.removeEventListener("resize",this.sh),window.removeEventListener("pointerdown",this.eh),window.removeEventListener("pointermove",this.rh),window.removeEventListener("pointerup",this.nh)}render(t,i){(this.resizePolicy.dirty||this.ih)&&this.sh(),super.renderInternal(t,i)}projectWorldPosition(i,s,e=new r){return e.copy(i).project(s),e.x=t.mapLinear(e.x,-1,1,this.x,this.width),e.y=t.mapLinear(e.y,-1,1,this.y,this.height),e}projectLayerPosition(i,s,e=-1,h=new r){return h.set(t.mapLinear(i.x,this.x,this.width,-1,1),t.mapLinear(i.y,this.y,this.height,-1,1),e).unproject(s)}buildRay(i,s,e=new M){const h=new r(t.mapLinear(i.x,this.x,this.width,-1,1),t.mapLinear(i.y,this.y,this.height,-1,1),-1).unproject(s),n=new r(t.mapLinear(i.x,this.x,this.width,-1,1),t.mapLinear(i.y,this.y,this.height,-1,1),1).unproject(s).sub(h).normalize();return e.set(h,n)}hh(t,i,s){const e=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,h=e?t.clientX-e.left:t.clientX,r=e?e.bottom-t.clientY:window.innerHeight-t.clientY,n=this.resizePolicy.calculateScale(window.innerWidth,window.innerHeight),o=h*n,a=r*n;U(this.mode)&&(this.emit(s,o,a,t.pointerId),this.inputWrapperInternal[i](o,a,t.pointerId))}}class Es extends Ai{constructor(t,i,s){super(),this.centerX=t,this.centerY=i,this.radius=s}contains(t,i){const s=t-this.centerX,e=i-this.centerY;return this.radius*this.radius>=s*s+e*e}}class Ms extends Ai{constructor(t){super(),this.vertices=t}contains(t,i){const s=this.vertices.length;if(3>s)return!1;let e=!1;for(let h=0,r=s-1;s>h;r=h++){const s=this.vertices[h],n=this.vertices[r],o=s.x,a=s.y,c=n.y;a>i!=c>i&&(n.x-o)*(i-a)/(c-a)+o>t&&(e=!e)}return e}}class Cs extends Ai{constructor(t,i,s,e,h){super(),this.x=t,this.y=i,this.width=s,this.height=e,this.radius=h,this.radius=Math.min(h,Math.min(s,e)/2)}contains(t,i){const s=this.x,e=this.x+this.width,h=this.y,r=this.y+this.height;if(s>t||t>e||h>i||i>r)return!1;const n=s+this.radius,o=e-this.radius,a=h+this.radius,c=r-this.radius;if(t>=n&&o>=t)return!0;if(i>=a&&c>=i)return!0;let u,l;u=n>t?n:o,l=a>i?a:c;const f=t-u,d=i-l;return this.radius*this.radius>=f*f+d*d}}class Ts extends Xi{constructor(t=0,i=!1){super("float calculateMask(){float aspect=p_textureResolution.x/p_textureResolution.y;vec2 p=(p_uv-0.5)*vec2(aspect,1.0);float angle=atan(p.y,p.x);angle=(angle+PI)/(2.0*PI);float adjusted=angle-p_startAngle;adjusted=p_direction>0.0 ? adjusted :-adjusted;adjusted=fract(adjusted);return step(adjusted,p_progress);}"),this.ah=t,this.uh=i}get startAngle(){return this.ah}get inverseDirection(){return this.uh}set startAngle(t){this.ah!==t&&(this.ah=t,this.dirtyInternal=!0)}set inverseDirection(t){this.uh!==t&&(this.uh=t,this.dirtyInternal=!0)}enumerateProperties(){return{direction:this.uh?-1:1,startAngle:this.ah}}}class As extends bs{constructor(t,i){super(),this.fh=t,this.dh=i}get rectWidth(){return this.fh}get rectHeight(){return this.dh}set rectWidth(t){t!==this.fh&&(this.fh=t,this.dirty=!0)}set rectHeight(t){t!==this.dh&&(this.dh=t,this.dirty=!0)}calculateScale(t,i){return Math.min(this.fh/t,this.dh/i)}}class Ps extends bs{constructor(t,i){super(),this.ph=t,this.wh=i}get fixedWidthLandscape(){return this.ph}get fixedHeightPortrait(){return this.wh}set fixedWidthLandscape(t){t!==this.ph&&(this.ph=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.wh&&(this.wh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.ph/t:this.wh/i}}class Us extends bs{constructor(t,i){super(),this.gh=t,this.yh=i}get fixedHeightLandscape(){return this.gh}get fixedWidthPortrait(){return this.yh}set fixedHeightLandscape(t){t!==this.gh&&(this.gh=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.yh&&(this.yh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.gh/i:this.yh/t}}class Hs extends bs{constructor(t,i){super(),this.fh=t,this.dh=i}get rectWidth(){return this.fh}get rectHeight(){return this.dh}set rectWidth(t){t!==this.fh&&(this.fh=t,this.dirty=!0)}set rectHeight(t){t!==this.dh&&(this.dh=t,this.dirty=!0)}calculateScale(t,i){return Math.max(this.fh/t,this.dh/i)}}class Rs extends bs{constructor(t,i){super(),this.gh=t,this.wh=i}get fixedHeightLandscape(){return this.gh}get fixedHeightPortrait(){return this.wh}set fixedHeightLandscape(t){t!==this.gh&&(this.gh=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.wh&&(this.wh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.gh/i:this.wh/i}}class Bs extends bs{constructor(t,i){super(),this.ph=t,this.yh=i}get fixedWidthLandscape(){return this.ph}get fixedWidthPortrait(){return this.yh}set fixedWidthLandscape(t){t!==this.ph&&(this.ph=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.yh&&(this.yh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.ph/t:this.yh/t}}export{di as UIAnchor,ki as UIAnimatedImage,Li as UIAnimatedImageLoopMode,Es as UIAreaCircle,Ms as UIAreaPolygon,Pi as UIAreaRectangle,Cs as UIAreaRoundedRectangle,oi as UIAspectConstraint,st as UIColor,ni as UIConstraint2DBuilder,ci as UICoverConstraintBuilder,fi as UICustomConstraint,Lt as UIExpression,li as UIFitConstraintBuilder,Ss as UIFullscreenLayer,zi as UIGraphics,Jt as UIHeightConstraint,Kt as UIHorizontalDistanceConstraint,Qt as UIHorizontalInterpolationConstraint,ti as UIHorizontalProportionConstraint,Fi as UIImage,Hi as UIInputDummy,Mi as UIInputEvent,Ti as UIMicro,pi as UIMicroAnchorMode,A as UIMode,Yi as UINineSlice,Gi as UINineSliceRegionMode,P as UIOrientation,Z as UIPriority,Ki as UIProgress,Ts as UIProgressMaskFunctionCircular,qi as UIProgressMaskFunctionDirectional,Dt as UIRelation,As as UIResizePolicyCover,Ps as UIResizePolicyCross,Us as UIResizePolicyCrossInverted,Hs as UIResizePolicyFit,Rs as UIResizePolicyFixedHeight,Bs as UIResizePolicyFixedWidth,_s as UIResizePolicyNone,is as UIScene,Zi as UISceneUpdateMode,Zt as UISingleParameterConstraint,xs as UIText,ds as UITextResizeMode,mt as UITransparencyMode,ii as UIVerticalDistanceConstraint,si as UIVerticalInterpolationConstraint,ei as UIVerticalProportionConstraint,hi as UIWidthConstraint};
|
|
1
|
+
import{MathUtils as t,Color as i,Vector4 as s,Texture as e,Vector2 as h,Vector3 as r,Matrix3 as n,Matrix4 as o,PlaneGeometry as a,InstancedBufferGeometry as c,ShaderMaterial as l,InstancedBufferAttribute as u,Mesh as f,Scene as d,OrthographicCamera as p,Quaternion as v,CanvasTexture as g,UVMapping as w,ClampToEdgeWrapping as y,LinearFilter as m,RGBAFormat as x,UnsignedByteType as b,SRGBColorSpace as _,NoColorSpace as I,WebGLRenderTarget as S,PerspectiveCamera as E,Ray as M}from"three";class C{constructor(){this.i=0,this.t=!1}on(t){this.i>0?(this.h??(this.h=[])).push(t):this.o(t)}once(t){if(this.i>0)return(this.h??(this.h=[])).push(t),void(this.v??(this.v=new Set)).add(t);(this.l??(this.l=new Set)).add(t),this.o(t)}off(t){if(void 0!==this.h){const i=this.h.indexOf(t);if(-1!==i)return this.h.splice(i,1),void this.v?.delete(t)}this.l?.delete(t),this.i>0?this._(t):this.u(t)}m(){if(void 0!==this.l&&this.l.size>0&&(this.l.forEach(t=>{this._(t)}),this.l=void 0),this.t&&(this.t=!1,this.p()),void 0!==this.h&&this.h.length>0){for(let t=0;this.h.length>t;t++){const i=this.h[t];!0===this.v?.has(i)&&(this.l??(this.l=new Set)).add(i),this.o(i)}this.h=void 0,this.v=void 0}}o(t){void 0!==this.S?void 0!==this.I?void 0!==this.R?void 0!==this.k?void 0!==this.C?void 0!==this.F?void 0!==this.N?void 0!==this.j?void 0!==this.q?void 0!==this.A?(this.B??(this.B=[])).push(t):this.A=t:this.q=t:this.j=t:this.N=t:this.F=t:this.C=t:this.k=t:this.R=t:this.I=t:this.S=t}_(t){if(this.t=!0,this.S!==t)if(this.I!==t)if(this.R!==t)if(this.k!==t)if(this.C!==t)if(this.F!==t)if(this.N!==t)if(this.j!==t)if(this.q!==t)if(this.A!==t){if(void 0!==this.B){const i=this.B.indexOf(t);-1!==i&&(this.B[i]=void 0)}}else this.A=void 0;else this.q=void 0;else this.j=void 0;else this.N=void 0;else this.F=void 0;else this.C=void 0;else this.k=void 0;else this.R=void 0;else this.I=void 0;else this.S=void 0}u(t){if(this.S===t)return this.S=void 0,void this.p();if(this.I===t)return this.I=void 0,void this.p();if(this.R===t)return this.R=void 0,void this.p();if(this.k===t)return this.k=void 0,void this.p();if(this.C===t)return this.C=void 0,void this.p();if(this.F===t)return this.F=void 0,void this.p();if(this.N===t)return this.N=void 0,void this.p();if(this.j===t)return this.j=void 0,void this.p();if(this.q===t)return this.q=void 0,void this.p();if(this.A===t)return this.A=void 0,void this.p();if(void 0!==this.B){const i=this.B.indexOf(t);-1!==i&&(this.B.splice(i,1),0===this.B.length&&(this.B=void 0))}}p(){const t=[];if(void 0!==this.S&&t.push(this.S),void 0!==this.I&&t.push(this.I),void 0!==this.R&&t.push(this.R),void 0!==this.k&&t.push(this.k),void 0!==this.C&&t.push(this.C),void 0!==this.F&&t.push(this.F),void 0!==this.N&&t.push(this.N),void 0!==this.j&&t.push(this.j),void 0!==this.q&&t.push(this.q),void 0!==this.A&&t.push(this.A),void 0!==this.B){for(let i=0;this.B.length>i;i++){const s=this.B[i];void 0!==s&&t.push(s)}this.B=void 0}const i=t.length;this.S=i>0?t[0]:void 0,this.I=i>1?t[1]:void 0,this.R=i>2?t[2]:void 0,this.k=i>3?t[3]:void 0,this.C=i>4?t[4]:void 0,this.F=i>5?t[5]:void 0,this.N=i>6?t[6]:void 0,this.j=i>7?t[7]:void 0,this.q=i>8?t[8]:void 0,this.A=i>9?t[9]:void 0,i>10&&(this.B=t.slice(10))}D(t){return this.S===t||this.I===t||this.R===t||this.k===t||this.C===t||this.F===t||this.N===t||this.j===t||this.q===t||this.A===t}G(t){return!!this.D(t)||!0===this.B?.includes(t)||!0===this.h?.includes(t)}H(t){}J(t){}}class T extends C{emit(){if(this.i++,this.S?.(),this.I?.(),this.R?.(),this.k?.(),this.C?.(),this.F?.(),this.N?.(),this.j?.(),this.q?.(),this.A?.(),void 0!==this.B)for(let t=0;this.B.length>t;t++)this.B[t]?.();this.i--,0===this.i&&this.m()}}class P extends C{emit(t){if(this.i++,this.S?.(t),this.I?.(t),this.R?.(t),this.k?.(t),this.C?.(t),this.F?.(t),this.N?.(t),this.j?.(t),this.q?.(t),this.A?.(t),void 0!==this.B)for(let i=0;this.B.length>i;i++)this.B[i]?.(t);this.i--,0===this.i&&this.m()}}class A extends C{emit(t,i){if(this.i++,this.S?.(t,i),this.I?.(t,i),this.R?.(t,i),this.k?.(t,i),this.C?.(t,i),this.F?.(t,i),this.N?.(t,i),this.j?.(t,i),this.q?.(t,i),this.A?.(t,i),void 0!==this.B)for(let s=0;this.B.length>s;s++){const e=this.B[s];e?.(t,i)}this.i--,0===this.i&&this.m()}}class U extends C{emit(t,i,s){if(this.i++,this.S?.(t,i,s),this.I?.(t,i,s),this.R?.(t,i,s),this.k?.(t,i,s),this.C?.(t,i,s),this.F?.(t,i,s),this.N?.(t,i,s),this.j?.(t,i,s),this.q?.(t,i,s),this.A?.(t,i,s),void 0!==this.B)for(let e=0;this.B.length>e;e++){const h=this.B[e];h?.(t,i,s)}this.i--,0===this.i&&this.m()}}var H,R;function B(t){return t===H.INTERACTIVE||t===H.INTERACTIVE_TRANSPARENT}function V(t){return t!==H.HIDDEN}function L(){return new D}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE",t[t.INTERACTIVE_TRANSPARENT=3]="INTERACTIVE_TRANSPARENT"})(H||(H={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(R||(R={}));class D{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new k(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new k(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new D;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class k{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new k(this.first,this.second)}}class W{constructor(t=""){this.M=t}id(){return this.T}name(){return this.M}setName(t){this.M=t}context(){return this.P}setContext(t){this.P=t}value(){return this.U}setValue(t){this.U=t}plus(t){return new z(this,t)}minus(t){return new z(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new z([t,this])}divide(t){return new z([1/t,this])}toJSON(){return{name:this.M,value:this.U}}toString(){return this.P+"["+this.M+":"+this.U+"]"}M;U=0;P=null;T=$++}let $=0;class z{constructor(){let t=(t=>{let i=0,s=()=>0,e=L();for(let h=0,r=t.length;r>h;++h){let r=t[h];if("number"==typeof r)i+=r;else if(r instanceof W)e.setDefault(r,s).second+=1;else if(r instanceof z){i+=r.constant();let t=r.terms();for(let i=0,h=t.size();h>i;i++){let h=t.itemAt(i);e.setDefault(h.first,s).second+=h.second}}else{if(!(r instanceof Array))throw Error("invalid Expression argument: "+r);{if(2!==r.length)throw Error("array must have length 2");let t=r[0],h=r[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(h instanceof W)e.setDefault(h,s).second+=t;else{if(!(h instanceof z))throw Error("array item 1 must be a variable or expression");{i+=h.constant()*t;let r=h.terms();for(let i=0,h=r.size();h>i;i++){let h=r.itemAt(i);e.setDefault(h.first,s).second+=h.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.V=t.terms,this.L=t.constant}terms(){return this.V}constant(){return this.L}value(){let t=this.L;for(let i=0,s=this.V.size();s>i;i++){let s=this.V.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new z(this,t)}minus(t){return new z(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new z([t,this])}divide(t){return new z([1/t,this])}isConstant(){return 0==this.V.size()}toString(){let t=this.V.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.L||(t+=" + "),t+=this.L,t}V;L}class F{static create(t,i,s,e=1){let h=0;return h+=1e6*Math.max(0,Math.min(1e3,t*e)),h+=1e3*Math.max(0,Math.min(1e3,i*e)),h+=Math.max(0,Math.min(1e3,s*e)),h}static required=F.create(1e3,1e3,1e3);static strong=F.create(1,0,0);static medium=F.create(0,1,0);static weak=F.create(0,0,1);static clip(t){return Math.max(0,Math.min(F.required,t))}}var N;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(N||(N={}));class O{constructor(t,i,s,e=F.required){this.W=i,this.$=F.clip(e),this.O=void 0===s&&t instanceof z?t:t.minus(s)}id(){return this.T}expression(){return this.O}op(){return this.W}strength(){return this.$}toString(){return this.O+" "+["<=",">=","="][this.W]+" 0 ("+this.$+")"}O;W;$;T=G++}let G=0;class j{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=F.required){let h=new O(t,i,s,e);return this.addConstraint(h),h}addConstraint(t){if(void 0!==this.Y.find(t))throw Error("duplicate constraint");let i=this.X(t),s=i.row,e=i.tag,h=this.Z(s,e);if(h.type()===X.Invalid&&s.allDummies()){if(!Y(s.constant()))throw Error("unsatisfiable constraint");h=e.marker}if(h.type()===X.Invalid){if(!this.K(s))throw Error("unsatisfiable constraint")}else s.solveFor(h),this.tt(h,s),this.it.insert(h,s);this.Y.insert(t,e),this.st(this.et)}removeConstraint(t){let i=this.Y.erase(t);if(void 0===i)throw Error("unknown constraint");this.ht(t,i.second);let s=i.second.marker,e=this.it.erase(s);if(void 0===e){let t=this.rt(s);if(t.type()===X.Invalid)throw Error("failed to find leaving row");e=this.it.erase(t),e.second.solveForEx(t,s),this.tt(s,e.second)}this.st(this.et)}hasConstraint(t){return this.Y.contains(t)}getConstraints(){return this.Y.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.nt.find(t))throw Error("duplicate edit variable");if((i=F.clip(i))===F.required)throw Error("bad required strength");let s=new z(t),e=new O(s,N.Eq,void 0,i);this.addConstraint(e);let h=this.Y.find(e).second;this.nt.insert(t,{tag:h,constraint:e,constant:0})}removeEditVariable(t){let i=this.nt.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.nt.contains(t)}suggestValue(t,i){let s=this.nt.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.it,h=s.second,r=i-h.constant;h.constant=i;let n=h.tag.marker,o=e.find(n);if(void 0!==o)return 0>o.second.add(-r)&&this.ot.push(n),void this.ct();let a=h.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(r)&&this.ot.push(a),void this.ct();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,h=s.coefficientFor(n);0!==h&&0>s.add(r*h)&&i.first.type()!==X.External&&this.ot.push(i.first)}this.ct()}updateVariables(){let t=this.lt,i=this.it;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),h=i.find(e.second);e.first.setValue(void 0!==h?h.second.constant():0)}}ut(t){return this.lt.setDefault(t,()=>this.ft(X.External)).second}X(t){let i=t.expression(),s=new J(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!Y(i.second)){let t=this.ut(i.first),e=this.it.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let h=this.et,r=t.strength(),n={marker:Z,other:Z};switch(t.op()){case N.Le:case N.Ge:{let i=t.op()===N.Le?1:-1,e=this.ft(X.Slack);if(n.marker=e,s.insertSymbol(e,i),F.required>r){let t=this.ft(X.Error);n.other=t,s.insertSymbol(t,-i),h.insertSymbol(t,r)}break}case N.Eq:if(F.required>r){let t=this.ft(X.Error),i=this.ft(X.Error);n.marker=t,n.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),h.insertSymbol(t,r),h.insertSymbol(i,r)}else{let t=this.ft(X.Dummy);n.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:n}}Z(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===X.External)return i.first}let e=i.marker.type();return e!==X.Slack&&e!==X.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==X.Slack&&e!==X.Error||t.coefficientFor(i.other)>=0?Z:i.other):i.marker}K(t){let i=this.ft(X.Slack);this.it.insert(i,t.copy()),this.dt=t.copy(),this.st(this.dt);let s=Y(this.dt.constant());this.dt=null;let e=this.it.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let h=this.vt(t);if(h.type()===X.Invalid)return!1;t.solveForEx(i,h),this.tt(h,t),this.it.insert(h,t)}let h=this.it;for(let t=0,s=h.size();s>t;++t)h.itemAt(t).second.removeSymbol(i);return this.et.removeSymbol(i),s}tt(t,i){let s=this.it;for(let e=0,h=s.size();h>e;++e){let h=s.itemAt(e);h.second.substitute(t,i),0>h.second.constant()&&h.first.type()!==X.External&&this.ot.push(h.first)}this.et.substitute(t,i),this.dt&&this.dt.substitute(t,i)}st(t){let i=0;for(;this.maxIterations>i;){let s=this.gt(t);if(s.type()===X.Invalid)return;let e=this.wt(s);if(e.type()===X.Invalid)throw Error("the objective is unbounded");let h=this.it.erase(e).second;h.solveForEx(e,s),this.tt(s,h),this.it.insert(s,h),i++}throw Error("solver iterations exceeded")}ct(){let t=this.it,i=this.ot;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.yt(e.second);if(i.type()===X.Invalid)throw Error("dual optimize failed");let h=e.second;t.erase(s),h.solveForEx(s,i),this.tt(i,h),t.insert(i,h)}}}gt(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first;if(0>s.second&&e.type()!==X.Dummy)return e}return Z}yt(t){let i=Number.MAX_VALUE,s=Z,e=t.cells();for(let t=0,h=e.size();h>t;++t){let h=e.itemAt(t),r=h.first,n=h.second;if(n>0&&r.type()!==X.Dummy){let t=this.et.coefficientFor(r)/n;i>t&&(i=t,s=r)}}return s}wt(t){let i=Number.MAX_VALUE,s=Z,e=this.it;for(let h=0,r=e.size();r>h;++h){let r=e.itemAt(h),n=r.first;if(n.type()!==X.External){let e=r.second,h=e.coefficientFor(t);if(0>h){let t=-e.constant()/h;i>t&&(i=t,s=n)}}}return s}rt(t){let i=Number.MAX_VALUE,s=i,e=i,h=Z,r=h,n=h,o=h,a=this.it;for(let i=0,h=a.size();h>i;++i){let h=a.itemAt(i),c=h.second,l=c.coefficientFor(t);if(0===l)continue;let u=h.first;if(u.type()===X.External)o=u;else if(0>l){let t=-c.constant()/l;s>t&&(s=t,r=u)}else{let t=c.constant()/l;e>t&&(e=t,n=u)}}return r!==h?r:n!==h?n:o}ht(t,i){i.marker.type()===X.Error&&this.xt(i.marker,t.strength()),i.other.type()===X.Error&&this.xt(i.other,t.strength())}xt(t,i){let s=this.it.find(t);void 0!==s?this.et.insertRow(s.second,-i):this.et.insertSymbol(t,-i)}vt(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first.type();if(e===X.Slack||e===X.Error)return s.first}return Z}ft(t){return new q(t,this.bt++)}Y=(()=>L())();it=(()=>L())();lt=(()=>L())();nt=(()=>L())();ot=[];et=new J;dt=null;bt=0}function Y(t){return 0>t?1e-8>-t:1e-8>t}var X;(t=>{t[t.Invalid=0]="Invalid",t[t.External=1]="External",t[t.Slack=2]="Slack",t[t.Error=3]="Error",t[t.Dummy=4]="Dummy"})(X||(X={}));class q{constructor(t,i){this.T=i,this._t=t}id(){return this.T}type(){return this._t}T;_t}let Z=new q(X.Invalid,-1);class J{constructor(t=0){this.L=t}cells(){return this.It}constant(){return this.L}isConstant(){return this.It.empty()}allDummies(){let t=this.It;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==X.Dummy)return!1;return!0}copy(){let t=new J(this.L);return t.It=this.It.copy(),t}add(t){return this.L+=t}insertSymbol(t,i=1){Y(this.It.setDefault(t,()=>0).second+=i)&&this.It.erase(t)}insertRow(t,i=1){this.L+=t.L*i;let s=t.It;for(let t=0,e=s.size();e>t;++t){let e=s.itemAt(t);this.insertSymbol(e.first,e.second*i)}}removeSymbol(t){this.It.erase(t)}reverseSign(){this.L=-this.L;let t=this.It;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.It,s=-1/i.erase(t).second;this.L*=s;for(let t=0,e=i.size();e>t;++t)i.itemAt(t).second*=s}solveForEx(t,i){this.insertSymbol(t,-1),this.solveFor(i)}coefficientFor(t){let i=this.It.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.It.erase(t);void 0!==s&&this.insertRow(i,s.second)}It=L();L}const K=1e3;var Q;function tt(t){switch(t){case Q.P0:return F.create(K,K,K);case Q.P1:return F.create(100,0,0);case Q.P2:return F.create(10,0,0);case Q.P3:return F.create(0,100,0);case Q.P4:return F.create(0,10,0);case Q.P5:return F.create(0,0,100);case Q.P6:return F.create(0,0,10);case Q.P7:return F.create(0,0,1);default:throw Error("convertPriority.priority: invalid priority")}}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(Q||(Q={}));class it{constructor(){this.dirty=!1,this.St=!1,this.Et=[],this.Mt=0}createInputCatcher(t,i,s,e){const h=this.Mt++;return this.Et.push({handler:h,catchPointerDown:t,catchPointerMove:i,catchPointerUp:s,zIndex:e,active:!0}),this.St=!0,this.dirty=!0,h}destroyInputCatcher(t){const i=this.Et.findIndex(i=>i.handler===t);if(-1===i)throw Error("UIInputWrapper.destroyInputCatcher.handler: handler not found");this.Et.splice(i,1)}getZIndex(t){this.Ct();const i=this.Et.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getZIndex.handler: handler not found");return i.zIndex}setZIndex(t,i){const s=this.Et.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setZIndex.handler: handler not found");s.zIndex!==i&&(s.zIndex=i,this.St=!0,this.dirty=!0)}getActive(t){const i=this.Et.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getActive.handler: handler not found");return i.active}setActive(t,i){const s=this.Et.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setActive.handler: handler not found");s.active!==i&&(s.active=i)}onPointerDown(t,i,s){this.Ct();for(let e=this.Et.length-1;e>=0;e--){const h=this.Et[e];if(h.active&&h.catchPointerDown(t,i,s))break}}onPointerMove(t,i,s){this.Ct();for(let e=this.Et.length-1;e>=0;e--){const h=this.Et[e];if(h.active&&h.catchPointerMove(t,i,s))break}}onPointerUp(t,i,s){this.Ct();for(let e=this.Et.length-1;e>=0;e--){const h=this.Et[e];if(h.active&&h.catchPointerUp(t,i,s))break}}Ct(){if(this.St){this.Et.sort((t,i)=>t.zIndex-i.zIndex);const t=this.Et.length,i=1024>t?1:1024/t;for(let s=0;t>s;s++)this.Et[s].zIndex=s*i;this.St=!1}}}function st(t){return.04045>t?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function et(t){return.0031308>t?12.92*t:1.055*Math.pow(t,.41666)-.055}const ht={black:0,white:16777215,red:16711680,green:32768,blue:255,yellow:16776960,cyan:65535,magenta:16711935,gray:8421504,grey:8421504,silver:12632256,maroon:8388608,olive:8421376,lime:65280,aqua:65535,teal:32896,navy:128,fuchsia:16711935,purple:8388736,orange:16753920,pink:16761035,brown:10824234,gold:16766720,violet:15631086,indigo:4915330,coral:16744272,salmon:16416882,khaki:15787660,plum:14524637,orchid:14315734,tan:13808780,beige:16119260,mint:10025880,lavender:15132410,crimson:14423100,azure:15794175,ivory:16777200,snow:16775930};class rt{constructor(...t){this.Tt=1,this.Pt=1,this.At=1,this.Ut=1,this.Ht=0,this.Rt=0,this.Bt=1,this.Vt=!1,this.Lt=!1,this.Dt=!1,t.length>0&&this.set(...t)}static get black(){return new rt("black")}static get white(){return new rt("white")}static get red(){return new rt("red")}static get green(){return new rt("green")}static get blue(){return new rt("blue")}static get yellow(){return new rt("yellow")}static get cyan(){return new rt("cyan")}static get magenta(){return new rt("magenta")}static get gray(){return new rt("gray")}static get grey(){return new rt("grey")}static get silver(){return new rt("silver")}static get maroon(){return new rt("maroon")}static get olive(){return new rt("olive")}static get lime(){return new rt("lime")}static get aqua(){return new rt("aqua")}static get teal(){return new rt("teal")}static get navy(){return new rt("navy")}static get fuchsia(){return new rt("fuchsia")}static get purple(){return new rt("purple")}static get orange(){return new rt("orange")}static get pink(){return new rt("pink")}static get brown(){return new rt("brown")}static get gold(){return new rt("gold")}static get violet(){return new rt("violet")}static get indigo(){return new rt("indigo")}static get coral(){return new rt("coral")}static get salmon(){return new rt("salmon")}static get khaki(){return new rt("khaki")}static get plum(){return new rt("plum")}static get orchid(){return new rt("orchid")}static get tan(){return new rt("tan")}static get beige(){return new rt("beige")}static get mint(){return new rt("mint")}static get lavender(){return new rt("lavender")}static get crimson(){return new rt("crimson")}static get azure(){return new rt("azure")}static get ivory(){return new rt("ivory")}static get snow(){return new rt("snow")}get r(){return this.kt(),this.Tt}get g(){return this.kt(),this.Pt}get b(){return this.kt(),this.At}get a(){return this.Ut}get hue(){return this.Wt(),this.Ht}get saturation(){return this.Wt(),this.Rt}get lightness(){return this.Wt(),this.Bt}get dirty(){return this.Vt}set r(i){i=t.clamp(i,0,1),this.kt(),i!==this.Tt&&(this.Tt=i,this.Dt=!0,this.Vt=!0)}set g(i){i=t.clamp(i,0,1),this.kt(),i!==this.Pt&&(this.Pt=i,this.Dt=!0,this.Vt=!0)}set b(i){i=t.clamp(i,0,1),this.kt(),i!==this.At&&(this.At=i,this.Dt=!0,this.Vt=!0)}set a(i){(i=t.clamp(i,0,1))!==this.Ut&&(this.Ut=i,this.Vt=!0)}set hue(i){i=t.clamp(i,0,360),this.Wt(),i!==this.Ht&&(this.Ht=i,this.Lt=!0,this.Vt=!0)}set saturation(i){i=t.clamp(i,0,1),this.Wt(),i!==this.Rt&&(this.Rt=i,this.Lt=!0,this.Vt=!0)}set lightness(i){i=t.clamp(i,0,1),this.Wt(),i!==this.Bt&&(this.Bt=i,this.Lt=!0,this.Vt=!0)}setDirtyFalse(){this.Vt=!1}set(...t){if(0===t.length||void 0===t[0])return this.setRGBA(1,1,1,1);if(t.length>=3&&"number"==typeof t[0]){const[i,s,e,h=1]=t;return this.setRGBA(i,s,e,h)}const[s,e=1]=t;if("string"==typeof s)return s.startsWith("#")?this.setHexString(s):this.setColorName(s,e);if(s instanceof rt)return this.copy(s);if(s instanceof i)return this.setThreeColor(s,e);if("number"==typeof s)return this.setHexRGB(s,e);throw Error("UIColor.set: cannot create color from provided arguments")}setRGBA(i,s,e,h=this.Ut){return i=t.clamp(i,0,1),s=t.clamp(s,0,1),e=t.clamp(e,0,1),h=t.clamp(h,0,1),this.kt(),i===this.Tt&&s===this.Pt&&e===this.At&&h===this.Ut||(this.Tt=i,this.Pt=s,this.At=e,this.Ut=h,this.Dt=!0,this.Vt=!0),this}getHexRGBA(){return this.kt(),Math.round(255*this.Tt)<<24|Math.round(255*this.Pt)<<16|Math.round(255*this.At)<<8|Math.round(255*this.Ut)}getHexRGB(){return this.kt(),Math.round(255*this.Tt)<<16|Math.round(255*this.Pt)<<8|Math.round(255*this.At)}getHexStringRGB(){return"#"+this.getHexRGB().toString(16).padStart(6,"0")}getHexStringRGBA(){return"#"+this.getHexRGBA().toString(16).padStart(8,"0")}setHexRGBA(t){this.kt();const i=(t>>16&255)/255,s=(t>>8&255)/255,e=(255&t)/255,h=(t>>24&255)/255;return i===this.Tt&&s===this.Pt&&e===this.At&&h===this.Ut||(this.Tt=i,this.Pt=s,this.At=e,this.Ut=h,this.Dt=!0,this.Vt=!0),this}setHexRGB(i,s=this.Ut){s=t.clamp(s,0,1),this.kt();const e=(i>>16&255)/255,h=(i>>8&255)/255,r=(255&i)/255;return e===this.Tt&&h===this.Pt&&r===this.At&&s===this.Ut||(this.Tt=e,this.Pt=h,this.At=r,this.Ut=s,this.Dt=!0,this.Vt=!0),this}setHexString(t){if(!t.startsWith("#"))throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"');const i=t.slice(1);if(6===i.length){const t=parseInt(i,16);if(isNaN(t))throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"');return this.setHexRGB(t)}if(8===i.length){const t=parseInt(i,16);if(isNaN(t))throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"');return this.setHexRGBA(t)}throw Error('UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"')}setHSL(i,s,e,h=this.Ut){return i=t.clamp(i,0,360),s=t.clamp(s,0,1),e=t.clamp(e,0,1),h=t.clamp(h,0,1),this.Wt(),i===this.Ht&&s===this.Rt&&e===this.Bt&&h===this.Ut||(this.Ht=i,this.Rt=s,this.Bt=e,this.Ut=h,this.Lt=!0,this.Vt=!0),this}setColorName(i,s=this.Ut){s=t.clamp(s,0,1);const e=i.toLowerCase().trim(),h=ht[e];if(void 0===h)throw Error("UIColor.setColorName.colorName: unknown color name");return this.setHexRGB(h,s)}setGLSLColor(i,s,e,h=this.Ut){h=t.clamp(h,0,1),this.kt();const r=et(i),n=et(s),o=et(e);return r===this.Tt&&n===this.Pt&&o===this.At&&h===this.Ut||(this.Tt=r,this.Pt=n,this.At=o,this.Ut=h,this.Dt=!0,this.Vt=!0),this}setThreeColor(i,s=this.Ut){return s=t.clamp(s,0,1),this.kt(),i.r===this.Tt&&i.g===this.Pt&&i.b===this.At&&s===this.Ut||(this.Tt=i.r,this.Pt=i.g,this.At=i.b,this.Ut=s,this.Dt=!0,this.Vt=!0),this}toCSSColor(){return this.kt(),`rgba(${Math.round(255*this.Tt)}, ${Math.round(255*this.Pt)}, ${Math.round(255*this.At)}, ${this.Ut})`}toGLSLColor(t=new s){return this.kt(),t.x=st(this.Tt),t.y=st(this.Pt),t.z=st(this.At),t.w=this.Ut,t}toThreeColor(t=new i){return this.kt(),t.r=this.Tt,t.g=this.Pt,t.b=this.At,t}copy(t){return t instanceof rt?(this.kt(),t.kt(),this.Tt===t.Tt&&this.Pt===t.Pt&&this.At===t.At&&this.Ut===t.Ut||(this.Tt=t.Tt,this.Pt=t.Pt,this.At=t.At,this.Ut=t.Ut,this.Dt=!0,this.Vt=!0)):(this.kt(),this.Tt===t.r&&this.Pt===t.g&&this.At===t.b&&1===this.Ut||(this.Tt=t.r,this.Pt=t.g,this.At=t.b,this.Ut=1,this.Dt=!0,this.Vt=!0)),this}clone(){return this.kt(),new rt(this.Tt,this.Pt,this.At,this.Ut)}kt(){if(this.Lt){const{Ht:t,Rt:i,Bt:s}=this,e=(1-Math.abs(2*s-1))*i,h=t/60,r=e*(1-Math.abs(h%2-1));let[n,o,a]=1>h?[e,r,0]:2>h?[r,e,0]:3>h?[0,e,r]:4>h?[0,r,e]:5>h?[r,0,e]:[e,0,r];const c=s-e/2;this.Tt=n+c,this.Pt=o+c,this.At=a+c,this.Lt=!1}}Wt(){if(this.Dt){const{Tt:t,Pt:i,At:s}=this,e=Math.max(t,i,s),h=Math.min(t,i,s),r=e-h,n=(e+h)/2;let o=0;0!==r&&(o=e===t?(i-s)/r+(s>i?6:0):e===i?(s-t)/r+2:(t-i)/r+4,o*=60);const a=0===r?0:r/(1-Math.abs(2*n-1));this.Ht=o,this.Rt=a,this.Bt=n,this.Dt=!1}}}let nt,ot;const at=()=>(ot??(ot=(()=>{const t=document.createElement("canvas"),i=t.getContext("webgl2")??t.getContext("webgl");if(!i)return!1;if(i instanceof WebGL2RenderingContext)try{const t=i.createTexture();i.bindTexture(i.TEXTURE_2D,t),i.texStorage2D(i.TEXTURE_2D,1,i.SRGB8_ALPHA8,2,2);const s=i.getError();return i.deleteTexture(t),s===i.NO_ERROR}catch{return!1}const s=i.getExtension("EXT_sRGB");if(!s)return!1;try{const t=i.createTexture();i.bindTexture(i.TEXTURE_2D,t),i.texImage2D(i.TEXTURE_2D,0,s.SRGB_ALPHA_EXT,2,2,0,s.SRGB_ALPHA_EXT,i.UNSIGNED_BYTE,null);const e=i.getError();return i.deleteTexture(t),e===i.NO_ERROR}catch{return!1}})()),ot),ct=Object.freeze({glslTypeName:"float",bufferSize:1,instantiable:!0}),lt=Object.freeze({glslTypeName:"sampler2D",bufferSize:-1,instantiable:!1}),ut=Object.freeze({glslTypeName:"vec2",bufferSize:2,instantiable:!0}),ft=Object.freeze({glslTypeName:"vec3",bufferSize:3,instantiable:!0}),dt=Object.freeze({glslTypeName:"vec4",bufferSize:4,instantiable:!0}),pt=Object.freeze({glslTypeName:"mat3",bufferSize:9,instantiable:!0}),vt=Object.freeze({glslTypeName:"mat4",bufferSize:16,instantiable:!0});function gt(t){if("string"==typeof t)switch(t){case"number":return ct;case"Texture":return lt;case"UIColor":case"Vector4":return dt;case"Vector2":return ut;case"Vector3":return ft;case"Matrix3":return pt;case"Matrix4":return vt;default:throw Error("resolveGLSLTypeInfo.value: unsupported property type name")}if("function"==typeof t){if(t===Number)return ct;if(t===e)return lt;if(t===rt)return dt;if(t===h)return ut;if(t===r)return ft;if(t===s)return dt;if(t===n)return pt;if(t===o)return vt;throw Error("resolveGLSLTypeInfo.value: unsupported property type constructor")}if("number"==typeof t)return ct;if(t instanceof e)return lt;if(t instanceof rt)return dt;if(t instanceof h)return ut;if(t instanceof r)return ft;if(t instanceof s)return dt;if(t instanceof n)return pt;if(t instanceof o)return vt;throw Error("resolveGLSLTypeInfo.value: unsupported property type")}function wt(t,i){const s=i.uniforms["p_"+t];if(void 0===s)throw Error("resolvePropertyUniform.name: unknown uniform");return s}function yt(t){const i={};for(const s in t){const e=t[s];i[s]={value:e,glslTypeInfo:gt(e)}}return i}function mt(t){return"number"==typeof t||t instanceof e?t:t.clone()}function xt(t){const i={};for(const s in t){const e=t[s];i[s]={value:mt(e.value),glslTypeInfo:e.glslTypeInfo}}return i}function bt(t){return t.elements[14]}var _t;(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(_t||(_t={}));const It=(()=>{const t=new a(1,1);t.translate(.5,.5,0);const i=new c;return i.index=t.index,i.setAttribute("position",t.attributes.position),i.setAttribute("uv",t.attributes.uv),t.dispose(),i})(),St=new s;function Et(t,i,e){if(t instanceof rt)t.toGLSLColor(St),i[e]=St.x,i[e+1]=St.y,i[e+2]=St.z,i[e+3]=St.w;else if(t instanceof h)i[e]=t.x,i[e+1]=t.y;else if(t instanceof r)i[e]=t.x,i[e+1]=t.y,i[e+2]=t.z;else if(t instanceof s)i[e]=t.x,i[e+1]=t.y,i[e+2]=t.z,i[e+3]=t.w;else if(t instanceof n||t instanceof o){const s=t.elements;for(let t=0;s.length>t;t++)i[e+t]=s[t]}else"number"==typeof t&&(i[e]=t)}function Mt(t,i){const s=gt(t);if(!s.instantiable)throw Error("buildEmptyInstancedBufferAttribute.value: cannot create instanced attribute for non-instantiable type");return new u(new Float32Array(i*s.bufferSize),s.bufferSize)}function Ct(t,i,e){if("number"==typeof t)return i[e];if(t instanceof h)return new h(i[e],i[e+1]);if(t instanceof r)return new r(i[e],i[e+1],i[e+2]);if(t instanceof s)return new s(i[e],i[e+1],i[e+2],i[e+3]);if(t instanceof rt)return(new rt).setGLSLColor(i[e],i[e+1],i[e+2],i[e+3]);if(t instanceof n){const t=new n;return t.fromArray(i,e),t}if(t instanceof o){const t=new o;return t.fromArray(i,e),t}throw Error("reconstructValue.referenceValue: cannot reconstruct value for type")}function Tt(t,i,s,e,h){if(0>=e||0===h)return;const r=s*i;t.copyWithin((s+h)*i,r,r+e*i)}function Pt(t,i,s,e,h){for(let r=0;h>r;r++)s[e+r]=t[i+r]}class At extends f{constructor(t,i,s,e=1){const h={},r={instanceVisibility:{value:1,glslTypeInfo:gt("number")},instanceTransform:{value:(new o).identity(),glslTypeInfo:gt("Matrix4")}};for(const t in i){const s=i[t];s.glslTypeInfo.instantiable?r[t]=s:h[t]=s}const n=It.clone(),a=((t,i,s,e)=>{const h={},r=[],n=[],o=[],a=[];for(const t in i){const{value:s,glslTypeInfo:e}=i[t];h["p_"+t]={value:s instanceof rt?s.toGLSLColor():s},r.push(`uniform ${e.glslTypeName} p_${t};`)}for(const t in s){const{glslTypeInfo:i}=s[t];n.push(`attribute ${i.glslTypeName} a_${t};`),o.push(`varying ${i.glslTypeName} p_${t};`),a.push(`p_${t} = a_${t};`)}const c=`\n // User attributes\n ${n.join("\n")}\n\n // Uniforms\n ${r.join("\n")}\n\n // Builtin varyings\n varying vec3 p_position;\n varying vec2 p_uv;\n\n // User varyings\n ${o.join("\n")}\n\n void main() {\n if (a_instanceVisibility < 0.5) {\n gl_Position = vec4(2.0, 2.0, 2.0, 1.0);\n return;\n }\n\n ${a.join("\n")}\n\n p_position = position;\n p_uv = uv;\n\n gl_Position = projectionMatrix * a_instanceTransform * vec4(position, 1.0);\n }\n `,u=((t,i,s)=>`\n // Defines\n #define PI 3.14159265359\n #define SRGB_SUPPORTED ${at()?"1":"0"}\n\n // Uniforms\n ${t.join("\n")}\n\n // Builtin varyings\n varying vec3 p_position;\n varying vec2 p_uv;\n\n // User varyings\n ${i.join("\n")}\n\n #include <alphahash_pars_fragment>\n\n // sRGB decode helper\n vec4 srgbTexture2D(sampler2D textureSampler, vec2 uv) {\n #if SRGB_SUPPORTED\n return texture2D(textureSampler, uv);\n #else\n vec4 textureValue = texture2D(textureSampler, uv);\n return vec4(pow(textureValue.rgb, vec3(2.2)), textureValue.a);\n #endif\n }\n\n // Source must define vec4 draw() function\n ${s}\n void main() {\n vec4 diffuseColor = draw();\n #ifdef USE_ALPHATEST\n if (diffuseColor.a < 0.50) {\n discard;\n }\n #endif\n #ifdef USE_ALPHAHASH\n if (diffuseColor.a < getAlphaHashThreshold(p_position)) {\n discard;\n }\n #endif\n gl_FragColor = linearToOutputTexel(diffuseColor);\n }\n `)(r,o,t);return new l({uniforms:h,vertexShader:c,fragmentShader:u,transparent:e===_t.BLEND,alphaTest:e===_t.CLIP?.5:0,alphaHash:e===_t.HASH,depthWrite:e!==_t.BLEND,depthTest:!0})})(t,h,r,s);super(n,a),this.frustumCulled=!1,this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1,this.source=t,this.transparency=s,this.$t=n,this.zt=a,this.Ft=h,this.Nt=r,this.Ot=new Map,this.Gt=Math.max(4*Math.ceil(e/4),4),this.jt=0,this.$t.instanceCount=0;for(const t in this.Nt){const{value:i}=this.Nt[t],s=Mt(i,this.Gt);this.$t.setAttribute("a_"+t,s),this.Ot.set(t,s)}for(const t in this.Ft){const{value:i}=this.Ft[t];wt(t,this.zt).value=i}this.zt.uniformsNeedUpdate=!0}get instancesCount(){return this.jt}insertAt(t,i,s,e){if(0>t||t>this.jt)throw Error(`UIGenericInstancedPlane.insertAt.index: out of bounds (index=${t}, count=${this.jt})`);this.Yt(this.jt+1),this.jt>t&&this.Xt(t,1),this.qt(t,i,s,e),this.jt++,this.$t.instanceCount=this.jt}removeAt(t){if(0>t||t>=this.jt)throw Error(`UIGenericInstancedPlane.removeAt.index: out of bounds (index=${t}, count=${this.jt})`);this.jt-1>t&&this.Zt(t+1,1),this.jt--,this.$t.instanceCount=this.jt}setPropertiesAt(t,i){if(0>t||t>=this.jt)throw Error(`UIGenericInstancedPlane.setPropertiesAt.index: out of bounds (index=${t}, count=${this.jt})`);for(const s in i){const{value:e,glslTypeInfo:h}=i[s];if(h.instantiable){const i=this.Jt(s);Et(e,i.array,t*i.itemSize),i.needsUpdate=!0}else wt(s,this.zt).value=e,this.zt.uniformsNeedUpdate=!0}}setTransformAt(t,i){if(0>t||t>=this.jt)throw Error(`UIGenericInstancedPlane.setTransformAt.index: out of bounds (index=${t}, count=${this.jt})`);const s=this.Jt("instanceTransform"),e=s.array,h=16*t,r=i.elements;for(let t=0;16>t;t++)e[h+t]=r[t];s.needsUpdate=!0}setVisibilityAt(t,i){if(0>t||t>=this.jt)throw Error(`UIGenericInstancedPlane.setVisibilityAt.index: out of bounds (index=${t}, count=${this.jt})`);const s=this.Jt("instanceVisibility");s.array[t]=i?1:0,s.needsUpdate=!0}extractDataAt(t){if(0>t||t>=this.jt)throw Error(`UIGenericInstancedPlane.extractDataAt.index: out of bounds (index=${t}, count=${this.jt})`);const i={};for(const t in this.Ft){const s=this.Ft[t];i[t]={value:mt(s.value),glslTypeInfo:s.glslTypeInfo}}for(const s in this.Nt){if("instanceVisibility"===s||"instanceTransform"===s)continue;const{value:e,glslTypeInfo:h}=this.Nt[s],r=this.Ot.get(s);i[s]={value:Ct(e,r.array,t*r.itemSize),glslTypeInfo:h}}const s=this.Ot.get("instanceTransform").array,e=new o;e.fromArray(s,16*t);const h=this.Ot.get("instanceVisibility");return{source:this.source,properties:i,transform:e,visibility:h.array[t]>=.5,transparency:this.transparency}}getZIndexAt(t){if(0>t||t>=this.jt)throw Error(`UIGenericInstancedPlane.getZIndexAt.index: out of bounds (index=${t}, count=${this.jt})`);return this.Ot.get("instanceTransform").array[16*t+14]}merge(t){if(0!==t.jt){this.Yt(this.jt+t.jt);for(const[i,s]of this.Ot){const e=t.Ot.get(i);if(!e)throw Error(`UIGenericInstancedPlane.merge: missing attribute ${i} in source`);const h=s.itemSize;Pt(e.array,0,s.array,this.jt*h,t.jt*h),s.needsUpdate=!0}this.jt+=t.jt,this.$t.instanceCount=this.jt,t.jt=0,t.$t.instanceCount=0}}split(t){if(0>=t||t>=this.jt)throw Error(`UIGenericInstancedPlane.split.atIndex: must be in range (0, count) (atIndex=${t}, count=${this.jt})`);const i=this.jt-t,s=new At(this.source,xt({...this.Ft,...this.Nt}),this.transparency,i);for(const[e,h]of this.Ot){const r=s.Ot.get(e);if(!r)throw Error(`UIGenericInstancedPlane.split: missing attribute ${e} in new plane`);const n=h.itemSize;Pt(h.array,t*n,r.array,0,i*n),r.needsUpdate=!0}return s.jt=i,s.$t.instanceCount=i,this.jt=t,this.$t.instanceCount=t,s}isCompatibleWith(t,i,s){return this.source===t&&this.transparency===s&&((t,i)=>{for(const s in i){if(!(s in t))return!1;const e=t[s].glslTypeInfo;if(e.glslTypeName!==i[s].glslTypeInfo.glslTypeName)return!1;if(!e.instantiable&&t[s].value!==i[s].value)return!1}return!0})({...this.Ft,...this.Nt},i)}getProperties(){return{...this.Ft,...this.Nt}}clearInstances(){this.jt=0,this.$t.instanceCount=0}destroy(){this.$t.dispose(),this.zt.dispose(),this.Ot.clear()}Yt(t){if(this.Gt>=t)return;const i=4*Math.ceil(t/4);for(const[t,s]of this.Ot){const e=s.itemSize,h=new Float32Array(i*e);h.set(s.array);const r=new u(h,e);this.$t.setAttribute("a_"+t,r),this.Ot.set(t,r)}this.Gt=i}Xt(t,i){const s=this.jt-t;if(s>0)for(const e of this.Ot.values())Tt(e.array,e.itemSize,t,s,i),e.needsUpdate=!0}Zt(t,i){const s=this.jt-t;if(s>0)for(const e of this.Ot.values())Tt(e.array,e.itemSize,t,s,-i),e.needsUpdate=!0}qt(t,i,s,e){const h=this.Jt("instanceVisibility");h.array[t]=e?1:0,h.needsUpdate=!0;const r=this.Jt("instanceTransform"),n=r.array,o=16*t,a=s.elements;for(let t=0;16>t;t++)n[o+t]=a[t];r.needsUpdate=!0;for(const s in i){const{value:e,glslTypeInfo:h}=i[s];if(h.instantiable){const i=this.Ot.get(s);i&&(Et(e,i.array,t*i.itemSize),i.needsUpdate=!0)}else wt(s,this.zt).value=e,this.zt.uniformsNeedUpdate=!0}}Jt(t){const i=this.Ot.get(t);if(void 0===i)throw Error(`UIGenericInstancedPlane.resolveAttribute.name: unknown attribute "${t}"`);return i}}class Ut{constructor(t){this.Kt=new Map,this.Mt=0,this.Qt=[],this.ti=new Map,this.ii=new Set,this.si=new Set,this.ei=new Set,this.hi=!1,this.ri=t}createPlane(t,i,s,e,h){const r=this.Mt++,n=yt((t=>{const i={};for(const s in t)i[s]=mt(t[s]);return i})(i)),o=bt(s),a={source:t,properties:n,transform:s.clone(),visibility:e,transparency:h,zIndex:o};return this.Kt.set(r,a),this.ii.add(r),this.hi=!0,r}destroyPlane(t){if(!this.Kt.has(t))throw Error(`UIPlaneRegistry.destroyPlane: handler ${t} not found`);this.Kt.delete(t),this.ii.has(t)?this.ii.delete(t):(this.ei.delete(t),this.si.add(t),this.hi=!0)}setProperties(t,i){const s=this.ni(t),e=yt(i);let h=!1;for(const t in e){const i=e[t];i.glslTypeInfo.instantiable||s.properties[t].value!==i.value&&(h=!0),s.properties[t]={value:i.value,glslTypeInfo:i.glslTypeInfo}}if(h&&!this.ii.has(t))this.ei.add(t),this.hi=!0;else{const i=this.ti.get(t);i&&i.mesh.setPropertiesAt(i.instanceIndex,e)}}setTransform(t,i){const s=this.ni(t),e=bt(i),h=s.zIndex;if(s.transform.copy(i),s.zIndex=e,h===e||this.ii.has(t)){const s=this.ti.get(t);s&&s.mesh.setTransformAt(s.instanceIndex,i)}else this.ei.add(t),this.hi=!0}setVisibility(t,i){this.ni(t).visibility=i;const s=this.ti.get(t);s&&s.mesh.setVisibilityAt(s.instanceIndex,i)}setTransparency(t,i){const s=this.ni(t);s.transparency!==i&&(s.transparency=i,this.ii.has(t)||(this.ei.add(t),this.hi=!0))}flush(){this.hi&&(this.oi(),this.ai(),this.ci(),this.li(),this.ui(),this.fi(),this.ii.clear(),this.si.clear(),this.ei.clear(),this.hi=!1)}oi(){for(const t of this.si){const i=this.ti.get(t);if(!i)continue;const{mesh:s,instanceIndex:e}=i;s.removeAt(e),this.di(s,e+1,-1),this.ti.delete(t)}}ai(){for(const t of this.ei){const i=this.ti.get(t);if(!i)continue;const{mesh:s,instanceIndex:e}=i;s.removeAt(e),this.di(s,e+1,-1),this.ti.delete(t),this.ii.add(t)}}ci(){if(0===this.ii.size)return;const t=[];for(const i of this.ii){const s=this.Kt.get(i);s&&t.push({handler:i,state:s})}t.sort((t,i)=>t.state.zIndex-i.state.zIndex);for(let i=1;t.length>i;i++)if(t[i].state.zIndex===t[i-1].state.zIndex)throw Error(`UIPlaneRegistry.flush: duplicate zIndex=${t[i].state.zIndex} for handlers ${t[i-1].handler} and ${t[i].handler}`);for(const{handler:i,state:s}of t)this.pi(i,s)}pi(t,i){const{source:s,properties:e,transform:h,visibility:r,transparency:n,zIndex:o}=i;let a=null;for(const t of this.Qt){if(!t.isCompatibleWith(s,e,n))continue;if(0===t.instancesCount){a=t;break}const i=t.getZIndexAt(0),h=t.getZIndexAt(t.instancesCount-1);if(o>=i-1&&h+1>=o){a=t;break}}if(a){const i=this.gi(a,o);a.insertAt(i,e,h,r),this.di(a,i,1),this.ti.set(t,{mesh:a,instanceIndex:i})}else{const i=this.wi(o),a=new At(s,xt(e),n);a.insertAt(0,e,h,r),this.Qt.splice(i,0,a),this.ri.add(a),this.ti.set(t,{mesh:a,instanceIndex:0})}}li(){let t=0;for(;this.Qt.length-1>t;){const i=this.Qt[t],s=this.Qt[t+1];if(0===i.instancesCount||0===s.instancesCount){t++;continue}const e=i.getZIndexAt(i.instancesCount-1);if(s.getZIndexAt(0)>e&&i.isCompatibleWith(s.source,s.getProperties(),s.transparency)){const e=i.instancesCount;i.merge(s),this.yi(s,i,e),this.ri.remove(s),s.destroy(),this.Qt.splice(t+1,1);continue}t++}}ui(){for(let t=this.Qt.length-1;t>=0;t--){const i=this.Qt[t];0===i.instancesCount&&(this.ri.remove(i),i.destroy(),this.Qt.splice(t,1))}}ni(t){const i=this.Kt.get(t);if(!i)throw Error(`UIPlaneRegistry.resolveState: handler ${t} not found`);return i}wi(t){for(let i=0;this.Qt.length>i;i++){const s=this.Qt[i];if(s.instancesCount>0&&s.getZIndexAt(0)>t)return i}return this.Qt.length}gi(t,i){for(let s=0;t.instancesCount>s;s++)if(t.getZIndexAt(s)>i)return s;return t.instancesCount}di(t,i,s){for(const e of this.ti.values())e.mesh!==t||i>e.instanceIndex||(e.instanceIndex+=s)}yi(t,i,s){for(const e of this.ti.values())e.mesh===t&&(e.mesh=i,e.instanceIndex+=s)}fi(){this.Qt.sort((t,i)=>(t.instancesCount>0?t.getZIndexAt(0):0)-(i.instancesCount>0?i.getZIndexAt(0):0));for(let t=0;this.Qt.length>t;t++)this.Qt[t].renderOrder=t}}let Ht=new i,Rt=0,Bt=!1,Vt=!1,Lt=!1,Dt=!1;class kt{constructor(t,i){this.ri=new d,this.mi=new Ut(this.ri),this.xi=new p(0,t,i,0,-1024,1024),this.xi.matrixAutoUpdate=!1,this.xi.matrixWorldAutoUpdate=!1}createPlane(t,i,s,e,h){return this.mi.createPlane(t,i,s,e,h)}destroyPlane(t){this.mi.destroyPlane(t)}setTransform(t,i){this.mi.setTransform(t,i)}setProperties(t,i){this.mi.setProperties(t,i)}setVisibility(t,i){this.mi.setVisibility(t,i)}setTransparency(t,i){this.mi.setTransparency(t,i)}insertCustomObject(t){return this.ri.add(t),this}removeCustomObject(t){return this.ri.remove(t),this}resize(t,i){return this.xi.right=t,this.xi.top=i,this.xi.updateProjectionMatrix(),this}render(t){return this.mi.flush(),Ht=t.getClearColor(Ht),Rt=t.getClearAlpha(),Bt=t.autoClear,Vt=t.autoClearColor,Lt=t.autoClearDepth,Dt=t.autoClearStencil,t.autoClear=!1,t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.setClearColor(0,1),t.clear(!1,!0,!0),t.render(this.ri,this.xi),t.setClearColor(Ht),t.setClearAlpha(Rt),t.autoClear=Bt,t.autoClearColor=Vt,t.autoClearDepth=Lt,t.autoClearStencil=Dt,this}}class Wt{constructor(t=0,i){if(this.constant=t,this.bi=i?new Map(i):new Map,i)for(let t=0;i.length>t;t++)Xt()}static plus(t,i){const s=new Wt(t.constant+i.constant,Array.from(t.bi.entries()));for(const[t,e]of i.bi)s.plus(t,e);return s}static minus(t,i){const s=new Wt(t.constant-i.constant,Array.from(t.bi.entries()));for(const[t,e]of i.bi)s.minus(t,e);return s}plus(t,i){return this.bi.set(t,(this.bi.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this.bi)this.bi.set(i,s*t);return this}divide(t){if(0===t)throw Error("UIExpression.divide.value: cannot divide by zero");return this.multiply(1/t)}hasTerm(t){return this.bi.has(t)}copy(t){this.constant=t.constant,this.bi.clear();for(const[i,s]of t.bi)this.bi.set(i,s);return this}clone(){return new Wt(this.constant,Array.from(this.bi.entries()))}prepareTerms(){return Array.from(this.bi.entries())}}var $t;(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})($t||($t={}));class zt{constructor(){this.dirty=!1,this._i=new j,this.Ii=!1,this.Si=new Map,this.Ei=0,this.Mi=new Map,this.Ci=0}createVariable(t,i){const s=this.Ei++,e=new W;if(i===Q.P0){const h={variable:e,priority:i,value:t};this.Si.set(s,h),h.constraint=this.Ti(new Wt(0,[[s,1]]),new Wt(t),$t.EQUAL,i);try{this._i?.addConstraint(h.constraint)}catch{this._i=void 0}}else{this.Si.set(s,{variable:e,priority:i,value:t});try{this._i?.addEditVariable(e,tt(i)),this._i?.suggestValue(e,t)}catch{this._i=void 0}}return this.Ii=!0,this.dirty=!0,s}removeVariable(t){const i=this.Si.get(t);if(void 0===i)throw Error("UISolverWrapper.removeVariable.index: variable does not exist");for(const i of this.Mi.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error("UISolverWrapper.removeVariable.index: variable is used in constraint");try{i.constraint?this._i?.removeConstraint(i.constraint):this._i?.removeEditVariable(i.variable)}catch{this._i=void 0}this.Si.delete(t),this.Ii=!0,this.dirty=!0}suggestVariableValue(t,i){const s=this.Si.get(t);if(void 0===s)throw Error("UISolverWrapper.suggestVariableValue.index: variable does not exist");s.value!==i&&(s.value=i,s.constraint?s.constraint=this.Pi(s.constraint,(new Wt).plus(t,1),new Wt(s.value),$t.EQUAL,s.priority):this._i?.suggestValue(s.variable,i),this.Ii=!0,this.dirty=!0)}setVariablePriority(t,i){const s=this.Si.get(t);if(void 0===s)throw Error("UISolverWrapper.setVariablePriority.index: variable does not exist");if(i!==s.priority){if(s.priority=i,s.priority===Q.P0){const i=(new Wt).plus(t,1),e=new Wt(s.value);s.constraint=this.Ti(i,e,$t.EQUAL,s.priority);try{this._i?.addConstraint(s.constraint)}catch{this._i=void 0}}else{if(s.constraint)try{this._i?.removeConstraint(s.constraint)}catch{this._i=void 0}s.constraint=void 0,this.Ai(t,s)}this.Ii=!0,this.dirty=!0}}readVariableValue(t){const i=this.Si.get(t);if(void 0===i)throw Error("UISolverWrapper.readVariableValue.index: variable does not exist");return void 0===this._i&&this.Ui(),this.Ii&&(this._i?.updateVariables(),this.Ii=!1),i.variable.value()}createConstraint(t,i,s,e,h){const r=this.Ci++,n=this.Ti(t,i,s,e);if(this.Mi.set(r,{constraint:n,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:h}),h){try{this._i?.addConstraint(n)}catch{this._i=void 0}this.Ii=!0,this.dirty=!0}return r}removeConstraint(t){const i=this.Mi.get(t);if(void 0===i)throw Error("UISolverWrapper.removeConstraint.index: constraint does not exist");if(i.enabled)try{this._i?.removeConstraint(i.constraint)}catch{this._i=void 0}this.Mi.delete(t),this.Ii=!0,this.dirty=!0}setConstraintLHS(t,i){const s=this.Mi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintLHS.index: constraint does not exist");s.lhs.copy(i),this.Hi(s),this.Ii=!0,this.dirty=!0}setConstraintRHS(t,i){const s=this.Mi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRHS.index: constraint does not exist");s.rhs.copy(i),this.Hi(s),this.Ii=!0,this.dirty=!0}setConstraintRelation(t,i){const s=this.Mi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRelation.index: constraint does not exist");s.relation!==i&&(s.relation=i,this.Hi(s),this.Ii=!0,this.dirty=!0)}setConstraintPriority(t,i){const s=this.Mi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintPriority.index: constraint does not exist");s.priority!==i&&(s.priority=i,this.Hi(s),this.Ii=!0,this.dirty=!0)}setConstraintEnabled(t,i){const s=this.Mi.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintEnabled.index: constraint does not exist");if(i!==s.enabled){s.enabled=i;try{s.enabled?this._i?.addConstraint(s.constraint):this._i?.removeConstraint(s.constraint)}catch{this._i=void 0}this.Ii=!0,this.dirty=!0}}Ai(t,i){const s=[];for(const i of this.Mi.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this._i?.removeConstraint(i.constraint)}catch{this._i=void 0}s.push(i)}this._i?.removeEditVariable(i.variable),this._i?.addEditVariable(i.variable,tt(i.priority));for(const t of s)t.constraint=this.Ti(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this._i?.addConstraint(t.constraint)}catch{this._i=void 0;break}}Hi(t){t.constraint=t.enabled?this.Pi(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.Ti(t.lhs,t.rhs,t.relation,t.priority)}Pi(t,i,s,e,h){try{this._i?.removeConstraint(t)}catch{this._i=void 0}const r=this.Ti(i,s,e,h);try{this._i?.addConstraint(r)}catch{this._i=void 0}return r}Ti(t,i,s,e){return new O(this.Ri(t),(t=>{switch(t){case $t.EQUAL:return N.Eq;case $t.LESS_THAN:return N.Le;case $t.GREATER_THAN:return N.Ge;default:throw Error("convertRelation.relation: invalid relation")}})(s),this.Ri(i),tt(e))}Ri(t){return new z(...t.prepareTerms().map(([t,i])=>{const s=this.Si.get(t);if(void 0===s)throw Error("UISolverWrapper.convertExpression.expression: variable does not exist");return[i,s.variable]}),t.constant)}Ui(){if(this._i)throw Error("UISolverWrapper.rebuildSolver: solver already exists");this._i=new j;for(const t of this.Si.values())t.constraint?this._i.addConstraint(t.constraint):(this._i.addEditVariable(t.variable,tt(t.priority)),this._i.suggestValue(t.variable,t.value));for(const t of this.Mi.values())t.enabled&&this._i.addConstraint(t.constraint);this.Ii=!0,this.dirty=!0}}const Ft=H.VISIBLE;class Nt{constructor(t){this.name="",this.inputWrapperInternal=new it,this.Bi=new zt,this.Vi=new A,this.Li=new A,this.Di=new U;const i=t.width??1024,s=t.height??1024;this.ki=new kt(i,s),this.name=t.name??"",this.Wi=t.mode??Ft,this.$i=i>s?R.HORIZONTAL:R.VERTICAL,this.xVariable=this.Bi.createVariable(0,Q.P0),this.yVariable=this.Bi.createVariable(0,Q.P0),this.wVariable=this.Bi.createVariable(i,Q.P0),this.hVariable=this.Bi.createVariable(s,Q.P0)}get sceneWrapper(){return this.ki}get solverWrapper(){return this.Bi}get inputWrapper(){return this.inputWrapperInternal}get x(){return this.Bi.readVariableValue(this.xVariable)}get y(){return this.Bi.readVariableValue(this.yVariable)}get width(){return this.Bi.readVariableValue(this.wVariable)}get height(){return this.Bi.readVariableValue(this.hVariable)}get mode(){return this.Wi}get orientation(){return this.$i}get signalOrientationChanged(){return this.Vi}get signalModeChanged(){return this.Li}get signalRendering(){return this.Di}set mode(t){t!==this.Wi&&(this.Wi=t,this.Li.emit(this.Wi,this))}resizeInternal(t,i){this.Bi.suggestVariableValue(this.wVariable,t),this.Bi.suggestVariableValue(this.hVariable,i),this.ki.resize(t,i);const s=t>i?R.HORIZONTAL:R.VERTICAL;s!==this.$i&&(this.$i=s,this.Vi.emit(this.$i,this))}renderInternal(t,i){V(this.mode)&&(this.Di.emit(t,i,this),this.ki.render(t)),this.Bi.dirty=!1,this.inputWrapperInternal.dirty=!1}}const Ot=1e-6;function Gt(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof Nt}function jt(t){return"object"==typeof t&&null!==t&&"number"==typeof t.xVariable&&"number"==typeof t.yVariable&&"number"==typeof t.x&&"number"==typeof t.y}function Yt(t){return jt(t)&&"number"==typeof t.wVariable&&"number"==typeof t.hVariable&&"number"==typeof t.width&&"number"==typeof t.height}function Xt(){}function qt(t,i,s){if(t instanceof Nt)return t;if(Gt(t))return t.layer;if(i instanceof Nt)return i;if(Gt(i))return i.layer;throw Error(s+": no valid subjects found")}function Zt(t,i,s){if(Gt(i))return i.layer;if(Gt(s))return s.layer;if(i instanceof Nt)return i;if(s instanceof Nt)return s;throw Error(t+": no valid subjects found")}class Jt{constructor(t,i){this.layer=t,this.solverWrapper=this.layer.solverWrapper,this.name=i??""}}class Kt extends Jt{constructor(t,i){var s,e,h;super(t,i?.name),this.zi=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.Fi=(s=i?.priority,s??Q.P0),this.Ni=(e=i?.relation,e??$t.EQUAL),this.$i=(h=i?.orientation,h??R.ALWAYS),this.layer.signalOrientationChanged.on(this.zi)}get priority(){return this.Fi}get relation(){return this.Ni}get orientation(){return this.$i}set priority(t){t!==this.Fi&&(this.Fi=t,this.solverWrapper.setConstraintPriority(this.constraint,this.Fi))}set relation(t){t!==this.Ni&&(this.Ni=t,this.solverWrapper.setConstraintRelation(this.constraint,this.Ni))}set orientation(t){t!==this.$i&&(this.$i=t,this.zi())}destroy(){this.layer.signalOrientationChanged.off(this.zi),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.$i===R.ALWAYS||this.$i===this.layer.orientation}}class Qt extends Kt{constructor(t,i={}){super(t.layer,i),this.Oi=t,this.Gi=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new Wt(0,[[this.Oi.hVariable,1]]),new Wt(this.Gi),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.Gi}set height(t){this.Gi!==t&&(this.Gi=t,this.solverWrapper.setConstraintRHS(this.constraint,new Wt(t)))}}class ti extends Kt{constructor(t,i,s={}){super(qt(t,i,"UIHorizontalDistanceConstraint.constructor"),s),this.ji=t,this.Yi=i,this.Xi=s.anchorA??.5,this.qi=s.anchorB??.5,this.Zi=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Ji(),new Wt(this.Zi),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Zi}get anchorA(){return this.Xi}get anchorB(){return this.qi}set distance(t){this.Zi!==t&&(this.Zi=t,this.solverWrapper.setConstraintRHS(this.constraint,new Wt(this.Zi)))}set anchorA(t){this.Xi!==t&&(this.Xi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorB(t){this.qi!==t&&(this.qi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}Ji(){let t,i;if(Yt(this.ji))t=new Wt(0,[[this.ji.xVariable,1],[this.ji.wVariable,this.Xi]]);else{if(!jt(this.ji))throw Error("UIHorizontalDistanceConstraint.buildLHS.a: invalid element type");t=(new Wt).plus(this.ji.xVariable,1)}if(Yt(this.Yi))i=new Wt(0,[[this.Yi.xVariable,1],[this.Yi.wVariable,this.qi]]);else{if(!jt(this.Yi))throw Error("UIHorizontalDistanceConstraint.buildLHS.b: invalid element type");i=(new Wt).plus(this.Yi.xVariable,1)}return Wt.minus(i,t)}}class ii extends Kt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Zt("UIHorizontalInterpolationConstraint.constructor",t,i),e),this.ji=t,this.Yi=i,this.Ki=s,this.Xi=h,this.qi=h,this.Qi=e.anchorC??.5,this.ts=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Ji(),new Wt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.ts}get anchorA(){return this.Xi}get anchorB(){return this.qi}get anchorC(){return this.Qi}set t(t){this.ts!==t&&(this.ts=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorA(t){this.Xi!==t&&(this.Xi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorB(t){this.qi!==t&&(this.qi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorC(t){this.Qi!==t&&(this.Qi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}Ji(){let t,i,s;if(Yt(this.ji))t=new Wt(0,[[this.ji.xVariable,1],[this.ji.wVariable,this.Xi]]);else{if(!jt(this.ji))throw Error("UIHorizontalInterpolationConstraint.buildLHS.a: invalid element type");t=(new Wt).plus(this.ji.xVariable,1)}if(Yt(this.Yi))i=new Wt(0,[[this.Yi.xVariable,1],[this.Yi.wVariable,this.qi]]);else{if(!jt(this.Yi))throw Error("UIHorizontalInterpolationConstraint.buildLHS.b: invalid element type");i=(new Wt).plus(this.Yi.xVariable,1)}if(Yt(this.Ki))s=new Wt(0,[[this.Ki.xVariable,1],[this.Ki.wVariable,this.Qi]]);else{if(!jt(this.Ki))throw Error("UIHorizontalInterpolationConstraint.buildLHS.c: invalid element type");s=(new Wt).plus(this.Ki.xVariable,1)}const e=t.clone().multiply(1-this.ts),h=i.clone().multiply(this.ts);return Wt.minus(Wt.minus(s,e),h)}}class si extends Kt{constructor(t,i,s={}){super(qt(t,i,"UIHorizontalProportionConstraint.constructor"),s),this.ji=t,this.Yi=i,this.ss=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new Wt(0),this.es(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.ss}set proportion(t){this.ss!==t&&(this.ss=t,this.solverWrapper.setConstraintRHS(this.constraint,this.es()))}es(){return Wt.minus(new Wt(0,[[this.ji.wVariable,this.ss]]),new Wt(0,[[this.Yi.wVariable,1]]))}}class ei extends Kt{constructor(t,i,s={}){super(qt(t,i,"UIVerticalDistanceConstraint.constructor"),s),this.ji=t,this.Yi=i,this.Xi=s.anchorA??.5,this.qi=s.anchorB??.5,this.Zi=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Ji(),new Wt(this.Zi),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Zi}get anchorA(){return this.Xi}get anchorB(){return this.qi}set distance(t){this.Zi!==t&&(this.Zi=t,this.solverWrapper.setConstraintRHS(this.constraint,new Wt(this.Zi)))}set anchorA(t){this.Xi!==t&&(this.Xi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorB(t){this.qi!==t&&(this.qi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}Ji(){let t,i;if(Yt(this.ji))t=new Wt(0,[[this.ji.yVariable,1],[this.ji.hVariable,this.Xi]]);else{if(!jt(this.ji))throw Error("UIVerticalDistanceConstraint.buildLHS.a: invalid element type");t=(new Wt).plus(this.ji.yVariable,1)}if(Yt(this.Yi))i=new Wt(0,[[this.Yi.yVariable,1],[this.Yi.hVariable,this.qi]]);else{if(!jt(this.Yi))throw Error("UIVerticalDistanceConstraint.buildLHS.b: invalid element type");i=(new Wt).plus(this.Yi.yVariable,1)}return Wt.minus(i,t)}}class hi extends Kt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Zt("UIVerticalInterpolationConstraint.constructor",t,i),e),this.ji=t,this.Yi=i,this.Ki=s,this.Xi=h,this.qi=h,this.Qi=e.anchorC??.5,this.ts=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Ji(),new Wt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.ts}get anchorA(){return this.Xi}get anchorB(){return this.qi}get anchorC(){return this.Qi}set t(t){this.ts!==t&&(this.ts=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorA(t){this.Xi!==t&&(this.Xi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorB(t){this.qi!==t&&(this.qi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}set anchorC(t){this.Qi!==t&&(this.Qi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}Ji(){let t,i,s;if(Yt(this.ji))t=new Wt(0,[[this.ji.yVariable,1],[this.ji.hVariable,this.Xi]]);else{if(!jt(this.ji))throw Error("UIVerticalInterpolationConstraint.buildLHS.a: invalid element type");t=(new Wt).plus(this.ji.yVariable,1)}if(Yt(this.Yi))i=new Wt(0,[[this.Yi.yVariable,1],[this.Yi.hVariable,this.qi]]);else{if(!jt(this.Yi))throw Error("UIVerticalInterpolationConstraint.buildLHS.b: invalid element type");i=(new Wt).plus(this.Yi.yVariable,1)}if(Yt(this.Ki))s=new Wt(0,[[this.Ki.yVariable,1],[this.Ki.hVariable,this.Qi]]);else{if(!jt(this.Ki))throw Error("UIVerticalInterpolationConstraint.buildLHS.c: invalid element type");s=(new Wt).plus(this.Ki.yVariable,1)}const e=t.clone().multiply(1-this.ts),h=i.clone().multiply(this.ts);return Wt.minus(Wt.minus(s,e),h)}}class ri extends Kt{constructor(t,i,s={}){super(qt(t,i,"UIVerticalProportionConstraint.constructor"),s),this.ji=t,this.Yi=i,this.ss=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new Wt(0),this.es(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.ss}set proportion(t){this.ss!==t&&(this.ss=t,this.solverWrapper.setConstraintRHS(this.constraint,this.es()))}es(){return Wt.minus(new Wt(0,[[this.ji.hVariable,this.ss]]),new Wt(0,[[this.Yi.hVariable,1]]))}}class ni extends Kt{constructor(t,i={}){super(t.layer,i),this.Oi=t,this.hs=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new Wt(0,[[this.Oi.wVariable,1]]),new Wt(this.hs),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.hs}set width(t){this.hs!==t&&(this.hs=t,this.solverWrapper.setConstraintRHS(this.constraint,new Wt(t)))}}function oi(t){return void 0===t?{}:Array.isArray(t)?{h:t[0],v:t[1]}:"object"==typeof t&&null!==t&&("h"in t||"v"in t)?t:{h:t,v:t}}class ai{static size(t,i={}){const s=oi(i.size),e=oi(i.priority),h=oi(i.relation),r=oi(i.orientation);return{h:new ni(t,{width:s.h,priority:e.h,relation:h.h,orientation:r.h}),v:new Qt(t,{height:s.v,priority:e.v,relation:h.v,orientation:r.v})}}static distance(t,i,s={}){const e=oi(s.anchorA),h=oi(s.anchorB),r=oi(s.distance),n=oi(s.priority),o=oi(s.relation),a=oi(s.orientation);return{h:new ti(t,i,{anchorA:e.h,anchorB:h.h,distance:r.h,priority:n.h,relation:o.h,orientation:a.h}),v:new ei(t,i,{anchorA:e.v,anchorB:h.v,distance:r.v,priority:n.v,relation:o.v,orientation:a.v})}}static proportion(t,i,s={}){const e=oi(s.proportion),h=oi(s.priority),r=oi(s.relation),n=oi(s.orientation);return{h:new si(t,i,{proportion:e.h,priority:h.h,relation:r.h,orientation:n.h}),v:new ri(t,i,{proportion:e.v,priority:h.v,relation:r.v,orientation:n.v})}}static interpolation(t,i,s,e={}){const h=oi(e.anchorA),r=oi(e.anchorB),n=oi(e.anchorC),o=oi(e.t),a=oi(e.priority),c=oi(e.relation),l=oi(e.orientation);return{h:new ii(t,i,s,{anchorA:h.h,anchorB:r.h,anchorC:n.h,t:o.h,priority:a.h,relation:c.h,orientation:l.h}),v:new hi(t,i,s,{anchorA:h.v,anchorB:r.v,anchorC:n.v,t:o.v,priority:a.v,relation:c.v,orientation:l.v})}}}class ci extends Kt{constructor(t,i={}){super(t.layer,i),this.Oi=t,this.rs=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Ji(),new Wt(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.rs}set aspect(t){this.rs!==t&&(this.rs=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ji()))}Ji(){return new Wt(0,[[this.Oi.wVariable,1],[this.Oi.hVariable,-this.rs]])}}const li=.5;class ui{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new ci(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new ti(t,i,{anchorA:s.anchorH??li,anchorB:s.anchorH??li,orientation:s.orientation}),yConstraint:new ei(t,i,{anchorA:s.anchorV??li,anchorB:s.anchorV??li,orientation:s.orientation}),widthConstraint:new si(t,i,{proportion:1,relation:$t.GREATER_THAN,orientation:s.orientation}),heightConstraint:new ri(t,i,{proportion:1,priority:Q.P1,orientation:s.orientation})}}}const fi=.5;class di{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new ci(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new ti(t,i,{anchorA:s.anchorH??fi,anchorB:s.anchorH??fi,orientation:s.orientation}),yConstraint:new ei(t,i,{anchorA:s.anchorV??fi,anchorB:s.anchorV??fi,orientation:s.orientation}),widthConstraint:new si(t,i,{proportion:1,relation:$t.LESS_THAN,orientation:s.orientation}),heightConstraint:new ri(t,i,{proportion:1,priority:Q.P1,orientation:s.orientation})}}}class pi extends Kt{constructor(t,i,s,e={}){super(t,e),this.ns=i,this.cs=s,this.constraint=this.solverWrapper.createConstraint(this.ns,this.cs,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.ns}get rhs(){return this.cs}setLHS(t){this.ns=t,this.solverWrapper.setConstraintLHS(this.constraint,this.ns)}setRHS(t){this.cs=t,this.solverWrapper.setConstraintRHS(this.constraint,this.cs)}}class vi{constructor(t,i){this.layer=t,this.name="";const s=i?.x??0,e=i?.y??0;this.solverWrapper=this.layer.solverWrapper,this.xVariable=this.solverWrapper.createVariable(s,Q.P7),this.yVariable=this.solverWrapper.createVariable(e,Q.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}var gi;(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(gi||(gi={}));const wi=.5,yi=gi.ROTATION_SCALE,mi=new r,xi=new v,bi=new r,_i=new o,Ii=new r(0,0,1);function Si(t,i,s,e,h,r,n,o,a,c,l,u,f,d,p,v,g){const w=s-d-p,y=e-v-g,m=o*s*c,x=a*e*l,b=Math.cos(u),_=Math.sin(u),I=m*b-x*_,S=m*_+x*b,E=d*c,M=g*l,C=E*b-M*_,T=E*_+M*b;if(f===gi.POSITION_ROTATION_SCALE)mi.x=t+r-I+C,mi.y=i+n-S+T;else{const h=a*e;mi.x=t+o*s-I+r+C,mi.y=i+h-S+n+T}return mi.z=h,bi.x=w*c,bi.y=y*l,xi.setFromAxisAngle(Ii,u),_i.compose(mi,xi,bi),_i}const Ei=new e;class Mi{constructor(t){this.ls=Ei,this.us=2,this.fs=2,this.ds=0,this.ps=0,this.vs=2,this.gs=2,this.ws=!1,this.ys=1,this.xs=0,this.bs=0,this._s=0,this.Is=0,this.Ss=!1,this.Es=!1,this.Ms=!1,this.Cs=new U,void 0!==t&&this.set(t)}get width(){return this.us/this.ys}get height(){return this.fs/this.ys}get trimmedWidth(){return(this.ws?this.gs:this.vs)/this.ys}get trimmedHeight(){return(this.ws?this.vs:this.gs)/this.ys}get texture(){return this.ls}get rotated(){return this.ws}get scale(){return this.ys}get trim(){const t=this.ys;return{left:this.xs/t,right:this.bs/t,top:this._s/t,bottom:this.Is/t}}get textureDirty(){return this.Ss}get uvTransformDirty(){return this.Es}get trimDirty(){return this.Ms}get signalDiminsionsChanged(){return this.Cs}setTextureDirtyFalse(){this.Ss=!1}setUVTransformDirtyFalse(){this.Es=!1}setTrimDirtyFalse(){this.Ms=!1}calculateUVTransform(t=new n){const i=this.ls.image?.naturalWidth??2,s=this.ls.image?.naturalHeight??2;if(this.ws){const e=this.vs,h=e/s;t.set(0,this.gs/i,this.ds/i,-h,0,(s-this.ps-e)/s+h,0,0,1)}else t.set(this.vs/i,0,this.ds/i,0,this.gs/s,(s-this.ps-this.gs)/s,0,0,1);return t}getResolution(t=new h){return t.set(this.width,this.height)}set(t){const i=this.width,s=this.height;t instanceof e?this.Ts(t):this.Ps(t),this.width===i&&this.height===s||this.Cs.emit(this.width,this.height,this)}Ts(t){const i=t.image?.naturalWidth??2,s=t.image?.naturalHeight??2;this.us=i,this.fs=s,this.texture!==t&&(this.ls=t,this.Ss=!0),(0!==this.ds||0!==this.ps||this.vs!==i||this.gs!==s||1!==this.ys||this.ws)&&(this.ds=0,this.ps=0,this.vs=i,this.gs=s,this.ws=!1,this.ys=1,this.Es=!0),0===this.xs&&0===this.bs&&0===this._s&&0===this.Is||(this.xs=0,this.bs=0,this._s=0,this.Is=0,this.Ms=!0)}Ps(t){this.us=t.sourceSize.w,this.fs=t.sourceSize.h,this.texture!==t.texture&&(this.ls=t.texture,this.Ss=!0);const i=t.scale??1,s=t.rotated??!1;0===this.ds&&0===this.ps&&this.vs===t.frame.w&&this.gs===t.frame.h&&this.ys===i&&this.ws===s||(this.ds=t.frame.x,this.ps=t.frame.y,this.vs=t.frame.w,this.gs=t.frame.h,this.ys=i,this.ws=s,this.Es=!0);const e=t.spriteSourceSize,h=e.x,r=e.y,n=this.us-e.x-e.w,o=this.fs-e.y-e.h;this.xs===h&&this.bs===n&&this._s===r&&this.Is===o||(this.xs=h,this.bs=n,this._s=r,this.Is=o,this.Ms=!0)}}var Ci="vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;return srgbTexture2D(p_texture,transformedUV)*p_color;}";class Ti{constructor(t){this.Vt=!0,this.As=t?.x??0,this.Us=t?.y??0,this.Hs=t?.anchorX??wi,this.Rs=t?.anchorY??wi,this.Bs=t?.scaleX??1,this.Vs=t?.scaleY??1,this.Ls=t?.rotation??0,this.Ds=t?.anchorMode??yi}get x(){return this.As}get y(){return this.Us}get anchorX(){return this.Hs}get anchorY(){return this.Rs}get scaleX(){return this.Bs}get scaleY(){return this.Vs}get angle(){return t.radToDeg(this.Ls)}get anchorMode(){return this.Ds}get rotation(){return this.Ls}get dirty(){return this.Vt}set x(t){t!==this.As&&(this.As=t,this.Vt=!0)}set y(t){t!==this.Us&&(this.Us=t,this.Vt=!0)}set anchorX(t){t!==this.Hs&&(this.Hs=t,this.Vt=!0)}set anchorY(t){t!==this.Rs&&(this.Rs=t,this.Vt=!0)}set scaleX(t){t!==this.Bs&&(this.Bs=t,this.Vt=!0)}set scaleY(t){t!==this.Vs&&(this.Vs=t,this.Vt=!0)}set angle(i){const s=t.degToRad(i);s!==this.Ls&&(this.Ls=s,this.Vt=!0)}set rotation(t){t!==this.Ls&&(this.Ls=t,this.Vt=!0)}set anchorMode(t){t!==this.Ds&&(this.Ds=t,this.Vt=!0)}setDirtyFalse(){this.Vt=!1}reset(){0===this.As&&0===this.Us&&this.Hs===wi&&this.Rs===wi&&1===this.Bs&&1===this.Vs&&0===this.Ls||(this.As=0,this.Us=0,this.Hs=wi,this.Rs=wi,this.Bs=1,this.Vs=1,this.Ls=0,this.Vt=!0)}copy(t){this.As===t.As&&this.Us===t.Us&&this.Hs===t.Hs&&this.Rs===t.Rs&&this.Bs===t.Bs&&this.Vs===t.Vs&&this.Ls===t.Ls&&this.Ds===t.Ds||(this.As=t.As,this.Us=t.Us,this.Hs=t.Hs,this.Rs=t.Rs,this.Bs=t.Bs,this.Vs=t.Vs,this.Ls=t.Ls,this.Ds=t.Ds,this.Vt=!0)}}class Pi{}class Ai extends Pi{constructor(t,i,s,e){super(),this.x=t,this.y=i,this.width=s,this.height=e}contains(t,i){return!(this.x>t||t>this.x+this.width||this.y>i||i>this.y+this.height)}}const Ui=H.VISIBLE;class Hi extends vi{constructor(t,i){const s=i?.width??64,e=i?.height??32;super(t,i),this.ks=!1,this.Ws=new P,this.$s=new P,this.zs=new P,this.Fs=new P,this.Ns=new P,this.catchPointerDown=(t,i,s)=>this.handleInputEvent(t,i,s,this.Ws),this.catchPointerMove=(t,i,s)=>this.handleInputEvent(t,i,s,this.$s),this.catchPointerUp=(t,i,s)=>this.handleInputEvent(t,i,s,this.zs),this.interactionArea=i?.interactionArea??new Ai(0,0,1,1),this.modeInternal=i?.mode??Ui,this.inputWrapper=this.layer.inputWrapper,this.wVariable=this.solverWrapper.createVariable(s,Q.P6),this.hVariable=this.solverWrapper.createVariable(e,Q.P6),this.Os=this.inputWrapper.createInputCatcher(this.catchPointerDown,this.catchPointerMove,this.catchPointerUp,0),this.inputWrapper.setActive(this.Os,B(this.modeInternal))}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get oppositeX(){return this.x+this.width}get oppositeY(){return this.y+this.height}get centerX(){return this.x+this.width/2}get centerY(){return this.y+this.height/2}get mode(){return this.modeInternal}get zIndex(){return this.inputWrapper.getZIndex(this.Os)}get signalPressed(){return this.Ws}get signalMoved(){return this.$s}get signalReleased(){return this.zs}get signalEntered(){return this.Fs}get signalLeft(){return this.Ns}set width(t){this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){this.solverWrapper.suggestVariableValue(this.hVariable,t)}set oppositeX(t){this.x=t-this.width}set oppositeY(t){this.y=t-this.height}set centerX(t){this.x=t-this.width/2}set centerY(t){this.y=t-this.height/2}set mode(t){if(this.modeInternal!==t){const i=B(t);this.inputWrapper.setActive(this.Os,i),this.modeInternal=t}}set zIndex(t){this.inputWrapper.setZIndex(this.Os,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.inputWrapper.destroyInputCatcher(this.Os),super.destroy()}handleInputEvent(i,s,e,h){const r=this.interactionArea.contains(t.mapLinear(i,this.x,this.oppositeX,0,1),t.mapLinear(s,this.y,this.oppositeY,0,1));return r&&h.emit({x:i,y:s,identifier:e,element:this}),this.ks&&!r?this.Ns.emit({x:i,y:s,identifier:e,element:this}):!this.ks&&r&&this.Fs.emit({x:i,y:s,identifier:e,element:this}),this.ks=r,this.modeInternal!==H.INTERACTIVE_TRANSPARENT&&r}}const Ri=_t.BLEND;class Bi extends Hi{constructor(t,i,s,e){super(t,e),this.Gs=!1,this.js=!1,this.Ys=(t,i)=>{this.onWillRender(t,i)},this.micro=new Ti(e?.micro),this.Xs=e?.transparencyMode??Ri,this.sceneWrapper=this.layer.sceneWrapper,this.planeHandler=this.sceneWrapper.createPlane(i,s,(new o).identity(),V(e?.mode??this.mode),this.Xs),this.layer.signalRendering.on(this.Ys)}get transparencyMode(){return this.Xs}set transparencyMode(t){this.Xs!==t&&(this.Xs=t,this.Gs=!0)}set mode(t){this.modeInternal!==t&&(this.js=V(this.modeInternal)!==V(t),super.mode=t)}destroy(){this.layer.signalRendering.off(this.Ys),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}setPlaneTransform(){(this.micro.dirty||this.inputWrapper.dirty||this.solverWrapper.dirty)&&(this.sceneWrapper.setTransform(this.planeHandler,((t,i,s,e,h,r,n,o,a,c,l,u,f)=>{const d=s*this.micro.scaleX,p=e*this.micro.scaleY,v=o*d,g=a*p,w=Math.cos(u),y=Math.sin(u),m=v*w-g*y,x=v*y+g*w;if(f===gi.POSITION_ROTATION_SCALE)mi.x=t+r-m,mi.y=i+n-x;else{const h=a*e;mi.x=t+o*s-m+r,mi.y=i+h-x+n}return mi.z=h,bi.x=d,bi.y=p,xi.setFromAxisAngle(Ii,u),_i.compose(mi,xi,bi),_i})(this.x,this.y,this.width,this.height,this.zIndex,this.micro.x,this.micro.y,this.micro.anchorX,this.micro.anchorY,0,0,this.micro.rotation,this.micro.anchorMode)),this.micro.setDirtyFalse())}onWillRender(t,i){this.Gs&&(this.sceneWrapper.setTransparency(this.planeHandler,this.Xs),this.Gs=!1),this.js&&(this.sceneWrapper.setVisibility(this.planeHandler,V(this.modeInternal)),this.js=!1),this.setPlaneTransform()}}var Vi;(t=>{t[t.NONE=0]="NONE",t[t.LOOP=1]="LOOP",t[t.PING_PONG=2]="PING_PONG"})(Vi||(Vi={}));const Li=Vi.LOOP;class Di extends Bi{constructor(t,i,s={}){const e=new rt(s.color),h=i.map(t=>new Mi(t)),r=h[0];s.width=s.width??r.width,s.height=s.height??r.height;const n=r.calculateUVTransform();super(t,Ci,{texture:r.texture,textureTransform:n,color:e},s),this.qs=!1,this.Zs=0,this.Js=!1,this.Ks=0,this.Qs=new T,this.te=new T,this.ie=new T,this.se=(t,i,s)=>{this.ee[this.Zs]===s&&(this.width=t,this.height=i)},this.he=e,this.ee=h,this.re=n,this.ne=s.frameRate??24,this.oe=s.timeScale??1,this.ae=s.loopMode??Li,this.ce(),!0===s.playByDefault&&this.play()}get color(){return this.he}get duration(){return this.ee.length/this.ne}get frameRate(){return this.ne}get loopMode(){return this.ae}get sequence(){return this.ee}get timeScale(){return this.oe}get signalPlayed(){return this.Qs}get signalPaused(){return this.te}get signalStopped(){return this.ie}set color(t){this.he.set(t)}set frameRate(t){this.ne=t}set loopMode(t){this.ae=t}set sequence(t){this.stop(),this.le();const i=t.length,s=this.ee.length;for(let e=0;Math.min(i,s)>e;e++)this.ee[e].set(t[e]);if(s>i)this.ee.length=i;else if(i>s)for(let e=s;i>e;e++)this.ee.push(new Mi(t[e]));this.ce()}set timeScale(t){this.oe=t}destroy(){this.le(),super.destroy()}play(){this.qs||(this.qs=!0,this.Qs.emit())}pause(){this.qs&&(this.qs=!1,this.te.emit())}stop(){(this.qs||this.Ks>0||this.Zs>0)&&(this.qs=!1,this.Ks=0,this.Zs=0,this.Js=!0,this.ie.emit())}onWillRender(t,i){if(this.qs&&0!==this.oe){this.Ks+=i*this.oe;const t=1/this.ne,s=this.ee.length,e=s-1;if(this.oe>0)for(;this.Ks>=t;){if(this.Ks-=t,this.Zs+=1,this.Zs>=s)if(this.ae===Vi.LOOP)this.Zs=0;else{if(this.ae!==Vi.PING_PONG){this.Zs=e,this.qs=!1,this.te.emit();break}this.Zs=e,this.oe=-this.oe}this.Js=!0}else for(;-t>=this.Ks;){if(this.Ks+=t,this.Zs-=1,0>this.Zs)if(this.ae===Vi.LOOP)this.Zs=e;else{if(this.ae!==Vi.PING_PONG){this.Zs=0,this.qs=!1,this.te.emit();break}this.Zs=0,this.oe=-this.oe}this.Js=!0}}super.onWillRender(t,i)}setPlaneTransform(){let t;this.he.dirty&&(t??(t={}),t.color=this.he,this.he.setDirtyFalse());const i=this.ee[this.Zs];if((i.textureDirty||this.Js)&&(t??(t={}),t.texture=i.texture,i.setTextureDirtyFalse()),(i.uvTransformDirty||this.Js)&&(t??(t={}),t.textureTransform=i.calculateUVTransform(this.re),i.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.Js||this.micro.dirty||i.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,s=i.trim;this.sceneWrapper.setTransform(this.planeHandler,Si(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,s.left,s.right,s.top,s.bottom)),this.Js=!1,this.micro.setDirtyFalse(),i.setTrimDirtyFalse()}}ce(){for(const t of this.ee)t.signalDiminsionsChanged.on(this.se)}le(){for(const t of this.ee)t.signalDiminsionsChanged.off(this.se)}}function ki(t,i){if(nt??(nt=(()=>{if("undefined"==typeof OffscreenCanvas)return!1;const t=document.createElement("canvas");t.width=4,t.height=4;const i=t.getContext("webgl")??t.getContext("webgl2");if(!i)return!1;try{const t=new OffscreenCanvas(4,4),s=t.getContext("2d");if(!s)return!1;s.fillStyle="#ff0000",s.fillRect(0,0,4,4);const e=i.createTexture();if(i.bindTexture(i.TEXTURE_2D,e),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.getError()!==i.NO_ERROR)return i.deleteTexture(e),!1;const h=i.createFramebuffer();if(i.bindFramebuffer(i.FRAMEBUFFER,h),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),i.checkFramebufferStatus(i.FRAMEBUFFER)!==i.FRAMEBUFFER_COMPLETE)return i.deleteFramebuffer(h),i.deleteTexture(e),!1;const r=new Uint8Array(4);return i.readPixels(0,0,1,1,i.RGBA,i.UNSIGNED_BYTE,r),i.bindFramebuffer(i.FRAMEBUFFER,null),i.deleteFramebuffer(h),i.deleteTexture(e),!!(r[0]>200&&50>r[1]&&50>r[2]&&r[3]>200)}catch(t){return!1}})()),nt)return new OffscreenCanvas(t,i);const s=document.createElement("canvas");return s.width=t,s.height=i,s}function Wi(t){const i=new g(t,w,y,y,m,m,x,b,1);return i.colorSpace=at()?_:I,i.generateMipmaps=!1,i}const $i=new rt;class zi extends Bi{constructor(t,i){const s=i?.width??2,e=i?.height??2,h=new rt(i?.color),r=ki(s,e),o=r.getContext("2d");if(!o)throw Error("UIGraphics.constructor: failed to get 2D context from canvas");const a=Wi(r);a.needsUpdate=!0,super(t,Ci,{texture:a,textureTransform:new n,color:h},i),this.ue=r,this.fe=o,this.de=a,this.he=h}get color(){return this.he}set color(t){this.he.set(t)}clear(t){return this.fe.clearRect(0,0,this.ue.width,this.ue.height),void 0!==t&&(this.fe.fillStyle=$i.set(t).toCSSColor(),this.fe.fillRect(0,0,this.ue.width,this.ue.height)),this.de.needsUpdate=!0,this}drawRect(t,i,s,e,h){return this.fe.fillStyle=$i.set(h).toCSSColor(),this.fe.fillRect(t,i,s,e),this.de.needsUpdate=!0,this}drawCircle(t,i,s,e){return this.fe.fillStyle=$i.set(e).toCSSColor(),this.fe.beginPath(),this.fe.arc(t,i,s,0,2*Math.PI),this.fe.fill(),this.de.needsUpdate=!0,this}drawArc(t,i,s,e,h,r){return this.fe.fillStyle=$i.set(r).toCSSColor(),this.fe.beginPath(),this.fe.arc(t,i,s,e,h),this.fe.fill(),this.de.needsUpdate=!0,this}drawPolyline(t,i,s=1){if(2>t.length)return this;this.fe.strokeStyle=$i.set(i).toCSSColor(),this.fe.lineWidth=s,this.fe.beginPath(),this.fe.moveTo(t[0][0],t[0][1]);for(let i=1;t.length>i;i++)this.fe.lineTo(t[i][0],t[i][1]);return this.fe.stroke(),this.de.needsUpdate=!0,this}destroy(){this.de.dispose(),super.destroy()}onWillRender(t,i){this.he.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.he}),this.he.setDirtyFalse()),super.onWillRender(t,i)}}class Fi extends Bi{constructor(t,i,s={}){const e=new rt(s.color),h=new Mi(i),r=h.calculateUVTransform();s.width=s.width??h.width,s.height=s.height??h.height,super(t,Ci,{texture:h.texture,textureTransform:r,color:e},s),this.se=(t,i)=>{this.width=t,this.height=i},this.texture=h,this.re=r,this.he=e,this.texture.signalDiminsionsChanged.on(this.se)}get color(){return this.he}set color(t){this.he.set(t)}destroy(){this.texture.signalDiminsionsChanged.off(this.se),super.destroy()}setPlaneTransform(){let t;if(this.he.dirty&&(t??(t={}),t.color=this.he,this.he.setDirtyFalse()),this.texture.textureDirty&&(t??(t={}),t.texture=this.texture.texture,this.texture.setTextureDirtyFalse()),this.texture.uvTransformDirty&&(t??(t={}),t.textureTransform=this.texture.calculateUVTransform(this.re),this.texture.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.micro.dirty||this.texture.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,i=this.texture.trim;this.sceneWrapper.setTransform(this.planeHandler,Si(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom)),this.micro.setDirtyFalse(),this.texture.setTrimDirtyFalse()}}}class Ni{constructor(t){this.Bt=0,this.Tt=0,this.ts=0,this.At=0,this.Vt=!1,this.set(t)}get left(){return this.Bt}get right(){return this.Tt}get top(){return this.ts}get bottom(){return this.At}get dirty(){return this.Vt}set left(t){this.Bt!==t&&(this.Bt=t,this.Vt=!0)}set right(t){this.Tt!==t&&(this.Tt=t,this.Vt=!0)}set top(t){this.ts!==t&&(this.ts=t,this.Vt=!0)}set bottom(t){this.At!==t&&(this.At=t,this.Vt=!0)}setHorizontal(t){this.Bt===t&&this.Tt===t||(this.Bt=t,this.Tt=t,this.Vt=!0)}setVertical(t){this.ts===t&&this.At===t||(this.ts=t,this.At=t,this.Vt=!0)}setUnified(t){this.Bt===t&&this.Tt===t&&this.ts===t&&this.At===t||(this.Bt=t,this.Tt=t,this.ts=t,this.At=t,this.Vt=!0)}set(t){const i=this.Bt,s=this.Tt,e=this.ts,h=this.At;if(void 0===t)this.Bt=0,this.Tt=0,this.ts=0,this.At=0;else if("number"==typeof t)this.Bt=t,this.Tt=t,this.ts=t,this.At=t;else if(Array.isArray(t))if(2===t.length){const i=t[0],s=t[1];this.Bt=i,this.Tt=i,this.ts=s,this.At=s}else{const i=t[1],s=t[2],e=t[3];this.Bt=t[0],this.Tt=i,this.ts=s,this.At=e}else if("left"in t){const i=t.right,s=t.top,e=t.bottom;this.Bt=t.left,this.Tt=i,this.ts=s,this.At=e}else{const i=t.horizontal,s=t.vertical;this.Bt=i,this.Tt=i,this.ts=s,this.At=s}this.Bt===i&&this.Tt===s&&this.ts===e&&this.At===h||(this.Vt=!0)}setVector4(t){this.Bt===t.x&&this.Tt===t.y&&this.ts===t.z&&this.At===t.w||(this.Bt=t.x,this.Tt=t.y,this.ts=t.z,this.At=t.w,this.Vt=!0)}toVector4(t=new s){return t.set(this.Bt,this.Tt,this.ts,this.At)}reset(){this.setUnified(0)}copy(t){this.Bt===t.Bt&&this.Tt===t.Tt&&this.ts===t.ts&&this.At===t.At||(this.Bt=t.Bt,this.Tt=t.Tt,this.ts=t.ts,this.At=t.At,this.Vt=!0)}setDirtyFalse(){this.Vt=!1}}var Oi;(t=>{t[t.NORMALIZED=0]="NORMALIZED",t[t.WORLD=1]="WORLD"})(Oi||(Oi={}));const Gi=Oi.WORLD;class ji extends Bi{constructor(t,i,e={}){const h=new rt(e.color),r=new Mi(i),n=r.calculateUVTransform();e.width=e.width??r.width,e.height=e.height??r.height;const o=new Ni(e.sliceBorders??.1),a=new Ni(e.sliceRegions??.1),c=e.regionMode??Gi,l=new s,u=new s;super(t,"vec4 draw(){vec2 localUV=p_uv;float left=p_sliceBorders.x;float right=p_sliceBorders.y;float top=p_sliceBorders.z;float bottom=p_sliceBorders.w;float leftFill=p_sliceRegions.x;float rightFill=p_sliceRegions.y;float topFill=p_sliceRegions.z;float bottomFill=p_sliceRegions.w;float lB=leftFill;float rB=1.0-rightFill;float bB=bottomFill;float tB=1.0-topFill;{float regionL=step(p_uv.x,lB);float regionR=step(rB,p_uv.x);float regionM=1.0-regionL-regionR;float xL=(p_uv.x/lB)*left;float xR=1.0-right+((p_uv.x-rB)/rightFill)*right;float xM=left+((p_uv.x-lB)/(rB-lB))*(1.0-left-right);localUV.x=regionL*xL+regionM*xM+regionR*xR;}{float regionB=step(p_uv.y,bB);float regionT=step(tB,p_uv.y);float regionC=1.0-regionB-regionT;float yB=(p_uv.y/bB)*bottom;float yT=1.0-top+((p_uv.y-tB)/topFill)*top;float yC=bottom+((p_uv.y-bB)/(tB-bB))*(1.0-bottom-top);localUV.y=regionB*yB+regionC*yC+regionT*yT;}vec2 transformedUV=(p_textureTransform*vec3(localUV,1.0)).xy;return srgbTexture2D(p_texture,transformedUV)*p_color;}",{texture:r.texture,textureTransform:n,color:h,sliceBorders:l,sliceRegions:u},e),this.pe=!0,this.ve=new s,this.ge=new s,this.we=!0,this.se=()=>{this.we=!0},this.texture=r,this.re=n,this.he=h,this.ye=o,this.me=a,this.xe=c,this.ve=l,this.ge=u,this.be=this.width,this._e=this.height,this.texture.signalDiminsionsChanged.on(this.se)}get color(){return this.he}get regionMode(){return this.xe}get sliceBorders(){return this.ye}get sliceRegions(){return this.me}set color(t){this.he.set(t)}set regionMode(t){this.xe!==t&&(this.xe=t,this.pe=!0)}set sliceBorders(t){this.ye.set(t)}set sliceRegions(t){this.me.set(t)}destroy(){this.texture.signalDiminsionsChanged.off(this.se),super.destroy()}setPlaneTransform(){let t;if((this.we||this.ye.dirty||this.texture.trimDirty)&&(t??(t={}),t.sliceBorders=this.Ie(this.ve),this.ye.setDirtyFalse(),this.we=!1),(this.me.dirty||this.pe||this.xe===Oi.WORLD&&this.Se())&&(t??(t={}),t.sliceRegions=this.Ee(this.ge),this.me.setDirtyFalse(),this.pe=!1,this.Me()),this.he.dirty&&(t??(t={}),t.color=this.he,this.he.setDirtyFalse()),this.texture.textureDirty&&(t??(t={}),t.texture=this.texture.texture,this.texture.setTextureDirtyFalse()),this.texture.uvTransformDirty&&(t??(t={}),t.textureTransform=this.texture.calculateUVTransform(this.re),this.texture.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.micro.dirty||this.texture.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,i=this.texture.trim;this.sceneWrapper.setTransform(this.planeHandler,Si(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom)),this.micro.setDirtyFalse(),this.texture.setTrimDirtyFalse()}}Ie(t){const i=this.texture.width,s=this.texture.height,e=this.texture.trim,h=e.right/i,r=e.top/s,n=e.bottom/s,o=(i-e.left-e.right)/i,a=(s-e.top-e.bottom)/s,c=this.ye.right,l=this.ye.top,u=this.ye.bottom,f=Math.max(0,this.ye.left-e.left/i)/o,d=Math.max(0,c-h)/o,p=Math.max(0,l-r)/a,v=Math.max(0,u-n)/a;return t.set(Math.min(1,f),Math.min(1,d),Math.min(1,p),Math.min(1,v))}Ee(t){if(this.xe===Oi.NORMALIZED)return t.set(this.me.left,this.me.right,this.me.top,this.me.bottom);const i=this.width,s=this.height;return t.set(this.me.left/i,this.me.right/i,this.me.top/s,this.me.bottom/s)}Se(){return this.solverWrapper.dirty&&(this.be!==Math.round(this.width)||this._e!==Math.round(this.height))}Me(){this.be=Math.round(this.width),this._e=Math.round(this.height)}}class Yi{constructor(t){this.source=t,this.dirtyInternal=!1}get dirty(){return this.dirtyInternal}setDirtyFalse(){this.dirtyInternal=!1}}class Xi extends Yi{constructor(t={x:1,y:0}){super("float calculateMask(){float aspect=p_textureResolution.x/p_textureResolution.y;vec2 halfExtents=vec2(aspect,1.0)*0.5;float maxProjection=dot(halfExtents,abs(p_direction));vec2 correctedUV=(p_uv-0.5)*vec2(aspect,1.0);float projection=dot(correctedUV,p_direction);float offset=(projection/maxProjection+1.0)*0.5;return step(offset,p_progress);}"),this.direction=new h,this.Ce=new h,this.direction.set(t.x,t.y).normalize(),this.Ce.copy(this.direction)}get dirty(){return this.Te(),this.dirtyInternal||!this.Ce.equals(this.direction)}setDirtyFalse(){this.Te(),this.Ce.copy(this.direction),super.setDirtyFalse()}enumerateProperties(){return this.Te(),{direction:this.direction}}Te(){const t=this.direction.lengthSq();Math.abs(t)>Ot?Math.abs(t-1)>Ot&&this.direction.divideScalar(t):this.direction.set(1,0)}}var qi,Zi="vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=srgbTexture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}";class Ji extends Bi{constructor(i,s,e={}){const h=new rt(e.color),r=new Mi(s),n=r.calculateUVTransform(),o=r.getResolution();e.width=e.width??r.width,e.height=e.height??r.height;const a=t.clamp(e.progress??1,0,1),c=e.maskFunction??new Xi;super(i,c.source+Zi,{texture:r.texture,textureTransform:n,textureResolution:o,color:h,progress:a,...c.enumerateProperties()},e),this.Pe=!1,this.Ae=!1,this.se=(t,i)=>{this.width===t&&this.height===i||(this.width=t,this.height=i,this.Ae=!0)},this.texture=r,this.re=n,this.Ue=o,this.he=h,this.He=a,this.Re=c,this.texture.signalDiminsionsChanged.on(this.se)}get color(){return this.he}get maskFunction(){return this.Re}get progress(){return this.He}set color(t){this.he.set(t)}set maskFunction(t){this.Re!==t&&(this.Re=t,this.Be())}set progress(i){i=t.clamp(i,0,1),this.He!==i&&(this.He=i,this.Pe=!0)}setPlaneTransform(){let t;if(this.he.dirty&&(t??(t={}),t.color=this.he,this.he.setDirtyFalse()),this.texture.textureDirty&&(t??(t={}),t.texture=this.texture.texture,this.texture.setTextureDirtyFalse()),this.texture.uvTransformDirty&&(t??(t={}),t.textureTransform=this.texture.calculateUVTransform(this.re),this.texture.setUVTransformDirtyFalse()),this.Pe&&(t??(t={}),t.progress=this.He,this.Pe=!1),this.Ae&&(t??(t={}),t.textureResolution=this.texture.getResolution(this.Ue),this.Ae=!1),this.maskFunction.dirty){t??(t={});const i=this.maskFunction.enumerateProperties();for(const s in i)t[s]=i[s];this.maskFunction.setDirtyFalse()}if(t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.micro.dirty||this.texture.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,i=this.texture.trim;this.sceneWrapper.setTransform(this.planeHandler,Si(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom)),this.micro.setDirtyFalse(),this.texture.setTrimDirtyFalse()}}Be(){this.sceneWrapper.destroyPlane(this.planeHandler);const t=this.micro,i=this.texture.trim;this.planeHandler=this.sceneWrapper.createPlane(this.Re.source+Zi,{texture:this.texture.texture,textureTransform:this.texture.calculateUVTransform(this.re),textureResolution:this.texture.getResolution(this.Ue),color:this.he,progress:this.He,...this.Re.enumerateProperties()},Si(this.x,this.y,this.width,this.height,this.zIndex,t.x,t.y,t.anchorX,t.anchorY,t.scaleX,t.scaleY,t.rotation,t.anchorMode,i.left,i.right,i.top,i.bottom),V(this.mode),this.transparencyMode),this.he.setDirtyFalse(),this.texture.setTextureDirtyFalse(),this.texture.setUVTransformDirtyFalse(),this.texture.setTrimDirtyFalse(),this.Pe=!1,this.Ae=!1,this.Re.setDirtyFalse(),this.micro.setDirtyFalse()}}(t=>{t[t.EVERY_FRAME=1]="EVERY_FRAME",t[t.EVERY_SECOND_FRAME=2]="EVERY_SECOND_FRAME",t[t.ON_PROPERTIES_CHANGE=3]="ON_PROPERTIES_CHANGE",t[t.ON_DIMENSIONS_CHANGE=4]="ON_DIMENSIONS_CHANGE",t[t.MANUAL=5]="MANUAL"})(qi||(qi={}));const Ki=qi.ON_PROPERTIES_CHANGE,Qi=new rt(0,0,0,1);class ts extends Bi{constructor(i,s={}){const e=t.clamp(s.resolutionFactor??.5,.1,2),h=s.width??64,r=s.height??32,o=new S(h*e,r*e,{format:x,minFilter:m,magFilter:m,type:b,depthBuffer:s.enableDepthBuffer??!0,stencilBuffer:!1}),a=new rt(s.color);super(i,Ci,{texture:o.texture,textureTransform:new n,color:a},s),this.Ve=!0,this.De=!1,this.ke=!1,this.We=!1,this.he=a,this.$e=new rt(s.clearColor??Qi),this.ze=o,this.Fe=s.scene??new d,this.Ne=s.camera??new E(60,h/r,.1,100),this.Oe=e,this.je=s.updateMode??Ki,this.We=s.updateMode!==qi.MANUAL}get camera(){return this.Ne}get clearColor(){return this.$e}get color(){return this.he}get resolutionFactor(){return this.Oe}get scene(){return this.Fe}get updateMode(){return this.je}set camera(t){this.Ne!==t&&(this.Ne=t,this.We=!0)}set clearColor(t){this.$e.set(t)}set color(t){this.he.set(t)}set resolutionFactor(i){i=t.clamp(i,.1,2),this.Oe!==i&&(this.Oe=i,this.ke=!0)}set scene(t){this.Fe!==t&&(this.Fe=t,this.We=!0)}set updateMode(t){this.je!==t&&(this.je=t,this.We=!0)}destroy(){this.ze.dispose(),super.destroy()}requestUpdate(){this.De=!0}onWillRender(t,i){this.Ve=!this.Ve,(this.De||this.je===qi.EVERY_FRAME||this.je===qi.EVERY_SECOND_FRAME&&this.Ve||this.je===qi.ON_PROPERTIES_CHANGE&&this.We||this.he.dirty||this.$e.dirty||this.je===qi.ON_DIMENSIONS_CHANGE&&(this.ke||this.solverWrapper.dirty))&&((this.ke||this.solverWrapper.dirty)&&(this.ze.setSize(this.width*this.Oe,this.height*this.Oe),this.ke=!1),this.he.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.he}),this.he.setDirtyFalse()),t.setClearColor(this.$e.getHexRGB(),this.$e.a),t.setRenderTarget(this.ze),t.clear(!0,!0,!1),t.render(this.Fe,this.Ne),this.We=!1,this.De=!1),super.onWillRender(t,i)}}const is="#000000",ss="left",es="Arial",hs="normal",rs="normal",ns=!1,os="transparent",as=!1,cs="#000000";class ls{constructor(t){this.Vt=!0,this.he=t?.color,this.Ye=t?.align,this.Xe=t?.fontFamily,this.qe=t?.fontSize,this.Ze=t?.fontStyle,this.Je=t?.fontWeight,this.Ke=t?.lineHeight,this.Qe=t?.enableShadow,this.th=t?.shadowOffsetX,this.ih=t?.shadowOffsetY,this.sh=t?.shadowBlur,this.eh=t?.shadowColor,this.hh=t?.enableStroke,this.rh=t?.strokeColor,this.nh=t?.strokeThickness}get color(){return this.he}get align(){return this.Ye}get fontFamily(){return this.Xe}get fontSize(){return this.qe}get fontStyle(){return this.Ze}get fontWeight(){return this.Je}get lineHeight(){return this.Ke}get enableShadow(){return this.Qe}get shadowOffsetX(){return this.th}get shadowOffsetY(){return this.ih}get shadowBlur(){return this.sh}get shadowColor(){return this.eh}get enableStroke(){return this.hh}get strokeColor(){return this.rh}get strokeThickness(){return this.nh}get dirty(){return this.Vt}set color(t){t!==this.he&&(this.he=t,this.Vt=!0)}set align(t){t!==this.Ye&&(this.Ye=t,this.Vt=!0)}set fontFamily(t){t!==this.Xe&&(this.Xe=t,this.Vt=!0)}set fontSize(t){t!==this.qe&&(this.qe=t,this.Vt=!0)}set fontStyle(t){t!==this.Ze&&(this.Ze=t,this.Vt=!0)}set fontWeight(t){t!==this.Je&&(this.Je=t,this.Vt=!0)}set lineHeight(t){t!==this.Ke&&(this.Ke=t,this.Vt=!0)}set enableShadow(t){t!==this.Qe&&(this.Qe=t,this.Vt=!0)}set shadowOffsetX(t){t!==this.th&&(this.th=t,this.Vt=!0)}set shadowOffsetY(t){t!==this.ih&&(this.ih=t,this.Vt=!0)}set shadowBlur(t){t!==this.sh&&(this.sh=t,this.Vt=!0)}set shadowColor(t){t!==this.eh&&(this.eh=t,this.Vt=!0)}set enableStroke(t){t!==this.hh&&(this.hh=t,this.Vt=!0)}set strokeColor(t){t!==this.rh&&(this.rh=t,this.Vt=!0)}set strokeThickness(t){t!==this.nh&&(this.nh=t,this.Vt=!0)}static resolve(t,i){const s=t.qe??i.qe??16;return{color:t.he??i.he??is,align:t.Ye??i.Ye??ss,fontFamily:t.Xe??i.Xe??es,fontSize:s,fontStyle:t.Ze??i.Ze??hs,fontWeight:t.Je??i.Je??rs,lineHeight:t.Ke??i.Ke??1.2*s,enableShadow:t.Qe??i.Qe??ns,shadowOffsetX:t.th??i.th??0,shadowOffsetY:t.ih??i.ih??0,shadowBlur:t.sh??i.sh??0,shadowColor:t.eh??i.eh??os,enableStroke:t.hh??i.hh??as,strokeColor:t.rh??i.rh??cs,strokeThickness:t.nh??i.nh??0}}setDirtyFalse(){this.Vt=!1}setDefaults(){this.he===is&&this.Ye===ss&&this.Xe===es&&16===this.qe&&this.Ze===hs&&this.Je===rs&&19.2===this.Ke&&this.Qe===ns&&0===this.th&&0===this.ih&&0===this.sh&&this.eh===os&&this.hh===as&&this.rh===cs&&0===this.nh||(this.he=is,this.Ye=ss,this.Xe=es,this.qe=16,this.Ze=hs,this.Je=rs,this.Ke=19.2,this.Qe=ns,this.th=0,this.ih=0,this.sh=0,this.eh=os,this.hh=as,this.rh=cs,this.nh=0,this.Vt=!0)}clear(){void 0===this.he&&void 0===this.Ye&&void 0===this.Xe&&void 0===this.qe&&void 0===this.Ze&&void 0===this.Je&&void 0===this.Ke&&void 0===this.Qe&&void 0===this.th&&void 0===this.ih&&void 0===this.sh&&void 0===this.eh&&void 0===this.hh&&void 0===this.rh&&void 0===this.nh||(this.he=void 0,this.Ye=void 0,this.Xe=void 0,this.qe=void 0,this.Ze=void 0,this.Je=void 0,this.Ke=void 0,this.Qe=void 0,this.th=void 0,this.ih=void 0,this.sh=void 0,this.eh=void 0,this.hh=void 0,this.rh=void 0,this.nh=void 0,this.Vt=!0)}copy(t){this.he===t.he&&this.Ye===t.Ye&&this.Xe===t.Xe&&this.qe===t.qe&&this.Ze===t.Ze&&this.Je===t.Je&&this.Ke===t.Ke&&this.Qe===t.Qe&&this.th===t.th&&this.ih===t.ih&&this.sh===t.sh&&this.eh===t.eh&&this.hh===t.hh&&this.rh===t.rh&&this.nh===t.nh||(this.he=t.he,this.Ye=t.Ye,this.Xe=t.Xe,this.qe=t.qe,this.Ze=t.Ze,this.Je=t.Je,this.Ke=t.Ke,this.Qe=t.Qe,this.th=t.th,this.ih=t.ih,this.sh=t.sh,this.eh=t.eh,this.hh=t.hh,this.rh=t.rh,this.nh=t.nh,this.Vt=!0)}calculatePadding(){let t=0;if(void 0!==this.hh&&(t+=this.nh??0),void 0!==this.Qe){const i=this.ih??0,s=2*(this.sh??0);t+=Math.max(Math.abs(this.th??0)+s,Math.abs(i)+s)}return Math.ceil(t)}}class us{constructor(t){this.Vt=!0,this.oh=t.text,this.style=new ls(t.style)}get text(){return this.oh}get dirty(){return this.Vt||this.style.dirty}set text(t){t!==this.oh&&(this.oh=t,this.Vt=!0)}setDirtyFalse(){this.Vt=!1,this.style.setDirtyFalse()}}var fs;(t=>{t[t.BREAK=0]="BREAK",t[t.SCALE=1]="SCALE"})(fs||(fs={}));const ds=fs.SCALE;function ps(t){return t.match(/\S+|\s|\n/g)??[]}function vs(t,i,s){if(t.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px "${s.fontFamily}"`,"\n"===i)return{width:1,height:s.lineHeight,baseline:0,lineHeight:s.lineHeight};const e=t.measureText(i);return{width:Math.ceil(e.width),height:Math.ceil(e.actualBoundingBoxAscent+e.actualBoundingBoxDescent),baseline:e.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function gs(t,i){const s=((t,i)=>{const s=[];let e=[],h=0,r=0,n=0,o=0;for(const a of i)"\n"!==a.text?0!==e.length&&h+a.metrics.width>t?(s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),e=[a],h=a.metrics.width,r=a.metrics.height,n=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),h+=a.metrics.width,r=Math.max(r,a.metrics.height),n=Math.max(n,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),e=[],h=0,r=0,n=0,o=0);return e.length>0&&s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),s})(i,t),e=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map(t=>t.width));let s=0;for(let i=0;t.length>i;i++){const e=t[i];s+=0===i?e.height:e.lineHeight}return{width:i,height:s}})(s);return{lines:s,size:e}}function ws(t,i,s,e,h){h.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px "${e.fontFamily}"`,e.enableShadow&&(h.shadowOffsetX=e.shadowOffsetX,h.shadowOffsetY=e.shadowOffsetY,h.shadowBlur=e.shadowBlur,h.shadowColor=e.shadowColor),e.enableStroke&&(h.strokeStyle=e.strokeColor,h.lineWidth=e.strokeThickness,h.strokeText(s,t,i)),h.fillStyle=e.color,h.fillText(s,t,i)}function ys(t,i,s,e){let h=t,r=0;for(const t of s)r=Math.max(t.width,r);for(let t=0;s.length>t;t++){const n=s[t],o=n.chunks[0]?.style.align??ss,a=n.chunks.every(t=>t.style.align===o)?o:ss;let c=0;"center"===a?c=(r-n.width)/2:"right"===a&&(c=r-n.width);let l=i+c;h+=0===t?n.height:n.lineHeight;for(const t of n.chunks)ws(l,h,t.text,t.style,e),l+=t.metrics.width}}class ms extends Bi{constructor(t,i,s={}){const e=ki(2,2),h=e.getContext("2d");if(!h)throw Error("UIText.constructor: failed to create canvas context");const r=Wi(e);r.needsUpdate=!0;const o=new rt(s.color);switch(super(t,Ci,{texture:r,textureTransform:new n,color:o}),this.ah=[],this.uh=!1,this.fh=!1,this.dh=!1,this.ph=[],this.gh=!1,this.he=o,this.wh=new Ni(s.padding),this.commonStyle=new ls(s.commonStyle),this.yh=s.maxLineWidth??1024,this.mh=s.resizeMode??ds,this.ue=e,this.fe=h,this.de=r,this.content=i,this.xh=this.width,this.bh=this.height,void 0===s.padding&&this.wh.setUnified(this.content.reduce((t,i)=>Math.max(t,i.style.calculatePadding()),this.commonStyle.calculatePadding())),this.mh){case fs.SCALE:this._h();break;case fs.BREAK:this.Ih()}}get color(){return this.he}get content(){return this.ah}get maxLineWidth(){return this.yh}get padding(){return this.wh}get resizeMode(){return this.mh}set color(t){this.he.set(t)}set content(t){this.ah!==t&&(this.ah="string"==typeof t?[new us({text:t,style:new ls})]:Array.isArray(t)?t.map(t=>new us("string"==typeof t?{text:t,style:new ls}:{text:t.text,style:new ls(t.style)})):[new us({text:t.text,style:new ls(t.style)})],this.uh=!0,this.gh=!0)}set maxLineWidth(t){this.yh!==t&&(this.yh=t,this.fh=!0)}set padding(t){this.wh.set(t)}set resizeMode(t){this.mh!==t&&(this.mh=t,this.dh=!0)}destroy(){this.de.dispose(),super.destroy()}onWillRender(t,i){switch(this.mh){case fs.SCALE:this._h();break;case fs.BREAK:this.Ih()}super.onWillRender(t,i)}_h(){if(!(this.he.dirty||this.dh||this.fh||this.wh.dirty||this.solverWrapper.dirty&&this.xh/this.bh!==Math.round(this.width)/Math.round(this.height)||this.Sh()))return;const t=this.Eh(),{lines:i,size:s}=gs(t,this.yh),e=s.height+(this.wh.top+this.wh.bottom),h=s.width+(this.wh.left+this.wh.right);this.width=h,this.height=e/h*Math.round(this.width),this.width=h/e*Math.round(this.height);const r=this.xh!==e||this.bh!==h;r&&(this.ue.height=e,this.ue.width=h),ys(this.wh.top,this.wh.left,i,this.fe),this.Mh(r),this.dh=!1,this.fh=!1,this.wh.setDirtyFalse(),this.Ch(),this.Th()}Ih(){if(!(this.he.dirty||this.dh||this.fh||this.wh.dirty||this.Ph()||this.Sh()))return;const t=this.Eh(),{size:i}=gs(t,this.yh),s=this.wh.top+this.wh.bottom,e=this.wh.left+this.wh.right;this.height=i.height+s,this.width=i.width+e;const{lines:h,size:r}=gs(t,Math.round(this.width)-e);this.height=r.height+s,this.width=r.width+e;const n=Math.max(Math.round(this.width),2),o=Math.max(Math.round(this.height),2),a=this.xh!==n||this.bh!==o;a&&(this.ue.width=n,this.ue.height=o),ys(this.wh.top,this.wh.left,h,this.fe),this.Mh(a),this.dh=!1,this.fh=!1,this.wh.setDirtyFalse(),this.Ch(),this.Th()}Mh(t){let i;this.he.dirty&&(i??(i={}),i.color=this.he,this.he.setDirtyFalse()),t&&(this.de.dispose(),this.de=Wi(this.ue),this.de.needsUpdate=!0,i??(i={}),i.texture=this.de),i&&this.sceneWrapper.setProperties(this.planeHandler,i)}Eh(){return this.gh&&(this.ph=((t,i,s)=>{const e=[];for(const h of i){const i=ls.resolve(h.style,s);for(const s of ps(h.text)){const h=vs(t,s,i);e.push({text:s,style:i,metrics:h})}}return e})(this.fe,this.ah,this.commonStyle),this.gh=!1),this.ph}Ph(){return this.solverWrapper.dirty&&(this.xh!==Math.round(this.width)||this.bh!==Math.round(this.height))}Ch(){this.xh=Math.round(this.width),this.bh=Math.round(this.height)}Sh(){return this.uh||this.content.some(t=>t.dirty)}Th(){this.uh=!1;for(const t of this.content)t.setDirtyFalse()}}class xs{constructor(){this.dirty=!1}}class bs extends xs{calculateScale(t,i){return 1}}const _s=new bs;class Is extends Nt{constructor(t){const i=t?.resizePolicy??_s,s=i.calculateScale(window.innerWidth,window.innerHeight);super({width:window.innerWidth*s,height:window.innerHeight*s,...t}),this.Ah=!1,this.Ws=new P,this.$s=new P,this.zs=new P,this.Uh=()=>{const t=this.resizePolicy.calculateScale(window.innerWidth,window.innerHeight);this.resizePolicy.dirty=!1,this.Ah=!1,this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Hh=t=>{this.Rh(t,"onPointerDown",this.Ws)},this.Bh=t=>{this.Rh(t,"onPointerMove",this.$s)},this.Vh=t=>{this.Rh(t,"onPointerUp",this.zs)},this.Lh=i,window.addEventListener("resize",this.Uh),window.addEventListener("pointerdown",this.Hh),window.addEventListener("pointermove",this.Bh),window.addEventListener("pointerup",this.Vh)}get resizePolicy(){return this.Lh}get signalPressed(){return this.Ws}get signalMoved(){return this.$s}get signalReleased(){return this.zs}set resizePolicy(t){this.Lh!==t&&(this.Lh=t,this.Ah=!0)}destroy(){window.removeEventListener("resize",this.Uh),window.removeEventListener("pointerdown",this.Hh),window.removeEventListener("pointermove",this.Bh),window.removeEventListener("pointerup",this.Vh)}render(t,i){(this.resizePolicy.dirty||this.Ah)&&this.Uh(),super.renderInternal(t,i)}projectWorldPosition(i,s,e=new r){return e.copy(i).project(s),e.x=t.mapLinear(e.x,-1,1,this.x,this.width),e.y=t.mapLinear(e.y,-1,1,this.y,this.height),e}projectLayerPosition(i,s,e=-1,h=new r){return h.set(t.mapLinear(i.x,this.x,this.width,-1,1),t.mapLinear(i.y,this.y,this.height,-1,1),e).unproject(s)}buildRay(i,s,e=new M){const h=new r(t.mapLinear(i.x,this.x,this.width,-1,1),t.mapLinear(i.y,this.y,this.height,-1,1),-1).unproject(s),n=new r(t.mapLinear(i.x,this.x,this.width,-1,1),t.mapLinear(i.y,this.y,this.height,-1,1),1).unproject(s).sub(h).normalize();return e.set(h,n)}Rh(t,i,s){const e=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,h=e?t.clientX-e.left:t.clientX,r=e?e.bottom-t.clientY:window.innerHeight-t.clientY,n=this.resizePolicy.calculateScale(window.innerWidth,window.innerHeight),o=h*n,a=r*n;B(this.mode)&&(s.emit({x:o,y:a,identifier:t.pointerId,layer:this}),this.inputWrapperInternal[i](o,a,t.pointerId))}}class Ss extends Pi{constructor(t,i,s){super(),this.centerX=t,this.centerY=i,this.radius=s}contains(t,i){const s=t-this.centerX,e=i-this.centerY;return this.radius*this.radius>=s*s+e*e}}class Es extends Pi{constructor(t){super(),this.vertices=t}contains(t,i){const s=this.vertices.length;if(3>s)return!1;let e=!1;for(let h=0,r=s-1;s>h;r=h++){const s=this.vertices[h],n=this.vertices[r],o=s.x,a=s.y,c=n.y;a>i!=c>i&&(n.x-o)*(i-a)/(c-a)+o>t&&(e=!e)}return e}}class Ms extends Pi{constructor(t,i,s,e,h){super(),this.x=t,this.y=i,this.width=s,this.height=e,this.radius=h,this.radius=Math.min(h,Math.min(s,e)/2)}contains(t,i){const s=this.x,e=this.x+this.width,h=this.y,r=this.y+this.height;if(s>t||t>e||h>i||i>r)return!1;const n=s+this.radius,o=e-this.radius,a=h+this.radius,c=r-this.radius;if(t>=n&&o>=t)return!0;if(i>=a&&c>=i)return!0;let l,u;l=n>t?n:o,u=a>i?a:c;const f=t-l,d=i-u;return this.radius*this.radius>=f*f+d*d}}class Cs extends Yi{constructor(t=0,i=!1){super("float calculateMask(){float aspect=p_textureResolution.x/p_textureResolution.y;vec2 p=(p_uv-0.5)*vec2(aspect,1.0);float angle=atan(p.y,p.x);angle=(angle+PI)/(2.0*PI);float adjusted=angle-p_startAngle;adjusted=p_direction>0.0 ? adjusted :-adjusted;adjusted=fract(adjusted);return step(adjusted,p_progress);}"),this.Dh=t,this.kh=i}get startAngle(){return this.Dh}get inverseDirection(){return this.kh}set startAngle(t){this.Dh!==t&&(this.Dh=t,this.dirtyInternal=!0)}set inverseDirection(t){this.kh!==t&&(this.kh=t,this.dirtyInternal=!0)}enumerateProperties(){return{direction:this.kh?-1:1,startAngle:this.Dh}}}class Ts extends xs{constructor(t,i){super(),this.Wh=t,this.$h=i}get rectWidth(){return this.Wh}get rectHeight(){return this.$h}set rectWidth(t){t!==this.Wh&&(this.Wh=t,this.dirty=!0)}set rectHeight(t){t!==this.$h&&(this.$h=t,this.dirty=!0)}calculateScale(t,i){return Math.min(this.Wh/t,this.$h/i)}}class Ps extends xs{constructor(t,i){super(),this.zh=t,this.Fh=i}get fixedWidthLandscape(){return this.zh}get fixedHeightPortrait(){return this.Fh}set fixedWidthLandscape(t){t!==this.zh&&(this.zh=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.Fh&&(this.Fh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.zh/t:this.Fh/i}}class As extends xs{constructor(t,i){super(),this.Nh=t,this.Oh=i}get fixedHeightLandscape(){return this.Nh}get fixedWidthPortrait(){return this.Oh}set fixedHeightLandscape(t){t!==this.Nh&&(this.Nh=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.Oh&&(this.Oh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.Nh/i:this.Oh/t}}class Us extends xs{constructor(t,i){super(),this.Wh=t,this.$h=i}get rectWidth(){return this.Wh}get rectHeight(){return this.$h}set rectWidth(t){t!==this.Wh&&(this.Wh=t,this.dirty=!0)}set rectHeight(t){t!==this.$h&&(this.$h=t,this.dirty=!0)}calculateScale(t,i){return Math.max(this.Wh/t,this.$h/i)}}class Hs extends xs{constructor(t,i){super(),this.Nh=t,this.Fh=i}get fixedHeightLandscape(){return this.Nh}get fixedHeightPortrait(){return this.Fh}set fixedHeightLandscape(t){t!==this.Nh&&(this.Nh=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.Fh&&(this.Fh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.Nh/i:this.Fh/i}}class Rs extends xs{constructor(t,i){super(),this.zh=t,this.Oh=i}get fixedWidthLandscape(){return this.zh}get fixedWidthPortrait(){return this.Oh}set fixedWidthLandscape(t){t!==this.zh&&(this.zh=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.Oh&&(this.Oh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.zh/t:this.Oh/t}}export{vi as UIAnchor,Di as UIAnimatedImage,Vi as UIAnimatedImageLoopMode,Ss as UIAreaCircle,Es as UIAreaPolygon,Ai as UIAreaRectangle,Ms as UIAreaRoundedRectangle,ci as UIAspectConstraint,rt as UIColor,ai as UIConstraint2DBuilder,ui as UICoverConstraintBuilder,pi as UICustomConstraint,Wt as UIExpression,di as UIFitConstraintBuilder,Is as UIFullscreenLayer,zi as UIGraphics,Qt as UIHeightConstraint,ti as UIHorizontalDistanceConstraint,ii as UIHorizontalInterpolationConstraint,si as UIHorizontalProportionConstraint,Fi as UIImage,Hi as UIInputDummy,Ti as UIMicro,gi as UIMicroAnchorMode,H as UIMode,ji as UINineSlice,Oi as UINineSliceRegionMode,R as UIOrientation,Q as UIPriority,Ji as UIProgress,Cs as UIProgressMaskFunctionCircular,Xi as UIProgressMaskFunctionDirectional,$t as UIRelation,Ts as UIResizePolicyCover,Ps as UIResizePolicyCross,As as UIResizePolicyCrossInverted,Us as UIResizePolicyFit,Hs as UIResizePolicyFixedHeight,Rs as UIResizePolicyFixedWidth,bs as UIResizePolicyNone,ts as UIScene,qi as UISceneUpdateMode,Kt as UISingleParameterConstraint,ms as UIText,fs as UITextResizeMode,_t as UITransparencyMode,ei as UIVerticalDistanceConstraint,hi as UIVerticalInterpolationConstraint,ri as UIVerticalProportionConstraint,ni as UIWidthConstraint};
|
|
2
2
|
//# sourceMappingURL=index.min.js.map
|