laymur 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +353 -2
  2. package/dist/builders/UIConstraint2DBuilder.d.ts +102 -14
  3. package/dist/composer/UIComposer.d.ts +0 -0
  4. package/dist/composer/UIFullscreenQuad.d.ts +0 -0
  5. package/dist/composer/UIPass.d.ts +0 -0
  6. package/dist/constraints/UIAspectConstraint.d.ts +40 -36
  7. package/dist/constraints/UIConstraint.d.ts +17 -20
  8. package/dist/constraints/UICoverConstraint.d.ts +0 -72
  9. package/dist/constraints/UICustomConstraint.d.ts +60 -0
  10. package/dist/constraints/UIFitConstraint.d.ts +0 -72
  11. package/dist/constraints/UIHeightConstraint.d.ts +32 -38
  12. package/dist/constraints/UIHorizontalDistanceConstraint.d.ts +77 -46
  13. package/dist/constraints/UIHorizontalProportionConstraint.d.ts +49 -40
  14. package/dist/constraints/UISingleParameterConstraint.d.ts +108 -0
  15. package/dist/constraints/UIVerticalDistanceConstraint.d.ts +77 -46
  16. package/dist/constraints/UIVerticalProportionConstraint.d.ts +49 -40
  17. package/dist/constraints/UIWidthConstraint.d.ts +32 -38
  18. package/dist/elements/UIAnchor.d.ts +58 -45
  19. package/dist/elements/UIDummy.d.ts +63 -12
  20. package/dist/elements/UIElement.d.ts +81 -93
  21. package/dist/elements/UIImage.d.ts +64 -33
  22. package/dist/elements/UINineSline.d.ts +0 -0
  23. package/dist/elements/UIProgress.d.ts +7 -95
  24. package/dist/elements/UIScene.d.ts +142 -84
  25. package/dist/elements/UIText.d.ts +124 -43
  26. package/dist/index.d.ts +10 -11
  27. package/dist/index.js +2867 -2718
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.min.js +1 -1
  30. package/dist/index.min.js.map +1 -1
  31. package/dist/layers/UIFullscreenLayer.d.ts +112 -0
  32. package/dist/layers/UILayer.d.ts +134 -57
  33. package/dist/materials/UIInstancedMaterial.d.ts +0 -0
  34. package/dist/materials/UIMaterial.d.ts +6 -6
  35. package/dist/materials/UINineSliceMaterial.d.ts +0 -0
  36. package/dist/materials/UIProgressMaterial.d.ts +0 -4
  37. package/dist/miscellaneous/UIExpression.d.ts +117 -0
  38. package/dist/miscellaneous/UIMicro.d.ts +73 -119
  39. package/dist/miscellaneous/UIOrientation.d.ts +2 -9
  40. package/dist/miscellaneous/UIPriority.d.ts +56 -0
  41. package/dist/miscellaneous/UIRelation.d.ts +43 -0
  42. package/dist/miscellaneous/UITextPadding.d.ts +7 -0
  43. package/dist/miscellaneous/UITextSpan.d.ts +6 -0
  44. package/dist/miscellaneous/UITextStyle.d.ts +18 -0
  45. package/dist/miscellaneous/asserts.d.ts +111 -4
  46. package/dist/miscellaneous/textInterfaces.d.ts +19 -0
  47. package/dist/miscellaneous/textTools.d.ts +8 -5
  48. package/dist/scalable/UIScalableMesh.d.ts +16 -0
  49. package/dist/scalable/UIScalablePlaneMesh.d.ts +14 -0
  50. package/dist/wrappers/UISceneWrapper.d.ts +18 -0
  51. package/dist/wrappers/UISolverWrapper.d.ts +29 -0
  52. package/package.json +1 -1
  53. package/dist/Passes/UIComposer.d.ts +0 -114
  54. package/dist/Passes/UIFullScreenQuad.d.ts +0 -51
  55. package/dist/Passes/UIPass.d.ts +0 -43
  56. package/dist/builders/UIConstraintContainerBuilder.d.ts +0 -20
  57. package/dist/builders/UIConstraintStackBuilder.d.ts +0 -24
  58. package/dist/constraints/UIConstraintPower.d.ts +0 -57
  59. package/dist/constraints/UIConstraintRule.d.ts +0 -46
  60. package/dist/layers/UIFullScreenLayer.d.ts +0 -13
  61. package/dist/miscellaneous/UIBlending.d.ts +0 -7
  62. package/dist/miscellaneous/UITextInterfaces.d.ts +0 -49
  63. package/dist/miscellaneous/math.d.ts +0 -1
  64. package/dist/miscellaneous/microTransformationTools.d.ts +0 -3
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import{MathUtils as t,Vector2 as i,Box2 as s,Matrix3 as e,Vector3 as h,ShaderMaterial as r,Color as n,AddEquation as o,SrcAlphaFactor as a,OneMinusSrcAlphaFactor as c,NormalBlending as l,CustomBlending as u,OneMinusDstColorFactor as d,OneFactor as f,MultiplyBlending as w,SubtractiveBlending as g,AdditiveBlending as p,PlaneGeometry as v,Scene as m,Mesh as b,OrthographicCamera as y,WebGLRenderTarget as C,UnsignedByteType as x,LinearFilter as E,RGBAFormat as _,NoBlending as I,Object3D as k,UniformsUtils as M,PerspectiveCamera as S,CanvasTexture as O}from"three";function T(){return new F}class F{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 A(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 A(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 F;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 A{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new A(this.first,this.second)}}class V{constructor(t=""){this.C=t}id(){return this._}name(){return this.C}setName(t){this.C=t}context(){return this.I}setContext(t){this.I=t}value(){return this.S}setValue(t){this.S=t}plus(t){return new z(this,t)}minus(t){return new z(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new z([t,this])}divide(t){return new z([1/t,this])}toJSON(){return{name:this.C,value:this.S}}toString(){return this.I+"["+this.C+":"+this.S+"]"}C;S=0;I=null;_=B++}let B=0;class z{constructor(){let t=(t=>{let i=0,s=()=>0,e=T();for(let h=0,r=t.length;r>h;++h){let r=t[h];if("number"==typeof r)i+=r;else if(r instanceof V)e.setDefault(r,s).second+=1;else if(r instanceof z){i+=r.constant();let t=r.terms();for(let i=0,h=t.size();h>i;i++){let h=t.itemAt(i);e.setDefault(h.first,s).second+=h.second}}else{if(!(r instanceof Array))throw Error("invalid Expression argument: "+r);{if(2!==r.length)throw Error("array must have length 2");let t=r[0],h=r[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(h instanceof V)e.setDefault(h,s).second+=t;else{if(!(h instanceof z))throw Error("array item 1 must be a variable or expression");{i+=h.constant()*t;let r=h.terms();for(let i=0,h=r.size();h>i;i++){let h=r.itemAt(i);e.setDefault(h.first,s).second+=h.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.O=t.terms,this.T=t.constant}terms(){return this.O}constant(){return this.T}value(){let t=this.T;for(let i=0,s=this.O.size();s>i;i++){let s=this.O.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new z(this,t)}minus(t){return new z(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new z([t,this])}divide(t){return new z([1/t,this])}isConstant(){return 0==this.O.size()}toString(){let t=this.O.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.T||(t+=" + "),t+=this.T,t}O;T}class D{static create(t,i,s,e=1){let h=0;return h+=1e6*Math.max(0,Math.min(1e3,t*e)),h+=1e3*Math.max(0,Math.min(1e3,i*e)),h+=Math.max(0,Math.min(1e3,s*e)),h}static required=D.create(1e3,1e3,1e3);static strong=D.create(1,0,0);static medium=D.create(0,1,0);static weak=D.create(0,0,1);static clip(t){return Math.max(0,Math.min(D.required,t))}}var P;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(P||(P={}));class ${constructor(t,i,s,e=D.required){this.F=i,this.A=D.clip(e),this.V=void 0===s&&t instanceof z?t:t.minus(s)}id(){return this._}expression(){return this.V}op(){return this.F}strength(){return this.A}toString(){return this.V+" "+["<=",">=","="][this.F]+" 0 ("+this.A+")"}V;F;A;_=U++}let U=0;class R{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=D.required){let h=new $(t,i,s,e);return this.addConstraint(h),h}addConstraint(t){if(void 0!==this.B.find(t))throw Error("duplicate constraint");let i=this.D(t),s=i.row,e=i.tag,h=this.P(s,e);if(h.type()===H.Invalid&&s.allDummies()){if(!L(s.constant()))throw Error("unsatisfiable constraint");h=e.marker}if(h.type()===H.Invalid){if(!this.$(s))throw Error("unsatisfiable constraint")}else s.solveFor(h),this.U(h,s),this.R.insert(h,s);this.B.insert(t,e),this.L(this.H)}removeConstraint(t){let i=this.B.erase(t);if(void 0===i)throw Error("unknown constraint");this.j(t,i.second);let s=i.second.marker,e=this.R.erase(s);if(void 0===e){let t=this.N(s);if(t.type()===H.Invalid)throw Error("failed to find leaving row");e=this.R.erase(t),e.second.solveForEx(t,s),this.U(s,e.second)}this.L(this.H)}hasConstraint(t){return this.B.contains(t)}getConstraints(){return this.B.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.W.find(t))throw Error("duplicate edit variable");if((i=D.clip(i))===D.required)throw Error("bad required strength");let s=new z(t),e=new $(s,P.Eq,void 0,i);this.addConstraint(e);let h=this.B.find(e).second;this.W.insert(t,{tag:h,constraint:e,constant:0})}removeEditVariable(t){let i=this.W.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.W.contains(t)}suggestValue(t,i){let s=this.W.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.R,h=s.second,r=i-h.constant;h.constant=i;let n=h.tag.marker,o=e.find(n);if(void 0!==o)return 0>o.second.add(-r)&&this.X.push(n),void this.Y();let a=h.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(r)&&this.X.push(a),void this.Y();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,h=s.coefficientFor(n);0!==h&&0>s.add(r*h)&&i.first.type()!==H.External&&this.X.push(i.first)}this.Y()}updateVariables(){let t=this.q,i=this.R;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),h=i.find(e.second);e.first.setValue(void 0!==h?h.second.constant():0)}}G(t){return this.q.setDefault(t,()=>this.J(H.External)).second}D(t){let i=t.expression(),s=new W(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!L(i.second)){let t=this.G(i.first),e=this.R.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let h=this.H,r=t.strength(),n={marker:N,other:N};switch(t.op()){case P.Le:case P.Ge:{let i=t.op()===P.Le?1:-1,e=this.J(H.Slack);if(n.marker=e,s.insertSymbol(e,i),D.required>r){let t=this.J(H.Error);n.other=t,s.insertSymbol(t,-i),h.insertSymbol(t,r)}break}case P.Eq:if(D.required>r){let t=this.J(H.Error),i=this.J(H.Error);n.marker=t,n.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),h.insertSymbol(t,r),h.insertSymbol(i,r)}else{let t=this.J(H.Dummy);n.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:n}}P(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()===H.External)return i.first}let e=i.marker.type();return e!==H.Slack&&e!==H.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==H.Slack&&e!==H.Error||t.coefficientFor(i.other)>=0?N:i.other):i.marker}$(t){let i=this.J(H.Slack);this.R.insert(i,t.copy()),this.K=t.copy(),this.L(this.K);let s=L(this.K.constant());this.K=null;let e=this.R.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let h=this.Z(t);if(h.type()===H.Invalid)return!1;t.solveForEx(i,h),this.U(h,t),this.R.insert(h,t)}let h=this.R;for(let t=0,s=h.size();s>t;++t)h.itemAt(t).second.removeSymbol(i);return this.H.removeSymbol(i),s}U(t,i){let s=this.R;for(let e=0,h=s.size();h>e;++e){let h=s.itemAt(e);h.second.substitute(t,i),0>h.second.constant()&&h.first.type()!==H.External&&this.X.push(h.first)}this.H.substitute(t,i),this.K&&this.K.substitute(t,i)}L(t){let i=0;for(;this.maxIterations>i;){let s=this.tt(t);if(s.type()===H.Invalid)return;let e=this.it(s);if(e.type()===H.Invalid)throw Error("the objective is unbounded");let h=this.R.erase(e).second;h.solveForEx(e,s),this.U(s,h),this.R.insert(s,h),i++}throw Error("solver iterations exceeded")}Y(){let t=this.R,i=this.X;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.st(e.second);if(i.type()===H.Invalid)throw Error("dual optimize failed");let h=e.second;t.erase(s),h.solveForEx(s,i),this.U(i,h),t.insert(i,h)}}}tt(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()!==H.Dummy)return e}return N}st(t){let i=Number.MAX_VALUE,s=N,e=t.cells();for(let t=0,h=e.size();h>t;++t){let h=e.itemAt(t),r=h.first,n=h.second;if(n>0&&r.type()!==H.Dummy){let t=this.H.coefficientFor(r)/n;i>t&&(i=t,s=r)}}return s}it(t){let i=Number.MAX_VALUE,s=N,e=this.R;for(let h=0,r=e.size();r>h;++h){let r=e.itemAt(h),n=r.first;if(n.type()!==H.External){let e=r.second,h=e.coefficientFor(t);if(0>h){let t=-e.constant()/h;i>t&&(i=t,s=n)}}}return s}N(t){let i=Number.MAX_VALUE,s=i,e=i,h=N,r=h,n=h,o=h,a=this.R;for(let i=0,h=a.size();h>i;++i){let h=a.itemAt(i),c=h.second,l=c.coefficientFor(t);if(0===l)continue;let u=h.first;if(u.type()===H.External)o=u;else if(0>l){let t=-c.constant()/l;s>t&&(s=t,r=u)}else{let t=c.constant()/l;e>t&&(e=t,n=u)}}return r!==h?r:n!==h?n:o}j(t,i){i.marker.type()===H.Error&&this.et(i.marker,t.strength()),i.other.type()===H.Error&&this.et(i.other,t.strength())}et(t,i){let s=this.R.find(t);void 0!==s?this.H.insertRow(s.second,-i):this.H.insertSymbol(t,-i)}Z(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===H.Slack||e===H.Error)return s.first}return N}J(t){return new j(t,this.ht++)}B=(()=>T())();R=(()=>T())();q=(()=>T())();W=(()=>T())();X=[];H=new W;K=null;ht=0}function L(t){return 0>t?1e-8>-t:1e-8>t}var H;(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"})(H||(H={}));class j{constructor(t,i){this._=i,this.rt=t}id(){return this._}type(){return this.rt}_;rt}let N=new j(H.Invalid,-1);class W{constructor(t=0){this.T=t}cells(){return this.nt}constant(){return this.T}isConstant(){return this.nt.empty()}allDummies(){let t=this.nt;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==H.Dummy)return!1;return!0}copy(){let t=new W(this.T);return t.nt=this.nt.copy(),t}add(t){return this.T+=t}insertSymbol(t,i=1){L(this.nt.setDefault(t,()=>0).second+=i)&&this.nt.erase(t)}insertRow(t,i=1){this.T+=t.T*i;let s=t.nt;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.nt.erase(t)}reverseSign(){this.T=-this.T;let t=this.nt;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.nt,s=-1/i.erase(t).second;this.T*=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.nt.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.nt.erase(t);void 0!==s&&this.insertRow(i,s.second)}nt=T();T}var X;function Y(t){return null!==t&&Object.values(X).some(i=>i===t)}function q(t){return t??X.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(X||(X={}));class G{constructor(t,i){this.layer=t,this.name="",this.layer.addUIConstraintInternal(this,i)}destroy(){this.layer.removeUIConstraintInternal(this)}}const J=1e3;var Q,K;function Z(t){return null!==t&&Object.values(Q).some(i=>i===t)}function tt(t){return t??Q.P0}function it(t){switch(t){case Q.P0:return D.create(J,J,J);case Q.P1:return D.create(100,0,0);case Q.P2:return D.create(10,0,0);case Q.P3:return D.create(0,100,0);case Q.P4:return D.create(0,10,0);case Q.P5:return D.create(0,0,100);case Q.P6:return D.create(0,0,10);case Q.P7:return D.create(0,0,1);default:return D.create(J,J,J)}}function st(t){return null!==t&&Object.values(K).some(i=>i===t)}function et(t){return t??K.EQUAL}function ht(t){switch(t){case K.EQUAL:return P.Eq;case K.LESS:return P.Le;case K.GREATER:return P.Ge;default:return P.Eq}}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(Q||(Q={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(K||(K={}));class rt extends G{constructor(t,i={}){super(t.layer,new Set([t])),this.ot=t,this.ct={height:i.height??t.height,power:tt(i.power),rule:et(i.rule),orientation:q(i.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){this.lt=new $(new z(this.ot.heightInternal),ht(this.ct.rule),this.ct.height,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class nt{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 ot{constructor(){this.o=new Map}on(t,i,s,e=0){return this.h(t,!1,e,i,s),this}once(t,i,s,e=0){return this.h(t,!0,e,i,s),this}off(t,i,s){const e=this.o.get(t);if(void 0===e)return this;e.u&&(e.u=!1,e.v=e.v.slice());const h=e.v;if(0===h.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;h.length>t;t++){const i=h[t];e.l.remove(i.ut,i.p)}return this}{const r=h.length;if(h[0].ut===i&&h[0].p===s)return 1===r?this.o.delete(t):h.shift(),this;const n=r-1;if(h[n].ut===i&&h[n].p===s)return h.pop(),this;if(10>r||h[0].M===h[n].M)for(let t=1;n>t;t++){const e=h[t];if(e.ut===i&&e.p===s)return h.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let r=0,n=h.length-1;for(;n>=r;){const i=r+n>>>1;t>h[i].M?r=i+1:n=i-1}const o=r;for(n=h.length-1;n>=r;){const i=r+n>>>1;h[i].M>t?n=i-1:r=i+1}const a=n;for(let t=o;a>=t;t++)if(h[t].ut===i&&h[t].p===s)return h.splice(t,1),this}}return this}emit(t,...i){const s=this.o.get(t);if(void 0===s)return!1;if(0===s.v.length)return!1;s.u?s.v=s.v.slice():s.u=!0;const e=s.v;let h=!1;for(let t=0;e.length>t;t++){const s=e[t];s.ut.apply(s.p,i),s.k&&(h=!0,s.m=!0)}const r=this.o.get(t);if(void 0===r)return!0;r.v===e&&(r.u=!1);const n=r.v;if(h){let i=0;for(let t=0;n.length>t;t++){const s=n[t];s.m?r.l.remove(s.ut,s.p):n[i++]=s}0===i?this.o.delete(t):n.length=i}return!0}h(t,i,s,e,h){let r=this.o.get(t);if(void 0===r)return void this.o.set(t,{v:[{ut:e,p:h,M:s,k:i,m:!1}],u:!1,l:new nt(e,h,s)});if(r.l.has(e,h))throw Error("Event listener already exists");r.l.insert(e,h,s);const n={ut:e,p:h,M:s,k:i,m:!1};r.u&&(r.u=!1,r.v=r.v.slice());{const t=r.v,i=n.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(n);if(t[0].M>=i)return void t.unshift(n);{let s=0,e=t.length;for(;e>s;){const h=s+e>>>1;i>t[h].M?s=h+1:e=h}t.splice(s,0,n)}}}}class at extends ot{constructor(i,s,e,h){super(),this.layer=i,this.object=h,this.xInternal=new V("x"),this.yInternal=new V("y"),this.needsRecalculationInternal=!1,this.name=t.generateUUID(),this.object&&(this.object.matrixAutoUpdate=!1),this.layer.addUIElementInternal(this,h),this.layer.addVariableInternal(this,this.xInternal,it(Q.P7)),this.layer.addVariableInternal(this,this.yInternal,it(Q.P7)),this.xInternal.setValue(s),this.yInternal.setValue(e),this.layer.suggestVariableInternal(this,this.xInternal,s),this.layer.suggestVariableInternal(this,this.yInternal,e)}get x(){return this.xInternal.value()}get y(){return this.yInternal.value()}get zIndex(){return this.object?.position.z??0}get needsRecalculation(){return this.needsRecalculationInternal}set x(t){this.layer.suggestVariableInternal(this,this.xInternal,t)}set y(t){this.layer.suggestVariableInternal(this,this.yInternal,t)}set zIndex(t){this.object&&this.object.renderOrder!==t&&(this.object.position.z=t,this.object.renderOrder=t,this.layer.sortInternal(),this.object.updateMatrix())}destroy(){this.layer.removeVariableInternal(this,this.yInternal),this.layer.removeVariableInternal(this,this.xInternal),this.layer.removeUIElementInternal(this)}renderInternal(t,i){this.render(t,i)}applyTransformations(){this.needsRecalculationInternal&&(this.object&&this.object.updateMatrix(),this.needsRecalculationInternal=!1)}}const ct=new i,lt=new s,ut=new e,dt=new e,ft=new e,wt=new e,gt=new e,pt=new h,vt=.5;class mt{constructor(){this.x=0,this.y=0,this.anchorX=vt,this.anchorY=vt,this.scaleX=1,this.scaleY=1,this.rotation=0,this.needsRecalculation=!1}}class bt{constructor(t,i){this.dt=t,this.ft=i}get x(){return this.dt.x}get y(){return this.dt.y}get anchorX(){return this.dt.anchorX}get anchorY(){return this.dt.anchorY}get scaleX(){return this.dt.scaleX}get scaleY(){return this.dt.scaleY}get angle(){return t.radToDeg(this.dt.rotation)}get rotation(){return this.dt.rotation}set x(t){t!==this.dt.x&&(this.dt.x=t,this.dt.needsRecalculation=!0)}set y(t){t!==this.dt.y&&(this.dt.y=t,this.dt.needsRecalculation=!0)}set anchorX(t){t!==this.dt.anchorX&&(this.dt.anchorX=t,this.dt.needsRecalculation=!0)}set anchorY(t){t!==this.dt.anchorY&&(this.dt.anchorY=t,this.dt.needsRecalculation=!0)}set scaleX(t){t!==this.dt.scaleX&&(this.dt.scaleX=t,this.dt.needsRecalculation=!0)}set scaleY(t){t!==this.dt.scaleY&&(this.dt.scaleY=t,this.dt.needsRecalculation=!0)}set angle(i){const s=t.degToRad(i);s!==this.dt.rotation&&(this.dt.rotation=s,this.dt.needsRecalculation=!0)}set rotation(t){t!==this.dt.rotation&&(this.dt.rotation=t,this.dt.needsRecalculation=!0)}setAnchorByGlobalPosition(t,i){const s=(t-this.ft.x)/this.ft.width,e=(i-this.ft.y)/this.ft.height;s===this.dt.anchorX&&e===this.dt.anchorY||(this.dt.anchorX=s,this.dt.anchorY=e,this.dt.needsRecalculation=!0)}reset(){0===this.dt.x&&0===this.dt.y&&this.dt.anchorX===vt&&this.dt.anchorY===vt&&1===this.dt.scaleX&&1===this.dt.scaleY&&0===this.dt.rotation||(this.dt.x=0,this.dt.y=0,this.dt.anchorX=vt,this.dt.anchorY=vt,this.dt.scaleX=1,this.dt.scaleY=1,this.dt.rotation=0,this.dt.needsRecalculation=!0)}}var yt,Ct;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(yt||(yt={})),(t=>{t[t.NORMAL=0]="NORMAL",t[t.ADDITIVE=1]="ADDITIVE",t[t.SUBTRACTIVE=2]="SUBTRACTIVE",t[t.MULTIPLY=3]="MULTIPLY",t[t.SCREEN=4]="SCREEN"})(Ct||(Ct={}));class xt extends r{constructor(t){super({uniforms:{map:{value:t},opacity:{value:1},color:{value:new n(1,1,1)}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D map;\n uniform float opacity;\n uniform vec3 color;\n varying vec2 vUv;\n\n void main() {\n vec4 textureColor = texture2D(map, vUv);\n gl_FragColor = vec4(textureColor.rgb * color, textureColor.a * opacity);\n #include <colorspace_fragment>\n }\n ",transparent:!0,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}setTexture(t){this.uniforms.map.value=t,this.uniformsNeedUpdate=!0}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=!0}setBlending(t){switch(this.premultipliedAlpha=!1,this.blendEquation=o,this.blendSrc=a,this.blendDst=c,t){case Ct.ADDITIVE:this.blending=p;break;case Ct.SUBTRACTIVE:this.blending=g;break;case Ct.MULTIPLY:this.blending=w,this.premultipliedAlpha=!0;break;case Ct.SCREEN:this.blending=u,this.blendEquation=o,this.blendSrc=d,this.blendDst=f;break;default:this.blending=l}this.needsUpdate=!0}}const Et=new v(1,1).translate(.5,.5,0),_t=new m,It=new b(Et);_t.add(It);class kt{constructor(t=0,i=0){this.wt=t,this.gt=i,this.vt=new y(-1,1,1,-1,0,1),this.bt()}get paddingHorizontal(){return this.wt}get paddingVertical(){return this.gt}set paddingHorizontal(t){this.wt!==t&&(this.wt=t,this.bt())}set paddingVertical(t){this.gt!==t&&(this.gt=t,this.bt())}render(t,i){It.material=i,t.render(_t,this.vt)}bt(){this.vt.left=-this.wt,this.vt.right=1+this.wt,this.vt.bottom=-this.gt,this.vt.top=1+this.gt,this.vt.updateProjectionMatrix()}}class Mt{constructor(){this.passes=[],this.yt=new xt,this.Ct=new kt,this.xt=!1,this.Et=!1,this._t=0;const t={format:_,minFilter:E,magFilter:E,type:x,depthBuffer:!1,stencilBuffer:!1};this.It=new C(1,1,t),this.kt=new C(1,1,t),this.It.texture.generateMipmaps=!1,this.kt.texture.generateMipmaps=!1}get needsUpdate(){return this.xt&&this.Mt()||this.St()}get paddingHasChanged(){return this.Et}get padding(){return this._t}requestUpdate(){this.xt=!0}compose(t,i,s,e,h=!0){const r=this.Mt();if(!(this.xt&&r||this.St()))return r||(this.Et=0!==this._t,this._t=0),this.xt=!1,r?this.yt:e;const n=this.Ot();this.Et=this._t!==n,this._t=n;const o=i+2*n,a=s+2*n;this.It.setSize(o,a),this.kt.setSize(o,a),this.Tt(i,s,n),t.setClearColor(0,0),t.setRenderTarget(this.kt),t.clear(!0,!1,!1);const c=e.blending;h&&(e.blending=I),this.Ct.render(t,e),e.blending=c;const l={width:i,height:s,padding:n};for(const i of this.passes)(i.needsUpdate||i.isValuable)&&(this.Ft(),t.setRenderTarget(this.kt),t.clear(!0,!1,!1),i.render(t,this.It.texture,l));return this.xt=!1,this.yt.setTexture(this.kt.texture),this.yt}destroy(){this.It.dispose(),this.kt.dispose()}Mt(){return this.passes.some(t=>t.isValuable)}St(){return this.passes.some(t=>t.needsUpdate)}Ot(){return this.passes.reduce((t,i)=>Math.max(t,i.padding),0)}Tt(t,i,s){this.Ct.paddingHorizontal=s/t,this.Ct.paddingVertical=s/i}Ft(){const t=this.It;this.It=this.kt,this.kt=t}}class St{constructor(t){this.dt=t}get passes(){return this.dt.passes}}var Ot;(t=>{t.CLICK="click"})(Ot||(Ot={}));class Tt extends ot{constructor(i,s,e,h,r,n){super(),this.layer=i,this.object=s,this.xInternal=new V("x"),this.yInternal=new V("y"),this.widthInternal=new V("width"),this.heightInternal=new V("height"),this.needsRecalculationInternal=!1,this.name=t.generateUUID(),this.microInternal=new mt,this.composerInternal=new Mt,this.modeInternal=yt.VISIBLE,this.micro=new bt(this.microInternal,this),this.composer=new St(this.composerInternal),this.object.matrixAutoUpdate=!1,this.layer.addUIElementInternal(this,this.object),this.layer.addVariableInternal(this,this.xInternal,it(Q.P7)),this.layer.addVariableInternal(this,this.yInternal,it(Q.P7)),this.layer.addVariableInternal(this,this.widthInternal,it(Q.P5)),this.layer.addVariableInternal(this,this.heightInternal,it(Q.P5)),this.xInternal.setValue(e),this.yInternal.setValue(h),this.widthInternal.setValue(r),this.heightInternal.setValue(n),this.layer.suggestVariableInternal(this,this.xInternal,e),this.layer.suggestVariableInternal(this,this.yInternal,h),this.layer.suggestVariableInternal(this,this.widthInternal,r),this.layer.suggestVariableInternal(this,this.heightInternal,n)}get x(){return this.xInternal.value()}get y(){return this.yInternal.value()}get width(){return this.widthInternal.value()}get height(){return this.heightInternal.value()}get zIndex(){return this.object.position.z}get mode(){return this.modeInternal}get needsRecalculation(){return this.needsRecalculationInternal}set x(t){this.layer.suggestVariableInternal(this,this.xInternal,t)}set y(t){this.layer.suggestVariableInternal(this,this.yInternal,t)}set width(t){this.layer.suggestVariableInternal(this,this.widthInternal,t)}set height(t){this.layer.suggestVariableInternal(this,this.heightInternal,t)}set zIndex(t){this.object.renderOrder!==t&&(this.object.position.z=t,this.object.renderOrder=t,this.layer.sortInternal(),this.object.updateMatrix())}set mode(t){this.modeInternal=t,this.object.visible=t!==yt.HIDDEN}destroy(){this.composerInternal.destroy(),this.layer.removeVariableInternal(this,this.heightInternal),this.layer.removeVariableInternal(this,this.widthInternal),this.layer.removeVariableInternal(this,this.yInternal),this.layer.removeVariableInternal(this,this.xInternal),this.layer.removeUIElementInternal(this)}renderInternal(t,i){this.render(t,i)}clickInternal(t,i){return this.click(t,i)}applyTransformations(){(this.needsRecalculationInternal||this.microInternal.needsRecalculation||this.composerInternal.paddingHasChanged)&&(((t,i,s,e,h,r,n)=>{const o=this.x-n,a=this.y-n,c=this.width+2*n,l=this.height+2*n,u=o+c*i.anchorX,d=a+l*i.anchorY,f=ut.set(1,0,-u,0,1,-d,0,0,1),w=dt.set(i.scaleX,0,0,0,i.scaleY,0,0,0,1),g=ft.set(Math.cos(i.rotation),-Math.sin(i.rotation),0,Math.sin(i.rotation),Math.cos(i.rotation),0,0,0,1),p=wt.set(1,0,i.x+u,0,1,i.y+d,0,0,1),v=gt.multiplyMatrices(p,g).multiply(w).multiply(f),m=pt.set(o,a,1).applyMatrix3(v);t.position.x=m.x,t.position.y=m.y,t.rotation.z=i.rotation,t.scale.x=c*i.scaleX,t.scale.y=l*i.scaleY})(this.object,this.microInternal,0,0,0,0,this.composerInternal.padding),this.object.updateMatrix(),this.needsRecalculationInternal=!1,this.microInternal.needsRecalculation=!1)}click(t,i){return this.mode===yt.INTERACTIVE&&(this.applyTransformations(),s=this.x,e=this.y,h=this.width,r=this.height,ct.set(t,i),lt.min.set(s,e),lt.max.set(h,r).add(lt.min),!!lt.containsPoint(ct)&&(this.emit(Ot.CLICK,this),!0));var s,e,h,r}}const Ft=new n(0);var At,Vt,Bt;(t=>{t.ORIENTATION_CHANGED="orientation_changed",t.CLICK="click"})(At||(At={}));class zt extends ot{constructor(){super(...arguments),this.mode=yt.VISIBLE,this.xInternal=new V,this.yInternal=new V,this.widthInternal=new V,this.heightInternal=new V,this.scene=new m,this.camera=new y,this.solver=new R,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=X.PORTRAIT,this.needsRecalculation=!1}get orientation(){return this.orientationPrivate}get width(){return this.widthInternal.value()}get height(){return this.heightInternal.value()}destroy(){this.solver=void 0;for(const t of this.constraints.keys())t.destroy();for(const t of this.elements.keys())t.destroy()}addUIElementInternal(t,i,s){if(this.elements.has(t))throw Error("Element already added");if(this.elements.set(t,{object:i,variables:new Map,constraints:new Set}),i){const t=s??this.scene.children.length;i.position.z=t,i.renderOrder=t,this.scene.add(i),this.sortInternal()}}removeUIElementInternal(t){const i=this.elements.get(t);if(void 0===i)throw Error("Element not found");if(i.variables.size>0)throw Error("Variables should be removed before removing element");if(i.constraints.size>0)throw Error("Constraints should be removed before removing element");this.elements.delete(t),i.object&&this.scene.remove(i.object)}addUIConstraintInternal(t,i){if(this.constraints.has(t))throw Error("Constraint already added");for(const s of i){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(i.constraints.has(t))throw Error("Something went wrong");i.constraints.add(t)}this.constraints.set(t,{elements:i,variables:new Map,constraints:new Set})}removeUIConstraintInternal(t){const i=this.constraints.get(t);if(void 0===i)throw Error("Constraint not found");if(i.variables.size>0)throw Error("Variables should be removed before removing constraint");if(i.constraints.size>0)throw Error("Constraints should be removed before removing constraint");for(const s of i.elements){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(!i.constraints.has(t))throw Error("Something went wrong");i.constraints.delete(t)}this.constraints.delete(t)}addConstraintInternal(t,i){const s=this.constraints.get(t);if(void 0===s)throw Error("Before adding constraint you need to add it's owner");if(s.constraints.has(i))throw Error("Constraint already exists");s.constraints.add(i);try{this.solver?.addConstraint(i)}catch{this.At()}this.needsRecalculation=!0}removeConstraintInternal(t,i){const s=this.constraints.get(t);if(void 0===s)throw Error("Before removing constraint you need to add it's owner");if(!s.constraints.has(i))throw Error("Constraint not found");s.constraints.delete(i);try{this.solver?.removeConstraint(i)}catch{this.At()}this.needsRecalculation=!0}addVariableInternal(t,i,s){const e=t instanceof Tt||t instanceof at?this.elements.get(t):this.constraints.get(t);if(void 0===e)throw Error("Before adding variable you need to add it's owner");if(e.variables.has(i))throw Error("Variable already exists");e.variables.set(i,{strength:s,suggestedValue:i.value()});try{this.solver?.addEditVariable(i,s)}catch{this.At()}this.needsRecalculation=!0}removeVariableInternal(t,i){const s=t instanceof Tt||t instanceof at?this.elements.get(t):this.constraints.get(t);if(void 0===s)throw Error("Before removing variable you need to add it's owner");if(!s.variables.has(i))throw Error("Variable does not exist");s.variables.delete(i);try{this.solver?.removeEditVariable(i)}catch{this.At()}this.needsRecalculation=!0}suggestVariableInternal(t,i,s){const e=t instanceof Tt||t instanceof at?this.elements.get(t):this.constraints.get(t);if(void 0===e)throw Error("Before suggesting variable you need to add it's owner");const h=e.variables.get(i);if(!h)throw Error("Variable does not exist");if(h.suggestedValue!==s){h.suggestedValue=s;try{this.solver?.suggestValue(i,s)}catch{this.At()}this.needsRecalculation=!0}}sortInternal(){this.scene.children.sort((t,i)=>t.position.z-i.position.z);for(let t=0;this.scene.children.length>t;t++){const i=this.scene.children[t];i.position.z=t,i.renderOrder=t}this.camera.position.set(0,0,this.scene.children.length+1),this.camera.near=1,this.camera.far=this.scene.children.length+1+1,this.camera.updateProjectionMatrix(),this.camera.updateMatrix()}render(t,i){if(this.mode===yt.HIDDEN)return;const s=t.getRenderTarget(),e=t.getClearColor(Ft),h=t.getClearAlpha();if(this.needsRecalculation){this.needsRecalculation=!1,this.solver?.updateVariables();for(const t of this.elements.keys())t.needsRecalculationInternal=!0}for(const s of this.elements.keys())s.renderInternal(t,i);t.setRenderTarget(s),t.setClearColor(e),t.setClearAlpha(h),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.mode!==yt.INTERACTIVE)return;this.emit(At.CLICK,this,t,i);const s=[...this.elements.keys()].filter(t=>t instanceof Tt).filter(t=>t.mode===yt.INTERACTIVE).sort((t,i)=>t.zIndex-i.zIndex);for(const e of s)if(e.clickInternal(t,i))break}resizeInternal(t,i){this.applyCameraSize(t,i),this.rebuildLayerConstraints(t,i),this.updateOrientation(t,i),this.needsRecalculation=!0}applyCameraSize(t,i){this.camera.bottom=0,this.camera.left=0,this.camera.right=t,this.camera.top=i,this.camera.updateProjectionMatrix()}rebuildLayerConstraints(t,i){this.constraintX&&(this.solver?.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(this.solver?.removeConstraint(this.constraintY),this.constraintY=void 0),this.constraintW&&(this.solver?.removeConstraint(this.constraintW),this.constraintW=void 0),this.constraintH&&(this.solver?.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new $(new z(this.xInternal),P.Eq,0,D.required),this.constraintY=new $(new z(this.yInternal),P.Eq,0,D.required),this.constraintW=new $(new z(this.widthInternal),P.Eq,t,D.required),this.constraintH=new $(new z(this.heightInternal),P.Eq,i,D.required),this.solver?.addConstraint(this.constraintX),this.solver?.addConstraint(this.constraintY),this.solver?.addConstraint(this.constraintW),this.solver?.addConstraint(this.constraintH)}updateOrientation(t,i){const s=this.orientationPrivate;if(this.orientationPrivate=t>i?X.LANDSCAPE:X.PORTRAIT,s!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t.enableConstraintInternal(this.orientationPrivate);for(const t of this.constraints.keys())t.disableConstraintInternal(this.orientationPrivate);this.solver=new R;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,s]of i.variables.entries())this.solver.addEditVariable(t,s.strength),this.solver.suggestValue(t,s.suggestedValue);this.constraintX&&this.solver.addConstraint(this.constraintX),this.constraintY&&this.solver.addConstraint(this.constraintY),this.constraintW&&this.solver.addConstraint(this.constraintW),this.constraintH&&this.solver.addConstraint(this.constraintH);for(const t of this.constraints.values())for(const i of t.constraints.values())this.solver.addConstraint(i);this.emit(At.ORIENTATION_CHANGED,this,this.orientation)}}At(){try{this.solver=void 0,this.solver=new R;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,s]of i.variables.entries())this.solver.addEditVariable(t,s.strength),this.solver.suggestValue(t,s.suggestedValue);this.constraintX&&this.solver.addConstraint(this.constraintX),this.constraintY&&this.solver.addConstraint(this.constraintY),this.constraintW&&this.solver.addConstraint(this.constraintW),this.constraintH&&this.solver.addConstraint(this.constraintH);for(const t of this.constraints.values())for(const i of t.constraints.values())this.solver.addConstraint(i)}catch(t){throw t}}}function Dt(t,i){if((t instanceof zt?t:t.layer)!==i.layer)throw Error(`Elements must be on the same layer - element "${i.constructor.name}" cannot interact with elements from a different layer`)}function Pt(t,i,s){if(0>=t||0>=i)throw Error(s??`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)}class $t extends G{constructor(t,i,s={}){Dt(t,i),super(i.layer,new Set(t instanceof Tt||t instanceof at?[t,i]:[i])),this.Vt=t,this.Bt=i,this.ct={anchorOne:s.anchorOne??.5,anchorTwo:s.anchorTwo??.5,distance:s.distance??0,power:tt(s.power),rule:et(s.rule),orientation:q(s.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){const t=this.Vt instanceof Tt||this.Vt instanceof zt?new z(this.Vt.xInternal).plus(new z(this.Vt.widthInternal).multiply(this.ct.anchorOne)):new z(this.Vt.xInternal),i=this.Bt instanceof Tt?new z(this.Bt.xInternal).plus(new z(this.Bt.widthInternal).multiply(this.ct.anchorTwo)):new z(this.Bt.xInternal);this.lt=new $(i.minus(t),ht(this.ct.rule),this.ct.distance,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class Ut extends G{constructor(t,i,s={}){Dt(t,i),super(i.layer,new Set(t instanceof Tt?[t,i]:[i])),this.Vt=t,this.Bt=i,this.ct={proportion:s.proportion??1,power:tt(s.power),rule:et(s.rule),orientation:q(s.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){const t=new z(this.Vt.widthInternal).multiply(this.ct.proportion),i=new z(this.Bt.widthInternal);this.lt=new $(t.minus(i),ht(this.ct.rule),0,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class Rt extends G{constructor(t,i,s={}){Dt(t,i),super(i.layer,new Set(t instanceof Tt||t instanceof at?[t,i]:[i])),this.Vt=t,this.Bt=i,this.ct={anchorOne:s.anchorOne??.5,anchorTwo:s.anchorTwo??.5,distance:s.distance??0,power:tt(s.power),rule:et(s.rule),orientation:q(s.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){const t=this.Vt instanceof Tt||this.Vt instanceof zt?new z(this.Vt.yInternal).plus(new z(this.Vt.heightInternal).multiply(this.ct.anchorOne)):new z(this.Vt.yInternal),i=this.Bt instanceof Tt?new z(this.Bt.yInternal).plus(new z(this.Bt.heightInternal).multiply(this.ct.anchorTwo)):new z(this.Bt.yInternal);this.lt=new $(i.minus(t),ht(this.ct.rule),this.ct.distance,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class Lt extends G{constructor(t,i,s={}){Dt(t,i),super(i.layer,new Set(t instanceof Tt?[t,i]:[i])),this.Vt=t,this.Bt=i,this.ct={proportion:s.proportion??1,power:tt(s.power),rule:et(s.rule),orientation:q(s.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){const t=new z(this.Vt.heightInternal).multiply(this.ct.proportion),i=new z(this.Bt.heightInternal);this.lt=new $(t.minus(i),ht(this.ct.rule),0,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class Ht extends G{constructor(t,i={}){super(t.layer,new Set([t])),this.ot=t,this.ct={width:i.width??t.width,power:tt(i.power),rule:et(i.rule),orientation:q(i.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){this.lt=new $(new z(this.ot.widthInternal),ht(this.ct.rule),this.ct.width,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class jt{static size(t,i={}){return{x:new Ht(t,{width:i.size?.h,power:i.power?.h,rule:i.rule?.h,orientation:i.orientation?.h}),y:new rt(t,{height:i.size?.v,power:i.power?.v,rule:i.rule?.v,orientation:i.orientation?.v})}}static distance(t,i,s={}){return{x:new $t(t,i,{anchorOne:s.anchorOne?.h,anchorTwo:s.anchorTwo?.h,distance:s.distance?.h,power:s.power?.h,rule:s.rule?.h,orientation:s.orientation?.h}),y:new Rt(t,i,{anchorOne:s.anchorOne?.v,anchorTwo:s.anchorTwo?.v,distance:s.distance?.v,power:s.power?.v,rule:s.rule?.v,orientation:s.orientation?.v})}}static proportion(t,i,s={}){return{x:new Ut(t,i,{proportion:s.proportion?.h,power:s.power?.h,rule:s.rule?.h,orientation:s.orientation?.h}),y:new Lt(t,i,{proportion:s.proportion?.v,power:s.power?.v,rule:s.rule?.v,orientation:s.orientation?.v})}}}(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(Vt||(Vt={}));class Nt{static build(t,i,s,e={}){const h=e.direction??Vt.FROM_LEFT_TOP,r=[],n=[];r.push(new $t(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:e.power,orientation:e.orientation}),new $t(t,s,{anchorOne:1,anchorTwo:1,distance:0,power:e.power,orientation:e.orientation}));const o=h===Vt.FROM_LEFT_TOP?1:0,a=h===Vt.FROM_LEFT_TOP?0:1;return n.push(new Rt(t,i,{anchorOne:o,anchorTwo:o,distance:0,power:e.power,orientation:e.orientation}),new Rt(t,s,{anchorOne:a,anchorTwo:a,distance:0,power:e.power,orientation:e.orientation})),{horizontalDistances:r,verticalDistances:n}}}class Wt{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:$t,proportionConstraint:Ut,centerDistanceConstraint:Rt})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:Rt,proportionConstraint:Lt,centerDistanceConstraint:$t})}static buildStack(t,i,s){const e=[],h=[],r=[];for(let n=0;t.length-1>n;n++){const o=t[n],a=t[n+1];e.push(new s.distanceConstraint(o,a,{anchorOne:1,anchorTwo:0,distance:i.distance,power:i.power,orientation:i.orientation})),!1!==i.keepProportions&&h.push(new s.proportionConstraint(o,a,{power:i.power,orientation:i.orientation})),!1!==i.keepAlignment&&r.push(new s.centerDistanceConstraint(o,a,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:e,proportionConstraints:h,alignmentConstraints:r}}}class Xt extends G{constructor(t,i={}){super(t.layer,new Set([t])),this.ot=t,this.ct={aspect:i.aspect??this.ot.width/this.ot.height,power:tt(i.power),rule:et(i.rule),orientation:q(i.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){const t=new z(this.ot.widthInternal).plus(new z(this.ot.heightInternal).multiply(-this.ct.aspect));this.lt=new $(t,ht(this.ct.rule),0,it(this.ct.power)),this.layer.addConstraintInternal(this,this.lt)}destroyConstraints(){this.lt&&(this.layer.removeConstraintInternal(this,this.lt),this.lt=void 0)}}class Yt extends G{constructor(t,i,s={}){Dt(t,i),super(i.layer,new Set(t instanceof Tt?[t,i]:[i])),this.Vt=t,this.Bt=i,this.ct={isStrict:s.isStrict??!0,horizontalAnchor:s.horizontalAnchor??.5,verticalAnchor:s.verticalAnchor??.5,orientation:q(s.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){this.zt=new $(new z(this.Vt.xInternal).plus(new z(this.Vt.widthInternal).multiply(this.ct.horizontalAnchor)),P.Eq,new z(this.Bt.xInternal).plus(new z(this.Bt.widthInternal).multiply(this.ct.horizontalAnchor))),this.Dt=new $(new z(this.Vt.yInternal).plus(new z(this.Vt.heightInternal).multiply(this.ct.verticalAnchor)),P.Eq,new z(this.Bt.yInternal).plus(new z(this.Bt.heightInternal).multiply(this.ct.verticalAnchor))),this.Pt=new $(new z(this.Vt.widthInternal),P.Eq,new z(this.Bt.widthInternal)),this.$t=new $(new z(this.Vt.heightInternal),P.Eq,new z(this.Bt.heightInternal)),this.layer.addConstraintInternal(this,this.zt),this.layer.addConstraintInternal(this,this.Dt),this.layer.addConstraintInternal(this,this.Pt),this.layer.addConstraintInternal(this,this.$t),this.ct.isStrict||(this.Ut=new $(new z(this.Vt.heightInternal),P.Eq,new z(this.Bt.heightInternal)),this.layer.addConstraintInternal(this,this.Ut))}destroyConstraints(){this.zt&&(this.layer.removeConstraintInternal(this,this.zt),this.zt=void 0),this.Dt&&(this.layer.removeConstraintInternal(this,this.Dt),this.Dt=void 0),this.Pt&&(this.layer.removeConstraintInternal(this,this.Pt),this.Pt=void 0),this.$t&&(this.layer.removeConstraintInternal(this,this.$t),this.$t=void 0),this.Ut&&(this.layer.removeConstraintInternal(this,this.Ut),this.Ut=void 0)}}class qt extends G{constructor(t,i,s={}){super(i.layer,new Set(t instanceof Tt?[t,i]:[i])),this.Vt=t,this.Bt=i,Dt(t,i),this.ct={isStrict:s.isStrict??!0,horizontalAnchor:s.horizontalAnchor??.5,verticalAnchor:s.verticalAnchor??.5,orientation:q(s.orientation)},this.ct.orientation!==X.ALWAYS&&this.ct.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}disableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t!==this.ct.orientation&&this.destroyConstraints()}enableConstraintInternal(t){this.ct.orientation!==X.ALWAYS&&t===this.ct.orientation&&this.buildConstraints()}buildConstraints(){this.zt=new $(new z(this.Vt.xInternal).plus(new z(this.Vt.widthInternal).multiply(this.ct.horizontalAnchor)),P.Eq,new z(this.Bt.xInternal).plus(new z(this.Bt.widthInternal).multiply(this.ct.horizontalAnchor))),this.Dt=new $(new z(this.Vt.yInternal).plus(new z(this.Vt.heightInternal).multiply(this.ct.verticalAnchor)),P.Eq,new z(this.Bt.yInternal).plus(new z(this.Bt.heightInternal).multiply(this.ct.verticalAnchor))),this.Pt=new $(new z(this.Vt.widthInternal),P.Ge,new z(this.Bt.widthInternal)),this.$t=new $(new z(this.Vt.heightInternal),P.Ge,new z(this.Bt.heightInternal)),this.layer.addConstraintInternal(this,this.zt),this.layer.addConstraintInternal(this,this.Dt),this.layer.addConstraintInternal(this,this.Pt),this.layer.addConstraintInternal(this,this.$t),this.ct.isStrict&&(this.Ut=new $(new z(this.Vt.heightInternal),P.Eq,new z(this.Bt.heightInternal),D.strong),this.layer.addConstraintInternal(this,this.Ut))}destroyConstraints(){this.zt&&(this.layer.removeConstraintInternal(this,this.zt),this.zt=void 0),this.Dt&&(this.layer.removeConstraintInternal(this,this.Dt),this.Dt=void 0),this.Pt&&(this.layer.removeConstraintInternal(this,this.Pt),this.Pt=void 0),this.$t&&(this.layer.removeConstraintInternal(this,this.$t),this.$t=void 0),this.Ut&&(this.layer.removeConstraintInternal(this,this.Ut),this.Ut=void 0)}}class Gt extends Tt{constructor(t,i=100,s=100){super(t,new k,0,0,i,s),this.applyTransformations()}render(){this.applyTransformations()}}class Jt extends Tt{constructor(t,i){const s=i.image?.width,e=i.image?.height;Pt(s,e,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${s}) or height (${e}). Image dimensions must be non-zero positive numbers.`);const h=new xt(i);super(t,new b(Et,h),0,0,s,e),this.Rt=Ct.NORMAL,this.Lt=h,this.Ht=i,this.applyTransformations()}get texture(){return this.Ht}get color(){return this.Lt.getColor()}get opacity(){return this.Lt.getOpacity()}get blending(){return this.Rt}set color(t){this.Lt.setColor(t),this.composerInternal.requestUpdate()}set opacity(t){this.Lt.setOpacity(t),this.composerInternal.requestUpdate()}set blending(t){this.Rt=t,this.Lt.setBlending(t),this.composerInternal.requestUpdate()}destroy(){this.Lt.dispose(),super.destroy()}render(t){this.object.material=this.composerInternal.compose(t,this.Ht.image.width,this.Ht.image.height,this.Lt),this.applyTransformations()}}class Qt extends r{constructor(t,i){super({uniforms:M.merge([{background:{value:i},foreground:{value:t},progress:{value:1},backgroundColor:{value:new n(1,1,1)},foregroundColor:{value:new n(1,1,1)},color:{value:new n(1,1,1)},backgroundOpacity:{value:1},foregroundOpacity:{value:1},opacity:{value:1},angle:{value:0},direction:{value:1}}]),vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D background;\n uniform sampler2D foreground;\n uniform float progress;\n uniform vec3 backgroundColor;\n uniform vec3 foregroundColor;\n uniform vec3 color;\n uniform float backgroundOpacity;\n uniform float foregroundOpacity;\n uniform float opacity;\n uniform float angle;\n uniform float direction;\n varying vec2 vUv;\n\n void 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 = smoothstep(threshold - 0.01, threshold + 0.01, progress);\n\n gl_FragColor = mix(backgroundColor, foregroundColor, progressMask);\n #include <colorspace_fragment>\n }\n ",transparent:!0,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}getBackgroundColor(){return this.uniforms.color.value.getHex()}getForegroundColor(){return this.uniforms.color.value.getHex()}getColor(){return this.uniforms.color.value.getHex()}getBackgroundOpacity(){return this.uniforms.backgroundOpacity.value}getForegroundOpacity(){return this.uniforms.foregroundOpacity.value}getOpacity(){return this.uniforms.opacity.value}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}setBackgroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setForegroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setBackgroundOpacity(t){this.uniforms.backgroundOpacity.value=t,this.uniformsNeedUpdate=!0}setForegroundOpacity(t){this.uniforms.foregroundOpacity.value=t,this.uniformsNeedUpdate=!0}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=!0}setAngle(t){this.uniforms.angle.value=t,this.uniformsNeedUpdate=!0}setIsForwardDirection(t){this.uniforms.direction.value=t?1:-1,this.uniformsNeedUpdate=!0}}class Kt extends Tt{constructor(i,s,e={}){const h=s.image?.width,r=s.image?.height;Pt(h,r,`Invalid image dimensions - texture "${s.name||"unnamed"}" has invalid width (${h}) or height (${r}). Image dimensions must be non-zero positive numbers.`);const n=e.textureBackground?.image?.width,o=e.textureBackground?.image?.height;e.textureBackground&&Pt(n,o,`Invalid image dimensions - texture "${e.textureBackground.name||"unnamed"}" has invalid width (${n}) or height (${o}). Image dimensions must be non-zero positive numbers.`);const a=new Qt(s,e.textureBackground),c=new b(Et,a);e.progress&&a.setProgress(e.progress),e.isForegroundDirection&&a.setIsForwardDirection(e.isForegroundDirection),e.angle&&a.setAngle(t.degToRad(e.angle)),e.color&&a.setColor(e.color),e.opacity&&a.setOpacity(e.opacity),e.backgroundColor&&a.setBackgroundColor(e.backgroundColor),e.foregroundColor&&a.setForegroundColor(e.foregroundColor),e.backgroundOpacity&&a.setBackgroundOpacity(e.backgroundOpacity),e.foregroundOpacity&&a.setForegroundOpacity(e.foregroundOpacity);const l=n??h,u=r??o;super(i,c,0,0,l,u),this.Lt=a,this.jt=l,this.Nt=u,this.applyTransformations()}get progress(){return this.Lt.getProgress()}get backgroundTexture(){return this.Lt.getBackgroundTexture()}get foregroundTexture(){return this.Lt.getForegroundTexture()}get backgroundColor(){return this.Lt.getBackgroundColor()}get foregroundColor(){return this.Lt.getForegroundColor()}get color(){return this.Lt.getColor()}get backgroundOpacity(){return this.Lt.getBackgroundOpacity()}get foregroundOpacity(){return this.Lt.getForegroundOpacity()}get opacity(){return this.Lt.getOpacity()}get angle(){return t.radToDeg(this.Lt.getAngle())}get isForwardDirection(){return this.Lt.getIsForwardDirection()}set progress(t){this.Lt.setProgress(t),this.composerInternal.requestUpdate()}set backgroundColor(t){this.Lt.setBackgroundColor(t),this.composerInternal.requestUpdate()}set foregroundColor(t){this.Lt.setForegroundColor(t),this.composerInternal.requestUpdate()}set color(t){this.Lt.setColor(t),this.composerInternal.requestUpdate()}set backgroundOpacity(t){this.Lt.setBackgroundOpacity(t),this.composerInternal.requestUpdate()}set foregroundOpacity(t){this.Lt.setForegroundOpacity(t),this.composerInternal.requestUpdate()}set opacity(t){this.Lt.setOpacity(t),this.composerInternal.requestUpdate()}set angle(i){this.Lt.setAngle(t.degToRad(i)),this.composerInternal.requestUpdate()}set isForwardDirection(t){this.Lt.setIsForwardDirection(t),this.composerInternal.requestUpdate()}destroy(){this.Lt.dispose(),super.destroy()}render(t){this.object.material=this.composerInternal.compose(t,this.jt,this.Nt,this.Lt),this.applyTransformations()}}(t=>{t.ALWAYS="always",t.PROPERTY_CHANGED="property_changed",t.MANUAL="manual"})(Bt||(Bt={}));const Zt=Bt.PROPERTY_CHANGED;class ti extends Tt{constructor(t,i={}){const s=i.resolutionFactor??.5;if(.1>s||s>8)throw Error(`Invalid resolution factor: ${s}. Must be between 0.1 and 8.`);const e=i.width??512,h=i.height??512;Pt(e,h,`Invalid width or height: ${e}x${h}. Must be positive.`);const r=new C(e*s,h*s,{format:_,minFilter:E,magFilter:E,type:x,depthBuffer:i.useDepth??!0,stencilBuffer:!1}),n=new xt(r.texture);super(t,new b(Et,n),0,0,e,h),this.Wt=!1,this.Xt=i.scene??new m,this.Yt=i.camera??new S(75,e/h,.1,100),this.qt=s,this.Gt=i.updateBehavior??Zt,i.renderedByDefault&&(this.Wt=!0),this.Jt=i.clearColor??0,this.Qt=i.clearAlpha??0,this.Kt=r,this.Lt=n,this.applyTransformations()}get needsRender(){return this.Wt}get color(){return this.Lt.getColor()}get opacity(){return this.Lt.getOpacity()}get scene(){return this.Xt}get camera(){return this.Yt}get clearColor(){return this.Jt}get clearAlpha(){return this.Qt}get resolutionFactor(){return this.qt}set color(t){this.Lt.setColor(t),this.composerInternal.requestUpdate()}set opacity(t){this.Lt.setOpacity(t),this.composerInternal.requestUpdate()}set scene(t){this.Xt!==t&&(this.Xt=t,this.Gt===Bt.PROPERTY_CHANGED&&this.requestRender())}set camera(t){this.Yt!==t&&(this.Yt=t,this.Gt===Bt.PROPERTY_CHANGED&&this.requestRender())}set clearColor(t){this.Jt!==t&&(this.Jt=t,this.Gt===Bt.PROPERTY_CHANGED&&this.requestRender())}set clearAlpha(t){this.Qt!==t&&(this.Qt=t,this.Gt===Bt.PROPERTY_CHANGED&&this.requestRender())}set resolutionFactor(t){this.qt!==t&&(this.qt=t,this.Kt.setSize(this.width*this.qt,this.height*this.qt),this.Gt===Bt.PROPERTY_CHANGED&&this.requestRender())}destroy(){this.Lt.dispose(),this.Kt.dispose(),super.destroy()}requestRender(){this.Wt=!0,this.composerInternal.requestUpdate()}render(t){(this.Wt||this.Gt===Bt.ALWAYS)&&(this.Wt=!1,this.Kt.setSize(this.width*this.qt,this.height*this.qt),t.setClearColor(this.Jt,this.clearAlpha),t.setRenderTarget(this.Kt),t.clear(!0,!0,!1),t.render(this.Xt,this.Yt)),this.object.material=this.composerInternal.compose(t,this.width*this.qt,this.height*this.qt,this.Lt),this.applyTransformations()}}function ii(t,i){const s=Math.max(t?.fontSize??i?.fontSize??16,1),e=t?.lineHeight??i?.lineHeight??1.2*s,h=Math.max(t?.shadowBlur??i?.shadowBlur??0,0),r=Math.max(t?.strokeWidth??i?.strokeWidth??0,0);return{color:t?.color??i?.color??"#000000",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize:s,fontStyle:t?.fontStyle??i?.fontStyle??"normal",fontWeight:t?.fontWeight??i?.fontWeight??"normal",lineHeight:e,enableShadow:t?.enableShadow??i?.enableShadow??!1,shadowOffsetX:t?.shadowOffsetX??i?.shadowOffsetX??0,shadowOffsetY:t?.shadowOffsetY??i?.shadowOffsetY??0,shadowBlur:h,shadowColor:t?.shadowColor??i?.shadowColor??"transparent",enableStroke:t?.enableStroke??i?.enableStroke??!1,strokeColor:t?.strokeColor??i?.strokeColor??"transparent",strokeWidth:r}}function si(t){return t.match(/\S+|\s|\n/g)??[]}function ei(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),h=e.width,r=Math.ceil(e.actualBoundingBoxAscent+e.actualBoundingBoxDescent);return{width:Math.ceil(h),height:r,baseline:e.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function hi(t,i,s,e,h){h.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px ${e.fontFamily}`,e.enableShadow&&(h.shadowOffsetX=e.shadowOffsetX,h.shadowOffsetY=e.shadowOffsetY,h.shadowBlur=e.shadowBlur,h.shadowColor=e.shadowColor),e.enableStroke&&(h.strokeStyle=e.strokeColor,h.lineWidth=e.strokeWidth,h.strokeText(s,t,i)),h.fillStyle=e.color,h.fillText(s,t,i)}class ri extends Tt{constructor(t,i,s={}){const e=document.createElement("canvas"),h=e.getContext("2d");if(!h)throw Error("Failed to create canvas context");const r=[],n=Array.isArray(i)?i:[i];for(const t of n){const i="string"==typeof t,e=i?t:t.text,n=ii(i?void 0:t.style,s.defaultStyle);for(const t of si(e)){const i=ei(h,t,n);r.push({text:t,style:n,metrics:i})}}const o=((t,i)=>{const s=[];let e=[],h=0,r=0,n=0,o=0;for(const a of i)"\n"!==a.text?h+a.metrics.width>t&&0!==e.length?(s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),e=[a],h=a.metrics.width,r=a.metrics.height,n=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),h+=a.metrics.width,r=Math.max(r,a.metrics.height),n=Math.max(n,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),e=[],h=0,r=0,n=0,o=0);return e.length>0&&s.push({chunks:e,width:h,height:r,baseline:n,lineHeight:o}),s})(s.maxWidth??1024,r),a=(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}})(o),c=(t=>"number"==typeof t?{left:t,right:t,top:t,bottom:t}:{left:Math.max(t?.left??0,0),right:Math.max(t?.right??0,0),top:Math.max(t?.top??0,0),bottom:Math.max(t?.bottom??0,0)})(s.padding);e.width=a.width+c.left+c.right,e.height=a.height+c.top+c.bottom;const l=new O(e),u=new xt(l);super(t,new b(Et,u),0,0,a.width,a.height),this.Zt=0,this.Lt=u,this.ti=l,this.ii=e,this.si=h,this.ei=a,this.hi=c,((t,i,s,e)=>{let h=this.hi.top;for(let t=0;s.length>t;t++){const r=s[t];let n=i;h+=0===t?r.height:r.lineHeight;for(const t of r.chunks)hi(n,h,t.text,t.style,e),n+=t.metrics.width}})(0,this.hi.left,o,this.si),this.ti.needsUpdate=!0,this.applyTransformations()}get color(){return this.Lt.getColor()}get opacity(){return this.Lt.getOpacity()}set color(t){this.Lt.setColor(t),this.composerInternal.requestUpdate()}set opacity(t){this.Lt.setOpacity(t),this.composerInternal.requestUpdate()}destroy(){this.Lt.dispose(),this.ti.dispose(),this.ii.remove(),super.destroy()}applyTransformations(){super.applyTransformations();const t=this.width/this.height;this.Zt!==t&&(this.Zt=t,this.height=this.width/((this.ei.width+this.hi.left+this.hi.right)/(this.ei.height+this.hi.top+this.hi.bottom)))}render(t){this.object.material=this.composerInternal.compose(t,this.ti.image.width,this.ti.image.height,this.Lt),this.applyTransformations()}}class ni extends zt{constructor(){super(),this.ri=1920,this.ni=()=>{const t=this.oi();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.ai=t=>{if(this.mode!==yt.INTERACTIVE)return;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,h=this.oi();this.clickInternal(s*h,e*h)},window.addEventListener("resize",this.ni),window.addEventListener("pointerdown",this.ai),this.ni()}get tergetScreenHeight(){return this.ri}set tergetScreenHeight(t){this.ri=t,this.resizeInternal(window.innerWidth,window.innerHeight)}destroy(){window.removeEventListener("resize",this.ni),window.removeEventListener("pointerdown",this.ai),super.destroy()}render(t,i){t.clear(!1,!0,!0),super.render(t,i)}oi(){return(this.tergetScreenHeight??window.innerHeight)/window.innerHeight}}function oi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}class ai{}export{at as UIAnchor,Xt as UIAspectConstraint,Ct as UIBlending,G as UIConstraint,jt as UIConstraint2DBuilder,Nt as UIConstraintContainerBuilder,Vt as UIConstraintContainerDirection,Q as UIConstraintPower,K as UIConstraintRule,Wt as UIConstraintStackBuilder,Yt as UICoverConstraint,Gt as UIDummy,Tt as UIElement,Ot as UIElementEvent,qt as UIFitConstraint,ni as UIFullScreenLayer,kt as UIFullScreenQuad,rt as UIHeightConstraint,$t as UIHorizontalDistanceConstraint,Ut as UIHorizontalProportionConstraint,Jt as UIImage,zt as UILayer,At as UILayerEvent,yt as UIMode,X as UIOrientation,ai as UIPass,Kt as UIProgress,ti as UIScene,Bt as UISceneUpdateMode,ri as UIText,Rt as UIVerticalDistanceConstraint,Lt as UIVerticalProportionConstraint,Ht as UIWidthConstraint,it as convertPowerToStrength,ht as convertRuleToOperator,Z as isUIConstraintPower,st as isUIConstraintRule,Y as isUIOrientation,oi as isUITextSpan,q as resolveOrientation,tt as resolvePower,et as resolveRule};
1
+ import{Scene as t,OrthographicCamera as i,MathUtils as s,ShaderMaterial as e,Color as r,PlaneGeometry as n,Mesh as h,UniformsUtils as o,WebGLRenderTarget as a,UnsignedByteType as u,LinearFilter as l,RGBAFormat as c,PerspectiveCamera as d,CanvasTexture as f}from"three";class g{constructor(t=0,i){this.constant=t,this._=i?new Map(i):new Map}static plus(t,i){const s=new g(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 g(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 g(this.constant,Array.from(this._.entries()))}prepareTermsInternal(){return Array.from(this._.entries())}}class p{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 w{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 n=r.length;if(r[0].C===i&&r[0].p===s)return 1===n?this.o.delete(t):r.shift(),this;const h=n-1;if(r[h].C===i&&r[h].p===s)return r.pop(),this;if(10>n||r[0].M===r[h].M)for(let t=1;h>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 n=0,h=r.length-1;for(;h>=n;){const i=n+h>>>1;t>r[i].M?n=i+1:h=i-1}const o=n;for(h=r.length-1;h>=n;){const i=n+h>>>1;r[i].M>t?h=i-1:n=i+1}const a=h;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 n=this.o.get(t);if(void 0===n)return!0;n.v===e&&(n.u=!1);const h=n.v;if(r){let i=0;for(let t=0;h.length>t;t++){const s=h[t];s.m?n.l.remove(s.C,s.p):h[i++]=s}0===i?this.o.delete(t):h.length=i}return!0}h(t,i,s,e,r){let n=this.o.get(t);if(void 0===n)return void this.o.set(t,{v:[{C:e,p:r,M:s,k:i,m:!1}],u:!1,l:new p(e,r,s)});if(n.l.has(e,r))throw Error("Event listener already exists");n.l.insert(e,r,s);const h={C:e,p:r,M:s,k:i,m:!1};n.u&&(n.u=!1,n.v=n.v.slice());{const t=n.v,i=h.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(h);if(t[0].M>=i)return void t.unshift(h);{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,h)}}}}var v,m;function y(t){return t??m.ALWAYS}function b(){return new x}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(v||(v={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(m||(m={}));class x{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 E(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 E(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 x;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 E{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new E(this.first,this.second)}}class _{constructor(t=""){this.I=t}id(){return this.S}name(){return this.I}setName(t){this.I=t}context(){return this.U}setContext(t){this.U=t}value(){return this.A}setValue(t){this.A=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.I,value:this.A}}toString(){return this.U+"["+this.I+":"+this.A+"]"}I;A=0;U=null;S=C++}let C=0;class I{constructor(){let t=(t=>{let i=0,s=()=>0,e=b();for(let r=0,n=t.length;n>r;++r){let n=t[r];if("number"==typeof n)i+=n;else if(n instanceof _)e.setDefault(n,s).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);e.setDefault(r.first,s).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 _)e.setDefault(r,s).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);e.setDefault(r.first,s).second+=r.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.T=t.terms,this.V=t.constant}terms(){return this.T}constant(){return this.V}value(){let t=this.V;for(let i=0,s=this.T.size();s>i;i++){let s=this.T.itemAt(i);t+=s.first.value()*s.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.T.size()}toString(){let t=this.T.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.V||(t+=" + "),t+=this.V,t}T;V}class k{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=k.create(1e3,1e3,1e3);static strong=k.create(1,0,0);static medium=k.create(0,1,0);static weak=k.create(0,0,1);static clip(t){return Math.max(0,Math.min(k.required,t))}}var M;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(M||(M={}));class S{constructor(t,i,s,e=k.required){this.F=i,this.O=k.clip(e),this.P=void 0===s&&t instanceof I?t:t.minus(s)}id(){return this.S}expression(){return this.P}op(){return this.F}strength(){return this.O}toString(){return this.P+" "+["<=",">=","="][this.F]+" 0 ("+this.O+")"}P;F;O;S=U++}let U=0;class A{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=k.required){let r=new S(t,i,s,e);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.H.find(t))throw Error("duplicate constraint");let i=this.B(t),s=i.row,e=i.tag,r=this.L(s,e);if(r.type()===V.Invalid&&s.allDummies()){if(!T(s.constant()))throw Error("unsatisfiable constraint");r=e.marker}if(r.type()===V.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.R(r,s),this.$.insert(r,s);this.H.insert(t,e),this.j(this.N)}removeConstraint(t){let i=this.H.erase(t);if(void 0===i)throw Error("unknown constraint");this.W(t,i.second);let s=i.second.marker,e=this.$.erase(s);if(void 0===e){let t=this.q(s);if(t.type()===V.Invalid)throw Error("failed to find leaving row");e=this.$.erase(t),e.second.solveForEx(t,s),this.R(s,e.second)}this.j(this.N)}hasConstraint(t){return this.H.contains(t)}getConstraints(){return this.H.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.X.find(t))throw Error("duplicate edit variable");if((i=k.clip(i))===k.required)throw Error("bad required strength");let s=new I(t),e=new S(s,M.Eq,void 0,i);this.addConstraint(e);let r=this.H.find(e).second;this.X.insert(t,{tag:r,constraint:e,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 s=this.X.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.$,r=s.second,n=i-r.constant;r.constant=i;let h=r.tag.marker,o=e.find(h);if(void 0!==o)return 0>o.second.add(-n)&&this.Y.push(h),void this.G();let a=r.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(n)&&this.Y.push(a),void this.G();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,r=s.coefficientFor(h);0!==r&&0>s.add(n*r)&&i.first.type()!==V.External&&this.Y.push(i.first)}this.G()}updateVariables(){let t=this.Z,i=this.$;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(V.External)).second}B(t){let i=t.expression(),s=new P(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!T(i.second)){let t=this.J(i.first),e=this.$.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let r=this.N,n=t.strength(),h={marker:O,other:O};switch(t.op()){case M.Le:case M.Ge:{let i=t.op()===M.Le?1:-1,e=this.K(V.Slack);if(h.marker=e,s.insertSymbol(e,i),k.required>n){let t=this.K(V.Error);h.other=t,s.insertSymbol(t,-i),r.insertSymbol(t,n)}break}case M.Eq:if(k.required>n){let t=this.K(V.Error),i=this.K(V.Error);h.marker=t,h.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),r.insertSymbol(t,n),r.insertSymbol(i,n)}else{let t=this.K(V.Dummy);h.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:h}}L(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===V.External)return i.first}let e=i.marker.type();return e!==V.Slack&&e!==V.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==V.Slack&&e!==V.Error||t.coefficientFor(i.other)>=0?O:i.other):i.marker}D(t){let i=this.K(V.Slack);this.$.insert(i,t.copy()),this.tt=t.copy(),this.j(this.tt);let s=T(this.tt.constant());this.tt=null;let e=this.$.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let r=this.it(t);if(r.type()===V.Invalid)return!1;t.solveForEx(i,r),this.R(r,t),this.$.insert(r,t)}let r=this.$;for(let t=0,s=r.size();s>t;++t)r.itemAt(t).second.removeSymbol(i);return this.N.removeSymbol(i),s}R(t,i){let s=this.$;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()!==V.External&&this.Y.push(r.first)}this.N.substitute(t,i),this.tt&&this.tt.substitute(t,i)}j(t){let i=0;for(;this.maxIterations>i;){let s=this.st(t);if(s.type()===V.Invalid)return;let e=this.et(s);if(e.type()===V.Invalid)throw Error("the objective is unbounded");let r=this.$.erase(e).second;r.solveForEx(e,s),this.R(s,r),this.$.insert(s,r),i++}throw Error("solver iterations exceeded")}G(){let t=this.$,i=this.Y;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.rt(e.second);if(i.type()===V.Invalid)throw Error("dual optimize failed");let r=e.second;t.erase(s),r.solveForEx(s,i),this.R(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()!==V.Dummy)return e}return O}rt(t){let i=Number.MAX_VALUE,s=O,e=t.cells();for(let t=0,r=e.size();r>t;++t){let r=e.itemAt(t),n=r.first,h=r.second;if(h>0&&n.type()!==V.Dummy){let t=this.N.coefficientFor(n)/h;i>t&&(i=t,s=n)}}return s}et(t){let i=Number.MAX_VALUE,s=O,e=this.$;for(let r=0,n=e.size();n>r;++r){let n=e.itemAt(r),h=n.first;if(h.type()!==V.External){let e=n.second,r=e.coefficientFor(t);if(0>r){let t=-e.constant()/r;i>t&&(i=t,s=h)}}}return s}q(t){let i=Number.MAX_VALUE,s=i,e=i,r=O,n=r,h=r,o=r,a=this.$;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)o=c;else if(0>l){let t=-u.constant()/l;s>t&&(s=t,n=c)}else{let t=u.constant()/l;e>t&&(e=t,h=c)}}return n!==r?n:h!==r?h:o}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 s=this.$.find(t);void 0!==s?this.N.insertRow(s.second,-i):this.N.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===V.Slack||e===V.Error)return s.first}return O}K(t){return new F(t,this.ht++)}H=(()=>b())();$=(()=>b())();Z=(()=>b())();X=(()=>b())();Y=[];N=new P;tt=null;ht=0}function T(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 F{constructor(t,i){this.S=i,this.ot=t}id(){return this.S}type(){return this.ot}S;ot}let O=new F(V.Invalid,-1);class P{constructor(t=0){this.V=t}cells(){return this.ut}constant(){return this.V}isConstant(){return this.ut.empty()}allDummies(){let t=this.ut;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==V.Dummy)return!1;return!0}copy(){let t=new P(this.V);return t.ut=this.ut.copy(),t}add(t){return this.V+=t}insertSymbol(t,i=1){T(this.ut.setDefault(t,()=>0).second+=i)&&this.ut.erase(t)}insertRow(t,i=1){this.V+=t.V*i;let s=t.ut;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.ut.erase(t)}reverseSign(){this.V=-this.V;let t=this.ut;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.ut,s=-1/i.erase(t).second;this.V*=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.ut.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.ut.erase(t);void 0!==s&&this.insertRow(i,s.second)}ut=b();V}const H=1e3;var B,L,D,R;function $(t){switch(t){case B.P0:return k.create(H,H,H);case B.P1:return k.create(100,0,0);case B.P2:return k.create(10,0,0);case B.P3:return k.create(0,100,0);case B.P4:return k.create(0,10,0);case B.P5:return k.create(0,0,100);case B.P6:return k.create(0,0,10);case B.P7:return k.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function z(t){return t??B.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"})(B||(B={}));class j{constructor(s,e){this.lt=new t,this.ct=new Map,this.dt=new i(0,s,e,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 s=this.ct.get(t);if(void 0===s)throw Error("Element not found");this.lt.remove(s),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 s=this.ct.get(t);if(void 0===s)throw Error("Element not found");s.renderOrder=i}setVisibility(t,i){const s=this.ct.get(t);if(void 0===s)throw Error("Element not found");s.visible=i}getSortedVisibleElements(){return Array.from(this.ct.keys()).sort((t,i)=>this.getZIndex(t)-this.getZIndex(i))}render(t,i){for(const[s,e]of this.ct){const r=s.micro,n=Math.cos(r.rotation),h=Math.sin(r.rotation),o=s.width*r.scaleX,a=s.height*r.scaleY,u=r.anchorX*o,l=r.anchorY*a,c=u*h+l*n;e.position.x=s.x+r.x-(u*n-l*h),e.position.y=s.y+r.y-c,e.scale.x=o,e.scale.y=a,e.rotation.z=r.rotation,s.onBeforeRenderInternal(t,i)}t.render(this.lt,this.dt)}}function N(t){switch(t){case L.EQUAL:return M.Eq;case L.LESS_THAN:return M.Le;case L.GREATER_THAN:return M.Ge;default:throw Error("Invalid relation: "+t)}}function W(t){return t??L.EQUAL}(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(L||(L={}));class q{constructor(){this.ft=new A,this.gt=!1,this.wt=new Map,this.vt=0,this.yt=new Map,this.bt=0}createVariable(t,i){const s=this.vt++,e=new _;if(i===B.P0){const r={variable:e,priority:i,value:t};this.wt.set(s,r),r.constraint=this.xt(new g(0,[[s,1]]),new g(t),L.EQUAL,i),this.ft.addConstraint(r.constraint)}else this.wt.set(s,{variable:e,priority:i,value:t}),this.ft.addEditVariable(e,$(i)),this.ft.suggestValue(e,t);return this.gt=!0,s}removeVariable(t){const i=this.wt.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`);i.constraint?this.ft.removeConstraint(i.constraint):this.ft.removeEditVariable(i.variable),this.wt.delete(t),this.gt=!0}suggestVariableValue(t,i){const s=this.wt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);s.value!==i&&(s.value=i,s.constraint?s.constraint=this.Et(s.constraint,(new g).plus(t,1),new g(s.value),L.EQUAL,s.priority):this.ft.suggestValue(s.variable,i),this.gt=!0)}setVariablePriority(t,i){const s=this.wt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);i!==s.priority&&(s.priority=i,s.constraint?s.constraint=this.Et(s.constraint,(new g).plus(t,1),new g(s.value),L.EQUAL,s.priority):this._t(t,s),this.gt=!0)}readVariableValue(t){const i=this.wt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return this.gt&&(this.ft.updateVariables(),this.gt=!1),i.variable.value()}createConstraint(t,i,s,e,r){const n=this.bt++,h=this.xt(t,i,s,e);return this.yt.set(n,{constraint:h,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:r}),this.ft.addConstraint(h),this.gt=!0,n}removeConstraint(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Constraint ${t} does not exist`);this.ft.removeConstraint(i.constraint),this.yt.delete(t),this.gt=!0}setConstraintLHS(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.lhs.copy(i),this.Ct(s),this.gt=!0}setConstraintRHS(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.rhs.copy(i),this.Ct(s),this.gt=!0}setConstraintRelation(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.relation=i,this.Ct(s),this.gt=!0}setConstraintPriority(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.priority=i,this.Ct(s),this.gt=!0}setConstraintEnabled(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);if(i!==s.enabled){s.enabled=i;try{s.enabled?this.ft.addConstraint(s.constraint):this.ft.removeConstraint(s.constraint)}catch{this.It()}this.gt=!0}}kt(t){return new I(...t.prepareTermsInternal().map(([t,i])=>{const s=this.wt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);return[i,s.variable]}),t.constant)}_t(t,i){let s=!1;const e=[];for(const i of this.yt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){if(!s)try{this.ft.removeConstraint(i.constraint)}catch{s=!0}e.push(i)}this.ft.removeEditVariable(i.variable),this.ft.addEditVariable(i.variable,$(i.priority));for(const t of e)t.constraint=new S(this.kt(t.lhs),N(t.relation),this.kt(t.rhs),$(t.priority));if(!s)for(const t of e)try{this.ft.addConstraint(t.constraint)}catch{s=!0;break}s&&this.It()}Ct(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,s,e,r){let n=!1;try{this.ft.removeConstraint(t)}catch{n=!0}const h=this.xt(i,s,e,r);if(!n)try{this.ft.addConstraint(h)}catch{n=!0}return n&&this.It(),h}xt(t,i,s,e){return new S(this.kt(t),N(s),this.kt(i),$(e))}It(){this.ft=new A;for(const t of this.wt.values())this.ft.addEditVariable(t.variable,t.priority),this.ft.suggestValue(t.variable,t.value);for(const t of this.yt.values())this.ft.addConstraint(t.constraint)}}(t=>{t.ORIENTATION_CHANGE="orientation_change",t.MODE_CHANGE="mode_change"})(D||(D={}));class X extends w{constructor(t,i){super(),this.name="",this.solverWrapper=new q,this.modeInternal=v.VISIBLE,this.sceneWrapper=new j(t,i),this.xVariable=this.solverWrapper.createVariable(0,B.P0),this.yVariable=this.solverWrapper.createVariable(0,B.P0),this.wVariable=this.solverWrapper.createVariable(t,B.P0),this.hVariable=this.solverWrapper.createVariable(i,B.P0),this.orientationInternal=t>i?m.HORIZONTAL:m.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(D.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?m.HORIZONTAL:m.VERTICAL;s!==this.orientationInternal&&(this.orientationInternal=s,this.emit(D.ORIENTATION_CHANGE,this.orientationInternal,this))}renderInternal(t,i){this.mode!==v.HIDDEN&&this.sceneWrapper.render(t,i)}clickInternal(t,i){if(this.mode===v.INTERACTIVE)for(const s of this.sceneWrapper.getSortedVisibleElements())if(s.onClickInternal(t,i))return}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperInternal(){return this.sceneWrapper}}class Y{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal()}}class G extends Y{constructor(t,i,s,e){super(t),this.Mt=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.priorityInternal=z(i),this.relationInternal=W(s),this.orientationInternal=y(e),this.layer.on(D.ORIENTATION_CHANGE,this.Mt)}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.Mt())}destroy(){this.layer.off(D.ORIENTATION_CHANGE,this.Mt),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===m.ALWAYS||this.orientationInternal===this.layer.orientation}}class Z extends G{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.St=t,this.Ut=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new g(0,[[this.St.hVariable,1]]),new g(this.Ut),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.Ut}set height(t){this.Ut!==t&&(this.Ut=t,this.solverWrapper.setConstraintRHS(this.constraint,new g(t)))}}function J(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof X}function Q(t){return"object"==typeof t&&null!==t&&"xVariable"in t&&"number"==typeof t.xVariable&&"yVariable"in t&&"number"==typeof t.yVariable}function K(t){return"object"==typeof t&&null!==t&&"wVariable"in t&&"number"==typeof t.wVariable&&"hVariable"in t&&"number"==typeof t.hVariable}function tt(t,i,s){if(t instanceof X&&i instanceof X)throw Error(s+": layer cannot be snapped to another layer");let e,r;if(!(t instanceof X||J(t)))throw Error(s+": A must be a UILayer or a UIPointElement");if(e=t instanceof X?t:t.layer,!(i instanceof X||J(i)))throw Error(s+": B must be a UILayer or a UIPointElement");if(r=i instanceof X?i:i.layer,e!==r)throw Error(s+": elements must be on the same layer");return e}function it(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 st(t,i){if(it(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function et(t,i){if(it(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class rt extends G{constructor(t,i,s={}){super(tt(t,i,"UIHorizontalDistanceConstraint"),s.priority,s.relation,s.orientation),this.At=t,this.Tt=i,this.Vt=s.anchorA??.5,this.Ft=s.anchorB??.5,this.Ot=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Pt(),new g(this.Ot),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Ot}get anchorA(){return this.Vt}get anchorB(){return this.Ft}set distance(t){this.Ot!==t&&(this.Ot=t,this.solverWrapper.setConstraintRHS(this.constraint,new g(this.Ot)))}set anchorA(t){this.Vt!==t&&(this.Vt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}set anchorB(t){this.Ft!==t&&(this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}Pt(){let t,i;if(K(this.At))t=new g(0,[[this.At.xVariable,1],[this.At.wVariable,this.Vt]]);else{if(!Q(this.At))throw Error("A is not a valid element type");t=(new g).plus(this.At.xVariable,1)}if(K(this.Tt))i=new g(0,[[this.Tt.xVariable,1],[this.Tt.wVariable,this.Ft]]);else{if(!Q(this.Tt))throw Error("B is not a valid element type");i=(new g).plus(this.Tt.xVariable,1)}return g.minus(i,t)}}class nt extends G{constructor(t,i,s={}){super(tt(t,i,"UIHorizontalProportionConstraint"),s.priority,s.relation,s.orientation),this.At=t,this.Tt=i,this.Ht=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(this.Pt(),new g(0),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Ht}set proportion(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}Pt(){return g.minus(new g(0,[[this.At.wVariable,this.Ht]]),new g(0,[[this.Tt.wVariable,1]]))}}class ht extends G{constructor(t,i,s={}){super(tt(t,i,"UIVerticalDistanceConstraint"),s.priority,s.relation,s.orientation),this.At=t,this.Tt=i,this.Vt=s.anchorA??.5,this.Ft=s.anchorB??.5,this.Ot=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Pt(),new g(this.Ot),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Ot}get anchorA(){return this.Vt}get anchorB(){return this.Ft}set distance(t){this.Ot!==t&&(this.Ot=t,this.solverWrapper.setConstraintRHS(this.constraint,new g(this.Ot)))}set anchorA(t){this.Vt!==t&&(this.Vt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}set anchorB(t){this.Ft!==t&&(this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}Pt(){let t,i;if(K(this.At))t=new g(0,[[this.At.yVariable,1],[this.At.hVariable,this.Vt]]);else{if(!Q(this.At))throw Error("A is not a valid element type");t=(new g).plus(this.At.yVariable,1)}if(K(this.Tt))i=new g(0,[[this.Tt.yVariable,1],[this.Tt.hVariable,this.Ft]]);else{if(!Q(this.Tt))throw Error("B is not a valid element type");i=(new g).plus(this.Tt.yVariable,1)}return g.minus(i,t)}}class ot extends G{constructor(t,i,s={}){super(tt(t,i,"UIVerticalProportionConstraint"),s.priority,s.relation,s.orientation),this.At=t,this.Tt=i,this.Ht=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(this.Pt(),new g(0),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Ht}set proportion(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}Pt(){return g.minus(new g(0,[[this.At.hVariable,this.Ht]]),new g(0,[[this.Tt.hVariable,1]]))}}class at extends G{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.St=t,this.Bt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new g(0,[[this.St.wVariable,1]]),new g(this.Bt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Bt}set width(t){this.Bt!==t&&(this.Bt=t,this.solverWrapper.setConstraintRHS(this.constraint,new g(t)))}}class ut{static size(t,i={}){return{h:new at(t,{width:i.size?.h,priority:i.priority?.h,relation:i.relation?.h,orientation:i.orientation?.h}),v:new Z(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 rt(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 ht(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 nt(t,i,{proportion:s.proportion?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new ot(t,i,{proportion:s.proportion?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}}class lt extends G{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.St=t,this.Lt=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Pt(),new g(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Lt}set aspect(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}Pt(){return new g(0,[[this.St.wVariable,1],[this.St.hVariable,-this.Lt]])}}class ct extends G{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Dt=i,this.Rt=s,this.constraint=this.solverWrapper.createConstraint(this.Dt,this.Rt,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Dt}get rhs(){return this.Rt}setLHS(t){this.Dt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Dt)}setRHS(t){this.Rt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Rt)}}class dt extends w{constructor(t,i,s){it(i,"UIAnchor x"),it(s,"UIAnchor y"),super(),this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal(),this.xVariable=this.solverWrapper.createVariable(i,B.P7),this.yVariable=this.solverWrapper.createVariable(s,B.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){it(t,"UIAnchor x"),this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){it(t,"UIAnchor y"),this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}class ft extends dt{constructor(t,i,s,e=100,r=100){st(e,"UIDummy width"),st(r,"UIDummy height"),super(t,i,s),this.wVariable=this.solverWrapper.createVariable(e,B.P6),this.hVariable=this.solverWrapper.createVariable(r,B.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){st(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){st(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}class gt{constructor(){this.$t=0,this.zt=0,this.jt=0,this.Nt=0,this.Wt=1,this.qt=1,this.Xt=0,this.gt=!1}get x(){return this.$t}get y(){return this.zt}get anchorX(){return this.jt}get anchorY(){return this.Nt}get scaleX(){return this.Wt}get scaleY(){return this.qt}get size(){return Math.max(this.Wt,this.qt)}get angle(){return s.radToDeg(this.Xt)}get rotation(){return this.Xt}set x(t){t!==this.$t&&(this.$t=t,this.gt=!0)}set y(t){t!==this.zt&&(this.zt=t,this.gt=!0)}set anchorX(t){t!==this.jt&&(this.jt=t,this.gt=!0)}set anchorY(t){t!==this.Nt&&(this.Nt=t,this.gt=!0)}set scaleX(t){t!==this.Wt&&(this.Wt=t,this.gt=!0)}set scaleY(t){t!==this.qt&&(this.qt=t,this.gt=!0)}set size(t){t===this.Wt&&t===this.qt||(this.Wt=t,this.qt=t,this.gt=!0)}set angle(t){const i=s.degToRad(t);i!==this.Xt&&(this.Xt=i,this.gt=!0)}set rotation(t){t!==this.Xt&&(this.Xt=t,this.gt=!0)}reset(){0===this.$t&&0===this.zt&&0===this.jt&&0===this.Nt&&1===this.Wt&&1===this.qt&&0===this.Xt||(this.$t=0,this.zt=0,this.jt=0,this.Nt=0,this.Wt=1,this.qt=1,this.Xt=0,this.gt=!0)}getRecalculationRequiredInternal(){return this.gt}resetRecalculationRequiredInternal(){this.gt=!1}}(t=>{t.CLICK="click"})(R||(R={}));class pt extends dt{constructor(t,i,s,e,r,n){st(e,"UIElement width"),st(r,"UIElement height"),super(t,i,s),this.object=n,this.micro=new gt,this.modeInternal=v.VISIBLE,this.sceneWrapper=this.layer.getSceneWrapperInternal(),this.sceneWrapper.insertObject(this,this.object),this.wVariable=this.solverWrapper.createVariable(e,B.P6),this.hVariable=this.solverWrapper.createVariable(r,B.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){st(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){st(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){it(t,"UIElement zIndex"),this.sceneWrapper.setZIndex(this,t)}set mode(t){t!==this.modeInternal&&(this.modeInternal=t,this.sceneWrapper.setVisibility(this,t!==v.HIDDEN))}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.removeObject(this),super.destroy()}onClickInternal(t,i){const s=this.modeInternal===v.INTERACTIVE&&t>this.x&&this.x+this.width>t&&i>this.y&&this.y+this.height>i;return s&&this.emit(R.CLICK,t,i,this),s}onBeforeRenderInternal(t,i){}}const wt=.75;class vt extends e{constructor(t){super({uniforms:{map:{value:t},opacity:{value:1},color:{value:new r(1,1,1)},alphaTest:{value:wt}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D map;\n uniform float opacity;\n uniform vec3 color;\n uniform float alphaTest;\n varying vec2 vUv;\n\n void 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:wt,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?wt:0,this.needsUpdate=!0,this.uniformsNeedUpdate=!0),this}}const mt=new n(1,1).translate(.5,.5,0);class yt extends pt{constructor(t,i,s=0,e=0){const r=i.image.width,n=i.image.height,o=new vt(i);super(t,s,e,r,n,new h(mt,o)),this.Yt=o,this.Gt=i}get texture(){return this.Gt}get color(){return this.Yt.getColor()}get opacity(){return this.Yt.getOpacity()}get transparency(){return this.Yt.getTransparency()}set texture(t){const i=t.image.width,s=t.image.height;st(i,"UIImage texture width"),st(s,"UIImage texture height"),this.Yt.setTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s)}set color(t){this.Yt.setColor(t)}set opacity(t){this.Yt.setOpacity(t)}set transparency(t){this.Yt.setTransparency(t)}destroy(){this.Yt.dispose(),super.destroy()}}class bt extends e{constructor(t,i){super({uniforms:o.merge([{background:{value:i},foreground:{value:t},progress:{value:1},backgroundColor:{value:new r(1,1,1)},foregroundColor:{value:new r(1,1,1)},color:{value:new r(1,1,1)},backgroundOpacity:{value:1},foregroundOpacity:{value:1},opacity:{value:1},angle:{value:0},direction:{value:1}}]),vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D background;\n uniform sampler2D foreground;\n uniform float progress;\n uniform vec3 backgroundColor;\n uniform vec3 foregroundColor;\n uniform vec3 color;\n uniform float backgroundOpacity;\n uniform float foregroundOpacity;\n uniform float opacity;\n uniform float angle;\n uniform float direction;\n varying vec2 vUv;\n\n void 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 = smoothstep(threshold - 0.01, threshold + 0.01, progress);\n\n gl_FragColor = mix(backgroundColor, foregroundColor, progressMask);\n #include <colorspace_fragment>\n }\n ",transparent:!0,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}getBackgroundColor(){return this.uniforms.color.value.getHex()}getForegroundColor(){return this.uniforms.color.value.getHex()}getBackgroundOpacity(){return this.uniforms.backgroundOpacity.value}getForegroundOpacity(){return this.uniforms.foregroundOpacity.value}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}setBackgroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setForegroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=!0}setBackgroundOpacity(t){this.uniforms.backgroundOpacity.value=t,this.uniformsNeedUpdate=!0}setForegroundOpacity(t){this.uniforms.foregroundOpacity.value=t,this.uniformsNeedUpdate=!0}setAngle(t){this.uniforms.angle.value=t,this.uniformsNeedUpdate=!0}setIsForwardDirection(t){this.uniforms.direction.value=t?1:-1,this.uniformsNeedUpdate=!0}}class xt extends pt{constructor(t,i,e={}){const r=i.image?.width,n=i.image?.height;st(r,"UIProgress foreground texture width"),st(n,"UIProgress foreground texture height");const o=e.textureBackground?.image?.width,a=e.textureBackground?.image?.height;e.textureBackground&&(st(o,"UIProgress background texture width"),st(a,"UIProgress background texture height"));const u=new bt(i,e.textureBackground),l=new h(mt,u);void 0!==e.progress&&u.setProgress(e.progress),void 0!==e.isForegroundDirection&&u.setIsForwardDirection(e.isForegroundDirection),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,o??r,n??a,l),this.Yt=u}get progress(){return this.Yt.getProgress()}get backgroundTexture(){return this.Yt.getBackgroundTexture()}get foregroundTexture(){return this.Yt.getForegroundTexture()}get backgroundColor(){return this.Yt.getBackgroundColor()}get foregroundColor(){return this.Yt.getForegroundColor()}get backgroundOpacity(){return this.Yt.getBackgroundOpacity()}get foregroundOpacity(){return this.Yt.getForegroundOpacity()}get angle(){return s.radToDeg(this.Yt.getAngle())}get isForwardDirection(){return this.Yt.getIsForwardDirection()}set progress(t){this.Yt.setProgress(t)}set backgroundTexture(t){if(t){const i=t.image.height;st(t.image.width,"UIElement background texture width"),st(i,"UIElement background texture height")}this.Yt.setBackgroundTexture(t)}set foregroundTexture(t){const i=t.image.width,s=t.image.height;st(i,"UIImage texture width"),st(s,"UIImage texture height"),this.Yt.setForegroundTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s)}set backgroundColor(t){this.Yt.setBackgroundColor(t)}set foregroundColor(t){this.Yt.setForegroundColor(t)}set backgroundOpacity(t){this.Yt.setBackgroundOpacity(t)}set foregroundOpacity(t){this.Yt.setForegroundOpacity(t)}set angle(t){this.Yt.setAngle(s.degToRad(t))}set isForwardDirection(t){this.Yt.setIsForwardDirection(t)}destroy(){this.Yt.dispose(),super.destroy()}}var Et;(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"})(Et||(Et={}));const _t=Et.PROPERTY_CHANGED;class Ct extends pt{constructor(i,s={}){const e=s.resolutionFactor??.5;if(.1>e||e>2)throw Error(`Invalid resolution factor: ${e}. Must be between 0.1 and 2.`);const r=s.width??512,n=s.height??512,o=new a(r*e,n*e,{format:c,minFilter:l,magFilter:l,type:u,depthBuffer:s.enableDepthBuffer??!0,stencilBuffer:!1}),f=new vt(o.texture);super(i,0,0,r,n,new h(mt,f)),this.Zt=!0,this.Jt=!1,this.Qt=!1,this.Yt=f,this.Kt=o,this.ti=s.scene??new t,this.ii=s.camera??new d(75,r/n,.1,100),this.si=e,this.ei=s.updateMode??_t,this.ri=s.clearColor??0,this.ni=s.clearAlpha??0,s.updateMode===Et.PROPERTY_CHANGED&&(this.Qt=!0)}get color(){return this.Yt.getColor()}get opacity(){return this.Yt.getOpacity()}get transparency(){return this.Yt.getTransparency()}get scene(){return this.ti}get camera(){return this.ii}get updateMode(){return this.ei}get resolutionFactor(){return this.si}get clearColor(){return this.ri}get clearAlpha(){return this.ni}set color(t){this.Yt.setColor(t)}set opacity(t){this.Yt.setOpacity(t)}set transparency(t){this.Yt.setTransparency(t)}set scene(t){this.ti!==t&&(this.ti=t,this.Jt=!0)}set camera(t){this.ii!==t&&(this.ii=t,this.Jt=!0)}set updateMode(t){this.ei!==t&&(this.ei=t,this.Jt=!0)}set resolutionFactor(t){this.si!==t&&(this.si=t,this.Kt.setSize(this.width*this.si,this.height*this.si),this.Jt=!0)}set clearColor(t){this.ri!==t&&(this.ri=t,this.Jt=!0)}set clearAlpha(t){this.ni!==t&&(this.ni=t,this.Jt=!0)}destroy(){this.Yt.dispose(),this.Kt.dispose(),super.destroy()}requestRender(){this.Qt=!0}onBeforeRenderInternal(t){(this.ei===Et.EACH_FRAME||this.ei===Et.EACH_SECOND_FRAME&&this.Zt||this.ei===Et.PROPERTY_CHANGED&&this.Jt||this.ei===Et.MANUAL&&this.Qt)&&(this.Qt=!1,this.Jt=!1,this.Zt=!this.Zt,this.Kt.setSize(this.width*this.si,this.height*this.si),t.setClearColor(this.ri,this.clearAlpha),t.setRenderTarget(this.Kt),t.clear(!0,!0,!1),t.render(this.ti,this.ii))}}function It(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 kt(t,i){const s=t?.fontSize??i?.fontSize??16;st(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&st(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;it(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;et(n,"Shadow offset X");const h=t?.shadowOffsetY??i?.shadowOffsetY??0;et(h,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;et(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return et(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:n,shadowOffsetY:h,shadowBlur:o,shadowColor:t?.shadowColor??i?.shadowColor??"transparent",enableStroke:t?.enableStroke??i?.enableStroke??!1,strokeColor:t?.strokeColor??i?.strokeColor??"#000000",strokeWidth:a}}function Mt(t){return t.match(/\S+|\s|\n/g)??[]}function St(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 Ut(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 At(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 et(i,"Padding left"),et(s,"Padding right"),et(e,"Padding top"),et(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class Tt extends pt{constructor(t,i,s={},e=0,r=0){const n=document.createElement("canvas"),o=n.getContext("2d");if(!o)throw Error("Failed to create canvas context");const a=new f(n),u=new vt(a);super(t,e,r,2,2,new h(mt,u)),this.hi=1,this.oi=1,this.Yt=u,this.ai=a,this.ui=n,this.li=o,this.ci=i,this.di=s.maxWidth??1024,this.fi=At(s.padding),this.gi=s.commonStyle??{},this.pi()}get color(){return this.Yt.getColor()}get opacity(){return this.Yt.getOpacity()}get transparency(){return this.Yt.getTransparency()}get content(){return this.ci}get maxWidth(){return this.di}get padding(){return this.fi}get commonStyle(){return this.gi}set color(t){this.Yt.setColor(t)}set opacity(t){this.Yt.setOpacity(t)}set transparency(t){this.Yt.setTransparency(t)}set content(t){this.ci=t,this.pi()}set maxWidth(t){this.di=t,this.pi()}set padding(t){this.fi=t,this.pi()}set commonStyle(t){this.gi=t,this.pi()}destroy(){this.Yt.dispose(),this.ai.dispose(),this.ui.remove(),super.destroy()}onBeforeRenderInternal(t,i){this.oi!==this.width/this.height&&(this.oi=this.hi,this.height=this.width/this.hi)}pi(){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,n=i?s:s.text,h=kt(i?void 0:s.style,e);for(const i of Mt(n)){const s=St(t,i,h);r.push({text:i,style:h,metrics:s})}}const n=((t,i)=>{const s=[];let e=[],r=0,n=0,h=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:n,baseline:h,lineHeight:o}),e=[a],r=a.metrics.width,n=a.metrics.height,h=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),r+=a.metrics.width,n=Math.max(n,a.metrics.height),h=Math.max(h,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[],r=0,n=0,h=0,o=0);return e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),s})(s,r),h=(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}})(n);return{lines:n,size:h}})(this.li,this.content,this.di,this.gi);this.ui.width=i.width+this.fi.left+this.fi.right,this.ui.height=i.height+this.fi.top+this.fi.bottom,this.hi=(i.width+this.fi.left+this.fi.right)/(i.height+this.fi.top+this.fi.bottom),((t,i,s,e)=>{let r=this.fi.top;for(let t=0;s.length>t;t++){const n=s[t];let h=i;r+=0===t?n.height:n.lineHeight;for(const t of n.chunks)Ut(h,r,t.text,t.style,e),h+=t.metrics.width}})(0,this.fi.left,t,this.li),this.ai.needsUpdate=!0}}class Vt extends X{constructor(t,i){void 0!==t&&st(t,"UIFullscreenLayer.fixedWidth"),void 0!==i&&st(i,"UIFullscreenLayer.fixedHeight"),super(1,1),this.wi=()=>{const t=this.mi();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.yi=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.mi();this.clickInternal(s*r,e*r)},this.bi=t,this.xi=i,window.addEventListener("resize",this.wi),window.addEventListener("pointerdown",this.yi),this.wi()}get fixedWidth(){return this.bi}get fixedHeight(){return this.xi}set fixedWidth(t){void 0!==t&&st(t,"UIFullscreenLayer.fixedWidth"),t!==this.bi&&(this.bi=t,this.wi())}set fixedHeight(t){void 0!==t&&st(t,"UIFullscreenLayer.fixedHeight"),t!==this.xi&&(this.xi=t,this.wi())}destroy(){window.removeEventListener("resize",this.wi),window.removeEventListener("pointerdown",this.yi)}render(t,i){it(i,"UIFullscreenLayer.deltaTime"),t.clear(!1,!0,!0),super.renderInternal(t,i)}mi(){return this.orientation===m.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 Ft(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||It(t.style))}export{dt as UIAnchor,lt as UIAspectConstraint,Y as UIConstraint,ut as UIConstraint2DBuilder,ct as UICustomConstraint,ft as UIDummy,pt as UIElement,R as UIElementEvent,g as UIExpression,Vt as UIFullscreenLayer,Z as UIHeightConstraint,rt as UIHorizontalDistanceConstraint,nt as UIHorizontalProportionConstraint,yt as UIImage,X as UILayer,D as UILayerEvent,gt as UIMicro,v as UIMode,m as UIOrientation,B as UIPriority,xt as UIProgress,L as UIRelation,Ct as UIScene,Et as UISceneUpdateMode,G as UISingleParameterConstraint,Tt as UIText,ht as UIVerticalDistanceConstraint,ot as UIVerticalProportionConstraint,at as UIWidthConstraint,$ as convertPriority,N as convertRelation,Ft as isUITextSpan,It as isUITextStyle,y as resolveOrientation,At as resolvePadding,z as resolvePriority,W as resolveRelation,kt as resolveTextStyle};
2
2
  //# sourceMappingURL=index.min.js.map