laymur 0.2.17 → 0.3.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 (43) hide show
  1. package/README.md +31 -24
  2. package/dist/builders/UIConstraint2DBuilder.d.ts +1 -1
  3. package/dist/builders/UICoverConstraintBuilder.d.ts +3 -1
  4. package/dist/builders/UIFitConstraintBuilder.d.ts +3 -1
  5. package/dist/constraints/UIAspectConstraint.d.ts +0 -1
  6. package/dist/constraints/UIConstraint.d.ts +3 -0
  7. package/dist/constraints/UIHorizontalDistanceConstraint.d.ts +0 -1
  8. package/dist/constraints/UIHorizontalProportionConstraint.d.ts +2 -3
  9. package/dist/constraints/UISingleParameterConstraint.d.ts +0 -2
  10. package/dist/constraints/UIVerticalDistanceConstraint.d.ts +0 -1
  11. package/dist/constraints/UIVerticalProportionConstraint.d.ts +2 -3
  12. package/dist/elements/UIDummy.d.ts +7 -1
  13. package/dist/elements/UIElement.d.ts +52 -38
  14. package/dist/elements/UIImage.d.ts +30 -42
  15. package/dist/elements/UINineSline.d.ts +61 -68
  16. package/dist/elements/UIProgress.d.ts +86 -110
  17. package/dist/elements/UIScene.d.ts +21 -30
  18. package/dist/elements/UIText.d.ts +27 -41
  19. package/dist/index.d.ts +4 -1
  20. package/dist/index.js +1237 -942
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.min.js +1 -1
  23. package/dist/index.min.js.map +1 -1
  24. package/dist/layers/UIFullscreenLayer.d.ts +0 -4
  25. package/dist/layers/UILayer.d.ts +50 -3
  26. package/dist/miscellaneous/UIColor.d.ts +171 -0
  27. package/dist/miscellaneous/UIInputEvent.d.ts +7 -0
  28. package/dist/miscellaneous/UIMicro.d.ts +3 -3
  29. package/dist/miscellaneous/{UIAnchorMode.d.ts → UIMicroAnchorMode.d.ts} +1 -1
  30. package/dist/miscellaneous/UINineSliceBorder.d.ts +6 -6
  31. package/dist/miscellaneous/UISceneWrapperClientAPI.d.ts +10 -0
  32. package/dist/miscellaneous/UITextPadding.d.ts +1 -1
  33. package/dist/miscellaneous/UITransparencyMode.d.ts +26 -0
  34. package/dist/miscellaneous/textTools.d.ts +4 -4
  35. package/dist/scalable/UIScalableMesh.d.ts +0 -16
  36. package/dist/scalable/UIScalablePlaneMesh.d.ts +0 -14
  37. package/dist/wrappers/UISceneWrapper.d.ts +17 -15
  38. package/dist/wrappers/UISolverWrapper.d.ts +185 -0
  39. package/package.json +1 -1
  40. package/dist/materials/UIMaterial.d.ts +0 -13
  41. package/dist/materials/UINineSliceMaterial.d.ts +0 -27
  42. package/dist/materials/UIProgressMaterial.d.ts +0 -29
  43. package/dist/miscellaneous/threeInstances.d.ts +0 -2
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Color as t,Scene as i,OrthographicCamera as e,MathUtils as s,ShaderMaterial as r,PlaneGeometry as n,Mesh as o,Vector2 as h,Vector4 as a,UniformsUtils as u,WebGLRenderTarget as l,UnsignedByteType as c,LinearFilter as d,RGBAFormat as f,PerspectiveCamera as g,CanvasTexture as p}from"three";class v{constructor(t=0,i){this.constant=t,this.C=i?new Map(i):new Map}static plus(t,i){const e=new v(t.constant+i.constant,Array.from(t.C.entries()));for(const[t,s]of i.C)e.plus(t,s);return e}static minus(t,i){const e=new v(t.constant-i.constant,Array.from(t.C.entries()));for(const[t,s]of i.C)e.minus(t,s);return e}plus(t,i){return this.C.set(t,(this.C.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,e]of this.C)this.C.set(i,e*t);return this}divide(t){return this.multiply(1/t)}hasTerm(t){return this.C.has(t)}copy(t){this.constant=t.constant,this.C.clear();for(const[i,e]of t.C)this.C.set(i,e);return this}clone(){return new v(this.constant,Array.from(this.C.entries()))}prepareTermsInternal(){return Array.from(this.C.entries())}}class w{constructor(t,i,e=0){this.t=new WeakMap,this.i=new Map,void 0!==t&&(void 0===i?this.i.set(t,e):this.t.set(i,new Map([[t,e]])))}insert(t,i,e=0){if(void 0===i){if(this.i.has(t))return;return void this.i.set(t,e)}const s=this.t.get(i);void 0===s?this.t.set(i,new Map([[t,e]])):s.has(t)||s.set(t,e)}remove(t,i){if(void 0===i)return void this.i.delete(t);const e=this.t.get(i);void 0!==e&&(e.delete(t),0===e.size&&this.t.delete(i))}has(t,i){if(void 0===i)return this.i.has(t);const e=this.t.get(i);return void 0!==e&&e.has(t)}getPriority(t,i){if(void 0===i)return this.i.get(t);const e=this.t.get(i);return void 0!==e?e.get(t):void 0}}class y{constructor(){this.o=new Map}on(t,i,e,s=0){return this.h(t,!1,s,i,e),this}once(t,i,e,s=0){return this.h(t,!0,s,i,e),this}off(t,i,e){const s=this.o.get(t);if(void 0===s)return this;s.u&&(s.u=!1,s.v=s.v.slice());const r=s.v;if(0===r.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;r.length>t;t++){const i=r[t];s.l.remove(i._,i.p)}return this}{const n=r.length;if(r[0]._===i&&r[0].p===e)return 1===n?this.o.delete(t):r.shift(),this;const o=n-1;if(r[o]._===i&&r[o].p===e)return r.pop(),this;if(10>n||r[0].M===r[o].M)for(let t=1;o>t;t++){const s=r[t];if(s._===i&&s.p===e)return r.splice(t,1),this}else{const t=s.l.getPriority(i,e);if(void 0===t)return this;let n=0,o=r.length-1;for(;o>=n;){const i=n+o>>>1;t>r[i].M?n=i+1:o=i-1}const h=n;for(o=r.length-1;o>=n;){const i=n+o>>>1;r[i].M>t?o=i-1:n=i+1}const a=o;for(let t=h;a>=t;t++)if(r[t]._===i&&r[t].p===e)return r.splice(t,1),this}}return this}emit(t,...i){const e=this.o.get(t);if(void 0===e)return!1;if(0===e.v.length)return!1;e.u?e.v=e.v.slice():e.u=!0;const s=e.v;let r=!1;for(let t=0;s.length>t;t++){const e=s[t];e._.apply(e.p,i),e.k&&(r=!0,e.m=!0)}const n=this.o.get(t);if(void 0===n)return!0;n.v===s&&(n.u=!1);const o=n.v;if(r){let i=0;for(let t=0;o.length>t;t++){const e=o[t];e.m?n.l.remove(e._,e.p):o[i++]=e}0===i?this.o.delete(t):o.length=i}return!0}h(t,i,e,s,r){let n=this.o.get(t);if(void 0===n)return void this.o.set(t,{v:[{_:s,p:r,M:e,k:i,m:!1}],u:!1,l:new w(s,r,e)});if(n.l.has(s,r))throw Error("Event listener already exists");n.l.insert(s,r,e);const o={_:s,p:r,M:e,k:i,m:!1};n.u&&(n.u=!1,n.v=n.v.slice());{const t=n.v,i=o.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(o);if(t[0].M>=i)return void t.unshift(o);{let e=0,s=t.length;for(;s>e;){const r=e+s>>>1;i>t[r].M?e=r+1:s=r}t.splice(e,0,o)}}}}var m,b;function x(t){return t??b.ALWAYS}function E(){return new C}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(m||(m={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(b||(b={}));class C{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 e=this.index[t.id()];if(void 0===e){const e=new _(t,i());return this.index[t.id()]=this.array.length,this.array.push(e),e}return this.array[e]}insert(t,i){const e=new _(t,i),s=this.index[t.id()];return void 0===s?(this.index[t.id()]=this.array.length,this.array.push(e)):this.array[s]=e,e}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const e=this.array[i],s=this.array.pop();return e!==s&&(this.array[i]=s,this.index[s.first.id()]=i),e}copy(){const t=new C;for(let i=0;this.array.length>i;i++){const e=this.array[i].copy();t.array[i]=e,t.index[e.first.id()]=i}return t}}class _{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new _(this.first,this.second)}}class S{constructor(t=""){this.S=t}id(){return this.B}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 I(this,t)}minus(t){return new I(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new I([t,this])}divide(t){return new I([1/t,this])}toJSON(){return{name:this.S,value:this.T}}toString(){return this.I+"["+this.S+":"+this.T+"]"}S;T=0;I=null;B=B++}let B=0;class I{constructor(){let t=(t=>{let i=0,e=()=>0,s=E();for(let r=0,n=t.length;n>r;++r){let n=t[r];if("number"==typeof n)i+=n;else if(n instanceof S)s.setDefault(n,e).second+=1;else if(n instanceof I){i+=n.constant();let t=n.terms();for(let i=0,r=t.size();r>i;i++){let r=t.itemAt(i);s.setDefault(r.first,e).second+=r.second}}else{if(!(n instanceof Array))throw Error("invalid Expression argument: "+n);{if(2!==n.length)throw Error("array must have length 2");let t=n[0],r=n[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(r instanceof S)s.setDefault(r,e).second+=t;else{if(!(r instanceof I))throw Error("array item 1 must be a variable or expression");{i+=r.constant()*t;let n=r.terms();for(let i=0,r=n.size();r>i;i++){let r=n.itemAt(i);s.setDefault(r.first,e).second+=r.second*t}}}}}}return{terms:s,constant:i}})(arguments);this.U=t.terms,this.A=t.constant}terms(){return this.U}constant(){return this.A}value(){let t=this.A;for(let i=0,e=this.U.size();e>i;i++){let e=this.U.itemAt(i);t+=e.first.value()*e.second}return t}plus(t){return new I(this,t)}minus(t){return new I(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new I([t,this])}divide(t){return new I([1/t,this])}isConstant(){return 0==this.U.size()}toString(){let t=this.U.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.A||(t+=" + "),t+=this.A,t}U;A}class T{static create(t,i,e,s=1){let r=0;return r+=1e6*Math.max(0,Math.min(1e3,t*s)),r+=1e3*Math.max(0,Math.min(1e3,i*s)),r+=Math.max(0,Math.min(1e3,e*s)),r}static required=T.create(1e3,1e3,1e3);static strong=T.create(1,0,0);static medium=T.create(0,1,0);static weak=T.create(0,0,1);static clip(t){return Math.max(0,Math.min(T.required,t))}}var k;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(k||(k={}));class U{constructor(t,i,e,s=T.required){this.P=i,this.V=T.clip(s),this.O=void 0===e&&t instanceof I?t:t.minus(e)}id(){return this.B}expression(){return this.O}op(){return this.P}strength(){return this.V}toString(){return this.O+" "+["<=",">=","="][this.P]+" 0 ("+this.V+")"}O;P;V;B=M++}let M=0;class A{maxIterations=1e3;constructor(){}createConstraint(t,i,e,s=T.required){let r=new U(t,i,e,s);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.F.find(t))throw Error("duplicate constraint");let i=this.L(t),e=i.row,s=i.tag,r=this.R(e,s);if(r.type()===V.Invalid&&e.allDummies()){if(!P(e.constant()))throw Error("unsatisfiable constraint");r=s.marker}if(r.type()===V.Invalid){if(!this.H(e))throw Error("unsatisfiable constraint")}else e.solveFor(r),this.D(r,e),this.N.insert(r,e);this.F.insert(t,s),this.$(this.j)}removeConstraint(t){let i=this.F.erase(t);if(void 0===i)throw Error("unknown constraint");this.W(t,i.second);let e=i.second.marker,s=this.N.erase(e);if(void 0===s){let t=this.q(e);if(t.type()===V.Invalid)throw Error("failed to find leaving row");s=this.N.erase(t),s.second.solveForEx(t,e),this.D(e,s.second)}this.$(this.j)}hasConstraint(t){return this.F.contains(t)}getConstraints(){return this.F.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.X.find(t))throw Error("duplicate edit variable");if((i=T.clip(i))===T.required)throw Error("bad required strength");let e=new I(t),s=new U(e,k.Eq,void 0,i);this.addConstraint(s);let r=this.F.find(s).second;this.X.insert(t,{tag:r,constraint:s,constant:0})}removeEditVariable(t){let i=this.X.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.X.contains(t)}suggestValue(t,i){let e=this.X.find(t);if(void 0===e)throw Error("unknown edit variable");let s=this.N,r=e.second,n=i-r.constant;r.constant=i;let o=r.tag.marker,h=s.find(o);if(void 0!==h)return 0>h.second.add(-n)&&this.Y.push(o),void this.G();let a=r.tag.other;if(h=s.find(a),void 0!==h)return 0>h.second.add(n)&&this.Y.push(a),void this.G();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t),e=i.second,r=e.coefficientFor(o);0!==r&&0>e.add(n*r)&&i.first.type()!==V.External&&this.Y.push(i.first)}this.G()}updateVariables(){let t=this.Z,i=this.N;for(let e=0,s=t.size();s>e;++e){let s=t.itemAt(e),r=i.find(s.second);s.first.setValue(void 0!==r?r.second.constant():0)}}J(t){return this.Z.setDefault(t,()=>this.K(V.External)).second}L(t){let i=t.expression(),e=new F(i.constant()),s=i.terms();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(!P(i.second)){let t=this.J(i.first),s=this.N.find(t);void 0!==s?e.insertRow(s.second,i.second):e.insertSymbol(t,i.second)}}let r=this.j,n=t.strength(),o={marker:z,other:z};switch(t.op()){case k.Le:case k.Ge:{let i=t.op()===k.Le?1:-1,s=this.K(V.Slack);if(o.marker=s,e.insertSymbol(s,i),T.required>n){let t=this.K(V.Error);o.other=t,e.insertSymbol(t,-i),r.insertSymbol(t,n)}break}case k.Eq:if(T.required>n){let t=this.K(V.Error),i=this.K(V.Error);o.marker=t,o.other=i,e.insertSymbol(t,-1),e.insertSymbol(i,1),r.insertSymbol(t,n),r.insertSymbol(i,n)}else{let t=this.K(V.Dummy);o.marker=t,e.insertSymbol(t)}}return 0>e.constant()&&e.reverseSign(),{row:e,tag:o}}R(t,i){let e=t.cells();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(i.first.type()===V.External)return i.first}let s=i.marker.type();return s!==V.Slack&&s!==V.Error||t.coefficientFor(i.marker)>=0?(s=i.other.type(),s!==V.Slack&&s!==V.Error||t.coefficientFor(i.other)>=0?z:i.other):i.marker}H(t){let i=this.K(V.Slack);this.N.insert(i,t.copy()),this.tt=t.copy(),this.$(this.tt);let e=P(this.tt.constant());this.tt=null;let s=this.N.erase(i);if(void 0!==s){let t=s.second;if(t.isConstant())return e;let r=this.it(t);if(r.type()===V.Invalid)return!1;t.solveForEx(i,r),this.D(r,t),this.N.insert(r,t)}let r=this.N;for(let t=0,e=r.size();e>t;++t)r.itemAt(t).second.removeSymbol(i);return this.j.removeSymbol(i),e}D(t,i){let e=this.N;for(let s=0,r=e.size();r>s;++s){let r=e.itemAt(s);r.second.substitute(t,i),0>r.second.constant()&&r.first.type()!==V.External&&this.Y.push(r.first)}this.j.substitute(t,i),this.tt&&this.tt.substitute(t,i)}$(t){let i=0;for(;this.maxIterations>i;){let e=this.et(t);if(e.type()===V.Invalid)return;let s=this.st(e);if(s.type()===V.Invalid)throw Error("the objective is unbounded");let r=this.N.erase(s).second;r.solveForEx(s,e),this.D(e,r),this.N.insert(e,r),i++}throw Error("solver iterations exceeded")}G(){let t=this.N,i=this.Y;for(;0!==i.length;){let e=i.pop(),s=t.find(e);if(void 0!==s&&0>s.second.constant()){let i=this.rt(s.second);if(i.type()===V.Invalid)throw Error("dual optimize failed");let r=s.second;t.erase(e),r.solveForEx(e,i),this.D(i,r),t.insert(i,r)}}}et(t){let i=t.cells();for(let t=0,e=i.size();e>t;++t){let e=i.itemAt(t),s=e.first;if(0>e.second&&s.type()!==V.Dummy)return s}return z}rt(t){let i=Number.MAX_VALUE,e=z,s=t.cells();for(let t=0,r=s.size();r>t;++t){let r=s.itemAt(t),n=r.first,o=r.second;if(o>0&&n.type()!==V.Dummy){let t=this.j.coefficientFor(n)/o;i>t&&(i=t,e=n)}}return e}st(t){let i=Number.MAX_VALUE,e=z,s=this.N;for(let r=0,n=s.size();n>r;++r){let n=s.itemAt(r),o=n.first;if(o.type()!==V.External){let s=n.second,r=s.coefficientFor(t);if(0>r){let t=-s.constant()/r;i>t&&(i=t,e=o)}}}return e}q(t){let i=Number.MAX_VALUE,e=i,s=i,r=z,n=r,o=r,h=r,a=this.N;for(let i=0,r=a.size();r>i;++i){let r=a.itemAt(i),u=r.second,l=u.coefficientFor(t);if(0===l)continue;let c=r.first;if(c.type()===V.External)h=c;else if(0>l){let t=-u.constant()/l;e>t&&(e=t,n=c)}else{let t=u.constant()/l;s>t&&(s=t,o=c)}}return n!==r?n:o!==r?o:h}W(t,i){i.marker.type()===V.Error&&this.nt(i.marker,t.strength()),i.other.type()===V.Error&&this.nt(i.other,t.strength())}nt(t,i){let e=this.N.find(t);void 0!==e?this.j.insertRow(e.second,-i):this.j.insertSymbol(t,-i)}it(t){let i=t.cells();for(let t=0,e=i.size();e>t;++t){let e=i.itemAt(t),s=e.first.type();if(s===V.Slack||s===V.Error)return e.first}return z}K(t){return new O(t,this.ot++)}F=(()=>E())();N=(()=>E())();Z=(()=>E())();X=(()=>E())();Y=[];j=new F;tt=null;ot=0}function P(t){return 0>t?1e-8>-t:1e-8>t}var V;(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"})(V||(V={}));class O{constructor(t,i){this.B=i,this.ht=t}id(){return this.B}type(){return this.ht}B;ht}let z=new O(V.Invalid,-1);class F{constructor(t=0){this.A=t}cells(){return this.ut}constant(){return this.A}isConstant(){return this.ut.empty()}allDummies(){let t=this.ut;for(let i=0,e=t.size();e>i;++i)if(t.itemAt(i).first.type()!==V.Dummy)return!1;return!0}copy(){let t=new F(this.A);return t.ut=this.ut.copy(),t}add(t){return this.A+=t}insertSymbol(t,i=1){P(this.ut.setDefault(t,()=>0).second+=i)&&this.ut.erase(t)}insertRow(t,i=1){this.A+=t.A*i;let e=t.ut;for(let t=0,s=e.size();s>t;++t){let s=e.itemAt(t);this.insertSymbol(s.first,s.second*i)}}removeSymbol(t){this.ut.erase(t)}reverseSign(){this.A=-this.A;let t=this.ut;for(let i=0,e=t.size();e>i;++i){let e=t.itemAt(i);e.second=-e.second}}solveFor(t){let i=this.ut,e=-1/i.erase(t).second;this.A*=e;for(let t=0,s=i.size();s>t;++t)i.itemAt(t).second*=e}solveForEx(t,i){this.insertSymbol(t,-1),this.solveFor(i)}coefficientFor(t){let i=this.ut.find(t);return void 0!==i?i.second:0}substitute(t,i){let e=this.ut.erase(t);void 0!==e&&this.insertRow(i,e.second)}ut=E();A}const L=1e3;var R,H;function D(t){switch(t){case R.P0:return T.create(L,L,L);case R.P1:return T.create(100,0,0);case R.P2:return T.create(10,0,0);case R.P3:return T.create(0,100,0);case R.P4:return T.create(0,10,0);case R.P5:return T.create(0,0,100);case R.P6:return T.create(0,0,10);case R.P7:return T.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function N(t){return t??R.P0}(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"})(R||(R={})),(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(H||(H={}));let $=new t,j=0,W=!1,q=!1,X=!1,Y=!1;class G{constructor(t,s){this.lt=new i,this.ct=new Map,this.dt=new e(0,t,s,0,-1,1)}insertObject(t,i){if(this.ct.has(t))throw Error("Element already exists");this.ct.set(t,i),this.lt.add(i)}replaceObject(t,i){const e=this.ct.get(t);if(void 0===e)throw Error("Element not found");this.lt.remove(e),this.lt.add(i),this.ct.set(t,i)}removeObject(t){const i=this.ct.get(t);if(void 0===i)throw Error("Element not found");this.lt.remove(i),this.ct.delete(t)}resize(t,i){this.dt.right=t,this.dt.top=i,this.dt.updateProjectionMatrix()}getVisibility(t){const i=this.ct.get(t);if(void 0===i)throw Error("Element not found");return i.visible}getZIndex(t){const i=this.ct.get(t);if(void 0===i)throw Error("Element not found");return i.renderOrder}setZIndex(t,i){const e=this.ct.get(t);if(void 0===e)throw Error("Element not found");e.renderOrder=i}setVisibility(t,i){const e=this.ct.get(t);if(void 0===e)throw Error("Element not found");e.visible=i}getSortedVisibleElements(){return Array.from(this.ct.keys()).sort((t,i)=>this.getZIndex(t)-this.getZIndex(i))}prepareRender(t){$=t.getClearColor($),j=t.getClearAlpha(),W=t.autoClear,q=t.autoClearColor,X=t.autoClearDepth,Y=t.autoClearStencil,t.autoClear=!1,t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.setClearColor(0,1);for(const[t,i]of this.ct){const e=t.micro,s=t.width*e.scaleX,r=t.height*e.scaleY,n=e.anchorX*s,o=e.anchorY*r,h=Math.cos(e.rotation),a=Math.sin(e.rotation),u=n*h-o*a,l=n*a+o*h;if(e.anchorMode===H.POSITION_ROTATION_SCALE)i.position.x=t.x+e.x-u,i.position.y=t.y+e.y-l;else{const s=e.anchorY*t.height;i.position.x=t.x+e.anchorX*t.width-u+e.x,i.position.y=t.y+s-l+e.y}i.scale.x=s,i.scale.y=r,i.rotation.z=e.rotation}}render(t){t.clear(!1,!0,!0),t.render(this.lt,this.dt),t.setClearColor($),t.setClearAlpha(j),t.autoClear=W,t.autoClearColor=q,t.autoClearDepth=X,t.autoClearStencil=Y}}var Q,Z;function J(t){switch(t){case Q.EQUAL:return k.Eq;case Q.LESS_THAN:return k.Le;case Q.GREATER_THAN:return k.Ge;default:throw Error("Invalid relation: "+t)}}function K(t){return t??Q.EQUAL}(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(Q||(Q={}));class tt{constructor(){this.ft=new A,this.gt=!1,this.vt=new Map,this.wt=0,this.yt=new Map,this.bt=0}createVariable(t,i){const e=this.wt++,s=new S;if(i===R.P0){const r={variable:s,priority:i,value:t};this.vt.set(e,r),r.constraint=this.xt(new v(0,[[e,1]]),new v(t),Q.EQUAL,i);try{this.ft?.addConstraint(r.constraint)}catch{this.ft=void 0}}else{this.vt.set(e,{variable:s,priority:i,value:t});try{this.ft?.addEditVariable(s,D(i)),this.ft?.suggestValue(s,t)}catch{this.ft=void 0}}return this.gt=!0,e}removeVariable(t){const i=this.vt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);for(const i of this.yt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error(`Variable ${t} is used in constraint`);try{i.constraint?this.ft?.removeConstraint(i.constraint):this.ft?.removeEditVariable(i.variable)}catch{this.ft=void 0}this.vt.delete(t),this.gt=!0}suggestVariableValue(t,i){const e=this.vt.get(t);if(void 0===e)throw Error(`Variable ${t} does not exist`);e.value!==i&&(e.value=i,e.constraint?e.constraint=this.Et(e.constraint,(new v).plus(t,1),new v(e.value),Q.EQUAL,e.priority):this.ft?.suggestValue(e.variable,i),this.gt=!0)}setVariablePriority(t,i){const e=this.vt.get(t);if(void 0===e)throw Error(`Variable ${t} does not exist`);if(i!==e.priority){if(e.priority=i,e.priority===R.P0){const i=(new v).plus(t,1),s=new v(e.value);e.constraint=this.xt(i,s,Q.EQUAL,e.priority);try{this.ft?.addConstraint(e.constraint)}catch{this.ft=void 0}}else{if(e.constraint)try{this.ft?.removeConstraint(e.constraint)}catch{this.ft=void 0}e.constraint=void 0,this.Ct(t,e)}this.gt=!0}}readVariableValue(t){const i=this.vt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return void 0===this.ft&&this._t(),this.gt&&(this.ft?.updateVariables(),this.gt=!1),i.variable.value()}createConstraint(t,i,e,s,r){const n=this.bt++,o=this.xt(t,i,e,s);if(this.yt.set(n,{constraint:o,lhs:t.clone(),rhs:i.clone(),priority:s,relation:e,enabled:r}),r){try{this.ft?.addConstraint(o)}catch{this.ft=void 0}this.gt=!0}return n}removeConstraint(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Constraint ${t} does not exist`);if(i.enabled)try{this.ft?.removeConstraint(i.constraint)}catch{this.ft=void 0}this.yt.delete(t),this.gt=!0}setConstraintLHS(t,i){const e=this.yt.get(t);if(void 0===e)throw Error(`Constraint ${t} does not exist`);e.lhs.copy(i),this.St(e),this.gt=!0}setConstraintRHS(t,i){const e=this.yt.get(t);if(void 0===e)throw Error(`Constraint ${t} does not exist`);e.rhs.copy(i),this.St(e),this.gt=!0}setConstraintRelation(t,i){const e=this.yt.get(t);if(void 0===e)throw Error(`Constraint ${t} does not exist`);e.relation=i,this.St(e),this.gt=!0}setConstraintPriority(t,i){const e=this.yt.get(t);if(void 0===e)throw Error(`Constraint ${t} does not exist`);e.priority=i,this.St(e),this.gt=!0}setConstraintEnabled(t,i){const e=this.yt.get(t);if(void 0===e)throw Error(`Constraint ${t} does not exist`);if(i!==e.enabled){e.enabled=i;try{e.enabled?this.ft?.addConstraint(e.constraint):this.ft?.removeConstraint(e.constraint)}catch{this.ft=void 0}this.gt=!0}}Ct(t,i){const e=[];for(const i of this.yt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.ft?.removeConstraint(i.constraint)}catch{this.ft=void 0}e.push(i)}this.ft?.removeEditVariable(i.variable),this.ft?.addEditVariable(i.variable,D(i.priority));for(const t of e)t.constraint=this.xt(t.lhs,t.rhs,t.relation,t.priority);for(const t of e)try{this.ft?.addConstraint(t.constraint)}catch{this.ft=void 0;break}}St(t){t.constraint=t.enabled?this.Et(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.xt(t.lhs,t.rhs,t.relation,t.priority)}Et(t,i,e,s,r){try{this.ft?.removeConstraint(t)}catch{this.ft=void 0}const n=this.xt(i,e,s,r);try{this.ft?.addConstraint(n)}catch{this.ft=void 0}return n}xt(t,i,e,s){return new U(this.Bt(t),J(e),this.Bt(i),D(s))}Bt(t){return new I(...t.prepareTermsInternal().map(([t,i])=>{const e=this.vt.get(t);if(void 0===e)throw Error(`Variable ${t} does not exist`);return[i,e.variable]}),t.constant)}_t(){if(this.ft)throw Error("Solver already exists");this.ft=new A;for(const t of this.vt.values())t.constraint?this.ft.addConstraint(t.constraint):(this.ft.addEditVariable(t.variable,D(t.priority)),this.ft.suggestValue(t.variable,t.value));for(const t of this.yt.values())t.enabled&&this.ft.addConstraint(t.constraint);this.gt=!0}}(t=>{t.ORIENTATION_CHANGE="orientation_change",t.MODE_CHANGE="mode_change",t.WILL_RENDER="will_render"})(Z||(Z={}));class it extends y{constructor(t,i){super(),this.name="",this.solverWrapper=new tt,this.modeInternal=m.VISIBLE,this.sceneWrapper=new G(t,i),this.xVariable=this.solverWrapper.createVariable(0,R.P0),this.yVariable=this.solverWrapper.createVariable(0,R.P0),this.wVariable=this.solverWrapper.createVariable(t,R.P0),this.hVariable=this.solverWrapper.createVariable(i,R.P0),this.orientationInternal=t>i?b.HORIZONTAL:b.VERTICAL}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get mode(){return this.modeInternal}get orientation(){return this.orientationInternal}set mode(t){t!==this.modeInternal&&(this.modeInternal=t,this.emit(Z.MODE_CHANGE,this.modeInternal,this))}resizeInternal(t,i){this.solverWrapper.suggestVariableValue(this.wVariable,t),this.solverWrapper.suggestVariableValue(this.hVariable,i),this.sceneWrapper.resize(t,i);const e=t>i?b.HORIZONTAL:b.VERTICAL;e!==this.orientationInternal&&(this.orientationInternal=e,this.emit(Z.ORIENTATION_CHANGE,this.orientationInternal,this))}renderInternal(t,i){this.mode!==m.HIDDEN&&(this.sceneWrapper.prepareRender(t),this.emit(Z.WILL_RENDER,t,i,this),this.sceneWrapper.render(t))}clickInternal(t,i){if(this.mode===m.INTERACTIVE)for(const e of this.sceneWrapper.getSortedVisibleElements())if(e.onClickInternal(t,i))return}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperInternal(){return this.sceneWrapper}}class et{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal()}}class st extends et{constructor(t,i,e,s){super(t),this.It=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.priorityInternal=N(i),this.relationInternal=K(e),this.orientationInternal=x(s),this.layer.on(Z.ORIENTATION_CHANGE,this.It)}get priority(){return this.priorityInternal}get relation(){return this.relationInternal}get orientation(){return this.orientationInternal}set priority(t){t!==this.priorityInternal&&(this.priorityInternal=t,this.solverWrapper.setConstraintPriority(this.constraint,this.priorityInternal))}set relation(t){t!==this.relationInternal&&(this.relationInternal=t,this.solverWrapper.setConstraintRelation(this.constraint,this.relationInternal))}set orientation(t){t!==this.orientationInternal&&(this.orientationInternal=t,this.It())}destroy(){this.layer.off(Z.ORIENTATION_CHANGE,this.It),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===b.ALWAYS||this.orientationInternal===this.layer.orientation}}class rt extends st{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Tt=t,this.kt=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new v(0,[[this.Tt.hVariable,1]]),new v(this.kt),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.kt}set height(t){this.kt!==t&&(this.kt=t,this.solverWrapper.setConstraintRHS(this.constraint,new v(t)))}}function nt(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof it}function ot(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}function at(t,i,e){if(t instanceof it&&i instanceof it)throw Error(e+": layer cannot be snapped to another layer");let s,r;if(!(t instanceof it||nt(t)))throw Error(e+": A must be a UILayer or a UIPointElement");if(s=t instanceof it?t:t.layer,!(i instanceof it||nt(i)))throw Error(e+": B must be a UILayer or a UIPointElement");if(r=i instanceof it?i:i.layer,s!==r)throw Error(e+": elements must be on the same layer");return s}function ut(t,i){if(!Number.isFinite(t))throw Error(i+": value must be a finite number");if(Math.abs(t)>Number.MAX_SAFE_INTEGER)throw Error(i+": value exceeds maximum safe integer range")}function lt(t,i){if(ut(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function ct(t,i){if(ut(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class dt extends st{constructor(t,i,e={}){super(at(t,i,"UIHorizontalDistanceConstraint"),e.priority,e.relation,e.orientation),this.Ut=t,this.Mt=i,this.At=e.anchorA??.5,this.Pt=e.anchorB??.5,this.Vt=e.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Ot(),new v(this.Vt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Vt}get anchorA(){return this.At}get anchorB(){return this.Pt}set distance(t){this.Vt!==t&&(this.Vt=t,this.solverWrapper.setConstraintRHS(this.constraint,new v(this.Vt)))}set anchorA(t){this.At!==t&&(this.At=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ot()))}set anchorB(t){this.Pt!==t&&(this.Pt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ot()))}Ot(){let t,i;if(ht(this.Ut))t=new v(0,[[this.Ut.xVariable,1],[this.Ut.wVariable,this.At]]);else{if(!ot(this.Ut))throw Error("A is not a valid element type");t=(new v).plus(this.Ut.xVariable,1)}if(ht(this.Mt))i=new v(0,[[this.Mt.xVariable,1],[this.Mt.wVariable,this.Pt]]);else{if(!ot(this.Mt))throw Error("B is not a valid element type");i=(new v).plus(this.Mt.xVariable,1)}return v.minus(i,t)}}class ft extends st{constructor(t,i,e={}){super(at(t,i,"UIHorizontalProportionConstraint"),e.priority,e.relation,e.orientation),this.Ut=t,this.Mt=i,this.zt=e.proportion??1,this.constraint=this.solverWrapper.createConstraint(new v(0),this.Ft(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Ft()))}Ft(){return v.minus(new v(0,[[this.Ut.wVariable,this.zt]]),new v(0,[[this.Mt.wVariable,1]]))}}class gt extends st{constructor(t,i,e={}){super(at(t,i,"UIVerticalDistanceConstraint"),e.priority,e.relation,e.orientation),this.Ut=t,this.Mt=i,this.At=e.anchorA??.5,this.Pt=e.anchorB??.5,this.Vt=e.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Ot(),new v(this.Vt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Vt}get anchorA(){return this.At}get anchorB(){return this.Pt}set distance(t){this.Vt!==t&&(this.Vt=t,this.solverWrapper.setConstraintRHS(this.constraint,new v(this.Vt)))}set anchorA(t){this.At!==t&&(this.At=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ot()))}set anchorB(t){this.Pt!==t&&(this.Pt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ot()))}Ot(){let t,i;if(ht(this.Ut))t=new v(0,[[this.Ut.yVariable,1],[this.Ut.hVariable,this.At]]);else{if(!ot(this.Ut))throw Error("A is not a valid element type");t=(new v).plus(this.Ut.yVariable,1)}if(ht(this.Mt))i=new v(0,[[this.Mt.yVariable,1],[this.Mt.hVariable,this.Pt]]);else{if(!ot(this.Mt))throw Error("B is not a valid element type");i=(new v).plus(this.Mt.yVariable,1)}return v.minus(i,t)}}class pt extends st{constructor(t,i,e={}){super(at(t,i,"UIVerticalProportionConstraint"),e.priority,e.relation,e.orientation),this.Ut=t,this.Mt=i,this.zt=e.proportion??1,this.constraint=this.solverWrapper.createConstraint(new v(0),this.Ft(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Ft()))}Ft(){return v.minus(new v(0,[[this.Ut.hVariable,this.zt]]),new v(0,[[this.Mt.hVariable,1]]))}}class vt extends st{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Tt=t,this.Lt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new v(0,[[this.Tt.wVariable,1]]),new v(this.Lt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Lt}set width(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintRHS(this.constraint,new v(t)))}}class wt{static size(t,i={}){return{h:new vt(t,{width:i.size?.h,priority:i.priority?.h,relation:i.relation?.h,orientation:i.orientation?.h}),v:new rt(t,{height:i.size?.v,priority:i.priority?.v,relation:i.relation?.v,orientation:i.orientation?.v})}}static distance(t,i,e={}){return{h:new dt(t,i,{anchorA:e.anchorA?.h,anchorB:e.anchorB?.h,distance:e.distance?.h,priority:e.priority?.h,relation:e.relation?.h,orientation:e.orientation?.h}),v:new gt(t,i,{anchorA:e.anchorA?.v,anchorB:e.anchorB?.v,distance:e.distance?.v,priority:e.priority?.v,relation:e.relation?.v,orientation:e.orientation?.v})}}static proportion(t,i,e={}){return{h:new ft(t,i,{proportion:e.proportion?.h,priority:e.priority?.h,relation:e.relation?.h,orientation:e.orientation?.h}),v:new pt(t,i,{proportion:e.proportion?.v,priority:e.priority?.v,relation:e.relation?.v,orientation:e.orientation?.v})}}}class yt extends st{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Tt=t,this.Rt=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Ot(),new v(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Rt}set aspect(t){this.Rt!==t&&(this.Rt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ot()))}Ot(){return new v(0,[[this.Tt.wVariable,1],[this.Tt.hVariable,-this.Rt]])}}const mt=.5;class bt{static build(t,i,e={}){let s;return!0===e.keepActiveAspect&&(s=new yt(i,{orientation:e.orientation})),{activeAspectConstraint:s,xConstraint:new dt(t,i,{anchorA:e.anchorH??mt,anchorB:e.anchorH??mt,orientation:e.orientation}),yConstraint:new gt(t,i,{anchorA:e.anchorV??mt,anchorB:e.anchorV??mt,orientation:e.orientation}),widthConstraint:new ft(t,i,{proportion:1,relation:Q.GREATER_THAN,orientation:e.orientation}),heightConstraint:new pt(t,i,{proportion:1,priority:R.P1,orientation:e.orientation})}}}const xt=.5;class Et{static build(t,i,e={}){let s;return!0===e.keepActiveAspect&&(s=new yt(i,{orientation:e.orientation})),{activeAspectConstraint:s,xConstraint:new dt(t,i,{anchorA:e.anchorH??xt,anchorB:e.anchorH??xt,orientation:e.orientation}),yConstraint:new gt(t,i,{anchorA:e.anchorV??xt,anchorB:e.anchorV??xt,orientation:e.orientation}),widthConstraint:new ft(t,i,{proportion:1,relation:Q.LESS_THAN,orientation:e.orientation}),heightConstraint:new pt(t,i,{proportion:1,priority:R.P1,orientation:e.orientation})}}}class Ct extends st{constructor(t,i,e,s={}){super(t,s.priority,s.relation,s.orientation),this.Ht=i,this.Dt=e,this.constraint=this.solverWrapper.createConstraint(this.Ht,this.Dt,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Ht}get rhs(){return this.Dt}setLHS(t){this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ht)}setRHS(t){this.Dt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt)}}class _t extends y{constructor(t,i,e){ut(i,"UIAnchor x"),ut(e,"UIAnchor y"),super(),this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal(),this.xVariable=this.solverWrapper.createVariable(i,R.P7),this.yVariable=this.solverWrapper.createVariable(e,R.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){ut(t,"UIAnchor x"),this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){ut(t,"UIAnchor y"),this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}class St extends _t{constructor(t,i,e,s=100,r=100){lt(s,"UIDummy width"),lt(r,"UIDummy height"),super(t,i,e),this.wVariable=this.solverWrapper.createVariable(s,R.P6),this.hVariable=this.solverWrapper.createVariable(r,R.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){lt(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){lt(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}const Bt=.5;class It{constructor(){this.Nt=0,this.$t=0,this.jt=Bt,this.Wt=Bt,this.qt=1,this.Xt=1,this.Yt=0,this.Gt=H.ROTATION_SCALE,this.gt=!1}get x(){return this.Nt}get y(){return this.$t}get anchorX(){return this.jt}get anchorY(){return this.Wt}get scaleX(){return this.qt}get scaleY(){return this.Xt}get size(){return Math.max(this.qt,this.Xt)}get angle(){return s.radToDeg(this.Yt)}get anchorMode(){return this.Gt}get rotation(){return this.Yt}set x(t){t!==this.Nt&&(this.Nt=t,this.gt=!0)}set y(t){t!==this.$t&&(this.$t=t,this.gt=!0)}set anchorX(t){t!==this.jt&&(this.jt=t,this.gt=!0)}set anchorY(t){t!==this.Wt&&(this.Wt=t,this.gt=!0)}set scaleX(t){t!==this.qt&&(this.qt=t,this.gt=!0)}set scaleY(t){t!==this.Xt&&(this.Xt=t,this.gt=!0)}set size(t){t===this.qt&&t===this.Xt||(this.qt=t,this.Xt=t,this.gt=!0)}set angle(t){const i=s.degToRad(t);i!==this.Yt&&(this.Yt=i,this.gt=!0)}set rotation(t){t!==this.Yt&&(this.Yt=t,this.gt=!0)}set anchorMode(t){t!==this.Gt&&(this.Gt=t,this.gt=!0)}reset(){0===this.Nt&&0===this.$t&&this.jt===Bt&&this.Wt===Bt&&1===this.qt&&1===this.Xt&&0===this.Yt||(this.Nt=0,this.$t=0,this.jt=Bt,this.Wt=Bt,this.qt=1,this.Xt=1,this.Yt=0,this.gt=!0)}getRecalculationRequiredInternal(){return this.gt}resetRecalculationRequiredInternal(){this.gt=!1}}var Tt;(t=>{t.CLICK="click"})(Tt||(Tt={}));class kt extends _t{constructor(t,i,e,s,r,n){lt(s,"UIElement width"),lt(r,"UIElement height"),super(t,i,e),this.object=n,this.micro=new It,this.modeInternal=m.VISIBLE,this.sceneWrapper=this.layer.getSceneWrapperInternal(),this.sceneWrapper.insertObject(this,this.object),this.wVariable=this.solverWrapper.createVariable(s,R.P6),this.hVariable=this.solverWrapper.createVariable(r,R.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get zIndex(){return this.sceneWrapper.getZIndex(this)}get mode(){return this.modeInternal}set width(t){lt(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){lt(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){ut(t,"UIElement zIndex"),this.sceneWrapper.setZIndex(this,t)}set mode(t){t!==this.modeInternal&&(this.modeInternal=t,this.sceneWrapper.setVisibility(this,t!==m.HIDDEN))}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.removeObject(this),super.destroy()}onClickInternal(t,i){const e=this.modeInternal===m.INTERACTIVE&&t>this.x&&this.x+this.width>t&&i>this.y&&this.y+this.height>i;return e&&this.emit(Tt.CLICK,t,i,this),e}}const Ut=.25;class Mt extends r{constructor(i){super({uniforms:{map:{value:i},opacity:{value:1},color:{value:new t(1,1,1)},alphaTest:{value:Ut}},vertexShader:"varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"uniform sampler2D map;\nuniform float opacity;\nuniform vec3 color;\nuniform float alphaTest;\nvarying vec2 vUv;\n\nvoid main() {\n vec4 diffuseColor = texture2D(map, vUv);\n #include <alphatest_fragment>\n gl_FragColor = vec4(diffuseColor.rgb * color, diffuseColor.a * opacity);\n #include <colorspace_fragment>\n}\n",transparent:!1,alphaTest:Ut,lights:!1,fog:!1,depthWrite:!1,depthTest:!1})}getTexture(){return this.uniforms.map.value}getColor(){return this.uniforms.color.value.getHex()}getOpacity(){return this.uniforms.opacity.value}getTransparency(){return this.transparent}setTexture(t){return this.uniforms.map.value=t,this.uniformsNeedUpdate=!0,this}setColor(t){return this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0,this}setOpacity(t){return this.uniforms.opacity.value=t,this.uniformsNeedUpdate=!0,this}setTransparency(t){return this.transparent!==t&&(this.transparent=t,this.uniforms.alphaTest.value=t?0:Ut,this.needsUpdate=!0,this.uniformsNeedUpdate=!0),this}}const At=new n(1,1).translate(.5,.5,0);class Pt extends kt{constructor(t,i,e=0,s=0){const r=i.image.width,n=i.image.height,h=new Mt(i);super(t,e,s,r,n,new o(At,h)),this.Qt=h,this.Zt=i}get texture(){return this.Zt}get color(){return this.Qt.getColor()}get opacity(){return this.Qt.getOpacity()}get transparency(){return this.Qt.getTransparency()}set texture(t){const i=t.image.width,e=t.image.height;lt(i,"UIImage texture width"),lt(e,"UIImage texture height"),this.Qt.setTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,e)}set color(t){this.Qt.setColor(t)}set opacity(t){this.Qt.setOpacity(t)}set transparency(t){this.Qt.setTransparency(t)}destroy(){this.Qt.dispose(),super.destroy()}}const Vt=.25;class Ot extends r{constructor(i){super({uniforms:{map:{value:i},color:{value:new t(16777215)},opacity:{value:1},alphaTest:{value:Vt},sliceBorders:{value:new a(0,0,0,0)},quadSize:{value:new h(1,1)},textureSize:{value:new h(i.image.width,i.image.height)}},vertexShader:"varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"uniform sampler2D map;\nuniform vec3 color;\nuniform float opacity;\nuniform float alphaTest;\nuniform vec4 sliceBorders;\nuniform vec2 quadSize;\nuniform vec2 textureSize;\nvarying vec2 vUv;\n\nvec2 calculateNineSliceUV(vec2 uv) {\n vec2 localUV = uv;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * textureSize.x;\n float rightPx = right * textureSize.x;\n float topPx = top * textureSize.y;\n float bottomPx = bottom * textureSize.y;\n\n float lB = leftPx / quadSize.x;\n float rB = 1.0 - (rightPx / quadSize.x);\n float tB = topPx / quadSize.y;\n float bB = 1.0 - (bottomPx / quadSize.y);\n\n {\n float regionL = step(uv.x, lB);\n float regionR = step(rB, uv.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = uv.x * (left / lB);\n float xR = 1.0 - right + ((uv.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((uv.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(uv.y, tB);\n float regionB = step(bB, uv.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = uv.y * (top / tB);\n float yB = 1.0 - bottom + ((uv.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((uv.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 textureColor = texture2D(map, calculateNineSliceUV(vUv));\n if (textureColor.a < alphaTest) {\n discard;\n }\n gl_FragColor = vec4(textureColor.rgb * color, textureColor.a * opacity);\n #include <colorspace_fragment>\n}\n",transparent:!1,alphaTest:Vt,lights:!1,fog:!1,depthWrite:!1,depthTest:!1})}getSliceBorderLeft(){return this.uniforms.sliceBorders.value.x}getSliceBorderRight(){return this.uniforms.sliceBorders.value.y}getSliceBorderTop(){return this.uniforms.sliceBorders.value.z}getSliceBorderBottom(){return this.uniforms.sliceBorders.value.w}getQuadSize(){const t=this.uniforms.quadSize.value;return{w:t.x,h:t.y}}getTexture(){return this.uniforms.map.value}getColor(){return this.uniforms.color.value.getHex()}getOpacity(){return this.uniforms.opacity.value}getTransparency(){return this.transparent}setSliceBorderLeft(t){return this.uniforms.sliceBorders.value.x=t,this.uniformsNeedUpdate=!0,this}setSliceBorderRight(t){return this.uniforms.sliceBorders.value.y=t,this.uniformsNeedUpdate=!0,this}setSliceBorderTop(t){return this.uniforms.sliceBorders.value.z=t,this.uniformsNeedUpdate=!0,this}setSliceBorderBottom(t){return this.uniforms.sliceBorders.value.w=t,this.uniformsNeedUpdate=!0,this}setSliceBorder(t,i,e,s){return this.uniforms.sliceBorders.value.set(t,i,e,s),this.uniformsNeedUpdate=!0,this}setQuadSize(t,i){return this.uniforms.quadSize.value.set(t,i),this.uniformsNeedUpdate=!0,this}setTexture(t){return this.uniforms.map.value=t,this.uniformsNeedUpdate=!0,this}setColor(t){return this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0,this}setOpacity(t){return this.uniforms.opacity.value=t,this.uniformsNeedUpdate=!0,this}setTransparency(t){return this.transparent!==t&&(this.transparent=t,this.uniforms.alphaTest.value=t?0:Vt,this.needsUpdate=!0,this.uniformsNeedUpdate=!0),this}}const zt=.25;class Ft extends kt{constructor(t,i,e={}){const s=i.image.width,r=i.image.height,n=new Ot(i),h=new o(At,n);super(t,e.x??0,e.y??0,s,r,h),this.Jt=()=>{this.Qt.setQuadSize(this.width*this.micro.scaleX,this.height*this.micro.scaleY)},this.layer.on(Z.WILL_RENDER,this.Jt),this.Qt=n,this.Zt=i;const a=(t=>{if(null==t)return{left:zt,right:zt,top:zt,bottom:zt};if("number"==typeof t)return{left:t,right:t,top:t,bottom:t};if("object"==typeof t){if("horizontal"in t&&"vertical"in t){const i="number"==typeof t.horizontal?t.horizontal:zt,e="number"==typeof t.vertical?t.vertical:zt;return{left:i,right:i,top:e,bottom:e}}return{left:"number"==typeof t.left?t.left:zt,right:"number"==typeof t.right?t.right:zt,top:"number"==typeof t.top?t.top:zt,bottom:"number"==typeof t.bottom?t.bottom:zt}}return{left:zt,right:zt,top:zt,bottom:zt}})(e.sliceBorder);this.Qt.setSliceBorder(a.left,a.right,a.top,a.bottom)}get sliceBorderLeft(){return this.Qt.getSliceBorderLeft()}get sliceBorderRight(){return this.Qt.getSliceBorderRight()}get sliceBorderTop(){return this.Qt.getSliceBorderTop()}get sliceBorderBottom(){return this.Qt.getSliceBorderBottom()}get texture(){return this.Zt}get color(){return this.Qt.getColor()}get opacity(){return this.Qt.getOpacity()}get transparency(){return this.Qt.getTransparency()}set sliceBorderLeft(t){this.Qt.setSliceBorderLeft(t)}set sliceBorderRight(t){this.Qt.setSliceBorderRight(t)}set sliceBorderTop(t){this.Qt.setSliceBorderTop(t)}set sliceBorderBottom(t){this.Qt.setSliceBorderBottom(t)}set texture(t){const i=t.image.width,e=t.image.height;lt(i,"UINineSlice texture width"),lt(e,"UINineSlice texture height"),this.Qt.setTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,e)}set color(t){this.Qt.setColor(t)}set opacity(t){this.Qt.setOpacity(t)}set transparency(t){this.Qt.setTransparency(t)}setSliceBorders(t,i,e,s){this.Qt.setSliceBorder(t,i,e,s)}destroy(){this.layer.off(Z.WILL_RENDER,this.Jt),this.Qt.dispose(),super.destroy()}}const Lt=.25;class Rt extends r{constructor(i,e){super({uniforms:u.merge([{background:{value:e},foreground:{value:i},progress:{value:1},color:{value:new t(1,1,1)},backgroundColor:{value:new t(1,1,1)},foregroundColor:{value:new t(1,1,1)},opacity:{value:1},backgroundOpacity:{value:1},foregroundOpacity:{value:1},alphaTest:{value:Lt},angle:{value:0},direction:{value:1}}]),vertexShader:"varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"uniform sampler2D background;\nuniform sampler2D foreground;\nuniform float progress;\nuniform vec3 color;\nuniform vec3 backgroundColor;\nuniform vec3 foregroundColor;\nuniform float opacity;\nuniform float backgroundOpacity;\nuniform float foregroundOpacity;\nuniform float alphaTest;\nuniform float angle;\nuniform float direction;\nvarying vec2 vUv;\n\nvoid main() {\n vec4 backgroundTexture = texture2D(background, vUv);\n vec4 foregroundTexture = texture2D(foreground, vUv);\n\n // Apply common color and opacity\n vec3 finalBackgroundColor = backgroundTexture.rgb * backgroundColor * color;\n vec3 finalForegroundColor = foregroundTexture.rgb * foregroundColor * color;\n float finalBackgroundOpacity = backgroundTexture.a * backgroundOpacity * opacity;\n float finalForegroundOpacity = foregroundTexture.a * foregroundOpacity * opacity;\n\n vec4 backgroundColor = vec4(finalBackgroundColor, finalBackgroundOpacity);\n vec4 foregroundColor = vec4(finalForegroundColor, finalForegroundOpacity);\n\n // Calculate progress threshold with angle and direction\n float adjustedX = mix(vUv.x, 1.0 - vUv.x, step(0.0, -direction));\n float tanAngle = tan(angle);\n float threshold = adjustedX - (vUv.y - 0.5) * tanAngle * sign(direction);\n float progressMask = step(threshold, progress);\n\n vec4 mixedColor = foregroundColor * progressMask\n + backgroundColor * (1.0 - foregroundColor.a * progressMask);\n\n if (mixedColor.a < alphaTest) {\n discard;\n }\n\n gl_FragColor = mixedColor;\n #include <colorspace_fragment>\n}\n",transparent:!1,alphaTest:Lt,lights:!1,fog:!1,depthWrite:!1,depthTest:!1})}getProgress(){return this.uniforms.progress.value}getBackgroundTexture(){return this.uniforms.background.value}getForegroundTexture(){return this.uniforms.foreground.value}getColor(){return this.uniforms.color.value.getHex()}getBackgroundColor(){return this.uniforms.backgroundColor.value.getHex()}getForegroundColor(){return this.uniforms.foregroundColor.value.getHex()}getOpacity(){return this.uniforms.opacity.value}getBackgroundOpacity(){return this.uniforms.backgroundOpacity.value}getForegroundOpacity(){return this.uniforms.foregroundOpacity.value}getTransparency(){return this.transparent}getAngle(){return this.uniforms.angle.value}getIsForwardDirection(){return 1===this.uniforms.direction.value}setProgress(t){this.uniforms.progress.value=t,this.uniformsNeedUpdate=!0}setBackgroundTexture(t){this.uniforms.background.value=t,this.uniformsNeedUpdate=!0}setForegroundTexture(t){this.uniforms.foreground.value=t,this.uniformsNeedUpdate=!0}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setBackgroundColor(t){this.uniforms.backgroundColor.value.setHex(t),this.uniformsNeedUpdate=!0}setForegroundColor(t){this.uniforms.foregroundColor.value.setHex(t),this.uniformsNeedUpdate=!0}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=!0}setBackgroundOpacity(t){this.uniforms.backgroundOpacity.value=t,this.uniformsNeedUpdate=!0}setForegroundOpacity(t){this.uniforms.foregroundOpacity.value=t,this.uniformsNeedUpdate=!0}setTransparency(t){return this.transparent!==t&&(this.transparent=t,this.uniforms.alphaTest.value=t?0:Lt,this.needsUpdate=!0,this.uniformsNeedUpdate=!0),this}setAngle(t){this.uniforms.angle.value=t,this.uniformsNeedUpdate=!0}setIsForwardDirection(t){this.uniforms.direction.value=t?1:-1,this.uniformsNeedUpdate=!0}}class Ht extends kt{constructor(t,i,e={}){const r=i.image?.width,n=i.image?.height;lt(r,"UIProgress foreground texture width"),lt(n,"UIProgress foreground texture height");const h=e.textureBackground?.image?.width,a=e.textureBackground?.image?.height;e.textureBackground&&(lt(h,"UIProgress background texture width"),lt(a,"UIProgress background texture height"));const u=new Rt(i,e.textureBackground),l=new o(At,u);void 0!==e.progress&&u.setProgress(e.progress),void 0!==e.isForwardDirection&&u.setIsForwardDirection(e.isForwardDirection),void 0!==e.angle&&u.setAngle(s.degToRad(e.angle)),void 0!==e.backgroundColor&&u.setBackgroundColor(e.backgroundColor),void 0!==e.foregroundColor&&u.setForegroundColor(e.foregroundColor),void 0!==e.backgroundOpacity&&u.setBackgroundOpacity(e.backgroundOpacity),void 0!==e.foregroundOpacity&&u.setForegroundOpacity(e.foregroundOpacity),super(t,e.x??0,e.y??0,h??r,n??a,l),this.Qt=u}get progress(){return this.Qt.getProgress()}get backgroundTexture(){return this.Qt.getBackgroundTexture()}get foregroundTexture(){return this.Qt.getForegroundTexture()}get color(){return this.Qt.getColor()}get backgroundColor(){return this.Qt.getBackgroundColor()}get foregroundColor(){return this.Qt.getForegroundColor()}get opacity(){return this.Qt.getOpacity()}get backgroundOpacity(){return this.Qt.getBackgroundOpacity()}get foregroundOpacity(){return this.Qt.getForegroundOpacity()}get transparency(){return this.Qt.getTransparency()}get angle(){return s.radToDeg(this.Qt.getAngle())}get isForwardDirection(){return this.Qt.getIsForwardDirection()}set progress(t){this.Qt.setProgress(t)}set backgroundTexture(t){if(t){const i=t.image.height;lt(t.image.width,"UIProgress background texture width"),lt(i,"UIProgress background texture height")}this.Qt.setBackgroundTexture(t)}set foregroundTexture(t){const i=t.image.width,e=t.image.height;lt(i,"UIProgress foreground texture width"),lt(e,"UIProgress foreground texture height"),this.Qt.setForegroundTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,e)}set color(t){this.Qt.setColor(t)}set backgroundColor(t){this.Qt.setBackgroundColor(t)}set foregroundColor(t){this.Qt.setForegroundColor(t)}set opacity(t){this.Qt.setOpacity(t)}set backgroundOpacity(t){this.Qt.setBackgroundOpacity(t)}set foregroundOpacity(t){this.Qt.setForegroundOpacity(t)}set transparency(t){this.Qt.setTransparency(t)}set angle(t){this.Qt.setAngle(s.degToRad(t))}set isForwardDirection(t){this.Qt.setIsForwardDirection(t)}destroy(){this.Qt.dispose(),super.destroy()}}var Dt;(t=>{t[t.EACH_FRAME=1]="EACH_FRAME",t[t.EACH_SECOND_FRAME=2]="EACH_SECOND_FRAME",t[t.PROPERTY_CHANGED=3]="PROPERTY_CHANGED",t[t.MANUAL=4]="MANUAL"})(Dt||(Dt={}));const Nt=Dt.PROPERTY_CHANGED;class $t extends kt{constructor(t,e={}){const s=e.resolutionFactor??.5;if(.1>s||s>2)throw Error(`Invalid resolution factor: ${s}. Must be between 0.1 and 2.`);const r=e.width??512,n=e.height??512,h=new l(r*s,n*s,{format:f,minFilter:d,magFilter:d,type:c,depthBuffer:e.enableDepthBuffer??!0,stencilBuffer:!1}),a=new Mt(h.texture);super(t,0,0,r,n,new o(At,a)),this.Kt=!0,this.ti=!1,this.ii=!1,this.Jt=t=>{(this.ei===Dt.EACH_FRAME||this.ei===Dt.EACH_SECOND_FRAME&&this.Kt||this.ei===Dt.PROPERTY_CHANGED&&this.ti||this.ei===Dt.MANUAL&&this.ii)&&(this.ii=!1,this.ti=!1,this.Kt=!this.Kt,this.si.setSize(this.width*this.ri,this.height*this.ri),t.setClearColor(this.ni,this.clearAlpha),t.setRenderTarget(this.si),t.clear(!0,!0,!1),t.render(this.oi,this.hi))},this.layer.on(Z.WILL_RENDER,this.Jt),this.Qt=a,this.si=h,this.oi=e.scene??new i,this.hi=e.camera??new g(75,r/n,.1,100),this.ri=s,this.ei=e.updateMode??Nt,this.ni=e.clearColor??0,this.ai=e.clearAlpha??0,e.updateMode===Dt.PROPERTY_CHANGED&&(this.ii=!0)}get color(){return this.Qt.getColor()}get opacity(){return this.Qt.getOpacity()}get transparency(){return this.Qt.getTransparency()}get scene(){return this.oi}get camera(){return this.hi}get updateMode(){return this.ei}get resolutionFactor(){return this.ri}get clearColor(){return this.ni}get clearAlpha(){return this.ai}set color(t){this.Qt.setColor(t)}set opacity(t){this.Qt.setOpacity(t)}set transparency(t){this.Qt.setTransparency(t)}set scene(t){this.oi!==t&&(this.oi=t,this.ti=!0)}set camera(t){this.hi!==t&&(this.hi=t,this.ti=!0)}set updateMode(t){this.ei!==t&&(this.ei=t,this.ti=!0)}set resolutionFactor(t){this.ri!==t&&(this.ri=t,this.si.setSize(this.width*this.ri,this.height*this.ri),this.ti=!0)}set clearColor(t){this.ni!==t&&(this.ni=t,this.ti=!0)}set clearAlpha(t){this.ai!==t&&(this.ai=t,this.ti=!0)}destroy(){this.layer.off(Z.WILL_RENDER,this.Jt),this.Qt.dispose(),this.si.dispose(),super.destroy()}requestRender(){this.ii=!0}}function jt(t){return"object"==typeof t&&null!==t&&!("string"!=typeof t.color||"string"!=typeof t.fontFamily||"number"!=typeof t.fontSize||"normal"!==t.fontStyle&&"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||"normal"!==t.fontWeight&&"bold"!==t.fontWeight&&"bolder"!==t.fontWeight&&"lighter"!==t.fontWeight&&"number"!=typeof t.fontWeight||"number"!=typeof t.lineHeight||"boolean"!=typeof t.enableShadow||"number"!=typeof t.shadowOffsetX||"number"!=typeof t.shadowOffsetY||"number"!=typeof t.shadowBlur||"string"!=typeof t.shadowColor||"boolean"!=typeof t.enableStroke||"string"!=typeof t.strokeColor||"number"!=typeof t.strokeWidth)}function Wt(t,i){const e=t?.fontSize??i?.fontSize??16;lt(e,"Font size");const s=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof s&&lt(s,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*e;ut(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;ct(n,"Shadow offset X");const o=t?.shadowOffsetY??i?.shadowOffsetY??0;ct(o,"Shadow offset Y");const h=t?.shadowBlur??i?.shadowBlur??0;ct(h,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return ct(a,"Stroke width"),{color:t?.color??i?.color??"#000000",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize:e,fontStyle:t?.fontStyle??i?.fontStyle??"normal",fontWeight:s,lineHeight:r,enableShadow:t?.enableShadow??i?.enableShadow??!1,shadowOffsetX:n,shadowOffsetY:o,shadowBlur:h,shadowColor:t?.shadowColor??i?.shadowColor??"transparent",enableStroke:t?.enableStroke??i?.enableStroke??!1,strokeColor:t?.strokeColor??i?.strokeColor??"#000000",strokeWidth:a}}function qt(t){return t.match(/\S+|\s|\n/g)??[]}function Xt(t,i,e){if(t.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px ${e.fontFamily}`,"\n"===i)return{width:0,height:e.lineHeight,baseline:0,lineHeight:e.lineHeight};const s=t.measureText(i);return{width:Math.ceil(s.width),height:Math.ceil(s.actualBoundingBoxAscent+s.actualBoundingBoxDescent),baseline:s.actualBoundingBoxDescent,lineHeight:e.lineHeight}}function Yt(t,i,e,s,r){r.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,s.enableShadow&&(r.shadowOffsetX=s.shadowOffsetX,r.shadowOffsetY=s.shadowOffsetY,r.shadowBlur=s.shadowBlur,r.shadowColor=s.shadowColor),s.enableStroke&&(r.strokeStyle=s.strokeColor,r.lineWidth=s.strokeWidth,r.strokeText(e,t,i)),r.fillStyle=s.color,r.fillText(e,t,i)}function Gt(t){if("number"==typeof t)return{left:t,right:t,top:t,bottom:t};if("object"==typeof t&&null!==t){const i="left"in t&&"number"==typeof t.left?t.left:0,e="right"in t&&"number"==typeof t.right?t.right:0,s="top"in t&&"number"==typeof t.top?t.top:0,r="bottom"in t&&"number"==typeof t.bottom?t.bottom:0;return ct(i,"Padding left"),ct(e,"Padding right"),ct(s,"Padding top"),ct(r,"Padding bottom"),{left:i,right:e,top:s,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class Qt extends kt{constructor(t,i,e={}){const s=document.createElement("canvas"),r=s.getContext("2d");if(!r)throw Error("Failed to create canvas context");const n=new p(s),h=new Mt(n),a=new o(At,h);super(t,e.x??0,e.y??0,2,2,a),this.ui=1,this.li=1,this.Jt=()=>{this.li!==this.width/this.height&&(this.li=this.ui,this.height=this.width/this.ui)},this.layer.on(Z.WILL_RENDER,this.Jt),this.Qt=h,this.ci=n,this.di=s,this.fi=r,this.gi=i,this.pi=e.maxWidth??1024,this.wi=Gt(e.padding),this.yi=e.commonStyle??{},this.mi()}get color(){return this.Qt.getColor()}get opacity(){return this.Qt.getOpacity()}get transparency(){return this.Qt.getTransparency()}get content(){return this.gi}get maxWidth(){return this.pi}get padding(){return this.wi}get commonStyle(){return this.yi}set color(t){this.Qt.setColor(t)}set opacity(t){this.Qt.setOpacity(t)}set transparency(t){this.Qt.setTransparency(t)}set content(t){this.gi=t,this.mi()}set maxWidth(t){this.pi=t,this.mi()}set padding(t){this.wi=t,this.mi()}set commonStyle(t){this.yi=t,this.mi()}destroy(){this.layer.off(Z.WILL_RENDER,this.Jt),this.Qt.dispose(),this.ci.dispose(),this.di.remove(),super.destroy()}mi(){const{lines:t,size:i}=((t,i,e,s)=>{const r=[];for(const e of Array.isArray(i)?i:[i]){const i="string"==typeof e,n=i?e:e.text,o=Wt(i?void 0:e.style,s);for(const i of qt(n)){const e=Xt(t,i,o);r.push({text:i,style:o,metrics:e})}}const n=((t,i)=>{const e=[];let s=[],r=0,n=0,o=0,h=0;for(const a of i)"\n"!==a.text?r+a.metrics.width>t&&0!==s.length?(e.push({chunks:s,width:r,height:n,baseline:o,lineHeight:h}),s=[a],r=a.metrics.width,n=a.metrics.height,o=a.metrics.baseline,h=a.metrics.lineHeight):(s.push(a),r+=a.metrics.width,n=Math.max(n,a.metrics.height),o=Math.max(o,a.metrics.baseline),h=Math.max(h,a.metrics.lineHeight)):(s.length>0&&e.push({chunks:s,width:r,height:n,baseline:o,lineHeight:h}),s=[],r=0,n=0,o=0,h=0);return s.length>0&&e.push({chunks:s,width:r,height:n,baseline:o,lineHeight:h}),e})(e,r),o=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map(t=>t.width));let e=0;for(let i=0;t.length>i;i++){const s=t[i];e+=0===i?s.height:s.lineHeight,i===t.length-1&&(e+=s.baseline)}return{width:i,height:e}})(n);return{lines:n,size:o}})(this.fi,this.content,this.pi,this.yi);this.di.width=i.width+this.wi.left+this.wi.right,this.di.height=i.height+this.wi.top+this.wi.bottom,this.width=this.di.width,this.height=this.di.height,this.ui=(i.width+this.wi.left+this.wi.right)/(i.height+this.wi.top+this.wi.bottom),((t,i,e,s)=>{let r=this.wi.top;for(let t=0;e.length>t;t++){const n=e[t];let o=i;r+=0===t?n.height:n.lineHeight;for(const t of n.chunks)Yt(o,r,t.text,t.style,s),o+=t.metrics.width}})(0,this.wi.left,t,this.fi),this.ci.needsUpdate=!0}}class Zt extends it{constructor(t,i){void 0!==t&&lt(t,"UIFullscreenLayer.fixedWidth"),void 0!==i&&lt(i,"UIFullscreenLayer.fixedHeight"),super(1,1),this.bi=()=>{const t=this.xi();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Ei=t=>{const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,e=i?t.clientX-i.left:t.clientX,s=i?i.bottom-t.clientY:window.innerHeight-t.clientY,r=this.xi();this.clickInternal(e*r,s*r)},this.Ci=t,this._i=i,window.addEventListener("resize",this.bi),window.addEventListener("pointerdown",this.Ei),this.bi()}get fixedWidth(){return this.Ci}get fixedHeight(){return this._i}set fixedWidth(t){void 0!==t&&lt(t,"UIFullscreenLayer.fixedWidth"),t!==this.Ci&&(this.Ci=t,this.bi())}set fixedHeight(t){void 0!==t&&lt(t,"UIFullscreenLayer.fixedHeight"),t!==this._i&&(this._i=t,this.bi())}destroy(){window.removeEventListener("resize",this.bi),window.removeEventListener("pointerdown",this.Ei)}render(t,i){ut(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}xi(){return this.orientation===b.HORIZONTAL?void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:1:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:1}}function Jt(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||jt(t.style))}export{_t as UIAnchor,H as UIAnchorMode,yt as UIAspectConstraint,et as UIConstraint,wt as UIConstraint2DBuilder,bt as UICoverConstraintBuilder,Ct as UICustomConstraint,St as UIDummy,kt as UIElement,Tt as UIElementEvent,v as UIExpression,Et as UIFitConstraintBuilder,Zt as UIFullscreenLayer,rt as UIHeightConstraint,dt as UIHorizontalDistanceConstraint,ft as UIHorizontalProportionConstraint,Pt as UIImage,it as UILayer,Z as UILayerEvent,It as UIMicro,m as UIMode,Ft as UINineSlice,b as UIOrientation,R as UIPriority,Ht as UIProgress,Q as UIRelation,$t as UIScene,Dt as UISceneUpdateMode,st as UISingleParameterConstraint,Qt as UIText,gt as UIVerticalDistanceConstraint,pt as UIVerticalProportionConstraint,vt as UIWidthConstraint,D as convertPriority,J as convertRelation,Jt as isUITextSpan,jt as isUITextStyle,x as resolveOrientation,Gt as resolvePadding,N as resolvePriority,K as resolveRelation,Wt as resolveTextStyle};
1
+ import{PlaneGeometry as t,Color as i,Scene as s,OrthographicCamera as e,ShaderMaterial as r,Vector4 as h,Mesh as n,Texture as o,Vector2 as a,Vector3 as l,Matrix2 as c,Matrix3 as u,Matrix4 as f,MathUtils as d,Quaternion as g,WebGLRenderTarget as p,UnsignedByteType as w,LinearFilter as m,RGBAFormat as v,PerspectiveCamera as y,CanvasTexture as b}from"three";class x{constructor(t=0,i){this.constant=t,this._=i?new Map(i):new Map}static plus(t,i){const s=new x(t.constant+i.constant,Array.from(t._.entries()));for(const[t,e]of i._)s.plus(t,e);return s}static minus(t,i){const s=new x(t.constant-i.constant,Array.from(t._.entries()));for(const[t,e]of i._)s.minus(t,e);return s}plus(t,i){return this._.set(t,(this._.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this._)this._.set(i,s*t);return this}divide(t){return this.multiply(1/t)}hasTerm(t){return this._.has(t)}copy(t){this.constant=t.constant,this._.clear();for(const[i,s]of t._)this._.set(i,s);return this}clone(){return new x(this.constant,Array.from(this._.entries()))}prepareTermsInternal(){return Array.from(this._.entries())}}class _{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 r=e.v;if(0===r.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;r.length>t;t++){const i=r[t];e.l.remove(i.C,i.p)}return this}{const h=r.length;if(r[0].C===i&&r[0].p===s)return 1===h?this.o.delete(t):r.shift(),this;const n=h-1;if(r[n].C===i&&r[n].p===s)return r.pop(),this;if(10>h||r[0].M===r[n].M)for(let t=1;n>t;t++){const e=r[t];if(e.C===i&&e.p===s)return r.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let h=0,n=r.length-1;for(;n>=h;){const i=h+n>>>1;t>r[i].M?h=i+1:n=i-1}const o=h;for(n=r.length-1;n>=h;){const i=h+n>>>1;r[i].M>t?n=i-1:h=i+1}const a=n;for(let t=o;a>=t;t++)if(r[t].C===i&&r[t].p===s)return r.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 r=!1;for(let t=0;e.length>t;t++){const s=e[t];s.C.apply(s.p,i),s.k&&(r=!0,s.m=!0)}const h=this.o.get(t);if(void 0===h)return!0;h.v===e&&(h.u=!1);const n=h.v;if(r){let i=0;for(let t=0;n.length>t;t++){const s=n[t];s.m?h.l.remove(s.C,s.p):n[i++]=s}0===i?this.o.delete(t):n.length=i}return!0}h(t,i,s,e,r){let h=this.o.get(t);if(void 0===h)return void this.o.set(t,{v:[{C:e,p:r,M:s,k:i,m:!1}],u:!1,l:new _(e,r,s)});if(h.l.has(e,r))throw Error("Event listener already exists");h.l.insert(e,r,s);const n={C:e,p:r,M:s,k:i,m:!1};h.u&&(h.u=!1,h.v=h.v.slice());{const t=h.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 r=s+e>>>1;i>t[r].M?s=r+1:e=r}t.splice(s,0,n)}}}}var C,I;function U(t){return t??I.ALWAYS}function M(){return new B}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(C||(C={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(I||(I={}));class B{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new V(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new V(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new B;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class V{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new V(this.first,this.second)}}class S{constructor(t=""){this.I=t}id(){return this.U}name(){return this.I}setName(t){this.I=t}context(){return this.B}setContext(t){this.B=t}value(){return this.V}setValue(t){this.V=t}plus(t){return new A(this,t)}minus(t){return new A(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new A([t,this])}divide(t){return new A([1/t,this])}toJSON(){return{name:this.I,value:this.V}}toString(){return this.B+"["+this.I+":"+this.V+"]"}I;V=0;B=null;U=k++}let k=0;class A{constructor(){let t=(t=>{let i=0,s=()=>0,e=M();for(let r=0,h=t.length;h>r;++r){let h=t[r];if("number"==typeof h)i+=h;else if(h instanceof S)e.setDefault(h,s).second+=1;else if(h instanceof A){i+=h.constant();let t=h.terms();for(let i=0,r=t.size();r>i;i++){let r=t.itemAt(i);e.setDefault(r.first,s).second+=r.second}}else{if(!(h instanceof Array))throw Error("invalid Expression argument: "+h);{if(2!==h.length)throw Error("array must have length 2");let t=h[0],r=h[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(r instanceof S)e.setDefault(r,s).second+=t;else{if(!(r instanceof A))throw Error("array item 1 must be a variable or expression");{i+=r.constant()*t;let h=r.terms();for(let i=0,r=h.size();r>i;i++){let r=h.itemAt(i);e.setDefault(r.first,s).second+=r.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.S=t.terms,this.A=t.constant}terms(){return this.S}constant(){return this.A}value(){let t=this.A;for(let i=0,s=this.S.size();s>i;i++){let s=this.S.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new A(this,t)}minus(t){return new A(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new A([t,this])}divide(t){return new A([1/t,this])}isConstant(){return 0==this.S.size()}toString(){let t=this.S.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.A||(t+=" + "),t+=this.A,t}S;A}class P{static create(t,i,s,e=1){let r=0;return r+=1e6*Math.max(0,Math.min(1e3,t*e)),r+=1e3*Math.max(0,Math.min(1e3,i*e)),r+=Math.max(0,Math.min(1e3,s*e)),r}static required=P.create(1e3,1e3,1e3);static strong=P.create(1,0,0);static medium=P.create(0,1,0);static weak=P.create(0,0,1);static clip(t){return Math.max(0,Math.min(P.required,t))}}var T;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(T||(T={}));class L{constructor(t,i,s,e=P.required){this.P=i,this.T=P.clip(e),this.L=void 0===s&&t instanceof A?t:t.minus(s)}id(){return this.U}expression(){return this.L}op(){return this.P}strength(){return this.T}toString(){return this.L+" "+["<=",">=","="][this.P]+" 0 ("+this.T+")"}L;P;T;U=R++}let R=0;class H{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=P.required){let r=new L(t,i,s,e);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.R.find(t))throw Error("duplicate constraint");let i=this.H(t),s=i.row,e=i.tag,r=this.$(s,e);if(r.type()===z.Invalid&&s.allDummies()){if(!$(s.constant()))throw Error("unsatisfiable constraint");r=e.marker}if(r.type()===z.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.N(r,s),this.F.insert(r,s);this.R.insert(t,e),this.W(this.O)}removeConstraint(t){let i=this.R.erase(t);if(void 0===i)throw Error("unknown constraint");this.j(t,i.second);let s=i.second.marker,e=this.F.erase(s);if(void 0===e){let t=this.q(s);if(t.type()===z.Invalid)throw Error("failed to find leaving row");e=this.F.erase(t),e.second.solveForEx(t,s),this.N(s,e.second)}this.W(this.O)}hasConstraint(t){return this.R.contains(t)}getConstraints(){return this.R.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.Y.find(t))throw Error("duplicate edit variable");if((i=P.clip(i))===P.required)throw Error("bad required strength");let s=new A(t),e=new L(s,T.Eq,void 0,i);this.addConstraint(e);let r=this.R.find(e).second;this.Y.insert(t,{tag:r,constraint:e,constant:0})}removeEditVariable(t){let i=this.Y.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.Y.contains(t)}suggestValue(t,i){let s=this.Y.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.F,r=s.second,h=i-r.constant;r.constant=i;let n=r.tag.marker,o=e.find(n);if(void 0!==o)return 0>o.second.add(-h)&&this.G.push(n),void this.X();let a=r.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(h)&&this.G.push(a),void this.X();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,r=s.coefficientFor(n);0!==r&&0>s.add(h*r)&&i.first.type()!==z.External&&this.G.push(i.first)}this.X()}updateVariables(){let t=this.Z,i=this.F;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),r=i.find(e.second);e.first.setValue(void 0!==r?r.second.constant():0)}}J(t){return this.Z.setDefault(t,()=>this.K(z.External)).second}H(t){let i=t.expression(),s=new F(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!$(i.second)){let t=this.J(i.first),e=this.F.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let r=this.O,h=t.strength(),n={marker:N,other:N};switch(t.op()){case T.Le:case T.Ge:{let i=t.op()===T.Le?1:-1,e=this.K(z.Slack);if(n.marker=e,s.insertSymbol(e,i),P.required>h){let t=this.K(z.Error);n.other=t,s.insertSymbol(t,-i),r.insertSymbol(t,h)}break}case T.Eq:if(P.required>h){let t=this.K(z.Error),i=this.K(z.Error);n.marker=t,n.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),r.insertSymbol(t,h),r.insertSymbol(i,h)}else{let t=this.K(z.Dummy);n.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:n}}$(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()===z.External)return i.first}let e=i.marker.type();return e!==z.Slack&&e!==z.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==z.Slack&&e!==z.Error||t.coefficientFor(i.other)>=0?N:i.other):i.marker}D(t){let i=this.K(z.Slack);this.F.insert(i,t.copy()),this.tt=t.copy(),this.W(this.tt);let s=$(this.tt.constant());this.tt=null;let e=this.F.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let r=this.it(t);if(r.type()===z.Invalid)return!1;t.solveForEx(i,r),this.N(r,t),this.F.insert(r,t)}let r=this.F;for(let t=0,s=r.size();s>t;++t)r.itemAt(t).second.removeSymbol(i);return this.O.removeSymbol(i),s}N(t,i){let s=this.F;for(let e=0,r=s.size();r>e;++e){let r=s.itemAt(e);r.second.substitute(t,i),0>r.second.constant()&&r.first.type()!==z.External&&this.G.push(r.first)}this.O.substitute(t,i),this.tt&&this.tt.substitute(t,i)}W(t){let i=0;for(;this.maxIterations>i;){let s=this.st(t);if(s.type()===z.Invalid)return;let e=this.et(s);if(e.type()===z.Invalid)throw Error("the objective is unbounded");let r=this.F.erase(e).second;r.solveForEx(e,s),this.N(s,r),this.F.insert(s,r),i++}throw Error("solver iterations exceeded")}X(){let t=this.F,i=this.G;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.rt(e.second);if(i.type()===z.Invalid)throw Error("dual optimize failed");let r=e.second;t.erase(s),r.solveForEx(s,i),this.N(i,r),t.insert(i,r)}}}st(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()!==z.Dummy)return e}return N}rt(t){let i=Number.MAX_VALUE,s=N,e=t.cells();for(let t=0,r=e.size();r>t;++t){let r=e.itemAt(t),h=r.first,n=r.second;if(n>0&&h.type()!==z.Dummy){let t=this.O.coefficientFor(h)/n;i>t&&(i=t,s=h)}}return s}et(t){let i=Number.MAX_VALUE,s=N,e=this.F;for(let r=0,h=e.size();h>r;++r){let h=e.itemAt(r),n=h.first;if(n.type()!==z.External){let e=h.second,r=e.coefficientFor(t);if(0>r){let t=-e.constant()/r;i>t&&(i=t,s=n)}}}return s}q(t){let i=Number.MAX_VALUE,s=i,e=i,r=N,h=r,n=r,o=r,a=this.F;for(let i=0,r=a.size();r>i;++i){let r=a.itemAt(i),l=r.second,c=l.coefficientFor(t);if(0===c)continue;let u=r.first;if(u.type()===z.External)o=u;else if(0>c){let t=-l.constant()/c;s>t&&(s=t,h=u)}else{let t=l.constant()/c;e>t&&(e=t,n=u)}}return h!==r?h:n!==r?n:o}j(t,i){i.marker.type()===z.Error&&this.ht(i.marker,t.strength()),i.other.type()===z.Error&&this.ht(i.other,t.strength())}ht(t,i){let s=this.F.find(t);void 0!==s?this.O.insertRow(s.second,-i):this.O.insertSymbol(t,-i)}it(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===z.Slack||e===z.Error)return s.first}return N}K(t){return new D(t,this.nt++)}R=(()=>M())();F=(()=>M())();Z=(()=>M())();Y=(()=>M())();G=[];O=new F;tt=null;nt=0}function $(t){return 0>t?1e-8>-t:1e-8>t}var z;(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"})(z||(z={}));class D{constructor(t,i){this.U=i,this.ot=t}id(){return this.U}type(){return this.ot}U;ot}let N=new D(z.Invalid,-1);class F{constructor(t=0){this.A=t}cells(){return this.lt}constant(){return this.A}isConstant(){return this.lt.empty()}allDummies(){let t=this.lt;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==z.Dummy)return!1;return!0}copy(){let t=new F(this.A);return t.lt=this.lt.copy(),t}add(t){return this.A+=t}insertSymbol(t,i=1){$(this.lt.setDefault(t,()=>0).second+=i)&&this.lt.erase(t)}insertRow(t,i=1){this.A+=t.A*i;let s=t.lt;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.lt.erase(t)}reverseSign(){this.A=-this.A;let t=this.lt;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.lt,s=-1/i.erase(t).second;this.A*=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.lt.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.lt.erase(t);void 0!==s&&this.insertRow(i,s.second)}lt=M();A}const W=1e3;var O;function j(t){switch(t){case O.P0:return P.create(W,W,W);case O.P1:return P.create(100,0,0);case O.P2:return P.create(10,0,0);case O.P3:return P.create(0,100,0);case O.P4:return P.create(0,10,0);case O.P5:return P.create(0,0,100);case O.P6:return P.create(0,0,10);case O.P7:return P.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function q(t){return t??O.P0}(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"})(O||(O={}));const Y={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};var G,X;(t=>{t.CHANGE="change"})(G||(G={}));class Z extends E{constructor(...t){if(super(),this.rInternal=1,this.gInternal=1,this.bInternal=1,this.aInternal=1,3>t.length||"number"!=typeof t[0]){if(t.length>=1){const[i,s=1]=t;"string"==typeof i?this.setName(i,s):this.setHexRGB(i,s)}}else{const[i,s,e,r=1]=t;this.rInternal=i,this.gInternal=s,this.bInternal=e,this.aInternal=r}}get r(){return this.rInternal}get g(){return this.gInternal}get b(){return this.bInternal}get a(){return this.aInternal}set r(t){this.rInternal=t,this.emit(G.CHANGE,this)}set g(t){this.gInternal=t,this.emit(G.CHANGE,this)}set b(t){this.bInternal=t,this.emit(G.CHANGE,this)}set a(t){this.aInternal=t,this.emit(G.CHANGE,this)}set(t,i,s,e=this.aInternal){return this.rInternal=t,this.gInternal=i,this.bInternal=s,this.aInternal=e,this.emit(G.CHANGE,this),this}getHexRGBA(){return Math.round(255*this.rInternal)<<24|Math.round(255*this.gInternal)<<16|Math.round(255*this.bInternal)<<8|Math.round(255*this.aInternal)}getHexRGB(){return Math.round(255*this.rInternal)<<16|Math.round(255*this.gInternal)<<8|Math.round(255*this.bInternal)}getHSL(){const{rInternal:t,gInternal:i,bInternal:s}=this,e=Math.max(t,i,s),r=Math.min(t,i,s),h=e-r,n=(e+r)/2;let o=0;return 0!==h&&(o=e===t?(i-s)/h+(s>i?6:0):e===i?(s-t)/h+2:(t-i)/h+4,o*=60),{h:o,s:0===h?0:h/(1-Math.abs(2*n-1)),l:n}}setHexRGBA(t){return this.rInternal=(t>>16&255)/255,this.gInternal=(t>>8&255)/255,this.bInternal=(255&t)/255,this.aInternal=(t>>24&255)/255,this.emit(G.CHANGE,this),this}setHexRGB(t,i=this.aInternal){return this.rInternal=(t>>16&255)/255,this.gInternal=(t>>8&255)/255,this.bInternal=(255&t)/255,this.aInternal=i,this.emit(G.CHANGE,this),this}setHSL(t,i,s,e=this.aInternal){const r=(1-Math.abs(2*s-1))*i,h=t/60,n=r*(1-Math.abs(h%2-1));let[o,a,l]=1>h?[r,n,0]:2>h?[n,r,0]:3>h?[0,r,n]:4>h?[0,n,r]:5>h?[n,0,r]:[r,0,n];const c=s-r/2;return this.set(o+c,a+c,l+c,e)}setName(t,i=this.aInternal){const s=t.toLowerCase().trim(),e=Y[s];if(void 0===e)throw Error(`Unknown color name: "${t}".`);return this.setHexRGB(e,i)}copy(t){return t instanceof Z?(this.rInternal=t.rInternal,this.gInternal=t.gInternal,this.bInternal=t.bInternal,this.aInternal=t.aInternal):(this.rInternal=t.r,this.gInternal=t.g,this.bInternal=t.b,this.aInternal=1),this.emit(G.CHANGE,this),this}clone(){return new Z(this.rInternal,this.gInternal,this.bInternal,this.aInternal)}}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(X||(X={}));const J=.25,Q=new Map([[Z,"vec4"],[i,"vec3"],[o,"sampler2D"],[a,"vec2"],[l,"vec3"],[h,"vec4"],[c,"mat2"],[u,"mat3"],[f,"mat4"]]),K=new t(1,1).translate(.5,.5,0);let tt=new i,it=0,st=!1,et=!1,rt=!1,ht=!1;class nt{constructor(t,i){this.ct=new s,this.ut=new Map,this.ft=0,this.dt=new e(0,t,i,0,-1024,1024)}createPlane(t,i){const s=Object.entries(i),e=new r({uniforms:{alphaTest:{value:J},...Object.fromEntries(s.map(([t,i])=>[t,{value:i instanceof Z?new h(i.r,i.g,i.b,i.a):i}]))},vertexShader:"out vec2 io_UV;\n#include <common>\n\nvoid main() {\n #include <begin_vertex>\n io_UV = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"in vec2 io_UV;\n\nuniform float alphaTest;\n\n#include <common>\n#include <alphahash_pars_fragment>\n"+s.map(([t,i])=>((t,i)=>{if("number"==typeof i)return`uniform float ${t};`;for(const[s,e]of Q)if(i instanceof s)return`uniform ${e} ${t};`;throw Error(`Unsupported uniform type for key "${t}"`)})(t,i)).join("\n")+t,transparent:!1,alphaTest:J,alphaHash:!1,lights:!1,fog:!1,depthWrite:!1,depthTest:!1}),o=new n(K,e);o.matrixAutoUpdate=!1,this.ct.add(o);const a=this.ft++;return this.ut.set(a,{plane:o,material:e}),a}destroyPlane(t){const i=this.gt(t);return this.ct.remove(i.plane),this.ut.delete(t),this}setTransform(t,i){const s=this.gt(t);return s.plane.matrix.copy(i),s.plane.matrixWorldNeedsUpdate=!0,this}setUniform(t,i,s){const e=this.gt(t);if(!(i in e.material.uniforms))throw Error(`Uniform ${i} not found in material`);return s instanceof Z?e.material.uniforms[i].value.set(s.r,s.g,s.b,s.a):e.material.uniforms[i].value=s,this}setTransparency(t,i){const s=this.gt(t);return i===X.BLEND?(s.material.transparent=!0,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!1):i===X.CLIP?(s.material.transparent=!1,s.material.alphaTest=J,s.material.uniforms.alphaTest.value=J,s.material.alphaHash=!1):(s.material.transparent=!1,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!0),s.material.uniformsNeedUpdate=!0,s.material.needsUpdate=!0,this}setVisibility(t,i){return this.gt(t).plane.visible=i,this}resize(t,i){return this.dt.right=t,this.dt.top=i,this.dt.updateProjectionMatrix(),this}render(t){return tt=t.getClearColor(tt),it=t.getClearAlpha(),st=t.autoClear,et=t.autoClearColor,rt=t.autoClearDepth,ht=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.ct,this.dt),t.setClearColor(tt),t.setClearAlpha(it),t.autoClear=st,t.autoClearColor=et,t.autoClearDepth=rt,t.autoClearStencil=ht,this}gt(t){const i=this.ut.get(t);if(!i)throw Error("No descriptor found for handler "+t);return i}}var ot,at;function lt(t){switch(t){case ot.EQUAL:return T.Eq;case ot.LESS_THAN:return T.Le;case ot.GREATER_THAN:return T.Ge;default:throw Error("Invalid relation: "+t)}}function ct(t){return t??ot.EQUAL}(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(ot||(ot={}));class ut{constructor(){this.wt=new H,this.vt=!1,this.yt=new Map,this.bt=0,this.xt=new Map,this._t=0}createVariable(t,i){const s=this.bt++,e=new S;if(i===O.P0){const r={variable:e,priority:i,value:t};this.yt.set(s,r),r.constraint=this.Et(new x(0,[[s,1]]),new x(t),ot.EQUAL,i);try{this.wt?.addConstraint(r.constraint)}catch{this.wt=void 0}}else{this.yt.set(s,{variable:e,priority:i,value:t});try{this.wt?.addEditVariable(e,j(i)),this.wt?.suggestValue(e,t)}catch{this.wt=void 0}}return this.vt=!0,s}removeVariable(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error(`Variable ${t} is used in constraint`);try{i.constraint?this.wt?.removeConstraint(i.constraint):this.wt?.removeEditVariable(i.variable)}catch{this.wt=void 0}this.yt.delete(t),this.vt=!0}suggestVariableValue(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);s.value!==i&&(s.value=i,s.constraint?s.constraint=this.Ct(s.constraint,(new x).plus(t,1),new x(s.value),ot.EQUAL,s.priority):this.wt?.suggestValue(s.variable,i),this.vt=!0)}setVariablePriority(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);if(i!==s.priority){if(s.priority=i,s.priority===O.P0){const i=(new x).plus(t,1),e=new x(s.value);s.constraint=this.Et(i,e,ot.EQUAL,s.priority);try{this.wt?.addConstraint(s.constraint)}catch{this.wt=void 0}}else{if(s.constraint)try{this.wt?.removeConstraint(s.constraint)}catch{this.wt=void 0}s.constraint=void 0,this.It(t,s)}this.vt=!0}}readVariableValue(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return void 0===this.wt&&this.Ut(),this.vt&&(this.wt?.updateVariables(),this.vt=!1),i.variable.value()}createConstraint(t,i,s,e,r){const h=this._t++,n=this.Et(t,i,s,e);if(this.xt.set(h,{constraint:n,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:r}),r){try{this.wt?.addConstraint(n)}catch{this.wt=void 0}this.vt=!0}return h}removeConstraint(t){const i=this.xt.get(t);if(void 0===i)throw Error(`Constraint ${t} does not exist`);if(i.enabled)try{this.wt?.removeConstraint(i.constraint)}catch{this.wt=void 0}this.xt.delete(t),this.vt=!0}setConstraintLHS(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.lhs.copy(i),this.Mt(s),this.vt=!0}setConstraintRHS(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.rhs.copy(i),this.Mt(s),this.vt=!0}setConstraintRelation(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.relation!==i&&(s.relation=i,this.Mt(s),this.vt=!0)}setConstraintPriority(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.priority!==i&&(s.priority=i,this.Mt(s),this.vt=!0)}setConstraintEnabled(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);if(i!==s.enabled){s.enabled=i;try{s.enabled?this.wt?.addConstraint(s.constraint):this.wt?.removeConstraint(s.constraint)}catch{this.wt=void 0}this.vt=!0}}It(t,i){const s=[];for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.wt?.removeConstraint(i.constraint)}catch{this.wt=void 0}s.push(i)}this.wt?.removeEditVariable(i.variable),this.wt?.addEditVariable(i.variable,j(i.priority));for(const t of s)t.constraint=this.Et(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.wt?.addConstraint(t.constraint)}catch{this.wt=void 0;break}}Mt(t){t.constraint=t.enabled?this.Ct(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.Et(t.lhs,t.rhs,t.relation,t.priority)}Ct(t,i,s,e,r){try{this.wt?.removeConstraint(t)}catch{this.wt=void 0}const h=this.Et(i,s,e,r);try{this.wt?.addConstraint(h)}catch{this.wt=void 0}return h}Et(t,i,s,e){return new L(this.Bt(t),lt(s),this.Bt(i),j(e))}Bt(t){return new A(...t.prepareTermsInternal().map(([t,i])=>{const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);return[i,s.variable]}),t.constant)}Ut(){if(this.wt)throw Error("Solver already exists");this.wt=new H;for(const t of this.yt.values())t.constraint?this.wt.addConstraint(t.constraint):(this.wt.addEditVariable(t.variable,j(t.priority)),this.wt.suggestValue(t.variable,t.value));for(const t of this.xt.values())t.enabled&&this.wt.addConstraint(t.constraint);this.vt=!0}}(t=>{t.ORIENTATION_CHANGE="orientation_change",t.MODE_CHANGE="mode_change",t.WILL_RENDER="will_render"})(at||(at={}));class ft extends E{constructor(t,i){super(),this.name="",this.solverWrapper=new ut,this.modeInternal=C.VISIBLE,this.Vt=[],this.sceneWrapper=new nt(t,i),this.xVariable=this.solverWrapper.createVariable(0,O.P0),this.yVariable=this.solverWrapper.createVariable(0,O.P0),this.wVariable=this.solverWrapper.createVariable(t,O.P0),this.hVariable=this.solverWrapper.createVariable(i,O.P0),this.orientationInternal=t>i?I.HORIZONTAL:I.VERTICAL}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get mode(){return this.modeInternal}get orientation(){return this.orientationInternal}set mode(t){t!==this.modeInternal&&(this.modeInternal=t,this.emit(at.MODE_CHANGE,this.modeInternal,this))}resizeInternal(t,i){this.solverWrapper.suggestVariableValue(this.wVariable,t),this.solverWrapper.suggestVariableValue(this.hVariable,i),this.sceneWrapper.resize(t,i);const s=t>i?I.HORIZONTAL:I.VERTICAL;s!==this.orientationInternal&&(this.orientationInternal=s,this.emit(at.ORIENTATION_CHANGE,this.orientationInternal,this))}renderInternal(t,i){this.mode!==C.HIDDEN&&(this.emit(at.WILL_RENDER,t,i,this),this.sceneWrapper.render(t))}pointerClickInternal(t,i){if(this.mode===C.INTERACTIVE){this.Vt.sort((t,i)=>i.zIndex-t.zIndex);for(const s of this.Vt)if(s.listener.catchClick(t,i))return}}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperClientAPI(){return this.sceneWrapper}listenPointerInput(t,i){if(this.Vt.find(i=>i.listener===t))throw Error("Listener already exists");this.Vt.push({zIndex:i,listener:t})}setListenerZIndex(t,i){const s=this.Vt.findIndex(i=>i.listener===t);if(-1===s)throw Error("Listener not found");this.Vt[s].zIndex=i}unlistenPointerInput(t){const i=this.Vt.findIndex(i=>i.listener===t);if(-1===i)throw Error("Listener not found");this.Vt.splice(i,1)}}class dt{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal()}}class gt extends dt{constructor(t,i,s,e){super(t),this.St=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.priorityInternal=q(i),this.relationInternal=ct(s),this.orientationInternal=U(e),this.layer.on(at.ORIENTATION_CHANGE,this.St)}get priority(){return this.priorityInternal}get relation(){return this.relationInternal}get orientation(){return this.orientationInternal}set priority(t){t!==this.priorityInternal&&(this.priorityInternal=t,this.solverWrapper.setConstraintPriority(this.constraint,this.priorityInternal))}set relation(t){t!==this.relationInternal&&(this.relationInternal=t,this.solverWrapper.setConstraintRelation(this.constraint,this.relationInternal))}set orientation(t){t!==this.orientationInternal&&(this.orientationInternal=t,this.St())}destroy(){this.layer.off(at.ORIENTATION_CHANGE,this.St),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===I.ALWAYS||this.orientationInternal===this.layer.orientation}}class pt extends gt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.kt=t,this.At=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new x(0,[[this.kt.hVariable,1]]),new x(this.At),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.At}set height(t){this.At!==t&&(this.At=t,this.solverWrapper.setConstraintRHS(this.constraint,new x(t)))}}function wt(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof ft}function mt(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 vt(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}function yt(t,i,s){if(t instanceof ft&&i instanceof ft)throw Error(s+": layer cannot be snapped to another layer");let e,r;if(!(t instanceof ft||wt(t)))throw Error(s+": A must be a UILayer or a UIPointElement");if(e=t instanceof ft?t:t.layer,!(i instanceof ft||wt(i)))throw Error(s+": B must be a UILayer or a UIPointElement");if(r=i instanceof ft?i:i.layer,e!==r)throw Error(s+": elements must be on the same layer");return e}function bt(t,i){if(!Number.isFinite(t))throw Error(i+": value must be a finite number");if(Math.abs(t)>Number.MAX_SAFE_INTEGER)throw Error(i+": value exceeds maximum safe integer range")}function xt(t,i){if(bt(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function _t(t,i){if(bt(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class Et extends gt{constructor(t,i,s={}){super(yt(t,i,"UIHorizontalDistanceConstraint"),s.priority,s.relation,s.orientation),this.Pt=t,this.Tt=i,this.Lt=s.anchorA??.5,this.Rt=s.anchorB??.5,this.Ht=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.$t(),new x(this.Ht),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Ht}get anchorA(){return this.Lt}get anchorB(){return this.Rt}set distance(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintRHS(this.constraint,new x(this.Ht)))}set anchorA(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.$t()))}set anchorB(t){this.Rt!==t&&(this.Rt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.$t()))}$t(){let t,i;if(vt(this.Pt))t=new x(0,[[this.Pt.xVariable,1],[this.Pt.wVariable,this.Lt]]);else{if(!mt(this.Pt))throw Error("A is not a valid element type");t=(new x).plus(this.Pt.xVariable,1)}if(vt(this.Tt))i=new x(0,[[this.Tt.xVariable,1],[this.Tt.wVariable,this.Rt]]);else{if(!mt(this.Tt))throw Error("B is not a valid element type");i=(new x).plus(this.Tt.xVariable,1)}return x.minus(i,t)}}class Ct extends gt{constructor(t,i,s={}){super(yt(t,i,"UIHorizontalProportionConstraint"),s.priority,s.relation,s.orientation),this.Pt=t,this.Tt=i,this.zt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new x(0),this.Dt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt()))}Dt(){return x.minus(new x(0,[[this.Pt.wVariable,this.zt]]),new x(0,[[this.Tt.wVariable,1]]))}}class It extends gt{constructor(t,i,s={}){super(yt(t,i,"UIVerticalDistanceConstraint"),s.priority,s.relation,s.orientation),this.Pt=t,this.Tt=i,this.Lt=s.anchorA??.5,this.Rt=s.anchorB??.5,this.Ht=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.$t(),new x(this.Ht),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Ht}get anchorA(){return this.Lt}get anchorB(){return this.Rt}set distance(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintRHS(this.constraint,new x(this.Ht)))}set anchorA(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.$t()))}set anchorB(t){this.Rt!==t&&(this.Rt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.$t()))}$t(){let t,i;if(vt(this.Pt))t=new x(0,[[this.Pt.yVariable,1],[this.Pt.hVariable,this.Lt]]);else{if(!mt(this.Pt))throw Error("A is not a valid element type");t=(new x).plus(this.Pt.yVariable,1)}if(vt(this.Tt))i=new x(0,[[this.Tt.yVariable,1],[this.Tt.hVariable,this.Rt]]);else{if(!mt(this.Tt))throw Error("B is not a valid element type");i=(new x).plus(this.Tt.yVariable,1)}return x.minus(i,t)}}class Ut extends gt{constructor(t,i,s={}){super(yt(t,i,"UIVerticalProportionConstraint"),s.priority,s.relation,s.orientation),this.Pt=t,this.Tt=i,this.zt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new x(0),this.Dt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt()))}Dt(){return x.minus(new x(0,[[this.Pt.hVariable,this.zt]]),new x(0,[[this.Tt.hVariable,1]]))}}class Mt extends gt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.kt=t,this.Nt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new x(0,[[this.kt.wVariable,1]]),new x(this.Nt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Nt}set width(t){this.Nt!==t&&(this.Nt=t,this.solverWrapper.setConstraintRHS(this.constraint,new x(t)))}}class Bt{static size(t,i={}){return{h:new Mt(t,{width:i.size?.h,priority:i.priority?.h,relation:i.relation?.h,orientation:i.orientation?.h}),v:new pt(t,{height:i.size?.v,priority:i.priority?.v,relation:i.relation?.v,orientation:i.orientation?.v})}}static distance(t,i,s={}){return{h:new Et(t,i,{anchorA:s.anchorA?.h,anchorB:s.anchorB?.h,distance:s.distance?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new It(t,i,{anchorA:s.anchorA?.v,anchorB:s.anchorB?.v,distance:s.distance?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}static proportion(t,i,s={}){return{h:new Ct(t,i,{proportion:s.proportion?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new Ut(t,i,{proportion:s.proportion?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}}class Vt extends gt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.kt=t,this.Ft=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.$t(),new x(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Ft}set aspect(t){this.Ft!==t&&(this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.$t()))}$t(){return new x(0,[[this.kt.wVariable,1],[this.kt.hVariable,-this.Ft]])}}const St=.5;class kt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Et(t,i,{anchorA:s.anchorH??St,anchorB:s.anchorH??St,orientation:s.orientation}),yConstraint:new It(t,i,{anchorA:s.anchorV??St,anchorB:s.anchorV??St,orientation:s.orientation}),widthConstraint:new Ct(t,i,{proportion:1,relation:ot.GREATER_THAN,orientation:s.orientation}),heightConstraint:new Ut(t,i,{proportion:1,priority:O.P1,orientation:s.orientation})}}}const At=.5;class Pt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Et(t,i,{anchorA:s.anchorH??At,anchorB:s.anchorH??At,orientation:s.orientation}),yConstraint:new It(t,i,{anchorA:s.anchorV??At,anchorB:s.anchorV??At,orientation:s.orientation}),widthConstraint:new Ct(t,i,{proportion:1,relation:ot.LESS_THAN,orientation:s.orientation}),heightConstraint:new Ut(t,i,{proportion:1,priority:O.P1,orientation:s.orientation})}}}class Tt extends gt{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Wt=i,this.Ot=s,this.constraint=this.solverWrapper.createConstraint(this.Wt,this.Ot,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Wt}get rhs(){return this.Ot}setLHS(t){this.Wt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Wt)}setRHS(t){this.Ot=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Ot)}}class Lt extends E{constructor(t,i,s){bt(i,"UIAnchor x"),bt(s,"UIAnchor y"),super(),this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal(),this.xVariable=this.solverWrapper.createVariable(i,O.P7),this.yVariable=this.solverWrapper.createVariable(s,O.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){bt(t,"UIAnchor x"),this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){bt(t,"UIAnchor y"),this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}class Rt extends Lt{constructor(t,i={}){const s=i.x??0,e=i.y??0,r=i.width??100,h=i.height??100;xt(r,"UIDummy width"),xt(h,"UIDummy height"),super(t,s,e),this.wVariable=this.solverWrapper.createVariable(r,O.P6),this.hVariable=this.solverWrapper.createVariable(h,O.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){xt(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){xt(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}var Ht,$t;(t=>{t.CLICK="click"})(Ht||(Ht={})),(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})($t||($t={}));const zt=.5;class Dt{constructor(){this.jt=0,this.qt=0,this.Yt=zt,this.Gt=zt,this.Xt=1,this.Zt=1,this.Jt=0,this.Qt=$t.ROTATION_SCALE,this.vt=!1}get x(){return this.jt}get y(){return this.qt}get anchorX(){return this.Yt}get anchorY(){return this.Gt}get scaleX(){return this.Xt}get scaleY(){return this.Zt}get size(){return Math.max(this.Xt,this.Zt)}get angle(){return d.radToDeg(this.Jt)}get anchorMode(){return this.Qt}get rotation(){return this.Jt}set x(t){t!==this.jt&&(this.jt=t,this.vt=!0)}set y(t){t!==this.qt&&(this.qt=t,this.vt=!0)}set anchorX(t){t!==this.Yt&&(this.Yt=t,this.vt=!0)}set anchorY(t){t!==this.Gt&&(this.Gt=t,this.vt=!0)}set scaleX(t){t!==this.Xt&&(this.Xt=t,this.vt=!0)}set scaleY(t){t!==this.Zt&&(this.Zt=t,this.vt=!0)}set size(t){t===this.Xt&&t===this.Zt||(this.Xt=t,this.Zt=t,this.vt=!0)}set angle(t){const i=d.degToRad(t);i!==this.Jt&&(this.Jt=i,this.vt=!0)}set rotation(t){t!==this.Jt&&(this.Jt=t,this.vt=!0)}set anchorMode(t){t!==this.Qt&&(this.Qt=t,this.vt=!0)}reset(){0===this.jt&&0===this.qt&&this.Yt===zt&&this.Gt===zt&&1===this.Xt&&1===this.Zt&&0===this.Jt||(this.jt=0,this.qt=0,this.Yt=zt,this.Gt=zt,this.Xt=1,this.Zt=1,this.Jt=0,this.vt=!0)}getRecalculationRequiredInternal(){return this.vt}resetRecalculationRequiredInternal(){this.vt=!1}}const Nt=new l,Ft=new g,Wt=new l,Ot=new f,jt=new l(0,0,1);class qt extends Lt{constructor(t,i,s,e,r,h,n){xt(e,"UIElement width"),xt(r,"UIElement height"),super(t,i,s),this.micro=new Dt,this.modeInternal=C.VISIBLE,this.transparencyInternal=X.CLIP,this.zIndexInternal=0,this.onClick=(t,i)=>{const s=((t,i,s)=>t>s.x&&s.x+s.width>t&&i>s.y&&s.y+s.height>i)(t,i,this);return s&&this.emit(Ht.CLICK,t,i,this),s},this.layer.on(at.WILL_RENDER,this.onWillRender,this),this.wVariable=this.solverWrapper.createVariable(e,O.P6),this.hVariable=this.solverWrapper.createVariable(r,O.P6),this.sceneWrapper=t.getSceneWrapperClientAPI(),this.planeHandler=this.sceneWrapper.createPlane(h,n)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get zIndex(){return this.zIndexInternal}get mode(){return this.modeInternal}get transparency(){return this.transparencyInternal}set width(t){xt(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){xt(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){bt(t,"UIElement zIndex"),this.zIndexInternal=t,this.listener&&this.layer.setListenerZIndex(this.listener,t)}set mode(t){this.modeInternal!==t&&(t===C.INTERACTIVE?(this.listener={catchClick:this.onClick},this.layer.listenPointerInput(this.listener,this.zIndexInternal)):this.modeInternal===C.INTERACTIVE&&this.listener&&(this.layer.unlistenPointerInput(this.listener),this.listener=void 0),this.modeInternal=t,this.sceneWrapper.setVisibility(this.planeHandler,t!==C.HIDDEN))}set transparency(t){this.transparencyInternal=t,this.sceneWrapper.setTransparency(this.planeHandler,t)}destroy(){this.layer.off(at.WILL_RENDER,this.onWillRender,this),this.listener&&this.layer.unlistenPointerInput(this.listener),this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}onWillRender(t,i){const s=this.micro,e=this.width*s.scaleX,r=this.height*s.scaleY,h=s.anchorX*e,n=s.anchorY*r,o=Math.cos(s.rotation),a=Math.sin(s.rotation),l=h*o-n*a,c=h*a+n*o;if(s.anchorMode===$t.POSITION_ROTATION_SCALE)Nt.x=this.x+s.x-l,Nt.y=this.y+s.y-c;else{const t=s.anchorY*this.height;Nt.x=this.x+s.anchorX*this.width-l+s.x,Nt.y=this.y+t-c+s.y}Nt.z=this.zIndexInternal,Wt.x=e,Wt.y=r,Ft.setFromAxisAngle(jt,s.rotation),Ot.compose(Nt,Ft,Wt),this.sceneWrapper.setTransform(this.planeHandler,Ot)}}var Yt="void main() {\n vec4 diffuseColor = texture(map, io_UV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";class Gt extends qt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,h=s.color??new Z;super(t,s.x??0,s.y??0,e,r,Yt,{map:i,color:h}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ti=i,this.ii=h,this.ii.on(G.CHANGE,this.Kt)}get texture(){return this.ti}get color(){return this.ii}set texture(t){const i=t.image.width,s=t.image.height;xt(i,"UIImage texture width"),xt(s,"UIImage texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ti=t,this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ii.copy(t)}destroy(){this.ii.off(G.CHANGE,this.Kt),super.destroy()}}const Xt=.25;class Zt extends qt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,n=s.color??new Z,o=(t=>{if(null==t)return{l:Xt,r:Xt,t:Xt,b:Xt};if("number"==typeof t)return{l:t,r:t,t,b:t};if("object"==typeof t){if("horizontal"in t&&"vertical"in t){const i="number"==typeof t.horizontal?t.horizontal:Xt,s="number"==typeof t.vertical?t.vertical:Xt;return{l:i,r:i,t:s,b:s}}return{l:"number"==typeof t.left?t.left:Xt,r:"number"==typeof t.right?t.right:Xt,t:"number"==typeof t.top?t.top:Xt,b:"number"==typeof t.bottom?t.bottom:Xt}}return{l:Xt,r:Xt,t:Xt,b:Xt}})(s.sliceBorders),a=new h(o.l,o.r,o.t,o.b),l=new h(e,r,e,r);super(t,s.x??0,s.y??0,e,r,"vec2 calculateNineSliceUV() {\n vec2 localUV = io_UV;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * dimensions.x;\n float rightPx = right * dimensions.x;\n float topPx = top * dimensions.y;\n float bottomPx = bottom * dimensions.y;\n\n float lB = leftPx / dimensions.z;\n float rB = 1.0 - (rightPx / dimensions.z);\n float tB = topPx / dimensions.w;\n float bB = 1.0 - (bottomPx / dimensions.w);\n\n {\n float regionL = step(io_UV.x, lB);\n float regionR = step(rB, io_UV.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = io_UV.x * (left / lB);\n float xR = 1.0 - right + ((io_UV.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((io_UV.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(io_UV.y, tB);\n float regionB = step(bB, io_UV.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = io_UV.y * (top / tB);\n float yB = 1.0 - bottom + ((io_UV.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((io_UV.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 diffuseColor = texture(map, calculateNineSliceUV()) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n",{map:i,color:n,sliceBorders:a,dimensions:l}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ti=i,this.ii=n,this.si=a,this.ei=l,this.ii.on(G.CHANGE,this.Kt)}get texture(){return this.ti}get color(){return this.ii}get sliceBorderLeft(){return this.si.x}get sliceBorderRight(){return this.si.y}get sliceBorderTop(){return this.si.z}get sliceBorderBottom(){return this.si.w}set texture(t){const i=t.image.width,s=t.image.height;xt(i,"UINineSlice texture width"),xt(s,"UINineSlice texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ei.x=i,this.ei.y=s,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.ei),this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ii.copy(t)}set sliceBorderLeft(t){this.si.x=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderRight(t){this.si.y=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderTop(t){this.si.z=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderBottom(t){this.si.w=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}setSliceBorders(t,i,s,e){this.si.set(t,i,s,e),this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}destroy(){this.ii.off(G.CHANGE,this.Kt),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.ei.z=this.width*this.micro.scaleX,this.ei.w=this.height*this.micro.scaleY,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.ei)}}const Jt=new o;var Qt,Kt;(t=>{t.HORIZONTAL="float calculateMask() {\n return step((direction * io_UV.x + (1.0 - direction) * 0.5), progress);\n }",t.VERTICAL="float calculateMask() {\n return step((direction * io_UV.y + (1.0 - direction) * 0.5), progress);\n }",t.DIAGONAL="float calculateMask() {\n float d = (io_UV.x + io_UV.y) * (0.1);\n return step((direction * d + (1.0 - direction) * 0.5), progress);\n }",t.CIRCLE="float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / 3.14159265;\n angle *= 0.5;\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }"})(Qt||(Qt={}));class ti extends qt{constructor(t,i,s={}){const e=i.image?.width,r=i.image?.height;xt(e,"UIProgress foreground texture width"),xt(r,"UIProgress foreground texture height"),s.backgroundTexture&&(xt(s.backgroundTexture.image.width,"UIProgress background texture width"),xt(s.backgroundTexture.image.height,"UIProgress background texture height"));const h=s.color??new Z,n=s.foregroundColor??new Z,o=s.backgroundColor??new Z,a=s.progress??1,l=s.inverseDirection??!1;super(t,s.x??0,s.y??0,e,r,(s.maskFunction??Qt.HORIZONTAL)+"void main() {\n vec4 foregroundDiffuseColor = texture(foregroundTexture, io_UV) * foregroundColor * color;\n vec4 backgroundDiffuseColor = texture(backgroundTexture, io_UV) * backgroundColor * color;\n\n float mask = calculateMask();\n vec4 diffuseColor = foregroundDiffuseColor * mask\n + backgroundDiffuseColor * (1.0 - foregroundDiffuseColor.a * mask);\n\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n",{foregroundTexture:i,backgroundTexture:s.backgroundTexture??Jt,color:h,foregroundColor:n,backgroundColor:o,progress:a,direction:l?-1:1}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ri=t=>{this.sceneWrapper.setUniform(this.planeHandler,"foregroundColor",t)},this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"backgroundColor",t)},this.ni=i,this.oi=s.backgroundTexture,this.ii=h,this.ai=n,this.li=o,this.ci=a,this.ui=l,this.ii.on(G.CHANGE,this.Kt),this.ai.on(G.CHANGE,this.ri),this.li.on(G.CHANGE,this.hi)}get foregroundTexture(){return this.ni}get backgroundTexture(){return this.oi}get color(){return this.ii}get foregroundColor(){return this.ai}get backgroundColor(){return this.li}get progress(){return this.ci}get inverseDirection(){return this.ui}set foregroundTexture(t){const i=t.image.width,s=t.image.height;xt(i,"UIProgress foreground texture width"),xt(s,"UIProgress foreground texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ni=t,this.sceneWrapper.setUniform(this.planeHandler,"foregroundTexture",t)}set backgroundTexture(t){void 0!==t&&(xt(t.image.width,"UIProgress background texture width"),xt(t.image.height,"UIProgress background texture height")),this.oi=t,this.sceneWrapper.setUniform(this.planeHandler,"backgroundTexture",t)}set color(t){this.ii.copy(t)}set foregroundColor(t){this.ai.copy(t)}set backgroundColor(t){this.li.copy(t)}set inverseDirection(t){this.ui=t,this.sceneWrapper.setUniform(this.planeHandler,"direction",t?-1:1)}set progress(t){this.ci=t,this.sceneWrapper.setUniform(this.planeHandler,"progress",t)}destroy(){this.ii.off(G.CHANGE,this.Kt),this.ai.off(G.CHANGE,this.ri),this.li.off(G.CHANGE,this.hi),super.destroy()}}(t=>{t[t.EACH_FRAME=1]="EACH_FRAME",t[t.EACH_SECOND_FRAME=2]="EACH_SECOND_FRAME",t[t.PROPERTY_CHANGED=3]="PROPERTY_CHANGED",t[t.MANUAL=4]="MANUAL"})(Kt||(Kt={}));const ii=Kt.PROPERTY_CHANGED;class si extends qt{constructor(t,i={}){const e=i.resolutionFactor??.5;if(.1>e||e>2)throw Error(`Invalid resolution factor: ${e}. Must be between 0.1 and 2.`);const r=i.width??512,h=i.height??512,n=new p(r*e,h*e,{format:v,minFilter:m,magFilter:m,type:w,depthBuffer:i.enableDepthBuffer??!0,stencilBuffer:!1}),o=i.color??new Z;super(t,0,0,r,h,Yt,{map:n.texture,color:o}),this.fi=!0,this.di=!1,this.gi=!1,this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.pi=n,this.ii=o,this.wi=i.scene??new s,this.mi=i.camera??new y(75,r/h,.1,100),this.yi=e,this.bi=i.updateMode??ii,this.xi=i.clearColor??0,this._i=i.clearAlpha??0,i.updateMode===Kt.PROPERTY_CHANGED&&(this.gi=!0),this.ii.on(G.CHANGE,this.Kt)}get color(){return this.ii}get scene(){return this.wi}get camera(){return this.mi}get updateMode(){return this.bi}get resolutionFactor(){return this.yi}get clearColor(){return this.xi}get clearAlpha(){return this._i}set color(t){this.ii.copy(t)}set scene(t){this.wi!==t&&(this.wi=t,this.di=!0)}set camera(t){this.mi!==t&&(this.mi=t,this.di=!0)}set updateMode(t){this.bi!==t&&(this.bi=t,this.di=!0)}set resolutionFactor(t){this.yi!==t&&(this.yi=t,this.pi.setSize(this.width*this.yi,this.height*this.yi),this.di=!0)}set clearColor(t){this.xi!==t&&(this.xi=t,this.di=!0)}set clearAlpha(t){this._i!==t&&(this._i=t,this.di=!0)}destroy(){this.ii.off(G.CHANGE,this.Kt),this.pi.dispose(),super.destroy()}requestRender(){this.gi=!0}onWillRender(t){(this.bi===Kt.EACH_FRAME||this.bi===Kt.EACH_SECOND_FRAME&&this.fi||this.bi===Kt.PROPERTY_CHANGED&&this.di||this.bi===Kt.MANUAL&&this.gi)&&(this.gi=!1,this.di=!1,this.fi=!this.fi,this.pi.setSize(this.width*this.yi,this.height*this.yi),t.setClearColor(this.xi,this.clearAlpha),t.setRenderTarget(this.pi),t.clear(!0,!0,!1),t.render(this.wi,this.mi))}}function ei(t){return"object"==typeof t&&null!==t&&!("string"!=typeof t.color||"string"!=typeof t.fontFamily||"number"!=typeof t.fontSize||"normal"!==t.fontStyle&&"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||"normal"!==t.fontWeight&&"bold"!==t.fontWeight&&"bolder"!==t.fontWeight&&"lighter"!==t.fontWeight&&"number"!=typeof t.fontWeight||"number"!=typeof t.lineHeight||"boolean"!=typeof t.enableShadow||"number"!=typeof t.shadowOffsetX||"number"!=typeof t.shadowOffsetY||"number"!=typeof t.shadowBlur||"string"!=typeof t.shadowColor||"boolean"!=typeof t.enableStroke||"string"!=typeof t.strokeColor||"number"!=typeof t.strokeWidth)}function ri(t,i){const s=t?.fontSize??i?.fontSize??16;xt(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&xt(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;bt(r,"Line height");const h=t?.shadowOffsetX??i?.shadowOffsetX??0;_t(h,"Shadow offset X");const n=t?.shadowOffsetY??i?.shadowOffsetY??0;_t(n,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;_t(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return _t(a,"Stroke width"),{color:t?.color??i?.color??"#000000",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize:s,fontStyle:t?.fontStyle??i?.fontStyle??"normal",fontWeight:e,lineHeight:r,enableShadow:t?.enableShadow??i?.enableShadow??!1,shadowOffsetX:h,shadowOffsetY:n,shadowBlur:o,shadowColor:t?.shadowColor??i?.shadowColor??"transparent",enableStroke:t?.enableStroke??i?.enableStroke??!1,strokeColor:t?.strokeColor??i?.strokeColor??"#000000",strokeWidth:a}}function hi(t){return t.match(/\S+|\s|\n/g)??[]}function ni(t,i,s){if(t.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,"\n"===i)return{width:0,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 oi(t,i,s,e,r){r.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px ${e.fontFamily}`,e.enableShadow&&(r.shadowOffsetX=e.shadowOffsetX,r.shadowOffsetY=e.shadowOffsetY,r.shadowBlur=e.shadowBlur,r.shadowColor=e.shadowColor),e.enableStroke&&(r.strokeStyle=e.strokeColor,r.lineWidth=e.strokeWidth,r.strokeText(s,t,i)),r.fillStyle=e.color,r.fillText(s,t,i)}function ai(t){if("number"==typeof t)return{left:t,right:t,top:t,bottom:t};if("object"==typeof t&&null!==t){const i="left"in t&&"number"==typeof t.left?t.left:0,s="right"in t&&"number"==typeof t.right?t.right:0,e="top"in t&&"number"==typeof t.top?t.top:0,r="bottom"in t&&"number"==typeof t.bottom?t.bottom:0;return _t(i,"Padding left"),_t(s,"Padding right"),_t(e,"Padding top"),_t(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class li extends qt{constructor(t,i,s={}){const e=new OffscreenCanvas(2,2),r=e.getContext("2d");if(!r)throw Error("UIText failed to create canvas context");const h=new b(e),n=s.color??new Z;super(t,s.x??0,s.y??0,2,2,Yt,{map:h,color:n}),this.Ei=1,this.Ci=1,this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.Ii=e,this.Ui=r,this.Mi=h,this.ii=n,this.Bi=i,this.Vi=s.maxWidth??1024,this.Si=ai(s.padding),this.ki=s.commonStyle??{},this.ii.on(G.CHANGE,this.Kt),this.Ai()}get color(){return this.ii}get content(){return this.Bi}get maxWidth(){return this.Vi}get padding(){return this.Si}get commonStyle(){return this.ki}set color(t){this.ii.copy(t)}set content(t){this.Bi=t,this.Ai()}set maxWidth(t){this.Vi=t,this.Ai()}set padding(t){this.Si=t,this.Ai()}set commonStyle(t){this.ki=t,this.Ai()}destroy(){this.ii.off(G.CHANGE,this.Kt),this.Mi.dispose(),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.Ci!==this.width/this.height&&(this.Ci=this.Ei,this.height=this.width/this.Ei)}Ai(){const{lines:t,size:i}=((t,i,s,e)=>{const r=[];for(const s of Array.isArray(i)?i:[i]){const i="string"==typeof s,h=i?s:s.text,n=ri(i?void 0:s.style,e);for(const i of hi(h)){const s=ni(t,i,n);r.push({text:i,style:n,metrics:s})}}const h=((t,i)=>{const s=[];let e=[],r=0,h=0,n=0,o=0;for(const a of i)"\n"!==a.text?r+a.metrics.width>t&&0!==e.length?(s.push({chunks:e,width:r,height:h,baseline:n,lineHeight:o}),e=[a],r=a.metrics.width,h=a.metrics.height,n=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),r+=a.metrics.width,h=Math.max(h,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:r,height:h,baseline:n,lineHeight:o}),e=[],r=0,h=0,n=0,o=0);return e.length>0&&s.push({chunks:e,width:r,height:h,baseline:n,lineHeight:o}),s})(s,r),n=(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,i===t.length-1&&(s+=e.baseline)}return{width:i,height:s}})(h);return{lines:h,size:n}})(this.Ui,this.content,this.Vi,this.ki);this.Ii.width=i.width+this.Si.left+this.Si.right,this.Ii.height=i.height+this.Si.top+this.Si.bottom,this.width=this.Ii.width,this.height=this.Ii.height,this.Ei=(i.width+this.Si.left+this.Si.right)/(i.height+this.Si.top+this.Si.bottom),((t,i,s,e)=>{let r=this.Si.top;for(let t=0;s.length>t;t++){const h=s[t];let n=i;r+=0===t?h.height:h.lineHeight;for(const t of h.chunks)oi(n,r,t.text,t.style,e),n+=t.metrics.width}})(0,this.Si.left,t,this.Ui),this.Mi.needsUpdate=!0}}class ci extends ft{constructor(t,i){void 0!==t&&xt(t,"UIFullscreenLayer.fixedWidth"),void 0!==i&&xt(i,"UIFullscreenLayer.fixedHeight"),super(window.innerWidth,window.innerHeight),this.Pi=()=>{const t=this.Ti();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Li=t=>{const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,s=i?t.clientX-i.left:t.clientX,e=i?i.bottom-t.clientY:window.innerHeight-t.clientY,r=this.Ti();this.pointerClickInternal(s*r,e*r)},this.Ri=t,this.Hi=i,window.addEventListener("resize",this.Pi),window.addEventListener("pointerdown",this.Li),this.Pi()}get fixedWidth(){return this.Ri}get fixedHeight(){return this.Hi}set fixedWidth(t){void 0!==t&&xt(t,"UIFullscreenLayer.fixedWidth"),t!==this.Ri&&(this.Ri=t,this.Pi())}set fixedHeight(t){void 0!==t&&xt(t,"UIFullscreenLayer.fixedHeight"),t!==this.Hi&&(this.Hi=t,this.Pi())}destroy(){window.removeEventListener("resize",this.Pi),window.removeEventListener("pointerdown",this.Li)}render(t,i){bt(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}Ti(){return this.orientation===I.HORIZONTAL?void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:1:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:1}}function ui(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||ei(t.style))}export{Lt as UIAnchor,Vt as UIAspectConstraint,Z as UIColor,G as UIColorEvent,dt as UIConstraint,Bt as UIConstraint2DBuilder,kt as UICoverConstraintBuilder,Tt as UICustomConstraint,Rt as UIDummy,qt as UIElement,x as UIExpression,Pt as UIFitConstraintBuilder,ci as UIFullscreenLayer,pt as UIHeightConstraint,Et as UIHorizontalDistanceConstraint,Ct as UIHorizontalProportionConstraint,Gt as UIImage,Ht as UIInputEvent,ft as UILayer,at as UILayerEvent,Dt as UIMicro,$t as UIMicroAnchorMode,C as UIMode,Zt as UINineSlice,I as UIOrientation,O as UIPriority,ti as UIProgress,Qt as UIProgressMaskFunction,ot as UIRelation,si as UIScene,Kt as UISceneUpdateMode,gt as UISingleParameterConstraint,li as UIText,X as UITransparencyMode,It as UIVerticalDistanceConstraint,Ut as UIVerticalProportionConstraint,Mt as UIWidthConstraint,j as convertPriority,lt as convertRelation,ui as isUITextSpan,ei as isUITextStyle,U as resolveOrientation,q as resolvePriority,ct as resolveRelation,ai as resolveTextPadding,ri as resolveTextStyle};
2
2
  //# sourceMappingURL=index.min.js.map