laymur 0.13.3 → 0.13.5

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