laymur 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import{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,WebGLRenderTarget as g,UnsignedByteType as w,LinearFilter as m,RGBAFormat as v,PerspectiveCamera as y,CanvasTexture as b,InstancedBufferGeometry as x,InstancedBufferAttribute as _}from"three";class E{constructor(t=0,i){this.constant=t,this._=i?new Map(i):new Map}static plus(t,i){const s=new E(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 E(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 E(this.constant,Array.from(this._.entries()))}prepareTermsInternal(){return Array.from(this._.entries())}}class C{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 I{constructor(){this.o=new Map}on(t,i,s,e=0){return this.h(t,!1,e,i,s),this}once(t,i,s,e=0){return this.h(t,!0,e,i,s),this}off(t,i,s){const e=this.o.get(t);if(void 0===e)return this;e.u&&(e.u=!1,e.v=e.v.slice());const r=e.v;if(0===r.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;r.length>t;t++){const i=r[t];e.l.remove(i.C,i.p)}return this}{const n=r.length;if(r[0].C===i&&r[0].p===s)return 1===n?this.o.delete(t):r.shift(),this;const h=n-1;if(r[h].C===i&&r[h].p===s)return r.pop(),this;if(10>n||r[0].M===r[h].M)for(let t=1;h>t;t++){const e=r[t];if(e.C===i&&e.p===s)return r.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let n=0,h=r.length-1;for(;h>=n;){const i=n+h>>>1;t>r[i].M?n=i+1:h=i-1}const o=n;for(h=r.length-1;h>=n;){const i=n+h>>>1;r[i].M>t?h=i-1:n=i+1}const a=h;for(let t=o;a>=t;t++)if(r[t].C===i&&r[t].p===s)return r.splice(t,1),this}}return this}emit(t,...i){const s=this.o.get(t);if(void 0===s)return!1;if(0===s.v.length)return!1;s.u?s.v=s.v.slice():s.u=!0;const e=s.v;let r=!1;for(let t=0;e.length>t;t++){const s=e[t];s.C.apply(s.p,i),s.k&&(r=!0,s.m=!0)}const n=this.o.get(t);if(void 0===n)return!0;n.v===e&&(n.u=!1);const h=n.v;if(r){let i=0;for(let t=0;h.length>t;t++){const s=h[t];s.m?n.l.remove(s.C,s.p):h[i++]=s}0===i?this.o.delete(t):h.length=i}return!0}h(t,i,s,e,r){let n=this.o.get(t);if(void 0===n)return void this.o.set(t,{v:[{C:e,p:r,M:s,k:i,m:!1}],u:!1,l:new C(e,r,s)});if(n.l.has(e,r))throw Error("Event listener already exists");n.l.insert(e,r,s);const h={C:e,p:r,M:s,k:i,m:!1};n.u&&(n.u=!1,n.v=n.v.slice());{const t=n.v,i=h.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(h);if(t[0].M>=i)return void t.unshift(h);{let s=0,e=t.length;for(;e>s;){const r=s+e>>>1;i>t[r].M?s=r+1:e=r}t.splice(s,0,h)}}}}var U,M;function S(t){return t??M.ALWAYS}function T(){return new B}(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"})(M||(M={}));class B{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new V(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new V(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new B;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class V{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new V(this.first,this.second)}}class A{constructor(t=""){this.I=t}id(){return this.U}name(){return this.I}setName(t){this.I=t}context(){return this.S}setContext(t){this.S=t}value(){return this.T}setValue(t){this.T=t}plus(t){return new P(this,t)}minus(t){return new P(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new P([t,this])}divide(t){return new P([1/t,this])}toJSON(){return{name:this.I,value:this.T}}toString(){return this.S+"["+this.I+":"+this.T+"]"}I;T=0;S=null;U=k++}let k=0;class P{constructor(){let t=(t=>{let i=0,s=()=>0,e=T();for(let r=0,n=t.length;n>r;++r){let n=t[r];if("number"==typeof n)i+=n;else if(n instanceof A)e.setDefault(n,s).second+=1;else if(n instanceof P){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 A)e.setDefault(r,s).second+=t;else{if(!(r instanceof P))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.B=t.terms,this.V=t.constant}terms(){return this.B}constant(){return this.V}value(){let t=this.V;for(let i=0,s=this.B.size();s>i;i++){let s=this.B.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new P(this,t)}minus(t){return new P(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new P([t,this])}divide(t){return new P([1/t,this])}isConstant(){return 0==this.B.size()}toString(){let t=this.B.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.V||(t+=" + "),t+=this.V,t}B;V}class ${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=$.create(1e3,1e3,1e3);static strong=$.create(1,0,0);static medium=$.create(0,1,0);static weak=$.create(0,0,1);static clip(t){return Math.max(0,Math.min($.required,t))}}var H;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(H||(H={}));class L{constructor(t,i,s,e=$.required){this.A=i,this.P=$.clip(e),this.$=void 0===s&&t instanceof P?t:t.minus(s)}id(){return this.U}expression(){return this.$}op(){return this.A}strength(){return this.P}toString(){return this.$+" "+["<=",">=","="][this.A]+" 0 ("+this.P+")"}$;A;P;U=R++}let R=0;class z{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=$.required){let r=new L(t,i,s,e);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.H.find(t))throw Error("duplicate constraint");let i=this.L(t),s=i.row,e=i.tag,r=this.R(s,e);if(r.type()===N.Invalid&&s.allDummies()){if(!D(s.constant()))throw Error("unsatisfiable constraint");r=e.marker}if(r.type()===N.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.N(r,s),this.O.insert(r,s);this.H.insert(t,e),this.F(this.j)}removeConstraint(t){let i=this.H.erase(t);if(void 0===i)throw Error("unknown constraint");this.W(t,i.second);let s=i.second.marker,e=this.O.erase(s);if(void 0===e){let t=this.G(s);if(t.type()===N.Invalid)throw Error("failed to find leaving row");e=this.O.erase(t),e.second.solveForEx(t,s),this.N(s,e.second)}this.F(this.j)}hasConstraint(t){return this.H.contains(t)}getConstraints(){return this.H.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.q.find(t))throw Error("duplicate edit variable");if((i=$.clip(i))===$.required)throw Error("bad required strength");let s=new P(t),e=new L(s,H.Eq,void 0,i);this.addConstraint(e);let r=this.H.find(e).second;this.q.insert(t,{tag:r,constraint:e,constant:0})}removeEditVariable(t){let i=this.q.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.q.contains(t)}suggestValue(t,i){let s=this.q.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.O,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()!==N.External&&this.Y.push(i.first)}this.X()}updateVariables(){let t=this.Z,i=this.O;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),r=i.find(e.second);e.first.setValue(void 0!==r?r.second.constant():0)}}J(t){return this.Z.setDefault(t,()=>this.K(N.External)).second}L(t){let i=t.expression(),s=new j(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!D(i.second)){let t=this.J(i.first),e=this.O.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let r=this.j,n=t.strength(),h={marker:F,other:F};switch(t.op()){case H.Le:case H.Ge:{let i=t.op()===H.Le?1:-1,e=this.K(N.Slack);if(h.marker=e,s.insertSymbol(e,i),$.required>n){let t=this.K(N.Error);h.other=t,s.insertSymbol(t,-i),r.insertSymbol(t,n)}break}case H.Eq:if($.required>n){let t=this.K(N.Error),i=this.K(N.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(N.Dummy);h.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:h}}R(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===N.External)return i.first}let e=i.marker.type();return e!==N.Slack&&e!==N.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==N.Slack&&e!==N.Error||t.coefficientFor(i.other)>=0?F:i.other):i.marker}D(t){let i=this.K(N.Slack);this.O.insert(i,t.copy()),this.tt=t.copy(),this.F(this.tt);let s=D(this.tt.constant());this.tt=null;let e=this.O.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let r=this.it(t);if(r.type()===N.Invalid)return!1;t.solveForEx(i,r),this.N(r,t),this.O.insert(r,t)}let r=this.O;for(let t=0,s=r.size();s>t;++t)r.itemAt(t).second.removeSymbol(i);return this.j.removeSymbol(i),s}N(t,i){let s=this.O;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()!==N.External&&this.Y.push(r.first)}this.j.substitute(t,i),this.tt&&this.tt.substitute(t,i)}F(t){let i=0;for(;this.maxIterations>i;){let s=this.st(t);if(s.type()===N.Invalid)return;let e=this.et(s);if(e.type()===N.Invalid)throw Error("the objective is unbounded");let r=this.O.erase(e).second;r.solveForEx(e,s),this.N(s,r),this.O.insert(s,r),i++}throw Error("solver iterations exceeded")}X(){let t=this.O,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()===N.Invalid)throw Error("dual optimize failed");let r=e.second;t.erase(s),r.solveForEx(s,i),this.N(i,r),t.insert(i,r)}}}st(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first;if(0>s.second&&e.type()!==N.Dummy)return e}return F}rt(t){let i=Number.MAX_VALUE,s=F,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()!==N.Dummy){let t=this.j.coefficientFor(n)/h;i>t&&(i=t,s=n)}}return s}et(t){let i=Number.MAX_VALUE,s=F,e=this.O;for(let r=0,n=e.size();n>r;++r){let n=e.itemAt(r),h=n.first;if(h.type()!==N.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}G(t){let i=Number.MAX_VALUE,s=i,e=i,r=F,n=r,h=r,o=r,a=this.O;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()===N.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}W(t,i){i.marker.type()===N.Error&&this.nt(i.marker,t.strength()),i.other.type()===N.Error&&this.nt(i.other,t.strength())}nt(t,i){let s=this.O.find(t);void 0!==s?this.j.insertRow(s.second,-i):this.j.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===N.Slack||e===N.Error)return s.first}return F}K(t){return new O(t,this.ht++)}H=(()=>T())();O=(()=>T())();Z=(()=>T())();q=(()=>T())();Y=[];j=new j;tt=null;ht=0}function D(t){return 0>t?1e-8>-t:1e-8>t}var N;(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"})(N||(N={}));class O{constructor(t,i){this.U=i,this.ot=t}id(){return this.U}type(){return this.ot}U;ot}let F=new O(N.Invalid,-1);class j{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()!==N.Dummy)return!1;return!0}copy(){let t=new j(this.V);return t.lt=this.lt.copy(),t}add(t){return this.V+=t}insertSymbol(t,i=1){D(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=T();V}const W=1e3;var G;function q(t){switch(t){case G.P0:return $.create(W,W,W);case G.P1:return $.create(100,0,0);case G.P2:return $.create(10,0,0);case G.P3:return $.create(0,100,0);case G.P4:return $.create(0,10,0);case G.P5:return $.create(0,0,100);case G.P6:return $.create(0,0,10);case G.P7:return $.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function Y(t){return t??G.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"})(G||(G={}));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 Z,J;(t=>{t.CHANGE="change"})(Z||(Z={}));class Q extends I{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(Z.CHANGE,this)}set g(t){this.gInternal=t,this.emit(Z.CHANGE,this)}set b(t){this.bInternal=t,this.emit(Z.CHANGE,this)}set a(t){this.aInternal=t,this.emit(Z.CHANGE,this)}set(t,i,s,e=this.aInternal){return this.rInternal=t,this.gInternal=i,this.bInternal=s,this.aInternal=e,this.emit(Z.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(Z.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(Z.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 Q?(this.rInternal=t.rInternal,this.gInternal=t.gInternal,this.bInternal=t.bInternal,this.aInternal=t.aInternal):(this.rInternal=t.r,this.gInternal=t.g,this.bInternal=t.b,this.aInternal=1),this.emit(Z.CHANGE,this),this}clone(){return new Q(this.rInternal,this.gInternal,this.bInternal,this.aInternal)}}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(J||(J={}));const K=.25,tt=new Map([[Q,"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 Q?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 Q?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===J.BLEND?(s.material.transparent=!0,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!1):i===J.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 H.Eq;case lt.LESS_THAN:return H.Le;case lt.GREATER_THAN:return H.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 z,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 A;if(i===G.P0){const r={variable:e,priority:i,value:t};this.yt.set(s,r),r.constraint=this.Et(new E(0,[[s,1]]),new E(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,q(i)),this.wt?.suggestValue(e,t)}catch{this.wt=void 0}}return this.vt=!0,s}removeVariable(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error(`Variable ${t} is used in constraint`);try{i.constraint?this.wt?.removeConstraint(i.constraint):this.wt?.removeEditVariable(i.variable)}catch{this.wt=void 0}this.yt.delete(t),this.vt=!0}suggestVariableValue(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);s.value!==i&&(s.value=i,s.constraint?s.constraint=this.Ct(s.constraint,(new E).plus(t,1),new E(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===G.P0){const i=(new E).plus(t,1),e=new E(s.value);s.constraint=this.Et(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.It(t,s)}this.vt=!0}}readVariableValue(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return void 0===this.wt&&this.Ut(),this.vt&&(this.wt?.updateVariables(),this.vt=!1),i.variable.value()}createConstraint(t,i,s,e,r){const n=this._t++,h=this.Et(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.Mt(s),this.vt=!0}setConstraintRHS(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.rhs.copy(i),this.Mt(s),this.vt=!0}setConstraintRelation(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.relation!==i&&(s.relation=i,this.Mt(s),this.vt=!0)}setConstraintPriority(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.priority!==i&&(s.priority=i,this.Mt(s),this.vt=!0)}setConstraintEnabled(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);if(i!==s.enabled){s.enabled=i;try{s.enabled?this.wt?.addConstraint(s.constraint):this.wt?.removeConstraint(s.constraint)}catch{this.wt=void 0}this.vt=!0}}It(t,i){const s=[];for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.wt?.removeConstraint(i.constraint)}catch{this.wt=void 0}s.push(i)}this.wt?.removeEditVariable(i.variable),this.wt?.addEditVariable(i.variable,q(i.priority));for(const t of s)t.constraint=this.Et(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.wt?.addConstraint(t.constraint)}catch{this.wt=void 0;break}}Mt(t){t.constraint=t.enabled?this.Ct(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.Et(t.lhs,t.rhs,t.relation,t.priority)}Ct(t,i,s,e,r){try{this.wt?.removeConstraint(t)}catch{this.wt=void 0}const n=this.Et(i,s,e,r);try{this.wt?.addConstraint(n)}catch{this.wt=void 0}return n}Et(t,i,s,e){return new L(this.St(t),ut(s),this.St(i),q(e))}St(t){return new P(...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 z;for(const t of this.yt.values())t.constraint?this.wt.addConstraint(t.constraint):(this.wt.addEditVariable(t.variable,q(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 I{constructor(t,i){super(),this.name="",this.solverWrapper=new dt,this.modeInternal=U.VISIBLE,this.Tt=[],this.sceneWrapper=new at(t,i),this.xVariable=this.solverWrapper.createVariable(0,G.P0),this.yVariable=this.solverWrapper.createVariable(0,G.P0),this.wVariable=this.solverWrapper.createVariable(t,G.P0),this.hVariable=this.solverWrapper.createVariable(i,G.P0),this.orientationInternal=t>i?M.HORIZONTAL:M.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?M.HORIZONTAL:M.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))}pointerClickInternal(t,i){if(this.mode===U.INTERACTIVE){this.Tt.sort((t,i)=>i.zIndex-t.zIndex);for(const s of this.Tt)if(s.listener.catchClick(t,i))return}}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperClientAPI(){return this.sceneWrapper}listenPointerInput(t,i){if(this.Tt.find(i=>i.listener===t))throw Error("Listener already exists");this.Tt.push({zIndex:i,listener:t})}setListenerZIndex(t,i){const s=this.Tt.findIndex(i=>i.listener===t);if(-1===s)throw Error("Listener not found");this.Tt[s].zIndex=i}unlistenPointerInput(t){const i=this.Tt.findIndex(i=>i.listener===t);if(-1===i)throw Error("Listener not found");this.Tt.splice(i,1)}}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.Bt=()=>{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.Bt)}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.Bt())}destroy(){this.layer.off(ct.ORIENTATION_CHANGE,this.Bt),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===M.ALWAYS||this.orientationInternal===this.layer.orientation}}class mt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Vt=t,this.At=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new E(0,[[this.Vt.hVariable,1]]),new E(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 E(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 Et(t,i){if(_t(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function Ct(t,i){if(_t(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class It extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalDistanceConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.$t=s.anchorA??.5,this.Ht=s.anchorB??.5,this.Lt=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Rt(),new E(this.Lt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Lt}get anchorA(){return this.$t}get anchorB(){return this.Ht}set distance(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintRHS(this.constraint,new E(this.Lt)))}set anchorA(t){this.$t!==t&&(this.$t=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}set anchorB(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}Rt(){let t,i;if(bt(this.kt))t=new E(0,[[this.kt.xVariable,1],[this.kt.wVariable,this.$t]]);else{if(!yt(this.kt))throw Error("A is not a valid element type");t=(new E).plus(this.kt.xVariable,1)}if(bt(this.Pt))i=new E(0,[[this.Pt.xVariable,1],[this.Pt.wVariable,this.Ht]]);else{if(!yt(this.Pt))throw Error("B is not a valid element type");i=(new E).plus(this.Pt.xVariable,1)}return E.minus(i,t)}}class Ut extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalProportionConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.zt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new E(0),this.Dt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt()))}Dt(){return E.minus(new E(0,[[this.kt.wVariable,this.zt]]),new E(0,[[this.Pt.wVariable,1]]))}}class Mt extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalDistanceConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.$t=s.anchorA??.5,this.Ht=s.anchorB??.5,this.Lt=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Rt(),new E(this.Lt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Lt}get anchorA(){return this.$t}get anchorB(){return this.Ht}set distance(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintRHS(this.constraint,new E(this.Lt)))}set anchorA(t){this.$t!==t&&(this.$t=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}set anchorB(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}Rt(){let t,i;if(bt(this.kt))t=new E(0,[[this.kt.yVariable,1],[this.kt.hVariable,this.$t]]);else{if(!yt(this.kt))throw Error("A is not a valid element type");t=(new E).plus(this.kt.yVariable,1)}if(bt(this.Pt))i=new E(0,[[this.Pt.yVariable,1],[this.Pt.hVariable,this.Ht]]);else{if(!yt(this.Pt))throw Error("B is not a valid element type");i=(new E).plus(this.Pt.yVariable,1)}return E.minus(i,t)}}class St extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalProportionConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.zt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new E(0),this.Dt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt()))}Dt(){return E.minus(new E(0,[[this.kt.hVariable,this.zt]]),new E(0,[[this.Pt.hVariable,1]]))}}class Tt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Vt=t,this.Nt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new E(0,[[this.Vt.wVariable,1]]),new E(this.Nt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Nt}set width(t){this.Nt!==t&&(this.Nt=t,this.solverWrapper.setConstraintRHS(this.constraint,new E(t)))}}class Bt{static size(t,i={}){return{h:new Tt(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 It(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 Mt(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.Vt=t,this.Ot=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Rt(),new E(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Ot}set aspect(t){this.Ot!==t&&(this.Ot=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}Rt(){return new E(0,[[this.Vt.wVariable,1],[this.Vt.hVariable,-this.Ot]])}}const At=.5;class kt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new It(t,i,{anchorA:s.anchorH??At,anchorB:s.anchorH??At,orientation:s.orientation}),yConstraint:new Mt(t,i,{anchorA:s.anchorV??At,anchorB:s.anchorV??At,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:G.P1,orientation:s.orientation})}}}const Pt=.5;class $t{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new It(t,i,{anchorA:s.anchorH??Pt,anchorB:s.anchorH??Pt,orientation:s.orientation}),yConstraint:new Mt(t,i,{anchorA:s.anchorV??Pt,anchorB:s.anchorV??Pt,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:G.P1,orientation:s.orientation})}}}class Ht extends wt{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Ft=i,this.jt=s,this.constraint=this.solverWrapper.createConstraint(this.Ft,this.jt,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Ft}get rhs(){return this.jt}setLHS(t){this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ft)}setRHS(t){this.jt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.jt)}}class Lt extends I{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,G.P7),this.yVariable=this.solverWrapper.createVariable(s,G.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)}}class Rt extends Lt{constructor(t,i={}){const s=i.x??0,e=i.y??0,r=i.width??100,n=i.height??100;Et(r,"UIDummy width"),Et(n,"UIDummy height"),super(t,s,e),this.wVariable=this.solverWrapper.createVariable(r,G.P6),this.hVariable=this.solverWrapper.createVariable(n,G.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){Et(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){Et(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}var zt,Dt;(t=>{t.CLICK="click"})(zt||(zt={})),(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(Dt||(Dt={}));const Nt=.5;class Ot{constructor(){this.Wt=0,this.Gt=0,this.qt=Nt,this.Yt=Nt,this.Xt=1,this.Zt=1,this.Jt=0,this.Qt=Dt.ROTATION_SCALE,this.vt=!1}get x(){return this.Wt}get y(){return this.Gt}get anchorX(){return this.qt}get anchorY(){return this.Yt}get scaleX(){return this.Xt}get scaleY(){return this.Zt}get size(){return Math.max(this.Xt,this.Zt)}get angle(){return d.radToDeg(this.Jt)}get anchorMode(){return this.Qt}get rotation(){return this.Jt}set x(t){t!==this.Wt&&(this.Wt=t,this.vt=!0)}set y(t){t!==this.Gt&&(this.Gt=t,this.vt=!0)}set anchorX(t){t!==this.qt&&(this.qt=t,this.vt=!0)}set anchorY(t){t!==this.Yt&&(this.Yt=t,this.vt=!0)}set scaleX(t){t!==this.Xt&&(this.Xt=t,this.vt=!0)}set scaleY(t){t!==this.Zt&&(this.Zt=t,this.vt=!0)}set size(t){t===this.Xt&&t===this.Zt||(this.Xt=t,this.Zt=t,this.vt=!0)}set angle(t){const i=d.degToRad(t);i!==this.Jt&&(this.Jt=i,this.vt=!0)}set rotation(t){t!==this.Jt&&(this.Jt=t,this.vt=!0)}set anchorMode(t){t!==this.Qt&&(this.Qt=t,this.vt=!0)}reset(){0===this.Wt&&0===this.Gt&&this.qt===Nt&&this.Yt===Nt&&1===this.Xt&&1===this.Zt&&0===this.Jt||(this.Wt=0,this.Gt=0,this.qt=Nt,this.Yt=Nt,this.Xt=1,this.Zt=1,this.Jt=0,this.vt=!0)}getRecalculationRequiredInternal(){return this.vt}resetRecalculationRequiredInternal(){this.vt=!1}}const Ft=new l,jt=new p,Wt=new l,Gt=new f,qt=new l(0,0,1);class Yt extends Lt{constructor(t,i,s,e,r,n,h){Et(e,"UIElement width"),Et(r,"UIElement height"),super(t,i,s),this.micro=new Ot,this.modeInternal=U.VISIBLE,this.transparencyInternal=J.CLIP,this.zIndexInternal=0,this.onClick=(t,i)=>{const s=((t,i,s)=>t>s.x&&s.x+s.width>t&&i>s.y&&s.y+s.height>i)(t,i,this);return s&&this.emit(zt.CLICK,t,i,this),s},this.layer.on(ct.WILL_RENDER,this.onWillRender,this),this.wVariable=this.solverWrapper.createVariable(e,G.P6),this.hVariable=this.solverWrapper.createVariable(r,G.P6),this.sceneWrapper=t.getSceneWrapperClientAPI(),this.planeHandler=this.sceneWrapper.createPlane(n,h)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get zIndex(){return this.zIndexInternal}get mode(){return this.modeInternal}get transparency(){return this.transparencyInternal}set width(t){Et(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){Et(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){_t(t,"UIElement zIndex"),this.zIndexInternal=t,this.listener&&this.layer.setListenerZIndex(this.listener,t)}set mode(t){this.modeInternal!==t&&(t===U.INTERACTIVE?(this.listener={catchClick:this.onClick},this.layer.listenPointerInput(this.listener,this.zIndexInternal)):this.modeInternal===U.INTERACTIVE&&this.listener&&(this.layer.unlistenPointerInput(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.unlistenPointerInput(this.listener),this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}onWillRender(t,i){const s=this.micro,e=this.width*s.scaleX,r=this.height*s.scaleY,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===Dt.POSITION_ROTATION_SCALE)Ft.x=this.x+s.x-l,Ft.y=this.y+s.y-c;else{const t=s.anchorY*this.height;Ft.x=this.x+s.anchorX*this.width-l+s.x,Ft.y=this.y+t-c+s.y}Ft.z=this.zIndexInternal,Wt.x=e,Wt.y=r,jt.setFromAxisAngle(qt,s.rotation),Gt.compose(Ft,jt,Wt),this.sceneWrapper.setTransform(this.planeHandler,Gt)}}var Xt="void main() {\n vec4 diffuseColor = texture(map, io_UV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";class Zt extends Yt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,n=s.color??new Q;super(t,s.x??0,s.y??0,e,r,Xt,{map:i,color:n}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ti=i,this.ii=n,this.ii.on(Z.CHANGE,this.Kt)}get texture(){return this.ti}get color(){return this.ii}set texture(t){const i=t.image.width,s=t.image.height;Et(i,"UIImage texture width"),Et(s,"UIImage texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ti=t,this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ii.copy(t)}destroy(){this.ii.off(Z.CHANGE,this.Kt),super.destroy()}}const Jt=.25;class Qt extends Yt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,h=s.color??new Q,o=(t=>{if(null==t)return{l:Jt,r:Jt,t:Jt,b:Jt};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:Jt,s="number"==typeof t.vertical?t.vertical:Jt;return{l:i,r:i,t:s,b:s}}return{l:"number"==typeof t.left?t.left:Jt,r:"number"==typeof t.right?t.right:Jt,t:"number"==typeof t.top?t.top:Jt,b:"number"==typeof t.bottom?t.bottom:Jt}}return{l:Jt,r:Jt,t:Jt,b:Jt}})(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.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ti=i,this.ii=h,this.si=a,this.ei=l,this.ii.on(Z.CHANGE,this.Kt)}get texture(){return this.ti}get color(){return this.ii}get sliceBorderLeft(){return this.si.x}get sliceBorderRight(){return this.si.y}get sliceBorderTop(){return this.si.z}get sliceBorderBottom(){return this.si.w}set texture(t){const i=t.image.width,s=t.image.height;Et(i,"UINineSlice texture width"),Et(s,"UINineSlice texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ei.x=i,this.ei.y=s,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.ei),this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ii.copy(t)}set sliceBorderLeft(t){this.si.x=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderRight(t){this.si.y=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderTop(t){this.si.z=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderBottom(t){this.si.w=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}setSliceBorders(t,i,s,e){this.si.set(t,i,s,e),this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}destroy(){this.ii.off(Z.CHANGE,this.Kt),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.ei.z=this.width*this.micro.scaleX,this.ei.w=this.height*this.micro.scaleY,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.ei)}}const Kt=new o;var ti,ii;(t=>{t.HORIZONTAL="float calculateMask() {\n return step((direction * io_UV.x + (1.0 - direction) * 0.5), progress);\n }",t.VERTICAL="float calculateMask() {\n return step((direction * io_UV.y + (1.0 - direction) * 0.5), progress);\n }",t.DIAGONAL="float calculateMask() {\n float d = (io_UV.x + io_UV.y) * (0.1);\n return step((direction * d + (1.0 - direction) * 0.5), progress);\n }",t.CIRCLE="float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / 3.14159265;\n angle *= 0.5;\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }"})(ti||(ti={}));class si extends Yt{constructor(t,i,s={}){const e=i.image?.width,r=i.image?.height;Et(e,"UIProgress foreground texture width"),Et(r,"UIProgress foreground texture height"),s.backgroundTexture&&(Et(s.backgroundTexture.image.width,"UIProgress background texture width"),Et(s.backgroundTexture.image.height,"UIProgress background texture height"));const n=s.color??new Q,h=s.foregroundColor??new Q,o=s.backgroundColor??new Q,a=s.progress??1,l=s.inverseDirection??!1;super(t,s.x??0,s.y??0,e,r,(s.maskFunction??ti.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??Kt,color:n,foregroundColor:h,backgroundColor:o,progress:a,direction:l?-1:1}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ri=t=>{this.sceneWrapper.setUniform(this.planeHandler,"foregroundColor",t)},this.ni=t=>{this.sceneWrapper.setUniform(this.planeHandler,"backgroundColor",t)},this.hi=i,this.oi=s.backgroundTexture,this.ii=n,this.ai=h,this.li=o,this.ci=a,this.ui=l,this.ii.on(Z.CHANGE,this.Kt),this.ai.on(Z.CHANGE,this.ri),this.li.on(Z.CHANGE,this.ni)}get foregroundTexture(){return this.hi}get backgroundTexture(){return this.oi}get color(){return this.ii}get foregroundColor(){return this.ai}get backgroundColor(){return this.li}get progress(){return this.ci}get inverseDirection(){return this.ui}set foregroundTexture(t){const i=t.image.width,s=t.image.height;Et(i,"UIProgress foreground texture width"),Et(s,"UIProgress foreground texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.hi=t,this.sceneWrapper.setUniform(this.planeHandler,"foregroundTexture",t)}set backgroundTexture(t){void 0!==t&&(Et(t.image.width,"UIProgress background texture width"),Et(t.image.height,"UIProgress background texture height")),this.oi=t,this.sceneWrapper.setUniform(this.planeHandler,"backgroundTexture",t)}set color(t){this.ii.copy(t)}set foregroundColor(t){this.ai.copy(t)}set backgroundColor(t){this.li.copy(t)}set inverseDirection(t){this.ui=t,this.sceneWrapper.setUniform(this.planeHandler,"direction",t?-1:1)}set progress(t){this.ci=t,this.sceneWrapper.setUniform(this.planeHandler,"progress",t)}destroy(){this.ii.off(Z.CHANGE,this.Kt),this.ai.off(Z.CHANGE,this.ri),this.li.off(Z.CHANGE,this.ni),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"})(ii||(ii={}));const ei=ii.PROPERTY_CHANGED;class ri extends Yt{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 g(r*e,n*e,{format:v,minFilter:m,magFilter:m,type:w,depthBuffer:i.enableDepthBuffer??!0,stencilBuffer:!1}),o=i.color??new Q;super(t,0,0,r,n,Xt,{map:h.texture,color:o}),this.fi=!0,this.di=!1,this.pi=!1,this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.gi=h,this.ii=o,this.wi=i.scene??new s,this.mi=i.camera??new y(75,r/n,.1,100),this.yi=e,this.bi=i.updateMode??ei,this.xi=i.clearColor??0,this._i=i.clearAlpha??0,i.updateMode===ii.PROPERTY_CHANGED&&(this.pi=!0),this.ii.on(Z.CHANGE,this.Kt)}get color(){return this.ii}get scene(){return this.wi}get camera(){return this.mi}get updateMode(){return this.bi}get resolutionFactor(){return this.yi}get clearColor(){return this.xi}get clearAlpha(){return this._i}set color(t){this.ii.copy(t)}set scene(t){this.wi!==t&&(this.wi=t,this.di=!0)}set camera(t){this.mi!==t&&(this.mi=t,this.di=!0)}set updateMode(t){this.bi!==t&&(this.bi=t,this.di=!0)}set resolutionFactor(t){this.yi!==t&&(this.yi=t,this.gi.setSize(this.width*this.yi,this.height*this.yi),this.di=!0)}set clearColor(t){this.xi!==t&&(this.xi=t,this.di=!0)}set clearAlpha(t){this._i!==t&&(this._i=t,this.di=!0)}destroy(){this.ii.off(Z.CHANGE,this.Kt),this.gi.dispose(),super.destroy()}requestRender(){this.pi=!0}onWillRender(t){(this.bi===ii.EACH_FRAME||this.bi===ii.EACH_SECOND_FRAME&&this.fi||this.bi===ii.PROPERTY_CHANGED&&this.di||this.bi===ii.MANUAL&&this.pi)&&(this.pi=!1,this.di=!1,this.fi=!this.fi,this.gi.setSize(this.width*this.yi,this.height*this.yi),t.setClearColor(this.xi,this.clearAlpha),t.setRenderTarget(this.gi),t.clear(!0,!0,!1),t.render(this.wi,this.mi))}}function ni(t){return"object"==typeof t&&null!==t&&!("string"!=typeof t.color||"string"!=typeof t.fontFamily||"number"!=typeof t.fontSize||"normal"!==t.fontStyle&&"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||"normal"!==t.fontWeight&&"bold"!==t.fontWeight&&"bolder"!==t.fontWeight&&"lighter"!==t.fontWeight&&"number"!=typeof t.fontWeight||"number"!=typeof t.lineHeight||"boolean"!=typeof t.enableShadow||"number"!=typeof t.shadowOffsetX||"number"!=typeof t.shadowOffsetY||"number"!=typeof t.shadowBlur||"string"!=typeof t.shadowColor||"boolean"!=typeof t.enableStroke||"string"!=typeof t.strokeColor||"number"!=typeof t.strokeWidth)}function hi(t,i){const s=t?.fontSize??i?.fontSize??16;Et(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&Et(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;_t(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;Ct(n,"Shadow offset X");const h=t?.shadowOffsetY??i?.shadowOffsetY??0;Ct(h,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;Ct(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return Ct(a,"Stroke width"),{color:t?.color??i?.color??"#000000",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize: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 oi(t){return t.match(/\S+|\s|\n/g)??[]}function ai(t,i,s){if(t.font=`${s.fontStyle} ${s.fontWeight} ${s.fontSize}px ${s.fontFamily}`,"\n"===i)return{width:0,height:s.lineHeight,baseline:0,lineHeight:s.lineHeight};const e=t.measureText(i);return{width:Math.ceil(e.width),height:Math.ceil(e.actualBoundingBoxAscent+e.actualBoundingBoxDescent),baseline:e.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function li(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 ci(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 Ct(i,"Padding left"),Ct(s,"Padding right"),Ct(e,"Padding top"),Ct(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class ui extends Yt{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 b(e),h=s.color??new Q;super(t,s.x??0,s.y??0,2,2,Xt,{map:n,color:h}),this.Ei=1,this.Ci=1,this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.Ii=e,this.Ui=r,this.Mi=n,this.ii=h,this.Si=i,this.Ti=s.maxWidth??1024,this.Bi=ci(s.padding),this.Vi=s.commonStyle??{},this.ii.on(Z.CHANGE,this.Kt),this.Ai()}get color(){return this.ii}get content(){return this.Si}get maxWidth(){return this.Ti}get padding(){return this.Bi}get commonStyle(){return this.Vi}set color(t){this.ii.copy(t)}set content(t){this.Si=t,this.Ai()}set maxWidth(t){this.Ti=t,this.Ai()}set padding(t){this.Bi=t,this.Ai()}set commonStyle(t){this.Vi=t,this.Ai()}destroy(){this.ii.off(Z.CHANGE,this.Kt),this.Mi.dispose(),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.Ci!==this.width/this.height&&(this.Ci=this.Ei,this.height=this.width/this.Ei)}Ai(){const{lines:t,size:i}=((t,i,s,e)=>{const r=[];for(const s of Array.isArray(i)?i:[i]){const i="string"==typeof s,n=i?s:s.text,h=hi(i?void 0:s.style,e);for(const i of oi(n)){const s=ai(t,i,h);r.push({text:i,style:h,metrics:s})}}const n=((t,i)=>{const s=[];let e=[],r=0,n=0,h=0,o=0;for(const a of i)"\n"!==a.text?r+a.metrics.width>t&&0!==e.length?(s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[a],r=a.metrics.width,n=a.metrics.height,h=a.metrics.baseline,o=a.metrics.lineHeight):(e.push(a),r+=a.metrics.width,n=Math.max(n,a.metrics.height),h=Math.max(h,a.metrics.baseline),o=Math.max(o,a.metrics.lineHeight)):(e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),e=[],r=0,n=0,h=0,o=0);return e.length>0&&s.push({chunks:e,width:r,height:n,baseline:h,lineHeight:o}),s})(s,r),h=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map(t=>t.width));let s=0;for(let i=0;t.length>i;i++){const e=t[i];s+=0===i?e.height:e.lineHeight,i===t.length-1&&(s+=e.baseline)}return{width:i,height:s}})(n);return{lines:n,size:h}})(this.Ui,this.content,this.Ti,this.Vi);this.Ii.width=i.width+this.Bi.left+this.Bi.right,this.Ii.height=i.height+this.Bi.top+this.Bi.bottom,this.width=this.Ii.width,this.height=this.Ii.height,this.Ei=(i.width+this.Bi.left+this.Bi.right)/(i.height+this.Bi.top+this.Bi.bottom),((t,i,s,e)=>{e.clearRect(0,0,e.canvas.width,e.canvas.height);let r=t;for(let t=0;s.length>t;t++){const n=s[t];let h=i;r+=0===t?n.height:n.lineHeight;for(const t of n.chunks)li(h,r,t.text,t.style,e),h+=t.metrics.width}})(this.Bi.top,this.Bi.left,t,this.Ui),this.Mi.needsUpdate=!0}}class fi extends pt{constructor(t,i){void 0!==t&&Et(t,"UIFullscreenLayer.fixedWidth"),void 0!==i&&Et(i,"UIFullscreenLayer.fixedHeight"),super(window.innerWidth,window.innerHeight),this.ki=()=>{const t=this.Pi();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.$i=t=>{const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,s=i?t.clientX-i.left:t.clientX,e=i?i.bottom-t.clientY:window.innerHeight-t.clientY,r=this.Pi();this.pointerClickInternal(s*r,e*r)},this.Hi=t,this.Li=i,window.addEventListener("resize",this.ki),window.addEventListener("pointerdown",this.$i),this.ki()}get fixedWidth(){return this.Hi}get fixedHeight(){return this.Li}set fixedWidth(t){void 0!==t&&Et(t,"UIFullscreenLayer.fixedWidth"),t!==this.Hi&&(this.Hi=t,this.ki())}set fixedHeight(t){void 0!==t&&Et(t,"UIFullscreenLayer.fixedHeight"),t!==this.Li&&(this.Li=t,this.ki())}destroy(){window.removeEventListener("resize",this.ki),window.removeEventListener("pointerdown",this.$i)}render(t,i){_t(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}Pi(){return this.orientation===M.HORIZONTAL?void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:1:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:1}}const di=(()=>{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 pi(t){if("Texture"===t||t instanceof o)return{glslType:"sampler2D",instantiable:!1,itemSize:-1};if("UIColor"===t||t instanceof Q)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 gi(t,i,s){const e=i.array;if(t instanceof Q)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 wi(t,i){const s=pi(t);if(!s.instantiable)throw Error("Invalid property type: "+t);return new _(new Float32Array(i*s.itemSize),s.itemSize)}class mi extends h{constructor(t,i,s=J.CLIP,e=16){const n={},h={instanceTransform:"Matrix4",uvTransform:"Matrix3",...s===J.CLIP?{alphaTest:"number"}:{}};for(const[t,s]of Object.entries(i))(pi(s).instantiable?h:n)[t]=s;const o=di.clone(),a=((t,i,s,e)=>{const n={},h=[],o=[],a=[],l=[];for(const[t,s]of Object.entries(i)){const i=pi(s).glslType;n["u_"+t]={value:null},h.push(`uniform ${i} u_${t};`)}for(const[t,i]of Object.entries(s)){const s=pi(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===J.BLEND,alphaTest:e===J.CLIP?.5:0,alphaHash:e===J.HASH})})(t,n,h,s);super(o,a),this.handlerToDescriptor=new Map,this.lastHandler=0,this.capacity=0,this.propertyBuffers=new Map,this.Ri=o,this.Ri.instanceCount=0,this.zi=a,this.capacity=Math.max(e,16);for(const[t,i]of Object.entries(h)){const s=wi(i,this.capacity);this.Ri.setAttribute("a_"+t,s),this.propertyBuffers.set("a_"+t,s)}}createInstances(t){const i=this.lastHandler++;return this.Ri.instanceCount+t>this.capacity&&this.Di(16*Math.ceil((this.capacity+t)/16)),this.handlerToDescriptor.set(i,{firstIndex:this.Ri.instanceCount,count:t}),this.Ri.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.Ni(r,i),r.firstIndex=i.firstIndex,this.Oi(r.firstIndex+r.count,r.count)):this.Oi(i.firstIndex+i.count,i.count),this.Ri.instanceCount-=i.count}updateProperties(t,i,s){Ct(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(pi(i).instantiable){const s=this.Fi(t);gi(i,s,n*s.itemSize)}else this.ji(t).value=i,this.zi.uniformsNeedUpdate=!0}}updateTransforms(t,i,s){Ct(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.Fi("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){Ct(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.Fi("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){Ct(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.Fi("visibility");r.array[(e.firstIndex+i+t)*r.itemSize]=s[t]?1:0,r.needsUpdate=!0}}destroy(){this.Ri.dispose(),this.zi.dispose()}gt(t){const i=this.handlerToDescriptor.get(t);if(void 0===i)throw Error("No active range found for handler: "+t);return i}Fi(t){const i=this.propertyBuffers.get("a_"+t);if(void 0===i)throw Error(`No attribute found for property: ${t} (a_${t})`);return i}ji(t){const i=this.zi.uniforms["u_"+t];if(void 0===i)throw Error("No uniform found for handler: "+t);return i}Di(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.Ri.setAttribute("a_"+i,n),this.propertyBuffers.set("a_"+i,n)}this.capacity=t}Ni(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}}Oi(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.Ri.instanceCount*r,h=i*r;for(let i=t*r;n-h>i;i++)e[i]=e[i+h];s.needsUpdate=!0}}}function vi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||ni(t.style))}export{Lt as UIAnchor,Vt as UIAspectConstraint,Q as UIColor,Z as UIColorEvent,gt as UIConstraint,Bt as UIConstraint2DBuilder,kt as UICoverConstraintBuilder,Ht as UICustomConstraint,Rt as UIDummy,Yt as UIElement,E as UIExpression,$t as UIFitConstraintBuilder,fi as UIFullscreenLayer,mi as UIGenericInstancedPlane,mt as UIHeightConstraint,It as UIHorizontalDistanceConstraint,Ut as UIHorizontalProportionConstraint,Zt as UIImage,zt as UIInputEvent,pt as UILayer,ct as UILayerEvent,Ot as UIMicro,Dt as UIMicroAnchorMode,U as UIMode,Qt as UINineSlice,M as UIOrientation,G as UIPriority,si as UIProgress,ti as UIProgressMaskFunction,lt as UIRelation,ri as UIScene,ii as UISceneUpdateMode,wt as UISingleParameterConstraint,ui as UIText,J as UITransparencyMode,Mt as UIVerticalDistanceConstraint,St as UIVerticalProportionConstraint,Tt as UIWidthConstraint,q as convertPriority,ut as convertRelation,vi as isUITextSpan,ni as isUITextStyle,S as resolveOrientation,Y as resolvePriority,ft as resolveRelation,ci as resolveTextPadding,hi 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,WebGLRenderTarget as g,UnsignedByteType as w,LinearFilter as m,RGBAFormat as v,PerspectiveCamera as y,CanvasTexture as b,InstancedBufferGeometry as x,InstancedBufferAttribute as _}from"three";class E{constructor(t=0,i){this.constant=t,this._=i?new Map(i):new Map}static plus(t,i){const s=new E(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 E(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 E(this.constant,Array.from(this._.entries()))}prepareTermsInternal(){return Array.from(this._.entries())}}class C{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 I{constructor(){this.o=new Map}on(t,i,s,e=0){return this.h(t,!1,e,i,s),this}once(t,i,s,e=0){return this.h(t,!0,e,i,s),this}off(t,i,s){const e=this.o.get(t);if(void 0===e)return this;e.u&&(e.u=!1,e.v=e.v.slice());const r=e.v;if(0===r.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;r.length>t;t++){const i=r[t];e.l.remove(i.C,i.p)}return this}{const n=r.length;if(r[0].C===i&&r[0].p===s)return 1===n?this.o.delete(t):r.shift(),this;const h=n-1;if(r[h].C===i&&r[h].p===s)return r.pop(),this;if(10>n||r[0].M===r[h].M)for(let t=1;h>t;t++){const e=r[t];if(e.C===i&&e.p===s)return r.splice(t,1),this}else{const t=e.l.getPriority(i,s);if(void 0===t)return this;let n=0,h=r.length-1;for(;h>=n;){const i=n+h>>>1;t>r[i].M?n=i+1:h=i-1}const o=n;for(h=r.length-1;h>=n;){const i=n+h>>>1;r[i].M>t?h=i-1:n=i+1}const a=h;for(let t=o;a>=t;t++)if(r[t].C===i&&r[t].p===s)return r.splice(t,1),this}}return this}emit(t,...i){const s=this.o.get(t);if(void 0===s)return!1;if(0===s.v.length)return!1;s.u?s.v=s.v.slice():s.u=!0;const e=s.v;let r=!1;for(let t=0;e.length>t;t++){const s=e[t];s.C.apply(s.p,i),s.k&&(r=!0,s.m=!0)}const n=this.o.get(t);if(void 0===n)return!0;n.v===e&&(n.u=!1);const h=n.v;if(r){let i=0;for(let t=0;h.length>t;t++){const s=h[t];s.m?n.l.remove(s.C,s.p):h[i++]=s}0===i?this.o.delete(t):h.length=i}return!0}h(t,i,s,e,r){let n=this.o.get(t);if(void 0===n)return void this.o.set(t,{v:[{C:e,p:r,M:s,k:i,m:!1}],u:!1,l:new C(e,r,s)});if(n.l.has(e,r))throw Error("Event listener already exists");n.l.insert(e,r,s);const h={C:e,p:r,M:s,k:i,m:!1};n.u&&(n.u=!1,n.v=n.v.slice());{const t=n.v,i=h.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(h);if(t[0].M>=i)return void t.unshift(h);{let s=0,e=t.length;for(;e>s;){const r=s+e>>>1;i>t[r].M?s=r+1:e=r}t.splice(s,0,h)}}}}var U,M;function S(t){return t??M.ALWAYS}function T(){return new B}(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"})(M||(M={}));class B{index={};array=[];size(){return this.array.length}empty(){return 0===this.array.length}itemAt(t){return this.array[t]}contains(t){return void 0!==this.index[t.id()]}find(t){const i=this.index[t.id()];return void 0===i?void 0:this.array[i]}setDefault(t,i){const s=this.index[t.id()];if(void 0===s){const s=new V(t,i());return this.index[t.id()]=this.array.length,this.array.push(s),s}return this.array[s]}insert(t,i){const s=new V(t,i),e=this.index[t.id()];return void 0===e?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[e]=s,s}erase(t){const i=this.index[t.id()];if(void 0===i)return;this.index[t.id()]=void 0;const s=this.array[i],e=this.array.pop();return s!==e&&(this.array[i]=e,this.index[e.first.id()]=i),s}copy(){const t=new B;for(let i=0;this.array.length>i;i++){const s=this.array[i].copy();t.array[i]=s,t.index[s.first.id()]=i}return t}}class V{first;second;constructor(t,i){this.first=t,this.second=i}copy(){return new V(this.first,this.second)}}class A{constructor(t=""){this.I=t}id(){return this.U}name(){return this.I}setName(t){this.I=t}context(){return this.S}setContext(t){this.S=t}value(){return this.T}setValue(t){this.T=t}plus(t){return new P(this,t)}minus(t){return new P(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new P([t,this])}divide(t){return new P([1/t,this])}toJSON(){return{name:this.I,value:this.T}}toString(){return this.S+"["+this.I+":"+this.T+"]"}I;T=0;S=null;U=k++}let k=0;class P{constructor(){let t=(t=>{let i=0,s=()=>0,e=T();for(let r=0,n=t.length;n>r;++r){let n=t[r];if("number"==typeof n)i+=n;else if(n instanceof A)e.setDefault(n,s).second+=1;else if(n instanceof P){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 A)e.setDefault(r,s).second+=t;else{if(!(r instanceof P))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.B=t.terms,this.V=t.constant}terms(){return this.B}constant(){return this.V}value(){let t=this.V;for(let i=0,s=this.B.size();s>i;i++){let s=this.B.itemAt(i);t+=s.first.value()*s.second}return t}plus(t){return new P(this,t)}minus(t){return new P(this,"number"==typeof t?-t:[-1,t])}multiply(t){return new P([t,this])}divide(t){return new P([1/t,this])}isConstant(){return 0==this.B.size()}toString(){let t=this.B.array.map(t=>t.second+"*"+t.first).join(" + ");return this.isConstant()||0===this.V||(t+=" + "),t+=this.V,t}B;V}class ${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=$.create(1e3,1e3,1e3);static strong=$.create(1,0,0);static medium=$.create(0,1,0);static weak=$.create(0,0,1);static clip(t){return Math.max(0,Math.min($.required,t))}}var H;(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(H||(H={}));class L{constructor(t,i,s,e=$.required){this.A=i,this.P=$.clip(e),this.$=void 0===s&&t instanceof P?t:t.minus(s)}id(){return this.U}expression(){return this.$}op(){return this.A}strength(){return this.P}toString(){return this.$+" "+["<=",">=","="][this.A]+" 0 ("+this.P+")"}$;A;P;U=R++}let R=0;class z{maxIterations=1e3;constructor(){}createConstraint(t,i,s,e=$.required){let r=new L(t,i,s,e);return this.addConstraint(r),r}addConstraint(t){if(void 0!==this.H.find(t))throw Error("duplicate constraint");let i=this.L(t),s=i.row,e=i.tag,r=this.R(s,e);if(r.type()===N.Invalid&&s.allDummies()){if(!D(s.constant()))throw Error("unsatisfiable constraint");r=e.marker}if(r.type()===N.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(r),this.N(r,s),this.O.insert(r,s);this.H.insert(t,e),this.F(this.j)}removeConstraint(t){let i=this.H.erase(t);if(void 0===i)throw Error("unknown constraint");this.W(t,i.second);let s=i.second.marker,e=this.O.erase(s);if(void 0===e){let t=this.G(s);if(t.type()===N.Invalid)throw Error("failed to find leaving row");e=this.O.erase(t),e.second.solveForEx(t,s),this.N(s,e.second)}this.F(this.j)}hasConstraint(t){return this.H.contains(t)}getConstraints(){return this.H.array.map(({first:t})=>t)}addEditVariable(t,i){if(void 0!==this.q.find(t))throw Error("duplicate edit variable");if((i=$.clip(i))===$.required)throw Error("bad required strength");let s=new P(t),e=new L(s,H.Eq,void 0,i);this.addConstraint(e);let r=this.H.find(e).second;this.q.insert(t,{tag:r,constraint:e,constant:0})}removeEditVariable(t){let i=this.q.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)}hasEditVariable(t){return this.q.contains(t)}suggestValue(t,i){let s=this.q.find(t);if(void 0===s)throw Error("unknown edit variable");let e=this.O,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()!==N.External&&this.Y.push(i.first)}this.X()}updateVariables(){let t=this.Z,i=this.O;for(let s=0,e=t.size();e>s;++s){let e=t.itemAt(s),r=i.find(e.second);e.first.setValue(void 0!==r?r.second.constant():0)}}J(t){return this.Z.setDefault(t,()=>this.K(N.External)).second}L(t){let i=t.expression(),s=new j(i.constant()),e=i.terms();for(let t=0,i=e.size();i>t;++t){let i=e.itemAt(t);if(!D(i.second)){let t=this.J(i.first),e=this.O.find(t);void 0!==e?s.insertRow(e.second,i.second):s.insertSymbol(t,i.second)}}let r=this.j,n=t.strength(),h={marker:F,other:F};switch(t.op()){case H.Le:case H.Ge:{let i=t.op()===H.Le?1:-1,e=this.K(N.Slack);if(h.marker=e,s.insertSymbol(e,i),$.required>n){let t=this.K(N.Error);h.other=t,s.insertSymbol(t,-i),r.insertSymbol(t,n)}break}case H.Eq:if($.required>n){let t=this.K(N.Error),i=this.K(N.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(N.Dummy);h.marker=t,s.insertSymbol(t)}}return 0>s.constant()&&s.reverseSign(),{row:s,tag:h}}R(t,i){let s=t.cells();for(let t=0,i=s.size();i>t;++t){let i=s.itemAt(t);if(i.first.type()===N.External)return i.first}let e=i.marker.type();return e!==N.Slack&&e!==N.Error||t.coefficientFor(i.marker)>=0?(e=i.other.type(),e!==N.Slack&&e!==N.Error||t.coefficientFor(i.other)>=0?F:i.other):i.marker}D(t){let i=this.K(N.Slack);this.O.insert(i,t.copy()),this.tt=t.copy(),this.F(this.tt);let s=D(this.tt.constant());this.tt=null;let e=this.O.erase(i);if(void 0!==e){let t=e.second;if(t.isConstant())return s;let r=this.it(t);if(r.type()===N.Invalid)return!1;t.solveForEx(i,r),this.N(r,t),this.O.insert(r,t)}let r=this.O;for(let t=0,s=r.size();s>t;++t)r.itemAt(t).second.removeSymbol(i);return this.j.removeSymbol(i),s}N(t,i){let s=this.O;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()!==N.External&&this.Y.push(r.first)}this.j.substitute(t,i),this.tt&&this.tt.substitute(t,i)}F(t){let i=0;for(;this.maxIterations>i;){let s=this.st(t);if(s.type()===N.Invalid)return;let e=this.et(s);if(e.type()===N.Invalid)throw Error("the objective is unbounded");let r=this.O.erase(e).second;r.solveForEx(e,s),this.N(s,r),this.O.insert(s,r),i++}throw Error("solver iterations exceeded")}X(){let t=this.O,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()===N.Invalid)throw Error("dual optimize failed");let r=e.second;t.erase(s),r.solveForEx(s,i),this.N(i,r),t.insert(i,r)}}}st(t){let i=t.cells();for(let t=0,s=i.size();s>t;++t){let s=i.itemAt(t),e=s.first;if(0>s.second&&e.type()!==N.Dummy)return e}return F}rt(t){let i=Number.MAX_VALUE,s=F,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()!==N.Dummy){let t=this.j.coefficientFor(n)/h;i>t&&(i=t,s=n)}}return s}et(t){let i=Number.MAX_VALUE,s=F,e=this.O;for(let r=0,n=e.size();n>r;++r){let n=e.itemAt(r),h=n.first;if(h.type()!==N.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}G(t){let i=Number.MAX_VALUE,s=i,e=i,r=F,n=r,h=r,o=r,a=this.O;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()===N.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}W(t,i){i.marker.type()===N.Error&&this.nt(i.marker,t.strength()),i.other.type()===N.Error&&this.nt(i.other,t.strength())}nt(t,i){let s=this.O.find(t);void 0!==s?this.j.insertRow(s.second,-i):this.j.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===N.Slack||e===N.Error)return s.first}return F}K(t){return new O(t,this.ht++)}H=(()=>T())();O=(()=>T())();Z=(()=>T())();q=(()=>T())();Y=[];j=new j;tt=null;ht=0}function D(t){return 0>t?1e-8>-t:1e-8>t}var N;(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"})(N||(N={}));class O{constructor(t,i){this.U=i,this.ot=t}id(){return this.U}type(){return this.ot}U;ot}let F=new O(N.Invalid,-1);class j{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()!==N.Dummy)return!1;return!0}copy(){let t=new j(this.V);return t.lt=this.lt.copy(),t}add(t){return this.V+=t}insertSymbol(t,i=1){D(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=T();V}const W=1e3;var G;function q(t){switch(t){case G.P0:return $.create(W,W,W);case G.P1:return $.create(100,0,0);case G.P2:return $.create(10,0,0);case G.P3:return $.create(0,100,0);case G.P4:return $.create(0,10,0);case G.P5:return $.create(0,0,100);case G.P6:return $.create(0,0,10);case G.P7:return $.create(0,0,1);default:throw Error("Invalid priority: "+t)}}function Y(t){return t??G.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"})(G||(G={}));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 Z,J;(t=>{t.CHANGE="change"})(Z||(Z={}));class Q extends I{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(Z.CHANGE,this)}set g(t){this.gInternal=t,this.emit(Z.CHANGE,this)}set b(t){this.bInternal=t,this.emit(Z.CHANGE,this)}set a(t){this.aInternal=t,this.emit(Z.CHANGE,this)}set(t,i,s,e=this.aInternal){return this.rInternal=t,this.gInternal=i,this.bInternal=s,this.aInternal=e,this.emit(Z.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(Z.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(Z.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 Q?(this.rInternal=t.rInternal,this.gInternal=t.gInternal,this.bInternal=t.bInternal,this.aInternal=t.aInternal):(this.rInternal=t.r,this.gInternal=t.g,this.bInternal=t.b,this.aInternal=1),this.emit(Z.CHANGE,this),this}clone(){return new Q(this.rInternal,this.gInternal,this.bInternal,this.aInternal)}}(t=>{t[t.CLIP=0]="CLIP",t[t.HASH=1]="HASH",t[t.BLEND=2]="BLEND"})(J||(J={}));const K=.25,tt=new Map([[Q,"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 Q?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 Q?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===J.BLEND?(s.material.transparent=!0,s.material.alphaTest=0,s.material.uniforms.alphaTest.value=0,s.material.alphaHash=!1):i===J.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 H.Eq;case lt.LESS_THAN:return H.Le;case lt.GREATER_THAN:return H.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 z,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 A;if(i===G.P0){const r={variable:e,priority:i,value:t};this.yt.set(s,r),r.constraint=this.Et(new E(0,[[s,1]]),new E(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,q(i)),this.wt?.suggestValue(e,t)}catch{this.wt=void 0}}return this.vt=!0,s}removeVariable(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t))throw Error(`Variable ${t} is used in constraint`);try{i.constraint?this.wt?.removeConstraint(i.constraint):this.wt?.removeEditVariable(i.variable)}catch{this.wt=void 0}this.yt.delete(t),this.vt=!0}suggestVariableValue(t,i){const s=this.yt.get(t);if(void 0===s)throw Error(`Variable ${t} does not exist`);s.value!==i&&(s.value=i,s.constraint?s.constraint=this.Ct(s.constraint,(new E).plus(t,1),new E(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===G.P0){const i=(new E).plus(t,1),e=new E(s.value);s.constraint=this.Et(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.It(t,s)}this.vt=!0}}readVariableValue(t){const i=this.yt.get(t);if(void 0===i)throw Error(`Variable ${t} does not exist`);return void 0===this.wt&&this.Ut(),this.vt&&(this.wt?.updateVariables(),this.vt=!1),i.variable.value()}createConstraint(t,i,s,e,r){const n=this._t++,h=this.Et(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.Mt(s),this.vt=!0}setConstraintRHS(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.rhs.copy(i),this.Mt(s),this.vt=!0}setConstraintRelation(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.relation!==i&&(s.relation=i,this.Mt(s),this.vt=!0)}setConstraintPriority(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);s.priority!==i&&(s.priority=i,this.Mt(s),this.vt=!0)}setConstraintEnabled(t,i){const s=this.xt.get(t);if(void 0===s)throw Error(`Constraint ${t} does not exist`);if(i!==s.enabled){s.enabled=i;try{s.enabled?this.wt?.addConstraint(s.constraint):this.wt?.removeConstraint(s.constraint)}catch{this.wt=void 0}this.vt=!0}}It(t,i){const s=[];for(const i of this.xt.values())if(i.lhs.hasTerm(t)||i.rhs.hasTerm(t)){try{this.wt?.removeConstraint(i.constraint)}catch{this.wt=void 0}s.push(i)}this.wt?.removeEditVariable(i.variable),this.wt?.addEditVariable(i.variable,q(i.priority));for(const t of s)t.constraint=this.Et(t.lhs,t.rhs,t.relation,t.priority);for(const t of s)try{this.wt?.addConstraint(t.constraint)}catch{this.wt=void 0;break}}Mt(t){t.constraint=t.enabled?this.Ct(t.constraint,t.lhs,t.rhs,t.relation,t.priority):this.Et(t.lhs,t.rhs,t.relation,t.priority)}Ct(t,i,s,e,r){try{this.wt?.removeConstraint(t)}catch{this.wt=void 0}const n=this.Et(i,s,e,r);try{this.wt?.addConstraint(n)}catch{this.wt=void 0}return n}Et(t,i,s,e){return new L(this.St(t),ut(s),this.St(i),q(e))}St(t){return new P(...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 z;for(const t of this.yt.values())t.constraint?this.wt.addConstraint(t.constraint):(this.wt.addEditVariable(t.variable,q(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 I{constructor(t,i){super(),this.name="",this.solverWrapper=new dt,this.modeInternal=U.VISIBLE,this.Tt=[],this.sceneWrapper=new at(t,i),this.xVariable=this.solverWrapper.createVariable(0,G.P0),this.yVariable=this.solverWrapper.createVariable(0,G.P0),this.wVariable=this.solverWrapper.createVariable(t,G.P0),this.hVariable=this.solverWrapper.createVariable(i,G.P0),this.orientationInternal=t>i?M.HORIZONTAL:M.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?M.HORIZONTAL:M.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))}pointerClickInternal(t,i){if(this.mode===U.INTERACTIVE){this.Tt.sort((t,i)=>i.zIndex-t.zIndex);for(const s of this.Tt)if(s.listener.catchClick(t,i))return}}getSolverWrapperInternal(){return this.solverWrapper}getSceneWrapperClientAPI(){return this.sceneWrapper}listenPointerInput(t,i){if(this.Tt.find(i=>i.listener===t))throw Error("Listener already exists");this.Tt.push({zIndex:i,listener:t})}setListenerZIndex(t,i){const s=this.Tt.findIndex(i=>i.listener===t);if(-1===s)throw Error("Listener not found");this.Tt[s].zIndex=i}unlistenPointerInput(t){const i=this.Tt.findIndex(i=>i.listener===t);if(-1===i)throw Error("Listener not found");this.Tt.splice(i,1)}}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.Bt=()=>{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.Bt)}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.Bt())}destroy(){this.layer.off(ct.ORIENTATION_CHANGE,this.Bt),this.solverWrapper.removeConstraint(this.constraint)}isConstraintEnabled(){return this.orientationInternal===M.ALWAYS||this.orientationInternal===this.layer.orientation}}class mt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Vt=t,this.At=i.height??t.height,this.constraint=this.solverWrapper.createConstraint(new E(0,[[this.Vt.hVariable,1]]),new E(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 E(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 Et(t,i){if(_t(t,i),1e-6>t)throw Error(i+": value must be greater than or equal to 0.000001")}function Ct(t,i){if(_t(t,i),0>t)throw Error(i+": value must be greater than or equal to 0")}class It extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalDistanceConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.$t=s.anchorA??.5,this.Ht=s.anchorB??.5,this.Lt=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Rt(),new E(this.Lt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Lt}get anchorA(){return this.$t}get anchorB(){return this.Ht}set distance(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintRHS(this.constraint,new E(this.Lt)))}set anchorA(t){this.$t!==t&&(this.$t=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}set anchorB(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}Rt(){let t,i;if(bt(this.kt))t=new E(0,[[this.kt.xVariable,1],[this.kt.wVariable,this.$t]]);else{if(!yt(this.kt))throw Error("A is not a valid element type");t=(new E).plus(this.kt.xVariable,1)}if(bt(this.Pt))i=new E(0,[[this.Pt.xVariable,1],[this.Pt.wVariable,this.Ht]]);else{if(!yt(this.Pt))throw Error("B is not a valid element type");i=(new E).plus(this.Pt.xVariable,1)}return E.minus(i,t)}}class Ut extends wt{constructor(t,i,s={}){super(xt(t,i,"UIHorizontalProportionConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.zt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new E(0),this.Dt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt()))}Dt(){return E.minus(new E(0,[[this.kt.wVariable,this.zt]]),new E(0,[[this.Pt.wVariable,1]]))}}class Mt extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalDistanceConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.$t=s.anchorA??.5,this.Ht=s.anchorB??.5,this.Lt=s.distance??0,this.constraint=this.solverWrapper.createConstraint(this.Rt(),new E(this.Lt),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get distance(){return this.Lt}get anchorA(){return this.$t}get anchorB(){return this.Ht}set distance(t){this.Lt!==t&&(this.Lt=t,this.solverWrapper.setConstraintRHS(this.constraint,new E(this.Lt)))}set anchorA(t){this.$t!==t&&(this.$t=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}set anchorB(t){this.Ht!==t&&(this.Ht=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}Rt(){let t,i;if(bt(this.kt))t=new E(0,[[this.kt.yVariable,1],[this.kt.hVariable,this.$t]]);else{if(!yt(this.kt))throw Error("A is not a valid element type");t=(new E).plus(this.kt.yVariable,1)}if(bt(this.Pt))i=new E(0,[[this.Pt.yVariable,1],[this.Pt.hVariable,this.Ht]]);else{if(!yt(this.Pt))throw Error("B is not a valid element type");i=(new E).plus(this.Pt.yVariable,1)}return E.minus(i,t)}}class St extends wt{constructor(t,i,s={}){super(xt(t,i,"UIVerticalProportionConstraint"),s.priority,s.relation,s.orientation),this.kt=t,this.Pt=i,this.zt=s.proportion??1,this.constraint=this.solverWrapper.createConstraint(new E(0),this.Dt(),this.relationInternal,this.priorityInternal,this.isConstraintEnabled())}get proportion(){return this.zt}set proportion(t){this.zt!==t&&(this.zt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.Dt()))}Dt(){return E.minus(new E(0,[[this.kt.hVariable,this.zt]]),new E(0,[[this.Pt.hVariable,1]]))}}class Tt extends wt{constructor(t,i={}){super(t.layer,i.priority,i.relation,i.orientation),this.Vt=t,this.Nt=i.width??t.width,this.constraint=this.solverWrapper.createConstraint(new E(0,[[this.Vt.wVariable,1]]),new E(this.Nt),this.relation,this.priority,this.isConstraintEnabled())}get width(){return this.Nt}set width(t){this.Nt!==t&&(this.Nt=t,this.solverWrapper.setConstraintRHS(this.constraint,new E(t)))}}class Bt{static size(t,i={}){return{h:new Tt(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 It(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 Mt(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.Vt=t,this.Ot=i.aspect??t.width/t.height,this.constraint=this.solverWrapper.createConstraint(this.Rt(),new E(0),this.relation,this.priority,this.isConstraintEnabled())}get aspect(){return this.Ot}set aspect(t){this.Ot!==t&&(this.Ot=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Rt()))}Rt(){return new E(0,[[this.Vt.wVariable,1],[this.Vt.hVariable,-this.Ot]])}}const At=.5;class kt{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new It(t,i,{anchorA:s.anchorH??At,anchorB:s.anchorH??At,orientation:s.orientation}),yConstraint:new Mt(t,i,{anchorA:s.anchorV??At,anchorB:s.anchorV??At,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:G.P1,orientation:s.orientation})}}}const Pt=.5;class $t{static build(t,i,s={}){let e;return!0===s.keepActiveAspect&&(e=new Vt(i,{orientation:s.orientation})),{activeAspectConstraint:e,xConstraint:new It(t,i,{anchorA:s.anchorH??Pt,anchorB:s.anchorH??Pt,orientation:s.orientation}),yConstraint:new Mt(t,i,{anchorA:s.anchorV??Pt,anchorB:s.anchorV??Pt,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:G.P1,orientation:s.orientation})}}}class Ht extends wt{constructor(t,i,s,e={}){super(t,e.priority,e.relation,e.orientation),this.Ft=i,this.jt=s,this.constraint=this.solverWrapper.createConstraint(this.Ft,this.jt,this.relation,this.priority,this.isConstraintEnabled())}get lhs(){return this.Ft}get rhs(){return this.jt}setLHS(t){this.Ft=t,this.solverWrapper.setConstraintLHS(this.constraint,this.Ft)}setRHS(t){this.jt=t,this.solverWrapper.setConstraintRHS(this.constraint,this.jt)}}class Lt extends I{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,G.P7),this.yVariable=this.solverWrapper.createVariable(s,G.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)}}class Rt extends Lt{constructor(t,i={}){const s=i.x??0,e=i.y??0,r=i.width??100,n=i.height??100;Et(r,"UIDummy width"),Et(n,"UIDummy height"),super(t,s,e),this.wVariable=this.solverWrapper.createVariable(r,G.P6),this.hVariable=this.solverWrapper.createVariable(n,G.P6)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}set width(t){Et(t,"UIDummy width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){Et(t,"UIDummy height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}destroy(){this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),super.destroy()}}var zt,Dt;(t=>{t.CLICK="click"})(zt||(zt={})),(t=>{t[t.ROTATION_SCALE=0]="ROTATION_SCALE",t[t.POSITION_ROTATION_SCALE=1]="POSITION_ROTATION_SCALE"})(Dt||(Dt={}));const Nt=.5;class Ot{constructor(){this.Wt=0,this.Gt=0,this.qt=Nt,this.Yt=Nt,this.Xt=1,this.Zt=1,this.Jt=0,this.Qt=Dt.ROTATION_SCALE,this.vt=!1}get x(){return this.Wt}get y(){return this.Gt}get anchorX(){return this.qt}get anchorY(){return this.Yt}get scaleX(){return this.Xt}get scaleY(){return this.Zt}get size(){return Math.max(this.Xt,this.Zt)}get angle(){return d.radToDeg(this.Jt)}get anchorMode(){return this.Qt}get rotation(){return this.Jt}set x(t){t!==this.Wt&&(this.Wt=t,this.vt=!0)}set y(t){t!==this.Gt&&(this.Gt=t,this.vt=!0)}set anchorX(t){t!==this.qt&&(this.qt=t,this.vt=!0)}set anchorY(t){t!==this.Yt&&(this.Yt=t,this.vt=!0)}set scaleX(t){t!==this.Xt&&(this.Xt=t,this.vt=!0)}set scaleY(t){t!==this.Zt&&(this.Zt=t,this.vt=!0)}set size(t){t===this.Xt&&t===this.Zt||(this.Xt=t,this.Zt=t,this.vt=!0)}set angle(t){const i=d.degToRad(t);i!==this.Jt&&(this.Jt=i,this.vt=!0)}set rotation(t){t!==this.Jt&&(this.Jt=t,this.vt=!0)}set anchorMode(t){t!==this.Qt&&(this.Qt=t,this.vt=!0)}reset(){0===this.Wt&&0===this.Gt&&this.qt===Nt&&this.Yt===Nt&&1===this.Xt&&1===this.Zt&&0===this.Jt||(this.Wt=0,this.Gt=0,this.qt=Nt,this.Yt=Nt,this.Xt=1,this.Zt=1,this.Jt=0,this.vt=!0)}getRecalculationRequiredInternal(){return this.vt}resetRecalculationRequiredInternal(){this.vt=!1}}const Ft=new l,jt=new p,Wt=new l,Gt=new f,qt=new l(0,0,1);class Yt extends Lt{constructor(t,i,s,e,r,n,h){Et(e,"UIElement width"),Et(r,"UIElement height"),super(t,i,s),this.micro=new Ot,this.modeInternal=U.VISIBLE,this.transparencyInternal=J.CLIP,this.zIndexInternal=0,this.onClick=(t,i)=>{const s=((t,i,s)=>t>s.x&&s.x+s.width>t&&i>s.y&&s.y+s.height>i)(t,i,this);return s&&this.emit(zt.CLICK,t,i,this),s},this.layer.on(ct.WILL_RENDER,this.onWillRender,this),this.wVariable=this.solverWrapper.createVariable(e,G.P6),this.hVariable=this.solverWrapper.createVariable(r,G.P6),this.sceneWrapper=t.getSceneWrapperClientAPI(),this.planeHandler=this.sceneWrapper.createPlane(n,h)}get width(){return this.solverWrapper.readVariableValue(this.wVariable)}get height(){return this.solverWrapper.readVariableValue(this.hVariable)}get zIndex(){return this.zIndexInternal}get mode(){return this.modeInternal}get transparency(){return this.transparencyInternal}set width(t){Et(t,"UIElement width"),this.solverWrapper.suggestVariableValue(this.wVariable,t)}set height(t){Et(t,"UIElement height"),this.solverWrapper.suggestVariableValue(this.hVariable,t)}set zIndex(t){_t(t,"UIElement zIndex"),this.zIndexInternal=t,this.listener&&this.layer.setListenerZIndex(this.listener,t)}set mode(t){this.modeInternal!==t&&(t===U.INTERACTIVE?(this.listener={catchClick:this.onClick},this.layer.listenPointerInput(this.listener,this.zIndexInternal)):this.modeInternal===U.INTERACTIVE&&this.listener&&(this.layer.unlistenPointerInput(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.unlistenPointerInput(this.listener),this.solverWrapper.removeVariable(this.hVariable),this.solverWrapper.removeVariable(this.wVariable),this.sceneWrapper.destroyPlane(this.planeHandler),super.destroy()}onWillRender(t,i){const s=this.micro,e=this.width*s.scaleX,r=this.height*s.scaleY,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===Dt.POSITION_ROTATION_SCALE)Ft.x=this.x+s.x-l,Ft.y=this.y+s.y-c;else{const t=s.anchorY*this.height;Ft.x=this.x+s.anchorX*this.width-l+s.x,Ft.y=this.y+t-c+s.y}Ft.z=this.zIndexInternal,Wt.x=e,Wt.y=r,jt.setFromAxisAngle(qt,s.rotation),Gt.compose(Ft,jt,Wt),this.sceneWrapper.setTransform(this.planeHandler,Gt)}}var Xt="void main() {\n vec4 diffuseColor = texture(map, io_UV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";class Zt extends Yt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,n=s.color??new Q;super(t,s.x??0,s.y??0,e,r,Xt,{map:i,color:n}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ti=i,this.ii=n,this.ii.on(Z.CHANGE,this.Kt)}get texture(){return this.ti}get color(){return this.ii}set texture(t){const i=t.image.width,s=t.image.height;Et(i,"UIImage texture width"),Et(s,"UIImage texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ti=t,this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ii.copy(t)}destroy(){this.ii.off(Z.CHANGE,this.Kt),super.destroy()}}const Jt=.25;class Qt extends Yt{constructor(t,i,s={}){const e=i.image.width,r=i.image.height,h=s.color??new Q,o=(t=>{if(null==t)return{l:Jt,r:Jt,t:Jt,b:Jt};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:Jt,s="number"==typeof t.vertical?t.vertical:Jt;return{l:i,r:i,t:s,b:s}}return{l:"number"==typeof t.left?t.left:Jt,r:"number"==typeof t.right?t.right:Jt,t:"number"==typeof t.top?t.top:Jt,b:"number"==typeof t.bottom?t.bottom:Jt}}return{l:Jt,r:Jt,t:Jt,b:Jt}})(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.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ti=i,this.ii=h,this.si=a,this.ei=l,this.ii.on(Z.CHANGE,this.Kt)}get texture(){return this.ti}get color(){return this.ii}get sliceBorderLeft(){return this.si.x}get sliceBorderRight(){return this.si.y}get sliceBorderTop(){return this.si.z}get sliceBorderBottom(){return this.si.w}set texture(t){const i=t.image.width,s=t.image.height;Et(i,"UINineSlice texture width"),Et(s,"UINineSlice texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.ei.x=i,this.ei.y=s,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.ei),this.sceneWrapper.setUniform(this.planeHandler,"map",t)}set color(t){this.ii.copy(t)}set sliceBorderLeft(t){this.si.x=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderRight(t){this.si.y=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderTop(t){this.si.z=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}set sliceBorderBottom(t){this.si.w=t,this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}setSliceBorders(t,i,s,e){this.si.set(t,i,s,e),this.sceneWrapper.setUniform(this.planeHandler,"sliceBorders",this.si)}destroy(){this.ii.off(Z.CHANGE,this.Kt),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.ei.z=this.width*this.micro.scaleX,this.ei.w=this.height*this.micro.scaleY,this.sceneWrapper.setUniform(this.planeHandler,"dimensions",this.ei)}}const Kt=new o;var ti,ii;(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 }"})(ti||(ti={}));class si extends Yt{constructor(t,i,s={}){const e=i.image?.width,r=i.image?.height;Et(e,"UIProgress foreground texture width"),Et(r,"UIProgress foreground texture height"),s.backgroundTexture&&(Et(s.backgroundTexture.image.width,"UIProgress background texture width"),Et(s.backgroundTexture.image.height,"UIProgress background texture height"));const n=s.color??new Q,h=s.foregroundColor??new Q,o=s.backgroundColor??new Q,a=s.progress??1,l=s.inverseDirection??!1;super(t,s.x??0,s.y??0,e,r,(s.maskFunction??ti.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??Kt,color:n,foregroundColor:h,backgroundColor:o,progress:a,direction:l?-1:1}),this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.ri=t=>{this.sceneWrapper.setUniform(this.planeHandler,"foregroundColor",t)},this.ni=t=>{this.sceneWrapper.setUniform(this.planeHandler,"backgroundColor",t)},this.hi=i,this.oi=s.backgroundTexture,this.ii=n,this.ai=h,this.li=o,this.ci=a,this.ui=l,this.ii.on(Z.CHANGE,this.Kt),this.ai.on(Z.CHANGE,this.ri),this.li.on(Z.CHANGE,this.ni)}get foregroundTexture(){return this.hi}get backgroundTexture(){return this.oi}get color(){return this.ii}get foregroundColor(){return this.ai}get backgroundColor(){return this.li}get progress(){return this.ci}get inverseDirection(){return this.ui}set foregroundTexture(t){const i=t.image.width,s=t.image.height;Et(i,"UIProgress foreground texture width"),Et(s,"UIProgress foreground texture height"),this.solverWrapper.suggestVariableValue(this.wVariable,i),this.solverWrapper.suggestVariableValue(this.hVariable,s),this.hi=t,this.sceneWrapper.setUniform(this.planeHandler,"foregroundTexture",t)}set backgroundTexture(t){void 0!==t&&(Et(t.image.width,"UIProgress background texture width"),Et(t.image.height,"UIProgress background texture height")),this.oi=t,this.sceneWrapper.setUniform(this.planeHandler,"backgroundTexture",t)}set color(t){this.ii.copy(t)}set foregroundColor(t){this.ai.copy(t)}set backgroundColor(t){this.li.copy(t)}set inverseDirection(t){this.ui=t,this.sceneWrapper.setUniform(this.planeHandler,"direction",t?-1:1)}set progress(t){this.ci=t,this.sceneWrapper.setUniform(this.planeHandler,"progress",t)}destroy(){this.ii.off(Z.CHANGE,this.Kt),this.ai.off(Z.CHANGE,this.ri),this.li.off(Z.CHANGE,this.ni),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"})(ii||(ii={}));const ei=ii.PROPERTY_CHANGED;class ri extends Yt{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 g(r*e,n*e,{format:v,minFilter:m,magFilter:m,type:w,depthBuffer:i.enableDepthBuffer??!0,stencilBuffer:!1}),o=i.color??new Q;super(t,0,0,r,n,Xt,{map:h.texture,color:o}),this.fi=!0,this.di=!1,this.pi=!1,this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.gi=h,this.ii=o,this.wi=i.scene??new s,this.mi=i.camera??new y(75,r/n,.1,100),this.yi=e,this.bi=i.updateMode??ei,this.xi=i.clearColor??0,this._i=i.clearAlpha??0,i.updateMode===ii.PROPERTY_CHANGED&&(this.pi=!0),this.ii.on(Z.CHANGE,this.Kt)}get color(){return this.ii}get scene(){return this.wi}get camera(){return this.mi}get updateMode(){return this.bi}get resolutionFactor(){return this.yi}get clearColor(){return this.xi}get clearAlpha(){return this._i}set color(t){this.ii.copy(t)}set scene(t){this.wi!==t&&(this.wi=t,this.di=!0)}set camera(t){this.mi!==t&&(this.mi=t,this.di=!0)}set updateMode(t){this.bi!==t&&(this.bi=t,this.di=!0)}set resolutionFactor(t){this.yi!==t&&(this.yi=t,this.gi.setSize(this.width*this.yi,this.height*this.yi),this.di=!0)}set clearColor(t){this.xi!==t&&(this.xi=t,this.di=!0)}set clearAlpha(t){this._i!==t&&(this._i=t,this.di=!0)}destroy(){this.ii.off(Z.CHANGE,this.Kt),this.gi.dispose(),super.destroy()}requestRender(){this.pi=!0}onWillRender(t){(this.bi===ii.EACH_FRAME||this.bi===ii.EACH_SECOND_FRAME&&this.fi||this.bi===ii.PROPERTY_CHANGED&&this.di||this.bi===ii.MANUAL&&this.pi)&&(this.pi=!1,this.di=!1,this.fi=!this.fi,this.gi.setSize(this.width*this.yi,this.height*this.yi),t.setClearColor(this.xi,this.clearAlpha),t.setRenderTarget(this.gi),t.clear(!0,!0,!1),t.render(this.wi,this.mi))}}function ni(t){return"object"==typeof t&&null!==t&&!("string"!=typeof t.color||"string"!=typeof t.fontFamily||"number"!=typeof t.fontSize||"normal"!==t.fontStyle&&"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||"normal"!==t.fontWeight&&"bold"!==t.fontWeight&&"bolder"!==t.fontWeight&&"lighter"!==t.fontWeight&&"number"!=typeof t.fontWeight||"number"!=typeof t.lineHeight||"boolean"!=typeof t.enableShadow||"number"!=typeof t.shadowOffsetX||"number"!=typeof t.shadowOffsetY||"number"!=typeof t.shadowBlur||"string"!=typeof t.shadowColor||"boolean"!=typeof t.enableStroke||"string"!=typeof t.strokeColor||"number"!=typeof t.strokeWidth)}function hi(t,i){const s=t?.fontSize??i?.fontSize??16;Et(s,"Font size");const e=t?.fontWeight??i?.fontWeight??"normal";"number"==typeof e&&Et(e,"Font weight");const r=t?.lineHeight??i?.lineHeight??1.2*s;_t(r,"Line height");const n=t?.shadowOffsetX??i?.shadowOffsetX??0;Ct(n,"Shadow offset X");const h=t?.shadowOffsetY??i?.shadowOffsetY??0;Ct(h,"Shadow offset Y");const o=t?.shadowBlur??i?.shadowBlur??0;Ct(o,"Shadow blur");const a=t?.strokeWidth??i?.strokeWidth??0;return Ct(a,"Stroke width"),{color:t?.color??i?.color??"#000000",fontFamily:t?.fontFamily??i?.fontFamily??"Arial",fontSize: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 oi(t){return t.match(/\S+|\s|\n/g)??[]}function ai(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 li(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 ci(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 ui(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 Ct(i,"Padding left"),Ct(s,"Padding right"),Ct(e,"Padding top"),Ct(r,"Padding bottom"),{left:i,right:s,top:e,bottom:r}}return{left:0,right:0,top:0,bottom:0}}class fi extends Yt{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 b(e),h=s.color??new Q;super(t,s.x??0,s.y??0,2,2,Xt,{map:n,color:h}),this.Ei=1,this.Kt=t=>{this.sceneWrapper.setUniform(this.planeHandler,"color",t)},this.Ci=e,this.Ii=r,this.Ui=n,this.ii=h,this.Mi=i,this.Si=s.maxWidth??1024,this.Ti=ui(s.padding),this.Bi=s.commonStyle??{},this.ii.on(Z.CHANGE,this.Kt),this.Vi()}get color(){return this.ii}get content(){return this.Mi}get maxWidth(){return this.Si}get padding(){return this.Ti}get commonStyle(){return this.Bi}set color(t){this.ii.copy(t)}set content(t){this.Mi=t,this.Vi()}set maxWidth(t){this.Si=t,this.Vi()}set padding(t){this.Ti=t,this.Vi()}set commonStyle(t){this.Bi=t,this.Vi()}destroy(){this.ii.off(Z.CHANGE,this.Kt),this.Ui.dispose(),super.destroy()}onWillRender(t,i){super.onWillRender(t,i),this.Ei!==this.width/this.height&&(this.height=this.width/this.Ei)}Vi(){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=hi(i?void 0:s.style,e);for(const i of oi(n)){const s=ai(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:li(n)}})(this.Ii,this.content,this.Si,this.Bi);this.Ci.width=i.width+this.Ti.left+this.Ti.right,this.Ci.height=i.height+this.Ti.top+this.Ti.bottom,this.width=this.Ci.width,this.height=this.Ci.height,this.Ei=this.Ci.width/this.Ci.height,((t,i,s,e)=>{let r=this.Ti.top;for(let t=0;s.length>t;t++){const n=s[t];let h=i;r+=0===t?n.height:n.lineHeight;for(const t of n.chunks)ci(h,r,t.text,t.style,e),h+=t.metrics.width}})(0,this.Ti.left,t,this.Ii),this.Ui.dispose(),this.Ui=new b(this.Ci),this.Ui.needsUpdate=!0}}class di extends pt{constructor(t,i){void 0!==t&&Et(t,"UIFullscreenLayer.fixedWidth"),void 0!==i&&Et(i,"UIFullscreenLayer.fixedHeight"),super(window.innerWidth,window.innerHeight),this.Ai=()=>{const t=this.ki();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.Pi=t=>{const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,s=i?t.clientX-i.left:t.clientX,e=i?i.bottom-t.clientY:window.innerHeight-t.clientY,r=this.ki();this.pointerClickInternal(s*r,e*r)},this.$i=t,this.Hi=i,window.addEventListener("resize",this.Ai),window.addEventListener("pointerdown",this.Pi),this.Ai()}get fixedWidth(){return this.$i}get fixedHeight(){return this.Hi}set fixedWidth(t){void 0!==t&&Et(t,"UIFullscreenLayer.fixedWidth"),t!==this.$i&&(this.$i=t,this.Ai())}set fixedHeight(t){void 0!==t&&Et(t,"UIFullscreenLayer.fixedHeight"),t!==this.Hi&&(this.Hi=t,this.Ai())}destroy(){window.removeEventListener("resize",this.Ai),window.removeEventListener("pointerdown",this.Pi)}render(t,i){_t(i,"UIFullscreenLayer.deltaTime"),super.renderInternal(t,i)}ki(){return this.orientation===M.HORIZONTAL?void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:1:void 0!==this.fixedHeight?this.fixedHeight/window.innerHeight:void 0!==this.fixedWidth?this.fixedWidth/window.innerWidth:1}}const pi=(()=>{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 gi(t){if("Texture"===t||t instanceof o)return{glslType:"sampler2D",instantiable:!1,itemSize:-1};if("UIColor"===t||t instanceof Q)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 wi(t,i,s){const e=i.array;if(t instanceof Q)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 mi(t,i){const s=gi(t);if(!s.instantiable)throw Error("Invalid property type: "+t);return new _(new Float32Array(i*s.itemSize),s.itemSize)}class vi extends h{constructor(t,i,s=J.CLIP,e=16){const n={},h={instanceTransform:"Matrix4",uvTransform:"Matrix3",...s===J.CLIP?{alphaTest:"number"}:{}};for(const[t,s]of Object.entries(i))(gi(s).instantiable?h:n)[t]=s;const o=pi.clone(),a=((t,i,s,e)=>{const n={},h=[],o=[],a=[],l=[];for(const[t,s]of Object.entries(i)){const i=gi(s).glslType;n["u_"+t]={value:null},h.push(`uniform ${i} u_${t};`)}for(const[t,i]of Object.entries(s)){const s=gi(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===J.BLEND,alphaTest:e===J.CLIP?.5:0,alphaHash:e===J.HASH})})(t,n,h,s);super(o,a),this.handlerToDescriptor=new Map,this.lastHandler=0,this.capacity=0,this.propertyBuffers=new Map,this.Li=o,this.Li.instanceCount=0,this.Ri=a,this.capacity=Math.max(e,16);for(const[t,i]of Object.entries(h)){const s=mi(i,this.capacity);this.Li.setAttribute("a_"+t,s),this.propertyBuffers.set("a_"+t,s)}}createInstances(t){const i=this.lastHandler++;return this.Li.instanceCount+t>this.capacity&&this.zi(16*Math.ceil((this.capacity+t)/16)),this.handlerToDescriptor.set(i,{firstIndex:this.Li.instanceCount,count:t}),this.Li.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.Di(r,i),r.firstIndex=i.firstIndex,this.Ni(r.firstIndex+r.count,r.count)):this.Ni(i.firstIndex+i.count,i.count),this.Li.instanceCount-=i.count}updateProperties(t,i,s){Ct(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(gi(i).instantiable){const s=this.Oi(t);wi(i,s,n*s.itemSize)}else this.Fi(t).value=i,this.Ri.uniformsNeedUpdate=!0}}updateTransforms(t,i,s){Ct(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.Oi("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){Ct(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.Oi("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){Ct(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.Oi("visibility");r.array[(e.firstIndex+i+t)*r.itemSize]=s[t]?1:0,r.needsUpdate=!0}}destroy(){this.Li.dispose(),this.Ri.dispose()}gt(t){const i=this.handlerToDescriptor.get(t);if(void 0===i)throw Error("No active range found for handler: "+t);return i}Oi(t){const i=this.propertyBuffers.get("a_"+t);if(void 0===i)throw Error(`No attribute found for property: ${t} (a_${t})`);return i}Fi(t){const i=this.Ri.uniforms["u_"+t];if(void 0===i)throw Error("No uniform found for handler: "+t);return i}zi(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.Li.setAttribute("a_"+i,n),this.propertyBuffers.set("a_"+i,n)}this.capacity=t}Di(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}}Ni(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.Li.instanceCount*r,h=i*r;for(let i=t*r;n-h>i;i++)e[i]=e[i+h];s.needsUpdate=!0}}}function yi(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text&&(!("style"in t)||ni(t.style))}export{Lt as UIAnchor,Vt as UIAspectConstraint,Q as UIColor,Z as UIColorEvent,gt as UIConstraint,Bt as UIConstraint2DBuilder,kt as UICoverConstraintBuilder,Ht as UICustomConstraint,Rt as UIDummy,Yt as UIElement,E as UIExpression,$t as UIFitConstraintBuilder,di as UIFullscreenLayer,vi as UIGenericInstancedPlane,mt as UIHeightConstraint,It as UIHorizontalDistanceConstraint,Ut as UIHorizontalProportionConstraint,Zt as UIImage,zt as UIInputEvent,pt as UILayer,ct as UILayerEvent,Ot as UIMicro,Dt as UIMicroAnchorMode,U as UIMode,Qt as UINineSlice,M as UIOrientation,G as UIPriority,si as UIProgress,ti as UIProgressMaskFunction,lt as UIRelation,ri as UIScene,ii as UISceneUpdateMode,wt as UISingleParameterConstraint,fi as UIText,J as UITransparencyMode,Mt as UIVerticalDistanceConstraint,St as UIVerticalProportionConstraint,Tt as UIWidthConstraint,q as convertPriority,ut as convertRelation,yi as isUITextSpan,ni as isUITextStyle,S as resolveOrientation,Y as resolvePriority,ft as resolveRelation,ui as resolveTextPadding,hi as resolveTextStyle};
2
2
  //# sourceMappingURL=index.min.js.map