laymur 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{Color as t,Scene as i,OrthographicCamera as s,MathUtils as e,ShaderMaterial 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.R(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.L(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.L(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}}R(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.L(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}L(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.L(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.L(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;function R(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 D(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={}));const L=new t;class ${constructor(t,e){this.lt=new i,this.ct=new Map,this.dt=new s(0,t,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){const s=t.getRenderTarget(),e=t.getClearColor(L),r=t.getClearAlpha(),n=t.autoClear,h=t.autoClearColor,o=t.autoClearDepth,a=t.autoClearStencil;t.autoClear=!1,t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.setClearColor(0,1);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.clear(!1,!0,!0),t.render(this.lt,this.dt),t.setRenderTarget(s),t.setClearColor(e),t.setClearAlpha(r),t.autoClear=n,t.autoClearColor=h,t.autoClearDepth=o,t.autoClearStencil=a}}var z,j,N;function W(t){switch(t){case z.EQUAL:return M.Eq;case z.LESS_THAN:return M.Le;case z.GREATER_THAN:return M.Ge;default:throw Error("Invalid relation: "+t)}}function q(t){return t??z.EQUAL}(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(z||(z={}));class X{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),z.EQUAL,i),this.ft.addConstraint(r.constraint)}else this.wt.set(s,{variable:e,priority:i,value:t}),this.ft.addEditVariable(e,R(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),z.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),z.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}),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,R(i.priority));for(const t of e)t.constraint=new S(this.kt(t.lhs),W(t.relation),this.kt(t.rhs),R(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),W(s),this.kt(i),R(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"})(j||(j={}));class Y extends w{constructor(t,i){super(),this.name="",this.solverWrapper=new X,this.modeInternal=v.VISIBLE,this.sceneWrapper=new $(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(j.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(j.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 G{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal()}}class Z extends G{constructor(t,i,s,e){super(t),this.Mt=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.priorityInternal=D(i),this.relationInternal=q(s),this.orientationInternal=y(e),this.layer.on(j.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(j.ORIENTATION_CHANGE,this.Mt),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===m.ALWAYS||this.orientationInternal===this.layer.orientation}}class J extends Z{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 Q(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof Y}function K(t){return"object"==typeof t&&null!==t&&"xVariable"in t&&"number"==typeof t.xVariable&&"yVariable"in t&&"number"==typeof t.yVariable}function tt(t){return"object"==typeof t&&null!==t&&"wVariable"in t&&"number"==typeof t.wVariable&&"hVariable"in t&&"number"==typeof t.hVariable}function it(t,i,s){if(t instanceof Y&&i instanceof Y)throw Error(s+": layer cannot be snapped to another layer");let e,r;if(!(t instanceof Y||Q(t)))throw Error(s+": A must be a UILayer or a UIPointElement");if(e=t instanceof Y?t:t.layer,!(i instanceof Y||Q(i)))throw Error(s+": B must be a UILayer or a UIPointElement");if(r=i instanceof Y?i:i.layer,e!==r)throw Error(s+": elements must be on the same layer");return e}function st(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 et(t,i){if(st(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function rt(t,i){if(st(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class nt extends Z{constructor(t,i,s={}){super(it(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(tt(this.At))t=new g(0,[[this.At.xVariable,1],[this.At.wVariable,this.Vt]]);else{if(!K(this.At))throw Error("A is not a valid element type");t=(new g).plus(this.At.xVariable,1)}if(tt(this.Tt))i=new g(0,[[this.Tt.xVariable,1],[this.Tt.wVariable,this.Ft]]);else{if(!K(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 ht extends Z{constructor(t,i,s={}){super(it(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(new g(0),this.Bt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Ht}set proportion(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Bt()))}Bt(){return g.minus(new g(0,[[this.At.wVariable,this.Ht]]),new g(0,[[this.Tt.wVariable,1]]))}}class ot extends Z{constructor(t,i,s={}){super(it(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(tt(this.At))t=new g(0,[[this.At.yVariable,1],[this.At.hVariable,this.Vt]]);else{if(!K(this.At))throw Error("A is not a valid element type");t=(new g).plus(this.At.yVariable,1)}if(tt(this.Tt))i=new g(0,[[this.Tt.yVariable,1],[this.Tt.hVariable,this.Ft]]);else{if(!K(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 at extends Z{constructor(t,i,s={}){super(it(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(new g(0),this.Bt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Ht}set proportion(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Bt()))}Bt(){return g.minus(new g(0,[[this.At.hVariable,this.Ht]]),new g(0,[[this.Tt.hVariable,1]]))}}class ut extends Z{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.St=t,this.Rt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new g(0,[[this.St.wVariable,1]]),new g(this.Rt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Rt}set width(t){this.Rt!==t&&(this.Rt=t,this.solverWrapper.setConstraintRHS(this.constraint,new g(t)))}}class lt{static size(t,i={}){return{h:new ut(t,{width:i.size?.h,priority:i.priority?.h,relation:i.relation?.h,orientation:i.orientation?.h}),v:new J(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 nt(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 ot(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 ht(t,i,{proportion:s.proportion?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new at(t,i,{proportion:s.proportion?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}}class ct extends Z{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.St=t,this.Dt=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.Dt}set aspect(t){this.Dt!==t&&(this.Dt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Pt()))}Pt(){return new g(0,[[this.St.wVariable,1],[this.St.hVariable,-this.Dt]])}}class dt extends Z{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Lt=i,this.$t=s,this.constraint=this.solverWrapper.createConstraint(this.Lt,this.$t,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Lt}get rhs(){return this.$t}setLHS(t){this.Lt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Lt)}setRHS(t){this.$t=t,this.solverWrapper.setConstraintRHS(this.constraint,this.$t)}}class ft extends w{constructor(t,i,s){st(i,"UIAnchor x"),st(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){st(t,"UIAnchor x"),this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){st(t,"UIAnchor y"),this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}class gt extends ft{constructor(t,i,s,e=100,r=100){et(e,"UIDummy width"),et(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){et(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){et(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}class pt{constructor(){this.zt=0,this.jt=0,this.Nt=0,this.Wt=0,this.qt=1,this.Xt=1,this.Yt=0,this.gt=!1}get x(){return this.zt}get y(){return this.jt}get anchorX(){return this.Nt}get anchorY(){return this.Wt}get scaleX(){return this.qt}get scaleY(){return this.Xt}get size(){return Math.max(this.qt,this.Xt)}get angle(){return e.radToDeg(this.Yt)}get rotation(){return this.Yt}set x(t){t!==this.zt&&(this.zt=t,this.gt=!0)}set y(t){t!==this.jt&&(this.jt=t,this.gt=!0)}set anchorX(t){t!==this.Nt&&(this.Nt=t,this.gt=!0)}set anchorY(t){t!==this.Wt&&(this.Wt=t,this.gt=!0)}set scaleX(t){t!==this.qt&&(this.qt=t,this.gt=!0)}set scaleY(t){t!==this.Xt&&(this.Xt=t,this.gt=!0)}set size(t){t===this.qt&&t===this.Xt||(this.qt=t,this.Xt=t,this.gt=!0)}set angle(t){const i=e.degToRad(t);i!==this.Yt&&(this.Yt=i,this.gt=!0)}set rotation(t){t!==this.Yt&&(this.Yt=t,this.gt=!0)}reset(){0===this.zt&&0===this.jt&&0===this.Nt&&0===this.Wt&&1===this.qt&&1===this.Xt&&0===this.Yt||(this.zt=0,this.jt=0,this.Nt=0,this.Wt=0,this.qt=1,this.Xt=1,this.Yt=0,this.gt=!0)}getRecalculationRequiredInternal(){return this.gt}resetRecalculationRequiredInternal(){this.gt=!1}}(t=>{t.CLICK="click"})(N||(N={}));class wt extends ft{constructor(t,i,s,e,r,n){et(e,"UIElement width"),et(r,"UIElement height"),super(t,i,s),this.object=n,this.micro=new pt,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){et(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){et(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){st(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(N.CLICK,t,i,this),s}onBeforeRenderInternal(t,i){}}const vt=.75;class mt extends r{constructor(i){super({uniforms:{map:{value:i},opacity:{value:1},color:{value:new t(1,1,1)},alphaTest:{value:vt}},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:vt,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?vt:0,this.needsUpdate=!0,this.uniformsNeedUpdate=!0),this}}const yt=new n(1,1).translate(.5,.5,0);class bt extends wt{constructor(t,i,s=0,e=0){const r=i.image.width,n=i.image.height,o=new mt(i);super(t,s,e,r,n,new h(yt,o)),this.Gt=o,this.Zt=i}get texture(){return this.Zt}get color(){return this.Gt.getColor()}get opacity(){return this.Gt.getOpacity()}get transparency(){return this.Gt.getTransparency()}set texture(t){const i=t.image.width,s=t.image.height;et(i,"UIImage texture width"),et(s,"UIImage texture height"),this.Gt.setTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s)}set color(t){this.Gt.setColor(t)}set opacity(t){this.Gt.setOpacity(t)}set transparency(t){this.Gt.setTransparency(t)}destroy(){this.Gt.dispose(),super.destroy()}}class xt extends r{constructor(i,s){super({uniforms:o.merge([{background:{value:s},foreground:{value:i},progress:{value:1},backgroundColor:{value:new t(1,1,1)},foregroundColor:{value:new t(1,1,1)},color:{value:new t(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 Et extends wt{constructor(t,i,s={}){const r=i.image?.width,n=i.image?.height;et(r,"UIProgress foreground texture width"),et(n,"UIProgress foreground texture height");const o=s.textureBackground?.image?.width,a=s.textureBackground?.image?.height;s.textureBackground&&(et(o,"UIProgress background texture width"),et(a,"UIProgress background texture height"));const u=new xt(i,s.textureBackground),l=new h(yt,u);void 0!==s.progress&&u.setProgress(s.progress),void 0!==s.isForegroundDirection&&u.setIsForwardDirection(s.isForegroundDirection),void 0!==s.angle&&u.setAngle(e.degToRad(s.angle)),void 0!==s.backgroundColor&&u.setBackgroundColor(s.backgroundColor),void 0!==s.foregroundColor&&u.setForegroundColor(s.foregroundColor),void 0!==s.backgroundOpacity&&u.setBackgroundOpacity(s.backgroundOpacity),void 0!==s.foregroundOpacity&&u.setForegroundOpacity(s.foregroundOpacity),super(t,s.x??0,s.y??0,o??r,n??a,l),this.Gt=u}get progress(){return this.Gt.getProgress()}get backgroundTexture(){return this.Gt.getBackgroundTexture()}get foregroundTexture(){return this.Gt.getForegroundTexture()}get backgroundColor(){return this.Gt.getBackgroundColor()}get foregroundColor(){return this.Gt.getForegroundColor()}get backgroundOpacity(){return this.Gt.getBackgroundOpacity()}get foregroundOpacity(){return this.Gt.getForegroundOpacity()}get angle(){return e.radToDeg(this.Gt.getAngle())}get isForwardDirection(){return this.Gt.getIsForwardDirection()}set progress(t){this.Gt.setProgress(t)}set backgroundTexture(t){if(t){const i=t.image.height;et(t.image.width,"UIElement background texture width"),et(i,"UIElement background texture height")}this.Gt.setBackgroundTexture(t)}set foregroundTexture(t){const i=t.image.width,s=t.image.height;et(i,"UIImage texture width"),et(s,"UIImage texture height"),this.Gt.setForegroundTexture(t),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s)}set backgroundColor(t){this.Gt.setBackgroundColor(t)}set foregroundColor(t){this.Gt.setForegroundColor(t)}set backgroundOpacity(t){this.Gt.setBackgroundOpacity(t)}set foregroundOpacity(t){this.Gt.setForegroundOpacity(t)}set angle(t){this.Gt.setAngle(e.degToRad(t))}set isForwardDirection(t){this.Gt.setIsForwardDirection(t)}destroy(){this.Gt.dispose(),super.destroy()}}var _t;(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"})(_t||(_t={}));const Ct=_t.PROPERTY_CHANGED;class It extends wt{constructor(t,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 mt(o.texture);super(t,0,0,r,n,new h(yt,f)),this.Jt=!0,this.Qt=!1,this.Kt=!1,this.Gt=f,this.ti=o,this.ii=s.scene??new i,this.si=s.camera??new d(75,r/n,.1,100),this.ei=e,this.ri=s.updateMode??Ct,this.ni=s.clearColor??0,this.hi=s.clearAlpha??0,s.updateMode===_t.PROPERTY_CHANGED&&(this.Kt=!0)}get color(){return this.Gt.getColor()}get opacity(){return this.Gt.getOpacity()}get transparency(){return this.Gt.getTransparency()}get scene(){return this.ii}get camera(){return this.si}get updateMode(){return this.ri}get resolutionFactor(){return this.ei}get clearColor(){return this.ni}get clearAlpha(){return this.hi}set color(t){this.Gt.setColor(t)}set opacity(t){this.Gt.setOpacity(t)}set transparency(t){this.Gt.setTransparency(t)}set scene(t){this.ii!==t&&(this.ii=t,this.Qt=!0)}set camera(t){this.si!==t&&(this.si=t,this.Qt=!0)}set updateMode(t){this.ri!==t&&(this.ri=t,this.Qt=!0)}set resolutionFactor(t){this.ei!==t&&(this.ei=t,this.ti.setSize(this.width*this.ei,this.height*this.ei),this.Qt=!0)}set clearColor(t){this.ni!==t&&(this.ni=t,this.Qt=!0)}set clearAlpha(t){this.hi!==t&&(this.hi=t,this.Qt=!0)}destroy(){this.Gt.dispose(),this.ti.dispose(),super.destroy()}requestRender(){this.Kt=!0}onBeforeRenderInternal(t){(this.ri===_t.EACH_FRAME||this.ri===_t.EACH_SECOND_FRAME&&this.Jt||this.ri===_t.PROPERTY_CHANGED&&this.Qt||this.ri===_t.MANUAL&&this.Kt)&&(this.Kt=!1,this.Qt=!1,this.Jt=!this.Jt,this.ti.setSize(this.width*this.ei,this.height*this.ei),t.setClearColor(this.ni,this.clearAlpha),t.setRenderTarget(this.ti),t.clear(!0,!0,!1),t.render(this.ii,this.si))}}function kt(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 Mt(t,i){const s=t?.fontSize??i?.fontSize??16;et(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&et(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;st(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;rt(n,"Shadow offset X");const h=t?.shadowOffsetY??i?.shadowOffsetY??0;rt(h,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;rt(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return rt(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 St(t){return t.match(/\S+|\s|\n/g)??[]}function Ut(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 At(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 Tt(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 rt(i,"Padding left"),rt(s,"Padding right"),rt(e,"Padding top"),rt(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class Vt extends wt{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 mt(a);super(t,e,r,2,2,new h(yt,u)),this.oi=1,this.ai=1,this.Gt=u,this.ui=a,this.li=n,this.ci=o,this.di=i,this.fi=s.maxWidth??1024,this.gi=Tt(s.padding),this.pi=s.commonStyle??{},this.wi()}get color(){return this.Gt.getColor()}get opacity(){return this.Gt.getOpacity()}get transparency(){return this.Gt.getTransparency()}get content(){return this.di}get maxWidth(){return this.fi}get padding(){return this.gi}get commonStyle(){return this.pi}set color(t){this.Gt.setColor(t)}set opacity(t){this.Gt.setOpacity(t)}set transparency(t){this.Gt.setTransparency(t)}set content(t){this.di=t,this.wi()}set maxWidth(t){this.fi=t,this.wi()}set padding(t){this.gi=t,this.wi()}set commonStyle(t){this.pi=t,this.wi()}destroy(){this.Gt.dispose(),this.ui.dispose(),this.li.remove(),super.destroy()}onBeforeRenderInternal(t,i){this.ai!==this.width/this.height&&(this.ai=this.oi,this.height=this.width/this.oi)}wi(){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=Mt(i?void 0:s.style,e);for(const i of St(n)){const s=Ut(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.ci,this.content,this.fi,this.pi);this.li.width=i.width+this.gi.left+this.gi.right,this.li.height=i.height+this.gi.top+this.gi.bottom,this.oi=(i.width+this.gi.left+this.gi.right)/(i.height+this.gi.top+this.gi.bottom),((t,i,s,e)=>{let r=this.gi.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)At(h,r,t.text,t.style,e),h+=t.metrics.width}})(0,this.gi.left,t,this.ci),this.ui.needsUpdate=!0}}class Ft extends Y{constructor(t,i){void 0!==t&&et(t,"UIFullscreenLayer.fixedWidth"),void 0!==i&&et(i,"UIFullscreenLayer.fixedHeight"),super(1,1),this.mi=()=>{const t=this.yi();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.bi=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.yi();this.clickInternal(s*r,e*r)},this.xi=t,this.Ei=i,window.addEventListener("resize",this.mi),window.addEventListener("pointerdown",this.bi),this.mi()}get fixedWidth(){return this.xi}get fixedHeight(){return this.Ei}set fixedWidth(t){void 0!==t&&et(t,"UIFullscreenLayer.fixedWidth"),t!==this.xi&&(this.xi=t,this.mi())}set fixedHeight(t){void 0!==t&&et(t,"UIFullscreenLayer.fixedHeight"),t!==this.Ei&&(this.Ei=t,this.mi())}destroy(){window.removeEventListener("resize",this.mi),window.removeEventListener("pointerdown",this.bi)}render(t,i){st(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}yi(){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 Ot(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||kt(t.style))}export{ft as UIAnchor,ct as UIAspectConstraint,G as UIConstraint,lt as UIConstraint2DBuilder,dt as UICustomConstraint,gt as UIDummy,wt as UIElement,N as UIElementEvent,g as UIExpression,Ft as UIFullscreenLayer,J as UIHeightConstraint,nt as UIHorizontalDistanceConstraint,ht as UIHorizontalProportionConstraint,bt as UIImage,Y as UILayer,j as UILayerEvent,pt as UIMicro,v as UIMode,m as UIOrientation,B as UIPriority,Et as UIProgress,z as UIRelation,It as UIScene,_t as UISceneUpdateMode,Z as UISingleParameterConstraint,Vt as UIText,ot as UIVerticalDistanceConstraint,at as UIVerticalProportionConstraint,ut as UIWidthConstraint,R as convertPriority,W as convertRelation,Ot as isUITextSpan,kt as isUITextStyle,y as resolveOrientation,Tt as resolvePadding,D as resolvePriority,q as resolveRelation,Mt as resolveTextStyle};
2
2
  //# sourceMappingURL=index.min.js.map