laymur 0.1.40 → 0.1.41

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.d.ts CHANGED
@@ -21,7 +21,7 @@ export * from "./Elements/UIProgress";
21
21
  export * from "./Elements/UIScene";
22
22
  export * from "./Elements/UIText";
23
23
  export * from "./Layers/UIFullScreenLayer";
24
- export { UILayerEvent } from "./Layers/UILayer";
24
+ export * from "./Layers/UILayer";
25
25
  export * from "./Layers/UIManualLayer";
26
26
  export * from "./Miscellaneous/UIBehavior";
27
27
  export { UIOrientation } from "./Miscellaneous/UIOrientation";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Vector2 as t,Box2 as i,Matrix3 as s,Vector3 as n,MathUtils as o,ShaderMaterial as e,Color as r,PlaneGeometry as h,Scene as l,Mesh as u,OrthographicCamera as a,WebGLRenderTarget as d,UnsignedByteType as c,LinearFilter as v,RGBAFormat as f,NoBlending as w,Object3D as p,UniformsUtils as g,CanvasTexture as m,Texture as y,PerspectiveCamera as b}from"three";function x(){return new C}var C=function(){function t(){this.index={},this.array=[]}return t.prototype.size=function(){return this.array.length},t.prototype.empty=function(){return 0===this.array.length},t.prototype.itemAt=function(t){return this.array[t]},t.prototype.contains=function(t){return void 0!==this.index[t.id()]},t.prototype.find=function(t){var i=this.index[t.id()];return void 0===i?void 0:this.array[i]},t.prototype.setDefault=function(t,i){var s=this.index[t.id()];if(void 0===s){var n=new S(t,i());return this.index[t.id()]=this.array.length,this.array.push(n),n}return this.array[s]},t.prototype.insert=function(t,i){var s=new S(t,i),n=this.index[t.id()];return void 0===n?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[n]=s,s},t.prototype.erase=function(t){var i=this.index[t.id()];if(void 0!==i){this.index[t.id()]=void 0;var s=this.array[i],n=this.array.pop();return s!==n&&(this.array[i]=n,this.index[n.first.id()]=i),s}},t.prototype.copy=function(){for(var i=new t,s=0;s<this.array.length;s++){var n=this.array[s].copy();i.array[s]=n,i.index[n.first.id()]=s}return i},t}(),S=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),E=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=k++,this.h=t}return t.prototype.id=function(){return this.o},t.prototype.name=function(){return this.h},t.prototype.setName=function(t){this.h=t},t.prototype.context=function(){return this.i},t.prototype.setContext=function(t){this.i=t},t.prototype.value=function(){return this.t},t.prototype.setValue=function(t){this.t=t},t.prototype.plus=function(t){return new O(this,t)},t.prototype.minus=function(t){return new O(this,"number"==typeof t?-t:[-1,t])},t.prototype.multiply=function(t){return new O([t,this])},t.prototype.divide=function(t){return new O([1/t,this])},t.prototype.toJSON=function(){return{name:this.h,value:this.t}},t.prototype.toString=function(){return this.i+"["+this.h+":"+this.t+"]"},t}(),k=0,O=function(){function t(){var t=T(arguments);this.l=t.terms,this.u=t.constant}return t.prototype.terms=function(){return this.l},t.prototype.constant=function(){return this.u},t.prototype.value=function(){for(var t=this.u,i=0,s=this.l.size();i<s;i++){var n=this.l.itemAt(i);t+=n.first.value()*n.second}return t},t.prototype.plus=function(i){return new t(this,i)},t.prototype.minus=function(i){return new t(this,"number"==typeof i?-i:[-1,i])},t.prototype.multiply=function(i){return new t([i,this])},t.prototype.divide=function(i){return new t([1/i,this])},t.prototype.isConstant=function(){return 0==this.l.size()},t.prototype.toString=function(){var t=this.l.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.u||(t+=" + "),t+this.u},t}();function T(t){for(var i=0,s=()=>0,n=x(),o=0,e=t.length;o<e;++o){var r=t[o];if("number"==typeof r)i+=r;else if(r instanceof E)n.setDefault(r,s).second+=1;else if(r instanceof O){i+=r.constant();for(var h=0,l=(c=r.terms()).size();h<l;h++){var u=c.itemAt(h);n.setDefault(u.first,s).second+=u.second}}else{if(!(r instanceof Array))throw Error("invalid Expression argument: "+r);if(2!==r.length)throw Error("array must have length 2");var a=r[0],d=r[1];if("number"!=typeof a)throw Error("array item 0 must be a number");if(d instanceof E)n.setDefault(d,s).second+=a;else{if(!(d instanceof O))throw Error("array item 1 must be a variable or expression");var c;for(i+=d.constant()*a,h=0,l=(c=d.terms()).size();h<l;h++)u=c.itemAt(h),n.setDefault(u.first,s).second+=u.second*a}}}return{terms:n,constant:i}}var M,P=(()=>{function t(){}return t.create=(t,i,s,n)=>{void 0===n&&(n=1);var o=0;return o+=1e6*Math.max(0,Math.min(1e3,t*n)),(o+=1e3*Math.max(0,Math.min(1e3,i*n)))+Math.max(0,Math.min(1e3,s*n))},t.clip=i=>Math.max(0,Math.min(t.required,i)),t.required=t.create(1e3,1e3,1e3),t.strong=t.create(1,0,0),t.medium=t.create(0,1,0),t.weak=t.create(0,0,1),t})();(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(M||(M={}));var I,$=function(){function t(t,i,s,n){void 0===n&&(n=P.required),this.o=A++,this.v=i,this.p=P.clip(n),this.m=void 0===s&&t instanceof O?t:t.minus(s)}return t.prototype.id=function(){return this.o},t.prototype.expression=function(){return this.m},t.prototype.op=function(){return this.v},t.prototype.strength=function(){return this.p},t.prototype.toString=function(){return this.m+" "+["<=",">=","="][this.v]+" 0 ("+this.p+")"},t}(),A=0,D=function(){function t(){this.C=x(),this.S=x(),this.k=x(),this.O=x(),this.T=[],this.M=new j,this.P=null,this.I=0}return t.prototype.createConstraint=function(t,i,s,n){void 0===n&&(n=P.required);var o=new $(t,i,s,n);return this.addConstraint(o),o},t.prototype.addConstraint=function(t){if(void 0!==this.C.find(t))throw Error("duplicate constraint");var i=this.$(t),s=i.row,n=i.tag,o=this.A(s,n);if(o.type()===I.Invalid&&s.allDummies()){if(!z(s.constant()))throw Error("unsatisfiable constraint");o=n.marker}if(o.type()===I.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(o),this.F(o,s),this.S.insert(o,s);this.C.insert(t,n),this.U(this.M)},t.prototype.removeConstraint=function(t){var i=this.C.erase(t);if(void 0===i)throw Error("unknown constraint");this.j(t,i.second);var s=i.second.marker,n=this.S.erase(s);if(void 0===n){var o=this.B(s);if(o.type()===I.Invalid)throw Error("failed to find leaving row");(n=this.S.erase(o)).second.solveForEx(o,s),this.F(s,n.second)}this.U(this.M)},t.prototype.hasConstraint=function(t){return this.C.contains(t)},t.prototype.addEditVariable=function(t,i){if(void 0!==this.O.find(t))throw Error("duplicate edit variable");if((i=P.clip(i))===P.required)throw Error("bad required strength");var s=new O(t),n=new $(s,M.Eq,void 0,i);this.addConstraint(n);var o=this.C.find(n).second;this.O.insert(t,{tag:o,constraint:n,constant:0})},t.prototype.removeEditVariable=function(t){var i=this.O.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)},t.prototype.hasEditVariable=function(t){return this.O.contains(t)},t.prototype.suggestValue=function(t,i){var s=this.O.find(t);if(void 0===s)throw Error("unknown edit variable");var n=this.S,o=s.second,e=i-o.constant;o.constant=i;var r=o.tag.marker,h=n.find(r);if(void 0!==h)return h.second.add(-e)<0&&this.T.push(r),void this.H();var l=o.tag.other;if(void 0!==(h=n.find(l)))return h.second.add(e)<0&&this.T.push(l),void this.H();for(var u=0,a=n.size();u<a;++u){var d=n.itemAt(u),c=d.second,v=c.coefficientFor(r);0!==v&&c.add(e*v)<0&&d.first.type()!==I.External&&this.T.push(d.first)}this.H()},t.prototype.updateVariables=function(){for(var t=this.k,i=this.S,s=0,n=t.size();s<n;++s){var o=t.itemAt(s),e=i.find(o.second);o.first.setValue(void 0!==e?e.second.constant():0)}},t.prototype.V=function(t){var i=this;return this.k.setDefault(t,(()=>i.R(I.External))).second},t.prototype.$=function(t){for(var i=t.expression(),s=new j(i.constant()),n=i.terms(),o=0,e=n.size();o<e;++o){var r=n.itemAt(o);if(!z(r.second)){var h=this.V(r.first),l=this.S.find(h);void 0!==l?s.insertRow(l.second,r.second):s.insertSymbol(h,r.second)}}var u=this.M,a=t.strength(),d={marker:U,other:U};switch(t.op()){case M.Le:case M.Ge:var c=t.op()===M.Le?1:-1,v=this.R(I.Slack);if(d.marker=v,s.insertSymbol(v,c),a<P.required){var f=this.R(I.Error);d.other=f,s.insertSymbol(f,-c),u.insertSymbol(f,a)}break;case M.Eq:if(a<P.required){var w=this.R(I.Error),p=this.R(I.Error);d.marker=w,d.other=p,s.insertSymbol(w,-1),s.insertSymbol(p,1),u.insertSymbol(w,a),u.insertSymbol(p,a)}else{var g=this.R(I.Dummy);d.marker=g,s.insertSymbol(g)}}return s.constant()<0&&s.reverseSign(),{row:s,tag:d}},t.prototype.A=(t,i)=>{for(var s=t.cells(),n=0,o=s.size();n<o;++n){var e=s.itemAt(n);if(e.first.type()===I.External)return e.first}var r=i.marker.type();return(r===I.Slack||r===I.Error)&&t.coefficientFor(i.marker)<0?i.marker:((r=i.other.type())===I.Slack||r===I.Error)&&t.coefficientFor(i.other)<0?i.other:U},t.prototype.D=function(t){var i=this.R(I.Slack);this.S.insert(i,t.copy()),this.P=t.copy(),this.U(this.P);var s=z(this.P.constant());this.P=null;var n=this.S.erase(i);if(void 0!==n){var o=n.second;if(o.isConstant())return s;var e=this.L(o);if(e.type()===I.Invalid)return 0;o.solveForEx(i,e),this.F(e,o),this.S.insert(e,o)}for(var r=this.S,h=0,l=r.size();h<l;++h)r.itemAt(h).second.removeSymbol(i);return this.M.removeSymbol(i),s},t.prototype.F=function(t,i){for(var s=this.S,n=0,o=s.size();n<o;++n){var e=s.itemAt(n);e.second.substitute(t,i),e.second.constant()<0&&e.first.type()!==I.External&&this.T.push(e.first)}this.M.substitute(t,i),this.P&&this.P.substitute(t,i)},t.prototype.U=function(t){for(;;){var i=this.K(t);if(i.type()===I.Invalid)return;var s=this._(i);if(s.type()===I.Invalid)throw Error("the objective is unbounded");var n=this.S.erase(s).second;n.solveForEx(s,i),this.F(i,n),this.S.insert(i,n)}},t.prototype.H=function(){for(var t=this.S,i=this.T;0!==i.length;){var s=i.pop(),n=t.find(s);if(void 0!==n&&n.second.constant()<0){var o=this.N(n.second);if(o.type()===I.Invalid)throw Error("dual optimize failed");var e=n.second;t.erase(s),e.solveForEx(s,o),this.F(o,e),t.insert(o,e)}}},t.prototype.K=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var o=i.itemAt(s),e=o.first;if(o.second<0&&e.type()!==I.Dummy)return e}return U},t.prototype.N=function(t){for(var i=Number.MAX_VALUE,s=U,n=t.cells(),o=0,e=n.size();o<e;++o){var r=n.itemAt(o),h=r.first,l=r.second;if(l>0&&h.type()!==I.Dummy){var u=this.M.coefficientFor(h)/l;u<i&&(i=u,s=h)}}return s},t.prototype._=function(t){for(var i=Number.MAX_VALUE,s=U,n=this.S,o=0,e=n.size();o<e;++o){var r=n.itemAt(o),h=r.first;if(h.type()!==I.External){var l=r.second,u=l.coefficientFor(t);if(u<0){var a=-l.constant()/u;a<i&&(i=a,s=h)}}}return s},t.prototype.B=function(t){for(var i=Number.MAX_VALUE,s=i,n=i,o=U,e=o,r=o,h=o,l=this.S,u=0,a=l.size();u<a;++u){var d=l.itemAt(u),c=d.second,v=c.coefficientFor(t);if(0!==v){var f=d.first;if(f.type()===I.External)h=f;else if(v<0)(w=-c.constant()/v)<s&&(s=w,e=f);else{var w;(w=c.constant()/v)<n&&(n=w,r=f)}}}return e!==o?e:r!==o?r:h},t.prototype.j=function(t,i){i.marker.type()===I.Error&&this.X(i.marker,t.strength()),i.other.type()===I.Error&&this.X(i.other,t.strength())},t.prototype.X=function(t,i){var s=this.S.find(t);void 0!==s?this.M.insertRow(s.second,-i):this.M.insertSymbol(t,-i)},t.prototype.L=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var o=i.itemAt(s),e=o.first.type();if(e===I.Slack||e===I.Error)return o.first}return U},t.prototype.R=function(t){return new F(t,this.I++)},t}();function z(t){return t<0?-t<1e-8:t<1e-8}(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"})(I||(I={}));var F=function(){function t(t,i){this.o=i,this.Y=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this.Y},t}(),U=new F(I.Invalid,-1),j=function(){function t(t){void 0===t&&(t=0),this.q=x(),this.u=t}return t.prototype.cells=function(){return this.q},t.prototype.constant=function(){return this.u},t.prototype.isConstant=function(){return this.q.empty()},t.prototype.allDummies=function(){for(var t=this.q,i=0,s=t.size();i<s;++i)if(t.itemAt(i).first.type()!==I.Dummy)return 0;return 1},t.prototype.copy=function(){var i=new t(this.u);return i.q=this.q.copy(),i},t.prototype.add=function(t){return this.u+=t},t.prototype.insertSymbol=function(t,i){void 0===i&&(i=1),z(this.q.setDefault(t,(()=>0)).second+=i)&&this.q.erase(t)},t.prototype.insertRow=function(t,i){void 0===i&&(i=1),this.u+=t.u*i;for(var s=t.q,n=0,o=s.size();n<o;++n){var e=s.itemAt(n);this.insertSymbol(e.first,e.second*i)}},t.prototype.removeSymbol=function(t){this.q.erase(t)},t.prototype.reverseSign=function(){this.u=-this.u;for(var t=this.q,i=0,s=t.size();i<s;++i){var n=t.itemAt(i);n.second=-n.second}},t.prototype.solveFor=function(t){var i=this.q,s=-1/i.erase(t).second;this.u*=s;for(var n=0,o=i.size();n<o;++n)i.itemAt(n).second*=s},t.prototype.solveForEx=function(t,i){this.insertSymbol(t,-1),this.solveFor(i)},t.prototype.coefficientFor=function(t){var i=this.q.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var s=this.q.erase(t);void 0!==s&&this.insertRow(i,s.second)},t}();const B=Symbol("xSymbol"),H=Symbol("ySymbol"),V=Symbol("widthSymbol"),R=Symbol("heightSymbol"),L=Symbol("addUIElementSymbol"),K=Symbol("removeUIElementSymbol"),_=Symbol("addConstraintSymbol"),N=Symbol("removeUIConstraintSymbol"),X=Symbol("addConstraintSymbol"),Y=Symbol("removeConstraintSymbol"),q=Symbol("addVariableSymbol"),W=Symbol("removeVariableSymbol"),G=Symbol("suggestVariableSymbol"),Q=Symbol("disableConstraintSymbol"),J=Symbol("enableConstraintSymbol"),Z=Symbol("needsRecalculation"),tt=Symbol("renderSymbol"),it=Symbol("clickSymbol");var st,nt,ot;function et(t){return null!==t&&Object.values(st).some((i=>i===t))}function rt(t){return null!=t?t:st.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(st||(st={}));class ht{constructor(t,i){this.layer=t,this.name="",this.layer[_](this,i)}destroy(){this.layer[N](this)}}function lt(t){return null!==t&&Object.values(nt).some((i=>i===t))}function ut(t){return null!=t?t:nt.P0}function at(t){switch(t){case nt.P0:return P.create(1e3,1e3,1e3);case nt.P1:return P.create(100,0,0);case nt.P2:return P.create(10,0,0);case nt.P3:return P.create(0,100,0);case nt.P4:return P.create(0,10,0);case nt.P5:return P.create(0,0,100);case nt.P6:return P.create(0,0,10);case nt.P7:return P.create(0,0,1);default:return P.create(1e3,1e3,1e3)}}function dt(t){return null!==t&&Object.values(ot).some((i=>i===t))}function ct(t){return null!=t?t:ot.EQUAL}function vt(t){switch(t){case ot.EQUAL:return M.Eq;case ot.LESS:return M.Le;case ot.GREATER:return M.Ge;default:return M.Eq}}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(nt||(nt={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(ot||(ot={}));class ft extends ht{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.options={height:null!==(s=null==i?void 0:i.height)&&void 0!==s?s:t.height,power:ut(null==i?void 0:i.power),rule:ct(null==i?void 0:i.rule),orientation:rt(null==i?void 0:i.orientation)},this.options.orientation!==st.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.options.orientation!==st.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[J](t){this.options.orientation!==st.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new $(new O(this.element[R]),vt(this.options.rule),this.options.height,at(this.options.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class wt{constructor(){this.listeners=new Map}on(t,i,s,n=100){return this.addListener(t,i,s,n,0),this}once(t,i,s,n=100){return this.addListener(t,i,s,n,1),this}off(t,i,s){const n=this.listeners.get(t);if(!n)return this;if(!i)return this.listeners.delete(t),this;const o=n.filter((t=>t.callback!==i||void 0!==s&&t.context!==s));return o.length?this.listeners.set(t,o):this.listeners.delete(t),this}emit(t,...i){const s=this.listeners.get(t);if(!(null==s?void 0:s.length))return 0;for(const n of[...s])n.callback.apply(n.context,i),n.once&&this.off(t,n.callback,n.context);return 1}addListener(t,i,s,n,o){let e=this.listeners.get(t);if(e||(e=[],this.listeners.set(t,e)),e.some((t=>t.callback===i&&t.context===s)))throw Error("Event listener already exists");const r={callback:i,context:s,priority:n,once:o};let h=0;for(;h<e.length&&e[h].priority<=n;)h++;e.splice(h,0,r)}}const pt=new t,gt=new i,mt=new s,yt=new s,bt=new s,xt=new s,Ct=new s,St=new n;var Et,kt;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(Et||(Et={}));const Ot=.5;class Tt{constructor(t){this.owner=t,this[kt]=0,this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=Ot,this.anchorYInternal=Ot,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0}get x(){return this.positionXInternal}get y(){return this.positionYInternal}get anchorX(){return this.anchorXInternal}get anchorY(){return this.anchorYInternal}get scaleX(){return this.scaleXInternal}get scaleY(){return this.scaleYInternal}get angle(){return o.radToDeg(this.rotationInternal)}get rotation(){return this.rotationInternal}set x(t){this.positionXInternal=t,this[Z]=1}set y(t){this.positionYInternal=t,this[Z]=1}set anchorX(t){this.anchorXInternal=t,this[Z]=1}set anchorY(t){this.anchorYInternal=t,this[Z]=1}set scaleX(t){this.scaleXInternal=t,this[Z]=1}set scaleY(t){this.scaleYInternal=t,this[Z]=1}set angle(t){this.rotationInternal=o.degToRad(t),this[Z]=1}set rotation(t){this.rotationInternal=t,this[Z]=1}setAnchorByGlobalPosition(t,i){const s=i-this.owner.y;this.anchorXInternal=(t-this.owner.x)/this.owner.width,this.anchorYInternal=s/this.owner.height,this[Z]=1}reset(){this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=Ot,this.anchorYInternal=Ot,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0,this[Z]=1}}kt=Z;class Mt extends e{constructor(t){super({uniforms:{map:{value:t},opacity:{value:1},color:{value:new r(1,1,1)}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D map;\n uniform float opacity;\n uniform vec3 color;\n varying vec2 vUv;\n\n void main() {\n vec4 textureColor = texture2D(map, vUv);\n gl_FragColor = vec4(textureColor.rgb * color, textureColor.a * opacity);\n #include <colorspace_fragment>\n }\n ",transparent:1,lights:0,fog:0})}getTexture(){return this.uniforms.map.value}getColor(){return this.uniforms.color.value.getHex()}getOpacity(){return this.uniforms.opacity.value}setTexture(t){this.uniforms.map.value=t,this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=1}}const Pt=new h(1,1).translate(.5,.5,0),It=new l,$t=new u(Pt);It.add($t);class At{constructor(t=0,i=0){this.paddingHorizontalInternal=t,this.paddingVerticalInternal=i,this.camera=new a(-1,1,1,-1,0,1),this.updateCameraTransform()}get paddingHorizontal(){return this.paddingHorizontalInternal}get paddingVertical(){return this.paddingVerticalInternal}set paddingHorizontal(t){this.paddingHorizontalInternal!==t&&(this.paddingHorizontalInternal=t,this.updateCameraTransform())}set paddingVertical(t){this.paddingVerticalInternal!==t&&(this.paddingVerticalInternal=t,this.updateCameraTransform())}render(t,i){$t.material=i,t.render(It,this.camera)}updateCameraTransform(){this.camera.left=-this.paddingHorizontalInternal,this.camera.right=1+this.paddingHorizontalInternal,this.camera.bottom=-this.paddingVerticalInternal,this.camera.top=1+this.paddingVerticalInternal,this.camera.updateProjectionMatrix()}}class Dt{constructor(){this.passes=[],this.defaultMaterial=new Mt,this.screen=new At,this.needsUpdateInternal=0,this.lastPaddingHasChangedInternal=0,this.lastPaddingInternal=0;const t={format:f,minFilter:v,magFilter:v,type:c,depthBuffer:0,stencilBuffer:0};this.fromRenderTarget=new d(1,1,t),this.toRenderTarget=new d(1,1,t),this.fromRenderTarget.texture.generateMipmaps=0,this.toRenderTarget.texture.generateMipmaps=0}get needsUpdate(){return this.needsUpdateInternal&&this.hasValuablePasses()||this.hasPassesNeedingUpdate()}get lastPaddingHasChanged(){return this.lastPaddingHasChangedInternal}get lastPadding(){return this.lastPaddingInternal}requestUpdate(){this.needsUpdateInternal=1}compose(t,i,s,n,o=1){const e=this.hasValuablePasses();if(!(this.needsUpdateInternal&&e||this.hasPassesNeedingUpdate()))return e||(this.lastPaddingHasChangedInternal=0!==this.lastPaddingInternal,this.lastPaddingInternal=0),this.needsUpdateInternal=0,e?this.defaultMaterial:n;const r=this.calculatePadding();this.lastPaddingHasChangedInternal=this.lastPaddingInternal!==r,this.lastPaddingInternal=r;const h=i+2*r,l=s+2*r;this.fromRenderTarget.setSize(h,l),this.toRenderTarget.setSize(h,l),this.setScreenPadding(i,s,r),t.setClearColor(0,0),t.setRenderTarget(this.toRenderTarget),t.clear(1,0,0);const u=n.blending;o&&(n.blending=w),this.screen.render(t,n),n.blending=u;const a={width:i,height:s,padding:r};for(let i=0;i<this.passes.length;i++){const s=this.passes[i];(s.needsUpdate||s.isValuable)&&(this.reverseRenderTargets(),t.setRenderTarget(this.toRenderTarget),t.clear(1,0,0),this.passes[i].render(t,this.fromRenderTarget.texture,a))}return this.needsUpdateInternal=0,this.defaultMaterial.setTexture(this.toRenderTarget.texture),this.defaultMaterial}destroy(){this.fromRenderTarget.dispose(),this.toRenderTarget.dispose()}hasValuablePasses(){return this.passes.some((t=>t.isValuable))}hasPassesNeedingUpdate(){return this.passes.some((t=>t.needsUpdate))}calculatePadding(){return this.passes.reduce(((t,i)=>Math.max(t,i.padding)),0)}setScreenPadding(t,i,s){this.screen.paddingHorizontal=s/t,this.screen.paddingVertical=s/i}reverseRenderTargets(){const t=this.fromRenderTarget;this.fromRenderTarget=this.toRenderTarget,this.toRenderTarget=t}}var zt,Ft,Ut,jt,Bt,Ht,Vt,Rt,Lt,Kt;(t=>{t.CLICK="click"})(Ht||(Ht={}));class _t extends wt{constructor(t,i,s,n,o,e){super(),this.layer=t,this.object=i,this.name="",this[zt]=new E("x"),this[Ft]=new E("y"),this[Ut]=new E("width"),this[jt]=new E("height"),this[Bt]=0,this.behaviorInternal=Et.VISIBLE,this.composer=new Dt,this.lastPadding=0,this.micro=new Tt(this),this.layer[L](this,this.object),this.layer[q](this,this[B],at(nt.P7)),this.layer[q](this,this[H],at(nt.P7)),this.layer[q](this,this[V],at(nt.P5)),this.layer[q](this,this[R],at(nt.P5)),this[B].setValue(s),this[H].setValue(n),this[V].setValue(o),this[R].setValue(e),this.layer[G](this,this[B],s),this.layer[G](this,this[H],n),this.layer[G](this,this[V],o),this.layer[G](this,this[R],e)}get passes(){return this.composer.passes}get x(){return this[B].value()}get y(){return this[H].value()}get width(){return this[V].value()}get height(){return this[R].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[G](this,this[B],t)}set y(t){this.layer[G](this,this[H],t)}set width(t){this.layer[G](this,this[V],t)}set height(t){this.layer[G](this,this[R],t)}set zIndex(t){this.object.position.z=t}set behavior(t){this.behaviorInternal=t,this.object.visible=t!==Et.HIDDEN}destroy(){this.composer.destroy(),this.layer[W](this,this[R]),this.layer[W](this,this[V]),this.layer[W](this,this[H]),this.layer[W](this,this[B]),this.layer[K](this)}[(zt=B,Ft=H,Ut=V,jt=R,Bt=Z,it)](t,i){return this.behavior!==Et.INTERACTIVE?0:(this.flushTransform(),s=this.x,n=this.y,o=this.width,e=this.height,pt.set(t,i),gt.min.set(s,n),gt.max.set(o,e).add(gt.min),gt.containsPoint(pt)?(this.emit(Ht.CLICK,this),1):0);var s,n,o,e}flushTransform(){(this[Z]||this.micro[Z]||this.composer.lastPaddingHasChanged)&&(((t,i,s,n,o,e,r)=>{const h=this.x-r,l=this.y-r,u=this.width+2*r,a=this.height+2*r,d=h+u*i.anchorX,c=l+a*i.anchorY,v=mt.set(1,0,-d,0,1,-c,0,0,1),f=yt.set(i.scaleX,0,0,0,i.scaleY,0,0,0,1),w=bt.set(Math.cos(i.rotation),-Math.sin(i.rotation),0,Math.sin(i.rotation),Math.cos(i.rotation),0,0,0,1),p=xt.set(1,0,i.x+d,0,1,i.y+c,0,0,1),g=Ct.multiplyMatrices(p,w).multiply(f).multiply(v),m=St.set(h,l,1).applyMatrix3(g);t.position.x=m.x,t.position.y=m.y,t.rotation.z=i.rotation,t.scale.x=u*i.scaleX,t.scale.y=a*i.scaleY})(this.object,this.micro,0,0,0,0,this.composer.lastPadding),this[Z]=0,this.micro[Z]=0)}}const Nt=new r(0);var Xt,Yt,qt;(t=>{t.ORIENTATION_CHANGED="orientationChanged"})(Xt||(Xt={}));class Wt extends wt{constructor(){super(...arguments),this.behavior=Et.VISIBLE,this[Vt]=new E,this[Rt]=new E,this[Lt]=new E,this[Kt]=new E,this.scene=new l,this.camera=new a,this.solver=new D,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=st.PORTRAIT,this.needsRecalculation=0}get orientation(){return this.orientationPrivate}destroy(){this.solver=void 0;for(const t of this.constraints.keys())t.destroy();for(const t of this.elements.keys())t.destroy()}[(Vt=B,Rt=H,Lt=V,Kt=R,L)](t,i){if(this.elements.has(t))throw Error("Element already added");this.elements.set(t,{object:i,variables:new Map,constraints:new Set}),i.position.z=500,this.scene.add(i)}[K](t){const i=this.elements.get(t);if(void 0===i)throw Error("Element not found");if(i.variables.size>0)throw Error("Variables should be removed before removing element");if(i.constraints.size>0)throw Error("Constraints should be removed before removing element");this.elements.delete(t),this.scene.remove(i.object)}[_](t,i){if(this.constraints.has(t))throw Error("Constraint already added");for(const s of i){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(i.constraints.has(t))throw Error("Something went wrong");i.constraints.add(t)}this.constraints.set(t,{elements:i,variables:new Map,constraints:new Set})}[N](t){const i=this.constraints.get(t);if(void 0===i)throw Error("Constraint not found");if(i.variables.size>0)throw Error("Variables should be removed before removing constraint");if(i.constraints.size>0)throw Error("Constraints should be removed before removing constraint");for(const s of i.elements){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(!i.constraints.has(t))throw Error("Something went wrong");i.constraints.delete(t)}this.constraints.delete(t)}[X](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before adding constraint you need to add it's owner");if(n.constraints.has(i))throw Error("Constraint already exists");n.constraints.add(i),null===(s=this.solver)||void 0===s||s.addConstraint(i),this.needsRecalculation=1}[Y](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before removing constraint you need to add it's owner");if(!n.constraints.has(i))throw Error("Constraint not found");n.constraints.delete(i),null===(s=this.solver)||void 0===s||s.removeConstraint(i),this.needsRecalculation=1}[q](t,i,s){var n;const o=t instanceof _t?this.elements.get(t):this.constraints.get(t);if(void 0===o)throw Error("Before adding variable you need to add it's owner");if(o.variables.has(i))throw Error("Variable already exists");o.variables.set(i,{strength:s,suggestedValue:i.value()}),null===(n=this.solver)||void 0===n||n.addEditVariable(i,s),this.needsRecalculation=1}[W](t,i){var s;const n=t instanceof _t?this.elements.get(t):this.constraints.get(t);if(void 0===n)throw Error("Before removing variable you need to add it's owner");if(!n.variables.has(i))throw Error("Variable does not exist");n.variables.delete(i),null===(s=this.solver)||void 0===s||s.removeEditVariable(i),this.needsRecalculation=1}[G](t,i,s){var n;const o=t instanceof _t?this.elements.get(t):this.constraints.get(t);if(void 0===o)throw Error("Before suggesting variable you need to add it's owner");const e=o.variables.get(i);if(!e)throw Error("Variable does not exist");e.suggestedValue!==s&&(e.suggestedValue=s,null===(n=this.solver)||void 0===n||n.suggestValue(i,s),this.needsRecalculation=1)}render(t){var i;if(this.behavior===Et.HIDDEN)return;const s=t.getRenderTarget(),n=t.getClearColor(Nt),o=t.getClearAlpha();if(this.needsRecalculation){this.needsRecalculation=0,null===(i=this.solver)||void 0===i||i.updateVariables();for(const t of this.elements.keys())t[Z]=1}for(const i of this.elements.keys())i[tt](t);t.setRenderTarget(s),t.setClearColor(n),t.setClearAlpha(o),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==Et.INTERACTIVE)return;const s=[...this.elements.keys()].filter((t=>t.behavior===Et.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const n of s)if(n[it](t,i))break}resizeInternal(t,i){this.applyCameraSize(t,i),this.rebuildLayerConstraints(t,i),this.updateOrientation(t,i),this.needsRecalculation=1}applyCameraSize(t,i){this.camera.near=-1e3,this.camera.far=0,this.camera.bottom=0,this.camera.left=0,this.camera.right=t,this.camera.top=i,this.camera.updateProjectionMatrix()}rebuildLayerConstraints(t,i){var s,n,o,e,r,h,l,u;this.constraintX&&(null===(s=this.solver)||void 0===s||s.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(null===(n=this.solver)||void 0===n||n.removeConstraint(this.constraintY),this.constraintY=void 0),this.constraintW&&(null===(o=this.solver)||void 0===o||o.removeConstraint(this.constraintW),this.constraintW=void 0),this.constraintH&&(null===(e=this.solver)||void 0===e||e.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new $(new O(this[B]),M.Eq,0,P.required),this.constraintY=new $(new O(this[H]),M.Eq,0,P.required),this.constraintW=new $(new O(this[V]),M.Eq,t,P.required),this.constraintH=new $(new O(this[R]),M.Eq,i,P.required),null===(r=this.solver)||void 0===r||r.addConstraint(this.constraintX),null===(h=this.solver)||void 0===h||h.addConstraint(this.constraintY),null===(l=this.solver)||void 0===l||l.addConstraint(this.constraintW),null===(u=this.solver)||void 0===u||u.addConstraint(this.constraintH)}updateOrientation(t,i){const s=this.orientationPrivate;if(this.orientationPrivate=t>i?st.LANDSCAPE:st.PORTRAIT,s!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t[J](this.orientationPrivate);for(const t of this.constraints.keys())t[Q](this.orientationPrivate);this.solver=new D;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,s]of i.variables.entries())this.solver.addEditVariable(t,s.strength),this.solver.suggestValue(t,s.suggestedValue);this.constraintX&&this.solver.addConstraint(this.constraintX),this.constraintY&&this.solver.addConstraint(this.constraintY),this.constraintW&&this.solver.addConstraint(this.constraintW),this.constraintH&&this.solver.addConstraint(this.constraintH);for(const t of this.constraints.values())for(const i of t.constraints.values())this.solver.addConstraint(i);this.emit(Xt.ORIENTATION_CHANGED,this,this.orientation)}}}function Gt(t,i){if((t instanceof Wt?t:t.layer)!==i.layer)throw Error(`Elements must be on the same layer - element "${i.constructor.name}" cannot interact with elements from a different layer`)}function Qt(t,i,s){if(t<=0||i<=0)throw Error(null!=s?s:`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)}class Jt extends ht{constructor(t,i,s){var n,o,e;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(o=null==s?void 0:s.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==s?void 0:s.distance)&&void 0!==e?e:0,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[B]).plus(new O(this.elementOne[V]).multiply(this.parameters.anchorOne)),i=new O(this.elementTwo[B]).plus(new O(this.elementTwo[V]).multiply(this.parameters.anchorTwo));this.constraint=new $(i.minus(t),vt(this.parameters.rule),this.parameters.distance,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class Zt extends ht{constructor(t,i,s){var n;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[V]).multiply(this.parameters.proportion),i=new O(this.elementTwo[V]);this.constraint=new $(t.minus(i),vt(this.parameters.rule),0,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ti extends ht{constructor(t,i,s){var n,o,e;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(o=null==s?void 0:s.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==s?void 0:s.distance)&&void 0!==e?e:0,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[H]).plus(new O(this.elementOne[R]).multiply(this.parameters.anchorOne)),i=new O(this.elementTwo[H]).plus(new O(this.elementTwo[R]).multiply(this.parameters.anchorTwo));this.constraint=new $(i.minus(t),vt(this.parameters.rule),this.parameters.distance,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ii extends ht{constructor(t,i,s){var n;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[R]).multiply(this.parameters.proportion),i=new O(this.elementTwo[R]);this.constraint=new $(t.minus(i),vt(this.parameters.rule),0,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class si extends ht{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.options={width:null!==(s=null==i?void 0:i.width)&&void 0!==s?s:t.width,power:ut(null==i?void 0:i.power),rule:ct(null==i?void 0:i.rule),orientation:rt(null==i?void 0:i.orientation)},this.options.orientation!==st.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.options.orientation!==st.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[J](t){this.options.orientation!==st.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new $(new O(this.element[V]),vt(this.options.rule),this.options.width,at(this.options.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ni{static size(t,i){var s,n,o,e,r,h,l,u;return{x:new si(t,{width:null===(s=i.size)||void 0===s?void 0:s.x,power:null===(n=i.power)||void 0===n?void 0:n.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:null===(e=i.orientation)||void 0===e?void 0:e.x}),y:new ft(t,{height:null===(r=i.size)||void 0===r?void 0:r.y,power:null===(h=i.power)||void 0===h?void 0:h.y,rule:null===(l=i.rule)||void 0===l?void 0:l.y,orientation:null===(u=i.orientation)||void 0===u?void 0:u.y})}}static distance(t,i,s){var n,o,e,r,h,l,u,a,d,c,v,f;return{x:new Jt(t,i,{anchorOne:null===(n=s.anchorOne)||void 0===n?void 0:n.x,anchorTwo:null===(o=s.anchorTwo)||void 0===o?void 0:o.x,distance:null===(e=s.distance)||void 0===e?void 0:e.x,power:null===(r=s.power)||void 0===r?void 0:r.x,rule:null===(h=s.rule)||void 0===h?void 0:h.x,orientation:null===(l=s.orientation)||void 0===l?void 0:l.x}),y:new ti(t,i,{anchorOne:null===(u=s.anchorOne)||void 0===u?void 0:u.y,anchorTwo:null===(a=s.anchorTwo)||void 0===a?void 0:a.y,distance:null===(d=s.distance)||void 0===d?void 0:d.y,power:null===(c=s.power)||void 0===c?void 0:c.y,rule:null===(v=s.rule)||void 0===v?void 0:v.y,orientation:null===(f=s.orientation)||void 0===f?void 0:f.y})}}static proportion(t,i,s){var n,o,e,r,h,l,u,a;return{x:new Zt(t,i,{proportion:null===(n=s.proportion)||void 0===n?void 0:n.x,power:null===(o=s.power)||void 0===o?void 0:o.x,rule:null===(e=s.rule)||void 0===e?void 0:e.x,orientation:null===(r=s.orientation)||void 0===r?void 0:r.x}),y:new ii(t,i,{proportion:null===(h=s.proportion)||void 0===h?void 0:h.y,power:null===(l=s.power)||void 0===l?void 0:l.y,rule:null===(u=s.rule)||void 0===u?void 0:u.y,orientation:null===(a=s.orientation)||void 0===a?void 0:a.y})}}}class oi extends ht{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={aspect:null!==(s=null==i?void 0:i.aspect)&&void 0!==s?s:this.element.width/this.element.height,power:ut(null==i?void 0:i.power),rule:ct(null==i?void 0:i.rule),orientation:rt(null==i?void 0:i.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.element[V]).plus(new O(this.element[R]).multiply(-this.parameters.aspect));this.constraint=new $(t,vt(this.parameters.rule),0,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ei extends ht{constructor(t,i,s){var n,o,e;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(o=null==s?void 0:s.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==s?void 0:s.verticalAnchor)&&void 0!==e?e:.5,orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new $(new O(this.elementOne[B]).plus(new O(this.elementOne[V]).multiply(this.parameters.horizontalAnchor)),M.Eq,new O(this.elementTwo[B]).plus(new O(this.elementTwo[V]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new $(new O(this.elementOne[H]).plus(new O(this.elementOne[R]).multiply(this.parameters.verticalAnchor)),M.Eq,new O(this.elementTwo[H]).plus(new O(this.elementTwo[R]).multiply(this.parameters.verticalAnchor))),this.constraintW=new $(new O(this.elementOne[V]),M.Le,new O(this.elementTwo[V])),this.constraintH=new $(new O(this.elementOne[R]),M.Le,new O(this.elementTwo[R])),this.layer[X](this,this.constraintX),this.layer[X](this,this.constraintY),this.layer[X](this,this.constraintW),this.layer[X](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new $(new O(this.elementOne[R]),M.Eq,new O(this.elementTwo[R]),P.strong),this.layer[X](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[Y](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[Y](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[Y](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[Y](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[Y](this,this.constraintStrict),this.constraintStrict=void 0)}}function ri(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function hi(t){return null!==t&&"object"==typeof t&&("x"in t&&lt(t.x)||"y"in t&&lt(t.y))}function li(t){return null!==t&&"object"==typeof t&&("x"in t&&dt(t.x)||"y"in t&&dt(t.y))}function ui(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof _t||t.elementOne instanceof Wt)&&t.elementTwo instanceof _t}function ai(t){return ui(t)&&"distance"in t&&ri(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&ri(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&ri(t.anchorTwo))&&(!("power"in t)||hi(t.power))&&(!("rule"in t)||li(t.rule))&&(!("orientation"in t)||et(t.orientation))}function di(t){return ui(t)&&"proportion"in t&&ri(t.proportion)&&(!("power"in t)||hi(t.power))&&(!("rule"in t)||li(t.rule))&&(!("orientation"in t)||et(t.orientation))}function ci(t){return ui(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&ri(t.anchor))}function vi(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof _t&&(!("power"in t)||lt(t.power))&&(!("rule"in t)||dt(t.rule))}function fi(t){return vi(t)&&"height"in t&&"number"==typeof t.height}function wi(t){return vi(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function pi(t){return vi(t)&&"keepSize"in t&&"boolean"==typeof t.keepSize}class gi{static fromDescription(t){const i=t instanceof Map?t.entries():Object.entries(t),s=new Map;for(const[t,o]of i){if(s.has(t))throw Error(`Duplicate constraint key "${t}" - each constraint must have a unique identifier`);if(vi(n=o)&&"width"in n&&"number"==typeof n.width)gi.buildWidthConstraint(t,o,s);else if(fi(o))gi.buildHeightConstraint(t,o,s);else if(wi(o))gi.buildKeepAspectConstraint(t,o,s);else if(pi(o))gi.buildKeepSizeConstraint(t,o,s);else if(ai(o))gi.buildDistanceConstraint(t,o,s);else if(di(o))gi.buildProportionalConstraint(t,o,s);else{if(!ci(o))throw Error(`Invalid constraint type for "${t}". Expected one of: Width, Height, KeepAspect, KeepSize, Distance, Proportional, or Cover constraint`);gi.buildCoverConstraint(t,o,s)}}var n;return Object.fromEntries(s)}static buildWidthConstraint(t,i,s){s.set(t,new si(i.element,{width:i.width,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildHeightConstraint(t,i,s){s.set(t,new ft(i.element,{height:i.height,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepAspectConstraint(t,i,s){s.set(t,new oi(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepSizeConstraint(t,i,s){const n=t.replace(/(KeepSize|Keep)$/,"")+"KeepWidth",o=t.replace(/(KeepSize|Keep)$/,"")+"KeepHeight";s.set(n,new si(i.element,{power:i.power,rule:i.rule,orientation:i.orientation})),s.set(o,new ft(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildDistanceConstraint(t,i,s){var n,o,e,r,h,l,u,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";s.set(h,new Jt(i.elementOne,i.elementTwo,{distance:i.distance.x,anchorOne:null===(n=i.anchorOne)||void 0===n?void 0:n.x,anchorTwo:null===(o=i.anchorTwo)||void 0===o?void 0:o.x,power:null===(e=i.power)||void 0===e?void 0:e.x,rule:null===(r=i.rule)||void 0===r?void 0:r.x,orientation:i.orientation}))}if("number"==typeof i.distance.y){const n=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";s.set(n,new ti(i.elementOne,i.elementTwo,{distance:i.distance.y,anchorOne:null===(h=i.anchorOne)||void 0===h?void 0:h.y,anchorTwo:null===(l=i.anchorTwo)||void 0===l?void 0:l.y,power:null===(u=i.power)||void 0===u?void 0:u.y,rule:null===(a=i.rule)||void 0===a?void 0:a.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,s){var n,o,e,r;if("number"==typeof i.proportion.x){const e=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";s.set(e,new Zt(i.elementOne,i.elementTwo,{proportion:i.proportion.x,power:null===(n=i.power)||void 0===n?void 0:n.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:i.orientation}))}if("number"==typeof i.proportion.y){const n=t.replace(/(VerticalProportional|VerticalProportion|Proportional|Proportion)$/,"")+"VerticalProportion";s.set(n,new ii(i.elementOne,i.elementTwo,{proportion:i.proportion.y,power:null===(e=i.power)||void 0===e?void 0:e.y,rule:null===(r=i.rule)||void 0===r?void 0:r.y,orientation:i.orientation}))}}static buildCoverConstraint(t,i,s){var n,o;s.set(t,new ei(i.elementOne,i.elementTwo,{isStrict:i.isStrict,horizontalAnchor:null===(n=i.anchor)||void 0===n?void 0:n.x,verticalAnchor:null===(o=i.anchor)||void 0===o?void 0:o.y}))}}(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(Yt||(Yt={}));class mi{static build(t,i,s,n={}){var o;const e=null!==(o=n.direction)&&void 0!==o?o:Yt.FROM_LEFT_TOP,r=[],h=[];r.push(new Jt(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:n.power,orientation:n.orientation}),new Jt(t,s,{anchorOne:1,anchorTwo:1,distance:0,power:n.power,orientation:n.orientation}));const l=e===Yt.FROM_LEFT_TOP?1:0,u=e===Yt.FROM_LEFT_TOP?0:1;return h.push(new ti(t,i,{anchorOne:l,anchorTwo:l,distance:0,power:n.power,orientation:n.orientation}),new ti(t,s,{anchorOne:u,anchorTwo:u,distance:0,power:n.power,orientation:n.orientation})),{horizontalDistances:r,verticalDistances:h}}}class yi{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:Jt,proportionConstraint:Zt,centerDistanceConstraint:ti})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:ti,proportionConstraint:ii,centerDistanceConstraint:Jt})}static buildStack(t,i,s){const n=[],o=[],e=[];for(let r=0;r<t.length-1;r++){const h=t[r],l=t[r+1];n.push(new s.distanceConstraint(h,l,{anchorOne:1,anchorTwo:0,distance:i.distance,power:i.power,orientation:i.orientation})),0!=i.keepProportions&&o.push(new s.proportionConstraint(h,l,{power:i.power,orientation:i.orientation})),0!=i.keepAlignment&&e.push(new s.centerDistanceConstraint(h,l,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:n,proportionConstraints:o,alignmentConstraints:e}}}class bi extends _t{constructor(t,i=1e3,s=1e3){super(t,new p,0,0,i,s),this.flushTransform()}[tt](){this.flushTransform()}}class xi extends _t{constructor(t,i){var s,n;const o=null===(s=i.image)||void 0===s?void 0:s.width,e=null===(n=i.image)||void 0===n?void 0:n.height;Qt(o,e,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${o}) or height (${e}). Image dimensions must be non-zero positive numbers.`);const r=new Mt(i);super(t,new u(Pt,r),0,0,o,e),this.material=r,this.textureInternal=i,this.flushTransform()}get texture(){return this.textureInternal}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),super.destroy()}[tt](t){this.object.material=this.composer.compose(t,this.textureInternal.image.width,this.textureInternal.image.height,this.material),this.flushTransform()}}class Ci extends e{constructor(t,i){super({uniforms:g.merge([{background:{value:i},foreground:{value:t},progress:{value:1},backgroundColor:{value:new r(1,1,1)},foregroundColor:{value:new r(1,1,1)},color:{value:new r(1,1,1)},backgroundOpacity:{value:1},foregroundOpacity:{value:1},opacity:{value:1},angle:{value:0},direction:{value:1}}]),vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D background;\n uniform sampler2D foreground;\n uniform float progress;\n uniform vec3 backgroundColor;\n uniform vec3 foregroundColor;\n uniform vec3 color;\n uniform float backgroundOpacity;\n uniform float foregroundOpacity;\n uniform float opacity;\n uniform float angle;\n uniform float direction;\n varying vec2 vUv;\n\n void main() {\n vec4 backgroundTexture = texture2D(background, vUv);\n vec4 foregroundTexture = texture2D(foreground, vUv);\n\n // Apply common color and opacity\n vec3 finalBackgroundColor = backgroundTexture.rgb * backgroundColor * color;\n vec3 finalForegroundColor = foregroundTexture.rgb * foregroundColor * color;\n float finalBackgroundOpacity = backgroundTexture.a * backgroundOpacity * opacity;\n float finalForegroundOpacity = foregroundTexture.a * foregroundOpacity * opacity;\n\n vec4 backgroundColor = vec4(finalBackgroundColor, finalBackgroundOpacity);\n vec4 foregroundColor = vec4(finalForegroundColor, finalForegroundOpacity);\n\n // Calculate progress threshold with angle and direction\n float adjustedX = mix(vUv.x, 1.0 - vUv.x, step(0.0, -direction));\n float tanAngle = tan(angle);\n float threshold = adjustedX - (vUv.y - 0.5) * tanAngle * sign(direction);\n float progressMask = smoothstep(threshold - 0.01, threshold + 0.01, progress);\n\n gl_FragColor = mix(backgroundColor, foregroundColor, progressMask);\n #include <colorspace_fragment>\n }\n ",transparent:1,lights:0,fog:0})}getProgress(){return this.uniforms.progress.value}getBackgroundTexture(){return this.uniforms.background.value}getForegroundTexture(){return this.uniforms.foreground.value}getBackgroundColor(){return this.uniforms.color.value.getHex()}getForegroundColor(){return this.uniforms.color.value.getHex()}getColor(){return this.uniforms.color.value.getHex()}getBackgroundOpacity(){return this.uniforms.backgroundOpacity.value}getForegroundOpacity(){return this.uniforms.foregroundOpacity.value}getOpacity(){return this.uniforms.opacity.value}getAngle(){return this.uniforms.angle.value}getIsForwardDirection(){return 1===this.uniforms.direction.value}setProgress(t){this.uniforms.progress.value=t,this.uniformsNeedUpdate=1}setBackgroundTexture(t){this.uniforms.background.value=t,this.uniformsNeedUpdate=1}setForegroundTexture(t){this.uniforms.foreground.value=t,this.uniformsNeedUpdate=1}setBackgroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setForegroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setBackgroundOpacity(t){this.uniforms.backgroundOpacity.value=t,this.uniformsNeedUpdate=1}setForegroundOpacity(t){this.uniforms.foregroundOpacity.value=t,this.uniformsNeedUpdate=1}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=1}setAngle(t){this.uniforms.angle.value=t,this.uniformsNeedUpdate=1}setIsForwardDirection(t){this.uniforms.direction.value=t?1:-1,this.uniformsNeedUpdate=1}}class Si extends _t{constructor(t,i,s,n={}){var e,r,h,l;const a=null===(e=i.image)||void 0===e?void 0:e.width,d=null===(r=i.image)||void 0===r?void 0:r.height;Qt(a,d,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${a}) or height (${d}). Image dimensions must be non-zero positive numbers.`);const c=null===(h=null==s?void 0:s.image)||void 0===h?void 0:h.width,v=null===(l=null==s?void 0:s.image)||void 0===l?void 0:l.height;s&&Qt(c,v,`Invalid image dimensions - texture "${s.name||"unnamed"}" has invalid width (${c}) or height (${v}). Image dimensions must be non-zero positive numbers.`);const f=new Ci(i,s),w=new u(Pt,f);n.progress&&f.setProgress(n.progress),n.isForegroundDirection&&f.setIsForwardDirection(n.isForegroundDirection),n.angle&&f.setAngle(o.degToRad(n.angle)),n.color&&f.setColor(n.color),n.opacity&&f.setOpacity(n.opacity),n.backgroundColor&&f.setBackgroundColor(n.backgroundColor),n.foregroundColor&&f.setForegroundColor(n.foregroundColor),n.backgroundOpacity&&f.setBackgroundOpacity(n.backgroundOpacity),n.foregroundOpacity&&f.setForegroundOpacity(n.foregroundOpacity);const p=null!=c?c:a,g=null!=d?d:v;super(t,w,0,0,p,g),this.material=f,this.imageWidth=p,this.imageHeight=g,this.flushTransform()}get progress(){return this.material.getProgress()}get backgroundTexture(){return this.material.getBackgroundTexture()}get foregroundTexture(){return this.material.getForegroundTexture()}get backgroundColor(){return this.material.getBackgroundColor()}get foregroundColor(){return this.material.getForegroundColor()}get color(){return this.material.getColor()}get backgroundOpacity(){return this.material.getBackgroundOpacity()}get foregroundOpacity(){return this.material.getForegroundOpacity()}get opacity(){return this.material.getOpacity()}get angle(){return o.radToDeg(this.material.getAngle())}get isForwardDirection(){return this.material.getIsForwardDirection()}set progress(t){this.material.setProgress(t),this.composer.requestUpdate()}set backgroundColor(t){this.material.setBackgroundColor(t),this.composer.requestUpdate()}set foregroundColor(t){this.material.setForegroundColor(t),this.composer.requestUpdate()}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set backgroundOpacity(t){this.material.setBackgroundOpacity(t),this.composer.requestUpdate()}set foregroundOpacity(t){this.material.setForegroundOpacity(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}set angle(t){this.material.setAngle(o.degToRad(t)),this.composer.requestUpdate()}set isForwardDirection(t){this.material.setIsForwardDirection(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),super.destroy()}[tt](t){this.object.material=this.composer.compose(t,this.imageWidth,this.imageHeight,this.material),this.flushTransform()}}function Ei(t,i){var s,n,o,e,r,h,l,u,a,d,c,v,f,w,p,g,m,y,b,x,C,S,E,k,O,T,M,P;const I=Math.max(null!==(n=null!==(s=null==t?void 0:t.fontSize)&&void 0!==s?s:null==i?void 0:i.fontSize)&&void 0!==n?n:16,1),$=null!==(e=null!==(o=null==t?void 0:t.lineHeight)&&void 0!==o?o:null==i?void 0:i.lineHeight)&&void 0!==e?e:1.2*I,A=Math.max(null!==(h=null!==(r=null==t?void 0:t.shadowBlur)&&void 0!==r?r:null==i?void 0:i.shadowBlur)&&void 0!==h?h:0,0),D=Math.max(null!==(u=null!==(l=null==t?void 0:t.strokeWidth)&&void 0!==l?l:null==i?void 0:i.strokeWidth)&&void 0!==u?u:0,0);return{color:null!==(d=null!==(a=null==t?void 0:t.color)&&void 0!==a?a:null==i?void 0:i.color)&&void 0!==d?d:"#000000",fontFamily:null!==(v=null!==(c=null==t?void 0:t.fontFamily)&&void 0!==c?c:null==i?void 0:i.fontFamily)&&void 0!==v?v:"Arial",fontSize:I,fontStyle:null!==(w=null!==(f=null==t?void 0:t.fontStyle)&&void 0!==f?f:null==i?void 0:i.fontStyle)&&void 0!==w?w:"normal",fontWeight:null!==(g=null!==(p=null==t?void 0:t.fontWeight)&&void 0!==p?p:null==i?void 0:i.fontWeight)&&void 0!==g?g:"normal",lineHeight:$,enableShadow:null!==(y=null!==(m=null==t?void 0:t.enableShadow)&&void 0!==m?m:null==i?void 0:i.enableShadow)&&void 0!==y?y:0,shadowOffsetX:null!==(x=null!==(b=null==t?void 0:t.shadowOffsetX)&&void 0!==b?b:null==i?void 0:i.shadowOffsetX)&&void 0!==x?x:0,shadowOffsetY:null!==(S=null!==(C=null==t?void 0:t.shadowOffsetY)&&void 0!==C?C:null==i?void 0:i.shadowOffsetY)&&void 0!==S?S:0,shadowBlur:A,shadowColor:null!==(k=null!==(E=null==t?void 0:t.shadowColor)&&void 0!==E?E:null==i?void 0:i.shadowColor)&&void 0!==k?k:"transparent",enableStroke:null!==(T=null!==(O=null==t?void 0:t.enableStroke)&&void 0!==O?O:null==i?void 0:i.enableStroke)&&void 0!==T?T:0,strokeColor:null!==(P=null!==(M=null==t?void 0:t.strokeColor)&&void 0!==M?M:null==i?void 0:i.strokeColor)&&void 0!==P?P:"transparent",strokeWidth:D}}function ki(t){return t.match(/\S+|\s|\n/g)||[]}function Oi(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 n=t.measureText(i),o=n.width,e=Math.ceil(n.actualBoundingBoxAscent+n.actualBoundingBoxDescent);return{width:Math.ceil(o),height:e,baseline:n.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function Ti(t,i,s,n,o){o.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize}px ${n.fontFamily}`,n.enableShadow&&(o.shadowOffsetX=n.shadowOffsetX,o.shadowOffsetY=n.shadowOffsetY,o.shadowBlur=n.shadowBlur,o.shadowColor=n.shadowColor),n.enableStroke&&(o.strokeStyle=n.strokeColor,o.lineWidth=n.strokeWidth,o.strokeText(s,t,i)),o.fillStyle=n.color,o.fillText(s,t,i)}class Mi extends _t{constructor(t,i,s={}){var n;const o=document.createElement("canvas"),e=o.getContext("2d");if(!e)throw Error("Failed to create canvas context");const r=[],h=Array.isArray(i)?i:[i];for(const t of h){const i="string"==typeof t,n=i?t:t.text,o=Ei(i?void 0:t.style,s.defaultStyle);for(const t of ki(n)){const i=Oi(e,t,o);r.push({text:t,style:o,metrics:i})}}const l=((t,i)=>{const s=[];let n=[],o=0,e=0,r=0,h=0;for(const l of i)"\n"!==l.text?o+l.metrics.width<=t||0===n.length?(n.push(l),o+=l.metrics.width,e=Math.max(e,l.metrics.height),r=Math.max(r,l.metrics.baseline),h=Math.max(h,l.metrics.lineHeight)):(s.push({chunks:n,width:o,height:e,baseline:r,lineHeight:h}),n=[l],o=l.metrics.width,e=l.metrics.height,r=l.metrics.baseline,h=l.metrics.lineHeight):(n.length>0&&s.push({chunks:n,width:o,height:e,baseline:r,lineHeight:h}),n=[],o=0,e=0,r=0,h=0);return n.length>0&&s.push({chunks:n,width:o,height:e,baseline:r,lineHeight:h}),s})(null!==(n=s.maxWidth)&&void 0!==n?n:1024,r),a=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map((t=>t.width)));let s=0;for(let i=0;i<t.length;i++){const n=t[i];s+=0===i?n.height:n.lineHeight,i===t.length-1&&(s+=n.baseline)}return{width:i,height:s}})(l),d=(t=>{var i,s,n,o;return"number"==typeof t?{left:t,right:t,top:t,bottom:t}:{left:Math.max(null!==(i=null==t?void 0:t.left)&&void 0!==i?i:0,0),right:Math.max(null!==(s=null==t?void 0:t.right)&&void 0!==s?s:0,0),top:Math.max(null!==(n=null==t?void 0:t.top)&&void 0!==n?n:0,0),bottom:Math.max(null!==(o=null==t?void 0:t.bottom)&&void 0!==o?o:0,0)}})(s.padding);o.width=a.width+d.left+d.right,o.height=a.height+d.top+d.bottom;const c=new m(o),v=new Mt(c);super(t,new u(Pt,v),0,0,a.width,a.height),this.lastSuggestedAspect=0,this.material=v,this.texture=c,this.canvas=o,this.context=e,this.textBlockSize=a,this.padding=d,((t,i,s,n)=>{let o=this.padding.top;for(let t=0;t<s.length;t++){const e=s[t];let r=i;o+=0===t?e.height:e.lineHeight;for(const t of e.chunks)Ti(r,o,t.text,t.style,n),r+=t.metrics.width}})(0,this.padding.left,l,this.context),this.texture.needsUpdate=1,this.flushTransform()}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),this.texture.dispose(),this.canvas.remove(),super.destroy()}flushTransform(){super.flushTransform();const t=this.width/this.height;this.lastSuggestedAspect!==t&&(this.lastSuggestedAspect=t,this.layer[G](this,this[R],this.width/((this.textBlockSize.width+this.padding.left+this.padding.right)/(this.textBlockSize.height+this.padding.top+this.padding.bottom))))}[tt](t){this.object.material=this.composer.compose(t,this.texture.image.width,this.texture.image.height,this.material),this.flushTransform()}}function Pi(t){return null!==t&&"object"==typeof t&&"background"in t&&t.background instanceof y&&"foreground"in t&&t.foreground instanceof y}function Ii(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}function $i(t){return null!==t&&"object"==typeof t&&"spans"in t&&Array.isArray(t.spans)&&t.spans.every((t=>"string"==typeof t||(t=>null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text)(t)))}function Ai(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class Di{static fromDescription(t,i){const s=i instanceof Map?i.entries():Object.entries(i),n=new Map;for(const[i,e]of s){if(n.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let s;if(e instanceof y)s=new xi(t,e);else if(null!==(o=e)&&"object"==typeof o&&"texture"in o&&o.texture instanceof y)s=new xi(t,e.texture);else if("string"==typeof e)s=new Mi(t,[e]);else if(Pi(e))s=new Si(t,e.background,e.foreground);else if(Ii(e))s=new Mi(t,[e.text],{defaultStyle:e.style});else if($i(e))s=new Mi(t,e.spans,{defaultStyle:e.defaultStyle});else{if(!Ai(e))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);s=new bi(t,e.width,e.height)}n.set(i,s)}var o;return Object.fromEntries(n)}}class zi extends ht{constructor(t,i,s){var n,o,e;super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Gt(t,i),this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(o=null==s?void 0:s.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==s?void 0:s.verticalAnchor)&&void 0!==e?e:.5,orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new $(new O(this.elementOne[B]).plus(new O(this.elementOne[V]).multiply(this.parameters.horizontalAnchor)),M.Eq,new O(this.elementTwo[B]).plus(new O(this.elementTwo[V]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new $(new O(this.elementOne[H]).plus(new O(this.elementOne[R]).multiply(this.parameters.verticalAnchor)),M.Eq,new O(this.elementTwo[H]).plus(new O(this.elementTwo[R]).multiply(this.parameters.verticalAnchor))),this.constraintW=new $(new O(this.elementOne[V]),M.Ge,new O(this.elementTwo[V])),this.constraintH=new $(new O(this.elementOne[R]),M.Ge,new O(this.elementTwo[R])),this.layer[X](this,this.constraintX),this.layer[X](this,this.constraintY),this.layer[X](this,this.constraintW),this.layer[X](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new $(new O(this.elementOne[R]),M.Eq,new O(this.elementTwo[R]),P.strong),this.layer[X](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[Y](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[Y](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[Y](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[Y](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[Y](this,this.constraintStrict),this.constraintStrict=void 0)}}(t=>{t.AUTO="AUTO",t.PROPERTY="PROPERTY",t.MANUAL="MANUAL"})(qt||(qt={}));const Fi=qt.PROPERTY;class Ui extends _t{constructor(t,i={}){var s,n,o,e,r,h,a,w,p,g;const m=null!==(s=i.resolutionFactor)&&void 0!==s?s:.5;if(m<.1||m>8)throw Error(`Invalid resolution factor: ${m}. Must be between 0.1 and 8.`);const y=null!==(n=i.width)&&void 0!==n?n:512,x=null!==(o=i.height)&&void 0!==o?o:512;Qt(y,x,`Invalid width or height: ${y}x${x}. Must be positive.`);const C=new d(y*m,x*m,{format:f,minFilter:v,magFilter:v,type:c,depthBuffer:null!==(e=i.useDepth)&&void 0!==e?e:1,stencilBuffer:0}),S=new Mt(C.texture);super(t,new u(Pt,S),0,0,y,x),this.needsRenderInternal=0,this.sceneInternal=null!==(r=i.scene)&&void 0!==r?r:new l,this.cameraInternal=null!==(h=i.camera)&&void 0!==h?h:new b(75,y/x,.1,100),this.resolutionFactorInternal=m,this.updateBehaviorInternal=null!==(a=i.updateBehavior)&&void 0!==a?a:Fi,null!==(w=i.renderedByDefault)&&void 0!==w&&w&&(this.needsRenderInternal=1),this.clearColorInternal=null!==(p=i.clearColor)&&void 0!==p?p:0,this.clearAlphaInternal=null!==(g=i.clearAlpha)&&void 0!==g?g:0,this.renderTarget=C,this.material=S,this.flushTransform()}get needsRender(){return this.needsRenderInternal}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}get scene(){return this.sceneInternal}get camera(){return this.cameraInternal}get clearColor(){return this.clearColorInternal}get clearAlpha(){return this.clearAlphaInternal}get resolutionFactor(){return this.resolutionFactorInternal}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}set scene(t){this.sceneInternal!==t&&(this.sceneInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set camera(t){this.cameraInternal!==t&&(this.cameraInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set clearColor(t){this.clearColorInternal!==t&&(this.clearColorInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set clearAlpha(t){this.clearAlphaInternal!==t&&(this.clearAlphaInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set resolutionFactor(t){this.resolutionFactorInternal!==t&&(this.resolutionFactorInternal=t,this.renderTarget.setSize(this.width*this.resolutionFactorInternal,this.height*this.resolutionFactorInternal),this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}destroy(){this.material.dispose(),this.renderTarget.dispose(),super.destroy()}requestRender(){this.needsRenderInternal=1,this.composer.requestUpdate()}[tt](t){(this.needsRenderInternal||this.updateBehaviorInternal===qt.AUTO)&&(this[Z]&&this.renderTarget.setSize(this.width*this.resolutionFactorInternal,this.height*this.resolutionFactorInternal),this.needsRenderInternal=0,t.setClearColor(this.clearColorInternal,this.clearAlpha),t.setRenderTarget(this.renderTarget),t.clear(1,1,0),t.render(this.sceneInternal,this.cameraInternal)),this.object.material=this.composer.compose(t,this.width*this.resolutionFactorInternal,this.height*this.resolutionFactorInternal,this.material),this.flushTransform()}}class ji extends Wt{constructor(){super(),this.targetScreenHeight=1920,this.onResize=()=>{const t=this.calculateScale();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.onClick=t=>{if(this.behavior!==Et.INTERACTIVE)return;const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,s=i?t.clientX-i.left:t.clientX,n=i?i.bottom-t.clientY:window.innerHeight-t.clientY,o=this.calculateScale();this.clickInternal(s*o,n*o)},window.addEventListener("resize",this.onResize),window.addEventListener("pointerdown",this.onClick),this.onResize()}get tergetScreenHeight(){return this.targetScreenHeight}set tergetScreenHeight(t){this.targetScreenHeight=t,this.resizeInternal(window.innerWidth,window.innerHeight)}destroy(){window.removeEventListener("resize",this.onResize),window.removeEventListener("pointerdown",this.onClick),super.destroy()}calculateScale(){var t;return(null!==(t=this.tergetScreenHeight)&&void 0!==t?t:window.innerHeight)/window.innerHeight}}class Bi extends Wt{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Hi{}export{oi as UIAspectConstraint,Et as UIBehavior,ni as UIConstraint2DBuilder,gi as UIConstraintBuilder,mi as UIConstraintContainerBuilder,Yt as UIConstraintContainerDirection,nt as UIConstraintPower,ot as UIConstraintRule,yi as UIConstraintStackBuilder,ei as UICoverConstraint,bi as UIDummy,Di as UIElementBuilder,Ht as UIElementEvent,zi as UIFitConstraint,ji as UIFullScreenLayer,At as UIFullScreenQuad,ft as UIHeightConstraint,Jt as UIHorizontalDistanceConstraint,Zt as UIHorizontalProportionConstraint,xi as UIImage,Xt as UILayerEvent,Bi as UIManualLayer,st as UIOrientation,Hi as UIPass,Si as UIProgress,Ui as UIScene,qt as UISceneUpdateBehavior,Mi as UIText,ti as UIVerticalDistanceConstraint,ii as UIVerticalProportionConstraint,si as UIWidthConstraint};
1
+ import{Vector2 as t,Box2 as i,Matrix3 as s,Vector3 as n,MathUtils as o,ShaderMaterial as e,Color as r,PlaneGeometry as h,Scene as l,Mesh as u,OrthographicCamera as a,WebGLRenderTarget as d,UnsignedByteType as c,LinearFilter as v,RGBAFormat as f,NoBlending as w,Object3D as p,UniformsUtils as g,CanvasTexture as m,Texture as y,PerspectiveCamera as b}from"three";function x(){return new C}var C=function(){function t(){this.index={},this.array=[]}return t.prototype.size=function(){return this.array.length},t.prototype.empty=function(){return 0===this.array.length},t.prototype.itemAt=function(t){return this.array[t]},t.prototype.contains=function(t){return void 0!==this.index[t.id()]},t.prototype.find=function(t){var i=this.index[t.id()];return void 0===i?void 0:this.array[i]},t.prototype.setDefault=function(t,i){var s=this.index[t.id()];if(void 0===s){var n=new S(t,i());return this.index[t.id()]=this.array.length,this.array.push(n),n}return this.array[s]},t.prototype.insert=function(t,i){var s=new S(t,i),n=this.index[t.id()];return void 0===n?(this.index[t.id()]=this.array.length,this.array.push(s)):this.array[n]=s,s},t.prototype.erase=function(t){var i=this.index[t.id()];if(void 0!==i){this.index[t.id()]=void 0;var s=this.array[i],n=this.array.pop();return s!==n&&(this.array[i]=n,this.index[n.first.id()]=i),s}},t.prototype.copy=function(){for(var i=new t,s=0;s<this.array.length;s++){var n=this.array[s].copy();i.array[s]=n,i.index[n.first.id()]=s}return i},t}(),S=function(){function t(t,i){this.first=t,this.second=i}return t.prototype.copy=function(){return new t(this.first,this.second)},t}(),E=function(){function t(t){void 0===t&&(t=""),this.t=0,this.i=null,this.o=k++,this.h=t}return t.prototype.id=function(){return this.o},t.prototype.name=function(){return this.h},t.prototype.setName=function(t){this.h=t},t.prototype.context=function(){return this.i},t.prototype.setContext=function(t){this.i=t},t.prototype.value=function(){return this.t},t.prototype.setValue=function(t){this.t=t},t.prototype.plus=function(t){return new O(this,t)},t.prototype.minus=function(t){return new O(this,"number"==typeof t?-t:[-1,t])},t.prototype.multiply=function(t){return new O([t,this])},t.prototype.divide=function(t){return new O([1/t,this])},t.prototype.toJSON=function(){return{name:this.h,value:this.t}},t.prototype.toString=function(){return this.i+"["+this.h+":"+this.t+"]"},t}(),k=0,O=function(){function t(){var t=T(arguments);this.l=t.terms,this.u=t.constant}return t.prototype.terms=function(){return this.l},t.prototype.constant=function(){return this.u},t.prototype.value=function(){for(var t=this.u,i=0,s=this.l.size();i<s;i++){var n=this.l.itemAt(i);t+=n.first.value()*n.second}return t},t.prototype.plus=function(i){return new t(this,i)},t.prototype.minus=function(i){return new t(this,"number"==typeof i?-i:[-1,i])},t.prototype.multiply=function(i){return new t([i,this])},t.prototype.divide=function(i){return new t([1/i,this])},t.prototype.isConstant=function(){return 0==this.l.size()},t.prototype.toString=function(){var t=this.l.array.map((t=>t.second+"*"+t.first)).join(" + ");return this.isConstant()||0===this.u||(t+=" + "),t+this.u},t}();function T(t){for(var i=0,s=()=>0,n=x(),o=0,e=t.length;o<e;++o){var r=t[o];if("number"==typeof r)i+=r;else if(r instanceof E)n.setDefault(r,s).second+=1;else if(r instanceof O){i+=r.constant();for(var h=0,l=(c=r.terms()).size();h<l;h++){var u=c.itemAt(h);n.setDefault(u.first,s).second+=u.second}}else{if(!(r instanceof Array))throw Error("invalid Expression argument: "+r);if(2!==r.length)throw Error("array must have length 2");var a=r[0],d=r[1];if("number"!=typeof a)throw Error("array item 0 must be a number");if(d instanceof E)n.setDefault(d,s).second+=a;else{if(!(d instanceof O))throw Error("array item 1 must be a variable or expression");var c;for(i+=d.constant()*a,h=0,l=(c=d.terms()).size();h<l;h++)u=c.itemAt(h),n.setDefault(u.first,s).second+=u.second*a}}}return{terms:n,constant:i}}var M,P=(()=>{function t(){}return t.create=(t,i,s,n)=>{void 0===n&&(n=1);var o=0;return o+=1e6*Math.max(0,Math.min(1e3,t*n)),(o+=1e3*Math.max(0,Math.min(1e3,i*n)))+Math.max(0,Math.min(1e3,s*n))},t.clip=i=>Math.max(0,Math.min(t.required,i)),t.required=t.create(1e3,1e3,1e3),t.strong=t.create(1,0,0),t.medium=t.create(0,1,0),t.weak=t.create(0,0,1),t})();(t=>{t[t.Le=0]="Le",t[t.Ge=1]="Ge",t[t.Eq=2]="Eq"})(M||(M={}));var I,$=function(){function t(t,i,s,n){void 0===n&&(n=P.required),this.o=A++,this.v=i,this.p=P.clip(n),this.m=void 0===s&&t instanceof O?t:t.minus(s)}return t.prototype.id=function(){return this.o},t.prototype.expression=function(){return this.m},t.prototype.op=function(){return this.v},t.prototype.strength=function(){return this.p},t.prototype.toString=function(){return this.m+" "+["<=",">=","="][this.v]+" 0 ("+this.p+")"},t}(),A=0,D=function(){function t(){this.C=x(),this.S=x(),this.k=x(),this.O=x(),this.T=[],this.M=new j,this.P=null,this.I=0}return t.prototype.createConstraint=function(t,i,s,n){void 0===n&&(n=P.required);var o=new $(t,i,s,n);return this.addConstraint(o),o},t.prototype.addConstraint=function(t){if(void 0!==this.C.find(t))throw Error("duplicate constraint");var i=this.$(t),s=i.row,n=i.tag,o=this.A(s,n);if(o.type()===I.Invalid&&s.allDummies()){if(!z(s.constant()))throw Error("unsatisfiable constraint");o=n.marker}if(o.type()===I.Invalid){if(!this.D(s))throw Error("unsatisfiable constraint")}else s.solveFor(o),this.F(o,s),this.S.insert(o,s);this.C.insert(t,n),this.U(this.M)},t.prototype.removeConstraint=function(t){var i=this.C.erase(t);if(void 0===i)throw Error("unknown constraint");this.j(t,i.second);var s=i.second.marker,n=this.S.erase(s);if(void 0===n){var o=this.B(s);if(o.type()===I.Invalid)throw Error("failed to find leaving row");(n=this.S.erase(o)).second.solveForEx(o,s),this.F(s,n.second)}this.U(this.M)},t.prototype.hasConstraint=function(t){return this.C.contains(t)},t.prototype.addEditVariable=function(t,i){if(void 0!==this.O.find(t))throw Error("duplicate edit variable");if((i=P.clip(i))===P.required)throw Error("bad required strength");var s=new O(t),n=new $(s,M.Eq,void 0,i);this.addConstraint(n);var o=this.C.find(n).second;this.O.insert(t,{tag:o,constraint:n,constant:0})},t.prototype.removeEditVariable=function(t){var i=this.O.erase(t);if(void 0===i)throw Error("unknown edit variable");this.removeConstraint(i.second.constraint)},t.prototype.hasEditVariable=function(t){return this.O.contains(t)},t.prototype.suggestValue=function(t,i){var s=this.O.find(t);if(void 0===s)throw Error("unknown edit variable");var n=this.S,o=s.second,e=i-o.constant;o.constant=i;var r=o.tag.marker,h=n.find(r);if(void 0!==h)return h.second.add(-e)<0&&this.T.push(r),void this.H();var l=o.tag.other;if(void 0!==(h=n.find(l)))return h.second.add(e)<0&&this.T.push(l),void this.H();for(var u=0,a=n.size();u<a;++u){var d=n.itemAt(u),c=d.second,v=c.coefficientFor(r);0!==v&&c.add(e*v)<0&&d.first.type()!==I.External&&this.T.push(d.first)}this.H()},t.prototype.updateVariables=function(){for(var t=this.k,i=this.S,s=0,n=t.size();s<n;++s){var o=t.itemAt(s),e=i.find(o.second);o.first.setValue(void 0!==e?e.second.constant():0)}},t.prototype.V=function(t){var i=this;return this.k.setDefault(t,(()=>i.R(I.External))).second},t.prototype.$=function(t){for(var i=t.expression(),s=new j(i.constant()),n=i.terms(),o=0,e=n.size();o<e;++o){var r=n.itemAt(o);if(!z(r.second)){var h=this.V(r.first),l=this.S.find(h);void 0!==l?s.insertRow(l.second,r.second):s.insertSymbol(h,r.second)}}var u=this.M,a=t.strength(),d={marker:U,other:U};switch(t.op()){case M.Le:case M.Ge:var c=t.op()===M.Le?1:-1,v=this.R(I.Slack);if(d.marker=v,s.insertSymbol(v,c),a<P.required){var f=this.R(I.Error);d.other=f,s.insertSymbol(f,-c),u.insertSymbol(f,a)}break;case M.Eq:if(a<P.required){var w=this.R(I.Error),p=this.R(I.Error);d.marker=w,d.other=p,s.insertSymbol(w,-1),s.insertSymbol(p,1),u.insertSymbol(w,a),u.insertSymbol(p,a)}else{var g=this.R(I.Dummy);d.marker=g,s.insertSymbol(g)}}return s.constant()<0&&s.reverseSign(),{row:s,tag:d}},t.prototype.A=(t,i)=>{for(var s=t.cells(),n=0,o=s.size();n<o;++n){var e=s.itemAt(n);if(e.first.type()===I.External)return e.first}var r=i.marker.type();return(r===I.Slack||r===I.Error)&&t.coefficientFor(i.marker)<0?i.marker:((r=i.other.type())===I.Slack||r===I.Error)&&t.coefficientFor(i.other)<0?i.other:U},t.prototype.D=function(t){var i=this.R(I.Slack);this.S.insert(i,t.copy()),this.P=t.copy(),this.U(this.P);var s=z(this.P.constant());this.P=null;var n=this.S.erase(i);if(void 0!==n){var o=n.second;if(o.isConstant())return s;var e=this.L(o);if(e.type()===I.Invalid)return 0;o.solveForEx(i,e),this.F(e,o),this.S.insert(e,o)}for(var r=this.S,h=0,l=r.size();h<l;++h)r.itemAt(h).second.removeSymbol(i);return this.M.removeSymbol(i),s},t.prototype.F=function(t,i){for(var s=this.S,n=0,o=s.size();n<o;++n){var e=s.itemAt(n);e.second.substitute(t,i),e.second.constant()<0&&e.first.type()!==I.External&&this.T.push(e.first)}this.M.substitute(t,i),this.P&&this.P.substitute(t,i)},t.prototype.U=function(t){for(;;){var i=this.K(t);if(i.type()===I.Invalid)return;var s=this._(i);if(s.type()===I.Invalid)throw Error("the objective is unbounded");var n=this.S.erase(s).second;n.solveForEx(s,i),this.F(i,n),this.S.insert(i,n)}},t.prototype.H=function(){for(var t=this.S,i=this.T;0!==i.length;){var s=i.pop(),n=t.find(s);if(void 0!==n&&n.second.constant()<0){var o=this.N(n.second);if(o.type()===I.Invalid)throw Error("dual optimize failed");var e=n.second;t.erase(s),e.solveForEx(s,o),this.F(o,e),t.insert(o,e)}}},t.prototype.K=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var o=i.itemAt(s),e=o.first;if(o.second<0&&e.type()!==I.Dummy)return e}return U},t.prototype.N=function(t){for(var i=Number.MAX_VALUE,s=U,n=t.cells(),o=0,e=n.size();o<e;++o){var r=n.itemAt(o),h=r.first,l=r.second;if(l>0&&h.type()!==I.Dummy){var u=this.M.coefficientFor(h)/l;u<i&&(i=u,s=h)}}return s},t.prototype._=function(t){for(var i=Number.MAX_VALUE,s=U,n=this.S,o=0,e=n.size();o<e;++o){var r=n.itemAt(o),h=r.first;if(h.type()!==I.External){var l=r.second,u=l.coefficientFor(t);if(u<0){var a=-l.constant()/u;a<i&&(i=a,s=h)}}}return s},t.prototype.B=function(t){for(var i=Number.MAX_VALUE,s=i,n=i,o=U,e=o,r=o,h=o,l=this.S,u=0,a=l.size();u<a;++u){var d=l.itemAt(u),c=d.second,v=c.coefficientFor(t);if(0!==v){var f=d.first;if(f.type()===I.External)h=f;else if(v<0)(w=-c.constant()/v)<s&&(s=w,e=f);else{var w;(w=c.constant()/v)<n&&(n=w,r=f)}}}return e!==o?e:r!==o?r:h},t.prototype.j=function(t,i){i.marker.type()===I.Error&&this.X(i.marker,t.strength()),i.other.type()===I.Error&&this.X(i.other,t.strength())},t.prototype.X=function(t,i){var s=this.S.find(t);void 0!==s?this.M.insertRow(s.second,-i):this.M.insertSymbol(t,-i)},t.prototype.L=t=>{for(var i=t.cells(),s=0,n=i.size();s<n;++s){var o=i.itemAt(s),e=o.first.type();if(e===I.Slack||e===I.Error)return o.first}return U},t.prototype.R=function(t){return new F(t,this.I++)},t}();function z(t){return t<0?-t<1e-8:t<1e-8}(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"})(I||(I={}));var F=function(){function t(t,i){this.o=i,this.Y=t}return t.prototype.id=function(){return this.o},t.prototype.type=function(){return this.Y},t}(),U=new F(I.Invalid,-1),j=function(){function t(t){void 0===t&&(t=0),this.q=x(),this.u=t}return t.prototype.cells=function(){return this.q},t.prototype.constant=function(){return this.u},t.prototype.isConstant=function(){return this.q.empty()},t.prototype.allDummies=function(){for(var t=this.q,i=0,s=t.size();i<s;++i)if(t.itemAt(i).first.type()!==I.Dummy)return 0;return 1},t.prototype.copy=function(){var i=new t(this.u);return i.q=this.q.copy(),i},t.prototype.add=function(t){return this.u+=t},t.prototype.insertSymbol=function(t,i){void 0===i&&(i=1),z(this.q.setDefault(t,(()=>0)).second+=i)&&this.q.erase(t)},t.prototype.insertRow=function(t,i){void 0===i&&(i=1),this.u+=t.u*i;for(var s=t.q,n=0,o=s.size();n<o;++n){var e=s.itemAt(n);this.insertSymbol(e.first,e.second*i)}},t.prototype.removeSymbol=function(t){this.q.erase(t)},t.prototype.reverseSign=function(){this.u=-this.u;for(var t=this.q,i=0,s=t.size();i<s;++i){var n=t.itemAt(i);n.second=-n.second}},t.prototype.solveFor=function(t){var i=this.q,s=-1/i.erase(t).second;this.u*=s;for(var n=0,o=i.size();n<o;++n)i.itemAt(n).second*=s},t.prototype.solveForEx=function(t,i){this.insertSymbol(t,-1),this.solveFor(i)},t.prototype.coefficientFor=function(t){var i=this.q.find(t);return void 0!==i?i.second:0},t.prototype.substitute=function(t,i){var s=this.q.erase(t);void 0!==s&&this.insertRow(i,s.second)},t}();const B=Symbol("xSymbol"),H=Symbol("ySymbol"),V=Symbol("widthSymbol"),R=Symbol("heightSymbol"),L=Symbol("addUIElementSymbol"),K=Symbol("removeUIElementSymbol"),_=Symbol("addConstraintSymbol"),N=Symbol("removeUIConstraintSymbol"),X=Symbol("addConstraintSymbol"),Y=Symbol("removeConstraintSymbol"),q=Symbol("addVariableSymbol"),W=Symbol("removeVariableSymbol"),G=Symbol("suggestVariableSymbol"),Q=Symbol("disableConstraintSymbol"),J=Symbol("enableConstraintSymbol"),Z=Symbol("needsRecalculation"),tt=Symbol("renderSymbol"),it=Symbol("clickSymbol");var st,nt,ot;function et(t){return null!==t&&Object.values(st).some((i=>i===t))}function rt(t){return null!=t?t:st.ALWAYS}(t=>{t[t.LANDSCAPE=0]="LANDSCAPE",t[t.PORTRAIT=1]="PORTRAIT",t[t.ALWAYS=2]="ALWAYS"})(st||(st={}));class ht{constructor(t,i){this.layer=t,this.name="",this.layer[_](this,i)}destroy(){this.layer[N](this)}}function lt(t){return null!==t&&Object.values(nt).some((i=>i===t))}function ut(t){return null!=t?t:nt.P0}function at(t){switch(t){case nt.P0:return P.create(1e3,1e3,1e3);case nt.P1:return P.create(100,0,0);case nt.P2:return P.create(10,0,0);case nt.P3:return P.create(0,100,0);case nt.P4:return P.create(0,10,0);case nt.P5:return P.create(0,0,100);case nt.P6:return P.create(0,0,10);case nt.P7:return P.create(0,0,1);default:return P.create(1e3,1e3,1e3)}}function dt(t){return null!==t&&Object.values(ot).some((i=>i===t))}function ct(t){return null!=t?t:ot.EQUAL}function vt(t){switch(t){case ot.EQUAL:return M.Eq;case ot.LESS:return M.Le;case ot.GREATER:return M.Ge;default:return M.Eq}}(t=>{t[t.P0=0]="P0",t[t.P1=1]="P1",t[t.P2=2]="P2",t[t.P3=3]="P3",t[t.P4=4]="P4",t[t.P5=5]="P5",t[t.P6=6]="P6",t[t.P7=7]="P7"})(nt||(nt={})),(t=>{t[t.EQUAL=2]="EQUAL",t[t.LESS=0]="LESS",t[t.GREATER=1]="GREATER"})(ot||(ot={}));class ft extends ht{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.options={height:null!==(s=null==i?void 0:i.height)&&void 0!==s?s:t.height,power:ut(null==i?void 0:i.power),rule:ct(null==i?void 0:i.rule),orientation:rt(null==i?void 0:i.orientation)},this.options.orientation!==st.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.options.orientation!==st.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[J](t){this.options.orientation!==st.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new $(new O(this.element[R]),vt(this.options.rule),this.options.height,at(this.options.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class wt{constructor(){this.listeners=new Map}on(t,i,s,n=100){return this.addListener(t,i,s,n,0),this}once(t,i,s,n=100){return this.addListener(t,i,s,n,1),this}off(t,i,s){const n=this.listeners.get(t);if(!n)return this;if(!i)return this.listeners.delete(t),this;const o=n.filter((t=>t.callback!==i||void 0!==s&&t.context!==s));return o.length?this.listeners.set(t,o):this.listeners.delete(t),this}emit(t,...i){const s=this.listeners.get(t);if(!(null==s?void 0:s.length))return 0;for(const n of[...s])n.callback.apply(n.context,i),n.once&&this.off(t,n.callback,n.context);return 1}addListener(t,i,s,n,o){let e=this.listeners.get(t);if(e||(e=[],this.listeners.set(t,e)),e.some((t=>t.callback===i&&t.context===s)))throw Error("Event listener already exists");const r={callback:i,context:s,priority:n,once:o};let h=0;for(;h<e.length&&e[h].priority<=n;)h++;e.splice(h,0,r)}}const pt=new t,gt=new i,mt=new s,yt=new s,bt=new s,xt=new s,Ct=new s,St=new n;var Et,kt;(t=>{t[t.HIDDEN=0]="HIDDEN",t[t.VISIBLE=1]="VISIBLE",t[t.INTERACTIVE=2]="INTERACTIVE"})(Et||(Et={}));const Ot=.5;class Tt{constructor(t){this.owner=t,this[kt]=0,this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=Ot,this.anchorYInternal=Ot,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0}get x(){return this.positionXInternal}get y(){return this.positionYInternal}get anchorX(){return this.anchorXInternal}get anchorY(){return this.anchorYInternal}get scaleX(){return this.scaleXInternal}get scaleY(){return this.scaleYInternal}get angle(){return o.radToDeg(this.rotationInternal)}get rotation(){return this.rotationInternal}set x(t){this.positionXInternal=t,this[Z]=1}set y(t){this.positionYInternal=t,this[Z]=1}set anchorX(t){this.anchorXInternal=t,this[Z]=1}set anchorY(t){this.anchorYInternal=t,this[Z]=1}set scaleX(t){this.scaleXInternal=t,this[Z]=1}set scaleY(t){this.scaleYInternal=t,this[Z]=1}set angle(t){this.rotationInternal=o.degToRad(t),this[Z]=1}set rotation(t){this.rotationInternal=t,this[Z]=1}setAnchorByGlobalPosition(t,i){const s=i-this.owner.y;this.anchorXInternal=(t-this.owner.x)/this.owner.width,this.anchorYInternal=s/this.owner.height,this[Z]=1}reset(){this.positionXInternal=0,this.positionYInternal=0,this.anchorXInternal=Ot,this.anchorYInternal=Ot,this.scaleXInternal=1,this.scaleYInternal=1,this.rotationInternal=0,this[Z]=1}}kt=Z;class Mt extends e{constructor(t){super({uniforms:{map:{value:t},opacity:{value:1},color:{value:new r(1,1,1)}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D map;\n uniform float opacity;\n uniform vec3 color;\n varying vec2 vUv;\n\n void main() {\n vec4 textureColor = texture2D(map, vUv);\n gl_FragColor = vec4(textureColor.rgb * color, textureColor.a * opacity);\n #include <colorspace_fragment>\n }\n ",transparent:1,lights:0,fog:0})}getTexture(){return this.uniforms.map.value}getColor(){return this.uniforms.color.value.getHex()}getOpacity(){return this.uniforms.opacity.value}setTexture(t){this.uniforms.map.value=t,this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=1}}const Pt=new h(1,1).translate(.5,.5,0),It=new l,$t=new u(Pt);It.add($t);class At{constructor(t=0,i=0){this.paddingHorizontalInternal=t,this.paddingVerticalInternal=i,this.camera=new a(-1,1,1,-1,0,1),this.updateCameraTransform()}get paddingHorizontal(){return this.paddingHorizontalInternal}get paddingVertical(){return this.paddingVerticalInternal}set paddingHorizontal(t){this.paddingHorizontalInternal!==t&&(this.paddingHorizontalInternal=t,this.updateCameraTransform())}set paddingVertical(t){this.paddingVerticalInternal!==t&&(this.paddingVerticalInternal=t,this.updateCameraTransform())}render(t,i){$t.material=i,t.render(It,this.camera)}updateCameraTransform(){this.camera.left=-this.paddingHorizontalInternal,this.camera.right=1+this.paddingHorizontalInternal,this.camera.bottom=-this.paddingVerticalInternal,this.camera.top=1+this.paddingVerticalInternal,this.camera.updateProjectionMatrix()}}class Dt{constructor(){this.passes=[],this.defaultMaterial=new Mt,this.screen=new At,this.needsUpdateInternal=0,this.lastPaddingHasChangedInternal=0,this.lastPaddingInternal=0;const t={format:f,minFilter:v,magFilter:v,type:c,depthBuffer:0,stencilBuffer:0};this.fromRenderTarget=new d(1,1,t),this.toRenderTarget=new d(1,1,t),this.fromRenderTarget.texture.generateMipmaps=0,this.toRenderTarget.texture.generateMipmaps=0}get needsUpdate(){return this.needsUpdateInternal&&this.hasValuablePasses()||this.hasPassesNeedingUpdate()}get lastPaddingHasChanged(){return this.lastPaddingHasChangedInternal}get lastPadding(){return this.lastPaddingInternal}requestUpdate(){this.needsUpdateInternal=1}compose(t,i,s,n,o=1){const e=this.hasValuablePasses();if(!(this.needsUpdateInternal&&e||this.hasPassesNeedingUpdate()))return e||(this.lastPaddingHasChangedInternal=0!==this.lastPaddingInternal,this.lastPaddingInternal=0),this.needsUpdateInternal=0,e?this.defaultMaterial:n;const r=this.calculatePadding();this.lastPaddingHasChangedInternal=this.lastPaddingInternal!==r,this.lastPaddingInternal=r;const h=i+2*r,l=s+2*r;this.fromRenderTarget.setSize(h,l),this.toRenderTarget.setSize(h,l),this.setScreenPadding(i,s,r),t.setClearColor(0,0),t.setRenderTarget(this.toRenderTarget),t.clear(1,0,0);const u=n.blending;o&&(n.blending=w),this.screen.render(t,n),n.blending=u;const a={width:i,height:s,padding:r};for(let i=0;i<this.passes.length;i++){const s=this.passes[i];(s.needsUpdate||s.isValuable)&&(this.reverseRenderTargets(),t.setRenderTarget(this.toRenderTarget),t.clear(1,0,0),this.passes[i].render(t,this.fromRenderTarget.texture,a))}return this.needsUpdateInternal=0,this.defaultMaterial.setTexture(this.toRenderTarget.texture),this.defaultMaterial}destroy(){this.fromRenderTarget.dispose(),this.toRenderTarget.dispose()}hasValuablePasses(){return this.passes.some((t=>t.isValuable))}hasPassesNeedingUpdate(){return this.passes.some((t=>t.needsUpdate))}calculatePadding(){return this.passes.reduce(((t,i)=>Math.max(t,i.padding)),0)}setScreenPadding(t,i,s){this.screen.paddingHorizontal=s/t,this.screen.paddingVertical=s/i}reverseRenderTargets(){const t=this.fromRenderTarget;this.fromRenderTarget=this.toRenderTarget,this.toRenderTarget=t}}var zt,Ft,Ut,jt,Bt,Ht,Vt,Rt,Lt,Kt;(t=>{t.CLICK="click"})(Ht||(Ht={}));class _t extends wt{constructor(t,i,s,n,o,e){super(),this.layer=t,this.object=i,this.name="",this[zt]=new E("x"),this[Ft]=new E("y"),this[Ut]=new E("width"),this[jt]=new E("height"),this[Bt]=0,this.behaviorInternal=Et.VISIBLE,this.composer=new Dt,this.lastPadding=0,this.micro=new Tt(this),this.layer[L](this,this.object),this.layer[q](this,this[B],at(nt.P7)),this.layer[q](this,this[H],at(nt.P7)),this.layer[q](this,this[V],at(nt.P5)),this.layer[q](this,this[R],at(nt.P5)),this[B].setValue(s),this[H].setValue(n),this[V].setValue(o),this[R].setValue(e),this.layer[G](this,this[B],s),this.layer[G](this,this[H],n),this.layer[G](this,this[V],o),this.layer[G](this,this[R],e)}get passes(){return this.composer.passes}get x(){return this[B].value()}get y(){return this[H].value()}get width(){return this[V].value()}get height(){return this[R].value()}get zIndex(){return this.object.position.z}get behavior(){return this.behaviorInternal}set x(t){this.layer[G](this,this[B],t)}set y(t){this.layer[G](this,this[H],t)}set width(t){this.layer[G](this,this[V],t)}set height(t){this.layer[G](this,this[R],t)}set zIndex(t){this.object.position.z=t}set behavior(t){this.behaviorInternal=t,this.object.visible=t!==Et.HIDDEN}destroy(){this.composer.destroy(),this.layer[W](this,this[R]),this.layer[W](this,this[V]),this.layer[W](this,this[H]),this.layer[W](this,this[B]),this.layer[K](this)}[(zt=B,Ft=H,Ut=V,jt=R,Bt=Z,it)](t,i){return this.behavior!==Et.INTERACTIVE?0:(this.flushTransform(),s=this.x,n=this.y,o=this.width,e=this.height,pt.set(t,i),gt.min.set(s,n),gt.max.set(o,e).add(gt.min),gt.containsPoint(pt)?(this.emit(Ht.CLICK,this),1):0);var s,n,o,e}flushTransform(){(this[Z]||this.micro[Z]||this.composer.lastPaddingHasChanged)&&(((t,i,s,n,o,e,r)=>{const h=this.x-r,l=this.y-r,u=this.width+2*r,a=this.height+2*r,d=h+u*i.anchorX,c=l+a*i.anchorY,v=mt.set(1,0,-d,0,1,-c,0,0,1),f=yt.set(i.scaleX,0,0,0,i.scaleY,0,0,0,1),w=bt.set(Math.cos(i.rotation),-Math.sin(i.rotation),0,Math.sin(i.rotation),Math.cos(i.rotation),0,0,0,1),p=xt.set(1,0,i.x+d,0,1,i.y+c,0,0,1),g=Ct.multiplyMatrices(p,w).multiply(f).multiply(v),m=St.set(h,l,1).applyMatrix3(g);t.position.x=m.x,t.position.y=m.y,t.rotation.z=i.rotation,t.scale.x=u*i.scaleX,t.scale.y=a*i.scaleY})(this.object,this.micro,0,0,0,0,this.composer.lastPadding),this[Z]=0,this.micro[Z]=0)}}const Nt=new r(0);var Xt,Yt,qt;(t=>{t.ORIENTATION_CHANGED="orientationChanged"})(Xt||(Xt={}));class Wt extends wt{constructor(){super(...arguments),this.behavior=Et.VISIBLE,this[Vt]=new E,this[Rt]=new E,this[Lt]=new E,this[Kt]=new E,this.scene=new l,this.camera=new a,this.solver=new D,this.elements=new Map,this.constraints=new Map,this.orientationPrivate=st.PORTRAIT,this.needsRecalculation=0}get orientation(){return this.orientationPrivate}destroy(){this.solver=void 0;for(const t of this.constraints.keys())t.destroy();for(const t of this.elements.keys())t.destroy()}[(Vt=B,Rt=H,Lt=V,Kt=R,L)](t,i){if(this.elements.has(t))throw Error("Element already added");this.elements.set(t,{object:i,variables:new Map,constraints:new Set}),i.position.z=500,this.scene.add(i)}[K](t){const i=this.elements.get(t);if(void 0===i)throw Error("Element not found");if(i.variables.size>0)throw Error("Variables should be removed before removing element");if(i.constraints.size>0)throw Error("Constraints should be removed before removing element");this.elements.delete(t),this.scene.remove(i.object)}[_](t,i){if(this.constraints.has(t))throw Error("Constraint already added");for(const s of i){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(i.constraints.has(t))throw Error("Something went wrong");i.constraints.add(t)}this.constraints.set(t,{elements:i,variables:new Map,constraints:new Set})}[N](t){const i=this.constraints.get(t);if(void 0===i)throw Error("Constraint not found");if(i.variables.size>0)throw Error("Variables should be removed before removing constraint");if(i.constraints.size>0)throw Error("Constraints should be removed before removing constraint");for(const s of i.elements){const i=this.elements.get(s);if(void 0===i)throw Error("Element not found");if(!i.constraints.has(t))throw Error("Something went wrong");i.constraints.delete(t)}this.constraints.delete(t)}[X](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before adding constraint you need to add it's owner");if(n.constraints.has(i))throw Error("Constraint already exists");n.constraints.add(i),null===(s=this.solver)||void 0===s||s.addConstraint(i),this.needsRecalculation=1}[Y](t,i){var s;const n=this.constraints.get(t);if(void 0===n)throw Error("Before removing constraint you need to add it's owner");if(!n.constraints.has(i))throw Error("Constraint not found");n.constraints.delete(i),null===(s=this.solver)||void 0===s||s.removeConstraint(i),this.needsRecalculation=1}[q](t,i,s){var n;const o=t instanceof _t?this.elements.get(t):this.constraints.get(t);if(void 0===o)throw Error("Before adding variable you need to add it's owner");if(o.variables.has(i))throw Error("Variable already exists");o.variables.set(i,{strength:s,suggestedValue:i.value()}),null===(n=this.solver)||void 0===n||n.addEditVariable(i,s),this.needsRecalculation=1}[W](t,i){var s;const n=t instanceof _t?this.elements.get(t):this.constraints.get(t);if(void 0===n)throw Error("Before removing variable you need to add it's owner");if(!n.variables.has(i))throw Error("Variable does not exist");n.variables.delete(i),null===(s=this.solver)||void 0===s||s.removeEditVariable(i),this.needsRecalculation=1}[G](t,i,s){var n;const o=t instanceof _t?this.elements.get(t):this.constraints.get(t);if(void 0===o)throw Error("Before suggesting variable you need to add it's owner");const e=o.variables.get(i);if(!e)throw Error("Variable does not exist");e.suggestedValue!==s&&(e.suggestedValue=s,null===(n=this.solver)||void 0===n||n.suggestValue(i,s),this.needsRecalculation=1)}render(t){var i;if(this.behavior===Et.HIDDEN)return;const s=t.getRenderTarget(),n=t.getClearColor(Nt),o=t.getClearAlpha();if(this.needsRecalculation){this.needsRecalculation=0,null===(i=this.solver)||void 0===i||i.updateVariables();for(const t of this.elements.keys())t[Z]=1}for(const i of this.elements.keys())i[tt](t);t.setRenderTarget(s),t.setClearColor(n),t.setClearAlpha(o),t.render(this.scene,this.camera)}clickInternal(t,i){if(this.behavior!==Et.INTERACTIVE)return;const s=[...this.elements.keys()].filter((t=>t.behavior===Et.INTERACTIVE)).sort(((t,i)=>t.zIndex-i.zIndex));for(const n of s)if(n[it](t,i))break}resizeInternal(t,i){this.applyCameraSize(t,i),this.rebuildLayerConstraints(t,i),this.updateOrientation(t,i),this.needsRecalculation=1}applyCameraSize(t,i){this.camera.near=-1e3,this.camera.far=0,this.camera.bottom=0,this.camera.left=0,this.camera.right=t,this.camera.top=i,this.camera.updateProjectionMatrix()}rebuildLayerConstraints(t,i){var s,n,o,e,r,h,l,u;this.constraintX&&(null===(s=this.solver)||void 0===s||s.removeConstraint(this.constraintX),this.constraintX=void 0),this.constraintY&&(null===(n=this.solver)||void 0===n||n.removeConstraint(this.constraintY),this.constraintY=void 0),this.constraintW&&(null===(o=this.solver)||void 0===o||o.removeConstraint(this.constraintW),this.constraintW=void 0),this.constraintH&&(null===(e=this.solver)||void 0===e||e.removeConstraint(this.constraintH),this.constraintH=void 0),this.constraintX=new $(new O(this[B]),M.Eq,0,P.required),this.constraintY=new $(new O(this[H]),M.Eq,0,P.required),this.constraintW=new $(new O(this[V]),M.Eq,t,P.required),this.constraintH=new $(new O(this[R]),M.Eq,i,P.required),null===(r=this.solver)||void 0===r||r.addConstraint(this.constraintX),null===(h=this.solver)||void 0===h||h.addConstraint(this.constraintY),null===(l=this.solver)||void 0===l||l.addConstraint(this.constraintW),null===(u=this.solver)||void 0===u||u.addConstraint(this.constraintH)}updateOrientation(t,i){const s=this.orientationPrivate;if(this.orientationPrivate=t>i?st.LANDSCAPE:st.PORTRAIT,s!==this.orientationPrivate){this.solver=void 0;for(const t of this.constraints.keys())t[J](this.orientationPrivate);for(const t of this.constraints.keys())t[Q](this.orientationPrivate);this.solver=new D;const t=[...this.elements.values(),...this.constraints.values()];for(const i of t)for(const[t,s]of i.variables.entries())this.solver.addEditVariable(t,s.strength),this.solver.suggestValue(t,s.suggestedValue);this.constraintX&&this.solver.addConstraint(this.constraintX),this.constraintY&&this.solver.addConstraint(this.constraintY),this.constraintW&&this.solver.addConstraint(this.constraintW),this.constraintH&&this.solver.addConstraint(this.constraintH);for(const t of this.constraints.values())for(const i of t.constraints.values())this.solver.addConstraint(i);this.emit(Xt.ORIENTATION_CHANGED,this,this.orientation)}}}function Gt(t,i){if((t instanceof Wt?t:t.layer)!==i.layer)throw Error(`Elements must be on the same layer - element "${i.constructor.name}" cannot interact with elements from a different layer`)}function Qt(t,i,s){if(t<=0||i<=0)throw Error(null!=s?s:`Invalid dimensions: width (${t}) and height (${i}) must both be positive numbers greater than 0`)}class Jt extends ht{constructor(t,i,s){var n,o,e;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(o=null==s?void 0:s.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==s?void 0:s.distance)&&void 0!==e?e:0,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[B]).plus(new O(this.elementOne[V]).multiply(this.parameters.anchorOne)),i=new O(this.elementTwo[B]).plus(new O(this.elementTwo[V]).multiply(this.parameters.anchorTwo));this.constraint=new $(i.minus(t),vt(this.parameters.rule),this.parameters.distance,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class Zt extends ht{constructor(t,i,s){var n;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[V]).multiply(this.parameters.proportion),i=new O(this.elementTwo[V]);this.constraint=new $(t.minus(i),vt(this.parameters.rule),0,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ti extends ht{constructor(t,i,s){var n,o,e;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={anchorOne:null!==(n=null==s?void 0:s.anchorOne)&&void 0!==n?n:.5,anchorTwo:null!==(o=null==s?void 0:s.anchorTwo)&&void 0!==o?o:.5,distance:null!==(e=null==s?void 0:s.distance)&&void 0!==e?e:0,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[H]).plus(new O(this.elementOne[R]).multiply(this.parameters.anchorOne)),i=new O(this.elementTwo[H]).plus(new O(this.elementTwo[R]).multiply(this.parameters.anchorTwo));this.constraint=new $(i.minus(t),vt(this.parameters.rule),this.parameters.distance,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ii extends ht{constructor(t,i,s){var n;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={proportion:null!==(n=null==s?void 0:s.proportion)&&void 0!==n?n:1,power:ut(null==s?void 0:s.power),rule:ct(null==s?void 0:s.rule),orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.elementOne[R]).multiply(this.parameters.proportion),i=new O(this.elementTwo[R]);this.constraint=new $(t.minus(i),vt(this.parameters.rule),0,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class si extends ht{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.options={width:null!==(s=null==i?void 0:i.width)&&void 0!==s?s:t.width,power:ut(null==i?void 0:i.power),rule:ct(null==i?void 0:i.rule),orientation:rt(null==i?void 0:i.orientation)},this.options.orientation!==st.ALWAYS&&this.options.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.options.orientation!==st.ALWAYS&&t!==this.options.orientation&&this.destroyConstraints()}[J](t){this.options.orientation!==st.ALWAYS&&t===this.options.orientation&&this.buildConstraints()}buildConstraints(){this.constraint=new $(new O(this.element[V]),vt(this.options.rule),this.options.width,at(this.options.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ni{static size(t,i){var s,n,o,e,r,h,l,u;return{x:new si(t,{width:null===(s=i.size)||void 0===s?void 0:s.x,power:null===(n=i.power)||void 0===n?void 0:n.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:null===(e=i.orientation)||void 0===e?void 0:e.x}),y:new ft(t,{height:null===(r=i.size)||void 0===r?void 0:r.y,power:null===(h=i.power)||void 0===h?void 0:h.y,rule:null===(l=i.rule)||void 0===l?void 0:l.y,orientation:null===(u=i.orientation)||void 0===u?void 0:u.y})}}static distance(t,i,s){var n,o,e,r,h,l,u,a,d,c,v,f;return{x:new Jt(t,i,{anchorOne:null===(n=s.anchorOne)||void 0===n?void 0:n.x,anchorTwo:null===(o=s.anchorTwo)||void 0===o?void 0:o.x,distance:null===(e=s.distance)||void 0===e?void 0:e.x,power:null===(r=s.power)||void 0===r?void 0:r.x,rule:null===(h=s.rule)||void 0===h?void 0:h.x,orientation:null===(l=s.orientation)||void 0===l?void 0:l.x}),y:new ti(t,i,{anchorOne:null===(u=s.anchorOne)||void 0===u?void 0:u.y,anchorTwo:null===(a=s.anchorTwo)||void 0===a?void 0:a.y,distance:null===(d=s.distance)||void 0===d?void 0:d.y,power:null===(c=s.power)||void 0===c?void 0:c.y,rule:null===(v=s.rule)||void 0===v?void 0:v.y,orientation:null===(f=s.orientation)||void 0===f?void 0:f.y})}}static proportion(t,i,s){var n,o,e,r,h,l,u,a;return{x:new Zt(t,i,{proportion:null===(n=s.proportion)||void 0===n?void 0:n.x,power:null===(o=s.power)||void 0===o?void 0:o.x,rule:null===(e=s.rule)||void 0===e?void 0:e.x,orientation:null===(r=s.orientation)||void 0===r?void 0:r.x}),y:new ii(t,i,{proportion:null===(h=s.proportion)||void 0===h?void 0:h.y,power:null===(l=s.power)||void 0===l?void 0:l.y,rule:null===(u=s.rule)||void 0===u?void 0:u.y,orientation:null===(a=s.orientation)||void 0===a?void 0:a.y})}}}class oi extends ht{constructor(t,i){var s;super(t.layer,new Set([t])),this.element=t,this.parameters={aspect:null!==(s=null==i?void 0:i.aspect)&&void 0!==s?s:this.element.width/this.element.height,power:ut(null==i?void 0:i.power),rule:ct(null==i?void 0:i.rule),orientation:rt(null==i?void 0:i.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){const t=new O(this.element[V]).plus(new O(this.element[R]).multiply(-this.parameters.aspect));this.constraint=new $(t,vt(this.parameters.rule),0,at(this.parameters.power)),this.layer[X](this,this.constraint)}destroyConstraints(){this.constraint&&(this.layer[Y](this,this.constraint),this.constraint=void 0)}}class ei extends ht{constructor(t,i,s){var n,o,e;Gt(t,i),super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(o=null==s?void 0:s.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==s?void 0:s.verticalAnchor)&&void 0!==e?e:.5,orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new $(new O(this.elementOne[B]).plus(new O(this.elementOne[V]).multiply(this.parameters.horizontalAnchor)),M.Eq,new O(this.elementTwo[B]).plus(new O(this.elementTwo[V]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new $(new O(this.elementOne[H]).plus(new O(this.elementOne[R]).multiply(this.parameters.verticalAnchor)),M.Eq,new O(this.elementTwo[H]).plus(new O(this.elementTwo[R]).multiply(this.parameters.verticalAnchor))),this.constraintW=new $(new O(this.elementOne[V]),M.Le,new O(this.elementTwo[V])),this.constraintH=new $(new O(this.elementOne[R]),M.Le,new O(this.elementTwo[R])),this.layer[X](this,this.constraintX),this.layer[X](this,this.constraintY),this.layer[X](this,this.constraintW),this.layer[X](this,this.constraintH),this.parameters.isStrict||(this.constraintStrict=new $(new O(this.elementOne[R]),M.Eq,new O(this.elementTwo[R]),P.strong),this.layer[X](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[Y](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[Y](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[Y](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[Y](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[Y](this,this.constraintStrict),this.constraintStrict=void 0)}}function ri(t){return null!==t&&"object"==typeof t&&("x"in t&&"number"==typeof t.x||"y"in t&&"number"==typeof t.y)}function hi(t){return null!==t&&"object"==typeof t&&("x"in t&&lt(t.x)||"y"in t&&lt(t.y))}function li(t){return null!==t&&"object"==typeof t&&("x"in t&&dt(t.x)||"y"in t&&dt(t.y))}function ui(t){return null!==t&&"object"==typeof t&&"elementOne"in t&&"elementTwo"in t&&(t.elementOne instanceof _t||t.elementOne instanceof Wt)&&t.elementTwo instanceof _t}function ai(t){return ui(t)&&"distance"in t&&ri(t.distance)&&(!("anchorOne"in t)||"anchorOne"in t&&ri(t.anchorOne))&&(!("anchorTwo"in t)||"anchorTwo"in t&&ri(t.anchorTwo))&&(!("power"in t)||hi(t.power))&&(!("rule"in t)||li(t.rule))&&(!("orientation"in t)||et(t.orientation))}function di(t){return ui(t)&&"proportion"in t&&ri(t.proportion)&&(!("power"in t)||hi(t.power))&&(!("rule"in t)||li(t.rule))&&(!("orientation"in t)||et(t.orientation))}function ci(t){return ui(t)&&"isStrict"in t&&"boolean"==typeof t.isStrict&&(!("anchor"in t)||"anchor"in t&&ri(t.anchor))}function vi(t){return null!==t&&"object"==typeof t&&"element"in t&&t.element instanceof _t&&(!("power"in t)||lt(t.power))&&(!("rule"in t)||dt(t.rule))}function fi(t){return vi(t)&&"height"in t&&"number"==typeof t.height}function wi(t){return vi(t)&&"keepAspect"in t&&"boolean"==typeof t.keepAspect}function pi(t){return vi(t)&&"keepSize"in t&&"boolean"==typeof t.keepSize}class gi{static fromDescription(t){const i=t instanceof Map?t.entries():Object.entries(t),s=new Map;for(const[t,o]of i){if(s.has(t))throw Error(`Duplicate constraint key "${t}" - each constraint must have a unique identifier`);if(vi(n=o)&&"width"in n&&"number"==typeof n.width)gi.buildWidthConstraint(t,o,s);else if(fi(o))gi.buildHeightConstraint(t,o,s);else if(wi(o))gi.buildKeepAspectConstraint(t,o,s);else if(pi(o))gi.buildKeepSizeConstraint(t,o,s);else if(ai(o))gi.buildDistanceConstraint(t,o,s);else if(di(o))gi.buildProportionalConstraint(t,o,s);else{if(!ci(o))throw Error(`Invalid constraint type for "${t}". Expected one of: Width, Height, KeepAspect, KeepSize, Distance, Proportional, or Cover constraint`);gi.buildCoverConstraint(t,o,s)}}var n;return Object.fromEntries(s)}static buildWidthConstraint(t,i,s){s.set(t,new si(i.element,{width:i.width,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildHeightConstraint(t,i,s){s.set(t,new ft(i.element,{height:i.height,power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepAspectConstraint(t,i,s){s.set(t,new oi(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildKeepSizeConstraint(t,i,s){const n=t.replace(/(KeepSize|Keep)$/,"")+"KeepWidth",o=t.replace(/(KeepSize|Keep)$/,"")+"KeepHeight";s.set(n,new si(i.element,{power:i.power,rule:i.rule,orientation:i.orientation})),s.set(o,new ft(i.element,{power:i.power,rule:i.rule,orientation:i.orientation}))}static buildDistanceConstraint(t,i,s){var n,o,e,r,h,l,u,a;if("number"==typeof i.distance.x){const h=t.replace(/(HorizontalDistance|Distance)$/,"")+"HorizontalDistance";s.set(h,new Jt(i.elementOne,i.elementTwo,{distance:i.distance.x,anchorOne:null===(n=i.anchorOne)||void 0===n?void 0:n.x,anchorTwo:null===(o=i.anchorTwo)||void 0===o?void 0:o.x,power:null===(e=i.power)||void 0===e?void 0:e.x,rule:null===(r=i.rule)||void 0===r?void 0:r.x,orientation:i.orientation}))}if("number"==typeof i.distance.y){const n=t.replace(/(VerticalDistance|Distance)$/,"")+"VerticalDistance";s.set(n,new ti(i.elementOne,i.elementTwo,{distance:i.distance.y,anchorOne:null===(h=i.anchorOne)||void 0===h?void 0:h.y,anchorTwo:null===(l=i.anchorTwo)||void 0===l?void 0:l.y,power:null===(u=i.power)||void 0===u?void 0:u.y,rule:null===(a=i.rule)||void 0===a?void 0:a.y,orientation:i.orientation}))}}static buildProportionalConstraint(t,i,s){var n,o,e,r;if("number"==typeof i.proportion.x){const e=t.replace(/(HorizontalProportional|HorizontalProportion|Proportional|Proportion)$/,"")+"HorizontalProportion";s.set(e,new Zt(i.elementOne,i.elementTwo,{proportion:i.proportion.x,power:null===(n=i.power)||void 0===n?void 0:n.x,rule:null===(o=i.rule)||void 0===o?void 0:o.x,orientation:i.orientation}))}if("number"==typeof i.proportion.y){const n=t.replace(/(VerticalProportional|VerticalProportion|Proportional|Proportion)$/,"")+"VerticalProportion";s.set(n,new ii(i.elementOne,i.elementTwo,{proportion:i.proportion.y,power:null===(e=i.power)||void 0===e?void 0:e.y,rule:null===(r=i.rule)||void 0===r?void 0:r.y,orientation:i.orientation}))}}static buildCoverConstraint(t,i,s){var n,o;s.set(t,new ei(i.elementOne,i.elementTwo,{isStrict:i.isStrict,horizontalAnchor:null===(n=i.anchor)||void 0===n?void 0:n.x,verticalAnchor:null===(o=i.anchor)||void 0===o?void 0:o.y}))}}(t=>{t[t.FROM_LEFT_TOP=0]="FROM_LEFT_TOP",t[t.FROM_LEFT_BOTTOM=1]="FROM_LEFT_BOTTOM"})(Yt||(Yt={}));class mi{static build(t,i,s,n={}){var o;const e=null!==(o=n.direction)&&void 0!==o?o:Yt.FROM_LEFT_TOP,r=[],h=[];r.push(new Jt(t,i,{anchorOne:0,anchorTwo:0,distance:0,power:n.power,orientation:n.orientation}),new Jt(t,s,{anchorOne:1,anchorTwo:1,distance:0,power:n.power,orientation:n.orientation}));const l=e===Yt.FROM_LEFT_TOP?1:0,u=e===Yt.FROM_LEFT_TOP?0:1;return h.push(new ti(t,i,{anchorOne:l,anchorTwo:l,distance:0,power:n.power,orientation:n.orientation}),new ti(t,s,{anchorOne:u,anchorTwo:u,distance:0,power:n.power,orientation:n.orientation})),{horizontalDistances:r,verticalDistances:h}}}class yi{static buildHorizontal(t,i){return this.buildStack(t,i,{distanceConstraint:Jt,proportionConstraint:Zt,centerDistanceConstraint:ti})}static buildVertical(t,i){return this.buildStack(t,i,{distanceConstraint:ti,proportionConstraint:ii,centerDistanceConstraint:Jt})}static buildStack(t,i,s){const n=[],o=[],e=[];for(let r=0;r<t.length-1;r++){const h=t[r],l=t[r+1];n.push(new s.distanceConstraint(h,l,{anchorOne:1,anchorTwo:0,distance:i.distance,power:i.power,orientation:i.orientation})),0!=i.keepProportions&&o.push(new s.proportionConstraint(h,l,{power:i.power,orientation:i.orientation})),0!=i.keepAlignment&&e.push(new s.centerDistanceConstraint(h,l,{power:i.power,anchorOne:0,anchorTwo:0,orientation:i.orientation}))}return{distanceConstraints:n,proportionConstraints:o,alignmentConstraints:e}}}class bi extends _t{constructor(t,i=1e3,s=1e3){super(t,new p,0,0,i,s),this.flushTransform()}[tt](){this.flushTransform()}}class xi extends _t{constructor(t,i){var s,n;const o=null===(s=i.image)||void 0===s?void 0:s.width,e=null===(n=i.image)||void 0===n?void 0:n.height;Qt(o,e,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${o}) or height (${e}). Image dimensions must be non-zero positive numbers.`);const r=new Mt(i);super(t,new u(Pt,r),0,0,o,e),this.material=r,this.textureInternal=i,this.flushTransform()}get texture(){return this.textureInternal}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),super.destroy()}[tt](t){this.object.material=this.composer.compose(t,this.textureInternal.image.width,this.textureInternal.image.height,this.material),this.flushTransform()}}class Ci extends e{constructor(t,i){super({uniforms:g.merge([{background:{value:i},foreground:{value:t},progress:{value:1},backgroundColor:{value:new r(1,1,1)},foregroundColor:{value:new r(1,1,1)},color:{value:new r(1,1,1)},backgroundOpacity:{value:1},foregroundOpacity:{value:1},opacity:{value:1},angle:{value:0},direction:{value:1}}]),vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D background;\n uniform sampler2D foreground;\n uniform float progress;\n uniform vec3 backgroundColor;\n uniform vec3 foregroundColor;\n uniform vec3 color;\n uniform float backgroundOpacity;\n uniform float foregroundOpacity;\n uniform float opacity;\n uniform float angle;\n uniform float direction;\n varying vec2 vUv;\n\n void main() {\n vec4 backgroundTexture = texture2D(background, vUv);\n vec4 foregroundTexture = texture2D(foreground, vUv);\n\n // Apply common color and opacity\n vec3 finalBackgroundColor = backgroundTexture.rgb * backgroundColor * color;\n vec3 finalForegroundColor = foregroundTexture.rgb * foregroundColor * color;\n float finalBackgroundOpacity = backgroundTexture.a * backgroundOpacity * opacity;\n float finalForegroundOpacity = foregroundTexture.a * foregroundOpacity * opacity;\n\n vec4 backgroundColor = vec4(finalBackgroundColor, finalBackgroundOpacity);\n vec4 foregroundColor = vec4(finalForegroundColor, finalForegroundOpacity);\n\n // Calculate progress threshold with angle and direction\n float adjustedX = mix(vUv.x, 1.0 - vUv.x, step(0.0, -direction));\n float tanAngle = tan(angle);\n float threshold = adjustedX - (vUv.y - 0.5) * tanAngle * sign(direction);\n float progressMask = smoothstep(threshold - 0.01, threshold + 0.01, progress);\n\n gl_FragColor = mix(backgroundColor, foregroundColor, progressMask);\n #include <colorspace_fragment>\n }\n ",transparent:1,lights:0,fog:0})}getProgress(){return this.uniforms.progress.value}getBackgroundTexture(){return this.uniforms.background.value}getForegroundTexture(){return this.uniforms.foreground.value}getBackgroundColor(){return this.uniforms.color.value.getHex()}getForegroundColor(){return this.uniforms.color.value.getHex()}getColor(){return this.uniforms.color.value.getHex()}getBackgroundOpacity(){return this.uniforms.backgroundOpacity.value}getForegroundOpacity(){return this.uniforms.foregroundOpacity.value}getOpacity(){return this.uniforms.opacity.value}getAngle(){return this.uniforms.angle.value}getIsForwardDirection(){return 1===this.uniforms.direction.value}setProgress(t){this.uniforms.progress.value=t,this.uniformsNeedUpdate=1}setBackgroundTexture(t){this.uniforms.background.value=t,this.uniformsNeedUpdate=1}setForegroundTexture(t){this.uniforms.foreground.value=t,this.uniformsNeedUpdate=1}setBackgroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setForegroundColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setColor(t){this.uniforms.color.value.setHex(t),this.uniformsNeedUpdate=1}setBackgroundOpacity(t){this.uniforms.backgroundOpacity.value=t,this.uniformsNeedUpdate=1}setForegroundOpacity(t){this.uniforms.foregroundOpacity.value=t,this.uniformsNeedUpdate=1}setOpacity(t){this.uniforms.opacity.value=t,this.uniformsNeedUpdate=1}setAngle(t){this.uniforms.angle.value=t,this.uniformsNeedUpdate=1}setIsForwardDirection(t){this.uniforms.direction.value=t?1:-1,this.uniformsNeedUpdate=1}}class Si extends _t{constructor(t,i,s,n={}){var e,r,h,l;const a=null===(e=i.image)||void 0===e?void 0:e.width,d=null===(r=i.image)||void 0===r?void 0:r.height;Qt(a,d,`Invalid image dimensions - texture "${i.name||"unnamed"}" has invalid width (${a}) or height (${d}). Image dimensions must be non-zero positive numbers.`);const c=null===(h=null==s?void 0:s.image)||void 0===h?void 0:h.width,v=null===(l=null==s?void 0:s.image)||void 0===l?void 0:l.height;s&&Qt(c,v,`Invalid image dimensions - texture "${s.name||"unnamed"}" has invalid width (${c}) or height (${v}). Image dimensions must be non-zero positive numbers.`);const f=new Ci(i,s),w=new u(Pt,f);n.progress&&f.setProgress(n.progress),n.isForegroundDirection&&f.setIsForwardDirection(n.isForegroundDirection),n.angle&&f.setAngle(o.degToRad(n.angle)),n.color&&f.setColor(n.color),n.opacity&&f.setOpacity(n.opacity),n.backgroundColor&&f.setBackgroundColor(n.backgroundColor),n.foregroundColor&&f.setForegroundColor(n.foregroundColor),n.backgroundOpacity&&f.setBackgroundOpacity(n.backgroundOpacity),n.foregroundOpacity&&f.setForegroundOpacity(n.foregroundOpacity);const p=null!=c?c:a,g=null!=d?d:v;super(t,w,0,0,p,g),this.material=f,this.imageWidth=p,this.imageHeight=g,this.flushTransform()}get progress(){return this.material.getProgress()}get backgroundTexture(){return this.material.getBackgroundTexture()}get foregroundTexture(){return this.material.getForegroundTexture()}get backgroundColor(){return this.material.getBackgroundColor()}get foregroundColor(){return this.material.getForegroundColor()}get color(){return this.material.getColor()}get backgroundOpacity(){return this.material.getBackgroundOpacity()}get foregroundOpacity(){return this.material.getForegroundOpacity()}get opacity(){return this.material.getOpacity()}get angle(){return o.radToDeg(this.material.getAngle())}get isForwardDirection(){return this.material.getIsForwardDirection()}set progress(t){this.material.setProgress(t),this.composer.requestUpdate()}set backgroundColor(t){this.material.setBackgroundColor(t),this.composer.requestUpdate()}set foregroundColor(t){this.material.setForegroundColor(t),this.composer.requestUpdate()}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set backgroundOpacity(t){this.material.setBackgroundOpacity(t),this.composer.requestUpdate()}set foregroundOpacity(t){this.material.setForegroundOpacity(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}set angle(t){this.material.setAngle(o.degToRad(t)),this.composer.requestUpdate()}set isForwardDirection(t){this.material.setIsForwardDirection(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),super.destroy()}[tt](t){this.object.material=this.composer.compose(t,this.imageWidth,this.imageHeight,this.material),this.flushTransform()}}function Ei(t,i){var s,n,o,e,r,h,l,u,a,d,c,v,f,w,p,g,m,y,b,x,C,S,E,k,O,T,M,P;const I=Math.max(null!==(n=null!==(s=null==t?void 0:t.fontSize)&&void 0!==s?s:null==i?void 0:i.fontSize)&&void 0!==n?n:16,1),$=null!==(e=null!==(o=null==t?void 0:t.lineHeight)&&void 0!==o?o:null==i?void 0:i.lineHeight)&&void 0!==e?e:1.2*I,A=Math.max(null!==(h=null!==(r=null==t?void 0:t.shadowBlur)&&void 0!==r?r:null==i?void 0:i.shadowBlur)&&void 0!==h?h:0,0),D=Math.max(null!==(u=null!==(l=null==t?void 0:t.strokeWidth)&&void 0!==l?l:null==i?void 0:i.strokeWidth)&&void 0!==u?u:0,0);return{color:null!==(d=null!==(a=null==t?void 0:t.color)&&void 0!==a?a:null==i?void 0:i.color)&&void 0!==d?d:"#000000",fontFamily:null!==(v=null!==(c=null==t?void 0:t.fontFamily)&&void 0!==c?c:null==i?void 0:i.fontFamily)&&void 0!==v?v:"Arial",fontSize:I,fontStyle:null!==(w=null!==(f=null==t?void 0:t.fontStyle)&&void 0!==f?f:null==i?void 0:i.fontStyle)&&void 0!==w?w:"normal",fontWeight:null!==(g=null!==(p=null==t?void 0:t.fontWeight)&&void 0!==p?p:null==i?void 0:i.fontWeight)&&void 0!==g?g:"normal",lineHeight:$,enableShadow:null!==(y=null!==(m=null==t?void 0:t.enableShadow)&&void 0!==m?m:null==i?void 0:i.enableShadow)&&void 0!==y?y:0,shadowOffsetX:null!==(x=null!==(b=null==t?void 0:t.shadowOffsetX)&&void 0!==b?b:null==i?void 0:i.shadowOffsetX)&&void 0!==x?x:0,shadowOffsetY:null!==(S=null!==(C=null==t?void 0:t.shadowOffsetY)&&void 0!==C?C:null==i?void 0:i.shadowOffsetY)&&void 0!==S?S:0,shadowBlur:A,shadowColor:null!==(k=null!==(E=null==t?void 0:t.shadowColor)&&void 0!==E?E:null==i?void 0:i.shadowColor)&&void 0!==k?k:"transparent",enableStroke:null!==(T=null!==(O=null==t?void 0:t.enableStroke)&&void 0!==O?O:null==i?void 0:i.enableStroke)&&void 0!==T?T:0,strokeColor:null!==(P=null!==(M=null==t?void 0:t.strokeColor)&&void 0!==M?M:null==i?void 0:i.strokeColor)&&void 0!==P?P:"transparent",strokeWidth:D}}function ki(t){return t.match(/\S+|\s|\n/g)||[]}function Oi(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 n=t.measureText(i),o=n.width,e=Math.ceil(n.actualBoundingBoxAscent+n.actualBoundingBoxDescent);return{width:Math.ceil(o),height:e,baseline:n.actualBoundingBoxDescent,lineHeight:s.lineHeight}}function Ti(t,i,s,n,o){o.font=`${n.fontStyle} ${n.fontWeight} ${n.fontSize}px ${n.fontFamily}`,n.enableShadow&&(o.shadowOffsetX=n.shadowOffsetX,o.shadowOffsetY=n.shadowOffsetY,o.shadowBlur=n.shadowBlur,o.shadowColor=n.shadowColor),n.enableStroke&&(o.strokeStyle=n.strokeColor,o.lineWidth=n.strokeWidth,o.strokeText(s,t,i)),o.fillStyle=n.color,o.fillText(s,t,i)}class Mi extends _t{constructor(t,i,s={}){var n;const o=document.createElement("canvas"),e=o.getContext("2d");if(!e)throw Error("Failed to create canvas context");const r=[],h=Array.isArray(i)?i:[i];for(const t of h){const i="string"==typeof t,n=i?t:t.text,o=Ei(i?void 0:t.style,s.defaultStyle);for(const t of ki(n)){const i=Oi(e,t,o);r.push({text:t,style:o,metrics:i})}}const l=((t,i)=>{const s=[];let n=[],o=0,e=0,r=0,h=0;for(const l of i)"\n"!==l.text?o+l.metrics.width<=t||0===n.length?(n.push(l),o+=l.metrics.width,e=Math.max(e,l.metrics.height),r=Math.max(r,l.metrics.baseline),h=Math.max(h,l.metrics.lineHeight)):(s.push({chunks:n,width:o,height:e,baseline:r,lineHeight:h}),n=[l],o=l.metrics.width,e=l.metrics.height,r=l.metrics.baseline,h=l.metrics.lineHeight):(n.length>0&&s.push({chunks:n,width:o,height:e,baseline:r,lineHeight:h}),n=[],o=0,e=0,r=0,h=0);return n.length>0&&s.push({chunks:n,width:o,height:e,baseline:r,lineHeight:h}),s})(null!==(n=s.maxWidth)&&void 0!==n?n:1024,r),a=(t=>{if(0===t.length)return{width:0,height:0};const i=Math.max(...t.map((t=>t.width)));let s=0;for(let i=0;i<t.length;i++){const n=t[i];s+=0===i?n.height:n.lineHeight,i===t.length-1&&(s+=n.baseline)}return{width:i,height:s}})(l),d=(t=>{var i,s,n,o;return"number"==typeof t?{left:t,right:t,top:t,bottom:t}:{left:Math.max(null!==(i=null==t?void 0:t.left)&&void 0!==i?i:0,0),right:Math.max(null!==(s=null==t?void 0:t.right)&&void 0!==s?s:0,0),top:Math.max(null!==(n=null==t?void 0:t.top)&&void 0!==n?n:0,0),bottom:Math.max(null!==(o=null==t?void 0:t.bottom)&&void 0!==o?o:0,0)}})(s.padding);o.width=a.width+d.left+d.right,o.height=a.height+d.top+d.bottom;const c=new m(o),v=new Mt(c);super(t,new u(Pt,v),0,0,a.width,a.height),this.lastSuggestedAspect=0,this.material=v,this.texture=c,this.canvas=o,this.context=e,this.textBlockSize=a,this.padding=d,((t,i,s,n)=>{let o=this.padding.top;for(let t=0;t<s.length;t++){const e=s[t];let r=i;o+=0===t?e.height:e.lineHeight;for(const t of e.chunks)Ti(r,o,t.text,t.style,n),r+=t.metrics.width}})(0,this.padding.left,l,this.context),this.texture.needsUpdate=1,this.flushTransform()}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}destroy(){this.material.dispose(),this.texture.dispose(),this.canvas.remove(),super.destroy()}flushTransform(){super.flushTransform();const t=this.width/this.height;this.lastSuggestedAspect!==t&&(this.lastSuggestedAspect=t,this.layer[G](this,this[R],this.width/((this.textBlockSize.width+this.padding.left+this.padding.right)/(this.textBlockSize.height+this.padding.top+this.padding.bottom))))}[tt](t){this.object.material=this.composer.compose(t,this.texture.image.width,this.texture.image.height,this.material),this.flushTransform()}}function Pi(t){return null!==t&&"object"==typeof t&&"background"in t&&t.background instanceof y&&"foreground"in t&&t.foreground instanceof y}function Ii(t){return null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text}function $i(t){return null!==t&&"object"==typeof t&&"spans"in t&&Array.isArray(t.spans)&&t.spans.every((t=>"string"==typeof t||(t=>null!==t&&"object"==typeof t&&"text"in t&&"string"==typeof t.text)(t)))}function Ai(t){return!(null===t||"object"!=typeof t||"width"in t&&"number"!=typeof t.width||"height"in t&&"number"!=typeof t.height)}class Di{static fromDescription(t,i){const s=i instanceof Map?i.entries():Object.entries(i),n=new Map;for(const[i,e]of s){if(n.has(i))throw Error(`Duplicate element key "${i}" - each UI element must have a unique identifier`);let s;if(e instanceof y)s=new xi(t,e);else if(null!==(o=e)&&"object"==typeof o&&"texture"in o&&o.texture instanceof y)s=new xi(t,e.texture);else if("string"==typeof e)s=new Mi(t,[e]);else if(Pi(e))s=new Si(t,e.background,e.foreground);else if(Ii(e))s=new Mi(t,[e.text],{defaultStyle:e.style});else if($i(e))s=new Mi(t,e.spans,{defaultStyle:e.defaultStyle});else{if(!Ai(e))throw Error(`Invalid UI element type for "${i}". Expected one of: Texture, UIImage, String, UITextDescription, or UITextEnhancedDescription`);s=new bi(t,e.width,e.height)}n.set(i,s)}var o;return Object.fromEntries(n)}}class zi extends ht{constructor(t,i,s){var n,o,e;super(i.layer,new Set(t instanceof _t?[t,i]:[i])),this.elementOne=t,this.elementTwo=i,Gt(t,i),this.parameters={isStrict:null!==(n=null==s?void 0:s.isStrict)&&void 0!==n?n:1,horizontalAnchor:null!==(o=null==s?void 0:s.horizontalAnchor)&&void 0!==o?o:.5,verticalAnchor:null!==(e=null==s?void 0:s.verticalAnchor)&&void 0!==e?e:.5,orientation:rt(null==s?void 0:s.orientation)},this.parameters.orientation!==st.ALWAYS&&this.parameters.orientation!==this.layer.orientation||this.buildConstraints()}destroy(){this.destroyConstraints(),super.destroy()}[Q](t){this.parameters.orientation!==st.ALWAYS&&t!==this.parameters.orientation&&this.destroyConstraints()}[J](t){this.parameters.orientation!==st.ALWAYS&&t===this.parameters.orientation&&this.buildConstraints()}buildConstraints(){this.constraintX=new $(new O(this.elementOne[B]).plus(new O(this.elementOne[V]).multiply(this.parameters.horizontalAnchor)),M.Eq,new O(this.elementTwo[B]).plus(new O(this.elementTwo[V]).multiply(this.parameters.horizontalAnchor))),this.constraintY=new $(new O(this.elementOne[H]).plus(new O(this.elementOne[R]).multiply(this.parameters.verticalAnchor)),M.Eq,new O(this.elementTwo[H]).plus(new O(this.elementTwo[R]).multiply(this.parameters.verticalAnchor))),this.constraintW=new $(new O(this.elementOne[V]),M.Ge,new O(this.elementTwo[V])),this.constraintH=new $(new O(this.elementOne[R]),M.Ge,new O(this.elementTwo[R])),this.layer[X](this,this.constraintX),this.layer[X](this,this.constraintY),this.layer[X](this,this.constraintW),this.layer[X](this,this.constraintH),0!=this.parameters.isStrict&&(this.constraintStrict=new $(new O(this.elementOne[R]),M.Eq,new O(this.elementTwo[R]),P.strong),this.layer[X](this,this.constraintStrict))}destroyConstraints(){this.constraintX&&(this.layer[Y](this,this.constraintX),this.constraintX=void 0),this.constraintY&&(this.layer[Y](this,this.constraintY),this.constraintY=void 0),this.constraintW&&(this.layer[Y](this,this.constraintW),this.constraintW=void 0),this.constraintH&&(this.layer[Y](this,this.constraintH),this.constraintH=void 0),this.constraintStrict&&(this.layer[Y](this,this.constraintStrict),this.constraintStrict=void 0)}}(t=>{t.AUTO="AUTO",t.PROPERTY="PROPERTY",t.MANUAL="MANUAL"})(qt||(qt={}));const Fi=qt.PROPERTY;class Ui extends _t{constructor(t,i={}){var s,n,o,e,r,h,a,w,p,g;const m=null!==(s=i.resolutionFactor)&&void 0!==s?s:.5;if(m<.1||m>8)throw Error(`Invalid resolution factor: ${m}. Must be between 0.1 and 8.`);const y=null!==(n=i.width)&&void 0!==n?n:512,x=null!==(o=i.height)&&void 0!==o?o:512;Qt(y,x,`Invalid width or height: ${y}x${x}. Must be positive.`);const C=new d(y*m,x*m,{format:f,minFilter:v,magFilter:v,type:c,depthBuffer:null!==(e=i.useDepth)&&void 0!==e?e:1,stencilBuffer:0}),S=new Mt(C.texture);super(t,new u(Pt,S),0,0,y,x),this.needsRenderInternal=0,this.sceneInternal=null!==(r=i.scene)&&void 0!==r?r:new l,this.cameraInternal=null!==(h=i.camera)&&void 0!==h?h:new b(75,y/x,.1,100),this.resolutionFactorInternal=m,this.updateBehaviorInternal=null!==(a=i.updateBehavior)&&void 0!==a?a:Fi,null!==(w=i.renderedByDefault)&&void 0!==w&&w&&(this.needsRenderInternal=1),this.clearColorInternal=null!==(p=i.clearColor)&&void 0!==p?p:0,this.clearAlphaInternal=null!==(g=i.clearAlpha)&&void 0!==g?g:0,this.renderTarget=C,this.material=S,this.flushTransform()}get needsRender(){return this.needsRenderInternal}get color(){return this.material.getColor()}get opacity(){return this.material.getOpacity()}get scene(){return this.sceneInternal}get camera(){return this.cameraInternal}get clearColor(){return this.clearColorInternal}get clearAlpha(){return this.clearAlphaInternal}get resolutionFactor(){return this.resolutionFactorInternal}set color(t){this.material.setColor(t),this.composer.requestUpdate()}set opacity(t){this.material.setOpacity(t),this.composer.requestUpdate()}set scene(t){this.sceneInternal!==t&&(this.sceneInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set camera(t){this.cameraInternal!==t&&(this.cameraInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set clearColor(t){this.clearColorInternal!==t&&(this.clearColorInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set clearAlpha(t){this.clearAlphaInternal!==t&&(this.clearAlphaInternal=t,this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}set resolutionFactor(t){this.resolutionFactorInternal!==t&&(this.resolutionFactorInternal=t,this.renderTarget.setSize(this.width*this.resolutionFactorInternal,this.height*this.resolutionFactorInternal),this.updateBehaviorInternal===qt.PROPERTY&&this.requestRender())}destroy(){this.material.dispose(),this.renderTarget.dispose(),super.destroy()}requestRender(){this.needsRenderInternal=1,this.composer.requestUpdate()}[tt](t){(this.needsRenderInternal||this.updateBehaviorInternal===qt.AUTO)&&(this[Z]&&this.renderTarget.setSize(this.width*this.resolutionFactorInternal,this.height*this.resolutionFactorInternal),this.needsRenderInternal=0,t.setClearColor(this.clearColorInternal,this.clearAlpha),t.setRenderTarget(this.renderTarget),t.clear(1,1,0),t.render(this.sceneInternal,this.cameraInternal)),this.object.material=this.composer.compose(t,this.width*this.resolutionFactorInternal,this.height*this.resolutionFactorInternal,this.material),this.flushTransform()}}class ji extends Wt{constructor(){super(),this.targetScreenHeight=1920,this.onResize=()=>{const t=this.calculateScale();this.resizeInternal(window.innerWidth*t,window.innerHeight*t)},this.onClick=t=>{if(this.behavior!==Et.INTERACTIVE)return;const i=t.target instanceof HTMLElement?t.target.getBoundingClientRect():null,s=i?t.clientX-i.left:t.clientX,n=i?i.bottom-t.clientY:window.innerHeight-t.clientY,o=this.calculateScale();this.clickInternal(s*o,n*o)},window.addEventListener("resize",this.onResize),window.addEventListener("pointerdown",this.onClick),this.onResize()}get tergetScreenHeight(){return this.targetScreenHeight}set tergetScreenHeight(t){this.targetScreenHeight=t,this.resizeInternal(window.innerWidth,window.innerHeight)}destroy(){window.removeEventListener("resize",this.onResize),window.removeEventListener("pointerdown",this.onClick),super.destroy()}calculateScale(){var t;return(null!==(t=this.tergetScreenHeight)&&void 0!==t?t:window.innerHeight)/window.innerHeight}}class Bi extends Wt{click(t,i){this.clickInternal(t,i)}resize(t,i){this.resizeInternal(t,i)}}class Hi{}export{oi as UIAspectConstraint,Et as UIBehavior,ni as UIConstraint2DBuilder,gi as UIConstraintBuilder,mi as UIConstraintContainerBuilder,Yt as UIConstraintContainerDirection,nt as UIConstraintPower,ot as UIConstraintRule,yi as UIConstraintStackBuilder,ei as UICoverConstraint,bi as UIDummy,Di as UIElementBuilder,Ht as UIElementEvent,zi as UIFitConstraint,ji as UIFullScreenLayer,At as UIFullScreenQuad,ft as UIHeightConstraint,Jt as UIHorizontalDistanceConstraint,Zt as UIHorizontalProportionConstraint,xi as UIImage,Wt as UILayer,Xt as UILayerEvent,Bi as UIManualLayer,st as UIOrientation,Hi as UIPass,Si as UIProgress,Ui as UIScene,qt as UISceneUpdateBehavior,Mi as UIText,ti as UIVerticalDistanceConstraint,ii as UIVerticalProportionConstraint,si as UIWidthConstraint};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laymur",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "tiny ui three js library",
5
5
  "scripts": {
6
6
  "clean": "rm -rf dist",