laymur 0.11.5 → 0.12.0

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.
Files changed (47) hide show
  1. package/README.md +33 -29
  2. package/dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts +1 -1
  3. package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +1 -1
  4. package/dist/constraints/UIConstraint.d.ts +2 -2
  5. package/dist/constraints/UICustomConstraint.d.ts +3 -3
  6. package/dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts +1 -1
  7. package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +1 -1
  8. package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +1 -1
  9. package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +1 -1
  10. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +1 -1
  11. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +1 -1
  12. package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts +1 -1
  13. package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +1 -1
  14. package/dist/constraints/{UISingleParameterConstraint.Internal.d.ts → UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts} +5 -3
  15. package/dist/constraints/{UISingleParameterConstraint.d.ts → UISingleParameterConstraint/UISingleParameterConstraint.d.ts} +5 -5
  16. package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +1 -1
  17. package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +1 -1
  18. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +1 -1
  19. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +1 -1
  20. package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts +1 -1
  21. package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +1 -1
  22. package/dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts +1 -1
  23. package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +1 -1
  24. package/dist/elements/UIAnchor/UIAnchor.d.ts +1 -1
  25. package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +15 -3
  26. package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +12 -6
  27. package/dist/elements/UIElement/UIElement.d.ts +1 -1
  28. package/dist/elements/UIGraphics/UIGraphics.d.ts +1 -1
  29. package/dist/elements/UIImage/UIImage.d.ts +1 -1
  30. package/dist/elements/UIInputDummy/UIInputDummy.d.ts +1 -1
  31. package/dist/elements/UINineSlice/UINineSlice.d.ts +10 -6
  32. package/dist/elements/UIProgress/UIProgress.d.ts +1 -1
  33. package/dist/elements/UIScene/UIScene.d.ts +1 -1
  34. package/dist/elements/UIText/UIText.d.ts +2 -2
  35. package/dist/index.d.ts +3 -2
  36. package/dist/index.js +185 -98
  37. package/dist/index.js.map +1 -1
  38. package/dist/index.min.js +1 -1
  39. package/dist/index.min.js.map +1 -1
  40. package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +9 -0
  41. package/dist/layers/{UIFullscreenLayer.d.ts → UIFullscreenLayer/UIFullscreenLayer.d.ts} +4 -8
  42. package/dist/layers/UILayer/UILayer.Internal.d.ts +29 -0
  43. package/dist/layers/{UILayer.d.ts → UILayer/UILayer.d.ts} +4 -9
  44. package/dist/miscellaneous/asserts.d.ts +1 -1
  45. package/dist/miscellaneous/shared.d.ts +1 -1
  46. package/package.json +1 -1
  47. package/dist/layers/UILayer.Internal.d.ts +0 -15
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Color as t,MathUtils 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 w,SRGBColorSpace as g,LinearFilter as y,WebGLRenderTarget as m,UnsignedByteType as _,RGBAFormat as b,PerspectiveCamera as x,Ray as S}from"three";class M{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 E{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 M(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 C,I;function T(t){return t===C.INTERACTIVE||t===C.INTERACTIVE_TRANSPARENT}function H(t){return t!==C.HIDDEN}function P(){return new A}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE",t[t.INTERACTIVE_TRANSPARENT=3]="INTERACTIVE_TRANSPARENT"})(C||(C={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(I||(I={}));class A{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 U(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 U(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 A;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 U{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new U(this.first,this.second)}}class V{constructor(t=""){this.S=t}id(){return this.C}name(){return this.S}setName(t){this.S=t}context(){return this.I}setContext(t){this.I=t}value(){return this.T}setValue(t){this.T=t}plus(t){return new R(this,t)}minus(t){return new R(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new R([t,this])}divide(t){return new R([1/t,this])}toJSON(){return{name:this.S,value:this.T}}toString(){return this.I+"["+this.S+":"+this.T+"]"}S;T=0;I=null;C=D++}let D=0;class R{constructor(){let t=(t=>{let i=0,s=()=>0,e=P();for(let h=0,r=t.length;r>h;++h){let r=t[h];if("number"==typeof r)i+=r;else if(r instanceof V)e.setDefault(r,s).second+=1;else if(r instanceof R){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 V)e.setDefault(h,s).second+=t;else{if(!(h instanceof R))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.H=t.terms,this.P=t.constant}terms(){return this.H}constant(){return this.P}value(){let t=this.P;for(let i=0,s=this.H.size();s>i;i++){let s=this.H.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new R(this,t)}minus(t){return new R(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new R([t,this])}divide(t){return new R([1/t,this])}isConstant(){return 0==this.H.size()}toString(){let t=this.H.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.P||(t+=" + "),t+=this.P,t}H;P}class B{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=B.create(1e3,1e3,1e3);static strong=B.create(1,0,0);static medium=B.create(0,1,0);static weak=B.create(0,0,1);static clip(t){return Math.max(0,Math.min(B.required,t))}}var L;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(L||(L={}));class k{constructor(t,i,s,e=B.required){this.A=i,this.U=B.clip(e),this.V=void 0===s&&t instanceof R?t:t.minus(s)}id(){return this.C}expression(){return this.V}op(){return this.A}strength(){return this.U}toString(){return this.V+" "+["<=",">=","="][this.A]+" 0 ("+this.U+")"}V;A;U;C=W++}let W=0;class z{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=B.required){let h=new k(t,i,s,e);return this.addConstraint(h),h}addConstraint(t){if(void 0!==this.D.find(t))throw Error("duplicate constraint");let i=this.R(t),s=i.row,e=i.tag,h=this.B(s,e);if(h.type()===O.Invalid&&s.allDummies()){if(!F(s.constant()))throw Error("unsatisfiable constraint");h=e.marker}if(h.type()===O.Invalid){if(!this.L(s))throw Error("unsatisfiable constraint")}else s.solveFor(h),this.W(h,s),this.F.insert(h,s);this.D.insert(t,e),this.O(this.j)}removeConstraint(t){let i=this.D.erase(t);if(void 0===i)throw Error("unknown constraint");this.N(t,i.second);let s=i.second.marker,e=this.F.erase(s);if(void 0===e){let t=this.$(s);if(t.type()===O.Invalid)throw Error("failed to find leaving row");e=this.F.erase(t),e.second.solveForEx(t,s),this.W(s,e.second)}this.O(this.j)}hasConstraint(t){return this.D.contains(t)}getConstraints(){return this.D.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.G.find(t))throw Error("duplicate edit variable");if((i=B.clip(i))===B.required)throw Error("bad required strength");let s=new R(t),e=new k(s,L.Eq,void 0,i);this.addConstraint(e);let h=this.D.find(e).second;this.G.insert(t,{tag:h,constraint:e,constant:0})}removeEditVariable(t){let i=this.G.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.G.contains(t)}suggestValue(t,i){let s=this.G.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.F,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.q();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.q();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()!==O.External&&this.Y.push(i.first)}this.q()}updateVariables(){let t=this.X,i=this.F;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.X.setDefault(t,()=>this.J(O.External)).second}R(t){let i=t.expression(),s=new $(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!F(i.second)){let t=this.Z(i.first),e=this.F.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let h=this.j,r=t.strength(),n={marker:N,other:N};switch(t.op()){case L.Le:case L.Ge:{let i=t.op()===L.Le?1:-1,e=this.J(O.Slack);if(n.marker=e,s.insertSymbol(e,i),B.required>r){let t=this.J(O.Error);n.other=t,s.insertSymbol(t,-i),h.insertSymbol(t,r)}break}case L.Eq:if(B.required>r){let t=this.J(O.Error),i=this.J(O.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(O.Dummy);n.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:n}}B(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()===O.External)return i.first}let e=i.marker.type();return e!==O.Slack&&e!==O.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==O.Slack&&e!==O.Error||t.coefficientFor(i.other)>=0?N:i.other):i.marker}L(t){let i=this.J(O.Slack);this.F.insert(i,t.copy()),this.K=t.copy(),this.O(this.K);let s=F(this.K.constant());this.K=null;let e=this.F.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let h=this.tt(t);if(h.type()===O.Invalid)return!1;t.solveForEx(i,h),this.W(h,t),this.F.insert(h,t)}let h=this.F;for(let t=0,s=h.size();s>t;++t)h.itemAt(t).second.removeSymbol(i);return this.j.removeSymbol(i),s}W(t,i){let s=this.F;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()!==O.External&&this.Y.push(h.first)}this.j.substitute(t,i),this.K&&this.K.substitute(t,i)}O(t){let i=0;for(;this.maxIterations>i;){let s=this.it(t);if(s.type()===O.Invalid)return;let e=this.st(s);if(e.type()===O.Invalid)throw Error("the objective is unbounded");let h=this.F.erase(e).second;h.solveForEx(e,s),this.W(s,h),this.F.insert(s,h),i++}throw Error("solver iterations exceeded")}q(){let t=this.F,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()===O.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()!==O.Dummy)return e}return N}et(t){let i=Number.MAX_VALUE,s=N,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()!==O.Dummy){let t=this.j.coefficientFor(r)/n;i>t&&(i=t,s=r)}}return s}st(t){let i=Number.MAX_VALUE,s=N,e=this.F;for(let h=0,r=e.size();r>h;++h){let r=e.itemAt(h),n=r.first;if(n.type()!==O.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}$(t){let i=Number.MAX_VALUE,s=i,e=i,h=N,r=h,n=h,o=h,a=this.F;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()===O.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}N(t,i){i.marker.type()===O.Error&&this.ht(i.marker,t.strength()),i.other.type()===O.Error&&this.ht(i.other,t.strength())}ht(t,i){let s=this.F.find(t);void 0!==s?this.j.insertRow(s.second,-i):this.j.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===O.Slack||e===O.Error)return s.first}return N}J(t){return new j(t,this.rt++)}D=(()=>P())();F=(()=>P())();X=(()=>P())();G=(()=>P())();Y=[];j=new $;K=null;rt=0}function F(t){return 0>t?1e-8>-t:1e-8>t}var O;(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"})(O||(O={}));class j{constructor(t,i){this.C=i,this.nt=t}id(){return this.C}type(){return this.nt}C;nt}let N=new j(O.Invalid,-1);class ${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()!==O.Dummy)return!1;return!0}copy(){let t=new $(this.P);return t.ot=this.ot.copy(),t}add(t){return this.P+=t}insertSymbol(t,i=1){F(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=P();P}const G=1e3;var Y,q;function X(t){switch(t){case Y.P0:return B.create(G,G,G);case Y.P1:return B.create(100,0,0);case Y.P2:return B.create(10,0,0);case Y.P3:return B.create(0,100,0);case Y.P4:return B.create(0,10,0);case Y.P5:return B.create(0,0,100);case Y.P6:return B.create(0,0,10);case Y.P7:return B.create(0,0,1);default:throw Error("convertPriority: 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"})(Y||(Y={}));class Z{constructor(){this.dirty=!1,this.ct=!1,this.lt=[],this.ut=0}createInputCatcher(t,i,s,e){const h=this.ut++;return this.lt.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.lt.findIndex(i=>i.handler===t);if(-1===i)throw Error("UIInputWrapper.destroyInputCatcher: handler not found");this.lt.splice(i,1)}getZIndex(t){this.ft();const i=this.lt.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getZIndex: handler not found");return i.zIndex}setZIndex(t,i){const s=this.lt.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setZIndex: handler not found");s.zIndex!==i&&(s.zIndex=i,this.ct=!0,this.dirty=!0)}getActive(t){const i=this.lt.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getActive: handler not found");return i.active}setActive(t,i){const s=this.lt.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setActive: handler not found");s.active!==i&&(s.active=i)}onPointerDown(t,i,s){this.ft();for(let e=this.lt.length-1;e>=0;e--){const h=this.lt[e];if(h.active&&h.catchPointerDown(t,i,s))break}}onPointerMove(t,i,s){this.ft();for(let e=this.lt.length-1;e>=0;e--){const h=this.lt[e];if(h.active&&h.catchPointerMove(t,i,s))break}}onPointerUp(t,i,s){this.ft();for(let e=this.lt.length-1;e>=0;e--){const h=this.lt[e];if(h.active&&h.catchPointerUp(t,i,s))break}}ft(){if(this.ct){this.lt.sort((t,i)=>t.zIndex-i.zIndex);const t=this.lt.length,i=1024>t?1:1024/t;for(let s=0;t>s;s++)this.lt[s].zIndex=s*i;this.ct=!1}}}function J(t){return.04045>t?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function K(t){return.0031308>t?12.92*t:1.055*Math.pow(t,.41666)-.055}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(q||(q={}));const Q={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 tt{constructor(...i){if(this.dt=1,this.vt=1,this.wt=1,this.gt=1,this.yt=0,this._t=0,this.bt=1,this.xt=!1,this.St=!1,this.Mt=!1,3>i.length||"number"!=typeof i[0]){if(i.length>=1&&void 0!==i[0]){const[s,e=1]=i;"string"==typeof s?s.startsWith("#")?this.setHexString(s):this.setColorName(s,e):s instanceof tt?(s.Et(),this.dt=s.dt,this.vt=s.vt,this.wt=s.wt,this.gt=s.gt):s instanceof t?(this.dt=s.r,this.vt=s.g,this.wt=s.b,this.gt=e):"number"==typeof s&&this.setHexRGB(s,e)}}else{const[t,s,e,h=1]=i;this.dt=t,this.vt=s,this.wt=e,this.gt=h}}static get black(){return new tt("black")}static get white(){return new tt("white")}static get red(){return new tt("red")}static get green(){return new tt("green")}static get blue(){return new tt("blue")}static get yellow(){return new tt("yellow")}static get cyan(){return new tt("cyan")}static get magenta(){return new tt("magenta")}static get gray(){return new tt("gray")}static get grey(){return new tt("grey")}static get silver(){return new tt("silver")}static get maroon(){return new tt("maroon")}static get olive(){return new tt("olive")}static get lime(){return new tt("lime")}static get aqua(){return new tt("aqua")}static get teal(){return new tt("teal")}static get navy(){return new tt("navy")}static get fuchsia(){return new tt("fuchsia")}static get purple(){return new tt("purple")}static get orange(){return new tt("orange")}static get pink(){return new tt("pink")}static get brown(){return new tt("brown")}static get gold(){return new tt("gold")}static get violet(){return new tt("violet")}static get indigo(){return new tt("indigo")}static get coral(){return new tt("coral")}static get salmon(){return new tt("salmon")}static get khaki(){return new tt("khaki")}static get plum(){return new tt("plum")}static get orchid(){return new tt("orchid")}static get tan(){return new tt("tan")}static get beige(){return new tt("beige")}static get mint(){return new tt("mint")}static get lavender(){return new tt("lavender")}static get crimson(){return new tt("crimson")}static get azure(){return new tt("azure")}static get ivory(){return new tt("ivory")}static get snow(){return new tt("snow")}get r(){return this.Et(),this.dt}get g(){return this.Et(),this.vt}get b(){return this.Et(),this.wt}get a(){return this.gt}get hue(){return this.Ct(),this.yt}get saturation(){return this.Ct(),this._t}get lightness(){return this.Ct(),this.bt}get dirty(){return this.xt}set r(t){t=i.clamp(t,0,1),this.Et(),t!==this.dt&&(this.dt=t,this.Mt=!0,this.xt=!0)}set g(t){t=i.clamp(t,0,1),this.Et(),t!==this.vt&&(this.vt=t,this.Mt=!0,this.xt=!0)}set b(t){t=i.clamp(t,0,1),this.Et(),t!==this.wt&&(this.wt=t,this.Mt=!0,this.xt=!0)}set a(t){(t=i.clamp(t,0,1))!==this.gt&&(this.gt=t,this.xt=!0)}set hue(t){t=i.clamp(t,0,360),this.Ct(),t!==this.yt&&(this.yt=t,this.St=!0,this.xt=!0)}set saturation(t){t=i.clamp(t,0,1),this.Ct(),t!==this._t&&(this._t=t,this.St=!0,this.xt=!0)}set lightness(t){t=i.clamp(t,0,1),this.Ct(),t!==this.bt&&(this.bt=t,this.St=!0,this.xt=!0)}setDirtyFalse(){this.xt=!1}set(t,s,e,h=this.gt){return t=i.clamp(t,0,1),s=i.clamp(s,0,1),e=i.clamp(e,0,1),h=i.clamp(h,0,1),this.Et(),t===this.dt&&s===this.vt&&e===this.wt&&h===this.gt||(this.dt=t,this.vt=s,this.wt=e,this.gt=h,this.Mt=!0,this.xt=!0),this}getHexRGBA(){return this.Et(),Math.round(255*this.dt)<<24|Math.round(255*this.vt)<<16|Math.round(255*this.wt)<<8|Math.round(255*this.gt)}getHexRGB(){return this.Et(),Math.round(255*this.dt)<<16|Math.round(255*this.vt)<<8|Math.round(255*this.wt)}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.vt&&e===this.wt&&h===this.gt||(this.dt=i,this.vt=s,this.wt=e,this.gt=h,this.Mt=!0,this.xt=!0),this}setHexRGB(t,s=this.gt){s=i.clamp(s,0,1),this.Et();const e=(t>>16&255)/255,h=(t>>8&255)/255,r=(255&t)/255;return e===this.dt&&h===this.vt&&r===this.wt&&s===this.gt||(this.dt=e,this.vt=h,this.wt=r,this.gt=s,this.Mt=!0,this.xt=!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(t,s,e,h=this.gt){return t=i.clamp(t,0,360),s=i.clamp(s,0,1),e=i.clamp(e,0,1),h=i.clamp(h,0,1),this.Ct(),t===this.yt&&s===this._t&&e===this.bt&&h===this.gt||(this.yt=t,this._t=s,this.bt=e,this.gt=h,this.St=!0,this.xt=!0),this}setColorName(t,s=this.gt){s=i.clamp(s,0,1);const e=t.toLowerCase().trim(),h=Q[e];if(void 0===h)throw Error("UIColor.setColorName.colorName: unknown color name");return this.setHexRGB(h,s)}setGLSLColor(t,s,e,h=this.gt){h=i.clamp(h,0,1),this.Et();const r=K(t),n=K(s),o=K(e);return r===this.dt&&n===this.vt&&o===this.wt&&h===this.gt||(this.dt=r,this.vt=n,this.wt=o,this.gt=h,this.Mt=!0,this.xt=!0),this}setThreeColor(t,s=this.gt){return s=i.clamp(s,0,1),this.Et(),t.r===this.dt&&t.g===this.vt&&t.b===this.wt&&s===this.gt||(this.dt=t.r,this.vt=t.g,this.wt=t.b,this.gt=s,this.Mt=!0,this.xt=!0),this}toCSSColor(){return this.Et(),`rgba(${Math.round(255*this.dt)}, ${Math.round(255*this.vt)}, ${Math.round(255*this.wt)}, ${this.gt})`}toGLSLColor(t=new s){return this.Et(),t.x=J(this.dt),t.y=J(this.vt),t.z=J(this.wt),t.w=this.gt,t}toThreeColor(i=new t){return this.Et(),i.r=this.dt,i.g=this.vt,i.b=this.wt,i}copy(t){return t instanceof tt?(this.Et(),t.Et(),this.dt===t.dt&&this.vt===t.vt&&this.wt===t.wt&&this.gt===t.gt||(this.dt=t.dt,this.vt=t.vt,this.wt=t.wt,this.gt=t.gt,this.Mt=!0,this.xt=!0)):(this.Et(),this.dt===t.r&&this.vt===t.g&&this.wt===t.b&&1===this.gt||(this.dt=t.r,this.vt=t.g,this.wt=t.b,this.gt=1,this.Mt=!0,this.xt=!0)),this}clone(){return this.Et(),new tt(this.dt,this.vt,this.wt,this.gt)}Et(){if(this.St){const{yt:t,_t: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.vt=o+c,this.wt=a+c,this.St=!1}}Ct(){if(this.Mt){const{dt:t,vt:i,wt: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._t=a,this.bt=n,this.Mt=!1}}}function it(t){if("number"==typeof t)return{glslType:"float",instantiable:!0,itemSize:1};if(t instanceof e)return{glslType:"sampler2D",instantiable:!1,itemSize:-1};if(t instanceof tt)return{glslType:"vec4",instantiable:!0,itemSize:4};if(t instanceof h)return{glslType:"vec2",instantiable:!0,itemSize:2};if(t instanceof r)return{glslType:"vec3",instantiable:!0,itemSize:3};if(t instanceof s)return{glslType:"vec4",instantiable:!0,itemSize:4};if(t instanceof n)return{glslType:"mat3",instantiable:!0,itemSize:9};if(t instanceof o)return{glslType:"mat4",instantiable:!0,itemSize:16};throw Error("resolveGLSLTypeInfo.value: unsupported property type")}function st(t,i){const s=i.uniforms["p_"+t];if(void 0===s)throw Error("resolveUniform.name: unknown uniform");return s}function et(t,i){const s=Object.keys(t),e=Object.keys(i);if(s.length!==e.length)return!1;for(const s of e){if(!(s in t))return!1;const e=it(t[s]),h=it(i[s]);if(e.glslType!==h.glslType)return!1;if(!h.instantiable&&i[s]!==t[s])return!1}return!0}function ht(t,i,s){return`\n // Defines\n #define PI 3.14159265359\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 // Source must define vec4 draw() function\n ${s}\n\n void main() {\n vec4 diffuseColor = draw();\n\n #ifdef USE_ALPHATEST\n if (diffuseColor.a < 0.50) {\n discard;\n }\n #endif\n\n #ifdef USE_ALPHAHASH\n if (diffuseColor.a < getAlphaHashThreshold(p_position)) {\n discard;\n }\n #endif\n\n gl_FragColor = linearToOutputTexel(diffuseColor);\n }\n `}const rt=(()=>{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})(),nt=new s,ot=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function at(t,i,e){if(t instanceof tt)t.toGLSLColor(nt),i[e]=nt.x,i[e+1]=nt.y,i[e+2]=nt.z,i[e+3]=nt.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 ct(t,i){const s=it(t);if(!s.instantiable)throw Error("buildEmptyInstancedBufferAttribute.value: cannot create instanced attribute for non-instantiable type");return new u(new Float32Array(i*s.itemSize),s.itemSize)}function lt(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 tt)return(new tt).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")}class ut extends f{constructor(t,i,s=q.BLEND,e=4){const h={},r={instanceVisibility:1,instanceTransform:(new o).identity()};for(const[t,s]of Object.entries(i))it(s).instantiable?r[t]=s:h[t]=s;const n=rt.clone(),a=((t,i,s,e)=>{const h={},r=[],n=[],o=[],a=[];for(const[t,s]of Object.entries(i)){const i=it(s);h["p_"+t]={value:s instanceof tt?s.toGLSLColor():s},r.push(`uniform ${i.glslType} p_${t};`)}for(const[t,i]of Object.entries(s)){const s=it(i);n.push(`attribute ${s.glslType} a_${t};`),o.push(`varying ${s.glslType} 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=ht(r,o,t);return new l({uniforms:h,vertexShader:c,fragmentShader:u,transparent:e===q.BLEND,alphaTest:e===q.CLIP?.5:0,alphaHash:e===q.HASH,depthWrite:e!==q.BLEND,depthTest:!0})})(t,h,r,s);super(n,a),this.source=t,this.transparency=s,this.It=new Map,this.Tt=new Map,this.ut=0,this.frustumCulled=!1,this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1,this.Ht=n,this.Ht.instanceCount=0,this.Pt=a,this.At=h,this.Ut=r,this.Vt=Math.max(4*Math.ceil(e/4),4);for(const[t,i]of Object.entries(this.Ut)){const s=ct(i,this.Vt);this.Ht.setAttribute("a_"+t,s),this.Tt.set(t,s)}for(const[t,i]of Object.entries(this.At))st(t,this.Pt).value=i;this.Pt.uniformsNeedUpdate=!0}get instanceCount(){return this.Ht.instanceCount}get properties(){return{...this.At,...this.Ut}}createInstance(){const t=this.ut++,i=this.Ht.instanceCount;return this.Dt(i+1),this.It.set(t,i),this.Ht.instanceCount++,this.Rt(i),t}destroyInstance(t){const i=this.Bt(t);this.It.delete(t);const s=this.Ht.instanceCount-1;s>i&&(this.Lt(s,i),this.kt(s,i)),this.Ht.instanceCount--}setProperties(t,i){const s=this.Bt(t);for(const[t,e]of Object.entries(i))if(it(e).instantiable){const i=this.Wt(t);at(e,i.array,s*i.itemSize),i.needsUpdate=!0}else st(t,this.Pt).value=e,this.Pt.uniformsNeedUpdate=!0}setTransform(t,i){const s=this.Bt(t),e=this.Wt("instanceTransform"),h=e.array,r=16*s,n=i.elements;for(let t=0;16>t;t++)h[r+t]=n[t];e.needsUpdate=!0}setVisibility(t,i){const s=this.Bt(t),e=this.Wt("instanceVisibility");e.array[s]=i?1:0,e.needsUpdate=!0}isCompatible(t,i,s=q.BLEND){return this.source===t&&this.transparency===s&&et(this.properties,i)}arePropertiesCompatible(t){return et(this.properties,t)}extractInstanceData(t){return{source:this.source,properties:this.extractProperties(t),transparency:this.transparency,transform:this.extractTransform(t),visibility:this.extractVisibility(t)}}extractProperties(t){const i=this.Bt(t),s={};for(const[t,i]of Object.entries(this.At))s[t]=i;for(const[t,e]of Object.entries(this.Ut)){const h=this.Tt.get(t);s[t]=lt(e,h.array,i*h.itemSize)}return s}extractTransform(t){const i=this.Bt(t),s=this.Tt.get("instanceTransform").array,e=new o;return e.fromArray(s,16*i),e}extractVisibility(t){const i=this.Bt(t);return this.Tt.get("instanceVisibility").array[i]>=.5}destroy(){this.Ht.dispose(),this.Pt.dispose(),this.Tt.clear(),this.It.clear()}Rt(t){const i=this.Tt.get("instanceVisibility"),s=this.Tt.get("instanceTransform");((t,i,s)=>{t[s]=1;const e=16*s;for(let t=0;16>t;t++)i[e+t]=ot[t]})(i.array,s.array,t),i.needsUpdate=!0,s.needsUpdate=!0}Dt(t){if(this.Vt>=t)return;const i=4*Math.ceil(t/4);for(const[t,s]of this.Tt.entries()){const e=s.itemSize,h=new Float32Array(i*e);h.set(s.array);const r=new u(h,e);this.Ht.setAttribute("a_"+t,r),this.Tt.set(t,r)}this.Vt=i}Lt(t,i){for(const s of this.Tt.values()){const e=s.array,h=s.itemSize,r=t*h,n=i*h;for(let t=0;h>t;t++)e[n+t]=e[r+t];s.needsUpdate=!0}}kt(t,i){for(const[s,e]of this.It)if(e===t){this.It.set(s,i);break}}Bt(t){const i=this.It.get(t);if(void 0===i)throw Error("UIGenericInstancedPlane.resolveIndex.handler: invalid handler");return i}Wt(t){const i=this.Tt.get(t);if(void 0===i)throw Error("UIGenericInstancedPlane.resolveAttribute.name: unknown attribute");return i}}const ft=new a(1,1).translate(.5,.5,0);class dt extends f{constructor(t,i,s){const e=((t,i,s)=>{const e={p_transform:{value:new o}},h=[];for(const[t,s]of Object.entries(i)){const i=it(s);e["p_"+t]={value:s instanceof tt?s.toGLSLColor():s},h.push(`uniform ${i.glslType} p_${t};`)}const r=`\n // Default uniform declarations\n uniform mat4 p_transform;\n\n // Custom uniform declarations\n ${h.join("\n")}\n\n // Default varying declarations\n varying vec3 p_position;\n varying vec2 p_uv;\n\n void main() {\n p_position = position;\n p_uv = uv;\n\n gl_Position = projectionMatrix * p_transform * vec4(position, 1.0);\n }\n `,n=ht(h,[],t);return new l({uniforms:e,vertexShader:r,fragmentShader:n,transparent:s===q.BLEND,alphaTest:s===q.CLIP?.5:0,alphaHash:s===q.HASH,depthWrite:s!==q.BLEND,depthTest:!0})})(t,i,s);super(ft,e),this.source=t,this.zt=(new o).identity(),this.frustumCulled=!1,this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1,this.Pt=e,this.Ft={...i},this.Ot=s}get properties(){return{...this.Ft}}get transform(){return this.zt}get visibility(){return this.visible}get transparency(){return this.Ot}setProperties(t){for(const[i,s]of Object.entries(t)){const t=st(i,this.Pt);s instanceof tt?s.toGLSLColor(t.value):t.value=s,this.Ft[i]=s}this.Pt.uniformsNeedUpdate=!0}setTransform(t){st("transform",this.Pt).value.copy(t),this.Pt.uniformsNeedUpdate=!0,this.zt.copy(t)}setVisibility(t){this.visible=t}setTransparency(t){this.Ot!==t&&(this.Pt.transparent=t===q.BLEND,this.Pt.alphaTest=t===q.CLIP?.5:0,this.Pt.alphaHash=t===q.HASH,this.Pt.depthWrite=t!==q.BLEND,this.Pt.needsUpdate=!0,this.Ot=t)}extractInstanceData(){return{source:this.source,properties:this.properties,transparency:this.Ot,transform:this.zt.clone(),visibility:this.visible}}isCompatible(t,i,s){return this.Ot===s&&this.source===t&&et(this.Ft,i)}arePropertiesCompatible(t){return et(this.Ft,t)}destroy(){this.Pt.dispose()}}class pt{constructor(t){this.jt=t,this.Nt=new Map,this.ut=0}create(t,i,s){const e=this.ut++,h={plane:void 0};return this.Nt.set(e,h),this.$t(h,{source:t,properties:i,transparency:s,transform:void 0,visibility:!0}),e}destroy(t){const i=this.Gt(t);this.Nt.delete(t),this.Yt(i)}setTransform(t,i){const s=this.Gt(t);s.plane instanceof ut&&void 0!==s.instanceHandler?s.plane.setTransform(s.instanceHandler,i):s.plane instanceof dt&&s.plane.setTransform(i)}setProperties(t,i){const s=this.Gt(t),e=this.qt(s),h={...e.properties,...i};this.Xt(s,e,h,e.transparency)?(this.Yt(s),this.$t(s,{...e,properties:h})):this.Zt(s,i)}setVisibility(t,i){const s=this.Gt(t);s.plane instanceof ut&&void 0!==s.instanceHandler?s.plane.setVisibility(s.instanceHandler,i):s.plane instanceof dt&&s.plane.setVisibility(i)}setTransparency(t,i){const s=this.Gt(t),e=this.qt(s);e.transparency!==i&&(this.Xt(s,e,e.properties,i)?(this.Yt(s),this.$t(s,{...e,transparency:i})):s.plane instanceof dt&&s.plane.setTransparency(i))}$t(t,i){const{source:s,properties:e,transparency:h,transform:r,visibility:n}=i,o=this.Jt(s,e,h);if(o)return void this.Kt(t,o,e,r,n);const a=this.Qt(s,e,h,t);if(a){const i=this.ti(a,e);return void this.Kt(t,i,e,r,n)}this.ii(t,s,e,h,r,n)}qt(t){return t.plane instanceof ut&&void 0!==t.instanceHandler?t.plane.extractInstanceData(t.instanceHandler):t.plane.extractInstanceData()}Yt(t){if(t.plane instanceof ut&&void 0!==t.instanceHandler){const i=t.plane;i.destroyInstance(t.instanceHandler),0===i.instanceCount?(this.jt.remove(i),i.destroy()):1===i.instanceCount&&this.si(i,t)}else t.plane instanceof dt&&(this.jt.remove(t.plane),t.plane.destroy());t.plane=void 0,delete t.instanceHandler}Zt(t,i){t.plane instanceof ut&&void 0!==t.instanceHandler?t.plane.setProperties(t.instanceHandler,i):t.plane instanceof dt&&t.plane.setProperties(i)}Xt(t,i,s,e){return t.plane instanceof ut?i.transparency!==e||!t.plane.arePropertiesCompatible(s):!!this.Jt(i.source,s,e)||!!this.Qt(i.source,s,e,t)}Kt(t,i,s,e,h){const r=i.createInstance();i.setProperties(r,s),e&&i.setTransform(r,e),i.setVisibility(r,h),t.plane=i,t.instanceHandler=r}ii(t,i,s,e,h,r){const n=new dt(i,s,e);n.setProperties(s),h&&n.setTransform(h),n.setVisibility(r),this.jt.add(n),t.plane=n,delete t.instanceHandler}Qt(t,i,s,e){for(const h of this.Nt.values())if(h!==e&&h.plane instanceof dt&&h.plane.isCompatible(t,i,s))return h}Jt(t,i,s){for(const e of this.Nt.values())if(e.plane instanceof ut&&e.plane.isCompatible(t,i,s))return e.plane}ti(t,i){const s=t.plane,e=s.extractInstanceData(),h=new ut(e.source,i,e.transparency),r=h.createInstance();return h.setProperties(r,e.properties),h.setTransform(r,e.transform),h.setVisibility(r,e.visibility),t.plane=h,t.instanceHandler=r,this.jt.remove(s),s.destroy(),this.jt.add(h),h}si(t,i){let s;for(const e of this.Nt.values())if(e!==i&&e.plane===t&&void 0!==e.instanceHandler){s=e;break}if(!s)return;const e=t.extractInstanceData(s.instanceHandler),h=new dt(e.source,e.properties,e.transparency);h.setProperties(e.properties),h.setTransform(e.transform),h.setVisibility(e.visibility),this.jt.remove(t),t.destroy(),this.jt.add(h),s.plane=h,delete s.instanceHandler}Gt(t){const i=this.Nt.get(t);if(!i)throw Error("UIGenericPlaneRegistry.resolveDescriptor.handler: descriptor not found");return i}}let vt=new t,wt=0,gt=!1,yt=!1,mt=!1,_t=!1;class bt{constructor(t,i){this.jt=new d,this.ei=new pt(this.jt),this.hi=new p(0,t,i,0,-1024,1024)}createPlane(t,i,s){return this.ei.create(t,i,s)}destroyPlane(t){this.ei.destroy(t)}setTransform(t,i){this.ei.setTransform(t,i)}setProperties(t,i){this.ei.setProperties(t,i)}setVisibility(t,i){this.ei.setVisibility(t,i)}setTransparency(t,i){this.ei.setTransparency(t,i)}insertCustomObject(t){return this.jt.add(t),this}removeCustomObject(t){return this.jt.remove(t),this}resize(t,i){return this.hi.right=t,this.hi.top=i,this.hi.updateProjectionMatrix(),this}render(t){return vt=t.getClearColor(vt),wt=t.getClearAlpha(),gt=t.autoClear,yt=t.autoClearColor,mt=t.autoClearDepth,_t=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.hi),t.setClearColor(vt),t.setClearAlpha(wt),t.autoClear=gt,t.autoClearColor=yt,t.autoClearDepth=mt,t.autoClearStencil=_t,this}}class xt{constructor(t=0,i){if(this.constant=t,this.ri=i?new Map(i):new Map,i)for(let t=0;i.length>t;t++)At()}static plus(t,i){const s=new xt(t.constant+i.constant,Array.from(t.ri.entries()));for(const[t,e]of i.ri)s.plus(t,e);return s}static minus(t,i){const s=new xt(t.constant-i.constant,Array.from(t.ri.entries()));for(const[t,e]of i.ri)s.minus(t,e);return s}plus(t,i){return this.ri.set(t,(this.ri.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this.ri)this.ri.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.ri.has(t)}copy(t){this.constant=t.constant,this.ri.clear();for(const[i,s]of t.ri)this.ri.set(i,s);return this}clone(){return new xt(this.constant,Array.from(this.ri.entries()))}prepareTerms(){return Array.from(this.ri.entries())}}var St,Mt;(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(St||(St={}));class Et{constructor(){this.dirty=!1,this.ni=new z,this.oi=!1,this.ai=new Map,this.ci=0,this.li=new Map,this.ui=0}createVariable(t,i){const s=this.ci++,e=new V;if(i===Y.P0){const h={variable:e,priority:i,value:t};this.ai.set(s,h),h.constraint=this.fi(new xt(0,[[s,1]]),new xt(t),St.EQUAL,i);try{this.ni?.addConstraint(h.constraint)}catch{this.ni=void 0}}else{this.ai.set(s,{variable:e,priority:i,value:t});try{this.ni?.addEditVariable(e,X(i)),this.ni?.suggestValue(e,t)}catch{this.ni=void 0}}return this.oi=!0,this.dirty=!0,s}removeVariable(t){const i=this.ai.get(t);if(void 0===i)throw Error("UISolverWrapper.removeVariable.index: variable does not exist");for(const i of this.li.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error("UISolverWrapper.removeVariable.index: variable is used in constraint");try{i.constraint?this.ni?.removeConstraint(i.constraint):this.ni?.removeEditVariable(i.variable)}catch{this.ni=void 0}this.ai.delete(t),this.oi=!0,this.dirty=!0}suggestVariableValue(t,i){const s=this.ai.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.di(s.constraint,(new xt).plus(t,1),new xt(s.value),St.EQUAL,s.priority):this.ni?.suggestValue(s.variable,i),this.oi=!0,this.dirty=!0)}setVariablePriority(t,i){const s=this.ai.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===Y.P0){const i=(new xt).plus(t,1),e=new xt(s.value);s.constraint=this.fi(i,e,St.EQUAL,s.priority);try{this.ni?.addConstraint(s.constraint)}catch{this.ni=void 0}}else{if(s.constraint)try{this.ni?.removeConstraint(s.constraint)}catch{this.ni=void 0}s.constraint=void 0,this.pi(t,s)}this.oi=!0,this.dirty=!0}}readVariableValue(t){const i=this.ai.get(t);if(void 0===i)throw Error("UISolverWrapper.readVariableValue.index: variable does not exist");return void 0===this.ni&&this.wi(),this.oi&&(this.ni?.updateVariables(),this.oi=!1),i.variable.value()}createConstraint(t,i,s,e,h){const r=this.ui++,n=this.fi(t,i,s,e);if(this.li.set(r,{constraint:n,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:h}),h){try{this.ni?.addConstraint(n)}catch{this.ni=void 0}this.oi=!0,this.dirty=!0}return r}removeConstraint(t){const i=this.li.get(t);if(void 0===i)throw Error("UISolverWrapper.removeConstraint.index: constraint does not exist");if(i.enabled)try{this.ni?.removeConstraint(i.constraint)}catch{this.ni=void 0}this.li.delete(t),this.oi=!0,this.dirty=!0}setConstraintLHS(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintLHS.index: constraint does not exist");s.lhs.copy(i),this.gi(s),this.oi=!0,this.dirty=!0}setConstraintRHS(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRHS.index: constraint does not exist");s.rhs.copy(i),this.gi(s),this.oi=!0,this.dirty=!0}setConstraintRelation(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRelation.index: constraint does not exist");s.relation!==i&&(s.relation=i,this.gi(s),this.oi=!0,this.dirty=!0)}setConstraintPriority(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintPriority.index: constraint does not exist");s.priority!==i&&(s.priority=i,this.gi(s),this.oi=!0,this.dirty=!0)}setConstraintEnabled(t,i){const s=this.li.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.ni?.addConstraint(s.constraint):this.ni?.removeConstraint(s.constraint)}catch{this.ni=void 0}this.oi=!0,this.dirty=!0}}pi(t,i){const s=[];for(const i of this.li.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.ni?.removeConstraint(i.constraint)}catch{this.ni=void 0}s.push(i)}this.ni?.removeEditVariable(i.variable),this.ni?.addEditVariable(i.variable,X(i.priority));for(const t of s)t.constraint=this.fi(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.ni?.addConstraint(t.constraint)}catch{this.ni=void 0;break}}gi(t){t.constraint=t.enabled?this.di(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.fi(t.lhs,t.rhs,t.relation,t.priority)}di(t,i,s,e,h){try{this.ni?.removeConstraint(t)}catch{this.ni=void 0}const r=this.fi(i,s,e,h);try{this.ni?.addConstraint(r)}catch{this.ni=void 0}return r}fi(t,i,s,e){return new k(this.yi(t),(t=>{switch(t){case St.EQUAL:return L.Eq;case St.LESS_THAN:return L.Le;case St.GREATER_THAN:return L.Ge;default:throw Error("convertRelation: invalid relation")}})(s),this.yi(i),X(e))}yi(t){return new R(...t.prepareTerms().map(([t,i])=>{const s=this.ai.get(t);if(void 0===s)throw Error("UISolverWrapper.convertExpression: variable does not exist");return[i,s.variable]}),t.constant)}wi(){if(this.ni)throw Error("UISolverWrapper.rebuildSolver: solver already exists");this.ni=new z;for(const t of this.ai.values())t.constraint?this.ni.addConstraint(t.constraint):(this.ni.addEditVariable(t.variable,X(t.priority)),this.ni.suggestValue(t.variable,t.value));for(const t of this.li.values())t.enabled&&this.ni.addConstraint(t.constraint);this.oi=!0,this.dirty=!0}}(t=>{t.ORIENTATION_CHANGED="orientation_changed",t.MODE_CHANGED="mode_changed",t.RENDERING="rendering"})(Mt||(Mt={}));class Ct extends E{constructor(t,i,s){super(),this.name="",this.inputWrapperInternal=new Z,this.mi=new Et,this._i=new bt(t,i),this.bi=s,this.xi=t>i?I.HORIZONTAL:I.VERTICAL,this.xVariable=this.mi.createVariable(0,Y.P0),this.yVariable=this.mi.createVariable(0,Y.P0),this.wVariable=this.mi.createVariable(t,Y.P0),this.hVariable=this.mi.createVariable(i,Y.P0)}get sceneWrapper(){return this._i}get solverWrapper(){return this.mi}get inputWrapper(){return this.inputWrapperInternal}get x(){return this.mi.readVariableValue(this.xVariable)}get y(){return this.mi.readVariableValue(this.yVariable)}get width(){return this.mi.readVariableValue(this.wVariable)}get height(){return this.mi.readVariableValue(this.hVariable)}get mode(){return this.bi}get orientation(){return this.xi}set mode(t){t!==this.bi&&(this.bi=t,this.emit(Mt.MODE_CHANGED,this.bi,this))}resizeInternal(t,i){this.mi.suggestVariableValue(this.wVariable,t),this.mi.suggestVariableValue(this.hVariable,i),this._i.resize(t,i);const s=t>i?I.HORIZONTAL:I.VERTICAL;s!==this.xi&&(this.xi=s,this.emit(Mt.ORIENTATION_CHANGED,this.xi,this))}renderInternal(t,i){H(this.mode)&&(this.emit(Mt.RENDERING,t,i,this),this._i.render(t)),this.mi.dirty=!1,this.inputWrapperInternal.dirty=!1}}function It(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof Ct}function Tt(t){return"object"==typeof t&&null!==t&&"xVariable"in t&&"number"==typeof t.xVariable&&"yVariable"in t&&"number"==typeof t.yVariable&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height}function Ht(t){return"object"==typeof t&&null!==t&&"wVariable"in t&&"number"==typeof t.wVariable&&"hVariable"in t&&"number"==typeof t.hVariable&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height}const Pt=1e-6;function At(){}function Ut(t,i,s){if(t instanceof Ct)return t;if(It(t))return t.layer;if(i instanceof Ct)return i;if(It(i))return i.layer;throw Error(s+": no valid subjects found")}function Vt(t,i,s){if(i instanceof Ct)return i;if(It(i))return i.layer;if(s instanceof Ct)return s;if(It(s))return s.layer;throw Error(t+": no valid subjects found")}class Dt{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.solverWrapper}}class Rt extends Dt{constructor(t,i){var s,e,h;super(t),this.Si=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.Mi=(s=i?.priority,s??Y.P0),this.Ei=(e=i?.relation,e??St.EQUAL),this.xi=(h=i?.orientation,h??I.ALWAYS),this.layer.on(Mt.ORIENTATION_CHANGED,this.Si)}get priority(){return this.Mi}get relation(){return this.Ei}get orientation(){return this.xi}set priority(t){t!==this.Mi&&(this.Mi=t,this.solverWrapper.setConstraintPriority(this.constraint,this.Mi))}set relation(t){t!==this.Ei&&(this.Ei=t,this.solverWrapper.setConstraintRelation(this.constraint,this.Ei))}set orientation(t){t!==this.xi&&(this.xi=t,this.Si())}destroy(){this.layer.off(Mt.ORIENTATION_CHANGED,this.Si),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.xi===I.ALWAYS||this.xi===this.layer.orientation}}class Bt extends Rt{constructor(t,i={}){super(t.layer,i),this.Ci=t,this.Ii=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new xt(0,[[this.Ci.hVariable,1]]),new xt(this.Ii),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.Ii}set height(t){this.Ii!==t&&(this.Ii=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(t)))}}class Lt extends Rt{constructor(t,i,s={}){super(Ut(t,i,"UIHorizontalDistanceConstraint.constructor"),s),this.Ti=t,this.Hi=i,this.Pi=s.anchorA??.5,this.Ai=s.anchorB??.5,this.Ui=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(this.Ui),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Ui}get anchorA(){return this.Pi}get anchorB(){return this.Ai}set distance(t){this.Ui!==t&&(this.Ui=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(this.Ui)))}set anchorA(t){this.Pi!==t&&(this.Pi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i;if(Ht(this.Ti))t=new xt(0,[[this.Ti.xVariable,1],[this.Ti.wVariable,this.Pi]]);else{if(!Tt(this.Ti))throw Error("UIHorizontalDistanceConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.xVariable,1)}if(Ht(this.Hi))i=new xt(0,[[this.Hi.xVariable,1],[this.Hi.wVariable,this.Ai]]);else{if(!Tt(this.Hi))throw Error("UIHorizontalDistanceConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Hi.xVariable,1)}return xt.minus(i,t)}}class kt extends Rt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Vt("UIHorizontalInterpolationConstraint.constructor",t,i),e),this.Ti=t,this.Hi=i,this.Di=s,this.Pi=h,this.Ai=h,this.Ri=e.anchorC??.5,this.Bi=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.Bi}get anchorA(){return this.Pi}get anchorB(){return this.Ai}get anchorC(){return this.Ri}set t(t){this.Bi!==t&&(this.Bi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorA(t){this.Pi!==t&&(this.Pi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorC(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i,s;if(Ht(this.Ti))t=new xt(0,[[this.Ti.xVariable,1],[this.Ti.wVariable,this.Pi]]);else{if(!Tt(this.Ti))throw Error("UIHorizontalInterpolationConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.xVariable,1)}if(Ht(this.Hi))i=new xt(0,[[this.Hi.xVariable,1],[this.Hi.wVariable,this.Ai]]);else{if(!Tt(this.Hi))throw Error("UIHorizontalInterpolationConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Hi.xVariable,1)}if(Ht(this.Di))s=new xt(0,[[this.Di.xVariable,1],[this.Di.wVariable,this.Ri]]);else{if(!Tt(this.Di))throw Error("UIHorizontalInterpolationConstraint.buildLHS.c: invalid element type");s=(new xt).plus(this.Di.xVariable,1)}const e=t.clone().multiply(1-this.Bi),h=i.clone().multiply(this.Bi);return xt.minus(xt.minus(s,e),h)}}class Wt extends Rt{constructor(t,i,s={}){super(Ut(t,i,"UIHorizontalProportionConstraint.constructor"),s),this.Ti=t,this.Hi=i,this.Li=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new xt(0),this.ki(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.Li}set proportion(t){this.Li!==t&&(this.Li=t,this.solverWrapper.setConstraintRHS(this.constraint,this.ki()))}ki(){return xt.minus(new xt(0,[[this.Ti.wVariable,this.Li]]),new xt(0,[[this.Hi.wVariable,1]]))}}class zt extends Rt{constructor(t,i,s={}){super(Ut(t,i,"UIVerticalDistanceConstraint.constructor"),s),this.Ti=t,this.Hi=i,this.Pi=s.anchorA??.5,this.Ai=s.anchorB??.5,this.Ui=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(this.Ui),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Ui}get anchorA(){return this.Pi}get anchorB(){return this.Ai}set distance(t){this.Ui!==t&&(this.Ui=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(this.Ui)))}set anchorA(t){this.Pi!==t&&(this.Pi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i;if(Ht(this.Ti))t=new xt(0,[[this.Ti.yVariable,1],[this.Ti.hVariable,this.Pi]]);else{if(!Tt(this.Ti))throw Error("UIVerticalDistanceConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.yVariable,1)}if(Ht(this.Hi))i=new xt(0,[[this.Hi.yVariable,1],[this.Hi.hVariable,this.Ai]]);else{if(!Tt(this.Hi))throw Error("UIVerticalDistanceConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Hi.yVariable,1)}return xt.minus(i,t)}}class Ft extends Rt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Vt("UIVerticalInterpolationConstraint.constructor",t,i),e),this.Ti=t,this.Hi=i,this.Di=s,this.Pi=h,this.Ai=h,this.Ri=e.anchorC??.5,this.Bi=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.Bi}get anchorA(){return this.Pi}get anchorB(){return this.Ai}get anchorC(){return this.Ri}set t(t){this.Bi!==t&&(this.Bi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorA(t){this.Pi!==t&&(this.Pi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorC(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i,s;if(Ht(this.Ti))t=new xt(0,[[this.Ti.yVariable,1],[this.Ti.hVariable,this.Pi]]);else{if(!Tt(this.Ti))throw Error("UIVerticalInterpolationConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.yVariable,1)}if(Ht(this.Hi))i=new xt(0,[[this.Hi.yVariable,1],[this.Hi.hVariable,this.Ai]]);else{if(!Tt(this.Hi))throw Error("UIVerticalInterpolationConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Hi.yVariable,1)}if(Ht(this.Di))s=new xt(0,[[this.Di.yVariable,1],[this.Di.hVariable,this.Ri]]);else{if(!Tt(this.Di))throw Error("UIVerticalInterpolationConstraint.buildLHS.c: invalid element type");s=(new xt).plus(this.Di.yVariable,1)}const e=t.clone().multiply(1-this.Bi),h=i.clone().multiply(this.Bi);return xt.minus(xt.minus(s,e),h)}}class Ot extends Rt{constructor(t,i,s={}){super(Ut(t,i,"UIVerticalProportionConstraint.constructor"),s),this.Ti=t,this.Hi=i,this.Li=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new xt(0),this.ki(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.Li}set proportion(t){this.Li!==t&&(this.Li=t,this.solverWrapper.setConstraintRHS(this.constraint,this.ki()))}ki(){return xt.minus(new xt(0,[[this.Ti.hVariable,this.Li]]),new xt(0,[[this.Hi.hVariable,1]]))}}class jt extends Rt{constructor(t,i={}){super(t.layer,i),this.Ci=t,this.Wi=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new xt(0,[[this.Ci.wVariable,1]]),new xt(this.Wi),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Wi}set width(t){this.Wi!==t&&(this.Wi=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(t)))}}function Nt(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 $t{static size(t,i={}){const s=Nt(i.size),e=Nt(i.priority),h=Nt(i.relation),r=Nt(i.orientation);return{h:new jt(t,{width:s.h,priority:e.h,relation:h.h,orientation:r.h}),v:new Bt(t,{height:s.v,priority:e.v,relation:h.v,orientation:r.v})}}static distance(t,i,s={}){const e=Nt(s.anchorA),h=Nt(s.anchorB),r=Nt(s.distance),n=Nt(s.priority),o=Nt(s.relation),a=Nt(s.orientation);return{h:new Lt(t,i,{anchorA:e.h,anchorB:h.h,distance:r.h,priority:n.h,relation:o.h,orientation:a.h}),v:new zt(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=Nt(s.proportion),h=Nt(s.priority),r=Nt(s.relation),n=Nt(s.orientation);return{h:new Wt(t,i,{proportion:e.h,priority:h.h,relation:r.h,orientation:n.h}),v:new Ot(t,i,{proportion:e.v,priority:h.v,relation:r.v,orientation:n.v})}}static interpolation(t,i,s,e={}){const h=Nt(e.anchorA),r=Nt(e.anchorB),n=Nt(e.anchorC),o=Nt(e.t),a=Nt(e.priority),c=Nt(e.relation),l=Nt(e.orientation);return{h:new kt(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 Ft(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 Gt extends Rt{constructor(t,i={}){super(t.layer,i),this.Ci=t,this.zi=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(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 xt(0,[[this.Ci.wVariable,1],[this.Ci.hVariable,-this.zi]])}}const Yt=.5;class qt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Gt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Lt(t,i,{anchorA:s.anchorH??Yt,anchorB:s.anchorH??Yt,orientation:s.orientation}),yConstraint:new zt(t,i,{anchorA:s.anchorV??Yt,anchorB:s.anchorV??Yt,orientation:s.orientation}),widthConstraint:new Wt(t,i,{proportion:1,relation:St.GREATER_THAN,orientation:s.orientation}),heightConstraint:new Ot(t,i,{proportion:1,priority:Y.P1,orientation:s.orientation})}}}const Xt=.5;class Zt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Gt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Lt(t,i,{anchorA:s.anchorH??Xt,anchorB:s.anchorH??Xt,orientation:s.orientation}),yConstraint:new zt(t,i,{anchorA:s.anchorV??Xt,anchorB:s.anchorV??Xt,orientation:s.orientation}),widthConstraint:new Wt(t,i,{proportion:1,relation:St.LESS_THAN,orientation:s.orientation}),heightConstraint:new Ot(t,i,{proportion:1,priority:Y.P1,orientation:s.orientation})}}}class Jt extends Rt{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 Kt extends E{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,Y.P7),this.yVariable=this.solverWrapper.createVariable(e,Y.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 Qt;(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(Qt||(Qt={}));const ti=.5,ii=Qt.ROTATION_SCALE,si=new r,ei=new v,hi=new r,ri=new o,ni=new r(0,0,1);function oi(t,i,s,e,h,r,n,o,a,c,l,u,f,d,p,v,w){const g=s-d-p,y=e-v-w,m=o*s*c,_=a*e*l,b=Math.cos(u),x=Math.sin(u),S=m*b-_*x,M=m*x+_*b,E=d*c,C=w*l,I=E*b-C*x,T=E*x+C*b;if(f===Qt.POSITION_ROTATION_SCALE)si.x=t+r-S+I,si.y=i+n-M+T;else{const h=a*e;si.x=t+o*s-S+r+I,si.y=i+h-M+n+T}return si.z=h,hi.x=g*c,hi.y=y*l,ei.setFromAxisAngle(ni,u),ri.compose(si,ei,hi),ri}const ai=new e;var ci;(t=>{t[t.DIMENSIONS_CHANGED=0]="DIMENSIONS_CHANGED"})(ci||(ci={}));class li extends E{constructor(t){super(),this.ji=ai,this.Ni=2,this.$i=2,this.Gi=0,this.Yi=0,this.qi=2,this.Xi=2,this.Zi=!1,this.Ji=1,this.Ki=0,this.Qi=0,this.ts=0,this.ss=0,this.es=!1,this.hs=!1,this.rs=!1,void 0!==t&&this.set(t)}get width(){return this.Ni/this.Ji}get height(){return this.$i/this.Ji}get trimmedWidth(){return(this.Zi?this.Xi:this.qi)/this.Ji}get trimmedHeight(){return(this.Zi?this.qi:this.Xi)/this.Ji}get texture(){return this.ji}get rotated(){return this.Zi}get scale(){return this.Ji}get trim(){const t=this.Ji;return{left:this.Ki/t,right:this.Qi/t,top:this.ts/t,bottom:this.ss/t}}get textureDirty(){return this.es}get uvTransformDirty(){return this.hs}get trimDirty(){return this.rs}setTextureDirtyFalse(){this.es=!1}setUVTransformDirtyFalse(){this.hs=!1}setTrimDirtyFalse(){this.rs=!1}calculateUVTransform(t=new n){const i=this.ji.image?.naturalWidth??2,s=this.ji.image?.naturalHeight??2;if(this.Zi){const e=this.qi,h=e/s;t.set(0,this.Xi/i,this.Gi/i,-h,0,(s-this.Yi-e)/s+h,0,0,1)}else t.set(this.qi/i,0,this.Gi/i,0,this.Xi/s,(s-this.Yi-this.Xi)/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.ns(t):this.cs(t),this.width===i&&this.height===s||this.emit(ci.DIMENSIONS_CHANGED,this.width,this.height,this)}ns(t){const i=t.image?.naturalWidth??2,s=t.image?.naturalHeight??2;this.Ni=i,this.$i=s,this.texture!==t&&(this.ji=t,this.es=!0),(0!==this.Gi||0!==this.Yi||this.qi!==i||this.Xi!==s||1!==this.Ji||this.Zi)&&(this.Gi=0,this.Yi=0,this.qi=i,this.Xi=s,this.Zi=!1,this.Ji=1,this.hs=!0),0===this.Ki&&0===this.Qi&&0===this.ts&&0===this.ss||(this.Ki=0,this.Qi=0,this.ts=0,this.ss=0,this.rs=!0)}cs(t){this.Ni=t.sourceSize.w,this.$i=t.sourceSize.h,this.texture!==t.texture&&(this.ji=t.texture,this.es=!0);const i=t.scale??1,s=t.rotated??!1;0===this.Gi&&0===this.Yi&&this.qi===t.frame.w&&this.Xi===t.frame.h&&this.Ji===i&&this.Zi===s||(this.Gi=t.frame.x,this.Yi=t.frame.y,this.qi=t.frame.w,this.Xi=t.frame.h,this.Ji=i,this.Zi=s,this.hs=!0);const e=t.spriteSourceSize,h=e.x,r=e.y,n=this.Ni-e.x-e.w,o=this.$i-e.y-e.h;this.Ki===h&&this.Qi===n&&this.ts===r&&this.ss===o||(this.Ki=h,this.Qi=n,this.ts=r,this.ss=o,this.rs=!0)}}var ui,fi="vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;return texture2D(p_texture,transformedUV)*p_color;}";class di{constructor(t){this.xt=!0,this.ls=t?.x??0,this.us=t?.y??0,this.fs=t?.anchorX??ti,this.ds=t?.anchorY??ti,this.ps=t?.scaleX??1,this.vs=t?.scaleY??1,this.ws=t?.rotation??0,this.gs=t?.anchorMode??ii}get x(){return this.ls}get y(){return this.us}get anchorX(){return this.fs}get anchorY(){return this.ds}get scaleX(){return this.ps}get scaleY(){return this.vs}get angle(){return i.radToDeg(this.ws)}get anchorMode(){return this.gs}get rotation(){return this.ws}get dirty(){return this.xt}set x(t){t!==this.ls&&(this.ls=t,this.xt=!0)}set y(t){t!==this.us&&(this.us=t,this.xt=!0)}set anchorX(t){t!==this.fs&&(this.fs=t,this.xt=!0)}set anchorY(t){t!==this.ds&&(this.ds=t,this.xt=!0)}set scaleX(t){t!==this.ps&&(this.ps=t,this.xt=!0)}set scaleY(t){t!==this.vs&&(this.vs=t,this.xt=!0)}set angle(t){const s=i.degToRad(t);s!==this.ws&&(this.ws=s,this.xt=!0)}set rotation(t){t!==this.ws&&(this.ws=t,this.xt=!0)}set anchorMode(t){t!==this.gs&&(this.gs=t,this.xt=!0)}setDirtyFalse(){this.xt=!1}reset(){0===this.ls&&0===this.us&&this.fs===ti&&this.ds===ti&&1===this.ps&&1===this.vs&&0===this.ws||(this.ls=0,this.us=0,this.fs=ti,this.ds=ti,this.ps=1,this.vs=1,this.ws=0,this.xt=!0)}copy(t){this.ls===t.ls&&this.us===t.us&&this.fs===t.fs&&this.ds===t.ds&&this.ps===t.ps&&this.vs===t.vs&&this.ws===t.ws&&this.gs===t.gs||(this.ls=t.ls,this.us=t.us,this.fs=t.fs,this.ds=t.ds,this.ps=t.ps,this.vs=t.vs,this.ws=t.ws,this.gs=t.gs,this.xt=!0)}}class pi{}class vi 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)}}(t=>{t.PRESSED="pointerdown",t.MOVED="pointermove",t.RELEASED="pointerup",t.ENTERED="pointerenter",t.LEFT="pointerleave"})(ui||(ui={}));const wi=C.VISIBLE;class gi extends Kt{constructor(t,i){const s=i?.width??64,e=i?.height??32;super(t,i),this.ys=!1,this.catchPointerDown=(t,i,s)=>this.handleInputEvent(t,i,s,ui.PRESSED),this.catchPointerMove=(t,i,s)=>this.handleInputEvent(t,i,s,ui.MOVED),this.catchPointerUp=(t,i,s)=>this.handleInputEvent(t,i,s,ui.RELEASED),this.interactionArea=i?.interactionArea??new vi(0,0,1,1),this.modeInternal=i?.mode??wi,this.inputWrapper=this.layer.inputWrapper,this.wVariable=this.solverWrapper.createVariable(s,Y.P6),this.hVariable=this.solverWrapper.createVariable(e,Y.P6),this._s=this.inputWrapper.createInputCatcher(this.catchPointerDown,this.catchPointerMove,this.catchPointerUp,0),this.inputWrapper.setActive(this._s,T(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=T(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(t,s,e,h){const r=this.interactionArea.contains(i.mapLinear(t,this.x,this.oppositeX,0,1),i.mapLinear(s,this.y,this.oppositeY,0,1));return r&&this.emit(h,t,s,e,this),this.ys&&!r?this.emit(ui.LEFT,t,s,e,this):!this.ys&&r&&this.emit(ui.ENTERED,t,s,e,this),this.ys=r,this.modeInternal!==C.INTERACTIVE_TRANSPARENT&&r}}const yi=q.BLEND;class mi extends gi{constructor(t,i,s,e){super(t,e),this.bs=!1,this.xs=!1,this.micro=new di(e?.micro),this.Ss=e?.transparencyMode??yi,this.sceneWrapper=this.layer.sceneWrapper,this.planeHandler=this.sceneWrapper.createPlane(i,s,this.Ss),void 0===e?.mode||H(e.mode)||(this.xs=!0),this.layer.on(Mt.RENDERING,this.onWillRender,this)}get transparencyMode(){return this.Ss}set transparencyMode(t){this.Ss!==t&&(this.Ss=t,this.bs=!0)}set mode(t){this.modeInternal!==t&&(this.xs=H(this.modeInternal)!==H(t),super.mode=t)}destroy(){this.layer.off(Mt.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,l,u,f)=>{const d=s*this.micro.scaleX,p=e*this.micro.scaleY,v=o*d,w=a*p,g=Math.cos(u),y=Math.sin(u),m=v*g-w*y,_=v*y+w*g;if(f===Qt.POSITION_ROTATION_SCALE)si.x=t+r-m,si.y=i+n-_;else{const h=a*e;si.x=t+o*s-m+r,si.y=i+h-_+n}return si.z=h,hi.x=d,hi.y=p,ei.setFromAxisAngle(ni,u),ri.compose(si,ei,hi),ri})(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.bs&&(this.sceneWrapper.setTransparency(this.planeHandler,this.Ss),this.bs=!1),this.xs&&(this.sceneWrapper.setVisibility(this.planeHandler,H(this.modeInternal)),this.xs=!1),this.setPlaneTransform()}}var _i,bi;(t=>{t[t.PLAYED=0]="PLAYED",t[t.PAUSED=1]="PAUSED",t[t.STOPPED=2]="STOPPED"})(_i||(_i={}));class xi extends mi{constructor(t,i,s={}){const e=new tt(s.color),h=i.map(t=>new li(t)),r=h[0];s.width=s.width??r.width,s.height=s.height??r.height;const n=r.calculateUVTransform();super(t,fi,{texture:r.texture,textureTransform:n,color:e},s),this.Ms=!1,this.Es=0,this.Cs=!1,this.Is=0,this.Ts=(t,i,s)=>{this.Hs[this.Es]===s&&(this.width=t,this.height=i)},this.Hs=h,this.Ps=n,this.As=s.frameRate??24,this.Us=s.loop??!0,this.color=e,this.Vs(),!0===s.playByDefault&&this.play()}get sequence(){return this.Hs}get frameRate(){return this.As}get loop(){return this.Us}get duration(){return this.Hs.length/this.As}set sequence(t){this.stop(),this.Ds();const i=t.length,s=this.Hs.length;for(let e=0;Math.min(i,s)>e;e++)this.Hs[e].set(t[e]);if(s>i)this.Hs.length=i;else if(i>s)for(let e=s;i>e;e++)this.Hs.push(new li(t[e]));this.Vs()}set frameRate(t){this.As=t}set loop(t){this.Us=t}destroy(){this.Ds(),super.destroy()}play(){this.Ms||(this.Ms=!0,this.emit(_i.PLAYED))}pause(){this.Ms&&(this.Ms=!1,this.emit(_i.PAUSED))}stop(){(this.Ms||this.Is>0||this.Es>0)&&(this.Ms=!1,this.Is=0,this.Es=0,this.Cs=!0,this.emit(_i.STOPPED))}onWillRender(t,i){if(this.Ms){this.Is+=i;const t=1/this.As;for(;this.Is>=t;){if(this.Is-=t,this.Es+=1,this.Us)this.Es%=this.Hs.length;else if(this.Es>=this.Hs.length){this.Es=this.Hs.length-1,this.Ms=!1,this.emit(_i.PAUSED);break}this.Cs=!0}}super.onWillRender(t,i)}setPlaneTransform(){let t;this.color.dirty&&(t??(t={}),t.color=this.color,this.color.setDirtyFalse());const i=this.Hs[this.Es];if((i.textureDirty||this.Cs)&&(t??(t={}),t.texture=i.texture,i.setTextureDirtyFalse()),(i.uvTransformDirty||this.Cs)&&(t??(t={}),t.textureTransform=i.calculateUVTransform(this.Ps),i.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.Cs||this.micro.dirty||i.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,s=i.trim;this.sceneWrapper.setTransform(this.planeHandler,oi(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.Cs=!1,this.micro.setDirtyFalse(),i.setTrimDirtyFalse()}}Vs(){for(const t of this.Hs)t.on(ci.DIMENSIONS_CHANGED,this.Ts)}Ds(){for(const t of this.Hs)t.off(ci.DIMENSIONS_CHANGED,this.Ts)}}class Si extends mi{constructor(t,i){const s=i?.width??64,e=i?.height??32,h=new tt(i?.color),r=new OffscreenCanvas(s,e),n=r.getContext("2d");if(!n)throw Error("UIGraphics.constructor: failed to get 2D context from OffscreenCanvas");const o=new w(r);o.colorSpace=g,o.minFilter=y,o.magFilter=y,o.needsUpdate=!0,super(t,fi,{texture:o,textureTransform:o.matrix,color:h},i),this.Rs=r,this.Bs=n,this.Ls=o,this.color=h}clear(t){return this.Bs.clearRect(0,0,this.Rs.width,this.Rs.height),void 0!==t&&(this.Bs.fillStyle=t.toCSSColor(),this.Bs.fillRect(0,0,this.Rs.width,this.Rs.height)),this.Ls.needsUpdate=!0,this}drawRect(t,i,s,e,h){return this.Bs.fillStyle=h.toCSSColor(),this.Bs.fillRect(t,i,s,e),this.Ls.needsUpdate=!0,this}drawCircle(t,i,s,e){return this.Bs.fillStyle=e.toCSSColor(),this.Bs.beginPath(),this.Bs.arc(t,i,s,0,2*Math.PI),this.Bs.fill(),this.Ls.needsUpdate=!0,this}drawArc(t,i,s,e,h,r){return this.Bs.fillStyle=r.toCSSColor(),this.Bs.beginPath(),this.Bs.arc(t,i,s,e,h),this.Bs.fill(),this.Ls.needsUpdate=!0,this}drawPolyline(t,i,s=1){if(2>t.length)return this;this.Bs.strokeStyle=i.toCSSColor(),this.Bs.lineWidth=s,this.Bs.beginPath(),this.Bs.moveTo(t[0][0],t[0][1]);for(let i=1;t.length>i;i++)this.Bs.lineTo(t[i][0],t[i][1]);return this.Bs.stroke(),this.Ls.needsUpdate=!0,this}destroy(){this.Ls.dispose(),super.destroy()}onWillRender(t,i){this.color.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.color}),this.color.setDirtyFalse()),super.onWillRender(t,i)}}class Mi extends mi{constructor(t,i,s={}){const e=new tt(s.color),h=new li(i),r=h.calculateUVTransform();s.width=s.width??h.width,s.height=s.height??h.height,super(t,fi,{texture:h.texture,textureTransform:r,color:e},s),this.Ts=(t,i)=>{this.width=t,this.height=i},this.texture=h,this.Ps=r,this.color=e,this.texture.on(ci.DIMENSIONS_CHANGED,this.Ts)}destroy(){this.texture.off(ci.DIMENSIONS_CHANGED,this.Ts),super.destroy()}setPlaneTransform(){let t;if(this.color.dirty&&(t??(t={}),t.color=this.color,this.color.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.Ps),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,oi(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 Ei{constructor(t){if(this.xt=!1,void 0===t)this.bt=0,this.dt=0,this.Bi=0,this.wt=0;else if("number"==typeof t)this.bt=t,this.dt=t,this.Bi=t,this.wt=t;else if("left"in t){const i=t.right,s=t.top,e=t.bottom;this.bt=t.left,this.dt=i,this.Bi=s,this.wt=e}else{const i=t.horizontal,s=t.vertical;this.bt=i,this.dt=i,this.Bi=s,this.wt=s}}get left(){return this.bt}get right(){return this.dt}get top(){return this.Bi}get bottom(){return this.wt}get dirty(){return this.xt}set left(t){this.bt!==t&&(this.bt=t,this.xt=!0)}set right(t){this.dt!==t&&(this.dt=t,this.xt=!0)}set top(t){this.Bi!==t&&(this.Bi=t,this.xt=!0)}set bottom(t){this.wt!==t&&(this.wt=t,this.xt=!0)}setHorizontal(t){this.bt===t&&this.dt===t||(this.bt=t,this.dt=t,this.xt=!0)}setVertical(t){this.Bi===t&&this.wt===t||(this.Bi=t,this.wt=t,this.xt=!0)}setUnified(t){this.bt===t&&this.dt===t&&this.Bi===t&&this.wt===t||(this.bt=t,this.dt=t,this.Bi=t,this.wt=t,this.xt=!0)}setVector4(t){this.bt===t.x&&this.dt===t.y&&this.Bi===t.z&&this.wt===t.w||(this.bt=t.x,this.dt=t.y,this.Bi=t.z,this.wt=t.w,this.xt=!0)}toVector4(t=new s){return t.set(this.bt,this.dt,this.Bi,this.wt)}reset(){this.setUnified(0)}copy(t){this.bt===t.bt&&this.dt===t.dt&&this.Bi===t.Bi&&this.wt===t.wt||(this.bt=t.bt,this.dt=t.dt,this.Bi=t.Bi,this.wt=t.wt,this.xt=!0)}setDirtyFalse(){this.xt=!1}}(t=>{t[t.NORMALIZED=0]="NORMALIZED",t[t.WORLD=1]="WORLD"})(bi||(bi={}));const Ci=bi.WORLD;class Ii extends mi{constructor(t,i,e={}){const h=new tt(e.color),r=new li(i),n=r.calculateUVTransform();e.width=e.width??r.width,e.height=e.height??r.height;const o=new Ei(e.sliceBorders??.1),a=new Ei(e.sliceRegions??.1),c=e.regionMode??Ci,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 texture2D(p_texture,transformedUV)*p_color;}",{texture:r.texture,textureTransform:n,color:h,sliceBorders:l,sliceRegions:u},e),this.ks=!1,this.Ws=new s,this.zs=new s,this.texture=r,this.Ps=n,this.color=h,this.sliceBorders=o,this.sliceRegions=a,this.Fs=c,this.Ws=l,this.zs=u,this.Os=this.width,this.js=this.height}get regionMode(){return this.Fs}set regionMode(t){this.Fs!==t&&(this.Fs=t,this.ks=!0)}setPlaneTransform(){if((this.ks||this.texture.textureDirty||this.texture.uvTransformDirty||this.texture.trimDirty||this.color.dirty||this.sliceBorders.dirty||this.sliceRegions.dirty||this.Fs===bi.WORLD&&this.Ns())&&(this.$s(this.Ws),this.Gs(this.zs),this.sceneWrapper.setProperties(this.planeHandler,{texture:this.texture.texture,textureTransform:this.texture.calculateUVTransform(this.Ps),color:this.color,sliceBorders:this.Ws,sliceRegions:this.zs}),this.ks=!1,this.color.setDirtyFalse(),this.sliceBorders.setDirtyFalse(),this.sliceRegions.setDirtyFalse(),this.Ys()),this.texture.textureDirty||this.texture.uvTransformDirty||this.texture.trimDirty||this.micro.dirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.texture.trim,i=this.micro;this.sceneWrapper.setTransform(this.planeHandler,oi(this.x,this.y,this.width,this.height,this.zIndex,i.x,i.y,i.anchorX,i.anchorY,i.scaleX,i.scaleY,i.rotation,i.anchorMode,t.left,t.right,t.top,t.bottom)),this.texture.setTextureDirtyFalse(),this.texture.setUVTransformDirtyFalse(),this.texture.setTrimDirtyFalse(),this.micro.setDirtyFalse()}}$s(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.sliceBorders.right,l=this.sliceBorders.top,u=this.sliceBorders.bottom,f=Math.max(0,this.sliceBorders.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))}Gs(t){if(this.Fs===bi.NORMALIZED)return t.set(this.sliceRegions.left,this.sliceRegions.right,this.sliceRegions.top,this.sliceRegions.bottom);const i=this.width,s=this.height;return t.set(this.sliceRegions.left/i,this.sliceRegions.right/i,this.sliceRegions.top/s,this.sliceRegions.bottom/s)}Ns(){return this.solverWrapper.dirty&&(this.Os!==Math.round(this.width)||this.js!==Math.round(this.height))}Ys(){this.Os=Math.round(this.width),this.js=Math.round(this.height)}}class Ti{constructor(t){this.source=t,this.dirtyInternal=!1}get dirty(){return this.dirtyInternal}setDirtyFalse(){this.dirtyInternal=!1}}class Hi extends Ti{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.qs=new h,this.direction.copy(t).normalize(),this.qs.copy(this.direction)}get dirty(){return this.Xs(),this.dirtyInternal||!this.qs.equals(this.direction)}setDirtyFalse(){this.Xs(),this.qs.copy(this.direction),super.setDirtyFalse()}enumerateProperties(){return this.Xs(),{direction:this.direction}}Xs(){const t=this.direction.lengthSq();Math.abs(t)>Pt?Math.abs(t-1)>Pt&&this.direction.divideScalar(t):this.direction.set(1,0)}}class Pi extends mi{constructor(t,s,e={}){const h=new tt(e.color),r=new li(s),n=r.calculateUVTransform(),o=r.getResolution();e.width=e.width??r.width,e.height=e.height??r.height;const a=i.clamp(e.progress??1,0,1),c=e.maskFunction??new Hi;super(t,c.source+"vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=texture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}",{texture:r.texture,textureTransform:n,textureResolution:o,color:h,progress:a,...c.enumerateProperties()},e),this.Zs=!1,this.Js=!1,this.Ts=(t,i)=>{this.width===t&&this.height===i||(this.width=t,this.height=i,this.Js=!0)},this.texture=r,this.Ps=n,this.Ks=o,this.color=h,this.Qs=a,this.maskFunction=c,this.texture.on(ci.DIMENSIONS_CHANGED,this.Ts)}get progress(){return this.Qs}set progress(t){t=i.clamp(t,0,1),this.Qs!==t&&(this.Qs=t,this.Zs=!0)}setPlaneTransform(){let t;if(this.color.dirty&&(t??(t={}),t.color=this.color,this.color.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.Ps),this.texture.setUVTransformDirtyFalse()),this.Zs&&(t??(t={}),t.progress=this.Qs,this.Zs=!1),this.Js&&(t??(t={}),t.textureResolution=this.texture.getResolution(this.Ks),this.Js=!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,oi(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()}}}var Ai;(t=>{t[t.EACH_FRAME=1]="EACH_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"})(Ai||(Ai={}));const Ui=Ai.ON_PROPERTIES_CHANGE,Vi=new tt(0,0,0,1);class Di extends mi{constructor(t,s={}){const e=i.clamp(s.resolutionFactor??.5,.1,2),h=s.width??64,r=s.height??32,o=new m(h*e,r*e,{format:b,minFilter:y,magFilter:y,type:_,depthBuffer:s.enableDepthBuffer??!0,stencilBuffer:!1}),a=new tt(s.color);super(t,fi,{texture:o.texture,textureTransform:new n,color:a},s),this.te=!0,this.ie=!1,this.se=!1,this.ee=!1,this.color=a,this.clearColor=new tt(s.clearColor??Vi),this.he=o,this.re=s.scene??new d,this.ne=s.camera??new x(60,h/r,.1,100),this.oe=e,this.ae=s.updateMode??Ui,this.ee=s.updateMode!==Ai.MANUAL}get scene(){return this.re}get camera(){return this.ne}get updateMode(){return this.ae}get resolutionFactor(){return this.oe}set scene(t){this.re!==t&&(this.re=t,this.ee=!0)}set camera(t){this.ne!==t&&(this.ne=t,this.ee=!0)}set updateMode(t){this.ae!==t&&(this.ae=t,this.ee=!0)}set resolutionFactor(t){t=i.clamp(t,.1,2),this.oe!==t&&(this.oe=t,this.se=!0)}destroy(){this.he.dispose(),super.destroy()}requestUpdate(){this.ie=!0}onWillRender(t,i){this.te=!this.te,(this.ie||this.ae===Ai.EACH_FRAME||this.ae===Ai.EVERY_SECOND_FRAME&&this.te||this.ae===Ai.ON_PROPERTIES_CHANGE&&this.ee||this.color.dirty||this.clearColor.dirty||this.ae===Ai.ON_DIMENSIONS_CHANGE&&(this.se||this.solverWrapper.dirty))&&((this.se||this.solverWrapper.dirty)&&(this.he.setSize(this.width*this.oe,this.height*this.oe),this.se=!1),this.color.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.color}),this.color.setDirtyFalse()),t.setClearColor(this.clearColor.getHexRGB(),this.clearColor.a),t.setRenderTarget(this.he),t.clear(!0,!0,!1),t.render(this.re,this.ne),this.ee=!1,this.ie=!1),super.onWillRender(t,i)}}const Ri="#000000",Bi="left",Li="Arial",ki="normal",Wi="normal",zi=!1,Fi="transparent",Oi=!1,ji="#000000";class Ni{constructor(t){this.xt=!0,this.ce=t?.color,this.le=t?.align,this.ue=t?.fontFamily,this.fe=t?.fontSize,this.de=t?.fontStyle,this.pe=t?.fontWeight,this.ve=t?.lineHeight,this.we=t?.enableShadow,this.ge=t?.shadowOffsetX,this.ye=t?.shadowOffsetY,this.me=t?.shadowBlur,this._e=t?.shadowColor,this.be=t?.enableStroke,this.xe=t?.strokeColor,this.Se=t?.strokeThickness}get color(){return this.ce}get align(){return this.le}get fontFamily(){return this.ue}get fontSize(){return this.fe}get fontStyle(){return this.de}get fontWeight(){return this.pe}get lineHeight(){return this.ve}get enableShadow(){return this.we}get shadowOffsetX(){return this.ge}get shadowOffsetY(){return this.ye}get shadowBlur(){return this.me}get shadowColor(){return this._e}get enableStroke(){return this.be}get strokeColor(){return this.xe}get strokeThickness(){return this.Se}get dirty(){return this.xt}set color(t){t!==this.ce&&(this.ce=t,this.xt=!0)}set align(t){t!==this.le&&(this.le=t,this.xt=!0)}set fontFamily(t){t!==this.ue&&(this.ue=t,this.xt=!0)}set fontSize(t){t!==this.fe&&(this.fe=t,this.xt=!0)}set fontStyle(t){t!==this.de&&(this.de=t,this.xt=!0)}set fontWeight(t){t!==this.pe&&(this.pe=t,this.xt=!0)}set lineHeight(t){t!==this.ve&&(this.ve=t,this.xt=!0)}set enableShadow(t){t!==this.we&&(this.we=t,this.xt=!0)}set shadowOffsetX(t){t!==this.ge&&(this.ge=t,this.xt=!0)}set shadowOffsetY(t){t!==this.ye&&(this.ye=t,this.xt=!0)}set shadowBlur(t){t!==this.me&&(this.me=t,this.xt=!0)}set shadowColor(t){t!==this._e&&(this._e=t,this.xt=!0)}set enableStroke(t){t!==this.be&&(this.be=t,this.xt=!0)}set strokeColor(t){t!==this.xe&&(this.xe=t,this.xt=!0)}set strokeThickness(t){t!==this.Se&&(this.Se=t,this.xt=!0)}static resolve(t,i){const s=t.fe??i.fe??16;return{color:t.ce??i.ce??Ri,align:t.le??i.le??Bi,fontFamily:t.ue??i.ue??Li,fontSize:s,fontStyle:t.de??i.de??ki,fontWeight:t.pe??i.pe??Wi,lineHeight:t.ve??i.ve??1.2*s,enableShadow:t.we??i.we??zi,shadowOffsetX:t.ge??i.ge??0,shadowOffsetY:t.ye??i.ye??0,shadowBlur:t.me??i.me??0,shadowColor:t._e??i._e??Fi,enableStroke:t.be??i.be??Oi,strokeColor:t.xe??i.xe??ji,strokeThickness:t.Se??i.Se??0}}setDirtyFalse(){this.xt=!1}setDefaults(){this.ce===Ri&&this.le===Bi&&this.ue===Li&&16===this.fe&&this.de===ki&&this.pe===Wi&&19.2===this.ve&&this.we===zi&&0===this.ge&&0===this.ye&&0===this.me&&this._e===Fi&&this.be===Oi&&this.xe===ji&&0===this.Se||(this.ce=Ri,this.le=Bi,this.ue=Li,this.fe=16,this.de=ki,this.pe=Wi,this.ve=19.2,this.we=zi,this.ge=0,this.ye=0,this.me=0,this._e=Fi,this.be=Oi,this.xe=ji,this.Se=0,this.xt=!0)}clear(){void 0===this.ce&&void 0===this.le&&void 0===this.ue&&void 0===this.fe&&void 0===this.de&&void 0===this.pe&&void 0===this.ve&&void 0===this.we&&void 0===this.ge&&void 0===this.ye&&void 0===this.me&&void 0===this._e&&void 0===this.be&&void 0===this.xe&&void 0===this.Se||(this.ce=void 0,this.le=void 0,this.ue=void 0,this.fe=void 0,this.de=void 0,this.pe=void 0,this.ve=void 0,this.we=void 0,this.ge=void 0,this.ye=void 0,this.me=void 0,this._e=void 0,this.be=void 0,this.xe=void 0,this.Se=void 0,this.xt=!0)}copy(t){this.ce===t.ce&&this.le===t.le&&this.ue===t.ue&&this.fe===t.fe&&this.de===t.de&&this.pe===t.pe&&this.ve===t.ve&&this.we===t.we&&this.ge===t.ge&&this.ye===t.ye&&this.me===t.me&&this._e===t._e&&this.be===t.be&&this.xe===t.xe&&this.Se===t.Se||(this.ce=t.ce,this.le=t.le,this.ue=t.ue,this.fe=t.fe,this.de=t.de,this.pe=t.pe,this.ve=t.ve,this.we=t.we,this.ge=t.ge,this.ye=t.ye,this.me=t.me,this._e=t._e,this.be=t.be,this.xe=t.xe,this.Se=t.Se,this.xt=!0)}calculatePadding(){let t=0;if(void 0!==this.be&&(t+=this.Se??0),void 0!==this.we){const i=this.ye??0,s=2*(this.me??0);t+=Math.max(Math.abs(this.ge??0)+s,Math.abs(i)+s)}return Math.ceil(t)}}class $i{constructor(t){this.xt=!0,this.Me=t.text,this.style=new Ni(t.style)}get text(){return this.Me}get dirty(){return this.xt||this.style.dirty}set text(t){t!==this.Me&&(this.Me=t,this.xt=!0)}setDirtyFalse(){this.xt=!1,this.style.setDirtyFalse()}}var Gi;(t=>{t[t.BREAK=0]="BREAK",t[t.SCALE=1]="SCALE"})(Gi||(Gi={}));const Yi=Gi.SCALE;function qi(t){return t.match(/\S+|\s|\n/g)??[]}function Xi(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 Zi(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 Ji(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 Ki(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??Bi,a=n.chunks.every(t=>t.style.align===o)?o:Bi;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)Ji(l,h,t.text,t.style,e),l+=t.metrics.width}}class Qi extends mi{constructor(t,i,s={}){const e=new OffscreenCanvas(2,2),h=e.getContext("2d");if(!h)throw Error("UIText.constructor: failed to create canvas context");const r=new w(e);r.colorSpace=g,r.needsUpdate=!0;const o=new tt(s.color);switch(super(t,fi,{texture:r,textureTransform:new n,color:o}),this.Ee=[],this.Ce=!1,this.Ie=!1,this.Te=!1,this.He=[],this.Pe=!1,this.color=o,this.padding=new Ei(s.padding),this.commonStyle=new Ni(s.commonStyle),this.Ae=s.maxLineWidth??1024,this.Ue=s.resizeMode??Yi,this.Rs=e,this.Bs=h,this.Ls=r,this.content=i,this.Os=this.width,this.js=this.height,void 0===s.padding&&this.padding.setUnified(this.content.reduce((t,i)=>Math.max(t,i.style.calculatePadding()),this.commonStyle.calculatePadding())),this.Ue){case Gi.SCALE:this.Ve();break;case Gi.BREAK:this.De()}}get content(){return this.Ee}get maxLineWidth(){return this.Ae}get resizeMode(){return this.Ue}set content(t){this.Ee!==t&&(this.Ee="string"==typeof t?[new $i({text:t,style:new Ni})]:Array.isArray(t)?t.map(t=>new $i("string"==typeof t?{text:t,style:new Ni}:{text:t.text,style:new Ni(t.style)})):[new $i({text:t.text,style:new Ni(t.style)})],this.Ce=!0,this.Pe=!0)}set maxLineWidth(t){this.Ae!==t&&(this.Ae=t,this.Ie=!0)}set resizeMode(t){this.Ue!==t&&(this.Ue=t,this.Te=!0)}destroy(){this.Ls.dispose(),super.destroy()}onWillRender(t,i){switch(this.color.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.color}),this.color.setDirtyFalse()),this.Ue){case Gi.SCALE:this.Ve();break;case Gi.BREAK:this.De()}super.onWillRender(t,i)}Ve(){if(!(this.Te||this.Ie||this.padding.dirty||this.solverWrapper.dirty&&this.Os/this.js!==Math.round(this.width)/Math.round(this.height)||this.Re()))return;const t=this.Be(),{lines:i,size:s}=Zi(t,this.Ae),e=s.height+(this.padding.top+this.padding.bottom),h=s.width+(this.padding.left+this.padding.right);this.width=h,this.height=e/h*Math.round(this.width),this.width=h/e*Math.round(this.height);const r=this.Os!==e||this.js!==h;r&&(this.Rs.height=e,this.Rs.width=h),Ki(this.padding.top,this.padding.left,i,this.Bs),r&&this.ke(),this.Te=!1,this.Ie=!1,this.padding.setDirtyFalse(),this.Ys(),this.We()}De(){if(!(this.Te||this.Ie||this.padding.dirty||this.Ns()||this.Re()))return;const t=this.Be(),{size:i}=Zi(t,this.Ae),s=this.padding.top+this.padding.bottom,e=this.padding.left+this.padding.right;this.height=i.height+s,this.width=i.width+e;const{lines:h,size:r}=Zi(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.Os!==n||this.js!==o;a&&(this.Rs.width=n,this.Rs.height=o),Ki(this.padding.top,this.padding.left,h,this.Bs),a&&this.ke(),this.Te=!1,this.Ie=!1,this.padding.setDirtyFalse(),this.Ys(),this.We()}ke(){this.Ls.dispose(),this.Ls=new w(this.Rs),this.Ls.colorSpace=g,this.Ls.needsUpdate=!0,this.sceneWrapper.setProperties(this.planeHandler,{texture:this.Ls})}Be(){return this.Pe&&(this.He=((t,i,s)=>{const e=[];for(const h of i){const i=Ni.resolve(h.style,s);for(const s of qi(h.text)){const h=Xi(t,s,i);e.push({text:s,style:i,metrics:h})}}return e})(this.Bs,this.Ee,this.commonStyle),this.Pe=!1),this.He}Ns(){return this.solverWrapper.dirty&&(this.Os!==Math.round(this.width)||this.js!==Math.round(this.height))}Ys(){this.Os=Math.round(this.width),this.js=Math.round(this.height)}Re(){return this.Ce||this.content.some(t=>t.dirty)}We(){this.Ce=!1;for(const t of this.content)t.setDirtyFalse()}}class ts{constructor(){this.dirty=!1}}class is extends ts{calculateScale(t,i){return 1}}class ss extends Ct{constructor(t=new is,i=C.VISIBLE){const s=t.calculateScale(window.innerWidth,window.innerHeight);super(window.innerWidth*s,window.innerHeight*s,i),this.ze=!1,this.Fe=()=>{const t=this.resizePolicy.calculateScale(window.innerWidth,window.innerHeight);this.resizePolicy.dirty=!1,this.ze=!1,this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Oe=t=>{this.je(t,"onPointerDown",ui.PRESSED)},this.Ne=t=>{this.je(t,"onPointerMove",ui.MOVED)},this.$e=t=>{this.je(t,"onPointerUp",ui.RELEASED)},this.Ye=t,window.addEventListener("resize",this.Fe),window.addEventListener("pointerdown",this.Oe),window.addEventListener("pointermove",this.Ne),window.addEventListener("pointerup",this.$e)}get resizePolicy(){return this.Ye}set resizePolicy(t){this.Ye!==t&&(this.Ye=t,this.ze=!0)}destroy(){window.removeEventListener("resize",this.Fe),window.removeEventListener("pointerdown",this.Oe),window.removeEventListener("pointermove",this.Ne),window.removeEventListener("pointerup",this.$e)}render(t,i){(this.resizePolicy.dirty||this.ze)&&this.Fe(),super.renderInternal(t,i)}projectWorldPosition(t,s){const e=t.clone().project(s);return e.x=i.mapLinear(e.x,-1,1,this.x,this.width),e.y=i.mapLinear(e.y,-1,1,this.y,this.height),e}projectLayerPosition(t,s,e=-1){return new r(i.mapLinear(t.x,this.x,this.width,-1,1),i.mapLinear(t.y,this.y,this.height,-1,1),e).unproject(s)}buildRay(t,s,e=new S){const h=new r(i.mapLinear(t.x,this.x,this.width,-1,1),i.mapLinear(t.y,this.y,this.height,-1,1),-1).unproject(s),n=new r(i.mapLinear(t.x,this.x,this.width,-1,1),i.mapLinear(t.y,this.y,this.height,-1,1),1).unproject(s).sub(h).normalize();return e.set(h,n)}je(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;T(this.mode)&&(this.emit(s,o,a,t.pointerId),this.inputWrapperInternal[i](o,a,t.pointerId))}}class es 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 hs 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 rs 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 ns extends Ti{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.qe=t,this.Xe=i}get startAngle(){return this.qe}get inverseDirection(){return this.Xe}set startAngle(t){this.qe!==t&&(this.qe=t,this.dirtyInternal=!0)}set inverseDirection(t){this.Xe!==t&&(this.Xe=t,this.dirtyInternal=!0)}enumerateProperties(){return{direction:this.Xe?-1:1,startAngle:this.qe}}}class os extends ts{constructor(t,i){super(),this.Ze=t,this.Je=i}get rectWidth(){return this.Ze}get rectHeight(){return this.Je}set rectWidth(t){t!==this.Ze&&(this.Ze=t,this.dirty=!0)}set rectHeight(t){t!==this.Je&&(this.Je=t,this.dirty=!0)}calculateScale(t,i){return Math.min(this.Ze/t,this.Je/i)}}class as extends ts{constructor(t,i){super(),this.Ke=t,this.Qe=i}get fixedWidthLandscape(){return this.Ke}get fixedHeightPortrait(){return this.Qe}set fixedWidthLandscape(t){t!==this.Ke&&(this.Ke=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.Qe&&(this.Qe=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.Ke/t:this.Qe/i}}class cs extends ts{constructor(t,i){super(),this.th=t,this.ih=i}get fixedHeightLandscape(){return this.th}get fixedWidthPortrait(){return this.ih}set fixedHeightLandscape(t){t!==this.th&&(this.th=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.ih&&(this.ih=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.th/i:this.ih/t}}class ls extends ts{constructor(t,i){super(),this.Ze=t,this.Je=i}get rectWidth(){return this.Ze}get rectHeight(){return this.Je}set rectWidth(t){t!==this.Ze&&(this.Ze=t,this.dirty=!0)}set rectHeight(t){t!==this.Je&&(this.Je=t,this.dirty=!0)}calculateScale(t,i){return Math.max(this.Ze/t,this.Je/i)}}class us extends ts{constructor(t,i){super(),this.th=t,this.Qe=i}get fixedHeightLandscape(){return this.th}get fixedHeightPortrait(){return this.Qe}set fixedHeightLandscape(t){t!==this.th&&(this.th=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.Qe&&(this.Qe=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.th/i:this.Qe/i}}class fs extends ts{constructor(t,i){super(),this.Ke=t,this.ih=i}get fixedWidthLandscape(){return this.Ke}get fixedWidthPortrait(){return this.ih}set fixedWidthLandscape(t){t!==this.Ke&&(this.Ke=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.ih&&(this.ih=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.Ke/t:this.ih/t}}export{Kt as UIAnchor,xi as UIAnimatedImage,es as UIAreaCircle,hs as UIAreaPolygon,vi as UIAreaRectangle,rs as UIAreaRoundedRectangle,Gt as UIAspectConstraint,tt as UIColor,$t as UIConstraint2DBuilder,qt as UICoverConstraintBuilder,Jt as UICustomConstraint,xt as UIExpression,Zt as UIFitConstraintBuilder,ss as UIFullscreenLayer,Si as UIGraphics,Bt as UIHeightConstraint,Lt as UIHorizontalDistanceConstraint,kt as UIHorizontalInterpolationConstraint,Wt as UIHorizontalProportionConstraint,Mi as UIImage,gi as UIInputDummy,ui as UIInputEvent,di as UIMicro,Qt as UIMicroAnchorMode,C as UIMode,Ii as UINineSlice,bi as UINineSliceRegionMode,I as UIOrientation,Y as UIPriority,Pi as UIProgress,ns as UIProgressMaskFunctionCircular,Hi as UIProgressMaskFunctionDirectional,St as UIRelation,os as UIResizePolicyCover,as as UIResizePolicyCross,cs as UIResizePolicyCrossInverted,ls as UIResizePolicyFit,us as UIResizePolicyFixedHeight,fs as UIResizePolicyFixedWidth,is as UIResizePolicyNone,Di as UIScene,Ai as UISceneUpdateMode,Rt as UISingleParameterConstraint,Qi as UIText,Gi as UITextResizeMode,q as UITransparencyMode,zt as UIVerticalDistanceConstraint,Ft as UIVerticalInterpolationConstraint,Ot as UIVerticalProportionConstraint,jt as UIWidthConstraint};
1
+ import{Color as t,MathUtils 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 w,SRGBColorSpace as g,LinearFilter as y,WebGLRenderTarget as m,UnsignedByteType as _,RGBAFormat as b,PerspectiveCamera as x,Ray as S}from"three";class M{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 E{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 M(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 I,C;function T(t){return t===I.INTERACTIVE||t===I.INTERACTIVE_TRANSPARENT}function P(t){return t!==I.HIDDEN}function H(){return new A}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE",t[t.INTERACTIVE_TRANSPARENT=3]="INTERACTIVE_TRANSPARENT"})(I||(I={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(C||(C={}));class A{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 U(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 U(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 A;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 U{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new U(this.first,this.second)}}class V{constructor(t=""){this.S=t}id(){return this.I}name(){return this.S}setName(t){this.S=t}context(){return this.C}setContext(t){this.C=t}value(){return this.T}setValue(t){this.T=t}plus(t){return new R(this,t)}minus(t){return new R(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new R([t,this])}divide(t){return new R([1/t,this])}toJSON(){return{name:this.S,value:this.T}}toString(){return this.C+"["+this.S+":"+this.T+"]"}S;T=0;C=null;I=D++}let D=0;class R{constructor(){let t=(t=>{let i=0,s=()=>0,e=H();for(let h=0,r=t.length;r>h;++h){let r=t[h];if("number"==typeof r)i+=r;else if(r instanceof V)e.setDefault(r,s).second+=1;else if(r instanceof R){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 V)e.setDefault(h,s).second+=t;else{if(!(h instanceof R))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.P=t.terms,this.H=t.constant}terms(){return this.P}constant(){return this.H}value(){let t=this.H;for(let i=0,s=this.P.size();s>i;i++){let s=this.P.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new R(this,t)}minus(t){return new R(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new R([t,this])}divide(t){return new R([1/t,this])}isConstant(){return 0==this.P.size()}toString(){let t=this.P.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.H||(t+=" + "),t+=this.H,t}P;H}class B{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=B.create(1e3,1e3,1e3);static strong=B.create(1,0,0);static medium=B.create(0,1,0);static weak=B.create(0,0,1);static clip(t){return Math.max(0,Math.min(B.required,t))}}var L;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(L||(L={}));class k{constructor(t,i,s,e=B.required){this.A=i,this.U=B.clip(e),this.V=void 0===s&&t instanceof R?t:t.minus(s)}id(){return this.I}expression(){return this.V}op(){return this.A}strength(){return this.U}toString(){return this.V+" "+["<=",">=","="][this.A]+" 0 ("+this.U+")"}V;A;U;I=W++}let W=0;class z{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=B.required){let h=new k(t,i,s,e);return this.addConstraint(h),h}addConstraint(t){if(void 0!==this.D.find(t))throw Error("duplicate constraint");let i=this.R(t),s=i.row,e=i.tag,h=this.B(s,e);if(h.type()===F.Invalid&&s.allDummies()){if(!O(s.constant()))throw Error("unsatisfiable constraint");h=e.marker}if(h.type()===F.Invalid){if(!this.L(s))throw Error("unsatisfiable constraint")}else s.solveFor(h),this.W(h,s),this.O.insert(h,s);this.D.insert(t,e),this.F(this.N)}removeConstraint(t){let i=this.D.erase(t);if(void 0===i)throw Error("unknown constraint");this.j(t,i.second);let s=i.second.marker,e=this.O.erase(s);if(void 0===e){let t=this.$(s);if(t.type()===F.Invalid)throw Error("failed to find leaving row");e=this.O.erase(t),e.second.solveForEx(t,s),this.W(s,e.second)}this.F(this.N)}hasConstraint(t){return this.D.contains(t)}getConstraints(){return this.D.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.G.find(t))throw Error("duplicate edit variable");if((i=B.clip(i))===B.required)throw Error("bad required strength");let s=new R(t),e=new k(s,L.Eq,void 0,i);this.addConstraint(e);let h=this.D.find(e).second;this.G.insert(t,{tag:h,constraint:e,constant:0})}removeEditVariable(t){let i=this.G.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.G.contains(t)}suggestValue(t,i){let s=this.G.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.O,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.q();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.q();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()!==F.External&&this.Y.push(i.first)}this.q()}updateVariables(){let t=this.X,i=this.O;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.X.setDefault(t,()=>this.J(F.External)).second}R(t){let i=t.expression(),s=new $(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.O.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let h=this.N,r=t.strength(),n={marker:j,other:j};switch(t.op()){case L.Le:case L.Ge:{let i=t.op()===L.Le?1:-1,e=this.J(F.Slack);if(n.marker=e,s.insertSymbol(e,i),B.required>r){let t=this.J(F.Error);n.other=t,s.insertSymbol(t,-i),h.insertSymbol(t,r)}break}case L.Eq:if(B.required>r){let t=this.J(F.Error),i=this.J(F.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(F.Dummy);n.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:n}}B(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()===F.External)return i.first}let e=i.marker.type();return e!==F.Slack&&e!==F.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==F.Slack&&e!==F.Error||t.coefficientFor(i.other)>=0?j:i.other):i.marker}L(t){let i=this.J(F.Slack);this.O.insert(i,t.copy()),this.K=t.copy(),this.F(this.K);let s=O(this.K.constant());this.K=null;let e=this.O.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let h=this.tt(t);if(h.type()===F.Invalid)return!1;t.solveForEx(i,h),this.W(h,t),this.O.insert(h,t)}let h=this.O;for(let t=0,s=h.size();s>t;++t)h.itemAt(t).second.removeSymbol(i);return this.N.removeSymbol(i),s}W(t,i){let s=this.O;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()!==F.External&&this.Y.push(h.first)}this.N.substitute(t,i),this.K&&this.K.substitute(t,i)}F(t){let i=0;for(;this.maxIterations>i;){let s=this.it(t);if(s.type()===F.Invalid)return;let e=this.st(s);if(e.type()===F.Invalid)throw Error("the objective is unbounded");let h=this.O.erase(e).second;h.solveForEx(e,s),this.W(s,h),this.O.insert(s,h),i++}throw Error("solver iterations exceeded")}q(){let t=this.O,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()===F.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()!==F.Dummy)return e}return j}et(t){let i=Number.MAX_VALUE,s=j,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()!==F.Dummy){let t=this.N.coefficientFor(r)/n;i>t&&(i=t,s=r)}}return s}st(t){let i=Number.MAX_VALUE,s=j,e=this.O;for(let h=0,r=e.size();r>h;++h){let r=e.itemAt(h),n=r.first;if(n.type()!==F.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}$(t){let i=Number.MAX_VALUE,s=i,e=i,h=j,r=h,n=h,o=h,a=this.O;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()===F.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}j(t,i){i.marker.type()===F.Error&&this.ht(i.marker,t.strength()),i.other.type()===F.Error&&this.ht(i.other,t.strength())}ht(t,i){let s=this.O.find(t);void 0!==s?this.N.insertRow(s.second,-i):this.N.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===F.Slack||e===F.Error)return s.first}return j}J(t){return new N(t,this.rt++)}D=(()=>H())();O=(()=>H())();X=(()=>H())();G=(()=>H())();Y=[];N=new $;K=null;rt=0}function O(t){return 0>t?1e-8>-t:1e-8>t}var F;(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"})(F||(F={}));class N{constructor(t,i){this.I=i,this.nt=t}id(){return this.I}type(){return this.nt}I;nt}let j=new N(F.Invalid,-1);class ${constructor(t=0){this.H=t}cells(){return this.ot}constant(){return this.H}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()!==F.Dummy)return!1;return!0}copy(){let t=new $(this.H);return t.ot=this.ot.copy(),t}add(t){return this.H+=t}insertSymbol(t,i=1){O(this.ot.setDefault(t,()=>0).second+=i)&&this.ot.erase(t)}insertRow(t,i=1){this.H+=t.H*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.H=-this.H;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.H*=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=H();H}const G=1e3;var Y,q;function X(t){switch(t){case Y.P0:return B.create(G,G,G);case Y.P1:return B.create(100,0,0);case Y.P2:return B.create(10,0,0);case Y.P3:return B.create(0,100,0);case Y.P4:return B.create(0,10,0);case Y.P5:return B.create(0,0,100);case Y.P6:return B.create(0,0,10);case Y.P7:return B.create(0,0,1);default:throw Error("convertPriority: 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"})(Y||(Y={}));class Z{constructor(){this.dirty=!1,this.ct=!1,this.lt=[],this.ut=0}createInputCatcher(t,i,s,e){const h=this.ut++;return this.lt.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.lt.findIndex(i=>i.handler===t);if(-1===i)throw Error("UIInputWrapper.destroyInputCatcher: handler not found");this.lt.splice(i,1)}getZIndex(t){this.ft();const i=this.lt.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getZIndex: handler not found");return i.zIndex}setZIndex(t,i){const s=this.lt.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setZIndex: handler not found");s.zIndex!==i&&(s.zIndex=i,this.ct=!0,this.dirty=!0)}getActive(t){const i=this.lt.find(i=>i.handler===t);if(!i)throw Error("UIInputWrapper.getActive: handler not found");return i.active}setActive(t,i){const s=this.lt.find(i=>i.handler===t);if(!s)throw Error("UIInputWrapper.setActive: handler not found");s.active!==i&&(s.active=i)}onPointerDown(t,i,s){this.ft();for(let e=this.lt.length-1;e>=0;e--){const h=this.lt[e];if(h.active&&h.catchPointerDown(t,i,s))break}}onPointerMove(t,i,s){this.ft();for(let e=this.lt.length-1;e>=0;e--){const h=this.lt[e];if(h.active&&h.catchPointerMove(t,i,s))break}}onPointerUp(t,i,s){this.ft();for(let e=this.lt.length-1;e>=0;e--){const h=this.lt[e];if(h.active&&h.catchPointerUp(t,i,s))break}}ft(){if(this.ct){this.lt.sort((t,i)=>t.zIndex-i.zIndex);const t=this.lt.length,i=1024>t?1:1024/t;for(let s=0;t>s;s++)this.lt[s].zIndex=s*i;this.ct=!1}}}function J(t){return.04045>t?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function K(t){return.0031308>t?12.92*t:1.055*Math.pow(t,.41666)-.055}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(q||(q={}));const Q={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 tt{constructor(...i){if(this.dt=1,this.vt=1,this.wt=1,this.gt=1,this.yt=0,this._t=0,this.bt=1,this.xt=!1,this.St=!1,this.Mt=!1,3>i.length||"number"!=typeof i[0]){if(i.length>=1&&void 0!==i[0]){const[s,e=1]=i;"string"==typeof s?s.startsWith("#")?this.setHexString(s):this.setColorName(s,e):s instanceof tt?(s.Et(),this.dt=s.dt,this.vt=s.vt,this.wt=s.wt,this.gt=s.gt):s instanceof t?(this.dt=s.r,this.vt=s.g,this.wt=s.b,this.gt=e):"number"==typeof s&&this.setHexRGB(s,e)}}else{const[t,s,e,h=1]=i;this.dt=t,this.vt=s,this.wt=e,this.gt=h}}static get black(){return new tt("black")}static get white(){return new tt("white")}static get red(){return new tt("red")}static get green(){return new tt("green")}static get blue(){return new tt("blue")}static get yellow(){return new tt("yellow")}static get cyan(){return new tt("cyan")}static get magenta(){return new tt("magenta")}static get gray(){return new tt("gray")}static get grey(){return new tt("grey")}static get silver(){return new tt("silver")}static get maroon(){return new tt("maroon")}static get olive(){return new tt("olive")}static get lime(){return new tt("lime")}static get aqua(){return new tt("aqua")}static get teal(){return new tt("teal")}static get navy(){return new tt("navy")}static get fuchsia(){return new tt("fuchsia")}static get purple(){return new tt("purple")}static get orange(){return new tt("orange")}static get pink(){return new tt("pink")}static get brown(){return new tt("brown")}static get gold(){return new tt("gold")}static get violet(){return new tt("violet")}static get indigo(){return new tt("indigo")}static get coral(){return new tt("coral")}static get salmon(){return new tt("salmon")}static get khaki(){return new tt("khaki")}static get plum(){return new tt("plum")}static get orchid(){return new tt("orchid")}static get tan(){return new tt("tan")}static get beige(){return new tt("beige")}static get mint(){return new tt("mint")}static get lavender(){return new tt("lavender")}static get crimson(){return new tt("crimson")}static get azure(){return new tt("azure")}static get ivory(){return new tt("ivory")}static get snow(){return new tt("snow")}get r(){return this.Et(),this.dt}get g(){return this.Et(),this.vt}get b(){return this.Et(),this.wt}get a(){return this.gt}get hue(){return this.It(),this.yt}get saturation(){return this.It(),this._t}get lightness(){return this.It(),this.bt}get dirty(){return this.xt}set r(t){t=i.clamp(t,0,1),this.Et(),t!==this.dt&&(this.dt=t,this.Mt=!0,this.xt=!0)}set g(t){t=i.clamp(t,0,1),this.Et(),t!==this.vt&&(this.vt=t,this.Mt=!0,this.xt=!0)}set b(t){t=i.clamp(t,0,1),this.Et(),t!==this.wt&&(this.wt=t,this.Mt=!0,this.xt=!0)}set a(t){(t=i.clamp(t,0,1))!==this.gt&&(this.gt=t,this.xt=!0)}set hue(t){t=i.clamp(t,0,360),this.It(),t!==this.yt&&(this.yt=t,this.St=!0,this.xt=!0)}set saturation(t){t=i.clamp(t,0,1),this.It(),t!==this._t&&(this._t=t,this.St=!0,this.xt=!0)}set lightness(t){t=i.clamp(t,0,1),this.It(),t!==this.bt&&(this.bt=t,this.St=!0,this.xt=!0)}setDirtyFalse(){this.xt=!1}set(t,s,e,h=this.gt){return t=i.clamp(t,0,1),s=i.clamp(s,0,1),e=i.clamp(e,0,1),h=i.clamp(h,0,1),this.Et(),t===this.dt&&s===this.vt&&e===this.wt&&h===this.gt||(this.dt=t,this.vt=s,this.wt=e,this.gt=h,this.Mt=!0,this.xt=!0),this}getHexRGBA(){return this.Et(),Math.round(255*this.dt)<<24|Math.round(255*this.vt)<<16|Math.round(255*this.wt)<<8|Math.round(255*this.gt)}getHexRGB(){return this.Et(),Math.round(255*this.dt)<<16|Math.round(255*this.vt)<<8|Math.round(255*this.wt)}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.vt&&e===this.wt&&h===this.gt||(this.dt=i,this.vt=s,this.wt=e,this.gt=h,this.Mt=!0,this.xt=!0),this}setHexRGB(t,s=this.gt){s=i.clamp(s,0,1),this.Et();const e=(t>>16&255)/255,h=(t>>8&255)/255,r=(255&t)/255;return e===this.dt&&h===this.vt&&r===this.wt&&s===this.gt||(this.dt=e,this.vt=h,this.wt=r,this.gt=s,this.Mt=!0,this.xt=!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(t,s,e,h=this.gt){return t=i.clamp(t,0,360),s=i.clamp(s,0,1),e=i.clamp(e,0,1),h=i.clamp(h,0,1),this.It(),t===this.yt&&s===this._t&&e===this.bt&&h===this.gt||(this.yt=t,this._t=s,this.bt=e,this.gt=h,this.St=!0,this.xt=!0),this}setColorName(t,s=this.gt){s=i.clamp(s,0,1);const e=t.toLowerCase().trim(),h=Q[e];if(void 0===h)throw Error("UIColor.setColorName.colorName: unknown color name");return this.setHexRGB(h,s)}setGLSLColor(t,s,e,h=this.gt){h=i.clamp(h,0,1),this.Et();const r=K(t),n=K(s),o=K(e);return r===this.dt&&n===this.vt&&o===this.wt&&h===this.gt||(this.dt=r,this.vt=n,this.wt=o,this.gt=h,this.Mt=!0,this.xt=!0),this}setThreeColor(t,s=this.gt){return s=i.clamp(s,0,1),this.Et(),t.r===this.dt&&t.g===this.vt&&t.b===this.wt&&s===this.gt||(this.dt=t.r,this.vt=t.g,this.wt=t.b,this.gt=s,this.Mt=!0,this.xt=!0),this}toCSSColor(){return this.Et(),`rgba(${Math.round(255*this.dt)}, ${Math.round(255*this.vt)}, ${Math.round(255*this.wt)}, ${this.gt})`}toGLSLColor(t=new s){return this.Et(),t.x=J(this.dt),t.y=J(this.vt),t.z=J(this.wt),t.w=this.gt,t}toThreeColor(i=new t){return this.Et(),i.r=this.dt,i.g=this.vt,i.b=this.wt,i}copy(t){return t instanceof tt?(this.Et(),t.Et(),this.dt===t.dt&&this.vt===t.vt&&this.wt===t.wt&&this.gt===t.gt||(this.dt=t.dt,this.vt=t.vt,this.wt=t.wt,this.gt=t.gt,this.Mt=!0,this.xt=!0)):(this.Et(),this.dt===t.r&&this.vt===t.g&&this.wt===t.b&&1===this.gt||(this.dt=t.r,this.vt=t.g,this.wt=t.b,this.gt=1,this.Mt=!0,this.xt=!0)),this}clone(){return this.Et(),new tt(this.dt,this.vt,this.wt,this.gt)}Et(){if(this.St){const{yt:t,_t: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.vt=o+c,this.wt=a+c,this.St=!1}}It(){if(this.Mt){const{dt:t,vt:i,wt: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._t=a,this.bt=n,this.Mt=!1}}}function it(t){if("number"==typeof t)return{glslType:"float",instantiable:!0,itemSize:1};if(t instanceof e)return{glslType:"sampler2D",instantiable:!1,itemSize:-1};if(t instanceof tt)return{glslType:"vec4",instantiable:!0,itemSize:4};if(t instanceof h)return{glslType:"vec2",instantiable:!0,itemSize:2};if(t instanceof r)return{glslType:"vec3",instantiable:!0,itemSize:3};if(t instanceof s)return{glslType:"vec4",instantiable:!0,itemSize:4};if(t instanceof n)return{glslType:"mat3",instantiable:!0,itemSize:9};if(t instanceof o)return{glslType:"mat4",instantiable:!0,itemSize:16};throw Error("resolveGLSLTypeInfo.value: unsupported property type")}function st(t,i){const s=i.uniforms["p_"+t];if(void 0===s)throw Error("resolveUniform.name: unknown uniform");return s}function et(t,i){const s=Object.keys(t),e=Object.keys(i);if(s.length!==e.length)return!1;for(const s of e){if(!(s in t))return!1;const e=it(t[s]),h=it(i[s]);if(e.glslType!==h.glslType)return!1;if(!h.instantiable&&i[s]!==t[s])return!1}return!0}function ht(t,i,s){return`\n // Defines\n #define PI 3.14159265359\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 // Source must define vec4 draw() function\n ${s}\n\n void main() {\n vec4 diffuseColor = draw();\n\n #ifdef USE_ALPHATEST\n if (diffuseColor.a < 0.50) {\n discard;\n }\n #endif\n\n #ifdef USE_ALPHAHASH\n if (diffuseColor.a < getAlphaHashThreshold(p_position)) {\n discard;\n }\n #endif\n\n gl_FragColor = linearToOutputTexel(diffuseColor);\n }\n `}const rt=(()=>{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})(),nt=new s,ot=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function at(t,i,e){if(t instanceof tt)t.toGLSLColor(nt),i[e]=nt.x,i[e+1]=nt.y,i[e+2]=nt.z,i[e+3]=nt.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 ct(t,i){const s=it(t);if(!s.instantiable)throw Error("buildEmptyInstancedBufferAttribute.value: cannot create instanced attribute for non-instantiable type");return new u(new Float32Array(i*s.itemSize),s.itemSize)}function lt(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 tt)return(new tt).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")}class ut extends f{constructor(t,i,s=q.BLEND,e=4){const h={},r={instanceVisibility:1,instanceTransform:(new o).identity()};for(const[t,s]of Object.entries(i))it(s).instantiable?r[t]=s:h[t]=s;const n=rt.clone(),a=((t,i,s,e)=>{const h={},r=[],n=[],o=[],a=[];for(const[t,s]of Object.entries(i)){const i=it(s);h["p_"+t]={value:s instanceof tt?s.toGLSLColor():s},r.push(`uniform ${i.glslType} p_${t};`)}for(const[t,i]of Object.entries(s)){const s=it(i);n.push(`attribute ${s.glslType} a_${t};`),o.push(`varying ${s.glslType} 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=ht(r,o,t);return new l({uniforms:h,vertexShader:c,fragmentShader:u,transparent:e===q.BLEND,alphaTest:e===q.CLIP?.5:0,alphaHash:e===q.HASH,depthWrite:e!==q.BLEND,depthTest:!0})})(t,h,r,s);super(n,a),this.source=t,this.transparency=s,this.Ct=new Map,this.Tt=new Map,this.ut=0,this.frustumCulled=!1,this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1,this.Pt=n,this.Pt.instanceCount=0,this.Ht=a,this.At=h,this.Ut=r,this.Vt=Math.max(4*Math.ceil(e/4),4);for(const[t,i]of Object.entries(this.Ut)){const s=ct(i,this.Vt);this.Pt.setAttribute("a_"+t,s),this.Tt.set(t,s)}for(const[t,i]of Object.entries(this.At))st(t,this.Ht).value=i;this.Ht.uniformsNeedUpdate=!0}get instanceCount(){return this.Pt.instanceCount}get properties(){return{...this.At,...this.Ut}}createInstance(){const t=this.ut++,i=this.Pt.instanceCount;return this.Dt(i+1),this.Ct.set(t,i),this.Pt.instanceCount++,this.Rt(i),t}destroyInstance(t){const i=this.Bt(t);this.Ct.delete(t);const s=this.Pt.instanceCount-1;s>i&&(this.Lt(s,i),this.kt(s,i)),this.Pt.instanceCount--}setProperties(t,i){const s=this.Bt(t);for(const[t,e]of Object.entries(i))if(it(e).instantiable){const i=this.Wt(t);at(e,i.array,s*i.itemSize),i.needsUpdate=!0}else st(t,this.Ht).value=e,this.Ht.uniformsNeedUpdate=!0}setTransform(t,i){const s=this.Bt(t),e=this.Wt("instanceTransform"),h=e.array,r=16*s,n=i.elements;for(let t=0;16>t;t++)h[r+t]=n[t];e.needsUpdate=!0}setVisibility(t,i){const s=this.Bt(t),e=this.Wt("instanceVisibility");e.array[s]=i?1:0,e.needsUpdate=!0}isCompatible(t,i,s=q.BLEND){return this.source===t&&this.transparency===s&&et(this.properties,i)}arePropertiesCompatible(t){return et(this.properties,t)}extractInstanceData(t){return{source:this.source,properties:this.extractProperties(t),transparency:this.transparency,transform:this.extractTransform(t),visibility:this.extractVisibility(t)}}extractProperties(t){const i=this.Bt(t),s={};for(const[t,i]of Object.entries(this.At))s[t]=i;for(const[t,e]of Object.entries(this.Ut)){const h=this.Tt.get(t);s[t]=lt(e,h.array,i*h.itemSize)}return s}extractTransform(t){const i=this.Bt(t),s=this.Tt.get("instanceTransform").array,e=new o;return e.fromArray(s,16*i),e}extractVisibility(t){const i=this.Bt(t);return this.Tt.get("instanceVisibility").array[i]>=.5}destroy(){this.Pt.dispose(),this.Ht.dispose(),this.Tt.clear(),this.Ct.clear()}Rt(t){const i=this.Tt.get("instanceVisibility"),s=this.Tt.get("instanceTransform");((t,i,s)=>{t[s]=1;const e=16*s;for(let t=0;16>t;t++)i[e+t]=ot[t]})(i.array,s.array,t),i.needsUpdate=!0,s.needsUpdate=!0}Dt(t){if(this.Vt>=t)return;const i=4*Math.ceil(t/4);for(const[t,s]of this.Tt.entries()){const e=s.itemSize,h=new Float32Array(i*e);h.set(s.array);const r=new u(h,e);this.Pt.setAttribute("a_"+t,r),this.Tt.set(t,r)}this.Vt=i}Lt(t,i){for(const s of this.Tt.values()){const e=s.array,h=s.itemSize,r=t*h,n=i*h;for(let t=0;h>t;t++)e[n+t]=e[r+t];s.needsUpdate=!0}}kt(t,i){for(const[s,e]of this.Ct)if(e===t){this.Ct.set(s,i);break}}Bt(t){const i=this.Ct.get(t);if(void 0===i)throw Error("UIGenericInstancedPlane.resolveIndex.handler: invalid handler");return i}Wt(t){const i=this.Tt.get(t);if(void 0===i)throw Error("UIGenericInstancedPlane.resolveAttribute.name: unknown attribute");return i}}const ft=new a(1,1).translate(.5,.5,0);class dt extends f{constructor(t,i,s){const e=((t,i,s)=>{const e={p_transform:{value:new o}},h=[];for(const[t,s]of Object.entries(i)){const i=it(s);e["p_"+t]={value:s instanceof tt?s.toGLSLColor():s},h.push(`uniform ${i.glslType} p_${t};`)}const r=`\n // Default uniform declarations\n uniform mat4 p_transform;\n\n // Custom uniform declarations\n ${h.join("\n")}\n\n // Default varying declarations\n varying vec3 p_position;\n varying vec2 p_uv;\n\n void main() {\n p_position = position;\n p_uv = uv;\n\n gl_Position = projectionMatrix * p_transform * vec4(position, 1.0);\n }\n `,n=ht(h,[],t);return new l({uniforms:e,vertexShader:r,fragmentShader:n,transparent:s===q.BLEND,alphaTest:s===q.CLIP?.5:0,alphaHash:s===q.HASH,depthWrite:s!==q.BLEND,depthTest:!0})})(t,i,s);super(ft,e),this.source=t,this.zt=(new o).identity(),this.frustumCulled=!1,this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1,this.Ht=e,this.Ot={...i},this.Ft=s}get properties(){return{...this.Ot}}get transform(){return this.zt}get visibility(){return this.visible}get transparency(){return this.Ft}setProperties(t){for(const[i,s]of Object.entries(t)){const t=st(i,this.Ht);s instanceof tt?s.toGLSLColor(t.value):t.value=s,this.Ot[i]=s}this.Ht.uniformsNeedUpdate=!0}setTransform(t){st("transform",this.Ht).value.copy(t),this.Ht.uniformsNeedUpdate=!0,this.zt.copy(t)}setVisibility(t){this.visible=t}setTransparency(t){this.Ft!==t&&(this.Ht.transparent=t===q.BLEND,this.Ht.alphaTest=t===q.CLIP?.5:0,this.Ht.alphaHash=t===q.HASH,this.Ht.depthWrite=t!==q.BLEND,this.Ht.needsUpdate=!0,this.Ft=t)}extractInstanceData(){return{source:this.source,properties:this.properties,transparency:this.Ft,transform:this.zt.clone(),visibility:this.visible}}isCompatible(t,i,s){return this.Ft===s&&this.source===t&&et(this.Ot,i)}arePropertiesCompatible(t){return et(this.Ot,t)}destroy(){this.Ht.dispose()}}class pt{constructor(t){this.Nt=t,this.jt=new Map,this.ut=0}create(t,i,s){const e=this.ut++,h={plane:void 0};return this.jt.set(e,h),this.$t(h,{source:t,properties:i,transparency:s,transform:void 0,visibility:!0}),e}destroy(t){const i=this.Gt(t);this.jt.delete(t),this.Yt(i)}setTransform(t,i){const s=this.Gt(t);s.plane instanceof ut&&void 0!==s.instanceHandler?s.plane.setTransform(s.instanceHandler,i):s.plane instanceof dt&&s.plane.setTransform(i)}setProperties(t,i){const s=this.Gt(t),e=this.qt(s),h={...e.properties,...i};this.Xt(s,e,h,e.transparency)?(this.Yt(s),this.$t(s,{...e,properties:h})):this.Zt(s,i)}setVisibility(t,i){const s=this.Gt(t);s.plane instanceof ut&&void 0!==s.instanceHandler?s.plane.setVisibility(s.instanceHandler,i):s.plane instanceof dt&&s.plane.setVisibility(i)}setTransparency(t,i){const s=this.Gt(t),e=this.qt(s);e.transparency!==i&&(this.Xt(s,e,e.properties,i)?(this.Yt(s),this.$t(s,{...e,transparency:i})):s.plane instanceof dt&&s.plane.setTransparency(i))}$t(t,i){const{source:s,properties:e,transparency:h,transform:r,visibility:n}=i,o=this.Jt(s,e,h);if(o)return void this.Kt(t,o,e,r,n);const a=this.Qt(s,e,h,t);if(a){const i=this.ti(a,e);return void this.Kt(t,i,e,r,n)}this.ii(t,s,e,h,r,n)}qt(t){return t.plane instanceof ut&&void 0!==t.instanceHandler?t.plane.extractInstanceData(t.instanceHandler):t.plane.extractInstanceData()}Yt(t){if(t.plane instanceof ut&&void 0!==t.instanceHandler){const i=t.plane;i.destroyInstance(t.instanceHandler),0===i.instanceCount?(this.Nt.remove(i),i.destroy()):1===i.instanceCount&&this.si(i,t)}else t.plane instanceof dt&&(this.Nt.remove(t.plane),t.plane.destroy());t.plane=void 0,delete t.instanceHandler}Zt(t,i){t.plane instanceof ut&&void 0!==t.instanceHandler?t.plane.setProperties(t.instanceHandler,i):t.plane instanceof dt&&t.plane.setProperties(i)}Xt(t,i,s,e){return t.plane instanceof ut?i.transparency!==e||!t.plane.arePropertiesCompatible(s):!!this.Jt(i.source,s,e)||!!this.Qt(i.source,s,e,t)}Kt(t,i,s,e,h){const r=i.createInstance();i.setProperties(r,s),e&&i.setTransform(r,e),i.setVisibility(r,h),t.plane=i,t.instanceHandler=r}ii(t,i,s,e,h,r){const n=new dt(i,s,e);n.setProperties(s),h&&n.setTransform(h),n.setVisibility(r),this.Nt.add(n),t.plane=n,delete t.instanceHandler}Qt(t,i,s,e){for(const h of this.jt.values())if(h!==e&&h.plane instanceof dt&&h.plane.isCompatible(t,i,s))return h}Jt(t,i,s){for(const e of this.jt.values())if(e.plane instanceof ut&&e.plane.isCompatible(t,i,s))return e.plane}ti(t,i){const s=t.plane,e=s.extractInstanceData(),h=new ut(e.source,i,e.transparency),r=h.createInstance();return h.setProperties(r,e.properties),h.setTransform(r,e.transform),h.setVisibility(r,e.visibility),t.plane=h,t.instanceHandler=r,this.Nt.remove(s),s.destroy(),this.Nt.add(h),h}si(t,i){let s;for(const e of this.jt.values())if(e!==i&&e.plane===t&&void 0!==e.instanceHandler){s=e;break}if(!s)return;const e=t.extractInstanceData(s.instanceHandler),h=new dt(e.source,e.properties,e.transparency);h.setProperties(e.properties),h.setTransform(e.transform),h.setVisibility(e.visibility),this.Nt.remove(t),t.destroy(),this.Nt.add(h),s.plane=h,delete s.instanceHandler}Gt(t){const i=this.jt.get(t);if(!i)throw Error("UIGenericPlaneRegistry.resolveDescriptor.handler: descriptor not found");return i}}let vt=new t,wt=0,gt=!1,yt=!1,mt=!1,_t=!1;class bt{constructor(t,i){this.Nt=new d,this.ei=new pt(this.Nt),this.hi=new p(0,t,i,0,-1024,1024)}createPlane(t,i,s){return this.ei.create(t,i,s)}destroyPlane(t){this.ei.destroy(t)}setTransform(t,i){this.ei.setTransform(t,i)}setProperties(t,i){this.ei.setProperties(t,i)}setVisibility(t,i){this.ei.setVisibility(t,i)}setTransparency(t,i){this.ei.setTransparency(t,i)}insertCustomObject(t){return this.Nt.add(t),this}removeCustomObject(t){return this.Nt.remove(t),this}resize(t,i){return this.hi.right=t,this.hi.top=i,this.hi.updateProjectionMatrix(),this}render(t){return vt=t.getClearColor(vt),wt=t.getClearAlpha(),gt=t.autoClear,yt=t.autoClearColor,mt=t.autoClearDepth,_t=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.Nt,this.hi),t.setClearColor(vt),t.setClearAlpha(wt),t.autoClear=gt,t.autoClearColor=yt,t.autoClearDepth=mt,t.autoClearStencil=_t,this}}class xt{constructor(t=0,i){if(this.constant=t,this.ri=i?new Map(i):new Map,i)for(let t=0;i.length>t;t++)Ut()}static plus(t,i){const s=new xt(t.constant+i.constant,Array.from(t.ri.entries()));for(const[t,e]of i.ri)s.plus(t,e);return s}static minus(t,i){const s=new xt(t.constant-i.constant,Array.from(t.ri.entries()));for(const[t,e]of i.ri)s.minus(t,e);return s}plus(t,i){return this.ri.set(t,(this.ri.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this.ri)this.ri.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.ri.has(t)}copy(t){this.constant=t.constant,this.ri.clear();for(const[i,s]of t.ri)this.ri.set(i,s);return this}clone(){return new xt(this.constant,Array.from(this.ri.entries()))}prepareTerms(){return Array.from(this.ri.entries())}}var St,Mt;(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(St||(St={}));class Et{constructor(){this.dirty=!1,this.ni=new z,this.oi=!1,this.ai=new Map,this.ci=0,this.li=new Map,this.ui=0}createVariable(t,i){const s=this.ci++,e=new V;if(i===Y.P0){const h={variable:e,priority:i,value:t};this.ai.set(s,h),h.constraint=this.fi(new xt(0,[[s,1]]),new xt(t),St.EQUAL,i);try{this.ni?.addConstraint(h.constraint)}catch{this.ni=void 0}}else{this.ai.set(s,{variable:e,priority:i,value:t});try{this.ni?.addEditVariable(e,X(i)),this.ni?.suggestValue(e,t)}catch{this.ni=void 0}}return this.oi=!0,this.dirty=!0,s}removeVariable(t){const i=this.ai.get(t);if(void 0===i)throw Error("UISolverWrapper.removeVariable.index: variable does not exist");for(const i of this.li.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error("UISolverWrapper.removeVariable.index: variable is used in constraint");try{i.constraint?this.ni?.removeConstraint(i.constraint):this.ni?.removeEditVariable(i.variable)}catch{this.ni=void 0}this.ai.delete(t),this.oi=!0,this.dirty=!0}suggestVariableValue(t,i){const s=this.ai.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.di(s.constraint,(new xt).plus(t,1),new xt(s.value),St.EQUAL,s.priority):this.ni?.suggestValue(s.variable,i),this.oi=!0,this.dirty=!0)}setVariablePriority(t,i){const s=this.ai.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===Y.P0){const i=(new xt).plus(t,1),e=new xt(s.value);s.constraint=this.fi(i,e,St.EQUAL,s.priority);try{this.ni?.addConstraint(s.constraint)}catch{this.ni=void 0}}else{if(s.constraint)try{this.ni?.removeConstraint(s.constraint)}catch{this.ni=void 0}s.constraint=void 0,this.pi(t,s)}this.oi=!0,this.dirty=!0}}readVariableValue(t){const i=this.ai.get(t);if(void 0===i)throw Error("UISolverWrapper.readVariableValue.index: variable does not exist");return void 0===this.ni&&this.wi(),this.oi&&(this.ni?.updateVariables(),this.oi=!1),i.variable.value()}createConstraint(t,i,s,e,h){const r=this.ui++,n=this.fi(t,i,s,e);if(this.li.set(r,{constraint:n,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:h}),h){try{this.ni?.addConstraint(n)}catch{this.ni=void 0}this.oi=!0,this.dirty=!0}return r}removeConstraint(t){const i=this.li.get(t);if(void 0===i)throw Error("UISolverWrapper.removeConstraint.index: constraint does not exist");if(i.enabled)try{this.ni?.removeConstraint(i.constraint)}catch{this.ni=void 0}this.li.delete(t),this.oi=!0,this.dirty=!0}setConstraintLHS(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintLHS.index: constraint does not exist");s.lhs.copy(i),this.gi(s),this.oi=!0,this.dirty=!0}setConstraintRHS(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRHS.index: constraint does not exist");s.rhs.copy(i),this.gi(s),this.oi=!0,this.dirty=!0}setConstraintRelation(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintRelation.index: constraint does not exist");s.relation!==i&&(s.relation=i,this.gi(s),this.oi=!0,this.dirty=!0)}setConstraintPriority(t,i){const s=this.li.get(t);if(void 0===s)throw Error("UISolverWrapper.setConstraintPriority.index: constraint does not exist");s.priority!==i&&(s.priority=i,this.gi(s),this.oi=!0,this.dirty=!0)}setConstraintEnabled(t,i){const s=this.li.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.ni?.addConstraint(s.constraint):this.ni?.removeConstraint(s.constraint)}catch{this.ni=void 0}this.oi=!0,this.dirty=!0}}pi(t,i){const s=[];for(const i of this.li.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.ni?.removeConstraint(i.constraint)}catch{this.ni=void 0}s.push(i)}this.ni?.removeEditVariable(i.variable),this.ni?.addEditVariable(i.variable,X(i.priority));for(const t of s)t.constraint=this.fi(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.ni?.addConstraint(t.constraint)}catch{this.ni=void 0;break}}gi(t){t.constraint=t.enabled?this.di(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.fi(t.lhs,t.rhs,t.relation,t.priority)}di(t,i,s,e,h){try{this.ni?.removeConstraint(t)}catch{this.ni=void 0}const r=this.fi(i,s,e,h);try{this.ni?.addConstraint(r)}catch{this.ni=void 0}return r}fi(t,i,s,e){return new k(this.yi(t),(t=>{switch(t){case St.EQUAL:return L.Eq;case St.LESS_THAN:return L.Le;case St.GREATER_THAN:return L.Ge;default:throw Error("convertRelation: invalid relation")}})(s),this.yi(i),X(e))}yi(t){return new R(...t.prepareTerms().map(([t,i])=>{const s=this.ai.get(t);if(void 0===s)throw Error("UISolverWrapper.convertExpression: variable does not exist");return[i,s.variable]}),t.constant)}wi(){if(this.ni)throw Error("UISolverWrapper.rebuildSolver: solver already exists");this.ni=new z;for(const t of this.ai.values())t.constraint?this.ni.addConstraint(t.constraint):(this.ni.addEditVariable(t.variable,X(t.priority)),this.ni.suggestValue(t.variable,t.value));for(const t of this.li.values())t.enabled&&this.ni.addConstraint(t.constraint);this.oi=!0,this.dirty=!0}}(t=>{t.ORIENTATION_CHANGED="orientation_changed",t.MODE_CHANGED="mode_changed",t.RENDERING="rendering"})(Mt||(Mt={}));const It=I.VISIBLE;class Ct extends E{constructor(t){super(),this.name="",this.inputWrapperInternal=new Z,this.mi=new Et;const i=t.width??1024,s=t.height??1024;this._i=new bt(i,s),this.name=t.name??"",this.bi=t.mode??It,this.xi=i>s?C.HORIZONTAL:C.VERTICAL,this.xVariable=this.mi.createVariable(0,Y.P0),this.yVariable=this.mi.createVariable(0,Y.P0),this.wVariable=this.mi.createVariable(i,Y.P0),this.hVariable=this.mi.createVariable(s,Y.P0)}get sceneWrapper(){return this._i}get solverWrapper(){return this.mi}get inputWrapper(){return this.inputWrapperInternal}get x(){return this.mi.readVariableValue(this.xVariable)}get y(){return this.mi.readVariableValue(this.yVariable)}get width(){return this.mi.readVariableValue(this.wVariable)}get height(){return this.mi.readVariableValue(this.hVariable)}get mode(){return this.bi}get orientation(){return this.xi}set mode(t){t!==this.bi&&(this.bi=t,this.emit(Mt.MODE_CHANGED,this.bi,this))}resizeInternal(t,i){this.mi.suggestVariableValue(this.wVariable,t),this.mi.suggestVariableValue(this.hVariable,i),this._i.resize(t,i);const s=t>i?C.HORIZONTAL:C.VERTICAL;s!==this.xi&&(this.xi=s,this.emit(Mt.ORIENTATION_CHANGED,this.xi,this))}renderInternal(t,i){P(this.mode)&&(this.emit(Mt.RENDERING,t,i,this),this._i.render(t)),this.mi.dirty=!1,this.inputWrapperInternal.dirty=!1}}function Tt(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof Ct}function Pt(t){return"object"==typeof t&&null!==t&&"xVariable"in t&&"number"==typeof t.xVariable&&"yVariable"in t&&"number"==typeof t.yVariable&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height}function Ht(t){return"object"==typeof t&&null!==t&&"wVariable"in t&&"number"==typeof t.wVariable&&"hVariable"in t&&"number"==typeof t.hVariable&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height}const At=1e-6;function Ut(){}function Vt(t,i,s){if(t instanceof Ct)return t;if(Tt(t))return t.layer;if(i instanceof Ct)return i;if(Tt(i))return i.layer;throw Error(s+": no valid subjects found")}function Dt(t,i,s){if(i instanceof Ct)return i;if(Tt(i))return i.layer;if(s instanceof Ct)return s;if(Tt(s))return s.layer;throw Error(t+": no valid subjects found")}class Rt{constructor(t,i){this.layer=t,this.solverWrapper=this.layer.solverWrapper,this.name=i??""}}class Bt extends Rt{constructor(t,i){var s,e,h;super(t,i?.name),this.Si=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.Mi=(s=i?.priority,s??Y.P0),this.Ei=(e=i?.relation,e??St.EQUAL),this.xi=(h=i?.orientation,h??C.ALWAYS),this.layer.on(Mt.ORIENTATION_CHANGED,this.Si)}get priority(){return this.Mi}get relation(){return this.Ei}get orientation(){return this.xi}set priority(t){t!==this.Mi&&(this.Mi=t,this.solverWrapper.setConstraintPriority(this.constraint,this.Mi))}set relation(t){t!==this.Ei&&(this.Ei=t,this.solverWrapper.setConstraintRelation(this.constraint,this.Ei))}set orientation(t){t!==this.xi&&(this.xi=t,this.Si())}destroy(){this.layer.off(Mt.ORIENTATION_CHANGED,this.Si),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.xi===C.ALWAYS||this.xi===this.layer.orientation}}class Lt extends Bt{constructor(t,i={}){super(t.layer,i),this.Ii=t,this.Ci=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new xt(0,[[this.Ii.hVariable,1]]),new xt(this.Ci),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.Ci}set height(t){this.Ci!==t&&(this.Ci=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(t)))}}class kt extends Bt{constructor(t,i,s={}){super(Vt(t,i,"UIHorizontalDistanceConstraint.constructor"),s),this.Ti=t,this.Pi=i,this.Hi=s.anchorA??.5,this.Ai=s.anchorB??.5,this.Ui=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(this.Ui),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Ui}get anchorA(){return this.Hi}get anchorB(){return this.Ai}set distance(t){this.Ui!==t&&(this.Ui=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(this.Ui)))}set anchorA(t){this.Hi!==t&&(this.Hi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i;if(Ht(this.Ti))t=new xt(0,[[this.Ti.xVariable,1],[this.Ti.wVariable,this.Hi]]);else{if(!Pt(this.Ti))throw Error("UIHorizontalDistanceConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.xVariable,1)}if(Ht(this.Pi))i=new xt(0,[[this.Pi.xVariable,1],[this.Pi.wVariable,this.Ai]]);else{if(!Pt(this.Pi))throw Error("UIHorizontalDistanceConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Pi.xVariable,1)}return xt.minus(i,t)}}class Wt extends Bt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Dt("UIHorizontalInterpolationConstraint.constructor",t,i),e),this.Ti=t,this.Pi=i,this.Di=s,this.Hi=h,this.Ai=h,this.Ri=e.anchorC??.5,this.Bi=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.Bi}get anchorA(){return this.Hi}get anchorB(){return this.Ai}get anchorC(){return this.Ri}set t(t){this.Bi!==t&&(this.Bi=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.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorC(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i,s;if(Ht(this.Ti))t=new xt(0,[[this.Ti.xVariable,1],[this.Ti.wVariable,this.Hi]]);else{if(!Pt(this.Ti))throw Error("UIHorizontalInterpolationConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.xVariable,1)}if(Ht(this.Pi))i=new xt(0,[[this.Pi.xVariable,1],[this.Pi.wVariable,this.Ai]]);else{if(!Pt(this.Pi))throw Error("UIHorizontalInterpolationConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Pi.xVariable,1)}if(Ht(this.Di))s=new xt(0,[[this.Di.xVariable,1],[this.Di.wVariable,this.Ri]]);else{if(!Pt(this.Di))throw Error("UIHorizontalInterpolationConstraint.buildLHS.c: invalid element type");s=(new xt).plus(this.Di.xVariable,1)}const e=t.clone().multiply(1-this.Bi),h=i.clone().multiply(this.Bi);return xt.minus(xt.minus(s,e),h)}}class zt extends Bt{constructor(t,i,s={}){super(Vt(t,i,"UIHorizontalProportionConstraint.constructor"),s),this.Ti=t,this.Pi=i,this.Li=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new xt(0),this.ki(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.Li}set proportion(t){this.Li!==t&&(this.Li=t,this.solverWrapper.setConstraintRHS(this.constraint,this.ki()))}ki(){return xt.minus(new xt(0,[[this.Ti.wVariable,this.Li]]),new xt(0,[[this.Pi.wVariable,1]]))}}class Ot extends Bt{constructor(t,i,s={}){super(Vt(t,i,"UIVerticalDistanceConstraint.constructor"),s),this.Ti=t,this.Pi=i,this.Hi=s.anchorA??.5,this.Ai=s.anchorB??.5,this.Ui=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(this.Ui),this.relation,this.priority,this.isConstraintEnabled())}get distance(){return this.Ui}get anchorA(){return this.Hi}get anchorB(){return this.Ai}set distance(t){this.Ui!==t&&(this.Ui=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(this.Ui)))}set anchorA(t){this.Hi!==t&&(this.Hi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorB(t){this.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i;if(Ht(this.Ti))t=new xt(0,[[this.Ti.yVariable,1],[this.Ti.hVariable,this.Hi]]);else{if(!Pt(this.Ti))throw Error("UIVerticalDistanceConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.yVariable,1)}if(Ht(this.Pi))i=new xt(0,[[this.Pi.yVariable,1],[this.Pi.hVariable,this.Ai]]);else{if(!Pt(this.Pi))throw Error("UIVerticalDistanceConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Pi.yVariable,1)}return xt.minus(i,t)}}class Ft extends Bt{constructor(t,i,s,e={}){const h=e.anchorA??.5;super(Dt("UIVerticalInterpolationConstraint.constructor",t,i),e),this.Ti=t,this.Pi=i,this.Di=s,this.Hi=h,this.Ai=h,this.Ri=e.anchorC??.5,this.Bi=e.t??.5,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(0),this.relation,this.priority,this.isConstraintEnabled())}get t(){return this.Bi}get anchorA(){return this.Hi}get anchorB(){return this.Ai}get anchorC(){return this.Ri}set t(t){this.Bi!==t&&(this.Bi=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.Ai!==t&&(this.Ai=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}set anchorC(t){this.Ri!==t&&(this.Ri=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Vi()))}Vi(){let t,i,s;if(Ht(this.Ti))t=new xt(0,[[this.Ti.yVariable,1],[this.Ti.hVariable,this.Hi]]);else{if(!Pt(this.Ti))throw Error("UIVerticalInterpolationConstraint.buildLHS.a: invalid element type");t=(new xt).plus(this.Ti.yVariable,1)}if(Ht(this.Pi))i=new xt(0,[[this.Pi.yVariable,1],[this.Pi.hVariable,this.Ai]]);else{if(!Pt(this.Pi))throw Error("UIVerticalInterpolationConstraint.buildLHS.b: invalid element type");i=(new xt).plus(this.Pi.yVariable,1)}if(Ht(this.Di))s=new xt(0,[[this.Di.yVariable,1],[this.Di.hVariable,this.Ri]]);else{if(!Pt(this.Di))throw Error("UIVerticalInterpolationConstraint.buildLHS.c: invalid element type");s=(new xt).plus(this.Di.yVariable,1)}const e=t.clone().multiply(1-this.Bi),h=i.clone().multiply(this.Bi);return xt.minus(xt.minus(s,e),h)}}class Nt extends Bt{constructor(t,i,s={}){super(Vt(t,i,"UIVerticalProportionConstraint.constructor"),s),this.Ti=t,this.Pi=i,this.Li=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new xt(0),this.ki(),this.relation,this.priority,this.isConstraintEnabled())}get proportion(){return this.Li}set proportion(t){this.Li!==t&&(this.Li=t,this.solverWrapper.setConstraintRHS(this.constraint,this.ki()))}ki(){return xt.minus(new xt(0,[[this.Ti.hVariable,this.Li]]),new xt(0,[[this.Pi.hVariable,1]]))}}class jt extends Bt{constructor(t,i={}){super(t.layer,i),this.Ii=t,this.Wi=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new xt(0,[[this.Ii.wVariable,1]]),new xt(this.Wi),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Wi}set width(t){this.Wi!==t&&(this.Wi=t,this.solverWrapper.setConstraintRHS(this.constraint,new xt(t)))}}function $t(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 Gt{static size(t,i={}){const s=$t(i.size),e=$t(i.priority),h=$t(i.relation),r=$t(i.orientation);return{h:new jt(t,{width:s.h,priority:e.h,relation:h.h,orientation:r.h}),v:new Lt(t,{height:s.v,priority:e.v,relation:h.v,orientation:r.v})}}static distance(t,i,s={}){const e=$t(s.anchorA),h=$t(s.anchorB),r=$t(s.distance),n=$t(s.priority),o=$t(s.relation),a=$t(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 Ot(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=$t(s.proportion),h=$t(s.priority),r=$t(s.relation),n=$t(s.orientation);return{h:new zt(t,i,{proportion:e.h,priority:h.h,relation:r.h,orientation:n.h}),v:new Nt(t,i,{proportion:e.v,priority:h.v,relation:r.v,orientation:n.v})}}static interpolation(t,i,s,e={}){const h=$t(e.anchorA),r=$t(e.anchorB),n=$t(e.anchorC),o=$t(e.t),a=$t(e.priority),c=$t(e.relation),l=$t(e.orientation);return{h:new Wt(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 Ft(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 Yt extends Bt{constructor(t,i={}){super(t.layer,i),this.Ii=t,this.zi=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Vi(),new xt(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 xt(0,[[this.Ii.wVariable,1],[this.Ii.hVariable,-this.zi]])}}const qt=.5;class Xt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Yt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new kt(t,i,{anchorA:s.anchorH??qt,anchorB:s.anchorH??qt,orientation:s.orientation}),yConstraint:new Ot(t,i,{anchorA:s.anchorV??qt,anchorB:s.anchorV??qt,orientation:s.orientation}),widthConstraint:new zt(t,i,{proportion:1,relation:St.GREATER_THAN,orientation:s.orientation}),heightConstraint:new Nt(t,i,{proportion:1,priority:Y.P1,orientation:s.orientation})}}}const Zt=.5;class Jt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Yt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new kt(t,i,{anchorA:s.anchorH??Zt,anchorB:s.anchorH??Zt,orientation:s.orientation}),yConstraint:new Ot(t,i,{anchorA:s.anchorV??Zt,anchorB:s.anchorV??Zt,orientation:s.orientation}),widthConstraint:new zt(t,i,{proportion:1,relation:St.LESS_THAN,orientation:s.orientation}),heightConstraint:new Nt(t,i,{proportion:1,priority:Y.P1,orientation:s.orientation})}}}class Kt extends Bt{constructor(t,i,s,e={}){super(t,e),this.Oi=i,this.Fi=s,this.constraint=this.solverWrapper.createConstraint(this.Oi,this.Fi,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Oi}get rhs(){return this.Fi}setLHS(t){this.Oi=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Oi)}setRHS(t){this.Fi=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Fi)}}class Qt extends E{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,Y.P7),this.yVariable=this.solverWrapper.createVariable(e,Y.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 ti;(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(ti||(ti={}));const ii=.5,si=ti.ROTATION_SCALE,ei=new r,hi=new v,ri=new r,ni=new o,oi=new r(0,0,1);function ai(t,i,s,e,h,r,n,o,a,c,l,u,f,d,p,v,w){const g=s-d-p,y=e-v-w,m=o*s*c,_=a*e*l,b=Math.cos(u),x=Math.sin(u),S=m*b-_*x,M=m*x+_*b,E=d*c,I=w*l,C=E*b-I*x,T=E*x+I*b;if(f===ti.POSITION_ROTATION_SCALE)ei.x=t+r-S+C,ei.y=i+n-M+T;else{const h=a*e;ei.x=t+o*s-S+r+C,ei.y=i+h-M+n+T}return ei.z=h,ri.x=g*c,ri.y=y*l,hi.setFromAxisAngle(oi,u),ni.compose(ei,hi,ri),ni}const ci=new e;var li;(t=>{t[t.DIMENSIONS_CHANGED=0]="DIMENSIONS_CHANGED"})(li||(li={}));class ui extends E{constructor(t){super(),this.Ni=ci,this.ji=2,this.$i=2,this.Gi=0,this.Yi=0,this.qi=2,this.Xi=2,this.Zi=!1,this.Ji=1,this.Ki=0,this.Qi=0,this.ts=0,this.ss=0,this.es=!1,this.hs=!1,this.rs=!1,void 0!==t&&this.set(t)}get width(){return this.ji/this.Ji}get height(){return this.$i/this.Ji}get trimmedWidth(){return(this.Zi?this.Xi:this.qi)/this.Ji}get trimmedHeight(){return(this.Zi?this.qi:this.Xi)/this.Ji}get texture(){return this.Ni}get rotated(){return this.Zi}get scale(){return this.Ji}get trim(){const t=this.Ji;return{left:this.Ki/t,right:this.Qi/t,top:this.ts/t,bottom:this.ss/t}}get textureDirty(){return this.es}get uvTransformDirty(){return this.hs}get trimDirty(){return this.rs}setTextureDirtyFalse(){this.es=!1}setUVTransformDirtyFalse(){this.hs=!1}setTrimDirtyFalse(){this.rs=!1}calculateUVTransform(t=new n){const i=this.Ni.image?.naturalWidth??2,s=this.Ni.image?.naturalHeight??2;if(this.Zi){const e=this.qi,h=e/s;t.set(0,this.Xi/i,this.Gi/i,-h,0,(s-this.Yi-e)/s+h,0,0,1)}else t.set(this.qi/i,0,this.Gi/i,0,this.Xi/s,(s-this.Yi-this.Xi)/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.ns(t):this.cs(t),this.width===i&&this.height===s||this.emit(li.DIMENSIONS_CHANGED,this.width,this.height,this)}ns(t){const i=t.image?.naturalWidth??2,s=t.image?.naturalHeight??2;this.ji=i,this.$i=s,this.texture!==t&&(this.Ni=t,this.es=!0),(0!==this.Gi||0!==this.Yi||this.qi!==i||this.Xi!==s||1!==this.Ji||this.Zi)&&(this.Gi=0,this.Yi=0,this.qi=i,this.Xi=s,this.Zi=!1,this.Ji=1,this.hs=!0),0===this.Ki&&0===this.Qi&&0===this.ts&&0===this.ss||(this.Ki=0,this.Qi=0,this.ts=0,this.ss=0,this.rs=!0)}cs(t){this.ji=t.sourceSize.w,this.$i=t.sourceSize.h,this.texture!==t.texture&&(this.Ni=t.texture,this.es=!0);const i=t.scale??1,s=t.rotated??!1;0===this.Gi&&0===this.Yi&&this.qi===t.frame.w&&this.Xi===t.frame.h&&this.Ji===i&&this.Zi===s||(this.Gi=t.frame.x,this.Yi=t.frame.y,this.qi=t.frame.w,this.Xi=t.frame.h,this.Ji=i,this.Zi=s,this.hs=!0);const e=t.spriteSourceSize,h=e.x,r=e.y,n=this.ji-e.x-e.w,o=this.$i-e.y-e.h;this.Ki===h&&this.Qi===n&&this.ts===r&&this.ss===o||(this.Ki=h,this.Qi=n,this.ts=r,this.ss=o,this.rs=!0)}}var fi,di="vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;return texture2D(p_texture,transformedUV)*p_color;}";class pi{constructor(t){this.xt=!0,this.ls=t?.x??0,this.us=t?.y??0,this.fs=t?.anchorX??ii,this.ds=t?.anchorY??ii,this.ps=t?.scaleX??1,this.vs=t?.scaleY??1,this.ws=t?.rotation??0,this.gs=t?.anchorMode??si}get x(){return this.ls}get y(){return this.us}get anchorX(){return this.fs}get anchorY(){return this.ds}get scaleX(){return this.ps}get scaleY(){return this.vs}get angle(){return i.radToDeg(this.ws)}get anchorMode(){return this.gs}get rotation(){return this.ws}get dirty(){return this.xt}set x(t){t!==this.ls&&(this.ls=t,this.xt=!0)}set y(t){t!==this.us&&(this.us=t,this.xt=!0)}set anchorX(t){t!==this.fs&&(this.fs=t,this.xt=!0)}set anchorY(t){t!==this.ds&&(this.ds=t,this.xt=!0)}set scaleX(t){t!==this.ps&&(this.ps=t,this.xt=!0)}set scaleY(t){t!==this.vs&&(this.vs=t,this.xt=!0)}set angle(t){const s=i.degToRad(t);s!==this.ws&&(this.ws=s,this.xt=!0)}set rotation(t){t!==this.ws&&(this.ws=t,this.xt=!0)}set anchorMode(t){t!==this.gs&&(this.gs=t,this.xt=!0)}setDirtyFalse(){this.xt=!1}reset(){0===this.ls&&0===this.us&&this.fs===ii&&this.ds===ii&&1===this.ps&&1===this.vs&&0===this.ws||(this.ls=0,this.us=0,this.fs=ii,this.ds=ii,this.ps=1,this.vs=1,this.ws=0,this.xt=!0)}copy(t){this.ls===t.ls&&this.us===t.us&&this.fs===t.fs&&this.ds===t.ds&&this.ps===t.ps&&this.vs===t.vs&&this.ws===t.ws&&this.gs===t.gs||(this.ls=t.ls,this.us=t.us,this.fs=t.fs,this.ds=t.ds,this.ps=t.ps,this.vs=t.vs,this.ws=t.ws,this.gs=t.gs,this.xt=!0)}}class vi{}class wi extends vi{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"})(fi||(fi={}));const gi=I.VISIBLE;class yi extends Qt{constructor(t,i){const s=i?.width??64,e=i?.height??32;super(t,i),this.ys=!1,this.catchPointerDown=(t,i,s)=>this.handleInputEvent(t,i,s,fi.PRESSED),this.catchPointerMove=(t,i,s)=>this.handleInputEvent(t,i,s,fi.MOVED),this.catchPointerUp=(t,i,s)=>this.handleInputEvent(t,i,s,fi.RELEASED),this.interactionArea=i?.interactionArea??new wi(0,0,1,1),this.modeInternal=i?.mode??gi,this.inputWrapper=this.layer.inputWrapper,this.wVariable=this.solverWrapper.createVariable(s,Y.P6),this.hVariable=this.solverWrapper.createVariable(e,Y.P6),this._s=this.inputWrapper.createInputCatcher(this.catchPointerDown,this.catchPointerMove,this.catchPointerUp,0),this.inputWrapper.setActive(this._s,T(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=T(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(t,s,e,h){const r=this.interactionArea.contains(i.mapLinear(t,this.x,this.oppositeX,0,1),i.mapLinear(s,this.y,this.oppositeY,0,1));return r&&this.emit(h,t,s,e,this),this.ys&&!r?this.emit(fi.LEFT,t,s,e,this):!this.ys&&r&&this.emit(fi.ENTERED,t,s,e,this),this.ys=r,this.modeInternal!==I.INTERACTIVE_TRANSPARENT&&r}}const mi=q.BLEND;class _i extends yi{constructor(t,i,s,e){super(t,e),this.bs=!1,this.xs=!1,this.micro=new pi(e?.micro),this.Ss=e?.transparencyMode??mi,this.sceneWrapper=this.layer.sceneWrapper,this.planeHandler=this.sceneWrapper.createPlane(i,s,this.Ss),void 0===e?.mode||P(e.mode)||(this.xs=!0),this.layer.on(Mt.RENDERING,this.onWillRender,this)}get transparencyMode(){return this.Ss}set transparencyMode(t){this.Ss!==t&&(this.Ss=t,this.bs=!0)}set mode(t){this.modeInternal!==t&&(this.xs=P(this.modeInternal)!==P(t),super.mode=t)}destroy(){this.layer.off(Mt.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,l,u,f)=>{const d=s*this.micro.scaleX,p=e*this.micro.scaleY,v=o*d,w=a*p,g=Math.cos(u),y=Math.sin(u),m=v*g-w*y,_=v*y+w*g;if(f===ti.POSITION_ROTATION_SCALE)ei.x=t+r-m,ei.y=i+n-_;else{const h=a*e;ei.x=t+o*s-m+r,ei.y=i+h-_+n}return ei.z=h,ri.x=d,ri.y=p,hi.setFromAxisAngle(oi,u),ni.compose(ei,hi,ri),ni})(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.bs&&(this.sceneWrapper.setTransparency(this.planeHandler,this.Ss),this.bs=!1),this.xs&&(this.sceneWrapper.setVisibility(this.planeHandler,P(this.modeInternal)),this.xs=!1),this.setPlaneTransform()}}var bi,xi;(t=>{t[t.PLAYED=0]="PLAYED",t[t.PAUSED=1]="PAUSED",t[t.STOPPED=2]="STOPPED"})(bi||(bi={})),(t=>{t[t.NONE=0]="NONE",t[t.LOOP=1]="LOOP",t[t.PING_PONG=2]="PING_PONG"})(xi||(xi={}));const Si=xi.LOOP;class Mi extends _i{constructor(t,i,s={}){const e=new tt(s.color),h=i.map(t=>new ui(t)),r=h[0];s.width=s.width??r.width,s.height=s.height??r.height;const n=r.calculateUVTransform();super(t,di,{texture:r.texture,textureTransform:n,color:e},s),this.Ms=!1,this.Es=0,this.Is=!1,this.Cs=0,this.Ts=(t,i,s)=>{this.Ps[this.Es]===s&&(this.width=t,this.height=i)},this.Ps=h,this.Hs=n,this.As=s.frameRate??24,this.Us=s.timeScale??1,this.Vs=s.loopMode??Si,this.color=e,this.Ds(),!0===s.playByDefault&&this.play()}get sequence(){return this.Ps}get frameRate(){return this.As}get timeScale(){return this.Us}get loopMode(){return this.Vs}get duration(){return this.Ps.length/this.As}set sequence(t){this.stop(),this.Rs();const i=t.length,s=this.Ps.length;for(let e=0;Math.min(i,s)>e;e++)this.Ps[e].set(t[e]);if(s>i)this.Ps.length=i;else if(i>s)for(let e=s;i>e;e++)this.Ps.push(new ui(t[e]));this.Ds()}set frameRate(t){this.As=t}set timeScale(t){this.Us=t}set loopMode(t){this.Vs=t}destroy(){this.Rs(),super.destroy()}play(){this.Ms||(this.Ms=!0,this.emit(bi.PLAYED))}pause(){this.Ms&&(this.Ms=!1,this.emit(bi.PAUSED))}stop(){(this.Ms||this.Cs>0||this.Es>0)&&(this.Ms=!1,this.Cs=0,this.Es=0,this.Is=!0,this.emit(bi.STOPPED))}onWillRender(t,i){if(this.Ms&&0!==this.Us){this.Cs+=i*this.Us;const t=1/this.As,s=this.Ps.length,e=s-1;if(this.Us>0)for(;this.Cs>=t;){if(this.Cs-=t,this.Es+=1,this.Es>=s)if(this.Vs===xi.LOOP)this.Es=0;else{if(this.Vs!==xi.PING_PONG){this.Es=e,this.Ms=!1,this.emit(bi.PAUSED);break}this.Es=e,this.Us=-this.Us}this.Is=!0}else for(;-t>=this.Cs;){if(this.Cs+=t,this.Es-=1,0>this.Es)if(this.Vs===xi.LOOP)this.Es=e;else{if(this.Vs!==xi.PING_PONG){this.Es=0,this.Ms=!1,this.emit(bi.PAUSED);break}this.Es=0,this.Us=-this.Us}this.Is=!0}}super.onWillRender(t,i)}setPlaneTransform(){let t;this.color.dirty&&(t??(t={}),t.color=this.color,this.color.setDirtyFalse());const i=this.Ps[this.Es];if((i.textureDirty||this.Is)&&(t??(t={}),t.texture=i.texture,i.setTextureDirtyFalse()),(i.uvTransformDirty||this.Is)&&(t??(t={}),t.textureTransform=i.calculateUVTransform(this.Hs),i.setUVTransformDirtyFalse()),t&&this.sceneWrapper.setProperties(this.planeHandler,t),this.Is||this.micro.dirty||i.trimDirty||this.inputWrapper.dirty||this.solverWrapper.dirty){const t=this.micro,s=i.trim;this.sceneWrapper.setTransform(this.planeHandler,ai(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.Is=!1,this.micro.setDirtyFalse(),i.setTrimDirtyFalse()}}Ds(){for(const t of this.Ps)t.on(li.DIMENSIONS_CHANGED,this.Ts)}Rs(){for(const t of this.Ps)t.off(li.DIMENSIONS_CHANGED,this.Ts)}}class Ei extends _i{constructor(t,i){const s=i?.width??64,e=i?.height??32,h=new tt(i?.color),r=new OffscreenCanvas(s,e),n=r.getContext("2d");if(!n)throw Error("UIGraphics.constructor: failed to get 2D context from OffscreenCanvas");const o=new w(r);o.colorSpace=g,o.minFilter=y,o.magFilter=y,o.needsUpdate=!0,super(t,di,{texture:o,textureTransform:o.matrix,color:h},i),this.Bs=r,this.Ls=n,this.ks=o,this.color=h}clear(t){return this.Ls.clearRect(0,0,this.Bs.width,this.Bs.height),void 0!==t&&(this.Ls.fillStyle=t.toCSSColor(),this.Ls.fillRect(0,0,this.Bs.width,this.Bs.height)),this.ks.needsUpdate=!0,this}drawRect(t,i,s,e,h){return this.Ls.fillStyle=h.toCSSColor(),this.Ls.fillRect(t,i,s,e),this.ks.needsUpdate=!0,this}drawCircle(t,i,s,e){return this.Ls.fillStyle=e.toCSSColor(),this.Ls.beginPath(),this.Ls.arc(t,i,s,0,2*Math.PI),this.Ls.fill(),this.ks.needsUpdate=!0,this}drawArc(t,i,s,e,h,r){return this.Ls.fillStyle=r.toCSSColor(),this.Ls.beginPath(),this.Ls.arc(t,i,s,e,h),this.Ls.fill(),this.ks.needsUpdate=!0,this}drawPolyline(t,i,s=1){if(2>t.length)return this;this.Ls.strokeStyle=i.toCSSColor(),this.Ls.lineWidth=s,this.Ls.beginPath(),this.Ls.moveTo(t[0][0],t[0][1]);for(let i=1;t.length>i;i++)this.Ls.lineTo(t[i][0],t[i][1]);return this.Ls.stroke(),this.ks.needsUpdate=!0,this}destroy(){this.ks.dispose(),super.destroy()}onWillRender(t,i){this.color.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.color}),this.color.setDirtyFalse()),super.onWillRender(t,i)}}class Ii extends _i{constructor(t,i,s={}){const e=new tt(s.color),h=new ui(i),r=h.calculateUVTransform();s.width=s.width??h.width,s.height=s.height??h.height,super(t,di,{texture:h.texture,textureTransform:r,color:e},s),this.Ts=(t,i)=>{this.width=t,this.height=i},this.texture=h,this.Hs=r,this.color=e,this.texture.on(li.DIMENSIONS_CHANGED,this.Ts)}destroy(){this.texture.off(li.DIMENSIONS_CHANGED,this.Ts),super.destroy()}setPlaneTransform(){let t;if(this.color.dirty&&(t??(t={}),t.color=this.color,this.color.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.Hs),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,ai(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 Ci{constructor(t){if(this.xt=!1,void 0===t)this.bt=0,this.dt=0,this.Bi=0,this.wt=0;else if("number"==typeof t)this.bt=t,this.dt=t,this.Bi=t,this.wt=t;else if("left"in t){const i=t.right,s=t.top,e=t.bottom;this.bt=t.left,this.dt=i,this.Bi=s,this.wt=e}else{const i=t.horizontal,s=t.vertical;this.bt=i,this.dt=i,this.Bi=s,this.wt=s}}get left(){return this.bt}get right(){return this.dt}get top(){return this.Bi}get bottom(){return this.wt}get dirty(){return this.xt}set left(t){this.bt!==t&&(this.bt=t,this.xt=!0)}set right(t){this.dt!==t&&(this.dt=t,this.xt=!0)}set top(t){this.Bi!==t&&(this.Bi=t,this.xt=!0)}set bottom(t){this.wt!==t&&(this.wt=t,this.xt=!0)}setHorizontal(t){this.bt===t&&this.dt===t||(this.bt=t,this.dt=t,this.xt=!0)}setVertical(t){this.Bi===t&&this.wt===t||(this.Bi=t,this.wt=t,this.xt=!0)}setUnified(t){this.bt===t&&this.dt===t&&this.Bi===t&&this.wt===t||(this.bt=t,this.dt=t,this.Bi=t,this.wt=t,this.xt=!0)}setVector4(t){this.bt===t.x&&this.dt===t.y&&this.Bi===t.z&&this.wt===t.w||(this.bt=t.x,this.dt=t.y,this.Bi=t.z,this.wt=t.w,this.xt=!0)}toVector4(t=new s){return t.set(this.bt,this.dt,this.Bi,this.wt)}reset(){this.setUnified(0)}copy(t){this.bt===t.bt&&this.dt===t.dt&&this.Bi===t.Bi&&this.wt===t.wt||(this.bt=t.bt,this.dt=t.dt,this.Bi=t.Bi,this.wt=t.wt,this.xt=!0)}setDirtyFalse(){this.xt=!1}}var Ti;(t=>{t[t.NORMALIZED=0]="NORMALIZED",t[t.WORLD=1]="WORLD"})(Ti||(Ti={}));const Pi=Ti.WORLD;class Hi extends _i{constructor(t,i,e={}){const h=new tt(e.color),r=new ui(i),n=r.calculateUVTransform();e.width=e.width??r.width,e.height=e.height??r.height;const o=new Ci(e.sliceBorders??.1),a=new Ci(e.sliceRegions??.1),c=e.regionMode??Pi,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 texture2D(p_texture,transformedUV)*p_color;}",{texture:r.texture,textureTransform:n,color:h,sliceBorders:l,sliceRegions:u},e),this.Ws=!0,this.zs=new s,this.Os=new s,this.Fs=!0,this.Ts=()=>{this.Fs=!0},this.texture=r,this.Hs=n,this.color=h,this.sliceBorders=o,this.sliceRegions=a,this.Ns=c,this.zs=l,this.Os=u,this.js=this.width,this.$s=this.height,this.texture.on(li.DIMENSIONS_CHANGED,this.Ts)}get regionMode(){return this.Ns}set regionMode(t){this.Ns!==t&&(this.Ns=t,this.Ws=!0)}destroy(){this.texture.off(li.DIMENSIONS_CHANGED,this.Ts),super.destroy()}setPlaneTransform(){let t;if((this.Fs||this.sliceBorders.dirty||this.texture.trimDirty)&&(t??(t={}),t.sliceBorders=this.Gs(this.zs),this.sliceBorders.setDirtyFalse(),this.Fs=!1),(this.sliceRegions.dirty||this.Ws||this.Ns===Ti.WORLD&&this.Ys())&&(t??(t={}),t.sliceRegions=this.qs(this.Os),this.sliceRegions.setDirtyFalse(),this.Ws=!1,this.Xs()),this.color.dirty&&(t??(t={}),t.color=this.color,this.color.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.Hs),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,ai(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()}}Gs(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.sliceBorders.right,l=this.sliceBorders.top,u=this.sliceBorders.bottom,f=Math.max(0,this.sliceBorders.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))}qs(t){if(this.Ns===Ti.NORMALIZED)return t.set(this.sliceRegions.left,this.sliceRegions.right,this.sliceRegions.top,this.sliceRegions.bottom);const i=this.width,s=this.height;return t.set(this.sliceRegions.left/i,this.sliceRegions.right/i,this.sliceRegions.top/s,this.sliceRegions.bottom/s)}Ys(){return this.solverWrapper.dirty&&(this.js!==Math.round(this.width)||this.$s!==Math.round(this.height))}Xs(){this.js=Math.round(this.width),this.$s=Math.round(this.height)}}class Ai{constructor(t){this.source=t,this.dirtyInternal=!1}get dirty(){return this.dirtyInternal}setDirtyFalse(){this.dirtyInternal=!1}}class Ui extends Ai{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.Zs=new h,this.direction.copy(t).normalize(),this.Zs.copy(this.direction)}get dirty(){return this.Js(),this.dirtyInternal||!this.Zs.equals(this.direction)}setDirtyFalse(){this.Js(),this.Zs.copy(this.direction),super.setDirtyFalse()}enumerateProperties(){return this.Js(),{direction:this.direction}}Js(){const t=this.direction.lengthSq();Math.abs(t)>At?Math.abs(t-1)>At&&this.direction.divideScalar(t):this.direction.set(1,0)}}class Vi extends _i{constructor(t,s,e={}){const h=new tt(e.color),r=new ui(s),n=r.calculateUVTransform(),o=r.getResolution();e.width=e.width??r.width,e.height=e.height??r.height;const a=i.clamp(e.progress??1,0,1),c=e.maskFunction??new Ui;super(t,c.source+"vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=texture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}",{texture:r.texture,textureTransform:n,textureResolution:o,color:h,progress:a,...c.enumerateProperties()},e),this.Ks=!1,this.Qs=!1,this.Ts=(t,i)=>{this.width===t&&this.height===i||(this.width=t,this.height=i,this.Qs=!0)},this.texture=r,this.Hs=n,this.te=o,this.color=h,this.ie=a,this.maskFunction=c,this.texture.on(li.DIMENSIONS_CHANGED,this.Ts)}get progress(){return this.ie}set progress(t){t=i.clamp(t,0,1),this.ie!==t&&(this.ie=t,this.Ks=!0)}setPlaneTransform(){let t;if(this.color.dirty&&(t??(t={}),t.color=this.color,this.color.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.Hs),this.texture.setUVTransformDirtyFalse()),this.Ks&&(t??(t={}),t.progress=this.ie,this.Ks=!1),this.Qs&&(t??(t={}),t.textureResolution=this.texture.getResolution(this.te),this.Qs=!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,ai(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()}}}var Di;(t=>{t[t.EACH_FRAME=1]="EACH_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"})(Di||(Di={}));const Ri=Di.ON_PROPERTIES_CHANGE,Bi=new tt(0,0,0,1);class Li extends _i{constructor(t,s={}){const e=i.clamp(s.resolutionFactor??.5,.1,2),h=s.width??64,r=s.height??32,o=new m(h*e,r*e,{format:b,minFilter:y,magFilter:y,type:_,depthBuffer:s.enableDepthBuffer??!0,stencilBuffer:!1}),a=new tt(s.color);super(t,di,{texture:o.texture,textureTransform:new n,color:a},s),this.se=!0,this.ee=!1,this.he=!1,this.re=!1,this.color=a,this.clearColor=new tt(s.clearColor??Bi),this.ne=o,this.oe=s.scene??new d,this.ae=s.camera??new x(60,h/r,.1,100),this.ce=e,this.le=s.updateMode??Ri,this.re=s.updateMode!==Di.MANUAL}get scene(){return this.oe}get camera(){return this.ae}get updateMode(){return this.le}get resolutionFactor(){return this.ce}set scene(t){this.oe!==t&&(this.oe=t,this.re=!0)}set camera(t){this.ae!==t&&(this.ae=t,this.re=!0)}set updateMode(t){this.le!==t&&(this.le=t,this.re=!0)}set resolutionFactor(t){t=i.clamp(t,.1,2),this.ce!==t&&(this.ce=t,this.he=!0)}destroy(){this.ne.dispose(),super.destroy()}requestUpdate(){this.ee=!0}onWillRender(t,i){this.se=!this.se,(this.ee||this.le===Di.EACH_FRAME||this.le===Di.EVERY_SECOND_FRAME&&this.se||this.le===Di.ON_PROPERTIES_CHANGE&&this.re||this.color.dirty||this.clearColor.dirty||this.le===Di.ON_DIMENSIONS_CHANGE&&(this.he||this.solverWrapper.dirty))&&((this.he||this.solverWrapper.dirty)&&(this.ne.setSize(this.width*this.ce,this.height*this.ce),this.he=!1),this.color.dirty&&(this.sceneWrapper.setProperties(this.planeHandler,{color:this.color}),this.color.setDirtyFalse()),t.setClearColor(this.clearColor.getHexRGB(),this.clearColor.a),t.setRenderTarget(this.ne),t.clear(!0,!0,!1),t.render(this.oe,this.ae),this.re=!1,this.ee=!1),super.onWillRender(t,i)}}const ki="#000000",Wi="left",zi="Arial",Oi="normal",Fi="normal",Ni=!1,ji="transparent",$i=!1,Gi="#000000";class Yi{constructor(t){this.xt=!0,this.ue=t?.color,this.fe=t?.align,this.de=t?.fontFamily,this.pe=t?.fontSize,this.ve=t?.fontStyle,this.we=t?.fontWeight,this.ge=t?.lineHeight,this.ye=t?.enableShadow,this.me=t?.shadowOffsetX,this._e=t?.shadowOffsetY,this.be=t?.shadowBlur,this.xe=t?.shadowColor,this.Se=t?.enableStroke,this.Me=t?.strokeColor,this.Ee=t?.strokeThickness}get color(){return this.ue}get align(){return this.fe}get fontFamily(){return this.de}get fontSize(){return this.pe}get fontStyle(){return this.ve}get fontWeight(){return this.we}get lineHeight(){return this.ge}get enableShadow(){return this.ye}get shadowOffsetX(){return this.me}get shadowOffsetY(){return this._e}get shadowBlur(){return this.be}get shadowColor(){return this.xe}get enableStroke(){return this.Se}get strokeColor(){return this.Me}get strokeThickness(){return this.Ee}get dirty(){return this.xt}set color(t){t!==this.ue&&(this.ue=t,this.xt=!0)}set align(t){t!==this.fe&&(this.fe=t,this.xt=!0)}set fontFamily(t){t!==this.de&&(this.de=t,this.xt=!0)}set fontSize(t){t!==this.pe&&(this.pe=t,this.xt=!0)}set fontStyle(t){t!==this.ve&&(this.ve=t,this.xt=!0)}set fontWeight(t){t!==this.we&&(this.we=t,this.xt=!0)}set lineHeight(t){t!==this.ge&&(this.ge=t,this.xt=!0)}set enableShadow(t){t!==this.ye&&(this.ye=t,this.xt=!0)}set shadowOffsetX(t){t!==this.me&&(this.me=t,this.xt=!0)}set shadowOffsetY(t){t!==this._e&&(this._e=t,this.xt=!0)}set shadowBlur(t){t!==this.be&&(this.be=t,this.xt=!0)}set shadowColor(t){t!==this.xe&&(this.xe=t,this.xt=!0)}set enableStroke(t){t!==this.Se&&(this.Se=t,this.xt=!0)}set strokeColor(t){t!==this.Me&&(this.Me=t,this.xt=!0)}set strokeThickness(t){t!==this.Ee&&(this.Ee=t,this.xt=!0)}static resolve(t,i){const s=t.pe??i.pe??16;return{color:t.ue??i.ue??ki,align:t.fe??i.fe??Wi,fontFamily:t.de??i.de??zi,fontSize:s,fontStyle:t.ve??i.ve??Oi,fontWeight:t.we??i.we??Fi,lineHeight:t.ge??i.ge??1.2*s,enableShadow:t.ye??i.ye??Ni,shadowOffsetX:t.me??i.me??0,shadowOffsetY:t._e??i._e??0,shadowBlur:t.be??i.be??0,shadowColor:t.xe??i.xe??ji,enableStroke:t.Se??i.Se??$i,strokeColor:t.Me??i.Me??Gi,strokeThickness:t.Ee??i.Ee??0}}setDirtyFalse(){this.xt=!1}setDefaults(){this.ue===ki&&this.fe===Wi&&this.de===zi&&16===this.pe&&this.ve===Oi&&this.we===Fi&&19.2===this.ge&&this.ye===Ni&&0===this.me&&0===this._e&&0===this.be&&this.xe===ji&&this.Se===$i&&this.Me===Gi&&0===this.Ee||(this.ue=ki,this.fe=Wi,this.de=zi,this.pe=16,this.ve=Oi,this.we=Fi,this.ge=19.2,this.ye=Ni,this.me=0,this._e=0,this.be=0,this.xe=ji,this.Se=$i,this.Me=Gi,this.Ee=0,this.xt=!0)}clear(){void 0===this.ue&&void 0===this.fe&&void 0===this.de&&void 0===this.pe&&void 0===this.ve&&void 0===this.we&&void 0===this.ge&&void 0===this.ye&&void 0===this.me&&void 0===this._e&&void 0===this.be&&void 0===this.xe&&void 0===this.Se&&void 0===this.Me&&void 0===this.Ee||(this.ue=void 0,this.fe=void 0,this.de=void 0,this.pe=void 0,this.ve=void 0,this.we=void 0,this.ge=void 0,this.ye=void 0,this.me=void 0,this._e=void 0,this.be=void 0,this.xe=void 0,this.Se=void 0,this.Me=void 0,this.Ee=void 0,this.xt=!0)}copy(t){this.ue===t.ue&&this.fe===t.fe&&this.de===t.de&&this.pe===t.pe&&this.ve===t.ve&&this.we===t.we&&this.ge===t.ge&&this.ye===t.ye&&this.me===t.me&&this._e===t._e&&this.be===t.be&&this.xe===t.xe&&this.Se===t.Se&&this.Me===t.Me&&this.Ee===t.Ee||(this.ue=t.ue,this.fe=t.fe,this.de=t.de,this.pe=t.pe,this.ve=t.ve,this.we=t.we,this.ge=t.ge,this.ye=t.ye,this.me=t.me,this._e=t._e,this.be=t.be,this.xe=t.xe,this.Se=t.Se,this.Me=t.Me,this.Ee=t.Ee,this.xt=!0)}calculatePadding(){let t=0;if(void 0!==this.Se&&(t+=this.Ee??0),void 0!==this.ye){const i=this._e??0,s=2*(this.be??0);t+=Math.max(Math.abs(this.me??0)+s,Math.abs(i)+s)}return Math.ceil(t)}}class qi{constructor(t){this.xt=!0,this.Ie=t.text,this.style=new Yi(t.style)}get text(){return this.Ie}get dirty(){return this.xt||this.style.dirty}set text(t){t!==this.Ie&&(this.Ie=t,this.xt=!0)}setDirtyFalse(){this.xt=!1,this.style.setDirtyFalse()}}var Xi;(t=>{t[t.BREAK=0]="BREAK",t[t.SCALE=1]="SCALE"})(Xi||(Xi={}));const Zi=Xi.SCALE;function Ji(t){return t.match(/\S+|\s|\n/g)??[]}function Ki(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 Qi(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 ts(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 is(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??Wi,a=n.chunks.every(t=>t.style.align===o)?o:Wi;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)ts(l,h,t.text,t.style,e),l+=t.metrics.width}}class ss extends _i{constructor(t,i,s={}){const e=new OffscreenCanvas(2,2),h=e.getContext("2d");if(!h)throw Error("UIText.constructor: failed to create canvas context");const r=new w(e);r.colorSpace=g,r.needsUpdate=!0;const o=new tt(s.color);switch(super(t,di,{texture:r,textureTransform:new n,color:o}),this.Ce=[],this.Te=!1,this.Pe=!1,this.He=!1,this.Ae=[],this.Ue=!1,this.color=o,this.padding=new Ci(s.padding),this.commonStyle=new Yi(s.commonStyle),this.Ve=s.maxLineWidth??1024,this.De=s.resizeMode??Zi,this.Bs=e,this.Ls=h,this.ks=r,this.content=i,this.Re=this.width,this.Be=this.height,void 0===s.padding&&this.padding.setUnified(this.content.reduce((t,i)=>Math.max(t,i.style.calculatePadding()),this.commonStyle.calculatePadding())),this.De){case Xi.SCALE:this.ke();break;case Xi.BREAK:this.We()}}get content(){return this.Ce}get maxLineWidth(){return this.Ve}get resizeMode(){return this.De}set content(t){this.Ce!==t&&(this.Ce="string"==typeof t?[new qi({text:t,style:new Yi})]:Array.isArray(t)?t.map(t=>new qi("string"==typeof t?{text:t,style:new Yi}:{text:t.text,style:new Yi(t.style)})):[new qi({text:t.text,style:new Yi(t.style)})],this.Te=!0,this.Ue=!0)}set maxLineWidth(t){this.Ve!==t&&(this.Ve=t,this.Pe=!0)}set resizeMode(t){this.De!==t&&(this.De=t,this.He=!0)}destroy(){this.ks.dispose(),super.destroy()}onWillRender(t,i){switch(this.De){case Xi.SCALE:this.ke();break;case Xi.BREAK:this.We()}super.onWillRender(t,i)}ke(){if(!(this.He||this.Pe||this.padding.dirty||this.solverWrapper.dirty&&this.Re/this.Be!==Math.round(this.width)/Math.round(this.height)||this.ze()))return;const t=this.Oe(),{lines:i,size:s}=Qi(t,this.Ve),e=s.height+(this.padding.top+this.padding.bottom),h=s.width+(this.padding.left+this.padding.right);this.width=h,this.height=e/h*Math.round(this.width),this.width=h/e*Math.round(this.height);const r=this.Re!==e||this.Be!==h;r&&(this.Bs.height=e,this.Bs.width=h),is(this.padding.top,this.padding.left,i,this.Ls),this.Fe(r),this.He=!1,this.Pe=!1,this.padding.setDirtyFalse(),this.Ne(),this.je()}We(){if(!(this.He||this.Pe||this.padding.dirty||this.$e()||this.ze()))return;const t=this.Oe(),{size:i}=Qi(t,this.Ve),s=this.padding.top+this.padding.bottom,e=this.padding.left+this.padding.right;this.height=i.height+s,this.width=i.width+e;const{lines:h,size:r}=Qi(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.Re!==n||this.Be!==o;a&&(this.Bs.width=n,this.Bs.height=o),is(this.padding.top,this.padding.left,h,this.Ls),this.Fe(a),this.He=!1,this.Pe=!1,this.padding.setDirtyFalse(),this.Ne(),this.je()}Fe(t){let i;this.color.dirty&&(i??(i={}),i.color=this.color,this.color.setDirtyFalse()),t&&(this.ks.dispose(),this.ks=new w(this.Bs),this.ks.colorSpace=g,this.ks.needsUpdate=!0,i??(i={}),i.texture=this.ks),i&&this.sceneWrapper.setProperties(this.planeHandler,i)}Oe(){return this.Ue&&(this.Ae=((t,i,s)=>{const e=[];for(const h of i){const i=Yi.resolve(h.style,s);for(const s of Ji(h.text)){const h=Ki(t,s,i);e.push({text:s,style:i,metrics:h})}}return e})(this.Ls,this.Ce,this.commonStyle),this.Ue=!1),this.Ae}$e(){return this.solverWrapper.dirty&&(this.Re!==Math.round(this.width)||this.Be!==Math.round(this.height))}Ne(){this.Re=Math.round(this.width),this.Be=Math.round(this.height)}ze(){return this.Te||this.content.some(t=>t.dirty)}je(){this.Te=!1;for(const t of this.content)t.setDirtyFalse()}}class es{constructor(){this.dirty=!1}}class hs extends es{calculateScale(t,i){return 1}}const rs=new hs;class ns extends Ct{constructor(t){const i=t?.resizePolicy??rs,s=i.calculateScale(window.innerWidth,window.innerHeight);super({width:window.innerWidth*s,height:window.innerHeight*s,...t}),this.Ye=!1,this.qe=()=>{const t=this.resizePolicy.calculateScale(window.innerWidth,window.innerHeight);this.resizePolicy.dirty=!1,this.Ye=!1,this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Xe=t=>{this.Ze(t,"onPointerDown",fi.PRESSED)},this.Je=t=>{this.Ze(t,"onPointerMove",fi.MOVED)},this.Ke=t=>{this.Ze(t,"onPointerUp",fi.RELEASED)},this.Qe=i,window.addEventListener("resize",this.qe),window.addEventListener("pointerdown",this.Xe),window.addEventListener("pointermove",this.Je),window.addEventListener("pointerup",this.Ke)}get resizePolicy(){return this.Qe}set resizePolicy(t){this.Qe!==t&&(this.Qe=t,this.Ye=!0)}destroy(){window.removeEventListener("resize",this.qe),window.removeEventListener("pointerdown",this.Xe),window.removeEventListener("pointermove",this.Je),window.removeEventListener("pointerup",this.Ke)}render(t,i){(this.resizePolicy.dirty||this.Ye)&&this.qe(),super.renderInternal(t,i)}projectWorldPosition(t,s){const e=t.clone().project(s);return e.x=i.mapLinear(e.x,-1,1,this.x,this.width),e.y=i.mapLinear(e.y,-1,1,this.y,this.height),e}projectLayerPosition(t,s,e=-1){return new r(i.mapLinear(t.x,this.x,this.width,-1,1),i.mapLinear(t.y,this.y,this.height,-1,1),e).unproject(s)}buildRay(t,s,e=new S){const h=new r(i.mapLinear(t.x,this.x,this.width,-1,1),i.mapLinear(t.y,this.y,this.height,-1,1),-1).unproject(s),n=new r(i.mapLinear(t.x,this.x,this.width,-1,1),i.mapLinear(t.y,this.y,this.height,-1,1),1).unproject(s).sub(h).normalize();return e.set(h,n)}Ze(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;T(this.mode)&&(this.emit(s,o,a,t.pointerId),this.inputWrapperInternal[i](o,a,t.pointerId))}}class os extends vi{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 as extends vi{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 vi{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 ls extends Ai{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.th=t,this.ih=i}get startAngle(){return this.th}get inverseDirection(){return this.ih}set startAngle(t){this.th!==t&&(this.th=t,this.dirtyInternal=!0)}set inverseDirection(t){this.ih!==t&&(this.ih=t,this.dirtyInternal=!0)}enumerateProperties(){return{direction:this.ih?-1:1,startAngle:this.th}}}class us extends es{constructor(t,i){super(),this.sh=t,this.eh=i}get rectWidth(){return this.sh}get rectHeight(){return this.eh}set rectWidth(t){t!==this.sh&&(this.sh=t,this.dirty=!0)}set rectHeight(t){t!==this.eh&&(this.eh=t,this.dirty=!0)}calculateScale(t,i){return Math.min(this.sh/t,this.eh/i)}}class fs extends es{constructor(t,i){super(),this.hh=t,this.rh=i}get fixedWidthLandscape(){return this.hh}get fixedHeightPortrait(){return this.rh}set fixedWidthLandscape(t){t!==this.hh&&(this.hh=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.rh&&(this.rh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.hh/t:this.rh/i}}class ds extends es{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 ps extends es{constructor(t,i){super(),this.sh=t,this.eh=i}get rectWidth(){return this.sh}get rectHeight(){return this.eh}set rectWidth(t){t!==this.sh&&(this.sh=t,this.dirty=!0)}set rectHeight(t){t!==this.eh&&(this.eh=t,this.dirty=!0)}calculateScale(t,i){return Math.max(this.sh/t,this.eh/i)}}class vs extends es{constructor(t,i){super(),this.nh=t,this.rh=i}get fixedHeightLandscape(){return this.nh}get fixedHeightPortrait(){return this.rh}set fixedHeightLandscape(t){t!==this.nh&&(this.nh=t,this.dirty=!0)}set fixedHeightPortrait(t){t!==this.rh&&(this.rh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.nh/i:this.rh/i}}class ws extends es{constructor(t,i){super(),this.hh=t,this.oh=i}get fixedWidthLandscape(){return this.hh}get fixedWidthPortrait(){return this.oh}set fixedWidthLandscape(t){t!==this.hh&&(this.hh=t,this.dirty=!0)}set fixedWidthPortrait(t){t!==this.oh&&(this.oh=t,this.dirty=!0)}calculateScale(t,i){return t>i?this.hh/t:this.oh/t}}export{Qt as UIAnchor,Mi as UIAnimatedImage,os as UIAreaCircle,as as UIAreaPolygon,wi as UIAreaRectangle,cs as UIAreaRoundedRectangle,Yt as UIAspectConstraint,tt as UIColor,Gt as UIConstraint2DBuilder,Xt as UICoverConstraintBuilder,Kt as UICustomConstraint,xt as UIExpression,Jt as UIFitConstraintBuilder,ns as UIFullscreenLayer,Ei as UIGraphics,Lt as UIHeightConstraint,kt as UIHorizontalDistanceConstraint,Wt as UIHorizontalInterpolationConstraint,zt as UIHorizontalProportionConstraint,Ii as UIImage,yi as UIInputDummy,fi as UIInputEvent,xi as UILoopMode,pi as UIMicro,ti as UIMicroAnchorMode,I as UIMode,Hi as UINineSlice,Ti as UINineSliceRegionMode,C as UIOrientation,Y as UIPriority,Vi as UIProgress,ls as UIProgressMaskFunctionCircular,Ui as UIProgressMaskFunctionDirectional,St as UIRelation,us as UIResizePolicyCover,fs as UIResizePolicyCross,ds as UIResizePolicyCrossInverted,ps as UIResizePolicyFit,vs as UIResizePolicyFixedHeight,ws as UIResizePolicyFixedWidth,hs as UIResizePolicyNone,Li as UIScene,Di as UISceneUpdateMode,Bt as UISingleParameterConstraint,ss as UIText,Xi as UITextResizeMode,q as UITransparencyMode,Ot as UIVerticalDistanceConstraint,Ft as UIVerticalInterpolationConstraint,Nt as UIVerticalProportionConstraint,jt as UIWidthConstraint};
2
2
  //# sourceMappingURL=index.min.js.map