laymur 0.6.1 → 0.6.2
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.js +64 -62
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/miscellaneous/UIColor.d.ts +4 -4
- package/package.json +1 -1
package/dist/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{PlaneGeometry as t,Color as i,Scene as s,OrthographicCamera as e,ShaderMaterial as r,Vector4 as n,Mesh as h,Texture as o,Vector2 as a,Vector3 as l,Matrix2 as c,Matrix3 as u,Matrix4 as f,MathUtils as d,Quaternion as p,CanvasTexture as g,LinearFilter as w,WebGLRenderTarget as m,UnsignedByteType as v,RGBAFormat as y,PerspectiveCamera as b,InstancedBufferGeometry as x,InstancedBufferAttribute as _}from"three";class I{constructor(t=0,i){this.constant=t,this._=i?new Map(i):new Map}static plus(t,i){const s=new I(t.constant+i.constant,Array.from(t._.entries()));for(const[t,e]of i._)s.plus(t,e);return s}static minus(t,i){const s=new I(t.constant-i.constant,Array.from(t._.entries()));for(const[t,e]of i._)s.minus(t,e);return s}plus(t,i){return this._.set(t,(this._.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this._)this._.set(i,s*t);return this}divide(t){return this.multiply(1/t)}hasTerm(t){return this._.has(t)}copy(t){this.constant=t.constant,this._.clear();for(const[i,s]of t._)this._.set(i,s);return this}clone(){return new I(this.constant,Array.from(this._.entries()))}prepareTermsInternal(){return Array.from(this._.entries())}}class E{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 P{constructor(){this.o=new Map}on(t,i,s,e=0){return this.h(t,!1,e,i,s),this}once(t,i,s,e=0){return this.h(t,!0,e,i,s),this}off(t,i,s){const e=this.o.get(t);if(void 0===e)return this;e.u&&(e.u=!1,e.v=e.v.slice());const r=e.v;if(0===r.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;r.length>t;t++){const i=r[t];e.l.remove(i.I,i.p)}return this}{const n=r.length;if(r[0].I===i&&r[0].p===s)return 1===n?this.o.delete(t):r.shift(),this;const h=n-1;if(r[h].I===i&&r[h].p===s)return r.pop(),this;if(10>n||r[0].M===r[h].M)for(let t=1;h>t;t++){const e=r[t];if(e.I===i&&e.p===s)return r.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let n=0,h=r.length-1;for(;h>=n;){const i=n+h>>>1;t>r[i].M?n=i+1:h=i-1}const o=n;for(h=r.length-1;h>=n;){const i=n+h>>>1;r[i].M>t?h=i-1:n=i+1}const a=h;for(let t=o;a>=t;t++)if(r[t].I===i&&r[t].p===s)return r.splice(t,1),this}}return this}emit(t,...i){const s=this.o.get(t);if(void 0===s)return!1;if(0===s.v.length)return!1;s.u?s.v=s.v.slice():s.u=!0;const e=s.v;let r=!1;for(let t=0;e.length>t;t++){const s=e[t];s.I.apply(s.p,i),s.k&&(r=!0,s.m=!0)}const n=this.o.get(t);if(void 0===n)return!0;n.v===e&&(n.u=!1);const h=n.v;if(r){let i=0;for(let t=0;h.length>t;t++){const s=h[t];s.m?n.l.remove(s.I,s.p):h[i++]=s}0===i?this.o.delete(t):h.length=i}return!0}h(t,i,s,e,r){let n=this.o.get(t);if(void 0===n)return void this.o.set(t,{v:[{I:e,p:r,M:s,k:i,m:!1}],u:!1,l:new E(e,r,s)});if(n.l.has(e,r))throw Error("Event listener already exists");n.l.insert(e,r,s);const h={I:e,p:r,M:s,k:i,m:!1};n.u&&(n.u=!1,n.v=n.v.slice());{const t=n.v,i=h.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(h);if(t[0].M>=i)return void t.unshift(h);{let s=0,e=t.length;for(;e>s;){const r=s+e>>>1;i>t[r].M?s=r+1:e=r}t.splice(s,0,h)}}}}var U,C;function S(t){return t??C.ALWAYS}function M(){return new T}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(U||(U={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(C||(C={}));class T{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new V(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new V(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new T;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class V{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new V(this.first,this.second)}}class B{constructor(t=""){this.P=t}id(){return this.U}name(){return this.P}setName(t){this.P=t}context(){return this.C}setContext(t){this.C=t}value(){return this.S}setValue(t){this.S=t}plus(t){return new H(this,t)}minus(t){return new H(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new H([t,this])}divide(t){return new H([1/t,this])}toJSON(){return{name:this.P,value:this.S}}toString(){return this.C+"["+this.P+":"+this.S+"]"}P;S=0;C=null;U=A++}let A=0;class H{constructor(){let t=(t=>{let i=0,s=()=>0,e=M();for(let r=0,n=t.length;n>r;++r){let n=t[r];if("number"==typeof n)i+=n;else if(n instanceof B)e.setDefault(n,s).second+=1;else if(n instanceof H){i+=n.constant();let t=n.terms();for(let i=0,r=t.size();r>i;i++){let r=t.itemAt(i);e.setDefault(r.first,s).second+=r.second}}else{if(!(n instanceof Array))throw Error("invalid Expression argument: "+n);{if(2!==n.length)throw Error("array must have length 2");let t=n[0],r=n[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(r instanceof B)e.setDefault(r,s).second+=t;else{if(!(r instanceof H))throw Error("array item 1 must be a variable or expression");{i+=r.constant()*t;let n=r.terms();for(let i=0,r=n.size();r>i;i++){let r=n.itemAt(i);e.setDefault(r.first,s).second+=r.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.T=t.terms,this.V=t.constant}terms(){return this.T}constant(){return this.V}value(){let t=this.V;for(let i=0,s=this.T.size();s>i;i++){let s=this.T.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new H(this,t)}minus(t){return new H(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new H([t,this])}divide(t){return new H([1/t,this])}isConstant(){return 0==this.T.size()}toString(){let t=this.T.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.V||(t+=" + "),t+=this.V,t}T;V}class R{static create(t,i,s,e=1){let r=0;return r+=1e6*Math.max(0,Math.min(1e3,t*e)),r+=1e3*Math.max(0,Math.min(1e3,i*e)),r+=Math.max(0,Math.min(1e3,s*e)),r}static required=R.create(1e3,1e3,1e3);static strong=R.create(1,0,0);static medium=R.create(0,1,0);static weak=R.create(0,0,1);static clip(t){return Math.max(0,Math.min(R.required,t))}}var z;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(z||(z={}));class k{constructor(t,i,s,e=R.required){this.B=i,this.A=R.clip(e),this.H=void 0===s&&t instanceof H?t:t.minus(s)}id(){return this.U}expression(){return this.H}op(){return this.B}strength(){return this.A}toString(){return this.H+" "+["<=",">=","="][this.B]+" 0 ("+this.A+")"}H;B;A;U=$++}let $=0;class L{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=R.required){let r=new k(t,i,s,e);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.R.find(t))throw Error("duplicate constraint");let i=this.$(t),s=i.row,e=i.tag,r=this.L(s,e);if(r.type()===F.Invalid&&s.allDummies()){if(!W(s.constant()))throw Error("unsatisfiable constraint");r=e.marker}if(r.type()===F.Invalid){if(!this.W(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.F(r,s),this.D.insert(r,s);this.R.insert(t,e),this.N(this.O)}removeConstraint(t){let i=this.R.erase(t);if(void 0===i)throw Error("unknown constraint");this.q(t,i.second);let s=i.second.marker,e=this.D.erase(s);if(void 0===e){let t=this.j(s);if(t.type()===F.Invalid)throw Error("failed to find leaving row");e=this.D.erase(t),e.second.solveForEx(t,s),this.F(s,e.second)}this.N(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=R.clip(i))===R.required)throw Error("bad required strength");let s=new H(t),e=new k(s,z.Eq,void 0,i);this.addConstraint(e);let r=this.R.find(e).second;this.G.insert(t,{tag:r,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.D,r=s.second,n=i-r.constant;r.constant=i;let h=r.tag.marker,o=e.find(h);if(void 0!==o)return 0>o.second.add(-n)&&this.Y.push(h),void this.X();let a=r.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(n)&&this.Y.push(a),void this.X();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,r=s.coefficientFor(h);0!==r&&0>s.add(n*r)&&i.first.type()!==F.External&&this.Y.push(i.first)}this.X()}updateVariables(){let t=this.J,i=this.D;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),r=i.find(e.second);e.first.setValue(void 0!==r?r.second.constant():0)}}Z(t){return this.J.setDefault(t,()=>this.K(F.External)).second}$(t){let i=t.expression(),s=new O(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!W(i.second)){let t=this.Z(i.first),e=this.D.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let r=this.O,n=t.strength(),h={marker:N,other:N};switch(t.op()){case z.Le:case z.Ge:{let i=t.op()===z.Le?1:-1,e=this.K(F.Slack);if(h.marker=e,s.insertSymbol(e,i),R.required>n){let t=this.K(F.Error);h.other=t,s.insertSymbol(t,-i),r.insertSymbol(t,n)}break}case z.Eq:if(R.required>n){let t=this.K(F.Error),i=this.K(F.Error);h.marker=t,h.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),r.insertSymbol(t,n),r.insertSymbol(i,n)}else{let t=this.K(F.Dummy);h.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:h}}L(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===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?N:i.other):i.marker}W(t){let i=this.K(F.Slack);this.D.insert(i,t.copy()),this.tt=t.copy(),this.N(this.tt);let s=W(this.tt.constant());this.tt=null;let e=this.D.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let r=this.it(t);if(r.type()===F.Invalid)return!1;t.solveForEx(i,r),this.F(r,t),this.D.insert(r,t)}let r=this.D;for(let t=0,s=r.size();s>t;++t)r.itemAt(t).second.removeSymbol(i);return this.O.removeSymbol(i),s}F(t,i){let s=this.D;for(let e=0,r=s.size();r>e;++e){let r=s.itemAt(e);r.second.substitute(t,i),0>r.second.constant()&&r.first.type()!==F.External&&this.Y.push(r.first)}this.O.substitute(t,i),this.tt&&this.tt.substitute(t,i)}N(t){let i=0;for(;this.maxIterations>i;){let s=this.st(t);if(s.type()===F.Invalid)return;let e=this.et(s);if(e.type()===F.Invalid)throw Error("the objective is unbounded");let r=this.D.erase(e).second;r.solveForEx(e,s),this.F(s,r),this.D.insert(s,r),i++}throw Error("solver iterations exceeded")}X(){let t=this.D,i=this.Y;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.rt(e.second);if(i.type()===F.Invalid)throw Error("dual optimize failed");let r=e.second;t.erase(s),r.solveForEx(s,i),this.F(i,r),t.insert(i,r)}}}st(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first;if(0>s.second&&e.type()!==F.Dummy)return e}return N}rt(t){let i=Number.MAX_VALUE,s=N,e=t.cells();for(let t=0,r=e.size();r>t;++t){let r=e.itemAt(t),n=r.first,h=r.second;if(h>0&&n.type()!==F.Dummy){let t=this.O.coefficientFor(n)/h;i>t&&(i=t,s=n)}}return s}et(t){let i=Number.MAX_VALUE,s=N,e=this.D;for(let r=0,n=e.size();n>r;++r){let n=e.itemAt(r),h=n.first;if(h.type()!==F.External){let e=n.second,r=e.coefficientFor(t);if(0>r){let t=-e.constant()/r;i>t&&(i=t,s=h)}}}return s}j(t){let i=Number.MAX_VALUE,s=i,e=i,r=N,n=r,h=r,o=r,a=this.D;for(let i=0,r=a.size();r>i;++i){let r=a.itemAt(i),l=r.second,c=l.coefficientFor(t);if(0===c)continue;let u=r.first;if(u.type()===F.External)o=u;else if(0>c){let t=-l.constant()/c;s>t&&(s=t,n=u)}else{let t=l.constant()/c;e>t&&(e=t,h=u)}}return n!==r?n:h!==r?h:o}q(t,i){i.marker.type()===F.Error&&this.nt(i.marker,t.strength()),i.other.type()===F.Error&&this.nt(i.other,t.strength())}nt(t,i){let s=this.D.find(t);void 0!==s?this.O.insertRow(s.second,-i):this.O.insertSymbol(t,-i)}it(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first.type();if(e===F.Slack||e===F.Error)return s.first}return N}K(t){return new D(t,this.ht++)}R=(()=>M())();D=(()=>M())();J=(()=>M())();G=(()=>M())();Y=[];O=new O;tt=null;ht=0}function W(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 D{constructor(t,i){this.U=i,this.ot=t}id(){return this.U}type(){return this.ot}U;ot}let N=new D(F.Invalid,-1);class O{constructor(t=0){this.V=t}cells(){return this.lt}constant(){return this.V}isConstant(){return this.lt.empty()}allDummies(){let t=this.lt;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==F.Dummy)return!1;return!0}copy(){let t=new O(this.V);return t.lt=this.lt.copy(),t}add(t){return this.V+=t}insertSymbol(t,i=1){W(this.lt.setDefault(t,()=>0).second+=i)&&this.lt.erase(t)}insertRow(t,i=1){this.V+=t.V*i;let s=t.lt;for(let t=0,e=s.size();e>t;++t){let e=s.itemAt(t);this.insertSymbol(e.first,e.second*i)}}removeSymbol(t){this.lt.erase(t)}reverseSign(){this.V=-this.V;let t=this.lt;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.lt,s=-1/i.erase(t).second;this.V*=s;for(let t=0,e=i.size();e>t;++t)i.itemAt(t).second*=s}solveForEx(t,i){this.insertSymbol(t,-1),this.solveFor(i)}coefficientFor(t){let i=this.lt.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.lt.erase(t);void 0!==s&&this.insertRow(i,s.second)}lt=M();V}const q=1e3;var j;function G(t){switch(t){case j.P0:return R.create(q,q,q);case j.P1:return R.create(100,0,0);case j.P2:return R.create(10,0,0);case j.P3:return R.create(0,100,0);case j.P4:return R.create(0,10,0);case j.P5:return R.create(0,0,100);case j.P6:return R.create(0,0,10);case j.P7:return R.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function Y(t){return t??j.P0}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(j||(j={}));const X={black:0,white:16777215,red:16711680,green:32768,blue:255,yellow:16776960,cyan:65535,magenta:16711935,gray:8421504,grey:8421504,silver:12632256,maroon:8388608,olive:8421376,lime:65280,aqua:65535,teal:32896,navy:128,fuchsia:16711935,purple:8388736,orange:16753920,pink:16761035,brown:10824234,gold:16766720,violet:15631086,indigo:4915330,coral:16744272,salmon:16416882,khaki:15787660,plum:14524637,orchid:14315734,tan:13808780,beige:16119260,mint:10025880,lavender:15132410,crimson:14423100,azure:15794175,ivory:16777200,snow:16775930};var J,Q;(t=>{t.CHANGE="change"})(J||(J={}));class Z extends P{constructor(...t){if(super(),this.rInternal=1,this.gInternal=1,this.bInternal=1,this.aInternal=1,3>t.length||"number"!=typeof t[0]){if(t.length>=1){const[i,s=1]=t;"string"==typeof i?this.setName(i,s):this.setHexRGB(i,s)}}else{const[i,s,e,r=1]=t;this.rInternal=i,this.gInternal=s,this.bInternal=e,this.aInternal=r}}get r(){return this.rInternal}get g(){return this.gInternal}get b(){return this.bInternal}get a(){return this.aInternal}set r(t){this.rInternal=t,this.emit(J.CHANGE,this)}set g(t){this.gInternal=t,this.emit(J.CHANGE,this)}set b(t){this.bInternal=t,this.emit(J.CHANGE,this)}set a(t){this.aInternal=t,this.emit(J.CHANGE,this)}set(t,i,s,e=this.aInternal){return this.rInternal=t,this.gInternal=i,this.bInternal=s,this.aInternal=e,this.emit(J.CHANGE,this),this}getHexRGBA(){return Math.round(255*this.rInternal)<<24|Math.round(255*this.gInternal)<<16|Math.round(255*this.bInternal)<<8|Math.round(255*this.aInternal)}getHexRGB(){return Math.round(255*this.rInternal)<<16|Math.round(255*this.gInternal)<<8|Math.round(255*this.bInternal)}getHSL(){const{rInternal:t,gInternal:i,bInternal:s}=this,e=Math.max(t,i,s),r=Math.min(t,i,s),n=e-r,h=(e+r)/2;let o=0;return 0!==n&&(o=e===t?(i-s)/n+(s>i?6:0):e===i?(s-t)/n+2:(t-i)/n+4,o*=60),{h:o,s:0===n?0:n/(1-Math.abs(2*h-1)),l:h}}setHexRGBA(t){return this.rInternal=(t>>16&255)/255,this.gInternal=(t>>8&255)/255,this.bInternal=(255&t)/255,this.aInternal=(t>>24&255)/255,this.emit(J.CHANGE,this),this}setHexRGB(t,i=this.aInternal){return this.rInternal=(t>>16&255)/255,this.gInternal=(t>>8&255)/255,this.bInternal=(255&t)/255,this.aInternal=i,this.emit(J.CHANGE,this),this}setHSL(t,i,s,e=this.aInternal){const r=(1-Math.abs(2*s-1))*i,n=t/60,h=r*(1-Math.abs(n%2-1));let[o,a,l]=1>n?[r,h,0]:2>n?[h,r,0]:3>n?[0,r,h]:4>n?[0,h,r]:5>n?[h,0,r]:[r,0,h];const c=s-r/2;return this.set(o+c,a+c,l+c,e)}setName(t,i=this.aInternal){const s=t.toLowerCase().trim(),e=X[s];if(void 0===e)throw Error(`Unknown color name: "${t}".`);return this.setHexRGB(e,i)}copy(t){return t instanceof Z?this.rInternal!==t.rInternal&&this.gInternal!==t.gInternal&&this.bInternal!==t.bInternal&&this.aInternal!==t.aInternal&&(this.rInternal=t.rInternal,this.gInternal=t.gInternal,this.bInternal=t.bInternal,this.aInternal=t.aInternal,this.emit(J.CHANGE,this)):this.rInternal!==t.r&&this.gInternal!==t.g&&this.bInternal!==t.b&&1!==this.aInternal&&(this.rInternal=t.r,this.gInternal=t.g,this.bInternal=t.b,this.aInternal=1,this.emit(J.CHANGE,this)),this}toCSSColor(){return`rgba(${Math.round(255*this.rInternal)}, ${Math.round(255*this.gInternal)}, ${Math.round(255*this.bInternal)}, ${this.aInternal})`}clone(){return new Z(this.rInternal,this.gInternal,this.bInternal,this.aInternal)}}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(Q||(Q={}));const K=.25,tt=new Map([[Z,"vec4"],[i,"vec3"],[o,"sampler2D"],[a,"vec2"],[l,"vec3"],[n,"vec4"],[c,"mat2"],[u,"mat3"],[f,"mat4"]]),it=new t(1,1).translate(.5,.5,0);let st=new i,et=0,rt=!1,nt=!1,ht=!1,ot=!1;class at{constructor(t,i){this.ct=new s,this.ut=new Map,this.ft=0,this.dt=new e(0,t,i,0,-1024,1024)}createPlane(t,i){const s=Object.entries(i),e=new r({uniforms:{alphaTest:{value:K},...Object.fromEntries(s.map(([t,i])=>[t,{value:i instanceof Z?new n(i.r,i.g,i.b,i.a):i}]))},vertexShader:"out vec2 io_UV;\n#include <common>\n\nvoid main() {\n #include <begin_vertex>\n io_UV = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"in vec2 io_UV;\n\nuniform float alphaTest;\n\n#include <common>\n#include <alphahash_pars_fragment>\n"+s.map(([t,i])=>((t,i)=>{if("number"==typeof i)return`uniform float ${t};`;for(const[s,e]of tt)if(i instanceof s)return`uniform ${e} ${t};`;throw Error(`Unsupported uniform type for key "${t}"`)})(t,i)).join("\n")+t,transparent:!1,alphaTest:K,alphaHash:!1,lights:!1,fog:!1,depthWrite:!1,depthTest:!0}),o=new h(it,e);o.frustumCulled=!1,o.matrixAutoUpdate=!1,this.ct.add(o);const a=this.ft++;return this.ut.set(a,{plane:o,material:e}),a}destroyPlane(t){const i=this.gt(t);return this.ct.remove(i.plane),this.ut.delete(t),this}setTransform(t,i){const s=this.gt(t);return s.plane.matrix.copy(i),s.plane.matrixWorldNeedsUpdate=!0,this}setUniform(t,i,s){const e=this.gt(t);if(!(i in e.material.uniforms))throw Error(`Uniform ${i} not found in material`);return s instanceof Z?e.material.uniforms[i].value.set(s.r,s.g,s.b,s.a):e.material.uniforms[i].value=s,this}setTransparency(t,i){const s=this.gt(t);return i===Q.BLEND?(s.material.transparent=!0,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!1):i===Q.CLIP?(s.material.transparent=!1,s.material.alphaTest=K,s.material.uniforms.alphaTest.value=K,s.material.alphaHash=!1):(s.material.transparent=!1,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!0),s.material.uniformsNeedUpdate=!0,s.material.needsUpdate=!0,this}setVisibility(t,i){return this.gt(t).plane.visible=i,this}insertCustomObject(t){return this.ct.add(t),this}removeCustomObject(t){return this.ct.remove(t),this}resize(t,i){return this.dt.right=t,this.dt.top=i,this.dt.updateProjectionMatrix(),this}render(t){return st=t.getClearColor(st),et=t.getClearAlpha(),rt=t.autoClear,nt=t.autoClearColor,ht=t.autoClearDepth,ot=t.autoClearStencil,t.autoClear=!1,t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.setClearColor(0,1),t.clear(!1,!0,!0),t.render(this.ct,this.dt),t.setClearColor(st),t.setClearAlpha(et),t.autoClear=rt,t.autoClearColor=nt,t.autoClearDepth=ht,t.autoClearStencil=ot,this}gt(t){const i=this.ut.get(t);if(!i)throw Error("No descriptor found for handler "+t);return i}}var lt,ct;function ut(t){switch(t){case lt.EQUAL:return z.Eq;case lt.LESS_THAN:return z.Le;case lt.GREATER_THAN:return z.Ge;default:throw Error("Invalid relation: "+t)}}function ft(t){return t??lt.EQUAL}(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(lt||(lt={}));class dt{constructor(){this.wt=new L,this.vt=!1,this.yt=new Map,this.bt=0,this.xt=new Map,this._t=0}createVariable(t,i){const s=this.bt++,e=new B;if(i===j.P0){const r={variable:e,priority:i,value:t};this.yt.set(s,r),r.constraint=this.It(new I(0,[[s,1]]),new I(t),lt.EQUAL,i);try{this.wt?.addConstraint(r.constraint)}catch{this.wt=void 0}}else{this.yt.set(s,{variable:e,priority:i,value:t});try{this.wt?.addEditVariable(e,G(i)),this.wt?.suggestValue(e,t)}catch{this.wt=void 0}}return this.vt=!0,s}removeVariable(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error(`Variable ${t} is used in constraint`);try{i.constraint?this.wt?.removeConstraint(i.constraint):this.wt?.removeEditVariable(i.variable)}catch{this.wt=void 0}this.yt.delete(t),this.vt=!0}suggestVariableValue(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);s.value!==i&&(s.value=i,s.constraint?s.constraint=this.Et(s.constraint,(new I).plus(t,1),new I(s.value),lt.EQUAL,s.priority):this.wt?.suggestValue(s.variable,i),this.vt=!0)}setVariablePriority(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);if(i!==s.priority){if(s.priority=i,s.priority===j.P0){const i=(new I).plus(t,1),e=new I(s.value);s.constraint=this.It(i,e,lt.EQUAL,s.priority);try{this.wt?.addConstraint(s.constraint)}catch{this.wt=void 0}}else{if(s.constraint)try{this.wt?.removeConstraint(s.constraint)}catch{this.wt=void 0}s.constraint=void 0,this.Pt(t,s)}this.vt=!0}}readVariableValue(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return void 0===this.wt&&this.Ut(),this.vt&&(this.wt?.updateVariables(),this.vt=!1),i.variable.value()}createConstraint(t,i,s,e,r){const n=this._t++,h=this.It(t,i,s,e);if(this.xt.set(n,{constraint:h,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:r}),r){try{this.wt?.addConstraint(h)}catch{this.wt=void 0}this.vt=!0}return n}removeConstraint(t){const i=this.xt.get(t);if(void 0===i)throw Error(`Constraint ${t} does not exist`);if(i.enabled)try{this.wt?.removeConstraint(i.constraint)}catch{this.wt=void 0}this.xt.delete(t),this.vt=!0}setConstraintLHS(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.lhs.copy(i),this.Ct(s),this.vt=!0}setConstraintRHS(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.rhs.copy(i),this.Ct(s),this.vt=!0}setConstraintRelation(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.relation!==i&&(s.relation=i,this.Ct(s),this.vt=!0)}setConstraintPriority(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.priority!==i&&(s.priority=i,this.Ct(s),this.vt=!0)}setConstraintEnabled(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);if(i!==s.enabled){s.enabled=i;try{s.enabled?this.wt?.addConstraint(s.constraint):this.wt?.removeConstraint(s.constraint)}catch{this.wt=void 0}this.vt=!0}}Pt(t,i){const s=[];for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.wt?.removeConstraint(i.constraint)}catch{this.wt=void 0}s.push(i)}this.wt?.removeEditVariable(i.variable),this.wt?.addEditVariable(i.variable,G(i.priority));for(const t of s)t.constraint=this.It(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.wt?.addConstraint(t.constraint)}catch{this.wt=void 0;break}}Ct(t){t.constraint=t.enabled?this.Et(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.It(t.lhs,t.rhs,t.relation,t.priority)}Et(t,i,s,e,r){try{this.wt?.removeConstraint(t)}catch{this.wt=void 0}const n=this.It(i,s,e,r);try{this.wt?.addConstraint(n)}catch{this.wt=void 0}return n}It(t,i,s,e){return new k(this.St(t),ut(s),this.St(i),G(e))}St(t){return new H(...t.prepareTermsInternal().map(([t,i])=>{const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);return[i,s.variable]}),t.constant)}Ut(){if(this.wt)throw Error("Solver already exists");this.wt=new L;for(const t of this.yt.values())t.constraint?this.wt.addConstraint(t.constraint):(this.wt.addEditVariable(t.variable,G(t.priority)),this.wt.suggestValue(t.variable,t.value));for(const t of this.xt.values())t.enabled&&this.wt.addConstraint(t.constraint);this.vt=!0}}(t=>{t.ORIENTATION_CHANGE="orientation_change",t.MODE_CHANGE="mode_change",t.WILL_RENDER="will_render"})(ct||(ct={}));class pt extends P{constructor(t,i){super(),this.name="",this.solverWrapper=new dt,this.modeInternal=U.VISIBLE,this.Mt=[],this.sceneWrapper=new at(t,i),this.xVariable=this.solverWrapper.createVariable(0,j.P0),this.yVariable=this.solverWrapper.createVariable(0,j.P0),this.wVariable=this.solverWrapper.createVariable(t,j.P0),this.hVariable=this.solverWrapper.createVariable(i,j.P0),this.orientationInternal=t>i?C.HORIZONTAL:C.VERTICAL}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get mode(){return this.modeInternal}get orientation(){return this.orientationInternal}set mode(t){t!==this.modeInternal&&(this.modeInternal=t,this.emit(ct.MODE_CHANGE,this.modeInternal,this))}resizeInternal(t,i){this.solverWrapper.suggestVariableValue(this.wVariable,t),this.solverWrapper.suggestVariableValue(this.hVariable,i),this.sceneWrapper.resize(t,i);const s=t>i?C.HORIZONTAL:C.VERTICAL;s!==this.orientationInternal&&(this.orientationInternal=s,this.emit(ct.ORIENTATION_CHANGE,this.orientationInternal,this))}renderInternal(t,i){this.mode!==U.HIDDEN&&(this.emit(ct.WILL_RENDER,t,i,this),this.sceneWrapper.render(t))}onPointerDownInternal(t,i,s){this.Tt(t,i,"catchPointerDown",s)}onPointerMoveInternal(t,i,s){this.Tt(t,i,"catchPointerMove",s)}onPointerUpInternal(t,i,s){this.Tt(t,i,"catchPointerUp",s)}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperClientAPI(){return this.sceneWrapper}subscribePointerInput(t){if(this.Mt.find(i=>i===t))throw Error("Listener already exists");this.Mt.push(t)}unsubscribePointerInput(t){const i=this.Mt.findIndex(i=>i===t);if(-1===i)throw Error("Listener not found");this.Mt.splice(i,1)}Tt(t,i,s,e){if(this.mode===U.INTERACTIVE){this.Mt.sort((t,i)=>i.zIndex-t.zIndex);for(const r of this.Mt)if(r[s](t,i,e))return}}}class gt{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal()}}class wt extends gt{constructor(t,i,s,e){super(t),this.Vt=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.priorityInternal=Y(i),this.relationInternal=ft(s),this.orientationInternal=S(e),this.layer.on(ct.ORIENTATION_CHANGE,this.Vt)}get priority(){return this.priorityInternal}get relation(){return this.relationInternal}get orientation(){return this.orientationInternal}set priority(t){t!==this.priorityInternal&&(this.priorityInternal=t,this.solverWrapper.setConstraintPriority(this.constraint,this.priorityInternal))}set relation(t){t!==this.relationInternal&&(this.relationInternal=t,this.solverWrapper.setConstraintRelation(this.constraint,this.relationInternal))}set orientation(t){t!==this.orientationInternal&&(this.orientationInternal=t,this.Vt())}destroy(){this.layer.off(ct.ORIENTATION_CHANGE,this.Vt),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===C.ALWAYS||this.orientationInternal===this.layer.orientation}}class mt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Bt=t,this.At=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new I(0,[[this.Bt.hVariable,1]]),new I(this.At),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.At}set height(t){this.At!==t&&(this.At=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(t)))}}function vt(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof pt}function yt(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 bt(t){return"object"==typeof t&&null!==t&&"wVariable"in t&&"number"==typeof t.wVariable&&"hVariable"in t&&"number"==typeof t.hVariable&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height}function xt(t,i,s){if(t instanceof pt&&i instanceof pt)throw Error(s+": layer cannot be snapped to another layer");let e,r;if(!(t instanceof pt||vt(t)))throw Error(s+": A must be a UILayer or a UIPointElement");if(e=t instanceof pt?t:t.layer,!(i instanceof pt||vt(i)))throw Error(s+": B must be a UILayer or a UIPointElement");if(r=i instanceof pt?i:i.layer,e!==r)throw Error(s+": elements must be on the same layer");return e}function _t(t,i){if(!Number.isFinite(t))throw Error(i+": value must be a finite number");if(Math.abs(t)>Number.MAX_SAFE_INTEGER)throw Error(i+": value exceeds maximum safe integer range")}function It(t,i){if(_t(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function Et(t,i){if(_t(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class Pt extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalDistanceConstraint"),s.priority,s.relation,s.orientation),this.Ht=t,this.Rt=i,this.zt=s.anchorA??.5,this.kt=s.anchorB??.5,this.$t=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Lt(),new I(this.$t),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.$t}get anchorA(){return this.zt}get anchorB(){return this.kt}set distance(t){this.$t!==t&&(this.$t=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(this.$t)))}set anchorA(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Lt()))}set anchorB(t){this.kt!==t&&(this.kt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Lt()))}Lt(){let t,i;if(bt(this.Ht))t=new I(0,[[this.Ht.xVariable,1],[this.Ht.wVariable,this.zt]]);else{if(!yt(this.Ht))throw Error("A is not a valid element type");t=(new I).plus(this.Ht.xVariable,1)}if(bt(this.Rt))i=new I(0,[[this.Rt.xVariable,1],[this.Rt.wVariable,this.kt]]);else{if(!yt(this.Rt))throw Error("B is not a valid element type");i=(new I).plus(this.Rt.xVariable,1)}return I.minus(i,t)}}class Ut extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalProportionConstraint"),s.priority,s.relation,s.orientation),this.Ht=t,this.Rt=i,this.Wt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new I(0),this.Ft(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Wt}set proportion(t){this.Wt!==t&&(this.Wt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Ft()))}Ft(){return I.minus(new I(0,[[this.Ht.wVariable,this.Wt]]),new I(0,[[this.Rt.wVariable,1]]))}}class Ct extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalDistanceConstraint"),s.priority,s.relation,s.orientation),this.Ht=t,this.Rt=i,this.zt=s.anchorA??.5,this.kt=s.anchorB??.5,this.$t=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Lt(),new I(this.$t),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.$t}get anchorA(){return this.zt}get anchorB(){return this.kt}set distance(t){this.$t!==t&&(this.$t=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(this.$t)))}set anchorA(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Lt()))}set anchorB(t){this.kt!==t&&(this.kt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Lt()))}Lt(){let t,i;if(bt(this.Ht))t=new I(0,[[this.Ht.yVariable,1],[this.Ht.hVariable,this.zt]]);else{if(!yt(this.Ht))throw Error("A is not a valid element type");t=(new I).plus(this.Ht.yVariable,1)}if(bt(this.Rt))i=new I(0,[[this.Rt.yVariable,1],[this.Rt.hVariable,this.kt]]);else{if(!yt(this.Rt))throw Error("B is not a valid element type");i=(new I).plus(this.Rt.yVariable,1)}return I.minus(i,t)}}class St extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalProportionConstraint"),s.priority,s.relation,s.orientation),this.Ht=t,this.Rt=i,this.Wt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new I(0),this.Ft(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Wt}set proportion(t){this.Wt!==t&&(this.Wt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Ft()))}Ft(){return I.minus(new I(0,[[this.Ht.hVariable,this.Wt]]),new I(0,[[this.Rt.hVariable,1]]))}}class Mt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Bt=t,this.Dt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new I(0,[[this.Bt.wVariable,1]]),new I(this.Dt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Dt}set width(t){this.Dt!==t&&(this.Dt=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(t)))}}class Tt{static size(t,i={}){return{h:new Mt(t,{width:i.size?.h,priority:i.priority?.h,relation:i.relation?.h,orientation:i.orientation?.h}),v:new mt(t,{height:i.size?.v,priority:i.priority?.v,relation:i.relation?.v,orientation:i.orientation?.v})}}static distance(t,i,s={}){return{h:new Pt(t,i,{anchorA:s.anchorA?.h,anchorB:s.anchorB?.h,distance:s.distance?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new Ct(t,i,{anchorA:s.anchorA?.v,anchorB:s.anchorB?.v,distance:s.distance?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}static proportion(t,i,s={}){return{h:new Ut(t,i,{proportion:s.proportion?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new St(t,i,{proportion:s.proportion?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}}class Vt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Bt=t,this.Nt=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Lt(),new I(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Nt}set aspect(t){this.Nt!==t&&(this.Nt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Lt()))}Lt(){return new I(0,[[this.Bt.wVariable,1],[this.Bt.hVariable,-this.Nt]])}}const Bt=.5;class At{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Pt(t,i,{anchorA:s.anchorH??Bt,anchorB:s.anchorH??Bt,orientation:s.orientation}),yConstraint:new Ct(t,i,{anchorA:s.anchorV??Bt,anchorB:s.anchorV??Bt,orientation:s.orientation}),widthConstraint:new Ut(t,i,{proportion:1,relation:lt.GREATER_THAN,orientation:s.orientation}),heightConstraint:new St(t,i,{proportion:1,priority:j.P1,orientation:s.orientation})}}}const Ht=.5;class Rt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Pt(t,i,{anchorA:s.anchorH??Ht,anchorB:s.anchorH??Ht,orientation:s.orientation}),yConstraint:new Ct(t,i,{anchorA:s.anchorV??Ht,anchorB:s.anchorV??Ht,orientation:s.orientation}),widthConstraint:new Ut(t,i,{proportion:1,relation:lt.LESS_THAN,orientation:s.orientation}),heightConstraint:new St(t,i,{proportion:1,priority:j.P1,orientation:s.orientation})}}}class zt extends wt{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Ot=i,this.qt=s,this.constraint=this.solverWrapper.createConstraint(this.Ot,this.qt,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Ot}get rhs(){return this.qt}setLHS(t){this.Ot=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ot)}setRHS(t){this.qt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.qt)}}class kt extends P{constructor(t,i,s){_t(i,"UIAnchor x"),_t(s,"UIAnchor y"),super(),this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal(),this.xVariable=this.solverWrapper.createVariable(i,j.P7),this.yVariable=this.solverWrapper.createVariable(s,j.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){_t(t,"UIAnchor x"),this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){_t(t,"UIAnchor y"),this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}var $t,Lt,Wt,Ft="void main() {\n vec2 transformedUV = (uvTransform * vec3(io_UV, 1.0)).xy;\n vec4 diffuseColor = texture(map, transformedUV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";(t=>{t.DOWN="pointerdown",t.MOVE="pointermove",t.UP="pointerup",t.ENTER="pointerenter",t.LEAVE="pointerleave"})($t||($t={})),(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(Lt||(Lt={})),(t=>{t[t.CHANGE=0]="CHANGE"})(Wt||(Wt={}));const Dt=.5;class Nt extends P{constructor(){super(...arguments),this.jt=0,this.Gt=0,this.Yt=Dt,this.Xt=Dt,this.Jt=1,this.Qt=1,this.Zt=0,this.Kt=Lt.ROTATION_SCALE,this.vt=!1}get x(){return this.jt}get y(){return this.Gt}get anchorX(){return this.Yt}get anchorY(){return this.Xt}get scaleX(){return this.Jt}get scaleY(){return this.Qt}get size(){return Math.max(this.Jt,this.Qt)}get angle(){return d.radToDeg(this.Zt)}get anchorMode(){return this.Kt}get rotation(){return this.Zt}set x(t){t!==this.jt&&(this.jt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set y(t){t!==this.Gt&&(this.Gt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set anchorX(t){t!==this.Yt&&(this.Yt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set anchorY(t){t!==this.Xt&&(this.Xt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set scaleX(t){t!==this.Jt&&(this.Jt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set scaleY(t){t!==this.Qt&&(this.Qt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set size(t){t===this.Jt&&t===this.Qt||(this.Jt=t,this.Qt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set angle(t){const i=d.degToRad(t);i!==this.Zt&&(this.Zt=i,this.vt=!0,this.emit(Wt.CHANGE,this))}set rotation(t){t!==this.Zt&&(this.Zt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}set anchorMode(t){t!==this.Kt&&(this.Kt=t,this.vt=!0,this.emit(Wt.CHANGE,this))}reset(){0===this.jt&&0===this.Gt&&this.Yt===Dt&&this.Xt===Dt&&1===this.Jt&&1===this.Qt&&0===this.Zt||(this.jt=0,this.Gt=0,this.Yt=Dt,this.Xt=Dt,this.Jt=1,this.Qt=1,this.Zt=0,this.vt=!0,this.emit(Wt.CHANGE,this))}copy(t){this.jt!==t.jt&&this.Gt!==t.Gt&&this.Yt!==t.Yt&&this.Xt!==t.Xt&&this.Jt!==t.Jt&&this.Qt!==t.Qt&&this.Zt!==t.Zt&&this.Kt!==t.Kt&&(this.jt=t.jt,this.Gt=t.Gt,this.Yt=t.Yt,this.Xt=t.Xt,this.Jt=t.Jt,this.Qt=t.Qt,this.Zt=t.Zt,this.Kt=t.Kt,this.emit(Wt.CHANGE,this),this.vt=!0)}getRecalculationRequiredInternal(){return this.vt}resetRecalculationRequiredInternal(){this.vt=!1}}const Ot=new l,qt=new p,jt=new l,Gt=new f,Yt=new l(0,0,1);class Xt extends kt{constructor(t,i,s,e,r,n,h){It(e,"UIElement width"),It(r,"UIElement height"),super(t,i,s),this.micro=new Nt,this.modeInternal=U.VISIBLE,this.transparencyInternal=Q.BLEND,this.zIndexInternal=0,this.isPointerInside=!1,this.catchPointerDown=(t,i,s)=>this.handleInputEvent(t,i,s,$t.DOWN),this.catchPointerMove=(t,i,s)=>this.handleInputEvent(t,i,s,$t.MOVE),this.catchPointerUp=(t,i,s)=>this.handleInputEvent(t,i,s,$t.UP),this.layer.on(ct.WILL_RENDER,this.onWillRender,this),this.wVariable=this.solverWrapper.createVariable(e,j.P6),this.hVariable=this.solverWrapper.createVariable(r,j.P6),this.sceneWrapper=t.getSceneWrapperClientAPI(),this.planeHandler=this.sceneWrapper.createPlane(n,h),this.sceneWrapper.setTransparency(this.planeHandler,this.transparencyInternal)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get zIndex(){return this.zIndexInternal}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 transparency(){return this.transparencyInternal}set width(t){It(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){It(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){_t(t,"UIElement zIndex"),this.zIndexInternal=t,this.listener&&(this.listener.zIndex=this.zIndexInternal)}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){this.modeInternal!==t&&(t===U.INTERACTIVE?(this.listener={catchPointerDown:this.catchPointerDown,catchPointerMove:this.catchPointerMove,catchPointerUp:this.catchPointerUp,zIndex:this.zIndexInternal},this.layer.subscribePointerInput(this.listener)):this.modeInternal===U.INTERACTIVE&&this.listener&&(this.layer.unsubscribePointerInput(this.listener),this.listener=void 0),this.modeInternal=t,this.sceneWrapper.setVisibility(this.planeHandler,t!==U.HIDDEN))}set transparency(t){this.transparencyInternal=t,this.sceneWrapper.setTransparency(this.planeHandler,t)}destroy(){this.layer.off(ct.WILL_RENDER,this.onWillRender,this),this.listener&&this.layer.unsubscribePointerInput(this.listener),this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}handleInputEvent(t,i,s,e){const r=t>this.x&&this.oppositeX>t&&i>this.y&&this.oppositeY>i;return r&&this.emit(e,t,i,s,this),this.isPointerInside&&!r?this.emit($t.LEAVE,t,i,s,this):!this.isPointerInside&&r&&this.emit($t.ENTER,t,i,s,this),this.isPointerInside=r,r}onWillRender(t,i){const s=this.micro,e=this.width*s.scaleX,r=this.height*s.scaleY,n=s.anchorX*e,h=s.anchorY*r,o=Math.cos(s.rotation),a=Math.sin(s.rotation),l=n*o-h*a,c=n*a+h*o;if(s.anchorMode===Lt.POSITION_ROTATION_SCALE)Ot.x=this.x+s.x-l,Ot.y=this.y+s.y-c;else{const t=s.anchorY*this.height;Ot.x=this.x+s.anchorX*this.width-l+s.x,Ot.y=this.y+t-c+s.y}Ot.z=this.zIndexInternal,jt.x=e,jt.y=r,qt.setFromAxisAngle(Yt,s.rotation),Gt.compose(Ot,qt,jt),this.sceneWrapper.setTransform(this.planeHandler,Gt)}}var Jt;(t=>{t[t.PLAY=0]="PLAY",t[t.PAUSE=1]="PAUSE",t[t.STOP=2]="STOP"})(Jt||(Jt={}));class Qt extends Xt{constructor(t,i,s={}){const e=s.width??100,r=s.height??100,n=s.color??new Z;let h;h=Array.isArray(i)?i.map(t=>(t.updateMatrix(),{texture:t,uvTransform:t.matrix})):i.transforms.map(t=>({texture:i.texture,uvTransform:t})),super(t,s.x??0,s.y??0,e,r,Ft,{map:h[0].texture,uvTransform:h[0].uvTransform,color:n}),this.ti=void 0,this.ii=0,this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ei=h,this.ri=n,this.ni=s.frameRate??24,this.hi=s.loop??!0,this.ri.on(J.CHANGE,this.si)}get color(){return this.ri}get frameRate(){return this.ni}get loop(){return this.hi}get duration(){return this.ei.length/this.ni}set color(t){this.ri.copy(t)}set frameRate(t){if(0>=t)throw Error("Frame rate must be greater than zero");const i=void 0!==this.ti;i&&this.pause(),this.ni=t,i&&this.play()}set loop(t){this.hi=t}play(){void 0===this.ti&&(this.ti=setInterval(()=>{if(this.ii++,this.hi)this.ii%=this.ei.length;else if(this.ii>=this.ei.length)return this.ii=this.ei.length-1,void this.pause();this.oi()},1e3/this.ni),this.emit(Jt.PLAY))}pause(){void 0!==this.ti&&(clearInterval(this.ti),this.ti=void 0,this.emit(Jt.PAUSE))}stop(){void 0!==this.ti&&(clearInterval(this.ti),this.ti=void 0),this.ii=0,this.oi(),this.emit(Jt.STOP)}destroy(){this.stop(),this.ri.off(J.CHANGE,this.si),super.destroy()}oi(){const t=this.ei[this.ii];this.sceneWrapper.setUniform(this.planeHandler,"map",t.texture),this.sceneWrapper.setUniform(this.planeHandler,"uvTransform",t.uvTransform)}}class Zt extends kt{constructor(t,i={}){const s=i.x??0,e=i.y??0,r=i.width??100,n=i.height??100;It(r,"UIDummy width"),It(n,"UIDummy height"),super(t,s,e),this.wVariable=this.solverWrapper.createVariable(r,j.P6),this.hVariable=this.solverWrapper.createVariable(n,j.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){It(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){It(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}class Kt extends Xt{constructor(t,i={}){const s=i.width??512,e=i.height??512,r=i.color??new Z,n=new OffscreenCanvas(s,e),h=n.getContext("2d");if(!h)throw Error("Failed to get 2D context from OffscreenCanvas");const o=new g(n);o.minFilter=w,o.magFilter=w,super(t,i.x??0,i.y??0,s,e,Ft,{map:o,uvTransform:o.matrix,color:r}),this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ai=n,this.li=h,this.ci=o,this.ri=r,this.ri.on(J.CHANGE,this.si),void 0!==i.mode&&(this.mode=i.mode)}get color(){return this.ri}set color(t){this.ri.copy(t)}clear(t){return this.li.clearRect(0,0,this.ai.width,this.ai.height),void 0!==t&&(this.li.fillStyle=t.toCSSColor(),this.li.fillRect(0,0,this.ai.width,this.ai.height)),this.ci.needsUpdate=!0,this}rect(t,i,s,e){return this.li.rect(t,i,s,e),this.ci.needsUpdate=!0,this}fillRect(t,i,s,e){return this.li.fillRect(t,i,s,e),this.ci.needsUpdate=!0,this}strokeRect(t,i,s,e){return this.li.strokeRect(t,i,s,e),this.ci.needsUpdate=!0,this}circle(t,i,s){return this.li.beginPath(),this.li.arc(t,i,s,0,2*Math.PI),this.li.closePath(),this.ci.needsUpdate=!0,this}beginPath(){return this.li.beginPath(),this.ci.needsUpdate=!0,this}closePath(){return this.li.closePath(),this.ci.needsUpdate=!0,this}fill(){return this.li.fill(),this.ci.needsUpdate=!0,this}stroke(){return this.li.stroke(),this.ci.needsUpdate=!0,this}moveTo(t,i){return this.li.moveTo(t,i),this}lineTo(t,i){return this.li.lineTo(t,i),this.ci.needsUpdate=!0,this}setFillStyle(t){return this.li.fillStyle=t instanceof Z?t.toCSSColor():t,this}setStrokeStyle(t){return this.li.strokeStyle=t instanceof Z?t.toCSSColor():t,this}setLineWidth(t){return this.li.lineWidth=t,this}destroy(){this.ri.off(J.CHANGE,this.si),this.ci.dispose(),super.destroy()}}class ti extends Xt{constructor(t,i,s={}){const e=s.width??i.image.width,r=s.height??i.image.height,n=s.color??new Z;super(t,s.x??0,s.y??0,e,r,Ft,{map:i,uvTransform:i.matrix,color:n}),this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ui=i,this.ri=n,this.ri.on(J.CHANGE,this.si),void 0!==s.mode&&(this.mode=s.mode)}get texture(){return this.ui}get color(){return this.ri}set texture(t){const i=t.image.width,s=t.image.height;It(i,"UIImage texture width"),It(s,"UIImage texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ui=t,this.sceneWrapper.setUniform(this.planeHandler,"map",t),this.sceneWrapper.setUniform(this.planeHandler,"uvTransform",t.matrix)}set color(t){this.ri.copy(t)}destroy(){this.ri.off(J.CHANGE,this.si),super.destroy()}}const ii=.25;class si extends Xt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,h=s.color??new Z,o=(t=>{if(null==t)return{l:ii,r:ii,t:ii,b:ii};if("number"==typeof t)return{l:t,r:t,t,b:t};if("object"==typeof t){if("horizontal"in t&&"vertical"in t){const i="number"==typeof t.horizontal?t.horizontal:ii,s="number"==typeof t.vertical?t.vertical:ii;return{l:i,r:i,t:s,b:s}}return{l:"number"==typeof t.left?t.left:ii,r:"number"==typeof t.right?t.right:ii,t:"number"==typeof t.top?t.top:ii,b:"number"==typeof t.bottom?t.bottom:ii}}return{l:ii,r:ii,t:ii,b:ii}})(s.sliceBorders),a=new n(o.l,o.r,o.t,o.b),l=new n(e,r,e,r);super(t,s.x??0,s.y??0,e,r,"vec2 calculateNineSliceUV() {\n vec2 localUV = io_UV;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * dimensions.x;\n float rightPx = right * dimensions.x;\n float topPx = top * dimensions.y;\n float bottomPx = bottom * dimensions.y;\n\n float lB = leftPx / dimensions.z;\n float rB = 1.0 - (rightPx / dimensions.z);\n float tB = topPx / dimensions.w;\n float bB = 1.0 - (bottomPx / dimensions.w);\n\n {\n float regionL = step(io_UV.x, lB);\n float regionR = step(rB, io_UV.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = io_UV.x * (left / lB);\n float xR = 1.0 - right + ((io_UV.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((io_UV.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(io_UV.y, tB);\n float regionB = step(bB, io_UV.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = io_UV.y * (top / tB);\n float yB = 1.0 - bottom + ((io_UV.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((io_UV.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 diffuseColor = texture(map, calculateNineSliceUV()) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n",{map:i,color:h,sliceBorders:a,dimensions:l}),this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ui=i,this.fi=a,this.di=l,this.ri=h,this.ri.on(J.CHANGE,this.si),void 0!==s.mode&&(this.mode=s.mode)}get texture(){return this.ui}get color(){return this.ri}get sliceBorderLeft(){return this.fi.x}get sliceBorderRight(){return this.fi.y}get sliceBorderTop(){return this.fi.z}get sliceBorderBottom(){return this.fi.w}set texture(t){const i=t.image.width,s=t.image.height;It(i,"UINineSlice texture width"),It(s,"UINineSlice texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.di.x=i,this.di.y=s,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.di),this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ri.copy(t)}set sliceBorderLeft(t){this.fi.x=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.fi)}set sliceBorderRight(t){this.fi.y=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.fi)}set sliceBorderTop(t){this.fi.z=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.fi)}set sliceBorderBottom(t){this.fi.w=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.fi)}setSliceBorders(t,i,s,e){this.fi.set(t,i,s,e),this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.fi)}destroy(){this.ri.off(J.CHANGE,this.si),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.di.z=this.width*this.micro.scaleX,this.di.w=this.height*this.micro.scaleY,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.di)}}const ei=new o;var ri,ni;(t=>{t.HORIZONTAL="float calculateMask() {\n return step((direction * io_UV.x + (1.0 - direction) * 0.5), progress);\n }",t.VERTICAL="float calculateMask() {\n return step((direction * io_UV.y + (1.0 - direction) * 0.5), progress);\n }",t.DIAGONAL="float calculateMask() {\n float d = (io_UV.x + io_UV.y) * (0.1);\n return step((direction * d + (1.0 - direction) * 0.5), progress);\n }",t.CIRCLE_LEFT="float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / 3.14159265;\n angle *= 0.5;\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }",t.CIRCLE_TOP="float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / (2.0 * 3.14159265);\n angle = mod(angle + 0.25, 1.0);\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }"})(ri||(ri={}));class hi extends Xt{constructor(t,i,s={}){const e=i.image?.width,r=i.image?.height;It(e,"UIProgress foreground texture width"),It(r,"UIProgress foreground texture height"),s.backgroundTexture&&(It(s.backgroundTexture.image.width,"UIProgress background texture width"),It(s.backgroundTexture.image.height,"UIProgress background texture height"));const n=s.color??new Z,h=s.foregroundColor??new Z,o=s.backgroundColor??new Z,a=s.progress??1,l=s.inverseDirection??!1;super(t,s.x??0,s.y??0,e,r,(s.maskFunction??ri.HORIZONTAL)+"void main() {\n vec4 foregroundDiffuseColor = texture(foregroundTexture, io_UV) * foregroundColor * color;\n vec4 backgroundDiffuseColor = texture(backgroundTexture, io_UV) * backgroundColor * color;\n\n float mask = calculateMask();\n vec4 diffuseColor = foregroundDiffuseColor * mask\n + backgroundDiffuseColor * (1.0 - foregroundDiffuseColor.a * mask);\n\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n",{foregroundTexture:i,backgroundTexture:s.backgroundTexture??ei,color:n,foregroundColor:h,backgroundColor:o,progress:a,direction:l?-1:1}),this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.pi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"foregroundColor",t)},this.gi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"backgroundColor",t)},this.wi=i,this.mi=s.backgroundTexture,this.ri=n,this.yi=h,this.bi=o,this.xi=a,this._i=l,this.ri.on(J.CHANGE,this.si),this.yi.on(J.CHANGE,this.pi),this.bi.on(J.CHANGE,this.gi),void 0!==s.mode&&(this.mode=s.mode)}get foregroundTexture(){return this.wi}get backgroundTexture(){return this.mi}get color(){return this.ri}get foregroundColor(){return this.yi}get backgroundColor(){return this.bi}get progress(){return this.xi}get inverseDirection(){return this._i}set foregroundTexture(t){const i=t.image.width,s=t.image.height;It(i,"UIProgress foreground texture width"),It(s,"UIProgress foreground texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.wi=t,this.sceneWrapper.setUniform(this.planeHandler,"foregroundTexture",t)}set backgroundTexture(t){void 0!==t&&(It(t.image.width,"UIProgress background texture width"),It(t.image.height,"UIProgress background texture height")),this.mi=t,this.sceneWrapper.setUniform(this.planeHandler,"backgroundTexture",t)}set color(t){this.ri.copy(t)}set foregroundColor(t){this.yi.copy(t)}set backgroundColor(t){this.bi.copy(t)}set inverseDirection(t){this._i=t,this.sceneWrapper.setUniform(this.planeHandler,"direction",t?-1:1)}set progress(t){this.xi=t,this.sceneWrapper.setUniform(this.planeHandler,"progress",t)}destroy(){this.ri.off(J.CHANGE,this.si),this.yi.off(J.CHANGE,this.pi),this.bi.off(J.CHANGE,this.gi),super.destroy()}}(t=>{t[t.EACH_FRAME=1]="EACH_FRAME",t[t.EACH_SECOND_FRAME=2]="EACH_SECOND_FRAME",t[t.PROPERTY_CHANGED=3]="PROPERTY_CHANGED",t[t.MANUAL=4]="MANUAL"})(ni||(ni={}));const oi=ni.PROPERTY_CHANGED;class ai extends Xt{constructor(t,i={}){const e=i.resolutionFactor??.5;if(.1>e||e>2)throw Error(`Invalid resolution factor: ${e}. Must be between 0.1 and 2.`);const r=i.width??512,n=i.height??512,h=new m(r*e,n*e,{format:y,minFilter:w,magFilter:w,type:v,depthBuffer:i.enableDepthBuffer??!0,stencilBuffer:!1}),o=i.color??new Z;super(t,0,0,r,n,Ft,{map:h.texture,uvTransform:new u,color:o}),this.Ii=!0,this.Ei=!1,this.Pi=!1,this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.Ui=h,this.Ci=i.scene??new s,this.Si=i.camera??new b(75,r/n,.1,100),this.Mi=e,this.Ti=i.updateMode??oi,this.Vi=i.clearColor??0,this.Bi=i.clearAlpha??0,i.updateMode===ni.PROPERTY_CHANGED&&(this.Pi=!0),this.ri=o,this.ri.on(J.CHANGE,this.si),void 0!==i.mode&&(this.mode=i.mode)}get color(){return this.ri}get scene(){return this.Ci}get camera(){return this.Si}get updateMode(){return this.Ti}get resolutionFactor(){return this.Mi}get clearColor(){return this.Vi}get clearAlpha(){return this.Bi}set color(t){this.ri.copy(t)}set scene(t){this.Ci!==t&&(this.Ci=t,this.Ei=!0)}set camera(t){this.Si!==t&&(this.Si=t,this.Ei=!0)}set updateMode(t){this.Ti!==t&&(this.Ti=t,this.Ei=!0)}set resolutionFactor(t){this.Mi!==t&&(this.Mi=t,this.Ui.setSize(this.width*this.Mi,this.height*this.Mi),this.Ei=!0)}set clearColor(t){this.Vi!==t&&(this.Vi=t,this.Ei=!0)}set clearAlpha(t){this.Bi!==t&&(this.Bi=t,this.Ei=!0)}destroy(){this.ri.off(J.CHANGE,this.si),this.Ui.dispose(),super.destroy()}requestRender(){this.Pi=!0}onWillRender(t){(this.Ti===ni.EACH_FRAME||this.Ti===ni.EACH_SECOND_FRAME&&this.Ii||this.Ti===ni.PROPERTY_CHANGED&&this.Ei||this.Ti===ni.MANUAL&&this.Pi)&&(this.Pi=!1,this.Ei=!1,this.Ii=!this.Ii,this.Ui.setSize(this.width*this.Mi,this.height*this.Mi),t.setClearColor(this.Vi,this.clearAlpha),t.setRenderTarget(this.Ui),t.clear(!0,!0,!1),t.render(this.Ci,this.Si))}}function li(t){return"object"==typeof t&&null!==t&&!("string"!=typeof t.color||"left"!==t.align&&"center"!==t.align&&"right"!==t.align||"string"!=typeof t.fontFamily||"number"!=typeof t.fontSize||"normal"!==t.fontStyle&&"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||"normal"!==t.fontWeight&&"bold"!==t.fontWeight&&"bolder"!==t.fontWeight&&"lighter"!==t.fontWeight&&"number"!=typeof t.fontWeight||"number"!=typeof t.lineHeight||"boolean"!=typeof t.enableShadow||"number"!=typeof t.shadowOffsetX||"number"!=typeof t.shadowOffsetY||"number"!=typeof t.shadowBlur||"string"!=typeof t.shadowColor||"boolean"!=typeof t.enableStroke||"string"!=typeof t.strokeColor||"number"!=typeof t.strokeWidth)}const ci={color:"#000000",align:"left",fontFamily:"Arial",fontSize:16,fontStyle:"normal",fontWeight:"normal",lineHeight:1.2,enableShadow:!1,shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,shadowColor:"transparent",enableStroke:!1,strokeColor:"#000000",strokeWidth:0};function ui(t,i){const s=t?.fontSize??i?.fontSize??16;It(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&It(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;_t(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;Et(n,"Shadow offset X");const h=t?.shadowOffsetY??i?.shadowOffsetY??0;Et(h,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;Et(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return Et(a,"Stroke width"),{color:t?.color??i?.color??ci.color,align:t?.align??i?.align??"left",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize:s,fontStyle:t?.fontStyle??i?.fontStyle??"normal",fontWeight:e,lineHeight:r,enableShadow:t?.enableShadow??i?.enableShadow??!1,shadowOffsetX:n,shadowOffsetY:h,shadowBlur:o,shadowColor:t?.shadowColor??i?.shadowColor??"transparent",enableStroke:t?.enableStroke??i?.enableStroke??!1,strokeColor:t?.strokeColor??i?.strokeColor??"#000000",strokeWidth:a}}function fi(t){return t.match(/\S+|\s|\n/g)??[]}function di(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 pi(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}}function gi(t,i,s,e,r){r.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px ${e.fontFamily}`,e.enableShadow&&(r.shadowOffsetX=e.shadowOffsetX,r.shadowOffsetY=e.shadowOffsetY,r.shadowBlur=e.shadowBlur,r.shadowColor=e.shadowColor),e.enableStroke&&(r.strokeStyle=e.strokeColor,r.lineWidth=e.strokeWidth,r.strokeText(s,t,i)),r.fillStyle=e.color,r.fillText(s,t,i)}function wi(t){if("number"==typeof t)return{left:t,right:t,top:t,bottom:t};if("object"==typeof t&&null!==t){const i="left"in t&&"number"==typeof t.left?t.left:0,s="right"in t&&"number"==typeof t.right?t.right:0,e="top"in t&&"number"==typeof t.top?t.top:0,r="bottom"in t&&"number"==typeof t.bottom?t.bottom:0;return Et(i,"Padding left"),Et(s,"Padding right"),Et(e,"Padding top"),Et(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class mi extends Xt{constructor(t,i,s={}){const e=new OffscreenCanvas(2,2),r=e.getContext("2d");if(!r)throw Error("UIText failed to create canvas context");const n=new g(e),h=s.color??new Z;super(t,s.x??0,s.y??0,2,2,Ft,{map:n,uvTransform:new u,color:h}),this.Ai=1,this.si=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ai=e,this.Hi=r,this.Ri=n,this.zi=i,this.ki=s.maxWidth??1024,this.$i=wi(s.padding),this.Li=s.commonStyle??{},this.ri=h,this.ri.on(J.CHANGE,this.si),this.Wi(),void 0!==s.mode&&(this.mode=s.mode)}get color(){return this.ri}get content(){return this.zi}get maxWidth(){return this.ki}get padding(){return this.$i}get commonStyle(){return this.Li}set color(t){this.ri.copy(t)}set content(t){this.zi=t,this.Wi()}set maxWidth(t){this.ki=t,this.Wi()}set padding(t){this.$i=t,this.Wi()}set commonStyle(t){this.Li=t,this.Wi()}destroy(){this.ri.off(J.CHANGE,this.si),this.Ri.dispose(),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.Ai!==this.width/this.height&&(this.height=this.width/this.Ai)}Wi(){const{lines:t,size:i}=((t,i,s,e)=>{const r=[];for(const s of Array.isArray(i)?i:[i]){const i="string"==typeof s,n=i?s:s.text,h=ui(i?void 0:s.style,e);for(const i of fi(n)){const s=di(t,i,h);r.push({text:i,style:h,metrics:s})}}const n=((t,i)=>{const s=[];let e=[],r=0,n=0,h=0,o=0;for(const a of i)"\n"!==a.text?r+a.metrics.width>t&&0!==e.length?(s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[a],r=a.metrics.width,n=a.metrics.height,h=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),r+=a.metrics.width,n=Math.max(n,a.metrics.height),h=Math.max(h,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[],r=0,n=0,h=0,o=0);return e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),s})(s,r);return{lines:n,size:pi(n)}})(this.Hi,this.content,this.ki,this.Li);this.ai.width=i.width+this.$i.left+this.$i.right,this.ai.height=i.height+this.$i.top+this.$i.bottom,this.width=this.ai.width,this.height=this.ai.height,this.Ai=this.ai.width/this.ai.height,((t,i,s,e)=>{let r=this.$i.top,n=0;for(const t of s)n=Math.max(t.width,n);for(let t=0;s.length>t;t++){const h=s[t],o=h.chunks[0]?.style.align??"left",a=h.chunks.every(t=>t.style.align===o)?o:"left";let l=0;"center"===a?l=(n-h.width)/2:"right"===a&&(l=n-h.width);let c=i+l;r+=0===t?h.height:h.lineHeight;for(const t of h.chunks)gi(c,r,t.text,t.style,e),c+=t.metrics.width}})(0,this.$i.left,t,this.Hi),this.Ri.dispose(),this.Ri=new g(this.ai),this.Ri.needsUpdate=!0,this.sceneWrapper.setUniform(this.planeHandler,"map",this.Ri)}}var vi;(t=>{t[t.CHANGE=0]="CHANGE"})(vi||(vi={}));class yi extends P{}class bi extends yi{calculateScaleInternal(t,i){return 1}}class xi extends pt{constructor(t=new bi,i=U.VISIBLE){super(window.innerWidth,window.innerHeight),this.Fi=()=>{const t=this.Di.calculateScaleInternal(window.innerWidth,window.innerHeight);this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Ni=t=>{this.Oi(t,"onPointerDownInternal",$t.DOWN)},this.qi=t=>{this.Oi(t,"onPointerMoveInternal",$t.MOVE)},this.ji=t=>{this.Oi(t,"onPointerUpInternal",$t.UP)},window.addEventListener("resize",this.Fi),window.addEventListener("pointerdown",this.Ni),window.addEventListener("pointermove",this.qi),window.addEventListener("pointerup",this.ji),this.mode=i,this.Di=t,this.Di.on(vi.CHANGE,this.Fi),this.Fi()}get resizePolicy(){return this.Di}set resizePolicy(t){this.Di!==t&&(this.Di.off(vi.CHANGE,this.Fi),this.Di=t,this.Di.on(vi.CHANGE,this.Fi),this.Fi())}destroy(){window.removeEventListener("resize",this.Fi),window.removeEventListener("pointerdown",this.Ni),window.removeEventListener("pointermove",this.qi),window.removeEventListener("pointerup",this.ji),this.Di.off(vi.CHANGE,this.Fi)}render(t,i){_t(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}projectWorldPosition(t,i){const s=t.project(i);return s.x=d.mapLinear(s.x,-1,1,this.x,this.width),s.y=d.mapLinear(s.y,-1,1,this.y,this.height),s}Oi(t,i,s){const e=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,r=e?t.clientX-e.left:t.clientX,n=e?e.bottom-t.clientY:window.innerHeight-t.clientY,h=this.Di.calculateScaleInternal(window.innerWidth,window.innerHeight),o=r*h,a=n*h;this[i](o,a,t.pointerId),this.emit(s,o,a,t.pointerId)}}const _i=(()=>{const i=new t(1,1),s=new x;return s.index=i.index,s.setAttribute("position",i.attributes.position),s.setAttribute("uv",i.attributes.uv),i.dispose(),s})();function Ii(t){if("Texture"===t||t instanceof o)return{glslType:"sampler2D",instantiable:!1,itemSize:-1};if("UIColor"===t||t instanceof Z)return{glslType:"vec4",instantiable:!0,itemSize:4};if("Vector2"===t||t instanceof a)return{glslType:"vec2",instantiable:!0,itemSize:2};if("Vector3"===t||t instanceof l)return{glslType:"vec3",instantiable:!0,itemSize:3};if("Vector4"===t||t instanceof n)return{glslType:"vec4",instantiable:!0,itemSize:4};if("Matrix2"===t||t instanceof c)return{glslType:"mat2",instantiable:!0,itemSize:4};if("Matrix3"===t||t instanceof u)return{glslType:"mat3",instantiable:!0,itemSize:9};if("Matrix4"===t||t instanceof f)return{glslType:"mat4",instantiable:!0,itemSize:16};if("number"===t||"number"==typeof t)return{glslType:"float",instantiable:!0,itemSize:1};throw Error("Unsupported property type: "+t)}function Ei(t,i,s){const e=i.array;if(t instanceof Z)e[s]=t.r,e[s+1]=t.g,e[s+2]=t.b,e[s+3]=t.a;else if(t instanceof a)e[s]=t.x,e[s+1]=t.y;else if(t instanceof l)e[s]=t.x,e[s+1]=t.y,e[s+2]=t.z;else if(t instanceof n)e[s]=t.x,e[s+1]=t.y,e[s+2]=t.z,e[s+3]=t.w;else if(t instanceof c){const i=t.elements;for(let t=0;i.length>t;t++)e[s+t]=i[t]}else if(t instanceof u){const i=t.elements;for(let t=0;i.length>t;t++)e[s+t]=i[t]}else if(t instanceof f){const i=t.elements;for(let t=0;i.length>t;t++)e[s+t]=i[t]}else"number"==typeof t&&(e[s]=t);i.needsUpdate=!0}function Pi(t,i){const s=Ii(t);if(!s.instantiable)throw Error("Invalid property type: "+t);return new _(new Float32Array(i*s.itemSize),s.itemSize)}class Ui extends h{constructor(t,i,s=Q.CLIP,e=16){const n={},h={instanceTransform:"Matrix4",uvTransform:"Matrix3",...s===Q.CLIP?{alphaTest:"number"}:{}};for(const[t,s]of Object.entries(i))(Ii(s).instantiable?h:n)[t]=s;const o=_i.clone(),a=((t,i,s,e)=>{const n={},h=[],o=[],a=[],l=[];for(const[t,s]of Object.entries(i)){const i=Ii(s).glslType;n["u_"+t]={value:null},h.push(`uniform ${i} u_${t};`)}for(const[t,i]of Object.entries(s)){const s=Ii(i).glslType;o.push(`attribute ${s} a_${t};`),a.push(`varying ${s} v_${t};`),l.push(`v_${t} = a_${t};`)}const c=`\n ${o.join("\n")}\n\n ${h.join("\n")}\n\n ${a.join("\n")}\n varying vec3 v_position;\n varying vec2 v_uv;\n\n void main() {\n if (a_visibility < 0.5) {\n gl_Position = vec4(2.0, 2.0, 2.0, 2.0);\n return;\n }\n\n ${l.join("\n")}\n\n v_position = position;\n v_uv = (a_uvTransform * vec3(uv, 1.0)).xy;\n\n gl_Position = projectionMatrix * modelViewMatrix * a_instanceTransform * vec4(position, 1.0);\n }\n `,u=`\n ${h.join("\n")}\n\n ${a.join("\n")}\n varying vec3 v_position;\n varying vec2 v_uv;\n\n #include <alphahash_pars_fragment>\n\n // Source have to define 'draw' function\n ${t}\n\n void main() {\n vec4 diffuseColor = draw();\n\n #ifdef USE_ALPHATEST\n if (diffuseColor.a < v_alphaTest) {\n discard;\n }\n #endif\n\n #ifdef USE_ALPHAHASH\n if (diffuseColor.a < getAlphaHashThreshold(v_position)) {\n discard;\n }\n #endif\n\n gl_FragColor = linearToOutputTexel(diffuseColor);\n }\n `;return new r({uniforms:n,vertexShader:c,fragmentShader:u,transparent:e===Q.BLEND,alphaTest:e===Q.CLIP?.5:0,alphaHash:e===Q.HASH})})(t,n,h,s);super(o,a),this.handlerToDescriptor=new Map,this.lastHandler=0,this.capacity=0,this.propertyBuffers=new Map,this.Gi=o,this.Gi.instanceCount=0,this.Yi=a,this.capacity=Math.max(e,16);for(const[t,i]of Object.entries(h)){const s=Pi(i,this.capacity);this.Gi.setAttribute("a_"+t,s),this.propertyBuffers.set("a_"+t,s)}}createInstances(t){const i=this.lastHandler++;return this.Gi.instanceCount+t>this.capacity&&this.Xi(16*Math.ceil((this.capacity+t)/16)),this.handlerToDescriptor.set(i,{firstIndex:this.Gi.instanceCount,count:t}),this.Gi.instanceCount+=t,i}destroyInstances(t){const i=this.handlerToDescriptor.get(t);if(void 0===i)throw Error("No range found for userIndex: "+t);this.handlerToDescriptor.delete(t);const s=Array.from(this.handlerToDescriptor.values()),e=i.firstIndex+i.count;let r;for(let t=s.length-1;t>e;t--){const e=s[t];if(e.count===i.count){r=e;break}}r?(this.Ji(r,i),r.firstIndex=i.firstIndex,this.Qi(r.firstIndex+r.count,r.count)):this.Qi(i.firstIndex+i.count,i.count),this.Gi.instanceCount-=i.count}updateProperties(t,i,s){Et(i,"UIGenericInstancedPlane updateProperties offset");const e=this.gt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=s[t],n=e.firstIndex+i+t;for(const[t,i]of Object.entries(r))if(Ii(i).instantiable){const s=this.Zi(t);Ei(i,s,n*s.itemSize)}else this.Ki(t).value=i,this.Yi.uniformsNeedUpdate=!0}}updateTransforms(t,i,s){Et(i,"UIGenericInstancedPlane updateTransforms offset");const e=this.gt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=this.Zi("instanceTransform"),n=r.array,h=(e.firstIndex+i+t)*r.itemSize,o=s[t].elements;for(let t=0;o.length>t;t++)n[h+t]=o[t];r.needsUpdate=!0}}updateUVTransforms(t,i,s){Et(i,"UIGenericInstancedPlane updateUVTransforms offset");const e=this.gt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=this.Zi("uvTransform"),n=r.array,h=(e.firstIndex+i+t)*r.itemSize,o=s[t].elements;for(let t=0;o.length>t;t++)n[h+t]=o[t];r.needsUpdate=!0}}updateVisibility(t,i,s){Et(i,"UIGenericInstancedPlane updateVisibility offset");const e=this.gt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=this.Zi("visibility");r.array[(e.firstIndex+i+t)*r.itemSize]=s[t]?1:0,r.needsUpdate=!0}}destroy(){this.Gi.dispose(),this.Yi.dispose()}gt(t){const i=this.handlerToDescriptor.get(t);if(void 0===i)throw Error("No active range found for handler: "+t);return i}Zi(t){const i=this.propertyBuffers.get("a_"+t);if(void 0===i)throw Error(`No attribute found for property: ${t} (a_${t})`);return i}Ki(t){const i=this.Yi.uniforms["u_"+t];if(void 0===i)throw Error("No uniform found for handler: "+t);return i}Xi(t){for(const[i,s]of this.propertyBuffers.entries()){const e=s.itemSize,r=new Float32Array(t*e);r.set(s.array);const n=new _(r,e);this.Gi.setAttribute("a_"+i,n),this.propertyBuffers.set("a_"+i,n)}this.capacity=t}Ji(t,i){for(const s of this.propertyBuffers.values()){const e=s.array,r=s.itemSize,n=t.firstIndex*r,h=i.firstIndex*r,o=t.count*r;for(let t=0;o>t;t++)e[h+t]=e[n+t];s.needsUpdate=!0}}Qi(t,i){for(const s of this.handlerToDescriptor.values())t>s.firstIndex||(s.firstIndex-=i);for(const s of this.propertyBuffers.values()){const e=s.array,r=s.itemSize,n=this.Gi.instanceCount*r,h=i*r;for(let i=t*r;n-h>i;i++)e[i]=e[i+h];s.needsUpdate=!0}}}class Ci extends yi{constructor(t,i){super(),It(t,"UIResizePolicyCross.fixedWidthLandscape"),It(i,"UIResizePolicyCross.fixedHeightPortrait"),this.ts=t,this.ss=i}get fixedWidthLandscape(){return this.ts}get fixedHeightPortrait(){return this.ss}set fixedWidthLandscape(t){It(t,"UIResizePolicyCross.fixedWidthLandscape"),t!==this.ts&&(this.ts=t,this.emit(vi.CHANGE))}set fixedHeightPortrait(t){It(t,"UIResizePolicyCross.fixedHeightPortrait"),t!==this.ss&&(this.ss=t,this.emit(vi.CHANGE))}calculateScaleInternal(t,i){return t>i?this.ts/t:this.ss/i}}class Si extends yi{constructor(t,i){super(),It(t,"UIResizePolicyCrossInverted.fixedHeightLandscape"),It(i,"UIResizePolicyCrossInverted.fixedWidthPortrait"),this.es=t,this.rs=i}get fixedHeightLandscape(){return this.es}get fixedWidthPortrait(){return this.rs}set fixedHeightLandscape(t){It(t,"UIResizePolicyCrossInverted.fixedHeightLandscape"),t!==this.es&&(this.es=t,this.emit(vi.CHANGE))}set fixedWidthPortrait(t){It(t,"UIResizePolicyCrossInverted.fixedWidthPortrait"),t!==this.rs&&(this.rs=t,this.emit(vi.CHANGE))}calculateScaleInternal(t,i){return t>i?this.es/i:this.rs/t}}class Mi extends yi{constructor(t,i,s=i,e=.1){super(),It(t,"UIResizePolicyFixedHeight.fixedHeightLandscape"),It(i,"UIResizePolicyFixedHeight.fixedHeightPortrait"),It(s,"UIResizePolicyFixedHeight.fixedHeightSquare"),It(e,"UIResizePolicy.squareEpsilon"),this.es=t,this.ss=i,this.ns=s,this.hs=e}get fixedHeightLandscape(){return this.es}get fixedHeightPortrait(){return this.ss}get fixedHeightSquare(){return this.ns}get squareEpsilon(){return this.hs}set fixedHeightLandscape(t){It(t,"UIResizePolicyFixedHeight.fixedHeightLandscape"),t!==this.es&&(this.es=t,this.emit(vi.CHANGE))}set fixedHeightPortrait(t){It(t,"UIResizePolicyFixedHeight.fixedHeightPortrait"),t!==this.ss&&(this.ss=t,this.emit(vi.CHANGE))}set fixedHeightSquare(t){It(t,"UIResizePolicyFixedHeight.fixedHeightSquare"),t!==this.ns&&(this.ns=t,this.emit(vi.CHANGE))}set squareEpsilon(t){It(t,"UIResizePolicy.squareEpsilon"),t!==this.hs&&(this.hs=t,this.emit(vi.CHANGE))}calculateScaleInternal(t,i){return this.ls(t,i)?this.ns/i:t>i?this.es/i:this.ss/i}ls(t,i){return this.hs>=Math.abs(t/i-1)}}class Ti extends yi{constructor(t,i,s=i,e=.1){super(),It(t,"UIResizePolicyFixedWidth.fixedWidthLandscape"),It(i,"UIResizePolicyFixedWidth.fixedWidthPortrait"),It(s,"UIResizePolicyFixedWidth.fixedWidthSquare"),It(e,"UIResizePolicy.squareEpsilon"),this.ts=t,this.rs=i,this.cs=s,this.hs=e}get fixedWidthLandscape(){return this.ts}get fixedWidthPortrait(){return this.rs}get fixedWidthSquare(){return this.cs}get squareEpsilon(){return this.hs}set fixedWidthLandscape(t){It(t,"UIResizePolicyFixedWidth.fixedWidthLandscape"),t!==this.ts&&(this.ts=t,this.emit(vi.CHANGE))}set fixedWidthPortrait(t){It(t,"UIResizePolicyFixedWidth.fixedWidthPortrait"),t!==this.rs&&(this.rs=t,this.emit(vi.CHANGE))}set fixedWidthSquare(t){It(t,"UIResizePolicyFixedWidth.fixedWidthSquare"),t!==this.cs&&(this.cs=t,this.emit(vi.CHANGE))}set squareEpsilon(t){It(t,"UIResizePolicy.squareEpsilon"),t!==this.hs&&(this.hs=t,this.emit(vi.CHANGE))}calculateScaleInternal(t,i){return this.ls(t,i)?this.cs/t:t>i?this.ts/t:this.rs/t}ls(t,i){return this.hs>=Math.abs(t/i-1)}}function Vi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||li(t.style))}export{ci as DEFAULT_TEXT_STYLE,kt as UIAnchor,Qt as UIAnimatedImage,Jt as UIAnimatedImageEvent,Vt as UIAspectConstraint,Z as UIColor,J as UIColorEvent,gt as UIConstraint,Tt as UIConstraint2DBuilder,At as UICoverConstraintBuilder,zt as UICustomConstraint,Zt as UIDummy,Xt as UIElement,I as UIExpression,Rt as UIFitConstraintBuilder,xi as UIFullscreenLayer,Ui as UIGenericInstancedPlane,Kt as UIGraphics,mt as UIHeightConstraint,Pt as UIHorizontalDistanceConstraint,Ut as UIHorizontalProportionConstraint,ti as UIImage,$t as UIInputEvent,pt as UILayer,ct as UILayerEvent,Nt as UIMicro,Lt as UIMicroAnchorMode,Wt as UIMicroEvent,U as UIMode,si as UINineSlice,C as UIOrientation,j as UIPriority,hi as UIProgress,ri as UIProgressMaskFunction,lt as UIRelation,yi as UIResizePolicy,Ci as UIResizePolicyCross,Si as UIResizePolicyCrossInverted,vi as UIResizePolicyEvent,Mi as UIResizePolicyFixedHeight,Ti as UIResizePolicyFixedWidth,bi as UIResizePolicyNone,ai as UIScene,ni as UISceneUpdateMode,wt as UISingleParameterConstraint,mi as UIText,Q as UITransparencyMode,Ct as UIVerticalDistanceConstraint,St as UIVerticalProportionConstraint,Mt as UIWidthConstraint,G as convertPriority,ut as convertRelation,Vi as isUITextSpan,li as isUITextStyle,S as resolveOrientation,Y as resolvePriority,ft as resolveRelation,wi as resolveTextPadding,ui as resolveTextStyle};
|
|
1
|
+
import{PlaneGeometry as t,Color as i,Scene as s,OrthographicCamera as e,ShaderMaterial as r,Vector4 as n,Mesh as h,Texture as o,Vector2 as a,Vector3 as l,Matrix2 as c,Matrix3 as u,Matrix4 as f,MathUtils as d,Quaternion as p,CanvasTexture as g,LinearFilter as w,WebGLRenderTarget as v,UnsignedByteType as m,RGBAFormat as y,PerspectiveCamera as b,InstancedBufferGeometry as x,InstancedBufferAttribute as _}from"three";class I{constructor(t=0,i){this.constant=t,this._=i?new Map(i):new Map}static plus(t,i){const s=new I(t.constant+i.constant,Array.from(t._.entries()));for(const[t,e]of i._)s.plus(t,e);return s}static minus(t,i){const s=new I(t.constant-i.constant,Array.from(t._.entries()));for(const[t,e]of i._)s.minus(t,e);return s}plus(t,i){return this._.set(t,(this._.get(t)??0)+i),this}minus(t,i){return this.plus(t,-i)}multiply(t){this.constant*=t;for(const[i,s]of this._)this._.set(i,s*t);return this}divide(t){return this.multiply(1/t)}hasTerm(t){return this._.has(t)}copy(t){this.constant=t.constant,this._.clear();for(const[i,s]of t._)this._.set(i,s);return this}clone(){return new I(this.constant,Array.from(this._.entries()))}prepareTermsInternal(){return Array.from(this._.entries())}}class E{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 P{constructor(){this.o=new Map}on(t,i,s,e=0){return this.h(t,!1,e,i,s),this}once(t,i,s,e=0){return this.h(t,!0,e,i,s),this}off(t,i,s){const e=this.o.get(t);if(void 0===e)return this;e.u&&(e.u=!1,e.v=e.v.slice());const r=e.v;if(0===r.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;r.length>t;t++){const i=r[t];e.l.remove(i.I,i.p)}return this}{const n=r.length;if(r[0].I===i&&r[0].p===s)return 1===n?this.o.delete(t):r.shift(),this;const h=n-1;if(r[h].I===i&&r[h].p===s)return r.pop(),this;if(10>n||r[0].M===r[h].M)for(let t=1;h>t;t++){const e=r[t];if(e.I===i&&e.p===s)return r.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let n=0,h=r.length-1;for(;h>=n;){const i=n+h>>>1;t>r[i].M?n=i+1:h=i-1}const o=n;for(h=r.length-1;h>=n;){const i=n+h>>>1;r[i].M>t?h=i-1:n=i+1}const a=h;for(let t=o;a>=t;t++)if(r[t].I===i&&r[t].p===s)return r.splice(t,1),this}}return this}emit(t,...i){const s=this.o.get(t);if(void 0===s)return!1;if(0===s.v.length)return!1;s.u?s.v=s.v.slice():s.u=!0;const e=s.v;let r=!1;for(let t=0;e.length>t;t++){const s=e[t];s.I.apply(s.p,i),s.k&&(r=!0,s.m=!0)}const n=this.o.get(t);if(void 0===n)return!0;n.v===e&&(n.u=!1);const h=n.v;if(r){let i=0;for(let t=0;h.length>t;t++){const s=h[t];s.m?n.l.remove(s.I,s.p):h[i++]=s}0===i?this.o.delete(t):h.length=i}return!0}h(t,i,s,e,r){let n=this.o.get(t);if(void 0===n)return void this.o.set(t,{v:[{I:e,p:r,M:s,k:i,m:!1}],u:!1,l:new E(e,r,s)});if(n.l.has(e,r))throw Error("Event listener already exists");n.l.insert(e,r,s);const h={I:e,p:r,M:s,k:i,m:!1};n.u&&(n.u=!1,n.v=n.v.slice());{const t=n.v,i=h.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(h);if(t[0].M>=i)return void t.unshift(h);{let s=0,e=t.length;for(;e>s;){const r=s+e>>>1;i>t[r].M?s=r+1:e=r}t.splice(s,0,h)}}}}var U,C;function S(t){return t??C.ALWAYS}function M(){return new T}(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(U||(U={})),(t=>{t[t.HORIZONTAL=0]="HORIZONTAL",t[t.VERTICAL=1]="VERTICAL",t[t.ALWAYS=2]="ALWAYS"})(C||(C={}));class T{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new V(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new V(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new T;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class V{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new V(this.first,this.second)}}class B{constructor(t=""){this.P=t}id(){return this.U}name(){return this.P}setName(t){this.P=t}context(){return this.C}setContext(t){this.C=t}value(){return this.S}setValue(t){this.S=t}plus(t){return new H(this,t)}minus(t){return new H(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new H([t,this])}divide(t){return new H([1/t,this])}toJSON(){return{name:this.P,value:this.S}}toString(){return this.C+"["+this.P+":"+this.S+"]"}P;S=0;C=null;U=A++}let A=0;class H{constructor(){let t=(t=>{let i=0,s=()=>0,e=M();for(let r=0,n=t.length;n>r;++r){let n=t[r];if("number"==typeof n)i+=n;else if(n instanceof B)e.setDefault(n,s).second+=1;else if(n instanceof H){i+=n.constant();let t=n.terms();for(let i=0,r=t.size();r>i;i++){let r=t.itemAt(i);e.setDefault(r.first,s).second+=r.second}}else{if(!(n instanceof Array))throw Error("invalid Expression argument: "+n);{if(2!==n.length)throw Error("array must have length 2");let t=n[0],r=n[1];if("number"!=typeof t)throw Error("array item 0 must be a number");if(r instanceof B)e.setDefault(r,s).second+=t;else{if(!(r instanceof H))throw Error("array item 1 must be a variable or expression");{i+=r.constant()*t;let n=r.terms();for(let i=0,r=n.size();r>i;i++){let r=n.itemAt(i);e.setDefault(r.first,s).second+=r.second*t}}}}}}return{terms:e,constant:i}})(arguments);this.T=t.terms,this.V=t.constant}terms(){return this.T}constant(){return this.V}value(){let t=this.V;for(let i=0,s=this.T.size();s>i;i++){let s=this.T.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new H(this,t)}minus(t){return new H(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new H([t,this])}divide(t){return new H([1/t,this])}isConstant(){return 0==this.T.size()}toString(){let t=this.T.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.V||(t+=" + "),t+=this.V,t}T;V}class R{static create(t,i,s,e=1){let r=0;return r+=1e6*Math.max(0,Math.min(1e3,t*e)),r+=1e3*Math.max(0,Math.min(1e3,i*e)),r+=Math.max(0,Math.min(1e3,s*e)),r}static required=R.create(1e3,1e3,1e3);static strong=R.create(1,0,0);static medium=R.create(0,1,0);static weak=R.create(0,0,1);static clip(t){return Math.max(0,Math.min(R.required,t))}}var z;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(z||(z={}));class k{constructor(t,i,s,e=R.required){this.B=i,this.A=R.clip(e),this.H=void 0===s&&t instanceof H?t:t.minus(s)}id(){return this.U}expression(){return this.H}op(){return this.B}strength(){return this.A}toString(){return this.H+" "+["<=",">=","="][this.B]+" 0 ("+this.A+")"}H;B;A;U=$++}let $=0;class L{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=R.required){let r=new k(t,i,s,e);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.R.find(t))throw Error("duplicate constraint");let i=this.$(t),s=i.row,e=i.tag,r=this.L(s,e);if(r.type()===F.Invalid&&s.allDummies()){if(!W(s.constant()))throw Error("unsatisfiable constraint");r=e.marker}if(r.type()===F.Invalid){if(!this.W(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.F(r,s),this.D.insert(r,s);this.R.insert(t,e),this.N(this.O)}removeConstraint(t){let i=this.R.erase(t);if(void 0===i)throw Error("unknown constraint");this.q(t,i.second);let s=i.second.marker,e=this.D.erase(s);if(void 0===e){let t=this.j(s);if(t.type()===F.Invalid)throw Error("failed to find leaving row");e=this.D.erase(t),e.second.solveForEx(t,s),this.F(s,e.second)}this.N(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=R.clip(i))===R.required)throw Error("bad required strength");let s=new H(t),e=new k(s,z.Eq,void 0,i);this.addConstraint(e);let r=this.R.find(e).second;this.G.insert(t,{tag:r,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.D,r=s.second,n=i-r.constant;r.constant=i;let h=r.tag.marker,o=e.find(h);if(void 0!==o)return 0>o.second.add(-n)&&this.Y.push(h),void this.X();let a=r.tag.other;if(o=e.find(a),void 0!==o)return 0>o.second.add(n)&&this.Y.push(a),void this.X();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t),s=i.second,r=s.coefficientFor(h);0!==r&&0>s.add(n*r)&&i.first.type()!==F.External&&this.Y.push(i.first)}this.X()}updateVariables(){let t=this.J,i=this.D;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),r=i.find(e.second);e.first.setValue(void 0!==r?r.second.constant():0)}}Z(t){return this.J.setDefault(t,()=>this.K(F.External)).second}$(t){let i=t.expression(),s=new O(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!W(i.second)){let t=this.Z(i.first),e=this.D.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let r=this.O,n=t.strength(),h={marker:N,other:N};switch(t.op()){case z.Le:case z.Ge:{let i=t.op()===z.Le?1:-1,e=this.K(F.Slack);if(h.marker=e,s.insertSymbol(e,i),R.required>n){let t=this.K(F.Error);h.other=t,s.insertSymbol(t,-i),r.insertSymbol(t,n)}break}case z.Eq:if(R.required>n){let t=this.K(F.Error),i=this.K(F.Error);h.marker=t,h.other=i,s.insertSymbol(t,-1),s.insertSymbol(i,1),r.insertSymbol(t,n),r.insertSymbol(i,n)}else{let t=this.K(F.Dummy);h.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:h}}L(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===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?N:i.other):i.marker}W(t){let i=this.K(F.Slack);this.D.insert(i,t.copy()),this.tt=t.copy(),this.N(this.tt);let s=W(this.tt.constant());this.tt=null;let e=this.D.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let r=this.it(t);if(r.type()===F.Invalid)return!1;t.solveForEx(i,r),this.F(r,t),this.D.insert(r,t)}let r=this.D;for(let t=0,s=r.size();s>t;++t)r.itemAt(t).second.removeSymbol(i);return this.O.removeSymbol(i),s}F(t,i){let s=this.D;for(let e=0,r=s.size();r>e;++e){let r=s.itemAt(e);r.second.substitute(t,i),0>r.second.constant()&&r.first.type()!==F.External&&this.Y.push(r.first)}this.O.substitute(t,i),this.tt&&this.tt.substitute(t,i)}N(t){let i=0;for(;this.maxIterations>i;){let s=this.st(t);if(s.type()===F.Invalid)return;let e=this.et(s);if(e.type()===F.Invalid)throw Error("the objective is unbounded");let r=this.D.erase(e).second;r.solveForEx(e,s),this.F(s,r),this.D.insert(s,r),i++}throw Error("solver iterations exceeded")}X(){let t=this.D,i=this.Y;for(;0!==i.length;){let s=i.pop(),e=t.find(s);if(void 0!==e&&0>e.second.constant()){let i=this.rt(e.second);if(i.type()===F.Invalid)throw Error("dual optimize failed");let r=e.second;t.erase(s),r.solveForEx(s,i),this.F(i,r),t.insert(i,r)}}}st(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first;if(0>s.second&&e.type()!==F.Dummy)return e}return N}rt(t){let i=Number.MAX_VALUE,s=N,e=t.cells();for(let t=0,r=e.size();r>t;++t){let r=e.itemAt(t),n=r.first,h=r.second;if(h>0&&n.type()!==F.Dummy){let t=this.O.coefficientFor(n)/h;i>t&&(i=t,s=n)}}return s}et(t){let i=Number.MAX_VALUE,s=N,e=this.D;for(let r=0,n=e.size();n>r;++r){let n=e.itemAt(r),h=n.first;if(h.type()!==F.External){let e=n.second,r=e.coefficientFor(t);if(0>r){let t=-e.constant()/r;i>t&&(i=t,s=h)}}}return s}j(t){let i=Number.MAX_VALUE,s=i,e=i,r=N,n=r,h=r,o=r,a=this.D;for(let i=0,r=a.size();r>i;++i){let r=a.itemAt(i),l=r.second,c=l.coefficientFor(t);if(0===c)continue;let u=r.first;if(u.type()===F.External)o=u;else if(0>c){let t=-l.constant()/c;s>t&&(s=t,n=u)}else{let t=l.constant()/c;e>t&&(e=t,h=u)}}return n!==r?n:h!==r?h:o}q(t,i){i.marker.type()===F.Error&&this.nt(i.marker,t.strength()),i.other.type()===F.Error&&this.nt(i.other,t.strength())}nt(t,i){let s=this.D.find(t);void 0!==s?this.O.insertRow(s.second,-i):this.O.insertSymbol(t,-i)}it(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first.type();if(e===F.Slack||e===F.Error)return s.first}return N}K(t){return new D(t,this.ht++)}R=(()=>M())();D=(()=>M())();J=(()=>M())();G=(()=>M())();Y=[];O=new O;tt=null;ht=0}function W(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 D{constructor(t,i){this.U=i,this.ot=t}id(){return this.U}type(){return this.ot}U;ot}let N=new D(F.Invalid,-1);class O{constructor(t=0){this.V=t}cells(){return this.lt}constant(){return this.V}isConstant(){return this.lt.empty()}allDummies(){let t=this.lt;for(let i=0,s=t.size();s>i;++i)if(t.itemAt(i).first.type()!==F.Dummy)return!1;return!0}copy(){let t=new O(this.V);return t.lt=this.lt.copy(),t}add(t){return this.V+=t}insertSymbol(t,i=1){W(this.lt.setDefault(t,()=>0).second+=i)&&this.lt.erase(t)}insertRow(t,i=1){this.V+=t.V*i;let s=t.lt;for(let t=0,e=s.size();e>t;++t){let e=s.itemAt(t);this.insertSymbol(e.first,e.second*i)}}removeSymbol(t){this.lt.erase(t)}reverseSign(){this.V=-this.V;let t=this.lt;for(let i=0,s=t.size();s>i;++i){let s=t.itemAt(i);s.second=-s.second}}solveFor(t){let i=this.lt,s=-1/i.erase(t).second;this.V*=s;for(let t=0,e=i.size();e>t;++t)i.itemAt(t).second*=s}solveForEx(t,i){this.insertSymbol(t,-1),this.solveFor(i)}coefficientFor(t){let i=this.lt.find(t);return void 0!==i?i.second:0}substitute(t,i){let s=this.lt.erase(t);void 0!==s&&this.insertRow(i,s.second)}lt=M();V}const q=1e3;var j;function G(t){switch(t){case j.P0:return R.create(q,q,q);case j.P1:return R.create(100,0,0);case j.P2:return R.create(10,0,0);case j.P3:return R.create(0,100,0);case j.P4:return R.create(0,10,0);case j.P5:return R.create(0,0,100);case j.P6:return R.create(0,0,10);case j.P7:return R.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function Y(t){return t??j.P0}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(j||(j={}));const X={black:0,white:16777215,red:16711680,green:32768,blue:255,yellow:16776960,cyan:65535,magenta:16711935,gray:8421504,grey:8421504,silver:12632256,maroon:8388608,olive:8421376,lime:65280,aqua:65535,teal:32896,navy:128,fuchsia:16711935,purple:8388736,orange:16753920,pink:16761035,brown:10824234,gold:16766720,violet:15631086,indigo:4915330,coral:16744272,salmon:16416882,khaki:15787660,plum:14524637,orchid:14315734,tan:13808780,beige:16119260,mint:10025880,lavender:15132410,crimson:14423100,azure:15794175,ivory:16777200,snow:16775930};var J,Q;(t=>{t.CHANGE="change"})(J||(J={}));class Z extends P{constructor(...t){if(super(),this.ct=1,this.ut=1,this.ft=1,this.dt=1,3>t.length||"number"!=typeof t[0]){if(t.length>=1){const[i,s=1]=t;"string"==typeof i?this.setName(i,s):this.setHexRGB(i,s)}}else{const[i,s,e,r=1]=t;this.ct=i,this.ut=s,this.ft=e,this.dt=r}}get r(){return this.ct}get g(){return this.ut}get b(){return this.ft}get a(){return this.dt}set r(t){this.ct=t,this.emit(J.CHANGE,this)}set g(t){this.ut=t,this.emit(J.CHANGE,this)}set b(t){this.ft=t,this.emit(J.CHANGE,this)}set a(t){this.dt=t,this.emit(J.CHANGE,this)}set(t,i,s,e=this.dt){return this.ct=t,this.ut=i,this.ft=s,this.dt=e,this.emit(J.CHANGE,this),this}getHexRGBA(){return Math.round(255*this.ct)<<24|Math.round(255*this.ut)<<16|Math.round(255*this.ft)<<8|Math.round(255*this.dt)}getHexRGB(){return Math.round(255*this.ct)<<16|Math.round(255*this.ut)<<8|Math.round(255*this.ft)}getHSL(){const{ct:t,ut:i,ft:s}=this,e=Math.max(t,i,s),r=Math.min(t,i,s),n=e-r,h=(e+r)/2;let o=0;return 0!==n&&(o=e===t?(i-s)/n+(s>i?6:0):e===i?(s-t)/n+2:(t-i)/n+4,o*=60),{h:o,s:0===n?0:n/(1-Math.abs(2*h-1)),l:h}}setHexRGBA(t){return this.ct=(t>>16&255)/255,this.ut=(t>>8&255)/255,this.ft=(255&t)/255,this.dt=(t>>24&255)/255,this.emit(J.CHANGE,this),this}setHexRGB(t,i=this.dt){return this.ct=(t>>16&255)/255,this.ut=(t>>8&255)/255,this.ft=(255&t)/255,this.dt=i,this.emit(J.CHANGE,this),this}setHSL(t,i,s,e=this.dt){const r=(1-Math.abs(2*s-1))*i,n=t/60,h=r*(1-Math.abs(n%2-1));let[o,a,l]=1>n?[r,h,0]:2>n?[h,r,0]:3>n?[0,r,h]:4>n?[0,h,r]:5>n?[h,0,r]:[r,0,h];const c=s-r/2;return this.set(o+c,a+c,l+c,e)}setName(t,i=this.dt){const s=t.toLowerCase().trim(),e=X[s];if(void 0===e)throw Error(`Unknown color name: "${t}".`);return this.setHexRGB(e,i)}copy(t){return t instanceof Z?this.ct!==t.ct&&this.ut!==t.ut&&this.ft!==t.ft&&this.dt!==t.dt&&(this.ct=t.ct,this.ut=t.ut,this.ft=t.ft,this.dt=t.dt,this.emit(J.CHANGE,this)):this.ct!==t.r&&this.ut!==t.g&&this.ft!==t.b&&1!==this.dt&&(this.ct=t.r,this.ut=t.g,this.ft=t.b,this.dt=1,this.emit(J.CHANGE,this)),this}toCSSColor(){return`rgba(${Math.round(255*this.ct)}, ${Math.round(255*this.ut)}, ${Math.round(255*this.ft)}, ${this.dt})`}clone(){return new Z(this.ct,this.ut,this.ft,this.dt)}}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(Q||(Q={}));const K=.25,tt=new Map([[Z,"vec4"],[i,"vec3"],[o,"sampler2D"],[a,"vec2"],[l,"vec3"],[n,"vec4"],[c,"mat2"],[u,"mat3"],[f,"mat4"]]),it=new t(1,1).translate(.5,.5,0);let st=new i,et=0,rt=!1,nt=!1,ht=!1,ot=!1;class at{constructor(t,i){this.gt=new s,this.wt=new Map,this.vt=0,this.yt=new e(0,t,i,0,-1024,1024)}createPlane(t,i){const s=Object.entries(i),e=new r({uniforms:{alphaTest:{value:K},...Object.fromEntries(s.map(([t,i])=>[t,{value:i instanceof Z?new n(i.r,i.g,i.b,i.a):i}]))},vertexShader:"out vec2 io_UV;\n#include <common>\n\nvoid main() {\n #include <begin_vertex>\n io_UV = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"in vec2 io_UV;\n\nuniform float alphaTest;\n\n#include <common>\n#include <alphahash_pars_fragment>\n"+s.map(([t,i])=>((t,i)=>{if("number"==typeof i)return`uniform float ${t};`;for(const[s,e]of tt)if(i instanceof s)return`uniform ${e} ${t};`;throw Error(`Unsupported uniform type for key "${t}"`)})(t,i)).join("\n")+t,transparent:!1,alphaTest:K,alphaHash:!1,lights:!1,fog:!1,depthWrite:!1,depthTest:!0}),o=new h(it,e);o.frustumCulled=!1,o.matrixAutoUpdate=!1,this.gt.add(o);const a=this.vt++;return this.wt.set(a,{plane:o,material:e}),a}destroyPlane(t){const i=this.bt(t);return this.gt.remove(i.plane),this.wt.delete(t),this}setTransform(t,i){const s=this.bt(t);return s.plane.matrix.copy(i),s.plane.matrixWorldNeedsUpdate=!0,this}setUniform(t,i,s){const e=this.bt(t);if(!(i in e.material.uniforms))throw Error(`Uniform ${i} not found in material`);return s instanceof Z?e.material.uniforms[i].value.set(s.r,s.g,s.b,s.a):e.material.uniforms[i].value=s,this}setTransparency(t,i){const s=this.bt(t);return i===Q.BLEND?(s.material.transparent=!0,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!1):i===Q.CLIP?(s.material.transparent=!1,s.material.alphaTest=K,s.material.uniforms.alphaTest.value=K,s.material.alphaHash=!1):(s.material.transparent=!1,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!0),s.material.uniformsNeedUpdate=!0,s.material.needsUpdate=!0,this}setVisibility(t,i){return this.bt(t).plane.visible=i,this}insertCustomObject(t){return this.gt.add(t),this}removeCustomObject(t){return this.gt.remove(t),this}resize(t,i){return this.yt.right=t,this.yt.top=i,this.yt.updateProjectionMatrix(),this}render(t){return st=t.getClearColor(st),et=t.getClearAlpha(),rt=t.autoClear,nt=t.autoClearColor,ht=t.autoClearDepth,ot=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.yt),t.setClearColor(st),t.setClearAlpha(et),t.autoClear=rt,t.autoClearColor=nt,t.autoClearDepth=ht,t.autoClearStencil=ot,this}bt(t){const i=this.wt.get(t);if(!i)throw Error("No descriptor found for handler "+t);return i}}var lt,ct;function ut(t){switch(t){case lt.EQUAL:return z.Eq;case lt.LESS_THAN:return z.Le;case lt.GREATER_THAN:return z.Ge;default:throw Error("Invalid relation: "+t)}}function ft(t){return t??lt.EQUAL}(t=>{t[t.EQUAL=0]="EQUAL",t[t.LESS_THAN=1]="LESS_THAN",t[t.GREATER_THAN=2]="GREATER_THAN"})(lt||(lt={}));class dt{constructor(){this.xt=new L,this._t=!1,this.It=new Map,this.Et=0,this.Pt=new Map,this.Ut=0}createVariable(t,i){const s=this.Et++,e=new B;if(i===j.P0){const r={variable:e,priority:i,value:t};this.It.set(s,r),r.constraint=this.Ct(new I(0,[[s,1]]),new I(t),lt.EQUAL,i);try{this.xt?.addConstraint(r.constraint)}catch{this.xt=void 0}}else{this.It.set(s,{variable:e,priority:i,value:t});try{this.xt?.addEditVariable(e,G(i)),this.xt?.suggestValue(e,t)}catch{this.xt=void 0}}return this._t=!0,s}removeVariable(t){const i=this.It.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);for(const i of this.Pt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error(`Variable ${t} is used in constraint`);try{i.constraint?this.xt?.removeConstraint(i.constraint):this.xt?.removeEditVariable(i.variable)}catch{this.xt=void 0}this.It.delete(t),this._t=!0}suggestVariableValue(t,i){const s=this.It.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);s.value!==i&&(s.value=i,s.constraint?s.constraint=this.St(s.constraint,(new I).plus(t,1),new I(s.value),lt.EQUAL,s.priority):this.xt?.suggestValue(s.variable,i),this._t=!0)}setVariablePriority(t,i){const s=this.It.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);if(i!==s.priority){if(s.priority=i,s.priority===j.P0){const i=(new I).plus(t,1),e=new I(s.value);s.constraint=this.Ct(i,e,lt.EQUAL,s.priority);try{this.xt?.addConstraint(s.constraint)}catch{this.xt=void 0}}else{if(s.constraint)try{this.xt?.removeConstraint(s.constraint)}catch{this.xt=void 0}s.constraint=void 0,this.Mt(t,s)}this._t=!0}}readVariableValue(t){const i=this.It.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return void 0===this.xt&&this.Tt(),this._t&&(this.xt?.updateVariables(),this._t=!1),i.variable.value()}createConstraint(t,i,s,e,r){const n=this.Ut++,h=this.Ct(t,i,s,e);if(this.Pt.set(n,{constraint:h,lhs:t.clone(),rhs:i.clone(),priority:e,relation:s,enabled:r}),r){try{this.xt?.addConstraint(h)}catch{this.xt=void 0}this._t=!0}return n}removeConstraint(t){const i=this.Pt.get(t);if(void 0===i)throw Error(`Constraint ${t} does not exist`);if(i.enabled)try{this.xt?.removeConstraint(i.constraint)}catch{this.xt=void 0}this.Pt.delete(t),this._t=!0}setConstraintLHS(t,i){const s=this.Pt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.lhs.copy(i),this.Vt(s),this._t=!0}setConstraintRHS(t,i){const s=this.Pt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.rhs.copy(i),this.Vt(s),this._t=!0}setConstraintRelation(t,i){const s=this.Pt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.relation!==i&&(s.relation=i,this.Vt(s),this._t=!0)}setConstraintPriority(t,i){const s=this.Pt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.priority!==i&&(s.priority=i,this.Vt(s),this._t=!0)}setConstraintEnabled(t,i){const s=this.Pt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);if(i!==s.enabled){s.enabled=i;try{s.enabled?this.xt?.addConstraint(s.constraint):this.xt?.removeConstraint(s.constraint)}catch{this.xt=void 0}this._t=!0}}Mt(t,i){const s=[];for(const i of this.Pt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.xt?.removeConstraint(i.constraint)}catch{this.xt=void 0}s.push(i)}this.xt?.removeEditVariable(i.variable),this.xt?.addEditVariable(i.variable,G(i.priority));for(const t of s)t.constraint=this.Ct(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.xt?.addConstraint(t.constraint)}catch{this.xt=void 0;break}}Vt(t){t.constraint=t.enabled?this.St(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.Ct(t.lhs,t.rhs,t.relation,t.priority)}St(t,i,s,e,r){try{this.xt?.removeConstraint(t)}catch{this.xt=void 0}const n=this.Ct(i,s,e,r);try{this.xt?.addConstraint(n)}catch{this.xt=void 0}return n}Ct(t,i,s,e){return new k(this.Bt(t),ut(s),this.Bt(i),G(e))}Bt(t){return new H(...t.prepareTermsInternal().map(([t,i])=>{const s=this.It.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);return[i,s.variable]}),t.constant)}Tt(){if(this.xt)throw Error("Solver already exists");this.xt=new L;for(const t of this.It.values())t.constraint?this.xt.addConstraint(t.constraint):(this.xt.addEditVariable(t.variable,G(t.priority)),this.xt.suggestValue(t.variable,t.value));for(const t of this.Pt.values())t.enabled&&this.xt.addConstraint(t.constraint);this._t=!0}}(t=>{t.ORIENTATION_CHANGE="orientation_change",t.MODE_CHANGE="mode_change",t.WILL_RENDER="will_render"})(ct||(ct={}));class pt extends P{constructor(t,i){super(),this.name="",this.solverWrapper=new dt,this.modeInternal=U.VISIBLE,this.At=[],this.sceneWrapper=new at(t,i),this.xVariable=this.solverWrapper.createVariable(0,j.P0),this.yVariable=this.solverWrapper.createVariable(0,j.P0),this.wVariable=this.solverWrapper.createVariable(t,j.P0),this.hVariable=this.solverWrapper.createVariable(i,j.P0),this.orientationInternal=t>i?C.HORIZONTAL:C.VERTICAL}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get mode(){return this.modeInternal}get orientation(){return this.orientationInternal}set mode(t){t!==this.modeInternal&&(this.modeInternal=t,this.emit(ct.MODE_CHANGE,this.modeInternal,this))}resizeInternal(t,i){this.solverWrapper.suggestVariableValue(this.wVariable,t),this.solverWrapper.suggestVariableValue(this.hVariable,i),this.sceneWrapper.resize(t,i);const s=t>i?C.HORIZONTAL:C.VERTICAL;s!==this.orientationInternal&&(this.orientationInternal=s,this.emit(ct.ORIENTATION_CHANGE,this.orientationInternal,this))}renderInternal(t,i){this.mode!==U.HIDDEN&&(this.emit(ct.WILL_RENDER,t,i,this),this.sceneWrapper.render(t))}onPointerDownInternal(t,i,s){this.Ht(t,i,"catchPointerDown",s)}onPointerMoveInternal(t,i,s){this.Ht(t,i,"catchPointerMove",s)}onPointerUpInternal(t,i,s){this.Ht(t,i,"catchPointerUp",s)}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperClientAPI(){return this.sceneWrapper}subscribePointerInput(t){if(this.At.find(i=>i===t))throw Error("Listener already exists");this.At.push(t)}unsubscribePointerInput(t){const i=this.At.findIndex(i=>i===t);if(-1===i)throw Error("Listener not found");this.At.splice(i,1)}Ht(t,i,s,e){if(this.mode===U.INTERACTIVE){this.At.sort((t,i)=>i.zIndex-t.zIndex);for(const r of this.At)if(r[s](t,i,e))return}}}class gt{constructor(t){this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal()}}class wt extends gt{constructor(t,i,s,e){super(t),this.Rt=()=>{this.solverWrapper.setConstraintEnabled(this.constraint,this.isConstraintEnabled())},this.priorityInternal=Y(i),this.relationInternal=ft(s),this.orientationInternal=S(e),this.layer.on(ct.ORIENTATION_CHANGE,this.Rt)}get priority(){return this.priorityInternal}get relation(){return this.relationInternal}get orientation(){return this.orientationInternal}set priority(t){t!==this.priorityInternal&&(this.priorityInternal=t,this.solverWrapper.setConstraintPriority(this.constraint,this.priorityInternal))}set relation(t){t!==this.relationInternal&&(this.relationInternal=t,this.solverWrapper.setConstraintRelation(this.constraint,this.relationInternal))}set orientation(t){t!==this.orientationInternal&&(this.orientationInternal=t,this.Rt())}destroy(){this.layer.off(ct.ORIENTATION_CHANGE,this.Rt),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===C.ALWAYS||this.orientationInternal===this.layer.orientation}}class vt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.zt=t,this.kt=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new I(0,[[this.zt.hVariable,1]]),new I(this.kt),this.relation,this.priority,this.isConstraintEnabled())}get height(){return this.kt}set height(t){this.kt!==t&&(this.kt=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(t)))}}function mt(t){return"object"==typeof t&&null!==t&&"layer"in t&&t.layer instanceof pt}function yt(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 bt(t){return"object"==typeof t&&null!==t&&"wVariable"in t&&"number"==typeof t.wVariable&&"hVariable"in t&&"number"==typeof t.hVariable&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height}function xt(t,i,s){if(t instanceof pt&&i instanceof pt)throw Error(s+": layer cannot be snapped to another layer");let e,r;if(!(t instanceof pt||mt(t)))throw Error(s+": A must be a UILayer or a UIPointElement");if(e=t instanceof pt?t:t.layer,!(i instanceof pt||mt(i)))throw Error(s+": B must be a UILayer or a UIPointElement");if(r=i instanceof pt?i:i.layer,e!==r)throw Error(s+": elements must be on the same layer");return e}function _t(t,i){if(!Number.isFinite(t))throw Error(i+": value must be a finite number");if(Math.abs(t)>Number.MAX_SAFE_INTEGER)throw Error(i+": value exceeds maximum safe integer range")}function It(t,i){if(_t(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function Et(t,i){if(_t(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class Pt extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalDistanceConstraint"),s.priority,s.relation,s.orientation),this.$t=t,this.Lt=i,this.Wt=s.anchorA??.5,this.Ft=s.anchorB??.5,this.Dt=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Nt(),new I(this.Dt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Dt}get anchorA(){return this.Wt}get anchorB(){return this.Ft}set distance(t){this.Dt!==t&&(this.Dt=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(this.Dt)))}set anchorA(t){this.Wt!==t&&(this.Wt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Nt()))}set anchorB(t){this.Ft!==t&&(this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Nt()))}Nt(){let t,i;if(bt(this.$t))t=new I(0,[[this.$t.xVariable,1],[this.$t.wVariable,this.Wt]]);else{if(!yt(this.$t))throw Error("A is not a valid element type");t=(new I).plus(this.$t.xVariable,1)}if(bt(this.Lt))i=new I(0,[[this.Lt.xVariable,1],[this.Lt.wVariable,this.Ft]]);else{if(!yt(this.Lt))throw Error("B is not a valid element type");i=(new I).plus(this.Lt.xVariable,1)}return I.minus(i,t)}}class Ut extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalProportionConstraint"),s.priority,s.relation,s.orientation),this.$t=t,this.Lt=i,this.Ot=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new I(0),this.qt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Ot}set proportion(t){this.Ot!==t&&(this.Ot=t,this.solverWrapper.setConstraintRHS(this.constraint,this.qt()))}qt(){return I.minus(new I(0,[[this.$t.wVariable,this.Ot]]),new I(0,[[this.Lt.wVariable,1]]))}}class Ct extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalDistanceConstraint"),s.priority,s.relation,s.orientation),this.$t=t,this.Lt=i,this.Wt=s.anchorA??.5,this.Ft=s.anchorB??.5,this.Dt=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Nt(),new I(this.Dt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Dt}get anchorA(){return this.Wt}get anchorB(){return this.Ft}set distance(t){this.Dt!==t&&(this.Dt=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(this.Dt)))}set anchorA(t){this.Wt!==t&&(this.Wt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Nt()))}set anchorB(t){this.Ft!==t&&(this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Nt()))}Nt(){let t,i;if(bt(this.$t))t=new I(0,[[this.$t.yVariable,1],[this.$t.hVariable,this.Wt]]);else{if(!yt(this.$t))throw Error("A is not a valid element type");t=(new I).plus(this.$t.yVariable,1)}if(bt(this.Lt))i=new I(0,[[this.Lt.yVariable,1],[this.Lt.hVariable,this.Ft]]);else{if(!yt(this.Lt))throw Error("B is not a valid element type");i=(new I).plus(this.Lt.yVariable,1)}return I.minus(i,t)}}class St extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalProportionConstraint"),s.priority,s.relation,s.orientation),this.$t=t,this.Lt=i,this.Ot=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new I(0),this.qt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.Ot}set proportion(t){this.Ot!==t&&(this.Ot=t,this.solverWrapper.setConstraintRHS(this.constraint,this.qt()))}qt(){return I.minus(new I(0,[[this.$t.hVariable,this.Ot]]),new I(0,[[this.Lt.hVariable,1]]))}}class Mt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.zt=t,this.jt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new I(0,[[this.zt.wVariable,1]]),new I(this.jt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.jt}set width(t){this.jt!==t&&(this.jt=t,this.solverWrapper.setConstraintRHS(this.constraint,new I(t)))}}class Tt{static size(t,i={}){return{h:new Mt(t,{width:i.size?.h,priority:i.priority?.h,relation:i.relation?.h,orientation:i.orientation?.h}),v:new vt(t,{height:i.size?.v,priority:i.priority?.v,relation:i.relation?.v,orientation:i.orientation?.v})}}static distance(t,i,s={}){return{h:new Pt(t,i,{anchorA:s.anchorA?.h,anchorB:s.anchorB?.h,distance:s.distance?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new Ct(t,i,{anchorA:s.anchorA?.v,anchorB:s.anchorB?.v,distance:s.distance?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}static proportion(t,i,s={}){return{h:new Ut(t,i,{proportion:s.proportion?.h,priority:s.priority?.h,relation:s.relation?.h,orientation:s.orientation?.h}),v:new St(t,i,{proportion:s.proportion?.v,priority:s.priority?.v,relation:s.relation?.v,orientation:s.orientation?.v})}}}class Vt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.zt=t,this.Gt=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Nt(),new I(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Gt}set aspect(t){this.Gt!==t&&(this.Gt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Nt()))}Nt(){return new I(0,[[this.zt.wVariable,1],[this.zt.hVariable,-this.Gt]])}}const Bt=.5;class At{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Pt(t,i,{anchorA:s.anchorH??Bt,anchorB:s.anchorH??Bt,orientation:s.orientation}),yConstraint:new Ct(t,i,{anchorA:s.anchorV??Bt,anchorB:s.anchorV??Bt,orientation:s.orientation}),widthConstraint:new Ut(t,i,{proportion:1,relation:lt.GREATER_THAN,orientation:s.orientation}),heightConstraint:new St(t,i,{proportion:1,priority:j.P1,orientation:s.orientation})}}}const Ht=.5;class Rt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new Pt(t,i,{anchorA:s.anchorH??Ht,anchorB:s.anchorH??Ht,orientation:s.orientation}),yConstraint:new Ct(t,i,{anchorA:s.anchorV??Ht,anchorB:s.anchorV??Ht,orientation:s.orientation}),widthConstraint:new Ut(t,i,{proportion:1,relation:lt.LESS_THAN,orientation:s.orientation}),heightConstraint:new St(t,i,{proportion:1,priority:j.P1,orientation:s.orientation})}}}class zt extends wt{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Yt=i,this.Xt=s,this.constraint=this.solverWrapper.createConstraint(this.Yt,this.Xt,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Yt}get rhs(){return this.Xt}setLHS(t){this.Yt=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Yt)}setRHS(t){this.Xt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Xt)}}class kt extends P{constructor(t,i,s){_t(i,"UIAnchor x"),_t(s,"UIAnchor y"),super(),this.layer=t,this.name="",this.solverWrapper=this.layer.getSolverWrapperInternal(),this.xVariable=this.solverWrapper.createVariable(i,j.P7),this.yVariable=this.solverWrapper.createVariable(s,j.P7)}get x(){return this.solverWrapper.readVariableValue(this.xVariable)}get y(){return this.solverWrapper.readVariableValue(this.yVariable)}set x(t){_t(t,"UIAnchor x"),this.solverWrapper.suggestVariableValue(this.xVariable,t)}set y(t){_t(t,"UIAnchor y"),this.solverWrapper.suggestVariableValue(this.yVariable,t)}destroy(){this.solverWrapper.removeVariable(this.yVariable),this.solverWrapper.removeVariable(this.xVariable)}}var $t,Lt,Wt,Ft="void main() {\n vec2 transformedUV = (uvTransform * vec3(io_UV, 1.0)).xy;\n vec4 diffuseColor = texture(map, transformedUV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";(t=>{t.DOWN="pointerdown",t.MOVE="pointermove",t.UP="pointerup",t.ENTER="pointerenter",t.LEAVE="pointerleave"})($t||($t={})),(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(Lt||(Lt={})),(t=>{t[t.CHANGE=0]="CHANGE"})(Wt||(Wt={}));const Dt=.5;class Nt extends P{constructor(){super(...arguments),this.Jt=0,this.Qt=0,this.Zt=Dt,this.Kt=Dt,this.ti=1,this.ii=1,this.si=0,this.ei=Lt.ROTATION_SCALE,this._t=!1}get x(){return this.Jt}get y(){return this.Qt}get anchorX(){return this.Zt}get anchorY(){return this.Kt}get scaleX(){return this.ti}get scaleY(){return this.ii}get size(){return Math.max(this.ti,this.ii)}get angle(){return d.radToDeg(this.si)}get anchorMode(){return this.ei}get rotation(){return this.si}set x(t){t!==this.Jt&&(this.Jt=t,this._t=!0,this.emit(Wt.CHANGE,this))}set y(t){t!==this.Qt&&(this.Qt=t,this._t=!0,this.emit(Wt.CHANGE,this))}set anchorX(t){t!==this.Zt&&(this.Zt=t,this._t=!0,this.emit(Wt.CHANGE,this))}set anchorY(t){t!==this.Kt&&(this.Kt=t,this._t=!0,this.emit(Wt.CHANGE,this))}set scaleX(t){t!==this.ti&&(this.ti=t,this._t=!0,this.emit(Wt.CHANGE,this))}set scaleY(t){t!==this.ii&&(this.ii=t,this._t=!0,this.emit(Wt.CHANGE,this))}set size(t){t===this.ti&&t===this.ii||(this.ti=t,this.ii=t,this._t=!0,this.emit(Wt.CHANGE,this))}set angle(t){const i=d.degToRad(t);i!==this.si&&(this.si=i,this._t=!0,this.emit(Wt.CHANGE,this))}set rotation(t){t!==this.si&&(this.si=t,this._t=!0,this.emit(Wt.CHANGE,this))}set anchorMode(t){t!==this.ei&&(this.ei=t,this._t=!0,this.emit(Wt.CHANGE,this))}reset(){0===this.Jt&&0===this.Qt&&this.Zt===Dt&&this.Kt===Dt&&1===this.ti&&1===this.ii&&0===this.si||(this.Jt=0,this.Qt=0,this.Zt=Dt,this.Kt=Dt,this.ti=1,this.ii=1,this.si=0,this._t=!0,this.emit(Wt.CHANGE,this))}copy(t){this.Jt!==t.Jt&&this.Qt!==t.Qt&&this.Zt!==t.Zt&&this.Kt!==t.Kt&&this.ti!==t.ti&&this.ii!==t.ii&&this.si!==t.si&&this.ei!==t.ei&&(this.Jt=t.Jt,this.Qt=t.Qt,this.Zt=t.Zt,this.Kt=t.Kt,this.ti=t.ti,this.ii=t.ii,this.si=t.si,this.ei=t.ei,this.emit(Wt.CHANGE,this),this._t=!0)}getRecalculationRequiredInternal(){return this._t}resetRecalculationRequiredInternal(){this._t=!1}}const Ot=new l,qt=new p,jt=new l,Gt=new f,Yt=new l(0,0,1);class Xt extends kt{constructor(t,i,s,e,r,n,h){It(e,"UIElement width"),It(r,"UIElement height"),super(t,i,s),this.micro=new Nt,this.modeInternal=U.VISIBLE,this.transparencyInternal=Q.BLEND,this.zIndexInternal=0,this.isPointerInside=!1,this.catchPointerDown=(t,i,s)=>this.handleInputEvent(t,i,s,$t.DOWN),this.catchPointerMove=(t,i,s)=>this.handleInputEvent(t,i,s,$t.MOVE),this.catchPointerUp=(t,i,s)=>this.handleInputEvent(t,i,s,$t.UP),this.layer.on(ct.WILL_RENDER,this.onWillRender,this),this.wVariable=this.solverWrapper.createVariable(e,j.P6),this.hVariable=this.solverWrapper.createVariable(r,j.P6),this.sceneWrapper=t.getSceneWrapperClientAPI(),this.planeHandler=this.sceneWrapper.createPlane(n,h),this.sceneWrapper.setTransparency(this.planeHandler,this.transparencyInternal)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get zIndex(){return this.zIndexInternal}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 transparency(){return this.transparencyInternal}set width(t){It(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){It(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){_t(t,"UIElement zIndex"),this.zIndexInternal=t,this.listener&&(this.listener.zIndex=this.zIndexInternal)}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){this.modeInternal!==t&&(t===U.INTERACTIVE?(this.listener={catchPointerDown:this.catchPointerDown,catchPointerMove:this.catchPointerMove,catchPointerUp:this.catchPointerUp,zIndex:this.zIndexInternal},this.layer.subscribePointerInput(this.listener)):this.modeInternal===U.INTERACTIVE&&this.listener&&(this.layer.unsubscribePointerInput(this.listener),this.listener=void 0),this.modeInternal=t,this.sceneWrapper.setVisibility(this.planeHandler,t!==U.HIDDEN))}set transparency(t){this.transparencyInternal=t,this.sceneWrapper.setTransparency(this.planeHandler,t)}destroy(){this.layer.off(ct.WILL_RENDER,this.onWillRender,this),this.listener&&this.layer.unsubscribePointerInput(this.listener),this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}handleInputEvent(t,i,s,e){const r=t>this.x&&this.oppositeX>t&&i>this.y&&this.oppositeY>i;return r&&this.emit(e,t,i,s,this),this.isPointerInside&&!r?this.emit($t.LEAVE,t,i,s,this):!this.isPointerInside&&r&&this.emit($t.ENTER,t,i,s,this),this.isPointerInside=r,r}onWillRender(t,i){const s=this.micro,e=this.width*s.scaleX,r=this.height*s.scaleY,n=s.anchorX*e,h=s.anchorY*r,o=Math.cos(s.rotation),a=Math.sin(s.rotation),l=n*o-h*a,c=n*a+h*o;if(s.anchorMode===Lt.POSITION_ROTATION_SCALE)Ot.x=this.x+s.x-l,Ot.y=this.y+s.y-c;else{const t=s.anchorY*this.height;Ot.x=this.x+s.anchorX*this.width-l+s.x,Ot.y=this.y+t-c+s.y}Ot.z=this.zIndexInternal,jt.x=e,jt.y=r,qt.setFromAxisAngle(Yt,s.rotation),Gt.compose(Ot,qt,jt),this.sceneWrapper.setTransform(this.planeHandler,Gt)}}var Jt;(t=>{t[t.PLAY=0]="PLAY",t[t.PAUSE=1]="PAUSE",t[t.STOP=2]="STOP"})(Jt||(Jt={}));class Qt extends Xt{constructor(t,i,s={}){const e=s.width??100,r=s.height??100,n=s.color??new Z;let h;h=Array.isArray(i)?i.map(t=>(t.updateMatrix(),{texture:t,uvTransform:t.matrix})):i.transforms.map(t=>({texture:i.texture,uvTransform:t})),super(t,s.x??0,s.y??0,e,r,Ft,{map:h[0].texture,uvTransform:h[0].uvTransform,color:n}),this.ri=void 0,this.ni=0,this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.oi=h,this.ai=n,this.li=s.frameRate??24,this.ci=s.loop??!0,this.ai.on(J.CHANGE,this.hi)}get color(){return this.ai}get frameRate(){return this.li}get loop(){return this.ci}get duration(){return this.oi.length/this.li}set color(t){this.ai.copy(t)}set frameRate(t){if(0>=t)throw Error("Frame rate must be greater than zero");const i=void 0!==this.ri;i&&this.pause(),this.li=t,i&&this.play()}set loop(t){this.ci=t}play(){void 0===this.ri&&(this.ri=setInterval(()=>{if(this.ni++,this.ci)this.ni%=this.oi.length;else if(this.ni>=this.oi.length)return this.ni=this.oi.length-1,void this.pause();this.ui()},1e3/this.li),this.emit(Jt.PLAY))}pause(){void 0!==this.ri&&(clearInterval(this.ri),this.ri=void 0,this.emit(Jt.PAUSE))}stop(){void 0!==this.ri&&(clearInterval(this.ri),this.ri=void 0),this.ni=0,this.ui(),this.emit(Jt.STOP)}destroy(){this.stop(),this.ai.off(J.CHANGE,this.hi),super.destroy()}ui(){const t=this.oi[this.ni];this.sceneWrapper.setUniform(this.planeHandler,"map",t.texture),this.sceneWrapper.setUniform(this.planeHandler,"uvTransform",t.uvTransform)}}class Zt extends kt{constructor(t,i={}){const s=i.x??0,e=i.y??0,r=i.width??100,n=i.height??100;It(r,"UIDummy width"),It(n,"UIDummy height"),super(t,s,e),this.wVariable=this.solverWrapper.createVariable(r,j.P6),this.hVariable=this.solverWrapper.createVariable(n,j.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){It(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){It(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}class Kt extends Xt{constructor(t,i={}){const s=i.width??512,e=i.height??512,r=i.color??new Z,n=new OffscreenCanvas(s,e),h=n.getContext("2d");if(!h)throw Error("Failed to get 2D context from OffscreenCanvas");const o=new g(n);o.minFilter=w,o.magFilter=w,super(t,i.x??0,i.y??0,s,e,Ft,{map:o,uvTransform:o.matrix,color:r}),this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.fi=n,this.di=h,this.pi=o,this.ai=r,this.ai.on(J.CHANGE,this.hi),void 0!==i.mode&&(this.mode=i.mode)}get color(){return this.ai}set color(t){this.ai.copy(t)}clear(t){return this.di.clearRect(0,0,this.fi.width,this.fi.height),void 0!==t&&(this.di.fillStyle=t.toCSSColor(),this.di.fillRect(0,0,this.fi.width,this.fi.height)),this.pi.needsUpdate=!0,this}rect(t,i,s,e){return this.di.rect(t,i,s,e),this.pi.needsUpdate=!0,this}fillRect(t,i,s,e){return this.di.fillRect(t,i,s,e),this.pi.needsUpdate=!0,this}strokeRect(t,i,s,e){return this.di.strokeRect(t,i,s,e),this.pi.needsUpdate=!0,this}circle(t,i,s){return this.di.beginPath(),this.di.arc(t,i,s,0,2*Math.PI),this.di.closePath(),this.pi.needsUpdate=!0,this}beginPath(){return this.di.beginPath(),this.pi.needsUpdate=!0,this}closePath(){return this.di.closePath(),this.pi.needsUpdate=!0,this}fill(){return this.di.fill(),this.pi.needsUpdate=!0,this}stroke(){return this.di.stroke(),this.pi.needsUpdate=!0,this}moveTo(t,i){return this.di.moveTo(t,i),this}lineTo(t,i){return this.di.lineTo(t,i),this.pi.needsUpdate=!0,this}setFillStyle(t){return this.di.fillStyle=t instanceof Z?t.toCSSColor():t,this}setStrokeStyle(t){return this.di.strokeStyle=t instanceof Z?t.toCSSColor():t,this}setLineWidth(t){return this.di.lineWidth=t,this}destroy(){this.ai.off(J.CHANGE,this.hi),this.pi.dispose(),super.destroy()}}class ti extends Xt{constructor(t,i,s={}){const e=s.width??i.image.width,r=s.height??i.image.height,n=s.color??new Z;super(t,s.x??0,s.y??0,e,r,Ft,{map:i,uvTransform:i.matrix,color:n}),this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.gi=i,this.ai=n,this.ai.on(J.CHANGE,this.hi),void 0!==s.mode&&(this.mode=s.mode)}get texture(){return this.gi}get color(){return this.ai}set texture(t){const i=t.image.width,s=t.image.height;It(i,"UIImage texture width"),It(s,"UIImage texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.gi=t,this.sceneWrapper.setUniform(this.planeHandler,"map",t),this.sceneWrapper.setUniform(this.planeHandler,"uvTransform",t.matrix)}set color(t){this.ai.copy(t)}destroy(){this.ai.off(J.CHANGE,this.hi),super.destroy()}}const ii=.25;class si extends Xt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,h=s.color??new Z,o=(t=>{if(null==t)return{l:ii,r:ii,t:ii,b:ii};if("number"==typeof t)return{l:t,r:t,t,b:t};if("object"==typeof t){if("horizontal"in t&&"vertical"in t){const i="number"==typeof t.horizontal?t.horizontal:ii,s="number"==typeof t.vertical?t.vertical:ii;return{l:i,r:i,t:s,b:s}}return{l:"number"==typeof t.left?t.left:ii,r:"number"==typeof t.right?t.right:ii,t:"number"==typeof t.top?t.top:ii,b:"number"==typeof t.bottom?t.bottom:ii}}return{l:ii,r:ii,t:ii,b:ii}})(s.sliceBorders),a=new n(o.l,o.r,o.t,o.b),l=new n(e,r,e,r);super(t,s.x??0,s.y??0,e,r,"vec2 calculateNineSliceUV() {\n vec2 localUV = io_UV;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * dimensions.x;\n float rightPx = right * dimensions.x;\n float topPx = top * dimensions.y;\n float bottomPx = bottom * dimensions.y;\n\n float lB = leftPx / dimensions.z;\n float rB = 1.0 - (rightPx / dimensions.z);\n float tB = topPx / dimensions.w;\n float bB = 1.0 - (bottomPx / dimensions.w);\n\n {\n float regionL = step(io_UV.x, lB);\n float regionR = step(rB, io_UV.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = io_UV.x * (left / lB);\n float xR = 1.0 - right + ((io_UV.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((io_UV.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(io_UV.y, tB);\n float regionB = step(bB, io_UV.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = io_UV.y * (top / tB);\n float yB = 1.0 - bottom + ((io_UV.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((io_UV.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 diffuseColor = texture(map, calculateNineSliceUV()) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n",{map:i,color:h,sliceBorders:a,dimensions:l}),this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.gi=i,this.wi=a,this.mi=l,this.ai=h,this.ai.on(J.CHANGE,this.hi),void 0!==s.mode&&(this.mode=s.mode)}get texture(){return this.gi}get color(){return this.ai}get sliceBorderLeft(){return this.wi.x}get sliceBorderRight(){return this.wi.y}get sliceBorderTop(){return this.wi.z}get sliceBorderBottom(){return this.wi.w}set texture(t){const i=t.image.width,s=t.image.height;It(i,"UINineSlice texture width"),It(s,"UINineSlice texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.mi.x=i,this.mi.y=s,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.mi),this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ai.copy(t)}set sliceBorderLeft(t){this.wi.x=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.wi)}set sliceBorderRight(t){this.wi.y=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.wi)}set sliceBorderTop(t){this.wi.z=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.wi)}set sliceBorderBottom(t){this.wi.w=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.wi)}setSliceBorders(t,i,s,e){this.wi.set(t,i,s,e),this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.wi)}destroy(){this.ai.off(J.CHANGE,this.hi),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.mi.z=this.width*this.micro.scaleX,this.mi.w=this.height*this.micro.scaleY,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.mi)}}const ei=new o;var ri,ni;(t=>{t.HORIZONTAL="float calculateMask() {\n return step((direction * io_UV.x + (1.0 - direction) * 0.5), progress);\n }",t.VERTICAL="float calculateMask() {\n return step((direction * io_UV.y + (1.0 - direction) * 0.5), progress);\n }",t.DIAGONAL="float calculateMask() {\n float d = (io_UV.x + io_UV.y) * (0.1);\n return step((direction * d + (1.0 - direction) * 0.5), progress);\n }",t.CIRCLE_LEFT="float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / 3.14159265;\n angle *= 0.5;\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }",t.CIRCLE_TOP="float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / (2.0 * 3.14159265);\n angle = mod(angle + 0.25, 1.0);\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }"})(ri||(ri={}));class hi extends Xt{constructor(t,i,s={}){const e=i.image?.width,r=i.image?.height;It(e,"UIProgress foreground texture width"),It(r,"UIProgress foreground texture height"),s.backgroundTexture&&(It(s.backgroundTexture.image.width,"UIProgress background texture width"),It(s.backgroundTexture.image.height,"UIProgress background texture height"));const n=s.color??new Z,h=s.foregroundColor??new Z,o=s.backgroundColor??new Z,a=s.progress??1,l=s.inverseDirection??!1;super(t,s.x??0,s.y??0,e,r,(s.maskFunction??ri.HORIZONTAL)+"void main() {\n vec4 foregroundDiffuseColor = texture(foregroundTexture, io_UV) * foregroundColor * color;\n vec4 backgroundDiffuseColor = texture(backgroundTexture, io_UV) * backgroundColor * color;\n\n float mask = calculateMask();\n vec4 diffuseColor = foregroundDiffuseColor * mask\n + backgroundDiffuseColor * (1.0 - foregroundDiffuseColor.a * mask);\n\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n",{foregroundTexture:i,backgroundTexture:s.backgroundTexture??ei,color:n,foregroundColor:h,backgroundColor:o,progress:a,direction:l?-1:1}),this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.yi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"foregroundColor",t)},this.bi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"backgroundColor",t)},this.xi=i,this._i=s.backgroundTexture,this.ai=n,this.Ii=h,this.Ei=o,this.Pi=a,this.Ui=l,this.ai.on(J.CHANGE,this.hi),this.Ii.on(J.CHANGE,this.yi),this.Ei.on(J.CHANGE,this.bi),void 0!==s.mode&&(this.mode=s.mode)}get foregroundTexture(){return this.xi}get backgroundTexture(){return this._i}get color(){return this.ai}get foregroundColor(){return this.Ii}get backgroundColor(){return this.Ei}get progress(){return this.Pi}get inverseDirection(){return this.Ui}set foregroundTexture(t){const i=t.image.width,s=t.image.height;It(i,"UIProgress foreground texture width"),It(s,"UIProgress foreground texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.xi=t,this.sceneWrapper.setUniform(this.planeHandler,"foregroundTexture",t)}set backgroundTexture(t){void 0!==t&&(It(t.image.width,"UIProgress background texture width"),It(t.image.height,"UIProgress background texture height")),this._i=t,this.sceneWrapper.setUniform(this.planeHandler,"backgroundTexture",t)}set color(t){this.ai.copy(t)}set foregroundColor(t){this.Ii.copy(t)}set backgroundColor(t){this.Ei.copy(t)}set inverseDirection(t){this.Ui=t,this.sceneWrapper.setUniform(this.planeHandler,"direction",t?-1:1)}set progress(t){this.Pi=t,this.sceneWrapper.setUniform(this.planeHandler,"progress",t)}destroy(){this.ai.off(J.CHANGE,this.hi),this.Ii.off(J.CHANGE,this.yi),this.Ei.off(J.CHANGE,this.bi),super.destroy()}}(t=>{t[t.EACH_FRAME=1]="EACH_FRAME",t[t.EACH_SECOND_FRAME=2]="EACH_SECOND_FRAME",t[t.PROPERTY_CHANGED=3]="PROPERTY_CHANGED",t[t.MANUAL=4]="MANUAL"})(ni||(ni={}));const oi=ni.PROPERTY_CHANGED;class ai extends Xt{constructor(t,i={}){const e=i.resolutionFactor??.5;if(.1>e||e>2)throw Error(`Invalid resolution factor: ${e}. Must be between 0.1 and 2.`);const r=i.width??512,n=i.height??512,h=new v(r*e,n*e,{format:y,minFilter:w,magFilter:w,type:m,depthBuffer:i.enableDepthBuffer??!0,stencilBuffer:!1}),o=i.color??new Z;super(t,0,0,r,n,Ft,{map:h.texture,uvTransform:new u,color:o}),this.Ci=!0,this.Si=!1,this.Mi=!1,this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.Ti=h,this.Vi=i.scene??new s,this.Bi=i.camera??new b(75,r/n,.1,100),this.Ai=e,this.Hi=i.updateMode??oi,this.Ri=i.clearColor??0,this.zi=i.clearAlpha??0,i.updateMode===ni.PROPERTY_CHANGED&&(this.Mi=!0),this.ai=o,this.ai.on(J.CHANGE,this.hi),void 0!==i.mode&&(this.mode=i.mode)}get color(){return this.ai}get scene(){return this.Vi}get camera(){return this.Bi}get updateMode(){return this.Hi}get resolutionFactor(){return this.Ai}get clearColor(){return this.Ri}get clearAlpha(){return this.zi}set color(t){this.ai.copy(t)}set scene(t){this.Vi!==t&&(this.Vi=t,this.Si=!0)}set camera(t){this.Bi!==t&&(this.Bi=t,this.Si=!0)}set updateMode(t){this.Hi!==t&&(this.Hi=t,this.Si=!0)}set resolutionFactor(t){this.Ai!==t&&(this.Ai=t,this.Ti.setSize(this.width*this.Ai,this.height*this.Ai),this.Si=!0)}set clearColor(t){this.Ri!==t&&(this.Ri=t,this.Si=!0)}set clearAlpha(t){this.zi!==t&&(this.zi=t,this.Si=!0)}destroy(){this.ai.off(J.CHANGE,this.hi),this.Ti.dispose(),super.destroy()}requestRender(){this.Mi=!0}onWillRender(t){(this.Hi===ni.EACH_FRAME||this.Hi===ni.EACH_SECOND_FRAME&&this.Ci||this.Hi===ni.PROPERTY_CHANGED&&this.Si||this.Hi===ni.MANUAL&&this.Mi)&&(this.Mi=!1,this.Si=!1,this.Ci=!this.Ci,this.Ti.setSize(this.width*this.Ai,this.height*this.Ai),t.setClearColor(this.Ri,this.clearAlpha),t.setRenderTarget(this.Ti),t.clear(!0,!0,!1),t.render(this.Vi,this.Bi))}}function li(t){return"object"==typeof t&&null!==t&&!("string"!=typeof t.color||"left"!==t.align&&"center"!==t.align&&"right"!==t.align||"string"!=typeof t.fontFamily||"number"!=typeof t.fontSize||"normal"!==t.fontStyle&&"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||"normal"!==t.fontWeight&&"bold"!==t.fontWeight&&"bolder"!==t.fontWeight&&"lighter"!==t.fontWeight&&"number"!=typeof t.fontWeight||"number"!=typeof t.lineHeight||"boolean"!=typeof t.enableShadow||"number"!=typeof t.shadowOffsetX||"number"!=typeof t.shadowOffsetY||"number"!=typeof t.shadowBlur||"string"!=typeof t.shadowColor||"boolean"!=typeof t.enableStroke||"string"!=typeof t.strokeColor||"number"!=typeof t.strokeWidth)}const ci={color:"#000000",align:"left",fontFamily:"Arial",fontSize:16,fontStyle:"normal",fontWeight:"normal",lineHeight:1.2,enableShadow:!1,shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,shadowColor:"transparent",enableStroke:!1,strokeColor:"#000000",strokeWidth:0};function ui(t,i){const s=t?.fontSize??i?.fontSize??16;It(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&It(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;_t(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;Et(n,"Shadow offset X");const h=t?.shadowOffsetY??i?.shadowOffsetY??0;Et(h,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;Et(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return Et(a,"Stroke width"),{color:t?.color??i?.color??ci.color,align:t?.align??i?.align??"left",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize:s,fontStyle:t?.fontStyle??i?.fontStyle??"normal",fontWeight:e,lineHeight:r,enableShadow:t?.enableShadow??i?.enableShadow??!1,shadowOffsetX:n,shadowOffsetY:h,shadowBlur:o,shadowColor:t?.shadowColor??i?.shadowColor??"transparent",enableStroke:t?.enableStroke??i?.enableStroke??!1,strokeColor:t?.strokeColor??i?.strokeColor??"#000000",strokeWidth:a}}function fi(t){return t.match(/\S+|\s|\n/g)??[]}function di(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 pi(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}}function gi(t,i,s,e,r){r.font=`${e.fontStyle} ${e.fontWeight} ${e.fontSize}px ${e.fontFamily}`,e.enableShadow&&(r.shadowOffsetX=e.shadowOffsetX,r.shadowOffsetY=e.shadowOffsetY,r.shadowBlur=e.shadowBlur,r.shadowColor=e.shadowColor),e.enableStroke&&(r.strokeStyle=e.strokeColor,r.lineWidth=e.strokeWidth,r.strokeText(s,t,i)),r.fillStyle=e.color,r.fillText(s,t,i)}function wi(t){if("number"==typeof t)return{left:t,right:t,top:t,bottom:t};if("object"==typeof t&&null!==t){const i="left"in t&&"number"==typeof t.left?t.left:0,s="right"in t&&"number"==typeof t.right?t.right:0,e="top"in t&&"number"==typeof t.top?t.top:0,r="bottom"in t&&"number"==typeof t.bottom?t.bottom:0;return Et(i,"Padding left"),Et(s,"Padding right"),Et(e,"Padding top"),Et(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class vi extends Xt{constructor(t,i,s={}){const e=new OffscreenCanvas(2,2),r=e.getContext("2d");if(!r)throw Error("UIText failed to create canvas context");const n=new g(e),h=s.color??new Z;super(t,s.x??0,s.y??0,2,2,Ft,{map:n,uvTransform:new u,color:h}),this.ki=1,this.hi=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.fi=e,this.$i=r,this.Li=n,this.Wi=i,this.Fi=s.maxWidth??1024,this.Di=wi(s.padding),this.Ni=s.commonStyle??{},this.ai=h,this.ai.on(J.CHANGE,this.hi),this.Oi(),void 0!==s.mode&&(this.mode=s.mode)}get color(){return this.ai}get content(){return this.Wi}get maxWidth(){return this.Fi}get padding(){return this.Di}get commonStyle(){return this.Ni}set color(t){this.ai.copy(t)}set content(t){this.Wi=t,this.Oi()}set maxWidth(t){this.Fi=t,this.Oi()}set padding(t){this.Di=t,this.Oi()}set commonStyle(t){this.Ni=t,this.Oi()}destroy(){this.ai.off(J.CHANGE,this.hi),this.Li.dispose(),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.ki!==this.width/this.height&&(this.height=this.width/this.ki)}Oi(){const{lines:t,size:i}=((t,i,s,e)=>{const r=[];for(const s of Array.isArray(i)?i:[i]){const i="string"==typeof s,n=i?s:s.text,h=ui(i?void 0:s.style,e);for(const i of fi(n)){const s=di(t,i,h);r.push({text:i,style:h,metrics:s})}}const n=((t,i)=>{const s=[];let e=[],r=0,n=0,h=0,o=0;for(const a of i)"\n"!==a.text?r+a.metrics.width>t&&0!==e.length?(s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[a],r=a.metrics.width,n=a.metrics.height,h=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),r+=a.metrics.width,n=Math.max(n,a.metrics.height),h=Math.max(h,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[],r=0,n=0,h=0,o=0);return e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),s})(s,r);return{lines:n,size:pi(n)}})(this.$i,this.content,this.Fi,this.Ni);this.fi.width=i.width+this.Di.left+this.Di.right,this.fi.height=i.height+this.Di.top+this.Di.bottom,this.width=this.fi.width,this.height=this.fi.height,this.ki=this.fi.width/this.fi.height,((t,i,s,e)=>{let r=this.Di.top,n=0;for(const t of s)n=Math.max(t.width,n);for(let t=0;s.length>t;t++){const h=s[t],o=h.chunks[0]?.style.align??"left",a=h.chunks.every(t=>t.style.align===o)?o:"left";let l=0;"center"===a?l=(n-h.width)/2:"right"===a&&(l=n-h.width);let c=i+l;r+=0===t?h.height:h.lineHeight;for(const t of h.chunks)gi(c,r,t.text,t.style,e),c+=t.metrics.width}})(0,this.Di.left,t,this.$i),this.Li.dispose(),this.Li=new g(this.fi),this.Li.needsUpdate=!0,this.sceneWrapper.setUniform(this.planeHandler,"map",this.Li)}}var mi;(t=>{t[t.CHANGE=0]="CHANGE"})(mi||(mi={}));class yi extends P{}class bi extends yi{calculateScaleInternal(t,i){return 1}}class xi extends pt{constructor(t=new bi,i=U.VISIBLE){super(window.innerWidth,window.innerHeight),this.qi=()=>{const t=this.ji.calculateScaleInternal(window.innerWidth,window.innerHeight);this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Gi=t=>{this.Yi(t,"onPointerDownInternal",$t.DOWN)},this.Xi=t=>{this.Yi(t,"onPointerMoveInternal",$t.MOVE)},this.Ji=t=>{this.Yi(t,"onPointerUpInternal",$t.UP)},window.addEventListener("resize",this.qi),window.addEventListener("pointerdown",this.Gi),window.addEventListener("pointermove",this.Xi),window.addEventListener("pointerup",this.Ji),this.mode=i,this.ji=t,this.ji.on(mi.CHANGE,this.qi),this.qi()}get resizePolicy(){return this.ji}set resizePolicy(t){this.ji!==t&&(this.ji.off(mi.CHANGE,this.qi),this.ji=t,this.ji.on(mi.CHANGE,this.qi),this.qi())}destroy(){window.removeEventListener("resize",this.qi),window.removeEventListener("pointerdown",this.Gi),window.removeEventListener("pointermove",this.Xi),window.removeEventListener("pointerup",this.Ji),this.ji.off(mi.CHANGE,this.qi)}render(t,i){_t(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}projectWorldPosition(t,i){const s=t.project(i);return s.x=d.mapLinear(s.x,-1,1,this.x,this.width),s.y=d.mapLinear(s.y,-1,1,this.y,this.height),s}Yi(t,i,s){const e=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,r=e?t.clientX-e.left:t.clientX,n=e?e.bottom-t.clientY:window.innerHeight-t.clientY,h=this.ji.calculateScaleInternal(window.innerWidth,window.innerHeight),o=r*h,a=n*h;this[i](o,a,t.pointerId),this.mode===U.INTERACTIVE&&this.emit(s,o,a,t.pointerId)}}const _i=(()=>{const i=new t(1,1),s=new x;return s.index=i.index,s.setAttribute("position",i.attributes.position),s.setAttribute("uv",i.attributes.uv),i.dispose(),s})();function Ii(t){if("Texture"===t||t instanceof o)return{glslType:"sampler2D",instantiable:!1,itemSize:-1};if("UIColor"===t||t instanceof Z)return{glslType:"vec4",instantiable:!0,itemSize:4};if("Vector2"===t||t instanceof a)return{glslType:"vec2",instantiable:!0,itemSize:2};if("Vector3"===t||t instanceof l)return{glslType:"vec3",instantiable:!0,itemSize:3};if("Vector4"===t||t instanceof n)return{glslType:"vec4",instantiable:!0,itemSize:4};if("Matrix2"===t||t instanceof c)return{glslType:"mat2",instantiable:!0,itemSize:4};if("Matrix3"===t||t instanceof u)return{glslType:"mat3",instantiable:!0,itemSize:9};if("Matrix4"===t||t instanceof f)return{glslType:"mat4",instantiable:!0,itemSize:16};if("number"===t||"number"==typeof t)return{glslType:"float",instantiable:!0,itemSize:1};throw Error("Unsupported property type: "+t)}function Ei(t,i,s){const e=i.array;if(t instanceof Z)e[s]=t.r,e[s+1]=t.g,e[s+2]=t.b,e[s+3]=t.a;else if(t instanceof a)e[s]=t.x,e[s+1]=t.y;else if(t instanceof l)e[s]=t.x,e[s+1]=t.y,e[s+2]=t.z;else if(t instanceof n)e[s]=t.x,e[s+1]=t.y,e[s+2]=t.z,e[s+3]=t.w;else if(t instanceof c){const i=t.elements;for(let t=0;i.length>t;t++)e[s+t]=i[t]}else if(t instanceof u){const i=t.elements;for(let t=0;i.length>t;t++)e[s+t]=i[t]}else if(t instanceof f){const i=t.elements;for(let t=0;i.length>t;t++)e[s+t]=i[t]}else"number"==typeof t&&(e[s]=t);i.needsUpdate=!0}function Pi(t,i){const s=Ii(t);if(!s.instantiable)throw Error("Invalid property type: "+t);return new _(new Float32Array(i*s.itemSize),s.itemSize)}class Ui extends h{constructor(t,i,s=Q.CLIP,e=16){const n={},h={instanceTransform:"Matrix4",uvTransform:"Matrix3",...s===Q.CLIP?{alphaTest:"number"}:{}};for(const[t,s]of Object.entries(i))(Ii(s).instantiable?h:n)[t]=s;const o=_i.clone(),a=((t,i,s,e)=>{const n={},h=[],o=[],a=[],l=[];for(const[t,s]of Object.entries(i)){const i=Ii(s).glslType;n["u_"+t]={value:null},h.push(`uniform ${i} u_${t};`)}for(const[t,i]of Object.entries(s)){const s=Ii(i).glslType;o.push(`attribute ${s} a_${t};`),a.push(`varying ${s} v_${t};`),l.push(`v_${t} = a_${t};`)}const c=`\n ${o.join("\n")}\n\n ${h.join("\n")}\n\n ${a.join("\n")}\n varying vec3 v_position;\n varying vec2 v_uv;\n\n void main() {\n if (a_visibility < 0.5) {\n gl_Position = vec4(2.0, 2.0, 2.0, 2.0);\n return;\n }\n\n ${l.join("\n")}\n\n v_position = position;\n v_uv = (a_uvTransform * vec3(uv, 1.0)).xy;\n\n gl_Position = projectionMatrix * modelViewMatrix * a_instanceTransform * vec4(position, 1.0);\n }\n `,u=`\n ${h.join("\n")}\n\n ${a.join("\n")}\n varying vec3 v_position;\n varying vec2 v_uv;\n\n #include <alphahash_pars_fragment>\n\n // Source have to define 'draw' function\n ${t}\n\n void main() {\n vec4 diffuseColor = draw();\n\n #ifdef USE_ALPHATEST\n if (diffuseColor.a < v_alphaTest) {\n discard;\n }\n #endif\n\n #ifdef USE_ALPHAHASH\n if (diffuseColor.a < getAlphaHashThreshold(v_position)) {\n discard;\n }\n #endif\n\n gl_FragColor = linearToOutputTexel(diffuseColor);\n }\n `;return new r({uniforms:n,vertexShader:c,fragmentShader:u,transparent:e===Q.BLEND,alphaTest:e===Q.CLIP?.5:0,alphaHash:e===Q.HASH})})(t,n,h,s);super(o,a),this.handlerToDescriptor=new Map,this.lastHandler=0,this.capacity=0,this.propertyBuffers=new Map,this.Qi=o,this.Qi.instanceCount=0,this.Zi=a,this.capacity=Math.max(e,16);for(const[t,i]of Object.entries(h)){const s=Pi(i,this.capacity);this.Qi.setAttribute("a_"+t,s),this.propertyBuffers.set("a_"+t,s)}}createInstances(t){const i=this.lastHandler++;return this.Qi.instanceCount+t>this.capacity&&this.Ki(16*Math.ceil((this.capacity+t)/16)),this.handlerToDescriptor.set(i,{firstIndex:this.Qi.instanceCount,count:t}),this.Qi.instanceCount+=t,i}destroyInstances(t){const i=this.handlerToDescriptor.get(t);if(void 0===i)throw Error("No range found for userIndex: "+t);this.handlerToDescriptor.delete(t);const s=Array.from(this.handlerToDescriptor.values()),e=i.firstIndex+i.count;let r;for(let t=s.length-1;t>e;t--){const e=s[t];if(e.count===i.count){r=e;break}}r?(this.ts(r,i),r.firstIndex=i.firstIndex,this.ss(r.firstIndex+r.count,r.count)):this.ss(i.firstIndex+i.count,i.count),this.Qi.instanceCount-=i.count}updateProperties(t,i,s){Et(i,"UIGenericInstancedPlane updateProperties offset");const e=this.bt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=s[t],n=e.firstIndex+i+t;for(const[t,i]of Object.entries(r))if(Ii(i).instantiable){const s=this.es(t);Ei(i,s,n*s.itemSize)}else this.rs(t).value=i,this.Zi.uniformsNeedUpdate=!0}}updateTransforms(t,i,s){Et(i,"UIGenericInstancedPlane updateTransforms offset");const e=this.bt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=this.es("instanceTransform"),n=r.array,h=(e.firstIndex+i+t)*r.itemSize,o=s[t].elements;for(let t=0;o.length>t;t++)n[h+t]=o[t];r.needsUpdate=!0}}updateUVTransforms(t,i,s){Et(i,"UIGenericInstancedPlane updateUVTransforms offset");const e=this.bt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=this.es("uvTransform"),n=r.array,h=(e.firstIndex+i+t)*r.itemSize,o=s[t].elements;for(let t=0;o.length>t;t++)n[h+t]=o[t];r.needsUpdate=!0}}updateVisibility(t,i,s){Et(i,"UIGenericInstancedPlane updateVisibility offset");const e=this.bt(t);if(s.length+i>e.count)throw Error(`Too many instances for handler: ${t}, offset: ${i}, and count: ${s.length}`);for(let t=0;s.length>t;t++){const r=this.es("visibility");r.array[(e.firstIndex+i+t)*r.itemSize]=s[t]?1:0,r.needsUpdate=!0}}destroy(){this.Qi.dispose(),this.Zi.dispose()}bt(t){const i=this.handlerToDescriptor.get(t);if(void 0===i)throw Error("No active range found for handler: "+t);return i}es(t){const i=this.propertyBuffers.get("a_"+t);if(void 0===i)throw Error(`No attribute found for property: ${t} (a_${t})`);return i}rs(t){const i=this.Zi.uniforms["u_"+t];if(void 0===i)throw Error("No uniform found for handler: "+t);return i}Ki(t){for(const[i,s]of this.propertyBuffers.entries()){const e=s.itemSize,r=new Float32Array(t*e);r.set(s.array);const n=new _(r,e);this.Qi.setAttribute("a_"+i,n),this.propertyBuffers.set("a_"+i,n)}this.capacity=t}ts(t,i){for(const s of this.propertyBuffers.values()){const e=s.array,r=s.itemSize,n=t.firstIndex*r,h=i.firstIndex*r,o=t.count*r;for(let t=0;o>t;t++)e[h+t]=e[n+t];s.needsUpdate=!0}}ss(t,i){for(const s of this.handlerToDescriptor.values())t>s.firstIndex||(s.firstIndex-=i);for(const s of this.propertyBuffers.values()){const e=s.array,r=s.itemSize,n=this.Qi.instanceCount*r,h=i*r;for(let i=t*r;n-h>i;i++)e[i]=e[i+h];s.needsUpdate=!0}}}class Ci extends yi{constructor(t,i){super(),It(t,"UIResizePolicyCross.fixedWidthLandscape"),It(i,"UIResizePolicyCross.fixedHeightPortrait"),this.ns=t,this.hs=i}get fixedWidthLandscape(){return this.ns}get fixedHeightPortrait(){return this.hs}set fixedWidthLandscape(t){It(t,"UIResizePolicyCross.fixedWidthLandscape"),t!==this.ns&&(this.ns=t,this.emit(mi.CHANGE))}set fixedHeightPortrait(t){It(t,"UIResizePolicyCross.fixedHeightPortrait"),t!==this.hs&&(this.hs=t,this.emit(mi.CHANGE))}calculateScaleInternal(t,i){return t>i?this.ns/t:this.hs/i}}class Si extends yi{constructor(t,i){super(),It(t,"UIResizePolicyCrossInverted.fixedHeightLandscape"),It(i,"UIResizePolicyCrossInverted.fixedWidthPortrait"),this.ls=t,this.cs=i}get fixedHeightLandscape(){return this.ls}get fixedWidthPortrait(){return this.cs}set fixedHeightLandscape(t){It(t,"UIResizePolicyCrossInverted.fixedHeightLandscape"),t!==this.ls&&(this.ls=t,this.emit(mi.CHANGE))}set fixedWidthPortrait(t){It(t,"UIResizePolicyCrossInverted.fixedWidthPortrait"),t!==this.cs&&(this.cs=t,this.emit(mi.CHANGE))}calculateScaleInternal(t,i){return t>i?this.ls/i:this.cs/t}}class Mi extends yi{constructor(t,i,s=i,e=.1){super(),It(t,"UIResizePolicyFixedHeight.fixedHeightLandscape"),It(i,"UIResizePolicyFixedHeight.fixedHeightPortrait"),It(s,"UIResizePolicyFixedHeight.fixedHeightSquare"),It(e,"UIResizePolicy.squareEpsilon"),this.ls=t,this.hs=i,this.us=s,this.fs=e}get fixedHeightLandscape(){return this.ls}get fixedHeightPortrait(){return this.hs}get fixedHeightSquare(){return this.us}get squareEpsilon(){return this.fs}set fixedHeightLandscape(t){It(t,"UIResizePolicyFixedHeight.fixedHeightLandscape"),t!==this.ls&&(this.ls=t,this.emit(mi.CHANGE))}set fixedHeightPortrait(t){It(t,"UIResizePolicyFixedHeight.fixedHeightPortrait"),t!==this.hs&&(this.hs=t,this.emit(mi.CHANGE))}set fixedHeightSquare(t){It(t,"UIResizePolicyFixedHeight.fixedHeightSquare"),t!==this.us&&(this.us=t,this.emit(mi.CHANGE))}set squareEpsilon(t){It(t,"UIResizePolicy.squareEpsilon"),t!==this.fs&&(this.fs=t,this.emit(mi.CHANGE))}calculateScaleInternal(t,i){return this.ds(t,i)?this.us/i:t>i?this.ls/i:this.hs/i}ds(t,i){return this.fs>=Math.abs(t/i-1)}}class Ti extends yi{constructor(t,i,s=i,e=.1){super(),It(t,"UIResizePolicyFixedWidth.fixedWidthLandscape"),It(i,"UIResizePolicyFixedWidth.fixedWidthPortrait"),It(s,"UIResizePolicyFixedWidth.fixedWidthSquare"),It(e,"UIResizePolicy.squareEpsilon"),this.ns=t,this.cs=i,this.ps=s,this.fs=e}get fixedWidthLandscape(){return this.ns}get fixedWidthPortrait(){return this.cs}get fixedWidthSquare(){return this.ps}get squareEpsilon(){return this.fs}set fixedWidthLandscape(t){It(t,"UIResizePolicyFixedWidth.fixedWidthLandscape"),t!==this.ns&&(this.ns=t,this.emit(mi.CHANGE))}set fixedWidthPortrait(t){It(t,"UIResizePolicyFixedWidth.fixedWidthPortrait"),t!==this.cs&&(this.cs=t,this.emit(mi.CHANGE))}set fixedWidthSquare(t){It(t,"UIResizePolicyFixedWidth.fixedWidthSquare"),t!==this.ps&&(this.ps=t,this.emit(mi.CHANGE))}set squareEpsilon(t){It(t,"UIResizePolicy.squareEpsilon"),t!==this.fs&&(this.fs=t,this.emit(mi.CHANGE))}calculateScaleInternal(t,i){return this.ds(t,i)?this.ps/t:t>i?this.ns/t:this.cs/t}ds(t,i){return this.fs>=Math.abs(t/i-1)}}function Vi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||li(t.style))}export{ci as DEFAULT_TEXT_STYLE,kt as UIAnchor,Qt as UIAnimatedImage,Jt as UIAnimatedImageEvent,Vt as UIAspectConstraint,Z as UIColor,J as UIColorEvent,gt as UIConstraint,Tt as UIConstraint2DBuilder,At as UICoverConstraintBuilder,zt as UICustomConstraint,Zt as UIDummy,Xt as UIElement,I as UIExpression,Rt as UIFitConstraintBuilder,xi as UIFullscreenLayer,Ui as UIGenericInstancedPlane,Kt as UIGraphics,vt as UIHeightConstraint,Pt as UIHorizontalDistanceConstraint,Ut as UIHorizontalProportionConstraint,ti as UIImage,$t as UIInputEvent,pt as UILayer,ct as UILayerEvent,Nt as UIMicro,Lt as UIMicroAnchorMode,Wt as UIMicroEvent,U as UIMode,si as UINineSlice,C as UIOrientation,j as UIPriority,hi as UIProgress,ri as UIProgressMaskFunction,lt as UIRelation,yi as UIResizePolicy,Ci as UIResizePolicyCross,Si as UIResizePolicyCrossInverted,mi as UIResizePolicyEvent,Mi as UIResizePolicyFixedHeight,Ti as UIResizePolicyFixedWidth,bi as UIResizePolicyNone,ai as UIScene,ni as UISceneUpdateMode,wt as UISingleParameterConstraint,vi as UIText,Q as UITransparencyMode,Ct as UIVerticalDistanceConstraint,St as UIVerticalProportionConstraint,Mt as UIWidthConstraint,G as convertPriority,ut as convertRelation,Vi as isUITextSpan,li as isUITextStyle,S as resolveOrientation,Y as resolvePriority,ft as resolveRelation,wi as resolveTextPadding,ui as resolveTextStyle};
|
|
2
2
|
//# sourceMappingURL=index.min.js.map
|